pi-subagents 0.85.0 → 0.87.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 +48 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-O7CPL6H4.js → chunk-2D2DQGC2.js} +9 -9
- package/bundle/{chunk-KZ34KQQH.js → chunk-2NY5PCKQ.js} +11 -5
- package/bundle/{chunk-PVIVCDG2.js → chunk-3CVOAS77.js} +2 -2
- package/bundle/{chunk-N7B2KD74.js → chunk-6O7YH2QV.js} +1 -1
- package/bundle/{chunk-IQIWF2VX.js → chunk-AIL46SZU.js} +8 -6
- package/bundle/{chunk-H2NLFTC5.js → chunk-BFF6YDK6.js} +1 -1
- package/bundle/{chunk-UX4SCV5N.js → chunk-C3KWLXDH.js} +159 -98
- package/bundle/{chunk-GCSLVFCX.js → chunk-C5QWQSSM.js} +1 -1
- package/bundle/{chunk-3UZ5FVVJ.js → chunk-DGTZKYIE.js} +39 -34
- package/bundle/{chunk-KDMFBYFM.js → chunk-ESWW6XSX.js} +1 -1
- package/bundle/{chunk-WOVMHDES.js → chunk-EYGBK6CE.js} +194 -94
- package/bundle/{chunk-CS4O36CZ.js → chunk-HDICKROY.js} +5 -5
- package/bundle/{chunk-DV2NCNPR.js → chunk-JLDQ6YUR.js} +12 -12
- package/bundle/{chunk-RQAUNAWG.js → chunk-LFKMM3UH.js} +2 -2
- package/bundle/{chunk-L2ENOFVZ.js → chunk-LZKVUWIY.js} +66 -26
- package/bundle/{chunk-RV5OGHLO.js → chunk-M2VBGET6.js} +2 -2
- package/bundle/{chunk-HFTBF7SG.js → chunk-OOE3R7IQ.js} +1 -1
- package/bundle/{chunk-JNXT3MPI.js → chunk-OTLDAYEQ.js} +5 -5
- package/bundle/{chunk-JWYG26RE.js → chunk-OZCPYJEY.js} +80 -37
- package/bundle/{chunk-LGMILZNE.js → chunk-PGU4TZV3.js} +79 -32
- package/bundle/{chunk-KEY3UQMQ.js → chunk-SIAQXPJ4.js} +6 -8
- package/bundle/{chunk-QO75KJBT.js → chunk-USRX7QXD.js} +2 -2
- package/bundle/{chunk-7MAE3DJV.js → chunk-VFUFOZBU.js} +1 -1
- package/bundle/{chunk-NF7IEKBH.js → chunk-W2BZS6UC.js} +27 -13
- package/bundle/{chunk-T5V5BRCL.js → chunk-W52LJANO.js} +1 -1
- package/bundle/{chunk-PHZP3KHB.js → chunk-XSDYTXHF.js} +18 -11
- package/bundle/{chunk-LTPH2DXH.js → chunk-XV7RTWTS.js} +3 -3
- package/bundle/{chunk-JO67XSKD.js → chunk-YEXKJJVS.js} +12 -7
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +12 -10
- package/bundle/project-panes.js +3 -3
- package/bundle/workflow-resources.js +1 -1
- package/docs/agents.md +9 -3
- package/docs/configuration.md +14 -6
- package/docs/extension-api.md +2 -0
- package/docs/models.md +6 -2
- package/docs/tool-reference.md +3 -0
- package/package.json +1 -1
- package/skills/pi-subagents/SKILL.md +7 -4
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.js +10 -6
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.js +37 -12
- package/src/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/index.js +4 -2
- package/src/extension/schemas.d.ts +2 -0
- package/src/extension/schemas.js +1 -0
- package/src/extension/tool-activation.js +10 -1
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +8 -8
- package/src/runs/background/async-execution.d.ts +2 -1
- package/src/runs/background/async-execution.js +4 -2
- package/src/runs/background/run-status.js +5 -4
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/subagent-runner.js +6 -6
- package/src/runs/background/wait-subscriptions.js +124 -12
- package/src/runs/foreground/async-stop-action.d.ts +1 -1
- package/src/runs/foreground/async-stop-action.js +9 -1
- package/src/runs/foreground/execution.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +1 -0
- package/src/runs/foreground/subagent-executor.js +51 -8
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/child-session.d.ts +5 -4
- package/src/runs/shared/child-session.js +43 -33
- package/src/runs/shared/external-cli-contract.d.ts +49 -0
- package/src/runs/shared/external-cli-contract.js +18 -13
- package/src/runs/shared/herdr-placed-run.js +3 -2
- package/src/runs/shared/mcp-config-sources.d.ts +2 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.js +5 -6
- package/src/runs/shared/model-resolution.d.ts +19 -4
- package/src/runs/shared/model-resolution.js +50 -51
- package/src/runs/shared/structured-output.js +10 -3
- package/src/shared/artifacts.js +25 -13
- package/src/shared/pruned-fork.js +2 -2
- package/src/shared/types.d.ts +71 -48
- package/src/tui/render.js +83 -22
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/review.js +2 -2
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +103 -39
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +1 -1
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +3 -1
|
@@ -11,10 +11,10 @@ import {
|
|
|
11
11
|
startWatchdogDiffBaselineCapture,
|
|
12
12
|
writeUserWatchdogEnabled,
|
|
13
13
|
writeWatchdogModelSettings
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-AIL46SZU.js";
|
|
15
15
|
import {
|
|
16
16
|
resolveGitRepositoryIdentity
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-2NY5PCKQ.js";
|
|
18
18
|
import {
|
|
19
19
|
listAsyncRuns,
|
|
20
20
|
parallelHandoffPath,
|
|
@@ -22,14 +22,14 @@ import {
|
|
|
22
22
|
readAsyncRecoveryDescriptor,
|
|
23
23
|
readWorkflowLaunchRecord,
|
|
24
24
|
resolveRetainedWorktreeCwd
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-XV7RTWTS.js";
|
|
26
26
|
import {
|
|
27
27
|
ownsRun
|
|
28
28
|
} from "./chunk-HXRB42AF.js";
|
|
29
29
|
import {
|
|
30
30
|
deepFreezeWorkflowArgs,
|
|
31
31
|
normalizeWorkflowArgs
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-W2BZS6UC.js";
|
|
33
33
|
import {
|
|
34
34
|
HOST_STEP_MAX_COUNT,
|
|
35
35
|
REQUIRE_LAUNCHER_SHAPE_ERROR,
|
|
@@ -54,21 +54,21 @@ import {
|
|
|
54
54
|
resolveMissionStoreLocation,
|
|
55
55
|
validateMissionId,
|
|
56
56
|
workflowRunParamsFingerprint
|
|
57
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-PGU4TZV3.js";
|
|
58
58
|
import {
|
|
59
59
|
requestAsyncCommand,
|
|
60
60
|
watchAsyncControlInbox
|
|
61
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-VFUFOZBU.js";
|
|
62
62
|
import {
|
|
63
63
|
supervisorChannelDir
|
|
64
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-SIAQXPJ4.js";
|
|
65
65
|
import {
|
|
66
66
|
createHerdrClient,
|
|
67
67
|
detectHerdr
|
|
68
|
-
} from "./chunk-
|
|
68
|
+
} from "./chunk-3CVOAS77.js";
|
|
69
69
|
import {
|
|
70
70
|
getProjectSubagentsDir
|
|
71
|
-
} from "./chunk-
|
|
71
|
+
} from "./chunk-XSDYTXHF.js";
|
|
72
72
|
import {
|
|
73
73
|
ExternalJobProviderError,
|
|
74
74
|
getExternalJobProvider,
|
|
@@ -78,9 +78,10 @@ import {
|
|
|
78
78
|
} from "./chunk-YYREO77V.js";
|
|
79
79
|
import {
|
|
80
80
|
mergeRuntimeAgents
|
|
81
|
-
} from "./chunk-
|
|
81
|
+
} from "./chunk-C5QWQSSM.js";
|
|
82
82
|
import {
|
|
83
83
|
CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL,
|
|
84
|
+
EXTERNAL_CLI_ADAPTER_SAFETY,
|
|
84
85
|
PI_CODING_AGENT_PACKAGE,
|
|
85
86
|
PI_CODING_AGENT_PACKAGE_ROOT_ENV,
|
|
86
87
|
PROMPT_REDACTED,
|
|
@@ -105,6 +106,7 @@ import {
|
|
|
105
106
|
getSupportedThinkingLevels,
|
|
106
107
|
isCodeOwnedExternalCliAdapterId,
|
|
107
108
|
isUnavailableSubagentModel,
|
|
109
|
+
knownModelProviders,
|
|
108
110
|
mergeAgentsForScope,
|
|
109
111
|
mergeBuiltinAgentOverride,
|
|
110
112
|
normalizeModelSegment,
|
|
@@ -135,7 +137,7 @@ import {
|
|
|
135
137
|
withFileLease,
|
|
136
138
|
writeAtomicJson,
|
|
137
139
|
writePrivateAtomicJson
|
|
138
|
-
} from "./chunk-
|
|
140
|
+
} from "./chunk-C3KWLXDH.js";
|
|
139
141
|
import {
|
|
140
142
|
DIRS,
|
|
141
143
|
INTERCOM_DETACH_REQUEST_EVENT,
|
|
@@ -2578,12 +2580,29 @@ function parseExternalCliMachine(value, label) {
|
|
|
2578
2580
|
const unknownRemoteGit = Object.keys(remoteGit).filter((field) => !["head", "branch", "dirty"].includes(field));
|
|
2579
2581
|
if (unknownRemoteGit.length > 0 || remoteGit.head !== void 0 && (typeof remoteGit.head !== "string" || !remoteGit.head.trim()) || remoteGit.branch !== void 0 && (typeof remoteGit.branch !== "string" || !remoteGit.branch.trim()) || remoteGit.dirty !== void 0 && typeof remoteGit.dirty !== "boolean") throw new Error(`${label}.machine.remoteGit is invalid.`);
|
|
2580
2582
|
}
|
|
2583
|
+
function parseCodeOwnedSafety(value, adapter, label) {
|
|
2584
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label}.safety is missing.`);
|
|
2585
|
+
const safety = value;
|
|
2586
|
+
const profile = EXTERNAL_CLI_ADAPTER_SAFETY[adapter];
|
|
2587
|
+
const unknownSafety = Object.keys(safety).filter((field) => !Object.hasOwn(profile, field));
|
|
2588
|
+
if (unknownSafety.length > 0) throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
|
|
2589
|
+
if (Object.entries(profile).some(([field, expected]) => safety[field] !== expected)) throw new Error(`${label}.safety is invalid.`);
|
|
2590
|
+
}
|
|
2591
|
+
function parseExternalCliSafetySource(value, label) {
|
|
2592
|
+
if (value === void 0) return false;
|
|
2593
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label}.safetySource must be an object.`);
|
|
2594
|
+
const source = value;
|
|
2595
|
+
const unknownSource = Object.keys(source).filter((field) => !["measured", "command"].includes(field));
|
|
2596
|
+
if (unknownSource.length > 0) throw new Error(`${label}.safetySource has unsupported fields: ${unknownSource.join(", ")}.`);
|
|
2597
|
+
if (source.measured !== false || source.command !== void 0 && (typeof source.command !== "string" || !source.command.trim())) throw new Error(`${label}.safetySource is invalid.`);
|
|
2598
|
+
return true;
|
|
2599
|
+
}
|
|
2581
2600
|
function parseExternalCliReceiptMetadata(value, key, source) {
|
|
2582
2601
|
if (value === void 0) return void 0;
|
|
2583
2602
|
const label = `Invalid workflow receipt '${source}': entry '${key}' externalAdapter`;
|
|
2584
2603
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} must be an object.`);
|
|
2585
2604
|
const metadata = value;
|
|
2586
|
-
const unknownMetadata = Object.keys(metadata).filter((field) => !["adapter", "capabilities", "machine", "safety", "outputArtifacts", "handoff", "supervisor", "nonResumableReason"].includes(field));
|
|
2605
|
+
const unknownMetadata = Object.keys(metadata).filter((field) => !["adapter", "capabilities", "machine", "safety", "safetySource", "outputArtifacts", "handoff", "supervisor", "nonResumableReason"].includes(field));
|
|
2587
2606
|
if (unknownMetadata.length > 0) throw new Error(`${label} has unsupported fields: ${unknownMetadata.join(", ")}.`);
|
|
2588
2607
|
const adapter = metadata.adapter;
|
|
2589
2608
|
if (!adapter || typeof adapter !== "object" || Array.isArray(adapter)) throw new Error(`${label}.adapter must be an object.`);
|
|
@@ -2601,47 +2620,23 @@ function parseExternalCliReceiptMetadata(value, key, source) {
|
|
|
2601
2620
|
}
|
|
2602
2621
|
if (metadata.machine !== void 0) parseExternalCliMachine(metadata.machine, label);
|
|
2603
2622
|
const safety = metadata.safety;
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
const safetyRecord = safety;
|
|
2607
|
-
const unknownSafety = Object.keys(safetyRecord).filter((field) => !["sandbox", "approvalPolicy", "ephemeral"].includes(field));
|
|
2608
|
-
if (unknownSafety.length > 0) throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
|
|
2609
|
-
if (safetyRecord.sandbox !== "read-only" || safetyRecord.approvalPolicy !== "never" || safetyRecord.ephemeral !== true) throw new Error(`${label}.safety is invalid.`);
|
|
2610
|
-
} else if (adapterRecord.id === "codex-exec-writer") {
|
|
2611
|
-
if (!safety || typeof safety !== "object" || Array.isArray(safety)) throw new Error(`${label}.safety is missing.`);
|
|
2612
|
-
const safetyRecord = safety;
|
|
2613
|
-
const unknownSafety = Object.keys(safetyRecord).filter((field) => !["access", "sandbox", "approvalPolicy", "ephemeral"].includes(field));
|
|
2614
|
-
if (unknownSafety.length > 0) throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
|
|
2615
|
-
if (safetyRecord.access !== "workspace-write" || safetyRecord.sandbox !== "workspace-write" || safetyRecord.approvalPolicy !== "never" || safetyRecord.ephemeral !== true) throw new Error(`${label}.safety is invalid.`);
|
|
2616
|
-
} else if (adapterRecord.id === "claude-code") {
|
|
2617
|
-
if (!safety || typeof safety !== "object" || Array.isArray(safety)) throw new Error(`${label}.safety is missing.`);
|
|
2623
|
+
const hasSafetySource = parseExternalCliSafetySource(metadata.safetySource, label);
|
|
2624
|
+
if (adapterRecord.id === "claude-code" && !hasSafetySource && safety && typeof safety === "object" && !Array.isArray(safety) && safety.authentication === void 0) {
|
|
2618
2625
|
const safetyRecord = safety;
|
|
2619
|
-
const
|
|
2620
|
-
const unknownSafety = Object.keys(safetyRecord).filter((field) => !(legacy ? ["permissionMode", "tools", "mcp", "settingSources", "sessionPersistence"] : ["access", "authentication", "permissionMode", "tools", "mcp", "settingSources", "userSettingsTrust", "sessionPersistence"]).includes(field));
|
|
2626
|
+
const unknownSafety = Object.keys(safetyRecord).filter((field) => !["permissionMode", "tools", "mcp", "settingSources", "sessionPersistence"].includes(field));
|
|
2621
2627
|
if (unknownSafety.length > 0) throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
|
|
2622
|
-
if (
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
} else if (adapterRecord.id === "claude-code-writer") {
|
|
2626
|
-
if (!safety || typeof safety !== "object" || Array.isArray(safety)) throw new Error(`${label}.safety is missing.`);
|
|
2627
|
-
const safetyRecord = safety;
|
|
2628
|
-
const unknownSafety = Object.keys(safetyRecord).filter((field) => !["access", "authentication", "permissionMode", "tools", "mcp", "settingSources", "userSettingsTrust", "sessionPersistence"].includes(field));
|
|
2629
|
-
if (unknownSafety.length > 0) throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
|
|
2630
|
-
if (safetyRecord.access !== "workspace-write" || safetyRecord.authentication !== "existing-cli-required" || safetyRecord.permissionMode !== "acceptEdits" || safetyRecord.tools !== "Read,Write,Edit,Glob,Grep" || safetyRecord.mcp !== "empty-strict" || safetyRecord.settingSources !== "user" || safetyRecord.userSettingsTrust !== "required" || safetyRecord.sessionPersistence !== false) throw new Error(`${label}.safety is invalid.`);
|
|
2631
|
-
} else if (adapterRecord.id === "cursor-agent" || adapterRecord.id === "cursor-agent-writer") {
|
|
2632
|
-
if (!safety || typeof safety !== "object" || Array.isArray(safety)) throw new Error(`${label}.safety is missing.`);
|
|
2633
|
-
const safetyRecord = safety;
|
|
2634
|
-
const unknownSafety = Object.keys(safetyRecord).filter((field) => !["access", "authentication", "mode", "sandbox", "workspaceTrust", "sessionReuse"].includes(field));
|
|
2635
|
-
if (unknownSafety.length > 0) throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
|
|
2636
|
-
const writer = adapterRecord.id === "cursor-agent-writer";
|
|
2637
|
-
if (safetyRecord.access !== (writer ? "workspace-write" : "read-only") || safetyRecord.authentication !== "cursor-api-key-or-existing-login" || safetyRecord.mode !== (writer ? "print" : "ask") || safetyRecord.sandbox !== "enabled" || safetyRecord.workspaceTrust !== "existing-required" || safetyRecord.sessionReuse !== false) throw new Error(`${label}.safety is invalid.`);
|
|
2628
|
+
if (safetyRecord.permissionMode !== "plan" || safetyRecord.tools !== "none" || safetyRecord.mcp !== "empty-strict" || safetyRecord.settingSources !== "none" || safetyRecord.sessionPersistence !== false) throw new Error(`${label}.safety is invalid.`);
|
|
2629
|
+
} else if (isCodeOwnedExternalCliAdapterId(adapterRecord.id)) {
|
|
2630
|
+
parseCodeOwnedSafety(safety, adapterRecord.id, label);
|
|
2638
2631
|
} else if (adapterRecord.id === "grok-build") {
|
|
2632
|
+
if (hasSafetySource) throw new Error(`${label}.safetySource is invalid for the legacy grok-build adapter.`);
|
|
2639
2633
|
if (!safety || typeof safety !== "object" || Array.isArray(safety)) throw new Error(`${label}.safety is missing.`);
|
|
2640
2634
|
const safetyRecord = safety;
|
|
2641
2635
|
const unknownSafety = Object.keys(safetyRecord).filter((field) => !["access", "authentication", "permissionMode", "tools", "deniedTools", "sandbox", "webSearch", "subagents", "config", "updates", "sessionPersistence"].includes(field));
|
|
2642
2636
|
if (unknownSafety.length > 0) throw new Error(`${label}.safety has unsupported fields: ${unknownSafety.join(", ")}.`);
|
|
2643
2637
|
if (safetyRecord.access !== "read-only" || safetyRecord.authentication !== "xai-api-key-required" || safetyRecord.permissionMode !== "plan" || safetyRecord.tools !== "read_file,grep,list_dir" || safetyRecord.deniedTools !== "run_terminal_cmd,search_replace,Agent,Bash,Edit,Write,MCPTool" || safetyRecord.sandbox !== "read-only" || safetyRecord.webSearch !== false || safetyRecord.subagents !== false || safetyRecord.config !== "temporary-home" || safetyRecord.updates !== "disabled" || safetyRecord.sessionPersistence !== false) throw new Error(`${label}.safety is invalid.`);
|
|
2644
|
-
} else if (
|
|
2638
|
+
} else if (hasSafetySource) throw new Error(`${label}.safetySource is invalid for the generic adapter.`);
|
|
2639
|
+
else if (safety !== void 0) throw new Error(`${label}.safety is invalid for the generic adapter.`);
|
|
2645
2640
|
const handoff = metadata.handoff;
|
|
2646
2641
|
if (!handoff || typeof handoff !== "object" || Array.isArray(handoff)) throw new Error(`${label}.handoff must be an object.`);
|
|
2647
2642
|
const handoffRecord = handoff;
|
|
@@ -3114,6 +3109,7 @@ function editableAgentConfig(agent) {
|
|
|
3114
3109
|
const next = { ...config };
|
|
3115
3110
|
if (!hasDeclaredField("model")) delete next.model;
|
|
3116
3111
|
if (!hasDeclaredField("thinking")) delete next.thinking;
|
|
3112
|
+
if (!hasDeclaredField("inheritGlobalContext")) next.inheritGlobalContext = false;
|
|
3117
3113
|
return next;
|
|
3118
3114
|
};
|
|
3119
3115
|
const {
|
|
@@ -3162,7 +3158,7 @@ function editableAgentConfig(agent) {
|
|
|
3162
3158
|
...base.thinking !== void 0 && hasDeclaredField("thinking") ? { thinking: base.thinking } : {},
|
|
3163
3159
|
systemPromptMode: base.systemPromptMode,
|
|
3164
3160
|
inheritProjectContext: base.inheritProjectContext,
|
|
3165
|
-
inheritGlobalContext: base.inheritGlobalContext,
|
|
3161
|
+
inheritGlobalContext: hasDeclaredField("inheritGlobalContext") && base.inheritGlobalContext,
|
|
3166
3162
|
inheritSkills: base.inheritSkills,
|
|
3167
3163
|
...base.defaultContext !== void 0 ? { defaultContext: base.defaultContext } : {},
|
|
3168
3164
|
...base.acceptanceRole !== void 0 ? { acceptanceRole: base.acceptanceRole } : {},
|
|
@@ -3785,7 +3781,8 @@ function handleList(params, ctx) {
|
|
|
3785
3781
|
const capabilityMode = params.capabilities === true;
|
|
3786
3782
|
const externalCliAvailability = capabilityMode ? externalCliAvailabilityForAgents([...agents, ...restrictedAgents]) : void 0;
|
|
3787
3783
|
const availableModels = capabilityMode ? ctx.modelRegistry.getAvailable().map(toModelInfo) : [];
|
|
3788
|
-
const
|
|
3784
|
+
const knownProviders = knownModelProviders(ctx.modelRegistry);
|
|
3785
|
+
const unavailableModels = new Set([...agents, ...restrictedAgents].filter((agent) => (agent.runner?.type ?? "pi") === "pi" && isUnavailableSubagentModel(agent.model, availableModels, agent.modelProvider ?? ctx.model?.provider, knownProviders)));
|
|
3789
3786
|
const formatLine = capabilityMode ? (agent, names) => formatAgentCapabilitiesLine(agent, names, externalCliAvailability, unavailableModels) : formatAgentListLine;
|
|
3790
3787
|
const lines = [
|
|
3791
3788
|
capabilityMode ? "Executable agents (capabilities):" : "Executable agents:",
|
|
@@ -3828,6 +3825,7 @@ function handleModels(params, ctx) {
|
|
|
3828
3825
|
const discovered = discoverCatalog(ctx, ctx.cwd, ctx.model?.provider);
|
|
3829
3826
|
const effectiveAgents = effectiveAgentsForScope(scope, discovered, ctx.runtimeAgentOwner, ctx.model?.provider).sort((a, b) => a.name.localeCompare(b.name));
|
|
3830
3827
|
const availableModels = ctx.modelRegistry.getAvailable().map(toModelInfo);
|
|
3828
|
+
const knownProviders = knownModelProviders(ctx.modelRegistry);
|
|
3831
3829
|
const currentModel = ctx.model ? { provider: ctx.model.provider, id: ctx.model.id } : void 0;
|
|
3832
3830
|
const preferredProvider = ctx.model?.provider;
|
|
3833
3831
|
const capabilityCeiling = resolveCurrentSubagentCapabilityCeiling(ctx.piSessionId);
|
|
@@ -3856,8 +3854,8 @@ function handleModels(params, ctx) {
|
|
|
3856
3854
|
];
|
|
3857
3855
|
const modelEntries = selectedAgents.flatMap((agent) => requestedAgent ? [{ agent, name: requestedAgent }] : [{ agent, name: agent.name }, ...(agent.aliases ?? []).map((name) => ({ agent, name }))]);
|
|
3858
3856
|
for (const { agent, name } of modelEntries) {
|
|
3859
|
-
const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, agent.modelProvider ?? preferredProvider);
|
|
3860
|
-
const shownModel = resolvedModel === void 0 ? "(unresolved)" : (agent.runner?.type ?? "pi") === "pi" && isUnavailableSubagentModel(agent.model, availableModels, agent.modelProvider ?? preferredProvider) ? `${resolvedModel} ${UNAVAILABLE_MODEL_MARKER}` : resolvedModel;
|
|
3857
|
+
const resolvedModel = resolveSubagentModelOverride(agent.model, currentModel, availableModels, agent.modelProvider ?? preferredProvider, { knownProviders });
|
|
3858
|
+
const shownModel = resolvedModel === void 0 ? "(unresolved)" : (agent.runner?.type ?? "pi") === "pi" && isUnavailableSubagentModel(agent.model, availableModels, agent.modelProvider ?? preferredProvider, knownProviders) ? `${resolvedModel} ${UNAVAILABLE_MODEL_MARKER}` : resolvedModel;
|
|
3861
3859
|
const effectiveThinking = resolveEffectiveThinking(resolvedModel, agent.thinking) ?? (agent.thinking === false ? "off" : void 0);
|
|
3862
3860
|
const source = `${formatModelSource(agent, currentModel)}${agent.disabled ? "; disabled" : ""}${isAgentAllowedByCapabilityCeiling(agent.name, capabilityCeiling) ? "" : "; restricted"}`;
|
|
3863
3861
|
if (requestedAgent) {
|
|
@@ -3972,7 +3970,7 @@ function handleCreate(params, ctx) {
|
|
|
3972
3970
|
if (mw) warnings.push(mw);
|
|
3973
3971
|
const sw = skillsWarning(ctx.cwd, agent);
|
|
3974
3972
|
if (sw) warnings.push(sw);
|
|
3975
|
-
fs7.writeFileSync(targetPath, serializeAgent(agent), "utf-8");
|
|
3973
|
+
fs7.writeFileSync(targetPath, serializeAgent(agent, { explicitInheritGlobalContext: hasKey(cfg, "inheritGlobalContext") }), "utf-8");
|
|
3976
3974
|
ctx.onAgentsChanged?.();
|
|
3977
3975
|
return result4([`Created agent '${runtimeName}' at ${targetPath}.`, ...warnings].join("\n"));
|
|
3978
3976
|
}
|
|
@@ -4362,7 +4360,7 @@ function resolveWatchdogModelInput(ctx, rawModel) {
|
|
|
4362
4360
|
if (!trimmed) throw new Error("Watchdog model must be a non-empty provider/model value.");
|
|
4363
4361
|
const availableModels = modelRegistryEntries(ctx);
|
|
4364
4362
|
const preferredProvider = typeof ctx.model?.provider === "string" ? ctx.model.provider : void 0;
|
|
4365
|
-
const resolved = resolveModelCandidate(trimmed, availableModels, preferredProvider) ?? trimmed;
|
|
4363
|
+
const resolved = resolveModelCandidate(trimmed, availableModels, preferredProvider, knownModelProviders(ctx.modelRegistry)) ?? trimmed;
|
|
4366
4364
|
const { baseModel, thinkingSuffix } = splitKnownThinkingSuffix(resolved);
|
|
4367
4365
|
const named = splitProviderModel(baseModel);
|
|
4368
4366
|
if (!named) throw new Error(`Watchdog model '${rawModel}' did not resolve to provider/model. Use a provider-qualified model such as openai-codex/gpt-5.5:high or anthropic/claude-opus-4-8:high.`);
|
|
@@ -6575,7 +6573,7 @@ function registerPiWebSessionLiveness(registration) {
|
|
|
6575
6573
|
// src/runs/background/wait-subscriptions.ts
|
|
6576
6574
|
import * as fs10 from "node:fs";
|
|
6577
6575
|
import * as path9 from "node:path";
|
|
6578
|
-
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
6576
|
+
import { createHash as createHash3, randomUUID as randomUUID4 } from "node:crypto";
|
|
6579
6577
|
var SUBSCRIPTION_VERSION = 1;
|
|
6580
6578
|
var STATUS_OUTCOMES = /* @__PURE__ */ new Set(["timed out", "could not be reconciled", "needs attention", "reconciliation failed"]);
|
|
6581
6579
|
var RECONCILE_INTERVAL_MS = 1e3;
|
|
@@ -6587,7 +6585,7 @@ function isNotFound(error2) {
|
|
|
6587
6585
|
function parseRecord(value) {
|
|
6588
6586
|
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
6589
6587
|
const record = value;
|
|
6590
|
-
if (record.version !== SUBSCRIPTION_VERSION || typeof record.token !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(record.token) || typeof record.sessionId !== "string" || record.targetKind !== "async" && record.targetKind !== "foreground" || typeof record.runId !== "string" || typeof record.requestedId !== "string" || typeof record.createdAt !== "number" || typeof record.expiresAt !== "number") return void 0;
|
|
6588
|
+
if (record.version !== SUBSCRIPTION_VERSION || typeof record.token !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(record.token) || typeof record.sessionId !== "string" || record.completionOwnerId !== void 0 && typeof record.completionOwnerId !== "string" || record.completionOwnerProcess !== void 0 && !isRecordedPid(record.completionOwnerProcess) || record.targetKind !== "async" && record.targetKind !== "foreground" || typeof record.runId !== "string" || typeof record.requestedId !== "string" || typeof record.createdAt !== "number" || typeof record.expiresAt !== "number") return void 0;
|
|
6591
6589
|
return record;
|
|
6592
6590
|
}
|
|
6593
6591
|
function needsAttention(run) {
|
|
@@ -6596,6 +6594,26 @@ function needsAttention(run) {
|
|
|
6596
6594
|
function subscriptionFile(dir, token) {
|
|
6597
6595
|
return path9.join(dir, `${token}.json`);
|
|
6598
6596
|
}
|
|
6597
|
+
function claimPrefix(token, replacedOwnerId) {
|
|
6598
|
+
return `${token}.claim-${createHash3("sha256").update(replacedOwnerId).digest("hex").slice(0, 16)}.`;
|
|
6599
|
+
}
|
|
6600
|
+
function latestClaimGeneration(files, prefix) {
|
|
6601
|
+
let latest = 0;
|
|
6602
|
+
for (const file of files) {
|
|
6603
|
+
const generation = file.startsWith(prefix) ? file.slice(prefix.length) : "";
|
|
6604
|
+
if (/^[1-9][0-9]*$/.test(generation)) latest = Math.max(latest, Number(generation));
|
|
6605
|
+
}
|
|
6606
|
+
return latest;
|
|
6607
|
+
}
|
|
6608
|
+
function removeClaimFiles(dir, token) {
|
|
6609
|
+
try {
|
|
6610
|
+
for (const file of fs10.readdirSync(dir)) {
|
|
6611
|
+
if (file.startsWith(`${token}.claim-`)) fs10.rmSync(path9.join(dir, file), { force: true });
|
|
6612
|
+
}
|
|
6613
|
+
} catch (error2) {
|
|
6614
|
+
if (!isNotFound(error2)) console.error(`Failed to remove claims of wait subscription '${token}':`, error2);
|
|
6615
|
+
}
|
|
6616
|
+
}
|
|
6599
6617
|
function formatWaitSubscriptions(state, now = Date.now()) {
|
|
6600
6618
|
const subscriptions = [...state.waitSubscriptions?.values() ?? []].sort((left, right) => left.createdAt - right.createdAt);
|
|
6601
6619
|
if (subscriptions.length === 0) return void 0;
|
|
@@ -6616,6 +6634,51 @@ function createWaitSubscriptionManager(pi, state, options = {}) {
|
|
|
6616
6634
|
let disposed = false;
|
|
6617
6635
|
let interval;
|
|
6618
6636
|
let lastForeignSweepAt = 0;
|
|
6637
|
+
const readRecordFile = (filePath) => {
|
|
6638
|
+
try {
|
|
6639
|
+
return parseRecord(JSON.parse(fs10.readFileSync(filePath, "utf-8")));
|
|
6640
|
+
} catch (error2) {
|
|
6641
|
+
if (isNotFound(error2)) return void 0;
|
|
6642
|
+
throw error2;
|
|
6643
|
+
}
|
|
6644
|
+
};
|
|
6645
|
+
const isDead = (recorded) => recorded !== void 0 && checkRecordedPidLiveness(recorded, {
|
|
6646
|
+
observedScope: currentPidNamespaceScope(),
|
|
6647
|
+
observedBootId: currentBootId(),
|
|
6648
|
+
kill: options.kill
|
|
6649
|
+
}) === "dead";
|
|
6650
|
+
const latestClaimantHolds = (claimPath) => {
|
|
6651
|
+
let body;
|
|
6652
|
+
try {
|
|
6653
|
+
body = JSON.parse(fs10.readFileSync(claimPath, "utf-8"));
|
|
6654
|
+
} catch (error2) {
|
|
6655
|
+
return !(error2 instanceof SyntaxError);
|
|
6656
|
+
}
|
|
6657
|
+
const claimant = body?.process;
|
|
6658
|
+
return isRecordedPid(claimant) && !isDead(claimant);
|
|
6659
|
+
};
|
|
6660
|
+
const claimRecord = (filePath, record) => {
|
|
6661
|
+
if (!record.completionOwnerId || record.completionOwnerId === state.completionOwnerId) return record;
|
|
6662
|
+
if (!isDead(record.completionOwnerProcess)) return void 0;
|
|
6663
|
+
if (!state.completionOwnerId) return record;
|
|
6664
|
+
const prefix = claimPrefix(record.token, record.completionOwnerId);
|
|
6665
|
+
const latest = latestClaimGeneration(fs10.readdirSync(subscriptionsDir), prefix);
|
|
6666
|
+
if (latest > 0 && latestClaimantHolds(path9.join(subscriptionsDir, `${prefix}${latest}`))) return void 0;
|
|
6667
|
+
const claimPath = path9.join(subscriptionsDir, `${prefix}${latest + 1}`);
|
|
6668
|
+
if (!createClaimFile(claimPath, { ownerId: state.completionOwnerId, process: currentRecordedPid() })) return void 0;
|
|
6669
|
+
try {
|
|
6670
|
+
if (readRecordFile(filePath)?.completionOwnerId !== record.completionOwnerId) {
|
|
6671
|
+
fs10.rmSync(claimPath, { force: true });
|
|
6672
|
+
return void 0;
|
|
6673
|
+
}
|
|
6674
|
+
const claimed = { ...record, completionOwnerId: state.completionOwnerId, completionOwnerProcess: currentRecordedPid() };
|
|
6675
|
+
writeAtomicJson(filePath, claimed);
|
|
6676
|
+
return claimed;
|
|
6677
|
+
} catch (error2) {
|
|
6678
|
+
fs10.rmSync(claimPath, { force: true });
|
|
6679
|
+
throw error2;
|
|
6680
|
+
}
|
|
6681
|
+
};
|
|
6619
6682
|
const sweepExpiredForeignSubscriptions = (force = false) => {
|
|
6620
6683
|
const sweptAt = now();
|
|
6621
6684
|
if (!force && sweptAt - lastForeignSweepAt < FOREIGN_SWEEP_INTERVAL_MS) return;
|
|
@@ -6631,7 +6694,7 @@ function createWaitSubscriptionManager(pi, state, options = {}) {
|
|
|
6631
6694
|
const filePath = path9.join(subscriptionsDir, file);
|
|
6632
6695
|
let record;
|
|
6633
6696
|
try {
|
|
6634
|
-
record =
|
|
6697
|
+
record = readRecordFile(filePath);
|
|
6635
6698
|
} catch (error2) {
|
|
6636
6699
|
console.error(`Ignoring invalid wait subscription '${filePath}':`, error2);
|
|
6637
6700
|
continue;
|
|
@@ -6642,23 +6705,31 @@ function createWaitSubscriptionManager(pi, state, options = {}) {
|
|
|
6642
6705
|
try {
|
|
6643
6706
|
fs10.unlinkSync(filePath);
|
|
6644
6707
|
} catch (error2) {
|
|
6645
|
-
if (!isNotFound(error2))
|
|
6708
|
+
if (!isNotFound(error2)) {
|
|
6709
|
+
console.error(`Failed to remove expired wait subscription '${filePath}':`, error2);
|
|
6710
|
+
continue;
|
|
6711
|
+
}
|
|
6646
6712
|
}
|
|
6713
|
+
removeClaimFiles(subscriptionsDir, record.token);
|
|
6647
6714
|
}
|
|
6648
6715
|
};
|
|
6649
6716
|
const remove = (record) => {
|
|
6717
|
+
let removed = true;
|
|
6650
6718
|
try {
|
|
6651
6719
|
fs10.unlinkSync(subscriptionFile(subscriptionsDir, record.token));
|
|
6652
6720
|
} catch (error2) {
|
|
6653
6721
|
if (!isNotFound(error2)) throw error2;
|
|
6722
|
+
removed = false;
|
|
6654
6723
|
}
|
|
6655
6724
|
subscriptions.delete(record.token);
|
|
6656
6725
|
unresolvedRestoredForegroundTokens.delete(record.token);
|
|
6726
|
+
removeClaimFiles(subscriptionsDir, record.token);
|
|
6727
|
+
return removed;
|
|
6657
6728
|
};
|
|
6658
6729
|
const settle = (record, outcome, detail, completion) => {
|
|
6659
6730
|
if (disposed || state.currentSessionId !== record.sessionId) return;
|
|
6660
6731
|
try {
|
|
6661
|
-
remove(record);
|
|
6732
|
+
if (!remove(record)) return;
|
|
6662
6733
|
} catch (error2) {
|
|
6663
6734
|
console.error(`Failed to clear wait subscription '${record.token}'; it remains armed:`, error2);
|
|
6664
6735
|
return;
|
|
@@ -6771,6 +6842,7 @@ Parent action: ${STATUS_OUTCOMES.has(outcome) ? STATUS_ACTION : COMPLETION_ACTIO
|
|
|
6771
6842
|
version: SUBSCRIPTION_VERSION,
|
|
6772
6843
|
token: randomUUID4(),
|
|
6773
6844
|
sessionId,
|
|
6845
|
+
...state.completionOwnerId ? { completionOwnerId: state.completionOwnerId, completionOwnerProcess: currentRecordedPid() } : {},
|
|
6774
6846
|
targetKind: input.targetKind,
|
|
6775
6847
|
runId: input.runId,
|
|
6776
6848
|
requestedId: input.requestedId,
|
|
@@ -6795,16 +6867,19 @@ Parent action: ${STATUS_OUTCOMES.has(outcome) ? STATUS_ACTION : COMPLETION_ACTIO
|
|
|
6795
6867
|
throw error2;
|
|
6796
6868
|
}
|
|
6797
6869
|
for (const file of files) {
|
|
6870
|
+
const filePath = path9.join(subscriptionsDir, file);
|
|
6871
|
+
let record;
|
|
6798
6872
|
try {
|
|
6799
|
-
const
|
|
6800
|
-
if (!
|
|
6801
|
-
|
|
6802
|
-
subscriptions.set(record.token, record);
|
|
6803
|
-
if (record.targetKind === "foreground" && !state.foregroundRuns?.has(record.runId)) unresolvedRestoredForegroundTokens.add(record.token);
|
|
6804
|
-
}
|
|
6873
|
+
const found = readRecordFile(filePath);
|
|
6874
|
+
if (!found || file !== `${found.token}.json` || found.sessionId !== state.currentSessionId) continue;
|
|
6875
|
+
record = claimRecord(filePath, found);
|
|
6805
6876
|
} catch (error2) {
|
|
6806
|
-
console.error(`
|
|
6877
|
+
console.error(`Failed to restore wait subscription '${filePath}':`, error2);
|
|
6878
|
+
continue;
|
|
6807
6879
|
}
|
|
6880
|
+
if (!record) continue;
|
|
6881
|
+
subscriptions.set(record.token, record);
|
|
6882
|
+
if (record.targetKind === "foreground" && !state.foregroundRuns?.has(record.runId)) unresolvedRestoredForegroundTokens.add(record.token);
|
|
6808
6883
|
}
|
|
6809
6884
|
reconcile();
|
|
6810
6885
|
},
|
|
@@ -7107,6 +7182,7 @@ var CHORD_PEER_ALIASES = [
|
|
|
7107
7182
|
{ specifier: "@earendil-works/chord", pkg: "@earendil-works/chord", subpath: "." },
|
|
7108
7183
|
{ specifier: "@earendil-works/chord/context", pkg: "@earendil-works/chord", subpath: "./context" }
|
|
7109
7184
|
];
|
|
7185
|
+
var SCHEMA_PACKAGE = "@earendil-works/pi-schema";
|
|
7110
7186
|
function readManifest(packageDir) {
|
|
7111
7187
|
try {
|
|
7112
7188
|
return JSON.parse(fs12.readFileSync(path11.join(packageDir, "package.json"), "utf-8"));
|
|
@@ -7197,6 +7273,15 @@ function resolveHostPeerAliases(piPackageRoot) {
|
|
|
7197
7273
|
if (target && fs12.existsSync(target)) aliases[specifier] = fs12.realpathSync(target);
|
|
7198
7274
|
else if (pkg !== CHORD_PACKAGE || chordRequired) missing.push(specifier);
|
|
7199
7275
|
}
|
|
7276
|
+
const piAiDir = findPeerPackageDir(piPackageRoot, "@earendil-works/pi-ai", hostManifest?.name);
|
|
7277
|
+
const piAiManifest = piAiDir ? readManifest(piAiDir) : void 0;
|
|
7278
|
+
if (piAiDir && piAiManifest && declaresDependency(piAiManifest, SCHEMA_PACKAGE)) {
|
|
7279
|
+
const schemaDir = findPeerPackageDir(fs12.realpathSync(piAiDir), SCHEMA_PACKAGE, void 0);
|
|
7280
|
+
for (const subpath of [".", "./formats"]) {
|
|
7281
|
+
const target = schemaDir ? resolvePackageSubpath(schemaDir, subpath) : void 0;
|
|
7282
|
+
if (!target || !fs12.existsSync(target)) missing.push(subpath === "." ? SCHEMA_PACKAGE : `${SCHEMA_PACKAGE}/formats`);
|
|
7283
|
+
}
|
|
7284
|
+
}
|
|
7200
7285
|
return { aliases, missing };
|
|
7201
7286
|
}
|
|
7202
7287
|
|
|
@@ -7468,10 +7553,12 @@ function createDefaultChildSessionFactory(options = {}) {
|
|
|
7468
7553
|
const loadPiCodingAgent = options.loadPiCodingAgent ?? loadHostPiCodingAgent;
|
|
7469
7554
|
const shutdownTimeoutMs = options.shutdownTimeoutMs ?? 5e3;
|
|
7470
7555
|
let runtime;
|
|
7471
|
-
const live = /* @__PURE__ */ new
|
|
7556
|
+
const live = /* @__PURE__ */ new Map();
|
|
7472
7557
|
const shutdowns = /* @__PURE__ */ new Set();
|
|
7473
7558
|
const mcpWaits = /* @__PURE__ */ new Map();
|
|
7474
|
-
let
|
|
7559
|
+
let globalDisposals = 0;
|
|
7560
|
+
const parentDisposals = /* @__PURE__ */ new Map();
|
|
7561
|
+
const parentDisposalEpoch = (parent) => parentDisposals.get(parent) ?? 0;
|
|
7475
7562
|
const sharedRuntime = async (pi) => {
|
|
7476
7563
|
runtime ??= pi.ModelRuntime.create().catch((error2) => {
|
|
7477
7564
|
runtime = void 0;
|
|
@@ -7479,9 +7566,28 @@ function createDefaultChildSessionFactory(options = {}) {
|
|
|
7479
7566
|
});
|
|
7480
7567
|
return runtime;
|
|
7481
7568
|
};
|
|
7569
|
+
const disposeMatching = async (matches) => {
|
|
7570
|
+
for (const [cancel, wait] of mcpWaits) if (matches(wait.parent)) cancel.abort();
|
|
7571
|
+
const children = [...live.keys()].filter((child) => !child.detached && matches(live.get(child)));
|
|
7572
|
+
for (const child of children) child.shutDown = true;
|
|
7573
|
+
await Promise.allSettled(children.map((child) => child.abort()));
|
|
7574
|
+
for (const child of children) {
|
|
7575
|
+
try {
|
|
7576
|
+
void child.dispose();
|
|
7577
|
+
} catch {
|
|
7578
|
+
}
|
|
7579
|
+
}
|
|
7580
|
+
await Promise.allSettled([
|
|
7581
|
+
...shutdowns,
|
|
7582
|
+
...[...mcpWaits.values()].filter((wait) => matches(wait.parent)).map((wait) => wait.ready)
|
|
7583
|
+
]);
|
|
7584
|
+
if (live.size === 0) runtime = void 0;
|
|
7585
|
+
};
|
|
7482
7586
|
return {
|
|
7483
7587
|
async create(launch) {
|
|
7484
|
-
const
|
|
7588
|
+
const globalDisposalsAtStart = globalDisposals;
|
|
7589
|
+
const parentEpochAtStart = parentDisposalEpoch(launch.parentSessionFile);
|
|
7590
|
+
const disposedSinceStart = () => globalDisposals !== globalDisposalsAtStart || parentDisposalEpoch(launch.parentSessionFile) !== parentEpochAtStart;
|
|
7485
7591
|
const pi = await loadPiCodingAgent();
|
|
7486
7592
|
const builtinMcpTools = launch.builtinMcpTools ?? [];
|
|
7487
7593
|
let readinessTool;
|
|
@@ -7630,11 +7736,11 @@ function createDefaultChildSessionFactory(options = {}) {
|
|
|
7630
7736
|
if (builtinMcp) {
|
|
7631
7737
|
const cancel = new AbortController();
|
|
7632
7738
|
const signal = launch.signal ? AbortSignal.any([cancel.signal, launch.signal]) : cancel.signal;
|
|
7633
|
-
if (
|
|
7739
|
+
if (disposedSinceStart()) cancel.abort();
|
|
7634
7740
|
const ready = (async () => {
|
|
7635
7741
|
try {
|
|
7636
7742
|
await builtinMcp.waitForTools(signal, () => loader.getExtensions().errors.find(({ path: path17 }) => path17 === "builtin:mcp")?.error);
|
|
7637
|
-
if (
|
|
7743
|
+
if (disposedSinceStart()) throw new Error("The child session factory was disposed while the child waited for its MCP tools.");
|
|
7638
7744
|
if (signal.aborted) throw new Error("The child launch was cancelled while waiting for its MCP tools.");
|
|
7639
7745
|
const missing = missingBuiltinMcpTools(session, builtinMcpTools.map(({ name }) => name));
|
|
7640
7746
|
if (missing.length) throw new Error(`Selected built-in MCP tools did not register in the child session: ${missing.join(", ")}. The MCP server may have failed to connect, or the name belongs to a different tool than the selector names; check it with /mcp.`);
|
|
@@ -7643,7 +7749,7 @@ function createDefaultChildSessionFactory(options = {}) {
|
|
|
7643
7749
|
throw error2;
|
|
7644
7750
|
}
|
|
7645
7751
|
})();
|
|
7646
|
-
mcpWaits.set(cancel, ready);
|
|
7752
|
+
mcpWaits.set(cancel, { ready, parent: launch.parentSessionFile });
|
|
7647
7753
|
try {
|
|
7648
7754
|
await ready;
|
|
7649
7755
|
} finally {
|
|
@@ -7697,23 +7803,16 @@ function createDefaultChildSessionFactory(options = {}) {
|
|
|
7697
7803
|
return session.model?.contextWindow;
|
|
7698
7804
|
}
|
|
7699
7805
|
};
|
|
7700
|
-
live.
|
|
7806
|
+
live.set(child, launch.parentSessionFile);
|
|
7701
7807
|
return child;
|
|
7702
7808
|
},
|
|
7703
7809
|
async dispose() {
|
|
7704
|
-
|
|
7705
|
-
|
|
7706
|
-
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7710
|
-
try {
|
|
7711
|
-
void child.dispose();
|
|
7712
|
-
} catch {
|
|
7713
|
-
}
|
|
7714
|
-
}
|
|
7715
|
-
await Promise.allSettled([...shutdowns, ...mcpWaits.values()]);
|
|
7716
|
-
if (live.size === 0) runtime = void 0;
|
|
7810
|
+
globalDisposals += 1;
|
|
7811
|
+
await disposeMatching(() => true);
|
|
7812
|
+
},
|
|
7813
|
+
async disposeForParent(parentSessionFile) {
|
|
7814
|
+
parentDisposals.set(parentSessionFile, parentDisposalEpoch(parentSessionFile) + 1);
|
|
7815
|
+
await disposeMatching((parent) => parent === parentSessionFile);
|
|
7717
7816
|
}
|
|
7718
7817
|
};
|
|
7719
7818
|
}
|
|
@@ -7725,28 +7824,28 @@ function childSessionFactory() {
|
|
|
7725
7824
|
}
|
|
7726
7825
|
function createLazyPlacementFactory(local) {
|
|
7727
7826
|
let placed;
|
|
7728
|
-
const factory = async () => placed ??= (await import("./chunk-
|
|
7827
|
+
const factory = async () => placed ??= (await import("./chunk-YEXKJJVS.js")).createPlacementAwareChildSessionFactory(local);
|
|
7729
7828
|
return {
|
|
7730
7829
|
async create(launch) {
|
|
7731
7830
|
return launch.machine ? (await factory()).create(launch) : local.create(launch);
|
|
7732
7831
|
},
|
|
7733
7832
|
async dispose() {
|
|
7734
|
-
|
|
7735
|
-
|
|
7833
|
+
await (placed ?? local).dispose();
|
|
7834
|
+
},
|
|
7835
|
+
async disposeForParent(parentSessionFile) {
|
|
7836
|
+
await (placed ?? local).disposeForParent(parentSessionFile);
|
|
7736
7837
|
}
|
|
7737
7838
|
};
|
|
7738
7839
|
}
|
|
7739
7840
|
function childSessionFactoryModule() {
|
|
7740
7841
|
return activeFactoryModule;
|
|
7741
7842
|
}
|
|
7742
|
-
async function
|
|
7743
|
-
|
|
7744
|
-
if (!factory) return;
|
|
7745
|
-
await factory.dispose();
|
|
7843
|
+
async function disposeChildSessionsForParent(parentSessionFile) {
|
|
7844
|
+
await activeFactory?.disposeForParent(parentSessionFile);
|
|
7746
7845
|
}
|
|
7747
7846
|
|
|
7748
7847
|
// src/workflows/workflow-reuse.ts
|
|
7749
|
-
import { createHash as
|
|
7848
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
7750
7849
|
import * as fs14 from "node:fs";
|
|
7751
7850
|
import * as path13 from "node:path";
|
|
7752
7851
|
var WORKFLOW_CHILD_JOURNAL_FILE = "workflow-children.jsonl";
|
|
@@ -7758,7 +7857,7 @@ function workflowStopCause(reason) {
|
|
|
7758
7857
|
return reason instanceof Error && "workflowStopCause" in reason && reason.workflowStopCause === WORKFLOW_STOP_CAUSE_RUNTIME_REPLACED ? WORKFLOW_STOP_CAUSE_RUNTIME_REPLACED : void 0;
|
|
7759
7858
|
}
|
|
7760
7859
|
function sha256(text2) {
|
|
7761
|
-
return
|
|
7860
|
+
return createHash4("sha256").update(text2).digest("hex");
|
|
7762
7861
|
}
|
|
7763
7862
|
function workflowScriptDigest(script) {
|
|
7764
7863
|
return sha256(script);
|
|
@@ -7883,7 +7982,7 @@ import { randomUUID as randomUUID6 } from "node:crypto";
|
|
|
7883
7982
|
import * as path14 from "node:path";
|
|
7884
7983
|
var MAX_WORKFLOW_RESUME_ATTEMPTS = 3;
|
|
7885
7984
|
function workflowResumeRefusal(code, reason, runId) {
|
|
7886
|
-
const byHand = code === "launch-missing" || code === "launch-invalid" || code === "structured" || code === "internal" || code === "digest" || code === "authority" ? relaunchByHandText(runId) : code === "capacity" || code === "attempts" || code === "launch-failed" ? resumeByHandText(runId) : "";
|
|
7985
|
+
const byHand = code === "launch-missing" || code === "launch-invalid" || code === "structured" || code === "internal" || code === "digest" || code === "authority" || code === "drained" ? relaunchByHandText(runId) : code === "capacity" || code === "attempts" || code === "launch-failed" ? resumeByHandText(runId) : "";
|
|
7887
7986
|
return { code, reason, byHand };
|
|
7888
7987
|
}
|
|
7889
7988
|
function manualWorkflowResumeRefusalText(runId, refusal) {
|
|
@@ -7913,6 +8012,7 @@ function prepareWorkflowResume(input) {
|
|
|
7913
8012
|
if (trigger === "manual") reconcileAsyncRun(sourceAsyncDir);
|
|
7914
8013
|
const status = readStatus(sourceAsyncDir);
|
|
7915
8014
|
if (!status || status.mode !== "workflow" || !isReusableWorkflowStopCause(status.workflow?.stopCause)) return refuse("not-interrupted", "not interrupted; pass message to revive one of its children");
|
|
8015
|
+
if (status.workflow?.drainRequestedAt !== void 0) return refuse("drained", "it was being drained when it was interrupted");
|
|
7916
8016
|
const attempt = (status.workflow?.resumeOrigin?.attempt ?? 0) + (status.workflow?.stopCause === WORKFLOW_STOP_CAUSE_OWNER_EXITED ? 1 : 0);
|
|
7917
8017
|
if (trigger === "auto" && attempt > MAX_WORKFLOW_RESUME_ATTEMPTS) return refuse("attempts", `${MAX_WORKFLOW_RESUME_ATTEMPTS} resumes already followed Pi exits`);
|
|
7918
8018
|
if (record.source === "structured") return refuse("structured", "launched from tasks/chain");
|
|
@@ -8658,7 +8758,7 @@ export {
|
|
|
8658
8758
|
childSessionHasQueuedMessages,
|
|
8659
8759
|
childSessionFactory,
|
|
8660
8760
|
childSessionFactoryModule,
|
|
8661
|
-
|
|
8761
|
+
disposeChildSessionsForParent,
|
|
8662
8762
|
WORKFLOW_RUNTIME_REPLACED_STOP_NOTICE,
|
|
8663
8763
|
runtimeReplacedAbortReason,
|
|
8664
8764
|
workflowStopCause,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isTrustedRecordedSessionFile,
|
|
3
3
|
resolveSubagentRunId
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2NY5PCKQ.js";
|
|
5
5
|
import {
|
|
6
6
|
agentStreamOptions,
|
|
7
7
|
opencodeSessionHeaders,
|
|
8
8
|
resolveAsyncResumeTarget
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-XV7RTWTS.js";
|
|
10
10
|
import {
|
|
11
11
|
ownsRun
|
|
12
12
|
} from "./chunk-HXRB42AF.js";
|
|
@@ -18,12 +18,12 @@ import {
|
|
|
18
18
|
reconcileAsyncRun,
|
|
19
19
|
resolveAuthorityDecision,
|
|
20
20
|
resolveMissionStoreLocation
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-PGU4TZV3.js";
|
|
22
22
|
import {
|
|
23
23
|
deliverInterruptRequest,
|
|
24
24
|
queueRevivalBrief,
|
|
25
25
|
requestAsyncSteer
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-VFUFOZBU.js";
|
|
27
27
|
import {
|
|
28
28
|
formatShellCommand
|
|
29
29
|
} from "./chunk-7J4ZXMY7.js";
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
tryLease,
|
|
35
35
|
writeAtomicJson,
|
|
36
36
|
writePrivateAtomicJson
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-C3KWLXDH.js";
|
|
38
38
|
import {
|
|
39
39
|
DIRS
|
|
40
40
|
} from "./chunk-JEZOSEWG.js";
|