claude-db 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/dist/capture/cursors.d.ts +1 -3
  3. package/dist/capture/cursors.js +16 -35
  4. package/dist/capture/flush.d.ts +1 -3
  5. package/dist/capture/flush.js +34 -34
  6. package/dist/capture/progress.js +4 -2
  7. package/dist/capture/transcript.d.ts +1 -1
  8. package/dist/capture/transcript.js +6 -6
  9. package/dist/catchup/gather.js +1 -1
  10. package/dist/cli/commands/catchup.js +2 -1
  11. package/dist/cli/commands/graph.js +9 -10
  12. package/dist/cli/commands/insight.js +10 -1
  13. package/dist/cli/commands/memory.js +2 -1
  14. package/dist/cli/commands/setup.js +1 -2
  15. package/dist/cli/commands/sync.js +4 -1
  16. package/dist/cli/install.js +1 -2
  17. package/dist/cli/instructions.d.ts +1 -3
  18. package/dist/cli/instructions.js +5 -40
  19. package/dist/cli/refresh.js +2 -6
  20. package/dist/config/load.js +2 -1
  21. package/dist/config/schema.d.ts +0 -2
  22. package/dist/config/schema.js +0 -2
  23. package/dist/context.js +16 -7
  24. package/dist/daemon/client.d.ts +5 -3
  25. package/dist/daemon/client.js +43 -25
  26. package/dist/daemon/paths.d.ts +3 -1
  27. package/dist/daemon/pid.d.ts +3 -0
  28. package/dist/daemon/pid.js +20 -0
  29. package/dist/daemon/server.js +9 -7
  30. package/dist/embed/local.js +4 -1
  31. package/dist/facts/claude-memory.js +2 -2
  32. package/dist/facts/last-chat.d.ts +1 -1
  33. package/dist/facts/last-chat.js +5 -4
  34. package/dist/facts/model.d.ts +1 -1
  35. package/dist/facts/model.js +20 -16
  36. package/dist/facts/start-render.d.ts +13 -0
  37. package/dist/facts/start-render.js +43 -0
  38. package/dist/facts/start.d.ts +3 -6
  39. package/dist/facts/start.js +32 -46
  40. package/dist/graph/grammars.js +2 -1
  41. package/dist/graph/index.d.ts +1 -1
  42. package/dist/graph/index.js +1 -1
  43. package/dist/graph/query/index.d.ts +1 -0
  44. package/dist/graph/query/index.js +1 -0
  45. package/dist/graph/query/stale.js +19 -2
  46. package/dist/graph/query/usages.d.ts +12 -0
  47. package/dist/graph/query/usages.js +37 -0
  48. package/dist/graph/scan/cache.js +2 -1
  49. package/dist/graph/scan/files.js +2 -2
  50. package/dist/hooks/compact.d.ts +1 -0
  51. package/dist/hooks/compact.js +3 -2
  52. package/dist/hooks/detached.d.ts +0 -1
  53. package/dist/hooks/detached.js +2 -6
  54. package/dist/hooks/grep-symbols.d.ts +3 -1
  55. package/dist/hooks/grep-symbols.js +41 -2
  56. package/dist/hooks/handlers/prefer-usages.js +15 -10
  57. package/dist/hooks/handlers/session-end.js +4 -6
  58. package/dist/hooks/handlers/session-start.js +19 -40
  59. package/dist/hooks/handlers/turn-end.js +1 -1
  60. package/dist/hooks/handlers/user-prompt.js +5 -5
  61. package/dist/hooks/local.js +0 -1
  62. package/dist/hooks/payload.js +6 -5
  63. package/dist/hooks/pick-deliver.js +2 -1
  64. package/dist/hooks/prompt-recall.d.ts +4 -2
  65. package/dist/hooks/prompt-recall.js +10 -10
  66. package/dist/hooks/route.js +8 -3
  67. package/dist/hooks/run.d.ts +1 -2
  68. package/dist/mcp/tools/ids.d.ts +3 -0
  69. package/dist/mcp/tools/ids.js +6 -0
  70. package/dist/mcp/tools/memory.js +2 -1
  71. package/dist/mcp/tools/observations.js +3 -2
  72. package/dist/mcp/tools/search.js +4 -9
  73. package/dist/mcp/tools/usages.js +18 -44
  74. package/dist/pick/worker.js +1 -2
  75. package/dist/search/service.d.ts +5 -0
  76. package/dist/search/service.js +11 -5
  77. package/dist/store/postgres/filters.d.ts +1 -0
  78. package/dist/store/postgres/filters.js +3 -0
  79. package/dist/store/postgres/graph.js +3 -2
  80. package/dist/store/postgres/index.js +3 -1
  81. package/dist/store/postgres/meta.d.ts +1 -0
  82. package/dist/store/postgres/meta.js +4 -0
  83. package/dist/store/postgres/observations.js +3 -3
  84. package/dist/store/project-resolver.d.ts +1 -0
  85. package/dist/store/project-resolver.js +1 -1
  86. package/dist/store/scoped-store.js +3 -1
  87. package/dist/store/sqlite/filters.d.ts +1 -0
  88. package/dist/store/sqlite/filters.js +6 -2
  89. package/dist/store/sqlite/graph.js +3 -2
  90. package/dist/store/sqlite/observations.js +6 -7
  91. package/dist/util/claude-binary.js +5 -4
  92. package/dist/util/claude-cli.js +2 -1
  93. package/dist/util/claude-dir.d.ts +2 -0
  94. package/dist/util/claude-dir.js +8 -0
  95. package/dist/util/env.d.ts +2 -0
  96. package/dist/util/env.js +6 -0
  97. package/dist/util/shortid.d.ts +3 -0
  98. package/dist/util/shortid.js +11 -0
  99. package/docs/how-it-works.md +5 -10
  100. package/docs/setup-guide.md +1 -1
  101. package/package.json +7 -6
  102. package/dist/capture/flush-lock.d.ts +0 -11
  103. package/dist/capture/flush-lock.js +0 -108
  104. package/dist/hooks/start-legacy.d.ts +0 -6
  105. package/dist/hooks/start-legacy.js +0 -47
@@ -29,12 +29,8 @@ A turn is also saved as soon as Claude finishes the reply, in the background, so
29
29
  another chat sees it without waiting for your next prompt. The save at the next
30
30
  prompt stays as the backup, for a reply you interrupted.
31
31
 
32
- Install also writes a short standing instruction into `CLAUDE.local.md` (or
33
- `~/.claude/CLAUDE.md` for a machine-wide install), telling Claude to search
34
- memory before asking you to re-explain something. Hook output is context the
35
- agent may or may not act on; a memory file is a rule for the whole session,
36
- which is what makes recall the default rather than something you have to ask
37
- for. `claude-db uninstall` takes the block back out.
32
+ The MCP server's own instructions tell Claude to search memory before asking
33
+ you to re-explain something. Install does not write to `CLAUDE.md`.
38
34
 
39
35
  **What gets saved.** One observation per turn, and only if that turn edited a
40
36
  file or ran a real command. Questions, `grep`, and "ok" are skipped. A busy day
@@ -153,8 +149,7 @@ database unfinished would be worse than saying nothing.
153
149
 
154
150
  ## Staying current
155
151
 
156
- `claude-db install` copies two things to disk: the `/cdb-scan` skill, and a
157
- standing instruction block in `CLAUDE.local.md`. Claude Code only reads skills
152
+ `claude-db install` copies the skills to disk. Claude Code only reads skills
158
153
  from `~/.claude/skills/`, so a copy has to exist there, but a copy drifts as
159
154
  soon as the package updates.
160
155
 
@@ -231,8 +226,8 @@ the backend, and `CLAUDE_DB_URL` overrides the config file.
231
226
 
232
227
  Search is hybrid, keyword plus vector, on all three backends. Ranking, fusion
233
228
  and token budgeting live in `src/search` rather than in the adapters, so recall
234
- behaves identically no matter which database is plugged in; only retrieval cost
235
- changes. Memory is partitioned by project path, so one database serves every
229
+ stays the same across databases, though keyword ranking differs per engine and
230
+ SQLite and MongoDB vector search scans only the newest rows up to a cap. Memory is partitioned by project path, so one database serves every
236
231
  repo you work in.
237
232
 
238
233
  MongoDB Atlas can index vector search instead of scanning brute-force, but
@@ -20,7 +20,7 @@ claude-db install --project
20
20
  Then restart Claude Code. Hooks and the MCP server load only when Claude Code starts.
21
21
 
22
22
  - Use `claude-db install` instead to switch it on for every project on this machine.
23
- - Keep `.mcp.json` and `CLAUDE.local.md` out of git. They hold personal paths and rules.
23
+ - Keep `.mcp.json` out of git. It holds a personal path.
24
24
 
25
25
  ## 3. Check it works
26
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-db",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Free, open-source memory for Claude Code. Remembers why decisions were made and maps your code. Your own database (SQLite, Postgres or MongoDB), no cloud, no subscription.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -33,6 +33,7 @@
33
33
  "typecheck": "tsc --noEmit -p tsconfig.json",
34
34
  "lint": "node scripts/lint.mjs && eslint . && node scripts/check-fixtures.mjs",
35
35
  "check:fixtures": "node scripts/check-fixtures.mjs",
36
+ "pretest": "npm run build",
36
37
  "test": "node scripts/unit.mjs && node scripts/local.mjs && node scripts/filter.mjs && node scripts/transcript.mjs && node scripts/inject.mjs && node scripts/smoke.mjs",
37
38
  "coverage": "c8 npm test",
38
39
  "check:package": "npm run build && publint && attw --pack . --profile esm-only",
@@ -128,10 +129,10 @@
128
129
  "access": "public"
129
130
  },
130
131
  "optionalDependencies": {
131
- "claude-db-grammars-linux-x64": "0.13.0",
132
- "claude-db-grammars-linux-arm64": "0.13.0",
133
- "claude-db-grammars-darwin-x64": "0.13.0",
134
- "claude-db-grammars-darwin-arm64": "0.13.0",
135
- "claude-db-grammars-win32-x64": "0.13.0"
132
+ "claude-db-grammars-linux-x64": "0.14.0",
133
+ "claude-db-grammars-linux-arm64": "0.14.0",
134
+ "claude-db-grammars-darwin-x64": "0.14.0",
135
+ "claude-db-grammars-darwin-arm64": "0.14.0",
136
+ "claude-db-grammars-win32-x64": "0.14.0"
136
137
  }
137
138
  }
@@ -1,11 +0,0 @@
1
- export interface FlushLockOptions {
2
- waitMs?: number;
3
- onTimeout?: 'run' | 'skip';
4
- }
5
- export type Locked<T> = {
6
- ran: true;
7
- value: T;
8
- } | {
9
- ran: false;
10
- };
11
- export declare function withFlushLock<T>(sessionId: string, work: () => Promise<T>, { waitMs, onTimeout }?: FlushLockOptions): Promise<Locked<T>>;
@@ -1,108 +0,0 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { closeSync, fstatSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync, } from 'node:fs';
3
- import { join } from 'node:path';
4
- import { CONFIG_DIR } from '../config/index.js';
5
- import { safeName } from '../util/json-file.js';
6
- const WAIT_MS = 5_000;
7
- const POLL_MS = 100;
8
- const STALE_MS = 2 * 60_000;
9
- const UNREADABLE_GRACE_MS = 5_000;
10
- const lockOf = (sessionId) => join(CONFIG_DIR, 'cursors', `${safeName(sessionId)}.lock`);
11
- function alive(pid) {
12
- try {
13
- process.kill(pid, 0);
14
- return true;
15
- }
16
- catch (error) {
17
- return error.code === 'EPERM';
18
- }
19
- }
20
- function readOpen(path) {
21
- let fd;
22
- try {
23
- fd = openSync(path, 'r');
24
- }
25
- catch {
26
- return null;
27
- }
28
- try {
29
- return { text: readFileSync(fd, 'utf8'), mtimeMs: fstatSync(fd).mtimeMs };
30
- }
31
- catch {
32
- return null;
33
- }
34
- finally {
35
- closeSync(fd);
36
- }
37
- }
38
- function abandoned(path, now) {
39
- const held = readOpen(path);
40
- if (!held)
41
- return false;
42
- const age = now - held.mtimeMs;
43
- if (age > STALE_MS)
44
- return true;
45
- const pid = Number(held.text.split(' ')[0]);
46
- if (!Number.isInteger(pid) || pid <= 0)
47
- return age > UNREADABLE_GRACE_MS;
48
- return !alive(pid);
49
- }
50
- function tryLock(path, owner) {
51
- try {
52
- writeFileSync(path, owner, { flag: 'wx' });
53
- return true;
54
- }
55
- catch {
56
- return false;
57
- }
58
- }
59
- function release(path, owner) {
60
- if (readOpen(path)?.text === owner)
61
- rmSync(path, { force: true });
62
- }
63
- function takeOver(lock, owner, now) {
64
- const breaker = `${lock}.break`;
65
- if (!tryLock(breaker, owner)) {
66
- if (!abandoned(breaker, now))
67
- return false;
68
- rmSync(breaker, { force: true });
69
- if (!tryLock(breaker, owner))
70
- return false;
71
- }
72
- try {
73
- if (!abandoned(lock, now))
74
- return false;
75
- rmSync(lock, { force: true });
76
- return tryLock(lock, owner);
77
- }
78
- finally {
79
- release(breaker, owner);
80
- }
81
- }
82
- async function acquire(lock, owner, waitMs) {
83
- mkdirSync(join(CONFIG_DIR, 'cursors'), { recursive: true });
84
- const until = Date.now() + waitMs;
85
- for (;;) {
86
- if (tryLock(lock, owner))
87
- return true;
88
- if (abandoned(lock, Date.now()) && takeOver(lock, owner, Date.now()))
89
- return true;
90
- if (Date.now() >= until)
91
- return false;
92
- await new Promise((settle) => setTimeout(settle, POLL_MS));
93
- }
94
- }
95
- export async function withFlushLock(sessionId, work, { waitMs = WAIT_MS, onTimeout = 'run' } = {}) {
96
- const lock = lockOf(sessionId);
97
- const owner = `${process.pid} ${randomUUID()}`;
98
- const held = await acquire(lock, owner, waitMs).catch(() => false);
99
- if (!held && onTimeout === 'skip')
100
- return { ran: false };
101
- try {
102
- return { ran: true, value: await work() };
103
- }
104
- finally {
105
- if (held)
106
- release(lock, owner);
107
- }
108
- }
@@ -1,6 +0,0 @@
1
- import type { RecallContext } from '../context.js';
2
- export interface LegacyBlock {
3
- text: string;
4
- hasMemory: boolean;
5
- }
6
- export declare function legacyBlock(ctx: RecallContext, project: string, restored: ReadonlySet<string>): Promise<LegacyBlock>;
@@ -1,47 +0,0 @@
1
- import { openWork } from '../capture/index.js';
2
- import { toShortId } from '../util/shortid.js';
3
- export async function legacyBlock(ctx, project, restored) {
4
- const sessions = await ctx.store.recentSessions(project, ctx.config.inject.sessions);
5
- if (sessions.length === 0) {
6
- return {
7
- text: '<project-memory>none yet for this project; it is recorded as you work</project-memory>',
8
- hasMemory: false,
9
- };
10
- }
11
- const lines = ['<project-memory>'];
12
- let budget = ctx.config.inject.maxChars;
13
- for (const session of sessions) {
14
- const when = new Date(session.startedAt).toISOString().slice(0, 10);
15
- const line = `- [${when}] ${session.summary ?? ''}`;
16
- if (line.length > budget)
17
- break;
18
- budget -= line.length;
19
- lines.push(line);
20
- }
21
- const open = (await openWork(ctx.store, project)).filter((obs) => !restored.has(obs.id));
22
- if (open.length > 0) {
23
- lines.push('', 'Not committed yet, newest first:');
24
- for (const obs of open.slice(0, 3))
25
- lines.push(`- ${obs.title}`);
26
- }
27
- const rules = (await ctx.store.list({ project, kind: 'preference', limit: 100, newest: true, bodies: false }))
28
- .filter((obs) => obs.status !== 'replaced' && !restored.has(obs.id))
29
- .sort((a, b) => {
30
- const manual = Number(b.sessionId === 'manual') - Number(a.sessionId === 'manual');
31
- return manual !== 0 ? manual : b.createdAt - a.createdAt;
32
- })
33
- .slice(0, 8);
34
- if (rules.length > 0) {
35
- lines.push('', 'Standing rules on record — expand any id with get_observations:');
36
- for (const obs of rules) {
37
- const when = new Date(obs.createdAt).toISOString().slice(0, 10);
38
- const line = `- ${toShortId(obs.id)} [${when}] ${obs.title}`.slice(0, 140);
39
- if (line.length > budget)
40
- break;
41
- budget -= line.length;
42
- lines.push(line);
43
- }
44
- }
45
- lines.push('</project-memory>');
46
- return { text: lines.join('\n'), hasMemory: true };
47
- }