Skip to content

Commit 05c8216

Browse files
authored
improvement(workflow-code): lean agent path for source get, params and help, and typed Function results in JSON fields (#10335)
1 parent 161199a commit 05c8216

27 files changed

Lines changed: 514 additions & 69 deletions

‎apps/docs/content/docs/cli/reference.mdx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8622,6 +8622,7 @@ sim workflows source get <workflowId> [options]
86228622
| `--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`. |
86238623
| `--dir <dir>` | No | Write the source, its lock and SDK type declarations into this directory instead of printing them. |
86248624
| `--force` | No | With --dir: replace another workflow's source or edits no apply has saved. |
8625+
| `--primer` | No | Also print the primer written atop .sim/AGENTS.md (a `primer` field in JSON). |
86258626

86268627
</CommandTable>
86278628

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

88138815
</CommandTable>
88148816

8815-
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.
8817+
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.
88168818

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

@@ -10035,6 +10037,7 @@ sim workspaces source get [options]
1003510037

1003610038
| Option | Required | Description |
1003710039
| --- | --- | --- |
10040+
| `--primer` | No | Also print the primer written atop .sim/AGENTS.md (a `primer` field in JSON). |
1003810041
| `--dir <dir>` | Yes | Directory to write the workspace source into. |
1003910042
| `--only <kinds>` | No | Read only these kinds (comma-separated folders: secrets.ts, credentials.ts, tools, skills, mcp, tables, knowledge, files, workflows, deployments). |
1004010043
| `--force` | No | Replace files with edits no apply has saved. |

‎apps/docs/content/docs/cli/workflows.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,7 @@ sim workflows source get <workflowId> [options]
13791379
| `--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`. |
13801380
| `--dir <dir>` | No | Write the source, its lock and SDK type declarations into this directory instead of printing them. |
13811381
| `--force` | No | With --dir: replace another workflow's source or edits no apply has saved. |
1382+
| `--primer` | No | Also print the primer written atop .sim/AGENTS.md (a `primer` field in JSON). |
13821383

13831384
</CommandTable>
13841385

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

15781580
</CommandTable>
15791581

1580-
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.
1582+
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.
15811583

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

‎apps/docs/content/docs/cli/workspaces.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ sim workspaces source get [options]
700700

701701
| Option | Required | Description |
702702
| --- | --- | --- |
703+
| `--primer` | No | Also print the primer written atop .sim/AGENTS.md (a `primer` field in JSON). |
703704
| `--dir <dir>` | Yes | Directory to write the workspace source into. |
704705
| `--only <kinds>` | No | Read only these kinds (comma-separated folders: secrets.ts, credentials.ts, tools, skills, mcp, tables, knowledge, files, workflows, deployments). |
705706
| `--force` | No | Replace files with edits no apply has saved. |

‎apps/docs/content/docs/workflows/code/coding-agents.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Claude Code, Cursor, Codex and other coding agents work from a directory that `g
77

88
## What get gives an agent
99

10-
- 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.
10+
- 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.
1111
- **`.sim/AGENTS.md`**: the primer followed by a reference, by task. A workspace directory also gets `.sim/GUIDE-advanced.md`.
1212
- **`.sim/examples/`**: one correct example of each common block to copy from.
1313
- **`.sim/sdk/`**: the type declarations, with `.sim/sdk/INDEX.md` listing the builders.
@@ -26,7 +26,7 @@ For a whole workspace, use `sim workspaces source` with the same steps; see [Man
2626

2727
## Look things up
2828

29-
- `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.
29+
- `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.
3030
- `sim workflows source resources` lists the tables, knowledge bases, credentials, workflows, skills, custom tools, MCP servers and environment variable names the file can name.
3131
- `sim workflows source catalog` shows the block catalog the source is checked against.
3232

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ description: Every file a workflow directory and a workspace directory holds, wh
1818
| `.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 |
1919
| `.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 |
2020
| `.sim/starter.json` | The workspace a starter was written for, before `create` | Not kept: removed once the workflow exists |
21-
| `.sim/AGENTS.md` | The guide for coding agents: the primer `get` prints, then a reference | Optional, written again by `get` |
21+
| `.sim/AGENTS.md` | The guide for coding agents: the primer, then a reference | Optional, written again by `get` |
2222
| `.sim/examples/` | Example workflows to copy from | Optional, written again by `get` |
2323
| `.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` |
2424
| `tsconfig.json` | Resolves the declarations and type-checks the blocks the workflow uses. Left as it is if you already have one | Commit |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This writes `workflow.ts`, any function code under `functions/`, type declaratio
1919

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

22-
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.
22+
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.
2323

2424
## 2. Edit and check
2525

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ sim workflows source apply --dir ./support-triage --yes
4444

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

47-
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).
47+
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).
4848

4949
## Related docs
5050

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ A secret is never printed. A literal value in a password field prints as `stored
196196

197197
### JSON fields
198198

199-
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`.
199+
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`.
200200

201201
### Input formats and tools
202202

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const log = table.insertRow('Log Question', {
3232
})
3333
```
3434

35-
`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.
35+
`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.
3636

3737
## Edit a workspace
3838

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ import {
2727
SDK_MAJOR,
2828
SDK_MODELS_FILE,
2929
sdkIndexHeader,
30+
typecheckCommand,
3031
type WorkspaceManifest,
3132
} from '@sim/workflow-sdk/codegen'
33+
import type { Command } from 'commander'
3234
import { printError, printLine } from '#sim-cli/output/io'
3335
import type { OutputFormat } from '../../config/index'
3436
import { readJsonFile, writeJsonFile } from '../../config/json-file'
@@ -55,6 +57,7 @@ import {
5557
withMissingLines,
5658
} from './source-dir'
5759
import { AGENTS_POINTER_MARKER, agentsPointer, type PrimerKind, primerFor } from './source-primer'
60+
import { shellWord } from './source-ui'
5861

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

574577
/**
575-
* Prints a tree write's result: in JSON or YAML one document with the primer as its `primer`
576-
* field, otherwise the fields and then the primer as text, so it reads as written.
578+
* Prints a tree write's result: the fields, then the primer as text when the result carries one
579+
* (in JSON or YAML it is the document's `primer` field). A get leaves the primer out unless
580+
* `--primer` asks for it: it is already the top of `.sim/AGENTS.md`.
577581
*/
578582
export function printTreeResult(
579583
format: OutputFormat,
580-
result: Record<string, unknown> & { primer: string }
584+
result: Record<string, unknown> & { primer?: string }
581585
): void {
582586
if (format === 'json' || format === 'yaml') {
583587
printProtocolResult(format, result)
584588
return
585589
}
586590
const { primer, ...fields } = result
587591
printProtocolResult(format, fields)
588-
printLine(`\n${primer}`)
592+
if (primer !== undefined) printLine(`\n${primer}`)
593+
}
594+
595+
/** Adds `--primer` to a get command: it prints the primer the get writes atop `.sim/AGENTS.md`. */
596+
export function primerOption(command: Command): void {
597+
command.option(
598+
'--primer',
599+
'Also print the primer written atop .sim/AGENTS.md (a `primer` field in JSON)'
600+
)
601+
}
602+
603+
/**
604+
* The commands of a directory's edit loop, in order, for a get's result: what the primer's loop
605+
* says, runnable from anywhere because each names the directory.
606+
*/
607+
export function editLoop(kind: PrimerKind, dir: string): string[] {
608+
const group = kind === 'workflow' ? 'sim workflows source' : 'sim workspaces source'
609+
const at = shellWord(dir)
610+
return [
611+
`${group} check --dir ${at}`,
612+
typecheckCommand(at),
613+
`${group} apply --dir ${at} --dry-run`,
614+
]
589615
}
590616

591617
/** What a directory's editable tree holds beside the printed source. */

0 commit comments

Comments
 (0)