claude-db 0.4.1 → 0.5.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 (203) hide show
  1. package/CHANGELOG.md +399 -0
  2. package/README.md +62 -94
  3. package/dist/capture/command.d.ts +0 -14
  4. package/dist/capture/command.js +0 -23
  5. package/dist/capture/flush.d.ts +1 -50
  6. package/dist/capture/flush.js +4 -63
  7. package/dist/capture/git.js +0 -20
  8. package/dist/capture/identity.d.ts +0 -17
  9. package/dist/capture/identity.js +1 -21
  10. package/dist/capture/index.d.ts +1 -0
  11. package/dist/capture/index.js +1 -0
  12. package/dist/capture/manual.d.ts +0 -19
  13. package/dist/capture/manual.js +0 -0
  14. package/dist/capture/progress.d.ts +4 -0
  15. package/dist/capture/progress.js +33 -0
  16. package/dist/capture/transcript.d.ts +0 -45
  17. package/dist/capture/transcript.js +4 -70
  18. package/dist/capture/turn-extractor.d.ts +0 -15
  19. package/dist/capture/turn-extractor.js +1 -104
  20. package/dist/cli/args.d.ts +4 -0
  21. package/dist/cli/args.js +16 -0
  22. package/dist/cli/commands/doctor.d.ts +1 -0
  23. package/dist/cli/commands/doctor.js +76 -0
  24. package/dist/cli/commands/graph.d.ts +2 -0
  25. package/dist/cli/commands/graph.js +93 -0
  26. package/dist/cli/commands/insight.d.ts +3 -0
  27. package/dist/cli/commands/insight.js +129 -0
  28. package/dist/cli/commands/maintain.d.ts +3 -0
  29. package/dist/cli/commands/maintain.js +77 -0
  30. package/dist/cli/commands/memory.d.ts +3 -0
  31. package/dist/cli/commands/memory.js +77 -0
  32. package/dist/cli/commands/seed.d.ts +1 -0
  33. package/dist/cli/commands/seed.js +43 -0
  34. package/dist/cli/commands/setup.d.ts +4 -0
  35. package/dist/cli/commands/setup.js +156 -0
  36. package/dist/cli/commands/sync.d.ts +1 -0
  37. package/dist/cli/commands/sync.js +95 -0
  38. package/dist/cli/commands/transfer.d.ts +9 -0
  39. package/dist/cli/commands/transfer.js +129 -0
  40. package/dist/cli/commands/use.d.ts +1 -0
  41. package/dist/cli/commands/use.js +90 -0
  42. package/dist/cli/constants.d.ts +2 -0
  43. package/dist/cli/constants.js +4 -0
  44. package/dist/cli/files.d.ts +4 -0
  45. package/dist/cli/files.js +33 -0
  46. package/dist/cli/index.js +15 -1080
  47. package/dist/cli/install.d.ts +1 -59
  48. package/dist/cli/install.js +5 -194
  49. package/dist/cli/instructions.d.ts +5 -0
  50. package/dist/cli/instructions.js +55 -0
  51. package/dist/cli/paths.d.ts +5 -0
  52. package/dist/cli/paths.js +19 -0
  53. package/dist/cli/refresh.d.ts +1 -0
  54. package/dist/cli/refresh.js +25 -0
  55. package/dist/cli/usage.d.ts +1 -0
  56. package/dist/cli/usage.js +39 -0
  57. package/dist/config/load.d.ts +0 -5
  58. package/dist/config/load.js +1 -8
  59. package/dist/config/schema.js +2 -58
  60. package/dist/context.d.ts +0 -10
  61. package/dist/context.js +0 -16
  62. package/dist/embed/builtin.d.ts +0 -12
  63. package/dist/embed/builtin.js +0 -20
  64. package/dist/embed/embedder.d.ts +0 -14
  65. package/dist/embed/embedder.js +0 -1
  66. package/dist/embed/index.d.ts +0 -9
  67. package/dist/embed/index.js +0 -9
  68. package/dist/embed/local.d.ts +0 -8
  69. package/dist/embed/local.js +0 -12
  70. package/dist/graph/index.d.ts +7 -0
  71. package/dist/graph/index.js +4 -0
  72. package/dist/graph/languages/ecmascript.d.ts +4 -0
  73. package/dist/graph/languages/ecmascript.js +47 -0
  74. package/dist/graph/languages/go.d.ts +2 -0
  75. package/dist/graph/languages/go.js +15 -0
  76. package/dist/graph/languages/index.d.ts +6 -0
  77. package/dist/graph/languages/index.js +20 -0
  78. package/dist/graph/languages/python.d.ts +2 -0
  79. package/dist/graph/languages/python.js +15 -0
  80. package/dist/graph/languages/rules.d.ts +18 -0
  81. package/dist/graph/languages/rules.js +1 -0
  82. package/dist/graph/languages/rust.d.ts +2 -0
  83. package/dist/graph/languages/rust.js +16 -0
  84. package/dist/graph/parser.d.ts +31 -0
  85. package/dist/graph/parser.js +29 -0
  86. package/dist/graph/query/format.d.ts +2 -0
  87. package/dist/graph/query/format.js +41 -0
  88. package/dist/graph/query/index.d.ts +5 -0
  89. package/dist/graph/query/index.js +4 -0
  90. package/dist/graph/query/lookup.d.ts +21 -0
  91. package/dist/graph/query/lookup.js +35 -0
  92. package/dist/graph/query/path.d.ts +2 -0
  93. package/dist/graph/query/path.js +48 -0
  94. package/dist/graph/query/refresh.d.ts +2 -0
  95. package/dist/graph/query/refresh.js +21 -0
  96. package/dist/graph/scan/extract.d.ts +15 -0
  97. package/dist/graph/scan/extract.js +101 -0
  98. package/dist/graph/scan/files.d.ts +12 -0
  99. package/dist/graph/scan/files.js +51 -0
  100. package/dist/graph/scan/index.d.ts +18 -0
  101. package/dist/graph/scan/index.js +44 -0
  102. package/dist/graph/scan/resolve.d.ts +3 -0
  103. package/dist/graph/scan/resolve.js +48 -0
  104. package/dist/hooks/payload.d.ts +0 -8
  105. package/dist/hooks/payload.js +0 -6
  106. package/dist/hooks/relevance.d.ts +0 -17
  107. package/dist/hooks/relevance.js +55 -38
  108. package/dist/hooks/session-end.js +0 -11
  109. package/dist/hooks/session-start.js +33 -14
  110. package/dist/hooks/user-prompt.js +0 -18
  111. package/dist/mcp/render.d.ts +0 -20
  112. package/dist/mcp/render.js +0 -39
  113. package/dist/mcp/server.js +46 -25
  114. package/dist/search/rank.d.ts +0 -14
  115. package/dist/search/rank.js +0 -16
  116. package/dist/search/service.d.ts +1 -32
  117. package/dist/search/service.js +1 -36
  118. package/dist/store/adapter.d.ts +11 -44
  119. package/dist/store/adapter.js +1 -12
  120. package/dist/store/index.d.ts +0 -11
  121. package/dist/store/index.js +0 -11
  122. package/dist/store/mongo/docs.d.ts +61 -0
  123. package/dist/store/mongo/docs.js +106 -0
  124. package/dist/store/mongo/driver.d.ts +1 -15
  125. package/dist/store/mongo/driver.js +0 -15
  126. package/dist/store/mongo/filters.d.ts +6 -0
  127. package/dist/store/mongo/filters.js +18 -0
  128. package/dist/store/mongo/graph.d.ts +12 -0
  129. package/dist/store/mongo/graph.js +61 -0
  130. package/dist/store/mongo/helpers.d.ts +2 -0
  131. package/dist/store/mongo/helpers.js +8 -0
  132. package/dist/store/mongo/index.d.ts +16 -13
  133. package/dist/store/mongo/index.js +52 -295
  134. package/dist/store/mongo/observations.d.ts +10 -0
  135. package/dist/store/mongo/observations.js +97 -0
  136. package/dist/store/mongo/search.d.ts +6 -0
  137. package/dist/store/mongo/search.js +51 -0
  138. package/dist/store/mongo/sessions.d.ts +6 -0
  139. package/dist/store/mongo/sessions.js +24 -0
  140. package/dist/store/mongo/vectorSearch.d.ts +5 -0
  141. package/dist/store/mongo/vectorSearch.js +57 -0
  142. package/dist/store/postgres/driver.d.ts +19 -0
  143. package/dist/store/postgres/driver.js +13 -0
  144. package/dist/store/postgres/filters.d.ts +2 -0
  145. package/dist/store/postgres/filters.js +22 -0
  146. package/dist/store/postgres/graph.d.ts +11 -0
  147. package/dist/store/postgres/graph.js +115 -0
  148. package/dist/store/postgres/index.d.ts +20 -33
  149. package/dist/store/postgres/index.js +43 -428
  150. package/dist/store/postgres/insert.d.ts +3 -0
  151. package/dist/store/postgres/insert.js +59 -0
  152. package/dist/store/postgres/meta.d.ts +10 -0
  153. package/dist/store/postgres/meta.js +54 -0
  154. package/dist/store/postgres/observations.d.ts +10 -0
  155. package/dist/store/postgres/observations.js +139 -0
  156. package/dist/store/postgres/rows.d.ts +6 -0
  157. package/dist/store/postgres/rows.js +74 -0
  158. package/dist/store/postgres/schema.d.ts +3 -0
  159. package/dist/store/postgres/schema.js +84 -0
  160. package/dist/store/postgres/search.d.ts +3 -0
  161. package/dist/store/postgres/search.js +20 -0
  162. package/dist/store/postgres/sessions.d.ts +5 -0
  163. package/dist/store/postgres/sessions.js +26 -0
  164. package/dist/store/postgres/vectorSearch.d.ts +3 -0
  165. package/dist/store/postgres/vectorSearch.js +21 -0
  166. package/dist/store/sqlite/filters.d.ts +9 -0
  167. package/dist/store/sqlite/filters.js +77 -0
  168. package/dist/store/sqlite/graph.d.ts +11 -0
  169. package/dist/store/sqlite/graph.js +100 -0
  170. package/dist/store/sqlite/index.d.ts +12 -10
  171. package/dist/store/sqlite/index.js +41 -379
  172. package/dist/store/sqlite/observations.d.ts +10 -0
  173. package/dist/store/sqlite/observations.js +128 -0
  174. package/dist/store/sqlite/rows.d.ts +8 -0
  175. package/dist/store/sqlite/rows.js +84 -0
  176. package/dist/store/sqlite/schema.sql +42 -2
  177. package/dist/store/sqlite/search.d.ts +5 -0
  178. package/dist/store/sqlite/search.js +86 -0
  179. package/dist/store/sqlite/sessions.d.ts +5 -0
  180. package/dist/store/sqlite/sessions.js +21 -0
  181. package/dist/types.d.ts +47 -40
  182. package/dist/types.js +0 -4
  183. package/dist/update.d.ts +0 -20
  184. package/dist/update.js +4 -29
  185. package/dist/usages/find.d.ts +2 -8
  186. package/dist/usages/find.js +51 -54
  187. package/dist/usages/index.d.ts +1 -1
  188. package/dist/usages/index.js +1 -1
  189. package/dist/util/project.d.ts +0 -12
  190. package/dist/util/project.js +0 -24
  191. package/dist/util/scope.d.ts +0 -9
  192. package/dist/util/scope.js +0 -9
  193. package/dist/util/shortid.d.ts +0 -5
  194. package/dist/util/shortid.js +1 -19
  195. package/dist/util/snippet.d.ts +0 -26
  196. package/dist/util/snippet.js +0 -30
  197. package/dist/util/vector.d.ts +0 -12
  198. package/dist/util/vector.js +0 -12
  199. package/dist/util/warnings.d.ts +0 -11
  200. package/dist/util/warnings.js +0 -11
  201. package/docs/how-it-works.md +183 -0
  202. package/package.json +14 -3
  203. package/skills/cdb-scan/SKILL.md +31 -6
@@ -0,0 +1,84 @@
1
+ import { toSnippet } from '../../util/snippet.js';
2
+ import { unpackVector } from '../../util/vector.js';
3
+ export function toBuffer(value) {
4
+ if (Buffer.isBuffer(value))
5
+ return value;
6
+ if (value instanceof Uint8Array)
7
+ return Buffer.from(value);
8
+ return Buffer.alloc(0);
9
+ }
10
+ export function toSession(row) {
11
+ const session = {
12
+ id: row['id'],
13
+ project: row['project'],
14
+ startedAt: Number(row['started_at']),
15
+ };
16
+ if (row['ended_at'] != null)
17
+ session.endedAt = Number(row['ended_at']);
18
+ if (row['summary'] != null)
19
+ session.summary = row['summary'];
20
+ return session;
21
+ }
22
+ export function toObservation(row) {
23
+ const obs = {
24
+ id: row['id'],
25
+ sessionId: row['session_id'],
26
+ project: row['project'],
27
+ kind: row['kind'],
28
+ title: row['title'],
29
+ body: row['body'],
30
+ files: JSON.parse(row['files'] ?? '[]'),
31
+ tags: JSON.parse(row['tags'] ?? '[]'),
32
+ createdAt: Number(row['created_at']),
33
+ };
34
+ if (row['embedding'])
35
+ obs.embedding = unpackVector(toBuffer(row['embedding']));
36
+ if (row['embedder'] != null)
37
+ obs.embedder = row['embedder'];
38
+ if (row['author'] != null)
39
+ obs.author = row['author'];
40
+ if (row['status'] != null)
41
+ obs.status = row['status'];
42
+ return obs;
43
+ }
44
+ export function toIndexEntry(row) {
45
+ const entry = {
46
+ id: row['id'],
47
+ kind: row['kind'],
48
+ title: row['title'],
49
+ project: row['project'],
50
+ createdAt: Number(row['created_at']),
51
+ score: Number(row['score'] ?? 0),
52
+ };
53
+ const snippet = toSnippet(row['snippet']);
54
+ if (snippet)
55
+ entry.snippet = snippet;
56
+ return entry;
57
+ }
58
+ export function toSymbol(row) {
59
+ return {
60
+ id: row['id'],
61
+ project: row['project'],
62
+ name: row['name'],
63
+ kind: row['kind'],
64
+ file: row['file'],
65
+ line: Number(row['line']),
66
+ lang: row['lang'],
67
+ signature: row['signature'] ?? '',
68
+ };
69
+ }
70
+ export function toEdge(row) {
71
+ return {
72
+ id: row['id'],
73
+ project: row['project'],
74
+ srcId: row['src_id'],
75
+ srcName: row['src_name'],
76
+ dstId: row['dst_id'] ?? '',
77
+ dstName: row['dst_name'],
78
+ relation: row['relation'],
79
+ confidence: row['confidence'],
80
+ score: Number(row['score'] ?? 1),
81
+ file: row['file'],
82
+ line: Number(row['line']),
83
+ };
84
+ }
@@ -26,14 +26,14 @@ CREATE TABLE IF NOT EXISTS observations (
26
26
  created_at INTEGER NOT NULL,
27
27
  embedding BLOB,
28
28
  embedder TEXT,
29
- author TEXT
29
+ author TEXT,
30
+ status TEXT NOT NULL DEFAULT 'done'
30
31
  );
31
32
 
32
33
  CREATE INDEX IF NOT EXISTS idx_obs_project_time
33
34
  ON observations(project, created_at DESC);
34
35
  CREATE INDEX IF NOT EXISTS idx_obs_kind
35
36
  ON observations(project, kind, created_at DESC);
36
- -- Covers the vector candidate scan, which reads only these columns.
37
37
  CREATE INDEX IF NOT EXISTS idx_obs_vector_scan
38
38
  ON observations(project, kind) WHERE embedding IS NOT NULL;
39
39
 
@@ -60,3 +60,43 @@ CREATE TRIGGER IF NOT EXISTS observations_au AFTER UPDATE ON observations BEGIN
60
60
  INSERT INTO observations_fts(rowid, title, body, tags, scope)
61
61
  VALUES (new.rowid, new.title, new.body, new.tags, new.scope);
62
62
  END;
63
+
64
+ CREATE TABLE IF NOT EXISTS symbols (
65
+ id TEXT PRIMARY KEY,
66
+ project TEXT NOT NULL,
67
+ name TEXT NOT NULL,
68
+ kind TEXT NOT NULL,
69
+ file TEXT NOT NULL,
70
+ line INTEGER NOT NULL,
71
+ lang TEXT NOT NULL,
72
+ signature TEXT NOT NULL DEFAULT ''
73
+ );
74
+
75
+ CREATE INDEX IF NOT EXISTS idx_symbols_lookup ON symbols(project, name);
76
+ CREATE INDEX IF NOT EXISTS idx_symbols_file ON symbols(project, file);
77
+
78
+ CREATE TABLE IF NOT EXISTS symbol_edges (
79
+ id TEXT PRIMARY KEY,
80
+ project TEXT NOT NULL,
81
+ src_id TEXT NOT NULL,
82
+ src_name TEXT NOT NULL,
83
+ dst_id TEXT NOT NULL DEFAULT '',
84
+ dst_name TEXT NOT NULL,
85
+ relation TEXT NOT NULL,
86
+ confidence TEXT NOT NULL,
87
+ score REAL NOT NULL DEFAULT 1.0,
88
+ file TEXT NOT NULL,
89
+ line INTEGER NOT NULL
90
+ );
91
+
92
+ CREATE INDEX IF NOT EXISTS idx_edges_src ON symbol_edges(project, src_id);
93
+ CREATE INDEX IF NOT EXISTS idx_edges_dst ON symbol_edges(project, dst_id);
94
+ CREATE INDEX IF NOT EXISTS idx_edges_file ON symbol_edges(project, file);
95
+
96
+ CREATE TABLE IF NOT EXISTS scanned_files (
97
+ project TEXT NOT NULL,
98
+ path TEXT NOT NULL,
99
+ hash TEXT NOT NULL,
100
+ scanned_at INTEGER NOT NULL,
101
+ PRIMARY KEY (project, path)
102
+ );
@@ -0,0 +1,5 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ import type { ObservationIndexEntry, SearchQuery, TimelineQuery } from '../../types.js';
3
+ export declare function searchKeyword(db: DatabaseSync, query: SearchQuery): Promise<ObservationIndexEntry[]>;
4
+ export declare function searchVector(db: DatabaseSync, vector: number[], query: SearchQuery): Promise<ObservationIndexEntry[]>;
5
+ export declare function timeline(db: DatabaseSync, query: TimelineQuery): Promise<ObservationIndexEntry[]>;
@@ -0,0 +1,86 @@
1
+ import { toBuffer, toIndexEntry } from './rows.js';
2
+ import { TAG_PREDICATE, appendScope, toMatchExpression } from './filters.js';
3
+ import { cosine, unpackVector } from '../../util/vector.js';
4
+ export async function searchKeyword(db, query) {
5
+ const match = toMatchExpression(query.text, query.project);
6
+ if (match === null)
7
+ return [];
8
+ const conditions = ['observations_fts MATCH ?'];
9
+ const params = [match];
10
+ if (query.kind) {
11
+ conditions.push('o.kind = ?');
12
+ params.push(query.kind);
13
+ }
14
+ if (query.tag) {
15
+ conditions.push(TAG_PREDICATE('o.'));
16
+ params.push(query.tag);
17
+ }
18
+ if (query.since !== undefined) {
19
+ conditions.push('o.created_at >= ?');
20
+ params.push(query.since);
21
+ }
22
+ if (query.until !== undefined) {
23
+ conditions.push('o.created_at <= ?');
24
+ params.push(query.until);
25
+ }
26
+ params.push(query.limit);
27
+ const rows = db
28
+ .prepare(`SELECT o.id, o.kind, o.title, o.project, o.created_at,
29
+ snippet(observations_fts, 1, '', '', '…', 14) AS snippet,
30
+ -bm25(observations_fts, 10.0, 1.0, 5.0, 0.0) AS score
31
+ FROM observations_fts
32
+ JOIN observations o ON o.rowid = observations_fts.rowid
33
+ WHERE ${conditions.join(' AND ')}
34
+ ORDER BY score DESC
35
+ LIMIT ?`)
36
+ .all(...params);
37
+ return rows.map(toIndexEntry);
38
+ }
39
+ export async function searchVector(db, vector, query) {
40
+ const conditions = ['embedding IS NOT NULL'];
41
+ const params = [];
42
+ appendScope(query, conditions, params, '');
43
+ if (query.embedder) {
44
+ conditions.push('(embedder = ? OR embedder IS NULL)');
45
+ params.push(query.embedder);
46
+ }
47
+ params.push(query.maxScanCandidates ?? 25000);
48
+ const rows = db
49
+ .prepare(`SELECT id, kind, title, project, created_at, embedding
50
+ FROM observations WHERE ${conditions.join(' AND ')}
51
+ ORDER BY created_at DESC LIMIT ?`)
52
+ .all(...params);
53
+ return rows
54
+ .map((row) => ({
55
+ id: row['id'],
56
+ kind: row['kind'],
57
+ title: row['title'],
58
+ project: row['project'],
59
+ createdAt: Number(row['created_at']),
60
+ score: row['embedding'] ? cosine(vector, unpackVector(toBuffer(row['embedding']))) : 0,
61
+ }))
62
+ .sort((a, b) => b.score - a.score)
63
+ .slice(0, query.limit);
64
+ }
65
+ export async function timeline(db, query) {
66
+ const anchor = db
67
+ .prepare('SELECT project, created_at FROM observations WHERE id = ?')
68
+ .get(query.observationId);
69
+ if (!anchor)
70
+ return [];
71
+ const rows = db
72
+ .prepare(`SELECT id, kind, title, project, created_at, 0 AS score FROM (
73
+ SELECT * FROM observations
74
+ WHERE project = ? AND created_at <= ?
75
+ ORDER BY created_at DESC LIMIT ?
76
+ )
77
+ UNION
78
+ SELECT id, kind, title, project, created_at, 0 AS score FROM (
79
+ SELECT * FROM observations
80
+ WHERE project = ? AND created_at > ?
81
+ ORDER BY created_at ASC LIMIT ?
82
+ )
83
+ ORDER BY created_at ASC`)
84
+ .all(anchor['project'], anchor['created_at'], query.before + 1, anchor['project'], anchor['created_at'], query.after);
85
+ return rows.map(toIndexEntry);
86
+ }
@@ -0,0 +1,5 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ import type { Session } from '../../types.js';
3
+ export declare function upsertSession(db: DatabaseSync, session: Session): Promise<void>;
4
+ export declare function getSession(db: DatabaseSync, id: string): Promise<Session | null>;
5
+ export declare function recentSessions(db: DatabaseSync, project: string, limit: number): Promise<Session[]>;
@@ -0,0 +1,21 @@
1
+ import { toSession } from './rows.js';
2
+ export async function upsertSession(db, session) {
3
+ db.prepare(`INSERT INTO sessions (id, project, started_at, ended_at, summary)
4
+ VALUES (?, ?, ?, ?, ?)
5
+ ON CONFLICT(id) DO UPDATE SET
6
+ project = excluded.project,
7
+ ended_at = COALESCE(excluded.ended_at, sessions.ended_at),
8
+ summary = COALESCE(excluded.summary, sessions.summary)`).run(session.id, session.project, session.startedAt, session.endedAt ?? null, session.summary ?? null);
9
+ }
10
+ export async function getSession(db, id) {
11
+ const row = db.prepare('SELECT * FROM sessions WHERE id = ?').get(id);
12
+ return row ? toSession(row) : null;
13
+ }
14
+ export async function recentSessions(db, project, limit) {
15
+ const rows = db
16
+ .prepare(`SELECT * FROM sessions
17
+ WHERE project = ? AND summary IS NOT NULL
18
+ ORDER BY started_at DESC LIMIT ?`)
19
+ .all(project, limit);
20
+ return rows.map(toSession);
21
+ }
package/dist/types.d.ts CHANGED
@@ -1,38 +1,27 @@
1
- /**
2
- * Core domain types. Storage-agnostic on purpose: every adapter maps these
3
- * to its own representation, and nothing outside src/store knows the difference.
4
- */
5
1
  export type ObservationKind = 'decision' | 'pattern' | 'bugfix' | 'context' | 'deadend' | 'preference';
6
2
  export interface Session {
7
- /** Stable id supplied by the agent host (Claude Code session id). */
8
3
  id: string;
9
- /** Absolute path of the project root this session ran in. */
10
4
  project: string;
11
5
  startedAt: number;
12
6
  endedAt?: number;
13
- /** One-paragraph recap written at session end. */
14
7
  summary?: string;
15
8
  }
9
+ export type ObservationStatus = 'open' | 'done';
16
10
  export interface Observation {
17
11
  id: string;
18
12
  sessionId: string;
19
13
  project: string;
20
14
  kind: ObservationKind;
21
- /** Single-sentence claim. This is what gets ranked and shown in the index. */
22
15
  title: string;
23
- /** Full reasoning, code excerpts, file paths. Fetched only on demand. */
24
16
  body: string;
25
17
  files: string[];
26
18
  tags: string[];
27
19
  createdAt: number;
28
- /** Present only when an embedder is configured. */
29
20
  embedding?: number[];
30
- /** Which embedder produced `embedding`. Absent on rows written before 0.2. */
31
21
  embedder?: string;
32
- /** Whose machine recorded this. Only interesting on a shared database. */
33
22
  author?: string;
23
+ status?: ObservationStatus;
34
24
  }
35
- /** Compact projection returned by search. Deliberately excludes `body`. */
36
25
  export interface ObservationIndexEntry {
37
26
  id: string;
38
27
  kind: ObservationKind;
@@ -40,60 +29,78 @@ export interface ObservationIndexEntry {
40
29
  project: string;
41
30
  createdAt: number;
42
31
  score: number;
43
- /**
44
- * A line of the body around the match, so a result can be chosen without
45
- * being expanded first. Produced by the keyword retriever, which is the only
46
- * one with query terms to centre on; a row found by vector similarity alone
47
- * has none.
48
- */
49
32
  snippet?: string;
50
33
  }
51
34
  export interface SearchQuery {
52
35
  text: string;
53
36
  project?: string;
54
37
  kind?: ObservationKind;
55
- /**
56
- * Narrows to observations touching one repository or top-level directory.
57
- *
58
- * A workspace that pools several repositories under one project key gets a
59
- * memory covering all of them, and "the backend only" is a natural thing to
60
- * ask that could not be expressed: tags were recorded and ranked, but never
61
- * filtered on.
62
- */
63
38
  tag?: string;
64
39
  since?: number;
65
40
  until?: number;
66
41
  limit: number;
67
- /** Ceiling for brute-force vector scans. Ignored by indexed backends. */
68
42
  maxScanCandidates?: number;
69
- /**
70
- * Restricts vector search to rows embedded by this model, plus rows that
71
- * predate the column. Vectors from different models are not comparable.
72
- */
73
43
  embedder?: string;
74
44
  }
75
- /**
76
- * What to delete. Every field narrows, and an empty filter means everything,
77
- * which is what `reset` asks for. An explicitly empty `ids` array deletes
78
- * nothing: `forget` with no resolvable id must not wipe the database.
79
- */
80
45
  export interface RemoveFilter {
81
46
  ids?: string[];
82
47
  project?: string;
83
48
  kind?: ObservationKind;
84
- /** Deletes observations recorded strictly before this timestamp. */
85
49
  before?: number;
86
50
  }
87
- /** Bulk read, ordered oldest first so `after` can page through a large table. */
88
51
  export interface ListFilter {
89
52
  project?: string;
90
53
  kind?: ObservationKind;
54
+ status?: ObservationStatus;
91
55
  after?: number;
92
56
  limit?: number;
93
57
  }
94
58
  export interface TimelineQuery {
95
- /** Anchor observation. Results are the ones surrounding it in time. */
96
59
  observationId: string;
97
60
  before: number;
98
61
  after: number;
99
62
  }
63
+ export type SymbolKind = 'function' | 'class' | 'interface' | 'type' | 'enum' | 'const' | 'method';
64
+ export type EdgeRelation = 'calls' | 'imports' | 'extends' | 'implements' | 'references' | 'defines';
65
+ export type EdgeConfidence = 'EXTRACTED' | 'INFERRED';
66
+ export interface CodeSymbol {
67
+ id: string;
68
+ project: string;
69
+ name: string;
70
+ kind: SymbolKind;
71
+ file: string;
72
+ line: number;
73
+ lang: string;
74
+ signature: string;
75
+ }
76
+ export interface CodeEdge {
77
+ id: string;
78
+ project: string;
79
+ srcId: string;
80
+ srcName: string;
81
+ dstId: string;
82
+ dstName: string;
83
+ relation: EdgeRelation;
84
+ confidence: EdgeConfidence;
85
+ score: number;
86
+ file: string;
87
+ line: number;
88
+ }
89
+ export interface SymbolFilter {
90
+ project: string;
91
+ name?: string;
92
+ file?: string;
93
+ limit?: number;
94
+ }
95
+ export interface EdgeFilter {
96
+ project: string;
97
+ srcIds?: string[];
98
+ dstIds?: string[];
99
+ limit?: number;
100
+ }
101
+ export interface ScannedFile {
102
+ project: string;
103
+ path: string;
104
+ hash: string;
105
+ scannedAt: number;
106
+ }
package/dist/types.js CHANGED
@@ -1,5 +1 @@
1
- /**
2
- * Core domain types. Storage-agnostic on purpose: every adapter maps these
3
- * to its own representation, and nothing outside src/store knows the difference.
4
- */
5
1
  export {};
package/dist/update.d.ts CHANGED
@@ -1,24 +1,12 @@
1
1
  export interface UpdateState {
2
- /** When the registry was last asked. */
3
2
  checkedAt?: number;
4
- /** Newest version the registry reported. */
5
3
  latest?: string;
6
- /** Version we installed ourselves, so the next session can mention it. */
7
4
  installed?: string;
8
5
  }
9
6
  export declare function packageVersion(): string;
10
7
  export declare function readState(): UpdateState;
11
8
  export declare function isDue(state: UpdateState, now?: number): boolean;
12
- /** -1, 0 or 1. Numeric per segment, so 0.2.10 beats 0.2.9. */
13
9
  export declare function compareVersions(a: string, b: string): number;
14
- /**
15
- * Caret semantics: 1.x may take any 1.y.z, but 0.2.x may only take 0.2.z.
16
- *
17
- * A release outside this range is allowed to change the database schema or the
18
- * config, and `init()` migrates on first connection — so installing one without
19
- * being asked would rewrite a user's database on their behalf. Those are
20
- * reported and left for a human.
21
- */
22
10
  export declare function isCompatible(current: string, candidate: string): boolean;
23
11
  export interface UpdateResult {
24
12
  current: string;
@@ -26,13 +14,5 @@ export interface UpdateResult {
26
14
  installed: boolean;
27
15
  reason?: string;
28
16
  }
29
- /**
30
- * Asks the registry, and installs when configured to.
31
- *
32
- * Only ever called from a detached process, never inline: the check is network
33
- * bound and `npm install -g` replaces the very files the hooks import, so
34
- * neither belongs anywhere near the prompt path.
35
- */
36
17
  export declare function checkForUpdate(mode: 'auto' | 'notify' | 'off'): Promise<UpdateResult>;
37
- /** One line for the session banner, or null when there is nothing to say. */
38
18
  export declare function updateNotice(): string | null;
package/dist/update.js CHANGED
@@ -28,14 +28,11 @@ function writeState(state) {
28
28
  mkdirSync(CONFIG_DIR, { recursive: true });
29
29
  writeFileSync(STATE_PATH, `${JSON.stringify(state, null, 2)}\n`, 'utf8');
30
30
  }
31
- catch {
32
- // A lost state file only costs one redundant check.
33
- }
31
+ catch { }
34
32
  }
35
33
  export function isDue(state, now = Date.now()) {
36
34
  return now - (state.checkedAt ?? 0) > CHECK_INTERVAL_MS;
37
35
  }
38
- /** -1, 0 or 1. Numeric per segment, so 0.2.10 beats 0.2.9. */
39
36
  export function compareVersions(a, b) {
40
37
  const left = a.split('.').map((part) => Number.parseInt(part, 10) || 0);
41
38
  const right = b.split('.').map((part) => Number.parseInt(part, 10) || 0);
@@ -46,24 +43,11 @@ export function compareVersions(a, b) {
46
43
  }
47
44
  return 0;
48
45
  }
49
- /**
50
- * Caret semantics: 1.x may take any 1.y.z, but 0.2.x may only take 0.2.z.
51
- *
52
- * A release outside this range is allowed to change the database schema or the
53
- * config, and `init()` migrates on first connection — so installing one without
54
- * being asked would rewrite a user's database on their behalf. Those are
55
- * reported and left for a human.
56
- */
57
46
  export function isCompatible(current, candidate) {
58
47
  const [curMajor = 0, curMinor = 0] = current.split('.').map(Number);
59
48
  const [newMajor = 0, newMinor = 0] = candidate.split('.').map(Number);
60
49
  return curMajor === 0 ? curMajor === newMajor && curMinor === newMinor : curMajor === newMajor;
61
50
  }
62
- /**
63
- * No abbreviated-packument accept header here: that format applies to the full
64
- * document, and asking for it on /latest returns 406. With the header this
65
- * check never once succeeded, and reported "up to date" while failing.
66
- */
67
51
  async function fetchLatest() {
68
52
  try {
69
53
  const res = await fetch(REGISTRY, { signal: AbortSignal.timeout(5000) });
@@ -76,13 +60,6 @@ async function fetchLatest() {
76
60
  return null;
77
61
  }
78
62
  }
79
- /**
80
- * Asks the registry, and installs when configured to.
81
- *
82
- * Only ever called from a detached process, never inline: the check is network
83
- * bound and `npm install -g` replaces the very files the hooks import, so
84
- * neither belongs anywhere near the prompt path.
85
- */
86
63
  export async function checkForUpdate(mode) {
87
64
  const current = packageVersion();
88
65
  if (mode === 'off')
@@ -91,8 +68,6 @@ export async function checkForUpdate(mode) {
91
68
  const state = { ...readState(), checkedAt: Date.now() };
92
69
  if (latest)
93
70
  state.latest = latest;
94
- // A failed check is not the same as being current, and saying so is what
95
- // stops a broken updater from looking like a healthy one forever.
96
71
  if (!latest) {
97
72
  writeState(state);
98
73
  return { current, latest: null, installed: false, reason: 'could not reach the registry' };
@@ -123,16 +98,16 @@ export async function checkForUpdate(mode) {
123
98
  current,
124
99
  latest,
125
100
  installed: false,
126
- reason: error instanceof Error ? error.message.split('\n')[0] ?? 'install failed' : 'install failed',
101
+ reason: error instanceof Error
102
+ ? (error.message.split('\n')[0] ?? 'install failed')
103
+ : 'install failed',
127
104
  };
128
105
  }
129
106
  }
130
- /** One line for the session banner, or null when there is nothing to say. */
131
107
  export function updateNotice() {
132
108
  const state = readState();
133
109
  const current = packageVersion();
134
110
  if (state.installed && compareVersions(state.installed, current) <= 0) {
135
- // We are running it now, so say so once and forget it.
136
111
  const { installed: _done, ...rest } = state;
137
112
  writeState(rest);
138
113
  return `claude-db updated to ${current}.`;
@@ -3,6 +3,7 @@ export interface UsageMatch {
3
3
  line: number;
4
4
  text: string;
5
5
  isDefinition: boolean;
6
+ isMatch: boolean;
6
7
  }
7
8
  export interface UsagesResult {
8
9
  root: string;
@@ -17,13 +18,6 @@ export interface FindUsagesInput {
17
18
  context: number;
18
19
  limit: number;
19
20
  }
20
- /**
21
- * Live `git grep`, never a persisted index.
22
- *
23
- * A symbol index that drifts from an edit is the same failure shape as every
24
- * silent-staleness bug this project has already shipped and fixed. This
25
- * re-derives the answer from the current source on every call, so there is
26
- * nothing to invalidate.
27
- */
28
21
  export declare function findUsages(input: FindUsagesInput): UsagesResult;
22
+ export declare function repoRootFor(start: string): string;
29
23
  export declare function formatUsages(result: UsagesResult): string;