@oyasmi/pipiclaw 0.9.2-beta.2 → 0.9.2-beta.4
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 +3 -0
- package/dist/agent/channel-runner.d.ts +13 -18
- package/dist/agent/channel-runner.js +44 -90
- package/dist/agent/command-extension.js +1 -1
- package/dist/agent/context-budget.d.ts +8 -0
- package/dist/agent/context-budget.js +10 -2
- package/dist/agent/job-manager.d.ts +1 -1
- package/dist/agent/job-manager.js +9 -1
- package/dist/agent/prompt/builder.d.ts +0 -1
- package/dist/agent/prompt/builder.js +1 -14
- package/dist/agent/prompt/manifest.js +2 -1
- package/dist/agent/prompt/sections.js +1 -1
- package/dist/agent/runner-factory.d.ts +19 -1
- package/dist/agent/runner-factory.js +8 -1
- package/dist/agent/session-events.d.ts +2 -2
- package/dist/agent/turn-prompt.d.ts +35 -0
- package/dist/agent/turn-prompt.js +37 -0
- package/dist/agent/turn-recovery.js +1 -1
- package/dist/agent/turn-state.d.ts +60 -0
- package/dist/agent/turn-state.js +95 -0
- package/dist/agent/types.d.ts +3 -3
- package/dist/{runtime → channel}/channel-context.d.ts +6 -2
- package/dist/{runtime → channel}/channel-context.js +6 -2
- package/dist/{runtime → channel}/channel-event.d.ts +8 -0
- package/dist/channel/channel-paths.d.ts +16 -0
- package/dist/{runtime → channel}/channel-paths.js +20 -0
- package/dist/{agent/commands.d.ts → commands/catalog.d.ts} +16 -1
- package/dist/{agent/commands.js → commands/catalog.js} +30 -0
- package/dist/index.d.ts +1 -1
- package/dist/log.js +14 -5
- package/dist/main.js +29 -0
- package/dist/memory/commands.js +2 -2
- package/dist/memory/maintenance-state.d.ts +8 -0
- package/dist/memory/maintenance-state.js +47 -4
- package/dist/memory/scheduler.d.ts +6 -0
- package/dist/memory/scheduler.js +19 -16
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/runtime/bootstrap.d.ts +2 -2
- package/dist/runtime/bootstrap.js +43 -13
- package/dist/runtime/delivery.d.ts +3 -3
- package/dist/runtime/dingtalk.d.ts +4 -4
- package/dist/runtime/dingtalk.js +2 -2
- package/dist/runtime/durable-dispatch.d.ts +7 -1
- package/dist/runtime/durable-dispatch.js +12 -2
- package/dist/runtime/event-commands.js +2 -2
- package/dist/runtime/events.d.ts +8 -1
- package/dist/runtime/events.js +15 -3
- package/dist/runtime/project-commands.js +2 -2
- package/dist/runtime/skill-commands.d.ts +27 -0
- package/dist/runtime/skill-commands.js +72 -0
- package/dist/runtime/subagent-commands.d.ts +8 -0
- package/dist/runtime/subagent-commands.js +29 -5
- package/dist/runtime/task-commands.js +2 -2
- package/dist/runtime/task-driver.d.ts +5 -1
- package/dist/runtime/task-driver.js +13 -12
- package/dist/runtime/task-migration.js +3 -2
- package/dist/runtime/task-wake.d.ts +6 -1
- package/dist/runtime/task-wake.js +21 -2
- package/dist/settings.d.ts +13 -0
- package/dist/settings.js +78 -0
- package/dist/shared/token-estimate.d.ts +1 -0
- package/dist/shared/token-estimate.js +19 -0
- package/dist/subagents/external/claude-code.js +20 -0
- package/dist/subagents/external/codex-cli.js +33 -0
- package/dist/subagents/external/harness.d.ts +8 -0
- package/dist/subagents/external/progress-tail.d.ts +14 -0
- package/dist/subagents/external/progress-tail.js +84 -0
- package/dist/subagents/external/run.js +1 -0
- package/dist/subagents/external/settlement.d.ts +4 -1
- package/dist/subagents/external/settlement.js +9 -2
- package/dist/subagents/runs.d.ts +45 -4
- package/dist/subagents/runs.js +187 -14
- package/dist/subagents/tool.js +4 -3
- package/dist/tasks/artifact-subject.d.ts +8 -0
- package/dist/tasks/artifact-subject.js +25 -0
- package/dist/tools/glob-match.d.ts +25 -4
- package/dist/tools/glob-match.js +175 -53
- package/dist/tools/glob.js +5 -2
- package/dist/tools/grep.js +4 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/registry.d.ts +1 -1
- package/dist/tools/send-media.d.ts +1 -1
- package/dist/tools/skill.d.ts +15 -0
- package/dist/tools/skill.js +16 -8
- package/dist/tui/app.js +5 -3
- package/dist/tui/commands.d.ts +1 -0
- package/dist/tui/commands.js +3 -1
- package/dist/tui/terminal-context.d.ts +2 -2
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/dist/tui/turn-controller.d.ts +2 -1
- package/dist/tui/turn-controller.js +2 -1
- package/examples/sub-agents/README.md +3 -2
- package/examples/sub-agents/builder-hard.md +17 -16
- package/examples/sub-agents/builder.md +16 -12
- package/examples/sub-agents/documenter.md +15 -16
- package/examples/sub-agents/explorer.md +16 -17
- package/examples/sub-agents/git-committer.md +18 -28
- package/examples/sub-agents/log-sifter.md +15 -14
- package/examples/sub-agents/planner.md +11 -11
- package/examples/sub-agents/reviewer.md +20 -13
- package/examples/sub-agents/scout.md +14 -11
- package/examples/sub-agents/verifier.md +17 -14
- package/examples/sub-agents/worker.md +18 -12
- package/package.json +1 -1
- package/dist/runtime/channel-paths.d.ts +0 -4
- /package/dist/{runtime → channel}/active-session-store.d.ts +0 -0
- /package/dist/{runtime → channel}/active-session-store.js +0 -0
- /package/dist/{runtime → channel}/channel-event.js +0 -0
- /package/dist/{runtime → channel}/channel-index.d.ts +0 -0
- /package/dist/{runtime → channel}/channel-index.js +0 -0
- /package/dist/{runtime → channel}/project-scope-store.d.ts +0 -0
- /package/dist/{runtime → channel}/project-scope-store.js +0 -0
- /package/dist/{runtime → channel}/store.d.ts +0 -0
- /package/dist/{runtime → channel}/store.js +0 -0
- /package/dist/{agent → commands}/reply-limits.d.ts +0 -0
- /package/dist/{agent → commands}/reply-limits.js +0 -0
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
* `createRuntimeContext`'s closures.
|
|
6
6
|
*/
|
|
7
7
|
import { type JobSnapshot } from "../agent/job-manager.js";
|
|
8
|
+
import type { ChannelEvent } from "../channel/channel-event.js";
|
|
8
9
|
import type { Executor } from "../executor.js";
|
|
9
10
|
import { type RunRecord } from "../subagents/runs.js";
|
|
10
11
|
import { type WakeTaskTransitionHooks } from "../tasks/store.js";
|
|
11
|
-
import type { ChannelEvent } from "./channel-event.js";
|
|
12
12
|
/**
|
|
13
13
|
* Whether a `[JOB:<jobId>] ... belongs to task <taskId>.` wake actually names a job that: exists
|
|
14
14
|
* on this channel, has actually finished (a still-`running` job cannot have produced this wake —
|
|
@@ -34,6 +34,9 @@ export declare function isTrustedInternalWake(event: ChannelEvent, kind: "job" |
|
|
|
34
34
|
export interface ClaimedDelegationWake {
|
|
35
35
|
taskId: string;
|
|
36
36
|
activated: boolean;
|
|
37
|
+
/** True when it is safe to drop this wake without a turn even though it did not activate the
|
|
38
|
+
* task itself — see `isTaskActivelyDriven`. Always true when `activated` is true. */
|
|
39
|
+
taskStillDriven: boolean;
|
|
37
40
|
finish(): Promise<void>;
|
|
38
41
|
rollback(): Promise<void>;
|
|
39
42
|
}
|
|
@@ -44,6 +47,8 @@ export declare function claimVerifiedDelegationWake(event: ChannelEvent, workspa
|
|
|
44
47
|
export interface ClaimedJobWake {
|
|
45
48
|
taskId: string;
|
|
46
49
|
activated: boolean;
|
|
50
|
+
/** See `ClaimedDelegationWake.taskStillDriven`. */
|
|
51
|
+
taskStillDriven: boolean;
|
|
47
52
|
finish(): Promise<void>;
|
|
48
53
|
}
|
|
49
54
|
/** Same shape as `claimVerifiedDelegationWake`, for a `[JOB:<jobId>] ... belongs to task
|
|
@@ -5,9 +5,24 @@
|
|
|
5
5
|
* `createRuntimeContext`'s closures.
|
|
6
6
|
*/
|
|
7
7
|
import { getChannelJobManager } from "../agent/job-manager.js";
|
|
8
|
+
import { getChannelDir } from "../channel/channel-paths.js";
|
|
8
9
|
import { getSubAgentRunManager } from "../subagents/runs.js";
|
|
9
|
-
import { activateWaitingTask, rollbackWaitingTask } from "../tasks/store.js";
|
|
10
|
-
import {
|
|
10
|
+
import { activateWaitingTask, readStoredTask, rollbackWaitingTask, } from "../tasks/store.js";
|
|
11
|
+
import { normalizeStoredStatus } from "../tasks/transitions.js";
|
|
12
|
+
/**
|
|
13
|
+
* True when `taskId` is currently `active` and enabled — i.e. the task driver already owns
|
|
14
|
+
* advancing it. A completion wake that could not activate the task (because it was not
|
|
15
|
+
* `waiting`) is safe to drop without spending an agent turn only in this case: some other wake in
|
|
16
|
+
* the same fan-out already activated it, and the driver will pick up the result. Every other case
|
|
17
|
+
* — `done`, archived, disabled, or the task missing entirely — has nobody left to look at the
|
|
18
|
+
* wake's result if it is dropped here, so the caller must still route it to a normal turn.
|
|
19
|
+
*/
|
|
20
|
+
async function isTaskActivelyDriven(channelDir, taskId) {
|
|
21
|
+
const document = await readStoredTask(channelDir, taskId, false, true).catch(() => undefined);
|
|
22
|
+
return (document !== undefined &&
|
|
23
|
+
normalizeStoredStatus(document.fields.status) === "active" &&
|
|
24
|
+
document.fields.enabled !== false);
|
|
25
|
+
}
|
|
11
26
|
/**
|
|
12
27
|
* Whether a `[JOB:<jobId>] ... belongs to task <taskId>.` wake actually names a job that: exists
|
|
13
28
|
* on this channel, has actually finished (a still-`running` job cannot have produced this wake —
|
|
@@ -56,9 +71,11 @@ export async function claimVerifiedDelegationWake(event, workspaceDir, hooks) {
|
|
|
56
71
|
}
|
|
57
72
|
const channelDir = getChannelDir(workspaceDir, event.channelId);
|
|
58
73
|
const activated = await activateWaitingTask(channelDir, wake.taskId, hooks);
|
|
74
|
+
const taskStillDriven = activated !== undefined || (await isTaskActivelyDriven(channelDir, wake.taskId));
|
|
59
75
|
return {
|
|
60
76
|
taskId: wake.taskId,
|
|
61
77
|
activated: activated !== undefined,
|
|
78
|
+
taskStillDriven,
|
|
62
79
|
finish: async () => {
|
|
63
80
|
await runManager.finishWakeConsumption(wake.resourceId, event.dispatchId);
|
|
64
81
|
},
|
|
@@ -81,9 +98,11 @@ export async function claimVerifiedJobWake(event, workspaceDir, executor, hooks)
|
|
|
81
98
|
}
|
|
82
99
|
const channelDir = getChannelDir(workspaceDir, event.channelId);
|
|
83
100
|
const activated = await activateWaitingTask(channelDir, wake.taskId, hooks);
|
|
101
|
+
const taskStillDriven = activated !== undefined || (await isTaskActivelyDriven(channelDir, wake.taskId));
|
|
84
102
|
return {
|
|
85
103
|
taskId: wake.taskId,
|
|
86
104
|
activated: activated !== undefined,
|
|
105
|
+
taskStillDriven,
|
|
87
106
|
finish: async () => {
|
|
88
107
|
await jobManager.finishWakeConsumption(wake.resourceId, event.dispatchId);
|
|
89
108
|
},
|
package/dist/settings.d.ts
CHANGED
|
@@ -71,6 +71,16 @@ export interface PipiclawSessionSearchSettings {
|
|
|
71
71
|
summarizeWithModel: boolean;
|
|
72
72
|
timeoutMs: number;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* How much out-of-band commentary a delegation run (`src/subagents/`) or background job produces
|
|
76
|
+
* outside of its own completion wake — plain text, not an LLM turn, so it reaches the channel in
|
|
77
|
+
* roughly the time the run itself takes rather than waiting on a wake turn's latency.
|
|
78
|
+
* `"off"` is today's behavior; `"settled"` adds only the one-line completion receipt; `"live"`
|
|
79
|
+
* also adds a sparse trickle of running-progress notices for long external runs.
|
|
80
|
+
*/
|
|
81
|
+
export interface PipiclawDelegationSettings {
|
|
82
|
+
notices: "off" | "settled" | "live";
|
|
83
|
+
}
|
|
74
84
|
/**
|
|
75
85
|
* Everything `settings.json` may contain (spec 035 D1).
|
|
76
86
|
*
|
|
@@ -120,6 +130,7 @@ export interface PipiclawSettings {
|
|
|
120
130
|
};
|
|
121
131
|
};
|
|
122
132
|
tui?: Partial<PipiclawTuiSettings>;
|
|
133
|
+
delegation?: Partial<PipiclawDelegationSettings>;
|
|
123
134
|
}
|
|
124
135
|
export interface PipiclawTuiSettings {
|
|
125
136
|
/**
|
|
@@ -140,6 +151,7 @@ export declare class PipiclawSettingsManager {
|
|
|
140
151
|
private settings;
|
|
141
152
|
private loadErrors;
|
|
142
153
|
private retiredKeys;
|
|
154
|
+
private invalidEnumValues;
|
|
143
155
|
/** The file's change token as of the last actual parse; see `reload`. */
|
|
144
156
|
private loadedStamp;
|
|
145
157
|
constructor(baseDir: string);
|
|
@@ -168,6 +180,7 @@ export declare class PipiclawSettingsManager {
|
|
|
168
180
|
getSessionSearchSettings(): PipiclawSessionSearchSettings;
|
|
169
181
|
getLoggingSettings(): PipiclawLoggingSettings;
|
|
170
182
|
getTuiSettings(): PipiclawTuiSettings;
|
|
183
|
+
getDelegationSettings(): PipiclawDelegationSettings;
|
|
171
184
|
getRetryEnabled(): boolean;
|
|
172
185
|
setRetryEnabled(enabled: boolean): void;
|
|
173
186
|
/**
|
package/dist/settings.js
CHANGED
|
@@ -15,6 +15,9 @@ import { fileStamp } from "./shared/file-stamp.js";
|
|
|
15
15
|
const DEFAULT_TUI = {
|
|
16
16
|
responseMode: "full_progress_then_plain_final",
|
|
17
17
|
};
|
|
18
|
+
const DEFAULT_DELEGATION = {
|
|
19
|
+
notices: "live",
|
|
20
|
+
};
|
|
18
21
|
const DEFAULT_COMPACTION = {
|
|
19
22
|
enabled: true,
|
|
20
23
|
reserveTokens: 16384,
|
|
@@ -132,6 +135,69 @@ function hasNestedKey(root, dottedPath) {
|
|
|
132
135
|
function findRetiredSettingsKeys(parsed) {
|
|
133
136
|
return RETIRED_SETTINGS_KEYS.filter((key) => hasNestedKey(parsed, key));
|
|
134
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Every enum-valued key, with the values it accepts.
|
|
140
|
+
*
|
|
141
|
+
* `settings.json` is hand-edited and nothing type-checks it, so a typo used to travel straight
|
|
142
|
+
* into the runtime as a string the code never compares equal to anything. The failure modes were
|
|
143
|
+
* not uniform and none of them said anything: `logging.level: "verbos"` made *every* log record
|
|
144
|
+
* fail its threshold comparison (`LEVEL_ORDER[level] >= NaN`) and silenced the log entirely;
|
|
145
|
+
* `delegation.notices: "liv"` fell through both negative checks and behaved as `live`, the
|
|
146
|
+
* opposite of the "off" a nervous operator was reaching for. Validating here — once, on load —
|
|
147
|
+
* means an unrecognized value is dropped so the documented default applies, and the operator is
|
|
148
|
+
* told which key was ignored.
|
|
149
|
+
*
|
|
150
|
+
* The value lists are literal rather than imported: `ResponseMode` lives in the DingTalk
|
|
151
|
+
* transport, and a value import would tie settings loading to that module's import graph. The
|
|
152
|
+
* `satisfies` clauses keep them honest against the unions they mirror.
|
|
153
|
+
*/
|
|
154
|
+
const ENUM_SETTINGS = [
|
|
155
|
+
{ path: "logging.level", values: ["debug", "info", "warn", "error"] },
|
|
156
|
+
{
|
|
157
|
+
path: "tui.responseMode",
|
|
158
|
+
values: [
|
|
159
|
+
"full_progress_then_plain_final",
|
|
160
|
+
"rolling_progress_then_plain_final",
|
|
161
|
+
"final_card_only",
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
{ path: "delegation.notices", values: ["off", "settled", "live"] },
|
|
165
|
+
];
|
|
166
|
+
function readNestedKey(root, dottedPath) {
|
|
167
|
+
const segments = dottedPath.split(".");
|
|
168
|
+
const key = segments.pop();
|
|
169
|
+
if (!key)
|
|
170
|
+
return undefined;
|
|
171
|
+
let node = root;
|
|
172
|
+
for (const segment of segments) {
|
|
173
|
+
if (!node || typeof node !== "object" || Array.isArray(node))
|
|
174
|
+
return undefined;
|
|
175
|
+
node = node[segment];
|
|
176
|
+
}
|
|
177
|
+
if (!node || typeof node !== "object" || Array.isArray(node))
|
|
178
|
+
return undefined;
|
|
179
|
+
const parent = node;
|
|
180
|
+
return Object.hasOwn(parent, key) ? { parent, key } : undefined;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Drop every enum key whose value is not one this build understands, and describe what was
|
|
184
|
+
* dropped. Deleting rather than coercing is deliberate: `??` then yields the same default a
|
|
185
|
+
* missing key would, so one bad value cannot produce a state the rest of the code never expects.
|
|
186
|
+
*/
|
|
187
|
+
function stripInvalidEnumValues(parsed) {
|
|
188
|
+
const problems = [];
|
|
189
|
+
for (const { path, values } of ENUM_SETTINGS) {
|
|
190
|
+
const found = readNestedKey(parsed, path);
|
|
191
|
+
if (!found)
|
|
192
|
+
continue;
|
|
193
|
+
const value = found.parent[found.key];
|
|
194
|
+
if (value === undefined || values.includes(value))
|
|
195
|
+
continue;
|
|
196
|
+
delete found.parent[found.key];
|
|
197
|
+
problems.push(`${path}: ${JSON.stringify(value)} is not one of ${values.join(" | ")}; using the default instead`);
|
|
198
|
+
}
|
|
199
|
+
return problems;
|
|
200
|
+
}
|
|
135
201
|
/**
|
|
136
202
|
* Settings manager for pipiclaw.
|
|
137
203
|
* Stores global settings in the pipiclaw root directory.
|
|
@@ -140,6 +206,7 @@ export class PipiclawSettingsManager {
|
|
|
140
206
|
constructor(baseDir) {
|
|
141
207
|
this.loadErrors = [];
|
|
142
208
|
this.retiredKeys = [];
|
|
209
|
+
this.invalidEnumValues = [];
|
|
143
210
|
/** The file's change token as of the last actual parse; see `reload`. */
|
|
144
211
|
this.loadedStamp = "";
|
|
145
212
|
this.settingsPath = join(baseDir, "settings.json");
|
|
@@ -148,6 +215,7 @@ export class PipiclawSettingsManager {
|
|
|
148
215
|
load() {
|
|
149
216
|
this.loadErrors = [];
|
|
150
217
|
this.retiredKeys = [];
|
|
218
|
+
this.invalidEnumValues = [];
|
|
151
219
|
this.loadedStamp = fileStamp(this.settingsPath);
|
|
152
220
|
if (!existsSync(this.settingsPath)) {
|
|
153
221
|
return {};
|
|
@@ -163,6 +231,7 @@ export class PipiclawSettingsManager {
|
|
|
163
231
|
return {};
|
|
164
232
|
}
|
|
165
233
|
this.retiredKeys = findRetiredSettingsKeys(parsed);
|
|
234
|
+
this.invalidEnumValues = stripInvalidEnumValues(parsed);
|
|
166
235
|
return parsed;
|
|
167
236
|
}
|
|
168
237
|
catch (error) {
|
|
@@ -218,6 +287,9 @@ export class PipiclawSettingsManager {
|
|
|
218
287
|
message: `${this.retiredKeys.join(", ")}: no longer configurable; these are now built-in constants and the values here are ignored. Remove them from settings.json.`,
|
|
219
288
|
});
|
|
220
289
|
}
|
|
290
|
+
for (const message of this.invalidEnumValues) {
|
|
291
|
+
diagnostics.push({ source: "settings", path: this.settingsPath, severity: "warning", message });
|
|
292
|
+
}
|
|
221
293
|
return diagnostics;
|
|
222
294
|
}
|
|
223
295
|
getCompactionSettings() {
|
|
@@ -284,6 +356,12 @@ export class PipiclawSettingsManager {
|
|
|
284
356
|
getTuiSettings() {
|
|
285
357
|
return { ...DEFAULT_TUI, ...this.settings.tui };
|
|
286
358
|
}
|
|
359
|
+
getDelegationSettings() {
|
|
360
|
+
return {
|
|
361
|
+
...DEFAULT_DELEGATION,
|
|
362
|
+
notices: this.settings.delegation?.notices ?? DEFAULT_DELEGATION.notices,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
287
365
|
getRetryEnabled() {
|
|
288
366
|
return this.settings.retry?.enabled ?? DEFAULT_RETRY.enabled;
|
|
289
367
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function estimateTokens(text: string): number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rough token estimate, shared by everything that has to reason about context size without
|
|
3
|
+
* calling a tokenizer. CJK runs about one token per character, Latin text about four characters
|
|
4
|
+
* per token; the provider's real tokenizer is the authority, and the usage ledger records what
|
|
5
|
+
* it billed.
|
|
6
|
+
*
|
|
7
|
+
* The script split matters wherever the estimate gates behavior rather than just reporting: a
|
|
8
|
+
* flat characters-per-token ratio tuned for Latin text underestimates Chinese input roughly
|
|
9
|
+
* threefold, so a budget check would clear a message that in fact does not fit.
|
|
10
|
+
*/
|
|
11
|
+
const CJK_REGEX = /\p{Script=Han}|\p{Script=Hiragana}|\p{Script=Katakana}|\p{Script=Hangul}/u;
|
|
12
|
+
export function estimateTokens(text) {
|
|
13
|
+
let cjk = 0;
|
|
14
|
+
for (const char of text) {
|
|
15
|
+
if (CJK_REGEX.test(char))
|
|
16
|
+
cjk++;
|
|
17
|
+
}
|
|
18
|
+
return Math.ceil(cjk + (text.length - cjk) / 4);
|
|
19
|
+
}
|
|
@@ -193,4 +193,24 @@ export const claudeCodeHarness = {
|
|
|
193
193
|
errorMessage,
|
|
194
194
|
};
|
|
195
195
|
},
|
|
196
|
+
// P1a: the first tool_use block in a streamed assistant message names the step currently
|
|
197
|
+
// running. Text-only assistant messages (reasoning, the final answer) have nothing to show.
|
|
198
|
+
toProgressLabel(line) {
|
|
199
|
+
let event;
|
|
200
|
+
try {
|
|
201
|
+
event = JSON.parse(line.trim());
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
if (!isRecord(event) || event.type !== "assistant" || !isRecord(event.message))
|
|
207
|
+
return undefined;
|
|
208
|
+
const parts = Array.isArray(event.message.content) ? event.message.content : [];
|
|
209
|
+
for (const part of parts) {
|
|
210
|
+
if (isRecord(part) && part.type === "tool_use" && typeof part.name === "string") {
|
|
211
|
+
return part.name;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
},
|
|
196
216
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRecord } from "../../shared/type-guards.js";
|
|
1
2
|
import { detectExistingFlags, expandPlaceholders, formatDroppedPlaceholderWarnings, } from "./harness.js";
|
|
2
3
|
/**
|
|
3
4
|
* `codex-cli` harness (spec 040, D3/D4). One prompt, one short-lived process, NDJSON on stdout
|
|
@@ -130,4 +131,36 @@ export const codexCliHarness = {
|
|
|
130
131
|
errorMessage,
|
|
131
132
|
};
|
|
132
133
|
},
|
|
134
|
+
// P1a: the two item types worth surfacing mid-run — the shell command a step is currently
|
|
135
|
+
// running, and todo-list progress. `agent_message`/everything else has nothing to show before
|
|
136
|
+
// the run is over.
|
|
137
|
+
toProgressLabel(line) {
|
|
138
|
+
let event;
|
|
139
|
+
try {
|
|
140
|
+
event = JSON.parse(line.trim());
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
if (typeof event !== "object" || event === null)
|
|
146
|
+
return undefined;
|
|
147
|
+
const record = event;
|
|
148
|
+
if (record.type !== "item.started" && record.type !== "item.updated")
|
|
149
|
+
return undefined;
|
|
150
|
+
const item = record.item;
|
|
151
|
+
if (!item)
|
|
152
|
+
return undefined;
|
|
153
|
+
if (item.type === "command_execution" && typeof item.command === "string") {
|
|
154
|
+
const firstLine = item.command.split("\n")[0]?.trim();
|
|
155
|
+
return firstLine ? firstLine.slice(0, 80) : undefined;
|
|
156
|
+
}
|
|
157
|
+
if (item.type === "todo_list" && Array.isArray(item.items)) {
|
|
158
|
+
const total = item.items.length;
|
|
159
|
+
if (total === 0)
|
|
160
|
+
return undefined;
|
|
161
|
+
const done = item.items.filter((entry) => isRecord(entry) && entry.completed === true).length;
|
|
162
|
+
return `待办 ${done}/${total}`;
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
},
|
|
133
166
|
};
|
|
@@ -76,6 +76,14 @@ export interface ExternalHarness {
|
|
|
76
76
|
/** Parse stdout into a unified outcome. Must never throw — a parse failure degrades to
|
|
77
77
|
* `protocolStatus: "unparsable"`, not an exception (D4). */
|
|
78
78
|
parseOutcome(input: ParseOutcomeInput): ExternalOutcome;
|
|
79
|
+
/**
|
|
80
|
+
* P1a: map one raw output line, still mid-run, to a short human-readable step label — e.g. the
|
|
81
|
+
* command a coding CLI just started, or a todo-list progress count. Same contract as
|
|
82
|
+
* `parseOutcome`: must never throw, and returns `undefined` for a line that carries no
|
|
83
|
+
* progress-worthy information (most lines). Optional — `exec` has no structured protocol to
|
|
84
|
+
* read mid-run, so it omits this entirely rather than implement a no-op.
|
|
85
|
+
*/
|
|
86
|
+
toProgressLabel?(line: string): string | undefined;
|
|
79
87
|
}
|
|
80
88
|
/**
|
|
81
89
|
* The D4 status table, shared by the live post-exit path and restart reconciliation (D10.3) so
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RunHarness } from "../runs.js";
|
|
2
|
+
export interface ExternalProgressTailInput {
|
|
3
|
+
artifactDir: string;
|
|
4
|
+
harnessId: RunHarness;
|
|
5
|
+
/** Process start time, so the "don't bother for a short run" window is measured from when the
|
|
6
|
+
* run actually started producing output, not from registration. */
|
|
7
|
+
startedAt: number;
|
|
8
|
+
onProgress: (label: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface ExternalProgressTail {
|
|
11
|
+
stop(): void;
|
|
12
|
+
}
|
|
13
|
+
/** Starts polling; returns a handle whose `stop()` is idempotent and always safe to call. */
|
|
14
|
+
export declare function startExternalProgressTail(input: ExternalProgressTailInput): ExternalProgressTail;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { getExternalHarness } from "./registry.js";
|
|
4
|
+
/**
|
|
5
|
+
* P1a: turns an external run's `events.jsonl` — already being written incrementally by the child
|
|
6
|
+
* process — into a trickle of human-readable "what is it doing right now" notices, instead of the
|
|
7
|
+
* silence that today lasts the whole run. Polls rather than watches: correctness never depends on
|
|
8
|
+
* catching every write, so a missed tick just costs one extra poll interval of staleness, and one
|
|
9
|
+
* timer per run stays far simpler than a filesystem watcher per run.
|
|
10
|
+
*
|
|
11
|
+
* Deliberately re-reads the whole file each tick instead of tracking a byte offset: an offset read
|
|
12
|
+
* has to handle a half-written trailing line, this doesn't, and a run's artifact file is small
|
|
13
|
+
* enough (single-digit MB even for a long run) that re-reading it every `POLL_MS` costs nothing a
|
|
14
|
+
* background process needs to care about.
|
|
15
|
+
*/
|
|
16
|
+
const POLL_MS = 15_000;
|
|
17
|
+
/** A run that finishes inside this window never gets a progress notice — the settled notice
|
|
18
|
+
* (P0-1) already covers it, and a 45s-or-shorter run does not need a running commentary. */
|
|
19
|
+
const FIRST_NOTICE_DELAY_MS = 45_000;
|
|
20
|
+
/** Floor between two progress notices for the same run, so a chatty harness cannot turn this into
|
|
21
|
+
* a stream of messages. */
|
|
22
|
+
const MIN_NOTICE_GAP_MS = 180_000;
|
|
23
|
+
/** Ceiling on notices for a single run — even a multi-hour run stops narrating after this many. */
|
|
24
|
+
const MAX_NOTICES = 6;
|
|
25
|
+
const NOOP_TAIL = { stop() { } };
|
|
26
|
+
/** Starts polling; returns a handle whose `stop()` is idempotent and always safe to call. */
|
|
27
|
+
export function startExternalProgressTail(input) {
|
|
28
|
+
const harness = getExternalHarness(input.harnessId);
|
|
29
|
+
const toProgressLabel = harness?.toProgressLabel;
|
|
30
|
+
if (!toProgressLabel)
|
|
31
|
+
return NOOP_TAIL; // exec, or a harness that hasn't implemented this.
|
|
32
|
+
const eventsPath = join(input.artifactDir, "events.jsonl");
|
|
33
|
+
let lastLabel;
|
|
34
|
+
let lastNoticeAt = 0;
|
|
35
|
+
let noticeCount = 0;
|
|
36
|
+
let stopped = false;
|
|
37
|
+
const tick = async () => {
|
|
38
|
+
if (stopped || noticeCount >= MAX_NOTICES)
|
|
39
|
+
return;
|
|
40
|
+
const now = Date.now();
|
|
41
|
+
if (now - input.startedAt < FIRST_NOTICE_DELAY_MS)
|
|
42
|
+
return;
|
|
43
|
+
if (lastNoticeAt && now - lastNoticeAt < MIN_NOTICE_GAP_MS)
|
|
44
|
+
return;
|
|
45
|
+
let text;
|
|
46
|
+
try {
|
|
47
|
+
text = await readFile(eventsPath, "utf-8");
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return; // Not written yet, or already cleaned up — try again next tick.
|
|
51
|
+
}
|
|
52
|
+
// Walk from the end: the most recent line that actually maps to a label wins, so a trailing
|
|
53
|
+
// run of unlabeled lines (a text message, a torn final line) does not hide real progress.
|
|
54
|
+
const lines = text.split("\n");
|
|
55
|
+
let label;
|
|
56
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
57
|
+
const line = lines[i]?.trim();
|
|
58
|
+
if (!line)
|
|
59
|
+
continue;
|
|
60
|
+
try {
|
|
61
|
+
label = toProgressLabel(line);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
label = undefined;
|
|
65
|
+
}
|
|
66
|
+
if (label)
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (!label || label === lastLabel || stopped)
|
|
70
|
+
return;
|
|
71
|
+
lastLabel = label;
|
|
72
|
+
lastNoticeAt = now;
|
|
73
|
+
noticeCount++;
|
|
74
|
+
input.onProgress(label);
|
|
75
|
+
};
|
|
76
|
+
const timer = setInterval(() => void tick(), POLL_MS);
|
|
77
|
+
timer.unref?.();
|
|
78
|
+
return {
|
|
79
|
+
stop() {
|
|
80
|
+
stopped = true;
|
|
81
|
+
clearInterval(timer);
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -392,6 +392,7 @@ export async function launchExternalRun(input) {
|
|
|
392
392
|
verifySubjectBefore,
|
|
393
393
|
verifyBaseCommit,
|
|
394
394
|
verifyBaselineUntrackedPaths,
|
|
395
|
+
mutates: input.mutates,
|
|
395
396
|
}, (settleInput, options) => runManager.settle(input.runId, settleInput, options), { announce: terminationReason !== "cancelled" }).catch((error) => {
|
|
396
397
|
log.logWarning(`Failed to settle external run ${input.runId}`, errorMessage(error));
|
|
397
398
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RunHarness, SettleInput } from "../runs.js";
|
|
1
|
+
import type { RunHarness, RunMutates, SettleInput } from "../runs.js";
|
|
2
2
|
import { type ExternalOutcome } from "./harness.js";
|
|
3
3
|
export interface BuildExternalSettleInputInput {
|
|
4
4
|
harnessId: RunHarness;
|
|
@@ -39,6 +39,9 @@ export interface FinalizeExternalRunInput {
|
|
|
39
39
|
/** Fixed verification base and initial untracked manifest, persisted for restart reconciliation. */
|
|
40
40
|
verifyBaseCommit?: string;
|
|
41
41
|
verifyBaselineUntrackedPaths?: string[];
|
|
42
|
+
/** P2-2: only a `write` run's completion pays for a `git status` summary — a `read` run cannot
|
|
43
|
+
* have changed anything, and this must never become a hidden cost on the common read-only path. */
|
|
44
|
+
mutates?: RunMutates;
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
44
47
|
* Read this run's artifact files, parse them through its harness, decide its verdict (including a
|
|
@@ -3,7 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import * as log from "../../log.js";
|
|
4
4
|
import { formatLocalTime } from "../../shared/local-time.js";
|
|
5
5
|
import { errorMessage } from "../../shared/text-utils.js";
|
|
6
|
-
import { workspaceSubjectHash } from "../../tasks/artifact-subject.js";
|
|
6
|
+
import { changedPathsSummary, workspaceSubjectHash } from "../../tasks/artifact-subject.js";
|
|
7
7
|
import { writeVerificationAttestation } from "../../tasks/verification.js";
|
|
8
8
|
import { resolveVerificationOutcome } from "../verification-outcome.js";
|
|
9
9
|
import { classifyExternalOutcome } from "./harness.js";
|
|
@@ -78,7 +78,7 @@ export async function finalizeExternalRun(input, settle, options) {
|
|
|
78
78
|
stderrTail,
|
|
79
79
|
errorMessage: `Unknown harness "${input.harnessId}"; cannot judge this run.`,
|
|
80
80
|
};
|
|
81
|
-
|
|
81
|
+
let settleInput = buildExternalSettleInput({
|
|
82
82
|
harnessId: input.harnessId,
|
|
83
83
|
outcome,
|
|
84
84
|
durationMs: input.durationMs,
|
|
@@ -86,6 +86,13 @@ export async function finalizeExternalRun(input, settle, options) {
|
|
|
86
86
|
terminationReason: input.terminationReason,
|
|
87
87
|
maxWallTimeSec: input.maxWallTimeSec,
|
|
88
88
|
});
|
|
89
|
+
// P2-2: only for a run that actually could have changed the working directory, and only once it
|
|
90
|
+
// is known to have finished cleanly — best-effort, never blocks or fails settlement.
|
|
91
|
+
if (input.mutates === "write" && settleInput.status === "completed") {
|
|
92
|
+
const workspaceSummary = await changedPathsSummary(input.workingDirectory).catch(() => undefined);
|
|
93
|
+
if (workspaceSummary)
|
|
94
|
+
settleInput = { ...settleInput, workspaceSummary };
|
|
95
|
+
}
|
|
89
96
|
const shouldVerify = input.purpose === "verify" &&
|
|
90
97
|
input.taskId !== undefined &&
|
|
91
98
|
input.channelDir !== undefined &&
|
package/dist/subagents/runs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ChannelEvent } from "../
|
|
2
|
-
import type { ChannelStore } from "../
|
|
1
|
+
import type { ChannelEvent } from "../channel/channel-event.js";
|
|
2
|
+
import type { ChannelStore } from "../channel/store.js";
|
|
3
3
|
import { type UsageTotals } from "../shared/types.js";
|
|
4
4
|
import type { UsageLedger } from "../usage/ledger.js";
|
|
5
5
|
/**
|
|
@@ -77,6 +77,9 @@ export interface RunRecord extends RunUsage {
|
|
|
77
77
|
verificationVerdict?: "pass" | "fail";
|
|
78
78
|
/** `enforced` only for a structurally read-only verifier; write-capable/external runs are advisory. */
|
|
79
79
|
verificationStrength?: "enforced" | "advisory";
|
|
80
|
+
/** P2-2: `git status --porcelain` taken right after a `mutates: "write"` run finished, so the
|
|
81
|
+
* wake's reader does not have to spend its own first tool call finding out what changed. */
|
|
82
|
+
workspaceSummary?: string;
|
|
80
83
|
/** Set once settlement (write output, free resources) has happened; guards against replay. */
|
|
81
84
|
settledAt?: number;
|
|
82
85
|
/**
|
|
@@ -169,6 +172,7 @@ interface PendingSettlement {
|
|
|
169
172
|
durationEstimated?: boolean;
|
|
170
173
|
verificationVerdict?: "pass" | "fail";
|
|
171
174
|
verificationStrength?: "enforced" | "advisory";
|
|
175
|
+
workspaceSummary?: string;
|
|
172
176
|
sessionId?: string;
|
|
173
177
|
finishedAt: number;
|
|
174
178
|
announce: boolean;
|
|
@@ -189,13 +193,38 @@ export interface SettleInput {
|
|
|
189
193
|
outputText: string;
|
|
190
194
|
verificationVerdict?: "pass" | "fail";
|
|
191
195
|
verificationStrength?: "enforced" | "advisory";
|
|
196
|
+
/** P2-2: see `RunRecord.workspaceSummary`. */
|
|
197
|
+
workspaceSummary?: string;
|
|
192
198
|
/** The harness's own session/thread id, captured even on failure so a later resume can still use it. */
|
|
193
199
|
sessionId?: string;
|
|
194
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* A best-effort, out-of-band notice about a run — distinct from the completion wake (`dispatch`).
|
|
203
|
+
* The wake is an LLM turn (its delivery latency is whatever the model takes to respond); a notice
|
|
204
|
+
* is plain text rendered straight to the channel, so it reaches the user in roughly the time the
|
|
205
|
+
* run itself takes to settle, not the wake turn's latency on top of that.
|
|
206
|
+
*/
|
|
207
|
+
export interface RunNotice {
|
|
208
|
+
kind: "settled" | "progress";
|
|
209
|
+
runId: string;
|
|
210
|
+
agent: string;
|
|
211
|
+
/** Only set for `kind: "settled"`. */
|
|
212
|
+
status?: RunStatus;
|
|
213
|
+
durationMs: number;
|
|
214
|
+
/** Only set for `kind: "progress"`: the harness's most recently observed step, already short. */
|
|
215
|
+
step?: string;
|
|
216
|
+
}
|
|
217
|
+
export type RunNotifier = (channelId: string, notice: RunNotice) => void | Promise<void>;
|
|
195
218
|
export interface RunManagerOptions {
|
|
196
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* Root of the per-channel record directories (`<stateDir>/<escaped channelId>/`, escaped by
|
|
221
|
+
* `getChannelDir`). Omit to skip persistence.
|
|
222
|
+
*/
|
|
197
223
|
stateDir?: string;
|
|
198
224
|
dispatch?: (event: ChannelEvent) => boolean | Promise<boolean>;
|
|
225
|
+
/** Best-effort out-of-band notice sink (see `RunNotice`). Never awaited by settlement or the
|
|
226
|
+
* progress tail — a slow or failing notifier must not delay either. */
|
|
227
|
+
notify?: RunNotifier;
|
|
199
228
|
ledger?: UsageLedger;
|
|
200
229
|
store?: ChannelStore;
|
|
201
230
|
}
|
|
@@ -219,8 +248,13 @@ export declare class SubAgentRunManager {
|
|
|
219
248
|
/** One-shot deadline checks for external processes adopted during restore. Unlike a child this
|
|
220
249
|
* daemon spawned itself, an adopted process cannot emit a `close` event to this process. */
|
|
221
250
|
private readonly externalRecoveryTimers;
|
|
251
|
+
/** Live external runs' tail-the-artifact-file progress pollers (P1a). Never persisted or
|
|
252
|
+
* reconstructed on restore — an adopted run has no fresher information to poll for than
|
|
253
|
+
* restart reconciliation already reads once from the finished process's own output. */
|
|
254
|
+
private readonly externalProgressTails;
|
|
222
255
|
private readonly queue;
|
|
223
256
|
constructor(channelId: string, options: RunManagerOptions);
|
|
257
|
+
private recordDir;
|
|
224
258
|
private recordPath;
|
|
225
259
|
private persist;
|
|
226
260
|
/**
|
|
@@ -231,6 +265,12 @@ export declare class SubAgentRunManager {
|
|
|
231
265
|
* the artifact is bad, leaving the run stuck in `running` is worse.
|
|
232
266
|
*/
|
|
233
267
|
private writeOutputFile;
|
|
268
|
+
/** Fire-and-forget: a notifier failure must never affect settlement or the progress tail. */
|
|
269
|
+
private emitNotice;
|
|
270
|
+
/** Start tailing a just-launched external run's artifact file for a human-readable step label
|
|
271
|
+
* (P1a). Best-effort only — see `progress-tail.ts` for the polling/pacing contract. */
|
|
272
|
+
private startExternalProgressTail;
|
|
273
|
+
private stopExternalProgressTail;
|
|
234
274
|
private forget;
|
|
235
275
|
get(runId: string): RunRecord | undefined;
|
|
236
276
|
list(): RunRecord[];
|
|
@@ -372,7 +412,8 @@ export declare function channelDelegationTaskIds(channelId: string): Set<string>
|
|
|
372
412
|
/**
|
|
373
413
|
* Re-adopt every channel's persisted runs at startup, settling any internal run still marked
|
|
374
414
|
* `running` as `lost` (D10.3). Channels are discovered from the state directory itself, exactly
|
|
375
|
-
* like `restoreChannelJobs
|
|
415
|
+
* like `restoreChannelJobs` — but by reading the records rather than trusting directory names,
|
|
416
|
+
* so a channel is adopted under the id the rest of the runtime can act on.
|
|
376
417
|
*/
|
|
377
418
|
export declare function restoreAllSubAgentRuns(): Promise<number>;
|
|
378
419
|
export {};
|