codemem 0.20.0-alpha.5 → 0.20.0-alpha.7

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,5 @@
1
+ {
2
+ "dependencies": {
3
+ "@opencode-ai/plugin": "1.2.27"
4
+ }
5
+ }
@@ -1,6 +1,6 @@
1
1
  import { appendFile, mkdir } from "node:fs/promises";
2
2
  import { existsSync, readFileSync } from "node:fs";
3
- import { dirname } from "node:path";
3
+ import { basename, dirname, resolve } from "node:path";
4
4
  import { createHash } from "node:crypto";
5
5
  import { spawn as nodeSpawn, execSync } from "node:child_process";
6
6
  import { tool } from "@opencode-ai/plugin";
@@ -15,7 +15,7 @@ import {
15
15
 
16
16
  const TRUTHY_VALUES = ["1", "true", "yes"];
17
17
  const DISABLED_VALUES = ["0", "false", "off"];
18
- const PINNED_BACKEND_VERSION = "0.20.0-alpha.5";
18
+ const PINNED_BACKEND_VERSION = "0.20.0-alpha.7";
19
19
 
20
20
  const normalizeEnvValue = (value) => (value || "").toLowerCase();
21
21
  const envHasValue = (value, truthyValues) =>
@@ -251,11 +251,76 @@ const buildOpencodeAdapterEvent = ({ sessionID, event }) => {
251
251
  };
252
252
  };
253
253
 
254
- const resolveProjectName = (project) =>
255
- project?.name ||
256
- (project?.root
257
- ? String(project.root).split(/[/\\]/).filter(Boolean).pop()
258
- : null) ||
254
+ const normalizeProjectLabel = (value) => {
255
+ if (typeof value !== "string") {
256
+ return null;
257
+ }
258
+ const cleaned = value.trim();
259
+ if (!cleaned) {
260
+ return null;
261
+ }
262
+ if (cleaned.includes("/") || cleaned.includes("\\")) {
263
+ const normalized = cleaned.replaceAll("\\", "/").replace(/\/+$/, "");
264
+ return basename(normalized) || null;
265
+ }
266
+ return cleaned;
267
+ };
268
+
269
+ const inferredProjectByCwd = new Map();
270
+
271
+ const inferProjectFromCwd = (cwd) => {
272
+ if (typeof cwd !== "string") {
273
+ return null;
274
+ }
275
+ const cleaned = cwd.trim();
276
+ if (!cleaned) {
277
+ return null;
278
+ }
279
+ if (inferredProjectByCwd.has(cleaned)) {
280
+ return inferredProjectByCwd.get(cleaned);
281
+ }
282
+
283
+ let current = cleaned;
284
+ while (true) {
285
+ const gitPath = `${current}/.git`;
286
+ if (existsSync(gitPath)) {
287
+ try {
288
+ const text = readFileSync(gitPath, "utf8").trim();
289
+ if (text.startsWith("gitdir:")) {
290
+ const normalized = resolve(current, text.slice("gitdir:".length).trim()).replaceAll(
291
+ "\\",
292
+ "/",
293
+ );
294
+ const worktreeMarker = "/.git/worktrees/";
295
+ const worktreeIndex = normalized.indexOf(worktreeMarker);
296
+ if (worktreeIndex >= 0) {
297
+ const inferred = normalizeProjectLabel(normalized.slice(0, worktreeIndex));
298
+ inferredProjectByCwd.set(cleaned, inferred);
299
+ return inferred;
300
+ }
301
+ }
302
+ } catch {
303
+ // .git is a directory in normal repos; fall through to cwd basename.
304
+ }
305
+ const inferred = normalizeProjectLabel(current);
306
+ inferredProjectByCwd.set(cleaned, inferred);
307
+ return inferred;
308
+ }
309
+ const parent = dirname(current);
310
+ if (parent === current) {
311
+ const inferred = normalizeProjectLabel(cleaned);
312
+ inferredProjectByCwd.set(cleaned, inferred);
313
+ return inferred;
314
+ }
315
+ current = parent;
316
+ }
317
+ };
318
+
319
+ const resolveProjectName = (project, cwd) =>
320
+ normalizeProjectLabel(process.env.CODEMEM_PROJECT) ||
321
+ normalizeProjectLabel(project?.name) ||
322
+ normalizeProjectLabel(project?.root) ||
323
+ inferProjectFromCwd(cwd) ||
259
324
  null;
260
325
 
261
326
  const selectRawEventId = ({ payload, nextEventId }) => {
@@ -599,7 +664,7 @@ export const OpencodeMemPlugin = async ({
599
664
  type,
600
665
  payload,
601
666
  cwd,
602
- project: resolveProjectName(project),
667
+ project: resolveProjectName(project, cwd),
603
668
  startedAt: sessionStartedAt,
604
669
  nowMs: now,
605
670
  nowMono:
@@ -1231,7 +1296,7 @@ export const OpencodeMemPlugin = async ({
1231
1296
  }
1232
1297
 
1233
1298
  // Project name for scoping
1234
- const projectName = resolveProjectName(project);
1299
+ const projectName = resolveProjectName(project, cwd);
1235
1300
  if (projectName) {
1236
1301
  parts.push(projectName);
1237
1302
  }
@@ -1822,6 +1887,9 @@ export const OpencodeMemPlugin = async ({
1822
1887
  export default OpencodeMemPlugin;
1823
1888
  export const __testUtils = {
1824
1889
  PINNED_BACKEND_VERSION,
1890
+ inferProjectFromCwd,
1891
+ normalizeProjectLabel,
1892
+ resolveProjectName,
1825
1893
  buildRunnerArgs,
1826
1894
  appendWorkingSetFileArgs,
1827
1895
  extractApplyPatchPaths,
@@ -10,6 +10,42 @@
10
10
  * echo '{"hook_event_name":"Stop","session_id":"...","last_assistant_message":"..."}' \
11
11
  * | codemem claude-hook-ingest
12
12
  */
13
+ import { resolveDbPath } from "@codemem/core";
13
14
  import { Command } from "commander";
15
+ type IngestResult = {
16
+ inserted: number;
17
+ skipped: number;
18
+ via: "http" | "direct";
19
+ };
20
+ type IngestOpts = {
21
+ host: string;
22
+ port: number;
23
+ db?: string;
24
+ dbPath?: string;
25
+ };
26
+ type IngestDeps = {
27
+ httpIngest?: typeof tryHttpIngest;
28
+ directIngest?: typeof directEnqueue;
29
+ resolveDb?: typeof resolveDbPath;
30
+ };
31
+ /** Try to POST the hook payload to the running viewer server. */
32
+ declare function tryHttpIngest(payload: Record<string, unknown>, host: string, port: number): Promise<{
33
+ ok: boolean;
34
+ inserted: number;
35
+ skipped: number;
36
+ }>;
37
+ /** Fall back to direct raw-event enqueue via the local SQLite store. */
38
+ export declare function directEnqueue(payload: Record<string, unknown>, dbPath: string): {
39
+ inserted: number;
40
+ skipped: number;
41
+ };
42
+ /**
43
+ * Ingest one Claude hook payload using the TS contract:
44
+ * HTTP enqueue first, then direct local enqueue fallback.
45
+ *
46
+ * This path intentionally does not implement file-spool/lock durability.
47
+ */
48
+ export declare function ingestClaudeHookPayload(payload: Record<string, unknown>, opts: IngestOpts, deps?: IngestDeps): Promise<IngestResult>;
14
49
  export declare const claudeHookIngestCommand: Command;
50
+ export {};
15
51
  //# sourceMappingURL=claude-hook-ingest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"claude-hook-ingest.d.ts","sourceRoot":"","sources":["../../src/commands/claude-hook-ingest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAUH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkHpC,eAAO,MAAM,uBAAuB,SAsDjC,CAAC"}
1
+ {"version":3,"file":"claude-hook-ingest.d.ts","sourceRoot":"","sources":["../../src/commands/claude-hook-ingest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAIN,aAAa,EAEb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,KAAK,YAAY,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAC;AAElF,KAAK,UAAU,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,UAAU,GAAG;IACjB,UAAU,CAAC,EAAE,OAAO,aAAa,CAAC;IAClC,YAAY,CAAC,EAAE,OAAO,aAAa,CAAC;IACpC,SAAS,CAAC,EAAE,OAAO,aAAa,CAAC;CACjC,CAAC;AAEF,iEAAiE;AACjE,iBAAe,aAAa,CAC3B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GACV,OAAO,CAAC;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAuB7D;AAED,wEAAwE;AACxE,wBAAgB,aAAa,CAC5B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,MAAM,EAAE,MAAM,GACZ;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CA2EvC;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,CAC5C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,IAAI,EAAE,UAAU,EAChB,IAAI,GAAE,UAAe,GACnB,OAAO,CAAC,YAAY,CAAC,CAavB;AAED,eAAO,MAAM,uBAAuB,SAgDjC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=claude-hook-ingest.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude-hook-ingest.test.d.ts","sourceRoot":"","sources":["../../src/commands/claude-hook-ingest.test.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/commands/db.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,eAAO,MAAM,SAAS,SAEe,CAAC"}
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/commands/db.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA2BpC,eAAO,MAAM,SAAS,SAEe,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=db.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.test.d.ts","sourceRoot":"","sources":["../../src/commands/db.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { Command } from "commander";
2
+ export declare function resolveEmbedProjectScope(cwd: string, projectOpt: string | undefined, allProjects: boolean | undefined): string | null;
3
+ export declare const embedCommand: Command;
4
+ //# sourceMappingURL=embed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../../src/commands/embed.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAYpC,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,WAAW,EAAE,OAAO,GAAG,SAAS,GAC9B,MAAM,GAAG,IAAI,CAOf;AAED,eAAO,MAAM,YAAY,SAuDvB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=embed.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embed.test.d.ts","sourceRoot":"","sources":["../../src/commands/embed.test.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/commands/memory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwHpC,eAAO,MAAM,iBAAiB,SAA4B,CAAC;AAC3D,eAAO,MAAM,mBAAmB,SAA8B,CAAC;AAC/D,eAAO,MAAM,qBAAqB,SAAgC,CAAC;AAEnE,eAAO,MAAM,aAAa,SAEa,CAAC"}
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/commands/memory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAyMpC,eAAO,MAAM,iBAAiB,SAA4B,CAAC;AAC3D,eAAO,MAAM,mBAAmB,SAA8B,CAAC;AAC/D,eAAO,MAAM,qBAAqB,SAAgC,CAAC;AAEnE,eAAO,MAAM,aAAa,SAEa,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../../src/commands/pack.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,eAAO,MAAM,WAAW,SAkFtB,CAAC"}
1
+ {"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../../src/commands/pack.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,eAAO,MAAM,WAAW,SAgFtB,CAAC"}
@@ -1,5 +1,7 @@
1
1
  import { Command } from "commander";
2
2
  import { type ResolvedServeInvocation } from "./serve-invocation.js";
3
3
  export declare function buildForegroundRunnerArgs(scriptPath: string, invocation: ResolvedServeInvocation, execArgv?: string[]): string[];
4
+ export declare function isSqliteVecLoadFailure(error: unknown): boolean;
5
+ export declare function sqliteVecFailureDiagnostics(error: unknown, dbPath: string): string[];
4
6
  export declare const serveCommand: Command;
5
7
  //# sourceMappingURL=serve.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/commands/serve.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAEN,KAAK,uBAAuB,EAG5B,MAAM,uBAAuB,CAAC;AAsG/B,wBAAgB,yBAAyB,CACxC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,uBAAuB,EACnC,QAAQ,GAAE,MAAM,EAAqB,GACnC,MAAM,EAAE,CAgBV;AAyKD,eAAO,MAAM,YAAY,SAuBtB,CAAC"}
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/commands/serve.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAEN,KAAK,uBAAuB,EAG5B,MAAM,uBAAuB,CAAC;AAsG/B,wBAAgB,yBAAyB,CACxC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,uBAAuB,EACnC,QAAQ,GAAE,MAAM,EAAqB,GACnC,MAAM,EAAE,CAgBV;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAS9D;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAUpF;AA8LD,eAAO,MAAM,YAAY,SAuBtB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA;;GAEG;AAuBH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8HpC,eAAO,MAAM,WAAW,SAE+B,CAAC"}
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA;;GAEG;AA8BH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8HpC,eAAO,MAAM,WAAW,SAE+B,CAAC"}