claude-memory-layer 1.0.31 → 1.0.33

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 (343) hide show
  1. package/README.md +9 -2
  2. package/dist/cli/index.js +1110 -72
  3. package/dist/cli/index.js.map +4 -4
  4. package/dist/core/index.js +414 -25
  5. package/dist/core/index.js.map +2 -2
  6. package/dist/hooks/post-tool-use.js +416 -27
  7. package/dist/hooks/post-tool-use.js.map +2 -2
  8. package/dist/hooks/semantic-daemon.js +416 -27
  9. package/dist/hooks/semantic-daemon.js.map +2 -2
  10. package/dist/hooks/session-end.js +416 -27
  11. package/dist/hooks/session-end.js.map +2 -2
  12. package/dist/hooks/session-start.js +416 -27
  13. package/dist/hooks/session-start.js.map +2 -2
  14. package/dist/hooks/stop.js +416 -27
  15. package/dist/hooks/stop.js.map +2 -2
  16. package/dist/hooks/user-prompt-submit.js +504 -34
  17. package/dist/hooks/user-prompt-submit.js.map +2 -2
  18. package/dist/index.js +416 -27
  19. package/dist/index.js.map +2 -2
  20. package/dist/mcp/index.js +407 -32
  21. package/dist/mcp/index.js.map +2 -2
  22. package/dist/server/api/index.js +850 -44
  23. package/dist/server/api/index.js.map +3 -3
  24. package/dist/server/index.js +1073 -64
  25. package/dist/server/index.js.map +3 -3
  26. package/dist/services/memory-service.js +416 -27
  27. package/dist/services/memory-service.js.map +2 -2
  28. package/dist/ui/assets/js/bootstrap.js +2 -0
  29. package/dist/ui/assets/js/overview.js +166 -3
  30. package/dist/ui/assets/js/state.js +3 -0
  31. package/dist/ui/index.html +20 -0
  32. package/dist/ui/style.css +193 -0
  33. package/package.json +15 -2
  34. package/scripts/postinstall-embedding-backend.cjs +16 -12
  35. package/AGENTS.md +0 -71
  36. package/CLAUDE.md +0 -30
  37. package/HANDOFF.md +0 -92
  38. package/Memo.txt +0 -558
  39. package/benchmarks/replay/anonymized-real-sessions.json +0 -48
  40. package/config/kpi-thresholds.json +0 -7
  41. package/context.md +0 -636
  42. package/docs/ARCHITECTURE_COMPARISON_AND_RECOMMENDATIONS.md +0 -627
  43. package/docs/HERMES_MEMORY_INGESTION_ANALYSIS.md +0 -440
  44. package/docs/MCP_MEMORY_SERVICE_COMPARATIVE_REVIEW.md +0 -271
  45. package/docs/MEMORY_USEFULNESS_AUDIT.md +0 -371
  46. package/docs/MEMORY_USEFULNESS_AUDIT_RAW.json +0 -80
  47. package/docs/MEMSEARCH_PROJECT_STRUCTURE_ANALYSIS.md +0 -333
  48. package/docs/MEMU_ADOPTION.md +0 -40
  49. package/docs/OPERATIONS.md +0 -18
  50. package/docs/PRODUCT_VALIDATION_MATRIX.md +0 -82
  51. package/docs/PROJECT_STRUCTURE_ANALYSIS.md +0 -421
  52. package/docs/REFACTORING_MILESTONES_AND_ISSUES.md +0 -501
  53. package/docs/REFACTORING_PLAN_THIN_CORE.md +0 -414
  54. package/docs/REFERENCE_PROJECT_ANALYSES.md +0 -25
  55. package/docs/SUPERLOCALMEMORY_PROJECT_STRUCTURE_ANALYSIS.md +0 -452
  56. package/docs/TARGET_ARCHITECTURE_AND_FOLDER_STRUCTURE.md +0 -446
  57. package/docs/architecture/comparison-index.md +0 -47
  58. package/docs/reports/codex-real-data-validation-20260505T040447Z.md +0 -46
  59. package/plan.md +0 -1642
  60. package/scripts/build.ts +0 -159
  61. package/scripts/bump-patch-version.sh +0 -18
  62. package/scripts/delete-unknown-projects.js +0 -154
  63. package/scripts/fix-sync-gap.js +0 -32
  64. package/scripts/generate-session-qrels.ts +0 -126
  65. package/scripts/heartbeat-memory-orchestrator.sh +0 -28
  66. package/scripts/replay-retrieval-benchmark.ts +0 -69
  67. package/scripts/report-sync-gap.js +0 -26
  68. package/scripts/review-queue-auto-resolve.js +0 -21
  69. package/scripts/sync-gap-auto-heal.sh +0 -17
  70. package/spec.md +0 -624
  71. package/specs/20260207-dashboard-upgrade/context.md +0 -38
  72. package/specs/20260207-dashboard-upgrade/spec.md +0 -96
  73. package/specs/citations-system/context.md +0 -243
  74. package/specs/citations-system/plan.md +0 -495
  75. package/specs/citations-system/spec.md +0 -371
  76. package/specs/endless-mode/context.md +0 -305
  77. package/specs/endless-mode/plan.md +0 -620
  78. package/specs/endless-mode/spec.md +0 -455
  79. package/specs/entity-edge-model/context.md +0 -401
  80. package/specs/entity-edge-model/plan.md +0 -459
  81. package/specs/entity-edge-model/spec.md +0 -391
  82. package/specs/evidence-aligner-v2/context.md +0 -401
  83. package/specs/evidence-aligner-v2/plan.md +0 -303
  84. package/specs/evidence-aligner-v2/spec.md +0 -312
  85. package/specs/mcp-desktop-integration/context.md +0 -278
  86. package/specs/mcp-desktop-integration/plan.md +0 -550
  87. package/specs/mcp-desktop-integration/spec.md +0 -494
  88. package/specs/memory-utilization-improvements/context.md +0 -145
  89. package/specs/memory-utilization-improvements/plan.md +0 -361
  90. package/specs/memory-utilization-improvements/spec.md +0 -361
  91. package/specs/post-tool-use-hook/context.md +0 -319
  92. package/specs/post-tool-use-hook/plan.md +0 -469
  93. package/specs/post-tool-use-hook/spec.md +0 -364
  94. package/specs/private-tags/context.md +0 -288
  95. package/specs/private-tags/plan.md +0 -412
  96. package/specs/private-tags/spec.md +0 -345
  97. package/specs/progressive-disclosure/context.md +0 -346
  98. package/specs/progressive-disclosure/plan.md +0 -663
  99. package/specs/progressive-disclosure/spec.md +0 -415
  100. package/specs/selective-tool-observation/context.md +0 -100
  101. package/specs/selective-tool-observation/plan.md +0 -158
  102. package/specs/selective-tool-observation/spec.md +0 -127
  103. package/specs/task-entity-system/context.md +0 -297
  104. package/specs/task-entity-system/plan.md +0 -301
  105. package/specs/task-entity-system/spec.md +0 -314
  106. package/specs/thin-core-refactor/context.md +0 -275
  107. package/specs/thin-core-refactor/plan.md +0 -536
  108. package/specs/thin-core-refactor/spec.md +0 -465
  109. package/specs/vector-outbox-v2/context.md +0 -470
  110. package/specs/vector-outbox-v2/plan.md +0 -562
  111. package/specs/vector-outbox-v2/spec.md +0 -466
  112. package/specs/web-viewer-ui/context.md +0 -384
  113. package/specs/web-viewer-ui/plan.md +0 -797
  114. package/specs/web-viewer-ui/spec.md +0 -516
  115. package/src/adapters/claude/capture/index.ts +0 -3
  116. package/src/adapters/claude/context/index.ts +0 -3
  117. package/src/adapters/claude/hooks/index.ts +0 -21
  118. package/src/adapters/claude/hooks/post-tool-use.ts +0 -239
  119. package/src/adapters/claude/hooks/prompt-injection-policy.ts +0 -104
  120. package/src/adapters/claude/hooks/semantic-daemon-client.ts +0 -209
  121. package/src/adapters/claude/hooks/semantic-daemon.ts +0 -283
  122. package/src/adapters/claude/hooks/session-end.ts +0 -59
  123. package/src/adapters/claude/hooks/session-start.ts +0 -73
  124. package/src/adapters/claude/hooks/stop.ts +0 -128
  125. package/src/adapters/claude/hooks/user-prompt-submit.ts +0 -361
  126. package/src/adapters/claude/index.ts +0 -4
  127. package/src/adapters/claude/transcript/index.ts +0 -4
  128. package/src/adapters/claude/transcript/transcript-reader.ts +0 -57
  129. package/src/adapters/claude/transcript/turn-reconstructor.ts +0 -65
  130. package/src/apps/cli/claude-settings-hooks.ts +0 -138
  131. package/src/apps/cli/codex-import-runner.ts +0 -125
  132. package/src/apps/cli/codex-validation-output.ts +0 -95
  133. package/src/apps/cli/hermes-import-runner.ts +0 -130
  134. package/src/apps/cli/hermes-validation-output.ts +0 -91
  135. package/src/apps/cli/index.ts +0 -1735
  136. package/src/apps/cli/mcp-install.ts +0 -106
  137. package/src/apps/cli/retrieval-disclosure-output.ts +0 -196
  138. package/src/apps/dashboard/assets/js/bootstrap.js +0 -244
  139. package/src/apps/dashboard/assets/js/chat.js +0 -373
  140. package/src/apps/dashboard/assets/js/disclosure.js +0 -232
  141. package/src/apps/dashboard/assets/js/modals.js +0 -298
  142. package/src/apps/dashboard/assets/js/overview.js +0 -655
  143. package/src/apps/dashboard/assets/js/state.js +0 -72
  144. package/src/apps/dashboard/assets/js/views.js +0 -468
  145. package/src/apps/dashboard/index.html +0 -543
  146. package/src/apps/dashboard/index.ts +0 -3
  147. package/src/apps/dashboard/style.css +0 -1750
  148. package/src/apps/index.ts +0 -5
  149. package/src/apps/server/api/chat.ts +0 -244
  150. package/src/apps/server/api/citations.ts +0 -105
  151. package/src/apps/server/api/events.ts +0 -137
  152. package/src/apps/server/api/health.ts +0 -53
  153. package/src/apps/server/api/index.ts +0 -26
  154. package/src/apps/server/api/projects.ts +0 -74
  155. package/src/apps/server/api/search.ts +0 -184
  156. package/src/apps/server/api/sessions.ts +0 -115
  157. package/src/apps/server/api/stats.ts +0 -723
  158. package/src/apps/server/api/turns.ts +0 -143
  159. package/src/apps/server/api/utils.ts +0 -65
  160. package/src/apps/server/index.ts +0 -111
  161. package/src/cli/index.ts +0 -3
  162. package/src/cli/retrieval-disclosure-output.ts +0 -2
  163. package/src/compat/index.ts +0 -5
  164. package/src/core/canonical-key.ts +0 -186
  165. package/src/core/citation-generator.ts +0 -63
  166. package/src/core/consolidated-store.ts +0 -356
  167. package/src/core/consolidation-worker.ts +0 -493
  168. package/src/core/context-formatter.ts +0 -276
  169. package/src/core/continuity-manager.ts +0 -341
  170. package/src/core/db-wrapper.ts +0 -64
  171. package/src/core/derive/fact-deriver.ts +0 -170
  172. package/src/core/derive/index.ts +0 -2
  173. package/src/core/derive/summary-deriver.ts +0 -76
  174. package/src/core/edge-repo.ts +0 -333
  175. package/src/core/embedder.ts +0 -4
  176. package/src/core/engine/embedding-maintenance-service.ts +0 -187
  177. package/src/core/engine/endless-memory-services.ts +0 -4
  178. package/src/core/engine/index.ts +0 -19
  179. package/src/core/engine/memory-engine-services.ts +0 -170
  180. package/src/core/engine/memory-ingest-service.ts +0 -317
  181. package/src/core/engine/memory-query-service.ts +0 -173
  182. package/src/core/engine/memory-runtime-service.ts +0 -162
  183. package/src/core/engine/memory-service-composition.ts +0 -231
  184. package/src/core/engine/retrieval-analytics-service.ts +0 -181
  185. package/src/core/engine/retrieval-disclosure-service.ts +0 -420
  186. package/src/core/engine/retrieval-orchestrator.ts +0 -377
  187. package/src/core/engine/retrieval-services.ts +0 -176
  188. package/src/core/engine/shared-memory-services.ts +0 -4
  189. package/src/core/entity-repo.ts +0 -349
  190. package/src/core/event-store.ts +0 -779
  191. package/src/core/evidence-aligner.ts +0 -635
  192. package/src/core/external-market-context.ts +0 -582
  193. package/src/core/graduation-worker.ts +0 -171
  194. package/src/core/graduation.ts +0 -377
  195. package/src/core/index.ts +0 -64
  196. package/src/core/ingest-interceptor.ts +0 -80
  197. package/src/core/markdown-mirror.ts +0 -70
  198. package/src/core/matcher.ts +0 -208
  199. package/src/core/md-mirror.ts +0 -92
  200. package/src/core/metadata-extractor.ts +0 -203
  201. package/src/core/model/memory-fact.ts +0 -30
  202. package/src/core/model/memory-rule.ts +0 -14
  203. package/src/core/model/memory-summary.ts +0 -21
  204. package/src/core/model/raw-event.ts +0 -28
  205. package/src/core/model/retrieval-result.ts +0 -35
  206. package/src/core/mongo-sync-config.ts +0 -165
  207. package/src/core/mongo-sync-worker.ts +0 -381
  208. package/src/core/privacy/filter.ts +0 -190
  209. package/src/core/privacy/index.ts +0 -20
  210. package/src/core/privacy/tag-parser.ts +0 -145
  211. package/src/core/product-validation-matrix.ts +0 -314
  212. package/src/core/progressive-retriever.ts +0 -414
  213. package/src/core/registry/project-path.ts +0 -54
  214. package/src/core/registry/session-registry.ts +0 -69
  215. package/src/core/replay-evaluator.ts +0 -625
  216. package/src/core/retrieval-benchmark.ts +0 -117
  217. package/src/core/retrieval-quality.ts +0 -109
  218. package/src/core/retriever.ts +0 -800
  219. package/src/core/session-qrels.ts +0 -360
  220. package/src/core/shared-event-store.ts +0 -114
  221. package/src/core/shared-promoter.ts +0 -249
  222. package/src/core/shared-store.ts +0 -289
  223. package/src/core/shared-vector-store.ts +0 -203
  224. package/src/core/sqlite-event-store.ts +0 -1846
  225. package/src/core/sqlite-wrapper.ts +0 -116
  226. package/src/core/sync-worker.ts +0 -228
  227. package/src/core/tag-taxonomy.ts +0 -51
  228. package/src/core/task/blocker-resolver.ts +0 -333
  229. package/src/core/task/index.ts +0 -9
  230. package/src/core/task/task-matcher.ts +0 -240
  231. package/src/core/task/task-projector.ts +0 -358
  232. package/src/core/task/task-resolver.ts +0 -421
  233. package/src/core/turn-state.ts +0 -207
  234. package/src/core/types.ts +0 -952
  235. package/src/core/vector-outbox.ts +0 -299
  236. package/src/core/vector-store.ts +0 -231
  237. package/src/core/vector-worker.ts +0 -521
  238. package/src/core/working-set-store.ts +0 -257
  239. package/src/extensions/endless-memory/endless-memory-services.ts +0 -350
  240. package/src/extensions/endless-memory/index.ts +0 -1
  241. package/src/extensions/index.ts +0 -5
  242. package/src/extensions/mcp/handlers.ts +0 -960
  243. package/src/extensions/mcp/index.ts +0 -48
  244. package/src/extensions/mcp/tools.ts +0 -252
  245. package/src/extensions/shared-memory/index.ts +0 -1
  246. package/src/extensions/shared-memory/shared-memory-services.ts +0 -211
  247. package/src/extensions/vector/embedder.ts +0 -234
  248. package/src/extensions/vector/index.ts +0 -1
  249. package/src/hooks/post-tool-use.ts +0 -9
  250. package/src/hooks/semantic-daemon-client.ts +0 -1
  251. package/src/hooks/semantic-daemon.ts +0 -11
  252. package/src/hooks/session-end.ts +0 -9
  253. package/src/hooks/session-start.ts +0 -9
  254. package/src/hooks/stop.ts +0 -9
  255. package/src/hooks/user-prompt-submit.ts +0 -9
  256. package/src/index.ts +0 -13
  257. package/src/mcp/handlers.ts +0 -2
  258. package/src/mcp/index.ts +0 -4
  259. package/src/mcp/tools.ts +0 -2
  260. package/src/server/api/chat.ts +0 -2
  261. package/src/server/api/citations.ts +0 -2
  262. package/src/server/api/events.ts +0 -2
  263. package/src/server/api/health.ts +0 -2
  264. package/src/server/api/index.ts +0 -2
  265. package/src/server/api/projects.ts +0 -2
  266. package/src/server/api/search.ts +0 -2
  267. package/src/server/api/sessions.ts +0 -2
  268. package/src/server/api/stats.ts +0 -2
  269. package/src/server/api/turns.ts +0 -2
  270. package/src/server/api/utils.ts +0 -2
  271. package/src/server/index.ts +0 -2
  272. package/src/services/bootstrap-organizer.ts +0 -463
  273. package/src/services/codex-session-history-importer.ts +0 -966
  274. package/src/services/hermes-session-history-importer.ts +0 -733
  275. package/src/services/memory-service-config.ts +0 -36
  276. package/src/services/memory-service-registry.ts +0 -150
  277. package/src/services/memory-service.ts +0 -688
  278. package/src/services/session-history-importer.ts +0 -629
  279. package/tests/README.md +0 -23
  280. package/tests/adapters/claude/claude-semantic-daemon-adapter.test.ts +0 -54
  281. package/tests/adapters/claude/claude-transcript-reconstructor.test.ts +0 -98
  282. package/tests/adapters/claude-hook-prompt-injection-policy.test.ts +0 -99
  283. package/tests/apps/app-layer-boundary.test.ts +0 -48
  284. package/tests/apps/claude-settings-hooks.test.ts +0 -107
  285. package/tests/apps/cli-disclosure-output.test.ts +0 -212
  286. package/tests/apps/codex-import-runner.test.ts +0 -99
  287. package/tests/apps/codex-validation-output.test.ts +0 -100
  288. package/tests/apps/hermes-import-runner.test.ts +0 -99
  289. package/tests/apps/mcp-install-command.test.ts +0 -59
  290. package/tests/apps/package-build-entrypoints.test.ts +0 -30
  291. package/tests/apps/postinstall-embedding-backend.test.ts +0 -185
  292. package/tests/apps/search-api-disclosure.test.ts +0 -162
  293. package/tests/apps/stats-api-lightweight.test.ts +0 -67
  294. package/tests/apps/ui-disclosure-output.test.ts +0 -140
  295. package/tests/core/bootstrap-organizer.test.ts +0 -111
  296. package/tests/core/canonical-key.test.ts +0 -101
  297. package/tests/core/codex-session-history-importer-validation.test.ts +0 -185
  298. package/tests/core/consolidation-worker.test.ts +0 -75
  299. package/tests/core/embedding-maintenance-service.test.ts +0 -282
  300. package/tests/core/evidence-aligner.test.ts +0 -152
  301. package/tests/core/external-market-context.test.ts +0 -209
  302. package/tests/core/fact-deriver.test.ts +0 -79
  303. package/tests/core/hermes-session-history-importer-validation.test.ts +0 -609
  304. package/tests/core/ingest-interceptor.test.ts +0 -38
  305. package/tests/core/markdown-mirror.test.ts +0 -85
  306. package/tests/core/matcher.test.ts +0 -112
  307. package/tests/core/md-mirror.test.ts +0 -50
  308. package/tests/core/memory-engine-services.test.ts +0 -240
  309. package/tests/core/memory-ingest-service.test.ts +0 -296
  310. package/tests/core/memory-query-service.test.ts +0 -129
  311. package/tests/core/memory-runtime-service.test.ts +0 -201
  312. package/tests/core/memory-service-composition.test.ts +0 -192
  313. package/tests/core/memory-service-config.test.ts +0 -41
  314. package/tests/core/memory-service-facade.test.ts +0 -30
  315. package/tests/core/memory-service-registry.test.ts +0 -206
  316. package/tests/core/product-validation-matrix.test.ts +0 -61
  317. package/tests/core/project-registry.test.ts +0 -78
  318. package/tests/core/replay-evaluator.test.ts +0 -181
  319. package/tests/core/retrieval-analytics-service.test.ts +0 -210
  320. package/tests/core/retrieval-benchmark.test.ts +0 -93
  321. package/tests/core/retrieval-disclosure-service.test.ts +0 -264
  322. package/tests/core/retrieval-orchestrator.test.ts +0 -403
  323. package/tests/core/retrieval-quality.test.ts +0 -31
  324. package/tests/core/retrieval-services.test.ts +0 -185
  325. package/tests/core/retriever-fallback-chain.test.ts +0 -223
  326. package/tests/core/retriever-strategy-scope.test.ts +0 -164
  327. package/tests/core/retriever.memu-adoption.test.ts +0 -122
  328. package/tests/core/session-history-importer-filter.test.ts +0 -78
  329. package/tests/core/session-qrels.test.ts +0 -250
  330. package/tests/core/sqlite-event-store-replication.test.ts +0 -127
  331. package/tests/core/summary-deriver.test.ts +0 -66
  332. package/tests/extensions/embedder-warning-suppression.test.ts +0 -84
  333. package/tests/extensions/endless-memory-extension-boundary.test.ts +0 -17
  334. package/tests/extensions/endless-memory-services.test.ts +0 -325
  335. package/tests/extensions/mcp-context-tools.test.ts +0 -905
  336. package/tests/extensions/mcp-extension-boundary.test.ts +0 -21
  337. package/tests/extensions/mcp-package-build.test.ts +0 -22
  338. package/tests/extensions/mcp-project-aware-tools.test.ts +0 -102
  339. package/tests/extensions/shared-memory-extension-boundary.test.ts +0 -24
  340. package/tests/extensions/shared-memory-services.test.ts +0 -309
  341. package/tests/extensions/vector-extension-boundary.test.ts +0 -21
  342. package/tsconfig.json +0 -24
  343. package/vitest.config.ts +0 -15
package/src/core/types.ts DELETED
@@ -1,952 +0,0 @@
1
- /**
2
- * Core types for claude-memory-layer plugin
3
- * Idris2 inspired: Complete, immutable type definitions with Zod validation
4
- */
5
-
6
- import { z } from 'zod';
7
-
8
- // ============================================================
9
- // Event Types
10
- // ============================================================
11
-
12
- export const EventTypeSchema = z.enum([
13
- 'user_prompt',
14
- 'agent_response',
15
- 'session_summary',
16
- 'tool_observation'
17
- ]);
18
- export type EventType = z.infer<typeof EventTypeSchema>;
19
-
20
- // ============================================================
21
- // Memory Event (L0 EventStore)
22
- // ============================================================
23
-
24
- export const MemoryEventSchema = z.object({
25
- id: z.string().uuid(),
26
- eventType: EventTypeSchema,
27
- sessionId: z.string(),
28
- timestamp: z.date(),
29
- content: z.string(),
30
- canonicalKey: z.string(),
31
- dedupeKey: z.string(),
32
- metadata: z.record(z.unknown()).optional()
33
- });
34
- export type MemoryEvent = z.infer<typeof MemoryEventSchema>;
35
-
36
- // Input for creating new events (id, dedupeKey generated automatically)
37
- export const MemoryEventInputSchema = MemoryEventSchema.omit({
38
- id: true,
39
- dedupeKey: true,
40
- canonicalKey: true
41
- });
42
- export type MemoryEventInput = z.infer<typeof MemoryEventInputSchema>;
43
-
44
- // ============================================================
45
- // Session
46
- // ============================================================
47
-
48
- export const SessionSchema = z.object({
49
- id: z.string(),
50
- startedAt: z.date(),
51
- endedAt: z.date().optional(),
52
- projectPath: z.string().optional(),
53
- summary: z.string().optional(),
54
- tags: z.array(z.string()).optional()
55
- });
56
- export type Session = z.infer<typeof SessionSchema>;
57
-
58
- // ============================================================
59
- // Insight (L1 Structured)
60
- // ============================================================
61
-
62
- export const InsightTypeSchema = z.enum([
63
- 'preference',
64
- 'pattern',
65
- 'expertise'
66
- ]);
67
- export type InsightType = z.infer<typeof InsightTypeSchema>;
68
-
69
- export const InsightSchema = z.object({
70
- id: z.string().uuid(),
71
- insightType: InsightTypeSchema,
72
- content: z.string(),
73
- canonicalKey: z.string(),
74
- confidence: z.number().min(0).max(1),
75
- sourceEvents: z.array(z.string().uuid()),
76
- createdAt: z.date(),
77
- lastUpdated: z.date()
78
- });
79
- export type Insight = z.infer<typeof InsightSchema>;
80
-
81
- // ============================================================
82
- // Memory Match (Search Result)
83
- // ============================================================
84
-
85
- export const MemoryMatchSchema = z.object({
86
- event: MemoryEventSchema,
87
- score: z.number().min(0).max(1),
88
- relevanceReason: z.string().optional()
89
- });
90
- export type MemoryMatch = z.infer<typeof MemoryMatchSchema>;
91
-
92
- // ============================================================
93
- // Match Confidence (AXIOMMIND)
94
- // ============================================================
95
-
96
- export const MatchConfidenceSchema = z.enum(['high', 'suggested', 'none']);
97
- export type MatchConfidence = z.infer<typeof MatchConfidenceSchema>;
98
-
99
- export const MatchResultSchema = z.object({
100
- match: MemoryMatchSchema.nullable(),
101
- confidence: MatchConfidenceSchema,
102
- gap: z.number().optional(),
103
- alternatives: z.array(MemoryMatchSchema).optional()
104
- });
105
- export type MatchResult = z.infer<typeof MatchResultSchema>;
106
-
107
- // AXIOMMIND Matching Thresholds
108
- export const MATCH_THRESHOLDS = {
109
- minCombinedScore: 0.92,
110
- minGap: 0.03,
111
- suggestionThreshold: 0.75
112
- } as const;
113
-
114
- // ============================================================
115
- // Memory Level (Graduation Pipeline)
116
- // ============================================================
117
-
118
- export const MemoryLevelSchema = z.enum(['L0', 'L1', 'L2', 'L3', 'L4']);
119
- export type MemoryLevel = z.infer<typeof MemoryLevelSchema>;
120
-
121
- export const GraduationResultSchema = z.object({
122
- eventId: z.string().uuid(),
123
- fromLevel: MemoryLevelSchema,
124
- toLevel: MemoryLevelSchema,
125
- success: z.boolean(),
126
- reason: z.string().optional()
127
- });
128
- export type GraduationResult = z.infer<typeof GraduationResultSchema>;
129
-
130
- // ============================================================
131
- // Evidence Span (AXIOMMIND Principle 4)
132
- // ============================================================
133
-
134
- export const EvidenceSpanSchema = z.object({
135
- start: z.number().int().nonnegative(),
136
- end: z.number().int().positive(),
137
- confidence: z.number().min(0).max(1),
138
- matchType: z.enum(['exact', 'fuzzy', 'none']),
139
- originalQuote: z.string(),
140
- alignedText: z.string()
141
- });
142
- export type EvidenceSpan = z.infer<typeof EvidenceSpanSchema>;
143
-
144
- // ============================================================
145
- // Configuration
146
- // ============================================================
147
-
148
- export const ConfigSchema = z.object({
149
- storage: z.object({
150
- path: z.string().default('~/.claude-code/memory'),
151
- maxSizeMB: z.number().default(500)
152
- }).default({}),
153
- embedding: z.object({
154
- provider: z.enum(['local', 'openai']).default('local'),
155
- model: z.string().default('Xenova/multilingual-e5-small'),
156
- openaiModel: z.string().default('Xenova/multilingual-e5-small'),
157
- batchSize: z.number().default(32)
158
- }).default({}),
159
- retrieval: z.object({
160
- topK: z.number().default(5),
161
- minScore: z.number().default(0.7),
162
- maxTokens: z.number().default(2000)
163
- }).default({}),
164
- matching: z.object({
165
- minCombinedScore: z.number().default(0.92),
166
- minGap: z.number().default(0.03),
167
- suggestionThreshold: z.number().default(0.75),
168
- weights: z.object({
169
- semanticSimilarity: z.number().default(0.4),
170
- ftsScore: z.number().default(0.25),
171
- recencyBonus: z.number().default(0.2),
172
- statusWeight: z.number().default(0.15)
173
- }).default({})
174
- }).default({}),
175
- privacy: z.object({
176
- excludePatterns: z.array(z.string()).default(['password', 'secret', 'api_key', 'token', 'bearer']),
177
- anonymize: z.boolean().default(false),
178
- privateTags: z.object({
179
- enabled: z.boolean().default(true),
180
- marker: z.enum(['[PRIVATE]', '[REDACTED]', '']).default('[PRIVATE]'),
181
- preserveLineCount: z.boolean().default(false),
182
- supportedFormats: z.array(z.enum(['xml', 'bracket', 'comment'])).default(['xml'])
183
- }).default({})
184
- }).default({}),
185
- toolObservation: z.object({
186
- enabled: z.boolean().default(true),
187
- excludedTools: z.array(z.string()).default(['TodoWrite', 'TodoRead']),
188
- minOutputLength: z.number().default(100),
189
- maxOutputLength: z.number().default(10000),
190
- maxOutputLines: z.number().default(100),
191
- storeOnlyOnSuccess: z.boolean().default(false)
192
- }).default({}),
193
- features: z.object({
194
- autoSave: z.boolean().default(true),
195
- sessionSummary: z.boolean().default(true),
196
- insightExtraction: z.boolean().default(true),
197
- crossProjectLearning: z.boolean().default(false),
198
- singleWriterMode: z.boolean().default(true),
199
- sharedStore: z.object({
200
- enabled: z.boolean().default(true),
201
- autoPromote: z.boolean().default(true),
202
- searchShared: z.boolean().default(true),
203
- minConfidenceForPromotion: z.number().default(0.8),
204
- sharedStoragePath: z.string().default('~/.claude-code/memory/shared')
205
- }).default({})
206
- }).default({}),
207
- mode: z.enum(['session', 'endless']).default('session'),
208
- endless: z.object({
209
- enabled: z.boolean().default(false),
210
- workingSet: z.object({
211
- maxEvents: z.number().default(100),
212
- timeWindowHours: z.number().default(24),
213
- minRelevanceScore: z.number().default(0.5)
214
- }).default({}),
215
- consolidation: z.object({
216
- triggerIntervalMs: z.number().default(3600000),
217
- triggerEventCount: z.number().default(100),
218
- triggerIdleMs: z.number().default(1800000),
219
- useLLMSummarization: z.boolean().default(false)
220
- }).default({}),
221
- continuity: z.object({
222
- minScoreForSeamless: z.number().default(0.7),
223
- topicDecayHours: z.number().default(48)
224
- }).default({})
225
- }).optional()
226
- });
227
- export type Config = z.infer<typeof ConfigSchema>;
228
-
229
- // ============================================================
230
- // Append Result (AXIOMMIND Principle 2: Append-only)
231
- // ============================================================
232
-
233
- export type AppendResult =
234
- | { success: true; eventId: string; isDuplicate: false }
235
- | { success: true; eventId: string; isDuplicate: true }
236
- | { success: false; error: string };
237
-
238
- // ============================================================
239
- // Hook Input/Output Types
240
- // ============================================================
241
-
242
- export interface SessionStartInput {
243
- session_id: string;
244
- cwd: string;
245
- }
246
-
247
- export interface SessionStartOutput {
248
- context?: string;
249
- }
250
-
251
- export interface UserPromptSubmitInput {
252
- session_id: string;
253
- prompt: string;
254
- }
255
-
256
- export interface UserPromptSubmitOutput {
257
- context?: string;
258
- }
259
-
260
- // Stop Hook Input (matches actual Claude Code hook format)
261
- export interface StopInput {
262
- session_id: string;
263
- transcript_path: string;
264
- cwd: string;
265
- permission_mode: string;
266
- hook_event_name: string;
267
- stop_hook_active: boolean;
268
- }
269
-
270
- export interface SessionEndInput {
271
- session_id: string;
272
- }
273
-
274
- // PostToolUse Hook Input (matches actual Claude Code hook format)
275
- export interface PostToolUseInput {
276
- session_id: string;
277
- hook_event_name: string;
278
- tool_name: string;
279
- tool_input: Record<string, unknown>;
280
- tool_use_id: string;
281
- // Claude Code sends tool_response as an object, not tool_output as string
282
- tool_response: {
283
- stdout?: string;
284
- stderr?: string;
285
- content?: string;
286
- interrupted?: boolean;
287
- isImage?: boolean;
288
- // For non-Bash tools, response may be a plain string or other format
289
- [key: string]: unknown;
290
- };
291
- cwd: string;
292
- transcript_path: string;
293
- permission_mode: string;
294
- }
295
-
296
- // ============================================================
297
- // Tool Observation Types
298
- // ============================================================
299
-
300
- export const ToolMetadataSchema = z.object({
301
- filePath: z.string().optional(),
302
- fileType: z.string().optional(),
303
- lineCount: z.number().optional(),
304
- command: z.string().optional(),
305
- exitCode: z.number().optional(),
306
- pattern: z.string().optional(),
307
- matchCount: z.number().optional(),
308
- url: z.string().optional(),
309
- statusCode: z.number().optional()
310
- });
311
- export type ToolMetadata = z.infer<typeof ToolMetadataSchema>;
312
-
313
- export const ToolObservationPayloadSchema = z.object({
314
- toolName: z.string(),
315
- toolInput: z.record(z.unknown()),
316
- toolOutput: z.string(),
317
- durationMs: z.number(),
318
- success: z.boolean(),
319
- errorMessage: z.string().optional(),
320
- metadata: ToolMetadataSchema.optional()
321
- });
322
- export type ToolObservationPayload = z.infer<typeof ToolObservationPayloadSchema>;
323
-
324
- // ============================================================
325
- // Vector Record
326
- // ============================================================
327
-
328
- export interface VectorRecord {
329
- id: string;
330
- eventId: string;
331
- sessionId: string;
332
- eventType: string;
333
- content: string;
334
- vector: number[];
335
- timestamp: string;
336
- metadata?: Record<string, unknown>;
337
- }
338
-
339
- // ============================================================
340
- // Outbox Item (Single-Writer Pattern)
341
- // ============================================================
342
-
343
- export interface OutboxItem {
344
- id: string;
345
- eventId: string;
346
- content: string;
347
- status: 'pending' | 'processing' | 'done' | 'failed';
348
- retryCount: number;
349
- createdAt: Date;
350
- errorMessage?: string;
351
- }
352
-
353
- // ============================================================
354
- // Entity Types (Task, Condition, Artifact)
355
- // ============================================================
356
-
357
- export const EntityTypeSchema = z.enum(['task', 'condition', 'artifact']);
358
- export type EntityType = z.infer<typeof EntityTypeSchema>;
359
-
360
- export const TaskStatusSchema = z.enum([
361
- 'pending',
362
- 'in_progress',
363
- 'blocked',
364
- 'done',
365
- 'cancelled'
366
- ]);
367
- export type TaskStatus = z.infer<typeof TaskStatusSchema>;
368
-
369
- export const TaskPrioritySchema = z.enum(['low', 'medium', 'high', 'critical']);
370
- export type TaskPriority = z.infer<typeof TaskPrioritySchema>;
371
-
372
- export const EntityStageSchema = z.enum([
373
- 'raw',
374
- 'working',
375
- 'candidate',
376
- 'verified',
377
- 'certified'
378
- ]);
379
- export type EntityStage = z.infer<typeof EntityStageSchema>;
380
-
381
- export const EntityStatusSchema = z.enum([
382
- 'active',
383
- 'contested',
384
- 'deprecated',
385
- 'superseded'
386
- ]);
387
- export type EntityStatus = z.infer<typeof EntityStatusSchema>;
388
-
389
- // Base Entity schema
390
- export const EntitySchema = z.object({
391
- entityId: z.string(),
392
- entityType: EntityTypeSchema,
393
- canonicalKey: z.string(),
394
- title: z.string(),
395
- stage: EntityStageSchema,
396
- status: EntityStatusSchema,
397
- currentJson: z.record(z.unknown()),
398
- titleNorm: z.string().optional(),
399
- searchText: z.string().optional(),
400
- createdAt: z.date(),
401
- updatedAt: z.date()
402
- });
403
- export type Entity = z.infer<typeof EntitySchema>;
404
-
405
- // Task-specific current_json structure
406
- export const TaskCurrentJsonSchema = z.object({
407
- status: TaskStatusSchema,
408
- priority: TaskPrioritySchema.optional(),
409
- blockers: z.array(z.string()).optional(),
410
- blockerSuggestions: z.array(z.string()).optional(),
411
- description: z.string().optional(),
412
- project: z.string().optional()
413
- });
414
- export type TaskCurrentJson = z.infer<typeof TaskCurrentJsonSchema>;
415
-
416
- // Entity alias for canonical key lookup
417
- export const EntityAliasSchema = z.object({
418
- entityType: EntityTypeSchema,
419
- canonicalKey: z.string(),
420
- entityId: z.string(),
421
- isPrimary: z.boolean()
422
- });
423
- export type EntityAlias = z.infer<typeof EntityAliasSchema>;
424
-
425
- // ============================================================
426
- // Edge Types (Relationships)
427
- // ============================================================
428
-
429
- export const NodeTypeSchema = z.enum(['entry', 'entity', 'event']);
430
- export type NodeType = z.infer<typeof NodeTypeSchema>;
431
-
432
- export const RelationTypeSchema = z.enum([
433
- 'evidence_of',
434
- 'blocked_by',
435
- 'blocked_by_suggested',
436
- 'resolves_to',
437
- 'derived_from',
438
- 'supersedes',
439
- 'source_of'
440
- ]);
441
- export type RelationType = z.infer<typeof RelationTypeSchema>;
442
-
443
- export const EdgeSchema = z.object({
444
- edgeId: z.string(),
445
- srcType: NodeTypeSchema,
446
- srcId: z.string(),
447
- relType: RelationTypeSchema,
448
- dstType: NodeTypeSchema,
449
- dstId: z.string(),
450
- metaJson: z.record(z.unknown()).optional(),
451
- createdAt: z.date()
452
- });
453
- export type Edge = z.infer<typeof EdgeSchema>;
454
-
455
- // ============================================================
456
- // Task Event Types (SoT for Task Entity)
457
- // ============================================================
458
-
459
- export const TaskEventTypeSchema = z.enum([
460
- 'task_created',
461
- 'task_status_changed',
462
- 'task_priority_changed',
463
- 'task_blockers_set',
464
- 'task_transition_rejected',
465
- 'condition_declared',
466
- 'artifact_declared',
467
- 'condition_resolved_to'
468
- ]);
469
- export type TaskEventType = z.infer<typeof TaskEventTypeSchema>;
470
-
471
- export const BlockerModeSchema = z.enum(['replace', 'suggest']);
472
- export type BlockerMode = z.infer<typeof BlockerModeSchema>;
473
-
474
- export const BlockerKindSchema = z.enum(['task', 'condition', 'artifact']);
475
- export type BlockerKind = z.infer<typeof BlockerKindSchema>;
476
-
477
- export const BlockerRefSchema = z.object({
478
- kind: BlockerKindSchema,
479
- entityId: z.string(),
480
- rawText: z.string().optional(),
481
- confidence: z.number().min(0).max(1).optional(),
482
- candidates: z.array(z.string()).optional()
483
- });
484
- export type BlockerRef = z.infer<typeof BlockerRefSchema>;
485
-
486
- // Task event payloads
487
- export const TaskCreatedPayloadSchema = z.object({
488
- taskId: z.string(),
489
- title: z.string(),
490
- canonicalKey: z.string(),
491
- initialStatus: TaskStatusSchema,
492
- priority: TaskPrioritySchema.optional(),
493
- description: z.string().optional(),
494
- project: z.string().optional()
495
- });
496
- export type TaskCreatedPayload = z.infer<typeof TaskCreatedPayloadSchema>;
497
-
498
- export const TaskStatusChangedPayloadSchema = z.object({
499
- taskId: z.string(),
500
- fromStatus: TaskStatusSchema,
501
- toStatus: TaskStatusSchema,
502
- reason: z.string().optional()
503
- });
504
- export type TaskStatusChangedPayload = z.infer<typeof TaskStatusChangedPayloadSchema>;
505
-
506
- export const TaskBlockersSetPayloadSchema = z.object({
507
- taskId: z.string(),
508
- mode: BlockerModeSchema,
509
- blockers: z.array(BlockerRefSchema),
510
- sourceEntryId: z.string().optional()
511
- });
512
- export type TaskBlockersSetPayload = z.infer<typeof TaskBlockersSetPayloadSchema>;
513
-
514
- // ============================================================
515
- // Entry Types (Immutable memory units)
516
- // ============================================================
517
-
518
- export const EntryTypeSchema = z.enum([
519
- 'fact',
520
- 'decision',
521
- 'insight',
522
- 'task_note',
523
- 'reference',
524
- 'preference',
525
- 'pattern',
526
- 'troubleshooting'
527
- ]);
528
- export type EntryType = z.infer<typeof EntryTypeSchema>;
529
-
530
- export const EntrySchema = z.object({
531
- entryId: z.string(),
532
- createdTs: z.date(),
533
- entryType: EntryTypeSchema,
534
- title: z.string(),
535
- contentJson: z.record(z.unknown()),
536
- stage: EntityStageSchema,
537
- status: EntityStatusSchema,
538
- supersededBy: z.string().optional(),
539
- buildId: z.string().optional(),
540
- evidenceJson: z.record(z.unknown()).optional(),
541
- canonicalKey: z.string()
542
- });
543
- export type Entry = z.infer<typeof EntrySchema>;
544
-
545
- // ============================================================
546
- // Evidence Aligner V2 Types
547
- // ============================================================
548
-
549
- export const ExtractedEvidenceSchema = z.object({
550
- messageIndex: z.number().int().nonnegative(),
551
- quote: z.string()
552
- });
553
- export type ExtractedEvidence = z.infer<typeof ExtractedEvidenceSchema>;
554
-
555
- export const AlignedEvidenceSchema = z.object({
556
- messageIndex: z.number().int().nonnegative(),
557
- quote: z.string(),
558
- spanStart: z.number().int().nonnegative(),
559
- spanEnd: z.number().int().positive(),
560
- quoteHash: z.string(),
561
- confidence: z.number().min(0).max(1),
562
- matchMethod: z.enum(['exact', 'normalized', 'fuzzy'])
563
- });
564
- export type AlignedEvidence = z.infer<typeof AlignedEvidenceSchema>;
565
-
566
- export const FailedEvidenceSchema = z.object({
567
- messageIndex: z.number().int().nonnegative(),
568
- quote: z.string(),
569
- failureReason: z.enum(['not_found', 'below_threshold', 'ambiguous', 'empty_quote', 'invalid_index'])
570
- });
571
- export type FailedEvidence = z.infer<typeof FailedEvidenceSchema>;
572
-
573
- export const EvidenceAlignResultSchema = z.discriminatedUnion('aligned', [
574
- z.object({ aligned: z.literal(true), evidence: AlignedEvidenceSchema }),
575
- z.object({ aligned: z.literal(false), evidence: FailedEvidenceSchema })
576
- ]);
577
- export type EvidenceAlignResult = z.infer<typeof EvidenceAlignResultSchema>;
578
-
579
- // ============================================================
580
- // Vector Outbox V2 Types
581
- // ============================================================
582
-
583
- export const OutboxStatusSchema = z.enum(['pending', 'processing', 'done', 'failed']);
584
- export type OutboxStatus = z.infer<typeof OutboxStatusSchema>;
585
-
586
- export const OutboxItemKindSchema = z.enum(['entry', 'task_title', 'event']);
587
- export type OutboxItemKind = z.infer<typeof OutboxItemKindSchema>;
588
-
589
- export const OutboxJobSchema = z.object({
590
- jobId: z.string(),
591
- itemKind: OutboxItemKindSchema,
592
- itemId: z.string(),
593
- embeddingVersion: z.string(),
594
- status: OutboxStatusSchema,
595
- retryCount: z.number().int().nonnegative(),
596
- error: z.string().optional(),
597
- createdAt: z.date(),
598
- updatedAt: z.date()
599
- });
600
- export type OutboxJob = z.infer<typeof OutboxJobSchema>;
601
-
602
- // Valid state transitions for outbox
603
- export const VALID_OUTBOX_TRANSITIONS: Array<{ from: OutboxStatus; to: OutboxStatus }> = [
604
- { from: 'pending', to: 'processing' },
605
- { from: 'processing', to: 'done' },
606
- { from: 'processing', to: 'failed' },
607
- { from: 'failed', to: 'pending' }
608
- ];
609
-
610
- // ============================================================
611
- // Build Runs (Pipeline metadata)
612
- // ============================================================
613
-
614
- export const BuildRunSchema = z.object({
615
- buildId: z.string(),
616
- startedAt: z.date(),
617
- finishedAt: z.date().optional(),
618
- extractorModel: z.string(),
619
- extractorPromptHash: z.string(),
620
- embedderModel: z.string(),
621
- embeddingVersion: z.string(),
622
- idrisVersion: z.string(),
623
- schemaVersion: z.string(),
624
- status: z.enum(['running', 'success', 'failed']),
625
- error: z.string().optional()
626
- });
627
- export type BuildRun = z.infer<typeof BuildRunSchema>;
628
-
629
- // ============================================================
630
- // Pipeline Metrics
631
- // ============================================================
632
-
633
- export const PipelineMetricSchema = z.object({
634
- id: z.string(),
635
- ts: z.date(),
636
- stage: z.string(),
637
- latencyMs: z.number(),
638
- success: z.boolean(),
639
- error: z.string().optional(),
640
- sessionId: z.string().optional()
641
- });
642
- export type PipelineMetric = z.infer<typeof PipelineMetricSchema>;
643
-
644
- // ============================================================
645
- // Progressive Disclosure Types
646
- // ============================================================
647
-
648
- // Layer 1: Search Index (lightweight)
649
- export const SearchIndexItemSchema = z.object({
650
- id: z.string(),
651
- summary: z.string().max(100),
652
- score: z.number(),
653
- type: z.enum(['user_prompt', 'agent_response', 'session_summary', 'tool_observation']),
654
- timestamp: z.date(),
655
- sessionId: z.string()
656
- });
657
- export type SearchIndexItem = z.infer<typeof SearchIndexItemSchema>;
658
-
659
- // Layer 2: Timeline
660
- export const TimelineItemSchema = z.object({
661
- id: z.string(),
662
- timestamp: z.date(),
663
- type: z.enum(['user_prompt', 'agent_response', 'session_summary', 'tool_observation']),
664
- preview: z.string().max(200),
665
- isTarget: z.boolean()
666
- });
667
- export type TimelineItem = z.infer<typeof TimelineItemSchema>;
668
-
669
- // Layer 3: Full Detail
670
- export const FullDetailSchema = z.object({
671
- id: z.string(),
672
- content: z.string(),
673
- type: z.enum(['user_prompt', 'agent_response', 'session_summary', 'tool_observation']),
674
- timestamp: z.date(),
675
- sessionId: z.string(),
676
- citationId: z.string().optional(),
677
- metadata: z.object({
678
- tokenCount: z.number(),
679
- hasCode: z.boolean(),
680
- files: z.array(z.string()).optional(),
681
- tools: z.array(z.string()).optional()
682
- })
683
- });
684
- export type FullDetail = z.infer<typeof FullDetailSchema>;
685
-
686
- // Progressive Search Result
687
- export const ProgressiveSearchResultSchema = z.object({
688
- index: z.array(SearchIndexItemSchema),
689
- timeline: z.array(TimelineItemSchema).optional(),
690
- details: z.array(FullDetailSchema).optional(),
691
- meta: z.object({
692
- totalMatches: z.number(),
693
- expandedCount: z.number(),
694
- estimatedTokens: z.number(),
695
- expansionReason: z.string().optional()
696
- })
697
- });
698
- export type ProgressiveSearchResult = z.infer<typeof ProgressiveSearchResultSchema>;
699
-
700
- // Progressive Disclosure Config
701
- export const ProgressiveDisclosureConfigSchema = z.object({
702
- enabled: z.boolean().default(true),
703
- layer1: z.object({
704
- topK: z.number().default(10),
705
- minScore: z.number().default(0.7)
706
- }).default({}),
707
- autoExpand: z.object({
708
- enabled: z.boolean().default(true),
709
- highConfidenceThreshold: z.number().default(0.92),
710
- scoreGapThreshold: z.number().default(0.1),
711
- maxAutoExpandCount: z.number().default(3)
712
- }).default({}),
713
- tokenBudget: z.object({
714
- maxTotalTokens: z.number().default(2000),
715
- layer1PerItem: z.number().default(50),
716
- layer2PerItem: z.number().default(40),
717
- layer3PerItem: z.number().default(500)
718
- }).default({})
719
- });
720
- export type ProgressiveDisclosureConfig = z.infer<typeof ProgressiveDisclosureConfigSchema>;
721
-
722
- // ============================================================
723
- // Citation Types
724
- // ============================================================
725
-
726
- export const CitationSchema = z.object({
727
- citationId: z.string().length(6),
728
- eventId: z.string(),
729
- createdAt: z.date()
730
- });
731
- export type Citation = z.infer<typeof CitationSchema>;
732
-
733
- export const CitationUsageSchema = z.object({
734
- usageId: z.string(),
735
- citationId: z.string(),
736
- sessionId: z.string(),
737
- usedAt: z.date(),
738
- context: z.string().optional()
739
- });
740
- export type CitationUsage = z.infer<typeof CitationUsageSchema>;
741
-
742
- export interface CitedSearchResult {
743
- event: MemoryEvent;
744
- citation: Citation;
745
- score: number;
746
- }
747
-
748
- export interface CitationStats {
749
- usageCount: number;
750
- lastUsed: Date | null;
751
- }
752
-
753
- // ============================================================
754
- // Endless Mode Types
755
- // ============================================================
756
-
757
- export const MemoryModeSchema = z.enum(['session', 'endless']);
758
- export type MemoryMode = z.infer<typeof MemoryModeSchema>;
759
-
760
- export const EndlessModeConfigSchema = z.object({
761
- enabled: z.boolean().default(false),
762
-
763
- workingSet: z.object({
764
- maxEvents: z.number().default(100),
765
- timeWindowHours: z.number().default(24),
766
- minRelevanceScore: z.number().default(0.5)
767
- }).default({}),
768
-
769
- consolidation: z.object({
770
- triggerIntervalMs: z.number().default(3600000), // 1 hour
771
- triggerEventCount: z.number().default(100),
772
- triggerIdleMs: z.number().default(1800000), // 30 minutes
773
- useLLMSummarization: z.boolean().default(false)
774
- }).default({}),
775
-
776
- continuity: z.object({
777
- minScoreForSeamless: z.number().default(0.7),
778
- topicDecayHours: z.number().default(48)
779
- }).default({})
780
- });
781
- export type EndlessModeConfig = z.infer<typeof EndlessModeConfigSchema>;
782
-
783
- // Working Set Item
784
- export const WorkingSetItemSchema = z.object({
785
- id: z.string(),
786
- eventId: z.string(),
787
- addedAt: z.date(),
788
- relevanceScore: z.number(),
789
- topics: z.array(z.string()).optional(),
790
- expiresAt: z.date()
791
- });
792
- export type WorkingSetItem = z.infer<typeof WorkingSetItemSchema>;
793
-
794
- // Working Set
795
- export interface WorkingSet {
796
- recentEvents: MemoryEvent[];
797
- lastActivity: Date;
798
- continuityScore: number;
799
- }
800
-
801
- // Consolidated Memory
802
- export const ConsolidatedMemorySchema = z.object({
803
- memoryId: z.string(),
804
- summary: z.string(),
805
- topics: z.array(z.string()),
806
- sourceEvents: z.array(z.string()),
807
- confidence: z.number(),
808
- createdAt: z.date(),
809
- accessedAt: z.date().optional(),
810
- accessCount: z.number().default(0)
811
- });
812
- export type ConsolidatedMemory = z.infer<typeof ConsolidatedMemorySchema>;
813
-
814
- // Consolidated Memory Input (for creation)
815
- export interface ConsolidatedMemoryInput {
816
- summary: string;
817
- topics: string[];
818
- sourceEvents: string[];
819
- confidence: number;
820
- }
821
-
822
- // Long-term Rule (promoted from stable summaries)
823
- export const ConsolidationRuleSchema = z.object({
824
- ruleId: z.string(),
825
- rule: z.string(),
826
- topics: z.array(z.string()),
827
- sourceMemoryIds: z.array(z.string()),
828
- sourceEvents: z.array(z.string()),
829
- confidence: z.number(),
830
- createdAt: z.date()
831
- });
832
- export type ConsolidationRule = z.infer<typeof ConsolidationRuleSchema>;
833
-
834
- export interface ConsolidationRuleInput {
835
- rule: string;
836
- topics: string[];
837
- sourceMemoryIds: string[];
838
- sourceEvents: string[];
839
- confidence: number;
840
- }
841
-
842
- export interface ConsolidationCostQualityReport {
843
- beforeTokenEstimate: number;
844
- afterTokenEstimate: number;
845
- reductionRatio: number;
846
- qualityGuardPassed: boolean;
847
- details: string;
848
- }
849
-
850
- // Event Group (for consolidation)
851
- export interface EventGroup {
852
- topics: string[];
853
- events: MemoryEvent[];
854
- }
855
-
856
- // Context Snapshot (for continuity calculation)
857
- export interface ContextSnapshot {
858
- id: string;
859
- timestamp: number;
860
- topics: string[];
861
- files: string[];
862
- entities: string[];
863
- }
864
-
865
- // Transition Type
866
- export const TransitionTypeSchema = z.enum(['seamless', 'topic_shift', 'break']);
867
- export type TransitionType = z.infer<typeof TransitionTypeSchema>;
868
-
869
- // Continuity Score Result
870
- export interface ContinuityScore {
871
- score: number;
872
- transitionType: TransitionType;
873
- }
874
-
875
- // Continuity Log
876
- export const ContinuityLogSchema = z.object({
877
- logId: z.string(),
878
- fromContextId: z.string().optional(),
879
- toContextId: z.string().optional(),
880
- continuityScore: z.number(),
881
- transitionType: TransitionTypeSchema,
882
- createdAt: z.date()
883
- });
884
- export type ContinuityLog = z.infer<typeof ContinuityLogSchema>;
885
-
886
- // Endless Mode Status
887
- export interface EndlessModeStatus {
888
- mode: MemoryMode;
889
- workingSetSize: number;
890
- continuityScore: number;
891
- consolidatedCount: number;
892
- lastConsolidation: Date | null;
893
- }
894
-
895
- // ============================================================
896
- // Shared Store Types (Cross-Project Knowledge)
897
- // ============================================================
898
-
899
- export const SharedEntryTypeSchema = z.enum([
900
- 'troubleshooting',
901
- 'best_practice',
902
- 'common_error'
903
- ]);
904
- export type SharedEntryType = z.infer<typeof SharedEntryTypeSchema>;
905
-
906
- export const SharedTroubleshootingEntrySchema = z.object({
907
- entryId: z.string(),
908
- sourceProjectHash: z.string(),
909
- sourceEntryId: z.string(),
910
- title: z.string(),
911
- symptoms: z.array(z.string()),
912
- rootCause: z.string(),
913
- solution: z.string(),
914
- topics: z.array(z.string()),
915
- technologies: z.array(z.string()).optional(),
916
- confidence: z.number().min(0).max(1),
917
- usageCount: z.number().default(0),
918
- lastUsedAt: z.date().optional(),
919
- promotedAt: z.date(),
920
- createdAt: z.date()
921
- });
922
- export type SharedTroubleshootingEntry = z.infer<typeof SharedTroubleshootingEntrySchema>;
923
-
924
- export interface SharedTroubleshootingInput {
925
- sourceProjectHash: string;
926
- sourceEntryId: string;
927
- title: string;
928
- symptoms: string[];
929
- rootCause: string;
930
- solution: string;
931
- topics: string[];
932
- technologies?: string[];
933
- confidence: number;
934
- }
935
-
936
- export const SharedStoreConfigSchema = z.object({
937
- enabled: z.boolean().default(true),
938
- autoPromote: z.boolean().default(true),
939
- searchShared: z.boolean().default(true),
940
- minConfidenceForPromotion: z.number().default(0.8),
941
- sharedStoragePath: z.string().default('~/.claude-code/memory/shared')
942
- });
943
- export type SharedStoreConfig = z.infer<typeof SharedStoreConfigSchema>;
944
-
945
- // Shared search result
946
- export interface SharedSearchResult {
947
- id: string;
948
- entryId: string;
949
- content: string;
950
- score: number;
951
- entryType: SharedEntryType;
952
- }