@oyasmi/pipiclaw 0.9.0-beta.5 → 0.9.0-beta.7
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.md +146 -177
- package/dist/agent/channel-runner.d.ts +8 -0
- package/dist/agent/channel-runner.js +154 -132
- package/dist/agent/commands.d.ts +6 -0
- package/dist/agent/job-manager.js +6 -10
- package/dist/agent/progress-formatter.js +3 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/main.js +2 -1
- package/dist/memory/extraction.js +0 -1
- package/dist/memory/maintenance-gates.d.ts +1 -1
- package/dist/memory/maintenance-jobs.js +2 -3
- package/dist/memory/metadata.d.ts +0 -15
- package/dist/memory/metadata.js +0 -7
- package/dist/memory/probation.d.ts +1 -5
- package/dist/memory/probation.js +2 -6
- package/dist/models/auth-cli.d.ts +1 -1
- package/dist/models/auth-cli.js +3 -2
- package/dist/paths.d.ts +0 -6
- package/dist/paths.js +0 -6
- package/dist/playbooks/agent-delegation.md +9 -8
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.d.ts +2 -2
- package/dist/playbooks/catalog.js +20 -9
- package/dist/playbooks/event-scheduling.md +1 -1
- package/dist/playbooks/memory-and-learning.md +1 -1
- package/dist/playbooks/outbound-media.md +5 -5
- package/dist/playbooks/runtime-orientation.md +1 -1
- package/dist/playbooks/task-driving.md +1 -1
- package/dist/playbooks/task-planning.md +1 -1
- package/dist/runtime/app-home.d.ts +32 -0
- package/dist/runtime/app-home.js +319 -0
- package/dist/runtime/bootstrap.d.ts +3 -69
- package/dist/runtime/bootstrap.js +113 -511
- package/dist/runtime/delivery.js +1 -1
- package/dist/runtime/dingtalk.d.ts +7 -6
- package/dist/runtime/dingtalk.js +5 -13
- package/dist/runtime/task-wake.d.ts +54 -0
- package/dist/runtime/task-wake.js +99 -0
- package/dist/shared/host-process.d.ts +5 -5
- package/dist/shared/host-process.js +19 -0
- package/dist/shared/wake-claim.d.ts +23 -0
- package/dist/shared/wake-claim.js +26 -0
- package/dist/subagents/discovery.d.ts +9 -1
- package/dist/subagents/discovery.js +37 -9
- package/dist/subagents/external/claude-code.js +4 -5
- package/dist/subagents/external/codex-cli.js +1 -7
- package/dist/subagents/external/exec.js +7 -2
- package/dist/subagents/external/harness.d.ts +0 -3
- package/dist/subagents/external/harness.js +18 -3
- package/dist/subagents/external/run.d.ts +5 -0
- package/dist/subagents/external/run.js +70 -31
- package/dist/subagents/runs.d.ts +40 -9
- package/dist/subagents/runs.js +194 -31
- package/dist/subagents/tool.d.ts +3 -1
- package/dist/subagents/tool.js +33 -14
- package/dist/tools/memory-manage.js +0 -1
- package/dist/tools/subagent-manage.js +18 -1
- package/dist/tui/app.d.ts +1 -1
- package/dist/tui/app.js +3 -2
- package/dist/tui/cli.d.ts +1 -1
- package/dist/tui/cli.js +1 -1
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/examples/sub-agents/README.md +25 -16
- package/examples/sub-agents/builder-hard.md +9 -8
- package/examples/sub-agents/builder.md +12 -11
- package/examples/sub-agents/documenter.md +11 -14
- package/examples/sub-agents/explorer.md +16 -13
- package/examples/sub-agents/git-committer.md +18 -16
- package/examples/sub-agents/log-sifter.md +19 -16
- package/examples/sub-agents/planner.md +17 -17
- package/examples/sub-agents/reviewer.md +13 -23
- package/examples/sub-agents/scout.md +5 -6
- package/examples/sub-agents/verifier.md +8 -14
- package/examples/sub-agents/worker.md +7 -8
- package/package.json +1 -1
package/dist/runtime/delivery.js
CHANGED
|
@@ -128,7 +128,7 @@ class ChannelDeliveryController {
|
|
|
128
128
|
if (this.progressStartedAt === 0) {
|
|
129
129
|
this.progressStartedAt = Date.now();
|
|
130
130
|
}
|
|
131
|
-
if (text.startsWith("
|
|
131
|
+
if (text.startsWith("➜ ")) {
|
|
132
132
|
this.toolCallCount++;
|
|
133
133
|
}
|
|
134
134
|
if (this.progressSegments.length > 0) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RuntimeCommandName } from "../agent/commands.js";
|
|
1
2
|
import type { FinalDelivery, MediaSender, MediaSendResult, OutboundMedia, ProgressStyle } from "./channel-context.js";
|
|
2
3
|
import type { ChannelObservation } from "./channel-index.js";
|
|
3
4
|
export type BusyMessageMode = "steer" | "followUp";
|
|
@@ -81,12 +82,12 @@ export interface DingTalkHandler {
|
|
|
81
82
|
reserveEvent?(event: DingTalkEvent): void;
|
|
82
83
|
handleEvent(event: DingTalkEvent, bot: DingTalkBot, isEvent?: boolean): Promise<void>;
|
|
83
84
|
handleStop(channelId: string, bot: DingTalkBot): Promise<StopOutcome>;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Render one of the stateless report commands (events/tasks/status/usage/context/subagents) to
|
|
87
|
+
* text. Single dispatch point shared by the busy-turn switch below and bootstrap's idle-turn
|
|
88
|
+
* switch — both used to hand-copy the same six-case table.
|
|
89
|
+
*/
|
|
90
|
+
runRuntimeCommand(event: DingTalkEvent, name: RuntimeCommandName, args: string): Promise<string>;
|
|
90
91
|
handleBusyMessage(event: DingTalkEvent, bot: DingTalkBot, mode: BusyMessageMode, queueText: string): Promise<BusyMessageResult>;
|
|
91
92
|
}
|
|
92
93
|
export declare class DingTalkBot implements MediaSender {
|
package/dist/runtime/dingtalk.js
CHANGED
|
@@ -11,7 +11,7 @@ import axios from "axios";
|
|
|
11
11
|
import { DWClient, TOPIC_ROBOT } from "dingtalk-stream";
|
|
12
12
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
13
13
|
import { dirname, join } from "path";
|
|
14
|
-
import { formatBusyCommandList, parseBuiltInCommand, renderBuiltInHelp } from "../agent/commands.js";
|
|
14
|
+
import { formatBusyCommandList, parseBuiltInCommand, renderBuiltInHelp, } from "../agent/commands.js";
|
|
15
15
|
import * as log from "../log.js";
|
|
16
16
|
import { errorMessage } from "../shared/text-utils.js";
|
|
17
17
|
import { isRecord } from "../shared/type-guards.js";
|
|
@@ -1094,23 +1094,15 @@ export class DingTalkBot {
|
|
|
1094
1094
|
return;
|
|
1095
1095
|
}
|
|
1096
1096
|
case "events":
|
|
1097
|
-
await this.handler.handleEventsCommand(event, this, builtInCommand.args);
|
|
1098
|
-
return;
|
|
1099
1097
|
case "tasks":
|
|
1100
|
-
await this.handler.handleTasksCommand(event, this, builtInCommand.args);
|
|
1101
|
-
return;
|
|
1102
1098
|
case "status":
|
|
1103
|
-
await this.handler.handleStatusCommand(event, this);
|
|
1104
|
-
return;
|
|
1105
1099
|
case "usage":
|
|
1106
|
-
await this.handler.handleUsageCommand(event, this, builtInCommand.args);
|
|
1107
|
-
return;
|
|
1108
1100
|
case "context":
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
await this.handler.handleSubagentsCommand(event, this, builtInCommand.args);
|
|
1101
|
+
case "subagents": {
|
|
1102
|
+
const response = await this.handler.runRuntimeCommand(event, builtInCommand.name, builtInCommand.args);
|
|
1103
|
+
await this.sendPlain(channelId, response);
|
|
1113
1104
|
return;
|
|
1105
|
+
}
|
|
1114
1106
|
}
|
|
1115
1107
|
}
|
|
1116
1108
|
// Session commands (/model, /new, …) and unknown slash commands cannot
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifying and claiming a background job's or delegation run's completion wake before it may
|
|
3
|
+
* activate a task parked with `waitingFor` (spec 040, D7/T9). Split out of `bootstrap.ts`: these
|
|
4
|
+
* are pure functions over an explicit `event`/`workspaceDir`/`executor`, with no dependency on
|
|
5
|
+
* `createRuntimeContext`'s closures.
|
|
6
|
+
*/
|
|
7
|
+
import { type JobSnapshot } from "../agent/job-manager.js";
|
|
8
|
+
import type { Executor } from "../executor.js";
|
|
9
|
+
import { type RunRecord } from "../subagents/runs.js";
|
|
10
|
+
import { type WakeTaskTransitionHooks } from "../tasks/store.js";
|
|
11
|
+
import type { DingTalkEvent } from "./dingtalk.js";
|
|
12
|
+
/**
|
|
13
|
+
* Whether a `[JOB:<jobId>] ... belongs to task <taskId>.` wake actually names a job that: exists
|
|
14
|
+
* on this channel, has actually finished (a still-`running` job cannot have produced this wake —
|
|
15
|
+
* accepting it anyway would let a message merely mentioning a live job's id activate a task
|
|
16
|
+
* early), and really is the one whose own contract names `taskId` (spec 040, T9). The text itself
|
|
17
|
+
* is never sufficient — it can be typed by any user, or echoed back by an external agent's own
|
|
18
|
+
* untrusted stdout.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isVerifiedJobWake(jobs: JobSnapshot[], jobId: string, taskId: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Same check as `isVerifiedJobWake`, for a `[SUBAGENT:<runId>] ... belongs to task <taskId>.`
|
|
23
|
+
* delegation wake. `settledAt` (rather than `status !== "running"`) is the terminal marker here
|
|
24
|
+
* because it is the one field `SubAgentRunManager.settle()` sets unconditionally and first, before
|
|
25
|
+
* usage/archive/wake side effects — the same idempotency guard the manager itself relies on.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isVerifiedDelegationWake(record: RunRecord | undefined, taskId: string): boolean;
|
|
28
|
+
/** Plain wake text is untrusted. Only an event carrying the producer-created structured envelope
|
|
29
|
+
* and its exact durable dispatch id may enter task activation; normal DingTalk inbound events do
|
|
30
|
+
* not populate `internalWake`, so copying a real wake's text is insufficient. */
|
|
31
|
+
export declare function isTrustedInternalWake(event: DingTalkEvent, kind: "job" | "subagent", resourceId: string, taskId: string): event is DingTalkEvent & {
|
|
32
|
+
dispatchId: string;
|
|
33
|
+
};
|
|
34
|
+
export interface ClaimedDelegationWake {
|
|
35
|
+
taskId: string;
|
|
36
|
+
generation?: number;
|
|
37
|
+
activated: boolean;
|
|
38
|
+
finish(): Promise<void>;
|
|
39
|
+
rollback(): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
/** Claim and activate a producer-created delegation wake without consuming it yet. Keeping the
|
|
42
|
+
* final marker separate lets transports such as TUI mark it consumed only after they have accepted
|
|
43
|
+
* the corresponding turn; a rejected submit remains replayable in the same or next process. */
|
|
44
|
+
export declare function claimVerifiedDelegationWake(event: DingTalkEvent, workspaceDir: string, hooks?: WakeTaskTransitionHooks): Promise<ClaimedDelegationWake | undefined>;
|
|
45
|
+
export interface ClaimedJobWake {
|
|
46
|
+
taskId: string;
|
|
47
|
+
generation?: number;
|
|
48
|
+
activated: boolean;
|
|
49
|
+
finish(): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
/** Same shape as `claimVerifiedDelegationWake`, for a `[JOB:<jobId>] ... belongs to task
|
|
52
|
+
* <taskId>.` completion wake. A background job has no handoff/rollback bookkeeping — its wake
|
|
53
|
+
* activation is a single unconditional step — so `ClaimedJobWake` omits `rollback`. */
|
|
54
|
+
export declare function claimVerifiedJobWake(event: DingTalkEvent, workspaceDir: string, executor: Executor, hooks?: WakeTaskTransitionHooks): Promise<ClaimedJobWake | undefined>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifying and claiming a background job's or delegation run's completion wake before it may
|
|
3
|
+
* activate a task parked with `waitingFor` (spec 040, D7/T9). Split out of `bootstrap.ts`: these
|
|
4
|
+
* are pure functions over an explicit `event`/`workspaceDir`/`executor`, with no dependency on
|
|
5
|
+
* `createRuntimeContext`'s closures.
|
|
6
|
+
*/
|
|
7
|
+
import { getChannelJobManager } from "../agent/job-manager.js";
|
|
8
|
+
import { getSubAgentRunManager } from "../subagents/runs.js";
|
|
9
|
+
import { activateWaitingTaskAndClaimAttempt, finishWakeTaskActivation, rollbackWakeTaskActivation, } from "../tasks/store.js";
|
|
10
|
+
import { getChannelDir } from "./channel-paths.js";
|
|
11
|
+
/**
|
|
12
|
+
* Whether a `[JOB:<jobId>] ... belongs to task <taskId>.` wake actually names a job that: exists
|
|
13
|
+
* on this channel, has actually finished (a still-`running` job cannot have produced this wake —
|
|
14
|
+
* accepting it anyway would let a message merely mentioning a live job's id activate a task
|
|
15
|
+
* early), and really is the one whose own contract names `taskId` (spec 040, T9). The text itself
|
|
16
|
+
* is never sufficient — it can be typed by any user, or echoed back by an external agent's own
|
|
17
|
+
* untrusted stdout.
|
|
18
|
+
*/
|
|
19
|
+
export function isVerifiedJobWake(jobs, jobId, taskId) {
|
|
20
|
+
const job = jobs.find((candidate) => candidate.id === jobId);
|
|
21
|
+
return job !== undefined && job.status !== "running" && job.taskId === taskId;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Same check as `isVerifiedJobWake`, for a `[SUBAGENT:<runId>] ... belongs to task <taskId>.`
|
|
25
|
+
* delegation wake. `settledAt` (rather than `status !== "running"`) is the terminal marker here
|
|
26
|
+
* because it is the one field `SubAgentRunManager.settle()` sets unconditionally and first, before
|
|
27
|
+
* usage/archive/wake side effects — the same idempotency guard the manager itself relies on.
|
|
28
|
+
*/
|
|
29
|
+
export function isVerifiedDelegationWake(record, taskId) {
|
|
30
|
+
return record !== undefined && record.settledAt !== undefined && record.taskId === taskId;
|
|
31
|
+
}
|
|
32
|
+
/** Plain wake text is untrusted. Only an event carrying the producer-created structured envelope
|
|
33
|
+
* and its exact durable dispatch id may enter task activation; normal DingTalk inbound events do
|
|
34
|
+
* not populate `internalWake`, so copying a real wake's text is insufficient. */
|
|
35
|
+
export function isTrustedInternalWake(event, kind, resourceId, taskId) {
|
|
36
|
+
const wake = event.internalWake;
|
|
37
|
+
return (wake?.kind === kind &&
|
|
38
|
+
wake.resourceId === resourceId &&
|
|
39
|
+
wake.taskId === taskId &&
|
|
40
|
+
typeof event.dispatchId === "string" &&
|
|
41
|
+
wake.dispatchId === event.dispatchId);
|
|
42
|
+
}
|
|
43
|
+
/** Claim and activate a producer-created delegation wake without consuming it yet. Keeping the
|
|
44
|
+
* final marker separate lets transports such as TUI mark it consumed only after they have accepted
|
|
45
|
+
* the corresponding turn; a rejected submit remains replayable in the same or next process. */
|
|
46
|
+
export async function claimVerifiedDelegationWake(event, workspaceDir, hooks) {
|
|
47
|
+
const wake = event.internalWake;
|
|
48
|
+
if (wake?.kind !== "subagent")
|
|
49
|
+
return undefined;
|
|
50
|
+
const runManager = getSubAgentRunManager(event.channelId);
|
|
51
|
+
const record = runManager.get(wake.resourceId);
|
|
52
|
+
if (!isTrustedInternalWake(event, "subagent", wake.resourceId, wake.taskId) ||
|
|
53
|
+
!isVerifiedDelegationWake(record, wake.taskId) ||
|
|
54
|
+
!(await runManager.beginWakeConsumption(wake.resourceId, wake.taskId, event.dispatchId))) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const channelDir = getChannelDir(workspaceDir, event.channelId);
|
|
58
|
+
const handoff = {
|
|
59
|
+
kind: "subagent",
|
|
60
|
+
resourceId: wake.resourceId,
|
|
61
|
+
dispatchId: event.dispatchId,
|
|
62
|
+
};
|
|
63
|
+
const activated = await activateWaitingTaskAndClaimAttempt(channelDir, wake.taskId, "external-signal", new Date(), hooks, handoff);
|
|
64
|
+
return {
|
|
65
|
+
taskId: wake.taskId,
|
|
66
|
+
generation: activated?.generation,
|
|
67
|
+
activated: activated !== undefined,
|
|
68
|
+
finish: async () => {
|
|
69
|
+
await runManager.finishWakeConsumption(wake.resourceId, event.dispatchId);
|
|
70
|
+
await finishWakeTaskActivation(channelDir, wake.taskId, handoff);
|
|
71
|
+
},
|
|
72
|
+
rollback: () => rollbackWakeTaskActivation(channelDir, wake.taskId, handoff),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** Same shape as `claimVerifiedDelegationWake`, for a `[JOB:<jobId>] ... belongs to task
|
|
76
|
+
* <taskId>.` completion wake. A background job has no handoff/rollback bookkeeping — its wake
|
|
77
|
+
* activation is a single unconditional step — so `ClaimedJobWake` omits `rollback`. */
|
|
78
|
+
export async function claimVerifiedJobWake(event, workspaceDir, executor, hooks) {
|
|
79
|
+
const wake = event.internalWake;
|
|
80
|
+
if (wake?.kind !== "job")
|
|
81
|
+
return undefined;
|
|
82
|
+
const jobManager = getChannelJobManager(event.channelId, executor);
|
|
83
|
+
const jobs = await jobManager.list();
|
|
84
|
+
if (!isTrustedInternalWake(event, "job", wake.resourceId, wake.taskId) ||
|
|
85
|
+
!isVerifiedJobWake(jobs, wake.resourceId, wake.taskId) ||
|
|
86
|
+
!(await jobManager.beginWakeConsumption(wake.resourceId, wake.taskId, event.dispatchId))) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
const channelDir = getChannelDir(workspaceDir, event.channelId);
|
|
90
|
+
const activated = await activateWaitingTaskAndClaimAttempt(channelDir, wake.taskId, "job", new Date(), hooks);
|
|
91
|
+
return {
|
|
92
|
+
taskId: wake.taskId,
|
|
93
|
+
generation: activated?.generation,
|
|
94
|
+
activated: activated !== undefined,
|
|
95
|
+
finish: async () => {
|
|
96
|
+
await jobManager.finishWakeConsumption(wake.resourceId, event.dispatchId);
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* children); this is for callers that spawn argv-direct, detached children of their own (D3/D4).
|
|
2
|
+
* A live pid's start time, as `ps` reports it — the only OS-verifiable way to tell a still-running
|
|
3
|
+
* process apart from an unrelated one that later reused the same pid (spec 040, D10.3). `undefined`
|
|
4
|
+
* when the pid is gone or `ps` itself is unavailable; callers must treat that as "cannot verify",
|
|
5
|
+
* never as proof either way.
|
|
7
6
|
*/
|
|
7
|
+
export declare function readProcessStartTime(pid: number): Promise<string | undefined>;
|
|
8
8
|
/** True if `pid` names a live process this user can at least see, without sending a real signal. */
|
|
9
9
|
export declare function isProcessAlive(pid: number): boolean;
|
|
10
10
|
/**
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
1
3
|
/**
|
|
2
4
|
* Stateless host-process operations shared by background jobs and external delegation runs
|
|
3
5
|
* (spec 040, D1): a liveness probe and a process-group kill. Nothing here is job- or run-specific
|
|
@@ -5,6 +7,23 @@
|
|
|
5
7
|
* machine. `job-manager.ts` still probes through its shell `Executor` (its jobs are shell
|
|
6
8
|
* children); this is for callers that spawn argv-direct, detached children of their own (D3/D4).
|
|
7
9
|
*/
|
|
10
|
+
const execFileAsync = promisify(execFile);
|
|
11
|
+
/**
|
|
12
|
+
* A live pid's start time, as `ps` reports it — the only OS-verifiable way to tell a still-running
|
|
13
|
+
* process apart from an unrelated one that later reused the same pid (spec 040, D10.3). `undefined`
|
|
14
|
+
* when the pid is gone or `ps` itself is unavailable; callers must treat that as "cannot verify",
|
|
15
|
+
* never as proof either way.
|
|
16
|
+
*/
|
|
17
|
+
export async function readProcessStartTime(pid) {
|
|
18
|
+
try {
|
|
19
|
+
const { stdout } = await execFileAsync("ps", ["-p", String(pid), "-o", "lstart="]);
|
|
20
|
+
const value = stdout.trim();
|
|
21
|
+
return value || undefined;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
8
27
|
/** True if `pid` names a live process this user can at least see, without sending a real signal. */
|
|
9
28
|
export function isProcessAlive(pid) {
|
|
10
29
|
try {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two-phase "claim, then finish" decision shared by `job-manager.ts` and `subagents/runs.ts`
|
|
3
|
+
* for reserving a completion wake exactly once (spec 040, D7/T9). Both managers persist a
|
|
4
|
+
* `RunRecord`/`JobRecord` differently and gate eligibility on a different terminal condition
|
|
5
|
+
* (job: `status !== "running"`; run: `settledAt` set), so only the claim/consume decision on the
|
|
6
|
+
* two shared fields is factored out here — not the queue, the persistence, or the eligibility check.
|
|
7
|
+
*/
|
|
8
|
+
export interface WakeClaimFields {
|
|
9
|
+
wakeClaimDispatchId?: string;
|
|
10
|
+
wakeConsumedAt?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Reserve `dispatchId` as the claim on `fields`, if `eligible` (the caller's terminal/taskId/
|
|
14
|
+
* dispatch-id-match check) holds and no conflicting claim or consumption already exists. Mutates
|
|
15
|
+
* `fields` in place and returns whether the claim was taken; the caller persists the result and
|
|
16
|
+
* rolls the mutation back on a failed write.
|
|
17
|
+
*/
|
|
18
|
+
export declare function beginWakeClaim(fields: WakeClaimFields, eligible: boolean, dispatchId: string): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Mark a previously claimed wake consumed, if `dispatchId` matches the outstanding claim and it
|
|
21
|
+
* has not already been consumed. Mutates `fields` in place and returns whether it changed.
|
|
22
|
+
*/
|
|
23
|
+
export declare function finishWakeClaim(fields: WakeClaimFields, dispatchId: string): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reserve `dispatchId` as the claim on `fields`, if `eligible` (the caller's terminal/taskId/
|
|
3
|
+
* dispatch-id-match check) holds and no conflicting claim or consumption already exists. Mutates
|
|
4
|
+
* `fields` in place and returns whether the claim was taken; the caller persists the result and
|
|
5
|
+
* rolls the mutation back on a failed write.
|
|
6
|
+
*/
|
|
7
|
+
export function beginWakeClaim(fields, eligible, dispatchId) {
|
|
8
|
+
if (!eligible ||
|
|
9
|
+
fields.wakeConsumedAt !== undefined ||
|
|
10
|
+
(fields.wakeClaimDispatchId !== undefined && fields.wakeClaimDispatchId !== dispatchId)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
fields.wakeClaimDispatchId = dispatchId;
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Mark a previously claimed wake consumed, if `dispatchId` matches the outstanding claim and it
|
|
18
|
+
* has not already been consumed. Mutates `fields` in place and returns whether it changed.
|
|
19
|
+
*/
|
|
20
|
+
export function finishWakeClaim(fields, dispatchId) {
|
|
21
|
+
if (fields.wakeClaimDispatchId !== dispatchId || fields.wakeConsumedAt !== undefined) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
fields.wakeConsumedAt = Date.now();
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
@@ -43,6 +43,14 @@ export declare const SUB_AGENT_EFFORT_PRESETS: {
|
|
|
43
43
|
readonly bashTimeoutSec: 180;
|
|
44
44
|
};
|
|
45
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* External runs have no turn/tool-call budget (D5) — `effort` only ever moves wall time, and at
|
|
48
|
+
* external scale, not the internal tuple above (P1-3: those numbers previously leaked onto
|
|
49
|
+
* external roles unchanged, where `deep` at 900s was *shorter* than the external default).
|
|
50
|
+
* `standard` and an unset `effort` both keep the role's own `maxWallTimeSec` (or the external
|
|
51
|
+
* default), so this only has entries for the two presets that actually override it.
|
|
52
|
+
*/
|
|
53
|
+
export declare const SUB_AGENT_EXTERNAL_EFFORT_WALL_TIME_SEC: Partial<Record<keyof typeof SUB_AGENT_EFFORT_PRESETS, number>>;
|
|
46
54
|
export type SubAgentEffort = keyof typeof SUB_AGENT_EFFORT_PRESETS;
|
|
47
55
|
/**
|
|
48
56
|
* The invocation-side spelling of `contextMode` + `memory`. Those two frontmatter knobs
|
|
@@ -77,7 +85,7 @@ export interface SubAgentConfig {
|
|
|
77
85
|
/** External only: the raw, unvalidated command line. Tokenized by the harness at invocation
|
|
78
86
|
* time (D4), never by discovery — discovery only checks that it is non-empty. */
|
|
79
87
|
command?: string;
|
|
80
|
-
/**
|
|
88
|
+
/** exec harness only: run `command` through `/bin/sh -lc` instead of argv-direct spawn (D4). */
|
|
81
89
|
shell?: boolean;
|
|
82
90
|
/** External only: env vars appended to (and overriding) the inherited environment (D8.2). */
|
|
83
91
|
env?: Record<string, string>;
|
|
@@ -42,6 +42,17 @@ export const SUB_AGENT_EFFORT_PRESETS = {
|
|
|
42
42
|
},
|
|
43
43
|
deep: { maxTurns: 48, maxToolCalls: 96, maxWallTimeSec: 900, bashTimeoutSec: 180 },
|
|
44
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* External runs have no turn/tool-call budget (D5) — `effort` only ever moves wall time, and at
|
|
47
|
+
* external scale, not the internal tuple above (P1-3: those numbers previously leaked onto
|
|
48
|
+
* external roles unchanged, where `deep` at 900s was *shorter* than the external default).
|
|
49
|
+
* `standard` and an unset `effort` both keep the role's own `maxWallTimeSec` (or the external
|
|
50
|
+
* default), so this only has entries for the two presets that actually override it.
|
|
51
|
+
*/
|
|
52
|
+
export const SUB_AGENT_EXTERNAL_EFFORT_WALL_TIME_SEC = {
|
|
53
|
+
quick: 600,
|
|
54
|
+
deep: 5400,
|
|
55
|
+
};
|
|
45
56
|
const ALLOWED_EFFORTS = Object.keys(SUB_AGENT_EFFORT_PRESETS);
|
|
46
57
|
/**
|
|
47
58
|
* The invocation-side spelling of `contextMode` + `memory`. Those two frontmatter knobs
|
|
@@ -440,6 +451,11 @@ function parseExternalAgent(entryName, filePath, frontmatter, body, name, descri
|
|
|
440
451
|
const shell = parseBooleanField(frontmatter.shell, "shell");
|
|
441
452
|
if (shell.error)
|
|
442
453
|
return { warning: `${entryName}: ${shell.error}` };
|
|
454
|
+
if (shell.value && harness.value !== "exec") {
|
|
455
|
+
return {
|
|
456
|
+
warning: `${entryName}: "shell: true" is only supported with harness: exec; structured harnesses must assemble their own argv`,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
443
459
|
const env = parseEnvMap(frontmatter.env);
|
|
444
460
|
if (env.error)
|
|
445
461
|
return { warning: `${entryName}: ${env.error}` };
|
|
@@ -618,16 +634,28 @@ subagentDefaultModelRef) {
|
|
|
618
634
|
if (effortOverride.error) {
|
|
619
635
|
return { error: effortOverride.error };
|
|
620
636
|
}
|
|
637
|
+
const effectiveRuntime = baseConfig?.runtime ?? "internal";
|
|
621
638
|
// An explicit `effort` replaces the whole budget tuple rather than merging field by
|
|
622
|
-
// field, so a preset never produces a combination no preset describes.
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
639
|
+
// field, so a preset never produces a combination no preset describes. External is a
|
|
640
|
+
// separate branch (P1-3): it has no turn/tool-call budget, and effort's wall-time numbers
|
|
641
|
+
// are at external scale, not the internal tuple.
|
|
642
|
+
const budget = effectiveRuntime === "external"
|
|
643
|
+
? {
|
|
644
|
+
maxTurns: DEFAULT_MAX_TURNS,
|
|
645
|
+
maxToolCalls: DEFAULT_MAX_TOOL_CALLS,
|
|
646
|
+
maxWallTimeSec: (effortOverride.value && SUB_AGENT_EXTERNAL_EFFORT_WALL_TIME_SEC[effortOverride.value]) ??
|
|
647
|
+
baseConfig?.maxWallTimeSec ??
|
|
648
|
+
DEFAULT_EXTERNAL_MAX_WALL_TIME_SEC,
|
|
649
|
+
bashTimeoutSec: DEFAULT_BASH_TIMEOUT_SEC,
|
|
650
|
+
}
|
|
651
|
+
: effortOverride.value
|
|
652
|
+
? SUB_AGENT_EFFORT_PRESETS[effortOverride.value]
|
|
653
|
+
: {
|
|
654
|
+
maxTurns: baseConfig?.maxTurns ?? DEFAULT_MAX_TURNS,
|
|
655
|
+
maxToolCalls: baseConfig?.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS,
|
|
656
|
+
maxWallTimeSec: baseConfig?.maxWallTimeSec ?? DEFAULT_MAX_WALL_TIME_SEC,
|
|
657
|
+
bashTimeoutSec: baseConfig?.bashTimeoutSec ?? DEFAULT_BASH_TIMEOUT_SEC,
|
|
658
|
+
};
|
|
631
659
|
const contextOverride = parseContextChoice(overrides.context);
|
|
632
660
|
if (contextOverride.error) {
|
|
633
661
|
return { error: contextOverride.error };
|
|
@@ -37,8 +37,6 @@ export const claudeCodeHarness = {
|
|
|
37
37
|
}
|
|
38
38
|
const [executable, ...rest] = input.argv;
|
|
39
39
|
const existing = detectExistingFlags(rest);
|
|
40
|
-
// D4's addendum table lists no auto-appended effort flag for claude-code — only $EFFORT
|
|
41
|
-
// expansion for a role author whose wrapper accepts one.
|
|
42
40
|
const effort = toClaudeEffort(input.thinkingLevel);
|
|
43
41
|
const { argv: expandedRest, used } = expandPlaceholders(rest, {
|
|
44
42
|
$MODEL: input.model,
|
|
@@ -50,6 +48,9 @@ export const claudeCodeHarness = {
|
|
|
50
48
|
if (!existing.model && input.model && !used.has("$MODEL")) {
|
|
51
49
|
args.push("--model", input.model);
|
|
52
50
|
}
|
|
51
|
+
if (!existing.effort && effort && !used.has("$EFFORT")) {
|
|
52
|
+
args.push("--effort", effort);
|
|
53
|
+
}
|
|
53
54
|
if (!used.has("$SYSTEM_PROMPT_FILE")) {
|
|
54
55
|
args.push("--append-system-prompt-file", input.systemPromptFile);
|
|
55
56
|
}
|
|
@@ -61,8 +62,7 @@ export const claudeCodeHarness = {
|
|
|
61
62
|
presetSessionId = randomUUID();
|
|
62
63
|
args.push("--session-id", presetSessionId);
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
return { executable, args, resumable: true, promptFiles, presetSessionId };
|
|
65
|
+
return { executable, args, resumable: true, presetSessionId };
|
|
66
66
|
},
|
|
67
67
|
parseOutcome(input) {
|
|
68
68
|
let finalText = "";
|
|
@@ -144,7 +144,6 @@ export const claudeCodeHarness = {
|
|
|
144
144
|
usage,
|
|
145
145
|
usageKnown,
|
|
146
146
|
costKnown,
|
|
147
|
-
outputTruncated: false,
|
|
148
147
|
stderrTail: input.stderrTail,
|
|
149
148
|
errorMessage,
|
|
150
149
|
};
|
|
@@ -53,12 +53,7 @@ export const codexCliHarness = {
|
|
|
53
53
|
const args = input.resumeSessionId
|
|
54
54
|
? [...baseArgs, "resume", input.resumeSessionId, "--json", "-"]
|
|
55
55
|
: [...baseArgs, "--json", "-"];
|
|
56
|
-
return {
|
|
57
|
-
executable,
|
|
58
|
-
args,
|
|
59
|
-
resumable: true,
|
|
60
|
-
promptFiles: used.has("$PROMPT_FILE") ? [input.promptFile] : undefined,
|
|
61
|
-
};
|
|
56
|
+
return { executable, args, resumable: true };
|
|
62
57
|
},
|
|
63
58
|
parseOutcome(input) {
|
|
64
59
|
let finalText = "";
|
|
@@ -125,7 +120,6 @@ export const codexCliHarness = {
|
|
|
125
120
|
usage,
|
|
126
121
|
usageKnown,
|
|
127
122
|
costKnown: false, // codex-cli never reports a cost field (D4).
|
|
128
|
-
outputTruncated: false,
|
|
129
123
|
stderrTail: input.stderrTail,
|
|
130
124
|
errorMessage,
|
|
131
125
|
};
|
|
@@ -22,7 +22,13 @@ export const execHarness = {
|
|
|
22
22
|
parseOutcome(input) {
|
|
23
23
|
const text = input.eventsText;
|
|
24
24
|
const truncated = text.length > MAX_OUTPUT_CHARS;
|
|
25
|
-
|
|
25
|
+
// The full, untruncated capture always stays on disk as this run's events.jsonl (spec 040
|
|
26
|
+
// D1's layout, unconditional for every external run) — a truncated reply must say so
|
|
27
|
+
// explicitly rather than silently dropping the tail (P1-3: the playbook's "full text is
|
|
28
|
+
// always recoverable" promise did not actually hold for a chatty `exec` role).
|
|
29
|
+
const finalText = truncated
|
|
30
|
+
? `${text.slice(0, MAX_OUTPUT_CHARS)}\n\n[... output truncated at ${MAX_OUTPUT_CHARS} characters; the full capture is this run's events.jsonl ...]`
|
|
31
|
+
: text;
|
|
26
32
|
return {
|
|
27
33
|
finalText,
|
|
28
34
|
terminalSeen: false, // Always false, even on success — exec has no protocol terminal (D4/D9).
|
|
@@ -30,7 +36,6 @@ export const execHarness = {
|
|
|
30
36
|
exitCode: input.exitCode,
|
|
31
37
|
usageKnown: false,
|
|
32
38
|
costKnown: false,
|
|
33
|
-
outputTruncated: truncated,
|
|
34
39
|
stderrTail: input.stderrTail,
|
|
35
40
|
errorMessage: input.exitCode === 0 ? undefined : `exec exited with code ${input.exitCode ?? "unknown"}`,
|
|
36
41
|
};
|
|
@@ -26,8 +26,6 @@ export interface BuildInvocationResult {
|
|
|
26
26
|
args: string[];
|
|
27
27
|
/** Whether this harness can be continued later via `resumeSessionId` (claude-code/codex-cli). */
|
|
28
28
|
resumable: boolean;
|
|
29
|
-
/** Paths this invocation references by flag, beyond stdin — kept for the `/subagents show` argv dump. */
|
|
30
|
-
promptFiles?: string[];
|
|
31
29
|
/**
|
|
32
30
|
* claude-code only (D4): a session id it picked and passed via `--session-id` *before* running,
|
|
33
31
|
* so `resume` does not depend on first successfully parsing a `result` event out of a run that
|
|
@@ -50,7 +48,6 @@ export interface ExternalOutcome {
|
|
|
50
48
|
usageKnown: boolean;
|
|
51
49
|
/** `codex-cli`/`exec` are always false: neither reports a cost field. */
|
|
52
50
|
costKnown: boolean;
|
|
53
|
-
outputTruncated: boolean;
|
|
54
51
|
stderrTail?: string;
|
|
55
52
|
errorMessage?: string;
|
|
56
53
|
}
|
|
@@ -33,7 +33,8 @@ export function classifyExternalOutcome(harnessId, outcome) {
|
|
|
33
33
|
}
|
|
34
34
|
const MODEL_FLAG_PATTERN = /^(--model|-m)$/;
|
|
35
35
|
const EFFORT_FLAG_PATTERN = /^(--effort|--thinking)$/;
|
|
36
|
-
const
|
|
36
|
+
const CODEX_CONFIG_FLAG_PATTERN = /^(-c|--config)$/;
|
|
37
|
+
const CODEX_MODEL_VALUE_PREFIX = "model=";
|
|
37
38
|
const CODEX_EFFORT_VALUE_PREFIX = "model_reasoning_effort=";
|
|
38
39
|
/** Which flags the user's own `command` already spells out, so a harness never injects a duplicate (D4). */
|
|
39
40
|
export function detectExistingFlags(argv) {
|
|
@@ -45,10 +46,24 @@ export function detectExistingFlags(argv) {
|
|
|
45
46
|
model = true;
|
|
46
47
|
if (EFFORT_FLAG_PATTERN.test(token))
|
|
47
48
|
effort = true;
|
|
48
|
-
if (
|
|
49
|
-
|
|
49
|
+
if (CODEX_CONFIG_FLAG_PATTERN.test(token)) {
|
|
50
|
+
const value = argv[i + 1];
|
|
51
|
+
if (value?.startsWith(CODEX_MODEL_VALUE_PREFIX))
|
|
52
|
+
model = true;
|
|
53
|
+
if (value?.startsWith(CODEX_EFFORT_VALUE_PREFIX))
|
|
54
|
+
effort = true;
|
|
55
|
+
}
|
|
50
56
|
if (token.startsWith("--model=") || token.startsWith("-m="))
|
|
51
57
|
model = true;
|
|
58
|
+
if (token.startsWith("--effort=") || token.startsWith("--thinking="))
|
|
59
|
+
effort = true;
|
|
60
|
+
if (token.startsWith("-c=") || token.startsWith("--config=")) {
|
|
61
|
+
const value = token.slice(token.indexOf("=") + 1);
|
|
62
|
+
if (value.startsWith(CODEX_MODEL_VALUE_PREFIX))
|
|
63
|
+
model = true;
|
|
64
|
+
if (value.startsWith(CODEX_EFFORT_VALUE_PREFIX))
|
|
65
|
+
effort = true;
|
|
66
|
+
}
|
|
52
67
|
}
|
|
53
68
|
return { model, effort };
|
|
54
69
|
}
|
|
@@ -7,6 +7,11 @@ import { type RunMutates } from "../runs.js";
|
|
|
7
7
|
* detached process. The launch order matters (D1): admission and the lease are the caller's job
|
|
8
8
|
* (tool.ts, shared with internal runs); this module owns everything from "persist launch intent"
|
|
9
9
|
* onward — spawn, pid persistence, stdin delivery, output capture, and settlement.
|
|
10
|
+
*
|
|
11
|
+
* stdout/stderr are opened as real files and handed to the child directly via `stdio` (P0-1): the
|
|
12
|
+
* child writes its own output, so it survives the daemon disappearing mid-run instead of writing
|
|
13
|
+
* into a pipe nobody is reading. A restart's own recovery (`SubAgentRunManager.restore()` /
|
|
14
|
+
* `sweep()`) reads the same files back once the process is confirmed gone.
|
|
10
15
|
*/
|
|
11
16
|
export interface LaunchExternalRunInput {
|
|
12
17
|
runId: string;
|