@vecteur/cli 0.11.1 → 0.13.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 +39 -45
- package/bin/vecteur.js +46 -101
- package/package.json +4 -4
- package/src/blocks.js +43 -170
- package/src/client.js +62 -271
- package/src/commands.js +21 -45
- package/src/contract.js +19 -60
- package/src/download.js +2 -7
- package/src/exchange.js +6 -5
- package/src/format.js +82 -596
- package/src/localfiles.js +4 -26
- package/src/markdown.js +43 -68
- package/src/mcp.js +60 -76
- package/src/session.js +67 -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/blocks.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { progress, plainLine, terminalText, terminalBlockLines } from "./format.js";
|
|
2
|
+
import { EVENT_KINDS } from "./contract.js";
|
|
2
3
|
|
|
3
4
|
function elapsed(run, now) {
|
|
4
5
|
if (!run) return null;
|
|
@@ -14,43 +15,25 @@ function elapsed(run, now) {
|
|
|
14
15
|
+ `${pad(Math.floor(seconds / 60) % 60)}:${pad(seconds % 60)}`;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
-
export function runView(run,
|
|
18
|
+
/** The wire owns the facts; this is the turn as a reader sees it. */
|
|
19
|
+
export function runView(run, now = Date.now()) {
|
|
19
20
|
const events = run?.events ?? [];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
const view = same ? cache.view : {
|
|
21
|
+
let progressLine = "Waiting for Vecteur";
|
|
22
|
+
for (const event of events) { const line = progress(event); if (line) progressLine = line.trim(); }
|
|
23
|
+
return {
|
|
25
24
|
subject: run ? { kind: "vecteur_run", id: run.run_id } : null,
|
|
26
|
-
answer:
|
|
27
|
-
|
|
25
|
+
answer: events.findLast(event => event.kind === "synthesis")?.payload.markdown ?? "",
|
|
26
|
+
artifacts: runArtifacts(events), progress: progressLine, terminal: run?.terminal ?? "",
|
|
27
|
+
blocks: runBlocks(run), elapsed: elapsed(run, now),
|
|
28
28
|
};
|
|
29
|
-
for (let index = same ? cache.count : 0; index < events.length; index++) {
|
|
30
|
-
const event = events[index];
|
|
31
|
-
if (event.kind === "synthesis") view.answer = event.payload.answer ?? "";
|
|
32
|
-
if (event.kind === "clarification") view.question = event.payload.state === "requested" ? event.payload : null;
|
|
33
|
-
if (["step_started", "step_finished", "task"].includes(event.kind)) view.steps.push(event);
|
|
34
|
-
const line = progress(event);
|
|
35
|
-
if (line) view.progress = line.trim();
|
|
36
|
-
}
|
|
37
|
-
view.terminal = run?.terminal ?? "";
|
|
38
|
-
view.artifacts = runArtifacts(events);
|
|
39
|
-
view.eventBlocks = eventBlocks(run);
|
|
40
|
-
view.transcript = run?.terminal ? humanRun(run) : "";
|
|
41
|
-
if (cache) Object.assign(cache, { run, runId: run?.run_id, events, count: events.length, terminal: run?.terminal, view });
|
|
42
|
-
return { ...view, blocks: [...view.eventBlocks, ...controlBlocks(run, view.eventBlocks.length)], elapsed: elapsed(run, now) };
|
|
43
29
|
}
|
|
44
30
|
|
|
45
|
-
|
|
46
|
-
/** Current revision per logical path; content identity never removes a destination. */
|
|
31
|
+
/** Current revision per path. */
|
|
47
32
|
export function runArtifacts(events = []) {
|
|
48
33
|
const rows = new Map();
|
|
49
34
|
for (const event of events) if (event.kind === "artifact") {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const prior = rows.get(key);
|
|
53
|
-
if (!prior || (artifact.revision ?? 0) >= (prior.revision ?? 0)) rows.set(key, artifact);
|
|
35
|
+
const prior = rows.get(event.payload.path);
|
|
36
|
+
if (!prior || event.payload.revision >= prior.revision) rows.set(event.payload.path, event.payload);
|
|
54
37
|
}
|
|
55
38
|
return [...rows.values()];
|
|
56
39
|
}
|
|
@@ -64,172 +47,62 @@ export function artifactRows(artifacts) {
|
|
|
64
47
|
});
|
|
65
48
|
}
|
|
66
49
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
/** Pure, replay-safe projection. Only the complete event prefix may leave the live region.
|
|
71
|
-
* Controls have no event anchor: they follow in a separate section and stay live until terminal.
|
|
72
|
-
* Payloads are never decorated/mutated, so machine JSON remains the owner's exact record.
|
|
73
|
-
*/
|
|
50
|
+
/** Pure, replay-safe projection: one block per tool call (with its result once it arrived), one for the terminal,
|
|
51
|
+
* and one for any event kind this build does not know. A block is committed once nothing before it is still running. */
|
|
74
52
|
export function runBlocks(run) {
|
|
75
|
-
const blocks = eventBlocks(run);
|
|
76
|
-
return [...blocks, ...controlBlocks(run, blocks.length)];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function eventBlocks(run) {
|
|
80
53
|
if (!run) return [];
|
|
81
54
|
const events = [...(run.events ?? [])].sort((a, b) => a.seq - b.seq);
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
let fold = null;
|
|
85
|
-
const closeFold = () => { if (fold) fold.closed = true; fold = null; };
|
|
55
|
+
const closed = events.some(event => event.kind === "terminal");
|
|
56
|
+
const byCall = new Map(), blocks = [];
|
|
86
57
|
for (const event of events) {
|
|
87
58
|
const payload = event.payload;
|
|
88
59
|
if (event.kind === "tool_call") {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
calls.set(key, call); byCall.set(payload.call_id, call);
|
|
93
|
-
if (sourceRead(payload)) {
|
|
94
|
-
if (!fold || fold.stepId !== payload.step_id) {
|
|
95
|
-
closeFold();
|
|
96
|
-
fold = { kind: "sources", key, seq: event.seq, stepId: payload.step_id, calls: [], closed: false };
|
|
97
|
-
blocks.push(fold);
|
|
98
|
-
}
|
|
99
|
-
fold.calls.push(call);
|
|
100
|
-
} else {
|
|
101
|
-
closeFold();
|
|
102
|
-
blocks.push({ kind: "tool", key, seq: event.seq, stepId: payload.step_id, calls: [call] });
|
|
103
|
-
}
|
|
60
|
+
if (byCall.has(payload.call_id)) continue; // a reconnect may replay a prefix
|
|
61
|
+
const block = { kind: "tool", key: `${run.run_id}:${payload.call_id}`, seq: event.seq, call: payload, result: null };
|
|
62
|
+
byCall.set(payload.call_id, block); blocks.push(block);
|
|
104
63
|
} else if (event.kind === "tool_result") {
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
} else if (event.kind === "step_finished" || event.kind === "clarification") {
|
|
108
|
-
closeFold();
|
|
109
|
-
// Each clarification transition is immutable, with the original questions available on resolution.
|
|
110
|
-
if (event.kind === "clarification" && payload.state === "requested") questions.set(payload.id, payload);
|
|
111
|
-
const question = event.kind === "clarification" ? questions.get(payload.id) : null;
|
|
112
|
-
const key = tuple(run.run_id, payload.step_id ?? payload.id, `${event.kind}:${event.seq}`);
|
|
113
|
-
if (seen.has(key)) continue;
|
|
114
|
-
seen.add(key);
|
|
115
|
-
blocks.push({ kind: event.kind === "clarification" ? "clarification" : "step",
|
|
116
|
-
key, seq: event.seq, stepId: payload.step_id, payload, ...(question ? { question } : {}) });
|
|
64
|
+
const block = byCall.get(payload.call_id);
|
|
65
|
+
if (block && !block.result) block.result = payload;
|
|
117
66
|
} else if (event.kind === "terminal") {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
67
|
+
blocks.push({ kind: "terminal", key: `${run.run_id}:terminal`, seq: event.seq, state: payload.state,
|
|
68
|
+
lines: terminalBlockLines({ ...run, terminal: payload.state }) });
|
|
69
|
+
} else if (!EVENT_KINDS.includes(event.kind)) {
|
|
70
|
+
blocks.push({ kind: "unknown", key: `${run.run_id}:unknown:${event.seq}`, seq: event.seq, eventKind: String(event.kind) });
|
|
121
71
|
}
|
|
122
72
|
}
|
|
123
73
|
let waiting = false, number = 0;
|
|
124
74
|
for (const block of blocks) {
|
|
125
|
-
|
|
126
|
-
&& (block.kind !== "sources" || block.closed || terminal);
|
|
127
|
-
waiting ||= !complete;
|
|
75
|
+
waiting ||= block.kind === "tool" && !block.result && !closed;
|
|
128
76
|
block.committed = !waiting;
|
|
129
77
|
block.number = ++number;
|
|
130
78
|
}
|
|
131
79
|
return blocks;
|
|
132
80
|
}
|
|
133
81
|
|
|
134
|
-
|
|
135
|
-
return [...(run?.controls ?? [])].sort((a, b) => a.sequence - b.sequence).map(control => ({
|
|
136
|
-
kind: "control", key: tuple(run.run_id, null, `control:${control.id}`),
|
|
137
|
-
sequence: control.sequence, payload: control, committed: !!run.terminal, number: ++number,
|
|
138
|
-
}));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
142
|
-
function sourceSummary(calls) {
|
|
143
|
-
const extracts = new Set(), files = new Set();
|
|
144
|
-
for (const { call, result } of calls) {
|
|
145
|
-
if (result?.status !== "ok" || result.files_changed?.length) return null;
|
|
146
|
-
let data;
|
|
147
|
-
try { data = JSON.parse(result.stdout_excerpt); } catch { return null; }
|
|
148
|
-
if (!data || typeof data !== "object" || Array.isArray(data)
|
|
149
|
-
|| data.extracts !== undefined && !Array.isArray(data.extracts)) return null;
|
|
150
|
-
// Count extracts actually read, rather than those merely offered/selected by context_list.
|
|
151
|
-
for (const extract of data.extracts ?? []) {
|
|
152
|
-
const handle = extract?.source_handle;
|
|
153
|
-
if (typeof extract?.id !== "string" || typeof handle?.cas_ref !== "string"
|
|
154
|
-
|| typeof handle?.acquisition_ref !== "string") return null;
|
|
155
|
-
extracts.add(extract.id);
|
|
156
|
-
files.add(JSON.stringify([handle.cas_ref, handle.acquisition_ref]));
|
|
157
|
-
}
|
|
158
|
-
if (call.summary !== "context_list" && !Array.isArray(data.extracts)) return null;
|
|
159
|
-
}
|
|
160
|
-
return extracts.size && files.size ? `Read ${plural(extracts.size, "extract")} from ${plural(files.size, "file")}` : null;
|
|
161
|
-
}
|
|
82
|
+
const TOOL_LABEL = tool => String(tool).charAt(0).toUpperCase() + String(tool).slice(1);
|
|
162
83
|
|
|
84
|
+
/** `{tool, title, status, rows}`; `full` adds the call's input and the result excerpt. */
|
|
163
85
|
export function blockContent(block, { full = false } = {}) {
|
|
164
86
|
if (block.kind === "terminal") return { title: `Terminal: ${block.state}`, rows: block.lines, status: block.state };
|
|
165
|
-
if (block.kind === "
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
if (block.kind === "clarification") {
|
|
178
|
-
const q = block.payload, source = block.question ?? q;
|
|
179
|
-
const rows = [q.state];
|
|
180
|
-
for (const question of source.questions ?? []) {
|
|
181
|
-
rows.push(question.question);
|
|
182
|
-
for (const choice of question.options ?? []) rows.push(`${choice.id ?? choice.value ?? ""} ${choice.label ?? choice}`);
|
|
183
|
-
}
|
|
184
|
-
if (q.answers) rows.push(`Answers: ${JSON.stringify(q.answers)}`);
|
|
185
|
-
return { title: "Clarification", status: q.state, rows };
|
|
186
|
-
}
|
|
187
|
-
const { call } = block.calls[0];
|
|
188
|
-
const engineering = !!engineeringCall(call, block.calls[0].result);
|
|
189
|
-
const capability = capabilityCall(call);
|
|
190
|
-
const tool = call.tool === "local_exec" ? "Bash" : engineering ? "Run" : call.tool === "python" ? "Python" : call.tool === "sources" ? "Sources"
|
|
191
|
-
: capability ? `${capability.label} ${capability.name}` : call.tool;
|
|
192
|
-
const status = block.calls.some(item => !item.result) ? block.committed ? "no result recorded" : "running"
|
|
193
|
-
: block.calls.find(item => item.result.status !== "ok")?.result.status ?? "ok";
|
|
194
|
-
const rows = [], preview = [];
|
|
195
|
-
const previewTail = status !== "ok";
|
|
196
|
-
const folded = block.kind === "sources" ? sourceSummary(block.calls) : null;
|
|
197
|
-
if (folded && !full) return { tool, title: call.tool === "local_exec" ? `${call.summary} · this computer` : call.title ?? "", status, rows: [`${folded} · ok`], preview: [] };
|
|
198
|
-
if (folded) rows.push(folded);
|
|
199
|
-
for (const item of block.calls) {
|
|
200
|
-
const c = item.call, r = item.result;
|
|
201
|
-
const state = r?.status ?? (block.committed ? "no result recorded" : "running");
|
|
202
|
-
const exit = r?.exit_code !== undefined && r.exit_code !== null ? ` · exit ${r.exit_code}` : "";
|
|
203
|
-
const seconds = r?.seconds !== undefined && r.seconds !== null ? ` · ${r.seconds}s` : "";
|
|
204
|
-
if (engineering && (r || !block.committed)) rows.push(...taskLines([
|
|
205
|
-
{ kind: "tool_call", payload: c }, ...(r ? [{ kind: "tool_result", payload: r }] : []),
|
|
206
|
-
{ kind: "step_finished", payload: { step_id: c.step_id, title: c.title, status: "computed" } },
|
|
207
|
-
]));
|
|
208
|
-
rows.push(`${state}${exit}${seconds}`);
|
|
209
|
-
for (const file of r?.files_changed ?? []) rows.push(`wrote ${file.path} (${file.bytes} B)`);
|
|
210
|
-
if (r?.status === "denied" && r.stderr_excerpt) rows.push(r.stderr_excerpt);
|
|
211
|
-
if (full) {
|
|
212
|
-
rows.push(`Call: ${c.call_id}`, `Title: ${c.title ?? ""}`, `Summary: ${c.summary ?? ""}`);
|
|
213
|
-
if (r?.stdout_ref) rows.push(`stdout_ref: ${r.stdout_ref}`);
|
|
214
|
-
if (r) rows.push(`stdout excerpt:\n${r.stdout_excerpt || "(empty)"}`, `stderr excerpt:\n${r.stderr_excerpt || "(empty)"}`);
|
|
215
|
-
} else if (!folded && !engineering) {
|
|
216
|
-
// A failed call often carries its only explanation on stderr.
|
|
217
|
-
const text = (r?.status === "ok" ? r.stdout_excerpt : r?.stderr_excerpt || r?.stdout_excerpt) ?? "";
|
|
218
|
-
if (text) preview.push(...terminalText(text).split("\n").filter(line => line.trim()));
|
|
219
|
-
}
|
|
87
|
+
if (block.kind === "unknown") return { title: `Unknown event kind: ${block.eventKind}`, rows: ["This CLI cannot read it; next: vecteur update"], status: "unknown" };
|
|
88
|
+
const { call, result } = block;
|
|
89
|
+
const status = result ? (result.ok ? "ok" : "failed") : block.committed ? "no result recorded" : "running";
|
|
90
|
+
const rows = [];
|
|
91
|
+
if (full) {
|
|
92
|
+
rows.push(`Call: ${call.call_id}`, `Input: ${JSON.stringify(call.input)}`);
|
|
93
|
+
if (result) rows.push(`${status} · ${result.bytes} B`, `Output excerpt:\n${result.excerpt || "(empty)"}`);
|
|
94
|
+
} else if (result && !result.ok) {
|
|
95
|
+
// A failed call's last line is usually its cause.
|
|
96
|
+
const cause = result.excerpt.split("\n").filter(line => line.trim()).at(-1);
|
|
97
|
+
if (cause) rows.push(cause);
|
|
220
98
|
}
|
|
221
|
-
return { tool
|
|
99
|
+
return { tool: TOOL_LABEL(call.tool), title: call.title, status, rows };
|
|
222
100
|
}
|
|
223
101
|
|
|
224
|
-
/** Human text for plain/dumb and /details, never JSON or terminal escape sequences. */
|
|
102
|
+
/** Human text for plain/dumb and /details: one line per call, never JSON or terminal escape sequences. */
|
|
225
103
|
export function blockText(block, options = {}) {
|
|
226
104
|
const content = blockContent(block, options);
|
|
227
|
-
const head = `[${content.status
|
|
105
|
+
const head = `[${content.status}] ${content.tool ? content.tool + " " : ""}${content.title}`;
|
|
228
106
|
const rows = content.rows.map(terminalText);
|
|
229
|
-
const preview = content.preview ?? [];
|
|
230
|
-
if (preview.length) {
|
|
231
|
-
rows.push(...(content.previewTail ? preview.slice(-3) : preview.slice(0, 3)));
|
|
232
|
-
rows.push(preview.length > 3 ? "… output excerpt truncated · ctrl+o for the full block" : "output excerpt · ctrl+o for the full block");
|
|
233
|
-
}
|
|
234
107
|
return `${plainLine(head)}${rows.length ? ": " + rows.join("\n ") : ""}`;
|
|
235
108
|
}
|