@oyasmi/pipiclaw 0.9.5 → 0.9.6-beta.2
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/README.en.md +300 -142
- package/README.md +295 -140
- package/dist/agent/builtin-commands.d.ts +1 -1
- package/dist/agent/builtin-commands.js +1 -1
- package/dist/agent/channel-runner.d.ts +4 -3
- package/dist/agent/channel-runner.js +17 -28
- package/dist/agent/maintenance-context.js +2 -2
- package/dist/agent/prompt/builder.d.ts +1 -1
- package/dist/agent/prompt/builder.js +1 -1
- package/dist/agent/prompt/extension.d.ts +1 -1
- package/dist/agent/prompt/extension.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +12 -5
- package/dist/agent/prompt/resources.d.ts +0 -3
- package/dist/agent/prompt/resources.js +0 -6
- package/dist/agent/prompt/sections.d.ts +2 -2
- package/dist/agent/prompt/sections.js +36 -26
- package/dist/agent/prompt/types.d.ts +3 -2
- package/dist/agent/runner-factory.js +1 -1
- package/dist/agent/session/command-extension.js +3 -1
- package/dist/agent/session/compaction-summary.js +3 -6
- package/dist/agent/session/compaction.d.ts +2 -0
- package/dist/agent/session/compaction.js +22 -14
- package/dist/agent/session/event-guards.d.ts +2 -1
- package/dist/agent/session/event-guards.js +6 -0
- package/dist/agent/session/model-selection.d.ts +2 -1
- package/dist/agent/session/model-selection.js +5 -5
- package/dist/agent/session/session-events.js +31 -4
- package/dist/agent/session/session-host.d.ts +5 -3
- package/dist/agent/session/session-host.js +20 -16
- package/dist/agent/status-render.js +3 -0
- package/dist/agent/stop-watchdog.js +5 -1
- package/dist/agent/turn/task-digest.d.ts +2 -5
- package/dist/agent/turn/task-digest.js +25 -45
- package/dist/agent/turn/turn-context.js +4 -6
- package/dist/agent/turn/turn-error.d.ts +1 -1
- package/dist/agent/turn/turn-error.js +9 -0
- package/dist/agent/turn/turn-pipeline.d.ts +10 -5
- package/dist/agent/turn/turn-pipeline.js +36 -7
- package/dist/agent/turn/turn-prompt.d.ts +2 -0
- package/dist/agent/turn/turn-prompt.js +2 -1
- package/dist/agent/turn/turn-recovery.js +4 -1
- package/dist/agent/turn/turn-state.d.ts +2 -0
- package/dist/agent/turn/turn-state.js +2 -1
- package/dist/agent/types.d.ts +23 -3
- package/dist/agent/types.js +2 -0
- package/dist/app/auth-command.d.ts +25 -0
- package/dist/app/auth-command.js +200 -67
- package/dist/app/home.d.ts +7 -8
- package/dist/app/home.js +143 -56
- package/dist/channel/attachments.d.ts +4 -0
- package/dist/channel/attachments.js +4 -0
- package/dist/channel/channel-context.d.ts +6 -0
- package/dist/channel/config.d.ts +3 -0
- package/dist/channel/config.js +11 -5
- package/dist/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +42 -10
- package/dist/commands/router.js +5 -1
- package/dist/desk/commands.d.ts +44 -5
- package/dist/desk/commands.js +162 -28
- package/dist/desk/paths.d.ts +6 -0
- package/dist/desk/paths.js +21 -1
- package/dist/desk/registry.d.ts +17 -2
- package/dist/desk/registry.js +122 -12
- package/dist/desk/types.d.ts +83 -1
- package/dist/dingtalk/bot.d.ts +1 -1
- package/dist/dingtalk/bot.js +4 -3
- package/dist/dingtalk/config.js +10 -10
- package/dist/dingtalk/delivery.js +15 -8
- package/dist/dingtalk/inbound-media.d.ts +36 -14
- package/dist/dingtalk/inbound-media.js +71 -12
- package/dist/dingtalk/inbound.d.ts +9 -2
- package/dist/dingtalk/inbound.js +17 -2
- package/dist/dingtalk/media.d.ts +4 -10
- package/dist/dingtalk/media.js +58 -32
- package/dist/events/commands.d.ts +2 -0
- package/dist/events/commands.js +13 -8
- package/dist/events/history.d.ts +9 -0
- package/dist/events/history.js +66 -0
- package/dist/events/parse.js +7 -3
- package/dist/events/types.d.ts +3 -0
- package/dist/events/watcher.d.ts +4 -8
- package/dist/events/watcher.js +53 -58
- package/dist/jobs/kill.d.ts +23 -0
- package/dist/jobs/kill.js +65 -0
- package/dist/jobs/manager.d.ts +19 -18
- package/dist/jobs/manager.js +36 -103
- package/dist/main.js +15 -3
- package/dist/memory/boundary-work.d.ts +2 -1
- package/dist/memory/boundary-work.js +1 -1
- package/dist/memory/lifecycle.d.ts +2 -1
- package/dist/memory/lifecycle.js +2 -2
- package/dist/memory/reflect-job.d.ts +2 -1
- package/dist/memory/reflect-job.js +1 -1
- package/dist/memory/reflect.d.ts +2 -1
- package/dist/memory/reflect.js +25 -4
- package/dist/memory/scheduler.d.ts +2 -1
- package/dist/memory/scheduler.js +1 -1
- package/dist/memory/session-corpus.d.ts +1 -1
- package/dist/memory/session-corpus.js +76 -1
- package/dist/memory/session-search.d.ts +2 -1
- package/dist/memory/session-search.js +14 -12
- package/dist/memory/sidecar-worker.d.ts +2 -1
- package/dist/memory/sidecar-worker.js +2 -4
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +19 -9
- package/dist/models/credential-work.d.ts +7 -0
- package/dist/models/credential-work.js +36 -0
- package/dist/models/login-ui.js +4 -4
- package/dist/models/provider-login.js +7 -6
- package/dist/models/requests.d.ts +8 -0
- package/dist/models/requests.js +69 -0
- package/dist/models/runtime.d.ts +3 -1
- package/dist/models/runtime.js +9 -2
- package/dist/playbooks/agent-delegation.md +20 -45
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/delegation-inline.md +25 -0
- package/dist/playbooks/delegation-recovery.md +28 -0
- package/dist/playbooks/event-scheduling.md +18 -37
- package/dist/playbooks/event-sensors.md +26 -0
- package/dist/playbooks/event-task-template.md +22 -0
- package/dist/playbooks/learning-and-skills.md +26 -0
- package/dist/playbooks/memory-operations.md +36 -0
- package/dist/playbooks/outbound-media.md +2 -2
- package/dist/playbooks/runtime-files.md +29 -0
- package/dist/playbooks/runtime-operations.md +25 -0
- package/dist/playbooks/runtime-orientation.md +18 -53
- package/dist/playbooks/task-lead.md +22 -68
- package/dist/playbooks/task-manage.md +38 -0
- package/dist/playbooks/task-recovery.md +24 -0
- package/dist/playbooks/task-verify.md +22 -0
- package/dist/runtime/bootstrap.d.ts +10 -0
- package/dist/runtime/bootstrap.js +93 -29
- package/dist/runtime/daemon-lock.js +3 -3
- package/dist/runtime/desk-runtime.d.ts +40 -7
- package/dist/runtime/desk-runtime.js +330 -44
- package/dist/runtime/durable-dispatch.d.ts +14 -2
- package/dist/runtime/durable-dispatch.js +207 -65
- package/dist/runtime/ingress-busy.js +17 -8
- package/dist/runtime/ingress-commands.js +24 -4
- package/dist/runtime/ingress-deps.d.ts +4 -1
- package/dist/runtime/ingress.js +6 -1
- package/dist/runtime/request-execution.js +7 -6
- package/dist/runtime/shutdown.d.ts +4 -1
- package/dist/runtime/shutdown.js +88 -35
- package/dist/runtime/task-close.d.ts +1 -1
- package/dist/runtime/task-close.js +6 -3
- package/dist/runtime/task-control.d.ts +2 -3
- package/dist/runtime/task-control.js +38 -11
- package/dist/runtime/task-input.js +1 -1
- package/dist/runtime/task-lane-types.d.ts +12 -2
- package/dist/runtime/task-lane-types.js +9 -0
- package/dist/runtime/task-lane.d.ts +2 -0
- package/dist/runtime/task-lane.js +38 -20
- package/dist/runtime/task-step.d.ts +3 -3
- package/dist/runtime/task-step.js +34 -16
- package/dist/runtime/transports.js +6 -5
- package/dist/runtime/turn-run.js +103 -66
- package/dist/security/command-guard.d.ts +1 -1
- package/dist/security/command-guard.js +259 -314
- package/dist/security/path-guard.js +48 -7
- package/dist/security/shell-parse.d.ts +10 -0
- package/dist/security/shell-parse.js +224 -0
- package/dist/security/types.d.ts +2 -0
- package/dist/subagents/commands.d.ts +1 -1
- package/dist/subagents/commands.js +14 -5
- package/dist/subagents/completion-wake.js +6 -0
- package/dist/subagents/detached-discovery.d.ts +1 -1
- package/dist/subagents/discovery.d.ts +18 -199
- package/dist/subagents/discovery.js +35 -289
- package/dist/subagents/dispatch.d.ts +1 -2
- package/dist/subagents/dispatch.js +50 -29
- package/dist/subagents/external/antigravity-cli.d.ts +2 -0
- package/dist/subagents/external/antigravity-cli.js +517 -0
- package/dist/subagents/external/claude-code.js +8 -17
- package/dist/subagents/external/codex-cli.js +8 -18
- package/dist/subagents/external/cursor-cli.js +34 -31
- package/dist/subagents/external/dispatch.d.ts +21 -7
- package/dist/subagents/external/dispatch.js +146 -12
- package/dist/subagents/external/exec.js +3 -0
- package/dist/subagents/external/harness.d.ts +57 -33
- package/dist/subagents/external/harness.js +69 -40
- package/dist/subagents/external/reconciliation.js +1 -0
- package/dist/subagents/external/registry.js +4 -1
- package/dist/subagents/external/role-warnings.d.ts +4 -13
- package/dist/subagents/external/role-warnings.js +4 -28
- package/dist/subagents/external/run.d.ts +1 -2
- package/dist/subagents/external/run.js +16 -26
- package/dist/subagents/external/settlement.d.ts +2 -0
- package/dist/subagents/external/settlement.js +13 -3
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/internal/outcome.d.ts +1 -2
- package/dist/subagents/internal/outcome.js +19 -12
- package/dist/subagents/internal/provider-retry.d.ts +1 -2
- package/dist/subagents/internal/provider-retry.js +2 -4
- package/dist/subagents/internal/run.d.ts +2 -3
- package/dist/subagents/internal/run.js +27 -4
- package/dist/subagents/internal/state.d.ts +2 -5
- package/dist/subagents/internal/state.js +1 -2
- package/dist/subagents/internal/worker.d.ts +1 -2
- package/dist/subagents/internal/worker.js +20 -10
- package/dist/subagents/resolve.d.ts +56 -0
- package/dist/subagents/resolve.js +202 -0
- package/dist/subagents/result.d.ts +6 -4
- package/dist/subagents/result.js +39 -6
- package/dist/subagents/run-record.d.ts +54 -2
- package/dist/subagents/run-record.js +7 -0
- package/dist/subagents/runs.d.ts +6 -31
- package/dist/subagents/runs.js +26 -31
- package/dist/subagents/task-envelope.d.ts +1 -2
- package/dist/subagents/task-envelope.js +13 -4
- package/dist/subagents/task-settlement.js +1 -0
- package/dist/subagents/types.d.ts +105 -6
- package/dist/subagents/types.js +16 -1
- package/dist/subagents/workspace-lease.d.ts +41 -24
- package/dist/subagents/workspace-lease.js +159 -24
- package/dist/subagents/worktree.d.ts +52 -0
- package/dist/subagents/worktree.js +363 -0
- package/dist/tasks/archive.js +4 -0
- package/dist/tasks/brief.d.ts +5 -1
- package/dist/tasks/brief.js +19 -5
- package/dist/tasks/commands.d.ts +6 -1
- package/dist/tasks/commands.js +32 -7
- package/dist/tasks/control.d.ts +11 -0
- package/dist/tasks/delivery.d.ts +2 -0
- package/dist/tasks/delivery.js +141 -21
- package/dist/tasks/loop-log.d.ts +12 -0
- package/dist/tasks/loop-log.js +10 -1
- package/dist/tasks/receipts.d.ts +7 -3
- package/dist/tasks/receipts.js +34 -5
- package/dist/tools/bash.d.ts +3 -0
- package/dist/tools/bash.js +29 -15
- package/dist/tools/contract/presentation.js +7 -5
- package/dist/tools/edit-diff.d.ts +11 -0
- package/dist/tools/edit-diff.js +148 -0
- package/dist/tools/edit-match.d.ts +18 -0
- package/dist/tools/edit-match.js +242 -0
- package/dist/tools/edit.d.ts +10 -2
- package/dist/tools/edit.js +91 -361
- package/dist/tools/event-manage.d.ts +2 -1
- package/dist/tools/event-manage.js +46 -39
- package/dist/tools/file-observations.d.ts +9 -0
- package/dist/tools/file-observations.js +50 -0
- package/dist/tools/glob-match.d.ts +3 -1
- package/dist/tools/glob-match.js +40 -17
- package/dist/tools/glob.d.ts +1 -0
- package/dist/tools/glob.js +39 -19
- package/dist/tools/grep-command.d.ts +13 -0
- package/dist/tools/grep-command.js +77 -0
- package/dist/tools/grep.js +96 -201
- package/dist/tools/index.d.ts +6 -2
- package/dist/tools/index.js +9 -4
- package/dist/tools/job.js +12 -11
- package/dist/tools/read.d.ts +2 -0
- package/dist/tools/read.js +10 -2
- package/dist/tools/registry.d.ts +16 -11
- package/dist/tools/registry.js +32 -12
- package/dist/tools/send-media.js +9 -5
- package/dist/tools/session-search.d.ts +2 -1
- package/dist/tools/session-search.js +15 -5
- package/dist/tools/skill.js +13 -12
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +25 -152
- package/dist/tools/subagent.d.ts +24 -2
- package/dist/tools/subagent.js +24 -18
- package/dist/tools/task-manage/control-tools.js +1 -1
- package/dist/tools/task-manage/factory.d.ts +2 -2
- package/dist/tools/task-manage/factory.js +40 -4
- package/dist/tools/task-manage/lifecycle.d.ts +3 -3
- package/dist/tools/task-manage/lifecycle.js +56 -13
- package/dist/tools/task-manage/schema.d.ts +4 -1
- package/dist/tools/task-manage/schema.js +4 -1
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/types.d.ts +5 -1
- package/dist/tools/write-content.d.ts +7 -1
- package/dist/tools/write-content.js +18 -6
- package/dist/tools/write.d.ts +3 -0
- package/dist/tools/write.js +6 -2
- package/dist/tui/cli.d.ts +6 -6
- package/dist/tui/cli.js +120 -28
- package/dist/tui/client.d.ts +7 -0
- package/dist/tui/client.js +67 -16
- package/dist/tui/frontend.d.ts +2 -0
- package/dist/tui/pitui-frontend.d.ts +4 -0
- package/dist/tui/pitui-frontend.js +27 -0
- package/dist/tui/render.d.ts +1 -0
- package/dist/tui/render.js +5 -0
- package/dist/tui/session.js +6 -0
- package/dist/usage/ledger.d.ts +1 -1
- package/dist/usage/render.js +1 -1
- package/dist/web/client.d.ts +1 -0
- package/dist/web/client.js +11 -0
- package/dist/web/fetch.js +6 -3
- package/dist/webapi/auth.d.ts +0 -3
- package/dist/webapi/auth.js +3 -7
- package/dist/webapi/config.js +17 -14
- package/dist/webapi/key-command.js +41 -41
- package/dist/webapi/response-state.d.ts +7 -1
- package/dist/webapi/response-state.js +166 -3
- package/dist/webapi/routes/websocket.js +24 -1
- package/dist/webapi/server.d.ts +3 -1
- package/dist/webapi/server.js +32 -1
- package/dist/webapi/service.js +8 -0
- package/dist/webapi/transport.d.ts +2 -0
- package/dist/webapi/transport.js +11 -1
- package/examples/sub-agents/README.md +43 -75
- package/examples/sub-agents/agy-main.md +21 -0
- package/examples/sub-agents/claude-high.md +21 -0
- package/examples/sub-agents/claude-main.md +21 -0
- package/examples/sub-agents/codex-flash.md +21 -0
- package/examples/sub-agents/codex-high.md +21 -0
- package/examples/sub-agents/codex-main.md +21 -0
- package/examples/sub-agents/codex-review.md +20 -0
- package/examples/sub-agents/cursor-high.md +20 -0
- package/examples/sub-agents/cursor-main.md +20 -0
- package/examples/sub-agents/glm-flash.md +21 -0
- package/examples/sub-agents/glm-high.md +21 -0
- package/examples/sub-agents/pi-scout.md +20 -0
- package/package.json +11 -12
- package/dist/agent/session/request-tools.d.ts +0 -3
- package/dist/agent/session/request-tools.js +0 -20
- package/dist/models/api-keys.d.ts +0 -11
- package/dist/models/api-keys.js +0 -22
- package/dist/playbooks/memory-and-learning.md +0 -55
- package/examples/sub-agents/agents/claude-high.md +0 -23
- package/examples/sub-agents/agents/claude-main.md +0 -23
- package/examples/sub-agents/agents/codex-flash.md +0 -23
- package/examples/sub-agents/agents/codex-high.md +0 -23
- package/examples/sub-agents/agents/codex-main.md +0 -23
- package/examples/sub-agents/agents/codex-review.md +0 -23
- package/examples/sub-agents/agents/cursor-high.md +0 -22
- package/examples/sub-agents/agents/cursor-main.md +0 -22
- package/examples/sub-agents/agents/glm-flash.md +0 -23
- package/examples/sub-agents/agents/glm-high.md +0 -23
- package/examples/sub-agents/agents/scout.md +0 -30
- package/examples/sub-agents/roles/builder-hard.md +0 -34
- package/examples/sub-agents/roles/builder.md +0 -34
- package/examples/sub-agents/roles/explorer.md +0 -39
- package/examples/sub-agents/roles/git-committer.md +0 -43
- package/examples/sub-agents/roles/planner.md +0 -33
- package/examples/sub-agents/roles/reviewer.md +0 -33
- package/examples/sub-agents/roles/verifier.md +0 -35
- package/examples/sub-agents/roles/worker.md +0 -34
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import { antigravityCliHarness } from "./antigravity-cli.js";
|
|
1
2
|
import { claudeCodeHarness } from "./claude-code.js";
|
|
2
3
|
import { codexCliHarness } from "./codex-cli.js";
|
|
3
4
|
import { cursorCliHarness } from "./cursor-cli.js";
|
|
4
5
|
import { execHarness } from "./exec.js";
|
|
6
|
+
/** Exhaustive `Record<RunHarness, ExternalHarness>`: adding an id to `EXTERNAL_HARNESS_IDS` fails typecheck until registered here. */
|
|
5
7
|
const harnesses = {
|
|
6
8
|
"codex-cli": codexCliHarness,
|
|
7
9
|
"claude-code": claudeCodeHarness,
|
|
8
10
|
"cursor-cli": cursorCliHarness,
|
|
11
|
+
"antigravity-cli": antigravityCliHarness,
|
|
9
12
|
exec: execHarness,
|
|
10
13
|
};
|
|
11
14
|
export function getExternalHarness(id) {
|
|
12
|
-
return harnesses[id];
|
|
15
|
+
return Object.hasOwn(harnesses, id) ? harnesses[id] : undefined;
|
|
13
16
|
}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
+
import type { ExternalRoleWarningInput } from "./harness.js";
|
|
1
2
|
/**
|
|
2
|
-
* Non-fatal external-role warnings (spec 042 D4/D10, spec 066 D6). The role still loads.
|
|
3
|
-
*
|
|
3
|
+
* Non-fatal external-role warnings (spec 042 D4/D10, spec 066 D6, spec 068 D7). The role still loads.
|
|
4
|
+
* Shared cross-harness checks run here; CLI-specific flag/mode rules live on each `ExternalHarness`.
|
|
4
5
|
*/
|
|
5
|
-
export
|
|
6
|
-
/** Role filename, so a warning can be traced back to the file that produced it. */
|
|
7
|
-
entryName: string;
|
|
8
|
-
harness: string;
|
|
9
|
-
command: string;
|
|
10
|
-
mutates: "read" | "write";
|
|
11
|
-
/** Resolved memory mode. Anything other than `none` discloses desk memory to the external process. */
|
|
12
|
-
memory: string;
|
|
13
|
-
/** True when frontmatter `model` is set. External models are never taken from the invocation. */
|
|
14
|
-
modelConfigured: boolean;
|
|
15
|
-
}
|
|
6
|
+
export type { ExternalRoleWarningInput };
|
|
16
7
|
/** Join every applicable warning. An unlucky combination must not hide one of them. */
|
|
17
8
|
export declare function externalRoleWarning(input: ExternalRoleWarningInput): string | undefined;
|
|
@@ -1,30 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const FORCE_TOKENS = new Set(["-f", "--force", "--yolo"]);
|
|
3
|
-
function hasWorktreeToken(token) {
|
|
4
|
-
return token === "--worktree" || token === "-w" || token.startsWith("--worktree=");
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Cursor print mode does not write files unless the command itself opts in, and a worktree flag
|
|
8
|
-
* writes somewhere the workspace lease does not cover. Token-based, not a substring search: a path
|
|
9
|
-
* that happens to contain `--force` is not a permission flag.
|
|
10
|
-
*/
|
|
11
|
-
function cursorCommandWarnings(input) {
|
|
12
|
-
if (input.harness !== "cursor-cli")
|
|
13
|
-
return [];
|
|
14
|
-
const tokens = splitShellWords(input.command);
|
|
15
|
-
const hasForce = tokens.some((token) => FORCE_TOKENS.has(token));
|
|
16
|
-
const warnings = [];
|
|
17
|
-
if (input.mutates === "write" && !hasForce) {
|
|
18
|
-
warnings.push(`${input.entryName}: print mode does not write changes to files unless command includes -f, --force, or --yolo`);
|
|
19
|
-
}
|
|
20
|
-
if (input.mutates === "read" && hasForce) {
|
|
21
|
-
warnings.push(`${input.entryName}: command includes -f, --force, or --yolo, so the CLI can modify files and the workspace write lock will not stop it`);
|
|
22
|
-
}
|
|
23
|
-
if (tokens.some(hasWorktreeToken)) {
|
|
24
|
-
warnings.push(`${input.entryName}: --worktree writes under ~/.cursor/worktrees/, outside the delegation working directory, so the workspace write lock does not cover those files`);
|
|
25
|
-
}
|
|
26
|
-
return warnings;
|
|
27
|
-
}
|
|
1
|
+
import { getExternalHarness } from "./registry.js";
|
|
28
2
|
/** Join every applicable warning. An unlucky combination must not hide one of them. */
|
|
29
3
|
export function externalRoleWarning(input) {
|
|
30
4
|
const warnings = [];
|
|
@@ -37,6 +11,8 @@ export function externalRoleWarning(input) {
|
|
|
37
11
|
if (input.command.includes("$MODEL") && !input.modelConfigured) {
|
|
38
12
|
warnings.push(`${input.entryName}: command references $MODEL but no "model" is configured; that argv token will be dropped on every dispatch`);
|
|
39
13
|
}
|
|
40
|
-
|
|
14
|
+
const harnessWarnings = getExternalHarness(input.harness)?.roleWarnings?.(input);
|
|
15
|
+
if (harnessWarnings)
|
|
16
|
+
warnings.push(...harnessWarnings);
|
|
41
17
|
return warnings.length > 0 ? warnings.join("; ") : undefined;
|
|
42
18
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { spawn as nodeSpawn } from "node:child_process";
|
|
2
2
|
import type { SecurityConfig } from "../../security/types.js";
|
|
3
3
|
import { probeCliVersion, readProcessStartTime } from "../../shared/host-process.js";
|
|
4
|
-
import type { SubAgentThinkingLevel } from "../
|
|
5
|
-
import type { RunMutates } from "../run-record.js";
|
|
4
|
+
import type { RunMutates, SubAgentThinkingLevel } from "../run-record.js";
|
|
6
5
|
import type { SubAgentRunManager } from "../runs.js";
|
|
7
6
|
import type { WorkspaceBaseline } from "../workspace-summary.js";
|
|
8
7
|
/**
|
|
@@ -23,7 +23,7 @@ import { finalizeExternalRun } from "./settlement.js";
|
|
|
23
23
|
* `GITHUB_TOKEN`/`NPM_TOKEN` with zero explanation) and under-blocks (`AWS_SECRET_ACCESS_KEY`,
|
|
24
24
|
* `GOOGLE_APPLICATION_CREDENTIALS`, `SSH_AUTH_SOCK` do not match the suffix at all). This list is
|
|
25
25
|
* therefore deliberately narrow: only the env vars pipiclaw's own LLM calls and DingTalk transport
|
|
26
|
-
* read (`src/models/
|
|
26
|
+
* read (`src/models/requests.ts`, the `pi-ai` provider registry). It is a courtesy against
|
|
27
27
|
* accidental inheritance, not a security boundary — the real boundary is the role's own command,
|
|
28
28
|
* CLI sandbox, and host account (AGENTS.md).
|
|
29
29
|
*/
|
|
@@ -95,19 +95,6 @@ function classifySpawnError(error) {
|
|
|
95
95
|
const code = error.code;
|
|
96
96
|
return code === "ENOENT" || code === "EACCES" ? "missing-binary" : "launch-failed";
|
|
97
97
|
}
|
|
98
|
-
function buildStdinContent(harnessId, systemPrompt, task) {
|
|
99
|
-
// claude-code has a real system-prompt flag (--append-system-prompt-file, D4); every other
|
|
100
|
-
// harness has no such channel, so the role's system prompt has nowhere to go but the prompt
|
|
101
|
-
// itself, folded ahead of the task.
|
|
102
|
-
if (harnessId === "claude-code")
|
|
103
|
-
return task;
|
|
104
|
-
const trimmedPrompt = systemPrompt.trim();
|
|
105
|
-
// A capability entry declares no system prompt at all: the task must then start the prompt,
|
|
106
|
-
// with no leading blank section and no `---` fence separating it from nothing.
|
|
107
|
-
if (!trimmedPrompt)
|
|
108
|
-
return `${task.trim()}\n`;
|
|
109
|
-
return `${trimmedPrompt}\n\n---\n\n${task.trim()}\n`;
|
|
110
|
-
}
|
|
111
98
|
/** Launches an external run. Resolves once the process is confirmed spawned (or fails fast if it
|
|
112
99
|
* never starts, spec 042 D2); the wait-for-exit-and-settle work continues in the background
|
|
113
100
|
* afterward. */
|
|
@@ -116,22 +103,22 @@ export async function launchExternalRun(input) {
|
|
|
116
103
|
if (!harness) {
|
|
117
104
|
throw new Error(`Unknown external harness "${input.harness}".`);
|
|
118
105
|
}
|
|
119
|
-
if (input.shell && harness.
|
|
106
|
+
if (input.shell && harness.requiresProtocolTerminal) {
|
|
120
107
|
throw new Error(`External harness "${harness.id}" cannot use shell mode because it would bypass protocol argv assembly. Use a wrapper script as command, or use harness: exec.`);
|
|
121
108
|
}
|
|
122
|
-
// `dispatch.ts`
|
|
123
|
-
// mints a new runId/artifactDir on the spot, so this is the one place that must be reliable
|
|
124
|
-
// either way.
|
|
109
|
+
// `dispatch.ts` creates the artifact dir for both fresh and `follow_up` runs; ensure it here too.
|
|
125
110
|
await mkdir(input.artifactDir, { recursive: true });
|
|
126
111
|
const promptFile = join(input.artifactDir, "prompt.txt");
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
//
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
112
|
+
const isResume = Boolean(input.resumeSessionId);
|
|
113
|
+
const task = `${input.task.trim()}\n`;
|
|
114
|
+
// A resumed transcript already contains the first stdin message. A dedicated system
|
|
115
|
+
// prompt flag still needs the role instructions on every invocation.
|
|
116
|
+
const systemPrompt = harness.acceptsSystemPromptFlag || !isResume ? input.systemPrompt.trim() : "";
|
|
117
|
+
const systemPromptFile = systemPrompt ? join(input.artifactDir, "system-prompt.txt") : undefined;
|
|
118
|
+
const stdinContent = systemPrompt && !harness.acceptsSystemPromptFlag ? `${systemPrompt}\n\n---\n\n${task}` : task;
|
|
119
|
+
await writeFile(promptFile, task, "utf-8");
|
|
133
120
|
if (systemPromptFile)
|
|
134
|
-
await writeFile(systemPromptFile, `${
|
|
121
|
+
await writeFile(systemPromptFile, `${systemPrompt}\n`, "utf-8");
|
|
135
122
|
const argv = input.shell ? [] : splitShellWords(input.command);
|
|
136
123
|
const invocation = input.shell
|
|
137
124
|
? { executable: "/bin/sh", args: ["-lc", input.command], resumable: false }
|
|
@@ -286,6 +273,7 @@ export async function launchExternalRun(input) {
|
|
|
286
273
|
argv: spawnedArgv,
|
|
287
274
|
deadlineAt,
|
|
288
275
|
sessionId: invocation.presetSessionId,
|
|
276
|
+
expectedResumeSessionId: harness.verifiesResumeSession ? input.resumeSessionId : undefined,
|
|
289
277
|
// Spec 042 D1: persisted so a restart reconciliation has the same inputs the live watcher
|
|
290
278
|
// below would — without these, a run that finishes after the daemon disappears would settle
|
|
291
279
|
// with an inaccurate timeout message and an unestimatable duration.
|
|
@@ -373,7 +361,8 @@ export async function launchExternalRun(input) {
|
|
|
373
361
|
fields: { runId: input.runId, taskId: input.taskId, observer: "live", deskDir: input.deskDir },
|
|
374
362
|
});
|
|
375
363
|
const durationMs = Date.now() - processStartedAt;
|
|
376
|
-
const
|
|
364
|
+
const launchedRecord = runManager.get(input.runId);
|
|
365
|
+
const terminationReason = launchedRecord?.terminationReason;
|
|
377
366
|
// Spec 042 D1: parse whatever the process actually wrote *before* applying a cancel/timeout
|
|
378
367
|
// override, instead of returning early on those two reasons. A run killed for wall-time budget
|
|
379
368
|
// or cancelled by request may still have produced useful output, usage, and a resumable session
|
|
@@ -390,6 +379,7 @@ export async function launchExternalRun(input) {
|
|
|
390
379
|
maxWallTimeSec: input.maxWallTimeSec,
|
|
391
380
|
mutates: input.mutates,
|
|
392
381
|
workspaceBaseline: input.workspaceBaseline,
|
|
382
|
+
expectedResumeSessionId: launchedRecord?.expectedResumeSessionId,
|
|
393
383
|
}, (settleInput, options) => runManager.settle(input.runId, settleInput, options), { announce: terminationReason !== "cancelled" }).catch((error) => {
|
|
394
384
|
log.logWarn("subagent.settle.failed", "External run settlement failed", {
|
|
395
385
|
reason: errorMessage(error),
|
|
@@ -33,6 +33,8 @@ export interface FinalizeExternalRunInput {
|
|
|
33
33
|
mutates?: RunMutates;
|
|
34
34
|
/** The run's dispatch-time snapshot, so the summary leaves out paths that were already dirty. */
|
|
35
35
|
workspaceBaseline?: WorkspaceBaseline;
|
|
36
|
+
/** Spec 068 D8: expected resumed session id for `antigravity-cli` follow-ups. */
|
|
37
|
+
expectedResumeSessionId?: string;
|
|
36
38
|
}
|
|
37
39
|
/**
|
|
38
40
|
* Read this run's artifact files, parse them through its harness, decide its verdict (for a
|
|
@@ -2,6 +2,7 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { resolveVerificationVerdict } from "../verification-outcome.js";
|
|
4
4
|
import { changedPathsSummary } from "../workspace-summary.js";
|
|
5
|
+
import { settleManagedWorktree } from "../worktree.js";
|
|
5
6
|
import { classifyExternalOutcome } from "./harness.js";
|
|
6
7
|
import { getExternalHarness } from "./registry.js";
|
|
7
8
|
/**
|
|
@@ -19,7 +20,8 @@ const STDERR_TAIL_CHARS = 2_000;
|
|
|
19
20
|
* session id — those come from whatever the process actually produced, parsed or not.
|
|
20
21
|
*/
|
|
21
22
|
export function buildExternalSettleInput(input) {
|
|
22
|
-
const
|
|
23
|
+
const harness = getExternalHarness(input.harnessId);
|
|
24
|
+
const classification = classifyExternalOutcome(harness ?? input.harnessId, input.outcome);
|
|
23
25
|
const cancelled = input.terminationReason === "cancelled";
|
|
24
26
|
const timedOut = input.terminationReason === "timeout";
|
|
25
27
|
const status = cancelled ? "cancelled" : timedOut ? "failed" : classification.status;
|
|
@@ -62,7 +64,12 @@ export async function finalizeExternalRun(input, settle, options) {
|
|
|
62
64
|
const eventsText = await readFile(eventsPath, "utf-8").catch(() => "");
|
|
63
65
|
const stderrTail = (await readFile(stderrPath, "utf-8").catch(() => "")).slice(-STDERR_TAIL_CHARS);
|
|
64
66
|
const outcome = harness
|
|
65
|
-
? harness.parseOutcome({
|
|
67
|
+
? harness.parseOutcome({
|
|
68
|
+
eventsText,
|
|
69
|
+
exitCode: input.exitCode,
|
|
70
|
+
stderrTail,
|
|
71
|
+
expectedResumeSessionId: input.expectedResumeSessionId,
|
|
72
|
+
})
|
|
66
73
|
: {
|
|
67
74
|
finalText: "",
|
|
68
75
|
terminalSeen: false,
|
|
@@ -80,9 +87,12 @@ export async function finalizeExternalRun(input, settle, options) {
|
|
|
80
87
|
terminationReason: input.terminationReason,
|
|
81
88
|
maxWallTimeSec: input.maxWallTimeSec,
|
|
82
89
|
});
|
|
90
|
+
const worktree = await settleManagedWorktree(input.artifactDir).catch(() => undefined);
|
|
91
|
+
if (worktree)
|
|
92
|
+
settleInput = { ...settleInput, worktree };
|
|
83
93
|
// P2-2: only for a run that actually could have changed the working directory, and only once it
|
|
84
94
|
// is known to have finished cleanly — best-effort, never blocks or fails settlement.
|
|
85
|
-
if (input.mutates === "write" && settleInput.status === "completed") {
|
|
95
|
+
if (input.mutates === "write" && settleInput.status === "completed" && !worktree?.cleaned) {
|
|
86
96
|
const workspaceSummary = await changedPathsSummary(input.workingDirectory, input.workspaceBaseline).catch(() => undefined);
|
|
87
97
|
if (workspaceSummary)
|
|
88
98
|
settleInput = { ...settleInput, workspaceSummary };
|
|
@@ -13,5 +13,5 @@ export declare function elapsedMs(record: RunRecord, now?: number): number;
|
|
|
13
13
|
* mistake it for a precise figure. */
|
|
14
14
|
export declare function formatRunDuration(record: RunRecord, now?: number): string;
|
|
15
15
|
export declare function harnessLabel(record: RunRecord): string;
|
|
16
|
-
/** `undefined` when cost genuinely is not known (e.g. `cursor-cli`, `codex-cli`, `exec`) — never displayed as $0. */
|
|
16
|
+
/** `undefined` when cost genuinely is not known (e.g. `cursor-cli`, `codex-cli`, `antigravity-cli`, `exec`) — never displayed as $0. */
|
|
17
17
|
export declare function formatCost(record: RunRecord): string | undefined;
|
package/dist/subagents/format.js
CHANGED
|
@@ -19,7 +19,7 @@ export function formatRunDuration(record, now = Date.now()) {
|
|
|
19
19
|
export function harnessLabel(record) {
|
|
20
20
|
return record.harness ? `${record.runtime}/${record.harness}` : record.runtime;
|
|
21
21
|
}
|
|
22
|
-
/** `undefined` when cost genuinely is not known (e.g. `cursor-cli`, `codex-cli`, `exec`) — never displayed as $0. */
|
|
22
|
+
/** `undefined` when cost genuinely is not known (e.g. `cursor-cli`, `codex-cli`, `antigravity-cli`, `exec`) — never displayed as $0. */
|
|
23
23
|
export function formatCost(record) {
|
|
24
24
|
if (!record.costKnown)
|
|
25
25
|
return undefined;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { ResolvedInternalSubAgentConfig } from "../discovery.js";
|
|
2
1
|
import type { SettleInput } from "../run-record.js";
|
|
3
|
-
import type { DelegationResult, SubAgentRunContext, SubAgentWorker } from "../types.js";
|
|
2
|
+
import type { DelegationResult, ResolvedInternalSubAgentConfig, SubAgentRunContext, SubAgentWorker } from "../types.js";
|
|
4
3
|
import { type WorkspaceBaseline } from "../workspace-summary.js";
|
|
5
4
|
import type { InternalRunState } from "./state.js";
|
|
6
5
|
/**
|
|
@@ -9,6 +9,7 @@ import { extractAssistantText } from "../../shared/text-utils.js";
|
|
|
9
9
|
import { buildFailureText, buildStoppedText, createDetails, finalizeSubAgentOutput, formatStatus } from "../result.js";
|
|
10
10
|
import { resolveVerificationVerdict } from "../verification-outcome.js";
|
|
11
11
|
import { changedPathsSummary } from "../workspace-summary.js";
|
|
12
|
+
import { settleManagedWorktree } from "../worktree.js";
|
|
12
13
|
import { getLastAssistantMessage } from "./worker.js";
|
|
13
14
|
/**
|
|
14
15
|
* Assemble the result of a finished worker. Rejects only for the single fatal case (no assistant
|
|
@@ -42,6 +43,18 @@ export async function buildInternalOutcome(input) {
|
|
|
42
43
|
// free/local model produces (tokens spent, nothing billed) — external harnesses
|
|
43
44
|
// override both explicitly once they land (D4/D9).
|
|
44
45
|
const costKnown = usage.cost.total > 0 || usage.total === 0;
|
|
46
|
+
if (effectiveFailureReason && !finalText.trim()) {
|
|
47
|
+
emitUpdate(formatStatus(config.name, "failed"));
|
|
48
|
+
// Settlement records the reason itself, not the next-step advice wrapped around it below.
|
|
49
|
+
state.failureReason = effectiveFailureReason;
|
|
50
|
+
// The delegating model can act on this alone — re-dispatch, narrow the task, or do the
|
|
51
|
+
// work itself — so it is not a user-facing error bubble.
|
|
52
|
+
throw new RecoverableToolError(`${fallbackLine}${buildFailureText(config, effectiveFailureReason, finalText)}\n` +
|
|
53
|
+
`Retry the delegation (narrower if it hit a budget), or do the work directly; subagent_run op=show runId=${runContext.runId} has the details.`);
|
|
54
|
+
}
|
|
55
|
+
const worktree = runContext.managedWorktree
|
|
56
|
+
? await settleManagedWorktree(runContext.artifactDir, undefined, runContext.runId).catch(() => undefined)
|
|
57
|
+
: undefined;
|
|
45
58
|
const baseSettleInput = {
|
|
46
59
|
usage,
|
|
47
60
|
usageKnown: true,
|
|
@@ -51,19 +64,11 @@ export async function buildInternalOutcome(input) {
|
|
|
51
64
|
durationMs,
|
|
52
65
|
verificationVerdict,
|
|
53
66
|
model: modelRef,
|
|
67
|
+
...(worktree ? { worktree } : {}),
|
|
54
68
|
};
|
|
55
69
|
if (effectiveFailureReason) {
|
|
56
|
-
if (!finalText.trim()) {
|
|
57
|
-
emitUpdate(formatStatus(config.name, "failed"));
|
|
58
|
-
// Settlement records the reason itself, not the next-step advice wrapped around it below.
|
|
59
|
-
state.failureReason = effectiveFailureReason;
|
|
60
|
-
// The delegating model can act on this alone — re-dispatch, narrow the task, or do the
|
|
61
|
-
// work itself — so it is not a user-facing error bubble.
|
|
62
|
-
throw new RecoverableToolError(`${fallbackLine}${buildFailureText(config, effectiveFailureReason, finalText)}\n` +
|
|
63
|
-
`Retry the delegation (narrower if it hit a budget), or do the work directly; subagent_run op=show runId=${runContext.runId} has the details.`);
|
|
64
|
-
}
|
|
65
70
|
emitUpdate(formatStatus(config.name, "stopped"));
|
|
66
|
-
const finalized = finalizeSubAgentOutput(runContext, finalText);
|
|
71
|
+
const finalized = finalizeSubAgentOutput(runContext, finalText, worktree);
|
|
67
72
|
return {
|
|
68
73
|
toolResult: {
|
|
69
74
|
content: [
|
|
@@ -84,6 +89,7 @@ export async function buildInternalOutcome(input) {
|
|
|
84
89
|
verificationVerdict,
|
|
85
90
|
resultTruncated: finalized.truncated,
|
|
86
91
|
modelOverride: modelRef,
|
|
92
|
+
worktree,
|
|
87
93
|
}),
|
|
88
94
|
},
|
|
89
95
|
settleInput: {
|
|
@@ -98,13 +104,13 @@ export async function buildInternalOutcome(input) {
|
|
|
98
104
|
}
|
|
99
105
|
// P2-2, same as an external write run: what this run changed, so the reader does not spend
|
|
100
106
|
// its first tool call finding out. Only a cleanly completed write run pays for it.
|
|
101
|
-
const workspaceSummary = config.mutates === "write"
|
|
107
|
+
const workspaceSummary = config.mutates === "write" && !worktree?.cleaned
|
|
102
108
|
? await changedPathsSummary(runContext.workingDirectory, input.workspaceBaseline).catch(() => undefined)
|
|
103
109
|
: undefined;
|
|
104
110
|
const workspaceLine = workspaceSummary
|
|
105
111
|
? `\n\nWorkspace after the run (git status --porcelain): ${workspaceSummary}`
|
|
106
112
|
: "";
|
|
107
|
-
const finalized = finalizeSubAgentOutput(runContext, finalText);
|
|
113
|
+
const finalized = finalizeSubAgentOutput(runContext, finalText, worktree);
|
|
108
114
|
return {
|
|
109
115
|
toolResult: {
|
|
110
116
|
content: [
|
|
@@ -126,6 +132,7 @@ export async function buildInternalOutcome(input) {
|
|
|
126
132
|
verificationVerdict,
|
|
127
133
|
resultTruncated: finalized.truncated,
|
|
128
134
|
modelOverride: modelRef,
|
|
135
|
+
worktree,
|
|
129
136
|
}),
|
|
130
137
|
},
|
|
131
138
|
settleInput: { ...baseSettleInput, status: "completed", outputText: finalText, workspaceSummary },
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type ResolvedInternalSubAgentConfig } from "../
|
|
2
|
-
import type { SubAgentToolOptions, SubAgentWorker } from "../types.js";
|
|
1
|
+
import { type ResolvedInternalSubAgentConfig, type SubAgentToolOptions, type SubAgentWorker } from "../types.js";
|
|
3
2
|
import type { InternalRunState } from "./state.js";
|
|
4
3
|
/**
|
|
5
4
|
* A transcript ending in a provider error is retried in place (the error message removed, the
|
|
@@ -7,8 +7,8 @@ import { clampThinkingLevel, isRetryableAssistantError } from "@earendil-works/p
|
|
|
7
7
|
import { shouldFallback } from "../../models/fallback.js";
|
|
8
8
|
import { formatModelReference } from "../../models/reference.js";
|
|
9
9
|
import { sleepUnref } from "../../shared/with-timeout.js";
|
|
10
|
-
import { DEFAULT_THINKING_LEVEL } from "../discovery.js";
|
|
11
10
|
import { formatStatus } from "../result.js";
|
|
11
|
+
import { DEFAULT_THINKING_LEVEL, } from "../types.js";
|
|
12
12
|
import { isAssistantMessage } from "./worker.js";
|
|
13
13
|
/**
|
|
14
14
|
* A provider error (429, overloaded, 5xx, dropped stream) used to fail an internal run outright —
|
|
@@ -57,9 +57,8 @@ export async function recoverFromProviderErrors(input) {
|
|
|
57
57
|
return;
|
|
58
58
|
if (!candidate || formatModelReference(candidate) === formatModelReference(state.activeModel))
|
|
59
59
|
return;
|
|
60
|
-
let candidateKey;
|
|
61
60
|
try {
|
|
62
|
-
|
|
61
|
+
await options.modelRequests.ensureAuth(candidate, retryBackoff.signal);
|
|
63
62
|
}
|
|
64
63
|
catch {
|
|
65
64
|
return;
|
|
@@ -70,7 +69,6 @@ export async function recoverFromProviderErrors(input) {
|
|
|
70
69
|
retries = 0;
|
|
71
70
|
const fromRef = formatModelReference(state.activeModel);
|
|
72
71
|
state.activeModel = candidate;
|
|
73
|
-
state.apiKey = candidateKey;
|
|
74
72
|
worker.state.model = candidate;
|
|
75
73
|
worker.state.thinkingLevel = clampThinkingLevel(candidate, config.thinkingLevel ?? DEFAULT_THINKING_LEVEL);
|
|
76
74
|
state.fallbackNote = `switched from ${fromRef} to backup model ${formatModelReference(candidate)} after: ${last.errorMessage?.split("\n")[0]?.slice(0, 200) ?? "unknown error"}`;
|
|
@@ -8,10 +8,9 @@
|
|
|
8
8
|
* lease release on every pre-registration failure, the cancel handle installed before any setup I/O,
|
|
9
9
|
* and the grace/detach split all stay here, in this order.
|
|
10
10
|
*/
|
|
11
|
-
import type
|
|
12
|
-
import type { ResolvedInternalSubAgentConfig } from "../discovery.js";
|
|
11
|
+
import { type Api, type Model } from "@earendil-works/pi-ai";
|
|
13
12
|
import type { SubAgentRunManager } from "../runs.js";
|
|
14
|
-
import type { DelegationParams, DelegationResult, SubAgentRunContext, SubAgentToolOptions } from "../types.js";
|
|
13
|
+
import type { DelegationParams, DelegationResult, ResolvedInternalSubAgentConfig, SubAgentRunContext, SubAgentToolOptions } from "../types.js";
|
|
15
14
|
import type { WorkspaceBaseline } from "../workspace-summary.js";
|
|
16
15
|
interface InternalRunInput {
|
|
17
16
|
options: SubAgentToolOptions;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `runtime: internal` half of delegation dispatch (spec 046 D2.5): register the durable run
|
|
3
|
+
* record, start the worker, drive it to completion (with the D6 convergence turn), settle it, and
|
|
4
|
+
* return either its real result or — once the sync grace window elapses — a "[Dispatched]"
|
|
5
|
+
* placeholder while the run keeps going in the background.
|
|
6
|
+
*
|
|
7
|
+
* Orchestration only: the worker, provider retry and outcome assembly live in their own files. The
|
|
8
|
+
* lease release on every pre-registration failure, the cancel handle installed before any setup I/O,
|
|
9
|
+
* and the grace/detach split all stay here, in this order.
|
|
10
|
+
*/
|
|
11
|
+
import { cleanupSessionResources } from "@earendil-works/pi-ai";
|
|
1
12
|
import * as log from "../../log.js";
|
|
2
13
|
import { formatModelReference } from "../../models/reference.js";
|
|
3
14
|
import { errorMessage } from "../../shared/text-utils.js";
|
|
@@ -20,15 +31,14 @@ const CONVERGENCE_PROMPT = "Your turn/tool-call/wall-time budget for this task i
|
|
|
20
31
|
export async function dispatchInternalRun(input) {
|
|
21
32
|
const { options, config, runLabel, mutatesNote, runContext, leaseKey, params, signal, onUpdate, runManager } = input;
|
|
22
33
|
const scopedExecutor = new DirectoryExecutor(options.executor, runContext.workingDirectory);
|
|
23
|
-
let apiKey;
|
|
24
34
|
try {
|
|
25
|
-
|
|
35
|
+
await options.modelRequests.ensureAuth(config.model, signal);
|
|
26
36
|
}
|
|
27
37
|
catch (error) {
|
|
28
38
|
releaseWorkspaceLease(leaseKey, runContext.runId);
|
|
29
39
|
throw error;
|
|
30
40
|
}
|
|
31
|
-
const state = createInternalRunState(config.model
|
|
41
|
+
const state = createInternalRunState(config.model);
|
|
32
42
|
/** Wakes a retry backoff early when the run is cancelled or out of wall time. */
|
|
33
43
|
const retryBackoff = new AbortController();
|
|
34
44
|
const handle = {};
|
|
@@ -140,7 +150,7 @@ export async function dispatchInternalRun(input) {
|
|
|
140
150
|
{
|
|
141
151
|
type: "text",
|
|
142
152
|
text: mutatesNote +
|
|
143
|
-
buildDispatchedText(runContext.runId, config.name, "internal, async", runContext.workingDirectory),
|
|
153
|
+
buildDispatchedText(runContext.runId, config.name, "internal, async", runContext.workingDirectory, runContext.managedWorktree),
|
|
144
154
|
},
|
|
145
155
|
],
|
|
146
156
|
details: createDetails({
|
|
@@ -203,6 +213,7 @@ async function runToCompletion(ctx) {
|
|
|
203
213
|
finally {
|
|
204
214
|
ctx.unsubscribe();
|
|
205
215
|
clearTimeout(ctx.wallClockTimer);
|
|
216
|
+
releaseSessionResources(runContext.runId);
|
|
206
217
|
}
|
|
207
218
|
return buildInternalOutcome({
|
|
208
219
|
worker,
|
|
@@ -226,6 +237,7 @@ async function failSetup(error, handle, state, runManager, runContext) {
|
|
|
226
237
|
catch {
|
|
227
238
|
// Preserve the setup error; settlement below is the lifecycle authority.
|
|
228
239
|
}
|
|
240
|
+
releaseSessionResources(runContext.runId);
|
|
229
241
|
const setupError = error instanceof Error ? error : new Error(String(error));
|
|
230
242
|
await runManager.settle(runContext.runId, {
|
|
231
243
|
status: "failed",
|
|
@@ -240,3 +252,14 @@ async function failSetup(error, handle, state, runManager, runContext) {
|
|
|
240
252
|
}, { announce: false });
|
|
241
253
|
throw setupError;
|
|
242
254
|
}
|
|
255
|
+
function releaseSessionResources(runId) {
|
|
256
|
+
try {
|
|
257
|
+
cleanupSessionResources(runId);
|
|
258
|
+
}
|
|
259
|
+
catch (error) {
|
|
260
|
+
log.logWarn("subagent.session.cleanup_failed", "Worker session cleanup failed", {
|
|
261
|
+
reason: errorMessage(error),
|
|
262
|
+
fields: { runId },
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
7
7
|
import { type UsageTotals } from "../../usage/totals.js";
|
|
8
|
-
import type { ResolvedInternalSubAgentConfig } from "../
|
|
9
|
-
import type { SubAgentRunContext, SubAgentToolFields } from "../types.js";
|
|
8
|
+
import type { ResolvedInternalSubAgentConfig, SubAgentRunContext, SubAgentToolFields } from "../types.js";
|
|
10
9
|
export interface InternalRunState {
|
|
11
10
|
readonly startedAt: number;
|
|
12
11
|
readonly usage: UsageTotals;
|
|
@@ -24,10 +23,8 @@ export interface InternalRunState {
|
|
|
24
23
|
activeModel: Model<Api>;
|
|
25
24
|
/** Set when the run switched to the backup model, for the reply and the record. */
|
|
26
25
|
fallbackNote: string | undefined;
|
|
27
|
-
/** Read on every provider request, so a backup-model switch only has to replace the key. */
|
|
28
|
-
apiKey: string;
|
|
29
26
|
}
|
|
30
|
-
export declare function createInternalRunState(model: Model<Api
|
|
27
|
+
export declare function createInternalRunState(model: Model<Api>): InternalRunState;
|
|
31
28
|
/** Progress sink: forwards a status line to the dispatching tool call until the run detaches. */
|
|
32
29
|
export declare function createUpdateEmitter(input: {
|
|
33
30
|
config: ResolvedInternalSubAgentConfig;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { formatModelReference } from "../../models/reference.js";
|
|
2
2
|
import { createEmptyUsageTotals } from "../../usage/totals.js";
|
|
3
3
|
import { createDetails } from "../result.js";
|
|
4
|
-
export function createInternalRunState(model
|
|
4
|
+
export function createInternalRunState(model) {
|
|
5
5
|
return {
|
|
6
6
|
startedAt: Date.now(),
|
|
7
7
|
usage: createEmptyUsageTotals(),
|
|
@@ -14,7 +14,6 @@ export function createInternalRunState(model, apiKey) {
|
|
|
14
14
|
lastUpdateText: "",
|
|
15
15
|
activeModel: model,
|
|
16
16
|
fallbackNote: undefined,
|
|
17
|
-
apiKey,
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
19
|
/** Progress sink: forwards a status line to the dispatching tool call until the run detaches. */
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
import { type AgentMessage, type AgentTool } from "@earendil-works/pi-agent-core";
|
|
6
6
|
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
7
7
|
import type { ExecOptions, ExecResult, Executor } from "../../executor.js";
|
|
8
|
-
import { type ResolvedInternalSubAgentConfig } from "../discovery.js";
|
|
9
8
|
import type { SubAgentRunManager } from "../runs.js";
|
|
10
|
-
import type
|
|
9
|
+
import { type ResolvedInternalSubAgentConfig, type SubAgentRunContext, type SubAgentToolOptions, type SubAgentWorker } from "../types.js";
|
|
11
10
|
import type { InternalRunState } from "./state.js";
|
|
12
11
|
/**
|
|
13
12
|
* Pins every command a run issues to the run's working directory. It sets the child's real `cwd`
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* SDK agent, and the event subscription that counts turns and tool calls and enforces the budgets.
|
|
4
4
|
*/
|
|
5
5
|
import { Agent } from "@earendil-works/pi-agent-core";
|
|
6
|
-
import { clampThinkingLevel
|
|
6
|
+
import { clampThinkingLevel } from "@earendil-works/pi-ai/compat";
|
|
7
7
|
import { convertToLlm } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import * as log from "../../log.js";
|
|
9
9
|
import { getJournalDir } from "../../memory/journal.js";
|
|
@@ -12,8 +12,9 @@ import { DEFAULT_SECURITY_CONFIG } from "../../security/config.js";
|
|
|
12
12
|
import { withExecutionTrace } from "../../tools/contract/execution-trace.js";
|
|
13
13
|
import { describeToolCall } from "../../tools/contract/presentation.js";
|
|
14
14
|
import { addUsage } from "../../usage/totals.js";
|
|
15
|
-
import {
|
|
15
|
+
import { withSubAgentsDirWriteDeny } from "../discovery.js";
|
|
16
16
|
import { formatStatus } from "../result.js";
|
|
17
|
+
import { DEFAULT_THINKING_LEVEL, } from "../types.js";
|
|
17
18
|
/**
|
|
18
19
|
* Pins every command a run issues to the run's working directory. It sets the child's real `cwd`
|
|
19
20
|
* rather than prefixing `cd <dir> &&`: the prefix silently produced a *different* command than the
|
|
@@ -69,23 +70,34 @@ function withSubagentMemoryWriteDeny(securityConfig, deskDir, workspaceDir) {
|
|
|
69
70
|
*/
|
|
70
71
|
export function buildSubagentTools(executor, bashTimeoutSec, options, runContext) {
|
|
71
72
|
const securityConfig = withSubagentMemoryWriteDeny(options.securityConfig ?? DEFAULT_SECURITY_CONFIG, options.deskDir, options.workspaceDir);
|
|
72
|
-
|
|
73
|
-
.buildWorkerTools({
|
|
73
|
+
const tools = options.buildWorkerTools({
|
|
74
74
|
executor,
|
|
75
75
|
fileStore: options.fileStore,
|
|
76
76
|
securityConfig,
|
|
77
77
|
securityContext: {
|
|
78
78
|
agentWorkspaceDir: options.workspaceDir,
|
|
79
79
|
cwd: runContext.workingDirectory,
|
|
80
|
+
...(options.appHomeDir ? { appHomeDir: options.appHomeDir } : {}),
|
|
80
81
|
},
|
|
81
82
|
channelId: options.runtimeContext.channelId,
|
|
82
83
|
deskDir: options.deskDir,
|
|
83
84
|
workspaceDir: options.workspaceDir,
|
|
84
85
|
webConfig: options.webConfig,
|
|
85
86
|
rtkEnabled: options.rtkEnabled,
|
|
87
|
+
bashInterceptorEnabled: options.bashInterceptorEnabled,
|
|
86
88
|
bashDefaultTimeoutSeconds: bashTimeoutSec,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
+
leaseOwnerRunId: runContext.runId,
|
|
90
|
+
});
|
|
91
|
+
if (runContext.purpose !== "verify")
|
|
92
|
+
return tools;
|
|
93
|
+
return tools
|
|
94
|
+
.filter((tool) => tool.name !== "write" && tool.name !== "edit")
|
|
95
|
+
.map((tool) => tool.name === "bash"
|
|
96
|
+
? {
|
|
97
|
+
...tool,
|
|
98
|
+
description: `${tool.description} Verification mode (purpose=verify): run read-only checks and tests only; do NOT modify tracked workspace files.`,
|
|
99
|
+
}
|
|
100
|
+
: tool);
|
|
89
101
|
}
|
|
90
102
|
function filterToolsByName(allTools, names) {
|
|
91
103
|
const allowed = new Set(names);
|
|
@@ -113,10 +125,10 @@ export function startWorker(input) {
|
|
|
113
125
|
handle.worker =
|
|
114
126
|
options.createWorker?.({
|
|
115
127
|
subAgent: config,
|
|
116
|
-
apiKey: state.apiKey,
|
|
117
128
|
tools: filterToolsByName(availableTools, config.tools),
|
|
118
129
|
}) ??
|
|
119
130
|
new Agent({
|
|
131
|
+
sessionId: runContext.runId,
|
|
120
132
|
initialState: {
|
|
121
133
|
systemPrompt: config.systemPrompt,
|
|
122
134
|
model: config.model,
|
|
@@ -129,14 +141,12 @@ export function startWorker(input) {
|
|
|
129
141
|
tools: filterToolsByName(availableTools, config.tools),
|
|
130
142
|
},
|
|
131
143
|
convertToLlm,
|
|
132
|
-
// Read on every request, so a backup-model switch only has to replace the key.
|
|
133
|
-
getApiKey: async () => state.apiKey,
|
|
134
144
|
streamFn: (model, context, streamOptions) => {
|
|
135
145
|
request++;
|
|
136
146
|
requestStartedAt = Date.now();
|
|
137
147
|
firstOutput = false;
|
|
138
148
|
log.logEvent("debug", "agent.provider.started", "Provider request started", { fields: traceFields() });
|
|
139
|
-
return
|
|
149
|
+
return options.modelRequests.stream(model, context, streamOptions);
|
|
140
150
|
},
|
|
141
151
|
});
|
|
142
152
|
handle.wallClockTimer = setTimeout(() => {
|