@xzzpig/pi-subagents 0.4.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +172 -1
- package/README.md +8 -0
- package/agents/oracle.md +3 -1
- package/agents/reviewer.md +1 -0
- package/agents/scout.md +2 -2
- package/agents/worker.md +2 -1
- package/async-retention-discovery-worker.mjs +180 -0
- package/docs/agents.md +79 -2
- package/docs/configuration.md +42 -14
- package/docs/extension-api.md +45 -2
- package/docs/models.md +2 -0
- package/docs/observability.md +41 -5
- package/docs/tool-reference.md +38 -39
- package/docs/workflows.md +173 -3
- package/package.json +13 -10
- package/prompts/council.md +48 -0
- package/skills/council-mode/SKILL.md +230 -0
- package/skills/pi-subagents/SKILL.md +8 -4
- package/skills/pi-subagents/references/constraints-and-recipes.md +13 -6
- package/skills/pi-subagents/references/execution-controls.md +40 -15
- package/skills/pi-subagents/references/management-authoring-rpc.md +3 -3
- package/skills/pi-subagents/references/multi-lane-orchestration.md +39 -0
- package/skills/pi-subagents/references/prompting-and-roles.md +4 -2
- package/src/agents/agent-management.ts +158 -357
- package/src/agents/agent-serializer.ts +4 -0
- package/src/agents/agents.ts +227 -53
- package/src/agents/builtin-names.ts +9 -0
- package/src/agents/runtime-agent-registry.ts +422 -0
- package/src/agents/skills.ts +1 -1
- package/src/api/agents.ts +7 -0
- package/src/api/external-job-provider.ts +186 -0
- package/src/api/preflight.ts +37 -9
- package/src/api/shared-types.ts +2 -0
- package/src/extension/config.ts +6 -3
- package/src/extension/context-injection.ts +118 -0
- package/src/extension/doctor.ts +15 -6
- package/src/extension/fanout-child.ts +2 -2
- package/src/extension/index.ts +224 -90
- package/src/extension/public-execution.ts +31 -2
- package/src/extension/rpc.ts +41 -1
- package/src/extension/schemas.ts +17 -37
- package/src/extension/tool-description.ts +35 -24
- package/src/inspectors/herdr/actions.ts +2 -2
- package/src/inspectors/herdr/inspector-runner.ts +2 -1
- package/src/inspectors/herdr/project-panes.ts +2 -2
- package/src/intercom/native-supervisor-channel.ts +32 -10
- package/src/missions/lifecycle.ts +6 -1
- package/src/missions/store.ts +4 -9
- package/src/missions/workflow-state.ts +2 -2
- package/src/profiles/profiles.ts +3 -1
- package/src/runs/background/active-run-index.ts +31 -8
- package/src/runs/background/async-execution.ts +70 -41
- package/src/runs/background/async-job-tracker.ts +24 -7
- package/src/runs/background/async-resume.ts +49 -16
- package/src/runs/background/async-retention.ts +886 -0
- package/src/runs/background/async-status-snapshot.ts +14 -5
- package/src/runs/background/async-status.ts +39 -53
- package/src/runs/background/auto-drain.ts +1 -0
- package/src/runs/background/chain-append.ts +3 -33
- package/src/runs/background/completion-dedupe.ts +5 -1
- package/src/runs/background/completion-replay.ts +22 -12
- package/src/runs/background/control-channel.ts +14 -68
- package/src/runs/background/fleet-view.ts +68 -19
- package/src/runs/background/index-segment.ts +59 -0
- package/src/runs/background/inspect-rpc.ts +443 -0
- package/src/runs/background/notify.ts +31 -5
- package/src/runs/background/result-files.ts +158 -90
- package/src/runs/background/result-watcher.ts +124 -20
- package/src/runs/background/resume-guidance.ts +8 -5
- package/src/runs/background/retained-children.ts +13 -3
- package/src/runs/background/run-id-query.ts +7 -0
- package/src/runs/background/run-id-resolver.ts +11 -9
- package/src/runs/background/run-status.ts +27 -18
- package/src/runs/background/scheduled-runs.ts +24 -4
- package/src/runs/background/stale-run-reconciler.ts +6 -3
- package/src/runs/background/steering.ts +11 -1
- package/src/runs/background/subagent-runner.ts +260 -144
- package/src/runs/background/subagent-wait.ts +17 -13
- package/src/runs/background/terminal-run-index.ts +138 -0
- package/src/runs/background/wait-completions.ts +21 -4
- package/src/runs/background/wait-subscriptions.ts +81 -2
- package/src/runs/background/wait-tool.ts +1 -0
- package/src/runs/foreground/async-steering-action.ts +21 -14
- package/src/runs/foreground/execution.ts +8 -2
- package/src/runs/foreground/subagent-executor.ts +816 -1593
- package/src/runs/foreground/workflow-detach-reconcile.ts +262 -0
- package/src/runs/foreground/workflow-foreground-steering.ts +6 -5
- package/src/runs/shared/acceptance.ts +48 -5
- package/src/runs/shared/chain-outputs.ts +1 -3
- package/src/runs/shared/external-job-bridge.ts +444 -0
- package/src/runs/shared/external-job-runner.ts +286 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +14 -0
- package/src/runs/shared/model-exclusions.ts +242 -0
- package/src/runs/shared/model-fallback.ts +153 -40
- package/src/runs/shared/orca-progress-tabs.ts +84 -22
- package/src/runs/shared/parallel-handoff.ts +46 -4
- package/src/runs/shared/parallel-utils.ts +4 -15
- package/src/runs/shared/permissions.ts +5 -1
- package/src/runs/shared/pi-args.ts +8 -1
- package/src/runs/shared/session-lease.ts +0 -6
- package/src/runs/shared/subagent-control.ts +51 -7
- package/src/runs/shared/subagent-prompt-runtime.ts +12 -6
- package/src/runs/shared/workflow-graph.ts +1 -23
- package/src/runs/shared/worktree.ts +14 -2
- package/src/shared/atomic-json.ts +22 -2
- package/src/shared/capacity-resilient-json.ts +102 -0
- package/src/shared/completion-owner.ts +14 -0
- package/src/shared/file-system-retry.ts +49 -1
- package/src/shared/fork-context.ts +59 -1
- package/src/shared/model-info.ts +20 -0
- package/src/shared/prompt-resources.ts +0 -40
- package/src/shared/settings.ts +5 -29
- package/src/shared/types.ts +110 -26
- package/src/shared/utils.ts +8 -0
- package/src/shared/watch-strategy.ts +10 -0
- package/src/slash/slash-bridge.ts +2 -1
- package/src/slash/slash-commands.ts +47 -7
- package/src/slash/slash-live-state.ts +3 -3
- package/src/tui/fleet-status.ts +86 -1
- package/src/tui/fleet.ts +117 -16
- package/src/tui/render.ts +73 -3
- package/src/watchdog/change-signature.ts +1 -1
- package/src/watchdog/lsp-diagnostics.ts +1 -0
- package/src/workflows/chat-progress.ts +2 -2
- package/src/workflows/scripted-workflow.ts +320 -79
- package/src/workflows/workflow-receipt.ts +140 -0
- package/src/runs/foreground/chain-clarify.ts +0 -1354
- package/src/runs/foreground/chain-execution.ts +0 -1581
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { writeAtomicJson } from "../../shared/atomic-json.ts";
|
|
4
|
+
import { getSingleResultOutput, readStatus } from "../../shared/utils.ts";
|
|
5
|
+
import {
|
|
6
|
+
DIRS,
|
|
7
|
+
SUBAGENT_ASYNC_COMPLETE_EVENT,
|
|
8
|
+
type AsyncStatus,
|
|
9
|
+
type IntercomEventBus,
|
|
10
|
+
type SingleResult,
|
|
11
|
+
type SubagentState,
|
|
12
|
+
} from "../../shared/types.ts";
|
|
13
|
+
import { updateActiveRunIndex } from "../background/active-run-index.ts";
|
|
14
|
+
import { resultFilePath, writeAsyncResultFile } from "../background/result-files.ts";
|
|
15
|
+
import { resolveAsyncResumeTarget } from "../background/async-resume.ts";
|
|
16
|
+
import { readWorkflowReceipt, workflowReceiptPath, writeWorkflowReceipt, type WorkflowReceipt } from "../../workflows/workflow-receipt.ts";
|
|
17
|
+
|
|
18
|
+
function cloneWorkflowStatus(status: AsyncStatus): AsyncStatus {
|
|
19
|
+
return {
|
|
20
|
+
...status,
|
|
21
|
+
steps: status.steps?.map((step) => ({ ...step })),
|
|
22
|
+
workflow: status.workflow ? { ...status.workflow, trace: [...(status.workflow.trace ?? [])] } : status.workflow,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function childSucceeded(result: Pick<SingleResult, "exitCode" | "error">): boolean {
|
|
27
|
+
return result.exitCode === 0 && !result.error;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function applyDetachedChildToPausedWorkflow(
|
|
31
|
+
status: AsyncStatus,
|
|
32
|
+
input: { childRunId: string; result: Pick<SingleResult, "exitCode" | "error" | "sessionFile">; workflowKey?: string },
|
|
33
|
+
): AsyncStatus | undefined {
|
|
34
|
+
if (status.mode !== "workflow" || status.state !== "paused") return undefined;
|
|
35
|
+
const next = cloneWorkflowStatus(status);
|
|
36
|
+
const step = next.steps?.find((candidate) => candidate.runId === input.childRunId)
|
|
37
|
+
?? (input.workflowKey ? next.steps?.find((candidate) => candidate.workflowKey === input.workflowKey) : undefined);
|
|
38
|
+
if (!step) return undefined;
|
|
39
|
+
const succeeded = childSucceeded(input.result);
|
|
40
|
+
const updatedAt = Date.now();
|
|
41
|
+
step.status = succeeded ? "completed" : "failed";
|
|
42
|
+
step.endedAt = updatedAt;
|
|
43
|
+
delete step.activityState;
|
|
44
|
+
delete step.currentTool;
|
|
45
|
+
delete step.currentToolStartedAt;
|
|
46
|
+
if (input.result.sessionFile) step.sessionFile = input.result.sessionFile;
|
|
47
|
+
if (succeeded) delete step.error;
|
|
48
|
+
else if (input.result.error) step.error = input.result.error;
|
|
49
|
+
next.lastUpdate = updatedAt;
|
|
50
|
+
const promoted = promotePausedWorkflowIfSettled(next);
|
|
51
|
+
if (promoted?.state === "failed" && input.result.error) promoted.error = input.result.error;
|
|
52
|
+
return promoted ?? next;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function promotePausedWorkflowIfSettled(status: AsyncStatus): AsyncStatus | undefined {
|
|
56
|
+
if (status.mode !== "workflow" || status.state !== "paused") return undefined;
|
|
57
|
+
const next = cloneWorkflowStatus(status);
|
|
58
|
+
const stillOpen = next.steps?.some((candidate) =>
|
|
59
|
+
candidate.status === "running"
|
|
60
|
+
|| (candidate.status === "paused" && candidate.activityState === "needs_attention")
|
|
61
|
+
) === true;
|
|
62
|
+
if (stillOpen || !next.steps?.length) return undefined;
|
|
63
|
+
const failed = next.steps.some((candidate) => candidate.status === "failed");
|
|
64
|
+
const updatedAt = Date.now();
|
|
65
|
+
next.lastUpdate = updatedAt;
|
|
66
|
+
next.state = failed ? "failed" : "complete";
|
|
67
|
+
next.endedAt = updatedAt;
|
|
68
|
+
delete next.activityState;
|
|
69
|
+
if (!failed) delete next.error;
|
|
70
|
+
return next;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function workflowResultChildren(status: AsyncStatus, childRunId: string, result: SingleResult, existingResults: unknown): unknown {
|
|
74
|
+
const output = getSingleResultOutput(result);
|
|
75
|
+
if (Array.isArray(existingResults)) {
|
|
76
|
+
return existingResults.map((entry) => {
|
|
77
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) return entry;
|
|
78
|
+
const child = entry as Record<string, unknown>;
|
|
79
|
+
if (child.runId !== childRunId) return child;
|
|
80
|
+
return {
|
|
81
|
+
...child,
|
|
82
|
+
success: childSucceeded(result),
|
|
83
|
+
output,
|
|
84
|
+
outputState: output.trim() ? "present" : "absent",
|
|
85
|
+
detached: undefined,
|
|
86
|
+
...(result.error ? { error: result.error } : {}),
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return status.steps?.map((step) => ({
|
|
91
|
+
workflowKey: step.workflowKey,
|
|
92
|
+
agent: step.agent,
|
|
93
|
+
runId: step.runId,
|
|
94
|
+
success: step.status === "completed" || step.status === "complete",
|
|
95
|
+
output: step.runId === childRunId ? output : "",
|
|
96
|
+
outputState: step.runId === childRunId && output.trim() ? "present" : "absent",
|
|
97
|
+
...(step.error ? { error: step.error } : {}),
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function publishedWorkflowResult(status: AsyncStatus, childRunId: string, result: SingleResult, asyncDir: string, existing?: Record<string, unknown>, receipt?: WorkflowReceipt): Record<string, unknown> {
|
|
102
|
+
const sessionId = status.sessionId ?? (typeof existing?.sessionId === "string" ? existing.sessionId : undefined);
|
|
103
|
+
const summary = status.state === "complete"
|
|
104
|
+
? `Workflow completed after detached child ${childRunId} finished.`
|
|
105
|
+
: status.error ?? (typeof existing?.summary === "string" ? existing.summary : undefined);
|
|
106
|
+
return {
|
|
107
|
+
...(existing ?? {}),
|
|
108
|
+
id: status.runId,
|
|
109
|
+
runId: status.runId,
|
|
110
|
+
toolCallId: status.toolCallId,
|
|
111
|
+
agent: "workflow",
|
|
112
|
+
mode: "workflow",
|
|
113
|
+
success: status.state === "complete",
|
|
114
|
+
state: status.state,
|
|
115
|
+
summary,
|
|
116
|
+
error: status.error,
|
|
117
|
+
activityState: status.activityState,
|
|
118
|
+
endedAt: status.endedAt,
|
|
119
|
+
timestamp: Date.now(),
|
|
120
|
+
results: workflowResultChildren(status, childRunId, result, existing?.results),
|
|
121
|
+
workflow: status.workflow,
|
|
122
|
+
...(receipt ? { workflowReceipt: { path: path.join(asyncDir, "workflow-receipt.json"), receipt } } : {}),
|
|
123
|
+
asyncDir,
|
|
124
|
+
cwd: status.cwd,
|
|
125
|
+
sessionId,
|
|
126
|
+
completionOwnerId: status.completionOwnerId,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function reconcileWorkflowReceipt(status: AsyncStatus, childRunId: string, result: SingleResult, asyncDir: string): WorkflowReceipt | undefined {
|
|
131
|
+
const receiptPath = workflowReceiptPath(DIRS.async, status.runId);
|
|
132
|
+
if (!fs.existsSync(receiptPath)) return undefined;
|
|
133
|
+
const receipt = readWorkflowReceipt(DIRS.async, status.runId);
|
|
134
|
+
const step = status.steps?.find((candidate) => candidate.runId === childRunId);
|
|
135
|
+
const key = step?.workflowKey;
|
|
136
|
+
if (!key) throw new Error(`Workflow receipt '${status.runId}' cannot identify detached child '${childRunId}' by stable key.`);
|
|
137
|
+
const entry = receipt.entries[key];
|
|
138
|
+
if (!entry) throw new Error(`Workflow receipt '${status.runId}' has no detached child key '${key}'.`);
|
|
139
|
+
let resumability: typeof entry.resumability;
|
|
140
|
+
try {
|
|
141
|
+
const target = resolveAsyncResumeTarget({ id: childRunId, dir: path.join(DIRS.async, childRunId) }, {}, { requireSessionFile: true, sessionId: status.sessionId });
|
|
142
|
+
resumability = target.kind === "revive" ? { state: "resumable" } : { state: "not-resumable", reason: "child is still running" };
|
|
143
|
+
} catch (error) {
|
|
144
|
+
resumability = { state: "not-resumable", reason: error instanceof Error ? error.message : String(error) };
|
|
145
|
+
}
|
|
146
|
+
const outputReference = result.savedOutputPath ?? result.outputReference?.path ?? entry.outputReference;
|
|
147
|
+
const updatedEntry: WorkflowReceipt["entries"][string] = resumability.state === "resumable"
|
|
148
|
+
? {
|
|
149
|
+
...entry,
|
|
150
|
+
...(step.agent ? { agent: step.agent } : {}),
|
|
151
|
+
...(step.context ? { resolvedContext: step.context } : {}),
|
|
152
|
+
latestRunId: entry.latestRunId ?? childRunId,
|
|
153
|
+
resumability,
|
|
154
|
+
...(outputReference ? { outputReference } : {}),
|
|
155
|
+
}
|
|
156
|
+
: {
|
|
157
|
+
...entry,
|
|
158
|
+
...(step.agent ? { agent: step.agent } : {}),
|
|
159
|
+
...(step.context ? { resolvedContext: step.context } : {}),
|
|
160
|
+
resumability,
|
|
161
|
+
...(outputReference ? { outputReference } : {}),
|
|
162
|
+
};
|
|
163
|
+
const next: WorkflowReceipt = {
|
|
164
|
+
...receipt,
|
|
165
|
+
state: status.state === "complete" ? "complete" : status.state === "stopped" ? "stopped" : status.state === "paused" ? "paused" : "failed",
|
|
166
|
+
entries: {
|
|
167
|
+
...receipt.entries,
|
|
168
|
+
[key]: updatedEntry,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
writeWorkflowReceipt(asyncDir, next);
|
|
172
|
+
return next;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function appendDetachedWorkflowEvent(asyncDir: string, event: Record<string, unknown>): void {
|
|
176
|
+
const eventsPath = path.join(asyncDir, "events.jsonl");
|
|
177
|
+
try {
|
|
178
|
+
fs.appendFileSync(eventsPath, `${JSON.stringify(event)}\n`, "utf-8");
|
|
179
|
+
} catch (error) {
|
|
180
|
+
console.error(`Failed to append detached workflow event '${eventsPath}':`, error);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export function reconcileDetachedWorkflowChildCompletion(input: {
|
|
185
|
+
state: SubagentState;
|
|
186
|
+
workflowRunId: string;
|
|
187
|
+
childRunId: string;
|
|
188
|
+
result: SingleResult;
|
|
189
|
+
events?: IntercomEventBus;
|
|
190
|
+
workflowKey?: string;
|
|
191
|
+
}): boolean {
|
|
192
|
+
const job = input.state.asyncJobs.get(input.workflowRunId);
|
|
193
|
+
const asyncDir = job?.asyncDir ?? path.join(DIRS.async, input.workflowRunId);
|
|
194
|
+
const status = readStatus(asyncDir);
|
|
195
|
+
if (!status) return false;
|
|
196
|
+
const next = applyDetachedChildToPausedWorkflow(status, {
|
|
197
|
+
childRunId: input.childRunId,
|
|
198
|
+
result: input.result,
|
|
199
|
+
workflowKey: input.workflowKey,
|
|
200
|
+
});
|
|
201
|
+
if (!next) return false;
|
|
202
|
+
writeAtomicJson(path.join(asyncDir, "status.json"), next);
|
|
203
|
+
updateActiveRunIndex(asyncDir, next.state, next.toolCallId);
|
|
204
|
+
if (job) {
|
|
205
|
+
job.status = next.state;
|
|
206
|
+
job.updatedAt = next.lastUpdate;
|
|
207
|
+
job.activityState = next.activityState;
|
|
208
|
+
job.steps = next.steps?.map((step, index) => ({ ...step, index }));
|
|
209
|
+
job.workflow = next.workflow;
|
|
210
|
+
}
|
|
211
|
+
const resultPath = resultFilePath(DIRS.results, input.workflowRunId);
|
|
212
|
+
let existing: Record<string, unknown> | undefined;
|
|
213
|
+
try {
|
|
214
|
+
const parsed: unknown = JSON.parse(fs.readFileSync(resultPath, "utf-8"));
|
|
215
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) existing = parsed as Record<string, unknown>;
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
218
|
+
}
|
|
219
|
+
let receipt: WorkflowReceipt | undefined;
|
|
220
|
+
let receiptError: string | undefined;
|
|
221
|
+
try {
|
|
222
|
+
receipt = reconcileWorkflowReceipt(next, input.childRunId, input.result, asyncDir);
|
|
223
|
+
} catch (error) {
|
|
224
|
+
receiptError = `Failed to reconcile async workflow receipt: ${error instanceof Error ? error.message : String(error)}`;
|
|
225
|
+
}
|
|
226
|
+
const published = publishedWorkflowResult(next, input.childRunId, input.result, asyncDir, existing, receipt);
|
|
227
|
+
writeAsyncResultFile(resultPath, published);
|
|
228
|
+
if (receiptError) {
|
|
229
|
+
appendDetachedWorkflowEvent(asyncDir, {
|
|
230
|
+
ts: Date.now(),
|
|
231
|
+
runId: input.workflowRunId,
|
|
232
|
+
type: "subagent.workflow.receipt_write_failed",
|
|
233
|
+
error: receiptError,
|
|
234
|
+
reconciledFromDetachedChild: input.childRunId,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
if (next.state === "complete" || next.state === "failed") {
|
|
238
|
+
appendDetachedWorkflowEvent(asyncDir, {
|
|
239
|
+
ts: Date.now(),
|
|
240
|
+
runId: input.workflowRunId,
|
|
241
|
+
type: "subagent.workflow.completed",
|
|
242
|
+
state: next.state,
|
|
243
|
+
...(next.error ? { error: next.error } : {}),
|
|
244
|
+
reconciledFromDetachedChild: input.childRunId,
|
|
245
|
+
});
|
|
246
|
+
input.events?.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, {
|
|
247
|
+
id: input.workflowRunId,
|
|
248
|
+
runId: input.workflowRunId,
|
|
249
|
+
source: "async",
|
|
250
|
+
mode: "workflow",
|
|
251
|
+
agent: "workflow",
|
|
252
|
+
success: next.state === "complete",
|
|
253
|
+
state: next.state,
|
|
254
|
+
summary: typeof published.summary === "string" ? published.summary : (next.state === "complete" ? "Workflow completed." : next.error),
|
|
255
|
+
sessionId: next.sessionId,
|
|
256
|
+
completionOwnerId: next.completionOwnerId,
|
|
257
|
+
timestamp: Date.now(),
|
|
258
|
+
triggerTurn: true,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
@@ -4,6 +4,7 @@ import * as path from "node:path";
|
|
|
4
4
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
5
5
|
import type { Details, ForegroundRunControl, SubagentState } from "../../shared/types.ts";
|
|
6
6
|
import { readStatus } from "../../shared/utils.ts";
|
|
7
|
+
import { steeringReceipt } from "../background/steering.ts";
|
|
7
8
|
import {
|
|
8
9
|
consumeSteerAckFromDir,
|
|
9
10
|
readSteerCapability,
|
|
@@ -146,18 +147,18 @@ export async function steerWorkflowForegroundTarget(input: {
|
|
|
146
147
|
targets: [target],
|
|
147
148
|
};
|
|
148
149
|
if (input.signal?.aborted) {
|
|
149
|
-
return { content: [{ type: "text", text: `Steering pending for foreground run ${control.runId} (request ${request.id}); caller aborted before acknowledgment.` }], details: { mode: "management", results: [], steering } };
|
|
150
|
+
return { content: [{ type: "text", text: steeringReceipt(request.message, `Steering pending for foreground run ${control.runId} (request ${request.id}); caller aborted before acknowledgment.`) }], details: { mode: "management", results: [], steering } };
|
|
150
151
|
}
|
|
151
152
|
if (ack?.state === "delivered") {
|
|
152
|
-
return { content: [{ type: "text", text: `Steering delivered for foreground run ${control.runId} (request ${request.id}).` }], details: { mode: "management", results: [], steering } };
|
|
153
|
+
return { content: [{ type: "text", text: steeringReceipt(request.message, `Steering delivered for foreground run ${control.runId} (request ${request.id}).`) }], details: { mode: "management", results: [], steering } };
|
|
153
154
|
}
|
|
154
155
|
if (ack?.state === "queued") {
|
|
155
|
-
return { content: [{ type: "text", text: `Steering queued for foreground run ${control.runId} (request ${request.id}).` }], details: { mode: "management", results: [], steering } };
|
|
156
|
+
return { content: [{ type: "text", text: steeringReceipt(request.message, `Steering queued for foreground run ${control.runId} (request ${request.id}).`) }], details: { mode: "management", results: [], steering } };
|
|
156
157
|
}
|
|
157
158
|
if (ack?.state === "failed") {
|
|
158
|
-
return { content: [{ type: "text", text: `Steering failed for foreground run ${control.runId} (request ${request.id}): ${ack.message}` }], isError: true, details: { mode: "management", results: [], steering } };
|
|
159
|
+
return { content: [{ type: "text", text: steeringReceipt(request.message, `Steering failed for foreground run ${control.runId} (request ${request.id}): ${ack.message}`) }], isError: true, details: { mode: "management", results: [], steering } };
|
|
159
160
|
}
|
|
160
|
-
return { content: [{ type: "text", text: `Steering pending for foreground run ${control.runId} (request ${request.id}); no acknowledgment was received.` }], details: { mode: "management", results: [], steering } };
|
|
161
|
+
return { content: [{ type: "text", text: steeringReceipt(request.message, `Steering pending for foreground run ${control.runId} (request ${request.id}); no acknowledgment was received.`) }], details: { mode: "management", results: [], steering } };
|
|
161
162
|
}
|
|
162
163
|
|
|
163
164
|
export function workflowForegroundSteeringDir(asyncDirRoot: string, workflowRunId: string, childRunId: string): string {
|
|
@@ -946,7 +946,7 @@ function reportEvidenceStatus(report: AcceptanceReport, kind: AcceptanceEvidence
|
|
|
946
946
|
}
|
|
947
947
|
|
|
948
948
|
function checkNoStagedFiles(cwd: string): AcceptanceRuntimeCheck {
|
|
949
|
-
const result = spawnSync("git", ["status", "--short"], { cwd, encoding: "utf-8" });
|
|
949
|
+
const result = spawnSync("git", ["status", "--short"], { cwd, encoding: "utf-8", windowsHide: true });
|
|
950
950
|
if (result.status !== 0) {
|
|
951
951
|
return { id: "no-staged-files", status: "not-applicable", message: "git status unavailable; no staged-files check skipped" };
|
|
952
952
|
}
|
|
@@ -1053,11 +1053,11 @@ interface VerifyWorkspaceState {
|
|
|
1053
1053
|
}
|
|
1054
1054
|
|
|
1055
1055
|
function readVerifyWorkspaceState(cwd: string): VerifyWorkspaceState | undefined {
|
|
1056
|
-
const repo = spawnSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf-8" });
|
|
1056
|
+
const repo = spawnSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf-8", windowsHide: true });
|
|
1057
1057
|
if (repo.status !== 0 || !repo.stdout.trim()) return undefined;
|
|
1058
1058
|
const repoRoot = fs.realpathSync(repo.stdout.trim());
|
|
1059
|
-
const head = spawnSync("git", ["rev-parse", "HEAD"], { cwd: repoRoot, encoding: "utf-8" });
|
|
1060
|
-
const diff = spawnSync("git", ["diff", "--binary", "--full-index", "HEAD", "--"], { cwd: repoRoot, encoding: "utf-8", maxBuffer: 50 * 1024 * 1024 });
|
|
1059
|
+
const head = spawnSync("git", ["rev-parse", "HEAD"], { cwd: repoRoot, encoding: "utf-8", windowsHide: true });
|
|
1060
|
+
const diff = spawnSync("git", ["diff", "--binary", "--full-index", "HEAD", "--"], { cwd: repoRoot, encoding: "utf-8", maxBuffer: 50 * 1024 * 1024, windowsHide: true });
|
|
1061
1061
|
if (head.status !== 0 || diff.status !== 0 || !head.stdout.trim()) return undefined;
|
|
1062
1062
|
return {
|
|
1063
1063
|
kind: "git-tracked",
|
|
@@ -1140,6 +1140,49 @@ async function runMemoizedVerifyCommand(command: AcceptanceVerifyCommand, defaul
|
|
|
1140
1140
|
return evidenced;
|
|
1141
1141
|
}
|
|
1142
1142
|
|
|
1143
|
+
/**
|
|
1144
|
+
* On Windows with `shell: true`, cmd.exe parses the command line itself and an
|
|
1145
|
+
* unquoted executable path containing spaces (e.g. `C:\Program Files\...\tool.exe`)
|
|
1146
|
+
* is split at the first space, so cmd tries to run `C:\Program` and fails.
|
|
1147
|
+
*
|
|
1148
|
+
* The command line is ambiguous, so only an unquoted absolute drive path with
|
|
1149
|
+
* a space in a directory component is safe to identify as an executable. That
|
|
1150
|
+
* path is quoted; everything after it is preserved as arguments.
|
|
1151
|
+
*
|
|
1152
|
+
* Commands that already start with a quote, single-token commands, and commands
|
|
1153
|
+
* whose first token already ends in an executable extension are returned
|
|
1154
|
+
* unchanged. Non-Windows platforms pass the command through untouched.
|
|
1155
|
+
*/
|
|
1156
|
+
export function quoteExecutableForShell(command: string, platform: string = process.platform): string {
|
|
1157
|
+
if (platform !== "win32") return command;
|
|
1158
|
+
const trimmed = command.trimStart();
|
|
1159
|
+
if (trimmed.startsWith("\"")) return command;
|
|
1160
|
+
const firstToken = trimmed.match(/^\S+/)?.[0];
|
|
1161
|
+
if (/\.(?:exe|bat|cmd|com|ps1)$/i.test(firstToken ?? "")) return command;
|
|
1162
|
+
const match = trimmed.match(/^([A-Za-z]:\\[^"<>|&*?\r\n]*?\s[^"<>|&*?\r\n]*?\\[^"<>|&*?\r\n]*?\.(?:exe|bat|cmd|com|ps1))(?=\s|$)/i);
|
|
1163
|
+
const executable = match?.[1];
|
|
1164
|
+
if (executable && /\s/.test(executable) && !/[A-Za-z]:\\/.test(executable.slice(3))) {
|
|
1165
|
+
const rest = trimmed.slice(executable.length);
|
|
1166
|
+
const leading = command.slice(0, command.length - trimmed.length);
|
|
1167
|
+
return `${leading}"${executable}"${rest}`;
|
|
1168
|
+
}
|
|
1169
|
+
const extensionlessSpacedFilenameMatch = trimmed.match(/^([A-Za-z]:\\[^"<>|&*?\r\n]*?\s[^"<>|&*?\r\n]*?)(?=\s+--|$)/i);
|
|
1170
|
+
const extensionlessSpacedFilename = extensionlessSpacedFilenameMatch?.[1];
|
|
1171
|
+
if (extensionlessSpacedFilename && /\s/.test(extensionlessSpacedFilename.slice(0, extensionlessSpacedFilename.lastIndexOf("\\"))) && !/[A-Za-z]:\\/.test(extensionlessSpacedFilename.slice(3))) {
|
|
1172
|
+
const rest = trimmed.slice(extensionlessSpacedFilename.length);
|
|
1173
|
+
const leading = command.slice(0, command.length - trimmed.length);
|
|
1174
|
+
return `${leading}"${extensionlessSpacedFilename}"${rest}`;
|
|
1175
|
+
}
|
|
1176
|
+
const extensionlessMatch = trimmed.match(/^([A-Za-z]:\\[^"<>|&*?\r\n]*?\s[^"<>|&*?\r\n]*?\\[^"<>|&*?\s\r\n]+)(?=\s|$)/i);
|
|
1177
|
+
const extensionlessExecutable = extensionlessMatch?.[1];
|
|
1178
|
+
if (extensionlessExecutable && /\s/.test(extensionlessExecutable) && !/[A-Za-z]:\\/.test(extensionlessExecutable.slice(3)) && !/\s/.test(extensionlessExecutable.slice(extensionlessExecutable.lastIndexOf("\\") + 1))) {
|
|
1179
|
+
const rest = trimmed.slice(extensionlessExecutable.length);
|
|
1180
|
+
const leading = command.slice(0, command.length - trimmed.length);
|
|
1181
|
+
return `${leading}"${extensionlessExecutable}"${rest}`;
|
|
1182
|
+
}
|
|
1183
|
+
return command;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1143
1186
|
function runVerifyCommand(command: AcceptanceVerifyCommand, defaultCwd: string, options: { signal?: AbortSignal; abortMessage?: string } = {}): Promise<AcceptanceVerifyResult> {
|
|
1144
1187
|
return new Promise((resolve) => {
|
|
1145
1188
|
const startedAt = Date.now();
|
|
@@ -1149,7 +1192,7 @@ function runVerifyCommand(command: AcceptanceVerifyCommand, defaultCwd: string,
|
|
|
1149
1192
|
let timedOut = false;
|
|
1150
1193
|
let settled = false;
|
|
1151
1194
|
let hardKill: NodeJS.Timeout | undefined;
|
|
1152
|
-
const child = spawn(command.command, {
|
|
1195
|
+
const child = spawn(quoteExecutableForShell(command.command), {
|
|
1153
1196
|
cwd,
|
|
1154
1197
|
env: effectiveVerifyEnv(command.env),
|
|
1155
1198
|
shell: true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isDynamicParallelStep, isParallelStep, type ChainStep, type SequentialStep } from "../../shared/settings.ts";
|
|
2
2
|
import type { ChainOutputMap, ChainOutputMapEntry, SingleResult } from "../../shared/types.ts";
|
|
3
3
|
import { getSingleResultOutput } from "../../shared/utils.ts";
|
|
4
4
|
import { DynamicFanoutError, hasDynamicFanoutFields, type DynamicFanoutConfig, validateDynamicStepShape } from "./dynamic-fanout.ts";
|
|
@@ -14,7 +14,6 @@ export interface ChainOutputValidationContext {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function outputNamesForStep(step: ChainStep): string[] {
|
|
17
|
-
if (isCheckpointStep(step)) return [];
|
|
18
17
|
if (isParallelStep(step)) return step.parallel.map((task) => task.as).filter((name): name is string => Boolean(name));
|
|
19
18
|
if (isDynamicParallelStep(step)) return [step.collect.as];
|
|
20
19
|
const name = (step as SequentialStep).as;
|
|
@@ -22,7 +21,6 @@ function outputNamesForStep(step: ChainStep): string[] {
|
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
function taskTemplatesForStep(step: ChainStep): string[] {
|
|
25
|
-
if (isCheckpointStep(step)) return [];
|
|
26
24
|
if (isParallelStep(step)) return step.parallel.map((task) => task.task ?? "{previous}");
|
|
27
25
|
if (isDynamicParallelStep(step)) return [step.parallel.task ?? "{previous}", step.parallel.label ?? ""].filter(Boolean);
|
|
28
26
|
return [(step as SequentialStep).task ?? "{previous}"];
|