@chenhw7/dsh-memory 0.1.2 → 0.3.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 (75) hide show
  1. package/README.md +115 -109
  2. package/README.zh-CN.md +117 -108
  3. package/cordis.patch.yml +13 -8
  4. package/lib/client/index.js +616 -185
  5. package/lib/context/conflict.d.ts +19 -2
  6. package/lib/context/conflict.d.ts.map +1 -1
  7. package/lib/context/conflict.js +33 -0
  8. package/lib/context/conflict.js.map +1 -1
  9. package/lib/context/index.d.ts +34 -10
  10. package/lib/context/index.d.ts.map +1 -1
  11. package/lib/context/index.js +195 -24
  12. package/lib/context/index.js.map +1 -1
  13. package/lib/context/policy.d.ts +28 -1
  14. package/lib/context/policy.d.ts.map +1 -1
  15. package/lib/context/policy.js +60 -3
  16. package/lib/context/policy.js.map +1 -1
  17. package/lib/index.d.ts +27 -7
  18. package/lib/index.d.ts.map +1 -1
  19. package/lib/index.js +22 -0
  20. package/lib/index.js.map +1 -1
  21. package/lib/notes/index.d.ts +66 -0
  22. package/lib/notes/index.d.ts.map +1 -0
  23. package/lib/notes/index.js +180 -0
  24. package/lib/notes/index.js.map +1 -0
  25. package/lib/notes/render.d.ts +32 -0
  26. package/lib/notes/render.d.ts.map +1 -0
  27. package/lib/notes/render.js +68 -0
  28. package/lib/notes/render.js.map +1 -0
  29. package/lib/notes/scope.d.ts +35 -0
  30. package/lib/notes/scope.d.ts.map +1 -0
  31. package/lib/notes/scope.js +44 -0
  32. package/lib/notes/scope.js.map +1 -0
  33. package/lib/notes/settings.d.ts +35 -0
  34. package/lib/notes/settings.d.ts.map +1 -0
  35. package/lib/notes/settings.js +36 -0
  36. package/lib/notes/settings.js.map +1 -0
  37. package/lib/notes/writer.d.ts +32 -0
  38. package/lib/notes/writer.d.ts.map +1 -0
  39. package/lib/notes/writer.js +71 -0
  40. package/lib/notes/writer.js.map +1 -0
  41. package/lib/review/accumulator.d.ts +53 -18
  42. package/lib/review/accumulator.d.ts.map +1 -1
  43. package/lib/review/accumulator.js +176 -36
  44. package/lib/review/accumulator.js.map +1 -1
  45. package/lib/review/dedup.d.ts +16 -3
  46. package/lib/review/dedup.d.ts.map +1 -1
  47. package/lib/review/dedup.js +21 -4
  48. package/lib/review/dedup.js.map +1 -1
  49. package/lib/review/extract.d.ts +81 -5
  50. package/lib/review/extract.d.ts.map +1 -1
  51. package/lib/review/extract.js +224 -31
  52. package/lib/review/extract.js.map +1 -1
  53. package/lib/review/index.d.ts +15 -2
  54. package/lib/review/index.d.ts.map +1 -1
  55. package/lib/review/index.js +137 -55
  56. package/lib/review/index.js.map +1 -1
  57. package/lib/scanner.d.ts +15 -0
  58. package/lib/scanner.d.ts.map +1 -1
  59. package/lib/scanner.js +20 -0
  60. package/lib/scanner.js.map +1 -1
  61. package/lib/store/bm25.d.ts +48 -0
  62. package/lib/store/bm25.d.ts.map +1 -0
  63. package/lib/store/bm25.js +115 -0
  64. package/lib/store/bm25.js.map +1 -0
  65. package/lib/store/index.d.ts +26 -3
  66. package/lib/store/index.d.ts.map +1 -1
  67. package/lib/store/index.js +111 -68
  68. package/lib/store/index.js.map +1 -1
  69. package/lib/tool/index.d.ts +3 -1
  70. package/lib/tool/index.d.ts.map +1 -1
  71. package/lib/tool/index.js +52 -9
  72. package/lib/tool/index.js.map +1 -1
  73. package/lib/types.d.ts +17 -1
  74. package/lib/types.d.ts.map +1 -1
  75. package/package.json +35 -30
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The scope×category render matrix for project notes (§4 of
3
+ * docs/PROJECT_NOTES.md): which store entries land in the notes files.
4
+ * Pure functions, zero host imports — shared by the notes renderer and by
5
+ * `memory-context` (which excludes the same set from its own snapshot/index
6
+ * injection so content never appears twice in the prompt).
7
+ *
8
+ * @module @chenhw7/dsh-memory/notes/scope
9
+ */
10
+ /** Categories rendered into CONVENTIONS.md. */
11
+ export const NOTES_CONVENTION_CATEGORIES = ['convention', 'preference'];
12
+ /** Categories rendered into PITFALLS.md (project- and global-scoped only). */
13
+ export const NOTES_PITFALL_CATEGORIES = ['failure', 'procedure', 'tool-quirk'];
14
+ /**
15
+ * Decide whether an entry is rendered into the notes files, and into which
16
+ * one. Rules (docs/PROJECT_NOTES.md §4):
17
+ * - `project`-scoped entries must match the current project name; an unknown
18
+ * project (no cwd) excludes them.
19
+ * - Conventions come from all three scopes (project > global > personal is
20
+ * the render order, doubling as the precedence hint).
21
+ * - Pitfalls come from `project` and `global` scopes only.
22
+ * - Entries without a category, or with categories outside the matrix
23
+ * (`insight`, `correction`, …), are never rendered.
24
+ *
25
+ * @param entry - the entry to classify.
26
+ * @param projectName - the current project name (cwd basename), or undefined.
27
+ * @returns the target notes file kind, or `undefined` when not rendered.
28
+ */
29
+ export function isRenderedEntry(entry, projectName) {
30
+ const category = entry.category;
31
+ if (category === undefined)
32
+ return undefined;
33
+ const inProject = entry.scope === 'project';
34
+ if (inProject && (projectName === undefined || entry.projectName !== projectName))
35
+ return undefined;
36
+ if ((entry.scope === 'user' || entry.scope === 'global' || inProject) && NOTES_CONVENTION_CATEGORIES.includes(category)) {
37
+ return 'conventions';
38
+ }
39
+ if ((entry.scope === 'global' || inProject) && NOTES_PITFALL_CATEGORIES.includes(category)) {
40
+ return 'pitfalls';
41
+ }
42
+ return undefined;
43
+ }
44
+ //# sourceMappingURL=scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../src/notes/scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,+CAA+C;AAC/C,MAAM,CAAC,MAAM,2BAA2B,GAA8B,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;AAElG,8EAA8E;AAC9E,MAAM,CAAC,MAAM,wBAAwB,GAA8B,CAAC,SAAS,EAAE,WAAW,EAAE,YAAY,CAAC,CAAA;AAQzG;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,eAAe,CAAC,KAAsB,EAAE,WAA+B;IACrF,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAA;IAC/B,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAC5C,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,KAAK,SAAS,CAAA;IAC3C,IAAI,SAAS,IAAI,CAAC,WAAW,KAAK,SAAS,IAAI,KAAK,CAAC,WAAW,KAAK,WAAW,CAAC;QAAE,OAAO,SAAS,CAAA;IACnG,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM,IAAI,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,2BAA2B,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxH,OAAO,aAAa,CAAA;IACtB,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,wBAAwB,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC3F,OAAO,UAAU,CAAA;IACnB,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Defaults and the read-side view for the notes keys of the `memory` settings
3
+ * namespace. Both consumers pull from here so defaults cannot drift:
4
+ * `memory-context`'s Config schema (schema `.default()` values → settings UI
5
+ * ownership) and the `memory-notes` plugin (defensive reads of the raw
6
+ * namespace value via `ctx.settings.get`).
7
+ *
8
+ * @module @chenhw7/dsh-memory/notes/settings
9
+ */
10
+ /** Whether notes export + injection are enabled. */
11
+ export declare const DEFAULT_NOTES_ENABLED = true;
12
+ /** Repo-relative directory holding the generated notes files. */
13
+ export declare const DEFAULT_NOTES_DIR = "docs/agent-memory";
14
+ /** Total character budget for the injected notes section. */
15
+ export declare const DEFAULT_NOTES_CHAR_LIMIT = 4000;
16
+ /** Whether the AGENTS.md pointer block is maintained. */
17
+ export declare const DEFAULT_NOTES_AGENTS_POINTER = true;
18
+ /** Max entries per generated file (oldest by updatedAt are truncated). */
19
+ export declare const DEFAULT_NOTES_MAX_ENTRIES_PER_FILE = 100;
20
+ /** The notes slice of the `memory` settings namespace, fully resolved. */
21
+ export interface NotesSettings {
22
+ readonly notesEnabled: boolean;
23
+ readonly notesDir: string;
24
+ readonly notesCharLimit: number;
25
+ readonly notesAgentsPointer: boolean;
26
+ readonly notesMaxEntriesPerFile: number;
27
+ }
28
+ /**
29
+ * Resolve the notes settings from an untyped namespace value (defaults for
30
+ * anything absent or mistyped).
31
+ * @param value - the raw `memory` namespace value (`ctx.settings.get` returns `unknown`).
32
+ * @returns the fully-resolved notes settings.
33
+ */
34
+ export declare function resolveNotesSettings(value: unknown): NotesSettings;
35
+ //# sourceMappingURL=settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../src/notes/settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,oDAAoD;AACpD,eAAO,MAAM,qBAAqB,OAAO,CAAA;AACzC,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,sBAAsB,CAAA;AACpD,6DAA6D;AAC7D,eAAO,MAAM,wBAAwB,OAAO,CAAA;AAC5C,yDAAyD;AACzD,eAAO,MAAM,4BAA4B,OAAO,CAAA;AAChD,0EAA0E;AAC1E,eAAO,MAAM,kCAAkC,MAAM,CAAA;AAErD,0EAA0E;AAC1E,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAA;IACpC,QAAQ,CAAC,sBAAsB,EAAE,MAAM,CAAA;CACxC;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CASlE"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Defaults and the read-side view for the notes keys of the `memory` settings
3
+ * namespace. Both consumers pull from here so defaults cannot drift:
4
+ * `memory-context`'s Config schema (schema `.default()` values → settings UI
5
+ * ownership) and the `memory-notes` plugin (defensive reads of the raw
6
+ * namespace value via `ctx.settings.get`).
7
+ *
8
+ * @module @chenhw7/dsh-memory/notes/settings
9
+ */
10
+ /** Whether notes export + injection are enabled. */
11
+ export const DEFAULT_NOTES_ENABLED = true;
12
+ /** Repo-relative directory holding the generated notes files. */
13
+ export const DEFAULT_NOTES_DIR = 'docs/agent-memory';
14
+ /** Total character budget for the injected notes section. */
15
+ export const DEFAULT_NOTES_CHAR_LIMIT = 4000;
16
+ /** Whether the AGENTS.md pointer block is maintained. */
17
+ export const DEFAULT_NOTES_AGENTS_POINTER = true;
18
+ /** Max entries per generated file (oldest by updatedAt are truncated). */
19
+ export const DEFAULT_NOTES_MAX_ENTRIES_PER_FILE = 100;
20
+ /**
21
+ * Resolve the notes settings from an untyped namespace value (defaults for
22
+ * anything absent or mistyped).
23
+ * @param value - the raw `memory` namespace value (`ctx.settings.get` returns `unknown`).
24
+ * @returns the fully-resolved notes settings.
25
+ */
26
+ export function resolveNotesSettings(value) {
27
+ const v = (typeof value === 'object' && value !== null ? value : {});
28
+ return {
29
+ notesEnabled: typeof v.notesEnabled === 'boolean' ? v.notesEnabled : DEFAULT_NOTES_ENABLED,
30
+ notesDir: typeof v.notesDir === 'string' && v.notesDir.trim().length > 0 ? v.notesDir.trim() : DEFAULT_NOTES_DIR,
31
+ notesCharLimit: typeof v.notesCharLimit === 'number' && v.notesCharLimit >= 0 ? Math.trunc(v.notesCharLimit) : DEFAULT_NOTES_CHAR_LIMIT,
32
+ notesAgentsPointer: typeof v.notesAgentsPointer === 'boolean' ? v.notesAgentsPointer : DEFAULT_NOTES_AGENTS_POINTER,
33
+ notesMaxEntriesPerFile: typeof v.notesMaxEntriesPerFile === 'number' && v.notesMaxEntriesPerFile >= 0 ? Math.trunc(v.notesMaxEntriesPerFile) : DEFAULT_NOTES_MAX_ENTR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O,CAAC,CAAC,kBAAkB,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,4BAA4B;QACnH,sBAAsB,EAAE,OAAO,CAAC,CAAC,sBAAsB,KAAK,QAAQ,IAAI,CAAC,CAAC,sBAAsB,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,kCAAkC;KAClL,CAAA;AACH,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Filesystem writes for project notes: atomic file replacement and the
3
+ * AGENTS.md pointer-block maintenance. The exporter is the single writer of
4
+ * the managed regions, so no locking is needed; atomic rename keeps readers
5
+ * (and concurrent sessions rendering the same truth) from ever seeing a torn
6
+ * file.
7
+ *
8
+ * @module @chenhw7/dsh-memory/notes/writer
9
+ */
10
+ /**
11
+ * Write a file atomically: write to a sibling temp file, then rename.
12
+ * Parent directories are created on demand.
13
+ * @param filePath - the target file path.
14
+ * @param content - the full file content.
15
+ */
16
+ export declare function writeFileAtomic(filePath: string, content: string): Promise<void>;
17
+ /** Marker opening the managed pointer block in AGENTS.md. */
18
+ export declare const AGENTS_POINTER_BEGIN = "<!-- dsh-memory:begin -->";
19
+ /** Marker closing the managed pointer block in AGENTS.md. */
20
+ export declare const AGENTS_POINTER_END = "<!-- dsh-memory:end -->";
21
+ /** The managed pointer block text for a given notes directory (repo-relative). */
22
+ export declare function agentsPointerBlock(notesDir: string): string;
23
+ /**
24
+ * Ensure the AGENTS.md pointer block exists. Creates a pointer-only AGENTS.md
25
+ * when absent; replaces an existing managed block in place (idempotent:
26
+ * rewrites only when the block text actually changed); appends the block when
27
+ * the file exists without one. Everything outside the markers is untouched.
28
+ * @param agentsPath - absolute path of the repository's AGENTS.md.
29
+ * @param notesDir - repo-relative notes directory named in the pointer.
30
+ */
31
+ export declare function ensureAgentsPointer(agentsPath: string, notesDir: string): Promise<void>;
32
+ //# sourceMappingURL=writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../src/notes/writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUtF;AAED,6DAA6D;AAC7D,eAAO,MAAM,oBAAoB,8BAA8B,CAAA;AAC/D,6DAA6D;AAC7D,eAAO,MAAM,kBAAkB,4BAA4B,CAAA;AAE3D,kFAAkF;AAClF,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqB7F"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Filesystem writes for project notes: atomic file replacement and the
3
+ * AGENTS.md pointer-block maintenance. The exporter is the single writer of
4
+ * the managed regions, so no locking is needed; atomic rename keeps readers
5
+ * (and concurrent sessions rendering the same truth) from ever seeing a torn
6
+ * file.
7
+ *
8
+ * @module @chenhw7/dsh-memory/notes/writer
9
+ */
10
+ import { mkdir, readFile, rename, unlink, writeFile } from 'node:fs/promises';
11
+ import path from 'node:path';
12
+ /**
13
+ * Write a file atomically: write to a sibling temp file, then rename.
14
+ * Parent directories are created on demand.
15
+ * @param filePath - the target file path.
16
+ * @param content - the full file content.
17
+ */
18
+ export async function writeFileAtomic(filePath, content) {
19
+ await mkdir(path.dirname(filePath), { recursive: true });
20
+ const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
21
+ try {
22
+ await writeFile(tmp, content, 'utf8');
23
+ await rename(tmp, filePath);
24
+ }
25
+ catch (error) {
26
+ await unlink(tmp).catch(() => { });
27
+ throw error;
28
+ }
29
+ }
30
+ /** Marker opening the managed pointer block in AGENTS.md. */
31
+ export const AGENTS_POINTER_BEGIN = '<!-- dsh-memory:begin -->';
32
+ /** Marker closing the managed pointer block in AGENTS.md. */
33
+ export const AGENTS_POINTER_END = '<!-- dsh-memory:end -->';
34
+ /** The managed pointer block text for a given notes directory (repo-relative). */
35
+ export function agentsPointerBlock(notesDir) {
36
+ return `${AGENTS_POINTER_BEGIN}\n> Agent-maintained project notes live in \`${notesDir}/\` (auto-generated by dsh-memory — do not edit those files by hand).\n${AGENTS_POINTER_END}`;
37
+ }
38
+ /**
39
+ * Ensure the AGENTS.md pointer block exists. Creates a pointer-only AGENTS.md
40
+ * when absent; replaces an existing managed block in place (idempotent:
41
+ * rewrites only when the block text actually changed); appends the block when
42
+ * the file exists without one. Everything outside the markers is untouched.
43
+ * @param agentsPath - absolute path of the repository's AGENTS.md.
44
+ * @param notesDir - repo-relative notes directory named in the pointer.
45
+ */
46
+ export async function ensureAgentsPointer(agentsPath, notesDir) {
47
+ const block = agentsPointerBlock(notesDir);
48
+ let existing;
49
+ try {
50
+ existing = await readFile(agentsPath, 'utf8');
51
+ }
52
+ catch (error) {
53
+ if (error.code !== 'ENOENT')
54
+ throw error;
55
+ }
56
+ if (existing === undefined) {
57
+ await writeFileAtomic(agentsPath, `${block}\n`);
58
+ return;
59
+ }
60
+ const beginIdx = existing.indexOf(AGENTS_POINTER_BEGIN);
61
+ const endIdx = existing.indexOf(AGENTS_POINTER_END);
62
+ if (beginIdx >= 0 && endIdx > beginIdx) {
63
+ const next = existing.slice(0, beginIdx) + block + existing.slice(endIdx + AGENTS_POINTER_END.length);
64
+ if (next !== existing)
65
+ await writeFileAtomic(agentsPath, next);
66
+ return;
67
+ }
68
+ const separator = existing.endsWith('\n') ? '\n' : '\n\n';
69
+ await writeFileAtomic(agentsPath, existing + separator + block + '\n');
70
+ }
71
+ //# sourceMappingURL=writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writer.js","sourceRoot":"","sources":["../../src/notes/writer.ts"],"names":[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AC;QACH,QAAQ,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAA;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,MAAM,KAAK,CAAA;IACrE,CAAC;IACD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,MAAM,eAAe,CAAC,UAAU,EAAE,GAAG,KAAK,IAAI,CAAC,CAAA;QAC/C,OAAM;IACR,CAAC;IACD,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACvD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAA;IACnD,IAAI,QAAQ,IAAI,CAAC,IAAI,MAAM,GAAG,QAAQ,EAAE,CAAC;QACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAA;QACrG,IAAI,IAAI,KAAK,QAAQ;YAAE,MAAM,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;QAC9D,OAAM;IACR,CAAC;IACD,MAAM,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAA;IACzD,MAAM,eAAe,CAAC,UAAU,EAAE,QAAQ,GAAG,SAAS,GAAG,KAAK,GAAG,IAAI,CAAC,CAAA;AACxE,CAAC"}
@@ -1,9 +1,17 @@
1
1
  /**
2
2
  * The periodic-review projection accumulator: a pure, synchronous fold over
3
- * `user/message` events (keyword/correction signals) and `tool/result` events
4
- * (tool-call failures) that collects candidate memory fragments. No LLM runs
5
- * here — the {@link agent/pre-step} listener drains the accumulator once it
6
- * reaches the configured threshold and runs one extraction call.
3
+ * session events that collects candidate memory fragments. No LLM runs here —
4
+ * the {@link agent/pre-step} listener drains the accumulator once it reaches
5
+ * the configured threshold and runs one extraction call.
6
+ *
7
+ * Signal sources (§5 of docs/PROJECT_NOTES.md):
8
+ * - `user/message` — keyword hits (explicit "remember" intent) and corrections
9
+ * (the user revises a prior statement).
10
+ * - `tool/call` + `tool/result` — **failure-streak pairing**: consecutive
11
+ * same-signature tool failures followed by a success emit one
12
+ * `pitfall-resolved` candidate (the workaround is verified by the success).
13
+ * One-shot failures no longer become candidates; the compaction/dispose
14
+ * flush still sees full events as the safety net.
7
15
  *
8
16
  * @module @chenhw7/dsh-memory/review/accumulator
9
17
  */
@@ -17,21 +25,47 @@ declare module '@deepseek-ai/dsh-session-projection/types' {
17
25
  'memory-review-candidates': AccumulatorView;
18
26
  }
19
27
  }
28
+ /** The signal emitted when a failure streak is resolved by a success. */
29
+ export declare const PITFALL_RESOLVED_SIGNAL = "pitfall-resolved";
20
30
  /** One candidate fragment collected by the accumulator. */
21
31
  export interface MemoryCandidate {
22
32
  /** The text fragment that matched a signal. */
23
33
  readonly text: string;
24
- /** Which signal class matched (`keyword`, `correction`, or `tool-failure`). */
34
+ /** Which signal class matched (`keyword`, `correction`, or `pitfall-resolved`). */
25
35
  readonly signal: string;
26
36
  /** Seq of the session event the fragment came from. */
27
37
  readonly seq: number;
28
38
  }
39
+ /** A registered tool call awaiting its result, keyed by callId. */
40
+ export interface OpenCall {
41
+ /** The invoked tool's name. */
42
+ readonly name: string;
43
+ /** The normalized signature (toolName + normalized primary argument). */
44
+ readonly signature: string;
45
+ /** Seq of the `tool/call` event. */
46
+ readonly seq: number;
47
+ }
48
+ /** One open failure streak for a signature. */
49
+ export interface OpenStreak {
50
+ /** Consecutive failure count so far. */
51
+ readonly count: number;
52
+ /** Truncated description of the most recent failure (error identity + text). */
53
+ readonly lastErrorText: string;
54
+ /** Seq of the first failure in the streak. */
55
+ readonly firstSeq: number;
56
+ /** Seq of the most recent failure (drives LRU eviction). */
57
+ readonly lastSeq: number;
58
+ }
29
59
  /** Internal accumulator state (plain JSON per the projection contract). */
30
60
  export interface AccumulatorState {
31
61
  /** Collected candidate fragments, in collection order. */
32
62
  readonly candidates: readonly MemoryCandidate[];
33
63
  /** Number of candidates collected so far (a derived length, cached for the threshold check). */
34
64
  readonly count: number;
65
+ /** Tool calls awaiting their results, keyed by callId (capped). */
66
+ readonly openCalls: Record<string, OpenCall>;
67
+ /** Open failure streaks, keyed by signature (capped, LRU-evicted). */
68
+ readonly openStreaks: Record<string, OpenStreak>;
35
69
  }
36
70
  /** The wire payload (read-side projection) is the accumulator state itself. */
37
71
  export type AccumulatorView = AccumulatorState;
@@ -51,27 +85,28 @@ export declare function messageText(event: SessionEvent): string | undefined;
51
85
  */
52
86
  export declare function detectSignal(text: string): string | undefined;
53
87
  /**
54
- * Extract a failure fragment from a `tool/result` event that carries an error.
55
- * @param event - a `tool/result` session event.
56
- * @returns the failure description text, or `undefined` when the event has no error.
88
+ * Normalize a tool invocation into a failure-streak signature:
89
+ * `toolName:argument-key`. Shell-like `command` arguments collapse to the
90
+ * first two tokens (`npm test`, `pnpm build`); path-like arguments use the
91
+ * path; everything else falls back to the bare tool name. Unparsable
92
+ * argument JSON also falls back to the bare tool name.
93
+ * @param name - the invoked tool's name.
94
+ * @param argumentsJson - the raw arguments JSON string from the `tool/call` event.
95
+ * @returns the normalized signature (≤ {@link SIGNATURE_LIMIT} chars).
57
96
  */
58
- export declare function toolFailureText(event: SessionEvent): string | undefined;
97
+ export declare function toolSignature(name: string, argumentsJson: string): string;
59
98
  /**
60
99
  * The projection's `apply` transition: fold one committed event into the
61
100
  * accumulator. Returns the SAME state reference for events that do not
62
- * contribute a candidate (the registry's `Object.is` gate).
63
- *
64
- * Signal sources:
65
- * - `user/message` — keyword hits (explicit "remember" intent) and corrections
66
- * (user revises a prior statement).
67
- * - `tool/result` — tool-call failures (§3.6 richer signals): a failed tool
68
- * execution may carry a durable workaround worth remembering.
101
+ * contribute any change (the registry's `Object.is` gate).
69
102
  *
70
103
  * @param state - the state covering all prior events.
71
104
  * @param event - the next committed session event.
72
- * @returns the next state (same reference when the event contributes nothing).
105
+ * @param pitfallThreshold - consecutive same-signature failures required
106
+ * before a following success emits a `pitfall-resolved` candidate.
107
+ * @returns the next state (same reference when the event changes nothing).
73
108
  */
74
- export declare function applyAccumulator(state: AccumulatorState, event: SessionEvent): AccumulatorState;
109
+ export declare function applyAccumulator(state: AccumulatorState, event: SessionEvent, pitfallThreshold?: number): AccumulatorState;
75
110
  /** Zod schema for the accumulator's wire payload. */
76
111
  export declare const accumulatorSchema: ZodType<AccumulatorView>;
77
112
  //# sourceMappingURL=accumulator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"accumulator.d.ts","sourceRoot":"","sources":["../../src/review/accumulator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAClC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAE5D,6EAA6E;AAC7E,eAAO,MAAM,4BAA4B,6BAA6B,CAAA;AAEtE,OAAO,QAAQ,2CAA2C,CAAC;IACzD,UAAU,oBAAoB;QAC5B,sEAAsE;QACtE,0BAA0B,EAAE,eAAe,CAAA;KAC5C;CACF;AAED,2DAA2D;AAC3D,MAAM,WAAW,eAAe;IAC9B,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,uDAAuD;IACvD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CACrB;AAED,2EAA2E;AAC3E,MAAM,WAAW,gBAAgB;IAC/B,0DAA0D;IAC1D,QAAQ,CAAC,UAAU,EAAE,SAAS,eAAe,EAAE,CAAA;IAC/C,gGAAgG;IAChG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED,+EA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