@scitrera/memorylayer-cc-plugin 0.1.22 → 0.2.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/LICENSE +177 -0
- package/README.md +11 -4
- package/dist/bin/memorylayer-hook.js +27 -9
- package/dist/bin/memorylayer-hook.js.map +1 -1
- package/dist/src/hooks/client.d.ts +21 -0
- package/dist/src/hooks/client.d.ts.map +1 -0
- package/dist/src/hooks/client.js +57 -0
- package/dist/src/hooks/client.js.map +1 -0
- package/dist/src/hooks/formatters.d.ts +33 -0
- package/dist/src/hooks/formatters.d.ts.map +1 -0
- package/dist/src/hooks/formatters.js +187 -0
- package/dist/src/hooks/formatters.js.map +1 -0
- package/dist/src/hooks/handlers/post-tool.d.ts +10 -0
- package/dist/src/hooks/handlers/post-tool.d.ts.map +1 -0
- package/dist/src/hooks/handlers/post-tool.js +98 -0
- package/dist/src/hooks/handlers/post-tool.js.map +1 -0
- package/dist/src/hooks/handlers/pre-compact.d.ts +5 -0
- package/dist/src/hooks/handlers/pre-compact.d.ts.map +1 -0
- package/dist/src/hooks/handlers/pre-compact.js +117 -0
- package/dist/src/hooks/handlers/pre-compact.js.map +1 -0
- package/dist/src/hooks/handlers/pre-tool.d.ts +10 -0
- package/dist/src/hooks/handlers/pre-tool.d.ts.map +1 -0
- package/dist/src/hooks/handlers/pre-tool.js +114 -0
- package/dist/src/hooks/handlers/pre-tool.js.map +1 -0
- package/dist/src/hooks/handlers/session-start.d.ts +10 -0
- package/dist/src/hooks/handlers/session-start.d.ts.map +1 -0
- package/dist/src/hooks/handlers/session-start.js +111 -0
- package/dist/src/hooks/handlers/session-start.js.map +1 -0
- package/dist/src/hooks/handlers/stop.d.ts +14 -0
- package/dist/src/hooks/handlers/stop.d.ts.map +1 -0
- package/dist/src/hooks/handlers/stop.js +49 -0
- package/dist/src/hooks/handlers/stop.js.map +1 -0
- package/dist/src/hooks/handlers/user-prompt.d.ts +10 -0
- package/dist/src/hooks/handlers/user-prompt.d.ts.map +1 -0
- package/dist/src/hooks/handlers/user-prompt.js +128 -0
- package/dist/src/hooks/handlers/user-prompt.js.map +1 -0
- package/dist/src/hooks/index.d.ts +18 -0
- package/dist/src/hooks/index.d.ts.map +1 -0
- package/dist/src/hooks/index.js +23 -0
- package/dist/src/hooks/index.js.map +1 -0
- package/dist/src/hooks/observation.d.ts +59 -0
- package/dist/src/hooks/observation.d.ts.map +1 -0
- package/dist/src/hooks/observation.js +421 -0
- package/dist/src/hooks/observation.js.map +1 -0
- package/dist/src/hooks/state.d.ts +73 -0
- package/dist/src/hooks/state.d.ts.map +1 -0
- package/dist/src/hooks/state.js +168 -0
- package/dist/src/hooks/state.js.map +1 -0
- package/dist/src/hooks/types.d.ts +86 -0
- package/dist/src/hooks/types.d.ts.map +1 -0
- package/dist/src/hooks/types.js +14 -0
- package/dist/src/hooks/types.js.map +1 -0
- package/package.json +9 -5
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observation extraction for auto-capture hooks.
|
|
3
|
+
* Extracts structured observation data from tool usage.
|
|
4
|
+
*/
|
|
5
|
+
import { createHash } from 'crypto';
|
|
6
|
+
// Tools to skip (internal/noisy/self-referential)
|
|
7
|
+
const SKIP_TOOLS = new Set([
|
|
8
|
+
'TodoWrite', 'TodoRead',
|
|
9
|
+
'AskFollowupQuestion', 'AskUserQuestion',
|
|
10
|
+
'AttemptCompletion',
|
|
11
|
+
'LS', // Low signal
|
|
12
|
+
]);
|
|
13
|
+
// Also skip any tool matching these prefixes (memory tools)
|
|
14
|
+
const SKIP_PREFIXES = [
|
|
15
|
+
'mcp__memorylayer',
|
|
16
|
+
'mcp__memory',
|
|
17
|
+
'memory_',
|
|
18
|
+
];
|
|
19
|
+
export function shouldSkipTool(toolName) {
|
|
20
|
+
if (SKIP_TOOLS.has(toolName))
|
|
21
|
+
return true;
|
|
22
|
+
return SKIP_PREFIXES.some(prefix => toolName.startsWith(prefix));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Classify tool as read/write/execute/search/other
|
|
26
|
+
*/
|
|
27
|
+
export function getObservationType(toolName) {
|
|
28
|
+
const readTools = ['Read', 'Glob', 'Grep', 'LS'];
|
|
29
|
+
const writeTools = ['Write', 'Edit', 'MultiEdit', 'NotebookEdit'];
|
|
30
|
+
const executeTools = ['Bash', 'Task', 'Skill'];
|
|
31
|
+
const searchTools = ['WebSearch', 'WebFetch'];
|
|
32
|
+
if (readTools.includes(toolName))
|
|
33
|
+
return 'read';
|
|
34
|
+
if (writeTools.includes(toolName))
|
|
35
|
+
return 'write';
|
|
36
|
+
if (executeTools.includes(toolName))
|
|
37
|
+
return 'execute';
|
|
38
|
+
if (searchTools.includes(toolName))
|
|
39
|
+
return 'search';
|
|
40
|
+
return 'other';
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Extract file paths from tool input, classified as read or modified
|
|
44
|
+
*/
|
|
45
|
+
export function extractFilePaths(toolName, toolInput) {
|
|
46
|
+
const filesRead = [];
|
|
47
|
+
const filesModified = [];
|
|
48
|
+
try {
|
|
49
|
+
const input = typeof toolInput === 'object' && toolInput !== null ? toolInput : {};
|
|
50
|
+
const filePath = input?.file_path || input?.path || '';
|
|
51
|
+
if (!filePath) {
|
|
52
|
+
// Try to extract paths from bash commands
|
|
53
|
+
if (toolName === 'Bash') {
|
|
54
|
+
const command = input?.command || '';
|
|
55
|
+
const pathMatches = command.match(/(?:^|\s)([^\s]+\.(ts|js|py|json|yaml|yml|md|txt|go|rs|java|c|cpp|h))\b/gi);
|
|
56
|
+
if (pathMatches) {
|
|
57
|
+
filesRead.push(...pathMatches.map((p) => p.trim()));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { filesRead, filesModified };
|
|
61
|
+
}
|
|
62
|
+
const type = getObservationType(toolName);
|
|
63
|
+
if (type === 'write') {
|
|
64
|
+
filesModified.push(filePath);
|
|
65
|
+
}
|
|
66
|
+
else if (type === 'read') {
|
|
67
|
+
filesRead.push(filePath);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Ignore parse errors
|
|
72
|
+
}
|
|
73
|
+
return { filesRead, filesModified };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Generate observation title from tool usage
|
|
77
|
+
*/
|
|
78
|
+
export function generateTitle(toolName, toolInput) {
|
|
79
|
+
try {
|
|
80
|
+
const input = typeof toolInput === 'object' && toolInput !== null ? toolInput : {};
|
|
81
|
+
switch (toolName) {
|
|
82
|
+
case 'Read':
|
|
83
|
+
return `Read ${input?.file_path || input?.path || 'file'}`;
|
|
84
|
+
case 'Write':
|
|
85
|
+
return `Write ${input?.file_path || input?.path || 'file'}`;
|
|
86
|
+
case 'Edit':
|
|
87
|
+
case 'MultiEdit':
|
|
88
|
+
return `Edit ${input?.file_path || input?.path || 'file'}`;
|
|
89
|
+
case 'Bash': {
|
|
90
|
+
const cmd = input?.command || '';
|
|
91
|
+
return `Run: ${cmd.substring(0, 50)}${cmd.length > 50 ? '...' : ''}`;
|
|
92
|
+
}
|
|
93
|
+
case 'Glob':
|
|
94
|
+
return `Find ${input?.pattern || 'files'}`;
|
|
95
|
+
case 'Grep':
|
|
96
|
+
return `Search "${input?.pattern || ''}"`;
|
|
97
|
+
case 'Task':
|
|
98
|
+
return `Task: ${input?.description || 'agent'}`;
|
|
99
|
+
case 'WebSearch':
|
|
100
|
+
return `Search: ${input?.query || ''}`;
|
|
101
|
+
case 'WebFetch':
|
|
102
|
+
return `Fetch: ${input?.url || ''}`;
|
|
103
|
+
default:
|
|
104
|
+
return `${toolName}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return toolName;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Extract facts from tool input/response
|
|
113
|
+
*/
|
|
114
|
+
export function extractFacts(toolName, toolInput, toolOutput) {
|
|
115
|
+
const facts = [];
|
|
116
|
+
try {
|
|
117
|
+
const input = typeof toolInput === 'object' && toolInput !== null ? toolInput : {};
|
|
118
|
+
const filePath = input?.file_path || input?.path || '';
|
|
119
|
+
switch (toolName) {
|
|
120
|
+
case 'Read':
|
|
121
|
+
if (filePath)
|
|
122
|
+
facts.push(`File read: ${filePath}`);
|
|
123
|
+
break;
|
|
124
|
+
case 'Write':
|
|
125
|
+
if (filePath)
|
|
126
|
+
facts.push(`File created/updated: ${filePath}`);
|
|
127
|
+
break;
|
|
128
|
+
case 'Edit':
|
|
129
|
+
case 'MultiEdit':
|
|
130
|
+
if (filePath)
|
|
131
|
+
facts.push(`File modified: ${filePath}`);
|
|
132
|
+
if (input?.old_string) {
|
|
133
|
+
facts.push(`Code replaced in ${filePath.split(/[/\\]/).pop() || 'file'}`);
|
|
134
|
+
}
|
|
135
|
+
break;
|
|
136
|
+
case 'Bash': {
|
|
137
|
+
const cmd = input?.command || '';
|
|
138
|
+
facts.push(`Command executed: ${cmd.substring(0, 100)}`);
|
|
139
|
+
// Extract test results
|
|
140
|
+
if (toolOutput) {
|
|
141
|
+
if (toolOutput.includes('passed') || toolOutput.includes('\u2713'))
|
|
142
|
+
facts.push('Tests passed');
|
|
143
|
+
if (toolOutput.includes('failed') || toolOutput.includes('\u2717'))
|
|
144
|
+
facts.push('Tests failed');
|
|
145
|
+
if (toolOutput.includes('error') || toolOutput.includes('Error'))
|
|
146
|
+
facts.push('Errors encountered');
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
case 'Glob':
|
|
151
|
+
if (input?.pattern)
|
|
152
|
+
facts.push(`Pattern searched: ${input.pattern}`);
|
|
153
|
+
break;
|
|
154
|
+
case 'Grep':
|
|
155
|
+
if (input?.pattern)
|
|
156
|
+
facts.push(`Code pattern searched: ${input.pattern}`);
|
|
157
|
+
if (input?.path)
|
|
158
|
+
facts.push(`Search scope: ${input.path}`);
|
|
159
|
+
break;
|
|
160
|
+
case 'WebSearch':
|
|
161
|
+
if (input?.query)
|
|
162
|
+
facts.push(`Web search: ${input.query}`);
|
|
163
|
+
break;
|
|
164
|
+
case 'WebFetch':
|
|
165
|
+
if (input?.url)
|
|
166
|
+
facts.push(`URL fetched: ${input.url}`);
|
|
167
|
+
break;
|
|
168
|
+
case 'Task':
|
|
169
|
+
if (input?.description)
|
|
170
|
+
facts.push(`Sub-task: ${input.description}`);
|
|
171
|
+
if (input?.subagent_type)
|
|
172
|
+
facts.push(`Agent type: ${input.subagent_type}`);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
// Ignore parse errors
|
|
178
|
+
}
|
|
179
|
+
return facts;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Extract concepts/topics from tool usage
|
|
183
|
+
*/
|
|
184
|
+
export function extractConcepts(toolName, toolInput) {
|
|
185
|
+
const concepts = new Set();
|
|
186
|
+
try {
|
|
187
|
+
const input = typeof toolInput === 'object' && toolInput !== null ? toolInput : {};
|
|
188
|
+
const filePath = (input?.file_path || input?.path || '');
|
|
189
|
+
// Extract concepts from file paths
|
|
190
|
+
if (filePath) {
|
|
191
|
+
// Directory-based concepts
|
|
192
|
+
const parts = filePath.split(/[/\\]/);
|
|
193
|
+
for (const part of parts) {
|
|
194
|
+
if (['src', 'lib', 'dist', 'node_modules', '.', '..'].includes(part))
|
|
195
|
+
continue;
|
|
196
|
+
if (part.includes('.')) {
|
|
197
|
+
// File extension concepts
|
|
198
|
+
const ext = part.split('.').pop();
|
|
199
|
+
const extMap = {
|
|
200
|
+
ts: 'typescript', tsx: 'react', js: 'javascript', jsx: 'react',
|
|
201
|
+
py: 'python', rs: 'rust', go: 'golang', css: 'styling', scss: 'styling',
|
|
202
|
+
html: 'html', json: 'configuration', yaml: 'configuration', yml: 'configuration',
|
|
203
|
+
md: 'documentation', test: 'testing', spec: 'testing', sql: 'database',
|
|
204
|
+
};
|
|
205
|
+
if (ext && extMap[ext])
|
|
206
|
+
concepts.add(extMap[ext]);
|
|
207
|
+
}
|
|
208
|
+
// Directory-based concepts
|
|
209
|
+
const dirMap = {
|
|
210
|
+
tests: 'testing', __tests__: 'testing', test: 'testing', spec: 'testing',
|
|
211
|
+
hooks: 'hooks', api: 'api', auth: 'authentication', db: 'database',
|
|
212
|
+
components: 'components', pages: 'pages', routes: 'routing', utils: 'utilities',
|
|
213
|
+
services: 'services', middleware: 'middleware', models: 'models', types: 'types',
|
|
214
|
+
cli: 'cli', config: 'configuration', migrations: 'database', schemas: 'schemas',
|
|
215
|
+
};
|
|
216
|
+
if (dirMap[part])
|
|
217
|
+
concepts.add(dirMap[part]);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Extract function/class names from Edit/MultiEdit for code-specific searchability
|
|
221
|
+
if (toolName === 'Edit' || toolName === 'MultiEdit') {
|
|
222
|
+
const oldStr = (input?.old_string || '');
|
|
223
|
+
const newStr = (input?.new_string || '');
|
|
224
|
+
const combined = oldStr + '\n' + newStr;
|
|
225
|
+
// Extract function names
|
|
226
|
+
const funcMatches = combined.match(/(?:function|async function|const|let|var)\s+(\w{3,})/g);
|
|
227
|
+
if (funcMatches) {
|
|
228
|
+
for (const m of funcMatches.slice(0, 3)) {
|
|
229
|
+
const name = m.replace(/(?:function|async function|const|let|var)\s+/, '');
|
|
230
|
+
concepts.add(`fn:${name}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// Extract class names
|
|
234
|
+
const classMatches = combined.match(/class\s+(\w{3,})/g);
|
|
235
|
+
if (classMatches) {
|
|
236
|
+
for (const m of classMatches.slice(0, 2)) {
|
|
237
|
+
concepts.add(`class:${m.replace('class ', '')}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Extract patterns: import, export, interface, type, enum
|
|
241
|
+
if (/\bimport\b/.test(combined))
|
|
242
|
+
concepts.add('pattern:import');
|
|
243
|
+
if (/\bexport\b/.test(combined))
|
|
244
|
+
concepts.add('pattern:export');
|
|
245
|
+
if (/\binterface\b/.test(combined))
|
|
246
|
+
concepts.add('pattern:interface');
|
|
247
|
+
if (/\benum\b/.test(combined))
|
|
248
|
+
concepts.add('pattern:enum');
|
|
249
|
+
if (/\btry\s*\{/.test(combined))
|
|
250
|
+
concepts.add('pattern:error-handling');
|
|
251
|
+
if (/\basync\b/.test(combined))
|
|
252
|
+
concepts.add('pattern:async');
|
|
253
|
+
}
|
|
254
|
+
// Tool-based concepts
|
|
255
|
+
switch (toolName) {
|
|
256
|
+
case 'Bash': {
|
|
257
|
+
const cmd = (input?.command || '');
|
|
258
|
+
if (cmd.includes('test') || cmd.includes('vitest') || cmd.includes('jest'))
|
|
259
|
+
concepts.add('testing');
|
|
260
|
+
if (cmd.includes('build') || cmd.includes('tsc'))
|
|
261
|
+
concepts.add('build');
|
|
262
|
+
if (cmd.includes('git'))
|
|
263
|
+
concepts.add('version-control');
|
|
264
|
+
if (cmd.includes('npm') || cmd.includes('yarn') || cmd.includes('pnpm'))
|
|
265
|
+
concepts.add('package-management');
|
|
266
|
+
if (cmd.includes('docker'))
|
|
267
|
+
concepts.add('containerization');
|
|
268
|
+
if (cmd.includes('lint') || cmd.includes('eslint'))
|
|
269
|
+
concepts.add('linting');
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case 'WebSearch':
|
|
273
|
+
concepts.add('research');
|
|
274
|
+
break;
|
|
275
|
+
case 'WebFetch':
|
|
276
|
+
concepts.add('web-content');
|
|
277
|
+
break;
|
|
278
|
+
case 'Task':
|
|
279
|
+
concepts.add('delegation');
|
|
280
|
+
if (input?.subagent_type)
|
|
281
|
+
concepts.add(input.subagent_type);
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
// Ignore parse errors
|
|
287
|
+
}
|
|
288
|
+
return Array.from(concepts);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Detect intent from tool usage and user prompt
|
|
292
|
+
*/
|
|
293
|
+
export function detectIntent(toolName, toolInput, prompt) {
|
|
294
|
+
const intentPatterns = {
|
|
295
|
+
bugfix: /fix|bug|error|issue|broken|crash|repair/i,
|
|
296
|
+
feature: /add|feature|implement|create|new|build/i,
|
|
297
|
+
refactor: /refactor|clean|rename|reorganize|restructure/i,
|
|
298
|
+
testing: /test|spec|coverage|verify/i,
|
|
299
|
+
investigation: /find|search|investigate|debug|analyze|explore/i,
|
|
300
|
+
documentation: /document|comment|readme|doc|explain/i,
|
|
301
|
+
};
|
|
302
|
+
// Check user prompt first (if available)
|
|
303
|
+
if (prompt) {
|
|
304
|
+
for (const [intent, pattern] of Object.entries(intentPatterns)) {
|
|
305
|
+
if (pattern.test(prompt)) {
|
|
306
|
+
return intent;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Check tool input
|
|
311
|
+
try {
|
|
312
|
+
const input = typeof toolInput === 'object' && toolInput !== null ? toolInput : {};
|
|
313
|
+
const inputStr = JSON.stringify(input);
|
|
314
|
+
for (const [intent, pattern] of Object.entries(intentPatterns)) {
|
|
315
|
+
if (pattern.test(inputStr)) {
|
|
316
|
+
return intent;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
catch {
|
|
321
|
+
// Ignore parse errors
|
|
322
|
+
}
|
|
323
|
+
// Tool-based intent detection
|
|
324
|
+
switch (toolName) {
|
|
325
|
+
case 'Read':
|
|
326
|
+
case 'Glob':
|
|
327
|
+
case 'Grep':
|
|
328
|
+
return 'investigation';
|
|
329
|
+
case 'Write':
|
|
330
|
+
return 'feature';
|
|
331
|
+
case 'Edit':
|
|
332
|
+
return null; // Too ambiguous without context
|
|
333
|
+
default:
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Compute content hash for deduplication
|
|
339
|
+
*/
|
|
340
|
+
export function computeContentHash(...parts) {
|
|
341
|
+
return createHash('sha256')
|
|
342
|
+
.update(parts.join('|'))
|
|
343
|
+
.digest('hex')
|
|
344
|
+
.slice(0, 16);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Truncate string to max length
|
|
348
|
+
*/
|
|
349
|
+
export function truncate(str, maxLen = 500) {
|
|
350
|
+
if (str.length <= maxLen)
|
|
351
|
+
return str;
|
|
352
|
+
return str.substring(0, maxLen) + '...';
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Build observation from hook input
|
|
356
|
+
*/
|
|
357
|
+
export function buildObservation(input, currentPrompt) {
|
|
358
|
+
const toolName = input.tool_name;
|
|
359
|
+
if (!toolName)
|
|
360
|
+
return null;
|
|
361
|
+
// Extract all components
|
|
362
|
+
const type = getObservationType(toolName);
|
|
363
|
+
const title = generateTitle(toolName, input.tool_input);
|
|
364
|
+
const { filesRead, filesModified } = extractFilePaths(toolName, input.tool_input);
|
|
365
|
+
const facts = extractFacts(toolName, input.tool_input, input.tool_output);
|
|
366
|
+
const concepts = extractConcepts(toolName, input.tool_input);
|
|
367
|
+
const intent = detectIntent(toolName, input.tool_input, currentPrompt);
|
|
368
|
+
// Build summary
|
|
369
|
+
const summary = buildSummary(toolName, input.tool_input, input.tool_output, filesRead, filesModified);
|
|
370
|
+
// Compute content hash for dedup
|
|
371
|
+
const contentHash = computeContentHash(toolName, JSON.stringify(input.tool_input || {}), summary);
|
|
372
|
+
// Skip if empty observation (no meaningful data extracted)
|
|
373
|
+
if (filesRead.length === 0 && filesModified.length === 0 && facts.length === 0 && concepts.length === 0) {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
return {
|
|
377
|
+
type,
|
|
378
|
+
title,
|
|
379
|
+
toolName,
|
|
380
|
+
filesRead,
|
|
381
|
+
filesModified,
|
|
382
|
+
facts,
|
|
383
|
+
concepts,
|
|
384
|
+
intent,
|
|
385
|
+
contentHash,
|
|
386
|
+
summary,
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Build human-readable summary
|
|
391
|
+
*/
|
|
392
|
+
function buildSummary(toolName, toolInput, _toolOutput, filesRead, filesModified) {
|
|
393
|
+
const parts = [];
|
|
394
|
+
if (filesRead.length > 0) {
|
|
395
|
+
parts.push(`Read: ${filesRead.join(', ')}`);
|
|
396
|
+
}
|
|
397
|
+
if (filesModified.length > 0) {
|
|
398
|
+
parts.push(`Modified: ${filesModified.join(', ')}`);
|
|
399
|
+
}
|
|
400
|
+
// Add tool-specific context
|
|
401
|
+
try {
|
|
402
|
+
const input = typeof toolInput === 'object' && toolInput !== null ? toolInput : {};
|
|
403
|
+
if (toolName === 'Bash') {
|
|
404
|
+
const cmd = input?.command || '';
|
|
405
|
+
parts.push(`Command: ${truncate(cmd, 100)}`);
|
|
406
|
+
}
|
|
407
|
+
else if (toolName === 'Grep') {
|
|
408
|
+
const pattern = input?.pattern || '';
|
|
409
|
+
parts.push(`Pattern: ${pattern}`);
|
|
410
|
+
}
|
|
411
|
+
else if (toolName === 'Task') {
|
|
412
|
+
const desc = input?.description || '';
|
|
413
|
+
parts.push(`Task: ${truncate(desc, 100)}`);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
// Ignore
|
|
418
|
+
}
|
|
419
|
+
return parts.length > 0 ? parts.join('; ') : `Used ${toolName}`;
|
|
420
|
+
}
|
|
421
|
+
//# sourceMappingURL=observation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observation.js","sourceRoot":"","sources":["../../../src/hooks/observation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGpC,kDAAkD;AAClD,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,WAAW,EAAE,UAAU;IACvB,qBAAqB,EAAE,iBAAiB;IACxC,mBAAmB;IACnB,IAAI,EAAG,aAAa;CACrB,CAAC,CAAC;AAEH,4DAA4D;AAC5D,MAAM,aAAa,GAAG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ClE,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook state management - persists state between hook invocations
|
|
3
|
+
*/
|
|
4
|
+
import type { HookState } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Read current hook state from disk
|
|
7
|
+
*/
|
|
8
|
+
export declare function readHookState(): HookState;
|
|
9
|
+
/**
|
|
10
|
+
* Write hook state to disk
|
|
11
|
+
*/
|
|
12
|
+
export declare function writeHookState(state: HookState): void;
|
|
13
|
+
/**
|
|
14
|
+
* Mark that recall has been done this turn for a specific query
|
|
15
|
+
*/
|
|
16
|
+
export declare function markRecallDone(query: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* Check if recall was already done this turn (any query)
|
|
19
|
+
*/
|
|
20
|
+
export declare function wasRecallDoneThisTurn(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Check if a specific query (or similar) was already recalled this turn.
|
|
23
|
+
* Allows different queries to proceed even if a recall was already done.
|
|
24
|
+
*/
|
|
25
|
+
export declare function wasQueryRecalledThisTurn(query: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Reset recall status for new turn
|
|
28
|
+
*/
|
|
29
|
+
export declare function resetRecallStatus(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Store the user's current topic for cross-hook context
|
|
32
|
+
*/
|
|
33
|
+
export declare function setCurrentTopic(topic: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get the user's current topic (set by UserPromptSubmit)
|
|
36
|
+
*/
|
|
37
|
+
export declare function getCurrentTopic(): string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Store the user's current prompt for cross-hook context
|
|
40
|
+
*/
|
|
41
|
+
export declare function setCurrentPrompt(prompt: string): void;
|
|
42
|
+
/**
|
|
43
|
+
* Get the user's current prompt (set by UserPromptSubmit)
|
|
44
|
+
*/
|
|
45
|
+
export declare function getCurrentPrompt(): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
* Update workspace/session info
|
|
48
|
+
*/
|
|
49
|
+
export declare function updateSessionInfo(workspaceId: string, sessionId?: string): void;
|
|
50
|
+
/** Return the last durably acknowledged byte boundary for this transcript. */
|
|
51
|
+
export declare function getCheckpointBoundary(sessionId: string, transcriptPath: string): number;
|
|
52
|
+
/** Advance a transcript boundary only after the server acknowledges raw capture. */
|
|
53
|
+
export declare function acknowledgeCheckpointBoundary(sessionId: string, transcriptPath: string, boundary: number): void;
|
|
54
|
+
/**
|
|
55
|
+
* Get current workspace ID from state
|
|
56
|
+
*/
|
|
57
|
+
export declare function getWorkspaceId(): string | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Get current session ID from hook-state.json (disk read, singleton).
|
|
60
|
+
* Prefer resolveSessionId() which checks env first and avoids disk I/O.
|
|
61
|
+
*/
|
|
62
|
+
export declare function getSessionIdFromHookState(): string | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Resolve session ID with env-first strategy.
|
|
65
|
+
*
|
|
66
|
+
* Prefers process.env.MEMORYLAYER_SESSION_ID (session-scoped via CLAUDE_ENV_FILE)
|
|
67
|
+
* over hook-state.json (singleton, shared across concurrent sessions).
|
|
68
|
+
* Only falls back to disk read if env var is not set.
|
|
69
|
+
*
|
|
70
|
+
* @param caller - label for diagnostic logging (e.g. "post-tool", "stop")
|
|
71
|
+
*/
|
|
72
|
+
export declare function resolveSessionId(caller: string): string | undefined;
|
|
73
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/hooks/state.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAU5C;;GAEG;AACH,wBAAgB,aAAa,IAAI,SAAS,CAUzC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CASrD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,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