pi-better-harness 0.59.2 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +89 -7
- package/extensions/harness-instructions/AGENTS.md +6 -2
- package/extensions/harness-instructions/examples.md +10 -0
- package/extensions/harness-instructions/index.ts +1 -0
- package/extensions/harness-instructions/modules/collaboration.md +1 -0
- package/extensions/harness-instructions/modules/communication.md +1 -0
- package/extensions/harness-instructions/modules/decisions.md +1 -0
- package/extensions/harness-instructions/modules/engineering.md +1 -0
- package/extensions/harness-instructions/modules/ownership.md +1 -0
- package/extensions/harness-instructions/modules/verification.md +1 -0
- package/extensions/recap/index.ts +15 -5
- package/extensions/settings/copy.ts +2 -1
- package/extensions/settings/index.ts +2 -2
- package/extensions/task-context/dynamic-workflow-runtime.ts +7 -7
- package/extensions/task-context/dynamic-workflow-view.ts +11 -1
- package/extensions/task-context/dynamic-workflow.ts +2 -1
- package/lib/cli.mjs +8 -3
- package/lib/install-settings.mjs +1 -0
- package/lib/instructions.mjs +28 -11
- package/lib/prompt-cases.mjs +89 -0
- package/lib/prompt-revisions.mjs +116 -0
- package/lib/prompt-task.mjs +87 -0
- package/lib/prompt-tools.d.mts +2 -0
- package/lib/prompt-tools.mjs +293 -0
- package/lib/prompt-turn.mjs +53 -0
- package/node_modules/pi-better-background-tasks/package.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-arm64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-arm64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-x64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-x64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-arm64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-arm64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-x64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-x64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/src/runtime/work-client.mjs +4 -2
- package/node_modules/pi-better-background-tasks/src/shared-navigator.ts +1 -1
- package/node_modules/pi-better-background-tasks/src/shared-work-client.mjs +4 -2
- package/node_modules/pi-better-subagents/package.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-arm64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-arm64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-x64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-x64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-arm64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-arm64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-x64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-x64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/src/runtime/work-client.mjs +4 -2
- package/node_modules/pi-better-subagents/shared-navigator.ts +1 -1
- package/node_modules/pi-better-subagents/shared-work-client.mjs +4 -2
- package/package.json +7 -5
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const sources = fileURLToPath(new URL("../extensions/harness-instructions/", import.meta.url));
|
|
7
|
+
const digest = value => createHash("sha256").update(value).digest("hex");
|
|
8
|
+
export const begin = "<!-- pi-better-harness:instructions:begin -->";
|
|
9
|
+
export const end = "<!-- pi-better-harness:instructions:end -->";
|
|
10
|
+
|
|
11
|
+
export function render({ template, modules }) {
|
|
12
|
+
const used = new Set();
|
|
13
|
+
const lines = template.trim().split(/\r?\n/).map(line => {
|
|
14
|
+
if (!line.includes("{{") && !line.includes("}}")) return line;
|
|
15
|
+
const id = /^\{\{([a-z][a-z0-9-]*)\}\}$/.exec(line)?.[1];
|
|
16
|
+
if (!id || !Object.hasOwn(modules, id) || used.has(id)) throw Error(`Invalid AGENTS.md template entry: ${line}`);
|
|
17
|
+
used.add(id);
|
|
18
|
+
const text = modules[id].trim().replace(/\r\n/g, "\n");
|
|
19
|
+
if (!text || text.includes(begin) || text.includes(end)) throw Error(`Empty text or reserved marker in modules/${id}.md`);
|
|
20
|
+
return text;
|
|
21
|
+
});
|
|
22
|
+
if (!used.size || used.size !== Object.keys(modules).length || template.includes(begin) || template.includes(end))
|
|
23
|
+
throw Error("Invalid AGENTS.md template or unused modules");
|
|
24
|
+
return lines.join("\n");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function revision(parent, template, modules) {
|
|
28
|
+
const rendered = render({ template, modules });
|
|
29
|
+
return { id: digest(JSON.stringify([parent, template, modules])), parent, template, modules, digest: digest(rendered), rendered };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function bundledRevision(directory = sources) {
|
|
33
|
+
const template = readFileSync(join(directory, "AGENTS.md"), "utf8");
|
|
34
|
+
const modules = Object.fromEntries([...template.matchAll(/^\{\{([a-z][a-z0-9-]*)\}\}\r?$/gm)].map(([, id]) =>
|
|
35
|
+
[id, readFileSync(join(directory, "modules", id + ".md"), "utf8").trim()]));
|
|
36
|
+
return revision(null, template, modules);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function read(path, fallback) {
|
|
40
|
+
try { return JSON.parse(readFileSync(path, "utf8")); }
|
|
41
|
+
catch (e) { if (e.code === "ENOENT" && fallback !== undefined) return fallback; throw e; }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function write(dir, name, value) {
|
|
45
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
46
|
+
const temp = join(dir, randomUUID());
|
|
47
|
+
try {
|
|
48
|
+
writeFileSync(temp, JSON.stringify(value), { flag: "wx", mode: 0o600 });
|
|
49
|
+
renameSync(temp, join(dir, name));
|
|
50
|
+
} finally { rmSync(temp, { force: true }); }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const store = dir => join(dir, "harness-prompt-revisions");
|
|
54
|
+
export const history = dir => read(join(store(dir), "history.json"), []);
|
|
55
|
+
export const activeRevision = dir => {
|
|
56
|
+
const selected = history(dir).at(-1);
|
|
57
|
+
return selected ? readRevision(dir, selected.to) : bundledRevision();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function checkId(id) {
|
|
61
|
+
if (typeof id !== "string" || !/^[a-f0-9]{64}$/.test(id)) throw Error("Expected a revision or evaluation ID from the prompt catalog");
|
|
62
|
+
}
|
|
63
|
+
export function readRevision(dir, id) {
|
|
64
|
+
checkId(id);
|
|
65
|
+
const record = read(join(store(dir), id + ".json"), null);
|
|
66
|
+
if (record) {
|
|
67
|
+
const verified = revision(record.parent, record.template, record.modules);
|
|
68
|
+
if (verified.id !== id || verified.digest !== record.digest || verified.rendered !== record.rendered)
|
|
69
|
+
throw Error(`Corrupt prompt revision ${id}`);
|
|
70
|
+
return verified;
|
|
71
|
+
}
|
|
72
|
+
const bundled = bundledRevision();
|
|
73
|
+
if (bundled.id === id) return bundled;
|
|
74
|
+
throw Error("Unknown prompt revision. Use prompt_list.");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function createCandidate(dir, active, base, module, text) {
|
|
78
|
+
const source = readRevision(dir, base);
|
|
79
|
+
let ancestor = source;
|
|
80
|
+
while (ancestor.id !== active && ancestor.parent) ancestor = readRevision(dir, ancestor.parent);
|
|
81
|
+
if (ancestor.id !== active) throw Error("Stale base. Read the active revision before editing.");
|
|
82
|
+
if (!Object.hasOwn(source.modules, module)) throw Error("Unknown module. Use prompt_list.");
|
|
83
|
+
const next = revision(base, source.template, { ...source.modules, [module]: text.trim() });
|
|
84
|
+
if (source.rendered === next.rendered) throw Error("Edit leaves the module unchanged");
|
|
85
|
+
for (const item of [source, next]) write(store(dir), item.id + ".json", item);
|
|
86
|
+
return { id: next.id, parent: base, module, before: source.modules[module], after: next.modules[module] };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function recordEvaluation(dir, result) {
|
|
90
|
+
const id = digest(JSON.stringify(result));
|
|
91
|
+
write(store(dir), "evaluation-" + id + ".json", result);
|
|
92
|
+
return id;
|
|
93
|
+
}
|
|
94
|
+
export function evaluation(dir, id) {
|
|
95
|
+
checkId(id);
|
|
96
|
+
const record = read(join(store(dir), "evaluation-" + id + ".json"), null);
|
|
97
|
+
if (!record || digest(JSON.stringify(record)) !== id) throw Error("Missing or invalid evaluation. Use prompt_compare.");
|
|
98
|
+
return record;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Called under the APPEND_SYSTEM.md lock. The durable selection precedes sync,
|
|
102
|
+
// so retrying the same transition can finish an interrupted installation.
|
|
103
|
+
export function selectRevision(dir, transition) {
|
|
104
|
+
const log = history(dir);
|
|
105
|
+
const last = log.at(-1);
|
|
106
|
+
if (last && Object.keys(transition).every(key => last[key] === transition[key])) return;
|
|
107
|
+
if (activeRevision(dir).id !== transition.from) throw Error("Active revision changed. Refresh prompt_list.");
|
|
108
|
+
const { from, to, evidence, action } = transition;
|
|
109
|
+
readRevision(dir, to);
|
|
110
|
+
if (action === "promote") {
|
|
111
|
+
const result = evaluation(dir, evidence);
|
|
112
|
+
if (result.active !== from || result.candidate !== to || !result.judgment?.trim() || result.requiresTurnReplay)
|
|
113
|
+
throw Error("Promotion requires a completed comparison for these revisions");
|
|
114
|
+
} else if (action !== "rollback" || !log.some(item => item.from === to)) throw Error("Choose a previously active revision");
|
|
115
|
+
write(store(dir), "history.json", [...log, transition]);
|
|
116
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join, relative, resolve, sep } from "node:path";
|
|
5
|
+
import { replayTurn } from "./prompt-turn.mjs";
|
|
6
|
+
|
|
7
|
+
async function workspaceFiles() {
|
|
8
|
+
const { tsImport } = await import("tsx/esm/api");
|
|
9
|
+
return tsImport("pi-better-subagents/workspace-files.ts", import.meta.url);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function git(root, ...args) {
|
|
13
|
+
return execFileSync("git", ["-C", root, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function checkpoint(cwd, spec) {
|
|
17
|
+
const { snapshotTree, verifyTree } = await workspaceFiles();
|
|
18
|
+
if (!Number.isInteger(spec.turns) || spec.turns < 1 || spec.turns > 64 || !Array.isArray(spec.required) ||
|
|
19
|
+
!Array.isArray(spec.checks) || !spec.checks.length || spec.checks.some(c => typeof c?.equals !== "string"))
|
|
20
|
+
throw Error("A task manifest needs turns (1-64), required paths and file equality checks.");
|
|
21
|
+
const root = realpathSync(cwd);
|
|
22
|
+
const temporary = realpathSync(tmpdir());
|
|
23
|
+
if (temporary === root || temporary.startsWith(root + sep)) throw Error("Task snapshot storage must be outside the source workspace.");
|
|
24
|
+
if (realpathSync(git(root, "rev-parse", "--show-toplevel")) !== root) throw Error("Capture tasks from the repository root.");
|
|
25
|
+
const head = git(root, "rev-parse", "HEAD");
|
|
26
|
+
const store = mkdtempSync(join(tmpdir(), "harness-task-snapshot-"));
|
|
27
|
+
try {
|
|
28
|
+
const omit = new Set([".git", ...(spec.omit ?? [])]);
|
|
29
|
+
const entries = snapshotTree(root, store, omit);
|
|
30
|
+
const paths = new Set(entries.filter(e => e.type === "file").map(e => e.name));
|
|
31
|
+
for (const path of [...spec.required, ...spec.checks.map(c => c.path)]) {
|
|
32
|
+
if (!paths.has(path)) throw Error(`Missing required regular file: ${path}`);
|
|
33
|
+
}
|
|
34
|
+
verifyTree(root, entries, omit);
|
|
35
|
+
if (git(root, "rev-parse", "HEAD") !== head) throw Error("Workspace revision changed during capture.");
|
|
36
|
+
const repo = join(store, "revision.git");
|
|
37
|
+
git(store, "init", "--bare", "--quiet", repo);
|
|
38
|
+
git(repo, "fetch", "--quiet", "--depth=1", "--no-tags", root, head);
|
|
39
|
+
git(repo, "update-ref", "HEAD", head);
|
|
40
|
+
return { head, root, store, entries, spec, dispose: () => rmSync(store, { recursive: true, force: true }) };
|
|
41
|
+
} catch (error) { rmSync(store, { recursive: true, force: true }); throw error; }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export async function taskArm(snapshot, body, laterInputs, generate, budget, signal) {
|
|
45
|
+
const { restoreTree, verifyTree } = await workspaceFiles();
|
|
46
|
+
const root = mkdtempSync(join(tmpdir(), "harness-task-arm-"));
|
|
47
|
+
const files = new Set(snapshot.entries.filter(e => e.type === "file").map(e => e.name));
|
|
48
|
+
const changes = new Map();
|
|
49
|
+
const turns = [];
|
|
50
|
+
let remaining = budget;
|
|
51
|
+
try {
|
|
52
|
+
git(root, "clone", "--no-checkout", "--quiet", join(snapshot.store, "revision.git"), ".");
|
|
53
|
+
const head = git(root, "rev-parse", "HEAD");
|
|
54
|
+
if (head !== snapshot.head) throw Error("Restored revision differs from the task checkpoint.");
|
|
55
|
+
git(root, "read-tree", head);
|
|
56
|
+
restoreTree(root, snapshot.store, snapshot.entries);
|
|
57
|
+
verifyTree(root, snapshot.entries, new Set([".git"]));
|
|
58
|
+
function dispatch(name, args) {
|
|
59
|
+
if (!["read", "write"].includes(name) || typeof args?.path !== "string")
|
|
60
|
+
return { reason: "Unsupported tool in isolated task" };
|
|
61
|
+
const path = relative(snapshot.root, resolve(snapshot.root, args.path));
|
|
62
|
+
if (!files.has(path) || realpathSync(join(root, path)) !== join(realpathSync(root), path) ||
|
|
63
|
+
path.split(sep).includes(".git")) return { reason: "Path outside restored regular files" };
|
|
64
|
+
const dest = join(root, path);
|
|
65
|
+
if (name === "read" && Object.keys(args).every(k => k === "path")) return { content: readFileSync(dest, "utf8") };
|
|
66
|
+
if (name !== "write" || typeof args.content !== "string" || Object.keys(args).some(k => !["path", "content"].includes(k)))
|
|
67
|
+
return { reason: "Unsupported file arguments" };
|
|
68
|
+
if (!changes.has(path)) changes.set(path, readFileSync(dest, "utf8"));
|
|
69
|
+
writeFileSync(dest, args.content);
|
|
70
|
+
return { content: `Wrote ${Buffer.byteLength(args.content)} bytes to ${args.path}` };
|
|
71
|
+
}
|
|
72
|
+
for (const input of [null, ...laterInputs]) {
|
|
73
|
+
if (input) body.messages.push(structuredClone(input));
|
|
74
|
+
const result = await replayTurn(body, { generate, dispatch, budget: remaining, signal });
|
|
75
|
+
remaining -= result.trace.filter(item => Object.hasOwn(item, "assistant")).length;
|
|
76
|
+
turns.push(result);
|
|
77
|
+
if (result.status !== "completed") break;
|
|
78
|
+
}
|
|
79
|
+
const diff = [...changes].map(([path, before]) => ({ path, before, after: readFileSync(join(root, path), "utf8") }))
|
|
80
|
+
.filter(item => item.before !== item.after);
|
|
81
|
+
const checks = snapshot.spec.checks.map(c => {
|
|
82
|
+
const actual = readFileSync(join(root, c.path), "utf8");
|
|
83
|
+
return { ...c, actual, passed: actual === c.equals };
|
|
84
|
+
});
|
|
85
|
+
return { head, budget, turns, status: turns.at(-1).status, diff, checks };
|
|
86
|
+
} finally { rmSync(root, { recursive: true, force: true }); }
|
|
87
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { Type } from "@sinclair/typebox";
|
|
3
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { isDeepStrictEqual } from "node:util";
|
|
6
|
+
import { evaluateCases, inspectSuite, moduleSlot, proposalCases, writingCases } from "./prompt-cases.mjs";
|
|
7
|
+
import { defaultAgentDir } from "./install-settings.mjs";
|
|
8
|
+
import { activatePrompt, promptSource } from "./instructions.mjs";
|
|
9
|
+
import { recordedDispatch, recordedTools, replayTurn } from "./prompt-turn.mjs";
|
|
10
|
+
import { checkpoint, taskArm } from "./prompt-task.mjs";
|
|
11
|
+
import { activeRevision, begin, createCandidate, end, history, readRevision, recordEvaluation } from "./prompt-revisions.mjs";
|
|
12
|
+
|
|
13
|
+
function difference(before, after) {
|
|
14
|
+
const a = before.split("\n");
|
|
15
|
+
const b = after.split("\n");
|
|
16
|
+
let first = 0;
|
|
17
|
+
while (first < a.length && a[first] === b[first]) first++;
|
|
18
|
+
let tail = 0;
|
|
19
|
+
while (tail < Math.min(a.length, b.length) - first && a[a.length - tail - 1] === b[b.length - tail - 1]) tail++;
|
|
20
|
+
return { line: first + 1, removed: a.slice(first, a.length - tail), added: b.slice(first, b.length - tail) };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function swapModule(payload, baseline, candidate) {
|
|
24
|
+
const body = structuredClone(payload);
|
|
25
|
+
const expected = [begin, baseline.rendered, end].join("\n");
|
|
26
|
+
const systems = body.messages.filter(m => ["system", "developer"].includes(m.role) && typeof m.content === "string");
|
|
27
|
+
const matches = systems.filter(m => m.content.replaceAll("\r\n", "\n").includes(expected));
|
|
28
|
+
if (matches.length !== 1) throw Error("The active managed block was shadowed or the captured session loaded a different revision.");
|
|
29
|
+
const message = matches[0];
|
|
30
|
+
const block = message.content.includes(expected) ? expected : expected.replaceAll("\n", "\r\n");
|
|
31
|
+
if (message.content.split(block).length !== 2) throw Error("Ambiguous managed block in the captured input");
|
|
32
|
+
const eol = block.includes("\r\n") ? "\r\n" : "\n";
|
|
33
|
+
message.content = message.content.replace(block, () => [begin, candidate.rendered.replaceAll("\n", eol), end].join(eol));
|
|
34
|
+
return body;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function generate(payload, model, ctx, signal) {
|
|
38
|
+
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
39
|
+
if (!auth.ok) throw Error(auth.error);
|
|
40
|
+
const { default: OpenAI } = await import("openai");
|
|
41
|
+
const client = new OpenAI({ baseURL: model.baseUrl, apiKey: auth.apiKey ?? "unused",
|
|
42
|
+
defaultHeaders: { ...model.headers, ...auth.headers }, maxRetries: 0 });
|
|
43
|
+
const stream = await client.chat.completions.create(payload, { signal });
|
|
44
|
+
let text = "";
|
|
45
|
+
const calls = [];
|
|
46
|
+
let requiresTurnReplay = false;
|
|
47
|
+
let finish;
|
|
48
|
+
for await (const chunk of stream) {
|
|
49
|
+
const choice = chunk.choices?.[0];
|
|
50
|
+
if (!choice) continue;
|
|
51
|
+
text += choice.delta.content ?? "";
|
|
52
|
+
for (const part of choice.delta.tool_calls ?? []) {
|
|
53
|
+
const call = calls[part.index] ??= { id: "", type: "function", function: { name: "", arguments: "" } };
|
|
54
|
+
call.id += part.id ?? "";
|
|
55
|
+
call.function.name += part.function?.name ?? "";
|
|
56
|
+
call.function.arguments += part.function?.arguments ?? "";
|
|
57
|
+
}
|
|
58
|
+
requiresTurnReplay ||= !!(choice.delta.tool_calls?.length || choice.delta.function_call);
|
|
59
|
+
finish = choice.finish_reason ?? finish;
|
|
60
|
+
}
|
|
61
|
+
if (!finish) throw Error("Incomplete response replay");
|
|
62
|
+
return { text, calls, finish, requiresTurnReplay: requiresTurnReplay || ["tool_calls", "function_call"].includes(finish) };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default function registerPromptTools(pi) {
|
|
66
|
+
const dir = defaultAgentDir();
|
|
67
|
+
if (promptSource(dir) !== "modular") return;
|
|
68
|
+
let capture;
|
|
69
|
+
let run;
|
|
70
|
+
let cases = writingCases;
|
|
71
|
+
let comparison;
|
|
72
|
+
let learning = false;
|
|
73
|
+
let proposal;
|
|
74
|
+
let task;
|
|
75
|
+
const string = Type.String({ minLength: 1 });
|
|
76
|
+
const tool = (name, description, fields, execute) => pi.registerTool({
|
|
77
|
+
name, label: name, description, parameters: Type.Object(fields),
|
|
78
|
+
async execute(_call, args, signal, _update, ctx) {
|
|
79
|
+
const details = await execute(args, ctx, signal);
|
|
80
|
+
return { details, content: [{ type: "text", text: JSON.stringify(details) }] };
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
function active() {
|
|
84
|
+
if (promptSource(dir) !== "modular") throw Error("Enable modular Harness instructions and reload.");
|
|
85
|
+
return activeRevision(dir);
|
|
86
|
+
}
|
|
87
|
+
tool("prompt_list", "Inspect modular instructions, selected revision and last captured answer.", {}, (_, ctx) => {
|
|
88
|
+
const current = activeRevision(dir);
|
|
89
|
+
const system = ctx.getSystemPrompt().replaceAll("\r\n", "\n");
|
|
90
|
+
const start = system.indexOf(begin + "\n");
|
|
91
|
+
const finish = system.indexOf("\n" + end, start);
|
|
92
|
+
const loaded = start >= 0 && finish > start ? system.slice(start + begin.length + 1, finish) : undefined;
|
|
93
|
+
return { source: promptSource(dir), active: current.id, modules: Object.keys(current.modules),
|
|
94
|
+
loadedDigest: loaded === undefined ? undefined : createHash("sha256").update(loaded).digest("hex"),
|
|
95
|
+
activeLoaded: loaded === current.rendered,
|
|
96
|
+
history: history(dir), captured: capture?.reference ? capture.id : undefined };
|
|
97
|
+
});
|
|
98
|
+
tool("prompt_read", "Read a module at a specific revision.", { revision: string, module: string }, args => {
|
|
99
|
+
const source = readRevision(dir, args.revision);
|
|
100
|
+
if (!Object.hasOwn(source.modules, args.module)) throw Error("Unknown module. Use prompt_list.");
|
|
101
|
+
return { revision: source.id, text: source.modules[args.module] };
|
|
102
|
+
});
|
|
103
|
+
tool("prompt_edit", "Create a candidate by replacing one module.", { base: string, module: string, text: string },
|
|
104
|
+
args => createCandidate(dir, active().id, args.base, args.module, args.text));
|
|
105
|
+
|
|
106
|
+
pi.registerCommand("prompt-capture", { description: "Keep the next response input in memory for paired replay.",
|
|
107
|
+
handler: async (_, ctx) => {
|
|
108
|
+
if (ctx.model?.api !== "openai-completions") throw Error("Response capture supports openai-completions models.");
|
|
109
|
+
active();
|
|
110
|
+
task?.snapshot.dispose();
|
|
111
|
+
task = undefined;
|
|
112
|
+
capture = { id: randomUUID(), recording: true, records: [] };
|
|
113
|
+
run = undefined;
|
|
114
|
+
ctx.ui.notify(`Capturing the next response for case ${capture.id}.`, "info");
|
|
115
|
+
} });
|
|
116
|
+
pi.registerCommand("prompt-task-capture", { description: "Checkpoint the current workspace before a task and capture its user turns.",
|
|
117
|
+
handler: async (path, ctx) => {
|
|
118
|
+
if (ctx.model?.api !== "openai-completions" || !path.trim()) throw Error("Choose an openai-completions model and a task manifest.");
|
|
119
|
+
const spec = JSON.parse(await readFile(resolve(ctx.cwd, path.trim()), "utf8"));
|
|
120
|
+
const snapshot = await checkpoint(ctx.cwd, spec);
|
|
121
|
+
task?.snapshot.dispose();
|
|
122
|
+
task = { snapshot, inputs: [], next: true };
|
|
123
|
+
capture = { id: randomUUID(), recording: true, records: [] };
|
|
124
|
+
run = undefined;
|
|
125
|
+
ctx.ui.notify(`Checkpointed ${snapshot.head} for ${spec.turns} user turns.`, "info");
|
|
126
|
+
} });
|
|
127
|
+
pi.on("before_provider_request", (event, ctx) => {
|
|
128
|
+
if (task && task.inputs.length < task.snapshot.spec.turns) {
|
|
129
|
+
const { messages, ...settings } = event.payload ?? {};
|
|
130
|
+
if (!Array.isArray(messages)) { task.problem = "Missing task request messages"; return; }
|
|
131
|
+
if (task.next) {
|
|
132
|
+
const input = messages.at(-1);
|
|
133
|
+
if (input?.role !== "user") task.problem = "Missing original user input";
|
|
134
|
+
else task.inputs.push(structuredClone(input));
|
|
135
|
+
if (task.previous && (messages.length !== task.previous.length + 2 || messages.at(-2).role !== "assistant" ||
|
|
136
|
+
!isDeepStrictEqual(messages.slice(0, -2), task.previous))) task.problem = "Task history changed between user turns";
|
|
137
|
+
task.next = false;
|
|
138
|
+
}
|
|
139
|
+
if (task.settings && (!isDeepStrictEqual(settings, task.settings) || ctx.model?.provider !== capture?.model?.provider))
|
|
140
|
+
task.problem = "Task model, provider options or tool definitions changed";
|
|
141
|
+
task.settings = structuredClone(settings);
|
|
142
|
+
task.previous = structuredClone(messages);
|
|
143
|
+
}
|
|
144
|
+
if (!capture?.recording || !Array.isArray(event.payload?.messages)) return;
|
|
145
|
+
if (capture.reference) {
|
|
146
|
+
capture.records = recordedTools(event.payload.messages, capture.payload.messages.length);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
capture.payload = structuredClone(event.payload);
|
|
150
|
+
capture.model = structuredClone(ctx.model);
|
|
151
|
+
});
|
|
152
|
+
pi.on("agent_end", () => { if (capture) capture.recording = false; if (task) task.next = true; });
|
|
153
|
+
pi.on("message_end", event => {
|
|
154
|
+
if (capture?.payload && !capture.reference && event.message.role === "assistant") {
|
|
155
|
+
if (["error", "aborted"].includes(event.message.stopReason)) {
|
|
156
|
+
capture = undefined;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
capture.reference = structuredClone(event.message.content.filter(part => part.type !== "thinking"));
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
pi.on("session_shutdown", () => {
|
|
163
|
+
task?.snapshot.dispose();
|
|
164
|
+
task = undefined;
|
|
165
|
+
capture = undefined;
|
|
166
|
+
run = undefined;
|
|
167
|
+
cases = writingCases;
|
|
168
|
+
comparison = undefined;
|
|
169
|
+
learning = false;
|
|
170
|
+
proposal = undefined;
|
|
171
|
+
});
|
|
172
|
+
tool("prompt_task_replay", "Restore a captured workspace independently for two bounded multi-turn task runs.",
|
|
173
|
+
{ caseId: string, candidate: string, budget: Type.Integer({ minimum: 1, maximum: 64 }) }, async (args, ctx, signal) => {
|
|
174
|
+
if (!task || !capture?.reference || args.caseId !== capture.id || task.inputs.length !== task.snapshot.spec.turns)
|
|
175
|
+
throw Error("Missing task checkpoint or original task inputs.");
|
|
176
|
+
if (task.problem) throw Error(task.problem);
|
|
177
|
+
const baseline = active();
|
|
178
|
+
const candidate = readRevision(dir, args.candidate);
|
|
179
|
+
const { snapshot, inputs } = task;
|
|
180
|
+
const { payload, model } = capture;
|
|
181
|
+
const arm = revision => taskArm(snapshot, swapModule(payload, baseline, revision), inputs.slice(1),
|
|
182
|
+
body => generate(body, model, ctx, signal), args.budget, signal);
|
|
183
|
+
return { caseId: args.caseId, active: baseline.id, candidate: candidate.id, restored: { head: snapshot.head, entries: snapshot.entries },
|
|
184
|
+
inputs, baselineOutput: await arm(baseline), candidateOutput: await arm(candidate) };
|
|
185
|
+
});
|
|
186
|
+
pi.registerCommand("prompt-export", { description: "Review and export the last replay case to a new JSON file.",
|
|
187
|
+
handler: async (path, ctx) => {
|
|
188
|
+
if (!ctx.hasUI || !path.trim() || !capture || !run || run.caseId !== capture.id)
|
|
189
|
+
throw Error("Replay the captured input first, then use /prompt-export <new-file.json> in the UI.");
|
|
190
|
+
const payload = swapModule(capture.payload, readRevision(dir, run.active), { rendered: moduleSlot });
|
|
191
|
+
const draft = { version: 1, cases: [{ id: capture.id, level: "response", provider: run.provider, model: run.model, payload,
|
|
192
|
+
expected: "", counterexample: "", failure: "", rubric: { required: [], forbidden: [] } }] };
|
|
193
|
+
const reviewed = await ctx.ui.editor("Review and redact captured input. Add expected behavior, counterexample and rubric.", JSON.stringify(draft, null, 2));
|
|
194
|
+
if (!reviewed) return;
|
|
195
|
+
inspectSuite(JSON.parse(reviewed));
|
|
196
|
+
await writeFile(resolve(ctx.cwd, path.trim()), reviewed + "\n", { flag: "wx", mode: 0o600 });
|
|
197
|
+
} });
|
|
198
|
+
pi.registerCommand("prompt-import", { description: "Load a reviewed case suite, or use the bundled writing cases with no argument.",
|
|
199
|
+
handler: async (path, ctx) => {
|
|
200
|
+
cases = path.trim() ? inspectSuite(JSON.parse(await readFile(resolve(ctx.cwd, path.trim()), "utf8"))) : writingCases;
|
|
201
|
+
comparison = undefined;
|
|
202
|
+
ctx.ui.notify(`Loaded ${cases.length} prompt cases.`, "info");
|
|
203
|
+
} });
|
|
204
|
+
const evaluate = (selected, candidate, count, ctx, signal) => evaluateCases(selected, active(), candidate, count,
|
|
205
|
+
c => c.model ? ctx.modelRegistry.find(c.provider, c.model) : ctx.model,
|
|
206
|
+
(body, model) => generate(body, model, ctx, signal), signal);
|
|
207
|
+
tool("prompt_evaluate", "Compare revisions on the imported suite or bundled writing cases.",
|
|
208
|
+
{ candidate: Type.Optional(string), samples: Type.Integer({ minimum: 1, maximum: 16 }) }, async (args, ctx, signal) => {
|
|
209
|
+
comparison = await evaluate(cases, args.candidate ? readRevision(dir, args.candidate) : active(), args.samples, ctx, signal);
|
|
210
|
+
return comparison;
|
|
211
|
+
});
|
|
212
|
+
pi.registerCommand("prompt-learning", { description: "Enable case-based proposals for this session (on/off), or discard the pending proposal.",
|
|
213
|
+
handler: async (args, ctx) => {
|
|
214
|
+
if (!["on", "off", "discard"].includes(args.trim())) throw Error("Use /prompt-learning on, off or discard.");
|
|
215
|
+
if (args.trim() !== "discard") learning = args.trim() === "on";
|
|
216
|
+
proposal = undefined;
|
|
217
|
+
ctx.ui.notify(`Case-based proposals ${learning ? "enabled" : "disabled"}. Pending proposal cleared.`, "info");
|
|
218
|
+
} });
|
|
219
|
+
tool("prompt_propose", "Propose one module edit for repeated observed failures and rerun those cases and a counterexample.",
|
|
220
|
+
{ module: string, text: string, failures: Type.Array(string, { minItems: 2 }), counterexample: string },
|
|
221
|
+
async (args, ctx, signal) => {
|
|
222
|
+
if (!learning || !comparison || comparison.active !== active().id)
|
|
223
|
+
throw Error("Enable /prompt-learning on and evaluate the current active revision.");
|
|
224
|
+
const selected = proposalCases(comparison, args.failures, args.counterexample, cases);
|
|
225
|
+
const before = comparison.results.filter(row => selected.some(c => c.id === row.id));
|
|
226
|
+
const edit = createCandidate(dir, comparison.active, comparison.active, args.module, args.text);
|
|
227
|
+
const after = await evaluate(selected, readRevision(dir, edit.id), comparison.sampleCount, ctx, signal);
|
|
228
|
+
proposal = { id: edit.id, edit, before, after, cases: selected, counterexample: args.counterexample };
|
|
229
|
+
return proposal;
|
|
230
|
+
});
|
|
231
|
+
tool("prompt_judge_proposal", "Record a judgment for the pending proposal and produce evidence for explicit promotion.",
|
|
232
|
+
{ candidate: string, judgment: string }, args => {
|
|
233
|
+
if (!learning || !proposal || proposal.id !== args.candidate) throw Error("Unknown or discarded proposal.");
|
|
234
|
+
const result = { ...proposal.after, proposal, judgment: args.judgment };
|
|
235
|
+
if (result.results.some(row => row.status !== "scored" || row.samples.some(s => [s.baseline, s.candidate].some(a => a.status === "inconclusive"))))
|
|
236
|
+
throw Error("Incomplete comparisons cannot authorize promotion. Inspect the proposal results.");
|
|
237
|
+
return { evaluation: recordEvaluation(dir, result), judgment: args.judgment };
|
|
238
|
+
});
|
|
239
|
+
tool("prompt_turn_replay", "Replay a captured user turn using its recorded tool results.",
|
|
240
|
+
{ caseId: string, candidate: string, budget: Type.Integer({ minimum: 1, maximum: 64 }) }, async (args, ctx, signal) => {
|
|
241
|
+
if (!capture?.reference || capture.id !== args.caseId) throw Error("Missing captured turn.");
|
|
242
|
+
const baseline = active();
|
|
243
|
+
const candidate = readRevision(dir, args.candidate);
|
|
244
|
+
const { payload, records, model } = capture;
|
|
245
|
+
const arm = revision => replayTurn(swapModule(payload, baseline, revision), {
|
|
246
|
+
generate: body => generate(body, model, ctx, signal), dispatch: recordedDispatch(records), budget: args.budget, signal });
|
|
247
|
+
return { caseId: args.caseId, active: baseline.id, candidate: candidate.id, baselineOutput: await arm(baseline), candidateOutput: await arm(candidate) };
|
|
248
|
+
});
|
|
249
|
+
tool("prompt_replay", "Generate both arms from a captured writing input. No requested tools are executed.",
|
|
250
|
+
{ caseId: string, candidate: string }, async (args, ctx, signal) => {
|
|
251
|
+
const selected = capture;
|
|
252
|
+
if (!selected?.reference || selected.id !== args.caseId) throw Error("Missing pre-answer input. Run /prompt-capture before the selected answer.");
|
|
253
|
+
const { payload, model } = selected;
|
|
254
|
+
if (model?.api !== "openai-completions" || payload.stream !== true || (payload.n ?? 1) !== 1)
|
|
255
|
+
throw Error("Replay requires a single streamed openai-completions response");
|
|
256
|
+
const baseline = active();
|
|
257
|
+
const candidate = readRevision(dir, args.candidate);
|
|
258
|
+
if (candidate.template !== baseline.template || Object.keys(baseline.modules).filter(k => candidate.modules[k] !== baseline.modules[k]).length !== 1)
|
|
259
|
+
throw Error("Choose a candidate with exactly one changed module.");
|
|
260
|
+
const original = swapModule(payload, baseline, baseline);
|
|
261
|
+
const changed = swapModule(payload, baseline, candidate);
|
|
262
|
+
const baselineOutput = await generate(original, model, ctx, signal);
|
|
263
|
+
const candidateOutput = await generate(changed, model, ctx, signal);
|
|
264
|
+
const { messages, tools, ...settings } = payload;
|
|
265
|
+
run = { id: randomUUID(), caseId: selected.id, active: baseline.id, candidate: candidate.id,
|
|
266
|
+
provider: model.provider, model: model.id, settings, inputDigest: createHash("sha256").update(JSON.stringify(payload)).digest("hex"),
|
|
267
|
+
reference: selected.reference, baselineOutput, candidateOutput,
|
|
268
|
+
difference: difference(baselineOutput.text, candidateOutput.text),
|
|
269
|
+
requiresTurnReplay: baselineOutput.requiresTurnReplay || candidateOutput.requiresTurnReplay };
|
|
270
|
+
return run;
|
|
271
|
+
});
|
|
272
|
+
tool("prompt_compare", "Record the rubric and judgment for a paired replay.",
|
|
273
|
+
{ runId: string, rubric: string, judgment: string }, args => {
|
|
274
|
+
if (!run || run.id !== args.runId) throw Error("Unknown run. Use the ID returned by prompt_replay.");
|
|
275
|
+
const result = { ...run, rubric: args.rubric, judgment: args.judgment };
|
|
276
|
+
return { evaluation: recordEvaluation(dir, result), ...result };
|
|
277
|
+
});
|
|
278
|
+
for (const action of ["promote", "rollback"]) {
|
|
279
|
+
const fields = { from: string, to: string };
|
|
280
|
+
if (action === "promote") fields.evidence = string;
|
|
281
|
+
tool("prompt_" + action, "Request maintainer approval to " + action + " a revision.", fields, async (args, ctx) => {
|
|
282
|
+
const from = readRevision(dir, args.from);
|
|
283
|
+
const to = readRevision(dir, args.to);
|
|
284
|
+
const { removed, added } = difference(from.rendered, to.rendered);
|
|
285
|
+
const changes = [...removed.map(line => "- " + line), ...added.map(line => "+ " + line)];
|
|
286
|
+
const question = [`Change active revision from ${args.from} to ${args.to}?`, "", ...changes].join("\n");
|
|
287
|
+
if (!ctx.hasUI || !await ctx.ui.confirm("Harness prompt " + action, question))
|
|
288
|
+
throw Error("Activation requires explicit maintainer confirmation.");
|
|
289
|
+
activatePrompt(dir, { ...args, action });
|
|
290
|
+
return { active: active().id };
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from "node:util";
|
|
2
|
+
|
|
3
|
+
// Use the provider's representation so images, errors and tool-call IDs survive
|
|
4
|
+
// capture exactly as they reached the next generation.
|
|
5
|
+
export function recordedTools(messages, start) {
|
|
6
|
+
const calls = new Map();
|
|
7
|
+
const records = [];
|
|
8
|
+
for (const message of messages.slice(start)) {
|
|
9
|
+
for (const call of message.tool_calls ?? []) calls.set(call.id, call.function);
|
|
10
|
+
if (message.role !== "tool") continue;
|
|
11
|
+
const call = calls.get(message.tool_call_id);
|
|
12
|
+
if (call) records.push({ name: call.name, args: JSON.parse(call.arguments), content: message.content });
|
|
13
|
+
}
|
|
14
|
+
return records;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export async function replayTurn(body, { generate, dispatch, budget, signal }) {
|
|
18
|
+
const trace = [];
|
|
19
|
+
for (let step = 0; step < budget; step++) {
|
|
20
|
+
if (signal?.aborted) return { status: "cancelled", trace, budget };
|
|
21
|
+
try {
|
|
22
|
+
const answer = await generate(body);
|
|
23
|
+
const calls = answer.calls ?? [];
|
|
24
|
+
trace.push({ assistant: answer.text, calls, finish: answer.finish });
|
|
25
|
+
if (signal?.aborted) return { status: "cancelled", trace, budget };
|
|
26
|
+
body.messages.push({ role: "assistant", content: answer.text || null, ...(calls.length && { tool_calls: calls }) });
|
|
27
|
+
if (!calls.length) return { status: answer.finish === "stop" ? "completed" : "incomplete", trace, budget };
|
|
28
|
+
for (const call of calls) {
|
|
29
|
+
if (signal?.aborted) return { status: "cancelled", trace, budget };
|
|
30
|
+
const name = call.function.name;
|
|
31
|
+
const args = JSON.parse(call.function.arguments);
|
|
32
|
+
const result = await dispatch(name, args);
|
|
33
|
+
trace.push({ name, args, ...result });
|
|
34
|
+
if (!Object.hasOwn(result, "content")) return { status: "diverged", trace, budget };
|
|
35
|
+
body.messages.push({ role: "tool", tool_call_id: call.id, content: result.content });
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return { status: signal?.aborted ? "cancelled" : "error", error: error.message, trace, budget };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { status: "budget", trace, budget };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function recordedDispatch(records) {
|
|
45
|
+
let position = 0;
|
|
46
|
+
return (name, args) => {
|
|
47
|
+
const next = records[position];
|
|
48
|
+
if (!next || name !== next.name || !isDeepStrictEqual(args, next.args))
|
|
49
|
+
return { reason: "No matching recorded result at this step", position, expected: next && { name: next.name, args: next.args } };
|
|
50
|
+
position++;
|
|
51
|
+
return { content: structuredClone(next.content) };
|
|
52
|
+
};
|
|
53
|
+
}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"build":{"format":1,"sourceDigest":"
|
|
1
|
+
{"build":{"format":1,"sourceDigest":"468622110981d6fc9f81e1d90cdd94020cf2bb9f30fe5c233e4d6e33c45f3777","piSdkVersion":"1.7.0","nodeVersion":"24.14.1","platform":"darwin-arm64","dependencyLockDigest":"6becccc0aa89805268794027bb9d0927ceab5ca05bee26a346d0d32e568968de","protocolVersion":1,"serverVersion":"0.9.0","contentId":"6820e2d7b407f67a1486f067100f5b6b6242048ce90a8c9f60f4c31491089f1b"},"sha256":"6671dc91a7d8c7e0190483496ef7f559e87ab9bfd8718ebefd3551e912e210ed"}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"build":{"format":1,"sourceDigest":"
|
|
1
|
+
{"build":{"format":1,"sourceDigest":"468622110981d6fc9f81e1d90cdd94020cf2bb9f30fe5c233e4d6e33c45f3777","piSdkVersion":"1.7.0","nodeVersion":"24.14.1","platform":"darwin-x64","dependencyLockDigest":"6becccc0aa89805268794027bb9d0927ceab5ca05bee26a346d0d32e568968de","protocolVersion":1,"serverVersion":"0.9.0","contentId":"90ae2971fd5ce0a78585ec86680bfbe05a1af56b61a94a0131e08bc4c4035920"},"sha256":"5285ecf21f787e558fb6a90eebfcf89ef7e1460a87fa3b50b7f69e53a8246a75"}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"build":{"format":1,"sourceDigest":"
|
|
1
|
+
{"build":{"format":1,"sourceDigest":"468622110981d6fc9f81e1d90cdd94020cf2bb9f30fe5c233e4d6e33c45f3777","piSdkVersion":"1.7.0","nodeVersion":"24.14.1","platform":"linux-arm64","dependencyLockDigest":"6becccc0aa89805268794027bb9d0927ceab5ca05bee26a346d0d32e568968de","protocolVersion":1,"serverVersion":"0.9.0","contentId":"eddb022db9b1e5fafeee6e2ad4966b2ee64a5cf78a46b687a36d2e81e689614c"},"sha256":"1361084e550334019591f4919ddfccf7ca51c6277b630de461a95af5e267f367"}
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"build":{"format":1,"sourceDigest":"
|
|
1
|
+
{"build":{"format":1,"sourceDigest":"468622110981d6fc9f81e1d90cdd94020cf2bb9f30fe5c233e4d6e33c45f3777","piSdkVersion":"1.7.0","nodeVersion":"24.14.1","platform":"linux-x64","dependencyLockDigest":"6becccc0aa89805268794027bb9d0927ceab5ca05bee26a346d0d32e568968de","protocolVersion":1,"serverVersion":"0.9.0","contentId":"2f9ea1309a479fd2cedb352787f532e0800d16238bb01d749340e65c8b92f366"},"sha256":"ffd2042a919971a9bb8fc670d8d282ea21ad7c18a09996da913e0420a9e0f997"}
|
|
@@ -78,12 +78,14 @@ export class WorkClient {
|
|
|
78
78
|
if (trace) this.lastSubscriptionTrace = trace;
|
|
79
79
|
const id = trace?.id ?? `work-${++this.sequence}`;
|
|
80
80
|
return new Promise((resolve, reject) => {
|
|
81
|
-
|
|
81
|
+
// The host rechecks the caller's grant between workers and replies after batch admission.
|
|
82
|
+
const launch = type === "runtime_launch_subagent";
|
|
83
|
+
const rejectPending = launch ? error => reject(unknownLaunchReceipt(error)) : reject;
|
|
82
84
|
const timer = setTimeout(() => {
|
|
83
85
|
this.pending.delete(id);
|
|
84
86
|
if (trace) trace.timedOutAt = Date.now();
|
|
85
87
|
rejectPending(new Error(`runtime-unhealthy: ${type} timed out${trace ? ` (${trace.id})` : ""}`));
|
|
86
|
-
}, 5000);
|
|
88
|
+
}, launch ? 120_000 : 5000);
|
|
87
89
|
this.pending.set(id, { resolve: value => {
|
|
88
90
|
if (trace) trace.receivedAt = Date.now();
|
|
89
91
|
// Apply subscription receipts in wire order, including events in the same socket chunk.
|
|
@@ -808,7 +808,7 @@ function statusGlyph(row: InternalRow): string {
|
|
|
808
808
|
function statusIndicator(row: InternalRow, now = Date.now()): { glyph: string; color: string } {
|
|
809
809
|
void now;
|
|
810
810
|
if (row.statusTone !== "running") return { glyph: statusGlyph(row), color: toneColor(row.statusTone, row.status) };
|
|
811
|
-
const glyph = row.treeDepth === 1 && row.providerId === "background-tasks" ? ">
|
|
811
|
+
const glyph = row.treeDepth === 1 && row.providerId === "background-tasks" ? ">" : RUNNING_DOT_GLYPH;
|
|
812
812
|
return { glyph, color: "accent" };
|
|
813
813
|
}
|
|
814
814
|
|