@stackmemoryai/stackmemory 1.2.1 → 1.2.4

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.
Files changed (100) hide show
  1. package/dist/src/cli/codex-sm.js +6 -8
  2. package/dist/src/cli/commands/config.js +0 -81
  3. package/dist/src/cli/commands/context-rehydrate.js +133 -47
  4. package/dist/src/cli/commands/db.js +35 -8
  5. package/dist/src/cli/commands/handoff.js +1 -1
  6. package/dist/src/cli/commands/linear.js +9 -0
  7. package/dist/src/cli/commands/ralph.js +2 -2
  8. package/dist/src/cli/commands/setup.js +2 -2
  9. package/dist/src/cli/commands/signup.js +3 -1
  10. package/dist/src/cli/commands/skills.js +123 -1
  11. package/dist/src/cli/commands/storage-tier.js +26 -8
  12. package/dist/src/cli/index.js +1 -57
  13. package/dist/src/core/config/feature-flags.js +0 -4
  14. package/dist/src/core/context/dual-stack-manager.js +10 -3
  15. package/dist/src/core/context/frame-database.js +32 -0
  16. package/dist/src/core/context/frame-handoff-manager.js +2 -2
  17. package/dist/src/core/context/{refactored-frame-manager.js → frame-manager.js} +3 -3
  18. package/dist/src/core/context/index.js +2 -2
  19. package/dist/src/core/database/sqlite-adapter.js +161 -1
  20. package/dist/src/core/digest/frame-digest-integration.js +1 -1
  21. package/dist/src/core/digest/index.js +1 -1
  22. package/dist/src/core/execution/parallel-executor.js +5 -1
  23. package/dist/src/core/projects/project-isolation.js +18 -4
  24. package/dist/src/core/security/index.js +2 -0
  25. package/dist/src/core/security/input-sanitizer.js +23 -0
  26. package/dist/src/core/utils/update-checker.js +10 -6
  27. package/dist/src/daemon/daemon-config.js +2 -1
  28. package/dist/src/daemon/services/auto-save-service.js +121 -0
  29. package/dist/src/daemon/services/maintenance-service.js +76 -1
  30. package/dist/src/features/sweep/prompt-builder.js +2 -2
  31. package/dist/src/hooks/graphiti-hooks.js +149 -0
  32. package/dist/src/hooks/session-summary.js +30 -0
  33. package/dist/src/integrations/graphiti/linear-graphiti-bridge.js +115 -0
  34. package/dist/src/integrations/greptile/client.js +101 -0
  35. package/dist/src/integrations/greptile/config.js +14 -0
  36. package/dist/src/integrations/greptile/index.js +11 -0
  37. package/dist/src/integrations/greptile/types.js +4 -0
  38. package/dist/src/integrations/linear/config.js +3 -1
  39. package/dist/src/integrations/linear/sync.js +18 -5
  40. package/dist/src/integrations/linear/webhook.js +16 -0
  41. package/dist/src/integrations/mcp/handlers/code-execution-handlers.js +33 -7
  42. package/dist/src/integrations/mcp/handlers/cord-handlers.js +397 -0
  43. package/dist/src/integrations/mcp/handlers/greptile-handlers.js +456 -0
  44. package/dist/src/integrations/mcp/handlers/index.js +55 -1
  45. package/dist/src/integrations/mcp/handlers/task-handlers.js +55 -12
  46. package/dist/src/integrations/mcp/handlers/team-handlers.js +211 -0
  47. package/dist/src/integrations/mcp/handlers/trace-handlers.js +25 -9
  48. package/dist/src/integrations/mcp/index.js +2 -2
  49. package/dist/src/integrations/mcp/refactored-server.js +31 -10
  50. package/dist/src/integrations/mcp/server.js +27 -0
  51. package/dist/src/integrations/mcp/tool-definitions.js +215 -1
  52. package/dist/src/integrations/ralph/context/context-budget-manager.js +10 -2
  53. package/dist/src/integrations/ralph/context/stackmemory-context-loader.js +54 -22
  54. package/dist/src/integrations/ralph/learning/pattern-learner.js +59 -24
  55. package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js +81 -35
  56. package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js +12 -4
  57. package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js +32 -9
  58. package/dist/src/integrations/ralph/swarm/git-workflow-manager.js +25 -8
  59. package/dist/src/integrations/ralph/swarm/swarm-coordinator.js +17 -5
  60. package/dist/src/integrations/ralph/visualization/ralph-debugger.js +73 -22
  61. package/dist/src/skills/claude-skills.js +46 -103
  62. package/dist/src/skills/parallel-agent-skill.js +514 -0
  63. package/dist/src/utils/hook-installer.js +8 -0
  64. package/package.json +5 -5
  65. package/scripts/gepa/.before-optimize.md +140 -159
  66. package/scripts/gepa/config.json +7 -1
  67. package/scripts/gepa/evals/fixtures/api-endpoint.ts +31 -0
  68. package/scripts/gepa/evals/fixtures/brittle-integration.ts +38 -0
  69. package/scripts/gepa/evals/fixtures/fts5-triggers.sql +23 -0
  70. package/scripts/gepa/evals/fixtures/leaky-service.ts +70 -0
  71. package/scripts/gepa/evals/fixtures/mcp-dispatch-stub.ts +39 -0
  72. package/scripts/gepa/evals/fixtures/pr-diff.txt +24 -0
  73. package/scripts/gepa/evals/fixtures/unsafe-webhook.ts +34 -0
  74. package/scripts/gepa/evals/fixtures/unwrapped-db-op.ts +42 -0
  75. package/scripts/gepa/evals/stackmemory-tasks.jsonl +8 -0
  76. package/scripts/gepa/generations/gen-000/baseline.md +172 -159
  77. package/scripts/gepa/generations/gen-001/baseline.md +172 -159
  78. package/scripts/gepa/generations/gen-001/variant-a.md +156 -146
  79. package/scripts/gepa/generations/gen-001/variant-b.md +199 -170
  80. package/scripts/gepa/generations/gen-001/variant-c.md +127 -46
  81. package/scripts/gepa/generations/gen-001/variant-d.md +160 -107
  82. package/scripts/gepa/hooks/reflect.js +44 -5
  83. package/scripts/gepa/optimize.js +281 -39
  84. package/scripts/gepa/results/eval-1-baseline.json +187 -10
  85. package/scripts/gepa/results/eval-1-variant-a.json +188 -11
  86. package/scripts/gepa/results/eval-1-variant-b.json +188 -11
  87. package/scripts/gepa/results/eval-1-variant-c.json +168 -11
  88. package/scripts/gepa/results/eval-1-variant-d.json +169 -12
  89. package/scripts/gepa/state.json +18 -18
  90. package/scripts/install-claude-hooks-auto.js +8 -0
  91. package/templates/claude-hooks/cord-trace.js +225 -0
  92. package/dist/src/core/config/storage-config.js +0 -114
  93. package/dist/src/core/storage/chromadb-adapter.js +0 -379
  94. package/dist/src/integrations/claude-code/enhanced-pre-clear-hooks.js +0 -458
  95. package/dist/src/integrations/ralph/coordination/enhanced-coordination.js +0 -409
  96. package/dist/src/skills/repo-ingestion-skill.js +0 -631
  97. package/templates/claude-hooks/chromadb-wrapper +0 -21
  98. /package/dist/src/core/context/{enhanced-rehydration.js → rehydration.js} +0 -0
  99. /package/dist/src/core/digest/{enhanced-hybrid-digest.js → hybrid-digest.js} +0 -0
  100. /package/dist/src/core/session/{enhanced-handoff.js → handoff.js} +0 -0
@@ -1,409 +0,0 @@
1
- import { fileURLToPath as __fileURLToPath } from 'url';
2
- import { dirname as __pathDirname } from 'path';
3
- const __filename = __fileURLToPath(import.meta.url);
4
- const __dirname = __pathDirname(__filename);
5
- import { EventEmitter } from "events";
6
- import { logger } from "../../../core/monitoring/logger.js";
7
- class EnhancedCoordinationSystem extends EventEmitter {
8
- agents = /* @__PURE__ */ new Map();
9
- messageQueue = [];
10
- dependencies = /* @__PURE__ */ new Map();
11
- conflicts = /* @__PURE__ */ new Map();
12
- coordinationRules = [];
13
- constructor() {
14
- super();
15
- this.setupDefaultRules();
16
- }
17
- /**
18
- * Register an agent with the coordination system
19
- */
20
- registerAgent(agent) {
21
- this.agents.set(agent.id, agent);
22
- logger.info(`Agent ${agent.role} registered for coordination`);
23
- this.broadcastMessage({
24
- id: this.generateId(),
25
- from: "system",
26
- to: "broadcast",
27
- type: "status_update",
28
- content: { type: "agent_joined", agent: agent.role },
29
- timestamp: Date.now(),
30
- priority: "normal"
31
- });
32
- }
33
- /**
34
- * Send message between agents
35
- */
36
- sendMessage(message) {
37
- const fullMessage = {
38
- ...message,
39
- id: this.generateId(),
40
- timestamp: Date.now()
41
- };
42
- this.messageQueue.push(fullMessage);
43
- this.routeMessage(fullMessage);
44
- this.emit("messageReceived", fullMessage);
45
- }
46
- /**
47
- * Broadcast message to all agents
48
- */
49
- broadcastMessage(message) {
50
- this.sendMessage({
51
- ...message,
52
- to: "broadcast"
53
- });
54
- }
55
- /**
56
- * Request help from other agents
57
- */
58
- requestHelp(fromAgent, helpType, context) {
59
- const suitableAgents = this.findSuitableHelpers(helpType);
60
- this.sendMessage({
61
- from: fromAgent,
62
- to: suitableAgents,
63
- type: "help_request",
64
- content: {
65
- helpType,
66
- context,
67
- requesterCapabilities: this.agents.get(fromAgent)?.capabilities || []
68
- },
69
- priority: "high"
70
- });
71
- }
72
- /**
73
- * Add task dependency
74
- */
75
- addDependency(dependency) {
76
- this.dependencies.set(dependency.taskId, dependency);
77
- this.updateCriticalPath();
78
- logger.info(
79
- `Added dependency: ${dependency.taskId} depends on ${dependency.dependsOn.join(", ")}`
80
- );
81
- }
82
- /**
83
- * Resolve conflicts automatically
84
- */
85
- async resolveConflict(conflictId) {
86
- const conflict = this.conflicts.get(conflictId);
87
- if (!conflict) return false;
88
- try {
89
- switch (conflict.resolutionStrategy) {
90
- case "voting":
91
- conflict.resolution = await this.resolveByVoting(conflict);
92
- break;
93
- case "expertise_based":
94
- conflict.resolution = await this.resolveByExpertise(conflict);
95
- break;
96
- case "random":
97
- conflict.resolution = await this.resolveRandomly(conflict);
98
- break;
99
- case "manager_override":
100
- conflict.resolution = await this.resolveByManagerOverride(conflict);
101
- break;
102
- }
103
- conflict.status = "resolved";
104
- this.conflicts.set(conflictId, conflict);
105
- this.broadcastMessage({
106
- from: "system",
107
- to: conflict.involvedAgents,
108
- type: "status_update",
109
- content: {
110
- type: "conflict_resolved",
111
- conflictId,
112
- resolution: conflict.resolution
113
- },
114
- priority: "high"
115
- });
116
- return true;
117
- } catch (error) {
118
- conflict.status = "escalated";
119
- logger.error(`Failed to resolve conflict ${conflictId}:`, error);
120
- return false;
121
- }
122
- }
123
- /**
124
- * Get optimal task execution order considering dependencies
125
- */
126
- getOptimalExecutionOrder(tasks) {
127
- const graph = this.buildDependencyGraph(tasks);
128
- return this.topologicalSort(graph, tasks);
129
- }
130
- /**
131
- * Detect and report coordination patterns
132
- */
133
- analyzeCoordinationPatterns() {
134
- const patterns = {
135
- communicationFrequency: /* @__PURE__ */ new Map(),
136
- helpRequestPatterns: [],
137
- conflictFrequency: /* @__PURE__ */ new Map(),
138
- bottlenecks: this.identifyBottlenecks()
139
- };
140
- for (const message of this.messageQueue) {
141
- const key = `${message.from}-${message.type}`;
142
- patterns.communicationFrequency.set(
143
- key,
144
- (patterns.communicationFrequency.get(key) || 0) + 1
145
- );
146
- }
147
- for (const conflict of this.conflicts.values()) {
148
- patterns.conflictFrequency.set(
149
- conflict.type,
150
- (patterns.conflictFrequency.get(conflict.type) || 0) + 1
151
- );
152
- }
153
- return patterns;
154
- }
155
- /**
156
- * Load balancing recommendations
157
- */
158
- getLoadBalancingRecommendations() {
159
- const recommendations = {
160
- overloadedAgents: [],
161
- underutilizedAgents: [],
162
- suggestedReassignments: []
163
- };
164
- for (const agent of this.agents.values()) {
165
- const workload = this.calculateAgentWorkload(agent);
166
- if (workload > 0.8) {
167
- recommendations.overloadedAgents.push(agent.id);
168
- } else if (workload < 0.3) {
169
- recommendations.underutilizedAgents.push(agent.id);
170
- }
171
- }
172
- for (const overloaded of recommendations.overloadedAgents) {
173
- for (const underutilized of recommendations.underutilizedAgents) {
174
- const compatibility = this.checkAgentCompatibility(
175
- overloaded,
176
- underutilized
177
- );
178
- if (compatibility.score > 0.7) {
179
- recommendations.suggestedReassignments.push({
180
- fromAgent: overloaded,
181
- toAgent: underutilized,
182
- taskType: compatibility.bestTaskType,
183
- reason: `Load balancing: ${compatibility.reason}`
184
- });
185
- }
186
- }
187
- }
188
- return recommendations;
189
- }
190
- routeMessage(message) {
191
- if (message.to === "broadcast") {
192
- for (const agentId of this.agents.keys()) {
193
- if (agentId !== message.from) {
194
- this.deliverMessage(agentId, message);
195
- }
196
- }
197
- } else {
198
- for (const agentId of message.to) {
199
- this.deliverMessage(agentId, message);
200
- }
201
- }
202
- this.applyCoordinationRules(message);
203
- }
204
- deliverMessage(agentId, message) {
205
- const agent = this.agents.get(agentId);
206
- if (agent) {
207
- logger.debug(`Message delivered to ${agent.role}: ${message.type}`);
208
- }
209
- }
210
- findSuitableHelpers(helpType) {
211
- const helpers = [];
212
- for (const agent of this.agents.values()) {
213
- if (this.canProvideHelp(agent, helpType)) {
214
- helpers.push(agent.id);
215
- }
216
- }
217
- return helpers;
218
- }
219
- canProvideHelp(agent, helpType) {
220
- const capabilities = agent.capabilities || [];
221
- switch (helpType) {
222
- case "code_review":
223
- return capabilities.includes("code_review") || agent.role === "reviewer";
224
- case "debugging":
225
- return capabilities.includes("debugging") || agent.role === "developer";
226
- case "testing":
227
- return capabilities.includes("testing") || agent.role === "tester";
228
- case "optimization":
229
- return capabilities.includes("optimization") || agent.role === "optimizer";
230
- default:
231
- return false;
232
- }
233
- }
234
- async resolveByVoting(conflict) {
235
- const votes = /* @__PURE__ */ new Map();
236
- for (const agentId of conflict.involvedAgents) {
237
- const agent = this.agents.get(agentId);
238
- if (agent) {
239
- votes.set(agentId, Math.random() > 0.5 ? "option_a" : "option_b");
240
- }
241
- }
242
- const results = /* @__PURE__ */ new Map();
243
- for (const vote of votes.values()) {
244
- results.set(vote, (results.get(vote) || 0) + 1);
245
- }
246
- return Array.from(results.entries()).reduce(
247
- (a, b) => a[1] > b[1] ? a : b
248
- )[0];
249
- }
250
- async resolveByExpertise(conflict) {
251
- let bestAgent = null;
252
- let bestExpertise = 0;
253
- for (const agentId of conflict.involvedAgents) {
254
- const agent = this.agents.get(agentId);
255
- if (agent) {
256
- const expertise = this.calculateExpertise(agent, conflict.type);
257
- if (expertise > bestExpertise) {
258
- bestExpertise = expertise;
259
- bestAgent = agent;
260
- }
261
- }
262
- }
263
- return {
264
- resolutionSource: bestAgent?.id,
265
- method: "expertise_based",
266
- expertiseScore: bestExpertise
267
- };
268
- }
269
- async resolveRandomly(conflict) {
270
- const options = ["option_a", "option_b", "compromise"];
271
- return options[Math.floor(Math.random() * options.length)];
272
- }
273
- async resolveByManagerOverride(conflict) {
274
- const manager = Array.from(this.agents.values()).find(
275
- (agent) => agent.role === "coordinator" || agent.role === "architect"
276
- );
277
- return {
278
- resolutionSource: manager?.id || "system",
279
- method: "manager_override"
280
- };
281
- }
282
- calculateExpertise(agent, conflictType) {
283
- const capabilities = agent.capabilities || [];
284
- const performance = agent.performance;
285
- let expertise = 0;
286
- switch (conflictType) {
287
- case "resource":
288
- expertise += capabilities.includes("resource_optimization") ? 0.5 : 0;
289
- break;
290
- case "task_overlap":
291
- expertise += capabilities.includes("coordination") ? 0.5 : 0;
292
- break;
293
- }
294
- if (performance) {
295
- expertise += performance.successRate * 0.3;
296
- expertise += Math.min(performance.tasksCompleted / 10, 0.2);
297
- }
298
- return Math.min(expertise, 1);
299
- }
300
- buildDependencyGraph(tasks) {
301
- const graph = /* @__PURE__ */ new Map();
302
- for (const task of tasks) {
303
- const deps = this.dependencies.get(task.id);
304
- graph.set(task.id, deps?.dependsOn || []);
305
- }
306
- return graph;
307
- }
308
- topologicalSort(graph, tasks) {
309
- const result = [];
310
- const visited = /* @__PURE__ */ new Set();
311
- const visiting = /* @__PURE__ */ new Set();
312
- const visit = (taskId) => {
313
- if (visited.has(taskId)) return;
314
- if (visiting.has(taskId)) {
315
- logger.warn(`Circular dependency detected involving task: ${taskId}`);
316
- return;
317
- }
318
- visiting.add(taskId);
319
- const deps = graph.get(taskId) || [];
320
- for (const dep of deps) {
321
- visit(dep);
322
- }
323
- visiting.delete(taskId);
324
- visited.add(taskId);
325
- const task = tasks.find((t) => t.id === taskId);
326
- if (task) result.push(task);
327
- };
328
- for (const task of tasks) {
329
- visit(task.id);
330
- }
331
- return result;
332
- }
333
- updateCriticalPath() {
334
- logger.debug("Critical path updated");
335
- }
336
- identifyBottlenecks() {
337
- const bottlenecks = [];
338
- for (const [taskId, dep] of this.dependencies) {
339
- if (dep.blockingFor.length > 2) {
340
- bottlenecks.push(taskId);
341
- }
342
- }
343
- return bottlenecks;
344
- }
345
- calculateAgentWorkload(agent) {
346
- let workload = 0;
347
- if (agent.status === "active") workload += 0.5;
348
- if (agent.currentTask) workload += 0.3;
349
- const recentMessages = this.messageQueue.filter(
350
- (m) => (m.from === agent.id || Array.isArray(m.to) && m.to.includes(agent.id)) && Date.now() - m.timestamp < 3e5
351
- // 5 minutes
352
- );
353
- workload += Math.min(recentMessages.length * 0.05, 0.2);
354
- return Math.min(workload, 1);
355
- }
356
- checkAgentCompatibility(agent1Id, agent2Id) {
357
- const agent1 = this.agents.get(agent1Id);
358
- const agent2 = this.agents.get(agent2Id);
359
- if (!agent1 || !agent2) {
360
- return { score: 0, bestTaskType: "", reason: "Agent not found" };
361
- }
362
- const caps1 = new Set(agent1.capabilities || []);
363
- const caps2 = new Set(agent2.capabilities || []);
364
- const overlap = new Set([...caps1].filter((x) => caps2.has(x)));
365
- const score = overlap.size / Math.max(caps1.size, caps2.size, 1);
366
- return {
367
- score,
368
- bestTaskType: Array.from(overlap)[0] || "general",
369
- reason: `Capability overlap: ${overlap.size} common skills`
370
- };
371
- }
372
- applyCoordinationRules(message) {
373
- for (const rule of this.coordinationRules) {
374
- if (rule.condition(message)) {
375
- rule.action(message, this);
376
- }
377
- }
378
- }
379
- setupDefaultRules() {
380
- this.coordinationRules = [
381
- {
382
- id: "help_request_timeout",
383
- condition: (msg) => msg.type === "help_request",
384
- action: (msg, system) => {
385
- setTimeout(() => {
386
- system.broadcastMessage({
387
- from: "system",
388
- to: "broadcast",
389
- type: "status_update",
390
- content: {
391
- type: "help_request_timeout",
392
- originalRequest: msg.id
393
- },
394
- priority: "urgent"
395
- });
396
- }, 3e5);
397
- }
398
- }
399
- ];
400
- }
401
- generateId() {
402
- return `coord_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
403
- }
404
- }
405
- var enhanced_coordination_default = EnhancedCoordinationSystem;
406
- export {
407
- EnhancedCoordinationSystem,
408
- enhanced_coordination_default as default
409
- };