@stackmemoryai/stackmemory 0.5.19 → 0.5.21
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 +125 -6
- package/dist/cli/claude-sm.js.map +2 -2
- package/dist/core/trace/index.js +0 -68
- package/dist/core/trace/index.js.map +2 -2
- package/dist/hooks/schemas.js +5 -3
- package/dist/hooks/schemas.js.map +2 -2
- package/dist/hooks/security-logger.js +155 -0
- package/dist/hooks/security-logger.js.map +7 -0
- package/dist/hooks/sms-webhook.js +37 -0
- package/dist/hooks/sms-webhook.js.map +2 -2
- package/package.json +1 -1
package/dist/cli/claude-sm.js
CHANGED
|
@@ -11,20 +11,51 @@ 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
|
+
const DEFAULT_SM_CONFIG = {
|
|
15
|
+
defaultWorktree: false,
|
|
16
|
+
defaultSandbox: false,
|
|
17
|
+
defaultChrome: false,
|
|
18
|
+
defaultTracing: true,
|
|
19
|
+
defaultRemote: false
|
|
20
|
+
};
|
|
21
|
+
function getConfigPath() {
|
|
22
|
+
return path.join(os.homedir(), ".stackmemory", "claude-sm.json");
|
|
23
|
+
}
|
|
24
|
+
function loadSMConfig() {
|
|
25
|
+
try {
|
|
26
|
+
const configPath = getConfigPath();
|
|
27
|
+
if (fs.existsSync(configPath)) {
|
|
28
|
+
const content = fs.readFileSync(configPath, "utf8");
|
|
29
|
+
return { ...DEFAULT_SM_CONFIG, ...JSON.parse(content) };
|
|
30
|
+
}
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
return { ...DEFAULT_SM_CONFIG };
|
|
34
|
+
}
|
|
35
|
+
function saveSMConfig(config) {
|
|
36
|
+
const configPath = getConfigPath();
|
|
37
|
+
const dir = path.dirname(configPath);
|
|
38
|
+
if (!fs.existsSync(dir)) {
|
|
39
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
40
|
+
}
|
|
41
|
+
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
42
|
+
}
|
|
14
43
|
class ClaudeSM {
|
|
15
44
|
config;
|
|
16
45
|
stackmemoryPath;
|
|
17
46
|
worktreeScriptPath;
|
|
18
47
|
claudeConfigDir;
|
|
48
|
+
smConfig;
|
|
19
49
|
constructor() {
|
|
50
|
+
this.smConfig = loadSMConfig();
|
|
20
51
|
this.config = {
|
|
21
52
|
instanceId: this.generateInstanceId(),
|
|
22
|
-
useSandbox:
|
|
23
|
-
useChrome:
|
|
24
|
-
useWorktree:
|
|
53
|
+
useSandbox: this.smConfig.defaultSandbox,
|
|
54
|
+
useChrome: this.smConfig.defaultChrome,
|
|
55
|
+
useWorktree: this.smConfig.defaultWorktree,
|
|
56
|
+
useRemote: this.smConfig.defaultRemote,
|
|
25
57
|
contextEnabled: true,
|
|
26
|
-
tracingEnabled:
|
|
27
|
-
// Enable tracing by default for claude-sm
|
|
58
|
+
tracingEnabled: this.smConfig.defaultTracing,
|
|
28
59
|
verboseTracing: false
|
|
29
60
|
};
|
|
30
61
|
this.stackmemoryPath = this.findStackMemory();
|
|
@@ -217,6 +248,17 @@ class ClaudeSM {
|
|
|
217
248
|
case "-w":
|
|
218
249
|
this.config.useWorktree = true;
|
|
219
250
|
break;
|
|
251
|
+
case "--no-worktree":
|
|
252
|
+
case "-W":
|
|
253
|
+
this.config.useWorktree = false;
|
|
254
|
+
break;
|
|
255
|
+
case "--remote":
|
|
256
|
+
case "-r":
|
|
257
|
+
this.config.useRemote = true;
|
|
258
|
+
break;
|
|
259
|
+
case "--no-remote":
|
|
260
|
+
this.config.useRemote = false;
|
|
261
|
+
break;
|
|
220
262
|
case "--sandbox":
|
|
221
263
|
case "-s":
|
|
222
264
|
this.config.useSandbox = true;
|
|
@@ -318,11 +360,19 @@ class ClaudeSM {
|
|
|
318
360
|
if (this.config.worktreePath) {
|
|
319
361
|
process.env["CLAUDE_WORKTREE_PATH"] = this.config.worktreePath;
|
|
320
362
|
}
|
|
363
|
+
if (this.config.useRemote) {
|
|
364
|
+
process.env["CLAUDE_REMOTE"] = "1";
|
|
365
|
+
}
|
|
321
366
|
console.log(chalk.gray(`\u{1F916} Instance ID: ${this.config.instanceId}`));
|
|
322
367
|
console.log(chalk.gray(`\u{1F4C1} Working in: ${process.cwd()}`));
|
|
323
368
|
if (this.config.useSandbox) {
|
|
324
369
|
console.log(chalk.yellow("\u{1F512} Sandbox mode enabled"));
|
|
325
370
|
}
|
|
371
|
+
if (this.config.useRemote) {
|
|
372
|
+
console.log(
|
|
373
|
+
chalk.cyan("\u{1F4F1} Remote mode: WhatsApp notifications for all questions")
|
|
374
|
+
);
|
|
375
|
+
}
|
|
326
376
|
if (this.config.useChrome) {
|
|
327
377
|
console.log(chalk.yellow("\u{1F310} Chrome automation enabled"));
|
|
328
378
|
}
|
|
@@ -408,7 +458,76 @@ class ClaudeSM {
|
|
|
408
458
|
});
|
|
409
459
|
}
|
|
410
460
|
}
|
|
411
|
-
program.name("claude-sm").description("Claude with StackMemory context and worktree isolation").version("1.0.0")
|
|
461
|
+
program.name("claude-sm").description("Claude with StackMemory context and worktree isolation").version("1.0.0");
|
|
462
|
+
const configCmd = program.command("config").description("Manage claude-sm defaults");
|
|
463
|
+
configCmd.command("show").description("Show current default settings").action(() => {
|
|
464
|
+
const config = loadSMConfig();
|
|
465
|
+
console.log(chalk.blue("claude-sm defaults:"));
|
|
466
|
+
console.log(
|
|
467
|
+
` defaultWorktree: ${config.defaultWorktree ? chalk.green("true") : chalk.gray("false")}`
|
|
468
|
+
);
|
|
469
|
+
console.log(
|
|
470
|
+
` defaultSandbox: ${config.defaultSandbox ? chalk.green("true") : chalk.gray("false")}`
|
|
471
|
+
);
|
|
472
|
+
console.log(
|
|
473
|
+
` defaultChrome: ${config.defaultChrome ? chalk.green("true") : chalk.gray("false")}`
|
|
474
|
+
);
|
|
475
|
+
console.log(
|
|
476
|
+
` defaultTracing: ${config.defaultTracing ? chalk.green("true") : chalk.gray("false")}`
|
|
477
|
+
);
|
|
478
|
+
console.log(
|
|
479
|
+
` defaultRemote: ${config.defaultRemote ? chalk.green("true") : chalk.gray("false")}`
|
|
480
|
+
);
|
|
481
|
+
console.log(chalk.gray(`
|
|
482
|
+
Config: ${getConfigPath()}`));
|
|
483
|
+
});
|
|
484
|
+
configCmd.command("set <key> <value>").description("Set a default (e.g., set worktree true)").action((key, value) => {
|
|
485
|
+
const config = loadSMConfig();
|
|
486
|
+
const boolValue = value === "true" || value === "1" || value === "on";
|
|
487
|
+
const keyMap = {
|
|
488
|
+
worktree: "defaultWorktree",
|
|
489
|
+
sandbox: "defaultSandbox",
|
|
490
|
+
chrome: "defaultChrome",
|
|
491
|
+
tracing: "defaultTracing",
|
|
492
|
+
remote: "defaultRemote"
|
|
493
|
+
};
|
|
494
|
+
const configKey = keyMap[key];
|
|
495
|
+
if (!configKey) {
|
|
496
|
+
console.log(chalk.red(`Unknown key: ${key}`));
|
|
497
|
+
console.log(
|
|
498
|
+
chalk.gray("Valid keys: worktree, sandbox, chrome, tracing, remote")
|
|
499
|
+
);
|
|
500
|
+
process.exit(1);
|
|
501
|
+
}
|
|
502
|
+
config[configKey] = boolValue;
|
|
503
|
+
saveSMConfig(config);
|
|
504
|
+
console.log(chalk.green(`Set ${key} = ${boolValue}`));
|
|
505
|
+
});
|
|
506
|
+
configCmd.command("worktree-on").description("Enable worktree mode by default").action(() => {
|
|
507
|
+
const config = loadSMConfig();
|
|
508
|
+
config.defaultWorktree = true;
|
|
509
|
+
saveSMConfig(config);
|
|
510
|
+
console.log(chalk.green("Worktree mode enabled by default"));
|
|
511
|
+
});
|
|
512
|
+
configCmd.command("worktree-off").description("Disable worktree mode by default").action(() => {
|
|
513
|
+
const config = loadSMConfig();
|
|
514
|
+
config.defaultWorktree = false;
|
|
515
|
+
saveSMConfig(config);
|
|
516
|
+
console.log(chalk.green("Worktree mode disabled by default"));
|
|
517
|
+
});
|
|
518
|
+
configCmd.command("remote-on").description("Enable remote mode by default (WhatsApp for all questions)").action(() => {
|
|
519
|
+
const config = loadSMConfig();
|
|
520
|
+
config.defaultRemote = true;
|
|
521
|
+
saveSMConfig(config);
|
|
522
|
+
console.log(chalk.green("Remote mode enabled by default"));
|
|
523
|
+
});
|
|
524
|
+
configCmd.command("remote-off").description("Disable remote mode by default").action(() => {
|
|
525
|
+
const config = loadSMConfig();
|
|
526
|
+
config.defaultRemote = false;
|
|
527
|
+
saveSMConfig(config);
|
|
528
|
+
console.log(chalk.green("Remote mode disabled by default"));
|
|
529
|
+
});
|
|
530
|
+
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("-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) => {
|
|
412
531
|
const claudeSM = new ClaudeSM();
|
|
413
532
|
const args = process.argv.slice(2);
|
|
414
533
|
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 ClaudeConfig {\n instanceId: string;\n worktreePath?: string;\n useSandbox: boolean;\n useChrome: boolean;\n useWorktree: boolean;\n contextEnabled: boolean;\n branch?: string;\n task?: string;\n tracingEnabled: boolean;\n verboseTracing: boolean;\n claudeBin?: string;\n}\n\nclass ClaudeSM {\n private config: ClaudeConfig;\n private stackmemoryPath: string;\n private worktreeScriptPath: string;\n private claudeConfigDir: string;\n\n constructor() {\n this.config = {\n instanceId: this.generateInstanceId(),\n useSandbox: false,\n useChrome: false,\n useWorktree: false,\n contextEnabled: true,\n tracingEnabled: true, // Enable tracing by default for claude-sm\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 '--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\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.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 .option('-w, --worktree', 'Create isolated worktree for this instance')\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;AAC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,KAAK,QAAQ,CAAC;AAAA,IACxB,CAAC;AAGD,YAAQ,GAAG,UAAU,MAAM;AACzB,WAAK,YAAY,8BAA8B;AAAA,QAC7C,QAAQ;AAAA,MACV,CAAC;AACD,aAAO,KAAK,QAAQ;AAAA,IACtB,CAAC;AAED,YAAQ,GAAG,WAAW,MAAM;AAC1B,WAAK,YAAY,6BAA6B;AAAA,QAC5C,QAAQ;AAAA,MACV,CAAC;AACD,aAAO,KAAK,SAAS;AAAA,IACvB,CAAC;AAAA,EACH;AACF;AAGA,QACG,KAAK,WAAW,EAChB,YAAY,wDAAwD,EACpE,QAAQ,OAAO,EACf,OAAO,kBAAkB,4CAA4C,EACrE,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';\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,YAA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AM,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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/core/trace/index.js
CHANGED
|
@@ -2,17 +2,6 @@ import { fileURLToPath as __fileURLToPath } from 'url';
|
|
|
2
2
|
import { dirname as __pathDirname } from 'path';
|
|
3
3
|
const __filename = __fileURLToPath(import.meta.url);
|
|
4
4
|
const __dirname = __pathDirname(__filename);
|
|
5
|
-
function getEnv(key, defaultValue) {
|
|
6
|
-
const value = process.env[key];
|
|
7
|
-
if (value === void 0) {
|
|
8
|
-
if (defaultValue !== void 0) return defaultValue;
|
|
9
|
-
throw new Error(`Environment variable ${key} is required`);
|
|
10
|
-
}
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
function getOptionalEnv(key) {
|
|
14
|
-
return process.env[key];
|
|
15
|
-
}
|
|
16
5
|
import {
|
|
17
6
|
trace,
|
|
18
7
|
TraceContext,
|
|
@@ -39,63 +28,6 @@ import {
|
|
|
39
28
|
wrapGraphQLClient
|
|
40
29
|
} from "./linear-api-wrapper.js";
|
|
41
30
|
function initializeTracing() {
|
|
42
|
-
const config = {
|
|
43
|
-
// Main control
|
|
44
|
-
DEBUG_TRACE: process.env["DEBUG_TRACE"] === "true",
|
|
45
|
-
STACKMEMORY_DEBUG: process.env["STACKMEMORY_DEBUG"] === "true",
|
|
46
|
-
// Output control
|
|
47
|
-
TRACE_OUTPUT: process.env["TRACE_OUTPUT"] || "console",
|
|
48
|
-
// console|file|both
|
|
49
|
-
TRACE_VERBOSITY: process.env["TRACE_VERBOSITY"] || "full",
|
|
50
|
-
// full|errors|summary
|
|
51
|
-
// Content control
|
|
52
|
-
TRACE_PARAMS: process.env["TRACE_PARAMS"] !== "false",
|
|
53
|
-
// Include parameters
|
|
54
|
-
TRACE_RESULTS: process.env["TRACE_RESULTS"] !== "false",
|
|
55
|
-
// Include results
|
|
56
|
-
TRACE_MASK_SENSITIVE: process.env["TRACE_MASK_SENSITIVE"] !== "false",
|
|
57
|
-
// Mask sensitive data
|
|
58
|
-
// Performance
|
|
59
|
-
TRACE_PERF_THRESHOLD: parseInt(
|
|
60
|
-
process.env["TRACE_PERF_THRESHOLD"] || "100"
|
|
61
|
-
),
|
|
62
|
-
// ms
|
|
63
|
-
TRACE_MEMORY: process.env["TRACE_MEMORY"] === "true",
|
|
64
|
-
// Track memory usage
|
|
65
|
-
TRACE_MAX_DEPTH: parseInt(process.env["TRACE_MAX_DEPTH"] || "20"),
|
|
66
|
-
// Max call depth
|
|
67
|
-
// Database specific
|
|
68
|
-
TRACE_DB: process.env["TRACE_DB"] === "true",
|
|
69
|
-
// Enable database tracing
|
|
70
|
-
TRACE_DB_SLOW: parseInt(process.env["TRACE_DB_SLOW"] || "100"),
|
|
71
|
-
// Slow query threshold
|
|
72
|
-
// API specific
|
|
73
|
-
TRACE_API: process.env["TRACE_API"] === "true",
|
|
74
|
-
// Enable API tracing
|
|
75
|
-
TRACE_API_SLOW: parseInt(process.env["TRACE_API_SLOW"] || "1000")
|
|
76
|
-
// Slow API threshold
|
|
77
|
-
};
|
|
78
|
-
if (config.DEBUG_TRACE || config.STACKMEMORY_DEBUG) {
|
|
79
|
-
console.log("Trace Configuration:", {
|
|
80
|
-
enabled: true,
|
|
81
|
-
output: config.TRACE_OUTPUT,
|
|
82
|
-
verbosity: config.TRACE_VERBOSITY,
|
|
83
|
-
includeParams: config.TRACE_PARAMS,
|
|
84
|
-
includeResults: config.TRACE_RESULTS,
|
|
85
|
-
maskSensitive: config.TRACE_MASK_SENSITIVE,
|
|
86
|
-
performanceThreshold: config.TRACE_PERF_THRESHOLD,
|
|
87
|
-
captureMemory: config.TRACE_MEMORY,
|
|
88
|
-
maxDepth: config.TRACE_MAX_DEPTH,
|
|
89
|
-
database: {
|
|
90
|
-
enabled: config.TRACE_DB,
|
|
91
|
-
slowThreshold: config.TRACE_DB_SLOW
|
|
92
|
-
},
|
|
93
|
-
api: {
|
|
94
|
-
enabled: config.TRACE_API,
|
|
95
|
-
slowThreshold: config.TRACE_API_SLOW
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
31
|
}
|
|
100
32
|
function withTracing(fn, options) {
|
|
101
33
|
const originalEnv = process.env["DEBUG_TRACE"];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/core/trace/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Trace Module Export\n * Central export for all tracing functionality\n */\n\nimport type { TraceConfig } from './debug-trace.js';\n
|
|
5
|
-
"mappings": ";;;;AAOA
|
|
4
|
+
"sourcesContent": ["/**\n * Trace Module Export\n * Central export for all tracing functionality\n */\n\nimport type { TraceConfig } from './debug-trace.js';\n\nexport {\n trace,\n TraceContext,\n Trace,\n TraceClass,\n TraceCritical,\n type TraceConfig,\n} from './debug-trace.js';\n\nexport {\n wrapCommand,\n wrapProgram,\n traceStep,\n traceQuery,\n traceAPI,\n} from './cli-trace-wrapper.js';\n\nexport {\n createTracedDatabase,\n wrapDatabase,\n getQueryStatistics,\n createTracedTransaction,\n} from './db-trace-wrapper.js';\n\nexport {\n TraceLinearAPI,\n createTracedFetch,\n wrapGraphQLClient,\n} from './linear-api-wrapper.js';\n\n/**\n * Initialize tracing based on environment configuration\n * Configuration is read directly from env vars by trace decorators\n */\nexport function initializeTracing(): void {\n // No-op - trace config is read from env vars on demand\n}\n\n/**\n * Helper to enable tracing for a specific scope\n */\nexport function withTracing<T>(fn: () => T, options?: Partial<TraceConfig>): T {\n const originalEnv = process.env['DEBUG_TRACE'];\n\n try {\n // Temporarily enable tracing\n process.env['DEBUG_TRACE'] = 'true';\n\n // Apply custom options if provided\n if (options) {\n if (options.output) process.env['TRACE_OUTPUT'] = options.output;\n if (options.verbosity) process.env['TRACE_VERBOSITY'] = options.verbosity;\n if (options.includeParams !== undefined) {\n process.env['TRACE_PARAMS'] = String(options.includeParams);\n }\n if (options.includeResults !== undefined) {\n process.env['TRACE_RESULTS'] = String(options.includeResults);\n }\n if (options.performanceThreshold !== undefined) {\n process.env['TRACE_PERF_THRESHOLD'] = String(\n options.performanceThreshold\n );\n }\n }\n\n return fn();\n } finally {\n // Restore original environment\n if (originalEnv === undefined) {\n delete process.env['DEBUG_TRACE'];\n } else {\n process.env['DEBUG_TRACE'] = originalEnv;\n }\n }\n}\n\n/**\n * Quick enable/disable functions for debugging\n */\nexport const enableTracing = () => {\n process.env['DEBUG_TRACE'] = 'true';\n console.log('Tracing enabled');\n};\n\nexport const disableTracing = () => {\n delete process.env['DEBUG_TRACE'];\n console.log('Tracing disabled');\n};\n\nexport const enableVerboseTracing = () => {\n process.env['DEBUG_TRACE'] = 'true';\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 console.log('Verbose tracing enabled');\n};\n\nexport const enableMinimalTracing = () => {\n process.env['DEBUG_TRACE'] = 'true';\n process.env['TRACE_VERBOSITY'] = 'summary';\n process.env['TRACE_PARAMS'] = 'false';\n process.env['TRACE_RESULTS'] = 'false';\n process.env['TRACE_MEMORY'] = 'false';\n console.log('\u2705 Minimal tracing enabled');\n};\n"],
|
|
5
|
+
"mappings": ";;;;AAOA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMA,SAAS,oBAA0B;AAE1C;AAKO,SAAS,YAAe,IAAa,SAAmC;AAC7E,QAAM,cAAc,QAAQ,IAAI,aAAa;AAE7C,MAAI;AAEF,YAAQ,IAAI,aAAa,IAAI;AAG7B,QAAI,SAAS;AACX,UAAI,QAAQ,OAAQ,SAAQ,IAAI,cAAc,IAAI,QAAQ;AAC1D,UAAI,QAAQ,UAAW,SAAQ,IAAI,iBAAiB,IAAI,QAAQ;AAChE,UAAI,QAAQ,kBAAkB,QAAW;AACvC,gBAAQ,IAAI,cAAc,IAAI,OAAO,QAAQ,aAAa;AAAA,MAC5D;AACA,UAAI,QAAQ,mBAAmB,QAAW;AACxC,gBAAQ,IAAI,eAAe,IAAI,OAAO,QAAQ,cAAc;AAAA,MAC9D;AACA,UAAI,QAAQ,yBAAyB,QAAW;AAC9C,gBAAQ,IAAI,sBAAsB,IAAI;AAAA,UACpC,QAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAEA,WAAO,GAAG;AAAA,EACZ,UAAE;AAEA,QAAI,gBAAgB,QAAW;AAC7B,aAAO,QAAQ,IAAI,aAAa;AAAA,IAClC,OAAO;AACL,cAAQ,IAAI,aAAa,IAAI;AAAA,IAC/B;AAAA,EACF;AACF;AAKO,MAAM,gBAAgB,MAAM;AACjC,UAAQ,IAAI,aAAa,IAAI;AAC7B,UAAQ,IAAI,iBAAiB;AAC/B;AAEO,MAAM,iBAAiB,MAAM;AAClC,SAAO,QAAQ,IAAI,aAAa;AAChC,UAAQ,IAAI,kBAAkB;AAChC;AAEO,MAAM,uBAAuB,MAAM;AACxC,UAAQ,IAAI,aAAa,IAAI;AAC7B,UAAQ,IAAI,iBAAiB,IAAI;AACjC,UAAQ,IAAI,cAAc,IAAI;AAC9B,UAAQ,IAAI,eAAe,IAAI;AAC/B,UAAQ,IAAI,cAAc,IAAI;AAC9B,UAAQ,IAAI,yBAAyB;AACvC;AAEO,MAAM,uBAAuB,MAAM;AACxC,UAAQ,IAAI,aAAa,IAAI;AAC7B,UAAQ,IAAI,iBAAiB,IAAI;AACjC,UAAQ,IAAI,cAAc,IAAI;AAC9B,UAAQ,IAAI,eAAe,IAAI;AAC/B,UAAQ,IAAI,cAAc,IAAI;AAC9B,UAAQ,IAAI,gCAA2B;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/hooks/schemas.js
CHANGED
|
@@ -3,6 +3,7 @@ import { dirname as __pathDirname } from 'path';
|
|
|
3
3
|
const __filename = __fileURLToPath(import.meta.url);
|
|
4
4
|
const __dirname = __pathDirname(__filename);
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import { logConfigInvalid } from "./security-logger.js";
|
|
6
7
|
const PromptOptionSchema = z.object({
|
|
7
8
|
key: z.string().max(10),
|
|
8
9
|
label: z.string().max(200),
|
|
@@ -71,10 +72,11 @@ function parseConfigSafe(schema, data, defaultValue, configName) {
|
|
|
71
72
|
if (result.success) {
|
|
72
73
|
return result.data;
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
result.error.issues.map((i) => `${i.path.join(".")}: ${i.message}`).join(", ")
|
|
75
|
+
const errors = result.error.issues.map(
|
|
76
|
+
(i) => `${i.path.join(".")}: ${i.message}`
|
|
77
77
|
);
|
|
78
|
+
logConfigInvalid(configName, errors);
|
|
79
|
+
console.error(`[hooks] Invalid ${configName} config:`, errors.join(", "));
|
|
78
80
|
return defaultValue;
|
|
79
81
|
}
|
|
80
82
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/schemas.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Zod schemas for hook configuration validation\n * Prevents malformed or malicious configs from being loaded\n */\n\nimport { z } from 'zod';\n\n// SMS/WhatsApp notification schemas\nexport const PromptOptionSchema = z.object({\n key: z.string().max(10),\n label: z.string().max(200),\n action: z.string().max(500).optional(),\n});\n\nexport const PendingPromptSchema = z.object({\n id: z.string().max(32),\n timestamp: z\n .string()\n .datetime({ offset: true })\n .or(z.string().regex(/^\\d{4}-\\d{2}-\\d{2}T/)),\n message: z.string().max(1000),\n options: z.array(PromptOptionSchema).max(10),\n type: z.enum(['options', 'yesno', 'freeform']),\n callback: z.string().max(500).optional(),\n expiresAt: z\n .string()\n .datetime({ offset: true })\n .or(z.string().regex(/^\\d{4}-\\d{2}-\\d{2}T/)),\n});\n\nexport const NotifyOnSchema = z.object({\n taskComplete: z.boolean(),\n reviewReady: z.boolean(),\n error: z.boolean(),\n custom: z.boolean(),\n});\n\nexport const QuietHoursSchema = z.object({\n enabled: z.boolean(),\n start: z.string().regex(/^\\d{2}:\\d{2}$/),\n end: z.string().regex(/^\\d{2}:\\d{2}$/),\n});\n\nexport const SMSConfigSchema = z.object({\n enabled: z.boolean(),\n channel: z.enum(['whatsapp', 'sms']),\n accountSid: z.string().max(100).optional(),\n authToken: z.string().max(100).optional(),\n smsFromNumber: z.string().max(20).optional(),\n smsToNumber: z.string().max(20).optional(),\n whatsappFromNumber: z.string().max(30).optional(),\n whatsappToNumber: z.string().max(30).optional(),\n fromNumber: z.string().max(20).optional(),\n toNumber: z.string().max(20).optional(),\n webhookUrl: z.string().url().max(500).optional(),\n notifyOn: NotifyOnSchema,\n quietHours: QuietHoursSchema.optional(),\n responseTimeout: z.number().int().min(30).max(3600),\n pendingPrompts: z.array(PendingPromptSchema).max(100),\n});\n\n// Action queue schemas\nexport const PendingActionSchema = z.object({\n id: z.string().max(32),\n promptId: z.string().max(32),\n response: z.string().max(1000),\n action: z.string().max(500),\n timestamp: z\n .string()\n .datetime({ offset: true })\n .or(z.string().regex(/^\\d{4}-\\d{2}-\\d{2}T/)),\n status: z.enum(['pending', 'running', 'completed', 'failed']),\n result: z.string().max(10000).optional(),\n error: z.string().max(1000).optional(),\n});\n\nexport const ActionQueueSchema = z.object({\n actions: z.array(PendingActionSchema).max(1000),\n lastChecked: z\n .string()\n .datetime({ offset: true })\n .or(z.string().regex(/^\\d{4}-\\d{2}-\\d{2}T/)),\n});\n\n// Auto-background config schema\nexport const AutoBackgroundConfigSchema = z.object({\n enabled: z.boolean(),\n timeoutMs: z.number().int().min(1000).max(600000),\n alwaysBackground: z.array(z.string().max(200)).max(100),\n neverBackground: z.array(z.string().max(200)).max(100),\n verbose: z.boolean().optional(),\n});\n\n// Type exports\nexport type SMSConfigValidated = z.infer<typeof SMSConfigSchema>;\nexport type ActionQueueValidated = z.infer<typeof ActionQueueSchema>;\nexport type AutoBackgroundConfigValidated = z.infer<\n typeof AutoBackgroundConfigSchema\n>;\n\n/**\n * Safely parse and validate config, returning default on failure\n */\nexport function parseConfigSafe<T>(\n schema: z.ZodSchema<T>,\n data: unknown,\n defaultValue: T,\n configName: string\n): T {\n const result = schema.safeParse(data);\n if (result.success) {\n return result.data;\n }\n
|
|
5
|
-
"mappings": ";;;;AAKA,SAAS,SAAS;
|
|
4
|
+
"sourcesContent": ["/**\n * Zod schemas for hook configuration validation\n * Prevents malformed or malicious configs from being loaded\n */\n\nimport { z } from 'zod';\nimport { logConfigInvalid } from './security-logger.js';\n\n// SMS/WhatsApp notification schemas\nexport const PromptOptionSchema = z.object({\n key: z.string().max(10),\n label: z.string().max(200),\n action: z.string().max(500).optional(),\n});\n\nexport const PendingPromptSchema = z.object({\n id: z.string().max(32),\n timestamp: z\n .string()\n .datetime({ offset: true })\n .or(z.string().regex(/^\\d{4}-\\d{2}-\\d{2}T/)),\n message: z.string().max(1000),\n options: z.array(PromptOptionSchema).max(10),\n type: z.enum(['options', 'yesno', 'freeform']),\n callback: z.string().max(500).optional(),\n expiresAt: z\n .string()\n .datetime({ offset: true })\n .or(z.string().regex(/^\\d{4}-\\d{2}-\\d{2}T/)),\n});\n\nexport const NotifyOnSchema = z.object({\n taskComplete: z.boolean(),\n reviewReady: z.boolean(),\n error: z.boolean(),\n custom: z.boolean(),\n});\n\nexport const QuietHoursSchema = z.object({\n enabled: z.boolean(),\n start: z.string().regex(/^\\d{2}:\\d{2}$/),\n end: z.string().regex(/^\\d{2}:\\d{2}$/),\n});\n\nexport const SMSConfigSchema = z.object({\n enabled: z.boolean(),\n channel: z.enum(['whatsapp', 'sms']),\n accountSid: z.string().max(100).optional(),\n authToken: z.string().max(100).optional(),\n smsFromNumber: z.string().max(20).optional(),\n smsToNumber: z.string().max(20).optional(),\n whatsappFromNumber: z.string().max(30).optional(),\n whatsappToNumber: z.string().max(30).optional(),\n fromNumber: z.string().max(20).optional(),\n toNumber: z.string().max(20).optional(),\n webhookUrl: z.string().url().max(500).optional(),\n notifyOn: NotifyOnSchema,\n quietHours: QuietHoursSchema.optional(),\n responseTimeout: z.number().int().min(30).max(3600),\n pendingPrompts: z.array(PendingPromptSchema).max(100),\n});\n\n// Action queue schemas\nexport const PendingActionSchema = z.object({\n id: z.string().max(32),\n promptId: z.string().max(32),\n response: z.string().max(1000),\n action: z.string().max(500),\n timestamp: z\n .string()\n .datetime({ offset: true })\n .or(z.string().regex(/^\\d{4}-\\d{2}-\\d{2}T/)),\n status: z.enum(['pending', 'running', 'completed', 'failed']),\n result: z.string().max(10000).optional(),\n error: z.string().max(1000).optional(),\n});\n\nexport const ActionQueueSchema = z.object({\n actions: z.array(PendingActionSchema).max(1000),\n lastChecked: z\n .string()\n .datetime({ offset: true })\n .or(z.string().regex(/^\\d{4}-\\d{2}-\\d{2}T/)),\n});\n\n// Auto-background config schema\nexport const AutoBackgroundConfigSchema = z.object({\n enabled: z.boolean(),\n timeoutMs: z.number().int().min(1000).max(600000),\n alwaysBackground: z.array(z.string().max(200)).max(100),\n neverBackground: z.array(z.string().max(200)).max(100),\n verbose: z.boolean().optional(),\n});\n\n// Type exports\nexport type SMSConfigValidated = z.infer<typeof SMSConfigSchema>;\nexport type ActionQueueValidated = z.infer<typeof ActionQueueSchema>;\nexport type AutoBackgroundConfigValidated = z.infer<\n typeof AutoBackgroundConfigSchema\n>;\n\n/**\n * Safely parse and validate config, returning default on failure\n */\nexport function parseConfigSafe<T>(\n schema: z.ZodSchema<T>,\n data: unknown,\n defaultValue: T,\n configName: string\n): T {\n const result = schema.safeParse(data);\n if (result.success) {\n return result.data;\n }\n const errors = result.error.issues.map(\n (i) => `${i.path.join('.')}: ${i.message}`\n );\n logConfigInvalid(configName, errors);\n console.error(`[hooks] Invalid ${configName} config:`, errors.join(', '));\n return defaultValue;\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAKA,SAAS,SAAS;AAClB,SAAS,wBAAwB;AAG1B,MAAM,qBAAqB,EAAE,OAAO;AAAA,EACzC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE;AAAA,EACtB,OAAO,EAAE,OAAO,EAAE,IAAI,GAAG;AAAA,EACzB,QAAQ,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,SAAS;AACvC,CAAC;AAEM,MAAM,sBAAsB,EAAE,OAAO;AAAA,EAC1C,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE;AAAA,EACrB,WAAW,EACR,OAAO,EACP,SAAS,EAAE,QAAQ,KAAK,CAAC,EACzB,GAAG,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAAA,EAC7C,SAAS,EAAE,OAAO,EAAE,IAAI,GAAI;AAAA,EAC5B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,EAAE,OAAO,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG;AAAA,EACtD,iBAAiB,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG;AAAA,EACrD,SAAS,EAAE,QAAQ,EAAE,SAAS;AAChC,CAAC;AAYM,SAAS,gBACd,QACA,MACA,cACA,YACG;AACH,QAAM,SAAS,OAAO,UAAU,IAAI;AACpC,MAAI,OAAO,SAAS;AAClB,WAAO,OAAO;AAAA,EAChB;AACA,QAAM,SAAS,OAAO,MAAM,OAAO;AAAA,IACjC,CAAC,MAAM,GAAG,EAAE,KAAK,KAAK,GAAG,CAAC,KAAK,EAAE,OAAO;AAAA,EAC1C;AACA,mBAAiB,YAAY,MAAM;AACnC,UAAQ,MAAM,mBAAmB,UAAU,YAAY,OAAO,KAAK,IAAI,CAAC;AACxE,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,155 @@
|
|
|
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 { appendFileSync, existsSync, readFileSync, writeFileSync } from "fs";
|
|
6
|
+
import { join } from "path";
|
|
7
|
+
import { homedir } from "os";
|
|
8
|
+
import { ensureSecureDir } from "./secure-fs.js";
|
|
9
|
+
const LOG_DIR = join(homedir(), ".stackmemory", "logs");
|
|
10
|
+
const SECURITY_LOG = join(LOG_DIR, "security.log");
|
|
11
|
+
const MAX_LOG_ENTRIES = 1e4;
|
|
12
|
+
let logCount = 0;
|
|
13
|
+
function logSecurityEvent(type, source, message, details, ip) {
|
|
14
|
+
try {
|
|
15
|
+
ensureSecureDir(LOG_DIR);
|
|
16
|
+
const event = {
|
|
17
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
18
|
+
type,
|
|
19
|
+
source,
|
|
20
|
+
message,
|
|
21
|
+
...details && { details },
|
|
22
|
+
...ip && { ip: maskIp(ip) }
|
|
23
|
+
};
|
|
24
|
+
const logLine = JSON.stringify(event) + "\n";
|
|
25
|
+
appendFileSync(SECURITY_LOG, logLine, { mode: 384 });
|
|
26
|
+
logCount++;
|
|
27
|
+
if (logCount > MAX_LOG_ENTRIES) {
|
|
28
|
+
rotateLog();
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function maskIp(ip) {
|
|
34
|
+
if (!ip) return "unknown";
|
|
35
|
+
if (ip === "::1" || ip === "::ffff:127.0.0.1") return "127.0.0.x";
|
|
36
|
+
const parts = ip.replace("::ffff:", "").split(".");
|
|
37
|
+
if (parts.length === 4) {
|
|
38
|
+
return `${parts[0]}.${parts[1]}.x.x`;
|
|
39
|
+
}
|
|
40
|
+
if (ip.includes(":")) {
|
|
41
|
+
const segments = ip.split(":");
|
|
42
|
+
if (segments.length >= 4) {
|
|
43
|
+
return segments.slice(0, 4).join(":") + ":x:x:x:x";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return "masked";
|
|
47
|
+
}
|
|
48
|
+
function rotateLog() {
|
|
49
|
+
try {
|
|
50
|
+
if (existsSync(SECURITY_LOG)) {
|
|
51
|
+
const content = readFileSync(SECURITY_LOG, "utf8");
|
|
52
|
+
const lines = content.trim().split("\n");
|
|
53
|
+
const keepLines = lines.slice(-MAX_LOG_ENTRIES / 2);
|
|
54
|
+
writeFileSync(SECURITY_LOG, keepLines.join("\n") + "\n", { mode: 384 });
|
|
55
|
+
logCount = keepLines.length;
|
|
56
|
+
}
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function logAuthSuccess(source, details) {
|
|
61
|
+
logSecurityEvent(
|
|
62
|
+
"auth_success",
|
|
63
|
+
source,
|
|
64
|
+
"Authentication successful",
|
|
65
|
+
details
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function logAuthFailure(source, reason, ip, details) {
|
|
69
|
+
logSecurityEvent(
|
|
70
|
+
"auth_failure",
|
|
71
|
+
source,
|
|
72
|
+
`Authentication failed: ${reason}`,
|
|
73
|
+
details,
|
|
74
|
+
ip
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
function logRateLimit(source, ip) {
|
|
78
|
+
logSecurityEvent("rate_limit", source, "Rate limit exceeded", void 0, ip);
|
|
79
|
+
}
|
|
80
|
+
function logActionAllowed(source, action) {
|
|
81
|
+
logSecurityEvent(
|
|
82
|
+
"action_allowed",
|
|
83
|
+
source,
|
|
84
|
+
`Action executed: ${action.substring(0, 100)}`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
function logActionBlocked(source, action, reason) {
|
|
88
|
+
logSecurityEvent("action_blocked", source, `Action blocked: ${reason}`, {
|
|
89
|
+
action: action.substring(0, 100)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function logConfigInvalid(source, errors) {
|
|
93
|
+
logSecurityEvent("config_invalid", source, "Invalid config rejected", {
|
|
94
|
+
errors: errors.slice(0, 5)
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function logWebhookRequest(source, method, path, ip) {
|
|
98
|
+
logSecurityEvent(
|
|
99
|
+
"webhook_request",
|
|
100
|
+
source,
|
|
101
|
+
`${method} ${path}`,
|
|
102
|
+
void 0,
|
|
103
|
+
ip
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
function logSignatureInvalid(source, ip) {
|
|
107
|
+
logSecurityEvent(
|
|
108
|
+
"signature_invalid",
|
|
109
|
+
source,
|
|
110
|
+
"Invalid request signature",
|
|
111
|
+
void 0,
|
|
112
|
+
ip
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
function logBodyTooLarge(source, size, ip) {
|
|
116
|
+
logSecurityEvent(
|
|
117
|
+
"body_too_large",
|
|
118
|
+
source,
|
|
119
|
+
`Request body too large: ${size} bytes`,
|
|
120
|
+
void 0,
|
|
121
|
+
ip
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
function logContentTypeInvalid(source, contentType, ip) {
|
|
125
|
+
logSecurityEvent(
|
|
126
|
+
"content_type_invalid",
|
|
127
|
+
source,
|
|
128
|
+
`Invalid content type: ${contentType}`,
|
|
129
|
+
void 0,
|
|
130
|
+
ip
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
function logCleanup(source, expiredPrompts, oldActions) {
|
|
134
|
+
if (expiredPrompts > 0 || oldActions > 0) {
|
|
135
|
+
logSecurityEvent("cleanup", source, "Cleanup completed", {
|
|
136
|
+
expiredPrompts,
|
|
137
|
+
oldActions
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
export {
|
|
142
|
+
logActionAllowed,
|
|
143
|
+
logActionBlocked,
|
|
144
|
+
logAuthFailure,
|
|
145
|
+
logAuthSuccess,
|
|
146
|
+
logBodyTooLarge,
|
|
147
|
+
logCleanup,
|
|
148
|
+
logConfigInvalid,
|
|
149
|
+
logContentTypeInvalid,
|
|
150
|
+
logRateLimit,
|
|
151
|
+
logSecurityEvent,
|
|
152
|
+
logSignatureInvalid,
|
|
153
|
+
logWebhookRequest
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=security-logger.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/security-logger.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Security Event Logger for hooks\n * Logs security-relevant events for audit trail\n */\n\nimport { appendFileSync, existsSync, readFileSync, writeFileSync } from 'fs';\nimport { join } from 'path';\nimport { homedir } from 'os';\nimport { ensureSecureDir } from './secure-fs.js';\n\nconst LOG_DIR = join(homedir(), '.stackmemory', 'logs');\nconst SECURITY_LOG = join(LOG_DIR, 'security.log');\nconst MAX_LOG_ENTRIES = 10000;\n\nexport type SecurityEventType =\n | 'auth_success'\n | 'auth_failure'\n | 'rate_limit'\n | 'action_allowed'\n | 'action_blocked'\n | 'config_invalid'\n | 'config_loaded'\n | 'webhook_request'\n | 'signature_invalid'\n | 'body_too_large'\n | 'content_type_invalid'\n | 'cleanup';\n\nexport interface SecurityEvent {\n timestamp: string;\n type: SecurityEventType;\n source: string;\n message: string;\n details?: Record<string, unknown>;\n ip?: string;\n}\n\nlet logCount = 0;\n\n/**\n * Log a security event\n */\nexport function logSecurityEvent(\n type: SecurityEventType,\n source: string,\n message: string,\n details?: Record<string, unknown>,\n ip?: string\n): void {\n try {\n ensureSecureDir(LOG_DIR);\n\n const event: SecurityEvent = {\n timestamp: new Date().toISOString(),\n type,\n source,\n message,\n ...(details && { details }),\n ...(ip && { ip: maskIp(ip) }),\n };\n\n const logLine = JSON.stringify(event) + '\\n';\n appendFileSync(SECURITY_LOG, logLine, { mode: 0o600 });\n\n logCount++;\n\n // Rotate log if too large (simple rotation - truncate)\n if (logCount > MAX_LOG_ENTRIES) {\n rotateLog();\n }\n } catch {\n // Don't let logging failures break the application\n }\n}\n\n/**\n * Mask IP address for privacy (keep first two octets)\n */\nfunction maskIp(ip: string): string {\n if (!ip) return 'unknown';\n\n // Handle IPv6 localhost\n if (ip === '::1' || ip === '::ffff:127.0.0.1') return '127.0.0.x';\n\n // Handle IPv4\n const parts = ip.replace('::ffff:', '').split('.');\n if (parts.length === 4) {\n return `${parts[0]}.${parts[1]}.x.x`;\n }\n\n // Handle IPv6 - mask last 64 bits\n if (ip.includes(':')) {\n const segments = ip.split(':');\n if (segments.length >= 4) {\n return segments.slice(0, 4).join(':') + ':x:x:x:x';\n }\n }\n\n return 'masked';\n}\n\n/**\n * Simple log rotation - keep last half of entries\n */\nfunction rotateLog(): void {\n try {\n if (existsSync(SECURITY_LOG)) {\n const content = readFileSync(SECURITY_LOG, 'utf8');\n const lines = content.trim().split('\\n');\n const keepLines = lines.slice(-MAX_LOG_ENTRIES / 2);\n writeFileSync(SECURITY_LOG, keepLines.join('\\n') + '\\n', { mode: 0o600 });\n logCount = keepLines.length;\n }\n } catch {\n // Ignore rotation errors\n }\n}\n\n// Convenience functions for common events\n\nexport function logAuthSuccess(\n source: string,\n details?: Record<string, unknown>\n): void {\n logSecurityEvent(\n 'auth_success',\n source,\n 'Authentication successful',\n details\n );\n}\n\nexport function logAuthFailure(\n source: string,\n reason: string,\n ip?: string,\n details?: Record<string, unknown>\n): void {\n logSecurityEvent(\n 'auth_failure',\n source,\n `Authentication failed: ${reason}`,\n details,\n ip\n );\n}\n\nexport function logRateLimit(source: string, ip: string): void {\n logSecurityEvent('rate_limit', source, 'Rate limit exceeded', undefined, ip);\n}\n\nexport function logActionAllowed(source: string, action: string): void {\n logSecurityEvent(\n 'action_allowed',\n source,\n `Action executed: ${action.substring(0, 100)}`\n );\n}\n\nexport function logActionBlocked(\n source: string,\n action: string,\n reason: string\n): void {\n logSecurityEvent('action_blocked', source, `Action blocked: ${reason}`, {\n action: action.substring(0, 100),\n });\n}\n\nexport function logConfigInvalid(source: string, errors: string[]): void {\n logSecurityEvent('config_invalid', source, 'Invalid config rejected', {\n errors: errors.slice(0, 5),\n });\n}\n\nexport function logWebhookRequest(\n source: string,\n method: string,\n path: string,\n ip?: string\n): void {\n logSecurityEvent(\n 'webhook_request',\n source,\n `${method} ${path}`,\n undefined,\n ip\n );\n}\n\nexport function logSignatureInvalid(source: string, ip?: string): void {\n logSecurityEvent(\n 'signature_invalid',\n source,\n 'Invalid request signature',\n undefined,\n ip\n );\n}\n\nexport function logBodyTooLarge(\n source: string,\n size: number,\n ip?: string\n): void {\n logSecurityEvent(\n 'body_too_large',\n source,\n `Request body too large: ${size} bytes`,\n undefined,\n ip\n );\n}\n\nexport function logContentTypeInvalid(\n source: string,\n contentType: string,\n ip?: string\n): void {\n logSecurityEvent(\n 'content_type_invalid',\n source,\n `Invalid content type: ${contentType}`,\n undefined,\n ip\n );\n}\n\nexport function logCleanup(\n source: string,\n expiredPrompts: number,\n oldActions: number\n): void {\n if (expiredPrompts > 0 || oldActions > 0) {\n logSecurityEvent('cleanup', source, 'Cleanup completed', {\n expiredPrompts,\n oldActions,\n });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAKA,SAAS,gBAAgB,YAAY,cAAc,qBAAqB;AACxE,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAEhC,MAAM,UAAU,KAAK,QAAQ,GAAG,gBAAgB,MAAM;AACtD,MAAM,eAAe,KAAK,SAAS,cAAc;AACjD,MAAM,kBAAkB;AAyBxB,IAAI,WAAW;AAKR,SAAS,iBACd,MACA,QACA,SACA,SACA,IACM;AACN,MAAI;AACF,oBAAgB,OAAO;AAEvB,UAAM,QAAuB;AAAA,MAC3B,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,MAClC;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAI,WAAW,EAAE,QAAQ;AAAA,MACzB,GAAI,MAAM,EAAE,IAAI,OAAO,EAAE,EAAE;AAAA,IAC7B;AAEA,UAAM,UAAU,KAAK,UAAU,KAAK,IAAI;AACxC,mBAAe,cAAc,SAAS,EAAE,MAAM,IAAM,CAAC;AAErD;AAGA,QAAI,WAAW,iBAAiB;AAC9B,gBAAU;AAAA,IACZ;AAAA,EACF,QAAQ;AAAA,EAER;AACF;AAKA,SAAS,OAAO,IAAoB;AAClC,MAAI,CAAC,GAAI,QAAO;AAGhB,MAAI,OAAO,SAAS,OAAO,mBAAoB,QAAO;AAGtD,QAAM,QAAQ,GAAG,QAAQ,WAAW,EAAE,EAAE,MAAM,GAAG;AACjD,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO,GAAG,MAAM,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAAA,EAChC;AAGA,MAAI,GAAG,SAAS,GAAG,GAAG;AACpB,UAAM,WAAW,GAAG,MAAM,GAAG;AAC7B,QAAI,SAAS,UAAU,GAAG;AACxB,aAAO,SAAS,MAAM,GAAG,CAAC,EAAE,KAA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,IACA;AAAA,EACF;AACF;AAEO,SAAS,oBAAoB,QAAgB,IAAmB;AACrE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,gBACd,QACA,MACA,IACM;AACN;AAAA,IACE;AAAA,IACA;AAAA,IACA,2BAA2B,IAAI;AAAA,IAC/B;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,sBACd,QACA,aACA,IACM;AACN;AAAA,IACE;AAAA,IACA;AAAA,IACA,yBAAyB,WAAW;AAAA,IACpC;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,WACd,QACA,gBACA,YACM;AACN,MAAI,iBAAiB,KAAK,aAAa,GAAG;AACxC,qBAAiB,WAAW,QAAQ,qBAAqB;AAAA,MACvD;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -20,7 +20,19 @@ import {
|
|
|
20
20
|
cleanupOldActions
|
|
21
21
|
} from "./sms-action-runner.js";
|
|
22
22
|
import { writeFileSecure, ensureSecureDir } from "./secure-fs.js";
|
|
23
|
+
import {
|
|
24
|
+
logWebhookRequest,
|
|
25
|
+
logRateLimit,
|
|
26
|
+
logSignatureInvalid,
|
|
27
|
+
logBodyTooLarge,
|
|
28
|
+
logContentTypeInvalid,
|
|
29
|
+
logActionAllowed,
|
|
30
|
+
logActionBlocked,
|
|
31
|
+
logCleanup
|
|
32
|
+
} from "./security-logger.js";
|
|
23
33
|
const CLEANUP_INTERVAL_MS = 5 * 60 * 1e3;
|
|
34
|
+
const MAX_SMS_BODY_LENGTH = 1e3;
|
|
35
|
+
const MAX_PHONE_LENGTH = 20;
|
|
24
36
|
const MAX_BODY_SIZE = 50 * 1024;
|
|
25
37
|
const RATE_LIMIT_WINDOW_MS = 60 * 1e3;
|
|
26
38
|
const RATE_LIMIT_MAX_REQUESTS = 30;
|
|
@@ -83,6 +95,14 @@ function storeLatestResponse(promptId, response, action) {
|
|
|
83
95
|
}
|
|
84
96
|
function handleSMSWebhook(payload) {
|
|
85
97
|
const { From, Body } = payload;
|
|
98
|
+
if (Body && Body.length > MAX_SMS_BODY_LENGTH) {
|
|
99
|
+
console.log(`[sms-webhook] Body too long: ${Body.length} chars`);
|
|
100
|
+
return { response: "Message too long. Max 1000 characters." };
|
|
101
|
+
}
|
|
102
|
+
if (From && From.length > MAX_PHONE_LENGTH) {
|
|
103
|
+
console.log(`[sms-webhook] Invalid phone number length`);
|
|
104
|
+
return { response: "Invalid phone number." };
|
|
105
|
+
}
|
|
86
106
|
console.log(`[sms-webhook] Received from ${From}: ${Body}`);
|
|
87
107
|
const result = processIncomingResponse(From, Body);
|
|
88
108
|
if (!result.matched) {
|
|
@@ -106,6 +126,7 @@ function handleSMSWebhook(payload) {
|
|
|
106
126
|
result.response || Body
|
|
107
127
|
);
|
|
108
128
|
if (actionResult.success) {
|
|
129
|
+
logActionAllowed("sms-webhook", result.action);
|
|
109
130
|
console.log(
|
|
110
131
|
`[sms-webhook] Action completed: ${(actionResult.output || "").substring(0, 200)}`
|
|
111
132
|
);
|
|
@@ -115,6 +136,11 @@ function handleSMSWebhook(payload) {
|
|
|
115
136
|
queued: false
|
|
116
137
|
};
|
|
117
138
|
} else {
|
|
139
|
+
logActionBlocked(
|
|
140
|
+
"sms-webhook",
|
|
141
|
+
result.action,
|
|
142
|
+
actionResult.error || "unknown"
|
|
143
|
+
);
|
|
118
144
|
console.log(`[sms-webhook] Action failed: ${actionResult.error}`);
|
|
119
145
|
queueAction(
|
|
120
146
|
result.prompt?.id || "unknown",
|
|
@@ -185,7 +211,14 @@ function startWebhookServer(port = 3456) {
|
|
|
185
211
|
}
|
|
186
212
|
if ((url.pathname === "/sms" || url.pathname === "/sms/incoming" || url.pathname === "/webhook") && req.method === "POST") {
|
|
187
213
|
const clientIp = req.socket.remoteAddress || "unknown";
|
|
214
|
+
logWebhookRequest(
|
|
215
|
+
"sms-webhook",
|
|
216
|
+
req.method || "POST",
|
|
217
|
+
url.pathname || "/sms",
|
|
218
|
+
clientIp
|
|
219
|
+
);
|
|
188
220
|
if (!checkRateLimit(clientIp)) {
|
|
221
|
+
logRateLimit("sms-webhook", clientIp);
|
|
189
222
|
res.writeHead(429, {
|
|
190
223
|
"Content-Type": "text/xml",
|
|
191
224
|
"Retry-After": "60"
|
|
@@ -195,6 +228,7 @@ function startWebhookServer(port = 3456) {
|
|
|
195
228
|
}
|
|
196
229
|
const contentType = req.headers["content-type"] || "";
|
|
197
230
|
if (!contentType.includes("application/x-www-form-urlencoded")) {
|
|
231
|
+
logContentTypeInvalid("sms-webhook", contentType, clientIp);
|
|
198
232
|
res.writeHead(400, { "Content-Type": "text/xml" });
|
|
199
233
|
res.end(twimlResponse("Invalid content type"));
|
|
200
234
|
return;
|
|
@@ -205,6 +239,7 @@ function startWebhookServer(port = 3456) {
|
|
|
205
239
|
body += chunk;
|
|
206
240
|
if (body.length > MAX_BODY_SIZE) {
|
|
207
241
|
bodyTooLarge = true;
|
|
242
|
+
logBodyTooLarge("sms-webhook", body.length, clientIp);
|
|
208
243
|
req.destroy();
|
|
209
244
|
}
|
|
210
245
|
});
|
|
@@ -225,6 +260,7 @@ function startWebhookServer(port = 3456) {
|
|
|
225
260
|
payload,
|
|
226
261
|
twilioSignature
|
|
227
262
|
)) {
|
|
263
|
+
logSignatureInvalid("sms-webhook", clientIp);
|
|
228
264
|
console.error("[sms-webhook] Invalid Twilio signature");
|
|
229
265
|
res.writeHead(401, { "Content-Type": "text/xml" });
|
|
230
266
|
res.end(twimlResponse("Unauthorized"));
|
|
@@ -299,6 +335,7 @@ function startWebhookServer(port = 3456) {
|
|
|
299
335
|
const expiredPrompts = cleanupExpiredPrompts();
|
|
300
336
|
const oldActions = cleanupOldActions();
|
|
301
337
|
if (expiredPrompts > 0 || oldActions > 0) {
|
|
338
|
+
logCleanup("sms-webhook", expiredPrompts, oldActions);
|
|
302
339
|
console.log(
|
|
303
340
|
`[sms-webhook] Cleanup: ${expiredPrompts} expired prompts, ${oldActions} old actions`
|
|
304
341
|
);
|
|
@@ -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';\n\n// Cleanup interval (5 minutes)\nconst CLEANUP_INTERVAL_MS = 5 * 60 * 1000;\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 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 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 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 // Rate limiting\n const clientIp = req.socket.remoteAddress || 'unknown';\n if (!checkRateLimit(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 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 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 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 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"],
|
|
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;
|
|
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"],
|
|
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,GA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AAS,iBAAiB,IAAI,IAAI;AACxC,MAAI,KAAK,UAAU;AACnB,MAAI,KAAK,cAAc,OAAO,QAAQ,CAAC;AACzC;AAGA,IAAI,QAAQ,KAAK,CAAC,GAAG,SAAS,gBAAgB,GAAG;AAC/C,QAAM,OAAO,SAAS,QAAQ,IAAI,kBAAkB,KAAK,QAAQ,EAAE;AACnE,qBAAmB,IAAI;AACzB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackmemoryai/stackmemory",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.21",
|
|
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",
|