@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/markdown.js
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
1
|
// GENERATED from frontend/src/run/markdown.ts; no runtime frontend dependency.
|
|
2
|
+
export const studyPath = (value) => value.replace(/(?<![\w.-])(?:\/work)?\/study\//g, '');
|
|
3
|
+
export const readerPaths = (source) => studyPath(source.replace(/`(?:\/work)?\/study\/?`|(?<![\w/.-])(?:\/work)?\/study\/?(?=[\s:;,.!?)]|$)/g, 'the study folder'));
|
|
4
|
+
const LISTED_FILE = /^\s*[-*]\s+`?[\w./-]+\.\w{1,5}`?\s*$/;
|
|
5
|
+
const LIST_LEAD = /^(?:\*\*)?(?:all\s+|the\s+)?(?:files?|deliverables?|outputs?|everything)\b[^\n]*:\s*(?:\*\*)?$/i;
|
|
6
|
+
export function withoutClosingFileList(source) {
|
|
7
|
+
const lines = source.split('\n');
|
|
8
|
+
const out = [];
|
|
9
|
+
for (let at = 0; at < lines.length; at += 1) {
|
|
10
|
+
if (LIST_LEAD.test(readerPaths(lines[at]).trim())) {
|
|
11
|
+
let end = at + 1;
|
|
12
|
+
while (end < lines.length && lines[end].trim() === '')
|
|
13
|
+
end += 1;
|
|
14
|
+
let last = end;
|
|
15
|
+
while (last < lines.length && LISTED_FILE.test(lines[last]))
|
|
16
|
+
last += 1;
|
|
17
|
+
if (last > end && (last === lines.length || !/^\s*[-*]\s/.test(lines[last]))) {
|
|
18
|
+
at = last - 1;
|
|
19
|
+
while (out.length && out.at(-1).trim() === '')
|
|
20
|
+
out.pop();
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
out.push(lines[at]);
|
|
25
|
+
}
|
|
26
|
+
return out.join('\n').trimEnd();
|
|
27
|
+
}
|
|
28
|
+
export function closeOpenMarks(source) {
|
|
29
|
+
if (source.split('\n').filter((line) => /^\s*```/.test(line)).length % 2)
|
|
30
|
+
return `${source}\n${'```'}`;
|
|
31
|
+
const text = /^\s*```/.test(source.split('\n').at(-1) ?? '') ? source : source.replace(/(?:\*\*|`)+$/, '');
|
|
32
|
+
const plain = text.replace(/```[\s\S]*?```/g, '');
|
|
33
|
+
const code = (plain.match(/`/g) ?? []).length % 2 === 1;
|
|
34
|
+
const bold = (plain.replace(/`[^`]*`?/g, '').match(/\*\*/g) ?? []).length % 2 === 1;
|
|
35
|
+
return `${text}${code ? '`' : ''}${bold && !code ? '**' : ''}`;
|
|
36
|
+
}
|
|
2
37
|
export function inlinePlain(inline) {
|
|
3
38
|
return inline.map((token) => token.text).join('');
|
|
4
39
|
}
|
|
5
|
-
export function tableGrid(block) {
|
|
6
|
-
const header = block.header.map(inlinePlain);
|
|
7
|
-
const rows = block.rows.map((row) => row.map(inlinePlain));
|
|
8
|
-
return header.length ? [header, ...rows] : rows;
|
|
9
|
-
}
|
|
10
40
|
const INLINE_PATTERN = /(!\[[^\]]*\]\([^)\s]+\)|`[^`]+`|\[[^\]\n]+\]\([^)\s]+\)|\*\*[^*]+\*\*|\*[^*]+\*|\$[A-Za-z_][A-Za-z0-9_.]*\$)/g;
|
|
11
41
|
const LINK_TOKEN = /^\[([^\]\n]+)\]\(([^)\s]+)\)$/;
|
|
12
42
|
const IMAGE_TOKEN = /^!\[([^\]]*)\]\(([^)\s]+)\)$/;
|
|
@@ -79,66 +109,6 @@ export function parseInline(text) {
|
|
|
79
109
|
}
|
|
80
110
|
return out;
|
|
81
111
|
}
|
|
82
|
-
export function withholdOpenTokens(text) {
|
|
83
|
-
const scrubbed = text.replace(/\\[*`$]/g, ' ');
|
|
84
|
-
const cuts = [];
|
|
85
|
-
const backticks = [...scrubbed.matchAll(/`/g)];
|
|
86
|
-
if (backticks.length % 2 === 1)
|
|
87
|
-
cuts.push(backticks[backticks.length - 1].index ?? 0);
|
|
88
|
-
const bolds = [...scrubbed.matchAll(/\*\*/g)];
|
|
89
|
-
if (bolds.length % 2 === 1)
|
|
90
|
-
cuts.push(bolds[bolds.length - 1].index ?? 0);
|
|
91
|
-
const openReference = /\$[A-Za-z_][A-Za-z0-9_.]*$/.exec(scrubbed);
|
|
92
|
-
if (openReference)
|
|
93
|
-
cuts.push(openReference.index);
|
|
94
|
-
const openLink = /\[[^\]\n]*\]\([^)\s]*$/.exec(scrubbed);
|
|
95
|
-
if (openLink)
|
|
96
|
-
cuts.push(openLink.index);
|
|
97
|
-
const tablePrefix = trailingTableDelimiterPrefix(text);
|
|
98
|
-
if (tablePrefix !== null)
|
|
99
|
-
cuts.push(tablePrefix);
|
|
100
|
-
if (!cuts.length)
|
|
101
|
-
return text;
|
|
102
|
-
return text.slice(0, Math.min(...cuts));
|
|
103
|
-
}
|
|
104
|
-
function trailingTableDelimiterPrefix(text) {
|
|
105
|
-
const lines = text.split('\n');
|
|
106
|
-
if (lines.length < 2)
|
|
107
|
-
return null;
|
|
108
|
-
const candidate = lines[lines.length - 1];
|
|
109
|
-
const header = lines[lines.length - 2];
|
|
110
|
-
if (!TABLE_ROW.test(candidate) || !TABLE_ROW.test(header))
|
|
111
|
-
return null;
|
|
112
|
-
if (lines.slice(0, -1).filter((line) => line.startsWith('```')).length % 2 === 1)
|
|
113
|
-
return null;
|
|
114
|
-
if (lines.length > 2 && TABLE_ROW.test(lines[lines.length - 3]))
|
|
115
|
-
return null;
|
|
116
|
-
const cells = (line) => line.trim().replace(/^\||\|$/g, '').split('|').map((cell) => cell.trim());
|
|
117
|
-
const delimiter = cells(candidate);
|
|
118
|
-
const headerCells = cells(header);
|
|
119
|
-
if (delimiter.length >= headerCells.length)
|
|
120
|
-
return null;
|
|
121
|
-
if (!delimiter.every((cell) => /^:?-+:?$/.test(cell)))
|
|
122
|
-
return null;
|
|
123
|
-
return text.lastIndexOf('\n') + 1;
|
|
124
|
-
}
|
|
125
|
-
export function splitStream(source) {
|
|
126
|
-
const lines = source.split('\n');
|
|
127
|
-
let fenceOpen = -1;
|
|
128
|
-
let offset = 0;
|
|
129
|
-
for (const line of lines) {
|
|
130
|
-
if (line.startsWith('```'))
|
|
131
|
-
fenceOpen = fenceOpen === -1 ? offset : -1;
|
|
132
|
-
offset += line.length + 1;
|
|
133
|
-
}
|
|
134
|
-
if (fenceOpen !== -1) {
|
|
135
|
-
return { frozen: source.slice(0, fenceOpen), tail: source.slice(fenceOpen) };
|
|
136
|
-
}
|
|
137
|
-
const boundary = source.lastIndexOf('\n\n');
|
|
138
|
-
if (boundary === -1)
|
|
139
|
-
return { frozen: '', tail: source };
|
|
140
|
-
return { frozen: source.slice(0, boundary + 2), tail: source.slice(boundary + 2) };
|
|
141
|
-
}
|
|
142
112
|
export function parseMarkdown(source) {
|
|
143
113
|
const blocks = [];
|
|
144
114
|
const lines = source.split('\n');
|
|
@@ -202,12 +172,15 @@ export function parseMarkdown(source) {
|
|
|
202
172
|
if (BULLET_ROW.test(line) || NUMBERED_ROW.test(line)) {
|
|
203
173
|
const ordered = NUMBERED_ROW.test(line);
|
|
204
174
|
const pattern = ordered ? NUMBERED_ROW : BULLET_ROW;
|
|
175
|
+
const base = /^\s*/.exec(line)[0].length;
|
|
205
176
|
const items = [];
|
|
206
177
|
while (index < lines.length) {
|
|
207
|
-
const
|
|
208
|
-
|
|
178
|
+
const indent = /^\s*/.exec(lines[index])[0].length;
|
|
179
|
+
const nested = indent >= base + 2 && items.length > 0;
|
|
180
|
+
const item = (nested ? BULLET_ROW.exec(lines[index]) ?? NUMBERED_ROW.exec(lines[index]) : pattern.exec(lines[index]));
|
|
181
|
+
if (!item || (!nested && indent > base + 1))
|
|
209
182
|
break;
|
|
210
|
-
items.push(parseInline(item[1]));
|
|
183
|
+
items.push({ inline: parseInline(item[1]), depth: nested ? 1 : 0, ordered: nested ? NUMBERED_ROW.test(lines[index]) : ordered });
|
|
211
184
|
index += 1;
|
|
212
185
|
}
|
|
213
186
|
blocks.push({ kind: 'list', ordered, items });
|
package/src/mcp.js
CHANGED
|
@@ -1,21 +1,53 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
|
|
1
4
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
2
5
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
3
6
|
import * as z from "zod/v4";
|
|
4
7
|
|
|
5
|
-
import { CliError, VecteurClient, redact } from "./client.js";
|
|
6
|
-
import { EVENT_KINDS,
|
|
8
|
+
import { CliError, OWNER_WORDED, VecteurClient, redact } from "./client.js";
|
|
9
|
+
import { EVENT_KINDS, STORED_WIRE_VERSIONS, TERMINAL_STATES } from "./contract.js";
|
|
7
10
|
import { canonicalJson } from "./format.js";
|
|
11
|
+
import { artifactToFolder, materialAttach } from "./exchange.js";
|
|
12
|
+
import { credentialsPath } from "./credentials.js";
|
|
13
|
+
import { readStore, withStoreLock, writeStore } from "./store.js";
|
|
8
14
|
|
|
9
15
|
const projectInput = z.object({ project_id: z.string().min(1) }).strict();
|
|
16
|
+
// The composer's selection shape: one exact-extract selection per material source (the
|
|
17
|
+
// `selections` that vecteur_material_attach returns).
|
|
18
|
+
const selectionInput = z.object({
|
|
19
|
+
source_handle: z.object({ cas_ref: z.string().regex(/^sha256:[0-9a-f]{64}$/), acquisition_ref: z.string().min(1) }).strict(),
|
|
20
|
+
offer_id: z.string().min(1),
|
|
21
|
+
selected_extract_ids: z.array(z.string().min(1)).min(1),
|
|
22
|
+
method: z.literal("exact-extract"),
|
|
23
|
+
}).strict();
|
|
10
24
|
const submitInput = z.object({
|
|
11
25
|
project_id: z.string().min(1),
|
|
12
26
|
ask: z.string().min(1),
|
|
27
|
+
selections: z.array(selectionInput).min(1).optional(),
|
|
28
|
+
discard_pending_material: z.boolean().optional(),
|
|
13
29
|
}).strict();
|
|
14
30
|
const runInput = z.object({ run_id: z.string().min(1) }).strict();
|
|
15
|
-
const
|
|
31
|
+
const startInput = z.object({
|
|
32
|
+
project_id: z.string().min(1), ask: z.string().min(1),
|
|
33
|
+
selections: z.array(selectionInput).min(1).optional(),
|
|
34
|
+
discard_pending_material: z.boolean().optional(),
|
|
35
|
+
request_key: z.string().regex(/^[A-Za-z0-9_-]{8,64}$/),
|
|
36
|
+
parent_state_hash: z.string().regex(/^[0-9a-f]{64}$/).nullable().optional(),
|
|
37
|
+
}).strict();
|
|
38
|
+
const ackFields = {
|
|
39
|
+
run_id: z.string().min(1), state_hash: z.string().min(1),
|
|
40
|
+
accepted_at: z.number().int().safe(), requested_route_id: z.string().min(1),
|
|
41
|
+
};
|
|
42
|
+
const startOutput = z.object({ ...ackFields, parent_state_hash: z.string().nullable() }).strict();
|
|
43
|
+
// The four wire v6 states, or "" while the Run is open.
|
|
44
|
+
const terminalOutput = z.union([z.enum([...TERMINAL_STATES]), z.literal("")]);
|
|
45
|
+
const statusOutput = z.object({
|
|
46
|
+
run_id: z.string().min(1), terminal: terminalOutput, last_seq: z.number().int().safe().min(-1),
|
|
47
|
+
}).strict();
|
|
16
48
|
const eventOutput = z.object({
|
|
17
49
|
run_id: z.string().min(1), seq: z.number().int().safe().nonnegative(),
|
|
18
|
-
kind:
|
|
50
|
+
kind: z.enum([...EVENT_KINDS]),
|
|
19
51
|
payload: z.record(z.string(), z.json()),
|
|
20
52
|
}).strict();
|
|
21
53
|
const memberOutput = z.object({
|
|
@@ -27,47 +59,46 @@ const projectOutput = z.object({
|
|
|
27
59
|
workspace_id: z.string().min(1), role: z.enum(["OWNER", "EDITOR", "VIEWER"]),
|
|
28
60
|
members: z.array(memberOutput),
|
|
29
61
|
created_at: z.number().int().safe(), updated_at: z.number().int().safe(),
|
|
62
|
+
engine: z.enum(["v5", "v6"]).optional(),
|
|
30
63
|
}).strict();
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}).strict();
|
|
41
|
-
const runControlEgressOutput = z.object({
|
|
42
|
-
candidate: z.number().int().safe().nonnegative(),
|
|
43
|
-
call: z.number().int().safe().nonnegative(),
|
|
44
|
-
}).strict();
|
|
45
|
-
const runControlOutput = z.object({
|
|
46
|
-
id: z.string().min(1),
|
|
47
|
-
kind: z.enum(["steer", "answer_now"]),
|
|
48
|
-
sequence: z.number().int().safe().positive(),
|
|
49
|
-
state: z.enum(["queued", "claimed", "dispatched", "not_dispatched"]),
|
|
50
|
-
attempt: z.number().int().safe().nonnegative().nullable(),
|
|
51
|
-
step: z.number().int().safe().nonnegative().nullable(),
|
|
52
|
-
egress: runControlEgressOutput.nullable(),
|
|
53
|
-
text: z.string().nullable().optional(),
|
|
54
|
-
}).strict();
|
|
55
|
-
const admittedOutput = z.object({
|
|
56
|
-
run_id: z.string().min(1), state_hash: z.string().min(1), result_hash: z.string(),
|
|
57
|
-
requested_route_id: z.string().min(1), profile: z.string().min(1),
|
|
58
|
-
stored_wire_version: z.union([z.literal(1), z.literal(2)]),
|
|
59
|
-
terminal: z.union([z.enum([...TERMINAL_STATES]), z.literal("")]),
|
|
64
|
+
// The owner's RunRecord, field for field; identity, state and events are checked, usage is the owner's object as served.
|
|
65
|
+
const runOutput = z.object({
|
|
66
|
+
run_id: z.string().min(1), project_id: z.string().min(1).optional(),
|
|
67
|
+
state_hash: z.string().regex(/^[0-9a-f]{64}$/), result_hash: z.string(),
|
|
68
|
+
requested_route_id: z.string().min(1).optional(), profile: z.string().optional(),
|
|
69
|
+
stored_wire_version: z.union(STORED_WIRE_VERSIONS.map(version => z.literal(version))).optional(),
|
|
70
|
+
terminal: terminalOutput,
|
|
71
|
+
usage: z.record(z.string(), z.json()).nullable().optional(),
|
|
72
|
+
accepted_at: z.number().int().safe().optional(),
|
|
60
73
|
duration_seconds: z.number().int().safe().nonnegative().nullable().optional(),
|
|
61
|
-
usage: z.object({
|
|
62
|
-
coverage: z.enum(["complete", "incomplete"]), provider_id: z.string().min(1),
|
|
63
|
-
model_id: z.string().min(1), observed_at: z.number().int().safe().nonnegative(),
|
|
64
|
-
billable_dimensions: z.array(billableDimensionsOutput).min(1),
|
|
65
|
-
}).strict(),
|
|
66
74
|
events: z.array(eventOutput),
|
|
67
|
-
controls: z.array(runControlOutput),
|
|
68
75
|
}).strict().refine(value => value.terminal === ""
|
|
69
76
|
? value.result_hash === "" && value.events.at(-1)?.kind !== "terminal"
|
|
70
|
-
: value.result_hash.length > 0, "Run terminal and result hash are not paired");
|
|
77
|
+
: value.result_hash.length > 0 && value.events.at(-1)?.kind === "terminal", "Run terminal and result hash are not paired");
|
|
78
|
+
|
|
79
|
+
const artifactInput = z.object({
|
|
80
|
+
project_id: z.string().min(1),
|
|
81
|
+
cas_ref: z.string().regex(/^sha256:[0-9a-f]{64}$/).optional(),
|
|
82
|
+
run_id: z.string().min(1).optional(),
|
|
83
|
+
artifact_path: z.string().min(1).optional(),
|
|
84
|
+
output: z.string().min(1).optional(),
|
|
85
|
+
}).strict();
|
|
86
|
+
const artifactOutput = z.object({
|
|
87
|
+
path: z.string().min(1), bytes: z.number().int().safe().nonnegative(),
|
|
88
|
+
cas_ref: z.string().regex(/^sha256:[0-9a-f]{64}$/), content_type: z.string().min(1), verified: z.literal(true),
|
|
89
|
+
}).strict();
|
|
90
|
+
const materialInput = z.object({
|
|
91
|
+
project_id: z.string().min(1), path: z.string().min(1),
|
|
92
|
+
confirm_origin: z.string().min(1),
|
|
93
|
+
expected_state_hash: z.string().min(1).nullable(),
|
|
94
|
+
}).strict();
|
|
95
|
+
const materialOutput = z.object({
|
|
96
|
+
project_id: z.string().min(1), project_name: z.string().min(1), destination: z.string().min(1),
|
|
97
|
+
filename: z.string().min(1), bytes: z.number().int().safe().positive(),
|
|
98
|
+
cas_ref: z.string().min(1), acquisition_ref: z.string().min(1), offer_id: z.string().min(1),
|
|
99
|
+
extract_count: z.number().int().safe().nonnegative(),
|
|
100
|
+
selections: z.array(selectionInput).min(1),
|
|
101
|
+
}).strict();
|
|
71
102
|
|
|
72
103
|
function success(value) {
|
|
73
104
|
return {
|
|
@@ -76,27 +107,62 @@ function success(value) {
|
|
|
76
107
|
};
|
|
77
108
|
}
|
|
78
109
|
|
|
79
|
-
function failure(error) {
|
|
110
|
+
function failure(error, lifecycle = false) {
|
|
80
111
|
const code = error instanceof CliError && /^[a-z][a-z0-9_]{0,63}$/.test(error.code)
|
|
81
112
|
? error.code : "internal_error";
|
|
113
|
+
// A read-only (v5) Project and a retired door carry the owner's own sentence (validated by the client).
|
|
114
|
+
const message = OWNER_WORDED.includes(code) ? { message: error.message } : {};
|
|
115
|
+
const details = Object.fromEntries((lifecycle ? ["run_id", "request_key", "parent_state_hash", "pending"] : ["run_id", "pending"])
|
|
116
|
+
.filter(field => error instanceof CliError && Object.hasOwn(error, field))
|
|
117
|
+
.map(field => [field, typeof error[field] === "string" ? redact(error[field]) : error[field]]));
|
|
82
118
|
return {
|
|
83
119
|
isError: true,
|
|
84
|
-
content: [{ type: "text", text: canonicalJson({ error: { code } }) }],
|
|
120
|
+
content: [{ type: "text", text: canonicalJson({ error: { code, ...message, ...details } }) }],
|
|
85
121
|
};
|
|
86
122
|
}
|
|
87
123
|
|
|
88
|
-
function tool(server, name, description, inputSchema, outputSchema, call) {
|
|
124
|
+
function tool(server, name, description, inputSchema, outputSchema, call, lifecycle = false) {
|
|
89
125
|
server.registerTool(name, { description, inputSchema, outputSchema }, async (input, context) => {
|
|
90
126
|
try {
|
|
91
127
|
return success(await call(input, context));
|
|
92
128
|
} catch (error) {
|
|
93
|
-
return failure(error);
|
|
129
|
+
return failure(error, lifecycle);
|
|
94
130
|
}
|
|
95
131
|
});
|
|
96
132
|
}
|
|
97
133
|
|
|
98
134
|
export function createVecteurMcpServer(client = new VecteurClient(), shutdownSignal = undefined) {
|
|
99
135
|
const server = new McpServer({ name: "vecteur", version: "0.1.0" });
|
|
136
|
+
// Upload is not admission. Pending material lives in the private local store beside the login,
|
|
137
|
+
// so a restarted server still refuses a submit/start that omits it. It is kept until a submit/start
|
|
138
|
+
// succeeds, including after refusals, unless the caller deliberately discards this Project's material.
|
|
139
|
+
const origin = client.config.origin, file = join(dirname(credentialsPath()), "mcp-pending.json");
|
|
140
|
+
const pendingStore = () => {
|
|
141
|
+
const value = readStore(file) ?? { version: 1, pending: {} };
|
|
142
|
+
if (value.version !== 1 || !value.pending || typeof value.pending !== "object") throw new CliError("store_unreadable", `${file} is not a pending-material store; bytes preserved`);
|
|
143
|
+
return value;
|
|
144
|
+
};
|
|
145
|
+
const updatePending = change => withStoreLock(file, () => { const value = pendingStore(); change(value.pending); writeStore(file, value); });
|
|
146
|
+
// One entry per Project and bytes: re-attaching the same file replaces its handle (the recovery after a restart).
|
|
147
|
+
const materialKey = (projectId, casRef) => canonicalJson([origin, projectId, casRef]);
|
|
148
|
+
const withMaterial = async (projectId, selections, discardPendingMaterial, call) => {
|
|
149
|
+
const pending = Object.entries(pendingStore().pending).filter(([, value]) => value.origin === origin && value.projectId === projectId);
|
|
150
|
+
const selected = new Set((selections ?? []).map(value => canonicalJson([value.source_handle.cas_ref, value.source_handle.acquisition_ref])));
|
|
151
|
+
if (discardPendingMaterial) {
|
|
152
|
+
if (pending.length) updatePending(store => { for (const [key] of pending) delete store[key]; });
|
|
153
|
+
} else if (pending.some(([, value]) => !selected.has(canonicalJson([value.cas_ref, value.acquisition_ref])))) {
|
|
154
|
+
// Name what is pending: a session that lost the selections re-attaches that file rather than discarding blind.
|
|
155
|
+
throw Object.assign(new CliError("selection_required", "Pass the attached material's returned selections to submit or start"),
|
|
156
|
+
{ pending: pending.map(([, value]) => value.cas_ref) });
|
|
157
|
+
}
|
|
158
|
+
const result = await call();
|
|
159
|
+
// The Run is admitted: a store failure now must not read as a refusal (a retry would admit a second Run).
|
|
160
|
+
// A leftover entry fails closed on the next call, where the caller can re-attach or discard.
|
|
161
|
+
if (!discardPendingMaterial && pending.length) try { updatePending(store => {
|
|
162
|
+
for (const [key, value] of pending) if (store[key]?.nonce === value.nonce) delete store[key];
|
|
163
|
+
}); } catch { /* fail closed: the entry stays pending */ }
|
|
164
|
+
return result;
|
|
165
|
+
};
|
|
100
166
|
const signal = (context) => shutdownSignal
|
|
101
167
|
? AbortSignal.any([context.mcpReq.signal, shutdownSignal]) : context.mcpReq.signal;
|
|
102
168
|
|
|
@@ -104,25 +170,48 @@ export function createVecteurMcpServer(client = new VecteurClient(), shutdownSig
|
|
|
104
170
|
({ project_id: projectId }, context) => client.projectGet(projectId, signal(context)));
|
|
105
171
|
|
|
106
172
|
tool(server, "vecteur_run_submit",
|
|
107
|
-
"Submit
|
|
108
|
-
submitInput,
|
|
173
|
+
"Submit an ask and return its terminal record. Pass vecteur_material_attach's returned selections verbatim; omitting this Project's pending material refuses, also after a server restart (attach again for its selections). Set discard_pending_material=true to forget this Project's pending material and use only the supplied selections (or none). For long Runs use vecteur_run_start and poll vecteur_run_status.",
|
|
174
|
+
submitInput, runOutput, async ({ project_id: projectId, ask, selections, discard_pending_material }, context) => {
|
|
109
175
|
const progressToken = context.mcpReq._meta?.progressToken;
|
|
110
176
|
const onEvent = progressToken === undefined ? null : (event) => context.mcpReq.notify({
|
|
111
177
|
method: "notifications/progress",
|
|
112
178
|
params: {
|
|
113
179
|
progressToken,
|
|
114
|
-
progress: event.seq
|
|
180
|
+
progress: event.seq, // events are numbered from 1 (wire.js FIRST_EVENT_SEQ): the count delivered
|
|
115
181
|
message: event.kind,
|
|
116
182
|
},
|
|
117
183
|
});
|
|
118
|
-
return client.runSubmit(projectId, ask, onEvent, signal(context));
|
|
184
|
+
return withMaterial(projectId, selections, discard_pending_material, () => client.runSubmit(projectId, ask, onEvent, signal(context), undefined, selections));
|
|
119
185
|
});
|
|
120
186
|
|
|
121
|
-
tool(server, "vecteur_run_get", "Get one Vecteur run record, including an open run.", runInput,
|
|
187
|
+
tool(server, "vecteur_run_get", "Get one Vecteur run record, including an open run.", runInput, runOutput,
|
|
122
188
|
({ run_id: runId }, context) => client.runGet(runId, signal(context)));
|
|
123
189
|
|
|
124
190
|
tool(server, "vecteur_run_events", "Validate run events against its direct record.", runInput,
|
|
125
|
-
|
|
191
|
+
runOutput, ({ run_id: runId }, context) => client.runEvents(runId, null, signal(context)));
|
|
192
|
+
|
|
193
|
+
tool(server, "vecteur_run_start", "Admit without waiting. Pass attached material's returned selections verbatim; omitting this Project's pending material refuses, also after a server restart (attach again for its selections). Set discard_pending_material=true to forget this Project's pending material and use only the supplied selections (or none). Freeze request_key, ask and parent_state_hash (null for no head) for retries. Detaching never cancels.",
|
|
194
|
+
startInput, startOutput, ({ project_id, ask, request_key, parent_state_hash, selections, discard_pending_material }, context) =>
|
|
195
|
+
withMaterial(project_id, selections, discard_pending_material, () => client.runStart(project_id, ask, {
|
|
196
|
+
requestKey: request_key, parentStateHash: parent_state_hash, selections, signal: signal(context),
|
|
197
|
+
})), true);
|
|
198
|
+
tool(server, "vecteur_run_status", "Poll one bounded Run record: its terminal state (completed, failed, cancelled, budget; empty while open) and last event sequence. A question from the agent is its answer; reply with a new ask.",
|
|
199
|
+
runInput, statusOutput, ({ run_id }, context) => client.runStatus(run_id, signal(context)), true);
|
|
200
|
+
|
|
201
|
+
const cwd = process.cwd();
|
|
202
|
+
tool(server, "vecteur_artifact_get",
|
|
203
|
+
"Download one run artifact into the server's working folder (never outside it), verified against its sha256 CAS id. Give cas_ref, or run_id with artifact_path. Never overwrites.",
|
|
204
|
+
artifactInput, artifactOutput, ({ project_id: projectId, cas_ref: casRef, run_id: runId, artifact_path: artifactPath, output }, context) =>
|
|
205
|
+
artifactToFolder(client, { projectId, casRef, runId, artifactPath, output, cwd, signal: signal(context) }));
|
|
206
|
+
|
|
207
|
+
tool(server, "vecteur_material_attach",
|
|
208
|
+
`Upload one local file to ${client.config.origin}. Pass the returned selections verbatim to vecteur_run_submit or vecteur_run_start for this Project; upload alone is not Run admission. Requires confirm_origin equal to that origin and expected_state_hash equal to the current head (null if none).`,
|
|
209
|
+
materialInput, materialOutput, async ({ project_id: projectId, path, confirm_origin: confirmOrigin, expected_state_hash: expectedStateHash }, context) => {
|
|
210
|
+
const result = await materialAttach(client, { projectId, path, confirmOrigin, expectedStateHash, cwd, signal: signal(context) });
|
|
211
|
+
updatePending(store => { for (const { source_handle: handle } of result.selections) store[materialKey(projectId, handle.cas_ref)] = {
|
|
212
|
+
origin, projectId, cas_ref: handle.cas_ref, acquisition_ref: handle.acquisition_ref, nonce: randomUUID() }; });
|
|
213
|
+
return result;
|
|
214
|
+
});
|
|
126
215
|
|
|
127
216
|
return server;
|
|
128
217
|
}
|