claude-memory-layer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/.claude-plugin/commands/memory-forget.md +42 -0
  2. package/.claude-plugin/commands/memory-history.md +34 -0
  3. package/.claude-plugin/commands/memory-import.md +56 -0
  4. package/.claude-plugin/commands/memory-list.md +37 -0
  5. package/.claude-plugin/commands/memory-search.md +36 -0
  6. package/.claude-plugin/commands/memory-stats.md +34 -0
  7. package/.claude-plugin/hooks.json +59 -0
  8. package/.claude-plugin/plugin.json +24 -0
  9. package/.history/package_20260201112328.json +45 -0
  10. package/.history/package_20260201113602.json +45 -0
  11. package/.history/package_20260201113713.json +45 -0
  12. package/.history/package_20260201114110.json +45 -0
  13. package/Memo.txt +558 -0
  14. package/README.md +520 -0
  15. package/context.md +636 -0
  16. package/dist/.claude-plugin/commands/memory-forget.md +42 -0
  17. package/dist/.claude-plugin/commands/memory-history.md +34 -0
  18. package/dist/.claude-plugin/commands/memory-import.md +56 -0
  19. package/dist/.claude-plugin/commands/memory-list.md +37 -0
  20. package/dist/.claude-plugin/commands/memory-search.md +36 -0
  21. package/dist/.claude-plugin/commands/memory-stats.md +34 -0
  22. package/dist/.claude-plugin/hooks.json +59 -0
  23. package/dist/.claude-plugin/plugin.json +24 -0
  24. package/dist/cli/index.js +3539 -0
  25. package/dist/cli/index.js.map +7 -0
  26. package/dist/core/index.js +4408 -0
  27. package/dist/core/index.js.map +7 -0
  28. package/dist/hooks/session-end.js +2971 -0
  29. package/dist/hooks/session-end.js.map +7 -0
  30. package/dist/hooks/session-start.js +2969 -0
  31. package/dist/hooks/session-start.js.map +7 -0
  32. package/dist/hooks/stop.js +3123 -0
  33. package/dist/hooks/stop.js.map +7 -0
  34. package/dist/hooks/user-prompt-submit.js +2960 -0
  35. package/dist/hooks/user-prompt-submit.js.map +7 -0
  36. package/dist/services/memory-service.js +2931 -0
  37. package/dist/services/memory-service.js.map +7 -0
  38. package/package.json +45 -0
  39. package/plan.md +1642 -0
  40. package/scripts/build.ts +102 -0
  41. package/spec.md +624 -0
  42. package/specs/citations-system/context.md +243 -0
  43. package/specs/citations-system/plan.md +495 -0
  44. package/specs/citations-system/spec.md +371 -0
  45. package/specs/endless-mode/context.md +305 -0
  46. package/specs/endless-mode/plan.md +620 -0
  47. package/specs/endless-mode/spec.md +455 -0
  48. package/specs/entity-edge-model/context.md +401 -0
  49. package/specs/entity-edge-model/plan.md +459 -0
  50. package/specs/entity-edge-model/spec.md +391 -0
  51. package/specs/evidence-aligner-v2/context.md +401 -0
  52. package/specs/evidence-aligner-v2/plan.md +303 -0
  53. package/specs/evidence-aligner-v2/spec.md +312 -0
  54. package/specs/mcp-desktop-integration/context.md +278 -0
  55. package/specs/mcp-desktop-integration/plan.md +550 -0
  56. package/specs/mcp-desktop-integration/spec.md +494 -0
  57. package/specs/post-tool-use-hook/context.md +319 -0
  58. package/specs/post-tool-use-hook/plan.md +469 -0
  59. package/specs/post-tool-use-hook/spec.md +364 -0
  60. package/specs/private-tags/context.md +288 -0
  61. package/specs/private-tags/plan.md +412 -0
  62. package/specs/private-tags/spec.md +345 -0
  63. package/specs/progressive-disclosure/context.md +346 -0
  64. package/specs/progressive-disclosure/plan.md +663 -0
  65. package/specs/progressive-disclosure/spec.md +415 -0
  66. package/specs/task-entity-system/context.md +297 -0
  67. package/specs/task-entity-system/plan.md +301 -0
  68. package/specs/task-entity-system/spec.md +314 -0
  69. package/specs/vector-outbox-v2/context.md +470 -0
  70. package/specs/vector-outbox-v2/plan.md +562 -0
  71. package/specs/vector-outbox-v2/spec.md +466 -0
  72. package/specs/web-viewer-ui/context.md +384 -0
  73. package/specs/web-viewer-ui/plan.md +797 -0
  74. package/specs/web-viewer-ui/spec.md +516 -0
  75. package/src/cli/index.ts +570 -0
  76. package/src/core/canonical-key.ts +186 -0
  77. package/src/core/citation-generator.ts +63 -0
  78. package/src/core/consolidated-store.ts +279 -0
  79. package/src/core/consolidation-worker.ts +384 -0
  80. package/src/core/context-formatter.ts +276 -0
  81. package/src/core/continuity-manager.ts +336 -0
  82. package/src/core/edge-repo.ts +324 -0
  83. package/src/core/embedder.ts +124 -0
  84. package/src/core/entity-repo.ts +342 -0
  85. package/src/core/event-store.ts +672 -0
  86. package/src/core/evidence-aligner.ts +635 -0
  87. package/src/core/graduation.ts +365 -0
  88. package/src/core/index.ts +32 -0
  89. package/src/core/matcher.ts +210 -0
  90. package/src/core/metadata-extractor.ts +203 -0
  91. package/src/core/privacy/filter.ts +179 -0
  92. package/src/core/privacy/index.ts +20 -0
  93. package/src/core/privacy/tag-parser.ts +145 -0
  94. package/src/core/progressive-retriever.ts +415 -0
  95. package/src/core/retriever.ts +235 -0
  96. package/src/core/task/blocker-resolver.ts +325 -0
  97. package/src/core/task/index.ts +9 -0
  98. package/src/core/task/task-matcher.ts +238 -0
  99. package/src/core/task/task-projector.ts +345 -0
  100. package/src/core/task/task-resolver.ts +414 -0
  101. package/src/core/types.ts +841 -0
  102. package/src/core/vector-outbox.ts +295 -0
  103. package/src/core/vector-store.ts +182 -0
  104. package/src/core/vector-worker.ts +488 -0
  105. package/src/core/working-set-store.ts +244 -0
  106. package/src/hooks/post-tool-use.ts +127 -0
  107. package/src/hooks/session-end.ts +78 -0
  108. package/src/hooks/session-start.ts +57 -0
  109. package/src/hooks/stop.ts +78 -0
  110. package/src/hooks/user-prompt-submit.ts +54 -0
  111. package/src/mcp/handlers.ts +212 -0
  112. package/src/mcp/index.ts +47 -0
  113. package/src/mcp/tools.ts +78 -0
  114. package/src/server/api/citations.ts +101 -0
  115. package/src/server/api/events.ts +101 -0
  116. package/src/server/api/index.ts +18 -0
  117. package/src/server/api/search.ts +98 -0
  118. package/src/server/api/sessions.ts +111 -0
  119. package/src/server/api/stats.ts +97 -0
  120. package/src/server/index.ts +91 -0
  121. package/src/services/memory-service.ts +626 -0
  122. package/src/services/session-history-importer.ts +367 -0
  123. package/tests/canonical-key.test.ts +101 -0
  124. package/tests/evidence-aligner.test.ts +152 -0
  125. package/tests/matcher.test.ts +112 -0
  126. package/tsconfig.json +24 -0
  127. package/vitest.config.ts +15 -0
@@ -0,0 +1,243 @@
1
+ # Citations System Context
2
+
3
+ > **Version**: 1.0.0
4
+ > **Created**: 2026-02-01
5
+
6
+ ## 1. 배경
7
+
8
+ ### 1.1 claude-mem의 접근 방식
9
+
10
+ claude-mem은 observation에 ID를 부여하여 참조 가능하게 함:
11
+
12
+ ```
13
+ [mem:abc123] 에서 참조한 정보입니다.
14
+ ```
15
+
16
+ **특징**:
17
+ - 모든 observation에 고유 ID
18
+ - 검색 결과에 ID 표시
19
+ - ID로 원본 조회 가능
20
+
21
+ ### 1.2 현재 code-memory의 상황
22
+
23
+ 현재 이벤트 ID는 존재하지만 인용 시스템 없음:
24
+
25
+ ```typescript
26
+ // 현재 검색 결과
27
+ {
28
+ eventId: "evt_abc123def456...", // 긴 UUID
29
+ content: "...",
30
+ score: 0.9
31
+ }
32
+ ```
33
+
34
+ **문제**:
35
+ 1. eventId가 너무 길어서 참조하기 불편
36
+ 2. 컨텍스트에 인용 표시 없음
37
+ 3. 출처 확인 어려움
38
+
39
+ ### 1.3 인용의 가치
40
+
41
+ | 인용 없음 | 인용 있음 |
42
+ |----------|----------|
43
+ | 출처 불명 | 명확한 출처 |
44
+ | 검증 불가 | 원본 확인 가능 |
45
+ | 맥락 손실 | 전후 관계 파악 |
46
+ | 신뢰도 낮음 | 신뢰도 높음 |
47
+
48
+ ## 2. ID 설계
49
+
50
+ ### 2.1 고려사항
51
+
52
+ | 요소 | 요구사항 |
53
+ |------|----------|
54
+ | 길이 | 짧고 기억하기 쉬움 |
55
+ | 고유성 | 충돌 확률 낮음 |
56
+ | 가독성 | 쉽게 읽고 말할 수 있음 |
57
+ | 생성 | 빠르고 결정적 |
58
+
59
+ ### 2.2 옵션 비교
60
+
61
+ | 옵션 | 예시 | 조합 수 | 장점 | 단점 |
62
+ |------|------|--------|------|------|
63
+ | 4자 base62 | a7Bc | 14.7M | 매우 짧음 | 충돌 위험 |
64
+ | **6자 base62** | a7Bc3x | 56.8B | 균형 | - |
65
+ | 8자 base62 | a7Bc3xYz | 218T | 충돌 없음 | 다소 김 |
66
+ | 8자 hex | ab12cd34 | 4.3B | 익숙함 | 효율 낮음 |
67
+
68
+ **선택**: 6자 base62 (56.8억 조합)
69
+ - 1000만 이벤트에서 충돌 확률 < 0.0001%
70
+
71
+ ### 2.3 생성 알고리즘
72
+
73
+ ```typescript
74
+ // SHA256 해시 기반 (결정적, 빠름)
75
+ function generateCitationId(eventId: string): string {
76
+ const hash = crypto.createHash('sha256').update(eventId).digest();
77
+
78
+ // base62 인코딩
79
+ const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
80
+ let id = '';
81
+ for (let i = 0; i < 6; i++) {
82
+ id += charset[hash[i] % 62];
83
+ }
84
+ return id;
85
+ }
86
+ ```
87
+
88
+ ## 3. 기존 코드와의 관계
89
+
90
+ ### 3.1 event-store.ts
91
+
92
+ 인용 테이블 추가:
93
+
94
+ ```sql
95
+ -- events 테이블과 1:1 관계
96
+ CREATE TABLE citations (
97
+ citation_id VARCHAR(8) PRIMARY KEY,
98
+ event_id VARCHAR NOT NULL UNIQUE REFERENCES events(event_id)
99
+ );
100
+ ```
101
+
102
+ ### 3.2 retriever.ts
103
+
104
+ 검색 결과에 인용 포함:
105
+
106
+ ```typescript
107
+ // 현재
108
+ async search(query): Promise<SearchResult[]>
109
+
110
+ // 확장
111
+ async searchWithCitations(query): Promise<CitedSearchResult[]>
112
+ ```
113
+
114
+ ### 3.3 context-formatter.ts
115
+
116
+ 인용 표시 포맷:
117
+
118
+ ```typescript
119
+ // 현재
120
+ > DuckDB를 사용하여...
121
+
122
+ // 확장
123
+ > DuckDB를 사용하여...
124
+ >
125
+ > [mem:a7Bc3x] - 2026-01-30, Session abc123
126
+ ```
127
+
128
+ ## 4. 설계 결정 사항
129
+
130
+ ### 4.1 생성 시점
131
+
132
+ **옵션 1: 이벤트 저장 시 즉시 생성**
133
+ - 장점: 항상 인용 ID 존재
134
+ - 단점: 저장 오버헤드
135
+
136
+ **옵션 2: 검색 시 지연 생성**
137
+ - 장점: 필요할 때만 생성
138
+ - 단점: 첫 검색 약간 느림
139
+
140
+ **선택**: 지연 생성 (getOrCreate 패턴)
141
+ - 저장 시 오버헤드 없음
142
+ - 대부분 이벤트는 검색되지 않음
143
+
144
+ ### 4.2 인용 포맷
145
+
146
+ **옵션들**:
147
+ 1. `[mem:a7Bc3x]` - 명확하고 검색 가능
148
+ 2. `(ref: a7Bc3x)` - 간결
149
+ 3. `¹` (각주 스타일) - 학술적
150
+ 4. `<a7Bc3x>` - 태그 스타일
151
+
152
+ **선택**: `[mem:a7Bc3x]`
153
+ - `mem:` 접두사로 명확한 의미
154
+ - 대괄호로 시각적 구분
155
+ - 검색/복사 용이
156
+
157
+ ### 4.3 컨텍스트 포함 방식
158
+
159
+ **인라인 방식** (선택):
160
+ ```markdown
161
+ > 내용...
162
+ > [mem:a7Bc3x] - 2026-01-30
163
+ ```
164
+
165
+ **각주 방식**:
166
+ ```markdown
167
+ DuckDB를 사용[1]...
168
+
169
+ ---
170
+ [1] mem:a7Bc3x - 2026-01-30
171
+ ```
172
+
173
+ **참조 방식**:
174
+ ```markdown
175
+ ## Content
176
+ DuckDB를 사용...
177
+
178
+ ## References
179
+ - [mem:a7Bc3x] Session abc123, 2026-01-30
180
+ ```
181
+
182
+ ## 5. 사용 추적
183
+
184
+ ### 5.1 목적
185
+
186
+ - 인기 있는 메모리 파악
187
+ - 자주 참조되는 지식 식별
188
+ - graduation 우선순위 결정
189
+
190
+ ### 5.2 추적 데이터
191
+
192
+ ```sql
193
+ CREATE TABLE citation_usages (
194
+ usage_id VARCHAR PRIMARY KEY,
195
+ citation_id VARCHAR NOT NULL,
196
+ session_id VARCHAR NOT NULL,
197
+ used_at TIMESTAMP,
198
+ context VARCHAR -- 검색 쿼리
199
+ );
200
+ ```
201
+
202
+ ### 5.3 통계 활용
203
+
204
+ ```typescript
205
+ // 인기 인용 → graduation 우선순위
206
+ async function graduationCandidates(): Promise<Event[]> {
207
+ const popular = await getPopularCitations({ limit: 100 });
208
+ return popular.filter(c => c.usageCount >= 5);
209
+ }
210
+ ```
211
+
212
+ ## 6. 성능 고려사항
213
+
214
+ ### 6.1 ID 생성
215
+
216
+ - SHA256 해시: ~1µs
217
+ - DB 조회 (exists): ~1ms
218
+ - 충돌 시 재시도: 드묾
219
+
220
+ ### 6.2 인덱스
221
+
222
+ ```sql
223
+ -- 빠른 조회를 위한 인덱스
224
+ CREATE INDEX idx_citations_event ON citations(event_id);
225
+ CREATE INDEX idx_usages_citation ON citation_usages(citation_id);
226
+ ```
227
+
228
+ ### 6.3 캐싱
229
+
230
+ ```typescript
231
+ // 최근 사용된 인용 캐싱
232
+ const citationCache = new LRUCache<string, Citation>({
233
+ max: 1000,
234
+ ttl: 3600000 // 1시간
235
+ });
236
+ ```
237
+
238
+ ## 7. 참고 자료
239
+
240
+ - **claude-mem**: Citation system with observation IDs
241
+ - **학술 인용**: APA, MLA 스타일
242
+ - **GitHub**: Issue/PR 참조 (#123)
243
+ - **Notion**: 블록 ID 참조 시스템