claude-db 0.12.2 → 0.12.4
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 +42 -0
- package/dist/capture/flush.js +41 -4
- package/dist/capture/index.d.ts +1 -0
- package/dist/capture/index.js +1 -0
- package/dist/capture/progress.js +8 -1
- package/dist/capture/vectors.d.ts +7 -0
- package/dist/capture/vectors.js +38 -0
- package/dist/catchup/gather.js +1 -0
- package/dist/cli/commands/adoption.js +41 -29
- package/dist/cli/commands/languages.js +10 -6
- package/dist/cli/commands/sync.js +5 -4
- package/dist/cli/commands/transfer.js +28 -8
- package/dist/facts/claude-memory.js +7 -2
- package/dist/facts/distill.js +4 -1
- package/dist/facts/handoff.js +6 -1
- package/dist/facts/health.js +2 -1
- package/dist/facts/known.js +2 -0
- package/dist/facts/start.js +1 -1
- package/dist/graph/query/answer.js +1 -1
- package/dist/graph/query/lookup.d.ts +1 -0
- package/dist/graph/query/lookup.js +2 -1
- package/dist/graph/query/path.js +69 -37
- package/dist/graph/query/suggest.js +1 -2
- package/dist/hooks/background.js +5 -1
- package/dist/hooks/compact.js +7 -1
- package/dist/hooks/detached.d.ts +1 -0
- package/dist/hooks/detached.js +37 -2
- package/dist/hooks/prefer-usages.js +1 -1
- package/dist/hooks/session-start.js +1 -1
- package/dist/hooks/start-legacy.js +1 -1
- package/dist/store/adapter.d.ts +5 -2
- package/dist/store/each.d.ts +2 -4
- package/dist/store/each.js +1 -0
- package/dist/store/mongo/graph.d.ts +2 -1
- package/dist/store/mongo/graph.js +17 -2
- package/dist/store/mongo/index.d.ts +4 -2
- package/dist/store/mongo/index.js +8 -2
- package/dist/store/mongo/observations.d.ts +2 -1
- package/dist/store/mongo/observations.js +25 -3
- package/dist/store/postgres/graph.d.ts +2 -1
- package/dist/store/postgres/graph.js +22 -7
- package/dist/store/postgres/index.d.ts +5 -2
- package/dist/store/postgres/index.js +14 -7
- package/dist/store/postgres/insert.js +3 -1
- package/dist/store/postgres/meta.d.ts +1 -0
- package/dist/store/postgres/meta.js +4 -0
- package/dist/store/postgres/observations.d.ts +3 -2
- package/dist/store/postgres/observations.js +40 -6
- package/dist/store/postgres/rows.js +1 -1
- package/dist/store/scoped-store.js +4 -0
- package/dist/store/sqlite/graph.d.ts +2 -1
- package/dist/store/sqlite/graph.js +19 -2
- package/dist/store/sqlite/index.d.ts +4 -2
- package/dist/store/sqlite/index.js +8 -2
- package/dist/store/sqlite/observations.d.ts +2 -1
- package/dist/store/sqlite/observations.js +32 -5
- package/dist/types.d.ts +9 -0
- package/package.json +6 -8
|
@@ -8,6 +8,7 @@ export async function insertObservations(pool, ensureVectorColumn, observations,
|
|
|
8
8
|
await client.query('BEGIN');
|
|
9
9
|
for (const obs of observations) {
|
|
10
10
|
const vectorStored = vectors && obs.embedding?.length === width;
|
|
11
|
+
const vectorKept = !obs.embedding?.length && obs.embedder != null;
|
|
11
12
|
const columns = [
|
|
12
13
|
'id',
|
|
13
14
|
'session_id',
|
|
@@ -43,8 +44,9 @@ export async function insertObservations(pool, ensureVectorColumn, observations,
|
|
|
43
44
|
const holes = values.map((_, i) => `$${i + 1}`).join(', ');
|
|
44
45
|
const updates = columns
|
|
45
46
|
.slice(1)
|
|
47
|
+
.filter((column) => !(vectorKept && column === 'embedder'))
|
|
46
48
|
.map((column) => `${column} = EXCLUDED.${column}`)
|
|
47
|
-
.concat(!vectorStored && (hasVectorColumn || vectors) ? ['embedding = NULL'] : [])
|
|
49
|
+
.concat(!vectorStored && !vectorKept && (hasVectorColumn || vectors) ? ['embedding = NULL'] : [])
|
|
48
50
|
.join(', ');
|
|
49
51
|
await client.query(`INSERT INTO observations (${columns.join(', ')}) VALUES (${holes})
|
|
50
52
|
ON CONFLICT (id) DO UPDATE SET ${updates}`, values);
|
|
@@ -8,3 +8,4 @@ export declare function ensureTagsIndexed(pool: Pool): Promise<void>;
|
|
|
8
8
|
export declare function readVectorDims(pool: Pool): Promise<number | null>;
|
|
9
9
|
export declare function tryEnableVector(pool: Pool): Promise<boolean>;
|
|
10
10
|
export declare function writeMeta(pool: Pool, vectorEnabled: boolean, vectorDims: number | null): Promise<void>;
|
|
11
|
+
export declare function indexEmbeddings(pool: Pool): Promise<void>;
|
|
@@ -65,3 +65,7 @@ export async function writeMeta(pool, vectorEnabled, vectorDims) {
|
|
|
65
65
|
vector_enabled = EXCLUDED.vector_enabled,
|
|
66
66
|
vector_dims = EXCLUDED.vector_dims`, [SCHEMA_VERSION, vectorEnabled, vectorDims]);
|
|
67
67
|
}
|
|
68
|
+
export async function indexEmbeddings(pool) {
|
|
69
|
+
await pool.query(`CREATE INDEX IF NOT EXISTS idx_obs_embedding
|
|
70
|
+
ON observations USING hnsw (embedding vector_cosine_ops)`);
|
|
71
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Pool } from './driver.js';
|
|
2
|
-
import type { ListFilter, Observation, ObservationIndexEntry, RemoveFilter, TimelineQuery } from '../../types.js';
|
|
2
|
+
import type { CountFilter, ListFilter, Observation, ObservationIndexEntry, RemoveFilter, TimelineQuery } from '../../types.js';
|
|
3
3
|
import type { ProjectSummary } from '../adapter.js';
|
|
4
4
|
export declare function getObservations(pool: Pool, ids: string[]): Promise<Observation[]>;
|
|
5
5
|
export declare function remove(pool: Pool, filter: RemoveFilter): Promise<number>;
|
|
6
|
-
export declare function list(pool: Pool, filter: ListFilter): Promise<Observation[]>;
|
|
6
|
+
export declare function list(pool: Pool, filter: ListFilter, hasVectorColumn?: boolean): Promise<Observation[]>;
|
|
7
|
+
export declare function count(pool: Pool, filter: CountFilter): Promise<number>;
|
|
7
8
|
export declare function listProjects(pool: Pool): Promise<ProjectSummary[]>;
|
|
8
9
|
export declare function inventory(pool: Pool): Promise<string[]>;
|
|
9
10
|
export declare function timeline(pool: Pool, query: TimelineQuery): Promise<ObservationIndexEntry[]>;
|
|
@@ -3,6 +3,13 @@ import { partitionIds } from '../../util/shortid.js';
|
|
|
3
3
|
import { excludeSessionsClause, projectClause } from './filters.js';
|
|
4
4
|
import { toIndexEntry, toObservation } from './rows.js';
|
|
5
5
|
import { noProjects } from '../project-scope.js';
|
|
6
|
+
const COLUMNS = 'id, session_id, project, kind, title, body, files, tags, created_at, embedder, author, status';
|
|
7
|
+
const WITHOUT_BODY = COLUMNS.replace(' body,', '');
|
|
8
|
+
function listColumns(filter) {
|
|
9
|
+
if (filter.vectors)
|
|
10
|
+
return '*';
|
|
11
|
+
return filter.bodies === false ? WITHOUT_BODY : COLUMNS;
|
|
12
|
+
}
|
|
6
13
|
export async function getObservations(pool, ids) {
|
|
7
14
|
if (ids.length === 0)
|
|
8
15
|
return [];
|
|
@@ -17,7 +24,7 @@ export async function getObservations(pool, ids) {
|
|
|
17
24
|
values.push(`${prefix.replace(/[%_]/g, '')}%`);
|
|
18
25
|
clauses.push(`id LIKE $${values.length}`);
|
|
19
26
|
}
|
|
20
|
-
const res = await pool.query(`SELECT
|
|
27
|
+
const res = await pool.query(`SELECT ${COLUMNS} FROM observations WHERE ${clauses.join(' OR ')}`, values);
|
|
21
28
|
return res.rows.map(toObservation);
|
|
22
29
|
}
|
|
23
30
|
export async function remove(pool, filter) {
|
|
@@ -76,11 +83,8 @@ export async function remove(pool, filter) {
|
|
|
76
83
|
client.release();
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
|
-
|
|
80
|
-
if (noProjects(filter.project))
|
|
81
|
-
return [];
|
|
86
|
+
function scopeConditions(filter, values) {
|
|
82
87
|
const conditions = [];
|
|
83
|
-
const values = [];
|
|
84
88
|
const project = projectClause(filter.project, values);
|
|
85
89
|
if (project)
|
|
86
90
|
conditions.push(project);
|
|
@@ -99,6 +103,17 @@ export async function list(pool, filter) {
|
|
|
99
103
|
values.push(filter.status);
|
|
100
104
|
conditions.push(`status = $${values.length}`);
|
|
101
105
|
}
|
|
106
|
+
if (filter.tag) {
|
|
107
|
+
values.push(JSON.stringify([filter.tag]));
|
|
108
|
+
conditions.push(`tags @> $${values.length}::jsonb`);
|
|
109
|
+
}
|
|
110
|
+
return conditions;
|
|
111
|
+
}
|
|
112
|
+
export async function list(pool, filter, hasVectorColumn = false) {
|
|
113
|
+
if (noProjects(filter.project))
|
|
114
|
+
return [];
|
|
115
|
+
const values = [];
|
|
116
|
+
const conditions = scopeConditions(filter, values);
|
|
102
117
|
if (filter.after !== undefined) {
|
|
103
118
|
if (filter.afterId === undefined) {
|
|
104
119
|
values.push(filter.after);
|
|
@@ -109,13 +124,32 @@ export async function list(pool, filter) {
|
|
|
109
124
|
conditions.push(`(created_at > $${values.length - 2} OR (created_at = $${values.length - 1} AND id > $${values.length}))`);
|
|
110
125
|
}
|
|
111
126
|
}
|
|
127
|
+
if (filter.vectorStale) {
|
|
128
|
+
const stale = hasVectorColumn
|
|
129
|
+
? ['embedder IS NULL', 'embedding IS NULL']
|
|
130
|
+
: ['embedder IS NULL'];
|
|
131
|
+
if (filter.vectorStale.embedder !== undefined) {
|
|
132
|
+
values.push(filter.vectorStale.embedder);
|
|
133
|
+
stale.push(`embedder <> $${values.length}`);
|
|
134
|
+
}
|
|
135
|
+
conditions.push(`(${stale.join(' OR ')})`);
|
|
136
|
+
}
|
|
112
137
|
values.push(filter.limit ?? 1000);
|
|
113
138
|
const direction = filter.newest ? 'DESC' : 'ASC';
|
|
114
|
-
const res = await pool.query(`SELECT
|
|
139
|
+
const res = await pool.query(`SELECT ${listColumns(filter)} FROM observations
|
|
115
140
|
${conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''}
|
|
116
141
|
ORDER BY created_at ${direction}, id ${direction} LIMIT $${values.length}`, values);
|
|
117
142
|
return res.rows.map(toObservation);
|
|
118
143
|
}
|
|
144
|
+
export async function count(pool, filter) {
|
|
145
|
+
if (noProjects(filter.project))
|
|
146
|
+
return 0;
|
|
147
|
+
const values = [];
|
|
148
|
+
const conditions = scopeConditions(filter, values);
|
|
149
|
+
const res = await pool.query(`SELECT COUNT(*)::int AS n FROM observations
|
|
150
|
+
${conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''}`, values);
|
|
151
|
+
return Number(res.rows[0]?.['n'] ?? 0);
|
|
152
|
+
}
|
|
119
153
|
export async function listProjects(pool) {
|
|
120
154
|
const res = await pool.query(`SELECT project, COUNT(*)::int AS n, MAX(created_at) AS last
|
|
121
155
|
FROM observations GROUP BY project ORDER BY last DESC`);
|
|
@@ -27,6 +27,10 @@ export function withProjectScope(inner, resolver) {
|
|
|
27
27
|
const project = await expand(filter.project);
|
|
28
28
|
return inner.list(project === undefined ? filter : { ...filter, project });
|
|
29
29
|
},
|
|
30
|
+
async count(filter) {
|
|
31
|
+
const project = await expand(filter.project);
|
|
32
|
+
return inner.count(project === undefined ? filter : { ...filter, project });
|
|
33
|
+
},
|
|
30
34
|
async searchKeyword(query) {
|
|
31
35
|
const project = await expand(query.project);
|
|
32
36
|
return inner.searchKeyword(project === undefined ? query : { ...query, project });
|
|
@@ -6,6 +6,7 @@ export declare function upsertGraph(db: DatabaseSync, scan: {
|
|
|
6
6
|
files: ScannedFile[];
|
|
7
7
|
}): Promise<void>;
|
|
8
8
|
export declare function findSymbols(db: DatabaseSync, filter: SymbolFilter): Promise<CodeSymbol[]>;
|
|
9
|
+
export declare function symbolNames(db: DatabaseSync, project: string, limit: number): Promise<string[]>;
|
|
9
10
|
export declare function findEdges(db: DatabaseSync, filter: EdgeFilter): Promise<CodeEdge[]>;
|
|
10
|
-
export declare function scannedFiles(db: DatabaseSync, project: string): Promise<ScannedFile[]>;
|
|
11
|
+
export declare function scannedFiles(db: DatabaseSync, project: string, limit?: number): Promise<ScannedFile[]>;
|
|
11
12
|
export declare function removeGraph(db: DatabaseSync, project: string, files?: string[]): Promise<number>;
|
|
@@ -45,6 +45,12 @@ export async function findSymbols(db, filter) {
|
|
|
45
45
|
.all(...params);
|
|
46
46
|
return rows.map(toSymbol);
|
|
47
47
|
}
|
|
48
|
+
export async function symbolNames(db, project, limit) {
|
|
49
|
+
const rows = db
|
|
50
|
+
.prepare('SELECT name FROM symbols WHERE project = ? ORDER BY file, line LIMIT ?')
|
|
51
|
+
.all(project, limit);
|
|
52
|
+
return rows.map((row) => row['name']);
|
|
53
|
+
}
|
|
48
54
|
export async function findEdges(db, filter) {
|
|
49
55
|
const params = [filter.project];
|
|
50
56
|
const sides = [];
|
|
@@ -57,6 +63,15 @@ export async function findEdges(db, filter) {
|
|
|
57
63
|
sides.push(`${column} IN (${ids.map(() => '?').join(',')})`);
|
|
58
64
|
params.push(...ids);
|
|
59
65
|
}
|
|
66
|
+
for (const [side, names] of [
|
|
67
|
+
['src', filter.unresolvedSrcNames],
|
|
68
|
+
['dst', filter.unresolvedDstNames],
|
|
69
|
+
]) {
|
|
70
|
+
if (!names || names.length === 0)
|
|
71
|
+
continue;
|
|
72
|
+
sides.push(`(${side}_id = '' AND ${side}_name IN (${names.map(() => '?').join(',')}))`);
|
|
73
|
+
params.push(...names);
|
|
74
|
+
}
|
|
60
75
|
let where = sides.length > 0 ? ` AND (${sides.join(' OR ')})` : '';
|
|
61
76
|
if (filter.dstName !== undefined) {
|
|
62
77
|
where += ' AND (dst_name = ? OR dst_name LIKE ?)';
|
|
@@ -68,8 +83,10 @@ export async function findEdges(db, filter) {
|
|
|
68
83
|
.all(...params);
|
|
69
84
|
return rows.map(toEdge);
|
|
70
85
|
}
|
|
71
|
-
export async function scannedFiles(db, project) {
|
|
72
|
-
const rows =
|
|
86
|
+
export async function scannedFiles(db, project, limit) {
|
|
87
|
+
const rows = (limit === undefined
|
|
88
|
+
? db.prepare('SELECT * FROM scanned_files WHERE project = ?').all(project)
|
|
89
|
+
: db.prepare('SELECT * FROM scanned_files WHERE project = ? LIMIT ?').all(project, limit));
|
|
73
90
|
return rows.map((row) => ({
|
|
74
91
|
project: row['project'],
|
|
75
92
|
path: row['path'],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CodeEdge, CodeSymbol, EdgeFilter, ListFilter, Observation, ObservationIndexEntry, ProjectFilter, RemoveFilter, ScannedFile, SearchQuery, Session, SymbolFilter, TimelineQuery } from '../../types.js';
|
|
1
|
+
import type { CodeEdge, CodeSymbol, CountFilter, 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 const HERE: string;
|
|
4
4
|
export declare class SqliteStore implements MemoryStore {
|
|
@@ -19,6 +19,7 @@ export declare class SqliteStore implements MemoryStore {
|
|
|
19
19
|
getObservations(ids: string[]): Promise<Observation[]>;
|
|
20
20
|
remove(filter: RemoveFilter): Promise<number>;
|
|
21
21
|
list(filter: ListFilter): Promise<Observation[]>;
|
|
22
|
+
count(filter: CountFilter): Promise<number>;
|
|
22
23
|
listProjects(): Promise<ProjectSummary[]>;
|
|
23
24
|
sessionProjects(): Promise<string[]>;
|
|
24
25
|
inventory(): Promise<string[]>;
|
|
@@ -33,7 +34,8 @@ export declare class SqliteStore implements MemoryStore {
|
|
|
33
34
|
files: ScannedFile[];
|
|
34
35
|
}): Promise<void>;
|
|
35
36
|
findSymbols(filter: SymbolFilter): Promise<CodeSymbol[]>;
|
|
37
|
+
symbolNames(project: string, limit: number): Promise<string[]>;
|
|
36
38
|
findEdges(filter: EdgeFilter): Promise<CodeEdge[]>;
|
|
37
|
-
scannedFiles(project: string): Promise<ScannedFile[]>;
|
|
39
|
+
scannedFiles(project: string, limit?: number): Promise<ScannedFile[]>;
|
|
38
40
|
removeGraph(project: string, files?: string[]): Promise<number>;
|
|
39
41
|
}
|
|
@@ -97,6 +97,9 @@ export class SqliteStore {
|
|
|
97
97
|
async list(filter) {
|
|
98
98
|
return observationsOps.list(this.db, filter);
|
|
99
99
|
}
|
|
100
|
+
async count(filter) {
|
|
101
|
+
return observationsOps.count(this.db, filter);
|
|
102
|
+
}
|
|
100
103
|
async listProjects() {
|
|
101
104
|
return observationsOps.listProjects(this.db);
|
|
102
105
|
}
|
|
@@ -127,11 +130,14 @@ export class SqliteStore {
|
|
|
127
130
|
async findSymbols(filter) {
|
|
128
131
|
return graphOps.findSymbols(this.db, filter);
|
|
129
132
|
}
|
|
133
|
+
async symbolNames(project, limit) {
|
|
134
|
+
return graphOps.symbolNames(this.db, project, limit);
|
|
135
|
+
}
|
|
130
136
|
async findEdges(filter) {
|
|
131
137
|
return graphOps.findEdges(this.db, filter);
|
|
132
138
|
}
|
|
133
|
-
async scannedFiles(project) {
|
|
134
|
-
return graphOps.scannedFiles(this.db, project);
|
|
139
|
+
async scannedFiles(project, limit) {
|
|
140
|
+
return graphOps.scannedFiles(this.db, project, limit);
|
|
135
141
|
}
|
|
136
142
|
async removeGraph(project, files) {
|
|
137
143
|
return graphOps.removeGraph(this.db, project, files);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { DatabaseSync } from 'node:sqlite';
|
|
2
|
-
import type { ListFilter, Observation, RemoveFilter } from '../../types.js';
|
|
2
|
+
import type { CountFilter, ListFilter, Observation, RemoveFilter } from '../../types.js';
|
|
3
3
|
import type { ProjectSummary } from '../adapter.js';
|
|
4
4
|
export declare function insertObservations(db: DatabaseSync, observations: Observation[]): Promise<void>;
|
|
5
5
|
export declare function getObservations(db: DatabaseSync, ids: string[]): Promise<Observation[]>;
|
|
6
6
|
export declare function remove(db: DatabaseSync, filter: RemoveFilter): Promise<number>;
|
|
7
7
|
export declare function list(db: DatabaseSync, filter: ListFilter): Promise<Observation[]>;
|
|
8
|
+
export declare function count(db: DatabaseSync, filter: CountFilter): Promise<number>;
|
|
8
9
|
export declare function listProjects(db: DatabaseSync): Promise<ProjectSummary[]>;
|
|
9
10
|
export declare function inventory(db: DatabaseSync): Promise<string[]>;
|
|
10
11
|
export declare function closeObservations(db: DatabaseSync, ids: string[]): Promise<number>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { foreignNames, isWholeScope } from '../adapter.js';
|
|
2
2
|
import { toObservation } from './rows.js';
|
|
3
|
-
import { excludeSessionsClause, projectClause, removeWhere } from './filters.js';
|
|
3
|
+
import { TAG_PREDICATE, excludeSessionsClause, projectClause, removeWhere } from './filters.js';
|
|
4
4
|
import { partitionIds } from '../../util/shortid.js';
|
|
5
5
|
import { packVector } from '../../util/vector.js';
|
|
6
6
|
import { scopeToken } from '../../util/scope.js';
|
|
@@ -76,11 +76,8 @@ export async function remove(db, filter) {
|
|
|
76
76
|
db.exec('VACUUM');
|
|
77
77
|
return count?.n ?? 0;
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
if (noProjects(filter.project))
|
|
81
|
-
return [];
|
|
79
|
+
function scopeConditions(filter, params) {
|
|
82
80
|
const conditions = [];
|
|
83
|
-
const params = [];
|
|
84
81
|
const project = projectClause('project', filter.project, params);
|
|
85
82
|
if (project)
|
|
86
83
|
conditions.push(project);
|
|
@@ -99,6 +96,17 @@ export async function list(db, filter) {
|
|
|
99
96
|
conditions.push('status = ?');
|
|
100
97
|
params.push(filter.status);
|
|
101
98
|
}
|
|
99
|
+
if (filter.tag) {
|
|
100
|
+
conditions.push(TAG_PREDICATE(''));
|
|
101
|
+
params.push(filter.tag);
|
|
102
|
+
}
|
|
103
|
+
return conditions;
|
|
104
|
+
}
|
|
105
|
+
export async function list(db, filter) {
|
|
106
|
+
if (noProjects(filter.project))
|
|
107
|
+
return [];
|
|
108
|
+
const params = [];
|
|
109
|
+
const conditions = scopeConditions(filter, params);
|
|
102
110
|
if (filter.after !== undefined) {
|
|
103
111
|
if (filter.afterId === undefined) {
|
|
104
112
|
conditions.push('created_at > ?');
|
|
@@ -109,6 +117,14 @@ export async function list(db, filter) {
|
|
|
109
117
|
params.push(filter.after, filter.after, filter.afterId);
|
|
110
118
|
}
|
|
111
119
|
}
|
|
120
|
+
if (filter.vectorStale) {
|
|
121
|
+
const stale = ['embedding IS NULL', 'embedder IS NULL'];
|
|
122
|
+
if (filter.vectorStale.embedder !== undefined) {
|
|
123
|
+
stale.push('embedder != ?');
|
|
124
|
+
params.push(filter.vectorStale.embedder);
|
|
125
|
+
}
|
|
126
|
+
conditions.push(`(${stale.join(' OR ')})`);
|
|
127
|
+
}
|
|
112
128
|
params.push(filter.limit ?? 1000);
|
|
113
129
|
const direction = filter.newest ? 'DESC' : 'ASC';
|
|
114
130
|
const rows = db
|
|
@@ -118,6 +134,17 @@ export async function list(db, filter) {
|
|
|
118
134
|
.all(...params);
|
|
119
135
|
return rows.map(toObservation);
|
|
120
136
|
}
|
|
137
|
+
export async function count(db, filter) {
|
|
138
|
+
if (noProjects(filter.project))
|
|
139
|
+
return 0;
|
|
140
|
+
const params = [];
|
|
141
|
+
const conditions = scopeConditions(filter, params);
|
|
142
|
+
const row = db
|
|
143
|
+
.prepare(`SELECT COUNT(*) AS n FROM observations
|
|
144
|
+
${conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : ''}`)
|
|
145
|
+
.get(...params);
|
|
146
|
+
return Number(row?.n ?? 0);
|
|
147
|
+
}
|
|
121
148
|
export async function listProjects(db) {
|
|
122
149
|
const rows = db
|
|
123
150
|
.prepare(`SELECT project, COUNT(*) AS n, MAX(created_at) AS last
|
package/dist/types.d.ts
CHANGED
|
@@ -58,11 +58,18 @@ export interface ListFilter {
|
|
|
58
58
|
excludeSessions?: string[];
|
|
59
59
|
kind?: ObservationKind;
|
|
60
60
|
status?: ObservationStatus;
|
|
61
|
+
tag?: string;
|
|
61
62
|
after?: number;
|
|
62
63
|
afterId?: string;
|
|
63
64
|
limit?: number;
|
|
64
65
|
newest?: boolean;
|
|
66
|
+
vectors?: boolean;
|
|
67
|
+
bodies?: boolean;
|
|
68
|
+
vectorStale?: {
|
|
69
|
+
embedder?: string;
|
|
70
|
+
};
|
|
65
71
|
}
|
|
72
|
+
export type CountFilter = Pick<ListFilter, 'project' | 'sessionId' | 'excludeSessions' | 'kind' | 'status' | 'tag'>;
|
|
66
73
|
export interface TimelineQuery {
|
|
67
74
|
observationId: string;
|
|
68
75
|
before: number;
|
|
@@ -104,6 +111,8 @@ export interface EdgeFilter {
|
|
|
104
111
|
project: string;
|
|
105
112
|
srcIds?: string[];
|
|
106
113
|
dstIds?: string[];
|
|
114
|
+
unresolvedSrcNames?: string[];
|
|
115
|
+
unresolvedDstNames?: string[];
|
|
107
116
|
dstName?: string;
|
|
108
117
|
limit?: number;
|
|
109
118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-db",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4",
|
|
4
4
|
"description": "Free, open-source memory for Claude Code. Remembers why decisions were made and maps your code. Your own database (SQLite, Postgres or MongoDB), no cloud, no subscription.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -54,8 +54,6 @@
|
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@ast-grep/napi": "^0.45.0",
|
|
56
56
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
57
|
-
"graphology": "^0.26.0",
|
|
58
|
-
"graphology-shortest-path": "^2.1.0",
|
|
59
57
|
"oxc-resolver": "^11.24.2",
|
|
60
58
|
"zod": "^4.4.3"
|
|
61
59
|
},
|
|
@@ -130,10 +128,10 @@
|
|
|
130
128
|
"access": "public"
|
|
131
129
|
},
|
|
132
130
|
"optionalDependencies": {
|
|
133
|
-
"claude-db-grammars-linux-x64": "0.12.
|
|
134
|
-
"claude-db-grammars-linux-arm64": "0.12.
|
|
135
|
-
"claude-db-grammars-darwin-x64": "0.12.
|
|
136
|
-
"claude-db-grammars-darwin-arm64": "0.12.
|
|
137
|
-
"claude-db-grammars-win32-x64": "0.12.
|
|
131
|
+
"claude-db-grammars-linux-x64": "0.12.4",
|
|
132
|
+
"claude-db-grammars-linux-arm64": "0.12.4",
|
|
133
|
+
"claude-db-grammars-darwin-x64": "0.12.4",
|
|
134
|
+
"claude-db-grammars-darwin-arm64": "0.12.4",
|
|
135
|
+
"claude-db-grammars-win32-x64": "0.12.4"
|
|
138
136
|
}
|
|
139
137
|
}
|