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.
Files changed (40) hide show
  1. package/README.md +17 -2
  2. package/dist/capture/flush.d.ts +22 -0
  3. package/dist/capture/flush.js +45 -10
  4. package/dist/capture/identity.d.ts +6 -0
  5. package/dist/capture/identity.js +14 -0
  6. package/dist/capture/index.d.ts +5 -3
  7. package/dist/capture/index.js +4 -3
  8. package/dist/capture/manual.d.ts +21 -0
  9. package/dist/capture/manual.js +40 -0
  10. package/dist/capture/transcript.d.ts +12 -0
  11. package/dist/capture/transcript.js +69 -1
  12. package/dist/capture/turn-extractor.js +40 -8
  13. package/dist/cli/index.js +376 -30
  14. package/dist/cli/install.d.ts +15 -1
  15. package/dist/cli/install.js +127 -8
  16. package/dist/config/schema.d.ts +1 -0
  17. package/dist/config/schema.js +9 -1
  18. package/dist/context.js +24 -2
  19. package/dist/embed/builtin.js +3 -1
  20. package/dist/hooks/relevance.js +11 -4
  21. package/dist/hooks/session-end.js +2 -1
  22. package/dist/hooks/session-start.js +22 -3
  23. package/dist/mcp/server.js +56 -6
  24. package/dist/search/service.js +4 -1
  25. package/dist/store/adapter.d.ts +22 -6
  26. package/dist/store/adapter.js +10 -1
  27. package/dist/store/mongo/driver.d.ts +1 -0
  28. package/dist/store/mongo/index.d.ts +3 -2
  29. package/dist/store/mongo/index.js +57 -7
  30. package/dist/store/postgres/index.d.ts +22 -8
  31. package/dist/store/postgres/index.js +165 -21
  32. package/dist/store/sqlite/index.d.ts +3 -2
  33. package/dist/store/sqlite/index.js +112 -9
  34. package/dist/store/sqlite/schema.sql +4 -3
  35. package/dist/types.d.ts +28 -0
  36. package/dist/util/project.d.ts +9 -10
  37. package/dist/util/project.js +52 -13
  38. package/dist/util/vector.d.ts +11 -1
  39. package/dist/util/vector.js +14 -3
  40. package/package.json +2 -2
package/README.md CHANGED
@@ -46,6 +46,13 @@ you send a prompt
46
46
  Both steps are hooks, so they always run. Nothing depends on Claude deciding to
47
47
  look something up.
48
48
 
49
+ Install also writes a short standing instruction into `CLAUDE.local.md` (or
50
+ `~/.claude/CLAUDE.md` for a machine-wide install), telling Claude to search
51
+ memory before asking you to re-explain something. Hook output is context the
52
+ agent may or may not act on; a memory file is a rule for the whole session,
53
+ which is what makes recall the default rather than something you have to ask
54
+ for. `claude-db uninstall` takes the block back out.
55
+
49
56
  **What gets saved.** One observation per turn, and only if that turn edited a
50
57
  file or ran a real command. Questions, `grep`, and "ok" are skipped. A busy day
51
58
  produces 10 to 20 rows, not hundreds.
@@ -71,7 +78,7 @@ Ran: Test run: pnpm test
71
78
 
72
79
  ## Commands
73
80
 
74
- Nine. `cdb` is a shorter alias for all of them.
81
+ `cdb` is a shorter alias for all of them.
75
82
 
76
83
  | Command | What it does |
77
84
  | --- | --- |
@@ -79,10 +86,18 @@ Nine. `cdb` is a shorter alias for all of them.
79
86
  | `claude-db uninstall [--project]` | Remove them, keeping your memory |
80
87
  | `claude-db status` | Is it wired up, has it recorded anything |
81
88
  | `claude-db doctor` | Resolved config and database connectivity |
82
- | `claude-db search <query>` | Search this project's memory |
89
+ | `claude-db search [--all] <query>` | Search this project's memory, or every project |
90
+ | `claude-db remember <text>` | Record a rule outright, e.g. "always use pnpm here" |
91
+ | `claude-db forget <id>` | Delete specific observations by id |
92
+ | `claude-db stats` | What this project's memory is made of |
83
93
  | `claude-db projects` | Every project with memory stored |
94
+ | `claude-db merge [<path>]` | Move memory from an old project path onto this one |
84
95
  | `claude-db use <url>` | Switch database and verify it |
85
96
  | `claude-db flush` | Re-ingest every transcript for this project |
97
+ | `claude-db export [--all]` | Dump memory as JSONL, for backup or migration |
98
+ | `claude-db import <file>` | Load a dump back in; safe to repeat |
99
+ | `claude-db reembed` | Re-embed everything with the current model |
100
+ | `claude-db prune --older-than <days>` | Delete old memory (dry run without `--yes`) |
86
101
  | `claude-db reset [--project] --yes` | Delete memory (dry run without `--yes`) |
87
102
 
88
103
  `--project` scopes to one repo instead of every project on the machine. It
@@ -1,4 +1,5 @@
1
1
  import type { RecallContext } from '../context.js';
2
+ import type { Observation } from '../types.js';
2
3
  export interface FlushResult {
3
4
  observations: number;
4
5
  summary: string | null;
@@ -17,4 +18,25 @@ export interface FlushResult {
17
18
  * same row rather than appending a duplicate.
18
19
  */
19
20
  export declare function flushSession(ctx: RecallContext, sessionId: string, project: string, transcriptPath?: string): Promise<FlushResult>;
21
+ /**
22
+ * Embeddings are an enhancement, never a precondition. A missing model must
23
+ * cost semantic recall, not the memory itself.
24
+ */
25
+ export declare function embedObservations(ctx: RecallContext, observations: Observation[]): Promise<void>;
26
+ /**
27
+ * Recap of the session so far, and the only thing SessionStart injects.
28
+ *
29
+ * Taking the last three titles of the current flush was close to useless once
30
+ * capture became incremental: a flush usually carries a single turn, so the
31
+ * recap of an entire day's session was whatever happened to be typed last.
32
+ * Carrying the previous summary forward makes it cover the session, and
33
+ * ranking by kind keeps a decision over the build command that followed it.
34
+ *
35
+ * ponytail: first three win, so a decision made late in a long session does
36
+ * not displace an earlier one. Rank the session's stored observations instead
37
+ * if that turns out to matter.
38
+ */
39
+ export declare function summarize(observations: Observation[], previous?: string): string;
20
40
  export declare function resetCursor(sessionId: string): void;
41
+ /** The session is over; its offset is scratch state nothing will read again. */
42
+ export declare function clearCursor(sessionId: string): void;
@@ -1,4 +1,4 @@
1
- import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
1
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
2
  import { dirname, join } from 'node:path';
3
3
  import { CONFIG_DIR } from '../config/index.js';
4
4
  import { readTranscript, transcriptPathFor } from './transcript.js';
@@ -29,9 +29,10 @@ export async function flushSession(ctx, sessionId, project, transcriptPath) {
29
29
  writeCursor(sessionId, nextOffset);
30
30
  return { observations: 0, summary: null };
31
31
  }
32
- await embedAll(ctx, observations);
32
+ await embedObservations(ctx, observations);
33
33
  await ctx.store.insertObservations(observations);
34
- const summary = summarize(observations);
34
+ const previous = await ctx.store.getSession(sessionId);
35
+ const summary = summarize(observations, previous?.summary);
35
36
  await ctx.store.upsertSession({
36
37
  id: sessionId,
37
38
  project,
@@ -45,7 +46,7 @@ export async function flushSession(ctx, sessionId, project, transcriptPath) {
45
46
  * Embeddings are an enhancement, never a precondition. A missing model must
46
47
  * cost semantic recall, not the memory itself.
47
48
  */
48
- async function embedAll(ctx, observations) {
49
+ export async function embedObservations(ctx, observations) {
49
50
  try {
50
51
  const embedder = await ctx.embedder();
51
52
  if (embedder.dimensions === 0)
@@ -53,8 +54,12 @@ async function embedAll(ctx, observations) {
53
54
  const vectors = await embedder.embed(observations.map((obs) => `${obs.title}\n${obs.body}`));
54
55
  observations.forEach((obs, index) => {
55
56
  const vector = vectors[index];
56
- if (vector && vector.length > 0)
57
+ if (vector && vector.length > 0) {
57
58
  obs.embedding = vector;
59
+ // Stamped so search can refuse to compare across embedding spaces and
60
+ // `reembed` can tell which rows are already current.
61
+ obs.embedder = embedder.id;
62
+ }
58
63
  });
59
64
  }
60
65
  catch (error) {
@@ -62,11 +67,37 @@ async function embedAll(ctx, observations) {
62
67
  `${error instanceof Error ? error.message : String(error)}\n`);
63
68
  }
64
69
  }
65
- /** Recap built from what was accomplished, not from file counts. */
66
- function summarize(observations) {
67
- const titles = observations.slice(-3).map((obs) => obs.title);
68
- const extra = observations.length - titles.length;
69
- return `${titles.join(' | ')}${extra > 0 ? ` (+${extra} earlier)` : ''}`;
70
+ /** Least forgettable first. What a session is *for* is usually a decision. */
71
+ const KIND_RANK = {
72
+ decision: 0,
73
+ deadend: 1,
74
+ preference: 2,
75
+ bugfix: 3,
76
+ pattern: 4,
77
+ context: 5,
78
+ };
79
+ /**
80
+ * Recap of the session so far, and the only thing SessionStart injects.
81
+ *
82
+ * Taking the last three titles of the current flush was close to useless once
83
+ * capture became incremental: a flush usually carries a single turn, so the
84
+ * recap of an entire day's session was whatever happened to be typed last.
85
+ * Carrying the previous summary forward makes it cover the session, and
86
+ * ranking by kind keeps a decision over the build command that followed it.
87
+ *
88
+ * ponytail: first three win, so a decision made late in a long session does
89
+ * not displace an earlier one. Rank the session's stored observations instead
90
+ * if that turns out to matter.
91
+ */
92
+ export function summarize(observations, previous) {
93
+ const kept = previous ? previous.split(' | ').filter(Boolean) : [];
94
+ for (const obs of [...observations].sort((a, b) => KIND_RANK[a.kind] - KIND_RANK[b.kind])) {
95
+ if (kept.length >= 3)
96
+ break;
97
+ if (!kept.includes(obs.title))
98
+ kept.push(obs.title);
99
+ }
100
+ return kept.join(' | ');
70
101
  }
71
102
  /**
72
103
  * Per-session byte offset into the transcript.
@@ -100,3 +131,7 @@ function writeCursor(sessionId, offset) {
100
131
  export function resetCursor(sessionId) {
101
132
  writeCursor(sessionId, 0);
102
133
  }
134
+ /** The session is over; its offset is scratch state nothing will read again. */
135
+ export function clearCursor(sessionId) {
136
+ rmSync(cursorPath(sessionId), { force: true });
137
+ }
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Who recorded an observation. Meaningless on a personal SQLite file and the
3
+ * whole point on a shared Postgres, where "decided X" is far weaker than
4
+ * "alex decided X". Captured now because it cannot be backfilled later.
5
+ */
6
+ export declare function currentAuthor(): string | undefined;
1
7
  /**
2
8
  * Derives a stable id for an observation from its content.
3
9
  *
@@ -1,4 +1,18 @@
1
1
  import { createHash } from 'node:crypto';
2
+ import { userInfo } from 'node:os';
3
+ /**
4
+ * Who recorded an observation. Meaningless on a personal SQLite file and the
5
+ * whole point on a shared Postgres, where "decided X" is far weaker than
6
+ * "alex decided X". Captured now because it cannot be backfilled later.
7
+ */
8
+ export function currentAuthor() {
9
+ try {
10
+ return userInfo().username || undefined;
11
+ }
12
+ catch {
13
+ return undefined;
14
+ }
15
+ }
2
16
  /**
3
17
  * Derives a stable id for an observation from its content.
4
18
  *
@@ -1,7 +1,9 @@
1
1
  export { classifyCommand } from './command.js';
2
- export { observationId } from './identity.js';
3
- export { readTranscript, transcriptPathFor } from './transcript.js';
2
+ export { currentAuthor, observationId } from './identity.js';
3
+ export { remember } from './manual.js';
4
+ export type { RememberInput } from './manual.js';
5
+ export { readTranscript, transcriptPathFor, transcriptsFor } from './transcript.js';
4
6
  export type { Turn, TranscriptRead } from './transcript.js';
5
7
  export { observationsFromTurns } from './turn-extractor.js';
6
- export { flushSession, resetCursor } from './flush.js';
8
+ export { flushSession, resetCursor, clearCursor, summarize, embedObservations, } from './flush.js';
7
9
  export type { FlushResult } from './flush.js';
@@ -1,5 +1,6 @@
1
1
  export { classifyCommand } from './command.js';
2
- export { observationId } from './identity.js';
3
- export { readTranscript, transcriptPathFor } from './transcript.js';
2
+ export { currentAuthor, observationId } from './identity.js';
3
+ export { remember } from './manual.js';
4
+ export { readTranscript, transcriptPathFor, transcriptsFor } from './transcript.js';
4
5
  export { observationsFromTurns } from './turn-extractor.js';
5
- export { flushSession, resetCursor } from './flush.js';
6
+ export { flushSession, resetCursor, clearCursor, summarize, embedObservations, } from './flush.js';
@@ -0,0 +1,21 @@
1
+ import type { RecallContext } from '../context.js';
2
+ import type { Observation, ObservationKind } from '../types.js';
3
+ export interface RememberInput {
4
+ project: string;
5
+ text: string;
6
+ kind?: ObservationKind;
7
+ files?: string[];
8
+ }
9
+ /**
10
+ * Records something the user stated outright, rather than something inferred
11
+ * from a transcript.
12
+ *
13
+ * Everything else in this package derives memory from what happened. That
14
+ * cannot capture a rule, because a rule is not an event: "we always use pnpm
15
+ * here" leaves no edit and no command, so the extractor correctly drops it and
16
+ * the one thing worth remembering forever is the one thing never stored.
17
+ *
18
+ * Written through the same shape as captured observations, so it is searched,
19
+ * ranked, injected, exported and pruned identically.
20
+ */
21
+ export declare function remember(ctx: RecallContext, input: RememberInput): Promise<Observation>;
@@ -0,0 +1,40 @@
1
+ import { embedObservations } from './flush.js';
2
+ import { currentAuthor, observationId } from './identity.js';
3
+ /**
4
+ * Records something the user stated outright, rather than something inferred
5
+ * from a transcript.
6
+ *
7
+ * Everything else in this package derives memory from what happened. That
8
+ * cannot capture a rule, because a rule is not an event: "we always use pnpm
9
+ * here" leaves no edit and no command, so the extractor correctly drops it and
10
+ * the one thing worth remembering forever is the one thing never stored.
11
+ *
12
+ * Written through the same shape as captured observations, so it is searched,
13
+ * ranked, injected, exported and pruned identically.
14
+ */
15
+ export async function remember(ctx, input) {
16
+ const createdAt = Date.now();
17
+ const author = currentAuthor();
18
+ const title = firstLine(input.text);
19
+ const observation = {
20
+ id: observationId('manual', createdAt, input.text),
21
+ sessionId: 'manual',
22
+ project: input.project,
23
+ kind: input.kind ?? 'preference',
24
+ title,
25
+ body: input.text,
26
+ files: input.files ?? [],
27
+ tags: ['manual'],
28
+ createdAt,
29
+ ...(author ? { author } : {}),
30
+ };
31
+ await embedObservations(ctx, [observation]);
32
+ await ctx.store.insertObservations([observation]);
33
+ return observation;
34
+ }
35
+ const TITLE_MAX = 80;
36
+ function firstLine(text) {
37
+ const line = text.trim().split('\n')[0]?.trim() ?? '';
38
+ const clipped = line.length <= TITLE_MAX ? line : `${line.slice(0, TITLE_MAX)}...`;
39
+ return clipped.length > 0 ? clipped : 'Note';
40
+ }
@@ -39,3 +39,15 @@ export declare function readTranscript(path: string, fromOffset?: number): Trans
39
39
  * the absolute path with separators and dots replaced by dashes.
40
40
  */
41
41
  export declare function transcriptPathFor(project: string, sessionId: string): string;
42
+ /**
43
+ * Every transcript belonging to a project, including sessions started from one
44
+ * of its subdirectories.
45
+ *
46
+ * Claude Code files transcripts under the directory the agent was launched in,
47
+ * while memory is keyed on the repository root, and those differ the moment
48
+ * anyone runs the agent from `repo/frontend`. Candidate directories are found
49
+ * by prefix and then confirmed by the `cwd` each transcript records: the slug
50
+ * maps both `/` and `.` to `-`, so it cannot tell `~/app` from `~/app-extra`,
51
+ * and without the second step a flush would ingest a neighbour's history.
52
+ */
53
+ export declare function transcriptsFor(project: string): string[];
@@ -1,6 +1,7 @@
1
- import { closeSync, fstatSync, openSync, readSync } from 'node:fs';
1
+ import { closeSync, fstatSync, openSync, readdirSync, readSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
3
  import { join } from 'node:path';
4
+ import { resolveProject } from '../util/project.js';
4
5
  /**
5
6
  * Claude Code already writes a complete record of every session to disk:
6
7
  * prompts, replies, and tool calls, appended as JSONL.
@@ -158,3 +159,70 @@ export function transcriptPathFor(project, sessionId) {
158
159
  const slug = project.replace(/[/.]/g, '-');
159
160
  return join(homedir(), '.claude', 'projects', slug, `${sessionId}.jsonl`);
160
161
  }
162
+ /**
163
+ * Every transcript belonging to a project, including sessions started from one
164
+ * of its subdirectories.
165
+ *
166
+ * Claude Code files transcripts under the directory the agent was launched in,
167
+ * while memory is keyed on the repository root, and those differ the moment
168
+ * anyone runs the agent from `repo/frontend`. Candidate directories are found
169
+ * by prefix and then confirmed by the `cwd` each transcript records: the slug
170
+ * maps both `/` and `.` to `-`, so it cannot tell `~/app` from `~/app-extra`,
171
+ * and without the second step a flush would ingest a neighbour's history.
172
+ */
173
+ export function transcriptsFor(project) {
174
+ const root = join(homedir(), '.claude', 'projects');
175
+ const slug = project.replace(/[/.]/g, '-');
176
+ let candidates;
177
+ try {
178
+ candidates = readdirSync(root).filter((name) => name === slug || name.startsWith(`${slug}-`));
179
+ }
180
+ catch {
181
+ return [];
182
+ }
183
+ const transcripts = [];
184
+ for (const dir of candidates) {
185
+ let files;
186
+ try {
187
+ files = readdirSync(join(root, dir)).filter((name) => name.endsWith('.jsonl'));
188
+ }
189
+ catch {
190
+ continue;
191
+ }
192
+ for (const file of files) {
193
+ const path = join(root, dir, file);
194
+ const cwd = transcriptCwd(path);
195
+ if (cwd === null || resolveProject(cwd) === project)
196
+ transcripts.push(path);
197
+ }
198
+ }
199
+ return transcripts.sort();
200
+ }
201
+ /** First cwd recorded in a transcript, without reading a 90MB file. */
202
+ function transcriptCwd(path) {
203
+ let fd;
204
+ try {
205
+ fd = openSync(path, 'r');
206
+ }
207
+ catch {
208
+ return null;
209
+ }
210
+ try {
211
+ const buffer = Buffer.allocUnsafe(65_536);
212
+ const read = readSync(fd, buffer, 0, buffer.length, 0);
213
+ for (const line of buffer.subarray(0, read).toString('utf8').split('\n')) {
214
+ try {
215
+ const cwd = JSON.parse(line).cwd;
216
+ if (typeof cwd === 'string' && cwd.length > 0)
217
+ return cwd;
218
+ }
219
+ catch {
220
+ // Entry without a cwd, or the torn last line of the window.
221
+ }
222
+ }
223
+ return null;
224
+ }
225
+ finally {
226
+ closeSync(fd);
227
+ }
228
+ }
@@ -1,5 +1,5 @@
1
1
  import { classifyCommand } from './command.js';
2
- import { observationId } from './identity.js';
2
+ import { currentAuthor, observationId } from './identity.js';
3
3
  /**
4
4
  * Builds observations from transcript turns.
5
5
  *
@@ -40,15 +40,18 @@ function buildObservation(turn, sessionId, project, config) {
40
40
  ]
41
41
  .filter((line) => line !== '')
42
42
  .join('\n'), config.capture.maxBodyChars));
43
+ const author = currentAuthor();
43
44
  return {
44
45
  id: observationId(sessionId, turn.timestamp, turn.prompt),
45
46
  sessionId,
46
47
  project,
47
- kind: classifyTurn(turn, commands.length > 0),
48
- title: buildTitle(turn, files),
48
+ ...(author ? { author } : {}),
49
+ kind: classifyTurn(turn),
50
+ // Redacted like the body: the title is injected above every future prompt.
51
+ title: redact(buildTitle(turn, files)),
49
52
  body,
50
53
  files,
51
- tags: [],
54
+ tags: topLevelDirs(files, project),
52
55
  createdAt: turn.timestamp,
53
56
  };
54
57
  }
@@ -88,8 +91,34 @@ function headline(sentence) {
88
91
  const word = clause.lastIndexOf(' ');
89
92
  return `${clause.slice(0, word > 30 ? word : TITLE_MAX)}...`;
90
93
  }
91
- function classifyTurn(turn, hasCommands) {
94
+ /**
95
+ * The first path segment under the project root, which is the repository name
96
+ * when the project directory holds several repos, and the top-level source
97
+ * folder when it is one repo. Tags carry real weight in every backend's index,
98
+ * so this is what makes a pooled memory filterable by where the work happened.
99
+ */
100
+ function topLevelDirs(files, project) {
101
+ const prefix = project.endsWith('/') ? project : `${project}/`;
102
+ const tags = new Set();
103
+ for (const file of files) {
104
+ if (!file.startsWith(prefix))
105
+ continue;
106
+ const parts = file.slice(prefix.length).split('/');
107
+ // Two or more parts means the first is a directory, not a root-level file.
108
+ if (parts.length > 1 && parts[0])
109
+ tags.add(parts[0]);
110
+ }
111
+ return [...tags].slice(0, 3);
112
+ }
113
+ function classifyTurn(turn) {
92
114
  const text = `${turn.prompt} ${turn.reasoning}`.toLowerCase();
115
+ // Read from the prompt alone, and only where the phrasing is a standing
116
+ // instruction. "the build always fails" is a bugfix, not a house rule, so
117
+ // always/never have to be followed by something imperative to count.
118
+ if (/\b(from now on|going forward|remember to|prefer)\b/.test(turn.prompt.toLowerCase()) ||
119
+ /\b(always|never)\s+(use|run|do|add|write|call|put|name|commit|push|import|install)\b/.test(turn.prompt.toLowerCase())) {
120
+ return 'preference';
121
+ }
93
122
  if (/\b(instead of|rather than|chose|decided|because|why we|trade-?off)\b/.test(text)) {
94
123
  return 'decision';
95
124
  }
@@ -98,9 +127,7 @@ function classifyTurn(turn, hasCommands) {
98
127
  }
99
128
  if (/\b(fix(ed)?|bug|broken|regression|error|crash)\b/.test(text))
100
129
  return 'bugfix';
101
- if (turn.files.length > 0)
102
- return 'pattern';
103
- return hasCommands ? 'context' : 'context';
130
+ return turn.files.length > 0 ? 'pattern' : 'context';
104
131
  }
105
132
  function firstSentence(text) {
106
133
  const trimmed = text.trim();
@@ -123,11 +150,16 @@ function isExcluded(file, patterns) {
123
150
  return patterns.some((pattern) => file.includes(pattern));
124
151
  }
125
152
  const PRIVATE_BLOCK = /<private>[\s\S]*?<\/private>/gi;
153
+ const PRIVATE_KEY = /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g;
126
154
  function redact(text) {
127
155
  return text
128
156
  .replace(PRIVATE_BLOCK, '[redacted]')
157
+ .replace(PRIVATE_KEY, '[redacted-private-key]')
129
158
  .replace(/\b(sk-[A-Za-z0-9_-]{16,})\b/g, '[redacted-key]')
130
159
  .replace(/\b(gh[pousr]_[A-Za-z0-9]{16,})\b/g, '[redacted-token]')
160
+ .replace(/\bAKIA[0-9A-Z]{16}\b/g, '[redacted-key]')
161
+ .replace(/\bxox[baprs]-[A-Za-z0-9-]{10,}/g, '[redacted-token]')
162
+ .replace(/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g, '[redacted-jwt]')
131
163
  .replace(/(?<=(password|secret|token|api[_-]?key)"?\s*[:=]\s*)"[^"]+"/gi, '"[redacted]"');
132
164
  }
133
165
  function truncate(text, max) {