claude-db 0.8.0 → 0.8.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 CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.1
4
+
5
+ ### Fixed
6
+
7
+ - **A wrong session summary could not be corrected, and kept teaching itself.**
8
+ Summaries are injected at every session start, but nothing could delete one:
9
+ the upsert coalesces a null summary to the existing value, so a summary was
10
+ write-once in practice. One carrying a false claim was therefore re-injected
11
+ into every new session, restated as fact, and captured back as fresh
12
+ observations that outranked the correction — memory records what was said,
13
+ not what is true, so a wrong statement gains credibility by being repeated.
14
+ `claude-db forget --session <id>` now clears one, on all three backends,
15
+ after which it stops being served. Clearing reports whether anything actually
16
+ changed, so the adapters agree rather than SQLite and Postgres counting a
17
+ matched row where MongoDB counted a change.
18
+
19
+ - **Scripted sessions are no longer captured by default.** A headless run —
20
+ a test harness, a cron job, anything driving `claude -p` — writes memory that
21
+ looks like your work but is not, and a fabricated test fixture becoming
22
+ project knowledge is exactly how the summary above was poisoned. Claude Code
23
+ identifies those sessions as `sdk-cli`, and they are now skipped.
24
+ `capture.scripted: true` captures them anyway, for anyone whose real work
25
+ runs through the SDK.
26
+
27
+ Detection has one blind spot worth stating: a `claude -p` spawned from inside
28
+ another Claude session inherits the parent's entrypoint and is
29
+ indistinguishable from it. `CLAUDE_DB_CAPTURE=off` covers that case and any
30
+ other session that should stay unrecorded, while leaving recall working.
31
+
3
32
  ## 0.8.0
4
33
 
5
34
  ### 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
+ }
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)
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-db",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
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",