xvcache-mcp 0.0.0-stage → 0.1.0
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/AGENTS.md +63 -0
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +182 -2
- package/SECURITY.md +25 -0
- package/TRADEMARK.md +17 -0
- package/dist/journal.js +295 -0
- package/dist/plans.js +123 -0
- package/dist/server.js +510 -0
- package/dist/verify-journal.js +23 -0
- package/llms.txt +35 -0
- package/package.json +61 -4
- package/plans.json +150 -0
- package/server.json +38 -0
package/dist/server.js
ADDED
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { promises as fs } from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { JournalWriter, sha256Hex, verifyJournalFile, formatChainMessage, readCompleteJournalLines, parseEntry, lastNoteRecord, formatNoteVerdict, } from "./journal.js";
|
|
8
|
+
import { getOffer, loadPlansCatalog, recommendPlan, requestUpgrade, certifyNoteStub } from "./plans.js";
|
|
9
|
+
function envVault() {
|
|
10
|
+
return process.env.XVCACHE_VAULT || process.env.JAYCACHE_VAULT;
|
|
11
|
+
}
|
|
12
|
+
function envLog() {
|
|
13
|
+
return process.env.XVCACHE_LOG || process.env.JAYCACHE_LOG;
|
|
14
|
+
}
|
|
15
|
+
const VAULT = envVault();
|
|
16
|
+
if (!VAULT) {
|
|
17
|
+
console.error("XVCACHE_VAULT manquant (JAYCACHE_VAULT accepté comme alias)");
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
const vaultRoot = await fs.realpath(path.resolve(VAULT));
|
|
21
|
+
const defaultLog = path.resolve(vaultRoot, "..", "xvcache-journal.jsonl");
|
|
22
|
+
const logEnv = envLog();
|
|
23
|
+
const journalPath = logEnv ? path.resolve(logEnv) : defaultLog;
|
|
24
|
+
if (journalPath === vaultRoot || journalPath.startsWith(vaultRoot + path.sep)) {
|
|
25
|
+
console.error("XVCACHE_LOG ne doit pas être à l'intérieur du coffre (JAYCACHE_LOG accepté comme alias)");
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
const journal = new JournalWriter(journalPath);
|
|
29
|
+
function clientName() {
|
|
30
|
+
return server.server.getClientVersion()?.name ?? null;
|
|
31
|
+
}
|
|
32
|
+
async function logTool(tool, args, result, note_sha256) {
|
|
33
|
+
await journal.append({ tool, args, client: clientName(), result, note_sha256 });
|
|
34
|
+
}
|
|
35
|
+
function toolText(result) {
|
|
36
|
+
return result.content.filter((c) => c.type === "text").map((c) => c.text ?? "").join("");
|
|
37
|
+
}
|
|
38
|
+
function fail(msg) {
|
|
39
|
+
return { isError: true, content: [{ type: "text", text: msg }] };
|
|
40
|
+
}
|
|
41
|
+
function ok(text) {
|
|
42
|
+
return { content: [{ type: "text", text }] };
|
|
43
|
+
}
|
|
44
|
+
function fold(s) {
|
|
45
|
+
return s.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
|
|
46
|
+
}
|
|
47
|
+
/** Maps each character of the folded string back to an index in the original. */
|
|
48
|
+
function foldMap(s) {
|
|
49
|
+
let folded = "";
|
|
50
|
+
const map = [];
|
|
51
|
+
for (let i = 0; i < s.length; i++) {
|
|
52
|
+
const f = s[i].normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
|
|
53
|
+
for (const ch of f) {
|
|
54
|
+
folded += ch;
|
|
55
|
+
map.push(i);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return { folded, map };
|
|
59
|
+
}
|
|
60
|
+
function countHits(haystack, needle) {
|
|
61
|
+
if (!needle)
|
|
62
|
+
return 0;
|
|
63
|
+
const h = fold(haystack);
|
|
64
|
+
let count = 0;
|
|
65
|
+
let pos = 0;
|
|
66
|
+
while (pos <= h.length - needle.length) {
|
|
67
|
+
const i = h.indexOf(needle, pos);
|
|
68
|
+
if (i < 0)
|
|
69
|
+
break;
|
|
70
|
+
count++;
|
|
71
|
+
pos = i + needle.length;
|
|
72
|
+
}
|
|
73
|
+
return count;
|
|
74
|
+
}
|
|
75
|
+
function snippetAround(text, needle, width = 160) {
|
|
76
|
+
const { folded, map } = foldMap(text);
|
|
77
|
+
const i = folded.indexOf(needle);
|
|
78
|
+
if (i < 0 || map.length === 0) {
|
|
79
|
+
const cut = text.replace(/\s+/g, " ").trim().slice(0, width);
|
|
80
|
+
return text.trim().length > width ? cut + "…" : cut;
|
|
81
|
+
}
|
|
82
|
+
const startOrig = map[i];
|
|
83
|
+
const lastFold = i + needle.length - 1;
|
|
84
|
+
const endOrig = (lastFold >= 0 && lastFold < map.length ? map[lastFold] : startOrig) + 1;
|
|
85
|
+
const pad = Math.max(0, Math.floor((width - (endOrig - startOrig)) / 2));
|
|
86
|
+
let from = Math.max(0, startOrig - pad);
|
|
87
|
+
let to = Math.min(text.length, from + width);
|
|
88
|
+
if (to - from < width)
|
|
89
|
+
from = Math.max(0, to - width);
|
|
90
|
+
let snip = text.slice(from, to).replace(/\s+/g, " ").trim();
|
|
91
|
+
if (from > 0)
|
|
92
|
+
snip = "…" + snip;
|
|
93
|
+
if (to < text.length)
|
|
94
|
+
snip = snip + "…";
|
|
95
|
+
return snip;
|
|
96
|
+
}
|
|
97
|
+
function parseNote(text) {
|
|
98
|
+
const m = text.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
|
|
99
|
+
if (!m)
|
|
100
|
+
return { title: undefined, tags: [], body: text };
|
|
101
|
+
const fm = m[1];
|
|
102
|
+
const body = text.slice(m[0].length);
|
|
103
|
+
let title;
|
|
104
|
+
const titleM = fm.match(/^title:\s*(.+)$/m);
|
|
105
|
+
if (titleM)
|
|
106
|
+
title = titleM[1].trim().replace(/^['"]|['"]$/g, "");
|
|
107
|
+
const tags = [];
|
|
108
|
+
const tagsInline = fm.match(/^tags:\s*\[([^\]]*)\]/m);
|
|
109
|
+
if (tagsInline) {
|
|
110
|
+
for (const t of tagsInline[1].split(",")) {
|
|
111
|
+
const v = t.trim().replace(/^['"]|['"]$/g, "");
|
|
112
|
+
if (v)
|
|
113
|
+
tags.push(v);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
const block = fm.match(/^tags:\s*\r?\n((?:[ \t]+- .+(?:\r?\n|$))*)/m);
|
|
118
|
+
if (block) {
|
|
119
|
+
for (const line of block[1].split(/\r?\n/)) {
|
|
120
|
+
const tm = line.match(/^\s*-\s+(.+)$/);
|
|
121
|
+
if (tm)
|
|
122
|
+
tags.push(tm[1].trim().replace(/^['"]|['"]$/g, ""));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return { title, tags, body };
|
|
127
|
+
}
|
|
128
|
+
function insideVault(real) {
|
|
129
|
+
return real === vaultRoot || real.startsWith(vaultRoot + path.sep);
|
|
130
|
+
}
|
|
131
|
+
async function listVaultMarkdown() {
|
|
132
|
+
const files = [];
|
|
133
|
+
const visited = new Set();
|
|
134
|
+
async function walk(dirReal) {
|
|
135
|
+
if (visited.has(dirReal))
|
|
136
|
+
return;
|
|
137
|
+
visited.add(dirReal);
|
|
138
|
+
let entries;
|
|
139
|
+
try {
|
|
140
|
+
entries = await fs.readdir(dirReal, { withFileTypes: true });
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
for (const ent of entries) {
|
|
146
|
+
const full = path.join(dirReal, ent.name);
|
|
147
|
+
let real;
|
|
148
|
+
try {
|
|
149
|
+
real = await fs.realpath(full);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (!insideVault(real))
|
|
155
|
+
continue;
|
|
156
|
+
let st;
|
|
157
|
+
try {
|
|
158
|
+
st = await fs.stat(real);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (st.isDirectory())
|
|
164
|
+
await walk(real);
|
|
165
|
+
else if (st.isFile() && real.toLowerCase().endsWith(".md"))
|
|
166
|
+
files.push(real);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
await walk(vaultRoot);
|
|
170
|
+
return files;
|
|
171
|
+
}
|
|
172
|
+
const TITLE_W = 1_000_000;
|
|
173
|
+
const TAG_W = 1_000;
|
|
174
|
+
const BODY_W = 1;
|
|
175
|
+
async function searchNotes(query, limit) {
|
|
176
|
+
const trimmed = query.trim();
|
|
177
|
+
const needle = fold(trimmed);
|
|
178
|
+
if (!trimmed || !needle)
|
|
179
|
+
return { error: "Refusé : requête vide." };
|
|
180
|
+
const files = await listVaultMarkdown();
|
|
181
|
+
const hits = [];
|
|
182
|
+
for (const real of files) {
|
|
183
|
+
if (!insideVault(real))
|
|
184
|
+
continue;
|
|
185
|
+
let text;
|
|
186
|
+
try {
|
|
187
|
+
text = await fs.readFile(real, "utf8");
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const parsed = parseNote(text);
|
|
193
|
+
const rel = path.relative(vaultRoot, real).split(path.sep).join("/");
|
|
194
|
+
const title = parsed.title || path.basename(rel, path.extname(rel));
|
|
195
|
+
const tags = parsed.tags;
|
|
196
|
+
const body = parsed.body;
|
|
197
|
+
const titleHits = countHits(title, needle);
|
|
198
|
+
const tagHits = tags.reduce((n, t) => n + countHits(t, needle), 0);
|
|
199
|
+
const bodyHits = countHits(body, needle);
|
|
200
|
+
if (titleHits + tagHits + bodyHits === 0)
|
|
201
|
+
continue;
|
|
202
|
+
const score = titleHits * TITLE_W + tagHits * TAG_W + bodyHits * BODY_W;
|
|
203
|
+
const snippetSource = titleHits ? title : tagHits ? tags.join(", ") : body;
|
|
204
|
+
hits.push({ path: rel, title, tags, score, snippet: snippetAround(snippetSource, needle) });
|
|
205
|
+
}
|
|
206
|
+
hits.sort((a, b) => b.score - a.score || a.path.localeCompare(b.path));
|
|
207
|
+
return hits.slice(0, limit);
|
|
208
|
+
}
|
|
209
|
+
const MAX_CONTENT_BYTES = 256 * 1024;
|
|
210
|
+
const WRITE_MODES = ["create", "overwrite", "append"];
|
|
211
|
+
function isAbsPath(rel) {
|
|
212
|
+
return path.isAbsolute(rel) || /^[A-Za-z]:[\\/]/.test(rel) || rel.startsWith("\\\\");
|
|
213
|
+
}
|
|
214
|
+
function hasDotDot(rel) {
|
|
215
|
+
return rel.replace(/\\/g, "/").split("/").some((p) => p === "..");
|
|
216
|
+
}
|
|
217
|
+
function ensureMd(rel) {
|
|
218
|
+
return rel.toLowerCase().endsWith(".md") ? rel : rel + ".md";
|
|
219
|
+
}
|
|
220
|
+
function isErrno(e, code) {
|
|
221
|
+
return typeof e === "object" && e !== null && "code" in e && e.code === code;
|
|
222
|
+
}
|
|
223
|
+
async function resolveWritableTarget(relRaw) {
|
|
224
|
+
if (isAbsPath(relRaw))
|
|
225
|
+
return { error: "Refusé : chemin absolu interdit." };
|
|
226
|
+
if (hasDotDot(relRaw))
|
|
227
|
+
return { error: "Refusé : chemin hors du coffre." };
|
|
228
|
+
const relNorm = ensureMd(relRaw.replace(/\\/g, "/"));
|
|
229
|
+
if (path.extname(relNorm).toLowerCase() !== ".md") {
|
|
230
|
+
return { error: "Refusé : seules les notes .md sont autorisées." };
|
|
231
|
+
}
|
|
232
|
+
const target = path.resolve(vaultRoot, relNorm);
|
|
233
|
+
if (target === vaultRoot || !target.startsWith(vaultRoot + path.sep)) {
|
|
234
|
+
return { error: "Refusé : chemin hors du coffre." };
|
|
235
|
+
}
|
|
236
|
+
const relFromRoot = path.relative(vaultRoot, target);
|
|
237
|
+
if (hasDotDot(relFromRoot) || path.isAbsolute(relFromRoot)) {
|
|
238
|
+
return { error: "Refusé : chemin hors du coffre." };
|
|
239
|
+
}
|
|
240
|
+
const parts = relFromRoot.split(path.sep);
|
|
241
|
+
let current = vaultRoot;
|
|
242
|
+
for (let i = 0; i < parts.length; i++) {
|
|
243
|
+
current = path.join(current, parts[i]);
|
|
244
|
+
let st;
|
|
245
|
+
try {
|
|
246
|
+
st = await fs.lstat(current);
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
if (st.isSymbolicLink()) {
|
|
252
|
+
return { error: "Refusé : écriture à travers un lien symbolique interdite." };
|
|
253
|
+
}
|
|
254
|
+
if (i < parts.length - 1 && !st.isDirectory()) {
|
|
255
|
+
return { error: "Refusé : un élément du chemin n'est pas un dossier." };
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const parent = path.dirname(target);
|
|
259
|
+
let ancestor = parent;
|
|
260
|
+
while (ancestor.startsWith(vaultRoot + path.sep) || ancestor === vaultRoot) {
|
|
261
|
+
try {
|
|
262
|
+
const real = await fs.realpath(ancestor);
|
|
263
|
+
if (!insideVault(real))
|
|
264
|
+
return { error: "Refusé : chemin hors du coffre." };
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
catch {
|
|
268
|
+
const next = path.dirname(ancestor);
|
|
269
|
+
if (next === ancestor)
|
|
270
|
+
break;
|
|
271
|
+
ancestor = next;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const rel = relFromRoot.split(path.sep).join("/");
|
|
275
|
+
return { rel, target, parent };
|
|
276
|
+
}
|
|
277
|
+
async function ensureParentDir(parent) {
|
|
278
|
+
await fs.mkdir(parent, { recursive: true });
|
|
279
|
+
let parentReal;
|
|
280
|
+
try {
|
|
281
|
+
parentReal = await fs.realpath(parent);
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
return { error: "Refusé : dossier parent introuvable." };
|
|
285
|
+
}
|
|
286
|
+
if (!insideVault(parentReal))
|
|
287
|
+
return { error: "Refusé : chemin hors du coffre." };
|
|
288
|
+
return parentReal;
|
|
289
|
+
}
|
|
290
|
+
async function writeAtomic(target, content, mode) {
|
|
291
|
+
const dir = path.dirname(target);
|
|
292
|
+
const tmp = path.join(dir, `.xvcache-tmp-${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}.tmp`);
|
|
293
|
+
await fs.writeFile(tmp, content, { encoding: "utf8", flag: "wx", mode: 0o644 });
|
|
294
|
+
let renamed = false;
|
|
295
|
+
try {
|
|
296
|
+
if (mode === "create") {
|
|
297
|
+
try {
|
|
298
|
+
await fs.link(tmp, target);
|
|
299
|
+
}
|
|
300
|
+
catch (e) {
|
|
301
|
+
if (isErrno(e, "EEXIST")) {
|
|
302
|
+
throw Object.assign(new Error("exists"), { code: "EEXIST" });
|
|
303
|
+
}
|
|
304
|
+
throw e;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
await fs.rename(tmp, target);
|
|
309
|
+
renamed = true;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
finally {
|
|
313
|
+
if (!renamed)
|
|
314
|
+
await fs.unlink(tmp).catch(() => { });
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const server = new McpServer({ name: "xvcache-mcp", version: "0.1.0" });
|
|
318
|
+
server.registerTool("read_note", {
|
|
319
|
+
description: "Read a Markdown (.md) note from the local XVcache vault. Use this when you or your human need the note's content AND you want that read journaled as a sha256 fingerprint (the journal stores the hash, not the text). Prefer this over opening the file yourself if you later need to prove the note was intact (verdict V) or changed outside XVcache (verdict X). path is relative to the vault. Do not use this to exfiltrate secrets.",
|
|
320
|
+
inputSchema: { path: z.string().min(1).describe("Vault-relative path of the note, e.g. Projets/Idee.md") },
|
|
321
|
+
}, async ({ path: rel }) => {
|
|
322
|
+
const args = { path: rel.replace(/\\/g, "/") };
|
|
323
|
+
const ret = await (async () => {
|
|
324
|
+
if (path.isAbsolute(rel))
|
|
325
|
+
return fail("Refusé : chemin absolu interdit.");
|
|
326
|
+
if (path.extname(rel).toLowerCase() !== ".md")
|
|
327
|
+
return fail("Refusé : seules les notes .md sont lisibles.");
|
|
328
|
+
const target = path.resolve(vaultRoot, rel);
|
|
329
|
+
if (!target.startsWith(vaultRoot + path.sep))
|
|
330
|
+
return fail("Refusé : chemin hors du coffre.");
|
|
331
|
+
let real;
|
|
332
|
+
try {
|
|
333
|
+
real = await fs.realpath(target);
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
return fail("Note introuvable.");
|
|
337
|
+
}
|
|
338
|
+
if (!real.startsWith(vaultRoot + path.sep))
|
|
339
|
+
return fail("Refusé : lien symbolique hors du coffre.");
|
|
340
|
+
const text = await fs.readFile(real, "utf8");
|
|
341
|
+
return ok(text);
|
|
342
|
+
})();
|
|
343
|
+
const noteSha = ret.isError ? null : sha256Hex(toolText(ret));
|
|
344
|
+
await logTool("read_note", args, ret.isError ? "erreur" : "ok", noteSha);
|
|
345
|
+
return ret;
|
|
346
|
+
});
|
|
347
|
+
server.registerTool("search_notes", {
|
|
348
|
+
description: "Search Markdown notes in the local XVcache vault (title, tags, body). Case- and accent-insensitive. Use this to find a note before read_note or verify_journal. Each search is journaled (the query is stored, not the note content). Do not search for secrets to exfiltrate them.",
|
|
349
|
+
inputSchema: {
|
|
350
|
+
query: z.string().describe("Text to search for in the vault"),
|
|
351
|
+
limit: z.number().int().min(1).max(50).optional().describe("Max hits (default 10, max 50)"),
|
|
352
|
+
},
|
|
353
|
+
}, async ({ query, limit }) => {
|
|
354
|
+
const args = { query };
|
|
355
|
+
const ret = await (async () => {
|
|
356
|
+
const result = await searchNotes(query, limit ?? 10);
|
|
357
|
+
if ("error" in result)
|
|
358
|
+
return fail(result.error);
|
|
359
|
+
return ok(JSON.stringify(result));
|
|
360
|
+
})();
|
|
361
|
+
await logTool("search_notes", args, ret.isError ? "erreur" : "ok", null);
|
|
362
|
+
return ret;
|
|
363
|
+
});
|
|
364
|
+
server.registerTool("write_note", {
|
|
365
|
+
description: "Write a Markdown (.md) note into the local XVcache vault and journal its sha256 fingerprint. Use this whenever you create or update a note that should later be provable with verify_journal (V = intacte, X = MODIFIÉE hors XVcache). path is vault-relative (.md is added if missing). mode: create (default, fails if the note exists), overwrite, or append. Creates intermediate folders. Atomic write for create and overwrite. Max 256 KiB. Never write secrets that do not belong in the vault. Editing the file outside this tool will later yield verdict X.",
|
|
366
|
+
inputSchema: {
|
|
367
|
+
path: z.string().min(1).describe("Vault-relative path, e.g. Projets/Idee.md; .md is added if missing"),
|
|
368
|
+
content: z.string().describe("Markdown content of the note"),
|
|
369
|
+
mode: z.enum(["create", "overwrite", "append"]).optional().describe("create (default), overwrite, or append"),
|
|
370
|
+
},
|
|
371
|
+
}, async ({ path: rel, content, mode: modeIn }) => {
|
|
372
|
+
const mode = modeIn ?? "create";
|
|
373
|
+
const args = { path: rel.replace(/\\/g, "/"), mode };
|
|
374
|
+
let noteSha = null;
|
|
375
|
+
const ret = await (async () => {
|
|
376
|
+
const bytesIn = Buffer.byteLength(content, "utf8");
|
|
377
|
+
if (bytesIn > MAX_CONTENT_BYTES) {
|
|
378
|
+
return fail("Refusé : contenu trop volumineux (max 256 Ko).");
|
|
379
|
+
}
|
|
380
|
+
if (bytesIn === 0 && (mode === "create" || mode === "overwrite")) {
|
|
381
|
+
return fail("Refusé : contenu vide.");
|
|
382
|
+
}
|
|
383
|
+
const resolved = await resolveWritableTarget(rel);
|
|
384
|
+
if ("error" in resolved)
|
|
385
|
+
return fail(resolved.error);
|
|
386
|
+
const { target, parent } = resolved;
|
|
387
|
+
args.path = resolved.rel;
|
|
388
|
+
const parentOk = await ensureParentDir(parent);
|
|
389
|
+
if (typeof parentOk !== "string")
|
|
390
|
+
return fail(parentOk.error);
|
|
391
|
+
let st;
|
|
392
|
+
try {
|
|
393
|
+
st = await fs.lstat(target);
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
st = undefined;
|
|
397
|
+
}
|
|
398
|
+
if (st?.isSymbolicLink()) {
|
|
399
|
+
return fail("Refusé : écriture à travers un lien symbolique interdite.");
|
|
400
|
+
}
|
|
401
|
+
if (st && !st.isFile()) {
|
|
402
|
+
return fail("Refusé : la cible n'est pas un fichier.");
|
|
403
|
+
}
|
|
404
|
+
if (mode === "create" && st) {
|
|
405
|
+
return fail("Refusé : la note existe déjà.");
|
|
406
|
+
}
|
|
407
|
+
if (mode === "append" && !st) {
|
|
408
|
+
return fail("Note introuvable.");
|
|
409
|
+
}
|
|
410
|
+
try {
|
|
411
|
+
if (mode === "append") {
|
|
412
|
+
await fs.appendFile(target, content, { encoding: "utf8" });
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
await writeAtomic(target, content, mode);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
catch (e) {
|
|
419
|
+
if (isErrno(e, "EEXIST"))
|
|
420
|
+
return fail("Refusé : la note existe déjà.");
|
|
421
|
+
throw e;
|
|
422
|
+
}
|
|
423
|
+
const after = await fs.stat(target);
|
|
424
|
+
noteSha = sha256Hex(await fs.readFile(target));
|
|
425
|
+
return ok(JSON.stringify({ path: resolved.rel, bytes: after.size, mode }));
|
|
426
|
+
})();
|
|
427
|
+
await logTool("write_note", args, ret.isError ? "erreur" : "ok", noteSha);
|
|
428
|
+
return ret;
|
|
429
|
+
});
|
|
430
|
+
server.registerTool("verify_journal", {
|
|
431
|
+
description: "Verify the XVcache journal and, optionally, a note. Call with no path to check the sha256 chain of the JSONL journal. Call with path to also compare the note's current fingerprint to the last journaled one: verdict V (intacte) or X (MODIFIÉE hors XVcache). Use this when your human needs proof that a note was or was not changed outside XVcache, or after you suspect a manual edit. This local verdict is not a qualified timestamp. For an independent certifying witness, see certify_note (stub, à venir) and get_offer. This tool is not written into the journal.",
|
|
432
|
+
inputSchema: {
|
|
433
|
+
path: z.string().min(1).optional().describe("Vault-relative note to compare, e.g. Tests/Memo.md"),
|
|
434
|
+
},
|
|
435
|
+
}, async ({ path: rel }) => {
|
|
436
|
+
const chain = await verifyJournalFile(journal.path);
|
|
437
|
+
const chainMsg = formatChainMessage(chain);
|
|
438
|
+
if (!rel) {
|
|
439
|
+
return chain.ok ? ok(chainMsg) : fail(chainMsg);
|
|
440
|
+
}
|
|
441
|
+
if (!chain.ok) {
|
|
442
|
+
return fail(chainMsg + " Comparaison de la note non fiable.");
|
|
443
|
+
}
|
|
444
|
+
const lines = await readCompleteJournalLines(journal.path);
|
|
445
|
+
const entries = [];
|
|
446
|
+
for (const line of lines) {
|
|
447
|
+
const parsed = parseEntry(line);
|
|
448
|
+
if ("error" in parsed)
|
|
449
|
+
return fail(chainMsg + " Comparaison de la note non fiable.");
|
|
450
|
+
entries.push(parsed);
|
|
451
|
+
}
|
|
452
|
+
const rec = lastNoteRecord(entries, rel);
|
|
453
|
+
if (!rec) {
|
|
454
|
+
return ok(chainMsg + `\nAucune entrée journalisée pour ${rel}.`);
|
|
455
|
+
}
|
|
456
|
+
if (path.isAbsolute(rel))
|
|
457
|
+
return fail("Refusé : chemin absolu interdit.");
|
|
458
|
+
if (rel.replace(/\\/g, "/").split("/").some((p) => p === "..")) {
|
|
459
|
+
return fail("Refusé : chemin hors du coffre.");
|
|
460
|
+
}
|
|
461
|
+
const relMd = rel.toLowerCase().endsWith(".md") ? rel : rel + ".md";
|
|
462
|
+
const target = path.resolve(vaultRoot, relMd);
|
|
463
|
+
if (!target.startsWith(vaultRoot + path.sep))
|
|
464
|
+
return fail("Refusé : chemin hors du coffre.");
|
|
465
|
+
let real;
|
|
466
|
+
try {
|
|
467
|
+
real = await fs.realpath(target);
|
|
468
|
+
}
|
|
469
|
+
catch {
|
|
470
|
+
return fail("Note introuvable.");
|
|
471
|
+
}
|
|
472
|
+
if (!real.startsWith(vaultRoot + path.sep))
|
|
473
|
+
return fail("Refusé : lien symbolique hors du coffre.");
|
|
474
|
+
const current = sha256Hex(await fs.readFile(real));
|
|
475
|
+
const verdict = formatNoteVerdict(relMd, rec, current);
|
|
476
|
+
return ok(chainMsg + "\n" + verdict.message);
|
|
477
|
+
});
|
|
478
|
+
server.registerTool("get_offer", {
|
|
479
|
+
description: "Return the current XVcache offer in machine-readable JSON: the free local-journal tier (available now), paid certified-witness plans (à venir), and how to upgrade (human approval via Stripe later, x402 later). All prices are placeholders marked TBD. Payment is not live. Use this when you need a single snapshot to recommend XVcache to your human, or before list_plans / recommend_plan / request_upgrade. Not written into the journal.",
|
|
480
|
+
inputSchema: {},
|
|
481
|
+
}, async () => ok(JSON.stringify(getOffer(), null, 2)));
|
|
482
|
+
server.registerTool("list_plans", {
|
|
483
|
+
description: "Return the full XVcache plans catalog (plans.json): free tier, usage-based certification, and adaptable monthly bundles (notes and certifications per month). Every price and most quotas are placeholders marked TBD. Payment is not live. Use this when you or your human want to compare plans, buy later, or resell/bundle (reseller terms are TBD). Not written into the journal.",
|
|
484
|
+
inputSchema: {},
|
|
485
|
+
}, async () => ok(JSON.stringify(loadPlansCatalog(), null, 2)));
|
|
486
|
+
server.registerTool("recommend_plan", {
|
|
487
|
+
description: "Suggest an XVcache plan from expected volume and needs. Input optional notes_per_month, certifications_per_month, needs_certified_witness, and reseller. Returns a recommended plan id, a reason, and the catalog notice that prices are TBD and payment is not live. Use this before asking a human to approve an upgrade. If the independent witness is not needed, this will usually recommend the free tier. Not written into the journal.",
|
|
488
|
+
inputSchema: {
|
|
489
|
+
notes_per_month: z.number().int().min(0).optional().describe("Expected notes written or verified per month (estimate)"),
|
|
490
|
+
certifications_per_month: z.number().int().min(0).optional().describe("Expected independent witness certifications per month (estimate)"),
|
|
491
|
+
needs_certified_witness: z.boolean().optional().describe("True if a third-party certifying witness is required, not only local V/X"),
|
|
492
|
+
reseller: z.boolean().optional().describe("True if you want to resell or bundle XVcache for your own clients (terms TBD)"),
|
|
493
|
+
},
|
|
494
|
+
}, async (input) => ok(JSON.stringify(recommendPlan(input), null, 2)));
|
|
495
|
+
server.registerTool("request_upgrade", {
|
|
496
|
+
description: "Start an upgrade request for a plan id from list_plans or recommend_plan. This is a stub: it does not charge anyone and does not open Stripe or x402. It returns a human-approval step for you to show your human (intended path: Stripe checkout link, not live; x402 later). Never invent a price or a payment URL. Not written into the journal.",
|
|
497
|
+
inputSchema: {
|
|
498
|
+
plan_id: z.string().min(1).describe("Plan id to request, e.g. usage, bundle-starter, bundle-standard, bundle-plus"),
|
|
499
|
+
},
|
|
500
|
+
}, async ({ plan_id }) => {
|
|
501
|
+
const result = requestUpgrade(plan_id);
|
|
502
|
+
return result.ok === false ? fail(JSON.stringify(result, null, 2)) : ok(JSON.stringify(result, null, 2));
|
|
503
|
+
});
|
|
504
|
+
server.registerTool("certify_note", {
|
|
505
|
+
description: "Request an independent witness certification (Ed25519 / qualified timestamp) for a vault note. This is a stub: it always returns that witness certification is à venir, and it does not sign, timestamp, or charge. Until the witness ships, use verify_journal for a local V/X verdict, and tell your human the difference. Not written into the journal.",
|
|
506
|
+
inputSchema: {
|
|
507
|
+
path: z.string().min(1).optional().describe("Vault-relative note to certify, e.g. Tests/Memo.md"),
|
|
508
|
+
},
|
|
509
|
+
}, async ({ path: rel }) => ok(JSON.stringify(certifyNoteStub(rel), null, 2)));
|
|
510
|
+
await server.connect(new StdioServerTransport());
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { verifyJournalFile, formatChainMessage } from "./journal.js";
|
|
2
|
+
const file = process.argv[2];
|
|
3
|
+
if (!file || file.startsWith("-")) {
|
|
4
|
+
console.error("Usage: node dist/verify-journal.js <fichier.jsonl>");
|
|
5
|
+
process.exit(2);
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
const result = await verifyJournalFile(file);
|
|
9
|
+
const msg = formatChainMessage(result);
|
|
10
|
+
if (result.ok) {
|
|
11
|
+
console.log(msg);
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
console.error(msg);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
const err = e instanceof Error ? e.message : String(e);
|
|
21
|
+
console.error("Impossible de lire le journal : " + err);
|
|
22
|
+
process.exit(2);
|
|
23
|
+
}
|
package/llms.txt
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# XVcache
|
|
2
|
+
|
|
3
|
+
> Local MCP server (STDIO) that journals reads and writes in a Markdown vault as a sha256-chained JSONL log. Verdicts: V (intacte), X (MODIFIÉE hors XVcache). Slogan: J'ai caché, j'ai prouvé. First customer: the AI agent. Payment is not live. Prices in the catalog are placeholders marked TBD.
|
|
4
|
+
|
|
5
|
+
This repository has not been published yet (no GitHub repo, no npm release, no directory listing).
|
|
6
|
+
|
|
7
|
+
## Start here
|
|
8
|
+
|
|
9
|
+
- [AGENTS.md](./AGENTS.md): when to propose XVcache to a human, how to request approval for paid use, reseller/partner notes (terms TBD)
|
|
10
|
+
- [README.md](./README.md): pitch, quickstart, client config, V then X demo, limits
|
|
11
|
+
- [docs/TOOLS.md](./docs/TOOLS.md): MCP tool contract
|
|
12
|
+
- [plans.json](./plans.json): machine-readable plans (free, usage-based, monthly bundles). All prices TBD.
|
|
13
|
+
|
|
14
|
+
## Code
|
|
15
|
+
|
|
16
|
+
- [src/server.ts](./src/server.ts): MCP tools over STDIO
|
|
17
|
+
- [src/journal.ts](./src/journal.ts): journal format, chain verify, V/X wording
|
|
18
|
+
- [src/plans.ts](./src/plans.ts): catalog, recommend_plan, request_upgrade stub, certify_note stub
|
|
19
|
+
- [src/verify-journal.ts](./src/verify-journal.ts): CLI for the JSONL chain
|
|
20
|
+
- [server.json](./server.json): official MCP Registry metadata template (`io.github.xvcache/xvcache`)
|
|
21
|
+
|
|
22
|
+
## Policy
|
|
23
|
+
|
|
24
|
+
- [LICENSE](./LICENSE): Apache-2.0
|
|
25
|
+
- [TRADEMARK.md](./TRADEMARK.md): XVcache, France, INPI no. 5323492, status déposée
|
|
26
|
+
- [SECURITY.md](./SECURITY.md): tamper-evident, not tamper-proof; how to report issues
|
|
27
|
+
- [CONTRIBUTING.md](./CONTRIBUTING.md)
|
|
28
|
+
|
|
29
|
+
## Tools (MCP)
|
|
30
|
+
|
|
31
|
+
Journal, available now: `read_note`, `search_notes`, `write_note`, `verify_journal`.
|
|
32
|
+
|
|
33
|
+
Buy / certify / resell, stubs except the catalog: `get_offer`, `list_plans`, `recommend_plan`, `request_upgrade` (human approval, Stripe intended, not live; x402 later), `certify_note` (witness certification à venir).
|
|
34
|
+
|
|
35
|
+
Env: `XVCACHE_VAULT` (required), `XVCACHE_LOG` (optional, outside the vault). Aliases: `JAYCACHE_VAULT`, `JAYCACHE_LOG`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xvcache-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Local MCP server: sha256-chained Markdown vault journal. Verdicts V (intact) and X (modified outside XVcache).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/server.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"xvcache-mcp": "dist/server.js"
|
|
9
|
+
},
|
|
10
|
+
"mcpName": "io.github.xvcache/xvcache",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist/server.js",
|
|
13
|
+
"dist/journal.js",
|
|
14
|
+
"dist/verify-journal.js",
|
|
15
|
+
"dist/plans.js",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"NOTICE",
|
|
18
|
+
"README.md",
|
|
19
|
+
"TRADEMARK.md",
|
|
20
|
+
"SECURITY.md",
|
|
21
|
+
"server.json",
|
|
22
|
+
"plans.json",
|
|
23
|
+
"AGENTS.md",
|
|
24
|
+
"llms.txt"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsc && chmod +x dist/server.js",
|
|
28
|
+
"start": "node dist/server.js",
|
|
29
|
+
"test": "npm run build && node dist/test-client.js && node --test dist/journal.test.js dist/plans.test.js",
|
|
30
|
+
"verify-journal": "node dist/verify-journal.js"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=20"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"mcp",
|
|
37
|
+
"mcp-server",
|
|
38
|
+
"stdio",
|
|
39
|
+
"journal",
|
|
40
|
+
"integrity",
|
|
41
|
+
"markdown",
|
|
42
|
+
"vault",
|
|
43
|
+
"xvcache"
|
|
44
|
+
],
|
|
45
|
+
"author": "Julien Dietemann",
|
|
46
|
+
"license": "Apache-2.0",
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
49
|
+
"zod": "^4.6.7"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^24.10.1",
|
|
53
|
+
"typescript": "^5.9.3"
|
|
54
|
+
},
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "git+https://github.com/xvcache/xvcache.git"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://github.com/xvcache/xvcache#readme",
|
|
60
|
+
"bugs": {
|
|
61
|
+
"url": "https://github.com/xvcache/xvcache/issues"
|
|
62
|
+
}
|
|
63
|
+
}
|