claude-db 0.7.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.
- package/CHANGELOG.md +97 -0
- package/README.md +11 -3
- package/dist/capture/flush.js +0 -4
- package/dist/capture/index.d.ts +1 -0
- package/dist/capture/index.js +1 -0
- package/dist/capture/summarize.d.ts +3 -0
- package/dist/capture/summarize.js +32 -0
- package/dist/capture/turn-extractor.js +12 -3
- package/dist/cli/commands/adoption.js +8 -2
- package/dist/cli/commands/doctor.js +39 -0
- package/dist/cli/commands/setup.js +10 -0
- package/dist/cli/commands/view-page.d.ts +2 -0
- package/dist/cli/commands/view-page.js +151 -0
- package/dist/cli/commands/view.d.ts +23 -0
- package/dist/cli/commands/view.js +99 -0
- package/dist/cli/index.js +4 -0
- package/dist/cli/install.js +9 -3
- package/dist/cli/usage.js +1 -0
- package/dist/config/schema.d.ts +10 -0
- package/dist/config/schema.js +3 -0
- package/dist/graph/languages/basic.d.ts +11 -0
- package/dist/graph/languages/basic.js +156 -0
- package/dist/graph/languages/index.d.ts +1 -0
- package/dist/graph/languages/index.js +7 -4
- package/dist/graph/languages/ruby.d.ts +2 -0
- package/dist/graph/languages/ruby.js +16 -0
- package/dist/graph/languages/rules.d.ts +1 -0
- package/dist/graph/query/suggest.d.ts +0 -1
- package/dist/graph/query/suggest.js +2 -9
- package/dist/graph/scan/extract.d.ts +1 -0
- package/dist/graph/scan/extract.js +43 -2
- package/dist/graph/scan/files.d.ts +1 -1
- package/dist/graph/scan/files.js +3 -2
- package/dist/graph/scan/resolve.js +2 -0
- package/dist/hooks/grep-symbols.d.ts +0 -1
- package/dist/hooks/grep-symbols.js +5 -5
- package/dist/hooks/relevance.d.ts +4 -0
- package/dist/hooks/relevance.js +10 -0
- package/dist/hooks/session-end.js +11 -2
- package/dist/hooks/session-start.js +9 -2
- package/dist/hooks/user-prompt.js +6 -3
- package/dist/mcp/tools/observations.js +1 -1
- package/package.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,102 @@
|
|
|
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
|
+
|
|
3
100
|
## 0.7.0
|
|
4
101
|
|
|
5
102
|
### 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
|
-
|
|
65
|
-
|
|
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 #
|
|
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
|
package/dist/capture/flush.js
CHANGED
|
@@ -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);
|
package/dist/capture/index.d.ts
CHANGED
|
@@ -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';
|
package/dist/capture/index.js
CHANGED
|
@@ -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,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 (
|
|
127
|
-
/\b(
|
|
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(
|
|
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, {
|
|
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
|
|
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, '')}`;
|
|
@@ -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,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>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createServer } from 'node:http';
|
|
2
|
+
import { execFile } from 'node:child_process';
|
|
3
|
+
import { writeFileSync } from 'node:fs';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { createContext } from '../../context.js';
|
|
6
|
+
import { resolveProject } from '../../util/project.js';
|
|
7
|
+
import { toShortId } from '../../util/shortid.js';
|
|
8
|
+
import { renderPage } from './view-page.js';
|
|
9
|
+
async function collect(ctx, project) {
|
|
10
|
+
const all = (await ctx.store.list({ project, limit: 500 })).sort((a, b) => b.createdAt - a.createdAt);
|
|
11
|
+
const kinds = {};
|
|
12
|
+
for (const obs of all)
|
|
13
|
+
kinds[obs.kind] = (kinds[obs.kind] ?? 0) + 1;
|
|
14
|
+
const rules = all
|
|
15
|
+
.filter((obs) => obs.kind === 'preference')
|
|
16
|
+
.sort((a, b) => {
|
|
17
|
+
const manual = Number(b.sessionId === 'manual') - Number(a.sessionId === 'manual');
|
|
18
|
+
return manual !== 0 ? manual : b.createdAt - a.createdAt;
|
|
19
|
+
})
|
|
20
|
+
.slice(0, 10)
|
|
21
|
+
.map((obs) => ({ id: toShortId(obs.id), when: obs.createdAt, title: obs.title }));
|
|
22
|
+
const sessions = (await ctx.store.recentSessions(project, 8)).map((session) => ({
|
|
23
|
+
when: session.startedAt,
|
|
24
|
+
summary: session.summary ?? '',
|
|
25
|
+
}));
|
|
26
|
+
return {
|
|
27
|
+
project,
|
|
28
|
+
database: ctx.config.database,
|
|
29
|
+
scannedFiles: (await ctx.store.scannedFiles(project)).length,
|
|
30
|
+
kinds,
|
|
31
|
+
rules,
|
|
32
|
+
sessions,
|
|
33
|
+
observations: all.slice(0, 80).map((obs) => ({
|
|
34
|
+
id: toShortId(obs.id),
|
|
35
|
+
kind: obs.kind,
|
|
36
|
+
when: obs.createdAt,
|
|
37
|
+
title: obs.title,
|
|
38
|
+
files: obs.files.length,
|
|
39
|
+
})),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export async function cmdView(args) {
|
|
43
|
+
const project = resolveProject(undefined);
|
|
44
|
+
const ctx = await createContext();
|
|
45
|
+
const exportAt = args.indexOf('--export');
|
|
46
|
+
if (exportAt >= 0) {
|
|
47
|
+
const target = resolve(args[exportAt + 1] ?? 'claude-db-memory.html');
|
|
48
|
+
writeFileSync(target, renderPage(await collect(ctx, project), false));
|
|
49
|
+
await ctx.close();
|
|
50
|
+
console.log(`Wrote snapshot to ${target}`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const server = createServer(async (req, res) => {
|
|
54
|
+
try {
|
|
55
|
+
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
56
|
+
if (url.pathname === '/api/data') {
|
|
57
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
58
|
+
res.end(JSON.stringify(await collect(ctx, project)));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (url.pathname === '/api/search') {
|
|
62
|
+
const query = url.searchParams.get('q') ?? '';
|
|
63
|
+
const entries = await ctx.search.search({ text: query, project, limit: 20 });
|
|
64
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
65
|
+
res.end(JSON.stringify(entries.map((entry) => ({
|
|
66
|
+
id: toShortId(entry.id),
|
|
67
|
+
kind: entry.kind,
|
|
68
|
+
when: entry.createdAt,
|
|
69
|
+
title: entry.title,
|
|
70
|
+
}))));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
|
|
74
|
+
res.end(renderPage(await collect(ctx, project), true));
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
res.writeHead(500, { 'content-type': 'text/plain' });
|
|
78
|
+
res.end(error instanceof Error ? error.message : String(error));
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
server.listen(0, '127.0.0.1', () => {
|
|
82
|
+
const address = server.address();
|
|
83
|
+
const port = typeof address === 'object' && address ? address.port : 0;
|
|
84
|
+
const url = `http://127.0.0.1:${port}`;
|
|
85
|
+
console.log(`Viewing ${project}`);
|
|
86
|
+
console.log(` ${url} (Ctrl+C to stop — nothing keeps running afterwards)`);
|
|
87
|
+
if (process.platform === 'darwin')
|
|
88
|
+
execFile('open', [url], () => { });
|
|
89
|
+
else if (process.platform === 'linux')
|
|
90
|
+
execFile('xdg-open', [url], () => { });
|
|
91
|
+
});
|
|
92
|
+
const stop = async () => {
|
|
93
|
+
server.close();
|
|
94
|
+
await ctx.close();
|
|
95
|
+
process.exit(0);
|
|
96
|
+
};
|
|
97
|
+
process.on('SIGINT', () => void stop());
|
|
98
|
+
process.on('SIGTERM', () => void stop());
|
|
99
|
+
}
|
package/dist/cli/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { cmdFlush, cmdReset, cmdUpdate } from './commands/maintain.js';
|
|
|
12
12
|
import { cmdScan, cmdUsages } from './commands/graph.js';
|
|
13
13
|
import { cmdSeed } from './commands/seed.js';
|
|
14
14
|
import { cmdAdoption } from './commands/adoption.js';
|
|
15
|
+
import { cmdView } from './commands/view.js';
|
|
15
16
|
import { silenceSqliteWarning } from '../util/warnings.js';
|
|
16
17
|
silenceSqliteWarning();
|
|
17
18
|
const [command, ...args] = process.argv.slice(2);
|
|
@@ -66,6 +67,9 @@ async function run() {
|
|
|
66
67
|
case 'adoption':
|
|
67
68
|
await cmdAdoption();
|
|
68
69
|
break;
|
|
70
|
+
case 'view':
|
|
71
|
+
await cmdView(args);
|
|
72
|
+
break;
|
|
69
73
|
case 'update':
|
|
70
74
|
await cmdUpdate(args);
|
|
71
75
|
break;
|