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,469 @@
|
|
|
1
|
+
# PostToolUse Hook 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
|
+
// 추가할 타입들
|
|
15
|
+
export const ToolObservationPayloadSchema = z.object({
|
|
16
|
+
toolName: z.string(),
|
|
17
|
+
toolInput: z.record(z.unknown()),
|
|
18
|
+
toolOutput: z.string(),
|
|
19
|
+
durationMs: z.number(),
|
|
20
|
+
success: z.boolean(),
|
|
21
|
+
errorMessage: z.string().optional(),
|
|
22
|
+
promptIndex: z.number(),
|
|
23
|
+
toolIndex: z.number(),
|
|
24
|
+
metadata: z.object({
|
|
25
|
+
filePath: z.string().optional(),
|
|
26
|
+
fileType: z.string().optional(),
|
|
27
|
+
lineCount: z.number().optional(),
|
|
28
|
+
command: z.string().optional(),
|
|
29
|
+
exitCode: z.number().optional(),
|
|
30
|
+
pattern: z.string().optional(),
|
|
31
|
+
matchCount: z.number().optional(),
|
|
32
|
+
url: z.string().optional(),
|
|
33
|
+
statusCode: z.number().optional()
|
|
34
|
+
}).optional()
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export type ToolObservationPayload = z.infer<typeof ToolObservationPayloadSchema>;
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**작업 항목**:
|
|
41
|
+
- [ ] ToolObservationPayloadSchema 추가
|
|
42
|
+
- [ ] EventType에 'tool_observation' 추가
|
|
43
|
+
- [ ] EventPayload union에 ToolObservationPayload 추가
|
|
44
|
+
|
|
45
|
+
### 1.2 설정 스키마 확장
|
|
46
|
+
|
|
47
|
+
**파일**: `src/core/types.ts` 수정
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// 설정에 tool observation 옵션 추가
|
|
51
|
+
export const ConfigSchema = z.object({
|
|
52
|
+
// ... 기존 설정
|
|
53
|
+
toolObservation: z.object({
|
|
54
|
+
enabled: z.boolean().default(true),
|
|
55
|
+
excludedTools: z.array(z.string()).default(['TodoWrite', 'TodoRead']),
|
|
56
|
+
maxOutputLength: z.number().default(10000),
|
|
57
|
+
maxOutputLines: z.number().default(100),
|
|
58
|
+
storeOnlyOnSuccess: z.boolean().default(false)
|
|
59
|
+
}).optional()
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**작업 항목**:
|
|
64
|
+
- [ ] toolObservation 설정 스키마 추가
|
|
65
|
+
- [ ] 기본값 정의
|
|
66
|
+
|
|
67
|
+
## Phase 2: 훅 구현 (P0)
|
|
68
|
+
|
|
69
|
+
### 2.1 PostToolUse 훅 파일 생성
|
|
70
|
+
|
|
71
|
+
**파일**: `src/hooks/post-tool-use.ts` (신규)
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { MemoryService } from '../services/memory-service';
|
|
75
|
+
import { maskSensitiveData, truncateOutput } from '../core/privacy';
|
|
76
|
+
|
|
77
|
+
interface PostToolUseInput {
|
|
78
|
+
tool_name: string;
|
|
79
|
+
tool_input: Record<string, unknown>;
|
|
80
|
+
tool_output: string;
|
|
81
|
+
tool_error?: string;
|
|
82
|
+
session_id: string;
|
|
83
|
+
started_at: string;
|
|
84
|
+
ended_at: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function handlePostToolUse(input: PostToolUseInput): Promise<void> {
|
|
88
|
+
const memoryService = await MemoryService.getInstance();
|
|
89
|
+
const config = await memoryService.getConfig();
|
|
90
|
+
|
|
91
|
+
// 1. 제외 도구 체크
|
|
92
|
+
if (config.toolObservation?.excludedTools?.includes(input.tool_name)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// 2. 실패 시 저장 스킵 옵션
|
|
97
|
+
const success = !input.tool_error;
|
|
98
|
+
if (!success && config.toolObservation?.storeOnlyOnSuccess) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 3. 민감 정보 마스킹
|
|
103
|
+
const maskedOutput = maskSensitiveData(input.tool_output);
|
|
104
|
+
const maskedInput = maskSensitiveInput(input.tool_input);
|
|
105
|
+
|
|
106
|
+
// 4. 출력 압축
|
|
107
|
+
const truncatedOutput = truncateOutput(maskedOutput, {
|
|
108
|
+
maxLength: config.toolObservation?.maxOutputLength,
|
|
109
|
+
maxLines: config.toolObservation?.maxOutputLines
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// 5. 메타데이터 추출
|
|
113
|
+
const metadata = extractMetadata(input.tool_name, maskedInput, success);
|
|
114
|
+
|
|
115
|
+
// 6. 이벤트 저장
|
|
116
|
+
await memoryService.storeToolObservation({
|
|
117
|
+
toolName: input.tool_name,
|
|
118
|
+
toolInput: maskedInput,
|
|
119
|
+
toolOutput: truncatedOutput,
|
|
120
|
+
durationMs: calculateDuration(input.started_at, input.ended_at),
|
|
121
|
+
success,
|
|
122
|
+
errorMessage: input.tool_error,
|
|
123
|
+
metadata
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
**작업 항목**:
|
|
129
|
+
- [ ] handlePostToolUse 함수 구현
|
|
130
|
+
- [ ] 제외 도구 체크 로직
|
|
131
|
+
- [ ] 성공/실패 필터링 로직
|
|
132
|
+
- [ ] 메타데이터 추출 함수
|
|
133
|
+
|
|
134
|
+
### 2.2 프라이버시 유틸리티
|
|
135
|
+
|
|
136
|
+
**파일**: `src/core/privacy.ts` (신규 또는 확장)
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
const SENSITIVE_PATTERNS = [
|
|
140
|
+
/password\s*[:=]\s*['"]?[^\s'"]+/gi,
|
|
141
|
+
/api[_-]?key\s*[:=]\s*['"]?[^\s'"]+/gi,
|
|
142
|
+
/secret\s*[:=]\s*['"]?[^\s'"]+/gi,
|
|
143
|
+
/token\s*[:=]\s*['"]?[^\s'"]+/gi,
|
|
144
|
+
/bearer\s+[a-zA-Z0-9\-_.]+/gi,
|
|
145
|
+
];
|
|
146
|
+
|
|
147
|
+
export function maskSensitiveData(content: string): string {
|
|
148
|
+
let masked = content;
|
|
149
|
+
for (const pattern of SENSITIVE_PATTERNS) {
|
|
150
|
+
masked = masked.replace(pattern, '[REDACTED]');
|
|
151
|
+
}
|
|
152
|
+
return masked;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function truncateOutput(
|
|
156
|
+
output: string,
|
|
157
|
+
options: { maxLength?: number; maxLines?: number }
|
|
158
|
+
): string {
|
|
159
|
+
const { maxLength = 10000, maxLines = 100 } = options;
|
|
160
|
+
// ... 구현
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**작업 항목**:
|
|
165
|
+
- [ ] maskSensitiveData 함수
|
|
166
|
+
- [ ] maskSensitiveInput 함수 (JSON 재귀 마스킹)
|
|
167
|
+
- [ ] truncateOutput 함수
|
|
168
|
+
- [ ] 도구별 압축 전략 구현
|
|
169
|
+
|
|
170
|
+
### 2.3 메타데이터 추출기
|
|
171
|
+
|
|
172
|
+
**파일**: `src/core/metadata-extractor.ts` (신규)
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
export function extractMetadata(
|
|
176
|
+
toolName: string,
|
|
177
|
+
input: Record<string, unknown>,
|
|
178
|
+
success: boolean
|
|
179
|
+
): ToolMetadata {
|
|
180
|
+
switch (toolName) {
|
|
181
|
+
case 'Read':
|
|
182
|
+
case 'Write':
|
|
183
|
+
case 'Edit':
|
|
184
|
+
return {
|
|
185
|
+
filePath: input.file_path as string,
|
|
186
|
+
fileType: getFileType(input.file_path as string)
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
case 'Bash':
|
|
190
|
+
return {
|
|
191
|
+
command: input.command as string
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
case 'Grep':
|
|
195
|
+
return {
|
|
196
|
+
pattern: input.pattern as string
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// ... 기타 도구
|
|
200
|
+
|
|
201
|
+
default:
|
|
202
|
+
return {};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
**작업 항목**:
|
|
208
|
+
- [ ] extractMetadata 함수
|
|
209
|
+
- [ ] 도구별 메타데이터 추출 로직
|
|
210
|
+
- [ ] getFileType 유틸리티
|
|
211
|
+
|
|
212
|
+
## Phase 3: 서비스 연동 (P0)
|
|
213
|
+
|
|
214
|
+
### 3.1 MemoryService 확장
|
|
215
|
+
|
|
216
|
+
**파일**: `src/services/memory-service.ts` 수정
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
export class MemoryService {
|
|
220
|
+
// 기존 메서드들...
|
|
221
|
+
|
|
222
|
+
async storeToolObservation(observation: ToolObservationPayload): Promise<string> {
|
|
223
|
+
const eventId = await this.eventStore.append({
|
|
224
|
+
eventType: 'tool_observation',
|
|
225
|
+
sessionId: this.currentSessionId,
|
|
226
|
+
payload: observation
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// 임베딩을 위한 outbox 추가
|
|
230
|
+
await this.eventStore.addToOutbox(eventId);
|
|
231
|
+
|
|
232
|
+
return eventId;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
**작업 항목**:
|
|
238
|
+
- [ ] storeToolObservation 메서드 추가
|
|
239
|
+
- [ ] Outbox 연동
|
|
240
|
+
|
|
241
|
+
### 3.2 임베딩 콘텐츠 생성
|
|
242
|
+
|
|
243
|
+
**파일**: `src/core/embedder.ts` 수정
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
export function createEmbeddingContent(event: Event): string {
|
|
247
|
+
if (event.eventType === 'tool_observation') {
|
|
248
|
+
return createToolObservationEmbedding(event.payload);
|
|
249
|
+
}
|
|
250
|
+
// 기존 로직...
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function createToolObservationEmbedding(payload: ToolObservationPayload): string {
|
|
254
|
+
const parts: string[] = [];
|
|
255
|
+
|
|
256
|
+
parts.push(`Tool: ${payload.toolName}`);
|
|
257
|
+
|
|
258
|
+
if (payload.metadata?.filePath) {
|
|
259
|
+
parts.push(`File: ${payload.metadata.filePath}`);
|
|
260
|
+
}
|
|
261
|
+
if (payload.metadata?.command) {
|
|
262
|
+
parts.push(`Command: ${payload.metadata.command}`);
|
|
263
|
+
}
|
|
264
|
+
if (payload.metadata?.pattern) {
|
|
265
|
+
parts.push(`Pattern: ${payload.metadata.pattern}`);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
parts.push(`Result: ${payload.success ? 'Success' : 'Failed'}`);
|
|
269
|
+
|
|
270
|
+
return parts.join('\n');
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
**작업 항목**:
|
|
275
|
+
- [ ] tool_observation 이벤트용 임베딩 콘텐츠 생성
|
|
276
|
+
- [ ] VectorWorker에서 tool_observation 처리
|
|
277
|
+
|
|
278
|
+
## Phase 4: 훅 등록 (P0)
|
|
279
|
+
|
|
280
|
+
### 4.1 hooks.json 수정
|
|
281
|
+
|
|
282
|
+
**파일**: `.claude-plugin/hooks.json` 수정
|
|
283
|
+
|
|
284
|
+
```json
|
|
285
|
+
{
|
|
286
|
+
"hooks": [
|
|
287
|
+
{
|
|
288
|
+
"event": "session-start",
|
|
289
|
+
"script": "node dist/hooks/session-start.js"
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
"event": "user-prompt-submit",
|
|
293
|
+
"script": "node dist/hooks/user-prompt-submit.js"
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
"event": "post-tool-use",
|
|
297
|
+
"script": "node dist/hooks/post-tool-use.js"
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
"event": "stop",
|
|
301
|
+
"script": "node dist/hooks/stop.js"
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
"event": "session-end",
|
|
305
|
+
"script": "node dist/hooks/session-end.js"
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
**작업 항목**:
|
|
312
|
+
- [ ] post-tool-use 훅 등록
|
|
313
|
+
- [ ] 스크립트 경로 확인
|
|
314
|
+
|
|
315
|
+
### 4.2 빌드 스크립트 수정
|
|
316
|
+
|
|
317
|
+
**파일**: `package.json` 또는 빌드 설정
|
|
318
|
+
|
|
319
|
+
```json
|
|
320
|
+
{
|
|
321
|
+
"scripts": {
|
|
322
|
+
"build:hooks": "esbuild src/hooks/*.ts --bundle --platform=node --outdir=dist/hooks"
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
**작업 항목**:
|
|
328
|
+
- [ ] post-tool-use.ts 빌드 포함
|
|
329
|
+
- [ ] 번들 테스트
|
|
330
|
+
|
|
331
|
+
## Phase 5: 검색 연동 (P1)
|
|
332
|
+
|
|
333
|
+
### 5.1 Retriever 확장
|
|
334
|
+
|
|
335
|
+
**파일**: `src/core/retriever.ts` 수정
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
export class Retriever {
|
|
339
|
+
async searchToolHistory(query: string, options?: SearchOptions): Promise<ToolObservation[]> {
|
|
340
|
+
const vectorResults = await this.vectorStore.search(query, {
|
|
341
|
+
filter: { eventType: 'tool_observation' },
|
|
342
|
+
topK: options?.topK ?? 5
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
return vectorResults.map(r => r.payload as ToolObservation);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
async getRecentToolsForFile(filePath: string): Promise<ToolObservation[]> {
|
|
349
|
+
// 특정 파일 관련 최근 도구 사용 조회
|
|
350
|
+
return this.eventStore.query({
|
|
351
|
+
eventType: 'tool_observation',
|
|
352
|
+
filter: { 'payload.metadata.filePath': filePath },
|
|
353
|
+
orderBy: 'timestamp DESC',
|
|
354
|
+
limit: 10
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
**작업 항목**:
|
|
361
|
+
- [ ] searchToolHistory 메서드
|
|
362
|
+
- [ ] getRecentToolsForFile 메서드
|
|
363
|
+
- [ ] 필터링 옵션
|
|
364
|
+
|
|
365
|
+
### 5.2 user-prompt-submit 확장
|
|
366
|
+
|
|
367
|
+
**파일**: `src/hooks/user-prompt-submit.ts` 수정
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
async function handleUserPromptSubmit(input: UserPromptInput): Promise<HookOutput> {
|
|
371
|
+
// 기존 메모리 검색
|
|
372
|
+
const memories = await retriever.search(input.prompt);
|
|
373
|
+
|
|
374
|
+
// 관련 도구 사용 이력 추가
|
|
375
|
+
const toolHistory = await retriever.searchToolHistory(input.prompt, { topK: 3 });
|
|
376
|
+
|
|
377
|
+
// 컨텍스트 조합
|
|
378
|
+
return {
|
|
379
|
+
context: formatContext(memories, toolHistory)
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
**작업 항목**:
|
|
385
|
+
- [ ] 도구 이력을 컨텍스트에 포함
|
|
386
|
+
- [ ] 포맷팅 함수 확장
|
|
387
|
+
|
|
388
|
+
## 파일 목록
|
|
389
|
+
|
|
390
|
+
### 신규 파일
|
|
391
|
+
```
|
|
392
|
+
src/hooks/post-tool-use.ts # 메인 훅 구현
|
|
393
|
+
src/core/privacy.ts # 프라이버시 유틸리티
|
|
394
|
+
src/core/metadata-extractor.ts # 메타데이터 추출
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### 수정 파일
|
|
398
|
+
```
|
|
399
|
+
src/core/types.ts # ToolObservationPayload 추가
|
|
400
|
+
src/services/memory-service.ts # storeToolObservation 메서드
|
|
401
|
+
src/core/embedder.ts # 임베딩 콘텐츠 생성
|
|
402
|
+
src/core/retriever.ts # 도구 이력 검색
|
|
403
|
+
src/hooks/user-prompt-submit.ts # 컨텍스트 포함
|
|
404
|
+
.claude-plugin/hooks.json # 훅 등록
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## 테스트
|
|
408
|
+
|
|
409
|
+
### 필수 테스트 케이스
|
|
410
|
+
|
|
411
|
+
1. **훅 호출 테스트**
|
|
412
|
+
```typescript
|
|
413
|
+
test('should store tool observation after Read', async () => {
|
|
414
|
+
await handlePostToolUse({
|
|
415
|
+
tool_name: 'Read',
|
|
416
|
+
tool_input: { file_path: '/test.ts' },
|
|
417
|
+
tool_output: 'file content...',
|
|
418
|
+
session_id: 'session_1',
|
|
419
|
+
started_at: '2026-02-01T10:00:00Z',
|
|
420
|
+
ended_at: '2026-02-01T10:00:01Z'
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
const events = await eventStore.query({ eventType: 'tool_observation' });
|
|
424
|
+
expect(events.length).toBe(1);
|
|
425
|
+
});
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
2. **민감 정보 마스킹**
|
|
429
|
+
```typescript
|
|
430
|
+
test('should mask sensitive data', () => {
|
|
431
|
+
const input = 'password=secret123';
|
|
432
|
+
const masked = maskSensitiveData(input);
|
|
433
|
+
expect(masked).toBe('[REDACTED]');
|
|
434
|
+
});
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
3. **제외 도구 스킵**
|
|
438
|
+
```typescript
|
|
439
|
+
test('should skip excluded tools', async () => {
|
|
440
|
+
await handlePostToolUse({
|
|
441
|
+
tool_name: 'TodoWrite',
|
|
442
|
+
// ...
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
const events = await eventStore.query({ eventType: 'tool_observation' });
|
|
446
|
+
expect(events.length).toBe(0);
|
|
447
|
+
});
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
4. **출력 압축**
|
|
451
|
+
```typescript
|
|
452
|
+
test('should truncate long output', () => {
|
|
453
|
+
const longOutput = 'x'.repeat(20000);
|
|
454
|
+
const truncated = truncateOutput(longOutput, { maxLength: 10000 });
|
|
455
|
+
expect(truncated.length).toBeLessThanOrEqual(10100); // marker 포함
|
|
456
|
+
});
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
## 마일스톤
|
|
460
|
+
|
|
461
|
+
| 단계 | 완료 기준 |
|
|
462
|
+
|------|----------|
|
|
463
|
+
| M1 | 타입 정의 완료 |
|
|
464
|
+
| M2 | 훅 기본 구현 (저장만) |
|
|
465
|
+
| M3 | 프라이버시 필터링 |
|
|
466
|
+
| M4 | 출력 압축 |
|
|
467
|
+
| M5 | 임베딩 연동 |
|
|
468
|
+
| M6 | 검색 연동 |
|
|
469
|
+
| M7 | 테스트 통과 |
|