claude-db 0.8.0 → 0.8.2

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 CHANGED
@@ -1,5 +1,58 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.2
4
+
5
+ ### Fixed
6
+
7
+ - **Hooks failed on Windows with MODULE_NOT_FOUND.** Hook commands were written
8
+ with backslash paths, but Claude Code runs them through bash whenever Git Bash
9
+ is present, and there a backslash is an escape character: an unquoted
10
+ `C:\Users\...\hooks\session-end.js` collapses to
11
+ `C:UsersAppData...hookssession-end.js`, which Node then resolves against the
12
+ project directory. Every hook failed. Paths are now written with forward
13
+ slashes, which Node accepts on Windows and bash leaves alone. The MCP server
14
+ was never affected, because its path is passed as an argument rather than
15
+ inside a command string. Reported and fixed by @bspangler21 (#10, #12).
16
+
17
+ - **`status` claimed claude-db was not installed on Windows**, and session start
18
+ never found the MCP server there. Both compared a path built with the
19
+ platform separator against a file that stores it differently — with forward
20
+ slashes now, and JSON-escaped backslashes before that — so the comparison
21
+ could not match. Path comparisons are now separator-insensitive.
22
+
23
+ - **The temporary-install guard did not work on Windows.** It split the install
24
+ path on forward slashes to look for `_npx`, so on a backslash path it found
25
+ nothing and let an install proceed from a directory that npx would delete.
26
+
27
+ ## 0.8.1
28
+
29
+ ### Fixed
30
+
31
+ - **A wrong session summary could not be corrected, and kept teaching itself.**
32
+ Summaries are injected at every session start, but nothing could delete one:
33
+ the upsert coalesces a null summary to the existing value, so a summary was
34
+ write-once in practice. One carrying a false claim was therefore re-injected
35
+ into every new session, restated as fact, and captured back as fresh
36
+ observations that outranked the correction — memory records what was said,
37
+ not what is true, so a wrong statement gains credibility by being repeated.
38
+ `claude-db forget --session <id>` now clears one, on all three backends,
39
+ after which it stops being served. Clearing reports whether anything actually
40
+ changed, so the adapters agree rather than SQLite and Postgres counting a
41
+ matched row where MongoDB counted a change.
42
+
43
+ - **Scripted sessions are no longer captured by default.** A headless run —
44
+ a test harness, a cron job, anything driving `claude -p` — writes memory that
45
+ looks like your work but is not, and a fabricated test fixture becoming
46
+ project knowledge is exactly how the summary above was poisoned. Claude Code
47
+ identifies those sessions as `sdk-cli`, and they are now skipped.
48
+ `capture.scripted: true` captures them anyway, for anyone whose real work
49
+ runs through the SDK.
50
+
51
+ Detection has one blind spot worth stating: a `claude -p` spawned from inside
52
+ another Claude session inherits the parent's entrypoint and is
53
+ indistinguishable from it. `CLAUDE_DB_CAPTURE=off` covers that case and any
54
+ other session that should stay unrecorded, while leaving recall working.
55
+
3
56
  ## 0.8.0
4
57
 
5
58
  ### Added
@@ -57,9 +57,14 @@ export async function cmdRemember(argv) {
57
57
  }
58
58
  }
59
59
  export async function cmdForget(argv) {
60
- const ids = argv.filter((arg) => typeof arg === 'string' && arg.length > 0);
60
+ const args = argv.filter((arg) => typeof arg === 'string' && arg.length > 0);
61
+ const sessionAt = args.indexOf('--session');
62
+ const ids = sessionAt >= 0 ? [] : args;
63
+ if (sessionAt >= 0)
64
+ return forgetSummary(args[sessionAt + 1]);
61
65
  if (ids.length === 0) {
62
66
  console.error('Usage: claude-db forget <id> [id...]');
67
+ console.error(' claude-db forget --session <session-id>');
63
68
  process.exit(1);
64
69
  }
65
70
  const ctx = await createContext();
@@ -75,3 +80,19 @@ export async function cmdForget(argv) {
75
80
  await ctx.close();
76
81
  }
77
82
  }
83
+ async function forgetSummary(sessionId) {
84
+ if (!sessionId) {
85
+ console.error('Usage: claude-db forget --session <session-id>');
86
+ process.exit(1);
87
+ }
88
+ const ctx = await createContext();
89
+ try {
90
+ const cleared = await ctx.store.clearSummary(sessionId);
91
+ console.log(cleared
92
+ ? `Cleared the summary for session ${sessionId}. It will no longer be injected.`
93
+ : `No session ${sessionId}, or it had no summary.`);
94
+ }
95
+ finally {
96
+ await ctx.close();
97
+ }
98
+ }
@@ -8,6 +8,7 @@ import { createContext } from '../../context.js';
8
8
  import { join, resolve } from 'node:path';
9
9
  import { readFileSync, statSync } from 'node:fs';
10
10
  import { resolveProject } from '../../util/project.js';
11
+ import { mentionsPath } from '../../util/paths.js';
11
12
  import { transcriptsFor } from '../../capture/index.js';
12
13
  export async function cmdInstall(scope) {
13
14
  const project = resolveProject(undefined);
@@ -158,7 +159,7 @@ function isInstalled(settingsPath) {
158
159
  }
159
160
  function fileMentions(path, needle) {
160
161
  try {
161
- return readFileSync(path, 'utf8').includes(needle);
162
+ return mentionsPath(readFileSync(path, 'utf8'), needle);
162
163
  }
163
164
  catch {
164
165
  return false;
@@ -4,6 +4,7 @@ import { execFileSync } from 'node:child_process';
4
4
  import { readJson, readText, writeAtomic, writeJson } from './files.js';
5
5
  import { removeInstructions, writeInstructions } from './instructions.js';
6
6
  import { rmSync } from 'node:fs';
7
+ import { toPosix } from '../util/paths.js';
7
8
  function writeSkill(distDir, scope, project) {
8
9
  const source = resolve(distDir, '..', 'skills', 'cdb-scan', 'SKILL.md');
9
10
  const body = readText(source);
@@ -22,7 +23,7 @@ const HOOKS = [
22
23
  ];
23
24
  export function assertStableLocation(distDir) {
24
25
  const ephemeral = ['_npx', '_cacache'];
25
- const segments = distDir.split('/');
26
+ const segments = toPosix(distDir).split('/');
26
27
  if (!ephemeral.some((name) => segments.includes(name)))
27
28
  return;
28
29
  throw new Error(`Refusing to install from a temporary location:\n ${distDir}\n\n` +
@@ -125,9 +126,9 @@ export function uninstall(distDir, scope, project) {
125
126
  return path;
126
127
  }
127
128
  function hookCommand(distDir, file) {
128
- return `node ${resolve(distDir, 'hooks', file)}`;
129
+ return `node ${toPosix(resolve(distDir, 'hooks', file))}`;
129
130
  }
130
131
  function isOurHook(command) {
131
- const path = command.replace(/\\/g, '/');
132
+ const path = toPosix(command);
132
133
  return HOOKS.some(([, file]) => path.endsWith(`/hooks/${file}`));
133
134
  }
package/dist/cli/usage.js CHANGED
@@ -12,6 +12,7 @@ export function usage() {
12
12
  remember [--kind k] <text> Record something outright, e.g. a house rule
13
13
  [--key <name>] ...under a stable name, replacing any earlier one
14
14
  forget <id> [id...] Delete specific observations by id
15
+ --session <id> ...or clear one session's summary, so it stops being injected
15
16
  projects List every project with memory in this database
16
17
  merge [<old-path>] [--yes] Move memory from an old project path onto this one
17
18
  stats What this project's memory is made of
@@ -21,6 +21,7 @@ export declare const ConfigSchema: z.ZodObject<{
21
21
  tools: z.ZodDefault<z.ZodArray<z.ZodString>>;
22
22
  exclude: z.ZodDefault<z.ZodArray<z.ZodString>>;
23
23
  maxBodyChars: z.ZodDefault<z.ZodNumber>;
24
+ scripted: z.ZodDefault<z.ZodBoolean>;
24
25
  summarize: z.ZodDefault<z.ZodEnum<{
25
26
  off: "off";
26
27
  on: "on";
@@ -15,6 +15,7 @@ export const ConfigSchema = z.object({
15
15
  tools: z.array(z.string()).default(['Edit', 'Write', 'Bash', 'NotebookEdit']),
16
16
  exclude: z.array(z.string()).default(['.env', 'secrets', 'node_modules', '.git/']),
17
17
  maxBodyChars: z.number().int().positive().default(4000),
18
+ scripted: z.boolean().default(false),
18
19
  summarize: z.enum(['off', 'on']).default('off'),
19
20
  summarizeModel: z.enum(['opus', 'sonnet', 'haiku']).default('opus'),
20
21
  })
@@ -8,6 +8,7 @@ export interface HookPayload {
8
8
  tool_response?: unknown;
9
9
  prompt?: string;
10
10
  }
11
+ export declare function capturingDisabled(scripted: boolean): boolean;
11
12
  export declare function readPayload(): Promise<HookPayload>;
12
13
  export declare function runHook(fn: () => Promise<void>): Promise<void>;
13
14
  export declare function emitContext(text: string): void;
@@ -1,3 +1,8 @@
1
+ export function capturingDisabled(scripted) {
2
+ if (process.env['CLAUDE_DB_CAPTURE'] === 'off')
3
+ return true;
4
+ return process.env['CLAUDE_CODE_ENTRYPOINT'] === 'sdk-cli' && !scripted;
5
+ }
1
6
  export async function readPayload() {
2
7
  const chunks = [];
3
8
  for await (const chunk of process.stdin)
@@ -5,11 +5,14 @@ import { fileURLToPath } from 'node:url';
5
5
  import { aiSummary, clearCursor, flushSession, observationsFromTurns, readTranscript, transcriptPathFor, } from '../capture/index.js';
6
6
  import { isDue, readState } from '../update.js';
7
7
  import { createContext } from '../context.js';
8
- import { readPayload, runHook } from './payload.js';
8
+ import { capturingDisabled, readPayload, runHook } from './payload.js';
9
+ import { loadConfig } from '../config/index.js';
9
10
  import { resolveProject } from '../util/project.js';
10
11
  import { silenceSqliteWarning } from '../util/warnings.js';
11
12
  silenceSqliteWarning();
12
13
  await runHook(async () => {
14
+ if (capturingDisabled(loadConfig().capture.scripted))
15
+ return;
13
16
  const payload = await readPayload();
14
17
  const sessionId = payload.session_id;
15
18
  if (!sessionId)
@@ -7,6 +7,7 @@ import { createContext } from '../context.js';
7
7
  import { openWork } from '../capture/index.js';
8
8
  import { emitContext, readPayload, runHook } from './payload.js';
9
9
  import { resolveProject } from '../util/project.js';
10
+ import { mentionsPath } from '../util/paths.js';
10
11
  import { toShortId } from '../util/shortid.js';
11
12
  import { refreshInstalled } from '../cli/refresh.js';
12
13
  import { updateNotice } from '../update.js';
@@ -36,7 +37,7 @@ function refreshInstalledQuietly(project) {
36
37
  function mcpRegistered(project) {
37
38
  return [join(project, '.mcp.json'), join(homedir(), '.claude.json')].some((path) => {
38
39
  try {
39
- return readFileSync(path, 'utf8').includes(SERVER);
40
+ return mentionsPath(readFileSync(path, 'utf8'), SERVER);
40
41
  }
41
42
  catch {
42
43
  return false;
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { flushSession } from '../capture/index.js';
3
3
  import { createContext } from '../context.js';
4
- import { emitContext, readPayload, runHook } from './payload.js';
4
+ import { capturingDisabled, emitContext, readPayload, runHook } from './payload.js';
5
+ import { loadConfig } from '../config/index.js';
5
6
  import { markShown, readShown } from './shown.js';
6
7
  import { overlapCount, renderPromptContext } from './relevance.js';
7
8
  import { isSearchable } from '../util/prompt.js';
@@ -9,6 +10,8 @@ import { resolveProject } from '../util/project.js';
9
10
  import { silenceSqliteWarning } from '../util/warnings.js';
10
11
  silenceSqliteWarning();
11
12
  await runHook(async () => {
13
+ if (capturingDisabled(loadConfig().capture.scripted))
14
+ return;
12
15
  const payload = await readPayload();
13
16
  const sessionId = payload.session_id;
14
17
  if (!sessionId)
@@ -12,6 +12,7 @@ export interface MemoryStore {
12
12
  upsertSession(session: Session): Promise<void>;
13
13
  getSession(id: string): Promise<Session | null>;
14
14
  recentSessions(project: string, limit: number): Promise<Session[]>;
15
+ clearSummary(id: string): Promise<boolean>;
15
16
  insertObservations(observations: Observation[]): Promise<void>;
16
17
  getObservations(ids: string[]): Promise<Observation[]>;
17
18
  remove(filter: RemoveFilter): Promise<number>;
@@ -18,6 +18,7 @@ export declare class MongoStore implements MemoryStore {
18
18
  upsertSession(session: Session): Promise<void>;
19
19
  getSession(id: string): Promise<Session | null>;
20
20
  recentSessions(project: string, limit: number): Promise<Session[]>;
21
+ clearSummary(id: string): Promise<boolean>;
21
22
  insertObservations(observations: Observation[]): Promise<void>;
22
23
  getObservations(ids: string[]): Promise<Observation[]>;
23
24
  remove(filter: RemoveFilter): Promise<number>;
@@ -60,6 +60,9 @@ export class MongoStore {
60
60
  async recentSessions(project, limit) {
61
61
  return sessionsOps.recentSessions(this.sessions, project, limit);
62
62
  }
63
+ async clearSummary(id) {
64
+ return sessionsOps.clearSummary(this.sessions, id);
65
+ }
63
66
  async insertObservations(observations) {
64
67
  return observationsOps.insertObservations(this.observations, this.sessions, this.symbols, this.edges, this.scanned, observations);
65
68
  }
@@ -3,4 +3,5 @@ import type { 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
+ export declare function clearSummary(sessions: Collection<SessionDoc>, id: string): Promise<boolean>;
6
7
  export declare function recentSessions(sessions: Collection<SessionDoc>, project: string, limit: number): Promise<Session[]>;
@@ -14,6 +14,10 @@ export async function getSession(sessions, id) {
14
14
  const doc = await sessions.findOne({ _id: id });
15
15
  return doc ? toSession(doc) : null;
16
16
  }
17
+ export async function clearSummary(sessions, id) {
18
+ const result = (await sessions.updateOne({ _id: id }, { $unset: { summary: '' } }));
19
+ return (result.modifiedCount ?? 0) > 0;
20
+ }
17
21
  export async function recentSessions(sessions, project, limit) {
18
22
  const docs = await sessions
19
23
  .find({ project, summary: { $type: 'string' } })
@@ -23,6 +23,7 @@ export declare class PostgresStore implements MemoryStore {
23
23
  upsertSession(session: Session): Promise<void>;
24
24
  getSession(id: string): Promise<Session | null>;
25
25
  recentSessions(project: string, limit: number): Promise<Session[]>;
26
+ clearSummary(id: string): Promise<boolean>;
26
27
  insertObservations(observations: Observation[]): Promise<void>;
27
28
  getObservations(ids: string[]): Promise<Observation[]>;
28
29
  remove(filter: RemoveFilter): Promise<number>;
@@ -82,6 +82,9 @@ export class PostgresStore {
82
82
  async recentSessions(project, limit) {
83
83
  return sessionsOps.recentSessions(this.pool, project, limit);
84
84
  }
85
+ async clearSummary(id) {
86
+ return sessionsOps.clearSummary(this.pool, id);
87
+ }
85
88
  async insertObservations(observations) {
86
89
  return insertOps.insertObservations(this.pool, (dims) => this.ensureVectorColumn(dims), observations);
87
90
  }
@@ -2,4 +2,5 @@ import type { Pool } from './driver.js';
2
2
  import type { 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
+ export declare function clearSummary(pool: Pool, id: string): Promise<boolean>;
5
6
  export declare function recentSessions(pool: Pool, project: string, limit: number): Promise<Session[]>;
@@ -18,6 +18,10 @@ export async function getSession(pool, id) {
18
18
  const row = res.rows[0];
19
19
  return row ? toSession(row) : null;
20
20
  }
21
+ export async function clearSummary(pool, id) {
22
+ const result = await pool.query('UPDATE sessions SET summary = NULL WHERE id = $1 AND summary IS NOT NULL', [id]);
23
+ return (result.rowCount ?? 0) > 0;
24
+ }
21
25
  export async function recentSessions(pool, project, limit) {
22
26
  const res = await pool.query(`SELECT * FROM sessions
23
27
  WHERE project = $1 AND summary IS NOT NULL
@@ -12,6 +12,7 @@ export declare class SqliteStore implements MemoryStore {
12
12
  upsertSession(session: Session): Promise<void>;
13
13
  getSession(id: string): Promise<Session | null>;
14
14
  recentSessions(project: string, limit: number): Promise<Session[]>;
15
+ clearSummary(id: string): Promise<boolean>;
15
16
  insertObservations(observations: Observation[]): Promise<void>;
16
17
  getObservations(ids: string[]): Promise<Observation[]>;
17
18
  remove(filter: RemoveFilter): Promise<number>;
@@ -56,6 +56,9 @@ export class SqliteStore {
56
56
  async recentSessions(project, limit) {
57
57
  return sessionsOps.recentSessions(this.db, project, limit);
58
58
  }
59
+ async clearSummary(id) {
60
+ return sessionsOps.clearSummary(this.db, id);
61
+ }
59
62
  async insertObservations(observations) {
60
63
  return observationsOps.insertObservations(this.db, observations);
61
64
  }
@@ -1,5 +1,6 @@
1
1
  import type { DatabaseSync } from 'node:sqlite';
2
2
  import type { Session } from '../../types.js';
3
3
  export declare function upsertSession(db: DatabaseSync, session: Session): Promise<void>;
4
+ export declare function clearSummary(db: DatabaseSync, id: string): Promise<boolean>;
4
5
  export declare function getSession(db: DatabaseSync, id: string): Promise<Session | null>;
5
6
  export declare function recentSessions(db: DatabaseSync, project: string, limit: number): Promise<Session[]>;
@@ -7,6 +7,12 @@ export async function upsertSession(db, session) {
7
7
  ended_at = COALESCE(excluded.ended_at, sessions.ended_at),
8
8
  summary = COALESCE(excluded.summary, sessions.summary)`).run(session.id, session.project, session.startedAt, session.endedAt ?? null, session.summary ?? null);
9
9
  }
10
+ export async function clearSummary(db, id) {
11
+ const result = db
12
+ .prepare('UPDATE sessions SET summary = NULL WHERE id = ? AND summary IS NOT NULL')
13
+ .run(id);
14
+ return Number(result.changes) > 0;
15
+ }
10
16
  export async function getSession(db, id) {
11
17
  const row = db.prepare('SELECT * FROM sessions WHERE id = ?').get(id);
12
18
  return row ? toSession(row) : null;
@@ -0,0 +1,2 @@
1
+ export declare function toPosix(path: string): string;
2
+ export declare function mentionsPath(text: string, needle: string): boolean;
@@ -0,0 +1,7 @@
1
+ export function toPosix(path) {
2
+ return path.replace(/\\/g, '/');
3
+ }
4
+ export function mentionsPath(text, needle) {
5
+ const flatten = (value) => toPosix(value).replace(/\/+/g, '/');
6
+ return flatten(text).includes(flatten(needle));
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-db",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
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",