Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .claude/rules/sim-workflow-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ workspace directory).
| `apps/sim/blocks/sdk-names/<type>.json` | Frozen SDK builder names, one file per block type |
| `apps/sim/app/workspace/**/panel/components/code/` | The read-only Code tab |

Public docs live in `apps/docs/content/docs/workflows/code/`. The exit-code, diagnostic-code, limit
and per-kind layout tables of `exit-codes.mdx`, `diagnostics.mdx`, `limits.mdx` and `directory.mdx` sit between
`workflow-code-docs` markers and come from their owners (`source-exit-codes.ts`, SYNTAX.md and `workspace-code`'s
`diagnostics/codes.ts` TSDoc, the `*_LIMITS` constants, `WORKSPACE_KIND_SPECS`): edit the owner, then run
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
`bun run generate:workflow-code-docs` (`check:workflow-code-docs` fails on drift, a diagnostic code a page names that
no engine emits, a limit or diagnostic code with no docs entry, and a `typescript@x.y.z` pin other than the CLI's).
A limit also needs a label in the generator's `WORKFLOW_LIMIT_LABELS` or `WORKSPACE_LIMIT_LABELS`.

Dependencies point one way: `packages/workflow-types` → `packages/workflow-code` →
`packages/workspace-code` and `packages/workflow-sdk` → the CLI and `apps/sim`. `check:boundaries` keeps both engines and `packages/table-cells` pure (no
Node built-ins, `eval`, `globalThis`, dynamic import): they run in the browser, the CLI and the
Expand Down
8 changes: 8 additions & 0 deletions .cursor/rules/sim-workflow-code.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ workspace directory).
| `apps/sim/blocks/sdk-names/<type>.json` | Frozen SDK builder names, one file per block type |
| `apps/sim/app/workspace/**/panel/components/code/` | The read-only Code tab |

Public docs live in `apps/docs/content/docs/workflows/code/`. The exit-code, diagnostic-code, limit
and per-kind layout tables of `exit-codes.mdx`, `diagnostics.mdx`, `limits.mdx` and `directory.mdx` sit between
`workflow-code-docs` markers and come from their owners (`source-exit-codes.ts`, SYNTAX.md and `workspace-code`'s
`diagnostics/codes.ts` TSDoc, the `*_LIMITS` constants, `WORKSPACE_KIND_SPECS`): edit the owner, then run
`bun run generate:workflow-code-docs` (`check:workflow-code-docs` fails on drift, a diagnostic code a page names that
no engine emits, a limit or diagnostic code with no docs entry, and a `typescript@x.y.z` pin other than the CLI's).
A limit also needs a label in the generator's `WORKFLOW_LIMIT_LABELS` or `WORKSPACE_LIMIT_LABELS`.

Dependencies point one way: `packages/workflow-types` → `packages/workflow-code` →
`packages/workspace-code` and `packages/workflow-sdk` → the CLI and `apps/sim`. `check:boundaries` keeps both engines and `packages/table-cells` pure (no
Node built-ins, `eval`, `globalThis`, dynamic import): they run in the browser, the CLI and the
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/content/docs/cli/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ sim tables rows query --help
| [`workflow-mcp-servers`](/cli/workflow-mcp-servers) | Expose deployed workflows as MCP tools |
| [`meta`](/cli/meta) | Inspect API availability and credential status |

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

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.

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

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

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

## Related docs

Expand Down
111 changes: 4 additions & 107 deletions apps/docs/content/docs/cli/scripting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -165,61 +165,7 @@ The CLI resends a request the API answers `429` only when sending it twice is sa
| `3` | Committed operation requires configuration |
| `4` | Wait timed out |

| Code | `sim workflows source apply` or `create` |
| --- | --- |
| `0` | Applied or created, or a dry run with no errors |
| `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 |
| `5` | The workflow changed since the directory was read (`409 SOURCE_STALE`): get it again, reapply the edit, and retry |
| `6` | The workflow or its folder is locked (`423`, `E_APPLY_LOCKED`); a locked block exits `1` (`E_APPLY_LOCKED_BLOCK`) |
| `7` | The source is over the size limits (`413`) |
| `9` | Still rate limited (`429`) after the CLI's retries; nothing was written |
| `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 |
| `13` | `AUTH_REQUIRED`: not logged in, or the server refused the credential; nothing was sent |
| `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` |
| `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 |

| Code | `sim workflows source status` or `sim workspaces source status` |
| --- | --- |
| `0` | Clean: nothing to apply, and the server changed nothing since the directory was read |
| `1` | Command/request failure |
| `7` | The source is too large for the server to read in one dry run |
| `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 |
| `11` | Local changes only: applying writes them |
| `12` | The server changed since the directory was read (drift, or a conflict with local changes) |
| `13` | `AUTH_REQUIRED`: not logged in, or the server refused the credential; the local changes are still shown |

| Code | `sim workflows source check` or `sim workspaces source check` |
| --- | --- |
| `0` | No errors (warnings may still print) |
| `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 |
| `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 |

| Code | `sim workflows source get --dir` or `sim workspaces source get` |
| --- | --- |
| `0` | Written |
| `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 |
| `7` | The workflow, or a kind of resource, is too large for one directory |
| `9` | Still rate limited (`429`) after the CLI's retries; nothing was written |
| `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 |
| `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 |
| `130` | Interrupted (Ctrl-C): run the get again |

| Code | `sim workspaces source apply` |
| --- | --- |
| `0` | Applied, or a dry run with no errors |
| `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 |
| `5` | A resource changed since the directory was read (`409 SOURCE_STALE`): get it again into a fresh directory, reapply the edit, and retry |
| `6` | A resource (a workflow or its folder, a table) is locked (`423`); a locked block exits `1` (`E_APPLY_LOCKED_BLOCK`) |
| `7` | The directory is over the size limits (`413`) |
| `8` | The apply stopped part-way: what was written is saved into the directory; apply again |
| `9` | Still rate limited (`429`) after the CLI's retries; nothing was written |
| `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 |
| `13` | `AUTH_REQUIRED`: not logged in, or the server refused the credential; nothing was sent |
| `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` |
| `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 |
| `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 |

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

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.

Expand Down Expand Up @@ -381,63 +327,14 @@ exit "$status"

## Workspace source in CI

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.

```yaml title=".github/workflows/sim-workspace.yml"
on:
pull_request:
paths: ['workspace/**']
push:
branches: [main]
paths: ['workspace/**']

concurrency: sim-workspace

permissions:
contents: write

jobs:
workspace:
runs-on: ubuntu-latest
env:
SIM_API_KEY: ${{ secrets.SIM_API_KEY }}
SIM_WORKSPACE: ${{ vars.SIM_WORKSPACE }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- uses: oven-sh/setup-bun@v2
- run: bun add -g sim
- run: sim workspaces source check --dir workspace
- run: bunx -p typescript@7.0.2 tsc -p workspace
- run: sim workspaces source apply --dir workspace --dry-run
- if: github.event_name == 'push'
run: sim workspaces source apply --dir workspace --yes
- if: ${{ !cancelled() && github.event_name == 'push' }}
run: |
git add -A workspace
if ! git diff --cached --quiet; then
git -c user.name=sim-bot -c user.email=sim-bot@users.noreply.github.com \
commit -m "chore(workspace): files the apply rewrote [skip ci]"
git push
fi
```

`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.

To promote the same directory to a second workspace, add a step with `--to` before the step that commits the files back:

```bash
sim workspaces source apply --dir workspace --to "$PROD_WORKSPACE_ID" --yes
```

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

## Related docs

- [Output formats](/cli/output)
- [Workflow commands](/cli/workflows)
- [Workflows as code: run in CI](/workflows/code/ci)
- [Workflows as code: exit codes](/workflows/code/exit-codes)
- [Workflow imports and workspace sync](/cli/workflow-sync)
- [Organization commands](/cli/organizations)
- [Troubleshooting](/cli/troubleshooting)
2 changes: 1 addition & 1 deletion apps/docs/content/docs/cli/workflows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ sim workflows mkdir <path>

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

## Other commands
## Workflows as code

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

Expand Down
1 change: 1 addition & 0 deletions apps/docs/content/docs/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"---Build---",
"chat",
"workflows",
"workflows/code",
"agents",
"---Workspace---",
"knowledgebase",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ Plain JavaScript without imports runs in isolated-vm within Node child workers i

| Variable | Description |
|----------|-------------|
| `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` |
| `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` |

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

Expand Down
Loading
Loading