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,312 @@
1
+ # Evidence Aligner V2 Specification
2
+
3
+ > **Version**: 2.0.0
4
+ > **Status**: Draft
5
+ > **Created**: 2026-01-31
6
+
7
+ ## 1. 개요
8
+
9
+ ### 1.1 문제 정의
10
+
11
+ 현재 시스템에서 LLM이 evidence의 spanStart/spanEnd를 직접 계산하는 방식의 문제:
12
+
13
+ 1. **부정확한 오프셋**: LLM이 문자 위치를 정확히 계산하기 어려움
14
+ 2. **환각 가능성**: 원문에 없는 내용을 증거로 제시할 수 있음
15
+ 3. **검증 불가**: LLM이 준 오프셋이 실제 원문과 일치하는지 확인 어려움
16
+
17
+ ### 1.2 해결 방향
18
+
19
+ **Quote-only 방식**:
20
+ - LLM은 **quote(인용문)**만 제공
21
+ - Pipeline(EvidenceAligner)이 원문에서 정확한 span 계산
22
+ - 매칭 실패 시 `evidenceAligned=false`로 표시 → Verified 승격 금지
23
+
24
+ ## 2. 핵심 개념
25
+
26
+ ### 2.1 Evidence 흐름
27
+
28
+ ```
29
+ LLM Extractor EvidenceAligner Database
30
+ │ │ │
31
+ │ { quote: "JSONB 제거" } │ │
32
+ ├─────────────────────────────────▶│ │
33
+ │ │ 원문에서 검색 │
34
+ │ │ ───────────── │
35
+ │ │ │
36
+ │ { spanStart: 142, │ │
37
+ │ spanEnd: 150, │ │
38
+ │ confidence: 1.0 } │ │
39
+ │◀─────────────────────────────────┤ │
40
+ │ │ │
41
+ │ │ evidence_aligned 이벤트 │
42
+ │ ├─────────────────────────▶│
43
+ ```
44
+
45
+ ### 2.2 Extractor 출력 스키마 변경
46
+
47
+ **기존 (금지)**:
48
+ ```json
49
+ {
50
+ "evidence": [{
51
+ "messageIndex": 3,
52
+ "spanStart": 142,
53
+ "spanEnd": 150
54
+ }]
55
+ }
56
+ ```
57
+
58
+ **신규 (권장)**:
59
+ ```json
60
+ {
61
+ "evidence": [{
62
+ "messageIndex": 3,
63
+ "quote": "content JSONB → JSON"
64
+ }]
65
+ }
66
+ ```
67
+
68
+ ### 2.3 정렬 알고리즘
69
+
70
+ ```typescript
71
+ interface AlignmentStep {
72
+ method: 'exact' | 'normalized' | 'fuzzy';
73
+ description: string;
74
+ }
75
+
76
+ const ALIGNMENT_STEPS: AlignmentStep[] = [
77
+ { method: 'exact', description: '정확한 substring 매칭' },
78
+ { method: 'normalized', description: '공백/개행 정규화 후 매칭' },
79
+ { method: 'fuzzy', description: 'Levenshtein 거리 기반 유사 매칭 (threshold: 0.85)' }
80
+ ];
81
+ ```
82
+
83
+ ## 3. 입출력 스키마
84
+
85
+ ### 3.1 입력
86
+
87
+ ```typescript
88
+ interface AlignInput {
89
+ sessionMessages: string[]; // 원문 메시지 배열
90
+ extractedJson: ExtractedData; // LLM 추출 결과
91
+ }
92
+
93
+ interface ExtractedEvidence {
94
+ messageIndex: number;
95
+ quote: string; // 30~200자 권장
96
+ }
97
+ ```
98
+
99
+ ### 3.2 출력
100
+
101
+ ```typescript
102
+ interface AlignedEvidence {
103
+ messageIndex: number;
104
+ quote: string;
105
+ quoteHash: string; // SHA256(quote)
106
+ spanStart: number; // 원문 내 시작 위치
107
+ spanEnd: number; // 원문 내 끝 위치
108
+ confidence: number; // 0.0 ~ 1.0
109
+ matchMethod: 'exact' | 'normalized' | 'fuzzy' | 'none';
110
+ }
111
+
112
+ interface AlignResult {
113
+ evidenceAligned: boolean; // 모든 evidence가 정렬됨
114
+ alignedEvidence: AlignedEvidence[];
115
+ failedQuotes: string[]; // 정렬 실패한 quote 목록
116
+ }
117
+ ```
118
+
119
+ ## 4. 정렬 로직 상세
120
+
121
+ ### 4.1 Exact Match
122
+
123
+ ```typescript
124
+ function exactMatch(quote: string, source: string): AlignedSpan | null {
125
+ const index = source.indexOf(quote);
126
+ if (index === -1) return null;
127
+
128
+ return {
129
+ spanStart: index,
130
+ spanEnd: index + quote.length,
131
+ confidence: 1.0,
132
+ matchMethod: 'exact'
133
+ };
134
+ }
135
+ ```
136
+
137
+ ### 4.2 Normalized Match
138
+
139
+ ```typescript
140
+ function normalizedMatch(quote: string, source: string): AlignedSpan | null {
141
+ const normalizedQuote = normalize(quote);
142
+ const normalizedSource = normalize(source);
143
+
144
+ const index = normalizedSource.indexOf(normalizedQuote);
145
+ if (index === -1) return null;
146
+
147
+ // 원본 source에서 실제 위치 역추적 필요
148
+ const originalSpan = mapToOriginal(source, normalizedSource, index, normalizedQuote.length);
149
+
150
+ return {
151
+ ...originalSpan,
152
+ confidence: 0.95,
153
+ matchMethod: 'normalized'
154
+ };
155
+ }
156
+
157
+ function normalize(text: string): string {
158
+ return text
159
+ .replace(/\s+/g, ' ') // 연속 공백 → 단일 공백
160
+ .replace(/\n+/g, ' ') // 개행 → 공백
161
+ .trim()
162
+ .toLowerCase();
163
+ }
164
+ ```
165
+
166
+ ### 4.3 Fuzzy Match
167
+
168
+ ```typescript
169
+ function fuzzyMatch(
170
+ quote: string,
171
+ source: string,
172
+ threshold: number = 0.85
173
+ ): AlignedSpan | null {
174
+ const normalizedQuote = normalize(quote);
175
+ const windowSize = Math.ceil(normalizedQuote.length * 1.2);
176
+
177
+ let bestMatch: { start: number; end: number; score: number } | null = null;
178
+
179
+ // 슬라이딩 윈도우로 유사도 검사
180
+ for (let i = 0; i <= source.length - windowSize; i++) {
181
+ const window = normalize(source.slice(i, i + windowSize));
182
+ const score = levenshteinSimilarity(normalizedQuote, window);
183
+
184
+ if (score >= threshold && (!bestMatch || score > bestMatch.score)) {
185
+ bestMatch = { start: i, end: i + windowSize, score };
186
+ }
187
+ }
188
+
189
+ if (!bestMatch) return null;
190
+
191
+ return {
192
+ spanStart: bestMatch.start,
193
+ spanEnd: bestMatch.end,
194
+ confidence: bestMatch.score,
195
+ matchMethod: 'fuzzy'
196
+ };
197
+ }
198
+ ```
199
+
200
+ ## 5. 이벤트 스키마
201
+
202
+ ### 5.1 evidence_aligned 이벤트
203
+
204
+ ```typescript
205
+ interface EvidenceAlignedEvent {
206
+ event_type: 'evidence_aligned';
207
+ session_id: string;
208
+ payload: {
209
+ source_event_id: string; // session_ingested event
210
+ extraction_event_id: string; // memory_extracted event
211
+ entry_id: string;
212
+ aligned_count: number;
213
+ failed_count: number;
214
+ evidence: AlignedEvidence[];
215
+ failed_quotes: string[];
216
+ };
217
+ }
218
+ ```
219
+
220
+ ## 6. Idris2 영감 적용
221
+
222
+ ### 6.1 증거 기반 타입 (Proof-Carrying)
223
+
224
+ **Idris2 개념**:
225
+ ```idris
226
+ -- 타입이 증거를 포함
227
+ data EvidencedFact : Type where
228
+ MkFact : (claim : String) -> (proof : Span) -> EvidencedFact
229
+ ```
230
+
231
+ **TypeScript 적용**:
232
+ ```typescript
233
+ // Discriminated Union으로 증거 유무 구분
234
+ type Evidence =
235
+ | { aligned: true; span: AlignedSpan }
236
+ | { aligned: false; failureReason: string };
237
+
238
+ // 증거가 있는 entry만 Verified로 승격 가능
239
+ type VerifiedEntry = {
240
+ evidence: Extract<Evidence, { aligned: true }>[]; // 모든 evidence가 aligned
241
+ };
242
+ ```
243
+
244
+ ### 6.2 불변식
245
+
246
+ ```typescript
247
+ // Zod로 불변식 검증
248
+ const AlignedEvidenceSchema = z.object({
249
+ confidence: z.number().min(0).max(1),
250
+ matchMethod: z.enum(['exact', 'normalized', 'fuzzy']),
251
+ // fuzzy면 confidence < 1.0
252
+ }).refine(
253
+ (e) => e.matchMethod !== 'exact' || e.confidence === 1.0,
254
+ { message: 'Exact match must have confidence 1.0' }
255
+ );
256
+ ```
257
+
258
+ ## 7. 승격 정책
259
+
260
+ ### 7.1 Evidence 기반 승격 조건
261
+
262
+ | Stage | Evidence 요구사항 |
263
+ |-------|------------------|
264
+ | raw → working | 없음 |
265
+ | working → candidate | 없음 |
266
+ | candidate → verified | **evidenceAligned=true** 필수 |
267
+ | verified → certified | 추가 검증 필요 |
268
+
269
+ ### 7.2 실패 처리
270
+
271
+ ```typescript
272
+ async function processEntry(entry: Entry): Promise<void> {
273
+ const alignResult = await aligner.align(sessionMessages, entry.evidence);
274
+
275
+ if (!alignResult.evidenceAligned) {
276
+ // Verified 승격 금지
277
+ entry.meta.promotionBlocked = true;
278
+ entry.meta.promotionBlockReason = 'Evidence alignment failed';
279
+ entry.meta.failedQuotes = alignResult.failedQuotes;
280
+ }
281
+ }
282
+ ```
283
+
284
+ ## 8. 기존 EvidenceAligner와 차이점
285
+
286
+ ### 8.1 현재 구현 (src/core/evidence-aligner.ts)
287
+
288
+ ```typescript
289
+ // 현재: quote 기반 정렬 지원
290
+ align(claims: string[], sourceContent: string): AlignmentResult {
291
+ // exact match만 지원
292
+ const exactSpan = this.findExactMatch(claim, sourceContent);
293
+ }
294
+ ```
295
+
296
+ ### 8.2 V2 개선사항
297
+
298
+ | 항목 | 현재 | V2 |
299
+ |------|-----|-----|
300
+ | 정규화 매칭 | 없음 | 공백/개행 정규화 |
301
+ | Fuzzy 매칭 | 없음 | Levenshtein 기반 (threshold 0.85) |
302
+ | 이벤트 기록 | 없음 | evidence_aligned 이벤트 발행 |
303
+ | 승격 연동 | 없음 | evidenceAligned → Verified 조건 |
304
+ | 메시지 인덱스 | 없음 | messageIndex 기반 정확한 소스 식별 |
305
+
306
+ ## 9. 성공 기준
307
+
308
+ - [ ] LLM Extractor가 quote만 출력하도록 프롬프트 수정
309
+ - [ ] EvidenceAligner가 3단계 정렬 (exact → normalized → fuzzy) 수행
310
+ - [ ] 정렬 결과가 evidence_aligned 이벤트로 기록됨
311
+ - [ ] evidenceAligned=false인 entry는 Verified 승격 불가
312
+ - [ ] 기존 evidence-aligner.ts와 호환 유지
@@ -0,0 +1,278 @@
1
+ # MCP Desktop Integration 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은 MCP (Model Context Protocol)를 통해 Claude Desktop 통합 제공:
11
+
12
+ ```
13
+ Claude Desktop → MCP Client → claude-mem MCP Server → Memory Storage
14
+ ```
15
+
16
+ **특징**:
17
+ - `mem-search` 도구로 자연어 검색
18
+ - Progressive disclosure 패턴 지원
19
+ - 동일한 메모리 저장소 공유
20
+
21
+ ### 1.2 MCP란?
22
+
23
+ **Model Context Protocol (MCP)**:
24
+ - Anthropic이 개발한 표준 프로토콜
25
+ - AI 모델과 외부 도구/데이터 연결
26
+ - JSON-RPC 기반 통신
27
+ - stdio 또는 HTTP 전송
28
+
29
+ ### 1.3 현재 code-memory의 상황
30
+
31
+ 현재 Claude Code CLI 전용:
32
+
33
+ ```
34
+ Claude Code CLI → Hooks → Memory Storage
35
+
36
+ (Desktop 접근 불가)
37
+ ```
38
+
39
+ **문제**:
40
+ 1. Claude Desktop에서 메모리 활용 불가
41
+ 2. CLI 없이는 검색 불가
42
+ 3. 환경 간 메모리 분리
43
+
44
+ ## 2. MCP 프로토콜 이해
45
+
46
+ ### 2.1 핵심 개념
47
+
48
+ ```
49
+ ┌─────────────────┐ ┌─────────────────┐
50
+ │ MCP Client │◀─────▶│ MCP Server │
51
+ │ (Claude Desktop)│ JSON │ (code-memory) │
52
+ └─────────────────┘ RPC └─────────────────┘
53
+ ```
54
+
55
+ **Client**: Claude Desktop, Claude.ai
56
+ **Server**: 도구/데이터 제공자
57
+ **Transport**: stdio (로컬), HTTP (원격)
58
+
59
+ ### 2.2 메시지 형식
60
+
61
+ ```typescript
62
+ // 요청
63
+ {
64
+ "jsonrpc": "2.0",
65
+ "id": 1,
66
+ "method": "tools/call",
67
+ "params": {
68
+ "name": "mem-search",
69
+ "arguments": { "query": "..." }
70
+ }
71
+ }
72
+
73
+ // 응답
74
+ {
75
+ "jsonrpc": "2.0",
76
+ "id": 1,
77
+ "result": {
78
+ "content": [{ "type": "text", "text": "..." }]
79
+ }
80
+ }
81
+ ```
82
+
83
+ ### 2.3 도구 정의
84
+
85
+ ```typescript
86
+ interface Tool {
87
+ name: string; // 도구 이름
88
+ description: string; // Claude에게 보여질 설명
89
+ inputSchema: JSONSchema; // 입력 스키마
90
+ }
91
+ ```
92
+
93
+ ## 3. 기존 코드와의 관계
94
+
95
+ ### 3.1 MemoryService 재사용
96
+
97
+ MCP 서버는 동일한 MemoryService 사용:
98
+
99
+ ```typescript
100
+ // CLI
101
+ const service = await MemoryService.getInstance();
102
+ await service.search(query);
103
+
104
+ // MCP Server
105
+ const service = await MemoryService.getInstance();
106
+ await service.search(query); // 동일한 코드
107
+ ```
108
+
109
+ ### 3.2 Progressive Retriever 재사용
110
+
111
+ ```typescript
112
+ // MCP mem-search → ProgressiveRetriever.smartSearch()
113
+ // MCP mem-timeline → ProgressiveRetriever.getTimeline()
114
+ // MCP mem-details → ProgressiveRetriever.getDetails()
115
+ ```
116
+
117
+ ### 3.3 저장소 공유
118
+
119
+ ```
120
+ ~/.claude-code/memory/
121
+ ├── events.duckdb ← CLI, MCP 모두 접근
122
+ └── vectors/ ← CLI, MCP 모두 접근
123
+ ```
124
+
125
+ ## 4. 설계 결정 사항
126
+
127
+ ### 4.1 패키지 구조
128
+
129
+ **옵션 1: 단일 패키지**
130
+ ```
131
+ code-memory/
132
+ ├── src/
133
+ │ ├── cli/
134
+ │ ├── core/
135
+ │ └── mcp/
136
+ ```
137
+
138
+ **옵션 2: 별도 패키지 (선택)**
139
+ ```
140
+ code-memory/
141
+ ├── packages/
142
+ │ ├── core/ # 공유 로직
143
+ │ ├── cli/ # CLI
144
+ │ └── mcp-server/ # MCP 서버
145
+ ```
146
+
147
+ **선택 이유**:
148
+ - 독립적 버전 관리
149
+ - npm 별도 배포 가능
150
+ - 의존성 분리
151
+
152
+ ### 4.2 전송 방식
153
+
154
+ **stdio (선택)**:
155
+ - Claude Desktop 기본 지원
156
+ - 로컬 실행, 보안 이점
157
+ - 설정 간단
158
+
159
+ **HTTP**:
160
+ - 원격 접근 가능
161
+ - 추가 보안 필요
162
+ - 포트 충돌 가능
163
+
164
+ ### 4.3 도구 설계
165
+
166
+ **Progressive Disclosure 패턴**:
167
+ 1. `mem-search`: Layer 1 (인덱스)
168
+ 2. `mem-timeline`: Layer 2 (타임라인)
169
+ 3. `mem-details`: Layer 3 (상세)
170
+
171
+ **이유**:
172
+ - 토큰 효율성
173
+ - 단계적 정보 제공
174
+ - 필요한 것만 조회
175
+
176
+ ## 5. Claude Desktop 설정
177
+
178
+ ### 5.1 설정 파일 위치
179
+
180
+ | OS | 경로 |
181
+ |------|------|
182
+ | macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` |
183
+ | Windows | `%APPDATA%\Claude\claude_desktop_config.json` |
184
+ | Linux | `~/.config/claude/claude_desktop_config.json` |
185
+
186
+ ### 5.2 설정 형식
187
+
188
+ ```json
189
+ {
190
+ "mcpServers": {
191
+ "server-name": {
192
+ "command": "실행 명령",
193
+ "args": ["인자들"],
194
+ "env": {
195
+ "환경변수": "값"
196
+ }
197
+ }
198
+ }
199
+ }
200
+ ```
201
+
202
+ ### 5.3 자동 설치의 이점
203
+
204
+ ```bash
205
+ $ code-memory mcp install
206
+ ```
207
+
208
+ **수동 설정 시 문제**:
209
+ - JSON 문법 오류 가능
210
+ - 경로 오타
211
+ - 플랫폼별 차이
212
+
213
+ **자동 설치 이점**:
214
+ - 오류 방지
215
+ - 플랫폼 자동 감지
216
+ - 설정 검증
217
+
218
+ ## 6. 보안 고려사항
219
+
220
+ ### 6.1 로컬 전용
221
+
222
+ ```typescript
223
+ // stdio 전송만 사용 (네트워크 노출 없음)
224
+ const transport = new StdioServerTransport();
225
+ ```
226
+
227
+ ### 6.2 경로 제한
228
+
229
+ ```typescript
230
+ // 홈 디렉토리 외부 접근 차단
231
+ const memoryPath = process.env.MEMORY_PATH;
232
+ if (!memoryPath.startsWith(os.homedir())) {
233
+ throw new Error('Invalid memory path');
234
+ }
235
+ ```
236
+
237
+ ### 6.3 Privacy 필터 적용
238
+
239
+ ```typescript
240
+ // MCP 응답에도 privacy 필터 적용
241
+ const filtered = applyPrivacyFilter(content, config.privacy);
242
+ ```
243
+
244
+ ## 7. 사용 시나리오
245
+
246
+ ### 7.1 Claude Desktop에서 검색
247
+
248
+ ```
249
+ User: "지난번에 DuckDB 스키마 어떻게 설계했었지?"
250
+
251
+ Claude: [mem-search 도구 호출]
252
+ query: "DuckDB 스키마 설계"
253
+
254
+ Found 2 relevant memories:
255
+
256
+ 1. [mem:a7Bc3x] (0.94)
257
+ DuckDB를 사용하여 이벤트 소싱 패턴을...
258
+
259
+ 지난번에 이벤트 소싱 패턴으로 설계하셨네요.
260
+ 자세한 내용을 보시려면 말씀해주세요.
261
+ ```
262
+
263
+ ### 7.2 상세 조회
264
+
265
+ ```
266
+ User: "첫 번째 결과 자세히 보여줘"
267
+
268
+ Claude: [mem-details 도구 호출]
269
+ ids: ["a7Bc3x"]
270
+
271
+ [전체 내용 표시]
272
+ ```
273
+
274
+ ## 8. 참고 자료
275
+
276
+ - **MCP 공식 문서**: https://modelcontextprotocol.io/
277
+ - **claude-mem MCP**: Desktop integration via MCP
278
+ - **Anthropic SDK**: @modelcontextprotocol/sdk