# uip maestro case sla

> Syntax and options for reading service-level agreement (SLA) and escalation settings on a Maestro Case Management definition with `uip maestro case sla`.

`uip maestro case sla` reads the service-level-agreement (SLA) duration, conditional SLA rules, and escalation notifications defined on a case-management `caseplan.json` file — at the case root, or on a specific stage. See [`uip maestro case`](./uip-maestro-case.md) for the overall Case Management subsystem this belongs to.

## Synopsis

```text
uip maestro case sla get <file> [--stage-id <stageId>]
uip maestro case sla escalation list <file> [--stage-id <stageId>]
uip maestro case sla rules list <file>
```

## Concepts

- **SLA target** — every read verb operates on either the case root (default) or one named stage, selected with `--stage-id <stageId>`. Omit it for the root-level SLA.
- **Default rule vs. conditional rules** — internally, a plain root/stage SLA (set via direct file edit) is stored as one `slaRules` entry with a fixed expression (`=js:true`) that always matches; a **conditional SLA rule** is an additional entry with a real JavaScript boolean expression (e.g. `=js:amount>1000`) evaluated against the case's data, letting different cases hit different SLA durations. Conditional rules are ordered before the default rule in the array — the first matching expression wins.
- **Duration unit** — every SLA duration is a `{count, unit}` pair; `unit` is one of `min`, `h`, `d`, `w`, `m` (minutes/hours/days/weeks/months).
- **Escalation rule** — an optional notification attached to the *default* SLA rule (root or stage), firing either `at-risk` (with an `--at-risk-percentage` threshold, e.g. 80% of the SLA duration elapsed) or `sla-breached`. Each escalation rule has one recipient — a `User` or `UserGroup`, identified by a target ID/email and a display value.
- **Legacy shape fallback** — `sla get` also recognizes an older, pre-`slaRules` shape (`{sla: {count, unit, escalationRule}}` written directly under the case/stage's data) if no `slaRules` array is present yet, and normalizes it into the same output shape.

## uip maestro case sla get

Read the effective SLA settings — duration and any conditional rules — for the case root or one stage.

### Arguments

| Name | Required | Purpose |
|---|---|---|
| `<file>` | yes | Path to the case-management JSON file (`caseplan.json`). |

### Options

| Long | Value | Description |
|---|---|---|
| `--stage-id <stageId>` | string | Stage ID to read the SLA from. Omit for the root-level SLA. |

### Example

```bash
uip maestro case sla get case.json
```

### Data shape (--output json)

```json
{
  "Code": "SlaFound",
  "Data": {
    "Target": "root",
    "SlaRules": [{ "expression": "=js:true", "count": 2, "unit": "d" }]
  }
}
```

`Target` is `"root"` or the stage ID you passed. `SlaRules` is empty (`[]`) when no SLA has been set (via direct file edit) on that target.

## uip maestro case sla escalation list

List escalation rules attached to the default SLA rule at the case root or a stage.

### Arguments

| Name | Required | Purpose |
|---|---|---|
| `<file>` | yes | Path to the case-management JSON file. |

### Options

| Long | Value | Description |
|---|---|---|
| `--stage-id <stageId>` | string | Stage ID to list escalations from. Omit for the root-level SLA. |

### Example

```bash
uip maestro case sla escalation list case.json
```

### Data shape (--output json)

```json
{
  "Code": "EscalationRulesList",
  "Data": {
    "Target": "root",
    "EscalationRules": [
      { "id": "esc_a1b2c3d4", "triggerInfo": { "type": "at-risk", "atRiskPercentage": 80 } }
    ]
  }
}
```

`EscalationRules` is `[]` when the target has no SLA rule set, or the SLA rule has no escalations.

## uip maestro case sla rules list

List every conditional SLA rule defined at the case root (conditional rules are root-only; a stage's SLA has no separate conditional-rules list).

### Arguments

| Name | Required | Purpose |
|---|---|---|
| `<file>` | yes | Path to the case-management JSON file. |

### Example

```bash
uip maestro case sla rules list case.json
```

### Data shape (--output json)

```json
{
  "Code": "SlaRulesList",
  "Data": {
    "SlaRules": [
      { "expression": "=js:amount>1000", "count": 4, "unit": "h" },
      { "expression": "=js:true", "count": 2, "unit": "d" }
    ]
  }
}
```

This returns the same underlying array as `sla get` on the root target — conditional rules first, the default (`=js:true`) rule last.

## Authoring an SLA directly

Configure SLAs and escalations by editing `caseplan.json`'s `slaRules` array yourself, matching the shapes above, then validate:

```bash
uip maestro case validate case.json
```

- **Set a plain SLA**: add or edit the entry with `expression: "=js:true"` in the target's `slaRules` array, setting `count`/`unit`.
- **Add a conditional rule**: prepend an entry with a real `expression` (e.g. `"=js:amount>1000"`) and its own `count`/`unit` before the default entry.
- **Add an escalation**: push an object onto the default rule's `escalationRule` array — `{ id, displayName?, action: { type: "notification", recipients: [{ scope: "User" | "UserGroup", target, value }] }, triggerInfo: { type: "at-risk" | "sla-breached", atRiskPercentage? } }`.
- **Remove anything**: delete the corresponding array entry and re-validate.

## Related

- [uip maestro case](./uip-maestro-case.md) — Case Management overview, `init`/`pack`/`debug`/`validate`/`spec`.
- [uip maestro case cases & stages](./uip-maestro-case-cases-stages.md) — the case/stage definitions an SLA target attaches to.
- [uip maestro case tasks](./uip-maestro-case-tasks.md) — task definitions (SLAs on tasks, if supported, are documented there).

## See also

- [Maestro tool overview](./uip-maestro-bpmn.md)
- [Global options](./global-options.md)
- [Exit codes](./exit-codes.md)
