claude-db 0.6.0 → 0.8.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 (49) hide show
  1. package/CHANGELOG.md +176 -0
  2. package/README.md +11 -3
  3. package/dist/capture/flush.js +0 -4
  4. package/dist/capture/index.d.ts +1 -0
  5. package/dist/capture/index.js +1 -0
  6. package/dist/capture/summarize.d.ts +3 -0
  7. package/dist/capture/summarize.js +32 -0
  8. package/dist/capture/turn-extractor.js +21 -6
  9. package/dist/cli/commands/adoption.d.ts +1 -0
  10. package/dist/cli/commands/adoption.js +94 -0
  11. package/dist/cli/commands/doctor.js +39 -0
  12. package/dist/cli/commands/setup.js +10 -0
  13. package/dist/cli/commands/view-page.d.ts +2 -0
  14. package/dist/cli/commands/view-page.js +151 -0
  15. package/dist/cli/commands/view.d.ts +23 -0
  16. package/dist/cli/commands/view.js +99 -0
  17. package/dist/cli/index.js +8 -0
  18. package/dist/cli/install.js +22 -12
  19. package/dist/cli/instructions.js +5 -4
  20. package/dist/cli/usage.js +2 -0
  21. package/dist/config/schema.d.ts +10 -0
  22. package/dist/config/schema.js +3 -0
  23. package/dist/graph/languages/basic.d.ts +11 -0
  24. package/dist/graph/languages/basic.js +156 -0
  25. package/dist/graph/languages/index.d.ts +1 -0
  26. package/dist/graph/languages/index.js +7 -4
  27. package/dist/graph/languages/ruby.d.ts +2 -0
  28. package/dist/graph/languages/ruby.js +16 -0
  29. package/dist/graph/languages/rules.d.ts +1 -0
  30. package/dist/graph/query/suggest.d.ts +0 -1
  31. package/dist/graph/query/suggest.js +2 -9
  32. package/dist/graph/scan/extract.d.ts +1 -0
  33. package/dist/graph/scan/extract.js +43 -2
  34. package/dist/graph/scan/files.d.ts +1 -1
  35. package/dist/graph/scan/files.js +3 -2
  36. package/dist/graph/scan/resolve.js +2 -0
  37. package/dist/hooks/grep-symbols.d.ts +2 -1
  38. package/dist/hooks/grep-symbols.js +14 -5
  39. package/dist/hooks/prefer-usages.js +25 -5
  40. package/dist/hooks/relevance.d.ts +4 -0
  41. package/dist/hooks/relevance.js +10 -0
  42. package/dist/hooks/session-end.js +11 -2
  43. package/dist/hooks/session-start.js +28 -2
  44. package/dist/hooks/user-prompt.js +6 -3
  45. package/dist/mcp/tools/memory.js +25 -23
  46. package/dist/mcp/tools/observations.js +32 -30
  47. package/dist/mcp/tools/search.js +13 -12
  48. package/dist/mcp/tools/usages.js +21 -20
  49. package/package.json +5 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,181 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Added
6
+
7
+ - **Every language now reaches the code graph.** Ruby is parsed properly, which
8
+ closes the gap a Rails user reported: `scan` skipped `.rb` files entirely, so
9
+ `usages` could not answer anything about a Rails codebase. Beyond that, 29
10
+ more languages — Java, C, C++, C#, Objective-C, Swift, Kotlin, Scala, PHP,
11
+ Perl, Lua, R, Julia, Dart, Elixir, Erlang, Clojure, Haskell, OCaml, F#,
12
+ Groovy, shell, PowerShell, SQL, Zig, Nim, Crystal, Solidity and Vala — are
13
+ read by a shared table of declaration patterns. That tier finds classes,
14
+ modules, functions and methods, matches references by name, and tags every
15
+ edge it produces `INFERRED`. A reference matching no declaration anywhere in
16
+ the repository produces no edge at all rather than a guess. It is less
17
+ precise than a real parse deliberately: the alternative for those languages
18
+ was nothing. Measured against ast-grep on this repository's TypeScript, the
19
+ pattern tier recovers 29% of symbols, which is why the seven parsed
20
+ languages keep their grammars.
21
+
22
+ - **`claude-db view` shows your memory in the browser.** A local page with the
23
+ memory stream, standing rules, recent sessions and live search. The server
24
+ runs only while the page is open and stops with Ctrl+C — no daemon, no
25
+ background process, nothing added to the install. `--export <file>` writes a
26
+ standalone HTML snapshot instead.
27
+
28
+ - **Session start offers `claude-db scan`** when a project has no code graph
29
+ yet, since `find_usages` and the symbol-grep hook are inert until it has run
30
+ and nothing said so.
31
+
32
+ - **Opt-in AI session summaries.** `capture.summarize: "on"` in
33
+ `~/.claude-memory/config.json` writes the end-of-session summary with your
34
+ own Claude Code CLI — no API key, no new dependency — and stores it prefixed
35
+ with `AI: ` so it is distinguishable from extracted text. It runs Opus at low
36
+ effort, which measured faster than the smaller models on this one-shot task
37
+ because nothing here needs reasoning; `capture.summarizeModel` accepts
38
+ `sonnet` or `haiku` instead. Default is `off`: capture stays deterministic
39
+ and free unless you ask otherwise, and any failure, timeout, refusal or
40
+ missing CLI silently keeps the deterministic summary.
41
+
42
+ - **House-rule linting.** `npm run lint` enforces what this codebase actually
43
+ requires and no general linter knows about: no comments in `src`, no `any`,
44
+ relative imports ending in `.js`, no leftover TODO markers, files under 250
45
+ lines, and no `console.log` in hooks, whose stdout is a protocol. It has no
46
+ dependencies. CI now runs it alongside a formatting check, which was never
47
+ enforced before.
48
+
49
+ ### Changed
50
+
51
+ - **Injected memory has to be relevant.** Search always returned its top
52
+ matches, so a prompt with no real match still got memory pasted above it —
53
+ measured at one useful injection in nine. Entries must now share at least
54
+ one content word with the prompt, which drops 16% of injections on a replay
55
+ of real sessions while keeping every match a person would call related.
56
+ Tunable with `inject.minOverlap`, `0` to switch it off. The fused search
57
+ score could not be used for this: rank fusion discards magnitude by design.
58
+
59
+ - **`decision` no longer means everything.** It covered 57% of stored
60
+ observations, which makes filtering by it pointless. Instrumenting the
61
+ classifier showed the cause was not user language but the assistant's own
62
+ narration — "verify rather than guess" — with `rather than` alone firing on
63
+ 130 of 184 decisions. Comparative phrases now only count in the user's
64
+ prompt; committed language like "chose" or "trade-off" still counts
65
+ anywhere. Measured on 321 real observations: 57% to 36%, with no true
66
+ decision reclassified. A rule buried in a long pasted prompt is also no
67
+ longer filed as a preference. Run `claude-db flush` to reclassify existing
68
+ memory in place.
69
+
70
+ - **Both injections state their cost**, ending with an approximate token
71
+ count, so the standing price of recall is visible rather than assumed.
72
+
73
+ - **`status` prints when this project was last worked in** next to when memory
74
+ last recorded something. Capture failing silently is the failure mode this
75
+ project keeps hitting; two dates side by side make it obvious.
76
+
77
+ - **`doctor` checks the wiring itself** — duplicate hook registrations and
78
+ hooks pointing at an install that no longer exists — and says when search is
79
+ running on the built-in embedder, with the two commands that upgrade it.
80
+ `install` reports the same thing, so the better option is discoverable at
81
+ the moment it is easiest to act on.
82
+
83
+ ### Fixed
84
+
85
+ - **Inherited symbols were mangled for every language.** A superclass arrived
86
+ wrapped in its own syntax, so Python recorded a class named `(Base)` and no
87
+ `extends` edge resolved. Ruby exposed it; the fix is shared.
88
+
89
+ - **Method names ending in `?` or `!`** are now valid symbols, which Ruby needs
90
+ and no other language minds.
91
+
92
+ - **AI summaries could be killed at the finish line.** The model call's timeout
93
+ matched the harness hook timeout exactly, so a slow one was terminated at the
94
+ moment it would have completed, wasting the call. It now runs with headroom.
95
+ Found before release; the feature ships opt-in either way.
96
+
97
+ - **`prettier --check` failed on committed code**, and nothing noticed because
98
+ CI never ran it. Fixed, and now enforced.
99
+
100
+ ## 0.7.0
101
+
102
+ ### Changed
103
+
104
+ - **The usages hook now directs instead of offering.** Replaying 1,871 Bash
105
+ commands from real transcripts showed the additive wording ("the grep below
106
+ still runs") produced 0% unprompted tool adoption — the graph answer arrived
107
+ and was ignored. The hook now names the grepped symbol and instructs the
108
+ agent to use `find_usages`, with the graph answer still inline so the
109
+ instruction is self-justifying.
110
+
111
+ - **Plain lowercase words count as symbols when the graph holds a real
112
+ declaration.** The symbol filter only matched camelCase, PascalCase and
113
+ snake_case, so single-word names — `search`, `forget`, `timeline`, exactly
114
+ the vocabulary a project's public surface tends to use — could never fire
115
+ the hook. Words of four or more characters now qualify, gated on resolving
116
+ to a declared function, method or class rather than a local `const`, so
117
+ greps for `value` or `result` stay silent. Measured on the replay corpus:
118
+ +9 fires, no regressions.
119
+
120
+ - **`git grep` and `rg` count as searching the tree.** Both are recursive by
121
+ default, but the hook required a `-r` flag or a path argument, so every
122
+ `git grep <symbol>` and bare `rg <symbol>` passed unseen. A piped `rg` is
123
+ still treated as output filtering. Space-separated flag values
124
+ (`rg -t ts`, `grep -A 3`) no longer confuse pattern extraction.
125
+
126
+ - **A preference's title is now the rule itself.** Titles were built from
127
+ the assistant's reasoning, so a turn that stated a standing rule while work
128
+ was in flight could be filed as a preference titled "140 checks pass" —
129
+ junk in the new session-start index. Preference titles now come from the
130
+ user's own words.
131
+
132
+ - **The installed instructions speak in the first person.** "This project has
133
+ persistent memory" reads as someone else's feature; "you have persistent
134
+ memory of this project" reads as the model's own recall. The installed
135
+ block now uses the second framing, matching how the model treats memory it
136
+ actually uses. Already-installed projects pick the new text up automatically
137
+ at the next session start.
138
+
139
+ ### Added
140
+
141
+ - **Session start injects a standing-rules index.** The model uses whatever is
142
+ already in its context and skips what costs a call, so memory it cannot see
143
+ is memory it does not use. The startup injection now lists the most recent
144
+ preference observations — one line each, with the id to expand via
145
+ `get_observations` — so recalling a standing rule becomes expanding a line
146
+ already on screen instead of discovering whether one exists. Rules recorded
147
+ explicitly with `remember` list ahead of auto-classified ones.
148
+
149
+ - **Symbol greps are blocked by default, with the graph answer in the deny
150
+ reason.** A blind A/B on a real task showed the block outperforms the
151
+ nudge: the agent pivots to `find_usages` immediately, loses no turn — the
152
+ answer it needed rides in the deny reason — and non-symbol greps pass
153
+ through untouched. `CLAUDE_DB_USAGES_HOOK=directive` keeps the softer
154
+ inject-only mode; `off` disables the hook entirely.
155
+
156
+ - **`claude-db adoption` measures whether any of this works.** It reads the
157
+ project's transcripts and reports Bash commands vs greps vs hook fires vs
158
+ memory tool calls — the grep-to-memory ratio that motivated this release,
159
+ reproducible on any project with one command.
160
+
161
+ ### Fixed
162
+
163
+ - **`claude-db install` stacked duplicate hooks whenever the install path
164
+ changed.** Registration deduped by exact command string, so reinstalling
165
+ from a new location — a repo build vs the global install, or any node
166
+ upgrade under nvm moving the global path — appended a second registration
167
+ with the same matcher: two node processes and two database opens on every
168
+ Bash call. Install now replaces its own hook entries by file name wherever
169
+ they point, and uninstall removes them from any path, not just the one it
170
+ is run from.
171
+
172
+ - **The graph could not answer for the MCP tool names themselves.**
173
+ `find_usages("forget")` returned nothing: tool names existed only as string
174
+ literals with anonymous handlers, so there was no declaration to index.
175
+ Handlers are now named functions matching their tools (`search`, `forget`,
176
+ `timeline`, `remember`, `get_observations`, `find_usages`), so the graph
177
+ answers questions about the project's own public surface.
178
+
3
179
  ## 0.6.0
4
180
 
5
181
  ### Fixed
package/README.md CHANGED
@@ -61,8 +61,10 @@ Claude then gets four modes through MCP: `text` (a live grep, works with no
61
61
  scan at all), `usages`, `explain` and `path`. Re-running `scan` is cheap: it
62
62
  hashes files and re-parses only what changed.
63
63
 
64
- Works out of the box on TypeScript, TSX, JavaScript, Python, Go and Rust. The
65
- parser ships with the package, so there is nothing else to install.
64
+ TypeScript, TSX, JavaScript, Python, Go, Rust and Ruby are parsed properly, and
65
+ every other language — Java, C, C++, C#, Swift, Kotlin, PHP, Elixir, shell and
66
+ twenty more — is read by pattern, which finds declarations and name-matched
67
+ references tagged `INFERRED`. Nothing else to install either way.
66
68
 
67
69
  ## Use another database
68
70
 
@@ -110,6 +112,7 @@ including the symbols where plain grep wins.
110
112
  | `claude-db scan [--force]` | Build the code graph for this repo |
111
113
  | `claude-db usages [--mode <m>] <symbol>` | What uses a symbol: live `git grep`, or the code graph |
112
114
  | `claude-db use <url>` | Switch database and verify it |
115
+ | `claude-db view` | See this project's memory live in the browser |
113
116
 
114
117
  Every other command, including `search`, `remember`, `seed`, `sync`, `export`,
115
118
  `prune` and `reset`, is in the [CLI reference](https://claude-db.vercel.app/docs/cli).
@@ -151,7 +154,8 @@ including the symbols where plain grep wins. Releases are in the
151
154
  ```bash
152
155
  npm install
153
156
  npm run build
154
- npm test # 326 checks
157
+ npm test # 415 checks
158
+ npm run lint # house rules: no comments, no any, import extensions
155
159
  npm run try # simulate a session, touches nothing
156
160
  npm run format
157
161
  ```
@@ -163,6 +167,10 @@ npm version patch
163
167
  git push --follow-tags
164
168
  ```
165
169
 
170
+ [CONTRIBUTING.md](./CONTRIBUTING.md) has the conventions, the test setup, and
171
+ how to add a language to the code graph. Security reports go through
172
+ [SECURITY.md](./SECURITY.md), privately.
173
+
166
174
  ## License
167
175
 
168
176
  Apache-2.0
@@ -36,10 +36,6 @@ export async function embedObservations(ctx, observations) {
36
36
  const embedder = await ctx.embedder();
37
37
  if (embedder.dimensions === 0)
38
38
  return;
39
- // ponytail: chunked because peak memory scales with the batch handed to one
40
- // forward pass, not with the database. Measured on all-MiniLM-L6-v2, 512-token
41
- // bodies: 8 -> 0.8GB, 16 -> 1.3GB, 32 -> 2.4GB, 64 -> 4.5GB, all at identical
42
- // wall-clock. Batching buys nothing on CPU, so keep it small.
43
39
  const size = ctx.config.embeddings.batchSize;
44
40
  for (let start = 0; start < observations.length; start += size) {
45
41
  const chunk = observations.slice(start, start + size);
@@ -9,3 +9,4 @@ export { observationsFromTurns, redact } from './turn-extractor.js';
9
9
  export { flushSession, resetCursor, clearCursor, sweepCursors, summarize, embedObservations, } from './flush.js';
10
10
  export type { FlushResult } from './flush.js';
11
11
  export { closeLandedWork, openWork } from './progress.js';
12
+ export { aiSummary, buildSummaryPrompt, validateSummary } from './summarize.js';
@@ -6,3 +6,4 @@ export { observationsFromGit } from './git.js';
6
6
  export { observationsFromTurns, redact } from './turn-extractor.js';
7
7
  export { flushSession, resetCursor, clearCursor, sweepCursors, summarize, embedObservations, } from './flush.js';
8
8
  export { closeLandedWork, openWork } from './progress.js';
9
+ export { aiSummary, buildSummaryPrompt, validateSummary } from './summarize.js';
@@ -0,0 +1,3 @@
1
+ export declare function buildSummaryPrompt(sessionText: string): string;
2
+ export declare function validateSummary(raw: string): string | null;
3
+ export declare function aiSummary(sessionText: string, model: string): Promise<string | null>;
@@ -0,0 +1,32 @@
1
+ import { execFile } from 'node:child_process';
2
+ const MAX_INPUT_CHARS = 8000;
3
+ const MAX_OUTPUT_CHARS = 800;
4
+ const TIMEOUT_MS = 45_000;
5
+ export function buildSummaryPrompt(sessionText) {
6
+ return ('Below are records of completed work, written by someone else. Summarize ' +
7
+ 'them in at most 3 plain sentences: what was done and why. Write only ' +
8
+ 'those sentences, with no preamble, no formatting, and no remarks about ' +
9
+ 'yourself or what you can see.\n\n' +
10
+ sessionText.slice(0, MAX_INPUT_CHARS));
11
+ }
12
+ const REFUSAL = /\b(i (don'?t|do not|cannot|can'?t)|no record|our conversation|as an ai)\b/i;
13
+ export function validateSummary(raw) {
14
+ const text = raw.trim();
15
+ if (!text || text.length >= MAX_OUTPUT_CHARS || text.includes('```'))
16
+ return null;
17
+ if (REFUSAL.test(text))
18
+ return null;
19
+ return text;
20
+ }
21
+ export async function aiSummary(sessionText, model) {
22
+ if (!sessionText.trim())
23
+ return null;
24
+ return new Promise((done) => {
25
+ try {
26
+ execFile('claude', ['-p', buildSummaryPrompt(sessionText), '--model', model, '--effort', 'low'], { timeout: TIMEOUT_MS, maxBuffer: 1024 * 1024 }, (error, stdout) => done(error ? null : validateSummary(stdout)));
27
+ }
28
+ catch {
29
+ done(null);
30
+ }
31
+ });
32
+ }
@@ -3,9 +3,14 @@ import { isSearchable } from '../util/prompt.js';
3
3
  import { currentAuthor, observationId } from './identity.js';
4
4
  export function observationsFromTurns(turns, sessionId, project, config) {
5
5
  return turns
6
+ .map(withoutPrivate)
6
7
  .filter((turn) => isSubstantive(turn, config))
7
8
  .map((turn) => buildObservation(turn, sessionId, project, config));
8
9
  }
10
+ function withoutPrivate(turn) {
11
+ const strip = (text) => text.replace(/<private>[\s\S]*?<\/private>/gi, '[private]');
12
+ return { ...turn, prompt: strip(turn.prompt), reasoning: strip(turn.reasoning) };
13
+ }
9
14
  function isSubstantive(turn, config) {
10
15
  const files = turn.files.filter((file) => !isExcluded(file, config.capture.exclude));
11
16
  const commands = turn.commands.filter((command) => classifyCommand(command) !== null);
@@ -32,14 +37,15 @@ function buildObservation(turn, sessionId, project, config) {
32
37
  .filter((line) => line !== '')
33
38
  .join('\n'), config.capture.maxBodyChars));
34
39
  const author = currentAuthor();
40
+ const kind = classifyTurn(turn);
35
41
  return {
36
42
  id: observationId(sessionId, turn.timestamp, turn.prompt),
37
43
  sessionId,
38
44
  project,
39
45
  ...(author ? { author } : {}),
40
46
  status: files.length > 0 ? 'open' : 'done',
41
- kind: classifyTurn(turn),
42
- title: redact(buildTitle(turn, files)),
47
+ kind,
48
+ title: redact(buildTitle(turn, files, kind)),
43
49
  body,
44
50
  files,
45
51
  tags: topLevelDirs(files, project),
@@ -66,7 +72,12 @@ function reports(sentence) {
66
72
  const text = sentence.replace(/\[redacted[^\]]*\]/g, '');
67
73
  return EVIDENCE.some((test) => test.test(text)) ? 1 : 0;
68
74
  }
69
- function buildTitle(turn, files) {
75
+ function buildTitle(turn, files, kind) {
76
+ if (kind === 'preference') {
77
+ const rule = firstSentence(redact(turn.prompt));
78
+ if (rule)
79
+ return headline(rule);
80
+ }
70
81
  const prose = stripMarkdown(redact(turn.reasoning));
71
82
  const scored = scoreSentences(prose);
72
83
  const best = scored.find(([, score]) => score > 0) ?? scored.find(([, score]) => score === 0);
@@ -115,13 +126,17 @@ export function topLevelDirs(files, project) {
115
126
  }
116
127
  return [...tags].slice(0, 3);
117
128
  }
129
+ const PREFERENCE_PROMPT_MAX = 600;
118
130
  export function classifyTurn(turn) {
131
+ const prompt = turn.prompt.toLowerCase();
119
132
  const text = `${turn.prompt} ${turn.reasoning}`.toLowerCase();
120
- if (/\b(from now on|going forward|remember to|prefer)\b/.test(turn.prompt.toLowerCase()) ||
121
- /\b(always|never)\s+(use|run|do|add|write|call|put|name|commit|push|import|install)\b/.test(turn.prompt.toLowerCase())) {
133
+ if (prompt.length <= PREFERENCE_PROMPT_MAX &&
134
+ (/\b(from now on|going forward|remember to|prefer)\b/.test(prompt) ||
135
+ /\b(always|never)\s+(use|run|do|add|write|call|put|name|commit|push|import|install)\b/.test(prompt))) {
122
136
  return 'preference';
123
137
  }
124
- if (/\b(instead of|rather than|in favou?r of|opted for|went with|chose|decided|trade-?off|why we)\b/.test(text)) {
138
+ if (/\b(opted for|went with|chose|settled on|decided?|decision|trade-?off|in favou?r of|why (did |do |does )?(we|i))\b/.test(text) ||
139
+ /\b(instead of|rather than)\b/.test(prompt)) {
125
140
  return 'decision';
126
141
  }
127
142
  if (/\b(didn'?t work|failed|reverted|abandoned|dead ?end|gave up|doesn'?t scale)\b/.test(text)) {
@@ -0,0 +1 @@
1
+ export declare function cmdAdoption(): Promise<void>;
@@ -0,0 +1,94 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { createContext } from '../../context.js';
3
+ import { queryGraph } from '../../graph/index.js';
4
+ import { transcriptsFor } from '../../capture/transcript.js';
5
+ import { resolveProject } from '../../util/project.js';
6
+ import { DECLARED, isSymbol, symbolsGreppedIn } from '../../hooks/grep-symbols.js';
7
+ export async function cmdAdoption() {
8
+ const project = resolveProject(undefined);
9
+ const files = transcriptsFor(project);
10
+ if (files.length === 0) {
11
+ console.log(`No transcripts found for ${project}.`);
12
+ return;
13
+ }
14
+ const seen = new Set();
15
+ const bash = [];
16
+ const memory = new Map();
17
+ for (const file of files) {
18
+ for (const line of readFileSync(file, 'utf8').split('\n')) {
19
+ if (!line.includes('"tool_use"'))
20
+ continue;
21
+ let entry;
22
+ try {
23
+ entry = JSON.parse(line);
24
+ }
25
+ catch {
26
+ continue;
27
+ }
28
+ const content = entry?.message?.content;
29
+ if (!Array.isArray(content))
30
+ continue;
31
+ for (const item of content) {
32
+ if (item?.type !== 'tool_use' || typeof item.id !== 'string' || seen.has(item.id))
33
+ continue;
34
+ seen.add(item.id);
35
+ const name = typeof item.name === 'string' ? item.name : '';
36
+ if (name === 'Bash' && typeof item.input?.command === 'string') {
37
+ bash.push(item.input.command);
38
+ }
39
+ if (name.startsWith('mcp__memory__')) {
40
+ const tool = name.slice('mcp__memory__'.length);
41
+ memory.set(tool, (memory.get(tool) ?? 0) + 1);
42
+ }
43
+ }
44
+ }
45
+ }
46
+ const greps = bash.filter((command) => /\b(?:grep|rg)\b/.test(command));
47
+ 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
+ }
77
+ const memoryTotal = [...memory.values()].reduce((a, b) => a + b, 0);
78
+ const pct = (n, of) => (of === 0 ? '0.0%' : `${((n / of) * 100).toFixed(1)}%`);
79
+ console.log(`Adoption for ${project} (${files.length} transcripts)\n`);
80
+ console.log(` Bash commands ${bash.length}`);
81
+ console.log(` containing grep/rg ${greps.length} (${pct(greps.length, bash.length)})`);
82
+ console.log(` usages-hook candidates ${candidates.length}`);
83
+ console.log(` would fire today ${fires} (${pct(fires, bash.length)} of all commands)`);
84
+ console.log(`\n memory tool calls ${memoryTotal}`);
85
+ for (const [tool, count] of [...memory].sort((a, b) => b[1] - a[1])) {
86
+ console.log(` ${tool.padEnd(18)} ${count}`);
87
+ }
88
+ if (greps.length > 0) {
89
+ const ratio = memoryTotal === 0
90
+ ? 'no memory calls yet'
91
+ : `${(greps.length / memoryTotal).toFixed(1)} greps per memory call`;
92
+ console.log(`\n ${ratio}`);
93
+ }
94
+ }
@@ -4,6 +4,8 @@ import { packageVersion } from '../../update.js';
4
4
  import { randomUUID } from 'node:crypto';
5
5
  import { remember } from '../../capture/index.js';
6
6
  import { resolveProject } from '../../util/project.js';
7
+ import { settingsPathFor } from '../paths.js';
8
+ import { existsSync, readFileSync } from 'node:fs';
7
9
  import { toShortId } from '../../util/shortid.js';
8
10
  export async function cmdDoctor(argv) {
9
11
  const base = loadConfig();
@@ -21,10 +23,47 @@ export async function cmdDoctor(argv) {
21
23
  console.log(`embedder : ${embedder.id} (${embedder.dimensions}d)`);
22
24
  console.log(`vectors : ${vectors}`);
23
25
  console.log(`search : ${vectors.startsWith('working') ? 'hybrid (keyword + vector)' : 'keyword only'}`);
26
+ if (embedder.id === 'builtin-hashing') {
27
+ console.log('hint : builtin embeddings are keyword-grade. For semantic vectors:');
28
+ console.log(' npm i -g @xenova/transformers && claude-db reembed');
29
+ }
30
+ checkWiring(resolveProject(undefined));
24
31
  const healthy = argv.includes('--deep') ? await deepCheck(ctx) : true;
25
32
  await ctx.close();
26
33
  process.exit(reachable && healthy ? 0 : 1);
27
34
  }
35
+ function checkWiring(project) {
36
+ const problems = [];
37
+ for (const scope of ['project', 'global']) {
38
+ const path = settingsPathFor(scope, project);
39
+ let settings;
40
+ try {
41
+ settings = JSON.parse(readFileSync(path, 'utf8'));
42
+ }
43
+ catch {
44
+ continue;
45
+ }
46
+ for (const [event, entries] of Object.entries(settings.hooks ?? {})) {
47
+ const ours = entries
48
+ .flatMap((entry) => entry.hooks.map((hook) => hook.command))
49
+ .filter((command) => /[\\/]hooks[\\/](session-start|session-end|user-prompt|prefer-usages)\.js$/.test(command.replace(/\\/g, '/')));
50
+ if (ours.length > 1)
51
+ problems.push(`${event} registered ${ours.length}x in ${path}`);
52
+ for (const command of ours) {
53
+ const file = command.replace(/^node\s+/, '');
54
+ if (!existsSync(file))
55
+ problems.push(`${event} points at missing ${file}`);
56
+ }
57
+ }
58
+ }
59
+ if (problems.length === 0) {
60
+ console.log('wiring : ok');
61
+ return;
62
+ }
63
+ for (const problem of problems)
64
+ console.log(`wiring : PROBLEM — ${problem}`);
65
+ console.log(' fix with: claude-db install (it replaces its own entries)');
66
+ }
28
67
  async function deepCheck(ctx) {
29
68
  const project = resolveProject(undefined);
30
69
  const canary = `zz${randomUUID().replace(/-/g, '')}`;
@@ -20,6 +20,7 @@ export async function cmdInstall(scope) {
20
20
  }
21
21
  const settingsPath = install(DIST_DIR, scope, project);
22
22
  const ctx = await createContext();
23
+ const embedder = await ctx.embedder();
23
24
  await ctx.close();
24
25
  console.log(`Scope : ${scope === 'project' ? `this project only (${project})` : 'all projects on this machine'}`);
25
26
  console.log(`Settings : ${settingsPath}`);
@@ -27,6 +28,14 @@ export async function cmdInstall(scope) {
27
28
  console.log(`Skill : ${skillPathFor(scope, project)} (/cdb-scan)`);
28
29
  console.log(`Config : ${CONFIG_PATH}`);
29
30
  console.log(`Database : ${ctx.config.database}`);
31
+ if (embedder.id === 'builtin-hashing') {
32
+ console.log('Search : keyword + basic vectors');
33
+ console.log(' for semantic search: npm i -g @xenova/transformers');
34
+ console.log(' then: claude-db reembed');
35
+ }
36
+ else {
37
+ console.log(`Search : keyword + semantic vectors (${embedder.id})`);
38
+ }
30
39
  console.log('\nRestart Claude Code to activate.');
31
40
  if (scope === 'project') {
32
41
  warnIfCommittable(project);
@@ -82,6 +91,7 @@ export async function cmdStatus() {
82
91
  const saved = (await ctx.store.listProjects()).find((entry) => entry.project === project);
83
92
  const lastSaved = saved?.lastActive ?? 0;
84
93
  const worked = workedAt(project);
94
+ console.log(`worked : ${worked.last > 0 ? ago(worked.last) : 'never'}`);
85
95
  console.log(`recorded : ${lastSaved > 0 ? ago(lastSaved) : 'never'}`);
86
96
  await closeLandedWork(ctx.store, project);
87
97
  const open = await openWork(ctx.store, project);
@@ -0,0 +1,2 @@
1
+ import type { ViewData } from './view.js';
2
+ export declare function renderPage(data: ViewData, live: boolean): string;