@stackmemoryai/stackmemory 0.5.8 → 0.5.9

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.
@@ -4,6 +4,8 @@ const __filename = __fileURLToPath(import.meta.url);
4
4
  const __dirname = __pathDirname(__filename);
5
5
  import { Command } from "commander";
6
6
  import chalk from "chalk";
7
+ import { execSync } from "child_process";
8
+ import { join } from "path";
7
9
  import {
8
10
  loadSMSConfig,
9
11
  saveSMSConfig,
@@ -13,6 +15,12 @@ import {
13
15
  notifyTaskComplete,
14
16
  cleanupExpiredPrompts
15
17
  } from "../../hooks/sms-notify.js";
18
+ import {
19
+ loadActionQueue,
20
+ processAllPendingActions,
21
+ cleanupOldActions,
22
+ startActionWatcher
23
+ } from "../../hooks/sms-action-runner.js";
16
24
  function createSMSNotifyCommand() {
17
25
  const cmd = new Command("notify").description(
18
26
  "SMS notification system for review alerts (optional, requires Twilio)"
@@ -264,6 +272,84 @@ Examples:
264
272
  saveSMSConfig(config);
265
273
  console.log(chalk.green(`Response timeout set to ${timeout} seconds`));
266
274
  });
275
+ cmd.command("actions").description("List queued actions from SMS responses").action(() => {
276
+ const queue = loadActionQueue();
277
+ if (queue.actions.length === 0) {
278
+ console.log(chalk.gray("No actions in queue"));
279
+ return;
280
+ }
281
+ console.log(chalk.blue("Action Queue:"));
282
+ queue.actions.forEach((a) => {
283
+ const statusColor = a.status === "completed" ? chalk.green : a.status === "failed" ? chalk.red : a.status === "running" ? chalk.yellow : chalk.gray;
284
+ console.log();
285
+ console.log(` ${chalk.gray("ID:")} ${a.id}`);
286
+ console.log(` ${chalk.gray("Status:")} ${statusColor(a.status)}`);
287
+ console.log(
288
+ ` ${chalk.gray("Action:")} ${a.action.substring(0, 60)}...`
289
+ );
290
+ console.log(` ${chalk.gray("Response:")} ${a.response}`);
291
+ if (a.error) {
292
+ console.log(` ${chalk.gray("Error:")} ${chalk.red(a.error)}`);
293
+ }
294
+ });
295
+ });
296
+ cmd.command("run-actions").description("Execute all pending actions from SMS responses").action(() => {
297
+ console.log(chalk.blue("Processing pending actions..."));
298
+ const result = processAllPendingActions();
299
+ console.log(
300
+ chalk.green(
301
+ `Processed ${result.processed} action(s): ${result.succeeded} succeeded, ${result.failed} failed`
302
+ )
303
+ );
304
+ });
305
+ cmd.command("watch").description("Watch for and execute SMS response actions").option("-i, --interval <ms>", "Check interval in milliseconds", "5000").action((options) => {
306
+ const interval = parseInt(options.interval, 10);
307
+ console.log(chalk.blue(`Watching for actions (interval: ${interval}ms)`));
308
+ console.log(chalk.gray("Press Ctrl+C to stop"));
309
+ startActionWatcher(interval);
310
+ });
311
+ cmd.command("cleanup-actions").description("Remove old completed actions").action(() => {
312
+ const removed = cleanupOldActions();
313
+ console.log(chalk.green(`Removed ${removed} old action(s)`));
314
+ });
315
+ cmd.command("install-hook").description("Install Claude Code notification hook").action(() => {
316
+ try {
317
+ const scriptPath = join(
318
+ __dirname,
319
+ "../../../scripts/install-notify-hook.sh"
320
+ );
321
+ execSync(`bash "${scriptPath}"`, { stdio: "inherit" });
322
+ } catch {
323
+ console.error(chalk.red("Failed to install hook"));
324
+ }
325
+ });
326
+ cmd.command("install-response-hook").description("Install Claude Code response handler hook").action(() => {
327
+ try {
328
+ const hooksDir = join(process.env["HOME"] || "~", ".claude", "hooks");
329
+ const hookSrc = join(
330
+ __dirname,
331
+ "../../../templates/claude-hooks/sms-response-handler.js"
332
+ );
333
+ const hookDest = join(hooksDir, "sms-response-handler.js");
334
+ execSync(`mkdir -p "${hooksDir}"`, { stdio: "inherit" });
335
+ execSync(`cp "${hookSrc}" "${hookDest}"`, { stdio: "inherit" });
336
+ execSync(`chmod +x "${hookDest}"`, { stdio: "inherit" });
337
+ console.log(chalk.green("Response handler hook installed!"));
338
+ console.log(chalk.gray(`Location: ${hookDest}`));
339
+ console.log();
340
+ console.log(chalk.blue("Add to ~/.claude/settings.json:"));
341
+ console.log(
342
+ chalk.gray(` "hooks": { "pre_tool_use": ["node ${hookDest}"] }`)
343
+ );
344
+ } catch {
345
+ console.error(chalk.red("Failed to install response hook"));
346
+ }
347
+ });
348
+ cmd.command("webhook").description("Start SMS webhook server for receiving responses").option("-p, --port <port>", "Port to listen on", "3456").action(async (options) => {
349
+ const { startWebhookServer } = await import("../../hooks/sms-webhook.js");
350
+ const port = parseInt(options.port, 10);
351
+ startWebhookServer(port);
352
+ });
267
353
  return cmd;
268
354
  }
269
355
  function maskPhone(phone) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/cli/commands/sms-notify.ts"],
4
- "sourcesContent": ["/**\n * CLI command for SMS notification management\n */\n\nimport { Command } from 'commander';\nimport chalk from 'chalk';\nimport {\n loadSMSConfig,\n saveSMSConfig,\n sendSMSNotification,\n notifyReviewReady,\n notifyWithYesNo,\n notifyTaskComplete,\n cleanupExpiredPrompts,\n} from '../../hooks/sms-notify.js';\n\nexport function createSMSNotifyCommand(): Command {\n const cmd = new Command('notify')\n .description(\n 'SMS notification system for review alerts (optional, requires Twilio)'\n )\n .addHelpText(\n 'after',\n `\nSetup (optional):\n 1. Create Twilio account at https://twilio.com\n 2. Get Account SID, Auth Token, and phone number\n 3. Set environment variables:\n export TWILIO_ACCOUNT_SID=your_sid\n export TWILIO_AUTH_TOKEN=your_token\n export TWILIO_FROM_NUMBER=+1234567890\n export TWILIO_TO_NUMBER=+1234567890\n 4. Enable: stackmemory notify enable\n\nExamples:\n stackmemory notify status Check configuration\n stackmemory notify enable Enable notifications\n stackmemory notify test Send test message\n stackmemory notify send \"PR ready\" Send custom message\n stackmemory notify review \"PR #123\" Send review notification with options\n stackmemory notify ask \"Deploy?\" Send yes/no prompt\n`\n );\n\n cmd\n .command('status')\n .description('Show notification configuration status')\n .action(() => {\n const config = loadSMSConfig();\n\n console.log(chalk.blue('SMS Notification Status:'));\n console.log();\n\n // Check if configured\n const hasCreds =\n config.accountSid &&\n config.authToken &&\n config.fromNumber &&\n config.toNumber;\n\n console.log(\n ` ${chalk.gray('Enabled:')} ${config.enabled ? chalk.green('yes') : chalk.red('no')}`\n );\n console.log(\n ` ${chalk.gray('Configured:')} ${hasCreds ? chalk.green('yes') : chalk.yellow('no (set env vars)')}`\n );\n\n if (config.fromNumber) {\n console.log(` ${chalk.gray('From:')} ${maskPhone(config.fromNumber)}`);\n }\n if (config.toNumber) {\n console.log(` ${chalk.gray('To:')} ${maskPhone(config.toNumber)}`);\n }\n\n console.log();\n console.log(chalk.blue('Notify On:'));\n console.log(\n ` ${chalk.gray('Task Complete:')} ${config.notifyOn.taskComplete ? 'yes' : 'no'}`\n );\n console.log(\n ` ${chalk.gray('Review Ready:')} ${config.notifyOn.reviewReady ? 'yes' : 'no'}`\n );\n console.log(\n ` ${chalk.gray('Errors:')} ${config.notifyOn.error ? 'yes' : 'no'}`\n );\n\n if (config.quietHours?.enabled) {\n console.log();\n console.log(\n chalk.blue(\n `Quiet Hours: ${config.quietHours.start} - ${config.quietHours.end}`\n )\n );\n }\n\n console.log();\n console.log(\n ` ${chalk.gray('Pending Prompts:')} ${config.pendingPrompts.length}`\n );\n console.log(\n ` ${chalk.gray('Response Timeout:')} ${config.responseTimeout}s`\n );\n\n if (!hasCreds) {\n console.log();\n console.log(\n chalk.yellow('To configure, set these environment variables:')\n );\n console.log(chalk.gray(' export TWILIO_ACCOUNT_SID=your_sid'));\n console.log(chalk.gray(' export TWILIO_AUTH_TOKEN=your_token'));\n console.log(chalk.gray(' export TWILIO_FROM_NUMBER=+1234567890'));\n console.log(chalk.gray(' export TWILIO_TO_NUMBER=+1234567890'));\n }\n });\n\n cmd\n .command('enable')\n .description('Enable SMS notifications')\n .action(() => {\n const config = loadSMSConfig();\n config.enabled = true;\n saveSMSConfig(config);\n console.log(chalk.green('SMS notifications enabled'));\n\n const hasCreds =\n config.accountSid &&\n config.authToken &&\n config.fromNumber &&\n config.toNumber;\n if (!hasCreds) {\n console.log(\n chalk.yellow(\n 'Note: Set Twilio environment variables to send messages'\n )\n );\n }\n });\n\n cmd\n .command('disable')\n .description('Disable SMS notifications')\n .action(() => {\n const config = loadSMSConfig();\n config.enabled = false;\n saveSMSConfig(config);\n console.log(chalk.yellow('SMS notifications disabled'));\n });\n\n cmd\n .command('test')\n .description('Send a test notification')\n .action(async () => {\n console.log(chalk.blue('Sending test notification...'));\n\n const result = await sendSMSNotification({\n type: 'custom',\n title: 'StackMemory Test',\n message: 'This is a test notification from StackMemory.',\n });\n\n if (result.success) {\n console.log(chalk.green('Test message sent successfully!'));\n } else {\n console.log(chalk.red(`Failed: ${result.error}`));\n }\n });\n\n cmd\n .command('send <message>')\n .description('Send a custom notification')\n .option('-t, --title <title>', 'Message title', 'StackMemory Alert')\n .action(async (message: string, options: { title: string }) => {\n const result = await sendSMSNotification({\n type: 'custom',\n title: options.title,\n message,\n });\n\n if (result.success) {\n console.log(chalk.green('Message sent!'));\n } else {\n console.log(chalk.red(`Failed: ${result.error}`));\n }\n });\n\n cmd\n .command('review <title>')\n .description('Send review-ready notification with options')\n .option('-m, --message <msg>', 'Description', 'Ready for your review')\n .option(\n '-o, --options <opts>',\n 'Comma-separated options',\n 'Approve,Request Changes,Skip'\n )\n .action(\n async (title: string, options: { message: string; options: string }) => {\n const opts = options.options.split(',').map((o) => ({\n label: o.trim(),\n }));\n\n console.log(chalk.blue('Sending review notification...'));\n\n const result = await notifyReviewReady(title, options.message, opts);\n\n if (result.success) {\n console.log(chalk.green('Review notification sent!'));\n if (result.promptId) {\n console.log(chalk.gray(`Prompt ID: ${result.promptId}`));\n }\n } else {\n console.log(chalk.red(`Failed: ${result.error}`));\n }\n }\n );\n\n cmd\n .command('ask <question>')\n .description('Send a yes/no prompt')\n .option('-t, --title <title>', 'Message title', 'StackMemory')\n .action(async (question: string, options: { title: string }) => {\n console.log(chalk.blue('Sending yes/no prompt...'));\n\n const result = await notifyWithYesNo(options.title, question);\n\n if (result.success) {\n console.log(chalk.green('Prompt sent!'));\n if (result.promptId) {\n console.log(chalk.gray(`Prompt ID: ${result.promptId}`));\n }\n } else {\n console.log(chalk.red(`Failed: ${result.error}`));\n }\n });\n\n cmd\n .command('complete <task>')\n .description('Send task completion notification')\n .option('-s, --summary <text>', 'Task summary', '')\n .action(async (task: string, options: { summary: string }) => {\n const result = await notifyTaskComplete(\n task,\n options.summary || `Task \"${task}\" has been completed.`\n );\n\n if (result.success) {\n console.log(chalk.green('Completion notification sent!'));\n } else {\n console.log(chalk.red(`Failed: ${result.error}`));\n }\n });\n\n cmd\n .command('quiet')\n .description('Configure quiet hours')\n .option('--enable', 'Enable quiet hours')\n .option('--disable', 'Disable quiet hours')\n .option('--start <time>', 'Start time (HH:MM)', '22:00')\n .option('--end <time>', 'End time (HH:MM)', '08:00')\n .action(\n (options: {\n enable?: boolean;\n disable?: boolean;\n start: string;\n end: string;\n }) => {\n const config = loadSMSConfig();\n\n if (!config.quietHours) {\n config.quietHours = { enabled: false, start: '22:00', end: '08:00' };\n }\n\n if (options.enable) {\n config.quietHours.enabled = true;\n } else if (options.disable) {\n config.quietHours.enabled = false;\n }\n\n if (options.start) {\n config.quietHours.start = options.start;\n }\n if (options.end) {\n config.quietHours.end = options.end;\n }\n\n saveSMSConfig(config);\n\n if (config.quietHours.enabled) {\n console.log(\n chalk.green(\n `Quiet hours enabled: ${config.quietHours.start} - ${config.quietHours.end}`\n )\n );\n } else {\n console.log(chalk.yellow('Quiet hours disabled'));\n }\n }\n );\n\n cmd\n .command('toggle <type>')\n .description(\n 'Toggle notification type (taskComplete|reviewReady|error|custom)'\n )\n .action((type: string) => {\n const config = loadSMSConfig();\n const validTypes = ['taskComplete', 'reviewReady', 'error', 'custom'];\n\n if (!validTypes.includes(type)) {\n console.log(chalk.red(`Invalid type. Use: ${validTypes.join(', ')}`));\n return;\n }\n\n const key = type as keyof typeof config.notifyOn;\n config.notifyOn[key] = !config.notifyOn[key];\n saveSMSConfig(config);\n\n console.log(\n chalk.green(\n `${type} notifications ${config.notifyOn[key] ? 'enabled' : 'disabled'}`\n )\n );\n });\n\n cmd\n .command('pending')\n .description('List pending prompts awaiting response')\n .action(() => {\n const config = loadSMSConfig();\n\n if (config.pendingPrompts.length === 0) {\n console.log(chalk.gray('No pending prompts'));\n return;\n }\n\n console.log(chalk.blue('Pending Prompts:'));\n config.pendingPrompts.forEach((p) => {\n const expires = new Date(p.expiresAt);\n const remaining = Math.round((expires.getTime() - Date.now()) / 1000);\n\n console.log();\n console.log(` ${chalk.gray('ID:')} ${p.id}`);\n console.log(` ${chalk.gray('Type:')} ${p.type}`);\n console.log(\n ` ${chalk.gray('Message:')} ${p.message.substring(0, 50)}...`\n );\n console.log(\n ` ${chalk.gray('Expires:')} ${remaining > 0 ? `${remaining}s` : chalk.red('expired')}`\n );\n });\n });\n\n cmd\n .command('cleanup')\n .description('Remove expired pending prompts')\n .action(() => {\n const removed = cleanupExpiredPrompts();\n console.log(chalk.green(`Removed ${removed} expired prompt(s)`));\n });\n\n cmd\n .command('timeout <seconds>')\n .description('Set response timeout for prompts')\n .action((seconds: string) => {\n const config = loadSMSConfig();\n const timeout = parseInt(seconds, 10);\n\n if (isNaN(timeout) || timeout < 30) {\n console.log(chalk.red('Timeout must be at least 30 seconds'));\n return;\n }\n\n config.responseTimeout = timeout;\n saveSMSConfig(config);\n console.log(chalk.green(`Response timeout set to ${timeout} seconds`));\n });\n\n return cmd;\n}\n\nfunction maskPhone(phone: string): string {\n if (phone.length < 8) return phone;\n return phone.substring(0, 4) + '****' + phone.substring(phone.length - 2);\n}\n"],
5
- "mappings": ";;;;AAIA,SAAS,eAAe;AACxB,OAAO,WAAW;AAClB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,SAAS,yBAAkC;AAChD,QAAM,MAAM,IAAI,QAAQ,QAAQ,EAC7B;AAAA,IACC;AAAA,EACF,EACC;AAAA,IACC;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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,EACvE,CAAC;AAEH,SAAO;AACT;AAEA,SAAS,UAAU,OAAuB;AACxC,MAAI,MAAM,SAAS,EAAG,QAAO;AAC7B,SAAO,MAAM,UAAU,GAAG,CAAC,IAAI,SAAS,MAAM,UAAU,MAAM,SAAS,CAAC;AAC1E;",
4
+ "sourcesContent": ["/**\n * CLI command for SMS notification management\n */\n\nimport { Command } from 'commander';\nimport chalk from 'chalk';\nimport { execSync } from 'child_process';\nimport { join } from 'path';\nimport {\n loadSMSConfig,\n saveSMSConfig,\n sendSMSNotification,\n notifyReviewReady,\n notifyWithYesNo,\n notifyTaskComplete,\n cleanupExpiredPrompts,\n} from '../../hooks/sms-notify.js';\nimport {\n loadActionQueue,\n processAllPendingActions,\n cleanupOldActions,\n startActionWatcher,\n} from '../../hooks/sms-action-runner.js';\n\n// __dirname provided by esbuild banner\n\nexport function createSMSNotifyCommand(): Command {\n const cmd = new Command('notify')\n .description(\n 'SMS notification system for review alerts (optional, requires Twilio)'\n )\n .addHelpText(\n 'after',\n `\nSetup (optional):\n 1. Create Twilio account at https://twilio.com\n 2. Get Account SID, Auth Token, and phone number\n 3. Set environment variables:\n export TWILIO_ACCOUNT_SID=your_sid\n export TWILIO_AUTH_TOKEN=your_token\n export TWILIO_FROM_NUMBER=+1234567890\n export TWILIO_TO_NUMBER=+1234567890\n 4. Enable: stackmemory notify enable\n\nExamples:\n stackmemory notify status Check configuration\n stackmemory notify enable Enable notifications\n stackmemory notify test Send test message\n stackmemory notify send \"PR ready\" Send custom message\n stackmemory notify review \"PR #123\" Send review notification with options\n stackmemory notify ask \"Deploy?\" Send yes/no prompt\n`\n );\n\n cmd\n .command('status')\n .description('Show notification configuration status')\n .action(() => {\n const config = loadSMSConfig();\n\n console.log(chalk.blue('SMS Notification Status:'));\n console.log();\n\n // Check if configured\n const hasCreds =\n config.accountSid &&\n config.authToken &&\n config.fromNumber &&\n config.toNumber;\n\n console.log(\n ` ${chalk.gray('Enabled:')} ${config.enabled ? chalk.green('yes') : chalk.red('no')}`\n );\n console.log(\n ` ${chalk.gray('Configured:')} ${hasCreds ? chalk.green('yes') : chalk.yellow('no (set env vars)')}`\n );\n\n if (config.fromNumber) {\n console.log(` ${chalk.gray('From:')} ${maskPhone(config.fromNumber)}`);\n }\n if (config.toNumber) {\n console.log(` ${chalk.gray('To:')} ${maskPhone(config.toNumber)}`);\n }\n\n console.log();\n console.log(chalk.blue('Notify On:'));\n console.log(\n ` ${chalk.gray('Task Complete:')} ${config.notifyOn.taskComplete ? 'yes' : 'no'}`\n );\n console.log(\n ` ${chalk.gray('Review Ready:')} ${config.notifyOn.reviewReady ? 'yes' : 'no'}`\n );\n console.log(\n ` ${chalk.gray('Errors:')} ${config.notifyOn.error ? 'yes' : 'no'}`\n );\n\n if (config.quietHours?.enabled) {\n console.log();\n console.log(\n chalk.blue(\n `Quiet Hours: ${config.quietHours.start} - ${config.quietHours.end}`\n )\n );\n }\n\n console.log();\n console.log(\n ` ${chalk.gray('Pending Prompts:')} ${config.pendingPrompts.length}`\n );\n console.log(\n ` ${chalk.gray('Response Timeout:')} ${config.responseTimeout}s`\n );\n\n if (!hasCreds) {\n console.log();\n console.log(\n chalk.yellow('To configure, set these environment variables:')\n );\n console.log(chalk.gray(' export TWILIO_ACCOUNT_SID=your_sid'));\n console.log(chalk.gray(' export TWILIO_AUTH_TOKEN=your_token'));\n console.log(chalk.gray(' export TWILIO_FROM_NUMBER=+1234567890'));\n console.log(chalk.gray(' export TWILIO_TO_NUMBER=+1234567890'));\n }\n });\n\n cmd\n .command('enable')\n .description('Enable SMS notifications')\n .action(() => {\n const config = loadSMSConfig();\n config.enabled = true;\n saveSMSConfig(config);\n console.log(chalk.green('SMS notifications enabled'));\n\n const hasCreds =\n config.accountSid &&\n config.authToken &&\n config.fromNumber &&\n config.toNumber;\n if (!hasCreds) {\n console.log(\n chalk.yellow(\n 'Note: Set Twilio environment variables to send messages'\n )\n );\n }\n });\n\n cmd\n .command('disable')\n .description('Disable SMS notifications')\n .action(() => {\n const config = loadSMSConfig();\n config.enabled = false;\n saveSMSConfig(config);\n console.log(chalk.yellow('SMS notifications disabled'));\n });\n\n cmd\n .command('test')\n .description('Send a test notification')\n .action(async () => {\n console.log(chalk.blue('Sending test notification...'));\n\n const result = await sendSMSNotification({\n type: 'custom',\n title: 'StackMemory Test',\n message: 'This is a test notification from StackMemory.',\n });\n\n if (result.success) {\n console.log(chalk.green('Test message sent successfully!'));\n } else {\n console.log(chalk.red(`Failed: ${result.error}`));\n }\n });\n\n cmd\n .command('send <message>')\n .description('Send a custom notification')\n .option('-t, --title <title>', 'Message title', 'StackMemory Alert')\n .action(async (message: string, options: { title: string }) => {\n const result = await sendSMSNotification({\n type: 'custom',\n title: options.title,\n message,\n });\n\n if (result.success) {\n console.log(chalk.green('Message sent!'));\n } else {\n console.log(chalk.red(`Failed: ${result.error}`));\n }\n });\n\n cmd\n .command('review <title>')\n .description('Send review-ready notification with options')\n .option('-m, --message <msg>', 'Description', 'Ready for your review')\n .option(\n '-o, --options <opts>',\n 'Comma-separated options',\n 'Approve,Request Changes,Skip'\n )\n .action(\n async (title: string, options: { message: string; options: string }) => {\n const opts = options.options.split(',').map((o) => ({\n label: o.trim(),\n }));\n\n console.log(chalk.blue('Sending review notification...'));\n\n const result = await notifyReviewReady(title, options.message, opts);\n\n if (result.success) {\n console.log(chalk.green('Review notification sent!'));\n if (result.promptId) {\n console.log(chalk.gray(`Prompt ID: ${result.promptId}`));\n }\n } else {\n console.log(chalk.red(`Failed: ${result.error}`));\n }\n }\n );\n\n cmd\n .command('ask <question>')\n .description('Send a yes/no prompt')\n .option('-t, --title <title>', 'Message title', 'StackMemory')\n .action(async (question: string, options: { title: string }) => {\n console.log(chalk.blue('Sending yes/no prompt...'));\n\n const result = await notifyWithYesNo(options.title, question);\n\n if (result.success) {\n console.log(chalk.green('Prompt sent!'));\n if (result.promptId) {\n console.log(chalk.gray(`Prompt ID: ${result.promptId}`));\n }\n } else {\n console.log(chalk.red(`Failed: ${result.error}`));\n }\n });\n\n cmd\n .command('complete <task>')\n .description('Send task completion notification')\n .option('-s, --summary <text>', 'Task summary', '')\n .action(async (task: string, options: { summary: string }) => {\n const result = await notifyTaskComplete(\n task,\n options.summary || `Task \"${task}\" has been completed.`\n );\n\n if (result.success) {\n console.log(chalk.green('Completion notification sent!'));\n } else {\n console.log(chalk.red(`Failed: ${result.error}`));\n }\n });\n\n cmd\n .command('quiet')\n .description('Configure quiet hours')\n .option('--enable', 'Enable quiet hours')\n .option('--disable', 'Disable quiet hours')\n .option('--start <time>', 'Start time (HH:MM)', '22:00')\n .option('--end <time>', 'End time (HH:MM)', '08:00')\n .action(\n (options: {\n enable?: boolean;\n disable?: boolean;\n start: string;\n end: string;\n }) => {\n const config = loadSMSConfig();\n\n if (!config.quietHours) {\n config.quietHours = { enabled: false, start: '22:00', end: '08:00' };\n }\n\n if (options.enable) {\n config.quietHours.enabled = true;\n } else if (options.disable) {\n config.quietHours.enabled = false;\n }\n\n if (options.start) {\n config.quietHours.start = options.start;\n }\n if (options.end) {\n config.quietHours.end = options.end;\n }\n\n saveSMSConfig(config);\n\n if (config.quietHours.enabled) {\n console.log(\n chalk.green(\n `Quiet hours enabled: ${config.quietHours.start} - ${config.quietHours.end}`\n )\n );\n } else {\n console.log(chalk.yellow('Quiet hours disabled'));\n }\n }\n );\n\n cmd\n .command('toggle <type>')\n .description(\n 'Toggle notification type (taskComplete|reviewReady|error|custom)'\n )\n .action((type: string) => {\n const config = loadSMSConfig();\n const validTypes = ['taskComplete', 'reviewReady', 'error', 'custom'];\n\n if (!validTypes.includes(type)) {\n console.log(chalk.red(`Invalid type. Use: ${validTypes.join(', ')}`));\n return;\n }\n\n const key = type as keyof typeof config.notifyOn;\n config.notifyOn[key] = !config.notifyOn[key];\n saveSMSConfig(config);\n\n console.log(\n chalk.green(\n `${type} notifications ${config.notifyOn[key] ? 'enabled' : 'disabled'}`\n )\n );\n });\n\n cmd\n .command('pending')\n .description('List pending prompts awaiting response')\n .action(() => {\n const config = loadSMSConfig();\n\n if (config.pendingPrompts.length === 0) {\n console.log(chalk.gray('No pending prompts'));\n return;\n }\n\n console.log(chalk.blue('Pending Prompts:'));\n config.pendingPrompts.forEach((p) => {\n const expires = new Date(p.expiresAt);\n const remaining = Math.round((expires.getTime() - Date.now()) / 1000);\n\n console.log();\n console.log(` ${chalk.gray('ID:')} ${p.id}`);\n console.log(` ${chalk.gray('Type:')} ${p.type}`);\n console.log(\n ` ${chalk.gray('Message:')} ${p.message.substring(0, 50)}...`\n );\n console.log(\n ` ${chalk.gray('Expires:')} ${remaining > 0 ? `${remaining}s` : chalk.red('expired')}`\n );\n });\n });\n\n cmd\n .command('cleanup')\n .description('Remove expired pending prompts')\n .action(() => {\n const removed = cleanupExpiredPrompts();\n console.log(chalk.green(`Removed ${removed} expired prompt(s)`));\n });\n\n cmd\n .command('timeout <seconds>')\n .description('Set response timeout for prompts')\n .action((seconds: string) => {\n const config = loadSMSConfig();\n const timeout = parseInt(seconds, 10);\n\n if (isNaN(timeout) || timeout < 30) {\n console.log(chalk.red('Timeout must be at least 30 seconds'));\n return;\n }\n\n config.responseTimeout = timeout;\n saveSMSConfig(config);\n console.log(chalk.green(`Response timeout set to ${timeout} seconds`));\n });\n\n // Action queue commands\n cmd\n .command('actions')\n .description('List queued actions from SMS responses')\n .action(() => {\n const queue = loadActionQueue();\n\n if (queue.actions.length === 0) {\n console.log(chalk.gray('No actions in queue'));\n return;\n }\n\n console.log(chalk.blue('Action Queue:'));\n queue.actions.forEach((a) => {\n const statusColor =\n a.status === 'completed'\n ? chalk.green\n : a.status === 'failed'\n ? chalk.red\n : a.status === 'running'\n ? chalk.yellow\n : chalk.gray;\n\n console.log();\n console.log(` ${chalk.gray('ID:')} ${a.id}`);\n console.log(` ${chalk.gray('Status:')} ${statusColor(a.status)}`);\n console.log(\n ` ${chalk.gray('Action:')} ${a.action.substring(0, 60)}...`\n );\n console.log(` ${chalk.gray('Response:')} ${a.response}`);\n if (a.error) {\n console.log(` ${chalk.gray('Error:')} ${chalk.red(a.error)}`);\n }\n });\n });\n\n cmd\n .command('run-actions')\n .description('Execute all pending actions from SMS responses')\n .action(() => {\n console.log(chalk.blue('Processing pending actions...'));\n const result = processAllPendingActions();\n\n console.log(\n chalk.green(\n `Processed ${result.processed} action(s): ${result.succeeded} succeeded, ${result.failed} failed`\n )\n );\n });\n\n cmd\n .command('watch')\n .description('Watch for and execute SMS response actions')\n .option('-i, --interval <ms>', 'Check interval in milliseconds', '5000')\n .action((options: { interval: string }) => {\n const interval = parseInt(options.interval, 10);\n console.log(chalk.blue(`Watching for actions (interval: ${interval}ms)`));\n console.log(chalk.gray('Press Ctrl+C to stop'));\n\n startActionWatcher(interval);\n });\n\n cmd\n .command('cleanup-actions')\n .description('Remove old completed actions')\n .action(() => {\n const removed = cleanupOldActions();\n console.log(chalk.green(`Removed ${removed} old action(s)`));\n });\n\n // Hook installation commands\n cmd\n .command('install-hook')\n .description('Install Claude Code notification hook')\n .action(() => {\n try {\n const scriptPath = join(\n __dirname,\n '../../../scripts/install-notify-hook.sh'\n );\n execSync(`bash \"${scriptPath}\"`, { stdio: 'inherit' });\n } catch {\n console.error(chalk.red('Failed to install hook'));\n }\n });\n\n cmd\n .command('install-response-hook')\n .description('Install Claude Code response handler hook')\n .action(() => {\n try {\n // Create install script inline\n const hooksDir = join(process.env['HOME'] || '~', '.claude', 'hooks');\n const hookSrc = join(\n __dirname,\n '../../../templates/claude-hooks/sms-response-handler.js'\n );\n const hookDest = join(hooksDir, 'sms-response-handler.js');\n\n execSync(`mkdir -p \"${hooksDir}\"`, { stdio: 'inherit' });\n execSync(`cp \"${hookSrc}\" \"${hookDest}\"`, { stdio: 'inherit' });\n execSync(`chmod +x \"${hookDest}\"`, { stdio: 'inherit' });\n\n console.log(chalk.green('Response handler hook installed!'));\n console.log(chalk.gray(`Location: ${hookDest}`));\n console.log();\n console.log(chalk.blue('Add to ~/.claude/settings.json:'));\n console.log(\n chalk.gray(` \"hooks\": { \"pre_tool_use\": [\"node ${hookDest}\"] }`)\n );\n } catch {\n console.error(chalk.red('Failed to install response hook'));\n }\n });\n\n cmd\n .command('webhook')\n .description('Start SMS webhook server for receiving responses')\n .option('-p, --port <port>', 'Port to listen on', '3456')\n .action(async (options: { port: string }) => {\n const { startWebhookServer } = await import('../../hooks/sms-webhook.js');\n const port = parseInt(options.port, 10);\n startWebhookServer(port);\n });\n\n return cmd;\n}\n\nfunction maskPhone(phone: string): string {\n if (phone.length < 8) return phone;\n return phone.substring(0, 4) + '****' + phone.substring(phone.length - 2);\n}\n"],
5
+ "mappings": ";;;;AAIA,SAAS,eAAe;AACxB,OAAO,WAAW;AAClB,SAAS,gBAAgB;AACzB,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIA,SAAS,yBAAkC;AAChD,QAAM,MAAM,IAAI,QAAQ,QAAQ,EAC7B;AAAA,IACC;AAAA,EACF,EACC;AAAA,IACC;AAAA,IACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBF;AAEF,MACG,QAAQ,QAAQ,EAChB,YAAY,wCAAwC,EACpD,OAAO,MAAM;AACZ,UAAM,SAAS,cAAc;AAE7B,YAAQ,IAAI,MAAM,KAAK,0BAA0B,CAAC;AAClD,YAAQ,IAAI;AAGZ,UAAM,WACJ,OAAO,cACP,OAAO,aACP,OAAO,cACP,OAAO;AAET,YAAQ;AAAA,MACN,KAAK,MAAM,KAAK,UAAU,CAAC,IAAI,OAAO,UAAU,MAAM,MAAM,KAAK,IAAI,MAAM,IAAI,IAAI,CAAC;AAAA,IACtF;AACA,YAAQ;AAAA,MACN,KAAK,MAAM,KAAK,aAAa,CAAC,IAAI,WAAW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O;AACT;AAEA,SAAS,UAAU,OAAuB;AACxC,MAAI,MAAM,SAAS,EAAG,QAAO;AAC7B,SAAO,MAAM,UAAU,GAAG,CAAC,IAAI,SAAS,MAAM,UAAU,MAAM,SAAS,CAAC;AAC1E;",
6
6
  "names": []
7
7
  }
@@ -8,4 +8,5 @@ export * from "./daemon.js";
8
8
  export * from "./auto-background.js";
9
9
  export * from "./sms-notify.js";
10
10
  export * from "./sms-webhook.js";
11
+ export * from "./sms-action-runner.js";
11
12
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/index.ts"],
4
- "sourcesContent": ["/**\n * StackMemory Hooks Module\n * User-configurable hook system for automation and suggestions\n */\n\nexport * from './events.js';\nexport * from './config.js';\nexport * from './daemon.js';\nexport * from './auto-background.js';\nexport * from './sms-notify.js';\nexport * from './sms-webhook.js';\n"],
5
- "mappings": ";;;;AAKA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
4
+ "sourcesContent": ["/**\n * StackMemory Hooks Module\n * User-configurable hook system for automation and suggestions\n */\n\nexport * from './events.js';\nexport * from './config.js';\nexport * from './daemon.js';\nexport * from './auto-background.js';\nexport * from './sms-notify.js';\nexport * from './sms-webhook.js';\nexport * from './sms-action-runner.js';\n"],
5
+ "mappings": ";;;;AAKA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,170 @@
1
+ import { fileURLToPath as __fileURLToPath } from 'url';
2
+ import { dirname as __pathDirname } from 'path';
3
+ const __filename = __fileURLToPath(import.meta.url);
4
+ const __dirname = __pathDirname(__filename);
5
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
6
+ import { join } from "path";
7
+ import { homedir } from "os";
8
+ import { execSync } from "child_process";
9
+ const QUEUE_PATH = join(homedir(), ".stackmemory", "sms-action-queue.json");
10
+ function loadActionQueue() {
11
+ try {
12
+ if (existsSync(QUEUE_PATH)) {
13
+ return JSON.parse(readFileSync(QUEUE_PATH, "utf8"));
14
+ }
15
+ } catch {
16
+ }
17
+ return { actions: [], lastChecked: (/* @__PURE__ */ new Date()).toISOString() };
18
+ }
19
+ function saveActionQueue(queue) {
20
+ try {
21
+ const dir = join(homedir(), ".stackmemory");
22
+ if (!existsSync(dir)) {
23
+ mkdirSync(dir, { recursive: true });
24
+ }
25
+ writeFileSync(QUEUE_PATH, JSON.stringify(queue, null, 2));
26
+ } catch {
27
+ }
28
+ }
29
+ function queueAction(promptId, response, action) {
30
+ const queue = loadActionQueue();
31
+ const id = Math.random().toString(36).substring(2, 10);
32
+ queue.actions.push({
33
+ id,
34
+ promptId,
35
+ response,
36
+ action,
37
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
38
+ status: "pending"
39
+ });
40
+ saveActionQueue(queue);
41
+ return id;
42
+ }
43
+ function getPendingActions() {
44
+ const queue = loadActionQueue();
45
+ return queue.actions.filter((a) => a.status === "pending");
46
+ }
47
+ function markActionRunning(id) {
48
+ const queue = loadActionQueue();
49
+ const action = queue.actions.find((a) => a.id === id);
50
+ if (action) {
51
+ action.status = "running";
52
+ saveActionQueue(queue);
53
+ }
54
+ }
55
+ function markActionCompleted(id, result, error) {
56
+ const queue = loadActionQueue();
57
+ const action = queue.actions.find((a) => a.id === id);
58
+ if (action) {
59
+ action.status = error ? "failed" : "completed";
60
+ action.result = result;
61
+ action.error = error;
62
+ saveActionQueue(queue);
63
+ }
64
+ }
65
+ function executeAction(action) {
66
+ markActionRunning(action.id);
67
+ try {
68
+ console.log(`[sms-action] Executing: ${action.action}`);
69
+ const output = execSync(action.action, {
70
+ encoding: "utf8",
71
+ timeout: 6e4,
72
+ // 1 minute timeout
73
+ stdio: ["pipe", "pipe", "pipe"]
74
+ });
75
+ markActionCompleted(action.id, output);
76
+ return { success: true, output };
77
+ } catch (err) {
78
+ const error = err instanceof Error ? err.message : String(err);
79
+ markActionCompleted(action.id, void 0, error);
80
+ return { success: false, error };
81
+ }
82
+ }
83
+ function processAllPendingActions() {
84
+ const pending = getPendingActions();
85
+ let succeeded = 0;
86
+ let failed = 0;
87
+ for (const action of pending) {
88
+ const result = executeAction(action);
89
+ if (result.success) {
90
+ succeeded++;
91
+ } else {
92
+ failed++;
93
+ }
94
+ }
95
+ return { processed: pending.length, succeeded, failed };
96
+ }
97
+ function cleanupOldActions() {
98
+ const queue = loadActionQueue();
99
+ const completed = queue.actions.filter(
100
+ (a) => a.status === "completed" || a.status === "failed"
101
+ );
102
+ if (completed.length > 50) {
103
+ const toRemove = completed.slice(0, completed.length - 50);
104
+ queue.actions = queue.actions.filter(
105
+ (a) => !toRemove.find((r) => r.id === a.id)
106
+ );
107
+ saveActionQueue(queue);
108
+ return toRemove.length;
109
+ }
110
+ return 0;
111
+ }
112
+ const ACTION_TEMPLATES = {
113
+ // Git/PR actions
114
+ approvePR: (prNumber) => `gh pr review ${prNumber} --approve && gh pr merge ${prNumber} --auto`,
115
+ requestChanges: (prNumber) => `gh pr review ${prNumber} --request-changes -b "Changes requested via SMS"`,
116
+ mergePR: (prNumber) => `gh pr merge ${prNumber} --squash`,
117
+ closePR: (prNumber) => `gh pr close ${prNumber}`,
118
+ // Deployment actions
119
+ deploy: (env = "production") => `npm run deploy:${env}`,
120
+ rollback: (env = "production") => `npm run rollback:${env}`,
121
+ verifyDeployment: (url) => `curl -sf ${url}/health || exit 1`,
122
+ // Build actions
123
+ rebuild: () => `npm run build`,
124
+ retest: () => `npm test`,
125
+ lint: () => `npm run lint:fix`,
126
+ // Notification actions
127
+ notifySlack: (message) => `curl -X POST $SLACK_WEBHOOK -d '{"text":"${message}"}'`,
128
+ notifyTeam: (message) => `stackmemory notify send "${message}" --title "Team Alert"`
129
+ };
130
+ function createAction(template, ...args) {
131
+ const fn = ACTION_TEMPLATES[template];
132
+ if (typeof fn === "function") {
133
+ return fn(...args);
134
+ }
135
+ return fn;
136
+ }
137
+ function startActionWatcher(intervalMs = 5e3) {
138
+ console.log(
139
+ `[sms-action] Starting action watcher (interval: ${intervalMs}ms)`
140
+ );
141
+ return setInterval(() => {
142
+ const pending = getPendingActions();
143
+ if (pending.length > 0) {
144
+ console.log(`[sms-action] Found ${pending.length} pending action(s)`);
145
+ processAllPendingActions();
146
+ }
147
+ }, intervalMs);
148
+ }
149
+ function handleSMSResponse(promptId, response, action) {
150
+ if (action) {
151
+ const actionId = queueAction(promptId, response, action);
152
+ console.log(`[sms-action] Queued action ${actionId}: ${action}`);
153
+ }
154
+ }
155
+ export {
156
+ ACTION_TEMPLATES,
157
+ cleanupOldActions,
158
+ createAction,
159
+ executeAction,
160
+ getPendingActions,
161
+ handleSMSResponse,
162
+ loadActionQueue,
163
+ markActionCompleted,
164
+ markActionRunning,
165
+ processAllPendingActions,
166
+ queueAction,
167
+ saveActionQueue,
168
+ startActionWatcher
169
+ };
170
+ //# sourceMappingURL=sms-action-runner.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/hooks/sms-action-runner.ts"],
4
+ "sourcesContent": ["/**\n * SMS Action Runner - Executes actions based on SMS responses\n * Bridges SMS responses to Claude Code actions\n */\n\nimport { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport { execSync } from 'child_process';\n\nexport interface PendingAction {\n id: string;\n promptId: string;\n response: string;\n action: string;\n timestamp: string;\n status: 'pending' | 'running' | 'completed' | 'failed';\n result?: string;\n error?: string;\n}\n\nexport interface ActionQueue {\n actions: PendingAction[];\n lastChecked: string;\n}\n\nconst QUEUE_PATH = join(homedir(), '.stackmemory', 'sms-action-queue.json');\n\nexport function loadActionQueue(): ActionQueue {\n try {\n if (existsSync(QUEUE_PATH)) {\n return JSON.parse(readFileSync(QUEUE_PATH, 'utf8'));\n }\n } catch {\n // Use defaults\n }\n return { actions: [], lastChecked: new Date().toISOString() };\n}\n\nexport function saveActionQueue(queue: ActionQueue): void {\n try {\n const dir = join(homedir(), '.stackmemory');\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n writeFileSync(QUEUE_PATH, JSON.stringify(queue, null, 2));\n } catch {\n // Silently fail\n }\n}\n\nexport function queueAction(\n promptId: string,\n response: string,\n action: string\n): string {\n const queue = loadActionQueue();\n const id = Math.random().toString(36).substring(2, 10);\n\n queue.actions.push({\n id,\n promptId,\n response,\n action,\n timestamp: new Date().toISOString(),\n status: 'pending',\n });\n\n saveActionQueue(queue);\n return id;\n}\n\nexport function getPendingActions(): PendingAction[] {\n const queue = loadActionQueue();\n return queue.actions.filter((a) => a.status === 'pending');\n}\n\nexport function markActionRunning(id: string): void {\n const queue = loadActionQueue();\n const action = queue.actions.find((a) => a.id === id);\n if (action) {\n action.status = 'running';\n saveActionQueue(queue);\n }\n}\n\nexport function markActionCompleted(\n id: string,\n result?: string,\n error?: string\n): void {\n const queue = loadActionQueue();\n const action = queue.actions.find((a) => a.id === id);\n if (action) {\n action.status = error ? 'failed' : 'completed';\n action.result = result;\n action.error = error;\n saveActionQueue(queue);\n }\n}\n\nexport function executeAction(action: PendingAction): {\n success: boolean;\n output?: string;\n error?: string;\n} {\n markActionRunning(action.id);\n\n try {\n console.log(`[sms-action] Executing: ${action.action}`);\n\n // Execute the action\n const output = execSync(action.action, {\n encoding: 'utf8',\n timeout: 60000, // 1 minute timeout\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n\n markActionCompleted(action.id, output);\n return { success: true, output };\n } catch (err) {\n const error = err instanceof Error ? err.message : String(err);\n markActionCompleted(action.id, undefined, error);\n return { success: false, error };\n }\n}\n\nexport function processAllPendingActions(): {\n processed: number;\n succeeded: number;\n failed: number;\n} {\n const pending = getPendingActions();\n let succeeded = 0;\n let failed = 0;\n\n for (const action of pending) {\n const result = executeAction(action);\n if (result.success) {\n succeeded++;\n } else {\n failed++;\n }\n }\n\n return { processed: pending.length, succeeded, failed };\n}\n\n// Clean up old completed actions (keep last 50)\nexport function cleanupOldActions(): number {\n const queue = loadActionQueue();\n const completed = queue.actions.filter(\n (a) => a.status === 'completed' || a.status === 'failed'\n );\n\n if (completed.length > 50) {\n const toRemove = completed.slice(0, completed.length - 50);\n queue.actions = queue.actions.filter(\n (a) => !toRemove.find((r) => r.id === a.id)\n );\n saveActionQueue(queue);\n return toRemove.length;\n }\n\n return 0;\n}\n\n/**\n * Action Templates - Common actions for SMS responses\n */\nexport const ACTION_TEMPLATES = {\n // Git/PR actions\n approvePR: (prNumber: string) =>\n `gh pr review ${prNumber} --approve && gh pr merge ${prNumber} --auto`,\n requestChanges: (prNumber: string) =>\n `gh pr review ${prNumber} --request-changes -b \"Changes requested via SMS\"`,\n mergePR: (prNumber: string) => `gh pr merge ${prNumber} --squash`,\n closePR: (prNumber: string) => `gh pr close ${prNumber}`,\n\n // Deployment actions\n deploy: (env: string = 'production') => `npm run deploy:${env}`,\n rollback: (env: string = 'production') => `npm run rollback:${env}`,\n verifyDeployment: (url: string) => `curl -sf ${url}/health || exit 1`,\n\n // Build actions\n rebuild: () => `npm run build`,\n retest: () => `npm test`,\n lint: () => `npm run lint:fix`,\n\n // Notification actions\n notifySlack: (message: string) =>\n `curl -X POST $SLACK_WEBHOOK -d '{\"text\":\"${message}\"}'`,\n notifyTeam: (message: string) =>\n `stackmemory notify send \"${message}\" --title \"Team Alert\"`,\n};\n\n/**\n * Create action string from template\n */\nexport function createAction(\n template: keyof typeof ACTION_TEMPLATES,\n ...args: string[]\n): string {\n const fn = ACTION_TEMPLATES[template];\n if (typeof fn === 'function') {\n return (fn as (...args: string[]) => string)(...args);\n }\n return fn;\n}\n\n/**\n * Watch for new actions and execute them\n */\nexport function startActionWatcher(intervalMs: number = 5000): NodeJS.Timeout {\n console.log(\n `[sms-action] Starting action watcher (interval: ${intervalMs}ms)`\n );\n\n return setInterval(() => {\n const pending = getPendingActions();\n if (pending.length > 0) {\n console.log(`[sms-action] Found ${pending.length} pending action(s)`);\n processAllPendingActions();\n }\n }, intervalMs);\n}\n\n/**\n * Integration with SMS webhook - queue action when response received\n */\nexport function handleSMSResponse(\n promptId: string,\n response: string,\n action?: string\n): void {\n if (action) {\n const actionId = queueAction(promptId, response, action);\n console.log(`[sms-action] Queued action ${actionId}: ${action}`);\n }\n}\n"],
5
+ "mappings": ";;;;AAKA,SAAS,YAAY,cAAc,eAAe,iBAAiB;AACnE,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,gBAAgB;AAkBzB,MAAM,aAAa,KAAK,QAAQ,GAAG,gBAAgB,uBAAuB;AAEnE,SAAS,kBAA+B;AAC7C,MAAI;AACF,QAAI,WAAW,UAAU,GAAG;AAC1B,aAAO,KAAK,MAAM,aAAa,YAAY,MAAM,CAAC;AAAA,IACpD;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO,EAAE,SAAS,CAAC,GAAG,cAAa,oBAAI,KAAK,GAAE,YAAY,EAAE;AAC9D;AAEO,SAAS,gBAAgB,OAA0B;AACxD,MAAI;AACF,UAAM,MAAM,KAAK,QAAQ,GAAG,cAAc;AAC1C,QAAI,CAAC,WAAW,GAAG,GAAG;AACpB,gBAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,IACpC;AACA,kBAAc,YAAY,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAAA,EAC1D,QAAQ;AAAA,EAER;AACF;AAEO,SAAS,YACd,UACA,UACA,QACQ;AACR,QAAM,QAAQ,gBAAgB;AAC9B,QAAM,KAAK,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,EAAE;AAErD,QAAM,QAAQ,KAAK;AAAA,IACjB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IAClC,QAAQ;AAAA,EACV,CAAC;AAED,kBAAgB,KAAK;AACrB,SAAO;AACT;AAEO,SAAS,oBAAqC;AACnD,QAAM,QAAQ,gBAAgB;A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AA,IACN,mDAAmD,UAAU;AAAA,EAC/D;AAEA,SAAO,YAAY,MAAM;AACvB,UAAM,UAAU,kBAAkB;AAClC,QAAI,QAAQ,SAAS,GAAG;AACtB,cAAQ,IAAI,sBAAsB,QAAQ,MAAM,oBAAoB;AACpE,+BAAyB;AAAA,IAC3B;AAAA,EACF,GAAG,UAAU;AACf;AAKO,SAAS,kBACd,UACA,UACA,QACM;AACN,MAAI,QAAQ;AACV,UAAM,WAAW,YAAY,UAAU,UAAU,MAAM;AACvD,YAAQ,IAAI,8BAA8B,QAAQ,KAAK,MAAM,EAAE;AAAA,EACjE;AACF;",
6
+ "names": []
7
+ }
@@ -4,8 +4,11 @@ const __filename = __fileURLToPath(import.meta.url);
4
4
  const __dirname = __pathDirname(__filename);
5
5
  import { createServer } from "http";
6
6
  import { parse as parseUrl } from "url";
7
+ import { existsSync, writeFileSync, mkdirSync } from "fs";
8
+ import { join } from "path";
9
+ import { homedir } from "os";
7
10
  import { processIncomingResponse, loadSMSConfig } from "./sms-notify.js";
8
- import { execSync } from "child_process";
11
+ import { queueAction } from "./sms-action-runner.js";
9
12
  function parseFormData(body) {
10
13
  const params = new URLSearchParams(body);
11
14
  const result = {};
@@ -14,6 +17,22 @@ function parseFormData(body) {
14
17
  });
15
18
  return result;
16
19
  }
20
+ function storeLatestResponse(promptId, response, action) {
21
+ const dir = join(homedir(), ".stackmemory");
22
+ if (!existsSync(dir)) {
23
+ mkdirSync(dir, { recursive: true });
24
+ }
25
+ const responsePath = join(dir, "sms-latest-response.json");
26
+ writeFileSync(
27
+ responsePath,
28
+ JSON.stringify({
29
+ promptId,
30
+ response,
31
+ action,
32
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
33
+ })
34
+ );
35
+ }
17
36
  function handleSMSWebhook(payload) {
18
37
  const { From, Body } = payload;
19
38
  console.log(`[sms-webhook] Received from ${From}: ${Body}`);
@@ -26,23 +45,26 @@ function handleSMSWebhook(payload) {
26
45
  }
27
46
  return { response: "No pending prompt found." };
28
47
  }
48
+ storeLatestResponse(
49
+ result.prompt?.id || "unknown",
50
+ result.response || Body,
51
+ result.action
52
+ );
29
53
  if (result.action) {
30
- try {
31
- console.log(`[sms-webhook] Executing action: ${result.action}`);
32
- execSync(result.action, { stdio: "inherit" });
33
- return {
34
- response: `Got it! Executing: ${result.action}`,
35
- action: result.action
36
- };
37
- } catch {
38
- return {
39
- response: `Received "${result.response}" but action failed.`,
40
- action: result.action
41
- };
42
- }
54
+ const actionId = queueAction(
55
+ result.prompt?.id || "unknown",
56
+ result.response || Body,
57
+ result.action
58
+ );
59
+ console.log(`[sms-webhook] Queued action ${actionId}: ${result.action}`);
60
+ return {
61
+ response: `Got it! Queued action: ${result.action.substring(0, 30)}...`,
62
+ action: result.action,
63
+ queued: true
64
+ };
43
65
  }
44
66
  return {
45
- response: `Received: ${result.response}`
67
+ response: `Received: ${result.response}. Next action will be triggered.`
46
68
  };
47
69
  }
48
70
  function twimlResponse(message) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/hooks/sms-webhook.ts"],
4
- "sourcesContent": ["/**\n * SMS Webhook Handler for receiving Twilio responses\n * Can run as standalone server or integrate with existing Express app\n */\n\nimport { createServer, IncomingMessage, ServerResponse } from 'http';\nimport { parse as parseUrl } from 'url';\nimport { processIncomingResponse, loadSMSConfig } from './sms-notify.js';\nimport { execSync } from 'child_process';\n\ninterface TwilioWebhookPayload {\n From: string;\n To: string;\n Body: string;\n MessageSid: string;\n}\n\nfunction parseFormData(body: string): Record<string, string> {\n const params = new URLSearchParams(body);\n const result: Record<string, string> = {};\n params.forEach((value, key) => {\n result[key] = value;\n });\n return result;\n}\n\nexport function handleSMSWebhook(payload: TwilioWebhookPayload): {\n response: string;\n action?: string;\n} {\n const { From, Body } = payload;\n\n console.log(`[sms-webhook] Received from ${From}: ${Body}`);\n\n const result = processIncomingResponse(From, Body);\n\n if (!result.matched) {\n if (result.prompt) {\n return {\n response: `Invalid response. Expected: ${result.prompt.options.map((o) => o.key).join(', ')}`,\n };\n }\n return { response: 'No pending prompt found.' };\n }\n\n // Execute action if specified\n if (result.action) {\n try {\n console.log(`[sms-webhook] Executing action: ${result.action}`);\n execSync(result.action, { stdio: 'inherit' });\n return {\n response: `Got it! Executing: ${result.action}`,\n action: result.action,\n };\n } catch {\n return {\n response: `Received \"${result.response}\" but action failed.`,\n action: result.action,\n };\n }\n }\n\n return {\n response: `Received: ${result.response}`,\n };\n}\n\n// TwiML response helper\nfunction twimlResponse(message: string): string {\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <Message>${escapeXml(message)}</Message>\n</Response>`;\n}\n\nfunction escapeXml(str: string): string {\n return str\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&apos;');\n}\n\n// Standalone webhook server\nexport function startWebhookServer(port: number = 3456): void {\n const server = createServer(\n async (req: IncomingMessage, res: ServerResponse) => {\n const url = parseUrl(req.url || '/', true);\n\n // Health check\n if (url.pathname === '/health') {\n res.writeHead(200, { 'Content-Type': 'application/json' });\n res.end(JSON.stringify({ status: 'ok' }));\n return;\n }\n\n // SMS webhook endpoint\n if (url.pathname === '/sms' && req.method === 'POST') {\n let body = '';\n req.on('data', (chunk) => {\n body += chunk;\n });\n\n req.on('end', () => {\n try {\n const payload = parseFormData(\n body\n ) as unknown as TwilioWebhookPayload;\n const result = handleSMSWebhook(payload);\n\n res.writeHead(200, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse(result.response));\n } catch (err) {\n console.error('[sms-webhook] Error:', err);\n res.writeHead(500, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse('Error processing message'));\n }\n });\n return;\n }\n\n // Status endpoint\n if (url.pathname === '/status') {\n const config = loadSMSConfig();\n res.writeHead(200, { 'Content-Type': 'application/json' });\n res.end(\n JSON.stringify({\n enabled: config.enabled,\n pendingPrompts: config.pendingPrompts.length,\n })\n );\n return;\n }\n\n res.writeHead(404);\n res.end('Not found');\n }\n );\n\n server.listen(port, () => {\n console.log(`[sms-webhook] Server listening on port ${port}`);\n console.log(`[sms-webhook] Webhook URL: http://localhost:${port}/sms`);\n console.log(`[sms-webhook] Configure this URL in Twilio console`);\n });\n}\n\n// Express middleware for integration\nexport function smsWebhookMiddleware(\n req: { body: TwilioWebhookPayload },\n res: { type: (t: string) => void; send: (s: string) => void }\n): void {\n const result = handleSMSWebhook(req.body);\n res.type('text/xml');\n res.send(twimlResponse(result.response));\n}\n\n// CLI entry\nif (process.argv[1]?.endsWith('sms-webhook.js')) {\n const port = parseInt(process.env['SMS_WEBHOOK_PORT'] || '3456', 10);\n startWebhookServer(port);\n}\n"],
5
- "mappings": ";;;;AAKA,SAAS,oBAAqD;AAC9D,SAAS,SAAS,gBAAgB;AAClC,SAAS,yBAAyB,qBAAqB;AACvD,SAAS,gBAAgB;AASzB,SAAS,cAAc,MAAsC;AAC3D,QAAM,SAAS,IAAI,gBAAgB,IAAI;AACvC,QAAM,SAAiC,CAAC;AACxC,SAAO,QAAQ,CAAC,OAAO,QAAQ;AAC7B,WAAO,GAAG,IAAI;AAAA,EAChB,CAAC;AACD,SAAO;AACT;AAEO,SAAS,iBAAiB,SAG/B;AACA,QAAM,EAAE,MAAM,KAAK,IAAI;AAEvB,UAAQ,IAAI,+BAA+B,IAAI,KAAK,IAAI,EAAE;AAE1D,QAAM,SAAS,wBAAwB,MAAM,IAAI;AAEjD,MAAI,CAAC,OAAO,SAAS;AACnB,QAAI,OAAO,QAAQ;AACjB,aAAO;AAAA,QACL,UAAU,+BAA+B,OAAO,OAAO,QAAQ,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAAA,MAC7F;AAAA,IACF;AACA,WAAO,EAAE,UAAU,2BAA2B;AAAA,EAChD;AAGA,MAAI,OAAO,QAAQ;AACjB,QAAI;AACF,cAAQ,IAAI,mCAAmC,OAAO,MAAM,EAAE;AA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,UACxC,SAAS,KAAK;AACZ,oBAAQ,MAAM,wBAAwB,GAAG;AACzC,gBAAI,UAAU,KAAK,EAAE,gBAAgB,WAAW,CAAC;AACjD,gBAAI,IAAI,cAAc,0BAA0B,CAAC;AAAA,UACnD;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAGA,UAAI,IAAI,aAAa,WAAW;AAC9B,cAAM,SAAS,cAAc;AAC7B,YAAI,UAAU,KAAK,EAAE,gBAAgB,mBAAmB,CAAC;AACzD,YAAI;AAAA,UACF,KAAK,UAAU;AAAA,YACb,SAAS,OAAO;AAAA,YAChB,gBAAgB,OAAO,eAAe;AAAA,UACxC,CAAC;AAAA,QACH;AACA;AAAA,MACF;AAEA,UAAI,UAAU,GAAG;AACjB,UAAI,IAAI,WAAW;AAAA,IACrB;AAAA,EACF;AAEA,SAAO,OAAO,MAAM,MAAM;AACxB,YAAQ,IAAI,0CAA0C,IAAI,EAAE;AAC5D,YAAQ,IAAI,+CAA+C,IAAI,MAAM;AACrE,YAAQ,IAAI,oDAAoD;AAAA,EAClE,CAAC;AACH;AAGO,SAAS,qBACd,KACA,KACM;AACN,QAAM,SAAS,iBAAiB,IAAI,IAAI;AACxC,MAAI,KAAK,UAAU;AACnB,MAAI,KAAK,cAAc,OAAO,QAAQ,CAAC;AACzC;AAGA,IAAI,QAAQ,KAAK,CAAC,GAAG,SAAS,gBAAgB,GAAG;AAC/C,QAAM,OAAO,SAAS,QAAQ,IAAI,kBAAkB,KAAK,QAAQ,EAAE;AACnE,qBAAmB,IAAI;AACzB;",
4
+ "sourcesContent": ["/**\n * SMS Webhook Handler for receiving Twilio responses\n * Can run as standalone server or integrate with existing Express app\n */\n\nimport { createServer, IncomingMessage, ServerResponse } from 'http';\nimport { parse as parseUrl } from 'url';\nimport { existsSync, writeFileSync, mkdirSync } from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport { processIncomingResponse, loadSMSConfig } from './sms-notify.js';\nimport { queueAction } from './sms-action-runner.js';\n\ninterface TwilioWebhookPayload {\n From: string;\n To: string;\n Body: string;\n MessageSid: string;\n}\n\nfunction parseFormData(body: string): Record<string, string> {\n const params = new URLSearchParams(body);\n const result: Record<string, string> = {};\n params.forEach((value, key) => {\n result[key] = value;\n });\n return result;\n}\n\n// Store response for Claude hook to pick up\nfunction storeLatestResponse(\n promptId: string,\n response: string,\n action?: string\n): void {\n const dir = join(homedir(), '.stackmemory');\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n const responsePath = join(dir, 'sms-latest-response.json');\n writeFileSync(\n responsePath,\n JSON.stringify({\n promptId,\n response,\n action,\n timestamp: new Date().toISOString(),\n })\n );\n}\n\nexport function handleSMSWebhook(payload: TwilioWebhookPayload): {\n response: string;\n action?: string;\n queued?: boolean;\n} {\n const { From, Body } = payload;\n\n console.log(`[sms-webhook] Received from ${From}: ${Body}`);\n\n const result = processIncomingResponse(From, Body);\n\n if (!result.matched) {\n if (result.prompt) {\n return {\n response: `Invalid response. Expected: ${result.prompt.options.map((o) => o.key).join(', ')}`,\n };\n }\n return { response: 'No pending prompt found.' };\n }\n\n // Store response for Claude hook\n storeLatestResponse(\n result.prompt?.id || 'unknown',\n result.response || Body,\n result.action\n );\n\n // Queue action for execution (instead of immediate execution)\n if (result.action) {\n const actionId = queueAction(\n result.prompt?.id || 'unknown',\n result.response || Body,\n result.action\n );\n console.log(`[sms-webhook] Queued action ${actionId}: ${result.action}`);\n\n return {\n response: `Got it! Queued action: ${result.action.substring(0, 30)}...`,\n action: result.action,\n queued: true,\n };\n }\n\n return {\n response: `Received: ${result.response}. Next action will be triggered.`,\n };\n}\n\n// TwiML response helper\nfunction twimlResponse(message: string): string {\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Response>\n <Message>${escapeXml(message)}</Message>\n</Response>`;\n}\n\nfunction escapeXml(str: string): string {\n return str\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;')\n .replace(/'/g, '&apos;');\n}\n\n// Standalone webhook server\nexport function startWebhookServer(port: number = 3456): void {\n const server = createServer(\n async (req: IncomingMessage, res: ServerResponse) => {\n const url = parseUrl(req.url || '/', true);\n\n // Health check\n if (url.pathname === '/health') {\n res.writeHead(200, { 'Content-Type': 'application/json' });\n res.end(JSON.stringify({ status: 'ok' }));\n return;\n }\n\n // SMS webhook endpoint\n if (url.pathname === '/sms' && req.method === 'POST') {\n let body = '';\n req.on('data', (chunk) => {\n body += chunk;\n });\n\n req.on('end', () => {\n try {\n const payload = parseFormData(\n body\n ) as unknown as TwilioWebhookPayload;\n const result = handleSMSWebhook(payload);\n\n res.writeHead(200, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse(result.response));\n } catch (err) {\n console.error('[sms-webhook] Error:', err);\n res.writeHead(500, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse('Error processing message'));\n }\n });\n return;\n }\n\n // Status endpoint\n if (url.pathname === '/status') {\n const config = loadSMSConfig();\n res.writeHead(200, { 'Content-Type': 'application/json' });\n res.end(\n JSON.stringify({\n enabled: config.enabled,\n pendingPrompts: config.pendingPrompts.length,\n })\n );\n return;\n }\n\n res.writeHead(404);\n res.end('Not found');\n }\n );\n\n server.listen(port, () => {\n console.log(`[sms-webhook] Server listening on port ${port}`);\n console.log(`[sms-webhook] Webhook URL: http://localhost:${port}/sms`);\n console.log(`[sms-webhook] Configure this URL in Twilio console`);\n });\n}\n\n// Express middleware for integration\nexport function smsWebhookMiddleware(\n req: { body: TwilioWebhookPayload },\n res: { type: (t: string) => void; send: (s: string) => void }\n): void {\n const result = handleSMSWebhook(req.body);\n res.type('text/xml');\n res.send(twimlResponse(result.response));\n}\n\n// CLI entry\nif (process.argv[1]?.endsWith('sms-webhook.js')) {\n const port = parseInt(process.env['SMS_WEBHOOK_PORT'] || '3456', 10);\n startWebhookServer(port);\n}\n"],
5
+ "mappings": ";;;;AAKA,SAAS,oBAAqD;AAC9D,SAAS,SAAS,gBAAgB;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,MAAM,wBAAwB,GAAG;AACzC,gBAAI,UAAU,KAAK,EAAE,gBAAgB,WAAW,CAAC;AACjD,gBAAI,IAAI,cAAc,0BAA0B,CAAC;AAAA,UACnD;AAAA,QACF,CAAC;AACD;AAAA,MACF;AAGA,UAAI,IAAI,aAAa,WAAW;AAC9B,cAAM,SAAS,cAAc;AAC7B,YAAI,UAAU,KAAK,EAAE,gBAAgB,mBAAmB,CAAC;AACzD,YAAI;AAAA,UACF,KAAK,UAAU;AAAA,YACb,SAAS,OAAO;AAAA,YAChB,gBAAgB,OAAO,eAAe;AAAA,UACxC,CAAC;AAAA,QACH;AACA;AAAA,MACF;AAEA,UAAI,UAAU,GAAG;AACjB,UAAI,IAAI,WAAW;AAAA,IACrB;AAAA,EACF;AAEA,SAAO,OAAO,MAAM,MAAM;AACxB,YAAQ,IAAI,0CAA0C,IAAI,EAAE;AAC5D,YAAQ,IAAI,+CAA+C,IAAI,MAAM;AACrE,YAAQ,IAAI,oDAAoD;AAAA,EAClE,CAAC;AACH;AAGO,SAAS,qBACd,KACA,KACM;AACN,QAAM,SAAS,iBAAiB,IAAI,IAAI;AACxC,MAAI,KAAK,UAAU;AACnB,MAAI,KAAK,cAAc,OAAO,QAAQ,CAAC;AACzC;AAGA,IAAI,QAAQ,KAAK,CAAC,GAAG,SAAS,gBAAgB,GAAG;AAC/C,QAAM,OAAO,SAAS,QAAQ,IAAI,kBAAkB,KAAK,QAAQ,EAAE;AACnE,qBAAmB,IAAI;AACzB;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackmemoryai/stackmemory",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "description": "Lossless memory runtime for AI coding tools - organizes context as a call stack instead of linear chat logs, with team collaboration and infinite retention",
5
5
  "engines": {
6
6
  "node": ">=20.0.0",
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Claude Code hook for processing SMS responses and triggering next actions
4
+ *
5
+ * This hook:
6
+ * 1. Checks for pending SMS responses on startup
7
+ * 2. Executes queued actions from SMS responses
8
+ * 3. Injects response context into Claude session
9
+ *
10
+ * Install: stackmemory notify install-response-hook
11
+ */
12
+
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+ const os = require('os');
16
+ const { execSync } = require('child_process');
17
+
18
+ const QUEUE_PATH = path.join(
19
+ os.homedir(),
20
+ '.stackmemory',
21
+ 'sms-action-queue.json'
22
+ );
23
+ const RESPONSE_PATH = path.join(
24
+ os.homedir(),
25
+ '.stackmemory',
26
+ 'sms-latest-response.json'
27
+ );
28
+
29
+ function loadActionQueue() {
30
+ try {
31
+ if (fs.existsSync(QUEUE_PATH)) {
32
+ return JSON.parse(fs.readFileSync(QUEUE_PATH, 'utf8'));
33
+ }
34
+ } catch {}
35
+ return { actions: [] };
36
+ }
37
+
38
+ function saveActionQueue(queue) {
39
+ const dir = path.join(os.homedir(), '.stackmemory');
40
+ if (!fs.existsSync(dir)) {
41
+ fs.mkdirSync(dir, { recursive: true });
42
+ }
43
+ fs.writeFileSync(QUEUE_PATH, JSON.stringify(queue, null, 2));
44
+ }
45
+
46
+ function loadLatestResponse() {
47
+ try {
48
+ if (fs.existsSync(RESPONSE_PATH)) {
49
+ const data = JSON.parse(fs.readFileSync(RESPONSE_PATH, 'utf8'));
50
+ // Only return if less than 5 minutes old
51
+ const age = Date.now() - new Date(data.timestamp).getTime();
52
+ if (age < 5 * 60 * 1000) {
53
+ return data;
54
+ }
55
+ }
56
+ } catch {}
57
+ return null;
58
+ }
59
+
60
+ function clearLatestResponse() {
61
+ try {
62
+ if (fs.existsSync(RESPONSE_PATH)) {
63
+ fs.unlinkSync(RESPONSE_PATH);
64
+ }
65
+ } catch {}
66
+ }
67
+
68
+ function executeAction(action) {
69
+ try {
70
+ console.error(`[sms-hook] Executing: ${action.action}`);
71
+ const output = execSync(action.action, {
72
+ encoding: 'utf8',
73
+ timeout: 60000,
74
+ stdio: ['pipe', 'pipe', 'pipe'],
75
+ });
76
+ return { success: true, output };
77
+ } catch (err) {
78
+ return { success: false, error: err.message };
79
+ }
80
+ }
81
+
82
+ function processPendingActions() {
83
+ const queue = loadActionQueue();
84
+ const pending = queue.actions.filter((a) => a.status === 'pending');
85
+
86
+ if (pending.length === 0) return null;
87
+
88
+ const results = [];
89
+
90
+ for (const action of pending) {
91
+ action.status = 'running';
92
+ saveActionQueue(queue);
93
+
94
+ const result = executeAction(action);
95
+
96
+ action.status = result.success ? 'completed' : 'failed';
97
+ action.result = result.output;
98
+ action.error = result.error;
99
+ saveActionQueue(queue);
100
+
101
+ results.push({
102
+ action: action.action,
103
+ response: action.response,
104
+ success: result.success,
105
+ output: result.output?.substring(0, 500),
106
+ error: result.error,
107
+ });
108
+ }
109
+
110
+ return results;
111
+ }
112
+
113
+ // Read hook input from stdin
114
+ let input = '';
115
+ process.stdin.setEncoding('utf8');
116
+ process.stdin.on('data', (chunk) => (input += chunk));
117
+ process.stdin.on('end', () => {
118
+ try {
119
+ const hookData = JSON.parse(input);
120
+ const { hook_type } = hookData;
121
+
122
+ // On session start, check for pending responses
123
+ if (hook_type === 'on_startup' || hook_type === 'pre_tool_use') {
124
+ // Check for SMS response waiting
125
+ const latestResponse = loadLatestResponse();
126
+ if (latestResponse) {
127
+ console.error(
128
+ `[sms-hook] SMS response received: "${latestResponse.response}"`
129
+ );
130
+
131
+ // Inject context for Claude
132
+ const context = {
133
+ type: 'sms_response',
134
+ response: latestResponse.response,
135
+ promptId: latestResponse.promptId,
136
+ timestamp: latestResponse.timestamp,
137
+ message: `User responded via SMS: "${latestResponse.response}"`,
138
+ };
139
+
140
+ clearLatestResponse();
141
+
142
+ console.log(
143
+ JSON.stringify({
144
+ decision: 'allow',
145
+ context: context,
146
+ user_message: `[SMS Response] User replied: "${latestResponse.response}"`,
147
+ })
148
+ );
149
+ return;
150
+ }
151
+
152
+ // Process any pending actions
153
+ const results = processPendingActions();
154
+ if (results && results.length > 0) {
155
+ console.error(`[sms-hook] Processed ${results.length} action(s)`);
156
+
157
+ const summary = results
158
+ .map((r) =>
159
+ r.success
160
+ ? `Executed: ${r.action.substring(0, 50)}...`
161
+ : `Failed: ${r.action.substring(0, 50)}... (${r.error})`
162
+ )
163
+ .join('\n');
164
+
165
+ console.log(
166
+ JSON.stringify({
167
+ decision: 'allow',
168
+ context: {
169
+ type: 'sms_actions_executed',
170
+ results,
171
+ },
172
+ user_message: `[SMS Actions] Executed queued actions:\n${summary}`,
173
+ })
174
+ );
175
+ return;
176
+ }
177
+ }
178
+
179
+ // Default: allow everything
180
+ console.log(JSON.stringify({ decision: 'allow' }));
181
+ } catch (err) {
182
+ console.error('[sms-hook] Error:', err.message);
183
+ console.log(JSON.stringify({ decision: 'allow' }));
184
+ }
185
+ });