@oyasmi/pipiclaw 0.9.5 → 0.9.6-beta.1
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 +220 -126
- package/README.md +217 -123
- package/dist/agent/channel-runner.d.ts +1 -1
- package/dist/agent/channel-runner.js +1 -1
- package/dist/agent/prompt/sections.js +1 -1
- package/dist/agent/prompt/types.d.ts +2 -1
- package/dist/agent/session/compaction.d.ts +2 -0
- package/dist/agent/session/compaction.js +22 -14
- package/dist/agent/session/session-host.d.ts +1 -1
- package/dist/agent/session/session-host.js +3 -1
- package/dist/agent/stop-watchdog.js +5 -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 +3 -1
- package/dist/channel/attachments.d.ts +4 -0
- package/dist/channel/attachments.js +4 -0
- package/dist/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +25 -9
- package/dist/commands/router.js +5 -1
- package/dist/desk/commands.d.ts +14 -2
- package/dist/desk/commands.js +68 -20
- package/dist/desk/registry.d.ts +6 -2
- package/dist/desk/registry.js +70 -4
- package/dist/desk/types.d.ts +17 -0
- package/dist/dingtalk/bot.d.ts +1 -1
- package/dist/dingtalk/bot.js +4 -3
- package/dist/dingtalk/delivery.js +13 -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 +18 -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 +3 -7
- package/dist/events/watcher.js +51 -56
- 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/memory/reflect.js +23 -3
- package/dist/memory/session-corpus.d.ts +1 -1
- package/dist/memory/session-corpus.js +70 -1
- package/dist/memory/session-search.js +13 -11
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +19 -9
- package/dist/playbooks/agent-delegation.md +5 -4
- package/dist/playbooks/memory-and-learning.md +1 -1
- package/dist/playbooks/task-lead.md +4 -4
- package/dist/runtime/bootstrap.d.ts +6 -0
- package/dist/runtime/bootstrap.js +11 -7
- package/dist/runtime/desk-runtime.d.ts +8 -2
- package/dist/runtime/desk-runtime.js +35 -4
- 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-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 +1 -0
- package/dist/runtime/shutdown.js +87 -35
- package/dist/runtime/task-control.d.ts +1 -0
- package/dist/runtime/task-control.js +25 -2
- package/dist/runtime/task-lane.d.ts +1 -0
- package/dist/runtime/task-lane.js +21 -6
- package/dist/runtime/task-step.js +11 -2
- package/dist/runtime/turn-run.js +103 -66
- package/dist/security/command-guard.d.ts +1 -1
- package/dist/security/command-guard.js +237 -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/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 +39 -20
- 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 +139 -11
- 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 +11 -11
- package/dist/subagents/external/settlement.d.ts +2 -0
- package/dist/subagents/external/settlement.js +8 -2
- 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/provider-retry.d.ts +1 -2
- package/dist/subagents/internal/provider-retry.js +1 -1
- package/dist/subagents/internal/run.d.ts +1 -2
- package/dist/subagents/internal/state.d.ts +1 -2
- package/dist/subagents/internal/worker.d.ts +1 -2
- package/dist/subagents/internal/worker.js +3 -1
- package/dist/subagents/resolve.d.ts +56 -0
- package/dist/subagents/resolve.js +202 -0
- package/dist/subagents/result.d.ts +1 -2
- package/dist/subagents/result.js +7 -3
- package/dist/subagents/run-record.d.ts +33 -2
- package/dist/subagents/run-record.js +2 -0
- package/dist/subagents/runs.d.ts +2 -24
- package/dist/subagents/runs.js +6 -0
- package/dist/subagents/task-envelope.d.ts +1 -2
- package/dist/subagents/task-envelope.js +8 -4
- package/dist/subagents/types.d.ts +93 -4
- package/dist/subagents/types.js +16 -1
- package/dist/subagents/workspace-lease.d.ts +11 -21
- package/dist/subagents/workspace-lease.js +48 -21
- package/dist/subagents/worktree.d.ts +10 -0
- package/dist/subagents/worktree.js +77 -0
- package/dist/tasks/archive.js +4 -0
- package/dist/tasks/commands.d.ts +3 -0
- package/dist/tasks/commands.js +16 -2
- package/dist/tasks/control.d.ts +2 -0
- package/dist/tasks/delivery.d.ts +2 -0
- package/dist/tasks/delivery.js +141 -21
- package/dist/tasks/loop-log.d.ts +2 -0
- package/dist/tasks/loop-log.js +9 -0
- package/dist/tools/bash.js +2 -0
- package/dist/tools/contract/presentation.js +3 -4
- package/dist/tools/event-manage.d.ts +2 -0
- package/dist/tools/event-manage.js +20 -2
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.js +2 -0
- package/dist/tools/registry.js +3 -1
- package/dist/tools/send-media.js +9 -5
- package/dist/tools/session-search.js +1 -1
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +15 -149
- package/dist/tools/subagent.d.ts +2 -0
- package/dist/tools/subagent.js +6 -1
- package/dist/tools/task-manage/factory.js +2 -2
- package/dist/tools/task-manage/lifecycle.d.ts +3 -3
- package/dist/tools/task-manage/lifecycle.js +49 -9
- package/dist/tools/task-manage/schema.d.ts +4 -1
- package/dist/tools/task-manage/schema.js +4 -1
- package/dist/tools/task-manage/types.d.ts +4 -1
- package/dist/tui/cli.d.ts +1 -6
- package/dist/tui/cli.js +29 -3
- package/dist/tui/client.d.ts +2 -0
- package/dist/tui/client.js +13 -4
- package/dist/usage/ledger.d.ts +1 -1
- package/dist/usage/render.js +1 -1
- package/examples/sub-agents/README.md +39 -73
- package/examples/sub-agents/agents/agy-main.md +23 -0
- package/examples/sub-agents/agents/claude-high.md +9 -9
- package/examples/sub-agents/agents/claude-main.md +9 -9
- package/examples/sub-agents/agents/codex-flash.md +9 -9
- package/examples/sub-agents/agents/codex-high.md +9 -9
- package/examples/sub-agents/agents/codex-main.md +9 -9
- package/examples/sub-agents/agents/codex-review.md +9 -9
- package/examples/sub-agents/agents/cursor-high.md +9 -9
- package/examples/sub-agents/agents/cursor-main.md +9 -9
- package/examples/sub-agents/agents/glm-flash.md +9 -9
- package/examples/sub-agents/agents/glm-high.md +9 -9
- package/package.json +8 -8
- 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,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
|
/**
|
|
@@ -95,11 +95,10 @@ 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(
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
if (harnessId === "claude-code")
|
|
98
|
+
function buildStdinContent(harness, systemPrompt, task) {
|
|
99
|
+
// Harnesses with a dedicated system-prompt flag (`claude-code`'s `--append-system-prompt-file`, D4)
|
|
100
|
+
// receive `task` alone on stdin; others fold `systemPrompt` ahead of `task`.
|
|
101
|
+
if (harness.acceptsSystemPromptFlag)
|
|
103
102
|
return task;
|
|
104
103
|
const trimmedPrompt = systemPrompt.trim();
|
|
105
104
|
// A capability entry declares no system prompt at all: the task must then start the prompt,
|
|
@@ -116,19 +115,17 @@ export async function launchExternalRun(input) {
|
|
|
116
115
|
if (!harness) {
|
|
117
116
|
throw new Error(`Unknown external harness "${input.harness}".`);
|
|
118
117
|
}
|
|
119
|
-
if (input.shell && harness.
|
|
118
|
+
if (input.shell && harness.requiresProtocolTerminal) {
|
|
120
119
|
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
120
|
}
|
|
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.
|
|
121
|
+
// `dispatch.ts` creates the artifact dir for both fresh and `follow_up` runs; ensure it here too.
|
|
125
122
|
await mkdir(input.artifactDir, { recursive: true });
|
|
126
123
|
const promptFile = join(input.artifactDir, "prompt.txt");
|
|
127
124
|
const trimmedSystemPrompt = input.systemPrompt.trim();
|
|
128
125
|
// Only written when the role actually declares one, so `system-prompt.txt`'s presence in a run's
|
|
129
126
|
// artifacts stays a truthful record of what was sent (D1 layout) instead of an empty decoy.
|
|
130
127
|
const systemPromptFile = trimmedSystemPrompt ? join(input.artifactDir, "system-prompt.txt") : undefined;
|
|
131
|
-
const stdinContent = buildStdinContent(harness
|
|
128
|
+
const stdinContent = buildStdinContent(harness, input.systemPrompt, input.task);
|
|
132
129
|
await writeFile(promptFile, `${input.task.trim()}\n`, "utf-8");
|
|
133
130
|
if (systemPromptFile)
|
|
134
131
|
await writeFile(systemPromptFile, `${trimmedSystemPrompt}\n`, "utf-8");
|
|
@@ -286,6 +283,7 @@ export async function launchExternalRun(input) {
|
|
|
286
283
|
argv: spawnedArgv,
|
|
287
284
|
deadlineAt,
|
|
288
285
|
sessionId: invocation.presetSessionId,
|
|
286
|
+
expectedResumeSessionId: harness.verifiesResumeSession ? input.resumeSessionId : undefined,
|
|
289
287
|
// Spec 042 D1: persisted so a restart reconciliation has the same inputs the live watcher
|
|
290
288
|
// below would — without these, a run that finishes after the daemon disappears would settle
|
|
291
289
|
// with an inaccurate timeout message and an unestimatable duration.
|
|
@@ -373,7 +371,8 @@ export async function launchExternalRun(input) {
|
|
|
373
371
|
fields: { runId: input.runId, taskId: input.taskId, observer: "live", deskDir: input.deskDir },
|
|
374
372
|
});
|
|
375
373
|
const durationMs = Date.now() - processStartedAt;
|
|
376
|
-
const
|
|
374
|
+
const launchedRecord = runManager.get(input.runId);
|
|
375
|
+
const terminationReason = launchedRecord?.terminationReason;
|
|
377
376
|
// Spec 042 D1: parse whatever the process actually wrote *before* applying a cancel/timeout
|
|
378
377
|
// override, instead of returning early on those two reasons. A run killed for wall-time budget
|
|
379
378
|
// or cancelled by request may still have produced useful output, usage, and a resumable session
|
|
@@ -390,6 +389,7 @@ export async function launchExternalRun(input) {
|
|
|
390
389
|
maxWallTimeSec: input.maxWallTimeSec,
|
|
391
390
|
mutates: input.mutates,
|
|
392
391
|
workspaceBaseline: input.workspaceBaseline,
|
|
392
|
+
expectedResumeSessionId: launchedRecord?.expectedResumeSessionId,
|
|
393
393
|
}, (settleInput, options) => runManager.settle(input.runId, settleInput, options), { announce: terminationReason !== "cancelled" }).catch((error) => {
|
|
394
394
|
log.logWarn("subagent.settle.failed", "External run settlement failed", {
|
|
395
395
|
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
|
|
@@ -19,7 +19,8 @@ const STDERR_TAIL_CHARS = 2_000;
|
|
|
19
19
|
* session id — those come from whatever the process actually produced, parsed or not.
|
|
20
20
|
*/
|
|
21
21
|
export function buildExternalSettleInput(input) {
|
|
22
|
-
const
|
|
22
|
+
const harness = getExternalHarness(input.harnessId);
|
|
23
|
+
const classification = classifyExternalOutcome(harness ?? input.harnessId, input.outcome);
|
|
23
24
|
const cancelled = input.terminationReason === "cancelled";
|
|
24
25
|
const timedOut = input.terminationReason === "timeout";
|
|
25
26
|
const status = cancelled ? "cancelled" : timedOut ? "failed" : classification.status;
|
|
@@ -62,7 +63,12 @@ export async function finalizeExternalRun(input, settle, options) {
|
|
|
62
63
|
const eventsText = await readFile(eventsPath, "utf-8").catch(() => "");
|
|
63
64
|
const stderrTail = (await readFile(stderrPath, "utf-8").catch(() => "")).slice(-STDERR_TAIL_CHARS);
|
|
64
65
|
const outcome = harness
|
|
65
|
-
? harness.parseOutcome({
|
|
66
|
+
? harness.parseOutcome({
|
|
67
|
+
eventsText,
|
|
68
|
+
exitCode: input.exitCode,
|
|
69
|
+
stderrTail,
|
|
70
|
+
expectedResumeSessionId: input.expectedResumeSessionId,
|
|
71
|
+
})
|
|
66
72
|
: {
|
|
67
73
|
finalText: "",
|
|
68
74
|
terminalSeen: false,
|
|
@@ -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
|
/**
|
|
@@ -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 —
|
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
* and the grace/detach split all stay here, in this order.
|
|
10
10
|
*/
|
|
11
11
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
12
|
-
import type { ResolvedInternalSubAgentConfig } from "../discovery.js";
|
|
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;
|
|
@@ -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;
|
|
@@ -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`
|
|
@@ -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
|
|
@@ -77,6 +78,7 @@ export function buildSubagentTools(executor, bashTimeoutSec, options, runContext
|
|
|
77
78
|
securityContext: {
|
|
78
79
|
agentWorkspaceDir: options.workspaceDir,
|
|
79
80
|
cwd: runContext.workingDirectory,
|
|
81
|
+
...(options.appHomeDir ? { appHomeDir: options.appHomeDir } : {}),
|
|
80
82
|
},
|
|
81
83
|
channelId: options.runtimeContext.channelId,
|
|
82
84
|
deskDir: options.deskDir,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Call-time invocation resolution for `subagent` (role-based) and `subagent_inline` (spec 046
|
|
3
|
+
* D2.1), plus delegation task-length validation and available-role formatting. Kept separate from
|
|
4
|
+
* `discovery.ts` so tool-call execution and inline workers do not couple to filesystem role scanning.
|
|
5
|
+
*/
|
|
6
|
+
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
7
|
+
import { type ResolvedInternalSubAgentConfig, type ResolvedSubAgentConfig, type SubAgentConfig } from "./types.js";
|
|
8
|
+
/**
|
|
9
|
+
* `subagent` (role-based) invocation surface (spec 046, D2.1). Deliberately has no override
|
|
10
|
+
* fields beyond `purpose`: everything else a configured role could vary lives in the role file.
|
|
11
|
+
*/
|
|
12
|
+
interface ConfiguredRoleOverrides {
|
|
13
|
+
agent: string;
|
|
14
|
+
/** Drives the thinkingLevel default: "verify" defaults on, everything else stays off. */
|
|
15
|
+
purpose?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* `subagent_inline` invocation surface (spec 046, D2.1) — a one-off executor with no role file,
|
|
19
|
+
* so every field a role file would otherwise supply is a call-time override here instead.
|
|
20
|
+
*/
|
|
21
|
+
interface InlineAgentOverrides {
|
|
22
|
+
systemPrompt: string;
|
|
23
|
+
tools?: string[];
|
|
24
|
+
model?: string;
|
|
25
|
+
/** Named budget preset; wins over frontmatter numbers as a whole tuple, never field by field. */
|
|
26
|
+
effort?: string;
|
|
27
|
+
/** Collapsed `contextMode` + `memory`. */
|
|
28
|
+
context?: string;
|
|
29
|
+
thinkingLevel?: string;
|
|
30
|
+
/** Drives the thinkingLevel default: "verify" defaults on, everything else stays off. */
|
|
31
|
+
purpose?: string;
|
|
32
|
+
mutates?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function validateSubAgentTask(task: string): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve a `subagent` (role-based) invocation (spec 046, D2.1).
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveConfiguredRole(availableModels: Model<Api>[], currentModel: Model<Api>, predefinedAgents: SubAgentConfig[], overrides: ConfiguredRoleOverrides,
|
|
39
|
+
/** `settings.subagentModel` (spec 032 D5): used only when the role file's frontmatter omits `model`. */
|
|
40
|
+
subagentDefaultModelRef?: string): {
|
|
41
|
+
config?: ResolvedSubAgentConfig;
|
|
42
|
+
error?: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Resolve a `subagent_inline` invocation (spec 046, D2.1) — a one-off internal executor with no
|
|
46
|
+
* role file.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveInlineAgent(availableModels: Model<Api>[], currentModel: Model<Api>, overrides: InlineAgentOverrides,
|
|
49
|
+
/** `settings.subagentModel` (spec 032 D5): used only when this call does not name a model. */
|
|
50
|
+
subagentDefaultModelRef?: string): {
|
|
51
|
+
config?: ResolvedInternalSubAgentConfig;
|
|
52
|
+
error?: string;
|
|
53
|
+
warning?: string;
|
|
54
|
+
};
|
|
55
|
+
export declare function formatSubAgentList(agents: SubAgentConfig[], maxItems?: number): string;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { formatModelReference } from "../models/reference.js";
|
|
2
|
+
import { inferMutatesFromTools, parseEnumField, readOptionalTrimmedString, resolveModelReference, validateSubAgentSystemPrompt, validateToolNames, } from "./discovery.js";
|
|
3
|
+
import { getExternalHarness } from "./external/registry.js";
|
|
4
|
+
import { ALLOWED_THINKING_LEVELS } from "./run-record.js";
|
|
5
|
+
import { ALLOWED_MUTATES, DEFAULT_BASH_TIMEOUT_SEC, DEFAULT_MAX_TOOL_CALLS, DEFAULT_MAX_TURNS, DEFAULT_MAX_WALL_TIME_SEC, DEFAULT_SUB_AGENT_TOOLS, DEFAULT_THINKING_LEVEL, } from "./types.js";
|
|
6
|
+
const MAX_SUB_AGENT_TASK_CHARS = 12000;
|
|
7
|
+
/**
|
|
8
|
+
* Execution budgets as a single named tuple. Frontmatter keeps the four numeric knobs
|
|
9
|
+
* (a human editing a config file has grounds to pick numbers); the invocation surface
|
|
10
|
+
* only offers these presets, because a model choosing `maxToolCalls` per delegation is
|
|
11
|
+
* guessing. `standard` is byte-identical to the DEFAULT_* values, so omitting `effort`
|
|
12
|
+
* leaves behavior unchanged.
|
|
13
|
+
*/
|
|
14
|
+
const SUB_AGENT_EFFORT_PRESETS = {
|
|
15
|
+
quick: { maxTurns: 8, maxToolCalls: 16, maxWallTimeSec: 120, bashTimeoutSec: 60 },
|
|
16
|
+
standard: {
|
|
17
|
+
maxTurns: DEFAULT_MAX_TURNS,
|
|
18
|
+
maxToolCalls: DEFAULT_MAX_TOOL_CALLS,
|
|
19
|
+
maxWallTimeSec: DEFAULT_MAX_WALL_TIME_SEC,
|
|
20
|
+
bashTimeoutSec: DEFAULT_BASH_TIMEOUT_SEC,
|
|
21
|
+
},
|
|
22
|
+
deep: { maxTurns: 64, maxToolCalls: 160, maxWallTimeSec: 1800, bashTimeoutSec: 300 },
|
|
23
|
+
};
|
|
24
|
+
const ALLOWED_EFFORTS = Object.keys(SUB_AGENT_EFFORT_PRESETS);
|
|
25
|
+
/**
|
|
26
|
+
* The invocation-side spelling of `contextMode` + `memory`. Those two frontmatter knobs
|
|
27
|
+
* encode only four meaningful states (`isolated` implies `memory: none`), so the calling
|
|
28
|
+
* surface collapses them into one enum.
|
|
29
|
+
*/
|
|
30
|
+
const ALLOWED_CONTEXT_CHOICES = ["none", "index"];
|
|
31
|
+
export function validateSubAgentTask(task) {
|
|
32
|
+
if (task.length <= MAX_SUB_AGENT_TASK_CHARS) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return `Sub-agent task exceeds ${MAX_SUB_AGENT_TASK_CHARS} characters (got ${task.length}).`;
|
|
36
|
+
}
|
|
37
|
+
function parseContextChoice(raw) {
|
|
38
|
+
const normalized = readOptionalTrimmedString(raw);
|
|
39
|
+
if (!normalized) {
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
if (!ALLOWED_CONTEXT_CHOICES.includes(normalized)) {
|
|
43
|
+
return {
|
|
44
|
+
error: `Unknown context "${normalized}". Allowed values: ${ALLOWED_CONTEXT_CHOICES.join(", ")}`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (normalized === "none") {
|
|
48
|
+
return { value: { contextMode: "isolated", memory: "none" } };
|
|
49
|
+
}
|
|
50
|
+
return { value: { contextMode: "contextual", memory: normalized } };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolve a `subagent` (role-based) invocation (spec 046, D2.1).
|
|
54
|
+
*/
|
|
55
|
+
export function resolveConfiguredRole(availableModels, currentModel, predefinedAgents, overrides,
|
|
56
|
+
/** `settings.subagentModel` (spec 032 D5): used only when the role file's frontmatter omits `model`. */
|
|
57
|
+
subagentDefaultModelRef) {
|
|
58
|
+
const baseConfig = predefinedAgents.find((agent) => agent.name === overrides.agent);
|
|
59
|
+
if (!baseConfig) {
|
|
60
|
+
const available = predefinedAgents.length > 0 ? predefinedAgents.map((agent) => agent.name).join(", ") : "none";
|
|
61
|
+
return { error: `Unknown sub-agent "${overrides.agent}". Available sub-agents: ${available}.` };
|
|
62
|
+
}
|
|
63
|
+
if (baseConfig.unavailable) {
|
|
64
|
+
return { error: `Sub-agent "${baseConfig.name}" is currently unavailable: ${baseConfig.unavailable}` };
|
|
65
|
+
}
|
|
66
|
+
if (baseConfig.runtime === "external") {
|
|
67
|
+
const verifyDefault = getExternalHarness(baseConfig.harness)?.supportsImplicitVerifyThinking
|
|
68
|
+
? DEFAULT_THINKING_LEVEL
|
|
69
|
+
: undefined;
|
|
70
|
+
return {
|
|
71
|
+
config: {
|
|
72
|
+
...baseConfig,
|
|
73
|
+
thinkingLevel: baseConfig.thinkingLevel ?? (overrides.purpose === "verify" ? verifyDefault : undefined),
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
let model = baseConfig.model;
|
|
78
|
+
let modelRef = baseConfig.modelRef;
|
|
79
|
+
if (!model && subagentDefaultModelRef) {
|
|
80
|
+
const resolved = resolveModelReference(subagentDefaultModelRef, availableModels);
|
|
81
|
+
if (!resolved.model) {
|
|
82
|
+
return { error: resolved.error };
|
|
83
|
+
}
|
|
84
|
+
model = resolved.model;
|
|
85
|
+
modelRef = formatModelReference(resolved.model);
|
|
86
|
+
}
|
|
87
|
+
const thinkingLevel = baseConfig.thinkingLevel ?? DEFAULT_THINKING_LEVEL;
|
|
88
|
+
const mutates = baseConfig.mutates ?? inferMutatesFromTools(baseConfig.tools);
|
|
89
|
+
return {
|
|
90
|
+
config: {
|
|
91
|
+
...baseConfig,
|
|
92
|
+
model: model ?? currentModel,
|
|
93
|
+
modelRef: modelRef ?? formatModelReference(model ?? currentModel),
|
|
94
|
+
thinkingLevel,
|
|
95
|
+
source: "predefined",
|
|
96
|
+
mutates,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Resolve a `subagent_inline` invocation (spec 046, D2.1) — a one-off internal executor with no
|
|
102
|
+
* role file.
|
|
103
|
+
*/
|
|
104
|
+
export function resolveInlineAgent(availableModels, currentModel, overrides,
|
|
105
|
+
/** `settings.subagentModel` (spec 032 D5): used only when this call does not name a model. */
|
|
106
|
+
subagentDefaultModelRef) {
|
|
107
|
+
const systemPrompt = overrides.systemPrompt.trim();
|
|
108
|
+
if (!systemPrompt) {
|
|
109
|
+
return { error: "Sub-agent system prompt cannot be empty." };
|
|
110
|
+
}
|
|
111
|
+
const promptLengthError = validateSubAgentSystemPrompt(systemPrompt, "Inline sub-agent systemPrompt");
|
|
112
|
+
if (promptLengthError) {
|
|
113
|
+
return { error: promptLengthError };
|
|
114
|
+
}
|
|
115
|
+
const tools = overrides.tools ? validateToolNames(overrides.tools) : { tools: [...DEFAULT_SUB_AGENT_TOOLS] };
|
|
116
|
+
if (tools.error) {
|
|
117
|
+
return { error: tools.error };
|
|
118
|
+
}
|
|
119
|
+
let model;
|
|
120
|
+
let modelRef;
|
|
121
|
+
if (overrides.model?.trim()) {
|
|
122
|
+
const resolved = resolveModelReference(overrides.model.trim(), availableModels);
|
|
123
|
+
if (!resolved.model) {
|
|
124
|
+
return { error: resolved.error };
|
|
125
|
+
}
|
|
126
|
+
model = resolved.model;
|
|
127
|
+
modelRef = formatModelReference(resolved.model);
|
|
128
|
+
}
|
|
129
|
+
else if (subagentDefaultModelRef) {
|
|
130
|
+
const resolved = resolveModelReference(subagentDefaultModelRef, availableModels);
|
|
131
|
+
if (!resolved.model) {
|
|
132
|
+
return { error: resolved.error };
|
|
133
|
+
}
|
|
134
|
+
model = resolved.model;
|
|
135
|
+
modelRef = formatModelReference(resolved.model);
|
|
136
|
+
}
|
|
137
|
+
const effortOverride = parseEnumField(overrides.effort, "effort", ALLOWED_EFFORTS);
|
|
138
|
+
if (effortOverride.error) {
|
|
139
|
+
return { error: effortOverride.error };
|
|
140
|
+
}
|
|
141
|
+
const budget = effortOverride.value
|
|
142
|
+
? SUB_AGENT_EFFORT_PRESETS[effortOverride.value]
|
|
143
|
+
: {
|
|
144
|
+
maxTurns: DEFAULT_MAX_TURNS,
|
|
145
|
+
maxToolCalls: DEFAULT_MAX_TOOL_CALLS,
|
|
146
|
+
maxWallTimeSec: DEFAULT_MAX_WALL_TIME_SEC,
|
|
147
|
+
bashTimeoutSec: DEFAULT_BASH_TIMEOUT_SEC,
|
|
148
|
+
};
|
|
149
|
+
const contextOverride = parseContextChoice(overrides.context);
|
|
150
|
+
if (contextOverride.error) {
|
|
151
|
+
return { error: contextOverride.error };
|
|
152
|
+
}
|
|
153
|
+
const contextMode = contextOverride.value?.contextMode ?? "isolated";
|
|
154
|
+
const memory = contextOverride.value?.memory ?? (contextMode === "contextual" ? "index" : "none");
|
|
155
|
+
const thinkingLevelOverride = overrides.thinkingLevel
|
|
156
|
+
? parseEnumField(overrides.thinkingLevel, "thinkingLevel", ALLOWED_THINKING_LEVELS)
|
|
157
|
+
: undefined;
|
|
158
|
+
if (thinkingLevelOverride?.error) {
|
|
159
|
+
return { error: thinkingLevelOverride.error };
|
|
160
|
+
}
|
|
161
|
+
const thinkingLevel = thinkingLevelOverride?.value ?? DEFAULT_THINKING_LEVEL;
|
|
162
|
+
const mutatesOverride = parseEnumField(overrides.mutates, "mutates", ALLOWED_MUTATES);
|
|
163
|
+
if (mutatesOverride.error) {
|
|
164
|
+
return { error: mutatesOverride.error };
|
|
165
|
+
}
|
|
166
|
+
const mutates = mutatesOverride.value ?? inferMutatesFromTools(tools.tools);
|
|
167
|
+
const bashWithoutMutatesWarning = tools.tools.includes("bash") && mutatesOverride.value === undefined
|
|
168
|
+
? 'tools include bash but "mutates" is not declared; if this task writes to the workspace, pass mutates: "write" so it takes the exclusive workspace write lease'
|
|
169
|
+
: undefined;
|
|
170
|
+
return {
|
|
171
|
+
warning: bashWithoutMutatesWarning,
|
|
172
|
+
config: {
|
|
173
|
+
name: "dynamic-subagent",
|
|
174
|
+
description: "Inline sub-agent",
|
|
175
|
+
systemPrompt,
|
|
176
|
+
tools: tools.tools,
|
|
177
|
+
model: model ?? currentModel,
|
|
178
|
+
modelRef: modelRef ?? formatModelReference(model ?? currentModel),
|
|
179
|
+
maxTurns: budget.maxTurns,
|
|
180
|
+
maxToolCalls: budget.maxToolCalls,
|
|
181
|
+
maxWallTimeSec: budget.maxWallTimeSec,
|
|
182
|
+
bashTimeoutSec: budget.bashTimeoutSec,
|
|
183
|
+
contextMode,
|
|
184
|
+
memory,
|
|
185
|
+
paths: [],
|
|
186
|
+
thinkingLevel,
|
|
187
|
+
source: "inline",
|
|
188
|
+
runtime: "internal",
|
|
189
|
+
mutates,
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
export function formatSubAgentList(agents, maxItems = 12) {
|
|
194
|
+
if (agents.length === 0) {
|
|
195
|
+
return "none";
|
|
196
|
+
}
|
|
197
|
+
const listed = agents.slice(0, maxItems).map((agent) => `- \`${agent.name}\`: ${agent.description}`);
|
|
198
|
+
if (agents.length <= maxItems) {
|
|
199
|
+
return listed.join("\n");
|
|
200
|
+
}
|
|
201
|
+
return `${listed.join("\n")}\n- ... and ${agents.length - maxItems} more`;
|
|
202
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { UsageTotals } from "../usage/totals.js";
|
|
2
|
-
import type { ResolvedSubAgentConfig, SubAgentConfig } from "./
|
|
3
|
-
import type { SubAgentRunContext, SubAgentToolFields } from "./types.js";
|
|
2
|
+
import type { ResolvedSubAgentConfig, SubAgentConfig, SubAgentRunContext, SubAgentToolFields } from "./types.js";
|
|
4
3
|
/**
|
|
5
4
|
* Reply budget for what a sub-agent hands back to its parent (spec 032 D4), measured in the
|
|
6
5
|
* same prompt-unit currency as the system prompt budget (shared/prompt-units.ts). The full
|
package/dist/subagents/result.js
CHANGED
|
@@ -63,10 +63,14 @@ export function buildStoppedText(config, reason, finalText) {
|
|
|
63
63
|
*/
|
|
64
64
|
export function finalizeSubAgentOutput(runContext, finalText) {
|
|
65
65
|
const outputPath = join(runContext.artifactDir, "output.md");
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
const worktreeHeader = runContext.managedWorktree
|
|
67
|
+
? `[Managed git worktree: ${runContext.workingDirectory}]\n\n`
|
|
68
|
+
: "";
|
|
69
|
+
const decorated = `${worktreeHeader}${finalText}`;
|
|
70
|
+
if (countPromptUnits(decorated) <= MAX_SUBAGENT_RESULT_UNITS && decorated.length <= MAX_SUBAGENT_RESULT_CHARS) {
|
|
71
|
+
return { replyText: decorated, truncated: false };
|
|
68
72
|
}
|
|
69
|
-
const clipped = clipTextByPromptUnits(
|
|
73
|
+
const clipped = clipTextByPromptUnits(decorated, MAX_SUBAGENT_RESULT_UNITS, {
|
|
70
74
|
headRatio: RESULT_TRUNCATION_HEAD_RATIO,
|
|
71
75
|
maxChars: MAX_SUBAGENT_RESULT_CHARS,
|
|
72
76
|
marker: `\n\n[... truncated; full output saved at ${outputPath} ...]\n\n`,
|
|
@@ -2,7 +2,10 @@ import type { UsageTotals } from "../usage/totals.js";
|
|
|
2
2
|
import type { WorkspaceBaseline } from "./workspace-summary.js";
|
|
3
3
|
export type RunStatus = "running" | "completed" | "failed" | "cancelled" | "lost";
|
|
4
4
|
export type RunRuntime = "internal" | "external";
|
|
5
|
-
export
|
|
5
|
+
export declare const ALLOWED_THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
6
|
+
export type SubAgentThinkingLevel = (typeof ALLOWED_THINKING_LEVELS)[number];
|
|
7
|
+
export declare const EXTERNAL_HARNESS_IDS: readonly ["claude-code", "codex-cli", "cursor-cli", "antigravity-cli", "exec"];
|
|
8
|
+
export type RunHarness = (typeof EXTERNAL_HARNESS_IDS)[number];
|
|
6
9
|
export type RunMutates = "read" | "write";
|
|
7
10
|
export type RunResolution = {
|
|
8
11
|
kind: "found";
|
|
@@ -35,7 +38,7 @@ export interface RunUsage {
|
|
|
35
38
|
usage: UsageTotals;
|
|
36
39
|
/** False for harnesses that cannot report tokens at all (`cursor-cli`, `exec`). */
|
|
37
40
|
usageKnown: boolean;
|
|
38
|
-
/** False for harnesses that omit a cost field (`cursor-cli`, `codex-cli`, `exec`). */
|
|
41
|
+
/** False for harnesses that omit a cost field (`cursor-cli`, `codex-cli`, `antigravity-cli`, `exec`). */
|
|
39
42
|
costKnown: boolean;
|
|
40
43
|
}
|
|
41
44
|
export interface RunRecord extends RunUsage {
|
|
@@ -97,6 +100,9 @@ export interface RunRecord extends RunUsage {
|
|
|
97
100
|
terminationReason?: "timeout" | "cancelled";
|
|
98
101
|
argv?: string[];
|
|
99
102
|
sessionId?: string;
|
|
103
|
+
/** Spec 068 D8: expected conversation id on an `antigravity-cli` follow-up, persisted at launch
|
|
104
|
+
* so both normal settlement and post-restart reconciliation verify the resumed session identity. */
|
|
105
|
+
expectedResumeSessionId?: string;
|
|
100
106
|
leaseKey?: string;
|
|
101
107
|
mutates?: RunMutates;
|
|
102
108
|
/** Spec 042 D1: the role's wall-time budget, persisted so restart reconciliation can report an
|
|
@@ -126,6 +132,31 @@ export interface RunRecord extends RunUsage {
|
|
|
126
132
|
* `undefined` if the probe failed or timed out) — the other half of the same diagnosis. */
|
|
127
133
|
cliVersion?: string;
|
|
128
134
|
}
|
|
135
|
+
export interface ExternalLaunchInfo {
|
|
136
|
+
pid: number;
|
|
137
|
+
pidStartedAt?: string;
|
|
138
|
+
argv: string[];
|
|
139
|
+
deadlineAt: number;
|
|
140
|
+
sessionId?: string;
|
|
141
|
+
/** Spec 068 D8: expected resumed session id for `antigravity-cli` follow-up verification. */
|
|
142
|
+
expectedResumeSessionId?: string;
|
|
143
|
+
/** Spec 042 D1: everything a restart reconciliation might need if this daemon disappears
|
|
144
|
+
* before the process exits — restore/deadline recovery must have the same inputs a live watcher
|
|
145
|
+
* would, not a thinner subset. */
|
|
146
|
+
maxWallTimeSec?: number;
|
|
147
|
+
processStartedAt?: number;
|
|
148
|
+
deskDir?: string;
|
|
149
|
+
/** Spec 042 D10: non-fatal invocation warnings from argv assembly (e.g. a dropped
|
|
150
|
+
* placeholder token), so they survive on the run rather than only ever hitting a log line. */
|
|
151
|
+
invocationWarnings?: string[];
|
|
152
|
+
/** Spec 042 D7: the role's `command`/`externalModelRef`/`shell` fingerprint at launch. */
|
|
153
|
+
roleFingerprint?: string;
|
|
154
|
+
/** Spec 042 D12: the harness adapter's schema version and a best-effort `--version` probe
|
|
155
|
+
* of the target CLI, so a later failure can be diagnosed as "adapter is stale" vs. "the
|
|
156
|
+
* agent itself failed" instead of looking identical. */
|
|
157
|
+
parserVersion?: number;
|
|
158
|
+
cliVersion?: string;
|
|
159
|
+
}
|
|
129
160
|
export interface RegisterRunInput {
|
|
130
161
|
runId: string;
|
|
131
162
|
channelId: string;
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* so the run manager and the external-run helpers can share it without an import cycle (spec 054 D9/D12).
|
|
5
5
|
*/
|
|
6
6
|
import { isRecord } from "../shared/type-guards.js";
|
|
7
|
+
export const ALLOWED_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
8
|
+
export const EXTERNAL_HARNESS_IDS = ["claude-code", "codex-cli", "cursor-cli", "antigravity-cli", "exec"];
|
|
7
9
|
/** D10.2: per-desk cap on concurrently running delegation runs (one run manager per desk, spec 058). */
|
|
8
10
|
export const MAX_RUNNING_SUBAGENT_RUNS_PER_DESK = 6;
|
|
9
11
|
/** D10.2: host-wide cap across every desk. Bounds unbounded process/worker growth only —
|