Skip to content
5 changes: 4 additions & 1 deletion apps/docs/content/docs/cli/reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8622,6 +8622,7 @@ sim workflows source get <workflowId> [options]
| `--function-code <value>` | No | Where function-block code goes: `files` (default) writes it to `functions/*` files referenced with `codeFile()`; `inline` prints it in tagged templates. Accepted values: `inline`, `files`. |
| `--dir <dir>` | No | Write the source, its lock and SDK type declarations into this directory instead of printing them. |
| `--force` | No | With --dir: replace another workflow's source or edits no apply has saved. |
| `--primer` | No | Also print the primer written atop .sim/AGENTS.md (a `primer` field in JSON). |

</CommandTable>

Expand Down Expand Up @@ -8809,10 +8810,11 @@ sim workflows source params <builder> [options]
| Option | Required | Description |
| --- | --- | --- |
| `--dir <dir>` | No | Source directory whose catalog to read. Defaults to `.`. |
| `--full` | No | Print every param with its type, enum, default and doc, not the brief form. |

</CommandTable>

Prints a builder's params (required first, with enums and defaults), the gate field that picks which others apply, and its outputs, from the block catalog the last get, create or check cached. No request is made. &lt;builder&gt; is the dotted builder path as source writes it: table.upsertRow, agent, trigger.schedule, slack.sendMessage (slack.tool.sendMessage names the same builder). A namespace (gmail, trigger.gmail) lists its builders; a block type prints the builder written for it (function is fn) or lists them (table_v2); a construct core.d.ts declares (loop, parallel, t, env) prints its declaration. Run it from a workflow or workspace source directory, or pass --dir.
Prints a builder in brief (an example call, the required params with types, the optional ones by name, the gate field that picks which others apply, and the outputs), from the block catalog the last get, create or check cached. --full prints every param with its type, enum, default and doc. A legacy builder names the one that replaces it. No request is made. &lt;builder&gt; is the dotted builder path as source writes it: table.upsertRow, agent, trigger.schedule, slack.sendMessage (slack.tool.sendMessage names the same builder). A namespace (gmail, trigger.gmail) lists its builders; a block type prints the builder written for it (function is fn) or lists them (table_v2); a construct core.d.ts declares (loop, parallel, t, env) prints its declaration. Run it from a workflow or workspace source directory, or pass --dir.

Exit codes: 0 printed; 1 no builder or namespace of that name (the closest one is named), or no cached catalog (run a get once).

Expand Down Expand Up @@ -10035,6 +10037,7 @@ sim workspaces source get [options]

| Option | Required | Description |
| --- | --- | --- |
| `--primer` | No | Also print the primer written atop .sim/AGENTS.md (a `primer` field in JSON). |
| `--dir <dir>` | Yes | Directory to write the workspace source into. |
| `--only <kinds>` | No | Read only these kinds (comma-separated folders: secrets.ts, credentials.ts, tools, skills, mcp, tables, knowledge, files, workflows, deployments). |
| `--force` | No | Replace files with edits no apply has saved. |
Expand Down
4 changes: 3 additions & 1 deletion apps/docs/content/docs/cli/workflows.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,7 @@ sim workflows source get <workflowId> [options]
| `--function-code <value>` | No | Where function-block code goes: `files` (default) writes it to `functions/*` files referenced with `codeFile()`; `inline` prints it in tagged templates. Accepted values: `inline`, `files`. |
| `--dir <dir>` | No | Write the source, its lock and SDK type declarations into this directory instead of printing them. |
| `--force` | No | With --dir: replace another workflow's source or edits no apply has saved. |
| `--primer` | No | Also print the primer written atop .sim/AGENTS.md (a `primer` field in JSON). |

</CommandTable>

Expand Down Expand Up @@ -1574,10 +1575,11 @@ sim workflows source params <builder> [options]
| Option | Required | Description |
| --- | --- | --- |
| `--dir <dir>` | No | Source directory whose catalog to read. Defaults to `.`. |
| `--full` | No | Print every param with its type, enum, default and doc, not the brief form. |

</CommandTable>

Prints a builder's params (required first, with enums and defaults), the gate field that picks which others apply, and its outputs, from the block catalog the last get, create or check cached. No request is made. &lt;builder&gt; is the dotted builder path as source writes it: table.upsertRow, agent, trigger.schedule, slack.sendMessage (slack.tool.sendMessage names the same builder). A namespace (gmail, trigger.gmail) lists its builders; a block type prints the builder written for it (function is fn) or lists them (table_v2); a construct core.d.ts declares (loop, parallel, t, env) prints its declaration. Run it from a workflow or workspace source directory, or pass --dir.
Prints a builder in brief (an example call, the required params with types, the optional ones by name, the gate field that picks which others apply, and the outputs), from the block catalog the last get, create or check cached. --full prints every param with its type, enum, default and doc. A legacy builder names the one that replaces it. No request is made. &lt;builder&gt; is the dotted builder path as source writes it: table.upsertRow, agent, trigger.schedule, slack.sendMessage (slack.tool.sendMessage names the same builder). A namespace (gmail, trigger.gmail) lists its builders; a block type prints the builder written for it (function is fn) or lists them (table_v2); a construct core.d.ts declares (loop, parallel, t, env) prints its declaration. Run it from a workflow or workspace source directory, or pass --dir.

Exit codes: 0 printed; 1 no builder or namespace of that name (the closest one is named), or no cached catalog (run a get once).

Expand Down
1 change: 1 addition & 0 deletions apps/docs/content/docs/cli/workspaces.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ sim workspaces source get [options]

| Option | Required | Description |
| --- | --- | --- |
| `--primer` | No | Also print the primer written atop .sim/AGENTS.md (a `primer` field in JSON). |
| `--dir <dir>` | Yes | Directory to write the workspace source into. |
| `--only <kinds>` | No | Read only these kinds (comma-separated folders: secrets.ts, credentials.ts, tools, skills, mcp, tables, knowledge, files, workflows, deployments). |
| `--force` | No | Replace files with edits no apply has saved. |
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/content/docs/workflows/code/coding-agents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Claude Code, Cursor, Codex and other coding agents work from a directory that `g

## What get gives an agent

- A **primer**: `get` prints it (in JSON output, its `primer` field), and it opens `.sim/AGENTS.md`. It covers the edit loop, how block identity, references and renames work, failures and retries, test runs, deletes, deploy, exit codes, and the params of each builder the workflow already uses.
- A **primer**, which opens `.sim/AGENTS.md`. `get` prints a short summary instead (the files written, the guide, and the `editLoop` commands to run); `get --primer` also prints the primer (in JSON output, its `primer` field). It covers the edit loop, how block identity, references and renames work, failures and retries, test runs, deletes, deploy, exit codes, and the params of each builder the workflow already uses.
- **`.sim/AGENTS.md`**: the primer followed by a reference, by task. A workspace directory also gets `.sim/GUIDE-advanced.md`.
- **`.sim/examples/`**: one correct example of each common block to copy from.
- **`.sim/sdk/`**: the type declarations, with `.sim/sdk/INDEX.md` listing the builders.
Expand All @@ -26,7 +26,7 @@ For a whole workspace, use `sim workspaces source` with the same steps; see [Man

## Look things up

- `sim workflows source params <builder>` prints a builder's params and outputs from the cached block catalog without a request. A namespace such as `gmail` lists its builders.
- `sim workflows source params <builder>` prints a builder in brief (an example call, the required params with types, the optional ones by name and the outputs) from the cached block catalog without a request. `--full` prints every param with its type, options, default and doc. A legacy builder names the one that replaces it, and a namespace such as `gmail` lists its builders.
- `sim workflows source resources` lists the tables, knowledge bases, credentials, workflows, skills, custom tools, MCP servers and environment variable names the file can name.
- `sim workflows source catalog` shows the block catalog the source is checked against.

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/workflows/code/directory.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ description: Every file a workflow directory and a workspace directory holds, wh
| `.sim/written.json` | A digest of each file as the CLI last wrote it, so `status` and `get` tell your edits from the CLI's | Commit |
| `.sim/stored-edges.json` | The connections the stored workflow held when it was printed, so an offline `check` tells them from connections you added. The CLI's own record, never sent | Commit |
| `.sim/starter.json` | The workspace a starter was written for, before `create` | Not kept: removed once the workflow exists |
| `.sim/AGENTS.md` | The guide for coding agents: the primer `get` prints, then a reference | Optional, written again by `get` |
| `.sim/AGENTS.md` | The guide for coding agents: the primer, then a reference | Optional, written again by `get` |
| `.sim/examples/` | Example workflows to copy from | Optional, written again by `get` |
| `.sim/sdk/` | Type declarations for the blocks the workflow uses, and your workspace's tables, credentials, knowledge bases and environment variable names. `.sim/sdk/INDEX.md` lists the builders | Optional, written again by `get` and `check` |
| `tsconfig.json` | Resolves the declarations and type-checks the blocks the workflow uses. Left as it is if you already have one | Commit |
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/workflows/code/edit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This writes `workflow.ts`, any function code under `functions/`, type declaratio

`get` into a directory that already holds source refuses to overwrite edits you have not applied, and refuses a directory that holds a different workflow. Pass `--force` to replace them. A workspace directory is always refused, `--force` included.

To write a block the workflow does not use yet, `sim workflows source params <builder>` (for example `table.upsertRow` or `trigger.schedule`) prints its params, required ones first with their options and defaults, and its outputs, from the cached block catalog without a request. A namespace such as `gmail` lists its builders.
To write a block the workflow does not use yet, `sim workflows source params <builder>` (for example `table.upsertRow` or `trigger.schedule`) prints an example call, its required params with their types, its optional params by name and its outputs, from the cached block catalog without a request (`--full` adds every param's options, default and doc). A namespace such as `gmail` lists its builders.

## 2. Edit and check

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/workflows/code/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sim workflows source apply --dir ./support-triage --yes

## For coding agents [#for-coding-agents]

Claude Code, Cursor, Codex and other coding agents work from a directory that `get` writes. `get` prints a primer and writes the full guide to `.sim/AGENTS.md`. See [Use with coding agents](/workflows/code/coding-agents).
Claude Code, Cursor, Codex and other coding agents work from a directory that `get` writes. `get` prints a summary with the edit loop and writes the primer and full guide to `.sim/AGENTS.md`. See [Use with coding agents](/workflows/code/coding-agents).

## Related docs

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/workflows/code/syntax.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ A secret is never printed. A literal value in a password field prints as `stored

### JSON fields

A field that holds JSON text, such as `responseFormat`, a table row's `data` or a response body, takes an object or array literal and stores it as formatted JSON. Each bare reference inside is quoted when the output is a string and left bare otherwise, because the run splices a string raw and any other value as JSON. A reference no output type is known for is stored bare with `W_JSON_REF_UNTYPED`. A template is a JSON string, which is how a value becomes text on purpose. A resource helper inside the literal is `E_UNSUPPORTED_SYNTAX`.
A field that holds JSON text, such as `responseFormat`, a table row's `data` or a response body, takes an object or array literal and stores it as formatted JSON. Each bare reference inside is quoted when the output is a string and left bare otherwise, because the run splices a string raw and any other value as JSON. A field of a Function's `result` has the type its JavaScript certainly returns there (a string literal, `String(…)`, `.toISOString().slice(…)` and the like are text; arithmetic, comparisons and literals are not). A reference no output type is known for is stored bare with `W_JSON_REF_UNTYPED`. A template is a JSON string, which is how a value becomes text on purpose. A resource helper inside the literal is `E_UNSUPPORTED_SYNTAX`.

### Input formats and tools

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/workflows/code/workspace.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const log = table.insertRow('Log Question', {
})
```

`get` prints a short primer for coding agents (in JSON output, its `primer` field) and writes it atop `.sim/AGENTS.md`, the guide, with deletes in depth, Git and CI, and promoting to another workspace in `.sim/GUIDE-advanced.md`. It also writes `.sim/examples/workspace/`, a complete example of every kind and the workflow that uses them.
`get` writes a short primer for coding agents atop `.sim/AGENTS.md` (`get --primer` also prints it, in JSON output as its `primer` field), the guide, with deletes in depth, Git and CI, and promoting to another workspace in `.sim/GUIDE-advanced.md`. It also writes `.sim/examples/workspace/`, a complete example of every kind and the workflow that uses them.

## Edit a workspace

Expand Down
34 changes: 30 additions & 4 deletions packages/sim-cli/src/commands/protocol/source-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ import {
SDK_MAJOR,
SDK_MODELS_FILE,
sdkIndexHeader,
typecheckCommand,
type WorkspaceManifest,
} from '@sim/workflow-sdk/codegen'
import type { Command } from 'commander'
import { printError, printLine } from '#sim-cli/output/io'
import type { OutputFormat } from '../../config/index'
import { readJsonFile, writeJsonFile } from '../../config/json-file'
Expand All @@ -55,6 +57,7 @@ import {
withMissingLines,
} from './source-dir'
import { AGENTS_POINTER_MARKER, agentsPointer, type PrimerKind, primerFor } from './source-primer'
import { shellWord } from './source-ui'

const TSCONFIG_FILE = 'tsconfig.json'
/** Where agents look first: the nearest `AGENTS.md` above the file they edit. */
Expand Down Expand Up @@ -572,20 +575,43 @@ export function finishTree(
}

/**
* Prints a tree write's result: in JSON or YAML one document with the primer as its `primer`
* field, otherwise the fields and then the primer as text, so it reads as written.
* Prints a tree write's result: the fields, then the primer as text when the result carries one
* (in JSON or YAML it is the document's `primer` field). A get leaves the primer out unless
* `--primer` asks for it: it is already the top of `.sim/AGENTS.md`.
*/
export function printTreeResult(
format: OutputFormat,
result: Record<string, unknown> & { primer: string }
result: Record<string, unknown> & { primer?: string }
): void {
if (format === 'json' || format === 'yaml') {
printProtocolResult(format, result)
return
}
const { primer, ...fields } = result
printProtocolResult(format, fields)
printLine(`\n${primer}`)
if (primer !== undefined) printLine(`\n${primer}`)
}

/** Adds `--primer` to a get command: it prints the primer the get writes atop `.sim/AGENTS.md`. */
export function primerOption(command: Command): void {
command.option(
'--primer',
'Also print the primer written atop .sim/AGENTS.md (a `primer` field in JSON)'
)
}

/**
* The commands of a directory's edit loop, in order, for a get's result: what the primer's loop
* says, runnable from anywhere because each names the directory.
*/
export function editLoop(kind: PrimerKind, dir: string): string[] {
const group = kind === 'workflow' ? 'sim workflows source' : 'sim workspaces source'
const at = shellWord(dir)
return [
`${group} check --dir ${at}`,
typecheckCommand(at),
`${group} apply --dir ${at} --dry-run`,
]
}

/** What a directory's editable tree holds beside the printed source. */
Expand Down
21 changes: 17 additions & 4 deletions packages/sim-cli/src/commands/protocol/workflow-source-get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,31 @@ describe('sim workflows source get --dir', () => {
expect(callsTo(CATALOG_PATH)[0][1].query).toBeUndefined()
})

it('prints the primer, which opens the guide, with a snippet for each builder the source calls and no other', async () => {
it('writes the primer atop the guide with a snippet for each builder the source calls and no other, printing it only with --primer', async () => {
serve({
[SOURCE_PATH]: () =>
source({ 'workflow.ts': "// @sim-sdk 1\nconst mail = gmail.sendEmail('Mail', {})\n" }),
})

await get('--dir', outDir)

const printed = JSON.parse(vi.mocked(console.log).mock.calls.at(-1)?.join(' ') ?? '{}')
expect(printed).not.toHaveProperty('primer')
expect(printed.guide).toBe('.sim/AGENTS.md')
expect(printed.editLoop).toEqual([
expect.stringMatching(/^sim workflows source check --dir /),
expect.stringMatching(/^bunx -p typescript@[\d.]+ tsc -p /),
expect.stringMatching(/^sim workflows source apply --dir .* --dry-run$/),
])
const agents = readFileSync(join(outDir, '.sim/AGENTS.md'), 'utf8')
expect(agents).toContain('- `gmail.sendEmail` (Gmail: Send Email)')
expect(agents).not.toContain('`slack.sendMessage`')

vi.mocked(console.log).mockClear()
await get('--dir', outDir, '--primer')

const { primer } = JSON.parse(vi.mocked(console.log).mock.calls.at(-1)?.join(' ') ?? '{}')
expect(readFileSync(join(outDir, '.sim/AGENTS.md'), 'utf8').startsWith(primer)).toBe(true)
expect(primer).toContain('- `gmail.sendEmail` (Gmail: Send Email)')
expect(primer).not.toContain('`slack.sendMessage`')
expect(agents.startsWith(primer)).toBe(true)
})

it('writes a root AGENTS.md pointing at the guide, and never replaces one it did not write', async () => {
Expand Down
Loading
Loading