claude-db 0.12.4 → 0.14.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 +93 -0
- package/dist/capture/cursors.d.ts +6 -0
- package/dist/capture/cursors.js +80 -0
- package/dist/capture/flush.d.ts +1 -3
- package/dist/capture/flush.js +35 -96
- package/dist/capture/index.d.ts +3 -3
- package/dist/capture/index.js +3 -3
- package/dist/capture/progress.js +4 -2
- package/dist/capture/reingest.d.ts +1 -0
- package/dist/capture/reingest.js +4 -1
- package/dist/capture/scrub.d.ts +1 -0
- package/dist/capture/scrub.js +4 -1
- package/dist/capture/transcript.d.ts +1 -1
- package/dist/capture/transcript.js +6 -6
- package/dist/capture/vectors.js +2 -1
- package/dist/catchup/gather.js +1 -1
- package/dist/cli/commands/catchup.js +2 -1
- package/dist/cli/commands/daemon.d.ts +1 -0
- package/dist/cli/commands/daemon.js +29 -0
- package/dist/cli/commands/distill.js +2 -1
- package/dist/cli/commands/graph.js +11 -11
- package/dist/cli/commands/insight.js +10 -1
- package/dist/cli/commands/maintain.js +3 -1
- package/dist/cli/commands/memory.js +2 -1
- package/dist/cli/commands/setup.js +1 -2
- package/dist/cli/commands/sync.js +4 -1
- package/dist/cli/index.js +4 -0
- package/dist/cli/install.js +1 -2
- package/dist/cli/instructions.d.ts +1 -3
- package/dist/cli/instructions.js +5 -40
- package/dist/cli/refresh.js +2 -6
- package/dist/cli/usage.js +1 -0
- package/dist/config/load.js +2 -1
- package/dist/config/schema.d.ts +4 -2
- package/dist/config/schema.js +6 -2
- package/dist/context.d.ts +1 -0
- package/dist/context.js +30 -6
- package/dist/daemon/client.d.ts +14 -0
- package/dist/daemon/client.js +106 -0
- package/dist/daemon/paths.d.ts +18 -0
- package/dist/daemon/paths.js +19 -0
- package/dist/daemon/pid.d.ts +3 -0
- package/dist/daemon/pid.js +20 -0
- package/dist/daemon/server.d.ts +2 -0
- package/dist/daemon/server.js +227 -0
- package/dist/embed/local.js +4 -1
- package/dist/facts/budget.d.ts +1 -0
- package/dist/facts/budget.js +4 -0
- package/dist/facts/claude-memory.js +3 -3
- package/dist/facts/distill.js +2 -2
- package/dist/facts/known.js +1 -1
- package/dist/facts/last-chat.d.ts +1 -1
- package/dist/facts/last-chat.js +5 -4
- package/dist/facts/model.d.ts +1 -1
- package/dist/facts/model.js +31 -16
- package/dist/facts/start-render.d.ts +13 -0
- package/dist/facts/start-render.js +43 -0
- package/dist/facts/start.d.ts +3 -6
- package/dist/facts/start.js +33 -47
- package/dist/graph/grammars.js +2 -1
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/graph/query/index.d.ts +1 -0
- package/dist/graph/query/index.js +1 -0
- package/dist/graph/query/refresh.js +5 -1
- package/dist/graph/query/stale.js +19 -2
- package/dist/graph/query/usages.d.ts +12 -0
- package/dist/graph/query/usages.js +37 -0
- package/dist/graph/scan/cache.d.ts +1 -0
- package/dist/graph/scan/cache.js +3 -2
- package/dist/graph/scan/files.js +2 -2
- package/dist/graph/scan/persist.js +12 -16
- package/dist/hooks/compact.d.ts +3 -1
- package/dist/hooks/compact.js +4 -3
- package/dist/hooks/detached.js +2 -0
- package/dist/hooks/graph-presence.d.ts +3 -0
- package/dist/hooks/graph-presence.js +42 -0
- package/dist/hooks/grep-symbols.d.ts +3 -1
- package/dist/hooks/grep-symbols.js +41 -2
- package/dist/hooks/handlers/prefer-usages.d.ts +2 -0
- package/dist/hooks/handlers/prefer-usages.js +118 -0
- package/dist/hooks/handlers/session-end.d.ts +2 -0
- package/dist/hooks/handlers/session-end.js +60 -0
- package/dist/hooks/handlers/session-start.d.ts +2 -0
- package/dist/hooks/handlers/session-start.js +83 -0
- package/dist/hooks/handlers/turn-end.d.ts +2 -0
- package/dist/hooks/handlers/turn-end.js +31 -0
- package/dist/hooks/handlers/user-prompt.d.ts +2 -0
- package/dist/hooks/handlers/user-prompt.js +55 -0
- package/dist/hooks/local.d.ts +2 -0
- package/dist/hooks/local.js +22 -0
- package/dist/hooks/payload.d.ts +9 -4
- package/dist/hooks/payload.js +30 -20
- package/dist/hooks/pick-deliver.js +2 -1
- package/dist/hooks/prefer-usages.js +2 -118
- package/dist/hooks/prompt-recall.d.ts +4 -2
- package/dist/hooks/prompt-recall.js +10 -10
- package/dist/hooks/route.d.ts +2 -0
- package/dist/hooks/route.js +33 -0
- package/dist/hooks/run.d.ts +13 -0
- package/dist/hooks/run.js +12 -0
- package/dist/hooks/save-turn.d.ts +2 -0
- package/dist/hooks/save-turn.js +11 -0
- package/dist/hooks/session-end.js +2 -63
- package/dist/hooks/session-start.js +2 -90
- package/dist/hooks/turn-end.js +2 -25
- package/dist/hooks/turn-save.js +10 -15
- package/dist/hooks/user-prompt.js +2 -58
- package/dist/mcp/tools/ids.d.ts +3 -0
- package/dist/mcp/tools/ids.js +6 -0
- package/dist/mcp/tools/memory.js +2 -1
- package/dist/mcp/tools/observations.js +3 -2
- package/dist/mcp/tools/search.js +4 -9
- package/dist/mcp/tools/usages.js +18 -44
- package/dist/pick/worker.js +1 -2
- package/dist/search/service.d.ts +6 -0
- package/dist/search/service.js +27 -11
- package/dist/store/adapter.d.ts +7 -5
- package/dist/store/mongo/index.d.ts +3 -6
- package/dist/store/mongo/index.js +5 -0
- package/dist/store/mongo/observations.js +13 -1
- package/dist/store/postgres/driver.d.ts +10 -3
- package/dist/store/postgres/driver.js +12 -0
- package/dist/store/postgres/filters.d.ts +1 -0
- package/dist/store/postgres/filters.js +3 -0
- package/dist/store/postgres/graph.d.ts +3 -5
- package/dist/store/postgres/graph.js +59 -52
- package/dist/store/postgres/index.d.ts +3 -6
- package/dist/store/postgres/index.js +8 -5
- package/dist/store/postgres/insert.js +98 -50
- package/dist/store/postgres/meta.d.ts +1 -0
- package/dist/store/postgres/meta.js +4 -0
- package/dist/store/postgres/observations.js +3 -3
- package/dist/store/project-resolver.d.ts +4 -0
- package/dist/store/project-resolver.js +34 -23
- package/dist/store/scoped-store.js +4 -2
- package/dist/store/sqlite/filters.d.ts +1 -0
- package/dist/store/sqlite/filters.js +6 -2
- package/dist/store/sqlite/graph.d.ts +3 -5
- package/dist/store/sqlite/graph.js +45 -35
- package/dist/store/sqlite/index.d.ts +3 -6
- package/dist/store/sqlite/index.js +3 -0
- package/dist/store/sqlite/observations.js +12 -9
- package/dist/util/claude-binary.js +5 -4
- package/dist/util/claude-cli.js +2 -1
- package/dist/util/claude-dir.d.ts +2 -0
- package/dist/util/claude-dir.js +8 -0
- package/dist/util/env.d.ts +2 -0
- package/dist/util/env.js +6 -0
- package/dist/util/job-lock.d.ts +1 -0
- package/dist/util/job-lock.js +50 -10
- package/dist/util/shortid.d.ts +3 -0
- package/dist/util/shortid.js +11 -0
- package/docs/how-it-works.md +5 -10
- package/docs/setup-guide.md +6 -1
- package/package.json +7 -6
- package/dist/hooks/start-legacy.d.ts +0 -6
- package/dist/hooks/start-legacy.js +0 -47
package/dist/hooks/turn-end.js
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { resolveProject } from '../util/project.js';
|
|
5
|
-
import { TURN_WORKER, runDetached } from './detached.js';
|
|
6
|
-
import { capturingDisabled, readPayload, runHook } from './payload.js';
|
|
7
|
-
import { queueTurnSave } from './turn-job.js';
|
|
8
|
-
await runHook(async () => {
|
|
9
|
-
if (capturingDisabled(loadConfig().capture.scripted))
|
|
10
|
-
return;
|
|
11
|
-
const payload = await readPayload();
|
|
12
|
-
const sessionId = payload.session_id;
|
|
13
|
-
if (!sessionId)
|
|
14
|
-
return;
|
|
15
|
-
const project = resolveProject(payload.cwd);
|
|
16
|
-
const tasks = Array.isArray(payload.background_tasks) ? payload.background_tasks : [];
|
|
17
|
-
const crons = Array.isArray(payload.session_crons) ? payload.session_crons : [];
|
|
18
|
-
const stillWorking = crons.length > 0 || tasks.some((task) => task?.status === 'running');
|
|
19
|
-
queueTurnSave(sessionId, {
|
|
20
|
-
project,
|
|
21
|
-
...(payload.transcript_path ? { transcriptPath: payload.transcript_path } : {}),
|
|
22
|
-
finalReply: payload.last_assistant_message ?? '',
|
|
23
|
-
activeToken: stillWorking ? null : activeToken(sessionId),
|
|
24
|
-
});
|
|
25
|
-
runDetached(TURN_WORKER, [sessionId], project, () => { });
|
|
26
|
-
});
|
|
2
|
+
import { routeHook } from './route.js';
|
|
3
|
+
await routeHook('turn-end');
|
package/dist/hooks/turn-save.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { clearActive } from '../capture/active.js';
|
|
3
|
-
import { flushSession } from '../capture/index.js';
|
|
4
2
|
import { createContext } from '../context.js';
|
|
5
3
|
import { silenceSqliteWarning } from '../util/warnings.js';
|
|
6
4
|
import { runHook } from './payload.js';
|
|
7
|
-
import {
|
|
5
|
+
import { saveQueuedTurn } from './save-turn.js';
|
|
8
6
|
silenceSqliteWarning();
|
|
9
7
|
await runHook(async () => {
|
|
10
8
|
const [sessionId] = process.argv.slice(2);
|
|
11
9
|
if (!sessionId)
|
|
12
10
|
return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
if (job.activeToken)
|
|
24
|
-
clearActive(sessionId, job.activeToken);
|
|
11
|
+
await saveQueuedTurn(sessionId, async (work) => {
|
|
12
|
+
const ctx = await createContext();
|
|
13
|
+
try {
|
|
14
|
+
return await work(ctx);
|
|
15
|
+
}
|
|
16
|
+
finally {
|
|
17
|
+
await ctx.close();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
25
20
|
});
|
|
@@ -1,59 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { createContext } from '../context.js';
|
|
5
|
-
import { capturingDisabled, emitContext, readPayload, runHook } from './payload.js';
|
|
6
|
-
import { loadConfig } from '../config/index.js';
|
|
7
|
-
import { markShown, readShown } from './shown.js';
|
|
8
|
-
import { promptCandidates, strictRecall, withCost } from './prompt-recall.js';
|
|
9
|
-
import { pickInBackground } from './background.js';
|
|
10
|
-
import { clearPick, startPick } from '../pick/pending.js';
|
|
11
|
-
import { takePick } from '../pick/run.js';
|
|
12
|
-
import { resolveProject } from '../util/project.js';
|
|
13
|
-
import { silenceSqliteWarning } from '../util/warnings.js';
|
|
14
|
-
silenceSqliteWarning();
|
|
15
|
-
await runHook(async () => {
|
|
16
|
-
if (capturingDisabled(loadConfig().capture.scripted))
|
|
17
|
-
return;
|
|
18
|
-
const payload = await readPayload();
|
|
19
|
-
const sessionId = payload.session_id;
|
|
20
|
-
if (!sessionId)
|
|
21
|
-
return;
|
|
22
|
-
const project = resolveProject(payload.cwd);
|
|
23
|
-
const ctx = await createContext();
|
|
24
|
-
try {
|
|
25
|
-
await ctx.store.upsertSession({ id: sessionId, project, startedAt: Date.now() });
|
|
26
|
-
recordActive(sessionId, project, payload.prompt ?? '');
|
|
27
|
-
const { lastReply } = await flushSession(ctx, sessionId, project, payload.transcript_path);
|
|
28
|
-
const candidates = await promptCandidates(ctx, {
|
|
29
|
-
prompt: payload.prompt ?? '',
|
|
30
|
-
project,
|
|
31
|
-
sessionId,
|
|
32
|
-
shown: readShown(sessionId),
|
|
33
|
-
});
|
|
34
|
-
if (!candidates) {
|
|
35
|
-
clearPick(sessionId);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const fallback = await strictRecall(ctx, candidates);
|
|
39
|
-
if (takePick(ctx.config)) {
|
|
40
|
-
const token = startPick(sessionId, {
|
|
41
|
-
project,
|
|
42
|
-
prompt: redact(candidates.prompt),
|
|
43
|
-
previousReply: redact(lastReply),
|
|
44
|
-
ids: candidates.entries.map((entry) => entry.id),
|
|
45
|
-
fallback: fallback ? { text: withCost(fallback.block), ids: fallback.ids } : null,
|
|
46
|
-
});
|
|
47
|
-
pickInBackground(project, sessionId, token);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
clearPick(sessionId);
|
|
51
|
-
if (!fallback)
|
|
52
|
-
return;
|
|
53
|
-
markShown(sessionId, fallback.ids);
|
|
54
|
-
emitContext(withCost(fallback.block));
|
|
55
|
-
}
|
|
56
|
-
finally {
|
|
57
|
-
await ctx.close();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
2
|
+
import { routeHook } from './route.js';
|
|
3
|
+
await routeHook('user-prompt');
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { INVALID_ID_HINT, isObservationId } from '../../util/shortid.js';
|
|
3
|
+
export const observationIdSchema = z.string().refine(isObservationId, {
|
|
4
|
+
error: (issue) => `${JSON.stringify(issue.input)} ${INVALID_ID_HINT}`,
|
|
5
|
+
});
|
|
6
|
+
export const observationIdsSchema = z.array(observationIdSchema).min(1).max(25);
|
package/dist/mcp/tools/memory.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { observationIdsSchema } from './ids.js';
|
|
2
3
|
import { KINDS } from './kinds.js';
|
|
3
4
|
import { remember as record } from '../../capture/index.js';
|
|
4
5
|
import { toShortId } from '../../util/shortid.js';
|
|
@@ -19,7 +20,7 @@ export function register(server, ctx) {
|
|
|
19
20
|
tags: z.array(z.string()).max(5).optional().describe('Extra tags for filtering'),
|
|
20
21
|
}, (args) => remember(ctx, args));
|
|
21
22
|
server.tool('forget', 'Delete observations by id, for memory that is wrong or obsolete. Ids come ' +
|
|
22
|
-
'from search. This cannot be undone, so confirm with the user first.', { ids:
|
|
23
|
+
'from search. This cannot be undone, so confirm with the user first.', { ids: observationIdsSchema }, (args) => forget(ctx, args));
|
|
23
24
|
}
|
|
24
25
|
async function remember(ctx, { text, kind, project, key, tags, }) {
|
|
25
26
|
const observation = await record(ctx, {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { observationIdSchema, observationIdsSchema } from './ids.js';
|
|
2
3
|
import { renderFull, renderIndex } from '../render.js';
|
|
3
4
|
export function register(server, ctx) {
|
|
4
5
|
server.tool('timeline', 'Given one observation id from search, show what happened immediately before ' +
|
|
5
6
|
'and after it. Use it when a single result is not enough to explain itself ' +
|
|
6
7
|
'and you need the session around it — what led to a decision and what came ' +
|
|
7
8
|
'of it. Ids are the short ids search prints.', {
|
|
8
|
-
observation_id:
|
|
9
|
+
observation_id: observationIdSchema,
|
|
9
10
|
before: z.number().int().min(0).max(20).default(5),
|
|
10
11
|
after: z.number().int().min(0).max(20).default(5),
|
|
11
12
|
}, (args) => timeline(ctx, args));
|
|
@@ -13,7 +14,7 @@ export function register(server, ctx) {
|
|
|
13
14
|
'ids it printed. Use it whenever a search snippet looks like it answers your ' +
|
|
14
15
|
'question but is cut off — the snippet is one line, the body is the reasoning. ' +
|
|
15
16
|
'Always batch every id you need into one call rather than calling repeatedly.', {
|
|
16
|
-
ids:
|
|
17
|
+
ids: observationIdsSchema,
|
|
17
18
|
chars: z
|
|
18
19
|
.number()
|
|
19
20
|
.int()
|
package/dist/mcp/tools/search.js
CHANGED
|
@@ -3,15 +3,10 @@ import { KINDS } from './kinds.js';
|
|
|
3
3
|
import { renderIndex } from '../render.js';
|
|
4
4
|
import { resolveProject } from '../../util/project.js';
|
|
5
5
|
export function register(server, ctx) {
|
|
6
|
-
server.tool('search', '
|
|
7
|
-
'
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
'reasoning behind them, which the source code cannot tell you. Returns a ' +
|
|
11
|
-
'compact index (id, kind, date, title, and a line of the matching body) ' +
|
|
12
|
-
'without full bodies; use the snippet to decide which ids are worth passing ' +
|
|
13
|
-
'to get_observations rather than expanding on the title alone. For a code ' +
|
|
14
|
-
'symbol use find_usages instead.', {
|
|
6
|
+
server.tool('search', 'Answers WHY: decisions, dead ends, bugs and the reasoning behind them, which the ' +
|
|
7
|
+
'source code cannot tell you. Returns a compact index (id, kind, date, title, a line ' +
|
|
8
|
+
'of the matching body) without full bodies; pick the ids worth passing to ' +
|
|
9
|
+
'get_observations from the snippet. For a code symbol use find_usages instead.', {
|
|
15
10
|
query: z.string().describe('Natural language description of what you need'),
|
|
16
11
|
project: z
|
|
17
12
|
.string()
|
package/dist/mcp/tools/usages.js
CHANGED
|
@@ -1,61 +1,43 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { findUsages as textUsages, formatUsages
|
|
3
|
-
import { NO_GRAPH, NO_GRAPH_FOR_PATH,
|
|
2
|
+
import { findUsages as textUsages, formatUsages } from '../../usages/index.js';
|
|
3
|
+
import { NO_GRAPH, NO_GRAPH_FOR_PATH, hasGraph, suggestFor, usagesAnswer, } from '../../graph/index.js';
|
|
4
4
|
import { resolveProject } from '../../util/project.js';
|
|
5
5
|
export function register(server, ctx) {
|
|
6
|
-
server.tool('find_usages', '
|
|
7
|
-
'
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'
|
|
12
|
-
'
|
|
13
|
-
|
|
14
|
-
'grep lines the graph could not link; "explain" adds what the symbol reaches, ' +
|
|
15
|
-
'"path" traces how two symbols connect (pass the second as `target`), and ' +
|
|
16
|
-
'"text" is a plain live `git grep`. Graph modes re-parse anything that ' +
|
|
17
|
-
'changed before replying, and answer from text until `claude-db scan` has ' +
|
|
18
|
-
'run. Every edge is tagged EXTRACTED (read literally from the syntax) or ' +
|
|
19
|
-
'INFERRED (matched by name across files, with a score). A miss suggests near ' +
|
|
20
|
-
'names, so a half-remembered symbol is still worth asking about. Use `search` ' +
|
|
21
|
-
'instead for "why is this the way it is" (history).', {
|
|
22
|
-
symbol: z
|
|
23
|
-
.string()
|
|
24
|
-
.min(1)
|
|
25
|
-
.max(200)
|
|
26
|
-
.describe('Exact name to search for, e.g. "useAuth" or "CartButton"'),
|
|
6
|
+
server.tool('find_usages', 'Look up a code symbol (function, class, method, type, constant): what references it ' +
|
|
7
|
+
'and how. Use it before editing, renaming or deleting one; use grep for plain text, ' +
|
|
8
|
+
'comments, logs and strings. Modes: "usages" (default) lists references with their ' +
|
|
9
|
+
'relation, then grep lines the graph could not link; "explain" adds what the symbol ' +
|
|
10
|
+
'reaches; "path" shows how `symbol` connects to `target`; "text" is a live git grep. ' +
|
|
11
|
+
'Edges are EXTRACTED (from syntax) or INFERRED (matched by name, scored). A miss ' +
|
|
12
|
+
'suggests near names.', {
|
|
13
|
+
symbol: z.string().min(1).max(200).describe('Exact name, e.g. "useAuth"'),
|
|
27
14
|
mode: z
|
|
28
15
|
.enum(['text', 'usages', 'explain', 'path'])
|
|
29
16
|
.default('usages')
|
|
30
|
-
.describe('
|
|
31
|
-
|
|
32
|
-
target: z.string().optional().describe('The second symbol, for mode "path" only'),
|
|
17
|
+
.describe('Default "usages"'),
|
|
18
|
+
target: z.string().optional().describe('Second symbol, for mode "path"'),
|
|
33
19
|
path: z
|
|
34
20
|
.string()
|
|
35
21
|
.optional()
|
|
36
|
-
.describe('A file or
|
|
37
|
-
'repository (never narrows on its own — a blast-radius check that quietly ' +
|
|
38
|
-
'skipped part of the repo would be worse than no check). Must be inside a ' +
|
|
39
|
-
'git working tree. Different from the memory tools’ project param, which ' +
|
|
40
|
-
'can point at a folder pooling several repos rather than being one itself'),
|
|
22
|
+
.describe('A file or folder inside a git working tree; omit for the whole repository'),
|
|
41
23
|
regex: z
|
|
42
24
|
.boolean()
|
|
43
25
|
.default(false)
|
|
44
|
-
.describe('Treat symbol as
|
|
26
|
+
.describe('Treat symbol as a regular expression (mode "text" only)'),
|
|
45
27
|
context: z
|
|
46
28
|
.number()
|
|
47
29
|
.int()
|
|
48
30
|
.min(0)
|
|
49
31
|
.max(10)
|
|
50
32
|
.default(0)
|
|
51
|
-
.describe('Lines of
|
|
33
|
+
.describe('Lines of context around each match (mode "text" only)'),
|
|
52
34
|
limit: z
|
|
53
35
|
.number()
|
|
54
36
|
.int()
|
|
55
37
|
.min(1)
|
|
56
38
|
.max(500)
|
|
57
39
|
.default(100)
|
|
58
|
-
.describe('Cap on matching lines
|
|
40
|
+
.describe('Cap on matching lines; the result says how many more exist'),
|
|
59
41
|
}, (args) => find_usages(ctx, args));
|
|
60
42
|
}
|
|
61
43
|
const reply = (text) => ({ content: [{ type: 'text', text }] });
|
|
@@ -76,14 +58,6 @@ async function find_usages(ctx, args) {
|
|
|
76
58
|
return reply(NO_GRAPH_FOR_PATH);
|
|
77
59
|
return reply(`${NO_GRAPH}\n${await textAnswer(ctx, args)}`);
|
|
78
60
|
}
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const answer = await answerQuery({
|
|
82
|
-
store: ctx.store,
|
|
83
|
-
root,
|
|
84
|
-
project,
|
|
85
|
-
query: { mode, symbol, ...(target ? { target } : {}), limit },
|
|
86
|
-
refresh: true,
|
|
87
|
-
});
|
|
88
|
-
return reply(formatGraph(answer, root));
|
|
61
|
+
const { mode, symbol, target, limit, path } = args;
|
|
62
|
+
return reply(await usagesAnswer({ store: ctx.store, project, mode, symbol, target, limit, path }));
|
|
89
63
|
}
|
package/dist/pick/worker.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createContext } from '../context.js';
|
|
3
3
|
import { runHook } from '../hooks/payload.js';
|
|
4
|
-
import { withCost } from '../hooks/prompt-recall.js';
|
|
5
4
|
import { silenceSqliteWarning } from '../util/warnings.js';
|
|
6
5
|
import { finishPick, takeJob } from './pending.js';
|
|
7
6
|
import { headlessPicker, pickMemories, recordPickFailure, recordPickSuccess } from './run.js';
|
|
@@ -24,7 +23,7 @@ await runHook(async () => {
|
|
|
24
23
|
}
|
|
25
24
|
recordPickSuccess();
|
|
26
25
|
if (outcome.kind === 'picked') {
|
|
27
|
-
finishPick(sessionId, token, { text:
|
|
26
|
+
finishPick(sessionId, token, { text: `${outcome.block}\n`, ids: outcome.ids });
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
29
|
finally {
|
package/dist/search/service.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import type { Embedder } from '../embed/index.js';
|
|
2
2
|
import type { MemoryStore } from '../store/adapter.js';
|
|
3
3
|
import type { Observation, ObservationIndexEntry, SearchQuery, TimelineQuery } from '../types.js';
|
|
4
|
+
export interface RankedCandidates {
|
|
5
|
+
keyword: ObservationIndexEntry[];
|
|
6
|
+
fused: ObservationIndexEntry[];
|
|
7
|
+
}
|
|
4
8
|
export declare class SearchService {
|
|
5
9
|
private readonly store;
|
|
6
10
|
private readonly embedder;
|
|
7
11
|
private readonly maxScanCandidates;
|
|
8
12
|
constructor(store: MemoryStore, embedder: Embedder | (() => Promise<Embedder>), maxScanCandidates?: number);
|
|
9
13
|
search(query: SearchQuery): Promise<ObservationIndexEntry[]>;
|
|
14
|
+
candidates(query: SearchQuery): Promise<RankedCandidates>;
|
|
15
|
+
private embed;
|
|
10
16
|
private vectorSearch;
|
|
11
17
|
timeline(query: TimelineQuery): Promise<ObservationIndexEntry[]>;
|
|
12
18
|
getObservations(ids: string[]): Promise<Observation[]>;
|
package/dist/search/service.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { applyRecencyBoost, fuse } from './rank.js';
|
|
2
2
|
import { meaningfulTokens } from './stopwords.js';
|
|
3
|
+
const WIDE_FACTOR = 3;
|
|
3
4
|
export class SearchService {
|
|
4
5
|
store;
|
|
5
6
|
embedder;
|
|
@@ -10,26 +11,41 @@ export class SearchService {
|
|
|
10
11
|
this.maxScanCandidates = maxScanCandidates;
|
|
11
12
|
}
|
|
12
13
|
async search(query) {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const { fused } = await this.candidates(query);
|
|
15
|
+
return applyRecencyBoost(fused, query.until ?? Date.now());
|
|
16
|
+
}
|
|
17
|
+
async candidates(query) {
|
|
18
|
+
const keywordText = meaningfulTokens(query.text).join(' ');
|
|
19
|
+
if (keywordText === '')
|
|
20
|
+
return { keyword: [], fused: [] };
|
|
15
21
|
const wide = {
|
|
16
22
|
...query,
|
|
17
|
-
limit: query.limit *
|
|
23
|
+
limit: query.limit * WIDE_FACTOR,
|
|
18
24
|
maxScanCandidates: query.maxScanCandidates ?? this.maxScanCandidates,
|
|
19
25
|
};
|
|
20
|
-
const
|
|
21
|
-
const
|
|
26
|
+
const embedded = this.embed(wide.text);
|
|
27
|
+
const keyword = await this.store.searchKeyword({ ...wide, text: keywordText }).catch(() => []);
|
|
28
|
+
const vector = await this.vectorSearch(wide, await embedded);
|
|
22
29
|
const fused = fuse([keyword, vector].filter((r) => r.length > 0), query.limit);
|
|
23
|
-
return
|
|
30
|
+
return { keyword, fused };
|
|
24
31
|
}
|
|
25
|
-
async
|
|
32
|
+
async embed(text) {
|
|
26
33
|
try {
|
|
27
34
|
const embedder = typeof this.embedder === 'function' ? await this.embedder() : this.embedder;
|
|
28
35
|
if (embedder.dimensions === 0)
|
|
29
|
-
return
|
|
30
|
-
const [embedding] = await embedder.embed([
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
return null;
|
|
37
|
+
const [embedding] = await embedder.embed([text]);
|
|
38
|
+
return embedding && embedding.length > 0 ? { embedder, embedding } : null;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async vectorSearch(query, embedded) {
|
|
45
|
+
if (!embedded)
|
|
46
|
+
return [];
|
|
47
|
+
const { embedder, embedding } = embedded;
|
|
48
|
+
try {
|
|
33
49
|
const candidates = await this.store.searchVector(embedding, {
|
|
34
50
|
...query,
|
|
35
51
|
embedder: embedder.id,
|
package/dist/store/adapter.d.ts
CHANGED
|
@@ -4,6 +4,11 @@ export interface ProjectSummary {
|
|
|
4
4
|
observations: number;
|
|
5
5
|
lastActive: number;
|
|
6
6
|
}
|
|
7
|
+
export interface GraphRows {
|
|
8
|
+
symbols: CodeSymbol[];
|
|
9
|
+
edges: CodeEdge[];
|
|
10
|
+
files: ScannedFile[];
|
|
11
|
+
}
|
|
7
12
|
export interface MemoryStore {
|
|
8
13
|
readonly kind: string;
|
|
9
14
|
init(): Promise<void>;
|
|
@@ -30,11 +35,8 @@ export interface MemoryStore {
|
|
|
30
35
|
timeline(query: TimelineQuery): Promise<ObservationIndexEntry[]>;
|
|
31
36
|
closeObservations(ids: string[]): Promise<number>;
|
|
32
37
|
markReplaced(ids: string[]): Promise<number>;
|
|
33
|
-
upsertGraph(scan:
|
|
34
|
-
|
|
35
|
-
edges: CodeEdge[];
|
|
36
|
-
files: ScannedFile[];
|
|
37
|
-
}): Promise<void>;
|
|
38
|
+
upsertGraph(scan: GraphRows): Promise<void>;
|
|
39
|
+
replaceGraph(project: string, files: string[] | null, scan: GraphRows): Promise<void>;
|
|
38
40
|
findSymbols(filter: SymbolFilter): Promise<CodeSymbol[]>;
|
|
39
41
|
symbolNames(project: string, limit: number): Promise<string[]>;
|
|
40
42
|
findEdges(filter: EdgeFilter): Promise<CodeEdge[]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CodeEdge, CodeSymbol, CountFilter, EdgeFilter, ListFilter, Observation, ObservationIndexEntry, ProjectFilter, RemoveFilter, ScannedFile, SearchQuery, Session, SymbolFilter, TimelineQuery } from '../../types.js';
|
|
2
|
-
import type { MemoryStore, ProjectSummary } from '../adapter.js';
|
|
2
|
+
import type { GraphRows, MemoryStore, ProjectSummary } from '../adapter.js';
|
|
3
3
|
export declare class MongoStore implements MemoryStore {
|
|
4
4
|
private readonly client;
|
|
5
5
|
private readonly db;
|
|
@@ -36,11 +36,8 @@ export declare class MongoStore implements MemoryStore {
|
|
|
36
36
|
markReplaced(ids: string[]): Promise<number>;
|
|
37
37
|
timeline(query: TimelineQuery): Promise<ObservationIndexEntry[]>;
|
|
38
38
|
hasAtlasVectorIndex(): Promise<boolean>;
|
|
39
|
-
upsertGraph(scan:
|
|
40
|
-
|
|
41
|
-
edges: CodeEdge[];
|
|
42
|
-
files: ScannedFile[];
|
|
43
|
-
}): Promise<void>;
|
|
39
|
+
upsertGraph(scan: GraphRows): Promise<void>;
|
|
40
|
+
replaceGraph(project: string, files: string[] | null, scan: GraphRows): Promise<void>;
|
|
44
41
|
findSymbols(filter: SymbolFilter): Promise<CodeSymbol[]>;
|
|
45
42
|
symbolNames(project: string, limit: number): Promise<string[]>;
|
|
46
43
|
findEdges(filter: EdgeFilter): Promise<CodeEdge[]>;
|
|
@@ -121,6 +121,11 @@ export class MongoStore {
|
|
|
121
121
|
async upsertGraph(scan) {
|
|
122
122
|
return graphOps.upsertGraph(this.symbols, this.edges, this.scanned, scan);
|
|
123
123
|
}
|
|
124
|
+
async replaceGraph(project, files, scan) {
|
|
125
|
+
if (files === null || files.length > 0)
|
|
126
|
+
await this.removeGraph(project, files ?? undefined);
|
|
127
|
+
await this.upsertGraph(scan);
|
|
128
|
+
}
|
|
124
129
|
async findSymbols(filter) {
|
|
125
130
|
return graphOps.findSymbols(this.symbols, this.edges, this.scanned, filter);
|
|
126
131
|
}
|
|
@@ -7,7 +7,19 @@ import { noProjects } from '../project-scope.js';
|
|
|
7
7
|
export async function insertObservations(collection, sessions, symbols, edges, scanned, rows) {
|
|
8
8
|
if (rows.length === 0)
|
|
9
9
|
return;
|
|
10
|
-
|
|
10
|
+
const reopening = rows.filter((obs) => obs.status === 'open').map((obs) => obs.id);
|
|
11
|
+
const closed = new Map();
|
|
12
|
+
if (reopening.length > 0) {
|
|
13
|
+
const docs = await collection
|
|
14
|
+
.find({ _id: { $in: reopening }, status: 'done' }, { projection: { files: 1 } })
|
|
15
|
+
.toArray();
|
|
16
|
+
for (const doc of docs)
|
|
17
|
+
closed.set(doc._id, doc.files);
|
|
18
|
+
}
|
|
19
|
+
const kept = (obs) => closed.has(obs.id) && JSON.stringify(closed.get(obs.id)) === JSON.stringify(obs.files)
|
|
20
|
+
? { ...obs, status: 'done' }
|
|
21
|
+
: obs;
|
|
22
|
+
await collection.bulkWrite(rows.map(kept).map((obs) => ({
|
|
11
23
|
replaceOne: {
|
|
12
24
|
filter: { _id: obs.id },
|
|
13
25
|
replacement: toDoc(obs),
|
|
@@ -10,10 +10,17 @@ export interface Pool {
|
|
|
10
10
|
query(sql: string, values?: unknown[]): Promise<QueryResult>;
|
|
11
11
|
connect(): Promise<PoolClient>;
|
|
12
12
|
end(): Promise<void>;
|
|
13
|
+
on(event: 'error', listener: (error: Error) => void): unknown;
|
|
14
|
+
}
|
|
15
|
+
export interface PoolConfig {
|
|
16
|
+
connectionString: string;
|
|
17
|
+
max?: number;
|
|
18
|
+
idleTimeoutMillis?: number;
|
|
19
|
+
allowExitOnIdle?: boolean;
|
|
20
|
+
keepAlive?: boolean;
|
|
13
21
|
}
|
|
14
22
|
export interface PgModule {
|
|
15
|
-
Pool: new (config:
|
|
16
|
-
connectionString: string;
|
|
17
|
-
}) => Pool;
|
|
23
|
+
Pool: new (config: PoolConfig) => Pool;
|
|
18
24
|
}
|
|
19
25
|
export declare function importPg(): Promise<PgModule>;
|
|
26
|
+
export declare function openPool(uri: string): Promise<Pool>;
|
|
@@ -12,3 +12,15 @@ export async function importPg() {
|
|
|
12
12
|
throw new Error('Postgres driver not installed. Run: npm install -g pg');
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
export async function openPool(uri) {
|
|
16
|
+
const pg = await importPg();
|
|
17
|
+
const pool = new pg.Pool({
|
|
18
|
+
connectionString: uri,
|
|
19
|
+
max: 4,
|
|
20
|
+
idleTimeoutMillis: 60_000,
|
|
21
|
+
allowExitOnIdle: true,
|
|
22
|
+
keepAlive: true,
|
|
23
|
+
});
|
|
24
|
+
pool.on('error', () => undefined);
|
|
25
|
+
return pool;
|
|
26
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProjectFilter, SearchQuery } from '../../types.js';
|
|
2
2
|
export declare function projectClause(filter: ProjectFilter | undefined, values: unknown[], column?: string): string | null;
|
|
3
|
+
export declare function likePrefix(prefix: string): string;
|
|
3
4
|
export declare function excludeSessionsClause(sessions: string[] | undefined, values: unknown[]): string | null;
|
|
4
5
|
export declare function appendScope(query: SearchQuery, conditions: string[], values: unknown[]): void;
|
|
@@ -6,6 +6,9 @@ export function projectClause(filter, values, column = 'project') {
|
|
|
6
6
|
values.push(projects);
|
|
7
7
|
return `${column} = ANY($${values.length}::text[])`;
|
|
8
8
|
}
|
|
9
|
+
export function likePrefix(prefix) {
|
|
10
|
+
return `${prefix.replace(/[\\%_]/g, '\\$&')}%`;
|
|
11
|
+
}
|
|
9
12
|
export function excludeSessionsClause(sessions, values) {
|
|
10
13
|
if (!sessions || sessions.length === 0)
|
|
11
14
|
return null;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { Pool } from './driver.js';
|
|
2
2
|
import type { CodeEdge, CodeSymbol, EdgeFilter, ScannedFile, SymbolFilter } from '../../types.js';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
files: ScannedFile[];
|
|
7
|
-
}): Promise<void>;
|
|
3
|
+
import type { GraphRows } from '../adapter.js';
|
|
4
|
+
export declare function upsertGraph(pool: Pool, scan: GraphRows): Promise<void>;
|
|
5
|
+
export declare function replaceGraph(pool: Pool, project: string, files: string[] | null, scan: GraphRows): Promise<void>;
|
|
8
6
|
export declare function findSymbols(pool: Pool, filter: SymbolFilter): Promise<CodeSymbol[]>;
|
|
9
7
|
export declare function symbolNames(pool: Pool, project: string, limit: number): Promise<string[]>;
|
|
10
8
|
export declare function findEdges(pool: Pool, filter: EdgeFilter): Promise<CodeEdge[]>;
|