Skip to content

Commit 487c06f

Browse files
committed
chore(workflow-code): print the source primers for the mothership skill; promote-record and lock-layout docs match the code
1 parent 573b219 commit 487c06f

5 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎apps/docs/content/docs/workflows/code/how-it-works.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The stored workflow and the file are two views of one canonical form, so a round
3131

3232
Some state has no syntax in the file. Sim keeps it from the stored workflow on every apply:
3333

34-
- **Layout.** Block positions stay in Sim. A new block is placed automatically. Moving blocks never makes a directory stale.
34+
- **Layout.** Block positions stay in Sim. `.sim/lock.json` keeps a copy, used only to place a block the target does not hold yet (a promotion or a fresh create); a new block is placed automatically. Moving blocks never makes a directory stale.
3535
- **Settings that do not run.** A value in a field that the block's current choices hide stays stored, so switching back in the workflow builder brings it back.
3636
- **Comments.** Comments in `workflow.ts` are stored with the workflow, by block, so a builder edit or a rename keeps them.
3737

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Prints the workflow and workspace source primers as JSON, for the mothership worker's
3+
* `workflow-source` skill. The text is the one `sim workflows source get` and `sim workspaces
4+
* source get` write atop `.sim/AGENTS.md`, so the agent's preloaded guide never differs from the
5+
* one the CLI gives a coding agent.
6+
*
7+
* bun run packages/sim-cli/scripts/print-source-primers.ts > primers.json
8+
*/
9+
import { type PrimerKind, sourcePrimer } from '#sim-cli/commands/protocol/source-primer'
10+
11+
const KINDS: readonly PrimerKind[] = ['workflow', 'workspace']
12+
13+
const primers = Object.fromEntries(KINDS.map((kind) => [kind, sourcePrimer(kind)]))
14+
15+
process.stdout.write(`${JSON.stringify(primers, null, 2)}\n`)

‎packages/sim-cli/src/commands/protocol/source-primer.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ Exit codes: 0 ok, 1 errors, ${SOURCE_STALE_EXIT_CODE} stale (get a fresh copy an
9999
`
100100
}
101101

102-
/** The primer for a `kind` directory, without builder snippets. */
102+
/**
103+
* The primer for a `kind` directory, without builder snippets. The mothership worker preloads the
104+
* same text as its `workflow-source` skill (`scripts/print-source-primers.ts`), so an edit here
105+
* shows up as worker drift until the next grammar sync.
106+
*/
103107
export function sourcePrimer(kind: PrimerKind): string {
104108
return kind === 'workflow' ? WORKFLOW_PRIMER : WORKSPACE_PRIMER
105109
}

‎packages/sim-cli/src/commands/protocol/workspace-source-dir.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ const ADVANCED_GUIDE = `# Sim workspace source: advanced
196196
197197
## Promote to another workspace
198198
199-
\`sim workspaces source apply --dir . --to <workspaceId> --dry-run\`, then \`--yes\`: applies this directory to another workspace (dev to prod). Each resource binds by key to the target's own: one the target holds under the same key is updated in place (a workflow keeps its id and block ids, so its webhook URLs), a key it lacks is created (or adopts a resource of the same name). Each promote records what it left in the target in \`.sim/targets/<workspaceId>.json\` (commit it), and the next promote compares with that: a resource changed in the target since is kept when this directory left it alone, and refused as stale (exit ${SOURCE_STALE_EXIT_CODE}) when this directory changed it too. A resource with no record (the first promote, or one created in the target since) is updated to match this directory; delete the record to take the target as it stands again. Secrets and credentials bind by name and key to the target's own; no value is copied. The target's resources this directory never declared (and no promote left there) are kept with a warning, even with \`--allow-delete\`; deleting them too takes \`--delete-target-only\` beside \`--allow-delete\`. A resource this directory deleted since the last promote is deleted in the target only with \`--allow-delete\`. Before the first promote, set the target's secrets (\`sim secrets set NAME --scope workspace -w <workspaceId>\`) and connect its credentials, or the workflows using them are held back. This directory stays bound to the workspace it was read from. Without \`--to\`, \`check\`, \`status\`, \`diff\` and \`apply\` act on the workspace this directory was read from, whatever the profile's default; a \`--workspace\` or \`SIM_WORKSPACE\` naming another is refused (\`SOURCE_OTHER_WORKSPACE\`). Any other command run in this directory or a folder of it (\`sim tables …\`, \`sim files …\`) acts on that workspace too, unless \`--workspace\` or \`SIM_WORKSPACE\` names another.
199+
\`sim workspaces source apply --dir . --to <workspaceId> --dry-run\`, then \`--yes\`: applies this directory to another workspace (dev to prod). Each resource binds by key to the target's own: one the target holds under the same key is updated in place (a workflow keeps its id and block ids, so its webhook URLs), a key it lacks is created (or adopts a resource of the same name). Each promote records what it left in the target in \`.sim/targets/<workspaceId>.json\` (commit it), and the next promote compares with that: a resource changed in the target since is kept when this directory left it alone, and refused as stale (exit ${SOURCE_STALE_EXIT_CODE}) when this directory changed it too. A resource with no record (the first promote, or one created in the target since) is updated to match this directory, so deleting the record makes the next promote overwrite every change made in the target since (no stale refusal). Secrets and credentials bind by name and key to the target's own; no value is copied. The target's resources this directory never declared (and no promote left there) are kept with a warning, even with \`--allow-delete\`; deleting them too takes \`--delete-target-only\` beside \`--allow-delete\`. A resource this directory deleted since the last promote is deleted in the target only with \`--allow-delete\`. Before the first promote, set the target's secrets (\`sim secrets set NAME --scope workspace -w <workspaceId>\`) and connect its credentials, or the workflows using them are held back. This directory stays bound to the workspace it was read from. Without \`--to\`, \`check\`, \`status\`, \`diff\` and \`apply\` act on the workspace this directory was read from, whatever the profile's default; a \`--workspace\` or \`SIM_WORKSPACE\` naming another is refused (\`SOURCE_OTHER_WORKSPACE\`). Any other command run in this directory or a folder of it (\`sim tables …\`, \`sim files …\`) acts on that workspace too, unless \`--workspace\` or \`SIM_WORKSPACE\` names another.
200200
`
201201

202202
/** The workspace directory's tree beside the printed source. */

‎packages/workspace-code/src/promote.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ function folderWorkflow(
175175

176176
/**
177177
* Reads a promotion record for `workspaceId`; `undefined` for anything else (no record, another
178-
* target's, an unreadable one), which makes the promotion take the target as it stands.
178+
* target's, an unreadable one): the promotion then has no baseline, so it updates every resource
179+
* to match the directory and refuses none as stale.
179180
*/
180181
export function parsePromotionRecord(
181182
input: unknown,

0 commit comments

Comments
 (0)