claude-db 0.2.2 → 0.2.3
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/dist/cli/index.js +26 -0
- package/dist/config/schema.d.ts +5 -0
- package/dist/config/schema.js +12 -0
- package/dist/hooks/session-end.js +15 -0
- package/dist/hooks/session-start.js +5 -0
- package/dist/update.d.ts +38 -0
- package/dist/update.js +144 -0
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { createContext } from '../context.js';
|
|
|
7
7
|
import { CONFIG_DIR, CONFIG_PATH, loadConfig, saveConfig } from '../config/index.js';
|
|
8
8
|
import { assertStableLocation, install, instructionsPathFor, mcpPathFor, settingsPathFor, uninstall, } from './install.js';
|
|
9
9
|
import { resolveProject } from '../util/project.js';
|
|
10
|
+
import { checkForUpdate, packageVersion } from '../update.js';
|
|
10
11
|
import { silenceSqliteWarning } from '../util/warnings.js';
|
|
11
12
|
import { toShortId } from '../util/shortid.js';
|
|
12
13
|
silenceSqliteWarning();
|
|
@@ -66,6 +67,9 @@ async function run() {
|
|
|
66
67
|
case 'stats':
|
|
67
68
|
await cmdStats();
|
|
68
69
|
break;
|
|
70
|
+
case 'update':
|
|
71
|
+
await cmdUpdate(args);
|
|
72
|
+
break;
|
|
69
73
|
case 'flush':
|
|
70
74
|
await cmdFlush();
|
|
71
75
|
break;
|
|
@@ -430,6 +434,7 @@ async function cmdDoctor() {
|
|
|
430
434
|
// embedder that cannot actually run is worse than printing nothing.
|
|
431
435
|
const embedder = await ctx.embedder();
|
|
432
436
|
const vectors = await probeEmbedder(embedder);
|
|
437
|
+
console.log(`version : ${packageVersion()}`);
|
|
433
438
|
console.log(`database : ${ctx.config.database}`);
|
|
434
439
|
console.log(`adapter : ${ctx.store.kind}`);
|
|
435
440
|
console.log(`reachable: ${reachable ? 'yes' : 'no'}`);
|
|
@@ -703,6 +708,26 @@ async function cmdStats() {
|
|
|
703
708
|
await ctx.close();
|
|
704
709
|
}
|
|
705
710
|
}
|
|
711
|
+
/**
|
|
712
|
+
* Also the entry point the SessionEnd hook spawns detached, with --quiet.
|
|
713
|
+
*/
|
|
714
|
+
async function cmdUpdate(argv) {
|
|
715
|
+
const quiet = argv.includes('--quiet');
|
|
716
|
+
const config = loadConfig();
|
|
717
|
+
// An explicit `claude-db update` means now, whatever the config says about
|
|
718
|
+
// the background behaviour.
|
|
719
|
+
const mode = quiet ? config.updates : 'auto';
|
|
720
|
+
const result = await checkForUpdate(mode);
|
|
721
|
+
if (quiet)
|
|
722
|
+
return;
|
|
723
|
+
if (result.installed)
|
|
724
|
+
console.log(`Updated ${result.current} -> ${result.latest}.`);
|
|
725
|
+
else if (result.latest && result.latest !== result.current) {
|
|
726
|
+
console.log(`${result.latest} is available (running ${result.current}): ${result.reason}`);
|
|
727
|
+
}
|
|
728
|
+
else
|
|
729
|
+
console.log(`Up to date (${result.current}).`);
|
|
730
|
+
}
|
|
706
731
|
function valueOf(argv, flag) {
|
|
707
732
|
const index = argv.indexOf(flag);
|
|
708
733
|
return index >= 0 ? argv[index + 1] : undefined;
|
|
@@ -724,6 +749,7 @@ function usage() {
|
|
|
724
749
|
flush Re-ingest every transcript for this project
|
|
725
750
|
export [--all] > out.jsonl Dump memory as JSONL, for backup or migration
|
|
726
751
|
import <file.jsonl> Load a dump back in (safe to repeat)
|
|
752
|
+
update Install a newer compatible release now
|
|
727
753
|
reembed Re-embed everything with the current model
|
|
728
754
|
prune --older-than <days> Delete old memory (dry run without --yes)
|
|
729
755
|
reset [--project] --yes Delete stored memory (dry run without --yes)
|
package/dist/config/schema.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export declare const ConfigSchema: z.ZodObject<{
|
|
|
11
11
|
maxScanCandidates: z.ZodDefault<z.ZodNumber>;
|
|
12
12
|
timeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
13
13
|
}, z.core.$strip>>;
|
|
14
|
+
updates: z.ZodDefault<z.ZodEnum<{
|
|
15
|
+
auto: "auto";
|
|
16
|
+
notify: "notify";
|
|
17
|
+
off: "off";
|
|
18
|
+
}>>;
|
|
14
19
|
capture: z.ZodPrefault<z.ZodObject<{
|
|
15
20
|
tools: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
16
21
|
exclude: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
package/dist/config/schema.js
CHANGED
|
@@ -26,6 +26,18 @@ export const ConfigSchema = z.object({
|
|
|
26
26
|
timeoutMs: z.number().int().nonnegative().default(3000),
|
|
27
27
|
})
|
|
28
28
|
.default({ provider: 'auto', maxScanCandidates: 25000, timeoutMs: 3000 }),
|
|
29
|
+
/**
|
|
30
|
+
* `notify` mentions a newer release at session start; `auto` also installs
|
|
31
|
+
* it; `off` never asks.
|
|
32
|
+
*
|
|
33
|
+
* Notify is the default. Installing on someone's behalf means executing code
|
|
34
|
+
* they did not choose, in a process holding their whole memory database, and
|
|
35
|
+
* it turns a single bad publish into silent execution everywhere. The nudge
|
|
36
|
+
* is what actually matters here: this tool fails silently by design — hooks
|
|
37
|
+
* swallow their errors so they can never break a session — so a user left on
|
|
38
|
+
* a broken release sees no error, just memory that never fills up.
|
|
39
|
+
*/
|
|
40
|
+
updates: z.enum(['auto', 'notify', 'off']).default('notify'),
|
|
29
41
|
capture: z
|
|
30
42
|
.object({
|
|
31
43
|
/** Tools whose invocations are worth remembering. */
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { spawn } from 'node:child_process';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
2
5
|
import { clearCursor, flushSession } from '../capture/index.js';
|
|
6
|
+
import { isDue, readState } from '../update.js';
|
|
3
7
|
import { createContext } from '../context.js';
|
|
4
8
|
import { readPayload, runHook } from './payload.js';
|
|
5
9
|
import { resolveProject } from '../util/project.js';
|
|
@@ -29,6 +33,17 @@ await runHook(async () => {
|
|
|
29
33
|
...(result.summary ? { summary: result.summary } : {}),
|
|
30
34
|
});
|
|
31
35
|
clearCursor(sessionId);
|
|
36
|
+
// At session end rather than session start: `npm install -g` replaces the
|
|
37
|
+
// files these hooks import, and this is the moment least likely to have a
|
|
38
|
+
// hook running. Detached and unref'd, so the session never waits on the
|
|
39
|
+
// network or on npm.
|
|
40
|
+
if (ctx.config.updates !== 'off' && isDue(readState())) {
|
|
41
|
+
const cli = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'cli', 'index.js');
|
|
42
|
+
spawn(process.execPath, [cli, 'update', '--quiet'], {
|
|
43
|
+
detached: true,
|
|
44
|
+
stdio: 'ignore',
|
|
45
|
+
}).unref();
|
|
46
|
+
}
|
|
32
47
|
}
|
|
33
48
|
finally {
|
|
34
49
|
await ctx.close();
|
|
@@ -6,6 +6,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
6
6
|
import { createContext } from '../context.js';
|
|
7
7
|
import { emitContext, readPayload, runHook } from './payload.js';
|
|
8
8
|
import { resolveProject } from '../util/project.js';
|
|
9
|
+
import { updateNotice } from '../update.js';
|
|
9
10
|
import { silenceSqliteWarning } from '../util/warnings.js';
|
|
10
11
|
silenceSqliteWarning();
|
|
11
12
|
const SERVER = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'mcp', 'server.js');
|
|
@@ -57,6 +58,10 @@ await runHook(async () => {
|
|
|
57
58
|
lines.push('Search this project\'s full history with the memory MCP tools before ' +
|
|
58
59
|
'asking the user to re-explain prior decisions.');
|
|
59
60
|
}
|
|
61
|
+
// Read from a local file the detached updater wrote; never a live check.
|
|
62
|
+
const notice = ctx.config.updates === 'off' ? null : updateNotice();
|
|
63
|
+
if (notice)
|
|
64
|
+
lines.push(notice);
|
|
60
65
|
emitContext(`${lines.join('\n')}\n`);
|
|
61
66
|
}
|
|
62
67
|
finally {
|
package/dist/update.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface UpdateState {
|
|
2
|
+
/** When the registry was last asked. */
|
|
3
|
+
checkedAt?: number;
|
|
4
|
+
/** Newest version the registry reported. */
|
|
5
|
+
latest?: string;
|
|
6
|
+
/** Version we installed ourselves, so the next session can mention it. */
|
|
7
|
+
installed?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function packageVersion(): string;
|
|
10
|
+
export declare function readState(): UpdateState;
|
|
11
|
+
export declare function isDue(state: UpdateState, now?: number): boolean;
|
|
12
|
+
/** -1, 0 or 1. Numeric per segment, so 0.2.10 beats 0.2.9. */
|
|
13
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
14
|
+
/**
|
|
15
|
+
* Caret semantics: 1.x may take any 1.y.z, but 0.2.x may only take 0.2.z.
|
|
16
|
+
*
|
|
17
|
+
* A release outside this range is allowed to change the database schema or the
|
|
18
|
+
* config, and `init()` migrates on first connection — so installing one without
|
|
19
|
+
* being asked would rewrite a user's database on their behalf. Those are
|
|
20
|
+
* reported and left for a human.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isCompatible(current: string, candidate: string): boolean;
|
|
23
|
+
export interface UpdateResult {
|
|
24
|
+
current: string;
|
|
25
|
+
latest: string | null;
|
|
26
|
+
installed: boolean;
|
|
27
|
+
reason?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Asks the registry, and installs when configured to.
|
|
31
|
+
*
|
|
32
|
+
* Only ever called from a detached process, never inline: the check is network
|
|
33
|
+
* bound and `npm install -g` replaces the very files the hooks import, so
|
|
34
|
+
* neither belongs anywhere near the prompt path.
|
|
35
|
+
*/
|
|
36
|
+
export declare function checkForUpdate(mode: 'auto' | 'notify' | 'off'): Promise<UpdateResult>;
|
|
37
|
+
/** One line for the session banner, or null when there is nothing to say. */
|
|
38
|
+
export declare function updateNotice(): string | null;
|
package/dist/update.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { CONFIG_DIR } from './config/index.js';
|
|
6
|
+
const STATE_PATH = join(CONFIG_DIR, 'update.json');
|
|
7
|
+
const REGISTRY = 'https://registry.npmjs.org/claude-db/latest';
|
|
8
|
+
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
9
|
+
export function packageVersion() {
|
|
10
|
+
try {
|
|
11
|
+
const path = resolve(dirname(fileURLToPath(import.meta.url)), '..', 'package.json');
|
|
12
|
+
return JSON.parse(readFileSync(path, 'utf8')).version ?? '0.0.0';
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return '0.0.0';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function readState() {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(readFileSync(STATE_PATH, 'utf8'));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function writeState(state) {
|
|
27
|
+
try {
|
|
28
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
29
|
+
writeFileSync(STATE_PATH, `${JSON.stringify(state, null, 2)}\n`, 'utf8');
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// A lost state file only costs one redundant check.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function isDue(state, now = Date.now()) {
|
|
36
|
+
return now - (state.checkedAt ?? 0) > CHECK_INTERVAL_MS;
|
|
37
|
+
}
|
|
38
|
+
/** -1, 0 or 1. Numeric per segment, so 0.2.10 beats 0.2.9. */
|
|
39
|
+
export function compareVersions(a, b) {
|
|
40
|
+
const left = a.split('.').map((part) => Number.parseInt(part, 10) || 0);
|
|
41
|
+
const right = b.split('.').map((part) => Number.parseInt(part, 10) || 0);
|
|
42
|
+
for (let i = 0; i < 3; i += 1) {
|
|
43
|
+
const diff = (left[i] ?? 0) - (right[i] ?? 0);
|
|
44
|
+
if (diff !== 0)
|
|
45
|
+
return diff > 0 ? 1 : -1;
|
|
46
|
+
}
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Caret semantics: 1.x may take any 1.y.z, but 0.2.x may only take 0.2.z.
|
|
51
|
+
*
|
|
52
|
+
* A release outside this range is allowed to change the database schema or the
|
|
53
|
+
* config, and `init()` migrates on first connection — so installing one without
|
|
54
|
+
* being asked would rewrite a user's database on their behalf. Those are
|
|
55
|
+
* reported and left for a human.
|
|
56
|
+
*/
|
|
57
|
+
export function isCompatible(current, candidate) {
|
|
58
|
+
const [curMajor = 0, curMinor = 0] = current.split('.').map(Number);
|
|
59
|
+
const [newMajor = 0, newMinor = 0] = candidate.split('.').map(Number);
|
|
60
|
+
return curMajor === 0 ? curMajor === newMajor && curMinor === newMinor : curMajor === newMajor;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* No abbreviated-packument accept header here: that format applies to the full
|
|
64
|
+
* document, and asking for it on /latest returns 406. With the header this
|
|
65
|
+
* check never once succeeded, and reported "up to date" while failing.
|
|
66
|
+
*/
|
|
67
|
+
async function fetchLatest() {
|
|
68
|
+
try {
|
|
69
|
+
const res = await fetch(REGISTRY, { signal: AbortSignal.timeout(5000) });
|
|
70
|
+
if (!res.ok)
|
|
71
|
+
return null;
|
|
72
|
+
const body = (await res.json());
|
|
73
|
+
return typeof body.version === 'string' ? body.version : null;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Asks the registry, and installs when configured to.
|
|
81
|
+
*
|
|
82
|
+
* Only ever called from a detached process, never inline: the check is network
|
|
83
|
+
* bound and `npm install -g` replaces the very files the hooks import, so
|
|
84
|
+
* neither belongs anywhere near the prompt path.
|
|
85
|
+
*/
|
|
86
|
+
export async function checkForUpdate(mode) {
|
|
87
|
+
const current = packageVersion();
|
|
88
|
+
if (mode === 'off')
|
|
89
|
+
return { current, latest: null, installed: false, reason: 'disabled' };
|
|
90
|
+
const latest = await fetchLatest();
|
|
91
|
+
const state = { ...readState(), checkedAt: Date.now() };
|
|
92
|
+
if (latest)
|
|
93
|
+
state.latest = latest;
|
|
94
|
+
// A failed check is not the same as being current, and saying so is what
|
|
95
|
+
// stops a broken updater from looking like a healthy one forever.
|
|
96
|
+
if (!latest) {
|
|
97
|
+
writeState(state);
|
|
98
|
+
return { current, latest: null, installed: false, reason: 'could not reach the registry' };
|
|
99
|
+
}
|
|
100
|
+
if (compareVersions(latest, current) <= 0) {
|
|
101
|
+
writeState(state);
|
|
102
|
+
return { current, latest, installed: false, reason: 'up to date' };
|
|
103
|
+
}
|
|
104
|
+
if (mode === 'notify') {
|
|
105
|
+
writeState(state);
|
|
106
|
+
return { current, latest, installed: false, reason: 'notify only' };
|
|
107
|
+
}
|
|
108
|
+
if (!isCompatible(current, latest)) {
|
|
109
|
+
writeState(state);
|
|
110
|
+
return { current, latest, installed: false, reason: 'not a compatible release' };
|
|
111
|
+
}
|
|
112
|
+
try {
|
|
113
|
+
execFileSync('npm', ['install', '-g', `claude-db@${latest}`], {
|
|
114
|
+
stdio: 'ignore',
|
|
115
|
+
timeout: 120_000,
|
|
116
|
+
});
|
|
117
|
+
writeState({ ...state, installed: latest });
|
|
118
|
+
return { current, latest, installed: true };
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
writeState(state);
|
|
122
|
+
return {
|
|
123
|
+
current,
|
|
124
|
+
latest,
|
|
125
|
+
installed: false,
|
|
126
|
+
reason: error instanceof Error ? error.message.split('\n')[0] ?? 'install failed' : 'install failed',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** One line for the session banner, or null when there is nothing to say. */
|
|
131
|
+
export function updateNotice() {
|
|
132
|
+
const state = readState();
|
|
133
|
+
const current = packageVersion();
|
|
134
|
+
if (state.installed && compareVersions(state.installed, current) <= 0) {
|
|
135
|
+
// We are running it now, so say so once and forget it.
|
|
136
|
+
const { installed: _done, ...rest } = state;
|
|
137
|
+
writeState(rest);
|
|
138
|
+
return `claude-db updated to ${current}.`;
|
|
139
|
+
}
|
|
140
|
+
if (state.latest && compareVersions(state.latest, current) > 0) {
|
|
141
|
+
return `claude-db ${state.latest} is available (running ${current}): npm i -g claude-db`;
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-db",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
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",
|