claude-db 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -2
- package/dist/capture/flush.d.ts +22 -0
- package/dist/capture/flush.js +45 -10
- package/dist/capture/identity.d.ts +6 -0
- package/dist/capture/identity.js +14 -0
- package/dist/capture/index.d.ts +5 -3
- package/dist/capture/index.js +4 -3
- package/dist/capture/manual.d.ts +21 -0
- package/dist/capture/manual.js +40 -0
- package/dist/capture/transcript.d.ts +12 -0
- package/dist/capture/transcript.js +69 -1
- package/dist/capture/turn-extractor.js +40 -8
- package/dist/cli/index.js +376 -30
- package/dist/cli/install.d.ts +15 -1
- package/dist/cli/install.js +127 -8
- package/dist/config/schema.d.ts +1 -0
- package/dist/config/schema.js +9 -1
- package/dist/context.js +24 -2
- package/dist/embed/builtin.js +3 -1
- package/dist/hooks/relevance.js +11 -4
- package/dist/hooks/session-end.js +2 -1
- package/dist/hooks/session-start.js +22 -3
- package/dist/mcp/server.js +56 -6
- package/dist/search/service.js +4 -1
- package/dist/store/adapter.d.ts +22 -6
- package/dist/store/adapter.js +10 -1
- package/dist/store/mongo/driver.d.ts +1 -0
- package/dist/store/mongo/index.d.ts +3 -2
- package/dist/store/mongo/index.js +57 -7
- package/dist/store/postgres/index.d.ts +22 -8
- package/dist/store/postgres/index.js +165 -21
- package/dist/store/sqlite/index.d.ts +3 -2
- package/dist/store/sqlite/index.js +112 -9
- package/dist/store/sqlite/schema.sql +4 -3
- package/dist/types.d.ts +28 -0
- package/dist/util/project.d.ts +9 -10
- package/dist/util/project.js +52 -13
- package/dist/util/vector.d.ts +11 -1
- package/dist/util/vector.js +14 -3
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
PRAGMA journal_mode = WAL;
|
|
2
2
|
PRAGMA synchronous = NORMAL;
|
|
3
|
+
PRAGMA recursive_triggers = ON;
|
|
3
4
|
|
|
4
5
|
CREATE TABLE IF NOT EXISTS sessions (
|
|
5
6
|
id TEXT PRIMARY KEY,
|
|
@@ -16,8 +17,6 @@ CREATE TABLE IF NOT EXISTS observations (
|
|
|
16
17
|
id TEXT PRIMARY KEY,
|
|
17
18
|
session_id TEXT NOT NULL,
|
|
18
19
|
project TEXT NOT NULL,
|
|
19
|
-
-- Single opaque token identifying the project, indexed inside FTS so that
|
|
20
|
-
-- scoping happens during the match rather than as a post-filter join.
|
|
21
20
|
scope TEXT NOT NULL DEFAULT '',
|
|
22
21
|
kind TEXT NOT NULL,
|
|
23
22
|
title TEXT NOT NULL,
|
|
@@ -25,7 +24,9 @@ CREATE TABLE IF NOT EXISTS observations (
|
|
|
25
24
|
files TEXT NOT NULL DEFAULT '[]',
|
|
26
25
|
tags TEXT NOT NULL DEFAULT '[]',
|
|
27
26
|
created_at INTEGER NOT NULL,
|
|
28
|
-
embedding BLOB
|
|
27
|
+
embedding BLOB,
|
|
28
|
+
embedder TEXT,
|
|
29
|
+
author TEXT
|
|
29
30
|
);
|
|
30
31
|
|
|
31
32
|
CREATE INDEX IF NOT EXISTS idx_obs_project_time
|
package/dist/types.d.ts
CHANGED
|
@@ -27,6 +27,10 @@ export interface Observation {
|
|
|
27
27
|
createdAt: number;
|
|
28
28
|
/** Present only when an embedder is configured. */
|
|
29
29
|
embedding?: number[];
|
|
30
|
+
/** Which embedder produced `embedding`. Absent on rows written before 0.2. */
|
|
31
|
+
embedder?: string;
|
|
32
|
+
/** Whose machine recorded this. Only interesting on a shared database. */
|
|
33
|
+
author?: string;
|
|
30
34
|
}
|
|
31
35
|
/** Compact projection returned by search. Deliberately excludes `body`. */
|
|
32
36
|
export interface ObservationIndexEntry {
|
|
@@ -46,6 +50,30 @@ export interface SearchQuery {
|
|
|
46
50
|
limit: number;
|
|
47
51
|
/** Ceiling for brute-force vector scans. Ignored by indexed backends. */
|
|
48
52
|
maxScanCandidates?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Restricts vector search to rows embedded by this model, plus rows that
|
|
55
|
+
* predate the column. Vectors from different models are not comparable.
|
|
56
|
+
*/
|
|
57
|
+
embedder?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* What to delete. Every field narrows, and an empty filter means everything,
|
|
61
|
+
* which is what `reset` asks for. An explicitly empty `ids` array deletes
|
|
62
|
+
* nothing: `forget` with no resolvable id must not wipe the database.
|
|
63
|
+
*/
|
|
64
|
+
export interface RemoveFilter {
|
|
65
|
+
ids?: string[];
|
|
66
|
+
project?: string;
|
|
67
|
+
kind?: ObservationKind;
|
|
68
|
+
/** Deletes observations recorded strictly before this timestamp. */
|
|
69
|
+
before?: number;
|
|
70
|
+
}
|
|
71
|
+
/** Bulk read, ordered oldest first so `after` can page through a large table. */
|
|
72
|
+
export interface ListFilter {
|
|
73
|
+
project?: string;
|
|
74
|
+
kind?: ObservationKind;
|
|
75
|
+
after?: number;
|
|
76
|
+
limit?: number;
|
|
49
77
|
}
|
|
50
78
|
export interface TimelineQuery {
|
|
51
79
|
/** Anchor observation. Results are the ones surrounding it in time. */
|
package/dist/util/project.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Canonicalises a project path so scoping survives symlinks
|
|
2
|
+
* Canonicalises a project path so scoping survives symlinks, then widens it to
|
|
3
|
+
* the repository root so every directory inside a repo keys the same memory.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* absolute path when the directory does not exist yet, which keeps callers
|
|
12
|
-
* working against paths that have not been created.
|
|
5
|
+
* Scoping is an exact string comparison, so two spellings of the same place
|
|
6
|
+
* silently split a project's memory in half. macOS makes symlinks the default
|
|
7
|
+
* case rather than an edge case: `/tmp` links to `/private/tmp`, so a hook
|
|
8
|
+
* reading `cwd` and a CLI reading `process.cwd()` disagree about one folder.
|
|
9
|
+
* Subdirectories are the same failure by a different route: running the agent
|
|
10
|
+
* from `repo/frontend` used to start a second, empty memory, indistinguishable
|
|
11
|
+
* from never having worked in the repo at all.
|
|
13
12
|
*/
|
|
14
13
|
export declare function resolveProject(path: string | undefined): string;
|
package/dist/util/project.js
CHANGED
|
@@ -1,24 +1,63 @@
|
|
|
1
|
-
import { realpathSync } from 'node:fs';
|
|
2
|
-
import {
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { dirname, join, resolve, sep } from 'node:path';
|
|
3
4
|
/**
|
|
4
|
-
* Canonicalises a project path so scoping survives symlinks
|
|
5
|
+
* Canonicalises a project path so scoping survives symlinks, then widens it to
|
|
6
|
+
* the repository root so every directory inside a repo keys the same memory.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* absolute path when the directory does not exist yet, which keeps callers
|
|
14
|
-
* working against paths that have not been created.
|
|
8
|
+
* Scoping is an exact string comparison, so two spellings of the same place
|
|
9
|
+
* silently split a project's memory in half. macOS makes symlinks the default
|
|
10
|
+
* case rather than an edge case: `/tmp` links to `/private/tmp`, so a hook
|
|
11
|
+
* reading `cwd` and a CLI reading `process.cwd()` disagree about one folder.
|
|
12
|
+
* Subdirectories are the same failure by a different route: running the agent
|
|
13
|
+
* from `repo/frontend` used to start a second, empty memory, indistinguishable
|
|
14
|
+
* from never having worked in the repo at all.
|
|
15
15
|
*/
|
|
16
16
|
export function resolveProject(path) {
|
|
17
17
|
const absolute = resolve(path ?? process.cwd());
|
|
18
|
+
let canonical;
|
|
18
19
|
try {
|
|
19
|
-
|
|
20
|
+
canonical = realpathSync(absolute);
|
|
20
21
|
}
|
|
21
22
|
catch {
|
|
22
23
|
return absolute;
|
|
23
24
|
}
|
|
25
|
+
return repoRoot(canonical) ?? canonical;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Nearest ancestor containing a `.git` entry, or null outside a work tree.
|
|
29
|
+
*
|
|
30
|
+
* Never returns the home directory or anything above it. People keep dotfiles
|
|
31
|
+
* repositories in `$HOME`, and without that guard every unrelated project on
|
|
32
|
+
* the machine would walk up, find `~/.git`, and collapse into a single shared
|
|
33
|
+
* memory. A directory that merely holds several repositories is not a repo
|
|
34
|
+
* itself, so it keeps its own key and its contents stay pooled.
|
|
35
|
+
*
|
|
36
|
+
* `.git` is a file rather than a directory in worktrees and submodules, so
|
|
37
|
+
* this tests for existence, not for a directory.
|
|
38
|
+
*/
|
|
39
|
+
function repoRoot(start) {
|
|
40
|
+
const home = canonicalHome();
|
|
41
|
+
for (let dir = start;;) {
|
|
42
|
+
if (dir === sep || dir === home || home.startsWith(dir + sep))
|
|
43
|
+
return null;
|
|
44
|
+
if (existsSync(join(dir, '.git')))
|
|
45
|
+
return dir;
|
|
46
|
+
const parent = dirname(dir);
|
|
47
|
+
if (parent === dir)
|
|
48
|
+
return null;
|
|
49
|
+
dir = parent;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
let cachedHome = null;
|
|
53
|
+
function canonicalHome() {
|
|
54
|
+
if (cachedHome === null) {
|
|
55
|
+
try {
|
|
56
|
+
cachedHome = realpathSync(homedir());
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
cachedHome = homedir();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return cachedHome;
|
|
24
63
|
}
|
package/dist/util/vector.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
/** Serialize an embedding for BLOB columns / BSON binary. */
|
|
2
2
|
export declare function packVector(values: number[]): Buffer;
|
|
3
3
|
export declare function unpackVector(buffer: Buffer): number[];
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Assumes both inputs are L2-normalized, which the embedder guarantees.
|
|
6
|
+
*
|
|
7
|
+
* Different widths are different embedding spaces, and a database accumulates
|
|
8
|
+
* both the moment `provider: auto` upgrades from the 256d builtin to 384d
|
|
9
|
+
* MiniLM. Scoring zero drops those below the relevance floor instead of
|
|
10
|
+
* comparing a prefix and returning a meaningless number.
|
|
11
|
+
*
|
|
12
|
+
* ponytail: width stands in for model identity; store an embedder id per row
|
|
13
|
+
* if two same-size models ever coexist.
|
|
14
|
+
*/
|
|
5
15
|
export declare function cosine(a: number[], b: number[]): number;
|
package/dist/util/vector.js
CHANGED
|
@@ -7,11 +7,22 @@ export function unpackVector(buffer) {
|
|
|
7
7
|
const copy = Buffer.from(buffer);
|
|
8
8
|
return Array.from(new Float32Array(copy.buffer, copy.byteOffset, copy.byteLength / 4));
|
|
9
9
|
}
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Assumes both inputs are L2-normalized, which the embedder guarantees.
|
|
12
|
+
*
|
|
13
|
+
* Different widths are different embedding spaces, and a database accumulates
|
|
14
|
+
* both the moment `provider: auto` upgrades from the 256d builtin to 384d
|
|
15
|
+
* MiniLM. Scoring zero drops those below the relevance floor instead of
|
|
16
|
+
* comparing a prefix and returning a meaningless number.
|
|
17
|
+
*
|
|
18
|
+
* ponytail: width stands in for model identity; store an embedder id per row
|
|
19
|
+
* if two same-size models ever coexist.
|
|
20
|
+
*/
|
|
11
21
|
export function cosine(a, b) {
|
|
12
|
-
|
|
22
|
+
if (a.length !== b.length)
|
|
23
|
+
return 0;
|
|
13
24
|
let dot = 0;
|
|
14
|
-
for (let i = 0; i <
|
|
25
|
+
for (let i = 0; i < a.length; i += 1)
|
|
15
26
|
dot += (a[i] ?? 0) * (b[i] ?? 0);
|
|
16
27
|
return dot;
|
|
17
28
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-db",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Persistent memory for Claude Code
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Persistent memory for Claude Code. Captures why decisions were made, not just which files changed. Bring your own database: SQLite, MongoDB or Postgres. No cloud, no subscription.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|