Skip to content

Commit bf6bc31

Browse files
authored
improvement(workflow-code): agent DX and check/server parity from the v6 benchmark (#10305)
Agent DX fixes from the A/B v6 benchmark: --stop-after output, destructive counting, status/dry-run parity, dry-run exit 15, canonical param names on ops, ops/run help and cookbook docs; check and lint parity for child result paths, lock caps and loop conditions; clearer undeployed-child and unknown-type errors.
1 parent cdac23d commit bf6bc31

90 files changed

Lines changed: 3476 additions & 1110 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/blocks.mdx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,16 @@ sim blocks get <blockId>
5353

5454
</CommandTable>
5555

56+
```text
57+
Reading it for `sim workflows operations apply`:
58+
id the type to add: `blocks get table` answers table_v2 (an add of legacy
59+
table is refused)
60+
inputSchema the field ids inputs takes; operationInputSchema, an operation's own
61+
inputDefinitions the block's inputs by name; one a pair of fields shares (tableId for
62+
tableSelector and manualTableId) is accepted in place of the pair
63+
outputs what it outputs on success; a failed block outputs {"error":"…"}
64+
instead, read on its error path as <name.error>
65+
Block settings such as retry are not fields: `sim workflows operations apply --help`.
66+
```
67+
5668
API request and response schemas: [getBlock](/api-reference/catalog/getBlock).

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

Lines changed: 48 additions & 5 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ The CLI resends a request the API answers `429` only when sending it twice is sa
207207
| Code | `sim workspaces source apply` |
208208
| --- | --- |
209209
| `0` | Applied, or a dry run with no errors |
210-
| `1` | The source has errors, every change it would write was held back for a secret or credential the workspace cannot satisfy (nothing was written), or command/request failure |
210+
| `1` | The source has errors, every change it would write was held back for a secret or credential the workspace cannot satisfy (nothing was written; its dry run exits `1` too), or command/request failure |
211211
| `5` | A resource changed since the directory was read (`409 SOURCE_STALE`): get it again into a fresh directory, reapply the edit, and retry |
212212
| `6` | A resource (a workflow or its folder, a table) is locked (`423`); a locked block exits `1` (`E_APPLY_LOCKED_BLOCK`) |
213213
| `7` | The directory is over the size limits (`413`) |
@@ -216,14 +216,14 @@ The CLI resends a request the API answers `429` only when sending it twice is sa
216216
| `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 |
217217
| `13` | `AUTH_REQUIRED`: not logged in, or the server refused the credential; nothing was sent |
218218
| `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` |
219-
| `15` | Written in part: changes that use a declared secret with no value, or a credential key nothing binds to, were held back and the rest was applied and saved; set the secret or connect the credential, then apply again (a promotion with `--to` too) |
219+
| `15` | Written in part: changes that use a declared secret with no value, or a credential key nothing binds to, were held back and the rest was applied and saved; set the secret or connect the credential, then apply again (a promotion with `--to` too). A dry run that would do so exits `15` too, having written nothing |
220220
| `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 |
221221

222-
Earlier CLI releases exited `1` when an apply held changes back, whether or not it wrote the rest. A script that reads `1` as "held back" should test for `15` too.
222+
Earlier CLI releases exited `1` when an apply held changes back, whether or not it wrote the rest, and its dry run exited `1` in either case. A script that reads `1` as "held back" should test for `15` too.
223223

224224
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.
225225

226-
A synchronous or followed workflow run prints its result before exiting 1 for failure/cancellation. A paused run is not failed and can return 0; use `runs wait` or inspect status if your script requires completion. Fetching a failed run or listing runs only reports their state.
226+
A synchronous or followed workflow run prints its result before exiting 1 for failure/cancellation. The result of a run that is not followed is the run record, whose `status` is `completed`, `failed`, `paused` or `cancelled`; it has no `success` field (a followed run's result is the stream's final frame, `success` and `output`), so branch on `status` or the exit code. A paused run is not failed and can return 0; use `runs wait` or inspect status if your script requires completion. Fetching a failed run or listing runs only reports their state.
227227

228228
Capture a failure without losing its output:
229229

@@ -381,7 +381,7 @@ exit "$status"
381381

382382
## Workspace source in CI
383383

384-
Keep a [workspace source directory](/workflows/workspace-code) in a repository, `.sim/` included, and let CI plan each pull request and apply each merge. The dry run exits `1` on errors and `5` when the workspace changed since the committed base; `check` downloads the block catalog once on a fresh runner. On GitHub Actions (`GITHUB_ACTIONS=true`), every source command also annotates each error and warning at its file and line, so they show inline on the pull request, and `apply` (a dry run too) appends its plan and errors to the job's step summary.
384+
Keep a [workspace source directory](/workflows/workspace-code) in a repository, `.sim/` included, and let CI plan each pull request and apply each merge. The dry run exits `1` on errors, `5` when the workspace changed since the committed base, and `15` when the apply would hold back changes that use a secret with no value or a credential nothing binds to; `check` downloads the block catalog once on a fresh runner. On GitHub Actions (`GITHUB_ACTIONS=true`), every source command also annotates each error and warning at its file and line, so they show inline on the pull request, and `apply` (a dry run too) appends its plan and errors to the job's step summary.
385385

386386
```yaml title=".github/workflows/sim-workspace.yml"
387387
on:

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ sim workflows create [options]
7474

7575
</CommandTable>
7676

77+
The new workflow's draft holds one Start block (start_trigger, named Start): connect the blocks you add from it.
78+
7779
API request and response schemas: [createWorkflow](/api-reference/workflows/createWorkflowV2).
7880

7981
### Update workflow
@@ -354,6 +356,23 @@ Source handles:
354356
Renames:
355357
An edit's {"name":"New name"} also rewrites every <old key.field> reference to the block, in
356358
other blocks' inputs and in a loop's or parallel's collection and condition.
359+
Inputs:
360+
inputs takes the field ids `sim blocks get <type>` lists (inputSchema, operationInputSchema),
361+
or the name a pair of them shares (inputDefinitions: tableId for tableSelector and
362+
manualTableId; a string goes to the typed field). Add the type it answers with: `blocks get
363+
table` answers table_v2, and an add of legacy table is refused.
364+
conditions (condition): [{"title":"if","value":"<start.n> > 3"},{"title":"else if","value":"…"},
365+
{"title":"else","value":""}]; the last entry is the else, and ids are assigned.
366+
inputFormat (Start): [{"name":"email","type":"string"}]; types string, number, boolean,
367+
object, array, file[]; an optional default "value" as text.
368+
Block settings, beside inputs in an add's or edit's params:
369+
"retry":{"enabled":true,"maxTries":3,"waitBetweenTriesMs":1000} retries a failed block; null
370+
clears it.
371+
Outputs:
372+
A block that fails outputs {"error":"<message>"}: connect its error handle and read
373+
<name.error> there (without one, the run fails). A Workflow block's result is the child's
374+
output; a child ending in a Response block gives {data, status, headers}, so read
375+
<call.result.data.x>.
357376
```
358377

359378
API request and response schemas: [applyWorkflowOperations](/api-reference/workflows/applyWorkflowOperations).
@@ -794,7 +813,7 @@ sim workflows run <workflowId> [options]
794813
| `--mock-payload` | No | Use the selected trigger's server-derived mock payload; runs the current saved workflow state (implies --manual). |
795814
| `--from-block <block>` | No | Run manually from this saved workflow block: its id, display name or key. |
796815
| `--source-run <runId>` | No | Prior run whose persisted state supplies upstream outputs (requires --from-block). |
797-
| `--stop-after <block>` | No | Stop the run after this saved block (its id, display name or key), failing it if the run takes a path that skips the block; with --from-block on the same block, re-runs only that block (implies --manual). |
816+
| `--stop-after <block>` | No | Stop the run after this saved block (its id, display name or key), failing it if the run takes a path that skips the block; with --from-block on the same block, re-runs only that block (implies --manual). Unless --select-output names others, blockOutputs holds the output of that block under its key (or id); output stays empty. |
798817
| `--dir <dir>` | No | This workflow's source directory: a failed run names the source file and line of the block that failed, read through its .sim/lock.json. Not with --async or --follow, and not for a run --wait-timeout leaves running. |
799818
| `--wait-timeout <seconds>` | No | Wait at most this many seconds for a synchronous run (0 waits until it settles). A run still going then continues in the background under async limits: the command prints its run record and exits 4, and `sim workflows runs wait` keeps waiting. Not with --async or --follow. |
800819
| `--follow` | No | Stream the run as it happens; progress on stderr, result on stdout. The stream reports only success and output, so the result omits the run id and timings a non-streaming run returns. |
@@ -803,6 +822,12 @@ sim workflows run <workflowId> [options]
803822

804823
</CommandTable>
805824

825+
Without --manual (or a flag that implies it) this runs the active deployment; a workflow never deployed has none. --manual runs the saved draft, as the source loop leaves it.
826+
827+
The result is the run: runId, status (completed, failed, paused or cancelled), error, output (the workflow's final output) and blockOutputs (what --select-output named). It has no success field: branch on status, or on the exit code. With --follow it is the stream's final frame instead: success and output.
828+
829+
Exit codes: 0 completed or paused (--async: queued); 1 failed or cancelled (the result is printed first, then the error on stderr), or the command failed; 4 still running when --wait-timeout elapsed.
830+
806831
API request and response schemas: [executeWorkflow](/api-reference/workflows/executeWorkflowV2).
807832

808833
### List runs for a workflow
@@ -1113,6 +1138,8 @@ sim workflows export <workflowId> [options]
11131138

11141139
</CommandTable>
11151140

1141+
Workspace bindings (a table, a child workflow, a knowledge base) print as null unless --include-workspace-bindings, and credentials always do: to read what a block is set to, use `sim workflows state get`.
1142+
11161143
API request and response schemas: [exportWorkflow](/api-reference/workflows/exportWorkflow).
11171144

11181145
### Preview workflow import
@@ -1361,6 +1388,8 @@ sim workflows source status [options]
13611388

13621389
</CommandTable>
13631390

1391+
With --json, `plan` is what applying would do as `apply --dry-run --allow-delete` reports it (its errors and warnings counted the same, a conflict as an error), and `next` the command to run (with --allow-delete only when the plan deletes something).
1392+
13641393
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).
13651394

13661395
API request and response schemas: [planWorkflowSource](/api-reference/workflows/planWorkflowSource), [applyWorkflowSource](/api-reference/workflows/applyWorkflowSource), [getSourceResources](/api-reference/workflows/getSourceResources).
@@ -1467,7 +1496,7 @@ Compiles workflow.ts (and the function files it names) with the compiler the ser
14671496

14681497
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.
14691498

1470-
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, W_REF_OUT_OF_SCOPE. --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 fails on none of them. In every mode, as the server refuses them: W_REF_OUT_OF_SCOPE is the error E_APPLY_REF_OUT_OF_SCOPE in any file of a block the edit added or changed; W_UNKNOWN_OPTION is the error E_APPLY_INVALID_SUBBLOCK_FIELD in workflow.ts on a block the edit added or changed; W_UNKNOWN_OUTPUT_PATH is the error E_APPLY_UNRESOLVED_REF in workflow.ts on a block the edit added or changed; W_UNRESOLVED_REF is the error E_APPLY_UNRESOLVED_REF in workflow.ts on a block the edit added or changed; W_UNKNOWN_BLOCK_TYPE is the error E_APPLY_INVALID_BLOCK_TYPE in workflow.ts on a block the edit added or changed; W_TYPE_NOT_ADDABLE is the error E_APPLY_TYPE_NOT_ADDABLE in workflow.ts on a block the edit added or changed; W_UNRESOLVED_REF is the error E_APPLY_UNRESOLVED_REF in a function file changed since the get; W_UNKNOWN_OUTPUT_PATH is the error E_APPLY_UNRESOLVED_REF in a function file changed since the get; W_CODE_FILE_REF_SYNTAX is the error E_APPLY_CODE_FILE_REF_SYNTAX in a function file changed since the get. A block counts as changed when the lock does not bind it, when the source moved it into another container, or when it compiles differently than in the source the last get or apply printed (.sim/stored-edges.json records a digest of each block). That last comparison needs the catalog the source was printed with in the cache: without it, a bound block that did not move counts as unchanged, so the server may refuse what the check passes. A $ref in a function file to a block the lock binds that the source no longer declares stays a warning, unless a warning cap left findings out: the server may infer that block was renamed and rewrite the reference, and refuses it otherwise. W_JSON_REF_UNTYPED is reported only on blocks the lock does not bind, and with --strict on every block.
1499+
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_CHILD_RESULT_PATH, W_BRANCH_UNWIRED, W_UNRESOLVED_REF, W_REF_OUT_OF_SCOPE, W_LOOP_CONDITION_SYNTAX. --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 fails on none of them. In every mode, as the server refuses them: W_REF_OUT_OF_SCOPE is the error E_APPLY_REF_OUT_OF_SCOPE in any file of a block the edit added or changed; W_LOOP_CONDITION_SYNTAX is the error E_APPLY_LOOP_CONDITION_SYNTAX in any file of a block the edit added or changed; W_UNKNOWN_OPTION is the error E_APPLY_INVALID_SUBBLOCK_FIELD in workflow.ts on a block the edit added or changed; W_UNKNOWN_OUTPUT_PATH is the error E_APPLY_UNRESOLVED_REF in workflow.ts on a block the edit added or changed; W_UNRESOLVED_REF is the error E_APPLY_UNRESOLVED_REF in workflow.ts on a block the edit added or changed; W_UNKNOWN_BLOCK_TYPE is the error E_APPLY_INVALID_BLOCK_TYPE in workflow.ts on a block the edit added or changed; W_TYPE_NOT_ADDABLE is the error E_APPLY_TYPE_NOT_ADDABLE in workflow.ts on a block the edit added or changed; W_UNRESOLVED_REF is the error E_APPLY_UNRESOLVED_REF in a function file changed since the get; W_UNKNOWN_OUTPUT_PATH is the error E_APPLY_UNRESOLVED_REF in a function file changed since the get; W_CODE_FILE_REF_SYNTAX is the error E_APPLY_CODE_FILE_REF_SYNTAX in a function file changed since the get. A block counts as changed when the lock does not bind it, when the source moved it into another container, or when it compiles differently than in the source the last get or apply printed (.sim/stored-edges.json records a digest of each block). That last comparison needs the catalog the source was printed with in the cache: without it, a bound block that did not move counts as unchanged, so the server may refuse what the check passes. A $ref in a function file to a block the lock binds that the source no longer declares stays a warning, unless a warning cap left findings out: the server may infer that block was renamed and rewrite the reference, and refuses it otherwise. W_JSON_REF_UNTYPED is reported only on blocks the lock does not bind, and with --strict on every block.
14711500

14721501
### Show the content of the changes in a workflow source directory
14731502

@@ -1529,7 +1558,7 @@ sim workflows source params <builder> [options]
15291558

15301559
</CommandTable>
15311560

1532-
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.
1561+
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 block type prints the builder written for it (function is fn) or lists them (table_v2); 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.
15331562

15341563
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).
15351564

0 commit comments

Comments
 (0)