@bastani/atomic 0.5.34 → 0.6.0-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.
Files changed (94) hide show
  1. package/README.md +329 -50
  2. package/dist/commands/cli/session.d.ts +67 -0
  3. package/dist/commands/cli/session.d.ts.map +1 -0
  4. package/dist/commands/cli/workflow-status.d.ts +63 -0
  5. package/dist/commands/cli/workflow-status.d.ts.map +1 -0
  6. package/dist/sdk/commander.d.ts +74 -0
  7. package/dist/sdk/commander.d.ts.map +1 -0
  8. package/dist/sdk/components/workflow-picker-panel.d.ts +14 -17
  9. package/dist/sdk/components/workflow-picker-panel.d.ts.map +1 -1
  10. package/dist/sdk/define-workflow.d.ts +18 -9
  11. package/dist/sdk/define-workflow.d.ts.map +1 -1
  12. package/dist/sdk/index.d.ts +4 -3
  13. package/dist/sdk/index.d.ts.map +1 -1
  14. package/dist/sdk/management-commands.d.ts +42 -0
  15. package/dist/sdk/management-commands.d.ts.map +1 -0
  16. package/dist/sdk/registry.d.ts +27 -0
  17. package/dist/sdk/registry.d.ts.map +1 -0
  18. package/dist/sdk/runtime/attached-footer.d.ts +1 -1
  19. package/dist/sdk/runtime/executor-env.d.ts +20 -0
  20. package/dist/sdk/runtime/executor-env.d.ts.map +1 -0
  21. package/dist/sdk/runtime/executor.d.ts +61 -10
  22. package/dist/sdk/runtime/executor.d.ts.map +1 -1
  23. package/dist/sdk/types.d.ts +147 -4
  24. package/dist/sdk/types.d.ts.map +1 -1
  25. package/dist/sdk/worker-shared.d.ts +42 -0
  26. package/dist/sdk/worker-shared.d.ts.map +1 -0
  27. package/dist/sdk/workflow-cli.d.ts +103 -0
  28. package/dist/sdk/workflow-cli.d.ts.map +1 -0
  29. package/dist/sdk/workflows/builtin-registry.d.ts +113 -0
  30. package/dist/sdk/workflows/builtin-registry.d.ts.map +1 -0
  31. package/dist/sdk/workflows/index.d.ts +5 -5
  32. package/dist/sdk/workflows/index.d.ts.map +1 -1
  33. package/package.json +12 -8
  34. package/src/cli.ts +85 -144
  35. package/src/commands/cli/chat/index.ts +10 -0
  36. package/src/commands/cli/workflow-command.test.ts +279 -938
  37. package/src/commands/cli/workflow-inputs.test.ts +41 -11
  38. package/src/commands/cli/workflow-inputs.ts +47 -12
  39. package/src/commands/cli/workflow-list.test.ts +234 -0
  40. package/src/commands/cli/workflow-list.ts +0 -0
  41. package/src/commands/cli/workflow.ts +11 -798
  42. package/src/scripts/constants.ts +2 -1
  43. package/src/sdk/commander.ts +161 -0
  44. package/src/sdk/components/workflow-picker-panel.tsx +78 -258
  45. package/src/sdk/define-workflow.test.ts +104 -11
  46. package/src/sdk/define-workflow.ts +47 -11
  47. package/src/sdk/errors.test.ts +16 -0
  48. package/src/sdk/index.ts +8 -8
  49. package/src/sdk/management-commands.ts +151 -0
  50. package/src/sdk/registry.ts +132 -0
  51. package/src/sdk/runtime/attached-footer.ts +1 -1
  52. package/src/sdk/runtime/executor-env.ts +45 -0
  53. package/src/sdk/runtime/executor.test.ts +37 -0
  54. package/src/sdk/runtime/executor.ts +147 -68
  55. package/src/sdk/types.ts +169 -4
  56. package/src/sdk/worker-shared.test.ts +163 -0
  57. package/src/sdk/worker-shared.ts +155 -0
  58. package/src/sdk/workflow-cli.ts +409 -0
  59. package/src/sdk/workflows/builtin/deep-research-codebase/claude/index.ts +1 -1
  60. package/src/sdk/workflows/builtin/deep-research-codebase/copilot/index.ts +1 -1
  61. package/src/sdk/workflows/builtin/deep-research-codebase/opencode/index.ts +1 -1
  62. package/src/sdk/workflows/builtin/open-claude-design/claude/index.ts +1 -1
  63. package/src/sdk/workflows/builtin/open-claude-design/copilot/index.ts +1 -1
  64. package/src/sdk/workflows/builtin/open-claude-design/opencode/index.ts +1 -1
  65. package/src/sdk/workflows/builtin/ralph/claude/index.ts +1 -1
  66. package/src/sdk/workflows/builtin/ralph/copilot/index.ts +1 -1
  67. package/src/sdk/workflows/builtin/ralph/opencode/index.ts +1 -1
  68. package/src/sdk/workflows/builtin-registry.ts +23 -0
  69. package/src/sdk/workflows/index.ts +10 -20
  70. package/src/services/system/auth.test.ts +63 -1
  71. package/.agents/skills/workflow-creator/SKILL.md +0 -334
  72. package/.agents/skills/workflow-creator/references/agent-sessions.md +0 -888
  73. package/.agents/skills/workflow-creator/references/computation-and-validation.md +0 -201
  74. package/.agents/skills/workflow-creator/references/control-flow.md +0 -470
  75. package/.agents/skills/workflow-creator/references/discovery-and-verification.md +0 -232
  76. package/.agents/skills/workflow-creator/references/failure-modes.md +0 -903
  77. package/.agents/skills/workflow-creator/references/getting-started.md +0 -275
  78. package/.agents/skills/workflow-creator/references/running-workflows.md +0 -235
  79. package/.agents/skills/workflow-creator/references/session-config.md +0 -384
  80. package/.agents/skills/workflow-creator/references/state-and-data-flow.md +0 -357
  81. package/.agents/skills/workflow-creator/references/user-input.md +0 -234
  82. package/.agents/skills/workflow-creator/references/workflow-inputs.md +0 -272
  83. package/dist/sdk/runtime/discovery.d.ts +0 -132
  84. package/dist/sdk/runtime/discovery.d.ts.map +0 -1
  85. package/dist/sdk/runtime/executor-entry.d.ts +0 -11
  86. package/dist/sdk/runtime/executor-entry.d.ts.map +0 -1
  87. package/dist/sdk/runtime/loader.d.ts +0 -70
  88. package/dist/sdk/runtime/loader.d.ts.map +0 -1
  89. package/dist/version.d.ts +0 -2
  90. package/dist/version.d.ts.map +0 -1
  91. package/src/commands/cli/workflow.test.ts +0 -317
  92. package/src/sdk/runtime/discovery.ts +0 -368
  93. package/src/sdk/runtime/executor-entry.ts +0 -18
  94. package/src/sdk/runtime/loader.ts +0 -267
@@ -1,232 +0,0 @@
1
- # Discovery and Verification
2
-
3
- ## Setup
4
-
5
- ```bash
6
- bun init # Create a new project
7
- bun add @bastani/atomic # Install the workflow SDK
8
- bun add @anthropic-ai/claude-agent-sdk # For Claude workflows
9
- bun add @github/copilot-sdk # For Copilot workflows
10
- bun add @opencode-ai/sdk # For OpenCode workflows
11
- ```
12
-
13
- Install only the agent SDK(s) you need.
14
-
15
- Create workflow files at `.atomic/workflows/<name>/<agent>/index.ts`.
16
-
17
- ## Workflow file structure
18
-
19
- ```
20
- .atomic/workflows/
21
- ├── my-workflow/
22
- │ ├── claude/index.ts
23
- │ ├── copilot/index.ts
24
- │ └── opencode/index.ts
25
- └── my-other-workflow/
26
- ├── claude/index.ts
27
- ├── copilot/index.ts
28
- ├── opencode/index.ts
29
- └── helpers/
30
- ├── prompts.ts
31
- └── parsers.ts
32
- ```
33
-
34
- The SDK ships two built-in workflows as reference implementations:
35
- - **`ralph`** — iterative plan → orchestrate → review → debug loop (`src/sdk/workflows/builtin/ralph/`)
36
- - **`deep-research-codebase`** — deterministic scout → parallel explorers → aggregator (`src/sdk/workflows/builtin/deep-research-codebase/`)
37
-
38
- Built-in workflows are **reserved** — a local or global workflow with the
39
- same name cannot shadow the built-in at resolution time. Pick distinct names
40
- for your own workflows. In installed projects, built-ins are resolved from
41
- the SDK package's bundled `workflows/builtin/` directory.
42
-
43
- ## Discovery paths
44
-
45
- | Scope | Path | Resolution |
46
- |-------|------|------------|
47
- | **Built-in** | SDK modules shipped with `@bastani/atomic` | **Reserved** — cannot be shadowed by local or global workflows of the same name |
48
- | **Local** | `.atomic/workflows/<name>/<agent>/index.ts` | Highest precedence among non-reserved names |
49
- | **Global** | `~/.atomic/workflows/<name>/<agent>/index.ts` | Lowest precedence among non-reserved names |
50
-
51
- Built-in workflow names (`ralph`, `deep-research-codebase`) are dropped from user sources before any merge. For non-reserved names, local overrides global.
52
-
53
- The `<agent>` subdirectory determines which SDK the workflow targets: `claude/`, `copilot/`, or `opencode/`.
54
-
55
- ## Workflows directory hygiene
56
-
57
- The workflows directory maintains its own auto-generated `.gitignore`. The
58
- runtime regenerates it if missing and uses it during discovery, so ignored
59
- directories such as `node_modules/`, `dist/`, `build/`, `coverage/`, `.cache/`,
60
- and `*.tsbuildinfo` do not pollute workflow discovery.
61
-
62
- ## Export format
63
-
64
- Every workflow file must use `export default` with a compiled workflow:
65
-
66
- ```ts
67
- import { defineWorkflow } from "@bastani/atomic/workflows";
68
-
69
- export default defineWorkflow({
70
- name: "my-workflow",
71
- description: "What this workflow does",
72
- })
73
- .for<"claude">()
74
- .run(async (ctx) => {
75
- await ctx.stage({ name: "step-1" }, {}, {}, async (s) => { /* ... */ });
76
- await ctx.stage({ name: "step-2" }, {}, {}, async (s) => { /* ... */ });
77
- })
78
- .compile();
79
- ```
80
-
81
- The `.compile()` method returns a `WorkflowDefinition` with `__brand: "WorkflowDefinition"`. The runtime checks this brand at load time.
82
-
83
- ## Validation
84
-
85
- ### Compile-time checks
86
-
87
- The `WorkflowBuilder` enforces these rules at definition time:
88
-
89
- 1. **Non-empty workflow** — `.compile()` throws if no `.run()` call was made
90
- 2. **Required workflow name** — `defineWorkflow()` throws if `name` is empty
91
-
92
- Session name uniqueness is enforced at runtime when `ctx.stage()` is called — duplicate names within the same workflow run will throw.
93
-
94
- ### Provider validation warnings
95
-
96
- The SDK includes regex-based validation for all three providers:
97
-
98
- - **Claude** (`validateClaudeWorkflow`): Warns on direct `createClaudeSession` or `claudeQuery` usage — the runtime now handles init/cleanup automatically. Use `s.session.query(prompt)` instead.
99
- - **Copilot** (`validateCopilotWorkflow`): Warns on manual `new CopilotClient` or `client.createSession()` usage — the runtime auto-creates and cleans up the client and session. Use `s.client` and `s.session` instead. Pass session config as the third argument to `ctx.stage()`.
100
- - **OpenCode** (`validateOpenCodeWorkflow`): Warns on manual `createOpencodeClient()` or `client.session.create()` usage — the runtime auto-creates the client and session. Use `s.client` and `s.session` instead. Pass client config as the second argument and session config as the third argument to `ctx.stage()`.
101
-
102
- These are non-blocking warnings — the workflow will still load.
103
-
104
- ### Runtime brand check
105
-
106
- At load time, the runtime verifies:
107
- - The file has a `default` export
108
- - The export has `__brand === "WorkflowDefinition"`
109
- - The definition has a `name` and a `run` callback
110
-
111
- ## SDK version compatibility
112
-
113
- Workflows may opt in to a minimum Atomic CLI version by declaring
114
- `minSDKVersion` on `defineWorkflow()`. The field is **optional and
115
- unset by default** — workflows that don't declare it are treated as
116
- compatible with every CLI release.
117
-
118
- ```ts
119
- export default defineWorkflow({
120
- name: "uses-new-stage-option",
121
- description: "...",
122
- minSDKVersion: "0.6.0",
123
- })
124
- .for<"claude">()
125
- .run(async (ctx) => { /* ... */ })
126
- .compile();
127
- ```
128
-
129
- ### When to set it
130
-
131
- Set `minSDKVersion` when the workflow uses an SDK surface that older
132
- CLIs don't ship — for example a new `ctx.stage()` option, a newly
133
- exported helper, or a new provider method. The version you declare is
134
- the **earliest release you tested against**, not a future wish list.
135
-
136
- Skip it when the workflow only touches stable APIs. Most workflows
137
- qualify. A needlessly high `minSDKVersion` is worse than no gate —
138
- it'll lock users out for no reason.
139
-
140
- ### Accepted format
141
-
142
- `MAJOR.MINOR.PATCH` with an optional numeric prerelease, matching the
143
- shape of Atomic's own releases:
144
-
145
- | Example | Parses | Notes |
146
- |---|---|---|
147
- | `"0.6.0"` | ✅ | Standard release |
148
- | `"1.2.3"` | ✅ | Standard release |
149
- | `"0.6.0-0"` | ✅ | Prerelease; ranks below the equivalent stable release (semver-compliant) |
150
- | `"0.6"` | ❌ | Missing patch; treated as unparseable and ignored |
151
- | `"latest"` | ❌ | Unparseable; ignored |
152
-
153
- Unparseable strings are silently accepted (the workflow loads as if
154
- `minSDKVersion` were unset) so a typo never blocks a workflow —
155
- the visible load error path is friendlier than a hard refusal with no
156
- context.
157
-
158
- ### What happens when the gate trips
159
-
160
- A workflow whose `minSDKVersion` exceeds the installed CLI is kept in
161
- discovery but marked **incompatible** — it never silently vanishes:
162
-
163
- | Surface | Behaviour |
164
- |---|---|
165
- | `WorkflowLoader.loadWorkflow()` | Returns `{ ok: false, stage: "load", error: IncompatibleSDKError }` carrying `requiredVersion` + `currentVersion` |
166
- | `loadWorkflowsMetadata()` | Yields an entry with `status: { kind: "incompatible", requiredVersion, currentVersion, message }` |
167
- | `atomic workflow list` | Row is dimmed, with an inline `⚠ needs v<X> (installed v<Y>)` badge after the name |
168
- | `atomic workflow -a <agent>` picker | Row shows a `⚠` gutter glyph; preview pane explains the version gap and remediation; Enter does not advance to the prompt phase; bottom hint dims `↵ select` to `↵ unavailable` |
169
- | `atomic workflow -n <name> -a <agent>` | Exits non-zero, prints the `IncompatibleSDKError` message (`requires Atomic SDK v<X>, but v<Y> is installed. Update Atomic, or re-save the workflow against the current SDK.`) |
170
-
171
- Load failures that aren't version-related (syntax error, missing
172
- `.compile()`, invalid default export) follow the same visible-entry
173
- contract but surface as `status: { kind: "error", stage, message }`
174
- with a `✗ broken` badge.
175
-
176
- ### Why this exists
177
-
178
- The previous default was to silently drop any workflow that failed to
179
- load. That turned the "I bumped `@bastani/atomic` and a user/global
180
- workflow quietly stopped showing up" scenario into a ghost bug — the
181
- user had no breadcrumb to follow. The `minSDKVersion` field lets
182
- workflow authors opt in to a clear upgrade path, and the visible
183
- diagnostic rows make the failure discoverable even for workflows that
184
- never declared the field.
185
-
186
- ## TypeScript configuration
187
-
188
- Standard module resolution handles all imports. The project's `tsconfig.json` should use `"moduleResolution": "bundler"` (Bun's default).
189
-
190
- ## Type checking
191
-
192
- Run the project's typecheck script to catch TypeScript errors before testing:
193
-
194
- ```bash
195
- bun typecheck
196
- ```
197
-
198
- This catches:
199
- - Invalid `SessionContext` / `WorkflowContext` field access
200
- - Wrong session callback signatures
201
- - Missing required fields (`name`)
202
- - SDK type mismatches (e.g., passing wrong types to `s.save()`)
203
- - Incorrect provider-specific method calls (e.g., calling `s.session.query()` in a Copilot workflow)
204
-
205
- **Note on provider type parameter:** Using `.for<"claude">()`, `.for<"copilot">()`, or `.for<"opencode">()` narrows `s.client` and `s.session` to the correct provider types throughout the `.run()` callback and all `ctx.stage()` callbacks. Without the type parameter, `s.client` and `s.session` resolve to a union of all provider types, which requires type guards to use provider-specific methods.
206
-
207
- ## Testing
208
-
209
- Run a free-form workflow by passing the prompt as a positional argument:
210
-
211
- ```bash
212
- atomic workflow -n <workflow-name> -a <agent> "<your prompt>"
213
- ```
214
-
215
- Where:
216
- - `-n` / `--name` — workflow name (matches directory name)
217
- - `-a` / `--agent` — target agent (`claude`, `copilot`, or `opencode`)
218
- - The quoted string is the user prompt, which the runtime stores under `ctx.inputs.prompt` so workflow authors can read it via `ctx.inputs.prompt ?? ""`
219
-
220
- Run a workflow with declared inputs by passing one `--<field>=<value>` flag per entry in its schema:
221
-
222
- ```bash
223
- atomic workflow -n <workflow-name> -a <agent> --field_a=value --field_b=value
224
- ```
225
-
226
- Or discover and run any workflow interactively through the picker:
227
-
228
- ```bash
229
- atomic workflow -a <agent>
230
- ```
231
-
232
- See `workflow-inputs.md` for the full `WorkflowInput` schema shape, validation rules, and picker behaviour.