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,620 @@
|
|
|
1
|
+
# Endless Mode 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 MemoryModeSchema = z.enum(['session', 'endless']);
|
|
15
|
+
export type MemoryMode = z.infer<typeof MemoryModeSchema>;
|
|
16
|
+
|
|
17
|
+
export const EndlessModeConfigSchema = z.object({
|
|
18
|
+
enabled: z.boolean().default(false),
|
|
19
|
+
|
|
20
|
+
workingSet: z.object({
|
|
21
|
+
maxEvents: z.number().default(100),
|
|
22
|
+
timeWindowHours: z.number().default(24),
|
|
23
|
+
minRelevanceScore: z.number().default(0.5)
|
|
24
|
+
}).default({}),
|
|
25
|
+
|
|
26
|
+
consolidation: z.object({
|
|
27
|
+
triggerIntervalMs: z.number().default(3600000),
|
|
28
|
+
triggerEventCount: z.number().default(100),
|
|
29
|
+
triggerIdleMs: z.number().default(1800000),
|
|
30
|
+
useLLMSummarization: z.boolean().default(false)
|
|
31
|
+
}).default({}),
|
|
32
|
+
|
|
33
|
+
continuity: z.object({
|
|
34
|
+
minScoreForSeamless: z.number().default(0.7),
|
|
35
|
+
topicDecayHours: z.number().default(48)
|
|
36
|
+
}).default({})
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// ConfigSchema 확장
|
|
40
|
+
export const ConfigSchema = z.object({
|
|
41
|
+
// ... 기존 설정
|
|
42
|
+
mode: MemoryModeSchema.default('session'),
|
|
43
|
+
endless: EndlessModeConfigSchema.optional()
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**작업 항목**:
|
|
48
|
+
- [ ] MemoryModeSchema 추가
|
|
49
|
+
- [ ] EndlessModeConfigSchema 추가
|
|
50
|
+
- [ ] ConfigSchema 확장
|
|
51
|
+
|
|
52
|
+
### 1.2 DB 스키마
|
|
53
|
+
|
|
54
|
+
**파일**: `src/core/event-store.ts` 수정
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
private async initSchema(): Promise<void> {
|
|
58
|
+
// 기존 테이블...
|
|
59
|
+
|
|
60
|
+
// Working Set 테이블
|
|
61
|
+
await this.db.exec(`
|
|
62
|
+
CREATE TABLE IF NOT EXISTS working_set (
|
|
63
|
+
id VARCHAR PRIMARY KEY,
|
|
64
|
+
event_id VARCHAR NOT NULL,
|
|
65
|
+
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
66
|
+
relevance_score FLOAT DEFAULT 1.0,
|
|
67
|
+
topics JSON,
|
|
68
|
+
expires_at TIMESTAMP
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
CREATE INDEX IF NOT EXISTS idx_working_set_expires
|
|
72
|
+
ON working_set(expires_at);
|
|
73
|
+
CREATE INDEX IF NOT EXISTS idx_working_set_relevance
|
|
74
|
+
ON working_set(relevance_score DESC);
|
|
75
|
+
`);
|
|
76
|
+
|
|
77
|
+
// Consolidated Memory 테이블
|
|
78
|
+
await this.db.exec(`
|
|
79
|
+
CREATE TABLE IF NOT EXISTS consolidated_memories (
|
|
80
|
+
memory_id VARCHAR PRIMARY KEY,
|
|
81
|
+
summary TEXT NOT NULL,
|
|
82
|
+
topics JSON,
|
|
83
|
+
source_events JSON,
|
|
84
|
+
confidence FLOAT DEFAULT 0.5,
|
|
85
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
86
|
+
accessed_at TIMESTAMP,
|
|
87
|
+
access_count INTEGER DEFAULT 0
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
CREATE INDEX IF NOT EXISTS idx_consolidated_confidence
|
|
91
|
+
ON consolidated_memories(confidence DESC);
|
|
92
|
+
`);
|
|
93
|
+
|
|
94
|
+
// Continuity Log 테이블
|
|
95
|
+
await this.db.exec(`
|
|
96
|
+
CREATE TABLE IF NOT EXISTS continuity_log (
|
|
97
|
+
log_id VARCHAR PRIMARY KEY,
|
|
98
|
+
from_context_id VARCHAR,
|
|
99
|
+
to_context_id VARCHAR,
|
|
100
|
+
continuity_score FLOAT,
|
|
101
|
+
transition_type VARCHAR,
|
|
102
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
103
|
+
);
|
|
104
|
+
`);
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**작업 항목**:
|
|
109
|
+
- [ ] working_set 테이블 생성
|
|
110
|
+
- [ ] consolidated_memories 테이블 생성
|
|
111
|
+
- [ ] continuity_log 테이블 생성
|
|
112
|
+
- [ ] 인덱스 생성
|
|
113
|
+
|
|
114
|
+
## Phase 2: Working Set 관리 (P0)
|
|
115
|
+
|
|
116
|
+
### 2.1 Working Set Store
|
|
117
|
+
|
|
118
|
+
**파일**: `src/core/working-set-store.ts` (신규)
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
export class WorkingSetStore {
|
|
122
|
+
constructor(private db: Database, private config: EndlessModeConfig) {}
|
|
123
|
+
|
|
124
|
+
async add(event: Event): Promise<void> {
|
|
125
|
+
const expiresAt = new Date(
|
|
126
|
+
Date.now() + this.config.workingSet.timeWindowHours * 60 * 60 * 1000
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
await this.db.run(`
|
|
130
|
+
INSERT OR REPLACE INTO working_set (id, event_id, added_at, expires_at)
|
|
131
|
+
VALUES (?, ?, ?, ?)
|
|
132
|
+
`, [crypto.randomUUID(), event.eventId, new Date(), expiresAt]);
|
|
133
|
+
|
|
134
|
+
// 크기 제한 적용
|
|
135
|
+
await this.enforceLimit();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async get(): Promise<WorkingSet> {
|
|
139
|
+
// 만료된 항목 정리
|
|
140
|
+
await this.db.run(`
|
|
141
|
+
DELETE FROM working_set WHERE expires_at < datetime('now')
|
|
142
|
+
`);
|
|
143
|
+
|
|
144
|
+
const items = await this.db.all(`
|
|
145
|
+
SELECT ws.*, e.*
|
|
146
|
+
FROM working_set ws
|
|
147
|
+
JOIN events e ON ws.event_id = e.event_id
|
|
148
|
+
ORDER BY ws.relevance_score DESC, ws.added_at DESC
|
|
149
|
+
LIMIT ?
|
|
150
|
+
`, [this.config.workingSet.maxEvents]);
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
recentEvents: items.map(i => i as Event),
|
|
154
|
+
lastActivity: items[0]?.added_at || new Date(),
|
|
155
|
+
continuityScore: await this.calculateContinuityScore()
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private async enforceLimit(): Promise<void> {
|
|
160
|
+
await this.db.run(`
|
|
161
|
+
DELETE FROM working_set
|
|
162
|
+
WHERE id NOT IN (
|
|
163
|
+
SELECT id FROM working_set
|
|
164
|
+
ORDER BY relevance_score DESC, added_at DESC
|
|
165
|
+
LIMIT ?
|
|
166
|
+
)
|
|
167
|
+
`, [this.config.workingSet.maxEvents]);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private async calculateContinuityScore(): Promise<number> {
|
|
171
|
+
// 최근 연속성 로그 기반 계산
|
|
172
|
+
const log = await this.db.get(`
|
|
173
|
+
SELECT AVG(continuity_score) as avg_score
|
|
174
|
+
FROM continuity_log
|
|
175
|
+
WHERE created_at > datetime('now', '-1 hour')
|
|
176
|
+
`);
|
|
177
|
+
|
|
178
|
+
return log?.avg_score || 0.5;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**작업 항목**:
|
|
184
|
+
- [ ] WorkingSetStore 클래스 구현
|
|
185
|
+
- [ ] add 메서드
|
|
186
|
+
- [ ] get 메서드
|
|
187
|
+
- [ ] enforceLimit 메서드
|
|
188
|
+
- [ ] calculateContinuityScore 메서드
|
|
189
|
+
|
|
190
|
+
### 2.2 훅 연동
|
|
191
|
+
|
|
192
|
+
**파일**: `src/hooks/stop.ts` 수정
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
export async function handleStop(input: StopInput): Promise<void> {
|
|
196
|
+
const memoryService = await MemoryService.getInstance();
|
|
197
|
+
const config = await memoryService.getConfig();
|
|
198
|
+
|
|
199
|
+
// 이벤트 저장 (기존)
|
|
200
|
+
const eventId = await memoryService.storeResponse(input);
|
|
201
|
+
|
|
202
|
+
// Endless Mode: Working Set에 추가
|
|
203
|
+
if (config.mode === 'endless') {
|
|
204
|
+
await memoryService.addToWorkingSet(eventId);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
**작업 항목**:
|
|
210
|
+
- [ ] stop 훅에서 Working Set 연동
|
|
211
|
+
- [ ] user-prompt-submit 훅에서 Working Set 연동
|
|
212
|
+
- [ ] post-tool-use 훅에서 Working Set 연동
|
|
213
|
+
|
|
214
|
+
## Phase 3: Consolidation Worker (P1)
|
|
215
|
+
|
|
216
|
+
### 3.1 Worker 구현
|
|
217
|
+
|
|
218
|
+
**파일**: `src/core/consolidation-worker.ts` (신규)
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
export class ConsolidationWorker {
|
|
222
|
+
private running = false;
|
|
223
|
+
private timeout: NodeJS.Timeout | null = null;
|
|
224
|
+
|
|
225
|
+
constructor(
|
|
226
|
+
private workingSetStore: WorkingSetStore,
|
|
227
|
+
private consolidatedStore: ConsolidatedStore,
|
|
228
|
+
private config: EndlessModeConfig
|
|
229
|
+
) {}
|
|
230
|
+
|
|
231
|
+
start(): void {
|
|
232
|
+
if (this.running) return;
|
|
233
|
+
this.running = true;
|
|
234
|
+
this.scheduleNext();
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
stop(): void {
|
|
238
|
+
this.running = false;
|
|
239
|
+
if (this.timeout) {
|
|
240
|
+
clearTimeout(this.timeout);
|
|
241
|
+
this.timeout = null;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
private scheduleNext(): void {
|
|
246
|
+
this.timeout = setTimeout(
|
|
247
|
+
() => this.run(),
|
|
248
|
+
this.config.consolidation.triggerIntervalMs
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
private async run(): Promise<void> {
|
|
253
|
+
if (!this.running) return;
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
await this.checkAndConsolidate();
|
|
257
|
+
} catch (error) {
|
|
258
|
+
console.error('Consolidation error:', error);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
this.scheduleNext();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private async checkAndConsolidate(): Promise<void> {
|
|
265
|
+
const workingSet = await this.workingSetStore.get();
|
|
266
|
+
|
|
267
|
+
if (!this.shouldConsolidate(workingSet)) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// 그룹화
|
|
272
|
+
const groups = this.groupByTopic(workingSet.recentEvents);
|
|
273
|
+
|
|
274
|
+
// 각 그룹 통합
|
|
275
|
+
for (const group of groups) {
|
|
276
|
+
if (group.events.length >= 3) { // 최소 3개 이벤트
|
|
277
|
+
const summary = await this.summarize(group);
|
|
278
|
+
|
|
279
|
+
await this.consolidatedStore.create({
|
|
280
|
+
summary,
|
|
281
|
+
topics: group.topics,
|
|
282
|
+
sourceEvents: group.events.map(e => e.eventId),
|
|
283
|
+
confidence: this.calculateConfidence(group)
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Working Set 정리 (통합된 이벤트 제거)
|
|
289
|
+
await this.workingSetStore.prune(groups.flatMap(g => g.events));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private shouldConsolidate(workingSet: WorkingSet): boolean {
|
|
293
|
+
return workingSet.recentEvents.length >= this.config.consolidation.triggerEventCount;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
private groupByTopic(events: Event[]): EventGroup[] {
|
|
297
|
+
// 간단한 키워드 기반 그룹화
|
|
298
|
+
const groups = new Map<string, EventGroup>();
|
|
299
|
+
|
|
300
|
+
for (const event of events) {
|
|
301
|
+
const topics = extractTopics(event.payload.content);
|
|
302
|
+
|
|
303
|
+
for (const topic of topics) {
|
|
304
|
+
if (!groups.has(topic)) {
|
|
305
|
+
groups.set(topic, { topics: [topic], events: [] });
|
|
306
|
+
}
|
|
307
|
+
groups.get(topic)!.events.push(event);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return Array.from(groups.values());
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private async summarize(group: EventGroup): Promise<string> {
|
|
315
|
+
// 규칙 기반 요약
|
|
316
|
+
const keyPoints = group.events
|
|
317
|
+
.map(e => extractKeyPoint(e.payload.content))
|
|
318
|
+
.filter(Boolean);
|
|
319
|
+
|
|
320
|
+
return keyPoints.join('\n- ');
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private calculateConfidence(group: EventGroup): number {
|
|
324
|
+
// 이벤트 수, 시간 근접성, 토픽 일관성 기반
|
|
325
|
+
const eventScore = Math.min(group.events.length / 10, 1);
|
|
326
|
+
const timeScore = calculateTimeProximity(group.events);
|
|
327
|
+
|
|
328
|
+
return (eventScore + timeScore) / 2;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
**작업 항목**:
|
|
334
|
+
- [ ] ConsolidationWorker 클래스 구현
|
|
335
|
+
- [ ] 스케줄링 로직
|
|
336
|
+
- [ ] 그룹화 로직
|
|
337
|
+
- [ ] 요약 생성
|
|
338
|
+
- [ ] 신뢰도 계산
|
|
339
|
+
|
|
340
|
+
### 3.2 Consolidated Store
|
|
341
|
+
|
|
342
|
+
**파일**: `src/core/consolidated-store.ts` (신규)
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
export class ConsolidatedStore {
|
|
346
|
+
constructor(private db: Database) {}
|
|
347
|
+
|
|
348
|
+
async create(memory: ConsolidatedMemoryInput): Promise<string> {
|
|
349
|
+
const memoryId = crypto.randomUUID();
|
|
350
|
+
|
|
351
|
+
await this.db.run(`
|
|
352
|
+
INSERT INTO consolidated_memories
|
|
353
|
+
(memory_id, summary, topics, source_events, confidence)
|
|
354
|
+
VALUES (?, ?, ?, ?, ?)
|
|
355
|
+
`, [
|
|
356
|
+
memoryId,
|
|
357
|
+
memory.summary,
|
|
358
|
+
JSON.stringify(memory.topics),
|
|
359
|
+
JSON.stringify(memory.sourceEvents),
|
|
360
|
+
memory.confidence
|
|
361
|
+
]);
|
|
362
|
+
|
|
363
|
+
return memoryId;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
async search(query: string, options?: { topK?: number }): Promise<ConsolidatedMemory[]> {
|
|
367
|
+
// 벡터 검색 또는 FTS
|
|
368
|
+
return this.db.all(`
|
|
369
|
+
SELECT * FROM consolidated_memories
|
|
370
|
+
WHERE summary LIKE ?
|
|
371
|
+
ORDER BY confidence DESC
|
|
372
|
+
LIMIT ?
|
|
373
|
+
`, [`%${query}%`, options?.topK || 5]);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async markAccessed(memoryId: string): Promise<void> {
|
|
377
|
+
await this.db.run(`
|
|
378
|
+
UPDATE consolidated_memories
|
|
379
|
+
SET accessed_at = datetime('now'),
|
|
380
|
+
access_count = access_count + 1
|
|
381
|
+
WHERE memory_id = ?
|
|
382
|
+
`, [memoryId]);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
**작업 항목**:
|
|
388
|
+
- [ ] ConsolidatedStore 클래스 구현
|
|
389
|
+
- [ ] create 메서드
|
|
390
|
+
- [ ] search 메서드
|
|
391
|
+
- [ ] markAccessed 메서드
|
|
392
|
+
|
|
393
|
+
## Phase 4: 컨텍스트 연속성 (P1)
|
|
394
|
+
|
|
395
|
+
### 4.1 연속성 계산
|
|
396
|
+
|
|
397
|
+
**파일**: `src/core/continuity-manager.ts` (신규)
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
export class ContinuityManager {
|
|
401
|
+
constructor(
|
|
402
|
+
private db: Database,
|
|
403
|
+
private config: EndlessModeConfig
|
|
404
|
+
) {}
|
|
405
|
+
|
|
406
|
+
async calculateScore(
|
|
407
|
+
currentContext: ContextSnapshot,
|
|
408
|
+
previousContext: ContextSnapshot
|
|
409
|
+
): Promise<ContinuityScore> {
|
|
410
|
+
let score = 0;
|
|
411
|
+
|
|
412
|
+
// 토픽 연속성 (30%)
|
|
413
|
+
const topicOverlap = this.calculateOverlap(
|
|
414
|
+
currentContext.topics,
|
|
415
|
+
previousContext.topics
|
|
416
|
+
);
|
|
417
|
+
score += topicOverlap * 0.3;
|
|
418
|
+
|
|
419
|
+
// 파일 연속성 (20%)
|
|
420
|
+
const fileOverlap = this.calculateOverlap(
|
|
421
|
+
currentContext.files,
|
|
422
|
+
previousContext.files
|
|
423
|
+
);
|
|
424
|
+
score += fileOverlap * 0.2;
|
|
425
|
+
|
|
426
|
+
// 시간 근접성 (30%)
|
|
427
|
+
const timeDiff = currentContext.timestamp - previousContext.timestamp;
|
|
428
|
+
const timeScore = Math.exp(-timeDiff / (this.config.continuity.topicDecayHours * 3600000));
|
|
429
|
+
score += timeScore * 0.3;
|
|
430
|
+
|
|
431
|
+
// 엔티티 연속성 (20%)
|
|
432
|
+
const entityOverlap = this.calculateOverlap(
|
|
433
|
+
currentContext.entities,
|
|
434
|
+
previousContext.entities
|
|
435
|
+
);
|
|
436
|
+
score += entityOverlap * 0.2;
|
|
437
|
+
|
|
438
|
+
// 전환 타입 결정
|
|
439
|
+
const transitionType = this.determineTransitionType(score);
|
|
440
|
+
|
|
441
|
+
// 로그 저장
|
|
442
|
+
await this.logTransition(currentContext, previousContext, score, transitionType);
|
|
443
|
+
|
|
444
|
+
return { score, transitionType };
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
private calculateOverlap(a: string[], b: string[]): number {
|
|
448
|
+
if (a.length === 0 || b.length === 0) return 0;
|
|
449
|
+
const intersection = a.filter(x => b.includes(x));
|
|
450
|
+
return intersection.length / Math.max(a.length, b.length);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
private determineTransitionType(score: number): TransitionType {
|
|
454
|
+
if (score >= this.config.continuity.minScoreForSeamless) {
|
|
455
|
+
return 'seamless';
|
|
456
|
+
} else if (score >= 0.4) {
|
|
457
|
+
return 'topic_shift';
|
|
458
|
+
} else {
|
|
459
|
+
return 'break';
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
private async logTransition(
|
|
464
|
+
current: ContextSnapshot,
|
|
465
|
+
previous: ContextSnapshot,
|
|
466
|
+
score: number,
|
|
467
|
+
type: TransitionType
|
|
468
|
+
): Promise<void> {
|
|
469
|
+
await this.db.run(`
|
|
470
|
+
INSERT INTO continuity_log
|
|
471
|
+
(log_id, from_context_id, to_context_id, continuity_score, transition_type)
|
|
472
|
+
VALUES (?, ?, ?, ?, ?)
|
|
473
|
+
`, [crypto.randomUUID(), previous.id, current.id, score, type]);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
**작업 항목**:
|
|
479
|
+
- [ ] ContinuityManager 클래스 구현
|
|
480
|
+
- [ ] calculateScore 메서드
|
|
481
|
+
- [ ] logTransition 메서드
|
|
482
|
+
- [ ] 전환 타입 결정 로직
|
|
483
|
+
|
|
484
|
+
### 4.2 컨텍스트 주입
|
|
485
|
+
|
|
486
|
+
**파일**: `src/hooks/user-prompt-submit.ts` 수정
|
|
487
|
+
|
|
488
|
+
```typescript
|
|
489
|
+
async function handleUserPromptSubmit(input: UserPromptInput): Promise<HookOutput> {
|
|
490
|
+
const memoryService = await MemoryService.getInstance();
|
|
491
|
+
const config = await memoryService.getConfig();
|
|
492
|
+
|
|
493
|
+
if (config.mode === 'endless') {
|
|
494
|
+
return await handleEndlessMode(input, memoryService);
|
|
495
|
+
} else {
|
|
496
|
+
return await handleSessionMode(input, memoryService);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
async function handleEndlessMode(
|
|
501
|
+
input: UserPromptInput,
|
|
502
|
+
memoryService: MemoryService
|
|
503
|
+
): Promise<HookOutput> {
|
|
504
|
+
// Working Set에서 관련 컨텍스트
|
|
505
|
+
const workingSet = await memoryService.getWorkingSet();
|
|
506
|
+
|
|
507
|
+
// Consolidated Memory에서 검색
|
|
508
|
+
const consolidated = await memoryService.searchConsolidated(
|
|
509
|
+
input.prompt,
|
|
510
|
+
{ topK: 3 }
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
// 연속성 점수
|
|
514
|
+
const continuityScore = workingSet.continuityScore;
|
|
515
|
+
|
|
516
|
+
// 컨텍스트 포맷팅
|
|
517
|
+
const context = formatEndlessContext({
|
|
518
|
+
workingSet: workingSet.recentEvents.slice(0, 10),
|
|
519
|
+
consolidated,
|
|
520
|
+
continuityScore
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
return {
|
|
524
|
+
context,
|
|
525
|
+
meta: {
|
|
526
|
+
mode: 'endless',
|
|
527
|
+
continuityScore,
|
|
528
|
+
workingSetSize: workingSet.recentEvents.length
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
**작업 항목**:
|
|
535
|
+
- [ ] Endless Mode 전용 컨텍스트 주입
|
|
536
|
+
- [ ] Working Set + Consolidated 조합
|
|
537
|
+
- [ ] 연속성 점수 포함
|
|
538
|
+
|
|
539
|
+
## Phase 5: CLI 및 UI (P1)
|
|
540
|
+
|
|
541
|
+
### 5.1 CLI 명령
|
|
542
|
+
|
|
543
|
+
**파일**: `src/cli/commands/endless.ts` (신규)
|
|
544
|
+
|
|
545
|
+
```typescript
|
|
546
|
+
export const endlessCommand = new Command('endless')
|
|
547
|
+
.description('Manage Endless Mode');
|
|
548
|
+
|
|
549
|
+
endlessCommand
|
|
550
|
+
.command('enable')
|
|
551
|
+
.description('Enable Endless Mode')
|
|
552
|
+
.action(async () => {
|
|
553
|
+
const memoryService = await MemoryService.getInstance();
|
|
554
|
+
await memoryService.setMode('endless');
|
|
555
|
+
await memoryService.initializeEndlessMode();
|
|
556
|
+
console.log('✓ Endless Mode enabled');
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
endlessCommand
|
|
560
|
+
.command('disable')
|
|
561
|
+
.description('Disable Endless Mode (return to Session Mode)')
|
|
562
|
+
.action(async () => {
|
|
563
|
+
const memoryService = await MemoryService.getInstance();
|
|
564
|
+
await memoryService.setMode('session');
|
|
565
|
+
console.log('✓ Returned to Session Mode');
|
|
566
|
+
});
|
|
567
|
+
|
|
568
|
+
endlessCommand
|
|
569
|
+
.command('status')
|
|
570
|
+
.description('Show Endless Mode status')
|
|
571
|
+
.action(async () => {
|
|
572
|
+
const memoryService = await MemoryService.getInstance();
|
|
573
|
+
const status = await memoryService.getEndlessStatus();
|
|
574
|
+
|
|
575
|
+
console.log(`Mode: ${status.mode}`);
|
|
576
|
+
console.log(`Working Set: ${status.workingSetSize} events`);
|
|
577
|
+
console.log(`Continuity Score: ${status.continuityScore.toFixed(2)}`);
|
|
578
|
+
console.log(`Consolidated: ${status.consolidatedCount} memories`);
|
|
579
|
+
});
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
**작업 항목**:
|
|
583
|
+
- [ ] enable 명령
|
|
584
|
+
- [ ] disable 명령
|
|
585
|
+
- [ ] status 명령
|
|
586
|
+
- [ ] consolidate 수동 트리거 명령
|
|
587
|
+
|
|
588
|
+
## 파일 목록
|
|
589
|
+
|
|
590
|
+
### 신규 파일
|
|
591
|
+
```
|
|
592
|
+
src/core/working-set-store.ts # Working Set 저장소
|
|
593
|
+
src/core/consolidated-store.ts # Consolidated Memory 저장소
|
|
594
|
+
src/core/consolidation-worker.ts # 통합 워커
|
|
595
|
+
src/core/continuity-manager.ts # 연속성 관리
|
|
596
|
+
src/cli/commands/endless.ts # CLI 명령
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
### 수정 파일
|
|
600
|
+
```
|
|
601
|
+
src/core/types.ts # 스키마 추가
|
|
602
|
+
src/core/event-store.ts # 테이블 추가
|
|
603
|
+
src/services/memory-service.ts # Endless Mode 메서드
|
|
604
|
+
src/hooks/user-prompt-submit.ts # 컨텍스트 주입
|
|
605
|
+
src/hooks/stop.ts # Working Set 연동
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
## 마일스톤
|
|
609
|
+
|
|
610
|
+
| 단계 | 완료 기준 |
|
|
611
|
+
|------|----------|
|
|
612
|
+
| M1 | 스키마 및 테이블 정의 |
|
|
613
|
+
| M2 | Working Set Store 구현 |
|
|
614
|
+
| M3 | Consolidated Store 구현 |
|
|
615
|
+
| M4 | Consolidation Worker 구현 |
|
|
616
|
+
| M5 | 연속성 관리 구현 |
|
|
617
|
+
| M6 | 훅 연동 |
|
|
618
|
+
| M7 | CLI 명령 |
|
|
619
|
+
| M8 | Web Viewer 대시보드 |
|
|
620
|
+
| M9 | 테스트 및 튜닝 |
|