@vecteur/cli 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +224 -15
- package/bin/vecteur.js +107 -10
- package/package.json +5 -1
- package/src/blocks.js +201 -6
- package/src/client.js +280 -29
- package/src/commands.js +56 -15
- package/src/contract.js +35 -7
- package/src/credentials.js +8 -0
- package/src/errors.js +4 -1
- package/src/exchange.js +85 -0
- package/src/executor.js +171 -0
- package/src/folders.js +28 -2
- package/src/format.js +332 -28
- package/src/input.js +7 -3
- package/src/localfiles.js +788 -0
- package/src/mcp.js +143 -9
- package/src/produce.js +49 -0
- package/src/session.js +693 -103
- package/src/terminal.js +65 -32
- package/src/tui/view.js +128 -55
package/src/format.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { runBlocks, runArtifacts, artifactRows, blockText } from "./blocks.js";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
+
AGENT_LABELS, EXECUTION_HORIZONS, HISTORICAL_STOP_HEADS, HORIZON_STOP_DEFECTS, MODEL_CATALOGUE, ORIGIN_KINDS, ORIGIN_WORD,
|
|
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,
|
|
3
6
|
validateArtifact, validateSynthesis,
|
|
4
7
|
} from "./contract.js";
|
|
5
8
|
import { CliError } from "./errors.js";
|
|
@@ -8,6 +11,38 @@ import { CliError } from "./errors.js";
|
|
|
8
11
|
export const terminalText = value => String(value ?? "").replace(/[\x00-\x08\x0b\x0c\x0d\x0e-\x1f\x7f-\x9f]/g,
|
|
9
12
|
char => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`).replace(/\t/g, " ");
|
|
10
13
|
|
|
14
|
+
/** A bounded unified whole-file hunk. This is a review display, never an executable patch. */
|
|
15
|
+
export function localFileDiff(before, after, from, to) {
|
|
16
|
+
const decode = bytes => new TextDecoder('utf-8',{fatal:true}).decode(bytes);
|
|
17
|
+
let a, b;
|
|
18
|
+
try { a=decode(before); b=decode(after); }
|
|
19
|
+
catch { return `${terminalText(from)} → ${terminalText(to)}: binary or non-UTF-8 diff unavailable`; }
|
|
20
|
+
const lines = text => text ? text.match(/[^\n]*\n|[^\n]+$/g) : [];
|
|
21
|
+
const left=lines(a), right=lines(b);
|
|
22
|
+
if (a===b) return `${terminalText(from)} → ${terminalText(to)}: already identical`;
|
|
23
|
+
const out=[`--- ${terminalText(from)}`,`+++ ${terminalText(to)}`,`@@ -${left.length?1:0},${left.length} +${right.length?1:0},${right.length} @@`];
|
|
24
|
+
let size=0, count=0;
|
|
25
|
+
for (const [prefix, rows] of [['-',left],['+',right]]) for(const line of rows) {
|
|
26
|
+
const rendered=prefix+terminalText(line.replace(/\n$/,''));
|
|
27
|
+
if (++count>200 || size+rendered.length>16000) return out.join('\n')+'\n… diff truncated (200 lines / 16000 characters)';
|
|
28
|
+
size+=rendered.length;out.push(rendered);
|
|
29
|
+
if(!line.endsWith('\n'))out.push('\');
|
|
30
|
+
}
|
|
31
|
+
return out.join('\n');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function proposalReview(rel, snapshot, bytes) {
|
|
35
|
+
return [snapshot.classification === 'local changed' ? `you changed ${terminalText(rel)} since Vecteur read it; your edit is kept`
|
|
36
|
+
: snapshot.classification === 'first sync' ? 'Vecteur has no earlier version of this file from you' : snapshot.classification,
|
|
37
|
+
snapshot.baseline ? snapshot.baseBytes ? localFileDiff(snapshot.baseBytes,snapshot.bytes ?? Buffer.alloc(0),'base','local now') : 'base → local now: base diff unavailable (hash-based status retained)' : '',
|
|
38
|
+
localFileDiff(snapshot.bytes ?? Buffer.alloc(0),bytes,'local now','proposed')].filter(Boolean).join('\n');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function adoptionHint(proposal, original) {
|
|
42
|
+
const quote = value => "'"+value.replaceAll("'", "'\\''")+"'";
|
|
43
|
+
return `Review and adopt in your editor, or:\nmv -i -- ${quote(proposal)} ${quote(original)}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
11
46
|
export function canonicalJson(value) {
|
|
12
47
|
validateNumbers(value);
|
|
13
48
|
return `${JSON.stringify(sortValue(value))}\n`;
|
|
@@ -158,7 +193,17 @@ export function doorObservation(text) {
|
|
|
158
193
|
return { verb: head[1], headline, warnings };
|
|
159
194
|
}
|
|
160
195
|
|
|
161
|
-
/**
|
|
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
|
+
|
|
162
207
|
function doorCallsByStep(events) {
|
|
163
208
|
const results = new Map();
|
|
164
209
|
for (const event of events) {
|
|
@@ -169,15 +214,10 @@ function doorCallsByStep(events) {
|
|
|
169
214
|
const rows = new Map();
|
|
170
215
|
for (const event of events) {
|
|
171
216
|
const call = event?.kind === "tool_call" ? event.payload : null;
|
|
172
|
-
const
|
|
173
|
-
if (!
|
|
174
|
-
const result = results.get(call.call_id);
|
|
175
|
-
const observation = result?.status === "ok" ? doorObservation(result.stdout_excerpt) : null;
|
|
176
|
-
if (result?.status === "ok" && observation?.verb !== verb) continue; // free code that opened with `# run x_y`
|
|
177
|
-
const refusal = result && result.status !== "ok"
|
|
178
|
-
? String(result.stderr_excerpt || result.stdout_excerpt || "").trim().split("\n").filter(Boolean).slice(-3).join(" · ") : "";
|
|
217
|
+
const door = engineeringCall(call, results.get(call?.call_id));
|
|
218
|
+
if (!door) continue;
|
|
179
219
|
const list = rows.get(call.step_id) ?? [];
|
|
180
|
-
list.push(
|
|
220
|
+
list.push(door);
|
|
181
221
|
rows.set(call.step_id, list);
|
|
182
222
|
}
|
|
183
223
|
return rows;
|
|
@@ -192,7 +232,80 @@ function doorLine({ purpose, verb, observation, refusal, running }) {
|
|
|
192
232
|
return lines.join("\n");
|
|
193
233
|
}
|
|
194
234
|
|
|
195
|
-
|
|
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) {
|
|
196
309
|
const doors = doorCallsByStep(events);
|
|
197
310
|
// The conclusion is engineering work (it prints the answer from evidence); its text is the
|
|
198
311
|
// synthesis, so the row stays one line.
|
|
@@ -201,8 +314,14 @@ export function taskLines(events) {
|
|
|
201
314
|
// Only a run that called the door tells engineering rows from execution rows; any other run
|
|
202
315
|
// prints exactly as before.
|
|
203
316
|
const distinguishes = doors.size > 0 || concluded.size > 0;
|
|
317
|
+
const specialist = specialistCallsByStep(events);
|
|
204
318
|
return events.flatMap((event) => {
|
|
205
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) {
|
|
206
325
|
const row = event.payload;
|
|
207
326
|
if (!row || typeof row !== "object" || typeof row.step_id !== "string") return [];
|
|
208
327
|
const outcome = CAUSE_WORD[row.cause] ?? row.status;
|
|
@@ -221,7 +340,7 @@ export function taskLines(events) {
|
|
|
221
340
|
? ` · ${row.attempts} ${row.attempts === 1 ? "attempt" : "attempts"}` : "";
|
|
222
341
|
const printed = result ? `\n ${plainLine(result)}` : "";
|
|
223
342
|
return [` ${plainLine(`${row.title} — ${outcome}${attempts}`)}${printed}`];
|
|
224
|
-
}
|
|
343
|
+
}
|
|
225
344
|
}
|
|
226
345
|
|
|
227
346
|
/**
|
|
@@ -318,7 +437,127 @@ function terminalPresentation(value) {
|
|
|
318
437
|
}
|
|
319
438
|
}
|
|
320
439
|
}
|
|
321
|
-
return { state, answer: payload.answer, defect, recovery: recovery ?? [] };
|
|
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;
|
|
536
|
+
for (const id of offer?.actions ?? []) {
|
|
537
|
+
if (id === "upgrade_plan") lines.push(`${PLAN_WORDS.pro_action}: ${origin}${STOP_ACTION_HREFS.upgrade_plan}`,
|
|
538
|
+
` ${fillWords(STOP_WORDS.action_line.upgrade_plan, { steps: String(proSteps), price: PLAN_WORDS.pro_price })}`);
|
|
539
|
+
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 === "ask_owner") lines.push(view.binding?.tier === "pro" ? STOP_WORDS.action_line.ask_owner_pro : STOP_WORDS.action_line.ask_owner_free);
|
|
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);
|
|
549
|
+
}
|
|
550
|
+
return lines.map(plainLine);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function stopActivity(view, artifacts) {
|
|
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(" ");
|
|
322
561
|
}
|
|
323
562
|
|
|
324
563
|
function recoveryLine(action) {
|
|
@@ -349,12 +588,32 @@ export function currentTransferTables(events) {
|
|
|
349
588
|
});
|
|
350
589
|
}
|
|
351
590
|
|
|
591
|
+
/** The existing typed stop/cause/recovery tail, shared by canonical terminal blocks. */
|
|
592
|
+
export function terminalBlockLines(value) {
|
|
593
|
+
const terminal = terminalPresentation(value);
|
|
594
|
+
const stop = stopViewOf(value.events);
|
|
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)))];
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/** The server owns amounts and coverage. This function never computes a currency value. */
|
|
602
|
+
export function turnFooter(run, cost) {
|
|
603
|
+
const seconds = run?.duration_seconds;
|
|
604
|
+
const duration = Number.isSafeInteger(seconds) && seconds >= 0 ? `${seconds}s` : "duration unavailable";
|
|
605
|
+
const amount = cost?.display?.scope_used ?? cost?.display?.used ?? "no exact amount available";
|
|
606
|
+
const coverage = cost?.coverage ? ` (${cost.coverage} coverage)` : "";
|
|
607
|
+
return plainLine(`✻ ${run?.terminal || "open"} · ${duration} · ${amount}${coverage} this UTC month · /usage`);
|
|
608
|
+
}
|
|
609
|
+
|
|
352
610
|
/** One projection of a Run record; plain text and the rich terminal both render these sections. */
|
|
353
|
-
export function runSections(value, { projectId, currentTransferIds } = {}) {
|
|
611
|
+
export function runSections(value, { projectId, currentTransferIds, stopOffer, origin } = {}) {
|
|
354
612
|
const terminal = value.terminal === "" ? null : terminalPresentation(value);
|
|
613
|
+
const stop = terminal ? stopViewOf(value.events) : null;
|
|
355
614
|
const origins = value.events.flatMap(event => event.kind === "step_finished"
|
|
356
615
|
? inputLines(event.payload?.step?.inputs ?? event.payload?.inputs) : []);
|
|
357
|
-
const artifacts = value.events
|
|
616
|
+
const artifacts = runArtifacts(value.events);
|
|
358
617
|
if (!artifacts.every(validateArtifact)) {
|
|
359
618
|
throw new CliError("artifact_invalid", "Run carries malformed artifact metadata");
|
|
360
619
|
}
|
|
@@ -372,33 +631,64 @@ export function runSections(value, { projectId, currentTransferIds } = {}) {
|
|
|
372
631
|
+ ` --output ${shellQuote("transfer-table.json")}${project}`];
|
|
373
632
|
});
|
|
374
633
|
const tail = [`Run: ${plainLine(value.run_id)}`];
|
|
375
|
-
if (terminal) {
|
|
634
|
+
if (terminal && !stop) {
|
|
376
635
|
tail.push(`Terminal: ${terminal.state}`);
|
|
377
636
|
if (terminal.defect !== undefined) tail.push(`Cause: ${terminal.defect}`);
|
|
637
|
+
tail.push(...capacityLine(terminal.defect, terminal.capacity));
|
|
378
638
|
tail.push(...terminal.recovery.map(recoveryLine));
|
|
379
639
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
640
|
+
// A horizon stop: its words, before the work. Only the model's own text is printed as its answer; host words and an old
|
|
641
|
+
// record's unproven text give way to what ran, in counts, never a value (planstop-r3; the web's StopSummary says the same).
|
|
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,
|
|
646
|
+
command: `vecteur artifact get ${shellQuote(row.artifact.cas_ref)} --output ${shellQuote(safeArtifactName(row.artifact))}${project}` })),
|
|
383
647
|
tail };
|
|
384
648
|
}
|
|
385
649
|
|
|
386
|
-
|
|
387
|
-
|
|
650
|
+
/** The host's publication notes as the browser shows them (`frontend/src/run/publication.ts`), first six each: the figures the
|
|
651
|
+
* run's evidence does not support as `Check: numbers not traced to a run: <figures>` (an unbound answer stays `ok`, so this line
|
|
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)}`)];
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export function humanRun(value, { projectId, cost, currentTransferIds, stopOffer, origin, shownKeys = new Set() } = {}) {
|
|
665
|
+
const run = runSections(value, { projectId, currentTransferIds, stopOffer, origin });
|
|
666
|
+
return humanRunSections(run, { cost, shownKeys });
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/** Render the supplied authoritative sections, suppressing only already printed rows. */
|
|
670
|
+
export function humanRunSections(run, { cost, shownKeys = new Set() } = {}) {
|
|
388
671
|
const lines = [];
|
|
389
|
-
if (run.
|
|
390
|
-
if (run.
|
|
672
|
+
if (run.stop.length) lines.push(...run.stop, "");
|
|
673
|
+
if (run.answer !== undefined && run.answer !== "") lines.push(run.answer, "", ...(run.checks?.length ? [...run.checks, ""] : []));
|
|
674
|
+
const remaining = run.blocks.filter(block => !shownKeys.has(block.key));
|
|
675
|
+
for (const block of remaining.filter(block => ["tool", "sources", "clarification"].includes(block.kind))) lines.push(blockText(block), "");
|
|
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, "");
|
|
391
679
|
if (run.origins.length) lines.push("Inputs and origins:", ...run.origins, "");
|
|
392
680
|
if (run.assumptions.length) lines.push("Assumptions:", ...run.assumptions, "");
|
|
393
681
|
for (const table of run.tables) lines.push(...table, "");
|
|
394
682
|
if (run.artifacts.length) {
|
|
395
683
|
lines.push("Artifacts:");
|
|
396
|
-
for (const { artifact, command } of run.artifacts) {
|
|
397
|
-
lines.push(` ${artifact.filename} (${artifact.kind}, ${artifact.id})`, ` ${command}`);
|
|
684
|
+
for (const { artifact, command, number, sameBytesAs } of run.artifacts) {
|
|
685
|
+
lines.push(` ${terminalText(artifact.path ?? artifact.filename)} (${plainLine(artifact.kind)}, ${plainLine(artifact.id)}) · /download ${number}${sameBytesAs ? ` · same bytes as ${sameBytesAs}` : ""}`, ` ${terminalText(command)}`);
|
|
398
686
|
}
|
|
399
687
|
lines.push("");
|
|
400
688
|
}
|
|
401
689
|
lines.push(...run.tail);
|
|
690
|
+
const controls = remaining.filter(block => block.kind === "control");
|
|
691
|
+
if (controls.length) lines.push("", "Controls:", ...controls.map(block => blockText(block)));
|
|
402
692
|
if (cost) lines.push("", humanCost(cost).trimEnd());
|
|
403
693
|
return `${lines.join("\n")}\n`;
|
|
404
694
|
}
|
|
@@ -432,18 +722,32 @@ export function human(value, options = {}) {
|
|
|
432
722
|
export function progress(event) {
|
|
433
723
|
if (event?.kind === "step_started") {
|
|
434
724
|
const title = plainLine(event.payload?.title ?? "");
|
|
435
|
-
return title.trim() ? `Starting: ${title}\n` : "Starting\n";
|
|
725
|
+
return title.trim() ? `Starting: ${childLabel(event.payload)}${title}\n` : "Starting\n";
|
|
436
726
|
}
|
|
437
727
|
if (event?.kind === "artifact") {
|
|
438
728
|
return `File ready: ${plainLine(event.payload.filename)}\n`;
|
|
439
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`;
|
|
440
744
|
if (event?.kind !== "step_finished") return "";
|
|
441
745
|
const lines = inputLines(event?.payload?.step?.inputs ?? event?.payload?.inputs);
|
|
442
746
|
const title = plainLine(event.payload?.step?.title ?? event.payload?.title ?? "");
|
|
443
|
-
const head = title.trim() ? `Finished: ${title}\n` : "Finished\n";
|
|
747
|
+
const head = title.trim() ? `Finished: ${childLabel(event.payload)}${title}\n` : "Finished\n";
|
|
444
748
|
return lines.length ? `${head}${lines.join("\n")}\n` : head;
|
|
445
749
|
}
|
|
446
750
|
|
|
447
|
-
function plainLine(value) {
|
|
751
|
+
export function plainLine(value) {
|
|
448
752
|
return String(value).replace(/[\u0000-\u001f\u007f-\u009f]+/g, " ");
|
|
449
753
|
}
|
package/src/input.js
CHANGED
|
@@ -5,7 +5,7 @@ const START = "\x1b[200~", END = "\x1b[201~";
|
|
|
5
5
|
const MAX_BYTES = 256 * 1024;
|
|
6
6
|
const graphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
7
7
|
|
|
8
|
-
/** Stream decoder shared by both
|
|
8
|
+
/** Stream decoder shared by both views; negotiated paste is one edit, never a send. */
|
|
9
9
|
export class ComposerInput extends EventEmitter {
|
|
10
10
|
constructor() {
|
|
11
11
|
super(); this.text = ""; this.cursor = 0; this.pending = ""; this.pasting = false;
|
|
@@ -61,10 +61,14 @@ export class ComposerInput extends EventEmitter {
|
|
|
61
61
|
this.checkpoint();
|
|
62
62
|
this.text = value; this.cursor += text.length; this.emit("change", this.text);
|
|
63
63
|
}
|
|
64
|
-
feed(bytes) {
|
|
64
|
+
feed(bytes, { unbracketed = false } = {}) {
|
|
65
65
|
clearTimeout(this.escapeTimer);
|
|
66
66
|
const epoch = this.focusEpoch;
|
|
67
|
-
|
|
67
|
+
let chunk = typeof bytes === "string" ? bytes : this.decoder.write(bytes);
|
|
68
|
+
// Unmarked multiline reads are drafts, including every trailing CR. A split read
|
|
69
|
+
// consisting only of CR/CRLF is indistinguishable from Enter without negotiation.
|
|
70
|
+
if (unbracketed) chunk = chunk === "\r\n" ? "\r" : chunk === "\r" ? chunk : chunk.replace(/\r\n?/g, "\n");
|
|
71
|
+
this.pending += chunk;
|
|
68
72
|
while (this.pending) {
|
|
69
73
|
if (this.pasting) {
|
|
70
74
|
const end = this.pending.indexOf(END);
|