@stackmemoryai/stackmemory 0.1.0 → 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.
Files changed (77) hide show
  1. package/dist/scripts/initialize.js +15 -15
  2. package/dist/scripts/initialize.js.map +1 -1
  3. package/dist/scripts/status.js +21 -11
  4. package/dist/scripts/status.js.map +1 -1
  5. package/dist/src/beads/beads-task-store.d.ts +117 -0
  6. package/dist/src/beads/beads-task-store.d.ts.map +1 -0
  7. package/dist/src/beads/beads-task-store.js +318 -0
  8. package/dist/src/beads/beads-task-store.js.map +1 -0
  9. package/dist/src/beads/task-aware-context.d.ts +103 -0
  10. package/dist/src/beads/task-aware-context.d.ts.map +1 -0
  11. package/dist/src/beads/task-aware-context.js +395 -0
  12. package/dist/src/beads/task-aware-context.js.map +1 -0
  13. package/dist/src/beads-task-store.d.ts +117 -0
  14. package/dist/src/beads-task-store.d.ts.map +1 -0
  15. package/dist/src/beads-task-store.js +318 -0
  16. package/dist/src/beads-task-store.js.map +1 -0
  17. package/dist/src/cli/cli.d.ts +7 -0
  18. package/dist/src/cli/cli.d.ts.map +1 -0
  19. package/dist/src/cli/cli.js +471 -0
  20. package/dist/src/cli/cli.js.map +1 -0
  21. package/dist/src/core/error-handler.d.ts +46 -0
  22. package/dist/src/core/error-handler.d.ts.map +1 -0
  23. package/dist/src/core/error-handler.js +212 -0
  24. package/dist/src/core/error-handler.js.map +1 -0
  25. package/dist/src/core/frame-manager.d.ts +106 -0
  26. package/dist/src/core/frame-manager.d.ts.map +1 -0
  27. package/dist/src/core/frame-manager.js +387 -0
  28. package/dist/src/core/frame-manager.js.map +1 -0
  29. package/dist/src/core/logger.d.ts +24 -0
  30. package/dist/src/core/logger.d.ts.map +1 -0
  31. package/dist/src/core/logger.js +121 -0
  32. package/dist/src/core/logger.js.map +1 -0
  33. package/dist/src/core/logger.test.d.ts +2 -0
  34. package/dist/src/core/logger.test.d.ts.map +1 -0
  35. package/dist/src/core/logger.test.js +31 -0
  36. package/dist/src/core/logger.test.js.map +1 -0
  37. package/dist/src/index.d.ts +4 -4
  38. package/dist/src/index.d.ts.map +1 -1
  39. package/dist/src/index.js +4 -4
  40. package/dist/src/index.js.map +1 -1
  41. package/dist/src/integrations/linear-auth.d.ts +99 -0
  42. package/dist/src/integrations/linear-auth.d.ts.map +1 -0
  43. package/dist/src/integrations/linear-auth.js +319 -0
  44. package/dist/src/integrations/linear-auth.js.map +1 -0
  45. package/dist/src/integrations/linear-auto-sync.d.ts +77 -0
  46. package/dist/src/integrations/linear-auto-sync.d.ts.map +1 -0
  47. package/dist/src/integrations/linear-auto-sync.js +268 -0
  48. package/dist/src/integrations/linear-auto-sync.js.map +1 -0
  49. package/dist/src/integrations/linear-client.d.ts +86 -0
  50. package/dist/src/integrations/linear-client.d.ts.map +1 -0
  51. package/dist/src/integrations/linear-client.js +275 -0
  52. package/dist/src/integrations/linear-client.js.map +1 -0
  53. package/dist/src/integrations/linear-config.d.ts +51 -0
  54. package/dist/src/integrations/linear-config.d.ts.map +1 -0
  55. package/dist/src/integrations/linear-config.js +103 -0
  56. package/dist/src/integrations/linear-config.js.map +1 -0
  57. package/dist/src/integrations/linear-sync.d.ts +95 -0
  58. package/dist/src/integrations/linear-sync.d.ts.map +1 -0
  59. package/dist/src/integrations/linear-sync.js +340 -0
  60. package/dist/src/integrations/linear-sync.js.map +1 -0
  61. package/dist/src/mcp/mcp-server.d.ts +38 -0
  62. package/dist/src/mcp/mcp-server.d.ts.map +1 -0
  63. package/dist/src/mcp/mcp-server.js +812 -0
  64. package/dist/src/mcp/mcp-server.js.map +1 -0
  65. package/dist/src/pebbles/pebbles-task-store.d.ts +117 -0
  66. package/dist/src/pebbles/pebbles-task-store.d.ts.map +1 -0
  67. package/dist/src/pebbles/pebbles-task-store.js +335 -0
  68. package/dist/src/pebbles/pebbles-task-store.js.map +1 -0
  69. package/dist/src/pebbles/task-aware-context.d.ts +103 -0
  70. package/dist/src/pebbles/task-aware-context.d.ts.map +1 -0
  71. package/dist/src/pebbles/task-aware-context.js +412 -0
  72. package/dist/src/pebbles/task-aware-context.js.map +1 -0
  73. package/dist/src/task-aware-context.d.ts +103 -0
  74. package/dist/src/task-aware-context.d.ts.map +1 -0
  75. package/dist/src/task-aware-context.js +395 -0
  76. package/dist/src/task-aware-context.js.map +1 -0
  77. package/package.json +40 -9
@@ -0,0 +1,812 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * StackMemory MCP Server - Local Instance
4
+ * This runs locally and provides context to Claude Code
5
+ */
6
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
7
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
8
+ import { z } from 'zod';
9
+ import Database from 'better-sqlite3';
10
+ import { readFileSync, existsSync, mkdirSync } from 'fs';
11
+ import { join, dirname } from 'path';
12
+ import { execSync } from 'child_process';
13
+ import { FrameManager } from '../core/frame-manager.js';
14
+ import { PebblesTaskStore, } from '../pebbles/pebbles-task-store.js';
15
+ // TODO: Temporarily disabled due to TypeScript errors
16
+ // import { LinearAuthManager, LinearOAuthSetup } from '../integrations/linear-auth.js';
17
+ // import { LinearSyncEngine, DEFAULT_SYNC_CONFIG } from '../integrations/linear-sync.js';
18
+ import { logger } from '../core/logger.js';
19
+ // ============================================
20
+ // Simple Local MCP Server
21
+ // ============================================
22
+ class LocalStackMemoryMCP {
23
+ server;
24
+ db;
25
+ projectRoot;
26
+ frameManager;
27
+ taskStore;
28
+ // TODO: Temporarily disabled
29
+ // private linearAuthManager: LinearAuthManager;
30
+ // private linearSync: LinearSyncEngine;
31
+ projectId;
32
+ contexts = new Map();
33
+ constructor() {
34
+ // Find project root (where .git is)
35
+ this.projectRoot = this.findProjectRoot();
36
+ this.projectId = this.getProjectId();
37
+ // Ensure .stackmemory directory exists
38
+ const dbDir = join(this.projectRoot, '.stackmemory');
39
+ if (!existsSync(dbDir)) {
40
+ mkdirSync(dbDir, { recursive: true });
41
+ }
42
+ // Initialize database
43
+ const dbPath = join(dbDir, 'context.db');
44
+ this.db = new Database(dbPath);
45
+ this.initDB();
46
+ // Initialize frame manager
47
+ this.frameManager = new FrameManager(this.db, this.projectId);
48
+ // Initialize task store
49
+ this.taskStore = new PebblesTaskStore(this.projectRoot, this.db);
50
+ // TODO: Initialize Linear integration (temporarily disabled)
51
+ // this.linearAuthManager = new LinearAuthManager(this.projectRoot);
52
+ // this.linearSync = new LinearSyncEngine(
53
+ // this.taskStore,
54
+ // this.linearAuthManager,
55
+ // DEFAULT_SYNC_CONFIG
56
+ // );
57
+ // Initialize MCP server
58
+ this.server = new Server({
59
+ name: 'stackmemory-local',
60
+ version: '0.1.0',
61
+ }, {
62
+ capabilities: {
63
+ tools: {},
64
+ },
65
+ });
66
+ this.setupHandlers();
67
+ this.loadInitialContext();
68
+ logger.info('StackMemory MCP Server initialized', {
69
+ projectRoot: this.projectRoot,
70
+ projectId: this.projectId,
71
+ });
72
+ }
73
+ findProjectRoot() {
74
+ let dir = process.cwd();
75
+ while (dir !== '/') {
76
+ if (existsSync(join(dir, '.git'))) {
77
+ return dir;
78
+ }
79
+ dir = dirname(dir);
80
+ }
81
+ return process.cwd();
82
+ }
83
+ initDB() {
84
+ this.db.exec(`
85
+ CREATE TABLE IF NOT EXISTS contexts (
86
+ id TEXT PRIMARY KEY,
87
+ type TEXT NOT NULL,
88
+ content TEXT NOT NULL,
89
+ importance REAL DEFAULT 0.5,
90
+ created_at INTEGER DEFAULT (unixepoch()),
91
+ last_accessed INTEGER DEFAULT (unixepoch()),
92
+ access_count INTEGER DEFAULT 1
93
+ );
94
+
95
+ CREATE TABLE IF NOT EXISTS frames (
96
+ frame_id TEXT PRIMARY KEY,
97
+ task TEXT NOT NULL,
98
+ status TEXT DEFAULT 'active',
99
+ created_at INTEGER DEFAULT (unixepoch())
100
+ );
101
+
102
+ CREATE TABLE IF NOT EXISTS attention_log (
103
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
104
+ context_id TEXT,
105
+ query TEXT,
106
+ response TEXT,
107
+ influence_score REAL,
108
+ timestamp INTEGER DEFAULT (unixepoch())
109
+ );
110
+ `);
111
+ }
112
+ loadInitialContext() {
113
+ // Load project information
114
+ const projectInfo = this.getProjectInfo();
115
+ this.addContext('project', `Project: ${projectInfo.name}\nPath: ${projectInfo.path}`, 0.9);
116
+ // Load recent git commits
117
+ try {
118
+ const recentCommits = execSync('git log --oneline -10', {
119
+ cwd: this.projectRoot,
120
+ }).toString();
121
+ this.addContext('git_history', `Recent commits:\n${recentCommits}`, 0.6);
122
+ }
123
+ catch {
124
+ // Not a git repo or git not available
125
+ }
126
+ // Load README if exists
127
+ const readmePath = join(this.projectRoot, 'README.md');
128
+ if (existsSync(readmePath)) {
129
+ const readme = readFileSync(readmePath, 'utf-8');
130
+ const summary = readme.substring(0, 500);
131
+ this.addContext('readme', `Project README:\n${summary}...`, 0.8);
132
+ }
133
+ // Load any existing decisions from previous sessions
134
+ this.loadStoredContexts();
135
+ }
136
+ getProjectId() {
137
+ // Use git remote or directory name as project ID
138
+ try {
139
+ const remoteUrl = execSync('git config --get remote.origin.url', {
140
+ cwd: this.projectRoot,
141
+ stdio: 'pipe',
142
+ })
143
+ .toString()
144
+ .trim();
145
+ return remoteUrl || this.projectRoot.split('/').pop() || 'unknown';
146
+ }
147
+ catch {
148
+ return this.projectRoot.split('/').pop() || 'unknown';
149
+ }
150
+ }
151
+ getProjectInfo() {
152
+ const packageJsonPath = join(this.projectRoot, 'package.json');
153
+ if (existsSync(packageJsonPath)) {
154
+ const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
155
+ return {
156
+ name: pkg.name || 'unknown',
157
+ path: this.projectRoot,
158
+ };
159
+ }
160
+ return {
161
+ name: this.projectRoot.split('/').pop() || 'unknown',
162
+ path: this.projectRoot,
163
+ };
164
+ }
165
+ addContext(type, content, importance = 0.5) {
166
+ const id = `${type}_${Date.now()}`;
167
+ this.db
168
+ .prepare(`
169
+ INSERT OR REPLACE INTO contexts (id, type, content, importance)
170
+ VALUES (?, ?, ?, ?)
171
+ `)
172
+ .run(id, type, content, importance);
173
+ this.contexts.set(id, { type, content, importance });
174
+ return id;
175
+ }
176
+ loadStoredContexts() {
177
+ const stored = this.db
178
+ .prepare(`
179
+ SELECT * FROM contexts
180
+ ORDER BY importance DESC, last_accessed DESC
181
+ LIMIT 50
182
+ `)
183
+ .all();
184
+ stored.forEach((ctx) => {
185
+ this.contexts.set(ctx.id, ctx);
186
+ });
187
+ }
188
+ setupHandlers() {
189
+ // Tool listing
190
+ this.server.setRequestHandler(z.object({
191
+ method: z.literal('tools/list'),
192
+ }), async () => {
193
+ return {
194
+ tools: [
195
+ {
196
+ name: 'get_context',
197
+ description: 'Get current project context',
198
+ inputSchema: {
199
+ type: 'object',
200
+ properties: {
201
+ query: {
202
+ type: 'string',
203
+ description: 'What you want to know',
204
+ },
205
+ limit: {
206
+ type: 'number',
207
+ description: 'Max contexts to return',
208
+ },
209
+ },
210
+ },
211
+ },
212
+ {
213
+ name: 'add_decision',
214
+ description: 'Record a decision or important information',
215
+ inputSchema: {
216
+ type: 'object',
217
+ properties: {
218
+ content: {
219
+ type: 'string',
220
+ description: 'The decision or information',
221
+ },
222
+ type: {
223
+ type: 'string',
224
+ enum: ['decision', 'constraint', 'learning'],
225
+ },
226
+ },
227
+ required: ['content', 'type'],
228
+ },
229
+ },
230
+ {
231
+ name: 'start_frame',
232
+ description: 'Start a new frame (task/subtask) on the call stack',
233
+ inputSchema: {
234
+ type: 'object',
235
+ properties: {
236
+ name: { type: 'string', description: 'Frame name/goal' },
237
+ type: {
238
+ type: 'string',
239
+ enum: [
240
+ 'task',
241
+ 'subtask',
242
+ 'tool_scope',
243
+ 'review',
244
+ 'write',
245
+ 'debug',
246
+ ],
247
+ description: 'Frame type',
248
+ },
249
+ constraints: {
250
+ type: 'array',
251
+ items: { type: 'string' },
252
+ description: 'Constraints for this frame',
253
+ },
254
+ },
255
+ required: ['name', 'type'],
256
+ },
257
+ },
258
+ {
259
+ name: 'close_frame',
260
+ description: 'Close current frame and generate digest',
261
+ inputSchema: {
262
+ type: 'object',
263
+ properties: {
264
+ result: {
265
+ type: 'string',
266
+ description: 'Frame completion result',
267
+ },
268
+ outputs: {
269
+ type: 'object',
270
+ description: 'Final outputs from frame',
271
+ },
272
+ },
273
+ },
274
+ },
275
+ {
276
+ name: 'add_anchor',
277
+ description: 'Add anchored fact/decision/constraint to current frame',
278
+ inputSchema: {
279
+ type: 'object',
280
+ properties: {
281
+ type: {
282
+ type: 'string',
283
+ enum: [
284
+ 'FACT',
285
+ 'DECISION',
286
+ 'CONSTRAINT',
287
+ 'INTERFACE_CONTRACT',
288
+ 'TODO',
289
+ 'RISK',
290
+ ],
291
+ description: 'Anchor type',
292
+ },
293
+ text: { type: 'string', description: 'Anchor content' },
294
+ priority: {
295
+ type: 'number',
296
+ description: 'Priority (0-10)',
297
+ minimum: 0,
298
+ maximum: 10,
299
+ },
300
+ },
301
+ required: ['type', 'text'],
302
+ },
303
+ },
304
+ {
305
+ name: 'get_hot_stack',
306
+ description: 'Get current active frames and context',
307
+ inputSchema: {
308
+ type: 'object',
309
+ properties: {
310
+ maxEvents: {
311
+ type: 'number',
312
+ description: 'Max recent events per frame',
313
+ default: 20,
314
+ },
315
+ },
316
+ },
317
+ },
318
+ {
319
+ name: 'create_task',
320
+ description: 'Create a new task in git-tracked JSONL storage',
321
+ inputSchema: {
322
+ type: 'object',
323
+ properties: {
324
+ title: { type: 'string', description: 'Task title' },
325
+ description: {
326
+ type: 'string',
327
+ description: 'Task description',
328
+ },
329
+ priority: {
330
+ type: 'string',
331
+ enum: ['low', 'medium', 'high', 'urgent'],
332
+ description: 'Task priority',
333
+ },
334
+ estimatedEffort: {
335
+ type: 'number',
336
+ description: 'Estimated effort in minutes',
337
+ },
338
+ dependsOn: {
339
+ type: 'array',
340
+ items: { type: 'string' },
341
+ description: 'Task IDs this depends on',
342
+ },
343
+ tags: {
344
+ type: 'array',
345
+ items: { type: 'string' },
346
+ description: 'Tags for categorization',
347
+ },
348
+ },
349
+ required: ['title'],
350
+ },
351
+ },
352
+ {
353
+ name: 'update_task_status',
354
+ description: 'Update task status with automatic time tracking',
355
+ inputSchema: {
356
+ type: 'object',
357
+ properties: {
358
+ taskId: { type: 'string', description: 'Task ID to update' },
359
+ status: {
360
+ type: 'string',
361
+ enum: [
362
+ 'pending',
363
+ 'in_progress',
364
+ 'completed',
365
+ 'blocked',
366
+ 'cancelled',
367
+ ],
368
+ description: 'New status',
369
+ },
370
+ reason: {
371
+ type: 'string',
372
+ description: 'Reason for status change (especially for blocked)',
373
+ },
374
+ },
375
+ required: ['taskId', 'status'],
376
+ },
377
+ },
378
+ {
379
+ name: 'get_active_tasks',
380
+ description: 'Get currently active tasks',
381
+ inputSchema: {
382
+ type: 'object',
383
+ properties: {
384
+ frameId: {
385
+ type: 'string',
386
+ description: 'Filter by specific frame ID',
387
+ },
388
+ },
389
+ },
390
+ },
391
+ {
392
+ name: 'get_task_metrics',
393
+ description: 'Get project task metrics and analytics',
394
+ inputSchema: {
395
+ type: 'object',
396
+ properties: {},
397
+ },
398
+ },
399
+ {
400
+ name: 'add_task_dependency',
401
+ description: 'Add dependency relationship between tasks',
402
+ inputSchema: {
403
+ type: 'object',
404
+ properties: {
405
+ taskId: {
406
+ type: 'string',
407
+ description: 'Task that depends on another',
408
+ },
409
+ dependsOnId: {
410
+ type: 'string',
411
+ description: 'Task ID that this depends on',
412
+ },
413
+ },
414
+ required: ['taskId', 'dependsOnId'],
415
+ },
416
+ },
417
+ ],
418
+ };
419
+ });
420
+ // Tool execution
421
+ this.server.setRequestHandler(z.object({
422
+ method: z.literal('tools/call'),
423
+ params: z.object({
424
+ name: z.string(),
425
+ arguments: z.record(z.unknown()),
426
+ }),
427
+ }), async (request) => {
428
+ const { name, arguments: args } = request.params;
429
+ switch (name) {
430
+ case 'get_context':
431
+ return this.handleGetContext(args);
432
+ case 'add_decision':
433
+ return this.handleAddDecision(args);
434
+ case 'start_frame':
435
+ return this.handleStartFrame(args);
436
+ case 'close_frame':
437
+ return this.handleCloseFrame(args);
438
+ case 'add_anchor':
439
+ return this.handleAddAnchor(args);
440
+ case 'get_hot_stack':
441
+ return this.handleGetHotStack(args);
442
+ case 'create_task':
443
+ return this.handleCreateTask(args);
444
+ case 'update_task_status':
445
+ return this.handleUpdateTaskStatus(args);
446
+ case 'get_active_tasks':
447
+ return this.handleGetActiveTasks(args);
448
+ case 'get_task_metrics':
449
+ return this.handleGetTaskMetrics(args);
450
+ case 'add_task_dependency':
451
+ return this.handleAddTaskDependency(args);
452
+ default:
453
+ throw new Error(`Unknown tool: ${name}`);
454
+ }
455
+ });
456
+ }
457
+ async handleGetContext(args) {
458
+ const { query = '', limit = 10 } = args;
459
+ // Get relevant contexts
460
+ const contexts = Array.from(this.contexts.values())
461
+ .sort((a, b) => b.importance - a.importance)
462
+ .slice(0, limit);
463
+ // Update access counts
464
+ contexts.forEach((ctx) => {
465
+ this.db
466
+ .prepare(`
467
+ UPDATE contexts
468
+ SET last_accessed = unixepoch(),
469
+ access_count = access_count + 1
470
+ WHERE id = ?
471
+ `)
472
+ .run(ctx.id);
473
+ });
474
+ // Format response
475
+ const response = contexts
476
+ .map((ctx) => `[${ctx.type.toUpperCase()}] (importance: ${ctx.importance.toFixed(2)})\n${ctx.content}`)
477
+ .join('\n\n---\n\n');
478
+ // Log for attention tracking
479
+ this.logAttention(query, response);
480
+ return {
481
+ content: [
482
+ {
483
+ type: 'text',
484
+ text: response ||
485
+ 'No context available yet. Start adding decisions and information!',
486
+ },
487
+ ],
488
+ };
489
+ }
490
+ async handleAddDecision(args) {
491
+ const { content, type = 'decision' } = args;
492
+ const id = this.addContext(type, content, 0.8);
493
+ return {
494
+ content: [
495
+ {
496
+ type: 'text',
497
+ text: `✓ Added ${type}: ${content}\nID: ${id}`,
498
+ },
499
+ ],
500
+ };
501
+ }
502
+ async handleStartFrame(args) {
503
+ const { name, type, constraints } = args;
504
+ const inputs = {};
505
+ if (constraints) {
506
+ inputs.constraints = constraints;
507
+ }
508
+ const frameId = this.frameManager.createFrame({
509
+ type: type,
510
+ name,
511
+ inputs,
512
+ });
513
+ // Log event
514
+ this.frameManager.addEvent('user_message', {
515
+ action: 'start_frame',
516
+ name,
517
+ type,
518
+ constraints,
519
+ });
520
+ // Add as context
521
+ this.addContext('active_frame', `Active frame: ${name} (${type})`, 0.9);
522
+ const stackDepth = this.frameManager.getStackDepth();
523
+ return {
524
+ content: [
525
+ {
526
+ type: 'text',
527
+ text: `🚀 Started ${type}: ${name}\nFrame ID: ${frameId}\nStack depth: ${stackDepth}`,
528
+ },
529
+ ],
530
+ };
531
+ }
532
+ async handleCloseFrame(args) {
533
+ const { result, outputs } = args;
534
+ const currentFrameId = this.frameManager.getCurrentFrameId();
535
+ if (!currentFrameId) {
536
+ return {
537
+ content: [
538
+ {
539
+ type: 'text',
540
+ text: '⚠️ No active frame to close',
541
+ },
542
+ ],
543
+ };
544
+ }
545
+ // Log completion event
546
+ this.frameManager.addEvent('assistant_message', {
547
+ action: 'close_frame',
548
+ result,
549
+ outputs,
550
+ });
551
+ this.frameManager.closeFrame(currentFrameId, outputs);
552
+ const newStackDepth = this.frameManager.getStackDepth();
553
+ return {
554
+ content: [
555
+ {
556
+ type: 'text',
557
+ text: `✅ Closed frame: ${result || 'completed'}\nStack depth: ${newStackDepth}`,
558
+ },
559
+ ],
560
+ };
561
+ }
562
+ async handleAddAnchor(args) {
563
+ const { type, text, priority = 5 } = args;
564
+ const anchorId = this.frameManager.addAnchor(type, text, priority);
565
+ // Log anchor creation
566
+ this.frameManager.addEvent('decision', {
567
+ anchor_type: type,
568
+ text,
569
+ priority,
570
+ anchor_id: anchorId,
571
+ });
572
+ return {
573
+ content: [
574
+ {
575
+ type: 'text',
576
+ text: `📌 Added ${type}: ${text}\nAnchor ID: ${anchorId}`,
577
+ },
578
+ ],
579
+ };
580
+ }
581
+ async handleGetHotStack(args) {
582
+ const { maxEvents = 20 } = args;
583
+ const hotStack = this.frameManager.getHotStackContext(maxEvents);
584
+ const activePath = this.frameManager.getActiveFramePath();
585
+ if (hotStack.length === 0) {
586
+ return {
587
+ content: [
588
+ {
589
+ type: 'text',
590
+ text: '📚 No active frames. Start a frame with start_frame tool.',
591
+ },
592
+ ],
593
+ };
594
+ }
595
+ let response = '📚 **Active Call Stack:**\n\n';
596
+ activePath.forEach((frame, index) => {
597
+ const indent = ' '.repeat(index);
598
+ const context = hotStack[index];
599
+ response += `${indent}${index + 1}. **${frame.name}** (${frame.type})\n`;
600
+ if (context && context.anchors && context.anchors.length > 0) {
601
+ response += `${indent} 📌 ${context.anchors.length} anchors\n`;
602
+ }
603
+ if (context && context.recentEvents && context.recentEvents.length > 0) {
604
+ response += `${indent} 📝 ${context.recentEvents.length} recent events\n`;
605
+ }
606
+ response += '\n';
607
+ });
608
+ response += `**Total stack depth:** ${hotStack.length}`;
609
+ // Log stack access
610
+ this.frameManager.addEvent('observation', {
611
+ action: 'get_hot_stack',
612
+ stack_depth: hotStack.length,
613
+ total_anchors: hotStack.reduce((sum, frame) => sum + frame.anchors.length, 0),
614
+ total_events: hotStack.reduce((sum, frame) => sum + frame.recentEvents.length, 0),
615
+ });
616
+ return {
617
+ content: [
618
+ {
619
+ type: 'text',
620
+ text: response,
621
+ },
622
+ ],
623
+ };
624
+ }
625
+ logAttention(query, response) {
626
+ // Simple attention logging for analysis
627
+ this.db
628
+ .prepare(`
629
+ INSERT INTO attention_log (query, response)
630
+ VALUES (?, ?)
631
+ `)
632
+ .run(query, response);
633
+ }
634
+ async handleCreateTask(args) {
635
+ const { title, description, priority, estimatedEffort, dependsOn, tags } = args;
636
+ const currentFrameId = this.frameManager.getCurrentFrameId();
637
+ if (!currentFrameId) {
638
+ return {
639
+ content: [
640
+ {
641
+ type: 'text',
642
+ text: '⚠️ No active frame. Start a frame first with start_frame tool.',
643
+ },
644
+ ],
645
+ };
646
+ }
647
+ const taskId = this.taskStore.createTask({
648
+ title,
649
+ description,
650
+ priority: priority,
651
+ frameId: currentFrameId,
652
+ dependsOn,
653
+ tags,
654
+ estimatedEffort,
655
+ });
656
+ // Log task creation event
657
+ this.frameManager.addEvent('decision', {
658
+ action: 'create_task',
659
+ task_id: taskId,
660
+ title,
661
+ priority: priority || 'medium',
662
+ });
663
+ return {
664
+ content: [
665
+ {
666
+ type: 'text',
667
+ text: `✅ Created task: ${title}\nID: ${taskId}\nFrame: ${currentFrameId}\nStored in: .stackmemory/tasks.jsonl`,
668
+ },
669
+ ],
670
+ };
671
+ }
672
+ async handleUpdateTaskStatus(args) {
673
+ const { taskId, status, reason } = args;
674
+ try {
675
+ this.taskStore.updateTaskStatus(taskId, status, reason);
676
+ // Log status change event
677
+ this.frameManager.addEvent('observation', {
678
+ action: 'update_task_status',
679
+ task_id: taskId,
680
+ new_status: status,
681
+ reason,
682
+ });
683
+ return {
684
+ content: [
685
+ {
686
+ type: 'text',
687
+ text: `✅ Updated task ${taskId} to ${status}${reason ? `\nReason: ${reason}` : ''}`,
688
+ },
689
+ ],
690
+ };
691
+ }
692
+ catch (error) {
693
+ return {
694
+ content: [
695
+ {
696
+ type: 'text',
697
+ text: `❌ Failed to update task: ${error}`,
698
+ },
699
+ ],
700
+ };
701
+ }
702
+ }
703
+ async handleGetActiveTasks(args) {
704
+ const { frameId } = args;
705
+ const activeTasks = this.taskStore.getActiveTasks(frameId);
706
+ if (activeTasks.length === 0) {
707
+ return {
708
+ content: [
709
+ {
710
+ type: 'text',
711
+ text: frameId
712
+ ? `📝 No active tasks in frame ${frameId}`
713
+ : '📝 No active tasks in project',
714
+ },
715
+ ],
716
+ };
717
+ }
718
+ let response = '📝 **Active Tasks**\n\n';
719
+ activeTasks.forEach((task) => {
720
+ const priority = task.priority.toUpperCase();
721
+ const status = task.status.replace('_', ' ').toUpperCase();
722
+ const effort = task.estimated_effort
723
+ ? ` (${task.estimated_effort}m)`
724
+ : '';
725
+ response += `- **[${status}]** ${task.title}${effort}\n`;
726
+ response += ` Priority: ${priority} | ID: ${task.id}\n`;
727
+ if (task.depends_on.length > 0) {
728
+ response += ` Depends on: ${task.depends_on.join(', ')}\n`;
729
+ }
730
+ response += '\n';
731
+ });
732
+ return {
733
+ content: [
734
+ {
735
+ type: 'text',
736
+ text: response,
737
+ },
738
+ ],
739
+ };
740
+ }
741
+ async handleGetTaskMetrics(_args) {
742
+ const metrics = this.taskStore.getMetrics();
743
+ let response = '📊 **Task Metrics**\n\n';
744
+ response += `**Total Tasks:** ${metrics.total_tasks}\n`;
745
+ response += `**Completion Rate:** ${(metrics.completion_rate * 100).toFixed(1)}%\n\n`;
746
+ response += '**By Status:**\n';
747
+ Object.entries(metrics.by_status).forEach(([status, count]) => {
748
+ response += `- ${status}: ${count}\n`;
749
+ });
750
+ response += '\n**By Priority:**\n';
751
+ Object.entries(metrics.by_priority).forEach(([priority, count]) => {
752
+ response += `- ${priority}: ${count}\n`;
753
+ });
754
+ if (metrics.blocked_tasks > 0) {
755
+ response += `\n⚠️ **${metrics.blocked_tasks} blocked tasks**`;
756
+ }
757
+ if (metrics.avg_effort_accuracy > 0) {
758
+ response += `\n🎯 **Effort Accuracy:** ${(metrics.avg_effort_accuracy * 100).toFixed(1)}%`;
759
+ }
760
+ return {
761
+ content: [
762
+ {
763
+ type: 'text',
764
+ text: response,
765
+ },
766
+ ],
767
+ };
768
+ }
769
+ async handleAddTaskDependency(args) {
770
+ const { taskId, dependsOnId } = args;
771
+ try {
772
+ this.taskStore.addDependency(taskId, dependsOnId);
773
+ // Log dependency creation
774
+ this.frameManager.addEvent('decision', {
775
+ action: 'add_task_dependency',
776
+ task_id: taskId,
777
+ depends_on_id: dependsOnId,
778
+ });
779
+ return {
780
+ content: [
781
+ {
782
+ type: 'text',
783
+ text: `🔗 Added dependency: ${taskId} depends on ${dependsOnId}`,
784
+ },
785
+ ],
786
+ };
787
+ }
788
+ catch (error) {
789
+ return {
790
+ content: [
791
+ {
792
+ type: 'text',
793
+ text: `❌ Failed to add dependency: ${error}`,
794
+ },
795
+ ],
796
+ };
797
+ }
798
+ }
799
+ async start() {
800
+ const transport = new StdioServerTransport();
801
+ await this.server.connect(transport);
802
+ console.error('StackMemory MCP Server started');
803
+ }
804
+ }
805
+ // Export the class
806
+ export default LocalStackMemoryMCP;
807
+ // Start the server
808
+ if (import.meta.url === `file://${process.argv[1]}`) {
809
+ const server = new LocalStackMemoryMCP();
810
+ server.start().catch(console.error);
811
+ }
812
+ //# sourceMappingURL=mcp-server.js.map