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.
- package/.claude-plugin/commands/memory-forget.md +42 -0
- package/.claude-plugin/commands/memory-history.md +34 -0
- package/.claude-plugin/commands/memory-import.md +56 -0
- package/.claude-plugin/commands/memory-list.md +37 -0
- package/.claude-plugin/commands/memory-search.md +36 -0
- package/.claude-plugin/commands/memory-stats.md +34 -0
- package/.claude-plugin/hooks.json +59 -0
- package/.claude-plugin/plugin.json +24 -0
- package/.history/package_20260201112328.json +45 -0
- package/.history/package_20260201113602.json +45 -0
- package/.history/package_20260201113713.json +45 -0
- package/.history/package_20260201114110.json +45 -0
- package/Memo.txt +558 -0
- package/README.md +520 -0
- package/context.md +636 -0
- package/dist/.claude-plugin/commands/memory-forget.md +42 -0
- package/dist/.claude-plugin/commands/memory-history.md +34 -0
- package/dist/.claude-plugin/commands/memory-import.md +56 -0
- package/dist/.claude-plugin/commands/memory-list.md +37 -0
- package/dist/.claude-plugin/commands/memory-search.md +36 -0
- package/dist/.claude-plugin/commands/memory-stats.md +34 -0
- package/dist/.claude-plugin/hooks.json +59 -0
- package/dist/.claude-plugin/plugin.json +24 -0
- package/dist/cli/index.js +3539 -0
- package/dist/cli/index.js.map +7 -0
- package/dist/core/index.js +4408 -0
- package/dist/core/index.js.map +7 -0
- package/dist/hooks/session-end.js +2971 -0
- package/dist/hooks/session-end.js.map +7 -0
- package/dist/hooks/session-start.js +2969 -0
- package/dist/hooks/session-start.js.map +7 -0
- package/dist/hooks/stop.js +3123 -0
- package/dist/hooks/stop.js.map +7 -0
- package/dist/hooks/user-prompt-submit.js +2960 -0
- package/dist/hooks/user-prompt-submit.js.map +7 -0
- package/dist/services/memory-service.js +2931 -0
- package/dist/services/memory-service.js.map +7 -0
- package/package.json +45 -0
- package/plan.md +1642 -0
- package/scripts/build.ts +102 -0
- package/spec.md +624 -0
- package/specs/citations-system/context.md +243 -0
- package/specs/citations-system/plan.md +495 -0
- package/specs/citations-system/spec.md +371 -0
- package/specs/endless-mode/context.md +305 -0
- package/specs/endless-mode/plan.md +620 -0
- package/specs/endless-mode/spec.md +455 -0
- package/specs/entity-edge-model/context.md +401 -0
- package/specs/entity-edge-model/plan.md +459 -0
- package/specs/entity-edge-model/spec.md +391 -0
- package/specs/evidence-aligner-v2/context.md +401 -0
- package/specs/evidence-aligner-v2/plan.md +303 -0
- package/specs/evidence-aligner-v2/spec.md +312 -0
- package/specs/mcp-desktop-integration/context.md +278 -0
- package/specs/mcp-desktop-integration/plan.md +550 -0
- package/specs/mcp-desktop-integration/spec.md +494 -0
- package/specs/post-tool-use-hook/context.md +319 -0
- package/specs/post-tool-use-hook/plan.md +469 -0
- package/specs/post-tool-use-hook/spec.md +364 -0
- package/specs/private-tags/context.md +288 -0
- package/specs/private-tags/plan.md +412 -0
- package/specs/private-tags/spec.md +345 -0
- package/specs/progressive-disclosure/context.md +346 -0
- package/specs/progressive-disclosure/plan.md +663 -0
- package/specs/progressive-disclosure/spec.md +415 -0
- package/specs/task-entity-system/context.md +297 -0
- package/specs/task-entity-system/plan.md +301 -0
- package/specs/task-entity-system/spec.md +314 -0
- package/specs/vector-outbox-v2/context.md +470 -0
- package/specs/vector-outbox-v2/plan.md +562 -0
- package/specs/vector-outbox-v2/spec.md +466 -0
- package/specs/web-viewer-ui/context.md +384 -0
- package/specs/web-viewer-ui/plan.md +797 -0
- package/specs/web-viewer-ui/spec.md +516 -0
- package/src/cli/index.ts +570 -0
- package/src/core/canonical-key.ts +186 -0
- package/src/core/citation-generator.ts +63 -0
- package/src/core/consolidated-store.ts +279 -0
- package/src/core/consolidation-worker.ts +384 -0
- package/src/core/context-formatter.ts +276 -0
- package/src/core/continuity-manager.ts +336 -0
- package/src/core/edge-repo.ts +324 -0
- package/src/core/embedder.ts +124 -0
- package/src/core/entity-repo.ts +342 -0
- package/src/core/event-store.ts +672 -0
- package/src/core/evidence-aligner.ts +635 -0
- package/src/core/graduation.ts +365 -0
- package/src/core/index.ts +32 -0
- package/src/core/matcher.ts +210 -0
- package/src/core/metadata-extractor.ts +203 -0
- package/src/core/privacy/filter.ts +179 -0
- package/src/core/privacy/index.ts +20 -0
- package/src/core/privacy/tag-parser.ts +145 -0
- package/src/core/progressive-retriever.ts +415 -0
- package/src/core/retriever.ts +235 -0
- package/src/core/task/blocker-resolver.ts +325 -0
- package/src/core/task/index.ts +9 -0
- package/src/core/task/task-matcher.ts +238 -0
- package/src/core/task/task-projector.ts +345 -0
- package/src/core/task/task-resolver.ts +414 -0
- package/src/core/types.ts +841 -0
- package/src/core/vector-outbox.ts +295 -0
- package/src/core/vector-store.ts +182 -0
- package/src/core/vector-worker.ts +488 -0
- package/src/core/working-set-store.ts +244 -0
- package/src/hooks/post-tool-use.ts +127 -0
- package/src/hooks/session-end.ts +78 -0
- package/src/hooks/session-start.ts +57 -0
- package/src/hooks/stop.ts +78 -0
- package/src/hooks/user-prompt-submit.ts +54 -0
- package/src/mcp/handlers.ts +212 -0
- package/src/mcp/index.ts +47 -0
- package/src/mcp/tools.ts +78 -0
- package/src/server/api/citations.ts +101 -0
- package/src/server/api/events.ts +101 -0
- package/src/server/api/index.ts +18 -0
- package/src/server/api/search.ts +98 -0
- package/src/server/api/sessions.ts +111 -0
- package/src/server/api/stats.ts +97 -0
- package/src/server/index.ts +91 -0
- package/src/services/memory-service.ts +626 -0
- package/src/services/session-history-importer.ts +367 -0
- package/tests/canonical-key.test.ts +101 -0
- package/tests/evidence-aligner.test.ts +152 -0
- package/tests/matcher.test.ts +112 -0
- package/tsconfig.json +24 -0
- package/vitest.config.ts +15 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
# Citations System Specification
|
|
2
|
+
|
|
3
|
+
> **Version**: 1.0.0
|
|
4
|
+
> **Status**: Draft
|
|
5
|
+
> **Created**: 2026-02-01
|
|
6
|
+
> **Reference**: claude-mem (thedotmack/claude-mem)
|
|
7
|
+
|
|
8
|
+
## 1. 개요
|
|
9
|
+
|
|
10
|
+
### 1.1 문제 정의
|
|
11
|
+
|
|
12
|
+
현재 시스템에서 메모리 출처 추적이 어려움:
|
|
13
|
+
|
|
14
|
+
1. **출처 불명확**: 검색 결과가 어느 세션에서 왔는지 즉시 파악 어려움
|
|
15
|
+
2. **검증 불가**: AI가 참조한 정보의 원본 확인 어려움
|
|
16
|
+
3. **맥락 손실**: 인용된 정보의 전후 맥락 파악 어려움
|
|
17
|
+
|
|
18
|
+
### 1.2 해결 방향
|
|
19
|
+
|
|
20
|
+
**Citations (인용) 시스템**:
|
|
21
|
+
- 모든 메모리에 고유 인용 ID 부여
|
|
22
|
+
- 컨텍스트 주입 시 인용 표시
|
|
23
|
+
- 클릭/명령으로 원본 조회 가능
|
|
24
|
+
|
|
25
|
+
## 2. 핵심 개념
|
|
26
|
+
|
|
27
|
+
### 2.1 인용 형식
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
[mem:abc123] 에서 참조한 정보입니다.
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2.2 인용 구조
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
interface Citation {
|
|
37
|
+
// 식별
|
|
38
|
+
id: string; // 짧은 인용 ID (6-8자)
|
|
39
|
+
eventId: string; // 전체 이벤트 ID
|
|
40
|
+
|
|
41
|
+
// 출처 정보
|
|
42
|
+
sessionId: string;
|
|
43
|
+
timestamp: Date;
|
|
44
|
+
eventType: 'prompt' | 'response' | 'tool' | 'insight';
|
|
45
|
+
|
|
46
|
+
// 메타데이터
|
|
47
|
+
preview: string; // 50자 미리보기
|
|
48
|
+
confidence: number; // 매칭 신뢰도
|
|
49
|
+
relevanceScore: number; // 검색 관련성 점수
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 2.3 인용 ID 생성
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
// 짧고 읽기 쉬운 ID
|
|
57
|
+
function generateCitationId(eventId: string): string {
|
|
58
|
+
// eventId의 해시에서 6자 추출
|
|
59
|
+
const hash = crypto.createHash('sha256')
|
|
60
|
+
.update(eventId)
|
|
61
|
+
.digest('base64url')
|
|
62
|
+
.slice(0, 6);
|
|
63
|
+
|
|
64
|
+
return hash; // 예: "a7Bc3x"
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 3. 데이터 스키마
|
|
69
|
+
|
|
70
|
+
### 3.1 인용 테이블
|
|
71
|
+
|
|
72
|
+
```sql
|
|
73
|
+
CREATE TABLE citations (
|
|
74
|
+
citation_id VARCHAR(8) PRIMARY KEY,
|
|
75
|
+
event_id VARCHAR NOT NULL REFERENCES events(event_id),
|
|
76
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
77
|
+
|
|
78
|
+
-- 인덱스
|
|
79
|
+
UNIQUE(event_id)
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
CREATE INDEX idx_citations_event ON citations(event_id);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 3.2 이벤트 확장
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const EventSchema = z.object({
|
|
89
|
+
eventId: z.string(),
|
|
90
|
+
// ... 기존 필드
|
|
91
|
+
|
|
92
|
+
// 인용 정보 추가
|
|
93
|
+
citationId: z.string().optional(), // 생성된 인용 ID
|
|
94
|
+
});
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 4. 인용 생성 흐름
|
|
98
|
+
|
|
99
|
+
### 4.1 자동 생성
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
// 이벤트 저장 시 자동으로 인용 ID 생성
|
|
103
|
+
async function storeEventWithCitation(event: Event): Promise<string> {
|
|
104
|
+
const eventId = await eventStore.append(event);
|
|
105
|
+
|
|
106
|
+
// 인용 ID 생성 및 저장
|
|
107
|
+
const citationId = generateCitationId(eventId);
|
|
108
|
+
await citationStore.create({
|
|
109
|
+
citationId,
|
|
110
|
+
eventId,
|
|
111
|
+
createdAt: new Date()
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return eventId;
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 4.2 지연 생성
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
// 검색 시 필요할 때만 인용 ID 생성
|
|
122
|
+
async function getCitationId(eventId: string): Promise<string> {
|
|
123
|
+
// 기존 인용 확인
|
|
124
|
+
const existing = await citationStore.findByEventId(eventId);
|
|
125
|
+
if (existing) {
|
|
126
|
+
return existing.citationId;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// 새로 생성
|
|
130
|
+
const citationId = generateCitationId(eventId);
|
|
131
|
+
await citationStore.create({ citationId, eventId });
|
|
132
|
+
return citationId;
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## 5. 컨텍스트 주입
|
|
137
|
+
|
|
138
|
+
### 5.1 인용 포함 포맷
|
|
139
|
+
|
|
140
|
+
```markdown
|
|
141
|
+
## Relevant Context
|
|
142
|
+
|
|
143
|
+
Based on previous conversations:
|
|
144
|
+
|
|
145
|
+
> DuckDB를 사용하여 이벤트 소싱 패턴을 구현하는 것이 좋습니다.
|
|
146
|
+
> 이벤트는 불변이어야 하며, append-only 방식으로 저장합니다.
|
|
147
|
+
>
|
|
148
|
+
> [mem:a7Bc3x] - 2026-01-30, Session abc123
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
> 타입 안전성을 위해 Zod 스키마를 사용하세요.
|
|
153
|
+
>
|
|
154
|
+
> [mem:x9Yz2w] - 2026-01-29, Session def456
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 5.2 포맷터 구현
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
interface CitedMemory {
|
|
161
|
+
content: string;
|
|
162
|
+
citation: Citation;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function formatCitedContext(memories: CitedMemory[]): string {
|
|
166
|
+
const parts = memories.map(m => {
|
|
167
|
+
const lines = [
|
|
168
|
+
`> ${m.content}`,
|
|
169
|
+
`>`,
|
|
170
|
+
`> [mem:${m.citation.id}] - ${formatDate(m.citation.timestamp)}, ` +
|
|
171
|
+
`Session ${m.citation.sessionId.slice(0, 6)}`
|
|
172
|
+
];
|
|
173
|
+
return lines.join('\n');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return [
|
|
177
|
+
'## Relevant Context',
|
|
178
|
+
'',
|
|
179
|
+
'Based on previous conversations:',
|
|
180
|
+
'',
|
|
181
|
+
parts.join('\n\n---\n\n')
|
|
182
|
+
].join('\n');
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## 6. 인용 조회
|
|
187
|
+
|
|
188
|
+
### 6.1 CLI 명령
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# 인용 ID로 원본 조회
|
|
192
|
+
$ code-memory show mem:a7Bc3x
|
|
193
|
+
|
|
194
|
+
📄 Memory Citation: a7Bc3x
|
|
195
|
+
|
|
196
|
+
Session: abc123
|
|
197
|
+
Date: 2026-01-30 14:05
|
|
198
|
+
Type: assistant_response
|
|
199
|
+
|
|
200
|
+
Content:
|
|
201
|
+
────────────────────────────────────────
|
|
202
|
+
DuckDB를 사용하여 이벤트 소싱 패턴을 구현하는 것이 좋습니다.
|
|
203
|
+
이벤트는 불변이어야 하며, append-only 방식으로 저장합니다.
|
|
204
|
+
|
|
205
|
+
스키마 예시:
|
|
206
|
+
```sql
|
|
207
|
+
CREATE TABLE events (
|
|
208
|
+
event_id VARCHAR PRIMARY KEY,
|
|
209
|
+
...
|
|
210
|
+
);
|
|
211
|
+
```
|
|
212
|
+
────────────────────────────────────────
|
|
213
|
+
|
|
214
|
+
Related:
|
|
215
|
+
Previous: [mem:b8Xc2y] - User question about DB design
|
|
216
|
+
Next: [mem:c9Yd3z] - Follow-up on indexing
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### 6.2 API 엔드포인트
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
// GET /api/citations/:id
|
|
223
|
+
router.get('/citations/:id', async (c) => {
|
|
224
|
+
const { id } = c.req.param();
|
|
225
|
+
|
|
226
|
+
const citation = await citationStore.findById(id);
|
|
227
|
+
if (!citation) {
|
|
228
|
+
return c.json({ error: 'Citation not found' }, 404);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const event = await eventStore.findById(citation.eventId);
|
|
232
|
+
const related = await getRelatedEvents(citation.eventId);
|
|
233
|
+
|
|
234
|
+
return c.json({
|
|
235
|
+
citation,
|
|
236
|
+
event,
|
|
237
|
+
related
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### 6.3 슬래시 명령
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
User: /show a7Bc3x
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
이 메모리의 전체 내용을 보여드립니다:
|
|
249
|
+
|
|
250
|
+
[원본 내용 표시]
|
|
251
|
+
---
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## 7. 인용 검색
|
|
255
|
+
|
|
256
|
+
### 7.1 인용 ID로 검색
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
async function searchByCitation(citationId: string): Promise<Event | null> {
|
|
260
|
+
const citation = await citationStore.findById(citationId);
|
|
261
|
+
if (!citation) return null;
|
|
262
|
+
|
|
263
|
+
return eventStore.findById(citation.eventId);
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### 7.2 역참조 검색
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
// 특정 이벤트를 인용한 세션들 조회
|
|
271
|
+
async function findCitingSession(citationId: string): Promise<string[]> {
|
|
272
|
+
// 인용 사용 로그에서 검색
|
|
273
|
+
const usages = await citationUsageStore.findByCitationId(citationId);
|
|
274
|
+
return [...new Set(usages.map(u => u.sessionId))];
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## 8. 인용 사용 추적
|
|
279
|
+
|
|
280
|
+
### 8.1 사용 로그
|
|
281
|
+
|
|
282
|
+
```sql
|
|
283
|
+
CREATE TABLE citation_usages (
|
|
284
|
+
usage_id VARCHAR PRIMARY KEY,
|
|
285
|
+
citation_id VARCHAR NOT NULL,
|
|
286
|
+
session_id VARCHAR NOT NULL,
|
|
287
|
+
used_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
288
|
+
context VARCHAR -- 어떤 쿼리에서 사용됐는지
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
CREATE INDEX idx_usages_citation ON citation_usages(citation_id);
|
|
292
|
+
CREATE INDEX idx_usages_session ON citation_usages(session_id);
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### 8.2 인기 인용 통계
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
async function getPopularCitations(limit: number = 10): Promise<CitationStats[]> {
|
|
299
|
+
return db.query(`
|
|
300
|
+
SELECT
|
|
301
|
+
c.citation_id,
|
|
302
|
+
COUNT(u.usage_id) as usage_count,
|
|
303
|
+
MAX(u.used_at) as last_used
|
|
304
|
+
FROM citations c
|
|
305
|
+
LEFT JOIN citation_usages u ON c.citation_id = u.citation_id
|
|
306
|
+
GROUP BY c.citation_id
|
|
307
|
+
ORDER BY usage_count DESC
|
|
308
|
+
LIMIT ?
|
|
309
|
+
`, [limit]);
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## 9. UI 표시
|
|
314
|
+
|
|
315
|
+
### 9.1 CLI
|
|
316
|
+
|
|
317
|
+
```
|
|
318
|
+
$ code-memory search "DuckDB"
|
|
319
|
+
|
|
320
|
+
🔍 Search Results:
|
|
321
|
+
|
|
322
|
+
#1 [mem:a7Bc3x] (score: 0.94)
|
|
323
|
+
"DuckDB를 사용하여 이벤트 소싱 패턴을..."
|
|
324
|
+
📅 2026-01-30 | 🔗 Session abc123
|
|
325
|
+
|
|
326
|
+
#2 [mem:d4Ef5g] (score: 0.87)
|
|
327
|
+
"DuckDB의 인덱싱 전략..."
|
|
328
|
+
📅 2026-01-29 | 🔗 Session def456
|
|
329
|
+
|
|
330
|
+
💡 Use "code-memory show mem:a7Bc3x" for full content
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### 9.2 Web Viewer
|
|
334
|
+
|
|
335
|
+
```html
|
|
336
|
+
<div class="search-result">
|
|
337
|
+
<div class="result-header">
|
|
338
|
+
<span class="citation-badge" title="Click to copy">
|
|
339
|
+
[mem:a7Bc3x]
|
|
340
|
+
</span>
|
|
341
|
+
<span class="score">0.94</span>
|
|
342
|
+
</div>
|
|
343
|
+
<p class="preview">DuckDB를 사용하여 이벤트 소싱 패턴을...</p>
|
|
344
|
+
<div class="metadata">
|
|
345
|
+
<span>📅 2026-01-30</span>
|
|
346
|
+
<a href="/sessions/abc123">🔗 Session abc123</a>
|
|
347
|
+
</div>
|
|
348
|
+
<button onclick="showCitation('a7Bc3x')">View Full</button>
|
|
349
|
+
</div>
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## 10. 설정
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
const CitationsConfigSchema = z.object({
|
|
356
|
+
enabled: z.boolean().default(true),
|
|
357
|
+
idLength: z.number().default(6), // 인용 ID 길이
|
|
358
|
+
includeInContext: z.boolean().default(true), // 컨텍스트에 포함
|
|
359
|
+
trackUsage: z.boolean().default(true), // 사용 추적
|
|
360
|
+
format: z.enum(['inline', 'footnote', 'reference']).default('inline')
|
|
361
|
+
});
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## 11. 성공 기준
|
|
365
|
+
|
|
366
|
+
- [ ] 모든 이벤트에 인용 ID 자동 생성
|
|
367
|
+
- [ ] 컨텍스트 주입 시 인용 표시
|
|
368
|
+
- [ ] `code-memory show mem:xxx` 명령 동작
|
|
369
|
+
- [ ] Web Viewer에서 인용 클릭 시 원본 표시
|
|
370
|
+
- [ ] 인용 사용 통계 수집
|
|
371
|
+
- [ ] 인용 ID 충돌 없음 (6자, 64^6 = 687억 조합)
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# Endless Mode 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은 "Endless Mode"를 Beta 기능으로 제공:
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
Biomimetic Memory Architecture for extended sessions
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**특징**:
|
|
17
|
+
- 세션 경계 없는 연속 메모리
|
|
18
|
+
- 자동 컨텍스트 통합
|
|
19
|
+
- 장기 학습 지원
|
|
20
|
+
|
|
21
|
+
### 1.2 인간 기억 시스템 모방
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
Human Memory:
|
|
25
|
+
┌─────────────────────────────────────────┐
|
|
26
|
+
│ Sensory → Working → Long-term │
|
|
27
|
+
│ (즉각) (단기) (장기) │
|
|
28
|
+
└─────────────────────────────────────────┘
|
|
29
|
+
|
|
30
|
+
Endless Mode:
|
|
31
|
+
┌─────────────────────────────────────────┐
|
|
32
|
+
│ Events → Working Set → Consolidated │
|
|
33
|
+
│ (L0) (Active) (Integrated) │
|
|
34
|
+
└─────────────────────────────────────────┘
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### 1.3 현재 code-memory의 세션 모델
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// 현재 세션 기반 모델
|
|
41
|
+
session_start → [conversations] → session_end
|
|
42
|
+
↓
|
|
43
|
+
session_summary
|
|
44
|
+
↓
|
|
45
|
+
(새 세션에서 검색)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**한계**:
|
|
49
|
+
1. 세션 경계에서 컨텍스트 단절
|
|
50
|
+
2. 재시작 시 처음부터 컨텍스트 구축
|
|
51
|
+
3. 장기 프로젝트에서 지식 파편화
|
|
52
|
+
|
|
53
|
+
## 2. Biomimetic Memory 개념
|
|
54
|
+
|
|
55
|
+
### 2.1 Working Memory (작업 기억)
|
|
56
|
+
|
|
57
|
+
인간의 작업 기억:
|
|
58
|
+
- 용량 제한: 7±2 항목
|
|
59
|
+
- 지속 시간: 15-30초
|
|
60
|
+
- 적극적 유지 필요
|
|
61
|
+
|
|
62
|
+
Endless Mode 적용:
|
|
63
|
+
```typescript
|
|
64
|
+
const workingSet = {
|
|
65
|
+
maxEvents: 100, // 용량 제한
|
|
66
|
+
timeWindowHours: 24, // 시간 제한
|
|
67
|
+
activeRehearsal: true // 관련성 높은 것 유지
|
|
68
|
+
};
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 2.2 Memory Consolidation (기억 통합)
|
|
72
|
+
|
|
73
|
+
인간의 기억 통합:
|
|
74
|
+
- 수면 중 발생
|
|
75
|
+
- 관련 기억 연결
|
|
76
|
+
- 불필요한 세부사항 제거
|
|
77
|
+
- 패턴 추출
|
|
78
|
+
|
|
79
|
+
Endless Mode 적용:
|
|
80
|
+
```typescript
|
|
81
|
+
const consolidation = {
|
|
82
|
+
triggerIdleTime: 30 * 60 * 1000, // 유휴 시 통합 (수면 유사)
|
|
83
|
+
groupByTopic: true, // 관련 기억 그룹화
|
|
84
|
+
summarize: true, // 세부사항 요약
|
|
85
|
+
extractPatterns: true // 패턴 추출
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 2.3 Context-Dependent Memory
|
|
90
|
+
|
|
91
|
+
인간: 특정 맥락에서 관련 기억 활성화
|
|
92
|
+
|
|
93
|
+
Endless Mode:
|
|
94
|
+
```typescript
|
|
95
|
+
// 현재 컨텍스트와 유사한 과거 컨텍스트 활성화
|
|
96
|
+
const relevantContext = await findSimilarContext(currentQuery);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 3. 기존 코드와의 관계
|
|
100
|
+
|
|
101
|
+
### 3.1 Graduation 파이프라인과의 관계
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
기존 Graduation:
|
|
105
|
+
L0 (Raw) → L1 (Structured) → L2 (Validated) → L3 (Verified) → L4 (Active)
|
|
106
|
+
|
|
107
|
+
Endless Mode 추가:
|
|
108
|
+
L0 (Raw) → Working Set → Consolidated Memory
|
|
109
|
+
↓ ↓
|
|
110
|
+
(Active) (Long-term)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**통합 방안**:
|
|
114
|
+
- Working Set은 L0-L2 이벤트 포함
|
|
115
|
+
- Consolidated Memory는 L3-L4 수준의 검증된 지식
|
|
116
|
+
|
|
117
|
+
### 3.2 Event Store
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// 기존: 세션 기반 저장
|
|
121
|
+
await eventStore.append({
|
|
122
|
+
sessionId: currentSession,
|
|
123
|
+
...event
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Endless Mode: 세션 개념 유연화
|
|
127
|
+
await eventStore.append({
|
|
128
|
+
sessionId: endlessSessionId, // 고정 또는 날짜 기반
|
|
129
|
+
workingSetId: currentWorkingSet,
|
|
130
|
+
...event
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 3.3 Retriever
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
// 기존
|
|
138
|
+
async search(query): Promise<Event[]>
|
|
139
|
+
|
|
140
|
+
// Endless Mode 확장
|
|
141
|
+
async searchWithContext(query, options): Promise<{
|
|
142
|
+
workingSet: Event[];
|
|
143
|
+
consolidated: ConsolidatedMemory[];
|
|
144
|
+
continuityScore: number;
|
|
145
|
+
}>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## 4. 설계 결정 사항
|
|
149
|
+
|
|
150
|
+
### 4.1 세션 ID 처리
|
|
151
|
+
|
|
152
|
+
**옵션 1: 고정 세션 ID**
|
|
153
|
+
```typescript
|
|
154
|
+
const ENDLESS_SESSION_ID = 'endless';
|
|
155
|
+
```
|
|
156
|
+
- 단순함
|
|
157
|
+
- 기존 코드 호환
|
|
158
|
+
|
|
159
|
+
**옵션 2: 날짜 기반 세션 ID**
|
|
160
|
+
```typescript
|
|
161
|
+
const sessionId = `endless_${format(new Date(), 'yyyy-MM-dd')}`;
|
|
162
|
+
```
|
|
163
|
+
- 일별 구분 가능
|
|
164
|
+
- 통계/분석 용이
|
|
165
|
+
|
|
166
|
+
**선택**: 하이브리드
|
|
167
|
+
- Endless Mode 내부: 날짜 기반
|
|
168
|
+
- 외부 인터페이스: 'endless'로 통합
|
|
169
|
+
|
|
170
|
+
### 4.2 통합 트리거
|
|
171
|
+
|
|
172
|
+
**옵션 1: 시간 기반만**
|
|
173
|
+
```typescript
|
|
174
|
+
setInterval(consolidate, 1 * 60 * 60 * 1000); // 1시간마다
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**옵션 2: 이벤트 수 기반만**
|
|
178
|
+
```typescript
|
|
179
|
+
if (workingSet.length >= 100) consolidate();
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**옵션 3: 하이브리드 (선택)**
|
|
183
|
+
```typescript
|
|
184
|
+
// 세 가지 조건 중 하나라도 충족 시
|
|
185
|
+
if (
|
|
186
|
+
timeSinceLastConsolidation >= 1 * 60 * 60 * 1000 ||
|
|
187
|
+
workingSet.length >= 100 ||
|
|
188
|
+
idleTime >= 30 * 60 * 1000
|
|
189
|
+
) {
|
|
190
|
+
consolidate();
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### 4.3 요약 생성
|
|
195
|
+
|
|
196
|
+
**옵션 1: 규칙 기반만**
|
|
197
|
+
```typescript
|
|
198
|
+
// 키포인트 추출
|
|
199
|
+
const summary = events
|
|
200
|
+
.map(e => extractKeyPoint(e))
|
|
201
|
+
.join('\n');
|
|
202
|
+
```
|
|
203
|
+
- 빠름, 무료
|
|
204
|
+
- 품질 제한
|
|
205
|
+
|
|
206
|
+
**옵션 2: LLM 기반**
|
|
207
|
+
```typescript
|
|
208
|
+
const summary = await llm.summarize(events);
|
|
209
|
+
```
|
|
210
|
+
- 고품질
|
|
211
|
+
- 비용, 지연
|
|
212
|
+
|
|
213
|
+
**선택**: 규칙 기반 기본, LLM 옵션
|
|
214
|
+
```typescript
|
|
215
|
+
if (config.useLLMSummarization) {
|
|
216
|
+
return await llmSummarize(events);
|
|
217
|
+
} else {
|
|
218
|
+
return extractKeyPoints(events);
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### 4.4 연속성 점수 가중치
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
const weights = {
|
|
226
|
+
topicOverlap: 0.3, // 주제 연속성
|
|
227
|
+
timeProximity: 0.3, // 시간 근접성
|
|
228
|
+
fileOverlap: 0.2, // 파일 연속성
|
|
229
|
+
entityOverlap: 0.2 // 엔티티 연속성
|
|
230
|
+
};
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
**조정 필요 시**:
|
|
234
|
+
- 코드 작업 중심: fileOverlap 가중치 증가
|
|
235
|
+
- 연구/학습 중심: topicOverlap 가중치 증가
|
|
236
|
+
|
|
237
|
+
## 5. 성능 고려사항
|
|
238
|
+
|
|
239
|
+
### 5.1 Working Set 크기
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
// 메모리 사용량 추정
|
|
243
|
+
// 100 이벤트 × 평균 2KB = 200KB
|
|
244
|
+
const maxWorkingSetSize = 100;
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### 5.2 Consolidation 비용
|
|
248
|
+
|
|
249
|
+
```typescript
|
|
250
|
+
// 통합 작업 시간 추정
|
|
251
|
+
// 100 이벤트 그룹화 + 요약: ~100ms
|
|
252
|
+
// LLM 요약 사용 시: ~2s
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### 5.3 검색 성능
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
// Working Set 검색: O(n), n=100, ~1ms
|
|
259
|
+
// Consolidated 검색: 벡터 검색, ~50ms
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## 6. 마이그레이션
|
|
263
|
+
|
|
264
|
+
### 6.1 Session → Endless
|
|
265
|
+
|
|
266
|
+
```typescript
|
|
267
|
+
async function migrateToEndless(): Promise<void> {
|
|
268
|
+
// 1. 최근 세션 이벤트를 Working Set에 추가
|
|
269
|
+
const recentEvents = await getRecentEvents(7 * 24); // 7일
|
|
270
|
+
|
|
271
|
+
for (const event of recentEvents) {
|
|
272
|
+
await workingSetStore.add(event);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// 2. 기존 세션 요약을 Consolidated Memory로 이전
|
|
276
|
+
const summaries = await getSessionSummaries();
|
|
277
|
+
|
|
278
|
+
for (const summary of summaries) {
|
|
279
|
+
await consolidatedStore.create({
|
|
280
|
+
summary: summary.content,
|
|
281
|
+
sourceEvents: [], // 원본 연결 불가
|
|
282
|
+
confidence: 0.6 // 낮은 신뢰도
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
### 6.2 Endless → Session 복귀
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
async function revertToSession(): Promise<void> {
|
|
292
|
+
// 모드만 변경, 데이터 유지
|
|
293
|
+
await setConfig('mode', 'session');
|
|
294
|
+
|
|
295
|
+
// Working Set과 Consolidated Memory는 유지
|
|
296
|
+
// (향후 Endless Mode 재활성화 시 활용)
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## 7. 참고 자료
|
|
301
|
+
|
|
302
|
+
- **claude-mem Beta**: Endless Mode, Biomimetic Memory Architecture
|
|
303
|
+
- **Cognitive Psychology**: Working Memory (Baddeley), Memory Consolidation
|
|
304
|
+
- **Spaced Repetition**: 장기 기억 강화 기법
|
|
305
|
+
- **기존 specs**: graduation.ts, vector-worker.ts
|