claude-db 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +126 -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 +12 -3
  9. package/dist/cli/commands/adoption.js +8 -2
  10. package/dist/cli/commands/doctor.js +39 -0
  11. package/dist/cli/commands/memory.js +22 -1
  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 +4 -0
  18. package/dist/cli/install.js +9 -3
  19. package/dist/cli/usage.js +2 -0
  20. package/dist/config/schema.d.ts +11 -0
  21. package/dist/config/schema.js +4 -0
  22. package/dist/graph/languages/basic.d.ts +11 -0
  23. package/dist/graph/languages/basic.js +156 -0
  24. package/dist/graph/languages/index.d.ts +1 -0
  25. package/dist/graph/languages/index.js +7 -4
  26. package/dist/graph/languages/ruby.d.ts +2 -0
  27. package/dist/graph/languages/ruby.js +16 -0
  28. package/dist/graph/languages/rules.d.ts +1 -0
  29. package/dist/graph/query/suggest.d.ts +0 -1
  30. package/dist/graph/query/suggest.js +2 -9
  31. package/dist/graph/scan/extract.d.ts +1 -0
  32. package/dist/graph/scan/extract.js +43 -2
  33. package/dist/graph/scan/files.d.ts +1 -1
  34. package/dist/graph/scan/files.js +3 -2
  35. package/dist/graph/scan/resolve.js +2 -0
  36. package/dist/hooks/grep-symbols.d.ts +0 -1
  37. package/dist/hooks/grep-symbols.js +5 -5
  38. package/dist/hooks/payload.d.ts +1 -0
  39. package/dist/hooks/payload.js +5 -0
  40. package/dist/hooks/relevance.d.ts +4 -0
  41. package/dist/hooks/relevance.js +10 -0
  42. package/dist/hooks/session-end.js +15 -3
  43. package/dist/hooks/session-start.js +9 -2
  44. package/dist/hooks/user-prompt.js +10 -4
  45. package/dist/mcp/tools/observations.js +1 -1
  46. package/dist/store/adapter.d.ts +1 -0
  47. package/dist/store/mongo/index.d.ts +1 -0
  48. package/dist/store/mongo/index.js +3 -0
  49. package/dist/store/mongo/sessions.d.ts +1 -0
  50. package/dist/store/mongo/sessions.js +4 -0
  51. package/dist/store/postgres/index.d.ts +1 -0
  52. package/dist/store/postgres/index.js +3 -0
  53. package/dist/store/postgres/sessions.d.ts +1 -0
  54. package/dist/store/postgres/sessions.js +4 -0
  55. package/dist/store/sqlite/index.d.ts +1 -0
  56. package/dist/store/sqlite/index.js +3 -0
  57. package/dist/store/sqlite/sessions.d.ts +1 -0
  58. package/dist/store/sqlite/sessions.js +6 -0
  59. package/package.json +5 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,131 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Fixed
6
+
7
+ - **A wrong session summary could not be corrected, and kept teaching itself.**
8
+ Summaries are injected at every session start, but nothing could delete one:
9
+ the upsert coalesces a null summary to the existing value, so a summary was
10
+ write-once in practice. One carrying a false claim was therefore re-injected
11
+ into every new session, restated as fact, and captured back as fresh
12
+ observations that outranked the correction — memory records what was said,
13
+ not what is true, so a wrong statement gains credibility by being repeated.
14
+ `claude-db forget --session <id>` now clears one, on all three backends,
15
+ after which it stops being served. Clearing reports whether anything actually
16
+ changed, so the adapters agree rather than SQLite and Postgres counting a
17
+ matched row where MongoDB counted a change.
18
+
19
+ - **Scripted sessions are no longer captured by default.** A headless run —
20
+ a test harness, a cron job, anything driving `claude -p` — writes memory that
21
+ looks like your work but is not, and a fabricated test fixture becoming
22
+ project knowledge is exactly how the summary above was poisoned. Claude Code
23
+ identifies those sessions as `sdk-cli`, and they are now skipped.
24
+ `capture.scripted: true` captures them anyway, for anyone whose real work
25
+ runs through the SDK.
26
+
27
+ Detection has one blind spot worth stating: a `claude -p` spawned from inside
28
+ another Claude session inherits the parent's entrypoint and is
29
+ indistinguishable from it. `CLAUDE_DB_CAPTURE=off` covers that case and any
30
+ other session that should stay unrecorded, while leaving recall working.
31
+
32
+ ## 0.8.0
33
+
34
+ ### Added
35
+
36
+ - **Every language now reaches the code graph.** Ruby is parsed properly, which
37
+ closes the gap a Rails user reported: `scan` skipped `.rb` files entirely, so
38
+ `usages` could not answer anything about a Rails codebase. Beyond that, 29
39
+ more languages — Java, C, C++, C#, Objective-C, Swift, Kotlin, Scala, PHP,
40
+ Perl, Lua, R, Julia, Dart, Elixir, Erlang, Clojure, Haskell, OCaml, F#,
41
+ Groovy, shell, PowerShell, SQL, Zig, Nim, Crystal, Solidity and Vala — are
42
+ read by a shared table of declaration patterns. That tier finds classes,
43
+ modules, functions and methods, matches references by name, and tags every
44
+ edge it produces `INFERRED`. A reference matching no declaration anywhere in
45
+ the repository produces no edge at all rather than a guess. It is less
46
+ precise than a real parse deliberately: the alternative for those languages
47
+ was nothing. Measured against ast-grep on this repository's TypeScript, the
48
+ pattern tier recovers 29% of symbols, which is why the seven parsed
49
+ languages keep their grammars.
50
+
51
+ - **`claude-db view` shows your memory in the browser.** A local page with the
52
+ memory stream, standing rules, recent sessions and live search. The server
53
+ runs only while the page is open and stops with Ctrl+C — no daemon, no
54
+ background process, nothing added to the install. `--export <file>` writes a
55
+ standalone HTML snapshot instead.
56
+
57
+ - **Session start offers `claude-db scan`** when a project has no code graph
58
+ yet, since `find_usages` and the symbol-grep hook are inert until it has run
59
+ and nothing said so.
60
+
61
+ - **Opt-in AI session summaries.** `capture.summarize: "on"` in
62
+ `~/.claude-memory/config.json` writes the end-of-session summary with your
63
+ own Claude Code CLI — no API key, no new dependency — and stores it prefixed
64
+ with `AI: ` so it is distinguishable from extracted text. It runs Opus at low
65
+ effort, which measured faster than the smaller models on this one-shot task
66
+ because nothing here needs reasoning; `capture.summarizeModel` accepts
67
+ `sonnet` or `haiku` instead. Default is `off`: capture stays deterministic
68
+ and free unless you ask otherwise, and any failure, timeout, refusal or
69
+ missing CLI silently keeps the deterministic summary.
70
+
71
+ - **House-rule linting.** `npm run lint` enforces what this codebase actually
72
+ requires and no general linter knows about: no comments in `src`, no `any`,
73
+ relative imports ending in `.js`, no leftover TODO markers, files under 250
74
+ lines, and no `console.log` in hooks, whose stdout is a protocol. It has no
75
+ dependencies. CI now runs it alongside a formatting check, which was never
76
+ enforced before.
77
+
78
+ ### Changed
79
+
80
+ - **Injected memory has to be relevant.** Search always returned its top
81
+ matches, so a prompt with no real match still got memory pasted above it —
82
+ measured at one useful injection in nine. Entries must now share at least
83
+ one content word with the prompt, which drops 16% of injections on a replay
84
+ of real sessions while keeping every match a person would call related.
85
+ Tunable with `inject.minOverlap`, `0` to switch it off. The fused search
86
+ score could not be used for this: rank fusion discards magnitude by design.
87
+
88
+ - **`decision` no longer means everything.** It covered 57% of stored
89
+ observations, which makes filtering by it pointless. Instrumenting the
90
+ classifier showed the cause was not user language but the assistant's own
91
+ narration — "verify rather than guess" — with `rather than` alone firing on
92
+ 130 of 184 decisions. Comparative phrases now only count in the user's
93
+ prompt; committed language like "chose" or "trade-off" still counts
94
+ anywhere. Measured on 321 real observations: 57% to 36%, with no true
95
+ decision reclassified. A rule buried in a long pasted prompt is also no
96
+ longer filed as a preference. Run `claude-db flush` to reclassify existing
97
+ memory in place.
98
+
99
+ - **Both injections state their cost**, ending with an approximate token
100
+ count, so the standing price of recall is visible rather than assumed.
101
+
102
+ - **`status` prints when this project was last worked in** next to when memory
103
+ last recorded something. Capture failing silently is the failure mode this
104
+ project keeps hitting; two dates side by side make it obvious.
105
+
106
+ - **`doctor` checks the wiring itself** — duplicate hook registrations and
107
+ hooks pointing at an install that no longer exists — and says when search is
108
+ running on the built-in embedder, with the two commands that upgrade it.
109
+ `install` reports the same thing, so the better option is discoverable at
110
+ the moment it is easiest to act on.
111
+
112
+ ### Fixed
113
+
114
+ - **Inherited symbols were mangled for every language.** A superclass arrived
115
+ wrapped in its own syntax, so Python recorded a class named `(Base)` and no
116
+ `extends` edge resolved. Ruby exposed it; the fix is shared.
117
+
118
+ - **Method names ending in `?` or `!`** are now valid symbols, which Ruby needs
119
+ and no other language minds.
120
+
121
+ - **AI summaries could be killed at the finish line.** The model call's timeout
122
+ matched the harness hook timeout exactly, so a slow one was terminated at the
123
+ moment it would have completed, wasting the call. It now runs with headroom.
124
+ Found before release; the feature ships opt-in either way.
125
+
126
+ - **`prettier --check` failed on committed code**, and nothing noticed because
127
+ CI never ran it. Fixed, and now enforced.
128
+
3
129
  ## 0.7.0
4
130
 
5
131
  ### Changed
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);
@@ -121,13 +126,17 @@ export function topLevelDirs(files, project) {
121
126
  }
122
127
  return [...tags].slice(0, 3);
123
128
  }
129
+ const PREFERENCE_PROMPT_MAX = 600;
124
130
  export function classifyTurn(turn) {
131
+ const prompt = turn.prompt.toLowerCase();
125
132
  const text = `${turn.prompt} ${turn.reasoning}`.toLowerCase();
126
- if (/\b(from now on|going forward|remember to|prefer)\b/.test(turn.prompt.toLowerCase()) ||
127
- /\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))) {
128
136
  return 'preference';
129
137
  }
130
- 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)) {
131
140
  return 'decision';
132
141
  }
133
142
  if (/\b(didn'?t work|failed|reverted|abandoned|dead ?end|gave up|doesn'?t scale)\b/.test(text)) {
@@ -54,7 +54,11 @@ export async function cmdAdoption() {
54
54
  for (const symbol of symbols.slice(0, 2)) {
55
55
  let fired = cache.get(symbol);
56
56
  if (fired === undefined) {
57
- const answer = await queryGraph(ctx.store, project, { mode: 'usages', symbol, limit: 20 });
57
+ const answer = await queryGraph(ctx.store, project, {
58
+ mode: 'usages',
59
+ symbol,
60
+ limit: 20,
61
+ });
58
62
  fired =
59
63
  !answer.empty &&
60
64
  (isSymbol(symbol) || answer.definitions.some((d) => DECLARED.has(d.kind)));
@@ -82,7 +86,9 @@ export async function cmdAdoption() {
82
86
  console.log(` ${tool.padEnd(18)} ${count}`);
83
87
  }
84
88
  if (greps.length > 0) {
85
- const ratio = memoryTotal === 0 ? 'no memory calls yet' : `${(greps.length / memoryTotal).toFixed(1)} greps per memory call`;
89
+ const ratio = memoryTotal === 0
90
+ ? 'no memory calls yet'
91
+ : `${(greps.length / memoryTotal).toFixed(1)} greps per memory call`;
86
92
  console.log(`\n ${ratio}`);
87
93
  }
88
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, '')}`;
@@ -57,9 +57,14 @@ export async function cmdRemember(argv) {
57
57
  }
58
58
  }
59
59
  export async function cmdForget(argv) {
60
- const ids = argv.filter((arg) => typeof arg === 'string' && arg.length > 0);
60
+ const args = argv.filter((arg) => typeof arg === 'string' && arg.length > 0);
61
+ const sessionAt = args.indexOf('--session');
62
+ const ids = sessionAt >= 0 ? [] : args;
63
+ if (sessionAt >= 0)
64
+ return forgetSummary(args[sessionAt + 1]);
61
65
  if (ids.length === 0) {
62
66
  console.error('Usage: claude-db forget <id> [id...]');
67
+ console.error(' claude-db forget --session <session-id>');
63
68
  process.exit(1);
64
69
  }
65
70
  const ctx = await createContext();
@@ -75,3 +80,19 @@ export async function cmdForget(argv) {
75
80
  await ctx.close();
76
81
  }
77
82
  }
83
+ async function forgetSummary(sessionId) {
84
+ if (!sessionId) {
85
+ console.error('Usage: claude-db forget --session <session-id>');
86
+ process.exit(1);
87
+ }
88
+ const ctx = await createContext();
89
+ try {
90
+ const cleared = await ctx.store.clearSummary(sessionId);
91
+ console.log(cleared
92
+ ? `Cleared the summary for session ${sessionId}. It will no longer be injected.`
93
+ : `No session ${sessionId}, or it had no summary.`);
94
+ }
95
+ finally {
96
+ await ctx.close();
97
+ }
98
+ }
@@ -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;
@@ -0,0 +1,151 @@
1
+ export function renderPage(data, live) {
2
+ const payload = JSON.stringify({ ...data, live }).replace(/</g, '\\u003c');
3
+ return `<!doctype html>
4
+ <html lang="en">
5
+ <head>
6
+ <meta charset="utf-8">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1">
8
+ <title>claude-db · memory</title>
9
+ <style>
10
+ :root {
11
+ --bg: #FAFAF7; --grid: #E7E5DC; --ink: #26231F; --muted: #6E6A62;
12
+ --accent: #C0532F; --surface: #FFFFFF; --line: #D8D5CC;
13
+ }
14
+ @media (prefers-color-scheme: dark) {
15
+ :root {
16
+ --bg: #1B1A18; --grid: #26241F; --ink: #E8E5DF; --muted: #9B968C;
17
+ --accent: #D96B45; --surface: #232120; --line: #3A372F;
18
+ }
19
+ }
20
+ * { box-sizing: border-box; }
21
+ body {
22
+ margin: 0; color: var(--ink); font: 15px/1.55 ui-sans-serif, system-ui, sans-serif;
23
+ background: linear-gradient(var(--grid) 1px, transparent 1px),
24
+ linear-gradient(90deg, var(--grid) 1px, transparent 1px), var(--bg);
25
+ background-size: 28px 28px;
26
+ }
27
+ main { max-width: 860px; margin: 0 auto; padding: 32px 20px 80px; }
28
+ h1 { font: 700 22px/1.2 ui-monospace, monospace; margin: 0; }
29
+ h2 { font: 600 12px/1 ui-monospace, monospace; letter-spacing: 0.1em;
30
+ text-transform: uppercase; color: var(--muted); margin: 28px 0 10px; }
31
+ .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
32
+ .chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
33
+ .chip { background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
34
+ padding: 3px 12px; font: 500 12px ui-monospace, monospace; }
35
+ .chip b { color: var(--accent); }
36
+ .card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; }
37
+ .row { display: flex; gap: 12px; align-items: baseline; padding: 9px 14px;
38
+ border-bottom: 1px solid var(--line); }
39
+ .row:last-child { border-bottom: none; }
40
+ .kind { font: 500 11px ui-monospace, monospace; color: var(--accent); min-width: 76px; }
41
+ .when { font: 400 11px ui-monospace, monospace; color: var(--muted); min-width: 84px;
42
+ font-variant-numeric: tabular-nums; }
43
+ .title { flex: 1; min-width: 0; overflow-wrap: break-word; }
44
+ .id { font: 400 11px ui-monospace, monospace; color: var(--muted); }
45
+ input {
46
+ width: 100%; padding: 10px 14px; font: inherit; color: inherit;
47
+ background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
48
+ }
49
+ input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
50
+ .live { color: var(--accent); font: 600 11px ui-monospace, monospace; }
51
+ .empty { padding: 12px 14px; color: var(--muted); font-size: 13.5px; }
52
+ </style>
53
+ </head>
54
+ <body>
55
+ <main>
56
+ <h1>claude-db <span class="live" id="live"></span></h1>
57
+ <div class="meta" id="meta"></div>
58
+ <div class="chips" id="chips"></div>
59
+
60
+ <h2>Search memory</h2>
61
+ <input id="q" type="search" placeholder="why is … / what did we decide about …" autocomplete="off">
62
+ <div class="card" id="results" style="margin-top:10px; display:none"></div>
63
+
64
+ <h2>Standing rules</h2>
65
+ <div class="card" id="rules"></div>
66
+
67
+ <h2>Recent sessions</h2>
68
+ <div class="card" id="sessions"></div>
69
+
70
+ <h2>Memory stream</h2>
71
+ <div class="card" id="stream"></div>
72
+ </main>
73
+ <script id="data" type="application/json">${payload}</script>
74
+ <script>
75
+ let data = JSON.parse(document.getElementById('data').textContent);
76
+ const el = (id) => document.getElementById(id);
77
+ const when = (t) => new Date(t).toISOString().slice(0, 16).replace('T', ' ');
78
+ function row(parts) {
79
+ const div = document.createElement('div');
80
+ div.className = 'row';
81
+ for (const [cls, text] of parts) {
82
+ const span = document.createElement('span');
83
+ span.className = cls;
84
+ span.textContent = text;
85
+ div.appendChild(span);
86
+ }
87
+ return div;
88
+ }
89
+ function fill(id, rows, emptyText) {
90
+ const box = el(id);
91
+ box.textContent = '';
92
+ if (rows.length === 0) {
93
+ const d = document.createElement('div');
94
+ d.className = 'empty';
95
+ d.textContent = emptyText;
96
+ box.appendChild(d);
97
+ return;
98
+ }
99
+ for (const r of rows) box.appendChild(r);
100
+ }
101
+ function render() {
102
+ el('live').textContent = data.live ? '· live' : '· snapshot';
103
+ el('meta').textContent = data.project + ' · ' + data.database +
104
+ ' · code graph: ' + (data.scannedFiles > 0 ? data.scannedFiles + ' files scanned' : 'not built');
105
+ el('chips').textContent = '';
106
+ for (const [kind, count] of Object.entries(data.kinds).sort((a, b) => b[1] - a[1])) {
107
+ const chip = document.createElement('span');
108
+ chip.className = 'chip';
109
+ const b = document.createElement('b');
110
+ b.textContent = String(count);
111
+ chip.appendChild(b);
112
+ chip.appendChild(document.createTextNode(' ' + kind));
113
+ el('chips').appendChild(chip);
114
+ }
115
+ fill('rules', data.rules.map((r) => row([["when", when(r.when).slice(0, 10)], ["title", r.title], ["id", r.id]])), 'No standing rules recorded yet.');
116
+ fill('sessions', data.sessions.map((s) => row([["when", when(s.when)], ["title", s.summary || '(no summary yet)']])), 'No sessions recorded yet.');
117
+ fill('stream', data.observations.map((o) => row([["kind", o.kind], ["when", when(o.when)], ["title", o.title], ["id", o.id]])), 'Nothing captured yet — memory is written as you work.');
118
+ }
119
+ render();
120
+
121
+ if (data.live) {
122
+ setInterval(async () => {
123
+ try {
124
+ const fresh = await (await fetch('/api/data')).json();
125
+ data = Object.assign(fresh, { live: true });
126
+ render();
127
+ } catch {}
128
+ }, 5000);
129
+
130
+ let timer;
131
+ el('q').addEventListener('input', () => {
132
+ clearTimeout(timer);
133
+ timer = setTimeout(async () => {
134
+ const q = el('q').value.trim();
135
+ const box = el('results');
136
+ if (q.length < 3) { box.style.display = 'none'; return; }
137
+ try {
138
+ const hits = await (await fetch('/api/search?q=' + encodeURIComponent(q))).json();
139
+ box.style.display = '';
140
+ fill('results', hits.map((h) => row([["kind", h.kind], ["when", when(h.when).slice(0, 10)], ["title", h.title], ["id", h.id]])), 'No matches.');
141
+ } catch {}
142
+ }, 250);
143
+ });
144
+ } else {
145
+ el('q').placeholder = 'search needs the live viewer: claude-db view';
146
+ el('q').disabled = true;
147
+ }
148
+ </script>
149
+ </body>
150
+ </html>`;
151
+ }
@@ -0,0 +1,23 @@
1
+ export interface ViewData {
2
+ project: string;
3
+ database: string;
4
+ scannedFiles: number;
5
+ kinds: Record<string, number>;
6
+ rules: {
7
+ id: string;
8
+ when: number;
9
+ title: string;
10
+ }[];
11
+ sessions: {
12
+ when: number;
13
+ summary: string;
14
+ }[];
15
+ observations: {
16
+ id: string;
17
+ kind: string;
18
+ when: number;
19
+ title: string;
20
+ files: number;
21
+ }[];
22
+ }
23
+ export declare function cmdView(args: (string | undefined)[]): Promise<void>;