pi-cohort 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +1151 -0
  2. package/LICENSE +22 -0
  3. package/README.md +1220 -0
  4. package/agents/context-builder.md +45 -0
  5. package/agents/delegate.md +12 -0
  6. package/agents/oracle.md +73 -0
  7. package/agents/planner.md +55 -0
  8. package/agents/reviewer.md +91 -0
  9. package/agents/scout.md +50 -0
  10. package/agents/worker.md +67 -0
  11. package/package.json +87 -0
  12. package/prompts/gather-context-and-clarify.md +13 -0
  13. package/prompts/parallel-cleanup.md +59 -0
  14. package/prompts/parallel-context-build.md +55 -0
  15. package/prompts/parallel-handoff-plan.md +61 -0
  16. package/prompts/parallel-review.md +54 -0
  17. package/prompts/review-loop.md +41 -0
  18. package/skills/pi-cohort/SKILL.md +818 -0
  19. package/src/agents/agent-management.ts +685 -0
  20. package/src/agents/agent-scope.ts +6 -0
  21. package/src/agents/agent-selection.ts +23 -0
  22. package/src/agents/agent-serializer.ts +83 -0
  23. package/src/agents/agents.ts +1141 -0
  24. package/src/agents/chain-serializer.ts +251 -0
  25. package/src/agents/frontmatter.ts +29 -0
  26. package/src/agents/identity.ts +30 -0
  27. package/src/agents/skills.ts +632 -0
  28. package/src/extension/config.ts +16 -0
  29. package/src/extension/control-notices.ts +92 -0
  30. package/src/extension/doctor.ts +236 -0
  31. package/src/extension/fanout-child.ts +170 -0
  32. package/src/extension/grand-total.ts +109 -0
  33. package/src/extension/index.ts +630 -0
  34. package/src/extension/schemas.ts +306 -0
  35. package/src/intercom/intercom-bridge.ts +379 -0
  36. package/src/intercom/result-intercom.ts +377 -0
  37. package/src/runs/background/async-execution.ts +796 -0
  38. package/src/runs/background/async-job-tracker.ts +320 -0
  39. package/src/runs/background/async-resume.ts +345 -0
  40. package/src/runs/background/async-status.ts +335 -0
  41. package/src/runs/background/completion-dedupe.ts +63 -0
  42. package/src/runs/background/notify.ts +108 -0
  43. package/src/runs/background/parallel-groups.ts +45 -0
  44. package/src/runs/background/result-watcher.ts +307 -0
  45. package/src/runs/background/run-id-resolver.ts +83 -0
  46. package/src/runs/background/run-status.ts +272 -0
  47. package/src/runs/background/stale-run-reconciler.ts +336 -0
  48. package/src/runs/background/subagent-runner.ts +2326 -0
  49. package/src/runs/background/top-level-async.ts +13 -0
  50. package/src/runs/foreground/chain-clarify.ts +1333 -0
  51. package/src/runs/foreground/chain-execution.ts +1187 -0
  52. package/src/runs/foreground/execution.ts +1028 -0
  53. package/src/runs/foreground/subagent-executor.ts +2580 -0
  54. package/src/runs/shared/acceptance.ts +605 -0
  55. package/src/runs/shared/chain-outputs.ts +101 -0
  56. package/src/runs/shared/completion-guard.ts +143 -0
  57. package/src/runs/shared/dynamic-fanout.ts +293 -0
  58. package/src/runs/shared/long-running-guard.ts +175 -0
  59. package/src/runs/shared/model-fallback.ts +103 -0
  60. package/src/runs/shared/nested-events.ts +822 -0
  61. package/src/runs/shared/nested-path.ts +52 -0
  62. package/src/runs/shared/nested-render.ts +115 -0
  63. package/src/runs/shared/parallel-utils.ts +136 -0
  64. package/src/runs/shared/pi-args.ts +221 -0
  65. package/src/runs/shared/pi-spawn.ts +115 -0
  66. package/src/runs/shared/run-history.ts +60 -0
  67. package/src/runs/shared/single-output.ts +164 -0
  68. package/src/runs/shared/structured-output.ts +77 -0
  69. package/src/runs/shared/subagent-control.ts +287 -0
  70. package/src/runs/shared/subagent-prompt-runtime.ts +220 -0
  71. package/src/runs/shared/workflow-graph.ts +206 -0
  72. package/src/runs/shared/worktree.ts +577 -0
  73. package/src/shared/artifacts.ts +98 -0
  74. package/src/shared/atomic-json.ts +16 -0
  75. package/src/shared/file-coalescer.ts +40 -0
  76. package/src/shared/fork-context.ts +76 -0
  77. package/src/shared/formatters.ts +133 -0
  78. package/src/shared/jsonl-writer.ts +81 -0
  79. package/src/shared/model-info.ts +78 -0
  80. package/src/shared/post-exit-stdio-guard.ts +85 -0
  81. package/src/shared/session-identity.ts +10 -0
  82. package/src/shared/session-tokens.ts +46 -0
  83. package/src/shared/settings.ts +447 -0
  84. package/src/shared/status-format.ts +59 -0
  85. package/src/shared/types.ts +1072 -0
  86. package/src/shared/utils.ts +451 -0
  87. package/src/slash/prompt-template-bridge.ts +397 -0
  88. package/src/slash/slash-bridge.ts +174 -0
  89. package/src/slash/slash-commands.ts +567 -0
  90. package/src/slash/slash-live-state.ts +292 -0
  91. package/src/tui/render-helpers.ts +80 -0
  92. package/src/tui/render.ts +1476 -0
@@ -0,0 +1,447 @@
1
+ /**
2
+ * Chain behavior, template resolution, and directory management
3
+ */
4
+
5
+ import * as fs from "node:fs";
6
+ import * as path from "node:path";
7
+ import type { AgentConfig } from "../agents/agents.ts";
8
+ import { normalizeSkillInput } from "../agents/skills.ts";
9
+ import { CHAIN_RUNS_DIR, type AcceptanceInput, type JsonSchemaObject, type OutputMode } from "./types.ts";
10
+ const CHAIN_DIR_MAX_AGE_MS = 24 * 60 * 60 * 1000; // 24 hours
11
+ const INITIAL_PROGRESS_CONTENT = "# Progress\n\n## Status\nIn Progress\n\n## Tasks\n\n## Files Changed\n\n## Notes\n";
12
+
13
+ // =============================================================================
14
+ // Behavior Resolution Types
15
+ // =============================================================================
16
+
17
+ export interface ResolvedStepBehavior {
18
+ output: string | false;
19
+ outputMode: OutputMode;
20
+ reads: string[] | false;
21
+ progress: boolean;
22
+ skills: string[] | false;
23
+ model?: string;
24
+ }
25
+
26
+ export interface StepOverrides {
27
+ output?: string | false;
28
+ outputMode?: OutputMode;
29
+ reads?: string[] | false;
30
+ progress?: boolean;
31
+ skills?: string[] | false;
32
+ model?: string;
33
+ }
34
+
35
+ function normalizeOutputOverride(output: string | false | undefined): string | false | undefined {
36
+ return output === "false" ? false : output;
37
+ }
38
+
39
+ // =============================================================================
40
+ // Chain Step Types
41
+ // =============================================================================
42
+
43
+ /** Sequential step: single agent execution */
44
+ export interface SequentialStep {
45
+ agent: string;
46
+ task?: string;
47
+ phase?: string;
48
+ label?: string;
49
+ as?: string;
50
+ outputSchema?: JsonSchemaObject;
51
+ cwd?: string;
52
+ output?: string | false;
53
+ outputMode?: OutputMode;
54
+ reads?: string[] | false;
55
+ progress?: boolean;
56
+ skill?: string | string[] | false;
57
+ model?: string;
58
+ acceptance?: AcceptanceInput;
59
+ }
60
+
61
+ /** Parallel task item within a parallel step */
62
+ export interface ParallelTaskItem {
63
+ agent: string;
64
+ task?: string;
65
+ phase?: string;
66
+ label?: string;
67
+ as?: string;
68
+ outputSchema?: JsonSchemaObject;
69
+ cwd?: string;
70
+ count?: number;
71
+ output?: string | false;
72
+ outputMode?: OutputMode;
73
+ reads?: string[] | false;
74
+ progress?: boolean;
75
+ skill?: string | string[] | false;
76
+ model?: string;
77
+ acceptance?: AcceptanceInput;
78
+ }
79
+
80
+ export interface DynamicExpandSpec {
81
+ from: {
82
+ output: string;
83
+ path: string;
84
+ };
85
+ item?: string;
86
+ key?: string;
87
+ maxItems?: number;
88
+ onEmpty?: "skip" | "fail";
89
+ }
90
+
91
+ export type DynamicParallelTemplate = Omit<ParallelTaskItem, "as" | "count">;
92
+
93
+ export interface DynamicCollectSpec {
94
+ as: string;
95
+ outputSchema?: JsonSchemaObject;
96
+ }
97
+
98
+ export interface DynamicParallelStep {
99
+ expand: DynamicExpandSpec;
100
+ parallel: DynamicParallelTemplate;
101
+ collect: DynamicCollectSpec;
102
+ concurrency?: number;
103
+ failFast?: boolean;
104
+ phase?: string;
105
+ label?: string;
106
+ acceptance?: AcceptanceInput;
107
+ }
108
+
109
+ /** Parallel step: multiple agents running concurrently */
110
+ export interface ParallelStep {
111
+ parallel: ParallelTaskItem[];
112
+ concurrency?: number;
113
+ failFast?: boolean;
114
+ worktree?: boolean;
115
+ cwd?: string;
116
+ }
117
+
118
+ /** Union type for chain steps */
119
+ export type ChainStep = SequentialStep | ParallelStep | DynamicParallelStep;
120
+
121
+ // =============================================================================
122
+ // Type Guards
123
+ // =============================================================================
124
+
125
+ export function isParallelStep(step: ChainStep): step is ParallelStep {
126
+ return "parallel" in step && Array.isArray((step as ParallelStep).parallel);
127
+ }
128
+
129
+ export function isDynamicParallelStep(step: ChainStep): step is DynamicParallelStep {
130
+ return "expand" in step && "collect" in step && "parallel" in step && !Array.isArray((step as { parallel?: unknown }).parallel);
131
+ }
132
+
133
+ /** Get all agent names in a step (single for sequential, multiple for parallel) */
134
+ export function getStepAgents(step: ChainStep): string[] {
135
+ if (isParallelStep(step)) {
136
+ return step.parallel.map((t) => t.agent);
137
+ }
138
+ if (isDynamicParallelStep(step)) {
139
+ return [step.parallel.agent];
140
+ }
141
+ return [step.agent];
142
+ }
143
+
144
+ // =============================================================================
145
+ // Chain Directory Management
146
+ // =============================================================================
147
+
148
+ export function createChainDir(runId: string, baseDir?: string): string {
149
+ const chainDir = path.join(baseDir ? path.resolve(baseDir) : CHAIN_RUNS_DIR, runId);
150
+ fs.mkdirSync(chainDir, { recursive: true });
151
+ return chainDir;
152
+ }
153
+
154
+ export function removeChainDir(chainDir: string): void {
155
+ try {
156
+ fs.rmSync(chainDir, { recursive: true });
157
+ } catch {
158
+ // Chain cleanup is best-effort. Runs can already have cleaned their temp dir.
159
+ }
160
+ }
161
+
162
+ export function cleanupOldChainDirs(): void {
163
+ if (!fs.existsSync(CHAIN_RUNS_DIR)) return;
164
+ const now = Date.now();
165
+ let dirs: string[];
166
+ try {
167
+ dirs = fs.readdirSync(CHAIN_RUNS_DIR);
168
+ } catch {
169
+ // Startup cleanup is best-effort. If the scoped temp root is unreadable,
170
+ // skip cleanup instead of failing extension startup.
171
+ return;
172
+ }
173
+
174
+ for (const dir of dirs) {
175
+ try {
176
+ const dirPath = path.join(CHAIN_RUNS_DIR, dir);
177
+ const stat = fs.statSync(dirPath);
178
+ if (stat.isDirectory() && now - stat.mtimeMs > CHAIN_DIR_MAX_AGE_MS) {
179
+ fs.rmSync(dirPath, { recursive: true });
180
+ }
181
+ } catch {
182
+ // Skip directories that can't be processed; continue with others
183
+ }
184
+ }
185
+ }
186
+
187
+ // =============================================================================
188
+ // Template Resolution
189
+ // =============================================================================
190
+
191
+ /** Resolved templates for a chain - string for sequential, string[] for parallel */
192
+ export type ResolvedTemplates = (string | string[])[];
193
+
194
+ /**
195
+ * Resolve templates for a chain with parallel step support.
196
+ * Returns string for sequential steps, string[] for parallel steps.
197
+ */
198
+ export function resolveChainTemplates(
199
+ steps: ChainStep[],
200
+ ): ResolvedTemplates {
201
+ return steps.map((step, i) => {
202
+ if (isParallelStep(step)) {
203
+ // Parallel step: resolve each task's template
204
+ return step.parallel.map((task) => {
205
+ if (task.task) return task.task;
206
+ // Default for parallel tasks is {previous}
207
+ return "{previous}";
208
+ });
209
+ }
210
+ if (isDynamicParallelStep(step)) {
211
+ return step.parallel.task ?? "{previous}";
212
+ }
213
+ // Sequential step: existing logic
214
+ const seq = step as SequentialStep;
215
+ if (seq.task) return seq.task;
216
+ // Default: first step uses {task}, others use {previous}
217
+ return i === 0 ? "{task}" : "{previous}";
218
+ });
219
+ }
220
+
221
+ // =============================================================================
222
+ // Behavior Resolution
223
+ // =============================================================================
224
+
225
+ /**
226
+ * Resolve effective chain behavior per step.
227
+ * Priority: step override > agent frontmatter > false (disabled)
228
+ */
229
+ export function resolveStepBehavior(
230
+ agentConfig: AgentConfig,
231
+ stepOverrides: StepOverrides,
232
+ chainSkills?: string[],
233
+ ): ResolvedStepBehavior {
234
+ // Output: step override > frontmatter > false (no output)
235
+ const stepOutput = normalizeOutputOverride(stepOverrides.output);
236
+ const output =
237
+ stepOutput !== undefined
238
+ ? stepOutput
239
+ : normalizeOutputOverride(agentConfig.output) ?? false;
240
+
241
+ // Reads: step override > frontmatter defaultReads > false (no reads)
242
+ const reads =
243
+ stepOverrides.reads !== undefined
244
+ ? stepOverrides.reads
245
+ : agentConfig.defaultReads ?? false;
246
+
247
+ // Progress: step override > frontmatter defaultProgress > false
248
+ const progress =
249
+ stepOverrides.progress !== undefined
250
+ ? stepOverrides.progress
251
+ : agentConfig.defaultProgress ?? false;
252
+
253
+ let skills: string[] | false;
254
+ if (stepOverrides.skills === false) {
255
+ skills = false;
256
+ } else if (stepOverrides.skills !== undefined) {
257
+ skills = [...stepOverrides.skills];
258
+ if (chainSkills && chainSkills.length > 0) {
259
+ skills = [...new Set([...skills, ...chainSkills])];
260
+ }
261
+ } else {
262
+ skills = agentConfig.skills ? [...agentConfig.skills] : [];
263
+ if (chainSkills && chainSkills.length > 0) {
264
+ skills = [...new Set([...skills, ...chainSkills])];
265
+ }
266
+ }
267
+
268
+ const outputMode = stepOverrides.outputMode ?? "inline";
269
+ const model = stepOverrides.model ?? agentConfig.model;
270
+ return { output, outputMode, reads, progress, skills, model };
271
+ }
272
+
273
+ export function resolveTaskTextForFileUpdatePolicy(task: string | undefined, originalTask?: string): string | undefined {
274
+ if (!task) return originalTask;
275
+ return originalTask ? task.replaceAll("{task}", originalTask) : task;
276
+ }
277
+
278
+ export function taskDisallowsFileUpdates(task: string | undefined): boolean {
279
+ if (!task) return false;
280
+ return /\breview[- ]only\b/i.test(task)
281
+ || /\bread[- ]only\s+(?:review|audit|inspection|pass)\b/i.test(task)
282
+ || /\b(?:no|without)\s+(?:file\s+)?edits?\b/i.test(task)
283
+ || /\b(?:do not|don't|must not)\s+(?:edit|modify|write|touch)\b/i.test(task)
284
+ || /\bleave\s+files?\s+unchanged\b/i.test(task);
285
+ }
286
+
287
+ export function suppressProgressForReadOnlyTask(behavior: ResolvedStepBehavior, task: string | undefined, originalTask?: string): ResolvedStepBehavior {
288
+ const policyTask = resolveTaskTextForFileUpdatePolicy(task, originalTask);
289
+ return behavior.progress && taskDisallowsFileUpdates(policyTask) ? { ...behavior, progress: false } : behavior;
290
+ }
291
+
292
+ // =============================================================================
293
+ // Chain Instruction Injection
294
+ // =============================================================================
295
+
296
+ /**
297
+ * Resolve a file path: absolute paths pass through, relative paths get chainDir prepended.
298
+ */
299
+ function resolveChainPath(filePath: string, chainDir: string): string {
300
+ return path.isAbsolute(filePath) ? filePath : path.join(chainDir, filePath);
301
+ }
302
+
303
+ /**
304
+ * Build chain instructions from resolved behavior.
305
+ * These are appended to the task to tell the agent what to read/write.
306
+ */
307
+ export function writeInitialProgressFile(progressDir: string): void {
308
+ fs.writeFileSync(path.join(progressDir, "progress.md"), INITIAL_PROGRESS_CONTENT);
309
+ }
310
+
311
+ export function buildChainInstructions(
312
+ behavior: ResolvedStepBehavior,
313
+ chainDir: string,
314
+ isFirstProgressAgent: boolean,
315
+ previousSummary?: string,
316
+ ): { prefix: string; suffix: string } {
317
+ const prefixParts: string[] = [];
318
+ const suffixParts: string[] = [];
319
+
320
+ // READS - prepend to override any hardcoded filenames in task text
321
+ if (behavior.reads && behavior.reads.length > 0) {
322
+ const files = behavior.reads.map((f) => resolveChainPath(f, chainDir));
323
+ prefixParts.push(`[Read from: ${files.join(", ")}]`);
324
+ }
325
+
326
+ // OUTPUT - prepend so agent knows where to write
327
+ if (behavior.output) {
328
+ const outputPath = resolveChainPath(behavior.output, chainDir);
329
+ prefixParts.push(`[Write to: ${outputPath}]`);
330
+ }
331
+
332
+ // Progress instructions in suffix (less critical)
333
+ if (behavior.progress) {
334
+ const progressPath = path.join(chainDir, "progress.md");
335
+ if (isFirstProgressAgent) {
336
+ suffixParts.push(`Create and maintain progress at: ${progressPath}`);
337
+ } else {
338
+ suffixParts.push(`Update progress at: ${progressPath}`);
339
+ }
340
+ }
341
+
342
+ // Include previous step's summary in suffix if available
343
+ if (previousSummary && previousSummary.trim()) {
344
+ suffixParts.push(`Previous step output:\n${previousSummary.trim()}`);
345
+ }
346
+
347
+ const prefix = prefixParts.length > 0
348
+ ? prefixParts.join("\n") + "\n\n"
349
+ : "";
350
+
351
+ const suffix = suffixParts.length > 0
352
+ ? "\n\n---\n" + suffixParts.join("\n")
353
+ : "";
354
+
355
+ return { prefix, suffix };
356
+ }
357
+
358
+ // =============================================================================
359
+ // Parallel Step Support
360
+ // =============================================================================
361
+
362
+ /**
363
+ * Resolve behaviors for all tasks in a parallel step.
364
+ * Creates namespaced output paths to avoid collisions.
365
+ */
366
+ export function resolveParallelBehaviors(
367
+ tasks: ParallelTaskItem[],
368
+ agentConfigs: AgentConfig[],
369
+ stepIndex: number,
370
+ chainSkills?: string[],
371
+ ): ResolvedStepBehavior[] {
372
+ return tasks.map((task, taskIndex) => {
373
+ const config = agentConfigs.find((a) => a.name === task.agent);
374
+ if (!config) {
375
+ throw new Error(`Unknown agent: ${task.agent}`);
376
+ }
377
+
378
+ // Build subdirectory path for this parallel task
379
+ const subdir = path.join(`parallel-${stepIndex}`, `${taskIndex}-${task.agent}`);
380
+
381
+ // Output: task override > agent default (namespaced) > false
382
+ // Absolute paths pass through unchanged; relative paths get namespaced under subdir
383
+ let output: string | false = false;
384
+ const taskOutput = normalizeOutputOverride(task.output);
385
+ const configOutput = normalizeOutputOverride(config.output);
386
+ if (taskOutput !== undefined) {
387
+ if (taskOutput === false) {
388
+ output = false;
389
+ } else if (path.isAbsolute(taskOutput)) {
390
+ output = taskOutput; // Absolute path: use as-is
391
+ } else {
392
+ output = path.join(subdir, taskOutput); // Relative: namespace under subdir
393
+ }
394
+ } else if (configOutput) {
395
+ // Agent defaults are always relative, so namespace them
396
+ output = path.join(subdir, configOutput);
397
+ }
398
+
399
+ // Reads: task override > agent default > false
400
+ const reads =
401
+ task.reads !== undefined ? task.reads : config.defaultReads ?? false;
402
+
403
+ // Progress: task override > agent default > false
404
+ const progress =
405
+ task.progress !== undefined
406
+ ? task.progress
407
+ : config.defaultProgress ?? false;
408
+
409
+ const taskSkillInput = normalizeSkillInput(task.skill);
410
+ let skills: string[] | false;
411
+ if (taskSkillInput === false) {
412
+ skills = false;
413
+ } else if (taskSkillInput !== undefined) {
414
+ skills = [...taskSkillInput];
415
+ if (chainSkills && chainSkills.length > 0) {
416
+ skills = [...new Set([...skills, ...chainSkills])];
417
+ }
418
+ } else {
419
+ skills = config.skills ? [...config.skills] : [];
420
+ if (chainSkills && chainSkills.length > 0) {
421
+ skills = [...new Set([...skills, ...chainSkills])];
422
+ }
423
+ }
424
+
425
+ const outputMode = task.outputMode ?? "inline";
426
+ const model = task.model ?? config.model;
427
+ return { output, outputMode, reads, progress, skills, model };
428
+ });
429
+ }
430
+
431
+ /**
432
+ * Create subdirectories for parallel step outputs
433
+ */
434
+ export function createParallelDirs(
435
+ chainDir: string,
436
+ stepIndex: number,
437
+ taskCount: number,
438
+ agentNames: string[],
439
+ ): void {
440
+ for (let i = 0; i < taskCount; i++) {
441
+ const subdir = path.join(chainDir, `parallel-${stepIndex}`, `${i}-${agentNames[i]}`);
442
+ fs.mkdirSync(subdir, { recursive: true });
443
+ }
444
+ }
445
+
446
+ export type { ParallelTaskResult } from "../runs/shared/parallel-utils.ts";
447
+ export { aggregateParallelOutputs } from "../runs/shared/parallel-utils.ts";
@@ -0,0 +1,59 @@
1
+ import type { ActivityState, AsyncJobStep } from "./types.ts";
2
+
3
+ type StepStatusLike = Pick<AsyncJobStep, "status">;
4
+
5
+ function formatActivityAge(ms: number): string {
6
+ if (ms < 1000) return "now";
7
+ if (ms < 60000) return `${Math.floor(ms / 1000)}s`;
8
+ return `${Math.floor(ms / 60000)}m`;
9
+ }
10
+
11
+ export function formatActivityLabel(lastActivityAt: number | undefined, activityState?: ActivityState, now = Date.now()): string | undefined {
12
+ if (lastActivityAt === undefined) {
13
+ if (activityState === "needs_attention") return "needs attention";
14
+ if (activityState === "active_long_running") return "active but long-running";
15
+ return undefined;
16
+ }
17
+ const age = formatActivityAge(Math.max(0, now - lastActivityAt));
18
+ if (activityState === "needs_attention") return `no activity for ${age}`;
19
+ if (activityState === "active_long_running") return `active but long-running · last activity ${age} ago`;
20
+ return age === "now" ? "active now" : `active ${age} ago`;
21
+ }
22
+
23
+ function isCompletedStepStatus(status: AsyncJobStep["status"]): boolean {
24
+ return status === "complete" || status === "completed";
25
+ }
26
+
27
+ export function aggregateStepStatus(steps: StepStatusLike[]): AsyncJobStep["status"] {
28
+ if (steps.some((step) => step.status === "running")) return "running";
29
+ if (steps.some((step) => step.status === "failed")) return "failed";
30
+ if (steps.some((step) => step.status === "paused")) return "paused";
31
+ if (steps.length > 0 && steps.every((step) => isCompletedStepStatus(step.status))) return "complete";
32
+ return "pending";
33
+ }
34
+
35
+ export function formatAgentRunningLabel(count: number): string {
36
+ return count === 1 ? "1 agent running" : `${count} agents running`;
37
+ }
38
+
39
+ export function formatParallelOutcome(steps: StepStatusLike[], total: number, options: { showRunning?: boolean } = {}): string {
40
+ const running = steps.filter((step) => step.status === "running").length;
41
+ const done = steps.filter((step) => isCompletedStepStatus(step.status)).length;
42
+ const failed = steps.filter((step) => step.status === "failed").length;
43
+ const paused = steps.filter((step) => step.status === "paused").length;
44
+ const parts = [`${done}/${total} done`];
45
+ if (options.showRunning !== false && running > 0) parts.unshift(formatAgentRunningLabel(running));
46
+ if (failed > 0) parts.push(`${failed} failed`);
47
+ if (paused > 0) parts.push(`${paused} paused`);
48
+ return parts.join(" · ");
49
+ }
50
+
51
+ export const STATUS_DIVIDER = "│";
52
+
53
+ // Leading-only separator: the interactive footer joins extension status
54
+ // segments with a single space, so a trailing divider here would collide with
55
+ // the next segment's leading one and render as "│ │". One leading bar per
56
+ // segment yields single dividers between sections, order-independent.
57
+ export function wrapStatus(text: string): string {
58
+ return `${STATUS_DIVIDER} ${text}`;
59
+ }