@xzzpig/pi-subagents 0.18.0 → 0.20.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 +129 -0
- package/README.md +1 -1
- package/docs/agents.md +32 -16
- package/docs/configuration.md +76 -9
- package/docs/extension-api.md +6 -5
- package/docs/missions.md +28 -14
- package/docs/models.md +8 -4
- package/docs/observability.md +10 -5
- package/docs/standalone-background.md +1 -1
- package/docs/tool-reference.md +90 -88
- package/docs/workflows.md +171 -173
- package/node_modules/@xzzpig/pi-components/package.json +4 -4
- package/package.json +6 -6
- package/prompts/review-loop.md +1 -1
- package/skills/council-mode/SKILL.md +1 -1
- package/skills/pi-subagents/SKILL.md +12 -5
- package/skills/pi-subagents/references/constraints-and-recipes.md +3 -3
- package/skills/pi-subagents/references/execution-controls.md +68 -67
- package/skills/pi-subagents/references/management-authoring-rpc.md +2 -2
- package/skills/pi-subagents/references/multi-lane-orchestration.md +1 -1
- package/skills/pi-subagents/references/prompting-and-roles.md +45 -48
- package/src/agents/advertised-agent-prompt.ts +21 -41
- package/src/agents/agent-management.ts +2 -2
- package/src/agents/agents.ts +66 -3
- package/src/api/preflight.ts +109 -63
- package/src/extension/config.ts +15 -4
- package/src/extension/control-notices.ts +3 -0
- package/src/extension/doctor.ts +1 -0
- package/src/extension/fanout-child.ts +12 -3
- package/src/extension/herdr-pi-bridge.ts +2 -0
- package/src/extension/index.ts +90 -174
- package/src/extension/public-execution.ts +72 -35
- package/src/extension/reply-workflow-script.ts +58 -0
- package/src/extension/rpc.ts +29 -10
- package/src/extension/schemas.ts +40 -135
- package/src/extension/tool-activation.ts +57 -108
- package/src/extension/tool-description.ts +62 -27
- package/src/extension/upgrade-notice.ts +40 -0
- package/src/integrations/herdr-status.ts +19 -3
- package/src/intercom/native-supervisor-channel.ts +4 -1
- package/src/missions/goal-driver.ts +44 -31
- package/src/missions/store.ts +10 -1
- package/src/profiles/profiles.ts +5 -2
- package/src/runs/background/async-execution.ts +146 -59
- package/src/runs/background/async-job-tracker.ts +66 -24
- package/src/runs/background/async-retention.ts +46 -16
- package/src/runs/background/await-async-run.ts +78 -0
- package/src/runs/background/chain-root-attachment.ts +4 -4
- package/src/runs/background/control-channel.ts +61 -2
- package/src/runs/background/notify.ts +5 -0
- package/src/runs/background/run-child-session.ts +17 -7
- package/src/runs/background/run-status.ts +6 -0
- package/src/runs/background/runner-aliases.ts +37 -6
- package/src/runs/background/runner-child-launch.ts +3 -0
- package/src/runs/background/scheduled-runs.ts +33 -18
- package/src/runs/background/stale-run-reconciler.ts +13 -2
- package/src/runs/background/subagent-runner.ts +58 -5
- package/src/runs/foreground/async-stop-action.ts +17 -3
- package/src/runs/foreground/command-action.ts +41 -0
- package/src/runs/foreground/execution.ts +145 -131
- package/src/runs/foreground/subagent-executor.ts +546 -296
- package/src/runs/shared/async-status-projection.ts +5 -0
- package/src/runs/shared/child-commands.ts +228 -0
- package/src/runs/shared/child-launch.ts +15 -2
- package/src/runs/shared/child-session.ts +184 -24
- package/src/runs/shared/child-tool-plan.ts +16 -4
- package/src/runs/shared/claude-code-adapter.ts +157 -2
- package/src/runs/shared/dynamic-fanout.ts +2 -2
- package/src/runs/shared/external-cli-preflight.ts +54 -6
- package/src/runs/shared/external-cli-runner.ts +5 -1
- package/src/runs/shared/mcp-config-sources.ts +2 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +104 -11
- package/src/runs/shared/model-resolution.ts +38 -10
- package/src/runs/shared/model-scope.ts +28 -9
- package/src/runs/shared/nested-events.ts +55 -55
- package/src/runs/shared/parallel-utils.ts +4 -0
- package/src/runs/shared/pi-spawn.ts +7 -95
- package/src/runs/shared/run-history.ts +87 -0
- package/src/runs/shared/subagent-control.ts +32 -17
- package/src/runs/shared/subagent-prompt-runtime.ts +14 -6
- package/src/runs/shared/worktree.ts +1 -1
- package/src/shared/disabled-features.ts +123 -0
- package/src/shared/extension-context.ts +13 -0
- package/src/shared/model-info.ts +9 -0
- package/src/shared/required-child-extensions.ts +39 -5
- package/src/shared/settings.ts +1 -1
- package/src/shared/types.ts +27 -1
- package/src/slash/prompt-template-bridge.ts +2 -2
- package/src/slash/slash-commands.ts +10 -5
- package/src/slash/subagent-cost.ts +9 -5
- package/src/slash/subagents-admin.ts +24 -24
- package/src/tui/fleet-status.ts +14 -6
- package/src/tui/fleet.ts +14 -2
- package/src/tui/render.ts +117 -56
- package/src/tui/running-tone.ts +28 -0
- package/src/watchdog/diff-tool.ts +23 -9
- package/src/watchdog/register-child.ts +3 -3
- package/src/watchdog/register-main.ts +3 -3
- package/src/watchdog/review.ts +2 -2
- package/src/watchdog/turn-delta.ts +1 -1
- package/src/workflows/chat-progress.ts +2 -2
- package/src/workflows/scripted-workflow.ts +117 -37
- package/src/workflows/structured-workflow-scripts.ts +177 -0
- package/src/workflows/workflow-checklist.ts +6 -0
- package/src/workflows/workflow-receipt.ts +10 -4
- package/src/workflows/workflow-resources.ts +44 -16
- package/src/workflows/workflow-reuse.ts +120 -0
- package/src/workflows/workflow-revival.ts +123 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
+
import { resolveNodeExecutable } from "../../shared/node-executable.ts";
|
|
4
5
|
|
|
5
6
|
const MAX_PROBE_OUTPUT_BYTES = 256 * 1024;
|
|
6
7
|
const MAX_PROBE_TIMEOUT_MS = 5_000;
|
|
@@ -40,20 +41,28 @@ export type ExternalCliBinaryAvailability =
|
|
|
40
41
|
| { available: true }
|
|
41
42
|
| { available: false; unavailableReason: string };
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
const BATCH_FILE = /\.(cmd|bat)$/i;
|
|
45
|
+
|
|
46
|
+
function resolveBinary(command: string, env: NodeJS.ProcessEnv, platform: NodeJS.Platform = process.platform): string {
|
|
47
|
+
const windows = platform === "win32";
|
|
48
|
+
if (path.isAbsolute(command) || command.includes(path.sep) || (windows && command.includes("/"))) {
|
|
45
49
|
const resolved = path.resolve(command);
|
|
46
50
|
fs.accessSync(resolved, fs.constants.X_OK);
|
|
47
51
|
return resolved;
|
|
48
52
|
}
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
// Windows environment names are case-insensitive, and a copied process.env keeps its spelling (often `Path`).
|
|
54
|
+
const read = (name: string) => windows ? Object.entries(env).find(([key]) => key.toUpperCase() === name)?.[1] : env[name];
|
|
55
|
+
const pathExt = windows ? (read("PATHEXT") ?? ".EXE;.CMD;.BAT;.COM").split(";").filter(Boolean) : [];
|
|
56
|
+
const named = pathExt.some((extension) => command.toLowerCase().endsWith(extension.toLowerCase()));
|
|
57
|
+
const extensions = windows ? (named ? ["", ...pathExt] : pathExt) : [""];
|
|
58
|
+
for (const directory of (read("PATH") ?? "").split(path.delimiter)) {
|
|
51
59
|
if (!directory) continue;
|
|
52
60
|
for (const extension of extensions) {
|
|
53
61
|
const candidate = path.join(directory, `${command}${extension}`);
|
|
54
62
|
try {
|
|
55
63
|
fs.accessSync(candidate, fs.constants.X_OK);
|
|
56
|
-
|
|
64
|
+
// A batch shim resolves its target from its own directory (%dp0%), so keep the path it was found at.
|
|
65
|
+
return windows && BATCH_FILE.test(candidate) ? candidate : fs.realpathSync(candidate);
|
|
57
66
|
} catch {}
|
|
58
67
|
}
|
|
59
68
|
}
|
|
@@ -71,8 +80,47 @@ export function resolveExternalCliBinaryAvailability(command: string, env: NodeJ
|
|
|
71
80
|
}
|
|
72
81
|
}
|
|
73
82
|
|
|
83
|
+
// npm's cmd-shim output for a `#!/usr/bin/env node` bin, with CRLF normalized; the target path sits between the two parts.
|
|
84
|
+
const NPM_NODE_SHIM_HEAD = '@ECHO off\nGOTO start\n:find_dp0\nSET dp0=%~dp0\nEXIT /b\n:start\nSETLOCAL\nCALL :find_dp0\n\nIF EXIST "%dp0%\\node.exe" (\n SET "_prog=%dp0%\\node.exe"\n) ELSE (\n SET "_prog=node"\n SET PATHEXT=%PATHEXT:;.JS;=;%\n)\n\nendLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\\';
|
|
85
|
+
const NPM_NODE_SHIM_TAIL = '" %*\n';
|
|
86
|
+
|
|
87
|
+
export interface ExternalCliSpawn {
|
|
88
|
+
command: string;
|
|
89
|
+
args: readonly string[];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Node refuses to spawn `.cmd`/`.bat` files without a shell (CVE-2024-27980), and a shell would expand
|
|
94
|
+
* `%` and `!` inside operator- and project-controlled arguments. On Windows, an npm Node shim is launched
|
|
95
|
+
* by running Node on its script directly; every other batch wrapper is rejected.
|
|
96
|
+
*/
|
|
97
|
+
export function resolveExternalCliSpawn(command: string, args: readonly string[], env: NodeJS.ProcessEnv, platform: NodeJS.Platform = process.platform): ExternalCliSpawn {
|
|
98
|
+
const unchanged = { command, args };
|
|
99
|
+
if (platform !== "win32") return unchanged;
|
|
100
|
+
let resolved: string;
|
|
101
|
+
try {
|
|
102
|
+
resolved = resolveBinary(command, env, platform);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
if (BATCH_FILE.test(command)) throw error;
|
|
105
|
+
return unchanged;
|
|
106
|
+
}
|
|
107
|
+
if (!BATCH_FILE.test(resolved)) return unchanged;
|
|
108
|
+
const shim = fs.readFileSync(resolved, "utf-8").replace(/\r\n/g, "\n");
|
|
109
|
+
const target = /\.cmd$/i.test(resolved) && shim.startsWith(NPM_NODE_SHIM_HEAD) && shim.endsWith(NPM_NODE_SHIM_TAIL)
|
|
110
|
+
? shim.slice(NPM_NODE_SHIM_HEAD.length, shim.length - NPM_NODE_SHIM_TAIL.length)
|
|
111
|
+
: "";
|
|
112
|
+
const directory = path.dirname(resolved);
|
|
113
|
+
const script = path.resolve(directory, target.split("\\").join(path.sep));
|
|
114
|
+
if (!target || /^\\|["%:/\n]/.test(target) || !fs.statSync(script, { throwIfNoEntry: false })?.isFile()) {
|
|
115
|
+
throw new Error(`External CLI '${resolved}' is a batch wrapper that cannot run without a shell. On Windows, only npm-generated Node shims and .exe files can launch.`);
|
|
116
|
+
}
|
|
117
|
+
const bundledNode = path.join(directory, "node.exe");
|
|
118
|
+
return { command: fs.existsSync(bundledNode) ? bundledNode : resolveNodeExecutable(), args: [script, ...args] };
|
|
119
|
+
}
|
|
120
|
+
|
|
74
121
|
function probeWithTimeout(binaryPath: string, args: readonly string[], env: NodeJS.ProcessEnv, label: string, timeoutMs: number, cwd?: string): string {
|
|
75
|
-
const
|
|
122
|
+
const launch = resolveExternalCliSpawn(binaryPath, args, env);
|
|
123
|
+
const result = spawnSync(launch.command, launch.args, {
|
|
76
124
|
cwd,
|
|
77
125
|
env,
|
|
78
126
|
encoding: "utf-8",
|
|
@@ -10,8 +10,10 @@ import { omitGitRoutingEnv } from "./git-environment.ts";
|
|
|
10
10
|
import {
|
|
11
11
|
invalidateExternalCliPreflight,
|
|
12
12
|
preflightExternalCli,
|
|
13
|
+
resolveExternalCliSpawn,
|
|
13
14
|
type ExternalCliPreflightResult,
|
|
14
15
|
type ExternalCliPreflightSpec,
|
|
16
|
+
type ExternalCliSpawn,
|
|
15
17
|
} from "./external-cli-preflight.ts";
|
|
16
18
|
|
|
17
19
|
const MAX_OUTPUT_TAIL_BYTES = 64 * 1024;
|
|
@@ -198,6 +200,7 @@ export function runExternalCli(input: {
|
|
|
198
200
|
};
|
|
199
201
|
const env = externalEnvironment(input.environment?.allowlist, input.environment?.values);
|
|
200
202
|
let preflight: ExternalCliPreflightResult | undefined;
|
|
203
|
+
let launch: ExternalCliSpawn;
|
|
201
204
|
try {
|
|
202
205
|
for (const directory of input.temporaryDirectories ?? []) {
|
|
203
206
|
fs.mkdirSync(directory, { mode: 0o700 });
|
|
@@ -210,6 +213,7 @@ export function runExternalCli(input: {
|
|
|
210
213
|
finally { fs.closeSync(promptDescriptor); }
|
|
211
214
|
}
|
|
212
215
|
if (input.preflight) preflight = preflightExternalCli(input.command, input.preflight, env, input.cwd);
|
|
216
|
+
launch = resolveExternalCliSpawn(preflight?.binaryPath ?? input.command, input.args ?? [], env);
|
|
213
217
|
} catch (error) {
|
|
214
218
|
const endedAt = Date.now();
|
|
215
219
|
const externalProcess = { startedAt, endedAt, durationMs: endedAt - startedAt, exitCode: 1, processSignal: null, stdoutPath, stderrPath, ...(input.finalOutputPath ? { finalOutputPath: input.finalOutputPath } : {}) } satisfies ExternalProcessStatus;
|
|
@@ -329,7 +333,7 @@ export function runExternalCli(input: {
|
|
|
329
333
|
}
|
|
330
334
|
appendPendingLine(chunk.subarray(start));
|
|
331
335
|
};
|
|
332
|
-
const child = spawn(
|
|
336
|
+
const child = spawn(launch.command, launch.args, {
|
|
333
337
|
cwd: input.cwd,
|
|
334
338
|
env,
|
|
335
339
|
stdio: ["pipe", "pipe", "pipe"],
|
|
@@ -40,6 +40,7 @@ export interface McpServerDefinition {
|
|
|
40
40
|
httpTransport?: string;
|
|
41
41
|
pluginDataDir?: string;
|
|
42
42
|
literalEnv?: boolean;
|
|
43
|
+
inheritEnv?: boolean;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export function isMcpServerDefinition(value: unknown): value is McpServerDefinition {
|
|
@@ -53,7 +54,7 @@ export function isMcpServerDefinition(value: unknown): value is McpServerDefinit
|
|
|
53
54
|
for (const field of ["env", "headers"] as const) {
|
|
54
55
|
if (value[field] !== undefined && !isStringRecord(value[field])) return false;
|
|
55
56
|
}
|
|
56
|
-
for (const field of ["exposeResources", "literalEnv"] as const) {
|
|
57
|
+
for (const field of ["exposeResources", "literalEnv", "inheritEnv"] as const) {
|
|
57
58
|
if (value[field] !== undefined && typeof value[field] !== "boolean") return false;
|
|
58
59
|
}
|
|
59
60
|
if (value.requestHeadersCommand !== undefined && !isRequestHeadersCommand(value.requestHeadersCommand)) return false;
|
|
@@ -67,6 +67,17 @@ export interface McpRuntimeSnapshotHost {
|
|
|
67
67
|
events: {
|
|
68
68
|
emit(event: string, request: McpRuntimeSnapshotRequest): void;
|
|
69
69
|
};
|
|
70
|
+
getAllTools?(): readonly McpHostToolInfo[];
|
|
71
|
+
getCommands?(): readonly { name: string; sourceInfo: { path: string } }[];
|
|
72
|
+
/** Pi 0.99: servers extensions added with `pi.registerMcpServer()`. */
|
|
73
|
+
getMcpServers?(): readonly { name: string }[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A `pi.getAllTools()` entry; `exposure` and `namespace` exist only from Pi 0.99. */
|
|
77
|
+
export interface McpHostToolInfo {
|
|
78
|
+
name: string;
|
|
79
|
+
exposure?: string;
|
|
80
|
+
namespace?: { name: string };
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
interface CachedTool {
|
|
@@ -96,6 +107,8 @@ export interface McpDirectToolResolution {
|
|
|
96
107
|
/** Normal loaded config plus the selected runtime server definitions. */
|
|
97
108
|
mcpConfig?: McpConfig;
|
|
98
109
|
runtimeServerNames?: string[];
|
|
110
|
+
/** Set when the selectors were resolved against Pi's built-in MCP instead of pi-mcp-adapter. */
|
|
111
|
+
builtin?: true;
|
|
99
112
|
}
|
|
100
113
|
|
|
101
114
|
export function resolveMcpDirectToolResolution(
|
|
@@ -106,6 +119,9 @@ export function resolveMcpDirectToolResolution(
|
|
|
106
119
|
): McpDirectToolResolution {
|
|
107
120
|
const selectors = normalizeMcpDirectToolSelectors(mcpDirectTools);
|
|
108
121
|
if (selectors.length === 0) return { selections: [], unresolvedSelectors: [] };
|
|
122
|
+
if (usesBuiltinMcp(runtimeSnapshotHost)) {
|
|
123
|
+
return resolveBuiltinMcpSelections(selectors, runtimeSnapshotHost.getAllTools?.() ?? []);
|
|
124
|
+
}
|
|
109
125
|
|
|
110
126
|
const config = configOverride ?? loadMcpConfig(cwd);
|
|
111
127
|
const { servers: selectedServers, tools: selectedTools } = parseMcpDirectToolSelectors(selectors);
|
|
@@ -146,6 +162,76 @@ export function resolveMcpDirectToolSelections(
|
|
|
146
162
|
return resolveMcpDirectToolResolution(mcpDirectTools, cwd, runtimeSnapshotHost).selections;
|
|
147
163
|
}
|
|
148
164
|
|
|
165
|
+
/**
|
|
166
|
+
* pi-mcp-adapter keeps priority whenever it is loaded. 2.x registers /mcp, so Pi does not load its
|
|
167
|
+
* built-in MCP. 3.x always registers /mcp-adapter and leaves /mcp to the built-in MCP.
|
|
168
|
+
*/
|
|
169
|
+
function usesBuiltinMcp(host: McpRuntimeSnapshotHost | undefined): host is McpRuntimeSnapshotHost {
|
|
170
|
+
const commands = host?.getCommands?.() ?? [];
|
|
171
|
+
return commands.find((command) => command.name === "mcp")?.sourceInfo.path === "builtin:mcp"
|
|
172
|
+
&& !commands.some((command) => /^mcp-adapter(?::\d+)?$/.test(command.name));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Pi names built-in MCP tools `mcp__<server>__<tool>` with everything but `[A-Za-z0-9_]` replaced
|
|
177
|
+
* by `_`, in the namespace `mcp__<server>` with `-` replaced by `_`. Selectors name the raw server
|
|
178
|
+
* and tool. An overlong name, or one an earlier tool already took (`a_b`
|
|
179
|
+
* before `a.b`), gets a suffix hashed from the raw server and tool (Pi's `createMcpToolName`), so
|
|
180
|
+
* that suffixed name identifies the tool. The unsuffixed name may belong to another raw tool; the
|
|
181
|
+
* child checks each granted tool's raw identity before it exposes the tool.
|
|
182
|
+
*/
|
|
183
|
+
function resolveBuiltinMcpSelections(selectors: string[], tools: readonly McpHostToolInfo[]): McpDirectToolResolution {
|
|
184
|
+
const selections: ResolvedMcpDirectToolSelection[] = [];
|
|
185
|
+
const unresolvedSelectors: string[] = [];
|
|
186
|
+
for (const selector of selectors) {
|
|
187
|
+
const slash = selector.indexOf("/");
|
|
188
|
+
const server = slash === -1 ? selector : selector.slice(0, slash);
|
|
189
|
+
const inServer = tools.filter((tool) => tool.namespace?.name === `mcp__${server.replace(/-/g, "_")}`);
|
|
190
|
+
const toolName = slash === -1 ? undefined : builtinMcpToolNames(server, selector.slice(slash + 1)).find((name) => inServer.some((tool) => tool.name === name));
|
|
191
|
+
const matches = inServer.filter((tool) => tool.exposure !== "hidden" && (slash === -1 || tool.name === toolName));
|
|
192
|
+
if (matches.length === 0) unresolvedSelectors.push(selector);
|
|
193
|
+
for (const tool of matches) {
|
|
194
|
+
if (!selections.some((selection) => selection.name === tool.name)) selections.push({ name: tool.name, selector });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return { selections, unresolvedSelectors, builtin: true };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** The names Pi's `createMcpToolName` can give a raw tool, the hash-suffixed one first. */
|
|
201
|
+
function builtinMcpToolNames(server: string, tool: string): string[] {
|
|
202
|
+
const name = `mcp__${server}__${tool}`.replace(/[^A-Za-z0-9_]/g, "_");
|
|
203
|
+
const hash = createHash("sha256").update(`${server}\0${tool}`).digest("hex").slice(0, 8);
|
|
204
|
+
const suffixed = `${name.slice(0, 64 - hash.length - 1)}_${hash}`;
|
|
205
|
+
return name.length <= 64 ? [suffixed, name] : [suffixed];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function formatUnresolvedBuiltinMcpSelectors(agentName: string | undefined, selectors: readonly string[]): string {
|
|
209
|
+
const subject = agentName ? `Agent '${agentName}'` : "Subagent";
|
|
210
|
+
return `${subject} selects MCP tools that Pi's built-in MCP does not offer: ${selectors.map((selector) => `mcp:${selector}`).join(", ")}. The server may be missing, disconnected, still connecting, or its tools hidden; check /mcp.`;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Selected servers that only an extension registered, which a child without ambient extensions
|
|
215
|
+
* never has. A server of the same name in an `mcp.json` the child reads takes precedence; like Pi,
|
|
216
|
+
* the project file is read only when the project is trusted.
|
|
217
|
+
*/
|
|
218
|
+
export function extensionOnlyMcpServers(selections: readonly ResolvedMcpDirectToolSelection[], host: McpRuntimeSnapshotHost, cwd: string, projectTrusted: boolean): string[] {
|
|
219
|
+
const registered = new Set(host.getMcpServers?.().map(({ name }) => name));
|
|
220
|
+
const servers = [...new Set(selections.map(({ selector }) => selector.split("/")[0]!))].filter((server) => registered.has(server));
|
|
221
|
+
if (servers.length === 0) return [];
|
|
222
|
+
const files = [path.join(getAgentDir(), "mcp.json"), ...(projectTrusted ? [path.join(cwd, ".pi", "mcp.json")] : [])];
|
|
223
|
+
const configured = new Set(files.flatMap((file) => {
|
|
224
|
+
let parsed: unknown;
|
|
225
|
+
try {
|
|
226
|
+
parsed = JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
227
|
+
} catch {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
return isRecord(parsed) && isRecord(parsed.mcpServers) ? Object.keys(parsed.mcpServers) : [];
|
|
231
|
+
}));
|
|
232
|
+
return servers.filter((server) => !configured.has(server));
|
|
233
|
+
}
|
|
234
|
+
|
|
149
235
|
function loadMetadataCache(): MetadataCache | null {
|
|
150
236
|
const cachePath = path.join(getAgentDir(), "mcp-cache.json");
|
|
151
237
|
let parsed: unknown;
|
|
@@ -262,15 +348,17 @@ function loadMcpConfig(cwd: string): McpConfig {
|
|
|
262
348
|
}
|
|
263
349
|
|
|
264
350
|
function getConfigPaths(projectRoot: string): string[] {
|
|
265
|
-
const
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
351
|
+
const agentDir = getAgentDir();
|
|
352
|
+
const projectDir = getProjectConfigDir(projectRoot);
|
|
353
|
+
// pi-mcp-adapter 3.x reads mcp-adapter.json. Pi's own mcp.json files belong to
|
|
354
|
+
// Pi's built-in MCP support, so servers there are never adapter-registered.
|
|
355
|
+
const candidates = [
|
|
356
|
+
GENERIC_GLOBAL_CONFIG_PATH,
|
|
357
|
+
path.join(agentDir, "mcp-adapter.json"),
|
|
358
|
+
path.resolve(projectRoot, ".mcp.json"),
|
|
359
|
+
path.join(projectDir, "mcp-adapter.json"),
|
|
360
|
+
];
|
|
361
|
+
return [...new Set(candidates)];
|
|
274
362
|
}
|
|
275
363
|
|
|
276
364
|
function readConfig(configPath: string): McpConfig | null {
|
|
@@ -381,11 +469,16 @@ function isServerCacheValid(entry: ServerCacheEntry | undefined, definition: Ser
|
|
|
381
469
|
}
|
|
382
470
|
|
|
383
471
|
export function computeMcpServerHash(definition: ServerEntry): string {
|
|
472
|
+
// Aligned with pi-mcp-adapter's computeServerHash; since 3.1.0 stdio hashes include
|
|
473
|
+
// inheritEnv/literalEnv. A mismatch leaves that server's cached direct-tool selectors unresolved.
|
|
474
|
+
const isStdio = definition.command !== undefined;
|
|
475
|
+
const literalEnv = isStdio && definition.literalEnv === true;
|
|
384
476
|
const identity: Record<string, unknown> = {
|
|
385
|
-
command: definition.command,
|
|
477
|
+
command: resolveConfigPath(definition.command),
|
|
386
478
|
args: definition.args,
|
|
387
479
|
socket: resolveConfigPath(definition.socket),
|
|
388
|
-
env: interpolateEnvRecord(definition.env),
|
|
480
|
+
env: literalEnv ? definition.env : interpolateEnvRecord(definition.env),
|
|
481
|
+
...(isStdio ? { inheritEnv: definition.inheritEnv !== false, literalEnv } : {}),
|
|
389
482
|
cwd: resolveConfigPath(definition.cwd),
|
|
390
483
|
url: resolveServerUrl(definition),
|
|
391
484
|
headers: interpolateEnvRecord(definition.headers),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { splitKnownThinkingSuffix as splitThinkingSuffix, type ModelInfo as AvailableModelInfo } from "../../shared/model-info.ts";
|
|
2
|
-
import { checkModelScope, type ModelScopeCheckRule, type ModelScopeViolation, type ModelSource } from "./model-scope.ts";
|
|
2
|
+
import { checkModelScope, SCOPED_PATTERN, type ModelScopeCheckRule, type ModelScopeViolation, type ModelSource } from "./model-scope.ts";
|
|
3
3
|
|
|
4
4
|
export type { AvailableModelInfo };
|
|
5
5
|
|
|
@@ -10,15 +10,23 @@ export interface ModelSelectionEvidence {
|
|
|
10
10
|
|
|
11
11
|
export { splitThinkingSuffix };
|
|
12
12
|
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Aliases apply only to the resolved launch candidate (without its thinking suffix) and the exact raw response ID.
|
|
15
|
+
* When the child's live selection is a Pi virtual model, assistant messages name the physical model it dispatched
|
|
16
|
+
* to, so the virtual selection's provider/id is compared exactly with the launch candidate instead.
|
|
17
|
+
*/
|
|
14
18
|
export function formatSubagentModelVerificationError(
|
|
15
19
|
expectedModel: string,
|
|
16
20
|
observedModel: string,
|
|
17
21
|
availableModels: AvailableModelInfo[] | undefined,
|
|
18
22
|
modelResponseAliases?: Record<string, string[]>,
|
|
23
|
+
observedVirtualModel?: string,
|
|
19
24
|
): string | undefined {
|
|
20
25
|
if (!availableModels || availableModels.length === 0) return undefined;
|
|
21
26
|
const expectedBase = splitThinkingSuffix(expectedModel).baseModel;
|
|
27
|
+
if (observedVirtualModel !== undefined) {
|
|
28
|
+
return observedVirtualModel === expectedBase ? undefined : `model_verification_failed: native Pi child selected virtual model '${observedVirtualModel}', but the launch candidate was '${expectedModel}'. modelResponseAliases does not apply to a virtual-model selection.`;
|
|
29
|
+
}
|
|
22
30
|
if (modelResponseAliases && Object.hasOwn(modelResponseAliases, expectedBase)
|
|
23
31
|
&& modelResponseAliases[expectedBase]?.includes(observedModel)) return undefined;
|
|
24
32
|
const observedBase = splitThinkingSuffix(observedModel).baseModel;
|
|
@@ -50,6 +58,23 @@ export function normalizeParentModel(model: unknown): ParentModel | undefined {
|
|
|
50
58
|
return { provider: candidate.provider, id: candidate.id };
|
|
51
59
|
}
|
|
52
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Provider/id ids of the host session's scoped-model snapshot (`ctx.scopedModels`).
|
|
63
|
+
* Pi reports an empty set when the session is unscoped (nothing configured, or no
|
|
64
|
+
* pattern matched), and then allows every model; `scoped` narrows that to `inherit`.
|
|
65
|
+
*/
|
|
66
|
+
export function scopedModelIdsFromContext(ctx: { scopedModels?: ReadonlyArray<{ model?: unknown }> }): string[] {
|
|
67
|
+
const scoped = ctx.scopedModels;
|
|
68
|
+
if (!Array.isArray(scoped)) return [];
|
|
69
|
+
const ids: string[] = [];
|
|
70
|
+
for (const entry of scoped) {
|
|
71
|
+
const model = entry?.model;
|
|
72
|
+
const normalized = normalizeParentModel(model);
|
|
73
|
+
if (normalized) ids.push(`${normalized.provider}/${normalized.id}`);
|
|
74
|
+
}
|
|
75
|
+
return ids;
|
|
76
|
+
}
|
|
77
|
+
|
|
53
78
|
/**
|
|
54
79
|
* Normalize a model id or provider segment for fuzzy comparison: case-fold,
|
|
55
80
|
* treat dots/underscores as dashes (so `4.5` matches `4-5`), and collapse
|
|
@@ -267,12 +292,15 @@ function configuredScopes(scope: ModelScopeCheckRule | ModelScopeCheckRule[] | u
|
|
|
267
292
|
return scope ? (Array.isArray(scope) ? scope : [scope]) : [];
|
|
268
293
|
}
|
|
269
294
|
|
|
270
|
-
function
|
|
271
|
-
const
|
|
272
|
-
.find((entry) => entry.enforce === true && (includeMixed
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
295
|
+
function throwForUnresolvedEnforcedReservedScope(scope: ModelScopeCheckRule | ModelScopeCheckRule[] | undefined, includeMixed = false): void {
|
|
296
|
+
const unresolvedReservedScope = configuredScopes(scope)
|
|
297
|
+
.find((entry) => entry.enforce === true && (includeMixed
|
|
298
|
+
? entry.allow?.some((pattern) => pattern === INHERIT_MODEL || pattern === SCOPED_PATTERN)
|
|
299
|
+
: entry.allow?.length === 1 && (entry.allow[0] === INHERIT_MODEL || entry.allow[0] === SCOPED_PATTERN)));
|
|
300
|
+
if (!unresolvedReservedScope) return;
|
|
301
|
+
const origin = unresolvedReservedScope.origin ?? "modelScope";
|
|
302
|
+
const token = unresolvedReservedScope.allow?.includes(INHERIT_MODEL) ? INHERIT_MODEL : SCOPED_PATTERN;
|
|
303
|
+
throw new Error(`Cannot enforce subagent model scope (${origin}): '${token}' requires a current parent session model.`);
|
|
276
304
|
}
|
|
277
305
|
|
|
278
306
|
function enforceModelScopes(
|
|
@@ -316,7 +344,7 @@ export function resolveSubagentModelOverride(
|
|
|
316
344
|
): string | undefined {
|
|
317
345
|
const trimmed = typeof requestedModel === "string" ? requestedModel.trim() : "";
|
|
318
346
|
const explicit = trimmed && trimmed !== INHERIT_MODEL ? trimmed : undefined;
|
|
319
|
-
if (!parentModel)
|
|
347
|
+
if (!parentModel) throwForUnresolvedEnforcedReservedScope(options?.scope, explicit === undefined || options?.source === "inherited");
|
|
320
348
|
let resolved: string | undefined;
|
|
321
349
|
let resolvedFromRegistry = explicit === undefined;
|
|
322
350
|
if (explicit === undefined) {
|
|
@@ -407,7 +435,7 @@ export function resolveModelSelection(
|
|
|
407
435
|
preferredProvider?: string,
|
|
408
436
|
options?: ResolveModelSelectionOptions,
|
|
409
437
|
): ModelSelectionEvidence {
|
|
410
|
-
if (!model)
|
|
438
|
+
if (!model) throwForUnresolvedEnforcedReservedScope(options?.scope, true);
|
|
411
439
|
const origin = options?.origin ?? (options?.primaryModelFromParent ? "inherited" : "configured");
|
|
412
440
|
const requestedModel = origin === "inherited" ? undefined : model;
|
|
413
441
|
const scopes = configuredScopes(options?.scope);
|
|
@@ -48,6 +48,10 @@ export interface ModelScopeViolation {
|
|
|
48
48
|
origin: string;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
export const SCOPED_PATTERN = "scoped";
|
|
52
|
+
|
|
53
|
+
const MAX_RENDERED_PATTERNS = 8;
|
|
54
|
+
|
|
51
55
|
function stripThinkingSuffix(model: string): string {
|
|
52
56
|
return splitKnownThinkingSuffix(model).baseModel;
|
|
53
57
|
}
|
|
@@ -86,6 +90,9 @@ export function checkModelScope(
|
|
|
86
90
|
const baseModel = stripThinkingSuffix(model);
|
|
87
91
|
const severity: ModelScopeViolation["severity"] = source === "explicit" || scope.strict === true ? "error" : "warn";
|
|
88
92
|
const origin = scope.origin ?? "modelScope";
|
|
93
|
+
const rendered = allow.length <= MAX_RENDERED_PATTERNS
|
|
94
|
+
? allow.join(", ")
|
|
95
|
+
: `${allow.slice(0, MAX_RENDERED_PATTERNS).join(", ")}, … (${allow.length} patterns total)`;
|
|
89
96
|
return {
|
|
90
97
|
model: baseModel,
|
|
91
98
|
severity,
|
|
@@ -93,12 +100,22 @@ export function checkModelScope(
|
|
|
93
100
|
origin,
|
|
94
101
|
message:
|
|
95
102
|
`Model '${baseModel}' is outside the configured subagent model scope (${origin}). ` +
|
|
96
|
-
`Allowed patterns: ${
|
|
103
|
+
`Allowed patterns: ${rendered}.`,
|
|
97
104
|
};
|
|
98
105
|
}
|
|
99
106
|
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
/** An empty scoped snapshot degrades `scoped` to `inherit`; absent inputs stay literal so enforced resolution fails closed. */
|
|
108
|
+
function expandReservedPatterns(
|
|
109
|
+
pattern: string,
|
|
110
|
+
parentModel: { provider: string; id: string } | undefined,
|
|
111
|
+
scopedModelIds: readonly string[] | undefined,
|
|
112
|
+
): string[] {
|
|
113
|
+
if (pattern === SCOPED_PATTERN) {
|
|
114
|
+
if (scopedModelIds?.length) return [...scopedModelIds];
|
|
115
|
+
return parentModel ? [`${parentModel.provider}/${parentModel.id}`] : [pattern];
|
|
116
|
+
}
|
|
117
|
+
if (pattern === "inherit") return parentModel ? [`${parentModel.provider}/${parentModel.id}`] : [pattern];
|
|
118
|
+
return [pattern];
|
|
102
119
|
}
|
|
103
120
|
|
|
104
121
|
function assertRecord(value: unknown, field: string, meta: { filePath: string }, expected = "an object"): Record<string, unknown> {
|
|
@@ -145,23 +162,25 @@ export function resolveModelScopesForAgent(
|
|
|
145
162
|
config: ModelScopeConfig | undefined,
|
|
146
163
|
agentName: string,
|
|
147
164
|
parentModel: { provider: string; id: string } | undefined,
|
|
165
|
+
scopedModelIds?: readonly string[],
|
|
148
166
|
): ResolvedModelScope[] {
|
|
149
167
|
if (!config) return [];
|
|
150
168
|
const scopes: ResolvedModelScope[] = [];
|
|
151
169
|
if (config.allow) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
...(config.strict !== undefined ? { strict: config.strict } : {}),
|
|
155
|
-
allow: config.allow.map((pattern) => expandInheritPattern(pattern, parentModel)),
|
|
170
|
+
const globalScope: ResolvedModelScope = {
|
|
171
|
+
allow: config.allow.flatMap((pattern) => expandReservedPatterns(pattern, parentModel, scopedModelIds)),
|
|
156
172
|
origin: "modelScope",
|
|
157
|
-
}
|
|
173
|
+
};
|
|
174
|
+
if (config.enforce !== undefined) globalScope.enforce = config.enforce;
|
|
175
|
+
if (config.strict !== undefined) globalScope.strict = config.strict;
|
|
176
|
+
scopes.push(globalScope);
|
|
158
177
|
}
|
|
159
178
|
const agentScope = config.agents?.[agentName];
|
|
160
179
|
if (agentScope?.allow) {
|
|
161
180
|
scopes.push({
|
|
162
181
|
enforce: agentScope.enforce ?? config.enforce,
|
|
163
182
|
strict: agentScope.strict ?? config.strict,
|
|
164
|
-
allow: agentScope.allow.
|
|
183
|
+
allow: agentScope.allow.flatMap((pattern) => expandReservedPatterns(pattern, parentModel, scopedModelIds)),
|
|
165
184
|
origin: `modelScope.agents.${agentName}`,
|
|
166
185
|
});
|
|
167
186
|
}
|
|
@@ -138,17 +138,17 @@ export function resolveNestedRoute(route: NestedRoute): NestedRoute {
|
|
|
138
138
|
const { rootRunId, capabilityToken } = route;
|
|
139
139
|
validateRouteShape(route);
|
|
140
140
|
const routeFile = path.join(commonRouteRoot(route), ROUTE_FILE);
|
|
141
|
-
let metadata: { rootRunId?: unknown; capabilityToken?: unknown };
|
|
142
|
-
try {
|
|
143
|
-
const parsed: unknown = JSON.parse(fs.readFileSync(routeFile, "utf-8"));
|
|
144
|
-
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
145
|
-
throw new Error("route metadata must be an object");
|
|
146
|
-
}
|
|
147
|
-
metadata = parsed as { rootRunId?: unknown; capabilityToken?: unknown };
|
|
148
|
-
} catch (error) {
|
|
149
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
150
|
-
throw new Error(`Nested event route metadata is unreadable: ${message}`);
|
|
151
|
-
}
|
|
141
|
+
let metadata: { rootRunId?: unknown; capabilityToken?: unknown };
|
|
142
|
+
try {
|
|
143
|
+
const parsed: unknown = JSON.parse(fs.readFileSync(routeFile, "utf-8"));
|
|
144
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
145
|
+
throw new Error("route metadata must be an object");
|
|
146
|
+
}
|
|
147
|
+
metadata = parsed as { rootRunId?: unknown; capabilityToken?: unknown };
|
|
148
|
+
} catch (error) {
|
|
149
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
150
|
+
throw new Error(`Nested event route metadata is unreadable: ${message}`);
|
|
151
|
+
}
|
|
152
152
|
if (metadata.rootRunId !== rootRunId || metadata.capabilityToken !== capabilityToken) {
|
|
153
153
|
throw new Error("Nested event route metadata does not match the provided root id and capability token.");
|
|
154
154
|
}
|
|
@@ -315,16 +315,16 @@ function sanitizeStep(input: unknown, depth: number): NestedStepSummary | undefi
|
|
|
315
315
|
: "pending";
|
|
316
316
|
const model = stringValue(raw.model);
|
|
317
317
|
const thinking = THINKING_LEVELS.find((level) => level === raw.thinking);
|
|
318
|
-
const sandbox = validateSandboxProfileNameOptional(raw.sandbox);
|
|
319
|
-
const permissionProfile = validatePermissionProfileNameOptional(raw.permissionProfile);
|
|
318
|
+
const sandbox = validateSandboxProfileNameOptional(raw.sandbox);
|
|
319
|
+
const permissionProfile = validatePermissionProfileNameOptional(raw.permissionProfile);
|
|
320
320
|
return {
|
|
321
321
|
agent,
|
|
322
322
|
status,
|
|
323
323
|
...(model ? { model } : {}),
|
|
324
324
|
...(thinking ? { thinking } : {}),
|
|
325
325
|
...(stringValue(raw.sessionName, 256) ? { sessionName: stringValue(raw.sessionName, 256) } : {}),
|
|
326
|
-
...(sandbox ? { sandbox } : {}),
|
|
327
|
-
...(permissionProfile ? { permissionProfile } : {}),
|
|
326
|
+
...(sandbox ? { sandbox } : {}),
|
|
327
|
+
...(permissionProfile ? { permissionProfile } : {}),
|
|
328
328
|
...(stringValue(raw.sessionFile, 2048) ? { sessionFile: stringValue(raw.sessionFile, 2048) } : {}),
|
|
329
329
|
...(raw.activityState === "active_long_running" || raw.activityState === "needs_attention" ? { activityState: raw.activityState } : {}),
|
|
330
330
|
...(clampNumber(raw.lastActivityAt) !== undefined ? { lastActivityAt: clampNumber(raw.lastActivityAt) } : {}),
|
|
@@ -357,8 +357,8 @@ export function sanitizeSummary(input: unknown, depth = 0): NestedRunSummary | u
|
|
|
357
357
|
: undefined;
|
|
358
358
|
const totalTokens = sanitizeTokenUsage(raw.totalTokens);
|
|
359
359
|
const totalCost = sanitizeCost(raw.totalCost);
|
|
360
|
-
const sandbox = validateSandboxProfileNameOptional(raw.sandbox);
|
|
361
|
-
const permissionProfile = validatePermissionProfileNameOptional(raw.permissionProfile);
|
|
360
|
+
const sandbox = validateSandboxProfileNameOptional(raw.sandbox);
|
|
361
|
+
const permissionProfile = validatePermissionProfileNameOptional(raw.permissionProfile);
|
|
362
362
|
return {
|
|
363
363
|
id: raw.id,
|
|
364
364
|
parentRunId: raw.parentRunId,
|
|
@@ -382,8 +382,8 @@ const permissionProfile = validatePermissionProfileNameOptional(raw.permissionPr
|
|
|
382
382
|
...(stringValue(raw.capabilityToken, 128) ? { capabilityToken: stringValue(raw.capabilityToken, 128) } : {}),
|
|
383
383
|
...(raw.mode === "single" || raw.mode === "parallel" || raw.mode === "chain" ? { mode: raw.mode } : {}),
|
|
384
384
|
...(stringValue(raw.agent, 128) ? { agent: stringValue(raw.agent, 128) } : {}),
|
|
385
|
-
...(sandbox ? { sandbox } : {}),
|
|
386
|
-
...(permissionProfile ? { permissionProfile } : {}),
|
|
385
|
+
...(sandbox ? { sandbox } : {}),
|
|
386
|
+
...(permissionProfile ? { permissionProfile } : {}),
|
|
387
387
|
...(Array.isArray(raw.agents) ? { agents: raw.agents.map((agent) => stringValue(agent, 128)).filter((agent): agent is string => Boolean(agent)).slice(0, MAX_STEPS) } : {}),
|
|
388
388
|
|
|
389
389
|
...(clampNumber(raw.currentStep) !== undefined ? { currentStep: clampNumber(raw.currentStep) } : {}),
|
|
@@ -1021,7 +1021,7 @@ export function hasLiveNestedDescendants(children: NestedRunSummary[] | undefine
|
|
|
1021
1021
|
}
|
|
1022
1022
|
|
|
1023
1023
|
export function nestedSummaryFromAsyncStatus(status: AsyncStatus, asyncDir: string, fallback: { id: string; parentRunId: string; parentStepIndex?: number; depth: number; path?: Array<{ runId: string; stepIndex?: number; agent?: string }>; mode?: SubagentRunMode; ts: number }): NestedRunSummary {
|
|
1024
|
-
const sandbox = validateSandboxProfileNameOptional(status.sandbox);
|
|
1024
|
+
const sandbox = validateSandboxProfileNameOptional(status.sandbox);
|
|
1025
1025
|
return {
|
|
1026
1026
|
id: status.runId || fallback.id,
|
|
1027
1027
|
parentRunId: fallback.parentRunId,
|
|
@@ -1032,7 +1032,7 @@ const sandbox = validateSandboxProfileNameOptional(status.sandbox);
|
|
|
1032
1032
|
...(status.pid ? { pid: status.pid } : {}),
|
|
1033
1033
|
...(status.sessionId ? { sessionId: status.sessionId } : {}),
|
|
1034
1034
|
mode: status.mode ?? fallback.mode,
|
|
1035
|
-
...(sandbox ? { sandbox } : {}),
|
|
1035
|
+
...(sandbox ? { sandbox } : {}),
|
|
1036
1036
|
...(status.steps?.length === 1 && status.steps[0]?.model ? { model: status.steps[0].model } : {}),
|
|
1037
1037
|
...(status.steps?.length === 1 && status.steps[0]?.thinking ? { thinking: status.steps[0].thinking } : {}),
|
|
1038
1038
|
...(status.steps?.length === 1 && status.steps[0]?.sessionName ? { sessionName: status.steps[0].sessionName } : {}),
|
|
@@ -1064,40 +1064,40 @@ const sandbox = validateSandboxProfileNameOptional(status.sandbox);
|
|
|
1064
1064
|
...(status.endedAt !== undefined ? { endedAt: status.endedAt } : {}),
|
|
1065
1065
|
lastUpdate: status.lastUpdate ?? fallback.ts,
|
|
1066
1066
|
...(status.sessionFile ? { sessionFile: status.sessionFile } : {}),
|
|
1067
|
-
...(status.steps?.length ? {
|
|
1068
|
-
steps: status.steps.map((step, index) => {
|
|
1069
|
-
const stepSandbox = validateSandboxProfileNameOptional(step.sandbox);
|
|
1070
|
-
return {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
...(stepSandbox ? { sandbox: stepSandbox } : {}),
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
};
|
|
1099
|
-
}).slice(0, MAX_STEPS),
|
|
1100
|
-
} : {}),
|
|
1067
|
+
...(status.steps?.length ? {
|
|
1068
|
+
steps: status.steps.map((step, index) => {
|
|
1069
|
+
const stepSandbox = validateSandboxProfileNameOptional(step.sandbox);
|
|
1070
|
+
return {
|
|
1071
|
+
agent: step.agent,
|
|
1072
|
+
...(step.sessionName ? { sessionName: step.sessionName } : {}),
|
|
1073
|
+
status: step.status,
|
|
1074
|
+
...(step.model ? { model: step.model } : {}),
|
|
1075
|
+
...(step.thinking ? { thinking: step.thinking } : {}),
|
|
1076
|
+
...(stepSandbox ? { sandbox: stepSandbox } : {}),
|
|
1077
|
+
...(step.sessionFile ? { sessionFile: step.sessionFile } : {}),
|
|
1078
|
+
...(step.activityState ? { activityState: step.activityState } : {}),
|
|
1079
|
+
...(step.lastActivityAt !== undefined ? { lastActivityAt: step.lastActivityAt } : {}),
|
|
1080
|
+
...(step.currentTool ? { currentTool: step.currentTool } : {}),
|
|
1081
|
+
...(step.currentToolStartedAt !== undefined ? { currentToolStartedAt: step.currentToolStartedAt } : {}),
|
|
1082
|
+
...(step.currentPath ? { currentPath: step.currentPath } : {}),
|
|
1083
|
+
...(step.turnCount !== undefined ? { turnCount: step.turnCount } : {}),
|
|
1084
|
+
...(step.toolCount !== undefined ? { toolCount: step.toolCount } : {}),
|
|
1085
|
+
...(step.startedAt !== undefined ? { startedAt: step.startedAt } : {}),
|
|
1086
|
+
...(step.endedAt !== undefined ? { endedAt: step.endedAt } : {}),
|
|
1087
|
+
...(step.error ? { error: step.error } : {}),
|
|
1088
|
+
...(step.launchResolvedExtensions ? { launchResolvedExtensions: step.launchResolvedExtensions } : {}),
|
|
1089
|
+
...runtimeAcknowledgedEntry(step.runtimeAcknowledgedExtensions),
|
|
1090
|
+
...(step.timedOut !== undefined ? { timedOut: step.timedOut } : {}),
|
|
1091
|
+
...(step.stopped !== undefined ? { stopped: step.stopped } : {}),
|
|
1092
|
+
...(step.turnBudget ? { turnBudget: step.turnBudget } : {}),
|
|
1093
|
+
...(step.turnBudgetExceeded !== undefined ? { turnBudgetExceeded: step.turnBudgetExceeded } : {}),
|
|
1094
|
+
...(step.wrapUpRequested !== undefined ? { wrapUpRequested: step.wrapUpRequested } : {}),
|
|
1095
|
+
...(step.processTerminal ? { processTerminal: sanitizeProcessTerminal(step.processTerminal, { runId: status.runId || fallback.id, runnerProcessInstanceId: step.processTerminal.runnerProcessInstanceId }, `${asyncDir}/status.json step ${index}`) } : {}),
|
|
1096
|
+
...(step.capabilityCeiling ? { capabilityCeiling: step.capabilityCeiling } : {}),
|
|
1097
|
+
...(step.capabilityAudit ? { capabilityAudit: step.capabilityAudit } : {}),
|
|
1098
|
+
};
|
|
1099
|
+
}).slice(0, MAX_STEPS),
|
|
1100
|
+
} : {}),
|
|
1101
1101
|
};
|
|
1102
1102
|
}
|
|
1103
1103
|
|