@stackmemoryai/stackmemory 0.5.21 → 0.5.22
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.
- package/dist/cli/claude-sm.js +94 -18
- package/dist/cli/claude-sm.js.map +2 -2
- package/dist/hooks/linear-task-picker.js +180 -0
- package/dist/hooks/linear-task-picker.js.map +7 -0
- package/dist/hooks/session-summary.js +197 -0
- package/dist/hooks/session-summary.js.map +7 -0
- package/dist/hooks/sms-action-runner.js +87 -20
- package/dist/hooks/sms-action-runner.js.map +2 -2
- package/dist/hooks/sms-webhook.js +6 -6
- package/dist/hooks/sms-webhook.js.map +2 -2
- package/package.json +1 -1
package/dist/cli/claude-sm.js
CHANGED
|
@@ -11,12 +11,18 @@ import { program } from "commander";
|
|
|
11
11
|
import { v4 as uuidv4 } from "uuid";
|
|
12
12
|
import chalk from "chalk";
|
|
13
13
|
import { initializeTracing, trace } from "../core/trace/index.js";
|
|
14
|
+
import {
|
|
15
|
+
generateSessionSummary,
|
|
16
|
+
formatSummaryMessage
|
|
17
|
+
} from "../hooks/session-summary.js";
|
|
18
|
+
import { sendNotification } from "../hooks/sms-notify.js";
|
|
14
19
|
const DEFAULT_SM_CONFIG = {
|
|
15
20
|
defaultWorktree: false,
|
|
16
21
|
defaultSandbox: false,
|
|
17
22
|
defaultChrome: false,
|
|
18
23
|
defaultTracing: true,
|
|
19
|
-
defaultRemote: false
|
|
24
|
+
defaultRemote: false,
|
|
25
|
+
defaultNotifyOnDone: true
|
|
20
26
|
};
|
|
21
27
|
function getConfigPath() {
|
|
22
28
|
return path.join(os.homedir(), ".stackmemory", "claude-sm.json");
|
|
@@ -54,9 +60,11 @@ class ClaudeSM {
|
|
|
54
60
|
useChrome: this.smConfig.defaultChrome,
|
|
55
61
|
useWorktree: this.smConfig.defaultWorktree,
|
|
56
62
|
useRemote: this.smConfig.defaultRemote,
|
|
63
|
+
notifyOnDone: this.smConfig.defaultNotifyOnDone,
|
|
57
64
|
contextEnabled: true,
|
|
58
65
|
tracingEnabled: this.smConfig.defaultTracing,
|
|
59
|
-
verboseTracing: false
|
|
66
|
+
verboseTracing: false,
|
|
67
|
+
sessionStartTime: Date.now()
|
|
60
68
|
};
|
|
61
69
|
this.stackmemoryPath = this.findStackMemory();
|
|
62
70
|
this.worktreeScriptPath = path.join(
|
|
@@ -192,18 +200,15 @@ class ClaudeSM {
|
|
|
192
200
|
if (!this.config.contextEnabled) return;
|
|
193
201
|
try {
|
|
194
202
|
console.log(chalk.blue("\u{1F4DA} Loading previous context..."));
|
|
195
|
-
const cmd = `${this.stackmemoryPath} context
|
|
196
|
-
const output = execSync(cmd, {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
);
|
|
203
|
+
const cmd = `${this.stackmemoryPath} context show`;
|
|
204
|
+
const output = execSync(cmd, {
|
|
205
|
+
encoding: "utf8",
|
|
206
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
207
|
+
// Capture stderr to suppress errors
|
|
208
|
+
});
|
|
209
|
+
const lines = output.trim().split("\n").filter((l) => l.trim());
|
|
210
|
+
if (lines.length > 3) {
|
|
211
|
+
console.log(chalk.gray("Context stack loaded"));
|
|
207
212
|
}
|
|
208
213
|
} catch {
|
|
209
214
|
}
|
|
@@ -238,6 +243,48 @@ class ClaudeSM {
|
|
|
238
243
|
);
|
|
239
244
|
}
|
|
240
245
|
}
|
|
246
|
+
async sendDoneNotification(exitCode) {
|
|
247
|
+
try {
|
|
248
|
+
const context = {
|
|
249
|
+
instanceId: this.config.instanceId,
|
|
250
|
+
exitCode,
|
|
251
|
+
sessionStartTime: this.config.sessionStartTime,
|
|
252
|
+
worktreePath: this.config.worktreePath,
|
|
253
|
+
branch: this.config.branch,
|
|
254
|
+
task: this.config.task
|
|
255
|
+
};
|
|
256
|
+
const summary = await generateSessionSummary(context);
|
|
257
|
+
const message = formatSummaryMessage(summary);
|
|
258
|
+
console.log(chalk.cyan("\nSending session summary via WhatsApp..."));
|
|
259
|
+
const options = summary.suggestions.slice(0, 4).map((s) => ({
|
|
260
|
+
key: s.key,
|
|
261
|
+
label: s.label,
|
|
262
|
+
action: s.action
|
|
263
|
+
}));
|
|
264
|
+
const result = await sendNotification({
|
|
265
|
+
type: "task_complete",
|
|
266
|
+
title: "Claude Session Complete",
|
|
267
|
+
message,
|
|
268
|
+
prompt: options.length > 0 ? {
|
|
269
|
+
type: "options",
|
|
270
|
+
options
|
|
271
|
+
} : void 0
|
|
272
|
+
});
|
|
273
|
+
if (result.success) {
|
|
274
|
+
console.log(chalk.green("Notification sent successfully"));
|
|
275
|
+
} else {
|
|
276
|
+
console.log(
|
|
277
|
+
chalk.yellow(`Notification not sent: ${result.error || "unknown"}`)
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
} catch (error) {
|
|
281
|
+
console.log(
|
|
282
|
+
chalk.yellow(
|
|
283
|
+
`Could not send notification: ${error instanceof Error ? error.message : "unknown"}`
|
|
284
|
+
)
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
241
288
|
async run(args) {
|
|
242
289
|
const claudeArgs = [];
|
|
243
290
|
let i = 0;
|
|
@@ -259,6 +306,13 @@ class ClaudeSM {
|
|
|
259
306
|
case "--no-remote":
|
|
260
307
|
this.config.useRemote = false;
|
|
261
308
|
break;
|
|
309
|
+
case "--notify-done":
|
|
310
|
+
case "-n":
|
|
311
|
+
this.config.notifyOnDone = true;
|
|
312
|
+
break;
|
|
313
|
+
case "--no-notify-done":
|
|
314
|
+
this.config.notifyOnDone = false;
|
|
315
|
+
break;
|
|
262
316
|
case "--sandbox":
|
|
263
317
|
case "-s":
|
|
264
318
|
this.config.useSandbox = true;
|
|
@@ -421,7 +475,7 @@ class ClaudeSM {
|
|
|
421
475
|
}
|
|
422
476
|
process.exit(1);
|
|
423
477
|
});
|
|
424
|
-
claude.on("exit", (code) => {
|
|
478
|
+
claude.on("exit", async (code) => {
|
|
425
479
|
this.saveContext("Claude session ended", {
|
|
426
480
|
action: "session_end",
|
|
427
481
|
exitCode: code
|
|
@@ -433,6 +487,9 @@ class ClaudeSM {
|
|
|
433
487
|
console.log(chalk.blue("Debug Trace Summary:"));
|
|
434
488
|
console.log(chalk.gray(summary));
|
|
435
489
|
}
|
|
490
|
+
if (this.config.notifyOnDone || this.config.useRemote) {
|
|
491
|
+
await this.sendDoneNotification(code);
|
|
492
|
+
}
|
|
436
493
|
if (this.config.worktreePath) {
|
|
437
494
|
console.log();
|
|
438
495
|
console.log(chalk.gray("\u2500".repeat(42)));
|
|
@@ -478,6 +535,9 @@ configCmd.command("show").description("Show current default settings").action(()
|
|
|
478
535
|
console.log(
|
|
479
536
|
` defaultRemote: ${config.defaultRemote ? chalk.green("true") : chalk.gray("false")}`
|
|
480
537
|
);
|
|
538
|
+
console.log(
|
|
539
|
+
` defaultNotifyOnDone: ${config.defaultNotifyOnDone ? chalk.green("true") : chalk.gray("false")}`
|
|
540
|
+
);
|
|
481
541
|
console.log(chalk.gray(`
|
|
482
542
|
Config: ${getConfigPath()}`));
|
|
483
543
|
});
|
|
@@ -489,13 +549,17 @@ configCmd.command("set <key> <value>").description("Set a default (e.g., set wor
|
|
|
489
549
|
sandbox: "defaultSandbox",
|
|
490
550
|
chrome: "defaultChrome",
|
|
491
551
|
tracing: "defaultTracing",
|
|
492
|
-
remote: "defaultRemote"
|
|
552
|
+
remote: "defaultRemote",
|
|
553
|
+
"notify-done": "defaultNotifyOnDone",
|
|
554
|
+
notifyondone: "defaultNotifyOnDone"
|
|
493
555
|
};
|
|
494
556
|
const configKey = keyMap[key];
|
|
495
557
|
if (!configKey) {
|
|
496
558
|
console.log(chalk.red(`Unknown key: ${key}`));
|
|
497
559
|
console.log(
|
|
498
|
-
chalk.gray(
|
|
560
|
+
chalk.gray(
|
|
561
|
+
"Valid keys: worktree, sandbox, chrome, tracing, remote, notify-done"
|
|
562
|
+
)
|
|
499
563
|
);
|
|
500
564
|
process.exit(1);
|
|
501
565
|
}
|
|
@@ -527,7 +591,19 @@ configCmd.command("remote-off").description("Disable remote mode by default").ac
|
|
|
527
591
|
saveSMConfig(config);
|
|
528
592
|
console.log(chalk.green("Remote mode disabled by default"));
|
|
529
593
|
});
|
|
530
|
-
|
|
594
|
+
configCmd.command("notify-done-on").description("Enable WhatsApp notification when session ends (default)").action(() => {
|
|
595
|
+
const config = loadSMConfig();
|
|
596
|
+
config.defaultNotifyOnDone = true;
|
|
597
|
+
saveSMConfig(config);
|
|
598
|
+
console.log(chalk.green("Notify-on-done enabled by default"));
|
|
599
|
+
});
|
|
600
|
+
configCmd.command("notify-done-off").description("Disable notification when session ends").action(() => {
|
|
601
|
+
const config = loadSMConfig();
|
|
602
|
+
config.defaultNotifyOnDone = false;
|
|
603
|
+
saveSMConfig(config);
|
|
604
|
+
console.log(chalk.green("Notify-on-done disabled by default"));
|
|
605
|
+
});
|
|
606
|
+
program.option("-w, --worktree", "Create isolated worktree for this instance").option("-W, --no-worktree", "Disable worktree (override default)").option("-r, --remote", "Enable remote mode (WhatsApp for all questions)").option("--no-remote", "Disable remote mode (override default)").option("-n, --notify-done", "Send WhatsApp notification when session ends").option("--no-notify-done", "Disable notification when session ends").option("-s, --sandbox", "Enable sandbox mode (file/network restrictions)").option("-c, --chrome", "Enable Chrome automation").option("-a, --auto", "Automatically detect and apply best settings").option("-b, --branch <name>", "Specify branch name for worktree").option("-t, --task <desc>", "Task description for context").option("--claude-bin <path>", "Path to claude CLI (or use CLAUDE_BIN)").option("--no-context", "Disable StackMemory context integration").option("--no-trace", "Disable debug tracing (enabled by default)").option("--verbose-trace", "Enable verbose debug tracing with full details").helpOption("-h, --help", "Display help").allowUnknownOption(true).action(async (_options) => {
|
|
531
607
|
const claudeSM = new ClaudeSM();
|
|
532
608
|
const args = process.argv.slice(2);
|
|
533
609
|
await claudeSM.run(args);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/cli/claude-sm.ts"],
|
|
4
|
-
"sourcesContent": ["#!/usr/bin/env node\n\n/**\n * claude-sm: Claude wrapper with StackMemory and worktree integration\n * Automatically manages context persistence and instance isolation\n */\n\nimport { spawn, execSync, execFileSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as os from 'os';\nimport { program } from 'commander';\nimport { v4 as uuidv4 } from 'uuid';\nimport chalk from 'chalk';\nimport { initializeTracing, trace } from '../core/trace/index.js';\n\n// __filename and __dirname are provided by esbuild banner for ESM compatibility\n\ninterface ClaudeSMConfig {\n defaultWorktree: boolean;\n defaultSandbox: boolean;\n defaultChrome: boolean;\n defaultTracing: boolean;\n defaultRemote: boolean;\n}\n\ninterface ClaudeConfig {\n instanceId: string;\n worktreePath?: string;\n useSandbox: boolean;\n useChrome: boolean;\n useWorktree: boolean;\n useRemote: boolean;\n contextEnabled: boolean;\n branch?: string;\n task?: string;\n tracingEnabled: boolean;\n verboseTracing: boolean;\n claudeBin?: string;\n}\n\nconst DEFAULT_SM_CONFIG: ClaudeSMConfig = {\n defaultWorktree: false,\n defaultSandbox: false,\n defaultChrome: false,\n defaultTracing: true,\n defaultRemote: false,\n};\n\nfunction getConfigPath(): string {\n return path.join(os.homedir(), '.stackmemory', 'claude-sm.json');\n}\n\nfunction loadSMConfig(): ClaudeSMConfig {\n try {\n const configPath = getConfigPath();\n if (fs.existsSync(configPath)) {\n const content = fs.readFileSync(configPath, 'utf8');\n return { ...DEFAULT_SM_CONFIG, ...JSON.parse(content) };\n }\n } catch {\n // Ignore errors, use defaults\n }\n return { ...DEFAULT_SM_CONFIG };\n}\n\nfunction saveSMConfig(config: ClaudeSMConfig): void {\n const configPath = getConfigPath();\n const dir = path.dirname(configPath);\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true });\n }\n fs.writeFileSync(configPath, JSON.stringify(config, null, 2));\n}\n\nclass ClaudeSM {\n private config: ClaudeConfig;\n private stackmemoryPath: string;\n private worktreeScriptPath: string;\n private claudeConfigDir: string;\n private smConfig: ClaudeSMConfig;\n\n constructor() {\n // Load persistent defaults\n this.smConfig = loadSMConfig();\n\n this.config = {\n instanceId: this.generateInstanceId(),\n useSandbox: this.smConfig.defaultSandbox,\n useChrome: this.smConfig.defaultChrome,\n useWorktree: this.smConfig.defaultWorktree,\n useRemote: this.smConfig.defaultRemote,\n contextEnabled: true,\n tracingEnabled: this.smConfig.defaultTracing,\n verboseTracing: false,\n };\n\n this.stackmemoryPath = this.findStackMemory();\n this.worktreeScriptPath = path.join(\n __dirname,\n '../../scripts/claude-worktree-manager.sh'\n );\n this.claudeConfigDir = path.join(os.homedir(), '.claude');\n\n // Ensure config directory exists\n if (!fs.existsSync(this.claudeConfigDir)) {\n fs.mkdirSync(this.claudeConfigDir, { recursive: true });\n }\n }\n\n private generateInstanceId(): string {\n return uuidv4().substring(0, 8);\n }\n\n private findStackMemory(): string {\n // Check multiple possible locations\n const possiblePaths = [\n path.join(os.homedir(), '.stackmemory', 'bin', 'stackmemory'),\n '/usr/local/bin/stackmemory',\n '/opt/homebrew/bin/stackmemory',\n 'stackmemory', // Rely on PATH\n ];\n\n for (const smPath of possiblePaths) {\n try {\n execFileSync('which', [smPath], { stdio: 'ignore' });\n return smPath;\n } catch {\n // Continue searching\n }\n }\n\n return 'stackmemory'; // Fallback to PATH\n }\n\n private isGitRepo(): boolean {\n try {\n execSync('git rev-parse --git-dir', { stdio: 'ignore' });\n return true;\n } catch {\n return false;\n }\n }\n\n private getCurrentBranch(): string {\n try {\n return execSync('git rev-parse --abbrev-ref HEAD', {\n encoding: 'utf8',\n }).trim();\n } catch {\n return 'main';\n }\n }\n\n private hasUncommittedChanges(): boolean {\n try {\n const status = execSync('git status --porcelain', { encoding: 'utf8' });\n return status.length > 0;\n } catch {\n return false;\n }\n }\n\n private resolveClaudeBin(): string | null {\n // 1) CLI-specified\n if (this.config.claudeBin && this.config.claudeBin.trim()) {\n return this.config.claudeBin.trim();\n }\n // 2) Env override\n const envBin = process.env['CLAUDE_BIN'];\n if (envBin && envBin.trim()) return envBin.trim();\n // 3) PATH detection\n try {\n execSync('which claude', { stdio: 'ignore' });\n return 'claude';\n } catch {}\n return null;\n }\n\n private setupWorktree(): string | null {\n if (!this.config.useWorktree || !this.isGitRepo()) {\n return null;\n }\n\n console.log(chalk.blue('\uD83C\uDF33 Setting up isolated worktree...'));\n\n const timestamp = new Date()\n .toISOString()\n .replace(/[:.]/g, '-')\n .substring(0, 19);\n const branch =\n this.config.branch ||\n `claude-${this.config.task || 'work'}-${timestamp}-${this.config.instanceId}`;\n const repoName = path.basename(process.cwd());\n const worktreePath = path.join(\n path.dirname(process.cwd()),\n `${repoName}--${branch}`\n );\n\n try {\n // Create worktree\n const flags = [];\n if (this.config.useSandbox) flags.push('--sandbox');\n if (this.config.useChrome) flags.push('--chrome');\n\n const cmd = `git worktree add -b \"${branch}\" \"${worktreePath}\"`;\n execSync(cmd, { stdio: 'inherit' });\n\n console.log(chalk.green(`\u2705 Worktree created: ${worktreePath}`));\n console.log(chalk.gray(` Branch: ${branch}`));\n\n // Save worktree config\n const configPath = path.join(worktreePath, '.claude-instance.json');\n const configData = {\n instanceId: this.config.instanceId,\n worktreePath,\n branch,\n task: this.config.task,\n sandboxEnabled: this.config.useSandbox,\n chromeEnabled: this.config.useChrome,\n created: new Date().toISOString(),\n parentRepo: process.cwd(),\n };\n fs.writeFileSync(configPath, JSON.stringify(configData, null, 2));\n\n // Copy environment files\n const envFiles = ['.env', '.env.local', '.mise.toml', '.tool-versions'];\n for (const file of envFiles) {\n const srcPath = path.join(process.cwd(), file);\n if (fs.existsSync(srcPath)) {\n fs.copyFileSync(srcPath, path.join(worktreePath, file));\n }\n }\n\n return worktreePath;\n } catch (err: unknown) {\n console.error(chalk.red('\u274C Failed to create worktree:'), err);\n return null;\n }\n }\n\n private saveContext(\n message: string,\n metadata: Record<string, unknown> = {}\n ): void {\n if (!this.config.contextEnabled) return;\n\n try {\n const contextData = {\n message,\n metadata: {\n ...metadata,\n instanceId: this.config.instanceId,\n worktree: this.config.worktreePath,\n timestamp: new Date().toISOString(),\n },\n };\n\n const cmd = `${this.stackmemoryPath} context save --json '${JSON.stringify(contextData)}'`;\n execSync(cmd, { stdio: 'ignore' });\n } catch {\n // Silently fail - don't interrupt Claude\n }\n }\n\n private loadContext(): void {\n if (!this.config.contextEnabled) return;\n\n try {\n console.log(chalk.blue('\uD83D\uDCDA Loading previous context...'));\n\n const cmd = `${this.stackmemoryPath} context list --limit 5 --format json`;\n const output = execSync(cmd, { encoding: 'utf8' });\n const contexts = JSON.parse(output);\n\n if (contexts.length > 0) {\n console.log(chalk.gray('Recent context loaded:'));\n contexts.forEach(\n (ctx: { message: string; metadata?: { timestamp?: string } }) => {\n console.log(\n chalk.gray(` - ${ctx.message} (${ctx.metadata?.timestamp})`)\n );\n }\n );\n }\n } catch {\n // Silently continue\n }\n }\n\n private detectMultipleInstances(): boolean {\n try {\n const lockDir = path.join(process.cwd(), '.claude-worktree-locks');\n if (!fs.existsSync(lockDir)) return false;\n\n const locks = fs.readdirSync(lockDir).filter((f) => f.endsWith('.lock'));\n const activeLocks = locks.filter((lockFile) => {\n const lockPath = path.join(lockDir, lockFile);\n const lockData = JSON.parse(fs.readFileSync(lockPath, 'utf8'));\n const lockAge = Date.now() - new Date(lockData.created).getTime();\n return lockAge < 24 * 60 * 60 * 1000; // Less than 24 hours old\n });\n\n return activeLocks.length > 0;\n } catch {\n return false;\n }\n }\n\n private suggestWorktreeMode(): void {\n if (this.hasUncommittedChanges()) {\n console.log(chalk.yellow('\u26A0\uFE0F Uncommitted changes detected'));\n console.log(\n chalk.gray(' Consider using --worktree to work in isolation')\n );\n }\n\n if (this.detectMultipleInstances()) {\n console.log(chalk.yellow('\u26A0\uFE0F Other Claude instances detected'));\n console.log(\n chalk.gray(' Using --worktree is recommended to avoid conflicts')\n );\n }\n }\n\n public async run(args: string[]): Promise<void> {\n // Parse arguments\n const claudeArgs: string[] = [];\n let i = 0;\n\n while (i < args.length) {\n const arg = args[i];\n\n switch (arg) {\n case '--worktree':\n case '-w':\n this.config.useWorktree = true;\n break;\n case '--no-worktree':\n case '-W':\n this.config.useWorktree = false;\n break;\n case '--remote':\n case '-r':\n this.config.useRemote = true;\n break;\n case '--no-remote':\n this.config.useRemote = false;\n break;\n case '--sandbox':\n case '-s':\n this.config.useSandbox = true;\n claudeArgs.push('--sandbox');\n break;\n case '--chrome':\n case '-c':\n this.config.useChrome = true;\n claudeArgs.push('--chrome');\n break;\n case '--no-context':\n this.config.contextEnabled = false;\n break;\n case '--no-trace':\n this.config.tracingEnabled = false;\n break;\n case '--verbose-trace':\n this.config.verboseTracing = true;\n break;\n case '--branch':\n case '-b':\n i++;\n this.config.branch = args[i];\n break;\n case '--task':\n case '-t':\n i++;\n this.config.task = args[i];\n break;\n case '--claude-bin':\n i++;\n this.config.claudeBin = args[i];\n process.env['CLAUDE_BIN'] = this.config.claudeBin;\n break;\n case '--auto':\n case '-a':\n // Auto mode: detect and apply best settings\n if (this.isGitRepo()) {\n this.config.useWorktree =\n this.hasUncommittedChanges() || this.detectMultipleInstances();\n }\n break;\n default:\n claudeArgs.push(arg);\n }\n i++;\n }\n\n // Initialize tracing system if enabled\n if (this.config.tracingEnabled) {\n // Set up environment for tracing\n process.env['DEBUG_TRACE'] = 'true';\n process.env['STACKMEMORY_DEBUG'] = 'true';\n process.env['TRACE_OUTPUT'] = 'file'; // Write to file to not clutter Claude output\n process.env['TRACE_MASK_SENSITIVE'] = 'true'; // Always mask sensitive data\n\n if (this.config.verboseTracing) {\n process.env['TRACE_VERBOSITY'] = 'full';\n process.env['TRACE_PARAMS'] = 'true';\n process.env['TRACE_RESULTS'] = 'true';\n process.env['TRACE_MEMORY'] = 'true';\n } else {\n process.env['TRACE_VERBOSITY'] = 'summary';\n process.env['TRACE_PARAMS'] = 'true';\n process.env['TRACE_RESULTS'] = 'false';\n }\n\n // Initialize the tracing system\n initializeTracing();\n\n // Start tracing this Claude session\n trace.command(\n 'claude-sm',\n {\n instanceId: this.config.instanceId,\n worktree: this.config.useWorktree,\n sandbox: this.config.useSandbox,\n task: this.config.task,\n },\n async () => {\n // Session tracing will wrap the entire Claude execution\n }\n );\n }\n\n // Show header\n console.log(chalk.blue('\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557'));\n console.log(chalk.blue('\u2551 Claude + StackMemory + Worktree \u2551'));\n console.log(chalk.blue('\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D'));\n console.log();\n\n // Check Git repo status\n if (this.isGitRepo()) {\n const branch = this.getCurrentBranch();\n console.log(chalk.gray(`\uD83D\uDCCD Current branch: ${branch}`));\n\n if (!this.config.useWorktree) {\n this.suggestWorktreeMode();\n }\n }\n\n // Setup worktree if requested\n if (this.config.useWorktree) {\n const worktreePath = this.setupWorktree();\n if (worktreePath) {\n this.config.worktreePath = worktreePath;\n process.chdir(worktreePath);\n\n // Save context about worktree creation\n this.saveContext('Created worktree for Claude instance', {\n action: 'worktree_created',\n path: worktreePath,\n branch: this.config.branch,\n });\n }\n }\n\n // Load previous context\n this.loadContext();\n\n // Setup environment\n process.env['CLAUDE_INSTANCE_ID'] = this.config.instanceId;\n if (this.config.worktreePath) {\n process.env['CLAUDE_WORKTREE_PATH'] = this.config.worktreePath;\n }\n if (this.config.useRemote) {\n process.env['CLAUDE_REMOTE'] = '1';\n }\n\n console.log(chalk.gray(`\uD83E\uDD16 Instance ID: ${this.config.instanceId}`));\n console.log(chalk.gray(`\uD83D\uDCC1 Working in: ${process.cwd()}`));\n\n if (this.config.useSandbox) {\n console.log(chalk.yellow('\uD83D\uDD12 Sandbox mode enabled'));\n }\n if (this.config.useRemote) {\n console.log(\n chalk.cyan('\uD83D\uDCF1 Remote mode: WhatsApp notifications for all questions')\n );\n }\n if (this.config.useChrome) {\n console.log(chalk.yellow('\uD83C\uDF10 Chrome automation enabled'));\n }\n if (this.config.tracingEnabled) {\n console.log(\n chalk.gray(`\uD83D\uDD0D Debug tracing enabled (logs to ~/.stackmemory/traces/)`)\n );\n if (this.config.verboseTracing) {\n console.log(\n chalk.gray(` Verbose mode: capturing all execution details`)\n );\n }\n }\n\n console.log();\n console.log(chalk.gray('Starting Claude...'));\n console.log(chalk.gray('\u2500'.repeat(42)));\n\n const claudeBin = this.resolveClaudeBin();\n if (!claudeBin) {\n console.error(chalk.red('\u274C Claude CLI not found.'));\n console.log(\n chalk.gray(\n ' Install Claude CLI or set an override:\\n' +\n ' export CLAUDE_BIN=/path/to/claude\\n' +\n ' claude-sm --help\\n\\n' +\n ' Ensure PATH includes npm global bin (npm bin -g).'\n )\n );\n process.exit(1);\n return;\n }\n\n // Launch Claude\n const claude = spawn(claudeBin, claudeArgs, {\n stdio: 'inherit',\n env: process.env,\n });\n\n claude.on('error', (err: NodeJS.ErrnoException) => {\n console.error(chalk.red('\u274C Failed to launch Claude CLI.'));\n if (err.code === 'ENOENT') {\n console.error(\n chalk.gray(' Not found. Set CLAUDE_BIN or install claude on PATH.')\n );\n } else if (err.code === 'EPERM' || err.code === 'EACCES') {\n console.error(\n chalk.gray(\n ' Permission/sandbox issue. Try outside a sandbox or set CLAUDE_BIN.'\n )\n );\n } else {\n console.error(chalk.gray(` ${err.message}`));\n }\n process.exit(1);\n });\n\n // Handle exit\n claude.on('exit', (code) => {\n // Save final context\n this.saveContext('Claude session ended', {\n action: 'session_end',\n exitCode: code,\n });\n\n // End tracing and show summary if enabled\n if (this.config.tracingEnabled) {\n const summary = trace.getExecutionSummary();\n console.log();\n console.log(chalk.gray('\u2500'.repeat(42)));\n console.log(chalk.blue('Debug Trace Summary:'));\n console.log(chalk.gray(summary));\n }\n\n // Offer to clean up worktree\n if (this.config.worktreePath) {\n console.log();\n console.log(chalk.gray('\u2500'.repeat(42)));\n console.log(chalk.blue('Session ended in worktree:'));\n console.log(chalk.gray(` ${this.config.worktreePath}`));\n console.log();\n console.log(chalk.gray('To remove worktree: gd_claude'));\n console.log(chalk.gray('To merge to main: cwm'));\n }\n\n process.exit(code || 0);\n });\n\n // Handle signals\n process.on('SIGINT', () => {\n this.saveContext('Claude session interrupted', {\n action: 'session_interrupt',\n });\n claude.kill('SIGINT');\n });\n\n process.on('SIGTERM', () => {\n this.saveContext('Claude session terminated', {\n action: 'session_terminate',\n });\n claude.kill('SIGTERM');\n });\n }\n}\n\n// CLI interface\nprogram\n .name('claude-sm')\n .description('Claude with StackMemory context and worktree isolation')\n .version('1.0.0');\n\n// Config subcommand\nconst configCmd = program\n .command('config')\n .description('Manage claude-sm defaults');\n\nconfigCmd\n .command('show')\n .description('Show current default settings')\n .action(() => {\n const config = loadSMConfig();\n console.log(chalk.blue('claude-sm defaults:'));\n console.log(\n ` defaultWorktree: ${config.defaultWorktree ? chalk.green('true') : chalk.gray('false')}`\n );\n console.log(\n ` defaultSandbox: ${config.defaultSandbox ? chalk.green('true') : chalk.gray('false')}`\n );\n console.log(\n ` defaultChrome: ${config.defaultChrome ? chalk.green('true') : chalk.gray('false')}`\n );\n console.log(\n ` defaultTracing: ${config.defaultTracing ? chalk.green('true') : chalk.gray('false')}`\n );\n console.log(\n ` defaultRemote: ${config.defaultRemote ? chalk.green('true') : chalk.gray('false')}`\n );\n console.log(chalk.gray(`\\nConfig: ${getConfigPath()}`));\n });\n\nconfigCmd\n .command('set <key> <value>')\n .description('Set a default (e.g., set worktree true)')\n .action((key: string, value: string) => {\n const config = loadSMConfig();\n const boolValue = value === 'true' || value === '1' || value === 'on';\n\n const keyMap: Record<string, keyof ClaudeSMConfig> = {\n worktree: 'defaultWorktree',\n sandbox: 'defaultSandbox',\n chrome: 'defaultChrome',\n tracing: 'defaultTracing',\n remote: 'defaultRemote',\n };\n\n const configKey = keyMap[key];\n if (!configKey) {\n console.log(chalk.red(`Unknown key: ${key}`));\n console.log(\n chalk.gray('Valid keys: worktree, sandbox, chrome, tracing, remote')\n );\n process.exit(1);\n }\n\n config[configKey] = boolValue;\n saveSMConfig(config);\n console.log(chalk.green(`Set ${key} = ${boolValue}`));\n });\n\nconfigCmd\n .command('worktree-on')\n .description('Enable worktree mode by default')\n .action(() => {\n const config = loadSMConfig();\n config.defaultWorktree = true;\n saveSMConfig(config);\n console.log(chalk.green('Worktree mode enabled by default'));\n });\n\nconfigCmd\n .command('worktree-off')\n .description('Disable worktree mode by default')\n .action(() => {\n const config = loadSMConfig();\n config.defaultWorktree = false;\n saveSMConfig(config);\n console.log(chalk.green('Worktree mode disabled by default'));\n });\n\nconfigCmd\n .command('remote-on')\n .description('Enable remote mode by default (WhatsApp for all questions)')\n .action(() => {\n const config = loadSMConfig();\n config.defaultRemote = true;\n saveSMConfig(config);\n console.log(chalk.green('Remote mode enabled by default'));\n });\n\nconfigCmd\n .command('remote-off')\n .description('Disable remote mode by default')\n .action(() => {\n const config = loadSMConfig();\n config.defaultRemote = false;\n saveSMConfig(config);\n console.log(chalk.green('Remote mode disabled by default'));\n });\n\n// Main command (default action when no subcommand)\nprogram\n .option('-w, --worktree', 'Create isolated worktree for this instance')\n .option('-W, --no-worktree', 'Disable worktree (override default)')\n .option('-r, --remote', 'Enable remote mode (WhatsApp for all questions)')\n .option('--no-remote', 'Disable remote mode (override default)')\n .option('-s, --sandbox', 'Enable sandbox mode (file/network restrictions)')\n .option('-c, --chrome', 'Enable Chrome automation')\n .option('-a, --auto', 'Automatically detect and apply best settings')\n .option('-b, --branch <name>', 'Specify branch name for worktree')\n .option('-t, --task <desc>', 'Task description for context')\n .option('--claude-bin <path>', 'Path to claude CLI (or use CLAUDE_BIN)')\n .option('--no-context', 'Disable StackMemory context integration')\n .option('--no-trace', 'Disable debug tracing (enabled by default)')\n .option('--verbose-trace', 'Enable verbose debug tracing with full details')\n .helpOption('-h, --help', 'Display help')\n .allowUnknownOption(true)\n .action(async (_options) => {\n const claudeSM = new ClaudeSM();\n const args = process.argv.slice(2);\n await claudeSM.run(args);\n });\n\n// Handle direct execution\n// ESM-safe CLI entry\nprogram.parse(process.argv);\n"],
|
|
5
|
-
"mappings": ";;;;;AAOA,SAAS,OAAO,UAAU,oBAAoB;AAC9C,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,YAAY,QAAQ;AACpB,SAAS,eAAe;AACxB,SAAS,MAAM,cAAc;AAC7B,OAAO,WAAW;AAClB,SAAS,mBAAmB,aAAa;AA2BzC,MAAM,oBAAoC;AAAA,EACxC,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,eAAe;AACjB;AAEA,SAAS,gBAAwB;AAC/B,SAAO,KAAK,KAAK,GAAG,QAAQ,GAAG,gBAAgB,gBAAgB;AACjE;AAEA,SAAS,eAA+B;AACtC,MAAI;AACF,UAAM,aAAa,cAAc;AACjC,QAAI,GAAG,WAAW,UAAU,GAAG;AAC7B,YAAM,UAAU,GAAG,aAAa,YAAY,MAAM;AAClD,aAAO,EAAE,GAAG,mBAAmB,GAAG,KAAK,MAAM,OAAO,EAAE;AAAA,IACxD;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO,EAAE,GAAG,kBAAkB;AAChC;AAEA,SAAS,aAAa,QAA8B;AAClD,QAAM,aAAa,cAAc;AACjC,QAAM,MAAM,KAAK,QAAQ,UAAU;AACnC,MAAI,CAAC,GAAG,WAAW,GAAG,GAAG;AACvB,OAAG,UAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,EACvC;AACA,KAAG,cAAc,YAAY,KAAK,UAAU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CAAkC,EAC9C,OAAO,MAAM;AACZ,QAAM,SAAS,aAAa;AAC5B,SAAO,kBAAkB;AACzB,eAAa,MAAM;AACnB,UAAQ,IAAI,MAAM,MAAM,mCAAmC,CAAC;AAC9D,CAAC;AAEH,UACG,QAAQ,WAAW,EACnB,YAAY,4DAA4D,EACxE,OAAO,MAAM;AACZ,QAAM,SAAS,aAAa;AAC5B,SAAO,gBAAgB;AACvB,eAAa,MAAM;AACnB,UAAQ,IAAI,MAAM,MAAM,gCAAgC,CAAC;AAC3D,CAAC;AAEH,UACG,QAAQ,YAAY,EACpB,YAAY,gCAAgC,EAC5C,OAAO,MAAM;AACZ,QAAM,SAAS,aAAa;AAC5B,SAAO,gBAAgB;AACvB,eAAa,MAAM;AACnB,UAAQ,IAAI,MAAM,MAAM,iCAAiC,CAAC;AAC5D,CAAC;AAGH,QACG,OAAO,kBAAkB,4CAA4C,EACrE,OAAO,qBAAqB,qCAAqC,EACjE,OAAO,gBAAgB,iDAAiD,EACxE,OAAO,eAAe,wCAAwC,EAC9D,OAAO,iBAAiB,iDAAiD,EACzE,OAAO,gBAAgB,0BAA0B,EACjD,OAAO,cAAc,8CAA8C,EACnE,OAAO,uBAAuB,kCAAkC,EAChE,OAAO,qBAAqB,8BAA8B,EAC1D,OAAO,uBAAuB,wCAAwC,EACtE,OAAO,gBAAgB,yCAAyC,EAChE,OAAO,cAAc,4CAA4C,EACjE,OAAO,mBAAmB,gDAAgD,EAC1E,WAAW,cAAc,cAAc,EACvC,mBAAmB,IAAI,EACvB,OAAO,OAAO,aAAa;AAC1B,QAAM,WAAW,IAAI,SAAS;AAC9B,QAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,QAAM,SAAS,IAAI,IAAI;AACzB,CAAC;AAIH,QAAQ,MAAM,QAAQ,IAAI;",
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env node\n\n/**\n * claude-sm: Claude wrapper with StackMemory and worktree integration\n * Automatically manages context persistence and instance isolation\n */\n\nimport { spawn, execSync, execFileSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as os from 'os';\nimport { program } from 'commander';\nimport { v4 as uuidv4 } from 'uuid';\nimport chalk from 'chalk';\nimport { initializeTracing, trace } from '../core/trace/index.js';\nimport {\n generateSessionSummary,\n formatSummaryMessage,\n SessionContext,\n} from '../hooks/session-summary.js';\nimport { sendNotification } from '../hooks/sms-notify.js';\n\n// __filename and __dirname are provided by esbuild banner for ESM compatibility\n\ninterface ClaudeSMConfig {\n defaultWorktree: boolean;\n defaultSandbox: boolean;\n defaultChrome: boolean;\n defaultTracing: boolean;\n defaultRemote: boolean;\n defaultNotifyOnDone: boolean;\n}\n\ninterface ClaudeConfig {\n instanceId: string;\n worktreePath?: string;\n useSandbox: boolean;\n useChrome: boolean;\n useWorktree: boolean;\n useRemote: boolean;\n notifyOnDone: boolean;\n contextEnabled: boolean;\n branch?: string;\n task?: string;\n tracingEnabled: boolean;\n verboseTracing: boolean;\n claudeBin?: string;\n sessionStartTime: number;\n}\n\nconst DEFAULT_SM_CONFIG: ClaudeSMConfig = {\n defaultWorktree: false,\n defaultSandbox: false,\n defaultChrome: false,\n defaultTracing: true,\n defaultRemote: false,\n defaultNotifyOnDone: true,\n};\n\nfunction getConfigPath(): string {\n return path.join(os.homedir(), '.stackmemory', 'claude-sm.json');\n}\n\nfunction loadSMConfig(): ClaudeSMConfig {\n try {\n const configPath = getConfigPath();\n if (fs.existsSync(configPath)) {\n const content = fs.readFileSync(configPath, 'utf8');\n return { ...DEFAULT_SM_CONFIG, ...JSON.parse(content) };\n }\n } catch {\n // Ignore errors, use defaults\n }\n return { ...DEFAULT_SM_CONFIG };\n}\n\nfunction saveSMConfig(config: ClaudeSMConfig): void {\n const configPath = getConfigPath();\n const dir = path.dirname(configPath);\n if (!fs.existsSync(dir)) {\n fs.mkdirSync(dir, { recursive: true });\n }\n fs.writeFileSync(configPath, JSON.stringify(config, null, 2));\n}\n\nclass ClaudeSM {\n private config: ClaudeConfig;\n private stackmemoryPath: string;\n private worktreeScriptPath: string;\n private claudeConfigDir: string;\n private smConfig: ClaudeSMConfig;\n\n constructor() {\n // Load persistent defaults\n this.smConfig = loadSMConfig();\n\n this.config = {\n instanceId: this.generateInstanceId(),\n useSandbox: this.smConfig.defaultSandbox,\n useChrome: this.smConfig.defaultChrome,\n useWorktree: this.smConfig.defaultWorktree,\n useRemote: this.smConfig.defaultRemote,\n notifyOnDone: this.smConfig.defaultNotifyOnDone,\n contextEnabled: true,\n tracingEnabled: this.smConfig.defaultTracing,\n verboseTracing: false,\n sessionStartTime: Date.now(),\n };\n\n this.stackmemoryPath = this.findStackMemory();\n this.worktreeScriptPath = path.join(\n __dirname,\n '../../scripts/claude-worktree-manager.sh'\n );\n this.claudeConfigDir = path.join(os.homedir(), '.claude');\n\n // Ensure config directory exists\n if (!fs.existsSync(this.claudeConfigDir)) {\n fs.mkdirSync(this.claudeConfigDir, { recursive: true });\n }\n }\n\n private generateInstanceId(): string {\n return uuidv4().substring(0, 8);\n }\n\n private findStackMemory(): string {\n // Check multiple possible locations\n const possiblePaths = [\n path.join(os.homedir(), '.stackmemory', 'bin', 'stackmemory'),\n '/usr/local/bin/stackmemory',\n '/opt/homebrew/bin/stackmemory',\n 'stackmemory', // Rely on PATH\n ];\n\n for (const smPath of possiblePaths) {\n try {\n execFileSync('which', [smPath], { stdio: 'ignore' });\n return smPath;\n } catch {\n // Continue searching\n }\n }\n\n return 'stackmemory'; // Fallback to PATH\n }\n\n private isGitRepo(): boolean {\n try {\n execSync('git rev-parse --git-dir', { stdio: 'ignore' });\n return true;\n } catch {\n return false;\n }\n }\n\n private getCurrentBranch(): string {\n try {\n return execSync('git rev-parse --abbrev-ref HEAD', {\n encoding: 'utf8',\n }).trim();\n } catch {\n return 'main';\n }\n }\n\n private hasUncommittedChanges(): boolean {\n try {\n const status = execSync('git status --porcelain', { encoding: 'utf8' });\n return status.length > 0;\n } catch {\n return false;\n }\n }\n\n private resolveClaudeBin(): string | null {\n // 1) CLI-specified\n if (this.config.claudeBin && this.config.claudeBin.trim()) {\n return this.config.claudeBin.trim();\n }\n // 2) Env override\n const envBin = process.env['CLAUDE_BIN'];\n if (envBin && envBin.trim()) return envBin.trim();\n // 3) PATH detection\n try {\n execSync('which claude', { stdio: 'ignore' });\n return 'claude';\n } catch {}\n return null;\n }\n\n private setupWorktree(): string | null {\n if (!this.config.useWorktree || !this.isGitRepo()) {\n return null;\n }\n\n console.log(chalk.blue('\uD83C\uDF33 Setting up isolated worktree...'));\n\n const timestamp = new Date()\n .toISOString()\n .replace(/[:.]/g, '-')\n .substring(0, 19);\n const branch =\n this.config.branch ||\n `claude-${this.config.task || 'work'}-${timestamp}-${this.config.instanceId}`;\n const repoName = path.basename(process.cwd());\n const worktreePath = path.join(\n path.dirname(process.cwd()),\n `${repoName}--${branch}`\n );\n\n try {\n // Create worktree\n const flags = [];\n if (this.config.useSandbox) flags.push('--sandbox');\n if (this.config.useChrome) flags.push('--chrome');\n\n const cmd = `git worktree add -b \"${branch}\" \"${worktreePath}\"`;\n execSync(cmd, { stdio: 'inherit' });\n\n console.log(chalk.green(`\u2705 Worktree created: ${worktreePath}`));\n console.log(chalk.gray(` Branch: ${branch}`));\n\n // Save worktree config\n const configPath = path.join(worktreePath, '.claude-instance.json');\n const configData = {\n instanceId: this.config.instanceId,\n worktreePath,\n branch,\n task: this.config.task,\n sandboxEnabled: this.config.useSandbox,\n chromeEnabled: this.config.useChrome,\n created: new Date().toISOString(),\n parentRepo: process.cwd(),\n };\n fs.writeFileSync(configPath, JSON.stringify(configData, null, 2));\n\n // Copy environment files\n const envFiles = ['.env', '.env.local', '.mise.toml', '.tool-versions'];\n for (const file of envFiles) {\n const srcPath = path.join(process.cwd(), file);\n if (fs.existsSync(srcPath)) {\n fs.copyFileSync(srcPath, path.join(worktreePath, file));\n }\n }\n\n return worktreePath;\n } catch (err: unknown) {\n console.error(chalk.red('\u274C Failed to create worktree:'), err);\n return null;\n }\n }\n\n private saveContext(\n message: string,\n metadata: Record<string, unknown> = {}\n ): void {\n if (!this.config.contextEnabled) return;\n\n try {\n const contextData = {\n message,\n metadata: {\n ...metadata,\n instanceId: this.config.instanceId,\n worktree: this.config.worktreePath,\n timestamp: new Date().toISOString(),\n },\n };\n\n const cmd = `${this.stackmemoryPath} context save --json '${JSON.stringify(contextData)}'`;\n execSync(cmd, { stdio: 'ignore' });\n } catch {\n // Silently fail - don't interrupt Claude\n }\n }\n\n private loadContext(): void {\n if (!this.config.contextEnabled) return;\n\n try {\n console.log(chalk.blue('\uD83D\uDCDA Loading previous context...'));\n\n // Use 'context show' command which outputs the current context stack\n const cmd = `${this.stackmemoryPath} context show`;\n const output = execSync(cmd, {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'], // Capture stderr to suppress errors\n });\n\n // Check if we got meaningful output (not empty or just headers)\n const lines = output\n .trim()\n .split('\\n')\n .filter((l) => l.trim());\n if (lines.length > 3) {\n // Has content beyond headers\n console.log(chalk.gray('Context stack loaded'));\n }\n } catch {\n // Silently continue - context loading is optional\n }\n }\n\n private detectMultipleInstances(): boolean {\n try {\n const lockDir = path.join(process.cwd(), '.claude-worktree-locks');\n if (!fs.existsSync(lockDir)) return false;\n\n const locks = fs.readdirSync(lockDir).filter((f) => f.endsWith('.lock'));\n const activeLocks = locks.filter((lockFile) => {\n const lockPath = path.join(lockDir, lockFile);\n const lockData = JSON.parse(fs.readFileSync(lockPath, 'utf8'));\n const lockAge = Date.now() - new Date(lockData.created).getTime();\n return lockAge < 24 * 60 * 60 * 1000; // Less than 24 hours old\n });\n\n return activeLocks.length > 0;\n } catch {\n return false;\n }\n }\n\n private suggestWorktreeMode(): void {\n if (this.hasUncommittedChanges()) {\n console.log(chalk.yellow('\u26A0\uFE0F Uncommitted changes detected'));\n console.log(\n chalk.gray(' Consider using --worktree to work in isolation')\n );\n }\n\n if (this.detectMultipleInstances()) {\n console.log(chalk.yellow('\u26A0\uFE0F Other Claude instances detected'));\n console.log(\n chalk.gray(' Using --worktree is recommended to avoid conflicts')\n );\n }\n }\n\n private async sendDoneNotification(exitCode: number | null): Promise<void> {\n try {\n const context: SessionContext = {\n instanceId: this.config.instanceId,\n exitCode,\n sessionStartTime: this.config.sessionStartTime,\n worktreePath: this.config.worktreePath,\n branch: this.config.branch,\n task: this.config.task,\n };\n\n const summary = await generateSessionSummary(context);\n const message = formatSummaryMessage(summary);\n\n console.log(chalk.cyan('\\nSending session summary via WhatsApp...'));\n\n // Build options from suggestions for interactive response\n const options = summary.suggestions.slice(0, 4).map((s) => ({\n key: s.key,\n label: s.label,\n action: s.action,\n }));\n\n const result = await sendNotification({\n type: 'task_complete',\n title: 'Claude Session Complete',\n message,\n prompt:\n options.length > 0\n ? {\n type: 'options',\n options,\n }\n : undefined,\n });\n\n if (result.success) {\n console.log(chalk.green('Notification sent successfully'));\n } else {\n console.log(\n chalk.yellow(`Notification not sent: ${result.error || 'unknown'}`)\n );\n }\n } catch (error) {\n console.log(\n chalk.yellow(\n `Could not send notification: ${error instanceof Error ? error.message : 'unknown'}`\n )\n );\n }\n }\n\n public async run(args: string[]): Promise<void> {\n // Parse arguments\n const claudeArgs: string[] = [];\n let i = 0;\n\n while (i < args.length) {\n const arg = args[i];\n\n switch (arg) {\n case '--worktree':\n case '-w':\n this.config.useWorktree = true;\n break;\n case '--no-worktree':\n case '-W':\n this.config.useWorktree = false;\n break;\n case '--remote':\n case '-r':\n this.config.useRemote = true;\n break;\n case '--no-remote':\n this.config.useRemote = false;\n break;\n case '--notify-done':\n case '-n':\n this.config.notifyOnDone = true;\n break;\n case '--no-notify-done':\n this.config.notifyOnDone = false;\n break;\n case '--sandbox':\n case '-s':\n this.config.useSandbox = true;\n claudeArgs.push('--sandbox');\n break;\n case '--chrome':\n case '-c':\n this.config.useChrome = true;\n claudeArgs.push('--chrome');\n break;\n case '--no-context':\n this.config.contextEnabled = false;\n break;\n case '--no-trace':\n this.config.tracingEnabled = false;\n break;\n case '--verbose-trace':\n this.config.verboseTracing = true;\n break;\n case '--branch':\n case '-b':\n i++;\n this.config.branch = args[i];\n break;\n case '--task':\n case '-t':\n i++;\n this.config.task = args[i];\n break;\n case '--claude-bin':\n i++;\n this.config.claudeBin = args[i];\n process.env['CLAUDE_BIN'] = this.config.claudeBin;\n break;\n case '--auto':\n case '-a':\n // Auto mode: detect and apply best settings\n if (this.isGitRepo()) {\n this.config.useWorktree =\n this.hasUncommittedChanges() || this.detectMultipleInstances();\n }\n break;\n default:\n claudeArgs.push(arg);\n }\n i++;\n }\n\n // Initialize tracing system if enabled\n if (this.config.tracingEnabled) {\n // Set up environment for tracing\n process.env['DEBUG_TRACE'] = 'true';\n process.env['STACKMEMORY_DEBUG'] = 'true';\n process.env['TRACE_OUTPUT'] = 'file'; // Write to file to not clutter Claude output\n process.env['TRACE_MASK_SENSITIVE'] = 'true'; // Always mask sensitive data\n\n if (this.config.verboseTracing) {\n process.env['TRACE_VERBOSITY'] = 'full';\n process.env['TRACE_PARAMS'] = 'true';\n process.env['TRACE_RESULTS'] = 'true';\n process.env['TRACE_MEMORY'] = 'true';\n } else {\n process.env['TRACE_VERBOSITY'] = 'summary';\n process.env['TRACE_PARAMS'] = 'true';\n process.env['TRACE_RESULTS'] = 'false';\n }\n\n // Initialize the tracing system\n initializeTracing();\n\n // Start tracing this Claude session\n trace.command(\n 'claude-sm',\n {\n instanceId: this.config.instanceId,\n worktree: this.config.useWorktree,\n sandbox: this.config.useSandbox,\n task: this.config.task,\n },\n async () => {\n // Session tracing will wrap the entire Claude execution\n }\n );\n }\n\n // Show header\n console.log(chalk.blue('\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557'));\n console.log(chalk.blue('\u2551 Claude + StackMemory + Worktree \u2551'));\n console.log(chalk.blue('\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D'));\n console.log();\n\n // Check Git repo status\n if (this.isGitRepo()) {\n const branch = this.getCurrentBranch();\n console.log(chalk.gray(`\uD83D\uDCCD Current branch: ${branch}`));\n\n if (!this.config.useWorktree) {\n this.suggestWorktreeMode();\n }\n }\n\n // Setup worktree if requested\n if (this.config.useWorktree) {\n const worktreePath = this.setupWorktree();\n if (worktreePath) {\n this.config.worktreePath = worktreePath;\n process.chdir(worktreePath);\n\n // Save context about worktree creation\n this.saveContext('Created worktree for Claude instance', {\n action: 'worktree_created',\n path: worktreePath,\n branch: this.config.branch,\n });\n }\n }\n\n // Load previous context\n this.loadContext();\n\n // Setup environment\n process.env['CLAUDE_INSTANCE_ID'] = this.config.instanceId;\n if (this.config.worktreePath) {\n process.env['CLAUDE_WORKTREE_PATH'] = this.config.worktreePath;\n }\n if (this.config.useRemote) {\n process.env['CLAUDE_REMOTE'] = '1';\n }\n\n console.log(chalk.gray(`\uD83E\uDD16 Instance ID: ${this.config.instanceId}`));\n console.log(chalk.gray(`\uD83D\uDCC1 Working in: ${process.cwd()}`));\n\n if (this.config.useSandbox) {\n console.log(chalk.yellow('\uD83D\uDD12 Sandbox mode enabled'));\n }\n if (this.config.useRemote) {\n console.log(\n chalk.cyan('\uD83D\uDCF1 Remote mode: WhatsApp notifications for all questions')\n );\n }\n if (this.config.useChrome) {\n console.log(chalk.yellow('\uD83C\uDF10 Chrome automation enabled'));\n }\n if (this.config.tracingEnabled) {\n console.log(\n chalk.gray(`\uD83D\uDD0D Debug tracing enabled (logs to ~/.stackmemory/traces/)`)\n );\n if (this.config.verboseTracing) {\n console.log(\n chalk.gray(` Verbose mode: capturing all execution details`)\n );\n }\n }\n\n console.log();\n console.log(chalk.gray('Starting Claude...'));\n console.log(chalk.gray('\u2500'.repeat(42)));\n\n const claudeBin = this.resolveClaudeBin();\n if (!claudeBin) {\n console.error(chalk.red('\u274C Claude CLI not found.'));\n console.log(\n chalk.gray(\n ' Install Claude CLI or set an override:\\n' +\n ' export CLAUDE_BIN=/path/to/claude\\n' +\n ' claude-sm --help\\n\\n' +\n ' Ensure PATH includes npm global bin (npm bin -g).'\n )\n );\n process.exit(1);\n return;\n }\n\n // Launch Claude\n const claude = spawn(claudeBin, claudeArgs, {\n stdio: 'inherit',\n env: process.env,\n });\n\n claude.on('error', (err: NodeJS.ErrnoException) => {\n console.error(chalk.red('\u274C Failed to launch Claude CLI.'));\n if (err.code === 'ENOENT') {\n console.error(\n chalk.gray(' Not found. Set CLAUDE_BIN or install claude on PATH.')\n );\n } else if (err.code === 'EPERM' || err.code === 'EACCES') {\n console.error(\n chalk.gray(\n ' Permission/sandbox issue. Try outside a sandbox or set CLAUDE_BIN.'\n )\n );\n } else {\n console.error(chalk.gray(` ${err.message}`));\n }\n process.exit(1);\n });\n\n // Handle exit\n claude.on('exit', async (code) => {\n // Save final context\n this.saveContext('Claude session ended', {\n action: 'session_end',\n exitCode: code,\n });\n\n // End tracing and show summary if enabled\n if (this.config.tracingEnabled) {\n const summary = trace.getExecutionSummary();\n console.log();\n console.log(chalk.gray('\u2500'.repeat(42)));\n console.log(chalk.blue('Debug Trace Summary:'));\n console.log(chalk.gray(summary));\n }\n\n // Send notification when done (if enabled)\n if (this.config.notifyOnDone || this.config.useRemote) {\n await this.sendDoneNotification(code);\n }\n\n // Offer to clean up worktree\n if (this.config.worktreePath) {\n console.log();\n console.log(chalk.gray('\u2500'.repeat(42)));\n console.log(chalk.blue('Session ended in worktree:'));\n console.log(chalk.gray(` ${this.config.worktreePath}`));\n console.log();\n console.log(chalk.gray('To remove worktree: gd_claude'));\n console.log(chalk.gray('To merge to main: cwm'));\n }\n\n process.exit(code || 0);\n });\n\n // Handle signals\n process.on('SIGINT', () => {\n this.saveContext('Claude session interrupted', {\n action: 'session_interrupt',\n });\n claude.kill('SIGINT');\n });\n\n process.on('SIGTERM', () => {\n this.saveContext('Claude session terminated', {\n action: 'session_terminate',\n });\n claude.kill('SIGTERM');\n });\n }\n}\n\n// CLI interface\nprogram\n .name('claude-sm')\n .description('Claude with StackMemory context and worktree isolation')\n .version('1.0.0');\n\n// Config subcommand\nconst configCmd = program\n .command('config')\n .description('Manage claude-sm defaults');\n\nconfigCmd\n .command('show')\n .description('Show current default settings')\n .action(() => {\n const config = loadSMConfig();\n console.log(chalk.blue('claude-sm defaults:'));\n console.log(\n ` defaultWorktree: ${config.defaultWorktree ? chalk.green('true') : chalk.gray('false')}`\n );\n console.log(\n ` defaultSandbox: ${config.defaultSandbox ? chalk.green('true') : chalk.gray('false')}`\n );\n console.log(\n ` defaultChrome: ${config.defaultChrome ? chalk.green('true') : chalk.gray('false')}`\n );\n console.log(\n ` defaultTracing: ${config.defaultTracing ? chalk.green('true') : chalk.gray('false')}`\n );\n console.log(\n ` defaultRemote: ${config.defaultRemote ? chalk.green('true') : chalk.gray('false')}`\n );\n console.log(\n ` defaultNotifyOnDone: ${config.defaultNotifyOnDone ? chalk.green('true') : chalk.gray('false')}`\n );\n console.log(chalk.gray(`\\nConfig: ${getConfigPath()}`));\n });\n\nconfigCmd\n .command('set <key> <value>')\n .description('Set a default (e.g., set worktree true)')\n .action((key: string, value: string) => {\n const config = loadSMConfig();\n const boolValue = value === 'true' || value === '1' || value === 'on';\n\n const keyMap: Record<string, keyof ClaudeSMConfig> = {\n worktree: 'defaultWorktree',\n sandbox: 'defaultSandbox',\n chrome: 'defaultChrome',\n tracing: 'defaultTracing',\n remote: 'defaultRemote',\n 'notify-done': 'defaultNotifyOnDone',\n notifyondone: 'defaultNotifyOnDone',\n };\n\n const configKey = keyMap[key];\n if (!configKey) {\n console.log(chalk.red(`Unknown key: ${key}`));\n console.log(\n chalk.gray(\n 'Valid keys: worktree, sandbox, chrome, tracing, remote, notify-done'\n )\n );\n process.exit(1);\n }\n\n config[configKey] = boolValue;\n saveSMConfig(config);\n console.log(chalk.green(`Set ${key} = ${boolValue}`));\n });\n\nconfigCmd\n .command('worktree-on')\n .description('Enable worktree mode by default')\n .action(() => {\n const config = loadSMConfig();\n config.defaultWorktree = true;\n saveSMConfig(config);\n console.log(chalk.green('Worktree mode enabled by default'));\n });\n\nconfigCmd\n .command('worktree-off')\n .description('Disable worktree mode by default')\n .action(() => {\n const config = loadSMConfig();\n config.defaultWorktree = false;\n saveSMConfig(config);\n console.log(chalk.green('Worktree mode disabled by default'));\n });\n\nconfigCmd\n .command('remote-on')\n .description('Enable remote mode by default (WhatsApp for all questions)')\n .action(() => {\n const config = loadSMConfig();\n config.defaultRemote = true;\n saveSMConfig(config);\n console.log(chalk.green('Remote mode enabled by default'));\n });\n\nconfigCmd\n .command('remote-off')\n .description('Disable remote mode by default')\n .action(() => {\n const config = loadSMConfig();\n config.defaultRemote = false;\n saveSMConfig(config);\n console.log(chalk.green('Remote mode disabled by default'));\n });\n\nconfigCmd\n .command('notify-done-on')\n .description('Enable WhatsApp notification when session ends (default)')\n .action(() => {\n const config = loadSMConfig();\n config.defaultNotifyOnDone = true;\n saveSMConfig(config);\n console.log(chalk.green('Notify-on-done enabled by default'));\n });\n\nconfigCmd\n .command('notify-done-off')\n .description('Disable notification when session ends')\n .action(() => {\n const config = loadSMConfig();\n config.defaultNotifyOnDone = false;\n saveSMConfig(config);\n console.log(chalk.green('Notify-on-done disabled by default'));\n });\n\n// Main command (default action when no subcommand)\nprogram\n .option('-w, --worktree', 'Create isolated worktree for this instance')\n .option('-W, --no-worktree', 'Disable worktree (override default)')\n .option('-r, --remote', 'Enable remote mode (WhatsApp for all questions)')\n .option('--no-remote', 'Disable remote mode (override default)')\n .option('-n, --notify-done', 'Send WhatsApp notification when session ends')\n .option('--no-notify-done', 'Disable notification when session ends')\n .option('-s, --sandbox', 'Enable sandbox mode (file/network restrictions)')\n .option('-c, --chrome', 'Enable Chrome automation')\n .option('-a, --auto', 'Automatically detect and apply best settings')\n .option('-b, --branch <name>', 'Specify branch name for worktree')\n .option('-t, --task <desc>', 'Task description for context')\n .option('--claude-bin <path>', 'Path to claude CLI (or use CLAUDE_BIN)')\n .option('--no-context', 'Disable StackMemory context integration')\n .option('--no-trace', 'Disable debug tracing (enabled by default)')\n .option('--verbose-trace', 'Enable verbose debug tracing with full details')\n .helpOption('-h, --help', 'Display help')\n .allowUnknownOption(true)\n .action(async (_options) => {\n const claudeSM = new ClaudeSM();\n const args = process.argv.slice(2);\n await claudeSM.run(args);\n });\n\n// Handle direct execution\n// ESM-safe CLI entry\nprogram.parse(process.argv);\n"],
|
|
5
|
+
"mappings": ";;;;;AAOA,SAAS,OAAO,UAAU,oBAAoB;AAC9C,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,YAAY,QAAQ;AACpB,SAAS,eAAe;AACxB,SAAS,MAAM,cAAc;AAC7B,OAAO,WAAW;AAClB,SAAS,mBAAmB,aAAa;AACzC;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AACP,SAAS,wBAAwB;AA8BjC,MAAM,oBAAoC;AAAA,EACxC,iBAAiB;AAAA,EACjB,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,eAAe;AAAA,EACf,qBAAqB;AACvB;AAEA,SAAS,gBAAwB;AAC/B,SAAO,KAAK,KAAK,GAAG,QAAQ,GAAG,gBAAgB,gBAAgB;AACjE;AAEA,SAAS,eAA+B;AACtC,MAAI;AACF,UAAM,aAAa,cAAc;AACjC,QAAI,GAAG,WAAW,UAAU,GAAG;AAC7B,YAAM,UAAU,GAAG,aAAa,YAAY,MAAM;AAClD,aAAO,EAAE,GAAG,mBAAmB,GAAG,KAAK,MAAM,OAAO,EAAE;AAAA,IACxD;AAAA,EACF,QAAQ;AAAA,EAER;AACA,SAAO,EAAE,GAAG,kBAAkB;AAChC;AAEA,SAAS,aAAa,QAA8B;AA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AM,MAAM,oCAAoC,CAAC;AAC/D,CAAC;AAGH,QACG,OAAO,kBAAkB,4CAA4C,EACrE,OAAO,qBAAqB,qCAAqC,EACjE,OAAO,gBAAgB,iDAAiD,EACxE,OAAO,eAAe,wCAAwC,EAC9D,OAAO,qBAAqB,8CAA8C,EAC1E,OAAO,oBAAoB,wCAAwC,EACnE,OAAO,iBAAiB,iDAAiD,EACzE,OAAO,gBAAgB,0BAA0B,EACjD,OAAO,cAAc,8CAA8C,EACnE,OAAO,uBAAuB,kCAAkC,EAChE,OAAO,qBAAqB,8BAA8B,EAC1D,OAAO,uBAAuB,wCAAwC,EACtE,OAAO,gBAAgB,yCAAyC,EAChE,OAAO,cAAc,4CAA4C,EACjE,OAAO,mBAAmB,gDAAgD,EAC1E,WAAW,cAAc,cAAc,EACvC,mBAAmB,IAAI,EACvB,OAAO,OAAO,aAAa;AAC1B,QAAM,WAAW,IAAI,SAAS;AAC9B,QAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,QAAM,SAAS,IAAI,IAAI;AACzB,CAAC;AAIH,QAAQ,MAAM,QAAQ,IAAI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,180 @@
|
|
|
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 { LinearClient } from "../integrations/linear/client.js";
|
|
6
|
+
import { LinearAuthManager } from "../integrations/linear/auth.js";
|
|
7
|
+
const TEST_KEYWORDS = [
|
|
8
|
+
"test",
|
|
9
|
+
"spec",
|
|
10
|
+
"unit test",
|
|
11
|
+
"integration test",
|
|
12
|
+
"e2e",
|
|
13
|
+
"end-to-end",
|
|
14
|
+
"jest",
|
|
15
|
+
"vitest",
|
|
16
|
+
"mocha"
|
|
17
|
+
];
|
|
18
|
+
const VALIDATION_KEYWORDS = [
|
|
19
|
+
"validate",
|
|
20
|
+
"verify",
|
|
21
|
+
"verification",
|
|
22
|
+
"acceptance criteria",
|
|
23
|
+
"ac:",
|
|
24
|
+
"acceptance:",
|
|
25
|
+
"given when then",
|
|
26
|
+
"criteria:"
|
|
27
|
+
];
|
|
28
|
+
const QA_KEYWORDS = ["qa", "quality", "regression", "coverage", "assertion"];
|
|
29
|
+
const TEST_LABELS = [
|
|
30
|
+
"needs-tests",
|
|
31
|
+
"test-required",
|
|
32
|
+
"qa-review",
|
|
33
|
+
"has-ac",
|
|
34
|
+
"acceptance-criteria",
|
|
35
|
+
"tdd",
|
|
36
|
+
"testing"
|
|
37
|
+
];
|
|
38
|
+
function containsKeywords(text, keywords) {
|
|
39
|
+
const lowerText = text.toLowerCase();
|
|
40
|
+
return keywords.some((kw) => lowerText.includes(kw.toLowerCase()));
|
|
41
|
+
}
|
|
42
|
+
function scoreTask(issue, preferTestTasks) {
|
|
43
|
+
let score = 0;
|
|
44
|
+
const description = issue.description || "";
|
|
45
|
+
const title = issue.title || "";
|
|
46
|
+
const fullText = `${title} ${description}`;
|
|
47
|
+
if (containsKeywords(fullText, TEST_KEYWORDS)) {
|
|
48
|
+
score += preferTestTasks ? 10 : 5;
|
|
49
|
+
}
|
|
50
|
+
if (containsKeywords(fullText, VALIDATION_KEYWORDS)) {
|
|
51
|
+
score += preferTestTasks ? 8 : 4;
|
|
52
|
+
}
|
|
53
|
+
if (containsKeywords(fullText, QA_KEYWORDS)) {
|
|
54
|
+
score += preferTestTasks ? 5 : 2;
|
|
55
|
+
}
|
|
56
|
+
const labelNames = issue.labels?.nodes?.map((l) => l.name.toLowerCase()) || [];
|
|
57
|
+
const hasTestLabel = TEST_LABELS.some(
|
|
58
|
+
(tl) => labelNames.some((ln) => ln.includes(tl))
|
|
59
|
+
);
|
|
60
|
+
if (hasTestLabel) {
|
|
61
|
+
score += preferTestTasks ? 5 : 3;
|
|
62
|
+
}
|
|
63
|
+
if (issue.priority === 1) {
|
|
64
|
+
score += 5;
|
|
65
|
+
} else if (issue.priority === 2) {
|
|
66
|
+
score += 3;
|
|
67
|
+
} else if (issue.priority === 3) {
|
|
68
|
+
score += 1;
|
|
69
|
+
}
|
|
70
|
+
if (description.includes("## Acceptance") || description.includes("### AC") || description.includes("- [ ]")) {
|
|
71
|
+
score += 2;
|
|
72
|
+
}
|
|
73
|
+
if (issue.estimate) {
|
|
74
|
+
score += 1;
|
|
75
|
+
}
|
|
76
|
+
return score;
|
|
77
|
+
}
|
|
78
|
+
function getLinearClient() {
|
|
79
|
+
const apiKey = process.env["LINEAR_API_KEY"];
|
|
80
|
+
if (apiKey) {
|
|
81
|
+
return new LinearClient({ apiKey });
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
const authManager = new LinearAuthManager();
|
|
85
|
+
const tokens = authManager.loadTokens();
|
|
86
|
+
if (tokens?.accessToken) {
|
|
87
|
+
return new LinearClient({ accessToken: tokens.accessToken });
|
|
88
|
+
}
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
async function pickNextLinearTask(options = {}) {
|
|
94
|
+
const client = getLinearClient();
|
|
95
|
+
if (!client) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
const { teamId, preferTestTasks = true, limit = 20 } = options;
|
|
99
|
+
try {
|
|
100
|
+
const [backlogIssues, unstartedIssues] = await Promise.all([
|
|
101
|
+
client.getIssues({ teamId, stateType: "backlog", limit }),
|
|
102
|
+
client.getIssues({ teamId, stateType: "unstarted", limit })
|
|
103
|
+
]);
|
|
104
|
+
const allIssues = [...backlogIssues, ...unstartedIssues];
|
|
105
|
+
const unassignedIssues = allIssues.filter((issue) => !issue.assignee);
|
|
106
|
+
if (unassignedIssues.length === 0) {
|
|
107
|
+
if (allIssues.length === 0) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const issuesToScore = unassignedIssues.length > 0 ? unassignedIssues : allIssues;
|
|
112
|
+
const scoredIssues = issuesToScore.map((issue) => ({
|
|
113
|
+
issue,
|
|
114
|
+
score: scoreTask(issue, preferTestTasks)
|
|
115
|
+
}));
|
|
116
|
+
scoredIssues.sort((a, b) => b.score - a.score);
|
|
117
|
+
const best = scoredIssues[0];
|
|
118
|
+
if (!best) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const description = best.issue.description || "";
|
|
122
|
+
const hasTestRequirements = containsKeywords(description, TEST_KEYWORDS) || containsKeywords(description, VALIDATION_KEYWORDS);
|
|
123
|
+
return {
|
|
124
|
+
id: best.issue.id,
|
|
125
|
+
identifier: best.issue.identifier,
|
|
126
|
+
title: best.issue.title,
|
|
127
|
+
priority: best.issue.priority,
|
|
128
|
+
hasTestRequirements,
|
|
129
|
+
estimatedPoints: best.issue.estimate,
|
|
130
|
+
url: best.issue.url,
|
|
131
|
+
score: best.score
|
|
132
|
+
};
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error("[linear-task-picker] Error fetching tasks:", error);
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async function getTopTaskSuggestions(options = {}, count = 3) {
|
|
139
|
+
const client = getLinearClient();
|
|
140
|
+
if (!client) {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
const { teamId, preferTestTasks = true, limit = 30 } = options;
|
|
144
|
+
try {
|
|
145
|
+
const [backlogIssues, unstartedIssues] = await Promise.all([
|
|
146
|
+
client.getIssues({ teamId, stateType: "backlog", limit }),
|
|
147
|
+
client.getIssues({ teamId, stateType: "unstarted", limit })
|
|
148
|
+
]);
|
|
149
|
+
const allIssues = [...backlogIssues, ...unstartedIssues];
|
|
150
|
+
const unassignedIssues = allIssues.filter((issue) => !issue.assignee);
|
|
151
|
+
const issuesToScore = unassignedIssues.length > 0 ? unassignedIssues : allIssues;
|
|
152
|
+
const scoredIssues = issuesToScore.map((issue) => ({
|
|
153
|
+
issue,
|
|
154
|
+
score: scoreTask(issue, preferTestTasks)
|
|
155
|
+
}));
|
|
156
|
+
scoredIssues.sort((a, b) => b.score - a.score);
|
|
157
|
+
return scoredIssues.slice(0, count).map(({ issue, score }) => {
|
|
158
|
+
const description = issue.description || "";
|
|
159
|
+
const hasTestRequirements = containsKeywords(description, TEST_KEYWORDS) || containsKeywords(description, VALIDATION_KEYWORDS);
|
|
160
|
+
return {
|
|
161
|
+
id: issue.id,
|
|
162
|
+
identifier: issue.identifier,
|
|
163
|
+
title: issue.title,
|
|
164
|
+
priority: issue.priority,
|
|
165
|
+
hasTestRequirements,
|
|
166
|
+
estimatedPoints: issue.estimate,
|
|
167
|
+
url: issue.url,
|
|
168
|
+
score
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.error("[linear-task-picker] Error fetching tasks:", error);
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
export {
|
|
177
|
+
getTopTaskSuggestions,
|
|
178
|
+
pickNextLinearTask
|
|
179
|
+
};
|
|
180
|
+
//# sourceMappingURL=linear-task-picker.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/linear-task-picker.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Linear Task Picker\n * Picks the next best task from Linear queue, prioritizing tasks with test/validation requirements\n */\n\nimport { LinearClient, LinearIssue } from '../integrations/linear/client.js';\nimport { LinearAuthManager } from '../integrations/linear/auth.js';\n\nexport interface TaskSuggestion {\n id: string;\n identifier: string; // e.g., \"STA-123\"\n title: string;\n priority: number;\n hasTestRequirements: boolean;\n estimatedPoints?: number;\n url: string;\n score: number;\n}\n\nexport interface PickerOptions {\n teamId?: string;\n preferTestTasks?: boolean;\n limit?: number;\n}\n\n// Keywords indicating test/validation requirements\nconst TEST_KEYWORDS = [\n 'test',\n 'spec',\n 'unit test',\n 'integration test',\n 'e2e',\n 'end-to-end',\n 'jest',\n 'vitest',\n 'mocha',\n];\n\nconst VALIDATION_KEYWORDS = [\n 'validate',\n 'verify',\n 'verification',\n 'acceptance criteria',\n 'ac:',\n 'acceptance:',\n 'given when then',\n 'criteria:',\n];\n\nconst QA_KEYWORDS = ['qa', 'quality', 'regression', 'coverage', 'assertion'];\n\n// Labels that indicate test requirements\nconst TEST_LABELS = [\n 'needs-tests',\n 'test-required',\n 'qa-review',\n 'has-ac',\n 'acceptance-criteria',\n 'tdd',\n 'testing',\n];\n\n/**\n * Check if text contains any of the keywords (case-insensitive)\n */\nfunction containsKeywords(text: string, keywords: string[]): boolean {\n const lowerText = text.toLowerCase();\n return keywords.some((kw) => lowerText.includes(kw.toLowerCase()));\n}\n\n/**\n * Score a task based on test/validation requirements\n */\nfunction scoreTask(issue: LinearIssue, preferTestTasks: boolean): number {\n let score = 0;\n const description = issue.description || '';\n const title = issue.title || '';\n const fullText = `${title} ${description}`;\n\n // +10 if has test/validation keywords in description\n if (containsKeywords(fullText, TEST_KEYWORDS)) {\n score += preferTestTasks ? 10 : 5;\n }\n\n if (containsKeywords(fullText, VALIDATION_KEYWORDS)) {\n score += preferTestTasks ? 8 : 4;\n }\n\n if (containsKeywords(fullText, QA_KEYWORDS)) {\n score += preferTestTasks ? 5 : 2;\n }\n\n // +5 if has test-related labels\n const labelNames =\n issue.labels?.nodes?.map((l: { name: string }) => l.name.toLowerCase()) ||\n [];\n const hasTestLabel = TEST_LABELS.some((tl) =>\n labelNames.some((ln: string) => ln.includes(tl))\n );\n if (hasTestLabel) {\n score += preferTestTasks ? 5 : 3;\n }\n\n // +3 for higher priority (urgent=1, high=2)\n if (issue.priority === 1) {\n score += 5; // Urgent\n } else if (issue.priority === 2) {\n score += 3; // High\n } else if (issue.priority === 3) {\n score += 1; // Medium\n }\n\n // +2 if has acceptance criteria pattern\n if (\n description.includes('## Acceptance') ||\n description.includes('### AC') ||\n description.includes('- [ ]')\n ) {\n score += 2;\n }\n\n // +1 if has estimate (indicates well-scoped)\n if (issue.estimate) {\n score += 1;\n }\n\n return score;\n}\n\n/**\n * Get Linear client instance\n */\nfunction getLinearClient(): LinearClient | null {\n // Try API key first\n const apiKey = process.env['LINEAR_API_KEY'];\n if (apiKey) {\n return new LinearClient({ apiKey });\n }\n\n // Fall back to OAuth\n try {\n const authManager = new LinearAuthManager();\n const tokens = authManager.loadTokens();\n if (tokens?.accessToken) {\n return new LinearClient({ accessToken: tokens.accessToken });\n }\n } catch {\n // Auth not available\n }\n\n return null;\n}\n\n/**\n * Pick the next best task from Linear\n */\nexport async function pickNextLinearTask(\n options: PickerOptions = {}\n): Promise<TaskSuggestion | null> {\n const client = getLinearClient();\n if (!client) {\n return null;\n }\n\n const { teamId, preferTestTasks = true, limit = 20 } = options;\n\n try {\n // Fetch backlog and unstarted issues\n const [backlogIssues, unstartedIssues] = await Promise.all([\n client.getIssues({ teamId, stateType: 'backlog', limit }),\n client.getIssues({ teamId, stateType: 'unstarted', limit }),\n ]);\n\n const allIssues = [...backlogIssues, ...unstartedIssues];\n\n // Filter out assigned issues (we want unassigned ones)\n const unassignedIssues = allIssues.filter((issue) => !issue.assignee);\n\n if (unassignedIssues.length === 0) {\n // If no unassigned, consider all\n if (allIssues.length === 0) {\n return null;\n }\n }\n\n const issuesToScore =\n unassignedIssues.length > 0 ? unassignedIssues : allIssues;\n\n // Score and sort\n const scoredIssues = issuesToScore.map((issue) => ({\n issue,\n score: scoreTask(issue, preferTestTasks),\n }));\n\n scoredIssues.sort((a, b) => b.score - a.score);\n\n const best = scoredIssues[0];\n if (!best) {\n return null;\n }\n\n const description = best.issue.description || '';\n const hasTestRequirements =\n containsKeywords(description, TEST_KEYWORDS) ||\n containsKeywords(description, VALIDATION_KEYWORDS);\n\n return {\n id: best.issue.id,\n identifier: best.issue.identifier,\n title: best.issue.title,\n priority: best.issue.priority,\n hasTestRequirements,\n estimatedPoints: best.issue.estimate,\n url: best.issue.url,\n score: best.score,\n };\n } catch (error) {\n console.error('[linear-task-picker] Error fetching tasks:', error);\n return null;\n }\n}\n\n/**\n * Get multiple task suggestions (for showing options)\n */\nexport async function getTopTaskSuggestions(\n options: PickerOptions = {},\n count: number = 3\n): Promise<TaskSuggestion[]> {\n const client = getLinearClient();\n if (!client) {\n return [];\n }\n\n const { teamId, preferTestTasks = true, limit = 30 } = options;\n\n try {\n const [backlogIssues, unstartedIssues] = await Promise.all([\n client.getIssues({ teamId, stateType: 'backlog', limit }),\n client.getIssues({ teamId, stateType: 'unstarted', limit }),\n ]);\n\n const allIssues = [...backlogIssues, ...unstartedIssues];\n const unassignedIssues = allIssues.filter((issue) => !issue.assignee);\n const issuesToScore =\n unassignedIssues.length > 0 ? unassignedIssues : allIssues;\n\n const scoredIssues = issuesToScore.map((issue) => ({\n issue,\n score: scoreTask(issue, preferTestTasks),\n }));\n\n scoredIssues.sort((a, b) => b.score - a.score);\n\n return scoredIssues.slice(0, count).map(({ issue, score }) => {\n const description = issue.description || '';\n const hasTestRequirements =\n containsKeywords(description, TEST_KEYWORDS) ||\n containsKeywords(description, VALIDATION_KEYWORDS);\n\n return {\n id: issue.id,\n identifier: issue.identifier,\n title: issue.title,\n priority: issue.priority,\n hasTestRequirements,\n estimatedPoints: issue.estimate,\n url: issue.url,\n score,\n };\n });\n } catch (error) {\n console.error('[linear-task-picker] Error fetching tasks:', error);\n return [];\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAKA,SAAS,oBAAiC;AAC1C,SAAS,yBAAyB;AAoBlC,MAAM,gBAAgB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,cAAc,CAAC,MAAM,WAAW,cAAc,YAAY,WAAW;AAG3E,MAAM,cAAc;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MAAM,eAAe;AACzC,YAAM,sBACJ,iBAAiB,aAAa,aAAa,KAC3C,iBAAiB,aAAa,mBAAmB;AAEnD,aAAO;AAAA,QACL,IAAI,MAAM;AAAA,QACV,YAAY,MAAM;AAAA,QAClB,OAAO,MAAM;AAAA,QACb,UAAU,MAAM;AAAA,QAChB;AAAA,QACA,iBAAiB,MAAM;AAAA,QACvB,KAAK,MAAM;AAAA,QACX;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,SAAS,OAAO;AACd,YAAQ,MAAM,8CAA8C,KAAK;AACjE,WAAO,CAAC;AAAA,EACV;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
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 { execSync } from "child_process";
|
|
6
|
+
import { pickNextLinearTask } from "./linear-task-picker.js";
|
|
7
|
+
function formatDuration(ms) {
|
|
8
|
+
const seconds = Math.floor(ms / 1e3);
|
|
9
|
+
const minutes = Math.floor(seconds / 60);
|
|
10
|
+
const hours = Math.floor(minutes / 60);
|
|
11
|
+
if (hours > 0) {
|
|
12
|
+
return `${hours}h ${minutes % 60}min`;
|
|
13
|
+
}
|
|
14
|
+
if (minutes > 0) {
|
|
15
|
+
return `${minutes}min`;
|
|
16
|
+
}
|
|
17
|
+
return `${seconds}s`;
|
|
18
|
+
}
|
|
19
|
+
function getCurrentBranch() {
|
|
20
|
+
try {
|
|
21
|
+
return execSync("git rev-parse --abbrev-ref HEAD", {
|
|
22
|
+
encoding: "utf8",
|
|
23
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
24
|
+
}).trim();
|
|
25
|
+
} catch {
|
|
26
|
+
return "unknown";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function hasUncommittedChanges() {
|
|
30
|
+
try {
|
|
31
|
+
const status = execSync("git status --porcelain", {
|
|
32
|
+
encoding: "utf8",
|
|
33
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
34
|
+
});
|
|
35
|
+
const lines = status.trim().split("\n").filter(Boolean);
|
|
36
|
+
return { changed: lines.length > 0, count: lines.length };
|
|
37
|
+
} catch {
|
|
38
|
+
return { changed: false, count: 0 };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function isInWorktree() {
|
|
42
|
+
try {
|
|
43
|
+
execSync("git rev-parse --is-inside-work-tree", {
|
|
44
|
+
encoding: "utf8",
|
|
45
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
46
|
+
});
|
|
47
|
+
const gitDir = execSync("git rev-parse --git-dir", {
|
|
48
|
+
encoding: "utf8",
|
|
49
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
50
|
+
}).trim();
|
|
51
|
+
return gitDir.includes(".git/worktrees/");
|
|
52
|
+
} catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function hasTestScript() {
|
|
57
|
+
try {
|
|
58
|
+
const packageJson = execSync("cat package.json", {
|
|
59
|
+
encoding: "utf8",
|
|
60
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
61
|
+
});
|
|
62
|
+
const pkg = JSON.parse(packageJson);
|
|
63
|
+
return !!(pkg.scripts?.test || pkg.scripts?.["test:run"]);
|
|
64
|
+
} catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function generateSuggestions(context) {
|
|
69
|
+
const suggestions = [];
|
|
70
|
+
let keyIndex = 1;
|
|
71
|
+
const changes = hasUncommittedChanges();
|
|
72
|
+
const inWorktree = isInWorktree();
|
|
73
|
+
const hasTests = hasTestScript();
|
|
74
|
+
if (context.exitCode !== 0 && context.exitCode !== null) {
|
|
75
|
+
suggestions.push({
|
|
76
|
+
key: String(keyIndex++),
|
|
77
|
+
label: "Review error logs",
|
|
78
|
+
action: "cat ~/.claude/logs/claude-*.log | tail -50",
|
|
79
|
+
priority: 100
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (changes.changed) {
|
|
83
|
+
suggestions.push({
|
|
84
|
+
key: String(keyIndex++),
|
|
85
|
+
label: `Commit changes (${changes.count} files)`,
|
|
86
|
+
action: "git add -A && git commit",
|
|
87
|
+
priority: 90
|
|
88
|
+
});
|
|
89
|
+
const branch = getCurrentBranch();
|
|
90
|
+
if (branch !== "main" && branch !== "master" && branch !== "unknown") {
|
|
91
|
+
suggestions.push({
|
|
92
|
+
key: String(keyIndex++),
|
|
93
|
+
label: "Create PR",
|
|
94
|
+
action: "gh pr create --fill",
|
|
95
|
+
priority: 80
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (hasTests && changes.changed) {
|
|
100
|
+
suggestions.push({
|
|
101
|
+
key: String(keyIndex++),
|
|
102
|
+
label: "Run tests",
|
|
103
|
+
action: "npm run test:run",
|
|
104
|
+
priority: 85
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (inWorktree) {
|
|
108
|
+
suggestions.push({
|
|
109
|
+
key: String(keyIndex++),
|
|
110
|
+
label: "Merge to main",
|
|
111
|
+
action: "cwm",
|
|
112
|
+
// custom alias
|
|
113
|
+
priority: 70
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const linearTask = await pickNextLinearTask({ preferTestTasks: true });
|
|
118
|
+
if (linearTask) {
|
|
119
|
+
suggestions.push({
|
|
120
|
+
key: String(keyIndex++),
|
|
121
|
+
label: `Start: ${linearTask.identifier} - ${linearTask.title.substring(0, 40)}${linearTask.title.length > 40 ? "..." : ""}${linearTask.hasTestRequirements ? " (has tests)" : ""}`,
|
|
122
|
+
action: `stackmemory task start ${linearTask.id} --assign-me`,
|
|
123
|
+
priority: 60
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
} catch {
|
|
127
|
+
}
|
|
128
|
+
const durationMs = Date.now() - context.sessionStartTime;
|
|
129
|
+
if (durationMs > 30 * 60 * 1e3) {
|
|
130
|
+
suggestions.push({
|
|
131
|
+
key: String(keyIndex++),
|
|
132
|
+
label: "Take a break",
|
|
133
|
+
action: 'echo "Great work! Time for a coffee break."',
|
|
134
|
+
priority: 10
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
suggestions.sort((a, b) => b.priority - a.priority);
|
|
138
|
+
suggestions.forEach((s, i) => {
|
|
139
|
+
s.key = String(i + 1);
|
|
140
|
+
});
|
|
141
|
+
return suggestions;
|
|
142
|
+
}
|
|
143
|
+
async function generateSessionSummary(context) {
|
|
144
|
+
const durationMs = Date.now() - context.sessionStartTime;
|
|
145
|
+
const duration = formatDuration(durationMs);
|
|
146
|
+
const branch = context.branch || getCurrentBranch();
|
|
147
|
+
let status = "success";
|
|
148
|
+
if (context.exitCode !== 0 && context.exitCode !== null) {
|
|
149
|
+
status = "error";
|
|
150
|
+
}
|
|
151
|
+
const suggestions = await generateSuggestions(context);
|
|
152
|
+
let linearTask;
|
|
153
|
+
try {
|
|
154
|
+
linearTask = await pickNextLinearTask({ preferTestTasks: true });
|
|
155
|
+
} catch {
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
duration,
|
|
159
|
+
exitCode: context.exitCode,
|
|
160
|
+
branch,
|
|
161
|
+
status,
|
|
162
|
+
suggestions,
|
|
163
|
+
linearTask
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function formatSummaryMessage(summary) {
|
|
167
|
+
const statusEmoji = summary.status === "success" ? "" : "";
|
|
168
|
+
const exitInfo = summary.exitCode !== null ? ` | Exit: ${summary.exitCode}` : "";
|
|
169
|
+
let message = `Claude session complete ${statusEmoji}
|
|
170
|
+
`;
|
|
171
|
+
message += `Duration: ${summary.duration}${exitInfo} | Branch: ${summary.branch}
|
|
172
|
+
|
|
173
|
+
`;
|
|
174
|
+
if (summary.suggestions.length > 0) {
|
|
175
|
+
message += `What to do next:
|
|
176
|
+
`;
|
|
177
|
+
for (const s of summary.suggestions.slice(0, 4)) {
|
|
178
|
+
message += `${s.key}. ${s.label}
|
|
179
|
+
`;
|
|
180
|
+
}
|
|
181
|
+
message += `
|
|
182
|
+
Reply with number or custom action`;
|
|
183
|
+
} else {
|
|
184
|
+
message += `No pending actions. Nice work!`;
|
|
185
|
+
}
|
|
186
|
+
return message;
|
|
187
|
+
}
|
|
188
|
+
function getActionForKey(suggestions, key) {
|
|
189
|
+
const suggestion = suggestions.find((s) => s.key === key);
|
|
190
|
+
return suggestion?.action || null;
|
|
191
|
+
}
|
|
192
|
+
export {
|
|
193
|
+
formatSummaryMessage,
|
|
194
|
+
generateSessionSummary,
|
|
195
|
+
getActionForKey
|
|
196
|
+
};
|
|
197
|
+
//# sourceMappingURL=session-summary.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/session-summary.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Session Summary Generator\n * Generates intelligent suggestions for what to do next after a Claude session\n */\n\nimport { execSync } from 'child_process';\nimport { pickNextLinearTask, TaskSuggestion } from './linear-task-picker.js';\n\nexport interface SessionContext {\n instanceId: string;\n exitCode: number | null;\n sessionStartTime: number;\n worktreePath?: string;\n branch?: string;\n task?: string;\n}\n\nexport interface Suggestion {\n key: string;\n label: string;\n action: string;\n priority: number;\n}\n\nexport interface SessionSummary {\n duration: string;\n exitCode: number | null;\n branch: string;\n status: 'success' | 'error' | 'interrupted';\n suggestions: Suggestion[];\n linearTask?: TaskSuggestion;\n}\n\n/**\n * Format duration in human-readable form\n */\nfunction formatDuration(ms: number): string {\n const seconds = Math.floor(ms / 1000);\n const minutes = Math.floor(seconds / 60);\n const hours = Math.floor(minutes / 60);\n\n if (hours > 0) {\n return `${hours}h ${minutes % 60}min`;\n }\n if (minutes > 0) {\n return `${minutes}min`;\n }\n return `${seconds}s`;\n}\n\n/**\n * Get current git branch\n */\nfunction getCurrentBranch(): string {\n try {\n return execSync('git rev-parse --abbrev-ref HEAD', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n } catch {\n return 'unknown';\n }\n}\n\n/**\n * Check for uncommitted changes\n */\nfunction hasUncommittedChanges(): { changed: boolean; count: number } {\n try {\n const status = execSync('git status --porcelain', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n const lines = status.trim().split('\\n').filter(Boolean);\n return { changed: lines.length > 0, count: lines.length };\n } catch {\n return { changed: false, count: 0 };\n }\n}\n\n/**\n * Check if we're in a worktree\n */\nfunction isInWorktree(): boolean {\n try {\n execSync('git rev-parse --is-inside-work-tree', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n // Check if it's a worktree (not the main repo)\n const gitDir = execSync('git rev-parse --git-dir', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n return gitDir.includes('.git/worktrees/');\n } catch {\n return false;\n }\n}\n\n/**\n * Check if tests exist and might need running\n */\nfunction hasTestScript(): boolean {\n try {\n const packageJson = execSync('cat package.json', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n const pkg = JSON.parse(packageJson);\n return !!(pkg.scripts?.test || pkg.scripts?.['test:run']);\n } catch {\n return false;\n }\n}\n\n/**\n * Generate suggestions based on session context\n */\nasync function generateSuggestions(\n context: SessionContext\n): Promise<Suggestion[]> {\n const suggestions: Suggestion[] = [];\n let keyIndex = 1;\n\n const changes = hasUncommittedChanges();\n const inWorktree = isInWorktree();\n const hasTests = hasTestScript();\n\n // Error case - suggest reviewing logs\n if (context.exitCode !== 0 && context.exitCode !== null) {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Review error logs',\n action: 'cat ~/.claude/logs/claude-*.log | tail -50',\n priority: 100,\n });\n }\n\n // Uncommitted changes - suggest commit or PR\n if (changes.changed) {\n suggestions.push({\n key: String(keyIndex++),\n label: `Commit changes (${changes.count} files)`,\n action: 'git add -A && git commit',\n priority: 90,\n });\n\n // If on feature branch, suggest PR\n const branch = getCurrentBranch();\n if (branch !== 'main' && branch !== 'master' && branch !== 'unknown') {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Create PR',\n action: 'gh pr create --fill',\n priority: 80,\n });\n }\n }\n\n // If tests exist and changes were made, suggest running tests\n if (hasTests && changes.changed) {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Run tests',\n action: 'npm run test:run',\n priority: 85,\n });\n }\n\n // Worktree-specific suggestions\n if (inWorktree) {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Merge to main',\n action: 'cwm', // custom alias\n priority: 70,\n });\n }\n\n // Try to get next Linear task\n try {\n const linearTask = await pickNextLinearTask({ preferTestTasks: true });\n if (linearTask) {\n suggestions.push({\n key: String(keyIndex++),\n label: `Start: ${linearTask.identifier} - ${linearTask.title.substring(0, 40)}${linearTask.title.length > 40 ? '...' : ''}${linearTask.hasTestRequirements ? ' (has tests)' : ''}`,\n action: `stackmemory task start ${linearTask.id} --assign-me`,\n priority: 60,\n });\n }\n } catch {\n // Linear not available, skip\n }\n\n // Long session suggestion\n const durationMs = Date.now() - context.sessionStartTime;\n if (durationMs > 30 * 60 * 1000) {\n // > 30 minutes\n suggestions.push({\n key: String(keyIndex++),\n label: 'Take a break',\n action: 'echo \"Great work! Time for a coffee break.\"',\n priority: 10,\n });\n }\n\n // Sort by priority (highest first) and re-key\n suggestions.sort((a, b) => b.priority - a.priority);\n suggestions.forEach((s, i) => {\n s.key = String(i + 1);\n });\n\n return suggestions;\n}\n\n/**\n * Generate full session summary\n */\nexport async function generateSessionSummary(\n context: SessionContext\n): Promise<SessionSummary> {\n const durationMs = Date.now() - context.sessionStartTime;\n const duration = formatDuration(durationMs);\n const branch = context.branch || getCurrentBranch();\n\n let status: 'success' | 'error' | 'interrupted' = 'success';\n if (context.exitCode !== 0 && context.exitCode !== null) {\n status = 'error';\n }\n\n const suggestions = await generateSuggestions(context);\n\n // Extract linear task if present\n let linearTask: TaskSuggestion | undefined;\n try {\n linearTask = await pickNextLinearTask({ preferTestTasks: true });\n } catch {\n // Linear not available\n }\n\n return {\n duration,\n exitCode: context.exitCode,\n branch,\n status,\n suggestions,\n linearTask,\n };\n}\n\n/**\n * Format session summary as WhatsApp message\n */\nexport function formatSummaryMessage(summary: SessionSummary): string {\n const statusEmoji = summary.status === 'success' ? '' : '';\n const exitInfo =\n summary.exitCode !== null ? ` | Exit: ${summary.exitCode}` : '';\n\n let message = `Claude session complete ${statusEmoji}\\n`;\n message += `Duration: ${summary.duration}${exitInfo} | Branch: ${summary.branch}\\n\\n`;\n\n if (summary.suggestions.length > 0) {\n message += `What to do next:\\n`;\n for (const s of summary.suggestions.slice(0, 4)) {\n message += `${s.key}. ${s.label}\\n`;\n }\n message += `\\nReply with number or custom action`;\n } else {\n message += `No pending actions. Nice work!`;\n }\n\n return message;\n}\n\n/**\n * Get action for a suggestion key\n */\nexport function getActionForKey(\n suggestions: Suggestion[],\n key: string\n): string | null {\n const suggestion = suggestions.find((s) => s.key === key);\n return suggestion?.action || null;\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAKA,SAAS,gBAAgB;AACzB,SAAS,0BAA0C;AA8BnD,SAAS,eAAe,IAAoB;AAC1C,QAAM,UAAU,KAAK,MAAM,KAAK,GAAI;AACpC,QAAM,UAAU,KAAK,MAAM,UAAU,EAAE;AACvC,QAAM,QAAQ,KAAK,MAAM,UAAU,EAAE;AAErC,MAAI,QAAQ,GAAG;AACb,WAAO,GAAG,KAAK,KAAK,UAAU,EAAE;AAAA,EAClC;AACA,MAAI,UAAU,GAAG;AACf,WAAO,GAAG,OAAO;AAAA,EACnB;AACA,SAAO,GAAG,OAAO;AACnB;AAKA,SAAS,mBAA2B;AAClC,MAAI;AACF,WAAO,SAAS,mCAAmC;AAAA,MACjD,UAAU;AAAA,MACV,OAAO,CAAC,QAAQ,QA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AG,CAAC,GAAG;AAC/C,iBAAW,GAAG,EAAE,GAAG,KAAK,EAAE,KAAK;AAAA;AAAA,IACjC;AACA,eAAW;AAAA;AAAA,EACb,OAAO;AACL,eAAW;AAAA,EACb;AAEA,SAAO;AACT;AAKO,SAAS,gBACd,aACA,KACe;AACf,QAAM,aAAa,YAAY,KAAK,CAAC,MAAM,EAAE,QAAQ,GAAG;AACxD,SAAO,YAAY,UAAU;AAC/B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -5,10 +5,12 @@ const __dirname = __pathDirname(__filename);
|
|
|
5
5
|
import { existsSync, readFileSync } from "fs";
|
|
6
6
|
import { join } from "path";
|
|
7
7
|
import { homedir } from "os";
|
|
8
|
-
import {
|
|
8
|
+
import { execFileSync } from "child_process";
|
|
9
9
|
import { randomBytes } from "crypto";
|
|
10
10
|
import { writeFileSecure, ensureSecureDir } from "./secure-fs.js";
|
|
11
11
|
import { ActionQueueSchema, parseConfigSafe } from "./schemas.js";
|
|
12
|
+
import { LinearClient } from "../integrations/linear/client.js";
|
|
13
|
+
import { LinearAuthManager } from "../integrations/linear/auth.js";
|
|
12
14
|
const SAFE_ACTION_PATTERNS = [
|
|
13
15
|
// Git/GitHub CLI commands (limited to safe operations)
|
|
14
16
|
{ pattern: /^gh pr (view|list|status|checks) (\d+)$/ },
|
|
@@ -20,8 +22,20 @@ const SAFE_ACTION_PATTERNS = [
|
|
|
20
22
|
{ pattern: /^npm (test|run build)$/ },
|
|
21
23
|
// StackMemory commands
|
|
22
24
|
{ pattern: /^stackmemory (status|notify check|context list)$/ },
|
|
25
|
+
// Task start with optional --assign-me flag (Linear task ID is UUID format)
|
|
26
|
+
{
|
|
27
|
+
pattern: /^stackmemory task start ([a-f0-9-]{36})( --assign-me)?$/
|
|
28
|
+
},
|
|
29
|
+
// Git commands
|
|
30
|
+
{ pattern: /^git (status|diff|log|branch)( --[a-z-]+)*$/ },
|
|
31
|
+
{ pattern: /^git add -A && git commit$/ },
|
|
32
|
+
{ pattern: /^gh pr create --fill$/ },
|
|
33
|
+
// Custom aliases (cwm = claude worktree merge)
|
|
34
|
+
{ pattern: /^cwm$/ },
|
|
23
35
|
// Simple echo/confirmation (no variables)
|
|
24
|
-
{
|
|
36
|
+
{
|
|
37
|
+
pattern: /^echo "?(Done|OK|Confirmed|Acknowledged|Great work! Time for a coffee break\.)"?$/
|
|
38
|
+
}
|
|
25
39
|
];
|
|
26
40
|
function isActionAllowed(action) {
|
|
27
41
|
const trimmed = action.trim();
|
|
@@ -73,7 +87,60 @@ function queueAction(promptId, response, action) {
|
|
|
73
87
|
saveActionQueue(queue);
|
|
74
88
|
return id;
|
|
75
89
|
}
|
|
76
|
-
function
|
|
90
|
+
function getLinearClient() {
|
|
91
|
+
const apiKey = process.env["LINEAR_API_KEY"];
|
|
92
|
+
if (apiKey) {
|
|
93
|
+
return new LinearClient({ apiKey });
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const authManager = new LinearAuthManager();
|
|
97
|
+
const tokens = authManager.loadTokens();
|
|
98
|
+
if (tokens?.accessToken) {
|
|
99
|
+
return new LinearClient({ accessToken: tokens.accessToken });
|
|
100
|
+
}
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
async function handleSpecialAction(action) {
|
|
106
|
+
const taskStartMatch = action.match(
|
|
107
|
+
/^stackmemory task start ([a-f0-9-]{36})( --assign-me)?$/
|
|
108
|
+
);
|
|
109
|
+
if (taskStartMatch) {
|
|
110
|
+
const issueId = taskStartMatch[1];
|
|
111
|
+
const client = getLinearClient();
|
|
112
|
+
if (!client) {
|
|
113
|
+
return {
|
|
114
|
+
handled: true,
|
|
115
|
+
success: false,
|
|
116
|
+
error: "Linear not configured. Set LINEAR_API_KEY or run stackmemory linear setup."
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const result = await client.startIssue(issueId);
|
|
121
|
+
if (result.success && result.issue) {
|
|
122
|
+
return {
|
|
123
|
+
handled: true,
|
|
124
|
+
success: true,
|
|
125
|
+
output: `Started: ${result.issue.identifier} - ${result.issue.title}`
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
handled: true,
|
|
130
|
+
success: false,
|
|
131
|
+
error: result.error || "Failed to start issue"
|
|
132
|
+
};
|
|
133
|
+
} catch (err) {
|
|
134
|
+
return {
|
|
135
|
+
handled: true,
|
|
136
|
+
success: false,
|
|
137
|
+
error: err instanceof Error ? err.message : "Unknown error"
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return { handled: false };
|
|
142
|
+
}
|
|
143
|
+
async function executeActionSafe(action, _response) {
|
|
77
144
|
if (!isActionAllowed(action)) {
|
|
78
145
|
console.error(`[sms-action] Action not in allowlist: ${action}`);
|
|
79
146
|
return {
|
|
@@ -81,6 +148,14 @@ function executeActionSafe(action, _response) {
|
|
|
81
148
|
error: `Action not allowed. Only pre-approved commands can be executed via SMS.`
|
|
82
149
|
};
|
|
83
150
|
}
|
|
151
|
+
const specialResult = await handleSpecialAction(action);
|
|
152
|
+
if (specialResult.handled) {
|
|
153
|
+
return {
|
|
154
|
+
success: specialResult.success || false,
|
|
155
|
+
output: specialResult.output,
|
|
156
|
+
error: specialResult.error
|
|
157
|
+
};
|
|
158
|
+
}
|
|
84
159
|
try {
|
|
85
160
|
console.log(`[sms-action] Executing safe action: ${action}`);
|
|
86
161
|
const parts = action.split(" ");
|
|
@@ -121,30 +196,22 @@ function markActionCompleted(id, result, error) {
|
|
|
121
196
|
saveActionQueue(queue);
|
|
122
197
|
}
|
|
123
198
|
}
|
|
124
|
-
function executeAction(action) {
|
|
199
|
+
async function executeAction(action) {
|
|
125
200
|
markActionRunning(action.id);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
// 1 minute timeout
|
|
132
|
-
stdio: ["pipe", "pipe", "pipe"]
|
|
133
|
-
});
|
|
134
|
-
markActionCompleted(action.id, output);
|
|
135
|
-
return { success: true, output };
|
|
136
|
-
} catch (err) {
|
|
137
|
-
const error = err instanceof Error ? err.message : String(err);
|
|
138
|
-
markActionCompleted(action.id, void 0, error);
|
|
139
|
-
return { success: false, error };
|
|
201
|
+
const result = await executeActionSafe(action.action, action.response);
|
|
202
|
+
if (result.success) {
|
|
203
|
+
markActionCompleted(action.id, result.output);
|
|
204
|
+
} else {
|
|
205
|
+
markActionCompleted(action.id, void 0, result.error);
|
|
140
206
|
}
|
|
207
|
+
return result;
|
|
141
208
|
}
|
|
142
|
-
function processAllPendingActions() {
|
|
209
|
+
async function processAllPendingActions() {
|
|
143
210
|
const pending = getPendingActions();
|
|
144
211
|
let succeeded = 0;
|
|
145
212
|
let failed = 0;
|
|
146
213
|
for (const action of pending) {
|
|
147
|
-
const result = executeAction(action);
|
|
214
|
+
const result = await executeAction(action);
|
|
148
215
|
if (result.success) {
|
|
149
216
|
succeeded++;
|
|
150
217
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 * Security: Uses allowlist-based action execution to prevent command injection\n */\n\nimport { existsSync, readFileSync } from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport { execSync, execFileSync } from 'child_process';\nimport { randomBytes } from 'crypto';\nimport { writeFileSecure, ensureSecureDir } from './secure-fs.js';\nimport { ActionQueueSchema, parseConfigSafe } from './schemas.js';\n\n// Allowlist of safe action patterns\nconst SAFE_ACTION_PATTERNS: Array<{\n pattern: RegExp;\n validate?: (match: RegExpMatchArray) => boolean;\n}> = [\n // Git/GitHub CLI commands (limited to safe operations)\n { pattern: /^gh pr (view|list|status|checks) (\\d+)$/ },\n { pattern: /^gh pr review (\\d+) --approve$/ },\n { pattern: /^gh pr merge (\\d+) --squash$/ },\n { pattern: /^gh issue (view|list) (\\d+)?$/ },\n\n // NPM commands (limited to safe operations)\n { pattern: /^npm run (build|test|lint|lint:fix|test:run)$/ },\n { pattern: /^npm (test|run build)$/ },\n\n // StackMemory commands\n { pattern: /^stackmemory (status|notify check|context list)$/ },\n\n // Simple echo/confirmation (no variables)\n { pattern: /^echo \"?(Done|OK|Confirmed|Acknowledged)\"?$/ },\n];\n\n/**\n * Check if an action is in the allowlist\n */\nfunction isActionAllowed(action: string): boolean {\n const trimmed = action.trim();\n return SAFE_ACTION_PATTERNS.some(({ pattern, validate }) => {\n const match = trimmed.match(pattern);\n if (!match) return false;\n if (validate && !validate(match)) return false;\n return true;\n });\n}\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\nconst DEFAULT_QUEUE: ActionQueue = {\n actions: [],\n lastChecked: new Date().toISOString(),\n};\n\nexport function loadActionQueue(): ActionQueue {\n try {\n if (existsSync(QUEUE_PATH)) {\n const data = JSON.parse(readFileSync(QUEUE_PATH, 'utf8'));\n return parseConfigSafe(\n ActionQueueSchema,\n data,\n DEFAULT_QUEUE,\n 'action-queue'\n );\n }\n } catch {\n // Use defaults\n }\n return { ...DEFAULT_QUEUE, lastChecked: new Date().toISOString() };\n}\n\nexport function saveActionQueue(queue: ActionQueue): void {\n try {\n ensureSecureDir(join(homedir(), '.stackmemory'));\n writeFileSecure(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 // Use cryptographically secure random ID\n const id = randomBytes(8).toString('hex');\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\n/**\n * Execute an action safely using allowlist validation\n * This prevents command injection by only allowing pre-approved commands\n */\nexport function executeActionSafe(\n action: string,\n _response: string\n): { success: boolean; output?: string; error?: string } {\n // Check if action is in allowlist\n if (!isActionAllowed(action)) {\n console.error(`[sms-action] Action not in allowlist: ${action}`);\n return {\n success: false,\n error: `Action not allowed. Only pre-approved commands can be executed via SMS.`,\n };\n }\n\n try {\n console.log(`[sms-action] Executing safe action: ${action}`);\n\n // Parse the action into command and args\n const parts = action.split(' ');\n const cmd = parts[0];\n const args = parts.slice(1);\n\n // Use execFileSync for commands without shell interpretation\n // This prevents shell injection even if the allowlist is somehow bypassed\n const output = execFileSync(cmd, args, {\n encoding: 'utf8',\n timeout: 60000,\n stdio: ['pipe', 'pipe', 'pipe'],\n shell: false, // Explicitly disable shell\n });\n\n return { success: true, output };\n } catch (err) {\n const error = err instanceof Error ? err.message : String(err);\n return { success: false, error };\n }\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 *\n * SECURITY NOTE: These templates return command strings that must be\n * validated against SAFE_ACTION_PATTERNS before execution.\n * Templates that accept user input are removed to prevent injection.\n */\nexport const ACTION_TEMPLATES = {\n // Git/PR actions (PR numbers must be validated as integers)\n approvePR: (prNumber: string) => {\n // Validate PR number is numeric only\n if (!/^\\d+$/.test(prNumber)) {\n throw new Error('Invalid PR number');\n }\n return `gh pr review ${prNumber} --approve`;\n },\n mergePR: (prNumber: string) => {\n if (!/^\\d+$/.test(prNumber)) {\n throw new Error('Invalid PR number');\n }\n return `gh pr merge ${prNumber} --squash`;\n },\n viewPR: (prNumber: string) => {\n if (!/^\\d+$/.test(prNumber)) {\n throw new Error('Invalid PR number');\n }\n return `gh pr view ${prNumber}`;\n },\n\n // Build actions (no user input)\n rebuild: () => `npm run build`,\n retest: () => `npm run test:run`,\n lint: () => `npm run lint:fix`,\n\n // Status actions (no user input)\n status: () => `stackmemory status`,\n checkNotifications: () => `stackmemory notify check`,\n\n // REMOVED for security - these templates allowed arbitrary user input:\n // - requestChanges (allowed arbitrary message)\n // - closePR (could be used maliciously)\n // - deploy/rollback (too dangerous for SMS)\n // - verifyDeployment (allowed arbitrary URL)\n // - notifySlack (allowed arbitrary message - command injection)\n // - notifyTeam (allowed arbitrary message - command injection)\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": ";;;;AAOA,SAAS,YAAY,oBAAoB;AACzC,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * SMS Action Runner - Executes actions based on SMS responses\n * Bridges SMS responses to Claude Code actions\n *\n * Security: Uses allowlist-based action execution to prevent command injection\n */\n\nimport { existsSync, readFileSync } from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport { execFileSync } from 'child_process';\nimport { randomBytes } from 'crypto';\nimport { writeFileSecure, ensureSecureDir } from './secure-fs.js';\nimport { ActionQueueSchema, parseConfigSafe } from './schemas.js';\nimport { LinearClient } from '../integrations/linear/client.js';\nimport { LinearAuthManager } from '../integrations/linear/auth.js';\n\n// Allowlist of safe action patterns\nconst SAFE_ACTION_PATTERNS: Array<{\n pattern: RegExp;\n validate?: (match: RegExpMatchArray) => boolean;\n}> = [\n // Git/GitHub CLI commands (limited to safe operations)\n { pattern: /^gh pr (view|list|status|checks) (\\d+)$/ },\n { pattern: /^gh pr review (\\d+) --approve$/ },\n { pattern: /^gh pr merge (\\d+) --squash$/ },\n { pattern: /^gh issue (view|list) (\\d+)?$/ },\n\n // NPM commands (limited to safe operations)\n { pattern: /^npm run (build|test|lint|lint:fix|test:run)$/ },\n { pattern: /^npm (test|run build)$/ },\n\n // StackMemory commands\n { pattern: /^stackmemory (status|notify check|context list)$/ },\n // Task start with optional --assign-me flag (Linear task ID is UUID format)\n {\n pattern: /^stackmemory task start ([a-f0-9-]{36})( --assign-me)?$/,\n },\n\n // Git commands\n { pattern: /^git (status|diff|log|branch)( --[a-z-]+)*$/ },\n { pattern: /^git add -A && git commit$/ },\n { pattern: /^gh pr create --fill$/ },\n\n // Custom aliases (cwm = claude worktree merge)\n { pattern: /^cwm$/ },\n\n // Simple echo/confirmation (no variables)\n {\n pattern:\n /^echo \"?(Done|OK|Confirmed|Acknowledged|Great work! Time for a coffee break\\.)\"?$/,\n },\n];\n\n/**\n * Check if an action is in the allowlist\n */\nfunction isActionAllowed(action: string): boolean {\n const trimmed = action.trim();\n return SAFE_ACTION_PATTERNS.some(({ pattern, validate }) => {\n const match = trimmed.match(pattern);\n if (!match) return false;\n if (validate && !validate(match)) return false;\n return true;\n });\n}\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\nconst DEFAULT_QUEUE: ActionQueue = {\n actions: [],\n lastChecked: new Date().toISOString(),\n};\n\nexport function loadActionQueue(): ActionQueue {\n try {\n if (existsSync(QUEUE_PATH)) {\n const data = JSON.parse(readFileSync(QUEUE_PATH, 'utf8'));\n return parseConfigSafe(\n ActionQueueSchema,\n data,\n DEFAULT_QUEUE,\n 'action-queue'\n );\n }\n } catch {\n // Use defaults\n }\n return { ...DEFAULT_QUEUE, lastChecked: new Date().toISOString() };\n}\n\nexport function saveActionQueue(queue: ActionQueue): void {\n try {\n ensureSecureDir(join(homedir(), '.stackmemory'));\n writeFileSecure(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 // Use cryptographically secure random ID\n const id = randomBytes(8).toString('hex');\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\n/**\n * Get Linear client if available\n */\nfunction getLinearClient(): LinearClient | null {\n const apiKey = process.env['LINEAR_API_KEY'];\n if (apiKey) {\n return new LinearClient({ apiKey });\n }\n\n try {\n const authManager = new LinearAuthManager();\n const tokens = authManager.loadTokens();\n if (tokens?.accessToken) {\n return new LinearClient({ accessToken: tokens.accessToken });\n }\n } catch {\n // Auth not available\n }\n\n return null;\n}\n\n/**\n * Handle special actions that require API calls instead of shell commands\n */\nasync function handleSpecialAction(action: string): Promise<{\n handled: boolean;\n success?: boolean;\n output?: string;\n error?: string;\n}> {\n // Handle stackmemory task start command\n const taskStartMatch = action.match(\n /^stackmemory task start ([a-f0-9-]{36})( --assign-me)?$/\n );\n if (taskStartMatch) {\n const issueId = taskStartMatch[1];\n const client = getLinearClient();\n\n if (!client) {\n return {\n handled: true,\n success: false,\n error:\n 'Linear not configured. Set LINEAR_API_KEY or run stackmemory linear setup.',\n };\n }\n\n try {\n const result = await client.startIssue(issueId);\n if (result.success && result.issue) {\n return {\n handled: true,\n success: true,\n output: `Started: ${result.issue.identifier} - ${result.issue.title}`,\n };\n }\n return {\n handled: true,\n success: false,\n error: result.error || 'Failed to start issue',\n };\n } catch (err) {\n return {\n handled: true,\n success: false,\n error: err instanceof Error ? err.message : 'Unknown error',\n };\n }\n }\n\n return { handled: false };\n}\n\n/**\n * Execute an action safely using allowlist validation\n * This prevents command injection by only allowing pre-approved commands\n */\nexport async function executeActionSafe(\n action: string,\n _response: string\n): Promise<{ success: boolean; output?: string; error?: string }> {\n // Check if action is in allowlist\n if (!isActionAllowed(action)) {\n console.error(`[sms-action] Action not in allowlist: ${action}`);\n return {\n success: false,\n error: `Action not allowed. Only pre-approved commands can be executed via SMS.`,\n };\n }\n\n // Check for special actions that need API calls\n const specialResult = await handleSpecialAction(action);\n if (specialResult.handled) {\n return {\n success: specialResult.success || false,\n output: specialResult.output,\n error: specialResult.error,\n };\n }\n\n try {\n console.log(`[sms-action] Executing safe action: ${action}`);\n\n // Parse the action into command and args\n const parts = action.split(' ');\n const cmd = parts[0];\n const args = parts.slice(1);\n\n // Use execFileSync for commands without shell interpretation\n // This prevents shell injection even if the allowlist is somehow bypassed\n const output = execFileSync(cmd, args, {\n encoding: 'utf8',\n timeout: 60000,\n stdio: ['pipe', 'pipe', 'pipe'],\n shell: false, // Explicitly disable shell\n });\n\n return { success: true, output };\n } catch (err) {\n const error = err instanceof Error ? err.message : String(err);\n return { success: false, error };\n }\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 async function executeAction(action: PendingAction): Promise<{\n success: boolean;\n output?: string;\n error?: string;\n}> {\n markActionRunning(action.id);\n\n // Use the safe execution path to prevent command injection\n const result = await executeActionSafe(action.action, action.response);\n\n if (result.success) {\n markActionCompleted(action.id, result.output);\n } else {\n markActionCompleted(action.id, undefined, result.error);\n }\n\n return result;\n}\n\nexport async function processAllPendingActions(): Promise<{\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 = await 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 *\n * SECURITY NOTE: These templates return command strings that must be\n * validated against SAFE_ACTION_PATTERNS before execution.\n * Templates that accept user input are removed to prevent injection.\n */\nexport const ACTION_TEMPLATES = {\n // Git/PR actions (PR numbers must be validated as integers)\n approvePR: (prNumber: string) => {\n // Validate PR number is numeric only\n if (!/^\\d+$/.test(prNumber)) {\n throw new Error('Invalid PR number');\n }\n return `gh pr review ${prNumber} --approve`;\n },\n mergePR: (prNumber: string) => {\n if (!/^\\d+$/.test(prNumber)) {\n throw new Error('Invalid PR number');\n }\n return `gh pr merge ${prNumber} --squash`;\n },\n viewPR: (prNumber: string) => {\n if (!/^\\d+$/.test(prNumber)) {\n throw new Error('Invalid PR number');\n }\n return `gh pr view ${prNumber}`;\n },\n\n // Build actions (no user input)\n rebuild: () => `npm run build`,\n retest: () => `npm run test:run`,\n lint: () => `npm run lint:fix`,\n\n // Status actions (no user input)\n status: () => `stackmemory status`,\n checkNotifications: () => `stackmemory notify check`,\n\n // REMOVED for security - these templates allowed arbitrary user input:\n // - requestChanges (allowed arbitrary message)\n // - closePR (could be used maliciously)\n // - deploy/rollback (too dangerous for SMS)\n // - verifyDeployment (allowed arbitrary URL)\n // - notifySlack (allowed arbitrary message - command injection)\n // - notifyTeam (allowed arbitrary message - command injection)\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": ";;;;AAOA,SAAS,YAAY,oBAAoB;AACzC,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB,uBAAuB;AACjD,SAAS,mBAAmB,uBAAuB;AACnD,SAAS,oBAAoB;AAC7B,SAAS,yBAAyB;AAGlC,MAAM,uBAGD;AAAA;AAAA,EAEH,EAAE,SAAS,0CAA0C;AAAA,EACrD,EAAE,SAAS,iCAAiC;AAAA,EAC5C,EAAE,SAAS,+BAA+B;AAAA,EAC1C,EAAE,SAAS,gCAAgC;AAAA;AAAA,EAG3C,EAAE,SAAS,gDAAgD;AAAA,EAC3D,EAAE,SAAS,yBAAyB;AAAA;AAAA,EAGpC,EAAE,SAAS,mDAAmD;AAAA;AAAA,EAE9D;AAA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
|
"names": []
|
|
7
7
|
}
|
|
@@ -93,7 +93,7 @@ function storeLatestResponse(promptId, response, action) {
|
|
|
93
93
|
})
|
|
94
94
|
);
|
|
95
95
|
}
|
|
96
|
-
function handleSMSWebhook(payload) {
|
|
96
|
+
async function handleSMSWebhook(payload) {
|
|
97
97
|
const { From, Body } = payload;
|
|
98
98
|
if (Body && Body.length > MAX_SMS_BODY_LENGTH) {
|
|
99
99
|
console.log(`[sms-webhook] Body too long: ${Body.length} chars`);
|
|
@@ -121,7 +121,7 @@ function handleSMSWebhook(payload) {
|
|
|
121
121
|
triggerResponseNotification(result.response || Body);
|
|
122
122
|
if (result.action) {
|
|
123
123
|
console.log(`[sms-webhook] Executing action: ${result.action}`);
|
|
124
|
-
const actionResult = executeActionSafe(
|
|
124
|
+
const actionResult = await executeActionSafe(
|
|
125
125
|
result.action,
|
|
126
126
|
result.response || Body
|
|
127
127
|
);
|
|
@@ -243,7 +243,7 @@ function startWebhookServer(port = 3456) {
|
|
|
243
243
|
req.destroy();
|
|
244
244
|
}
|
|
245
245
|
});
|
|
246
|
-
req.on("end", () => {
|
|
246
|
+
req.on("end", async () => {
|
|
247
247
|
if (bodyTooLarge) {
|
|
248
248
|
res.writeHead(413, { "Content-Type": "text/xml" });
|
|
249
249
|
res.end(twimlResponse("Request too large"));
|
|
@@ -266,7 +266,7 @@ function startWebhookServer(port = 3456) {
|
|
|
266
266
|
res.end(twimlResponse("Unauthorized"));
|
|
267
267
|
return;
|
|
268
268
|
}
|
|
269
|
-
const result = handleSMSWebhook(payload);
|
|
269
|
+
const result = await handleSMSWebhook(payload);
|
|
270
270
|
res.writeHead(200, { "Content-Type": "text/xml" });
|
|
271
271
|
res.end(twimlResponse(result.response));
|
|
272
272
|
} catch (err) {
|
|
@@ -348,8 +348,8 @@ function startWebhookServer(port = 3456) {
|
|
|
348
348
|
);
|
|
349
349
|
});
|
|
350
350
|
}
|
|
351
|
-
function smsWebhookMiddleware(req, res) {
|
|
352
|
-
const result = handleSMSWebhook(req.body);
|
|
351
|
+
async function smsWebhookMiddleware(req, res) {
|
|
352
|
+
const result = await handleSMSWebhook(req.body);
|
|
353
353
|
res.type("text/xml");
|
|
354
354
|
res.send(twimlResponse(result.response));
|
|
355
355
|
}
|
|
@@ -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 * Security features:\n * - Twilio signature verification\n * - Rate limiting per IP\n * - Body size limits\n * - Content-type validation\n * - Safe action execution (no shell injection)\n */\n\nimport { createServer, IncomingMessage, ServerResponse } from 'http';\nimport { parse as parseUrl } from 'url';\nimport { existsSync, readFileSync } from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport { createHmac } from 'crypto';\nimport { execFileSync } from 'child_process';\nimport {\n processIncomingResponse,\n loadSMSConfig,\n cleanupExpiredPrompts,\n} from './sms-notify.js';\nimport {\n queueAction,\n executeActionSafe,\n cleanupOldActions,\n} from './sms-action-runner.js';\nimport { writeFileSecure, ensureSecureDir } from './secure-fs.js';\nimport {\n logWebhookRequest,\n logRateLimit,\n logSignatureInvalid,\n logBodyTooLarge,\n logContentTypeInvalid,\n logActionAllowed,\n logActionBlocked,\n logCleanup,\n} from './security-logger.js';\n\n// Cleanup interval (5 minutes)\nconst CLEANUP_INTERVAL_MS = 5 * 60 * 1000;\n\n// Input validation constants\nconst MAX_SMS_BODY_LENGTH = 1000;\nconst MAX_PHONE_LENGTH = 20;\n\n// Security constants\nconst MAX_BODY_SIZE = 50 * 1024; // 50KB max body\nconst RATE_LIMIT_WINDOW_MS = 60 * 1000; // 1 minute\nconst RATE_LIMIT_MAX_REQUESTS = 30; // 30 requests per minute per IP\n\n// Rate limiting store (in production, use Redis)\nconst rateLimitStore = new Map<string, { count: number; resetTime: number }>();\n\nfunction checkRateLimit(ip: string): boolean {\n const now = Date.now();\n const record = rateLimitStore.get(ip);\n\n if (!record || now > record.resetTime) {\n rateLimitStore.set(ip, { count: 1, resetTime: now + RATE_LIMIT_WINDOW_MS });\n return true;\n }\n\n if (record.count >= RATE_LIMIT_MAX_REQUESTS) {\n return false;\n }\n\n record.count++;\n return true;\n}\n\n// Twilio signature verification\nfunction verifyTwilioSignature(\n url: string,\n params: Record<string, string>,\n signature: string\n): boolean {\n const authToken = process.env['TWILIO_AUTH_TOKEN'];\n if (!authToken) {\n console.warn(\n '[sms-webhook] TWILIO_AUTH_TOKEN not set, skipping signature verification'\n );\n return true; // Allow in development, but log warning\n }\n\n // Build the data string (URL + sorted params)\n const sortedKeys = Object.keys(params).sort();\n let data = url;\n for (const key of sortedKeys) {\n data += key + params[key];\n }\n\n // Calculate expected signature\n const hmac = createHmac('sha1', authToken);\n hmac.update(data);\n const expectedSignature = hmac.digest('base64');\n\n return signature === expectedSignature;\n}\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 ensureSecureDir(join(homedir(), '.stackmemory'));\n const responsePath = join(\n homedir(),\n '.stackmemory',\n 'sms-latest-response.json'\n );\n writeFileSecure(\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 // Input length validation\n if (Body && Body.length > MAX_SMS_BODY_LENGTH) {\n console.log(`[sms-webhook] Body too long: ${Body.length} chars`);\n return { response: 'Message too long. Max 1000 characters.' };\n }\n\n if (From && From.length > MAX_PHONE_LENGTH) {\n console.log(`[sms-webhook] Invalid phone number length`);\n return { response: 'Invalid phone number.' };\n }\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 // Trigger notification to alert user/Claude\n triggerResponseNotification(result.response || Body);\n\n // Execute action safely if present (no shell injection)\n if (result.action) {\n console.log(`[sms-webhook] Executing action: ${result.action}`);\n\n const actionResult = executeActionSafe(\n result.action,\n result.response || Body\n );\n\n if (actionResult.success) {\n logActionAllowed('sms-webhook', result.action);\n console.log(\n `[sms-webhook] Action completed: ${(actionResult.output || '').substring(0, 200)}`\n );\n\n return {\n response: `Done! Action executed successfully.`,\n action: result.action,\n queued: false,\n };\n } else {\n logActionBlocked(\n 'sms-webhook',\n result.action,\n actionResult.error || 'unknown'\n );\n console.log(`[sms-webhook] Action failed: ${actionResult.error}`);\n\n // Queue for retry\n queueAction(\n result.prompt?.id || 'unknown',\n result.response || Body,\n result.action\n );\n\n return {\n response: `Action failed, queued for retry: ${(actionResult.error || '').substring(0, 50)}`,\n action: result.action,\n queued: true,\n };\n }\n }\n\n return {\n response: `Received: ${result.response}. Next action will be triggered.`,\n };\n}\n\n// Escape string for AppleScript (prevent injection)\nfunction escapeAppleScript(str: string): string {\n return str\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r')\n .substring(0, 200); // Limit length\n}\n\n// Trigger notification when response received\nfunction triggerResponseNotification(response: string): void {\n const safeMessage = escapeAppleScript(`SMS Response: ${response}`);\n\n // macOS notification using execFile (safer than execSync with shell)\n try {\n execFileSync(\n 'osascript',\n [\n '-e',\n `display notification \"${safeMessage}\" with title \"StackMemory\" sound name \"Glass\"`,\n ],\n { stdio: 'ignore', timeout: 5000 }\n );\n } catch {\n // Ignore if not on macOS\n }\n\n // Write signal file for other processes\n try {\n const signalPath = join(homedir(), '.stackmemory', 'sms-signal.txt');\n writeFileSecure(\n signalPath,\n JSON.stringify({\n type: 'sms_response',\n response,\n timestamp: new Date().toISOString(),\n })\n );\n } catch {\n // Ignore\n }\n\n console.log(`\\n*** SMS RESPONSE RECEIVED: \"${response}\" ***`);\n console.log(`*** Run: stackmemory notify run-actions ***\\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, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\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 (incoming messages)\n if (\n (url.pathname === '/sms' ||\n url.pathname === '/sms/incoming' ||\n url.pathname === '/webhook') &&\n req.method === 'POST'\n ) {\n const clientIp = req.socket.remoteAddress || 'unknown';\n\n // Log webhook request\n logWebhookRequest(\n 'sms-webhook',\n req.method || 'POST',\n url.pathname || '/sms',\n clientIp\n );\n\n // Rate limiting\n if (!checkRateLimit(clientIp)) {\n logRateLimit('sms-webhook', clientIp);\n res.writeHead(429, {\n 'Content-Type': 'text/xml',\n 'Retry-After': '60',\n });\n res.end(twimlResponse('Too many requests. Please try again later.'));\n return;\n }\n\n // Content-type validation\n const contentType = req.headers['content-type'] || '';\n if (!contentType.includes('application/x-www-form-urlencoded')) {\n logContentTypeInvalid('sms-webhook', contentType, clientIp);\n res.writeHead(400, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse('Invalid content type'));\n return;\n }\n\n let body = '';\n let bodyTooLarge = false;\n\n req.on('data', (chunk) => {\n body += chunk;\n // Body size limit\n if (body.length > MAX_BODY_SIZE) {\n bodyTooLarge = true;\n logBodyTooLarge('sms-webhook', body.length, clientIp);\n req.destroy();\n }\n });\n\n req.on('end', () => {\n if (bodyTooLarge) {\n res.writeHead(413, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse('Request too large'));\n return;\n }\n\n try {\n const payload = parseFormData(\n body\n ) as unknown as TwilioWebhookPayload;\n\n // Verify Twilio signature\n const twilioSignature = req.headers['x-twilio-signature'] as string;\n const webhookUrl = `${req.headers['x-forwarded-proto'] || 'http'}://${req.headers.host}${req.url}`;\n\n if (\n twilioSignature &&\n !verifyTwilioSignature(\n webhookUrl,\n payload as unknown as Record<string, string>,\n twilioSignature\n )\n ) {\n logSignatureInvalid('sms-webhook', clientIp);\n console.error('[sms-webhook] Invalid Twilio signature');\n res.writeHead(401, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse('Unauthorized'));\n return;\n }\n\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 callback endpoint (delivery status updates)\n if (url.pathname === '/sms/status' && 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(body);\n console.log(\n `[sms-webhook] Status update: ${payload['MessageSid']} -> ${payload['MessageStatus']}`\n );\n\n // Store status for tracking\n const statusPath = join(\n homedir(),\n '.stackmemory',\n 'sms-status.json'\n );\n const statuses: Record<string, string> = existsSync(statusPath)\n ? JSON.parse(readFileSync(statusPath, 'utf8'))\n : {};\n statuses[payload['MessageSid']] = payload['MessageStatus'];\n writeFileSecure(statusPath, JSON.stringify(statuses, null, 2));\n\n res.writeHead(200, { 'Content-Type': 'text/plain' });\n res.end('OK');\n } catch (err) {\n console.error('[sms-webhook] Status error:', err);\n res.writeHead(500);\n res.end('Error');\n }\n });\n return;\n }\n\n // Server 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(\n `[sms-webhook] Incoming messages: http://localhost:${port}/sms/incoming`\n );\n console.log(\n `[sms-webhook] Status callback: http://localhost:${port}/sms/status`\n );\n console.log(`[sms-webhook] Configure these URLs in Twilio console`);\n\n // Start timed cleanup of expired prompts and old actions\n setInterval(() => {\n try {\n const expiredPrompts = cleanupExpiredPrompts();\n const oldActions = cleanupOldActions();\n if (expiredPrompts > 0 || oldActions > 0) {\n logCleanup('sms-webhook', expiredPrompts, oldActions);\n console.log(\n `[sms-webhook] Cleanup: ${expiredPrompts} expired prompts, ${oldActions} old actions`\n );\n }\n } catch {\n // Ignore cleanup errors\n }\n }, CLEANUP_INTERVAL_MS);\n console.log(\n `[sms-webhook] Cleanup interval: every ${CLEANUP_INTERVAL_MS / 1000}s`\n );\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"],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S;AACzC,OAAK,OAAO,IAAI;AAChB,QAAM,oBAAoB,KAAK,OAAO,QAAQ;AAE9C,SAAO,cAAc;AACvB;AASA,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;AAGA,SAAS,oBACP,UACA,UACA,QACM;AACN,kBAAgB,KAAK,QAAQ,GAAG,cAAc,CAAC;AAC/C,QAAM,eAAe;AAAA,IACnB,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EACF;AACA;AAAA,IACE;AAAA,IACA,KAAK,UAAU;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IACpC,CAAC;AAAA,EACH;AACF;
|
|
4
|
+
"sourcesContent": ["/**\n * SMS Webhook Handler for receiving Twilio responses\n * Can run as standalone server or integrate with existing Express app\n *\n * Security features:\n * - Twilio signature verification\n * - Rate limiting per IP\n * - Body size limits\n * - Content-type validation\n * - Safe action execution (no shell injection)\n */\n\nimport { createServer, IncomingMessage, ServerResponse } from 'http';\nimport { parse as parseUrl } from 'url';\nimport { existsSync, readFileSync } from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport { createHmac } from 'crypto';\nimport { execFileSync } from 'child_process';\nimport {\n processIncomingResponse,\n loadSMSConfig,\n cleanupExpiredPrompts,\n} from './sms-notify.js';\nimport {\n queueAction,\n executeActionSafe,\n cleanupOldActions,\n} from './sms-action-runner.js';\nimport { writeFileSecure, ensureSecureDir } from './secure-fs.js';\nimport {\n logWebhookRequest,\n logRateLimit,\n logSignatureInvalid,\n logBodyTooLarge,\n logContentTypeInvalid,\n logActionAllowed,\n logActionBlocked,\n logCleanup,\n} from './security-logger.js';\n\n// Cleanup interval (5 minutes)\nconst CLEANUP_INTERVAL_MS = 5 * 60 * 1000;\n\n// Input validation constants\nconst MAX_SMS_BODY_LENGTH = 1000;\nconst MAX_PHONE_LENGTH = 20;\n\n// Security constants\nconst MAX_BODY_SIZE = 50 * 1024; // 50KB max body\nconst RATE_LIMIT_WINDOW_MS = 60 * 1000; // 1 minute\nconst RATE_LIMIT_MAX_REQUESTS = 30; // 30 requests per minute per IP\n\n// Rate limiting store (in production, use Redis)\nconst rateLimitStore = new Map<string, { count: number; resetTime: number }>();\n\nfunction checkRateLimit(ip: string): boolean {\n const now = Date.now();\n const record = rateLimitStore.get(ip);\n\n if (!record || now > record.resetTime) {\n rateLimitStore.set(ip, { count: 1, resetTime: now + RATE_LIMIT_WINDOW_MS });\n return true;\n }\n\n if (record.count >= RATE_LIMIT_MAX_REQUESTS) {\n return false;\n }\n\n record.count++;\n return true;\n}\n\n// Twilio signature verification\nfunction verifyTwilioSignature(\n url: string,\n params: Record<string, string>,\n signature: string\n): boolean {\n const authToken = process.env['TWILIO_AUTH_TOKEN'];\n if (!authToken) {\n console.warn(\n '[sms-webhook] TWILIO_AUTH_TOKEN not set, skipping signature verification'\n );\n return true; // Allow in development, but log warning\n }\n\n // Build the data string (URL + sorted params)\n const sortedKeys = Object.keys(params).sort();\n let data = url;\n for (const key of sortedKeys) {\n data += key + params[key];\n }\n\n // Calculate expected signature\n const hmac = createHmac('sha1', authToken);\n hmac.update(data);\n const expectedSignature = hmac.digest('base64');\n\n return signature === expectedSignature;\n}\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 ensureSecureDir(join(homedir(), '.stackmemory'));\n const responsePath = join(\n homedir(),\n '.stackmemory',\n 'sms-latest-response.json'\n );\n writeFileSecure(\n responsePath,\n JSON.stringify({\n promptId,\n response,\n action,\n timestamp: new Date().toISOString(),\n })\n );\n}\n\nexport async function handleSMSWebhook(payload: TwilioWebhookPayload): Promise<{\n response: string;\n action?: string;\n queued?: boolean;\n}> {\n const { From, Body } = payload;\n\n // Input length validation\n if (Body && Body.length > MAX_SMS_BODY_LENGTH) {\n console.log(`[sms-webhook] Body too long: ${Body.length} chars`);\n return { response: 'Message too long. Max 1000 characters.' };\n }\n\n if (From && From.length > MAX_PHONE_LENGTH) {\n console.log(`[sms-webhook] Invalid phone number length`);\n return { response: 'Invalid phone number.' };\n }\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 // Trigger notification to alert user/Claude\n triggerResponseNotification(result.response || Body);\n\n // Execute action safely if present (no shell injection)\n if (result.action) {\n console.log(`[sms-webhook] Executing action: ${result.action}`);\n\n const actionResult = await executeActionSafe(\n result.action,\n result.response || Body\n );\n\n if (actionResult.success) {\n logActionAllowed('sms-webhook', result.action);\n console.log(\n `[sms-webhook] Action completed: ${(actionResult.output || '').substring(0, 200)}`\n );\n\n return {\n response: `Done! Action executed successfully.`,\n action: result.action,\n queued: false,\n };\n } else {\n logActionBlocked(\n 'sms-webhook',\n result.action,\n actionResult.error || 'unknown'\n );\n console.log(`[sms-webhook] Action failed: ${actionResult.error}`);\n\n // Queue for retry\n queueAction(\n result.prompt?.id || 'unknown',\n result.response || Body,\n result.action\n );\n\n return {\n response: `Action failed, queued for retry: ${(actionResult.error || '').substring(0, 50)}`,\n action: result.action,\n queued: true,\n };\n }\n }\n\n return {\n response: `Received: ${result.response}. Next action will be triggered.`,\n };\n}\n\n// Escape string for AppleScript (prevent injection)\nfunction escapeAppleScript(str: string): string {\n return str\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, '\\\\n')\n .replace(/\\r/g, '\\\\r')\n .substring(0, 200); // Limit length\n}\n\n// Trigger notification when response received\nfunction triggerResponseNotification(response: string): void {\n const safeMessage = escapeAppleScript(`SMS Response: ${response}`);\n\n // macOS notification using execFile (safer than execSync with shell)\n try {\n execFileSync(\n 'osascript',\n [\n '-e',\n `display notification \"${safeMessage}\" with title \"StackMemory\" sound name \"Glass\"`,\n ],\n { stdio: 'ignore', timeout: 5000 }\n );\n } catch {\n // Ignore if not on macOS\n }\n\n // Write signal file for other processes\n try {\n const signalPath = join(homedir(), '.stackmemory', 'sms-signal.txt');\n writeFileSecure(\n signalPath,\n JSON.stringify({\n type: 'sms_response',\n response,\n timestamp: new Date().toISOString(),\n })\n );\n } catch {\n // Ignore\n }\n\n console.log(`\\n*** SMS RESPONSE RECEIVED: \"${response}\" ***`);\n console.log(`*** Run: stackmemory notify run-actions ***\\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, '&')\n .replace(/</g, '<')\n .replace(/>/g, '>')\n .replace(/\"/g, '"')\n .replace(/'/g, ''');\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 (incoming messages)\n if (\n (url.pathname === '/sms' ||\n url.pathname === '/sms/incoming' ||\n url.pathname === '/webhook') &&\n req.method === 'POST'\n ) {\n const clientIp = req.socket.remoteAddress || 'unknown';\n\n // Log webhook request\n logWebhookRequest(\n 'sms-webhook',\n req.method || 'POST',\n url.pathname || '/sms',\n clientIp\n );\n\n // Rate limiting\n if (!checkRateLimit(clientIp)) {\n logRateLimit('sms-webhook', clientIp);\n res.writeHead(429, {\n 'Content-Type': 'text/xml',\n 'Retry-After': '60',\n });\n res.end(twimlResponse('Too many requests. Please try again later.'));\n return;\n }\n\n // Content-type validation\n const contentType = req.headers['content-type'] || '';\n if (!contentType.includes('application/x-www-form-urlencoded')) {\n logContentTypeInvalid('sms-webhook', contentType, clientIp);\n res.writeHead(400, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse('Invalid content type'));\n return;\n }\n\n let body = '';\n let bodyTooLarge = false;\n\n req.on('data', (chunk) => {\n body += chunk;\n // Body size limit\n if (body.length > MAX_BODY_SIZE) {\n bodyTooLarge = true;\n logBodyTooLarge('sms-webhook', body.length, clientIp);\n req.destroy();\n }\n });\n\n req.on('end', async () => {\n if (bodyTooLarge) {\n res.writeHead(413, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse('Request too large'));\n return;\n }\n\n try {\n const payload = parseFormData(\n body\n ) as unknown as TwilioWebhookPayload;\n\n // Verify Twilio signature\n const twilioSignature = req.headers['x-twilio-signature'] as string;\n const webhookUrl = `${req.headers['x-forwarded-proto'] || 'http'}://${req.headers.host}${req.url}`;\n\n if (\n twilioSignature &&\n !verifyTwilioSignature(\n webhookUrl,\n payload as unknown as Record<string, string>,\n twilioSignature\n )\n ) {\n logSignatureInvalid('sms-webhook', clientIp);\n console.error('[sms-webhook] Invalid Twilio signature');\n res.writeHead(401, { 'Content-Type': 'text/xml' });\n res.end(twimlResponse('Unauthorized'));\n return;\n }\n\n const result = await 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 callback endpoint (delivery status updates)\n if (url.pathname === '/sms/status' && 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(body);\n console.log(\n `[sms-webhook] Status update: ${payload['MessageSid']} -> ${payload['MessageStatus']}`\n );\n\n // Store status for tracking\n const statusPath = join(\n homedir(),\n '.stackmemory',\n 'sms-status.json'\n );\n const statuses: Record<string, string> = existsSync(statusPath)\n ? JSON.parse(readFileSync(statusPath, 'utf8'))\n : {};\n statuses[payload['MessageSid']] = payload['MessageStatus'];\n writeFileSecure(statusPath, JSON.stringify(statuses, null, 2));\n\n res.writeHead(200, { 'Content-Type': 'text/plain' });\n res.end('OK');\n } catch (err) {\n console.error('[sms-webhook] Status error:', err);\n res.writeHead(500);\n res.end('Error');\n }\n });\n return;\n }\n\n // Server 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(\n `[sms-webhook] Incoming messages: http://localhost:${port}/sms/incoming`\n );\n console.log(\n `[sms-webhook] Status callback: http://localhost:${port}/sms/status`\n );\n console.log(`[sms-webhook] Configure these URLs in Twilio console`);\n\n // Start timed cleanup of expired prompts and old actions\n setInterval(() => {\n try {\n const expiredPrompts = cleanupExpiredPrompts();\n const oldActions = cleanupOldActions();\n if (expiredPrompts > 0 || oldActions > 0) {\n logCleanup('sms-webhook', expiredPrompts, oldActions);\n console.log(\n `[sms-webhook] Cleanup: ${expiredPrompts} expired prompts, ${oldActions} old actions`\n );\n }\n } catch {\n // Ignore cleanup errors\n }\n }, CLEANUP_INTERVAL_MS);\n console.log(\n `[sms-webhook] Cleanup interval: every ${CLEANUP_INTERVAL_MS / 1000}s`\n );\n });\n}\n\n// Express middleware for integration\nexport async function smsWebhookMiddleware(\n req: { body: TwilioWebhookPayload },\n res: { type: (t: string) => void; send: (s: string) => void }\n): Promise<void> {\n const result = await 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": ";;;;AAYA,SAAS,oBAAqD;AAC9D,SAAS,SAAS,gBAAgB;AAClC,SAAS,YAAY,oBAAoB;AACzC,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB,uBAAuB;AACjD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,MAAM,sBAAsB,IAAI,KAAK;AAGrC,MAAM,sBAAsB;AAC5B,MAAM,mBAAmB;AAGzB,MAAM,gBAAgB,KAAK;AAC3B,MAAM,uBAAuB,KAAK;AAClC,MAAM,0BAA0B;AAGhC,MAAM,iBAAiB,oBAAI,IAAkD;AAE7E,SAAS,eAAe,IAAqB;AAC3C,QAAM,MAAM,KAAK,IAAI;AACrB,QAAM,SAAS,eAAe,IAAI,EAAE;AAEpC,MAAI,CAAC,UAAU,MAAM,OAAO,WAAW;AACrC,mBAAe,IAAI,IAAI,EAAE,OAAO,GAAG,WAAW,MAAM,qBAAqB,CAAC;AAC1E,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,SAAS,yBAAyB;AAC3C,WAAO;AAAA,EACT;AAEA,SAAO;AACP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,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.
|
|
3
|
+
"version": "0.5.22",
|
|
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",
|