@stackmemoryai/stackmemory 0.3.3 → 0.3.5
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/README.md +19 -18
- package/dist/cli/commands/chromadb.js +267 -0
- package/dist/cli/commands/chromadb.js.map +7 -0
- package/dist/cli/commands/context.js +15 -5
- package/dist/cli/commands/context.js.map +2 -2
- package/dist/cli/commands/skills.js +262 -0
- package/dist/cli/commands/skills.js.map +7 -0
- package/dist/cli/index.js +5 -0
- package/dist/cli/index.js.map +2 -2
- package/dist/core/context/frame-handoff-manager.js +399 -9
- package/dist/core/context/frame-handoff-manager.js.map +2 -2
- package/dist/core/context/frame-manager.js +11 -2
- package/dist/core/context/frame-manager.js.map +2 -2
- package/dist/core/storage/chromadb-adapter.js +346 -0
- package/dist/core/storage/chromadb-adapter.js.map +7 -0
- package/dist/skills/claude-skills.js +666 -0
- package/dist/skills/claude-skills.js.map +7 -0
- package/package.json +21 -31
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
import { logger } from "../core/monitoring/logger.js";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import * as os from "os";
|
|
5
|
+
class HandoffSkill {
|
|
6
|
+
constructor(context) {
|
|
7
|
+
this.context = context;
|
|
8
|
+
}
|
|
9
|
+
async execute(targetUser, message, options) {
|
|
10
|
+
try {
|
|
11
|
+
const activeStack = this.context.dualStackManager.getActiveStack();
|
|
12
|
+
let framesToHandoff = options?.frames || [];
|
|
13
|
+
if (options?.autoDetect !== false && framesToHandoff.length === 0) {
|
|
14
|
+
const allFrames = await activeStack.getAllFrames();
|
|
15
|
+
const relevantFrames = allFrames.filter(
|
|
16
|
+
(f) => f.state === "completed" || f.outputs && Array.isArray(f.outputs) && f.outputs.some((o) => o.type === "error")
|
|
17
|
+
);
|
|
18
|
+
framesToHandoff = relevantFrames.slice(-5).map((f) => f.frameId);
|
|
19
|
+
}
|
|
20
|
+
if (framesToHandoff.length === 0) {
|
|
21
|
+
return {
|
|
22
|
+
success: false,
|
|
23
|
+
message: "No frames to handoff. Specify frames or complete some work first."
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const frameDetails = await Promise.all(
|
|
27
|
+
framesToHandoff.map((id) => activeStack.getFrame(id))
|
|
28
|
+
);
|
|
29
|
+
const summary = this.generateHandoffSummary(frameDetails, message);
|
|
30
|
+
const metadata = {
|
|
31
|
+
initiatedAt: /* @__PURE__ */ new Date(),
|
|
32
|
+
initiatorId: this.context.userId,
|
|
33
|
+
targetUserId: targetUser,
|
|
34
|
+
frameContext: {
|
|
35
|
+
totalFrames: framesToHandoff.length,
|
|
36
|
+
frameTypes: [
|
|
37
|
+
...new Set(frameDetails.map((f) => f?.type || "unknown"))
|
|
38
|
+
],
|
|
39
|
+
estimatedSize: JSON.stringify(frameDetails).length,
|
|
40
|
+
dependencies: this.extractDependencies(frameDetails)
|
|
41
|
+
},
|
|
42
|
+
businessContext: {
|
|
43
|
+
priority: options?.priority || "medium",
|
|
44
|
+
stakeholders: [targetUser]
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const availableStacks = await this.context.dualStackManager.getAvailableStacks();
|
|
48
|
+
let targetStackId = availableStacks.find(
|
|
49
|
+
(s) => s.type === "shared"
|
|
50
|
+
)?.stackId;
|
|
51
|
+
if (!targetStackId) {
|
|
52
|
+
targetStackId = await this.context.dualStackManager.createSharedStack(
|
|
53
|
+
"team",
|
|
54
|
+
`Handoff: ${message.slice(0, 50)}`,
|
|
55
|
+
this.context.userId
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
const handoffId = await this.context.handoffManager.initiateHandoff(
|
|
59
|
+
targetStackId,
|
|
60
|
+
framesToHandoff,
|
|
61
|
+
metadata,
|
|
62
|
+
targetUser,
|
|
63
|
+
summary
|
|
64
|
+
);
|
|
65
|
+
const actionItems = this.generateActionItems(frameDetails);
|
|
66
|
+
return {
|
|
67
|
+
success: true,
|
|
68
|
+
message: `Handoff initiated to @${targetUser}`,
|
|
69
|
+
data: {
|
|
70
|
+
handoffId,
|
|
71
|
+
frameCount: framesToHandoff.length,
|
|
72
|
+
priority: options?.priority || "medium",
|
|
73
|
+
actionItems,
|
|
74
|
+
targetStack: targetStackId
|
|
75
|
+
},
|
|
76
|
+
action: `Notified ${targetUser}. Handoff ID: ${handoffId}`
|
|
77
|
+
};
|
|
78
|
+
} catch (error) {
|
|
79
|
+
logger.error("Handoff skill error:", error);
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
message: `Failed to initiate handoff: ${error.message}`
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
generateHandoffSummary(frames, message) {
|
|
87
|
+
const completed = frames.filter((f) => f?.state === "completed").length;
|
|
88
|
+
const blocked = frames.filter(
|
|
89
|
+
(f) => f?.outputs?.some((o) => o.type === "error")
|
|
90
|
+
).length;
|
|
91
|
+
return `
|
|
92
|
+
## Handoff Summary
|
|
93
|
+
**Message**: ${message}
|
|
94
|
+
**Frames**: ${frames.length} total (${completed} completed, ${blocked} blocked)
|
|
95
|
+
|
|
96
|
+
### Work Completed:
|
|
97
|
+
${frames.filter((f) => f?.state === "completed").map((f) => `- ${f.name}: ${f.digest_deterministic?.summary || "No summary"}`).join("\n")}
|
|
98
|
+
|
|
99
|
+
### Attention Required:
|
|
100
|
+
${frames.filter((f) => f?.outputs?.some((o) => o.type === "error")).map(
|
|
101
|
+
(f) => `- ${f.name}: ${f.outputs.find((o) => o.type === "error")?.content || "Error"}`
|
|
102
|
+
).join("\n") || "None"}
|
|
103
|
+
|
|
104
|
+
### Context:
|
|
105
|
+
${frames.map((f) => f?.digest_ai?.context || "").filter(Boolean).join("\n")}
|
|
106
|
+
`.trim();
|
|
107
|
+
}
|
|
108
|
+
extractDependencies(frames) {
|
|
109
|
+
const deps = /* @__PURE__ */ new Set();
|
|
110
|
+
frames.forEach((frame) => {
|
|
111
|
+
if (frame?.inputs?.dependencies) {
|
|
112
|
+
if (Array.isArray(frame.inputs.dependencies)) {
|
|
113
|
+
frame.inputs.dependencies.forEach((d) => deps.add(d));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (frame?.outputs) {
|
|
117
|
+
frame.outputs.forEach((output) => {
|
|
118
|
+
if (output.type === "dependency") {
|
|
119
|
+
deps.add(output.content);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
return Array.from(deps);
|
|
125
|
+
}
|
|
126
|
+
generateActionItems(frames) {
|
|
127
|
+
const items = [];
|
|
128
|
+
frames.forEach((frame) => {
|
|
129
|
+
if (frame?.outputs) {
|
|
130
|
+
frame.outputs.forEach((output) => {
|
|
131
|
+
if (output.type === "todo" || output.content?.includes("TODO")) {
|
|
132
|
+
items.push(output.content);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
if (frame?.outputs?.some((o) => o.type === "error")) {
|
|
137
|
+
items.push(`Resolve error in ${frame.name}`);
|
|
138
|
+
}
|
|
139
|
+
if (frame?.inputs?.tests === "pending" || frame?.type === "implementation" || frame?.name && frame.name.toLowerCase().includes("implementation")) {
|
|
140
|
+
items.push(`Write tests for ${frame.name}`);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
return items;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
class CheckpointSkill {
|
|
147
|
+
constructor(context) {
|
|
148
|
+
this.context = context;
|
|
149
|
+
this.checkpointDir = path.join(
|
|
150
|
+
os.homedir(),
|
|
151
|
+
".stackmemory",
|
|
152
|
+
"checkpoints",
|
|
153
|
+
context.projectId
|
|
154
|
+
);
|
|
155
|
+
fs.mkdirSync(this.checkpointDir, { recursive: true });
|
|
156
|
+
}
|
|
157
|
+
checkpointDir;
|
|
158
|
+
async create(description, options) {
|
|
159
|
+
try {
|
|
160
|
+
const timestamp = Date.now();
|
|
161
|
+
const checkpointId = `checkpoint-${timestamp}-${Math.random().toString(36).slice(2, 8)}`;
|
|
162
|
+
const activeStack = this.context.dualStackManager.getActiveStack();
|
|
163
|
+
const currentContext = this.context.dualStackManager.getCurrentContext();
|
|
164
|
+
const allFrames = await activeStack.getAllFrames();
|
|
165
|
+
const checkpoint = {
|
|
166
|
+
id: checkpointId,
|
|
167
|
+
timestamp,
|
|
168
|
+
description,
|
|
169
|
+
context: {
|
|
170
|
+
stackId: currentContext.stackId,
|
|
171
|
+
stackType: currentContext.type,
|
|
172
|
+
userId: this.context.userId,
|
|
173
|
+
projectId: this.context.projectId
|
|
174
|
+
},
|
|
175
|
+
frames: allFrames,
|
|
176
|
+
metadata: {
|
|
177
|
+
...options?.metadata,
|
|
178
|
+
frameCount: allFrames.length,
|
|
179
|
+
activeFrames: allFrames.filter((f) => f.state === "active").length,
|
|
180
|
+
completedFrames: allFrames.filter((f) => f.state === "completed").length
|
|
181
|
+
},
|
|
182
|
+
files: options?.includeFiles || []
|
|
183
|
+
};
|
|
184
|
+
const checkpointPath = path.join(
|
|
185
|
+
this.checkpointDir,
|
|
186
|
+
`${checkpointId}.json`
|
|
187
|
+
);
|
|
188
|
+
fs.writeFileSync(checkpointPath, JSON.stringify(checkpoint, null, 2));
|
|
189
|
+
if (options?.includeFiles && options.includeFiles.length > 0) {
|
|
190
|
+
const filesDir = path.join(this.checkpointDir, checkpointId, "files");
|
|
191
|
+
fs.mkdirSync(filesDir, { recursive: true });
|
|
192
|
+
for (const file of options.includeFiles) {
|
|
193
|
+
if (fs.existsSync(file)) {
|
|
194
|
+
const basename = path.basename(file);
|
|
195
|
+
const backupPath = path.join(filesDir, basename);
|
|
196
|
+
fs.copyFileSync(file, backupPath);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (options?.autoDetectRisky) {
|
|
201
|
+
const riskyPatterns = [
|
|
202
|
+
"migration",
|
|
203
|
+
"database",
|
|
204
|
+
"deploy",
|
|
205
|
+
"production",
|
|
206
|
+
"delete",
|
|
207
|
+
"remove",
|
|
208
|
+
"drop",
|
|
209
|
+
"migrate"
|
|
210
|
+
// Add more specific pattern
|
|
211
|
+
];
|
|
212
|
+
const isRisky = allFrames.some((frame) => {
|
|
213
|
+
const nameMatches = frame.name && riskyPatterns.some(
|
|
214
|
+
(pattern) => frame.name.toLowerCase().includes(pattern)
|
|
215
|
+
);
|
|
216
|
+
const commandMatches = frame.inputs?.command && riskyPatterns.some(
|
|
217
|
+
(pattern) => frame.inputs.command.toLowerCase().includes(pattern)
|
|
218
|
+
);
|
|
219
|
+
return nameMatches || commandMatches;
|
|
220
|
+
});
|
|
221
|
+
if (isRisky) {
|
|
222
|
+
checkpoint.metadata.riskyOperation = true;
|
|
223
|
+
checkpoint.metadata.autoCheckpoint = true;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
fs.writeFileSync(checkpointPath, JSON.stringify(checkpoint, null, 2));
|
|
227
|
+
logger.info(`Created checkpoint: ${checkpointId}`);
|
|
228
|
+
return {
|
|
229
|
+
success: true,
|
|
230
|
+
message: `Checkpoint created: ${description}`,
|
|
231
|
+
data: {
|
|
232
|
+
checkpointId,
|
|
233
|
+
timestamp: new Date(timestamp).toISOString(),
|
|
234
|
+
frameCount: checkpoint.metadata.frameCount,
|
|
235
|
+
location: checkpointPath
|
|
236
|
+
},
|
|
237
|
+
action: `Saved checkpoint ${checkpointId}`
|
|
238
|
+
};
|
|
239
|
+
} catch (error) {
|
|
240
|
+
logger.error("Checkpoint creation error:", error);
|
|
241
|
+
return {
|
|
242
|
+
success: false,
|
|
243
|
+
message: `Failed to create checkpoint: ${error.message}`
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
async restore(checkpointId) {
|
|
248
|
+
try {
|
|
249
|
+
const checkpointPath = path.join(
|
|
250
|
+
this.checkpointDir,
|
|
251
|
+
`${checkpointId}.json`
|
|
252
|
+
);
|
|
253
|
+
if (!fs.existsSync(checkpointPath)) {
|
|
254
|
+
const files = fs.readdirSync(this.checkpointDir);
|
|
255
|
+
const match = files.find((f) => f.includes(checkpointId));
|
|
256
|
+
if (match) {
|
|
257
|
+
checkpointId = match.replace(".json", "");
|
|
258
|
+
} else {
|
|
259
|
+
return {
|
|
260
|
+
success: false,
|
|
261
|
+
message: `Checkpoint not found: ${checkpointId}`
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const checkpoint = JSON.parse(fs.readFileSync(checkpointPath, "utf-8"));
|
|
266
|
+
await this.context.dualStackManager.switchToStack(
|
|
267
|
+
checkpoint.context.stackId
|
|
268
|
+
);
|
|
269
|
+
const filesDir = path.join(this.checkpointDir, checkpointId, "files");
|
|
270
|
+
if (fs.existsSync(filesDir)) {
|
|
271
|
+
const files = fs.readdirSync(filesDir);
|
|
272
|
+
for (const file of files) {
|
|
273
|
+
const backupPath = path.join(filesDir, file);
|
|
274
|
+
const originalPath = checkpoint.files.find(
|
|
275
|
+
(f) => path.basename(f) === file
|
|
276
|
+
);
|
|
277
|
+
if (originalPath && fs.existsSync(backupPath)) {
|
|
278
|
+
fs.copyFileSync(backupPath, originalPath);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
logger.info(`Restored checkpoint: ${checkpointId}`);
|
|
283
|
+
return {
|
|
284
|
+
success: true,
|
|
285
|
+
message: `Restored to checkpoint: ${checkpoint.description}`,
|
|
286
|
+
data: {
|
|
287
|
+
checkpointId,
|
|
288
|
+
timestamp: new Date(checkpoint.timestamp).toISOString(),
|
|
289
|
+
frameCount: checkpoint.metadata.frameCount,
|
|
290
|
+
filesRestored: checkpoint.files.length
|
|
291
|
+
},
|
|
292
|
+
action: `Restored checkpoint from ${new Date(checkpoint.timestamp).toLocaleString()}`
|
|
293
|
+
};
|
|
294
|
+
} catch (error) {
|
|
295
|
+
logger.error("Checkpoint restoration error:", error);
|
|
296
|
+
return {
|
|
297
|
+
success: false,
|
|
298
|
+
message: `Failed to restore checkpoint: ${error.message}`
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
async list(options) {
|
|
303
|
+
try {
|
|
304
|
+
const files = fs.readdirSync(this.checkpointDir).filter((f) => f.endsWith(".json")).map((f) => {
|
|
305
|
+
const checkpointPath = path.join(this.checkpointDir, f);
|
|
306
|
+
const checkpoint = JSON.parse(
|
|
307
|
+
fs.readFileSync(checkpointPath, "utf-8")
|
|
308
|
+
);
|
|
309
|
+
return checkpoint;
|
|
310
|
+
}).filter((c) => !options?.since || c.timestamp > options.since.getTime()).sort((a, b) => b.timestamp - a.timestamp).slice(0, options?.limit || 10);
|
|
311
|
+
return {
|
|
312
|
+
success: true,
|
|
313
|
+
message: `Found ${files.length} checkpoints`,
|
|
314
|
+
data: files.map((c) => ({
|
|
315
|
+
id: c.id,
|
|
316
|
+
description: c.description,
|
|
317
|
+
timestamp: new Date(c.timestamp).toISOString(),
|
|
318
|
+
frameCount: c.metadata.frameCount,
|
|
319
|
+
risky: c.metadata.riskyOperation || false
|
|
320
|
+
}))
|
|
321
|
+
};
|
|
322
|
+
} catch (error) {
|
|
323
|
+
logger.error("Checkpoint list error:", error);
|
|
324
|
+
return {
|
|
325
|
+
success: false,
|
|
326
|
+
message: `Failed to list checkpoints: ${error.message}`
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
async diff(checkpoint1, checkpoint2) {
|
|
331
|
+
try {
|
|
332
|
+
const cp1 = await this.loadCheckpoint(checkpoint1);
|
|
333
|
+
const cp2 = await this.loadCheckpoint(checkpoint2);
|
|
334
|
+
if (!cp1 || !cp2) {
|
|
335
|
+
return {
|
|
336
|
+
success: false,
|
|
337
|
+
message: "One or both checkpoints not found"
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
const diff = {
|
|
341
|
+
timeDiff: Math.abs(cp2.timestamp - cp1.timestamp),
|
|
342
|
+
framesDiff: cp2.frames.length - cp1.frames.length,
|
|
343
|
+
newFrames: cp2.frames.filter(
|
|
344
|
+
(f2) => !cp1.frames.some((f1) => f1.frameId === f2.frameId)
|
|
345
|
+
),
|
|
346
|
+
removedFrames: cp1.frames.filter(
|
|
347
|
+
(f1) => !cp2.frames.some((f2) => f2.frameId === f1.frameId)
|
|
348
|
+
),
|
|
349
|
+
modifiedFrames: cp2.frames.filter((f2) => {
|
|
350
|
+
const f1 = cp1.frames.find((f) => f.frameId === f2.frameId);
|
|
351
|
+
return f1 && JSON.stringify(f1) !== JSON.stringify(f2);
|
|
352
|
+
})
|
|
353
|
+
};
|
|
354
|
+
return {
|
|
355
|
+
success: true,
|
|
356
|
+
message: `Diff between ${cp1.description} and ${cp2.description}`,
|
|
357
|
+
data: {
|
|
358
|
+
timeDiff: `${Math.round(diff.timeDiff / 1e3 / 60)} minutes`,
|
|
359
|
+
framesDiff: diff.framesDiff > 0 ? `+${diff.framesDiff}` : `${diff.framesDiff}`,
|
|
360
|
+
newFrames: diff.newFrames.length,
|
|
361
|
+
removedFrames: diff.removedFrames.length,
|
|
362
|
+
modifiedFrames: diff.modifiedFrames.length,
|
|
363
|
+
details: diff
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
} catch (error) {
|
|
367
|
+
logger.error("Checkpoint diff error:", error);
|
|
368
|
+
return {
|
|
369
|
+
success: false,
|
|
370
|
+
message: `Failed to diff checkpoints: ${error.message}`
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
async loadCheckpoint(checkpointId) {
|
|
375
|
+
const checkpointPath = path.join(
|
|
376
|
+
this.checkpointDir,
|
|
377
|
+
`${checkpointId}.json`
|
|
378
|
+
);
|
|
379
|
+
if (fs.existsSync(checkpointPath)) {
|
|
380
|
+
return JSON.parse(fs.readFileSync(checkpointPath, "utf-8"));
|
|
381
|
+
}
|
|
382
|
+
const files = fs.readdirSync(this.checkpointDir);
|
|
383
|
+
const match = files.find((f) => f.includes(checkpointId));
|
|
384
|
+
if (match) {
|
|
385
|
+
const path2 = path2.join(this.checkpointDir, match);
|
|
386
|
+
return JSON.parse(fs.readFileSync(path2, "utf-8"));
|
|
387
|
+
}
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
class ArchaeologistSkill {
|
|
392
|
+
constructor(context) {
|
|
393
|
+
this.context = context;
|
|
394
|
+
}
|
|
395
|
+
async dig(query, options) {
|
|
396
|
+
try {
|
|
397
|
+
const depth = this.parseDepth(options?.depth || "30days");
|
|
398
|
+
const since = new Date(Date.now() - depth);
|
|
399
|
+
const results = await this.context.contextRetriever.retrieve({
|
|
400
|
+
query,
|
|
401
|
+
projectId: this.context.projectId,
|
|
402
|
+
limit: 50,
|
|
403
|
+
minScore: 0.3
|
|
404
|
+
});
|
|
405
|
+
const filtered = results.filter(
|
|
406
|
+
(r) => !depth || new Date(r.timestamp) > since
|
|
407
|
+
);
|
|
408
|
+
let patterns = [];
|
|
409
|
+
if (options?.patterns) {
|
|
410
|
+
patterns = this.extractPatterns(filtered);
|
|
411
|
+
}
|
|
412
|
+
let decisions = [];
|
|
413
|
+
if (options?.decisions) {
|
|
414
|
+
decisions = this.extractDecisions(filtered);
|
|
415
|
+
}
|
|
416
|
+
let timeline = [];
|
|
417
|
+
if (options?.timeline) {
|
|
418
|
+
timeline = this.generateTimeline(filtered);
|
|
419
|
+
}
|
|
420
|
+
const topResults = filtered.slice(0, 10);
|
|
421
|
+
const summary = this.generateArchaeologySummary(
|
|
422
|
+
topResults,
|
|
423
|
+
patterns,
|
|
424
|
+
decisions,
|
|
425
|
+
timeline
|
|
426
|
+
);
|
|
427
|
+
return {
|
|
428
|
+
success: true,
|
|
429
|
+
message: `Found ${filtered.length} relevant results`,
|
|
430
|
+
data: {
|
|
431
|
+
totalResults: filtered.length,
|
|
432
|
+
timeRange: {
|
|
433
|
+
from: since.toISOString(),
|
|
434
|
+
to: (/* @__PURE__ */ new Date()).toISOString()
|
|
435
|
+
},
|
|
436
|
+
topResults: topResults.map((r) => ({
|
|
437
|
+
frameId: r.frameId,
|
|
438
|
+
score: r.score,
|
|
439
|
+
timestamp: r.timestamp,
|
|
440
|
+
summary: r.content.slice(0, 100) + "..."
|
|
441
|
+
})),
|
|
442
|
+
patterns,
|
|
443
|
+
decisions,
|
|
444
|
+
timeline,
|
|
445
|
+
summary
|
|
446
|
+
},
|
|
447
|
+
action: `Analyzed ${filtered.length} frames from ${options?.depth || "30days"} of history`
|
|
448
|
+
};
|
|
449
|
+
} catch (error) {
|
|
450
|
+
logger.error("Archaeology skill error:", error);
|
|
451
|
+
return {
|
|
452
|
+
success: false,
|
|
453
|
+
message: `Failed to dig through context: ${error.message}`
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
parseDepth(depth) {
|
|
458
|
+
const match = depth.match(/^(\d+)(days?|weeks?|months?|years?|all)$/i);
|
|
459
|
+
if (!match) {
|
|
460
|
+
return 30 * 24 * 60 * 60 * 1e3;
|
|
461
|
+
}
|
|
462
|
+
const [, num, unit] = match;
|
|
463
|
+
const value = parseInt(num);
|
|
464
|
+
switch (unit.toLowerCase()) {
|
|
465
|
+
case "day":
|
|
466
|
+
case "days":
|
|
467
|
+
return value * 24 * 60 * 60 * 1e3;
|
|
468
|
+
case "week":
|
|
469
|
+
case "weeks":
|
|
470
|
+
return value * 7 * 24 * 60 * 60 * 1e3;
|
|
471
|
+
case "month":
|
|
472
|
+
case "months":
|
|
473
|
+
return value * 30 * 24 * 60 * 60 * 1e3;
|
|
474
|
+
case "year":
|
|
475
|
+
case "years":
|
|
476
|
+
return value * 365 * 24 * 60 * 60 * 1e3;
|
|
477
|
+
case "all":
|
|
478
|
+
return Number.MAX_SAFE_INTEGER;
|
|
479
|
+
default:
|
|
480
|
+
return 30 * 24 * 60 * 60 * 1e3;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
extractPatterns(results) {
|
|
484
|
+
const patterns = /* @__PURE__ */ new Map();
|
|
485
|
+
const patternTypes = [
|
|
486
|
+
{ regex: /test.*then.*implement/i, name: "TDD" },
|
|
487
|
+
{ regex: /refactor/i, name: "Refactoring" },
|
|
488
|
+
{ regex: /debug|fix|error|bug/i, name: "Debugging" },
|
|
489
|
+
{ regex: /implement.*feature/i, name: "Feature Development" },
|
|
490
|
+
{ regex: /review|code review/i, name: "Code Review" },
|
|
491
|
+
{ regex: /deploy|release/i, name: "Deployment" },
|
|
492
|
+
{ regex: /optimize|performance/i, name: "Optimization" }
|
|
493
|
+
];
|
|
494
|
+
results.forEach((result) => {
|
|
495
|
+
patternTypes.forEach((pattern) => {
|
|
496
|
+
if (pattern.regex.test(result.content)) {
|
|
497
|
+
patterns.set(pattern.name, (patterns.get(pattern.name) || 0) + 1);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
return Array.from(patterns.entries()).map(([name, count]) => ({ name, count })).sort((a, b) => b.count - a.count);
|
|
502
|
+
}
|
|
503
|
+
extractDecisions(results) {
|
|
504
|
+
const decisions = [];
|
|
505
|
+
const decisionKeywords = [
|
|
506
|
+
"decided",
|
|
507
|
+
"chose",
|
|
508
|
+
"selected",
|
|
509
|
+
"will use",
|
|
510
|
+
"going with",
|
|
511
|
+
"approach",
|
|
512
|
+
"strategy",
|
|
513
|
+
"solution"
|
|
514
|
+
];
|
|
515
|
+
results.forEach((result) => {
|
|
516
|
+
const content = result.content.toLowerCase();
|
|
517
|
+
if (decisionKeywords.some((keyword) => content.includes(keyword))) {
|
|
518
|
+
const sentences = result.content.split(/[.!?]+/);
|
|
519
|
+
const decisionSentence = sentences.find(
|
|
520
|
+
(s) => decisionKeywords.some((k) => s.toLowerCase().includes(k))
|
|
521
|
+
);
|
|
522
|
+
if (decisionSentence) {
|
|
523
|
+
decisions.push({
|
|
524
|
+
frameId: result.frameId,
|
|
525
|
+
timestamp: result.timestamp,
|
|
526
|
+
decision: decisionSentence.trim(),
|
|
527
|
+
context: result.content.slice(0, 200)
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
return decisions.slice(0, 10);
|
|
533
|
+
}
|
|
534
|
+
generateTimeline(results) {
|
|
535
|
+
const timeline = /* @__PURE__ */ new Map();
|
|
536
|
+
results.forEach((result) => {
|
|
537
|
+
const date = new Date(result.timestamp).toDateString();
|
|
538
|
+
if (!timeline.has(date)) {
|
|
539
|
+
timeline.set(date, []);
|
|
540
|
+
}
|
|
541
|
+
timeline.get(date).push(result);
|
|
542
|
+
});
|
|
543
|
+
return Array.from(timeline.entries()).map(([date, items]) => ({
|
|
544
|
+
date,
|
|
545
|
+
itemCount: items.length,
|
|
546
|
+
highlights: items.slice(0, 3).map((item) => ({
|
|
547
|
+
frameId: item.frameId,
|
|
548
|
+
summary: item.content.slice(0, 50) + "..."
|
|
549
|
+
}))
|
|
550
|
+
})).sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
|
|
551
|
+
}
|
|
552
|
+
generateArchaeologySummary(results, patterns, decisions, timeline) {
|
|
553
|
+
let summary = "## Context Archaeology Report\n\n";
|
|
554
|
+
if (results.length > 0) {
|
|
555
|
+
summary += `### Most Relevant Context (${results.length} results)
|
|
556
|
+
`;
|
|
557
|
+
results.slice(0, 3).forEach((r) => {
|
|
558
|
+
summary += `- **${new Date(r.timestamp).toLocaleDateString()}**: ${r.content.slice(0, 100)}...
|
|
559
|
+
`;
|
|
560
|
+
});
|
|
561
|
+
summary += "\n";
|
|
562
|
+
}
|
|
563
|
+
if (patterns.length > 0) {
|
|
564
|
+
summary += `### Detected Patterns
|
|
565
|
+
`;
|
|
566
|
+
patterns.slice(0, 5).forEach((p) => {
|
|
567
|
+
summary += `- ${p.name}: ${p.count} occurrences
|
|
568
|
+
`;
|
|
569
|
+
});
|
|
570
|
+
summary += "\n";
|
|
571
|
+
}
|
|
572
|
+
if (decisions.length > 0) {
|
|
573
|
+
summary += `### Key Decisions
|
|
574
|
+
`;
|
|
575
|
+
decisions.slice(0, 5).forEach((d) => {
|
|
576
|
+
summary += `- **${new Date(d.timestamp).toLocaleDateString()}**: ${d.decision}
|
|
577
|
+
`;
|
|
578
|
+
});
|
|
579
|
+
summary += "\n";
|
|
580
|
+
}
|
|
581
|
+
if (timeline.length > 0) {
|
|
582
|
+
summary += `### Activity Timeline
|
|
583
|
+
`;
|
|
584
|
+
timeline.slice(0, 5).forEach((t) => {
|
|
585
|
+
summary += `- **${t.date}**: ${t.itemCount} activities
|
|
586
|
+
`;
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
return summary;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
class ClaudeSkillsManager {
|
|
593
|
+
constructor(context) {
|
|
594
|
+
this.context = context;
|
|
595
|
+
this.handoffSkill = new HandoffSkill(context);
|
|
596
|
+
this.checkpointSkill = new CheckpointSkill(context);
|
|
597
|
+
this.archaeologistSkill = new ArchaeologistSkill(context);
|
|
598
|
+
}
|
|
599
|
+
handoffSkill;
|
|
600
|
+
checkpointSkill;
|
|
601
|
+
archaeologistSkill;
|
|
602
|
+
async executeSkill(skillName, args, options) {
|
|
603
|
+
switch (skillName) {
|
|
604
|
+
case "handoff":
|
|
605
|
+
return this.handoffSkill.execute(args[0], args[1], options);
|
|
606
|
+
case "checkpoint":
|
|
607
|
+
const subcommand = args[0];
|
|
608
|
+
switch (subcommand) {
|
|
609
|
+
case "create":
|
|
610
|
+
return this.checkpointSkill.create(args[1], options);
|
|
611
|
+
case "restore":
|
|
612
|
+
return this.checkpointSkill.restore(args[1]);
|
|
613
|
+
case "list":
|
|
614
|
+
return this.checkpointSkill.list(options);
|
|
615
|
+
case "diff":
|
|
616
|
+
return this.checkpointSkill.diff(args[1], args[2]);
|
|
617
|
+
default:
|
|
618
|
+
return {
|
|
619
|
+
success: false,
|
|
620
|
+
message: `Unknown checkpoint subcommand: ${subcommand}`
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
case "dig":
|
|
624
|
+
return this.archaeologistSkill.dig(args[0], options);
|
|
625
|
+
default:
|
|
626
|
+
return {
|
|
627
|
+
success: false,
|
|
628
|
+
message: `Unknown skill: ${skillName}`
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
getAvailableSkills() {
|
|
633
|
+
return ["handoff", "checkpoint", "dig"];
|
|
634
|
+
}
|
|
635
|
+
getSkillHelp(skillName) {
|
|
636
|
+
switch (skillName) {
|
|
637
|
+
case "handoff":
|
|
638
|
+
return `
|
|
639
|
+
/handoff @user "message" [--priority high] [--frames frame1,frame2]
|
|
640
|
+
Streamline frame handoffs between team members
|
|
641
|
+
`;
|
|
642
|
+
case "checkpoint":
|
|
643
|
+
return `
|
|
644
|
+
/checkpoint create "description" [--files file1,file2] [--auto-detect-risky]
|
|
645
|
+
/checkpoint restore <id>
|
|
646
|
+
/checkpoint list [--limit 10] [--since "2024-01-01"]
|
|
647
|
+
/checkpoint diff <id1> <id2>
|
|
648
|
+
Create and manage recovery points
|
|
649
|
+
`;
|
|
650
|
+
case "dig":
|
|
651
|
+
return `
|
|
652
|
+
/dig "query" [--depth 6months] [--patterns] [--decisions] [--timeline]
|
|
653
|
+
Deep historical context retrieval across sessions
|
|
654
|
+
`;
|
|
655
|
+
default:
|
|
656
|
+
return `Unknown skill: ${skillName}`;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
export {
|
|
661
|
+
ArchaeologistSkill,
|
|
662
|
+
CheckpointSkill,
|
|
663
|
+
ClaudeSkillsManager,
|
|
664
|
+
HandoffSkill
|
|
665
|
+
};
|
|
666
|
+
//# sourceMappingURL=claude-skills.js.map
|