@vecteur/cli 0.10.0 → 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 +216 -24
- package/bin/vecteur.js +72 -46
- package/package.json +5 -1
- package/src/blocks.js +88 -20
- package/src/client.js +192 -167
- package/src/commands.js +26 -22
- package/src/contract.js +25 -38
- package/src/credentials.js +8 -0
- package/src/download.js +2 -7
- package/src/errors.js +4 -1
- package/src/exchange.js +86 -0
- package/src/folders.js +28 -2
- package/src/format.js +109 -342
- package/src/input.js +7 -3
- package/src/localfiles.js +766 -0
- package/src/markdown.js +41 -68
- package/src/mcp.js +139 -50
- package/src/session.js +464 -185
- package/src/stop-words.js +19 -0
- package/src/terminal.js +52 -37
- package/src/tui/view.js +108 -72
- package/src/wire.js +73 -0
package/src/wire.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Wire v6 as this door reads it: one run is one turn; an event is `{run_id, seq, kind, payload}`.
|
|
2
|
+
* The vocabularies are the owner's (`contract.js`, generated); the payload shapes below follow `runner/wire.py`.
|
|
3
|
+
* Anything this reader does not know is refused by name, never rendered as a success. */
|
|
4
|
+
import { EVENT_KINDS, STORED_WIRE_VERSIONS, TERMINAL_DEFECTS, TERMINAL_STATES, TOOL_KINDS } from "./contract.js";
|
|
5
|
+
import { CliError } from "./errors.js";
|
|
6
|
+
|
|
7
|
+
const CAS_REF = /^sha256:[0-9a-f]{64}$/;
|
|
8
|
+
const STATE_HASH = /^[0-9a-f]{64}$/;
|
|
9
|
+
const object = value => !!value && typeof value === "object" && !Array.isArray(value);
|
|
10
|
+
const text = value => typeof value === "string" && value.length > 0;
|
|
11
|
+
const count = value => Number.isSafeInteger(value) && value >= 0;
|
|
12
|
+
|
|
13
|
+
export const isStateHash = value => typeof value === "string" && STATE_HASH.test(value);
|
|
14
|
+
|
|
15
|
+
/** One check per kind; a payload may carry more than these fields, never less. */
|
|
16
|
+
const PAYLOADS = {
|
|
17
|
+
assistant_delta: p => typeof p.text === "string",
|
|
18
|
+
tool_call: p => text(p.call_id) && TOOL_KINDS.includes(p.tool) && typeof p.title === "string" && object(p.input),
|
|
19
|
+
tool_result: p => text(p.call_id) && typeof p.ok === "boolean" && typeof p.excerpt === "string" && count(p.bytes),
|
|
20
|
+
synthesis: p => typeof p.markdown === "string",
|
|
21
|
+
artifact: p => text(p.path) && count(p.revision) && CAS_REF.test(p.cas_ref) && text(p.media_type) && count(p.bytes) && text(p.kind),
|
|
22
|
+
study: p => CAS_REF.test(p.cas_ref),
|
|
23
|
+
review: p => CAS_REF.test(p.cas_ref) && text(p.verdict),
|
|
24
|
+
terminal: p => (p.defect === undefined || TERMINAL_DEFECTS.includes(p.defect)) && (p.usage === null || object(p.usage)),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** The runner numbers a run's events from 1 (runner/store.py `append`) and resumes after the Last-Event-ID it is sent. */
|
|
28
|
+
export const FIRST_EVENT_SEQ = 1;
|
|
29
|
+
|
|
30
|
+
export function validateEvent(value, runId, expectedSeq) {
|
|
31
|
+
if (!object(value) || Object.keys(value).sort().join(",") !== "kind,payload,run_id,seq") {
|
|
32
|
+
throw new CliError("event_invalid", "Server returned malformed owner data");
|
|
33
|
+
}
|
|
34
|
+
if (value.run_id !== runId || value.seq !== expectedSeq) {
|
|
35
|
+
throw new CliError("event_sequence_invalid", `Expected event sequence ${expectedSeq}`);
|
|
36
|
+
}
|
|
37
|
+
if (!EVENT_KINDS.includes(value.kind)) {
|
|
38
|
+
throw new CliError("event_kind_unknown", `Run event ${expectedSeq} has a kind this CLI does not know (${String(value.kind).slice(0, 40)}); next: vecteur update`);
|
|
39
|
+
}
|
|
40
|
+
if (value.kind === "terminal" && object(value.payload) && !TERMINAL_STATES.includes(value.payload.state)) {
|
|
41
|
+
throw new CliError("terminal_state_unknown", `Run ended in a state this CLI does not know (${String(value.payload.state).slice(0, 40)}); next: vecteur update`);
|
|
42
|
+
}
|
|
43
|
+
if (!object(value.payload) || !PAYLOADS[value.kind](value.payload)) {
|
|
44
|
+
throw new CliError("event_invalid", `Run event ${expectedSeq} (${value.kind}) is malformed`);
|
|
45
|
+
}
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The run record: an open run has no terminal and no result hash; a closed one has both, and its last event says the same state. */
|
|
50
|
+
export function validateRun(value, runId = value?.run_id) {
|
|
51
|
+
const invalid = why => new CliError("run_invalid", `Server returned malformed run record (${why})`);
|
|
52
|
+
if (!object(value) || !text(value.run_id) || value.run_id !== runId) throw invalid("identity");
|
|
53
|
+
if (!isStateHash(value.state_hash)) throw invalid("state_hash");
|
|
54
|
+
if (typeof value.result_hash !== "string" || typeof value.terminal !== "string" || !Array.isArray(value.events)) throw invalid("shape");
|
|
55
|
+
if (value.stored_wire_version !== undefined && !STORED_WIRE_VERSIONS.includes(value.stored_wire_version)) {
|
|
56
|
+
throw new CliError("wire_version_unsupported", "this Run is stored in a wire version this CLI cannot read; next: vecteur update");
|
|
57
|
+
}
|
|
58
|
+
if (value.duration_seconds !== undefined && value.duration_seconds !== null && !count(value.duration_seconds)) throw invalid("duration_seconds");
|
|
59
|
+
value.events.forEach((event, index) => validateEvent(event, value.run_id, FIRST_EVENT_SEQ + index));
|
|
60
|
+
const last = value.events.at(-1);
|
|
61
|
+
if (value.events.some((event, index) => event.kind === "terminal" && index !== value.events.length - 1)) throw invalid("events after terminal");
|
|
62
|
+
if (value.terminal === "") {
|
|
63
|
+
if (value.result_hash !== "" || last?.kind === "terminal") throw invalid("open run carries a result");
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
if (!TERMINAL_STATES.includes(value.terminal)) {
|
|
67
|
+
throw new CliError("terminal_state_unknown", `Run ended in a state this CLI does not know (${value.terminal.slice(0, 40)}); next: vecteur update`);
|
|
68
|
+
}
|
|
69
|
+
if (!value.result_hash) throw invalid("terminal without result_hash");
|
|
70
|
+
if (last?.kind !== "terminal") throw new CliError("terminal_invalid", "Run record has no final terminal event");
|
|
71
|
+
if (last.payload.state !== value.terminal) throw new CliError("terminal_mismatch", "Run terminal event disagrees with its record");
|
|
72
|
+
return value;
|
|
73
|
+
}
|