@xzzpig/pi-subagents 0.24.2 → 0.25.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 +22 -0
- package/bundle/agent-management.js +4 -4
- package/bundle/agents.js +3 -3
- package/bundle/child-tool-plan.js +2 -2
- package/bundle/chunk-34TUUBRN.js +1107 -0
- package/bundle/{chunk-SW2VMNIU.js → chunk-5OD3OWTE.js} +2 -2
- package/bundle/{chunk-XWWUDWUW.js → chunk-5YEOWNSD.js} +371 -135
- package/bundle/{chunk-EUPJB4S7.js → chunk-5Z7JAORM.js} +196 -1219
- package/bundle/{chunk-LCDJWBVM.js → chunk-66JNFRFS.js} +1 -1
- package/bundle/{chunk-4UH4WS4G.js → chunk-6MNRKUHY.js} +23 -12
- package/bundle/{chunk-ED55MIC2.js → chunk-CGFF4WA3.js} +42 -19
- package/bundle/{chunk-TMHVDPYW.js → chunk-DLVPMML3.js} +263 -154
- package/bundle/chunk-HXRB42AF.js +108 -0
- package/bundle/{chunk-355ECEP2.js → chunk-IH7LQVEE.js} +29 -14
- package/bundle/{chunk-CYY5UMJU.js → chunk-IJWITCC6.js} +411 -249
- package/bundle/{chunk-RU522D5W.js → chunk-IKFKH5EL.js} +369 -50
- package/bundle/{chunk-Z6TFJ6BR.js → chunk-INWSUNI6.js} +1 -1
- package/bundle/{chunk-JEA2ZKUA.js → chunk-IUDEI6FJ.js} +35 -200
- package/bundle/{chunk-WW76JRIX.js → chunk-JAXVBXGF.js} +1 -1
- package/bundle/{chunk-ICNYIALB.js → chunk-JH5H4CYJ.js} +784 -474
- package/bundle/{chunk-35GII5EF.js → chunk-JWFLPSTP.js} +41 -117
- package/bundle/{chunk-224WMDIV.js → chunk-KCJFGKVK.js} +350 -123
- package/bundle/{chunk-RB4GELQA.js → chunk-LPJEKHOY.js} +1 -1
- package/bundle/chunk-LYKG4FKH.js +523 -0
- package/bundle/{chunk-X6LOM3Z4.js → chunk-LZ3HBDTR.js} +161 -78
- package/bundle/{chunk-FG6SQJAR.js → chunk-OGPOCGWX.js} +24 -6
- package/bundle/{chunk-BQ2OAB4Q.js → chunk-OSVXFWPG.js} +67 -30
- package/bundle/{chunk-FJWI64H7.js → chunk-RMSABUN3.js} +27 -13
- package/bundle/{chunk-H36HBZB2.js → chunk-SJPABBZG.js} +2 -2
- package/bundle/{chunk-3U633XDZ.js → chunk-U3ZDUUTM.js} +11 -3
- package/bundle/{chunk-LVWU2HOO.js → chunk-ULGMXABL.js} +16 -7
- package/bundle/{chunk-WPW4V6HM.js → chunk-W7ZA6TYD.js} +2 -2
- package/bundle/{chunk-V2KFIGFH.js → chunk-XAC2XNAP.js} +503 -304
- package/bundle/{chunk-O4D5PBVI.js → chunk-YWXILP5N.js} +3 -2
- 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 +27 -6
- package/docs/configuration.md +20 -8
- package/docs/extension-api.md +18 -1
- package/docs/models.md +6 -2
- package/docs/observability.md +2 -0
- package/docs/tool-reference.md +7 -1
- package/docs/workflows.md +30 -2
- package/package.json +2 -2
- package/skills/pi-subagents/SKILL.md +15 -6
- package/skills/pi-subagents/references/prompting-and-roles.md +1 -0
- package/src/agents/agent-management.d.ts +1 -0
- package/src/agents/agent-management.js +46 -18
- package/src/agents/agent-memory.d.ts +1 -4
- package/src/agents/agent-memory.js +1 -4
- package/src/agents/agent-serializer.d.ts +2 -0
- package/src/agents/agent-serializer.js +1 -1
- package/src/agents/agents.d.ts +2 -3
- package/src/agents/agents.js +46 -20
- 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/api/preflight.d.ts +3 -1
- package/src/api/preflight.js +2 -0
- package/src/extension/config.d.ts +1 -0
- package/src/extension/config.js +13 -1
- package/src/extension/herdr-pi-bridge.js +10 -2
- package/src/extension/index.d.ts +0 -13
- package/src/extension/index.js +51 -37
- 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 +12 -3
- package/src/extension/schemas.js +7 -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 +55 -15
- 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 +7 -10
- package/src/runs/background/async-execution.js +66 -29
- 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 +114 -40
- package/src/runs/background/async-retention.d.ts +0 -2
- package/src/runs/background/async-retention.js +17 -6
- package/src/runs/background/async-status.d.ts +2 -0
- package/src/runs/background/async-status.js +4 -0
- 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 +2 -3
- package/src/runs/background/run-child-session.js +5 -8
- package/src/runs/background/run-status.js +9 -7
- package/src/runs/background/runner-aliases.js +15 -0
- package/src/runs/background/scheduled-runs.d.ts +3 -1
- package/src/runs/background/scheduled-runs.js +13 -16
- package/src/runs/background/steering.d.ts +2 -11
- package/src/runs/background/steering.js +11 -6
- package/src/runs/background/subagent-runner.d.ts +2 -6
- package/src/runs/background/subagent-runner.js +88 -70
- 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-subscriptions.js +124 -12
- 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/async-steering-action.js +24 -9
- 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.d.ts +0 -3
- package/src/runs/foreground/execution.js +56 -24
- package/src/runs/foreground/prompt-audit.js +1 -0
- package/src/runs/foreground/subagent-executor.d.ts +5 -10
- package/src/runs/foreground/subagent-executor.js +164 -49
- package/src/runs/shared/acceptance.js +69 -26
- package/src/runs/shared/async-status-projection.d.ts +2 -0
- package/src/runs/shared/async-status-projection.js +10 -0
- 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 +6 -5
- package/src/runs/shared/child-session.js +85 -38
- 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 +51 -24
- package/src/runs/shared/lane-metadata.d.ts +0 -1
- package/src/runs/shared/lane-metadata.js +0 -1
- package/src/runs/shared/mcp-config-sources.d.ts +4 -1
- package/src/runs/shared/mcp-config-sources.js +1 -1
- package/src/runs/shared/mcp-direct-tool-allowlist.d.ts +0 -3
- package/src/runs/shared/mcp-direct-tool-allowlist.js +26 -17
- 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 +20 -5
- package/src/runs/shared/model-resolution.js +55 -50
- 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 +18 -4
- package/src/runs/shared/supervisor-wait-timer.d.ts +16 -0
- package/src/runs/shared/supervisor-wait-timer.js +61 -0
- 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/artifacts.d.ts +1 -0
- package/src/shared/artifacts.js +132 -22
- 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/pruned-fork.js +2 -2
- package/src/shared/reported-progress.d.ts +1 -0
- package/src/shared/reported-progress.js +12 -0
- 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/status-format.d.ts +1 -0
- package/src/shared/status-format.js +1 -1
- package/src/shared/types.d.ts +108 -59
- package/src/shared/types.js +0 -12
- package/src/shared/utils.d.ts +3 -15
- package/src/shared/utils.js +4 -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.js +6 -4
- package/src/tui/render.d.ts +0 -9
- package/src/tui/render.js +194 -68
- package/src/tui/subagent-messages.js +3 -2
- package/src/watchdog/model-selection.js +2 -2
- package/src/watchdog/permission-arbiter.js +1 -0
- package/src/watchdog/register-child.d.ts +2 -3
- package/src/watchdog/register-child.js +2 -3
- package/src/watchdog/review.d.ts +0 -5
- package/src/watchdog/review.js +4 -3
- package/src/watchdog/turn-delta.js +2 -1
- package/src/workflows/scripted-workflow.d.ts +2 -0
- package/src/workflows/scripted-workflow.js +344 -59
- package/src/workflows/structured-workflow-scripts.d.ts +4 -3
- package/src/workflows/structured-workflow-scripts.js +32 -11
- 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-resources.js +4 -4
- package/src/workflows/workflow-resume-claim.d.ts +2 -0
- package/src/workflows/workflow-resume-claim.js +3 -3
- package/src/workflows/workflow-resume.d.ts +1 -1
- package/src/workflows/workflow-resume.js +13 -8
- package/src/workflows/workflow-script-worker.d.ts +13 -0
- package/src/workflows/workflow-script-worker.js +81 -0
- package/workflow-script-process.cjs +36 -0
- package/workflow-script-worker.cjs +4 -1
- package/bundle/chunk-U4ODUYAG.js +0 -235
|
@@ -12,6 +12,11 @@ import {
|
|
|
12
12
|
truncateDisplayText
|
|
13
13
|
} from "./chunk-YFCK7H2S.js";
|
|
14
14
|
|
|
15
|
+
// src/shared/atomic-json.ts
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
17
|
+
import * as fs from "node:fs";
|
|
18
|
+
import * as path from "node:path";
|
|
19
|
+
|
|
15
20
|
// src/shared/file-system-retry.ts
|
|
16
21
|
var WAIT_BUFFER = typeof SharedArrayBuffer !== "undefined" ? new SharedArrayBuffer(4) : void 0;
|
|
17
22
|
var WAIT_VIEW = WAIT_BUFFER ? new Int32Array(WAIT_BUFFER) : void 0;
|
|
@@ -70,9 +75,6 @@ function runFileSystemOperationWithRetry(operation, options = {}) {
|
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
// src/shared/atomic-json.ts
|
|
73
|
-
import { createHash } from "node:crypto";
|
|
74
|
-
import * as fs from "node:fs";
|
|
75
|
-
import * as path from "node:path";
|
|
76
78
|
var MAX_PATH_COMPONENT_BYTES = 255;
|
|
77
79
|
function renameWithRetry(fsImpl, sourcePath, targetPath, retryDelaysMs, wait) {
|
|
78
80
|
runFileSystemOperationWithRetry(() => {
|
|
@@ -169,6 +171,14 @@ function validateCodeOwnedProfileRunner(agent) {
|
|
|
169
171
|
}
|
|
170
172
|
return void 0;
|
|
171
173
|
}
|
|
174
|
+
var EXTERNAL_CLI_ADAPTER_SAFETY = {
|
|
175
|
+
"codex-exec": { sandbox: "read-only", approvalPolicy: "never", ephemeral: true },
|
|
176
|
+
"codex-exec-writer": { access: "workspace-write", sandbox: "workspace-write", approvalPolicy: "never", ephemeral: true },
|
|
177
|
+
"claude-code": { access: "read-only", authentication: "existing-cli-required", permissionMode: "plan", tools: "none", mcp: "empty-strict", settingSources: "user", userSettingsTrust: "required", sessionPersistence: false },
|
|
178
|
+
"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 },
|
|
179
|
+
"cursor-agent": { access: "read-only", authentication: "cursor-api-key-or-existing-login", mode: "ask", sandbox: "enabled", workspaceTrust: "existing-required", sessionReuse: false },
|
|
180
|
+
"cursor-agent-writer": { access: "workspace-write", authentication: "cursor-api-key-or-existing-login", mode: "print", sandbox: "enabled", workspaceTrust: "existing-required", sessionReuse: false }
|
|
181
|
+
};
|
|
172
182
|
function parseExternalCliCapabilityNarrowing(value, label) {
|
|
173
183
|
if (value === void 0) return void 0;
|
|
174
184
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error(`${label} must be an object.`);
|
|
@@ -181,13 +191,8 @@ function parseExternalCliCapabilityNarrowing(value, label) {
|
|
|
181
191
|
return input;
|
|
182
192
|
}
|
|
183
193
|
function resolveExternalCliRunnerStatus(input) {
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
const claudeCode = input.adapter === "claude-code";
|
|
187
|
-
const claudeCodeWriter = input.adapter === "claude-code-writer";
|
|
188
|
-
const cursorAgent = input.adapter === "cursor-agent";
|
|
189
|
-
const cursorAgentWriter = input.adapter === "cursor-agent-writer";
|
|
190
|
-
const cursor = cursorAgent || cursorAgentWriter;
|
|
194
|
+
const cursor = input.adapter === "cursor-agent" || input.adapter === "cursor-agent-writer";
|
|
195
|
+
const profileSafety = input.adapter ? EXTERNAL_CLI_ADAPTER_SAFETY[input.adapter] : void 0;
|
|
191
196
|
const unsupported = cursor ? PROMPT_FILE_UNSUPPORTED : UNSUPPORTED;
|
|
192
197
|
return {
|
|
193
198
|
type: "external-cli",
|
|
@@ -195,12 +200,11 @@ function resolveExternalCliRunnerStatus(input) {
|
|
|
195
200
|
args: input.args ?? [],
|
|
196
201
|
promptDelivery: cursor ? "prompt-file" : input.promptDelivery ?? "stdin",
|
|
197
202
|
adapter: { id: input.adapter ?? "external-cli", version: 1, executionMode: cursor ? "one-shot-prompt-file" : "one-shot-stdin" },
|
|
198
|
-
...
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
...cursorAgentWriter ? { safety: { access: "workspace-write", authentication: "cursor-api-key-or-existing-login", mode: "print", sandbox: "enabled", workspaceTrust: "existing-required", sessionReuse: false } } : {},
|
|
203
|
+
...profileSafety ? {
|
|
204
|
+
safety: { ...profileSafety },
|
|
205
|
+
// A Herdr saved machine launches the remote adapter binary, never runner.command.
|
|
206
|
+
safetySource: { measured: false, ...input.machine ? {} : { command: input.command } }
|
|
207
|
+
} : {},
|
|
204
208
|
...input.machine ? { machine: input.machine } : {},
|
|
205
209
|
capabilities: {
|
|
206
210
|
stop: true,
|
|
@@ -248,6 +252,7 @@ function externalCliReceiptMetadata(input) {
|
|
|
248
252
|
capabilities: { ...runner.capabilities },
|
|
249
253
|
...machine ? { machine: { ...machine, ...machine.remoteGit ? { remoteGit: { ...machine.remoteGit } } : {} } } : {},
|
|
250
254
|
...runner.safety ? { safety: { ...runner.safety } } : {},
|
|
255
|
+
...runner.safetySource ? { safetySource: { ...runner.safetySource } } : {},
|
|
251
256
|
...input.externalProcess ? {
|
|
252
257
|
outputArtifacts: {
|
|
253
258
|
stdoutPath: input.externalProcess.stdoutPath,
|
|
@@ -263,9 +268,9 @@ function externalCliReceiptMetadata(input) {
|
|
|
263
268
|
|
|
264
269
|
// src/agents/skills.ts
|
|
265
270
|
import { execSync as execSync2 } from "node:child_process";
|
|
266
|
-
import * as
|
|
267
|
-
import * as
|
|
268
|
-
import * as
|
|
271
|
+
import * as fs16 from "node:fs";
|
|
272
|
+
import * as os7 from "node:os";
|
|
273
|
+
import * as path17 from "node:path";
|
|
269
274
|
import { parse as parseYaml2 } from "yaml";
|
|
270
275
|
|
|
271
276
|
// src/agents/frontmatter.ts
|
|
@@ -278,12 +283,12 @@ function foldBlock(block) {
|
|
|
278
283
|
let previousIsMoreIndented = false;
|
|
279
284
|
let blankLines = 0;
|
|
280
285
|
for (const line of block.split("\n")) {
|
|
281
|
-
const
|
|
282
|
-
if (
|
|
286
|
+
const current2 = line.trimEnd();
|
|
287
|
+
if (current2.trim() === "") {
|
|
283
288
|
if (hasContent) blankLines++;
|
|
284
289
|
continue;
|
|
285
290
|
}
|
|
286
|
-
const currentIsMoreIndented =
|
|
291
|
+
const currentIsMoreIndented = current2.length > current2.trimStart().length;
|
|
287
292
|
if (hasContent) {
|
|
288
293
|
if (blankLines > 0) {
|
|
289
294
|
folded += "\n".repeat(blankLines + (previousIsMoreIndented || currentIsMoreIndented ? 1 : 0));
|
|
@@ -291,7 +296,7 @@ function foldBlock(block) {
|
|
|
291
296
|
folded += previousIsMoreIndented || currentIsMoreIndented ? "\n" : " ";
|
|
292
297
|
}
|
|
293
298
|
}
|
|
294
|
-
folded +=
|
|
299
|
+
folded += current2;
|
|
295
300
|
hasContent = true;
|
|
296
301
|
previousIsMoreIndented = currentIsMoreIndented;
|
|
297
302
|
blankLines = 0;
|
|
@@ -392,15 +397,15 @@ function flushBlockLines(blockLines, folded, literal) {
|
|
|
392
397
|
}
|
|
393
398
|
|
|
394
399
|
// src/shared/utils.ts
|
|
400
|
+
import * as fs15 from "node:fs";
|
|
401
|
+
import * as os6 from "node:os";
|
|
402
|
+
import * as path16 from "node:path";
|
|
403
|
+
|
|
404
|
+
// src/shared/settings.ts
|
|
395
405
|
import * as fs14 from "node:fs";
|
|
396
406
|
import * as os5 from "node:os";
|
|
397
407
|
import * as path15 from "node:path";
|
|
398
408
|
|
|
399
|
-
// src/shared/settings.ts
|
|
400
|
-
import * as fs13 from "node:fs";
|
|
401
|
-
import * as os4 from "node:os";
|
|
402
|
-
import * as path14 from "node:path";
|
|
403
|
-
|
|
404
409
|
// src/agents/agents.ts
|
|
405
410
|
import { execSync } from "node:child_process";
|
|
406
411
|
import * as fs11 from "node:fs";
|
|
@@ -444,8 +449,8 @@ function deadOwner(owner) {
|
|
|
444
449
|
} catch (error) {
|
|
445
450
|
return error.code === "ESRCH";
|
|
446
451
|
}
|
|
447
|
-
const
|
|
448
|
-
return owner.processStart !== void 0 &&
|
|
452
|
+
const current2 = startIdentity(owner.pid);
|
|
453
|
+
return owner.processStart !== void 0 && current2 !== void 0 && owner.processStart !== current2;
|
|
449
454
|
}
|
|
450
455
|
function tryLease(lockPath) {
|
|
451
456
|
const owner = { token: randomUUID(), pid: process.pid, hostname: os.hostname(), processStart: startIdentity(process.pid) };
|
|
@@ -579,7 +584,7 @@ async function waitUntilGroupTerminal(processGroupId, timeoutMs) {
|
|
|
579
584
|
if (!Array.isArray(members)) return { state: "enumeration-failed", diagnostic: members.diagnostic };
|
|
580
585
|
return { state: "still-active", diagnostic: `Process group ${processGroupId} still has active members: ${members.join(", ")}.` };
|
|
581
586
|
}
|
|
582
|
-
await new Promise((
|
|
587
|
+
await new Promise((resolve12) => setTimeout(resolve12, Math.min(VERIFY_INTERVAL_MS, remaining)));
|
|
583
588
|
}
|
|
584
589
|
}
|
|
585
590
|
function observed(processGroupId) {
|
|
@@ -692,36 +697,36 @@ var MAX_EXTENSION_BINDINGS_BYTES = 16 * 1024;
|
|
|
692
697
|
var MAX_EXTENSION_BINDINGS_DEPTH = 16;
|
|
693
698
|
var MAX_EXTENSION_BINDINGS_PROPERTIES = 256;
|
|
694
699
|
var EXTENSION_BINDING_NAMESPACE = /^[A-Za-z0-9](?:[A-Za-z0-9._-]{0,62})\/[1-9][0-9]{0,8}$/;
|
|
695
|
-
function canonicalizeJson(value,
|
|
700
|
+
function canonicalizeJson(value, path18, depth, seen, propertyCount) {
|
|
696
701
|
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
697
702
|
if (typeof value === "number") {
|
|
698
|
-
if (!Number.isFinite(value)) throw new Error(`${
|
|
703
|
+
if (!Number.isFinite(value)) throw new Error(`${path18} must contain only finite JSON numbers.`);
|
|
699
704
|
return value;
|
|
700
705
|
}
|
|
701
|
-
if (typeof value !== "object") throw new Error(`${
|
|
702
|
-
if (depth > MAX_EXTENSION_BINDINGS_DEPTH) throw new Error(`${
|
|
703
|
-
if (seen.has(value)) throw new Error(`${
|
|
706
|
+
if (typeof value !== "object") throw new Error(`${path18} must contain only plain JSON values.`);
|
|
707
|
+
if (depth > MAX_EXTENSION_BINDINGS_DEPTH) throw new Error(`${path18} exceeds the maximum nesting depth of ${MAX_EXTENSION_BINDINGS_DEPTH}.`);
|
|
708
|
+
if (seen.has(value)) throw new Error(`${path18} must not contain cycles.`);
|
|
704
709
|
seen.add(value);
|
|
705
710
|
try {
|
|
706
711
|
if (Array.isArray(value)) {
|
|
707
712
|
const output2 = [];
|
|
708
713
|
for (let index = 0; index < value.length; index++) {
|
|
709
|
-
if (!Object.prototype.hasOwnProperty.call(value, index)) throw new Error(`${
|
|
710
|
-
output2.push(canonicalizeJson(value[index], `${
|
|
714
|
+
if (!Object.prototype.hasOwnProperty.call(value, index)) throw new Error(`${path18} must not contain sparse arrays.`);
|
|
715
|
+
output2.push(canonicalizeJson(value[index], `${path18}[${index}]`, depth + 1, seen, propertyCount));
|
|
711
716
|
}
|
|
712
717
|
return Object.freeze(output2);
|
|
713
718
|
}
|
|
714
719
|
const prototype = Object.getPrototypeOf(value);
|
|
715
|
-
if (prototype !== Object.prototype && prototype !== null) throw new Error(`${
|
|
716
|
-
if (Object.getOwnPropertySymbols(value).length > 0) throw new Error(`${
|
|
720
|
+
if (prototype !== Object.prototype && prototype !== null) throw new Error(`${path18} must contain only plain JSON objects.`);
|
|
721
|
+
if (Object.getOwnPropertySymbols(value).length > 0) throw new Error(`${path18} must not contain symbol keys.`);
|
|
717
722
|
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
718
723
|
const output = {};
|
|
719
724
|
for (const key of Object.keys(descriptors).sort()) {
|
|
720
725
|
const descriptor = descriptors[key];
|
|
721
|
-
if (!descriptor.enumerable || !("value" in descriptor)) throw new Error(`${
|
|
726
|
+
if (!descriptor.enumerable || !("value" in descriptor)) throw new Error(`${path18}.${key} must be an enumerable data property.`);
|
|
722
727
|
propertyCount.value += 1;
|
|
723
728
|
if (propertyCount.value > MAX_EXTENSION_BINDINGS_PROPERTIES) throw new Error(`extensionBindings exceeds ${MAX_EXTENSION_BINDINGS_PROPERTIES} total properties.`);
|
|
724
|
-
Object.defineProperty(output, key, { value: canonicalizeJson(descriptor.value, `${
|
|
729
|
+
Object.defineProperty(output, key, { value: canonicalizeJson(descriptor.value, `${path18}.${key}`, depth + 1, seen, propertyCount), enumerable: true, writable: false, configurable: false });
|
|
725
730
|
}
|
|
726
731
|
return Object.freeze(output);
|
|
727
732
|
} finally {
|
|
@@ -858,7 +863,7 @@ var MAX_RAW_LOG_BYTES = 8 * 1024 * 1024;
|
|
|
858
863
|
var MAX_PARSER_LINE_BYTES = 256 * 1024;
|
|
859
864
|
var MAX_PARSER_STREAM_BYTES = 32 * 1024 * 1024;
|
|
860
865
|
var MAX_PARSER_OUTPUT_BYTES = 1024 * 1024;
|
|
861
|
-
var MAX_SKIPPABLE_LINE_BYTES = 1024 * 1024;
|
|
866
|
+
var MAX_SKIPPABLE_LINE_BYTES = 8 * 1024 * 1024;
|
|
862
867
|
|
|
863
868
|
// src/shared/model-info.ts
|
|
864
869
|
var THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
@@ -1279,7 +1284,7 @@ function serializeAgent(config, options = {}) {
|
|
|
1279
1284
|
if (config.thinking || preserve("thinking")) lines.push(`thinking: ${config.thinking ?? ""}`);
|
|
1280
1285
|
if (!preservingExistingFrontmatter || preserve("systemPromptMode")) lines.push(`systemPromptMode: ${config.systemPromptMode}`);
|
|
1281
1286
|
if (!preservingExistingFrontmatter || preserve("inheritProjectContext")) lines.push(`inheritProjectContext: ${config.inheritProjectContext ? "true" : "false"}`);
|
|
1282
|
-
if (config.inheritGlobalContext || preserve("inheritGlobalContext")) lines.push(`inheritGlobalContext: ${config.inheritGlobalContext ? "true" : "false"}`);
|
|
1287
|
+
if (config.inheritGlobalContext || preserve("inheritGlobalContext") || options.explicitInheritGlobalContext) lines.push(`inheritGlobalContext: ${config.inheritGlobalContext ? "true" : "false"}`);
|
|
1283
1288
|
if (!preservingExistingFrontmatter || preserve("inheritSkills")) lines.push(`inheritSkills: ${config.inheritSkills ? "true" : "false"}`);
|
|
1284
1289
|
if (config.defaultContext || preserve("defaultContext")) lines.push(`defaultContext: ${config.defaultContext ?? ""}`);
|
|
1285
1290
|
if (config.runner || preserve("runner")) {
|
|
@@ -1472,14 +1477,14 @@ function readPiPackageJson(packageJsonPath, readFileSync11 = (filePath, encoding
|
|
|
1472
1477
|
}
|
|
1473
1478
|
function selectPiPackage(deps) {
|
|
1474
1479
|
const existsSync10 = deps.existsSync ?? fs6.existsSync;
|
|
1475
|
-
const
|
|
1480
|
+
const realpathSync12 = deps.realpathSync ?? fs6.realpathSync;
|
|
1476
1481
|
const argv1 = deps.argv1 ?? process.argv[1];
|
|
1477
1482
|
const env = deps.env ?? process.env;
|
|
1478
1483
|
if (argv1) {
|
|
1479
1484
|
const argvPath = normalizePath(argv1);
|
|
1480
1485
|
if (isRunnableNodeScript(argvPath, existsSync10)) {
|
|
1481
1486
|
try {
|
|
1482
|
-
const canonicalArgvPath =
|
|
1487
|
+
const canonicalArgvPath = realpathSync12(argvPath);
|
|
1483
1488
|
const root2 = isRunnableNodeScript(canonicalArgvPath, existsSync10) ? findPiPackageRootFromEntry(canonicalArgvPath) : void 0;
|
|
1484
1489
|
if (root2) return { root: root2, cliScript: canonicalArgvPath };
|
|
1485
1490
|
} catch {
|
|
@@ -1661,6 +1666,8 @@ function createStructuredOutputToolParameters(schema, options = {}) {
|
|
|
1661
1666
|
};
|
|
1662
1667
|
}
|
|
1663
1668
|
var cachedCompile;
|
|
1669
|
+
var loadedCompile;
|
|
1670
|
+
var compileLoadError;
|
|
1664
1671
|
async function resolveCompileFromPackageRoot(packageRoot) {
|
|
1665
1672
|
const requireFromRoot = createRequire(path7.join(packageRoot, "package.json"));
|
|
1666
1673
|
const resolved = requireFromRoot.resolve("typebox/compile");
|
|
@@ -1696,23 +1703,30 @@ async function importCompile() {
|
|
|
1696
1703
|
}
|
|
1697
1704
|
function loadCompile() {
|
|
1698
1705
|
if (!cachedCompile) {
|
|
1699
|
-
cachedCompile = importCompile().
|
|
1706
|
+
cachedCompile = importCompile().then((compile) => {
|
|
1707
|
+
loadedCompile = compile;
|
|
1708
|
+
return compile;
|
|
1709
|
+
}, (error) => {
|
|
1700
1710
|
cachedCompile = void 0;
|
|
1711
|
+
compileLoadError = error;
|
|
1701
1712
|
throw error;
|
|
1702
1713
|
});
|
|
1703
1714
|
}
|
|
1704
1715
|
return cachedCompile;
|
|
1705
1716
|
}
|
|
1717
|
+
function structuredOutputValidatorReady() {
|
|
1718
|
+
return loadCompile().then(() => void 0, () => void 0);
|
|
1719
|
+
}
|
|
1706
1720
|
function jsonPointerTarget(root, pointer) {
|
|
1707
1721
|
if (pointer === "#") return root;
|
|
1708
1722
|
if (!pointer.startsWith("#/")) return void 0;
|
|
1709
|
-
let
|
|
1723
|
+
let current2 = root;
|
|
1710
1724
|
for (const encoded of pointer.slice(2).split("/")) {
|
|
1711
|
-
if (!
|
|
1725
|
+
if (!current2 || typeof current2 !== "object") return void 0;
|
|
1712
1726
|
const key = encoded.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
1713
|
-
|
|
1727
|
+
current2 = current2[key];
|
|
1714
1728
|
}
|
|
1715
|
-
return
|
|
1729
|
+
return current2;
|
|
1716
1730
|
}
|
|
1717
1731
|
function resolveLocalRefs(root, node) {
|
|
1718
1732
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -1857,15 +1871,29 @@ function createStructuredOutputRuntime(schema, baseDir, options = {}) {
|
|
|
1857
1871
|
};
|
|
1858
1872
|
}
|
|
1859
1873
|
async function validateStructuredOutputValue(schema, value) {
|
|
1860
|
-
|
|
1874
|
+
return validateWithCompile(await loadCompile(), schema, value);
|
|
1875
|
+
}
|
|
1876
|
+
function prepareStructuredOutputArguments(schema, args) {
|
|
1877
|
+
if (!args || typeof args !== "object" || !("value" in args)) return args;
|
|
1878
|
+
if (!loadedCompile) throw compileLoadError ?? new Error("Structured output validator is still loading; call structured_output again.");
|
|
1879
|
+
const validation = validateWithCompile(loadedCompile, schema, args.value);
|
|
1880
|
+
if (validation.status === "invalid") throw new Error(`Structured output validation failed: ${validation.message}`);
|
|
1881
|
+
return args;
|
|
1882
|
+
}
|
|
1883
|
+
function validateWithCompile(compile, schema, value) {
|
|
1861
1884
|
let validator;
|
|
1862
1885
|
try {
|
|
1863
1886
|
validator = compile(schema);
|
|
1864
1887
|
} catch (error) {
|
|
1865
1888
|
return { status: "invalid", message: `invalid outputSchema: ${error instanceof Error ? error.message : String(error)}` };
|
|
1866
1889
|
}
|
|
1867
|
-
|
|
1868
|
-
|
|
1890
|
+
let originalErrors;
|
|
1891
|
+
try {
|
|
1892
|
+
if (validator.Check(value)) return { status: "valid" };
|
|
1893
|
+
originalErrors = [...validator.Errors(value)];
|
|
1894
|
+
} catch (error) {
|
|
1895
|
+
return { status: "invalid", message: `outputSchema cannot be validated (cyclic or too deep): ${error instanceof Error ? error.message : String(error)}` };
|
|
1896
|
+
}
|
|
1869
1897
|
const errors = [];
|
|
1870
1898
|
const uniqueErrors = /* @__PURE__ */ new Set();
|
|
1871
1899
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -2245,9 +2273,9 @@ function acceptChildWatchdogEvent(input) {
|
|
|
2245
2273
|
...warnings?.length ? { warnings } : {}
|
|
2246
2274
|
};
|
|
2247
2275
|
}
|
|
2248
|
-
function applyChildWatchdogMessage(
|
|
2249
|
-
if (message?.role !== "assistant" || !
|
|
2250
|
-
return { ...
|
|
2276
|
+
function applyChildWatchdogMessage(current2, message) {
|
|
2277
|
+
if (message?.role !== "assistant" || !current2?.warnings?.some((entry) => !entry.addressed)) return void 0;
|
|
2278
|
+
return { ...current2, warnings: current2.warnings.map((entry) => entry.addressed ? entry : { ...entry, addressed: true }) };
|
|
2251
2279
|
}
|
|
2252
2280
|
function unresolvedChildWatchdogBlockers(progress) {
|
|
2253
2281
|
return (progress?.warnings ?? []).filter((warning) => warning.severity === "blocker" && (!warning.addressed || warning.stalemate));
|
|
@@ -3255,12 +3283,30 @@ function verifyRedactionEnv(env) {
|
|
|
3255
3283
|
return value.length >= 4 && SENSITIVE_ENV_KEY_PATTERN.test(key);
|
|
3256
3284
|
}));
|
|
3257
3285
|
}
|
|
3258
|
-
function
|
|
3286
|
+
function verifySecrets(env) {
|
|
3287
|
+
return [...new Set(Object.values(verifyRedactionEnv(env)).filter(Boolean))].sort((left, right) => right.length - left.length);
|
|
3288
|
+
}
|
|
3289
|
+
function redactSecrets(value, secrets) {
|
|
3259
3290
|
let redacted = value;
|
|
3260
|
-
const secrets = [...new Set(Object.values(verifyRedactionEnv(env)).filter(Boolean))].sort((left, right) => right.length - left.length);
|
|
3261
3291
|
for (const secret of secrets) redacted = redacted.replaceAll(secret, "[REDACTED]");
|
|
3262
3292
|
return redacted;
|
|
3263
3293
|
}
|
|
3294
|
+
function redactVerifyEnv(value, env) {
|
|
3295
|
+
return redactSecrets(value, verifySecrets(env));
|
|
3296
|
+
}
|
|
3297
|
+
function parseRedactedVerifyValue(text, secrets) {
|
|
3298
|
+
return JSON.parse(text, (_key, value, context) => {
|
|
3299
|
+
if (typeof value === "string") return redactSecrets(value, secrets);
|
|
3300
|
+
if (typeof value === "number" && secrets.length > 0) {
|
|
3301
|
+
const source = context?.source;
|
|
3302
|
+
return source !== void 0 && redactSecrets(source, secrets) === source ? value : "[REDACTED]";
|
|
3303
|
+
}
|
|
3304
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
3305
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [redactSecrets(key, secrets), item]));
|
|
3306
|
+
}
|
|
3307
|
+
return value;
|
|
3308
|
+
});
|
|
3309
|
+
}
|
|
3264
3310
|
var DEFAULT_VERIFY_TIMEOUT_MS = 12e4;
|
|
3265
3311
|
function hash(value) {
|
|
3266
3312
|
return createHash2("sha256").update(value).digest("hex");
|
|
@@ -3286,32 +3332,48 @@ function isCachedVerifyResult(value) {
|
|
|
3286
3332
|
return typeof result.id === "string" && typeof result.command === "string" && (typeof result.exitCode === "number" || result.exitCode === null) && (result.status === "passed" || result.status === "failed" || result.status === "timed-out" || result.status === "allowed-failure") && typeof result.durationMs === "number";
|
|
3287
3333
|
}
|
|
3288
3334
|
var TYPED_VERIFY_OUTPUT_MAX_BYTES = 12e3;
|
|
3289
|
-
async function applyTypedVerifyOutput(command, run) {
|
|
3335
|
+
async function applyTypedVerifyOutput(command, run, rawStdout) {
|
|
3290
3336
|
if (run.status !== "passed") return;
|
|
3291
|
-
const
|
|
3337
|
+
const secrets = verifySecrets(command.env);
|
|
3338
|
+
const stdout = rawStdout.trim();
|
|
3292
3339
|
const fail = (message) => {
|
|
3293
3340
|
run.status = "failed";
|
|
3294
|
-
run.structuredOutputError = message;
|
|
3341
|
+
run.structuredOutputError = redactSecrets(message, secrets);
|
|
3295
3342
|
};
|
|
3296
|
-
if (!stdout
|
|
3297
|
-
if (stdout.
|
|
3343
|
+
if (!stdout) return fail('output: "json" command printed nothing on stdout.');
|
|
3344
|
+
if (stdout.length > TYPED_VERIFY_OUTPUT_MAX_BYTES) return fail(`output: "json" stdout exceeded ${TYPED_VERIFY_OUTPUT_MAX_BYTES} characters and was truncated.`);
|
|
3298
3345
|
let value;
|
|
3299
3346
|
try {
|
|
3300
3347
|
value = JSON.parse(stdout);
|
|
3301
|
-
} catch
|
|
3302
|
-
|
|
3348
|
+
} catch {
|
|
3349
|
+
let reason = "parse failed";
|
|
3350
|
+
try {
|
|
3351
|
+
JSON.parse(redactSecrets(stdout, secrets));
|
|
3352
|
+
} catch (error) {
|
|
3353
|
+
reason = error instanceof Error ? error.message : String(error);
|
|
3354
|
+
}
|
|
3355
|
+
return fail(`output: "json" stdout is not valid JSON: ${reason}`);
|
|
3303
3356
|
}
|
|
3357
|
+
const redactedValue = parseRedactedVerifyValue(stdout, secrets);
|
|
3304
3358
|
if (command.schema) {
|
|
3305
3359
|
const validation = await validateStructuredOutputValue(command.schema, value);
|
|
3306
|
-
if (validation.status === "invalid")
|
|
3360
|
+
if (validation.status === "invalid") {
|
|
3361
|
+
const redactedValidation = await validateStructuredOutputValue(command.schema, redactedValue);
|
|
3362
|
+
return fail(`output: "json" stdout does not match gate.schema${redactedValidation.status === "invalid" ? `: ${redactedValidation.message}` : "."}`);
|
|
3363
|
+
}
|
|
3307
3364
|
}
|
|
3308
|
-
run.structuredOutput =
|
|
3365
|
+
run.structuredOutput = redactedValue;
|
|
3309
3366
|
}
|
|
3310
3367
|
function typedVerifyOutput(ledger) {
|
|
3311
3368
|
const run = ledger?.verifyRuns?.find((entry) => entry.structuredOutput !== void 0);
|
|
3312
3369
|
return run ? { value: run.structuredOutput } : void 0;
|
|
3313
3370
|
}
|
|
3314
3371
|
async function runMemoizedVerifyCommand(command, defaultCwd, options = {}) {
|
|
3372
|
+
if (command.output === "json") {
|
|
3373
|
+
const { run, rawStdout } = await runVerifyCommand(command, defaultCwd, options);
|
|
3374
|
+
await applyTypedVerifyOutput(command, run, rawStdout);
|
|
3375
|
+
return run;
|
|
3376
|
+
}
|
|
3315
3377
|
const cwd = command.cwd ? path8.resolve(defaultCwd, command.cwd) : defaultCwd;
|
|
3316
3378
|
let workspaceState;
|
|
3317
3379
|
try {
|
|
@@ -3319,8 +3381,8 @@ async function runMemoizedVerifyCommand(command, defaultCwd, options = {}) {
|
|
|
3319
3381
|
} catch {
|
|
3320
3382
|
workspaceState = void 0;
|
|
3321
3383
|
}
|
|
3322
|
-
if (!workspaceState || !options.artifactsDir || !options.runId
|
|
3323
|
-
return runVerifyCommand(command, defaultCwd, options);
|
|
3384
|
+
if (!workspaceState || !options.artifactsDir || !options.runId) {
|
|
3385
|
+
return (await runVerifyCommand(command, defaultCwd, options)).run;
|
|
3324
3386
|
}
|
|
3325
3387
|
const envKeys = Object.keys(command.env ?? {}).sort();
|
|
3326
3388
|
const envHash = hash(JSON.stringify(Object.fromEntries(Object.entries(effectiveVerifyEnv(command.env)).sort(([left], [right]) => left.localeCompare(right)))));
|
|
@@ -3344,7 +3406,7 @@ async function runMemoizedVerifyCommand(command, defaultCwd, options = {}) {
|
|
|
3344
3406
|
}
|
|
3345
3407
|
} catch {
|
|
3346
3408
|
}
|
|
3347
|
-
const result = await runVerifyCommand(command, defaultCwd, options);
|
|
3409
|
+
const { run: result } = await runVerifyCommand(command, defaultCwd, options);
|
|
3348
3410
|
const evidenced = { ...result, artifactPath, cacheKey, memoized: false, envKeys, envHash, workspaceState };
|
|
3349
3411
|
try {
|
|
3350
3412
|
fs8.mkdirSync(path8.dirname(artifactPath), { recursive: true });
|
|
@@ -3373,11 +3435,11 @@ function quoteExecutableForShell(command, platform = process.platform) {
|
|
|
3373
3435
|
const firstToken = trimmed.match(/^\S+/)?.[0];
|
|
3374
3436
|
if (/\.(?:exe|bat|cmd|com|ps1)$/i.test(firstToken ?? "")) return command;
|
|
3375
3437
|
const match = trimmed.match(/^([A-Za-z]:\\[^"<>|&*?\r\n]*?\s[^"<>|&*?\r\n]*?\\[^"<>|&*?\r\n]*?\.(?:exe|bat|cmd|com|ps1))(?=\s|$)/i);
|
|
3376
|
-
const
|
|
3377
|
-
if (
|
|
3378
|
-
const rest = trimmed.slice(
|
|
3438
|
+
const executable2 = match?.[1];
|
|
3439
|
+
if (executable2 && /\s/.test(executable2) && !/[A-Za-z]:\\/.test(executable2.slice(3))) {
|
|
3440
|
+
const rest = trimmed.slice(executable2.length);
|
|
3379
3441
|
const leading = command.slice(0, command.length - trimmed.length);
|
|
3380
|
-
return `${leading}"${
|
|
3442
|
+
return `${leading}"${executable2}"${rest}`;
|
|
3381
3443
|
}
|
|
3382
3444
|
const extensionlessSpacedFilenameMatch = trimmed.match(/^([A-Za-z]:\\[^"<>|&*?\r\n]*?\s[^"<>|&*?\r\n]*?)(?=\s+--|$)/i);
|
|
3383
3445
|
const extensionlessSpacedFilename = extensionlessSpacedFilenameMatch?.[1];
|
|
@@ -3396,7 +3458,7 @@ function quoteExecutableForShell(command, platform = process.platform) {
|
|
|
3396
3458
|
return command;
|
|
3397
3459
|
}
|
|
3398
3460
|
function runVerifyCommand(command, defaultCwd, options = {}) {
|
|
3399
|
-
return new Promise((
|
|
3461
|
+
return new Promise((resolve12) => {
|
|
3400
3462
|
const startedAt = Date.now();
|
|
3401
3463
|
const cwd = command.cwd ? path8.resolve(defaultCwd, command.cwd) : defaultCwd;
|
|
3402
3464
|
let stdout = "";
|
|
@@ -3417,12 +3479,15 @@ function runVerifyCommand(command, defaultCwd, options = {}) {
|
|
|
3417
3479
|
clearTimeout(timeout);
|
|
3418
3480
|
if (hardKill) clearTimeout(hardKill);
|
|
3419
3481
|
options.signal?.removeEventListener("abort", abortVerification);
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3482
|
+
resolve12({
|
|
3483
|
+
run: {
|
|
3484
|
+
id: command.id,
|
|
3485
|
+
command: command.command,
|
|
3486
|
+
cwd,
|
|
3487
|
+
durationMs: Date.now() - startedAt,
|
|
3488
|
+
...result
|
|
3489
|
+
},
|
|
3490
|
+
rawStdout: stdout
|
|
3426
3491
|
});
|
|
3427
3492
|
};
|
|
3428
3493
|
const abortVerification = () => {
|
|
@@ -3544,7 +3609,6 @@ async function evaluateAcceptance(input) {
|
|
|
3544
3609
|
artifactsDir: input.artifactsDir,
|
|
3545
3610
|
runId: input.runId
|
|
3546
3611
|
});
|
|
3547
|
-
if (command.output === "json") await applyTypedVerifyOutput(command, run);
|
|
3548
3612
|
ledger.verifyRuns.push(run);
|
|
3549
3613
|
if (input.signal?.aborted) break;
|
|
3550
3614
|
}
|
|
@@ -4102,11 +4166,11 @@ function resolveMemoryDir(rootDir, scopedPath) {
|
|
|
4102
4166
|
return { error: "memory root must not be a symlink" };
|
|
4103
4167
|
}
|
|
4104
4168
|
const rootReal = fs9.existsSync(rootDir) ? fs9.realpathSync(rootDir) : path9.resolve(rootDir);
|
|
4105
|
-
let
|
|
4169
|
+
let current2 = rootDir;
|
|
4106
4170
|
for (const segment of segments) {
|
|
4107
|
-
|
|
4108
|
-
if (!fs9.existsSync(
|
|
4109
|
-
const currentReal = fs9.realpathSync(
|
|
4171
|
+
current2 = path9.join(current2, segment);
|
|
4172
|
+
if (!fs9.existsSync(current2)) break;
|
|
4173
|
+
const currentReal = fs9.realpathSync(current2);
|
|
4110
4174
|
if (!isWithin(currentReal, rootReal)) {
|
|
4111
4175
|
return { error: "memory path resolves outside the memory root" };
|
|
4112
4176
|
}
|
|
@@ -4224,7 +4288,20 @@ function buildAgentMemoryInjection(agent, cwd) {
|
|
|
4224
4288
|
// src/runs/shared/permissions.ts
|
|
4225
4289
|
import * as fs10 from "node:fs";
|
|
4226
4290
|
import * as path10 from "node:path";
|
|
4227
|
-
|
|
4291
|
+
|
|
4292
|
+
// src/shared/wait-tool-name.ts
|
|
4293
|
+
var DEFAULT_WAIT_TOOL_NAME = "bg_wait";
|
|
4294
|
+
var current = DEFAULT_WAIT_TOOL_NAME;
|
|
4295
|
+
function waitToolName() {
|
|
4296
|
+
return current;
|
|
4297
|
+
}
|
|
4298
|
+
function setWaitToolName(name) {
|
|
4299
|
+
current = name;
|
|
4300
|
+
}
|
|
4301
|
+
|
|
4302
|
+
// src/runs/shared/permissions.ts
|
|
4303
|
+
var COORDINATION_TOOLS = /* @__PURE__ */ new Set(["contact_supervisor", "intercom", "structured_output"]);
|
|
4304
|
+
var isInternalTool = (tool) => COORDINATION_TOOLS.has(tool) || tool === waitToolName();
|
|
4228
4305
|
var DECISIONS = /* @__PURE__ */ new Set(["allow", "ask", "deny"]);
|
|
4229
4306
|
var MAX_POLICY_BYTES = 16 * 1024;
|
|
4230
4307
|
var MAX_PREVIEW_BYTES = 2048;
|
|
@@ -4240,7 +4317,7 @@ function validatePermissionRules(value, label) {
|
|
|
4240
4317
|
for (const [tool, decision] of Object.entries(value)) {
|
|
4241
4318
|
if (!tool.trim()) throw new Error(`${label} contains an empty tool name.`);
|
|
4242
4319
|
if (tool === "bash") throw new Error(`${label}.bash is unsupported; pi-subagents leaves bash policy to pi-guard.`);
|
|
4243
|
-
if (
|
|
4320
|
+
if (isInternalTool(tool) || tool === DEFAULT_WAIT_TOOL_NAME) throw new Error(`${label}.${tool} is reserved for child coordination and cannot be gated.`);
|
|
4244
4321
|
if (!DECISIONS.has(decision)) throw new Error(`${label}.${tool} must be allow, ask, or deny.`);
|
|
4245
4322
|
result[tool] = decision;
|
|
4246
4323
|
}
|
|
@@ -4260,7 +4337,7 @@ function resolvePermissionRules(globalConfig, agentRules) {
|
|
|
4260
4337
|
return Object.keys(merged).length ? merged : void 0;
|
|
4261
4338
|
}
|
|
4262
4339
|
function permissionDecision(rules, toolName) {
|
|
4263
|
-
if (toolName === "bash" ||
|
|
4340
|
+
if (toolName === "bash" || isInternalTool(toolName)) return "allow";
|
|
4264
4341
|
return rules?.[toolName] ?? "allow";
|
|
4265
4342
|
}
|
|
4266
4343
|
function redact(value, key = "", depth = 0) {
|
|
@@ -4379,7 +4456,7 @@ function formatAvailableAgentLines(agents) {
|
|
|
4379
4456
|
const short = description.length > MAX_LISTED_DESCRIPTION_CHARS ? `${description.slice(0, MAX_LISTED_DESCRIPTION_CHARS - 1).trimEnd()}\u2026` : description;
|
|
4380
4457
|
return `- ${agent.name} (${agent.source})${short ? ` \u2014 ${short}` : ""}`;
|
|
4381
4458
|
});
|
|
4382
|
-
if (sorted.length > MAX_LISTED_AGENTS) lines.push(`+${sorted.length - MAX_LISTED_AGENTS} more; {action:"list"}`);
|
|
4459
|
+
if (sorted.length > MAX_LISTED_AGENTS) lines.push(`+${sorted.length - MAX_LISTED_AGENTS} more; {action:"list", options:{search:"<term>"}}`);
|
|
4383
4460
|
return lines.length ? lines : ["- (none)"];
|
|
4384
4461
|
}
|
|
4385
4462
|
function suggestAgentName(name, agents) {
|
|
@@ -5092,19 +5169,18 @@ function readSubagentSettings(filePath) {
|
|
|
5092
5169
|
const subagentsObject = subagents;
|
|
5093
5170
|
let disableBuiltins;
|
|
5094
5171
|
if ("disableBuiltins" in subagentsObject) {
|
|
5095
|
-
if (typeof subagentsObject.disableBuiltins === "boolean")
|
|
5096
|
-
|
|
5097
|
-
} else {
|
|
5098
|
-
throw new Error(`Subagent settings in '${filePath}' have invalid 'disableBuiltins'; expected a boolean.`);
|
|
5099
|
-
}
|
|
5172
|
+
if (typeof subagentsObject.disableBuiltins === "boolean") disableBuiltins = subagentsObject.disableBuiltins;
|
|
5173
|
+
else throw new Error(`Subagent settings in '${filePath}' have invalid 'disableBuiltins'; expected a boolean.`);
|
|
5100
5174
|
}
|
|
5101
5175
|
let disableThinking;
|
|
5102
5176
|
if ("disableThinking" in subagentsObject) {
|
|
5103
|
-
if (typeof subagentsObject.disableThinking === "boolean")
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5177
|
+
if (typeof subagentsObject.disableThinking === "boolean") disableThinking = subagentsObject.disableThinking;
|
|
5178
|
+
else throw new Error(`Subagent settings in '${filePath}' have invalid 'disableThinking'; expected a boolean.`);
|
|
5179
|
+
}
|
|
5180
|
+
let defaultInheritGlobalContext;
|
|
5181
|
+
if ("defaultInheritGlobalContext" in subagentsObject) {
|
|
5182
|
+
if (typeof subagentsObject.defaultInheritGlobalContext === "boolean") defaultInheritGlobalContext = subagentsObject.defaultInheritGlobalContext;
|
|
5183
|
+
else throw new Error(`Subagent settings in '${filePath}' have invalid 'defaultInheritGlobalContext'; expected a boolean.`);
|
|
5108
5184
|
}
|
|
5109
5185
|
let defaultModel;
|
|
5110
5186
|
if ("defaultModel" in subagentsObject) {
|
|
@@ -5187,6 +5263,7 @@ function readSubagentSettings(filePath) {
|
|
|
5187
5263
|
...maxThinking !== void 0 ? { maxThinking } : {},
|
|
5188
5264
|
...defaultExtensions !== void 0 ? { defaultExtensions } : {},
|
|
5189
5265
|
...defaultSubagentOnlyExtensions !== void 0 ? { defaultSubagentOnlyExtensions } : {},
|
|
5266
|
+
...defaultInheritGlobalContext !== void 0 ? { defaultInheritGlobalContext } : {},
|
|
5190
5267
|
...agentScanDirs !== void 0 ? { agentScanDirs } : {},
|
|
5191
5268
|
...agentExcludeDirs !== void 0 ? { agentExcludeDirs } : {},
|
|
5192
5269
|
...disableBuiltins !== void 0 ? { disableBuiltins } : {},
|
|
@@ -5302,13 +5379,30 @@ function applySubagentDefaultSubagentOnlyExtensions(agents, defaultSubagentOnlyE
|
|
|
5302
5379
|
return next;
|
|
5303
5380
|
});
|
|
5304
5381
|
}
|
|
5305
|
-
function
|
|
5306
|
-
return
|
|
5307
|
-
|
|
5308
|
-
|
|
5309
|
-
|
|
5382
|
+
function resolveSubagentDefaultInheritGlobalContext(userSettings, projectSettings, projectSettingsPath) {
|
|
5383
|
+
if (projectSettingsPath && projectSettings.defaultInheritGlobalContext !== void 0) return projectSettings.defaultInheritGlobalContext;
|
|
5384
|
+
return userSettings.defaultInheritGlobalContext;
|
|
5385
|
+
}
|
|
5386
|
+
function applySubagentDefaultInheritGlobalContext(agents, defaultInheritGlobalContext) {
|
|
5387
|
+
if (!defaultInheritGlobalContext) return agents;
|
|
5388
|
+
return agents.map((agent) => {
|
|
5389
|
+
const frontmatterFields = agentFrontmatterFields.get(agent);
|
|
5390
|
+
if (agent.inheritGlobalContext || frontmatterFields?.has("inheritGlobalContext")) return agent;
|
|
5391
|
+
const next = { ...agent, inheritGlobalContext: true };
|
|
5392
|
+
if (frontmatterFields) agentFrontmatterFields.set(next, frontmatterFields);
|
|
5393
|
+
return next;
|
|
5394
|
+
});
|
|
5395
|
+
}
|
|
5396
|
+
function applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions, defaultInheritGlobalContext) {
|
|
5397
|
+
return applySubagentDefaultInheritGlobalContext(
|
|
5398
|
+
applySubagentDefaultSubagentOnlyExtensions(
|
|
5399
|
+
applySubagentDefaultExtensions(
|
|
5400
|
+
applySubagentDefaultThinking(applySubagentDefaultModel(agents, defaultModel, defaultProvider), defaultThinking),
|
|
5401
|
+
defaultExtensions
|
|
5402
|
+
),
|
|
5403
|
+
defaultSubagentOnlyExtensions
|
|
5310
5404
|
),
|
|
5311
|
-
|
|
5405
|
+
defaultInheritGlobalContext
|
|
5312
5406
|
);
|
|
5313
5407
|
}
|
|
5314
5408
|
function applyToolsOverride(target, toolsOverride) {
|
|
@@ -5328,7 +5422,8 @@ function applyBuiltinOverride(agent, override, meta) {
|
|
|
5328
5422
|
...meta,
|
|
5329
5423
|
base: agent.override?.base ?? cloneOverrideBase(agent),
|
|
5330
5424
|
fields: [.../* @__PURE__ */ new Set([...agent.override?.fields ?? [], ...Object.keys(override)])].sort(),
|
|
5331
|
-
fieldScopes: Object.fromEntries(Object.entries({ ...agent.override?.fieldScopes ?? {} }).map(([field, scopes]) => [field, [...scopes]]))
|
|
5425
|
+
fieldScopes: Object.fromEntries(Object.entries({ ...agent.override?.fieldScopes ?? {} }).map(([field, scopes]) => [field, [...scopes]])),
|
|
5426
|
+
paths: { ...agent.override?.paths, [meta.scope]: meta.path }
|
|
5332
5427
|
};
|
|
5333
5428
|
for (const field of Object.keys(override)) {
|
|
5334
5429
|
const scopes = overrideInfo.fieldScopes[field] ?? [];
|
|
@@ -5432,10 +5527,12 @@ function applyBuiltinOverrides(builtinAgents, userSettings, projectSettings, use
|
|
|
5432
5527
|
};
|
|
5433
5528
|
return builtinAgents.map((agent) => {
|
|
5434
5529
|
const projectOverride = projectSettings.overrides[agent.name];
|
|
5530
|
+
const userOverride = userSettings.overrides[agent.name];
|
|
5435
5531
|
if (projectOverride && projectSettingsPath) {
|
|
5532
|
+
const withUserOverride = userOverride ? applyBuiltinOverride(agent, userOverride, { scope: "user", path: userSettingsPath }) : agent;
|
|
5436
5533
|
return applyGlobalThinking(
|
|
5437
|
-
applyBuiltinOverride(
|
|
5438
|
-
projectOverride.thinking !== void 0
|
|
5534
|
+
applyBuiltinOverride(withUserOverride, projectOverride, { scope: "project", path: projectSettingsPath }),
|
|
5535
|
+
projectOverride.thinking !== void 0 || !projectThinkingConfigured && userOverride?.thinking !== void 0
|
|
5439
5536
|
);
|
|
5440
5537
|
}
|
|
5441
5538
|
if (projectBulkDisabled && projectSettingsPath) {
|
|
@@ -5444,7 +5541,6 @@ function applyBuiltinOverrides(builtinAgents, userSettings, projectSettings, use
|
|
|
5444
5541
|
false
|
|
5445
5542
|
);
|
|
5446
5543
|
}
|
|
5447
|
-
const userOverride = userSettings.overrides[agent.name];
|
|
5448
5544
|
if (userOverride) {
|
|
5449
5545
|
return applyGlobalThinking(
|
|
5450
5546
|
applyBuiltinOverride(agent, userOverride, { scope: "user", path: userSettingsPath }),
|
|
@@ -5511,9 +5607,9 @@ function removeBuiltinAgentOverride(cwd, name, scope, options) {
|
|
|
5511
5607
|
const agentOverrides = nextSubagents.agentOverrides;
|
|
5512
5608
|
if (!agentOverrides || typeof agentOverrides !== "object" || Array.isArray(agentOverrides)) return { path: filePath, removed: false, machinePreserved: false };
|
|
5513
5609
|
const nextOverrides = { ...agentOverrides };
|
|
5514
|
-
const
|
|
5610
|
+
const current2 = nextOverrides[name];
|
|
5515
5611
|
if (!Object.prototype.hasOwnProperty.call(nextOverrides, name)) return { path: filePath, removed: false, machinePreserved: false };
|
|
5516
|
-
const configuredMachine =
|
|
5612
|
+
const configuredMachine = current2 && typeof current2 === "object" && !Array.isArray(current2) ? current2.machine : void 0;
|
|
5517
5613
|
const machine = configuredMachine === false || typeof configuredMachine === "string" && configuredMachine.trim() ? configuredMachine : void 0;
|
|
5518
5614
|
if (options?.preserveMachine && machine !== void 0) nextOverrides[name] = { machine };
|
|
5519
5615
|
else delete nextOverrides[name];
|
|
@@ -5653,11 +5749,11 @@ function inspectAgentDefinitionDirectory(dir, operations = DEFAULT_AGENT_DEFINIT
|
|
|
5653
5749
|
let unreadable = false;
|
|
5654
5750
|
const visitedDirectories = /* @__PURE__ */ new Set();
|
|
5655
5751
|
const inspectedDirectories = /* @__PURE__ */ new Set();
|
|
5656
|
-
const visit = (
|
|
5657
|
-
inspectedDirectories.add(path11.resolve(
|
|
5752
|
+
const visit = (current2) => {
|
|
5753
|
+
inspectedDirectories.add(path11.resolve(current2));
|
|
5658
5754
|
let realDir;
|
|
5659
5755
|
try {
|
|
5660
|
-
realDir = operations.realpathSync?.(
|
|
5756
|
+
realDir = operations.realpathSync?.(current2) ?? path11.resolve(current2);
|
|
5661
5757
|
} catch {
|
|
5662
5758
|
unreadable = true;
|
|
5663
5759
|
return;
|
|
@@ -5666,13 +5762,13 @@ function inspectAgentDefinitionDirectory(dir, operations = DEFAULT_AGENT_DEFINIT
|
|
|
5666
5762
|
visitedDirectories.add(realDir);
|
|
5667
5763
|
let entries;
|
|
5668
5764
|
try {
|
|
5669
|
-
entries = operations.readdirSync(
|
|
5765
|
+
entries = operations.readdirSync(current2).sort((a, b) => a.name.localeCompare(b.name));
|
|
5670
5766
|
} catch {
|
|
5671
5767
|
unreadable = true;
|
|
5672
5768
|
return;
|
|
5673
5769
|
}
|
|
5674
5770
|
for (const entry of entries) {
|
|
5675
|
-
const filePath = path11.join(
|
|
5771
|
+
const filePath = path11.join(current2, entry.name);
|
|
5676
5772
|
if (isExcluded(filePath)) continue;
|
|
5677
5773
|
let isDirectory2 = entry.isDirectory();
|
|
5678
5774
|
if (entry.isSymbolicLink()) {
|
|
@@ -6161,11 +6257,11 @@ function addDirectoryWatchPaths(paths, root, files, directories = []) {
|
|
|
6161
6257
|
}
|
|
6162
6258
|
for (const file of files) {
|
|
6163
6259
|
paths.add(path11.resolve(file));
|
|
6164
|
-
let
|
|
6165
|
-
while (isPathWithin(resolvedRoot,
|
|
6166
|
-
paths.add(
|
|
6167
|
-
if (
|
|
6168
|
-
|
|
6260
|
+
let current2 = path11.resolve(path11.dirname(file));
|
|
6261
|
+
while (isPathWithin(resolvedRoot, current2)) {
|
|
6262
|
+
paths.add(current2);
|
|
6263
|
+
if (current2 === resolvedRoot) break;
|
|
6264
|
+
current2 = path11.dirname(current2);
|
|
6169
6265
|
}
|
|
6170
6266
|
}
|
|
6171
6267
|
}
|
|
@@ -6206,12 +6302,12 @@ function discoveryCacheKey(cwd, preferredModelProvider, globalNpmRoot, projectTr
|
|
|
6206
6302
|
}
|
|
6207
6303
|
function projectDiscoveryWatchPaths(cwd) {
|
|
6208
6304
|
const paths = [];
|
|
6209
|
-
let
|
|
6305
|
+
let current2 = path11.resolve(cwd);
|
|
6210
6306
|
while (true) {
|
|
6211
|
-
paths.push(getProjectConfigDir(
|
|
6212
|
-
const parent = path11.dirname(
|
|
6213
|
-
if (parent ===
|
|
6214
|
-
|
|
6307
|
+
paths.push(getProjectConfigDir(current2), path11.join(current2, ".agents"), path11.join(current2, ".git"));
|
|
6308
|
+
const parent = path11.dirname(current2);
|
|
6309
|
+
if (parent === current2) break;
|
|
6310
|
+
current2 = parent;
|
|
6215
6311
|
}
|
|
6216
6312
|
return paths;
|
|
6217
6313
|
}
|
|
@@ -6315,7 +6411,7 @@ function getAgentDiscoverySources(cwd, preferredModelProvider, includeChains = f
|
|
|
6315
6411
|
const key = discoveryCacheKey(cwd, preferredModelProvider, globalNpmRoot, projectTrusted);
|
|
6316
6412
|
const cached = agentDiscoveryCache.get(key);
|
|
6317
6413
|
if (cached && cached.fingerprint === discoveryFingerprint(cached.sources)) {
|
|
6318
|
-
if (includeChains) {
|
|
6414
|
+
if (includeChains && !cached.sources.userChains) {
|
|
6319
6415
|
ensureDiscoveryChains(cached.sources);
|
|
6320
6416
|
cached.fingerprint = discoveryFingerprint(cached.sources);
|
|
6321
6417
|
}
|
|
@@ -6358,7 +6454,8 @@ function configuredAgentsForScope(sources, scope, settingsScope = scope) {
|
|
|
6358
6454
|
const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, sources.projectSettingsPath);
|
|
6359
6455
|
const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, sources.projectSettingsPath);
|
|
6360
6456
|
const defaultSubagentOnlyExtensions = resolveSubagentDefaultSubagentOnlyExtensions(userSettings, projectSettings, sources.projectSettingsPath);
|
|
6361
|
-
const
|
|
6457
|
+
const defaultInheritGlobalContext = resolveSubagentDefaultInheritGlobalContext(userSettings, projectSettings, sources.projectSettingsPath);
|
|
6458
|
+
const applyDefaults = (agents) => applySubagentDefaults(agents, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions, defaultInheritGlobalContext);
|
|
6362
6459
|
const builtin = applyBuiltinOverrides(applyDefaults(sources.builtinLoaded.agents), userSettings, projectSettings, sources.userSettingsPath, sources.projectSettingsPath);
|
|
6363
6460
|
const user = applyCustomAgentOverrides(
|
|
6364
6461
|
applyDefaults(scope === "project" ? [] : sources.userLoaded.flatMap((loaded) => loaded.loaded.agents)),
|
|
@@ -6506,13 +6603,14 @@ function discoverAgentsUncached(cwd, scope, preferredModelProvider, options = {}
|
|
|
6506
6603
|
const maxThinking = resolveSubagentMaxThinking(userSettings, projectSettings, projectSettingsPath);
|
|
6507
6604
|
const defaultExtensions = resolveSubagentDefaultExtensions(userSettings, projectSettings, projectSettingsPath);
|
|
6508
6605
|
const defaultSubagentOnlyExtensions = resolveSubagentDefaultSubagentOnlyExtensions(userSettings, projectSettings, projectSettingsPath);
|
|
6606
|
+
const defaultInheritGlobalContext = resolveSubagentDefaultInheritGlobalContext(userSettings, projectSettings, projectSettingsPath);
|
|
6509
6607
|
const modelScope = projectSettings.modelScope ?? userSettings.modelScope;
|
|
6510
6608
|
const injectAgents = projectSettings.injectAgents !== void 0 ? projectSettings.injectAgents : userSettings.injectAgents;
|
|
6511
6609
|
const packageSubagentPaths = collectPackageSubagentPaths(effectiveCwd, { includeUser: scope !== "project", includeProject: scope !== "user", globalNpmRoot: options.globalNpmRoot });
|
|
6512
6610
|
const isExcluded = agentExclusions(agentExclusionRoots(userSettingsPath, projectSettingsPath));
|
|
6513
6611
|
const directories = [reportAgentDefinitionDirectory("builtin", BUILTIN_AGENTS_DIR, BUILTIN_AGENT_DEFINITION_INSPECTION)];
|
|
6514
6612
|
const builtinLoaded = loadAgentsFromDefinitionFiles(BUILTIN_AGENT_DEFINITION_FILES, "builtin");
|
|
6515
|
-
const applyDefaults = (agents2) => applySubagentDefaults(agents2, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions);
|
|
6613
|
+
const applyDefaults = (agents2) => applySubagentDefaults(agents2, defaultModel, defaultProvider, defaultThinking, defaultExtensions, defaultSubagentOnlyExtensions, defaultInheritGlobalContext);
|
|
6516
6614
|
const builtinAgents = applyBuiltinOverrides(applyDefaults(builtinLoaded.agents), userSettings, projectSettings, userSettingsPath, projectSettingsPath);
|
|
6517
6615
|
const userScanDirs = settingsAgentScanDirs(userSettings.agentScanDirs ?? [], isExcluded);
|
|
6518
6616
|
const projectScanDirs = settingsAgentScanDirs(projectSettings.agentScanDirs ?? [], isExcluded);
|
|
@@ -6556,11 +6654,82 @@ function discoverAgentsAll(cwd, preferredModelProvider, options = {}) {
|
|
|
6556
6654
|
}
|
|
6557
6655
|
|
|
6558
6656
|
// src/runs/shared/child-launch-plan.ts
|
|
6559
|
-
import * as
|
|
6657
|
+
import * as path14 from "node:path";
|
|
6560
6658
|
|
|
6561
6659
|
// src/runs/shared/single-output.ts
|
|
6660
|
+
import * as fs13 from "node:fs";
|
|
6661
|
+
import * as path13 from "node:path";
|
|
6662
|
+
|
|
6663
|
+
// src/runs/shared/rex-machine.ts
|
|
6664
|
+
import { spawnSync as spawnSync4 } from "node:child_process";
|
|
6562
6665
|
import * as fs12 from "node:fs";
|
|
6666
|
+
import * as os4 from "node:os";
|
|
6563
6667
|
import * as path12 from "node:path";
|
|
6668
|
+
var REX_LOCAL_MACHINE = "local";
|
|
6669
|
+
var REX_EXIT_GONE = 3;
|
|
6670
|
+
var REX_EXIT_UNREACHABLE = 4;
|
|
6671
|
+
function isRexLocalMachine(machine) {
|
|
6672
|
+
return machine?.provider === "rex" && !("target" in machine);
|
|
6673
|
+
}
|
|
6674
|
+
var REX_BUNDLE_BIN = "Library/Application Support/com.superlogical.rex/RexServer/Versions/Current/Rex Server.app/Contents/MacOS/rex";
|
|
6675
|
+
var REX_CALL_TIMEOUT_MS = 15e3;
|
|
6676
|
+
var REX_MAX_OUTPUT = 1024 * 1024;
|
|
6677
|
+
function rexGlobalArgs(server) {
|
|
6678
|
+
return server ? ["--autostart=false", "-S", server] : ["--autostart=false"];
|
|
6679
|
+
}
|
|
6680
|
+
function executable(file) {
|
|
6681
|
+
try {
|
|
6682
|
+
fs12.accessSync(file, fs12.constants.X_OK);
|
|
6683
|
+
return fs12.statSync(file).isFile();
|
|
6684
|
+
} catch {
|
|
6685
|
+
return false;
|
|
6686
|
+
}
|
|
6687
|
+
}
|
|
6688
|
+
function resolveRexBinary(env = process.env) {
|
|
6689
|
+
const fromDir = env.REX_BIN_DIR ? [path12.join(env.REX_BIN_DIR, "rex")] : [];
|
|
6690
|
+
const fromPath = (env.PATH ?? "").split(path12.delimiter).filter((dir) => path12.isAbsolute(dir)).map((dir) => path12.join(dir, "rex"));
|
|
6691
|
+
const found = [...fromDir, ...fromPath, path12.join(os4.homedir(), REX_BUNDLE_BIN)].find(executable);
|
|
6692
|
+
if (!found) throw new Error("The Rex CLI was not found: set REX_BIN_DIR, put rex on PATH, or install Rex.");
|
|
6693
|
+
return found;
|
|
6694
|
+
}
|
|
6695
|
+
function rexCommandEnv(source = process.env) {
|
|
6696
|
+
const { REX_SESSION: _session, REX_BLOCK: _block, REX_SERVER: _server, ...env } = source;
|
|
6697
|
+
return env;
|
|
6698
|
+
}
|
|
6699
|
+
function sessionConfirmed(stdout, session) {
|
|
6700
|
+
try {
|
|
6701
|
+
const parsed = JSON.parse(stdout);
|
|
6702
|
+
return parsed?.session_id === session;
|
|
6703
|
+
} catch {
|
|
6704
|
+
return false;
|
|
6705
|
+
}
|
|
6706
|
+
}
|
|
6707
|
+
function resolveRexLocalPlacement(input) {
|
|
6708
|
+
if (process.platform === "win32") throw new Error("Machine 'local' runs the child in a Rex pane, which is not supported on Windows.");
|
|
6709
|
+
const env = input.env ?? process.env, session = env.REX_SESSION?.trim(), server = env.REX_SERVER?.trim();
|
|
6710
|
+
if (!session) throw new Error("Machine 'local' opens the child in a new tab of this Rex session, but this Pi is not running inside Rex (REX_SESSION is not set).");
|
|
6711
|
+
const result = spawnSync4(resolveRexBinary(env), [...rexGlobalArgs(server), "session", "inspect", session, "--json"], { encoding: "utf8", env: rexCommandEnv(env), timeout: REX_CALL_TIMEOUT_MS, maxBuffer: REX_MAX_OUTPUT, windowsHide: true });
|
|
6712
|
+
if (result.error) throw new Error(`Could not ask Rex about this session: ${result.error.message}`, { cause: result.error });
|
|
6713
|
+
if (result.status === REX_EXIT_GONE) throw new Error(`Machine 'local' needs this Pi's Rex session, but the Rex server does not know session ${session}.`);
|
|
6714
|
+
if (result.status === REX_EXIT_UNREACHABLE) throw new Error("Machine 'local' needs the Rex server, but it is unreachable.");
|
|
6715
|
+
if (result.status !== 0) throw new Error(`rex session inspect exited with code ${result.status}: ${(result.stderr || result.stdout).trim().slice(0, 512)}`);
|
|
6716
|
+
if (!sessionConfirmed(result.stdout, session)) throw new Error(`The Rex server did not confirm session ${session}.`);
|
|
6717
|
+
const stepCwd = input.stepCwd?.trim();
|
|
6718
|
+
const home = stepCwd === "~" || stepCwd?.startsWith("~/") ? path12.join(os4.homedir(), stepCwd.slice(1)) : void 0;
|
|
6719
|
+
const requested = home ?? (stepCwd ? path12.resolve(input.cwd, stepCwd) : input.cwd);
|
|
6720
|
+
let cwd;
|
|
6721
|
+
try {
|
|
6722
|
+
cwd = fs12.realpathSync(requested);
|
|
6723
|
+
} catch (error) {
|
|
6724
|
+
throw new Error(`Machine 'local' cwd does not exist: ${requested}.`, { cause: error });
|
|
6725
|
+
}
|
|
6726
|
+
if (!fs12.statSync(cwd).isDirectory()) throw new Error(`Machine 'local' cwd is not a directory: ${requested}.`);
|
|
6727
|
+
const machine = { provider: "rex", id: REX_LOCAL_MACHINE, session, cwd };
|
|
6728
|
+
if (server) machine.server = server;
|
|
6729
|
+
return machine;
|
|
6730
|
+
}
|
|
6731
|
+
|
|
6732
|
+
// src/runs/shared/single-output.ts
|
|
6564
6733
|
var READ_ONLY_OUTPUT_TOOLS = /* @__PURE__ */ new Set([
|
|
6565
6734
|
"read",
|
|
6566
6735
|
"grep",
|
|
@@ -6589,7 +6758,7 @@ function snapshotFromStatError(error) {
|
|
|
6589
6758
|
}
|
|
6590
6759
|
function extractChildWrittenOutput(messages, outputPath, cwd) {
|
|
6591
6760
|
if (!messages?.length || !outputPath) return void 0;
|
|
6592
|
-
const resolvedTarget =
|
|
6761
|
+
const resolvedTarget = path13.resolve(cwd ?? ".", outputPath);
|
|
6593
6762
|
const comparableTarget = process.platform === "win32" ? resolvedTarget.toLowerCase() : resolvedTarget;
|
|
6594
6763
|
const successfulCallIds = /* @__PURE__ */ new Set();
|
|
6595
6764
|
for (const message of messages) {
|
|
@@ -6604,7 +6773,7 @@ function extractChildWrittenOutput(messages, outputPath, cwd) {
|
|
|
6604
6773
|
if (part.type !== "toolCall" || part.name !== "write" || !successfulCallIds.has(part.id)) continue;
|
|
6605
6774
|
const args = typeof part.arguments === "object" && part.arguments !== null && !Array.isArray(part.arguments) ? part.arguments : {};
|
|
6606
6775
|
if (typeof args.path !== "string" || typeof args.content !== "string") continue;
|
|
6607
|
-
const resolvedWritePath =
|
|
6776
|
+
const resolvedWritePath = path13.resolve(cwd ?? ".", args.path);
|
|
6608
6777
|
const comparableWritePath = process.platform === "win32" ? resolvedWritePath.toLowerCase() : resolvedWritePath;
|
|
6609
6778
|
if (comparableWritePath !== comparableTarget) continue;
|
|
6610
6779
|
content = args.content;
|
|
@@ -6620,10 +6789,10 @@ function normalizeSingleOutputOverride(output, defaultOutput) {
|
|
|
6620
6789
|
}
|
|
6621
6790
|
function resolveSingleOutputPath(output, runtimeCwd, requestedCwd, relativeBaseDir) {
|
|
6622
6791
|
if (typeof output !== "string" || !output || output === "false" || output === "true") return void 0;
|
|
6623
|
-
if (
|
|
6624
|
-
if (relativeBaseDir) return
|
|
6625
|
-
const baseCwd = requestedCwd ?
|
|
6626
|
-
return
|
|
6792
|
+
if (path13.isAbsolute(output)) return output;
|
|
6793
|
+
if (relativeBaseDir) return path13.resolve(relativeBaseDir, output);
|
|
6794
|
+
const baseCwd = requestedCwd ? path13.isAbsolute(requestedCwd) ? requestedCwd : path13.resolve(runtimeCwd, requestedCwd) : runtimeCwd;
|
|
6795
|
+
return path13.resolve(baseCwd, output);
|
|
6627
6796
|
}
|
|
6628
6797
|
function requestedOutputPathFromTask(task) {
|
|
6629
6798
|
for (const line of task.split(/\r?\n/).reverse()) {
|
|
@@ -6637,12 +6806,13 @@ function requestedOutputPathFromTask(task) {
|
|
|
6637
6806
|
function outputPathMappingFromTask(task, savedPath) {
|
|
6638
6807
|
const requestedPath = requestedOutputPathFromTask(task);
|
|
6639
6808
|
if (!requestedPath || !savedPath) return void 0;
|
|
6640
|
-
if (
|
|
6809
|
+
if (path13.isAbsolute(requestedPath) && path13.normalize(requestedPath) === path13.normalize(savedPath)) return void 0;
|
|
6641
6810
|
return { requestedPath, savedPath };
|
|
6642
6811
|
}
|
|
6643
|
-
function injectSingleOutputInstruction(task, outputPath, capabilities) {
|
|
6812
|
+
function injectSingleOutputInstruction(task, outputPath, capabilities, machine) {
|
|
6644
6813
|
if (!outputPath) return task;
|
|
6645
|
-
const
|
|
6814
|
+
const remote = machine !== void 0 && !isRexLocalMachine(machine);
|
|
6815
|
+
const delivery = !remote && (!capabilities || hasOutputWriteCapability(capabilities.tools, capabilities.mcpDirectTools)) ? `Write your findings to exactly this path: ${outputPath}` : [
|
|
6646
6816
|
"Return the complete artifact in your final response.",
|
|
6647
6817
|
`The runtime will persist it to exactly this path: ${outputPath}`,
|
|
6648
6818
|
"Do not call contact_supervisor merely because no write-capable tool is available."
|
|
@@ -6674,7 +6844,7 @@ function formatByteSize(bytes) {
|
|
|
6674
6844
|
return `${value.toFixed(1)} ${units[unitIndex]}`;
|
|
6675
6845
|
}
|
|
6676
6846
|
function formatSavedOutputReference(savedPath, fullOutput) {
|
|
6677
|
-
const absolutePath =
|
|
6847
|
+
const absolutePath = path13.resolve(savedPath);
|
|
6678
6848
|
const bytes = Buffer.byteLength(fullOutput, "utf-8");
|
|
6679
6849
|
const lines = countLines(fullOutput);
|
|
6680
6850
|
return {
|
|
@@ -6690,9 +6860,9 @@ var SAVED_OUTPUT_LINE = /\n\nOutput saved to: (.+) \([^()\n]*\)\. Read this file
|
|
|
6690
6860
|
var MAX_UNFILED_TRAILING_BLOCKS = 8;
|
|
6691
6861
|
function readFullOutputFile(filePath) {
|
|
6692
6862
|
try {
|
|
6693
|
-
const stat =
|
|
6863
|
+
const stat = fs13.statSync(filePath);
|
|
6694
6864
|
if (!stat.isFile() || stat.size > MAX_FULL_OUTPUT_FILE_BYTES) return void 0;
|
|
6695
|
-
return
|
|
6865
|
+
return fs13.readFileSync(filePath, "utf-8");
|
|
6696
6866
|
} catch {
|
|
6697
6867
|
return void 0;
|
|
6698
6868
|
}
|
|
@@ -6710,7 +6880,7 @@ function fileBackedHead(output, fullOutput, maxTrailingBlocks) {
|
|
|
6710
6880
|
}
|
|
6711
6881
|
function capInlineOutput(output, files) {
|
|
6712
6882
|
const match = files.savedPath ? output.match(SAVED_OUTPUT_LINE) : null;
|
|
6713
|
-
const savedLine = match && files.savedPath && match[1] ===
|
|
6883
|
+
const savedLine = match && files.savedPath && match[1] === path13.resolve(files.savedPath) ? match : void 0;
|
|
6714
6884
|
const body = savedLine ? output.slice(0, savedLine.index) : output;
|
|
6715
6885
|
const filePath = savedLine ? files.savedPath : files.artifactPath;
|
|
6716
6886
|
if (body.length <= INLINE_OUTPUT_HEAD_CHARS || !filePath) return output;
|
|
@@ -6750,15 +6920,15 @@ function validateFileOnlyOutputMode(outputMode, outputPath, context) {
|
|
|
6750
6920
|
return void 0;
|
|
6751
6921
|
}
|
|
6752
6922
|
function resolveSingleOutputClaimPath(outputPath) {
|
|
6753
|
-
let existing =
|
|
6923
|
+
let existing = path13.resolve(outputPath);
|
|
6754
6924
|
const missingSegments = [];
|
|
6755
|
-
while (!
|
|
6756
|
-
missingSegments.unshift(
|
|
6757
|
-
const parent =
|
|
6925
|
+
while (!fs13.existsSync(existing)) {
|
|
6926
|
+
missingSegments.unshift(path13.basename(existing));
|
|
6927
|
+
const parent = path13.dirname(existing);
|
|
6758
6928
|
if (parent === existing) break;
|
|
6759
6929
|
existing = parent;
|
|
6760
6930
|
}
|
|
6761
|
-
return
|
|
6931
|
+
return path13.join(fs13.realpathSync(existing), ...missingSegments);
|
|
6762
6932
|
}
|
|
6763
6933
|
function outputClaimError(outputPath, expectedClaimPath) {
|
|
6764
6934
|
if (expectedClaimPath && resolveSingleOutputClaimPath(outputPath) !== expectedClaimPath) return "Output path changed after it was claimed.";
|
|
@@ -6767,7 +6937,7 @@ function outputClaimError(outputPath, expectedClaimPath) {
|
|
|
6767
6937
|
function captureSingleOutputSnapshot(outputPath) {
|
|
6768
6938
|
if (!outputPath) return void 0;
|
|
6769
6939
|
try {
|
|
6770
|
-
const stat =
|
|
6940
|
+
const stat = fs13.statSync(outputPath);
|
|
6771
6941
|
return { exists: true, mtimeMs: stat.mtimeMs, size: stat.size };
|
|
6772
6942
|
} catch (error) {
|
|
6773
6943
|
return snapshotFromStatError(error);
|
|
@@ -6776,7 +6946,7 @@ function captureSingleOutputSnapshot(outputPath) {
|
|
|
6776
6946
|
function inspectSingleOutputChange(outputPath, beforeRun) {
|
|
6777
6947
|
if (beforeRun?.error) return { changed: false, error: beforeRun.error };
|
|
6778
6948
|
try {
|
|
6779
|
-
const stat =
|
|
6949
|
+
const stat = fs13.statSync(outputPath);
|
|
6780
6950
|
return {
|
|
6781
6951
|
changed: !beforeRun?.exists || stat.mtimeMs !== beforeRun.mtimeMs || stat.size !== beforeRun.size
|
|
6782
6952
|
};
|
|
@@ -6795,8 +6965,8 @@ function persistSingleOutput(outputPath, fullOutput, expectedClaimPath) {
|
|
|
6795
6965
|
try {
|
|
6796
6966
|
const claimError = outputClaimError(outputPath, expectedClaimPath);
|
|
6797
6967
|
if (claimError) return { error: claimError, fatalError: true };
|
|
6798
|
-
|
|
6799
|
-
|
|
6968
|
+
fs13.mkdirSync(path13.dirname(outputPath), { recursive: true });
|
|
6969
|
+
fs13.writeFileSync(outputPath, fullOutput, "utf-8");
|
|
6800
6970
|
return { savedPath: outputPath };
|
|
6801
6971
|
} catch (err) {
|
|
6802
6972
|
return { error: err instanceof Error ? err.message : String(err) };
|
|
@@ -6815,7 +6985,7 @@ function resolveSingleOutput(outputPath, fallbackOutput, beforeRun, expectedClai
|
|
|
6815
6985
|
}
|
|
6816
6986
|
if (changedSinceStart.changed) {
|
|
6817
6987
|
try {
|
|
6818
|
-
return { fullOutput:
|
|
6988
|
+
return { fullOutput: fs13.readFileSync(outputPath, "utf-8"), savedPath: outputPath };
|
|
6819
6989
|
} catch (error) {
|
|
6820
6990
|
return {
|
|
6821
6991
|
fullOutput: fallbackOutput,
|
|
@@ -6919,12 +7089,12 @@ function planChildLaunch(input) {
|
|
|
6919
7089
|
input.originalTask
|
|
6920
7090
|
);
|
|
6921
7091
|
const inheritedRelativeParallelOutput = Boolean(
|
|
6922
|
-
input.parallelOutputNamespace && input.stepOverrides.output === void 0 && typeof behavior.output === "string" && !
|
|
7092
|
+
input.parallelOutputNamespace && input.stepOverrides.output === void 0 && typeof behavior.output === "string" && !path14.isAbsolute(behavior.output)
|
|
6923
7093
|
);
|
|
6924
7094
|
if (inheritedRelativeParallelOutput && input.parallelOutputNamespace?.taskIndex !== void 0) {
|
|
6925
7095
|
behavior = {
|
|
6926
7096
|
...behavior,
|
|
6927
|
-
output:
|
|
7097
|
+
output: path14.join(
|
|
6928
7098
|
`parallel-${input.parallelOutputNamespace.stepIndex}`,
|
|
6929
7099
|
`${input.parallelOutputNamespace.taskIndex}-${input.agentConfig.name}`,
|
|
6930
7100
|
behavior.output
|
|
@@ -6956,8 +7126,8 @@ var Semaphore = class {
|
|
|
6956
7126
|
this.available--;
|
|
6957
7127
|
return Promise.resolve();
|
|
6958
7128
|
}
|
|
6959
|
-
return new Promise((
|
|
6960
|
-
this.queue.push(
|
|
7129
|
+
return new Promise((resolve12) => {
|
|
7130
|
+
this.queue.push(resolve12);
|
|
6961
7131
|
});
|
|
6962
7132
|
}
|
|
6963
7133
|
release() {
|
|
@@ -6989,47 +7159,47 @@ function getStepAgents(step) {
|
|
|
6989
7159
|
return [step.agent];
|
|
6990
7160
|
}
|
|
6991
7161
|
function cleanupOldChainDirs() {
|
|
6992
|
-
if (!
|
|
7162
|
+
if (!fs14.existsSync(CHAIN_RUNS_DIR)) return;
|
|
6993
7163
|
const now = Date.now();
|
|
6994
7164
|
let dirs;
|
|
6995
7165
|
try {
|
|
6996
|
-
dirs =
|
|
7166
|
+
dirs = fs14.readdirSync(CHAIN_RUNS_DIR);
|
|
6997
7167
|
} catch {
|
|
6998
7168
|
return;
|
|
6999
7169
|
}
|
|
7000
7170
|
for (const dir of dirs) {
|
|
7001
7171
|
try {
|
|
7002
|
-
const dirPath =
|
|
7003
|
-
const stat =
|
|
7172
|
+
const dirPath = path15.join(CHAIN_RUNS_DIR, dir);
|
|
7173
|
+
const stat = fs14.statSync(dirPath);
|
|
7004
7174
|
if (stat.isDirectory() && now - stat.mtimeMs > CHAIN_DIR_MAX_AGE_MS) {
|
|
7005
|
-
|
|
7175
|
+
fs14.rmSync(dirPath, { recursive: true });
|
|
7006
7176
|
}
|
|
7007
7177
|
} catch {
|
|
7008
7178
|
}
|
|
7009
7179
|
}
|
|
7010
7180
|
}
|
|
7011
7181
|
function expandHomePath(filePath) {
|
|
7012
|
-
if (filePath === "~") return
|
|
7013
|
-
if (filePath.startsWith("~/")) return
|
|
7182
|
+
if (filePath === "~") return os5.homedir();
|
|
7183
|
+
if (filePath.startsWith("~/")) return path15.join(os5.homedir(), filePath.slice(2));
|
|
7014
7184
|
return filePath;
|
|
7015
7185
|
}
|
|
7016
7186
|
function resolveChainPath(filePath, chainDir) {
|
|
7017
7187
|
const expanded = expandHomePath(filePath);
|
|
7018
|
-
return
|
|
7188
|
+
return path15.isAbsolute(expanded) ? expanded : path15.join(chainDir, expanded);
|
|
7019
7189
|
}
|
|
7020
7190
|
function resolveExistingReadInstructionPaths(reads, instructionCwd, existenceCwd = instructionCwd) {
|
|
7021
7191
|
return reads.flatMap((filePath) => {
|
|
7022
7192
|
const instructionPath = resolveChainPath(filePath, instructionCwd);
|
|
7023
7193
|
const existencePath = resolveChainPath(filePath, existenceCwd);
|
|
7024
|
-
return
|
|
7194
|
+
return fs14.existsSync(existencePath) ? [instructionPath] : [];
|
|
7025
7195
|
});
|
|
7026
7196
|
}
|
|
7027
7197
|
function resolveExistingReadPaths(reads, cwd) {
|
|
7028
7198
|
return resolveExistingReadInstructionPaths(reads, cwd);
|
|
7029
7199
|
}
|
|
7030
7200
|
function writeInitialProgressFile(progressDir) {
|
|
7031
|
-
|
|
7032
|
-
|
|
7201
|
+
fs14.mkdirSync(progressDir, { recursive: true });
|
|
7202
|
+
fs14.writeFileSync(path15.join(progressDir, "progress.md"), INITIAL_PROGRESS_CONTENT);
|
|
7033
7203
|
}
|
|
7034
7204
|
function buildChainInstructions(behavior, chainDir, isFirstProgressAgent, previousSummary, readExistenceDir = chainDir) {
|
|
7035
7205
|
const prefixParts = [];
|
|
@@ -7043,7 +7213,7 @@ function buildChainInstructions(behavior, chainDir, isFirstProgressAgent, previo
|
|
|
7043
7213
|
prefixParts.push(`[Write to: ${outputPath}]`);
|
|
7044
7214
|
}
|
|
7045
7215
|
if (behavior.progress) {
|
|
7046
|
-
const progressPath =
|
|
7216
|
+
const progressPath = path15.join(chainDir, "progress.md");
|
|
7047
7217
|
if (isFirstProgressAgent) {
|
|
7048
7218
|
suffixParts.push(`Create and maintain progress at: ${progressPath}`);
|
|
7049
7219
|
} else {
|
|
@@ -7282,15 +7452,19 @@ function stripTrailingDateStamp(segment) {
|
|
|
7282
7452
|
if (compact && isPlausibleDateStamp(compact[2], compact[3], compact[4])) return compact[1];
|
|
7283
7453
|
return segment;
|
|
7284
7454
|
}
|
|
7285
|
-
function isRegisteredProvider(provider, availableModels) {
|
|
7455
|
+
function isRegisteredProvider(provider, availableModels, knownProviders) {
|
|
7286
7456
|
const normalized = normalizeModelSegment(provider);
|
|
7287
|
-
return availableModels.some((entry) => normalizeModelSegment(entry.provider) === normalized);
|
|
7457
|
+
return availableModels.some((entry) => normalizeModelSegment(entry.provider) === normalized) || (knownProviders?.().some((name) => normalizeModelSegment(name) === normalized) ?? false);
|
|
7288
7458
|
}
|
|
7289
|
-
function
|
|
7459
|
+
function knownModelProviders(registry) {
|
|
7460
|
+
let providers;
|
|
7461
|
+
return () => providers ??= [...new Set(registry.getAll().map((model) => model.provider))];
|
|
7462
|
+
}
|
|
7463
|
+
function splitQualifiedModelQuery(baseModel, availableModels, knownProviders) {
|
|
7290
7464
|
const slashIdx = baseModel.indexOf("/");
|
|
7291
7465
|
if (slashIdx !== -1) {
|
|
7292
7466
|
const providerPart = baseModel.slice(0, slashIdx);
|
|
7293
|
-
if (isRegisteredProvider(providerPart, availableModels)) {
|
|
7467
|
+
if (isRegisteredProvider(providerPart, availableModels, knownProviders)) {
|
|
7294
7468
|
return { queryProvider: normalizeModelSegment(providerPart), queryIdRaw: baseModel.slice(slashIdx + 1) };
|
|
7295
7469
|
}
|
|
7296
7470
|
return { queryIdRaw: baseModel };
|
|
@@ -7300,7 +7474,7 @@ function splitQualifiedModelQuery(baseModel, availableModels) {
|
|
|
7300
7474
|
const separatorIdx = baseModel.indexOf(separator);
|
|
7301
7475
|
if (separatorIdx <= 0) continue;
|
|
7302
7476
|
const providerPart = baseModel.slice(0, separatorIdx);
|
|
7303
|
-
if (!isRegisteredProvider(providerPart, availableModels)) continue;
|
|
7477
|
+
if (!isRegisteredProvider(providerPart, availableModels, knownProviders)) continue;
|
|
7304
7478
|
return { queryProvider: normalizeModelSegment(providerPart), queryIdRaw: baseModel.slice(separatorIdx + 1) };
|
|
7305
7479
|
}
|
|
7306
7480
|
return { queryIdRaw: baseModel };
|
|
@@ -7314,22 +7488,22 @@ function resolveExactIdMatches(baseModel, availableModels, preferredProvider) {
|
|
|
7314
7488
|
if (exactMatches.length === 1) return exactMatches[0].fullId;
|
|
7315
7489
|
return void 0;
|
|
7316
7490
|
}
|
|
7317
|
-
function resolveBaseModelCandidate(baseModel, availableModels, preferredProvider) {
|
|
7491
|
+
function resolveBaseModelCandidate(baseModel, availableModels, preferredProvider, knownProviders) {
|
|
7318
7492
|
const exact = availableModels.find((entry) => entry.fullId === baseModel);
|
|
7319
7493
|
if (exact) return exact.fullId;
|
|
7320
|
-
const { queryProvider } = splitQualifiedModelQuery(baseModel, availableModels);
|
|
7494
|
+
const { queryProvider } = splitQualifiedModelQuery(baseModel, availableModels, knownProviders);
|
|
7321
7495
|
if (queryProvider === void 0) {
|
|
7322
7496
|
const exactId = resolveExactIdMatches(baseModel, availableModels, preferredProvider);
|
|
7323
7497
|
if (exactId) return exactId;
|
|
7324
7498
|
}
|
|
7325
|
-
const fuzzy = fuzzyResolveModel(baseModel, availableModels, preferredProvider);
|
|
7499
|
+
const fuzzy = fuzzyResolveModel(baseModel, availableModels, preferredProvider, knownProviders);
|
|
7326
7500
|
if (fuzzy || queryProvider === void 0) return fuzzy;
|
|
7327
7501
|
const queryId = normalizeModelSegment(baseModel);
|
|
7328
7502
|
const prefixedIdMatches = availableModels.filter((entry) => normalizeModelSegment(entry.id) === queryId && normalizeModelSegment(entry.provider) === queryProvider);
|
|
7329
7503
|
return prefixedIdMatches.length === 1 ? prefixedIdMatches[0].fullId : void 0;
|
|
7330
7504
|
}
|
|
7331
|
-
function fuzzyResolveModel(baseModel, availableModels, preferredProvider) {
|
|
7332
|
-
const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels);
|
|
7505
|
+
function fuzzyResolveModel(baseModel, availableModels, preferredProvider, knownProviders) {
|
|
7506
|
+
const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels, knownProviders);
|
|
7333
7507
|
const queryId = normalizeModelSegment(queryIdRaw);
|
|
7334
7508
|
const queryIdNoDate = stripTrailingDateStamp(queryId);
|
|
7335
7509
|
const candidates = availableModels.filter((entry) => {
|
|
@@ -7347,41 +7521,41 @@ function fuzzyResolveModel(baseModel, availableModels, preferredProvider) {
|
|
|
7347
7521
|
if (candidates.length === 1) return candidates[0].fullId;
|
|
7348
7522
|
return void 0;
|
|
7349
7523
|
}
|
|
7350
|
-
function resolveModelCandidate(model, availableModels, preferredProvider) {
|
|
7524
|
+
function resolveModelCandidate(model, availableModels, preferredProvider, knownProviders) {
|
|
7351
7525
|
if (!model) return void 0;
|
|
7352
7526
|
if (!availableModels || availableModels.length === 0) return model;
|
|
7353
|
-
const resolvedWhole = resolveBaseModelCandidate(model, availableModels, preferredProvider);
|
|
7527
|
+
const resolvedWhole = resolveBaseModelCandidate(model, availableModels, preferredProvider, knownProviders);
|
|
7354
7528
|
if (resolvedWhole) return resolvedWhole;
|
|
7355
7529
|
const { baseModel, thinkingSuffix } = splitKnownThinkingSuffix(model);
|
|
7356
7530
|
if (!thinkingSuffix) return model;
|
|
7357
|
-
const resolvedBase = resolveBaseModelCandidate(baseModel, availableModels, preferredProvider);
|
|
7531
|
+
const resolvedBase = resolveBaseModelCandidate(baseModel, availableModels, preferredProvider, knownProviders);
|
|
7358
7532
|
if (resolvedBase) return `${resolvedBase}${thinkingSuffix}`;
|
|
7359
7533
|
return model;
|
|
7360
7534
|
}
|
|
7361
|
-
function resolveSubagentModelCandidate(model, availableModels, preferredProvider) {
|
|
7535
|
+
function resolveSubagentModelCandidate(model, availableModels, preferredProvider, knownProviders) {
|
|
7362
7536
|
if (!availableModels || availableModels.length === 0) return model;
|
|
7363
|
-
const resolvedWhole = resolveBaseModelCandidate(model, availableModels, preferredProvider);
|
|
7537
|
+
const resolvedWhole = resolveBaseModelCandidate(model, availableModels, preferredProvider, knownProviders);
|
|
7364
7538
|
if (resolvedWhole) return resolvedWhole;
|
|
7365
7539
|
const { baseModel, thinkingSuffix } = splitKnownThinkingSuffix(model);
|
|
7366
|
-
const resolvedBase = thinkingSuffix ? resolveBaseModelCandidate(baseModel, availableModels, preferredProvider) : void 0;
|
|
7540
|
+
const resolvedBase = thinkingSuffix ? resolveBaseModelCandidate(baseModel, availableModels, preferredProvider, knownProviders) : void 0;
|
|
7367
7541
|
return resolvedBase ? `${resolvedBase}${thinkingSuffix}` : void 0;
|
|
7368
7542
|
}
|
|
7369
|
-
function suggestAlternateProviderModel(model, availableModels) {
|
|
7543
|
+
function suggestAlternateProviderModel(model, availableModels, knownProviders) {
|
|
7370
7544
|
if (!availableModels || availableModels.length === 0) return void 0;
|
|
7371
7545
|
const { baseModel, thinkingSuffix } = splitKnownThinkingSuffix(model);
|
|
7372
|
-
const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels);
|
|
7546
|
+
const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels, knownProviders);
|
|
7373
7547
|
if (queryProvider === void 0) return void 0;
|
|
7374
|
-
const suggestion = resolveBaseModelCandidate(queryIdRaw, availableModels);
|
|
7548
|
+
const suggestion = resolveBaseModelCandidate(queryIdRaw, availableModels) ?? resolveBaseModelCandidate(baseModel, availableModels);
|
|
7375
7549
|
if (!suggestion) return void 0;
|
|
7376
7550
|
const matched = availableModels.find((entry) => entry.fullId === suggestion);
|
|
7377
7551
|
if (!matched || normalizeModelSegment(matched.provider) === queryProvider) return void 0;
|
|
7378
7552
|
return `${suggestion}${thinkingSuffix}`;
|
|
7379
7553
|
}
|
|
7380
7554
|
var MAX_MODEL_CANDIDATES = 5;
|
|
7381
|
-
function closestModelCandidates(model, availableModels) {
|
|
7555
|
+
function closestModelCandidates(model, availableModels, knownProviders) {
|
|
7382
7556
|
if (!availableModels || availableModels.length === 0) return [];
|
|
7383
7557
|
const { baseModel, thinkingSuffix } = splitKnownThinkingSuffix(model);
|
|
7384
|
-
const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels);
|
|
7558
|
+
const { queryProvider, queryIdRaw } = splitQualifiedModelQuery(baseModel, availableModels, knownProviders);
|
|
7385
7559
|
const queryId = normalizeModelSegment(queryIdRaw);
|
|
7386
7560
|
const queryIdNoDate = stripTrailingDateStamp(queryId);
|
|
7387
7561
|
return availableModels.map((entry) => {
|
|
@@ -7396,11 +7570,16 @@ function closestModelCandidates(model, availableModels) {
|
|
|
7396
7570
|
};
|
|
7397
7571
|
}).filter((entry) => entry.sameId || entry.close).sort((left, right) => Number(right.sameId) - Number(left.sameId) || left.distance - right.distance || Number(right.sameProvider) - Number(left.sameProvider) || left.fullId.localeCompare(right.fullId)).slice(0, MAX_MODEL_CANDIDATES).map((entry) => `${entry.fullId}${thinkingSuffix}`);
|
|
7398
7572
|
}
|
|
7399
|
-
function
|
|
7400
|
-
const
|
|
7573
|
+
function isUnavailableSubagentModel(model, availableModels, preferredProvider, knownProviders) {
|
|
7574
|
+
const trimmed = model?.trim();
|
|
7575
|
+
if (!trimmed || trimmed === INHERIT_MODEL || !availableModels?.length) return false;
|
|
7576
|
+
return resolveSubagentModelCandidate(trimmed, availableModels, preferredProvider, knownProviders) === void 0;
|
|
7577
|
+
}
|
|
7578
|
+
function resolveRequiredSubagentModelCandidate(model, availableModels, preferredProvider, knownProviders) {
|
|
7579
|
+
const resolved = resolveSubagentModelCandidate(model, availableModels, preferredProvider, knownProviders);
|
|
7401
7580
|
if (resolved) return resolved;
|
|
7402
|
-
const suggestion = suggestAlternateProviderModel(model, availableModels);
|
|
7403
|
-
const candidates = closestModelCandidates(model, availableModels).filter((candidate) => candidate !== suggestion);
|
|
7581
|
+
const suggestion = suggestAlternateProviderModel(model, availableModels, knownProviders);
|
|
7582
|
+
const candidates = closestModelCandidates(model, availableModels, knownProviders).filter((candidate) => candidate !== suggestion);
|
|
7404
7583
|
throw new Error(
|
|
7405
7584
|
`Unknown subagent model '${model}' in the active Pi model registry.${suggestion ? ` Did you mean '${suggestion}'?` : ""}${candidates.length ? ` Closest registry models: ${candidates.join(", ")}.` : ""}`
|
|
7406
7585
|
);
|
|
@@ -7429,22 +7608,15 @@ function resolveSubagentModelOverride(requestedModel, parentModel, availableMode
|
|
|
7429
7608
|
const explicit = trimmed && trimmed !== INHERIT_MODEL ? trimmed : void 0;
|
|
7430
7609
|
if (!parentModel) throwForUnresolvedEnforcedReservedScope(options?.scope, explicit === void 0 || options?.source === "inherited");
|
|
7431
7610
|
let resolved;
|
|
7432
|
-
let resolvedFromRegistry = explicit === void 0;
|
|
7433
7611
|
if (explicit === void 0) {
|
|
7434
7612
|
resolved = parentModel ? `${parentModel.provider}/${parentModel.id}` : void 0;
|
|
7613
|
+
} else if (options?.source === "explicit") {
|
|
7614
|
+
resolved = resolveRequiredSubagentModelCandidate(explicit, availableModels, preferredProvider, options.knownProviders);
|
|
7435
7615
|
} else {
|
|
7436
|
-
|
|
7437
|
-
if (
|
|
7438
|
-
resolved = candidate ?? resolveRequiredSubagentModelCandidate(explicit, availableModels, preferredProvider);
|
|
7439
|
-
resolvedFromRegistry = true;
|
|
7440
|
-
} else if (candidate) {
|
|
7441
|
-
resolved = candidate;
|
|
7442
|
-
resolvedFromRegistry = true;
|
|
7443
|
-
} else {
|
|
7444
|
-
resolved = explicit;
|
|
7445
|
-
}
|
|
7616
|
+
resolved = resolveSubagentModelCandidate(explicit, availableModels, preferredProvider, options?.knownProviders);
|
|
7617
|
+
if (!resolved) return explicit;
|
|
7446
7618
|
}
|
|
7447
|
-
if (resolved && options?.scope
|
|
7619
|
+
if (resolved && options?.scope) {
|
|
7448
7620
|
const source = explicit === void 0 ? "inherited" : options.source ?? "inherited";
|
|
7449
7621
|
enforceModelScopes(resolved, options.scope, source, options.onWarn);
|
|
7450
7622
|
}
|
|
@@ -7485,12 +7657,11 @@ function resolveModelSelection(model, availableModels, preferredProvider, option
|
|
|
7485
7657
|
const origin = options?.origin ?? (options?.primaryModelFromParent ? "inherited" : "configured");
|
|
7486
7658
|
const requestedModel = origin === "inherited" ? void 0 : model;
|
|
7487
7659
|
const scopes = configuredScopes(options?.scope);
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7660
|
+
let resolved = model?.trim();
|
|
7661
|
+
if (model && (origin === "explicit" || origin !== "inherited" && !options?.primaryModelFromParent)) {
|
|
7662
|
+
resolved = resolveRequiredSubagentModelCandidate(model.trim(), availableModels, preferredProvider, options?.knownProviders);
|
|
7663
|
+
if (origin === "explicit") enforceModelScopes(resolved, scopes, "explicit", options?.onWarn);
|
|
7492
7664
|
}
|
|
7493
|
-
const resolved = model && (origin === "inherited" || origin === "explicit" || options?.primaryModelFromParent) ? model.trim() : model ? resolveRequiredSubagentModelCandidate(model.trim(), availableModels, preferredProvider) : void 0;
|
|
7494
7665
|
if (resolved && scopes.some((scope) => scope.enforce === true && scope.strict === true)) {
|
|
7495
7666
|
enforceModelScopes(resolved, scopes, "inherited", options?.onWarn);
|
|
7496
7667
|
}
|
|
@@ -7527,7 +7698,7 @@ var PI_CODING_AGENT_PACKAGE_ROOT_ENV = "PI_SUBAGENTS_PI_CODING_AGENT_PACKAGE_ROO
|
|
|
7527
7698
|
var PROMPT_REDACTED = "[prompt redacted]";
|
|
7528
7699
|
var SUBAGENT_STOPPED_MESSAGE = "Subagent stopped.";
|
|
7529
7700
|
var SUBAGENT_TIMED_OUT_MESSAGE = "Subagent timed out.";
|
|
7530
|
-
function resolveWatchPath(watchPath, nativeRealpath =
|
|
7701
|
+
function resolveWatchPath(watchPath, nativeRealpath = fs15.realpathSync.native) {
|
|
7531
7702
|
try {
|
|
7532
7703
|
return nativeRealpath(watchPath);
|
|
7533
7704
|
} catch {
|
|
@@ -7540,7 +7711,7 @@ function validConfigDirName(value) {
|
|
|
7540
7711
|
function readConfigDirNameFromPackageRoot(packageRoot) {
|
|
7541
7712
|
if (!packageRoot) return void 0;
|
|
7542
7713
|
try {
|
|
7543
|
-
const pkg = JSON.parse(
|
|
7714
|
+
const pkg = JSON.parse(fs15.readFileSync(path16.join(packageRoot, "package.json"), "utf-8"));
|
|
7544
7715
|
if (pkg.name !== PI_CODING_AGENT_PACKAGE_NAME) return void 0;
|
|
7545
7716
|
return validConfigDirName(pkg.piConfig?.configDir);
|
|
7546
7717
|
} catch {
|
|
@@ -7552,11 +7723,11 @@ function resolveConfigDirNameFromPackageJson(entryPoint = process.argv[1], packa
|
|
|
7552
7723
|
if (packageRootValue) return packageRootValue;
|
|
7553
7724
|
if (!entryPoint) return void 0;
|
|
7554
7725
|
try {
|
|
7555
|
-
let dir =
|
|
7556
|
-
while (dir !==
|
|
7726
|
+
let dir = path16.dirname(fs15.realpathSync(entryPoint));
|
|
7727
|
+
while (dir !== path16.dirname(dir)) {
|
|
7557
7728
|
const value = readConfigDirNameFromPackageRoot(dir);
|
|
7558
7729
|
if (value) return value;
|
|
7559
|
-
dir =
|
|
7730
|
+
dir = path16.dirname(dir);
|
|
7560
7731
|
}
|
|
7561
7732
|
} catch {
|
|
7562
7733
|
}
|
|
@@ -7578,14 +7749,14 @@ function getConfigDirName() {
|
|
|
7578
7749
|
return value;
|
|
7579
7750
|
}
|
|
7580
7751
|
function getProjectConfigDir(projectRoot) {
|
|
7581
|
-
return
|
|
7752
|
+
return path16.join(projectRoot, getConfigDirName());
|
|
7582
7753
|
}
|
|
7583
7754
|
function getAgentDir() {
|
|
7584
7755
|
const configured = process.env.PI_CODING_AGENT_DIR;
|
|
7585
|
-
const home = process.env.HOME || process.env.USERPROFILE ||
|
|
7756
|
+
const home = process.env.HOME || process.env.USERPROFILE || os6.homedir();
|
|
7586
7757
|
if (configured === "~") return home;
|
|
7587
|
-
if (configured?.startsWith("~/") || configured?.startsWith("~\\")) return
|
|
7588
|
-
return configured ||
|
|
7758
|
+
if (configured?.startsWith("~/") || configured?.startsWith("~\\")) return path16.join(home, configured.slice(2));
|
|
7759
|
+
return configured || path16.join(home, getConfigDirName(), "agent");
|
|
7589
7760
|
}
|
|
7590
7761
|
var statusCache = /* @__PURE__ */ new Map();
|
|
7591
7762
|
var MAX_STATUS_CACHE_ENTRIES = 512;
|
|
@@ -7594,19 +7765,19 @@ function getErrorMessage(error) {
|
|
|
7594
7765
|
}
|
|
7595
7766
|
function resolveChildCwd(baseCwd, childCwd) {
|
|
7596
7767
|
if (!childCwd) return baseCwd;
|
|
7597
|
-
return
|
|
7768
|
+
return path16.isAbsolute(childCwd) ? childCwd : path16.resolve(baseCwd, childCwd);
|
|
7598
7769
|
}
|
|
7599
7770
|
function isNotFoundError(error) {
|
|
7600
7771
|
return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
7601
7772
|
}
|
|
7602
7773
|
function readStatus(asyncDir) {
|
|
7603
|
-
if (Buffer.byteLength(
|
|
7774
|
+
if (Buffer.byteLength(path16.basename(asyncDir), "utf-8") > 255) {
|
|
7604
7775
|
return null;
|
|
7605
7776
|
}
|
|
7606
|
-
const statusPath =
|
|
7777
|
+
const statusPath = path16.join(asyncDir, "status.json");
|
|
7607
7778
|
let stat;
|
|
7608
7779
|
try {
|
|
7609
|
-
stat =
|
|
7780
|
+
stat = fs15.statSync(statusPath);
|
|
7610
7781
|
} catch (error) {
|
|
7611
7782
|
if (isNotFoundError(error)) {
|
|
7612
7783
|
statusCache.delete(statusPath);
|
|
@@ -7624,7 +7795,7 @@ function readStatus(asyncDir) {
|
|
|
7624
7795
|
}
|
|
7625
7796
|
let content;
|
|
7626
7797
|
try {
|
|
7627
|
-
content =
|
|
7798
|
+
content = fs15.readFileSync(statusPath, "utf-8");
|
|
7628
7799
|
} catch (error) {
|
|
7629
7800
|
if (isNotFoundError(error)) {
|
|
7630
7801
|
statusCache.delete(statusPath);
|
|
@@ -7664,12 +7835,12 @@ function readStatus(asyncDir) {
|
|
|
7664
7835
|
return status;
|
|
7665
7836
|
}
|
|
7666
7837
|
function findLatestSessionFile(sessionDir) {
|
|
7667
|
-
if (!
|
|
7668
|
-
const files =
|
|
7669
|
-
const filePath =
|
|
7838
|
+
if (!fs15.existsSync(sessionDir)) return null;
|
|
7839
|
+
const files = fs15.readdirSync(sessionDir).filter((f) => f.endsWith(".jsonl")).map((f) => {
|
|
7840
|
+
const filePath = path16.join(sessionDir, f);
|
|
7670
7841
|
return {
|
|
7671
7842
|
path: filePath,
|
|
7672
|
-
mtime:
|
|
7843
|
+
mtime: fs15.statSync(filePath).mtimeMs
|
|
7673
7844
|
};
|
|
7674
7845
|
}).sort((a, b) => b.mtime - a.mtime);
|
|
7675
7846
|
const latest = files[0];
|
|
@@ -7720,6 +7891,10 @@ function getFinalOutput(messages) {
|
|
|
7720
7891
|
function getSingleResultOutput(result) {
|
|
7721
7892
|
return result.finalOutput ?? getFinalOutput(result.messages ?? []);
|
|
7722
7893
|
}
|
|
7894
|
+
var TRUNCATED_RESPONSE_ERROR = "Response was truncated: the model reached its maximum output length.";
|
|
7895
|
+
function getTerminalAssistantStopReason(messages) {
|
|
7896
|
+
return messages.findLast((message) => message.role === "assistant")?.stopReason;
|
|
7897
|
+
}
|
|
7723
7898
|
function getDisplayItems(messages) {
|
|
7724
7899
|
if (!messages || messages.length === 0) return [];
|
|
7725
7900
|
const items = [];
|
|
@@ -7975,12 +8150,12 @@ function stripSkillFrontmatter(content) {
|
|
|
7975
8150
|
return normalized.slice(endIndex + 4).trim();
|
|
7976
8151
|
}
|
|
7977
8152
|
function isWithinPath(filePath, dir) {
|
|
7978
|
-
const relative6 =
|
|
7979
|
-
return relative6 === "" || !relative6.startsWith("..") && !
|
|
8153
|
+
const relative6 = path17.relative(dir, filePath);
|
|
8154
|
+
return relative6 === "" || !relative6.startsWith("..") && !path17.isAbsolute(relative6);
|
|
7980
8155
|
}
|
|
7981
8156
|
function readOptionalJsonFile(filePath, label) {
|
|
7982
8157
|
try {
|
|
7983
|
-
return JSON.parse(
|
|
8158
|
+
return JSON.parse(fs16.readFileSync(filePath, "utf-8"));
|
|
7984
8159
|
} catch (error) {
|
|
7985
8160
|
const code = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
|
|
7986
8161
|
if (code === "ENOENT" || code === "ENOTDIR") return null;
|
|
@@ -7992,38 +8167,38 @@ function readOptionalJsonFile(filePath, label) {
|
|
|
7992
8167
|
}
|
|
7993
8168
|
function readJsonFileBestEffort2(filePath) {
|
|
7994
8169
|
try {
|
|
7995
|
-
return JSON.parse(
|
|
8170
|
+
return JSON.parse(fs16.readFileSync(filePath, "utf-8"));
|
|
7996
8171
|
} catch {
|
|
7997
8172
|
return null;
|
|
7998
8173
|
}
|
|
7999
8174
|
}
|
|
8000
8175
|
function extractSkillPathsFromPackageRoot(packageRoot, source, bestEffort = false) {
|
|
8001
|
-
const packageJsonPath =
|
|
8176
|
+
const packageJsonPath = path17.join(packageRoot, "package.json");
|
|
8002
8177
|
const pkg = bestEffort ? readJsonFileBestEffort2(packageJsonPath) : readOptionalJsonFile(packageJsonPath, "package manifest");
|
|
8003
8178
|
if (!pkg || typeof pkg !== "object" || Array.isArray(pkg)) return [];
|
|
8004
8179
|
const pi = pkg.pi;
|
|
8005
8180
|
if (!pi || typeof pi !== "object" || Array.isArray(pi)) return [];
|
|
8006
8181
|
const skills = pi.skills;
|
|
8007
8182
|
if (!Array.isArray(skills)) return [];
|
|
8008
|
-
return skills.filter((entry) => typeof entry === "string").map((entry) => ({ path:
|
|
8183
|
+
return skills.filter((entry) => typeof entry === "string").map((entry) => ({ path: path17.resolve(packageRoot, entry), source }));
|
|
8009
8184
|
}
|
|
8010
8185
|
var cachedGlobalNpmRoot2 = null;
|
|
8011
8186
|
function getGlobalNpmRoot2() {
|
|
8012
8187
|
const offline = process.env.PI_OFFLINE?.toLowerCase();
|
|
8013
8188
|
if (offline === "1" || offline === "true" || offline === "yes") return null;
|
|
8014
8189
|
if (cachedGlobalNpmRoot2 !== null) return cachedGlobalNpmRoot2;
|
|
8015
|
-
const windowsGlobalRoot = process.platform === "win32" && process.env.APPDATA ?
|
|
8190
|
+
const windowsGlobalRoot = process.platform === "win32" && process.env.APPDATA ? path17.join(process.env.APPDATA, "npm", "node_modules") : void 0;
|
|
8016
8191
|
if (windowsGlobalRoot) {
|
|
8017
8192
|
try {
|
|
8018
|
-
if (
|
|
8019
|
-
cachedGlobalNpmRoot2 =
|
|
8193
|
+
if (fs16.statSync(windowsGlobalRoot).isDirectory()) {
|
|
8194
|
+
cachedGlobalNpmRoot2 = fs16.realpathSync(windowsGlobalRoot);
|
|
8020
8195
|
return cachedGlobalNpmRoot2;
|
|
8021
8196
|
}
|
|
8022
8197
|
} catch {
|
|
8023
8198
|
}
|
|
8024
8199
|
}
|
|
8025
8200
|
try {
|
|
8026
|
-
cachedGlobalNpmRoot2 =
|
|
8201
|
+
cachedGlobalNpmRoot2 = fs16.realpathSync(execSync2("npm root -g", { encoding: "utf-8", timeout: 5e3, windowsHide: true, stdio: ["ignore", "pipe", "ignore"] }).trim());
|
|
8027
8202
|
return cachedGlobalNpmRoot2;
|
|
8028
8203
|
} catch {
|
|
8029
8204
|
cachedGlobalNpmRoot2 = "";
|
|
@@ -8033,8 +8208,8 @@ function getGlobalNpmRoot2() {
|
|
|
8033
8208
|
function collectInstalledPackageSkillPaths(cwd, agentDir) {
|
|
8034
8209
|
const projectConfigDir = getProjectConfigDir(cwd);
|
|
8035
8210
|
const dirs = [
|
|
8036
|
-
{ path:
|
|
8037
|
-
{ path:
|
|
8211
|
+
{ path: path17.join(projectConfigDir, "npm", "node_modules"), source: "project-package" },
|
|
8212
|
+
{ path: path17.join(agentDir, "npm", "node_modules"), source: "user-package" }
|
|
8038
8213
|
];
|
|
8039
8214
|
const globalRoot = getGlobalNpmRoot2();
|
|
8040
8215
|
if (globalRoot) {
|
|
@@ -8042,10 +8217,10 @@ function collectInstalledPackageSkillPaths(cwd, agentDir) {
|
|
|
8042
8217
|
}
|
|
8043
8218
|
const results = [];
|
|
8044
8219
|
for (const dir of dirs) {
|
|
8045
|
-
if (!
|
|
8220
|
+
if (!fs16.existsSync(dir.path)) continue;
|
|
8046
8221
|
let entries;
|
|
8047
8222
|
try {
|
|
8048
|
-
entries =
|
|
8223
|
+
entries = fs16.readdirSync(dir.path, { withFileTypes: true });
|
|
8049
8224
|
} catch {
|
|
8050
8225
|
continue;
|
|
8051
8226
|
}
|
|
@@ -8053,22 +8228,22 @@ function collectInstalledPackageSkillPaths(cwd, agentDir) {
|
|
|
8053
8228
|
if (entry.name.startsWith(".")) continue;
|
|
8054
8229
|
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
8055
8230
|
if (entry.name.startsWith("@")) {
|
|
8056
|
-
const scopeDir =
|
|
8231
|
+
const scopeDir = path17.join(dir.path, entry.name);
|
|
8057
8232
|
let scopeEntries;
|
|
8058
8233
|
try {
|
|
8059
|
-
scopeEntries =
|
|
8234
|
+
scopeEntries = fs16.readdirSync(scopeDir, { withFileTypes: true });
|
|
8060
8235
|
} catch {
|
|
8061
8236
|
continue;
|
|
8062
8237
|
}
|
|
8063
8238
|
for (const scopeEntry of scopeEntries) {
|
|
8064
8239
|
if (scopeEntry.name.startsWith(".")) continue;
|
|
8065
8240
|
if (!scopeEntry.isDirectory() && !scopeEntry.isSymbolicLink()) continue;
|
|
8066
|
-
const pkgRoot2 =
|
|
8241
|
+
const pkgRoot2 = path17.join(scopeDir, scopeEntry.name);
|
|
8067
8242
|
results.push(...extractSkillPathsFromPackageRoot(pkgRoot2, dir.source, true));
|
|
8068
8243
|
}
|
|
8069
8244
|
continue;
|
|
8070
8245
|
}
|
|
8071
|
-
const pkgRoot =
|
|
8246
|
+
const pkgRoot = path17.join(dir.path, entry.name);
|
|
8072
8247
|
results.push(...extractSkillPathsFromPackageRoot(pkgRoot, dir.source, true));
|
|
8073
8248
|
}
|
|
8074
8249
|
}
|
|
@@ -8078,8 +8253,8 @@ function collectSettingsSkillPaths(cwd, agentDir) {
|
|
|
8078
8253
|
const results = [];
|
|
8079
8254
|
const projectConfigDir = getProjectConfigDir(cwd);
|
|
8080
8255
|
const settingsFiles = [
|
|
8081
|
-
{ file:
|
|
8082
|
-
{ file:
|
|
8256
|
+
{ file: path17.join(projectConfigDir, "settings.json"), base: projectConfigDir, source: "project-settings" },
|
|
8257
|
+
{ file: path17.join(agentDir, "settings.json"), base: agentDir, source: "user-settings" }
|
|
8083
8258
|
];
|
|
8084
8259
|
for (const { file, base, source } of settingsFiles) {
|
|
8085
8260
|
const settings = readOptionalJsonFile(file, "skills settings file");
|
|
@@ -8090,9 +8265,9 @@ function collectSettingsSkillPaths(cwd, agentDir) {
|
|
|
8090
8265
|
if (typeof entry !== "string") continue;
|
|
8091
8266
|
let resolved = entry;
|
|
8092
8267
|
if (resolved.startsWith("~/")) {
|
|
8093
|
-
resolved =
|
|
8094
|
-
} else if (!
|
|
8095
|
-
resolved =
|
|
8268
|
+
resolved = path17.join(os7.homedir(), resolved.slice(2));
|
|
8269
|
+
} else if (!path17.isAbsolute(resolved)) {
|
|
8270
|
+
resolved = path17.resolve(base, resolved);
|
|
8096
8271
|
}
|
|
8097
8272
|
results.push({ path: resolved, source });
|
|
8098
8273
|
}
|
|
@@ -8100,7 +8275,7 @@ function collectSettingsSkillPaths(cwd, agentDir) {
|
|
|
8100
8275
|
return results;
|
|
8101
8276
|
}
|
|
8102
8277
|
function isSafePackagePath2(value) {
|
|
8103
|
-
return value.length > 0 && !
|
|
8278
|
+
return value.length > 0 && !path17.isAbsolute(value) && value.split(/[\\/]/).every((part) => part.length > 0 && part !== "." && part !== "..");
|
|
8104
8279
|
}
|
|
8105
8280
|
function parseNpmPackageName2(source) {
|
|
8106
8281
|
const spec = source.slice(4).trim();
|
|
@@ -8149,26 +8324,26 @@ function resolveSettingsPackageRoot2(source, baseDir) {
|
|
|
8149
8324
|
if (!trimmed) return void 0;
|
|
8150
8325
|
if (trimmed.startsWith("git:")) {
|
|
8151
8326
|
const parsed = parseGitPackagePath2(trimmed);
|
|
8152
|
-
return parsed ?
|
|
8327
|
+
return parsed ? path17.join(baseDir, "git", parsed.host, parsed.repoPath) : void 0;
|
|
8153
8328
|
}
|
|
8154
8329
|
if (trimmed.startsWith("npm:")) {
|
|
8155
8330
|
const packageName = parseNpmPackageName2(trimmed);
|
|
8156
|
-
return packageName ?
|
|
8331
|
+
return packageName ? path17.join(baseDir, "npm", "node_modules", packageName) : void 0;
|
|
8157
8332
|
}
|
|
8158
8333
|
const normalized = trimmed.startsWith("file:") ? trimmed.slice(5) : trimmed;
|
|
8159
|
-
if (normalized === "~") return
|
|
8160
|
-
if (normalized.startsWith("~/")) return
|
|
8161
|
-
if (
|
|
8334
|
+
if (normalized === "~") return os7.homedir();
|
|
8335
|
+
if (normalized.startsWith("~/")) return path17.join(os7.homedir(), normalized.slice(2));
|
|
8336
|
+
if (path17.isAbsolute(normalized)) return normalized;
|
|
8162
8337
|
if (normalized === "." || normalized === ".." || normalized.startsWith("./") || normalized.startsWith("../")) {
|
|
8163
|
-
return
|
|
8338
|
+
return path17.resolve(baseDir, normalized);
|
|
8164
8339
|
}
|
|
8165
8340
|
return void 0;
|
|
8166
8341
|
}
|
|
8167
8342
|
function collectSettingsPackageSkillPaths(cwd, agentDir) {
|
|
8168
8343
|
const projectConfigDir = getProjectConfigDir(cwd);
|
|
8169
8344
|
const settingsFiles = [
|
|
8170
|
-
{ file:
|
|
8171
|
-
{ file:
|
|
8345
|
+
{ file: path17.join(projectConfigDir, "settings.json"), base: projectConfigDir, source: "project-package" },
|
|
8346
|
+
{ file: path17.join(agentDir, "settings.json"), base: agentDir, source: "user-package" }
|
|
8172
8347
|
];
|
|
8173
8348
|
const results = [];
|
|
8174
8349
|
for (const { file, base, source } of settingsFiles) {
|
|
@@ -8189,10 +8364,10 @@ function collectSettingsPackageSkillPaths(cwd, agentDir) {
|
|
|
8189
8364
|
function buildSkillPaths(cwd, agentDir) {
|
|
8190
8365
|
const projectConfigDir = getProjectConfigDir(cwd);
|
|
8191
8366
|
const skillPaths = [
|
|
8192
|
-
{ path:
|
|
8193
|
-
{ path:
|
|
8194
|
-
{ path:
|
|
8195
|
-
{ path:
|
|
8367
|
+
{ path: path17.join(projectConfigDir, "skills"), source: "project" },
|
|
8368
|
+
{ path: path17.join(cwd, ".agents", "skills"), source: "project" },
|
|
8369
|
+
{ path: path17.join(agentDir, "skills"), source: "user" },
|
|
8370
|
+
{ path: path17.join(os7.homedir(), ".agents", "skills"), source: "user" },
|
|
8196
8371
|
...collectInstalledPackageSkillPaths(cwd, agentDir),
|
|
8197
8372
|
...collectSettingsPackageSkillPaths(cwd, agentDir),
|
|
8198
8373
|
...extractSkillPathsFromPackageRoot(cwd, "project-package"),
|
|
@@ -8200,7 +8375,7 @@ function buildSkillPaths(cwd, agentDir) {
|
|
|
8200
8375
|
];
|
|
8201
8376
|
const deduped = /* @__PURE__ */ new Map();
|
|
8202
8377
|
for (const entry of skillPaths) {
|
|
8203
|
-
const resolvedPath =
|
|
8378
|
+
const resolvedPath = path17.resolve(entry.path);
|
|
8204
8379
|
const existing = deduped.get(resolvedPath);
|
|
8205
8380
|
if (!existing || (SOURCE_PRIORITY[entry.source] ?? 0) > (SOURCE_PRIORITY[existing.source] ?? 0)) {
|
|
8206
8381
|
deduped.set(resolvedPath, { path: resolvedPath, source: entry.source });
|
|
@@ -8210,14 +8385,14 @@ function buildSkillPaths(cwd, agentDir) {
|
|
|
8210
8385
|
}
|
|
8211
8386
|
function inferSkillSource(filePath, cwd, agentDir, sourceHint) {
|
|
8212
8387
|
if (sourceHint) return sourceHint;
|
|
8213
|
-
const projectConfigRoot =
|
|
8214
|
-
const projectSkillsRoot =
|
|
8215
|
-
const projectPackagesRoot =
|
|
8216
|
-
const projectAgentsRoot =
|
|
8217
|
-
const userSkillsRoot =
|
|
8218
|
-
const userPackagesRoot =
|
|
8219
|
-
const userAgentRoot =
|
|
8220
|
-
const userAgentsRoot =
|
|
8388
|
+
const projectConfigRoot = path17.resolve(getProjectConfigDir(cwd));
|
|
8389
|
+
const projectSkillsRoot = path17.resolve(projectConfigRoot, "skills");
|
|
8390
|
+
const projectPackagesRoot = path17.resolve(projectConfigRoot, "npm", "node_modules");
|
|
8391
|
+
const projectAgentsRoot = path17.resolve(cwd, ".agents");
|
|
8392
|
+
const userSkillsRoot = path17.resolve(agentDir, "skills");
|
|
8393
|
+
const userPackagesRoot = path17.resolve(agentDir, "npm", "node_modules");
|
|
8394
|
+
const userAgentRoot = path17.resolve(agentDir);
|
|
8395
|
+
const userAgentsRoot = path17.resolve(os7.homedir(), ".agents");
|
|
8221
8396
|
if (isWithinPath(filePath, projectPackagesRoot)) return "project-package";
|
|
8222
8397
|
if (isWithinPath(filePath, projectSkillsRoot) || isWithinPath(filePath, projectAgentsRoot)) return "project";
|
|
8223
8398
|
if (isWithinPath(filePath, projectConfigRoot)) return "project-settings";
|
|
@@ -8241,7 +8416,7 @@ function parseSkillDescription(content) {
|
|
|
8241
8416
|
}
|
|
8242
8417
|
function maybeReadSkillMetadata(filePath) {
|
|
8243
8418
|
try {
|
|
8244
|
-
const content =
|
|
8419
|
+
const content = fs16.readFileSync(filePath, "utf-8");
|
|
8245
8420
|
return { description: parseSkillDescription(content), disableModelInvocation: maybeReadSkillDisableModelInvocation(content) };
|
|
8246
8421
|
} catch {
|
|
8247
8422
|
return {};
|
|
@@ -8266,8 +8441,8 @@ function collectFilesystemSkills(cwd, agentDir, skillPaths) {
|
|
|
8266
8441
|
const visitedDirectories = /* @__PURE__ */ new Map();
|
|
8267
8442
|
let order = 0;
|
|
8268
8443
|
const pushEntry = (name, filePath, sourceHint) => {
|
|
8269
|
-
const resolvedFile =
|
|
8270
|
-
if (!
|
|
8444
|
+
const resolvedFile = path17.resolve(filePath);
|
|
8445
|
+
if (!fs16.existsSync(resolvedFile)) return;
|
|
8271
8446
|
const source = inferSkillSource(resolvedFile, cwd, agentDir, sourceHint);
|
|
8272
8447
|
const { description, disableModelInvocation } = maybeReadSkillMetadata(resolvedFile);
|
|
8273
8448
|
const existingIndex = seen.get(resolvedFile);
|
|
@@ -8299,9 +8474,9 @@ function collectFilesystemSkills(cwd, agentDir, skillPaths) {
|
|
|
8299
8474
|
const markDirectoryVisited = (dirPath, sourceHint) => {
|
|
8300
8475
|
let resolvedDir;
|
|
8301
8476
|
try {
|
|
8302
|
-
resolvedDir =
|
|
8477
|
+
resolvedDir = fs16.realpathSync(dirPath);
|
|
8303
8478
|
} catch {
|
|
8304
|
-
resolvedDir =
|
|
8479
|
+
resolvedDir = path17.resolve(dirPath);
|
|
8305
8480
|
}
|
|
8306
8481
|
const priority = sourceHint ? SOURCE_PRIORITY[sourceHint] ?? 0 : SOURCE_PRIORITY.unknown;
|
|
8307
8482
|
const previousPriority = visitedDirectories.get(resolvedDir);
|
|
@@ -8311,24 +8486,24 @@ function collectFilesystemSkills(cwd, agentDir, skillPaths) {
|
|
|
8311
8486
|
};
|
|
8312
8487
|
const walkSkillDirectories = (dirPath, sourceHint) => {
|
|
8313
8488
|
if (!markDirectoryVisited(dirPath, sourceHint)) return;
|
|
8314
|
-
const skillFile =
|
|
8315
|
-
if (
|
|
8316
|
-
pushEntry(
|
|
8489
|
+
const skillFile = path17.join(dirPath, "SKILL.md");
|
|
8490
|
+
if (fs16.existsSync(skillFile)) {
|
|
8491
|
+
pushEntry(path17.basename(dirPath), skillFile, sourceHint);
|
|
8317
8492
|
return;
|
|
8318
8493
|
}
|
|
8319
8494
|
let entriesInDir;
|
|
8320
8495
|
try {
|
|
8321
|
-
entriesInDir =
|
|
8496
|
+
entriesInDir = fs16.readdirSync(dirPath, { withFileTypes: true });
|
|
8322
8497
|
} catch {
|
|
8323
8498
|
return;
|
|
8324
8499
|
}
|
|
8325
8500
|
for (const entry of entriesInDir) {
|
|
8326
8501
|
if (shouldSkipDirectory(entry.name)) continue;
|
|
8327
8502
|
if (!entry.isDirectory() && !entry.isSymbolicLink()) continue;
|
|
8328
|
-
const entryPath =
|
|
8503
|
+
const entryPath = path17.join(dirPath, entry.name);
|
|
8329
8504
|
let stat;
|
|
8330
8505
|
try {
|
|
8331
|
-
stat =
|
|
8506
|
+
stat = fs16.statSync(entryPath);
|
|
8332
8507
|
} catch {
|
|
8333
8508
|
continue;
|
|
8334
8509
|
}
|
|
@@ -8338,41 +8513,41 @@ function collectFilesystemSkills(cwd, agentDir, skillPaths) {
|
|
|
8338
8513
|
}
|
|
8339
8514
|
};
|
|
8340
8515
|
for (const skillPath of skillPaths) {
|
|
8341
|
-
if (!
|
|
8516
|
+
if (!fs16.existsSync(skillPath.path)) continue;
|
|
8342
8517
|
let stat;
|
|
8343
8518
|
try {
|
|
8344
|
-
stat =
|
|
8519
|
+
stat = fs16.statSync(skillPath.path);
|
|
8345
8520
|
} catch {
|
|
8346
8521
|
continue;
|
|
8347
8522
|
}
|
|
8348
8523
|
if (stat.isFile()) {
|
|
8349
|
-
const fileName =
|
|
8524
|
+
const fileName = path17.basename(skillPath.path);
|
|
8350
8525
|
if (!fileName.toLowerCase().endsWith(".md")) continue;
|
|
8351
|
-
const skillName = fileName.toLowerCase() === "skill.md" ?
|
|
8526
|
+
const skillName = fileName.toLowerCase() === "skill.md" ? path17.basename(path17.dirname(skillPath.path)) : path17.basename(fileName, path17.extname(fileName));
|
|
8352
8527
|
pushEntry(skillName, skillPath.path, skillPath.source);
|
|
8353
8528
|
continue;
|
|
8354
8529
|
}
|
|
8355
8530
|
if (!stat.isDirectory()) continue;
|
|
8356
|
-
const rootSkillFile =
|
|
8357
|
-
if (
|
|
8358
|
-
pushEntry(
|
|
8531
|
+
const rootSkillFile = path17.join(skillPath.path, "SKILL.md");
|
|
8532
|
+
if (fs16.existsSync(rootSkillFile)) {
|
|
8533
|
+
pushEntry(path17.basename(skillPath.path), rootSkillFile, skillPath.source);
|
|
8359
8534
|
continue;
|
|
8360
8535
|
}
|
|
8361
8536
|
markDirectoryVisited(skillPath.path, skillPath.source);
|
|
8362
8537
|
let childEntries;
|
|
8363
8538
|
try {
|
|
8364
|
-
childEntries =
|
|
8539
|
+
childEntries = fs16.readdirSync(skillPath.path, { withFileTypes: true });
|
|
8365
8540
|
} catch {
|
|
8366
8541
|
continue;
|
|
8367
8542
|
}
|
|
8368
8543
|
for (const child of childEntries) {
|
|
8369
8544
|
if (child.name.startsWith(".")) continue;
|
|
8370
|
-
const childPath =
|
|
8545
|
+
const childPath = path17.join(skillPath.path, child.name);
|
|
8371
8546
|
if (child.isDirectory() || child.isSymbolicLink()) {
|
|
8372
8547
|
if (shouldSkipDirectory(child.name)) continue;
|
|
8373
8548
|
let childStat;
|
|
8374
8549
|
try {
|
|
8375
|
-
childStat =
|
|
8550
|
+
childStat = fs16.statSync(childPath);
|
|
8376
8551
|
} catch {
|
|
8377
8552
|
continue;
|
|
8378
8553
|
}
|
|
@@ -8380,7 +8555,7 @@ function collectFilesystemSkills(cwd, agentDir, skillPaths) {
|
|
|
8380
8555
|
continue;
|
|
8381
8556
|
}
|
|
8382
8557
|
if (child.isFile() && child.name.toLowerCase().endsWith(".md")) {
|
|
8383
|
-
pushEntry(
|
|
8558
|
+
pushEntry(path17.basename(child.name, path17.extname(child.name)), childPath, skillPath.source);
|
|
8384
8559
|
}
|
|
8385
8560
|
}
|
|
8386
8561
|
}
|
|
@@ -8396,8 +8571,8 @@ function getCachedSkills(cwd) {
|
|
|
8396
8571
|
const loaded = collectFilesystemSkills(cwd, agentDir, skillPaths);
|
|
8397
8572
|
const dedupedByName = /* @__PURE__ */ new Map();
|
|
8398
8573
|
for (const entry of loaded) {
|
|
8399
|
-
const
|
|
8400
|
-
dedupedByName.set(entry.name, chooseHigherPrioritySkill(
|
|
8574
|
+
const current2 = dedupedByName.get(entry.name);
|
|
8575
|
+
dedupedByName.set(entry.name, chooseHigherPrioritySkill(current2, entry));
|
|
8401
8576
|
}
|
|
8402
8577
|
const skills = [...dedupedByName.values()].sort((a, b) => a.order - b.order);
|
|
8403
8578
|
loadSkillsCache = { cwd, agentDir, skills, timestamp: now };
|
|
@@ -8411,12 +8586,12 @@ function resolveSkillPath(skillName, cwd) {
|
|
|
8411
8586
|
}
|
|
8412
8587
|
function readSkill(skillName, skillPath, source) {
|
|
8413
8588
|
try {
|
|
8414
|
-
const stat =
|
|
8589
|
+
const stat = fs16.statSync(skillPath);
|
|
8415
8590
|
const cached = skillCache.get(skillPath);
|
|
8416
8591
|
if (cached && cached.mtime === stat.mtimeMs) {
|
|
8417
8592
|
return cached.skill;
|
|
8418
8593
|
}
|
|
8419
|
-
const raw =
|
|
8594
|
+
const raw = fs16.readFileSync(skillPath, "utf-8");
|
|
8420
8595
|
const content = stripSkillFrontmatter(raw);
|
|
8421
8596
|
const description = parseSkillDescription(raw);
|
|
8422
8597
|
const disableModelInvocation = maybeReadSkillDisableModelInvocation(raw);
|
|
@@ -8445,7 +8620,7 @@ function resolveSkills(skillNames, cwd, localSkillPaths, localBaseDir) {
|
|
|
8445
8620
|
if (localSkillPaths?.length) {
|
|
8446
8621
|
const agentDir = getAgentDir();
|
|
8447
8622
|
const localEntries = collectFilesystemSkills(cwd, agentDir, localSkillPaths.map((entry) => ({
|
|
8448
|
-
path:
|
|
8623
|
+
path: path17.resolve(localBaseDir ?? cwd, entry),
|
|
8449
8624
|
source: "unknown"
|
|
8450
8625
|
})));
|
|
8451
8626
|
for (const entry of localEntries) {
|
|
@@ -8473,7 +8648,7 @@ function resolveSkills(skillNames, cwd, localSkillPaths, localBaseDir) {
|
|
|
8473
8648
|
function resolveSkillsWithFallback(skillNames, primaryCwd, fallbackCwd, localSkillPaths, localBaseDir) {
|
|
8474
8649
|
const primary = resolveSkills(skillNames, primaryCwd, localSkillPaths, localBaseDir);
|
|
8475
8650
|
if (!fallbackCwd || primary.missing.length === 0) return primary;
|
|
8476
|
-
if (
|
|
8651
|
+
if (path17.resolve(primaryCwd) === path17.resolve(fallbackCwd)) return primary;
|
|
8477
8652
|
const fallback = resolveSkills(primary.missing, fallbackCwd);
|
|
8478
8653
|
return {
|
|
8479
8654
|
resolved: [...primary.resolved, ...fallback.resolved],
|
|
@@ -8548,6 +8723,7 @@ export {
|
|
|
8548
8723
|
CODE_OWNED_EXTERNAL_CLI_ADAPTER_LABEL,
|
|
8549
8724
|
isCodeOwnedExternalCliAdapterId,
|
|
8550
8725
|
validateCodeOwnedProfileRunner,
|
|
8726
|
+
EXTERNAL_CLI_ADAPTER_SAFETY,
|
|
8551
8727
|
parseExternalCliCapabilityNarrowing,
|
|
8552
8728
|
resolveExternalCliRunnerStatus,
|
|
8553
8729
|
normalizeExternalCliRunnerStatus,
|
|
@@ -8559,6 +8735,17 @@ export {
|
|
|
8559
8735
|
buildSkillInjection,
|
|
8560
8736
|
normalizeSkillInput,
|
|
8561
8737
|
discoverAvailableSkills,
|
|
8738
|
+
REX_LOCAL_MACHINE,
|
|
8739
|
+
REX_EXIT_GONE,
|
|
8740
|
+
REX_EXIT_UNREACHABLE,
|
|
8741
|
+
isRexLocalMachine,
|
|
8742
|
+
REX_BUNDLE_BIN,
|
|
8743
|
+
REX_CALL_TIMEOUT_MS,
|
|
8744
|
+
REX_MAX_OUTPUT,
|
|
8745
|
+
rexGlobalArgs,
|
|
8746
|
+
resolveRexBinary,
|
|
8747
|
+
rexCommandEnv,
|
|
8748
|
+
resolveRexLocalPlacement,
|
|
8562
8749
|
extractChildWrittenOutput,
|
|
8563
8750
|
normalizeSingleOutputOverride,
|
|
8564
8751
|
resolveSingleOutputPath,
|
|
@@ -8618,7 +8805,9 @@ export {
|
|
|
8618
8805
|
normalizeParentModel,
|
|
8619
8806
|
scopedModelIdsFromContext,
|
|
8620
8807
|
normalizeModelSegment,
|
|
8808
|
+
knownModelProviders,
|
|
8621
8809
|
resolveModelCandidate,
|
|
8810
|
+
isUnavailableSubagentModel,
|
|
8622
8811
|
resolveSubagentModelOverride,
|
|
8623
8812
|
resolveEffectiveSubagentModel,
|
|
8624
8813
|
resolveModelOrigin,
|
|
@@ -8640,6 +8829,8 @@ export {
|
|
|
8640
8829
|
assistantMessageError,
|
|
8641
8830
|
getFinalOutput,
|
|
8642
8831
|
getSingleResultOutput,
|
|
8832
|
+
TRUNCATED_RESPONSE_ERROR,
|
|
8833
|
+
getTerminalAssistantStopReason,
|
|
8643
8834
|
getDisplayItems,
|
|
8644
8835
|
sumResultsUsage,
|
|
8645
8836
|
toAgentToolUsage,
|
|
@@ -8690,9 +8881,11 @@ export {
|
|
|
8690
8881
|
MISSING_STRUCTURED_ACCEPTANCE_REPORT_ERROR,
|
|
8691
8882
|
formatStructuredOutputRejectionError,
|
|
8692
8883
|
createStructuredOutputToolParameters,
|
|
8884
|
+
structuredOutputValidatorReady,
|
|
8693
8885
|
assertJsonSchemaObject,
|
|
8694
8886
|
createStructuredOutputRuntime,
|
|
8695
8887
|
validateStructuredOutputValue,
|
|
8888
|
+
prepareStructuredOutputArguments,
|
|
8696
8889
|
cleanupStructuredOutputRuntime,
|
|
8697
8890
|
ChainOutputValidationError,
|
|
8698
8891
|
validateChainOutputBindings,
|
|
@@ -8712,6 +8905,7 @@ export {
|
|
|
8712
8905
|
childWatchdogProgressForModel,
|
|
8713
8906
|
isAgentContract,
|
|
8714
8907
|
attachContractProjections,
|
|
8908
|
+
normalizeAcceptanceInput,
|
|
8715
8909
|
resolveAcceptanceReportMode,
|
|
8716
8910
|
parseGateInput,
|
|
8717
8911
|
acceptanceHasTypedVerify,
|
|
@@ -8724,6 +8918,7 @@ export {
|
|
|
8724
8918
|
resolveEffectiveAcceptance,
|
|
8725
8919
|
formatReviewGateLabel,
|
|
8726
8920
|
formatAcceptancePrompt,
|
|
8921
|
+
parseAcceptanceReport,
|
|
8727
8922
|
stripAcceptanceReport,
|
|
8728
8923
|
validateAcceptanceReport,
|
|
8729
8924
|
captureStagedIndexBaseline,
|
|
@@ -8744,6 +8939,9 @@ export {
|
|
|
8744
8939
|
projectScopeRequiresTrustMessage,
|
|
8745
8940
|
BUILTIN_AGENT_NAMES,
|
|
8746
8941
|
buildAgentMemoryInjection,
|
|
8942
|
+
DEFAULT_WAIT_TOOL_NAME,
|
|
8943
|
+
waitToolName,
|
|
8944
|
+
setWaitToolName,
|
|
8747
8945
|
redactSecretValues,
|
|
8748
8946
|
validatePermissionRules,
|
|
8749
8947
|
validatePermissionConfig,
|
|
@@ -8756,6 +8954,7 @@ export {
|
|
|
8756
8954
|
defaultInheritSkills,
|
|
8757
8955
|
findBlockingAgentDiagnostic,
|
|
8758
8956
|
unknownAgentDiagnosticContext,
|
|
8957
|
+
MAX_LISTED_AGENTS,
|
|
8759
8958
|
formatAvailableAgentLines,
|
|
8760
8959
|
suggestAgentName,
|
|
8761
8960
|
formatUnknownAgentError,
|