pi-subagents 0.84.0 → 0.86.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 +83 -0
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/{chunk-JG4QKI5M.js → chunk-2IYBCYFU.js} +214 -97
- package/bundle/{chunk-V2BZYLEP.js → chunk-374MZFF4.js} +7 -2
- package/bundle/{chunk-4E7BKDTX.js → chunk-3RKFH2UZ.js} +11 -156
- package/bundle/{chunk-F4ASL6OV.js → chunk-5H4BICQZ.js} +1 -1
- package/bundle/{chunk-PALJGGYC.js → chunk-6VD7BGIC.js} +6 -3
- package/bundle/{chunk-C5P5CHYK.js → chunk-77ASNIEM.js} +1 -1
- package/bundle/{chunk-XDQORLZ5.js → chunk-7ADDXUGF.js} +15 -6
- package/bundle/{chunk-PV63UFUR.js → chunk-7QA7ZA46.js} +183 -28
- package/bundle/{chunk-NKQ6JNAS.js → chunk-7ZUFN6ME.js} +2 -1
- package/bundle/{chunk-SSG7IEP5.js → chunk-A637IMAO.js} +2 -2
- package/bundle/{chunk-L3WFKBEI.js → chunk-BGXEAYUM.js} +247 -153
- package/bundle/{chunk-J5YL7LYR.js → chunk-BU6PFPVX.js} +59 -27
- package/bundle/{chunk-DZDETGRJ.js → chunk-BWC2LVII.js} +259 -216
- package/bundle/{chunk-CGN2TVE7.js → chunk-GJGTMLPE.js} +322 -18
- package/bundle/{chunk-D3JAFGMO.js → chunk-GRJHIXYF.js} +1 -1
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-LFDBD4PW.js → chunk-LGINOOY5.js} +2 -2
- package/bundle/{chunk-G2Z6ZH26.js → chunk-NAFLUJ26.js} +1 -1
- package/bundle/{chunk-235AWJUQ.js → chunk-O3YH7XIY.js} +324 -111
- package/bundle/{chunk-2DHZTCOL.js → chunk-PYOAIN3V.js} +2 -2
- package/bundle/{chunk-LNRJCP2Y.js → chunk-QGO6HXHG.js} +417 -242
- package/bundle/{chunk-VQVVHSY6.js → chunk-QM3JGE4W.js} +22 -11
- package/bundle/{chunk-2S4K53MV.js → chunk-S2Q75LP3.js} +1 -1
- package/bundle/{chunk-NENDSQUY.js → chunk-UR7OW5S7.js} +9 -6
- package/bundle/{chunk-AKOIVLA5.js → chunk-WN2E5XHN.js} +135 -77
- package/bundle/{chunk-2D52JFLF.js → chunk-YK3QYNLE.js} +41 -117
- package/bundle/{chunk-7BWGNDNK.js → chunk-ZJJCPV3L.js} +190 -1177
- package/bundle/chunk-ZPY5QZCS.js +1067 -0
- package/bundle/control-channel.js +2 -2
- package/bundle/index.js +1 -1
- package/bundle/intercom-bridge.js +2 -2
- package/bundle/preflight.js +8 -8
- package/bundle/project-panes.js +3 -3
- package/docs/agents.md +23 -2
- package/docs/configuration.md +4 -4
- package/docs/extension-api.md +16 -1
- package/docs/tool-reference.md +2 -0
- package/docs/workflows.md +30 -2
- package/package.json +1 -1
- package/src/agents/agent-management.js +27 -11
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agents.d.ts +1 -3
- package/src/agents/agents.js +7 -6
- package/src/agents/frontmatter.js +1 -8
- package/src/agents/global-npm-root.d.ts +1 -0
- package/src/agents/global-npm-root.js +11 -3
- package/src/agents/skills.d.ts +0 -3
- package/src/agents/skills.js +0 -3
- package/src/extension/config.js +7 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +43 -32
- package/src/extension/public-execution.d.ts +1 -0
- package/src/extension/public-execution.js +4 -0
- package/src/extension/reply-workflow-script.js +24 -4
- package/src/extension/schemas.d.ts +8 -3
- package/src/extension/schemas.js +5 -3
- package/src/extension/session-switch.d.ts +25 -0
- package/src/extension/session-switch.js +138 -0
- package/src/extension/subagent-guide.d.ts +1 -1
- package/src/extension/subagent-guide.js +1 -1
- package/src/extension/subagent-launch-tool.d.ts +25 -0
- package/src/extension/subagent-launch-tool.js +48 -0
- package/src/extension/tool-activation.js +35 -12
- package/src/extension/tool-description.d.ts +1 -1
- package/src/extension/tool-description.js +14 -8
- package/src/inspectors/herdr/actions.d.ts +0 -1
- package/src/inspectors/herdr/actions.js +0 -1
- package/src/inspectors/session-roots-codec.d.ts +0 -1
- package/src/inspectors/session-roots-codec.js +0 -1
- package/src/inspectors/tmux/actions.d.ts +0 -1
- package/src/inspectors/tmux/actions.js +0 -1
- package/src/integrations/herdr-status.js +3 -8
- package/src/intercom/native-supervisor-channel.js +65 -9
- package/src/runs/background/async-execution.d.ts +5 -9
- package/src/runs/background/async-execution.js +62 -27
- package/src/runs/background/async-job-tracker.js +12 -0
- package/src/runs/background/async-resume.d.ts +2 -1
- package/src/runs/background/async-resume.js +112 -39
- package/src/runs/background/async-retention.js +6 -1
- package/src/runs/background/auto-drain.js +2 -1
- package/src/runs/background/boot-id.d.ts +1 -3
- package/src/runs/background/boot-id.js +1 -3
- package/src/runs/background/completion-batcher.d.ts +3 -4
- package/src/runs/background/completion-batcher.js +2 -3
- package/src/runs/background/control-channel.d.ts +0 -6
- package/src/runs/background/control-channel.js +0 -6
- package/src/runs/background/fleet-view.js +2 -3
- package/src/runs/background/notify.d.ts +0 -2
- package/src/runs/background/notify.js +0 -2
- package/src/runs/background/result-watcher.d.ts +1 -0
- package/src/runs/background/result-watcher.js +59 -29
- package/src/runs/background/resume-guidance.js +4 -2
- package/src/runs/background/retained-children.js +2 -1
- package/src/runs/background/run-child-session.d.ts +0 -1
- package/src/runs/background/run-child-session.js +1 -1
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/subagent-runner.d.ts +2 -4
- package/src/runs/background/subagent-runner.js +15 -12
- package/src/runs/background/subagent-wait.js +12 -15
- package/src/runs/background/wait-config.d.ts +2 -0
- package/src/runs/background/wait-config.js +17 -3
- package/src/runs/background/wait-tool.js +4 -2
- package/src/runs/background/workflow-terminal-proof.d.ts +0 -1
- package/src/runs/background/workflow-terminal-proof.js +0 -1
- package/src/runs/foreground/execution.d.ts +0 -3
- package/src/runs/foreground/execution.js +17 -9
- package/src/runs/foreground/subagent-executor.d.ts +3 -2
- package/src/runs/foreground/subagent-executor.js +107 -26
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/child-commands.js +15 -2
- package/src/runs/shared/child-hooks.d.ts +1 -7
- package/src/runs/shared/child-hooks.js +13 -5
- package/src/runs/shared/child-launch.js +6 -2
- package/src/runs/shared/child-runtime-config.d.ts +0 -1
- package/src/runs/shared/child-session.d.ts +1 -1
- package/src/runs/shared/child-session.js +21 -2
- package/src/runs/shared/child-tool-plan.d.ts +0 -1
- package/src/runs/shared/child-tool-plan.js +0 -1
- package/src/runs/shared/claude-code-adapter.js +11 -0
- 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/external-cli-runner.js +26 -6
- package/src/runs/shared/herdr-connection.js +2 -1
- package/src/runs/shared/herdr-pane-host.d.ts +2 -2
- package/src/runs/shared/herdr-pane-host.js +17 -1
- package/src/runs/shared/herdr-placed-run.js +48 -22
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-direct-tool-grant.js +8 -1
- package/src/runs/shared/model-resolution-diagnostic.d.ts +0 -1
- package/src/runs/shared/model-resolution.d.ts +2 -2
- package/src/runs/shared/model-resolution.js +7 -1
- package/src/runs/shared/model-scope.d.ts +1 -5
- package/src/runs/shared/model-scope.js +1 -5
- package/src/runs/shared/mutation-evidence.d.ts +1 -1
- package/src/runs/shared/mutation-evidence.js +52 -7
- package/src/runs/shared/nested-events.d.ts +1 -0
- package/src/runs/shared/nested-events.js +1 -1
- package/src/runs/shared/parallel-utils.d.ts +0 -1
- package/src/runs/shared/permissions.js +5 -3
- package/src/runs/shared/placement-host.d.ts +5 -1
- package/src/runs/shared/rex-pane-host.d.ts +0 -1
- package/src/runs/shared/rex-pane-host.js +0 -2
- package/src/runs/shared/run-launch-folder.d.ts +12 -0
- package/src/runs/shared/run-launch-folder.js +21 -0
- package/src/runs/shared/runner-launcher.d.ts +12 -1
- package/src/runs/shared/runner-launcher.js +16 -0
- package/src/runs/shared/single-output.d.ts +3 -3
- package/src/runs/shared/single-output.js +5 -3
- package/src/runs/shared/structured-output.d.ts +8 -0
- package/src/runs/shared/structured-output.js +40 -5
- package/src/runs/shared/subagent-prompt-runtime.d.ts +0 -1
- package/src/runs/shared/subagent-prompt-runtime.js +4 -2
- package/src/runs/shared/tool-timeout.js +2 -1
- package/src/runs/shared/worktree-cleanup-plan.d.ts +0 -1
- package/src/runs/shared/worktree-cleanup-plan.js +0 -1
- package/src/runs/shared/worktree.d.ts +3 -0
- package/src/runs/shared/worktree.js +20 -0
- package/src/shared/capacity-resilient-json.d.ts +1 -1
- package/src/shared/child-cache-retention.d.ts +1 -2
- package/src/shared/child-cache-retention.js +1 -2
- package/src/shared/fleet-transcript-reader.d.ts +51 -0
- package/src/shared/fleet-transcript-reader.js +333 -0
- package/src/shared/formatters.d.ts +0 -18
- package/src/shared/formatters.js +0 -18
- package/src/shared/session-succession.d.ts +16 -1
- package/src/shared/session-succession.js +41 -2
- package/src/shared/session-warnings.d.ts +7 -0
- package/src/shared/session-warnings.js +26 -0
- package/src/shared/settings.d.ts +0 -23
- package/src/shared/settings.js +3 -35
- package/src/shared/types.d.ts +85 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +0 -14
- package/src/shared/utils.js +0 -22
- package/src/shared/wait-tool-name.d.ts +8 -0
- package/src/shared/wait-tool-name.js +13 -0
- package/src/slash/slash-commands.js +2 -1
- package/src/slash/subagent-cost.d.ts +3 -2
- package/src/slash/subagent-cost.js +22 -3
- package/src/slash/subagents-admin.js +0 -1
- package/src/tui/fleet-status.d.ts +0 -5
- package/src/tui/fleet-status.js +4 -24
- package/src/tui/fleet-transcript.d.ts +1 -44
- package/src/tui/fleet-transcript.js +1 -327
- package/src/tui/fleet.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +161 -66
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.js +241 -20
- package/src/workflows/workflow-launch-record.d.ts +15 -6
- package/src/workflows/workflow-launch-record.js +30 -12
- package/src/workflows/workflow-receipt.js +36 -53
- package/src/workflows/workflow-resume-claim.js +2 -2
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +11 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +79 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
|
@@ -90,7 +90,6 @@ export interface ChildRuntimeConfig {
|
|
|
90
90
|
permissions?: ChildPermissions;
|
|
91
91
|
toolBudget?: ResolvedToolBudget;
|
|
92
92
|
childWatchdog?: ChildWatchdogConfig;
|
|
93
|
-
/** Receives child watchdog status events. */
|
|
94
93
|
watchdogStatus?: (event: ChildWatchdogStatusEvent) => void;
|
|
95
94
|
waitTool: ResolvedWaitToolConfig;
|
|
96
95
|
runtimeState?: SubagentState;
|
|
@@ -16,7 +16,7 @@ export interface ChildSessionExtensionError {
|
|
|
16
16
|
}
|
|
17
17
|
export interface ChildHookExtension {
|
|
18
18
|
name: string;
|
|
19
|
-
factory: (pi: ExtensionAPI) => void
|
|
19
|
+
factory: (pi: ExtensionAPI) => void | Promise<void>;
|
|
20
20
|
}
|
|
21
21
|
export type ChildSessionStorage = {
|
|
22
22
|
kind: "file";
|
|
@@ -18,6 +18,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
18
18
|
import * as fs from "node:fs";
|
|
19
19
|
import * as path from "node:path";
|
|
20
20
|
import { pathToFileURL } from "node:url";
|
|
21
|
+
import { cleanupSessionResources, registerSessionResourceCleanup } from "@earendil-works/pi-ai";
|
|
21
22
|
import { CHILD_COMMAND_TOOL, createChildCommandRuntime } from "./child-commands.js";
|
|
22
23
|
import { supervisorChannelDir } from "./child-tool-plan.js";
|
|
23
24
|
import { pinChildCacheRetention } from "../../shared/child-cache-retention.js";
|
|
@@ -138,6 +139,24 @@ function prioritizeChildCommandRuntime(result) {
|
|
|
138
139
|
extensions.unshift(commands);
|
|
139
140
|
return { ...result, extensions };
|
|
140
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* `dispose()` releases session resources only in the SDK's copy of pi-ai. Under Pi's bundled CLI, the host's
|
|
144
|
+
* extensions register theirs in a different copy: the one this module imports. The observer is registered per
|
|
145
|
+
* dispose because Pi reloads extensions without a module cache, so a module-level one would pile up on each reload.
|
|
146
|
+
*/
|
|
147
|
+
function disposeChildSession(session) {
|
|
148
|
+
let released = false;
|
|
149
|
+
const unregister = registerSessionResourceCleanup((sessionId) => { if (sessionId === session.sessionId)
|
|
150
|
+
released = true; });
|
|
151
|
+
try {
|
|
152
|
+
session.dispose();
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
unregister();
|
|
156
|
+
if (!released)
|
|
157
|
+
cleanupSessionResources(session.sessionId);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
141
160
|
/** One launch at a time from env application through `session_start`, so parallel launches never observe each other's `processEnv` while their extensions load and start. */
|
|
142
161
|
let loading = Promise.resolve();
|
|
143
162
|
/**
|
|
@@ -472,7 +491,7 @@ export function createDefaultChildSessionFactory(options = {}) {
|
|
|
472
491
|
launch.onExtensionError?.({ extensionPath: "<session>", event: "session_shutdown", error });
|
|
473
492
|
}
|
|
474
493
|
finally {
|
|
475
|
-
session
|
|
494
|
+
disposeChildSession(session);
|
|
476
495
|
}
|
|
477
496
|
};
|
|
478
497
|
let inheritedProviders = new Set();
|
|
@@ -552,7 +571,7 @@ export function createDefaultChildSessionFactory(options = {}) {
|
|
|
552
571
|
});
|
|
553
572
|
}
|
|
554
573
|
catch (error) {
|
|
555
|
-
session
|
|
574
|
+
disposeChildSession(session);
|
|
556
575
|
throw error;
|
|
557
576
|
}
|
|
558
577
|
finally {
|
|
@@ -74,7 +74,6 @@ export declare function formatRuntimeSnapshotMcpServersError(agentName: string |
|
|
|
74
74
|
export declare function assertNoToolModifierEntries(agentName: string | undefined, tools: readonly string[]): void;
|
|
75
75
|
export declare function projectLaunchResolvedChildExtensions(toolPlan: Pick<PiLaunchToolPlan, "runtimeExtensions" | "configuredExtensions" | "requiredExtensions" | "extensionArgs" | "disableAmbientExtensions">): LaunchResolvedChildExtensions;
|
|
76
76
|
/**
|
|
77
|
-
* Resolve the permission-system extension entry point when installed.
|
|
78
77
|
* Returns the absolute path to the extension's main module, or undefined
|
|
79
78
|
* when the package is not installed. Callers can check `autoInject` config
|
|
80
79
|
* to decide whether to include it in child sessions.
|
|
@@ -138,7 +138,6 @@ export function projectLaunchResolvedChildExtensions(toolPlan) {
|
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
|
-
* Resolve the permission-system extension entry point when installed.
|
|
142
141
|
* Returns the absolute path to the extension's main module, or undefined
|
|
143
142
|
* when the package is not installed. Callers can check `autoInject` config
|
|
144
143
|
* to decide whether to include it in child sessions.
|
|
@@ -201,6 +201,17 @@ export function createClaudeCodeJsonlParser() {
|
|
|
201
201
|
}
|
|
202
202
|
return { phase: terminal ? terminal.state : "streaming", eventCount };
|
|
203
203
|
},
|
|
204
|
+
/**
|
|
205
|
+
* Reading an image returns it as base64 in a user-role tool result, so that line can be far
|
|
206
|
+
* larger than the parser line limit. Only user lines are absorbed: a terminal `result` is
|
|
207
|
+
* never skipped, because dropping it would discard the answer. The runner bounds the size.
|
|
208
|
+
*/
|
|
209
|
+
skipOversizedLine(prefix) {
|
|
210
|
+
if (terminal || !/^\s*\{\s*"type"\s*:\s*"user"\s*,/.test(prefix))
|
|
211
|
+
return undefined;
|
|
212
|
+
eventCount += 1;
|
|
213
|
+
return { phase: "streaming", eventCount };
|
|
214
|
+
},
|
|
204
215
|
finish() {
|
|
205
216
|
return terminal;
|
|
206
217
|
},
|
|
@@ -12,6 +12,55 @@ export declare function validateCodeOwnedProfileRunner(agent: {
|
|
|
12
12
|
adapter?: string;
|
|
13
13
|
};
|
|
14
14
|
}): string | undefined;
|
|
15
|
+
export declare const EXTERNAL_CLI_ADAPTER_SAFETY: {
|
|
16
|
+
readonly "codex-exec": {
|
|
17
|
+
readonly sandbox: "read-only";
|
|
18
|
+
readonly approvalPolicy: "never";
|
|
19
|
+
readonly ephemeral: true;
|
|
20
|
+
};
|
|
21
|
+
readonly "codex-exec-writer": {
|
|
22
|
+
readonly access: "workspace-write";
|
|
23
|
+
readonly sandbox: "workspace-write";
|
|
24
|
+
readonly approvalPolicy: "never";
|
|
25
|
+
readonly ephemeral: true;
|
|
26
|
+
};
|
|
27
|
+
readonly "claude-code": {
|
|
28
|
+
readonly access: "read-only";
|
|
29
|
+
readonly authentication: "existing-cli-required";
|
|
30
|
+
readonly permissionMode: "plan";
|
|
31
|
+
readonly tools: "none";
|
|
32
|
+
readonly mcp: "empty-strict";
|
|
33
|
+
readonly settingSources: "user";
|
|
34
|
+
readonly userSettingsTrust: "required";
|
|
35
|
+
readonly sessionPersistence: false;
|
|
36
|
+
};
|
|
37
|
+
readonly "claude-code-writer": {
|
|
38
|
+
readonly access: "workspace-write";
|
|
39
|
+
readonly authentication: "existing-cli-required";
|
|
40
|
+
readonly permissionMode: "acceptEdits";
|
|
41
|
+
readonly tools: "Read,Write,Edit,Glob,Grep";
|
|
42
|
+
readonly mcp: "empty-strict";
|
|
43
|
+
readonly settingSources: "user";
|
|
44
|
+
readonly userSettingsTrust: "required";
|
|
45
|
+
readonly sessionPersistence: false;
|
|
46
|
+
};
|
|
47
|
+
readonly "cursor-agent": {
|
|
48
|
+
readonly access: "read-only";
|
|
49
|
+
readonly authentication: "cursor-api-key-or-existing-login";
|
|
50
|
+
readonly mode: "ask";
|
|
51
|
+
readonly sandbox: "enabled";
|
|
52
|
+
readonly workspaceTrust: "existing-required";
|
|
53
|
+
readonly sessionReuse: false;
|
|
54
|
+
};
|
|
55
|
+
readonly "cursor-agent-writer": {
|
|
56
|
+
readonly access: "workspace-write";
|
|
57
|
+
readonly authentication: "cursor-api-key-or-existing-login";
|
|
58
|
+
readonly mode: "print";
|
|
59
|
+
readonly sandbox: "enabled";
|
|
60
|
+
readonly workspaceTrust: "existing-required";
|
|
61
|
+
readonly sessionReuse: false;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
15
64
|
export declare function parseExternalCliCapabilityNarrowing(value: unknown, label: string): ExternalCliCapabilityNarrowing | undefined;
|
|
16
65
|
export declare function resolveExternalCliRunnerStatus(input: {
|
|
17
66
|
adapter?: CodeOwnedExternalCliAdapterId;
|
|
@@ -40,6 +40,16 @@ export function validateCodeOwnedProfileRunner(agent) {
|
|
|
40
40
|
}
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
|
+
// What each adapter's own argv asks the CLI for. It is a profile, not a measurement:
|
|
44
|
+
// a runner command that wraps the CLI can grant something else.
|
|
45
|
+
export const EXTERNAL_CLI_ADAPTER_SAFETY = {
|
|
46
|
+
"codex-exec": { sandbox: "read-only", approvalPolicy: "never", ephemeral: true },
|
|
47
|
+
"codex-exec-writer": { access: "workspace-write", sandbox: "workspace-write", approvalPolicy: "never", ephemeral: true },
|
|
48
|
+
"claude-code": { access: "read-only", authentication: "existing-cli-required", permissionMode: "plan", tools: "none", mcp: "empty-strict", settingSources: "user", userSettingsTrust: "required", sessionPersistence: false },
|
|
49
|
+
"claude-code-writer": { access: "workspace-write", authentication: "existing-cli-required", permissionMode: "acceptEdits", tools: "Read,Write,Edit,Glob,Grep", mcp: "empty-strict", settingSources: "user", userSettingsTrust: "required", sessionPersistence: false },
|
|
50
|
+
"cursor-agent": { access: "read-only", authentication: "cursor-api-key-or-existing-login", mode: "ask", sandbox: "enabled", workspaceTrust: "existing-required", sessionReuse: false },
|
|
51
|
+
"cursor-agent-writer": { access: "workspace-write", authentication: "cursor-api-key-or-existing-login", mode: "print", sandbox: "enabled", workspaceTrust: "existing-required", sessionReuse: false },
|
|
52
|
+
};
|
|
43
53
|
export function parseExternalCliCapabilityNarrowing(value, label) {
|
|
44
54
|
if (value === undefined)
|
|
45
55
|
return undefined;
|
|
@@ -56,13 +66,8 @@ export function parseExternalCliCapabilityNarrowing(value, label) {
|
|
|
56
66
|
return input;
|
|
57
67
|
}
|
|
58
68
|
export function resolveExternalCliRunnerStatus(input) {
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const claudeCode = input.adapter === "claude-code";
|
|
62
|
-
const claudeCodeWriter = input.adapter === "claude-code-writer";
|
|
63
|
-
const cursorAgent = input.adapter === "cursor-agent";
|
|
64
|
-
const cursorAgentWriter = input.adapter === "cursor-agent-writer";
|
|
65
|
-
const cursor = cursorAgent || cursorAgentWriter;
|
|
69
|
+
const cursor = input.adapter === "cursor-agent" || input.adapter === "cursor-agent-writer";
|
|
70
|
+
const profileSafety = input.adapter ? EXTERNAL_CLI_ADAPTER_SAFETY[input.adapter] : undefined;
|
|
66
71
|
const unsupported = cursor ? PROMPT_FILE_UNSUPPORTED : UNSUPPORTED;
|
|
67
72
|
return {
|
|
68
73
|
type: "external-cli",
|
|
@@ -70,12 +75,11 @@ export function resolveExternalCliRunnerStatus(input) {
|
|
|
70
75
|
args: input.args ?? [],
|
|
71
76
|
promptDelivery: cursor ? "prompt-file" : input.promptDelivery ?? "stdin",
|
|
72
77
|
adapter: { id: input.adapter ?? "external-cli", version: 1, executionMode: cursor ? "one-shot-prompt-file" : "one-shot-stdin" },
|
|
73
|
-
...(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
...(cursorAgentWriter ? { safety: { access: "workspace-write", authentication: "cursor-api-key-or-existing-login", mode: "print", sandbox: "enabled", workspaceTrust: "existing-required", sessionReuse: false } } : {}),
|
|
78
|
+
...(profileSafety ? {
|
|
79
|
+
safety: { ...profileSafety },
|
|
80
|
+
// A Herdr saved machine launches the remote adapter binary, never runner.command.
|
|
81
|
+
safetySource: { measured: false, ...(input.machine ? {} : { command: input.command }) },
|
|
82
|
+
} : {}),
|
|
79
83
|
...(input.machine ? { machine: input.machine } : {}),
|
|
80
84
|
capabilities: {
|
|
81
85
|
stop: true,
|
|
@@ -131,6 +135,7 @@ export function externalCliReceiptMetadata(input) {
|
|
|
131
135
|
capabilities: { ...runner.capabilities },
|
|
132
136
|
...(machine ? { machine: { ...machine, ...(machine.remoteGit ? { remoteGit: { ...machine.remoteGit } } : {}) } } : {}),
|
|
133
137
|
...(runner.safety ? { safety: { ...runner.safety } } : {}),
|
|
138
|
+
...(runner.safetySource ? { safetySource: { ...runner.safetySource } } : {}),
|
|
134
139
|
...(input.externalProcess ? {
|
|
135
140
|
outputArtifacts: {
|
|
136
141
|
stdoutPath: input.externalProcess.stdoutPath,
|
|
@@ -15,7 +15,9 @@ const MAX_PARSER_LINE_BYTES = 256 * 1024;
|
|
|
15
15
|
const MAX_PARSER_STREAM_BYTES = 32 * 1024 * 1024;
|
|
16
16
|
const MAX_PARSER_OUTPUT_BYTES = 1024 * 1024;
|
|
17
17
|
const MAX_OVERSIZED_LINE_PREFIX_BYTES = 512;
|
|
18
|
-
|
|
18
|
+
// A skipped line keeps only its prefix in memory, and the stream limit still bounds the run.
|
|
19
|
+
// Claude Code puts a read image's base64 in its tool-result line twice.
|
|
20
|
+
const MAX_SKIPPABLE_LINE_BYTES = 8 * 1024 * 1024;
|
|
19
21
|
const PARSER_PROGRESS_INTERVAL_MS = 100;
|
|
20
22
|
export function buildExternalCliPrompt(systemInstructions, task) {
|
|
21
23
|
return `<System instructions>\n${systemInstructions.trim()}\n\n<Task>\n${task}`;
|
|
@@ -196,6 +198,22 @@ export function runExternalCli(input) {
|
|
|
196
198
|
let processTree;
|
|
197
199
|
let processPid;
|
|
198
200
|
let termination;
|
|
201
|
+
// A throwing onProcess fails the run only after the process is stopped and temp paths are removed.
|
|
202
|
+
let callbackFailed = false;
|
|
203
|
+
let callbackError;
|
|
204
|
+
const notifyProcess = (status) => {
|
|
205
|
+
try {
|
|
206
|
+
input.onProcess?.(status);
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (callbackFailed)
|
|
210
|
+
return;
|
|
211
|
+
callbackFailed = true;
|
|
212
|
+
callbackError = error;
|
|
213
|
+
if (!settled && processTree && processPid !== undefined)
|
|
214
|
+
termination ??= terminateExternalProcessTree(processPid, processTree);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
199
217
|
const flushProgress = () => {
|
|
200
218
|
if (!latestProgress)
|
|
201
219
|
return;
|
|
@@ -217,7 +235,7 @@ export function runExternalCli(input) {
|
|
|
217
235
|
progressTimer.unref?.();
|
|
218
236
|
};
|
|
219
237
|
const terminate = (reason) => {
|
|
220
|
-
if (settled || timedOut || stopped || parserError)
|
|
238
|
+
if (settled || timedOut || stopped || parserError || callbackFailed)
|
|
221
239
|
return;
|
|
222
240
|
timedOut = reason === "timeout";
|
|
223
241
|
stopped = reason === "stop";
|
|
@@ -323,7 +341,7 @@ export function runExternalCli(input) {
|
|
|
323
341
|
stderrPath,
|
|
324
342
|
...(input.finalOutputPath ? { finalOutputPath: input.finalOutputPath } : {}),
|
|
325
343
|
};
|
|
326
|
-
|
|
344
|
+
notifyProcess(initialProcess);
|
|
327
345
|
child.stdout.on("data", (chunk) => {
|
|
328
346
|
parseChunk(chunk);
|
|
329
347
|
writeBoundedLog(child.stdout, stdoutStream, chunk, stdoutLog, limits.stdoutLogBytes);
|
|
@@ -380,7 +398,7 @@ export function runExternalCli(input) {
|
|
|
380
398
|
...(stdoutLog.total > stdoutLog.bytes ? { stdoutTruncated: true } : {}),
|
|
381
399
|
...(stderrLog.total > stderrLog.bytes ? { stderrTruncated: true } : {}),
|
|
382
400
|
};
|
|
383
|
-
|
|
401
|
+
notifyProcess(externalProcess);
|
|
384
402
|
const stderr = stderrTail.text().trim();
|
|
385
403
|
const parserFailure = parserError?.message ?? (parserTerminal?.state === "failed" ? parserTerminal.error ?? "External CLI parser reported terminal failure." : undefined);
|
|
386
404
|
const treeFailure = process.platform !== "win32" && treeProof?.state === "unknown"
|
|
@@ -415,11 +433,13 @@ export function runExternalCli(input) {
|
|
|
415
433
|
reject(cleanupError);
|
|
416
434
|
return;
|
|
417
435
|
}
|
|
418
|
-
if (
|
|
436
|
+
if (callbackFailed)
|
|
437
|
+
reject(callbackError);
|
|
438
|
+
else if (streamFailure?.status === "rejected")
|
|
419
439
|
reject(streamFailure.reason);
|
|
420
440
|
else
|
|
421
441
|
resolve(result);
|
|
422
|
-
})();
|
|
442
|
+
})().catch(reject);
|
|
423
443
|
});
|
|
424
444
|
});
|
|
425
445
|
}
|
|
@@ -238,7 +238,8 @@ function openSshSockets(machine, options) {
|
|
|
238
238
|
if (!path.posix.isAbsolute(remotePath))
|
|
239
239
|
throw new Error("Remote socket path must be absolute.");
|
|
240
240
|
const local = path.join(dir, `${name}.sock`);
|
|
241
|
-
|
|
241
|
+
// Some sshd policies drop sessions that run no command (`ssh -N`). The remote command reads the open stdin pipe, so it ends on EOF when the connection closes; a non-tty `sleep` would outlive the forwarder.
|
|
242
|
+
const child = spawn(options.sshBin ?? "ssh", [...herdrSshArgs(options.env), "-o", "StreamLocalBindUnlink=yes", "-L", `${local}:${remotePath}`, machine.target, remoteShellCommand("exec cat >/dev/null")], { env: hardenedSshEnv(options.env), stdio: ["pipe", "ignore", "ignore"], windowsHide: true });
|
|
242
243
|
children.add(child);
|
|
243
244
|
const stop = async () => { await terminateChild(child); children.delete(child); try {
|
|
244
245
|
fs.rmSync(local, { force: true });
|
|
@@ -2,7 +2,7 @@ import type { HerdrMachineReference, PlacementMachineReference } from "../../sha
|
|
|
2
2
|
import { type HerdrForwardedConnection, type HerdrRpcClient } from "./herdr-connection.ts";
|
|
3
3
|
import type { HerdrRunIdentity } from "./herdr-placed-run.ts";
|
|
4
4
|
import { PlacedRunOwner, type PlacedBridgeManifest } from "./placed-run-owner.ts";
|
|
5
|
-
import { type PlacementAgentKind, type PlacementBridgeIdentity, type PlacementEvidenceProof, type PlacementOwnedPane, type PlacementReconnectCheck, type PlacementRunState, type PlacementStartOptions } from "./placement-host.ts";
|
|
5
|
+
import { type PlacementAgentKind, type PlacementBridgeIdentity, type PlacementEvidenceProof, type PlacementOwnedPane, type PlacementPromptOptions, type PlacementReconnectCheck, type PlacementRunState, type PlacementStartOptions } from "./placement-host.ts";
|
|
6
6
|
export interface HerdrPaneCandidate {
|
|
7
7
|
endpoint: {
|
|
8
8
|
session: string | null;
|
|
@@ -43,7 +43,7 @@ export declare const herdrPaneHost: {
|
|
|
43
43
|
owned: PlacementOwnedPane;
|
|
44
44
|
terminalId: string;
|
|
45
45
|
}>;
|
|
46
|
-
prompt(connection: HerdrForwardedConnection, identity: HerdrRunIdentity, text: string): Promise<void>;
|
|
46
|
+
prompt(connection: HerdrForwardedConnection, identity: HerdrRunIdentity, text: string, options?: PlacementPromptOptions): Promise<void>;
|
|
47
47
|
subscribe(connection: HerdrForwardedConnection, paneId: string, listener: (event: unknown) => void, onDisconnect: (error: Error) => void): Promise<() => void>;
|
|
48
48
|
paneEvent(event: unknown, fallback: PlacementRunState): {
|
|
49
49
|
terminalId: unknown;
|
|
@@ -104,7 +104,23 @@ export const herdrPaneHost = {
|
|
|
104
104
|
connect(machine) { return connectHerdrMachine(asHerdrMachine(machine)); },
|
|
105
105
|
sessionOf(connection) { return connection.endpoint.session; },
|
|
106
106
|
async launch(connection, machine, runId, runtimeDir, request, onPane, options) { const owned = await provisionHerdrOwnedPane(connection, asHerdrMachine(machine), runId, runtimeDir, request.environment); await onPane(owned); const { terminalId } = await startHerdrAgent(connection, owned, request.kind, request.name, request.args, options); return { owned, terminalId }; },
|
|
107
|
-
async prompt(connection, identity, text
|
|
107
|
+
async prompt(connection, identity, text, options = {}) {
|
|
108
|
+
// Herdr registers a started agent's name asynchronously, so a prompt right after start can be refused; a refused prompt was not delivered.
|
|
109
|
+
const clock = options.clock ?? { now: () => Date.now(), wait: (ms) => new Promise((resolve) => setTimeout(resolve, ms)) }, deadline = clock.now() + (options.timeoutMs ?? 5_000), pollMs = options.pollMs ?? 100;
|
|
110
|
+
for (;;) {
|
|
111
|
+
try {
|
|
112
|
+
await connection.client.call("agent.prompt", { target: identity.agentName, text });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
if (!(error instanceof Error) || !error.message.includes("is not an active named agent") || clock.now() >= deadline)
|
|
117
|
+
throw error;
|
|
118
|
+
await clock.wait(Math.min(pollMs, deadline - clock.now()));
|
|
119
|
+
if (options.stopped?.())
|
|
120
|
+
throw new Error("Remote Pi prompt was not sent because the run was stopped.", { cause: error });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
108
124
|
subscribe(connection, paneId, listener, onDisconnect) { return connection.client.subscribe(herdrStatusSubscriptions(paneId), listener, onDisconnect); },
|
|
109
125
|
paneEvent(event, fallback) { const data = event && typeof event === "object" ? event.data : undefined; return data ? { terminalId: data.terminal_id, paneId: data.pane_id, state: herdrRunState(data.agent_status, fallback) } : undefined; },
|
|
110
126
|
async panes(connection) { return { endpoint: connection.endpoint, agents: snapshotAgents(parseHerdrSessionSnapshot(await connection.client.call("session.snapshot"))) }; },
|
|
@@ -7,6 +7,7 @@ import { herdrPaneHost, HerdrPlacedRunOwner } from "./herdr-pane-host.js";
|
|
|
7
7
|
import { encodeHerdrPiFrame, HERDR_PI_MODE_ENV, HERDR_PI_PROTOCOL, HERDR_PI_RUN_ENV, HERDR_PI_RUNTIME_DIR_ENV, HerdrPiFrameDecoder, validateHerdrPiRunId } from "./herdr-pi-protocol.js";
|
|
8
8
|
import { discoverPlacedBridgeManifest } from "./placed-run-owner.js";
|
|
9
9
|
import { RexPlacedRunOwner } from "./rex-pane-host.js";
|
|
10
|
+
import { ensureSupervisorChannelDir } from "../../intercom/native-supervisor-channel.js";
|
|
10
11
|
import { isRexLocalMachine } from "./rex-machine.js";
|
|
11
12
|
import { PLACED_RESTORE_UNSUPPORTED } from "./herdr-machine.js";
|
|
12
13
|
/** The pane half comes from the host; the bridge half (run, package, protocol, native session, evidence cursor) is host-neutral. */
|
|
@@ -136,21 +137,35 @@ export class HerdrPiSession {
|
|
|
136
137
|
#reconnectFactory;
|
|
137
138
|
#reconnectFailure;
|
|
138
139
|
#replyTimer;
|
|
140
|
+
#repliesInFlight = new Set();
|
|
139
141
|
supervisorDir;
|
|
140
142
|
runtime;
|
|
141
143
|
owner;
|
|
142
144
|
constructor(owner, bridgeForward, bridge, requestedTools, model, runtime, initialGit) { this.owner = owner; this.bridgeForward = bridgeForward; this.bridge = bridge; this.requestedTools = requestedTools; this.model = model; this.runtime = runtime; this.supervisorDir = runtime.supervisorChannelDir; this.#initialGit = initialGit; bridge.adopt((frame) => this.#frame(frame)); if (this.supervisorDir) {
|
|
143
|
-
this.#replyTimer = setInterval(() =>
|
|
144
|
-
const file = path.join(replies, name);
|
|
145
|
-
try {
|
|
146
|
-
const value = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
147
|
-
if (typeof value.message === "string" && typeof value.requestId === "string")
|
|
148
|
-
void this.#operation("supervisor-reply", value.message, value.requestId, typeof value.error === "string" ? value.error : undefined).then(() => fs.rmSync(file, { force: true }));
|
|
149
|
-
}
|
|
150
|
-
catch { }
|
|
151
|
-
} }, 50);
|
|
145
|
+
this.#replyTimer = setInterval(() => this.#deliverSupervisorReplies(this.supervisorDir), 50);
|
|
152
146
|
this.#replyTimer.unref?.();
|
|
153
147
|
} }
|
|
148
|
+
// Runs on a timer, where a throw or an unhandled rejection exits Pi. A reply that can't be read or delivered stays
|
|
149
|
+
// on disk for the next tick, once its earlier delivery has settled; a lost transport reaches the session through the
|
|
150
|
+
// bridge failure.
|
|
151
|
+
#deliverSupervisorReplies(supervisorDir) { const replies = path.join(supervisorDir, "replies"); let names; try {
|
|
152
|
+
names = fs.existsSync(replies) ? fs.readdirSync(replies) : [];
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return;
|
|
156
|
+
} for (const name of names) {
|
|
157
|
+
const file = path.join(replies, name);
|
|
158
|
+
if (this.#repliesInFlight.has(file))
|
|
159
|
+
continue;
|
|
160
|
+
try {
|
|
161
|
+
const value = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
162
|
+
if (typeof value.message === "string" && typeof value.requestId === "string") {
|
|
163
|
+
this.#repliesInFlight.add(file);
|
|
164
|
+
void this.#operation("supervisor-reply", value.message, value.requestId, typeof value.error === "string" ? value.error : undefined).then(() => fs.rmSync(file, { force: true })).catch(() => { }).finally(() => this.#repliesInFlight.delete(file));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch { }
|
|
168
|
+
} }
|
|
154
169
|
get host() { return this.owner.host; }
|
|
155
170
|
get identity() { return this.owner.identity; }
|
|
156
171
|
set identity(value) { this.owner.identity = value; }
|
|
@@ -218,23 +233,34 @@ export class HerdrPiSession {
|
|
|
218
233
|
for (const listener of this.#listeners)
|
|
219
234
|
listener({ type: "agent_settled" });
|
|
220
235
|
} }
|
|
221
|
-
#relaySupervisor(frame) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
236
|
+
#relaySupervisor(frame) {
|
|
237
|
+
if (!this.supervisorDir || typeof frame.requestId !== "string")
|
|
238
|
+
return;
|
|
239
|
+
const reason = frame.reason;
|
|
240
|
+
if (reason !== "need_decision" && reason !== "interview_request" && reason !== "progress_update")
|
|
241
|
+
return;
|
|
242
|
+
const createdAt = Date.now();
|
|
243
|
+
const file = path.join(this.supervisorDir, "requests", `${path.basename(frame.requestId)}.json`);
|
|
244
|
+
const request = { type: "subagent.supervisor.request", id: frame.requestId, createdAt, ...(reason !== "progress_update" ? { expiresAt: createdAt + 10 * 60_000 } : {}), reason, message: typeof frame.message === "string" ? frame.message : "", ...(frame.interview && typeof frame.interview === "object" ? { interview: frame.interview } : {}), expectsReply: reason !== "progress_update", runId: this.runtime.runId ?? this.identity.runId, agent: this.runtime.agent ?? "remote", childIndex: this.runtime.childIndex ?? 0, orchestratorSessionId: this.runtime.orchestratorSessionId };
|
|
245
|
+
// The parent's stale-channel cleanup removes an idle channel's empty directories after a minute.
|
|
246
|
+
ensureSupervisorChannelDir(this.supervisorDir);
|
|
247
|
+
try {
|
|
248
|
+
fs.writeFileSync(file, JSON.stringify(request), { mode: 0o600, flag: "wx" });
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
if (error.code !== "EEXIST")
|
|
252
|
+
throw error;
|
|
253
|
+
const existing = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
254
|
+
if (existing.id !== frame.requestId || existing.reason !== reason)
|
|
255
|
+
throw new Error("Supervisor relay identity changed during replay.");
|
|
256
|
+
}
|
|
257
|
+
if (reason === "progress_update")
|
|
258
|
+
this.bridge.supervisorDelivered(frame.requestId);
|
|
225
259
|
}
|
|
226
|
-
catch (error) {
|
|
227
|
-
if (error.code !== "EEXIST")
|
|
228
|
-
throw error;
|
|
229
|
-
const existing = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
230
|
-
if (existing.id !== frame.requestId || existing.reason !== reason)
|
|
231
|
-
throw new Error("Supervisor relay identity changed during replay.");
|
|
232
|
-
} if (reason === "progress_update")
|
|
233
|
-
this.bridge.supervisorDelivered(frame.requestId); }
|
|
234
260
|
async #operation(operation, text, supervisorId, supervisorError) { const requestId = `${++this.#sequence}_${randomBytes(5).toString("hex")}`; let completion = Promise.resolve(); if (operation === "prompt")
|
|
235
261
|
completion = new Promise((resolve, reject) => this.#operations.set(requestId, { resolve, reject, accepted: false, settled: false })); try {
|
|
236
262
|
await Promise.race([this.bridge.prepare(requestId, operation, text, supervisorId, supervisorError), this.bridge.failure]);
|
|
237
|
-
await this.host.prompt(this.connection, this.identity, `/pi-subagents-bridge ${requestId}
|
|
263
|
+
await this.host.prompt(this.connection, this.identity, `/pi-subagents-bridge ${requestId}`, operation === "abort" ? {} : { stopped: () => this.#aborted || this.#disposed });
|
|
238
264
|
await completion;
|
|
239
265
|
}
|
|
240
266
|
catch (error) {
|
|
@@ -8,7 +8,6 @@ export declare const WORKFLOW_LANE_OUTPUT_PATHS_MAX = 10;
|
|
|
8
8
|
export declare const WORKTREE_STATUS_PATH_MAX_BYTES = 4096;
|
|
9
9
|
export declare const WORKTREE_STATUS_BRANCH_MAX_BYTES = 256;
|
|
10
10
|
export declare const WORKTREE_STATUS_NAMING_LABEL_MAX_BYTES = 256;
|
|
11
|
-
/** Normalize and validate launch-declared lane metadata. */
|
|
12
11
|
export declare function normalizeWorkflowLaneMetadata(value: unknown, label?: string): WorkflowLaneMetadata | undefined;
|
|
13
12
|
export declare function assertWorkflowLaneKey(lane: WorkflowLaneMetadata | undefined, workflowKey: string | undefined, label?: string): void;
|
|
14
13
|
export interface WorktreeStatusReference {
|
|
@@ -43,7 +43,6 @@ function boundedStringArray(value, label, maxItems, maxBytes) {
|
|
|
43
43
|
return boundedNonEmptyString(entry, `${label}[${index}]`, maxBytes);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
/** Normalize and validate launch-declared lane metadata. */
|
|
47
46
|
export function normalizeWorkflowLaneMetadata(value, label = "lane") {
|
|
48
47
|
if (value === undefined)
|
|
49
48
|
return undefined;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
const BUILTIN_TOOL_NAMES = new Set(["read", "bash", "edit", "write", "grep", "find", "ls", "mcp"]);
|
|
2
2
|
export function normalizeMcpDirectToolSelectors(selectors) {
|
|
3
|
-
return [...new Set((selectors ?? []).map(
|
|
3
|
+
return [...new Set((selectors ?? []).map(trimTrailingSlashes).filter(Boolean))];
|
|
4
|
+
}
|
|
5
|
+
/** A `/+$/` replace rescans the selector from every index when the string ends in anything else. */
|
|
6
|
+
function trimTrailingSlashes(selector) {
|
|
7
|
+
let end = selector.length;
|
|
8
|
+
while (end > 0 && selector[end - 1] === "/")
|
|
9
|
+
end -= 1;
|
|
10
|
+
return selector.slice(0, end);
|
|
4
11
|
}
|
|
5
12
|
export function parseMcpDirectToolSelectors(selectors) {
|
|
6
13
|
const servers = new Set();
|
|
@@ -12,7 +12,6 @@ export { splitThinkingSuffix };
|
|
|
12
12
|
* to, so the virtual selection's provider/id is compared exactly with the launch candidate instead.
|
|
13
13
|
*/
|
|
14
14
|
export declare function formatSubagentModelVerificationError(expectedModel: string, observedModel: string, availableModels: AvailableModelInfo[] | undefined, modelResponseAliases?: Record<string, string[]>, observedVirtualModel?: string): string | undefined;
|
|
15
|
-
/** Sentinel model value requesting that a subagent inherit the parent session's model. */
|
|
16
15
|
export declare const INHERIT_MODEL = "inherit";
|
|
17
16
|
/** Minimal shape of the parent session's in-memory model (`ctx.model`). */
|
|
18
17
|
export interface ParentModel {
|
|
@@ -56,6 +55,8 @@ export declare function fuzzyResolveModel(baseModel: string, availableModels: Av
|
|
|
56
55
|
* query.
|
|
57
56
|
*/
|
|
58
57
|
export declare function resolveModelCandidate(model: string | undefined, availableModels: AvailableModelInfo[] | undefined, preferredProvider?: string): string | undefined;
|
|
58
|
+
/** A configured pin that launch refuses because the registry cannot resolve it. An empty registry checks nothing. */
|
|
59
|
+
export declare function isUnavailableSubagentModel(model: string | undefined, availableModels: AvailableModelInfo[] | undefined, preferredProvider?: string): boolean;
|
|
59
60
|
export interface ResolveSubagentModelOverrideOptions {
|
|
60
61
|
/** When set with `enforce: true`, out-of-scope models are rejected. */
|
|
61
62
|
scope?: ModelScopeCheckRule | ModelScopeCheckRule[];
|
|
@@ -90,7 +91,6 @@ export interface ResolveModelSelectionOptions {
|
|
|
90
91
|
onWarn?: (violation: ModelScopeViolation) => void;
|
|
91
92
|
/** The primary model came from the running parent session, not configuration. */
|
|
92
93
|
primaryModelFromParent?: boolean;
|
|
93
|
-
/** How the model was selected. */
|
|
94
94
|
origin?: ModelOrigin;
|
|
95
95
|
}
|
|
96
96
|
export declare function resolveModelOrigin(input: {
|
|
@@ -31,7 +31,6 @@ export function formatSubagentModelVerificationError(expectedModel, observedMode
|
|
|
31
31
|
}
|
|
32
32
|
return `model_verification_failed: native Pi child reported a different model than the launch candidate. Expected '${expectedModel}' but observed '${observedModel}'. If you have independently verified this response ID identifies the requested model, declare the exact mapping in modelResponseAliases in ~/.pi/agent/extensions/subagent/config.json (see docs/configuration.md#modelresponsealiases). Use the resolved provider/model ID without its thinking suffix as the key. This leaves the outgoing request unchanged. Configuration changes affect new independent native runs; resumed native runs retain their launch-time declaration. External CLI adapters do not use this setting.`;
|
|
33
33
|
}
|
|
34
|
-
/** Sentinel model value requesting that a subagent inherit the parent session's model. */
|
|
35
34
|
export const INHERIT_MODEL = "inherit";
|
|
36
35
|
export function normalizeParentModel(model) {
|
|
37
36
|
if (!model || typeof model !== "object")
|
|
@@ -257,6 +256,13 @@ function closestModelCandidates(model, availableModels) {
|
|
|
257
256
|
.slice(0, MAX_MODEL_CANDIDATES)
|
|
258
257
|
.map((entry) => `${entry.fullId}${thinkingSuffix}`);
|
|
259
258
|
}
|
|
259
|
+
/** A configured pin that launch refuses because the registry cannot resolve it. An empty registry checks nothing. */
|
|
260
|
+
export function isUnavailableSubagentModel(model, availableModels, preferredProvider) {
|
|
261
|
+
const trimmed = model?.trim();
|
|
262
|
+
if (!trimmed || trimmed === INHERIT_MODEL || !availableModels?.length)
|
|
263
|
+
return false;
|
|
264
|
+
return resolveSubagentModelCandidate(trimmed, availableModels, preferredProvider) === undefined;
|
|
265
|
+
}
|
|
260
266
|
function resolveRequiredSubagentModelCandidate(model, availableModels, preferredProvider) {
|
|
261
267
|
const resolved = resolveSubagentModelCandidate(model, availableModels, preferredProvider);
|
|
262
268
|
if (resolved)
|
|
@@ -8,9 +8,6 @@
|
|
|
8
8
|
* inherited from agent frontmatter / `defaultModel` / the parent session only
|
|
9
9
|
* emits a warning so existing configurations keep working. Optional strict
|
|
10
10
|
* enforcement makes inherited models hard errors too.
|
|
11
|
-
*
|
|
12
|
-
* The decision logic ({@link checkModelScope}) is a pure function of its
|
|
13
|
-
* inputs so it can be unit-tested without touching the filesystem or config.
|
|
14
11
|
*/
|
|
15
12
|
export interface ModelScopeRule {
|
|
16
13
|
enforce?: boolean;
|
|
@@ -60,8 +57,7 @@ export declare function resolveModelScopesForAgent(config: ModelScopeConfig | un
|
|
|
60
57
|
} | undefined, scopedModelIds?: readonly string[]): ResolvedModelScope[];
|
|
61
58
|
/**
|
|
62
59
|
* Validate and normalize a raw `subagents.modelScope` value from settings.
|
|
63
|
-
* Throws a descriptive error for malformed configs
|
|
64
|
-
* settings-parsing style). Returns `undefined` when the field is absent.
|
|
60
|
+
* Throws a descriptive error for malformed configs. Returns `undefined` when the field is absent.
|
|
65
61
|
*/
|
|
66
62
|
export declare function parseModelScopeConfig(value: unknown, meta: {
|
|
67
63
|
filePath: string;
|
|
@@ -8,9 +8,6 @@
|
|
|
8
8
|
* inherited from agent frontmatter / `defaultModel` / the parent session only
|
|
9
9
|
* emits a warning so existing configurations keep working. Optional strict
|
|
10
10
|
* enforcement makes inherited models hard errors too.
|
|
11
|
-
*
|
|
12
|
-
* The decision logic ({@link checkModelScope}) is a pure function of its
|
|
13
|
-
* inputs so it can be unit-tested without touching the filesystem or config.
|
|
14
11
|
*/
|
|
15
12
|
import { splitKnownThinkingSuffix } from "../../shared/model-info.js";
|
|
16
13
|
export const SCOPED_PATTERN = "scoped";
|
|
@@ -140,8 +137,7 @@ export function resolveModelScopesForAgent(config, agentName, parentModel, scope
|
|
|
140
137
|
}
|
|
141
138
|
/**
|
|
142
139
|
* Validate and normalize a raw `subagents.modelScope` value from settings.
|
|
143
|
-
* Throws a descriptive error for malformed configs
|
|
144
|
-
* settings-parsing style). Returns `undefined` when the field is absent.
|
|
140
|
+
* Throws a descriptive error for malformed configs. Returns `undefined` when the field is absent.
|
|
145
141
|
*/
|
|
146
142
|
export function parseModelScopeConfig(value, meta) {
|
|
147
143
|
if (value === undefined)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ArtifactPaths, TimeoutRecoveryProjection, TimeoutRecoverySummary, TrackedMutationEvidence, TrackedMutationSnapshot } from "../../shared/types.ts";
|
|
2
2
|
export declare function snapshotTrackedMutations(cwd: string): TrackedMutationSnapshot;
|
|
3
|
-
export declare function collectTrackedMutationEvidence(snapshot: TrackedMutationSnapshot, cwd?: string): TrackedMutationEvidence
|
|
3
|
+
export declare function collectTrackedMutationEvidence(snapshot: TrackedMutationSnapshot, cwd?: string): Promise<TrackedMutationEvidence>;
|
|
4
4
|
/** Keep status and completion details to bounded routing evidence, not raw output or effects. */
|
|
5
5
|
export declare function projectTimeoutRecovery(value: unknown): TimeoutRecoveryProjection | undefined;
|
|
6
6
|
/** Render only the bounded recovery route needed by a parent/operator. */
|