@systemdox/mcp-server 0.1.46 → 0.1.47

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.
@@ -2,10 +2,10 @@
2
2
 
3
3
  // src/tools/team-setup.ts
4
4
  import { z } from "zod";
5
- import { existsSync as existsSync2 } from "fs";
5
+ import { existsSync as existsSync3 } from "fs";
6
6
  import { lstat as lstat2 } from "fs/promises";
7
- import { homedir as homedir2 } from "os";
8
- import { join as join2, resolve as resolve2 } from "path";
7
+ import { homedir as homedir3 } from "os";
8
+ import { join as join4, resolve as resolve3 } from "path";
9
9
 
10
10
  // src/lib/skills.ts
11
11
  import { createHash } from "crypto";
@@ -67,25 +67,912 @@ async function readTextFiles(root, paths, what) {
67
67
  }
68
68
 
69
69
  // src/lib/person-values.ts
70
+ var PHONE = "phone";
71
+ var EMAIL = "email";
72
+ var HOME_PATH = "home-path";
73
+ var NATIONAL_PREFIX = "+44";
70
74
  var W = "[\\p{L}\\p{N}_]";
71
75
  var D = "\\p{Nd}";
72
76
  var WORD_OR = (extra) => `[\\p{L}\\p{N}_${extra}]`;
73
- var PERSON_ID = "(?:con|ctc|usr)_[0-9A-Za-z]{10,40}";
77
+ var PERSON_ID = "(?:(?:con|ctc)_[0-9A-Za-z]{10,40}|usr_[0-9A-Za-z-]{10,40})";
74
78
  var PERSON_TOKEN = `\`${PERSON_ID}\`(?:[ \\t]*\\([^()\\n]*\\))?`;
75
79
  var BEFORE = `(?<!${WORD_OR("+.:/\\\\\\-")})(?<!${D}[ -])`;
76
80
  var AFTER = `(?!${WORD_OR(":/\\\\")}|\\.${D}|[ -]?${D}|-${W})`;
77
81
  var E164 = `${BEFORE}\\+${D}+(?:[ -]${D}+)*${AFTER}`;
78
82
  var NATIONAL = `${BEFORE}0${D}*(?:[ -]${D}+)*${AFTER}`;
83
+ var GROUP_SIZES = /* @__PURE__ */ new Set([2, 3, 4, 5, 6]);
79
84
  var ATEXT = "[A-Za-z0-9!#$%&'*+/=?^_{|}~\\-]";
80
85
  var EMAIL_RE = "(?<![A-Za-z0-9!#$%&*+/=?^_{|}~.@\\-])[A-Za-z0-9_]" + ATEXT + "*(?:\\." + ATEXT + "+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9\\-]{0,61}[A-Za-z0-9])?\\.)+[A-Za-z]{2,63}(?![A-Za-z0-9\\-]|\\.[A-Za-z0-9])";
81
86
  var HOME_PREFIX = "(?:[A-Za-z]:\\\\+Users\\\\+|[A-Za-z]:/+Users/+|/Users/|/home/)";
82
87
  var HOME = `(?<!${WORD_OR(".~:/\\\\$}\\-")})${HOME_PREFIX}[^\\\\/\\s"'\`<>|:*?]+`;
83
88
  var KEY_PREFIX = `(?<!${W})(?:pweb_[a-z]+_key_|sk-ant-|sk_live_|rk_live_|github_pat_|gh[pousr]_|sntrys_|xox[baprs]-)[A-Za-z0-9_\\-]{4,}`;
89
+ var global = (source, flags = "") => new RegExp(source, `gu${flags}`);
90
+ var whole = (source, flags = "") => new RegExp(`^(?:${source})$`, `u${flags}`);
91
+ function lineOf(text2, start) {
92
+ let line = 1;
93
+ for (let i = text2.indexOf("\n"); i !== -1 && i < start; i = text2.indexOf("\n", i + 1)) line++;
94
+ return line;
95
+ }
96
+ function phoneShape(value) {
97
+ const groups = value.replace(/^\++/, "").split(/[ -]/);
98
+ const digits = [...groups.join("")];
99
+ if (value.startsWith("+")) return digits.length >= 8 && digits.length <= 15 && digits[0] !== "0";
100
+ if (digits.length < 10 || digits.length > 11) return false;
101
+ return groups.length === 1 || groups.slice(1).every((g) => GROUP_SIZES.has([...g].length));
102
+ }
103
+ function normalise(kind, value) {
104
+ const v = typeof value === "string" ? value.trim() : "";
105
+ if (kind === PHONE) {
106
+ if (!(whole(E164).test(v) || whole(NATIONAL).test(v)) || !phoneShape(v)) {
107
+ throw new Error("not a phone number");
108
+ }
109
+ const digits = v.replace(/[ -]/g, "");
110
+ return digits.startsWith("+") ? digits : NATIONAL_PREFIX + digits.slice(1);
111
+ }
112
+ if (kind === EMAIL) {
113
+ if (!whole(EMAIL_RE).test(v)) throw new Error("not an email address");
114
+ return v.toLowerCase();
115
+ }
116
+ throw new Error(`not a value kind: ${JSON.stringify(kind)}`);
117
+ }
118
+ function findPersonValues(text2) {
119
+ if (typeof text2 !== "string" || !text2) return [];
120
+ const skipped = [...text2.matchAll(global(PERSON_TOKEN))].map((m) => [m.index, m.index + m[0].length]);
121
+ const found = [];
122
+ const add = (kind, m, normalised) => {
123
+ const start = m.index;
124
+ const end = start + m[0].length;
125
+ if (skipped.some(([s, e]) => s <= start && end <= e)) return;
126
+ if (found.some((f) => f.start < end && start < f.end)) return;
127
+ found.push({ kind, value: m[0], normalised, line: lineOf(text2, start), start, end });
128
+ };
129
+ for (const m of text2.matchAll(global(EMAIL_RE))) add(EMAIL, m, m[0].toLowerCase());
130
+ for (const source of [E164, NATIONAL]) {
131
+ for (const m of text2.matchAll(global(source))) {
132
+ if (phoneShape(m[0])) add(PHONE, m, normalise(PHONE, m[0]));
133
+ }
134
+ }
135
+ for (const m of text2.matchAll(global(HOME, "i"))) add(HOME_PATH, m, m[0]);
136
+ return found.sort((a, b) => a.start - b.start);
137
+ }
138
+ function findSecrets(text2) {
139
+ if (typeof text2 !== "string" || !text2) return [];
140
+ return [...text2.matchAll(global(KEY_PREFIX))].map((m) => ({ kind: "key-prefix", line: lineOf(text2, m.index) }));
141
+ }
84
142
 
85
143
  // src/lib/team-setup-types.ts
86
144
  var PARTS = ["hooks", "mcp", "agents", "commands", "instructions"];
87
145
  var PERSON_ID_RE = new RegExp(`^${PERSON_ID}$`);
88
146
 
147
+ // src/sync-memory.ts
148
+ import { existsSync as existsSync2 } from "fs";
149
+ import { mkdir as mkdir3, readdir as readdir2, readFile as readFile3, rm as rm3, writeFile as writeFile3 } from "fs/promises";
150
+ import { dirname as dirname3, join as join3, resolve as resolve2 } from "path";
151
+
152
+ // src/lib/memory-sync.ts
153
+ import { createHash as createHash2 } from "crypto";
154
+ var INDEX_FILE = "MEMORY.md";
155
+ var SHAREABLE_TYPES = ["feedback", "project", "reference"];
156
+ var FILE_PATH_RE = /^[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*$/;
157
+ var CONFLICT_COPY_RE = /\.local-\d{4}-\d{2}-\d{2}(?:-\d+)?\.md$/;
158
+ function sha256(text2) {
159
+ return createHash2("sha256").update(text2, "utf8").digest("hex");
160
+ }
161
+ function isFilePath(path) {
162
+ return path.length <= 512 && FILE_PATH_RE.test(path) && !path.split("/").some((s) => s === "." || s === "..");
163
+ }
164
+ function isConflictCopy(path) {
165
+ return CONFLICT_COPY_RE.test(path.split("/").pop() ?? path);
166
+ }
167
+ var BLOCK_RE = /^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
168
+ var YAML_FALSE = /* @__PURE__ */ new Set(["false", "False", "FALSE", "no", "No", "NO", "off", "Off", "OFF"]);
169
+ function readFrontmatter(text2) {
170
+ const m = BLOCK_RE.exec(text2);
171
+ if (!m) return void 0;
172
+ const front = { shareFalse: false };
173
+ for (const line of m[1].split(/\r?\n/)) {
174
+ const kv = /^([A-Za-z_][\w-]*)[ \t]*:[ \t]*(.*?)[ \t]*$/.exec(line);
175
+ if (!kv) continue;
176
+ const raw = kv[2].replace(/[ \t]+#.*$/, "");
177
+ const quoted = /^(["'])(.*)\1$/.exec(raw);
178
+ const value = quoted ? quoted[2] : raw;
179
+ if (kv[1] === "type") front.type = value.trim().toLowerCase();
180
+ if (kv[1] === "share") front.shareFalse = quoted ? value.trim().toLowerCase() === "false" : YAML_FALSE.has(value);
181
+ }
182
+ return front;
183
+ }
184
+ function isShareable(path, text2) {
185
+ if (isConflictCopy(path) || !path.endsWith(".md")) return false;
186
+ const front = readFrontmatter(text2);
187
+ if (front?.shareFalse) return false;
188
+ if (path === INDEX_FILE) return true;
189
+ return !!front && SHAREABLE_TYPES.includes(front.type ?? "");
190
+ }
191
+ function addShareFalse(text2) {
192
+ const eol = text2.includes("\r\n") ? "\r\n" : "\n";
193
+ const m = BLOCK_RE.exec(text2);
194
+ if (!m) return `---${eol}share: false${eol}---${eol}${text2}`;
195
+ const lines = m[1].split(/\r?\n/).filter((l) => !/^share[ \t]*:/.test(l));
196
+ lines.push("share: false");
197
+ const closing = m[0].slice(m[0].lastIndexOf("---"));
198
+ return `---${eol}${lines.join(eol)}${eol}${closing}${text2.slice(m[0].length)}`;
199
+ }
200
+ function localDate(now) {
201
+ const p = (n) => String(n).padStart(2, "0");
202
+ return `${now.getFullYear()}-${p(now.getMonth() + 1)}-${p(now.getDate())}`;
203
+ }
204
+ function conflictCopyName(path, date, taken) {
205
+ const stem = path.replace(/\.md$/, "");
206
+ for (let n = 1; ; n++) {
207
+ const name = `${stem}.local-${date}${n === 1 ? "" : `-${n}`}.md`;
208
+ if (!taken.has(name.toLowerCase())) return name;
209
+ }
210
+ }
211
+ function decide(path, base, team, local) {
212
+ if (team === local) return "unchanged";
213
+ if (team === base) return local === void 0 ? "delete-team" : "local";
214
+ if (local === base) return team === void 0 ? "delete-local" : "team";
215
+ if (path === INDEX_FILE && team !== void 0 && local !== void 0) return "index";
216
+ if (team === void 0) return "local";
217
+ if (local === void 0) return "team";
218
+ return "conflict";
219
+ }
220
+ function decideAll(input) {
221
+ const localHashes = Object.fromEntries(Object.entries(input.local).map(([p, t]) => [p, sha256(t)]));
222
+ const paths = /* @__PURE__ */ new Set([...Object.keys(input.base), ...Object.keys(input.team), ...Object.keys(localHashes)]);
223
+ const rows = {};
224
+ const needed = /* @__PURE__ */ new Set();
225
+ for (const path of [...paths].sort()) {
226
+ if (input.excluded.has(path)) continue;
227
+ const row = decide(path, input.base[path], input.team[path], localHashes[path]);
228
+ rows[path] = row;
229
+ if (row === "team" || row === "conflict" || row === "index") needed.add(input.team[path]);
230
+ if (row === "index" && input.base[path]) needed.add(input.base[path]);
231
+ }
232
+ return { rows, needed: [...needed] };
233
+ }
234
+ function planMerge(input, rows, texts) {
235
+ const plan = {
236
+ manifest: {},
237
+ upload: {},
238
+ writes: {},
239
+ deletes: [],
240
+ pulled: [],
241
+ pushed: [],
242
+ deletedHere: [],
243
+ deletedFromTeam: [],
244
+ conflicts: [],
245
+ indexTeamLines: []
246
+ };
247
+ const taken = new Set(input.taken);
248
+ const teamText = (path) => {
249
+ const text2 = texts[input.team[path]];
250
+ if (text2 === void 0) throw new Error(`the team's ${path} could not be read`);
251
+ return text2;
252
+ };
253
+ for (const path of input.excluded) if (input.team[path]) plan.manifest[path] = input.team[path];
254
+ for (const [path, row] of Object.entries(rows)) {
255
+ const team = input.team[path];
256
+ const local = input.local[path];
257
+ switch (row) {
258
+ case "unchanged":
259
+ if (team) plan.manifest[path] = team;
260
+ break;
261
+ case "local":
262
+ plan.manifest[path] = sha256(local);
263
+ plan.upload[path] = local;
264
+ plan.pushed.push(path);
265
+ break;
266
+ case "delete-team":
267
+ plan.deletedFromTeam.push(path);
268
+ break;
269
+ case "team":
270
+ plan.manifest[path] = team;
271
+ plan.writes[path] = teamText(path);
272
+ plan.pulled.push(path);
273
+ break;
274
+ case "delete-local":
275
+ plan.deletes.push(path);
276
+ plan.deletedHere.push(path);
277
+ break;
278
+ case "conflict": {
279
+ const copy = conflictCopyName(path, input.date, taken);
280
+ taken.add(copy.toLowerCase());
281
+ plan.manifest[path] = team;
282
+ plan.writes[path] = teamText(path);
283
+ plan.writes[copy] = local;
284
+ plan.conflicts.push({ path, copy });
285
+ break;
286
+ }
287
+ case "index": {
288
+ const base = input.base[path] ? texts[input.base[path]] : void 0;
289
+ const merged = mergeIndex(base, teamText(path), local);
290
+ const hash = sha256(merged.text);
291
+ plan.manifest[path] = hash;
292
+ if (merged.text !== local) {
293
+ plan.writes[path] = merged.text;
294
+ plan.pulled.push(path);
295
+ }
296
+ if (hash !== team) {
297
+ plan.upload[path] = merged.text;
298
+ plan.pushed.push(path);
299
+ }
300
+ plan.indexTeamLines.push(...merged.teamLines);
301
+ break;
302
+ }
303
+ }
304
+ }
305
+ return plan;
306
+ }
307
+ var LINK_RE = /\]\(\s*<?([^)\s>]+)>?(?:\s+["'(][^)]*)?\)/;
308
+ function entries(lines) {
309
+ const seen = /* @__PURE__ */ new Map();
310
+ return lines.map((line) => {
311
+ const link = LINK_RE.exec(line);
312
+ const id = link ? `link:${link[1]}` : `text:${line}`;
313
+ const n = seen.get(id) ?? 0;
314
+ seen.set(id, n + 1);
315
+ return { key: n ? `${id}#${n}` : id, line };
316
+ });
317
+ }
318
+ var splitLines = (text2) => text2.split(/\r?\n/);
319
+ function mergeIndex(base, team, local) {
320
+ const eol = local.includes("\r\n") ? "\r\n" : "\n";
321
+ const b = new Map(entries(base === void 0 ? [] : splitLines(base)).map((e) => [e.key, e.line]));
322
+ const teamEntries = entries(splitLines(team));
323
+ const t = new Map(teamEntries.map((e) => [e.key, e.line]));
324
+ const localEntries = entries(splitLines(local));
325
+ const result = [];
326
+ const teamLines = [];
327
+ for (const e of localEntries) {
328
+ const was = b.get(e.key);
329
+ const theirs = t.get(e.key);
330
+ if (theirs === e.line || theirs === was) result.push(e);
331
+ else if (e.line === was) {
332
+ if (theirs !== void 0) result.push({ key: e.key, line: theirs });
333
+ } else {
334
+ result.push(e);
335
+ if (theirs !== void 0) teamLines.push(theirs);
336
+ }
337
+ }
338
+ const baseEntries = entries(base === void 0 ? [] : splitLines(base));
339
+ const localKeys = new Set(localEntries.map((e) => e.key));
340
+ const replacedHere = /* @__PURE__ */ new Map();
341
+ baseEntries.forEach((e, i) => {
342
+ if (e.key.startsWith("text:") && !t.has(e.key) && !localKeys.has(e.key)) {
343
+ replacedHere.set(e.key, i ? baseEntries[i - 1].key : "");
344
+ }
345
+ });
346
+ const inResult = (key) => result.findIndex((e) => e.key === key);
347
+ teamEntries.forEach((e, i) => {
348
+ if (inResult(e.key) !== -1) return;
349
+ const was = b.get(e.key);
350
+ const before = i ? teamEntries[i - 1].key : "";
351
+ const both = e.key.startsWith("text:") && [...replacedHere].find(([, prev]) => prev === before);
352
+ if (was === void 0 && both) {
353
+ replacedHere.delete(both[0]);
354
+ teamLines.push(e.line);
355
+ } else if (was === void 0) {
356
+ let at = -1;
357
+ for (let j = i - 1; j >= 0 && at === -1; j--) at = inResult(teamEntries[j].key);
358
+ result.splice(at + 1, 0, e);
359
+ } else if (e.line !== was) {
360
+ teamLines.push(e.line);
361
+ }
362
+ });
363
+ return { text: result.map((e) => e.line).join(eol), teamLines };
364
+ }
365
+ var groupKey = (kind, normalised) => `${kind}:${normalised}`;
366
+ function collectValues(files) {
367
+ const groups = /* @__PURE__ */ new Map();
368
+ const homePaths = [];
369
+ const findings = {};
370
+ for (const path of Object.keys(files).sort()) {
371
+ const found = findPersonValues(files[path]);
372
+ findings[path] = found;
373
+ for (const f of found) {
374
+ if (f.kind === HOME_PATH) {
375
+ if (!homePaths.includes(path)) homePaths.push(path);
376
+ continue;
377
+ }
378
+ const key = groupKey(f.kind, f.normalised);
379
+ const group = groups.get(key);
380
+ if (group) {
381
+ if (!group.files.includes(path)) group.files.push(path);
382
+ } else {
383
+ groups.set(key, {
384
+ kind: f.kind,
385
+ value: f.value,
386
+ normalised: f.normalised,
387
+ files: [path],
388
+ first: { path, line: f.line, text: splitLines(files[path])[f.line - 1].trim() }
389
+ });
390
+ }
391
+ }
392
+ }
393
+ return { groups: [...groups.values()], homePaths, findings };
394
+ }
395
+ function personToken(personId, label) {
396
+ return label ? `\`${personId}\` (${label})` : `\`${personId}\``;
397
+ }
398
+ function rewriteValues(text2, findings, replacement) {
399
+ let out = "";
400
+ let last = 0;
401
+ for (const f of [...findings].sort((a, b) => a.start - b.start)) {
402
+ const to = replacement(f);
403
+ if (to === void 0) continue;
404
+ out += text2.slice(last, f.start) + to;
405
+ last = f.end;
406
+ }
407
+ return out + text2.slice(last);
408
+ }
409
+ function lineDiff(before, after) {
410
+ const a = splitLines(before);
411
+ const b = splitLines(after);
412
+ const out = [];
413
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
414
+ if (a[i] === b[i]) continue;
415
+ if (a[i] !== void 0) out.push(`- ${a[i]}`);
416
+ if (b[i] !== void 0) out.push(`+ ${b[i]}`);
417
+ }
418
+ return out;
419
+ }
420
+
421
+ // src/lib/team-setup-files.ts
422
+ import { execFile } from "child_process";
423
+ import { chmod, mkdir as mkdir2, readFile as readFile2, rename, rm as rm2, writeFile as writeFile2 } from "fs/promises";
424
+ import { homedir as homedir2, userInfo } from "os";
425
+ import { dirname as dirname2, join as join2 } from "path";
426
+ import { promisify } from "util";
427
+ var SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
428
+ function isWorkspace(value) {
429
+ return typeof value === "string" && value.length <= 64 && SLUG_RE.test(value);
430
+ }
431
+ function homeDir() {
432
+ return homedir2();
433
+ }
434
+ function systemdoxDir() {
435
+ return join2(homeDir(), ".claude", "systemdox");
436
+ }
437
+ function workspaceDir(workspace) {
438
+ if (!isWorkspace(workspace)) throw new Error(`${JSON.stringify(workspace)} is not a workspace name`);
439
+ return join2(systemdoxDir(), workspace);
440
+ }
441
+ function statePath(workspace) {
442
+ return join2(workspaceDir(workspace), "state.json");
443
+ }
444
+ async function readJson(path, empty) {
445
+ let text2;
446
+ try {
447
+ text2 = await readFile2(path, "utf8");
448
+ } catch (e) {
449
+ if (e.code === "ENOENT") return empty;
450
+ throw e;
451
+ }
452
+ try {
453
+ return JSON.parse(text2);
454
+ } catch {
455
+ throw new Error(`${path} is not valid JSON: fix or remove it, then run this again`);
456
+ }
457
+ }
458
+ async function writeJsonAtomically(path, value, mode) {
459
+ await mkdir2(dirname2(path), { recursive: true });
460
+ const tmp = `${path}.${process.pid}.tmp`;
461
+ await writeFile2(tmp, JSON.stringify(value, null, 2) + "\n", mode === void 0 ? "utf8" : { encoding: "utf8", mode });
462
+ await rename(tmp, path);
463
+ }
464
+ var run = promisify(execFile);
465
+ async function readState(workspace) {
466
+ return readJson(statePath(workspace), {});
467
+ }
468
+ async function writeState(workspace, state) {
469
+ await writeJsonAtomically(statePath(workspace), state);
470
+ }
471
+ async function updateState(workspace, change) {
472
+ const state = await readState(workspace);
473
+ change(state);
474
+ await writeState(workspace, state);
475
+ return state;
476
+ }
477
+
478
+ // src/sync-memory.ts
479
+ var SYNC_MEMORY_COMMAND = "npx -y @systemdox/mcp-server sync-memory";
480
+ var SyncFailed = class extends Error {
481
+ };
482
+ function refusal(e) {
483
+ if (!(e instanceof Error)) return {};
484
+ const { status, code } = e;
485
+ return { status: typeof status === "number" ? status : void 0, code: typeof code === "string" ? code : void 0 };
486
+ }
487
+ var toPath = (root, rel) => join3(root, ...rel.split("/"));
488
+ async function readFolder(root) {
489
+ const files = {};
490
+ const names = /* @__PURE__ */ new Set();
491
+ async function walk2(dir, prefix) {
492
+ for (const e of await readdir2(dir, { withFileTypes: true })) {
493
+ if (e.name.startsWith(".")) continue;
494
+ const rel = prefix ? `${prefix}/${e.name}` : e.name;
495
+ if (e.isDirectory()) await walk2(join3(dir, e.name), rel);
496
+ else if (e.isFile()) {
497
+ names.add(rel.toLowerCase());
498
+ if (e.name.endsWith(".md")) files[rel] = await readFile3(join3(dir, e.name), "utf8");
499
+ }
500
+ }
501
+ }
502
+ if (existsSync2(root)) await walk2(root, "");
503
+ return { files, names };
504
+ }
505
+ async function pullTeam(client, ws, project) {
506
+ try {
507
+ const latest = await client.getMemory(ws, project);
508
+ return {
509
+ version: latest.version,
510
+ manifest: Object.fromEntries(Object.entries(latest.files).map(([p, f]) => [p, f.sha256])),
511
+ exists: true
512
+ };
513
+ } catch (e) {
514
+ if (refusal(e).status === 404) return { version: 0, manifest: {}, exists: false };
515
+ throw e;
516
+ }
517
+ }
518
+ async function readTexts(client, ws, project, hashes) {
519
+ const texts = {};
520
+ const one = async (batch) => {
521
+ let left = batch;
522
+ while (left.length) {
523
+ const got = await client.readBlobs(ws, project, left);
524
+ for (const b of got.blobs) texts[b.sha256] = b.content;
525
+ if (!got.blobs.length) break;
526
+ left = got.remaining;
527
+ }
528
+ };
529
+ for (let i = 0; i < hashes.length; i += 1e3) {
530
+ const batch = hashes.slice(i, i + 1e3);
531
+ try {
532
+ await one(batch);
533
+ } catch (e) {
534
+ if (!(refusal(e).status === 404)) throw e;
535
+ for (const h of batch) {
536
+ try {
537
+ await one([h]);
538
+ } catch (err) {
539
+ if (!(refusal(err).status === 404)) throw err;
540
+ }
541
+ }
542
+ }
543
+ }
544
+ return texts;
545
+ }
546
+ var Report = class {
547
+ pulled = /* @__PURE__ */ new Set();
548
+ pushed = /* @__PURE__ */ new Set();
549
+ deletedHere = /* @__PURE__ */ new Set();
550
+ deletedFromTeam = /* @__PURE__ */ new Set();
551
+ conflicts = [];
552
+ skipped = /* @__PURE__ */ new Map();
553
+ people = [];
554
+ toAnswer = /* @__PURE__ */ new Map();
555
+ add(plan) {
556
+ plan.pulled.forEach((p) => this.pulled.add(p));
557
+ plan.pushed.forEach((p) => this.pushed.add(p));
558
+ plan.deletedHere.forEach((p) => this.deletedHere.add(p));
559
+ plan.deletedFromTeam.forEach((p) => this.deletedFromTeam.add(p));
560
+ for (const c of plan.conflicts) this.conflicts.push(`${c.path}: the team's text; yours is beside it as ${c.copy}`);
561
+ for (const line of plan.indexTeamLines) this.conflicts.push(`${INDEX_FILE}: your line was kept; the team's was: ${line}`);
562
+ }
563
+ skip(path, reason) {
564
+ if (!this.skipped.has(path)) this.skipped.set(path, reason);
565
+ }
566
+ lines(summary, dryRun) {
567
+ const out = [summary];
568
+ const section = (title, items) => {
569
+ if (items.length) out.push("", `${title}:`, ...items.map((i) => `- ${i}`));
570
+ };
571
+ const sorted = (s) => [...s].sort();
572
+ section(dryRun ? "Would pull" : "Pulled", sorted(this.pulled));
573
+ section(dryRun ? "Would push" : "Pushed", sorted(this.pushed));
574
+ section(dryRun ? "Would delete" : "Deleted", [
575
+ ...sorted(this.deletedHere).map((p) => `${p} (here: the team deleted it)`),
576
+ ...sorted(this.deletedFromTeam).map((p) => `${p} (from the team: you deleted it)`)
577
+ ]);
578
+ section("Conflicts", this.conflicts);
579
+ section(
580
+ "Skipped",
581
+ [...this.skipped.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([p, why]) => `${p}: ${why}`)
582
+ );
583
+ section(
584
+ "People",
585
+ this.people.map(
586
+ (a) => [a.kind, a.answer, a.label, a.personId && `\`${a.personId}\``, a.files !== void 0 && `${a.files} files`].filter(Boolean).join(", ")
587
+ )
588
+ );
589
+ if (this.toAnswer.size) {
590
+ out.push(
591
+ "",
592
+ `Values still to answer: ${[...this.toAnswer.entries()].map(([kind, n]) => `${n} ${kind}`).join(", ")}.`
593
+ );
594
+ }
595
+ return out;
596
+ }
597
+ };
598
+ var ANSWER_WORDS = {
599
+ member: "a member's contact",
600
+ person: "someone else",
601
+ ours: "ours, not a person"
602
+ };
603
+ function labelProblem(label) {
604
+ if (!label) return "a label is needed";
605
+ if (label.length > 60) return "a label is at most 60 characters";
606
+ if (findPersonValues(label).length) return "a label is a role, never a phone number, an email address or a path";
607
+ return void 0;
608
+ }
609
+ async function askLabel(ask, out, question, optional) {
610
+ for (; ; ) {
611
+ const label = (await ask(question)).trim();
612
+ if (optional && !label) return void 0;
613
+ const problem = labelProblem(label);
614
+ if (!problem) return label;
615
+ out(` ${problem}.`);
616
+ }
617
+ }
618
+ async function people(opts, ws, files, report, hint) {
619
+ const { client, out, ask, dryRun } = opts;
620
+ const terminal = !!ask && !dryRun;
621
+ const held = /* @__PURE__ */ new Set();
622
+ const leftOut = /* @__PURE__ */ new Set();
623
+ const current = { ...files };
624
+ for (const [path, text2] of Object.entries(current)) {
625
+ const secret = findSecrets(text2)[0];
626
+ if (secret) {
627
+ held.add(path);
628
+ report.skip(path, `a secret (${secret.kind}) on line ${secret.line}: remove it, then sync again`);
629
+ }
630
+ }
631
+ const { groups, findings } = collectValues(current);
632
+ const answers = /* @__PURE__ */ new Map();
633
+ for (let i = 0; i < groups.length; i += 500) {
634
+ const batch = groups.slice(i, i + 500);
635
+ const got = await client.lookupValues(ws, batch.map((g) => ({ kind: g.kind, value: g.value })));
636
+ batch.forEach((g, j) => {
637
+ const a = got.answers[j];
638
+ if (a && a.answer !== "unanswered") answers.set(groupKey(g.kind, g.normalised), a);
639
+ });
640
+ }
641
+ const vaultDown = /* @__PURE__ */ new Set();
642
+ if (terminal) {
643
+ const filed = [];
644
+ for (const g of groups) {
645
+ const key = groupKey(g.kind, g.normalised);
646
+ if (answers.has(key)) continue;
647
+ let choices = ["m", "p", "o", "x", "s"];
648
+ for (; ; ) {
649
+ const question = [
650
+ `${g.value} (${g.kind}) is in ${g.files.length} file${g.files.length === 1 ? "" : "s"}. First line it appears on, in ${g.first.path}:`,
651
+ ` ${g.first.text}`,
652
+ [
653
+ choices.includes("m") && "[m] a member's contact",
654
+ "[p] someone else",
655
+ "[o] ours, not a person",
656
+ "[x] leave these files out",
657
+ "[s] skip for now"
658
+ ].filter(Boolean).join(" "),
659
+ `Answer (${choices.join("/")}): `
660
+ ].join("\n");
661
+ const answer = (await ask(question)).trim().toLowerCase();
662
+ if (!choices.includes(answer)) continue;
663
+ if (answer === "s") break;
664
+ if (answer === "x") {
665
+ for (const path of g.files) {
666
+ if (leftOut.has(path)) continue;
667
+ current[path] = addShareFalse(current[path]);
668
+ await writeFile3(toPath(opts.dir, path), current[path], "utf8");
669
+ leftOut.add(path);
670
+ }
671
+ report.people.push({ kind: g.kind, answer: "left out (share: false)", files: g.files.length });
672
+ break;
673
+ }
674
+ if (answer === "p") {
675
+ const label2 = await askLabel(ask, out, "Their role, as a label (e.g. reseller, sales; never a name): ", false);
676
+ let entry = filed.length ? await (async () => {
677
+ const list = filed.map((f, i) => ` ${i + 1}. ${f.label}: ${f.groups.map((x) => x.value).join(", ")}`);
678
+ for (; ; ) {
679
+ const same = (await ask(["The same person as one filed above?", ...list, "Number, or Enter for a new person: "].join("\n"))).trim();
680
+ if (!same) return void 0;
681
+ const n = Number(same);
682
+ if (Number.isInteger(n) && n >= 1 && n <= filed.length && filed[n - 1].groups.length < 4) return filed[n - 1];
683
+ }
684
+ })() : void 0;
685
+ if (!entry) {
686
+ entry = { groups: [], label: label2 };
687
+ filed.push(entry);
688
+ }
689
+ entry.groups.push(g);
690
+ break;
691
+ }
692
+ const label = answer === "m" ? await askLabel(ask, out, "A role label for it (e.g. owner, business mobile), or Enter for none: ", true) : void 0;
693
+ let result;
694
+ try {
695
+ result = await client.answerValues(ws, [
696
+ { kind: g.kind, value: g.value, answer: answer === "m" ? "member" : "ours", ...label ? { label } : {} }
697
+ ]);
698
+ } catch (e) {
699
+ if (refusal(e).code === "SYD-K019") {
700
+ vaultDown.add(key);
701
+ out(" The vault did not answer (SYD-K019): the files holding it wait for the next sync.");
702
+ break;
703
+ }
704
+ throw e;
705
+ }
706
+ if (result.stored[0]) {
707
+ answers.set(key, result.stored[0]);
708
+ report.people.push({ kind: g.kind, answer: ANSWER_WORDS[result.stored[0].answer], label: result.stored[0].label, personId: result.stored[0].personId });
709
+ break;
710
+ }
711
+ const refused = result.refused[0];
712
+ if (refused?.code === "SYD-K021") {
713
+ out(` ${refused.detail}. Add them in Staff first, or answer p to file them.`);
714
+ choices = choices.filter((c) => c !== "m");
715
+ } else if (refused) out(` ${refused.detail}`);
716
+ }
717
+ }
718
+ for (let i = 0; i < filed.length; i += 50) {
719
+ const batch = filed.slice(i, i + 50);
720
+ let result;
721
+ try {
722
+ result = await client.fileMemoryPeople(
723
+ ws,
724
+ batch.map((f) => ({ values: f.groups.map((g) => ({ kind: g.kind, value: g.value })), label: f.label }))
725
+ );
726
+ } catch (e) {
727
+ if (refusal(e).code === "SYD-K019") {
728
+ out("Contacts did not answer (SYD-K019): the files holding those values wait for the next sync.");
729
+ batch.forEach((f) => f.groups.forEach((g) => vaultDown.add(groupKey(g.kind, g.normalised))));
730
+ continue;
731
+ }
732
+ throw e;
733
+ }
734
+ for (const stored of result.stored) {
735
+ let key;
736
+ try {
737
+ key = groupKey(stored.kind, normalise(stored.kind, stored.value));
738
+ } catch {
739
+ continue;
740
+ }
741
+ answers.set(key, stored);
742
+ }
743
+ for (const r of result.refused) {
744
+ out(` ${batch[r.index]?.label ?? ""}: ${r.detail}`);
745
+ }
746
+ for (const f of batch) {
747
+ const a = answers.get(groupKey(f.groups[0].kind, f.groups[0].normalised));
748
+ if (a?.answer === "person") {
749
+ for (const g of f.groups) report.people.push({ kind: g.kind, answer: ANSWER_WORDS.person, label: a.label, personId: a.personId });
750
+ }
751
+ }
752
+ }
753
+ }
754
+ const rewritten = {};
755
+ for (const [path, text2] of Object.entries(current)) {
756
+ if (leftOut.has(path) || held.has(path)) continue;
757
+ const next = rewriteValues(text2, findings[path] ?? [], (f) => {
758
+ if (f.kind === HOME_PATH) return "~";
759
+ const a = answers.get(groupKey(f.kind, f.normalised));
760
+ return a && (a.answer === "member" || a.answer === "person") && a.personId ? personToken(a.personId, a.label) : void 0;
761
+ });
762
+ if (next !== text2) rewritten[path] = next;
763
+ }
764
+ const paths = Object.keys(rewritten).sort();
765
+ if (paths.length && terminal) {
766
+ out("", "The rewrite:");
767
+ for (const path of paths) out(path, ...lineDiff(current[path], rewritten[path]).map((l) => ` ${l}`));
768
+ const yes = /^y(es)?$/i.test((await ask(`Rewrite ${paths.length} file${paths.length === 1 ? "" : "s"} as shown? [y/N] `)).trim());
769
+ if (yes) {
770
+ for (const path of paths) {
771
+ await writeFile3(toPath(opts.dir, path), rewritten[path], "utf8");
772
+ current[path] = rewritten[path];
773
+ }
774
+ }
775
+ }
776
+ for (const [path, text2] of Object.entries(current)) {
777
+ if (leftOut.has(path) || held.has(path)) continue;
778
+ const pending = findPersonValues(text2).filter((f) => {
779
+ if (f.kind === HOME_PATH) return true;
780
+ return answers.get(groupKey(f.kind, f.normalised))?.answer !== "ours";
781
+ });
782
+ if (!pending.length) continue;
783
+ held.add(path);
784
+ const keys = pending.filter((f) => f.kind !== HOME_PATH).map((f) => groupKey(f.kind, f.normalised));
785
+ if (keys.some((k) => vaultDown.has(k))) {
786
+ report.skip(path, "the vault did not answer (SYD-K019) for a value in it; it syncs once the value is filed");
787
+ } else if (keys.some((k) => !answers.has(k))) {
788
+ report.skip(path, `it holds a value nobody has answered for: run \`${hint}\` in a terminal`);
789
+ } else {
790
+ report.skip(path, `it holds a value to rewrite as its identifier or ~: run \`${hint}\` in a terminal`);
791
+ }
792
+ }
793
+ for (const g of groups) {
794
+ const key = groupKey(g.kind, g.normalised);
795
+ if (!answers.has(key) && g.files.some((p) => !leftOut.has(p))) {
796
+ report.toAnswer.set(g.kind, (report.toAnswer.get(g.kind) ?? 0) + 1);
797
+ }
798
+ }
799
+ return { files: current, held, leftOut };
800
+ }
801
+ async function applyPlan(dir, plan) {
802
+ for (const [path, text2] of Object.entries(plan.writes)) {
803
+ const full = toPath(dir, path);
804
+ await mkdir3(dirname3(full), { recursive: true });
805
+ await writeFile3(full, text2, "utf8");
806
+ }
807
+ for (const path of plan.deletes) await rm3(toPath(dir, path), { force: true });
808
+ }
809
+ var sameManifest = (a, b) => Object.keys(a).length === Object.keys(b).length && Object.entries(a).every(([p, h]) => b[p] === h);
810
+ async function upload(client, ws, project, plan, team, report) {
811
+ const byHash = /* @__PURE__ */ new Map();
812
+ for (const path of Object.keys(plan.upload)) {
813
+ const h = plan.manifest[path];
814
+ byHash.set(h, [...byHash.get(h) ?? [], path]);
815
+ }
816
+ const hashes = [...byHash.keys()];
817
+ const missing = [];
818
+ for (let i = 0; i < hashes.length; i += 1e4) {
819
+ missing.push(...(await client.findMissingBlobs(ws, project, hashes.slice(i, i + 1e4))).missing);
820
+ }
821
+ const blobs = missing.map((h) => ({ sha256: h, content: plan.upload[byHash.get(h)[0]] }));
822
+ let batch = [];
823
+ let bytes = 0;
824
+ const send = async () => {
825
+ if (!batch.length) return;
826
+ const result = await client.uploadBlobs(ws, project, batch);
827
+ for (const r of result.refused) {
828
+ for (const path of byHash.get(r.sha256) ?? []) {
829
+ if (team[path]) plan.manifest[path] = team[path];
830
+ else delete plan.manifest[path];
831
+ plan.pushed = plan.pushed.filter((p) => p !== path);
832
+ report.pushed.delete(path);
833
+ report.skip(path, `refused by SystemDox, ${r.detail.startsWith(r.code) ? r.detail : `${r.code}: ${r.detail}`}`);
834
+ }
835
+ }
836
+ batch = [];
837
+ bytes = 0;
838
+ };
839
+ for (const blob of blobs) {
840
+ const size = Buffer.byteLength(blob.content, "utf8");
841
+ if (batch.length === 100 || batch.length && bytes + size > 5 * 1024 * 1024 - 64 * 1024) await send();
842
+ batch.push(blob);
843
+ bytes += size;
844
+ }
845
+ await send();
846
+ }
847
+ async function syncMemory(opts) {
848
+ const { client, out } = opts;
849
+ const now = opts.now?.() ?? /* @__PURE__ */ new Date();
850
+ try {
851
+ const own = await client.getOwnTeamSetup();
852
+ const ws = own.workspace;
853
+ const project = opts.project ?? (own.memory.length === 1 ? own.memory[0].project : void 0);
854
+ if (!project) {
855
+ throw new SyncFailed(
856
+ own.memory.length ? `${ws} has ${own.memory.length} team memories (${own.memory.map((m) => m.project).join(", ")}): name one with --project.` : `${ws} has no team memory yet: name the project to start with --project.`
857
+ );
858
+ }
859
+ const dir = resolve2(opts.dir ?? join3(workspaceDir(ws), "memory", project));
860
+ const run2 = { ...opts, dir };
861
+ const hint = [SYNC_MEMORY_COMMAND, `--project ${project}`, opts.dir ? `--dir "${opts.dir}"` : ""].filter(Boolean).join(" ");
862
+ const report = new Report();
863
+ const date = localDate(now);
864
+ const stored = (await readState(ws)).memory?.[project];
865
+ let team = await pullTeam(client, ws, project);
866
+ let base = stored ? { version: stored.version, manifest: stored.manifest, exists: true } : { version: 0, manifest: {}, exists: false };
867
+ const folder = await readFolder(dir);
868
+ const shared = {};
869
+ const notShared = /* @__PURE__ */ new Set();
870
+ for (const [path, text2] of Object.entries(folder.files)) {
871
+ if (!isShareable(path, text2)) notShared.add(path);
872
+ else if (!isFilePath(path)) {
873
+ notShared.add(path);
874
+ report.skip(path, "its name has characters a team memory path cannot hold (letters, digits, '.', '_', '-')");
875
+ } else shared[path] = text2;
876
+ }
877
+ const importWrites = {};
878
+ if (opts.importDir) {
879
+ const other = await readFolder(resolve2(opts.importDir));
880
+ const taken = new Set(folder.names);
881
+ for (const [path, text2] of Object.entries(other.files).sort(([a], [b]) => a.localeCompare(b))) {
882
+ if (!isShareable(path, text2) || !isFilePath(path)) continue;
883
+ const here = folder.files[path];
884
+ if (here === void 0) {
885
+ shared[path] = text2;
886
+ importWrites[path] = text2;
887
+ taken.add(path.toLowerCase());
888
+ } else if (here !== text2) {
889
+ const copy = conflictCopyName(path, date, taken);
890
+ taken.add(copy.toLowerCase());
891
+ importWrites[copy] = text2;
892
+ report.conflicts.push(`${path}: this folder's text; the imported one is beside it as ${copy}`);
893
+ }
894
+ }
895
+ folder.names = taken;
896
+ if (!opts.dryRun) {
897
+ for (const [path, text2] of Object.entries(importWrites)) {
898
+ const full = toPath(dir, path);
899
+ await mkdir3(dirname3(full), { recursive: true });
900
+ await writeFile3(full, text2, "utf8");
901
+ }
902
+ }
903
+ }
904
+ const found = await people(run2, ws, shared, report, hint);
905
+ for (const path of found.leftOut) {
906
+ delete found.files[path];
907
+ notShared.add(path);
908
+ }
909
+ const excluded = /* @__PURE__ */ new Set([...found.held, ...notShared]);
910
+ for (const path of found.held) delete found.files[path];
911
+ for (let attempt = 1; ; attempt++) {
912
+ const input = { base: base.manifest, team: team.manifest, local: found.files, excluded, taken: folder.names, date };
913
+ const { rows, needed } = decideAll(input);
914
+ const texts = needed.length ? await readTexts(client, ws, project, needed) : {};
915
+ const plan = planMerge(input, rows, texts);
916
+ report.add(plan);
917
+ if (opts.dryRun) {
918
+ const skipped = report.skipped.size;
919
+ out(
920
+ ...report.lines(
921
+ `Dry run of ${ws}/${project} against version ${team.version}: would pull ${report.pulled.size}, push ${report.pushed.size} and delete ${report.deletedHere.size + report.deletedFromTeam.size}; ${report.conflicts.length} conflicts, ${skipped} skipped. Nothing was asked, written or sent.`,
922
+ true
923
+ )
924
+ );
925
+ return 0;
926
+ }
927
+ await applyPlan(dir, plan);
928
+ let version = team.version;
929
+ if (!sameManifest(plan.manifest, team.manifest)) {
930
+ await upload(client, ws, project, plan, team.manifest, report);
931
+ }
932
+ if (!sameManifest(plan.manifest, team.manifest)) {
933
+ try {
934
+ version = (await client.pushMemoryVersion(ws, project, { baseVersion: team.version, manifest: plan.manifest })).version;
935
+ } catch (e) {
936
+ if (!(refusal(e).status === 409 && refusal(e).code === "SYD-K010")) throw e;
937
+ if (attempt === 2) {
938
+ out(
939
+ ...report.lines(
940
+ `Not pushed: ${ws}/${project} moved on twice while this sync merged. Your folder holds the merge; run sync-memory again.`,
941
+ false
942
+ )
943
+ );
944
+ return 2;
945
+ }
946
+ base = team;
947
+ for (const p of plan.pushed) report.pushed.delete(p);
948
+ const again = await readFolder(dir);
949
+ folder.names = again.names;
950
+ found.files = {};
951
+ for (const [path, text2] of Object.entries(again.files)) {
952
+ if (excluded.has(path) || !isShareable(path, text2) || !isFilePath(path)) continue;
953
+ found.files[path] = text2;
954
+ }
955
+ team = await pullTeam(client, ws, project);
956
+ continue;
957
+ }
958
+ }
959
+ await updateState(ws, (state) => {
960
+ state.memory = { ...state.memory, [project]: { version, manifest: plan.manifest } };
961
+ });
962
+ out(
963
+ ...report.lines(
964
+ `Synced ${ws}/${project} at version ${version}: ${report.pulled.size} pulled, ${report.pushed.size} pushed, ${report.deletedHere.size + report.deletedFromTeam.size} deleted, ${report.conflicts.length} conflicts, ${report.skipped.size} skipped.`,
965
+ false
966
+ )
967
+ );
968
+ return 0;
969
+ }
970
+ } catch (e) {
971
+ out(e.message);
972
+ return 1;
973
+ }
974
+ }
975
+
89
976
  // src/tools/team-setup.ts
90
977
  var LAYOUT = {
91
978
  hooks: { files: ["hooks/hooks.json"], folders: [{ dir: "scripts", md: false }], required: "hooks/hooks.json" },
@@ -95,7 +982,7 @@ var LAYOUT = {
95
982
  instructions: { files: ["CLAUDE.md"], folders: [], required: "CLAUDE.md" }
96
983
  };
97
984
  function expandHome(path) {
98
- return path.replace(/^~(?=$|[\\/])/, homedir2());
985
+ return path.replace(/^~(?=$|[\\/])/, homedir3());
99
986
  }
100
987
  function text(t) {
101
988
  return { content: [{ type: "text", text: t }] };
@@ -109,7 +996,7 @@ async function isLink(path) {
109
996
  }
110
997
  }
111
998
  async function readPartDirectory(part, directory) {
112
- const root = resolve2(directory);
999
+ const root = resolve3(directory);
113
1000
  const layout = LAYOUT[part];
114
1001
  const paths = [];
115
1002
  const leftOut = [];
@@ -119,21 +1006,21 @@ async function readPartDirectory(part, directory) {
119
1006
  let present = true;
120
1007
  for (let i = 1; i <= segments.length; i++) {
121
1008
  const rel = segments.slice(0, i).join("/");
122
- if (await isLink(join2(root, ...segments.slice(0, i)))) {
1009
+ if (await isLink(join4(root, ...segments.slice(0, i)))) {
123
1010
  links.push(rel);
124
1011
  present = false;
125
1012
  break;
126
1013
  }
127
1014
  }
128
- if (present && existsSync2(join2(root, ...segments))) paths.push(path);
1015
+ if (present && existsSync3(join4(root, ...segments))) paths.push(path);
129
1016
  }
130
1017
  for (const { dir, md } of layout.folders) {
131
- const full = join2(root, dir);
1018
+ const full = join4(root, dir);
132
1019
  if (await isLink(full)) {
133
1020
  links.push(dir);
134
1021
  continue;
135
1022
  }
136
- if (!existsSync2(full)) continue;
1023
+ if (!existsSync3(full)) continue;
137
1024
  const walked = await walk(full, { skipHidden: true });
138
1025
  links.push(...walked.links.map((p) => `${dir}/${p}`));
139
1026
  leftOut.push(...walked.hidden.map((p) => `${dir}/${p}`));
@@ -235,6 +1122,29 @@ function registerTeamSetupTools(server, apiClient, { localFiles }) {
235
1122
  return text(describePerson(args.id, person));
236
1123
  }
237
1124
  );
1125
+ if (!localFiles) return;
1126
+ server.registerTool(
1127
+ "sync_memory",
1128
+ {
1129
+ title: "Sync Memory",
1130
+ description: `Sync one project's team memory on this computer with SystemDox: pull the files the team changed, push the ones changed here, keep both texts of a file changed on both sides. It never answers for a person: a file that still holds a phone number, an email address or a home-folder path is skipped and listed, with the command for the member to run in their own terminal (\`${SYNC_MEMORY_COMMAND}\`). Pass dryRun to see what it would do without writing or sending anything.`,
1131
+ inputSchema: {
1132
+ project: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "a project name: lower case letters, digits and -").optional().describe("The project's team memory, e.g. puglieseweb-ltd; needed when the workspace has more than one"),
1133
+ dryRun: z.boolean().optional().describe("Show what would be pulled, pushed, deleted, conflicted and skipped, and change nothing")
1134
+ },
1135
+ annotations: { readOnlyHint: false }
1136
+ },
1137
+ async (args) => {
1138
+ const lines = [];
1139
+ const code = await syncMemory({
1140
+ project: args.project,
1141
+ dryRun: !!args.dryRun,
1142
+ client: apiClient,
1143
+ out: (...l) => lines.push(...l)
1144
+ });
1145
+ return { ...text(lines.join("\n")), ...code ? { isError: true } : {} };
1146
+ }
1147
+ );
238
1148
  }
239
1149
  export {
240
1150
  readPartDirectory,