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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.3
4
+
5
+ ### Fixed
6
+
7
+ - **`distill` no longer stops on Postgres.** A Claude memory file with no `modified` time made it fail with
8
+ `invalid input syntax for type bigint`, so chats waited for days. Times are now whole milliseconds.
9
+ - **Rows saved without a vector get one later.** A row is saved as text only when the embedding model is still
10
+ loading, or when its width differs from the Postgres column. The next chat start fills such rows in the
11
+ background, at most every 6 hours, once an embedder of the right width loads. It never replaces a vector from
12
+ another embedder.
13
+ - **Background jobs keep their output.** It goes to `~/.claude-memory/logs/background.log`, which rolls over at
14
+ 1 MB.
15
+ - **The waiting-chats warning names `claude-db distill --backfill`**, which works through them.
16
+ - **`claude-db languages` lists TypeScript, TSX and JavaScript** as built in.
17
+
18
+ ### Changed
19
+
20
+ - **A grep for a symbol that is not in the graph is faster.** The hook no longer runs a "did you mean" scan it
21
+ never shows.
22
+ - **`claude-db adoption` is faster.** It looks each symbol up once, several at a time, and shows a counter on a
23
+ terminal.
24
+
25
+ ## 0.12.2
26
+
27
+ ### Fixed
28
+
29
+ - **A new chat knows what the other chats did, even while they are still open.** The start of each chat shows
30
+ the newest 5 requests from other chats, grouped by chat, with a chat's summary once it has ended. A request is
31
+ saved as soon as Claude finishes the reply, and one that another chat is still working on, also in a
32
+ background task, is shown as not finished yet. A handoff note stays, marked `older than the last chat` once a
33
+ later request has moved past it. `/catchup` shows the same and leaves out the chat it runs in.
34
+
3
35
  ## 0.12.1
4
36
 
5
37
  ### Changed
@@ -0,0 +1,12 @@
1
+ export interface ActiveRequest {
2
+ sessionId: string;
3
+ project: string;
4
+ request: string;
5
+ askedAt: number;
6
+ token: string;
7
+ }
8
+ export declare function recordActive(sessionId: string, project: string, prompt: string, now?: number): void;
9
+ export declare function activeToken(sessionId: string): string | null;
10
+ export declare function clearActive(sessionId: string, token?: string): void;
11
+ export declare function activeRequests(projects: readonly string[], current: string | undefined, now?: number): ActiveRequest[];
12
+ export declare function sweepActive(now?: number): void;
@@ -0,0 +1,74 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { readdirSync, rmSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { CONFIG_DIR } from '../config/dir.js';
5
+ import { readJson, safeName, sweepOlderThan, writeJsonAtomic } from '../util/json-file.js';
6
+ import { isSearchable, readablePrompt } from '../util/prompt.js';
7
+ import { redact } from './redact.js';
8
+ import { isSyntheticPrompt } from './transcript.js';
9
+ import { clipAsked, stripPrivate } from './turn-extractor.js';
10
+ const SHOWN_FOR_MS = 2 * 60 * 60 * 1000;
11
+ const KEPT_FOR_MS = 24 * 60 * 60 * 1000;
12
+ const SHOWN_AT_MOST = 2;
13
+ function folder() {
14
+ return join(CONFIG_DIR, 'active');
15
+ }
16
+ function fileFor(sessionId) {
17
+ return join(folder(), `${safeName(sessionId)}.json`);
18
+ }
19
+ function readActive(file) {
20
+ const value = readJson(file);
21
+ const valid = typeof value?.sessionId === 'string' &&
22
+ typeof value.project === 'string' &&
23
+ typeof value.request === 'string' &&
24
+ typeof value.askedAt === 'number' &&
25
+ typeof value.token === 'string';
26
+ return valid ? value : null;
27
+ }
28
+ export function recordActive(sessionId, project, prompt, now = Date.now()) {
29
+ if (isSyntheticPrompt(prompt))
30
+ return;
31
+ const text = readablePrompt(stripPrivate(prompt));
32
+ if (!isSearchable(text)) {
33
+ clearActive(sessionId);
34
+ return;
35
+ }
36
+ const request = clipAsked(redact(text));
37
+ writeJsonAtomic(fileFor(sessionId), {
38
+ sessionId,
39
+ project,
40
+ request,
41
+ askedAt: now,
42
+ token: randomUUID(),
43
+ });
44
+ }
45
+ export function activeToken(sessionId) {
46
+ return readActive(fileFor(sessionId))?.token ?? null;
47
+ }
48
+ export function clearActive(sessionId, token) {
49
+ const file = fileFor(sessionId);
50
+ if (token !== undefined && readActive(file)?.token !== token)
51
+ return;
52
+ rmSync(file, { force: true });
53
+ }
54
+ export function activeRequests(projects, current, now = Date.now()) {
55
+ let names;
56
+ try {
57
+ names = readdirSync(folder());
58
+ }
59
+ catch {
60
+ return [];
61
+ }
62
+ return names
63
+ .filter((name) => name.endsWith('.json'))
64
+ .map((name) => readActive(join(folder(), name)))
65
+ .filter((entry) => entry !== null &&
66
+ projects.includes(entry.project) &&
67
+ entry.sessionId !== current &&
68
+ now - entry.askedAt <= SHOWN_FOR_MS)
69
+ .sort((a, b) => b.askedAt - a.askedAt)
70
+ .slice(0, SHOWN_AT_MOST);
71
+ }
72
+ export function sweepActive(now = Date.now()) {
73
+ sweepOlderThan(folder(), KEPT_FOR_MS, now);
74
+ }
@@ -5,7 +5,7 @@ export interface FlushResult {
5
5
  summary: string | null;
6
6
  lastReply: string;
7
7
  }
8
- export declare function flushSession(ctx: RecallContext, sessionId: string, project: string, transcriptPath?: string, rebuild?: boolean): Promise<FlushResult>;
8
+ export declare function flushSession(ctx: RecallContext, sessionId: string, project: string, transcriptPath?: string, rebuild?: boolean, finalReply?: string): Promise<FlushResult>;
9
9
  export declare function embedObservations(ctx: RecallContext, observations: Observation[]): Promise<void>;
10
10
  export declare function summarize(observations: Observation[], previous?: string): string;
11
11
  export declare function resetCursor(sessionId: string): void;
@@ -4,10 +4,13 @@ import { CONFIG_DIR } from '../config/index.js';
4
4
  import { readTranscript, sessionIdsOnDisk, transcriptPathFor } from './transcript.js';
5
5
  import { observationsFromTurns } from './turn-extractor.js';
6
6
  import { closeLandedWork } from './progress.js';
7
- export async function flushSession(ctx, sessionId, project, transcriptPath, rebuild = false) {
7
+ import { noteMissingVectors } from './vectors.js';
8
+ export async function flushSession(ctx, sessionId, project, transcriptPath, rebuild = false, finalReply = '') {
8
9
  const path = transcriptPath ?? transcriptPathFor(project, sessionId);
9
10
  const cursor = readCursor(sessionId);
10
- const { turns, nextOffset } = readTranscript(path, cursor);
11
+ const read = readTranscript(path, cursor);
12
+ const { nextOffset } = read;
13
+ const turns = withFinalReply(read.turns, finalReply);
11
14
  const lastReply = turns.at(-1)?.reasoning ?? '';
12
15
  if (turns.length === 0) {
13
16
  await closeLandedWork(ctx.store, project);
@@ -35,10 +38,15 @@ export async function flushSession(ctx, sessionId, project, transcriptPath, rebu
35
38
  return { observations: observations.length, summary, lastReply };
36
39
  }
37
40
  export async function embedObservations(ctx, observations) {
41
+ if (observations.length === 0)
42
+ return;
38
43
  try {
39
44
  const embedder = await ctx.embedder();
40
- if (embedder.dimensions === 0)
45
+ if (embedder.dimensions === 0) {
46
+ if (ctx.config.embeddings.provider !== 'none')
47
+ noteMissingVectors(observations);
41
48
  return;
49
+ }
42
50
  const size = ctx.config.embeddings.batchSize;
43
51
  for (let start = 0; start < observations.length; start += size) {
44
52
  const chunk = observations.slice(start, start + size);
@@ -51,8 +59,11 @@ export async function embedObservations(ctx, observations) {
51
59
  }
52
60
  });
53
61
  }
62
+ const stored = ctx.store.storedVectorDims?.() ?? null;
63
+ noteMissingVectors(observations, stored !== null && stored !== embedder.dimensions);
54
64
  }
55
65
  catch (error) {
66
+ noteMissingVectors(observations);
56
67
  process.stderr.write(`[claude-db] embedding skipped: ` +
57
68
  `${error instanceof Error ? error.message : String(error)}\n`);
58
69
  }
@@ -65,6 +76,14 @@ const KIND_RANK = {
65
76
  pattern: 4,
66
77
  context: 5,
67
78
  };
79
+ function withFinalReply(turns, finalReply) {
80
+ const reply = finalReply.trim();
81
+ const last = turns.at(-1);
82
+ if (!last || !reply || last.reasoning.includes(reply))
83
+ return turns;
84
+ const reasoning = last.reasoning ? `${last.reasoning}\n${reply}` : reply;
85
+ return [...turns.slice(0, -1), { ...last, reasoning }];
86
+ }
68
87
  export function summarize(observations, previous) {
69
88
  const kept = previous ? previous.split(' | ').filter(Boolean) : [];
70
89
  for (const obs of [...observations].sort((a, b) => KIND_RANK[a.kind] - KIND_RANK[b.kind])) {
@@ -1,2 +1,3 @@
1
1
  import type { Observation } from '../types.js';
2
+ export declare const GIT_SESSION = "git";
2
3
  export declare function observationsFromGit(project: string, limit: number): Observation[];
@@ -3,6 +3,7 @@ import { join } from 'node:path';
3
3
  import { observationId } from './identity.js';
4
4
  import { redact } from './redact.js';
5
5
  import { classifyTurn, topLevelDirs } from './turn-extractor.js';
6
+ export const GIT_SESSION = 'git';
6
7
  const RECORD = '';
7
8
  const FIELD = '';
8
9
  const NOT_WORTH_KEEPING = /^(v?\d+\.\d+\.\d+|merge |revert "|bump |release |chore\(release\)|\d+\.\d+\.\d+$)/i;
@@ -44,8 +45,8 @@ function toObservation(record, project) {
44
45
  return null;
45
46
  const timestamp = createdAt;
46
47
  return {
47
- id: observationId('git', 0, sha),
48
- sessionId: 'git',
48
+ id: observationId(GIT_SESSION, 0, sha),
49
+ sessionId: GIT_SESSION,
49
50
  project,
50
51
  ...(author ? { author } : {}),
51
52
  kind: classifyTurn({
@@ -10,6 +10,7 @@ export { redact } from './redact.js';
10
10
  export { claimScrub, finishScrub, releaseScrub, scrubSecrets } from './scrub.js';
11
11
  export { flushSession, resetCursor, clearCursor, sweepCursors, summarize, embedObservations, } from './flush.js';
12
12
  export type { FlushResult } from './flush.js';
13
+ export { claimReembed, finishReembed, releaseReembed, startReembed, vectorsMissing, } from './vectors.js';
13
14
  export { closeLandedWork, openWork } from './progress.js';
14
15
  export { REINGEST_VERSION, claimReingest, finishReingest, reingestDone, reingestProject, rememberedTranscripts, reingestSession, releaseReingest, } from './reingest.js';
15
16
  export type { ProjectReingest, SessionReingest } from './reingest.js';
@@ -7,6 +7,7 @@ export { observationsFromTurns } from './turn-extractor.js';
7
7
  export { redact } from './redact.js';
8
8
  export { claimScrub, finishScrub, releaseScrub, scrubSecrets } from './scrub.js';
9
9
  export { flushSession, resetCursor, clearCursor, sweepCursors, summarize, embedObservations, } from './flush.js';
10
+ export { claimReembed, finishReembed, releaseReembed, startReembed, vectorsMissing, } from './vectors.js';
10
11
  export { closeLandedWork, openWork } from './progress.js';
11
12
  export { REINGEST_VERSION, claimReingest, finishReingest, reingestDone, reingestProject, rememberedTranscripts, reingestSession, releaseReingest, } from './reingest.js';
12
13
  export { aiSummary, buildSummaryPrompt, validateSummary } from './summarize.js';
@@ -12,6 +12,7 @@ export interface TranscriptRead {
12
12
  lastTimestamp: number;
13
13
  }
14
14
  export declare function readTranscript(path: string, fromOffset?: number): TranscriptRead;
15
+ export declare function isSyntheticPrompt(text: string): boolean;
15
16
  export declare function transcriptPathFor(project: string, sessionId: string): string;
16
17
  export declare function transcriptsFor(project: string): string[];
17
18
  export declare function sessionIdsOnDisk(): string[];
@@ -117,7 +117,7 @@ function extractToolCalls(content) {
117
117
  }
118
118
  return calls;
119
119
  }
120
- function isSyntheticPrompt(text) {
120
+ export function isSyntheticPrompt(text) {
121
121
  return (text.includes('<system-reminder>') ||
122
122
  text.includes('<project-memory>') ||
123
123
  text.includes('<recalled-memory>') ||
@@ -125,7 +125,8 @@ function isSyntheticPrompt(text) {
125
125
  isRelayedMessage(text) ||
126
126
  text.startsWith('Caveat:') ||
127
127
  text.startsWith('[Request interrupted') ||
128
- text.startsWith('<local-command'));
128
+ text.startsWith('<local-command') ||
129
+ text.startsWith('<task-notification>'));
129
130
  }
130
131
  function projectSlug(project) {
131
132
  return project.replace(/[^a-zA-Z0-9]/g, '-');
@@ -1,6 +1,9 @@
1
1
  import type { Config } from '../config/index.js';
2
2
  import type { Observation, ObservationKind } from '../types.js';
3
3
  import type { Turn } from './transcript.js';
4
+ export declare function clipAsked(text: string): string;
5
+ export declare function askedIn(body: string): string;
6
+ export declare function stripPrivate(text: string): string;
4
7
  export declare function observationsFromTurns(turns: Turn[], sessionId: string, project: string, config: Config): Observation[];
5
8
  export declare function topLevelDirs(files: string[], project: string): string[];
6
9
  export declare function classifyTurn(turn: Turn): ObservationKind;
@@ -2,6 +2,17 @@ import { classifyCommand } from './command.js';
2
2
  import { isSearchable, readablePrompt } from '../util/prompt.js';
3
3
  import { currentAuthor, observationId } from './identity.js';
4
4
  import { redact } from './redact.js';
5
+ const ASKED_CHARS = 120;
6
+ export function clipAsked(text) {
7
+ const asked = text.replace(/\s+/g, ' ').trim();
8
+ return asked.length > ASKED_CHARS ? `${asked.slice(0, ASKED_CHARS)}…` : asked;
9
+ }
10
+ export function askedIn(body) {
11
+ return clipAsked(/^Asked: (.*)$/m.exec(body)?.[1] ?? '');
12
+ }
13
+ export function stripPrivate(text) {
14
+ return text.replace(/<private>[\s\S]*?(?:<\/private>|$)/gi, '[private]');
15
+ }
5
16
  export function observationsFromTurns(turns, sessionId, project, config) {
6
17
  return turns
7
18
  .map(withoutPrivate)
@@ -13,8 +24,7 @@ export function observationsFromTurns(turns, sessionId, project, config) {
13
24
  .map(({ id, turn }) => buildObservation(turn, id, sessionId, project, config));
14
25
  }
15
26
  function withoutPrivate(turn) {
16
- const strip = (text) => text.replace(/<private>[\s\S]*?(?:<\/private>|$)/gi, '[private]');
17
- return { ...turn, prompt: strip(turn.prompt), reasoning: strip(turn.reasoning) };
27
+ return { ...turn, prompt: stripPrivate(turn.prompt), reasoning: stripPrivate(turn.reasoning) };
18
28
  }
19
29
  function isSubstantive(turn, config) {
20
30
  const files = turn.files.filter((file) => !isExcluded(file, config.capture.exclude));
@@ -0,0 +1,7 @@
1
+ import type { Observation } from '../types.js';
2
+ export declare function noteMissingVectors(observations: Observation[], everyRow?: boolean): void;
3
+ export declare const vectorsMissing: (project: string) => boolean;
4
+ export declare function claimReembed(project: string, now?: number): boolean;
5
+ export declare function startReembed(project: string): void;
6
+ export declare function finishReembed(project: string, now?: number): void;
7
+ export declare function releaseReembed(project: string): void;
@@ -0,0 +1,38 @@
1
+ import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { CONFIG_DIR } from '../config/index.js';
4
+ import { claimJob, finishJob, jobMark, releaseJob } from '../util/job-lock.js';
5
+ import { scopeToken } from '../util/scope.js';
6
+ const JOB = 'reembed';
7
+ const FLAGS = 'vectors-missing';
8
+ const REEMBED_EVERY_MS = 6 * 60 * 60 * 1000;
9
+ const flagPath = (project) => join(CONFIG_DIR, FLAGS, `${scopeToken(project)}.flag`);
10
+ export function noteMissingVectors(observations, everyRow = false) {
11
+ const projects = new Set(observations.filter((obs) => everyRow || !obs.embedding?.length).map((obs) => obs.project));
12
+ for (const project of projects) {
13
+ try {
14
+ mkdirSync(join(CONFIG_DIR, FLAGS), { recursive: true });
15
+ writeFileSync(flagPath(project), '');
16
+ }
17
+ catch {
18
+ continue;
19
+ }
20
+ }
21
+ }
22
+ export const vectorsMissing = (project) => existsSync(flagPath(project));
23
+ export function claimReembed(project, now = Date.now()) {
24
+ if (!vectorsMissing(project))
25
+ return false;
26
+ if (now - jobMark(JOB, project) < REEMBED_EVERY_MS)
27
+ return false;
28
+ return claimJob(JOB, project, now);
29
+ }
30
+ export function startReembed(project) {
31
+ rmSync(flagPath(project), { force: true });
32
+ }
33
+ export function finishReembed(project, now = Date.now()) {
34
+ finishJob(JOB, project, now);
35
+ }
36
+ export function releaseReembed(project) {
37
+ releaseJob(JOB, project);
38
+ }
@@ -4,15 +4,20 @@ export interface CatchupData {
4
4
  handoff: {
5
5
  at: number;
6
6
  lines: string[];
7
+ passed: boolean;
7
8
  } | null;
8
- lastChat: {
9
+ unfinished: {
9
10
  at: number;
10
- summary: string;
11
+ request: string;
12
+ }[];
13
+ chats: {
14
+ at: number;
15
+ summary: string | null;
11
16
  work: string[];
12
- } | null;
17
+ }[];
13
18
  todos: string[];
14
19
  decisions: string[];
15
20
  uncommitted: string[];
16
21
  git: GitState | null;
17
22
  }
18
- export declare function gatherCatchup(ctx: RecallContext, project: string, now?: number): Promise<CatchupData>;
23
+ export declare function gatherCatchup(ctx: RecallContext, project: string, current?: string, now?: number): Promise<CatchupData>;
@@ -1,32 +1,30 @@
1
1
  import { openWork } from '../capture/progress.js';
2
2
  import { FACT_SESSION, factLabel, factType, onePerKey } from '../facts/model.js';
3
- import { handoffBodyLines, newestHandoff } from '../facts/handoff.js';
3
+ import { activeRequests } from '../capture/active.js';
4
+ import { handoffBodyLines, newestHandoff, passedNote } from '../facts/handoff.js';
5
+ import { latestRequestAt, recentChats, turnLine } from '../facts/last-chat.js';
4
6
  import { readGitState } from './git-state.js';
5
- const CHAT_TITLES = 6;
6
7
  const TODOS = 5;
7
8
  const UNCOMMITTED = 5;
8
9
  const DECISIONS = 5;
9
10
  const FACTS_SCANNED = 100;
10
- export async function gatherCatchup(ctx, project, now = Date.now()) {
11
+ export async function gatherCatchup(ctx, project, current, now = Date.now()) {
11
12
  const handoff = await newestHandoff(ctx, project, now);
12
- const [latest] = await ctx.store.recentSessions(project, 1);
13
- const chatWork = latest
14
- ? (await ctx.store.list({ project, sessionId: latest.id, newest: true, limit: CHAT_TITLES }))
15
- .filter((obs) => obs.status !== 'replaced')
16
- .map((obs) => obs.title)
17
- : [];
13
+ const unfinished = activeRequests(await ctx.store.projectScope(project), current, now);
14
+ const chats = await recentChats(ctx, project, current);
15
+ const latest = latestRequestAt(chats, unfinished);
18
16
  const facts = await ctx.store.list({
19
17
  project,
20
18
  sessionId: FACT_SESSION,
21
19
  newest: true,
22
20
  limit: FACTS_SCANNED,
23
21
  });
24
- const current = onePerKey(facts.filter((obs) => obs.status !== 'replaced'));
25
- const todos = current
22
+ const kept = onePerKey(facts.filter((obs) => obs.status !== 'replaced'));
23
+ const todos = kept
26
24
  .filter((obs) => factType(obs) === 'todo')
27
25
  .slice(0, TODOS)
28
26
  .map((obs) => obs.title);
29
- const decisions = current
27
+ const decisions = kept
30
28
  .filter((obs) => ['decision', 'deadend'].includes(factType(obs) ?? ''))
31
29
  .slice(0, DECISIONS)
32
30
  .map((obs) => `${factLabel(obs)}: ${obs.title}`);
@@ -34,10 +32,19 @@ export async function gatherCatchup(ctx, project, now = Date.now()) {
34
32
  .slice(0, UNCOMMITTED)
35
33
  .map((obs) => obs.title);
36
34
  return {
37
- handoff: handoff ? { at: handoff.createdAt, lines: handoffBodyLines(handoff) } : null,
38
- lastChat: latest
39
- ? { at: latest.startedAt, summary: latest.summary ?? '', work: chatWork }
35
+ handoff: handoff
36
+ ? {
37
+ at: handoff.createdAt,
38
+ lines: handoffBodyLines(handoff),
39
+ passed: passedNote(handoff.createdAt, latest),
40
+ }
40
41
  : null,
42
+ unfinished: unfinished.map((entry) => ({ at: entry.askedAt, request: entry.request })),
43
+ chats: chats.map((chat) => ({
44
+ at: chat.at,
45
+ summary: chat.summary,
46
+ work: chat.turns.map(turnLine),
47
+ })),
41
48
  todos,
42
49
  decisions,
43
50
  uncommitted,
@@ -1,4 +1,5 @@
1
- import { formatDay } from '../util/day.js';
1
+ import { handoffHeading } from '../facts/handoff.js';
2
+ import { formatDay, formatDayTime } from '../util/day.js';
2
3
  export const NOTHING_RECORDED = 'Nothing recorded for this project yet.';
3
4
  function section(heading, lines) {
4
5
  return lines.length === 0 ? [] : [heading, ...lines, ''];
@@ -22,22 +23,30 @@ function branchLine(git) {
22
23
  const state = git.changed === 0 ? 'clean' : `${git.changed} file${git.changed === 1 ? '' : 's'} uncommitted`;
23
24
  return [`Branch: ${git.branch ?? 'detached HEAD'}, ${state}`, ''];
24
25
  }
25
- function chatBlock(chat, now) {
26
- if (!chat)
27
- return [];
28
- const heading = `Last chat (${formatDay(chat.at, now)}): ${chat.summary || 'no summary'}`;
29
- return [heading, ...bullets(chat.work), ''];
26
+ function chatBlocks(chats, now) {
27
+ return chats.flatMap((chat, index) => {
28
+ if (!chat.summary && chat.work.length === 0)
29
+ return [];
30
+ const heading = `${index === 0 ? 'Last chat' : 'Chat before'} (${formatDay(chat.at, now)}):`;
31
+ return [chat.summary ? `${heading} ${chat.summary}` : heading, ...bullets(chat.work), ''];
32
+ });
33
+ }
34
+ function unfinishedBlocks(unfinished, now) {
35
+ return unfinished.flatMap((entry) => section(`Not finished yet in another chat (${formatDayTime(entry.at, now)}):`, [
36
+ ` - asked "${entry.request}"`,
37
+ ]));
30
38
  }
31
39
  function handoffBlock(handoff, now) {
32
40
  if (!handoff)
33
41
  return [];
34
- return section(`Last handoff (${formatDay(handoff.at, now)}):`, handoff.lines.map((line) => ` ${line}`));
42
+ return section(handoffHeading(handoff.at, handoff.passed, now), handoff.lines.map((line) => ` ${line}`));
35
43
  }
36
44
  export function renderCatchup(data, now = Date.now()) {
37
45
  const { status, commits } = gitLines(data);
38
46
  const blocks = [
39
47
  ...handoffBlock(data.handoff, now),
40
- ...chatBlock(data.lastChat, now),
48
+ ...unfinishedBlocks(data.unfinished, now),
49
+ ...chatBlocks(data.chats, now),
41
50
  ...section('Still to do (from facts):', bullets(data.todos)),
42
51
  ...section('Decisions and dead ends (from facts):', bullets(data.decisions)),
43
52
  ...section('Not committed yet (recorded work):', bullets(data.uncommitted)),
@@ -4,6 +4,8 @@ import { queryGraph } from '../../graph/index.js';
4
4
  import { transcriptsFor } from '../../capture/transcript.js';
5
5
  import { resolveProject } from '../../util/project.js';
6
6
  import { DECLARED, isSymbol, symbolsGreppedIn } from '../../hooks/grep-symbols.js';
7
+ const MAX_SYMBOLS = 2;
8
+ const LOOKUPS_IN_FLIGHT = 8;
7
9
  export async function cmdAdoption() {
8
10
  const project = resolveProject(undefined);
9
11
  const files = transcriptsFor(project);
@@ -45,35 +47,8 @@ export async function cmdAdoption() {
45
47
  }
46
48
  const greps = bash.filter((command) => /\b(?:grep|rg)\b/.test(command));
47
49
  const candidates = greps.map((command) => symbolsGreppedIn(command)).filter((s) => s.length > 0);
48
- const ctx = await createContext();
49
- let fires = 0;
50
- const cache = new Map();
51
- try {
52
- for (const symbols of candidates) {
53
- let hit = false;
54
- for (const symbol of symbols.slice(0, 2)) {
55
- let fired = cache.get(symbol);
56
- if (fired === undefined) {
57
- const answer = await queryGraph(ctx.store, project, {
58
- mode: 'usages',
59
- symbol,
60
- limit: 20,
61
- });
62
- fired =
63
- !answer.empty &&
64
- (isSymbol(symbol) || answer.definitions.some((d) => DECLARED.has(d.kind)));
65
- cache.set(symbol, fired);
66
- }
67
- if (fired)
68
- hit = true;
69
- }
70
- if (hit)
71
- fires++;
72
- }
73
- }
74
- finally {
75
- await ctx.close();
76
- }
50
+ const firing = await symbolsThatFire(project, candidates.flatMap((symbols) => symbols.slice(0, MAX_SYMBOLS)));
51
+ const fires = candidates.filter((symbols) => symbols.slice(0, MAX_SYMBOLS).some((symbol) => firing.has(symbol))).length;
77
52
  const memoryTotal = [...memory.values()].reduce((a, b) => a + b, 0);
78
53
  const pct = (n, of) => (of === 0 ? '0.0%' : `${((n / of) * 100).toFixed(1)}%`);
79
54
  console.log(`Adoption for ${project} (${files.length} transcripts)\n`);
@@ -92,3 +67,40 @@ export async function cmdAdoption() {
92
67
  console.log(`\n ${ratio}`);
93
68
  }
94
69
  }
70
+ async function symbolsThatFire(project, symbols) {
71
+ const unique = [...new Set(symbols)];
72
+ const firing = new Set();
73
+ if (unique.length === 0)
74
+ return firing;
75
+ const ctx = await createContext();
76
+ const tty = process.stderr.isTTY === true;
77
+ let next = 0;
78
+ let done = 0;
79
+ const lookup = async () => {
80
+ while (next < unique.length) {
81
+ const symbol = unique[next++];
82
+ const answer = await queryGraph(ctx.store, project, {
83
+ mode: 'usages',
84
+ symbol,
85
+ limit: 20,
86
+ suggest: false,
87
+ });
88
+ if (!answer.empty &&
89
+ (isSymbol(symbol) || answer.definitions.some((d) => DECLARED.has(d.kind)))) {
90
+ firing.add(symbol);
91
+ }
92
+ done += 1;
93
+ if (tty)
94
+ process.stderr.write(`\rchecking symbols ${done}/${unique.length}`);
95
+ }
96
+ };
97
+ try {
98
+ await Promise.all(Array.from({ length: Math.min(LOOKUPS_IN_FLIGHT, unique.length) }, () => lookup()));
99
+ }
100
+ finally {
101
+ if (tty)
102
+ process.stderr.write('\r\x1b[K');
103
+ await ctx.close();
104
+ }
105
+ return firing;
106
+ }
@@ -6,7 +6,8 @@ export async function cmdCatchup() {
6
6
  const project = resolveProject(undefined);
7
7
  const ctx = await createContext();
8
8
  try {
9
- console.log(renderCatchup(await gatherCatchup(ctx, project)));
9
+ const current = process.env['CLAUDE_CODE_SESSION_ID'] || undefined;
10
+ console.log(renderCatchup(await gatherCatchup(ctx, project, current)));
10
11
  }
11
12
  finally {
12
13
  await ctx.close();
@@ -1,13 +1,17 @@
1
1
  import { GRAMMARS, PLATFORM, hasGrammar } from '../../graph/grammars.js';
2
- import { languageNames } from '../../graph/index.js';
2
+ import { LANGUAGES, languageNames } from '../../graph/index.js';
3
3
  const SHIPPED = 'Grammars ship with claude-db for each platform, so there is nothing to add or remove.';
4
- const stateOf = (name) => hasGrammar(name)
5
- ? 'read with real syntax'
6
- : `read by pattern: no grammar for ${PLATFORM} in this install`;
4
+ const stateOf = (name) => {
5
+ if (!GRAMMARS.includes(name))
6
+ return 'read with real syntax, built in';
7
+ return hasGrammar(name)
8
+ ? 'read with real syntax'
9
+ : `read by pattern: no grammar for ${PLATFORM} in this install`;
10
+ };
7
11
  function listLanguages() {
8
12
  console.log(`read with real syntax: ${languageNames()}`);
9
- for (const name of GRAMMARS)
10
- console.log(` ${name.padEnd(8)} ${stateOf(name)}`);
13
+ for (const { id, label } of LANGUAGES)
14
+ console.log(` ${label.padEnd(10)} ${stateOf(id)}`);
11
15
  if (GRAMMARS.some((name) => !hasGrammar(name))) {
12
16
  console.log('Reinstall claude-db to add the grammars for this platform.');
13
17
  }