@stackmemoryai/stackmemory 0.5.55 → 0.5.57

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.
@@ -65,11 +65,11 @@ function createCaptureCommand() {
65
65
  try {
66
66
  gitStatus = execSync("git status --short", {
67
67
  encoding: "utf-8",
68
- cwd: projectRoot
68
+ cwd: projectRoot,
69
+ stdio: ["pipe", "pipe", "pipe"]
69
70
  });
70
71
  hasChanges = gitStatus.trim().length > 0;
71
72
  } catch {
72
- console.log("\u26A0\uFE0F Not in a git repository");
73
73
  }
74
74
  if (hasChanges && options.commit !== false) {
75
75
  try {
@@ -178,11 +178,13 @@ function createCaptureCommand() {
178
178
  try {
179
179
  const branch2 = execSync("git rev-parse --abbrev-ref HEAD", {
180
180
  encoding: "utf-8",
181
- cwd: projectRoot
181
+ cwd: projectRoot,
182
+ stdio: ["pipe", "pipe", "pipe"]
182
183
  }).trim();
183
184
  const lastCommit = execSync("git log -1 --oneline", {
184
185
  encoding: "utf-8",
185
- cwd: projectRoot
186
+ cwd: projectRoot,
187
+ stdio: ["pipe", "pipe", "pipe"]
186
188
  }).trim();
187
189
  gitInfo = `
188
190
  Git Status:
@@ -247,7 +249,8 @@ Generated by stackmemory capture at ${timestamp}
247
249
  try {
248
250
  branch = execSync("git rev-parse --abbrev-ref HEAD", {
249
251
  encoding: "utf-8",
250
- cwd: projectRoot
252
+ cwd: projectRoot,
253
+ stdio: ["pipe", "pipe", "pipe"]
251
254
  }).trim();
252
255
  } catch {
253
256
  }
@@ -333,10 +336,11 @@ function createRestoreCommand() {
333
336
  }
334
337
  try {
335
338
  const gitStatus = execSync("git status --short", {
336
- encoding: "utf-8"
339
+ encoding: "utf-8",
340
+ stdio: ["pipe", "pipe", "pipe"]
337
341
  }).trim();
338
342
  if (gitStatus) {
339
- console.log("\n\u26A0\uFE0F Current uncommitted changes:");
343
+ console.log("\n Current uncommitted changes:");
340
344
  console.log(gitStatus);
341
345
  }
342
346
  } catch {
@@ -423,7 +427,8 @@ async function captureHandoff(reason, exitCode, wrappedCommand, sessionStart, qu
423
427
  try {
424
428
  const gitStatus = execSync("git status --short", {
425
429
  encoding: "utf-8",
426
- cwd: projectRoot
430
+ cwd: projectRoot,
431
+ stdio: ["pipe", "pipe", "pipe"]
427
432
  }).trim();
428
433
  if (gitStatus) {
429
434
  console.log("\nYou have uncommitted changes");
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/cli/commands/handoff.ts"],
4
- "sourcesContent": ["/**\n * Handoff command - Commits work and generates a prompt for the next session\n */\n\nimport { Command } from 'commander';\nimport { execSync, execFileSync, spawn, ChildProcess } from 'child_process';\nimport {\n existsSync,\n readFileSync,\n writeFileSync,\n mkdirSync,\n readdirSync,\n unlinkSync,\n} from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport Database from 'better-sqlite3';\nimport { z } from 'zod';\nimport { FrameManager } from '../../core/context/index.js';\nimport { LinearTaskManager } from '../../features/tasks/linear-task-manager.js';\nimport { logger } from '../../core/monitoring/logger.js';\nimport { EnhancedHandoffGenerator } from '../../core/session/enhanced-handoff.js';\n\n// Handoff versioning - keep last N handoffs\nconst MAX_HANDOFF_VERSIONS = 10;\n\nfunction saveVersionedHandoff(\n projectRoot: string,\n branch: string,\n content: string\n): string {\n const handoffsDir = join(projectRoot, '.stackmemory', 'handoffs');\n if (!existsSync(handoffsDir)) {\n mkdirSync(handoffsDir, { recursive: true });\n }\n\n // Generate versioned filename: YYYY-MM-DD-HH-mm-branch.md\n const now = new Date();\n const timestamp = now.toISOString().slice(0, 16).replace(/[T:]/g, '-');\n const safeBranch = branch.replace(/[^a-zA-Z0-9-]/g, '-').slice(0, 30);\n const filename = `${timestamp}-${safeBranch}.md`;\n const versionedPath = join(handoffsDir, filename);\n\n // Save versioned handoff\n writeFileSync(versionedPath, content);\n\n // Clean up old handoffs (keep last N)\n try {\n const files = readdirSync(handoffsDir)\n .filter((f) => f.endsWith('.md'))\n .sort()\n .reverse();\n\n for (const oldFile of files.slice(MAX_HANDOFF_VERSIONS)) {\n unlinkSync(join(handoffsDir, oldFile));\n }\n } catch {\n // Cleanup failed, not critical\n }\n\n return versionedPath;\n}\n\n// Input validation schemas\nconst CommitMessageSchema = z\n .string()\n .min(1, 'Commit message cannot be empty')\n .max(200, 'Commit message too long')\n .regex(\n /^[a-zA-Z0-9\\s\\-_.,:()\\/\\[\\]]+$/,\n 'Commit message contains invalid characters'\n )\n .refine(\n (msg) => !msg.includes('\\n'),\n 'Commit message cannot contain newlines'\n )\n .refine(\n (msg) => !msg.includes('\"'),\n 'Commit message cannot contain double quotes'\n )\n .refine(\n (msg) => !msg.includes('`'),\n 'Commit message cannot contain backticks'\n );\n\nexport function createCaptureCommand(): Command {\n const cmd = new Command('capture');\n\n cmd\n .description('Commit current work and generate a handoff prompt')\n .option('-m, --message <message>', 'Custom commit message')\n .option('--no-commit', 'Skip git commit')\n .option('--copy', 'Copy the handoff prompt to clipboard')\n .option('--basic', 'Use basic handoff format instead of enhanced')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n // 1. Check git status\n let gitStatus = '';\n let hasChanges = false;\n\n try {\n gitStatus = execSync('git status --short', {\n encoding: 'utf-8',\n cwd: projectRoot,\n });\n hasChanges = gitStatus.trim().length > 0;\n } catch {\n console.log('\u26A0\uFE0F Not in a git repository');\n }\n\n // 2. Commit if there are changes and not skipped\n if (hasChanges && options.commit !== false) {\n try {\n // Get current branch\n const currentBranch = execSync('git rev-parse --abbrev-ref HEAD', {\n encoding: 'utf-8',\n cwd: projectRoot,\n }).trim();\n\n // Stage all changes\n execSync('git add -A', { cwd: projectRoot });\n\n // Generate or use custom commit message\n let commitMessage =\n options.message ||\n `chore: handoff checkpoint on ${currentBranch}`;\n\n // Validate commit message\n try {\n commitMessage = CommitMessageSchema.parse(commitMessage);\n } catch (validationError) {\n console.error(\n '\u274C Invalid commit message:',\n (validationError as Error).message\n );\n return;\n }\n\n // Commit using execFileSync for safety\n execFileSync('git', ['commit', '-m', commitMessage], {\n cwd: projectRoot,\n stdio: 'inherit',\n });\n\n console.log(`\u2705 Committed changes: \"${commitMessage}\"`);\n console.log(` Branch: ${currentBranch}`);\n } catch (err: unknown) {\n console.error(\n '\u274C Failed to commit changes:',\n (err as Error).message\n );\n }\n } else if (!hasChanges) {\n console.log('\u2139\uFE0F No changes to commit');\n }\n\n // 3. Gather context for handoff prompt\n let contextSummary = '';\n let tasksSummary = '';\n let recentWork = '';\n\n if (existsSync(dbPath)) {\n const db = new Database(dbPath);\n\n // Get recent context\n const frameManager = new FrameManager(db, 'cli-project');\n const activeFrames = frameManager.getActiveFramePath();\n\n if (activeFrames.length > 0) {\n contextSummary = 'Active context frames:\\n';\n activeFrames.forEach((frame) => {\n contextSummary += ` - ${frame.name} [${frame.type}]\\n`;\n });\n }\n\n // Get task status\n const taskStore = new LinearTaskManager(projectRoot, db);\n const activeTasks = taskStore.getActiveTasks();\n\n const inProgress = activeTasks.filter(\n (t: any) => t.status === 'in_progress'\n );\n const todo = activeTasks.filter((t: any) => t.status === 'pending');\n const recentlyCompleted = activeTasks\n .filter((t: any) => t.status === 'completed' && t.completed_at)\n .sort(\n (a: any, b: any) => (b.completed_at || 0) - (a.completed_at || 0)\n )\n .slice(0, 3);\n\n if (inProgress.length > 0 || todo.length > 0) {\n tasksSummary = '\\nTasks:\\n';\n\n if (inProgress.length > 0) {\n tasksSummary += 'In Progress:\\n';\n inProgress.forEach((t: any) => {\n const externalId = t.external_refs?.linear?.id;\n tasksSummary += ` - ${t.title}${externalId ? ` [${externalId}]` : ''}\\n`;\n });\n }\n\n if (todo.length > 0) {\n tasksSummary += 'TODO:\\n';\n todo.slice(0, 5).forEach((t: any) => {\n const externalId = t.external_refs?.linear?.id;\n tasksSummary += ` - ${t.title}${externalId ? ` [${externalId}]` : ''}\\n`;\n });\n if (todo.length > 5) {\n tasksSummary += ` ... and ${todo.length - 5} more\\n`;\n }\n }\n }\n\n if (recentlyCompleted.length > 0) {\n recentWork = '\\nRecently Completed:\\n';\n recentlyCompleted.forEach((t: any) => {\n recentWork += ` \u2713 ${t.title}\\n`;\n });\n }\n\n // Get recent events\n const recentEvents = db\n .prepare(\n `\n SELECT event_type as type, payload as data, datetime(ts, 'unixepoch') as time\n FROM events\n ORDER BY ts DESC\n LIMIT 5\n `\n )\n .all() as any[];\n\n if (recentEvents.length > 0) {\n recentWork += '\\nRecent Activity:\\n';\n recentEvents.forEach((event) => {\n const data = JSON.parse(event.data);\n recentWork += ` - ${event.type}: ${data.message || data.name || 'activity'}\\n`;\n });\n }\n\n db.close();\n }\n\n // 4. Get current git info\n let gitInfo = '';\n try {\n const branch = execSync('git rev-parse --abbrev-ref HEAD', {\n encoding: 'utf-8',\n cwd: projectRoot,\n }).trim();\n\n const lastCommit = execSync('git log -1 --oneline', {\n encoding: 'utf-8',\n cwd: projectRoot,\n }).trim();\n\n gitInfo = `\\nGit Status:\\n Branch: ${branch}\\n Last commit: ${lastCommit}\\n`;\n } catch {\n // Ignore git errors\n }\n\n // 5. Check for any blockers or notes\n let notes = '';\n const notesPath = join(projectRoot, '.stackmemory', 'handoff.md');\n if (existsSync(notesPath)) {\n const handoffNotes = readFileSync(notesPath, 'utf-8');\n if (handoffNotes.trim()) {\n notes = `\\nNotes from previous handoff:\\n${handoffNotes}\\n`;\n }\n }\n\n // 6. Generate the handoff prompt\n let handoffPrompt: string;\n\n if (options.basic) {\n // Use basic handoff format\n const timestamp = new Date().toISOString();\n handoffPrompt = `# Session Handoff - ${timestamp}\n\n## Project: ${projectRoot.split('/').pop()}\n\n${gitInfo}\n${contextSummary}\n${tasksSummary}\n${recentWork}\n${notes}\n\n## Continue from here:\n\n1. Run \\`stackmemory status\\` to check the current state\n2. Review any in-progress tasks above\n3. Check for any uncommitted changes with \\`git status\\`\n4. Resume work on the active context\n\n## Quick Commands:\n- \\`stackmemory context load --recent\\` - Load recent context\n- \\`stackmemory task list --state in_progress\\` - Show in-progress tasks\n- \\`stackmemory linear sync\\` - Sync with Linear if configured\n- \\`stackmemory log recent\\` - View recent activity\n\n---\nGenerated by stackmemory capture at ${timestamp}\n`;\n } else {\n // Use high-efficacy enhanced handoff generator (default)\n const enhancedGenerator = new EnhancedHandoffGenerator(projectRoot);\n const enhancedHandoff = await enhancedGenerator.generate();\n handoffPrompt = enhancedGenerator.toMarkdown(enhancedHandoff);\n console.log(`Estimated tokens: ~${enhancedHandoff.estimatedTokens}`);\n }\n\n // 7. Save handoff prompt (both latest and versioned)\n const stackmemoryDir = join(projectRoot, '.stackmemory');\n if (!existsSync(stackmemoryDir)) {\n mkdirSync(stackmemoryDir, { recursive: true });\n }\n const handoffPath = join(stackmemoryDir, 'last-handoff.md');\n writeFileSync(handoffPath, handoffPrompt);\n\n // Save versioned copy\n let branch = 'unknown';\n try {\n branch = execSync('git rev-parse --abbrev-ref HEAD', {\n encoding: 'utf-8',\n cwd: projectRoot,\n }).trim();\n } catch {\n // Not a git repo\n }\n const versionedPath = saveVersionedHandoff(\n projectRoot,\n branch,\n handoffPrompt\n );\n console.log(\n `Versioned: ${versionedPath.split('/').slice(-2).join('/')}`\n );\n\n // 8. Display the prompt\n console.log('\\n' + '='.repeat(60));\n console.log(handoffPrompt);\n console.log('='.repeat(60));\n\n // 9. Copy to clipboard if requested\n if (options.copy) {\n try {\n // Use execFileSync with predefined commands for safety\n if (process.platform === 'darwin') {\n execFileSync('pbcopy', [], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n } else if (process.platform === 'win32') {\n execFileSync('clip', [], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n } else {\n execFileSync('xclip', ['-selection', 'clipboard'], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n }\n\n console.log('\\n\u2705 Handoff prompt copied to clipboard!');\n } catch {\n console.log('\\n\u26A0\uFE0F Could not copy to clipboard');\n }\n }\n\n console.log(`\\n\uD83D\uDCBE Handoff saved to: ${handoffPath}`);\n console.log('\uD83D\uDCCB Use this prompt when starting your next session');\n } catch (error: unknown) {\n logger.error('Capture command failed', error as Error);\n console.error('\u274C Capture failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n return cmd;\n}\n\nexport function createRestoreCommand(): Command {\n const cmd = new Command('restore');\n\n cmd\n .description('Restore context from last handoff')\n .option('--no-copy', 'Do not copy prompt to clipboard')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const handoffPath = join(\n projectRoot,\n '.stackmemory',\n 'last-handoff.md'\n );\n const metaPath = join(\n process.env['HOME'] || '~',\n '.stackmemory',\n 'handoffs',\n 'last-handoff-meta.json'\n );\n\n if (!existsSync(handoffPath)) {\n console.log('\u274C No handoff found in this project');\n console.log('\uD83D\uDCA1 Run \"stackmemory capture\" to create one');\n return;\n }\n\n // Read handoff prompt\n const handoffPrompt = readFileSync(handoffPath, 'utf-8');\n\n // Display the prompt\n console.log('\\n' + '='.repeat(60));\n console.log('\uD83D\uDCCB RESTORED HANDOFF');\n console.log('='.repeat(60));\n console.log(handoffPrompt);\n console.log('='.repeat(60));\n\n // Check for metadata\n if (existsSync(metaPath)) {\n const metadata = JSON.parse(readFileSync(metaPath, 'utf-8'));\n console.log('\\n\uD83D\uDCCA Session Metadata:');\n console.log(` Timestamp: ${metadata.timestamp}`);\n console.log(` Reason: ${metadata.reason}`);\n console.log(` Duration: ${metadata.session_duration}s`);\n console.log(` Command: ${metadata.command}`);\n }\n\n // Check current git status\n try {\n const gitStatus = execSync('git status --short', {\n encoding: 'utf-8',\n }).trim();\n if (gitStatus) {\n console.log('\\n\u26A0\uFE0F Current uncommitted changes:');\n console.log(gitStatus);\n }\n } catch {\n // Not a git repo\n }\n\n // Copy to clipboard unless disabled\n if (options.copy !== false) {\n try {\n // Use execFileSync with predefined commands for safety\n if (process.platform === 'darwin') {\n execFileSync('pbcopy', [], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n } else if (process.platform === 'win32') {\n execFileSync('clip', [], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n } else {\n execFileSync('xclip', ['-selection', 'clipboard'], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n }\n\n console.log('\\n\u2705 Handoff prompt copied to clipboard!');\n } catch {\n console.log('\\n\u26A0\uFE0F Could not copy to clipboard');\n }\n }\n\n console.log('\\n\uD83D\uDE80 Ready to continue where you left off!');\n } catch (error: unknown) {\n logger.error('Restore failed', error as Error);\n console.error('\u274C Restore failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n return cmd;\n}\n\ninterface AutoCaptureMetadata {\n timestamp: string;\n reason: string;\n exit_code: number;\n command: string;\n pid: number;\n cwd: string;\n user: string;\n session_duration: number;\n}\n\nasync function captureHandoff(\n reason: string,\n exitCode: number,\n wrappedCommand: string,\n sessionStart: number,\n quiet: boolean\n): Promise<void> {\n const projectRoot = process.cwd();\n const handoffDir = join(homedir(), '.stackmemory', 'handoffs');\n const logFile = join(handoffDir, 'auto-handoff.log');\n\n // Ensure handoff directory exists\n if (!existsSync(handoffDir)) {\n mkdirSync(handoffDir, { recursive: true });\n }\n\n const logMessage = (msg: string): void => {\n const timestamp = new Date().toISOString().slice(0, 19).replace('T', ' ');\n const logLine = `[${timestamp}] ${msg}\\n`;\n try {\n writeFileSync(logFile, logLine, { flag: 'a' });\n } catch {\n // Logging failed, continue anyway\n }\n };\n\n if (!quiet) {\n console.log('\\nCapturing handoff context...');\n }\n logMessage(`Capturing handoff: reason=${reason}, exit_code=${exitCode}`);\n\n try {\n // Run stackmemory capture --no-commit\n execFileSync(\n process.execPath,\n [process.argv[1], 'capture', '--no-commit'],\n {\n cwd: projectRoot,\n stdio: quiet ? 'pipe' : 'inherit',\n }\n );\n\n // Save metadata\n const metadata: AutoCaptureMetadata = {\n timestamp: new Date().toISOString(),\n reason,\n exit_code: exitCode,\n command: wrappedCommand,\n pid: process.pid,\n cwd: projectRoot,\n user: process.env['USER'] || 'unknown',\n session_duration: Math.floor((Date.now() - sessionStart) / 1000),\n };\n\n const metadataPath = join(handoffDir, 'last-handoff-meta.json');\n writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));\n\n if (!quiet) {\n console.log('Handoff captured successfully');\n logMessage(`Handoff captured: ${metadataPath}`);\n\n // Show session summary\n console.log('\\nSession Summary:');\n console.log(` Duration: ${metadata.session_duration} seconds`);\n console.log(` Exit reason: ${reason}`);\n\n // Check for uncommitted changes\n try {\n const gitStatus = execSync('git status --short', {\n encoding: 'utf-8',\n cwd: projectRoot,\n }).trim();\n if (gitStatus) {\n console.log('\\nYou have uncommitted changes');\n console.log(' Run \"git status\" to review');\n }\n } catch {\n // Not a git repo or git not available\n }\n\n console.log('\\nRun \"stackmemory restore\" in your next session');\n }\n } catch (err) {\n if (!quiet) {\n console.error('Failed to capture handoff:', (err as Error).message);\n }\n logMessage(`ERROR: ${(err as Error).message}`);\n }\n}\n\nexport function createAutoCaptureCommand(): Command {\n const cmd = new Command('auto-capture');\n\n cmd\n .description('Wrap a command with automatic handoff capture on termination')\n .option('-a, --auto', 'Auto-capture on normal exit (no prompt)')\n .option('-q, --quiet', 'Suppress output')\n .option('-t, --tag <tag>', 'Tag this session')\n .argument('[command...]', 'Command to wrap with auto-handoff')\n .action(async (commandArgs: string[], options) => {\n const autoCapture = options.auto || false;\n const quiet = options.quiet || false;\n const tag = options.tag || '';\n\n // If no command provided, show usage\n if (!commandArgs || commandArgs.length === 0) {\n console.log('StackMemory Auto-Handoff');\n console.log('-'.repeat(50));\n console.log('');\n console.log(\n 'Wraps a command with automatic handoff capture on termination.'\n );\n console.log('');\n console.log('Usage:');\n console.log(' stackmemory auto-capture [options] <command> [args...]');\n console.log('');\n console.log('Examples:');\n console.log(' stackmemory auto-capture claude');\n console.log(' stackmemory auto-capture -a npm run dev');\n console.log(' stackmemory auto-capture -t \"feature-work\" vim');\n console.log('');\n console.log('Options:');\n console.log(\n ' -a, --auto Auto-capture on normal exit (no prompt)'\n );\n console.log(' -q, --quiet Suppress output');\n console.log(' -t, --tag <tag> Tag this session');\n return;\n }\n\n const wrappedCommand = commandArgs.join(' ');\n const sessionStart = Date.now();\n let capturedAlready = false;\n\n if (!quiet) {\n console.log('StackMemory Auto-Handoff Wrapper');\n console.log(`Wrapping: ${wrappedCommand}`);\n if (tag) {\n console.log(`Tag: ${tag}`);\n }\n console.log('Handoff will be captured on termination');\n console.log('');\n }\n\n // Spawn the wrapped command\n const [cmd, ...args] = commandArgs;\n let childProcess: ChildProcess;\n\n try {\n childProcess = spawn(cmd, args, {\n stdio: 'inherit',\n shell: false,\n cwd: process.cwd(),\n env: process.env,\n });\n } catch (err) {\n console.error(`Failed to start command: ${(err as Error).message}`);\n process.exit(1);\n return;\n }\n\n // Handle signals - forward to child and capture on termination\n const handleSignal = async (\n signal: NodeJS.Signals,\n exitCode: number\n ): Promise<void> => {\n if (capturedAlready) return;\n capturedAlready = true;\n\n if (!quiet) {\n console.log(`\\nReceived ${signal}`);\n }\n\n // Kill the child process if still running\n if (childProcess.pid && !childProcess.killed) {\n childProcess.kill(signal);\n }\n\n await captureHandoff(\n signal,\n exitCode,\n wrappedCommand,\n sessionStart,\n quiet\n );\n process.exit(exitCode);\n };\n\n process.on('SIGINT', () => handleSignal('SIGINT', 130));\n process.on('SIGTERM', () => handleSignal('SIGTERM', 143));\n process.on('SIGHUP', () => handleSignal('SIGHUP', 129));\n\n // Handle child process exit\n childProcess.on('exit', async (code, signal) => {\n if (capturedAlready) return;\n capturedAlready = true;\n\n const exitCode = code ?? (signal ? 128 : 0);\n\n if (signal) {\n // Child was killed by a signal\n await captureHandoff(\n signal,\n exitCode,\n wrappedCommand,\n sessionStart,\n quiet\n );\n } else if (exitCode !== 0) {\n // Unexpected exit\n if (!quiet) {\n console.log(`\\nCommand exited with code: ${exitCode}`);\n }\n await captureHandoff(\n 'unexpected_exit',\n exitCode,\n wrappedCommand,\n sessionStart,\n quiet\n );\n } else if (autoCapture) {\n // Normal exit with auto-capture enabled\n await captureHandoff(\n 'normal_exit',\n 0,\n wrappedCommand,\n sessionStart,\n quiet\n );\n } else {\n // Normal exit - prompt for capture (simplified for CLI, auto-capture)\n // In non-interactive contexts, default to capturing\n if (process.stdin.isTTY) {\n // Interactive - we could prompt but keeping it simple\n console.log(\n '\\nSession ending. Use -a flag for auto-capture on normal exit.'\n );\n }\n }\n\n process.exit(exitCode);\n });\n\n // Handle spawn errors\n childProcess.on('error', async (err) => {\n if (capturedAlready) return;\n capturedAlready = true;\n\n console.error(`Command error: ${err.message}`);\n await captureHandoff(\n 'spawn_error',\n 1,\n wrappedCommand,\n sessionStart,\n quiet\n );\n process.exit(1);\n });\n });\n\n return cmd;\n}\n\n/** @deprecated Use createCaptureCommand, createRestoreCommand, createAutoCaptureCommand */\nexport function createHandoffCommand(): Command {\n const cmd = new Command('handoff');\n cmd.description('(deprecated) Use \"capture\" or \"restore\" instead');\n return cmd;\n}\n"],
5
- "mappings": ";;;;AAIA,SAAS,eAAe;AACxB,SAAS,UAAU,cAAc,aAA2B;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,OAAO,cAAc;AACrB,SAAS,SAAS;AAClB,SAAS,oBAAoB;AAC7B,SAAS,yBAAyB;AAClC,SAAS,cAAc;AACvB,SAAS,gCAAgC;AAGzC,MAAM,uBAAuB;AAE7B,SAAS,qBACP,aACA,QACA,SACQ;AACR,QAAM,cAAc,KAAK,aAAa,gBAAgB,UAAU;AAChE,MAAI,CAAC,WAAW,WAAW,GAAG;AAC5B,cAAU,aAAa,EAAE,WAAW,KAAK,CAAC;AAAA,EAC5C;AAGA,QAAM,MAAM,oBAAI,KAAK;AACrB,QAAM,YAAY,IAAI,YAAY,EAAE,MAAM,GAAG,EAAE,EAAE,QAAQ,SAAS,GAAG;AACrE,QAAM,aAAa,OAAO,QAAQ,kBAAkB,GAAG,EAAE,MAAM,GAAG,EAAE;AACpE,QAAM,WAAW,GA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EAAE;AAAA,QACvD;AACA,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,WAAW,aAAa;AAEtB,cAAM;AAAA,UACJ;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF,OAAO;AAGL,YAAI,QAAQ,MAAM,OAAO;AAEvB,kBAAQ;AAAA,YACN;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAEA,cAAQ,KAAK,QAAQ;AAAA,IACvB,CAAC;AAGD,iBAAa,GAAG,SAAS,OAAO,QAAQ;AACtC,UAAI,gBAAiB;AACrB,wBAAkB;AAElB,cAAQ,MAAM,kBAAkB,IAAI,OAAO,EAAE;AAC7C,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB,CAAC;AAAA,EACH,CAAC;AAEH,SAAO;AACT;AAGO,SAAS,uBAAgC;AAC9C,QAAM,MAAM,IAAI,QAAQ,SAAS;AACjC,MAAI,YAAY,iDAAiD;AACjE,SAAO;AACT;",
4
+ "sourcesContent": ["/**\n * Handoff command - Commits work and generates a prompt for the next session\n */\n\nimport { Command } from 'commander';\nimport { execSync, execFileSync, spawn, ChildProcess } from 'child_process';\nimport {\n existsSync,\n readFileSync,\n writeFileSync,\n mkdirSync,\n readdirSync,\n unlinkSync,\n} from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport Database from 'better-sqlite3';\nimport { z } from 'zod';\nimport { FrameManager } from '../../core/context/index.js';\nimport { LinearTaskManager } from '../../features/tasks/linear-task-manager.js';\nimport { logger } from '../../core/monitoring/logger.js';\nimport { EnhancedHandoffGenerator } from '../../core/session/enhanced-handoff.js';\n\n// Handoff versioning - keep last N handoffs\nconst MAX_HANDOFF_VERSIONS = 10;\n\nfunction saveVersionedHandoff(\n projectRoot: string,\n branch: string,\n content: string\n): string {\n const handoffsDir = join(projectRoot, '.stackmemory', 'handoffs');\n if (!existsSync(handoffsDir)) {\n mkdirSync(handoffsDir, { recursive: true });\n }\n\n // Generate versioned filename: YYYY-MM-DD-HH-mm-branch.md\n const now = new Date();\n const timestamp = now.toISOString().slice(0, 16).replace(/[T:]/g, '-');\n const safeBranch = branch.replace(/[^a-zA-Z0-9-]/g, '-').slice(0, 30);\n const filename = `${timestamp}-${safeBranch}.md`;\n const versionedPath = join(handoffsDir, filename);\n\n // Save versioned handoff\n writeFileSync(versionedPath, content);\n\n // Clean up old handoffs (keep last N)\n try {\n const files = readdirSync(handoffsDir)\n .filter((f) => f.endsWith('.md'))\n .sort()\n .reverse();\n\n for (const oldFile of files.slice(MAX_HANDOFF_VERSIONS)) {\n unlinkSync(join(handoffsDir, oldFile));\n }\n } catch {\n // Cleanup failed, not critical\n }\n\n return versionedPath;\n}\n\n// Input validation schemas\nconst CommitMessageSchema = z\n .string()\n .min(1, 'Commit message cannot be empty')\n .max(200, 'Commit message too long')\n .regex(\n /^[a-zA-Z0-9\\s\\-_.,:()\\/\\[\\]]+$/,\n 'Commit message contains invalid characters'\n )\n .refine(\n (msg) => !msg.includes('\\n'),\n 'Commit message cannot contain newlines'\n )\n .refine(\n (msg) => !msg.includes('\"'),\n 'Commit message cannot contain double quotes'\n )\n .refine(\n (msg) => !msg.includes('`'),\n 'Commit message cannot contain backticks'\n );\n\nexport function createCaptureCommand(): Command {\n const cmd = new Command('capture');\n\n cmd\n .description('Commit current work and generate a handoff prompt')\n .option('-m, --message <message>', 'Custom commit message')\n .option('--no-commit', 'Skip git commit')\n .option('--copy', 'Copy the handoff prompt to clipboard')\n .option('--basic', 'Use basic handoff format instead of enhanced')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n // 1. Check git status\n let gitStatus = '';\n let hasChanges = false;\n\n try {\n gitStatus = execSync('git status --short', {\n encoding: 'utf-8',\n cwd: projectRoot,\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n hasChanges = gitStatus.trim().length > 0;\n } catch {\n // Not a git repository - silently skip git operations\n }\n\n // 2. Commit if there are changes and not skipped\n if (hasChanges && options.commit !== false) {\n try {\n // Get current branch\n const currentBranch = execSync('git rev-parse --abbrev-ref HEAD', {\n encoding: 'utf-8',\n cwd: projectRoot,\n }).trim();\n\n // Stage all changes\n execSync('git add -A', { cwd: projectRoot });\n\n // Generate or use custom commit message\n let commitMessage =\n options.message ||\n `chore: handoff checkpoint on ${currentBranch}`;\n\n // Validate commit message\n try {\n commitMessage = CommitMessageSchema.parse(commitMessage);\n } catch (validationError) {\n console.error(\n '\u274C Invalid commit message:',\n (validationError as Error).message\n );\n return;\n }\n\n // Commit using execFileSync for safety\n execFileSync('git', ['commit', '-m', commitMessage], {\n cwd: projectRoot,\n stdio: 'inherit',\n });\n\n console.log(`\u2705 Committed changes: \"${commitMessage}\"`);\n console.log(` Branch: ${currentBranch}`);\n } catch (err: unknown) {\n console.error(\n '\u274C Failed to commit changes:',\n (err as Error).message\n );\n }\n } else if (!hasChanges) {\n console.log('\u2139\uFE0F No changes to commit');\n }\n\n // 3. Gather context for handoff prompt\n let contextSummary = '';\n let tasksSummary = '';\n let recentWork = '';\n\n if (existsSync(dbPath)) {\n const db = new Database(dbPath);\n\n // Get recent context\n const frameManager = new FrameManager(db, 'cli-project');\n const activeFrames = frameManager.getActiveFramePath();\n\n if (activeFrames.length > 0) {\n contextSummary = 'Active context frames:\\n';\n activeFrames.forEach((frame) => {\n contextSummary += ` - ${frame.name} [${frame.type}]\\n`;\n });\n }\n\n // Get task status\n const taskStore = new LinearTaskManager(projectRoot, db);\n const activeTasks = taskStore.getActiveTasks();\n\n const inProgress = activeTasks.filter(\n (t: any) => t.status === 'in_progress'\n );\n const todo = activeTasks.filter((t: any) => t.status === 'pending');\n const recentlyCompleted = activeTasks\n .filter((t: any) => t.status === 'completed' && t.completed_at)\n .sort(\n (a: any, b: any) => (b.completed_at || 0) - (a.completed_at || 0)\n )\n .slice(0, 3);\n\n if (inProgress.length > 0 || todo.length > 0) {\n tasksSummary = '\\nTasks:\\n';\n\n if (inProgress.length > 0) {\n tasksSummary += 'In Progress:\\n';\n inProgress.forEach((t: any) => {\n const externalId = t.external_refs?.linear?.id;\n tasksSummary += ` - ${t.title}${externalId ? ` [${externalId}]` : ''}\\n`;\n });\n }\n\n if (todo.length > 0) {\n tasksSummary += 'TODO:\\n';\n todo.slice(0, 5).forEach((t: any) => {\n const externalId = t.external_refs?.linear?.id;\n tasksSummary += ` - ${t.title}${externalId ? ` [${externalId}]` : ''}\\n`;\n });\n if (todo.length > 5) {\n tasksSummary += ` ... and ${todo.length - 5} more\\n`;\n }\n }\n }\n\n if (recentlyCompleted.length > 0) {\n recentWork = '\\nRecently Completed:\\n';\n recentlyCompleted.forEach((t: any) => {\n recentWork += ` \u2713 ${t.title}\\n`;\n });\n }\n\n // Get recent events\n const recentEvents = db\n .prepare(\n `\n SELECT event_type as type, payload as data, datetime(ts, 'unixepoch') as time\n FROM events\n ORDER BY ts DESC\n LIMIT 5\n `\n )\n .all() as any[];\n\n if (recentEvents.length > 0) {\n recentWork += '\\nRecent Activity:\\n';\n recentEvents.forEach((event) => {\n const data = JSON.parse(event.data);\n recentWork += ` - ${event.type}: ${data.message || data.name || 'activity'}\\n`;\n });\n }\n\n db.close();\n }\n\n // 4. Get current git info\n let gitInfo = '';\n try {\n const branch = execSync('git rev-parse --abbrev-ref HEAD', {\n encoding: 'utf-8',\n cwd: projectRoot,\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n\n const lastCommit = execSync('git log -1 --oneline', {\n encoding: 'utf-8',\n cwd: projectRoot,\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n\n gitInfo = `\\nGit Status:\\n Branch: ${branch}\\n Last commit: ${lastCommit}\\n`;\n } catch {\n // Not a git repository - silently ignore\n }\n\n // 5. Check for any blockers or notes\n let notes = '';\n const notesPath = join(projectRoot, '.stackmemory', 'handoff.md');\n if (existsSync(notesPath)) {\n const handoffNotes = readFileSync(notesPath, 'utf-8');\n if (handoffNotes.trim()) {\n notes = `\\nNotes from previous handoff:\\n${handoffNotes}\\n`;\n }\n }\n\n // 6. Generate the handoff prompt\n let handoffPrompt: string;\n\n if (options.basic) {\n // Use basic handoff format\n const timestamp = new Date().toISOString();\n handoffPrompt = `# Session Handoff - ${timestamp}\n\n## Project: ${projectRoot.split('/').pop()}\n\n${gitInfo}\n${contextSummary}\n${tasksSummary}\n${recentWork}\n${notes}\n\n## Continue from here:\n\n1. Run \\`stackmemory status\\` to check the current state\n2. Review any in-progress tasks above\n3. Check for any uncommitted changes with \\`git status\\`\n4. Resume work on the active context\n\n## Quick Commands:\n- \\`stackmemory context load --recent\\` - Load recent context\n- \\`stackmemory task list --state in_progress\\` - Show in-progress tasks\n- \\`stackmemory linear sync\\` - Sync with Linear if configured\n- \\`stackmemory log recent\\` - View recent activity\n\n---\nGenerated by stackmemory capture at ${timestamp}\n`;\n } else {\n // Use high-efficacy enhanced handoff generator (default)\n const enhancedGenerator = new EnhancedHandoffGenerator(projectRoot);\n const enhancedHandoff = await enhancedGenerator.generate();\n handoffPrompt = enhancedGenerator.toMarkdown(enhancedHandoff);\n console.log(`Estimated tokens: ~${enhancedHandoff.estimatedTokens}`);\n }\n\n // 7. Save handoff prompt (both latest and versioned)\n const stackmemoryDir = join(projectRoot, '.stackmemory');\n if (!existsSync(stackmemoryDir)) {\n mkdirSync(stackmemoryDir, { recursive: true });\n }\n const handoffPath = join(stackmemoryDir, 'last-handoff.md');\n writeFileSync(handoffPath, handoffPrompt);\n\n // Save versioned copy\n let branch = 'unknown';\n try {\n branch = execSync('git rev-parse --abbrev-ref HEAD', {\n encoding: 'utf-8',\n cwd: projectRoot,\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n } catch {\n // Not a git repo\n }\n const versionedPath = saveVersionedHandoff(\n projectRoot,\n branch,\n handoffPrompt\n );\n console.log(\n `Versioned: ${versionedPath.split('/').slice(-2).join('/')}`\n );\n\n // 8. Display the prompt\n console.log('\\n' + '='.repeat(60));\n console.log(handoffPrompt);\n console.log('='.repeat(60));\n\n // 9. Copy to clipboard if requested\n if (options.copy) {\n try {\n // Use execFileSync with predefined commands for safety\n if (process.platform === 'darwin') {\n execFileSync('pbcopy', [], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n } else if (process.platform === 'win32') {\n execFileSync('clip', [], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n } else {\n execFileSync('xclip', ['-selection', 'clipboard'], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n }\n\n console.log('\\n\u2705 Handoff prompt copied to clipboard!');\n } catch {\n console.log('\\n\u26A0\uFE0F Could not copy to clipboard');\n }\n }\n\n console.log(`\\n\uD83D\uDCBE Handoff saved to: ${handoffPath}`);\n console.log('\uD83D\uDCCB Use this prompt when starting your next session');\n } catch (error: unknown) {\n logger.error('Capture command failed', error as Error);\n console.error('\u274C Capture failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n return cmd;\n}\n\nexport function createRestoreCommand(): Command {\n const cmd = new Command('restore');\n\n cmd\n .description('Restore context from last handoff')\n .option('--no-copy', 'Do not copy prompt to clipboard')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const handoffPath = join(\n projectRoot,\n '.stackmemory',\n 'last-handoff.md'\n );\n const metaPath = join(\n process.env['HOME'] || '~',\n '.stackmemory',\n 'handoffs',\n 'last-handoff-meta.json'\n );\n\n if (!existsSync(handoffPath)) {\n console.log('\u274C No handoff found in this project');\n console.log('\uD83D\uDCA1 Run \"stackmemory capture\" to create one');\n return;\n }\n\n // Read handoff prompt\n const handoffPrompt = readFileSync(handoffPath, 'utf-8');\n\n // Display the prompt\n console.log('\\n' + '='.repeat(60));\n console.log('\uD83D\uDCCB RESTORED HANDOFF');\n console.log('='.repeat(60));\n console.log(handoffPrompt);\n console.log('='.repeat(60));\n\n // Check for metadata\n if (existsSync(metaPath)) {\n const metadata = JSON.parse(readFileSync(metaPath, 'utf-8'));\n console.log('\\n\uD83D\uDCCA Session Metadata:');\n console.log(` Timestamp: ${metadata.timestamp}`);\n console.log(` Reason: ${metadata.reason}`);\n console.log(` Duration: ${metadata.session_duration}s`);\n console.log(` Command: ${metadata.command}`);\n }\n\n // Check current git status\n try {\n const gitStatus = execSync('git status --short', {\n encoding: 'utf-8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n if (gitStatus) {\n console.log('\\n Current uncommitted changes:');\n console.log(gitStatus);\n }\n } catch {\n // Not a git repo - silently ignore\n }\n\n // Copy to clipboard unless disabled\n if (options.copy !== false) {\n try {\n // Use execFileSync with predefined commands for safety\n if (process.platform === 'darwin') {\n execFileSync('pbcopy', [], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n } else if (process.platform === 'win32') {\n execFileSync('clip', [], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n } else {\n execFileSync('xclip', ['-selection', 'clipboard'], {\n input: handoffPrompt,\n cwd: projectRoot,\n });\n }\n\n console.log('\\n\u2705 Handoff prompt copied to clipboard!');\n } catch {\n console.log('\\n\u26A0\uFE0F Could not copy to clipboard');\n }\n }\n\n console.log('\\n\uD83D\uDE80 Ready to continue where you left off!');\n } catch (error: unknown) {\n logger.error('Restore failed', error as Error);\n console.error('\u274C Restore failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n return cmd;\n}\n\ninterface AutoCaptureMetadata {\n timestamp: string;\n reason: string;\n exit_code: number;\n command: string;\n pid: number;\n cwd: string;\n user: string;\n session_duration: number;\n}\n\nasync function captureHandoff(\n reason: string,\n exitCode: number,\n wrappedCommand: string,\n sessionStart: number,\n quiet: boolean\n): Promise<void> {\n const projectRoot = process.cwd();\n const handoffDir = join(homedir(), '.stackmemory', 'handoffs');\n const logFile = join(handoffDir, 'auto-handoff.log');\n\n // Ensure handoff directory exists\n if (!existsSync(handoffDir)) {\n mkdirSync(handoffDir, { recursive: true });\n }\n\n const logMessage = (msg: string): void => {\n const timestamp = new Date().toISOString().slice(0, 19).replace('T', ' ');\n const logLine = `[${timestamp}] ${msg}\\n`;\n try {\n writeFileSync(logFile, logLine, { flag: 'a' });\n } catch {\n // Logging failed, continue anyway\n }\n };\n\n if (!quiet) {\n console.log('\\nCapturing handoff context...');\n }\n logMessage(`Capturing handoff: reason=${reason}, exit_code=${exitCode}`);\n\n try {\n // Run stackmemory capture --no-commit\n execFileSync(\n process.execPath,\n [process.argv[1], 'capture', '--no-commit'],\n {\n cwd: projectRoot,\n stdio: quiet ? 'pipe' : 'inherit',\n }\n );\n\n // Save metadata\n const metadata: AutoCaptureMetadata = {\n timestamp: new Date().toISOString(),\n reason,\n exit_code: exitCode,\n command: wrappedCommand,\n pid: process.pid,\n cwd: projectRoot,\n user: process.env['USER'] || 'unknown',\n session_duration: Math.floor((Date.now() - sessionStart) / 1000),\n };\n\n const metadataPath = join(handoffDir, 'last-handoff-meta.json');\n writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));\n\n if (!quiet) {\n console.log('Handoff captured successfully');\n logMessage(`Handoff captured: ${metadataPath}`);\n\n // Show session summary\n console.log('\\nSession Summary:');\n console.log(` Duration: ${metadata.session_duration} seconds`);\n console.log(` Exit reason: ${reason}`);\n\n // Check for uncommitted changes\n try {\n const gitStatus = execSync('git status --short', {\n encoding: 'utf-8',\n cwd: projectRoot,\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n if (gitStatus) {\n console.log('\\nYou have uncommitted changes');\n console.log(' Run \"git status\" to review');\n }\n } catch {\n // Not a git repo - silently ignore\n }\n\n console.log('\\nRun \"stackmemory restore\" in your next session');\n }\n } catch (err) {\n if (!quiet) {\n console.error('Failed to capture handoff:', (err as Error).message);\n }\n logMessage(`ERROR: ${(err as Error).message}`);\n }\n}\n\nexport function createAutoCaptureCommand(): Command {\n const cmd = new Command('auto-capture');\n\n cmd\n .description('Wrap a command with automatic handoff capture on termination')\n .option('-a, --auto', 'Auto-capture on normal exit (no prompt)')\n .option('-q, --quiet', 'Suppress output')\n .option('-t, --tag <tag>', 'Tag this session')\n .argument('[command...]', 'Command to wrap with auto-handoff')\n .action(async (commandArgs: string[], options) => {\n const autoCapture = options.auto || false;\n const quiet = options.quiet || false;\n const tag = options.tag || '';\n\n // If no command provided, show usage\n if (!commandArgs || commandArgs.length === 0) {\n console.log('StackMemory Auto-Handoff');\n console.log('-'.repeat(50));\n console.log('');\n console.log(\n 'Wraps a command with automatic handoff capture on termination.'\n );\n console.log('');\n console.log('Usage:');\n console.log(' stackmemory auto-capture [options] <command> [args...]');\n console.log('');\n console.log('Examples:');\n console.log(' stackmemory auto-capture claude');\n console.log(' stackmemory auto-capture -a npm run dev');\n console.log(' stackmemory auto-capture -t \"feature-work\" vim');\n console.log('');\n console.log('Options:');\n console.log(\n ' -a, --auto Auto-capture on normal exit (no prompt)'\n );\n console.log(' -q, --quiet Suppress output');\n console.log(' -t, --tag <tag> Tag this session');\n return;\n }\n\n const wrappedCommand = commandArgs.join(' ');\n const sessionStart = Date.now();\n let capturedAlready = false;\n\n if (!quiet) {\n console.log('StackMemory Auto-Handoff Wrapper');\n console.log(`Wrapping: ${wrappedCommand}`);\n if (tag) {\n console.log(`Tag: ${tag}`);\n }\n console.log('Handoff will be captured on termination');\n console.log('');\n }\n\n // Spawn the wrapped command\n const [cmd, ...args] = commandArgs;\n let childProcess: ChildProcess;\n\n try {\n childProcess = spawn(cmd, args, {\n stdio: 'inherit',\n shell: false,\n cwd: process.cwd(),\n env: process.env,\n });\n } catch (err) {\n console.error(`Failed to start command: ${(err as Error).message}`);\n process.exit(1);\n return;\n }\n\n // Handle signals - forward to child and capture on termination\n const handleSignal = async (\n signal: NodeJS.Signals,\n exitCode: number\n ): Promise<void> => {\n if (capturedAlready) return;\n capturedAlready = true;\n\n if (!quiet) {\n console.log(`\\nReceived ${signal}`);\n }\n\n // Kill the child process if still running\n if (childProcess.pid && !childProcess.killed) {\n childProcess.kill(signal);\n }\n\n await captureHandoff(\n signal,\n exitCode,\n wrappedCommand,\n sessionStart,\n quiet\n );\n process.exit(exitCode);\n };\n\n process.on('SIGINT', () => handleSignal('SIGINT', 130));\n process.on('SIGTERM', () => handleSignal('SIGTERM', 143));\n process.on('SIGHUP', () => handleSignal('SIGHUP', 129));\n\n // Handle child process exit\n childProcess.on('exit', async (code, signal) => {\n if (capturedAlready) return;\n capturedAlready = true;\n\n const exitCode = code ?? (signal ? 128 : 0);\n\n if (signal) {\n // Child was killed by a signal\n await captureHandoff(\n signal,\n exitCode,\n wrappedCommand,\n sessionStart,\n quiet\n );\n } else if (exitCode !== 0) {\n // Unexpected exit\n if (!quiet) {\n console.log(`\\nCommand exited with code: ${exitCode}`);\n }\n await captureHandoff(\n 'unexpected_exit',\n exitCode,\n wrappedCommand,\n sessionStart,\n quiet\n );\n } else if (autoCapture) {\n // Normal exit with auto-capture enabled\n await captureHandoff(\n 'normal_exit',\n 0,\n wrappedCommand,\n sessionStart,\n quiet\n );\n } else {\n // Normal exit - prompt for capture (simplified for CLI, auto-capture)\n // In non-interactive contexts, default to capturing\n if (process.stdin.isTTY) {\n // Interactive - we could prompt but keeping it simple\n console.log(\n '\\nSession ending. Use -a flag for auto-capture on normal exit.'\n );\n }\n }\n\n process.exit(exitCode);\n });\n\n // Handle spawn errors\n childProcess.on('error', async (err) => {\n if (capturedAlready) return;\n capturedAlready = true;\n\n console.error(`Command error: ${err.message}`);\n await captureHandoff(\n 'spawn_error',\n 1,\n wrappedCommand,\n sessionStart,\n quiet\n );\n process.exit(1);\n });\n });\n\n return cmd;\n}\n\n/** @deprecated Use createCaptureCommand, createRestoreCommand, createAutoCaptureCommand */\nexport function createHandoffCommand(): Command {\n const cmd = new Command('handoff');\n cmd.description('(deprecated) Use \"capture\" or \"restore\" instead');\n return cmd;\n}\n"],
5
+ "mappings": ";;;;AAIA,SAAS,eAAe;AACxB,SAAS,UAAU,cAAc,aAA2B;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;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AkB;AAElB,cAAQ,MAAM,kBAAkB,IAAI,OAAO,EAAE;AAC7C,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,cAAQ,KAAK,CAAC;AAAA,IAChB,CAAC;AAAA,EACH,CAAC;AAEH,SAAO;AACT;AAGO,SAAS,uBAAgC;AAC9C,QAAM,MAAM,IAAI,QAAQ,SAAS;AACjC,MAAI,YAAY,iDAAiD;AACjE,SAAO;AACT;",
6
6
  "names": ["branch", "cmd"]
7
7
  }
@@ -421,15 +421,281 @@ function createSetupPluginsCommand() {
421
421
  });
422
422
  return cmd;
423
423
  }
424
+ function createSetupRemoteCommand() {
425
+ const cmd = new Command("setup-remote");
426
+ cmd.description("Configure remote MCP server to auto-start on boot").option("--port <number>", "Port for remote server", "3847").option("--project <path>", "Project root directory").option("--uninstall", "Remove the auto-start service").option("--status", "Check service status").action(async (options) => {
427
+ const home = homedir();
428
+ const platform = process.platform;
429
+ const serviceName = platform === "darwin" ? "com.stackmemory.remote-mcp" : "stackmemory-remote-mcp";
430
+ const serviceDir = platform === "darwin" ? join(home, "Library", "LaunchAgents") : join(home, ".config", "systemd", "user");
431
+ const serviceFile = platform === "darwin" ? join(serviceDir, `${serviceName}.plist`) : join(serviceDir, `${serviceName}.service`);
432
+ const logDir = join(home, ".stackmemory", "logs");
433
+ const pidFile = join(home, ".stackmemory", "remote-mcp.pid");
434
+ if (options.status) {
435
+ console.log(chalk.cyan("\nRemote MCP Server Status\n"));
436
+ if (platform === "darwin") {
437
+ try {
438
+ const result = execSync(
439
+ `launchctl list | grep ${serviceName} || true`,
440
+ { encoding: "utf-8" }
441
+ );
442
+ if (result.includes(serviceName)) {
443
+ console.log(chalk.green("[RUNNING]") + " Service is active");
444
+ try {
445
+ const health = execSync(
446
+ `curl -s http://localhost:${options.port}/health 2>/dev/null`,
447
+ { encoding: "utf-8" }
448
+ );
449
+ const data = JSON.parse(health);
450
+ console.log(chalk.gray(` Project: ${data.projectId}`));
451
+ console.log(
452
+ chalk.gray(` URL: http://localhost:${options.port}/sse`)
453
+ );
454
+ } catch {
455
+ console.log(
456
+ chalk.yellow(" Server not responding to health check")
457
+ );
458
+ }
459
+ } else {
460
+ console.log(chalk.yellow("[STOPPED]") + " Service not running");
461
+ }
462
+ } catch {
463
+ console.log(chalk.yellow("[UNKNOWN]") + " Could not check status");
464
+ }
465
+ } else if (platform === "linux") {
466
+ try {
467
+ execSync(`systemctl --user is-active ${serviceName}`, {
468
+ stdio: "pipe"
469
+ });
470
+ console.log(chalk.green("[RUNNING]") + " Service is active");
471
+ } catch {
472
+ console.log(chalk.yellow("[STOPPED]") + " Service not running");
473
+ }
474
+ }
475
+ console.log(chalk.gray(`
476
+ Service file: ${serviceFile}`));
477
+ console.log(chalk.gray(`Logs: ${logDir}/remote-mcp.log`));
478
+ return;
479
+ }
480
+ if (options.uninstall) {
481
+ console.log(chalk.cyan("\nUninstalling Remote MCP Server Service\n"));
482
+ if (platform === "darwin") {
483
+ try {
484
+ execSync(`launchctl unload "${serviceFile}"`, { stdio: "pipe" });
485
+ console.log(chalk.green("[OK]") + " Service unloaded");
486
+ } catch {
487
+ console.log(chalk.gray("[SKIP]") + " Service was not loaded");
488
+ }
489
+ if (existsSync(serviceFile)) {
490
+ const fs = await import("fs/promises");
491
+ await fs.unlink(serviceFile);
492
+ console.log(chalk.green("[OK]") + " Service file removed");
493
+ }
494
+ } else if (platform === "linux") {
495
+ try {
496
+ execSync(`systemctl --user stop ${serviceName}`, { stdio: "pipe" });
497
+ execSync(`systemctl --user disable ${serviceName}`, {
498
+ stdio: "pipe"
499
+ });
500
+ console.log(chalk.green("[OK]") + " Service stopped and disabled");
501
+ } catch {
502
+ console.log(chalk.gray("[SKIP]") + " Service was not running");
503
+ }
504
+ if (existsSync(serviceFile)) {
505
+ const fs = await import("fs/promises");
506
+ await fs.unlink(serviceFile);
507
+ execSync("systemctl --user daemon-reload", { stdio: "pipe" });
508
+ console.log(chalk.green("[OK]") + " Service file removed");
509
+ }
510
+ }
511
+ console.log(chalk.green("\nRemote MCP service uninstalled"));
512
+ return;
513
+ }
514
+ console.log(chalk.cyan("\nSetting up Remote MCP Server Auto-Start\n"));
515
+ if (platform !== "darwin" && platform !== "linux") {
516
+ console.log(
517
+ chalk.red("Auto-start is only supported on macOS and Linux")
518
+ );
519
+ console.log(chalk.gray("\nManual start: stackmemory mcp-remote"));
520
+ return;
521
+ }
522
+ if (!existsSync(serviceDir)) {
523
+ mkdirSync(serviceDir, { recursive: true });
524
+ }
525
+ if (!existsSync(logDir)) {
526
+ mkdirSync(logDir, { recursive: true });
527
+ }
528
+ let nodePath;
529
+ try {
530
+ nodePath = execSync("which node", { encoding: "utf-8" }).trim();
531
+ } catch {
532
+ nodePath = "/usr/local/bin/node";
533
+ }
534
+ let stackmemoryPath;
535
+ try {
536
+ stackmemoryPath = execSync("which stackmemory", {
537
+ encoding: "utf-8"
538
+ }).trim();
539
+ } catch {
540
+ try {
541
+ const npmRoot = execSync("npm root -g", { encoding: "utf-8" }).trim();
542
+ stackmemoryPath = join(
543
+ npmRoot,
544
+ "@stackmemoryai",
545
+ "stackmemory",
546
+ "dist",
547
+ "cli",
548
+ "index.js"
549
+ );
550
+ } catch {
551
+ stackmemoryPath = "npx stackmemory";
552
+ }
553
+ }
554
+ const projectPath = options.project || home;
555
+ const port = options.port || "3847";
556
+ if (platform === "darwin") {
557
+ const plist = `<?xml version="1.0" encoding="UTF-8"?>
558
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
559
+ <plist version="1.0">
560
+ <dict>
561
+ <key>Label</key>
562
+ <string>${serviceName}</string>
563
+
564
+ <key>ProgramArguments</key>
565
+ <array>
566
+ <string>${stackmemoryPath.includes("npx") ? "npx" : nodePath}</string>
567
+ ${stackmemoryPath.includes("npx") ? "<string>stackmemory</string>" : `<string>${stackmemoryPath}</string>`}
568
+ <string>mcp-remote</string>
569
+ <string>--port</string>
570
+ <string>${port}</string>
571
+ <string>--project</string>
572
+ <string>${projectPath}</string>
573
+ </array>
574
+
575
+ <key>RunAtLoad</key>
576
+ <true/>
577
+
578
+ <key>KeepAlive</key>
579
+ <dict>
580
+ <key>SuccessfulExit</key>
581
+ <false/>
582
+ </dict>
583
+
584
+ <key>WorkingDirectory</key>
585
+ <string>${projectPath}</string>
586
+
587
+ <key>StandardOutPath</key>
588
+ <string>${logDir}/remote-mcp.log</string>
589
+
590
+ <key>StandardErrorPath</key>
591
+ <string>${logDir}/remote-mcp.error.log</string>
592
+
593
+ <key>EnvironmentVariables</key>
594
+ <dict>
595
+ <key>HOME</key>
596
+ <string>${home}</string>
597
+ <key>PATH</key>
598
+ <string>/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin</string>
599
+ <key>NODE_ENV</key>
600
+ <string>production</string>
601
+ </dict>
602
+
603
+ <key>ThrottleInterval</key>
604
+ <integer>10</integer>
605
+ </dict>
606
+ </plist>`;
607
+ writeFileSync(serviceFile, plist);
608
+ console.log(chalk.green("[OK]") + " Created launchd service file");
609
+ try {
610
+ execSync(`launchctl unload "${serviceFile}" 2>/dev/null`, {
611
+ stdio: "pipe"
612
+ });
613
+ } catch {
614
+ }
615
+ try {
616
+ execSync(`launchctl load -w "${serviceFile}"`, { stdio: "pipe" });
617
+ console.log(chalk.green("[OK]") + " Service loaded and started");
618
+ } catch (err) {
619
+ console.log(chalk.red("[ERROR]") + ` Failed to load service: ${err}`);
620
+ return;
621
+ }
622
+ } else if (platform === "linux") {
623
+ const service = `[Unit]
624
+ Description=StackMemory Remote MCP Server
625
+ Documentation=https://github.com/stackmemoryai/stackmemory
626
+ After=network.target
627
+
628
+ [Service]
629
+ Type=simple
630
+ ExecStart=${stackmemoryPath.includes("npx") ? "npx stackmemory" : `${nodePath} ${stackmemoryPath}`} mcp-remote --port ${port} --project ${projectPath}
631
+ Restart=on-failure
632
+ RestartSec=10
633
+ WorkingDirectory=${projectPath}
634
+
635
+ Environment=HOME=${home}
636
+ Environment=PATH=/usr/local/bin:/usr/bin:/bin
637
+ Environment=NODE_ENV=production
638
+
639
+ StandardOutput=append:${logDir}/remote-mcp.log
640
+ StandardError=append:${logDir}/remote-mcp.error.log
641
+
642
+ [Install]
643
+ WantedBy=default.target`;
644
+ writeFileSync(serviceFile, service);
645
+ console.log(chalk.green("[OK]") + " Created systemd service file");
646
+ try {
647
+ execSync("systemctl --user daemon-reload", { stdio: "pipe" });
648
+ execSync(`systemctl --user enable ${serviceName}`, { stdio: "pipe" });
649
+ execSync(`systemctl --user start ${serviceName}`, { stdio: "pipe" });
650
+ console.log(chalk.green("[OK]") + " Service enabled and started");
651
+ } catch (err) {
652
+ console.log(
653
+ chalk.red("[ERROR]") + ` Failed to start service: ${err}`
654
+ );
655
+ return;
656
+ }
657
+ }
658
+ console.log(chalk.cyan("\nVerifying server...\n"));
659
+ await new Promise((resolve) => setTimeout(resolve, 2e3));
660
+ try {
661
+ const health = execSync(
662
+ `curl -s http://localhost:${port}/health 2>/dev/null`,
663
+ { encoding: "utf-8" }
664
+ );
665
+ const data = JSON.parse(health);
666
+ console.log(chalk.green("[OK]") + " Server is running");
667
+ console.log(chalk.gray(` Project: ${data.projectId}`));
668
+ } catch {
669
+ console.log(
670
+ chalk.yellow("[WARN]") + " Server not responding yet (may still be starting)"
671
+ );
672
+ }
673
+ console.log(
674
+ chalk.green("\nRemote MCP Server configured for auto-start!")
675
+ );
676
+ console.log(chalk.cyan("\nConnection info:"));
677
+ console.log(chalk.white(` URL: http://localhost:${port}/sse`));
678
+ console.log(chalk.white(` Health: http://localhost:${port}/health`));
679
+ console.log(chalk.gray(`
680
+ Logs: ${logDir}/remote-mcp.log`));
681
+ console.log(chalk.gray(`Service: ${serviceFile}`));
682
+ console.log(chalk.cyan("\nFor external access (ngrok):"));
683
+ console.log(chalk.white(` ngrok http ${port}`));
684
+ console.log(chalk.gray(" Then use the ngrok URL + /sse in Claude.ai"));
685
+ });
686
+ return cmd;
687
+ }
424
688
  function registerSetupCommands(program) {
425
689
  program.addCommand(createSetupMCPCommand());
426
690
  program.addCommand(createDoctorCommand());
427
691
  program.addCommand(createSetupPluginsCommand());
692
+ program.addCommand(createSetupRemoteCommand());
428
693
  }
429
694
  export {
430
695
  createDoctorCommand,
431
696
  createSetupMCPCommand,
432
697
  createSetupPluginsCommand,
698
+ createSetupRemoteCommand,
433
699
  registerSetupCommands
434
700
  };
435
701
  //# sourceMappingURL=setup.js.map