Skip to content

Commit a34de41

Browse files
committed
docs(workflows): drift job fails when Sim was not checked, fork note for stored values, generator ignores generated regions
1 parent 633be83 commit a34de41

6 files changed

Lines changed: 23 additions & 17 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ Public docs live in `apps/docs/content/docs/workflows/code/`. The exit-code, dia
5252
and per-kind layout tables of `exit-codes.mdx`, `diagnostics.mdx`, `limits.mdx` and `directory.mdx` sit between
5353
`workflow-code-docs` markers and come from their owners (`source-exit-codes.ts`, SYNTAX.md and `workspace-code`'s
5454
`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 code a page names that no
56-
engine emits, a limit or code with no docs entry, and a `typescript@x.y.z` pin other than the CLI's).
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`.
5758

5859
Dependencies point one way: `packages/workflow-types` → `packages/workflow-code` →
5960
`packages/workspace-code` and `packages/workflow-sdk` → the CLI and `apps/sim`. `check:boundaries` keeps both engines and `packages/table-cells` pure (no

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ Public docs live in `apps/docs/content/docs/workflows/code/`. The exit-code, dia
3232
and per-kind layout tables of `exit-codes.mdx`, `diagnostics.mdx`, `limits.mdx` and `directory.mdx` sit between
3333
`workflow-code-docs` markers and come from their owners (`source-exit-codes.ts`, SYNTAX.md and `workspace-code`'s
3434
`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 code a page names that no
36-
engine emits, a limit or code with no docs entry, and a `typescript@x.y.z` pin other than the CLI's).
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`.
3738

3839
Dependencies point one way: `packages/workflow-types` → `packages/workflow-code` →
3940
`packages/workspace-code` and `packages/workflow-sdk` → the CLI and `apps/sim`. `check:boundaries` keeps both engines and `packages/table-cells` pure (no

‎apps/docs/content/docs/workflows/code/ci.mdx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ jobs:
140140
- run: bun add -g sim
141141
- run: |
142142
status=0
143-
sim workspaces source status --dir workspace || status=$?
143+
sim workspaces source status --dir workspace --output json > status.json || status=$?
144+
if [ "$status" -eq 0 ] || [ "$status" -eq 11 ] || [ "$status" -eq 12 ]; then
145+
[ "$(jq -r .server status.json)" = checked ] || { echo "Sim was not checked: $(jq -r .note status.json)"; exit 1; }
146+
fi
144147
case "$status" in
145148
0) exit 0 ;;
146149
11|12) ;;
@@ -157,7 +160,7 @@ jobs:
157160
fi
158161
```
159162

160-
To bring the change into git instead, run `sim workspaces source get --dir workspace` on a new branch and open a pull request.
163+
`status` exits `0` or `11` without asking Sim when the server is unreachable, so the job reads the `server` field of its JSON output and fails unless it is `checked`. To bring the change into git instead, run `sim workspaces source get --dir workspace` on a new branch and open a pull request.
161164

162165
### Promote in CI
163166

‎apps/docs/content/docs/workflows/code/create.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ If another workflow already has that name, the command exits `1` with `SOURCE_NA
3232

3333
## Fork a workflow
3434

35-
Copy its directory, delete the copy's `.sim/`, and create it under a new name:
35+
Copy its directory, delete the copy's `.sim/`, and create it under a new name. A copy has no stored workflow to take a saved secret from, so replace each `stored()` in the file, which `get` printed for a value it does not show, with `env.NAME` or the value; otherwise the create fails with `E_STORED_VALUE_MISSING`.
3636

3737
```bash
3838
sim workflows source create --dir ./copy --workspace <workspaceId> --name "New name" --yes

‎apps/docs/content/docs/workflows/code/directory.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ A resource's key is its file or folder name, and a workflow names it by that key
6262
- `knowledge/<key>/knowledge.ts` (`defineKnowledgeBase({ name, description?, folder?, chunking?, embeddingModel? })`) and `knowledge/<key>/docs/`, one file per document, flat. A workflow: `knowledgeBase('<key>')`. Connector-synced documents are never part of source.
6363
- `files/<path>`: every file is one workspace file at that folder path; no declaration.
6464
- `workflows/<key>/`: one workflow each, exactly a `sim workflows source get --dir` directory (`workflow.ts`, `functions/*`, `.sim/lock.json`, `.sim/base.json`).
65-
- `deployments/<workflow key>.ts`: `defineDeployment({ live: 'draft' \| 'pinned', api?: { public? }, chat? })` deploys `workflows/<workflow key>/`, so its schedule, webhook, API and chat triggers run. `live: 'draft'` publishes the draft whenever it differs from the live version; `'pinned'` never redeploys and says when the draft differs. A chat password is `env.NAME` (or `stored()` to keep the stored one); chat outputs name a block by its name. Removing the file undeploys the workflow (needs `--allow-delete`). Deploying needs workspace admin, never a workspace API key. MCP publishing is not part of source.
65+
- `deployments/<workflow key>.ts`: `defineDeployment({ live: 'draft' | 'pinned', api?: { public? }, chat? })` deploys `workflows/<workflow key>/`, so its schedule, webhook, API and chat triggers run. `live: 'draft'` publishes the draft whenever it differs from the live version; `'pinned'` never redeploys and says when the draft differs. A chat password is `env.NAME` (or `stored()` to keep the stored one); chat outputs name a block by its name. Removing the file undeploys the workflow (needs `--allow-delete`). Deploying needs workspace admin, never a workspace API key. MCP publishing is not part of source.
6666

6767
{/* workflow-code-docs:directory-kinds:end */}
6868

‎scripts/sync-workflow-code-docs.ts‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,14 @@ const beginMarker = (region: Region) =>
5757
`{/* workflow-code-docs:${region}:begin — generated by \`bun run generate:workflow-code-docs\`; do not edit between markers */}`
5858
const endMarker = (region: Region) => `{/* workflow-code-docs:${region}:end */}`
5959

60-
/** Text safe for MDX prose and a table cell: braces and angle brackets escaped outside code spans. */
60+
/** Text safe for MDX prose: braces and angle brackets escaped outside code spans. */
6161
function mdx(text: string): string {
6262
return text
6363
.split(/(`[^`]*`)/)
6464
.map((part, index) =>
6565
index % 2 === 1
66-
? part.replaceAll('|', '\\|')
67-
: part
68-
.replaceAll('{', '\\{')
69-
.replaceAll('}', '\\}')
70-
.replaceAll('<', '&lt;')
71-
.replaceAll('|', '\\|')
66+
? part
67+
: part.replaceAll('{', '\\{').replaceAll('}', '\\}').replaceAll('<', '&lt;')
7268
)
7369
.join('')
7470
}
@@ -84,7 +80,7 @@ function tsdocText(lines: string[]): string {
8480
}
8581

8682
function cell(text: string): string {
87-
return mdx(text.replaceAll('\n', ' '))
83+
return mdx(text.replaceAll('\n', ' ')).replaceAll('|', '\\|')
8884
}
8985

9086
const indent = (block: string, spaces: number) =>
@@ -461,12 +457,17 @@ function walkMdx(dir: string): string[] {
461457
.map((entry) => path.join(dir, entry))
462458
}
463459

460+
/** A generated region, which the owners already check, so stale rows never block regenerating it. */
461+
const GENERATED_REGION =
462+
/\{\/\* workflow-code-docs:[\w-]+:begin[\s\S]*?\{\/\* workflow-code-docs:[\w-]+:end \*\/\}/g
463+
464464
function checkProse(errors: string[]): void {
465465
const known = new Set<string>([...DIAGNOSTIC_CODES, ...WORKSPACE_DIAGNOSTIC_CODES])
466466
for (const file of walkMdx(PAGES_DIR)) {
467467
const rel = path.relative(rootDir, file)
468468
const text = fs.readFileSync(file, 'utf8')
469-
for (const match of text.matchAll(/`([EWI]_[A-Z0-9_]+)`/g)) {
469+
const prose = text.replace(GENERATED_REGION, '')
470+
for (const match of prose.matchAll(/`([EWI]_[A-Z0-9_]+)`/g)) {
470471
if (!known.has(match[1])) errors.push(`${rel} names ${match[1]}, which no engine emits`)
471472
}
472473
}

0 commit comments

Comments
 (0)