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,797 @@
|
|
|
1
|
+
# Web Viewer UI 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 HTTP 서버 설정
|
|
10
|
+
|
|
11
|
+
**파일**: `src/server/index.ts` (신규)
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Hono } from 'hono';
|
|
15
|
+
import { cors } from 'hono/cors';
|
|
16
|
+
import { serveStatic } from 'hono/bun';
|
|
17
|
+
|
|
18
|
+
const app = new Hono();
|
|
19
|
+
|
|
20
|
+
// CORS (개발용)
|
|
21
|
+
app.use('/*', cors());
|
|
22
|
+
|
|
23
|
+
// Static files
|
|
24
|
+
app.use('/*', serveStatic({ root: './dist/ui' }));
|
|
25
|
+
|
|
26
|
+
// API routes
|
|
27
|
+
app.route('/api', apiRouter);
|
|
28
|
+
|
|
29
|
+
export function startServer(port: number = 37777) {
|
|
30
|
+
return Bun.serve({
|
|
31
|
+
hostname: '127.0.0.1',
|
|
32
|
+
port,
|
|
33
|
+
fetch: app.fetch
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**작업 항목**:
|
|
39
|
+
- [ ] Hono 라우터 설정
|
|
40
|
+
- [ ] Static 파일 서빙
|
|
41
|
+
- [ ] CORS 설정
|
|
42
|
+
- [ ] 에러 핸들링 미들웨어
|
|
43
|
+
|
|
44
|
+
### 1.2 API 라우터
|
|
45
|
+
|
|
46
|
+
**파일**: `src/server/api/index.ts` (신규)
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { Hono } from 'hono';
|
|
50
|
+
import { sessionsRouter } from './sessions';
|
|
51
|
+
import { eventsRouter } from './events';
|
|
52
|
+
import { searchRouter } from './search';
|
|
53
|
+
import { statsRouter } from './stats';
|
|
54
|
+
import { configRouter } from './config';
|
|
55
|
+
|
|
56
|
+
export const apiRouter = new Hono()
|
|
57
|
+
.route('/sessions', sessionsRouter)
|
|
58
|
+
.route('/events', eventsRouter)
|
|
59
|
+
.route('/search', searchRouter)
|
|
60
|
+
.route('/stats', statsRouter)
|
|
61
|
+
.route('/config', configRouter);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**작업 항목**:
|
|
65
|
+
- [ ] API 라우터 분리 구조
|
|
66
|
+
- [ ] 공통 미들웨어 (로깅, 인증)
|
|
67
|
+
|
|
68
|
+
## Phase 2: REST API 구현 (P0)
|
|
69
|
+
|
|
70
|
+
### 2.1 Sessions API
|
|
71
|
+
|
|
72
|
+
**파일**: `src/server/api/sessions.ts` (신규)
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { Hono } from 'hono';
|
|
76
|
+
import { MemoryService } from '../../services/memory-service';
|
|
77
|
+
|
|
78
|
+
export const sessionsRouter = new Hono();
|
|
79
|
+
|
|
80
|
+
// GET /api/sessions
|
|
81
|
+
sessionsRouter.get('/', async (c) => {
|
|
82
|
+
const { page = 1, pageSize = 20 } = c.req.query();
|
|
83
|
+
const memoryService = await MemoryService.getInstance();
|
|
84
|
+
|
|
85
|
+
const sessions = await memoryService.getSessions({
|
|
86
|
+
page: Number(page),
|
|
87
|
+
pageSize: Number(pageSize)
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return c.json({
|
|
91
|
+
sessions: sessions.items,
|
|
92
|
+
total: sessions.total,
|
|
93
|
+
page: Number(page),
|
|
94
|
+
pageSize: Number(pageSize)
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// GET /api/sessions/:id
|
|
99
|
+
sessionsRouter.get('/:id', async (c) => {
|
|
100
|
+
const { id } = c.req.param();
|
|
101
|
+
const memoryService = await MemoryService.getInstance();
|
|
102
|
+
|
|
103
|
+
const session = await memoryService.getSessionById(id);
|
|
104
|
+
if (!session) {
|
|
105
|
+
return c.json({ error: 'Session not found' }, 404);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const events = await memoryService.getEventsBySession(id);
|
|
109
|
+
const stats = await memoryService.getSessionStats(id);
|
|
110
|
+
|
|
111
|
+
return c.json({ session, events, stats });
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**작업 항목**:
|
|
116
|
+
- [ ] 세션 목록 조회
|
|
117
|
+
- [ ] 세션 상세 조회
|
|
118
|
+
- [ ] 페이지네이션 구현
|
|
119
|
+
- [ ] 정렬 옵션
|
|
120
|
+
|
|
121
|
+
### 2.2 Events API
|
|
122
|
+
|
|
123
|
+
**파일**: `src/server/api/events.ts` (신규)
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
export const eventsRouter = new Hono();
|
|
127
|
+
|
|
128
|
+
// GET /api/events
|
|
129
|
+
eventsRouter.get('/', async (c) => {
|
|
130
|
+
const { sessionId, type, limit = 100, offset = 0 } = c.req.query();
|
|
131
|
+
const memoryService = await MemoryService.getInstance();
|
|
132
|
+
|
|
133
|
+
const events = await memoryService.getEvents({
|
|
134
|
+
sessionId,
|
|
135
|
+
eventType: type,
|
|
136
|
+
limit: Number(limit),
|
|
137
|
+
offset: Number(offset)
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return c.json({
|
|
141
|
+
events: events.map(e => ({
|
|
142
|
+
eventId: e.eventId,
|
|
143
|
+
eventType: e.eventType,
|
|
144
|
+
timestamp: e.timestamp,
|
|
145
|
+
sessionId: e.sessionId,
|
|
146
|
+
preview: generatePreview(e.payload, 100)
|
|
147
|
+
})),
|
|
148
|
+
total: events.total
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// GET /api/events/:id
|
|
153
|
+
eventsRouter.get('/:id', async (c) => {
|
|
154
|
+
const { id } = c.req.param();
|
|
155
|
+
const memoryService = await MemoryService.getInstance();
|
|
156
|
+
|
|
157
|
+
const event = await memoryService.getEventById(id);
|
|
158
|
+
if (!event) {
|
|
159
|
+
return c.json({ error: 'Event not found' }, 404);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const related = await memoryService.getRelatedEvents(id);
|
|
163
|
+
|
|
164
|
+
return c.json({ event, related });
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**작업 항목**:
|
|
169
|
+
- [ ] 이벤트 목록 조회 (필터링)
|
|
170
|
+
- [ ] 이벤트 상세 조회
|
|
171
|
+
- [ ] 미리보기 생성
|
|
172
|
+
- [ ] 관련 이벤트 조회
|
|
173
|
+
|
|
174
|
+
### 2.3 Search API
|
|
175
|
+
|
|
176
|
+
**파일**: `src/server/api/search.ts` (신규)
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
export const searchRouter = new Hono();
|
|
180
|
+
|
|
181
|
+
// POST /api/search
|
|
182
|
+
searchRouter.post('/', async (c) => {
|
|
183
|
+
const body = await c.req.json<SearchRequest>();
|
|
184
|
+
const memoryService = await MemoryService.getInstance();
|
|
185
|
+
|
|
186
|
+
const startTime = Date.now();
|
|
187
|
+
|
|
188
|
+
const results = await memoryService.search(body.query, {
|
|
189
|
+
filters: body.filters,
|
|
190
|
+
topK: body.options?.topK ?? 10,
|
|
191
|
+
minScore: body.options?.minScore ?? 0.7,
|
|
192
|
+
progressive: body.options?.progressive ?? true
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return c.json({
|
|
196
|
+
results: results.map(r => ({
|
|
197
|
+
id: r.id,
|
|
198
|
+
score: r.score,
|
|
199
|
+
type: r.type,
|
|
200
|
+
timestamp: r.timestamp,
|
|
201
|
+
sessionId: r.sessionId,
|
|
202
|
+
preview: r.preview,
|
|
203
|
+
highlight: highlightMatches(r.content, body.query)
|
|
204
|
+
})),
|
|
205
|
+
meta: {
|
|
206
|
+
totalMatches: results.length,
|
|
207
|
+
searchTime: Date.now() - startTime,
|
|
208
|
+
mode: 'hybrid'
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**작업 항목**:
|
|
215
|
+
- [ ] 검색 API 구현
|
|
216
|
+
- [ ] 필터링 옵션
|
|
217
|
+
- [ ] 하이라이트 기능
|
|
218
|
+
- [ ] Progressive 모드 지원
|
|
219
|
+
|
|
220
|
+
### 2.4 Stats API
|
|
221
|
+
|
|
222
|
+
**파일**: `src/server/api/stats.ts` (신규)
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
export const statsRouter = new Hono();
|
|
226
|
+
|
|
227
|
+
// GET /api/stats
|
|
228
|
+
statsRouter.get('/', async (c) => {
|
|
229
|
+
const memoryService = await MemoryService.getInstance();
|
|
230
|
+
const stats = await memoryService.getStats();
|
|
231
|
+
|
|
232
|
+
return c.json({
|
|
233
|
+
storage: {
|
|
234
|
+
eventCount: stats.events.count,
|
|
235
|
+
vectorCount: stats.vectors.count,
|
|
236
|
+
dbSizeMB: stats.storage.duckdb / (1024 * 1024),
|
|
237
|
+
vectorSizeMB: stats.storage.lancedb / (1024 * 1024)
|
|
238
|
+
},
|
|
239
|
+
sessions: {
|
|
240
|
+
total: stats.sessions.total,
|
|
241
|
+
active: stats.sessions.active,
|
|
242
|
+
thisWeek: stats.sessions.thisWeek
|
|
243
|
+
},
|
|
244
|
+
embeddings: {
|
|
245
|
+
pending: stats.outbox.pending,
|
|
246
|
+
processed: stats.outbox.processed,
|
|
247
|
+
failed: stats.outbox.failed,
|
|
248
|
+
avgProcessTime: stats.outbox.avgTime
|
|
249
|
+
},
|
|
250
|
+
memory: {
|
|
251
|
+
heapUsed: process.memoryUsage().heapUsed,
|
|
252
|
+
heapTotal: process.memoryUsage().heapTotal
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
// GET /api/stats/timeline
|
|
258
|
+
statsRouter.get('/timeline', async (c) => {
|
|
259
|
+
const { days = 7 } = c.req.query();
|
|
260
|
+
const memoryService = await MemoryService.getInstance();
|
|
261
|
+
|
|
262
|
+
const timeline = await memoryService.getActivityTimeline(Number(days));
|
|
263
|
+
|
|
264
|
+
return c.json({ daily: timeline });
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
**작업 항목**:
|
|
269
|
+
- [ ] 전체 통계 조회
|
|
270
|
+
- [ ] 타임라인 통계
|
|
271
|
+
- [ ] 메모리 사용량
|
|
272
|
+
|
|
273
|
+
## Phase 3: WebSocket 구현 (P1)
|
|
274
|
+
|
|
275
|
+
### 3.1 WebSocket 서버
|
|
276
|
+
|
|
277
|
+
**파일**: `src/server/websocket.ts` (신규)
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
import { EventEmitter } from 'events';
|
|
281
|
+
|
|
282
|
+
const eventBus = new EventEmitter();
|
|
283
|
+
|
|
284
|
+
interface WSClient {
|
|
285
|
+
ws: WebSocket;
|
|
286
|
+
subscriptions: Set<string>;
|
|
287
|
+
filters: {
|
|
288
|
+
sessionId?: string;
|
|
289
|
+
eventType?: string[];
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const clients = new Map<string, WSClient>();
|
|
294
|
+
|
|
295
|
+
export function handleWebSocket(ws: WebSocket) {
|
|
296
|
+
const clientId = crypto.randomUUID();
|
|
297
|
+
|
|
298
|
+
clients.set(clientId, {
|
|
299
|
+
ws,
|
|
300
|
+
subscriptions: new Set(),
|
|
301
|
+
filters: {}
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
ws.onmessage = (event) => {
|
|
305
|
+
const msg = JSON.parse(event.data);
|
|
306
|
+
|
|
307
|
+
if (msg.type === 'subscribe') {
|
|
308
|
+
const client = clients.get(clientId);
|
|
309
|
+
msg.channels.forEach((ch: string) => client?.subscriptions.add(ch));
|
|
310
|
+
if (msg.filters) {
|
|
311
|
+
client!.filters = msg.filters;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (msg.type === 'unsubscribe') {
|
|
316
|
+
const client = clients.get(clientId);
|
|
317
|
+
msg.channels.forEach((ch: string) => client?.subscriptions.delete(ch));
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
ws.onclose = () => {
|
|
322
|
+
clients.delete(clientId);
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// 이벤트 브로드캐스트
|
|
327
|
+
export function broadcastEvent(channel: string, data: unknown) {
|
|
328
|
+
for (const client of clients.values()) {
|
|
329
|
+
if (client.subscriptions.has(channel)) {
|
|
330
|
+
// 필터 적용
|
|
331
|
+
if (channel === 'events' && client.filters.sessionId) {
|
|
332
|
+
if ((data as any).sessionId !== client.filters.sessionId) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
client.ws.send(JSON.stringify({ channel, data }));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
**작업 항목**:
|
|
344
|
+
- [ ] WebSocket 연결 관리
|
|
345
|
+
- [ ] 구독/구독취소 처리
|
|
346
|
+
- [ ] 필터링 적용
|
|
347
|
+
- [ ] 브로드캐스트 함수
|
|
348
|
+
|
|
349
|
+
### 3.2 이벤트 연동
|
|
350
|
+
|
|
351
|
+
**파일**: `src/services/memory-service.ts` 수정
|
|
352
|
+
|
|
353
|
+
```typescript
|
|
354
|
+
import { broadcastEvent } from '../server/websocket';
|
|
355
|
+
|
|
356
|
+
export class MemoryService {
|
|
357
|
+
async storeEvent(event: Event): Promise<string> {
|
|
358
|
+
const eventId = await this.eventStore.append(event);
|
|
359
|
+
|
|
360
|
+
// WebSocket 브로드캐스트
|
|
361
|
+
broadcastEvent('events', {
|
|
362
|
+
type: 'new_event',
|
|
363
|
+
event: {
|
|
364
|
+
eventId,
|
|
365
|
+
eventType: event.eventType,
|
|
366
|
+
timestamp: event.timestamp,
|
|
367
|
+
sessionId: event.sessionId,
|
|
368
|
+
preview: generatePreview(event.payload, 100)
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
return eventId;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
**작업 항목**:
|
|
378
|
+
- [ ] 이벤트 저장 시 브로드캐스트
|
|
379
|
+
- [ ] Outbox 상태 브로드캐스트
|
|
380
|
+
- [ ] 통계 업데이트 브로드캐스트
|
|
381
|
+
|
|
382
|
+
## Phase 4: UI 구현 (P1)
|
|
383
|
+
|
|
384
|
+
### 4.1 HTML 템플릿
|
|
385
|
+
|
|
386
|
+
**파일**: `src/ui/index.html` (신규)
|
|
387
|
+
|
|
388
|
+
```html
|
|
389
|
+
<!DOCTYPE html>
|
|
390
|
+
<html lang="en">
|
|
391
|
+
<head>
|
|
392
|
+
<meta charset="UTF-8">
|
|
393
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
394
|
+
<title>Code Memory Dashboard</title>
|
|
395
|
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
396
|
+
<script type="module" src="/app.js"></script>
|
|
397
|
+
</head>
|
|
398
|
+
<body class="bg-gray-900 text-gray-100">
|
|
399
|
+
<div id="app"></div>
|
|
400
|
+
</body>
|
|
401
|
+
</html>
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
**작업 항목**:
|
|
405
|
+
- [ ] HTML 기본 템플릿
|
|
406
|
+
- [ ] Tailwind 설정
|
|
407
|
+
- [ ] 다크 테마
|
|
408
|
+
|
|
409
|
+
### 4.2 메인 앱
|
|
410
|
+
|
|
411
|
+
**파일**: `src/ui/app.ts` (신규)
|
|
412
|
+
|
|
413
|
+
```typescript
|
|
414
|
+
import { h, render } from 'preact';
|
|
415
|
+
import { signal } from '@preact/signals';
|
|
416
|
+
import { Router, Route } from 'preact-router';
|
|
417
|
+
|
|
418
|
+
import { Dashboard } from './pages/Dashboard';
|
|
419
|
+
import { Sessions } from './pages/Sessions';
|
|
420
|
+
import { Timeline } from './pages/Timeline';
|
|
421
|
+
import { Search } from './pages/Search';
|
|
422
|
+
import { Stats } from './pages/Stats';
|
|
423
|
+
|
|
424
|
+
const currentPath = signal(window.location.pathname);
|
|
425
|
+
|
|
426
|
+
function App() {
|
|
427
|
+
return h('div', { class: 'min-h-screen' },
|
|
428
|
+
h('nav', { class: 'bg-gray-800 p-4' },
|
|
429
|
+
h('div', { class: 'flex items-center gap-4' },
|
|
430
|
+
h('span', { class: 'text-xl font-bold' }, '🧠 Code Memory'),
|
|
431
|
+
h('a', { href: '/', class: 'hover:text-blue-400' }, 'Dashboard'),
|
|
432
|
+
h('a', { href: '/sessions', class: 'hover:text-blue-400' }, 'Sessions'),
|
|
433
|
+
h('a', { href: '/timeline', class: 'hover:text-blue-400' }, 'Timeline'),
|
|
434
|
+
h('a', { href: '/search', class: 'hover:text-blue-400' }, 'Search'),
|
|
435
|
+
h('a', { href: '/stats', class: 'hover:text-blue-400' }, 'Stats')
|
|
436
|
+
)
|
|
437
|
+
),
|
|
438
|
+
h('main', { class: 'p-4' },
|
|
439
|
+
h(Router, {},
|
|
440
|
+
h(Route, { path: '/', component: Dashboard }),
|
|
441
|
+
h(Route, { path: '/sessions', component: Sessions }),
|
|
442
|
+
h(Route, { path: '/sessions/:id', component: SessionDetail }),
|
|
443
|
+
h(Route, { path: '/timeline', component: Timeline }),
|
|
444
|
+
h(Route, { path: '/search', component: Search }),
|
|
445
|
+
h(Route, { path: '/stats', component: Stats })
|
|
446
|
+
)
|
|
447
|
+
)
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
render(h(App), document.getElementById('app')!);
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
**작업 항목**:
|
|
455
|
+
- [ ] Preact 앱 설정
|
|
456
|
+
- [ ] 라우터 구성
|
|
457
|
+
- [ ] 네비게이션 바
|
|
458
|
+
|
|
459
|
+
### 4.3 API 클라이언트
|
|
460
|
+
|
|
461
|
+
**파일**: `src/ui/api.ts` (신규)
|
|
462
|
+
|
|
463
|
+
```typescript
|
|
464
|
+
const BASE_URL = '/api';
|
|
465
|
+
|
|
466
|
+
export async function fetchSessions(options?: { page?: number; pageSize?: number }) {
|
|
467
|
+
const params = new URLSearchParams();
|
|
468
|
+
if (options?.page) params.set('page', String(options.page));
|
|
469
|
+
if (options?.pageSize) params.set('pageSize', String(options.pageSize));
|
|
470
|
+
|
|
471
|
+
const res = await fetch(`${BASE_URL}/sessions?${params}`);
|
|
472
|
+
return res.json();
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export async function fetchEvents(options?: { sessionId?: string; type?: string; limit?: number }) {
|
|
476
|
+
const params = new URLSearchParams();
|
|
477
|
+
if (options?.sessionId) params.set('sessionId', options.sessionId);
|
|
478
|
+
if (options?.type) params.set('type', options.type);
|
|
479
|
+
if (options?.limit) params.set('limit', String(options.limit));
|
|
480
|
+
|
|
481
|
+
const res = await fetch(`${BASE_URL}/events?${params}`);
|
|
482
|
+
return res.json();
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export async function search(query: string, options?: SearchOptions) {
|
|
486
|
+
const res = await fetch(`${BASE_URL}/search`, {
|
|
487
|
+
method: 'POST',
|
|
488
|
+
headers: { 'Content-Type': 'application/json' },
|
|
489
|
+
body: JSON.stringify({ query, options })
|
|
490
|
+
});
|
|
491
|
+
return res.json();
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export async function fetchStats() {
|
|
495
|
+
const res = await fetch(`${BASE_URL}/stats`);
|
|
496
|
+
return res.json();
|
|
497
|
+
}
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
**작업 항목**:
|
|
501
|
+
- [ ] Sessions API 클라이언트
|
|
502
|
+
- [ ] Events API 클라이언트
|
|
503
|
+
- [ ] Search API 클라이언트
|
|
504
|
+
- [ ] Stats API 클라이언트
|
|
505
|
+
|
|
506
|
+
### 4.4 WebSocket 클라이언트
|
|
507
|
+
|
|
508
|
+
**파일**: `src/ui/websocket.ts` (신규)
|
|
509
|
+
|
|
510
|
+
```typescript
|
|
511
|
+
import { signal } from '@preact/signals';
|
|
512
|
+
|
|
513
|
+
export const wsConnected = signal(false);
|
|
514
|
+
export const liveEvents = signal<Event[]>([]);
|
|
515
|
+
export const outboxStatus = signal({ pending: 0, processing: [], failed: [] });
|
|
516
|
+
|
|
517
|
+
let ws: WebSocket | null = null;
|
|
518
|
+
|
|
519
|
+
export function connectWebSocket() {
|
|
520
|
+
ws = new WebSocket(`ws://${window.location.host}/ws`);
|
|
521
|
+
|
|
522
|
+
ws.onopen = () => {
|
|
523
|
+
wsConnected.value = true;
|
|
524
|
+
ws?.send(JSON.stringify({
|
|
525
|
+
type: 'subscribe',
|
|
526
|
+
channels: ['events', 'outbox']
|
|
527
|
+
}));
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
ws.onmessage = (event) => {
|
|
531
|
+
const msg = JSON.parse(event.data);
|
|
532
|
+
|
|
533
|
+
if (msg.channel === 'events') {
|
|
534
|
+
liveEvents.value = [msg.data.event, ...liveEvents.value.slice(0, 99)];
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
if (msg.channel === 'outbox') {
|
|
538
|
+
outboxStatus.value = msg.data;
|
|
539
|
+
}
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
ws.onclose = () => {
|
|
543
|
+
wsConnected.value = false;
|
|
544
|
+
setTimeout(connectWebSocket, 3000); // 재연결
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
export function subscribeToSession(sessionId: string) {
|
|
549
|
+
ws?.send(JSON.stringify({
|
|
550
|
+
type: 'subscribe',
|
|
551
|
+
channels: ['events'],
|
|
552
|
+
filters: { sessionId }
|
|
553
|
+
}));
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
**작업 항목**:
|
|
558
|
+
- [ ] WebSocket 연결 관리
|
|
559
|
+
- [ ] 자동 재연결
|
|
560
|
+
- [ ] 구독 관리
|
|
561
|
+
- [ ] 실시간 상태 시그널
|
|
562
|
+
|
|
563
|
+
## Phase 5: 페이지 컴포넌트 (P1)
|
|
564
|
+
|
|
565
|
+
### 5.1 Dashboard 페이지
|
|
566
|
+
|
|
567
|
+
**파일**: `src/ui/pages/Dashboard.ts` (신규)
|
|
568
|
+
|
|
569
|
+
```typescript
|
|
570
|
+
import { h } from 'preact';
|
|
571
|
+
import { useEffect, useState } from 'preact/hooks';
|
|
572
|
+
import { fetchStats, fetchSessions } from '../api';
|
|
573
|
+
|
|
574
|
+
export function Dashboard() {
|
|
575
|
+
const [stats, setStats] = useState(null);
|
|
576
|
+
const [recentSessions, setRecentSessions] = useState([]);
|
|
577
|
+
|
|
578
|
+
useEffect(() => {
|
|
579
|
+
fetchStats().then(setStats);
|
|
580
|
+
fetchSessions({ pageSize: 5 }).then(data => setRecentSessions(data.sessions));
|
|
581
|
+
}, []);
|
|
582
|
+
|
|
583
|
+
return h('div', { class: 'space-y-6' },
|
|
584
|
+
// Stats cards
|
|
585
|
+
h('div', { class: 'grid grid-cols-3 gap-4' },
|
|
586
|
+
h(StatCard, { title: 'Events', value: stats?.storage.eventCount }),
|
|
587
|
+
h(StatCard, { title: 'Vectors', value: stats?.storage.vectorCount }),
|
|
588
|
+
h(StatCard, { title: 'Sessions', value: stats?.sessions.total })
|
|
589
|
+
),
|
|
590
|
+
// Recent sessions
|
|
591
|
+
h('div', { class: 'bg-gray-800 rounded p-4' },
|
|
592
|
+
h('h2', { class: 'text-lg font-semibold mb-4' }, 'Recent Sessions'),
|
|
593
|
+
recentSessions.map(s => h(SessionItem, { session: s }))
|
|
594
|
+
)
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
**작업 항목**:
|
|
600
|
+
- [ ] 통계 카드 컴포넌트
|
|
601
|
+
- [ ] 최근 세션 목록
|
|
602
|
+
- [ ] 실시간 업데이트
|
|
603
|
+
|
|
604
|
+
### 5.2 Timeline 페이지
|
|
605
|
+
|
|
606
|
+
**파일**: `src/ui/pages/Timeline.ts` (신규)
|
|
607
|
+
|
|
608
|
+
```typescript
|
|
609
|
+
import { h } from 'preact';
|
|
610
|
+
import { useEffect } from 'preact/hooks';
|
|
611
|
+
import { liveEvents, connectWebSocket } from '../websocket';
|
|
612
|
+
|
|
613
|
+
export function Timeline() {
|
|
614
|
+
useEffect(() => {
|
|
615
|
+
connectWebSocket();
|
|
616
|
+
}, []);
|
|
617
|
+
|
|
618
|
+
return h('div', { class: 'space-y-4' },
|
|
619
|
+
h('div', { class: 'flex items-center justify-between' },
|
|
620
|
+
h('h1', { class: 'text-xl font-bold' }, '📅 Timeline'),
|
|
621
|
+
h('span', { class: 'text-green-400' }, '● Live')
|
|
622
|
+
),
|
|
623
|
+
h('div', { class: 'space-y-2' },
|
|
624
|
+
liveEvents.value.map(event =>
|
|
625
|
+
h(TimelineItem, { event })
|
|
626
|
+
)
|
|
627
|
+
)
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
function TimelineItem({ event }) {
|
|
632
|
+
const icons = {
|
|
633
|
+
user_prompt: '💬',
|
|
634
|
+
assistant_response: '🤖',
|
|
635
|
+
tool_observation: '🛠️'
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
return h('div', { class: 'flex gap-4 p-4 bg-gray-800 rounded' },
|
|
639
|
+
h('div', { class: 'text-2xl' }, icons[event.eventType] || '📝'),
|
|
640
|
+
h('div', { class: 'flex-1' },
|
|
641
|
+
h('div', { class: 'text-sm text-gray-400' },
|
|
642
|
+
new Date(event.timestamp).toLocaleTimeString()
|
|
643
|
+
),
|
|
644
|
+
h('div', {}, event.preview)
|
|
645
|
+
)
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
**작업 항목**:
|
|
651
|
+
- [ ] 실시간 타임라인
|
|
652
|
+
- [ ] 이벤트 타입별 아이콘
|
|
653
|
+
- [ ] 필터링 옵션
|
|
654
|
+
- [ ] 무한 스크롤
|
|
655
|
+
|
|
656
|
+
### 5.3 Search 페이지
|
|
657
|
+
|
|
658
|
+
**파일**: `src/ui/pages/Search.ts` (신규)
|
|
659
|
+
|
|
660
|
+
```typescript
|
|
661
|
+
import { h } from 'preact';
|
|
662
|
+
import { useState } from 'preact/hooks';
|
|
663
|
+
import { search } from '../api';
|
|
664
|
+
|
|
665
|
+
export function Search() {
|
|
666
|
+
const [query, setQuery] = useState('');
|
|
667
|
+
const [results, setResults] = useState([]);
|
|
668
|
+
const [loading, setLoading] = useState(false);
|
|
669
|
+
|
|
670
|
+
async function handleSearch() {
|
|
671
|
+
if (!query.trim()) return;
|
|
672
|
+
setLoading(true);
|
|
673
|
+
const data = await search(query);
|
|
674
|
+
setResults(data.results);
|
|
675
|
+
setLoading(false);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
return h('div', { class: 'space-y-4' },
|
|
679
|
+
h('div', { class: 'flex gap-2' },
|
|
680
|
+
h('input', {
|
|
681
|
+
type: 'text',
|
|
682
|
+
value: query,
|
|
683
|
+
onInput: (e) => setQuery(e.target.value),
|
|
684
|
+
onKeyDown: (e) => e.key === 'Enter' && handleSearch(),
|
|
685
|
+
placeholder: 'Search memories...',
|
|
686
|
+
class: 'flex-1 bg-gray-800 rounded px-4 py-2'
|
|
687
|
+
}),
|
|
688
|
+
h('button', {
|
|
689
|
+
onClick: handleSearch,
|
|
690
|
+
class: 'bg-blue-600 px-4 py-2 rounded'
|
|
691
|
+
}, 'Search')
|
|
692
|
+
),
|
|
693
|
+
loading && h('div', {}, 'Searching...'),
|
|
694
|
+
h('div', { class: 'space-y-2' },
|
|
695
|
+
results.map(r => h(SearchResult, { result: r }))
|
|
696
|
+
)
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
**작업 항목**:
|
|
702
|
+
- [ ] 검색 입력
|
|
703
|
+
- [ ] 필터 옵션
|
|
704
|
+
- [ ] 결과 표시
|
|
705
|
+
- [ ] 하이라이트
|
|
706
|
+
|
|
707
|
+
## Phase 6: 빌드 및 통합 (P0)
|
|
708
|
+
|
|
709
|
+
### 6.1 빌드 스크립트
|
|
710
|
+
|
|
711
|
+
**파일**: `package.json` 수정
|
|
712
|
+
|
|
713
|
+
```json
|
|
714
|
+
{
|
|
715
|
+
"scripts": {
|
|
716
|
+
"build:ui": "esbuild src/ui/app.ts --bundle --outfile=dist/ui/app.js --minify",
|
|
717
|
+
"build:server": "esbuild src/server/index.ts --bundle --platform=node --outfile=dist/server.js",
|
|
718
|
+
"dev:ui": "esbuild src/ui/app.ts --bundle --outfile=dist/ui/app.js --watch",
|
|
719
|
+
"start:server": "bun dist/server.js"
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
**작업 항목**:
|
|
725
|
+
- [ ] UI 빌드 스크립트
|
|
726
|
+
- [ ] 서버 빌드 스크립트
|
|
727
|
+
- [ ] 개발 모드 설정
|
|
728
|
+
|
|
729
|
+
### 6.2 서버 자동 시작
|
|
730
|
+
|
|
731
|
+
**파일**: `src/hooks/session-start.ts` 수정
|
|
732
|
+
|
|
733
|
+
```typescript
|
|
734
|
+
import { startServer, isServerRunning } from '../server';
|
|
735
|
+
|
|
736
|
+
export async function handleSessionStart(): Promise<void> {
|
|
737
|
+
// 서버 실행 확인 및 시작
|
|
738
|
+
if (!await isServerRunning(37777)) {
|
|
739
|
+
startServer(37777);
|
|
740
|
+
console.log('Memory viewer started at http://localhost:37777');
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// 기존 로직...
|
|
744
|
+
}
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
**작업 항목**:
|
|
748
|
+
- [ ] 세션 시작 시 서버 자동 시작
|
|
749
|
+
- [ ] 포트 충돌 처리
|
|
750
|
+
- [ ] 로그 출력
|
|
751
|
+
|
|
752
|
+
## 파일 목록
|
|
753
|
+
|
|
754
|
+
### 신규 파일
|
|
755
|
+
```
|
|
756
|
+
# Server
|
|
757
|
+
src/server/index.ts # HTTP 서버 메인
|
|
758
|
+
src/server/api/index.ts # API 라우터
|
|
759
|
+
src/server/api/sessions.ts # Sessions API
|
|
760
|
+
src/server/api/events.ts # Events API
|
|
761
|
+
src/server/api/search.ts # Search API
|
|
762
|
+
src/server/api/stats.ts # Stats API
|
|
763
|
+
src/server/api/config.ts # Config API
|
|
764
|
+
src/server/websocket.ts # WebSocket 핸들러
|
|
765
|
+
|
|
766
|
+
# UI
|
|
767
|
+
src/ui/index.html # HTML 템플릿
|
|
768
|
+
src/ui/app.ts # Preact 앱
|
|
769
|
+
src/ui/api.ts # API 클라이언트
|
|
770
|
+
src/ui/websocket.ts # WebSocket 클라이언트
|
|
771
|
+
src/ui/pages/Dashboard.ts # 대시보드 페이지
|
|
772
|
+
src/ui/pages/Sessions.ts # 세션 페이지
|
|
773
|
+
src/ui/pages/Timeline.ts # 타임라인 페이지
|
|
774
|
+
src/ui/pages/Search.ts # 검색 페이지
|
|
775
|
+
src/ui/pages/Stats.ts # 통계 페이지
|
|
776
|
+
src/ui/components/*.ts # 공통 컴포넌트
|
|
777
|
+
```
|
|
778
|
+
|
|
779
|
+
### 수정 파일
|
|
780
|
+
```
|
|
781
|
+
src/services/memory-service.ts # WebSocket 브로드캐스트 추가
|
|
782
|
+
src/hooks/session-start.ts # 서버 자동 시작
|
|
783
|
+
package.json # 빌드 스크립트
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
## 마일스톤
|
|
787
|
+
|
|
788
|
+
| 단계 | 완료 기준 |
|
|
789
|
+
|------|----------|
|
|
790
|
+
| M1 | HTTP 서버 + 정적 파일 서빙 |
|
|
791
|
+
| M2 | REST API (Sessions, Events) |
|
|
792
|
+
| M3 | REST API (Search, Stats, Config) |
|
|
793
|
+
| M4 | WebSocket 기본 구현 |
|
|
794
|
+
| M5 | UI 기본 레이아웃 |
|
|
795
|
+
| M6 | Dashboard + Timeline 페이지 |
|
|
796
|
+
| M7 | Search + Stats 페이지 |
|
|
797
|
+
| M8 | 빌드 및 통합 테스트 |
|