Skip to content

Commit 6856efa

Browse files
authored
fix(workflow-code): staging QA fixes for workflows and workspace as code (#10220)
Fixes from the staging end-to-end QA of workflows and workspace as code: check and catalog fixes, visibility gate on source apply, CLI exit and interrupt handling, apply DX (binding, findings, created ids, deploy), workspace batching under the body ceiling, params reference and slim primer, diagnostics and rename identity, plus the review fixes.
1 parent b3e928f commit 6856efa

153 files changed

Lines changed: 9751 additions & 1258 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/docs/content/docs/cli/reference.mdx‎

Lines changed: 50 additions & 11 deletions
Large diffs are not rendered by default.

‎apps/docs/content/docs/cli/scripting.mdx‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,22 @@ The CLI resends a request the API answers `429` only when sending it twice is sa
170170
| `0` | Applied or created, or a dry run with no errors |
171171
| `1` | The source has errors (each printed as `file:line:column` with its frame and hint), or command/request failure |
172172
| `5` | The workflow changed since the directory was read (`409 SOURCE_STALE`): get it again, reapply the edit, and retry |
173-
| `6` | The workflow is locked (`423`) |
173+
| `6` | The workflow or its folder is locked (`423`, `E_APPLY_LOCKED`); a locked block exits `1` (`E_APPLY_LOCKED_BLOCK`) |
174174
| `7` | The source is over the size limits (`413`) |
175175
| `9` | Still rate limited (`429`) after the CLI's retries; nothing was written |
176176
| `10` | `--dir` is a workflow folder of a workspace directory another `sim` command is using (`SOURCE_DIR_BUSY`); nothing was written: run it again once the other finished |
177+
| `13` | `AUTH_REQUIRED`: not logged in, or the server refused the credential; nothing was sent |
178+
| `14` | Run without `--yes` and with no terminal to ask: the plan was printed with no errors and nothing was written; run the same command with `--yes` |
179+
| `130` | Interrupted (Ctrl-C). A write already sent is finished and saved into the directory first, waiting up to 60s for its answer; a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check |
180+
181+
| Code | `sim workflows source status` or `sim workspaces source status` |
182+
| --- | --- |
183+
| `0` | Clean: nothing to apply, and the server changed nothing since the directory was read |
184+
| `1` | Command/request failure |
185+
| `7` | The source is too large for the server to read in one dry run |
186+
| `11` | Local changes only: applying writes them |
187+
| `12` | The server changed since the directory was read (drift, or a conflict with local changes) |
188+
| `13` | `AUTH_REQUIRED`: not logged in, or the server refused the credential; the local changes are still shown |
177189

178190
| Code | `sim workflows source check` or `sim workspaces source check` |
179191
| --- | --- |
@@ -192,11 +204,13 @@ The CLI resends a request the API answers `429` only when sending it twice is sa
192204
| `0` | Applied, or a dry run with no errors |
193205
| `1` | The source has errors, changes were held back for a secret or credential the workspace cannot satisfy, or command/request failure |
194206
| `5` | A resource changed since the directory was read (`409 SOURCE_STALE`): get it again into a fresh directory, reapply the edit, and retry |
195-
| `6` | A resource is locked (`423`) |
207+
| `6` | A resource (a workflow or its folder, a table) is locked (`423`); a locked block exits `1` (`E_APPLY_LOCKED_BLOCK`) |
196208
| `7` | The directory is over the size limits (`413`) |
197209
| `8` | The apply stopped part-way: what was written is saved into the directory; apply again |
198210
| `9` | Still rate limited (`429`) after the CLI's retries; nothing was written |
199211
| `10` | Busy, retry: another apply is writing the workspace (`409 SOURCE_BUSY`), or another `sim workspaces source` command is using the same directory (`SOURCE_DIR_BUSY`); nothing was written: run the command again once the other finished |
212+
| `13` | `AUTH_REQUIRED`: not logged in, or the server refused the credential; nothing was sent |
213+
| `130` | Interrupted (Ctrl-C). A write already sent is finished and saved into the directory first, waiting up to 60s for its answer; a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check |
200214

201215
Both waits default to 3600 seconds; `--wait-timeout 0` waits indefinitely. `SIM_TIMEOUT_SECONDS` independently bounds one API request. A timeout does not cancel the underlying run or operation.
202216

@@ -403,12 +417,14 @@ jobs:
403417
404418
`check` runs first because it is offline and fast, and it regenerates `.sim/sdk/workspace.d.ts`, so the `tsc` step after it types resources the pull request adds. A workspace API key can apply tables, rows, knowledge bases, files, custom tools, MCP servers and credential bindings. Workflows, skills, secrets and deployments need a member's personal API key, and deployments need an admin. Apply rewrites files under the directory (each `.sim/base.json`, ids it allocated, values the server normalized), and the next apply compares with them, so the last step commits them back to the branch; `[skip ci]` keeps that commit from running the job again. Where the branch is protected, run `sim workspaces source get --dir workspace` on a new branch instead and open a pull request. After merging two branches that each applied, a dry run with no changes means the files match the workspace. Exit `5` means a resource changed since this branch's base: get the workspace into a fresh directory and carry the edit over. Exit `10` means another apply is writing the workspace (or another command is using the directory), so retry; the `concurrency` key keeps two runs of this job from overlapping.
405419
406-
To promote the same directory to a second workspace, add a step with `--to`:
420+
To promote the same directory to a second workspace, add a step with `--to` before the step that commits the files back:
407421

408422
```bash
409423
sim workspaces source apply --dir workspace --to "$PROD_WORKSPACE_ID" --yes
410424
```
411425

426+
The promotion writes `workspace/.sim/targets/<workspaceId>.json`, what it left in that workspace. Committing it lets the next run tell a change made in that workspace since (kept, or exit `5` when the directory changed the same resource) from one to promote.
427+
412428
## Related docs
413429

414430
- [Output formats](/cli/output)

‎apps/docs/content/docs/cli/workflows.mdx‎

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,7 @@ sim workflows source status [options]
13371337

13381338
</CommandTable>
13391339

1340-
Exit codes: 0 clean (nothing to apply, and the server changed nothing since the directory was read); 11 local changes only (applying writes them); 12 the server changed since the directory was read: drift (a resource edited, added or deleted there that the directory leaves alone) or a conflict (also changed here, so applying it is refused as stale), with or without local changes; 7 the source is too large for the server to read in one dry run; 1 the command failed. A server that cannot be reached is not a failure: the status shows the local changes only and says so (exit 0 or 11).
1340+
Exit codes: 0 clean (nothing to apply, and the server changed nothing since the directory was read); 11 local changes only (applying writes them); 12 the server changed since the directory was read: drift (a resource edited, added or deleted there that the directory leaves alone) or a conflict (also changed here, so applying it is refused as stale), with or without local changes; 7 the source is too large for the server to read in one dry run; 1 the command failed; 13 not logged in (AUTH_REQUIRED) or the credential was refused: the status shows the local changes only, then run `sim login`. A server that cannot be reached is not a failure: the status shows the local changes only and says so (exit 0 or 11).
13411341

13421342
API request and response schemas: [applyWorkflowSource](/api-reference/workflows/applyWorkflowSource).
13431343

@@ -1353,17 +1353,19 @@ sim workflows source create [options]
13531353

13541354
| Option | Required | Description |
13551355
| --- | --- | --- |
1356+
| `--verbose` | No | With --output json, also list info findings (such as blocks placed by autolayout). |
13561357
| `--dir <dir>` | Yes | Source directory: workflow.ts and functions/*. Without workflow.ts, writes a starter and the types instead (an error with --dry-run or --yes). |
13571358
| `--dry-run` | No | Check the source and show the outcome without creating anything. |
13581359
| `--name <name>` | No | The workflow name (default: the source's). |
13591360
| `--folder <path>` | No | The folder to create it in (default: the root). |
13601361
| `-y, --yes` | No | Create without asking for confirmation. |
1362+
| `--deploy` | No | After the write is saved, deploy the workflow (as `sim workflows deploy <workflowId>` does). |
13611363

13621364
</CommandTable>
13631365

1364-
Exit codes: 0 created (or a clean dry run, or a starter written); 1 the source has errors (each printed as file:line:column with its frame and hint), the workflow name is taken (SOURCE_NAME_TAKEN: pass --name), or the command failed; 6 the folder is locked; 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries, so nothing was created: wait a minute and run it again. Exit 10 (busy, retry): --dir is a workflow folder of a workspace directory another sim command is using (SOURCE_DIR_BUSY); nothing was read or written. Run this one again once it finished.
1366+
Exit codes: 0 created (or a clean dry run, or a starter written); 1 the source has errors (each printed as file:line:column with its frame and hint), the workflow name is taken (SOURCE_NAME_TAKEN: pass --name), or the command failed (a starter is created in the workspace its types were written for unless --workspace names another); 6 the folder is locked; 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries, so nothing was created: wait a minute and run it again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was created (run the same command with --yes). Exit 10 (busy, retry): --dir is a workflow folder of a workspace directory another sim command is using (SOURCE_DIR_BUSY); nothing was read or written. Run this one again once it finished. Exit 13: not logged in, or the server refused the credential (AUTH_REQUIRED); nothing was sent. Run `sim login`, or fix or unset SIM_API_KEY when the key comes from it. Exit 130: interrupted (Ctrl-C). A write already sent is finished and saved into the directory first, waiting up to 60s for its answer; a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check.
13651367

1366-
API request and response schemas: [createWorkflowFromSource](/api-reference/workflows/createWorkflowFromSource), [getSourceCatalog](/api-reference/catalog/getSourceCatalog), [getSourceResources](/api-reference/workflows/getSourceResources).
1368+
API request and response schemas: [createWorkflowFromSource](/api-reference/workflows/createWorkflowFromSource), [getSourceCatalog](/api-reference/catalog/getSourceCatalog), [getSourceResources](/api-reference/workflows/getSourceResources), [deployWorkflow](/api-reference/workflows/deployWorkflow).
13671369

13681370
### Apply a workflow source directory to a workflow draft
13691371

@@ -1387,16 +1389,18 @@ sim workflows source apply [workflowId] [options]
13871389

13881390
| Option | Required | Description |
13891391
| --- | --- | --- |
1392+
| `--verbose` | No | With --output json, also list info findings (such as blocks placed by autolayout). |
13901393
| `--dir <dir>` | Yes | Source directory: workflow.ts, functions/*, .sim/lock.json and .sim/base.json. |
13911394
| `--dry-run` | No | Check the source and show the outcome without saving or writing files. |
13921395
| `-y, --yes` | No | Apply without asking for confirmation. |
1396+
| `--deploy` | No | After the write is saved, deploy the workflow (as `sim workflows deploy <workflowId>` does). |
13931397
| `--allow-delete` | No | Delete blocks the source no longer declares; without it, an apply that deletes a block is refused. |
13941398

13951399
</CommandTable>
13961400

1397-
Exit codes: 0 applied (or a clean dry run); 1 the source has errors (each printed as file:line:column with its frame and hint) or the command failed; 5 the workflow changed since the directory was read (SOURCE_STALE, on a dry run too: get it again, reapply the edit, retry); 6 the workflow or its folder is locked; 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries, so nothing was written: wait a minute and run it again. Exit 10 (busy, retry): --dir is a workflow folder of a workspace directory another sim command is using (SOURCE_DIR_BUSY); nothing was read or written. Run this one again once it finished.
1401+
Exit codes: 0 applied (or a clean dry run); 1 the source has errors (each printed as file:line:column with its frame and hint) or the command failed; 5 the workflow changed since the directory was read (SOURCE_STALE, on a dry run too: get it again, reapply the edit, retry); 6 the workflow or its folder is locked (E_APPLY_LOCKED; a locked block exits 1, E_APPLY_LOCKED_BLOCK); 7 the source is too large; 9 rate limited (HTTP 429) after the CLI's retries, so nothing was written: wait a minute and run it again; 14 without --yes and with no terminal to ask: the plan was printed with no errors and nothing was written (run the same command with --yes to apply it). Exit 10 (busy, retry): --dir is a workflow folder of a workspace directory another sim command is using (SOURCE_DIR_BUSY); nothing was read or written. Run this one again once it finished. Exit 13: not logged in, or the server refused the credential (AUTH_REQUIRED); nothing was sent. Run `sim login`, or fix or unset SIM_API_KEY when the key comes from it. Exit 130: interrupted (Ctrl-C). A write already sent is finished and saved into the directory first, waiting up to 60s for its answer; a second Ctrl-C, or no answer by then, stops at once and prints that it may have been written and how to check.
13981402

1399-
API request and response schemas: [applyWorkflowSource](/api-reference/workflows/applyWorkflowSource).
1403+
API request and response schemas: [applyWorkflowSource](/api-reference/workflows/applyWorkflowSource), [deployWorkflow](/api-reference/workflows/deployWorkflow).
14001404

14011405
### Show the block catalog workflow source is checked against
14021406

@@ -1431,14 +1435,15 @@ sim workflows source check [options]
14311435
| `--dir <dir>` | No | Source directory: workflow.ts, functions/* and .sim/. Defaults to `.`. |
14321436
| `--strict` | No | Fail on the warnings listed below in every block, not only new ones. |
14331437
| `--no-strict` | No | Never fail on a warning. |
1438+
| `--verbose` | No | With --output json, also list info findings (such as blocks placed by autolayout). |
14341439

14351440
</CommandTable>
14361441

14371442
Compiles workflow.ts (and the function files it names) with the compiler the server runs, against the workspace's block catalog the last get or create cached, and prints the findings as the dry run does. No request is made. It covers the source itself (syntax, builders, params, references, wiring). In a workflow folder of a workspace directory (workflows/&lt;key&gt;), it reads the workspace's .sim/base.json and also checks env names, resource keys and table columns against what the directory declares. The dry run still checks what only the server knows (stored values, deployment), so run it before applying. A check also adds the blocks the source now uses to the CLI's tsconfig.json, so tsc type-checks a block the edit added; in a workspace directory it also regenerates .sim/sdk/workspace.d.ts, so tsc types each workflow's inputs as its files declare them.
14381443

14391444
Exit codes: 0 no errors; 1 errors (each printed as file:line:column with its frame and hint), or no cached catalog (run the get once). With --output json, stdout is one document that also lists every finding under diagnostics.
14401445

1441-
These warnings, which an apply saves as written, fail the check as errors on every block the lock does not bind (a block added since the get, or every block of a new workflow): W_REQUIRED_MISSING, W_UNKNOWN_OPTION, W_UNKNOWN_OUTPUT_PATH, W_VALUE_KIND, W_OUT_OF_RANGE, W_LITERAL_SECRET, W_TABLE_UNKNOWN_COLUMN, W_CHILD_INPUT_UNKNOWN, W_BRANCH_UNWIRED. --strict fails on them in every block, except W_BRANCH_UNWIRED on a block the lock binds (the stored workflow may hold it, and the server then stays quiet); --no-strict never fails on a warning.
1446+
These warnings, which an apply saves as written, fail the check as errors on every block the lock does not bind (a block added since the get, or every block of a new workflow): W_REQUIRED_MISSING, W_UNKNOWN_OPTION, W_UNKNOWN_OUTPUT_PATH, W_VALUE_KIND, W_OUT_OF_RANGE, W_LITERAL_SECRET, W_TABLE_UNKNOWN_COLUMN, W_CHILD_INPUT_UNKNOWN, W_BRANCH_UNWIRED, W_UNRESOLVED_REF. --strict fails on them in every block, except W_BRANCH_UNWIRED on a block the lock binds (the stored workflow may hold it, and the server then stays quiet); --no-strict never fails on a warning. W_JSON_REF_UNTYPED is reported only on blocks the lock does not bind, and with --strict on every block.
14421447

14431448
### Show the content of the changes in a workflow source directory
14441449

@@ -1472,6 +1477,38 @@ Without --server, each file created, edited or deleted since the directory was r
14721477

14731478
API request and response schemas: [getWorkflowSource](/api-reference/workflows/getWorkflowSource).
14741479

1480+
### Print a builder's params and outputs from the cached block catalog
1481+
1482+
Offline.
1483+
1484+
```bash
1485+
sim workflows source params <builder> [options]
1486+
```
1487+
1488+
**Arguments**
1489+
1490+
<CommandTable>
1491+
1492+
| Argument | Required | Description |
1493+
| --- | --- | --- |
1494+
| `builder` | Yes | Builder path (table.upsertRow, agent, trigger.schedule) or namespace |
1495+
1496+
</CommandTable>
1497+
1498+
**Options**
1499+
1500+
<CommandTable>
1501+
1502+
| Option | Required | Description |
1503+
| --- | --- | --- |
1504+
| `--dir <dir>` | No | Source directory whose catalog to read. Defaults to `.`. |
1505+
1506+
</CommandTable>
1507+
1508+
Prints a builder's params (required first, with enums and defaults), the gate field that picks which others apply, and its outputs, from the block catalog the last get, create or check cached. No request is made. &lt;builder&gt; is the dotted builder path as source writes it: table.upsertRow, agent, trigger.schedule, slack.sendMessage (slack.tool.sendMessage names the same builder). A namespace (gmail, trigger.gmail) lists its builders; a construct core.d.ts declares (loop, parallel, t, env) prints its declaration. Run it from a workflow or workspace source directory, or pass --dir.
1509+
1510+
Exit codes: 0 printed; 1 no builder or namespace of that name (the closest one is named), or no cached catalog (run a get once).
1511+
14751512
### List the tables, knowledge bases, credentials, workflows, skills, custom tools, MCP servers and env names source can name
14761513

14771514
```bash

0 commit comments

Comments
 (0)