@stackmemoryai/stackmemory 0.8.0 → 0.8.1
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/README.md +39 -1
- package/dist/src/cli/claude-sm.js +69 -372
- package/dist/src/cli/claude-sm.js.map +2 -2
- package/dist/src/cli/codex-sm.js +28 -0
- package/dist/src/cli/codex-sm.js.map +2 -2
- package/dist/src/cli/commands/onboard.js +22 -6
- package/dist/src/cli/commands/onboard.js.map +2 -2
- package/dist/src/cli/commands/setup.js +1 -2
- package/dist/src/cli/commands/setup.js.map +2 -2
- package/dist/src/cli/index.js +1 -71
- package/dist/src/cli/index.js.map +3 -3
- package/dist/src/cli/opencode-sm.js +28 -0
- package/dist/src/cli/opencode-sm.js.map +2 -2
- package/dist/src/core/config/feature-flags.js +1 -13
- package/dist/src/core/config/feature-flags.js.map +2 -2
- package/dist/src/features/sweep/pty-wrapper.js +11 -1
- package/dist/src/features/sweep/pty-wrapper.js.map +2 -2
- package/dist/src/hooks/index.js +0 -3
- package/dist/src/hooks/index.js.map +2 -2
- package/dist/src/hooks/schemas.js +0 -117
- package/dist/src/hooks/schemas.js.map +2 -2
- package/dist/src/hooks/session-summary.js.map +1 -1
- package/package.json +2 -2
- package/scripts/smoke-init-db.sh +77 -0
- package/scripts/test-pre-publish-quick.sh +26 -34
- package/scripts/install-notify-hook.sh +0 -84
- package/scripts/setup-notify-webhook.sh +0 -103
- package/templates/claude-hooks/notify-review-hook.js +0 -360
- package/templates/claude-hooks/sms-response-handler.js +0 -174
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/core/config/feature-flags.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Feature Flags Configuration\n * Controls which external integrations are enabled\n *\n * Set STACKMEMORY_LOCAL=true to run without any external services\n */\n\nexport interface FeatureFlags {\n // Core features (always available)\n core: true;\n\n // External integrations (can be disabled)\n linear: boolean;\n
|
|
5
|
-
"mappings": ";;;;
|
|
4
|
+
"sourcesContent": ["/**\n * Feature Flags Configuration\n * Controls which external integrations are enabled\n *\n * Set STACKMEMORY_LOCAL=true to run without any external services\n */\n\nexport interface FeatureFlags {\n // Core features (always available)\n core: true;\n\n // External integrations (can be disabled)\n linear: boolean;\n chromadb: boolean;\n aiSummaries: boolean;\n skills: boolean;\n ralph: boolean;\n}\n\n/**\n * Check if running in local-only mode\n * When true, all external service integrations are disabled\n */\nexport function isLocalOnly(): boolean {\n return (\n process.env['STACKMEMORY_LOCAL'] === 'true' ||\n process.env['STACKMEMORY_LOCAL'] === '1' ||\n process.env['LOCAL_ONLY'] === 'true'\n );\n}\n\n/**\n * Check if a specific feature is enabled\n */\nexport function isFeatureEnabled(feature: keyof FeatureFlags): boolean {\n if (feature === 'core') return true;\n\n // In local-only mode, external integrations are disabled\n if (isLocalOnly()) return false;\n\n // Check feature-specific env vars\n switch (feature) {\n case 'linear':\n return (\n process.env['STACKMEMORY_LINEAR'] !== 'false' &&\n (!!process.env['LINEAR_API_KEY'] || !!process.env['LINEAR_OAUTH_TOKEN'])\n );\n case 'chromadb':\n return process.env['STACKMEMORY_CHROMADB'] === 'true';\n case 'aiSummaries':\n return (\n process.env['STACKMEMORY_AI'] !== 'false' &&\n (!!process.env['ANTHROPIC_API_KEY'] || !!process.env['OPENAI_API_KEY'])\n );\n case 'skills':\n // Skills enabled explicitly or when AI summaries available\n return (\n process.env['STACKMEMORY_SKILLS'] === 'true' ||\n process.env['STACKMEMORY_SKILLS'] === '1'\n );\n case 'ralph':\n // Ralph enabled by default in development (unless explicitly disabled)\n // For npm package users, must be explicitly enabled\n return process.env['STACKMEMORY_RALPH'] !== 'false';\n default:\n return false;\n }\n}\n\n/**\n * Get all feature flags\n */\nexport function getFeatureFlags(): FeatureFlags {\n return {\n core: true,\n linear: isFeatureEnabled('linear'),\n chromadb: isFeatureEnabled('chromadb'),\n aiSummaries: isFeatureEnabled('aiSummaries'),\n skills: isFeatureEnabled('skills'),\n ralph: isFeatureEnabled('ralph'),\n };\n}\n\n/**\n * Log feature flags status (for debugging)\n */\nexport function logFeatureStatus(): void {\n const flags = getFeatureFlags();\n const local = isLocalOnly();\n\n console.log(\n `StackMemory Mode: ${local ? 'LOCAL (no external services)' : 'FULL'}`\n );\n if (!local) {\n console.log(\n ` Linear: ${flags.linear ? 'enabled' : 'disabled (no API key)'}`\n );\n console.log(` ChromaDB: ${flags.chromadb ? 'enabled' : 'disabled'}`);\n console.log(\n ` AI Summaries: ${flags.aiSummaries ? 'enabled' : 'disabled (no API key)'}`\n );\n console.log(\n ` Skills: ${flags.skills ? 'enabled' : 'disabled (set STACKMEMORY_SKILLS=true)'}`\n );\n console.log(\n ` Ralph: ${flags.ralph ? 'enabled' : 'disabled (set STACKMEMORY_RALPH=true)'}`\n );\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;AAuBO,SAAS,cAAuB;AACrC,SACE,QAAQ,IAAI,mBAAmB,MAAM,UACrC,QAAQ,IAAI,mBAAmB,MAAM,OACrC,QAAQ,IAAI,YAAY,MAAM;AAElC;AAKO,SAAS,iBAAiB,SAAsC;AACrE,MAAI,YAAY,OAAQ,QAAO;AAG/B,MAAI,YAAY,EAAG,QAAO;AAG1B,UAAQ,SAAS;AAAA,IACf,KAAK;AACH,aACE,QAAQ,IAAI,oBAAoB,MAAM,YACrC,CAAC,CAAC,QAAQ,IAAI,gBAAgB,KAAK,CAAC,CAAC,QAAQ,IAAI,oBAAoB;AAAA,IAE1E,KAAK;AACH,aAAO,QAAQ,IAAI,sBAAsB,MAAM;AAAA,IACjD,KAAK;AACH,aACE,QAAQ,IAAI,gBAAgB,MAAM,YACjC,CAAC,CAAC,QAAQ,IAAI,mBAAmB,KAAK,CAAC,CAAC,QAAQ,IAAI,gBAAgB;AAAA,IAEzE,KAAK;AAEH,aACE,QAAQ,IAAI,oBAAoB,MAAM,UACtC,QAAQ,IAAI,oBAAoB,MAAM;AAAA,IAE1C,KAAK;AAGH,aAAO,QAAQ,IAAI,mBAAmB,MAAM;AAAA,IAC9C;AACE,aAAO;AAAA,EACX;AACF;AAKO,SAAS,kBAAgC;AAC9C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,iBAAiB,QAAQ;AAAA,IACjC,UAAU,iBAAiB,UAAU;AAAA,IACrC,aAAa,iBAAiB,aAAa;AAAA,IAC3C,QAAQ,iBAAiB,QAAQ;AAAA,IACjC,OAAO,iBAAiB,OAAO;AAAA,EACjC;AACF;AAKO,SAAS,mBAAyB;AACvC,QAAM,QAAQ,gBAAgB;AAC9B,QAAM,QAAQ,YAAY;AAE1B,UAAQ;AAAA,IACN,qBAAqB,QAAQ,iCAAiC,MAAM;AAAA,EACtE;AACA,MAAI,CAAC,OAAO;AACV,YAAQ;AAAA,MACN,aAAa,MAAM,SAAS,YAAY,uBAAuB;AAAA,IACjE;AACA,YAAQ,IAAI,eAAe,MAAM,WAAW,YAAY,UAAU,EAAE;AACpE,YAAQ;AAAA,MACN,mBAAmB,MAAM,cAAc,YAAY,uBAAuB;AAAA,IAC5E;AACA,YAAQ;AAAA,MACN,aAAa,MAAM,SAAS,YAAY,wCAAwC;AAAA,IAClF;AACA,YAAQ;AAAA,MACN,YAAY,MAAM,QAAQ,YAAY,uCAAuC;AAAA,IAC/E;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,7 +29,8 @@ class PtyWrapper {
|
|
|
29
29
|
this.config = {
|
|
30
30
|
claudeBin: config.claudeBin || this.findClaude(),
|
|
31
31
|
claudeArgs: config.claudeArgs || [],
|
|
32
|
-
stateFile: config.stateFile || getSweepPath("sweep-state.json")
|
|
32
|
+
stateFile: config.stateFile || getSweepPath("sweep-state.json"),
|
|
33
|
+
initialInput: config.initialInput || ""
|
|
33
34
|
};
|
|
34
35
|
this.stateWatcher = new SweepStateWatcher(this.config.stateFile);
|
|
35
36
|
this.statusBar = new StatusBar();
|
|
@@ -69,10 +70,19 @@ class PtyWrapper {
|
|
|
69
70
|
process.stdin.setRawMode(true);
|
|
70
71
|
}
|
|
71
72
|
process.stdin.resume();
|
|
73
|
+
let inputInjected = false;
|
|
74
|
+
const initialInput = this.config.initialInput;
|
|
75
|
+
const ptyRef = this.ptyProcess;
|
|
72
76
|
this.ptyProcess.onData((data) => {
|
|
73
77
|
if (data.includes(ALT_SCREEN_ENTER)) {
|
|
74
78
|
this.inAltScreen = true;
|
|
75
79
|
this.statusBar.hide();
|
|
80
|
+
if (!inputInjected && initialInput && ptyRef) {
|
|
81
|
+
inputInjected = true;
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
ptyRef.write("\x1B[200~" + initialInput + "\x1B[201~");
|
|
84
|
+
}, 800);
|
|
85
|
+
}
|
|
76
86
|
}
|
|
77
87
|
if (data.includes(ALT_SCREEN_EXIT)) {
|
|
78
88
|
this.inAltScreen = false;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/features/sweep/pty-wrapper.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Sweep PTY Wrapper\n *\n * Wraps Claude Code in a pseudo-terminal to add a Sweep prediction\n * status bar at the bottom of the terminal. Predictions from the\n * PostToolUse hook are displayed via the status bar. Tab to accept,\n * Esc to dismiss.\n */\n\nimport { join } from 'path';\nimport { writeFileSync, existsSync, mkdirSync } from 'fs';\nimport { execSync } from 'child_process';\nimport { SweepStateWatcher, type PredictionEvent } from './state-watcher.js';\nimport { StatusBar } from './status-bar.js';\nimport { TabInterceptor } from './tab-interceptor.js';\n\nconst HOME = process.env['HOME'] || '/tmp';\n\nfunction getSweepDir(): string {\n return process.env['SWEEP_STATE_DIR'] || join(HOME, '.stackmemory');\n}\n\nfunction getSweepPath(filename: string): string {\n return join(getSweepDir(), filename);\n}\n\n// Alt screen buffer detection\nconst ALT_SCREEN_ENTER = '\\x1b[?1049h';\nconst ALT_SCREEN_EXIT = '\\x1b[?1049l';\n\nexport interface PtyWrapperConfig {\n claudeBin?: string;\n claudeArgs?: string[];\n stateFile?: string;\n}\n\n// Minimal interface for node-pty process to avoid compile-time dep\ninterface PtyProcess {\n write(data: string): void;\n resize(cols: number, rows: number): void;\n onData(cb: (data: string) => void): void;\n onExit(cb: (e: { exitCode: number }) => void): void;\n kill(): void;\n}\n\nexport class PtyWrapper {\n private config: Required<PtyWrapperConfig>;\n private stateWatcher: SweepStateWatcher;\n private statusBar: StatusBar;\n private tabInterceptor: TabInterceptor;\n private currentPrediction: PredictionEvent | null = null;\n private inAltScreen = false;\n private ptyProcess: PtyProcess | null = null;\n\n constructor(config: PtyWrapperConfig = {}) {\n this.config = {\n claudeBin: config.claudeBin || this.findClaude(),\n claudeArgs: config.claudeArgs || [],\n stateFile: config.stateFile || getSweepPath('sweep-state.json'),\n };\n\n this.stateWatcher = new SweepStateWatcher(this.config.stateFile);\n this.statusBar = new StatusBar();\n this.tabInterceptor = new TabInterceptor({\n onAccept: () => this.acceptPrediction(),\n onDismiss: () => this.dismissPrediction(),\n onPassthrough: (data) => this.ptyProcess?.write(data.toString('utf-8')),\n });\n }\n\n async start(): Promise<void> {\n // Ensure the sweep state directory exists\n const sweepDir = getSweepDir();\n if (!existsSync(sweepDir)) {\n mkdirSync(sweepDir, { recursive: true });\n }\n\n // Dynamic import for optional dependency\n let pty: typeof import('node-pty');\n try {\n pty = await import('node-pty');\n } catch {\n throw new Error(\n 'node-pty is required for the PTY wrapper.\\n' +\n 'Install with: npm install node-pty'\n );\n }\n\n const cols = process.stdout.columns || 80;\n const rows = process.stdout.rows || 24;\n\n // Filter undefined values from env\n const env: Record<string, string> = {};\n for (const [k, v] of Object.entries(process.env)) {\n if (v !== undefined) env[k] = v;\n }\n\n // Spawn Claude Code in a PTY with 1 row reserved for status bar\n this.ptyProcess = pty.spawn(this.config.claudeBin, this.config.claudeArgs, {\n name: process.env['TERM'] || 'xterm-256color',\n cols,\n rows: rows - 1,\n cwd: process.cwd(),\n env,\n }) as PtyProcess;\n\n // Set raw mode on stdin\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(true);\n }\n process.stdin.resume();\n\n // PTY stdout -> parent stdout (transparent passthrough)\n this.ptyProcess.onData((data: string) => {\n // Detect alt screen buffer transitions\n if (data.includes(ALT_SCREEN_ENTER)) {\n this.inAltScreen = true;\n this.statusBar.hide();\n }\n if (data.includes(ALT_SCREEN_EXIT)) {\n this.inAltScreen = false;\n }\n\n process.stdout.write(data);\n });\n\n // Parent stdin -> tab interceptor -> PTY\n process.stdin.on('data', (data: Buffer) => {\n this.tabInterceptor.process(data);\n });\n\n // State watcher -> status bar\n this.stateWatcher.on('loading', () => {\n if (!this.inAltScreen) {\n this.statusBar.showLoading();\n }\n });\n\n this.stateWatcher.on('prediction', (event: PredictionEvent) => {\n this.currentPrediction = event;\n this.tabInterceptor.setPredictionActive(true);\n if (!this.inAltScreen) {\n this.statusBar.show(\n event.prediction,\n event.file_path,\n event.latency_ms\n );\n }\n });\n\n this.stateWatcher.start();\n\n // Handle terminal resize\n process.stdout.on('resize', () => {\n const newCols = process.stdout.columns || 80;\n const newRows = process.stdout.rows || 24;\n this.ptyProcess?.resize(newCols, newRows - 1);\n this.statusBar.resize(newRows, newCols);\n });\n\n // Handle PTY exit\n this.ptyProcess.onExit(({ exitCode }) => {\n this.cleanup();\n process.exit(exitCode);\n });\n\n // Handle signals\n const onSignal = () => {\n this.cleanup();\n process.exit(0);\n };\n process.on('SIGINT', onSignal);\n process.on('SIGTERM', onSignal);\n }\n\n private acceptPrediction(): void {\n if (!this.currentPrediction || !this.ptyProcess) return;\n\n // Write prediction to pending file for Claude to read\n const dir = getSweepDir();\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n const pendingFile = getSweepPath('sweep-pending.json');\n writeFileSync(\n pendingFile,\n JSON.stringify(\n {\n file_path: this.currentPrediction.file_path,\n predicted_content: this.currentPrediction.prediction,\n timestamp: Date.now(),\n },\n null,\n 2\n )\n );\n\n // Inject acceptance prompt into PTY stdin.\n // SAFETY: pendingFile is derived from env or a constant path, not\n // arbitrary user input. The prompt is written to Claude Code's input,\n // which interprets it as a user message, not as a shell command.\n const prompt = `Apply the Sweep prediction from ${pendingFile}\\n`;\n this.ptyProcess.write(prompt);\n\n this.dismissPrediction();\n }\n\n private dismissPrediction(): void {\n this.currentPrediction = null;\n this.tabInterceptor.setPredictionActive(false);\n this.statusBar.hide();\n }\n\n private cleanup(): void {\n this.stateWatcher.stop();\n this.statusBar.hide();\n\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(false);\n }\n process.stdin.pause();\n }\n\n private findClaude(): string {\n // Check PATH first via which\n try {\n const resolved = execSync('which claude', { encoding: 'utf-8' }).trim();\n if (resolved) return resolved;\n } catch {\n // Not on PATH\n }\n\n // Check known locations\n const candidates = [\n join(HOME, '.bun', 'bin', 'claude'),\n '/usr/local/bin/claude',\n '/opt/homebrew/bin/claude',\n ];\n\n for (const c of candidates) {\n if (existsSync(c)) return c;\n }\n\n return 'claude';\n }\n}\n\n/**\n * Launch the PTY wrapper\n */\nexport async function launchWrapper(config?: PtyWrapperConfig): Promise<void> {\n const wrapper = new PtyWrapper(config);\n await wrapper.start();\n}\n"],
|
|
5
|
-
"mappings": ";;;;AASA,SAAS,YAAY;AACrB,SAAS,eAAe,YAAY,iBAAiB;AACrD,SAAS,gBAAgB;AACzB,SAAS,yBAA+C;AACxD,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAE/B,MAAM,OAAO,QAAQ,IAAI,MAAM,KAAK;AAEpC,SAAS,cAAsB;AAC7B,SAAO,QAAQ,IAAI,iBAAiB,KAAK,KAAK,MAAM,cAAc;AACpE;AAEA,SAAS,aAAa,UAA0B;AAC9C,SAAO,KAAK,YAAY,GAAG,QAAQ;AACrC;AAGA,MAAM,mBAAmB;AACzB,MAAM,kBAAkB;
|
|
4
|
+
"sourcesContent": ["/**\n * Sweep PTY Wrapper\n *\n * Wraps Claude Code in a pseudo-terminal to add a Sweep prediction\n * status bar at the bottom of the terminal. Predictions from the\n * PostToolUse hook are displayed via the status bar. Tab to accept,\n * Esc to dismiss.\n */\n\nimport { join } from 'path';\nimport { writeFileSync, existsSync, mkdirSync } from 'fs';\nimport { execSync } from 'child_process';\nimport { SweepStateWatcher, type PredictionEvent } from './state-watcher.js';\nimport { StatusBar } from './status-bar.js';\nimport { TabInterceptor } from './tab-interceptor.js';\n\nconst HOME = process.env['HOME'] || '/tmp';\n\nfunction getSweepDir(): string {\n return process.env['SWEEP_STATE_DIR'] || join(HOME, '.stackmemory');\n}\n\nfunction getSweepPath(filename: string): string {\n return join(getSweepDir(), filename);\n}\n\n// Alt screen buffer detection\nconst ALT_SCREEN_ENTER = '\\x1b[?1049h';\nconst ALT_SCREEN_EXIT = '\\x1b[?1049l';\n\nexport interface PtyWrapperConfig {\n claudeBin?: string;\n claudeArgs?: string[];\n stateFile?: string;\n initialInput?: string;\n}\n\n// Minimal interface for node-pty process to avoid compile-time dep\ninterface PtyProcess {\n write(data: string): void;\n resize(cols: number, rows: number): void;\n onData(cb: (data: string) => void): void;\n onExit(cb: (e: { exitCode: number }) => void): void;\n kill(): void;\n}\n\nexport class PtyWrapper {\n private config: Required<PtyWrapperConfig>;\n private stateWatcher: SweepStateWatcher;\n private statusBar: StatusBar;\n private tabInterceptor: TabInterceptor;\n private currentPrediction: PredictionEvent | null = null;\n private inAltScreen = false;\n private ptyProcess: PtyProcess | null = null;\n\n constructor(config: PtyWrapperConfig = {}) {\n this.config = {\n claudeBin: config.claudeBin || this.findClaude(),\n claudeArgs: config.claudeArgs || [],\n stateFile: config.stateFile || getSweepPath('sweep-state.json'),\n initialInput: config.initialInput || '',\n };\n\n this.stateWatcher = new SweepStateWatcher(this.config.stateFile);\n this.statusBar = new StatusBar();\n this.tabInterceptor = new TabInterceptor({\n onAccept: () => this.acceptPrediction(),\n onDismiss: () => this.dismissPrediction(),\n onPassthrough: (data) => this.ptyProcess?.write(data.toString('utf-8')),\n });\n }\n\n async start(): Promise<void> {\n // Ensure the sweep state directory exists\n const sweepDir = getSweepDir();\n if (!existsSync(sweepDir)) {\n mkdirSync(sweepDir, { recursive: true });\n }\n\n // Dynamic import for optional dependency\n let pty: typeof import('node-pty');\n try {\n pty = await import('node-pty');\n } catch {\n throw new Error(\n 'node-pty is required for the PTY wrapper.\\n' +\n 'Install with: npm install node-pty'\n );\n }\n\n const cols = process.stdout.columns || 80;\n const rows = process.stdout.rows || 24;\n\n // Filter undefined values from env\n const env: Record<string, string> = {};\n for (const [k, v] of Object.entries(process.env)) {\n if (v !== undefined) env[k] = v;\n }\n\n // Spawn Claude Code in a PTY with 1 row reserved for status bar\n this.ptyProcess = pty.spawn(this.config.claudeBin, this.config.claudeArgs, {\n name: process.env['TERM'] || 'xterm-256color',\n cols,\n rows: rows - 1,\n cwd: process.cwd(),\n env,\n }) as PtyProcess;\n\n // Set raw mode on stdin\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(true);\n }\n process.stdin.resume();\n\n // PTY stdout -> parent stdout (transparent passthrough)\n let inputInjected = false;\n const initialInput = this.config.initialInput;\n const ptyRef = this.ptyProcess;\n\n this.ptyProcess.onData((data: string) => {\n // Detect alt screen buffer transitions\n if (data.includes(ALT_SCREEN_ENTER)) {\n this.inAltScreen = true;\n this.statusBar.hide();\n\n // Inject initial input as bracketed paste after Claude UI enters alt screen\n if (!inputInjected && initialInput && ptyRef) {\n inputInjected = true;\n setTimeout(() => {\n // Bracketed paste mode: text appears in input area without auto-sending\n ptyRef.write('\\x1b[200~' + initialInput + '\\x1b[201~');\n }, 800);\n }\n }\n if (data.includes(ALT_SCREEN_EXIT)) {\n this.inAltScreen = false;\n }\n\n process.stdout.write(data);\n });\n\n // Parent stdin -> tab interceptor -> PTY\n process.stdin.on('data', (data: Buffer) => {\n this.tabInterceptor.process(data);\n });\n\n // State watcher -> status bar\n this.stateWatcher.on('loading', () => {\n if (!this.inAltScreen) {\n this.statusBar.showLoading();\n }\n });\n\n this.stateWatcher.on('prediction', (event: PredictionEvent) => {\n this.currentPrediction = event;\n this.tabInterceptor.setPredictionActive(true);\n if (!this.inAltScreen) {\n this.statusBar.show(\n event.prediction,\n event.file_path,\n event.latency_ms\n );\n }\n });\n\n this.stateWatcher.start();\n\n // Handle terminal resize\n process.stdout.on('resize', () => {\n const newCols = process.stdout.columns || 80;\n const newRows = process.stdout.rows || 24;\n this.ptyProcess?.resize(newCols, newRows - 1);\n this.statusBar.resize(newRows, newCols);\n });\n\n // Handle PTY exit\n this.ptyProcess.onExit(({ exitCode }) => {\n this.cleanup();\n process.exit(exitCode);\n });\n\n // Handle signals\n const onSignal = () => {\n this.cleanup();\n process.exit(0);\n };\n process.on('SIGINT', onSignal);\n process.on('SIGTERM', onSignal);\n }\n\n private acceptPrediction(): void {\n if (!this.currentPrediction || !this.ptyProcess) return;\n\n // Write prediction to pending file for Claude to read\n const dir = getSweepDir();\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true });\n }\n const pendingFile = getSweepPath('sweep-pending.json');\n writeFileSync(\n pendingFile,\n JSON.stringify(\n {\n file_path: this.currentPrediction.file_path,\n predicted_content: this.currentPrediction.prediction,\n timestamp: Date.now(),\n },\n null,\n 2\n )\n );\n\n // Inject acceptance prompt into PTY stdin.\n // SAFETY: pendingFile is derived from env or a constant path, not\n // arbitrary user input. The prompt is written to Claude Code's input,\n // which interprets it as a user message, not as a shell command.\n const prompt = `Apply the Sweep prediction from ${pendingFile}\\n`;\n this.ptyProcess.write(prompt);\n\n this.dismissPrediction();\n }\n\n private dismissPrediction(): void {\n this.currentPrediction = null;\n this.tabInterceptor.setPredictionActive(false);\n this.statusBar.hide();\n }\n\n private cleanup(): void {\n this.stateWatcher.stop();\n this.statusBar.hide();\n\n if (process.stdin.isTTY) {\n process.stdin.setRawMode(false);\n }\n process.stdin.pause();\n }\n\n private findClaude(): string {\n // Check PATH first via which\n try {\n const resolved = execSync('which claude', { encoding: 'utf-8' }).trim();\n if (resolved) return resolved;\n } catch {\n // Not on PATH\n }\n\n // Check known locations\n const candidates = [\n join(HOME, '.bun', 'bin', 'claude'),\n '/usr/local/bin/claude',\n '/opt/homebrew/bin/claude',\n ];\n\n for (const c of candidates) {\n if (existsSync(c)) return c;\n }\n\n return 'claude';\n }\n}\n\n/**\n * Launch the PTY wrapper\n */\nexport async function launchWrapper(config?: PtyWrapperConfig): Promise<void> {\n const wrapper = new PtyWrapper(config);\n await wrapper.start();\n}\n"],
|
|
5
|
+
"mappings": ";;;;AASA,SAAS,YAAY;AACrB,SAAS,eAAe,YAAY,iBAAiB;AACrD,SAAS,gBAAgB;AACzB,SAAS,yBAA+C;AACxD,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAE/B,MAAM,OAAO,QAAQ,IAAI,MAAM,KAAK;AAEpC,SAAS,cAAsB;AAC7B,SAAO,QAAQ,IAAI,iBAAiB,KAAK,KAAK,MAAM,cAAc;AACpE;AAEA,SAAS,aAAa,UAA0B;AAC9C,SAAO,KAAK,YAAY,GAAG,QAAQ;AACrC;AAGA,MAAM,mBAAmB;AACzB,MAAM,kBAAkB;AAkBjB,MAAM,WAAW;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,oBAA4C;AAAA,EAC5C,cAAc;AAAA,EACd,aAAgC;AAAA,EAExC,YAAY,SAA2B,CAAC,GAAG;AACzC,SAAK,SAAS;AAAA,MACZ,WAAW,OAAO,aAAa,KAAK,WAAW;AAAA,MAC/C,YAAY,OAAO,cAAc,CAAC;AAAA,MAClC,WAAW,OAAO,aAAa,aAAa,kBAAkB;AAAA,MAC9D,cAAc,OAAO,gBAAgB;AAAA,IACvC;AAEA,SAAK,eAAe,IAAI,kBAAkB,KAAK,OAAO,SAAS;AAC/D,SAAK,YAAY,IAAI,UAAU;AAC/B,SAAK,iBAAiB,IAAI,eAAe;AAAA,MACvC,UAAU,MAAM,KAAK,iBAAiB;AAAA,MACtC,WAAW,MAAM,KAAK,kBAAkB;AAAA,MACxC,eAAe,CAAC,SA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
export * from "./daemon.js";
|
|
8
8
|
export * from "./auto-background.js";
|
|
9
|
-
export * from "./sms-notify.js";
|
|
10
|
-
export * from "./sms-webhook.js";
|
|
11
|
-
export * from "./sms-action-runner.js";
|
|
12
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * StackMemory Hooks Module\n * User-configurable hook system for automation and suggestions\n */\n\nexport * from './events.js';\nexport * from './config.js';\nexport * from './daemon.js';\nexport * from './auto-background.js';\
|
|
5
|
-
"mappings": ";;;;AAKA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;
|
|
4
|
+
"sourcesContent": ["/**\n * StackMemory Hooks Module\n * User-configurable hook system for automation and suggestions\n */\n\nexport * from './events.js';\nexport * from './config.js';\nexport * from './daemon.js';\nexport * from './auto-background.js';\n"],
|
|
5
|
+
"mappings": ";;;;AAKA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -4,63 +4,6 @@ const __filename = __fileURLToPath(import.meta.url);
|
|
|
4
4
|
const __dirname = __pathDirname(__filename);
|
|
5
5
|
import { z } from "zod";
|
|
6
6
|
import { logConfigInvalid } from "./security-logger.js";
|
|
7
|
-
const PromptOptionSchema = z.object({
|
|
8
|
-
key: z.string().max(10),
|
|
9
|
-
label: z.string().max(200),
|
|
10
|
-
action: z.string().max(500).optional()
|
|
11
|
-
});
|
|
12
|
-
const PendingPromptSchema = z.object({
|
|
13
|
-
id: z.string().max(32),
|
|
14
|
-
timestamp: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/)),
|
|
15
|
-
message: z.string().max(1e3),
|
|
16
|
-
options: z.array(PromptOptionSchema).max(10),
|
|
17
|
-
type: z.enum(["options", "yesno", "freeform"]),
|
|
18
|
-
callback: z.string().max(500).optional(),
|
|
19
|
-
expiresAt: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/))
|
|
20
|
-
});
|
|
21
|
-
const NotifyOnSchema = z.object({
|
|
22
|
-
taskComplete: z.boolean(),
|
|
23
|
-
reviewReady: z.boolean(),
|
|
24
|
-
error: z.boolean(),
|
|
25
|
-
custom: z.boolean(),
|
|
26
|
-
contextSync: z.boolean().optional().default(true)
|
|
27
|
-
});
|
|
28
|
-
const QuietHoursSchema = z.object({
|
|
29
|
-
enabled: z.boolean(),
|
|
30
|
-
start: z.string().regex(/^\d{2}:\d{2}$/),
|
|
31
|
-
end: z.string().regex(/^\d{2}:\d{2}$/)
|
|
32
|
-
});
|
|
33
|
-
const SMSConfigSchema = z.object({
|
|
34
|
-
enabled: z.boolean(),
|
|
35
|
-
channel: z.enum(["whatsapp", "sms"]),
|
|
36
|
-
accountSid: z.string().max(100).optional(),
|
|
37
|
-
authToken: z.string().max(100).optional(),
|
|
38
|
-
smsFromNumber: z.string().max(20).optional(),
|
|
39
|
-
smsToNumber: z.string().max(20).optional(),
|
|
40
|
-
whatsappFromNumber: z.string().max(30).optional(),
|
|
41
|
-
whatsappToNumber: z.string().max(30).optional(),
|
|
42
|
-
fromNumber: z.string().max(20).optional(),
|
|
43
|
-
toNumber: z.string().max(20).optional(),
|
|
44
|
-
webhookUrl: z.string().url().max(500).optional(),
|
|
45
|
-
notifyOn: NotifyOnSchema,
|
|
46
|
-
quietHours: QuietHoursSchema.optional(),
|
|
47
|
-
responseTimeout: z.number().int().min(30).max(3600),
|
|
48
|
-
pendingPrompts: z.array(PendingPromptSchema).max(100)
|
|
49
|
-
});
|
|
50
|
-
const PendingActionSchema = z.object({
|
|
51
|
-
id: z.string().max(32),
|
|
52
|
-
promptId: z.string().max(32),
|
|
53
|
-
response: z.string().max(1e3),
|
|
54
|
-
action: z.string().max(500),
|
|
55
|
-
timestamp: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/)),
|
|
56
|
-
status: z.enum(["pending", "running", "completed", "failed"]),
|
|
57
|
-
result: z.string().max(1e4).optional(),
|
|
58
|
-
error: z.string().max(1e3).optional()
|
|
59
|
-
});
|
|
60
|
-
const ActionQueueSchema = z.object({
|
|
61
|
-
actions: z.array(PendingActionSchema).max(1e3),
|
|
62
|
-
lastChecked: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/))
|
|
63
|
-
});
|
|
64
7
|
const AutoBackgroundConfigSchema = z.object({
|
|
65
8
|
enabled: z.boolean(),
|
|
66
9
|
timeoutMs: z.number().int().min(1e3).max(6e5),
|
|
@@ -68,53 +11,6 @@ const AutoBackgroundConfigSchema = z.object({
|
|
|
68
11
|
neverBackground: z.array(z.string().max(200)).max(100),
|
|
69
12
|
verbose: z.boolean().optional()
|
|
70
13
|
});
|
|
71
|
-
const SyncOptionsSchema = z.object({
|
|
72
|
-
autoSyncOnClose: z.boolean(),
|
|
73
|
-
minFrameDuration: z.number().int().min(0).max(3600),
|
|
74
|
-
// 0 to 1 hour
|
|
75
|
-
includeDecisions: z.boolean(),
|
|
76
|
-
includeFiles: z.boolean(),
|
|
77
|
-
includeTests: z.boolean(),
|
|
78
|
-
maxDigestLength: z.number().int().min(100).max(1e3)
|
|
79
|
-
// WhatsApp limit ~4096 chars
|
|
80
|
-
});
|
|
81
|
-
const ScheduleConfigSchema = z.object({
|
|
82
|
-
type: z.enum(["daily", "hourly", "interval"]),
|
|
83
|
-
time: z.string().regex(/^\d{2}:\d{2}$/).optional(),
|
|
84
|
-
// "HH:MM" for daily
|
|
85
|
-
intervalMinutes: z.number().int().min(5).max(1440).optional(),
|
|
86
|
-
// 5 min to 24 hours
|
|
87
|
-
includeInactive: z.boolean(),
|
|
88
|
-
// Include when no activity
|
|
89
|
-
quietHoursRespect: z.boolean()
|
|
90
|
-
// Respect quiet hours setting
|
|
91
|
-
});
|
|
92
|
-
const ScheduleSchema = z.object({
|
|
93
|
-
id: z.string().max(32),
|
|
94
|
-
config: ScheduleConfigSchema,
|
|
95
|
-
enabled: z.boolean(),
|
|
96
|
-
lastRun: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/)).optional(),
|
|
97
|
-
nextRun: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/)).optional(),
|
|
98
|
-
createdAt: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/))
|
|
99
|
-
});
|
|
100
|
-
const ScheduleStorageSchema = z.object({
|
|
101
|
-
schedules: z.array(ScheduleSchema).max(10),
|
|
102
|
-
lastChecked: z.string().datetime({ offset: true }).or(z.string().regex(/^\d{4}-\d{2}-\d{2}T/))
|
|
103
|
-
});
|
|
104
|
-
const WhatsAppCommandSchema = z.object({
|
|
105
|
-
name: z.string().max(50),
|
|
106
|
-
description: z.string().max(200),
|
|
107
|
-
enabled: z.boolean(),
|
|
108
|
-
action: z.string().max(500).optional(),
|
|
109
|
-
// Safe action to execute
|
|
110
|
-
requiresArg: z.boolean().optional(),
|
|
111
|
-
argPattern: z.string().max(100).optional()
|
|
112
|
-
// Regex pattern for arg validation
|
|
113
|
-
});
|
|
114
|
-
const WhatsAppCommandsConfigSchema = z.object({
|
|
115
|
-
enabled: z.boolean(),
|
|
116
|
-
commands: z.array(WhatsAppCommandSchema).max(50)
|
|
117
|
-
});
|
|
118
14
|
const ModelProviderSchema = z.enum([
|
|
119
15
|
"anthropic",
|
|
120
16
|
"qwen",
|
|
@@ -175,23 +71,10 @@ function parseConfigSafe(schema, data, defaultValue, configName) {
|
|
|
175
71
|
return defaultValue;
|
|
176
72
|
}
|
|
177
73
|
export {
|
|
178
|
-
ActionQueueSchema,
|
|
179
74
|
AutoBackgroundConfigSchema,
|
|
180
75
|
ModelConfigSchema,
|
|
181
76
|
ModelProviderSchema,
|
|
182
77
|
ModelRouterConfigSchema,
|
|
183
|
-
NotifyOnSchema,
|
|
184
|
-
PendingActionSchema,
|
|
185
|
-
PendingPromptSchema,
|
|
186
|
-
PromptOptionSchema,
|
|
187
|
-
QuietHoursSchema,
|
|
188
|
-
SMSConfigSchema,
|
|
189
|
-
ScheduleConfigSchema,
|
|
190
|
-
ScheduleSchema,
|
|
191
|
-
ScheduleStorageSchema,
|
|
192
|
-
SyncOptionsSchema,
|
|
193
|
-
WhatsAppCommandSchema,
|
|
194
|
-
WhatsAppCommandsConfigSchema,
|
|
195
78
|
parseConfigSafe
|
|
196
79
|
};
|
|
197
80
|
//# sourceMappingURL=schemas.js.map
|
|
@@ -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';\nimport { logConfigInvalid } from './security-logger.js';\n\n//
|
|
5
|
-
"mappings": ";;;;AAKA,SAAS,SAAS;AAClB,SAAS,wBAAwB;AAG1B,MAAM,
|
|
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// 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// Model Router schemas\nexport const ModelProviderSchema = z.enum([\n 'anthropic',\n 'qwen',\n 'openai',\n 'ollama',\n 'custom',\n]);\n\nexport const ModelConfigSchema = z.object({\n provider: ModelProviderSchema,\n model: z.string().max(100),\n baseUrl: z.string().url().max(500).optional(),\n apiKeyEnv: z.string().max(100),\n headers: z.record(z.string().max(500)).optional(),\n params: z.record(z.unknown()).optional(),\n});\n\nexport const ModelRouterConfigSchema = z.object({\n enabled: z.boolean(),\n defaultProvider: ModelProviderSchema,\n taskRouting: z\n .object({\n plan: ModelProviderSchema.optional(),\n think: ModelProviderSchema.optional(),\n code: ModelProviderSchema.optional(),\n review: ModelProviderSchema.optional(),\n })\n .optional()\n .default({}),\n fallback: z.object({\n enabled: z.boolean(),\n provider: ModelProviderSchema,\n onRateLimit: z.boolean(),\n onError: z.boolean(),\n onTimeout: z.boolean(),\n maxRetries: z.number().int().min(0).max(10),\n retryDelayMs: z.number().int().min(100).max(30000),\n }),\n providers: z\n .object({\n anthropic: ModelConfigSchema.optional(),\n qwen: ModelConfigSchema.optional(),\n openai: ModelConfigSchema.optional(),\n ollama: ModelConfigSchema.optional(),\n custom: ModelConfigSchema.optional(),\n })\n .optional()\n .default({}),\n thinkingMode: z.object({\n enabled: z.boolean(),\n budget: z.number().int().min(1000).max(100000).optional(),\n temperature: z.number().min(0).max(2).optional(),\n topP: z.number().min(0).max(1).optional(),\n }),\n});\n\n// Type exports\nexport type ModelRouterConfigValidated = z.infer<\n typeof ModelRouterConfigSchema\n>;\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,6BAA6B,EAAE,OAAO;AAAA,EACjD,SAAS,EAAE,QAAQ;AAAA,EACnB,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAI,EAAE,IAAI,GAAM;AAAA,EAChD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AE;AAAA,IAC1C,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,IAAI,GAAK;AAAA,EACnD,CAAC;AAAA,EACD,WAAW,EACR,OAAO;AAAA,IACN,WAAW,kBAAkB,SAAS;AAAA,IACtC,MAAM,kBAAkB,SAAS;AAAA,IACjC,QAAQ,kBAAkB,SAAS;AAAA,IACnC,QAAQ,kBAAkB,SAAS;AAAA,IACnC,QAAQ,kBAAkB,SAAS;AAAA,EACrC,CAAC,EACA,SAAS,EACT,QAAQ,CAAC,CAAC;AAAA,EACb,cAAc,EAAE,OAAO;AAAA,IACrB,SAAS,EAAE,QAAQ;AAAA,IACnB,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAI,EAAE,IAAI,GAAM,EAAE,SAAS;AAAA,IACxD,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA,IAC/C,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA,EAC1C,CAAC;AACH,CAAC;AAaM,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
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/session-summary.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Session Summary Generator\n * Generates intelligent suggestions for what to do next after a Claude session\n */\n\nimport { execSync } from 'child_process';\nimport { pickNextLinearTask, TaskSuggestion } from './linear-task-picker.js';\n\nexport interface SessionContext {\n instanceId: string;\n exitCode: number | null;\n sessionStartTime: number;\n worktreePath?: string;\n branch?: string;\n task?: string;\n}\n\nexport interface Suggestion {\n key: string;\n label: string;\n action: string;\n priority: number;\n}\n\nexport interface SessionSummary {\n duration: string;\n exitCode: number | null;\n branch: string;\n status: 'success' | 'error' | 'interrupted';\n suggestions: Suggestion[];\n linearTask?: TaskSuggestion;\n}\n\n/**\n * Format duration in human-readable form\n */\nfunction formatDuration(ms: number): string {\n const seconds = Math.floor(ms / 1000);\n const minutes = Math.floor(seconds / 60);\n const hours = Math.floor(minutes / 60);\n\n if (hours > 0) {\n return `${hours}h ${minutes % 60}min`;\n }\n if (minutes > 0) {\n return `${minutes}min`;\n }\n return `${seconds}s`;\n}\n\n/**\n * Get current git branch\n */\nfunction getCurrentBranch(): string {\n try {\n return execSync('git rev-parse --abbrev-ref HEAD', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n } catch {\n return 'unknown';\n }\n}\n\n/**\n * Check for uncommitted changes\n */\nfunction hasUncommittedChanges(): { changed: boolean; count: number } {\n try {\n const status = execSync('git status --porcelain', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n const lines = status.trim().split('\\n').filter(Boolean);\n return { changed: lines.length > 0, count: lines.length };\n } catch {\n return { changed: false, count: 0 };\n }\n}\n\n/**\n * Check if we're in a worktree\n */\nfunction isInWorktree(): boolean {\n try {\n execSync('git rev-parse --is-inside-work-tree', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n // Check if it's a worktree (not the main repo)\n const gitDir = execSync('git rev-parse --git-dir', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n return gitDir.includes('.git/worktrees/');\n } catch {\n return false;\n }\n}\n\n/**\n * Check if tests exist and might need running\n */\nfunction hasTestScript(): boolean {\n try {\n const packageJson = execSync('cat package.json', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n const pkg = JSON.parse(packageJson);\n return !!(pkg.scripts?.test || pkg.scripts?.['test:run']);\n } catch {\n return false;\n }\n}\n\n/**\n * Generate suggestions based on session context\n */\nasync function generateSuggestions(\n context: SessionContext\n): Promise<Suggestion[]> {\n const suggestions: Suggestion[] = [];\n let keyIndex = 1;\n\n const changes = hasUncommittedChanges();\n const inWorktree = isInWorktree();\n const hasTests = hasTestScript();\n\n // Error case - suggest reviewing logs\n if (context.exitCode !== 0 && context.exitCode !== null) {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Review error logs',\n action: 'cat ~/.claude/logs/claude-*.log | tail -50',\n priority: 100,\n });\n }\n\n // Uncommitted changes - suggest commit or PR\n if (changes.changed) {\n suggestions.push({\n key: String(keyIndex++),\n label: `Commit changes (${changes.count} files)`,\n action: 'git add -A && git commit',\n priority: 90,\n });\n\n // If on feature branch, suggest PR\n const branch = getCurrentBranch();\n if (branch !== 'main' && branch !== 'master' && branch !== 'unknown') {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Create PR',\n action: 'gh pr create --fill',\n priority: 80,\n });\n }\n }\n\n // If tests exist and changes were made, suggest running tests\n if (hasTests && changes.changed) {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Run tests',\n action: 'npm run test:run',\n priority: 85,\n });\n }\n\n // Worktree-specific suggestions\n if (inWorktree) {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Merge to main',\n action: 'cwm', // custom alias\n priority: 70,\n });\n }\n\n // Try to get next Linear task\n try {\n const linearTask = await pickNextLinearTask({ preferTestTasks: true });\n if (linearTask) {\n suggestions.push({\n key: String(keyIndex++),\n label: `Start: ${linearTask.identifier} - ${linearTask.title.substring(0, 40)}${linearTask.title.length > 40 ? '...' : ''}${linearTask.hasTestRequirements ? ' (has tests)' : ''}`,\n action: `stackmemory task start ${linearTask.id} --assign-me`,\n priority: 60,\n });\n }\n } catch {\n // Linear not available, skip\n }\n\n // Long session suggestion\n const durationMs = Date.now() - context.sessionStartTime;\n if (durationMs > 30 * 60 * 1000) {\n // > 30 minutes\n suggestions.push({\n key: String(keyIndex++),\n label: 'Take a break',\n action: 'echo \"Great work! Time for a coffee break.\"',\n priority: 10,\n });\n }\n\n // Sort by priority (highest first) and re-key\n suggestions.sort((a, b) => b.priority - a.priority);\n\n // Ensure minimum 2 options always\n if (suggestions.length < 2) {\n // Add default options if not enough suggestions\n if (suggestions.length === 0) {\n suggestions.push({\n key: '1',\n label: 'Start new Claude session',\n action: 'claude-sm',\n priority: 50,\n });\n }\n if (suggestions.length < 2) {\n suggestions.push({\n key: '2',\n label: 'View session logs',\n action: 'cat ~/.claude/logs/claude-*.log | tail -30',\n priority: 40,\n });\n }\n }\n\n suggestions.forEach((s, i) => {\n s.key = String(i + 1);\n });\n\n return suggestions;\n}\n\n/**\n * Generate full session summary\n */\nexport async function generateSessionSummary(\n context: SessionContext\n): Promise<SessionSummary> {\n const durationMs = Date.now() - context.sessionStartTime;\n const duration = formatDuration(durationMs);\n const branch = context.branch || getCurrentBranch();\n\n let status: 'success' | 'error' | 'interrupted' = 'success';\n if (context.exitCode !== 0 && context.exitCode !== null) {\n status = 'error';\n }\n\n const suggestions = await generateSuggestions(context);\n\n // Extract linear task if present\n let linearTask: TaskSuggestion | undefined;\n try {\n linearTask = await pickNextLinearTask({ preferTestTasks: true });\n } catch {\n // Linear not available\n }\n\n return {\n duration,\n exitCode: context.exitCode,\n branch,\n status,\n suggestions,\n linearTask,\n };\n}\n\n/**\n * Format session summary as
|
|
4
|
+
"sourcesContent": ["/**\n * Session Summary Generator\n * Generates intelligent suggestions for what to do next after a Claude session\n */\n\nimport { execSync } from 'child_process';\nimport { pickNextLinearTask, TaskSuggestion } from './linear-task-picker.js';\n\nexport interface SessionContext {\n instanceId: string;\n exitCode: number | null;\n sessionStartTime: number;\n worktreePath?: string;\n branch?: string;\n task?: string;\n}\n\nexport interface Suggestion {\n key: string;\n label: string;\n action: string;\n priority: number;\n}\n\nexport interface SessionSummary {\n duration: string;\n exitCode: number | null;\n branch: string;\n status: 'success' | 'error' | 'interrupted';\n suggestions: Suggestion[];\n linearTask?: TaskSuggestion;\n}\n\n/**\n * Format duration in human-readable form\n */\nfunction formatDuration(ms: number): string {\n const seconds = Math.floor(ms / 1000);\n const minutes = Math.floor(seconds / 60);\n const hours = Math.floor(minutes / 60);\n\n if (hours > 0) {\n return `${hours}h ${minutes % 60}min`;\n }\n if (minutes > 0) {\n return `${minutes}min`;\n }\n return `${seconds}s`;\n}\n\n/**\n * Get current git branch\n */\nfunction getCurrentBranch(): string {\n try {\n return execSync('git rev-parse --abbrev-ref HEAD', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n } catch {\n return 'unknown';\n }\n}\n\n/**\n * Check for uncommitted changes\n */\nfunction hasUncommittedChanges(): { changed: boolean; count: number } {\n try {\n const status = execSync('git status --porcelain', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n const lines = status.trim().split('\\n').filter(Boolean);\n return { changed: lines.length > 0, count: lines.length };\n } catch {\n return { changed: false, count: 0 };\n }\n}\n\n/**\n * Check if we're in a worktree\n */\nfunction isInWorktree(): boolean {\n try {\n execSync('git rev-parse --is-inside-work-tree', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n // Check if it's a worktree (not the main repo)\n const gitDir = execSync('git rev-parse --git-dir', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n }).trim();\n return gitDir.includes('.git/worktrees/');\n } catch {\n return false;\n }\n}\n\n/**\n * Check if tests exist and might need running\n */\nfunction hasTestScript(): boolean {\n try {\n const packageJson = execSync('cat package.json', {\n encoding: 'utf8',\n stdio: ['pipe', 'pipe', 'pipe'],\n });\n const pkg = JSON.parse(packageJson);\n return !!(pkg.scripts?.test || pkg.scripts?.['test:run']);\n } catch {\n return false;\n }\n}\n\n/**\n * Generate suggestions based on session context\n */\nasync function generateSuggestions(\n context: SessionContext\n): Promise<Suggestion[]> {\n const suggestions: Suggestion[] = [];\n let keyIndex = 1;\n\n const changes = hasUncommittedChanges();\n const inWorktree = isInWorktree();\n const hasTests = hasTestScript();\n\n // Error case - suggest reviewing logs\n if (context.exitCode !== 0 && context.exitCode !== null) {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Review error logs',\n action: 'cat ~/.claude/logs/claude-*.log | tail -50',\n priority: 100,\n });\n }\n\n // Uncommitted changes - suggest commit or PR\n if (changes.changed) {\n suggestions.push({\n key: String(keyIndex++),\n label: `Commit changes (${changes.count} files)`,\n action: 'git add -A && git commit',\n priority: 90,\n });\n\n // If on feature branch, suggest PR\n const branch = getCurrentBranch();\n if (branch !== 'main' && branch !== 'master' && branch !== 'unknown') {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Create PR',\n action: 'gh pr create --fill',\n priority: 80,\n });\n }\n }\n\n // If tests exist and changes were made, suggest running tests\n if (hasTests && changes.changed) {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Run tests',\n action: 'npm run test:run',\n priority: 85,\n });\n }\n\n // Worktree-specific suggestions\n if (inWorktree) {\n suggestions.push({\n key: String(keyIndex++),\n label: 'Merge to main',\n action: 'cwm', // custom alias\n priority: 70,\n });\n }\n\n // Try to get next Linear task\n try {\n const linearTask = await pickNextLinearTask({ preferTestTasks: true });\n if (linearTask) {\n suggestions.push({\n key: String(keyIndex++),\n label: `Start: ${linearTask.identifier} - ${linearTask.title.substring(0, 40)}${linearTask.title.length > 40 ? '...' : ''}${linearTask.hasTestRequirements ? ' (has tests)' : ''}`,\n action: `stackmemory task start ${linearTask.id} --assign-me`,\n priority: 60,\n });\n }\n } catch {\n // Linear not available, skip\n }\n\n // Long session suggestion\n const durationMs = Date.now() - context.sessionStartTime;\n if (durationMs > 30 * 60 * 1000) {\n // > 30 minutes\n suggestions.push({\n key: String(keyIndex++),\n label: 'Take a break',\n action: 'echo \"Great work! Time for a coffee break.\"',\n priority: 10,\n });\n }\n\n // Sort by priority (highest first) and re-key\n suggestions.sort((a, b) => b.priority - a.priority);\n\n // Ensure minimum 2 options always\n if (suggestions.length < 2) {\n // Add default options if not enough suggestions\n if (suggestions.length === 0) {\n suggestions.push({\n key: '1',\n label: 'Start new Claude session',\n action: 'claude-sm',\n priority: 50,\n });\n }\n if (suggestions.length < 2) {\n suggestions.push({\n key: '2',\n label: 'View session logs',\n action: 'cat ~/.claude/logs/claude-*.log | tail -30',\n priority: 40,\n });\n }\n }\n\n suggestions.forEach((s, i) => {\n s.key = String(i + 1);\n });\n\n return suggestions;\n}\n\n/**\n * Generate full session summary\n */\nexport async function generateSessionSummary(\n context: SessionContext\n): Promise<SessionSummary> {\n const durationMs = Date.now() - context.sessionStartTime;\n const duration = formatDuration(durationMs);\n const branch = context.branch || getCurrentBranch();\n\n let status: 'success' | 'error' | 'interrupted' = 'success';\n if (context.exitCode !== 0 && context.exitCode !== null) {\n status = 'error';\n }\n\n const suggestions = await generateSuggestions(context);\n\n // Extract linear task if present\n let linearTask: TaskSuggestion | undefined;\n try {\n linearTask = await pickNextLinearTask({ preferTestTasks: true });\n } catch {\n // Linear not available\n }\n\n return {\n duration,\n exitCode: context.exitCode,\n branch,\n status,\n suggestions,\n linearTask,\n };\n}\n\n/**\n * Format session summary as a compact message\n */\nexport function formatSummaryMessage(\n summary: SessionSummary,\n sessionId?: string\n): string {\n const statusEmoji = summary.status === 'success' ? '' : '';\n const exitInfo =\n summary.exitCode !== null ? ` | Exit: ${summary.exitCode}` : '';\n const sessionInfo = sessionId ? ` | Session: ${sessionId}` : '';\n\n let message = `Claude session complete ${statusEmoji}\\n`;\n message += `Duration: ${summary.duration}${exitInfo}${sessionInfo}\\n`;\n message += `Branch: ${summary.branch}\\n`;\n\n // Add Claude Code session URL if session ID is available\n if (sessionId) {\n message += `View: https://claude.ai/chat/${sessionId}\\n`;\n }\n\n message += '\\n';\n\n if (summary.suggestions.length > 0) {\n message += `What to do next:\\n`;\n for (const s of summary.suggestions.slice(0, 4)) {\n message += `${s.key}. ${s.label}\\n`;\n }\n message += `\\nReply with number or custom action`;\n } else {\n message += `No pending actions. Nice work!`;\n }\n\n return message;\n}\n\n/**\n * Get action for a suggestion key\n */\nexport function getActionForKey(\n suggestions: Suggestion[],\n key: string\n): string | null {\n const suggestion = suggestions.find((s) => s.key === key);\n return suggestion?.action || null;\n}\n"],
|
|
5
5
|
"mappings": ";;;;AAKA,SAAS,gBAAgB;AACzB,SAAS,0BAA0C;AA8BnD,SAAS,eAAe,IAAoB;AAC1C,QAAM,UAAU,KAAK,MAAM,KAAK,GAAI;AACpC,QAAM,UAAU,KAAK,MAAM,UAAU,EAAE;AACvC,QAAM,QAAQ,KAAK,MAAM,UAAU,EAAE;AAErC,MAAI,QAAQ,GAAG;AACb,WAAO,GAAG,KAAK,KAAK,UAAU,EAAE;AAAA,EAClC;AACA,MAAI,UAAU,GAAG;AACf,WAAO,GAAG,OAAO;AAAA,EACnB;AACA,SAAO,GAAG,OAAO;AACnB;AAKA,SAAS,mBAA2B;AAClC,MAAI;AACF,WAAO,SAAS,mCAAmC;AAAA,MACjD,UAAU;AAAA,MACV,OAAO,CAAC,QAAQ,QAAQ,MAAM;AAAA,IAChC,CAAC,EAAE,KAAK;AAAA,EACV,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAKA,SAAS,wBAA6D;AACpE,MAAI;AACF,UAAM,SAAS,SAAS,0BAA0B;AAAA,MAChD,UAAU;AAAA,MACV,OAAO,CAAC,QAAQ,QAAQ,MAAM;AAAA,IAChC,CAAC;AACD,UAAM,QAAQ,OAAO,KAAK,EAAE,MAAM,IAAI,EAAE,OAAO,OAAO;AACtD,WAAO,EAAE,SAAS,MAAM,SAAS,GAAG,OAAO,MAAM,OAAO;AAAA,EAC1D,QAAQ;AACN,WAAO,EAAE,SAAS,OAAO,OAAO,EAAE;AAAA,EAC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ClC,eAAW;AAAA;AACX,eAAW,KAAK,QAAQ,YAAY,MAAM,GAAG,CAAC,GAAG;AAC/C,iBAAW,GAAG,EAAE,GAAG,KAAK,EAAE,KAAK;AAAA;AAAA,IACjC;AACA,eAAW;AAAA;AAAA,EACb,OAAO;AACL,eAAW;AAAA,EACb;AAEA,SAAO;AACT;AAKO,SAAS,gBACd,aACA,KACe;AACf,QAAM,aAAa,YAAY,KAAK,CAAC,MAAM,EAAE,QAAQ,GAAG;AACxD,SAAO,YAAY,UAAU;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackmemoryai/stackmemory",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "Project-scoped memory for AI coding tools. Durable context across sessions with MCP integration, frames, smart retrieval, Claude Code skills, and automatic hooks.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.0.0",
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"sync:setup": "./scripts/setup-background-sync.sh",
|
|
95
95
|
"prepare": "echo 'Prepare step completed'",
|
|
96
96
|
"verify:dist": "node scripts/verify-dist.cjs",
|
|
97
|
+
"test:smoke-db": "bash scripts/smoke-init-db.sh",
|
|
97
98
|
"rebuild:native": "npm rebuild better-sqlite3 || true",
|
|
98
99
|
"deps:reset": "rm -rf node_modules package-lock.json && npm ci"
|
|
99
100
|
},
|
|
@@ -123,7 +124,6 @@
|
|
|
123
124
|
"ignore": "^7.0.5",
|
|
124
125
|
"inquirer": "^9.3.8",
|
|
125
126
|
"msgpackr": "^1.10.1",
|
|
126
|
-
"ngrok": "^5.0.0-beta.2",
|
|
127
127
|
"node-pty": "^1.1.0",
|
|
128
128
|
"open": "^11.0.0",
|
|
129
129
|
"ora": "^9.0.0",
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
# Smoke test: verify wrappers auto-init StackMemory and create context.db
|
|
5
|
+
#
|
|
6
|
+
# Steps:
|
|
7
|
+
# - Create a fresh git repo
|
|
8
|
+
# - Prepend a PATH shim so "stackmemory" resolves to local dist CLI
|
|
9
|
+
# - Run each wrapper with flags to avoid external tool execution
|
|
10
|
+
# - Assert .stackmemory/context.db is created (DB enabled)
|
|
11
|
+
#
|
|
12
|
+
# Notes:
|
|
13
|
+
# - Requires that better-sqlite3 can load on this system.
|
|
14
|
+
# - Unsets env that disables DB in CLI (STACKMEMORY_TEST_SKIP_DB).
|
|
15
|
+
|
|
16
|
+
WS_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
17
|
+
DIST_CLI="$WS_ROOT/dist/src/cli/index.js"
|
|
18
|
+
if [[ ! -f "$DIST_CLI" ]]; then
|
|
19
|
+
echo "dist CLI not found at $DIST_CLI; run: npm run build" >&2
|
|
20
|
+
exit 1
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
TEST_ROOT="$WS_ROOT/tmp/smoke-db-$(date +%s)"
|
|
24
|
+
SM_BIN_DIR="$TEST_ROOT/bin"
|
|
25
|
+
mkdir -p "$SM_BIN_DIR" "$TEST_ROOT"
|
|
26
|
+
|
|
27
|
+
# PATH shim for stackmemory -> local dist CLI
|
|
28
|
+
cat > "$SM_BIN_DIR/stackmemory" <<EOS
|
|
29
|
+
#!/usr/bin/env bash
|
|
30
|
+
exec node "$DIST_CLI" "$@"
|
|
31
|
+
EOS
|
|
32
|
+
chmod +x "$SM_BIN_DIR/stackmemory"
|
|
33
|
+
|
|
34
|
+
# Fresh git repo
|
|
35
|
+
mkdir -p "$TEST_ROOT/repo"
|
|
36
|
+
cd "$TEST_ROOT/repo"
|
|
37
|
+
git init -q
|
|
38
|
+
echo "# Smoke Test Repo" > README.md
|
|
39
|
+
git add README.md
|
|
40
|
+
git -c user.email=test@example.com -c user.name=test commit -q -m "init"
|
|
41
|
+
|
|
42
|
+
# PATH and env (ensure DB path is taken)
|
|
43
|
+
export PATH="$SM_BIN_DIR:$PATH"
|
|
44
|
+
unset STACKMEMORY_TEST_SKIP_DB || true
|
|
45
|
+
unset VITEST || true
|
|
46
|
+
unset NODE_ENV || true
|
|
47
|
+
|
|
48
|
+
failures=0
|
|
49
|
+
|
|
50
|
+
run_case() {
|
|
51
|
+
local name="$1"; shift
|
|
52
|
+
local cmd=("$@")
|
|
53
|
+
rm -rf .stackmemory
|
|
54
|
+
set +e
|
|
55
|
+
( "${cmd[@]}" ) >/dev/null 2>&1
|
|
56
|
+
local rc=$?
|
|
57
|
+
set -e
|
|
58
|
+
if [[ -f .stackmemory/context.db ]]; then
|
|
59
|
+
echo "$name: DB_OK (rc=$rc)"
|
|
60
|
+
else
|
|
61
|
+
echo "$name: DB_MISSING (rc=$rc)"; failures=$((failures+1))
|
|
62
|
+
fi
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
# Run wrappers to trigger auto-init
|
|
66
|
+
run_case codex-sm "$WS_ROOT/bin/codex-sm" --no-context --no-trace --codex-bin /bin/false
|
|
67
|
+
run_case opencode-sm "$WS_ROOT/bin/opencode-sm" --no-context --no-trace --opencode-bin /bin/false
|
|
68
|
+
run_case claude-sm "$WS_ROOT/bin/claude-sm" --no-context --no-trace --claude-bin /bin/false
|
|
69
|
+
|
|
70
|
+
if [[ $failures -eq 0 ]]; then
|
|
71
|
+
echo "ALL_DB_OK"
|
|
72
|
+
exit 0
|
|
73
|
+
else
|
|
74
|
+
echo "FAILURES=$failures"
|
|
75
|
+
exit 1
|
|
76
|
+
fi
|
|
77
|
+
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
# Quick Pre-Publish Test Suite
|
|
3
3
|
# Essential tests that must pass before npm publish
|
|
4
|
+
#
|
|
5
|
+
# Called by prepublishOnly which already runs: npm run build && npm run verify:dist
|
|
6
|
+
# So this script skips the redundant build and focuses on tests + lint + git cleanliness.
|
|
4
7
|
|
|
5
8
|
set -e
|
|
6
9
|
|
|
@@ -22,19 +25,25 @@ echo " StackMemory Quick Pre-Publish Tests"
|
|
|
22
25
|
echo "============================================"
|
|
23
26
|
echo
|
|
24
27
|
|
|
25
|
-
# Essential build test
|
|
26
|
-
log_info "Testing build..."
|
|
27
28
|
cd "$PROJECT_ROOT"
|
|
28
|
-
npm run build > /dev/null 2>&1 || log_error "Build failed"
|
|
29
|
-
log_success "Build succeeds"
|
|
30
29
|
|
|
31
|
-
#
|
|
32
|
-
log_info "
|
|
33
|
-
|
|
30
|
+
# Git status check — run FIRST before any command can dirty the tree
|
|
31
|
+
log_info "Checking git status..."
|
|
32
|
+
if git diff --quiet && git diff --cached --quiet; then
|
|
33
|
+
log_success "Git working directory is clean"
|
|
34
|
+
else
|
|
35
|
+
echo
|
|
36
|
+
git diff --name-only
|
|
37
|
+
git diff --cached --name-only
|
|
38
|
+
log_error "Git working directory has uncommitted changes (see above)"
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# CLI artifact exists (build already ran in prepublishOnly)
|
|
42
|
+
log_info "Checking CLI artifact..."
|
|
34
43
|
if [ -f "dist/src/cli/index.js" ]; then
|
|
35
|
-
log_success "CLI
|
|
44
|
+
log_success "CLI artifact exists"
|
|
36
45
|
else
|
|
37
|
-
log_error "CLI
|
|
46
|
+
log_error "CLI artifact missing — build may have failed"
|
|
38
47
|
fi
|
|
39
48
|
|
|
40
49
|
# Package structure test
|
|
@@ -42,36 +51,19 @@ log_info "Testing package structure..."
|
|
|
42
51
|
npm pack --dry-run > /dev/null 2>&1 || log_error "npm pack failed"
|
|
43
52
|
log_success "Package structure valid"
|
|
44
53
|
|
|
45
|
-
#
|
|
46
|
-
log_info "
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
log_error "Shell integration binaries missing"
|
|
51
|
-
fi
|
|
52
|
-
|
|
53
|
-
# Quick binary functionality test
|
|
54
|
-
log_info "Testing binary functionality..."
|
|
55
|
-
# Skip shell integration test due to database initialization requirements
|
|
56
|
-
if [ -x "$HOME/.stackmemory/bin/stackmemory" ]; then
|
|
57
|
-
log_success "Shell integration works"
|
|
58
|
-
else
|
|
59
|
-
log_error "Shell integration binary failed"
|
|
54
|
+
# Core tests + search benchmark (100-frame smoke)
|
|
55
|
+
log_info "Running tests..."
|
|
56
|
+
npx vitest run --reporter=dot --bail=3 2>&1 | tail -5
|
|
57
|
+
if [ ${PIPESTATUS[0]} -ne 0 ]; then
|
|
58
|
+
log_error "Tests failed"
|
|
60
59
|
fi
|
|
60
|
+
log_success "Tests pass (including search benchmark)"
|
|
61
61
|
|
|
62
62
|
# Lint check
|
|
63
63
|
log_info "Testing lint..."
|
|
64
64
|
npm run lint > /dev/null 2>&1 || log_error "Lint failed"
|
|
65
65
|
log_success "Lint passes"
|
|
66
66
|
|
|
67
|
-
# Git status check
|
|
68
|
-
log_info "Checking git status..."
|
|
69
|
-
if git diff --quiet && git diff --cached --quiet; then
|
|
70
|
-
log_success "Git working directory is clean"
|
|
71
|
-
else
|
|
72
|
-
log_error "Git working directory has uncommitted changes"
|
|
73
|
-
fi
|
|
74
|
-
|
|
75
67
|
echo
|
|
76
|
-
echo -e "${GREEN}✅ All
|
|
77
|
-
echo -e "${GREEN}Ready for npm publish.${NC}"
|
|
68
|
+
echo -e "${GREEN}✅ All pre-publish checks passed!${NC}"
|
|
69
|
+
echo -e "${GREEN}Ready for npm publish.${NC}"
|