claude-db 0.12.1 → 0.12.3

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 (70) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/capture/active.d.ts +12 -0
  3. package/dist/capture/active.js +74 -0
  4. package/dist/capture/flush.d.ts +1 -1
  5. package/dist/capture/flush.js +22 -3
  6. package/dist/capture/git.d.ts +1 -0
  7. package/dist/capture/git.js +3 -2
  8. package/dist/capture/index.d.ts +1 -0
  9. package/dist/capture/index.js +1 -0
  10. package/dist/capture/transcript.d.ts +1 -0
  11. package/dist/capture/transcript.js +3 -2
  12. package/dist/capture/turn-extractor.d.ts +3 -0
  13. package/dist/capture/turn-extractor.js +12 -2
  14. package/dist/capture/vectors.d.ts +7 -0
  15. package/dist/capture/vectors.js +38 -0
  16. package/dist/catchup/gather.d.ts +9 -4
  17. package/dist/catchup/gather.js +22 -15
  18. package/dist/catchup/render.js +17 -8
  19. package/dist/cli/commands/adoption.js +41 -29
  20. package/dist/cli/commands/catchup.js +2 -1
  21. package/dist/cli/commands/languages.js +10 -6
  22. package/dist/cli/commands/transfer.js +24 -5
  23. package/dist/cli/install.js +1 -0
  24. package/dist/facts/claude-memory.js +1 -1
  25. package/dist/facts/handoff.d.ts +2 -0
  26. package/dist/facts/handoff.js +7 -0
  27. package/dist/facts/health.js +2 -1
  28. package/dist/facts/last-chat.d.ts +13 -0
  29. package/dist/facts/last-chat.js +45 -0
  30. package/dist/facts/start.d.ts +2 -1
  31. package/dist/facts/start.js +44 -5
  32. package/dist/graph/query/lookup.d.ts +1 -0
  33. package/dist/graph/query/lookup.js +2 -1
  34. package/dist/hooks/background.js +5 -1
  35. package/dist/hooks/detached.d.ts +2 -0
  36. package/dist/hooks/detached.js +38 -2
  37. package/dist/hooks/payload.d.ts +5 -0
  38. package/dist/hooks/prefer-usages.js +1 -1
  39. package/dist/hooks/relevance.js +1 -5
  40. package/dist/hooks/session-end.js +6 -0
  41. package/dist/hooks/session-start.js +9 -6
  42. package/dist/hooks/turn-end.d.ts +2 -0
  43. package/dist/hooks/turn-end.js +26 -0
  44. package/dist/hooks/turn-job.d.ts +10 -0
  45. package/dist/hooks/turn-job.js +30 -0
  46. package/dist/hooks/turn-save.d.ts +2 -0
  47. package/dist/hooks/turn-save.js +25 -0
  48. package/dist/hooks/user-prompt.js +2 -0
  49. package/dist/pick/pending.js +7 -37
  50. package/dist/store/adapter.d.ts +1 -0
  51. package/dist/store/mongo/filters.d.ts +1 -0
  52. package/dist/store/mongo/filters.js +9 -3
  53. package/dist/store/mongo/observations.js +2 -3
  54. package/dist/store/postgres/filters.d.ts +1 -0
  55. package/dist/store/postgres/filters.js +9 -4
  56. package/dist/store/postgres/index.d.ts +1 -0
  57. package/dist/store/postgres/index.js +3 -0
  58. package/dist/store/postgres/observations.js +4 -1
  59. package/dist/store/sqlite/filters.d.ts +1 -0
  60. package/dist/store/sqlite/filters.js +9 -4
  61. package/dist/store/sqlite/observations.js +4 -1
  62. package/dist/store/sqlite/search.js +4 -5
  63. package/dist/types.d.ts +1 -0
  64. package/dist/util/day.d.ts +1 -0
  65. package/dist/util/day.js +4 -0
  66. package/dist/util/json-file.d.ts +4 -0
  67. package/dist/util/json-file.js +37 -0
  68. package/docs/how-it-works.md +6 -1
  69. package/package.json +6 -6
  70. package/skills/catchup/SKILL.md +6 -2
@@ -1,32 +1,16 @@
1
1
  import { randomUUID } from 'node:crypto';
2
- import { mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, } from 'node:fs';
2
+ import { renameSync, rmSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  import { CONFIG_DIR } from '../config/dir.js';
5
+ import { readJson, safeName, sweepOlderThan, writeJsonAtomic } from '../util/json-file.js';
5
6
  const STALE_MS = 10 * 60 * 1000;
6
7
  const ORPHAN_MS = 24 * 60 * 60 * 1000;
7
8
  const TOKEN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
8
9
  function folder() {
9
10
  return join(CONFIG_DIR, 'pick', 'pending');
10
11
  }
11
- function safe(sessionId) {
12
- return sessionId.replace(/[^\w-]/g, '_');
13
- }
14
12
  function path(sessionId, suffix) {
15
- return join(folder(), `${safe(sessionId)}${suffix}`);
16
- }
17
- function readJson(file) {
18
- try {
19
- return JSON.parse(readFileSync(file, 'utf8'));
20
- }
21
- catch {
22
- return null;
23
- }
24
- }
25
- function writeAtomic(file, value) {
26
- mkdirSync(folder(), { recursive: true });
27
- const temp = `${file}.${randomUUID()}.tmp`;
28
- writeFileSync(temp, JSON.stringify(value), 'utf8');
29
- renameSync(temp, file);
13
+ return join(folder(), `${safeName(sessionId)}${suffix}`);
30
14
  }
31
15
  function isToken(value) {
32
16
  return typeof value === 'string' && TOKEN.test(value);
@@ -40,27 +24,13 @@ export function clearPick(sessionId) {
40
24
  rmSync(path(sessionId, '.json'), { force: true });
41
25
  }
42
26
  export function sweepPicks(now = Date.now()) {
43
- let names;
44
- try {
45
- names = readdirSync(folder());
46
- }
47
- catch {
48
- return;
49
- }
50
- for (const name of names) {
51
- const file = join(folder(), name);
52
- try {
53
- if (now - statSync(file).mtimeMs > ORPHAN_MS)
54
- rmSync(file, { force: true });
55
- }
56
- catch { }
57
- }
27
+ sweepOlderThan(folder(), ORPHAN_MS, now);
58
28
  }
59
29
  export function startPick(sessionId, job, now = Date.now()) {
60
30
  clearPick(sessionId);
61
31
  const token = randomUUID();
62
- writeAtomic(path(sessionId, `.${token}.job.json`), job);
63
- writeAtomic(path(sessionId, '.json'), { token, startedAt: now });
32
+ writeJsonAtomic(path(sessionId, `.${token}.job.json`), job);
33
+ writeJsonAtomic(path(sessionId, '.json'), { token, startedAt: now });
64
34
  return token;
65
35
  }
66
36
  export function takeJob(sessionId, token) {
@@ -85,7 +55,7 @@ function current(sessionId, now) {
85
55
  export function finishPick(sessionId, token, ready, now = Date.now()) {
86
56
  if (current(sessionId, now)?.token !== token)
87
57
  return false;
88
- writeAtomic(path(sessionId, `.${token}.ready.json`), ready);
58
+ writeJsonAtomic(path(sessionId, `.${token}.ready.json`), ready);
89
59
  return true;
90
60
  }
91
61
  export function takeReady(sessionId, now = Date.now()) {
@@ -19,6 +19,7 @@ export interface MemoryStore {
19
19
  insertObservations(observations: Observation[]): Promise<void>;
20
20
  getObservations(ids: string[]): Promise<Observation[]>;
21
21
  migrateVectorDims?(dims: number): Promise<boolean>;
22
+ storedVectorDims?(): number | null;
22
23
  remove(filter: RemoveFilter): Promise<number>;
23
24
  list(filter: ListFilter): Promise<Observation[]>;
24
25
  listProjects(): Promise<ProjectSummary[]>;
@@ -5,4 +5,5 @@ export interface VectorCache {
5
5
  atlasVectorIndex: boolean | null;
6
6
  }
7
7
  export declare function scopeFilter(query: SearchQuery): Doc;
8
+ export declare function sessionMatch(only: string | undefined, exclude: string[] | undefined): Doc;
8
9
  export declare function visibleFilter(query: SearchQuery): Doc;
@@ -23,11 +23,17 @@ export function scopeFilter(query) {
23
23
  }
24
24
  return filter;
25
25
  }
26
+ export function sessionMatch(only, exclude) {
27
+ const match = {};
28
+ if (only)
29
+ match['$eq'] = only;
30
+ if (exclude && exclude.length > 0)
31
+ match['$nin'] = exclude;
32
+ return Object.keys(match).length === 0 ? {} : { sessionId: match };
33
+ }
26
34
  export function visibleFilter(query) {
27
35
  return {
28
36
  status: { $ne: 'replaced' },
29
- ...(query.excludeSessions && query.excludeSessions.length > 0
30
- ? { sessionId: { $nin: query.excludeSessions } }
31
- : {}),
37
+ ...sessionMatch(undefined, query.excludeSessions),
32
38
  };
33
39
  }
@@ -1,6 +1,6 @@
1
1
  import { isWholeScope } from '../adapter.js';
2
2
  import { toDoc, toObservation } from './docs.js';
3
- import { projectMatch } from './filters.js';
3
+ import { projectMatch, sessionMatch } from './filters.js';
4
4
  import { escapeRegex } from './helpers.js';
5
5
  import { partitionIds } from '../../util/shortid.js';
6
6
  import { noProjects } from '../project-scope.js';
@@ -65,8 +65,7 @@ export async function list(observations, sessions, symbols, edges, scanned, filt
65
65
  return [];
66
66
  const query = {};
67
67
  Object.assign(query, projectMatch(filter.project));
68
- if (filter.sessionId)
69
- query['sessionId'] = filter.sessionId;
68
+ Object.assign(query, sessionMatch(filter.sessionId, filter.excludeSessions));
70
69
  if (filter.kind)
71
70
  query['kind'] = filter.kind;
72
71
  if (filter.status)
@@ -1,3 +1,4 @@
1
1
  import type { ProjectFilter, SearchQuery } from '../../types.js';
2
2
  export declare function projectClause(filter: ProjectFilter | undefined, values: unknown[], column?: string): string | null;
3
+ export declare function excludeSessionsClause(sessions: string[] | undefined, values: unknown[]): string | null;
3
4
  export declare function appendScope(query: SearchQuery, conditions: string[], values: unknown[]): void;
@@ -6,6 +6,12 @@ export function projectClause(filter, values, column = 'project') {
6
6
  values.push(projects);
7
7
  return `${column} = ANY($${values.length}::text[])`;
8
8
  }
9
+ export function excludeSessionsClause(sessions, values) {
10
+ if (!sessions || sessions.length === 0)
11
+ return null;
12
+ values.push(sessions);
13
+ return `session_id <> ALL($${values.length}::text[])`;
14
+ }
9
15
  export function appendScope(query, conditions, values) {
10
16
  conditions.push("status <> 'replaced'");
11
17
  const project = projectClause(query.project, values);
@@ -27,8 +33,7 @@ export function appendScope(query, conditions, values) {
27
33
  values.push(query.until);
28
34
  conditions.push(`created_at <= $${values.length}`);
29
35
  }
30
- if (query.excludeSessions && query.excludeSessions.length > 0) {
31
- values.push(query.excludeSessions);
32
- conditions.push(`session_id <> ALL($${values.length}::text[])`);
33
- }
36
+ const excluded = excludeSessionsClause(query.excludeSessions, values);
37
+ if (excluded)
38
+ conditions.push(excluded);
34
39
  }
@@ -18,6 +18,7 @@ export declare class PostgresStore implements MemoryStore {
18
18
  ensureTagsIndexed(): Promise<void>;
19
19
  readVectorDims(): Promise<number | null>;
20
20
  migrateVectorDims(dims: number): Promise<boolean>;
21
+ storedVectorDims(): number | null;
21
22
  private ensureVectorColumn;
22
23
  close(): Promise<void>;
23
24
  ping(): Promise<boolean>;
@@ -65,6 +65,9 @@ export class PostgresStore {
65
65
  await this.writeMeta();
66
66
  return true;
67
67
  }
68
+ storedVectorDims() {
69
+ return this.vectorEnabled ? this.vectorDims : null;
70
+ }
68
71
  async ensureVectorColumn(dims) {
69
72
  if (!this.vectorEnabled)
70
73
  return false;
@@ -1,6 +1,6 @@
1
1
  import { foreignNames, isWholeScope } from '../adapter.js';
2
2
  import { partitionIds } from '../../util/shortid.js';
3
- import { projectClause } from './filters.js';
3
+ import { excludeSessionsClause, projectClause } from './filters.js';
4
4
  import { toIndexEntry, toObservation } from './rows.js';
5
5
  import { noProjects } from '../project-scope.js';
6
6
  export async function getObservations(pool, ids) {
@@ -88,6 +88,9 @@ export async function list(pool, filter) {
88
88
  values.push(filter.sessionId);
89
89
  conditions.push(`session_id = $${values.length}`);
90
90
  }
91
+ const excluded = excludeSessionsClause(filter.excludeSessions, values);
92
+ if (excluded)
93
+ conditions.push(excluded);
91
94
  if (filter.kind) {
92
95
  values.push(filter.kind);
93
96
  conditions.push(`kind = $${values.length}`);
@@ -1,5 +1,6 @@
1
1
  import type { ProjectFilter, RemoveFilter, SearchQuery } from '../../types.js';
2
2
  export declare function projectClause(column: string, filter: ProjectFilter | undefined, params: unknown[]): string | null;
3
+ export declare function excludeSessionsClause(column: string, sessions: string[] | undefined, params: unknown[]): string | null;
3
4
  export declare function removeWhere(filter: RemoveFilter): {
4
5
  where: string;
5
6
  params: unknown[];
@@ -12,6 +12,12 @@ export function projectClause(column, filter, params) {
12
12
  ? `${column} = ?`
13
13
  : `${column} IN (${projects.map(() => '?').join(',')})`;
14
14
  }
15
+ export function excludeSessionsClause(column, sessions, params) {
16
+ if (!sessions || sessions.length === 0)
17
+ return null;
18
+ params.push(...sessions);
19
+ return `${column} NOT IN (${sessions.map(() => '?').join(',')})`;
20
+ }
15
21
  export function removeWhere(filter) {
16
22
  const conditions = [];
17
23
  const params = [];
@@ -66,10 +72,9 @@ export function appendScope(query, conditions, params, prefix) {
66
72
  conditions.push(`${prefix}created_at <= ?`);
67
73
  params.push(query.until);
68
74
  }
69
- if (query.excludeSessions && query.excludeSessions.length > 0) {
70
- conditions.push(`${prefix}session_id NOT IN (${query.excludeSessions.map(() => '?').join(',')})`);
71
- params.push(...query.excludeSessions);
72
- }
75
+ const excluded = excludeSessionsClause(`${prefix}session_id`, query.excludeSessions, params);
76
+ if (excluded)
77
+ conditions.push(excluded);
73
78
  }
74
79
  function scopeExpression(filter) {
75
80
  const tokens = projectsOf(filter).map(scopeToken);
@@ -1,6 +1,6 @@
1
1
  import { foreignNames, isWholeScope } from '../adapter.js';
2
2
  import { toObservation } from './rows.js';
3
- import { projectClause, removeWhere } from './filters.js';
3
+ import { excludeSessionsClause, projectClause, removeWhere } from './filters.js';
4
4
  import { partitionIds } from '../../util/shortid.js';
5
5
  import { packVector } from '../../util/vector.js';
6
6
  import { scopeToken } from '../../util/scope.js';
@@ -88,6 +88,9 @@ export async function list(db, filter) {
88
88
  conditions.push('session_id = ?');
89
89
  params.push(filter.sessionId);
90
90
  }
91
+ const excluded = excludeSessionsClause('session_id', filter.excludeSessions, params);
92
+ if (excluded)
93
+ conditions.push(excluded);
91
94
  if (filter.kind) {
92
95
  conditions.push('kind = ?');
93
96
  params.push(filter.kind);
@@ -1,5 +1,5 @@
1
1
  import { toBuffer, toIndexEntry } from './rows.js';
2
- import { TAG_PREDICATE, appendScope, toMatchExpression } from './filters.js';
2
+ import { TAG_PREDICATE, appendScope, excludeSessionsClause, toMatchExpression } from './filters.js';
3
3
  import { cosine, unpackVector } from '../../util/vector.js';
4
4
  import { noProjects } from '../project-scope.js';
5
5
  export async function searchKeyword(db, query) {
@@ -26,10 +26,9 @@ export async function searchKeyword(db, query) {
26
26
  conditions.push('o.created_at <= ?');
27
27
  params.push(query.until);
28
28
  }
29
- if (query.excludeSessions && query.excludeSessions.length > 0) {
30
- conditions.push(`o.session_id NOT IN (${query.excludeSessions.map(() => '?').join(',')})`);
31
- params.push(...query.excludeSessions);
32
- }
29
+ const excluded = excludeSessionsClause('o.session_id', query.excludeSessions, params);
30
+ if (excluded)
31
+ conditions.push(excluded);
33
32
  params.push(query.limit);
34
33
  const rows = db
35
34
  .prepare(`SELECT o.id, o.kind, o.title, o.project, o.created_at,
package/dist/types.d.ts CHANGED
@@ -55,6 +55,7 @@ export interface RemoveFilter {
55
55
  export interface ListFilter {
56
56
  project?: ProjectFilter;
57
57
  sessionId?: string;
58
+ excludeSessions?: string[];
58
59
  kind?: ObservationKind;
59
60
  status?: ObservationStatus;
60
61
  after?: number;
@@ -1 +1,2 @@
1
+ export declare function formatDayTime(at: number, now?: number): string;
1
2
  export declare function formatDay(at: number, now?: number): string;
package/dist/util/day.js CHANGED
@@ -4,6 +4,10 @@ const OTHER_YEAR = new Intl.DateTimeFormat('en-US', {
4
4
  day: 'numeric',
5
5
  year: 'numeric',
6
6
  });
7
+ const CLOCK = new Intl.DateTimeFormat('en-GB', { hour: '2-digit', minute: '2-digit' });
8
+ export function formatDayTime(at, now = Date.now()) {
9
+ return `${formatDay(at, now)}, ${CLOCK.format(new Date(at))}`;
10
+ }
7
11
  export function formatDay(at, now = Date.now()) {
8
12
  const date = new Date(at);
9
13
  const format = date.getFullYear() === new Date(now).getFullYear() ? THIS_YEAR : OTHER_YEAR;
@@ -0,0 +1,4 @@
1
+ export declare function safeName(id: string): string;
2
+ export declare function readJson<T>(file: string): T | null;
3
+ export declare function writeJsonAtomic(file: string, value: unknown): void;
4
+ export declare function sweepOlderThan(folder: string, maxAgeMs: number, now?: number): void;
@@ -0,0 +1,37 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync, } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+ export function safeName(id) {
5
+ return id.replace(/[^\w-]/g, '_');
6
+ }
7
+ export function readJson(file) {
8
+ try {
9
+ return JSON.parse(readFileSync(file, 'utf8'));
10
+ }
11
+ catch {
12
+ return null;
13
+ }
14
+ }
15
+ export function writeJsonAtomic(file, value) {
16
+ mkdirSync(dirname(file), { recursive: true });
17
+ const temp = `${file}.${randomUUID()}.tmp`;
18
+ writeFileSync(temp, JSON.stringify(value), 'utf8');
19
+ renameSync(temp, file);
20
+ }
21
+ export function sweepOlderThan(folder, maxAgeMs, now = Date.now()) {
22
+ let names;
23
+ try {
24
+ names = readdirSync(folder);
25
+ }
26
+ catch {
27
+ return;
28
+ }
29
+ for (const name of names) {
30
+ const file = join(folder, name);
31
+ try {
32
+ if (now - statSync(file).mtimeMs > maxAgeMs)
33
+ rmSync(file, { force: true });
34
+ }
35
+ catch { }
36
+ }
37
+ }
@@ -25,6 +25,10 @@ you send a prompt
25
25
  Both steps are hooks, so they always run. Nothing depends on Claude deciding to
26
26
  look something up.
27
27
 
28
+ A turn is also saved as soon as Claude finishes the reply, in the background, so
29
+ another chat sees it without waiting for your next prompt. The save at the next
30
+ prompt stays as the backup, for a reply you interrupted.
31
+
28
32
  Install also writes a short standing instruction into `CLAUDE.local.md` (or
29
33
  `~/.claude/CLAUDE.md` for a machine-wide install), telling Claude to search
30
34
  memory before asking you to re-explain something. Hook output is context the
@@ -36,7 +40,8 @@ for. `claude-db uninstall` takes the block back out.
36
40
  file or ran a real command. Questions, `grep`, and "ok" are skipped. A busy day
37
41
  produces 10 to 20 rows, not hundreds.
38
42
 
39
- **What gets injected.** Recent session summaries at startup. Above a prompt, at
43
+ **What gets injected.** At startup: facts, the newest 5 requests from other
44
+ chats, any request another chat has not finished, and the handoff note. Above a prompt, at
40
45
  most two memories from earlier chats, picked by Claude Haiku:
41
46
 
42
47
  1. Search finds the ten closest memories from other chats. If none shares at
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-db",
3
- "version": "0.12.1",
3
+ "version": "0.12.3",
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",
@@ -130,10 +130,10 @@
130
130
  "access": "public"
131
131
  },
132
132
  "optionalDependencies": {
133
- "claude-db-grammars-linux-x64": "0.12.1",
134
- "claude-db-grammars-linux-arm64": "0.12.1",
135
- "claude-db-grammars-darwin-x64": "0.12.1",
136
- "claude-db-grammars-darwin-arm64": "0.12.1",
137
- "claude-db-grammars-win32-x64": "0.12.1"
133
+ "claude-db-grammars-linux-x64": "0.12.3",
134
+ "claude-db-grammars-linux-arm64": "0.12.3",
135
+ "claude-db-grammars-darwin-x64": "0.12.3",
136
+ "claude-db-grammars-darwin-arm64": "0.12.3",
137
+ "claude-db-grammars-win32-x64": "0.12.3"
138
138
  }
139
139
  }
@@ -14,8 +14,12 @@ claude-db catchup
14
14
  It prints what memory and git know about this project, in plain text. Some parts may be missing. A part
15
15
  with nothing in it is left out.
16
16
 
17
- - `Last handoff` is a note the user or a teammate saved on purpose. Trust it most.
18
- - `Last chat` is the newest recorded chat, with a few lines of the work done in it.
17
+ - `Last handoff` is a note the user or a teammate saved on purpose. Trust it most, unless its heading says
18
+ `older than the last chat`. Then the last chat is newer, and wins where they differ.
19
+ - `Not finished yet in another chat` is a request another chat is still working on, or that was stopped.
20
+ Say so under **Open**.
21
+ - `Last chat` and `Chat before` are the other chats with the newest recorded requests, open or ended, newest
22
+ first: the 5 newest requests in all.
19
23
  - `Still to do` are to-dos found in earlier chats.
20
24
  - `Not committed yet` is recorded work that no commit has covered.
21
25
  - `Decisions and dead ends` are what was chosen or ruled out, with the reason.