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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Pool } from './driver.js';
|
|
2
|
-
import type { Session } from '../../types.js';
|
|
2
|
+
import type { ProjectFilter, Session } from '../../types.js';
|
|
3
3
|
export declare function upsertSession(pool: Pool, session: Session): Promise<void>;
|
|
4
4
|
export declare function getSession(pool: Pool, id: string): Promise<Session | null>;
|
|
5
5
|
export declare function clearSummary(pool: Pool, id: string): Promise<boolean>;
|
|
6
|
-
export declare function recentSessions(pool: Pool, project:
|
|
6
|
+
export declare function recentSessions(pool: Pool, project: ProjectFilter, limit: number): Promise<Session[]>;
|
|
7
7
|
export declare function sessionProjects(pool: Pool): Promise<string[]>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { projectClause } from './filters.js';
|
|
1
2
|
import { toSession } from './rows.js';
|
|
2
3
|
import { summaryTime } from '../session-time.js';
|
|
4
|
+
import { noProjects } from '../project-scope.js';
|
|
3
5
|
export async function upsertSession(pool, session) {
|
|
4
6
|
await pool.query(`INSERT INTO sessions (id, project, started_at, ended_at, summary, updated_at, distilled_at)
|
|
5
7
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
@@ -28,9 +30,14 @@ export async function clearSummary(pool, id) {
|
|
|
28
30
|
return (result.rowCount ?? 0) > 0;
|
|
29
31
|
}
|
|
30
32
|
export async function recentSessions(pool, project, limit) {
|
|
33
|
+
if (noProjects(project))
|
|
34
|
+
return [];
|
|
35
|
+
const values = [];
|
|
36
|
+
const scope = projectClause(project, values) ?? 'TRUE';
|
|
37
|
+
values.push(limit);
|
|
31
38
|
const res = await pool.query(`SELECT * FROM sessions
|
|
32
|
-
WHERE
|
|
33
|
-
ORDER BY started_at DESC LIMIT
|
|
39
|
+
WHERE ${scope} AND summary IS NOT NULL
|
|
40
|
+
ORDER BY started_at DESC LIMIT $${values.length}`, values);
|
|
34
41
|
return res.rows.map(toSession);
|
|
35
42
|
}
|
|
36
43
|
export async function sessionProjects(pool) {
|
|
@@ -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 searchVector(pool, vectorEnabled, vectorDims, vector, query) {
|
|
5
|
+
if (noProjects(query.project))
|
|
6
|
+
return [];
|
|
4
7
|
if (!vectorEnabled || vectorDims !== vector.length)
|
|
5
8
|
return [];
|
|
6
9
|
const conditions = ['embedding IS NOT NULL'];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MemoryStore } from './adapter.js';
|
|
2
|
+
export interface ScopeResolverOptions {
|
|
3
|
+
store: Pick<MemoryStore, 'linkProject' | 'projectScope'>;
|
|
4
|
+
remote: string;
|
|
5
|
+
isFolder?: (value: string) => boolean;
|
|
6
|
+
keyOf?: (folder: string, remote: string) => string;
|
|
7
|
+
}
|
|
8
|
+
export interface ProjectScope {
|
|
9
|
+
key: string;
|
|
10
|
+
names: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface ScopeResolver {
|
|
13
|
+
resolve(value: string): Promise<ProjectScope>;
|
|
14
|
+
}
|
|
15
|
+
export declare function isExistingFolder(value: string): boolean;
|
|
16
|
+
export declare function createScopeResolver(options: ScopeResolverOptions): ScopeResolver;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { statSync } from 'node:fs';
|
|
2
|
+
import { isAbsolute } from 'node:path';
|
|
3
|
+
import { projectKey } from '../util/project-key.js';
|
|
4
|
+
import { orderScope } from './project-scope.js';
|
|
5
|
+
export function isExistingFolder(value) {
|
|
6
|
+
if (!isAbsolute(value))
|
|
7
|
+
return false;
|
|
8
|
+
try {
|
|
9
|
+
return statSync(value, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function createScopeResolver(options) {
|
|
16
|
+
const { store, remote, isFolder = isExistingFolder, keyOf = (folder, name) => projectKey(folder, { remote: name }), } = options;
|
|
17
|
+
const keys = new Map();
|
|
18
|
+
async function linkedKey(folder) {
|
|
19
|
+
const key = keyOf(folder, remote);
|
|
20
|
+
try {
|
|
21
|
+
await store.linkProject(folder, key);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return key;
|
|
25
|
+
}
|
|
26
|
+
return key;
|
|
27
|
+
}
|
|
28
|
+
async function namesFor(folder, key) {
|
|
29
|
+
try {
|
|
30
|
+
return orderScope(folder, [...(await store.projectScope(folder)), key]);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return orderScope(folder, [key]);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
async resolve(value) {
|
|
38
|
+
if (!isFolder(value))
|
|
39
|
+
return { key: value, names: [value] };
|
|
40
|
+
let pending = keys.get(value);
|
|
41
|
+
if (!pending) {
|
|
42
|
+
pending = linkedKey(value);
|
|
43
|
+
keys.set(value, pending);
|
|
44
|
+
}
|
|
45
|
+
const key = await pending;
|
|
46
|
+
return { key, names: await namesFor(value, key) };
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ProjectFilter } from '../types.js';
|
|
2
|
+
export declare function projectsOf(filter: ProjectFilter | undefined): string[];
|
|
3
|
+
export declare function noProjects(filter: ProjectFilter | undefined): boolean;
|
|
4
|
+
export declare function isLinkable(folder: string, key: string): boolean;
|
|
5
|
+
export declare function orderScope(folder: string, related: Iterable<string>): string[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function projectsOf(filter) {
|
|
2
|
+
if (filter === undefined)
|
|
3
|
+
return [];
|
|
4
|
+
const values = typeof filter === 'string' ? [filter] : filter;
|
|
5
|
+
return [...new Set(values.filter((value) => value.length > 0))];
|
|
6
|
+
}
|
|
7
|
+
export function noProjects(filter) {
|
|
8
|
+
return typeof filter !== 'string' && filter !== undefined && projectsOf(filter).length === 0;
|
|
9
|
+
}
|
|
10
|
+
export function isLinkable(folder, key) {
|
|
11
|
+
return folder.trim().length > 0 && key.trim().length > 0 && folder !== key;
|
|
12
|
+
}
|
|
13
|
+
export function orderScope(folder, related) {
|
|
14
|
+
const others = [...new Set(related)].filter((value) => value !== folder).sort();
|
|
15
|
+
return [folder, ...others];
|
|
16
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export function withProjectScope(inner, resolver) {
|
|
2
|
+
const keyOf = async (project) => (await resolver.resolve(project)).key;
|
|
3
|
+
async function expand(filter) {
|
|
4
|
+
if (filter === undefined)
|
|
5
|
+
return undefined;
|
|
6
|
+
const values = typeof filter === 'string' ? [filter] : filter;
|
|
7
|
+
const scopes = await Promise.all(values.map((value) => resolver.resolve(value)));
|
|
8
|
+
const names = [...new Set(scopes.flatMap((scope) => scope.names))];
|
|
9
|
+
return typeof filter === 'string' && names.length === 1 ? names[0] : names;
|
|
10
|
+
}
|
|
11
|
+
const overrides = {
|
|
12
|
+
async insertObservations(observations) {
|
|
13
|
+
const keyed = await Promise.all(observations.map(async (obs) => ({ ...obs, project: await keyOf(obs.project) })));
|
|
14
|
+
return inner.insertObservations(keyed);
|
|
15
|
+
},
|
|
16
|
+
async upsertSession(session) {
|
|
17
|
+
return inner.upsertSession({ ...session, project: await keyOf(session.project) });
|
|
18
|
+
},
|
|
19
|
+
async recentSessions(project, limit) {
|
|
20
|
+
return inner.recentSessions((await expand(project)) ?? project, limit);
|
|
21
|
+
},
|
|
22
|
+
async remove(filter) {
|
|
23
|
+
const project = await expand(filter.project);
|
|
24
|
+
return inner.remove(project === undefined ? filter : { ...filter, project });
|
|
25
|
+
},
|
|
26
|
+
async list(filter) {
|
|
27
|
+
const project = await expand(filter.project);
|
|
28
|
+
return inner.list(project === undefined ? filter : { ...filter, project });
|
|
29
|
+
},
|
|
30
|
+
async searchKeyword(query) {
|
|
31
|
+
const project = await expand(query.project);
|
|
32
|
+
return inner.searchKeyword(project === undefined ? query : { ...query, project });
|
|
33
|
+
},
|
|
34
|
+
async searchVector(vector, query) {
|
|
35
|
+
const project = await expand(query.project);
|
|
36
|
+
return inner.searchVector(vector, project === undefined ? query : { ...query, project });
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
return new Proxy(inner, {
|
|
40
|
+
get(target, property, receiver) {
|
|
41
|
+
if (property in overrides)
|
|
42
|
+
return overrides[property];
|
|
43
|
+
const value = Reflect.get(target, property, receiver);
|
|
44
|
+
if (typeof value !== 'function')
|
|
45
|
+
return value;
|
|
46
|
+
return value.bind(target);
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { RemoveFilter, SearchQuery } from '../../types.js';
|
|
1
|
+
import type { ProjectFilter, RemoveFilter, SearchQuery } from '../../types.js';
|
|
2
|
+
export declare function projectClause(column: string, filter: ProjectFilter | undefined, params: unknown[]): string | null;
|
|
2
3
|
export declare function removeWhere(filter: RemoveFilter): {
|
|
3
4
|
where: string;
|
|
4
5
|
params: unknown[];
|
|
5
6
|
};
|
|
6
7
|
export declare const TAG_PREDICATE: (prefix: string) => string;
|
|
7
8
|
export declare function appendScope(query: SearchQuery, conditions: string[], params: unknown[], prefix: string): void;
|
|
8
|
-
export declare function toMatchExpression(text: string, project?:
|
|
9
|
+
export declare function toMatchExpression(text: string, project?: ProjectFilter): string | null;
|
|
9
10
|
export declare function toFilePath(uri: string): string;
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import { projectsOf } from '../project-scope.js';
|
|
1
2
|
import { partitionIds } from '../../util/shortid.js';
|
|
2
3
|
import { resolve } from 'node:path';
|
|
3
4
|
import { scopeToken } from '../../util/scope.js';
|
|
4
5
|
import { meaningfulTokens } from '../../search/stopwords.js';
|
|
6
|
+
export function projectClause(column, filter, params) {
|
|
7
|
+
const projects = projectsOf(filter);
|
|
8
|
+
if (projects.length === 0)
|
|
9
|
+
return null;
|
|
10
|
+
params.push(...projects);
|
|
11
|
+
return projects.length === 1
|
|
12
|
+
? `${column} = ?`
|
|
13
|
+
: `${column} IN (${projects.map(() => '?').join(',')})`;
|
|
14
|
+
}
|
|
5
15
|
export function removeWhere(filter) {
|
|
6
16
|
const conditions = [];
|
|
7
17
|
const params = [];
|
|
@@ -18,10 +28,9 @@ export function removeWhere(filter) {
|
|
|
18
28
|
}
|
|
19
29
|
conditions.push(`(${alternatives.join(' OR ')})`);
|
|
20
30
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
31
|
+
const project = projectClause('project', filter.project, params);
|
|
32
|
+
if (project)
|
|
33
|
+
conditions.push(project);
|
|
25
34
|
if (filter.kind) {
|
|
26
35
|
conditions.push('kind = ?');
|
|
27
36
|
params.push(filter.kind);
|
|
@@ -38,10 +47,9 @@ export function removeWhere(filter) {
|
|
|
38
47
|
export const TAG_PREDICATE = (prefix) => `EXISTS (SELECT 1 FROM json_each(${prefix}tags) WHERE value = ?)`;
|
|
39
48
|
export function appendScope(query, conditions, params, prefix) {
|
|
40
49
|
conditions.push(`${prefix}status != 'replaced'`);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
50
|
+
const project = projectClause(`${prefix}project`, query.project, params);
|
|
51
|
+
if (project)
|
|
52
|
+
conditions.push(project);
|
|
45
53
|
if (query.kind) {
|
|
46
54
|
conditions.push(`${prefix}kind = ?`);
|
|
47
55
|
params.push(query.kind);
|
|
@@ -63,9 +71,15 @@ export function appendScope(query, conditions, params, prefix) {
|
|
|
63
71
|
params.push(...query.excludeSessions);
|
|
64
72
|
}
|
|
65
73
|
}
|
|
74
|
+
function scopeExpression(filter) {
|
|
75
|
+
const tokens = projectsOf(filter).map(scopeToken);
|
|
76
|
+
if (tokens.length === 0)
|
|
77
|
+
return null;
|
|
78
|
+
return tokens.length === 1 ? `scope:${tokens[0]}` : `scope:(${tokens.join(' OR ')})`;
|
|
79
|
+
}
|
|
66
80
|
export function toMatchExpression(text, project) {
|
|
67
81
|
const tokens = meaningfulTokens(text);
|
|
68
|
-
const scope =
|
|
82
|
+
const scope = scopeExpression(project);
|
|
69
83
|
if (tokens.length === 0)
|
|
70
84
|
return null;
|
|
71
85
|
const terms = tokens.map((token) => `"${token}"`).join(' OR ');
|
|
@@ -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 const HERE: string;
|
|
4
4
|
export declare class SqliteStore implements MemoryStore {
|
|
@@ -9,9 +9,11 @@ export declare class SqliteStore implements 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
|
clearSummary(id: string): Promise<boolean>;
|
|
16
18
|
insertObservations(observations: Observation[]): Promise<void>;
|
|
17
19
|
getObservations(ids: string[]): Promise<Observation[]>;
|
|
@@ -2,6 +2,7 @@ import * as observationsOps from './observations.js';
|
|
|
2
2
|
import * as searchOps from './search.js';
|
|
3
3
|
import * as sessionsOps from './sessions.js';
|
|
4
4
|
import * as graphOps from './graph.js';
|
|
5
|
+
import * as projectLinksOps from './project-links.js';
|
|
5
6
|
import { DatabaseSync } from 'node:sqlite';
|
|
6
7
|
import { toFilePath } from './filters.js';
|
|
7
8
|
import { dirname, resolve } from 'node:path';
|
|
@@ -66,6 +67,12 @@ export class SqliteStore {
|
|
|
66
67
|
async ping() {
|
|
67
68
|
return this.db.prepare('SELECT 1 AS ok').get() !== undefined;
|
|
68
69
|
}
|
|
70
|
+
async linkProject(folder, key, now = Date.now()) {
|
|
71
|
+
return projectLinksOps.linkProject(this.db, folder, key, now);
|
|
72
|
+
}
|
|
73
|
+
async projectScope(folder) {
|
|
74
|
+
return projectLinksOps.projectScope(this.db, folder);
|
|
75
|
+
}
|
|
69
76
|
async upsertSession(session) {
|
|
70
77
|
return sessionsOps.upsertSession(this.db, session);
|
|
71
78
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { foreignNames, isWholeScope } from '../adapter.js';
|
|
2
2
|
import { toObservation } from './rows.js';
|
|
3
|
-
import { removeWhere } from './filters.js';
|
|
3
|
+
import { 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';
|
|
7
|
+
import { noProjects } from '../project-scope.js';
|
|
7
8
|
export async function insertObservations(db, observations) {
|
|
8
9
|
if (observations.length === 0)
|
|
9
10
|
return;
|
|
@@ -43,6 +44,8 @@ export async function getObservations(db, ids) {
|
|
|
43
44
|
return rows.map(toObservation);
|
|
44
45
|
}
|
|
45
46
|
export async function remove(db, filter) {
|
|
47
|
+
if (noProjects(filter.project))
|
|
48
|
+
return 0;
|
|
46
49
|
if (filter.ids?.length === 0)
|
|
47
50
|
return 0;
|
|
48
51
|
const { where, params } = removeWhere(filter);
|
|
@@ -54,8 +57,10 @@ export async function remove(db, filter) {
|
|
|
54
57
|
try {
|
|
55
58
|
db.prepare(`DELETE FROM observations ${where}`).run(...params);
|
|
56
59
|
if (wipe) {
|
|
57
|
-
const
|
|
58
|
-
const
|
|
60
|
+
const wipeParams = [];
|
|
61
|
+
const wipeClause = projectClause('project', filter.project, wipeParams);
|
|
62
|
+
const scope = wipeClause ? `WHERE ${wipeClause}` : '';
|
|
63
|
+
const scopeParams = wipeParams;
|
|
59
64
|
db.prepare(`DELETE FROM sessions ${scope}`).run(...scopeParams);
|
|
60
65
|
for (const table of ['symbols', 'symbol_edges', 'scanned_files']) {
|
|
61
66
|
db.prepare(`DELETE FROM ${table} ${scope}`).run(...scopeParams);
|
|
@@ -72,12 +77,13 @@ export async function remove(db, filter) {
|
|
|
72
77
|
return count?.n ?? 0;
|
|
73
78
|
}
|
|
74
79
|
export async function list(db, filter) {
|
|
80
|
+
if (noProjects(filter.project))
|
|
81
|
+
return [];
|
|
75
82
|
const conditions = [];
|
|
76
83
|
const params = [];
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
84
|
+
const project = projectClause('project', filter.project, params);
|
|
85
|
+
if (project)
|
|
86
|
+
conditions.push(project);
|
|
81
87
|
if (filter.sessionId) {
|
|
82
88
|
conditions.push('session_id = ?');
|
|
83
89
|
params.push(filter.sessionId);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isLinkable, orderScope } from '../project-scope.js';
|
|
2
|
+
export async function linkProject(db, folder, key, now) {
|
|
3
|
+
if (!isLinkable(folder, key))
|
|
4
|
+
return;
|
|
5
|
+
db.prepare('INSERT OR IGNORE INTO project_links (folder, project_key, first_seen) VALUES (?, ?, ?)').run(folder, key, now);
|
|
6
|
+
}
|
|
7
|
+
export async function projectScope(db, folder) {
|
|
8
|
+
const rows = db
|
|
9
|
+
.prepare(`SELECT project_key AS value FROM project_links WHERE folder = ?
|
|
10
|
+
UNION
|
|
11
|
+
SELECT folder AS value FROM project_links
|
|
12
|
+
WHERE project_key IN (SELECT project_key FROM project_links WHERE folder = ?)`)
|
|
13
|
+
.all(folder, folder);
|
|
14
|
+
return orderScope(folder, rows.map((row) => String(row['value'])));
|
|
15
|
+
}
|
|
@@ -102,3 +102,12 @@ CREATE TABLE IF NOT EXISTS scanned_files (
|
|
|
102
102
|
scanned_at INTEGER NOT NULL,
|
|
103
103
|
PRIMARY KEY (project, path)
|
|
104
104
|
);
|
|
105
|
+
|
|
106
|
+
CREATE TABLE IF NOT EXISTS project_links (
|
|
107
|
+
folder TEXT NOT NULL,
|
|
108
|
+
project_key TEXT NOT NULL,
|
|
109
|
+
first_seen INTEGER NOT NULL,
|
|
110
|
+
PRIMARY KEY (folder, project_key)
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
CREATE INDEX IF NOT EXISTS idx_project_links_key ON project_links(project_key);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { toBuffer, toIndexEntry } from './rows.js';
|
|
2
2
|
import { TAG_PREDICATE, appendScope, toMatchExpression } from './filters.js';
|
|
3
3
|
import { cosine, unpackVector } from '../../util/vector.js';
|
|
4
|
+
import { noProjects } from '../project-scope.js';
|
|
4
5
|
export async function searchKeyword(db, query) {
|
|
6
|
+
if (noProjects(query.project))
|
|
7
|
+
return [];
|
|
5
8
|
const match = toMatchExpression(query.text, query.project);
|
|
6
9
|
if (match === null)
|
|
7
10
|
return [];
|
|
@@ -41,6 +44,8 @@ export async function searchKeyword(db, query) {
|
|
|
41
44
|
return rows.map(toIndexEntry);
|
|
42
45
|
}
|
|
43
46
|
export async function searchVector(db, vector, query) {
|
|
47
|
+
if (noProjects(query.project))
|
|
48
|
+
return [];
|
|
44
49
|
const conditions = ['embedding IS NOT NULL'];
|
|
45
50
|
const params = [];
|
|
46
51
|
appendScope(query, conditions, params, '');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DatabaseSync } from 'node:sqlite';
|
|
2
|
-
import type { Session } from '../../types.js';
|
|
2
|
+
import type { ProjectFilter, Session } from '../../types.js';
|
|
3
3
|
export declare function upsertSession(db: DatabaseSync, session: Session): Promise<void>;
|
|
4
4
|
export declare function clearSummary(db: DatabaseSync, id: string): Promise<boolean>;
|
|
5
5
|
export declare function getSession(db: DatabaseSync, id: string): Promise<Session | null>;
|
|
6
|
-
export declare function recentSessions(db: DatabaseSync, project:
|
|
6
|
+
export declare function recentSessions(db: DatabaseSync, project: ProjectFilter, limit: number): Promise<Session[]>;
|
|
7
7
|
export declare function sessionProjects(db: DatabaseSync): Promise<string[]>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { projectClause } from './filters.js';
|
|
1
2
|
import { toSession } from './rows.js';
|
|
2
3
|
import { summaryTime } from '../session-time.js';
|
|
4
|
+
import { noProjects } from '../project-scope.js';
|
|
3
5
|
export async function upsertSession(db, session) {
|
|
4
6
|
db.prepare(`INSERT INTO sessions (id, project, started_at, ended_at, summary, updated_at, distilled_at)
|
|
5
7
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
@@ -21,11 +23,15 @@ export async function getSession(db, id) {
|
|
|
21
23
|
return row ? toSession(row) : null;
|
|
22
24
|
}
|
|
23
25
|
export async function recentSessions(db, project, limit) {
|
|
26
|
+
if (noProjects(project))
|
|
27
|
+
return [];
|
|
28
|
+
const params = [];
|
|
29
|
+
const scope = projectClause('project', project, params) ?? '1 = 1';
|
|
24
30
|
const rows = db
|
|
25
31
|
.prepare(`SELECT * FROM sessions
|
|
26
|
-
WHERE
|
|
32
|
+
WHERE ${scope} AND summary IS NOT NULL
|
|
27
33
|
ORDER BY started_at DESC LIMIT ?`)
|
|
28
|
-
.all(
|
|
34
|
+
.all(...params, limit);
|
|
29
35
|
return rows.map(toSession);
|
|
30
36
|
}
|
|
31
37
|
export async function sessionProjects(db) {
|
package/dist/types.d.ts
CHANGED
|
@@ -33,9 +33,10 @@ export interface ObservationIndexEntry {
|
|
|
33
33
|
score: number;
|
|
34
34
|
snippet?: string;
|
|
35
35
|
}
|
|
36
|
+
export type ProjectFilter = string | readonly string[];
|
|
36
37
|
export interface SearchQuery {
|
|
37
38
|
text: string;
|
|
38
|
-
project?:
|
|
39
|
+
project?: ProjectFilter;
|
|
39
40
|
kind?: ObservationKind;
|
|
40
41
|
tag?: string;
|
|
41
42
|
since?: number;
|
|
@@ -47,12 +48,12 @@ export interface SearchQuery {
|
|
|
47
48
|
}
|
|
48
49
|
export interface RemoveFilter {
|
|
49
50
|
ids?: string[];
|
|
50
|
-
project?:
|
|
51
|
+
project?: ProjectFilter;
|
|
51
52
|
kind?: ObservationKind;
|
|
52
53
|
before?: number;
|
|
53
54
|
}
|
|
54
55
|
export interface ListFilter {
|
|
55
|
-
project?:
|
|
56
|
+
project?: ProjectFilter;
|
|
56
57
|
sessionId?: string;
|
|
57
58
|
kind?: ObservationKind;
|
|
58
59
|
status?: ObservationStatus;
|
|
@@ -3,7 +3,21 @@ export interface ProcessInfo {
|
|
|
3
3
|
exe: string;
|
|
4
4
|
}
|
|
5
5
|
export type InspectProcess = (pid: number) => ProcessInfo | null;
|
|
6
|
+
export declare function inspectWithPs(pid: number): ProcessInfo | null;
|
|
7
|
+
export declare function inspectProcess(pid: number): ProcessInfo | null;
|
|
6
8
|
export declare function findClaudeAncestor(start?: number, inspect?: InspectProcess): string | null;
|
|
7
9
|
export declare function rememberedBinary(file?: string): string | null;
|
|
8
10
|
export declare function rememberClaudeBinary(env?: NodeJS.ProcessEnv, file?: string, find?: () => string | null): void;
|
|
9
|
-
export
|
|
11
|
+
export type ClaudeSource = 'CLAUDE_CODE_EXECPATH' | 'saved path' | 'parent process' | 'PATH';
|
|
12
|
+
export interface ClaudeLocation {
|
|
13
|
+
path: string;
|
|
14
|
+
source: ClaudeSource;
|
|
15
|
+
}
|
|
16
|
+
export interface ClaudeLookup {
|
|
17
|
+
remembered: () => string | null;
|
|
18
|
+
ancestor: () => string | null;
|
|
19
|
+
onPath: (env: NodeJS.ProcessEnv) => string | null;
|
|
20
|
+
}
|
|
21
|
+
export declare function findOnPath(env?: NodeJS.ProcessEnv): string | null;
|
|
22
|
+
export declare function resolveClaude(env?: NodeJS.ProcessEnv, lookup?: Partial<ClaudeLookup>): ClaudeLocation | null;
|
|
23
|
+
export declare function claudeBinary(env?: NodeJS.ProcessEnv, lookup?: Partial<ClaudeLookup>): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
|
-
import { mkdirSync, readFileSync, readlinkSync, statSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { basename, join } from 'node:path';
|
|
2
|
+
import { accessSync, constants, mkdirSync, readFileSync, readlinkSync, statSync, writeFileSync, } from 'node:fs';
|
|
3
|
+
import { basename, delimiter, isAbsolute, join } from 'node:path';
|
|
4
4
|
import { CONFIG_DIR } from '../config/dir.js';
|
|
5
5
|
const REMEMBERED_FILE = join(CONFIG_DIR, 'claude-binary');
|
|
6
6
|
const MAX_ANCESTORS = 8;
|
|
@@ -15,7 +15,7 @@ function inspectOnLinux(pid) {
|
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
function inspectWithPs(pid) {
|
|
18
|
+
export function inspectWithPs(pid) {
|
|
19
19
|
try {
|
|
20
20
|
const line = execFileSync('ps', ['-o', 'ppid=,comm=', '-p', String(pid)], {
|
|
21
21
|
encoding: 'utf8',
|
|
@@ -29,7 +29,7 @@ function inspectWithPs(pid) {
|
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
function inspectProcess(pid) {
|
|
32
|
+
export function inspectProcess(pid) {
|
|
33
33
|
if (process.platform === 'win32')
|
|
34
34
|
return null;
|
|
35
35
|
return process.platform === 'linux' ? inspectOnLinux(pid) : inspectWithPs(pid);
|
|
@@ -44,7 +44,7 @@ export function findClaudeAncestor(start = process.ppid, inspect = inspectProces
|
|
|
44
44
|
if (!info)
|
|
45
45
|
return null;
|
|
46
46
|
if (isClaude(info.exe))
|
|
47
|
-
return info.exe;
|
|
47
|
+
return isAbsolute(info.exe) ? info.exe : null;
|
|
48
48
|
pid = info.parent;
|
|
49
49
|
}
|
|
50
50
|
return null;
|
|
@@ -69,6 +69,38 @@ export function rememberClaudeBinary(env = process.env, file = REMEMBERED_FILE,
|
|
|
69
69
|
}
|
|
70
70
|
catch { }
|
|
71
71
|
}
|
|
72
|
-
export function
|
|
73
|
-
|
|
72
|
+
export function findOnPath(env = process.env) {
|
|
73
|
+
const names = process.platform === 'win32' ? ['claude.exe', 'claude.cmd'] : ['claude'];
|
|
74
|
+
for (const dir of (env['PATH'] ?? '').split(delimiter)) {
|
|
75
|
+
if (dir === '')
|
|
76
|
+
continue;
|
|
77
|
+
for (const name of names) {
|
|
78
|
+
const candidate = join(dir, name);
|
|
79
|
+
try {
|
|
80
|
+
if (!statSync(candidate).isFile())
|
|
81
|
+
continue;
|
|
82
|
+
accessSync(candidate, constants.X_OK);
|
|
83
|
+
return candidate;
|
|
84
|
+
}
|
|
85
|
+
catch { }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
export function resolveClaude(env = process.env, lookup = {}) {
|
|
91
|
+
const { remembered = rememberedBinary, ancestor = findClaudeAncestor, onPath = findOnPath, } = lookup;
|
|
92
|
+
const fromEnv = env['CLAUDE_CODE_EXECPATH'];
|
|
93
|
+
if (fromEnv)
|
|
94
|
+
return { path: fromEnv, source: 'CLAUDE_CODE_EXECPATH' };
|
|
95
|
+
const saved = remembered();
|
|
96
|
+
if (saved)
|
|
97
|
+
return { path: saved, source: 'saved path' };
|
|
98
|
+
const parent = ancestor();
|
|
99
|
+
if (parent)
|
|
100
|
+
return { path: parent, source: 'parent process' };
|
|
101
|
+
const found = onPath(env);
|
|
102
|
+
return found ? { path: found, source: 'PATH' } : null;
|
|
103
|
+
}
|
|
104
|
+
export function claudeBinary(env = process.env, lookup = {}) {
|
|
105
|
+
return resolveClaude(env, lookup)?.path ?? 'claude';
|
|
74
106
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type RemoteReader = (folder: string, remote: string) => string | null;
|
|
2
|
+
export interface ProjectKeyOptions {
|
|
3
|
+
remote?: string;
|
|
4
|
+
readRemote?: RemoteReader;
|
|
5
|
+
}
|
|
6
|
+
export declare function readRemoteUrl(folder: string, remote: string): string | null;
|
|
7
|
+
export declare function projectKey(folder: string, options?: ProjectKeyOptions): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { DEFAULT_REMOTE, isRemoteName, normalizeRemote } from './remote-key.js';
|
|
3
|
+
const GIT_TIMEOUT_MS = 3000;
|
|
4
|
+
export function readRemoteUrl(folder, remote) {
|
|
5
|
+
try {
|
|
6
|
+
const url = execFileSync('git', ['-C', folder, 'config', '--get', `remote.${remote}.url`], {
|
|
7
|
+
encoding: 'utf8',
|
|
8
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
9
|
+
timeout: GIT_TIMEOUT_MS,
|
|
10
|
+
}).trim();
|
|
11
|
+
return url.length > 0 ? url : null;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export function projectKey(folder, options = {}) {
|
|
18
|
+
const { remote = DEFAULT_REMOTE, readRemote = readRemoteUrl } = options;
|
|
19
|
+
if (!isRemoteName(remote))
|
|
20
|
+
return folder;
|
|
21
|
+
const url = readRemote(folder, remote);
|
|
22
|
+
return (url === null ? null : normalizeRemote(url)) ?? folder;
|
|
23
|
+
}
|