@pi-agents/orchid 0.1.0-beta.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 (163) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/LICENSE +21 -0
  3. package/README.md +246 -0
  4. package/agents/AGENTS-MANIFEST.md +42 -0
  5. package/agents/brain.md +42 -0
  6. package/agents/context-builder.md +46 -0
  7. package/agents/delegate.md +12 -0
  8. package/agents/dev-1.md +42 -0
  9. package/agents/oracle.md +73 -0
  10. package/agents/planner.md +55 -0
  11. package/agents/researcher.md +52 -0
  12. package/agents/reviewer.md +79 -0
  13. package/agents/scout.md +50 -0
  14. package/agents/tester.md +45 -0
  15. package/agents/worker.md +55 -0
  16. package/extensions/ralph.ts +1 -0
  17. package/extensions/reviewer-extension.ts +125 -0
  18. package/extensions/task-orchestrator.ts +28 -0
  19. package/package.json +63 -0
  20. package/prompts/gather-context-and-clarify.md +13 -0
  21. package/prompts/parallel-cleanup.md +59 -0
  22. package/prompts/parallel-context-build.md +53 -0
  23. package/prompts/parallel-handoff-plan.md +59 -0
  24. package/prompts/parallel-research.md +50 -0
  25. package/prompts/parallel-review.md +54 -0
  26. package/prompts/review-loop.md +41 -0
  27. package/skills/orchid/SKILL.md +214 -0
  28. package/skills/orchid/orchid-cleanup/SKILL.md +122 -0
  29. package/skills/orchid/orchid-converge/SKILL.md +124 -0
  30. package/skills/orchid/orchid-decompose/SKILL.md +201 -0
  31. package/skills/orchid/orchid-doctor/SKILL.md +162 -0
  32. package/skills/orchid/orchid-investigate/SKILL.md +102 -0
  33. package/skills/orchid/orchid-launch/SKILL.md +147 -0
  34. package/skills/ralph/SKILL.md +73 -0
  35. package/skills/subagents/pi-subagents/SKILL.md +813 -0
  36. package/src/index.ts +7 -0
  37. package/src/orchestrator/abort.ts +534 -0
  38. package/src/orchestrator/agent-bridge-extension.ts +1020 -0
  39. package/src/orchestrator/agent-host.ts +954 -0
  40. package/src/orchestrator/cleanup.ts +776 -0
  41. package/src/orchestrator/config-loader.ts +1412 -0
  42. package/src/orchestrator/config-schema.ts +690 -0
  43. package/src/orchestrator/config.ts +81 -0
  44. package/src/orchestrator/context-window.ts +66 -0
  45. package/src/orchestrator/diagnostic-reports.ts +475 -0
  46. package/src/orchestrator/diagnostics.ts +394 -0
  47. package/src/orchestrator/discovery.ts +1833 -0
  48. package/src/orchestrator/engine-worker.ts +415 -0
  49. package/src/orchestrator/engine.ts +5940 -0
  50. package/src/orchestrator/execution.ts +3104 -0
  51. package/src/orchestrator/extension.ts +5934 -0
  52. package/src/orchestrator/formatting.ts +785 -0
  53. package/src/orchestrator/git.ts +88 -0
  54. package/src/orchestrator/index.ts +28 -0
  55. package/src/orchestrator/lane-runner.ts +1787 -0
  56. package/src/orchestrator/mailbox.ts +780 -0
  57. package/src/orchestrator/merge.ts +3414 -0
  58. package/src/orchestrator/messages.ts +1062 -0
  59. package/src/orchestrator/migrations.ts +278 -0
  60. package/src/orchestrator/naming.ts +117 -0
  61. package/src/orchestrator/path-resolver.ts +275 -0
  62. package/src/orchestrator/persistence.ts +2625 -0
  63. package/src/orchestrator/process-registry.ts +452 -0
  64. package/src/orchestrator/quality-gate.ts +1085 -0
  65. package/src/orchestrator/resume.ts +3488 -0
  66. package/src/orchestrator/sessions.ts +57 -0
  67. package/src/orchestrator/settings-loader.ts +136 -0
  68. package/src/orchestrator/settings-tui.ts +2208 -0
  69. package/src/orchestrator/sidecar-telemetry.ts +267 -0
  70. package/src/orchestrator/supervisor.ts +4548 -0
  71. package/src/orchestrator/task-executor-core.ts +675 -0
  72. package/src/orchestrator/tmux-compat.ts +37 -0
  73. package/src/orchestrator/tool-allowlist-constants.ts +37 -0
  74. package/src/orchestrator/types.ts +4465 -0
  75. package/src/orchestrator/verification.ts +547 -0
  76. package/src/orchestrator/waves.ts +1564 -0
  77. package/src/orchestrator/workspace.ts +707 -0
  78. package/src/orchestrator/worktree.ts +2725 -0
  79. package/src/ralph/index.ts +825 -0
  80. package/src/subagents/agents/agent-management.ts +648 -0
  81. package/src/subagents/agents/agent-scope.ts +6 -0
  82. package/src/subagents/agents/agent-selection.ts +23 -0
  83. package/src/subagents/agents/agent-serializer.ts +86 -0
  84. package/src/subagents/agents/agents.ts +832 -0
  85. package/src/subagents/agents/chain-serializer.ts +137 -0
  86. package/src/subagents/agents/frontmatter.ts +29 -0
  87. package/src/subagents/agents/identity.ts +30 -0
  88. package/src/subagents/agents/skills.ts +632 -0
  89. package/src/subagents/extension/config.ts +16 -0
  90. package/src/subagents/extension/control-notices.ts +92 -0
  91. package/src/subagents/extension/doctor.ts +199 -0
  92. package/src/subagents/extension/fanout-child.ts +170 -0
  93. package/src/subagents/extension/index.ts +573 -0
  94. package/src/subagents/extension/schemas.ts +168 -0
  95. package/src/subagents/intercom/intercom-bridge.ts +379 -0
  96. package/src/subagents/intercom/result-intercom.ts +377 -0
  97. package/src/subagents/runs/background/async-execution.ts +712 -0
  98. package/src/subagents/runs/background/async-job-tracker.ts +310 -0
  99. package/src/subagents/runs/background/async-resume.ts +345 -0
  100. package/src/subagents/runs/background/async-status.ts +325 -0
  101. package/src/subagents/runs/background/completion-dedupe.ts +63 -0
  102. package/src/subagents/runs/background/notify.ts +108 -0
  103. package/src/subagents/runs/background/parallel-groups.ts +45 -0
  104. package/src/subagents/runs/background/result-watcher.ts +307 -0
  105. package/src/subagents/runs/background/run-id-resolver.ts +83 -0
  106. package/src/subagents/runs/background/run-status.ts +269 -0
  107. package/src/subagents/runs/background/stale-run-reconciler.ts +336 -0
  108. package/src/subagents/runs/background/subagent-runner.ts +1808 -0
  109. package/src/subagents/runs/background/top-level-async.ts +13 -0
  110. package/src/subagents/runs/foreground/chain-clarify.ts +1333 -0
  111. package/src/subagents/runs/foreground/chain-execution.ts +938 -0
  112. package/src/subagents/runs/foreground/execution.ts +918 -0
  113. package/src/subagents/runs/foreground/subagent-executor.ts +2527 -0
  114. package/src/subagents/runs/shared/completion-guard.ts +147 -0
  115. package/src/subagents/runs/shared/long-running-guard.ts +175 -0
  116. package/src/subagents/runs/shared/mcp-direct-tool-allowlist.ts +365 -0
  117. package/src/subagents/runs/shared/model-fallback.ts +103 -0
  118. package/src/subagents/runs/shared/nested-events.ts +819 -0
  119. package/src/subagents/runs/shared/nested-path.ts +52 -0
  120. package/src/subagents/runs/shared/nested-render.ts +115 -0
  121. package/src/subagents/runs/shared/parallel-utils.ts +109 -0
  122. package/src/subagents/runs/shared/pi-args.ts +220 -0
  123. package/src/subagents/runs/shared/pi-spawn.ts +115 -0
  124. package/src/subagents/runs/shared/run-history.ts +60 -0
  125. package/src/subagents/runs/shared/single-output.ts +164 -0
  126. package/src/subagents/runs/shared/subagent-control.ts +226 -0
  127. package/src/subagents/runs/shared/subagent-prompt-runtime.ts +170 -0
  128. package/src/subagents/runs/shared/worktree.ts +577 -0
  129. package/src/subagents/shared/artifacts.ts +98 -0
  130. package/src/subagents/shared/atomic-json.ts +16 -0
  131. package/src/subagents/shared/file-coalescer.ts +40 -0
  132. package/src/subagents/shared/fork-context.ts +76 -0
  133. package/src/subagents/shared/formatters.ts +133 -0
  134. package/src/subagents/shared/jsonl-writer.ts +81 -0
  135. package/src/subagents/shared/model-info.ts +78 -0
  136. package/src/subagents/shared/post-exit-stdio-guard.ts +85 -0
  137. package/src/subagents/shared/session-identity.ts +10 -0
  138. package/src/subagents/shared/session-tokens.ts +44 -0
  139. package/src/subagents/shared/settings.ts +397 -0
  140. package/src/subagents/shared/status-format.ts +49 -0
  141. package/src/subagents/shared/types.ts +822 -0
  142. package/src/subagents/shared/utils.ts +450 -0
  143. package/src/subagents/slash/prompt-template-bridge.ts +397 -0
  144. package/src/subagents/slash/slash-bridge.ts +174 -0
  145. package/src/subagents/slash/slash-commands.ts +528 -0
  146. package/src/subagents/slash/slash-live-state.ts +292 -0
  147. package/src/subagents/tui/render-helpers.ts +80 -0
  148. package/src/subagents/tui/render.ts +1358 -0
  149. package/templates/agents/local/supervisor.md +33 -0
  150. package/templates/agents/local/task-merger.md +27 -0
  151. package/templates/agents/local/task-reviewer.md +30 -0
  152. package/templates/agents/local/task-worker.md +34 -0
  153. package/templates/agents/supervisor-routing.md +92 -0
  154. package/templates/agents/supervisor.md +229 -0
  155. package/templates/agents/task-merger.md +214 -0
  156. package/templates/agents/task-reviewer.md +260 -0
  157. package/templates/agents/task-worker-segment.md +44 -0
  158. package/templates/agents/task-worker.md +557 -0
  159. package/templates/tasks/CONTEXT.md +30 -0
  160. package/templates/tasks/EXAMPLE-001-hello-world/PROMPT.md +98 -0
  161. package/templates/tasks/EXAMPLE-001-hello-world/STATUS.md +73 -0
  162. package/templates/tasks/EXAMPLE-002-parallel-smoke/PROMPT.md +97 -0
  163. package/templates/tasks/EXAMPLE-002-parallel-smoke/STATUS.md +73 -0
@@ -0,0 +1,397 @@
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 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
+ cwd?: string;
48
+ output?: string | false;
49
+ outputMode?: OutputMode;
50
+ reads?: string[] | false;
51
+ progress?: boolean;
52
+ skill?: string | string[] | false;
53
+ model?: string;
54
+ }
55
+
56
+ /** Parallel task item within a parallel step */
57
+ interface ParallelTaskItem {
58
+ agent: string;
59
+ task?: string;
60
+ cwd?: string;
61
+ count?: number;
62
+ output?: string | false;
63
+ outputMode?: OutputMode;
64
+ reads?: string[] | false;
65
+ progress?: boolean;
66
+ skill?: string | string[] | false;
67
+ model?: string;
68
+ }
69
+
70
+ /** Parallel step: multiple agents running concurrently */
71
+ interface ParallelStep {
72
+ parallel: ParallelTaskItem[];
73
+ concurrency?: number;
74
+ failFast?: boolean;
75
+ worktree?: boolean;
76
+ }
77
+
78
+ /** Union type for chain steps */
79
+ export type ChainStep = SequentialStep | ParallelStep;
80
+
81
+ // =============================================================================
82
+ // Type Guards
83
+ // =============================================================================
84
+
85
+ export function isParallelStep(step: ChainStep): step is ParallelStep {
86
+ return "parallel" in step && Array.isArray((step as ParallelStep).parallel);
87
+ }
88
+
89
+ /** Get all agent names in a step (single for sequential, multiple for parallel) */
90
+ export function getStepAgents(step: ChainStep): string[] {
91
+ if (isParallelStep(step)) {
92
+ return step.parallel.map((t) => t.agent);
93
+ }
94
+ return [step.agent];
95
+ }
96
+
97
+ // =============================================================================
98
+ // Chain Directory Management
99
+ // =============================================================================
100
+
101
+ export function createChainDir(runId: string, baseDir?: string): string {
102
+ const chainDir = path.join(baseDir ? path.resolve(baseDir) : CHAIN_RUNS_DIR, runId);
103
+ fs.mkdirSync(chainDir, { recursive: true });
104
+ return chainDir;
105
+ }
106
+
107
+ export function removeChainDir(chainDir: string): void {
108
+ try {
109
+ fs.rmSync(chainDir, { recursive: true });
110
+ } catch {
111
+ // Chain cleanup is best-effort. Runs can already have cleaned their temp dir.
112
+ }
113
+ }
114
+
115
+ export function cleanupOldChainDirs(): void {
116
+ if (!fs.existsSync(CHAIN_RUNS_DIR)) return;
117
+ const now = Date.now();
118
+ let dirs: string[];
119
+ try {
120
+ dirs = fs.readdirSync(CHAIN_RUNS_DIR);
121
+ } catch {
122
+ // Startup cleanup is best-effort. If the scoped temp root is unreadable,
123
+ // skip cleanup instead of failing extension startup.
124
+ return;
125
+ }
126
+
127
+ for (const dir of dirs) {
128
+ try {
129
+ const dirPath = path.join(CHAIN_RUNS_DIR, dir);
130
+ const stat = fs.statSync(dirPath);
131
+ if (stat.isDirectory() && now - stat.mtimeMs > CHAIN_DIR_MAX_AGE_MS) {
132
+ fs.rmSync(dirPath, { recursive: true });
133
+ }
134
+ } catch {
135
+ // Skip directories that can't be processed; continue with others
136
+ }
137
+ }
138
+ }
139
+
140
+ // =============================================================================
141
+ // Template Resolution
142
+ // =============================================================================
143
+
144
+ /** Resolved templates for a chain - string for sequential, string[] for parallel */
145
+ export type ResolvedTemplates = (string | string[])[];
146
+
147
+ /**
148
+ * Resolve templates for a chain with parallel step support.
149
+ * Returns string for sequential steps, string[] for parallel steps.
150
+ */
151
+ export function resolveChainTemplates(
152
+ steps: ChainStep[],
153
+ ): ResolvedTemplates {
154
+ return steps.map((step, i) => {
155
+ if (isParallelStep(step)) {
156
+ // Parallel step: resolve each task's template
157
+ return step.parallel.map((task) => {
158
+ if (task.task) return task.task;
159
+ // Default for parallel tasks is {previous}
160
+ return "{previous}";
161
+ });
162
+ }
163
+ // Sequential step: existing logic
164
+ const seq = step as SequentialStep;
165
+ if (seq.task) return seq.task;
166
+ // Default: first step uses {task}, others use {previous}
167
+ return i === 0 ? "{task}" : "{previous}";
168
+ });
169
+ }
170
+
171
+ // =============================================================================
172
+ // Behavior Resolution
173
+ // =============================================================================
174
+
175
+ /**
176
+ * Resolve effective chain behavior per step.
177
+ * Priority: step override > agent frontmatter > false (disabled)
178
+ */
179
+ export function resolveStepBehavior(
180
+ agentConfig: AgentConfig,
181
+ stepOverrides: StepOverrides,
182
+ chainSkills?: string[],
183
+ ): ResolvedStepBehavior {
184
+ // Output: step override > frontmatter > false (no output)
185
+ const stepOutput = normalizeOutputOverride(stepOverrides.output);
186
+ const output =
187
+ stepOutput !== undefined
188
+ ? stepOutput
189
+ : normalizeOutputOverride(agentConfig.output) ?? false;
190
+
191
+ // Reads: step override > frontmatter defaultReads > false (no reads)
192
+ const reads =
193
+ stepOverrides.reads !== undefined
194
+ ? stepOverrides.reads
195
+ : agentConfig.defaultReads ?? false;
196
+
197
+ // Progress: step override > frontmatter defaultProgress > false
198
+ const progress =
199
+ stepOverrides.progress !== undefined
200
+ ? stepOverrides.progress
201
+ : agentConfig.defaultProgress ?? false;
202
+
203
+ let skills: string[] | false;
204
+ if (stepOverrides.skills === false) {
205
+ skills = false;
206
+ } else if (stepOverrides.skills !== undefined) {
207
+ skills = [...stepOverrides.skills];
208
+ if (chainSkills && chainSkills.length > 0) {
209
+ skills = [...new Set([...skills, ...chainSkills])];
210
+ }
211
+ } else {
212
+ skills = agentConfig.skills ? [...agentConfig.skills] : [];
213
+ if (chainSkills && chainSkills.length > 0) {
214
+ skills = [...new Set([...skills, ...chainSkills])];
215
+ }
216
+ }
217
+
218
+ const outputMode = stepOverrides.outputMode ?? "inline";
219
+ const model = stepOverrides.model ?? agentConfig.model;
220
+ return { output, outputMode, reads, progress, skills, model };
221
+ }
222
+
223
+ export function resolveTaskTextForFileUpdatePolicy(task: string | undefined, originalTask?: string): string | undefined {
224
+ if (!task) return originalTask;
225
+ return originalTask ? task.replaceAll("{task}", originalTask) : task;
226
+ }
227
+
228
+ export function taskDisallowsFileUpdates(task: string | undefined): boolean {
229
+ if (!task) return false;
230
+ return /\breview[- ]only\b/i.test(task)
231
+ || /\bread[- ]only\s+(?:review|audit|inspection|pass)\b/i.test(task)
232
+ || /\b(?:no|without)\s+(?:file\s+)?edits?\b/i.test(task)
233
+ || /\b(?:do not|don't|must not)\s+(?:edit|modify|write|touch)\b/i.test(task)
234
+ || /\bleave\s+files?\s+unchanged\b/i.test(task);
235
+ }
236
+
237
+ export function suppressProgressForReadOnlyTask(behavior: ResolvedStepBehavior, task: string | undefined, originalTask?: string): ResolvedStepBehavior {
238
+ const policyTask = resolveTaskTextForFileUpdatePolicy(task, originalTask);
239
+ return behavior.progress && taskDisallowsFileUpdates(policyTask) ? { ...behavior, progress: false } : behavior;
240
+ }
241
+
242
+ // =============================================================================
243
+ // Chain Instruction Injection
244
+ // =============================================================================
245
+
246
+ /**
247
+ * Resolve a file path: absolute paths pass through, relative paths get chainDir prepended.
248
+ */
249
+ function resolveChainPath(filePath: string, chainDir: string): string {
250
+ return path.isAbsolute(filePath) ? filePath : path.join(chainDir, filePath);
251
+ }
252
+
253
+ /**
254
+ * Build chain instructions from resolved behavior.
255
+ * These are appended to the task to tell the agent what to read/write.
256
+ */
257
+ export function writeInitialProgressFile(progressDir: string): void {
258
+ fs.writeFileSync(path.join(progressDir, "progress.md"), INITIAL_PROGRESS_CONTENT);
259
+ }
260
+
261
+ export function buildChainInstructions(
262
+ behavior: ResolvedStepBehavior,
263
+ chainDir: string,
264
+ isFirstProgressAgent: boolean,
265
+ previousSummary?: string,
266
+ ): { prefix: string; suffix: string } {
267
+ const prefixParts: string[] = [];
268
+ const suffixParts: string[] = [];
269
+
270
+ // READS - prepend to override any hardcoded filenames in task text
271
+ if (behavior.reads && behavior.reads.length > 0) {
272
+ const files = behavior.reads.map((f) => resolveChainPath(f, chainDir));
273
+ prefixParts.push(`[Read from: ${files.join(", ")}]`);
274
+ }
275
+
276
+ // OUTPUT - prepend so agent knows where to write
277
+ if (behavior.output) {
278
+ const outputPath = resolveChainPath(behavior.output, chainDir);
279
+ prefixParts.push(`[Write to: ${outputPath}]`);
280
+ }
281
+
282
+ // Progress instructions in suffix (less critical)
283
+ if (behavior.progress) {
284
+ const progressPath = path.join(chainDir, "progress.md");
285
+ if (isFirstProgressAgent) {
286
+ suffixParts.push(`Create and maintain progress at: ${progressPath}`);
287
+ } else {
288
+ suffixParts.push(`Update progress at: ${progressPath}`);
289
+ }
290
+ }
291
+
292
+ // Include previous step's summary in suffix if available
293
+ if (previousSummary && previousSummary.trim()) {
294
+ suffixParts.push(`Previous step output:\n${previousSummary.trim()}`);
295
+ }
296
+
297
+ const prefix = prefixParts.length > 0
298
+ ? prefixParts.join("\n") + "\n\n"
299
+ : "";
300
+
301
+ const suffix = suffixParts.length > 0
302
+ ? "\n\n---\n" + suffixParts.join("\n")
303
+ : "";
304
+
305
+ return { prefix, suffix };
306
+ }
307
+
308
+ // =============================================================================
309
+ // Parallel Step Support
310
+ // =============================================================================
311
+
312
+ /**
313
+ * Resolve behaviors for all tasks in a parallel step.
314
+ * Creates namespaced output paths to avoid collisions.
315
+ */
316
+ export function resolveParallelBehaviors(
317
+ tasks: ParallelTaskItem[],
318
+ agentConfigs: AgentConfig[],
319
+ stepIndex: number,
320
+ chainSkills?: string[],
321
+ ): ResolvedStepBehavior[] {
322
+ return tasks.map((task, taskIndex) => {
323
+ const config = agentConfigs.find((a) => a.name === task.agent);
324
+ if (!config) {
325
+ throw new Error(`Unknown agent: ${task.agent}`);
326
+ }
327
+
328
+ // Build subdirectory path for this parallel task
329
+ const subdir = path.join(`parallel-${stepIndex}`, `${taskIndex}-${task.agent}`);
330
+
331
+ // Output: task override > agent default (namespaced) > false
332
+ // Absolute paths pass through unchanged; relative paths get namespaced under subdir
333
+ let output: string | false = false;
334
+ const taskOutput = normalizeOutputOverride(task.output);
335
+ const configOutput = normalizeOutputOverride(config.output);
336
+ if (taskOutput !== undefined) {
337
+ if (taskOutput === false) {
338
+ output = false;
339
+ } else if (path.isAbsolute(taskOutput)) {
340
+ output = taskOutput; // Absolute path: use as-is
341
+ } else {
342
+ output = path.join(subdir, taskOutput); // Relative: namespace under subdir
343
+ }
344
+ } else if (configOutput) {
345
+ // Agent defaults are always relative, so namespace them
346
+ output = path.join(subdir, configOutput);
347
+ }
348
+
349
+ // Reads: task override > agent default > false
350
+ const reads =
351
+ task.reads !== undefined ? task.reads : config.defaultReads ?? false;
352
+
353
+ // Progress: task override > agent default > false
354
+ const progress =
355
+ task.progress !== undefined
356
+ ? task.progress
357
+ : config.defaultProgress ?? false;
358
+
359
+ const taskSkillInput = normalizeSkillInput(task.skill);
360
+ let skills: string[] | false;
361
+ if (taskSkillInput === false) {
362
+ skills = false;
363
+ } else if (taskSkillInput !== undefined) {
364
+ skills = [...taskSkillInput];
365
+ if (chainSkills && chainSkills.length > 0) {
366
+ skills = [...new Set([...skills, ...chainSkills])];
367
+ }
368
+ } else {
369
+ skills = config.skills ? [...config.skills] : [];
370
+ if (chainSkills && chainSkills.length > 0) {
371
+ skills = [...new Set([...skills, ...chainSkills])];
372
+ }
373
+ }
374
+
375
+ const outputMode = task.outputMode ?? "inline";
376
+ const model = task.model ?? config.model;
377
+ return { output, outputMode, reads, progress, skills, model };
378
+ });
379
+ }
380
+
381
+ /**
382
+ * Create subdirectories for parallel step outputs
383
+ */
384
+ export function createParallelDirs(
385
+ chainDir: string,
386
+ stepIndex: number,
387
+ taskCount: number,
388
+ agentNames: string[],
389
+ ): void {
390
+ for (let i = 0; i < taskCount; i++) {
391
+ const subdir = path.join(chainDir, `parallel-${stepIndex}`, `${i}-${agentNames[i]}`);
392
+ fs.mkdirSync(subdir, { recursive: true });
393
+ }
394
+ }
395
+
396
+ export type { ParallelTaskResult } from "../runs/shared/parallel-utils.ts";
397
+ export { aggregateParallelOutputs } from "../runs/shared/parallel-utils.ts";
@@ -0,0 +1,49 @@
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
+ }