claude-db 0.7.0 → 0.8.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.
- package/CHANGELOG.md +126 -0
- package/README.md +11 -3
- package/dist/capture/flush.js +0 -4
- package/dist/capture/index.d.ts +1 -0
- package/dist/capture/index.js +1 -0
- package/dist/capture/summarize.d.ts +3 -0
- package/dist/capture/summarize.js +32 -0
- package/dist/capture/turn-extractor.js +12 -3
- package/dist/cli/commands/adoption.js +8 -2
- package/dist/cli/commands/doctor.js +39 -0
- package/dist/cli/commands/memory.js +22 -1
- package/dist/cli/commands/setup.js +10 -0
- package/dist/cli/commands/view-page.d.ts +2 -0
- package/dist/cli/commands/view-page.js +151 -0
- package/dist/cli/commands/view.d.ts +23 -0
- package/dist/cli/commands/view.js +99 -0
- package/dist/cli/index.js +4 -0
- package/dist/cli/install.js +9 -3
- package/dist/cli/usage.js +2 -0
- package/dist/config/schema.d.ts +11 -0
- package/dist/config/schema.js +4 -0
- package/dist/graph/languages/basic.d.ts +11 -0
- package/dist/graph/languages/basic.js +156 -0
- package/dist/graph/languages/index.d.ts +1 -0
- package/dist/graph/languages/index.js +7 -4
- package/dist/graph/languages/ruby.d.ts +2 -0
- package/dist/graph/languages/ruby.js +16 -0
- package/dist/graph/languages/rules.d.ts +1 -0
- package/dist/graph/query/suggest.d.ts +0 -1
- package/dist/graph/query/suggest.js +2 -9
- package/dist/graph/scan/extract.d.ts +1 -0
- package/dist/graph/scan/extract.js +43 -2
- package/dist/graph/scan/files.d.ts +1 -1
- package/dist/graph/scan/files.js +3 -2
- package/dist/graph/scan/resolve.js +2 -0
- package/dist/hooks/grep-symbols.d.ts +0 -1
- package/dist/hooks/grep-symbols.js +5 -5
- package/dist/hooks/payload.d.ts +1 -0
- package/dist/hooks/payload.js +5 -0
- package/dist/hooks/relevance.d.ts +4 -0
- package/dist/hooks/relevance.js +10 -0
- package/dist/hooks/session-end.js +15 -3
- package/dist/hooks/session-start.js +9 -2
- package/dist/hooks/user-prompt.js +10 -4
- package/dist/mcp/tools/observations.js +1 -1
- package/dist/store/adapter.d.ts +1 -0
- package/dist/store/mongo/index.d.ts +1 -0
- package/dist/store/mongo/index.js +3 -0
- package/dist/store/mongo/sessions.d.ts +1 -0
- package/dist/store/mongo/sessions.js +4 -0
- package/dist/store/postgres/index.d.ts +1 -0
- package/dist/store/postgres/index.js +3 -0
- package/dist/store/postgres/sessions.d.ts +1 -0
- package/dist/store/postgres/sessions.js +4 -0
- package/dist/store/sqlite/index.d.ts +1 -0
- package/dist/store/sqlite/index.js +3 -0
- package/dist/store/sqlite/sessions.d.ts +1 -0
- package/dist/store/sqlite/sessions.js +6 -0
- package/package.json +5 -3
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import type { Observation, ObservationIndexEntry } from '../types.js';
|
|
2
|
+
export declare function overlapCount(prompt: string, entry: {
|
|
3
|
+
title: string;
|
|
4
|
+
snippet?: string | undefined;
|
|
5
|
+
}): number;
|
|
2
6
|
export declare function renderPromptContext(entries: ObservationIndexEntry[], maxChars: number, expanded?: Observation[], expandMaxChars?: number): string | null;
|
package/dist/hooks/relevance.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
+
import { meaningfulTokens } from '../search/stopwords.js';
|
|
1
2
|
import { toShortId } from '../util/shortid.js';
|
|
3
|
+
export function overlapCount(prompt, entry) {
|
|
4
|
+
const wanted = new Set(meaningfulTokens(prompt.toLowerCase()));
|
|
5
|
+
const offered = new Set(meaningfulTokens(`${entry.title} ${entry.snippet ?? ''}`.toLowerCase()));
|
|
6
|
+
let shared = 0;
|
|
7
|
+
for (const word of wanted)
|
|
8
|
+
if (offered.has(word))
|
|
9
|
+
shared++;
|
|
10
|
+
return shared;
|
|
11
|
+
}
|
|
2
12
|
export function renderPromptContext(entries, maxChars, expanded = [], expandMaxChars = 900) {
|
|
3
13
|
if (entries.length === 0)
|
|
4
14
|
return null;
|
|
@@ -2,14 +2,17 @@
|
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import { dirname, resolve } from 'node:path';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { clearCursor, flushSession } from '../capture/index.js';
|
|
5
|
+
import { aiSummary, clearCursor, flushSession, observationsFromTurns, readTranscript, transcriptPathFor, } from '../capture/index.js';
|
|
6
6
|
import { isDue, readState } from '../update.js';
|
|
7
7
|
import { createContext } from '../context.js';
|
|
8
|
-
import { readPayload, runHook } from './payload.js';
|
|
8
|
+
import { capturingDisabled, readPayload, runHook } from './payload.js';
|
|
9
|
+
import { loadConfig } from '../config/index.js';
|
|
9
10
|
import { resolveProject } from '../util/project.js';
|
|
10
11
|
import { silenceSqliteWarning } from '../util/warnings.js';
|
|
11
12
|
silenceSqliteWarning();
|
|
12
13
|
await runHook(async () => {
|
|
14
|
+
if (capturingDisabled(loadConfig().capture.scripted))
|
|
15
|
+
return;
|
|
13
16
|
const payload = await readPayload();
|
|
14
17
|
const sessionId = payload.session_id;
|
|
15
18
|
if (!sessionId)
|
|
@@ -18,12 +21,21 @@ await runHook(async () => {
|
|
|
18
21
|
const ctx = await createContext();
|
|
19
22
|
try {
|
|
20
23
|
const result = await flushSession(ctx, sessionId, project, payload.transcript_path);
|
|
24
|
+
let summary = result.summary;
|
|
25
|
+
if (ctx.config.capture.summarize === 'on') {
|
|
26
|
+
const path = payload.transcript_path ?? transcriptPathFor(project, sessionId);
|
|
27
|
+
const { turns } = readTranscript(path, 0);
|
|
28
|
+
const observations = observationsFromTurns(turns, sessionId, project, ctx.config);
|
|
29
|
+
const ai = await aiSummary(observations.map((obs) => `${obs.title}\n${obs.body}`).join('\n\n'), ctx.config.capture.summarizeModel);
|
|
30
|
+
if (ai)
|
|
31
|
+
summary = `AI: ${ai}`;
|
|
32
|
+
}
|
|
21
33
|
await ctx.store.upsertSession({
|
|
22
34
|
id: sessionId,
|
|
23
35
|
project,
|
|
24
36
|
startedAt: Date.now(),
|
|
25
37
|
endedAt: Date.now(),
|
|
26
|
-
...(
|
|
38
|
+
...(summary ? { summary } : {}),
|
|
27
39
|
});
|
|
28
40
|
clearCursor(sessionId);
|
|
29
41
|
if (ctx.config.updates !== 'off' && isDue(readState())) {
|
|
@@ -50,9 +50,13 @@ await runHook(async () => {
|
|
|
50
50
|
const ctx = await createContext();
|
|
51
51
|
try {
|
|
52
52
|
const sessions = await ctx.store.recentSessions(project, ctx.config.inject.sessions);
|
|
53
|
+
const scanned = (await ctx.store.scannedFiles(project)).length;
|
|
54
|
+
const scanHint = 'Code graph not built yet — run `claude-db scan` once to enable ' +
|
|
55
|
+
'find_usages and the symbol-grep hook.';
|
|
53
56
|
if (sessions.length === 0) {
|
|
54
57
|
emitContext('<project-memory>none yet for this project; ' +
|
|
55
|
-
'it is recorded as you work</project-memory>\n'
|
|
58
|
+
'it is recorded as you work</project-memory>\n' +
|
|
59
|
+
(scanned === 0 ? `${scanHint}\n` : ''));
|
|
56
60
|
return;
|
|
57
61
|
}
|
|
58
62
|
const lines = ['<project-memory>'];
|
|
@@ -96,10 +100,13 @@ await runHook(async () => {
|
|
|
96
100
|
lines.push("Search this project's full history with the memory MCP tools before " +
|
|
97
101
|
'asking the user to re-explain prior decisions.');
|
|
98
102
|
}
|
|
103
|
+
if (scanned === 0)
|
|
104
|
+
lines.push(scanHint);
|
|
99
105
|
const notice = ctx.config.updates === 'off' ? null : updateNotice();
|
|
100
106
|
if (notice)
|
|
101
107
|
lines.push(notice);
|
|
102
|
-
|
|
108
|
+
const body = lines.join('\n');
|
|
109
|
+
emitContext(`${body}\n(context ≈ ${Math.round(body.length / 4)} tokens)\n`);
|
|
103
110
|
await refreshGraphQuietly(ctx.store, project);
|
|
104
111
|
}
|
|
105
112
|
finally {
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { flushSession } from '../capture/index.js';
|
|
3
3
|
import { createContext } from '../context.js';
|
|
4
|
-
import { emitContext, readPayload, runHook } from './payload.js';
|
|
4
|
+
import { capturingDisabled, emitContext, readPayload, runHook } from './payload.js';
|
|
5
|
+
import { loadConfig } from '../config/index.js';
|
|
5
6
|
import { markShown, readShown } from './shown.js';
|
|
6
|
-
import { renderPromptContext } from './relevance.js';
|
|
7
|
+
import { overlapCount, renderPromptContext } from './relevance.js';
|
|
7
8
|
import { isSearchable } from '../util/prompt.js';
|
|
8
9
|
import { resolveProject } from '../util/project.js';
|
|
9
10
|
import { silenceSqliteWarning } from '../util/warnings.js';
|
|
10
11
|
silenceSqliteWarning();
|
|
11
12
|
await runHook(async () => {
|
|
13
|
+
if (capturingDisabled(loadConfig().capture.scripted))
|
|
14
|
+
return;
|
|
12
15
|
const payload = await readPayload();
|
|
13
16
|
const sessionId = payload.session_id;
|
|
14
17
|
if (!sessionId)
|
|
@@ -27,7 +30,10 @@ await runHook(async () => {
|
|
|
27
30
|
project,
|
|
28
31
|
limit: ctx.config.inject.promptResults,
|
|
29
32
|
});
|
|
30
|
-
const
|
|
33
|
+
const floor = ctx.config.inject.minOverlap;
|
|
34
|
+
const entries = found
|
|
35
|
+
.filter((entry) => !shown.has(entry.id))
|
|
36
|
+
.filter((entry) => floor === 0 || overlapCount(prompt, entry) >= floor);
|
|
31
37
|
if (entries.length === 0)
|
|
32
38
|
return;
|
|
33
39
|
const toExpand = entries.slice(0, ctx.config.inject.expandTop);
|
|
@@ -38,7 +44,7 @@ await runHook(async () => {
|
|
|
38
44
|
if (!block)
|
|
39
45
|
return;
|
|
40
46
|
markShown(sessionId, entries.map((entry) => entry.id));
|
|
41
|
-
emitContext(`${block}\n`);
|
|
47
|
+
emitContext(`${block}\n(context ≈ ${Math.round(block.length / 4)} tokens)\n`);
|
|
42
48
|
}
|
|
43
49
|
finally {
|
|
44
50
|
await ctx.close();
|
|
@@ -25,7 +25,7 @@ export function register(server, ctx) {
|
|
|
25
25
|
'truncated answer says there is more'),
|
|
26
26
|
}, (args) => get_observations(ctx, args));
|
|
27
27
|
}
|
|
28
|
-
async function timeline(ctx, { observation_id, before, after
|
|
28
|
+
async function timeline(ctx, { observation_id, before, after }) {
|
|
29
29
|
const entries = await ctx.search.timeline({ observationId: observation_id, before, after });
|
|
30
30
|
if (entries.length === 0) {
|
|
31
31
|
const [found] = await ctx.search.getObservations([observation_id]);
|
package/dist/store/adapter.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface MemoryStore {
|
|
|
12
12
|
upsertSession(session: Session): Promise<void>;
|
|
13
13
|
getSession(id: string): Promise<Session | null>;
|
|
14
14
|
recentSessions(project: string, limit: number): Promise<Session[]>;
|
|
15
|
+
clearSummary(id: string): Promise<boolean>;
|
|
15
16
|
insertObservations(observations: Observation[]): Promise<void>;
|
|
16
17
|
getObservations(ids: string[]): Promise<Observation[]>;
|
|
17
18
|
remove(filter: RemoveFilter): Promise<number>;
|
|
@@ -18,6 +18,7 @@ export declare class MongoStore implements MemoryStore {
|
|
|
18
18
|
upsertSession(session: Session): Promise<void>;
|
|
19
19
|
getSession(id: string): Promise<Session | null>;
|
|
20
20
|
recentSessions(project: string, limit: number): Promise<Session[]>;
|
|
21
|
+
clearSummary(id: string): Promise<boolean>;
|
|
21
22
|
insertObservations(observations: Observation[]): Promise<void>;
|
|
22
23
|
getObservations(ids: string[]): Promise<Observation[]>;
|
|
23
24
|
remove(filter: RemoveFilter): Promise<number>;
|
|
@@ -60,6 +60,9 @@ export class MongoStore {
|
|
|
60
60
|
async recentSessions(project, limit) {
|
|
61
61
|
return sessionsOps.recentSessions(this.sessions, project, limit);
|
|
62
62
|
}
|
|
63
|
+
async clearSummary(id) {
|
|
64
|
+
return sessionsOps.clearSummary(this.sessions, id);
|
|
65
|
+
}
|
|
63
66
|
async insertObservations(observations) {
|
|
64
67
|
return observationsOps.insertObservations(this.observations, this.sessions, this.symbols, this.edges, this.scanned, observations);
|
|
65
68
|
}
|
|
@@ -3,4 +3,5 @@ import type { Session } from '../../types.js';
|
|
|
3
3
|
import type { SessionDoc } from './docs.js';
|
|
4
4
|
export declare function upsertSession(sessions: Collection<SessionDoc>, session: Session): Promise<void>;
|
|
5
5
|
export declare function getSession(sessions: Collection<SessionDoc>, id: string): Promise<Session | null>;
|
|
6
|
+
export declare function clearSummary(sessions: Collection<SessionDoc>, id: string): Promise<boolean>;
|
|
6
7
|
export declare function recentSessions(sessions: Collection<SessionDoc>, project: string, limit: number): Promise<Session[]>;
|
|
@@ -14,6 +14,10 @@ export async function getSession(sessions, id) {
|
|
|
14
14
|
const doc = await sessions.findOne({ _id: id });
|
|
15
15
|
return doc ? toSession(doc) : null;
|
|
16
16
|
}
|
|
17
|
+
export async function clearSummary(sessions, id) {
|
|
18
|
+
const result = (await sessions.updateOne({ _id: id }, { $unset: { summary: '' } }));
|
|
19
|
+
return (result.modifiedCount ?? 0) > 0;
|
|
20
|
+
}
|
|
17
21
|
export async function recentSessions(sessions, project, limit) {
|
|
18
22
|
const docs = await sessions
|
|
19
23
|
.find({ project, summary: { $type: 'string' } })
|
|
@@ -23,6 +23,7 @@ export declare class PostgresStore implements MemoryStore {
|
|
|
23
23
|
upsertSession(session: Session): Promise<void>;
|
|
24
24
|
getSession(id: string): Promise<Session | null>;
|
|
25
25
|
recentSessions(project: string, limit: number): Promise<Session[]>;
|
|
26
|
+
clearSummary(id: string): Promise<boolean>;
|
|
26
27
|
insertObservations(observations: Observation[]): Promise<void>;
|
|
27
28
|
getObservations(ids: string[]): Promise<Observation[]>;
|
|
28
29
|
remove(filter: RemoveFilter): Promise<number>;
|
|
@@ -82,6 +82,9 @@ export class PostgresStore {
|
|
|
82
82
|
async recentSessions(project, limit) {
|
|
83
83
|
return sessionsOps.recentSessions(this.pool, project, limit);
|
|
84
84
|
}
|
|
85
|
+
async clearSummary(id) {
|
|
86
|
+
return sessionsOps.clearSummary(this.pool, id);
|
|
87
|
+
}
|
|
85
88
|
async insertObservations(observations) {
|
|
86
89
|
return insertOps.insertObservations(this.pool, (dims) => this.ensureVectorColumn(dims), observations);
|
|
87
90
|
}
|
|
@@ -2,4 +2,5 @@ import type { Pool } from './driver.js';
|
|
|
2
2
|
import type { Session } from '../../types.js';
|
|
3
3
|
export declare function upsertSession(pool: Pool, session: Session): Promise<void>;
|
|
4
4
|
export declare function getSession(pool: Pool, id: string): Promise<Session | null>;
|
|
5
|
+
export declare function clearSummary(pool: Pool, id: string): Promise<boolean>;
|
|
5
6
|
export declare function recentSessions(pool: Pool, project: string, limit: number): Promise<Session[]>;
|
|
@@ -18,6 +18,10 @@ export async function getSession(pool, id) {
|
|
|
18
18
|
const row = res.rows[0];
|
|
19
19
|
return row ? toSession(row) : null;
|
|
20
20
|
}
|
|
21
|
+
export async function clearSummary(pool, id) {
|
|
22
|
+
const result = await pool.query('UPDATE sessions SET summary = NULL WHERE id = $1 AND summary IS NOT NULL', [id]);
|
|
23
|
+
return (result.rowCount ?? 0) > 0;
|
|
24
|
+
}
|
|
21
25
|
export async function recentSessions(pool, project, limit) {
|
|
22
26
|
const res = await pool.query(`SELECT * FROM sessions
|
|
23
27
|
WHERE project = $1 AND summary IS NOT NULL
|
|
@@ -12,6 +12,7 @@ export declare class SqliteStore implements MemoryStore {
|
|
|
12
12
|
upsertSession(session: Session): Promise<void>;
|
|
13
13
|
getSession(id: string): Promise<Session | null>;
|
|
14
14
|
recentSessions(project: string, limit: number): Promise<Session[]>;
|
|
15
|
+
clearSummary(id: string): Promise<boolean>;
|
|
15
16
|
insertObservations(observations: Observation[]): Promise<void>;
|
|
16
17
|
getObservations(ids: string[]): Promise<Observation[]>;
|
|
17
18
|
remove(filter: RemoveFilter): Promise<number>;
|
|
@@ -56,6 +56,9 @@ export class SqliteStore {
|
|
|
56
56
|
async recentSessions(project, limit) {
|
|
57
57
|
return sessionsOps.recentSessions(this.db, project, limit);
|
|
58
58
|
}
|
|
59
|
+
async clearSummary(id) {
|
|
60
|
+
return sessionsOps.clearSummary(this.db, id);
|
|
61
|
+
}
|
|
59
62
|
async insertObservations(observations) {
|
|
60
63
|
return observationsOps.insertObservations(this.db, observations);
|
|
61
64
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DatabaseSync } from 'node:sqlite';
|
|
2
2
|
import type { Session } from '../../types.js';
|
|
3
3
|
export declare function upsertSession(db: DatabaseSync, session: Session): Promise<void>;
|
|
4
|
+
export declare function clearSummary(db: DatabaseSync, id: string): Promise<boolean>;
|
|
4
5
|
export declare function getSession(db: DatabaseSync, id: string): Promise<Session | null>;
|
|
5
6
|
export declare function recentSessions(db: DatabaseSync, project: string, limit: number): Promise<Session[]>;
|
|
@@ -7,6 +7,12 @@ export async function upsertSession(db, session) {
|
|
|
7
7
|
ended_at = COALESCE(excluded.ended_at, sessions.ended_at),
|
|
8
8
|
summary = COALESCE(excluded.summary, sessions.summary)`).run(session.id, session.project, session.startedAt, session.endedAt ?? null, session.summary ?? null);
|
|
9
9
|
}
|
|
10
|
+
export async function clearSummary(db, id) {
|
|
11
|
+
const result = db
|
|
12
|
+
.prepare('UPDATE sessions SET summary = NULL WHERE id = ? AND summary IS NOT NULL')
|
|
13
|
+
.run(id);
|
|
14
|
+
return Number(result.changes) > 0;
|
|
15
|
+
}
|
|
10
16
|
export async function getSession(db, id) {
|
|
11
17
|
const row = db.prepare('SELECT * FROM sessions WHERE id = ?').get(id);
|
|
12
18
|
return row ? toSession(row) : null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-db",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Persistent memory for Claude Code. Captures why decisions were made, not just which files changed. Bring your own database: SQLite, MongoDB or Postgres. No cloud, no subscription.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"build": "tsc -p tsconfig.json && node scripts/copy-assets.mjs",
|
|
30
30
|
"dev": "tsc -w -p tsconfig.json",
|
|
31
31
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
32
|
+
"lint": "node scripts/lint.mjs",
|
|
32
33
|
"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",
|
|
33
34
|
"smoke": "node scripts/smoke.mjs",
|
|
34
35
|
"unit": "node scripts/unit.mjs",
|
|
@@ -45,6 +46,7 @@
|
|
|
45
46
|
"dependencies": {
|
|
46
47
|
"@ast-grep/lang-go": "^0.0.6",
|
|
47
48
|
"@ast-grep/lang-python": "^0.0.6",
|
|
49
|
+
"@ast-grep/lang-ruby": "^0.0.7",
|
|
48
50
|
"@ast-grep/lang-rust": "^0.0.7",
|
|
49
51
|
"@ast-grep/napi": "^0.45.0",
|
|
50
52
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
@@ -54,8 +56,8 @@
|
|
|
54
56
|
},
|
|
55
57
|
"devDependencies": {
|
|
56
58
|
"@types/node": "^22.20.1",
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
+
"prettier": "^3.8.0",
|
|
60
|
+
"typescript": "^5.9.3"
|
|
59
61
|
},
|
|
60
62
|
"keywords": [
|
|
61
63
|
"claude",
|