@stackmemoryai/stackmemory 0.2.3 → 0.2.6

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 (187) hide show
  1. package/README.md +108 -0
  2. package/dist/index.js +382 -0
  3. package/dist/src/analytics/api/analytics-api.d.ts +24 -0
  4. package/dist/src/analytics/api/analytics-api.d.ts.map +1 -0
  5. package/dist/src/analytics/api/analytics-api.js +279 -0
  6. package/dist/src/analytics/api/analytics-api.js.map +1 -0
  7. package/dist/src/analytics/core/analytics-service.d.ts +23 -0
  8. package/dist/src/analytics/core/analytics-service.d.ts.map +1 -0
  9. package/dist/src/analytics/core/analytics-service.js +160 -0
  10. package/dist/src/analytics/core/analytics-service.js.map +1 -0
  11. package/dist/src/analytics/index.d.ts +12 -0
  12. package/dist/src/analytics/index.d.ts.map +1 -0
  13. package/dist/src/analytics/index.js +11 -0
  14. package/dist/src/analytics/index.js.map +1 -0
  15. package/dist/src/analytics/queries/metrics-queries.d.ts +11 -0
  16. package/dist/src/analytics/queries/metrics-queries.d.ts.map +1 -0
  17. package/dist/src/analytics/queries/metrics-queries.js +179 -0
  18. package/dist/src/analytics/queries/metrics-queries.js.map +1 -0
  19. package/dist/src/analytics/types/metrics.d.ts +60 -0
  20. package/dist/src/analytics/types/metrics.d.ts.map +1 -0
  21. package/dist/src/analytics/types/metrics.js +2 -0
  22. package/dist/src/analytics/types/metrics.js.map +1 -0
  23. package/dist/src/cli/analytics-viewer.d.ts +3 -0
  24. package/dist/src/cli/analytics-viewer.d.ts.map +1 -0
  25. package/dist/src/cli/analytics-viewer.js +89 -0
  26. package/dist/src/cli/analytics-viewer.js.map +1 -0
  27. package/dist/src/cli/browser-test.d.ts +6 -0
  28. package/dist/src/cli/browser-test.d.ts.map +1 -0
  29. package/dist/src/cli/browser-test.js +32 -0
  30. package/dist/src/cli/browser-test.js.map +1 -0
  31. package/dist/src/cli/cli.js +233 -1
  32. package/dist/src/cli/cli.js.map +1 -1
  33. package/dist/src/cli/commands/projects.d.ts +8 -0
  34. package/dist/src/cli/commands/projects.d.ts.map +1 -0
  35. package/dist/src/cli/commands/projects.js +220 -0
  36. package/dist/src/cli/commands/projects.js.map +1 -0
  37. package/dist/src/cli/index.d.ts +7 -0
  38. package/dist/src/cli/index.d.ts.map +1 -0
  39. package/dist/src/cli/index.js +704 -0
  40. package/dist/src/cli/index.js.map +1 -0
  41. package/dist/src/cli/project-commands.d.ts +8 -0
  42. package/dist/src/cli/project-commands.d.ts.map +1 -0
  43. package/dist/src/cli/project-commands.js +212 -0
  44. package/dist/src/cli/project-commands.js.map +1 -0
  45. package/dist/src/cli/utils/viewer.d.ts +3 -0
  46. package/dist/src/cli/utils/viewer.d.ts.map +1 -0
  47. package/dist/src/cli/utils/viewer.js +89 -0
  48. package/dist/src/cli/utils/viewer.js.map +1 -0
  49. package/dist/src/core/context/frame-manager.d.ts +106 -0
  50. package/dist/src/core/context/frame-manager.d.ts.map +1 -0
  51. package/dist/src/core/context/frame-manager.js +387 -0
  52. package/dist/src/core/context/frame-manager.js.map +1 -0
  53. package/dist/src/core/logger.test.js +1 -1
  54. package/dist/src/core/logger.test.js.map +1 -1
  55. package/dist/src/core/monitoring/error-handler.d.ts +46 -0
  56. package/dist/src/core/monitoring/error-handler.d.ts.map +1 -0
  57. package/dist/src/core/monitoring/error-handler.js +212 -0
  58. package/dist/src/core/monitoring/error-handler.js.map +1 -0
  59. package/dist/src/core/monitoring/logger.d.ts +24 -0
  60. package/dist/src/core/monitoring/logger.d.ts.map +1 -0
  61. package/dist/src/core/monitoring/logger.js +121 -0
  62. package/dist/src/core/monitoring/logger.js.map +1 -0
  63. package/dist/src/core/monitoring/metrics.d.ts +7 -0
  64. package/dist/src/core/monitoring/metrics.d.ts.map +1 -0
  65. package/dist/src/core/monitoring/metrics.js +13 -0
  66. package/dist/src/core/monitoring/metrics.js.map +1 -0
  67. package/dist/src/core/monitoring/progress-tracker.d.ts +95 -0
  68. package/dist/src/core/monitoring/progress-tracker.d.ts.map +1 -0
  69. package/dist/src/core/monitoring/progress-tracker.js +178 -0
  70. package/dist/src/core/monitoring/progress-tracker.js.map +1 -0
  71. package/dist/src/core/progress-tracker.d.ts +95 -0
  72. package/dist/src/core/progress-tracker.d.ts.map +1 -0
  73. package/dist/src/core/progress-tracker.js +178 -0
  74. package/dist/src/core/progress-tracker.js.map +1 -0
  75. package/dist/src/core/project-manager.d.ts +130 -0
  76. package/dist/src/core/project-manager.d.ts.map +1 -0
  77. package/dist/src/core/project-manager.js +582 -0
  78. package/dist/src/core/project-manager.js.map +1 -0
  79. package/dist/src/core/projects/project-manager.d.ts +130 -0
  80. package/dist/src/core/projects/project-manager.d.ts.map +1 -0
  81. package/dist/src/core/projects/project-manager.js +591 -0
  82. package/dist/src/core/projects/project-manager.js.map +1 -0
  83. package/dist/src/core/update-checker.d.ts +38 -0
  84. package/dist/src/core/update-checker.d.ts.map +1 -0
  85. package/dist/src/core/update-checker.js +156 -0
  86. package/dist/src/core/update-checker.js.map +1 -0
  87. package/dist/src/core/utils/update-checker.d.ts +38 -0
  88. package/dist/src/core/utils/update-checker.d.ts.map +1 -0
  89. package/dist/src/core/utils/update-checker.js +156 -0
  90. package/dist/src/core/utils/update-checker.js.map +1 -0
  91. package/dist/src/features/analytics/api/analytics-api.d.ts +24 -0
  92. package/dist/src/features/analytics/api/analytics-api.d.ts.map +1 -0
  93. package/dist/src/features/analytics/api/analytics-api.js +289 -0
  94. package/dist/src/features/analytics/api/analytics-api.js.map +1 -0
  95. package/dist/src/features/analytics/core/analytics-service.d.ts +23 -0
  96. package/dist/src/features/analytics/core/analytics-service.d.ts.map +1 -0
  97. package/dist/src/features/analytics/core/analytics-service.js +160 -0
  98. package/dist/src/features/analytics/core/analytics-service.js.map +1 -0
  99. package/dist/src/features/analytics/index.d.ts +12 -0
  100. package/dist/src/features/analytics/index.d.ts.map +1 -0
  101. package/dist/src/features/analytics/index.js +11 -0
  102. package/dist/src/features/analytics/index.js.map +1 -0
  103. package/dist/src/features/analytics/queries/metrics-queries.d.ts +11 -0
  104. package/dist/src/features/analytics/queries/metrics-queries.d.ts.map +1 -0
  105. package/dist/src/features/analytics/queries/metrics-queries.js +183 -0
  106. package/dist/src/features/analytics/queries/metrics-queries.js.map +1 -0
  107. package/dist/src/features/analytics/types/metrics.d.ts +60 -0
  108. package/dist/src/features/analytics/types/metrics.d.ts.map +1 -0
  109. package/dist/src/features/analytics/types/metrics.js +2 -0
  110. package/dist/src/features/analytics/types/metrics.js.map +1 -0
  111. package/dist/src/features/browser/browser-mcp.d.ts +94 -0
  112. package/dist/src/features/browser/browser-mcp.d.ts.map +1 -0
  113. package/dist/src/features/browser/browser-mcp.js +456 -0
  114. package/dist/src/features/browser/browser-mcp.js.map +1 -0
  115. package/dist/src/features/tasks/pebbles-task-store.d.ts +117 -0
  116. package/dist/src/features/tasks/pebbles-task-store.d.ts.map +1 -0
  117. package/dist/src/features/tasks/pebbles-task-store.js +335 -0
  118. package/dist/src/features/tasks/pebbles-task-store.js.map +1 -0
  119. package/dist/src/features/tasks/task-aware-context.d.ts +103 -0
  120. package/dist/src/features/tasks/task-aware-context.d.ts.map +1 -0
  121. package/dist/src/features/tasks/task-aware-context.js +412 -0
  122. package/dist/src/features/tasks/task-aware-context.js.map +1 -0
  123. package/dist/src/index.d.ts +4 -4
  124. package/dist/src/index.d.ts.map +1 -1
  125. package/dist/src/index.js +4 -4
  126. package/dist/src/index.js.map +1 -1
  127. package/dist/src/integrations/browser-mcp.d.ts +94 -0
  128. package/dist/src/integrations/browser-mcp.d.ts.map +1 -0
  129. package/dist/src/integrations/browser-mcp.js +431 -0
  130. package/dist/src/integrations/browser-mcp.js.map +1 -0
  131. package/dist/src/integrations/linear/auth.d.ts +99 -0
  132. package/dist/src/integrations/linear/auth.d.ts.map +1 -0
  133. package/dist/src/integrations/linear/auth.js +319 -0
  134. package/dist/src/integrations/linear/auth.js.map +1 -0
  135. package/dist/src/integrations/linear/auto-sync.d.ts +77 -0
  136. package/dist/src/integrations/linear/auto-sync.d.ts.map +1 -0
  137. package/dist/src/integrations/linear/auto-sync.js +268 -0
  138. package/dist/src/integrations/linear/auto-sync.js.map +1 -0
  139. package/dist/src/integrations/linear/client.d.ts +86 -0
  140. package/dist/src/integrations/linear/client.d.ts.map +1 -0
  141. package/dist/src/integrations/linear/client.js +277 -0
  142. package/dist/src/integrations/linear/client.js.map +1 -0
  143. package/dist/src/integrations/linear/config.d.ts +51 -0
  144. package/dist/src/integrations/linear/config.d.ts.map +1 -0
  145. package/dist/src/integrations/linear/config.js +103 -0
  146. package/dist/src/integrations/linear/config.js.map +1 -0
  147. package/dist/src/integrations/linear/sync.d.ts +97 -0
  148. package/dist/src/integrations/linear/sync.d.ts.map +1 -0
  149. package/dist/src/integrations/linear/sync.js +391 -0
  150. package/dist/src/integrations/linear/sync.js.map +1 -0
  151. package/dist/src/integrations/mcp/server.d.ts +40 -0
  152. package/dist/src/integrations/mcp/server.d.ts.map +1 -0
  153. package/dist/src/integrations/mcp/server.js +828 -0
  154. package/dist/src/integrations/mcp/server.js.map +1 -0
  155. package/dist/src/mcp/mcp-server.d.ts +2 -0
  156. package/dist/src/mcp/mcp-server.d.ts.map +1 -1
  157. package/dist/src/mcp/mcp-server.js +16 -0
  158. package/dist/src/mcp/mcp-server.js.map +1 -1
  159. package/dist/src/railway/index.d.ts +7 -0
  160. package/dist/src/railway/index.d.ts.map +1 -0
  161. package/dist/src/railway/index.js +401 -0
  162. package/dist/src/railway/index.js.map +1 -0
  163. package/dist/src/runway/auth/auth-middleware.d.ts +66 -0
  164. package/dist/src/runway/auth/auth-middleware.d.ts.map +1 -0
  165. package/dist/src/runway/auth/auth-middleware.js +337 -0
  166. package/dist/src/runway/auth/auth-middleware.js.map +1 -0
  167. package/dist/src/runway/server/runway-mcp-server.d.ts +46 -0
  168. package/dist/src/runway/server/runway-mcp-server.d.ts.map +1 -0
  169. package/dist/src/runway/server/runway-mcp-server.js +601 -0
  170. package/dist/src/runway/server/runway-mcp-server.js.map +1 -0
  171. package/dist/src/runway.bak/auth/auth-middleware.d.ts +66 -0
  172. package/dist/src/runway.bak/auth/auth-middleware.d.ts.map +1 -0
  173. package/dist/src/runway.bak/auth/auth-middleware.js +337 -0
  174. package/dist/src/runway.bak/auth/auth-middleware.js.map +1 -0
  175. package/dist/src/runway.bak/server/runway-mcp-server.d.ts +46 -0
  176. package/dist/src/runway.bak/server/runway-mcp-server.d.ts.map +1 -0
  177. package/dist/src/runway.bak/server/runway-mcp-server.js +601 -0
  178. package/dist/src/runway.bak/server/runway-mcp-server.js.map +1 -0
  179. package/dist/src/servers/production/auth-middleware.d.ts +66 -0
  180. package/dist/src/servers/production/auth-middleware.d.ts.map +1 -0
  181. package/dist/src/servers/production/auth-middleware.js +346 -0
  182. package/dist/src/servers/production/auth-middleware.js.map +1 -0
  183. package/dist/src/servers/railway/index.d.ts +7 -0
  184. package/dist/src/servers/railway/index.d.ts.map +1 -0
  185. package/dist/src/servers/railway/index.js +401 -0
  186. package/dist/src/servers/railway/index.js.map +1 -0
  187. package/package.json +27 -5
@@ -0,0 +1,704 @@
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 '../core/monitoring/logger.js';
8
+ import { FrameManager } from '../core/context/frame-manager.js';
9
+ import { PebblesTaskStore } from '../features/tasks/pebbles-task-store.js';
10
+ import { LinearAuthManager, LinearOAuthSetup, } from '../integrations/linear/auth.js';
11
+ import { LinearSyncEngine, DEFAULT_SYNC_CONFIG, } from '../integrations/linear/sync.js';
12
+ import { initializeAutoSync, getAutoSyncService, stopAutoSync, } from '../integrations/linear/auto-sync.js';
13
+ import { LinearConfigManager } from '../integrations/linear/config.js';
14
+ import { UpdateChecker } from '../core/utils/update-checker.js';
15
+ import { ProgressTracker } from '../core/monitoring/progress-tracker.js';
16
+ import { registerProjectCommands } from './commands/projects.js';
17
+ import { ProjectManager } from '../core/projects/project-manager.js';
18
+ import Database from 'better-sqlite3';
19
+ import { join } from 'path';
20
+ import { existsSync, mkdirSync } from 'fs';
21
+ const VERSION = '0.2.4';
22
+ // Check for updates on CLI startup
23
+ UpdateChecker.checkForUpdates(VERSION, true).catch(() => {
24
+ // Silently ignore errors
25
+ });
26
+ program
27
+ .name('stackmemory')
28
+ .description('Lossless memory runtime for AI coding tools')
29
+ .version(VERSION);
30
+ program
31
+ .command('init')
32
+ .description('Initialize StackMemory in current project')
33
+ .action(async () => {
34
+ try {
35
+ const projectRoot = process.cwd();
36
+ const dbDir = join(projectRoot, '.stackmemory');
37
+ if (!existsSync(dbDir)) {
38
+ mkdirSync(dbDir, { recursive: true });
39
+ }
40
+ const dbPath = join(dbDir, 'context.db');
41
+ const db = new Database(dbPath);
42
+ new FrameManager(db, 'cli-project');
43
+ logger.info('StackMemory initialized successfully', { projectRoot });
44
+ console.log('āœ… StackMemory initialized in', projectRoot);
45
+ db.close();
46
+ }
47
+ catch (error) {
48
+ logger.error('Failed to initialize StackMemory', error);
49
+ console.error('āŒ Initialization failed:', error.message);
50
+ process.exit(1);
51
+ }
52
+ });
53
+ program
54
+ .command('status')
55
+ .description('Show current StackMemory status')
56
+ .action(async () => {
57
+ try {
58
+ const projectRoot = process.cwd();
59
+ const dbPath = join(projectRoot, '.stackmemory', 'context.db');
60
+ if (!existsSync(dbPath)) {
61
+ console.log('āŒ StackMemory not initialized. Run "stackmemory init" first.');
62
+ return;
63
+ }
64
+ // Check for updates and display if available
65
+ await UpdateChecker.checkForUpdates(VERSION);
66
+ const db = new Database(dbPath);
67
+ const frameManager = new FrameManager(db, 'cli-project');
68
+ const activeFrames = frameManager.getActiveFramePath();
69
+ const stackDepth = frameManager.getStackDepth();
70
+ console.log('šŸ“Š StackMemory Status:');
71
+ console.log(` Stack depth: ${stackDepth}`);
72
+ console.log(` Active frames: ${activeFrames.length}`);
73
+ if (activeFrames.length > 0) {
74
+ console.log('\\nšŸ“š Active Frames:');
75
+ activeFrames.forEach((frame, i) => {
76
+ const indent = ' '.repeat(i);
77
+ console.log(`${indent}${i + 1}. ${frame.name} (${frame.type})`);
78
+ });
79
+ }
80
+ db.close();
81
+ }
82
+ catch (error) {
83
+ logger.error('Failed to get status', error);
84
+ console.error('āŒ Status check failed:', error.message);
85
+ process.exit(1);
86
+ }
87
+ });
88
+ // Linear Integration Commands
89
+ const linearCommand = program
90
+ .command('linear')
91
+ .description('Linear API integration commands');
92
+ linearCommand
93
+ .command('setup')
94
+ .description('Setup Linear OAuth integration')
95
+ .action(async () => {
96
+ try {
97
+ const projectRoot = process.cwd();
98
+ const linearSetup = new LinearOAuthSetup(projectRoot);
99
+ const { authUrl, instructions } = await linearSetup.setupInteractive();
100
+ console.log('šŸ”— Linear OAuth Setup\n');
101
+ instructions.forEach((instruction) => {
102
+ console.log(instruction);
103
+ });
104
+ if (authUrl) {
105
+ console.log('\nšŸ“‹ Next step: Complete authorization and run:');
106
+ console.log('stackmemory linear authorize <auth-code>');
107
+ }
108
+ }
109
+ catch (error) {
110
+ logger.error('Linear setup failed', error);
111
+ console.error('āŒ Setup failed:', error.message);
112
+ process.exit(1);
113
+ }
114
+ });
115
+ linearCommand
116
+ .command('authorize')
117
+ .description('Complete Linear OAuth authorization')
118
+ .argument('<code>', 'Authorization code from Linear')
119
+ .action(async (authCode) => {
120
+ try {
121
+ const projectRoot = process.cwd();
122
+ const linearSetup = new LinearOAuthSetup(projectRoot);
123
+ const success = await linearSetup.completeAuth(authCode);
124
+ if (success) {
125
+ console.log('āœ… Linear integration authorized successfully!');
126
+ console.log('🧪 Testing connection...');
127
+ const connectionOk = await linearSetup.testConnection();
128
+ if (connectionOk) {
129
+ console.log('āœ… Linear connection test passed!');
130
+ console.log('\nšŸš€ You can now use:');
131
+ console.log('- stackmemory linear sync');
132
+ console.log('- stackmemory linear status');
133
+ }
134
+ else {
135
+ console.log('āš ļø Linear connection test failed. Check your configuration.');
136
+ }
137
+ }
138
+ else {
139
+ console.error('āŒ Authorization failed. Please try again.');
140
+ process.exit(1);
141
+ }
142
+ }
143
+ catch (error) {
144
+ logger.error('Linear authorization failed', error);
145
+ console.error('āŒ Authorization failed:', error.message);
146
+ process.exit(1);
147
+ }
148
+ });
149
+ linearCommand
150
+ .command('status')
151
+ .description('Show Linear integration status')
152
+ .action(async () => {
153
+ try {
154
+ const projectRoot = process.cwd();
155
+ const authManager = new LinearAuthManager(projectRoot);
156
+ const isConfigured = authManager.isConfigured();
157
+ console.log('šŸ“Š Linear Integration Status:');
158
+ console.log(` Configured: ${isConfigured ? 'āœ…' : 'āŒ'}`);
159
+ if (isConfigured) {
160
+ const config = authManager.loadConfig();
161
+ const tokens = authManager.loadTokens();
162
+ console.log(` Client ID: ${config?.clientId ? config.clientId.substring(0, 8) + '...' : 'Not set'}`);
163
+ console.log(` Tokens: ${tokens ? 'āœ… Valid' : 'āŒ Missing'}`);
164
+ if (tokens) {
165
+ const expiresIn = Math.floor((tokens.expiresAt - Date.now()) / 1000 / 60);
166
+ console.log(` Token expires: ${expiresIn > 0 ? `${expiresIn} minutes` : 'Expired'}`);
167
+ }
168
+ // Test connection
169
+ console.log('\n🧪 Testing connection...');
170
+ const linearSetup = new LinearOAuthSetup(projectRoot);
171
+ const connectionOk = await linearSetup.testConnection();
172
+ console.log(` Connection: ${connectionOk ? 'āœ… OK' : 'āŒ Failed'}`);
173
+ }
174
+ else {
175
+ console.log('\nšŸ’” Run "stackmemory linear setup" to get started');
176
+ }
177
+ }
178
+ catch (error) {
179
+ logger.error('Linear status check failed', error);
180
+ console.error('āŒ Status check failed:', error.message);
181
+ process.exit(1);
182
+ }
183
+ });
184
+ linearCommand
185
+ .command('sync')
186
+ .description('Sync tasks with Linear')
187
+ .option('-d, --direction <direction>', 'Sync direction: bidirectional, to_linear, from_linear', 'bidirectional')
188
+ .action(async (options) => {
189
+ try {
190
+ const projectRoot = process.cwd();
191
+ const dbPath = join(projectRoot, '.stackmemory', 'context.db');
192
+ if (!existsSync(dbPath)) {
193
+ console.log('āŒ StackMemory not initialized. Run "stackmemory init" first.');
194
+ return;
195
+ }
196
+ const authManager = new LinearAuthManager(projectRoot);
197
+ // Check for API key from environment first
198
+ if (!process.env.LINEAR_API_KEY && !authManager.isConfigured()) {
199
+ console.log('āŒ Linear not configured. Set LINEAR_API_KEY environment variable or run "stackmemory linear setup" first.');
200
+ return;
201
+ }
202
+ const db = new Database(dbPath);
203
+ const taskStore = new PebblesTaskStore(projectRoot, db);
204
+ const syncConfig = {
205
+ ...DEFAULT_SYNC_CONFIG,
206
+ enabled: true,
207
+ direction: options.direction,
208
+ };
209
+ const linearSync = new LinearSyncEngine(taskStore, authManager, syncConfig);
210
+ console.log(`šŸ”„ Starting ${options.direction} sync with Linear...`);
211
+ const result = await linearSync.sync();
212
+ // Track progress
213
+ const progress = new ProgressTracker(projectRoot);
214
+ if (result.success) {
215
+ console.log('āœ… Sync completed successfully!');
216
+ console.log(` To Linear: ${result.synced.toLinear} created`);
217
+ console.log(` From Linear: ${result.synced.fromLinear} created`);
218
+ console.log(` Updated: ${result.synced.updated}`);
219
+ // Update progress tracker
220
+ progress.updateLinearStatus({
221
+ lastSync: new Date().toISOString(),
222
+ tasksSynced: result.synced.toLinear +
223
+ result.synced.fromLinear +
224
+ result.synced.updated,
225
+ });
226
+ if (result.conflicts.length > 0) {
227
+ console.log(`\nāš ļø Conflicts detected: ${result.conflicts.length}`);
228
+ result.conflicts.forEach((conflict) => {
229
+ console.log(` - ${conflict.taskId}: ${conflict.reason}`);
230
+ });
231
+ }
232
+ }
233
+ else {
234
+ console.log('āŒ Sync failed');
235
+ if (result.errors.length > 0) {
236
+ result.errors.forEach((error) => {
237
+ console.log(` Error: ${error}`);
238
+ });
239
+ }
240
+ }
241
+ db.close();
242
+ }
243
+ catch (error) {
244
+ logger.error('Linear sync failed', error);
245
+ console.error('āŒ Sync failed:', error.message);
246
+ process.exit(1);
247
+ }
248
+ });
249
+ // Auto-sync commands
250
+ linearCommand
251
+ .command('auto-sync')
252
+ .description('Manage automatic synchronization')
253
+ .option('--start', 'Start auto-sync service')
254
+ .option('--stop', 'Stop auto-sync service')
255
+ .option('--status', 'Show auto-sync status')
256
+ .option('--interval <minutes>', 'Set sync interval in minutes', '5')
257
+ .option('--direction <direction>', 'Set sync direction: bidirectional, to_linear, from_linear', 'bidirectional')
258
+ .option('--quiet-start <hour>', 'Start of quiet hours (0-23)', '22')
259
+ .option('--quiet-end <hour>', 'End of quiet hours (0-23)', '7')
260
+ .action(async (options) => {
261
+ try {
262
+ const projectRoot = process.cwd();
263
+ if (options.status) {
264
+ const service = getAutoSyncService();
265
+ if (service) {
266
+ const status = service.getStatus();
267
+ console.log('šŸ“Š Linear Auto-Sync Status:');
268
+ console.log(` Running: ${status.running ? 'āœ…' : 'āŒ'}`);
269
+ console.log(` Direction: ${status.config.direction}`);
270
+ console.log(` Interval: ${status.config.interval} minutes`);
271
+ console.log(` Conflict Resolution: ${status.config.conflictResolution}`);
272
+ if (status.lastSyncTime > 0) {
273
+ const lastSync = new Date(status.lastSyncTime);
274
+ console.log(` Last Sync: ${lastSync.toLocaleString()}`);
275
+ }
276
+ if (status.nextSyncTime) {
277
+ const nextSync = new Date(status.nextSyncTime);
278
+ console.log(` Next Sync: ${nextSync.toLocaleString()}`);
279
+ }
280
+ if (status.config.quietHours) {
281
+ console.log(` Quiet Hours: ${status.config.quietHours.start}:00 - ${status.config.quietHours.end}:00`);
282
+ }
283
+ if (status.retryCount > 0) {
284
+ console.log(` āš ļø Retry Count: ${status.retryCount}`);
285
+ }
286
+ }
287
+ else {
288
+ console.log('šŸ“Š Linear Auto-Sync Status: āŒ Not running');
289
+ }
290
+ return;
291
+ }
292
+ if (options.start) {
293
+ const authManager = new LinearAuthManager(projectRoot);
294
+ if (!authManager.isConfigured()) {
295
+ console.log('āŒ Linear not configured. Run "stackmemory linear setup" first.');
296
+ return;
297
+ }
298
+ const config = {
299
+ interval: parseInt(options.interval),
300
+ direction: options.direction,
301
+ quietHours: {
302
+ start: parseInt(options.quietStart),
303
+ end: parseInt(options.quietEnd),
304
+ },
305
+ };
306
+ const service = initializeAutoSync(projectRoot, config);
307
+ await service.start();
308
+ console.log('āœ… Linear auto-sync started');
309
+ console.log(` Interval: ${config.interval} minutes`);
310
+ console.log(` Direction: ${config.direction}`);
311
+ console.log(` Quiet Hours: ${config.quietHours.start}:00 - ${config.quietHours.end}:00`);
312
+ console.log('\nšŸ’” Use "stackmemory linear auto-sync --status" to check status');
313
+ // Keep process alive for auto-sync
314
+ process.on('SIGINT', () => {
315
+ console.log('\nšŸ›‘ Stopping auto-sync service...');
316
+ service.stop();
317
+ process.exit(0);
318
+ });
319
+ console.log('šŸ”„ Auto-sync running... Press Ctrl+C to stop');
320
+ // Keep the process running
321
+ await new Promise(() => { }); // Intentionally never resolves
322
+ }
323
+ if (options.stop) {
324
+ stopAutoSync();
325
+ console.log('šŸ›‘ Linear auto-sync stopped');
326
+ }
327
+ if (!options.start && !options.stop && !options.status) {
328
+ console.log('šŸ’” Usage:');
329
+ console.log(' --start Start auto-sync service');
330
+ console.log(' --stop Stop auto-sync service');
331
+ console.log(' --status Show current status');
332
+ console.log('\nExample: stackmemory linear auto-sync --start --interval 10');
333
+ }
334
+ }
335
+ catch (error) {
336
+ logger.error('Linear auto-sync command failed', error);
337
+ console.error('āŒ Auto-sync failed:', error.message);
338
+ process.exit(1);
339
+ }
340
+ });
341
+ linearCommand
342
+ .command('force-sync')
343
+ .description('Force immediate synchronization')
344
+ .action(async () => {
345
+ try {
346
+ const service = getAutoSyncService();
347
+ if (service) {
348
+ console.log('šŸ”„ Forcing immediate sync...');
349
+ await service.forceSync();
350
+ console.log('āœ… Sync completed');
351
+ }
352
+ else {
353
+ console.log('āŒ Auto-sync service not running. Use manual sync instead:');
354
+ console.log(' stackmemory linear sync');
355
+ }
356
+ }
357
+ catch (error) {
358
+ logger.error('Force sync failed', error);
359
+ console.error('āŒ Force sync failed:', error.message);
360
+ process.exit(1);
361
+ }
362
+ });
363
+ linearCommand
364
+ .command('config')
365
+ .description('Configure auto-sync settings')
366
+ .option('--show', 'Show current configuration')
367
+ .option('--set-interval <minutes>', 'Set sync interval in minutes')
368
+ .option('--set-direction <direction>', 'Set sync direction: bidirectional, to_linear, from_linear')
369
+ .option('--set-conflict-resolution <strategy>', 'Set conflict resolution: newest_wins, linear_wins, stackmemory_wins, manual')
370
+ .option('--set-quiet-start <hour>', 'Set start of quiet hours (0-23)')
371
+ .option('--set-quiet-end <hour>', 'Set end of quiet hours (0-23)')
372
+ .option('--enable', 'Enable auto-sync')
373
+ .option('--disable', 'Disable auto-sync')
374
+ .option('--reset', 'Reset to default configuration')
375
+ .action(async (options) => {
376
+ try {
377
+ const projectRoot = process.cwd();
378
+ const configManager = new LinearConfigManager(projectRoot);
379
+ if (options.reset) {
380
+ configManager.resetConfig();
381
+ console.log('āœ… Configuration reset to defaults');
382
+ return;
383
+ }
384
+ if (options.show) {
385
+ const config = configManager.loadConfig();
386
+ if (config) {
387
+ console.log('šŸ“Š Linear Auto-Sync Configuration:');
388
+ console.log(` Enabled: ${config.enabled ? 'āœ…' : 'āŒ'}`);
389
+ console.log(` Interval: ${config.interval} minutes`);
390
+ console.log(` Direction: ${config.direction}`);
391
+ console.log(` Conflict Resolution: ${config.conflictResolution}`);
392
+ console.log(` Retry Attempts: ${config.retryAttempts}`);
393
+ console.log(` Retry Delay: ${config.retryDelay / 1000}s`);
394
+ if (config.quietHours) {
395
+ console.log(` Quiet Hours: ${config.quietHours.start}:00 - ${config.quietHours.end}:00`);
396
+ }
397
+ const lastUpdated = new Date(config.lastUpdated);
398
+ console.log(` Last Updated: ${lastUpdated.toLocaleString()}`);
399
+ }
400
+ else {
401
+ console.log('šŸ“Š No configuration found. Using defaults.');
402
+ const defaultConfig = configManager.getDefaultConfig();
403
+ console.log(` Default interval: ${defaultConfig.interval} minutes`);
404
+ console.log(` Default direction: ${defaultConfig.direction}`);
405
+ }
406
+ return;
407
+ }
408
+ // Update configuration
409
+ const updates = {};
410
+ if (options.setInterval) {
411
+ const interval = parseInt(options.setInterval);
412
+ if (isNaN(interval) || interval < 1) {
413
+ console.error('āŒ Interval must be a positive number');
414
+ process.exit(1);
415
+ }
416
+ updates.interval = interval;
417
+ console.log(`āœ… Set interval to ${interval} minutes`);
418
+ }
419
+ if (options.setDirection) {
420
+ const validDirections = ['bidirectional', 'to_linear', 'from_linear'];
421
+ if (!validDirections.includes(options.setDirection)) {
422
+ console.error(`āŒ Invalid direction. Must be one of: ${validDirections.join(', ')}`);
423
+ process.exit(1);
424
+ }
425
+ updates.direction = options.setDirection;
426
+ console.log(`āœ… Set direction to ${options.setDirection}`);
427
+ }
428
+ if (options.setConflictResolution) {
429
+ const validStrategies = [
430
+ 'newest_wins',
431
+ 'linear_wins',
432
+ 'stackmemory_wins',
433
+ 'manual',
434
+ ];
435
+ if (!validStrategies.includes(options.setConflictResolution)) {
436
+ console.error(`āŒ Invalid strategy. Must be one of: ${validStrategies.join(', ')}`);
437
+ process.exit(1);
438
+ }
439
+ updates.conflictResolution = options.setConflictResolution;
440
+ console.log(`āœ… Set conflict resolution to ${options.setConflictResolution}`);
441
+ }
442
+ if (options.setQuietStart) {
443
+ const hour = parseInt(options.setQuietStart);
444
+ if (isNaN(hour) || hour < 0 || hour > 23) {
445
+ console.error('āŒ Quiet start hour must be between 0 and 23');
446
+ process.exit(1);
447
+ }
448
+ const currentConfig = configManager.loadConfig() || configManager.getDefaultConfig();
449
+ updates.quietHours = {
450
+ start: hour,
451
+ end: currentConfig.quietHours?.end || 7,
452
+ };
453
+ console.log(`āœ… Set quiet hours start to ${hour}:00`);
454
+ }
455
+ if (options.setQuietEnd) {
456
+ const hour = parseInt(options.setQuietEnd);
457
+ if (isNaN(hour) || hour < 0 || hour > 23) {
458
+ console.error('āŒ Quiet end hour must be between 0 and 23');
459
+ process.exit(1);
460
+ }
461
+ const currentConfig = configManager.loadConfig() || configManager.getDefaultConfig();
462
+ updates.quietHours = {
463
+ start: currentConfig.quietHours?.start || 22,
464
+ end: hour,
465
+ };
466
+ console.log(`āœ… Set quiet hours end to ${hour}:00`);
467
+ }
468
+ if (options.enable) {
469
+ updates.enabled = true;
470
+ console.log('āœ… Auto-sync enabled');
471
+ }
472
+ if (options.disable) {
473
+ updates.enabled = false;
474
+ console.log('āŒ Auto-sync disabled');
475
+ }
476
+ if (Object.keys(updates).length > 0) {
477
+ configManager.saveConfig(updates);
478
+ console.log('\nšŸ’” Configuration updated. Restart auto-sync service to apply changes.');
479
+ }
480
+ else if (!options.show) {
481
+ console.log('šŸ’” Use --show to view current configuration');
482
+ console.log('šŸ’” Use --help to see all configuration options');
483
+ }
484
+ }
485
+ catch (error) {
486
+ logger.error('Linear config command failed', error);
487
+ console.error('āŒ Config failed:', error.message);
488
+ process.exit(1);
489
+ }
490
+ });
491
+ program
492
+ .command('update-check')
493
+ .description('Check for StackMemory updates')
494
+ .action(async () => {
495
+ try {
496
+ console.log('šŸ” Checking for updates...');
497
+ await UpdateChecker.forceCheck(VERSION);
498
+ }
499
+ catch (error) {
500
+ logger.error('Update check failed', error);
501
+ console.error('āŒ Update check failed:', error.message);
502
+ process.exit(1);
503
+ }
504
+ });
505
+ program
506
+ .command('analytics')
507
+ .description('Launch task analytics dashboard')
508
+ .option('-p, --port <port>', 'Port for dashboard server', '3000')
509
+ .option('-o, --open', 'Open dashboard in browser')
510
+ .option('--export <format>', 'Export metrics (json|csv)')
511
+ .option('--sync', 'Sync with Linear before launching')
512
+ .option('--view', 'Show analytics in terminal')
513
+ .action(async (options) => {
514
+ try {
515
+ const projectRoot = process.cwd();
516
+ const dbPath = join(projectRoot, '.stackmemory', 'context.db');
517
+ if (!existsSync(dbPath)) {
518
+ console.log('āŒ StackMemory not initialized. Run "stackmemory init" first.');
519
+ return;
520
+ }
521
+ if (options.view) {
522
+ const { displayAnalyticsDashboard } = await import('./utils/viewer.js');
523
+ await displayAnalyticsDashboard(projectRoot);
524
+ return;
525
+ }
526
+ if (options.export) {
527
+ const { AnalyticsService } = await import('../features/analytics/index.js');
528
+ const service = new AnalyticsService(projectRoot);
529
+ if (options.sync) {
530
+ console.log('šŸ”„ Syncing with Linear...');
531
+ await service.syncLinearTasks();
532
+ }
533
+ const state = await service.getDashboardState();
534
+ if (options.export === 'csv') {
535
+ console.log('šŸ“Š Exporting metrics as CSV...');
536
+ // Convert to CSV format
537
+ const tasks = state.recentTasks;
538
+ const headers = [
539
+ 'ID',
540
+ 'Title',
541
+ 'State',
542
+ 'Priority',
543
+ 'Created',
544
+ 'Completed',
545
+ ];
546
+ const rows = tasks.map((t) => [
547
+ t.id,
548
+ t.title,
549
+ t.state,
550
+ t.priority,
551
+ t.createdAt.toISOString(),
552
+ t.completedAt?.toISOString() || '',
553
+ ]);
554
+ console.log(headers.join(','));
555
+ rows.forEach((r) => console.log(r.join(',')));
556
+ }
557
+ else {
558
+ console.log(JSON.stringify(state, null, 2));
559
+ }
560
+ service.close();
561
+ return;
562
+ }
563
+ // Launch dashboard server
564
+ console.log(`šŸš€ Launching analytics dashboard on port ${options.port}...`);
565
+ const express = (await import('express')).default;
566
+ const { AnalyticsAPI } = await import('../features/analytics/index.js');
567
+ const { createServer } = await import('http');
568
+ const app = express();
569
+ const analyticsAPI = new AnalyticsAPI(projectRoot);
570
+ if (options.sync) {
571
+ console.log('šŸ”„ Syncing with Linear...');
572
+ const service = new (await import('../features/analytics/index.js')).AnalyticsService(projectRoot);
573
+ await service.syncLinearTasks();
574
+ service.close();
575
+ }
576
+ app.use('/api/analytics', analyticsAPI.getRouter());
577
+ // Serve the HTML dashboard
578
+ app.get('/', async (req, res) => {
579
+ const { fileURLToPath } = await import('url');
580
+ const { dirname } = await import('path');
581
+ const __filename = fileURLToPath(import.meta.url);
582
+ const __dirname = dirname(__filename);
583
+ const dashboardPath = join(__dirname, '../analytics/dashboard.html');
584
+ if (existsSync(dashboardPath)) {
585
+ res.sendFile(dashboardPath);
586
+ }
587
+ else {
588
+ // Fallback to inline HTML if file not found
589
+ const { existsSync: fsExists } = await import('fs');
590
+ const { join: pathJoin } = await import('path');
591
+ const htmlPath = pathJoin(__dirname, '../analytics/dashboard.html');
592
+ if (fsExists(htmlPath)) {
593
+ res.sendFile(htmlPath);
594
+ }
595
+ else {
596
+ res.send(`
597
+ <!DOCTYPE html>
598
+ <html>
599
+ <head>
600
+ <title>StackMemory Analytics</title>
601
+ <style>
602
+ body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; padding: 20px; }
603
+ h1 { color: #333; }
604
+ .status { color: #22c55e; }
605
+ </style>
606
+ </head>
607
+ <body>
608
+ <h1>šŸ“Š StackMemory Analytics Dashboard</h1>
609
+ <p class="status">āœ… Server running</p>
610
+ <p>Dashboard available at: /src/analytics/dashboard.html</p>
611
+ <p>API Endpoints:</p>
612
+ <ul>
613
+ <li>GET /api/analytics/metrics</li>
614
+ <li>GET /api/analytics/tasks</li>
615
+ <li>POST /api/analytics/sync</li>
616
+ </ul>
617
+ </body>
618
+ </html>
619
+ `);
620
+ }
621
+ }
622
+ });
623
+ const server = createServer(app);
624
+ analyticsAPI.setupWebSocket(server);
625
+ server.listen(options.port, async () => {
626
+ console.log(`āœ… Analytics dashboard running at http://localhost:${options.port}`);
627
+ if (options.open) {
628
+ const { exec } = await import('child_process');
629
+ const url = `http://localhost:${options.port}`;
630
+ const command = process.platform === 'darwin'
631
+ ? `open ${url}`
632
+ : process.platform === 'win32'
633
+ ? `start ${url}`
634
+ : `xdg-open ${url}`;
635
+ exec(command);
636
+ }
637
+ });
638
+ process.on('SIGINT', () => {
639
+ console.log('\nšŸ‘‹ Shutting down analytics dashboard...');
640
+ analyticsAPI.close();
641
+ server.close();
642
+ process.exit(0);
643
+ });
644
+ }
645
+ catch (error) {
646
+ logger.error('Analytics command failed', error);
647
+ console.error('āŒ Analytics failed:', error.message);
648
+ process.exit(1);
649
+ }
650
+ });
651
+ program
652
+ .command('progress')
653
+ .description('Show current progress and recent changes')
654
+ .action(async () => {
655
+ try {
656
+ const projectRoot = process.cwd();
657
+ const dbPath = join(projectRoot, '.stackmemory', 'context.db');
658
+ if (!existsSync(dbPath)) {
659
+ console.log('āŒ StackMemory not initialized. Run "stackmemory init" first.');
660
+ return;
661
+ }
662
+ const progress = new ProgressTracker(projectRoot);
663
+ console.log(progress.getSummary());
664
+ }
665
+ catch (error) {
666
+ logger.error('Failed to show progress', error);
667
+ console.error('āŒ Failed to show progress:', error.message);
668
+ process.exit(1);
669
+ }
670
+ });
671
+ program
672
+ .command('mcp-server')
673
+ .description('Start StackMemory MCP server for Claude Desktop')
674
+ .option('-p, --project <path>', 'Project root directory', process.cwd())
675
+ .action(async (options) => {
676
+ try {
677
+ const { runMCPServer } = await import('../integrations/mcp/server.js');
678
+ // Set project root
679
+ process.env.PROJECT_ROOT = options.project;
680
+ console.log('šŸš€ Starting StackMemory MCP Server...');
681
+ console.log(` Project: ${options.project}`);
682
+ console.log(` Version: ${VERSION}`);
683
+ // Check for updates silently
684
+ UpdateChecker.checkForUpdates(VERSION, true).catch(() => { });
685
+ // Start the MCP server
686
+ await runMCPServer();
687
+ }
688
+ catch (error) {
689
+ logger.error('Failed to start MCP server', error);
690
+ console.error('āŒ MCP server failed:', error.message);
691
+ process.exit(1);
692
+ }
693
+ });
694
+ // Register project management commands
695
+ registerProjectCommands(program);
696
+ // Auto-detect current project on startup
697
+ if (process.argv.length > 2) {
698
+ const manager = ProjectManager.getInstance();
699
+ manager.detectProject().catch(() => {
700
+ // Silently fail if not in a project directory
701
+ });
702
+ }
703
+ program.parse();
704
+ //# sourceMappingURL=index.js.map