Skip to content

Commit 1f440b5

Browse files
author
StackMemory Bot (CLI)
committed
fix(skills): resolve SQLite pragma conflict in skills CLI + fix hook installer
- Wrap pragma calls in frame-database initSchema() with try/catch to handle re-initialization on same connection gracefully - Fix STACKMEMORY_AUTO_HOOKS=true to install hooks instead of skipping - Convert on-task-complete template to CJS for Node compatibility
1 parent f5350ce commit 1f440b5

5 files changed

Lines changed: 33 additions & 21 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"@types/blessed": "^0.1.27",
110110
"@types/inquirer": "^9.0.9",
111111
"@types/pg": "^8.16.0",
112-
"better-sqlite3": "^9.2.2",
112+
"better-sqlite3": "^9.6.0",
113113
"chalk": "^5.3.0",
114114
"cli-table3": "^0.6.5",
115115
"commander": "^11.1.0",

scripts/install-claude-hooks-auto.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ const distDir = join(__dirname, '..', 'dist');
3535
* Returns true if user consents, false otherwise
3636
*/
3737
async function askForConsent() {
38-
// Skip prompt if:
39-
// 1. Not a TTY (CI/CD, piped input)
40-
// 2. STACKMEMORY_AUTO_HOOKS=true is set
41-
// 3. Running in CI environment
42-
if (
43-
!process.stdin.isTTY ||
44-
process.env.STACKMEMORY_AUTO_HOOKS === 'true' ||
45-
process.env.CI === 'true'
46-
) {
47-
// In non-interactive mode, skip hook installation silently
38+
// Auto-install if STACKMEMORY_AUTO_HOOKS=true (no prompt needed)
39+
if (process.env.STACKMEMORY_AUTO_HOOKS === 'true') {
40+
console.log(
41+
'STACKMEMORY_AUTO_HOOKS=true — installing hooks automatically.'
42+
);
43+
return true;
44+
}
45+
46+
// Skip prompt if not interactive (CI/CD, piped input)
47+
if (!process.stdin.isTTY || process.env.CI === 'true') {
4848
console.log(
4949
'StackMemory installed. Run "stackmemory setup-mcp" to configure Claude Code integration.'
5050
);

src/core/context/frame-database.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,24 @@ export class FrameDatabase {
8080
*/
8181
initSchema(): void {
8282
try {
83-
// Enable WAL mode for better concurrency
84-
this.db.pragma('journal_mode = WAL');
85-
this.db.pragma('synchronous = NORMAL');
86-
// Enforce referential integrity
87-
this.db.pragma('foreign_keys = ON');
83+
// Pragmas may fail if another component already opened this database
84+
// and left an implicit transaction (e.g. SQLiteAdapter.connect()).
85+
// Wrap each in try/catch so schema creation still proceeds.
86+
try {
87+
this.db.pragma('journal_mode = WAL');
88+
} catch {
89+
// WAL mode likely already set by adapter
90+
}
91+
try {
92+
this.db.pragma('synchronous = NORMAL');
93+
} catch {
94+
// Safety level cannot change inside a transaction — skip
95+
}
96+
try {
97+
this.db.pragma('foreign_keys = ON');
98+
} catch {
99+
// Foreign keys likely already enabled
100+
}
88101

89102
// Create frames table
90103
this.db.exec(`

templates/claude-hooks/on-task-complete.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* 3. Logs to ~/.stackmemory/logs/hook-errors.log on failure (non-blocking)
1111
*/
1212

13-
import fs from 'fs';
14-
import path from 'path';
13+
const fs = require('fs');
14+
const path = require('path');
1515

1616
async function onTaskComplete() {
1717
try {
@@ -20,14 +20,13 @@ async function onTaskComplete() {
2020
// Sync Linear if STA task
2121
if (input.task && input.task.includes('STA-')) {
2222
try {
23-
const smBin = path.join(process.env.HOME || '', '.stackmemory', 'bin');
2423
const syncScript = path.join(
2524
process.cwd(),
2625
'scripts',
2726
'sync-linear-graphql.js'
2827
);
2928
if (fs.existsSync(syncScript)) {
30-
const { execSync } = await import('child_process');
29+
const { execSync } = require('child_process');
3130
execSync(`node "${syncScript}"`, {
3231
stdio: 'ignore',
3332
timeout: 10000,

0 commit comments

Comments
 (0)