claude-db 0.10.3 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/README.md +41 -78
- package/dist/catchup/gather.d.ts +18 -0
- package/dist/catchup/gather.js +46 -0
- package/dist/catchup/git-state.d.ts +9 -0
- package/dist/catchup/git-state.js +35 -0
- package/dist/catchup/render.d.ts +3 -0
- package/dist/catchup/render.js +49 -0
- package/dist/cli/backfill-output.d.ts +13 -0
- package/dist/cli/backfill-output.js +78 -0
- package/dist/cli/commands/catchup.d.ts +1 -0
- package/dist/cli/commands/catchup.js +14 -0
- package/dist/cli/commands/distill.js +13 -2
- package/dist/cli/commands/doctor.d.ts +2 -0
- package/dist/cli/commands/doctor.js +42 -3
- package/dist/cli/commands/insight.js +2 -1
- package/dist/cli/commands/setup.js +29 -9
- package/dist/cli/files.d.ts +2 -0
- package/dist/cli/files.js +15 -1
- package/dist/cli/index.js +9 -0
- package/dist/cli/install.d.ts +6 -1
- package/dist/cli/install.js +11 -20
- package/dist/cli/paths.d.ts +1 -1
- package/dist/cli/paths.js +2 -2
- package/dist/cli/refresh.js +4 -12
- package/dist/cli/skills.d.ts +17 -0
- package/dist/cli/skills.js +70 -0
- package/dist/cli/usage.js +2 -0
- package/dist/config/schema.d.ts +3 -0
- package/dist/config/schema.js +8 -0
- package/dist/context.js +5 -2
- package/dist/facts/distill.d.ts +16 -3
- package/dist/facts/distill.js +22 -31
- package/dist/facts/handoff.d.ts +6 -0
- package/dist/facts/handoff.js +35 -0
- package/dist/facts/health.d.ts +3 -0
- package/dist/facts/health.js +10 -0
- package/dist/facts/known.d.ts +4 -0
- package/dist/facts/known.js +38 -0
- package/dist/facts/model.d.ts +1 -0
- package/dist/facts/model.js +12 -0
- package/dist/facts/ops.d.ts +1 -1
- package/dist/facts/ops.js +4 -2
- package/dist/facts/start.js +20 -5
- package/dist/store/adapter.d.ts +4 -2
- package/dist/store/adapter.js +1 -1
- package/dist/store/mongo/docs.d.ts +6 -0
- package/dist/store/mongo/filters.d.ts +2 -1
- package/dist/store/mongo/filters.js +9 -2
- package/dist/store/mongo/index.d.ts +5 -2
- package/dist/store/mongo/index.js +13 -2
- package/dist/store/mongo/observations.js +9 -5
- package/dist/store/mongo/project-links.d.ts +4 -0
- package/dist/store/mongo/project-links.js +13 -0
- package/dist/store/mongo/search.js +3 -0
- package/dist/store/mongo/sessions.d.ts +2 -2
- package/dist/store/mongo/sessions.js +5 -1
- package/dist/store/mongo/vectorSearch.js +3 -0
- package/dist/store/postgres/filters.d.ts +2 -1
- package/dist/store/postgres/filters.js +11 -4
- package/dist/store/postgres/index.d.ts +4 -2
- package/dist/store/postgres/index.js +7 -0
- package/dist/store/postgres/observations.js +15 -10
- package/dist/store/postgres/project-links.d.ts +3 -0
- package/dist/store/postgres/project-links.js +15 -0
- package/dist/store/postgres/schema.d.ts +2 -2
- package/dist/store/postgres/schema.js +9 -1
- package/dist/store/postgres/search.js +3 -0
- package/dist/store/postgres/sessions.d.ts +2 -2
- package/dist/store/postgres/sessions.js +9 -2
- package/dist/store/postgres/vectorSearch.js +3 -0
- package/dist/store/project-resolver.d.ts +16 -0
- package/dist/store/project-resolver.js +49 -0
- package/dist/store/project-scope.d.ts +5 -0
- package/dist/store/project-scope.js +16 -0
- package/dist/store/scoped-store.d.ts +3 -0
- package/dist/store/scoped-store.js +49 -0
- package/dist/store/sqlite/filters.d.ts +3 -2
- package/dist/store/sqlite/filters.js +23 -9
- package/dist/store/sqlite/index.d.ts +4 -2
- package/dist/store/sqlite/index.js +7 -0
- package/dist/store/sqlite/observations.js +13 -7
- package/dist/store/sqlite/project-links.d.ts +3 -0
- package/dist/store/sqlite/project-links.js +15 -0
- package/dist/store/sqlite/schema.sql +9 -0
- package/dist/store/sqlite/search.js +5 -0
- package/dist/store/sqlite/sessions.d.ts +2 -2
- package/dist/store/sqlite/sessions.js +8 -2
- package/dist/types.d.ts +4 -3
- package/dist/util/claude-binary.d.ts +15 -1
- package/dist/util/claude-binary.js +39 -7
- package/dist/util/project-key.d.ts +7 -0
- package/dist/util/project-key.js +23 -0
- package/dist/util/remote-key.d.ts +3 -0
- package/dist/util/remote-key.js +50 -0
- package/docs/setup-guide.md +47 -291
- package/package.json +2 -2
- package/skills/catchup/SKILL.md +46 -0
- package/skills/handoff/SKILL.md +78 -0
|
@@ -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/model.d.ts
CHANGED
|
@@ -24,5 +24,6 @@ export declare function scopeProject(scope: FactScope, project: string): string;
|
|
|
24
24
|
export declare function factId(owner: string, key: string): string;
|
|
25
25
|
export declare function factType(obs: Observation): FactType | null;
|
|
26
26
|
export declare function factKey(obs: Observation): string | null;
|
|
27
|
+
export declare function onePerKey(rows: Observation[]): Observation[];
|
|
27
28
|
export declare function factLabel(obs: Observation): string | null;
|
|
28
29
|
export declare function factToObservation(fact: Fact, project: string): Observation;
|
package/dist/facts/model.js
CHANGED
|
@@ -55,6 +55,18 @@ export function factType(obs) {
|
|
|
55
55
|
export function factKey(obs) {
|
|
56
56
|
return obs.tags.find((tag) => tag.startsWith('key:'))?.slice(4) ?? null;
|
|
57
57
|
}
|
|
58
|
+
export function onePerKey(rows) {
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
return rows.filter((obs) => {
|
|
61
|
+
const key = factKey(obs);
|
|
62
|
+
if (key === null)
|
|
63
|
+
return true;
|
|
64
|
+
if (seen.has(key))
|
|
65
|
+
return false;
|
|
66
|
+
seen.add(key);
|
|
67
|
+
return true;
|
|
68
|
+
});
|
|
69
|
+
}
|
|
58
70
|
export function factLabel(obs) {
|
|
59
71
|
const type = factType(obs);
|
|
60
72
|
if (type)
|
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
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { openWork } from '../capture/progress.js';
|
|
2
|
-
import { FACT_SESSION, factType, youScope } from './model.js';
|
|
2
|
+
import { FACT_SESSION, factType, onePerKey, youScope } from './model.js';
|
|
3
|
+
import { newestHandoff, handoffBodyLines } from './handoff.js';
|
|
3
4
|
import { MANUAL_SESSION, factLine, seenByClaude } from './render.js';
|
|
5
|
+
import { formatDay } from '../util/day.js';
|
|
6
|
+
import { toShortId } from '../util/shortid.js';
|
|
4
7
|
const ABOUT_YOU = 6;
|
|
5
8
|
const THIS_PROJECT = 10;
|
|
6
9
|
const TODOS = 4;
|
|
@@ -9,10 +12,12 @@ const ORDER = ['rule', 'decision', 'deadend', 'fact'];
|
|
|
9
12
|
export async function startFacts(ctx, project, hidden = new Set()) {
|
|
10
13
|
const visible = (obs) => obs.status !== 'replaced' && !hidden.has(obs.id) && !seenByClaude(obs, project);
|
|
11
14
|
const list = async (owner, sessionId, limit) => (await ctx.store.list({ project: owner, sessionId, newest: true, limit })).filter(visible);
|
|
12
|
-
const you = await list(youScope(), FACT_SESSION, 50);
|
|
13
|
-
const facts = await list(project, FACT_SESSION, 300);
|
|
14
|
-
const
|
|
15
|
-
|
|
15
|
+
const you = onePerKey(await list(youScope(), FACT_SESSION, 50));
|
|
16
|
+
const facts = onePerKey(await list(project, FACT_SESSION, 300));
|
|
17
|
+
const handoff = await newestHandoff(ctx, project);
|
|
18
|
+
const shownHandoff = handoff && visible(handoff) ? handoff : null;
|
|
19
|
+
const manual = (await list(project, MANUAL_SESSION, 20)).filter((obs) => obs.id !== handoff?.id);
|
|
20
|
+
if (you.length + facts.length + manual.length === 0 && !shownHandoff)
|
|
16
21
|
return null;
|
|
17
22
|
const rank = (obs) => {
|
|
18
23
|
const index = ORDER.indexOf(factType(obs) ?? 'rule');
|
|
@@ -26,6 +31,10 @@ export async function startFacts(ctx, project, hidden = new Set()) {
|
|
|
26
31
|
const sections = [
|
|
27
32
|
['About you:', you.slice(0, ABOUT_YOU).map((obs) => [factLine(obs), obs.id])],
|
|
28
33
|
['This project:', known.slice(0, THIS_PROJECT).map((obs) => [factLine(obs), obs.id])],
|
|
34
|
+
[
|
|
35
|
+
shownHandoff ? `Last handoff (${formatDay(shownHandoff.createdAt)}):` : '',
|
|
36
|
+
shownHandoff ? handoffEntries(shownHandoff) : [],
|
|
37
|
+
],
|
|
29
38
|
[
|
|
30
39
|
'Where you stopped:',
|
|
31
40
|
[
|
|
@@ -55,3 +64,9 @@ export async function startFacts(ctx, project, hidden = new Set()) {
|
|
|
55
64
|
lines.push('</memory>');
|
|
56
65
|
return { block: lines.join('\n'), ids };
|
|
57
66
|
}
|
|
67
|
+
function handoffEntries(handoff) {
|
|
68
|
+
return handoffBodyLines(handoff).map((line, index) => [
|
|
69
|
+
index === 0 ? `${line} (${toShortId(handoff.id)})` : line,
|
|
70
|
+
index === 0 ? handoff.id : null,
|
|
71
|
+
]);
|
|
72
|
+
}
|
package/dist/store/adapter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CodeEdge, CodeSymbol, EdgeFilter, ListFilter, Observation, ObservationIndexEntry, RemoveFilter, ScannedFile, SearchQuery, Session, SymbolFilter, TimelineQuery } from '../types.js';
|
|
1
|
+
import type { CodeEdge, CodeSymbol, EdgeFilter, ListFilter, Observation, ObservationIndexEntry, ProjectFilter, RemoveFilter, ScannedFile, SearchQuery, Session, SymbolFilter, TimelineQuery } from '../types.js';
|
|
2
2
|
export interface ProjectSummary {
|
|
3
3
|
project: string;
|
|
4
4
|
observations: number;
|
|
@@ -9,9 +9,11 @@ export interface MemoryStore {
|
|
|
9
9
|
init(): Promise<void>;
|
|
10
10
|
close(): Promise<void>;
|
|
11
11
|
ping(): Promise<boolean>;
|
|
12
|
+
linkProject(folder: string, key: string, now?: number): Promise<void>;
|
|
13
|
+
projectScope(folder: string): Promise<string[]>;
|
|
12
14
|
upsertSession(session: Session): Promise<void>;
|
|
13
15
|
getSession(id: string): Promise<Session | null>;
|
|
14
|
-
recentSessions(project:
|
|
16
|
+
recentSessions(project: ProjectFilter, limit: number): Promise<Session[]>;
|
|
15
17
|
sessionProjects(): Promise<string[]>;
|
|
16
18
|
clearSummary(id: string): Promise<boolean>;
|
|
17
19
|
insertObservations(observations: Observation[]): Promise<void>;
|
package/dist/store/adapter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function isWholeScope(filter) {
|
|
2
2
|
return !filter.ids && !filter.kind && filter.before === undefined;
|
|
3
3
|
}
|
|
4
|
-
const OURS = /^(claude_db_meta|sessions|observations|symbols|symbol_edges|scanned_files)(_fts(_\w+)?)?$/;
|
|
4
|
+
const OURS = /^(claude_db_meta|sessions|observations|symbols|symbol_edges|scanned_files|project_links)(_fts(_\w+)?)?$/;
|
|
5
5
|
export function foreignNames(names) {
|
|
6
6
|
return names.filter((name) => name.length > 0 && !OURS.test(name));
|
|
7
7
|
}
|
|
@@ -54,6 +54,12 @@ export interface ScannedFileDoc extends Doc {
|
|
|
54
54
|
hash: string;
|
|
55
55
|
scannedAt: number;
|
|
56
56
|
}
|
|
57
|
+
export interface ProjectLinkDoc extends Doc {
|
|
58
|
+
_id: string;
|
|
59
|
+
folder: string;
|
|
60
|
+
projectKey: string;
|
|
61
|
+
firstSeen: number;
|
|
62
|
+
}
|
|
57
63
|
export declare function upsertsOf<T extends object>(rows: T[], idOf: (row: T) => string): Doc[];
|
|
58
64
|
export declare function toSession(doc: SessionDoc): Session;
|
|
59
65
|
export declare function toDoc(obs: Observation): ObservationDoc;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Doc } from './driver.js';
|
|
2
|
-
import type { SearchQuery } from '../../types.js';
|
|
2
|
+
import type { ProjectFilter, SearchQuery } from '../../types.js';
|
|
3
|
+
export declare function projectMatch(filter: ProjectFilter | undefined): Doc;
|
|
3
4
|
export interface VectorCache {
|
|
4
5
|
atlasVectorIndex: boolean | null;
|
|
5
6
|
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
import { projectsOf } from '../project-scope.js';
|
|
2
|
+
export function projectMatch(filter) {
|
|
3
|
+
const projects = projectsOf(filter);
|
|
4
|
+
if (projects.length === 0)
|
|
5
|
+
return {};
|
|
6
|
+
const [only] = projects;
|
|
7
|
+
return { project: projects.length === 1 ? only : { $in: projects } };
|
|
8
|
+
}
|
|
1
9
|
export function scopeFilter(query) {
|
|
2
10
|
const filter = {};
|
|
3
|
-
|
|
4
|
-
filter['project'] = query.project;
|
|
11
|
+
Object.assign(filter, projectMatch(query.project));
|
|
5
12
|
if (query.kind)
|
|
6
13
|
filter['kind'] = query.kind;
|
|
7
14
|
if (query.tag)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CodeEdge, CodeSymbol, EdgeFilter, ListFilter, Observation, ObservationIndexEntry, RemoveFilter, ScannedFile, SearchQuery, Session, SymbolFilter, TimelineQuery } from '../../types.js';
|
|
1
|
+
import type { CodeEdge, CodeSymbol, EdgeFilter, ListFilter, Observation, ObservationIndexEntry, ProjectFilter, RemoveFilter, ScannedFile, SearchQuery, Session, SymbolFilter, TimelineQuery } from '../../types.js';
|
|
2
2
|
import type { MemoryStore, ProjectSummary } from '../adapter.js';
|
|
3
3
|
export declare class MongoStore implements MemoryStore {
|
|
4
4
|
private readonly client;
|
|
@@ -8,6 +8,7 @@ export declare class MongoStore implements MemoryStore {
|
|
|
8
8
|
private readonly symbols;
|
|
9
9
|
private readonly edges;
|
|
10
10
|
private readonly scanned;
|
|
11
|
+
private readonly links;
|
|
11
12
|
readonly kind = "mongodb";
|
|
12
13
|
private readonly cache;
|
|
13
14
|
private constructor();
|
|
@@ -15,9 +16,11 @@ export declare class MongoStore implements MemoryStore {
|
|
|
15
16
|
init(): Promise<void>;
|
|
16
17
|
close(): Promise<void>;
|
|
17
18
|
ping(): Promise<boolean>;
|
|
19
|
+
linkProject(folder: string, key: string, now?: number): Promise<void>;
|
|
20
|
+
projectScope(folder: string): Promise<string[]>;
|
|
18
21
|
upsertSession(session: Session): Promise<void>;
|
|
19
22
|
getSession(id: string): Promise<Session | null>;
|
|
20
|
-
recentSessions(project:
|
|
23
|
+
recentSessions(project: ProjectFilter, limit: number): Promise<Session[]>;
|
|
21
24
|
sessionProjects(): Promise<string[]>;
|
|
22
25
|
clearSummary(id: string): Promise<boolean>;
|
|
23
26
|
insertObservations(observations: Observation[]): Promise<void>;
|
|
@@ -3,6 +3,7 @@ import * as searchOps from './search.js';
|
|
|
3
3
|
import * as observationsOps from './observations.js';
|
|
4
4
|
import * as sessionsOps from './sessions.js';
|
|
5
5
|
import * as graphOps from './graph.js';
|
|
6
|
+
import * as projectLinksOps from './project-links.js';
|
|
6
7
|
import { databaseNameFrom } from './helpers.js';
|
|
7
8
|
import { foreignNames } from '../adapter.js';
|
|
8
9
|
import { importMongo } from './driver.js';
|
|
@@ -14,9 +15,10 @@ export class MongoStore {
|
|
|
14
15
|
symbols;
|
|
15
16
|
edges;
|
|
16
17
|
scanned;
|
|
18
|
+
links;
|
|
17
19
|
kind = 'mongodb';
|
|
18
20
|
cache = { atlasVectorIndex: null };
|
|
19
|
-
constructor(client, db, sessions, observations, symbols, edges, scanned) {
|
|
21
|
+
constructor(client, db, sessions, observations, symbols, edges, scanned, links) {
|
|
20
22
|
this.client = client;
|
|
21
23
|
this.db = db;
|
|
22
24
|
this.sessions = sessions;
|
|
@@ -24,13 +26,14 @@ export class MongoStore {
|
|
|
24
26
|
this.symbols = symbols;
|
|
25
27
|
this.edges = edges;
|
|
26
28
|
this.scanned = scanned;
|
|
29
|
+
this.links = links;
|
|
27
30
|
}
|
|
28
31
|
static async create(uri) {
|
|
29
32
|
const mongo = await importMongo();
|
|
30
33
|
const client = new mongo.MongoClient(uri);
|
|
31
34
|
await client.connect();
|
|
32
35
|
const db = client.db(databaseNameFrom(uri) ?? 'claude_memory_db');
|
|
33
|
-
return new MongoStore(client, db, db.collection('sessions'), db.collection('observations'), db.collection('symbols'), db.collection('symbol_edges'), db.collection('scanned_files'));
|
|
36
|
+
return new MongoStore(client, db, db.collection('sessions'), db.collection('observations'), db.collection('symbols'), db.collection('symbol_edges'), db.collection('scanned_files'), db.collection('project_links'));
|
|
34
37
|
}
|
|
35
38
|
async init() {
|
|
36
39
|
await this.sessions.createIndex({ project: 1, startedAt: -1 });
|
|
@@ -43,6 +46,8 @@ export class MongoStore {
|
|
|
43
46
|
await this.edges.createIndex({ project: 1, dstId: 1 });
|
|
44
47
|
await this.edges.createIndex({ project: 1, file: 1 });
|
|
45
48
|
await this.scanned.createIndex({ project: 1, path: 1 }, { unique: true });
|
|
49
|
+
await this.links.createIndex({ folder: 1, projectKey: 1 }, { unique: true });
|
|
50
|
+
await this.links.createIndex({ projectKey: 1 });
|
|
46
51
|
}
|
|
47
52
|
async close() {
|
|
48
53
|
await this.client.close();
|
|
@@ -51,6 +56,12 @@ export class MongoStore {
|
|
|
51
56
|
const res = await this.db.command({ ping: 1 });
|
|
52
57
|
return res['ok'] === 1;
|
|
53
58
|
}
|
|
59
|
+
async linkProject(folder, key, now = Date.now()) {
|
|
60
|
+
return projectLinksOps.linkProject(this.links, folder, key, now);
|
|
61
|
+
}
|
|
62
|
+
async projectScope(folder) {
|
|
63
|
+
return projectLinksOps.projectScope(this.links, folder);
|
|
64
|
+
}
|
|
54
65
|
async upsertSession(session) {
|
|
55
66
|
return sessionsOps.upsertSession(this.sessions, session);
|
|
56
67
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { isWholeScope } from '../adapter.js';
|
|
2
2
|
import { toDoc, toObservation } from './docs.js';
|
|
3
|
+
import { projectMatch } from './filters.js';
|
|
3
4
|
import { escapeRegex } from './helpers.js';
|
|
4
5
|
import { partitionIds } from '../../util/shortid.js';
|
|
6
|
+
import { noProjects } from '../project-scope.js';
|
|
5
7
|
export async function insertObservations(collection, sessions, symbols, edges, scanned, rows) {
|
|
6
8
|
if (rows.length === 0)
|
|
7
9
|
return;
|
|
@@ -27,11 +29,12 @@ export async function getObservations(observations, sessions, symbols, edges, sc
|
|
|
27
29
|
return docs.map(toObservation);
|
|
28
30
|
}
|
|
29
31
|
export async function remove(observations, sessions, symbols, edges, scanned, filter) {
|
|
32
|
+
if (noProjects(filter.project))
|
|
33
|
+
return 0;
|
|
30
34
|
if (filter.ids?.length === 0)
|
|
31
35
|
return 0;
|
|
32
36
|
const query = {};
|
|
33
|
-
|
|
34
|
-
query['project'] = filter.project;
|
|
37
|
+
Object.assign(query, projectMatch(filter.project));
|
|
35
38
|
if (filter.kind)
|
|
36
39
|
query['kind'] = filter.kind;
|
|
37
40
|
if (filter.before !== undefined)
|
|
@@ -49,7 +52,7 @@ export async function remove(observations, sessions, symbols, edges, scanned, fi
|
|
|
49
52
|
const count = await observations.countDocuments(query);
|
|
50
53
|
await observations.deleteMany(query);
|
|
51
54
|
if (isWholeScope(filter)) {
|
|
52
|
-
const scope = filter.project
|
|
55
|
+
const scope = projectMatch(filter.project);
|
|
53
56
|
await sessions.deleteMany(scope);
|
|
54
57
|
await symbols.deleteMany(scope);
|
|
55
58
|
await edges.deleteMany(scope);
|
|
@@ -58,9 +61,10 @@ export async function remove(observations, sessions, symbols, edges, scanned, fi
|
|
|
58
61
|
return count;
|
|
59
62
|
}
|
|
60
63
|
export async function list(observations, sessions, symbols, edges, scanned, filter) {
|
|
64
|
+
if (noProjects(filter.project))
|
|
65
|
+
return [];
|
|
61
66
|
const query = {};
|
|
62
|
-
|
|
63
|
-
query['project'] = filter.project;
|
|
67
|
+
Object.assign(query, projectMatch(filter.project));
|
|
64
68
|
if (filter.sessionId)
|
|
65
69
|
query['sessionId'] = filter.sessionId;
|
|
66
70
|
if (filter.kind)
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Collection } from './driver.js';
|
|
2
|
+
import type { ProjectLinkDoc } from './docs.js';
|
|
3
|
+
export declare function linkProject(links: Collection<ProjectLinkDoc>, folder: string, key: string, now: number): Promise<void>;
|
|
4
|
+
export declare function projectScope(links: Collection<ProjectLinkDoc>, folder: string): Promise<string[]>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isLinkable, orderScope } from '../project-scope.js';
|
|
2
|
+
const ID_SEPARATOR = '\u0000';
|
|
3
|
+
export async function linkProject(links, folder, key, now) {
|
|
4
|
+
if (!isLinkable(folder, key))
|
|
5
|
+
return;
|
|
6
|
+
await links.updateOne({ _id: `${folder}${ID_SEPARATOR}${key}` }, { $setOnInsert: { folder, projectKey: key, firstSeen: now } }, { upsert: true });
|
|
7
|
+
}
|
|
8
|
+
export async function projectScope(links, folder) {
|
|
9
|
+
const own = await links.find({ folder }).toArray();
|
|
10
|
+
const keys = own.map((doc) => doc.projectKey);
|
|
11
|
+
const shared = keys.length > 0 ? await links.find({ projectKey: { $in: keys } }).toArray() : [];
|
|
12
|
+
return orderScope(folder, [...keys, ...shared.map((doc) => doc.folder)]);
|
|
13
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { toIndexEntry } from './docs.js';
|
|
2
2
|
import { scopeFilter, visibleFilter } from './filters.js';
|
|
3
|
+
import { noProjects } from '../project-scope.js';
|
|
3
4
|
export async function searchKeyword(observations, query) {
|
|
5
|
+
if (noProjects(query.project))
|
|
6
|
+
return [];
|
|
4
7
|
const filter = {
|
|
5
8
|
$text: { $search: query.text },
|
|
6
9
|
...scopeFilter(query),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Collection } from './driver.js';
|
|
2
|
-
import type { Session } from '../../types.js';
|
|
2
|
+
import type { ProjectFilter, Session } from '../../types.js';
|
|
3
3
|
import type { SessionDoc } from './docs.js';
|
|
4
4
|
export declare function upsertSession(sessions: Collection<SessionDoc>, session: Session): Promise<void>;
|
|
5
5
|
export declare function getSession(sessions: Collection<SessionDoc>, id: string): Promise<Session | null>;
|
|
6
6
|
export declare function clearSummary(sessions: Collection<SessionDoc>, id: string): Promise<boolean>;
|
|
7
|
-
export declare function recentSessions(sessions: Collection<SessionDoc>, project:
|
|
7
|
+
export declare function recentSessions(sessions: Collection<SessionDoc>, project: ProjectFilter, limit: number): Promise<Session[]>;
|
|
8
8
|
export declare function sessionProjects(sessions: Collection<SessionDoc>): Promise<string[]>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { projectMatch } from './filters.js';
|
|
1
2
|
import { toSession } from './docs.js';
|
|
2
3
|
import { summaryTime } from '../session-time.js';
|
|
4
|
+
import { noProjects } from '../project-scope.js';
|
|
3
5
|
export async function upsertSession(sessions, session) {
|
|
4
6
|
const set = { project: session.project };
|
|
5
7
|
if (session.endedAt !== undefined)
|
|
@@ -22,8 +24,10 @@ export async function clearSummary(sessions, id) {
|
|
|
22
24
|
return (result.modifiedCount ?? 0) > 0;
|
|
23
25
|
}
|
|
24
26
|
export async function recentSessions(sessions, project, limit) {
|
|
27
|
+
if (noProjects(project))
|
|
28
|
+
return [];
|
|
25
29
|
const docs = await sessions
|
|
26
|
-
.find({ project, summary: { $type: 'string' } })
|
|
30
|
+
.find({ ...projectMatch(project), summary: { $type: 'string' } })
|
|
27
31
|
.sort({ startedAt: -1 })
|
|
28
32
|
.limit(limit)
|
|
29
33
|
.toArray();
|
|
@@ -2,7 +2,10 @@ import { toIndexEntry } from './docs.js';
|
|
|
2
2
|
import { scopeFilter, visibleFilter } from './filters.js';
|
|
3
3
|
import * as searchOps from './search.js';
|
|
4
4
|
import { cosine } from '../../util/vector.js';
|
|
5
|
+
import { noProjects } from '../project-scope.js';
|
|
5
6
|
export async function searchVector(observations, cache, vector, query) {
|
|
7
|
+
if (noProjects(query.project))
|
|
8
|
+
return [];
|
|
6
9
|
if (cache.atlasVectorIndex === null) {
|
|
7
10
|
cache.atlasVectorIndex = await searchOps.hasAtlasVectorIndex(observations);
|
|
8
11
|
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { SearchQuery } from '../../types.js';
|
|
1
|
+
import type { ProjectFilter, SearchQuery } from '../../types.js';
|
|
2
|
+
export declare function projectClause(filter: ProjectFilter | undefined, values: unknown[], column?: string): string | null;
|
|
2
3
|
export declare function appendScope(query: SearchQuery, conditions: string[], values: unknown[]): void;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { projectsOf } from '../project-scope.js';
|
|
2
|
+
export function projectClause(filter, values, column = 'project') {
|
|
3
|
+
const projects = projectsOf(filter);
|
|
4
|
+
if (projects.length === 0)
|
|
5
|
+
return null;
|
|
6
|
+
values.push(projects);
|
|
7
|
+
return `${column} = ANY($${values.length}::text[])`;
|
|
8
|
+
}
|
|
1
9
|
export function appendScope(query, conditions, values) {
|
|
2
10
|
conditions.push("status <> 'replaced'");
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
conditions.push(
|
|
6
|
-
}
|
|
11
|
+
const project = projectClause(query.project, values);
|
|
12
|
+
if (project)
|
|
13
|
+
conditions.push(project);
|
|
7
14
|
if (query.kind) {
|
|
8
15
|
values.push(query.kind);
|
|
9
16
|
conditions.push(`kind = $${values.length}`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CodeEdge, CodeSymbol, EdgeFilter, ListFilter, Observation, ObservationIndexEntry, RemoveFilter, ScannedFile, SearchQuery, Session, SymbolFilter, TimelineQuery } from '../../types.js';
|
|
1
|
+
import type { CodeEdge, CodeSymbol, EdgeFilter, ListFilter, Observation, ObservationIndexEntry, ProjectFilter, RemoveFilter, ScannedFile, SearchQuery, Session, SymbolFilter, TimelineQuery } from '../../types.js';
|
|
2
2
|
import type { MemoryStore, ProjectSummary } from '../adapter.js';
|
|
3
3
|
export declare class PostgresStore implements MemoryStore {
|
|
4
4
|
private readonly pool;
|
|
@@ -21,10 +21,12 @@ export declare class PostgresStore implements MemoryStore {
|
|
|
21
21
|
private ensureVectorColumn;
|
|
22
22
|
close(): Promise<void>;
|
|
23
23
|
ping(): Promise<boolean>;
|
|
24
|
+
linkProject(folder: string, key: string, now?: number): Promise<void>;
|
|
25
|
+
projectScope(folder: string): Promise<string[]>;
|
|
24
26
|
upsertSession(session: Session): Promise<void>;
|
|
25
27
|
getSession(id: string): Promise<Session | null>;
|
|
26
28
|
sessionProjects(): Promise<string[]>;
|
|
27
|
-
recentSessions(project:
|
|
29
|
+
recentSessions(project: ProjectFilter, limit: number): Promise<Session[]>;
|
|
28
30
|
clearSummary(id: string): Promise<boolean>;
|
|
29
31
|
insertObservations(observations: Observation[]): Promise<void>;
|
|
30
32
|
getObservations(ids: string[]): Promise<Observation[]>;
|
|
@@ -5,6 +5,7 @@ import * as searchOps from './search.js';
|
|
|
5
5
|
import * as observationsOps from './observations.js';
|
|
6
6
|
import * as sessionsOps from './sessions.js';
|
|
7
7
|
import * as graphOps from './graph.js';
|
|
8
|
+
import * as projectLinksOps from './project-links.js';
|
|
8
9
|
import { importPg } from './driver.js';
|
|
9
10
|
import { DDL, SCHEMA_VERSION } from './schema.js';
|
|
10
11
|
export class PostgresStore {
|
|
@@ -90,6 +91,12 @@ export class PostgresStore {
|
|
|
90
91
|
const res = await this.pool.query('SELECT 1 AS ok');
|
|
91
92
|
return res.rowCount === 1;
|
|
92
93
|
}
|
|
94
|
+
async linkProject(folder, key, now = Date.now()) {
|
|
95
|
+
return projectLinksOps.linkProject(this.pool, folder, key, now);
|
|
96
|
+
}
|
|
97
|
+
async projectScope(folder) {
|
|
98
|
+
return projectLinksOps.projectScope(this.pool, folder);
|
|
99
|
+
}
|
|
93
100
|
async upsertSession(session) {
|
|
94
101
|
return sessionsOps.upsertSession(this.pool, session);
|
|
95
102
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { foreignNames, isWholeScope } from '../adapter.js';
|
|
2
2
|
import { partitionIds } from '../../util/shortid.js';
|
|
3
|
+
import { projectClause } from './filters.js';
|
|
3
4
|
import { toIndexEntry, toObservation } from './rows.js';
|
|
5
|
+
import { noProjects } from '../project-scope.js';
|
|
4
6
|
export async function getObservations(pool, ids) {
|
|
5
7
|
if (ids.length === 0)
|
|
6
8
|
return [];
|
|
@@ -19,6 +21,8 @@ export async function getObservations(pool, ids) {
|
|
|
19
21
|
return res.rows.map(toObservation);
|
|
20
22
|
}
|
|
21
23
|
export async function remove(pool, filter) {
|
|
24
|
+
if (noProjects(filter.project))
|
|
25
|
+
return 0;
|
|
22
26
|
if (filter.ids?.length === 0)
|
|
23
27
|
return 0;
|
|
24
28
|
const conditions = [];
|
|
@@ -36,10 +40,9 @@ export async function remove(pool, filter) {
|
|
|
36
40
|
}
|
|
37
41
|
conditions.push(`(${alternatives.join(' OR ')})`);
|
|
38
42
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
conditions.push(
|
|
42
|
-
}
|
|
43
|
+
const project = projectClause(filter.project, values);
|
|
44
|
+
if (project)
|
|
45
|
+
conditions.push(project);
|
|
43
46
|
if (filter.kind) {
|
|
44
47
|
values.push(filter.kind);
|
|
45
48
|
conditions.push(`kind = $${values.length}`);
|
|
@@ -55,8 +58,9 @@ export async function remove(pool, filter) {
|
|
|
55
58
|
const counted = await client.query(`SELECT COUNT(*)::int AS n FROM observations ${where}`, values);
|
|
56
59
|
await client.query(`DELETE FROM observations ${where}`, values);
|
|
57
60
|
if (isWholeScope(filter)) {
|
|
58
|
-
const
|
|
59
|
-
const
|
|
61
|
+
const scopeValues = [];
|
|
62
|
+
const wipeClause = projectClause(filter.project, scopeValues);
|
|
63
|
+
const scope = wipeClause ? `WHERE ${wipeClause}` : '';
|
|
60
64
|
for (const table of ['sessions', 'symbols', 'symbol_edges', 'scanned_files']) {
|
|
61
65
|
await client.query(`DELETE FROM ${table} ${scope}`, scopeValues);
|
|
62
66
|
}
|
|
@@ -73,12 +77,13 @@ export async function remove(pool, filter) {
|
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
79
|
export async function list(pool, filter) {
|
|
80
|
+
if (noProjects(filter.project))
|
|
81
|
+
return [];
|
|
76
82
|
const conditions = [];
|
|
77
83
|
const values = [];
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
conditions.push(
|
|
81
|
-
}
|
|
84
|
+
const project = projectClause(filter.project, values);
|
|
85
|
+
if (project)
|
|
86
|
+
conditions.push(project);
|
|
82
87
|
if (filter.sessionId) {
|
|
83
88
|
values.push(filter.sessionId);
|
|
84
89
|
conditions.push(`session_id = $${values.length}`);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isLinkable, orderScope } from '../project-scope.js';
|
|
2
|
+
export async function linkProject(pool, folder, key, now) {
|
|
3
|
+
if (!isLinkable(folder, key))
|
|
4
|
+
return;
|
|
5
|
+
await pool.query(`INSERT INTO project_links (folder, project_key, first_seen)
|
|
6
|
+
VALUES ($1, $2, $3)
|
|
7
|
+
ON CONFLICT (folder, project_key) DO NOTHING`, [folder, key, now]);
|
|
8
|
+
}
|
|
9
|
+
export async function projectScope(pool, folder) {
|
|
10
|
+
const res = await pool.query(`SELECT project_key AS value FROM project_links WHERE folder = $1
|
|
11
|
+
UNION
|
|
12
|
+
SELECT folder AS value FROM project_links
|
|
13
|
+
WHERE project_key IN (SELECT project_key FROM project_links WHERE folder = $1)`, [folder]);
|
|
14
|
+
return orderScope(folder, res.rows.map((row) => String(row['value'])));
|
|
15
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const TSV_EXPRESSION = "\n setweight(to_tsvector('english', coalesce(title, '')), 'A') ||\n setweight(to_tsvector('english', coalesce(tags::text, '')), 'B') ||\n setweight(to_tsvector('english', coalesce(body, '')), 'C')";
|
|
2
|
-
export declare const SCHEMA_VERSION =
|
|
3
|
-
export declare const DDL = "\n CREATE TABLE IF NOT EXISTS claude_db_meta (\n id INT PRIMARY KEY,\n version INT NOT NULL,\n vector_enabled BOOLEAN NOT NULL DEFAULT FALSE,\n vector_dims INT\n );\n\n CREATE TABLE IF NOT EXISTS sessions (\n id TEXT PRIMARY KEY,\n project TEXT NOT NULL,\n started_at BIGINT NOT NULL,\n ended_at BIGINT,\n summary TEXT\n );\n CREATE INDEX IF NOT EXISTS idx_sessions_project\n ON sessions(project, started_at DESC);\n\n CREATE TABLE IF NOT EXISTS observations (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n project TEXT NOT NULL,\n kind TEXT NOT NULL,\n title TEXT NOT NULL,\n body TEXT NOT NULL,\n files JSONB NOT NULL DEFAULT '[]'::jsonb,\n tags JSONB NOT NULL DEFAULT '[]'::jsonb,\n created_at BIGINT NOT NULL,\n embedder TEXT,\n author TEXT,\n tsv TSVECTOR GENERATED ALWAYS AS (\n setweight(to_tsvector('english', coalesce(title, '')), 'A') ||\n setweight(to_tsvector('english', coalesce(tags::text, '')), 'B') ||\n setweight(to_tsvector('english', coalesce(body, '')), 'C')) STORED\n );\n CREATE INDEX IF NOT EXISTS idx_obs_tsv ON observations USING GIN(tsv);\n CREATE INDEX IF NOT EXISTS idx_obs_project_time\n ON observations(project, created_at DESC);\n CREATE INDEX IF NOT EXISTS idx_obs_tags ON observations USING GIN(tags);\n\n ALTER TABLE observations ADD COLUMN IF NOT EXISTS embedder TEXT;\n ALTER TABLE observations ADD COLUMN IF NOT EXISTS author TEXT;\n ALTER TABLE observations ADD COLUMN IF NOT EXISTS status TEXT NOT NULL DEFAULT 'done';\n\n ALTER TABLE sessions ADD COLUMN IF NOT EXISTS updated_at BIGINT;\n ALTER TABLE sessions ADD COLUMN IF NOT EXISTS distilled_at BIGINT;\n\n CREATE TABLE IF NOT EXISTS symbols (\n id TEXT PRIMARY KEY,\n project TEXT NOT NULL,\n name TEXT NOT NULL,\n kind TEXT NOT NULL,\n file TEXT NOT NULL,\n line INT NOT NULL,\n lang TEXT NOT NULL,\n signature TEXT NOT NULL DEFAULT ''\n );\n CREATE INDEX IF NOT EXISTS idx_symbols_lookup ON symbols(project, name);\n CREATE INDEX IF NOT EXISTS idx_symbols_file ON symbols(project, file);\n\n CREATE TABLE IF NOT EXISTS symbol_edges (\n id TEXT PRIMARY KEY,\n project TEXT NOT NULL,\n src_id TEXT NOT NULL,\n src_name TEXT NOT NULL,\n dst_id TEXT NOT NULL DEFAULT '',\n dst_name TEXT NOT NULL,\n relation TEXT NOT NULL,\n confidence TEXT NOT NULL,\n score REAL NOT NULL DEFAULT 1.0,\n file TEXT NOT NULL,\n line INT NOT NULL\n );\n CREATE INDEX IF NOT EXISTS idx_edges_src ON symbol_edges(project, src_id);\n CREATE INDEX IF NOT EXISTS idx_edges_dst ON symbol_edges(project, dst_id);\n CREATE INDEX IF NOT EXISTS idx_edges_file ON symbol_edges(project, file);\n\n CREATE TABLE IF NOT EXISTS scanned_files (\n project TEXT NOT NULL,\n path TEXT NOT NULL,\n hash TEXT NOT NULL,\n scanned_at BIGINT NOT NULL,\n PRIMARY KEY (project, path)\n );\n";
|
|
2
|
+
export declare const SCHEMA_VERSION = 5;
|
|
3
|
+
export declare const DDL = "\n CREATE TABLE IF NOT EXISTS claude_db_meta (\n id INT PRIMARY KEY,\n version INT NOT NULL,\n vector_enabled BOOLEAN NOT NULL DEFAULT FALSE,\n vector_dims INT\n );\n\n CREATE TABLE IF NOT EXISTS sessions (\n id TEXT PRIMARY KEY,\n project TEXT NOT NULL,\n started_at BIGINT NOT NULL,\n ended_at BIGINT,\n summary TEXT\n );\n CREATE INDEX IF NOT EXISTS idx_sessions_project\n ON sessions(project, started_at DESC);\n\n CREATE TABLE IF NOT EXISTS observations (\n id TEXT PRIMARY KEY,\n session_id TEXT NOT NULL,\n project TEXT NOT NULL,\n kind TEXT NOT NULL,\n title TEXT NOT NULL,\n body TEXT NOT NULL,\n files JSONB NOT NULL DEFAULT '[]'::jsonb,\n tags JSONB NOT NULL DEFAULT '[]'::jsonb,\n created_at BIGINT NOT NULL,\n embedder TEXT,\n author TEXT,\n tsv TSVECTOR GENERATED ALWAYS AS (\n setweight(to_tsvector('english', coalesce(title, '')), 'A') ||\n setweight(to_tsvector('english', coalesce(tags::text, '')), 'B') ||\n setweight(to_tsvector('english', coalesce(body, '')), 'C')) STORED\n );\n CREATE INDEX IF NOT EXISTS idx_obs_tsv ON observations USING GIN(tsv);\n CREATE INDEX IF NOT EXISTS idx_obs_project_time\n ON observations(project, created_at DESC);\n CREATE INDEX IF NOT EXISTS idx_obs_tags ON observations USING GIN(tags);\n\n ALTER TABLE observations ADD COLUMN IF NOT EXISTS embedder TEXT;\n ALTER TABLE observations ADD COLUMN IF NOT EXISTS author TEXT;\n ALTER TABLE observations ADD COLUMN IF NOT EXISTS status TEXT NOT NULL DEFAULT 'done';\n\n ALTER TABLE sessions ADD COLUMN IF NOT EXISTS updated_at BIGINT;\n ALTER TABLE sessions ADD COLUMN IF NOT EXISTS distilled_at BIGINT;\n\n CREATE TABLE IF NOT EXISTS project_links (\n folder TEXT NOT NULL,\n project_key TEXT NOT NULL,\n first_seen BIGINT NOT NULL,\n PRIMARY KEY (folder, project_key)\n );\n CREATE INDEX IF NOT EXISTS idx_project_links_key ON project_links(project_key);\n\n CREATE TABLE IF NOT EXISTS symbols (\n id TEXT PRIMARY KEY,\n project TEXT NOT NULL,\n name TEXT NOT NULL,\n kind TEXT NOT NULL,\n file TEXT NOT NULL,\n line INT NOT NULL,\n lang TEXT NOT NULL,\n signature TEXT NOT NULL DEFAULT ''\n );\n CREATE INDEX IF NOT EXISTS idx_symbols_lookup ON symbols(project, name);\n CREATE INDEX IF NOT EXISTS idx_symbols_file ON symbols(project, file);\n\n CREATE TABLE IF NOT EXISTS symbol_edges (\n id TEXT PRIMARY KEY,\n project TEXT NOT NULL,\n src_id TEXT NOT NULL,\n src_name TEXT NOT NULL,\n dst_id TEXT NOT NULL DEFAULT '',\n dst_name TEXT NOT NULL,\n relation TEXT NOT NULL,\n confidence TEXT NOT NULL,\n score REAL NOT NULL DEFAULT 1.0,\n file TEXT NOT NULL,\n line INT NOT NULL\n );\n CREATE INDEX IF NOT EXISTS idx_edges_src ON symbol_edges(project, src_id);\n CREATE INDEX IF NOT EXISTS idx_edges_dst ON symbol_edges(project, dst_id);\n CREATE INDEX IF NOT EXISTS idx_edges_file ON symbol_edges(project, file);\n\n CREATE TABLE IF NOT EXISTS scanned_files (\n project TEXT NOT NULL,\n path TEXT NOT NULL,\n hash TEXT NOT NULL,\n scanned_at BIGINT NOT NULL,\n PRIMARY KEY (project, path)\n );\n";
|
|
@@ -2,7 +2,7 @@ export const TSV_EXPRESSION = `
|
|
|
2
2
|
setweight(to_tsvector('english', coalesce(title, '')), 'A') ||
|
|
3
3
|
setweight(to_tsvector('english', coalesce(tags::text, '')), 'B') ||
|
|
4
4
|
setweight(to_tsvector('english', coalesce(body, '')), 'C')`;
|
|
5
|
-
export const SCHEMA_VERSION =
|
|
5
|
+
export const SCHEMA_VERSION = 5;
|
|
6
6
|
export const DDL = `
|
|
7
7
|
CREATE TABLE IF NOT EXISTS claude_db_meta (
|
|
8
8
|
id INT PRIMARY KEY,
|
|
@@ -47,6 +47,14 @@ export const DDL = `
|
|
|
47
47
|
ALTER TABLE sessions ADD COLUMN IF NOT EXISTS updated_at BIGINT;
|
|
48
48
|
ALTER TABLE sessions ADD COLUMN IF NOT EXISTS distilled_at BIGINT;
|
|
49
49
|
|
|
50
|
+
CREATE TABLE IF NOT EXISTS project_links (
|
|
51
|
+
folder TEXT NOT NULL,
|
|
52
|
+
project_key TEXT NOT NULL,
|
|
53
|
+
first_seen BIGINT NOT NULL,
|
|
54
|
+
PRIMARY KEY (folder, project_key)
|
|
55
|
+
);
|
|
56
|
+
CREATE INDEX IF NOT EXISTS idx_project_links_key ON project_links(project_key);
|
|
57
|
+
|
|
50
58
|
CREATE TABLE IF NOT EXISTS symbols (
|
|
51
59
|
id TEXT PRIMARY KEY,
|
|
52
60
|
project TEXT NOT NULL,
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { appendScope } from './filters.js';
|
|
2
2
|
import { toIndexEntry } from './rows.js';
|
|
3
|
+
import { noProjects } from '../project-scope.js';
|
|
3
4
|
export async function searchKeyword(pool, query) {
|
|
5
|
+
if (noProjects(query.project))
|
|
6
|
+
return [];
|
|
4
7
|
const conditions = ['tsv @@ q.tsq'];
|
|
5
8
|
const values = [query.text];
|
|
6
9
|
appendScope(query, conditions, values);
|