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
@@ -1,495 +0,0 @@
1
- # Citations System Implementation Plan
2
-
3
- > **Version**: 1.0.0
4
- > **Status**: Draft
5
- > **Created**: 2026-02-01
6
-
7
- ## Phase 1: 인용 저장소 (P0)
8
-
9
- ### 1.1 스키마 정의
10
-
11
- **파일**: `src/core/types.ts` 수정
12
-
13
- ```typescript
14
- export const CitationSchema = z.object({
15
- citationId: z.string().length(6),
16
- eventId: z.string(),
17
- createdAt: z.date()
18
- });
19
-
20
- export type Citation = z.infer<typeof CitationSchema>;
21
-
22
- export const CitationUsageSchema = z.object({
23
- usageId: z.string(),
24
- citationId: z.string(),
25
- sessionId: z.string(),
26
- usedAt: z.date(),
27
- context: z.string().optional()
28
- });
29
-
30
- export type CitationUsage = z.infer<typeof CitationUsageSchema>;
31
- ```
32
-
33
- **작업 항목**:
34
- - [ ] Citation 스키마 추가
35
- - [ ] CitationUsage 스키마 추가
36
- - [ ] 설정 스키마 확장
37
-
38
- ### 1.2 DB 테이블
39
-
40
- **파일**: `src/core/event-store.ts` 수정
41
-
42
- ```typescript
43
- private async initSchema(): Promise<void> {
44
- // 기존 테이블...
45
-
46
- // 인용 테이블
47
- await this.db.exec(`
48
- CREATE TABLE IF NOT EXISTS citations (
49
- citation_id VARCHAR(8) PRIMARY KEY,
50
- event_id VARCHAR NOT NULL,
51
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
52
- UNIQUE(event_id)
53
- );
54
-
55
- CREATE INDEX IF NOT EXISTS idx_citations_event ON citations(event_id);
56
- `);
57
-
58
- // 사용 로그 테이블
59
- await this.db.exec(`
60
- CREATE TABLE IF NOT EXISTS citation_usages (
61
- usage_id VARCHAR PRIMARY KEY,
62
- citation_id VARCHAR NOT NULL,
63
- session_id VARCHAR NOT NULL,
64
- used_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
65
- context VARCHAR
66
- );
67
-
68
- CREATE INDEX IF NOT EXISTS idx_usages_citation ON citation_usages(citation_id);
69
- `);
70
- }
71
- ```
72
-
73
- **작업 항목**:
74
- - [ ] citations 테이블 생성
75
- - [ ] citation_usages 테이블 생성
76
- - [ ] 인덱스 생성
77
-
78
- ## Phase 2: 인용 ID 생성 (P0)
79
-
80
- ### 2.1 ID 생성기
81
-
82
- **파일**: `src/core/citation-generator.ts` (신규)
83
-
84
- ```typescript
85
- import { createHash } from 'crypto';
86
-
87
- const ID_LENGTH = 6;
88
- const CHARSET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
89
-
90
- export function generateCitationId(eventId: string): string {
91
- const hash = createHash('sha256')
92
- .update(eventId)
93
- .digest();
94
-
95
- let id = '';
96
- for (let i = 0; i < ID_LENGTH; i++) {
97
- id += CHARSET[hash[i] % CHARSET.length];
98
- }
99
-
100
- return id;
101
- }
102
-
103
- // 충돌 처리 (드문 경우)
104
- export async function generateUniqueCitationId(
105
- eventId: string,
106
- store: CitationStore
107
- ): Promise<string> {
108
- let id = generateCitationId(eventId);
109
- let attempt = 0;
110
-
111
- while (await store.exists(id) && attempt < 10) {
112
- // 솔트 추가하여 재생성
113
- id = generateCitationId(`${eventId}:${attempt}`);
114
- attempt++;
115
- }
116
-
117
- if (attempt >= 10) {
118
- throw new Error('Failed to generate unique citation ID');
119
- }
120
-
121
- return id;
122
- }
123
- ```
124
-
125
- **작업 항목**:
126
- - [ ] generateCitationId 함수 구현
127
- - [ ] 충돌 처리 로직
128
- - [ ] 유닛 테스트
129
-
130
- ### 2.2 인용 저장소
131
-
132
- **파일**: `src/core/citation-store.ts` (신규)
133
-
134
- ```typescript
135
- export class CitationStore {
136
- constructor(private db: Database) {}
137
-
138
- async create(citation: CitationInput): Promise<Citation> {
139
- await this.db.run(`
140
- INSERT INTO citations (citation_id, event_id, created_at)
141
- VALUES (?, ?, ?)
142
- `, [citation.citationId, citation.eventId, new Date()]);
143
-
144
- return { ...citation, createdAt: new Date() };
145
- }
146
-
147
- async findById(citationId: string): Promise<Citation | null> {
148
- return this.db.get(`
149
- SELECT * FROM citations WHERE citation_id = ?
150
- `, [citationId]);
151
- }
152
-
153
- async findByEventId(eventId: string): Promise<Citation | null> {
154
- return this.db.get(`
155
- SELECT * FROM citations WHERE event_id = ?
156
- `, [eventId]);
157
- }
158
-
159
- async exists(citationId: string): Promise<boolean> {
160
- const result = await this.db.get(`
161
- SELECT 1 FROM citations WHERE citation_id = ?
162
- `, [citationId]);
163
- return !!result;
164
- }
165
-
166
- async getOrCreate(eventId: string): Promise<Citation> {
167
- const existing = await this.findByEventId(eventId);
168
- if (existing) return existing;
169
-
170
- const citationId = await generateUniqueCitationId(eventId, this);
171
- return this.create({ citationId, eventId });
172
- }
173
- }
174
- ```
175
-
176
- **작업 항목**:
177
- - [ ] CitationStore 클래스 구현
178
- - [ ] CRUD 메서드
179
- - [ ] getOrCreate 패턴
180
-
181
- ## Phase 3: 컨텍스트 통합 (P0)
182
-
183
- ### 3.1 인용 포함 검색
184
-
185
- **파일**: `src/core/retriever.ts` 수정
186
-
187
- ```typescript
188
- export interface CitedSearchResult {
189
- event: Event;
190
- citation: Citation;
191
- score: number;
192
- }
193
-
194
- export class Retriever {
195
- async searchWithCitations(
196
- query: string,
197
- options?: SearchOptions
198
- ): Promise<CitedSearchResult[]> {
199
- const results = await this.search(query, options);
200
-
201
- return Promise.all(
202
- results.map(async (result) => {
203
- const citation = await this.citationStore.getOrCreate(result.eventId);
204
- return {
205
- event: result,
206
- citation,
207
- score: result.score
208
- };
209
- })
210
- );
211
- }
212
- }
213
- ```
214
-
215
- **작업 항목**:
216
- - [ ] searchWithCitations 메서드 추가
217
- - [ ] 인용 자동 생성/조회
218
-
219
- ### 3.2 컨텍스트 포맷터 수정
220
-
221
- **파일**: `src/core/context-formatter.ts` 수정
222
-
223
- ```typescript
224
- export function formatContextWithCitations(
225
- results: CitedSearchResult[],
226
- options?: FormatOptions
227
- ): string {
228
- const format = options?.format ?? 'inline';
229
-
230
- switch (format) {
231
- case 'inline':
232
- return formatInline(results);
233
- case 'footnote':
234
- return formatFootnote(results);
235
- case 'reference':
236
- return formatReference(results);
237
- }
238
- }
239
-
240
- function formatInline(results: CitedSearchResult[]): string {
241
- return results.map(r => {
242
- const date = r.event.timestamp.toLocaleDateString();
243
- const session = r.event.sessionId.slice(0, 6);
244
-
245
- return [
246
- `> ${r.event.payload.content}`,
247
- `>`,
248
- `> [mem:${r.citation.citationId}] - ${date}, Session ${session}`
249
- ].join('\n');
250
- }).join('\n\n---\n\n');
251
- }
252
- ```
253
-
254
- **작업 항목**:
255
- - [ ] 인라인 포맷 구현
256
- - [ ] 각주 포맷 구현
257
- - [ ] 참조 포맷 구현
258
-
259
- ## Phase 4: 조회 인터페이스 (P0)
260
-
261
- ### 4.1 CLI 명령
262
-
263
- **파일**: `src/cli/commands/show.ts` (신규)
264
-
265
- ```typescript
266
- import { Command } from 'commander';
267
-
268
- export const showCommand = new Command('show')
269
- .argument('<citation>', 'Citation ID (e.g., mem:a7Bc3x or just a7Bc3x)')
270
- .description('Show full content of a cited memory')
271
- .action(async (citation: string) => {
272
- const memoryService = await MemoryService.getInstance();
273
-
274
- // mem: 접두사 제거
275
- const citationId = citation.replace(/^mem:/, '');
276
-
277
- const result = await memoryService.getCitedMemory(citationId);
278
-
279
- if (!result) {
280
- console.log(chalk.red(`Citation not found: ${citationId}`));
281
- return;
282
- }
283
-
284
- // 출력 포맷팅
285
- console.log(chalk.bold(`📄 Memory Citation: ${citationId}`));
286
- console.log();
287
- console.log(`Session: ${result.event.sessionId}`);
288
- console.log(`Date: ${result.event.timestamp.toLocaleString()}`);
289
- console.log(`Type: ${result.event.eventType}`);
290
- console.log();
291
- console.log('Content:');
292
- console.log('─'.repeat(40));
293
- console.log(result.event.payload.content);
294
- console.log('─'.repeat(40));
295
-
296
- if (result.related) {
297
- console.log();
298
- console.log('Related:');
299
- if (result.related.previous) {
300
- console.log(` Previous: [mem:${result.related.previous.citationId}]`);
301
- }
302
- if (result.related.next) {
303
- console.log(` Next: [mem:${result.related.next.citationId}]`);
304
- }
305
- }
306
- });
307
- ```
308
-
309
- **작업 항목**:
310
- - [ ] show 명령 구현
311
- - [ ] 출력 포맷팅
312
- - [ ] 관련 인용 표시
313
-
314
- ### 4.2 API 엔드포인트
315
-
316
- **파일**: `src/server/api/citations.ts` (신규)
317
-
318
- ```typescript
319
- import { Hono } from 'hono';
320
-
321
- export const citationsRouter = new Hono();
322
-
323
- // GET /api/citations/:id
324
- citationsRouter.get('/:id', async (c) => {
325
- const { id } = c.req.param();
326
- const memoryService = await MemoryService.getInstance();
327
-
328
- const result = await memoryService.getCitedMemory(id);
329
-
330
- if (!result) {
331
- return c.json({ error: 'Citation not found' }, 404);
332
- }
333
-
334
- return c.json(result);
335
- });
336
-
337
- // GET /api/citations/:id/related
338
- citationsRouter.get('/:id/related', async (c) => {
339
- const { id } = c.req.param();
340
- const memoryService = await MemoryService.getInstance();
341
-
342
- const related = await memoryService.getRelatedCitations(id);
343
-
344
- return c.json({ related });
345
- });
346
- ```
347
-
348
- **작업 항목**:
349
- - [ ] 인용 조회 API
350
- - [ ] 관련 인용 API
351
- - [ ] 에러 처리
352
-
353
- ## Phase 5: 사용 추적 (P1)
354
-
355
- ### 5.1 사용 로깅
356
-
357
- **파일**: `src/core/citation-store.ts` 수정
358
-
359
- ```typescript
360
- export class CitationStore {
361
- async logUsage(
362
- citationId: string,
363
- sessionId: string,
364
- context?: string
365
- ): Promise<void> {
366
- const usageId = crypto.randomUUID();
367
-
368
- await this.db.run(`
369
- INSERT INTO citation_usages (usage_id, citation_id, session_id, used_at, context)
370
- VALUES (?, ?, ?, ?, ?)
371
- `, [usageId, citationId, sessionId, new Date(), context]);
372
- }
373
-
374
- async getUsageStats(citationId: string): Promise<CitationStats> {
375
- const result = await this.db.get(`
376
- SELECT
377
- COUNT(*) as usage_count,
378
- MAX(used_at) as last_used
379
- FROM citation_usages
380
- WHERE citation_id = ?
381
- `, [citationId]);
382
-
383
- return {
384
- usageCount: result.usage_count,
385
- lastUsed: result.last_used ? new Date(result.last_used) : null
386
- };
387
- }
388
- }
389
- ```
390
-
391
- **작업 항목**:
392
- - [ ] 사용 로깅 구현
393
- - [ ] 통계 조회
394
- - [ ] user-prompt-submit 훅에서 로깅
395
-
396
- ### 5.2 인기 인용 통계
397
-
398
- ```typescript
399
- async getPopularCitations(options?: { limit?: number; days?: number }): Promise<PopularCitation[]> {
400
- const { limit = 10, days = 30 } = options || {};
401
-
402
- return this.db.query(`
403
- SELECT
404
- c.citation_id,
405
- e.event_type,
406
- SUBSTR(JSON_EXTRACT(e.payload_json, '$.content'), 1, 100) as preview,
407
- COUNT(u.usage_id) as usage_count,
408
- MAX(u.used_at) as last_used
409
- FROM citations c
410
- JOIN events e ON c.event_id = e.event_id
411
- LEFT JOIN citation_usages u ON c.citation_id = u.citation_id
412
- AND u.used_at > datetime('now', '-${days} days')
413
- GROUP BY c.citation_id
414
- ORDER BY usage_count DESC
415
- LIMIT ?
416
- `, [limit]);
417
- }
418
- ```
419
-
420
- **작업 항목**:
421
- - [ ] 인기 인용 조회
422
- - [ ] 기간별 필터링
423
- - [ ] Stats API에 추가
424
-
425
- ## 파일 목록
426
-
427
- ### 신규 파일
428
- ```
429
- src/core/citation-generator.ts # ID 생성
430
- src/core/citation-store.ts # 인용 저장소
431
- src/cli/commands/show.ts # show 명령
432
- src/server/api/citations.ts # 인용 API
433
- ```
434
-
435
- ### 수정 파일
436
- ```
437
- src/core/types.ts # 스키마 추가
438
- src/core/event-store.ts # 테이블 추가
439
- src/core/retriever.ts # 인용 포함 검색
440
- src/core/context-formatter.ts # 인용 포맷
441
- src/hooks/user-prompt-submit.ts # 사용 로깅
442
- src/cli/index.ts # show 명령 등록
443
- src/server/api/index.ts # citations 라우터 추가
444
- ```
445
-
446
- ## 테스트
447
-
448
- ### 필수 테스트 케이스
449
-
450
- 1. **ID 생성**
451
- ```typescript
452
- test('should generate 6-char citation ID', () => {
453
- const id = generateCitationId('event_123');
454
- expect(id.length).toBe(6);
455
- expect(/^[A-Za-z0-9]+$/.test(id)).toBe(true);
456
- });
457
- ```
458
-
459
- 2. **충돌 처리**
460
- ```typescript
461
- test('should handle ID collision', async () => {
462
- // 첫 번째 이벤트 저장
463
- await store.create({ citationId: 'abc123', eventId: 'event_1' });
464
-
465
- // 충돌 시 다른 ID 생성
466
- const id = await generateUniqueCitationId('event_2', store);
467
- expect(id).not.toBe('abc123');
468
- });
469
- ```
470
-
471
- 3. **컨텍스트 포맷**
472
- ```typescript
473
- test('should format context with citations', () => {
474
- const formatted = formatContextWithCitations([{
475
- event: mockEvent,
476
- citation: { citationId: 'a7Bc3x', ... },
477
- score: 0.9
478
- }]);
479
-
480
- expect(formatted).toContain('[mem:a7Bc3x]');
481
- });
482
- ```
483
-
484
- ## 마일스톤
485
-
486
- | 단계 | 완료 기준 |
487
- |------|----------|
488
- | M1 | 스키마 및 테이블 생성 |
489
- | M2 | ID 생성기 구현 |
490
- | M3 | CitationStore 구현 |
491
- | M4 | 검색에 인용 통합 |
492
- | M5 | CLI show 명령 |
493
- | M6 | API 엔드포인트 |
494
- | M7 | 사용 추적 |
495
- | M8 | 테스트 통과 |