claude-db 0.2.3 → 0.3.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/README.md +16 -4
- package/dist/capture/flush.d.ts +20 -1
- package/dist/capture/flush.js +45 -5
- package/dist/capture/git.d.ts +2 -0
- package/dist/capture/git.js +96 -0
- package/dist/capture/index.d.ts +4 -3
- package/dist/capture/index.js +4 -3
- package/dist/capture/manual.d.ts +9 -0
- package/dist/capture/manual.js +0 -0
- package/dist/capture/transcript.d.ts +8 -0
- package/dist/capture/transcript.js +30 -0
- package/dist/capture/turn-extractor.d.ts +9 -1
- package/dist/capture/turn-extractor.js +74 -13
- package/dist/cli/index.js +383 -27
- package/dist/cli/install.d.ts +8 -0
- package/dist/cli/install.js +24 -0
- package/dist/mcp/render.d.ts +23 -0
- package/dist/mcp/render.js +49 -0
- package/dist/mcp/server.d.ts +1 -7
- package/dist/mcp/server.js +37 -36
- package/dist/store/adapter.d.ts +10 -0
- package/dist/store/adapter.js +8 -0
- package/dist/store/mongo/index.d.ts +1 -0
- package/dist/store/mongo/index.js +34 -3
- package/dist/store/postgres/index.d.ts +15 -0
- package/dist/store/postgres/index.js +89 -4
- package/dist/store/sqlite/index.d.ts +1 -0
- package/dist/store/sqlite/index.js +32 -2
- package/dist/types.d.ts +16 -0
- package/dist/util/snippet.d.ts +28 -0
- package/dist/util/snippet.js +52 -0
- package/package.json +2 -1
- package/skills/cdb-scan/SKILL.md +72 -0
package/README.md
CHANGED
|
@@ -61,6 +61,10 @@ produces 10 to 20 rows, not hundreds.
|
|
|
61
61
|
best match in full on each prompt. Roughly 350 tokens when something relevant
|
|
62
62
|
exists, zero when it doesn't.
|
|
63
63
|
|
|
64
|
+
**What search returns.** An id, kind, date, title and one line of the matching
|
|
65
|
+
body — enough to tell two similarly-titled rows apart without expanding either.
|
|
66
|
+
Full bodies come only from `get_observations`, for ids you picked.
|
|
67
|
+
|
|
64
68
|
An example of one stored memory:
|
|
65
69
|
|
|
66
70
|
```
|
|
@@ -84,15 +88,17 @@ Ran: Test run: pnpm test
|
|
|
84
88
|
| --- | --- |
|
|
85
89
|
| `claude-db install [--project]` | Register hooks and the MCP server |
|
|
86
90
|
| `claude-db uninstall [--project]` | Remove them, keeping your memory |
|
|
87
|
-
| `claude-db status` | Is it wired up,
|
|
88
|
-
| `claude-db doctor` | Resolved config
|
|
89
|
-
| `claude-db search [--all] <query>` | Search this project's memory, or every project |
|
|
90
|
-
| `claude-db remember <text>` | Record a rule outright, e.g. "always use pnpm here" |
|
|
91
|
+
| `claude-db status` | Is it wired up, and when did it last record anything |
|
|
92
|
+
| `claude-db doctor [--deep]` | Resolved config; `--deep` proves a full round trip |
|
|
93
|
+
| `claude-db search [--all] [--tag <name>] <query>` | Search this project's memory, or every project |
|
|
94
|
+
| `claude-db remember [--key <name>] <text>` | Record a rule outright, e.g. "always use pnpm here" |
|
|
91
95
|
| `claude-db forget <id>` | Delete specific observations by id |
|
|
96
|
+
| `claude-db seed --from-git` | Fill a cold memory from this repo's history |
|
|
92
97
|
| `claude-db stats` | What this project's memory is made of |
|
|
93
98
|
| `claude-db projects` | Every project with memory stored |
|
|
94
99
|
| `claude-db merge [<path>]` | Move memory from an old project path onto this one |
|
|
95
100
|
| `claude-db use <url>` | Switch database and verify it |
|
|
101
|
+
| `claude-db sync <url>` | Two-way merge with another database |
|
|
96
102
|
| `claude-db flush` | Re-ingest every transcript for this project |
|
|
97
103
|
| `claude-db export [--all]` | Dump memory as JSONL, for backup or migration |
|
|
98
104
|
| `claude-db import <file>` | Load a dump back in; safe to repeat |
|
|
@@ -100,6 +106,12 @@ Ran: Test run: pnpm test
|
|
|
100
106
|
| `claude-db prune --older-than <days>` | Delete old memory (dry run without `--yes`) |
|
|
101
107
|
| `claude-db reset [--project] --yes` | Delete memory (dry run without `--yes`) |
|
|
102
108
|
|
|
109
|
+
Install also adds a `/cdb-scan` skill: run it once on an existing project and
|
|
110
|
+
Claude surveys the codebase into memory — stack, layout, conventions,
|
|
111
|
+
workflows — so search has something to find before you have any history. Those
|
|
112
|
+
notes are tagged `inferred`, because they are a reading of the code rather than
|
|
113
|
+
a record of what happened.
|
|
114
|
+
|
|
103
115
|
`--project` scopes to one repo instead of every project on the machine. It
|
|
104
116
|
writes `.claude/settings.local.json` and `.mcp.json` — add `.mcp.json` to your
|
|
105
117
|
`.gitignore`, since it holds a machine-specific path.
|
package/dist/capture/flush.d.ts
CHANGED
|
@@ -17,7 +17,14 @@ export interface FlushResult {
|
|
|
17
17
|
* because observation ids are content-derived: re-reading a turn rewrites the
|
|
18
18
|
* same row rather than appending a duplicate.
|
|
19
19
|
*/
|
|
20
|
-
export declare function flushSession(ctx: RecallContext, sessionId: string, project: string, transcriptPath?: string
|
|
20
|
+
export declare function flushSession(ctx: RecallContext, sessionId: string, project: string, transcriptPath?: string,
|
|
21
|
+
/**
|
|
22
|
+
* Discards the stored recap instead of extending it. A manual flush re-reads
|
|
23
|
+
* the whole transcript, so the summary can be rebuilt from scratch — and
|
|
24
|
+
* after an upgrade it has to be, or the recap injected at every SessionStart
|
|
25
|
+
* keeps quoting titles the new extractor would no longer write.
|
|
26
|
+
*/
|
|
27
|
+
rebuild?: boolean): Promise<FlushResult>;
|
|
21
28
|
/**
|
|
22
29
|
* Embeddings are an enhancement, never a precondition. A missing model must
|
|
23
30
|
* cost semantic recall, not the memory itself.
|
|
@@ -40,3 +47,15 @@ export declare function summarize(observations: Observation[], previous?: string
|
|
|
40
47
|
export declare function resetCursor(sessionId: string): void;
|
|
41
48
|
/** The session is over; its offset is scratch state nothing will read again. */
|
|
42
49
|
export declare function clearCursor(sessionId: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Drops cursors whose transcript no longer exists anywhere.
|
|
52
|
+
*
|
|
53
|
+
* Clearing on SessionEnd only covers sessions that end after it shipped, so a
|
|
54
|
+
* machine that has been running this for a while keeps a file per session it
|
|
55
|
+
* ever saw. Harmless, and untidy in a way that makes the rest look unmaintained.
|
|
56
|
+
*
|
|
57
|
+
* Checked against every transcript on disk rather than this project's, because
|
|
58
|
+
* cursors are keyed by session alone: sweeping on a per-project basis would
|
|
59
|
+
* delete another project's live cursor and cost it a full re-read.
|
|
60
|
+
*/
|
|
61
|
+
export declare function sweepCursors(): number;
|
package/dist/capture/flush.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
1
|
+
import { mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { CONFIG_DIR } from '../config/index.js';
|
|
4
|
-
import { readTranscript, transcriptPathFor } from './transcript.js';
|
|
4
|
+
import { readTranscript, sessionIdsOnDisk, transcriptPathFor } from './transcript.js';
|
|
5
5
|
import { observationsFromTurns } from './turn-extractor.js';
|
|
6
6
|
/**
|
|
7
7
|
* Persists everything new in a session's transcript.
|
|
@@ -16,7 +16,14 @@ import { observationsFromTurns } from './turn-extractor.js';
|
|
|
16
16
|
* because observation ids are content-derived: re-reading a turn rewrites the
|
|
17
17
|
* same row rather than appending a duplicate.
|
|
18
18
|
*/
|
|
19
|
-
export async function flushSession(ctx, sessionId, project, transcriptPath
|
|
19
|
+
export async function flushSession(ctx, sessionId, project, transcriptPath,
|
|
20
|
+
/**
|
|
21
|
+
* Discards the stored recap instead of extending it. A manual flush re-reads
|
|
22
|
+
* the whole transcript, so the summary can be rebuilt from scratch — and
|
|
23
|
+
* after an upgrade it has to be, or the recap injected at every SessionStart
|
|
24
|
+
* keeps quoting titles the new extractor would no longer write.
|
|
25
|
+
*/
|
|
26
|
+
rebuild = false) {
|
|
20
27
|
const path = transcriptPath ?? transcriptPathFor(project, sessionId);
|
|
21
28
|
const cursor = readCursor(sessionId);
|
|
22
29
|
const { turns, nextOffset } = readTranscript(path, cursor);
|
|
@@ -31,7 +38,7 @@ export async function flushSession(ctx, sessionId, project, transcriptPath) {
|
|
|
31
38
|
}
|
|
32
39
|
await embedObservations(ctx, observations);
|
|
33
40
|
await ctx.store.insertObservations(observations);
|
|
34
|
-
const previous = await ctx.store.getSession(sessionId);
|
|
41
|
+
const previous = rebuild ? null : await ctx.store.getSession(sessionId);
|
|
35
42
|
const summary = summarize(observations, previous?.summary);
|
|
36
43
|
await ctx.store.upsertSession({
|
|
37
44
|
id: sessionId,
|
|
@@ -106,8 +113,11 @@ export function summarize(observations, previous) {
|
|
|
106
113
|
* local file, it is worthless on another machine, and it must not sync to a
|
|
107
114
|
* shared Postgres or Mongo alongside real memory.
|
|
108
115
|
*/
|
|
116
|
+
function cursorName(sessionId) {
|
|
117
|
+
return `${sessionId.replace(/[^\w-]/g, '_')}.offset`;
|
|
118
|
+
}
|
|
109
119
|
function cursorPath(sessionId) {
|
|
110
|
-
return join(CONFIG_DIR, 'cursors',
|
|
120
|
+
return join(CONFIG_DIR, 'cursors', cursorName(sessionId));
|
|
111
121
|
}
|
|
112
122
|
function readCursor(sessionId) {
|
|
113
123
|
try {
|
|
@@ -135,3 +145,33 @@ export function resetCursor(sessionId) {
|
|
|
135
145
|
export function clearCursor(sessionId) {
|
|
136
146
|
rmSync(cursorPath(sessionId), { force: true });
|
|
137
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Drops cursors whose transcript no longer exists anywhere.
|
|
150
|
+
*
|
|
151
|
+
* Clearing on SessionEnd only covers sessions that end after it shipped, so a
|
|
152
|
+
* machine that has been running this for a while keeps a file per session it
|
|
153
|
+
* ever saw. Harmless, and untidy in a way that makes the rest look unmaintained.
|
|
154
|
+
*
|
|
155
|
+
* Checked against every transcript on disk rather than this project's, because
|
|
156
|
+
* cursors are keyed by session alone: sweeping on a per-project basis would
|
|
157
|
+
* delete another project's live cursor and cost it a full re-read.
|
|
158
|
+
*/
|
|
159
|
+
export function sweepCursors() {
|
|
160
|
+
const dir = join(CONFIG_DIR, 'cursors');
|
|
161
|
+
let files;
|
|
162
|
+
try {
|
|
163
|
+
files = readdirSync(dir);
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
const live = new Set(sessionIdsOnDisk().map(cursorName));
|
|
169
|
+
let removed = 0;
|
|
170
|
+
for (const file of files) {
|
|
171
|
+
if (!file.endsWith('.offset') || live.has(file))
|
|
172
|
+
continue;
|
|
173
|
+
rmSync(join(dir, file), { force: true });
|
|
174
|
+
removed += 1;
|
|
175
|
+
}
|
|
176
|
+
return removed;
|
|
177
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { observationId } from './identity.js';
|
|
4
|
+
import { classifyTurn, redact, topLevelDirs } from './turn-extractor.js';
|
|
5
|
+
/**
|
|
6
|
+
* Builds memory from git history.
|
|
7
|
+
*
|
|
8
|
+
* A fresh install knows nothing and stays useless for weeks while it fills up,
|
|
9
|
+
* which is the worst moment to be asking someone to trust it. Git history is
|
|
10
|
+
* already a near-perfect source for exactly the fields an observation wants —
|
|
11
|
+
* subject, reasoning, files, author, date — and unlike a profile written by a
|
|
12
|
+
* model it is a record of things that actually happened.
|
|
13
|
+
*
|
|
14
|
+
* Ids derive from the commit sha, so this is safe to re-run: later commits are
|
|
15
|
+
* added and earlier ones are rewritten in place rather than duplicated.
|
|
16
|
+
*/
|
|
17
|
+
// Unit and record separators: neither can appear in a commit message, so the
|
|
18
|
+
// output parses without any quoting rules.
|
|
19
|
+
const RECORD = '';
|
|
20
|
+
const FIELD = '';
|
|
21
|
+
/** Releases and formatting sweeps touch many files and explain nothing. */
|
|
22
|
+
const NOT_WORTH_KEEPING = /^(v?\d+\.\d+\.\d+|merge |revert "|bump |release |chore\(release\)|\d+\.\d+\.\d+$)/i;
|
|
23
|
+
export function observationsFromGit(project, limit) {
|
|
24
|
+
const raw = execFileSync('git', [
|
|
25
|
+
'-C',
|
|
26
|
+
project,
|
|
27
|
+
'log',
|
|
28
|
+
`-n${limit}`,
|
|
29
|
+
'--no-merges',
|
|
30
|
+
`--pretty=format:${RECORD}%H${FIELD}%an${FIELD}%aI${FIELD}%s${FIELD}%b${FIELD}`,
|
|
31
|
+
'--name-only',
|
|
32
|
+
], { encoding: 'utf8', maxBuffer: 128 * 1024 * 1024 });
|
|
33
|
+
const observations = [];
|
|
34
|
+
for (const record of raw.split(RECORD)) {
|
|
35
|
+
const observation = toObservation(record, project);
|
|
36
|
+
if (observation)
|
|
37
|
+
observations.push(observation);
|
|
38
|
+
}
|
|
39
|
+
return observations;
|
|
40
|
+
}
|
|
41
|
+
function toObservation(record, project) {
|
|
42
|
+
if (record.trim().length === 0)
|
|
43
|
+
return null;
|
|
44
|
+
// The format string ends with a separator, so --name-only's paths arrive as
|
|
45
|
+
// their own field rather than having to be told apart from the body — which
|
|
46
|
+
// cannot be done by looking, since commit bodies contain blank lines too.
|
|
47
|
+
const [sha, author, date, subject, body = '', paths = ''] = record.split(FIELD);
|
|
48
|
+
if (!sha || !subject || !date)
|
|
49
|
+
return null;
|
|
50
|
+
if (NOT_WORTH_KEEPING.test(subject.trim()))
|
|
51
|
+
return null;
|
|
52
|
+
const files = paths
|
|
53
|
+
.split('\n')
|
|
54
|
+
.map((line) => line.trim())
|
|
55
|
+
.filter((line) => line.length > 0)
|
|
56
|
+
.map((path) => join(project, path));
|
|
57
|
+
if (files.length === 0)
|
|
58
|
+
return null;
|
|
59
|
+
const createdAt = Date.parse(date);
|
|
60
|
+
if (!Number.isFinite(createdAt))
|
|
61
|
+
return null;
|
|
62
|
+
const timestamp = createdAt;
|
|
63
|
+
return {
|
|
64
|
+
// The sha alone, so re-seeding rewrites rather than appends and two
|
|
65
|
+
// machines seeding the same repository agree on every id.
|
|
66
|
+
id: observationId('git', 0, sha),
|
|
67
|
+
sessionId: 'git',
|
|
68
|
+
project,
|
|
69
|
+
...(author ? { author } : {}),
|
|
70
|
+
kind: classifyTurn({
|
|
71
|
+
prompt: subject,
|
|
72
|
+
reasoning: body,
|
|
73
|
+
files,
|
|
74
|
+
commands: [],
|
|
75
|
+
timestamp,
|
|
76
|
+
offset: 0,
|
|
77
|
+
}),
|
|
78
|
+
title: redact(subject.trim()).slice(0, 80),
|
|
79
|
+
body: redact([
|
|
80
|
+
`Committed ${sha.slice(0, 8)}${author ? ` by ${author}` : ''}`,
|
|
81
|
+
'',
|
|
82
|
+
subject.trim(),
|
|
83
|
+
body.trim(),
|
|
84
|
+
'',
|
|
85
|
+
`Files: ${files.slice(0, 20).map(shortPath).join(', ')}`,
|
|
86
|
+
]
|
|
87
|
+
.filter((line, index) => line !== '' || index > 0)
|
|
88
|
+
.join('\n')),
|
|
89
|
+
files,
|
|
90
|
+
tags: topLevelDirs(files, project),
|
|
91
|
+
createdAt,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function shortPath(path) {
|
|
95
|
+
return path.split('/').filter(Boolean).slice(-2).join('/');
|
|
96
|
+
}
|
package/dist/capture/index.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ export { classifyCommand } from './command.js';
|
|
|
2
2
|
export { currentAuthor, observationId } from './identity.js';
|
|
3
3
|
export { remember } from './manual.js';
|
|
4
4
|
export type { RememberInput } from './manual.js';
|
|
5
|
-
export { readTranscript, transcriptPathFor, transcriptsFor } from './transcript.js';
|
|
5
|
+
export { readTranscript, sessionIdsOnDisk, transcriptPathFor, transcriptsFor, } from './transcript.js';
|
|
6
6
|
export type { Turn, TranscriptRead } from './transcript.js';
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
7
|
+
export { observationsFromGit } from './git.js';
|
|
8
|
+
export { observationsFromTurns, redact } from './turn-extractor.js';
|
|
9
|
+
export { flushSession, resetCursor, clearCursor, sweepCursors, summarize, embedObservations, } from './flush.js';
|
|
9
10
|
export type { FlushResult } from './flush.js';
|
package/dist/capture/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { classifyCommand } from './command.js';
|
|
2
2
|
export { currentAuthor, observationId } from './identity.js';
|
|
3
3
|
export { remember } from './manual.js';
|
|
4
|
-
export { readTranscript, transcriptPathFor, transcriptsFor } from './transcript.js';
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
4
|
+
export { readTranscript, sessionIdsOnDisk, transcriptPathFor, transcriptsFor, } from './transcript.js';
|
|
5
|
+
export { observationsFromGit } from './git.js';
|
|
6
|
+
export { observationsFromTurns, redact } from './turn-extractor.js';
|
|
7
|
+
export { flushSession, resetCursor, clearCursor, sweepCursors, summarize, embedObservations, } from './flush.js';
|
package/dist/capture/manual.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export interface RememberInput {
|
|
|
5
5
|
text: string;
|
|
6
6
|
kind?: ObservationKind;
|
|
7
7
|
files?: string[];
|
|
8
|
+
/** Extra tags, alongside `manual`. */
|
|
9
|
+
tags?: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Stable identity within the project. Remembering the same key again
|
|
12
|
+
* overwrites rather than adding a near-duplicate, which is what lets a
|
|
13
|
+
* survey of the codebase be re-run as it changes instead of accumulating
|
|
14
|
+
* one stale copy per run.
|
|
15
|
+
*/
|
|
16
|
+
key?: string;
|
|
8
17
|
}
|
|
9
18
|
/**
|
|
10
19
|
* Records something the user stated outright, rather than something inferred
|
package/dist/capture/manual.js
CHANGED
|
Binary file
|
|
@@ -51,3 +51,11 @@ export declare function transcriptPathFor(project: string, sessionId: string): s
|
|
|
51
51
|
* and without the second step a flush would ingest a neighbour's history.
|
|
52
52
|
*/
|
|
53
53
|
export declare function transcriptsFor(project: string): string[];
|
|
54
|
+
/**
|
|
55
|
+
* Every session id with a transcript still on disk, across all projects.
|
|
56
|
+
*
|
|
57
|
+
* Deliberately not filtered by project: this answers "does this session still
|
|
58
|
+
* exist at all", which is the only safe question to ask before discarding
|
|
59
|
+
* local state keyed on a session id alone.
|
|
60
|
+
*/
|
|
61
|
+
export declare function sessionIdsOnDisk(): string[];
|
|
@@ -198,6 +198,36 @@ export function transcriptsFor(project) {
|
|
|
198
198
|
}
|
|
199
199
|
return transcripts.sort();
|
|
200
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Every session id with a transcript still on disk, across all projects.
|
|
203
|
+
*
|
|
204
|
+
* Deliberately not filtered by project: this answers "does this session still
|
|
205
|
+
* exist at all", which is the only safe question to ask before discarding
|
|
206
|
+
* local state keyed on a session id alone.
|
|
207
|
+
*/
|
|
208
|
+
export function sessionIdsOnDisk() {
|
|
209
|
+
const root = join(homedir(), '.claude', 'projects');
|
|
210
|
+
const ids = [];
|
|
211
|
+
let dirs;
|
|
212
|
+
try {
|
|
213
|
+
dirs = readdirSync(root);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
return ids;
|
|
217
|
+
}
|
|
218
|
+
for (const dir of dirs) {
|
|
219
|
+
try {
|
|
220
|
+
for (const name of readdirSync(join(root, dir))) {
|
|
221
|
+
if (name.endsWith('.jsonl'))
|
|
222
|
+
ids.push(name.slice(0, -'.jsonl'.length));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
// Not a directory, or unreadable: nothing to learn from it.
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return ids;
|
|
230
|
+
}
|
|
201
231
|
/** First cwd recorded in a transcript, without reading a 90MB file. */
|
|
202
232
|
function transcriptCwd(path) {
|
|
203
233
|
let fd;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Config } from '../config/index.js';
|
|
2
|
-
import type { Observation } from '../types.js';
|
|
2
|
+
import type { Observation, ObservationKind } from '../types.js';
|
|
3
3
|
import type { Turn } from './transcript.js';
|
|
4
4
|
/**
|
|
5
5
|
* Builds observations from transcript turns.
|
|
@@ -11,4 +11,12 @@ import type { Turn } from './transcript.js';
|
|
|
11
11
|
* produce a memory worth recalling.
|
|
12
12
|
*/
|
|
13
13
|
export declare function observationsFromTurns(turns: Turn[], sessionId: string, project: string, config: Config): Observation[];
|
|
14
|
+
/**
|
|
15
|
+
* The first path segment under the project root, which is the repository name
|
|
16
|
+
* when the project directory holds several repos, and the top-level source
|
|
17
|
+
* folder when it is one repo. Tags carry real weight in every backend's index,
|
|
18
|
+
* so this is what makes a pooled memory filterable by where the work happened.
|
|
19
|
+
*/
|
|
20
|
+
export declare function topLevelDirs(files: string[], project: string): string[];
|
|
21
|
+
export declare function classifyTurn(turn: Turn): ObservationKind;
|
|
14
22
|
export declare function redact(text: string): string;
|
|
@@ -66,32 +66,88 @@ function buildObservation(turn, sessionId, project, config) {
|
|
|
66
66
|
* block — the body may hold the answer, but nothing ever surfaces it.
|
|
67
67
|
*/
|
|
68
68
|
const ANNOUNCEMENT = /^(now|next|then|first|right|ok|okay|good question|great|sure|perfect|let me|let's|i'?ll|here'?s|two|three|four|before|starting|continuing)\b/i;
|
|
69
|
+
/**
|
|
70
|
+
* Narration of work in progress: "Working through the improvements now."
|
|
71
|
+
*
|
|
72
|
+
* A participle opener describes what is being done, where a title has to say
|
|
73
|
+
* what was. Listed rather than matched as a generic `\w+ing`, which would take
|
|
74
|
+
* "Nothing changed" and "Something in the cache" with it.
|
|
75
|
+
*/
|
|
76
|
+
const IN_PROGRESS = /^(work|add|fix|runn|updat|writ|build|mak|mov|remov|check|test|switch|wir|tak|go|do|try|look|read|creat|implement|refactor|pull|push|sett)ing\b/i;
|
|
77
|
+
/**
|
|
78
|
+
* Openers that point at something already said instead of saying it.
|
|
79
|
+
*
|
|
80
|
+
* Measured against real titles after the 0.2.2 fix: "That's the same gap we
|
|
81
|
+
* just closed" displaced "remember() stores text raw — no redaction", because
|
|
82
|
+
* the vague sentence happened to contain a past-tense verb. A back-reference
|
|
83
|
+
* carries none of the claim — whatever it refers to is the claim — so it
|
|
84
|
+
* belongs with the announcements rather than being scored against them.
|
|
85
|
+
*/
|
|
86
|
+
const BACKREFERENCE = /^(that'?s|this is|these are|it'?s|there'?s|you'?(ve|re)|we'?(ve|re)|yes\b|no\b|exactly|correct|agreed|fair enough|both\b|either\b|same\b)/i;
|
|
69
87
|
function announces(sentence) {
|
|
70
|
-
return sentence.endsWith(':') ||
|
|
88
|
+
return (sentence.endsWith(':') ||
|
|
89
|
+
ANNOUNCEMENT.test(sentence) ||
|
|
90
|
+
BACKREFERENCE.test(sentence) ||
|
|
91
|
+
IN_PROGRESS.test(sentence));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Marks of a sentence that reports an outcome rather than an intention.
|
|
95
|
+
*
|
|
96
|
+
* Skipping announcements alone still leaves the first merely-neutral sentence
|
|
97
|
+
* winning, so a reply that opens with "Working through the improvements now."
|
|
98
|
+
* stores that as its title. Scoring the opening few instead lets a later
|
|
99
|
+
* sentence carrying a filename, a version or a past-tense verb take the slot.
|
|
100
|
+
*/
|
|
101
|
+
const EVIDENCE = [
|
|
102
|
+
/[\w-]+\.(ts|tsx|js|jsx|mjs|json|md|sql|py|go|rs|ya?ml|sh|toml|txt|css|html|lock)\b/i,
|
|
103
|
+
/\b\w{3,}ed\b/i,
|
|
104
|
+
/\d/,
|
|
105
|
+
];
|
|
106
|
+
/** -1 announces the work, 0 says nothing in particular, 1 reports an outcome. */
|
|
107
|
+
function reports(sentence) {
|
|
108
|
+
if (announces(sentence))
|
|
109
|
+
return -1;
|
|
110
|
+
// A redaction marker is not evidence. "[redacted-key]" reads as a past-tense
|
|
111
|
+
// verb to the rule above, which would promote a pasted secret over the
|
|
112
|
+
// sentence that says what was actually done.
|
|
113
|
+
const text = sentence.replace(/\[redacted[^\]]*\]/g, '');
|
|
114
|
+
return EVIDENCE.some((test) => test.test(text)) ? 1 : 0;
|
|
71
115
|
}
|
|
72
116
|
/**
|
|
73
|
-
* Prefers the
|
|
117
|
+
* Prefers the sentence of the reply that reports the most.
|
|
74
118
|
*
|
|
75
119
|
* The prompt states a request ("can you create one icon"); the reply states
|
|
76
120
|
* what actually happened ("Built mouse-scroll-icon.tsx, first of the Huge
|
|
77
121
|
* Tier 1 Gestures batch"). The second is what someone searching their history
|
|
78
122
|
* is looking for, and it is written in the vocabulary of the codebase — but
|
|
79
123
|
* only once the throat-clearing in front of it is skipped.
|
|
124
|
+
*
|
|
125
|
+
* Redacted before it is scored, not just before it is stored: a sentence made
|
|
126
|
+
* of a pasted key is dense with digits, and would otherwise outscore the one
|
|
127
|
+
* that says what was done.
|
|
80
128
|
*/
|
|
81
129
|
function buildTitle(turn, files) {
|
|
82
|
-
const prose = stripMarkdown(turn.reasoning);
|
|
130
|
+
const prose = stripMarkdown(redact(turn.reasoning));
|
|
83
131
|
// Bounded: past the first few sentences a reply has moved on to detail that
|
|
84
132
|
// no longer summarises the turn.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
133
|
+
const scored = sentences(prose)
|
|
134
|
+
.slice(0, 6)
|
|
135
|
+
.filter((sentence) => sentence.length >= 15)
|
|
136
|
+
.map((sentence) => [sentence, reports(sentence)]);
|
|
137
|
+
// The first sentence that reports, not the one that reports most: a later
|
|
138
|
+
// sentence accumulates signals just by being long and specific, while the
|
|
139
|
+
// summary comes first and the detail follows it.
|
|
140
|
+
const best = scored.find(([, score]) => score > 0) ?? scored.find(([, score]) => score === 0);
|
|
141
|
+
if (best)
|
|
142
|
+
return headline(best[0]);
|
|
143
|
+
// Nothing in the reply reports anything, so it is all narration. The prompt
|
|
144
|
+
// is the only record of intent, and intent beats "Working through it now."
|
|
145
|
+
const prompt = firstSentence(redact(turn.prompt));
|
|
146
|
+
if (prompt)
|
|
147
|
+
return headline(prompt);
|
|
89
148
|
const opening = firstSentence(prose);
|
|
90
149
|
if (opening && opening.length >= 15)
|
|
91
150
|
return headline(opening);
|
|
92
|
-
const prompt = firstSentence(turn.prompt);
|
|
93
|
-
if (prompt)
|
|
94
|
-
return headline(prompt);
|
|
95
151
|
return files.length > 0 ? `Changed ${shortPath(files[0] ?? '')}` : 'Session work';
|
|
96
152
|
}
|
|
97
153
|
/** Split on sentence enders followed by space, so "0.2.1" stays intact. */
|
|
@@ -126,7 +182,7 @@ function headline(sentence) {
|
|
|
126
182
|
* folder when it is one repo. Tags carry real weight in every backend's index,
|
|
127
183
|
* so this is what makes a pooled memory filterable by where the work happened.
|
|
128
184
|
*/
|
|
129
|
-
function topLevelDirs(files, project) {
|
|
185
|
+
export function topLevelDirs(files, project) {
|
|
130
186
|
const prefix = project.endsWith('/') ? project : `${project}/`;
|
|
131
187
|
const tags = new Set();
|
|
132
188
|
for (const file of files) {
|
|
@@ -139,7 +195,7 @@ function topLevelDirs(files, project) {
|
|
|
139
195
|
}
|
|
140
196
|
return [...tags].slice(0, 3);
|
|
141
197
|
}
|
|
142
|
-
function classifyTurn(turn) {
|
|
198
|
+
export function classifyTurn(turn) {
|
|
143
199
|
const text = `${turn.prompt} ${turn.reasoning}`.toLowerCase();
|
|
144
200
|
// Read from the prompt alone, and only where the phrasing is a standing
|
|
145
201
|
// instruction. "the build always fails" is a bugfix, not a house rule, so
|
|
@@ -148,7 +204,12 @@ function classifyTurn(turn) {
|
|
|
148
204
|
/\b(always|never)\s+(use|run|do|add|write|call|put|name|commit|push|import|install)\b/.test(turn.prompt.toLowerCase())) {
|
|
149
205
|
return 'preference';
|
|
150
206
|
}
|
|
151
|
-
|
|
207
|
+
// `because` used to be in here and matched 98 of 471 stored decisions on its
|
|
208
|
+
// own, which is how every second observation became a `decision` and the
|
|
209
|
+
// filter stopped narrowing anything. It explains as readily as it decides —
|
|
210
|
+
// "the build failed because the cache key was stale" is a bugfix — so what is
|
|
211
|
+
// left names an alternative that was weighed.
|
|
212
|
+
if (/\b(instead of|rather than|in favou?r of|opted for|went with|chose|decided|trade-?off|why we)\b/.test(text)) {
|
|
152
213
|
return 'decision';
|
|
153
214
|
}
|
|
154
215
|
if (/\b(didn'?t work|failed|reverted|abandoned|dead ?end|gave up|doesn'?t scale)\b/.test(text)) {
|