claude-db 0.11.0 → 0.12.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 +63 -0
- package/README.md +44 -81
- package/dist/catchup/gather.d.ts +1 -0
- package/dist/catchup/gather.js +9 -2
- package/dist/catchup/git-state.d.ts +2 -0
- package/dist/catchup/git-state.js +3 -0
- package/dist/catchup/render.js +8 -0
- package/dist/cli/commands/graph.js +104 -80
- package/dist/cli/commands/languages.d.ts +1 -0
- package/dist/cli/commands/languages.js +22 -0
- package/dist/cli/files.d.ts +2 -0
- package/dist/cli/files.js +15 -1
- package/dist/cli/index.js +4 -0
- package/dist/cli/install.js +4 -3
- package/dist/cli/skills.js +6 -1
- package/dist/cli/usage.js +3 -1
- package/dist/facts/distill.d.ts +0 -2
- package/dist/facts/distill.js +4 -26
- package/dist/facts/handoff.js +11 -1
- package/dist/facts/known.d.ts +4 -0
- package/dist/facts/known.js +38 -0
- package/dist/facts/ops.d.ts +1 -1
- package/dist/facts/ops.js +4 -2
- package/dist/facts/start.js +5 -1
- package/dist/graph/ast.d.ts +4 -0
- package/dist/graph/ast.js +11 -0
- package/dist/graph/grammars.d.ts +14 -0
- package/dist/graph/grammars.js +58 -0
- package/dist/graph/index.d.ts +2 -2
- package/dist/graph/index.js +2 -2
- package/dist/graph/languages/basic.js +5 -1
- package/dist/graph/languages/ecmascript.js +7 -0
- package/dist/graph/languages/go.js +0 -1
- package/dist/graph/languages/index.d.ts +1 -1
- package/dist/graph/languages/index.js +34 -9
- package/dist/graph/languages/java.d.ts +2 -0
- package/dist/graph/languages/java.js +38 -0
- package/dist/graph/languages/kotlin.d.ts +2 -0
- package/dist/graph/languages/kotlin.js +19 -0
- package/dist/graph/languages/python.js +10 -2
- package/dist/graph/languages/rules.d.ts +11 -0
- package/dist/graph/languages/rust.js +2 -1
- package/dist/graph/modules/binding.d.ts +61 -0
- package/dist/graph/modules/binding.js +43 -0
- package/dist/graph/modules/ecmascript/bind.d.ts +4 -0
- package/dist/graph/modules/ecmascript/bind.js +17 -0
- package/dist/graph/modules/ecmascript/contexts.d.ts +6 -0
- package/dist/graph/modules/ecmascript/contexts.js +86 -0
- package/dist/graph/modules/ecmascript/exports.d.ts +9 -0
- package/dist/graph/modules/ecmascript/exports.js +91 -0
- package/dist/graph/modules/ecmascript/imports.d.ts +4 -0
- package/dist/graph/modules/ecmascript/imports.js +73 -0
- package/dist/graph/modules/ecmascript/package-resolver.d.ts +4 -0
- package/dist/graph/modules/ecmascript/package-resolver.js +73 -0
- package/dist/graph/modules/ecmascript/resolver.d.ts +2 -0
- package/dist/graph/modules/ecmascript/resolver.js +22 -0
- package/dist/graph/modules/ecmascript/specifiers.d.ts +3 -0
- package/dist/graph/modules/ecmascript/specifiers.js +15 -0
- package/dist/graph/modules/ecmascript/system.d.ts +2 -0
- package/dist/graph/modules/ecmascript/system.js +18 -0
- package/dist/graph/modules/ecmascript/workspace-resolver.d.ts +5 -0
- package/dist/graph/modules/ecmascript/workspace-resolver.js +38 -0
- package/dist/graph/modules/go/grammar.d.ts +2 -0
- package/dist/graph/modules/go/grammar.js +54 -0
- package/dist/graph/modules/go/imports.d.ts +4 -0
- package/dist/graph/modules/go/imports.js +32 -0
- package/dist/graph/modules/go/resolver.d.ts +2 -0
- package/dist/graph/modules/go/resolver.js +54 -0
- package/dist/graph/modules/go/system.d.ts +2 -0
- package/dist/graph/modules/go/system.js +16 -0
- package/dist/graph/modules/java/declarations.d.ts +9 -0
- package/dist/graph/modules/java/declarations.js +108 -0
- package/dist/graph/modules/java/grammar.d.ts +2 -0
- package/dist/graph/modules/java/grammar.js +135 -0
- package/dist/graph/modules/java/imports.d.ts +4 -0
- package/dist/graph/modules/java/imports.js +13 -0
- package/dist/graph/modules/java/receivers.d.ts +3 -0
- package/dist/graph/modules/java/receivers.js +139 -0
- package/dist/graph/modules/java/system.d.ts +1 -0
- package/dist/graph/modules/java/system.js +13 -0
- package/dist/graph/modules/jvm/linking.d.ts +20 -0
- package/dist/graph/modules/jvm/linking.js +64 -0
- package/dist/graph/modules/jvm/packages.d.ts +5 -0
- package/dist/graph/modules/jvm/packages.js +58 -0
- package/dist/graph/modules/jvm/receivers.d.ts +44 -0
- package/dist/graph/modules/jvm/receivers.js +77 -0
- package/dist/graph/modules/jvm/system.d.ts +18 -0
- package/dist/graph/modules/jvm/system.js +29 -0
- package/dist/graph/modules/jvm/types.d.ts +3 -0
- package/dist/graph/modules/jvm/types.js +11 -0
- package/dist/graph/modules/kotlin/declarations.d.ts +8 -0
- package/dist/graph/modules/kotlin/declarations.js +69 -0
- package/dist/graph/modules/kotlin/grammar.d.ts +2 -0
- package/dist/graph/modules/kotlin/grammar.js +78 -0
- package/dist/graph/modules/kotlin/imports.d.ts +4 -0
- package/dist/graph/modules/kotlin/imports.js +25 -0
- package/dist/graph/modules/kotlin/receivers.d.ts +3 -0
- package/dist/graph/modules/kotlin/receivers.js +105 -0
- package/dist/graph/modules/kotlin/references.d.ts +8 -0
- package/dist/graph/modules/kotlin/references.js +69 -0
- package/dist/graph/modules/kotlin/system.d.ts +1 -0
- package/dist/graph/modules/kotlin/system.js +15 -0
- package/dist/graph/modules/members.d.ts +17 -0
- package/dist/graph/modules/members.js +30 -0
- package/dist/graph/modules/module-index.d.ts +9 -0
- package/dist/graph/modules/module-index.js +62 -0
- package/dist/graph/modules/names.d.ts +2 -0
- package/dist/graph/modules/names.js +3 -0
- package/dist/graph/modules/python/grammar.d.ts +2 -0
- package/dist/graph/modules/python/grammar.js +100 -0
- package/dist/graph/modules/python/imports.d.ts +3 -0
- package/dist/graph/modules/python/imports.js +72 -0
- package/dist/graph/modules/python/resolver.d.ts +2 -0
- package/dist/graph/modules/python/resolver.js +78 -0
- package/dist/graph/modules/python/system.d.ts +2 -0
- package/dist/graph/modules/python/system.js +16 -0
- package/dist/graph/modules/rebind.d.ts +8 -0
- package/dist/graph/modules/rebind.js +51 -0
- package/dist/graph/modules/registry.d.ts +5 -0
- package/dist/graph/modules/registry.js +47 -0
- package/dist/graph/modules/rust/grammar.d.ts +2 -0
- package/dist/graph/modules/rust/grammar.js +94 -0
- package/dist/graph/modules/rust/imports.d.ts +3 -0
- package/dist/graph/modules/rust/imports.js +90 -0
- package/dist/graph/modules/rust/resolver.d.ts +3 -0
- package/dist/graph/modules/rust/resolver.js +153 -0
- package/dist/graph/modules/rust/system.d.ts +2 -0
- package/dist/graph/modules/rust/system.js +16 -0
- package/dist/graph/modules/shadowing.d.ts +17 -0
- package/dist/graph/modules/shadowing.js +65 -0
- package/dist/graph/modules/system.d.ts +39 -0
- package/dist/graph/modules/system.js +1 -0
- package/dist/graph/modules/uses.d.ts +14 -0
- package/dist/graph/modules/uses.js +62 -0
- package/dist/graph/parser.d.ts +9 -11
- package/dist/graph/parser.js +5 -4
- package/dist/graph/query/answer.d.ts +15 -0
- package/dist/graph/query/answer.js +22 -0
- package/dist/graph/query/format.d.ts +8 -1
- package/dist/graph/query/format.js +103 -30
- package/dist/graph/query/groups.d.ts +14 -0
- package/dist/graph/query/groups.js +51 -0
- package/dist/graph/query/index.d.ts +2 -1
- package/dist/graph/query/index.js +2 -1
- package/dist/graph/query/lookup.d.ts +2 -0
- package/dist/graph/query/lookup.js +19 -2
- package/dist/graph/query/refresh.js +17 -18
- package/dist/graph/query/stale.d.ts +2 -0
- package/dist/graph/query/stale.js +39 -0
- package/dist/graph/query/text.d.ts +12 -0
- package/dist/graph/query/text.js +26 -0
- package/dist/graph/scan/binder.d.ts +13 -0
- package/dist/graph/scan/binder.js +210 -0
- package/dist/graph/scan/cache.d.ts +11 -0
- package/dist/graph/scan/cache.js +140 -0
- package/dist/graph/scan/extract.d.ts +4 -17
- package/dist/graph/scan/extract.js +105 -83
- package/dist/graph/scan/files.d.ts +3 -9
- package/dist/graph/scan/files.js +3 -2
- package/dist/graph/scan/index.d.ts +8 -3
- package/dist/graph/scan/index.js +96 -36
- package/dist/graph/scan/job.d.ts +1 -0
- package/dist/graph/scan/job.js +1 -0
- package/dist/graph/scan/persist.d.ts +3 -0
- package/dist/graph/scan/persist.js +22 -0
- package/dist/graph/scan/receivers.d.ts +21 -0
- package/dist/graph/scan/receivers.js +87 -0
- package/dist/graph/scan/resolve.d.ts +8 -2
- package/dist/graph/scan/resolve.js +50 -56
- package/dist/graph/scan/spans.d.ts +13 -0
- package/dist/graph/scan/spans.js +42 -0
- package/dist/graph/symbols.d.ts +10 -0
- package/dist/graph/symbols.js +30 -0
- package/dist/graph/types.d.ts +56 -0
- package/dist/graph/types.js +1 -0
- package/dist/hooks/background.js +1 -16
- package/dist/hooks/detached.d.ts +3 -0
- package/dist/hooks/detached.js +16 -0
- package/dist/hooks/graph-refresh.d.ts +1 -0
- package/dist/hooks/graph-refresh.js +9 -0
- package/dist/hooks/prefer-usages.js +53 -12
- package/dist/hooks/session-start.js +8 -8
- package/dist/mcp/tools/usages.js +40 -31
- package/dist/types.d.ts +1 -1
- package/dist/usages/find.js +1 -0
- package/docs/how-it-works.md +10 -8
- package/docs/setup-guide.md +47 -299
- package/package.json +17 -6
- package/skills/catchup/SKILL.md +2 -0
- package/skills/handoff/SKILL.md +23 -7
package/dist/cli/install.js
CHANGED
|
@@ -2,7 +2,7 @@ import { instructionsPathFor, mcpPathFor, settingsPathFor } from './paths.js';
|
|
|
2
2
|
import { installSkills, removeSkills } from './skills.js';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { execFileSync } from 'node:child_process';
|
|
5
|
-
import { readJson, writeJson } from './files.js';
|
|
5
|
+
import { readJson, writeJson, writeJsonOrRemove } from './files.js';
|
|
6
6
|
import { removeInstructions, writeInstructions } from './instructions.js';
|
|
7
7
|
import { toPosix } from '../util/paths.js';
|
|
8
8
|
const HOOKS = [
|
|
@@ -104,6 +104,7 @@ export function uninstall(distDir, scope, project) {
|
|
|
104
104
|
const settings = readJson(path);
|
|
105
105
|
if (Object.keys(settings).length === 0)
|
|
106
106
|
return null;
|
|
107
|
+
const save = scope === 'project' ? writeJsonOrRemove : writeJson;
|
|
107
108
|
const hooks = (settings['hooks'] ?? {});
|
|
108
109
|
for (const [event, entries] of Object.entries(hooks)) {
|
|
109
110
|
const kept = withoutOurHooks(entries);
|
|
@@ -116,7 +117,7 @@ export function uninstall(distDir, scope, project) {
|
|
|
116
117
|
settings['hooks'] = hooks;
|
|
117
118
|
else
|
|
118
119
|
delete settings['hooks'];
|
|
119
|
-
|
|
120
|
+
save(path, settings);
|
|
120
121
|
removeInstructions(instructionsPathFor(scope, project));
|
|
121
122
|
removeSkills(scope, project);
|
|
122
123
|
if (scope === 'global' && claudeMcp(['mcp', 'remove', 'memory', '-s', 'user'])) {
|
|
@@ -132,7 +133,7 @@ export function uninstall(distDir, scope, project) {
|
|
|
132
133
|
else
|
|
133
134
|
delete mcpConfig['mcpServers'];
|
|
134
135
|
if (existed)
|
|
135
|
-
|
|
136
|
+
save(mcpPath, mcpConfig);
|
|
136
137
|
return path;
|
|
137
138
|
}
|
|
138
139
|
function hookCommand(distDir, file) {
|
package/dist/cli/skills.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rmSync } from 'node:fs';
|
|
2
2
|
import { dirname, resolve } from 'node:path';
|
|
3
|
-
import { readText, writeAtomic } from './files.js';
|
|
3
|
+
import { readText, removeIfEmpty, writeAtomic } from './files.js';
|
|
4
4
|
import { skillPathFor } from './paths.js';
|
|
5
5
|
export const SKILL_MARKER = 'Shipped with claude-db.';
|
|
6
6
|
export const SKILLS = [
|
|
@@ -52,6 +52,11 @@ export function removeSkills(scope, project) {
|
|
|
52
52
|
continue;
|
|
53
53
|
rmSync(dirname(path), { recursive: true, force: true });
|
|
54
54
|
}
|
|
55
|
+
if (scope !== 'project')
|
|
56
|
+
return;
|
|
57
|
+
const skillsDir = dirname(dirname(skillPathFor(scope, project)));
|
|
58
|
+
removeIfEmpty(skillsDir);
|
|
59
|
+
removeIfEmpty(dirname(skillsDir));
|
|
55
60
|
}
|
|
56
61
|
export function describeSkills(project) {
|
|
57
62
|
const scopes = ['project', 'global'];
|
package/dist/cli/usage.js
CHANGED
|
@@ -26,7 +26,9 @@ export function usage() {
|
|
|
26
26
|
[--repair] ...only chats that already have memory
|
|
27
27
|
seed --from-git [--limit n] Fill a cold memory from this repo's history
|
|
28
28
|
scan [--force] Map this repo's symbols and how they connect
|
|
29
|
-
|
|
29
|
+
languages Show how each language is read: real syntax or pattern
|
|
30
|
+
usages [--mode m] <symbol> Who uses a symbol: the graph, then text it could not link
|
|
31
|
+
[--mode usages|explain|path|text]
|
|
30
32
|
[--target <symbol>] ...the second symbol, for --mode path
|
|
31
33
|
[--regex] [--context n] [--path <dir>] [--limit n]
|
|
32
34
|
export [--all] > out.jsonl Dump memory as JSONL, for backup or migration
|
package/dist/facts/distill.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { RecallContext } from '../context.js';
|
|
2
2
|
import type { Observation } from '../types.js';
|
|
3
3
|
import type { HeadlessResult } from '../util/claude-cli.js';
|
|
4
|
-
import type { ExistingFact } from './ops.js';
|
|
5
4
|
export declare const FACTS_JOB = "facts";
|
|
6
5
|
export type Runner = (prompt: string, model: string, timeoutMs: number) => Promise<HeadlessResult>;
|
|
7
6
|
export type DistillOutcome = 'distilled' | 'empty' | 'over-budget' | 'failed';
|
|
@@ -33,7 +32,6 @@ export declare function distillSession(ctx: RecallContext, project: string, sess
|
|
|
33
32
|
export declare function pendingSessions(ctx: RecallContext, project: string, now?: number): Promise<string[]>;
|
|
34
33
|
export declare function oldestPendingAt(ctx: RecallContext, project: string, now?: number): Promise<number | null>;
|
|
35
34
|
export declare function backfill(ctx: RecallContext, project: string, run?: Runner, onStep?: (step: BackfillStep) => void): Promise<BackfillResult>;
|
|
36
|
-
export declare function existingFacts(ctx: RecallContext, project: string): Promise<ExistingFact[]>;
|
|
37
35
|
export declare function chatWindows(rows: Observation[], most?: number): string[];
|
|
38
36
|
export declare function factCounts(ctx: RecallContext, project: string): Promise<{
|
|
39
37
|
project: number;
|
package/dist/facts/distill.js
CHANGED
|
@@ -2,7 +2,8 @@ import { embedObservations } from '../capture/flush.js';
|
|
|
2
2
|
import { runHeadlessResult } from '../util/claude-cli.js';
|
|
3
3
|
import { formatDay } from '../util/day.js';
|
|
4
4
|
import { recordDistillFailure, recordDistillSuccess, takeDistillCalls } from './budget.js';
|
|
5
|
-
import { FACT_SESSION, factId,
|
|
5
|
+
import { FACT_SESSION, factId, factToObservation, youScope } from './model.js';
|
|
6
|
+
import { existingFacts, notedByUser } from './known.js';
|
|
6
7
|
import { buildDistillPrompt, parseOps } from './ops.js';
|
|
7
8
|
export const FACTS_JOB = 'facts';
|
|
8
9
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -10,7 +11,6 @@ const WINDOW_CHARS = 40_000;
|
|
|
10
11
|
const MAX_WINDOWS = 6;
|
|
11
12
|
const ROW_CHARS = 900;
|
|
12
13
|
const SEPARATOR = '\n\n---\n\n';
|
|
13
|
-
const EXISTING_LIMIT = 80;
|
|
14
14
|
const SESSION_ROWS = 1000;
|
|
15
15
|
const TIMEOUT_MS = 120_000;
|
|
16
16
|
export async function distillSession(ctx, project, sessionId, run = runHeadlessResult) {
|
|
@@ -47,7 +47,8 @@ export async function distillSession(ctx, project, sessionId, run = runHeadlessR
|
|
|
47
47
|
}
|
|
48
48
|
async function distillWindow(ctx, project, chat, source, at, run) {
|
|
49
49
|
const existing = await existingFacts(ctx, project);
|
|
50
|
-
const
|
|
50
|
+
const noted = await notedByUser(ctx, project);
|
|
51
|
+
const reply = await run(buildDistillPrompt(chat, existing, noted), ctx.config.distill.model, TIMEOUT_MS);
|
|
51
52
|
if (!reply.ok)
|
|
52
53
|
return { ok: false, reason: reply.reason };
|
|
53
54
|
const ops = parseOps(reply.stdout);
|
|
@@ -96,29 +97,6 @@ export async function backfill(ctx, project, run = runHeadlessResult, onStep = (
|
|
|
96
97
|
}
|
|
97
98
|
return { distilled, facts, remaining: 0, stopped: 'done' };
|
|
98
99
|
}
|
|
99
|
-
export async function existingFacts(ctx, project) {
|
|
100
|
-
const owners = [
|
|
101
|
-
[project, 'project'],
|
|
102
|
-
[youScope(), 'you'],
|
|
103
|
-
];
|
|
104
|
-
const facts = [];
|
|
105
|
-
for (const [owner, scope] of owners) {
|
|
106
|
-
const rows = await ctx.store.list({
|
|
107
|
-
project: owner,
|
|
108
|
-
sessionId: FACT_SESSION,
|
|
109
|
-
newest: true,
|
|
110
|
-
limit: EXISTING_LIMIT,
|
|
111
|
-
});
|
|
112
|
-
for (const obs of onePerKey(rows.filter((row) => row.status !== 'replaced'))) {
|
|
113
|
-
const key = factKey(obs);
|
|
114
|
-
const type = factType(obs);
|
|
115
|
-
if (obs.status === 'replaced' || !key || !type)
|
|
116
|
-
continue;
|
|
117
|
-
facts.push({ key, type, scope, text: obs.title });
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return facts;
|
|
121
|
-
}
|
|
122
100
|
export function chatWindows(rows, most = MAX_WINDOWS) {
|
|
123
101
|
const windows = [];
|
|
124
102
|
let current = [];
|
package/dist/facts/handoff.js
CHANGED
|
@@ -4,6 +4,8 @@ export const HANDOFF_KEY = 'handoff';
|
|
|
4
4
|
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
5
5
|
const HANDOFF_MAX_AGE_MS = 14 * DAY_MS;
|
|
6
6
|
const MANUAL_NOTES_SCANNED = 50;
|
|
7
|
+
const HANDOFF_MAX_LINES = 8;
|
|
8
|
+
const HANDOFF_LINE_CHARS = 220;
|
|
7
9
|
export async function newestHandoff(ctx, project, now = Date.now()) {
|
|
8
10
|
const notes = await ctx.store.list({
|
|
9
11
|
project,
|
|
@@ -16,10 +18,18 @@ export async function newestHandoff(ctx, project, now = Date.now()) {
|
|
|
16
18
|
now - obs.createdAt <= HANDOFF_MAX_AGE_MS;
|
|
17
19
|
return notes.find(current) ?? null;
|
|
18
20
|
}
|
|
21
|
+
function clipLine(line) {
|
|
22
|
+
return line.length > HANDOFF_LINE_CHARS
|
|
23
|
+
? `${line.slice(0, HANDOFF_LINE_CHARS - 1).trimEnd()}…`
|
|
24
|
+
: line;
|
|
25
|
+
}
|
|
19
26
|
export function handoffBodyLines(obs) {
|
|
20
|
-
|
|
27
|
+
const lines = obs.body
|
|
21
28
|
.split('\n')
|
|
22
29
|
.slice(1)
|
|
23
30
|
.map((line) => line.trimEnd())
|
|
24
31
|
.filter((line) => line.trim().length > 0);
|
|
32
|
+
const shown = lines.slice(0, HANDOFF_MAX_LINES).map(clipLine);
|
|
33
|
+
const hidden = lines.length - shown.length;
|
|
34
|
+
return hidden > 0 ? [...shown, `- ...${hidden} more line(s) in the full note`] : shown;
|
|
25
35
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RecallContext } from '../context.js';
|
|
2
|
+
import type { ExistingFact } from './ops.js';
|
|
3
|
+
export declare function existingFacts(ctx: RecallContext, project: string): Promise<ExistingFact[]>;
|
|
4
|
+
export declare function notedByUser(ctx: RecallContext, project: string): Promise<string[]>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { HANDOFF_TAG } from './handoff.js';
|
|
2
|
+
import { FACT_SESSION, factKey, factType, onePerKey, youScope } from './model.js';
|
|
3
|
+
import { MANUAL_SESSION } from './render.js';
|
|
4
|
+
const EXISTING_LIMIT = 80;
|
|
5
|
+
export async function existingFacts(ctx, project) {
|
|
6
|
+
const owners = [
|
|
7
|
+
[project, 'project'],
|
|
8
|
+
[youScope(), 'you'],
|
|
9
|
+
];
|
|
10
|
+
const facts = [];
|
|
11
|
+
for (const [owner, scope] of owners) {
|
|
12
|
+
const rows = await ctx.store.list({
|
|
13
|
+
project: owner,
|
|
14
|
+
sessionId: FACT_SESSION,
|
|
15
|
+
newest: true,
|
|
16
|
+
limit: EXISTING_LIMIT,
|
|
17
|
+
});
|
|
18
|
+
for (const obs of onePerKey(rows.filter((row) => row.status !== 'replaced'))) {
|
|
19
|
+
const key = factKey(obs);
|
|
20
|
+
const type = factType(obs);
|
|
21
|
+
if (obs.status === 'replaced' || !key || !type)
|
|
22
|
+
continue;
|
|
23
|
+
facts.push({ key, type, scope, text: obs.title });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return facts;
|
|
27
|
+
}
|
|
28
|
+
export async function notedByUser(ctx, project) {
|
|
29
|
+
const rows = await ctx.store.list({
|
|
30
|
+
project,
|
|
31
|
+
sessionId: MANUAL_SESSION,
|
|
32
|
+
newest: true,
|
|
33
|
+
limit: EXISTING_LIMIT,
|
|
34
|
+
});
|
|
35
|
+
return rows
|
|
36
|
+
.filter((row) => row.status !== 'replaced' && !row.tags.includes(HANDOFF_TAG))
|
|
37
|
+
.map((row) => row.title);
|
|
38
|
+
}
|
package/dist/facts/ops.d.ts
CHANGED
|
@@ -19,5 +19,5 @@ export interface RetireOp {
|
|
|
19
19
|
key: string;
|
|
20
20
|
}
|
|
21
21
|
export type FactOp = SetOp | RetireOp;
|
|
22
|
-
export declare function buildDistillPrompt(chat: string, existing: ExistingFact[]): string;
|
|
22
|
+
export declare function buildDistillPrompt(chat: string, existing: ExistingFact[], noted?: string[]): string;
|
|
23
23
|
export declare function parseOps(stdout: string): FactOp[];
|
package/dist/facts/ops.js
CHANGED
|
@@ -4,11 +4,12 @@ const KEY = /^[a-z0-9][a-z0-9-]{1,59}$/;
|
|
|
4
4
|
const TEXT_MAX = 200;
|
|
5
5
|
const WHY_MAX = 300;
|
|
6
6
|
const FILES_MAX = 5;
|
|
7
|
-
export function buildDistillPrompt(chat, existing) {
|
|
7
|
+
export function buildDistillPrompt(chat, existing, noted = []) {
|
|
8
8
|
return [
|
|
9
9
|
'You keep the long-term memory of a software project for a coding assistant. Read the',
|
|
10
10
|
'CHAT LOG of one past session and decide what is worth remembering in future sessions.',
|
|
11
|
-
'EXISTING FACTS are what is already remembered.',
|
|
11
|
+
'EXISTING FACTS are what is already remembered. NOTED BY THE USER are rules the user saved',
|
|
12
|
+
'by hand. They are remembered too, so never write a fact that repeats one of them.',
|
|
12
13
|
'',
|
|
13
14
|
'Write one JSON object per line, and nothing else:',
|
|
14
15
|
'{"op":"set","key":"short-kebab-key","type":"rule","scope":"project","text":"...","why":"...","files":["src/a.ts"]}',
|
|
@@ -33,6 +34,7 @@ export function buildDistillPrompt(chat, existing) {
|
|
|
33
34
|
...existing.map((fact) => `${fact.key} [${fact.type}, ${fact.scope}] ${fact.text}`),
|
|
34
35
|
'</existing-facts>',
|
|
35
36
|
'',
|
|
37
|
+
...(noted.length > 0 ? ['<noted-by-user>', ...noted, '</noted-by-user>', ''] : []),
|
|
36
38
|
'<chat-log>',
|
|
37
39
|
chat,
|
|
38
40
|
'</chat-log>',
|
package/dist/facts/start.js
CHANGED
|
@@ -3,6 +3,7 @@ import { FACT_SESSION, factType, onePerKey, youScope } from './model.js';
|
|
|
3
3
|
import { newestHandoff, handoffBodyLines } from './handoff.js';
|
|
4
4
|
import { MANUAL_SESSION, factLine, seenByClaude } from './render.js';
|
|
5
5
|
import { formatDay } from '../util/day.js';
|
|
6
|
+
import { toShortId } from '../util/shortid.js';
|
|
6
7
|
const ABOUT_YOU = 6;
|
|
7
8
|
const THIS_PROJECT = 10;
|
|
8
9
|
const TODOS = 4;
|
|
@@ -64,5 +65,8 @@ export async function startFacts(ctx, project, hidden = new Set()) {
|
|
|
64
65
|
return { block: lines.join('\n'), ids };
|
|
65
66
|
}
|
|
66
67
|
function handoffEntries(handoff) {
|
|
67
|
-
return handoffBodyLines(handoff).map((line, index) => [
|
|
68
|
+
return handoffBodyLines(handoff).map((line, index) => [
|
|
69
|
+
index === 0 ? `${line} (${toShortId(handoff.id)})` : line,
|
|
70
|
+
index === 0 ? handoff.id : null,
|
|
71
|
+
]);
|
|
68
72
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function sameNode(a, b) {
|
|
2
|
+
if (!a)
|
|
3
|
+
return false;
|
|
4
|
+
const left = a.range().start;
|
|
5
|
+
const right = b.range().start;
|
|
6
|
+
return left.line === right.line && left.column === right.column;
|
|
7
|
+
}
|
|
8
|
+
export function originFrom({ start, end }) {
|
|
9
|
+
return `${start.line}:${start.column}-${end.line}:${end.column}`;
|
|
10
|
+
}
|
|
11
|
+
export const originOf = (node) => originFrom(node.range());
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Grammar {
|
|
2
|
+
readonly libraryPath: string;
|
|
3
|
+
}
|
|
4
|
+
export type Load = (id: string) => unknown;
|
|
5
|
+
export declare const GRAMMARS: readonly string[];
|
|
6
|
+
export declare const PLATFORM: string;
|
|
7
|
+
export declare const PLATFORM_PACKAGE: string;
|
|
8
|
+
export declare const grammarHome: () => string;
|
|
9
|
+
export declare const isUsable: (grammar: unknown) => grammar is Grammar;
|
|
10
|
+
export declare function findGrammar(name: string, loads: readonly Load[]): Grammar | undefined;
|
|
11
|
+
export declare function loadGrammar(name: string): Grammar | undefined;
|
|
12
|
+
export declare const hasGrammar: (name: string) => boolean;
|
|
13
|
+
export declare const availableGrammars: () => string[];
|
|
14
|
+
export declare function grammarSignature(): string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { CONFIG_DIR } from '../config/dir.js';
|
|
5
|
+
export const GRAMMARS = ['go', 'java', 'kotlin', 'python', 'ruby', 'rust'];
|
|
6
|
+
export const PLATFORM = `${process.platform}-${process.arch}`;
|
|
7
|
+
export const PLATFORM_PACKAGE = `claude-db-grammars-${PLATFORM}`;
|
|
8
|
+
const loaded = new Map();
|
|
9
|
+
export const grammarHome = () => process.env.CLAUDE_DB_GRAMMARS ?? join(CONFIG_DIR, 'grammars');
|
|
10
|
+
const places = () => [
|
|
11
|
+
createRequire(import.meta.url),
|
|
12
|
+
createRequire(join(grammarHome(), 'package.json')),
|
|
13
|
+
];
|
|
14
|
+
function fromPlatform(load, name) {
|
|
15
|
+
const grammars = load(PLATFORM_PACKAGE);
|
|
16
|
+
return grammars[name];
|
|
17
|
+
}
|
|
18
|
+
function fromAstGrep(load, name) {
|
|
19
|
+
const grammar = load(`@ast-grep/lang-${name}`);
|
|
20
|
+
return grammar.default ?? grammar;
|
|
21
|
+
}
|
|
22
|
+
function librarySize(grammar) {
|
|
23
|
+
try {
|
|
24
|
+
const path = grammar.libraryPath;
|
|
25
|
+
return typeof path === 'string' && path.length > 0 ? statSync(path).size : 0;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export const isUsable = (grammar) => librarySize(grammar) > 0;
|
|
32
|
+
export function findGrammar(name, loads) {
|
|
33
|
+
for (const read of [fromPlatform, fromAstGrep]) {
|
|
34
|
+
for (const load of loads) {
|
|
35
|
+
try {
|
|
36
|
+
const grammar = read(load, name);
|
|
37
|
+
if (isUsable(grammar))
|
|
38
|
+
return grammar;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
export function loadGrammar(name) {
|
|
48
|
+
if (!loaded.has(name))
|
|
49
|
+
loaded.set(name, findGrammar(name, places()) ?? null);
|
|
50
|
+
return loaded.get(name) ?? undefined;
|
|
51
|
+
}
|
|
52
|
+
export const hasGrammar = (name) => loadGrammar(name) !== undefined;
|
|
53
|
+
export const availableGrammars = () => GRAMMARS.filter(hasGrammar);
|
|
54
|
+
export function grammarSignature() {
|
|
55
|
+
return availableGrammars()
|
|
56
|
+
.map((name) => `${name}:${librarySize(loadGrammar(name))}`)
|
|
57
|
+
.join(',');
|
|
58
|
+
}
|
package/dist/graph/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { LANGUAGES, languageFor, languageNames } from './languages/index.js';
|
|
2
|
-
export { SCAN_VERSION, currentHashes, hashOf, scanRepository } from './scan/index.js';
|
|
3
|
-
export { formatGraph, nearest, queryGraph, refreshGraph, suggestFor } from './query/index.js';
|
|
2
|
+
export { SCAN_VERSION, currentHashes, hashOf, saveScan, scanRepository } from './scan/index.js';
|
|
3
|
+
export { NO_GRAPH, NO_GRAPH_FOR_PATH, addText, answerQuery, formatGraph, formatText, hasGraph, nearest, queryGraph, refreshGraph, suggestFor, } from './query/index.js';
|
package/dist/graph/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { LANGUAGES, languageFor, languageNames } from './languages/index.js';
|
|
2
|
-
export { SCAN_VERSION, currentHashes, hashOf, scanRepository } from './scan/index.js';
|
|
3
|
-
export { formatGraph, nearest, queryGraph, refreshGraph, suggestFor } from './query/index.js';
|
|
2
|
+
export { SCAN_VERSION, currentHashes, hashOf, saveScan, scanRepository } from './scan/index.js';
|
|
3
|
+
export { NO_GRAPH, NO_GRAPH_FOR_PATH, addText, answerQuery, formatGraph, formatText, hasGraph, nearest, queryGraph, refreshGraph, suggestFor, } from './query/index.js';
|
|
@@ -2,8 +2,12 @@ const LABELS = {
|
|
|
2
2
|
c: ['.c', '.h'],
|
|
3
3
|
cpp: ['.cc', '.cpp', '.cxx', '.hpp', '.hh'],
|
|
4
4
|
csharp: ['.cs'],
|
|
5
|
-
java: ['.java'],
|
|
6
5
|
kotlin: ['.kt', '.kts'],
|
|
6
|
+
go: ['.go'],
|
|
7
|
+
java: ['.java'],
|
|
8
|
+
python: ['.py', '.pyi'],
|
|
9
|
+
ruby: ['.rb', '.rake'],
|
|
10
|
+
rust: ['.rs'],
|
|
7
11
|
swift: ['.swift'],
|
|
8
12
|
'objective-c': ['.m', '.mm'],
|
|
9
13
|
scala: ['.scala'],
|
|
@@ -9,6 +9,7 @@ const SHARED_REFERENCES = [
|
|
|
9
9
|
{ kind: 'call_expression', field: ['function', 'property'], relation: 'calls' },
|
|
10
10
|
{ kind: 'call_expression', field: ['function', 'object'], relation: 'references' },
|
|
11
11
|
{ kind: 'new_expression', field: ['constructor'], relation: 'calls' },
|
|
12
|
+
{ kind: 'new_expression', field: ['constructor', 'property'], relation: 'calls' },
|
|
12
13
|
{ kind: 'import_statement', field: ['source'], relation: 'imports' },
|
|
13
14
|
{ kind: 'export_statement', field: ['source'], relation: 'imports' },
|
|
14
15
|
];
|
|
@@ -37,6 +38,12 @@ const TYPED_REFERENCES = [
|
|
|
37
38
|
relation: 'references',
|
|
38
39
|
excludeParents: TYPE_DECLARATION_SITES,
|
|
39
40
|
},
|
|
41
|
+
{
|
|
42
|
+
kind: 'member_expression',
|
|
43
|
+
field: ['property'],
|
|
44
|
+
relation: 'references',
|
|
45
|
+
objectKinds: ['satisfies_expression', 'as_expression'],
|
|
46
|
+
},
|
|
40
47
|
];
|
|
41
48
|
export const typescript = {
|
|
42
49
|
id: 'TypeScript',
|
|
@@ -10,6 +10,5 @@ export const go = {
|
|
|
10
10
|
references: [
|
|
11
11
|
{ kind: 'call_expression', field: ['function'], relation: 'calls' },
|
|
12
12
|
{ kind: 'call_expression', field: ['function', 'field'], relation: 'calls' },
|
|
13
|
-
{ kind: 'import_spec', field: ['path'], relation: 'imports' },
|
|
14
13
|
],
|
|
15
14
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { LanguageSpec } from './rules.js';
|
|
2
2
|
export type { LanguageSpec } from './rules.js';
|
|
3
3
|
export declare const LANGUAGES: LanguageSpec[];
|
|
4
|
-
export declare const DYNAMIC_LANGUAGES: string[];
|
|
5
4
|
export { BASIC_FINGERPRINT, callsIn, declarationsIn } from './basic.js';
|
|
5
|
+
export declare const needsGrammar: (spec: LanguageSpec) => boolean;
|
|
6
6
|
export declare function languageFor(path: string): LanguageSpec | null;
|
|
7
7
|
export declare function languageNames(): string;
|
|
@@ -1,23 +1,48 @@
|
|
|
1
|
+
import { GRAMMARS, hasGrammar } from '../grammars.js';
|
|
1
2
|
import { BASIC_LANGUAGES } from './basic.js';
|
|
2
3
|
import { javascript, tsx, typescript } from './ecmascript.js';
|
|
3
4
|
import { go } from './go.js';
|
|
5
|
+
import { java } from './java.js';
|
|
6
|
+
import { kotlin } from './kotlin.js';
|
|
4
7
|
import { python } from './python.js';
|
|
5
8
|
import { ruby } from './ruby.js';
|
|
6
9
|
import { rust } from './rust.js';
|
|
7
|
-
export const LANGUAGES = [
|
|
8
|
-
|
|
10
|
+
export const LANGUAGES = [
|
|
11
|
+
typescript,
|
|
12
|
+
tsx,
|
|
13
|
+
javascript,
|
|
14
|
+
python,
|
|
15
|
+
go,
|
|
16
|
+
rust,
|
|
17
|
+
ruby,
|
|
18
|
+
java,
|
|
19
|
+
kotlin,
|
|
20
|
+
];
|
|
9
21
|
export { BASIC_FINGERPRINT, callsIn, declarationsIn } from './basic.js';
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
22
|
+
export const needsGrammar = (spec) => GRAMMARS.includes(spec.id);
|
|
23
|
+
const isReadable = (spec) => !needsGrammar(spec) || hasGrammar(spec.id);
|
|
24
|
+
const byExtension = (specs) => {
|
|
25
|
+
const found = new Map();
|
|
26
|
+
for (const spec of specs) {
|
|
27
|
+
for (const extension of spec.extensions)
|
|
28
|
+
found.set(extension, spec);
|
|
29
|
+
}
|
|
30
|
+
return found;
|
|
31
|
+
};
|
|
32
|
+
const REAL = byExtension(LANGUAGES);
|
|
33
|
+
const BASIC = byExtension(BASIC_LANGUAGES);
|
|
15
34
|
export function languageFor(path) {
|
|
16
35
|
const dot = path.lastIndexOf('.');
|
|
17
36
|
if (dot < 0)
|
|
18
37
|
return null;
|
|
19
|
-
|
|
38
|
+
const extension = path.slice(dot).toLowerCase();
|
|
39
|
+
const real = REAL.get(extension);
|
|
40
|
+
if (real && isReadable(real))
|
|
41
|
+
return real;
|
|
42
|
+
return BASIC.get(extension) ?? null;
|
|
20
43
|
}
|
|
21
44
|
export function languageNames() {
|
|
22
|
-
|
|
45
|
+
const parsed = LANGUAGES.filter(isReadable).map((spec) => spec.label);
|
|
46
|
+
const patterns = BASIC_LANGUAGES.filter((spec) => !parsed.includes(spec.label));
|
|
47
|
+
return `${parsed.join(', ')}, and ${patterns.length} more by pattern`;
|
|
23
48
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const TYPES = [
|
|
2
|
+
{ kind: 'type_identifier' },
|
|
3
|
+
{ kind: 'scoped_type_identifier' },
|
|
4
|
+
{ kind: 'generic_type', select: ['type_identifier', 'scoped_type_identifier'] },
|
|
5
|
+
];
|
|
6
|
+
export const java = {
|
|
7
|
+
id: 'java',
|
|
8
|
+
label: 'java',
|
|
9
|
+
extensions: ['.java'],
|
|
10
|
+
definitions: [
|
|
11
|
+
{ kind: 'class_declaration', field: ['name'], symbol: 'class' },
|
|
12
|
+
{ kind: 'record_declaration', field: ['name'], symbol: 'class' },
|
|
13
|
+
{ kind: 'interface_declaration', field: ['name'], symbol: 'interface' },
|
|
14
|
+
{ kind: 'annotation_type_declaration', field: ['name'], symbol: 'interface' },
|
|
15
|
+
{ kind: 'enum_declaration', field: ['name'], symbol: 'enum' },
|
|
16
|
+
{ kind: 'method_declaration', field: ['name'], symbol: 'method' },
|
|
17
|
+
],
|
|
18
|
+
references: [
|
|
19
|
+
{ kind: 'method_invocation', field: ['name'], relation: 'calls' },
|
|
20
|
+
{ kind: 'method_invocation', field: ['name'], qualifier: 'object', relation: 'calls' },
|
|
21
|
+
{ kind: 'object_creation_expression', field: [], relation: 'calls', listOf: TYPES },
|
|
22
|
+
{ kind: 'superclass', field: [], relation: 'extends', listOf: TYPES },
|
|
23
|
+
{
|
|
24
|
+
kind: 'type_list',
|
|
25
|
+
field: [],
|
|
26
|
+
relation: 'implements',
|
|
27
|
+
parents: ['super_interfaces'],
|
|
28
|
+
listOf: TYPES,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
kind: 'type_list',
|
|
32
|
+
field: [],
|
|
33
|
+
relation: 'extends',
|
|
34
|
+
parents: ['extends_interfaces'],
|
|
35
|
+
listOf: TYPES,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const BODIES = ['class_body', 'enum_class_body'];
|
|
2
|
+
export const kotlin = {
|
|
3
|
+
id: 'kotlin',
|
|
4
|
+
label: 'kotlin',
|
|
5
|
+
extensions: ['.kt', '.kts'],
|
|
6
|
+
definitions: [
|
|
7
|
+
{ kind: 'class_declaration', field: [], nameKind: 'type_identifier', symbol: 'class' },
|
|
8
|
+
{ kind: 'object_declaration', field: [], nameKind: 'type_identifier', symbol: 'class' },
|
|
9
|
+
{ kind: 'type_alias', field: [], nameKind: 'type_identifier', symbol: 'type' },
|
|
10
|
+
{
|
|
11
|
+
kind: 'function_declaration',
|
|
12
|
+
field: [],
|
|
13
|
+
nameKind: 'simple_identifier',
|
|
14
|
+
symbol: 'function',
|
|
15
|
+
memberOf: BODIES,
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
references: [],
|
|
19
|
+
};
|
|
@@ -9,7 +9,15 @@ export const python = {
|
|
|
9
9
|
references: [
|
|
10
10
|
{ kind: 'call', field: ['function'], relation: 'calls' },
|
|
11
11
|
{ kind: 'call', field: ['function', 'attribute'], relation: 'calls' },
|
|
12
|
-
{
|
|
13
|
-
|
|
12
|
+
{
|
|
13
|
+
kind: 'class_definition',
|
|
14
|
+
field: ['superclasses'],
|
|
15
|
+
relation: 'extends',
|
|
16
|
+
listOf: [
|
|
17
|
+
{ kind: 'identifier' },
|
|
18
|
+
{ kind: 'attribute' },
|
|
19
|
+
{ kind: 'subscript', field: 'value' },
|
|
20
|
+
],
|
|
21
|
+
},
|
|
14
22
|
],
|
|
15
23
|
};
|
|
@@ -3,6 +3,13 @@ export interface DefinitionRule {
|
|
|
3
3
|
kind: string;
|
|
4
4
|
field: string[];
|
|
5
5
|
symbol: SymbolKind;
|
|
6
|
+
nameKind?: string;
|
|
7
|
+
memberOf?: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface ListItem {
|
|
10
|
+
kind: string;
|
|
11
|
+
field?: string;
|
|
12
|
+
select?: string[];
|
|
6
13
|
}
|
|
7
14
|
export interface ReferenceRule {
|
|
8
15
|
kind: string;
|
|
@@ -10,6 +17,10 @@ export interface ReferenceRule {
|
|
|
10
17
|
relation: EdgeRelation;
|
|
11
18
|
namePattern?: RegExp;
|
|
12
19
|
excludeParents?: string[];
|
|
20
|
+
objectKinds?: string[];
|
|
21
|
+
listOf?: ListItem[];
|
|
22
|
+
qualifier?: string;
|
|
23
|
+
parents?: string[];
|
|
13
24
|
}
|
|
14
25
|
export interface LanguageSpec {
|
|
15
26
|
id: string;
|
|
@@ -11,6 +11,7 @@ export const rust = {
|
|
|
11
11
|
],
|
|
12
12
|
references: [
|
|
13
13
|
{ kind: 'call_expression', field: ['function'], relation: 'calls' },
|
|
14
|
-
{ kind: '
|
|
14
|
+
{ kind: 'call_expression', field: ['function', 'name'], relation: 'calls' },
|
|
15
|
+
{ kind: 'call_expression', field: ['function', 'field'], relation: 'calls' },
|
|
15
16
|
],
|
|
16
17
|
};
|