@vecteur/cli 0.11.1 → 0.12.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 +28 -45
- package/bin/vecteur.js +29 -100
- package/package.json +3 -3
- package/src/blocks.js +43 -170
- package/src/client.js +38 -264
- package/src/commands.js +7 -44
- package/src/contract.js +19 -60
- package/src/download.js +2 -7
- package/src/exchange.js +6 -5
- package/src/format.js +59 -596
- package/src/localfiles.js +4 -26
- package/src/markdown.js +41 -68
- package/src/mcp.js +30 -75
- package/src/session.js +66 -377
- package/src/stop-words.js +19 -0
- package/src/terminal.js +7 -25
- package/src/tui/view.js +25 -62
- package/src/wire.js +73 -0
- package/src/executor.js +0 -171
- package/src/produce.js +0 -49
package/src/format.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { runBlocks, runArtifacts, artifactRows, blockText } from "./blocks.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
PLAN_WORDS, STOP_ACTION_HREFS, STOP_BINDING_FIELDS, STOP_BINDING_SCOPES, STOP_CAUSES, STOP_FIELDS, STOP_PERIODS,
|
|
5
|
-
STOP_RESULT_KINDS, STOP_WORDS, TERMINAL_FIELDS, TERMINAL_RECOVERY_DECLARATIONS,
|
|
6
|
-
validateArtifact, validateSynthesis,
|
|
7
|
-
} from "./contract.js";
|
|
2
|
+
import { MODEL_CHOICES, PLAN_WORDS, STOP_ACTION_HREFS, TERMINAL_STATES } from "./contract.js";
|
|
3
|
+
import { STOP_WORDS } from "./stop-words.js";
|
|
8
4
|
import { CliError } from "./errors.js";
|
|
9
5
|
|
|
10
6
|
/** Terminal presentation only; exact copy and JSON paths retain the original bytes. */
|
|
@@ -76,526 +72,59 @@ function sortValue(value) {
|
|
|
76
72
|
return value;
|
|
77
73
|
}
|
|
78
74
|
|
|
79
|
-
/**
|
|
80
|
-
* ONE CLASSIFICATION OF THE EVIDENCE A RUN USED, SPOKEN BY THIS DOOR TOO.
|
|
81
|
-
*
|
|
82
|
-
* PRD-UX-16: every load-bearing value in a step's inputs shows its origin — your brief, assumed,
|
|
83
|
-
* derived, your file, catalogue, default — and a value the program attributed to nothing renders
|
|
84
|
-
* an explicit marker, NEVER a blank. PRD-CLI-9: every door sees the same state. The web has said
|
|
85
|
-
* this for a while; this door printed `[3] step_finished` and nothing else, so the same run
|
|
86
|
-
* answered "where did this number come from?" on one surface and stayed silent on the other.
|
|
87
|
-
*
|
|
88
|
-
* The words come from `contract.js`, generated from `frontend/src/run/provenance.ts` — the
|
|
89
|
-
* web's own owner — so the two doors cannot drift into different vocabularies without the
|
|
90
|
-
* contract gate going red.
|
|
91
|
-
*/
|
|
92
|
-
export function originWord(origin) {
|
|
93
|
-
if (!origin || typeof origin !== "object" || typeof origin.kind !== "string") {
|
|
94
|
-
return ORIGIN_WORD.unattributed;
|
|
95
|
-
}
|
|
96
|
-
// A kind the engine invented and this build does not know is NOT silently "unstated": that
|
|
97
|
-
// would report an attribution failure where there is a version skew, and the two read
|
|
98
|
-
// completely differently to whoever is trying to trust the number.
|
|
99
|
-
if (!ORIGIN_KINDS.includes(origin.kind)) return `unknown origin \`${origin.kind}\``;
|
|
100
|
-
return ORIGIN_WORD[origin.kind];
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** `name = value unit (origin word, ref)` — one line per input, in wire order. */
|
|
104
|
-
export function inputLines(inputs) {
|
|
105
|
-
if (!Array.isArray(inputs)) return [];
|
|
106
|
-
return inputs.map((row) => {
|
|
107
|
-
const unit = typeof row?.unit === "string" && row.unit ? ` ${row.unit}` : "";
|
|
108
|
-
const word = originWord(row?.origin);
|
|
109
|
-
// The REF is what makes the word actionable — "your file" is a category, "your file
|
|
110
|
-
// (orbit.csv)" is an answer. It is omitted only when the origin does not carry one.
|
|
111
|
-
const ref = typeof row?.origin?.ref === "string" && row.origin.ref
|
|
112
|
-
? ` ${row.origin.ref}` : "";
|
|
113
|
-
const rendered = `${row?.name ?? "?"} = ${JSON.stringify(row?.value)}${unit} (${word}${ref})`;
|
|
114
|
-
return ` ${plainLine(rendered)}`;
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* ONE ROW PER INTENT, SPOKEN BY THIS DOOR TOO (RunWire v2, CONTRACTS.md S1).
|
|
120
|
-
*
|
|
121
|
-
* The rows are the `step_finished` facts keyed by `step_id`: the finding as the title, the
|
|
122
|
-
* outcome word, the attempt count and the `RESULT:` line the program printed. Tool calls stay
|
|
123
|
-
* folded; this door prints the plan, not the process.
|
|
124
|
-
*/
|
|
125
|
-
/** The budget that closed a partial row (`step_finished.cause`), in the reader's words — the same
|
|
126
|
-
* words the workbench's row meta uses (`StepRow.vue`). */
|
|
127
|
-
const CAUSE_WORD = Object.freeze({
|
|
128
|
-
row_budget: "stopped at its budget", wall_budget: "stopped at the turn's time limit",
|
|
129
|
-
answer_now: "stopped to answer now; what it printed stands",
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* THE ENGINEERING DOOR, SPOKEN BY THIS DOOR TOO (v2.4 S3; the web reads the same bytes in
|
|
134
|
-
* `frontend/src/run/door.ts`, and both readers are held to `tests/fixtures/door-observations.json`).
|
|
135
|
-
*
|
|
136
|
-
* A `python` call whose summary is `run <verb>` is a call of one published engineering method;
|
|
137
|
-
* its result's stdout is the bounded observation `laplace_ope/door_tail.py` prints. The reader is
|
|
138
|
-
* tolerant: the excerpt keeps a long stream's first and last lines around `[…]`, so every section
|
|
139
|
-
* is optional and the last `RESULT:` line is the headline of last resort.
|
|
140
|
-
*/
|
|
141
|
-
const DOOR_SUMMARY = /^run ([a-z][a-z0-9]*(?:_[a-z0-9]+)+)$/;
|
|
142
|
-
const DOOR_HEAD = /^([a-z][a-z0-9_]*): ok\b/;
|
|
143
|
-
const QUANTITY_LINE = /^ {2}(\S+) = (.*?)(?: {2}-- (.*))?$/;
|
|
144
|
-
const SECTION_OPEN = /^(inputs \(as given\):|inputs the owner defaulted|not set \(|quantities:|validity:|warnings:|files:|RESULT:)/;
|
|
145
|
-
const NUMBER = /^(-?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?|true|false|nan|-?inf)(?: (.+))?$/;
|
|
146
|
-
|
|
147
|
-
function quantityParts(text) {
|
|
148
|
-
const trimmed = text.trim();
|
|
149
|
-
if (trimmed.startsWith("[") || trimmed.startsWith("{")) return { value: trimmed, unit: "" };
|
|
150
|
-
const number = NUMBER.exec(trimmed);
|
|
151
|
-
return number ? { value: number[1], unit: (number[2] ?? "").trim() } : { value: trimmed, unit: "" };
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/** `{verb, headline: [{id, label, value, unit}], warnings}` of an observation, or null. */
|
|
155
|
-
export function doorObservation(text) {
|
|
156
|
-
const lines = String(text ?? "").split("\n").map(line => line.replace(/\s+$/, ""));
|
|
157
|
-
const head = DOOR_HEAD.exec(lines.find(line => line.trim()) ?? "");
|
|
158
|
-
if (!head) return null;
|
|
159
|
-
const cut = new Set();
|
|
160
|
-
lines.forEach((line, index) => {
|
|
161
|
-
if (line.trim() === "[…]") [index - 1, index, index + 1].forEach(n => cut.add(n));
|
|
162
|
-
});
|
|
163
|
-
const quantities = [];
|
|
164
|
-
const warnings = [];
|
|
165
|
-
let resultLine = "";
|
|
166
|
-
let section = "";
|
|
167
|
-
for (const [index, line] of lines.entries()) {
|
|
168
|
-
if (index === 0 || cut.has(index)) continue;
|
|
169
|
-
const open = SECTION_OPEN.exec(line);
|
|
170
|
-
if (open) {
|
|
171
|
-
section = open[1];
|
|
172
|
-
if (section === "warnings:" && line.includes("none")) section = "";
|
|
173
|
-
if (section === "RESULT:") resultLine = line.slice("RESULT:".length).trim();
|
|
174
|
-
continue;
|
|
175
|
-
}
|
|
176
|
-
if (section === "quantities:") {
|
|
177
|
-
const row = QUANTITY_LINE.exec(line);
|
|
178
|
-
if (row) quantities.push({ id: row[1], label: row[3]?.trim() || row[1].replaceAll("_", " "), ...quantityParts(row[2]) });
|
|
179
|
-
} else if (section === "warnings:" && /^ {2}- /.test(line)) {
|
|
180
|
-
warnings.push(line.replace(/^ {2}- /, "").trim());
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
const byId = new Map(quantities.map(quantity => [quantity.id, quantity]));
|
|
184
|
-
const headline = [];
|
|
185
|
-
for (const part of resultLine.split(/; (?=\S+ = )/)) {
|
|
186
|
-
const row = /^(\S+) = (.*)$/.exec(part.trim());
|
|
187
|
-
if (!row) continue;
|
|
188
|
-
headline.push({ id: row[1], label: byId.get(row[1])?.label ?? row[1].replaceAll("_", " "), ...quantityParts(row[2]) });
|
|
189
|
-
}
|
|
190
|
-
// No parsable RESULT line: the last three physical quantities stand in (else the first three).
|
|
191
|
-
if (!headline.length) headline.push(...quantities.filter(quantity => quantity.unit).slice(-3));
|
|
192
|
-
if (!headline.length) headline.push(...quantities.slice(0, 3));
|
|
193
|
-
return { verb: head[1], headline, warnings };
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/** One qualification for both engineering rows and tool blocks; successful stdout must confirm the verb. */
|
|
197
|
-
export function engineeringCall(call, result) {
|
|
198
|
-
const verb = call?.tool === "python" ? DOOR_SUMMARY.exec(String(call.summary ?? "").trim())?.[1] : null;
|
|
199
|
-
if (!verb) return null;
|
|
200
|
-
const observation = result?.status === "ok" ? doorObservation(result.stdout_excerpt) : null;
|
|
201
|
-
if (result?.status === "ok" && observation?.verb !== verb) return null;
|
|
202
|
-
const refusal = result && result.status !== "ok"
|
|
203
|
-
? String(result.stderr_excerpt || result.stdout_excerpt || "").trim().split("\n").filter(Boolean).slice(-3).join(" · ") : "";
|
|
204
|
-
return { purpose: String(call.title ?? "").trim(), verb, observation, refusal, running: !result };
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
function doorCallsByStep(events) {
|
|
208
|
-
const results = new Map();
|
|
209
|
-
for (const event of events) {
|
|
210
|
-
if (event?.kind === "tool_result" && typeof event.payload?.call_id === "string") {
|
|
211
|
-
results.set(event.payload.call_id, event.payload);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
const rows = new Map();
|
|
215
|
-
for (const event of events) {
|
|
216
|
-
const call = event?.kind === "tool_call" ? event.payload : null;
|
|
217
|
-
const door = engineeringCall(call, results.get(call?.call_id));
|
|
218
|
-
if (!door) continue;
|
|
219
|
-
const list = rows.get(call.step_id) ?? [];
|
|
220
|
-
list.push(door);
|
|
221
|
-
rows.set(call.step_id, list);
|
|
222
|
-
}
|
|
223
|
-
return rows;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function doorLine({ purpose, verb, observation, refusal, running }) {
|
|
227
|
-
const said = observation
|
|
228
|
-
? observation.headline.map(quantity => `${quantity.label} ${quantity.value}${quantity.unit ? ` ${quantity.unit}` : ""}`).join(", ")
|
|
229
|
-
: (refusal ? `refused: ${refusal}` : running ? "running" : "computed");
|
|
230
|
-
const lines = [` ▸ ${plainLine(purpose || verb)} — ${verb}: ${plainLine(said)}`];
|
|
231
|
-
for (const warning of (observation?.warnings ?? []).slice(0, 2)) lines.push(` ! ${plainLine(warning)}`);
|
|
232
|
-
return lines.join("\n");
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/** v5x (SPEC-r5 §3.3): the reader's word for a root capability family (`web`: the internet; `kc`: the customer's documents). */
|
|
236
|
-
const CAPABILITY_LABELS = Object.freeze({ web: "Web", kc: "Documents" });
|
|
237
|
-
|
|
238
|
-
/** A well-formed root `capability_tool` call as `{ label, name }` ("Web", "web_search"); null for any other call or a malformed one. */
|
|
239
|
-
export function capabilityCall(call) {
|
|
240
|
-
if (call?.tool !== "capability_tool") return null;
|
|
241
|
-
if (typeof call.family !== "string" || !Object.hasOwn(CAPABILITY_LABELS, call.family) || !isIdentifier(call.name)) return null;
|
|
242
|
-
return { label: CAPABILITY_LABELS[call.family], name: call.name };
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/** The owner's identifier shape (`laplace_ope.wire._identity`): a non-empty string of at most 200 Unicode CODE POINTS,
|
|
246
|
-
* with no leading or trailing character Python's `str.strip()` removes. That set is every code point with
|
|
247
|
-
* `str.isspace()` true, enumerated from CPython 3.12 (29 code points: U+0009-000D, U+001C-001F, U+0020, U+0085, U+00A0,
|
|
248
|
-
* U+1680, U+2000-200A, U+2028, U+2029, U+202F, U+205F, U+3000); U+FEFF and U+180E are NOT in it. */
|
|
249
|
-
const PY_SPACE = /^[\t\n\v\f\r\x1c-\x1f \x85\xa0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]|[\t\n\v\f\r\x1c-\x1f \x85\xa0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]$/u;
|
|
250
|
-
function isIdentifier(value) {
|
|
251
|
-
return typeof value === "string" && value.length > 0 && [...value].length <= 200 && !PY_SPACE.test(value);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/** RunWire v4 (A8): a specialist family call (`specialist_tool`) folds under its own child row, by `step_id`;
|
|
255
|
-
* v5x: a root capability call folds under its root row the same way, named "Web web_search". */
|
|
256
|
-
function specialistCallsByStep(events) {
|
|
257
|
-
const rows = new Map();
|
|
258
|
-
for (const event of events) {
|
|
259
|
-
const call = event?.kind === "tool_call" ? event.payload : null;
|
|
260
|
-
const capability = capabilityCall(call);
|
|
261
|
-
const name = capability ? `${capability.label} ${capability.name}`
|
|
262
|
-
: call?.tool === "specialist_tool" && typeof call.specialist_tool === "string" ? call.specialist_tool : null;
|
|
263
|
-
if (name !== null) rows.set(call.step_id, [...(rows.get(call.step_id) ?? []), name]);
|
|
264
|
-
}
|
|
265
|
-
return rows;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function specialistCallsLine(tools) {
|
|
269
|
-
const counts = new Map();
|
|
270
|
-
for (const tool of tools) counts.set(tool, (counts.get(tool) ?? 0) + 1);
|
|
271
|
-
return `tools: ${[...counts].map(([tool, n]) => plainLine(n > 1 ? `${tool} ×${n}` : tool)).join(", ")}`;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* A RunWire v3 child row (v5 §4.2) prints under its delegating row with the agent's label
|
|
276
|
-
* from the owner vocabulary; a main row (no `agent`) prints exactly as it always has.
|
|
277
|
-
*/
|
|
278
|
-
function childLabel(row) {
|
|
279
|
-
return typeof row?.agent === "string" && Object.hasOwn(AGENT_LABELS, row.agent)
|
|
280
|
-
? `[${AGENT_LABELS[row.agent]}] ` : "";
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export function taskLines(events, { facts = false } = {}) {
|
|
284
|
-
const entries = mainTaskLines(events);
|
|
285
|
-
if (facts) for (const entry of entries) {
|
|
286
|
-
const row = entry.row;
|
|
287
|
-
const missing = [row.status, row.cause, row.result_line].filter(value =>
|
|
288
|
-
typeof value === "string" && value && !entry.line.includes(plainLine(value)));
|
|
289
|
-
if (missing.length) entry.line += `\n ${missing.map(plainLine).join(" · ")}`;
|
|
290
|
-
}
|
|
291
|
-
const nested = (line, row) => line.split("\n").map((part, index) =>
|
|
292
|
-
index === 0 ? ` ↳ ${childLabel(row)}${part.trimStart()}` : ` ${part}`).join("\n");
|
|
293
|
-
const children = entries.filter(({ row }) => childLabel(row));
|
|
294
|
-
const placed = new Set();
|
|
295
|
-
const lines = [];
|
|
296
|
-
for (const entry of entries) {
|
|
297
|
-
if (childLabel(entry.row)) continue;
|
|
298
|
-
lines.push(entry.line);
|
|
299
|
-
for (const child of children) {
|
|
300
|
-
if (child.row.parent_step_id === entry.row.step_id) { lines.push(nested(child.line, child.row)); placed.add(child); }
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
// A child whose delegating row is still open prints last, still labelled and nested.
|
|
304
|
-
for (const child of children) if (!placed.has(child)) lines.push(nested(child.line, child.row));
|
|
305
|
-
return lines;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
function mainTaskLines(events) {
|
|
309
|
-
const doors = doorCallsByStep(events);
|
|
310
|
-
// The conclusion is engineering work (it prints the answer from evidence); its text is the
|
|
311
|
-
// synthesis, so the row stays one line.
|
|
312
|
-
const concluded = new Set(events.filter((event) => event?.kind === "tool_call" && event.payload?.tool === "conclude")
|
|
313
|
-
.map((event) => event.payload.step_id));
|
|
314
|
-
// Only a run that called the door tells engineering rows from execution rows; any other run
|
|
315
|
-
// prints exactly as before.
|
|
316
|
-
const distinguishes = doors.size > 0 || concluded.size > 0;
|
|
317
|
-
const specialist = specialistCallsByStep(events);
|
|
318
|
-
return events.flatMap((event) => {
|
|
319
|
-
if (event?.kind !== "step_finished") return [];
|
|
320
|
-
const calls = specialist.get(event.payload?.step_id);
|
|
321
|
-
return rowLines(event).map(line => ({ line: calls ? `${line}\n ${specialistCallsLine(calls)}` : line, row: event.payload }));
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
function rowLines(event) {
|
|
325
|
-
const row = event.payload;
|
|
326
|
-
if (!row || typeof row !== "object" || typeof row.step_id !== "string") return [];
|
|
327
|
-
const outcome = CAUSE_WORD[row.cause] ?? row.status;
|
|
328
|
-
const result = typeof row.result_line === "string" && row.result_line.trim() ? row.result_line : "";
|
|
329
|
-
if (distinguishes) {
|
|
330
|
-
const calls = doors.get(row.step_id);
|
|
331
|
-
if (calls?.length) {
|
|
332
|
-
const rest = row.status === "computed" ? [] : [` (${plainLine(row.title)} — ${outcome})`];
|
|
333
|
-
return [[...calls.map(doorLine), ...rest].join("\n")];
|
|
334
|
-
}
|
|
335
|
-
if (row.status === "asked" || concluded.has(row.step_id)) return [` ▸ ${plainLine(`${row.title} — ${outcome}`)}`];
|
|
336
|
-
// Execution, compressed to one line: what ran, how it ended, what it printed.
|
|
337
|
-
return [` · ${plainLine(`${row.title} — ${outcome}${result ? `: ${result}` : ""}`)}`];
|
|
338
|
-
}
|
|
339
|
-
const attempts = Number.isInteger(row.attempts) && row.attempts > 0
|
|
340
|
-
? ` · ${row.attempts} ${row.attempts === 1 ? "attempt" : "attempts"}` : "";
|
|
341
|
-
const printed = result ? `\n ${plainLine(result)}` : "";
|
|
342
|
-
return [` ${plainLine(`${row.title} — ${outcome}${attempts}`)}${printed}`];
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* SOURCES › ASSUMPTIONS, SPOKEN BY THIS DOOR TOO (RunWire v2 `input_rows`, CONTRACTS S1).
|
|
348
|
-
*
|
|
349
|
-
* One block per owner verb the turn's programs called, the LAST ledger event of the run
|
|
350
|
-
* standing: what the customer stated (`your brief`), what the program assumed, what the
|
|
351
|
-
* method's declared default was let stand, and how many arguments the program set from a
|
|
352
|
-
* variable (no value the record can read). Rows print through `inputLines`, the same shape
|
|
353
|
-
* as the legacy step inputs, so the origin words are the contract's.
|
|
354
|
-
*/
|
|
355
|
-
export function assumptionLines(events) {
|
|
356
|
-
const ledger = events.filter((event) => event?.kind === "input_rows").at(-1);
|
|
357
|
-
const blocks = Array.isArray(ledger?.payload?.blocks) ? ledger.payload.blocks : [];
|
|
358
|
-
return blocks.flatMap((block) => {
|
|
359
|
-
if (!block || typeof block.verb !== "string") return [];
|
|
360
|
-
const set = Number.isInteger(block.program_set) && block.program_set > 0
|
|
361
|
-
? ` · ${block.program_set} set by the program` : "";
|
|
362
|
-
const rows = Array.isArray(block.rows) ? block.rows : [];
|
|
363
|
-
return [` ${plainLine(block.verb)}${set}`, ...inputLines(rows)];
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
75
|
export function shellQuote(value) {
|
|
368
76
|
return `'${String(value).replaceAll("'", `'"'"'`)}'`;
|
|
369
77
|
}
|
|
370
78
|
|
|
371
79
|
export function safeArtifactName(artifact) {
|
|
372
|
-
const leaf = artifact.
|
|
80
|
+
const leaf = artifact.path.replaceAll("\\", "/").split("/").at(-1);
|
|
373
81
|
if (!leaf || leaf === "." || leaf === ".." || leaf.startsWith("-") || leaf.startsWith(".")) {
|
|
374
82
|
return `artifact-${artifact.cas_ref.slice("sha256:".length, "sha256:".length + 12)}`;
|
|
375
83
|
}
|
|
376
84
|
return leaf;
|
|
377
85
|
}
|
|
378
86
|
|
|
87
|
+
/** The closed turn: its state, its typed defect and its answer (the last `synthesis`). An unknown state is refused by name. */
|
|
379
88
|
function terminalPresentation(value) {
|
|
380
|
-
const
|
|
381
|
-
if (
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
if (
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
if (payload.answer !== undefined
|
|
407
|
-
&& (!synthesis || payload.answer !== synthesis.answer)) {
|
|
408
|
-
throw new CliError("synthesis_invalid", "Run terminal answer differs from its synthesis");
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
const defect = payload.defect;
|
|
412
|
-
const recovery = payload.recovery;
|
|
413
|
-
if (!["ok", "partial"].includes(state) && defect === undefined) {
|
|
414
|
-
throw new CliError("recovery_invalid", `Run terminal ${state} carries no typed cause/recovery`);
|
|
415
|
-
}
|
|
416
|
-
if ((defect === undefined) !== (recovery === undefined)) {
|
|
417
|
-
throw new CliError("recovery_invalid", "Run terminal cause and recovery must travel together");
|
|
418
|
-
}
|
|
419
|
-
if (defect !== undefined) {
|
|
420
|
-
const declarations = TERMINAL_RECOVERY_DECLARATIONS[defect];
|
|
421
|
-
if (!declarations || !Array.isArray(recovery) || recovery.length === 0) {
|
|
422
|
-
throw new CliError("recovery_invalid", "Run terminal recovery is not owner-declared");
|
|
423
|
-
}
|
|
424
|
-
for (const action of recovery) {
|
|
425
|
-
const fields = action && typeof action === "object" && !Array.isArray(action)
|
|
426
|
-
? Object.keys(action).sort().join(",") : "";
|
|
427
|
-
const declaration = declarations.find(([capability]) => capability === action?.capability);
|
|
428
|
-
const argumentsValue = action?.arguments;
|
|
429
|
-
if (fields !== "arguments,capability" || !declaration || !argumentsValue
|
|
430
|
-
|| typeof argumentsValue !== "object" || Array.isArray(argumentsValue)
|
|
431
|
-
|| Object.keys(argumentsValue).sort().join(",") !== [...declaration[1]].sort().join(",")
|
|
432
|
-
|| Object.values(argumentsValue).some(item => !(
|
|
433
|
-
(typeof item === "string" && item.length > 0)
|
|
434
|
-
|| (Number.isSafeInteger(item) && item > 0)
|
|
435
|
-
))) {
|
|
436
|
-
throw new CliError("recovery_invalid", "Run terminal recovery action is malformed");
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return { state, answer: payload.answer, defect, recovery: recovery ?? [], capacity: payload.capacity };
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/** `study_capacity` names its scope in the resource prefix (the frontend `run/terminal-note.ts` holds the same two sentences). */
|
|
444
|
-
const STUDY_CAPACITY_WORDS = {
|
|
445
|
-
study_: "This study cannot grow further in this project; its results stay readable and downloadable.",
|
|
446
|
-
run_: "This run reached its working limit; start a new run to continue.",
|
|
447
|
-
};
|
|
448
|
-
function capacityLine(defect, capacity) {
|
|
449
|
-
const resource = typeof capacity?.resource === "string" ? capacity.resource : "";
|
|
450
|
-
const prefix = Object.keys(STUDY_CAPACITY_WORDS).find(candidate => resource.startsWith(candidate));
|
|
451
|
-
return defect === "study_capacity" && prefix ? [STUDY_CAPACITY_WORDS[prefix]] : [];
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/** The stop's words and rule: `frontend/src/run/stop.ts` holds the same one over the same generated heads. */
|
|
455
|
-
const squeeze = text => String(text).split(/\s+/).filter(Boolean).join(" ");
|
|
456
|
-
function historicalResult(defect, state, answer, events) {
|
|
457
|
-
if (!answer) return "none";
|
|
458
|
-
const heads = HISTORICAL_STOP_HEADS[defect] ?? [];
|
|
459
|
-
const [head, ...bullets] = answer.split("\n");
|
|
460
|
-
if (!heads.includes(head) || !bullets.length || bullets.some(line => !line.startsWith("- "))) return "authored";
|
|
461
|
-
// A draft the record shows the model released first is the model's, whatever it quotes.
|
|
462
|
-
if (events.some(event => event.kind === "assistant_delta" && event.payload?.step !== null
|
|
463
|
-
&& String(event.payload?.text).startsWith(head))) return "authored";
|
|
464
|
-
if (state !== "partial") return "unproven";
|
|
465
|
-
const printed = new Set(events.filter(event => event.kind === "tool_result" && event.payload?.status === "ok"
|
|
466
|
-
&& typeof event.payload?.stdout_excerpt === "string").flatMap(event => event.payload.stdout_excerpt.split("\n").map(squeeze)));
|
|
467
|
-
const proven = bullet => {
|
|
468
|
-
const words = bullet.slice(2);
|
|
469
|
-
for (let at = words.indexOf(": "); at >= 0; at = words.indexOf(": ", at + 1)) {
|
|
470
|
-
const found = words.slice(at + 2);
|
|
471
|
-
if (printed.has(found) || printed.has(`RESULT: ${found}`)) return true;
|
|
472
|
-
}
|
|
473
|
-
return false;
|
|
474
|
-
};
|
|
475
|
-
return bullets.every(proven) ? "summary" : "unproven";
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
function isRunStop(stop) {
|
|
479
|
-
const sameFields = (value, names) => !!value && typeof value === "object" && !Array.isArray(value)
|
|
480
|
-
&& Object.keys(value).length === names.length && names.every(name => Object.hasOwn(value, name));
|
|
481
|
-
if (!sameFields(stop, STOP_FIELDS) || !STOP_CAUSES.includes(stop.cause) || !STOP_RESULT_KINDS.includes(stop.result_kind)
|
|
482
|
-
|| typeof stop.source_run !== "string" || !stop.source_run
|
|
483
|
-
|| !(stop.parent_state_hash === null || /^[0-9a-f]{64}$/.test(stop.parent_state_hash))) return false;
|
|
484
|
-
if (stop.binding === null) return stop.renews_at === null;
|
|
485
|
-
return stop.cause === "plan_limit" && sameFields(stop.binding, STOP_BINDING_FIELDS)
|
|
486
|
-
&& STOP_BINDING_SCOPES.includes(stop.binding.scope) && STOP_PERIODS.includes(stop.binding.period)
|
|
487
|
-
&& [null, "free", "pro", "enterprise"].includes(stop.binding.tier)
|
|
488
|
-
&& Number.isSafeInteger(stop.renews_at) && stop.renews_at > 0;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
/** What an old record's cause alone proves; a `provider_budget_exhausted` could have been the plan or the upstream. */
|
|
492
|
-
const HISTORICAL_CAUSE = { budget_exhausted: "run_limit", max_tokens: "output_limit", provider_route_exhausted: "route_failure" };
|
|
493
|
-
|
|
494
|
-
export function stopViewOf(events) {
|
|
495
|
-
const terminal = events.at(-1);
|
|
496
|
-
if (terminal?.kind !== "terminal") return null;
|
|
497
|
-
const payload = terminal.payload ?? {};
|
|
498
|
-
if (!HORIZON_STOP_DEFECTS.includes(payload.defect) || !["partial", "blocked"].includes(payload.state)) return null;
|
|
499
|
-
if ("stop" in payload && !isRunStop(payload.stop)) throw new CliError("terminal_invalid", "Run terminal stop is not the closed record");
|
|
500
|
-
const programs = new Set(events.filter(event => event.kind === "tool_call" && ["python", "replay"].includes(event.payload?.tool))
|
|
501
|
-
.map(event => event.payload.call_id));
|
|
502
|
-
const results = events.filter(event => event.kind === "tool_result" && programs.has(event.payload?.call_id));
|
|
503
|
-
const counts = {
|
|
504
|
-
computed: results.filter(event => event.payload.status === "ok").length,
|
|
505
|
-
failed: results.filter(event => event.payload.status !== "ok").length,
|
|
506
|
-
readOnly: events.filter(event => event.kind === "step_finished" && event.payload?.status === "read").length,
|
|
507
|
-
};
|
|
508
|
-
const stop = payload.stop;
|
|
509
|
-
if (stop) return { typed: true, cause: stop.cause, binding: stop.binding, renewsAt: stop.renews_at, result: stop.result_kind, defect: payload.defect, ...counts };
|
|
510
|
-
return { typed: false, cause: HISTORICAL_CAUSE[payload.defect] ?? null, binding: null, renewsAt: null, defect: payload.defect,
|
|
511
|
-
result: historicalResult(payload.defect, payload.state, typeof payload.answer === "string" ? payload.answer : "", events), ...counts };
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
const fillWords = (template, values) => template.replace(/\{(\w+)\}/g, (_, name) => values[name] ?? "");
|
|
515
|
-
const WEEKDAY = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
516
|
-
const MONTH = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
517
|
-
function renewalDate(at) {
|
|
518
|
-
const date = new Date(at * 1000);
|
|
519
|
-
return `${WEEKDAY[date.getUTCDay()]} ${date.getUTCDate()} ${MONTH[date.getUTCMonth()]}`;
|
|
520
|
-
}
|
|
521
|
-
const PLAN_NAME = { free: "Free", pro: "Pro", enterprise: "Enterprise" };
|
|
522
|
-
|
|
523
|
-
/** The stop block: no code, no plumbing. `offer` is the server's answer for this reader; without it no plan is named. */
|
|
524
|
-
function stopLines(view, value, offer, origin = "") {
|
|
525
|
-
const model = MODEL_CATALOGUE.find(profile => profile.profile_id === value.profile)?.label ?? "The model";
|
|
526
|
-
const plan = view.binding?.tier ? PLAN_NAME[view.binding.tier] : "";
|
|
527
|
-
const period = view.binding?.period === "utc_month" ? "month" : "week";
|
|
528
|
-
const key = view.cause === null || view.cause === "plan_limit"
|
|
529
|
-
? (!view.binding ? "limit" : view.binding.scope === "platform" ? "plan_platform" : "plan_restriction") : view.cause;
|
|
530
|
-
const words = { model, plan, period };
|
|
531
|
-
const result = view.result === "authored" ? STOP_WORDS.result.authored
|
|
532
|
-
: view.computed ? STOP_WORDS.result.computed : STOP_WORDS.result.nothing;
|
|
533
|
-
const lines = [fillWords(STOP_WORDS.heading[key], words),
|
|
534
|
-
`${fillWords(STOP_WORDS.reason[key], words)} ${fillWords(result, words)}`];
|
|
535
|
-
const proSteps = EXECUTION_HORIZONS.find(row => row.tier === "pro")?.max_steps;
|
|
89
|
+
const last = value.events.at(-1);
|
|
90
|
+
if (last?.kind !== "terminal") throw new CliError("terminal_invalid", "Run record has no final terminal event");
|
|
91
|
+
const state = last.payload?.state;
|
|
92
|
+
if (!TERMINAL_STATES.includes(state)) {
|
|
93
|
+
throw new CliError("terminal_state_unknown", `Run ended in a state this CLI does not know (${plainLine(state).slice(0, 40)}); next: vecteur update`);
|
|
94
|
+
}
|
|
95
|
+
if (state !== value.terminal) throw new CliError("terminal_mismatch", "Run terminal event disagrees with its record");
|
|
96
|
+
return { state, defect: last.payload.defect, answer: value.events.findLast(event => event.kind === "synthesis")?.payload.markdown };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** A template with every `{name}` filled, or null when one is not: a half-filled sentence is never printed. */
|
|
100
|
+
function fillWords(template, values) {
|
|
101
|
+
let missing = false;
|
|
102
|
+
const said = template.replace(/\{(\w+)\}/g, (_, name) => { if (values[name] === undefined) missing = true; return values[name] ?? ""; });
|
|
103
|
+
return missing ? null : said;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The stop card of a `budget` terminal. The wire carries no stop object: the words are the generic limit's
|
|
107
|
+
* (`stop-words.js`), and what this reader may do about it is the server's offer; without it no plan is named. */
|
|
108
|
+
function stopLines(value, terminal, offer, origin = "") {
|
|
109
|
+
const choice = MODEL_CHOICES.find(row => row.route_id === value.requested_route_id && row.route_id !== "auto");
|
|
110
|
+
const words = { model: choice?.label ?? "The model", price: PLAN_WORDS.pro_price };
|
|
111
|
+
const computed = value.events.some(event => event.kind === "tool_result" && event.payload.ok);
|
|
112
|
+
const result = terminal.answer ? STOP_WORDS.result.authored : computed ? STOP_WORDS.result.computed : STOP_WORDS.result.nothing;
|
|
113
|
+
const lines = [STOP_WORDS.heading.limit, `${fillWords(STOP_WORDS.reason.limit, words) ?? ""} ${result}`.trim()];
|
|
536
114
|
for (const id of offer?.actions ?? []) {
|
|
537
115
|
if (id === "upgrade_plan") lines.push(`${PLAN_WORDS.pro_action}: ${origin}${STOP_ACTION_HREFS.upgrade_plan}`,
|
|
538
|
-
|
|
116
|
+
...[fillWords(STOP_WORDS.action_line.upgrade_plan, words)].filter(Boolean).map(line => ` ${line}`));
|
|
539
117
|
if (id === "contact_sales") lines.push(`${PLAN_WORDS.enterprise_action}: ${origin}${STOP_ACTION_HREFS.contact_sales}`, ` ${STOP_WORDS.action_line.contact_sales}`);
|
|
540
|
-
if (id === "
|
|
541
|
-
}
|
|
542
|
-
if (view.cause !== null && STOP_WORDS.forward[view.cause]) lines.push(STOP_WORDS.forward[view.cause]);
|
|
543
|
-
if (view.renewsAt !== null) {
|
|
544
|
-
lines.push(view.renewsAt <= (offer?.as_of ?? Math.floor(Date.now() / 1000)) ? STOP_WORDS.renews.renewed
|
|
545
|
-
: fillWords(view.binding?.scope === "platform" ? STOP_WORDS.renews.plan : STOP_WORDS.renews.restriction, { plan, date: renewalDate(view.renewsAt) }));
|
|
546
|
-
}
|
|
547
|
-
if (offer ? offer.actions.includes("see_usage") : (view.cause === null || view.cause === "plan_limit")) {
|
|
548
|
-
lines.push(`${STOP_WORDS.see_usage}: ${origin}${STOP_ACTION_HREFS.see_usage}`, STOP_WORDS.usage_note);
|
|
118
|
+
if (id === "continue_with_model" && offer.continuation) lines.push(`${fillWords(STOP_WORDS.continue_with, { model: offer.continuation.label })}: /model, then ask a follow-up`);
|
|
549
119
|
}
|
|
120
|
+
if (!offer || offer.actions.includes("see_usage")) lines.push(`${STOP_WORDS.see_usage}: ${origin}${STOP_ACTION_HREFS.see_usage}`, STOP_WORDS.usage_note);
|
|
550
121
|
return lines.map(plainLine);
|
|
551
122
|
}
|
|
552
123
|
|
|
553
|
-
|
|
554
|
-
const plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
555
|
-
return [
|
|
556
|
-
view.computed ? `${plural(view.computed, "program")} ran to the end.` : "",
|
|
557
|
-
view.failed ? `${plural(view.failed, "program")} failed and computed nothing.` : "",
|
|
558
|
-
view.readOnly ? `${plural(view.readOnly, "step")} only read methods or files.` : "",
|
|
559
|
-
artifacts ? `${plural(artifacts, "file")} saved.` : "",
|
|
560
|
-
].filter(Boolean).join(" ");
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
function recoveryLine(action) {
|
|
564
|
-
const args = Object.entries(action.arguments)
|
|
565
|
-
.map(([name, value]) => `${name}=${JSON.stringify(value)}`).join(" ");
|
|
566
|
-
return `Recovery: ${action.capability}${args ? ` ${args}` : ""}`;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
export function currentTransferTables(events) {
|
|
570
|
-
const candidates = new Map();
|
|
571
|
-
const cleared = new Map();
|
|
572
|
-
for (const event of events) {
|
|
573
|
-
if (event.kind !== "engineering_projection") continue;
|
|
574
|
-
const projection = event.payload;
|
|
575
|
-
if (projection?.kind === "projection_clear" && projection.clear_kind === "transfer_table") {
|
|
576
|
-
const ids = cleared.get(projection.node_id) ?? new Set();
|
|
577
|
-
ids.add(projection.execution_id);
|
|
578
|
-
cleared.set(projection.node_id, ids);
|
|
579
|
-
} else if (projection?.kind === "transfer_table") {
|
|
580
|
-
const rows = candidates.get(projection.node_id) ?? [];
|
|
581
|
-
rows.push(projection);
|
|
582
|
-
candidates.set(projection.node_id, rows);
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
return [...candidates.entries()].flatMap(([node, rows]) => {
|
|
586
|
-
const current = [...rows].reverse().find(row => !cleared.get(node)?.has(row.execution_id));
|
|
587
|
-
return current ? [current] : [];
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
/** The existing typed stop/cause/recovery tail, shared by canonical terminal blocks. */
|
|
124
|
+
/** The typed tail of a closed turn, shared by the terminal block and the transcript. */
|
|
592
125
|
export function terminalBlockLines(value) {
|
|
593
126
|
const terminal = terminalPresentation(value);
|
|
594
|
-
|
|
595
|
-
return [`Terminal: ${plainLine(terminal.state)}`,
|
|
596
|
-
...(stop ? stopLines(stop, value) : []),
|
|
597
|
-
...(terminal.defect ? [`Cause: ${plainLine(terminal.defect)}`] : []),
|
|
598
|
-
...terminal.recovery.map(action => terminalText(recoveryLine(action)))];
|
|
127
|
+
return [`Terminal: ${terminal.state}`, ...(terminal.defect ? [`Cause: ${plainLine(terminal.defect)}`] : [])];
|
|
599
128
|
}
|
|
600
129
|
|
|
601
130
|
/** The server owns amounts and coverage. This function never computes a currency value. */
|
|
@@ -608,87 +137,41 @@ export function turnFooter(run, cost) {
|
|
|
608
137
|
}
|
|
609
138
|
|
|
610
139
|
/** One projection of a Run record; plain text and the rich terminal both render these sections. */
|
|
611
|
-
export function runSections(value, { projectId,
|
|
140
|
+
export function runSections(value, { projectId, stopOffer, origin } = {}) {
|
|
612
141
|
const terminal = value.terminal === "" ? null : terminalPresentation(value);
|
|
613
|
-
const stop = terminal ? stopViewOf(value.events) : null;
|
|
614
|
-
const origins = value.events.flatMap(event => event.kind === "step_finished"
|
|
615
|
-
? inputLines(event.payload?.step?.inputs ?? event.payload?.inputs) : []);
|
|
616
|
-
const artifacts = runArtifacts(value.events);
|
|
617
|
-
if (!artifacts.every(validateArtifact)) {
|
|
618
|
-
throw new CliError("artifact_invalid", "Run carries malformed artifact metadata");
|
|
619
|
-
}
|
|
620
142
|
const project = projectId ? ` --project ${shellQuote(projectId)}` : "";
|
|
621
|
-
const
|
|
622
|
-
|
|
623
|
-
if (
|
|
624
|
-
|
|
625
|
-
throw new CliError("projection_invalid", "Transfer table metadata is malformed");
|
|
626
|
-
}
|
|
627
|
-
return [`Transfer table: ${plainLine(projection.search_status)} · input origins ${projection.origin}`
|
|
628
|
-
+ ` · validation ${plainLine(projection.validation_status)}`
|
|
629
|
-
+ ` · path ${projection.withheld ? "withheld" : "shown"}`,
|
|
630
|
-
` vecteur projection get ${shellQuote(value.run_id)} ${shellQuote(projection.projection_id)}`
|
|
631
|
-
+ ` --output ${shellQuote("transfer-table.json")}${project}`];
|
|
632
|
-
});
|
|
633
|
-
const tail = [`Run: ${plainLine(value.run_id)}`];
|
|
634
|
-
if (terminal && !stop) {
|
|
635
|
-
tail.push(`Terminal: ${terminal.state}`);
|
|
636
|
-
if (terminal.defect !== undefined) tail.push(`Cause: ${terminal.defect}`);
|
|
637
|
-
tail.push(...capacityLine(terminal.defect, terminal.capacity));
|
|
638
|
-
tail.push(...terminal.recovery.map(recoveryLine));
|
|
143
|
+
const tail = [`Run: ${plainLine(value.run_id)}`, ...(terminal ? terminalBlockLines(value) : [])];
|
|
144
|
+
for (const event of value.events) {
|
|
145
|
+
if (event.kind === "review") tail.push(`Review: ${plainLine(event.payload.verdict)}`);
|
|
146
|
+
if (event.kind === "study") tail.push(`Study record: vecteur artifact get ${shellQuote(event.payload.cas_ref)}${project}`);
|
|
639
147
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const hidden = stop && stop.result !== "authored";
|
|
643
|
-
const answer = hidden ? stopActivity(stop, artifacts.length) : terminal?.answer;
|
|
644
|
-
return { blocks: runBlocks(value), events: value.events, checks: hidden ? [] : publicationChecks(value.events), duration_seconds: value.duration_seconds, stop: stop ? stopLines(stop, value, stopOffer, origin) : [], answer, state: terminal?.state ?? "", tasks: taskLines(value.events, { facts: true }), origins,
|
|
645
|
-
assumptions: assumptionLines(value.events), tables, artifacts: artifactRows(artifacts).map(row => ({ ...row,
|
|
148
|
+
return { blocks: runBlocks(value), state: terminal?.state ?? "", answer: terminal?.answer, duration_seconds: value.duration_seconds,
|
|
149
|
+
artifacts: artifactRows(runArtifacts(value.events)).map(row => ({ ...row,
|
|
646
150
|
command: `vecteur artifact get ${shellQuote(row.artifact.cas_ref)} --output ${shellQuote(safeArtifactName(row.artifact))}${project}` })),
|
|
647
|
-
tail };
|
|
151
|
+
tail, stop: terminal?.state === "budget" ? stopLines(value, terminal, stopOffer, origin) : [] };
|
|
648
152
|
}
|
|
649
153
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
* is the review annotation), then each non-blank warning detail as `Check: <detail>`. The last synthesis owns them; anything
|
|
653
|
-
* malformed is simply not shown. */
|
|
654
|
-
export function publicationChecks(events) {
|
|
655
|
-
const publication = events.findLast(event => event.kind === "synthesis")?.payload?.core?.publication;
|
|
656
|
-
const rows = Array.isArray(publication?.rows) ? publication.rows : [];
|
|
657
|
-
const unbound = [...new Set(rows.filter(row => row?.status === "unbound" && typeof row.text === "string").map(row => row.text))].slice(0, 6);
|
|
658
|
-
const warnings = Array.isArray(publication?.warnings) ? publication.warnings : [];
|
|
659
|
-
return [...(unbound.length ? [`Check: numbers not traced to a run: ${unbound.map(plainLine).join(", ")}`] : []),
|
|
660
|
-
...warnings.map(item => item?.detail).filter(detail => typeof detail === "string" && detail.trim() !== "")
|
|
661
|
-
.slice(0, 6).map(detail => `Check: ${plainLine(detail)}`)];
|
|
154
|
+
export function humanRun(value, { projectId, cost, stopOffer, origin, shownKeys = new Set() } = {}) {
|
|
155
|
+
return humanRunSections(runSections(value, { projectId, stopOffer, origin }), { cost, shownKeys });
|
|
662
156
|
}
|
|
663
157
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
return humanRunSections(run, { cost, shownKeys });
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
/** Render the supplied authoritative sections, suppressing only already printed rows. */
|
|
158
|
+
/** A turn in plain text: the working trace (one line per tool call), the answer, the files, the terminal state and,
|
|
159
|
+
* at a limit, the stop card. Rows already printed live are not repeated. */
|
|
670
160
|
export function humanRunSections(run, { cost, shownKeys = new Set() } = {}) {
|
|
671
161
|
const lines = [];
|
|
672
|
-
|
|
673
|
-
if (
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
const shownSteps = new Set(run.blocks.filter(block => block.kind === "step" && shownKeys.has(block.key)).map(block => block.stepId));
|
|
677
|
-
const tasks = shownSteps.size ? taskLines(run.events.filter(event => event.kind !== "step_finished" || !shownSteps.has(event.payload?.step_id)), { facts: true }) : run.tasks;
|
|
678
|
-
if (tasks.length) lines.push("Steps:", ...tasks, "");
|
|
679
|
-
if (run.origins.length) lines.push("Inputs and origins:", ...run.origins, "");
|
|
680
|
-
if (run.assumptions.length) lines.push("Assumptions:", ...run.assumptions, "");
|
|
681
|
-
for (const table of run.tables) lines.push(...table, "");
|
|
162
|
+
const trace = run.blocks.filter(block => block.kind !== "terminal" && !shownKeys.has(block.key));
|
|
163
|
+
if (trace.length) lines.push("Working:", ...trace.map(block => ` ${blockText(block)}`), "");
|
|
164
|
+
if (run.answer) lines.push(run.answer, "");
|
|
165
|
+
else if (run.state) lines.push("No answer was published for this Run.", "");
|
|
682
166
|
if (run.artifacts.length) {
|
|
683
|
-
lines.push("
|
|
167
|
+
lines.push("Files:");
|
|
684
168
|
for (const { artifact, command, number, sameBytesAs } of run.artifacts) {
|
|
685
|
-
lines.push(` ${terminalText(artifact.path
|
|
169
|
+
lines.push(` ${terminalText(artifact.path)} (${plainLine(artifact.kind)}, ${artifact.bytes} B) · /download ${number}${sameBytesAs ? ` · same bytes as ${sameBytesAs}` : ""}`, ` ${terminalText(command)}`);
|
|
686
170
|
}
|
|
687
171
|
lines.push("");
|
|
688
172
|
}
|
|
689
173
|
lines.push(...run.tail);
|
|
690
|
-
|
|
691
|
-
if (controls.length) lines.push("", "Controls:", ...controls.map(block => blockText(block)));
|
|
174
|
+
if (run.stop.length) lines.push("", ...run.stop);
|
|
692
175
|
if (cost) lines.push("", humanCost(cost).trimEnd());
|
|
693
176
|
return `${lines.join("\n")}\n`;
|
|
694
177
|
}
|
|
@@ -719,33 +202,13 @@ export function human(value, options = {}) {
|
|
|
719
202
|
return canonicalJson(value);
|
|
720
203
|
}
|
|
721
204
|
|
|
205
|
+
/** One live line per event worth a line: a tool call as it starts, a failed result, a file as it lands. */
|
|
722
206
|
export function progress(event) {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
return `File ready: ${plainLine(event.payload.filename)}\n`;
|
|
729
|
-
}
|
|
730
|
-
if (event?.kind === "tool_call" && event.payload?.tool === "specialist_tool" && typeof event.payload.specialist_tool === "string") {
|
|
731
|
-
// RunWire v4 (A8): each specialist family call is a live row of its own agent.
|
|
732
|
-
const tool = event.payload.specialist_tool;
|
|
733
|
-
const said = String(event.payload.summary ?? "").replace(new RegExp(`^${tool.replace(/[^\w]/g, "")}\\s*`), "").slice(0, 100);
|
|
734
|
-
return `Specialist call: ${childLabel(event.payload)}${plainLine(tool)}${said.trim() ? ` — ${plainLine(said.trim())}` : ""}\n`;
|
|
735
|
-
}
|
|
736
|
-
const capability = event?.kind === "tool_call" ? capabilityCall(event.payload) : null;
|
|
737
|
-
if (capability) {
|
|
738
|
-
// v5x: a root capability call is a live row of the root agent, labelled by its family.
|
|
739
|
-
const summary = String(event.payload.summary ?? "");
|
|
740
|
-
const said = (summary.startsWith(capability.name) ? summary.slice(capability.name.length) : summary).trim().slice(0, 100);
|
|
741
|
-
return `${capability.label} call: ${plainLine(capability.name)}${said ? ` — ${plainLine(said)}` : ""}\n`;
|
|
742
|
-
}
|
|
743
|
-
if (event?.kind === "tool_call" && event.payload?.tool === "local_exec") return `● Bash ${plainLine(event.payload.summary)} · this computer\n`;
|
|
744
|
-
if (event?.kind !== "step_finished") return "";
|
|
745
|
-
const lines = inputLines(event?.payload?.step?.inputs ?? event?.payload?.inputs);
|
|
746
|
-
const title = plainLine(event.payload?.step?.title ?? event.payload?.title ?? "");
|
|
747
|
-
const head = title.trim() ? `Finished: ${childLabel(event.payload)}${title}\n` : "Finished\n";
|
|
748
|
-
return lines.length ? `${head}${lines.join("\n")}\n` : head;
|
|
207
|
+
const payload = event?.payload;
|
|
208
|
+
if (event?.kind === "tool_call") return `${String(payload.tool).charAt(0).toUpperCase()}${String(payload.tool).slice(1)}: ${plainLine(payload.title)}\n`;
|
|
209
|
+
if (event?.kind === "tool_result" && !payload.ok) return ` failed: ${plainLine(payload.excerpt.split("\n").filter(line => line.trim()).at(-1) ?? "no output")}\n`;
|
|
210
|
+
if (event?.kind === "artifact") return `File ready: ${plainLine(payload.path)}\n`;
|
|
211
|
+
return "";
|
|
749
212
|
}
|
|
750
213
|
|
|
751
214
|
export function plainLine(value) {
|