claude-memory-layer 1.0.31 → 1.0.32

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 (313) hide show
  1. package/README.md +9 -2
  2. package/dist/cli/index.js +1 -1
  3. package/package.json +11 -2
  4. package/scripts/postinstall-embedding-backend.cjs +16 -12
  5. package/AGENTS.md +0 -71
  6. package/CLAUDE.md +0 -30
  7. package/HANDOFF.md +0 -92
  8. package/Memo.txt +0 -558
  9. package/benchmarks/replay/anonymized-real-sessions.json +0 -48
  10. package/config/kpi-thresholds.json +0 -7
  11. package/context.md +0 -636
  12. package/docs/ARCHITECTURE_COMPARISON_AND_RECOMMENDATIONS.md +0 -627
  13. package/docs/HERMES_MEMORY_INGESTION_ANALYSIS.md +0 -440
  14. package/docs/MCP_MEMORY_SERVICE_COMPARATIVE_REVIEW.md +0 -271
  15. package/docs/MEMORY_USEFULNESS_AUDIT.md +0 -371
  16. package/docs/MEMORY_USEFULNESS_AUDIT_RAW.json +0 -80
  17. package/docs/MEMSEARCH_PROJECT_STRUCTURE_ANALYSIS.md +0 -333
  18. package/docs/MEMU_ADOPTION.md +0 -40
  19. package/docs/OPERATIONS.md +0 -18
  20. package/docs/PRODUCT_VALIDATION_MATRIX.md +0 -82
  21. package/docs/PROJECT_STRUCTURE_ANALYSIS.md +0 -421
  22. package/docs/REFACTORING_MILESTONES_AND_ISSUES.md +0 -501
  23. package/docs/REFACTORING_PLAN_THIN_CORE.md +0 -414
  24. package/docs/REFERENCE_PROJECT_ANALYSES.md +0 -25
  25. package/docs/SUPERLOCALMEMORY_PROJECT_STRUCTURE_ANALYSIS.md +0 -452
  26. package/docs/TARGET_ARCHITECTURE_AND_FOLDER_STRUCTURE.md +0 -446
  27. package/docs/architecture/comparison-index.md +0 -47
  28. package/docs/reports/codex-real-data-validation-20260505T040447Z.md +0 -46
  29. package/plan.md +0 -1642
  30. package/scripts/build.ts +0 -159
  31. package/scripts/bump-patch-version.sh +0 -18
  32. package/scripts/delete-unknown-projects.js +0 -154
  33. package/scripts/fix-sync-gap.js +0 -32
  34. package/scripts/generate-session-qrels.ts +0 -126
  35. package/scripts/heartbeat-memory-orchestrator.sh +0 -28
  36. package/scripts/replay-retrieval-benchmark.ts +0 -69
  37. package/scripts/report-sync-gap.js +0 -26
  38. package/scripts/review-queue-auto-resolve.js +0 -21
  39. package/scripts/sync-gap-auto-heal.sh +0 -17
  40. package/spec.md +0 -624
  41. package/specs/20260207-dashboard-upgrade/context.md +0 -38
  42. package/specs/20260207-dashboard-upgrade/spec.md +0 -96
  43. package/specs/citations-system/context.md +0 -243
  44. package/specs/citations-system/plan.md +0 -495
  45. package/specs/citations-system/spec.md +0 -371
  46. package/specs/endless-mode/context.md +0 -305
  47. package/specs/endless-mode/plan.md +0 -620
  48. package/specs/endless-mode/spec.md +0 -455
  49. package/specs/entity-edge-model/context.md +0 -401
  50. package/specs/entity-edge-model/plan.md +0 -459
  51. package/specs/entity-edge-model/spec.md +0 -391
  52. package/specs/evidence-aligner-v2/context.md +0 -401
  53. package/specs/evidence-aligner-v2/plan.md +0 -303
  54. package/specs/evidence-aligner-v2/spec.md +0 -312
  55. package/specs/mcp-desktop-integration/context.md +0 -278
  56. package/specs/mcp-desktop-integration/plan.md +0 -550
  57. package/specs/mcp-desktop-integration/spec.md +0 -494
  58. package/specs/memory-utilization-improvements/context.md +0 -145
  59. package/specs/memory-utilization-improvements/plan.md +0 -361
  60. package/specs/memory-utilization-improvements/spec.md +0 -361
  61. package/specs/post-tool-use-hook/context.md +0 -319
  62. package/specs/post-tool-use-hook/plan.md +0 -469
  63. package/specs/post-tool-use-hook/spec.md +0 -364
  64. package/specs/private-tags/context.md +0 -288
  65. package/specs/private-tags/plan.md +0 -412
  66. package/specs/private-tags/spec.md +0 -345
  67. package/specs/progressive-disclosure/context.md +0 -346
  68. package/specs/progressive-disclosure/plan.md +0 -663
  69. package/specs/progressive-disclosure/spec.md +0 -415
  70. package/specs/selective-tool-observation/context.md +0 -100
  71. package/specs/selective-tool-observation/plan.md +0 -158
  72. package/specs/selective-tool-observation/spec.md +0 -127
  73. package/specs/task-entity-system/context.md +0 -297
  74. package/specs/task-entity-system/plan.md +0 -301
  75. package/specs/task-entity-system/spec.md +0 -314
  76. package/specs/thin-core-refactor/context.md +0 -275
  77. package/specs/thin-core-refactor/plan.md +0 -536
  78. package/specs/thin-core-refactor/spec.md +0 -465
  79. package/specs/vector-outbox-v2/context.md +0 -470
  80. package/specs/vector-outbox-v2/plan.md +0 -562
  81. package/specs/vector-outbox-v2/spec.md +0 -466
  82. package/specs/web-viewer-ui/context.md +0 -384
  83. package/specs/web-viewer-ui/plan.md +0 -797
  84. package/specs/web-viewer-ui/spec.md +0 -516
  85. package/src/adapters/claude/capture/index.ts +0 -3
  86. package/src/adapters/claude/context/index.ts +0 -3
  87. package/src/adapters/claude/hooks/index.ts +0 -21
  88. package/src/adapters/claude/hooks/post-tool-use.ts +0 -239
  89. package/src/adapters/claude/hooks/prompt-injection-policy.ts +0 -104
  90. package/src/adapters/claude/hooks/semantic-daemon-client.ts +0 -209
  91. package/src/adapters/claude/hooks/semantic-daemon.ts +0 -283
  92. package/src/adapters/claude/hooks/session-end.ts +0 -59
  93. package/src/adapters/claude/hooks/session-start.ts +0 -73
  94. package/src/adapters/claude/hooks/stop.ts +0 -128
  95. package/src/adapters/claude/hooks/user-prompt-submit.ts +0 -361
  96. package/src/adapters/claude/index.ts +0 -4
  97. package/src/adapters/claude/transcript/index.ts +0 -4
  98. package/src/adapters/claude/transcript/transcript-reader.ts +0 -57
  99. package/src/adapters/claude/transcript/turn-reconstructor.ts +0 -65
  100. package/src/apps/cli/claude-settings-hooks.ts +0 -138
  101. package/src/apps/cli/codex-import-runner.ts +0 -125
  102. package/src/apps/cli/codex-validation-output.ts +0 -95
  103. package/src/apps/cli/hermes-import-runner.ts +0 -130
  104. package/src/apps/cli/hermes-validation-output.ts +0 -91
  105. package/src/apps/cli/index.ts +0 -1735
  106. package/src/apps/cli/mcp-install.ts +0 -106
  107. package/src/apps/cli/retrieval-disclosure-output.ts +0 -196
  108. package/src/apps/dashboard/assets/js/bootstrap.js +0 -244
  109. package/src/apps/dashboard/assets/js/chat.js +0 -373
  110. package/src/apps/dashboard/assets/js/disclosure.js +0 -232
  111. package/src/apps/dashboard/assets/js/modals.js +0 -298
  112. package/src/apps/dashboard/assets/js/overview.js +0 -655
  113. package/src/apps/dashboard/assets/js/state.js +0 -72
  114. package/src/apps/dashboard/assets/js/views.js +0 -468
  115. package/src/apps/dashboard/index.html +0 -543
  116. package/src/apps/dashboard/index.ts +0 -3
  117. package/src/apps/dashboard/style.css +0 -1750
  118. package/src/apps/index.ts +0 -5
  119. package/src/apps/server/api/chat.ts +0 -244
  120. package/src/apps/server/api/citations.ts +0 -105
  121. package/src/apps/server/api/events.ts +0 -137
  122. package/src/apps/server/api/health.ts +0 -53
  123. package/src/apps/server/api/index.ts +0 -26
  124. package/src/apps/server/api/projects.ts +0 -74
  125. package/src/apps/server/api/search.ts +0 -184
  126. package/src/apps/server/api/sessions.ts +0 -115
  127. package/src/apps/server/api/stats.ts +0 -723
  128. package/src/apps/server/api/turns.ts +0 -143
  129. package/src/apps/server/api/utils.ts +0 -65
  130. package/src/apps/server/index.ts +0 -111
  131. package/src/cli/index.ts +0 -3
  132. package/src/cli/retrieval-disclosure-output.ts +0 -2
  133. package/src/compat/index.ts +0 -5
  134. package/src/core/canonical-key.ts +0 -186
  135. package/src/core/citation-generator.ts +0 -63
  136. package/src/core/consolidated-store.ts +0 -356
  137. package/src/core/consolidation-worker.ts +0 -493
  138. package/src/core/context-formatter.ts +0 -276
  139. package/src/core/continuity-manager.ts +0 -341
  140. package/src/core/db-wrapper.ts +0 -64
  141. package/src/core/derive/fact-deriver.ts +0 -170
  142. package/src/core/derive/index.ts +0 -2
  143. package/src/core/derive/summary-deriver.ts +0 -76
  144. package/src/core/edge-repo.ts +0 -333
  145. package/src/core/embedder.ts +0 -4
  146. package/src/core/engine/embedding-maintenance-service.ts +0 -187
  147. package/src/core/engine/endless-memory-services.ts +0 -4
  148. package/src/core/engine/index.ts +0 -19
  149. package/src/core/engine/memory-engine-services.ts +0 -170
  150. package/src/core/engine/memory-ingest-service.ts +0 -317
  151. package/src/core/engine/memory-query-service.ts +0 -173
  152. package/src/core/engine/memory-runtime-service.ts +0 -162
  153. package/src/core/engine/memory-service-composition.ts +0 -231
  154. package/src/core/engine/retrieval-analytics-service.ts +0 -181
  155. package/src/core/engine/retrieval-disclosure-service.ts +0 -420
  156. package/src/core/engine/retrieval-orchestrator.ts +0 -377
  157. package/src/core/engine/retrieval-services.ts +0 -176
  158. package/src/core/engine/shared-memory-services.ts +0 -4
  159. package/src/core/entity-repo.ts +0 -349
  160. package/src/core/event-store.ts +0 -779
  161. package/src/core/evidence-aligner.ts +0 -635
  162. package/src/core/external-market-context.ts +0 -582
  163. package/src/core/graduation-worker.ts +0 -171
  164. package/src/core/graduation.ts +0 -377
  165. package/src/core/index.ts +0 -64
  166. package/src/core/ingest-interceptor.ts +0 -80
  167. package/src/core/markdown-mirror.ts +0 -70
  168. package/src/core/matcher.ts +0 -208
  169. package/src/core/md-mirror.ts +0 -92
  170. package/src/core/metadata-extractor.ts +0 -203
  171. package/src/core/model/memory-fact.ts +0 -30
  172. package/src/core/model/memory-rule.ts +0 -14
  173. package/src/core/model/memory-summary.ts +0 -21
  174. package/src/core/model/raw-event.ts +0 -28
  175. package/src/core/model/retrieval-result.ts +0 -35
  176. package/src/core/mongo-sync-config.ts +0 -165
  177. package/src/core/mongo-sync-worker.ts +0 -381
  178. package/src/core/privacy/filter.ts +0 -190
  179. package/src/core/privacy/index.ts +0 -20
  180. package/src/core/privacy/tag-parser.ts +0 -145
  181. package/src/core/product-validation-matrix.ts +0 -314
  182. package/src/core/progressive-retriever.ts +0 -414
  183. package/src/core/registry/project-path.ts +0 -54
  184. package/src/core/registry/session-registry.ts +0 -69
  185. package/src/core/replay-evaluator.ts +0 -625
  186. package/src/core/retrieval-benchmark.ts +0 -117
  187. package/src/core/retrieval-quality.ts +0 -109
  188. package/src/core/retriever.ts +0 -800
  189. package/src/core/session-qrels.ts +0 -360
  190. package/src/core/shared-event-store.ts +0 -114
  191. package/src/core/shared-promoter.ts +0 -249
  192. package/src/core/shared-store.ts +0 -289
  193. package/src/core/shared-vector-store.ts +0 -203
  194. package/src/core/sqlite-event-store.ts +0 -1846
  195. package/src/core/sqlite-wrapper.ts +0 -116
  196. package/src/core/sync-worker.ts +0 -228
  197. package/src/core/tag-taxonomy.ts +0 -51
  198. package/src/core/task/blocker-resolver.ts +0 -333
  199. package/src/core/task/index.ts +0 -9
  200. package/src/core/task/task-matcher.ts +0 -240
  201. package/src/core/task/task-projector.ts +0 -358
  202. package/src/core/task/task-resolver.ts +0 -421
  203. package/src/core/turn-state.ts +0 -207
  204. package/src/core/types.ts +0 -952
  205. package/src/core/vector-outbox.ts +0 -299
  206. package/src/core/vector-store.ts +0 -231
  207. package/src/core/vector-worker.ts +0 -521
  208. package/src/core/working-set-store.ts +0 -257
  209. package/src/extensions/endless-memory/endless-memory-services.ts +0 -350
  210. package/src/extensions/endless-memory/index.ts +0 -1
  211. package/src/extensions/index.ts +0 -5
  212. package/src/extensions/mcp/handlers.ts +0 -960
  213. package/src/extensions/mcp/index.ts +0 -48
  214. package/src/extensions/mcp/tools.ts +0 -252
  215. package/src/extensions/shared-memory/index.ts +0 -1
  216. package/src/extensions/shared-memory/shared-memory-services.ts +0 -211
  217. package/src/extensions/vector/embedder.ts +0 -234
  218. package/src/extensions/vector/index.ts +0 -1
  219. package/src/hooks/post-tool-use.ts +0 -9
  220. package/src/hooks/semantic-daemon-client.ts +0 -1
  221. package/src/hooks/semantic-daemon.ts +0 -11
  222. package/src/hooks/session-end.ts +0 -9
  223. package/src/hooks/session-start.ts +0 -9
  224. package/src/hooks/stop.ts +0 -9
  225. package/src/hooks/user-prompt-submit.ts +0 -9
  226. package/src/index.ts +0 -13
  227. package/src/mcp/handlers.ts +0 -2
  228. package/src/mcp/index.ts +0 -4
  229. package/src/mcp/tools.ts +0 -2
  230. package/src/server/api/chat.ts +0 -2
  231. package/src/server/api/citations.ts +0 -2
  232. package/src/server/api/events.ts +0 -2
  233. package/src/server/api/health.ts +0 -2
  234. package/src/server/api/index.ts +0 -2
  235. package/src/server/api/projects.ts +0 -2
  236. package/src/server/api/search.ts +0 -2
  237. package/src/server/api/sessions.ts +0 -2
  238. package/src/server/api/stats.ts +0 -2
  239. package/src/server/api/turns.ts +0 -2
  240. package/src/server/api/utils.ts +0 -2
  241. package/src/server/index.ts +0 -2
  242. package/src/services/bootstrap-organizer.ts +0 -463
  243. package/src/services/codex-session-history-importer.ts +0 -966
  244. package/src/services/hermes-session-history-importer.ts +0 -733
  245. package/src/services/memory-service-config.ts +0 -36
  246. package/src/services/memory-service-registry.ts +0 -150
  247. package/src/services/memory-service.ts +0 -688
  248. package/src/services/session-history-importer.ts +0 -629
  249. package/tests/README.md +0 -23
  250. package/tests/adapters/claude/claude-semantic-daemon-adapter.test.ts +0 -54
  251. package/tests/adapters/claude/claude-transcript-reconstructor.test.ts +0 -98
  252. package/tests/adapters/claude-hook-prompt-injection-policy.test.ts +0 -99
  253. package/tests/apps/app-layer-boundary.test.ts +0 -48
  254. package/tests/apps/claude-settings-hooks.test.ts +0 -107
  255. package/tests/apps/cli-disclosure-output.test.ts +0 -212
  256. package/tests/apps/codex-import-runner.test.ts +0 -99
  257. package/tests/apps/codex-validation-output.test.ts +0 -100
  258. package/tests/apps/hermes-import-runner.test.ts +0 -99
  259. package/tests/apps/mcp-install-command.test.ts +0 -59
  260. package/tests/apps/package-build-entrypoints.test.ts +0 -30
  261. package/tests/apps/postinstall-embedding-backend.test.ts +0 -185
  262. package/tests/apps/search-api-disclosure.test.ts +0 -162
  263. package/tests/apps/stats-api-lightweight.test.ts +0 -67
  264. package/tests/apps/ui-disclosure-output.test.ts +0 -140
  265. package/tests/core/bootstrap-organizer.test.ts +0 -111
  266. package/tests/core/canonical-key.test.ts +0 -101
  267. package/tests/core/codex-session-history-importer-validation.test.ts +0 -185
  268. package/tests/core/consolidation-worker.test.ts +0 -75
  269. package/tests/core/embedding-maintenance-service.test.ts +0 -282
  270. package/tests/core/evidence-aligner.test.ts +0 -152
  271. package/tests/core/external-market-context.test.ts +0 -209
  272. package/tests/core/fact-deriver.test.ts +0 -79
  273. package/tests/core/hermes-session-history-importer-validation.test.ts +0 -609
  274. package/tests/core/ingest-interceptor.test.ts +0 -38
  275. package/tests/core/markdown-mirror.test.ts +0 -85
  276. package/tests/core/matcher.test.ts +0 -112
  277. package/tests/core/md-mirror.test.ts +0 -50
  278. package/tests/core/memory-engine-services.test.ts +0 -240
  279. package/tests/core/memory-ingest-service.test.ts +0 -296
  280. package/tests/core/memory-query-service.test.ts +0 -129
  281. package/tests/core/memory-runtime-service.test.ts +0 -201
  282. package/tests/core/memory-service-composition.test.ts +0 -192
  283. package/tests/core/memory-service-config.test.ts +0 -41
  284. package/tests/core/memory-service-facade.test.ts +0 -30
  285. package/tests/core/memory-service-registry.test.ts +0 -206
  286. package/tests/core/product-validation-matrix.test.ts +0 -61
  287. package/tests/core/project-registry.test.ts +0 -78
  288. package/tests/core/replay-evaluator.test.ts +0 -181
  289. package/tests/core/retrieval-analytics-service.test.ts +0 -210
  290. package/tests/core/retrieval-benchmark.test.ts +0 -93
  291. package/tests/core/retrieval-disclosure-service.test.ts +0 -264
  292. package/tests/core/retrieval-orchestrator.test.ts +0 -403
  293. package/tests/core/retrieval-quality.test.ts +0 -31
  294. package/tests/core/retrieval-services.test.ts +0 -185
  295. package/tests/core/retriever-fallback-chain.test.ts +0 -223
  296. package/tests/core/retriever-strategy-scope.test.ts +0 -164
  297. package/tests/core/retriever.memu-adoption.test.ts +0 -122
  298. package/tests/core/session-history-importer-filter.test.ts +0 -78
  299. package/tests/core/session-qrels.test.ts +0 -250
  300. package/tests/core/sqlite-event-store-replication.test.ts +0 -127
  301. package/tests/core/summary-deriver.test.ts +0 -66
  302. package/tests/extensions/embedder-warning-suppression.test.ts +0 -84
  303. package/tests/extensions/endless-memory-extension-boundary.test.ts +0 -17
  304. package/tests/extensions/endless-memory-services.test.ts +0 -325
  305. package/tests/extensions/mcp-context-tools.test.ts +0 -905
  306. package/tests/extensions/mcp-extension-boundary.test.ts +0 -21
  307. package/tests/extensions/mcp-package-build.test.ts +0 -22
  308. package/tests/extensions/mcp-project-aware-tools.test.ts +0 -102
  309. package/tests/extensions/shared-memory-extension-boundary.test.ts +0 -24
  310. package/tests/extensions/shared-memory-services.test.ts +0 -309
  311. package/tests/extensions/vector-extension-boundary.test.ts +0 -21
  312. package/tsconfig.json +0 -24
  313. 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
- }