@bastani/atomic 0.8.23 → 0.8.24-alpha.1

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 (70) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +7 -0
  3. package/dist/builtin/intercom/package.json +1 -1
  4. package/dist/builtin/mcp/CHANGELOG.md +7 -0
  5. package/dist/builtin/mcp/package.json +1 -1
  6. package/dist/builtin/subagents/CHANGELOG.md +22 -0
  7. package/dist/builtin/subagents/README.md +16 -0
  8. package/dist/builtin/subagents/agents/code-simplifier.md +2 -3
  9. package/dist/builtin/subagents/agents/codebase-analyzer.md +2 -3
  10. package/dist/builtin/subagents/agents/codebase-locator.md +2 -3
  11. package/dist/builtin/subagents/agents/codebase-online-researcher.md +2 -3
  12. package/dist/builtin/subagents/agents/codebase-pattern-finder.md +2 -3
  13. package/dist/builtin/subagents/agents/codebase-research-analyzer.md +2 -3
  14. package/dist/builtin/subagents/agents/codebase-research-locator.md +2 -3
  15. package/dist/builtin/subagents/agents/debugger.md +2 -3
  16. package/dist/builtin/subagents/package.json +1 -1
  17. package/dist/builtin/subagents/skills/subagent/SKILL.md +6 -0
  18. package/dist/builtin/subagents/src/agents/agent-serializer.ts +3 -0
  19. package/dist/builtin/subagents/src/agents/agents.ts +20 -1
  20. package/dist/builtin/subagents/src/runs/background/async-execution.ts +1 -1
  21. package/dist/builtin/subagents/src/runs/background/subagent-runner.ts +3 -1
  22. package/dist/builtin/subagents/src/runs/foreground/chain-clarify.ts +7 -7
  23. package/dist/builtin/subagents/src/runs/foreground/execution.ts +5 -1
  24. package/dist/builtin/subagents/src/runs/shared/model-fallback.ts +9 -10
  25. package/dist/builtin/subagents/src/shared/types.ts +1 -0
  26. package/dist/builtin/web-access/CHANGELOG.md +7 -0
  27. package/dist/builtin/web-access/package.json +1 -1
  28. package/dist/builtin/workflows/CHANGELOG.md +25 -0
  29. package/dist/builtin/workflows/README.md +38 -41
  30. package/dist/builtin/workflows/builtin/deep-research-codebase.d.ts +35 -0
  31. package/dist/builtin/workflows/builtin/deep-research-codebase.ts +11 -14
  32. package/dist/builtin/workflows/builtin/goal.d.ts +46 -0
  33. package/dist/builtin/workflows/builtin/goal.ts +10 -12
  34. package/dist/builtin/workflows/builtin/index.d.ts +136 -0
  35. package/dist/builtin/workflows/builtin/open-claude-design.d.ts +44 -0
  36. package/dist/builtin/workflows/builtin/open-claude-design.ts +19 -20
  37. package/dist/builtin/workflows/builtin/ralph.d.ts +36 -0
  38. package/dist/builtin/workflows/builtin/ralph.ts +20 -24
  39. package/dist/builtin/workflows/package.json +15 -5
  40. package/dist/builtin/workflows/src/authoring.ts +410 -0
  41. package/dist/builtin/workflows/src/extension/workflow-module-loader.ts +6 -12
  42. package/dist/builtin/workflows/src/extension/workflow-schema.ts +3 -2
  43. package/dist/builtin/workflows/src/index.ts +0 -5
  44. package/dist/builtin/workflows/src/runs/foreground/executor.ts +23 -9
  45. package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +33 -5
  46. package/dist/builtin/workflows/src/runs/shared/model-fallback.ts +61 -10
  47. package/dist/builtin/workflows/src/sdk-surface.ts +12 -2
  48. package/dist/builtin/workflows/src/shared/authoring-contract.ts +660 -0
  49. package/dist/builtin/workflows/src/shared/render-inputs-schema.ts +1 -1
  50. package/dist/builtin/workflows/src/shared/types.ts +65 -350
  51. package/dist/builtin/workflows/src/workflows/define-workflow.ts +59 -44
  52. package/dist/core/atomic-guide-command.d.ts.map +1 -1
  53. package/dist/core/atomic-guide-command.js +1 -1
  54. package/dist/core/atomic-guide-command.js.map +1 -1
  55. package/dist/modes/interactive/components/chat-message-renderer.d.ts +1 -0
  56. package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
  57. package/dist/modes/interactive/components/chat-message-renderer.js +13 -1
  58. package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
  59. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  60. package/dist/modes/interactive/interactive-mode.js +1 -1
  61. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  62. package/dist/utils/changelog.d.ts.map +1 -1
  63. package/dist/utils/changelog.js +23 -16
  64. package/dist/utils/changelog.js.map +1 -1
  65. package/docs/extensions.md +2 -2
  66. package/docs/packages.md +8 -4
  67. package/docs/subagents.md +30 -0
  68. package/docs/workflows.md +39 -21
  69. package/package.json +1 -1
  70. package/dist/builtin/workflows/src/runs/shared/workflow-runner.ts +0 -335
@@ -9,16 +9,40 @@
9
9
  */
10
10
 
11
11
  import type { Static, TOptional, TSchema } from "typebox";
12
+ import type * as AuthoringContract from "../shared/authoring-contract.js";
12
13
  import type {
13
14
  WorkflowDefinition,
14
15
  WorkflowInputBindings,
15
16
  WorkflowInputValues,
16
17
  WorkflowOutputValues,
18
+ WorkflowRunContext,
19
+ WorkflowSerializableValue,
17
20
  WorkflowRunFn,
18
21
  WorkflowWorktreeInputBinding,
19
22
  } from "../shared/types.js";
20
23
  import { normalizeWorkflowName } from "./identity.js";
21
24
 
25
+ const BRANDED_WORKFLOW_DEFINITIONS = new WeakSet<object>();
26
+
27
+ // Package-internal runtime brand. It deliberately is not exported through the
28
+ // public SDK surface; only defineWorkflow(...).compile() and executor-created
29
+ // direct workflows can mint discoverable definitions.
30
+ export function stampWorkflowDefinition<
31
+ TInputs extends WorkflowInputValues,
32
+ TOutputs extends WorkflowOutputValues,
33
+ >(
34
+ definition: WorkflowDefinition<TInputs, TOutputs>,
35
+ ): WorkflowDefinition<TInputs, TOutputs> {
36
+ BRANDED_WORKFLOW_DEFINITIONS.add(definition);
37
+ return definition;
38
+ }
39
+
40
+ export function isBrandedWorkflowDefinition(value: unknown): value is WorkflowDefinition {
41
+ return value !== null &&
42
+ typeof value === "object" &&
43
+ BRANDED_WORKFLOW_DEFINITIONS.has(value);
44
+ }
45
+
22
46
  // ---------------------------------------------------------------------------
23
47
  // Type inference helpers (TypeBox Static<> mapping)
24
48
  // ---------------------------------------------------------------------------
@@ -39,6 +63,16 @@ type DeclaredEntry<K extends string, S extends TSchema> =
39
63
  type Simplify<T> = { [K in keyof T]: T[K] } & {};
40
64
 
41
65
  type SimplifyWorkflowOutputs<T> = Simplify<T>;
66
+ type DeclaredOutputEntry<K extends string, S extends TSchema> =
67
+ S extends TOptional<TSchema>
68
+ ? { readonly [P in K]?: Static<S> & WorkflowSerializableValue }
69
+ : { readonly [P in K]: Static<S> & WorkflowSerializableValue };
70
+
71
+ type AccumulateWorkflowOutput<TOutputs, K extends string, S extends TSchema> = Simplify<
72
+ string extends keyof TOutputs
73
+ ? DeclaredOutputEntry<K, S>
74
+ : TOutputs & DeclaredOutputEntry<K, S>
75
+ >;
42
76
 
43
77
  interface BuilderState<TInputs extends WorkflowInputValues> {
44
78
  readonly name: string;
@@ -66,34 +100,18 @@ interface BuilderState<TInputs extends WorkflowInputValues> {
66
100
  * compatible with the type-erased registry without casts.
67
101
  */
68
102
  export interface WorkflowBuilder<
69
- TInputs extends WorkflowInputValues = WorkflowInputValues,
103
+ TInputs extends WorkflowInputValues = {},
70
104
  TOutputs extends WorkflowOutputValues = {},
105
+ > extends Omit<
106
+ AuthoringContract.WorkflowBuilder<TInputs, TOutputs>,
107
+ "description" | "input" | "output" | "worktreeFromInputs" | "run"
71
108
  > {
72
- /** Set (or replace) the human-readable description. Returns a new builder. */
73
109
  description(text: string): WorkflowBuilder<TInputs, TOutputs>;
74
- /**
75
- * Declare a typed input. Returns a new builder whose TInputs grows with
76
- * the new key (typed as the schema's default value type).
77
- */
78
- input<K extends string, S extends TSchema>(
79
- key: K,
80
- schema: S,
81
- ): WorkflowBuilder<TInputs & DeclaredEntry<K, S>, TOutputs>;
82
- /**
83
- * Declare a typed output. Returns a new builder whose TOutputs grows with
84
- * the new key (optional when the schema is `Type.Optional(...)`, otherwise
85
- * required), so the `.run()` return is statically checked against the
86
- * declared contract.
87
- */
88
- output<K extends string, S extends TSchema>(
89
- key: K,
90
- schema: S,
91
- ): WorkflowBuilder<TInputs, TOutputs & DeclaredEntry<K, S>>;
92
- /** Bind workflow inputs to reusable git worktree runtime defaults. */
110
+ input<K extends string, S extends TSchema>(key: K, schema: S): WorkflowBuilder<TInputs & DeclaredEntry<K, S>, TOutputs>;
111
+ output<K extends string, S extends TSchema>(key: K, schema: S): WorkflowBuilder<TInputs, AccumulateWorkflowOutput<TOutputs, K, S>>;
93
112
  worktreeFromInputs(binding: WorkflowWorktreeInputBinding): WorkflowBuilder<TInputs, TOutputs>;
94
- /** Seal the run function. Returns a builder on which .compile() is available. */
95
- run(
96
- fn: WorkflowRunFn<Simplify<TInputs>, SimplifyWorkflowOutputs<TOutputs>>,
113
+ run<TActualOutputs extends SimplifyWorkflowOutputs<TOutputs>>(
114
+ fn: (ctx: WorkflowRunContext<Simplify<TInputs>>) => Promise<AuthoringContract.NoExtraOutputs<SimplifyWorkflowOutputs<TOutputs>, TActualOutputs>> | AuthoringContract.NoExtraOutputs<SimplifyWorkflowOutputs<TOutputs>, TActualOutputs>,
97
115
  ): CompletedWorkflowBuilder<TInputs, TOutputs>;
98
116
  }
99
117
 
@@ -104,21 +122,17 @@ export interface WorkflowBuilder<
104
122
  export interface CompletedWorkflowBuilder<
105
123
  TInputs extends WorkflowInputValues,
106
124
  TOutputs extends WorkflowOutputValues,
125
+ > extends Omit<
126
+ AuthoringContract.CompletedWorkflowBuilder<TInputs, TOutputs>,
127
+ "description" | "input" | "output" | "worktreeFromInputs" | "run" | "compile"
107
128
  > {
108
129
  description(text: string): CompletedWorkflowBuilder<TInputs, TOutputs>;
109
- input<K extends string, S extends TSchema>(
110
- key: K,
111
- schema: S,
112
- ): CompletedWorkflowBuilder<TInputs & DeclaredEntry<K, S>, TOutputs>;
113
- output<K extends string, S extends TSchema>(
114
- key: K,
115
- schema: S,
116
- ): CompletedWorkflowBuilder<TInputs, TOutputs & DeclaredEntry<K, S>>;
130
+ input<K extends string, S extends TSchema>(key: K, schema: S): CompletedWorkflowBuilder<TInputs & DeclaredEntry<K, S>, TOutputs>;
131
+ output<K extends string, S extends TSchema>(key: K, schema: S): CompletedWorkflowBuilder<TInputs, AccumulateWorkflowOutput<TOutputs, K, S>>;
117
132
  worktreeFromInputs(binding: WorkflowWorktreeInputBinding): CompletedWorkflowBuilder<TInputs, TOutputs>;
118
- run(
119
- fn: WorkflowRunFn<Simplify<TInputs>, SimplifyWorkflowOutputs<TOutputs>>,
133
+ run<TActualOutputs extends SimplifyWorkflowOutputs<TOutputs>>(
134
+ fn: (ctx: WorkflowRunContext<Simplify<TInputs>>) => Promise<AuthoringContract.NoExtraOutputs<SimplifyWorkflowOutputs<TOutputs>, TActualOutputs>> | AuthoringContract.NoExtraOutputs<SimplifyWorkflowOutputs<TOutputs>, TActualOutputs>,
120
135
  ): CompletedWorkflowBuilder<TInputs, TOutputs>;
121
- /** Freeze and return the completed WorkflowDefinition. */
122
136
  compile(): WorkflowDefinition<Simplify<TInputs>, SimplifyWorkflowOutputs<TOutputs>>;
123
137
  }
124
138
 
@@ -162,7 +176,7 @@ function makeBuilder<
162
176
 
163
177
  output<K extends string, S extends TSchema>(key: K, schema: S) {
164
178
  requireNonEmptyString(key, "output key");
165
- return makeBuilder<TInputs, TOutputs & DeclaredEntry<K, S>>({
179
+ return makeBuilder<TInputs, AccumulateWorkflowOutput<TOutputs, K, S>>({
166
180
  ...state,
167
181
  outputs: { ...state.outputs, [key]: schema },
168
182
  });
@@ -178,7 +192,9 @@ function makeBuilder<
178
192
  });
179
193
  },
180
194
 
181
- run(fn: WorkflowRunFn<Simplify<TInputs>, SimplifyWorkflowOutputs<TOutputs>>) {
195
+ run<TActualOutputs extends SimplifyWorkflowOutputs<TOutputs>>(
196
+ fn: (ctx: WorkflowRunContext<Simplify<TInputs>>) => Promise<AuthoringContract.NoExtraOutputs<SimplifyWorkflowOutputs<TOutputs>, TActualOutputs>> | AuthoringContract.NoExtraOutputs<SimplifyWorkflowOutputs<TOutputs>, TActualOutputs>,
197
+ ) {
182
198
  return makeBuilder<TInputs, TOutputs>({
183
199
  ...state,
184
200
  runFn: fn as unknown as WorkflowRunFn<TInputs, WorkflowOutputValues>,
@@ -204,7 +220,7 @@ function makeBuilder<
204
220
  : {}),
205
221
  });
206
222
 
207
- const definition: WorkflowDefinition<Simplify<TInputs>, SimplifyWorkflowOutputs<TOutputs>> = {
223
+ const definition = {
208
224
  __piWorkflow: true,
209
225
  name: state.name,
210
226
  normalizedName,
@@ -213,8 +229,10 @@ function makeBuilder<
213
229
  ...(Object.keys(frozenOutputs).length > 0 ? { outputs: frozenOutputs } : {}),
214
230
  ...(Object.keys(inputBindings).length > 0 ? { inputBindings } : {}),
215
231
  run: state.runFn as unknown as WorkflowRunFn<Simplify<TInputs>, SimplifyWorkflowOutputs<TOutputs>>,
216
- };
232
+ } as WorkflowDefinition<Simplify<TInputs>, SimplifyWorkflowOutputs<TOutputs>>;
217
233
 
234
+ // Stamp before freezing so the WeakSet brand can be attached.
235
+ stampWorkflowDefinition(definition);
218
236
  return Object.freeze(definition) as WorkflowDefinition<Simplify<TInputs>, SimplifyWorkflowOutputs<TOutputs>>;
219
237
  },
220
238
  };
@@ -246,7 +264,7 @@ export function defineWorkflow(name: string): WorkflowBuilder {
246
264
  throw new TypeError("defineWorkflow: name must be a non-empty string");
247
265
  }
248
266
 
249
- const initialState: BuilderState<WorkflowInputValues> = {
267
+ const initialState: BuilderState<{}> = {
250
268
  name,
251
269
  description: "",
252
270
  inputs: {},
@@ -255,8 +273,5 @@ export function defineWorkflow(name: string): WorkflowBuilder {
255
273
  runFn: undefined,
256
274
  };
257
275
 
258
- // Start with an empty output map so excess-property checks engage as soon as
259
- // the first `.output(...)` is declared; a workflow with no declared outputs
260
- // must return `{}` (the executor rejects any undeclared key).
261
- return makeBuilder<WorkflowInputValues, {}>(initialState);
276
+ return makeBuilder<{}, {}>(initialState);
262
277
  }
@@ -1 +1 @@
1
- {"version":3,"file":"atomic-guide-command.d.ts","sourceRoot":"","sources":["../../src/core/atomic-guide-command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D,eAAO,MAAM,yBAAyB,WAAW,CAAC;AAClD,eAAO,MAAM,gCAAgC,qCACT,CAAC;AAqNrC,QAAA,MAAM,cAAc;mBAEV,UAAU;;oBAET,UAAU;0BACJ,oBAAoB;;;mBAI3B,WAAW;;oBAEV,WAAW;0BACL,iBAAiB;;;mBAIxB,SAAS;;oBAER,SAAS;0BACH,0BAA0B;;;mBAIjC,WAAW;;oBAEV,YAAY;0BACN,sBAAsB;;EASpC,CAAC;AAEJ,KAAK,kBAAkB,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1D,KAAK,sBAAsB,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAEzD,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,sBAAsB,CAAC;AAE9D,eAAO,MAAM,yBAAyB,EAAE,SAAS,qBAAqB,EACtB,CAAC;AAiBjD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,GACb,MAAM,IAAI,qBAAqB,CAEjC;AAoCD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAOtE;AAED,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,MAAM,GACb,gBAAgB,EAAE,GAAG,IAAI,CAa3B;AAED,iBAAS,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CActD;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,eAAe,EACrB,GAAG,EAAE,MAAM,GACV,MAAM,CAGR;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,qBAAqB,GAC5B,eAAe,CAEjB","sourcesContent":["import * as path from \"node:path\";\nimport type { AutocompleteItem } from \"@earendil-works/pi-tui\";\nimport { getChangelogPath, parseChangelog } from \"../utils/changelog.ts\";\n\nexport const ATOMIC_GUIDE_COMMAND_NAME = \"atomic\";\nexport const ATOMIC_GUIDE_COMMAND_DESCRIPTION =\n \"Atomic onboarding and help guide\";\n\nconst OVERVIEW = `# Atomic overview\n\nAtomic turns one-off prompts into developer workflows: on-call debugging, repo research that turns into implementation, testing and review loops, and larger multi-stage automation. Use \\`/workflow goal\\` for small-to-medium changes with a clear work surface, exact outcome, and named validation; keep \\`/workflow ralph\\` for larger migrations, broad refactors, and spec-to-PR work. Start Atomic in a project with \\`atomic\\`, then talk to it normally. Use \\`@file\\` to attach files, \\`!command\\` to run shell output through the model, and \\`!!command\\` to run shell output without adding it to context.\n\n## Core session commands\n\n| Command | Use |\n|---|---|\n| \\`/login\\` | configure auth |\n| \\`/model\\` | switch model |\n| \\`/settings\\` | thinking level, theme, message delivery, transport |\n| \\`/new\\`, \\`/resume\\` | start or resume sessions |\n| \\`/tree\\`, \\`/fork\\`, \\`/clone\\` | branch or navigate session history |\n| \\`/compact\\` | summarize older context |\n| \\`/hotkeys\\`, \\`/changelog\\` | local help and release notes |\n\n## Examples of using Atomic\n\n| Goal | How to use |\n|---|---|\n| On-call / broken behavior | Run \\`/run debugger \"Reproduce the failure, patch the root cause, and validate it\"\\` for a focused fix loop, or ask Atomic in chat to build a reusable workflow that does the same |\n| Research → spec → implementation | Chain \\`/skill:research-codebase\\` → \\`/skill:create-spec\\` → \\`/workflow goal objective=\"...\"\\` for bounded scoped work with explicit validation; use \\`/workflow ralph ...\\` when the work needs planning, broad refactoring, or PR prep |\n| Testing / regression hardening | Run \\`/skill:tdd\\` for test-first work, then \\`/parallel-review current diff\\`, then land the change |\n| Large repo discovery | Run \\`/parallel codebase-locator \"map the area\" -> codebase-analyzer \"trace the current flow\" -> codebase-pattern-finder \"find patterns\" --bg\\`, or \\`/workflow deep-research-codebase\\` for whole-repo synthesis |\n| UI / product polish | Run \\`/skill:impeccable\\` for interface critique and refinement, or \\`/workflow open-claude-design\\` for generation + refinement loops |\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`deep-research-codebase\\` | broad repo or cross-cutting research before you decide what to change (for one area, use \\`/skill:research-codebase\\`; this indexes the whole repo) | \\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\` |\n| \\`goal\\` | small-to-medium scoped changes when you can name the work surface, outcome, and validation; keeps receipts in a ledger and stops as \\`complete\\`, \\`blocked\\`, or \\`needs_human\\` | \\`/workflow goal objective=\"Implement specs/<date>-<topic>.md, run focused tests, and validate the changed behavior\"\\` |\n| \\`ralph\\` | larger migrations, broad refactors, multi-package changes, and spec-to-PR work where you want Atomic to plan, delegate, simplify, review, iterate, and prepare a PR report | \\`/workflow ralph prompt=\"Plan and implement specs/<date>-<topic>.md, then prepare the PR\"\\` |\n| \\`open-claude-design\\` | UI and design-system work that benefits from generation and refinement loops | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow list\\` to see what is available and \\`/workflow inputs <name>\\` to inspect inputs in your environment.\n\n## Top skills\n\n| Skill | When to use | How to run |\n|---|---|---|\n| \\`research-codebase\\` | write a grounded research artifact for one subsystem or question | \\`/skill:research-codebase how the rate limiter works in src/middleware/\\` |\n| \\`create-spec\\` | turn research into an implementation-ready plan | \\`/skill:create-spec from research/docs/<date>-<topic>.md\\` |\n| \\`tdd\\` | do test-first feature or bug work | \\`/skill:tdd\\` |\n| \\`prompt-engineer\\` | tighten a vague prompt before a long run | \\`/skill:prompt-engineer Draft a sharper implementation prompt for ...\\` |\n| \\`subagent\\` | learn delegation patterns and exact \\`/run\\`, \\`/parallel\\`, and \\`/chain\\` usage | \\`/skill:subagent\\` |\n| \\`impeccable\\` | critique or refine frontend and product UI | \\`/skill:impeccable\\` |\n\n## Subagents\n\nSubagents are focused child Atomic sessions you can point at one job inside the repo.\n\n| Built-in subagent | Use |\n|---|---|\n| \\`codebase-locator\\` | find relevant files, tests, entrypoints, and configs |\n| \\`codebase-analyzer\\` | explain current behavior with file:line refs |\n| \\`codebase-pattern-finder\\` | find existing code to model after |\n| \\`debugger\\` | reproduce, diagnose, and fix broken behavior |\n\nHow the direct commands map to repo work:\n- \\`/run\\` = one specialist on one job, for example \\`/run codebase-locator \"Map the webhook retry flow\"\\`\n- \\`/parallel\\` = several independent specialists at once, for example \\`/parallel codebase-locator \"map retry files\" -> codebase-pattern-finder \"find existing retry/backoff patterns\" -> codebase-online-researcher \"research current retry guidance\" --bg\\`\n- \\`/chain\\` = ordered handoffs, for example \\`/chain codebase-locator \"find the auth files\" -> codebase-analyzer \"trace the auth flow\" -> debugger \"patch the failing auth edge case\"\\`\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see the pieces used on a code task\n\\`/atomic workflows\\` — learn when to use workflows`;\n\nconst EXAMPLE = `# Practical example\n\nThis is an example of a spec-driven development process using Atomic workflows. Use it when you are new to a repo or the task has non-trivial scope. Type the examples below into the Atomic TUI chat after starting \\`atomic\\` in your project.\n\n## 1. Research what exists\n\nUse \\`/skill:research-codebase\\` for a scoped area, subsystem, or directory:\n\n\\`/skill:research-codebase how the rate limiter works in src/middleware/\\`\n\nUse \\`deep-research-codebase\\` when the answer spans the whole repo or a cross-cutting implementation path:\n\n\\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\`\n\nIf the research prompt is vague, tighten it first with \\`/skill:prompt-engineer\\`:\n\n\\`/skill:prompt-engineer Draft a sharper repo-research prompt for understanding payment retries end to end, including retries, queues, and failure handling.\\`\n\n## 2. Create a spec when requirements are fuzzy\n\nSkip this if the implementation request is already precise.\n\n\\`/skill:create-spec from research/docs/<date>-<topic>.md\\`\n\n## 3. Implement with review built in\n\nFor ordinary work, ask Atomic directly and require validation:\n\n\\`Implement the approved spec in specs/<date>-<topic>.md. Run focused tests and summarize validation.\\`\n\nFor small-to-medium scoped changes where you can identify the work surface, exact outcome, and validation, use \\`goal\\`:\n\n\\`/workflow goal objective=\"Implement specs/<date>-<topic>.md, run focused tests, and finish when the documented behavior is validated\"\\`\n\nFor larger migrations, broad refactors, multi-package changes, or spec-to-PR work, use \\`ralph\\`:\n\n\\`/workflow ralph prompt=\"Plan and implement specs/<date>-<topic>.md, then prepare the PR\"\\`\n\n## 4. Decide and land\n\nIf you used \\`goal\\`, the workflow already persisted receipts in a goal ledger and reviewer-gated completion. Use its final status — \\`complete\\`, \\`blocked\\`, or \\`needs_human\\` — plus the remaining-work report to decide whether to ship, unblock, or clarify.\n\nIf you used \\`ralph\\`, the workflow planned the approach, delegated implementation through sub-agents, simplified, reviewed, iterated, and prepared a pull-request report. Use its review feedback and PR report to decide whether to ship or iterate again.\n\nIf you implemented directly instead of using a workflow, you can still run:\n\n\\`/parallel-review current diff\\`\n\nAtomic will synthesize reviewer feedback and ask before applying fixes.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic workflows\\` — learn when to use workflows\n\\`/atomic overview\\` — quick refresh`;\n\nconst WORKFLOWS = `# Workflows primer\n\nA workflow is a TypeScript-defined pipeline built with \\`defineWorkflow(...).run(...).compile()\\`. It can run tasks, chains, parallel fan-out, human-in-the-loop prompts, background status, and model fallback chains.\n\nYou do not have to write TypeScript to add one. Describe the workflow you want in plain chat — goal, inputs, stages, which steps are parallel or sequential, handoff/output shape, and any model or thinking-level preferences — and Atomic will use the workflow docs to scaffold a reusable definition under \\`.atomic/workflows/\\` and reload it for you. Hand-edit the TypeScript afterward when you want precise control.\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`deep-research-codebase\\` | broad repo or cross-cutting research before you decide what to change (for one area, use \\`/skill:research-codebase\\`; this indexes the whole repo) | \\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\` |\n| \\`goal\\` | small-to-medium scoped changes with a clear outcome and named validation | \\`/workflow goal objective=\"Update the CLI docs, include one usage example, and verify the docs build passes\"\\` |\n| \\`ralph\\` | larger migrations, broad refactors, multi-package changes, and spec-to-PR work | \\`/workflow ralph prompt=\"Plan a database-layer migration, implement it, review it, and prepare the PR\"\\` |\n| \\`open-claude-design\\` | frontend and product design work | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow inputs <name>\\` to inspect the exact inputs in your environment.\n\nUse \\`/skill:research-codebase ...\\` when you want research on one subsystem, directory, or focused question. Use \\`/workflow deep-research-codebase ...\\` when the answer needs end-to-end tracing across many parts of the repo.\n\nIf you are drafting research, reviewer, or synthesis prompts for a workflow, use \\`/skill:prompt-engineer\\` first. It is a good fit when a stage prompt feels vague, overloaded, or underspecified.\n\n## What good workflow authoring looks like\n\nA good workflow request is explicit about stage purpose, model choice, handoff, and the decision each step must return.\n\nExample: ask Atomic in chat with something like this:\n\n~~~text\nCreate a reusable workflow called review-changes.\n\nIt should accept one required text input called target for a diff, PR summary, or review target.\n\nRun two independent review stages in parallel with fresh context:\n- one reviewer focused on correctness, regressions, and missing tests using openai-codex/gpt-5.5 at xhigh thinking\n- one reviewer focused on edge cases, maintainability, and hidden risks using anthropic/claude-opus-4-8 at xhigh thinking\n\nThen add an aggregate stage that consolidates both reviews, deduplicates overlap, keeps only evidence-backed issues, and separates blockers from optional suggestions using openai/gpt-5.5 at high thinking.\n\nFinally add an adjudicate stage using anthropic/claude-sonnet-4 at high thinking that decides what to fix now, what to defer, and what to reject. Return a short action list with rationale.\n\nThe workflow should return structured output with consolidated_review and decision fields.\n~~~\n\nWhy this is good:\n- it names the workflow and required input\n- it specifies which stages are parallel vs sequential\n- each stage has one job\n- it defines the handoff and final outputs\n- it calls out model choice and thinking level where that matters\n\n## Run and inspect\n\n\\`/workflow list\\`\n\n\\`/workflow inputs goal\\`\n\n\\`/workflow goal objective=\"Fix the settings form validation bug, add the focused test, and finish when invalid emails show the inline error without submitting\"\\`\n\n\\`/workflow inputs ralph\\`\n\n\\`/workflow ralph prompt=\"Migrate the database layer to Drizzle and prepare the PR\"\\`\n\n\\`/workflow status\\`\n\n\\`/workflow connect <run-id>\\`\n\n\\`/workflow interrupt <run-id>\\`\n\n\\`/workflow resume <run-id>\\`\n\nWorkflows run as background tasks. Use F2 or \\`/workflow connect <run-id>\\` for the graph viewer. Human-in-the-loop prompts appear there, not as chat modals, and awaiting-input states do not wake the main chat agent. Completion and failure notices are steered back into the main chat; answers submitted in the workflow UI interrupt stale main-chat questions so the model does not ask again.\n\n## Author your own\n\nDescribe your workflow in plain chat — say what you want the workflow to accomplish, what inputs it should accept, what stages should run, and what final output or decision it should return. Atomic will use the workflow docs to scaffold a reusable definition under \\`.atomic/workflows/\\`, ask clarifying questions when stage purpose, models, or handoffs are ambiguous, and run \\`/workflow reload\\` so you can launch it immediately.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see workflows in a normal task flow\n\\`/atomic overview\\` — quick refresh`;\n\nconst GUIDE_SECTIONS = [\n {\n name: \"overview\",\n aliases: [],\n label: \"overview\",\n description: \"30-second overview\",\n render: () => OVERVIEW,\n },\n {\n name: \"workflows\",\n aliases: [\"workflow\"],\n label: \"workflows\",\n description: \"Workflow primer\",\n render: () => WORKFLOWS,\n },\n {\n name: \"example\",\n aliases: [\"examples\"],\n label: \"example\",\n description: \"Practical first workflow\",\n render: () => EXAMPLE,\n },\n {\n name: \"whats-new\",\n aliases: [\"what's new\", \"whats new\", \"news\", \"updates\", \"changelog\"],\n label: \"what's new\",\n description: \"Recent release notes\",\n render: readLatestStableChangelog,\n },\n] as const satisfies readonly {\n readonly name: string;\n readonly aliases: readonly string[];\n readonly label: string;\n readonly description: string;\n readonly render: (cwd: string) => string;\n}[];\n\ntype AtomicGuideSection = (typeof GUIDE_SECTIONS)[number];\ntype AtomicGuideSectionName = AtomicGuideSection[\"name\"];\n\nexport type AtomicGuideHelpChoice = AtomicGuideSection[\"label\"];\n\nexport type AtomicGuideMode = \"help\" | AtomicGuideSectionName;\n\nexport const ATOMIC_GUIDE_HELP_CHOICES: readonly AtomicGuideHelpChoice[] =\n GUIDE_SECTIONS.map((section) => section.label);\n\nconst GUIDE_SECTIONS_BY_NAME = new Map<\n AtomicGuideSectionName,\n AtomicGuideSection\n>(GUIDE_SECTIONS.map((section) => [section.name, section]));\nconst GUIDE_SECTIONS_BY_LABEL = new Map<string, AtomicGuideSection>(\n GUIDE_SECTIONS.map((section) => [section.label, section]),\n);\nconst GUIDE_SECTIONS_BY_INPUT = new Map<string, AtomicGuideSection>(\n GUIDE_SECTIONS.flatMap((section) =>\n [section.name, section.label, ...section.aliases].map(\n (input) => [input, section] as const,\n ),\n ),\n);\n\nexport function isAtomicGuideHelpChoice(\n choice: string,\n): choice is AtomicGuideHelpChoice {\n return GUIDE_SECTIONS_BY_LABEL.has(choice);\n}\n\nconst ATOMIC_GUIDE_TRAILING_PUNCTUATION = \"?!.,;:\";\n\nfunction stripTrailingAtomicGuidePunctuation(value: string): string {\n let end = value.length;\n while (\n end > 0 &&\n ATOMIC_GUIDE_TRAILING_PUNCTUATION.includes(value.charAt(end - 1))\n ) {\n end--;\n }\n return value.slice(0, end);\n}\n\nfunction getGuideSectionForChoice(\n choice: string,\n): AtomicGuideSection | undefined {\n return GUIDE_SECTIONS_BY_LABEL.get(choice);\n}\n\nfunction getGuideSectionForMode(\n mode: AtomicGuideSectionName,\n): AtomicGuideSection {\n const section = GUIDE_SECTIONS_BY_NAME.get(mode);\n if (!section) throw new Error(`Unknown Atomic guide section: ${mode}`);\n return section;\n}\n\nfunction getAtomicGuideHelpMenu(): string {\n const sectionHelp = GUIDE_SECTIONS.map(\n (section) => `- \\`${section.label}\\` — run \\`/atomic ${section.label}\\``,\n ).join(\"\\n\");\n return `# Atomic\\n\\nSelect where to start:\\n\\n${sectionHelp}`;\n}\n\nexport function normalizeAtomicGuideMode(args: string): AtomicGuideMode {\n const normalized = stripTrailingAtomicGuidePunctuation(\n args.trim().toLowerCase(),\n );\n if (!normalized) return \"help\";\n\n return GUIDE_SECTIONS_BY_INPUT.get(normalized)?.name ?? \"help\";\n}\n\nexport function getAtomicGuideArgumentCompletions(\n prefix: string,\n): AutocompleteItem[] | null {\n const query = prefix.trim().toLowerCase();\n const items = GUIDE_SECTIONS.map((section) => ({\n value: section.label,\n label: section.label,\n description: section.description,\n }));\n const filtered = query\n ? items.filter(\n (item) => item.value.startsWith(query) || item.label.startsWith(query),\n )\n : items;\n return filtered.length > 0 ? filtered : null;\n}\n\nfunction readLatestStableChangelog(cwd: string): string {\n const changelogPath = getChangelogPath();\n const stableSections = parseChangelog(changelogPath)\n .filter((entry) => entry.prerelease === null)\n .slice(0, 3)\n .map((entry) => entry.content.trim())\n .filter(Boolean);\n\n if (stableSections.length === 0) {\n return `# What's new\\n\\nNo stable release sections were found. Try \\`/changelog\\` for the interactive changelog viewer.\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n }\n\n const relativePath = path.relative(cwd, changelogPath) || changelogPath;\n return `# What's new\\n\\n${stableSections.join(\"\\n\\n\")}\\n\\nSource: \\`${relativePath}\\`\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n}\n\nexport function getAtomicGuideMessage(\n mode: AtomicGuideMode,\n cwd: string,\n): string {\n if (mode === \"help\") return getAtomicGuideHelpMenu();\n return getGuideSectionForMode(mode).render(cwd);\n}\n\nexport function atomicGuideModeForChoice(\n choice: AtomicGuideHelpChoice,\n): AtomicGuideMode {\n return getGuideSectionForChoice(choice)?.name ?? \"help\";\n}\n"]}
1
+ {"version":3,"file":"atomic-guide-command.d.ts","sourceRoot":"","sources":["../../src/core/atomic-guide-command.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D,eAAO,MAAM,yBAAyB,WAAW,CAAC;AAClD,eAAO,MAAM,gCAAgC,qCACT,CAAC;AAqNrC,QAAA,MAAM,cAAc;mBAEV,UAAU;;oBAET,UAAU;0BACJ,oBAAoB;;;mBAI3B,WAAW;;oBAEV,WAAW;0BACL,iBAAiB;;;mBAIxB,SAAS;;oBAER,SAAS;0BACH,0BAA0B;;;mBAIjC,WAAW;;oBAEV,YAAY;0BACN,sBAAsB;;EASpC,CAAC;AAEJ,KAAK,kBAAkB,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1D,KAAK,sBAAsB,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAEzD,MAAM,MAAM,qBAAqB,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,sBAAsB,CAAC;AAE9D,eAAO,MAAM,yBAAyB,EAAE,SAAS,qBAAqB,EACtB,CAAC;AAiBjD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,GACb,MAAM,IAAI,qBAAqB,CAEjC;AAoCD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAOtE;AAED,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,MAAM,GACb,gBAAgB,EAAE,GAAG,IAAI,CAa3B;AAED,iBAAS,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CActD;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,eAAe,EACrB,GAAG,EAAE,MAAM,GACV,MAAM,CAGR;AAED,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,qBAAqB,GAC5B,eAAe,CAEjB","sourcesContent":["import * as path from \"node:path\";\nimport type { AutocompleteItem } from \"@earendil-works/pi-tui\";\nimport { getChangelogPath, parseChangelog } from \"../utils/changelog.ts\";\n\nexport const ATOMIC_GUIDE_COMMAND_NAME = \"atomic\";\nexport const ATOMIC_GUIDE_COMMAND_DESCRIPTION =\n \"Atomic onboarding and help guide\";\n\nconst OVERVIEW = `# Atomic overview\n\nAtomic turns one-off prompts into developer workflows: on-call debugging, repo research that turns into implementation, testing and review loops, and larger multi-stage automation. Use \\`/workflow goal\\` for small-to-medium changes with a clear work surface, exact outcome, and named validation; keep \\`/workflow ralph\\` for larger migrations, broad refactors, and spec-to-PR work. Start Atomic in a project with \\`atomic\\`, then talk to it normally. Use \\`@file\\` to attach files, \\`!command\\` to run shell output through the model, and \\`!!command\\` to run shell output without adding it to context.\n\n## Core session commands\n\n| Command | Use |\n|---|---|\n| \\`/login\\` | configure auth |\n| \\`/model\\` | switch model |\n| \\`/settings\\` | thinking level, theme, message delivery, transport |\n| \\`/new\\`, \\`/resume\\` | start or resume sessions |\n| \\`/tree\\`, \\`/fork\\`, \\`/clone\\` | branch or navigate session history |\n| \\`/compact\\` | summarize older context |\n| \\`/hotkeys\\`, \\`/changelog\\` | local help and release notes |\n\n## Examples of using Atomic\n\n| Goal | How to use |\n|---|---|\n| On-call / broken behavior | Run \\`/run debugger \"Reproduce the failure, patch the root cause, and validate it\"\\` for a focused fix loop, or ask Atomic in chat to build a reusable workflow that does the same |\n| Research → spec → implementation | Chain \\`/skill:research-codebase\\` → \\`/skill:create-spec\\` → \\`/workflow goal objective=\"...\"\\` for bounded scoped work with explicit validation; use \\`/workflow ralph ...\\` when the work needs planning, broad refactoring, or PR prep |\n| Testing / regression hardening | Run \\`/skill:tdd\\` for test-first work, then \\`/parallel-review current diff\\`, then land the change |\n| Large repo discovery | Run \\`/parallel codebase-locator \"map the area\" -> codebase-analyzer \"trace the current flow\" -> codebase-pattern-finder \"find patterns\" --bg\\`, or \\`/workflow deep-research-codebase\\` for whole-repo synthesis |\n| UI / product polish | Run \\`/skill:impeccable\\` for interface critique and refinement, or \\`/workflow open-claude-design\\` for generation + refinement loops |\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`deep-research-codebase\\` | broad repo or cross-cutting research before you decide what to change (for one area, use \\`/skill:research-codebase\\`; this indexes the whole repo) | \\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\` |\n| \\`goal\\` | small-to-medium scoped changes when you can name the work surface, outcome, and validation; keeps receipts in a ledger and stops as \\`complete\\`, \\`blocked\\`, or \\`needs_human\\` | \\`/workflow goal objective=\"Implement specs/<date>-<topic>.md, run focused tests, and validate the changed behavior\"\\` |\n| \\`ralph\\` | larger migrations, broad refactors, multi-package changes, and spec-to-PR work where you want Atomic to plan, delegate, simplify, review, iterate, and prepare a PR report | \\`/workflow ralph prompt=\"Plan and implement specs/<date>-<topic>.md, then prepare the PR\"\\` |\n| \\`open-claude-design\\` | UI and design-system work that benefits from generation and refinement loops | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow list\\` to see what is available and \\`/workflow inputs <name>\\` to inspect inputs in your environment.\n\n## Top skills\n\n| Skill | When to use | How to run |\n|---|---|---|\n| \\`research-codebase\\` | write a grounded research artifact for one subsystem or question | \\`/skill:research-codebase how the rate limiter works in src/middleware/\\` |\n| \\`create-spec\\` | turn research into an implementation-ready plan | \\`/skill:create-spec from research/docs/<date>-<topic>.md\\` |\n| \\`tdd\\` | do test-first feature or bug work | \\`/skill:tdd\\` |\n| \\`prompt-engineer\\` | tighten a vague prompt before a long run | \\`/skill:prompt-engineer Draft a sharper implementation prompt for ...\\` |\n| \\`subagent\\` | learn delegation patterns and exact \\`/run\\`, \\`/parallel\\`, and \\`/chain\\` usage | \\`/skill:subagent\\` |\n| \\`impeccable\\` | critique or refine frontend and product UI | \\`/skill:impeccable\\` |\n\n## Subagents\n\nSubagents are focused child Atomic sessions you can point at one job inside the repo.\n\n| Built-in subagent | Use |\n|---|---|\n| \\`codebase-locator\\` | find relevant files, tests, entrypoints, and configs |\n| \\`codebase-analyzer\\` | explain current behavior with file:line refs |\n| \\`codebase-pattern-finder\\` | find existing code to model after |\n| \\`debugger\\` | reproduce, diagnose, and fix broken behavior |\n\nHow the direct commands map to repo work:\n- \\`/run\\` = one specialist on one job, for example \\`/run codebase-locator \"Map the webhook retry flow\"\\`\n- \\`/parallel\\` = several independent specialists at once, for example \\`/parallel codebase-locator \"map retry files\" -> codebase-pattern-finder \"find existing retry/backoff patterns\" -> codebase-online-researcher \"research current retry guidance\" --bg\\`\n- \\`/chain\\` = ordered handoffs, for example \\`/chain codebase-locator \"find the auth files\" -> codebase-analyzer \"trace the auth flow\" -> debugger \"patch the failing auth edge case\"\\`\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see the pieces used on a code task\n\\`/atomic workflows\\` — learn when to use workflows`;\n\nconst EXAMPLE = `# Practical example\n\nThis is an example of a spec-driven development process using Atomic workflows. Use it when you are new to a repo or the task has non-trivial scope. Type the examples below into the Atomic TUI chat after starting \\`atomic\\` in your project.\n\n## 1. Research what exists\n\nUse \\`/skill:research-codebase\\` for a scoped area, subsystem, or directory:\n\n\\`/skill:research-codebase how the rate limiter works in src/middleware/\\`\n\nUse \\`deep-research-codebase\\` when the answer spans the whole repo or a cross-cutting implementation path:\n\n\\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\`\n\nIf the research prompt is vague, tighten it first with \\`/skill:prompt-engineer\\`:\n\n\\`/skill:prompt-engineer Draft a sharper repo-research prompt for understanding payment retries end to end, including retries, queues, and failure handling.\\`\n\n## 2. Create a spec when requirements are fuzzy\n\nSkip this if the implementation request is already precise.\n\n\\`/skill:create-spec from research/docs/<date>-<topic>.md\\`\n\n## 3. Implement with review built in\n\nFor ordinary work, ask Atomic directly and require validation:\n\n\\`Implement the approved spec in specs/<date>-<topic>.md. Run focused tests and summarize validation.\\`\n\nFor small-to-medium scoped changes where you can identify the work surface, exact outcome, and validation, use \\`goal\\`:\n\n\\`/workflow goal objective=\"Implement specs/<date>-<topic>.md, run focused tests, and finish when the documented behavior is validated\"\\`\n\nFor larger migrations, broad refactors, multi-package changes, or spec-to-PR work, use \\`ralph\\`:\n\n\\`/workflow ralph prompt=\"Plan and implement specs/<date>-<topic>.md, then prepare the PR\"\\`\n\n## 4. Decide and land\n\nIf you used \\`goal\\`, the workflow already persisted receipts in a goal ledger and reviewer-gated completion. Use its final status — \\`complete\\`, \\`blocked\\`, or \\`needs_human\\` — plus the remaining-work report to decide whether to ship, unblock, or clarify.\n\nIf you used \\`ralph\\`, the workflow planned the approach, delegated implementation through sub-agents, simplified, reviewed, iterated, and prepared a pull-request report. Use its review feedback and PR report to decide whether to ship or iterate again.\n\nIf you implemented directly instead of using a workflow, you can still run:\n\n\\`/parallel-review current diff\\`\n\nAtomic will synthesize reviewer feedback and ask before applying fixes.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic workflows\\` — learn when to use workflows\n\\`/atomic overview\\` — quick refresh`;\n\nconst WORKFLOWS = `# Workflows primer\n\nA workflow is a TypeScript-defined pipeline exported from \\`defineWorkflow(...).compile()\\`. It can run tasks, chains, parallel fan-out, human-in-the-loop prompts, background status, and model fallback chains.\n\nYou do not have to write TypeScript to add one. Describe the workflow you want in plain chat — goal, inputs, stages, which steps are parallel or sequential, handoff/output shape, and any model or thinking-level preferences — and Atomic will use the workflow docs to scaffold a reusable definition under \\`.atomic/workflows/\\` and reload it for you. Hand-edit the TypeScript afterward when you want precise control.\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`deep-research-codebase\\` | broad repo or cross-cutting research before you decide what to change (for one area, use \\`/skill:research-codebase\\`; this indexes the whole repo) | \\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\` |\n| \\`goal\\` | small-to-medium scoped changes with a clear outcome and named validation | \\`/workflow goal objective=\"Update the CLI docs, include one usage example, and verify the docs build passes\"\\` |\n| \\`ralph\\` | larger migrations, broad refactors, multi-package changes, and spec-to-PR work | \\`/workflow ralph prompt=\"Plan a database-layer migration, implement it, review it, and prepare the PR\"\\` |\n| \\`open-claude-design\\` | frontend and product design work | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow inputs <name>\\` to inspect the exact inputs in your environment.\n\nUse \\`/skill:research-codebase ...\\` when you want research on one subsystem, directory, or focused question. Use \\`/workflow deep-research-codebase ...\\` when the answer needs end-to-end tracing across many parts of the repo.\n\nIf you are drafting research, reviewer, or synthesis prompts for a workflow, use \\`/skill:prompt-engineer\\` first. It is a good fit when a stage prompt feels vague, overloaded, or underspecified.\n\n## What good workflow authoring looks like\n\nA good workflow request is explicit about stage purpose, model choice, handoff, and the decision each step must return.\n\nExample: ask Atomic in chat with something like this:\n\n~~~text\nCreate a reusable workflow called review-changes.\n\nIt should accept one required text input called target for a diff, PR summary, or review target.\n\nRun two independent review stages in parallel with fresh context:\n- one reviewer focused on correctness, regressions, and missing tests using openai-codex/gpt-5.5 at xhigh thinking\n- one reviewer focused on edge cases, maintainability, and hidden risks using anthropic/claude-opus-4-8 at xhigh thinking\n\nThen add an aggregate stage that consolidates both reviews, deduplicates overlap, keeps only evidence-backed issues, and separates blockers from optional suggestions using openai/gpt-5.5 at high thinking.\n\nFinally add an adjudicate stage using anthropic/claude-sonnet-4 at high thinking that decides what to fix now, what to defer, and what to reject. Return a short action list with rationale.\n\nThe workflow should return structured output with consolidated_review and decision fields.\n~~~\n\nWhy this is good:\n- it names the workflow and required input\n- it specifies which stages are parallel vs sequential\n- each stage has one job\n- it defines the handoff and final outputs\n- it calls out model choice and thinking level where that matters\n\n## Run and inspect\n\n\\`/workflow list\\`\n\n\\`/workflow inputs goal\\`\n\n\\`/workflow goal objective=\"Fix the settings form validation bug, add the focused test, and finish when invalid emails show the inline error without submitting\"\\`\n\n\\`/workflow inputs ralph\\`\n\n\\`/workflow ralph prompt=\"Migrate the database layer to Drizzle and prepare the PR\"\\`\n\n\\`/workflow status\\`\n\n\\`/workflow connect <run-id>\\`\n\n\\`/workflow interrupt <run-id>\\`\n\n\\`/workflow resume <run-id>\\`\n\nWorkflows run as background tasks. Use F2 or \\`/workflow connect <run-id>\\` for the graph viewer. Human-in-the-loop prompts appear there, not as chat modals, and awaiting-input states do not wake the main chat agent. Completion and failure notices are steered back into the main chat; answers submitted in the workflow UI interrupt stale main-chat questions so the model does not ask again.\n\n## Author your own\n\nDescribe your workflow in plain chat — say what you want the workflow to accomplish, what inputs it should accept, what stages should run, and what final output or decision it should return. Atomic will use the workflow docs to scaffold a reusable definition under \\`.atomic/workflows/\\`, ask clarifying questions when stage purpose, models, or handoffs are ambiguous, and run \\`/workflow reload\\` so you can launch it immediately.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see workflows in a normal task flow\n\\`/atomic overview\\` — quick refresh`;\n\nconst GUIDE_SECTIONS = [\n {\n name: \"overview\",\n aliases: [],\n label: \"overview\",\n description: \"30-second overview\",\n render: () => OVERVIEW,\n },\n {\n name: \"workflows\",\n aliases: [\"workflow\"],\n label: \"workflows\",\n description: \"Workflow primer\",\n render: () => WORKFLOWS,\n },\n {\n name: \"example\",\n aliases: [\"examples\"],\n label: \"example\",\n description: \"Practical first workflow\",\n render: () => EXAMPLE,\n },\n {\n name: \"whats-new\",\n aliases: [\"what's new\", \"whats new\", \"news\", \"updates\", \"changelog\"],\n label: \"what's new\",\n description: \"Recent release notes\",\n render: readLatestStableChangelog,\n },\n] as const satisfies readonly {\n readonly name: string;\n readonly aliases: readonly string[];\n readonly label: string;\n readonly description: string;\n readonly render: (cwd: string) => string;\n}[];\n\ntype AtomicGuideSection = (typeof GUIDE_SECTIONS)[number];\ntype AtomicGuideSectionName = AtomicGuideSection[\"name\"];\n\nexport type AtomicGuideHelpChoice = AtomicGuideSection[\"label\"];\n\nexport type AtomicGuideMode = \"help\" | AtomicGuideSectionName;\n\nexport const ATOMIC_GUIDE_HELP_CHOICES: readonly AtomicGuideHelpChoice[] =\n GUIDE_SECTIONS.map((section) => section.label);\n\nconst GUIDE_SECTIONS_BY_NAME = new Map<\n AtomicGuideSectionName,\n AtomicGuideSection\n>(GUIDE_SECTIONS.map((section) => [section.name, section]));\nconst GUIDE_SECTIONS_BY_LABEL = new Map<string, AtomicGuideSection>(\n GUIDE_SECTIONS.map((section) => [section.label, section]),\n);\nconst GUIDE_SECTIONS_BY_INPUT = new Map<string, AtomicGuideSection>(\n GUIDE_SECTIONS.flatMap((section) =>\n [section.name, section.label, ...section.aliases].map(\n (input) => [input, section] as const,\n ),\n ),\n);\n\nexport function isAtomicGuideHelpChoice(\n choice: string,\n): choice is AtomicGuideHelpChoice {\n return GUIDE_SECTIONS_BY_LABEL.has(choice);\n}\n\nconst ATOMIC_GUIDE_TRAILING_PUNCTUATION = \"?!.,;:\";\n\nfunction stripTrailingAtomicGuidePunctuation(value: string): string {\n let end = value.length;\n while (\n end > 0 &&\n ATOMIC_GUIDE_TRAILING_PUNCTUATION.includes(value.charAt(end - 1))\n ) {\n end--;\n }\n return value.slice(0, end);\n}\n\nfunction getGuideSectionForChoice(\n choice: string,\n): AtomicGuideSection | undefined {\n return GUIDE_SECTIONS_BY_LABEL.get(choice);\n}\n\nfunction getGuideSectionForMode(\n mode: AtomicGuideSectionName,\n): AtomicGuideSection {\n const section = GUIDE_SECTIONS_BY_NAME.get(mode);\n if (!section) throw new Error(`Unknown Atomic guide section: ${mode}`);\n return section;\n}\n\nfunction getAtomicGuideHelpMenu(): string {\n const sectionHelp = GUIDE_SECTIONS.map(\n (section) => `- \\`${section.label}\\` — run \\`/atomic ${section.label}\\``,\n ).join(\"\\n\");\n return `# Atomic\\n\\nSelect where to start:\\n\\n${sectionHelp}`;\n}\n\nexport function normalizeAtomicGuideMode(args: string): AtomicGuideMode {\n const normalized = stripTrailingAtomicGuidePunctuation(\n args.trim().toLowerCase(),\n );\n if (!normalized) return \"help\";\n\n return GUIDE_SECTIONS_BY_INPUT.get(normalized)?.name ?? \"help\";\n}\n\nexport function getAtomicGuideArgumentCompletions(\n prefix: string,\n): AutocompleteItem[] | null {\n const query = prefix.trim().toLowerCase();\n const items = GUIDE_SECTIONS.map((section) => ({\n value: section.label,\n label: section.label,\n description: section.description,\n }));\n const filtered = query\n ? items.filter(\n (item) => item.value.startsWith(query) || item.label.startsWith(query),\n )\n : items;\n return filtered.length > 0 ? filtered : null;\n}\n\nfunction readLatestStableChangelog(cwd: string): string {\n const changelogPath = getChangelogPath();\n const stableSections = parseChangelog(changelogPath)\n .filter((entry) => entry.prerelease === null)\n .slice(0, 3)\n .map((entry) => entry.content.trim())\n .filter(Boolean);\n\n if (stableSections.length === 0) {\n return `# What's new\\n\\nNo stable release sections were found. Try \\`/changelog\\` for the interactive changelog viewer.\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n }\n\n const relativePath = path.relative(cwd, changelogPath) || changelogPath;\n return `# What's new\\n\\n${stableSections.join(\"\\n\\n\")}\\n\\nSource: \\`${relativePath}\\`\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n}\n\nexport function getAtomicGuideMessage(\n mode: AtomicGuideMode,\n cwd: string,\n): string {\n if (mode === \"help\") return getAtomicGuideHelpMenu();\n return getGuideSectionForMode(mode).render(cwd);\n}\n\nexport function atomicGuideModeForChoice(\n choice: AtomicGuideHelpChoice,\n): AtomicGuideMode {\n return getGuideSectionForChoice(choice)?.name ?? \"help\";\n}\n"]}
@@ -130,7 +130,7 @@ Where to next:
130
130
  \`/atomic overview\` — quick refresh`;
131
131
  const WORKFLOWS = `# Workflows primer
132
132
 
133
- A workflow is a TypeScript-defined pipeline built with \`defineWorkflow(...).run(...).compile()\`. It can run tasks, chains, parallel fan-out, human-in-the-loop prompts, background status, and model fallback chains.
133
+ A workflow is a TypeScript-defined pipeline exported from \`defineWorkflow(...).compile()\`. It can run tasks, chains, parallel fan-out, human-in-the-loop prompts, background status, and model fallback chains.
134
134
 
135
135
  You do not have to write TypeScript to add one. Describe the workflow you want in plain chat — goal, inputs, stages, which steps are parallel or sequential, handoff/output shape, and any model or thinking-level preferences — and Atomic will use the workflow docs to scaffold a reusable definition under \`.atomic/workflows/\` and reload it for you. Hand-edit the TypeScript afterward when you want precise control.
136
136
 
@@ -1 +1 @@
1
- {"version":3,"file":"atomic-guide-command.js","sourceRoot":"","sources":["../../src/core/atomic-guide-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEzE,MAAM,CAAC,MAAM,yBAAyB,GAAG,QAAQ,CAAC;AAClD,MAAM,CAAC,MAAM,gCAAgC,GAC3C,kCAAkC,CAAC;AAErC,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oDAqEmC,CAAC;AAErD,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCAuDqB,CAAC;AAEtC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCAiFmB,CAAC;AAEtC,MAAM,cAAc,GAAG;IACrB;QACE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,EAAE;QACX,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,oBAAoB;QACjC,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ;KACvB;IACD;QACE,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,CAAC,UAAU,CAAC;QACrB,KAAK,EAAE,WAAW;QAClB,WAAW,EAAE,iBAAiB;QAC9B,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS;KACxB;IACD;QACE,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,CAAC,UAAU,CAAC;QACrB,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,0BAA0B;QACvC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO;KACtB;IACD;QACE,IA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,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,MAA6B;IAE7B,OAAO,wBAAwB,CAAC,MAAM,CAAC,EAAE,IAAI,IAAI,MAAM,CAAC;AAC1D,CAAC","sourcesContent":["import * as path from \"node:path\";\nimport type { AutocompleteItem } from \"@earendil-works/pi-tui\";\nimport { getChangelogPath, parseChangelog } from \"../utils/changelog.ts\";\n\nexport const ATOMIC_GUIDE_COMMAND_NAME = \"atomic\";\nexport const ATOMIC_GUIDE_COMMAND_DESCRIPTION =\n \"Atomic onboarding and help guide\";\n\nconst OVERVIEW = `# Atomic overview\n\nAtomic turns one-off prompts into developer workflows: on-call debugging, repo research that turns into implementation, testing and review loops, and larger multi-stage automation. Use \\`/workflow goal\\` for small-to-medium changes with a clear work surface, exact outcome, and named validation; keep \\`/workflow ralph\\` for larger migrations, broad refactors, and spec-to-PR work. Start Atomic in a project with \\`atomic\\`, then talk to it normally. Use \\`@file\\` to attach files, \\`!command\\` to run shell output through the model, and \\`!!command\\` to run shell output without adding it to context.\n\n## Core session commands\n\n| Command | Use |\n|---|---|\n| \\`/login\\` | configure auth |\n| \\`/model\\` | switch model |\n| \\`/settings\\` | thinking level, theme, message delivery, transport |\n| \\`/new\\`, \\`/resume\\` | start or resume sessions |\n| \\`/tree\\`, \\`/fork\\`, \\`/clone\\` | branch or navigate session history |\n| \\`/compact\\` | summarize older context |\n| \\`/hotkeys\\`, \\`/changelog\\` | local help and release notes |\n\n## Examples of using Atomic\n\n| Goal | How to use |\n|---|---|\n| On-call / broken behavior | Run \\`/run debugger \"Reproduce the failure, patch the root cause, and validate it\"\\` for a focused fix loop, or ask Atomic in chat to build a reusable workflow that does the same |\n| Research → spec → implementation | Chain \\`/skill:research-codebase\\` → \\`/skill:create-spec\\` → \\`/workflow goal objective=\"...\"\\` for bounded scoped work with explicit validation; use \\`/workflow ralph ...\\` when the work needs planning, broad refactoring, or PR prep |\n| Testing / regression hardening | Run \\`/skill:tdd\\` for test-first work, then \\`/parallel-review current diff\\`, then land the change |\n| Large repo discovery | Run \\`/parallel codebase-locator \"map the area\" -> codebase-analyzer \"trace the current flow\" -> codebase-pattern-finder \"find patterns\" --bg\\`, or \\`/workflow deep-research-codebase\\` for whole-repo synthesis |\n| UI / product polish | Run \\`/skill:impeccable\\` for interface critique and refinement, or \\`/workflow open-claude-design\\` for generation + refinement loops |\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`deep-research-codebase\\` | broad repo or cross-cutting research before you decide what to change (for one area, use \\`/skill:research-codebase\\`; this indexes the whole repo) | \\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\` |\n| \\`goal\\` | small-to-medium scoped changes when you can name the work surface, outcome, and validation; keeps receipts in a ledger and stops as \\`complete\\`, \\`blocked\\`, or \\`needs_human\\` | \\`/workflow goal objective=\"Implement specs/<date>-<topic>.md, run focused tests, and validate the changed behavior\"\\` |\n| \\`ralph\\` | larger migrations, broad refactors, multi-package changes, and spec-to-PR work where you want Atomic to plan, delegate, simplify, review, iterate, and prepare a PR report | \\`/workflow ralph prompt=\"Plan and implement specs/<date>-<topic>.md, then prepare the PR\"\\` |\n| \\`open-claude-design\\` | UI and design-system work that benefits from generation and refinement loops | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow list\\` to see what is available and \\`/workflow inputs <name>\\` to inspect inputs in your environment.\n\n## Top skills\n\n| Skill | When to use | How to run |\n|---|---|---|\n| \\`research-codebase\\` | write a grounded research artifact for one subsystem or question | \\`/skill:research-codebase how the rate limiter works in src/middleware/\\` |\n| \\`create-spec\\` | turn research into an implementation-ready plan | \\`/skill:create-spec from research/docs/<date>-<topic>.md\\` |\n| \\`tdd\\` | do test-first feature or bug work | \\`/skill:tdd\\` |\n| \\`prompt-engineer\\` | tighten a vague prompt before a long run | \\`/skill:prompt-engineer Draft a sharper implementation prompt for ...\\` |\n| \\`subagent\\` | learn delegation patterns and exact \\`/run\\`, \\`/parallel\\`, and \\`/chain\\` usage | \\`/skill:subagent\\` |\n| \\`impeccable\\` | critique or refine frontend and product UI | \\`/skill:impeccable\\` |\n\n## Subagents\n\nSubagents are focused child Atomic sessions you can point at one job inside the repo.\n\n| Built-in subagent | Use |\n|---|---|\n| \\`codebase-locator\\` | find relevant files, tests, entrypoints, and configs |\n| \\`codebase-analyzer\\` | explain current behavior with file:line refs |\n| \\`codebase-pattern-finder\\` | find existing code to model after |\n| \\`debugger\\` | reproduce, diagnose, and fix broken behavior |\n\nHow the direct commands map to repo work:\n- \\`/run\\` = one specialist on one job, for example \\`/run codebase-locator \"Map the webhook retry flow\"\\`\n- \\`/parallel\\` = several independent specialists at once, for example \\`/parallel codebase-locator \"map retry files\" -> codebase-pattern-finder \"find existing retry/backoff patterns\" -> codebase-online-researcher \"research current retry guidance\" --bg\\`\n- \\`/chain\\` = ordered handoffs, for example \\`/chain codebase-locator \"find the auth files\" -> codebase-analyzer \"trace the auth flow\" -> debugger \"patch the failing auth edge case\"\\`\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see the pieces used on a code task\n\\`/atomic workflows\\` — learn when to use workflows`;\n\nconst EXAMPLE = `# Practical example\n\nThis is an example of a spec-driven development process using Atomic workflows. Use it when you are new to a repo or the task has non-trivial scope. Type the examples below into the Atomic TUI chat after starting \\`atomic\\` in your project.\n\n## 1. Research what exists\n\nUse \\`/skill:research-codebase\\` for a scoped area, subsystem, or directory:\n\n\\`/skill:research-codebase how the rate limiter works in src/middleware/\\`\n\nUse \\`deep-research-codebase\\` when the answer spans the whole repo or a cross-cutting implementation path:\n\n\\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\`\n\nIf the research prompt is vague, tighten it first with \\`/skill:prompt-engineer\\`:\n\n\\`/skill:prompt-engineer Draft a sharper repo-research prompt for understanding payment retries end to end, including retries, queues, and failure handling.\\`\n\n## 2. Create a spec when requirements are fuzzy\n\nSkip this if the implementation request is already precise.\n\n\\`/skill:create-spec from research/docs/<date>-<topic>.md\\`\n\n## 3. Implement with review built in\n\nFor ordinary work, ask Atomic directly and require validation:\n\n\\`Implement the approved spec in specs/<date>-<topic>.md. Run focused tests and summarize validation.\\`\n\nFor small-to-medium scoped changes where you can identify the work surface, exact outcome, and validation, use \\`goal\\`:\n\n\\`/workflow goal objective=\"Implement specs/<date>-<topic>.md, run focused tests, and finish when the documented behavior is validated\"\\`\n\nFor larger migrations, broad refactors, multi-package changes, or spec-to-PR work, use \\`ralph\\`:\n\n\\`/workflow ralph prompt=\"Plan and implement specs/<date>-<topic>.md, then prepare the PR\"\\`\n\n## 4. Decide and land\n\nIf you used \\`goal\\`, the workflow already persisted receipts in a goal ledger and reviewer-gated completion. Use its final status — \\`complete\\`, \\`blocked\\`, or \\`needs_human\\` — plus the remaining-work report to decide whether to ship, unblock, or clarify.\n\nIf you used \\`ralph\\`, the workflow planned the approach, delegated implementation through sub-agents, simplified, reviewed, iterated, and prepared a pull-request report. Use its review feedback and PR report to decide whether to ship or iterate again.\n\nIf you implemented directly instead of using a workflow, you can still run:\n\n\\`/parallel-review current diff\\`\n\nAtomic will synthesize reviewer feedback and ask before applying fixes.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic workflows\\` — learn when to use workflows\n\\`/atomic overview\\` — quick refresh`;\n\nconst WORKFLOWS = `# Workflows primer\n\nA workflow is a TypeScript-defined pipeline built with \\`defineWorkflow(...).run(...).compile()\\`. It can run tasks, chains, parallel fan-out, human-in-the-loop prompts, background status, and model fallback chains.\n\nYou do not have to write TypeScript to add one. Describe the workflow you want in plain chat — goal, inputs, stages, which steps are parallel or sequential, handoff/output shape, and any model or thinking-level preferences — and Atomic will use the workflow docs to scaffold a reusable definition under \\`.atomic/workflows/\\` and reload it for you. Hand-edit the TypeScript afterward when you want precise control.\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`deep-research-codebase\\` | broad repo or cross-cutting research before you decide what to change (for one area, use \\`/skill:research-codebase\\`; this indexes the whole repo) | \\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\` |\n| \\`goal\\` | small-to-medium scoped changes with a clear outcome and named validation | \\`/workflow goal objective=\"Update the CLI docs, include one usage example, and verify the docs build passes\"\\` |\n| \\`ralph\\` | larger migrations, broad refactors, multi-package changes, and spec-to-PR work | \\`/workflow ralph prompt=\"Plan a database-layer migration, implement it, review it, and prepare the PR\"\\` |\n| \\`open-claude-design\\` | frontend and product design work | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow inputs <name>\\` to inspect the exact inputs in your environment.\n\nUse \\`/skill:research-codebase ...\\` when you want research on one subsystem, directory, or focused question. Use \\`/workflow deep-research-codebase ...\\` when the answer needs end-to-end tracing across many parts of the repo.\n\nIf you are drafting research, reviewer, or synthesis prompts for a workflow, use \\`/skill:prompt-engineer\\` first. It is a good fit when a stage prompt feels vague, overloaded, or underspecified.\n\n## What good workflow authoring looks like\n\nA good workflow request is explicit about stage purpose, model choice, handoff, and the decision each step must return.\n\nExample: ask Atomic in chat with something like this:\n\n~~~text\nCreate a reusable workflow called review-changes.\n\nIt should accept one required text input called target for a diff, PR summary, or review target.\n\nRun two independent review stages in parallel with fresh context:\n- one reviewer focused on correctness, regressions, and missing tests using openai-codex/gpt-5.5 at xhigh thinking\n- one reviewer focused on edge cases, maintainability, and hidden risks using anthropic/claude-opus-4-8 at xhigh thinking\n\nThen add an aggregate stage that consolidates both reviews, deduplicates overlap, keeps only evidence-backed issues, and separates blockers from optional suggestions using openai/gpt-5.5 at high thinking.\n\nFinally add an adjudicate stage using anthropic/claude-sonnet-4 at high thinking that decides what to fix now, what to defer, and what to reject. Return a short action list with rationale.\n\nThe workflow should return structured output with consolidated_review and decision fields.\n~~~\n\nWhy this is good:\n- it names the workflow and required input\n- it specifies which stages are parallel vs sequential\n- each stage has one job\n- it defines the handoff and final outputs\n- it calls out model choice and thinking level where that matters\n\n## Run and inspect\n\n\\`/workflow list\\`\n\n\\`/workflow inputs goal\\`\n\n\\`/workflow goal objective=\"Fix the settings form validation bug, add the focused test, and finish when invalid emails show the inline error without submitting\"\\`\n\n\\`/workflow inputs ralph\\`\n\n\\`/workflow ralph prompt=\"Migrate the database layer to Drizzle and prepare the PR\"\\`\n\n\\`/workflow status\\`\n\n\\`/workflow connect <run-id>\\`\n\n\\`/workflow interrupt <run-id>\\`\n\n\\`/workflow resume <run-id>\\`\n\nWorkflows run as background tasks. Use F2 or \\`/workflow connect <run-id>\\` for the graph viewer. Human-in-the-loop prompts appear there, not as chat modals, and awaiting-input states do not wake the main chat agent. Completion and failure notices are steered back into the main chat; answers submitted in the workflow UI interrupt stale main-chat questions so the model does not ask again.\n\n## Author your own\n\nDescribe your workflow in plain chat — say what you want the workflow to accomplish, what inputs it should accept, what stages should run, and what final output or decision it should return. Atomic will use the workflow docs to scaffold a reusable definition under \\`.atomic/workflows/\\`, ask clarifying questions when stage purpose, models, or handoffs are ambiguous, and run \\`/workflow reload\\` so you can launch it immediately.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see workflows in a normal task flow\n\\`/atomic overview\\` — quick refresh`;\n\nconst GUIDE_SECTIONS = [\n {\n name: \"overview\",\n aliases: [],\n label: \"overview\",\n description: \"30-second overview\",\n render: () => OVERVIEW,\n },\n {\n name: \"workflows\",\n aliases: [\"workflow\"],\n label: \"workflows\",\n description: \"Workflow primer\",\n render: () => WORKFLOWS,\n },\n {\n name: \"example\",\n aliases: [\"examples\"],\n label: \"example\",\n description: \"Practical first workflow\",\n render: () => EXAMPLE,\n },\n {\n name: \"whats-new\",\n aliases: [\"what's new\", \"whats new\", \"news\", \"updates\", \"changelog\"],\n label: \"what's new\",\n description: \"Recent release notes\",\n render: readLatestStableChangelog,\n },\n] as const satisfies readonly {\n readonly name: string;\n readonly aliases: readonly string[];\n readonly label: string;\n readonly description: string;\n readonly render: (cwd: string) => string;\n}[];\n\ntype AtomicGuideSection = (typeof GUIDE_SECTIONS)[number];\ntype AtomicGuideSectionName = AtomicGuideSection[\"name\"];\n\nexport type AtomicGuideHelpChoice = AtomicGuideSection[\"label\"];\n\nexport type AtomicGuideMode = \"help\" | AtomicGuideSectionName;\n\nexport const ATOMIC_GUIDE_HELP_CHOICES: readonly AtomicGuideHelpChoice[] =\n GUIDE_SECTIONS.map((section) => section.label);\n\nconst GUIDE_SECTIONS_BY_NAME = new Map<\n AtomicGuideSectionName,\n AtomicGuideSection\n>(GUIDE_SECTIONS.map((section) => [section.name, section]));\nconst GUIDE_SECTIONS_BY_LABEL = new Map<string, AtomicGuideSection>(\n GUIDE_SECTIONS.map((section) => [section.label, section]),\n);\nconst GUIDE_SECTIONS_BY_INPUT = new Map<string, AtomicGuideSection>(\n GUIDE_SECTIONS.flatMap((section) =>\n [section.name, section.label, ...section.aliases].map(\n (input) => [input, section] as const,\n ),\n ),\n);\n\nexport function isAtomicGuideHelpChoice(\n choice: string,\n): choice is AtomicGuideHelpChoice {\n return GUIDE_SECTIONS_BY_LABEL.has(choice);\n}\n\nconst ATOMIC_GUIDE_TRAILING_PUNCTUATION = \"?!.,;:\";\n\nfunction stripTrailingAtomicGuidePunctuation(value: string): string {\n let end = value.length;\n while (\n end > 0 &&\n ATOMIC_GUIDE_TRAILING_PUNCTUATION.includes(value.charAt(end - 1))\n ) {\n end--;\n }\n return value.slice(0, end);\n}\n\nfunction getGuideSectionForChoice(\n choice: string,\n): AtomicGuideSection | undefined {\n return GUIDE_SECTIONS_BY_LABEL.get(choice);\n}\n\nfunction getGuideSectionForMode(\n mode: AtomicGuideSectionName,\n): AtomicGuideSection {\n const section = GUIDE_SECTIONS_BY_NAME.get(mode);\n if (!section) throw new Error(`Unknown Atomic guide section: ${mode}`);\n return section;\n}\n\nfunction getAtomicGuideHelpMenu(): string {\n const sectionHelp = GUIDE_SECTIONS.map(\n (section) => `- \\`${section.label}\\` — run \\`/atomic ${section.label}\\``,\n ).join(\"\\n\");\n return `# Atomic\\n\\nSelect where to start:\\n\\n${sectionHelp}`;\n}\n\nexport function normalizeAtomicGuideMode(args: string): AtomicGuideMode {\n const normalized = stripTrailingAtomicGuidePunctuation(\n args.trim().toLowerCase(),\n );\n if (!normalized) return \"help\";\n\n return GUIDE_SECTIONS_BY_INPUT.get(normalized)?.name ?? \"help\";\n}\n\nexport function getAtomicGuideArgumentCompletions(\n prefix: string,\n): AutocompleteItem[] | null {\n const query = prefix.trim().toLowerCase();\n const items = GUIDE_SECTIONS.map((section) => ({\n value: section.label,\n label: section.label,\n description: section.description,\n }));\n const filtered = query\n ? items.filter(\n (item) => item.value.startsWith(query) || item.label.startsWith(query),\n )\n : items;\n return filtered.length > 0 ? filtered : null;\n}\n\nfunction readLatestStableChangelog(cwd: string): string {\n const changelogPath = getChangelogPath();\n const stableSections = parseChangelog(changelogPath)\n .filter((entry) => entry.prerelease === null)\n .slice(0, 3)\n .map((entry) => entry.content.trim())\n .filter(Boolean);\n\n if (stableSections.length === 0) {\n return `# What's new\\n\\nNo stable release sections were found. Try \\`/changelog\\` for the interactive changelog viewer.\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n }\n\n const relativePath = path.relative(cwd, changelogPath) || changelogPath;\n return `# What's new\\n\\n${stableSections.join(\"\\n\\n\")}\\n\\nSource: \\`${relativePath}\\`\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n}\n\nexport function getAtomicGuideMessage(\n mode: AtomicGuideMode,\n cwd: string,\n): string {\n if (mode === \"help\") return getAtomicGuideHelpMenu();\n return getGuideSectionForMode(mode).render(cwd);\n}\n\nexport function atomicGuideModeForChoice(\n choice: AtomicGuideHelpChoice,\n): AtomicGuideMode {\n return getGuideSectionForChoice(choice)?.name ?? \"help\";\n}\n"]}
1
+ {"version":3,"file":"atomic-guide-command.js","sourceRoot":"","sources":["../../src/core/atomic-guide-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEzE,MAAM,CAAC,MAAM,yBAAyB,GAAG,QAAQ,CAAC;AAClD,MAAM,CAAC,MAAM,gCAAgC,GAC3C,kCAAkC,CAAC;AAErC,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oDAqEmC,CAAC;AAErD,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCAuDqB,CAAC;AAEtC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCAiFmB,CAAC;AAEtC,MAAM,cAAc,GAAG;IACrB;QACE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,EAAE;QACX,KAAK,EAAE,UAAU;QACjB,WAAW,EAAE,oBAAoB;QACjC,MAAM,EAAE,GAAG,EAAE,CAAC,QAAQ;KACvB;IACD;QACE,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,CAAC,UAAU,CAAC;QACrB,KAAK,EAAE,WAAW;QAClB,WAAW,EAAE,iBAAiB;QAC9B,MAAM,EAAE,GAAG,EAAE,CAAC,SAAS;KACxB;IACD;QACE,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,CAAC,UAAU,CAAC;QACrB,KAAK,EAAE,SAAS;QAChB,WAAW,EAAE,0BAA0B;QACvC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO;KACtB;IACD;QACE,IAAI,EAAE,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AAsB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,MAA6B;IAE7B,OAAO,wBAAwB,CAAC,MAAM,CAAC,EAAE,IAAI,IAAI,MAAM,CAAC;AAC1D,CAAC","sourcesContent":["import * as path from \"node:path\";\nimport type { AutocompleteItem } from \"@earendil-works/pi-tui\";\nimport { getChangelogPath, parseChangelog } from \"../utils/changelog.ts\";\n\nexport const ATOMIC_GUIDE_COMMAND_NAME = \"atomic\";\nexport const ATOMIC_GUIDE_COMMAND_DESCRIPTION =\n \"Atomic onboarding and help guide\";\n\nconst OVERVIEW = `# Atomic overview\n\nAtomic turns one-off prompts into developer workflows: on-call debugging, repo research that turns into implementation, testing and review loops, and larger multi-stage automation. Use \\`/workflow goal\\` for small-to-medium changes with a clear work surface, exact outcome, and named validation; keep \\`/workflow ralph\\` for larger migrations, broad refactors, and spec-to-PR work. Start Atomic in a project with \\`atomic\\`, then talk to it normally. Use \\`@file\\` to attach files, \\`!command\\` to run shell output through the model, and \\`!!command\\` to run shell output without adding it to context.\n\n## Core session commands\n\n| Command | Use |\n|---|---|\n| \\`/login\\` | configure auth |\n| \\`/model\\` | switch model |\n| \\`/settings\\` | thinking level, theme, message delivery, transport |\n| \\`/new\\`, \\`/resume\\` | start or resume sessions |\n| \\`/tree\\`, \\`/fork\\`, \\`/clone\\` | branch or navigate session history |\n| \\`/compact\\` | summarize older context |\n| \\`/hotkeys\\`, \\`/changelog\\` | local help and release notes |\n\n## Examples of using Atomic\n\n| Goal | How to use |\n|---|---|\n| On-call / broken behavior | Run \\`/run debugger \"Reproduce the failure, patch the root cause, and validate it\"\\` for a focused fix loop, or ask Atomic in chat to build a reusable workflow that does the same |\n| Research → spec → implementation | Chain \\`/skill:research-codebase\\` → \\`/skill:create-spec\\` → \\`/workflow goal objective=\"...\"\\` for bounded scoped work with explicit validation; use \\`/workflow ralph ...\\` when the work needs planning, broad refactoring, or PR prep |\n| Testing / regression hardening | Run \\`/skill:tdd\\` for test-first work, then \\`/parallel-review current diff\\`, then land the change |\n| Large repo discovery | Run \\`/parallel codebase-locator \"map the area\" -> codebase-analyzer \"trace the current flow\" -> codebase-pattern-finder \"find patterns\" --bg\\`, or \\`/workflow deep-research-codebase\\` for whole-repo synthesis |\n| UI / product polish | Run \\`/skill:impeccable\\` for interface critique and refinement, or \\`/workflow open-claude-design\\` for generation + refinement loops |\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`deep-research-codebase\\` | broad repo or cross-cutting research before you decide what to change (for one area, use \\`/skill:research-codebase\\`; this indexes the whole repo) | \\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\` |\n| \\`goal\\` | small-to-medium scoped changes when you can name the work surface, outcome, and validation; keeps receipts in a ledger and stops as \\`complete\\`, \\`blocked\\`, or \\`needs_human\\` | \\`/workflow goal objective=\"Implement specs/<date>-<topic>.md, run focused tests, and validate the changed behavior\"\\` |\n| \\`ralph\\` | larger migrations, broad refactors, multi-package changes, and spec-to-PR work where you want Atomic to plan, delegate, simplify, review, iterate, and prepare a PR report | \\`/workflow ralph prompt=\"Plan and implement specs/<date>-<topic>.md, then prepare the PR\"\\` |\n| \\`open-claude-design\\` | UI and design-system work that benefits from generation and refinement loops | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow list\\` to see what is available and \\`/workflow inputs <name>\\` to inspect inputs in your environment.\n\n## Top skills\n\n| Skill | When to use | How to run |\n|---|---|---|\n| \\`research-codebase\\` | write a grounded research artifact for one subsystem or question | \\`/skill:research-codebase how the rate limiter works in src/middleware/\\` |\n| \\`create-spec\\` | turn research into an implementation-ready plan | \\`/skill:create-spec from research/docs/<date>-<topic>.md\\` |\n| \\`tdd\\` | do test-first feature or bug work | \\`/skill:tdd\\` |\n| \\`prompt-engineer\\` | tighten a vague prompt before a long run | \\`/skill:prompt-engineer Draft a sharper implementation prompt for ...\\` |\n| \\`subagent\\` | learn delegation patterns and exact \\`/run\\`, \\`/parallel\\`, and \\`/chain\\` usage | \\`/skill:subagent\\` |\n| \\`impeccable\\` | critique or refine frontend and product UI | \\`/skill:impeccable\\` |\n\n## Subagents\n\nSubagents are focused child Atomic sessions you can point at one job inside the repo.\n\n| Built-in subagent | Use |\n|---|---|\n| \\`codebase-locator\\` | find relevant files, tests, entrypoints, and configs |\n| \\`codebase-analyzer\\` | explain current behavior with file:line refs |\n| \\`codebase-pattern-finder\\` | find existing code to model after |\n| \\`debugger\\` | reproduce, diagnose, and fix broken behavior |\n\nHow the direct commands map to repo work:\n- \\`/run\\` = one specialist on one job, for example \\`/run codebase-locator \"Map the webhook retry flow\"\\`\n- \\`/parallel\\` = several independent specialists at once, for example \\`/parallel codebase-locator \"map retry files\" -> codebase-pattern-finder \"find existing retry/backoff patterns\" -> codebase-online-researcher \"research current retry guidance\" --bg\\`\n- \\`/chain\\` = ordered handoffs, for example \\`/chain codebase-locator \"find the auth files\" -> codebase-analyzer \"trace the auth flow\" -> debugger \"patch the failing auth edge case\"\\`\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see the pieces used on a code task\n\\`/atomic workflows\\` — learn when to use workflows`;\n\nconst EXAMPLE = `# Practical example\n\nThis is an example of a spec-driven development process using Atomic workflows. Use it when you are new to a repo or the task has non-trivial scope. Type the examples below into the Atomic TUI chat after starting \\`atomic\\` in your project.\n\n## 1. Research what exists\n\nUse \\`/skill:research-codebase\\` for a scoped area, subsystem, or directory:\n\n\\`/skill:research-codebase how the rate limiter works in src/middleware/\\`\n\nUse \\`deep-research-codebase\\` when the answer spans the whole repo or a cross-cutting implementation path:\n\n\\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\`\n\nIf the research prompt is vague, tighten it first with \\`/skill:prompt-engineer\\`:\n\n\\`/skill:prompt-engineer Draft a sharper repo-research prompt for understanding payment retries end to end, including retries, queues, and failure handling.\\`\n\n## 2. Create a spec when requirements are fuzzy\n\nSkip this if the implementation request is already precise.\n\n\\`/skill:create-spec from research/docs/<date>-<topic>.md\\`\n\n## 3. Implement with review built in\n\nFor ordinary work, ask Atomic directly and require validation:\n\n\\`Implement the approved spec in specs/<date>-<topic>.md. Run focused tests and summarize validation.\\`\n\nFor small-to-medium scoped changes where you can identify the work surface, exact outcome, and validation, use \\`goal\\`:\n\n\\`/workflow goal objective=\"Implement specs/<date>-<topic>.md, run focused tests, and finish when the documented behavior is validated\"\\`\n\nFor larger migrations, broad refactors, multi-package changes, or spec-to-PR work, use \\`ralph\\`:\n\n\\`/workflow ralph prompt=\"Plan and implement specs/<date>-<topic>.md, then prepare the PR\"\\`\n\n## 4. Decide and land\n\nIf you used \\`goal\\`, the workflow already persisted receipts in a goal ledger and reviewer-gated completion. Use its final status — \\`complete\\`, \\`blocked\\`, or \\`needs_human\\` — plus the remaining-work report to decide whether to ship, unblock, or clarify.\n\nIf you used \\`ralph\\`, the workflow planned the approach, delegated implementation through sub-agents, simplified, reviewed, iterated, and prepared a pull-request report. Use its review feedback and PR report to decide whether to ship or iterate again.\n\nIf you implemented directly instead of using a workflow, you can still run:\n\n\\`/parallel-review current diff\\`\n\nAtomic will synthesize reviewer feedback and ask before applying fixes.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic workflows\\` — learn when to use workflows\n\\`/atomic overview\\` — quick refresh`;\n\nconst WORKFLOWS = `# Workflows primer\n\nA workflow is a TypeScript-defined pipeline exported from \\`defineWorkflow(...).compile()\\`. It can run tasks, chains, parallel fan-out, human-in-the-loop prompts, background status, and model fallback chains.\n\nYou do not have to write TypeScript to add one. Describe the workflow you want in plain chat — goal, inputs, stages, which steps are parallel or sequential, handoff/output shape, and any model or thinking-level preferences — and Atomic will use the workflow docs to scaffold a reusable definition under \\`.atomic/workflows/\\` and reload it for you. Hand-edit the TypeScript afterward when you want precise control.\n\n## Built-in workflows\n\n| Workflow | When to use | How to run |\n|---|---|---|\n| \\`deep-research-codebase\\` | broad repo or cross-cutting research before you decide what to change (for one area, use \\`/skill:research-codebase\\`; this indexes the whole repo) | \\`/workflow deep-research-codebase prompt=\"How do payment retries work end to end?\"\\` |\n| \\`goal\\` | small-to-medium scoped changes with a clear outcome and named validation | \\`/workflow goal objective=\"Update the CLI docs, include one usage example, and verify the docs build passes\"\\` |\n| \\`ralph\\` | larger migrations, broad refactors, multi-package changes, and spec-to-PR work | \\`/workflow ralph prompt=\"Plan a database-layer migration, implement it, review it, and prepare the PR\"\\` |\n| \\`open-claude-design\\` | frontend and product design work | \\`/workflow open-claude-design prompt=\"Refresh the settings page hierarchy\"\\` |\n\nUse \\`/workflow inputs <name>\\` to inspect the exact inputs in your environment.\n\nUse \\`/skill:research-codebase ...\\` when you want research on one subsystem, directory, or focused question. Use \\`/workflow deep-research-codebase ...\\` when the answer needs end-to-end tracing across many parts of the repo.\n\nIf you are drafting research, reviewer, or synthesis prompts for a workflow, use \\`/skill:prompt-engineer\\` first. It is a good fit when a stage prompt feels vague, overloaded, or underspecified.\n\n## What good workflow authoring looks like\n\nA good workflow request is explicit about stage purpose, model choice, handoff, and the decision each step must return.\n\nExample: ask Atomic in chat with something like this:\n\n~~~text\nCreate a reusable workflow called review-changes.\n\nIt should accept one required text input called target for a diff, PR summary, or review target.\n\nRun two independent review stages in parallel with fresh context:\n- one reviewer focused on correctness, regressions, and missing tests using openai-codex/gpt-5.5 at xhigh thinking\n- one reviewer focused on edge cases, maintainability, and hidden risks using anthropic/claude-opus-4-8 at xhigh thinking\n\nThen add an aggregate stage that consolidates both reviews, deduplicates overlap, keeps only evidence-backed issues, and separates blockers from optional suggestions using openai/gpt-5.5 at high thinking.\n\nFinally add an adjudicate stage using anthropic/claude-sonnet-4 at high thinking that decides what to fix now, what to defer, and what to reject. Return a short action list with rationale.\n\nThe workflow should return structured output with consolidated_review and decision fields.\n~~~\n\nWhy this is good:\n- it names the workflow and required input\n- it specifies which stages are parallel vs sequential\n- each stage has one job\n- it defines the handoff and final outputs\n- it calls out model choice and thinking level where that matters\n\n## Run and inspect\n\n\\`/workflow list\\`\n\n\\`/workflow inputs goal\\`\n\n\\`/workflow goal objective=\"Fix the settings form validation bug, add the focused test, and finish when invalid emails show the inline error without submitting\"\\`\n\n\\`/workflow inputs ralph\\`\n\n\\`/workflow ralph prompt=\"Migrate the database layer to Drizzle and prepare the PR\"\\`\n\n\\`/workflow status\\`\n\n\\`/workflow connect <run-id>\\`\n\n\\`/workflow interrupt <run-id>\\`\n\n\\`/workflow resume <run-id>\\`\n\nWorkflows run as background tasks. Use F2 or \\`/workflow connect <run-id>\\` for the graph viewer. Human-in-the-loop prompts appear there, not as chat modals, and awaiting-input states do not wake the main chat agent. Completion and failure notices are steered back into the main chat; answers submitted in the workflow UI interrupt stale main-chat questions so the model does not ask again.\n\n## Author your own\n\nDescribe your workflow in plain chat — say what you want the workflow to accomplish, what inputs it should accept, what stages should run, and what final output or decision it should return. Atomic will use the workflow docs to scaffold a reusable definition under \\`.atomic/workflows/\\`, ask clarifying questions when stage purpose, models, or handoffs are ambiguous, and run \\`/workflow reload\\` so you can launch it immediately.\n\n─────────────────────────────────────────────────────────────────\n\nWhere to next:\n\n\\`/atomic example\\` — see workflows in a normal task flow\n\\`/atomic overview\\` — quick refresh`;\n\nconst GUIDE_SECTIONS = [\n {\n name: \"overview\",\n aliases: [],\n label: \"overview\",\n description: \"30-second overview\",\n render: () => OVERVIEW,\n },\n {\n name: \"workflows\",\n aliases: [\"workflow\"],\n label: \"workflows\",\n description: \"Workflow primer\",\n render: () => WORKFLOWS,\n },\n {\n name: \"example\",\n aliases: [\"examples\"],\n label: \"example\",\n description: \"Practical first workflow\",\n render: () => EXAMPLE,\n },\n {\n name: \"whats-new\",\n aliases: [\"what's new\", \"whats new\", \"news\", \"updates\", \"changelog\"],\n label: \"what's new\",\n description: \"Recent release notes\",\n render: readLatestStableChangelog,\n },\n] as const satisfies readonly {\n readonly name: string;\n readonly aliases: readonly string[];\n readonly label: string;\n readonly description: string;\n readonly render: (cwd: string) => string;\n}[];\n\ntype AtomicGuideSection = (typeof GUIDE_SECTIONS)[number];\ntype AtomicGuideSectionName = AtomicGuideSection[\"name\"];\n\nexport type AtomicGuideHelpChoice = AtomicGuideSection[\"label\"];\n\nexport type AtomicGuideMode = \"help\" | AtomicGuideSectionName;\n\nexport const ATOMIC_GUIDE_HELP_CHOICES: readonly AtomicGuideHelpChoice[] =\n GUIDE_SECTIONS.map((section) => section.label);\n\nconst GUIDE_SECTIONS_BY_NAME = new Map<\n AtomicGuideSectionName,\n AtomicGuideSection\n>(GUIDE_SECTIONS.map((section) => [section.name, section]));\nconst GUIDE_SECTIONS_BY_LABEL = new Map<string, AtomicGuideSection>(\n GUIDE_SECTIONS.map((section) => [section.label, section]),\n);\nconst GUIDE_SECTIONS_BY_INPUT = new Map<string, AtomicGuideSection>(\n GUIDE_SECTIONS.flatMap((section) =>\n [section.name, section.label, ...section.aliases].map(\n (input) => [input, section] as const,\n ),\n ),\n);\n\nexport function isAtomicGuideHelpChoice(\n choice: string,\n): choice is AtomicGuideHelpChoice {\n return GUIDE_SECTIONS_BY_LABEL.has(choice);\n}\n\nconst ATOMIC_GUIDE_TRAILING_PUNCTUATION = \"?!.,;:\";\n\nfunction stripTrailingAtomicGuidePunctuation(value: string): string {\n let end = value.length;\n while (\n end > 0 &&\n ATOMIC_GUIDE_TRAILING_PUNCTUATION.includes(value.charAt(end - 1))\n ) {\n end--;\n }\n return value.slice(0, end);\n}\n\nfunction getGuideSectionForChoice(\n choice: string,\n): AtomicGuideSection | undefined {\n return GUIDE_SECTIONS_BY_LABEL.get(choice);\n}\n\nfunction getGuideSectionForMode(\n mode: AtomicGuideSectionName,\n): AtomicGuideSection {\n const section = GUIDE_SECTIONS_BY_NAME.get(mode);\n if (!section) throw new Error(`Unknown Atomic guide section: ${mode}`);\n return section;\n}\n\nfunction getAtomicGuideHelpMenu(): string {\n const sectionHelp = GUIDE_SECTIONS.map(\n (section) => `- \\`${section.label}\\` — run \\`/atomic ${section.label}\\``,\n ).join(\"\\n\");\n return `# Atomic\\n\\nSelect where to start:\\n\\n${sectionHelp}`;\n}\n\nexport function normalizeAtomicGuideMode(args: string): AtomicGuideMode {\n const normalized = stripTrailingAtomicGuidePunctuation(\n args.trim().toLowerCase(),\n );\n if (!normalized) return \"help\";\n\n return GUIDE_SECTIONS_BY_INPUT.get(normalized)?.name ?? \"help\";\n}\n\nexport function getAtomicGuideArgumentCompletions(\n prefix: string,\n): AutocompleteItem[] | null {\n const query = prefix.trim().toLowerCase();\n const items = GUIDE_SECTIONS.map((section) => ({\n value: section.label,\n label: section.label,\n description: section.description,\n }));\n const filtered = query\n ? items.filter(\n (item) => item.value.startsWith(query) || item.label.startsWith(query),\n )\n : items;\n return filtered.length > 0 ? filtered : null;\n}\n\nfunction readLatestStableChangelog(cwd: string): string {\n const changelogPath = getChangelogPath();\n const stableSections = parseChangelog(changelogPath)\n .filter((entry) => entry.prerelease === null)\n .slice(0, 3)\n .map((entry) => entry.content.trim())\n .filter(Boolean);\n\n if (stableSections.length === 0) {\n return `# What's new\\n\\nNo stable release sections were found. Try \\`/changelog\\` for the interactive changelog viewer.\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n }\n\n const relativePath = path.relative(cwd, changelogPath) || changelogPath;\n return `# What's new\\n\\n${stableSections.join(\"\\n\\n\")}\\n\\nSource: \\`${relativePath}\\`\\n\\n─────────────────────────────────────────────────────────────────\\n\\nWhere to next:\\n\\n\\`/atomic example\\` — see a practical first workflow\\n\\`/atomic overview\\` — quick refresh`;\n}\n\nexport function getAtomicGuideMessage(\n mode: AtomicGuideMode,\n cwd: string,\n): string {\n if (mode === \"help\") return getAtomicGuideHelpMenu();\n return getGuideSectionForMode(mode).render(cwd);\n}\n\nexport function atomicGuideModeForChoice(\n choice: AtomicGuideHelpChoice,\n): AtomicGuideMode {\n return getGuideSectionForChoice(choice)?.name ?? \"help\";\n}\n"]}
@@ -91,6 +91,7 @@ export declare class LiveChatEntriesController {
91
91
  private currentStreamingAssistantMessage;
92
92
  private upsertToolEntry;
93
93
  private updateToolResult;
94
+ private isSyntheticToolCallId;
94
95
  private findToolEntryIndex;
95
96
  private reindexPendingTools;
96
97
  private isAssistantEntry;
@@ -1 +1 @@
1
- {"version":3,"file":"chat-message-renderer.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-message-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAmB,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,GAAG,EAAE,MAAM,wBAAwB,CAAC;AACvG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACzF,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,wBAAwB,EACxB,aAAa,EACd,MAAM,2BAA2B,CAAC;AAYnC,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,gBAAgB,CAAA;CAAE,GACnE;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,GACD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,oBAAoB,CAAC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A4B;IAYpC,OAAO,CAAC,gCAAgC;IAKxC,OAAO,CAAC,eAAe;IAyBvB,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,kBAAkB;IAS1B,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,WAAW;CAGpB;AA4DD,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,wBAAwB,GAChC,SAAS,CAwEX","sourcesContent":["import type { AssistantMessage, ToolResultMessage } from \"@earendil-works/pi-ai\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport { Container, Text, type Component, type MarkdownTheme, type TUI } from \"@earendil-works/pi-tui\";\nimport type { TSchema } from \"typebox\";\nimport type { MessageRenderer, ToolDefinition } from \"../../../core/extensions/types.ts\";\nimport type {\n BashExecutionMessage,\n BranchSummaryMessage,\n CompactionSummaryMessage,\n CustomMessage,\n} from \"../../../core/messages.ts\";\nimport { parseSkillBlock } from \"../../../core/agent-session.ts\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\nimport { AssistantMessageComponent } from \"./assistant-message.ts\";\nimport { BashExecutionComponent } from \"./bash-execution.ts\";\nimport { BranchSummaryMessageComponent } from \"./branch-summary-message.ts\";\nimport { CompactionSummaryMessageComponent } from \"./compaction-summary-message.ts\";\nimport { CustomMessageComponent } from \"./custom-message.ts\";\nimport { SkillInvocationMessageComponent } from \"./skill-invocation-message.ts\";\nimport { ToolExecutionComponent } from \"./tool-execution.ts\";\nimport { UserMessageComponent } from \"./user-message.ts\";\n\nexport type ChatMessageEntry =\n | { role: \"assistant\"; kind: \"assistant\"; message: AssistantMessage }\n | {\n role: \"tool\";\n kind: \"tool\";\n toolName: string;\n toolCallId: string;\n args: unknown;\n result?: ToolResultMessage;\n isPartial?: boolean;\n }\n | { role: \"tool\"; kind: \"bashExecution\"; message: BashExecutionMessage; isPartial?: boolean }\n | { role: \"user\"; kind: \"user\"; text: string }\n | { role: \"custom\"; kind: \"custom\"; message: CustomMessage<unknown> }\n | { role: \"summary\"; kind: \"branchSummary\"; message: BranchSummaryMessage }\n | { role: \"summary\"; kind: \"compactionSummary\"; message: CompactionSummaryMessage }\n | { role: \"system\"; kind: \"system\"; text: string };\n\nexport interface ChatMessageRenderOptions {\n ui: Pick<TUI, \"requestRender\">;\n cwd: string;\n markdownTheme?: MarkdownTheme;\n hideThinkingBlock?: boolean;\n hiddenThinkingLabel?: string;\n toolOutputExpanded?: boolean;\n showImages?: boolean;\n imageWidthCells?: number;\n getToolDefinition?: (toolName: string) => ToolDefinition<TSchema, unknown> | undefined;\n getCustomMessageRenderer?: (customType: string) => MessageRenderer | undefined;\n}\n\nexport function chatEntriesFromAgentMessages(\n messages: readonly AgentMessage[],\n): ChatMessageEntry[] {\n const entries: ChatMessageEntry[] = [];\n const pendingTools = new Map<string, Extract<ChatMessageEntry, { kind: \"tool\" }>>();\n\n for (const message of messages) {\n switch (message.role) {\n case \"assistant\": {\n entries.push({ role: \"assistant\", kind: \"assistant\", message });\n for (const content of message.content) {\n if (content.type !== \"toolCall\") continue;\n const toolEntry: ChatMessageEntry = {\n role: \"tool\",\n kind: \"tool\",\n toolName: content.name,\n toolCallId: content.id,\n args: content.arguments,\n isPartial: true,\n };\n entries.push(toolEntry);\n pendingTools.set(content.id, toolEntry);\n }\n if (message.stopReason === \"aborted\" || message.stopReason === \"error\") {\n const errorText = message.stopReason === \"aborted\"\n ? message.errorMessage || \"Operation aborted\"\n : message.errorMessage || \"Unknown error\";\n for (const toolEntry of pendingTools.values()) {\n toolEntry.result = {\n role: \"toolResult\",\n toolCallId: toolEntry.toolCallId,\n toolName: toolEntry.toolName,\n content: [{ type: \"text\", text: errorText }],\n isError: true,\n timestamp: message.timestamp,\n };\n toolEntry.isPartial = false;\n }\n pendingTools.clear();\n }\n break;\n }\n case \"toolResult\": {\n const toolEntry = pendingTools.get(message.toolCallId);\n if (toolEntry) {\n toolEntry.result = message;\n toolEntry.isPartial = false;\n pendingTools.delete(message.toolCallId);\n } else {\n entries.push({\n role: \"tool\",\n kind: \"tool\",\n toolName: message.toolName,\n toolCallId: message.toolCallId,\n args: {},\n result: message,\n isPartial: false,\n });\n }\n break;\n }\n case \"user\": {\n const text = getMessageText(message);\n if (text) entries.push({ role: \"user\", kind: \"user\", text });\n break;\n }\n case \"bashExecution\":\n entries.push({ role: \"tool\", kind: \"bashExecution\", message });\n break;\n case \"custom\":\n if (message.display) entries.push({ role: \"custom\", kind: \"custom\", message });\n break;\n case \"branchSummary\":\n entries.push({ role: \"summary\", kind: \"branchSummary\", message });\n break;\n case \"compactionSummary\":\n entries.push({ role: \"summary\", kind: \"compactionSummary\", message });\n break;\n default: {\n const role = (message as { role: string }).role;\n entries.push({ role: \"system\", kind: \"system\", text: role });\n break;\n }\n }\n }\n\n return entries;\n}\n\nexport interface LiveChatEventLike {\n readonly type?: unknown;\n readonly message?: unknown;\n readonly assistantMessageEvent?: { readonly type?: unknown; readonly delta?: unknown };\n readonly toolCallId?: unknown;\n readonly toolName?: unknown;\n readonly args?: unknown;\n readonly partialResult?: unknown;\n readonly result?: unknown;\n readonly isError?: unknown;\n}\n\ntype LiveChatEntry = ChatMessageEntry | { role: string };\n\nexport class LiveChatEntriesController {\n private streamingAssistantIndex: number | undefined;\n private pendingToolIndexes = new Map<string, number>();\n\n declare private readonly entries: LiveChatEntry[];\n\n constructor(entries: LiveChatEntry[]) {\n this.entries = entries;\n\t}\n\n appendMessages(messages: readonly AgentMessage[]): void {\n this.entries.push(...chatEntriesFromAgentMessages(messages));\n this.reindexPendingTools();\n }\n\n appendUserText(text: string): void {\n this.entries.push({ role: \"user\", kind: \"user\", text });\n }\n\n applyEvent(event: LiveChatEventLike): boolean {\n const type = String(event.type ?? \"\");\n switch (type) {\n case \"message_start\":\n return this.handleMessageStart(event.message);\n case \"message_update\":\n return this.handleMessageUpdate(event);\n case \"message_end\":\n return this.handleMessageEnd(event.message);\n case \"tool_execution_start\":\n return this.upsertToolEntry({\n toolCallId: typeof event.toolCallId === \"string\" ? event.toolCallId : undefined,\n toolName: typeof event.toolName === \"string\" ? event.toolName : \"tool\",\n args: event.args,\n isPartial: true,\n });\n case \"tool_execution_update\": {\n const toolCallId = typeof event.toolCallId === \"string\" ? event.toolCallId : undefined;\n if (!toolCallId) return false;\n return this.updateToolResult(toolCallId, event.partialResult, true, false);\n }\n case \"tool_execution_end\": {\n const toolCallId = typeof event.toolCallId === \"string\" ? event.toolCallId : undefined;\n if (!toolCallId) return false;\n return this.updateToolResult(toolCallId, event.result, false, event.isError === true);\n }\n default:\n return false;\n }\n }\n\n pendingToolIds(): string[] {\n return [...this.pendingToolIndexes.keys()];\n }\n\n clearPendingTools(): void {\n this.pendingToolIndexes.clear();\n }\n\n private handleMessageStart(message: unknown): boolean {\n if (!isAgentMessageLike(message)) return false;\n if (message.role === \"assistant\") {\n this.streamingAssistantIndex = undefined;\n return this.updateAssistantMessage(message as AssistantMessage);\n }\n if (message.role === \"toolResult\") {\n const toolResult = message as ToolResultMessage;\n // Match the main InteractiveMode live-chat behavior: tool output is\n // rendered from tool_execution_end. The subsequent persisted\n // message_start/toolResult echo is absorbed so it cannot append or\n // overwrite a second row for the same tool call.\n if (this.findToolEntryIndex(toolResult.toolCallId) >= 0) return true;\n }\n const entries = chatEntriesFromAgentMessages([message as AgentMessage]);\n if (entries.length === 0) return false;\n this.entries.push(...entries);\n this.reindexPendingTools();\n return true;\n }\n\n private handleMessageUpdate(event: LiveChatEventLike): boolean {\n const message = event.message;\n let changed = false;\n const snapshotHasPayload = isAgentMessageLike(message) &&\n message.role === \"assistant\" &&\n assistantContentHasRenderablePayload((message as { content?: unknown }).content);\n if (isAgentMessageLike(message) && message.role === \"assistant\" && snapshotHasPayload) {\n changed = this.updateAssistantMessage(message as AssistantMessage) || changed;\n }\n const assistantEvent = event.assistantMessageEvent;\n const streamType = String(assistantEvent?.type ?? \"\");\n const delta = typeof assistantEvent?.delta === \"string\" ? assistantEvent.delta : \"\";\n if (!changed && streamType === \"text_delta\" && delta) {\n changed = this.appendAssistantTextDelta(delta);\n } else if (!changed && streamType === \"thinking_delta\" && delta) {\n changed = this.appendAssistantThinkingDelta(delta);\n }\n return changed;\n }\n\n private handleMessageEnd(message: unknown): boolean {\n if (!isAgentMessageLike(message) || message.role !== \"assistant\") return false;\n const changed = this.updateAssistantMessage(message as AssistantMessage);\n const stopReason = typeof message.stopReason === \"string\" ? message.stopReason : \"\";\n if (stopReason === \"aborted\" || stopReason === \"error\") {\n const errorText = typeof message.errorMessage === \"string\" && message.errorMessage\n ? message.errorMessage\n : stopReason === \"aborted\"\n ? \"Operation aborted\"\n : \"Unknown error\";\n for (const toolCallId of this.pendingToolIds()) {\n this.updateToolResult(toolCallId, { content: [{ type: \"text\", text: errorText }] }, false, true);\n }\n this.clearPendingTools();\n }\n this.streamingAssistantIndex = undefined;\n return changed || true;\n }\n\n private updateAssistantMessage(message: AssistantMessage): boolean {\n if (this.streamingAssistantIndex !== undefined && this.isAssistantEntry(this.entries[this.streamingAssistantIndex])) {\n this.entries[this.streamingAssistantIndex] = {\n ...(this.entries[this.streamingAssistantIndex] as Extract<ChatMessageEntry, { kind: \"assistant\" }>),\n message,\n };\n } else {\n this.entries.push({ role: \"assistant\", kind: \"assistant\", message });\n this.streamingAssistantIndex = this.entries.length - 1;\n }\n for (const content of message.content) {\n if (content.type !== \"toolCall\") continue;\n this.upsertToolEntry({\n toolCallId: content.id,\n toolName: content.name,\n args: content.arguments,\n isPartial: true,\n });\n }\n return true;\n }\n\n private appendAssistantTextDelta(delta: string): boolean {\n const current = this.currentStreamingAssistantMessage();\n const content = current ? [...current.content] : [];\n const lastText = [...content].reverse().find((item) => item.type === \"text\");\n if (lastText && lastText.type === \"text\") lastText.text += delta;\n else content.push({ type: \"text\", text: delta });\n return this.updateAssistantMessage({\n ...(current ?? minimalAssistantMessage()),\n content,\n });\n }\n\n private appendAssistantThinkingDelta(delta: string): boolean {\n const current = this.currentStreamingAssistantMessage();\n const content = current ? [...current.content] : [];\n const lastThinking = [...content].reverse().find((item) => item.type === \"thinking\");\n if (lastThinking && lastThinking.type === \"thinking\") lastThinking.thinking += delta;\n else content.push({ type: \"thinking\", thinking: delta });\n return this.updateAssistantMessage({\n ...(current ?? minimalAssistantMessage()),\n content,\n });\n }\n\n private currentStreamingAssistantMessage(): AssistantMessage | undefined {\n const entry = this.streamingAssistantIndex !== undefined ? this.entries[this.streamingAssistantIndex] : undefined;\n return this.isAssistantEntry(entry) ? entry.message : undefined;\n }\n\n private upsertToolEntry(update: {\n toolCallId?: string;\n toolName: string;\n args?: unknown;\n isPartial: boolean;\n }): boolean {\n const toolCallId = update.toolCallId ?? `live-${update.toolName}`;\n const index = this.pendingToolIndexes.get(toolCallId) ?? this.findToolEntryIndex(toolCallId, update.toolName);\n const previous = index >= 0 ? this.entries[index] : undefined;\n const previousTool = this.isToolEntry(previous) ? previous : undefined;\n const next: ChatMessageEntry = {\n role: \"tool\",\n kind: \"tool\",\n toolName: previousTool?.toolName ?? update.toolName,\n toolCallId,\n args: update.args ?? previousTool?.args ?? {},\n result: previousTool?.result,\n isPartial: update.isPartial,\n };\n if (index >= 0) this.entries[index] = next;\n else this.entries.push(next);\n this.pendingToolIndexes.set(toolCallId, index >= 0 ? index : this.entries.length - 1);\n return true;\n }\n\n private updateToolResult(toolCallId: string, result: unknown, isPartial: boolean, isError: boolean): boolean {\n const index = this.pendingToolIndexes.get(toolCallId) ?? this.findToolEntryIndex(toolCallId);\n if (index < 0) return false;\n const entry = this.entries[index];\n if (!this.isToolEntry(entry)) return false;\n const resultObject = toolResultFromUnknown(result, entry.toolName, toolCallId, isError);\n this.entries[index] = { ...entry, result: resultObject, isPartial };\n if (!isPartial) this.pendingToolIndexes.delete(toolCallId);\n return true;\n }\n\n private findToolEntryIndex(toolCallId: string, toolName?: string): number {\n for (let i = this.entries.length - 1; i >= 0; i--) {\n const entry = this.entries[i];\n if (!this.isToolEntry(entry)) continue;\n if (entry.toolCallId === toolCallId || (toolName && entry.toolName === toolName && entry.isPartial !== false)) return i;\n }\n return -1;\n }\n\n private reindexPendingTools(): void {\n this.pendingToolIndexes.clear();\n for (let i = 0; i < this.entries.length; i++) {\n const entry = this.entries[i];\n if (this.isToolEntry(entry) && entry.isPartial !== false) this.pendingToolIndexes.set(entry.toolCallId, i);\n }\n }\n\n private isAssistantEntry(entry: LiveChatEntry | undefined): entry is Extract<ChatMessageEntry, { kind: \"assistant\" }> {\n return isChatMessageEntry(entry) && entry.kind === \"assistant\";\n }\n\n private isToolEntry(entry: LiveChatEntry | undefined): entry is Extract<ChatMessageEntry, { kind: \"tool\" }> {\n return isChatMessageEntry(entry) && entry.kind === \"tool\";\n }\n}\n\nfunction isChatMessageEntry(entry: LiveChatEntry | undefined): entry is ChatMessageEntry {\n return entry !== undefined && \"kind\" in entry;\n}\n\nfunction isAgentMessageLike(message: unknown): message is AgentMessage & { stopReason?: unknown; errorMessage?: unknown } {\n return message !== null && typeof message === \"object\" && \"role\" in message;\n}\n\nfunction assistantContentHasRenderablePayload(content: unknown): boolean {\n if (typeof content === \"string\") return content.length > 0;\n if (!Array.isArray(content)) return false;\n return content.some((item) => {\n if (typeof item === \"string\") return item.length > 0;\n if (item == null || typeof item !== \"object\") return false;\n const obj = item as { type?: unknown; text?: unknown; thinking?: unknown };\n return (obj.type === \"text\" && typeof obj.text === \"string\" && obj.text.length > 0) ||\n (obj.type === \"thinking\" && typeof obj.thinking === \"string\" && obj.thinking.length > 0) ||\n obj.type === \"toolCall\";\n });\n}\n\nfunction minimalAssistantMessage(): AssistantMessage {\n return {\n role: \"assistant\",\n content: [],\n stopReason: \"stop\",\n } as unknown as AssistantMessage;\n}\n\nfunction toolResultFromUnknown(\n result: unknown,\n toolName: string,\n toolCallId: string,\n isError: boolean,\n): ToolResultMessage {\n if (result !== null && typeof result === \"object\" && \"content\" in result) {\n const candidate = result as { content?: unknown; details?: unknown };\n const content = Array.isArray(candidate.content) ? candidate.content : [];\n return {\n role: \"toolResult\",\n toolCallId,\n toolName,\n content: content as ToolResultMessage[\"content\"],\n details: candidate.details,\n isError,\n timestamp: Date.now(),\n };\n }\n return {\n role: \"toolResult\",\n toolCallId,\n toolName,\n content: typeof result === \"string\" ? [{ type: \"text\", text: result }] : [],\n isError,\n timestamp: Date.now(),\n };\n}\n\nexport function renderChatMessageEntry(\n entry: ChatMessageEntry,\n options: ChatMessageRenderOptions,\n): Component {\n const messageEntry = entry as ChatMessageEntry;\n const markdownTheme = options.markdownTheme ?? getMarkdownTheme();\n\n switch (messageEntry.kind) {\n case \"assistant\":\n return new AssistantMessageComponent(\n messageEntry.message,\n options.hideThinkingBlock ?? false,\n markdownTheme,\n options.hiddenThinkingLabel ?? \"Thinking...\",\n );\n case \"tool\": {\n const component = new ToolExecutionComponent(\n messageEntry.toolName,\n messageEntry.toolCallId,\n messageEntry.args,\n {\n showImages: options.showImages ?? true,\n imageWidthCells: options.imageWidthCells,\n },\n options.getToolDefinition?.(messageEntry.toolName),\n options.ui as TUI,\n options.cwd,\n );\n component.setExpanded(options.toolOutputExpanded ?? false);\n if (messageEntry.result) component.updateResult(messageEntry.result, messageEntry.isPartial ?? false);\n return component;\n }\n case \"bashExecution\": {\n const component = new BashExecutionComponent(\n messageEntry.message.command,\n options.ui as TUI,\n messageEntry.message.excludeFromContext,\n );\n if (messageEntry.message.output) component.appendOutput(messageEntry.message.output);\n if (messageEntry.isPartial !== true) {\n component.setComplete(\n messageEntry.message.exitCode,\n messageEntry.message.cancelled,\n messageEntry.message.truncated\n ? ({ truncated: true } as Parameters<BashExecutionComponent[\"setComplete\"]>[2])\n : undefined,\n messageEntry.message.fullOutputPath,\n );\n }\n return component;\n }\n case \"user\":\n return userMessageComponent(messageEntry.text, markdownTheme, options.toolOutputExpanded ?? false);\n case \"custom\": {\n const component = new CustomMessageComponent(\n messageEntry.message,\n options.getCustomMessageRenderer?.(messageEntry.message.customType),\n markdownTheme,\n );\n component.setExpanded(options.toolOutputExpanded ?? false);\n return component;\n }\n case \"branchSummary\": {\n const component = new BranchSummaryMessageComponent(messageEntry.message, markdownTheme);\n component.setExpanded(options.toolOutputExpanded ?? false);\n return component;\n }\n case \"compactionSummary\": {\n const component = new CompactionSummaryMessageComponent(messageEntry.message, markdownTheme);\n component.setExpanded(options.toolOutputExpanded ?? false);\n return component;\n }\n case \"system\":\n return new Text(theme.fg(\"dim\", messageEntry.text), 1, 0);\n }\n}\n\nfunction userMessageComponent(text: string, markdownTheme: MarkdownTheme, expanded: boolean): Component {\n const skillBlock = parseSkillBlock(text);\n if (!skillBlock) return new UserMessageComponent(text, markdownTheme);\n\n const container = new Container();\n const skillComponent = new SkillInvocationMessageComponent(skillBlock, markdownTheme);\n skillComponent.setExpanded(expanded);\n container.addChild(skillComponent);\n if (skillBlock.userMessage) {\n container.addChild(new UserMessageComponent(skillBlock.userMessage, markdownTheme));\n }\n return container;\n}\n\nfunction getMessageText(message: Extract<AgentMessage, { role: \"user\" }>): string {\n return messageContentText(message.content).trim();\n}\n\nfunction messageContentText(content: unknown): string {\n if (typeof content === \"string\") return content;\n if (!Array.isArray(content)) return \"\";\n const parts: string[] = [];\n for (const item of content) {\n if (item == null) continue;\n if (typeof item === \"string\") {\n parts.push(item);\n continue;\n }\n if (typeof item !== \"object\") continue;\n const text = (item as { text?: unknown }).text;\n if (typeof text === \"string\") parts.push(text);\n }\n return parts.join(\"\");\n}\n"]}
1
+ {"version":3,"file":"chat-message-renderer.d.ts","sourceRoot":"","sources":["../../../../src/modes/interactive/components/chat-message-renderer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACjF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAmB,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,KAAK,GAAG,EAAE,MAAM,wBAAwB,CAAC;AACvG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;A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AAgB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzD,qBAAa,yBAAyB;IACpC,OAAO,CAAC,uBAAuB,CAAqB;IACpD,OAAO,CAAC,kBAAkB,CAA6B;IAEvD,iBAAyB,OAAO,CAAkB;IAElD,YAAY,OAAO,EAAE,aAAa,EAAE,EAEpC;IAEA,cAAc,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,IAAI,CAGtD;IAED,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEjC;IAED,UAAU,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CA6B5C;IAED,cAAc,IAAI,MAAM,EAAE,CAEzB;IAED,iBAAiB,IAAI,IAAI,CAExB;IAED,OAAO,CAAC,kBAAkB;IAqB1B,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,sBAAsB;IAsB9B,OAAO,CAAC,wBAAwB;IAYhC,OAAO,CAAC,4BAA4B;IAYpC,OAAO,CAAC,gCAAgC;IAKxC,OAAO,CAAC,eAAe;IAyBvB,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,qBAAqB;IAI7B,OAAO,CAAC,kBAAkB;IAoB1B,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,WAAW;CAGpB;AA4DD,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,wBAAwB,GAChC,SAAS,CAwEX","sourcesContent":["import type { AssistantMessage, ToolResultMessage } from \"@earendil-works/pi-ai\";\nimport type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport { Container, Text, type Component, type MarkdownTheme, type TUI } from \"@earendil-works/pi-tui\";\nimport type { TSchema } from \"typebox\";\nimport type { MessageRenderer, ToolDefinition } from \"../../../core/extensions/types.ts\";\nimport type {\n BashExecutionMessage,\n BranchSummaryMessage,\n CompactionSummaryMessage,\n CustomMessage,\n} from \"../../../core/messages.ts\";\nimport { parseSkillBlock } from \"../../../core/agent-session.ts\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.ts\";\nimport { AssistantMessageComponent } from \"./assistant-message.ts\";\nimport { BashExecutionComponent } from \"./bash-execution.ts\";\nimport { BranchSummaryMessageComponent } from \"./branch-summary-message.ts\";\nimport { CompactionSummaryMessageComponent } from \"./compaction-summary-message.ts\";\nimport { CustomMessageComponent } from \"./custom-message.ts\";\nimport { SkillInvocationMessageComponent } from \"./skill-invocation-message.ts\";\nimport { ToolExecutionComponent } from \"./tool-execution.ts\";\nimport { UserMessageComponent } from \"./user-message.ts\";\n\nexport type ChatMessageEntry =\n | { role: \"assistant\"; kind: \"assistant\"; message: AssistantMessage }\n | {\n role: \"tool\";\n kind: \"tool\";\n toolName: string;\n toolCallId: string;\n args: unknown;\n result?: ToolResultMessage;\n isPartial?: boolean;\n }\n | { role: \"tool\"; kind: \"bashExecution\"; message: BashExecutionMessage; isPartial?: boolean }\n | { role: \"user\"; kind: \"user\"; text: string }\n | { role: \"custom\"; kind: \"custom\"; message: CustomMessage<unknown> }\n | { role: \"summary\"; kind: \"branchSummary\"; message: BranchSummaryMessage }\n | { role: \"summary\"; kind: \"compactionSummary\"; message: CompactionSummaryMessage }\n | { role: \"system\"; kind: \"system\"; text: string };\n\nexport interface ChatMessageRenderOptions {\n ui: Pick<TUI, \"requestRender\">;\n cwd: string;\n markdownTheme?: MarkdownTheme;\n hideThinkingBlock?: boolean;\n hiddenThinkingLabel?: string;\n toolOutputExpanded?: boolean;\n showImages?: boolean;\n imageWidthCells?: number;\n getToolDefinition?: (toolName: string) => ToolDefinition<TSchema, unknown> | undefined;\n getCustomMessageRenderer?: (customType: string) => MessageRenderer | undefined;\n}\n\nexport function chatEntriesFromAgentMessages(\n messages: readonly AgentMessage[],\n): ChatMessageEntry[] {\n const entries: ChatMessageEntry[] = [];\n const pendingTools = new Map<string, Extract<ChatMessageEntry, { kind: \"tool\" }>>();\n\n for (const message of messages) {\n switch (message.role) {\n case \"assistant\": {\n entries.push({ role: \"assistant\", kind: \"assistant\", message });\n for (const content of message.content) {\n if (content.type !== \"toolCall\") continue;\n const toolEntry: ChatMessageEntry = {\n role: \"tool\",\n kind: \"tool\",\n toolName: content.name,\n toolCallId: content.id,\n args: content.arguments,\n isPartial: true,\n };\n entries.push(toolEntry);\n pendingTools.set(content.id, toolEntry);\n }\n if (message.stopReason === \"aborted\" || message.stopReason === \"error\") {\n const errorText = message.stopReason === \"aborted\"\n ? message.errorMessage || \"Operation aborted\"\n : message.errorMessage || \"Unknown error\";\n for (const toolEntry of pendingTools.values()) {\n toolEntry.result = {\n role: \"toolResult\",\n toolCallId: toolEntry.toolCallId,\n toolName: toolEntry.toolName,\n content: [{ type: \"text\", text: errorText }],\n isError: true,\n timestamp: message.timestamp,\n };\n toolEntry.isPartial = false;\n }\n pendingTools.clear();\n }\n break;\n }\n case \"toolResult\": {\n const toolEntry = pendingTools.get(message.toolCallId);\n if (toolEntry) {\n toolEntry.result = message;\n toolEntry.isPartial = false;\n pendingTools.delete(message.toolCallId);\n } else {\n entries.push({\n role: \"tool\",\n kind: \"tool\",\n toolName: message.toolName,\n toolCallId: message.toolCallId,\n args: {},\n result: message,\n isPartial: false,\n });\n }\n break;\n }\n case \"user\": {\n const text = getMessageText(message);\n if (text) entries.push({ role: \"user\", kind: \"user\", text });\n break;\n }\n case \"bashExecution\":\n entries.push({ role: \"tool\", kind: \"bashExecution\", message });\n break;\n case \"custom\":\n if (message.display) entries.push({ role: \"custom\", kind: \"custom\", message });\n break;\n case \"branchSummary\":\n entries.push({ role: \"summary\", kind: \"branchSummary\", message });\n break;\n case \"compactionSummary\":\n entries.push({ role: \"summary\", kind: \"compactionSummary\", message });\n break;\n default: {\n const role = (message as { role: string }).role;\n entries.push({ role: \"system\", kind: \"system\", text: role });\n break;\n }\n }\n }\n\n return entries;\n}\n\nexport interface LiveChatEventLike {\n readonly type?: unknown;\n readonly message?: unknown;\n readonly assistantMessageEvent?: { readonly type?: unknown; readonly delta?: unknown };\n readonly toolCallId?: unknown;\n readonly toolName?: unknown;\n readonly args?: unknown;\n readonly partialResult?: unknown;\n readonly result?: unknown;\n readonly isError?: unknown;\n}\n\ntype LiveChatEntry = ChatMessageEntry | { role: string };\n\nexport class LiveChatEntriesController {\n private streamingAssistantIndex: number | undefined;\n private pendingToolIndexes = new Map<string, number>();\n\n declare private readonly entries: LiveChatEntry[];\n\n constructor(entries: LiveChatEntry[]) {\n this.entries = entries;\n\t}\n\n appendMessages(messages: readonly AgentMessage[]): void {\n this.entries.push(...chatEntriesFromAgentMessages(messages));\n this.reindexPendingTools();\n }\n\n appendUserText(text: string): void {\n this.entries.push({ role: \"user\", kind: \"user\", text });\n }\n\n applyEvent(event: LiveChatEventLike): boolean {\n const type = String(event.type ?? \"\");\n switch (type) {\n case \"message_start\":\n return this.handleMessageStart(event.message);\n case \"message_update\":\n return this.handleMessageUpdate(event);\n case \"message_end\":\n return this.handleMessageEnd(event.message);\n case \"tool_execution_start\":\n return this.upsertToolEntry({\n toolCallId: typeof event.toolCallId === \"string\" ? event.toolCallId : undefined,\n toolName: typeof event.toolName === \"string\" ? event.toolName : \"tool\",\n args: event.args,\n isPartial: true,\n });\n case \"tool_execution_update\": {\n const toolCallId = typeof event.toolCallId === \"string\" ? event.toolCallId : undefined;\n if (!toolCallId) return false;\n return this.updateToolResult(toolCallId, event.partialResult, true, false);\n }\n case \"tool_execution_end\": {\n const toolCallId = typeof event.toolCallId === \"string\" ? event.toolCallId : undefined;\n if (!toolCallId) return false;\n return this.updateToolResult(toolCallId, event.result, false, event.isError === true);\n }\n default:\n return false;\n }\n }\n\n pendingToolIds(): string[] {\n return [...this.pendingToolIndexes.keys()];\n }\n\n clearPendingTools(): void {\n this.pendingToolIndexes.clear();\n }\n\n private handleMessageStart(message: unknown): boolean {\n if (!isAgentMessageLike(message)) return false;\n if (message.role === \"assistant\") {\n this.streamingAssistantIndex = undefined;\n return this.updateAssistantMessage(message as AssistantMessage);\n }\n if (message.role === \"toolResult\") {\n const toolResult = message as ToolResultMessage;\n // Match the main InteractiveMode live-chat behavior: tool output is\n // rendered from tool_execution_end. The subsequent persisted\n // message_start/toolResult echo is absorbed so it cannot append or\n // overwrite a second row for the same tool call.\n if (this.findToolEntryIndex(toolResult.toolCallId) >= 0) return true;\n }\n const entries = chatEntriesFromAgentMessages([message as AgentMessage]);\n if (entries.length === 0) return false;\n this.entries.push(...entries);\n this.reindexPendingTools();\n return true;\n }\n\n private handleMessageUpdate(event: LiveChatEventLike): boolean {\n const message = event.message;\n let changed = false;\n const snapshotHasPayload = isAgentMessageLike(message) &&\n message.role === \"assistant\" &&\n assistantContentHasRenderablePayload((message as { content?: unknown }).content);\n if (isAgentMessageLike(message) && message.role === \"assistant\" && snapshotHasPayload) {\n changed = this.updateAssistantMessage(message as AssistantMessage) || changed;\n }\n const assistantEvent = event.assistantMessageEvent;\n const streamType = String(assistantEvent?.type ?? \"\");\n const delta = typeof assistantEvent?.delta === \"string\" ? assistantEvent.delta : \"\";\n if (!changed && streamType === \"text_delta\" && delta) {\n changed = this.appendAssistantTextDelta(delta);\n } else if (!changed && streamType === \"thinking_delta\" && delta) {\n changed = this.appendAssistantThinkingDelta(delta);\n }\n return changed;\n }\n\n private handleMessageEnd(message: unknown): boolean {\n if (!isAgentMessageLike(message) || message.role !== \"assistant\") return false;\n const changed = this.updateAssistantMessage(message as AssistantMessage);\n const stopReason = typeof message.stopReason === \"string\" ? message.stopReason : \"\";\n if (stopReason === \"aborted\" || stopReason === \"error\") {\n const errorText = typeof message.errorMessage === \"string\" && message.errorMessage\n ? message.errorMessage\n : stopReason === \"aborted\"\n ? \"Operation aborted\"\n : \"Unknown error\";\n for (const toolCallId of this.pendingToolIds()) {\n this.updateToolResult(toolCallId, { content: [{ type: \"text\", text: errorText }] }, false, true);\n }\n this.clearPendingTools();\n }\n this.streamingAssistantIndex = undefined;\n return changed || true;\n }\n\n private updateAssistantMessage(message: AssistantMessage): boolean {\n if (this.streamingAssistantIndex !== undefined && this.isAssistantEntry(this.entries[this.streamingAssistantIndex])) {\n this.entries[this.streamingAssistantIndex] = {\n ...(this.entries[this.streamingAssistantIndex] as Extract<ChatMessageEntry, { kind: \"assistant\" }>),\n message,\n };\n } else {\n this.entries.push({ role: \"assistant\", kind: \"assistant\", message });\n this.streamingAssistantIndex = this.entries.length - 1;\n }\n for (const content of message.content) {\n if (content.type !== \"toolCall\") continue;\n this.upsertToolEntry({\n toolCallId: content.id,\n toolName: content.name,\n args: content.arguments,\n isPartial: true,\n });\n }\n return true;\n }\n\n private appendAssistantTextDelta(delta: string): boolean {\n const current = this.currentStreamingAssistantMessage();\n const content = current ? [...current.content] : [];\n const lastText = [...content].reverse().find((item) => item.type === \"text\");\n if (lastText && lastText.type === \"text\") lastText.text += delta;\n else content.push({ type: \"text\", text: delta });\n return this.updateAssistantMessage({\n ...(current ?? minimalAssistantMessage()),\n content,\n });\n }\n\n private appendAssistantThinkingDelta(delta: string): boolean {\n const current = this.currentStreamingAssistantMessage();\n const content = current ? [...current.content] : [];\n const lastThinking = [...content].reverse().find((item) => item.type === \"thinking\");\n if (lastThinking && lastThinking.type === \"thinking\") lastThinking.thinking += delta;\n else content.push({ type: \"thinking\", thinking: delta });\n return this.updateAssistantMessage({\n ...(current ?? minimalAssistantMessage()),\n content,\n });\n }\n\n private currentStreamingAssistantMessage(): AssistantMessage | undefined {\n const entry = this.streamingAssistantIndex !== undefined ? this.entries[this.streamingAssistantIndex] : undefined;\n return this.isAssistantEntry(entry) ? entry.message : undefined;\n }\n\n private upsertToolEntry(update: {\n toolCallId?: string;\n toolName: string;\n args?: unknown;\n isPartial: boolean;\n }): boolean {\n const toolCallId = update.toolCallId ?? `live-${update.toolName}`;\n const index = this.pendingToolIndexes.get(toolCallId) ?? this.findToolEntryIndex(toolCallId, update.toolName);\n const previous = index >= 0 ? this.entries[index] : undefined;\n const previousTool = this.isToolEntry(previous) ? previous : undefined;\n const next: ChatMessageEntry = {\n role: \"tool\",\n kind: \"tool\",\n toolName: previousTool?.toolName ?? update.toolName,\n toolCallId,\n args: update.args ?? previousTool?.args ?? {},\n result: previousTool?.result,\n isPartial: update.isPartial,\n };\n if (index >= 0) this.entries[index] = next;\n else this.entries.push(next);\n this.pendingToolIndexes.set(toolCallId, index >= 0 ? index : this.entries.length - 1);\n return true;\n }\n\n private updateToolResult(toolCallId: string, result: unknown, isPartial: boolean, isError: boolean): boolean {\n const index = this.pendingToolIndexes.get(toolCallId) ?? this.findToolEntryIndex(toolCallId);\n if (index < 0) return false;\n const entry = this.entries[index];\n if (!this.isToolEntry(entry)) return false;\n const resultObject = toolResultFromUnknown(result, entry.toolName, toolCallId, isError);\n this.entries[index] = { ...entry, result: resultObject, isPartial };\n if (!isPartial) this.pendingToolIndexes.delete(toolCallId);\n return true;\n }\n\n private isSyntheticToolCallId(toolCallId: string): boolean {\n return toolCallId.startsWith(\"live-\");\n }\n\n private findToolEntryIndex(toolCallId: string, toolName?: string): number {\n for (let i = this.entries.length - 1; i >= 0; i--) {\n const entry = this.entries[i];\n if (!this.isToolEntry(entry)) continue;\n if (entry.toolCallId === toolCallId) return i;\n // Legacy reconciliation ONLY: a synthetic `live-<name>` id may pair with a\n // row for the same in-flight tool name (or vice versa). Never collapse two\n // distinct concrete toolCallIds — that merges parallel tool calls (#1198).\n if (\n toolName &&\n entry.toolName === toolName &&\n entry.isPartial !== false &&\n (this.isSyntheticToolCallId(toolCallId) || this.isSyntheticToolCallId(entry.toolCallId))\n ) {\n return i;\n }\n }\n return -1;\n }\n\n private reindexPendingTools(): void {\n this.pendingToolIndexes.clear();\n for (let i = 0; i < this.entries.length; i++) {\n const entry = this.entries[i];\n if (this.isToolEntry(entry) && entry.isPartial !== false) this.pendingToolIndexes.set(entry.toolCallId, i);\n }\n }\n\n private isAssistantEntry(entry: LiveChatEntry | undefined): entry is Extract<ChatMessageEntry, { kind: \"assistant\" }> {\n return isChatMessageEntry(entry) && entry.kind === \"assistant\";\n }\n\n private isToolEntry(entry: LiveChatEntry | undefined): entry is Extract<ChatMessageEntry, { kind: \"tool\" }> {\n return isChatMessageEntry(entry) && entry.kind === \"tool\";\n }\n}\n\nfunction isChatMessageEntry(entry: LiveChatEntry | undefined): entry is ChatMessageEntry {\n return entry !== undefined && \"kind\" in entry;\n}\n\nfunction isAgentMessageLike(message: unknown): message is AgentMessage & { stopReason?: unknown; errorMessage?: unknown } {\n return message !== null && typeof message === \"object\" && \"role\" in message;\n}\n\nfunction assistantContentHasRenderablePayload(content: unknown): boolean {\n if (typeof content === \"string\") return content.length > 0;\n if (!Array.isArray(content)) return false;\n return content.some((item) => {\n if (typeof item === \"string\") return item.length > 0;\n if (item == null || typeof item !== \"object\") return false;\n const obj = item as { type?: unknown; text?: unknown; thinking?: unknown };\n return (obj.type === \"text\" && typeof obj.text === \"string\" && obj.text.length > 0) ||\n (obj.type === \"thinking\" && typeof obj.thinking === \"string\" && obj.thinking.length > 0) ||\n obj.type === \"toolCall\";\n });\n}\n\nfunction minimalAssistantMessage(): AssistantMessage {\n return {\n role: \"assistant\",\n content: [],\n stopReason: \"stop\",\n } as unknown as AssistantMessage;\n}\n\nfunction toolResultFromUnknown(\n result: unknown,\n toolName: string,\n toolCallId: string,\n isError: boolean,\n): ToolResultMessage {\n if (result !== null && typeof result === \"object\" && \"content\" in result) {\n const candidate = result as { content?: unknown; details?: unknown };\n const content = Array.isArray(candidate.content) ? candidate.content : [];\n return {\n role: \"toolResult\",\n toolCallId,\n toolName,\n content: content as ToolResultMessage[\"content\"],\n details: candidate.details,\n isError,\n timestamp: Date.now(),\n };\n }\n return {\n role: \"toolResult\",\n toolCallId,\n toolName,\n content: typeof result === \"string\" ? [{ type: \"text\", text: result }] : [],\n isError,\n timestamp: Date.now(),\n };\n}\n\nexport function renderChatMessageEntry(\n entry: ChatMessageEntry,\n options: ChatMessageRenderOptions,\n): Component {\n const messageEntry = entry as ChatMessageEntry;\n const markdownTheme = options.markdownTheme ?? getMarkdownTheme();\n\n switch (messageEntry.kind) {\n case \"assistant\":\n return new AssistantMessageComponent(\n messageEntry.message,\n options.hideThinkingBlock ?? false,\n markdownTheme,\n options.hiddenThinkingLabel ?? \"Thinking...\",\n );\n case \"tool\": {\n const component = new ToolExecutionComponent(\n messageEntry.toolName,\n messageEntry.toolCallId,\n messageEntry.args,\n {\n showImages: options.showImages ?? true,\n imageWidthCells: options.imageWidthCells,\n },\n options.getToolDefinition?.(messageEntry.toolName),\n options.ui as TUI,\n options.cwd,\n );\n component.setExpanded(options.toolOutputExpanded ?? false);\n if (messageEntry.result) component.updateResult(messageEntry.result, messageEntry.isPartial ?? false);\n return component;\n }\n case \"bashExecution\": {\n const component = new BashExecutionComponent(\n messageEntry.message.command,\n options.ui as TUI,\n messageEntry.message.excludeFromContext,\n );\n if (messageEntry.message.output) component.appendOutput(messageEntry.message.output);\n if (messageEntry.isPartial !== true) {\n component.setComplete(\n messageEntry.message.exitCode,\n messageEntry.message.cancelled,\n messageEntry.message.truncated\n ? ({ truncated: true } as Parameters<BashExecutionComponent[\"setComplete\"]>[2])\n : undefined,\n messageEntry.message.fullOutputPath,\n );\n }\n return component;\n }\n case \"user\":\n return userMessageComponent(messageEntry.text, markdownTheme, options.toolOutputExpanded ?? false);\n case \"custom\": {\n const component = new CustomMessageComponent(\n messageEntry.message,\n options.getCustomMessageRenderer?.(messageEntry.message.customType),\n markdownTheme,\n );\n component.setExpanded(options.toolOutputExpanded ?? false);\n return component;\n }\n case \"branchSummary\": {\n const component = new BranchSummaryMessageComponent(messageEntry.message, markdownTheme);\n component.setExpanded(options.toolOutputExpanded ?? false);\n return component;\n }\n case \"compactionSummary\": {\n const component = new CompactionSummaryMessageComponent(messageEntry.message, markdownTheme);\n component.setExpanded(options.toolOutputExpanded ?? false);\n return component;\n }\n case \"system\":\n return new Text(theme.fg(\"dim\", messageEntry.text), 1, 0);\n }\n}\n\nfunction userMessageComponent(text: string, markdownTheme: MarkdownTheme, expanded: boolean): Component {\n const skillBlock = parseSkillBlock(text);\n if (!skillBlock) return new UserMessageComponent(text, markdownTheme);\n\n const container = new Container();\n const skillComponent = new SkillInvocationMessageComponent(skillBlock, markdownTheme);\n skillComponent.setExpanded(expanded);\n container.addChild(skillComponent);\n if (skillBlock.userMessage) {\n container.addChild(new UserMessageComponent(skillBlock.userMessage, markdownTheme));\n }\n return container;\n}\n\nfunction getMessageText(message: Extract<AgentMessage, { role: \"user\" }>): string {\n return messageContentText(message.content).trim();\n}\n\nfunction messageContentText(content: unknown): string {\n if (typeof content === \"string\") return content;\n if (!Array.isArray(content)) return \"\";\n const parts: string[] = [];\n for (const item of content) {\n if (item == null) continue;\n if (typeof item === \"string\") {\n parts.push(item);\n continue;\n }\n if (typeof item !== \"object\") continue;\n const text = (item as { text?: unknown }).text;\n if (typeof text === \"string\") parts.push(text);\n }\n return parts.join(\"\");\n}\n"]}
@@ -296,13 +296,25 @@ export class LiveChatEntriesController {
296
296
  this.pendingToolIndexes.delete(toolCallId);
297
297
  return true;
298
298
  }
299
+ isSyntheticToolCallId(toolCallId) {
300
+ return toolCallId.startsWith("live-");
301
+ }
299
302
  findToolEntryIndex(toolCallId, toolName) {
300
303
  for (let i = this.entries.length - 1; i >= 0; i--) {
301
304
  const entry = this.entries[i];
302
305
  if (!this.isToolEntry(entry))
303
306
  continue;
304
- if (entry.toolCallId === toolCallId || (toolName && entry.toolName === toolName && entry.isPartial !== false))
307
+ if (entry.toolCallId === toolCallId)
308
+ return i;
309
+ // Legacy reconciliation ONLY: a synthetic `live-<name>` id may pair with a
310
+ // row for the same in-flight tool name (or vice versa). Never collapse two
311
+ // distinct concrete toolCallIds — that merges parallel tool calls (#1198).
312
+ if (toolName &&
313
+ entry.toolName === toolName &&
314
+ entry.isPartial !== false &&
315
+ (this.isSyntheticToolCallId(toolCallId) || this.isSyntheticToolCallId(entry.toolCallId))) {
305
316
  return i;
317
+ }
306
318
  }
307
319
  return -1;
308
320
  }