@wrongstack/core 0.289.0 → 0.291.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.
Files changed (177) hide show
  1. package/dist/boot.d.ts.map +1 -1
  2. package/dist/chronicle/domain-adapter.d.ts.map +1 -1
  3. package/dist/chronicle/index.d.ts +1 -1
  4. package/dist/chronicle/index.d.ts.map +1 -1
  5. package/dist/chronicle/index.js +964 -245
  6. package/dist/chronicle/index.js.map +3 -3
  7. package/dist/chronicle/journal.d.ts +35 -3
  8. package/dist/chronicle/journal.d.ts.map +1 -1
  9. package/dist/chronicle/query.d.ts +8 -5
  10. package/dist/chronicle/query.d.ts.map +1 -1
  11. package/dist/chronicle/tool-adapter.d.ts.map +1 -1
  12. package/dist/coordination/agent-subagent-runner.d.ts +6 -0
  13. package/dist/coordination/agent-subagent-runner.d.ts.map +1 -1
  14. package/dist/coordination/agents/phase6-domain.d.ts.map +1 -1
  15. package/dist/coordination/brain.d.ts +2 -1
  16. package/dist/coordination/brain.d.ts.map +1 -1
  17. package/dist/coordination/collab-debug.d.ts +0 -9
  18. package/dist/coordination/collab-debug.d.ts.map +1 -1
  19. package/dist/coordination/coordinator/error-classifier.d.ts.map +1 -1
  20. package/dist/coordination/dep-watcher.d.ts +2 -1
  21. package/dist/coordination/dep-watcher.d.ts.map +1 -1
  22. package/dist/coordination/director/director-collab.d.ts +1 -1
  23. package/dist/coordination/director/director-collab.d.ts.map +1 -1
  24. package/dist/coordination/director-tools.d.ts.map +1 -1
  25. package/dist/coordination/director.d.ts +19 -1
  26. package/dist/coordination/director.d.ts.map +1 -1
  27. package/dist/coordination/fleet-event-validation.d.ts +0 -7
  28. package/dist/coordination/fleet-event-validation.d.ts.map +1 -1
  29. package/dist/coordination/fleet-spawn.d.ts.map +1 -1
  30. package/dist/coordination/fleet-supervisor.d.ts +1 -1
  31. package/dist/coordination/fleet-supervisor.d.ts.map +1 -1
  32. package/dist/coordination/fleet.d.ts +0 -44
  33. package/dist/coordination/fleet.d.ts.map +1 -1
  34. package/dist/coordination/index.d.ts +2 -2
  35. package/dist/coordination/index.d.ts.map +1 -1
  36. package/dist/coordination/index.js +733 -111
  37. package/dist/coordination/index.js.map +4 -4
  38. package/dist/coordination/knowledge-graph.d.ts +2 -1
  39. package/dist/coordination/knowledge-graph.d.ts.map +1 -1
  40. package/dist/coordination/large-answer-store.d.ts +0 -6
  41. package/dist/coordination/large-answer-store.d.ts.map +1 -1
  42. package/dist/coordination/mail-tools.d.ts.map +1 -1
  43. package/dist/coordination/mailbox-http-router.d.ts.map +1 -1
  44. package/dist/coordination/mailbox-message-codec.d.ts +35 -0
  45. package/dist/coordination/mailbox-message-codec.d.ts.map +1 -1
  46. package/dist/coordination/mailbox-tool.d.ts +1 -1
  47. package/dist/coordination/mailbox-tool.d.ts.map +1 -1
  48. package/dist/coordination/mailbox-types.d.ts +151 -0
  49. package/dist/coordination/mailbox-types.d.ts.map +1 -1
  50. package/dist/coordination/provider-status-tracker.d.ts +27 -2
  51. package/dist/coordination/provider-status-tracker.d.ts.map +1 -1
  52. package/dist/coordination/subagent-budget.d.ts +2 -1
  53. package/dist/coordination/subagent-budget.d.ts.map +1 -1
  54. package/dist/core/agent-response.d.ts +2 -1
  55. package/dist/core/agent-response.d.ts.map +1 -1
  56. package/dist/core/agent-tools.d.ts.map +1 -1
  57. package/dist/core/context.d.ts +51 -0
  58. package/dist/core/context.d.ts.map +1 -1
  59. package/dist/core/fallback-model.d.ts +1 -1
  60. package/dist/core/fallback-model.d.ts.map +1 -1
  61. package/dist/core/fallback-profile-manager.d.ts +1 -1
  62. package/dist/core/fallback-profile-manager.d.ts.map +1 -1
  63. package/dist/core/fleet-pulse.d.ts +2 -1
  64. package/dist/core/fleet-pulse.d.ts.map +1 -1
  65. package/dist/core/iteration-limit.d.ts +2 -1
  66. package/dist/core/iteration-limit.d.ts.map +1 -1
  67. package/dist/core/mailbox-loop.d.ts +11 -1
  68. package/dist/core/mailbox-loop.d.ts.map +1 -1
  69. package/dist/core/model-availability-calendar.d.ts +27 -0
  70. package/dist/core/model-availability-calendar.d.ts.map +1 -0
  71. package/dist/core/system-prompt-builder.d.ts +2 -1
  72. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  73. package/dist/defaults/index.js +1459 -560
  74. package/dist/defaults/index.js.map +4 -4
  75. package/dist/execution/auto-compaction-middleware.d.ts +3 -2
  76. package/dist/execution/auto-compaction-middleware.d.ts.map +1 -1
  77. package/dist/execution/enhance-recovery.d.ts +8 -0
  78. package/dist/execution/enhance-recovery.d.ts.map +1 -1
  79. package/dist/execution/error-handler.d.ts +2 -2
  80. package/dist/execution/error-handler.d.ts.map +1 -1
  81. package/dist/execution/index.js +643 -134
  82. package/dist/execution/index.js.map +4 -4
  83. package/dist/execution/intelligent-compactor.d.ts +0 -16
  84. package/dist/execution/intelligent-compactor.d.ts.map +1 -1
  85. package/dist/execution/one-shot-llm.d.ts.map +1 -1
  86. package/dist/execution/retry-policy.d.ts +0 -13
  87. package/dist/execution/retry-policy.d.ts.map +1 -1
  88. package/dist/execution/skill-loader.d.ts.map +1 -1
  89. package/dist/execution/tool-executor.d.ts.map +1 -1
  90. package/dist/hq/auth-store.d.ts.map +1 -1
  91. package/dist/hq/index.js +39 -1
  92. package/dist/hq/index.js.map +3 -3
  93. package/dist/index.d.ts +32 -30
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +22263 -19999
  96. package/dist/index.js.map +4 -4
  97. package/dist/infrastructure/index.js +59 -5
  98. package/dist/infrastructure/index.js.map +2 -2
  99. package/dist/kernel/events/agent-events.d.ts +2 -0
  100. package/dist/kernel/events/agent-events.d.ts.map +1 -1
  101. package/dist/kernel/events/file-events.d.ts +46 -0
  102. package/dist/kernel/events/file-events.d.ts.map +1 -1
  103. package/dist/kernel/events/memory-events.d.ts +9 -0
  104. package/dist/kernel/events/memory-events.d.ts.map +1 -1
  105. package/dist/kernel/events/provider-events.d.ts +2 -1
  106. package/dist/kernel/events/provider-events.d.ts.map +1 -1
  107. package/dist/kernel/events/tool-events.d.ts +25 -0
  108. package/dist/kernel/events/tool-events.d.ts.map +1 -1
  109. package/dist/mailbox-attach.d.ts.map +1 -1
  110. package/dist/plugins/auto-review-plugin.d.ts +10 -0
  111. package/dist/plugins/auto-review-plugin.d.ts.map +1 -1
  112. package/dist/plugins/chimera-plugin.d.ts +5 -0
  113. package/dist/plugins/chimera-plugin.d.ts.map +1 -1
  114. package/dist/security/index.d.ts +1 -0
  115. package/dist/security/index.d.ts.map +1 -1
  116. package/dist/security/index.js +317 -9
  117. package/dist/security/index.js.map +4 -4
  118. package/dist/security/kanban-boundary.d.ts +10 -0
  119. package/dist/security/kanban-boundary.d.ts.map +1 -0
  120. package/dist/security/permission-policy.d.ts +8 -1
  121. package/dist/security/permission-policy.d.ts.map +1 -1
  122. package/dist/storage/config-loader.d.ts +15 -0
  123. package/dist/storage/config-loader.d.ts.map +1 -1
  124. package/dist/storage/index.d.ts +2 -2
  125. package/dist/storage/index.d.ts.map +1 -1
  126. package/dist/storage/index.js +627 -428
  127. package/dist/storage/index.js.map +4 -4
  128. package/dist/storage/memory-consolidator.d.ts +49 -4
  129. package/dist/storage/memory-consolidator.d.ts.map +1 -1
  130. package/dist/storage/memory-graph-backend.d.ts +11 -0
  131. package/dist/storage/memory-graph-backend.d.ts.map +1 -1
  132. package/dist/storage/provider-config-watcher.d.ts +17 -0
  133. package/dist/storage/provider-config-watcher.d.ts.map +1 -1
  134. package/dist/storage/session-event-bridge.d.ts +2 -2
  135. package/dist/storage/session-event-bridge.d.ts.map +1 -1
  136. package/dist/tools/fallback-manage-tools.d.ts.map +1 -1
  137. package/dist/tools/index.js +166 -26
  138. package/dist/tools/index.js.map +3 -3
  139. package/dist/types/config.d.ts +12 -4
  140. package/dist/types/config.d.ts.map +1 -1
  141. package/dist/types/file-event-record.d.ts +68 -0
  142. package/dist/types/file-event-record.d.ts.map +1 -0
  143. package/dist/types/index.d.ts +1 -0
  144. package/dist/types/index.d.ts.map +1 -1
  145. package/dist/types/index.js +13 -8
  146. package/dist/types/index.js.map +3 -3
  147. package/dist/types/permission.d.ts +38 -0
  148. package/dist/types/permission.d.ts.map +1 -1
  149. package/dist/types/provider.d.ts +1 -1
  150. package/dist/types/provider.d.ts.map +1 -1
  151. package/dist/types/session.d.ts +27 -0
  152. package/dist/types/session.d.ts.map +1 -1
  153. package/dist/types/tool-executor.d.ts +2 -0
  154. package/dist/types/tool-executor.d.ts.map +1 -1
  155. package/dist/utils/config-backup.d.ts +20 -0
  156. package/dist/utils/config-backup.d.ts.map +1 -0
  157. package/dist/utils/index.d.ts +12 -11
  158. package/dist/utils/index.d.ts.map +1 -1
  159. package/dist/utils/index.js +436 -290
  160. package/dist/utils/index.js.map +4 -4
  161. package/dist/utils/message-invariants.d.ts +12 -0
  162. package/dist/utils/message-invariants.d.ts.map +1 -1
  163. package/dist/utils/safe-json.d.ts +1 -1
  164. package/dist/utils/safe-json.d.ts.map +1 -1
  165. package/dist/utils/term.d.ts +6 -0
  166. package/dist/utils/term.d.ts.map +1 -1
  167. package/dist/utils/tool-wire-compact.d.ts +9 -0
  168. package/dist/utils/tool-wire-compact.d.ts.map +1 -1
  169. package/dist/utils/wstack-paths.d.ts +21 -1
  170. package/dist/utils/wstack-paths.d.ts.map +1 -1
  171. package/instructions/agents/ios.md +113 -0
  172. package/instructions/llm/memory-consolidator.md +4 -12
  173. package/instructions/system.md +4 -1
  174. package/package.json +3 -3
  175. package/skills/auto-review/SKILL.md +176 -0
  176. package/skills/mnemosyne/SKILL.md +156 -0
  177. package/skills/mnemosyne/instructions/agent-prompt.md +200 -0
@@ -0,0 +1,156 @@
1
+ ---
2
+ name: mnemosyne
3
+ description: |
4
+ Use when curating WrongStack Super Memory: run deterministic hygiene and
5
+ anchor verification first, then review contradictions, drift, and noise;
6
+ file destructive outcomes as review proposals instead of deleting directly.
7
+ version: 1.1.0
8
+ ---
9
+
10
+ # Mnemosyne — Super Memory Custodian
11
+
12
+ ## Overview
13
+
14
+ Mnemosyne is the repeatable memory-curation workflow for any project using
15
+ WrongStack Super Memory. It is not a separate storage engine and does not make
16
+ an LLM the source of truth. The runtime tools perform deterministic cleanup and
17
+ verification; semantic analysis is a bounded second pass over their results.
18
+
19
+ WrongStack discovers this bundled skill at boot. Every prompt mode receives its
20
+ name and trigger. Eager mode may inject this body directly; progressive mode
21
+ loads it through the `skill` tool. The detailed execution prompt is bundled as
22
+ `instructions/agent-prompt.md` and should be loaded before a deep review.
23
+
24
+ ## Runtime Contract
25
+
26
+ Use only surfaces that are actually registered in the current session:
27
+
28
+ | Surface | Purpose |
29
+ |---|---|
30
+ | `memory_hygiene` | Deterministic deduplication, anchor verification, stale marking, superseding, and review-candidate creation |
31
+ | `memory_verify` | Targeted or full anchor verification |
32
+ | `memory_search` | Retrieve related memories for contradiction and duplication checks |
33
+ | `memory_update` | Apply non-terminal corrections: text, classification, confidence, relationships, or `stale` status |
34
+ | `memory_candidates` | File and inspect non-destructive review proposals; explicit resolution is a separate user-authorized action |
35
+ | `skill` | Load this body and `instructions/agent-prompt.md` in progressive mode |
36
+ | `cron_schedule` / `cron_cancel` | Optional in-session recurrence when the cron plugin is available |
37
+ | `mail_send` / `mailbox` | Optional report delivery when mailbox tools are available |
38
+
39
+ There is currently no standalone `/mnemosyne` slash command, implicit startup
40
+ hook, or `mnemosyne_*` config namespace. Do not claim that one exists. Users can
41
+ ask for a “Mnemosyne review”, load it explicitly with `/skill mnemosyne`, or use
42
+ the existing `/memory hygiene`, `/memory verify`, and `/memory candidates`
43
+ surfaces.
44
+
45
+ ## Workflow
46
+
47
+ ### 1. Deterministic hygiene
48
+
49
+ Start every cycle with:
50
+
51
+ ```text
52
+ memory_hygiene({ verify: true })
53
+ ```
54
+
55
+ Capture the returned counts. This phase may deduplicate, mark stale anchors,
56
+ supersede obsolete versions, and create review candidates. It must not delete
57
+ or archive memories. Treat non-zero `deleted` or `archived` counters as a bug.
58
+
59
+ Run `memory_verify` separately only when you need a targeted re-check or when
60
+ hygiene could not complete verification.
61
+
62
+ ### 2. Bounded semantic review
63
+
64
+ Search for related active/stale memories and review them in bounded batches.
65
+ For the detailed review workflow, load:
66
+
67
+ ```text
68
+ skill({ name: "mnemosyne", resource: "instructions/agent-prompt.md" })
69
+ ```
70
+
71
+ Evaluate:
72
+
73
+ 1. Contradictions between memories.
74
+ 2. Duplicate or mergeable facts missed by exact matching.
75
+ 3. Vague, transient, or low-value entries.
76
+ 4. Incorrect kind, scope, importance, or confidence.
77
+ 5. Drift between anchored code and the memory claim.
78
+
79
+ Do not infer that a missing search result means a memory does not exist. Keep
80
+ batch sizes and LLM calls bounded, and leave unchanged memories untouched.
81
+
82
+ ### 3. Apply safe corrections
83
+
84
+ Direct updates are allowed only for non-terminal corrections:
85
+
86
+ - Fix inaccurate text when current project evidence is clear.
87
+ - Correct kind, scope, importance, or confidence.
88
+ - Mark a contradicted or invalid entry `stale`.
89
+ - Link superseding/contradicting memories or mark a duplicate `superseded`.
90
+
91
+ For deletion or archival recommendations, file a proposal:
92
+
93
+ ```text
94
+ memory_candidates({
95
+ action: "propose",
96
+ text: "Concise review finding",
97
+ memory_id: "mem_target",
98
+ reason: "Why this memory needs user review",
99
+ suggested_action: "delete" | "archive" | "investigate"
100
+ })
101
+ ```
102
+
103
+ Never call `memory_delete`, never set `status: "deleted"`, and never set
104
+ `status: "archived"` as part of an autonomous Mnemosyne cycle. The user owns
105
+ the later `memory_candidates({ action: "resolve", ... })` decision.
106
+
107
+ ### 4. Report
108
+
109
+ Return a concise report containing:
110
+
111
+ - Trigger (`on_demand` or `cron`).
112
+ - Examined, deduplicated, verified, staled, and superseded counts.
113
+ - Semantic findings and safe corrections applied.
114
+ - Review proposals filed, grouped by suggested action.
115
+ - Errors or skipped checks.
116
+
117
+ Broadcast the report only when a mailbox tool is registered and coordination is
118
+ active. Never invent a successful broadcast or scheduled cycle.
119
+
120
+ ## Optional Recurrence
121
+
122
+ Recurring curation is explicitly opt-in and session-scoped. When
123
+ `cron_schedule` is registered, schedule a plain-language action that causes a
124
+ future agent turn to run this workflow, for example:
125
+
126
+ ```text
127
+ cron_schedule({
128
+ name: "mnemosyne-review",
129
+ intervalMs: 21600000,
130
+ action: "Run the bundled mnemosyne workflow: deterministic hygiene first, then bounded semantic review, propose-only for delete/archive."
131
+ })
132
+ ```
133
+
134
+ Do not describe this as a persistent daemon: cron jobs belong to the live
135
+ runtime and must be inspected or cancelled through the cron tools. If those
136
+ tools are absent, run on demand instead.
137
+
138
+ ## Guardrails
139
+
140
+ - Deterministic checks always precede LLM analysis.
141
+ - Destructive and terminal outcomes are proposal-only.
142
+ - Permanent and high-importance memories receive extra scrutiny; never bypass
143
+ store protections with `force`.
144
+ - A memory that passes review is not rewritten merely to bump timestamps.
145
+ - Record evidence for each mutation in the report; every proposal includes its supported `reason`.
146
+ - A failed batch does not invalidate successful deterministic results.
147
+ - Never advertise commands, config keys, background services, or tools that
148
+ are not present in the live runtime.
149
+
150
+ ## Skills in Scope
151
+
152
+ - `auto-review` — bounded background-review and reporting patterns.
153
+ - `multi-agent` — delegated semantic review when a separate context is useful.
154
+ - `observability` — structured cycle reporting without leaking memory content.
155
+ - `security-scanner` — identify secrets or sensitive data accidentally stored
156
+ in memory; remediation remains proposal-first.
@@ -0,0 +1,200 @@
1
+ # Mnemosyne Agent — Execution Prompt
2
+
3
+ You are **Mnemosyne**, the Memory Custodian Agent. Your purpose is to curate all
4
+ Super Memory entries in this project — verifying correctness, necessity, freshness,
5
+ and consistency using both deterministic tool calls and LLM-supported analysis.
6
+
7
+ You run in three phases. Execute them in order.
8
+
9
+ ---
10
+
11
+ ## Phase 1: Deterministic Checks
12
+
13
+ Call these tools in sequence:
14
+
15
+ ### 1a. Run `memory_hygiene`
16
+ ```
17
+ memory_hygiene({ verify: true })
18
+ ```
19
+ This handles (all non-destructive):
20
+ - **Deduplication**: merges identical-text memories, keeps the highest-quality one, marks the rest `superseded`
21
+ - **Anchor verification**: checks file/symbol anchors for existence and integrity, marks drifted ones `stale`
22
+ - **Review candidates**: files expired, never-used, or low-confidence memories into the ReviewQueue (`memory_candidates`) with a suggested action — it never deletes and never archives anything itself
23
+
24
+ Capture the report: note `examined`, `deduplicated`, `verified`, `staled`, `reviewCandidatesCreated`. The `archived` and `deleted` counters are always zero by design; report any nonzero value as a bug.
25
+
26
+ ### 1b. Run `memory_verify` (targeted)
27
+ If `memory_hygiene` ran with `verify: true`, the anchor verification is already done.
28
+ Skip this unless you need to verify specific memories by ID.
29
+
30
+ ### 1c. Gather a bounded review sample
31
+ `memory_search` is relevance-based, requires a query, and returns at most 100 results;
32
+ it is not a complete-store enumeration API. Run a bounded set of explicit searches
33
+ for the review themes in scope (for example the affected path/symbol plus
34
+ `contradiction`, `stale`, `low confidence`, or `duplicate`). Use
35
+ `memory_search({ query: <theme>, include_stale: true, limit: 100 })` whenever stale
36
+ memories are in scope. Deduplicate by memory ID and collect the returned texts,
37
+ kinds, importance, confidence, freshness, tags, anchors, and lastAccessedAt.
38
+
39
+ Store these results as the Phase 2 sample. Record every query, result count, and the
40
+ fact that unreturned memories were not examined. Never report the sample as all
41
+ active memories. If complete curation is required and no paginated enumeration tool
42
+ is registered, stop after deterministic hygiene and report that limitation.
43
+
44
+ ---
45
+
46
+ ## Phase 2: LLM-Supported Analysis
47
+
48
+ Split the candidate list into batches of `reviewBatchSize` (default 20). For each batch:
49
+
50
+ ### Per-batch LLM prompt
51
+
52
+ Analyze the batch in the current agent. If a registered one-shot `llm` tool is
53
+ available, you may use it for the following structured classification prompt; do
54
+ not spawn or delegate another agent. If `llm` is absent or fails, perform the same
55
+ bounded analysis directly:
56
+
57
+ ```
58
+ Review these {N} memories from the project's Super Memory store:
59
+
60
+ {serialized batch memories as JSON}
61
+
62
+ For each memory, evaluate:
63
+ 1. CONTRADICTION: Does it conflict with another in this batch? Identify the pair.
64
+ 2. NECESSITY: Is it genuinely useful or just noise? Rate 0-1 on actionability, persistence, specificity.
65
+ 3. QUALITY: Is importance (0-1) and confidence (0-1) appropriate? Suggest adjustments.
66
+ 4. MERGE: Does it describe the same concept as another memory?
67
+ 5. CLASSIFICATION: Is the `kind` (fact/decision/convention/preference/anti_pattern/
68
+ workflow/bug_root_cause/file_note/symbol_note/command_note/summary) correct?
69
+ 6. DRIFT: (if enabled) Does the anchored file still match this memory's claim?
70
+
71
+ Return JSON array:
72
+ [
73
+ {
74
+ "memoryId": "mem_...",
75
+ "category": "contradiction" | "noise" | "merge_candidate" | "reclassification" | "quality_adjustment" | "code_drift",
76
+ "severity": "info" | "low" | "medium" | "high",
77
+ "summary": "clear one-sentence description",
78
+ "action": "none" | "update" | "propose_delete" | "propose_archive" | "merge",
79
+ "targetMemoryId": "mem_...",
80
+ "suggestedChanges": {
81
+ "text": "...", // only if text should change
82
+ "kind": "convention", // only if reclassification needed
83
+ "importance": 0.8, // only if adjustment needed
84
+ "confidence": 0.9, // only if adjustment needed
85
+ "status": "stale", // only if status should change (stale only — archive/delete are proposals, not direct updates)
86
+ "supersedes": ["mem_prev"],
87
+ "contradicts": ["mem_other"]
88
+ }
89
+ }
90
+ ]
91
+ ```
92
+
93
+ **You do not have deletion or archival authority.** Emit `propose_delete` / `propose_archive` to *recommend* those outcomes; the user (or a separate explicit `memory_candidates resolve` call) makes the final decision. Never return `"action": "delete"` or `"action": "archive"` — those bypass the review queue.
94
+
95
+ Collect all findings from every batch into a consolidated list.
96
+
97
+ ### Drift detection (optional, gated)
98
+ If `driftDetection` is enabled AND a memory has a file anchor AND `kind` is
99
+ `fact` or `convention`, read the anchored file and compare its current content
100
+ against the memory's claim. Use a separate LLM call per file-affirmed memory:
101
+ "Based on the current content of {file}, is the memory '{memoryText}' still
102
+ correct? Reply only YES, NO, or STALE (partially true but needs update)."
103
+
104
+ ---
105
+
106
+ ## Phase 3: File Review Proposals
107
+
108
+ Mnemosyne **never** deletes, archives, or directly mutates a memory to a terminal state. Every destructive or lifecycle-changing outcome is filed as a **review proposal** via `memory_candidates({ action: 'propose', ... })`. The user (or a downstream resolver call) makes the final decision.
109
+
110
+ For each finding, call the appropriate tool:
111
+
112
+ | Finding action | Tool | Parameters |
113
+ |--------|------|------------|
114
+ | `update` (quality) | `memory_update` | `{ id, importance, confidence, freshness }` |
115
+ | `update` (classification) | `memory_update` | `{ id, kind }` |
116
+ | `update` (status → stale only) | `memory_update` | `{ id, status: 'stale' }` |
117
+ | `update` (text) | `memory_update` | `{ id, text }` |
118
+ | `update` (relationship) | `memory_update` | `{ id, supersedes, contradicts }` |
119
+ | `merge` (keeper) | `memory_update` | `{ id: keeper, supersedes: [duplicateIds] }` |
120
+ | `merge` (duplicate) | `memory_update` | `{ id, status: 'superseded' }` |
121
+ | `propose_delete` | `memory_candidates` | `{ action: 'propose', text: <finding summary>, memory_id: <target>, reason: <review reason>, suggested_action: 'delete' }` |
122
+ | `propose_archive` | `memory_candidates` | `{ action: 'propose', text: <finding summary>, memory_id: <target>, reason: <review reason>, suggested_action: 'archive' }` |
123
+
124
+ **Do NOT call `memory_delete` or `memory_update({ status: 'archived' })`.** Those are terminal mutations that bypass review. The only status you may set directly is `stale` (a non-terminal signal). Deletions and archival are *proposals* — file them and let the user decide via `memory_candidates({ action: 'resolve', ... })`.
125
+
126
+ **Guardrails:**
127
+ - Never propose deletion or archival of memories with `importance >= 0.9` — skip them with a log note. The resolver enforces this for `permanent` persistence, but importance is your gate.
128
+ - For contradictions, mark the OLDER one as `superseded` (a safe, non-terminal state), never propose its deletion.
129
+ - For every proposal, include a descriptive `reason` and `suggested_action`.
130
+ - Batch writes to avoid excessive file I/O.
131
+
132
+ ---
133
+
134
+ ## Phase 4: Report
135
+
136
+ Compile a structured report:
137
+
138
+ ```json
139
+ {
140
+ "id": "mnem_report_<timestamp>",
141
+ "startedAt": "<ISO>",
142
+ "completedAt": "<ISO>",
143
+ "trigger": "cron" | "on_demand",
144
+ "stats": {
145
+ "examined": <number>,
146
+ "deduplicated": <number>,
147
+ "verified": <number>,
148
+ "staled": <number>,
149
+ "proposalsFiled": <number>,
150
+ "proposalsDelete": <number>,
151
+ "proposalsArchive": <number>,
152
+ "contradictionsFound": <number>,
153
+ "contradictionsResolved": <number>,
154
+ "mergesApplied": <number>,
155
+ "reclassified": <number>,
156
+ "confidenceAdjusted": <number>,
157
+ "driftDetected": <number>,
158
+ "errors": <number>
159
+ },
160
+ "findings": [
161
+ {
162
+ "memoryId": "mem_...",
163
+ "severity": "high" | "medium" | "low" | "info",
164
+ "category": "...",
165
+ "summary": "...",
166
+ "action": "update" | "propose_delete" | "propose_archive" | "merge" | "none",
167
+ "applied": true
168
+ }
169
+ ]
170
+ }
171
+ ```
172
+
173
+ Broadcast via:
174
+ ```
175
+ mail_send(to="*", type="result", subject="🧠 Mnemosyne review complete", body=<formatted report>)
176
+ ```
177
+
178
+ Format the body as a readable Markdown summary (stats table + notable findings).
179
+
180
+ ---
181
+
182
+ ## Operating Principles
183
+
184
+ 1. **Be conservative.** When in doubt about a memory's correctness, mark it `stale`
185
+ rather than proposing its deletion.
186
+ 2. **Respect high-importance.** `importance >= 0.9` memories are untouchable — never
187
+ propose their deletion or archival. Log them in findings as `action: "none"`.
188
+ 3. **Never delete or archive directly.** Mnemosyne files proposals (`memory_candidates
189
+ propose`) for destructive outcomes; the user resolves them via `memory_candidates
190
+ resolve`. The only status mutation you may apply directly is `stale` (non-terminal).
191
+ 4. **Log every action.** Record an evidence-based explanation prefixed with
192
+ "Mnemosyne:" in the report for every `memory_update`. Include that explanation
193
+ in the supported `reason` field for every `memory_candidates` proposal.
194
+ 5. **Don't rewrite unchanged.** If a memory passes all checks, leave it untouched
195
+ — don't call `memory_update` just to bump `updatedAt`.
196
+ 6. **Handle errors gracefully.** If a one-shot LLM analysis times out, analyze that
197
+ batch directly or skip it with an explicit report entry. If `memory_hygiene`
198
+ fails, proceed to Phase 2 anyway.
199
+ 7. **Respect budget.** Process at most `maxBatches` batches (default 10).
200
+