@moxn/mcp-kb 0.4.1 → 0.6.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.
@@ -0,0 +1,582 @@
1
+ /**
2
+ * `pull` / `push`: move a document body between the server and local disk
3
+ * without the body passing through the model.
4
+ *
5
+ * Tool arguments and results are what a model reads and writes, so the only way
6
+ * to keep a body out of its context is for something on the client side to hold
7
+ * it. This proxy is that something: `pull` turns a `read` into a file and
8
+ * returns the path; the agent searches and edits the file with its own tools;
9
+ * `push` sends the file back and returns the outcome.
10
+ *
11
+ * The rules that make this safe:
12
+ *
13
+ * - **The caller never names a path.** Every path derives from a validated
14
+ * document UUID and an encoded branch name. A prompt-injected document can
15
+ * otherwise talk the model into `push path=~/.ssh/id_rsa`, and this process
16
+ * sits outside the host's file permissions, so nothing else would stop it.
17
+ * - **Symlinks and hard links are refused**, for the same reason: replacing the
18
+ * checkout file with a link to a secret must not turn `push` into an upload.
19
+ * - **A checkout is one document on one branch.** `push` writes to the branch
20
+ * the file was pulled from and refuses to guess between two.
21
+ * - **Every push is guarded by the pulled revision.** There is no unguarded
22
+ * path, and no local merge: a moved document is refused by the server, the
23
+ * file is left alone, and the agent reconciles against the kept base copy.
24
+ * - **`push` writes the body and nothing else.** The revision deliberately does
25
+ * not cover tags or the description, so a declarative `replace_document` from
26
+ * this file would silently undo a tag someone added after the pull. Front-matter
27
+ * in the file is context; editing it is refused, not dropped.
28
+ * - **`push` is an agent change like `edit`.** The server (`replace_body`)
29
+ * marks the blocks the push changed so a person can revert them inline, and
30
+ * keeps the revert markers of earlier agent changes on blocks it left alone.
31
+ * `revertMarkersCleared`, passed on, reports markers it could not keep.
32
+ *
33
+ * Layout, under `<root>/.moxn/checkouts/<workspace>/`:
34
+ *
35
+ * <branch>/<documentId>.md the file the agent edits
36
+ * .state/<branch>/<documentId>.json revision, branch, content hash
37
+ * .state/<branch>/<documentId>.base.md the file as pulled
38
+ */
39
+ import { createHash, randomBytes } from 'node:crypto';
40
+ import { constants as fsConstants, promises as fs } from 'node:fs';
41
+ import * as path from 'node:path';
42
+ import { fileURLToPath } from 'node:url';
43
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
44
+ const MAX_NAME = 255;
45
+ /**
46
+ * Stays under Vercel's 4.5 MB request limit once the body is JSON-escaped and
47
+ * wrapped. Refusing here gives a clear error instead of an opaque 413.
48
+ */
49
+ const MAX_PUSH_BYTES = 4 * 1024 * 1024;
50
+ const H2_ANCHOR = /^## (.*?) \{#([0-9a-f-]{36})\}\s*$/i;
51
+ export const checkoutTools = [
52
+ {
53
+ name: 'pull',
54
+ description: `Write one markdown document to a local file and return its path, WITHOUT returning the body. Use this instead of \`read\` when the document is large, or when you will search it or make several edits: the body stays out of your context, and you work on the file with your own file tools (Grep, Read, Edit).
55
+
56
+ The file is a for-edit read: YAML front-matter plus body, with \`{#id}\` anchors on the H2 lines. Keep those anchors, because they preserve section identity, comments and authorship. The front-matter is there for context and cannot be pushed: change a name, tags or properties with the \`documents\` and \`metadata\` tools.
57
+
58
+ Returns \`path\`, \`branchName\`, \`revision\`, \`lines\` and a \`sections\` map of H2 line numbers. The checkout is gitignored, so search the file by its full path; a recursive ripgrep over the checkout directory skips it without --no-ignore.
59
+
60
+ Requires an agent with local file tools. Markdown documents only (kind='md'). Pass \`commitId\` for a read-only copy of a past version. Refuses to replace a file with local edits unless \`overwrite\` is true.`,
61
+ inputSchema: {
62
+ type: 'object',
63
+ additionalProperties: false,
64
+ required: ['documentId'],
65
+ properties: {
66
+ documentId: { type: 'string', format: 'uuid', description: 'Document UUID.' },
67
+ branchName: {
68
+ type: 'string',
69
+ description: "Branch to check out. Defaults to the document's default branch. Mutually exclusive with commitId.",
70
+ },
71
+ commitId: {
72
+ type: 'string',
73
+ format: 'uuid',
74
+ description: 'Check out this past commit, read-only. Mutually exclusive with branchName.',
75
+ },
76
+ overwrite: {
77
+ type: 'boolean',
78
+ description: 'Discard local edits to this checkout. Default false.',
79
+ },
80
+ },
81
+ },
82
+ },
83
+ {
84
+ name: 'push',
85
+ description: `Commit a file from \`pull\` back to the branch it was pulled from, WITHOUT sending the body through you. Writes the body only, then refreshes the local file from the server, so tags and metadata changed by anyone else are kept. A file whose front-matter was edited is refused (\`frontmatter_changed\`): restore it and use the \`documents\` or \`metadata\` tools for those.
86
+
87
+ A push commits at once, like every write. Like \`edit\`, the blocks you changed carry revert markers so a person can revert them inline, and earlier agent changes on blocks you left alone keep theirs. \`revertMarkersCleared: true\` means some earlier markers could not be kept: those on blocks you rewrote, or all of them when the rewrite was too large to diff. Section headings (H2) never carry markers. When a change needs sign-off before it lands, push to a branch and open a merge request.
88
+
89
+ Pass \`branchName\` only when the document is checked out on more than one branch; the push is refused rather than guessed. Pushing an unchanged file does nothing.
90
+
91
+ Guarded by the pulled revision: if the document moved, nothing is written and you get \`stale_checkout\` with your file untouched. To recover, compare \`details.path\` with \`details.basePath\` to capture your edits, \`pull\` with \`overwrite: true\`, re-apply them and push again.
92
+
93
+ Returns \`revision\`, \`bodyChanged\`, \`normalized\` (true when the server rewrote your markdown on commit; the local file now holds its version) and the commit's changes. A document with sections you may not change is refused with \`forbidden\`; use the \`edit\` tool for those.`,
94
+ inputSchema: {
95
+ type: 'object',
96
+ additionalProperties: false,
97
+ required: ['documentId'],
98
+ properties: {
99
+ documentId: { type: 'string', format: 'uuid', description: 'Document UUID.' },
100
+ branchName: {
101
+ type: 'string',
102
+ description: 'Which checkout to push. Needed only when the document is checked out on several branches.',
103
+ },
104
+ commitMessage: { type: 'string', description: 'Optional commit message.' },
105
+ },
106
+ },
107
+ },
108
+ ];
109
+ const TOOL_NAMES = new Set(checkoutTools.map((tool) => tool.name));
110
+ export function isCheckoutTool(name) {
111
+ return TOOL_NAMES.has(name);
112
+ }
113
+ class CheckoutError extends Error {
114
+ code;
115
+ details;
116
+ constructor(code, message, details) {
117
+ super(message);
118
+ this.code = code;
119
+ this.details = details;
120
+ }
121
+ }
122
+ function ok(value) {
123
+ return { content: [{ type: 'text', text: JSON.stringify(value, null, 2) }] };
124
+ }
125
+ function failure(error) {
126
+ return {
127
+ content: [
128
+ {
129
+ type: 'text',
130
+ text: JSON.stringify({
131
+ error_code: error.code,
132
+ retryable: false,
133
+ message: error.message,
134
+ ...(error.details ? { details: error.details } : {}),
135
+ }),
136
+ },
137
+ ],
138
+ isError: true,
139
+ };
140
+ }
141
+ // ── Arguments ───────────────────────────────────────────────────────────────
142
+ function assertOnlyKnownArgs(args, tool) {
143
+ const definition = checkoutTools.find((t) => t.name === tool);
144
+ const known = Object.keys(definition?.inputSchema.properties ?? {});
145
+ const unknown = Object.keys(args).filter((key) => !known.includes(key));
146
+ if (unknown.length > 0) {
147
+ throw new CheckoutError('invalid_input', `${tool}: unexpected argument(s): ${unknown.join(', ')}. Paths are derived from the document id and cannot be chosen.`);
148
+ }
149
+ }
150
+ function uuidArg(args, key) {
151
+ const value = args[key];
152
+ if (typeof value !== 'string' || !UUID.test(value)) {
153
+ throw new CheckoutError('invalid_input', `${key} must be a UUID.`);
154
+ }
155
+ return value.toLowerCase();
156
+ }
157
+ function optionalStringArg(args, key) {
158
+ const value = args[key];
159
+ if (value === undefined)
160
+ return undefined;
161
+ if (typeof value !== 'string' || value.length === 0 || value.length > MAX_NAME) {
162
+ throw new CheckoutError('invalid_input', `${key} must be a non-empty string of at most ${MAX_NAME} characters.`);
163
+ }
164
+ return value;
165
+ }
166
+ // ── Paths ───────────────────────────────────────────────────────────────────
167
+ /** One path segment from any string. `encodeURIComponent` leaves dots alone. */
168
+ function encodeSegment(value) {
169
+ return encodeURIComponent(value).replace(/\./g, '%2E');
170
+ }
171
+ function checkoutPaths(root, workspace, branchSegment, documentId) {
172
+ const scope = ['.moxn', 'checkouts', encodeSegment(workspace)];
173
+ const dirSegments = [...scope, branchSegment];
174
+ const stateSegments = [...scope, '.state', branchSegment];
175
+ return {
176
+ dirSegments,
177
+ stateSegments,
178
+ file: path.join(root, ...dirSegments, `${documentId}.md`),
179
+ base: path.join(root, ...stateSegments, `${documentId}.base.md`),
180
+ state: path.join(root, ...stateSegments, `${documentId}.json`),
181
+ };
182
+ }
183
+ /**
184
+ * Where `.moxn/` lives: an explicit override, else the client's first MCP root
185
+ * (the directory the agent's own file tools can reach without prompting), else
186
+ * the working directory. A client launched from `/` has no project at all, so
187
+ * that case lands in the home directory rather than at the filesystem root.
188
+ */
189
+ export async function resolveCheckoutRoot(deps) {
190
+ if (deps.override)
191
+ return path.resolve(deps.override);
192
+ const roots = await deps.listRoots().catch(() => []);
193
+ const fileRoot = roots.find((uri) => uri.startsWith('file://'));
194
+ if (fileRoot)
195
+ return fileURLToPath(fileRoot);
196
+ return deps.cwd === path.parse(deps.cwd).root ? deps.home : deps.cwd;
197
+ }
198
+ const branchSegmentFor = (branchName) => encodeSegment(branchName);
199
+ const commitSegmentFor = (commitId) => `@commit-${commitId}`;
200
+ function unsafePath(target, why) {
201
+ return new CheckoutError('unsafe_path', `Refusing to use ${target}: ${why}. Remove it and pull again.`, { path: target });
202
+ }
203
+ /** Create each segment under `root`, refusing a symlink at any level. */
204
+ async function ensureDirectory(root, segments) {
205
+ let current = root;
206
+ for (const segment of segments) {
207
+ current = path.join(current, segment);
208
+ const entry = await fs.lstat(current).catch((error) => {
209
+ if (error.code === 'ENOENT')
210
+ return null;
211
+ throw error;
212
+ });
213
+ if (entry === null) {
214
+ await fs.mkdir(current, { mode: 0o700 }).catch((error) => {
215
+ if (error.code !== 'EEXIST')
216
+ throw error;
217
+ });
218
+ continue;
219
+ }
220
+ if (!entry.isDirectory()) {
221
+ throw unsafePath(current, 'expected a real directory');
222
+ }
223
+ }
224
+ }
225
+ /**
226
+ * Write to a temp file and rename over the target. A rename replaces a symlink
227
+ * at the destination rather than following it, so this cannot write through one.
228
+ */
229
+ async function atomicWrite(target, contents) {
230
+ const temp = `${target}.${randomBytes(6).toString('hex')}.tmp`;
231
+ await fs.writeFile(temp, contents, { mode: 0o600, flag: 'wx' });
232
+ try {
233
+ await fs.rename(temp, target);
234
+ }
235
+ catch (error) {
236
+ await fs.rm(temp, { force: true });
237
+ throw error;
238
+ }
239
+ }
240
+ /** The checkout's contents, or null when absent. Links are refused. */
241
+ async function readRegularFile(target) {
242
+ // O_NOFOLLOW closes the race where the platform has it; the lstat covers the
243
+ // one that does not. O_NONBLOCK stops a FIFO planted here from hanging the open.
244
+ const flags = fsConstants.O_RDONLY |
245
+ (fsConstants.O_NOFOLLOW ?? 0) |
246
+ (fsConstants.O_NONBLOCK ?? 0);
247
+ let handle;
248
+ try {
249
+ if ((await fs.lstat(target)).isSymbolicLink()) {
250
+ throw unsafePath(target, 'it is a symbolic link');
251
+ }
252
+ handle = await fs.open(target, flags);
253
+ }
254
+ catch (error) {
255
+ const code = error.code;
256
+ if (code === 'ENOENT' || code === 'ENOTDIR')
257
+ return null;
258
+ if (code === 'ELOOP')
259
+ throw unsafePath(target, 'it is a symbolic link');
260
+ throw error;
261
+ }
262
+ try {
263
+ const stat = await handle.stat();
264
+ if (!stat.isFile())
265
+ throw unsafePath(target, 'it is not a regular file');
266
+ if (stat.nlink > 1)
267
+ throw unsafePath(target, 'it is hard-linked to another file');
268
+ return await handle.readFile('utf8');
269
+ }
270
+ finally {
271
+ await handle.close();
272
+ }
273
+ }
274
+ // ── State ───────────────────────────────────────────────────────────────────
275
+ const sha256 = (text) => createHash('sha256').update(text, 'utf8').digest('hex');
276
+ const withTrailingNewline = (text) => text.endsWith('\n') ? text : `${text}\n`;
277
+ const FRONT_MATTER = /^---\n(?:[\s\S]*?\n)?---(?:\n|$)/;
278
+ function splitFrontMatter(text) {
279
+ const frontMatter = FRONT_MATTER.exec(text)?.[0] ?? '';
280
+ return { frontMatter, body: text.slice(frontMatter.length) };
281
+ }
282
+ function countLines(text) {
283
+ return text.endsWith('\n') ? text.split('\n').length - 1 : text.split('\n').length;
284
+ }
285
+ function sectionMap(text) {
286
+ return text.split('\n').flatMap((line, index) => {
287
+ const match = H2_ANCHOR.exec(line);
288
+ return match ? [{ line: index + 1, name: match[1], sectionId: match[2] }] : [];
289
+ });
290
+ }
291
+ async function readState(file) {
292
+ const raw = await readRegularFile(file);
293
+ if (raw === null)
294
+ return null;
295
+ try {
296
+ return JSON.parse(raw);
297
+ }
298
+ catch {
299
+ throw new CheckoutError('checkout_failed', `Checkout state at ${file} is unreadable. Pull again with overwrite: true.`);
300
+ }
301
+ }
302
+ /** Write the base copy and state first: a crash then reads as "locally modified". */
303
+ async function recordCheckout(root, paths, state, contents) {
304
+ await ensureDirectory(root, ['.moxn', 'checkouts']);
305
+ await fs
306
+ .writeFile(path.join(root, '.moxn', 'checkouts', '.gitignore'), '*\n', {
307
+ mode: 0o600,
308
+ flag: 'wx',
309
+ })
310
+ .catch((error) => {
311
+ if (error.code !== 'EEXIST')
312
+ throw error;
313
+ });
314
+ await ensureDirectory(root, paths.stateSegments);
315
+ await ensureDirectory(root, paths.dirSegments);
316
+ await atomicWrite(paths.base, contents);
317
+ await atomicWrite(paths.state, `${JSON.stringify(state, null, 2)}\n`);
318
+ await atomicWrite(paths.file, contents);
319
+ }
320
+ function parseResult(result) {
321
+ const text = result.content?.[0]?.text;
322
+ if (typeof text !== 'string') {
323
+ throw new CheckoutError('bad_response', 'The server returned an empty response.');
324
+ }
325
+ try {
326
+ return JSON.parse(text);
327
+ }
328
+ catch {
329
+ throw new CheckoutError('bad_response', 'The server returned an unexpected response.');
330
+ }
331
+ }
332
+ /** The remote read behind `pull` and the read-back after `push`. */
333
+ async function remoteRead(env, documentId, target) {
334
+ return env.callTool('read', {
335
+ items: [
336
+ {
337
+ type: 'document',
338
+ documentId,
339
+ ...(target.commitId
340
+ ? { commitId: target.commitId }
341
+ : {
342
+ forEdit: true,
343
+ ...(target.branchName ? { branchName: target.branchName } : {}),
344
+ }),
345
+ },
346
+ ],
347
+ includeComments: false,
348
+ footnotes: false,
349
+ projections: 'structured',
350
+ });
351
+ }
352
+ function readItemFrom(result) {
353
+ const parsed = parseResult(result);
354
+ const item = parsed.items?.[0];
355
+ if (!item) {
356
+ throw new CheckoutError('bad_response', 'The server returned no document.');
357
+ }
358
+ if (item.error)
359
+ throw new CheckoutError('read_failed', item.error);
360
+ if (item.kind && item.kind !== 'md') {
361
+ throw new CheckoutError('unsupported_kind', `pull handles markdown documents; this one is kind='${item.kind}'. Use read and the tool for that kind.`);
362
+ }
363
+ if (typeof item.markdown !== 'string' || typeof item.branchName !== 'string') {
364
+ throw new CheckoutError('bad_response', 'The server returned no document body.');
365
+ }
366
+ return {
367
+ markdown: item.markdown,
368
+ branchName: item.branchName,
369
+ revision: item.revision ?? null,
370
+ };
371
+ }
372
+ // ── pull ────────────────────────────────────────────────────────────────────
373
+ async function pull(args, env) {
374
+ assertOnlyKnownArgs(args, 'pull');
375
+ const documentId = uuidArg(args, 'documentId');
376
+ const branchName = optionalStringArg(args, 'branchName');
377
+ const commitId = args.commitId === undefined ? undefined : uuidArg(args, 'commitId');
378
+ if (branchName !== undefined && commitId !== undefined) {
379
+ throw new CheckoutError('invalid_input', 'branchName and commitId are mutually exclusive.');
380
+ }
381
+ const overwrite = args.overwrite === true;
382
+ const response = await remoteRead(env, documentId, { branchName, commitId });
383
+ if (response.isError)
384
+ return response;
385
+ const item = readItemFrom(response);
386
+ // Fail closed: without a token the eventual push could not be guarded.
387
+ if (!commitId && !item.revision) {
388
+ throw new CheckoutError('bad_response', 'The server returned no revision for this read, so a later push could not be guarded.');
389
+ }
390
+ const root = await env.root();
391
+ const segment = commitId
392
+ ? commitSegmentFor(commitId)
393
+ : branchSegmentFor(item.branchName);
394
+ const paths = checkoutPaths(root, env.workspace, segment, documentId);
395
+ if (!overwrite) {
396
+ const existing = await readRegularFile(paths.file);
397
+ if (existing !== null) {
398
+ const state = await readState(paths.state);
399
+ if (state === null || state.hash !== sha256(existing)) {
400
+ throw new CheckoutError('local_changes', 'This checkout has local edits. Push them, or pull with overwrite: true to discard them.', { path: paths.file, basePath: paths.base });
401
+ }
402
+ }
403
+ }
404
+ const contents = withTrailingNewline(item.markdown);
405
+ await recordCheckout(root, paths, {
406
+ version: 1,
407
+ documentId,
408
+ branchName: item.branchName,
409
+ ...(commitId ? { commitId } : {}),
410
+ baseUrl: env.baseUrl,
411
+ revision: item.revision,
412
+ hash: sha256(contents),
413
+ pulledAt: new Date().toISOString(),
414
+ }, contents);
415
+ return ok({
416
+ success: true,
417
+ path: paths.file,
418
+ documentId,
419
+ branchName: item.branchName,
420
+ ...(commitId ? { commitId, readOnly: true } : { revision: item.revision }),
421
+ bytes: Buffer.byteLength(contents, 'utf8'),
422
+ lines: countLines(contents),
423
+ sections: sectionMap(contents),
424
+ });
425
+ }
426
+ // ── push ────────────────────────────────────────────────────────────────────
427
+ /** The one pushable checkout for this document, or a refusal. */
428
+ async function locateCheckout(root, env, documentId, branchName) {
429
+ const noCheckout = (message) => new CheckoutError('no_checkout', message);
430
+ if (branchName !== undefined) {
431
+ const paths = checkoutPaths(root, env.workspace, branchSegmentFor(branchName), documentId);
432
+ const state = await readState(paths.state);
433
+ // Branch names are case-sensitive and some filesystems are not, so `Feature`
434
+ // and `feature` can share a directory. The state says which one it holds.
435
+ if (state === null || state.commitId || state.branchName !== branchName) {
436
+ throw noCheckout(`Document ${documentId} is not checked out on "${branchName}".`);
437
+ }
438
+ return { paths, state };
439
+ }
440
+ const stateRoot = path.join(root, '.moxn', 'checkouts', encodeSegment(env.workspace), '.state');
441
+ const segments = await fs.readdir(stateRoot).catch(() => []);
442
+ const found = [];
443
+ for (const segment of segments) {
444
+ const paths = checkoutPaths(root, env.workspace, segment, documentId);
445
+ const state = await readState(paths.state);
446
+ if (state !== null && !state.commitId)
447
+ found.push({ paths, state });
448
+ }
449
+ if (found.length === 0) {
450
+ throw noCheckout(`Document ${documentId} has no checkout to push. Pull it first.`);
451
+ }
452
+ if (found.length > 1) {
453
+ const branches = found.map((entry) => entry.state.branchName);
454
+ throw new CheckoutError('ambiguous_checkout', `Document ${documentId} is checked out on ${branches.length} branches: ${branches.join(', ')}. Pass branchName.`, { branches });
455
+ }
456
+ return found[0];
457
+ }
458
+ /** The server's "document moved" refusal carries the live token. */
459
+ function currentRevisionFrom(result) {
460
+ try {
461
+ const parsed = parseResult(result);
462
+ return parsed.error_code === 'invalid_operation' &&
463
+ typeof parsed.details?.currentRevision === 'string'
464
+ ? parsed.details.currentRevision
465
+ : null;
466
+ }
467
+ catch {
468
+ return null;
469
+ }
470
+ }
471
+ async function push(args, env) {
472
+ assertOnlyKnownArgs(args, 'push');
473
+ const documentId = uuidArg(args, 'documentId');
474
+ const branchName = optionalStringArg(args, 'branchName');
475
+ const commitMessage = args.commitMessage;
476
+ if (commitMessage !== undefined && typeof commitMessage !== 'string') {
477
+ throw new CheckoutError('invalid_input', 'commitMessage must be a string.');
478
+ }
479
+ const root = await env.root();
480
+ const { paths, state } = await locateCheckout(root, env, documentId, branchName);
481
+ if (state.baseUrl !== env.baseUrl) {
482
+ throw new CheckoutError('wrong_deployment', `This checkout came from ${state.baseUrl}, but this connection is to ${env.baseUrl}. Document ids are not portable between deployments.`);
483
+ }
484
+ // A linked DIRECTORY would slip past the no-follow open below, which only
485
+ // covers the last path component.
486
+ await ensureDirectory(root, paths.dirSegments);
487
+ await ensureDirectory(root, paths.stateSegments);
488
+ const local = await readRegularFile(paths.file);
489
+ if (local === null) {
490
+ throw new CheckoutError('no_checkout', `The checkout file ${paths.file} is gone. Pull again with overwrite: true.`);
491
+ }
492
+ if (typeof state.revision !== 'string') {
493
+ throw new CheckoutError('no_checkout', 'This checkout has no revision, so a push could not be guarded. Pull again with overwrite: true.');
494
+ }
495
+ const unchanged = {
496
+ documentId,
497
+ branchName: state.branchName,
498
+ revision: state.revision,
499
+ path: paths.file,
500
+ };
501
+ if (sha256(local) === state.hash) {
502
+ return ok({ success: true, noChanges: true, ...unchanged });
503
+ }
504
+ const base = await readRegularFile(paths.base);
505
+ if (base === null) {
506
+ throw new CheckoutError('no_checkout', `The base copy ${paths.base} is gone. Pull again with overwrite: true.`);
507
+ }
508
+ if (splitFrontMatter(local).frontMatter !== splitFrontMatter(base).frontMatter) {
509
+ throw new CheckoutError('frontmatter_changed', 'push writes the body only, and the front-matter in this file was edited. Restore it (basePath has the original), and change a name, tags or properties with the documents and metadata tools.', { path: paths.file, basePath: paths.base });
510
+ }
511
+ if (Buffer.byteLength(JSON.stringify(local), 'utf8') > MAX_PUSH_BYTES) {
512
+ throw new CheckoutError('too_large', `This body is over the ${MAX_PUSH_BYTES / (1024 * 1024)} MB request limit. Split the document, or change it section by section with the edit tool.`, { path: paths.file });
513
+ }
514
+ const write = await env.callTool('documents', {
515
+ action: 'replace_body',
516
+ documentId,
517
+ branchName: state.branchName,
518
+ markdown: local,
519
+ baseRevision: state.revision,
520
+ ...(commitMessage ? { commitMessage } : {}),
521
+ });
522
+ if (write.isError) {
523
+ const currentRevision = currentRevisionFrom(write);
524
+ if (currentRevision !== null) {
525
+ throw new CheckoutError('stale_checkout', 'The document moved since you pulled it, so nothing was written and your file is untouched. Compare path with basePath to capture your edits, pull with overwrite: true, re-apply them and push again.', { currentRevision, path: paths.file, basePath: paths.base });
526
+ }
527
+ return write;
528
+ }
529
+ const written = parseResult(write);
530
+ // Bookkeeping, plus `sections`, replaced by the line-numbered map below, and
531
+ // `frontMatterIgnored`, always true here: the file's front-matter is checked above.
532
+ const { sections: _sections, branchId: _branchId, commit: _commit, frontMatterIgnored: _frontMatterIgnored, previousBodyEpoch: _previousBodyEpoch, currentBodyEpoch: _currentBodyEpoch, ...outcome } = written;
533
+ // The write landed. From here a failure must not read as a failed push, and
534
+ // leaving the state on the old revision is the safe default: a later push is
535
+ // refused by the server rather than replayed over somebody else's change.
536
+ try {
537
+ const readBack = await remoteRead(env, documentId, {
538
+ branchName: state.branchName,
539
+ });
540
+ if (readBack.isError)
541
+ throw new Error('read-back was refused');
542
+ const item = readItemFrom(readBack);
543
+ if (!item.revision)
544
+ throw new Error('read-back carried no revision');
545
+ const contents = withTrailingNewline(item.markdown);
546
+ await recordCheckout(root, paths, {
547
+ ...state,
548
+ revision: item.revision,
549
+ hash: sha256(contents),
550
+ pulledAt: new Date().toISOString(),
551
+ }, contents);
552
+ return ok({
553
+ ...outcome,
554
+ revision: item.revision,
555
+ // The body only: front-matter moving here is other people's metadata.
556
+ normalized: splitFrontMatter(contents).body !== splitFrontMatter(local).body,
557
+ path: paths.file,
558
+ bytes: Buffer.byteLength(contents, 'utf8'),
559
+ lines: countLines(contents),
560
+ sections: sectionMap(contents),
561
+ });
562
+ }
563
+ catch (error) {
564
+ return ok({
565
+ ...outcome,
566
+ readBackFailed: true,
567
+ warning: `The commit landed, but refreshing the local file failed (${error instanceof Error ? error.message : String(error)}). Pull with overwrite: true before editing again.`,
568
+ path: paths.file,
569
+ });
570
+ }
571
+ }
572
+ export async function runCheckoutTool(name, args, env) {
573
+ try {
574
+ return name === 'pull' ? await pull(args ?? {}, env) : await push(args ?? {}, env);
575
+ }
576
+ catch (error) {
577
+ if (error instanceof CheckoutError)
578
+ return failure(error);
579
+ return failure(new CheckoutError('checkout_failed', error instanceof Error ? error.message : String(error)));
580
+ }
581
+ }
582
+ //# sourceMappingURL=checkout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout.js","sourceRoot":"","sources":["../src/checkout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AA8BzC,MAAM,IAAI,GAAG,iEAAiE,CAAC;AAC/E,MAAM,QAAQ,GAAG,GAAG,CAAC;AAErB;;;GAGG;AACH,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,GAAG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YACV,cAAc,EAAE,IAAI;YACpB,OAAO,EAAE,4DAA4D,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,oDAAoD;YAC/K,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,IAAY,EACZ,IAAyC,EACzC,GAAgB;IAEhB,IAAI,CAAC;QACH,OAAO,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;IACrF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,aAAa;YAAE,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;QAC1D,OAAO,OAAO,CACZ,IAAI,aAAa,CACf,iBAAiB,EACjB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CACF,CAAC;IACJ,CAAC;AACH,CAAC"}
package/dist/proxy.d.ts CHANGED
@@ -7,11 +7,19 @@
7
7
  * Authentication is lazy - it only happens on the first actual request,
8
8
  * allowing the server to respond to MCP initialize immediately.
9
9
  *
10
- * File upload transformation: When LLMs provide content blocks with
11
- * `type: "file"` and a local path, the proxy uploads the file to
12
- * Supabase storage and transforms the block to `type: "storage"`
13
- * before forwarding to the server.
10
+ * Two tools are served here rather than remotely: `pull` and `push` move a
11
+ * document body to and from local disk so it never passes through the model
12
+ * (see checkout.ts). Everything else is forwarded.
14
13
  */
14
+ /**
15
+ * Make a server error body safe to repeat into a log or an error message.
16
+ *
17
+ * Both destinations persist: stderr goes to the MCP host's log file, and a
18
+ * thrown message reaches model context. An unbounded verbatim echo of a
19
+ * server payload puts whatever the server happened to include — secrets in a
20
+ * stack trace, bind parameters — into both. Truncate and scrub instead.
21
+ */
22
+ export declare function summarizeErrorBody(body: string): string;
15
23
  /**
16
24
  * Create and start the proxy server.
17
25
  * Server starts immediately; authentication happens lazily on first request.
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAqdH;;;GAGG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CA6PhD"}
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA+FH;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAcvD;AA+OD;;;GAGG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAuRhD"}