@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,140 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { writePrivateAtomicJson } from "../shared/atomic-json.ts";
|
|
4
|
+
import type { WorkflowReceipt, WorkflowReceiptEntry, WorkflowReceiptState } from "../shared/types.ts";
|
|
5
|
+
import type { WorkflowReceiptResumeReference, WorkflowScriptChildResult } from "./scripted-workflow.ts";
|
|
6
|
+
|
|
7
|
+
export type { WorkflowReceipt, WorkflowReceiptEntry, WorkflowReceiptState } from "../shared/types.ts";
|
|
8
|
+
|
|
9
|
+
export const WORKFLOW_RECEIPT_VERSION = 1;
|
|
10
|
+
export const WORKFLOW_RECEIPT_FILE = "workflow-receipt.json";
|
|
11
|
+
|
|
12
|
+
const KEY_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
13
|
+
|
|
14
|
+
function assertSafeRunId(value: string, label: string): string {
|
|
15
|
+
const normalized = value.trim();
|
|
16
|
+
if (!normalized || path.basename(normalized) !== normalized || normalized === "." || normalized === "..") {
|
|
17
|
+
throw new Error(`${label} must be an exact workflow run id, not a path or prefix.`);
|
|
18
|
+
}
|
|
19
|
+
return normalized;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function assertKey(value: string, label: string): string {
|
|
23
|
+
if (!KEY_PATTERN.test(value)) throw new Error(`${label} is invalid.`);
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function workflowReceiptPath(asyncDirRoot: string, workflowRunId: string): string {
|
|
28
|
+
return path.join(asyncDirRoot, assertSafeRunId(workflowRunId, "workflowRunId"), WORKFLOW_RECEIPT_FILE);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function buildWorkflowReceipt(input: {
|
|
32
|
+
workflowRunId: string;
|
|
33
|
+
state: WorkflowReceiptState;
|
|
34
|
+
children: WorkflowScriptChildResult[];
|
|
35
|
+
createdAt?: number;
|
|
36
|
+
}): WorkflowReceipt {
|
|
37
|
+
const workflowRunId = assertSafeRunId(input.workflowRunId, "workflowRunId");
|
|
38
|
+
const entries: Record<string, WorkflowReceiptEntry> = Object.create(null) as Record<string, WorkflowReceiptEntry>;
|
|
39
|
+
for (const child of input.children) {
|
|
40
|
+
const key = assertKey(child.key, "workflow receipt child key");
|
|
41
|
+
if (entries[key]) throw new Error(`Workflow receipt has duplicate child key '${key}'.`);
|
|
42
|
+
const runIds = [...new Set((child.continuation?.runIds ?? (child.runId ? [child.runId] : [])).filter((runId) => typeof runId === "string" && runId.trim()).map((runId) => runId.trim()))];
|
|
43
|
+
const latestRunId = runIds.at(-1);
|
|
44
|
+
const resumability = child.resumability ?? { state: "not-resumable", reason: child.runId ? "resumability was not recorded" : "child produced no run id" };
|
|
45
|
+
if (resumability.state === "resumable" && !latestRunId) throw new Error(`Workflow receipt child '${key}' is resumable but has no retained run id.`);
|
|
46
|
+
const base = {
|
|
47
|
+
key,
|
|
48
|
+
...(child.agent ? { agent: child.agent } : {}),
|
|
49
|
+
...(child.requestedContext ? { requestedContext: child.requestedContext } : {}),
|
|
50
|
+
...(child.resolvedContext ? { resolvedContext: child.resolvedContext } : {}),
|
|
51
|
+
...(child.outputReference ? { outputReference: child.outputReference } : {}),
|
|
52
|
+
continuation: { runIds },
|
|
53
|
+
};
|
|
54
|
+
entries[key] = resumability.state === "resumable"
|
|
55
|
+
? { ...base, latestRunId: latestRunId!, resumability }
|
|
56
|
+
: { ...base, ...(latestRunId ? { latestRunId } : {}), resumability };
|
|
57
|
+
}
|
|
58
|
+
return { version: WORKFLOW_RECEIPT_VERSION, workflowRunId, state: input.state, createdAt: input.createdAt ?? Date.now(), entries };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function writeWorkflowReceipt(asyncDir: string, receipt: WorkflowReceipt): string {
|
|
62
|
+
const receiptPath = path.join(asyncDir, WORKFLOW_RECEIPT_FILE);
|
|
63
|
+
writePrivateAtomicJson(receiptPath, receipt);
|
|
64
|
+
return receiptPath;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function parseEntry(value: unknown, key: string, source: string): WorkflowReceiptEntry {
|
|
68
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`Invalid workflow receipt '${source}': entry '${key}' must be an object.`);
|
|
69
|
+
const entry = value as Record<string, unknown>;
|
|
70
|
+
if (entry.key !== key) throw new Error(`Invalid workflow receipt '${source}': entry '${key}' has a mismatched key.`);
|
|
71
|
+
const latestRunId = entry.latestRunId;
|
|
72
|
+
if (latestRunId !== undefined && (typeof latestRunId !== "string" || !latestRunId.trim())) throw new Error(`Invalid workflow receipt '${source}': entry '${key}' latestRunId must be non-empty.`);
|
|
73
|
+
const continuation = entry.continuation;
|
|
74
|
+
if (!continuation || typeof continuation !== "object" || Array.isArray(continuation) || !Array.isArray((continuation as Record<string, unknown>).runIds)) {
|
|
75
|
+
throw new Error(`Invalid workflow receipt '${source}': entry '${key}' continuation is missing.`);
|
|
76
|
+
}
|
|
77
|
+
const runIds = (continuation as { runIds: unknown[] }).runIds;
|
|
78
|
+
if (runIds.some((runId) => typeof runId !== "string" || !runId.trim())) throw new Error(`Invalid workflow receipt '${source}': entry '${key}' continuation contains an invalid run id.`);
|
|
79
|
+
if (latestRunId !== undefined && runIds.at(-1) !== latestRunId) throw new Error(`Workflow receipt '${source}' entry '${key}' is stale: latestRunId does not match its continuation lineage.`);
|
|
80
|
+
const resumability = entry.resumability;
|
|
81
|
+
if (!resumability || typeof resumability !== "object" || Array.isArray(resumability)) throw new Error(`Invalid workflow receipt '${source}': entry '${key}' resumability is missing.`);
|
|
82
|
+
const state = (resumability as Record<string, unknown>).state;
|
|
83
|
+
if (state !== "resumable" && state !== "not-resumable") throw new Error(`Invalid workflow receipt '${source}': entry '${key}' resumability state is invalid.`);
|
|
84
|
+
const reason = (resumability as Record<string, unknown>).reason;
|
|
85
|
+
if (state === "resumable" && latestRunId === undefined) throw new Error(`Invalid workflow receipt '${source}': entry '${key}' resumable entry has no retained run id.`);
|
|
86
|
+
if (state === "not-resumable" && (typeof reason !== "string" || !reason.trim())) throw new Error(`Invalid workflow receipt '${source}': entry '${key}' non-resumable reason is missing.`);
|
|
87
|
+
return value as WorkflowReceiptEntry;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function readWorkflowReceipt(asyncDirRoot: string, workflowRunId: string): WorkflowReceipt {
|
|
91
|
+
const receiptPath = workflowReceiptPath(asyncDirRoot, workflowRunId);
|
|
92
|
+
let value: unknown;
|
|
93
|
+
try {
|
|
94
|
+
value = JSON.parse(fs.readFileSync(receiptPath, "utf-8")) as unknown;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") throw new Error(`Workflow receipt '${workflowRunId}' was not found.`);
|
|
97
|
+
throw new Error(`Workflow receipt '${workflowRunId}' could not be read: ${error instanceof Error ? error.message : String(error)}`, { cause: error instanceof Error ? error : undefined });
|
|
98
|
+
}
|
|
99
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`Invalid workflow receipt '${receiptPath}': expected an object.`);
|
|
100
|
+
const receipt = value as Record<string, unknown>;
|
|
101
|
+
if (receipt.version !== WORKFLOW_RECEIPT_VERSION) throw new Error(`Invalid workflow receipt '${receiptPath}': unsupported version.`);
|
|
102
|
+
if (receipt.workflowRunId !== workflowRunId) throw new Error(`Workflow receipt '${receiptPath}' is stale: workflowRunId does not match.`);
|
|
103
|
+
if (receipt.state !== "complete" && receipt.state !== "failed" && receipt.state !== "paused" && receipt.state !== "stopped") {
|
|
104
|
+
throw new Error(`Workflow receipt '${receiptPath}' is stale: workflow is not terminal.`);
|
|
105
|
+
}
|
|
106
|
+
if (typeof receipt.createdAt !== "number" || !Number.isFinite(receipt.createdAt)) throw new Error(`Invalid workflow receipt '${receiptPath}': createdAt is invalid.`);
|
|
107
|
+
if (!receipt.entries || typeof receipt.entries !== "object" || Array.isArray(receipt.entries)) throw new Error(`Invalid workflow receipt '${receiptPath}': entries must be an object.`);
|
|
108
|
+
const entries: Record<string, WorkflowReceiptEntry> = Object.create(null) as Record<string, WorkflowReceiptEntry>;
|
|
109
|
+
for (const [key, entry] of Object.entries(receipt.entries as Record<string, unknown>)) entries[assertKey(key, "workflow receipt key")] = parseEntry(entry, key, receiptPath);
|
|
110
|
+
return { version: 1, workflowRunId, state: receipt.state, createdAt: receipt.createdAt, entries };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function resolveWorkflowReceiptResumeEntry(input: {
|
|
114
|
+
reference: WorkflowReceiptResumeReference;
|
|
115
|
+
asyncDirRoot: string;
|
|
116
|
+
assertResumable?: (runId: string) => void;
|
|
117
|
+
}): WorkflowReceiptEntry & { latestRunId: string; resumability: { state: "resumable" } } {
|
|
118
|
+
if (input.reference.latest !== true) throw new Error("Keyed workflow receipt resume requires latest: true.");
|
|
119
|
+
const key = assertKey(input.reference.key, "keyed resume key");
|
|
120
|
+
const receipt = readWorkflowReceipt(input.asyncDirRoot, input.reference.workflowRunId.trim());
|
|
121
|
+
const entry = receipt.entries[key];
|
|
122
|
+
if (!entry) throw new Error(`Workflow receipt '${receipt.workflowRunId}' has no child key '${key}'.`);
|
|
123
|
+
assertResumableEntry(entry, receipt.workflowRunId, key);
|
|
124
|
+
input.assertResumable?.(entry.latestRunId);
|
|
125
|
+
return entry;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function assertResumableEntry(entry: WorkflowReceiptEntry, workflowRunId: string, key: string): asserts entry is WorkflowReceiptEntry & { latestRunId: string; resumability: { state: "resumable" } } {
|
|
129
|
+
if (entry.resumability.state !== "resumable") throw new Error(`Workflow receipt '${workflowRunId}' child '${key}' is not resumable: ${entry.resumability.reason}.`);
|
|
130
|
+
if (!entry.latestRunId) throw new Error(`Workflow receipt '${workflowRunId}' child '${key}' has no retained run id.`);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function resolveWorkflowReceiptResume(input: {
|
|
134
|
+
reference: WorkflowReceiptResumeReference;
|
|
135
|
+
asyncDirRoot: string;
|
|
136
|
+
assertResumable?: (runId: string) => void;
|
|
137
|
+
}): string {
|
|
138
|
+
const entry = resolveWorkflowReceiptResumeEntry(input);
|
|
139
|
+
return entry.latestRunId;
|
|
140
|
+
}
|