@codemem/mcp 0.43.1 → 0.44.0-alpha.1

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.
@@ -1,27 +1,27 @@
1
1
  import { createHash as e, randomUUID as t } from "node:crypto";
2
- import { ObserverClient as n, VERSION as r, buildDistillReport as i, dedupeOrderedIds as a, judgeDistillReport as o, projectMatchesFilter as s, reconcileFailedRetrievalSurface as c, recordRetrievalSurface as l, resolveProject as u, resolveProjectRoot as d, storeVectors as f, toJson as p } from "@codemem/core";
3
- import { existsSync as m, readFileSync as h } from "node:fs";
4
- import { homedir as g } from "node:os";
5
- import { join as _ } from "node:path";
6
- import { McpServer as v } from "@modelcontextprotocol/sdk/server/mcp.js";
7
- import { z as y } from "zod";
2
+ import { MEMORY_KIND_DESCRIPTIONS as n, ObserverClient as r, REMEMBER_MEMORY_KINDS as i, VERSION as a, buildDistillReport as o, dedupeOrderedIds as s, judgeDistillReport as c, projectMatchesFilter as l, reconcileFailedRetrievalSurface as u, recordRetrievalSurface as d, resolveProject as f, resolveProjectRoot as p, storeVectors as m, toJson as h } from "@codemem/core";
3
+ import { existsSync as g, readFileSync as ee } from "node:fs";
4
+ import { homedir as _ } from "node:os";
5
+ import { join as v } from "node:path";
6
+ import { McpServer as y } from "@modelcontextprotocol/sdk/server/mcp.js";
7
+ import { z as b } from "zod";
8
8
  //#region src/canonical-json.ts
9
- function b(e) {
9
+ function x(e) {
10
10
  return JSON.stringify(e, (e, t) => typeof t != "object" || !t || Array.isArray(t) ? t : Object.fromEntries(Object.entries(t).toSorted(([e], [t]) => e < t ? -1 : +(e > t)))) ?? "undefined";
11
11
  }
12
12
  //#endregion
13
13
  //#region src/project-scope.ts
14
- function x(e) {
14
+ function S(e) {
15
15
  return e?.trim() || null;
16
16
  }
17
- function S() {
18
- return x(process.env.CODEMEM_PROJECT) ?? u(process.cwd());
17
+ function C() {
18
+ return S(process.env.CODEMEM_PROJECT) ?? f(process.cwd());
19
19
  }
20
- function C(e) {
21
- return x(e.project) ?? x(e.envProject) ?? null;
20
+ function w(e) {
21
+ return S(e.project) ?? S(e.envProject) ?? null;
22
22
  }
23
- function w(e, t = S()) {
24
- let n = {}, r = !1, i = (typeof e.project == "string" ? x(e.project) : void 0) || x(t) || void 0;
23
+ function T(e, t = C()) {
24
+ let n = {}, r = !1, i = (typeof e.project == "string" ? S(e.project) : void 0) || S(t) || void 0;
25
25
  i && (n.project = i, r = !0);
26
26
  for (let t of [
27
27
  "kind",
@@ -53,13 +53,13 @@ function w(e, t = S()) {
53
53
  }
54
54
  //#endregion
55
55
  //#region src/content.ts
56
- function T(e) {
56
+ function E(e) {
57
57
  return { content: [{
58
58
  type: "text",
59
59
  text: JSON.stringify(e)
60
60
  }] };
61
61
  }
62
- function E(e) {
62
+ function D(e) {
63
63
  return { content: [{
64
64
  type: "text",
65
65
  text: JSON.stringify({ error: e })
@@ -67,95 +67,87 @@ function E(e) {
67
67
  }
68
68
  //#endregion
69
69
  //#region src/schemas.ts
70
- var ee = {
71
- scope_id: y.string().optional().describe("Filter by a single sharing domain scope_id"),
72
- include_scope_ids: y.array(y.string()).optional().describe("Sharing domain scope_ids to include"),
73
- exclude_scope_ids: y.array(y.string()).optional().describe("Sharing domain scope_ids to exclude")
74
- }, D = {
75
- kind: y.string().optional().describe("Filter by memory kind"),
76
- project: y.string().optional().describe("Filter by project scope (matches sessions.project)"),
77
- ...ee,
78
- visibility: y.array(y.string()).optional(),
79
- include_visibility: y.array(y.string()).optional(),
80
- exclude_visibility: y.array(y.string()).optional(),
81
- include_workspace_ids: y.array(y.string()).optional(),
82
- exclude_workspace_ids: y.array(y.string()).optional(),
83
- include_workspace_kinds: y.array(y.string()).optional(),
84
- exclude_workspace_kinds: y.array(y.string()).optional(),
85
- include_actor_ids: y.array(y.string()).optional(),
86
- exclude_actor_ids: y.array(y.string()).optional(),
87
- include_trust_states: y.array(y.string()).optional(),
88
- exclude_trust_states: y.array(y.string()).optional(),
89
- ownership_scope: y.string().optional(),
90
- personal_first: y.union([y.boolean(), y.string()]).optional(),
91
- trust_bias: y.string().optional(),
92
- widen_shared_when_weak: y.union([y.boolean(), y.string()]).optional(),
93
- widen_shared_min_personal_results: y.number().int().optional(),
94
- widen_shared_min_personal_score: y.number().optional()
95
- }, O = y.enum([
96
- "discovery",
97
- "change",
98
- "feature",
99
- "bugfix",
100
- "refactor",
101
- "decision",
102
- "exploration"
103
- ]), k = Object.keys(D).toSorted();
70
+ var O = {
71
+ scope_id: b.string().optional().describe("Filter by a single sharing domain scope_id"),
72
+ include_scope_ids: b.array(b.string()).optional().describe("Sharing domain scope_ids to include"),
73
+ exclude_scope_ids: b.array(b.string()).optional().describe("Sharing domain scope_ids to exclude")
74
+ }, k = {
75
+ kind: b.string().optional().describe("Filter by memory kind"),
76
+ project: b.string().optional().describe("Filter by project scope (matches sessions.project)"),
77
+ ...O,
78
+ visibility: b.array(b.string()).optional(),
79
+ include_visibility: b.array(b.string()).optional(),
80
+ exclude_visibility: b.array(b.string()).optional(),
81
+ include_workspace_ids: b.array(b.string()).optional(),
82
+ exclude_workspace_ids: b.array(b.string()).optional(),
83
+ include_workspace_kinds: b.array(b.string()).optional(),
84
+ exclude_workspace_kinds: b.array(b.string()).optional(),
85
+ include_actor_ids: b.array(b.string()).optional(),
86
+ exclude_actor_ids: b.array(b.string()).optional(),
87
+ include_trust_states: b.array(b.string()).optional(),
88
+ exclude_trust_states: b.array(b.string()).optional(),
89
+ ownership_scope: b.string().optional(),
90
+ personal_first: b.union([b.boolean(), b.string()]).optional(),
91
+ trust_bias: b.string().optional(),
92
+ widen_shared_when_weak: b.union([b.boolean(), b.string()]).optional(),
93
+ widen_shared_min_personal_results: b.number().int().optional(),
94
+ widen_shared_min_personal_score: b.number().optional()
95
+ }, A = b.enum(i), j = Object.keys(k).toSorted();
104
96
  //#endregion
105
97
  //#region src/tools/distill.ts
106
- function A(e, t, n) {
107
- if (!m(e)) return null;
108
- let r = h(e, "utf8");
98
+ function M(e, t, n) {
99
+ if (!g(e)) return null;
100
+ let r = ee(e, "utf8");
109
101
  return r.trim() ? {
110
102
  path: t,
111
103
  text: r,
112
104
  scope: n
113
105
  } : null;
114
106
  }
115
- function j(e, t = process.cwd()) {
116
- let n = d(t) ?? t;
117
- return [e ? A(_(n, "AGENTS.md"), "AGENTS.md", "project") : null, A(_(g(), ".config", "opencode", "AGENTS.md"), "~/.config/opencode/AGENTS.md", "user")].filter((e) => e != null);
107
+ function te(e, t = process.cwd()) {
108
+ let n = p(t) ?? t;
109
+ return [e ? M(v(n, "AGENTS.md"), "AGENTS.md", "project") : null, M(v(_(), ".config", "opencode", "AGENTS.md"), "~/.config/opencode/AGENTS.md", "user")].filter((e) => e != null);
118
110
  }
119
- function M(e, t) {
111
+ function ne(e, t) {
120
112
  if (e.all_projects) return !1;
121
- let n = u(process.cwd());
113
+ let n = f(process.cwd());
122
114
  if (!n) return !1;
123
- let r = typeof e.project == "string" ? e.project.trim() : "", i = r ? u(process.cwd(), r) : t;
124
- return i ? s(i, n) : !1;
115
+ let r = typeof e.project == "string" ? e.project.trim() : "", i = r ? f(process.cwd(), r) : t;
116
+ return i ? l(i, n) : !1;
125
117
  }
126
- function N(e, t) {
118
+ function re(e, t) {
127
119
  if (e.all_projects && typeof e.project == "string" && e.project.trim()) throw Error("project cannot be combined with all_projects");
128
- return w(e, e.all_projects ? null : t);
120
+ return T(e, e.all_projects ? null : t);
129
121
  }
130
- function te(e, t) {
131
- let { defaultProject: r, store: a } = t;
122
+ function ie(e, t) {
123
+ let { defaultProject: n, store: i } = t;
132
124
  e.tool("memory_distill_candidates", "Mine recurring memories into reviewable context candidates. Read-only; does not modify context files.", {
133
- limit: y.number().int().min(1).max(50).default(10).describe("Max candidates"),
134
- min_recurrence: y.number().int().min(1).max(50).default(2).describe("Minimum member count per candidate"),
135
- all_projects: y.boolean().default(!1).describe("Mine memories across all projects"),
136
- include_documented: y.boolean().default(!1).describe("Include candidates already represented in context files"),
137
- max_evidence_items: y.number().int().min(1).max(20).default(5).describe("Evidence snippets per candidate"),
138
- judge: y.boolean().default(!0).describe("Judge candidates with the observer model and drop routine-activity clusters (on by default; falls back to unjudged output when no observer model is configured)"),
139
- ...D
125
+ limit: b.number().int().min(1).max(50).default(10).describe("Max candidates"),
126
+ min_recurrence: b.number().int().min(1).max(50).default(2).describe("Minimum member count per candidate"),
127
+ all_projects: b.boolean().default(!1).describe("Mine memories across all projects"),
128
+ include_documented: b.boolean().default(!1).describe("Include candidates already represented in context files"),
129
+ max_evidence_items: b.number().int().min(1).max(20).default(5).describe("Evidence snippets per candidate"),
130
+ judge: b.boolean().default(!0).describe("Judge candidates with the observer model and drop routine-activity clusters (on by default; falls back to unjudged output when no observer model is configured)"),
131
+ ...k
140
132
  }, async (e) => {
141
133
  try {
142
- let t = r(), s = N(e, t), c = e.kind ? [e.kind] : void 0, l = e.judge ? Math.min(e.limit * 3, e.limit + 20) : e.limit, u = await i(a, {
134
+ let t = n(), a = re(e, t), s = e.kind ? [e.kind] : void 0, l = e.judge ? Math.min(e.limit * 3, e.limit + 20) : e.limit, u = await o(i, {
143
135
  candidate: {
144
136
  includeDocumented: e.include_documented,
145
137
  maxEvidenceItems: e.max_evidence_items
146
138
  },
147
- contextDocuments: j(M(e, t)),
139
+ contextDocuments: te(ne(e, t)),
148
140
  corpus: {
149
- filters: s ?? null,
150
- kinds: c
141
+ filters: a ?? null,
142
+ kinds: s
151
143
  },
152
144
  limit: l,
153
145
  minRecurrence: e.min_recurrence
154
146
  });
155
147
  if (e.judge) {
156
148
  try {
157
- let e = new n();
158
- u = await o(u, async (t, n) => (await e.observe(t, n)).raw);
149
+ let e = new r();
150
+ u = await c(u, async (t, n) => (await e.observe(t, n)).raw);
159
151
  } catch (e) {
160
152
  let t = e instanceof Error ? e.message : String(e);
161
153
  u = {
@@ -176,31 +168,31 @@ function te(e, t) {
176
168
  }
177
169
  });
178
170
  }
179
- return T(u);
171
+ return E(u);
180
172
  } catch (e) {
181
- return E(e instanceof Error ? e.message : String(e));
173
+ return D(e instanceof Error ? e.message : String(e));
182
174
  }
183
175
  });
184
176
  }
185
177
  //#endregion
186
178
  //#region src/mcp-retrieval-ledger.ts
187
- var ne = 300 * 1e3, re = 2e3, P = /* @__PURE__ */ new WeakMap(), F = 0;
188
- function I(e, t, n) {
179
+ var N = 3e5, P = 2e3, F = /* @__PURE__ */ new WeakMap(), I = 0;
180
+ function L(e, t, n) {
189
181
  if (e.captureRetrievalLedger) try {
190
- let r = l(e.store.db, t);
191
- n && !r.ok && r.reason === "idempotency_conflict" && (t.retrievalStatus === "succeeded" && t.deliveryStatus === "handed_off" || t.retrievalStatus === "no_results" && t.deliveryStatus === "not_attempted") && c(e.store.db, t);
182
+ let r = d(e.store.db, t);
183
+ n && !r.ok && r.reason === "idempotency_conflict" && (t.retrievalStatus === "succeeded" && t.deliveryStatus === "handed_off" || t.retrievalStatus === "no_results" && t.deliveryStatus === "not_attempted") && u(e.store.db, t);
192
184
  } catch {}
193
185
  }
194
- function L(e) {
186
+ function R(e) {
195
187
  if (e == null) return t();
196
188
  let n = e.slice(0, 32).split("");
197
189
  n[12] = "5", n[16] = (Number.parseInt(n[16] ?? "0", 16) & 3 | 8).toString(16);
198
190
  let r = n.join("");
199
191
  return `${r.slice(0, 8)}-${r.slice(8, 12)}-${r.slice(12, 16)}-${r.slice(16, 20)}-${r.slice(20)}`;
200
192
  }
201
- function R(t, n) {
193
+ function z(t, n) {
202
194
  if (n.requestId == null) return null;
203
- let r = e("sha256").update(b({
195
+ let r = e("sha256").update(x({
204
196
  method: "tools/call",
205
197
  params: {
206
198
  name: n.toolName,
@@ -213,8 +205,8 @@ function R(t, n) {
213
205
  r
214
206
  ])).digest("hex");
215
207
  }
216
- function z(e) {
217
- let t = P.get(e);
208
+ function B(e) {
209
+ let t = F.get(e);
218
210
  return t || (t = {
219
211
  byInvocation: /* @__PURE__ */ new WeakMap(),
220
212
  activeByRequest: /* @__PURE__ */ new Map(),
@@ -222,14 +214,14 @@ function z(e) {
222
214
  pendingFailureCount: 0,
223
215
  nextPendingFailureOrder: 0,
224
216
  nextInvocationSequence: 0
225
- }, P.set(e, t)), t;
217
+ }, F.set(e, t)), t;
226
218
  }
227
- function B(e, t) {
219
+ function V(e, t) {
228
220
  for (let [n, r] of e.pendingFailures) {
229
221
  let i = r.filter((e) => e.expiresAt > t);
230
222
  e.pendingFailureCount -= r.length - i.length, i.length === 0 ? e.pendingFailures.delete(n) : i.length !== r.length && e.pendingFailures.set(n, i);
231
223
  }
232
- for (; e.pendingFailureCount > re;) {
224
+ for (; e.pendingFailureCount > P;) {
233
225
  let t, n = Infinity;
234
226
  for (let [r, i] of e.pendingFailures) {
235
227
  let e = i[0]?.order;
@@ -244,25 +236,25 @@ function B(e, t) {
244
236
  --e.pendingFailureCount, r.length === 0 && e.pendingFailures.delete(t);
245
237
  }
246
238
  }
247
- function V(e, t) {
239
+ function H(e, t) {
248
240
  let n = e.pendingFailures.get(t);
249
241
  if (!n) return;
250
242
  let r = n.shift();
251
243
  if (r) return --e.pendingFailureCount, n.length === 0 && e.pendingFailures.delete(t), r.identity;
252
244
  }
253
- function H(e, t, n) {
245
+ function U(e, t, n) {
254
246
  let r = e.pendingFailures.get(t), i = r?.findIndex((e) => e.identity.attemptId === n) ?? -1;
255
247
  !r || i < 0 || (r.splice(i, 1), --e.pendingFailureCount, r.length === 0 && e.pendingFailures.delete(t));
256
248
  }
257
- function U(e, t, n, r) {
249
+ function W(e, t, n, r) {
258
250
  let i = e.pendingFailures.get(t) ?? [];
259
251
  i.some((e) => e.identity.attemptId === n.attemptId) || (i.push({
260
252
  identity: n,
261
- expiresAt: r + ne,
253
+ expiresAt: r + N,
262
254
  order: e.nextPendingFailureOrder
263
- }), e.nextPendingFailureOrder += 1, e.pendingFailures.set(t, i), e.pendingFailureCount += 1, B(e, r));
255
+ }), e.nextPendingFailureOrder += 1, e.pendingFailures.set(t, i), e.pendingFailureCount += 1, V(e, r));
264
256
  }
265
- function W() {
257
+ function G() {
266
258
  try {
267
259
  return {
268
260
  baseRequestId: null,
@@ -270,26 +262,26 @@ function W() {
270
262
  attemptId: t()
271
263
  };
272
264
  } catch {
273
- let e = Date.now().toString(16).slice(-8).padStart(8, "0"), t = F.toString(16).slice(-4).padStart(4, "0");
274
- return F = (F + 1) % 65536, {
265
+ let e = Date.now().toString(16).slice(-8).padStart(8, "0"), t = I.toString(16).slice(-4).padStart(4, "0");
266
+ return I = (I + 1) % 65536, {
275
267
  baseRequestId: null,
276
268
  requestId: null,
277
269
  attemptId: `00000000-0000-4000-8000-${e}${t}`
278
270
  };
279
271
  }
280
272
  }
281
- function G(t, n) {
282
- let r = R(t, n);
273
+ function K(t, n) {
274
+ let r = z(t, n);
283
275
  if (t.retrievalLedgerIdentityMode === "stateless" || r == null) return {
284
276
  baseRequestId: r,
285
277
  requestId: r,
286
- attemptId: L(r)
278
+ attemptId: R(r)
287
279
  };
288
- let i = z(t);
289
- B(i, Date.now());
280
+ let i = B(t);
281
+ V(i, Date.now());
290
282
  let a = n.invocationIdentity ? i.byInvocation.get(n.invocationIdentity) : void 0, o = a?.baseRequestId === r ? a : void 0;
291
283
  if (!o) {
292
- let a = (i.activeByRequest.get(r) ?? 0) === 0 ? V(i, r) : void 0;
284
+ let a = (i.activeByRequest.get(r) ?? 0) === 0 ? H(i, r) : void 0;
293
285
  if (a) o = a;
294
286
  else {
295
287
  let n = i.nextInvocationSequence;
@@ -302,36 +294,36 @@ function G(t, n) {
302
294
  o = {
303
295
  baseRequestId: r,
304
296
  requestId: a,
305
- attemptId: L(a)
297
+ attemptId: R(a)
306
298
  };
307
299
  }
308
300
  n.invocationIdentity && i.byInvocation.set(n.invocationIdentity, o);
309
301
  }
310
302
  return i.activeByRequest.set(r, (i.activeByRequest.get(r) ?? 0) + 1), o;
311
303
  }
312
- function K(e, t) {
304
+ function q(e, t) {
313
305
  try {
314
- return G(e, t);
306
+ return K(e, t);
315
307
  } catch {
316
- return W();
308
+ return G();
317
309
  }
318
310
  }
319
- function q(e, t, n) {
311
+ function J(e, t, n) {
320
312
  if (e.retrievalLedgerIdentityMode === "stateless" || t.baseRequestId == null) return;
321
- let r = z(e), i = r.activeByRequest.get(t.baseRequestId) ?? 0;
322
- i <= 1 ? r.activeByRequest.delete(t.baseRequestId) : r.activeByRequest.set(t.baseRequestId, i - 1), n === "failed" ? U(r, t.baseRequestId, t, Date.now()) : H(r, t.baseRequestId, t.attemptId);
313
+ let r = B(e), i = r.activeByRequest.get(t.baseRequestId) ?? 0;
314
+ i <= 1 ? r.activeByRequest.delete(t.baseRequestId) : r.activeByRequest.set(t.baseRequestId, i - 1), n === "failed" ? W(r, t.baseRequestId, t, Date.now()) : U(r, t.baseRequestId, t.attemptId);
323
315
  }
324
- function J(e, t, n) {
316
+ function Y(e, t, n) {
325
317
  try {
326
- q(e, t, n);
318
+ J(e, t, n);
327
319
  } catch {}
328
320
  }
329
- async function Y(e, t, n) {
330
- let r = K(e, t), i = r.requestId, a = r.attemptId, o = /* @__PURE__ */ new Date(), s;
321
+ async function X(e, t, n) {
322
+ let r = q(e, t), i = r.requestId, a = r.attemptId, o = /* @__PURE__ */ new Date(), s;
331
323
  try {
332
324
  s = t.resolveFilters?.();
333
- let c = await n(s), l = /* @__PURE__ */ new Date(), u = c.error ? E(c.error) : T(c.value), d = t.sourceSessionId ?? e.retrievalLedgerScopeId, f = c.memoryIds.length > 0, p = c.error === "not_found" && !f, m = c.error != null && !p || c.retrievalStatus === "failed" && !f, h = m ? [] : c.memoryIds, g = c.retrievalStatus === "unknown" ? "unknown" : "succeeded";
334
- return I(e, {
325
+ let c = await n(s), l = /* @__PURE__ */ new Date(), u = c.error ? D(c.error) : E(c.value), d = t.sourceSessionId ?? e.retrievalLedgerScopeId, f = c.memoryIds.length > 0, p = c.error === "not_found" && !f, m = c.error != null && !p || c.retrievalStatus === "failed" && !f, h = m ? [] : c.memoryIds, g = c.retrievalStatus === "unknown" ? "unknown" : "succeeded";
326
+ return L(e, {
335
327
  attemptId: a,
336
328
  surface: t.surface,
337
329
  trigger: "explicit",
@@ -353,10 +345,10 @@ async function Y(e, t, n) {
353
345
  limitRequested: t.limit,
354
346
  failureCode: m ? "tool_failed" : void 0,
355
347
  failureStage: m ? "retrieval" : void 0
356
- }, !m), J(e, r, m ? "failed" : "completed"), u;
348
+ }, !m), Y(e, r, m ? "failed" : "completed"), u;
357
349
  } catch (n) {
358
350
  let c = /* @__PURE__ */ new Date(), l = t.sourceSessionId ?? e.retrievalLedgerScopeId;
359
- return I(e, {
351
+ return L(e, {
360
352
  attemptId: a,
361
353
  surface: t.surface,
362
354
  trigger: "explicit",
@@ -377,34 +369,34 @@ async function Y(e, t, n) {
377
369
  filters: s,
378
370
  failureCode: "tool_failed",
379
371
  failureStage: "retrieval"
380
- }, !1), J(e, r, "failed"), E(n instanceof Error ? n.message : String(n));
372
+ }, !1), Y(e, r, "failed"), D(n instanceof Error ? n.message : String(n));
381
373
  }
382
374
  }
383
375
  //#endregion
384
376
  //#region src/memory-access.ts
385
- function X(e, t, n) {
377
+ function Z(e, t, n) {
386
378
  return e.timeline(null, t, 0, 0, n ?? null).find((e) => e.id === t) ?? null;
387
379
  }
388
- function Z(e, t, n) {
380
+ function Q(e, t, n) {
389
381
  if (t.length === 0) return [];
390
382
  let r = [];
391
383
  for (let i of t) {
392
- let t = X(e, i, n);
384
+ let t = Z(e, i, n);
393
385
  t && r.push(t);
394
386
  }
395
387
  return r;
396
388
  }
397
- function ie(e, t, n) {
398
- return X(e, t, n) ? (e.forget(t), !0) : !1;
389
+ function ae(e, t, n) {
390
+ return Z(e, t, n) ? (e.forget(t), !0) : !1;
399
391
  }
400
- function ae(e, t, n = {}) {
392
+ function oe(e, t, n = {}) {
401
393
  return e.db.transaction(() => {
402
- let r = n.now?.() ?? (/* @__PURE__ */ new Date()).toISOString(), i = n.user ?? process.env.USER ?? "unknown", a = n.cwd ?? process.cwd(), o = C({
394
+ let r = n.now?.() ?? (/* @__PURE__ */ new Date()).toISOString(), i = n.user ?? process.env.USER ?? "unknown", a = n.cwd ?? process.cwd(), o = w({
403
395
  project: t.project,
404
396
  envProject: n.envProject
405
- }), s = e.db.prepare("INSERT INTO sessions(started_at, ended_at, cwd, project, user, tool_version, metadata_json)\n VALUES (?, ?, ?, ?, ?, ?, ?)").run(r, r, a, o, i, "mcp-ts", p({ mcp: !0 })), c = Number(s.lastInsertRowid), l = e.remember(c, t.kind, t.title, t.body, t.confidence);
406
- if (!X(e, l)) throw Error("unauthorized_scope");
407
- return e.db.prepare("UPDATE sessions SET ended_at = ?, metadata_json = ? WHERE id = ?").run(n.now?.() ?? (/* @__PURE__ */ new Date()).toISOString(), p({ mcp: !0 }), c), {
397
+ }), s = e.db.prepare("INSERT INTO sessions(started_at, ended_at, cwd, project, user, tool_version, metadata_json)\n VALUES (?, ?, ?, ?, ?, ?, ?)").run(r, r, a, o, i, "mcp-ts", h({ mcp: !0 })), c = Number(s.lastInsertRowid), l = e.remember(c, t.kind, t.title, t.body, t.confidence);
398
+ if (!Z(e, l)) throw Error("unauthorized_scope");
399
+ return e.db.prepare("UPDATE sessions SET ended_at = ?, metadata_json = ? WHERE id = ?").run(n.now?.() ?? (/* @__PURE__ */ new Date()).toISOString(), h({ mcp: !0 }), c), {
408
400
  memId: l,
409
401
  title: t.title,
410
402
  body: t.body
@@ -413,22 +405,22 @@ function ae(e, t, n = {}) {
413
405
  }
414
406
  //#endregion
415
407
  //#region src/tools/items.ts
416
- function oe(e, t) {
408
+ function se(e, t) {
417
409
  let { envProject: n, store: r } = t;
418
410
  e.tool("memory_get", "Fetch a single memory item by ID.", {
419
- memory_id: y.number().int().describe("Memory ID"),
420
- ...D
421
- }, async (e, n) => Y(t, {
411
+ memory_id: b.number().int().describe("Memory ID"),
412
+ ...k
413
+ }, async (e, n) => X(t, {
422
414
  surface: "mcp_get",
423
415
  toolName: "memory_get",
424
416
  toolArguments: e,
425
417
  limit: 1,
426
- resolveFilters: () => w(e, null),
418
+ resolveFilters: () => T(e, null),
427
419
  requestId: n?.requestId,
428
420
  sourceSessionId: n?.sessionId,
429
421
  invocationIdentity: n?.signal
430
422
  }, (t) => {
431
- let n = X(r, e.memory_id, t);
423
+ let n = Z(r, e.memory_id, t);
432
424
  return n ? {
433
425
  value: n,
434
426
  memoryIds: [n.id],
@@ -440,55 +432,55 @@ function oe(e, t) {
440
432
  filters: t
441
433
  };
442
434
  })), e.tool("memory_get_observations", "Fetch multiple memory items by their IDs.", {
443
- ids: y.array(y.number().int()).max(200).describe("Memory IDs to fetch"),
444
- ...D
445
- }, async (e, n) => Y(t, {
435
+ ids: b.array(b.number().int()).max(200).describe("Memory IDs to fetch"),
436
+ ...k
437
+ }, async (e, n) => X(t, {
446
438
  surface: "mcp_get_observations",
447
439
  toolName: "memory_get_observations",
448
440
  toolArguments: e,
449
441
  limit: e.ids.length,
450
- resolveFilters: () => w(e, null),
442
+ resolveFilters: () => T(e, null),
451
443
  requestId: n?.requestId,
452
444
  sourceSessionId: n?.sessionId,
453
445
  invocationIdentity: n?.signal
454
446
  }, (t) => {
455
- let n = Z(r, e.ids, t);
447
+ let n = Q(r, e.ids, t);
456
448
  return {
457
449
  value: { items: n },
458
450
  memoryIds: n.map((e) => e.id),
459
451
  filters: t
460
452
  };
461
453
  })), e.tool("memory_remember", "Create a new memory. Use for milestones, decisions, and notable facts.", {
462
- kind: O.describe("Memory kind"),
463
- title: y.string().describe("Short title"),
464
- body: y.string().describe("Body text (high-signal content)"),
465
- confidence: y.number().min(0).max(1).default(.5).describe("Confidence 0-1"),
466
- project: y.string().optional().describe("Project identifier")
454
+ kind: A.describe("Memory kind"),
455
+ title: b.string().describe("Short title"),
456
+ body: b.string().describe("Body text (high-signal content)"),
457
+ confidence: b.number().min(0).max(1).default(.5).describe("Confidence 0-1"),
458
+ project: b.string().optional().describe("Project identifier")
467
459
  }, async (e) => {
468
460
  try {
469
- let t = ae(r, e, { envProject: n() });
461
+ let t = oe(r, e, { envProject: n() });
470
462
  try {
471
- await f(r.db, t.memId, t.title, t.body);
463
+ await m(r.db, t.memId, t.title, t.body);
472
464
  } catch {}
473
- return T({ id: t.memId });
465
+ return E({ id: t.memId });
474
466
  } catch (e) {
475
- return E(e instanceof Error ? e.message : String(e));
467
+ return D(e instanceof Error ? e.message : String(e));
476
468
  }
477
469
  }), e.tool("memory_forget", "Soft-delete a memory item. Use for incorrect or sensitive data.", {
478
- memory_id: y.number().int().describe("Memory ID to forget"),
479
- ...D
470
+ memory_id: b.number().int().describe("Memory ID to forget"),
471
+ ...k
480
472
  }, async (e) => {
481
473
  try {
482
- return ie(r, e.memory_id, w(e, null)) ? T({ status: "ok" }) : E("not_found");
474
+ return ae(r, e.memory_id, T(e, null)) ? E({ status: "ok" }) : D("not_found");
483
475
  } catch (e) {
484
- return E(e instanceof Error ? e.message : String(e));
476
+ return D(e instanceof Error ? e.message : String(e));
485
477
  }
486
478
  });
487
479
  }
488
480
  //#endregion
489
481
  //#region src/tools/learn.ts
490
- function se(e) {
491
- e.tool("memory_learn", "Learn how to use codemem memory tools. Call this first if unfamiliar.", {}, async () => T({
482
+ function ce(e) {
483
+ e.tool("memory_learn", "Learn how to use codemem memory tools. Call this first if unfamiliar.", {}, async () => E({
492
484
  intro: "Use this tool when you're new to codemem or unsure when to recall/persist.",
493
485
  client_hint: "If you are unfamiliar with codemem, call memory.learn first.",
494
486
  recall: {
@@ -556,22 +548,11 @@ function se(e) {
556
548
  }));
557
549
  }
558
550
  //#endregion
559
- //#region src/memory-kinds.ts
560
- var Q = {
561
- discovery: "Something learned about the codebase, architecture, or tools",
562
- change: "A code change that was made",
563
- feature: "A new feature that was implemented",
564
- bugfix: "A bug that was found and fixed",
565
- refactor: "Code that was refactored or restructured",
566
- decision: "A design or architecture decision",
567
- exploration: "An experiment or investigation (may not have shipped)"
568
- };
569
- //#endregion
570
551
  //#region src/tools/schema.ts
571
- function ce(e) {
572
- e.tool("memory_schema", "Return the memory schema — kinds, fields, and available filters.", {}, async () => T({
573
- kinds: Object.keys(Q),
574
- kind_descriptions: Q,
552
+ function le(e) {
553
+ e.tool("memory_schema", "Return the memory schema — kinds, fields, and available filters.", {}, async () => E({
554
+ kinds: Object.keys(n),
555
+ kind_descriptions: n,
575
556
  fields: {
576
557
  title: "short text",
577
558
  body: "long text",
@@ -583,24 +564,24 @@ function ce(e) {
583
564
  files_modified: "list<string>",
584
565
  prompt_number: "int"
585
566
  },
586
- filters: k
567
+ filters: j
587
568
  }));
588
569
  }
589
570
  //#endregion
590
571
  //#region src/tools/search.ts
591
- function le(e, t) {
572
+ function $(e, t) {
592
573
  let { defaultProject: n, store: r } = t;
593
574
  e.tool("memory_search", "Search memories by text query. Returns full body text for each match.", {
594
- query: y.string().describe("Search query"),
595
- limit: y.number().int().min(1).max(50).default(5).describe("Max results"),
596
- ...D
597
- }, async (e, i) => Y(t, {
575
+ query: b.string().describe("Search query"),
576
+ limit: b.number().int().min(1).max(50).default(5).describe("Max results"),
577
+ ...k
578
+ }, async (e, i) => X(t, {
598
579
  surface: "mcp_search",
599
580
  toolName: "memory_search",
600
581
  toolArguments: e,
601
582
  query: e.query,
602
583
  limit: e.limit,
603
- resolveFilters: () => w(e, n()),
584
+ resolveFilters: () => T(e, n()),
604
585
  requestId: i?.requestId,
605
586
  sourceSessionId: i?.sessionId,
606
587
  invocationIdentity: i?.signal
@@ -621,16 +602,16 @@ function le(e, t) {
621
602
  filters: t
622
603
  };
623
604
  })), e.tool("memory_search_index", "Search memories by text query. Returns compact index entries (no body) for browsing.", {
624
- query: y.string().describe("Search query"),
625
- limit: y.number().int().min(1).max(50).default(8).describe("Max results"),
626
- ...D
627
- }, async (e, i) => Y(t, {
605
+ query: b.string().describe("Search query"),
606
+ limit: b.number().int().min(1).max(50).default(8).describe("Max results"),
607
+ ...k
608
+ }, async (e, i) => X(t, {
628
609
  surface: "mcp_search_index",
629
610
  toolName: "memory_search_index",
630
611
  toolArguments: e,
631
612
  query: e.query,
632
613
  limit: e.limit,
633
- resolveFilters: () => w(e, n()),
614
+ resolveFilters: () => T(e, n()),
634
615
  requestId: i?.requestId,
635
616
  sourceSessionId: i?.sessionId,
636
617
  invocationIdentity: i?.signal
@@ -650,18 +631,18 @@ function le(e, t) {
650
631
  filters: t
651
632
  };
652
633
  })), e.tool("memory_explain", "Explain search results with detailed scoring breakdown.", {
653
- query: y.string().optional().describe("Search query"),
654
- ids: y.array(y.number().int()).max(200).optional().describe("Specific memory IDs to explain"),
655
- limit: y.number().int().min(1).max(50).default(10).describe("Max results"),
656
- include_pack_context: y.boolean().default(!1).describe("Include formatted pack context"),
657
- ...D
658
- }, async (e, i) => Y(t, {
634
+ query: b.string().optional().describe("Search query"),
635
+ ids: b.array(b.number().int()).max(200).optional().describe("Specific memory IDs to explain"),
636
+ limit: b.number().int().min(1).max(50).default(10).describe("Max results"),
637
+ include_pack_context: b.boolean().default(!1).describe("Include formatted pack context"),
638
+ ...k
639
+ }, async (e, i) => X(t, {
659
640
  surface: "mcp_explain",
660
641
  toolName: "memory_explain",
661
642
  toolArguments: e,
662
643
  query: e.query,
663
644
  limit: e.limit,
664
- resolveFilters: () => w(e, n()),
645
+ resolveFilters: () => T(e, n()),
665
646
  requestId: i?.requestId,
666
647
  sourceSessionId: i?.sessionId,
667
648
  invocationIdentity: i?.signal
@@ -674,14 +655,14 @@ function le(e, t) {
674
655
  retrievalStatus: i ? "failed" : void 0
675
656
  };
676
657
  })), e.tool("memory_recent", "Return recent memories, newest first.", {
677
- limit: y.number().int().min(1).max(100).default(8).describe("Max results"),
678
- ...D
679
- }, async (e, i) => Y(t, {
658
+ limit: b.number().int().min(1).max(100).default(8).describe("Max results"),
659
+ ...k
660
+ }, async (e, i) => X(t, {
680
661
  surface: "mcp_recent",
681
662
  toolName: "memory_recent",
682
663
  toolArguments: e,
683
664
  limit: e.limit,
684
- resolveFilters: () => w(e, n()),
665
+ resolveFilters: () => T(e, n()),
685
666
  requestId: i?.requestId,
686
667
  sourceSessionId: i?.sessionId,
687
668
  invocationIdentity: i?.signal
@@ -693,29 +674,29 @@ function le(e, t) {
693
674
  filters: t
694
675
  };
695
676
  })), e.tool("memory_pack", "Build a formatted memory pack from search results — quick one-shot context block.", {
696
- context: y.string().describe("Context description to search for"),
697
- limit: y.number().int().min(1).max(50).optional().describe("Max items to include"),
698
- compact: y.boolean().optional().describe("When true, render a scannable index of all items with full detail only for the top N (default 3). Saves tokens when broad overview matters more than per-item detail."),
699
- compact_detail_count: y.number().int().min(0).max(50).optional().describe("Number of items to show in full detail in compact mode (default 3)"),
700
- compression_mode: y.enum([
677
+ context: b.string().describe("Context description to search for"),
678
+ limit: b.number().int().min(1).max(50).optional().describe("Max items to include"),
679
+ compact: b.boolean().optional().describe("When true, render a scannable index of all items with full detail only for the top N (default 3). Saves tokens when broad overview matters more than per-item detail."),
680
+ compact_detail_count: b.number().int().min(0).max(50).optional().describe("Number of items to show in full detail in compact mode (default 3)"),
681
+ compression_mode: b.enum([
701
682
  "off",
702
683
  "compact",
703
684
  "ids"
704
685
  ]).optional().describe("Near-related compression mode: off disables it, compact applies only to compact rendering, ids applies in all modes. Defaults to CODEMEM_PACK_COMPRESSION or compact."),
705
- ...D
706
- }, async (e, i) => Y(t, {
686
+ ...k
687
+ }, async (e, i) => X(t, {
707
688
  surface: "mcp_pack",
708
689
  toolName: "memory_pack",
709
690
  toolArguments: e,
710
691
  query: e.context,
711
692
  limit: e.limit ?? null,
712
- resolveFilters: () => w(e, n()),
693
+ resolveFilters: () => T(e, n()),
713
694
  requestId: i?.requestId,
714
695
  sourceSessionId: i?.sessionId,
715
696
  invocationIdentity: i?.signal
716
697
  }, async (t) => {
717
698
  let n = e.compact || e.compact_detail_count != null || e.compression_mode != null ? {
718
- compact: e.compact ?? (e.compact_detail_count == null ? void 0 : !0),
699
+ compact: e.compact ?? (e.compact_detail_count != null || void 0),
719
700
  compactDetailCount: e.compact_detail_count,
720
701
  compressionMode: e.compression_mode
721
702
  } : void 0, i = await r.buildMemoryPackAsync(e.context, e.limit ?? void 0, null, t, n);
@@ -728,21 +709,21 @@ function le(e, t) {
728
709
  }
729
710
  //#endregion
730
711
  //#region src/tools/timeline.ts
731
- function $(e, t) {
712
+ function ue(e, t) {
732
713
  let { defaultProject: n, store: r } = t;
733
714
  e.tool("memory_timeline", "Get a chronological window of memories around an anchor (by ID or query).", {
734
- query: y.string().optional().describe("Search query to find anchor"),
735
- memory_id: y.number().int().optional().describe("Anchor memory ID"),
736
- depth_before: y.number().int().min(0).default(3).describe("Items before anchor"),
737
- depth_after: y.number().int().min(0).default(3).describe("Items after anchor"),
738
- ...D
739
- }, async (e, i) => Y(t, {
715
+ query: b.string().optional().describe("Search query to find anchor"),
716
+ memory_id: b.number().int().optional().describe("Anchor memory ID"),
717
+ depth_before: b.number().int().min(0).default(3).describe("Items before anchor"),
718
+ depth_after: b.number().int().min(0).default(3).describe("Items after anchor"),
719
+ ...k
720
+ }, async (e, i) => X(t, {
740
721
  surface: "mcp_timeline",
741
722
  toolName: "memory_timeline",
742
723
  toolArguments: e,
743
724
  query: e.query,
744
725
  limit: e.depth_before + e.depth_after + 1,
745
- resolveFilters: () => w(e, n()),
726
+ resolveFilters: () => T(e, n()),
746
727
  requestId: i?.requestId,
747
728
  sourceSessionId: i?.sessionId,
748
729
  invocationIdentity: i?.signal
@@ -754,33 +735,33 @@ function $(e, t) {
754
735
  filters: t
755
736
  };
756
737
  })), e.tool("memory_expand", "Fetch memories by ID with surrounding timeline context.", {
757
- ids: y.array(y.union([y.number(), y.string()])).max(200).describe("Memory IDs to expand"),
758
- depth_before: y.number().int().min(0).default(3).describe("Timeline items before"),
759
- depth_after: y.number().int().min(0).default(3).describe("Timeline items after"),
760
- include_observations: y.boolean().default(!1).describe("Include full observation details"),
761
- ...D
762
- }, async (e, i) => Y(t, {
738
+ ids: b.array(b.union([b.number(), b.string()])).max(200).describe("Memory IDs to expand"),
739
+ depth_before: b.number().int().min(0).default(3).describe("Timeline items before"),
740
+ depth_after: b.number().int().min(0).default(3).describe("Timeline items after"),
741
+ include_observations: b.boolean().default(!1).describe("Include full observation details"),
742
+ ...k
743
+ }, async (e, i) => X(t, {
763
744
  surface: "mcp_expand",
764
745
  toolName: "memory_expand",
765
746
  toolArguments: e,
766
747
  limit: e.ids.length,
767
- resolveFilters: () => w(e, e.project !== void 0 && !e.project.trim() ? null : n()),
748
+ resolveFilters: () => T(e, e.project !== void 0 && !e.project.trim() ? null : n()),
768
749
  requestId: i?.requestId,
769
750
  sourceSessionId: i?.sessionId,
770
751
  invocationIdentity: i?.signal
771
752
  }, (t) => {
772
- let n = t?.project ?? null, { ordered: i, invalid: o } = a(e.ids), c = [];
773
- o.length > 0 && c.push({
753
+ let n = t?.project ?? null, { ordered: i, invalid: a } = s(e.ids), o = [];
754
+ a.length > 0 && o.push({
774
755
  code: "INVALID_ARGUMENT",
775
756
  field: "ids",
776
757
  message: "some ids are not valid integers",
777
- ids: o
758
+ ids: a
778
759
  });
779
- let l = [], u = [], d = [], f = [], p = [], m = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Map();
760
+ let c = [], u = [], d = [], f = [], p = [], m = /* @__PURE__ */ new Set(), h = /* @__PURE__ */ new Map();
780
761
  for (let a of i) {
781
762
  let i = r.get(a);
782
763
  if (!i?.active) {
783
- l.push(a);
764
+ c.push(a);
784
765
  continue;
785
766
  }
786
767
  let o = i.session_id;
@@ -789,7 +770,7 @@ function $(e, t) {
789
770
  let e = r.db.prepare("SELECT project FROM sessions WHERE id = ? LIMIT 1").get(o);
790
771
  h.set(o, typeof e?.project == "string" ? e.project : null);
791
772
  }
792
- if (!s(n, h.get(o) ?? null)) {
773
+ if (!l(n, h.get(o) ?? null)) {
793
774
  u.push(a);
794
775
  continue;
795
776
  }
@@ -797,28 +778,28 @@ function $(e, t) {
797
778
  u.push(a);
798
779
  continue;
799
780
  }
800
- let c = r.timeline(null, a, e.depth_before, e.depth_after, t), g = c.find((e) => e.id === a);
781
+ let s = r.timeline(null, a, e.depth_before, e.depth_after, t), g = s.find((e) => e.id === a);
801
782
  if (!g) {
802
783
  d.push(a);
803
784
  continue;
804
785
  }
805
786
  f.push(g);
806
- for (let e of c) {
787
+ for (let e of s) {
807
788
  let t = e.id;
808
789
  t <= 0 || m.has(t) || (m.add(t), p.push(e));
809
790
  }
810
791
  }
811
- l.length > 0 && c.push({
792
+ c.length > 0 && o.push({
812
793
  code: "NOT_FOUND",
813
794
  field: "ids",
814
795
  message: "some requested ids were not found",
815
- ids: l
816
- }), u.length > 0 && c.push({
796
+ ids: c
797
+ }), u.length > 0 && o.push({
817
798
  code: "PROJECT_MISMATCH",
818
799
  field: "project",
819
800
  message: "some requested ids are outside the requested project scope",
820
801
  ids: u
821
- }), d.length > 0 && c.push({
802
+ }), d.length > 0 && o.push({
822
803
  code: "FILTER_MISMATCH",
823
804
  field: "filters",
824
805
  message: "some requested ids are outside the requested filters",
@@ -828,15 +809,15 @@ function $(e, t) {
828
809
  if (e.include_observations) {
829
810
  let e = /* @__PURE__ */ new Set(), n = [];
830
811
  for (let t of [...f, ...p]) t.id > 0 && !e.has(t.id) && (e.add(t.id), n.push(t.id));
831
- g = Z(r, n, t);
812
+ g = Q(r, n, t);
832
813
  }
833
814
  return {
834
815
  value: {
835
816
  anchors: f,
836
817
  timeline: p,
837
818
  observations: g,
838
- missing_ids: i.filter((e) => l.includes(e) || u.includes(e) || d.includes(e)),
839
- errors: c,
819
+ missing_ids: i.filter((e) => c.includes(e) || u.includes(e) || d.includes(e)),
820
+ errors: o,
840
821
  metadata: {
841
822
  project: n,
842
823
  requested_ids_count: i.length,
@@ -856,21 +837,21 @@ function $(e, t) {
856
837
  }
857
838
  //#endregion
858
839
  //#region src/server.ts
859
- function ue(e, n = {}) {
860
- let i = new v({
840
+ function de(e, n = {}) {
841
+ let r = new y({
861
842
  name: "codemem",
862
- version: r
863
- }), a = {
843
+ version: a
844
+ }), i = {
864
845
  store: e,
865
- defaultProject: () => n.resolveDefaultProject ? n.resolveDefaultProject() : n.defaultProject === void 0 ? S() : n.defaultProject,
846
+ defaultProject: () => n.resolveDefaultProject ? n.resolveDefaultProject() : n.defaultProject === void 0 ? C() : n.defaultProject,
866
847
  envProject: () => n.envProject === void 0 ? process.env.CODEMEM_PROJECT ?? null : n.envProject,
867
848
  captureRetrievalLedger: n.captureRetrievalLedger !== !1,
868
849
  retrievalLedgerScopeId: n.retrievalLedgerScopeId ?? t(),
869
850
  retrievalLedgerIdentityMode: n.retrievalLedgerIdentityMode ?? "session"
870
851
  };
871
- return le(i, a), $(i, a), te(i, a), oe(i, a), ce(i), se(i), i;
852
+ return $(r, i), ue(r, i), ie(r, i), se(r, i), le(r), ce(r), r;
872
853
  }
873
854
  //#endregion
874
- export { b as n, ue as t };
855
+ export { x as n, de as t };
875
856
 
876
- //# sourceMappingURL=server-BshtPXit.js.map
857
+ //# sourceMappingURL=server-C8Yl-9J0.js.map