@xzzpig/pi-subagents 0.20.0 → 0.22.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 +164 -0
- package/README.md +1 -1
- package/agents/oracle.md +8 -19
- package/agents/researcher.md +0 -3
- package/agents/reviewer.md +17 -61
- package/agents/scout.md +1 -4
- package/agents/worker.md +8 -25
- package/docs/agents.md +72 -7
- package/docs/configuration.md +58 -7
- package/docs/extension-api.md +36 -11
- package/docs/fork-extensions.md +1 -0
- package/docs/fork-supervisor-routing.md +77 -0
- package/docs/missions.md +34 -17
- package/docs/models.md +1 -1
- package/docs/observability.md +10 -5
- package/docs/tool-reference.md +117 -84
- package/docs/watchdog.md +8 -6
- package/docs/workflows.md +16 -7
- package/index.ts +5 -0
- package/package.json +6 -3
- package/prompts/council.md +1 -1
- package/skills/pi-subagents/SKILL.md +1 -1
- package/skills/pi-subagents/references/constraints-and-recipes.md +1 -1
- package/skills/pi-subagents/references/execution-controls.md +16 -16
- package/skills/pi-subagents/references/management-authoring-rpc.md +16 -12
- package/skills/pi-subagents/references/prompting-and-roles.md +3 -3
- package/src/agents/advertised-agent-prompt.ts +9 -1
- package/src/agents/agent-management.ts +4 -0
- package/src/agents/agent-memory.ts +3 -3
- package/src/agents/agent-scope.ts +4 -0
- package/src/agents/agent-serializer.ts +8 -1
- package/src/agents/agents.ts +191 -145
- package/src/api/preflight.ts +8 -4
- package/src/api/supervisor-routing.ts +196 -0
- package/src/extension/config.ts +21 -2
- package/src/extension/context-injection.ts +6 -1
- package/src/extension/control-notices.ts +1 -9
- package/src/extension/declaration-pinning.ts +164 -0
- package/src/extension/doctor.ts +7 -10
- package/src/extension/fanout-child.ts +7 -8
- package/src/extension/index.ts +143 -134
- package/src/extension/reply-workflow-script.ts +20 -11
- package/src/extension/rpc.ts +11 -6
- package/src/extension/schemas.ts +34 -30
- package/src/extension/subagent-guide.ts +86 -6
- package/src/extension/subagent-options.ts +47 -0
- package/src/extension/tool-activation.ts +3 -2
- package/src/extension/tool-description.ts +51 -68
- package/src/inspectors/actions.ts +37 -11
- package/src/inspectors/plugins.ts +3 -2
- package/src/inspectors/tmux/actions.ts +204 -0
- package/src/inspectors/tmux/client.ts +85 -0
- package/src/inspectors/tmux/plugin.ts +21 -0
- package/src/integrations/herdr-status.ts +18 -49
- package/src/integrations/program-status.ts +215 -0
- package/src/intercom/fork-supervisor-routing.ts +533 -0
- package/src/intercom/native-supervisor-channel.ts +152 -13
- package/src/intercom/result-intercom.ts +3 -2
- package/src/intercom/supervisor-ui.ts +2 -174
- package/src/missions/store.ts +25 -5
- package/src/profiles/profiles.ts +24 -21
- package/src/runs/background/active-async-capacity.ts +58 -8
- package/src/runs/background/async-execution.ts +143 -38
- package/src/runs/background/async-job-tracker.ts +11 -4
- package/src/runs/background/async-resume.ts +5 -2
- package/src/runs/background/await-async-run.ts +14 -9
- package/src/runs/background/binary-bootstrap.ts +2 -1
- package/src/runs/background/calendar-schedule.ts +90 -0
- package/src/runs/background/chain-root-attachment.ts +9 -5
- package/src/runs/background/fleet-view.ts +5 -5
- package/src/runs/background/notify.ts +185 -12
- package/src/runs/background/result-files.ts +116 -5
- package/src/runs/background/result-watcher.ts +99 -66
- package/src/runs/background/resume-guidance.ts +2 -2
- package/src/runs/background/run-child-session.ts +16 -2
- package/src/runs/background/run-id-resolver.ts +8 -5
- package/src/runs/background/run-status.ts +21 -16
- package/src/runs/background/runner-child-launch.ts +1 -0
- package/src/runs/background/runner-http-dispatcher.ts +3 -0
- package/src/runs/background/scheduled-runs.ts +256 -61
- package/src/runs/background/subagent-runner-bootstrap.ts +4 -1
- package/src/runs/background/subagent-runner.ts +32 -12
- package/src/runs/background/subagent-wait.ts +38 -19
- package/src/runs/background/terminal-run-index.ts +46 -1
- package/src/runs/background/wait-completions.ts +1 -0
- package/src/runs/background/wait-tool.ts +33 -23
- package/src/runs/background/workflow-terminal-proof.ts +39 -22
- package/src/runs/foreground/async-stop-action.ts +48 -22
- package/src/runs/foreground/execution.ts +94 -52
- package/src/runs/foreground/foreground-history.ts +1 -0
- package/src/runs/foreground/subagent-executor.ts +232 -77
- package/src/runs/shared/child-commands.ts +2 -1
- package/src/runs/shared/child-hooks.ts +4 -3
- package/src/runs/shared/child-launch.ts +3 -0
- package/src/runs/shared/child-session.ts +41 -24
- package/src/runs/shared/child-tool-plan.ts +13 -26
- package/src/runs/shared/dynamic-fanout.ts +1 -1
- package/src/runs/shared/fork-command-result.ts +10 -0
- package/src/runs/shared/herdr-placed-run.ts +5 -4
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +5 -3
- package/src/runs/shared/model-resolution-diagnostic.ts +25 -0
- package/src/runs/shared/model-resolution.ts +30 -1
- package/src/runs/shared/nested-events.ts +5 -0
- package/src/runs/shared/parallel-handoff.ts +56 -8
- package/src/runs/shared/parallel-utils.ts +2 -0
- package/src/runs/shared/partial-output.ts +48 -0
- package/src/runs/shared/runner-launcher.ts +25 -0
- package/src/runs/shared/single-output.ts +53 -0
- package/src/runs/shared/structured-output.ts +14 -7
- package/src/runs/shared/subagent-control.ts +3 -3
- package/src/runs/shared/subagent-prompt-runtime.ts +47 -24
- package/src/runs/shared/workflow-async-child-guidance.ts +1 -1
- package/src/runs/shared/worktree-cleanup-apply.ts +160 -0
- package/src/runs/shared/worktree-cleanup-plan.ts +41 -19
- package/src/runs/shared/worktree-lock.ts +29 -0
- package/src/runs/shared/worktree.ts +12 -1
- package/src/shared/atomic-json.ts +4 -2
- package/src/shared/edit-distance.ts +33 -0
- package/src/shared/file-lease.ts +74 -0
- package/src/shared/formatters.ts +1 -5
- package/src/shared/model-info.ts +22 -0
- package/src/shared/package-version.ts +17 -0
- package/src/shared/parent-wake.ts +79 -0
- package/src/shared/pruned-fork.ts +7 -1
- package/src/shared/runtime-module-path.ts +19 -0
- package/src/shared/settings-file-lease.ts +36 -0
- package/src/shared/types.ts +36 -2
- package/src/shared/utils.ts +8 -6
- package/src/slash/prompt-template-bridge.ts +21 -20
- package/src/slash/slash-commands.ts +3 -3
- package/src/slash/subagents-admin.ts +2 -1
- package/src/tui/fleet-native-transcript.ts +2 -0
- package/src/tui/fleet-transcript.ts +12 -3
- package/src/tui/fleet.ts +11 -8
- package/src/tui/render.ts +27 -19
- package/src/tui/subagent-messages.ts +305 -0
- package/src/watchdog/diff-tool.ts +2 -2
- package/src/watchdog/register-main.ts +2 -22
- package/src/watchdog/render.ts +2 -24
- package/src/watchdog/runtime.ts +6 -4
- package/src/watchdog/settings.ts +18 -13
- package/src/watchdog/tool-actions.ts +2 -2
- package/src/workflows/scripted-workflow.ts +20 -6
- package/src/workflows/workflow-resources.ts +11 -0
|
@@ -5,8 +5,9 @@ import { writePrivateAtomicJson } from "../../shared/atomic-json.ts";
|
|
|
5
5
|
import { TEMP_ROOT_DIR, type ActiveAsyncCapacitySnapshot, type AsyncStatus } from "../../shared/types.ts";
|
|
6
6
|
import { readStatus } from "../../shared/utils.ts";
|
|
7
7
|
import { checkPidLiveness, type PidLiveness } from "./stale-run-reconciler.ts";
|
|
8
|
+
import { currentPidNamespaceScope } from "./pid-namespace.ts";
|
|
8
9
|
import { readProcessTerminal } from "./process-terminal.ts";
|
|
9
|
-
import { isTerminalAsyncState as terminalState, readWorkflowChildProcessEvidence } from "./workflow-terminal-proof.ts";
|
|
10
|
+
import { isTerminalAsyncState as terminalState, readWorkflowChildEvidence, readWorkflowChildProcessEvidence } from "./workflow-terminal-proof.ts";
|
|
10
11
|
|
|
11
12
|
export const ACTIVE_ASYNC_CAPACITY_DIR = path.join(TEMP_ROOT_DIR, "session-active-async-capacity");
|
|
12
13
|
export const DEFAULT_ABANDONED_SLOT_RELEASE_AFTER_MS = 20 * 60 * 1000;
|
|
@@ -44,11 +45,12 @@ interface CapacityOptions {
|
|
|
44
45
|
token?: () => string;
|
|
45
46
|
abandonedSlotReleaseAfterMs?: number | false;
|
|
46
47
|
pidLiveness?: (pid: number) => PidLiveness;
|
|
48
|
+
pidNamespaceScope?: () => string | undefined;
|
|
47
49
|
afterSlotRename?: (releasedDir: string) => void;
|
|
48
50
|
writeOwner?: (filePath: string, owner: ActiveAsyncCapacityOwner) => void;
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
interface AbandonedRunnerEvidence {
|
|
52
54
|
releasedBy: "abandoned-timeout";
|
|
53
55
|
processProof: "unknown";
|
|
54
56
|
runnerPid: "gone";
|
|
@@ -56,6 +58,18 @@ export interface ActiveAsyncCapacityReleaseEvidence {
|
|
|
56
58
|
abandonedSlotReleaseAfterMs: number;
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
/** A workflow's own status PID is the parent Pi host, so workflow evidence names its dead child runners instead. */
|
|
62
|
+
interface AbandonedWorkflowEvidence {
|
|
63
|
+
releasedBy: "abandoned-timeout";
|
|
64
|
+
processProof: "unknown";
|
|
65
|
+
controller: "unregistered";
|
|
66
|
+
workflowEndedAgeMs: number;
|
|
67
|
+
abandonedChildren: Array<{ runId: string; lastActivityAgeMs: number }>;
|
|
68
|
+
abandonedSlotReleaseAfterMs: number;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type ActiveAsyncCapacityReleaseEvidence = AbandonedRunnerEvidence | AbandonedWorkflowEvidence;
|
|
72
|
+
|
|
59
73
|
export type ActiveAsyncCapacityReleaseVerdict =
|
|
60
74
|
| { state: "releasable"; reason: string; evidence?: ActiveAsyncCapacityReleaseEvidence }
|
|
61
75
|
| { state: "retained"; reason: string }
|
|
@@ -232,12 +246,14 @@ function runnerReleaseVerdict(owner: ActiveAsyncCapacityOwner, status: AsyncStat
|
|
|
232
246
|
: abandonedRunnerReleaseVerdict(status, proof?.state ?? "missing", options);
|
|
233
247
|
}
|
|
234
248
|
|
|
235
|
-
function abandonedRunnerReleaseVerdict(status: AsyncStatus, proofState: string, options: CapacityOptions):
|
|
249
|
+
function abandonedRunnerReleaseVerdict(status: AsyncStatus, proofState: string, options: CapacityOptions): { state: "retained"; reason: string } | { state: "releasable"; reason: string; evidence: AbandonedRunnerEvidence } {
|
|
236
250
|
const proofReason = `process-terminal proof is ${proofState}`;
|
|
237
251
|
const thresholdMs = resolveAbandonedSlotReleaseAfterMs(options.abandonedSlotReleaseAfterMs);
|
|
238
252
|
if (thresholdMs === false) return { state: "retained", reason: `${proofReason}; abandoned-timeout policy is disabled` };
|
|
239
253
|
if (status.state !== "failed") return { state: "retained", reason: `${proofReason}; abandoned-timeout policy requires a failed run, not ${status.state}` };
|
|
240
254
|
if (typeof status.pid !== "number" || !Number.isInteger(status.pid) || status.pid < 1) return { state: "retained", reason: `${proofReason}; runner PID is missing or invalid` };
|
|
255
|
+
// A PID from another namespace can look dead here while the runner is alive.
|
|
256
|
+
if (status.pidNamespaceScope !== undefined && status.pidNamespaceScope !== (options.pidNamespaceScope ?? currentPidNamespaceScope)()) return { state: "retained", reason: `${proofReason}; runner PID namespace differs from this process, so liveness is unknown` };
|
|
241
257
|
const liveness = (options.pidLiveness ?? checkPidLiveness)(status.pid);
|
|
242
258
|
if (liveness !== "dead") return { state: "retained", reason: `${proofReason}; runner PID liveness is ${liveness}` };
|
|
243
259
|
const lastActivityAt = status.lastActivityAt ?? status.lastUpdate ?? status.endedAt;
|
|
@@ -245,7 +261,7 @@ function abandonedRunnerReleaseVerdict(status: AsyncStatus, proofState: string,
|
|
|
245
261
|
const now = options.now?.() ?? Date.now();
|
|
246
262
|
const lastActivityAgeMs = Math.max(0, now - lastActivityAt);
|
|
247
263
|
if (lastActivityAgeMs <= thresholdMs) return { state: "retained", reason: `${proofReason}; last activity age ${lastActivityAgeMs}ms has not exceeded abandoned-timeout ${thresholdMs}ms` };
|
|
248
|
-
const evidence:
|
|
264
|
+
const evidence: AbandonedRunnerEvidence = {
|
|
249
265
|
releasedBy: "abandoned-timeout",
|
|
250
266
|
processProof: "unknown",
|
|
251
267
|
runnerPid: "gone",
|
|
@@ -259,7 +275,7 @@ function abandonedRunnerReleaseVerdict(status: AsyncStatus, proofState: string,
|
|
|
259
275
|
};
|
|
260
276
|
}
|
|
261
277
|
|
|
262
|
-
function workflowReleaseVerdict(owner: ActiveAsyncCapacityOwner, status: AsyncStatus | null, liveWorkflowRunIds: ReadonlySet<string
|
|
278
|
+
function workflowReleaseVerdict(owner: ActiveAsyncCapacityOwner, status: AsyncStatus | null, liveWorkflowRunIds: ReadonlySet<string>, options: CapacityOptions): ActiveAsyncCapacityReleaseVerdict {
|
|
263
279
|
if (!status) return { state: "retained", reason: "status file is missing or unreadable" };
|
|
264
280
|
if (status.sessionId !== owner.ownerSessionId) return { state: "retained", reason: `status session ${status.sessionId ?? "unknown"} does not match owner session ${owner.ownerSessionId}` };
|
|
265
281
|
if (status.runId !== owner.runId) return { state: "retained", reason: `status run ${status.runId} does not match owner run ${owner.runId}` };
|
|
@@ -267,15 +283,49 @@ function workflowReleaseVerdict(owner: ActiveAsyncCapacityOwner, status: AsyncSt
|
|
|
267
283
|
if (!terminalState(status.state)) return { state: "retained", reason: `workflow is still ${status.state}` };
|
|
268
284
|
if (liveWorkflowRunIds.has(owner.runId)) return { state: "retained", reason: "workflow controller is still live" };
|
|
269
285
|
const evidence = readWorkflowChildProcessEvidence(owner.asyncDir, status.steps);
|
|
270
|
-
if (evidence.state
|
|
271
|
-
return
|
|
286
|
+
if (evidence.state === "observed") return { state: "releasable", reason: "workflow is terminal, controller is gone, and async children have observed proof" };
|
|
287
|
+
return abandonedWorkflowReleaseVerdict(owner, status, evidence.reason, options);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Every unresolved async child must itself pass the abandoned runner policy; any other unresolved child keeps the slot. */
|
|
291
|
+
function abandonedWorkflowReleaseVerdict(owner: ActiveAsyncCapacityOwner, status: AsyncStatus, proofReason: string, options: CapacityOptions): ActiveAsyncCapacityReleaseVerdict {
|
|
292
|
+
const thresholdMs = resolveAbandonedSlotReleaseAfterMs(options.abandonedSlotReleaseAfterMs);
|
|
293
|
+
if (thresholdMs === false) return { state: "retained", reason: `${proofReason}; abandoned-timeout policy is disabled` };
|
|
294
|
+
if (!status.steps) return { state: "retained", reason: proofReason };
|
|
295
|
+
if (typeof status.endedAt !== "number" || !Number.isFinite(status.endedAt)) return { state: "retained", reason: `${proofReason}; workflow end timestamp is missing or invalid` };
|
|
296
|
+
const workflowEndedAgeMs = (options.now?.() ?? Date.now()) - status.endedAt;
|
|
297
|
+
if (workflowEndedAgeMs <= thresholdMs) return { state: "retained", reason: `${proofReason}; workflow ended ${workflowEndedAgeMs}ms ago, within abandoned-timeout ${thresholdMs}ms` };
|
|
298
|
+
const abandonedChildren: AbandonedWorkflowEvidence["abandonedChildren"] = [];
|
|
299
|
+
for (const step of status.steps) {
|
|
300
|
+
const child = readWorkflowChildEvidence(owner.asyncDir, step);
|
|
301
|
+
if (!child || child.state === "resolved") continue;
|
|
302
|
+
const unresolved = child.unresolvedProof;
|
|
303
|
+
if (!unresolved) return { state: "retained", reason: child.reason };
|
|
304
|
+
if (unresolved.status.sessionId !== owner.ownerSessionId) return { state: "retained", reason: `${child.reason}; child session ${unresolved.status.sessionId ?? "unknown"} does not match owner session ${owner.ownerSessionId}` };
|
|
305
|
+
const verdict = abandonedRunnerReleaseVerdict(unresolved.status, unresolved.proofState, options);
|
|
306
|
+
if (verdict.state !== "releasable") return { state: "retained", reason: `async workflow child ${unresolved.status.runId}: ${verdict.reason}` };
|
|
307
|
+
abandonedChildren.push({ runId: unresolved.status.runId, lastActivityAgeMs: verdict.evidence.lastActivityAgeMs });
|
|
308
|
+
}
|
|
309
|
+
const evidence: AbandonedWorkflowEvidence = {
|
|
310
|
+
releasedBy: "abandoned-timeout",
|
|
311
|
+
processProof: "unknown",
|
|
312
|
+
controller: "unregistered",
|
|
313
|
+
workflowEndedAgeMs,
|
|
314
|
+
abandonedChildren,
|
|
315
|
+
abandonedSlotReleaseAfterMs: thresholdMs,
|
|
316
|
+
};
|
|
317
|
+
return {
|
|
318
|
+
state: "releasable",
|
|
319
|
+
reason: `${evidence.releasedBy}: ${proofReason}; workflow controller is unregistered; failed async children ${abandonedChildren.map((child) => child.runId).join(", ")} have dead runner PIDs; process proof unknown; workflow ended ${workflowEndedAgeMs}ms ago, over ${thresholdMs}ms`,
|
|
320
|
+
evidence,
|
|
321
|
+
};
|
|
272
322
|
}
|
|
273
323
|
|
|
274
324
|
function ownerReleaseVerdict(owner: ActiveAsyncCapacityOwner, liveWorkflowRunIds: ReadonlySet<string>, options: CapacityOptions): ActiveAsyncCapacityReleaseVerdict {
|
|
275
325
|
const status = readStatus(owner.asyncDir);
|
|
276
326
|
return owner.kind === "runner"
|
|
277
327
|
? runnerReleaseVerdict(owner, status, options)
|
|
278
|
-
: workflowReleaseVerdict(owner, status, liveWorkflowRunIds);
|
|
328
|
+
: workflowReleaseVerdict(owner, status, liveWorkflowRunIds, options);
|
|
279
329
|
}
|
|
280
330
|
|
|
281
331
|
function capacitySessionDirs(rootDir: string, sessionId?: string): string[] {
|