@stackmemoryai/stackmemory 0.1.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 (50) hide show
  1. package/README.md +317 -0
  2. package/dist/attention-scoring/src/attention-tracker.d.ts +79 -0
  3. package/dist/attention-scoring/src/attention-tracker.d.ts.map +1 -0
  4. package/dist/attention-scoring/src/attention-tracker.js +488 -0
  5. package/dist/attention-scoring/src/attention-tracker.js.map +1 -0
  6. package/dist/attention-scoring/src/mcp-integration.d.ts +56 -0
  7. package/dist/attention-scoring/src/mcp-integration.d.ts.map +1 -0
  8. package/dist/attention-scoring/src/mcp-integration.js +369 -0
  9. package/dist/attention-scoring/src/mcp-integration.js.map +1 -0
  10. package/dist/p2p-sync/src/p2p-sync.d.ts +81 -0
  11. package/dist/p2p-sync/src/p2p-sync.d.ts.map +1 -0
  12. package/dist/p2p-sync/src/p2p-sync.js +457 -0
  13. package/dist/p2p-sync/src/p2p-sync.js.map +1 -0
  14. package/dist/p2p-sync/src/team-context-sync.d.ts +99 -0
  15. package/dist/p2p-sync/src/team-context-sync.d.ts.map +1 -0
  16. package/dist/p2p-sync/src/team-context-sync.js +491 -0
  17. package/dist/p2p-sync/src/team-context-sync.js.map +1 -0
  18. package/dist/scripts/initialize.d.ts +6 -0
  19. package/dist/scripts/initialize.d.ts.map +1 -0
  20. package/dist/scripts/initialize.js +93 -0
  21. package/dist/scripts/initialize.js.map +1 -0
  22. package/dist/scripts/status.d.ts +6 -0
  23. package/dist/scripts/status.d.ts.map +1 -0
  24. package/dist/scripts/status.js +87 -0
  25. package/dist/scripts/status.js.map +1 -0
  26. package/dist/src/cli.d.ts +7 -0
  27. package/dist/src/cli.d.ts.map +1 -0
  28. package/dist/src/cli.js +73 -0
  29. package/dist/src/cli.js.map +1 -0
  30. package/dist/src/error-handler.d.ts +42 -0
  31. package/dist/src/error-handler.d.ts.map +1 -0
  32. package/dist/src/error-handler.js +155 -0
  33. package/dist/src/error-handler.js.map +1 -0
  34. package/dist/src/frame-manager.d.ts +106 -0
  35. package/dist/src/frame-manager.d.ts.map +1 -0
  36. package/dist/src/frame-manager.js +361 -0
  37. package/dist/src/frame-manager.js.map +1 -0
  38. package/dist/src/index.d.ts +21 -0
  39. package/dist/src/index.d.ts.map +1 -0
  40. package/dist/src/index.js +9 -0
  41. package/dist/src/index.js.map +1 -0
  42. package/dist/src/logger.d.ts +24 -0
  43. package/dist/src/logger.d.ts.map +1 -0
  44. package/dist/src/logger.js +120 -0
  45. package/dist/src/logger.js.map +1 -0
  46. package/dist/src/mcp-server.d.ts +32 -0
  47. package/dist/src/mcp-server.d.ts.map +1 -0
  48. package/dist/src/mcp-server.js +441 -0
  49. package/dist/src/mcp-server.js.map +1 -0
  50. package/package.json +69 -0
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env tsx
2
+ /**
3
+ * Check StackMemory status and statistics
4
+ */
5
+ import Database from 'better-sqlite3';
6
+ import { existsSync } from 'fs';
7
+ import { join } from 'path';
8
+ import chalk from 'chalk';
9
+ const projectRoot = process.cwd();
10
+ const dbPath = join(projectRoot, '.stackmemory', 'context.db');
11
+ if (!existsSync(dbPath)) {
12
+ console.log(chalk.red('āŒ StackMemory not initialized in this project'));
13
+ console.log(chalk.gray('Run: npm run init'));
14
+ process.exit(1);
15
+ }
16
+ const db = new Database(dbPath, { readonly: true });
17
+ console.log(chalk.blue.bold('\nšŸ“Š StackMemory Status\n'));
18
+ // Get statistics
19
+ const stats = {
20
+ contexts: db.prepare('SELECT COUNT(*) as count FROM contexts').get(),
21
+ frames: db.prepare('SELECT COUNT(*) as count FROM frames').get(),
22
+ attention: db.prepare('SELECT COUNT(*) as count FROM attention_log').get(),
23
+ };
24
+ console.log(chalk.green('Database:') + ` ${dbPath}`);
25
+ console.log(chalk.green('Contexts:') + ` ${stats.contexts.count}`);
26
+ console.log(chalk.green('Frames:') + ` ${stats.frames.count}`);
27
+ console.log(chalk.green('Attention logs:') + ` ${stats.attention.count}`);
28
+ // Get top contexts by importance
29
+ console.log(chalk.blue('\nšŸŽÆ Top Contexts by Importance:\n'));
30
+ const topContexts = db.prepare(`
31
+ SELECT type, substr(content, 1, 60) as preview, importance, access_count
32
+ FROM contexts
33
+ ORDER BY importance DESC, access_count DESC
34
+ LIMIT 5
35
+ `).all();
36
+ topContexts.forEach((ctx, i) => {
37
+ const importance = 'ā—'.repeat(Math.round(ctx.importance * 5));
38
+ console.log(chalk.cyan(`${i + 1}.`) +
39
+ ` [${ctx.type}] ` +
40
+ chalk.gray(`(${ctx.access_count} uses)`) +
41
+ ` ${importance}`);
42
+ console.log(chalk.gray(` ${ctx.preview}...`));
43
+ });
44
+ // Get active frames
45
+ const activeFrames = db.prepare(`
46
+ SELECT task, datetime(created_at, 'unixepoch') as started
47
+ FROM frames
48
+ WHERE status = 'active'
49
+ ORDER BY created_at DESC
50
+ LIMIT 3
51
+ `).all();
52
+ if (activeFrames.length > 0) {
53
+ console.log(chalk.blue('\nšŸ”„ Active Tasks:\n'));
54
+ activeFrames.forEach(frame => {
55
+ console.log(chalk.green('•') + ` ${frame.task}`);
56
+ console.log(chalk.gray(` Started: ${frame.started}`));
57
+ });
58
+ }
59
+ // Get recent attention patterns
60
+ const recentAttention = db.prepare(`
61
+ SELECT
62
+ substr(query, 1, 50) as query_preview,
63
+ COUNT(*) as count
64
+ FROM attention_log
65
+ WHERE timestamp > unixepoch() - 86400
66
+ GROUP BY query_preview
67
+ ORDER BY count DESC
68
+ LIMIT 3
69
+ `).all();
70
+ if (recentAttention.length > 0) {
71
+ console.log(chalk.blue('\nšŸ‘ļø Recent Query Patterns:\n'));
72
+ recentAttention.forEach(pattern => {
73
+ console.log(chalk.yellow('?') + ` "${pattern.query_preview}..." (${pattern.count}x)`);
74
+ });
75
+ }
76
+ // Show context decay
77
+ const oldContexts = db.prepare(`
78
+ SELECT COUNT(*) as count
79
+ FROM contexts
80
+ WHERE last_accessed < unixepoch() - 86400 * 7
81
+ `).get();
82
+ if (oldContexts.count > 0) {
83
+ console.log(chalk.yellow(`\nāš ļø ${oldContexts.count} contexts haven't been accessed in 7+ days`));
84
+ }
85
+ console.log(chalk.gray('\nšŸ’” Tip: Run "npm run analyze" for detailed attention analysis\n'));
86
+ db.close();
87
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../scripts/status.ts"],"names":[],"mappings":";AACA;;GAEG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;AAClC,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;AAE/D,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC,CAAC;IACxE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC;IAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;AAEpD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,CAAC;AAE1D,iBAAiB;AACjB,MAAM,KAAK,GAAG;IACZ,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,wCAAwC,CAAC,CAAC,GAAG,EAAS;IAC3E,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,sCAAsC,CAAC,CAAC,GAAG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EAAE,CAAC;IAC1B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,WAAW,CAAC,KAAK,4CAA4C,CAAC,CAAC,CAAC;AACpG,CAAC;AAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAC,CAAC;AAE7F,EAAE,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * StackMemory CLI
4
+ * Command-line interface for StackMemory operations
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AACA;;;GAGG"}
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * StackMemory CLI
4
+ * Command-line interface for StackMemory operations
5
+ */
6
+ import { program } from 'commander';
7
+ import { logger } from './logger.js';
8
+ import { FrameManager } from './frame-manager.js';
9
+ import Database from 'better-sqlite3';
10
+ import { join } from 'path';
11
+ import { existsSync, mkdirSync } from 'fs';
12
+ program
13
+ .name('stackmemory')
14
+ .description('Lossless memory runtime for AI coding tools')
15
+ .version('0.1.0');
16
+ program
17
+ .command('init')
18
+ .description('Initialize StackMemory in current project')
19
+ .action(async () => {
20
+ try {
21
+ const projectRoot = process.cwd();
22
+ const dbDir = join(projectRoot, '.stackmemory');
23
+ if (!existsSync(dbDir)) {
24
+ mkdirSync(dbDir, { recursive: true });
25
+ }
26
+ const dbPath = join(dbDir, 'context.db');
27
+ const db = new Database(dbPath);
28
+ const frameManager = new FrameManager(db, 'cli-project');
29
+ logger.info('StackMemory initialized successfully', { projectRoot });
30
+ console.log('āœ… StackMemory initialized in', projectRoot);
31
+ db.close();
32
+ }
33
+ catch (error) {
34
+ logger.error('Failed to initialize StackMemory', error);
35
+ console.error('āŒ Initialization failed:', error.message);
36
+ process.exit(1);
37
+ }
38
+ });
39
+ program
40
+ .command('status')
41
+ .description('Show current StackMemory status')
42
+ .action(async () => {
43
+ try {
44
+ const projectRoot = process.cwd();
45
+ const dbPath = join(projectRoot, '.stackmemory', 'context.db');
46
+ if (!existsSync(dbPath)) {
47
+ console.log('āŒ StackMemory not initialized. Run "stackmemory init" first.');
48
+ return;
49
+ }
50
+ const db = new Database(dbPath);
51
+ const frameManager = new FrameManager(db, 'cli-project');
52
+ const activeFrames = frameManager.getActiveFramePath();
53
+ const stackDepth = frameManager.getStackDepth();
54
+ console.log('šŸ“Š StackMemory Status:');
55
+ console.log(` Stack depth: ${stackDepth}`);
56
+ console.log(` Active frames: ${activeFrames.length}`);
57
+ if (activeFrames.length > 0) {
58
+ console.log('\\nšŸ“š Active Frames:');
59
+ activeFrames.forEach((frame, i) => {
60
+ const indent = ' '.repeat(i);
61
+ console.log(`${indent}${i + 1}. ${frame.name} (${frame.type})`);
62
+ });
63
+ }
64
+ db.close();
65
+ }
66
+ catch (error) {
67
+ logger.error('Failed to get status', error);
68
+ console.error('āŒ Status check failed:', error.message);
69
+ process.exit(1);
70
+ }
71
+ });
72
+ program.parse();
73
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AACA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,IAAI,EAAW,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE3C,OAAO;KACJ,IAAI,CAAC,aAAa,CAAC;KACnB,WAAW,CAAC,6CAA6C,CAAC;KAC1D,OAAO,CAAC,OAAO,CAAC,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AAC,CAAC;QAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Comprehensive error handling for StackMemory CLI
3
+ */
4
+ export declare enum ErrorCode {
5
+ AUTH_FAILED = "AUTH_FAILED",
6
+ TOKEN_EXPIRED = "TOKEN_EXPIRED",
7
+ INVALID_CREDENTIALS = "INVALID_CREDENTIALS",
8
+ FILE_NOT_FOUND = "FILE_NOT_FOUND",
9
+ PERMISSION_DENIED = "PERMISSION_DENIED",
10
+ DISK_FULL = "DISK_FULL",
11
+ NOT_GIT_REPO = "NOT_GIT_REPO",
12
+ GIT_COMMAND_FAILED = "GIT_COMMAND_FAILED",
13
+ INVALID_BRANCH = "INVALID_BRANCH",
14
+ DB_CONNECTION_FAILED = "DB_CONNECTION_FAILED",
15
+ DB_QUERY_FAILED = "DB_QUERY_FAILED",
16
+ DB_CORRUPTION = "DB_CORRUPTION",
17
+ NETWORK_ERROR = "NETWORK_ERROR",
18
+ API_ERROR = "API_ERROR",
19
+ TIMEOUT = "TIMEOUT",
20
+ INVALID_INPUT = "INVALID_INPUT",
21
+ VALIDATION_FAILED = "VALIDATION_FAILED",
22
+ UNKNOWN_ERROR = "UNKNOWN_ERROR",
23
+ OPERATION_FAILED = "OPERATION_FAILED",
24
+ CONFIGURATION_ERROR = "CONFIGURATION_ERROR"
25
+ }
26
+ export declare class StackMemoryError extends Error {
27
+ readonly code: ErrorCode;
28
+ readonly context: Record<string, unknown>;
29
+ readonly userMessage: string;
30
+ readonly recoverable: boolean;
31
+ constructor(code: ErrorCode, message: string, userMessage?: string, context?: Record<string, unknown>, recoverable?: boolean, cause?: Error);
32
+ private getDefaultUserMessage;
33
+ static fromNodeError(nodeError: NodeJS.ErrnoException, context?: Record<string, unknown>): StackMemoryError;
34
+ }
35
+ export declare class ErrorHandler {
36
+ static handle(error: unknown, operation: string): never;
37
+ static safeExecute<T>(operation: () => Promise<T> | T, operationName: string, fallback?: T): Promise<T | undefined>;
38
+ }
39
+ export declare const validateInput: (value: unknown, name: string, validator: (val: unknown) => boolean) => asserts value is NonNullable<unknown>;
40
+ export declare const validateEmail: (email: string) => asserts email is string;
41
+ export declare const validatePath: (filePath: string) => asserts filePath is string;
42
+ //# sourceMappingURL=error-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../src/error-handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,oBAAY,SAAS;IAEnB,WAAW,gBAAgB;IAC3B,aAAa,kBAAkB;IAC/B,mBAAmB,wBAAwB;IAG3C,cAAc,mBAAmB;IACjC,iBAAiB,sBAAsB;IACvC,SAAS,cAAc;IAGvB,YAAY,iBAAiB;IAC7B,kBAAkB,uBAAuB;IACzC,cAAc,mBAAmB;IAGjC,oBAAoB,yBAAyB;IAC7C,eAAe,oBAAoB;IACnC,aAAa,kBAAkB;IAG/B,aAAa,kBAAkB;IAC/B,SAAS,cAAc;IACvB,OAAO,YAAY;IAGnB,aAAa,kBAAkB;IAC/B,iBAAiB,sBAAsB;IAGvC,aAAa,kBAAkB;IAC/B,gBAAgB,qBAAqB;IACrC,mBAAmB,wBAAwB;CAC5C;AAED,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,SAAgB,IAAI,EAAE,SAAS,CAAC;IAChC,SAAgB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjD,SAAgB,WAAW,EAAE,MAAM,CAAC;IACpC,SAAgB,WAAW,EAAE,OAAO,CAAC;gBAGnC,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,MAAM,EACpB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACrC,WAAW,GAAE,OAAe,EAC5B,KAAK,CAAC,EAAE,KAAK;IAsBf,OAAO,CAAC,qBAAqB;IAqB7B,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,cAAc,EAAE,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,gBAAgB;CAwDhH;AAED,qBAAa,YAAY;IACvB,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,GAAG,KAAK;WAkD1C,WAAW,CAAC,CAAC,EACxB,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAC/B,aAAa,EAAE,MAAM,EACrB,QAAQ,CAAC,EAAE,CAAC,GACX,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;CAY1B;AAGD,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,EAAE,MAAM,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,KAAG,QAAQ,KAAK,IAAI,WAAW,CAAC,OAAO,CAUtI,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,QAAQ,KAAK,IAAI,MAW9D,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM,KAAG,QAAQ,QAAQ,IAAI,MAUnE,CAAC"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Comprehensive error handling for StackMemory CLI
3
+ */
4
+ import { logger } from './logger.js';
5
+ export var ErrorCode;
6
+ (function (ErrorCode) {
7
+ // Authentication errors
8
+ ErrorCode["AUTH_FAILED"] = "AUTH_FAILED";
9
+ ErrorCode["TOKEN_EXPIRED"] = "TOKEN_EXPIRED";
10
+ ErrorCode["INVALID_CREDENTIALS"] = "INVALID_CREDENTIALS";
11
+ // File system errors
12
+ ErrorCode["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
13
+ ErrorCode["PERMISSION_DENIED"] = "PERMISSION_DENIED";
14
+ ErrorCode["DISK_FULL"] = "DISK_FULL";
15
+ // Git operation errors
16
+ ErrorCode["NOT_GIT_REPO"] = "NOT_GIT_REPO";
17
+ ErrorCode["GIT_COMMAND_FAILED"] = "GIT_COMMAND_FAILED";
18
+ ErrorCode["INVALID_BRANCH"] = "INVALID_BRANCH";
19
+ // Database errors
20
+ ErrorCode["DB_CONNECTION_FAILED"] = "DB_CONNECTION_FAILED";
21
+ ErrorCode["DB_QUERY_FAILED"] = "DB_QUERY_FAILED";
22
+ ErrorCode["DB_CORRUPTION"] = "DB_CORRUPTION";
23
+ // Network errors
24
+ ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
25
+ ErrorCode["API_ERROR"] = "API_ERROR";
26
+ ErrorCode["TIMEOUT"] = "TIMEOUT";
27
+ // Validation errors
28
+ ErrorCode["INVALID_INPUT"] = "INVALID_INPUT";
29
+ ErrorCode["VALIDATION_FAILED"] = "VALIDATION_FAILED";
30
+ // General errors
31
+ ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
32
+ ErrorCode["OPERATION_FAILED"] = "OPERATION_FAILED";
33
+ ErrorCode["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
34
+ })(ErrorCode || (ErrorCode = {}));
35
+ export class StackMemoryError extends Error {
36
+ code;
37
+ context;
38
+ userMessage;
39
+ recoverable;
40
+ constructor(code, message, userMessage, context = {}, recoverable = false, cause) {
41
+ super(message);
42
+ this.name = 'StackMemoryError';
43
+ this.code = code;
44
+ this.context = context;
45
+ this.userMessage = userMessage || this.getDefaultUserMessage(code);
46
+ this.recoverable = recoverable;
47
+ if (cause && Error.captureStackTrace) {
48
+ Error.captureStackTrace(this, StackMemoryError);
49
+ }
50
+ // Log the error
51
+ logger.error(message, cause, {
52
+ code,
53
+ context,
54
+ recoverable,
55
+ userMessage: this.userMessage
56
+ });
57
+ }
58
+ getDefaultUserMessage(code) {
59
+ switch (code) {
60
+ case ErrorCode.AUTH_FAILED:
61
+ return 'Authentication failed. Please check your credentials and try again.';
62
+ case ErrorCode.NOT_GIT_REPO:
63
+ return 'This command requires a git repository. Please run it from within a git repository.';
64
+ case ErrorCode.PERMISSION_DENIED:
65
+ return 'Permission denied. Please check file permissions or run with appropriate privileges.';
66
+ case ErrorCode.NETWORK_ERROR:
67
+ return 'Network error. Please check your internet connection and try again.';
68
+ case ErrorCode.INVALID_INPUT:
69
+ return 'Invalid input provided. Please check your command and try again.';
70
+ case ErrorCode.DB_CONNECTION_FAILED:
71
+ return 'Database connection failed. Please try again or contact support if the issue persists.';
72
+ case ErrorCode.GIT_COMMAND_FAILED:
73
+ return 'Git operation failed. Please ensure your repository is in a valid state.';
74
+ default:
75
+ return 'An unexpected error occurred. Please try again or contact support.';
76
+ }
77
+ }
78
+ static fromNodeError(nodeError, context = {}) {
79
+ const code = nodeError.code;
80
+ switch (code) {
81
+ case 'ENOENT':
82
+ return new StackMemoryError(ErrorCode.FILE_NOT_FOUND, `File or directory not found: ${nodeError.path}`, 'The requested file or directory was not found.', { ...context, path: nodeError.path }, false, nodeError);
83
+ case 'EACCES':
84
+ case 'EPERM':
85
+ return new StackMemoryError(ErrorCode.PERMISSION_DENIED, `Permission denied: ${nodeError.path}`, 'Permission denied. Please check file permissions.', { ...context, path: nodeError.path }, true, nodeError);
86
+ case 'ENOSPC':
87
+ return new StackMemoryError(ErrorCode.DISK_FULL, 'No space left on device', 'Insufficient disk space. Please free up space and try again.', context, true, nodeError);
88
+ case 'ETIMEDOUT':
89
+ return new StackMemoryError(ErrorCode.TIMEOUT, 'Operation timed out', 'The operation timed out. Please try again.', context, true, nodeError);
90
+ default:
91
+ return new StackMemoryError(ErrorCode.UNKNOWN_ERROR, nodeError.message, 'An unexpected system error occurred.', { ...context, nodeErrorCode: code }, false, nodeError);
92
+ }
93
+ }
94
+ }
95
+ export class ErrorHandler {
96
+ static handle(error, operation) {
97
+ if (error instanceof StackMemoryError) {
98
+ // Already a well-formed StackMemory error
99
+ console.error(`āŒ ${error.userMessage}`);
100
+ if (error.recoverable) {
101
+ console.error('šŸ’” This error may be recoverable. Please try again.');
102
+ }
103
+ process.exit(1);
104
+ }
105
+ if (error instanceof Error) {
106
+ // Convert Node.js error to StackMemoryError
107
+ let stackMemoryError;
108
+ if ('code' in error && typeof error.code === 'string') {
109
+ stackMemoryError = StackMemoryError.fromNodeError(error, { operation });
110
+ }
111
+ else {
112
+ stackMemoryError = new StackMemoryError(ErrorCode.OPERATION_FAILED, `Operation '${operation}' failed: ${error.message}`, `Operation failed: ${error.message}`, { operation }, false, error);
113
+ }
114
+ console.error(`āŒ ${stackMemoryError.userMessage}`);
115
+ if (stackMemoryError.recoverable) {
116
+ console.error('šŸ’” This error may be recoverable. Please try again.');
117
+ }
118
+ process.exit(1);
119
+ }
120
+ // Unknown error type
121
+ const unknownError = new StackMemoryError(ErrorCode.UNKNOWN_ERROR, `Unknown error in operation '${operation}': ${String(error)}`, 'An unexpected error occurred.', { operation, errorType: typeof error }, false);
122
+ console.error(`āŒ ${unknownError.userMessage}`);
123
+ process.exit(1);
124
+ }
125
+ static async safeExecute(operation, operationName, fallback) {
126
+ try {
127
+ return await operation();
128
+ }
129
+ catch (error) {
130
+ if (fallback !== undefined) {
131
+ logger.warn(`Operation '${operationName}' failed, using fallback`, { error: String(error) });
132
+ return fallback;
133
+ }
134
+ ErrorHandler.handle(error, operationName);
135
+ }
136
+ }
137
+ }
138
+ // Utility functions for common error scenarios
139
+ export const validateInput = (value, name, validator) => {
140
+ if (!validator(value)) {
141
+ throw new StackMemoryError(ErrorCode.INVALID_INPUT, `Invalid ${name}: ${String(value)}`, `Please provide a valid ${name}.`, { name, value }, true);
142
+ }
143
+ };
144
+ export const validateEmail = (email) => {
145
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
146
+ if (!emailRegex.test(email) || email.length > 254) {
147
+ throw new StackMemoryError(ErrorCode.INVALID_INPUT, `Invalid email format: ${email}`, 'Please provide a valid email address.', { email }, true);
148
+ }
149
+ };
150
+ export const validatePath = (filePath) => {
151
+ if (!filePath || filePath.includes('..') || filePath.includes('\0')) {
152
+ throw new StackMemoryError(ErrorCode.INVALID_INPUT, `Invalid path: ${filePath}`, 'Invalid file path provided.', { path: filePath }, true);
153
+ }
154
+ };
155
+ //# sourceMappingURL=error-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/error-handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,CAAN,IAAY,SAkCX;AAlCD,WAAY,SAAS;IACnB,wBAAwB;IACxB,wCAA2B,CAAA;IAC3B,4CAA+B,CAAA;IAC/B,wDAA2C,CAAA;IAE3C,qBAAqB;IACrB,8CAAiC,CAAA;IACjC,oDAAuC,CAAA;IACvC,oCAAuB,CAAA;IAEvB,uBAAuB;IACvB,0CAA6B,CAAA;IAC7B,sDAAyC,CAAA;IACzC,8CAAiC,CAAA;IAEjC,kBAAkB;IAClB,0DAA6C,CAAA;IAC7C,gDAAmC,CAAA;IACnC,4CAA+B,CAAA;IAE/B,iBAAiB;IACjB,4CAA+B,CAAA;IAC/B,oCAAuB,CAAA;IACvB,gCAAmB,CAAA;IAEnB,oBAAoB;IACpB,4CAA+B,CAAA;IAC/B,oDAAuC,CAAA;IAEvC,iBAAiB;IACjB,4CAA+B,CAAA;IAC/B,kDAAqC,CAAA;IACrC,wDAA2C,CAAA;AAC7C,CAAC,EAlCW,SAAS,KAAT,SAAS,QAkCpB;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzB,IAAI,CAAY;IAChB,OAAO,CAA0B;IACjC,WAAW,CAAS;IACpB,WAAW,CAAU;IAErC,YACE,IAAe,EACf,OAAe,EACf,WAAoB,EACpB,UAAmC,EAAE,EACrC,cAAuB,KAAK,EAC5B,KAAa;QAEb,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAA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,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,gBAAgB,CACxB,SAAS,CAAC,aAAa,EACvB,iBAAiB,QAAQ,EAAE,EAC3B,6BAA6B,EAC7B,EAAE,IAAI,EAAE,QAAQ,EAAE,EAClB,IAAI,CACL,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * StackMemory Frame Manager - Call Stack Implementation
3
+ * Manages nested frames representing the call stack of work
4
+ */
5
+ import Database from 'better-sqlite3';
6
+ export type FrameType = 'task' | 'subtask' | 'tool_scope' | 'review' | 'write' | 'debug';
7
+ export type FrameState = 'active' | 'closed';
8
+ export interface Frame {
9
+ frame_id: string;
10
+ run_id: string;
11
+ project_id: string;
12
+ parent_frame_id?: string;
13
+ depth: number;
14
+ type: FrameType;
15
+ name: string;
16
+ state: FrameState;
17
+ inputs: Record<string, any>;
18
+ outputs: Record<string, any>;
19
+ digest_text?: string;
20
+ digest_json: Record<string, any>;
21
+ created_at: number;
22
+ closed_at?: number;
23
+ }
24
+ export interface FrameContext {
25
+ frameId: string;
26
+ header: {
27
+ goal: string;
28
+ constraints?: string[];
29
+ definitions?: Record<string, string>;
30
+ };
31
+ anchors: Anchor[];
32
+ recentEvents: Event[];
33
+ activeArtifacts: string[];
34
+ }
35
+ export interface Anchor {
36
+ anchor_id: string;
37
+ frame_id: string;
38
+ type: 'FACT' | 'DECISION' | 'CONSTRAINT' | 'INTERFACE_CONTRACT' | 'TODO' | 'RISK';
39
+ text: string;
40
+ priority: number;
41
+ metadata: Record<string, any>;
42
+ }
43
+ export interface Event {
44
+ event_id: string;
45
+ frame_id: string;
46
+ run_id: string;
47
+ seq: number;
48
+ event_type: 'user_message' | 'assistant_message' | 'tool_call' | 'tool_result' | 'decision' | 'constraint' | 'artifact' | 'observation';
49
+ payload: Record<string, any>;
50
+ ts: number;
51
+ }
52
+ export declare class FrameManager {
53
+ private db;
54
+ private currentRunId;
55
+ private projectId;
56
+ private activeStack;
57
+ constructor(db: Database.Database, projectId: string, runId?: string);
58
+ private initializeSchema;
59
+ private loadActiveStack;
60
+ private buildStackOrder;
61
+ /**
62
+ * Create a new frame and push to stack
63
+ */
64
+ createFrame(options: {
65
+ type: FrameType;
66
+ name: string;
67
+ inputs?: Record<string, any>;
68
+ parentFrameId?: string;
69
+ }): string;
70
+ /**
71
+ * Close the current frame and generate digest
72
+ */
73
+ closeFrame(frameId?: string, outputs?: Record<string, any>): void;
74
+ private closeChildFrames;
75
+ /**
76
+ * Generate digest for a frame
77
+ */
78
+ private generateDigest;
79
+ private generateDigestText;
80
+ /**
81
+ * Add event to current frame
82
+ */
83
+ addEvent(eventType: Event['event_type'], payload: Record<string, any>, frameId?: string): string;
84
+ /**
85
+ * Add anchor to frame
86
+ */
87
+ addAnchor(type: Anchor['type'], text: string, priority?: number, metadata?: Record<string, any>, frameId?: string): string;
88
+ /**
89
+ * Get hot stack context for current active frames
90
+ */
91
+ getHotStackContext(maxEvents?: number): FrameContext[];
92
+ /**
93
+ * Get active frame path (root to current)
94
+ */
95
+ getActiveFramePath(): Frame[];
96
+ getCurrentFrameId(): string | undefined;
97
+ getStackDepth(): number;
98
+ private getFrameDepth;
99
+ private getFrame;
100
+ private getFrameEvents;
101
+ private getFrameAnchors;
102
+ private getNextEventSequence;
103
+ private extractConstraints;
104
+ private getActiveArtifacts;
105
+ }
106
+ //# sourceMappingURL=frame-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame-manager.d.ts","sourceRoot":"","sources":["../../src/frame-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAMtC,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,CAAC;AACzF,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE7C,MAAM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