Skip to content

Commit 0cf4e2b

Browse files
authored
improvement(workflow-code): reorganize the workflows-as-code docs with generated exit-code, diagnostic and limit references (#10334)
Workflows and workspace as code docs move under /workflows/code as a tutorial, how-to pages and generated references; exit codes, diagnostics and limits are generated from the engine (check:workflow-code-docs fails on drift); /workflows/workspace-code redirects to /workflows/code/workspace; CI recipes for a PR plan comment and a scheduled drift job; quick fixes from the docs audit.
1 parent 5860704 commit 0cf4e2b

36 files changed

Lines changed: 2166 additions & 551 deletions

‎.claude/rules/sim-workflow-code.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ workspace directory).
4848
| `apps/sim/blocks/sdk-names/<type>.json` | Frozen SDK builder names, one file per block type |
4949
| `apps/sim/app/workspace/**/panel/components/code/` | The read-only Code tab |
5050

51+
Public docs live in `apps/docs/content/docs/workflows/code/`. The exit-code, diagnostic-code, limit
52+
and per-kind layout tables of `exit-codes.mdx`, `diagnostics.mdx`, `limits.mdx` and `directory.mdx` sit between
53+
`workflow-code-docs` markers and come from their owners (`source-exit-codes.ts`, SYNTAX.md and `workspace-code`'s
54+
`diagnostics/codes.ts` TSDoc, the `*_LIMITS` constants, `WORKSPACE_KIND_SPECS`): edit the owner, then run
55+
`bun run generate:workflow-code-docs` (`check:workflow-code-docs` fails on drift, a diagnostic code a page names that
56+
no engine emits, a limit or diagnostic code with no docs entry, and a `typescript@x.y.z` pin other than the CLI's).
57+
A limit also needs a label in the generator's `WORKFLOW_LIMIT_LABELS` or `WORKSPACE_LIMIT_LABELS`.
58+
5159
Dependencies point one way: `packages/workflow-types` → `packages/workflow-code` →
5260
`packages/workspace-code` and `packages/workflow-sdk` → the CLI and `apps/sim`. `check:boundaries` keeps both engines and `packages/table-cells` pure (no
5361
Node built-ins, `eval`, `globalThis`, dynamic import): they run in the browser, the CLI and the

‎.cursor/rules/sim-workflow-code.mdc‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ workspace directory).
2828
| `apps/sim/blocks/sdk-names/<type>.json` | Frozen SDK builder names, one file per block type |
2929
| `apps/sim/app/workspace/**/panel/components/code/` | The read-only Code tab |
3030

31+
Public docs live in `apps/docs/content/docs/workflows/code/`. The exit-code, diagnostic-code, limit
32+
and per-kind layout tables of `exit-codes.mdx`, `diagnostics.mdx`, `limits.mdx` and `directory.mdx` sit between
33+
`workflow-code-docs` markers and come from their owners (`source-exit-codes.ts`, SYNTAX.md and `workspace-code`'s
34+
`diagnostics/codes.ts` TSDoc, the `*_LIMITS` constants, `WORKSPACE_KIND_SPECS`): edit the owner, then run
35+
`bun run generate:workflow-code-docs` (`check:workflow-code-docs` fails on drift, a diagnostic code a page names that
36+
no engine emits, a limit or diagnostic code with no docs entry, and a `typescript@x.y.z` pin other than the CLI's).
37+
A limit also needs a label in the generator's `WORKFLOW_LIMIT_LABELS` or `WORKSPACE_LIMIT_LABELS`.
38+
3139
Dependencies point one way: `packages/workflow-types` → `packages/workflow-code` →
3240
`packages/workspace-code` and `packages/workflow-sdk` → the CLI and `apps/sim`. `check:boundaries` keeps both engines and `packages/table-cells` pure (no
3341
Node built-ins, `eval`, `globalThis`, dynamic import): they run in the browser, the CLI and the

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ sim tables rows query --help
140140
| [`workflow-mcp-servers`](/cli/workflow-mcp-servers) | Expose deployed workflows as MCP tools |
141141
| [`meta`](/cli/meta) | Inspect API availability and credential status |
142142

143-
To edit a workflow as a TypeScript file, or a whole workspace as a directory, use `sim workflows source` and `sim workspaces source` (in preview). See [Workflows as code](/workflows/code) and [Workspace as code](/workflows/workspace-code).
143+
To edit a workflow as a TypeScript file, or a whole workspace as a directory, use `sim workflows source` and `sim workspaces source` (in preview). See [Workflows as code](/workflows/code) and [Manage a workspace as code](/workflows/code/workspace).
144144

145145
The [command overview](/cli/commands) lists global options and root commands. The [complete reference](/cli/reference) contains every subcommand, argument, and option on one page. Both are generated from the CLI.
146146

@@ -177,7 +177,7 @@ The repository is also a native Claude Code and Codex plugin, which exposes the
177177

178178
The skills assume `sim` is installed and signed in, so complete [Your first command](#your-first-command) first. They never store or print API keys. These agent skills are separate from the workspace skills you manage with [`sim skills`](/cli/skills).
179179

180-
To have a coding agent edit workflow files directly, see [Workflows as code for coding agents](/workflows/code#for-coding-agents).
180+
To have a coding agent edit workflow files directly, see [Use workflows as code with coding agents](/workflows/code/coding-agents).
181181

182182
## Related docs
183183

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

Lines changed: 4 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -165,61 +165,7 @@ The CLI resends a request the API answers `429` only when sending it twice is sa
165165
| `3` | Committed operation requires configuration |
166166
| `4` | Wait timed out |
167167

168-
| Code | `sim workflows source apply` or `create` |
169-
| --- | --- |
170-
| `0` | Applied or created, or a dry run with no errors |
171-
| `1` | The source has errors (each printed as `file:line:column` with its frame and hint), `create`'s workflow name is taken (`SOURCE_NAME_TAKEN`: pass `--name`), or command/request failure |
172-
| `5` | The workflow changed since the directory was read (`409 SOURCE_STALE`): get it again, reapply the edit, and retry |
173-
| `6` | The workflow or its folder is locked (`423`, `E_APPLY_LOCKED`); a locked block exits `1` (`E_APPLY_LOCKED_BLOCK`) |
174-
| `7` | The source is over the size limits (`413`) |
175-
| `9` | Still rate limited (`429`) after the CLI's retries; nothing was written |
176-
| `10` | Busy, retry: another `sim` command is using `--dir`, or the workspace directory it is a workflow folder of (`SOURCE_DIR_BUSY`); nothing was read or 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-
| `10` | `sim workspaces source status` only: another `sim workspaces source` command is using the directory (`SOURCE_DIR_BUSY`); nothing was read: run it again once the other finished |
187-
| `11` | Local changes only: applying writes them |
188-
| `12` | The server changed since the directory was read (drift, or a conflict with local changes) |
189-
| `13` | `AUTH_REQUIRED`: not logged in, or the server refused the credential; the local changes are still shown |
190-
191-
| Code | `sim workflows source check` or `sim workspaces source check` |
192-
| --- | --- |
193-
| `0` | No errors (warnings may still print) |
194-
| `1` | The source has errors, or a warning that fails the check on a block the edit added (see `--strict`), or no block catalog is cached: run the get once |
195-
| `10` | `sim workspaces source check` only: another `sim workspaces source` command is using the directory (`SOURCE_DIR_BUSY`); nothing was read: run it again once the other finished |
196-
197-
| Code | `sim workflows source get --dir` or `sim workspaces source get` |
198-
| --- | --- |
199-
| `0` | Written |
200-
| `1` | The directory holds edits no apply has saved (`SOURCE_LOCAL_EDITS`) or another workflow's source (`SOURCE_WORKFLOW_MISMATCH`): apply them, get into another directory, or pass `--force`; it is the other kind of source directory (`SOURCE_DIR_KIND_MISMATCH`, even with `--force`); for a workspace, `--workspace` names another workspace than the one the directory was read from (`SOURCE_OTHER_WORKSPACE`) or a downloaded binary file does not match its listing (`SOURCE_BLOB_MISMATCH`); or command/request failure |
201-
| `7` | The workflow, or a kind of resource, is too large for one directory |
202-
| `9` | Still rate limited (`429`) after the CLI's retries; nothing was written |
203-
| `10` | Busy, retry: another `sim` command is using the directory (or, for a workflow folder, its workspace directory) (`SOURCE_DIR_BUSY`); nothing was read or written: run it again once the other finished |
204-
| `13` | `AUTH_REQUIRED`: not logged in, the login expired, or the server refused the credential; nothing was read or written: run `sim login` and the get again |
205-
| `130` | Interrupted (Ctrl-C): run the get again |
206-
207-
| Code | `sim workspaces source apply` |
208-
| --- | --- |
209-
| `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; its dry run exits `1` too), or command/request failure |
211-
| `5` | A resource changed since the directory was read (`409 SOURCE_STALE`): get it again into a fresh directory, reapply the edit, and retry |
212-
| `6` | A resource (a workflow or its folder, a table) is locked (`423`); a locked block exits `1` (`E_APPLY_LOCKED_BLOCK`) |
213-
| `7` | The directory is over the size limits (`413`) |
214-
| `8` | The apply stopped part-way: what was written is saved into the directory; apply again |
215-
| `9` | Still rate limited (`429`) after the CLI's retries; nothing was written |
216-
| `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 |
217-
| `13` | `AUTH_REQUIRED`: not logged in, or the server refused the credential; nothing was sent |
218-
| `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). A dry run that would do so exits `15` too, having written nothing |
220-
| `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 |
221-
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.
168+
The source commands (`sim workflows source` and `sim workspaces source`) have codes of their own, among them `5` stale, `10` busy, `11` and `12` for `status`, `14` for an apply without `--yes`, and `15` for an apply that held changes back. [Exit codes](/workflows/code/exit-codes) lists each one with what to do next.
223169

224170
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.
225171

@@ -381,63 +327,14 @@ exit "$status"
381327

382328
## Workspace source in CI
383329

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.
385-
386-
```yaml title=".github/workflows/sim-workspace.yml"
387-
on:
388-
pull_request:
389-
paths: ['workspace/**']
390-
push:
391-
branches: [main]
392-
paths: ['workspace/**']
393-
394-
concurrency: sim-workspace
395-
396-
permissions:
397-
contents: write
398-
399-
jobs:
400-
workspace:
401-
runs-on: ubuntu-latest
402-
env:
403-
SIM_API_KEY: ${{ secrets.SIM_API_KEY }}
404-
SIM_WORKSPACE: ${{ vars.SIM_WORKSPACE }}
405-
steps:
406-
- uses: actions/checkout@v4
407-
- uses: actions/setup-node@v4
408-
with:
409-
node-version: '20'
410-
- uses: oven-sh/setup-bun@v2
411-
- run: bun add -g sim
412-
- run: sim workspaces source check --dir workspace
413-
- run: bunx -p typescript@7.0.2 tsc -p workspace
414-
- run: sim workspaces source apply --dir workspace --dry-run
415-
- if: github.event_name == 'push'
416-
run: sim workspaces source apply --dir workspace --yes
417-
- if: ${{ !cancelled() && github.event_name == 'push' }}
418-
run: |
419-
git add -A workspace
420-
if ! git diff --cached --quiet; then
421-
git -c user.name=sim-bot -c user.email=sim-bot@users.noreply.github.com \
422-
commit -m "chore(workspace): files the apply rewrote [skip ci]"
423-
git push
424-
fi
425-
```
426-
427-
`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. That step runs even when the apply failed (`!cancelled()`), because an apply can fail having written part of its plan: exit `15` means it held back changes that use a secret with no value or a credential nothing binds to and applied the rest, and exit `8` means it stopped part-way. Either way the directory records what was written, so committing it keeps the next run from being refused as stale (exit `5`) for resources this run wrote; the job still fails, so set the secret, connect the credential or fix the failure, and push 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.
428-
429-
To promote the same directory to a second workspace, add a step with `--to` before the step that commits the files back:
430-
431-
```bash
432-
sim workspaces source apply --dir workspace --to "$PROD_WORKSPACE_ID" --yes
433-
```
434-
435-
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.
330+
Dry-run source on pull requests, apply on merge, comment the plan and detect drift on a schedule: see [Run in CI](/workflows/code/ci) for GitHub Actions recipes.
436331

437332
## Related docs
438333

439334
- [Output formats](/cli/output)
440335
- [Workflow commands](/cli/workflows)
336+
- [Workflows as code: run in CI](/workflows/code/ci)
337+
- [Workflows as code: exit codes](/workflows/code/exit-codes)
441338
- [Workflow imports and workspace sync](/cli/workflow-sync)
442339
- [Organization commands](/cli/organizations)
443340
- [Troubleshooting](/cli/troubleshooting)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ sim workflows mkdir <path>
13401340

13411341
API request and response schemas: [createWorkflowFolder](/api-reference/workflows/createWorkflowsFolder).
13421342

1343-
## Other commands
1343+
## Workflows as code
13441344

13451345
### Show a workflow’s draft as TypeScript source with its identity lock
13461346

‎apps/docs/content/docs/meta.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"---Build---",
1212
"chat",
1313
"workflows",
14+
"workflows/code",
1415
"agents",
1516
"---Workspace---",
1617
"knowledgebase",

‎apps/docs/content/docs/platform/self-hosting/environment-variables.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Plain JavaScript without imports runs in isolated-vm within Node child workers i
199199

200200
| Variable | Description |
201201
|----------|-------------|
202-
| `WORKFLOW_CODE` | Set to `true` to enable [workflows as code](/workflows/code) and [workspace as code](/workflows/workspace-code): the read-only **Code** tab in the workflow builder, and the source API and MCP operations that the `sim workflows source` and `sim workspaces source` CLI commands call. Off when unset; while off, those operations answer `403` |
202+
| `WORKFLOW_CODE` | Set to `true` to enable [workflows as code](/workflows/code) and [workspace as code](/workflows/code/workspace): the read-only **Code** tab in the workflow builder, and the source API and MCP operations that the `sim workflows source` and `sim workspaces source` CLI commands call. Off when unset; while off, those operations answer `403` |
203203

204204
## Chat and PII [#chat--pii]
205205

0 commit comments

Comments
 (0)