@xzzpig/pi-subagents 0.15.1 → 0.18.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 +178 -1
- package/README.md +5 -3
- package/agents/claude-code-writer.md +1 -0
- package/agents/codex-exec-writer.md +1 -0
- package/agents/cursor-agent-writer.md +1 -0
- package/agents/reviewer.md +3 -2
- package/agents/worker.md +3 -2
- package/docs/agents.md +19 -12
- package/docs/configuration.md +21 -3
- package/docs/extension-api.md +70 -4
- package/docs/fork-extensions.md +23 -15
- package/docs/models.md +5 -3
- package/docs/observability.md +23 -13
- package/docs/standalone-background.md +4 -4
- package/docs/tool-reference.md +40 -19
- package/docs/watchdog.md +2 -0
- package/docs/workflows.md +57 -3
- package/inspector-runner.mjs +1 -1
- package/package.json +14 -8
- package/prompts/council.md +6 -3
- package/runner-peer-loader.mjs +4 -7
- package/runner-peer-preload.mjs +5 -7
- package/skills/pi-subagents/SKILL.md +1 -0
- package/skills/pi-subagents/references/constraints-and-recipes.md +5 -2
- package/skills/pi-subagents/references/execution-controls.md +6 -4
- package/skills/pi-subagents/references/management-authoring-rpc.md +3 -3
- package/skills/pi-subagents/references/multi-lane-orchestration.md +8 -0
- package/skills/pi-subagents/references/prompting-and-roles.md +16 -15
- package/src/agents/agent-eject.ts +3 -3
- package/src/agents/agent-management.ts +61 -52
- package/src/agents/agent-memory.ts +90 -3
- package/src/agents/agent-serializer.ts +4 -4
- package/src/agents/agents.ts +125 -51
- package/src/agents/global-npm-root.ts +58 -0
- package/src/agents/proactive-skills.ts +4 -1
- package/src/agents/runtime-agent-registry.ts +14 -11
- package/src/agents/skills.ts +42 -9
- package/src/api/delegation.ts +15 -0
- package/src/api/inspectors.ts +27 -0
- package/src/api/preflight.ts +60 -60
- package/src/extension/doctor.ts +9 -4
- package/src/extension/fanout-child.ts +8 -0
- package/src/extension/index.ts +101 -48
- package/src/extension/rpc.ts +10 -1
- package/src/extension/schemas.ts +12 -6
- package/src/extension/subagent-guide.ts +12 -4
- package/src/extension/tool-activation.ts +197 -0
- package/src/extension/tool-description.ts +1 -1
- package/src/inspectors/ghostty/plugin.ts +13 -1
- package/src/inspectors/plugins.ts +70 -3
- package/src/intercom/intercom-bridge.ts +2 -0
- package/src/intercom/native-supervisor-channel.ts +22 -15
- package/src/intercom/result-intercom.ts +4 -0
- package/src/runs/background/active-async-capacity.ts +3 -25
- package/src/runs/background/async-execution.ts +100 -140
- package/src/runs/background/async-job-tracker.ts +28 -34
- package/src/runs/background/async-resume.ts +16 -8
- package/src/runs/background/async-status.ts +2 -0
- package/src/runs/background/binary-bootstrap.ts +34 -6
- package/src/runs/background/fleet-view.ts +51 -7
- package/src/runs/background/notify.ts +93 -7
- package/src/runs/background/pid-namespace.ts +18 -0
- package/src/runs/background/process-terminal-candidate.ts +98 -0
- package/src/runs/background/process-terminal.ts +17 -96
- package/src/runs/background/result-watcher.ts +1 -1
- package/src/runs/background/retained-children.ts +3 -2
- package/src/runs/background/run-child-session.ts +16 -5
- package/src/runs/background/run-id-resolver.ts +10 -5
- package/src/runs/background/run-status.ts +10 -4
- package/src/runs/background/runner-aliases.ts +25 -15
- package/src/runs/background/runner-child-launch.ts +1 -2
- package/src/runs/background/runner-startup-failure.ts +56 -0
- package/src/runs/background/stale-run-reconciler.ts +19 -3
- package/src/runs/background/subagent-runner-bootstrap.ts +276 -0
- package/src/runs/background/subagent-runner.ts +96 -287
- package/src/runs/background/wait-tool.ts +2 -0
- package/src/runs/background/workflow-terminal-proof.ts +68 -0
- package/src/runs/foreground/execution.ts +217 -250
- package/src/runs/foreground/prompt-audit.ts +3 -9
- package/src/runs/foreground/subagent-executor.ts +377 -119
- package/src/runs/shared/acceptance.ts +167 -68
- package/src/runs/shared/capability-ceiling.ts +4 -1
- package/src/runs/shared/child-hooks.ts +1 -16
- package/src/runs/shared/child-launch.ts +22 -14
- package/src/runs/shared/child-runtime-config.ts +3 -0
- package/src/runs/shared/child-session.ts +52 -2
- package/src/runs/shared/child-tool-plan.ts +23 -113
- package/src/runs/shared/dynamic-fanout.ts +1 -1
- package/src/runs/shared/external-cli-runner.ts +3 -1
- package/src/runs/shared/external-job-bridge.ts +54 -0
- package/src/runs/shared/git-environment.ts +29 -0
- package/src/runs/shared/mcp-config-sources.ts +3 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +1 -1
- package/src/runs/shared/mcp-direct-tool-grant.ts +22 -6
- package/src/runs/shared/model-resolution.ts +6 -1
- package/src/runs/shared/nested-events.ts +67 -55
- package/src/runs/shared/orca-progress-tabs.ts +3 -2
- package/src/runs/shared/parallel-utils.ts +2 -1
- package/src/runs/shared/pi-spawn.ts +92 -6
- package/src/runs/shared/profile-launch-env.ts +10 -2
- package/src/runs/shared/single-output.ts +11 -2
- package/src/runs/shared/structured-output.ts +227 -7
- package/src/runs/shared/subagent-control.ts +2 -16
- package/src/runs/shared/subagent-prompt-runtime.ts +27 -5
- package/src/runs/shared/tool-availability.ts +2 -2
- package/src/runs/shared/tool-budget.ts +21 -0
- package/src/runs/shared/usage-reconciliation.ts +73 -0
- package/src/runs/shared/worktree.ts +35 -8
- package/src/shared/child-session-name.ts +4 -2
- package/src/shared/fork-context.ts +11 -4
- package/src/shared/launch-contract.ts +1 -1
- package/src/shared/pruned-fork.ts +69 -56
- package/src/shared/types.ts +52 -16
- package/src/slash/delegation-adapters.ts +25 -1
- package/src/slash/prompt-template-bridge.ts +16 -1
- package/src/slash/prompt-workflows.ts +12 -1
- package/src/slash/slash-commands.ts +7 -241
- package/src/slash/subagent-cost.ts +313 -0
- package/src/slash/subagents-admin.ts +28 -29
- package/src/tui/fleet-status.ts +24 -2
- package/src/tui/fleet.ts +7 -4
- package/src/tui/render.ts +53 -19
- package/src/watchdog/diff-tool.ts +24 -3
- package/src/watchdog/permission-arbiter.ts +13 -15
- package/src/watchdog/register-child.ts +10 -2
- package/src/watchdog/review.ts +14 -14
- package/src/watchdog/runtime.ts +2 -1
- package/src/watchdog/turn-delta.ts +11 -5
- package/src/workflows/scripted-workflow.ts +109 -23
- package/src/workflows/workflow-child-summary.ts +4 -2
- package/src/workflows/workflow-settlement.ts +4 -1
- package/src/runs/shared/completion-evidence.ts +0 -89
- package/src/runs/shared/completion-guard.ts +0 -255
- package/src/runs/shared/llm-intent-arbiter.ts +0 -321
- package/src/runs/shared/task-intent.ts +0 -244
|
@@ -16,7 +16,7 @@ export const SUBAGENT_SAFETY_GUIDANCE = `SAFETY-CRITICAL SUBAGENT GUIDANCE:
|
|
|
16
16
|
• Async follows asyncByDefault (normally true); async:false only to block the parent, not for final reviews/gates. Consume results at dependency barriers. Native async completion wakes this session: return control, no sleep/poll or bg_wait merely for a wake. bg_wait is for provider/detached work without native notification needing a same-turn result.
|
|
17
17
|
• Ordinary child subagents are not orchestrators; only configured fanout within depth/session limits. For an authorized delegated workflow, keep one writer per cwd/worktree and isolate concurrent writers. Use fresh-context read-only reviewers when independent review was requested, then parent synthesis/fixes. Oracle/advisor unknowns use supervisor dialogue; one-shot only when requested.
|
|
18
18
|
• Bind durable output on runs.run/runs.all, not task filename prose; return actual outputReference/outputPathMapping/artifactPaths, evidence and residual risks.
|
|
19
|
-
• children.list: resume only resumable rows. {action:"resume",id,message} detaches a follow-up/challenge with stored agent/model/tool contract.
|
|
19
|
+
• children.list is workflow-only, not an exhaustive list of direct native children: resume only resumable rows. When an intended child's exact run id is known, inspect it with {action:"status",id}; if status identifies the candidate, attempt {action:"resume",id,message}. Resume authoritatively checks eligibility, may reject it, and otherwise detaches a follow-up/challenge with the stored agent/model/tool contract. Use a labeled same-role fallback only when no known candidate exists or resume rejects eligibility. Scripts await runs.run(newKey,{resume:runId,task}); continue from latest returned runId. Each distinct resume pass needs a new stable key; same-key reuse requires identical launch parameters.
|
|
20
20
|
• Named resources own authority; raw workflowScript/workflowScriptPath cannot use runs.host. Granted commands/relative outputs use workflow cwd, never per-step cwd.
|
|
21
21
|
• Inspect asyncId/asyncDir (status.json, events.jsonl, logs) with status/debug.run; control with interrupt/stop/resume/steer. Read {action:"guide",topic:"tool-reference"} for controls/evidence gates.`;
|
|
22
22
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { openGhosttyInspector, type GhosttyRunner } from "./actions.ts";
|
|
2
2
|
import type { InspectorPlugin } from "../types.ts";
|
|
3
3
|
|
|
4
|
+
/** 独立 Ghostty.app 的 bundle id (作者 Mitchell Hashimoto)。 */
|
|
5
|
+
const GHOSTTY_BUNDLE_ID = "com.mitchellh.ghostty";
|
|
6
|
+
|
|
4
7
|
export interface GhosttyPluginDeps {
|
|
5
8
|
platform?: NodeJS.Platform;
|
|
6
9
|
runner?: GhosttyRunner;
|
|
@@ -10,7 +13,16 @@ export function createGhosttyInspectorPlugin(deps: GhosttyPluginDeps = {}): Insp
|
|
|
10
13
|
const platform = deps.platform ?? process.platform;
|
|
11
14
|
return {
|
|
12
15
|
name: "ghostty",
|
|
13
|
-
available: (context) =>
|
|
16
|
+
available: (context) => {
|
|
17
|
+
// cmux 内嵌 Ghostty 内核, 也会把 TERM_PROGRAM 设成 "ghostty"。仅凭环境变量会让 plugin
|
|
18
|
+
// 在 cmux 下误接管, 随后 osascript 连不上真正的 Ghostty 应用而抛 -1728/-2741。
|
|
19
|
+
if (platform !== "darwin") return false;
|
|
20
|
+
if (context.env.TERM_PROGRAM?.toLowerCase() !== "ghostty") return false;
|
|
21
|
+
// macOS GUI 应用启动子进程时注入 __CFBundleIdentifier, 标识当前终端宿主 app。
|
|
22
|
+
// cmux 的 bundle id 是 com.cmuxterm.app, 而非 Ghostty; 即便系统同时装了独立 Ghostty,
|
|
23
|
+
// 也能据此判定当前终端不是 Ghostty, 避免误连独立 Ghostty 的窗口。
|
|
24
|
+
return context.env.__CFBundleIdentifier?.trim() === GHOSTTY_BUNDLE_ID;
|
|
25
|
+
},
|
|
14
26
|
owns: () => false,
|
|
15
27
|
open: (context, launch, params) => openGhosttyInspector(context, launch, params, deps.runner),
|
|
16
28
|
};
|
|
@@ -1,8 +1,75 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { INSPECTOR_REGISTER_EVENT, type InspectorRegistrationRequest } from "../api/inspectors.ts";
|
|
1
3
|
import { createHerdrInspectorPlugin } from "./herdr/plugin.ts";
|
|
2
4
|
import { createGhosttyInspectorPlugin } from "./ghostty/plugin.ts";
|
|
3
5
|
import type { InspectorPlugin } from "./types.ts";
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
type InspectorOwner = Pick<ExtensionAPI, "events">;
|
|
8
|
+
// Keyed by event bus: a runtime that claims a registration can be replaced by a duplicate
|
|
9
|
+
// pi-subagents runtime on the same bus, and the registration must survive that takeover.
|
|
10
|
+
const registries = new WeakMap<InspectorOwner["events"], { plugins: Map<string, InspectorPlugin>; owners: number }>();
|
|
11
|
+
|
|
12
|
+
/** Built-ins retain host preference; external providers follow registration order. */
|
|
13
|
+
export function getInspectorPlugins(pi: InspectorOwner): readonly InspectorPlugin[] {
|
|
14
|
+
return [createHerdrInspectorPlugin(), createGhosttyInspectorPlugin(), ...(registries.get(pi.events)?.plugins.values() ?? [])];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Registrations live while any owner runtime listens on this bus; child runtimes use their own bus. */
|
|
18
|
+
export function registerInspectorEventListener(pi: InspectorOwner): () => void {
|
|
19
|
+
let registry = registries.get(pi.events);
|
|
20
|
+
if (!registry) {
|
|
21
|
+
registry = { plugins: new Map(), owners: 0 };
|
|
22
|
+
registries.set(pi.events, registry);
|
|
23
|
+
}
|
|
24
|
+
registry.owners += 1;
|
|
25
|
+
const { plugins } = registry;
|
|
26
|
+
const builtinNames = new Set([createHerdrInspectorPlugin().name, createGhosttyInspectorPlugin().name]);
|
|
27
|
+
/* oxlint-disable anti-slop/no-runtime-typeof -- This listener validates the untyped event-bus boundary, including callable provider methods. */
|
|
28
|
+
const unsubscribe = pi.events.on(INSPECTOR_REGISTER_EVENT, (rawRequest) => {
|
|
29
|
+
if (!rawRequest || typeof rawRequest !== "object" || Array.isArray(rawRequest)) return;
|
|
30
|
+
// SAFETY: The envelope is an object; its version and plugin are validated below before storing callbacks.
|
|
31
|
+
const request = rawRequest as Partial<InspectorRegistrationRequest>;
|
|
32
|
+
if (request.result !== undefined) return;
|
|
33
|
+
try {
|
|
34
|
+
if (request.version !== 1) throw new Error(`Unsupported inspector registration version '${String(request.version)}'.`);
|
|
35
|
+
const plugin = request.plugin;
|
|
36
|
+
if (!plugin || typeof plugin !== "object" || Array.isArray(plugin)) throw new Error("Inspector plugin must be an object.");
|
|
37
|
+
const name = plugin.name;
|
|
38
|
+
if (typeof name !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(name)) {
|
|
39
|
+
throw new Error("Inspector plugin name must contain 1–128 letters, digits, dots, underscores, or hyphens and start with a letter or digit.");
|
|
40
|
+
}
|
|
41
|
+
if (builtinNames.has(name) || plugins.has(name)) throw new Error(`Inspector plugin '${name}' is already registered.`);
|
|
42
|
+
for (const method of ["available", "owns", "open"] as const) {
|
|
43
|
+
if (typeof plugin[method] !== "function") throw new Error(`Inspector plugin '${name}' requires ${method}().`);
|
|
44
|
+
}
|
|
45
|
+
for (const method of ["status", "close"] as const) {
|
|
46
|
+
if (plugin[method] !== undefined && typeof plugin[method] !== "function") throw new Error(`Inspector plugin '${name}' ${method} must be a function when provided.`);
|
|
47
|
+
}
|
|
48
|
+
plugins.set(name, plugin);
|
|
49
|
+
let disposed = false;
|
|
50
|
+
request.result = {
|
|
51
|
+
ok: true,
|
|
52
|
+
registration: {
|
|
53
|
+
dispose() {
|
|
54
|
+
if (disposed) return;
|
|
55
|
+
disposed = true;
|
|
56
|
+
plugins.delete(name);
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
} catch (error) {
|
|
61
|
+
request.result = { ok: false, error: error instanceof Error ? error : new Error(String(error)) };
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
/* oxlint-enable anti-slop/no-runtime-typeof */
|
|
65
|
+
let closed = false;
|
|
66
|
+
return () => {
|
|
67
|
+
if (closed) return;
|
|
68
|
+
closed = true;
|
|
69
|
+
unsubscribe();
|
|
70
|
+
registry.owners -= 1;
|
|
71
|
+
if (registry.owners > 0) return;
|
|
72
|
+
plugins.clear();
|
|
73
|
+
if (registries.get(pi.events) === registry) registries.delete(pi.events);
|
|
74
|
+
};
|
|
8
75
|
}
|
|
@@ -90,6 +90,8 @@ interface ResolveIntercomBridgeInput {
|
|
|
90
90
|
agentDir?: string;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
// Inside a child, callers pass the child's intercom route instead of its session
|
|
94
|
+
// name: the name is a readable label and need not be unique.
|
|
93
95
|
export function resolveIntercomSessionTarget(sessionName: string | undefined, sessionId: string, intercomSessionId = process.env[PI_INTERCOM_SESSION_ID_ENV]): string {
|
|
94
96
|
const trimmedName = sessionName?.trim();
|
|
95
97
|
if (trimmedName) return trimmedName;
|
|
@@ -288,13 +288,18 @@ function parseRequestFile(file: string, channelDir: string): PendingSupervisorRe
|
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
function
|
|
291
|
+
function isMissingSupervisorDirectory(error: unknown, platform: NodeJS.Platform): boolean {
|
|
292
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
293
|
+
return code === "ENOENT" || (platform === "win32" && code === "UNKNOWN");
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function listRequestFiles(channelDirs: string[] | undefined, platform: NodeJS.Platform): Array<{ channelDir: string; file: string }> {
|
|
292
297
|
if (!channelDirs) {
|
|
293
298
|
try {
|
|
294
299
|
channelDirs = fs.readdirSync(SUPERVISOR_CHANNEL_ROOT, { withFileTypes: true })
|
|
295
300
|
.filter(entry => entry.isDirectory()).map(entry => path.join(SUPERVISOR_CHANNEL_ROOT, entry.name));
|
|
296
301
|
} catch (error) {
|
|
297
|
-
if ((error
|
|
302
|
+
if (isMissingSupervisorDirectory(error, platform)) return [];
|
|
298
303
|
throw error;
|
|
299
304
|
}
|
|
300
305
|
}
|
|
@@ -314,11 +319,11 @@ function listRequestFiles(channelDirs?: string[]): Array<{ channelDir: string; f
|
|
|
314
319
|
return files;
|
|
315
320
|
}
|
|
316
321
|
|
|
317
|
-
function readDirectoryEntries(dir: string): fs.Dirent[] | undefined {
|
|
322
|
+
function readDirectoryEntries(dir: string, platform: NodeJS.Platform): fs.Dirent[] | undefined {
|
|
318
323
|
try {
|
|
319
324
|
return fs.readdirSync(dir, { withFileTypes: true });
|
|
320
325
|
} catch (error) {
|
|
321
|
-
if ((error
|
|
326
|
+
if (isMissingSupervisorDirectory(error, platform)) return [];
|
|
322
327
|
return undefined;
|
|
323
328
|
}
|
|
324
329
|
}
|
|
@@ -343,7 +348,7 @@ function removeEmptyDirectory(dir: string): boolean {
|
|
|
343
348
|
}
|
|
344
349
|
}
|
|
345
350
|
|
|
346
|
-
function removeStaleEmptySupervisorChannel(channelDir: string, nowMs: number): boolean {
|
|
351
|
+
function removeStaleEmptySupervisorChannel(channelDir: string, nowMs: number, platform: NodeJS.Platform): boolean {
|
|
347
352
|
const requestsDir = path.join(channelDir, REQUESTS_DIR);
|
|
348
353
|
const repliesDir = path.join(channelDir, REPLIES_DIR);
|
|
349
354
|
const newestKnownMtimeMs = Math.max(
|
|
@@ -353,9 +358,9 @@ function removeStaleEmptySupervisorChannel(channelDir: string, nowMs: number): b
|
|
|
353
358
|
);
|
|
354
359
|
if (nowMs - newestKnownMtimeMs < STALE_EMPTY_CHANNEL_AGE_MS) return false;
|
|
355
360
|
|
|
356
|
-
const requestEntries = readDirectoryEntries(requestsDir);
|
|
361
|
+
const requestEntries = readDirectoryEntries(requestsDir, platform);
|
|
357
362
|
if (!requestEntries || requestEntries.length > 0) return false;
|
|
358
|
-
const replyEntries = readDirectoryEntries(repliesDir);
|
|
363
|
+
const replyEntries = readDirectoryEntries(repliesDir, platform);
|
|
359
364
|
if (!replyEntries || replyEntries.length > 0) return false;
|
|
360
365
|
|
|
361
366
|
if (!removeEmptyDirectory(requestsDir)) return false;
|
|
@@ -364,12 +369,12 @@ function removeStaleEmptySupervisorChannel(channelDir: string, nowMs: number): b
|
|
|
364
369
|
return true;
|
|
365
370
|
}
|
|
366
371
|
|
|
367
|
-
function cleanupStaleEmptySupervisorChannels(nowMs = Date.now()): number {
|
|
372
|
+
function cleanupStaleEmptySupervisorChannels(nowMs = Date.now(), platform: NodeJS.Platform = process.platform): number {
|
|
368
373
|
let channelEntries: fs.Dirent[];
|
|
369
374
|
try {
|
|
370
375
|
channelEntries = fs.readdirSync(SUPERVISOR_CHANNEL_ROOT, { withFileTypes: true });
|
|
371
376
|
} catch (error) {
|
|
372
|
-
if ((error
|
|
377
|
+
if (isMissingSupervisorDirectory(error, platform)) return 0;
|
|
373
378
|
throw error;
|
|
374
379
|
}
|
|
375
380
|
|
|
@@ -377,7 +382,7 @@ function cleanupStaleEmptySupervisorChannels(nowMs = Date.now()): number {
|
|
|
377
382
|
for (const entry of channelEntries) {
|
|
378
383
|
if (!entry.isDirectory()) continue;
|
|
379
384
|
try {
|
|
380
|
-
if (removeStaleEmptySupervisorChannel(path.join(SUPERVISOR_CHANNEL_ROOT, entry.name), nowMs)) removed++;
|
|
385
|
+
if (removeStaleEmptySupervisorChannel(path.join(SUPERVISOR_CHANNEL_ROOT, entry.name), nowMs, platform)) removed++;
|
|
381
386
|
} catch {
|
|
382
387
|
// Cleanup is opportunistic; active writers can race with us and will be picked up by a later pass.
|
|
383
388
|
}
|
|
@@ -482,7 +487,9 @@ function refreshPendingRequests(pending: Map<string, PendingSupervisorRequest>,
|
|
|
482
487
|
|
|
483
488
|
function formatPendingLine(request: PendingSupervisorRequest): string {
|
|
484
489
|
const replyHint = request.expectsReply ? ` Reply: ${supervisorReplyHint(request.id)}` : "";
|
|
485
|
-
|
|
490
|
+
const header = `- ${request.id}: ${request.agent} [${request.runId}#${request.childIndex}] ${request.reason}.${replyHint}`;
|
|
491
|
+
// The request notice can be missed; pending is the parent's only way to read the question again.
|
|
492
|
+
return request.message ? `${header}\n ${request.message.replace(/\n/g, "\n ")}` : header;
|
|
486
493
|
}
|
|
487
494
|
|
|
488
495
|
function requestVisibleText(request: PendingSupervisorRequest): string {
|
|
@@ -709,7 +716,7 @@ export function createNativeSupervisorChannel(pi: ExtensionAPI, state: SubagentS
|
|
|
709
716
|
if (nowMs - lastStaleCleanupAt < STALE_EMPTY_CHANNEL_CLEANUP_INTERVAL_MS) return;
|
|
710
717
|
lastStaleCleanupAt = nowMs;
|
|
711
718
|
try {
|
|
712
|
-
cleanupStaleEmptySupervisorChannels(nowMs);
|
|
719
|
+
cleanupStaleEmptySupervisorChannels(nowMs, platform);
|
|
713
720
|
} catch {
|
|
714
721
|
// Supervisor delivery must not fail because best-effort temp cleanup failed.
|
|
715
722
|
}
|
|
@@ -721,7 +728,7 @@ export function createNativeSupervisorChannel(pi: ExtensionAPI, state: SubagentS
|
|
|
721
728
|
refreshPendingRequests(pending, state, observeRequestLifecycle, runState);
|
|
722
729
|
const now = Date.now();
|
|
723
730
|
const channels = deps.getChannelDirs?.();
|
|
724
|
-
for (const { channelDir, file } of listRequestFiles(channels?.dirs)) {
|
|
731
|
+
for (const { channelDir, file } of listRequestFiles(channels?.dirs, platform)) {
|
|
725
732
|
if (seenFiles.has(file)) continue;
|
|
726
733
|
const request = parseRequestFile(file, channelDir);
|
|
727
734
|
if (!request || !requestMatchesOwner(request, state)) continue;
|
|
@@ -816,7 +823,7 @@ export function createNativeSupervisorChannel(pi: ExtensionAPI, state: SubagentS
|
|
|
816
823
|
try {
|
|
817
824
|
channelEntries = fs.readdirSync(SUPERVISOR_CHANNEL_ROOT, { withFileTypes: true });
|
|
818
825
|
} catch (error) {
|
|
819
|
-
if ((error
|
|
826
|
+
if (isMissingSupervisorDirectory(error, platform)) return;
|
|
820
827
|
startPolling();
|
|
821
828
|
return;
|
|
822
829
|
}
|
|
@@ -848,7 +855,7 @@ export function createNativeSupervisorChannel(pi: ExtensionAPI, state: SubagentS
|
|
|
848
855
|
let files: string[];
|
|
849
856
|
try { files = fs.readdirSync(path.join(channelDir, REQUESTS_DIR)); }
|
|
850
857
|
catch (error) {
|
|
851
|
-
if ((error
|
|
858
|
+
if (isMissingSupervisorDirectory(error, platform)) return [];
|
|
852
859
|
throw error;
|
|
853
860
|
}
|
|
854
861
|
const now = Date.now();
|
|
@@ -31,6 +31,7 @@ export function resolveSubagentResultStatus(input: {
|
|
|
31
31
|
if (input.detached) return "detached";
|
|
32
32
|
if (input.stopped || input.state === "stopped") return "stopped";
|
|
33
33
|
if (input.interrupted || input.state === "paused") return "paused";
|
|
34
|
+
if (input.state === "running" || input.state === "queued") return "running";
|
|
34
35
|
if (input.success === true) return "completed";
|
|
35
36
|
if (isUnexplainedProcessSignal(input) && input.exitCode !== 0) return "stopped";
|
|
36
37
|
if (input.success === false) return "failed";
|
|
@@ -42,6 +43,7 @@ export function resolveSubagentResultStatus(input: {
|
|
|
42
43
|
|
|
43
44
|
function countStatuses(children: SubagentResultIntercomChild[]): Record<SubagentResultStatus, number> {
|
|
44
45
|
const counts: Record<SubagentResultStatus, number> = {
|
|
46
|
+
running: 0,
|
|
45
47
|
completed: 0,
|
|
46
48
|
failed: 0,
|
|
47
49
|
paused: 0,
|
|
@@ -56,6 +58,7 @@ function countStatuses(children: SubagentResultIntercomChild[]): Record<Subagent
|
|
|
56
58
|
|
|
57
59
|
function formatStatusCounts(counts: Record<SubagentResultStatus, number>): string {
|
|
58
60
|
const parts = [
|
|
61
|
+
counts.running ? `${counts.running} running` : undefined,
|
|
59
62
|
counts.completed ? `${counts.completed} completed` : undefined,
|
|
60
63
|
counts.failed ? `${counts.failed} failed` : undefined,
|
|
61
64
|
counts.stopped ? `${counts.stopped} stopped` : undefined,
|
|
@@ -85,6 +88,7 @@ function resolveGroupedStatus(children: SubagentResultIntercomChild[]): Subagent
|
|
|
85
88
|
if (counts.failed > 0) return "failed";
|
|
86
89
|
if (counts.stopped > 0) return "stopped";
|
|
87
90
|
if (counts.paused > 0) return "paused";
|
|
91
|
+
if (counts.running > 0) return "running";
|
|
88
92
|
if (counts.completed > 0) return "completed";
|
|
89
93
|
if (counts.detached > 0) return "detached";
|
|
90
94
|
return "failed";
|
|
@@ -6,6 +6,7 @@ import { TEMP_ROOT_DIR, type ActiveAsyncCapacitySnapshot, type AsyncStatus } fro
|
|
|
6
6
|
import { readStatus } from "../../shared/utils.ts";
|
|
7
7
|
import { checkPidLiveness, type PidLiveness } from "./stale-run-reconciler.ts";
|
|
8
8
|
import { readProcessTerminal } from "./process-terminal.ts";
|
|
9
|
+
import { isTerminalAsyncState as terminalState, readWorkflowChildProcessEvidence } from "./workflow-terminal-proof.ts";
|
|
9
10
|
|
|
10
11
|
export const ACTIVE_ASYNC_CAPACITY_DIR = path.join(TEMP_ROOT_DIR, "session-active-async-capacity");
|
|
11
12
|
export const DEFAULT_ABANDONED_SLOT_RELEASE_AFTER_MS = 20 * 60 * 1000;
|
|
@@ -209,10 +210,6 @@ function appendAbandonedReleaseEvent(asyncDir: string, owner: ActiveAsyncCapacit
|
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
212
|
|
|
212
|
-
function terminalState(state: AsyncStatus["state"]): boolean {
|
|
213
|
-
return state !== "queued" && state !== "running" && state !== "paused";
|
|
214
|
-
}
|
|
215
|
-
|
|
216
213
|
function runnerReleaseVerdict(owner: ActiveAsyncCapacityOwner, status: AsyncStatus | null, options: CapacityOptions): ActiveAsyncCapacityReleaseVerdict {
|
|
217
214
|
if (!status) return { state: "retained", reason: "status file is missing or unreadable" };
|
|
218
215
|
if (!owner.runnerProcessInstanceId) return { state: "retained", reason: "runner process identity has not been recorded" };
|
|
@@ -269,27 +266,8 @@ function workflowReleaseVerdict(owner: ActiveAsyncCapacityOwner, status: AsyncSt
|
|
|
269
266
|
if (status.mode !== "workflow") return { state: "retained", reason: `status mode is ${status.mode}, not workflow` };
|
|
270
267
|
if (!terminalState(status.state)) return { state: "retained", reason: `workflow is still ${status.state}` };
|
|
271
268
|
if (liveWorkflowRunIds.has(owner.runId)) return { state: "retained", reason: "workflow controller is still live" };
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (typeof step.async !== "boolean") return { state: "retained", reason: `workflow child ${label} is missing async classification` };
|
|
275
|
-
if (!step.async) continue;
|
|
276
|
-
if (!step.runId) return { state: "retained", reason: `async workflow child ${label} is missing run id` };
|
|
277
|
-
const childDir = path.join(path.dirname(owner.asyncDir), step.runId);
|
|
278
|
-
if (!fs.existsSync(childDir)) return { state: "retained", reason: `async workflow child ${label} directory is missing` };
|
|
279
|
-
const childStatus = readStatus(childDir);
|
|
280
|
-
if (!childStatus) return { state: "retained", reason: `async workflow child ${label} status is missing or unreadable` };
|
|
281
|
-
if (!terminalState(childStatus.state)) return { state: "retained", reason: `async workflow child ${label} is still ${childStatus.state}` };
|
|
282
|
-
if (!childStatus.processTerminal?.runnerProcessInstanceId) return { state: "retained", reason: `async workflow child ${label} has no runner process identity` };
|
|
283
|
-
if (childStatus.processTerminal.state === "not-started"
|
|
284
|
-
&& childStatus.processTerminal.runId === step.runId
|
|
285
|
-
&& typeof childStatus.error === "string"
|
|
286
|
-
&& childStatus.error) continue;
|
|
287
|
-
const proof = readProcessTerminal(childDir, {
|
|
288
|
-
runId: step.runId,
|
|
289
|
-
runnerProcessInstanceId: childStatus.processTerminal.runnerProcessInstanceId,
|
|
290
|
-
});
|
|
291
|
-
if (proof?.state !== "observed" || proof.runId !== step.runId) return { state: "retained", reason: `async workflow child ${label} process-terminal proof is ${proof?.state ?? "missing"}` };
|
|
292
|
-
}
|
|
269
|
+
const evidence = readWorkflowChildProcessEvidence(owner.asyncDir, status.steps);
|
|
270
|
+
if (evidence.state !== "observed") return { state: "retained", reason: evidence.reason };
|
|
293
271
|
return { state: "releasable", reason: "workflow is terminal, controller is gone, and async children have observed proof" };
|
|
294
272
|
}
|
|
295
273
|
|