diff --git a/packages/sim-cli/src/commands/protocol/source-primer.ts b/packages/sim-cli/src/commands/protocol/source-primer.ts index d342918e843..abe7f939349 100644 --- a/packages/sim-cli/src/commands/protocol/source-primer.ts +++ b/packages/sim-cli/src/commands/protocol/source-primer.ts @@ -40,13 +40,13 @@ const PARAMS_COMMAND = 'sim workflows source params' /** The rules every source directory shares, after the kind's own edit loop. */ function sharedRules(group: string, extraRenames = ''): string { - return `- **Identity**: a block is its entry in \`${SOURCE_LOCK_FILE}\`, bound by its const or its display name. Rename display names (first argument) or consts, any number per apply: apply rewrites each reference, \`$ref.\` in function files too. Renaming both (one block per apply) keeps it only if settings, neighbours or references still tie it to the old block, else it is a delete (\`E_APPLY_BLOCK_DELETE\`). -- **References**: in \`${SOURCE_ENTRY_FILE}\` read an output as \`x.content\`, a loop or parallel item as \`p.currentItem\` (\`p.index\`), a child's response field as \`c.result.data.\` (typed by its \`response\`), text as \`\` t\`…\` \`\`, env as \`env.NAME\`. In a function file (\`codeFile('./functions/x.js')\`) read an output as \`$ref..\`, the key: the display name lowercased, no whitespace or dots ("Triage Agent" → \`$ref.triageagent.content\`); in a loop body \`$ref.loop.currentItem\` / \`$ref.loop.index\` (a parallel: \`$ref.parallel.…\`); env as \`$env.NAME\`. In \`.py\`/\`.sh\` files write \`\` and \`{{NAME}}\`, not \`$ref\`/\`$env\`. Read an index or item only inside its container (\`E_APPLY_REF_OUT_OF_SCOPE\`), after it its \`.results\`. A \`$ref\` naming no block errors in a function file you edited (\`E_APPLY_UNRESOLVED_REF\`). + return `- **Identity**: a block is its entry in \`${SOURCE_LOCK_FILE}\`, bound by its const or its display name. Rename display names (first argument) or consts, any number per apply, with any other edits: apply rewrites each reference, \`$ref.\` in function files too. Renaming a block's const and its display name together (one such block per apply) keeps it only if settings, neighbours or references still match, else it is a delete (\`E_APPLY_BLOCK_DELETE\`). +- **References**: in \`${SOURCE_ENTRY_FILE}\` read an output as \`x.content\`, a loop or parallel item as \`p.currentItem\` (\`p.index\`), a child call \`runWorkflow('Name', { workflowId: childWorkflow('') })\`'s response field as \`c.result.data.\` (typed by its \`response\`), text as \`\` t\`…\` \`\`, env as \`env.NAME\`. In a function file (\`codeFile('./functions/x.js')\`) read an output as \`$ref..\`, the key: the display name lowercased, no whitespace or dots ("Triage Agent" → \`$ref.triageagent.content\`); in a loop body \`$ref.loop.currentItem\` / \`$ref.loop.index\` (a parallel: \`$ref.parallel.…\`); env as \`$env.NAME\`. In \`.py\`/\`.sh\` files write \`\` and \`{{NAME}}\`, not \`$ref\`/\`$env\`. Read an index or item only inside its container (\`E_APPLY_REF_OUT_OF_SCOPE\`), after it its \`.results\`. A \`$ref\` naming no block errors in a function file you edited (\`E_APPLY_UNRESOLVED_REF\`). - **Renames**: one workflow variable per apply (two at once: delete + add).${extraRenames} -- **Builders**: \`${PARAMS_COMMAND} \` (a namespace lists its builders). +- **Builders**: \`${PARAMS_COMMAND} \` (or a namespace). - **Credentials**: \`sim credentials connect --name ""\`, give the owner its link, then \`credential('')\` (\`sim workflows source resources\`). -- **Failures**: \`x.onError(y)\` runs \`y\` when \`x\` fails, reading the message as \`x.error\` (a Function's \`x.errorMessage\` drops the line and code: reply with it). Retry is block meta (third argument): \`agent('Name', {…}, { retry: { enabled: true, maxTries: 3, waitBetweenTriesMs: 2000 } })\` reruns the block after a failure; an \`api\` block's \`retries\` repeat only the request (timeout, reset, 429, 5xx) inside each try. A reference to a block that did not run is \`null\` (a whole value, function code, a condition) or \`''\` in text. Branches may rejoin before one \`response\` (a function picks the value with \`??\`: \`.sim/examples/cookbook.ts\`); branches that end apart each need one. -- **Run and debug**: \`--manual\` runs the saved draft, without it the deployed version. Runs write real data (rows, emails): use test resources. With \`--dir \`, a failed run names the file and line; then \`sim logs get --trace --no-include-workflow-state\`; rows: \`sim tables rows list \`. +- **Failures**: \`x.onError(y)\` runs \`y\` when \`x\` fails, reading the message as \`x.error\` (a Function's \`x.errorMessage\` drops the line and code: reply with it). Retry is block meta (third argument): \`agent('Name', {…}, { retry: { enabled: true, maxTries: 3, waitBetweenTriesMs: 2000 } })\` reruns a failed block; an \`api\` block's \`retries\` repeat only the request (timeout, reset, 429, 5xx) inside each try. A reference to a block that did not run is \`null\` (a value, function code, a condition) or \`''\` in text. Branches may rejoin before one \`response\` (a function picks the value with \`??\`: \`.sim/examples/cookbook.ts\`); branches that end apart each need one. +- **Run and debug**: \`--manual\` runs the saved draft, without it the deployed version. Runs write real data: use test resources. With \`--dir \`, a failed run names the file and line; then \`sim logs get --trace --no-include-workflow-state\`; rows: \`sim tables rows list
\`. - **Exit codes**: 0 ok, 1 errors, ${SOURCE_STALE_EXIT_CODE} stale (\`${group} get --dir \`, redo the edit there), ${RATE_LIMITED_EXIT_CODE} rate limited, ${SOURCE_BUSY_EXIT_CODE} busy, ${SOURCE_LOCAL_CHANGES_EXIT_CODE}/${SOURCE_DRIFT_EXIT_CODE} \`status\`: your edits / the server changed.` } @@ -54,7 +54,7 @@ const WORKFLOW_PRIMER = `# Sim workflow source: primer \`${SOURCE_ENTRY_FILE}\` is a Sim workflow as TypeScript; the server compiles it statically and nothing in it runs. Run commands here: they read the workflow id from \`${SOURCE_BASE_FILE}\` (a starter has none: \`${SOURCE_STARTER_FILE}\` names its workspace, and its loop ends in \`sim workflows source create --dir . --yes\`, not \`apply\`, which makes the workflow), and each (table commands too) acts on its workspace; source commands refuse a \`-w\` naming another, the rest follow it. -**Edit loop**: write every file, then run one chained command; fix what it reports next: \`sim workflows source check --dir . && sim workflows source apply --dir . --yes && sim workflows run --manual --input '{…}'\`. A non-zero exit stops the chain. \`check\` compiles and type-checks (no separate \`tsc\`). Apply re-checks, so \`apply --dry-run\` is only for review. Apply saves the draft in canonical form: read \`${SOURCE_ENTRY_FILE}\` again before the next edit. +**Edit loop**: write every file, then run one chained command and fix what it reports: \`sim workflows source check --dir . && sim workflows source apply --dir . --yes && sim workflows run --manual --input '{…}'\`. A non-zero exit stops the chain. \`check\` also type-checks (no \`tsc\`). Apply re-checks, so \`apply --dry-run\` is only for review. Apply saves the draft in canonical form: read \`${SOURCE_ENTRY_FILE}\` again before the next edit. - **Deletes**: removing a block or a variable needs \`apply --allow-delete\` (\`E_APPLY_BLOCK_DELETE\` / \`E_APPLY_VARIABLE_DELETE\`). - **Deploy**: apply saves a draft; \`apply --deploy\` also deploys it, or \`sim workflows deploy \` publishes the saved draft later. @@ -63,16 +63,16 @@ ${sharedRules('sim workflows source')} /** What a rename in a workspace directory rewrites beyond a workflow's own blocks. */ const WORKSPACE_RENAMES = - " A column or file: change its \`name\`, keep its key (cells stay; a file's never changes: \`E_KEY_RENAMED\`). Table blocks (\`data\`, \`conflictColumn\`, filters) use the column name, not the key, and keep old names (\`W_TABLE_COLUMN_RENAMED_IN_USE\`)." + " A column or file: change its \`name\`, keep its key (cells stay; a file's never changes: \`E_KEY_RENAMED\`). Table blocks (\`data\`, \`conflictColumn\`, filters) use column names and keep old ones (\`W_TABLE_COLUMN_RENAMED_IN_USE\`)." const WORKSPACE_PRIMER = `# Sim workspace source: primer -This directory is a Sim workspace as files (\`tables/\`, \`workflows//\`); nothing here runs. Run commands here: each (table commands too) acts on the workspace \`${SOURCE_BASE_FILE}\` names; source commands refuse a \`-w\` naming another, the rest follow it. Every \`.ts\` file starts with \`// @sim-sdk ${SDK_MAJOR}\`. +A Sim workspace as files (\`tables/\`, \`workflows//\`); nothing here runs. Run commands here: each (table commands too) acts on the workspace \`${SOURCE_BASE_FILE}\` names; source commands refuse a \`-w\` naming another, the rest follow it. Every \`.ts\` file starts with \`// @sim-sdk ${SDK_MAJOR}\`. -**Edit loop**: write every file, then run one chained command; fix what it reports next: \`sim workspaces source check --dir . && sim workspaces source apply --dir . --yes\`; test with \`sim workflows run --manual --input '{…}'\`. \`check\` compiles and type-checks (no separate \`tsc\`). Apply re-checks, so \`apply --dry-run\` is only for review. Apply rewrites files: reread one before editing it. +**Edit loop**: write every file, then run one chained command and fix what it reports: \`sim workspaces source check --dir . && sim workspaces source apply --dir . --yes\`; test with \`sim workflows run --manual --input '{…}'\`. \`check\` also type-checks (no \`tsc\`). Apply re-checks, so \`apply --dry-run\` is only for review. Apply rewrites files: reread before editing. - **Deletes**: removing a file, folder, column, block or variable needs \`apply --allow-delete\` and is permanent. -- **Deploy**: \`deployments/.ts\` (\`defineDeployment({ live: 'draft' })\`) deploys it on apply; without one, apply never deploys. +- **Deploy**: \`deployments/.ts\` (\`defineDeployment({ live: 'draft' })\`) deploys it on apply; without one, no deploy. - **Exit ${SOURCE_HELD_EXIT_CODE}**: partly written; changes needing an unset secret or unbound credential were held: set it, apply again. ${sharedRules('sim workspaces source', WORKSPACE_RENAMES)} `