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.
- package/CHANGELOG.md +56 -0
- package/dist/capture/cursors.d.ts +1 -3
- package/dist/capture/cursors.js +16 -35
- package/dist/capture/flush.d.ts +1 -3
- package/dist/capture/flush.js +34 -34
- package/dist/capture/progress.js +4 -2
- package/dist/capture/transcript.d.ts +1 -1
- package/dist/capture/transcript.js +6 -6
- package/dist/catchup/gather.js +1 -1
- package/dist/cli/commands/catchup.js +2 -1
- package/dist/cli/commands/graph.js +9 -10
- package/dist/cli/commands/insight.js +10 -1
- package/dist/cli/commands/memory.js +2 -1
- package/dist/cli/commands/setup.js +1 -2
- package/dist/cli/commands/sync.js +4 -1
- package/dist/cli/install.js +1 -2
- package/dist/cli/instructions.d.ts +1 -3
- package/dist/cli/instructions.js +5 -40
- package/dist/cli/refresh.js +2 -6
- package/dist/config/load.js +2 -1
- package/dist/config/schema.d.ts +0 -2
- package/dist/config/schema.js +0 -2
- package/dist/context.js +16 -7
- package/dist/daemon/client.d.ts +5 -3
- package/dist/daemon/client.js +43 -25
- package/dist/daemon/paths.d.ts +3 -1
- package/dist/daemon/pid.d.ts +3 -0
- package/dist/daemon/pid.js +20 -0
- package/dist/daemon/server.js +9 -7
- package/dist/embed/local.js +4 -1
- package/dist/facts/claude-memory.js +2 -2
- package/dist/facts/last-chat.d.ts +1 -1
- package/dist/facts/last-chat.js +5 -4
- package/dist/facts/model.d.ts +1 -1
- package/dist/facts/model.js +20 -16
- package/dist/facts/start-render.d.ts +13 -0
- package/dist/facts/start-render.js +43 -0
- package/dist/facts/start.d.ts +3 -6
- package/dist/facts/start.js +32 -46
- package/dist/graph/grammars.js +2 -1
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/graph/query/index.d.ts +1 -0
- package/dist/graph/query/index.js +1 -0
- package/dist/graph/query/stale.js +19 -2
- package/dist/graph/query/usages.d.ts +12 -0
- package/dist/graph/query/usages.js +37 -0
- package/dist/graph/scan/cache.js +2 -1
- package/dist/graph/scan/files.js +2 -2
- package/dist/hooks/compact.d.ts +1 -0
- package/dist/hooks/compact.js +3 -2
- package/dist/hooks/detached.d.ts +0 -1
- package/dist/hooks/detached.js +2 -6
- package/dist/hooks/grep-symbols.d.ts +3 -1
- package/dist/hooks/grep-symbols.js +41 -2
- package/dist/hooks/handlers/prefer-usages.js +15 -10
- package/dist/hooks/handlers/session-end.js +4 -6
- package/dist/hooks/handlers/session-start.js +19 -40
- package/dist/hooks/handlers/turn-end.js +1 -1
- package/dist/hooks/handlers/user-prompt.js +5 -5
- package/dist/hooks/local.js +0 -1
- package/dist/hooks/payload.js +6 -5
- package/dist/hooks/pick-deliver.js +2 -1
- package/dist/hooks/prompt-recall.d.ts +4 -2
- package/dist/hooks/prompt-recall.js +10 -10
- package/dist/hooks/route.js +8 -3
- package/dist/hooks/run.d.ts +1 -2
- package/dist/mcp/tools/ids.d.ts +3 -0
- package/dist/mcp/tools/ids.js +6 -0
- package/dist/mcp/tools/memory.js +2 -1
- package/dist/mcp/tools/observations.js +3 -2
- package/dist/mcp/tools/search.js +4 -9
- package/dist/mcp/tools/usages.js +18 -44
- package/dist/pick/worker.js +1 -2
- package/dist/search/service.d.ts +5 -0
- package/dist/search/service.js +11 -5
- package/dist/store/postgres/filters.d.ts +1 -0
- package/dist/store/postgres/filters.js +3 -0
- package/dist/store/postgres/graph.js +3 -2
- package/dist/store/postgres/index.js +3 -1
- package/dist/store/postgres/meta.d.ts +1 -0
- package/dist/store/postgres/meta.js +4 -0
- package/dist/store/postgres/observations.js +3 -3
- package/dist/store/project-resolver.d.ts +1 -0
- package/dist/store/project-resolver.js +1 -1
- package/dist/store/scoped-store.js +3 -1
- package/dist/store/sqlite/filters.d.ts +1 -0
- package/dist/store/sqlite/filters.js +6 -2
- package/dist/store/sqlite/graph.js +3 -2
- package/dist/store/sqlite/observations.js +6 -7
- package/dist/util/claude-binary.js +5 -4
- package/dist/util/claude-cli.js +2 -1
- package/dist/util/claude-dir.d.ts +2 -0
- package/dist/util/claude-dir.js +8 -0
- package/dist/util/env.d.ts +2 -0
- package/dist/util/env.js +6 -0
- package/dist/util/shortid.d.ts +3 -0
- package/dist/util/shortid.js +11 -0
- package/docs/how-it-works.md +5 -10
- package/docs/setup-guide.md +1 -1
- package/package.json +7 -6
- package/dist/capture/flush-lock.d.ts +0 -11
- package/dist/capture/flush-lock.js +0 -108
- package/dist/hooks/start-legacy.d.ts +0 -6
- package/dist/hooks/start-legacy.js +0 -47
package/docs/how-it-works.md
CHANGED
|
@@ -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
|
-
|
|
33
|
-
|
|
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
|
|
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
|
-
|
|
235
|
-
|
|
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
|
package/docs/setup-guide.md
CHANGED
|
@@ -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`
|
|
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.
|
|
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.
|
|
132
|
-
"claude-db-grammars-linux-arm64": "0.
|
|
133
|
-
"claude-db-grammars-darwin-x64": "0.
|
|
134
|
-
"claude-db-grammars-darwin-arm64": "0.
|
|
135
|
-
"claude-db-grammars-win32-x64": "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,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
|
-
}
|