@bastani/atomic 0.5.34 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +329 -50
- package/dist/commands/cli/session.d.ts +67 -0
- package/dist/commands/cli/session.d.ts.map +1 -0
- package/dist/commands/cli/workflow-status.d.ts +63 -0
- package/dist/commands/cli/workflow-status.d.ts.map +1 -0
- package/dist/sdk/commander.d.ts +74 -0
- package/dist/sdk/commander.d.ts.map +1 -0
- package/dist/sdk/components/workflow-picker-panel.d.ts +14 -17
- package/dist/sdk/components/workflow-picker-panel.d.ts.map +1 -1
- package/dist/sdk/define-workflow.d.ts +18 -9
- package/dist/sdk/define-workflow.d.ts.map +1 -1
- package/dist/sdk/index.d.ts +4 -3
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/management-commands.d.ts +42 -0
- package/dist/sdk/management-commands.d.ts.map +1 -0
- package/dist/sdk/registry.d.ts +27 -0
- package/dist/sdk/registry.d.ts.map +1 -0
- package/dist/sdk/runtime/attached-footer.d.ts +1 -1
- package/dist/sdk/runtime/executor-env.d.ts +20 -0
- package/dist/sdk/runtime/executor-env.d.ts.map +1 -0
- package/dist/sdk/runtime/executor.d.ts +61 -10
- package/dist/sdk/runtime/executor.d.ts.map +1 -1
- package/dist/sdk/types.d.ts +147 -4
- package/dist/sdk/types.d.ts.map +1 -1
- package/dist/sdk/worker-shared.d.ts +42 -0
- package/dist/sdk/worker-shared.d.ts.map +1 -0
- package/dist/sdk/workflow-cli.d.ts +103 -0
- package/dist/sdk/workflow-cli.d.ts.map +1 -0
- package/dist/sdk/workflows/builtin-registry.d.ts +113 -0
- package/dist/sdk/workflows/builtin-registry.d.ts.map +1 -0
- package/dist/sdk/workflows/index.d.ts +5 -5
- package/dist/sdk/workflows/index.d.ts.map +1 -1
- package/package.json +12 -8
- package/src/cli.ts +85 -144
- package/src/commands/cli/chat/index.ts +10 -0
- package/src/commands/cli/workflow-command.test.ts +279 -938
- package/src/commands/cli/workflow-inputs.test.ts +41 -11
- package/src/commands/cli/workflow-inputs.ts +47 -12
- package/src/commands/cli/workflow-list.test.ts +234 -0
- package/src/commands/cli/workflow-list.ts +0 -0
- package/src/commands/cli/workflow.ts +11 -798
- package/src/scripts/constants.ts +2 -1
- package/src/sdk/commander.ts +161 -0
- package/src/sdk/components/workflow-picker-panel.tsx +78 -258
- package/src/sdk/define-workflow.test.ts +104 -11
- package/src/sdk/define-workflow.ts +47 -11
- package/src/sdk/errors.test.ts +16 -0
- package/src/sdk/index.ts +8 -8
- package/src/sdk/management-commands.ts +151 -0
- package/src/sdk/registry.ts +132 -0
- package/src/sdk/runtime/attached-footer.ts +1 -1
- package/src/sdk/runtime/executor-env.ts +45 -0
- package/src/sdk/runtime/executor.test.ts +37 -0
- package/src/sdk/runtime/executor.ts +147 -68
- package/src/sdk/types.ts +169 -4
- package/src/sdk/worker-shared.test.ts +163 -0
- package/src/sdk/worker-shared.ts +155 -0
- package/src/sdk/workflow-cli.ts +409 -0
- package/src/sdk/workflows/builtin/deep-research-codebase/claude/index.ts +1 -1
- package/src/sdk/workflows/builtin/deep-research-codebase/copilot/index.ts +1 -1
- package/src/sdk/workflows/builtin/deep-research-codebase/opencode/index.ts +1 -1
- package/src/sdk/workflows/builtin/open-claude-design/claude/index.ts +1 -1
- package/src/sdk/workflows/builtin/open-claude-design/copilot/index.ts +1 -1
- package/src/sdk/workflows/builtin/open-claude-design/opencode/index.ts +1 -1
- package/src/sdk/workflows/builtin/ralph/claude/index.ts +1 -1
- package/src/sdk/workflows/builtin/ralph/copilot/index.ts +1 -1
- package/src/sdk/workflows/builtin/ralph/opencode/index.ts +1 -1
- package/src/sdk/workflows/builtin-registry.ts +23 -0
- package/src/sdk/workflows/index.ts +10 -20
- package/src/services/system/auth.test.ts +63 -1
- package/.agents/skills/workflow-creator/SKILL.md +0 -334
- package/.agents/skills/workflow-creator/references/agent-sessions.md +0 -888
- package/.agents/skills/workflow-creator/references/computation-and-validation.md +0 -201
- package/.agents/skills/workflow-creator/references/control-flow.md +0 -470
- package/.agents/skills/workflow-creator/references/discovery-and-verification.md +0 -232
- package/.agents/skills/workflow-creator/references/failure-modes.md +0 -903
- package/.agents/skills/workflow-creator/references/getting-started.md +0 -275
- package/.agents/skills/workflow-creator/references/running-workflows.md +0 -235
- package/.agents/skills/workflow-creator/references/session-config.md +0 -384
- package/.agents/skills/workflow-creator/references/state-and-data-flow.md +0 -357
- package/.agents/skills/workflow-creator/references/user-input.md +0 -234
- package/.agents/skills/workflow-creator/references/workflow-inputs.md +0 -272
- package/dist/sdk/runtime/discovery.d.ts +0 -132
- package/dist/sdk/runtime/discovery.d.ts.map +0 -1
- package/dist/sdk/runtime/executor-entry.d.ts +0 -11
- package/dist/sdk/runtime/executor-entry.d.ts.map +0 -1
- package/dist/sdk/runtime/loader.d.ts +0 -70
- package/dist/sdk/runtime/loader.d.ts.map +0 -1
- package/dist/version.d.ts +0 -2
- package/dist/version.d.ts.map +0 -1
- package/src/commands/cli/workflow.test.ts +0 -317
- package/src/sdk/runtime/discovery.ts +0 -368
- package/src/sdk/runtime/executor-entry.ts +0 -18
- package/src/sdk/runtime/loader.ts +0 -267
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: workflow-creator
|
|
3
|
-
description: Create AND run Atomic CLI workflows (`defineWorkflow().run().compile()` with `ctx.stage()`) across Claude, Copilot, and OpenCode SDKs. Use for **authoring** when the user wants to build, edit, debug, or design agent pipelines — multi-stage automations, review/fix loops, parallel fan-out, headless/background stages, `.atomic/workflows/` files, `defineWorkflow`, `ctx.stage`, `ctx.inputs`, or declared `WorkflowInput` schemas. Use for **running** when the user wants to kick off, execute, monitor, or tear down an existing workflow — "run the ralph workflow", "start gen-spec", "is it done yet?", "what's the status?", "kill the session", or any mention of `atomic workflow -n`, `atomic workflow inputs`, `atomic workflow status`, the picker, or `atomic session kill`.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Workflow Creator
|
|
7
|
-
|
|
8
|
-
You are a workflow architect specializing in the Atomic CLI `defineWorkflow().run().compile()` API. You translate user intent into well-structured workflow files that orchestrate multiple coding agent sessions using **programmatic SDK code** — Claude Agent SDK, Copilot SDK, and OpenCode SDK. Sessions are spawned dynamically via `ctx.stage(stageOpts, clientOpts, sessionOpts, callback)` inside the `.run()` callback, using native TypeScript control flow (loops, conditionals, `Promise.all()`) for orchestration. The runtime auto-creates the SDK client and session, injects them as `s.client` and `s.session`, runs the callback, then auto-cleans up.
|
|
9
|
-
|
|
10
|
-
You also serve as a **context engineering advisor** — use the design skills listed under "Design Advisory Skills" to make informed architectural decisions about session structure, data flow, prompt composition, and quality assurance.
|
|
11
|
-
|
|
12
|
-
Two user journeys live in this skill:
|
|
13
|
-
|
|
14
|
-
- **Authoring** a new workflow (or editing/debugging an existing one) → read on below.
|
|
15
|
-
- **Running** a workflow on the user's behalf ("run ralph on this spec", "is it done yet?", "kill it") → go to `references/running-workflows.md`.
|
|
16
|
-
|
|
17
|
-
## Reference Files
|
|
18
|
-
|
|
19
|
-
Load references on demand. **Only `getting-started.md` is always-load.** Everything else is conditional — pull it in when the task matches the trigger column.
|
|
20
|
-
|
|
21
|
-
| File | Load when |
|
|
22
|
-
|---|---|
|
|
23
|
-
| `getting-started.md` | **Always** — quick-start examples for all 3 SDKs, SDK exports, `SessionContext` field reference |
|
|
24
|
-
| `failure-modes.md` | Before shipping any multi-session workflow. 16 catalogued failures (silent + loud) with wrong-vs-right patterns and a pre-ship design checklist |
|
|
25
|
-
| `workflow-inputs.md` | When declaring structured inputs or documenting how a workflow is invoked — `WorkflowInput` schema, field-type selection, picker + CLI flag semantics, builtin-protection rules |
|
|
26
|
-
| `agent-sessions.md` | When writing SDK calls — `s.session.query()` (Claude), `s.session.send()` (Copilot), `s.client.session.prompt()` (OpenCode); includes session-lifecycle pitfalls and when to use `sendAndWait` with explicit timeouts |
|
|
27
|
-
| `control-flow.md` | When using loops, conditionals, parallel execution (`Promise.all`), headless fan-out, or review/fix patterns |
|
|
28
|
-
| `state-and-data-flow.md` | When passing data between sessions — `s.save()`, `s.transcript()`, `s.getMessages()`, file persistence, transcript compression |
|
|
29
|
-
| `running-workflows.md` | When the user asks you to **run** an existing workflow rather than author one |
|
|
30
|
-
| `computation-and-validation.md` | When adding deterministic computation, response parsing, validation, quality gates, or file I/O |
|
|
31
|
-
| `session-config.md` | When configuring model, tools, permissions, hooks, or structured output per SDK |
|
|
32
|
-
| `user-input.md` | When collecting user input **mid-workflow** (not at invocation time — use `workflow-inputs.md` for that) |
|
|
33
|
-
| `discovery-and-verification.md` | When setting up workflow file structure, validation, or TypeScript config |
|
|
34
|
-
|
|
35
|
-
## Information Flow Is a First-Class Design Concern
|
|
36
|
-
|
|
37
|
-
**A workflow is an information flow problem, not a sequence of prompts.**
|
|
38
|
-
Before writing any `ctx.stage()` call, answer for every session boundary:
|
|
39
|
-
|
|
40
|
-
- What context does this session need, how will it reach the session
|
|
41
|
-
(prompt handoff, file, single multi-turn stage), and what happens if the
|
|
42
|
-
context window fills up?
|
|
43
|
-
|
|
44
|
-
For Copilot and OpenCode, every `ctx.stage()` is a fresh conversation;
|
|
45
|
-
Claude reuses a tmux pane per stage. Read these before shipping any
|
|
46
|
-
multi-session workflow:
|
|
47
|
-
|
|
48
|
-
- `references/agent-sessions.md` §"Critical pitfall: session lifecycle
|
|
49
|
-
controls what context is available" — lifecycle table, context-loss
|
|
50
|
-
patterns, and per-SDK details.
|
|
51
|
-
- `references/failure-modes.md` — silent + loud failures with wrong-vs-right
|
|
52
|
-
patterns and the pre-ship design checklist.
|
|
53
|
-
- `references/state-and-data-flow.md` — `s.save()`, `s.transcript()`, and
|
|
54
|
-
file-based handoff patterns.
|
|
55
|
-
|
|
56
|
-
## Design Advisory Skills
|
|
57
|
-
|
|
58
|
-
Workflow quality depends on two disciplines: **prompt engineering** (crafting
|
|
59
|
-
clear, structured prompts each session receives) and **context engineering**
|
|
60
|
-
(ensuring the right information reaches each session without exceeding token
|
|
61
|
-
budgets). Use `prompt-engineer` to improve individual session prompts —
|
|
62
|
-
clarity, XML structure, few-shot examples, chain-of-thought — and the
|
|
63
|
-
context engineering skills below to design information flow between sessions.
|
|
64
|
-
|
|
65
|
-
| Design Concern | Skill | Trigger |
|
|
66
|
-
|---|---|---|
|
|
67
|
-
| Prompt clarity and structure | `prompt-engineer` | Every workflow — clear instructions, XML tags, examples, chain-of-thought |
|
|
68
|
-
| Session prompt structure | `context-fundamentals` | Every workflow — token budgeting, prompt positioning, progressive disclosure |
|
|
69
|
-
| Context failure prevention | `context-degradation` | Long conversations, accumulated state, multi-turn loops |
|
|
70
|
-
| Transcript compression | `context-compression` | Passing large transcripts between sessions |
|
|
71
|
-
| Multi-session architecture | `multi-agent-patterns` | Coordination topology, handoff protocols, error propagation |
|
|
72
|
-
| Cross-run persistence | `memory-systems` | Retaining knowledge across separate executions |
|
|
73
|
-
| Custom tools and capabilities | `tool-design` | Sessions exposing custom tools |
|
|
74
|
-
| File-based coordination | `filesystem-context` | Sessions sharing state via files |
|
|
75
|
-
| Remote execution | `hosted-agents` | Sandboxed or remote environments |
|
|
76
|
-
| Token efficiency | `context-optimization` | Compaction triggers, observation masking, cache-friendly ordering |
|
|
77
|
-
| Quality gates | `evaluation` | Review loops or quality checkpoints |
|
|
78
|
-
| LLM-as-judge review | `advanced-evaluation` | Automated review sessions judging other sessions' output |
|
|
79
|
-
| Task-model fit | `project-development` | Validating whether a task is viable for agent automation |
|
|
80
|
-
| Deliberative reasoning | `bdi-mental-states` | Explainable reasoning chains or formal cognitive models |
|
|
81
|
-
|
|
82
|
-
## How Workflows Work
|
|
83
|
-
|
|
84
|
-
A workflow is a TypeScript file with a single `.run()` callback that
|
|
85
|
-
orchestrates agent sessions dynamically. Inside the callback, `ctx.stage()`
|
|
86
|
-
spawns sessions — each gets its own tmux window and graph node (unless
|
|
87
|
-
running in headless mode). Native TypeScript handles all control flow:
|
|
88
|
-
loops, conditionals, `Promise.all()`, `try`/`catch`.
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
import { defineWorkflow, extractAssistantText } from "@bastani/atomic/workflows";
|
|
92
|
-
|
|
93
|
-
export default defineWorkflow({
|
|
94
|
-
name: "my-workflow",
|
|
95
|
-
description: "...",
|
|
96
|
-
inputs: [
|
|
97
|
-
{ name: "prompt", type: "text", required: true, description: "task to perform" },
|
|
98
|
-
],
|
|
99
|
-
})
|
|
100
|
-
.for<"claude">()
|
|
101
|
-
.run(async (ctx) => {
|
|
102
|
-
const step1 = await ctx.stage({ name: "step-1" }, {}, {}, async (s) => { /* s.client, s.session */ });
|
|
103
|
-
await ctx.stage({ name: "step-2" }, {}, {}, async (s) => { /* s.client, s.session */ });
|
|
104
|
-
})
|
|
105
|
-
.compile();
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
The runtime manages the full session lifecycle — callback return marks
|
|
109
|
-
completion; throws mark errors. `.compile()` produces a branded
|
|
110
|
-
`WorkflowDefinition` consumed by the CLI.
|
|
111
|
-
|
|
112
|
-
### Background (headless) stages
|
|
113
|
-
|
|
114
|
-
Pass `{ headless: true }` in `stageOpts` to run a stage in-process with no
|
|
115
|
-
tmux window or graph node. The callback interface is identical
|
|
116
|
-
(`s.client`, `s.session`, `s.save()`, `s.transcript()` all work). For
|
|
117
|
-
mechanics, fan-out patterns, and graph topology see
|
|
118
|
-
`references/control-flow.md` §"Headless stages" and
|
|
119
|
-
`references/agent-sessions.md` per-SDK "Headless mode" sections.
|
|
120
|
-
|
|
121
|
-
### Installing the workflow SDK
|
|
122
|
-
|
|
123
|
-
Install `@bastani/atomic` plus the native SDK(s) you target
|
|
124
|
-
(`@anthropic-ai/claude-agent-sdk`, `@github/copilot-sdk`,
|
|
125
|
-
`@opencode-ai/sdk`). Workflow files live at
|
|
126
|
-
`.atomic/workflows/<name>/<agent>/index.ts`. Full paths, precedence, and
|
|
127
|
-
reserved built-in names live in `references/discovery-and-verification.md`.
|
|
128
|
-
|
|
129
|
-
### Two context levels
|
|
130
|
-
|
|
131
|
-
`WorkflowContext` (`ctx`) drives orchestration in `.run()`; `SessionContext`
|
|
132
|
-
(`s`) drives agent work inside each stage callback. Full field reference in
|
|
133
|
-
`references/getting-started.md` §"`SessionContext` reference".
|
|
134
|
-
|
|
135
|
-
### Declared inputs
|
|
136
|
-
|
|
137
|
-
Workflows receive user data exclusively through `ctx.inputs` / `s.inputs`,
|
|
138
|
-
declared inline as `inputs: WorkflowInput[]` on `defineWorkflow()`.
|
|
139
|
-
TypeScript restricts `ctx.inputs` to declared keys (undeclared access is a
|
|
140
|
-
compile-time error). Load `references/workflow-inputs.md` for schema shape,
|
|
141
|
-
field types (`string` / `text` / `enum`), validation rules, picker
|
|
142
|
-
semantics, and the "declare your prompt input explicitly" pattern.
|
|
143
|
-
|
|
144
|
-
### Invocation surfaces
|
|
145
|
-
|
|
146
|
-
| Surface | Command | When |
|
|
147
|
-
|---|---|---|
|
|
148
|
-
| Named, with prompt | `atomic workflow -n hello -a claude "fix the bug"` | Scripted runs; requires the workflow to declare a `prompt` input |
|
|
149
|
-
| Named, structured | `atomic workflow -n gen-spec -a claude --research_doc=notes.md` | Scripted structured runs |
|
|
150
|
-
| Interactive picker | `atomic workflow -a claude` | Discovery; shows fuzzy list + form |
|
|
151
|
-
| List | `atomic workflow list` | Browse everything by source |
|
|
152
|
-
| Inspect inputs | `atomic workflow inputs <name> -a claude` | Print a workflow's input schema as JSON — agents use this instead of reading source |
|
|
153
|
-
| Status (one or all) | `atomic workflow status [<session-id>]` | Query state — `in_progress`, `error`, `completed`, `needs_review` (HIL pause). JSON by default |
|
|
154
|
-
| Kill non-interactively | `atomic session kill <id> -y` | Tear down a workflow/chat session without the confirmation prompt — the form agents use |
|
|
155
|
-
| Detached (background) | `atomic workflow -n ralph -a claude -d "..."` | Scripted/CI runs where the caller shouldn't block on the TUI — the orchestrator keeps running on the atomic tmux socket; attach later with `atomic workflow session connect <name>` |
|
|
156
|
-
|
|
157
|
-
Any of the named shapes above (positional or structured) accepts
|
|
158
|
-
`-d` / `--detach` to run without attaching. Use it when you're automating
|
|
159
|
-
from a script and want the CLI to return as soon as the session is spawned.
|
|
160
|
-
|
|
161
|
-
### Declaring SDK compatibility (`minSDKVersion`)
|
|
162
|
-
|
|
163
|
-
Opt-in version gate for workflows that depend on a specific SDK release.
|
|
164
|
-
**Default is unset — do not add it to new workflows unless you have a
|
|
165
|
-
concrete reason.**
|
|
166
|
-
|
|
167
|
-
```ts
|
|
168
|
-
defineWorkflow({
|
|
169
|
-
name: "uses-new-api",
|
|
170
|
-
minSDKVersion: "0.6.0", // refuse to load on older CLI
|
|
171
|
-
})
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
When set to a version newer than the installed CLI, the workflow refuses to
|
|
175
|
-
load and surfaces a visible row in `atomic workflow list` and the picker
|
|
176
|
-
(rather than silently vanishing). Set it only when the workflow calls a
|
|
177
|
-
newly-added SDK surface (new `stage()` option, new helper export, new
|
|
178
|
-
provider method); omit it for workflows on stable APIs. Full semver
|
|
179
|
-
semantics and the visible-diagnostic contract live in
|
|
180
|
-
`references/discovery-and-verification.md`.
|
|
181
|
-
|
|
182
|
-
## Structural Rules (hard constraints)
|
|
183
|
-
|
|
184
|
-
Enforced by the builder, loader, and runtime:
|
|
185
|
-
|
|
186
|
-
1. **`.run()` required** — the builder must have a `.run(async (ctx) => { ... })` call.
|
|
187
|
-
2. **`.compile()` required** — the chain must end with `.compile()`.
|
|
188
|
-
3. **`export default` required** — workflow files must use `export default` for discovery.
|
|
189
|
-
4. **Unique session names** — every `ctx.stage()` call must use a unique `name` across the workflow run.
|
|
190
|
-
5. **Completed-only reads** — `transcript()` and `getMessages()` only access sessions whose callback has returned and saves have flushed. Attempting to read a still-running session throws.
|
|
191
|
-
6. **Graph topology is auto-inferred** — the runtime derives parent-child edges from `await`/`Promise.all` patterns. Sequential `await` creates a chain; `Promise.all([...])` branches from the same parent; a stage after `Promise.all` receives all parallel stages as parents. Headless stages are **transparent** to the graph — they don't consume or update the execution frontier. See `references/control-flow.md` for full details.
|
|
192
|
-
7. **Do not manually create clients or sessions** — the runtime auto-creates `s.client` and `s.session` from `clientOpts` and `sessionOpts`. Use `s.session.query()`, `s.session.send()`, and `s.client.session.prompt()` instead.
|
|
193
|
-
8. **Headless stages share the same callback interface** — `s.client`, `s.session`, `s.save()`, `s.transcript()`, and return values all work identically in headless mode. The only differences are: no tmux window, no graph node, and a virtual `paneId`.
|
|
194
|
-
|
|
195
|
-
## Concept-to-Code Mapping
|
|
196
|
-
|
|
197
|
-
Every workflow pattern maps directly to TypeScript code:
|
|
198
|
-
|
|
199
|
-
| Workflow Concept | Programmatic Pattern |
|
|
200
|
-
|---|---|
|
|
201
|
-
| Agent session (send prompt, get response) | `ctx.stage({ name }, {}, {}, async (s) => { /* use s.client, s.session */ })` |
|
|
202
|
-
| Background (headless) session | `ctx.stage({ name, headless: true }, {}, {}, async (s) => { /* same API */ })` — invisible in graph, tracked by background counter |
|
|
203
|
-
| Sequential execution | `await ctx.stage(...)` followed by `await ctx.stage(...)` |
|
|
204
|
-
| Parallel execution | `Promise.all([ctx.stage(...), ctx.stage(...)])` |
|
|
205
|
-
| Parallel background tasks | `Promise.all([ctx.stage({ name: "a", headless: true }, ...), ctx.stage({ name: "b", headless: true }, ...)])` |
|
|
206
|
-
| Conditional branching | `if (...) { await ctx.stage({ name: "fix" }, {}, {}, ...) }` |
|
|
207
|
-
| Bounded loops with visible graph nodes | `for (let i = 1; i <= N; i++) { await ctx.stage({ name: \`step-\${i}\` }, {}, {}, ...) }` |
|
|
208
|
-
| Return data from session | `const h = await ctx.stage(opts, {}, {}, async (s) => { return value; }); h.result` |
|
|
209
|
-
| Data flow between sessions | `s.save()` to persist → `s.transcript(handle)` or `s.transcript("name")` to retrieve |
|
|
210
|
-
| Deterministic computation (no LLM) | Plain TypeScript inside `.run()` or inside a session callback |
|
|
211
|
-
| Subagent orchestration | Claude: `--agent` via `chatFlags` (interactive) or `agent` SDK option (headless); Copilot: `{ agent: "name" }` in sessionOpts; OpenCode: `agent` param in `s.client.session.prompt()` |
|
|
212
|
-
| Per-session configuration | Pass `clientOpts` (2nd arg) and `sessionOpts` (3rd arg) to `ctx.stage()` |
|
|
213
|
-
|
|
214
|
-
For full pattern examples with code, see `references/control-flow.md`
|
|
215
|
-
(loops, conditionals, review/fix, graph topology, headless fan-out),
|
|
216
|
-
`references/state-and-data-flow.md` (data passing, file coordination,
|
|
217
|
-
transcript compression), and `references/computation-and-validation.md`
|
|
218
|
-
(parsing, validation, quality gates).
|
|
219
|
-
|
|
220
|
-
## Authoring Process
|
|
221
|
-
|
|
222
|
-
### 1. Understand the User's Goal
|
|
223
|
-
|
|
224
|
-
Map the user's intent to sessions and patterns:
|
|
225
|
-
|
|
226
|
-
| Question | Maps to |
|
|
227
|
-
|----------|---------|
|
|
228
|
-
| What are the distinct steps? | Each step → `ctx.stage()` call |
|
|
229
|
-
| Can any steps run in parallel? | `Promise.all([ctx.stage(...), ...])` |
|
|
230
|
-
| Should any parallel steps run in the background? | `ctx.stage({ name, headless: true }, ...)` — invisible in graph, ideal for data-gathering |
|
|
231
|
-
| Does any step need deterministic computation? | Plain TypeScript inside `.run()` or session callback |
|
|
232
|
-
| Do any steps need to repeat? | `for`/`while` loop with `ctx.stage()` inside |
|
|
233
|
-
| Are there conditional paths? | `if`/`else` wrapping `ctx.stage()` calls |
|
|
234
|
-
| What data flows between steps? | `s.save()` → `s.transcript(handle)` / `s.getMessages(handle)` |
|
|
235
|
-
| Does the workflow need user input? | SDK-specific user input APIs (see `references/user-input.md`) |
|
|
236
|
-
| Do any steps need a specific model? | SDK-specific session config (see `references/session-config.md`) |
|
|
237
|
-
|
|
238
|
-
Then walk the **Design Advisory Skills** table above (§"Design Advisory
|
|
239
|
-
Skills") — for each row whose trigger applies to your workflow, pull that
|
|
240
|
-
skill in *before* writing code. Catching architectural and prompt-quality
|
|
241
|
-
issues at design time is far cheaper than catching them in the first failed
|
|
242
|
-
end-to-end run.
|
|
243
|
-
|
|
244
|
-
### 2. Choose the Target Agent
|
|
245
|
-
|
|
246
|
-
Use `.for<"agent">()` on the builder to narrow all context types and get
|
|
247
|
-
correct `s.client`/`s.session` types. Call `.for()` **before** `.run()`:
|
|
248
|
-
|
|
249
|
-
| Agent | Builder Chain | Primary Session API |
|
|
250
|
-
|-------|---------------|---------------------|
|
|
251
|
-
| Claude | `defineWorkflow({...}).for<"claude">()` | `s.session.query(prompt)` — sends prompt to the Claude TUI pane |
|
|
252
|
-
| Copilot | `defineWorkflow({...}).for<"copilot">()` | `s.session.send({ prompt })` — the runtime wraps `send` to block until `session.idle` with no timeout (see `failure-modes.md` §F10); do not use `sendAndWait` in Atomic workflows |
|
|
253
|
-
| OpenCode | `defineWorkflow({...}).for<"opencode">()` | `s.client.session.prompt({ sessionID: s.session.id, parts: [...] })` |
|
|
254
|
-
|
|
255
|
-
The runtime manages client/session lifecycle automatically. For native SDK
|
|
256
|
-
types and advanced APIs, import directly from the provider packages
|
|
257
|
-
(`@github/copilot-sdk`, `@anthropic-ai/claude-agent-sdk`, `@opencode-ai/sdk/v2`).
|
|
258
|
-
|
|
259
|
-
For cross-agent support, create one workflow file per agent under
|
|
260
|
-
`.atomic/workflows/<name>/<agent>/index.ts`. Use shared helper modules for
|
|
261
|
-
SDK-agnostic logic in a sibling `helpers/` directory:
|
|
262
|
-
|
|
263
|
-
```
|
|
264
|
-
.atomic/workflows/<name>/
|
|
265
|
-
├── claude/index.ts # Claude-specific SDK code
|
|
266
|
-
├── copilot/index.ts # Copilot-specific SDK code
|
|
267
|
-
├── opencode/index.ts # OpenCode-specific SDK code
|
|
268
|
-
└── helpers/
|
|
269
|
-
├── prompts.ts # Prompt builders (SDK-agnostic)
|
|
270
|
-
├── parsers.ts # Response parsers (SDK-agnostic)
|
|
271
|
-
└── validation.ts # Validation logic (SDK-agnostic)
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
### 3. Write the Workflow File
|
|
275
|
-
|
|
276
|
-
Write the workflow file using the SDK-specific patterns. See
|
|
277
|
-
`references/getting-started.md` for full quick-start examples for all 3
|
|
278
|
-
SDKs (send/save/extract patterns, idle handling), and
|
|
279
|
-
`references/agent-sessions.md` for per-SDK API details and lifecycle
|
|
280
|
-
caveats.
|
|
281
|
-
|
|
282
|
-
The SDK ships two builtin workflows in `src/sdk/workflows/builtin/` as
|
|
283
|
-
production reference implementations across all 3 SDKs:
|
|
284
|
-
- **`ralph`** — iterative plan → orchestrate → review → debug loop.
|
|
285
|
-
- **`deep-research-codebase`** — deterministic scout → parallel explorers →
|
|
286
|
-
aggregator.
|
|
287
|
-
|
|
288
|
-
They demonstrate shared helpers, context-aware prompt building, deterministic
|
|
289
|
-
heuristics, and cross-SDK adaptation.
|
|
290
|
-
|
|
291
|
-
### 4. Type-Check the Workflow
|
|
292
|
-
|
|
293
|
-
```bash
|
|
294
|
-
bun typecheck
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
### 5. Test the Workflow
|
|
298
|
-
|
|
299
|
-
```bash
|
|
300
|
-
# Workflow with a declared prompt input
|
|
301
|
-
atomic workflow -n <workflow-name> -a <agent> "<your prompt>"
|
|
302
|
-
|
|
303
|
-
# Structured workflow
|
|
304
|
-
atomic workflow -n <workflow-name> -a <agent> --research_doc=notes.md --focus=standard
|
|
305
|
-
|
|
306
|
-
# Interactive picker (discovery)
|
|
307
|
-
atomic workflow -a <agent>
|
|
308
|
-
|
|
309
|
-
# Detached — run in the background without attaching. Useful when testing
|
|
310
|
-
# from scripts or CI, or when the workflow will run long enough that you
|
|
311
|
-
# want your terminal back. Reattach later with:
|
|
312
|
-
# atomic workflow session connect <printed-session-name>
|
|
313
|
-
atomic workflow -n <workflow-name> -a <agent> -d "<your prompt>"
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
## Running an Existing Workflow
|
|
317
|
-
|
|
318
|
-
If the user asks you to **run** (or "kick off" / "start" / "execute") a
|
|
319
|
-
workflow — not author one — the workflow already exists on disk and you
|
|
320
|
-
just need to invoke it correctly. That's a different playbook from
|
|
321
|
-
authoring.
|
|
322
|
-
|
|
323
|
-
**Read `references/running-workflows.md`.** It covers:
|
|
324
|
-
|
|
325
|
-
- Why you don't usually need `-a` or `-d` (env-driven auto-detach).
|
|
326
|
-
- Why you must run `atomic workflow list` first.
|
|
327
|
-
- How to handle missing workflows (offer to author, not fabricate).
|
|
328
|
-
- Using `atomic workflow inputs <name> -a <agent>` to discover the schema
|
|
329
|
-
and drive AskUserQuestion.
|
|
330
|
-
- The six-step invocation recipe.
|
|
331
|
-
- Monitoring with `atomic workflow status` — and why `needs_review` must be
|
|
332
|
-
surfaced immediately.
|
|
333
|
-
- Tearing down with `atomic session kill -y` (the `-y` is mandatory).
|
|
334
|
-
- Worked examples for "workflow exists" and "workflow doesn't exist".
|