@stackmemoryai/stackmemory 0.3.0 → 0.3.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/dist/cli/codex-sm.js +48 -19
- package/dist/cli/codex-sm.js.map +2 -2
- package/dist/cli/index.js +1 -1
- package/dist/cli/index.js.map +1 -1
- package/package.json +4 -1
package/dist/cli/codex-sm.js
CHANGED
|
@@ -49,7 +49,9 @@ class CodexSM {
|
|
|
49
49
|
}
|
|
50
50
|
getCurrentBranch() {
|
|
51
51
|
try {
|
|
52
|
-
return execSync("git rev-parse --abbrev-ref HEAD", {
|
|
52
|
+
return execSync("git rev-parse --abbrev-ref HEAD", {
|
|
53
|
+
encoding: "utf8"
|
|
54
|
+
}).trim();
|
|
53
55
|
} catch {
|
|
54
56
|
return "main";
|
|
55
57
|
}
|
|
@@ -68,7 +70,10 @@ class CodexSM {
|
|
|
68
70
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").substring(0, 19);
|
|
69
71
|
const branch = this.config.branch || `codex-${this.config.task || "work"}-${timestamp}-${this.config.instanceId}`;
|
|
70
72
|
const repoName = path.basename(process.cwd());
|
|
71
|
-
const worktreePath = path.join(
|
|
73
|
+
const worktreePath = path.join(
|
|
74
|
+
path.dirname(process.cwd()),
|
|
75
|
+
`${repoName}--${branch}`
|
|
76
|
+
);
|
|
72
77
|
try {
|
|
73
78
|
const cmd = `git worktree add -b "${branch}" "${worktreePath}"`;
|
|
74
79
|
execSync(cmd, { stdio: "inherit" });
|
|
@@ -87,7 +92,8 @@ class CodexSM {
|
|
|
87
92
|
const envFiles = [".env", ".env.local", ".mise.toml", ".tool-versions"];
|
|
88
93
|
for (const file of envFiles) {
|
|
89
94
|
const srcPath = path.join(process.cwd(), file);
|
|
90
|
-
if (fs.existsSync(srcPath))
|
|
95
|
+
if (fs.existsSync(srcPath))
|
|
96
|
+
fs.copyFileSync(srcPath, path.join(worktreePath, file));
|
|
91
97
|
}
|
|
92
98
|
return worktreePath;
|
|
93
99
|
} catch (err) {
|
|
@@ -121,9 +127,13 @@ class CodexSM {
|
|
|
121
127
|
const contexts = JSON.parse(output);
|
|
122
128
|
if (Array.isArray(contexts) && contexts.length > 0) {
|
|
123
129
|
console.log(chalk.gray("Recent context loaded:"));
|
|
124
|
-
contexts.forEach(
|
|
125
|
-
|
|
126
|
-
|
|
130
|
+
contexts.forEach(
|
|
131
|
+
(ctx) => {
|
|
132
|
+
console.log(
|
|
133
|
+
chalk.gray(` - ${ctx.message} (${ctx.metadata?.timestamp})`)
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
);
|
|
127
137
|
}
|
|
128
138
|
} catch {
|
|
129
139
|
}
|
|
@@ -131,7 +141,9 @@ class CodexSM {
|
|
|
131
141
|
suggestWorktreeMode() {
|
|
132
142
|
if (this.hasUncommittedChanges()) {
|
|
133
143
|
console.log(chalk.yellow("\u26A0\uFE0F Uncommitted changes detected"));
|
|
134
|
-
console.log(
|
|
144
|
+
console.log(
|
|
145
|
+
chalk.gray(" Consider using --worktree to work in isolation")
|
|
146
|
+
);
|
|
135
147
|
}
|
|
136
148
|
}
|
|
137
149
|
async run(args) {
|
|
@@ -190,12 +202,16 @@ class CodexSM {
|
|
|
190
202
|
process.env.TRACE_RESULTS = "false";
|
|
191
203
|
}
|
|
192
204
|
initializeTracing();
|
|
193
|
-
trace.command(
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
205
|
+
trace.command(
|
|
206
|
+
"codex-sm",
|
|
207
|
+
{
|
|
208
|
+
instanceId: this.config.instanceId,
|
|
209
|
+
worktree: this.config.useWorktree,
|
|
210
|
+
task: this.config.task
|
|
211
|
+
},
|
|
212
|
+
async () => {
|
|
213
|
+
}
|
|
214
|
+
);
|
|
199
215
|
}
|
|
200
216
|
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"));
|
|
201
217
|
console.log(chalk.blue("\u2551 Codex + StackMemory + Worktree \u2551"));
|
|
@@ -220,7 +236,8 @@ class CodexSM {
|
|
|
220
236
|
}
|
|
221
237
|
this.loadContext();
|
|
222
238
|
process.env.CODEX_INSTANCE_ID = this.config.instanceId;
|
|
223
|
-
if (this.config.worktreePath)
|
|
239
|
+
if (this.config.worktreePath)
|
|
240
|
+
process.env.CODEX_WORKTREE_PATH = this.config.worktreePath;
|
|
224
241
|
console.log(chalk.gray(`\u{1F916} Instance ID: ${this.config.instanceId}`));
|
|
225
242
|
console.log(chalk.gray(`\u{1F4C1} Working in: ${process.cwd()}`));
|
|
226
243
|
console.log();
|
|
@@ -240,13 +257,21 @@ class CodexSM {
|
|
|
240
257
|
return null;
|
|
241
258
|
})();
|
|
242
259
|
if (!codexBin) {
|
|
243
|
-
console.error(
|
|
260
|
+
console.error(
|
|
261
|
+
chalk.red("\u274C Codex CLI not found in PATH (codex or codex-cli).")
|
|
262
|
+
);
|
|
244
263
|
process.exit(1);
|
|
245
264
|
return;
|
|
246
265
|
}
|
|
247
|
-
const child = spawn(codexBin, codexArgs, {
|
|
266
|
+
const child = spawn(codexBin, codexArgs, {
|
|
267
|
+
stdio: "inherit",
|
|
268
|
+
env: process.env
|
|
269
|
+
});
|
|
248
270
|
child.on("exit", (code) => {
|
|
249
|
-
this.saveContext("Codex session ended", {
|
|
271
|
+
this.saveContext("Codex session ended", {
|
|
272
|
+
action: "session_end",
|
|
273
|
+
exitCode: code
|
|
274
|
+
});
|
|
250
275
|
if (this.config.tracingEnabled) {
|
|
251
276
|
const summary = trace.getExecutionSummary();
|
|
252
277
|
console.log();
|
|
@@ -263,11 +288,15 @@ class CodexSM {
|
|
|
263
288
|
process.exit(code || 0);
|
|
264
289
|
});
|
|
265
290
|
process.on("SIGINT", () => {
|
|
266
|
-
this.saveContext("Codex session interrupted", {
|
|
291
|
+
this.saveContext("Codex session interrupted", {
|
|
292
|
+
action: "session_interrupt"
|
|
293
|
+
});
|
|
267
294
|
child.kill("SIGINT");
|
|
268
295
|
});
|
|
269
296
|
process.on("SIGTERM", () => {
|
|
270
|
-
this.saveContext("Codex session terminated", {
|
|
297
|
+
this.saveContext("Codex session terminated", {
|
|
298
|
+
action: "session_terminate"
|
|
299
|
+
});
|
|
271
300
|
child.kill("SIGTERM");
|
|
272
301
|
});
|
|
273
302
|
}
|
package/dist/cli/codex-sm.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/cli/codex-sm.ts"],
|
|
4
|
-
"sourcesContent": ["#!/usr/bin/env node\n\n/**\n * codex-sm: Codex wrapper with StackMemory and worktree integration\n * Automatically manages context persistence, optional worktree isolation, and tracing\n */\n\nimport { spawn, execSync } 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\ninterface CodexConfig {\n instanceId: string;\n worktreePath?: string;\n useWorktree: boolean;\n contextEnabled: boolean;\n branch?: string;\n task?: string;\n tracingEnabled: boolean;\n verboseTracing: boolean;\n}\n\nclass CodexSM {\n private config: CodexConfig;\n private stackmemoryPath: string;\n\n constructor() {\n this.config = {\n instanceId: this.generateInstanceId(),\n useWorktree: false,\n contextEnabled: true,\n tracingEnabled: true,\n verboseTracing: false,\n };\n\n this.stackmemoryPath = this.findStackMemory();\n }\n\n private generateInstanceId(): string {\n return uuidv4().substring(0, 8);\n }\n\n private findStackMemory(): string {\n const possiblePaths = [\n path.join(os.homedir(), '.stackmemory', 'bin', 'stackmemory'),\n '/usr/local/bin/stackmemory',\n '/opt/homebrew/bin/stackmemory',\n 'stackmemory',\n ];\n for (const smPath of possiblePaths) {\n try {\n execSync(`which ${smPath}`, { stdio: 'ignore' });\n return smPath;\n } catch {\n // continue\n }\n }\n return 'stackmemory';\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', { encoding: 'utf8' }).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 setupWorktree(): string | null {\n if (!this.config.useWorktree || !this.isGitRepo()) return null;\n\n console.log(chalk.blue('\uD83C\uDF33 Setting up isolated worktree...'));\n\n const timestamp = new Date().toISOString().replace(/[:.]/g, '-').substring(0, 19);\n const branch =\n this.config.branch || `codex-${this.config.task || 'work'}-${timestamp}-${this.config.instanceId}`;\n const repoName = path.basename(process.cwd());\n const worktreePath = path.join(path.dirname(process.cwd()), `${repoName}--${branch}`);\n\n try {\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 const configPath = path.join(worktreePath, '.codex-instance.json');\n const configData = {\n instanceId: this.config.instanceId,\n worktreePath,\n branch,\n task: this.config.task,\n created: new Date().toISOString(),\n parentRepo: process.cwd(),\n };\n fs.writeFileSync(configPath, JSON.stringify(configData, null, 2));\n\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)) fs.copyFileSync(srcPath, path.join(worktreePath, file));\n }\n\n return worktreePath;\n } catch (err) {\n console.error(chalk.red('\u274C Failed to create worktree:'), err);\n return null;\n }\n }\n\n private saveContext(message: string, metadata: Record<string, unknown> = {}): void {\n if (!this.config.contextEnabled) return;\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 const cmd = `${this.stackmemoryPath} context save --json '${JSON.stringify(contextData)}'`;\n execSync(cmd, { stdio: 'ignore' });\n } catch {\n // ignore\n }\n }\n\n private loadContext(): void {\n if (!this.config.contextEnabled) return;\n try {\n console.log(chalk.blue('\uD83D\uDCDA Loading previous context...'));\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 if (Array.isArray(contexts) && contexts.length > 0) {\n console.log(chalk.gray('Recent context loaded:'));\n contexts.forEach((ctx: { message: string; metadata?: { timestamp?: string } }) => {\n console.log(chalk.gray(` - ${ctx.message} (${ctx.metadata?.timestamp})`));\n });\n }\n } catch {\n // ignore\n }\n }\n\n private suggestWorktreeMode(): void {\n if (this.hasUncommittedChanges()) {\n console.log(chalk.yellow('\u26A0\uFE0F Uncommitted changes detected'));\n console.log(chalk.gray(' Consider using --worktree to work in isolation'));\n }\n }\n\n public async run(args: string[]): Promise<void> {\n const codexArgs: string[] = [];\n let i = 0;\n while (i < args.length) {\n const arg = args[i];\n switch (arg) {\n case '--worktree':\n case '-w':\n this.config.useWorktree = true;\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 '--auto':\n case '-a':\n if (this.isGitRepo()) {\n this.config.useWorktree = this.hasUncommittedChanges();\n }\n break;\n default:\n codexArgs.push(arg);\n }\n i++;\n }\n\n if (this.config.tracingEnabled) {\n process.env.DEBUG_TRACE = 'true';\n process.env.STACKMEMORY_DEBUG = 'true';\n process.env.TRACE_OUTPUT = 'file';\n process.env.TRACE_MASK_SENSITIVE = 'true';\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 initializeTracing();\n trace.command('codex-sm', {\n instanceId: this.config.instanceId,\n worktree: this.config.useWorktree,\n task: this.config.task,\n }, async () => {});\n }\n\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 Codex + 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 if (this.isGitRepo()) {\n const branch = this.getCurrentBranch();\n console.log(chalk.gray(`\uD83D\uDCCD Current branch: ${branch}`));\n if (!this.config.useWorktree) this.suggestWorktreeMode();\n }\n\n if (this.config.useWorktree) {\n const worktreePath = this.setupWorktree();\n if (worktreePath) {\n this.config.worktreePath = worktreePath;\n process.chdir(worktreePath);\n this.saveContext('Created worktree for Codex instance', {\n action: 'worktree_created',\n path: worktreePath,\n branch: this.config.branch,\n });\n }\n }\n\n this.loadContext();\n\n process.env.CODEX_INSTANCE_ID = this.config.instanceId;\n if (this.config.worktreePath) process.env.CODEX_WORKTREE_PATH = this.config.worktreePath;\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 console.log();\n console.log(chalk.gray('Starting Codex...'));\n console.log(chalk.gray('\u2500'.repeat(42)));\n\n const codexBin = (() => {\n try { execSync('which codex', { stdio: 'ignore' }); return 'codex'; } catch {}\n try { execSync('which codex-cli', { stdio: 'ignore' }); return 'codex-cli'; } catch {}\n return null;\n })();\n\n if (!codexBin) {\n console.error(chalk.red('\u274C Codex CLI not found in PATH (codex or codex-cli).'));\n process.exit(1);\n return;\n }\n\n const child = spawn(codexBin, codexArgs, { stdio: 'inherit', env: process.env });\n\n child.on('exit', (code) => {\n this.saveContext('Codex session ended', { action: 'session_end', exitCode: code });\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 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 }\n process.exit(code || 0);\n });\n\n process.on('SIGINT', () => {\n this.saveContext('Codex session interrupted', { action: 'session_interrupt' });\n child.kill('SIGINT');\n });\n\n process.on('SIGTERM', () => {\n this.saveContext('Codex session terminated', { action: 'session_terminate' });\n child.kill('SIGTERM');\n });\n }\n}\n\nprogram\n .name('codex-sm')\n .description('Codex with StackMemory context and optional worktree isolation')\n .version('1.0.0')\n .option('-w, --worktree', 'Create isolated worktree for this instance')\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('--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 codexSM = new CodexSM();\n const args = process.argv.slice(2);\n await codexSM.run(args);\n });\n\nif (require.main === module) {\n program.parse(process.argv);\n}\n\n"],
|
|
5
|
-
"mappings": ";AAOA,SAAS,OAAO,gBAAgB;AAChC,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,YAAY,QAAQ;AACpB,SAAS,eAAe;AACxB,SAAS,MAAM,cAAc;AAC7B,OAAO,WAAW;AAClB,SAAS,mBAAmB,aAAa;AAazC,MAAM,QAAQ;AAAA,EACJ;AAAA,EACA;AAAA,EAER,cAAc;AACZ,SAAK,SAAS;AAAA,MACZ,YAAY,KAAK,mBAAmB;AAAA,MACpC,aAAa;AAAA,MACb,gBAAgB;AAAA,MAChB,gBAAgB;AAAA,MAChB,gBAAgB;AAAA,IAClB;AAEA,SAAK,kBAAkB,KAAK,gBAAgB;AAAA,EAC9C;AAAA,EAEQ,qBAA6B;AACnC,WAAO,OAAO,EAAE,UAAU,GAAG,CAAC;AAAA,EAChC;AAAA,EAEQ,kBAA0B;AAChC,UAAM,gBAAgB;AAAA,MACpB,KAAK,KAAK,GAAG,QAAQ,GAAG,gBAAgB,OAAO,aAAa;AAAA,MAC5D;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,eAAW,UAAU,eAAe;AAClC,UAAI;AACF,iBAAS,SAAS,MAAM,IAAI,EAAE,OAAO,SAAS,CAAC;AAC/C,eAAO;AAAA,MACT,QAAQ;AAAA,MAER;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEQ,YAAqB;AAC3B,QAAI;AACF,eAAS,2BAA2B,EAAE,OAAO,SAAS,CAAC;AACvD,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEQ,mBAA2B;AACjC,QAAI;AACF,aAAO,SAAS,mCAAmC,
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env node\n\n/**\n * codex-sm: Codex wrapper with StackMemory and worktree integration\n * Automatically manages context persistence, optional worktree isolation, and tracing\n */\n\nimport { spawn, execSync } 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\ninterface CodexConfig {\n instanceId: string;\n worktreePath?: string;\n useWorktree: boolean;\n contextEnabled: boolean;\n branch?: string;\n task?: string;\n tracingEnabled: boolean;\n verboseTracing: boolean;\n}\n\nclass CodexSM {\n private config: CodexConfig;\n private stackmemoryPath: string;\n\n constructor() {\n this.config = {\n instanceId: this.generateInstanceId(),\n useWorktree: false,\n contextEnabled: true,\n tracingEnabled: true,\n verboseTracing: false,\n };\n\n this.stackmemoryPath = this.findStackMemory();\n }\n\n private generateInstanceId(): string {\n return uuidv4().substring(0, 8);\n }\n\n private findStackMemory(): string {\n const possiblePaths = [\n path.join(os.homedir(), '.stackmemory', 'bin', 'stackmemory'),\n '/usr/local/bin/stackmemory',\n '/opt/homebrew/bin/stackmemory',\n 'stackmemory',\n ];\n for (const smPath of possiblePaths) {\n try {\n execSync(`which ${smPath}`, { stdio: 'ignore' });\n return smPath;\n } catch {\n // continue\n }\n }\n return 'stackmemory';\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 setupWorktree(): string | null {\n if (!this.config.useWorktree || !this.isGitRepo()) return null;\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 `codex-${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 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 const configPath = path.join(worktreePath, '.codex-instance.json');\n const configData = {\n instanceId: this.config.instanceId,\n worktreePath,\n branch,\n task: this.config.task,\n created: new Date().toISOString(),\n parentRepo: process.cwd(),\n };\n fs.writeFileSync(configPath, JSON.stringify(configData, null, 2));\n\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 return worktreePath;\n } catch (err) {\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 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 const cmd = `${this.stackmemoryPath} context save --json '${JSON.stringify(contextData)}'`;\n execSync(cmd, { stdio: 'ignore' });\n } catch {\n // ignore\n }\n }\n\n private loadContext(): void {\n if (!this.config.contextEnabled) return;\n try {\n console.log(chalk.blue('\uD83D\uDCDA Loading previous context...'));\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 if (Array.isArray(contexts) && 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 // ignore\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\n public async run(args: string[]): Promise<void> {\n const codexArgs: string[] = [];\n let i = 0;\n while (i < args.length) {\n const arg = args[i];\n switch (arg) {\n case '--worktree':\n case '-w':\n this.config.useWorktree = true;\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 '--auto':\n case '-a':\n if (this.isGitRepo()) {\n this.config.useWorktree = this.hasUncommittedChanges();\n }\n break;\n default:\n codexArgs.push(arg);\n }\n i++;\n }\n\n if (this.config.tracingEnabled) {\n process.env.DEBUG_TRACE = 'true';\n process.env.STACKMEMORY_DEBUG = 'true';\n process.env.TRACE_OUTPUT = 'file';\n process.env.TRACE_MASK_SENSITIVE = 'true';\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 initializeTracing();\n trace.command(\n 'codex-sm',\n {\n instanceId: this.config.instanceId,\n worktree: this.config.useWorktree,\n task: this.config.task,\n },\n async () => {}\n );\n }\n\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 Codex + 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 if (this.isGitRepo()) {\n const branch = this.getCurrentBranch();\n console.log(chalk.gray(`\uD83D\uDCCD Current branch: ${branch}`));\n if (!this.config.useWorktree) this.suggestWorktreeMode();\n }\n\n if (this.config.useWorktree) {\n const worktreePath = this.setupWorktree();\n if (worktreePath) {\n this.config.worktreePath = worktreePath;\n process.chdir(worktreePath);\n this.saveContext('Created worktree for Codex instance', {\n action: 'worktree_created',\n path: worktreePath,\n branch: this.config.branch,\n });\n }\n }\n\n this.loadContext();\n\n process.env.CODEX_INSTANCE_ID = this.config.instanceId;\n if (this.config.worktreePath)\n process.env.CODEX_WORKTREE_PATH = this.config.worktreePath;\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 console.log();\n console.log(chalk.gray('Starting Codex...'));\n console.log(chalk.gray('\u2500'.repeat(42)));\n\n const codexBin = (() => {\n try {\n execSync('which codex', { stdio: 'ignore' });\n return 'codex';\n } catch {}\n try {\n execSync('which codex-cli', { stdio: 'ignore' });\n return 'codex-cli';\n } catch {}\n return null;\n })();\n\n if (!codexBin) {\n console.error(\n chalk.red('\u274C Codex CLI not found in PATH (codex or codex-cli).')\n );\n process.exit(1);\n return;\n }\n\n const child = spawn(codexBin, codexArgs, {\n stdio: 'inherit',\n env: process.env,\n });\n\n child.on('exit', (code) => {\n this.saveContext('Codex session ended', {\n action: 'session_end',\n exitCode: code,\n });\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 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 }\n process.exit(code || 0);\n });\n\n process.on('SIGINT', () => {\n this.saveContext('Codex session interrupted', {\n action: 'session_interrupt',\n });\n child.kill('SIGINT');\n });\n\n process.on('SIGTERM', () => {\n this.saveContext('Codex session terminated', {\n action: 'session_terminate',\n });\n child.kill('SIGTERM');\n });\n }\n}\n\nprogram\n .name('codex-sm')\n .description('Codex with StackMemory context and optional worktree isolation')\n .version('1.0.0')\n .option('-w, --worktree', 'Create isolated worktree for this instance')\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('--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 codexSM = new CodexSM();\n const args = process.argv.slice(2);\n await codexSM.run(args);\n });\n\nif (require.main === module) {\n program.parse(process.argv);\n}\n"],
|
|
5
|
+
"mappings": ";AAOA,SAAS,OAAO,gBAAgB;AAChC,YAAY,QAAQ;AACpB,YAAY,UAAU;AACtB,YAAY,QAAQ;AACpB,SAAS,eAAe;AACxB,SAAS,MAAM,cAAc;AAC7B,OAAO,WAAW;AAClB,SAAS,mBAAmB,aAAa;AAazC,MAAM,QAAQ;AAAA,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O,EACf,OAAO,kBAAkB,4CAA4C,EACrE,OAAO,cAAc,8CAA8C,EACnE,OAAO,uBAAuB,kCAAkC,EAChE,OAAO,qBAAqB,8BAA8B,EAC1D,OAAO,gBAAgB,yCAAyC,EAChE,OAAO,cAAc,4CAA4C,EACjE,OAAO,mBAAmB,gDAAgD,EAC1E,WAAW,cAAc,cAAc,EACvC,mBAAmB,IAAI,EACvB,OAAO,OAAO,aAAa;AAC1B,QAAM,UAAU,IAAI,QAAQ;AAC5B,QAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,QAAM,QAAQ,IAAI,IAAI;AACxB,CAAC;AAEH,IAAI,QAAQ,SAAS,QAAQ;AAC3B,UAAQ,MAAM,QAAQ,IAAI;AAC5B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cli/index.js
CHANGED
|
@@ -38,7 +38,7 @@ import { ProjectManager } from "../core/projects/project-manager.js";
|
|
|
38
38
|
import Database from "better-sqlite3";
|
|
39
39
|
import { join } from "path";
|
|
40
40
|
import { existsSync, mkdirSync } from "fs";
|
|
41
|
-
const VERSION = "0.
|
|
41
|
+
const VERSION = "0.3.1";
|
|
42
42
|
UpdateChecker.checkForUpdates(VERSION, true).catch(() => {
|
|
43
43
|
});
|
|
44
44
|
program.name("stackmemory").description("Lossless memory runtime for AI coding tools").version(VERSION);
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/cli/index.ts"],
|
|
4
|
-
"sourcesContent": ["#!/usr/bin/env node\n/**\n * StackMemory CLI\n * Command-line interface for StackMemory operations\n */\n\nimport { program } from 'commander';\nimport { logger } from '../core/monitoring/logger.js';\nimport { FrameManager } from '../core/context/frame-manager.js';\nimport { sessionManager, FrameQueryMode } from '../core/session/index.js';\nimport { PebblesTaskStore } from '../features/tasks/pebbles-task-store.js';\nimport {\n LinearAuthManager,\n LinearOAuthSetup,\n} from '../integrations/linear/auth.js';\nimport {\n LinearSyncEngine,\n DEFAULT_SYNC_CONFIG,\n} from '../integrations/linear/sync.js';\nimport {\n initializeAutoSync,\n getAutoSyncService,\n stopAutoSync,\n} from '../integrations/linear/auto-sync.js';\nimport { LinearConfigManager } from '../integrations/linear/config.js';\nimport { UpdateChecker } from '../core/utils/update-checker.js';\nimport { ProgressTracker } from '../core/monitoring/progress-tracker.js';\nimport { registerProjectCommands } from './commands/projects.js';\nimport { registerLinearCommands } from './commands/linear.js';\nimport { registerLinearTestCommand } from './commands/linear-test.js';\nimport { createSessionCommands } from './commands/session.js';\nimport { registerWorktreeCommands } from './commands/worktree.js';\nimport { registerOnboardingCommand } from './commands/onboard.js';\nimport { webhookCommand } from './commands/webhook.js';\nimport { createTaskCommands } from './commands/tasks.js';\nimport { createSearchCommand } from './commands/search.js';\nimport { createLogCommand } from './commands/log.js';\nimport { createContextCommands } from './commands/context.js';\nimport { createConfigCommand } from './commands/config.js';\nimport { createAgentCommand } from './commands/agent.js';\nimport { createHandoffCommand } from './commands/handoff.js';\nimport { ProjectManager } from '../core/projects/project-manager.js';\nimport Database from 'better-sqlite3';\nimport { join } from 'path';\nimport { existsSync, mkdirSync } from 'fs';\n\nconst VERSION = '0.2.7';\n\n// Check for updates on CLI startup\nUpdateChecker.checkForUpdates(VERSION, true).catch(() => {\n // Silently ignore errors\n});\n\nprogram\n .name('stackmemory')\n .description('Lossless memory runtime for AI coding tools')\n .version(VERSION);\n\nprogram\n .command('init')\n .description('Initialize StackMemory in current project')\n .action(async () => {\n try {\n const projectRoot = process.cwd();\n const dbDir = join(projectRoot, '.stackmemory');\n\n if (!existsSync(dbDir)) {\n mkdirSync(dbDir, { recursive: true });\n }\n\n const dbPath = join(dbDir, 'context.db');\n const db = new Database(dbPath);\n new FrameManager(db, 'cli-project');\n\n logger.info('StackMemory initialized successfully', { projectRoot });\n console.log('\u2705 StackMemory initialized in', projectRoot);\n\n db.close();\n } catch (error) {\n logger.error('Failed to initialize StackMemory', error as Error);\n console.error('\u274C Initialization failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nprogram\n .command('status')\n .description('Show current StackMemory status')\n .option('--all', 'Show all active frames across sessions')\n .option('--project', 'Show all active frames in current project')\n .option('--session <id>', 'Show frames for specific session')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n if (!existsSync(dbPath)) {\n console.log(\n '\u274C StackMemory not initialized. Run \"stackmemory init\" first.'\n );\n return;\n }\n\n // Check for updates and display if available\n await UpdateChecker.checkForUpdates(VERSION);\n\n // Initialize session manager\n await sessionManager.initialize();\n const session = await sessionManager.getOrCreateSession({\n projectPath: projectRoot,\n sessionId: options.session,\n });\n\n const db = new Database(dbPath);\n const frameManager = new FrameManager(db, session.projectId);\n\n // Set query mode based on options\n if (options.all) {\n frameManager.setQueryMode(FrameQueryMode.ALL_ACTIVE);\n } else if (options.project) {\n frameManager.setQueryMode(FrameQueryMode.PROJECT_ACTIVE);\n }\n\n const activeFrames = frameManager.getActiveFramePath();\n const stackDepth = frameManager.getStackDepth();\n\n // Always get total counts across all sessions\n const totalStats = db\n .prepare(\n `\n SELECT \n COUNT(*) as total_frames,\n SUM(CASE WHEN state = 'active' THEN 1 ELSE 0 END) as active_frames,\n SUM(CASE WHEN state = 'closed' THEN 1 ELSE 0 END) as closed_frames,\n COUNT(DISTINCT run_id) as total_sessions\n FROM frames\n WHERE project_id = ?\n `\n )\n .get(session.projectId) as any;\n\n const contextCount = db\n .prepare(\n `\n SELECT COUNT(*) as count FROM contexts\n `\n )\n .get() as any;\n\n const eventCount = db\n .prepare(\n `\n SELECT COUNT(*) as count FROM events\n `\n )\n .get() as any;\n\n console.log('\uD83D\uDCCA StackMemory Status:');\n console.log(\n ` Session: ${session.sessionId.slice(0, 8)} (${session.state}, ${Math.round((Date.now() - session.startedAt) / 1000 / 60)}min old)`\n );\n console.log(` Project: ${session.projectId}`);\n if (session.branch) {\n console.log(` Branch: ${session.branch}`);\n }\n\n // Show total database statistics\n console.log(`\\n Database Statistics:`);\n console.log(` Total contexts: ${contextCount.count}`);\n console.log(\n ` Total frames: ${totalStats.total_frames} (${totalStats.active_frames} active, ${totalStats.closed_frames} closed)`\n );\n console.log(` Total events: ${eventCount.count}`);\n console.log(` Total sessions: ${totalStats.total_sessions}`);\n\n // Show recent activity\n const recentFrames = db\n .prepare(\n `\n SELECT name, type, state, datetime(created_at, 'unixepoch') as created\n FROM frames\n WHERE project_id = ?\n ORDER BY created_at DESC\n LIMIT 3\n `\n )\n .all(session.projectId) as any[];\n\n if (recentFrames.length > 0) {\n console.log(`\\n Recent Activity:`);\n recentFrames.forEach((f: any) => {\n const stateIcon = f.state === 'active' ? '\uD83D\uDFE2' : '\u26AB';\n console.log(` ${stateIcon} ${f.name} [${f.type}] - ${f.created}`);\n });\n }\n\n console.log(`\\n Current Session:`);\n console.log(` Stack depth: ${stackDepth}`);\n console.log(` Active frames: ${activeFrames.length}`);\n\n if (activeFrames.length > 0) {\n activeFrames.forEach((frame, i) => {\n const indent = ' ' + ' '.repeat(frame.depth || i);\n const prefix = i === 0 ? '\u2514\u2500' : ' \u2514\u2500';\n console.log(`${indent}${prefix} ${frame.name} [${frame.type}]`);\n });\n }\n\n // Show other sessions if in default mode\n if (!options.all && !options.project) {\n const otherSessions = await sessionManager.listSessions({\n projectId: session.projectId,\n state: 'active',\n });\n\n const otherActive = otherSessions.filter(\n (s) => s.sessionId !== session.sessionId\n );\n if (otherActive.length > 0) {\n console.log(`\\n Other Active Sessions (same project):`);\n otherActive.forEach((s) => {\n const age = Math.round(\n (Date.now() - s.lastActiveAt) / 1000 / 60 / 60\n );\n console.log(\n ` - ${s.sessionId.slice(0, 8)}: ${s.branch || 'main'}, ${age}h old`\n );\n });\n console.log(`\\n Tip: Use --all to see frames across sessions`);\n }\n }\n\n db.close();\n } catch (error) {\n logger.error('Failed to get status', error as Error);\n console.error('\u274C Status check failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n// Linear Integration Commands\nconst linearCommand = program\n .command('linear')\n .description('Linear API integration commands');\n\nlinearCommand\n .command('setup')\n .description('Setup Linear OAuth integration')\n .action(async () => {\n try {\n const projectRoot = process.cwd();\n const linearSetup = new LinearOAuthSetup(projectRoot);\n\n const { authUrl, instructions } = await linearSetup.setupInteractive();\n\n console.log('\uD83D\uDD17 Linear OAuth Setup\\n');\n\n instructions.forEach((instruction) => {\n console.log(instruction);\n });\n\n if (authUrl) {\n console.log('\\n\uD83D\uDCCB Next step: Complete authorization and run:');\n console.log('stackmemory linear authorize <auth-code>');\n }\n } catch (error) {\n logger.error('Linear setup failed', error as Error);\n console.error('\u274C Setup failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('authorize')\n .description('Complete Linear OAuth authorization')\n .argument('<code>', 'Authorization code from Linear')\n .action(async (authCode: string) => {\n try {\n const projectRoot = process.cwd();\n const linearSetup = new LinearOAuthSetup(projectRoot);\n\n const success = await linearSetup.completeAuth(authCode);\n\n if (success) {\n console.log('\u2705 Linear integration authorized successfully!');\n console.log('\uD83E\uDDEA Testing connection...');\n\n const connectionOk = await linearSetup.testConnection();\n if (connectionOk) {\n console.log('\u2705 Linear connection test passed!');\n console.log('\\n\uD83D\uDE80 You can now use:');\n console.log('- stackmemory linear sync');\n console.log('- stackmemory linear status');\n } else {\n console.log(\n '\u26A0\uFE0F Linear connection test failed. Check your configuration.'\n );\n }\n } else {\n console.error('\u274C Authorization failed. Please try again.');\n process.exit(1);\n }\n } catch (error) {\n logger.error('Linear authorization failed', error as Error);\n console.error('\u274C Authorization failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('status')\n .description('Show Linear integration status')\n .action(async () => {\n try {\n const projectRoot = process.cwd();\n const authManager = new LinearAuthManager(projectRoot);\n\n const isConfigured = authManager.isConfigured();\n\n console.log('\uD83D\uDCCA Linear Integration Status:');\n console.log(` Configured: ${isConfigured ? '\u2705' : '\u274C'}`);\n\n if (isConfigured) {\n const config = authManager.loadConfig();\n const tokens = authManager.loadTokens();\n\n console.log(\n ` Client ID: ${config?.clientId ? config.clientId.substring(0, 8) + '...' : 'Not set'}`\n );\n console.log(` Tokens: ${tokens ? '\u2705 Valid' : '\u274C Missing'}`);\n\n if (tokens) {\n const expiresIn = Math.floor(\n (tokens.expiresAt - Date.now()) / 1000 / 60\n );\n console.log(\n ` Token expires: ${expiresIn > 0 ? `${expiresIn} minutes` : 'Expired'}`\n );\n }\n\n // Test connection\n console.log('\\n\uD83E\uDDEA Testing connection...');\n const linearSetup = new LinearOAuthSetup(projectRoot);\n const connectionOk = await linearSetup.testConnection();\n console.log(` Connection: ${connectionOk ? '\u2705 OK' : '\u274C Failed'}`);\n } else {\n console.log('\\n\uD83D\uDCA1 Run \"stackmemory linear setup\" to get started');\n }\n } catch (error) {\n logger.error('Linear status check failed', error as Error);\n console.error('\u274C Status check failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('sync')\n .description('Sync tasks with Linear')\n .option(\n '-d, --direction <direction>',\n 'Sync direction: bidirectional, to_linear, from_linear',\n 'bidirectional'\n )\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n if (!existsSync(dbPath)) {\n console.log(\n '\u274C StackMemory not initialized. Run \"stackmemory init\" first.'\n );\n return;\n }\n\n const authManager = new LinearAuthManager(projectRoot);\n\n // Check for API key from environment first\n if (!process.env.LINEAR_API_KEY && !authManager.isConfigured()) {\n console.log(\n '\u274C Linear not configured. Set LINEAR_API_KEY environment variable or run \"stackmemory linear setup\" first.'\n );\n return;\n }\n\n const db = new Database(dbPath);\n const taskStore = new PebblesTaskStore(projectRoot, db);\n\n const syncConfig = {\n ...DEFAULT_SYNC_CONFIG,\n enabled: true,\n direction: options.direction,\n };\n\n const linearSync = new LinearSyncEngine(\n taskStore,\n authManager,\n syncConfig\n );\n\n console.log(`\uD83D\uDD04 Starting ${options.direction} sync with Linear...`);\n\n const result = await linearSync.sync();\n\n // Track progress\n const progress = new ProgressTracker(projectRoot);\n\n if (result.success) {\n console.log('\u2705 Sync completed successfully!');\n console.log(` To Linear: ${result.synced.toLinear} created`);\n console.log(` From Linear: ${result.synced.fromLinear} created`);\n console.log(` Updated: ${result.synced.updated}`);\n\n // Update progress tracker\n progress.updateLinearStatus({\n lastSync: new Date().toISOString(),\n tasksSynced:\n result.synced.toLinear +\n result.synced.fromLinear +\n result.synced.updated,\n });\n\n if (result.conflicts.length > 0) {\n console.log(`\\n\u26A0\uFE0F Conflicts detected: ${result.conflicts.length}`);\n result.conflicts.forEach((conflict) => {\n console.log(` - ${conflict.taskId}: ${conflict.reason}`);\n });\n }\n } else {\n console.log('\u274C Sync failed');\n if (result.errors.length > 0) {\n result.errors.forEach((error) => {\n console.log(` Error: ${error}`);\n });\n }\n }\n\n db.close();\n } catch (error) {\n logger.error('Linear sync failed', error as Error);\n console.error('\u274C Sync failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n// Auto-sync commands\nlinearCommand\n .command('auto-sync')\n .description('Manage automatic synchronization')\n .option('--start', 'Start auto-sync service')\n .option('--stop', 'Stop auto-sync service')\n .option('--status', 'Show auto-sync status')\n .option('--interval <minutes>', 'Set sync interval in minutes', '5')\n .option(\n '--direction <direction>',\n 'Set sync direction: bidirectional, to_linear, from_linear',\n 'bidirectional'\n )\n .option('--quiet-start <hour>', 'Start of quiet hours (0-23)', '22')\n .option('--quiet-end <hour>', 'End of quiet hours (0-23)', '7')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n\n if (options.status) {\n const service = getAutoSyncService();\n if (service) {\n const status = service.getStatus();\n console.log('\uD83D\uDCCA Linear Auto-Sync Status:');\n console.log(` Running: ${status.running ? '\u2705' : '\u274C'}`);\n console.log(` Direction: ${status.config.direction}`);\n console.log(` Interval: ${status.config.interval} minutes`);\n console.log(\n ` Conflict Resolution: ${status.config.conflictResolution}`\n );\n\n if (status.lastSyncTime > 0) {\n const lastSync = new Date(status.lastSyncTime);\n console.log(` Last Sync: ${lastSync.toLocaleString()}`);\n }\n\n if (status.nextSyncTime) {\n const nextSync = new Date(status.nextSyncTime);\n console.log(` Next Sync: ${nextSync.toLocaleString()}`);\n }\n\n if (status.config.quietHours) {\n console.log(\n ` Quiet Hours: ${status.config.quietHours.start}:00 - ${status.config.quietHours.end}:00`\n );\n }\n\n if (status.retryCount > 0) {\n console.log(` \u26A0\uFE0F Retry Count: ${status.retryCount}`);\n }\n } else {\n console.log('\uD83D\uDCCA Linear Auto-Sync Status: \u274C Not running');\n }\n return;\n }\n\n if (options.start) {\n const authManager = new LinearAuthManager(projectRoot);\n if (!authManager.isConfigured()) {\n console.log(\n '\u274C Linear not configured. Run \"stackmemory linear setup\" first.'\n );\n return;\n }\n\n const config = {\n interval: parseInt(options.interval),\n direction: options.direction,\n quietHours: {\n start: parseInt(options.quietStart),\n end: parseInt(options.quietEnd),\n },\n };\n\n const service = initializeAutoSync(projectRoot, config);\n await service.start();\n\n console.log('\u2705 Linear auto-sync started');\n console.log(` Interval: ${config.interval} minutes`);\n console.log(` Direction: ${config.direction}`);\n console.log(\n ` Quiet Hours: ${config.quietHours.start}:00 - ${config.quietHours.end}:00`\n );\n console.log(\n '\\n\uD83D\uDCA1 Use \"stackmemory linear auto-sync --status\" to check status'\n );\n\n // Keep process alive for auto-sync\n process.on('SIGINT', () => {\n console.log('\\n\uD83D\uDED1 Stopping auto-sync service...');\n service.stop();\n process.exit(0);\n });\n\n console.log('\uD83D\uDD04 Auto-sync running... Press Ctrl+C to stop');\n // Keep the process running\n await new Promise(() => {}); // Intentionally never resolves\n }\n\n if (options.stop) {\n stopAutoSync();\n console.log('\uD83D\uDED1 Linear auto-sync stopped');\n }\n\n if (!options.start && !options.stop && !options.status) {\n console.log('\uD83D\uDCA1 Usage:');\n console.log(' --start Start auto-sync service');\n console.log(' --stop Stop auto-sync service');\n console.log(' --status Show current status');\n console.log(\n '\\nExample: stackmemory linear auto-sync --start --interval 10'\n );\n }\n } catch (error) {\n logger.error('Linear auto-sync command failed', error as Error);\n console.error('\u274C Auto-sync failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('force-sync')\n .description('Force immediate synchronization')\n .action(async () => {\n try {\n const service = getAutoSyncService();\n if (service) {\n console.log('\uD83D\uDD04 Forcing immediate sync...');\n await service.forceSync();\n console.log('\u2705 Sync completed');\n } else {\n console.log(\n '\u274C Auto-sync service not running. Use manual sync instead:'\n );\n console.log(' stackmemory linear sync');\n }\n } catch (error) {\n logger.error('Force sync failed', error as Error);\n console.error('\u274C Force sync failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('update <issueId>')\n .description('Update Linear task status')\n .option(\n '-s, --status <status>',\n 'New status (todo, in-progress, done, canceled)'\n )\n .option('-t, --title <title>', 'Update task title')\n .option('-d, --description <desc>', 'Update task description')\n .option(\n '-p, --priority <priority>',\n 'Set priority (1=urgent, 2=high, 3=medium, 4=low)'\n )\n .action(async (issueId, options) => {\n try {\n const projectRoot = process.cwd();\n const authManager = new LinearAuthManager(projectRoot);\n const tokens = authManager.loadTokens();\n\n if (!tokens) {\n console.error('\u274C Not authenticated. Run: stackmemory linear setup');\n process.exit(1);\n }\n\n const { LinearClient } = await import('../integrations/linear/client.js');\n const client = new LinearClient({\n apiKey: tokens.accessToken,\n });\n\n // Find the issue first\n let issue = await client.getIssue(issueId);\n if (!issue) {\n // Try finding by identifier\n issue = await client.findIssueByIdentifier(issueId);\n }\n\n if (!issue) {\n console.error(`\u274C Issue ${issueId} not found`);\n process.exit(1);\n }\n\n const updates: Record<string, unknown> = {};\n\n // Handle status update\n if (options.status) {\n const team = await client.getTeam();\n const states = await client.getWorkflowStates(team.id);\n\n const statusMap: Record<string, string> = {\n todo: 'unstarted',\n 'in-progress': 'started',\n done: 'completed',\n canceled: 'cancelled',\n };\n\n const targetType =\n statusMap[options.status.toLowerCase()] || options.status;\n const targetState = states.find(\n (s: { type: string }) => s.type === targetType\n );\n\n if (!targetState) {\n console.error(`\u274C Invalid status: ${options.status}`);\n console.log('Available states:');\n states.forEach((s: { name: string; type: string }) =>\n console.log(` - ${s.name} (${s.type})`)\n );\n process.exit(1);\n }\n\n updates.stateId = targetState.id;\n }\n\n if (options.title) updates.title = options.title;\n if (options.description) updates.description = options.description;\n if (options.priority) updates.priority = parseInt(options.priority);\n\n // Perform update\n const updatedIssue = await client.updateIssue(issue.id, updates);\n\n console.log(\n `\u2705 Updated ${updatedIssue.identifier}: ${updatedIssue.title}`\n );\n if (options.status) {\n console.log(` Status: ${updatedIssue.state.name}`);\n }\n console.log(` ${updatedIssue.url}`);\n\n // Auto-sync to local tasks after update\n console.log('\\n\uD83D\uDD04 Syncing to local tasks...');\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n if (existsSync(dbPath)) {\n const db = new Database(dbPath);\n const taskStore = new PebblesTaskStore(projectRoot, db);\n const { LinearSyncEngine, DEFAULT_SYNC_CONFIG } =\n await import('../integrations/linear/sync.js');\n const syncEngine = new LinearSyncEngine(\n taskStore,\n authManager,\n { ...DEFAULT_SYNC_CONFIG, enabled: true, direction: 'from_linear' },\n projectRoot\n );\n const syncResult = await syncEngine.sync();\n if (syncResult.success) {\n console.log(\n ` \u2705 Local tasks synced (${syncResult.synced.fromLinear} new, ${syncResult.synced.updated} updated)`\n );\n }\n db.close();\n }\n } catch (error) {\n logger.error('Failed to update Linear task', error as Error);\n console.error('\u274C Failed to update task:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('config')\n .description('Configure auto-sync settings')\n .option('--show', 'Show current configuration')\n .option('--set-interval <minutes>', 'Set sync interval in minutes')\n .option(\n '--set-direction <direction>',\n 'Set sync direction: bidirectional, to_linear, from_linear'\n )\n .option(\n '--set-conflict-resolution <strategy>',\n 'Set conflict resolution: newest_wins, linear_wins, stackmemory_wins, manual'\n )\n .option('--set-quiet-start <hour>', 'Set start of quiet hours (0-23)')\n .option('--set-quiet-end <hour>', 'Set end of quiet hours (0-23)')\n .option('--enable', 'Enable auto-sync')\n .option('--disable', 'Disable auto-sync')\n .option('--reset', 'Reset to default configuration')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const configManager = new LinearConfigManager(projectRoot);\n\n if (options.reset) {\n configManager.resetConfig();\n console.log('\u2705 Configuration reset to defaults');\n return;\n }\n\n if (options.show) {\n const config = configManager.loadConfig();\n if (config) {\n console.log('\uD83D\uDCCA Linear Auto-Sync Configuration:');\n console.log(` Enabled: ${config.enabled ? '\u2705' : '\u274C'}`);\n console.log(` Interval: ${config.interval} minutes`);\n console.log(` Direction: ${config.direction}`);\n console.log(` Conflict Resolution: ${config.conflictResolution}`);\n console.log(` Retry Attempts: ${config.retryAttempts}`);\n console.log(` Retry Delay: ${config.retryDelay / 1000}s`);\n\n if (config.quietHours) {\n console.log(\n ` Quiet Hours: ${config.quietHours.start}:00 - ${config.quietHours.end}:00`\n );\n }\n\n const lastUpdated = new Date(config.lastUpdated);\n console.log(` Last Updated: ${lastUpdated.toLocaleString()}`);\n } else {\n console.log('\uD83D\uDCCA No configuration found. Using defaults.');\n const defaultConfig = configManager.getDefaultConfig();\n console.log(` Default interval: ${defaultConfig.interval} minutes`);\n console.log(` Default direction: ${defaultConfig.direction}`);\n }\n return;\n }\n\n // Update configuration\n const updates: Record<string, unknown> = {};\n\n if (options.setInterval) {\n const interval = parseInt(options.setInterval);\n if (isNaN(interval) || interval < 1) {\n console.error('\u274C Interval must be a positive number');\n process.exit(1);\n }\n updates.interval = interval;\n console.log(`\u2705 Set interval to ${interval} minutes`);\n }\n\n if (options.setDirection) {\n const validDirections = ['bidirectional', 'to_linear', 'from_linear'];\n if (!validDirections.includes(options.setDirection)) {\n console.error(\n `\u274C Invalid direction. Must be one of: ${validDirections.join(', ')}`\n );\n process.exit(1);\n }\n updates.direction = options.setDirection;\n console.log(`\u2705 Set direction to ${options.setDirection}`);\n }\n\n if (options.setConflictResolution) {\n const validStrategies = [\n 'newest_wins',\n 'linear_wins',\n 'stackmemory_wins',\n 'manual',\n ];\n if (!validStrategies.includes(options.setConflictResolution)) {\n console.error(\n `\u274C Invalid strategy. Must be one of: ${validStrategies.join(', ')}`\n );\n process.exit(1);\n }\n updates.conflictResolution = options.setConflictResolution;\n console.log(\n `\u2705 Set conflict resolution to ${options.setConflictResolution}`\n );\n }\n\n if (options.setQuietStart) {\n const hour = parseInt(options.setQuietStart);\n if (isNaN(hour) || hour < 0 || hour > 23) {\n console.error('\u274C Quiet start hour must be between 0 and 23');\n process.exit(1);\n }\n const currentConfig =\n configManager.loadConfig() || configManager.getDefaultConfig();\n updates.quietHours = {\n start: hour,\n end: currentConfig.quietHours?.end || 7,\n };\n console.log(`\u2705 Set quiet hours start to ${hour}:00`);\n }\n\n if (options.setQuietEnd) {\n const hour = parseInt(options.setQuietEnd);\n if (isNaN(hour) || hour < 0 || hour > 23) {\n console.error('\u274C Quiet end hour must be between 0 and 23');\n process.exit(1);\n }\n const currentConfig =\n configManager.loadConfig() || configManager.getDefaultConfig();\n updates.quietHours = {\n start: currentConfig.quietHours?.start || 22,\n end: hour,\n };\n console.log(`\u2705 Set quiet hours end to ${hour}:00`);\n }\n\n if (options.enable) {\n updates.enabled = true;\n console.log('\u2705 Auto-sync enabled');\n }\n\n if (options.disable) {\n updates.enabled = false;\n console.log('\u274C Auto-sync disabled');\n }\n\n if (Object.keys(updates).length > 0) {\n configManager.saveConfig(updates);\n console.log(\n '\\n\uD83D\uDCA1 Configuration updated. Restart auto-sync service to apply changes.'\n );\n } else if (!options.show) {\n console.log('\uD83D\uDCA1 Use --show to view current configuration');\n console.log('\uD83D\uDCA1 Use --help to see all configuration options');\n }\n } catch (error) {\n logger.error('Linear config command failed', error as Error);\n console.error('\u274C Config failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nprogram\n .command('update-check')\n .description('Check for StackMemory updates')\n .action(async () => {\n try {\n console.log('\uD83D\uDD0D Checking for updates...');\n await UpdateChecker.forceCheck(VERSION);\n } catch (error) {\n logger.error('Update check failed', error as Error);\n console.error('\u274C Update check failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nprogram\n .command('analytics')\n .description('Launch task analytics dashboard')\n .option('-p, --port <port>', 'Port for dashboard server', '3000')\n .option('-o, --open', 'Open dashboard in browser')\n .option('--export <format>', 'Export metrics (json|csv)')\n .option('--sync', 'Sync with Linear before launching')\n .option('--view', 'Show analytics in terminal')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n if (!existsSync(dbPath)) {\n console.log(\n '\u274C StackMemory not initialized. Run \"stackmemory init\" first.'\n );\n return;\n }\n\n if (options.view) {\n const { displayAnalyticsDashboard } = await import('./utils/viewer.js');\n await displayAnalyticsDashboard(projectRoot);\n return;\n }\n\n if (options.export) {\n const { AnalyticsService } =\n await import('../features/analytics/index.js');\n const service = new AnalyticsService(projectRoot);\n\n if (options.sync) {\n console.log('\uD83D\uDD04 Syncing with Linear...');\n await service.syncLinearTasks();\n }\n\n const state = await service.getDashboardState();\n\n if (options.export === 'csv') {\n console.log('\uD83D\uDCCA Exporting metrics as CSV...');\n // Convert to CSV format\n const tasks = state.recentTasks;\n const headers = [\n 'ID',\n 'Title',\n 'State',\n 'Priority',\n 'Created',\n 'Completed',\n ];\n const rows = tasks.map((t) => [\n t.id,\n t.title,\n t.state,\n t.priority,\n t.createdAt.toISOString(),\n t.completedAt?.toISOString() || '',\n ]);\n console.log(headers.join(','));\n rows.forEach((r) => console.log(r.join(',')));\n } else {\n console.log(JSON.stringify(state, null, 2));\n }\n\n service.close();\n return;\n }\n\n // Launch dashboard server\n console.log(\n `\uD83D\uDE80 Launching analytics dashboard on port ${options.port}...`\n );\n\n const express = (await import('express')).default;\n const { AnalyticsAPI } = await import('../features/analytics/index.js');\n const { createServer } = await import('http');\n\n const app = express();\n\n // Add error handling middleware\n app.use(\n (\n err: Error,\n _req: import('express').Request,\n res: import('express').Response,\n _next: import('express').NextFunction\n ) => {\n console.error('Express error:', err);\n res.status(500).json({ error: err.message });\n }\n );\n\n const analyticsAPI = new AnalyticsAPI(projectRoot);\n\n if (options.sync) {\n console.log('\uD83D\uDD04 Syncing with Linear...');\n const service = new (\n await import('../features/analytics/index.js')\n ).AnalyticsService(projectRoot);\n await service.syncLinearTasks();\n service.close();\n }\n\n app.use('/api/analytics', analyticsAPI.getRouter());\n\n // Serve the HTML dashboard\n app.get('/', async (req, res) => {\n // Try multiple paths for the dashboard HTML\n const possiblePaths = [\n join(projectRoot, 'src/features/analytics/dashboard.html'),\n join(projectRoot, 'dist/features/analytics/dashboard.html'),\n ];\n\n for (const dashboardPath of possiblePaths) {\n if (existsSync(dashboardPath)) {\n res.sendFile(dashboardPath);\n return;\n }\n }\n\n // Inline fallback dashboard\n res.send(`<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>StackMemory Analytics</title>\n <script src=\"https://cdn.jsdelivr.net/npm/chart.js\"></script>\n <style>\n * { margin: 0; padding: 0; box-sizing: border-box; }\n body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #1a1a2e; color: #eee; padding: 20px; }\n .container { max-width: 1200px; margin: 0 auto; }\n h1 { color: #667eea; margin-bottom: 20px; }\n .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 30px; }\n .card { background: #16213e; border-radius: 12px; padding: 20px; }\n .metric-value { font-size: 2.5em; font-weight: bold; color: #667eea; }\n .metric-label { color: #888; text-transform: uppercase; font-size: 0.8em; }\n .task-list { max-height: 400px; overflow-y: auto; }\n .task-item { padding: 10px; border-left: 3px solid #667eea; margin-bottom: 8px; background: #1a1a2e; }\n .task-item.completed { border-color: #22c55e; }\n .task-item.in_progress { border-color: #f59e0b; }\n .status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.8em; margin-right: 8px; }\n .status.completed { background: #22c55e30; color: #22c55e; }\n .status.in_progress { background: #f59e0b30; color: #f59e0b; }\n .status.todo { background: #667eea30; color: #667eea; }\n </style>\n</head>\n<body>\n <div class=\"container\">\n <h1>\uD83D\uDCCA StackMemory Analytics</h1>\n <div class=\"grid\" id=\"metrics\"></div>\n <div class=\"card\"><h3>Recent Tasks</h3><div class=\"task-list\" id=\"tasks\">Loading...</div></div>\n </div>\n <script>\n async function load() {\n const metrics = await fetch('/api/analytics/metrics').then(r => r.json());\n const tasks = await fetch('/api/analytics/tasks').then(r => r.json());\n \n document.getElementById('metrics').innerHTML = \\`\n <div class=\"card\"><div class=\"metric-label\">Total</div><div class=\"metric-value\">\\${metrics.data.metrics.totalTasks}</div></div>\n <div class=\"card\"><div class=\"metric-label\">Completed</div><div class=\"metric-value\">\\${metrics.data.metrics.completedTasks}</div></div>\n <div class=\"card\"><div class=\"metric-label\">In Progress</div><div class=\"metric-value\">\\${metrics.data.metrics.inProgressTasks}</div></div>\n <div class=\"card\"><div class=\"metric-label\">Completion</div><div class=\"metric-value\">\\${metrics.data.metrics.completionRate.toFixed(0)}%</div></div>\n \\`;\n \n document.getElementById('tasks').innerHTML = tasks.data.tasks.slice(0, 10).map(t => \\`\n <div class=\"task-item \\${t.state}\">\n <span class=\"status \\${t.state}\">\\${t.state}</span>\n <strong>\\${t.title}</strong>\n </div>\n \\`).join('');\n }\n load();\n setInterval(load, 30000);\n </script>\n</body>\n</html>`);\n });\n\n const server = createServer(app);\n analyticsAPI.setupWebSocket(server);\n\n server.listen(options.port, async () => {\n console.log(\n `\u2705 Analytics dashboard running at http://localhost:${options.port}`\n );\n\n if (options.open) {\n const { exec } = await import('child_process');\n const url = `http://localhost:${options.port}`;\n const command =\n process.platform === 'darwin'\n ? `open ${url}`\n : process.platform === 'win32'\n ? `start ${url}`\n : `xdg-open ${url}`;\n exec(command);\n }\n });\n\n process.on('SIGINT', () => {\n console.log('\\n\uD83D\uDC4B Shutting down analytics dashboard...');\n analyticsAPI.close();\n server.close();\n process.exit(0);\n });\n\n // Keep the process alive\n await new Promise(() => {});\n } catch (error) {\n logger.error('Analytics command failed', error as Error);\n console.error('\u274C Analytics failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nprogram\n .command('progress')\n .description('Show current progress and recent changes')\n .action(async () => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n if (!existsSync(dbPath)) {\n console.log(\n '\u274C StackMemory not initialized. Run \"stackmemory init\" first.'\n );\n return;\n }\n\n const progress = new ProgressTracker(projectRoot);\n console.log(progress.getSummary());\n } catch (error) {\n logger.error('Failed to show progress', error as Error);\n console.error('\u274C Failed to show progress:', (error as Error).message);\n process.exit(1);\n }\n });\n\nprogram\n .command('mcp-server')\n .description('Start StackMemory MCP server for Claude Desktop')\n .option('-p, --project <path>', 'Project root directory', process.cwd())\n .action(async (options) => {\n try {\n const { runMCPServer } = await import('../integrations/mcp/server.js');\n\n // Set project root\n process.env.PROJECT_ROOT = options.project;\n\n console.log('\uD83D\uDE80 Starting StackMemory MCP Server...');\n console.log(` Project: ${options.project}`);\n console.log(` Version: ${VERSION}`);\n\n // Check for updates silently\n UpdateChecker.checkForUpdates(VERSION, true).catch(() => {});\n\n // Start the MCP server\n await runMCPServer();\n } catch (error) {\n logger.error('Failed to start MCP server', error as Error);\n console.error('\u274C MCP server failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n// Add test context command\nprogram\n .command('context:test')\n .description('Test context persistence by creating sample frames')\n .action(async () => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n if (!existsSync(dbPath)) {\n console.log(\n '\u274C StackMemory not initialized. Run \"stackmemory init\" first.'\n );\n return;\n }\n\n const db = new Database(dbPath);\n const frameManager = new FrameManager(db, 'cli-project');\n\n // Create test frames\n console.log('\uD83D\uDCDD Creating test context frames...');\n\n const rootFrame = frameManager.createFrame({\n type: 'task',\n name: 'Test Session',\n inputs: { test: true, timestamp: new Date().toISOString() },\n });\n\n const taskFrame = frameManager.createFrame({\n type: 'subtask',\n name: 'Sample Task',\n inputs: { description: 'Testing context persistence' },\n parentFrameId: rootFrame,\n });\n\n const commandFrame = frameManager.createFrame({\n type: 'tool_scope',\n name: 'test-command',\n inputs: { args: ['--test'] },\n parentFrameId: taskFrame,\n });\n\n // Add some events\n frameManager.addEvent(\n 'observation',\n {\n message: 'Test event recorded',\n },\n commandFrame\n );\n\n console.log('\u2705 Test frames created!');\n console.log(`\uD83D\uDCCA Stack depth: ${frameManager.getStackDepth()}`);\n console.log(\n `\uD83D\uDD04 Active frames: ${frameManager.getActiveFramePath().length}`\n );\n\n // Close one frame to test state changes\n frameManager.closeFrame(commandFrame);\n console.log(\n `\uD83D\uDCCA After closing command frame: depth = ${frameManager.getStackDepth()}`\n );\n\n db.close();\n } catch (error) {\n logger.error('Test context failed', error as Error);\n console.error('\u274C Test failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n// Register project management commands\n// Register command modules\nregisterOnboardingCommand(program);\nregisterProjectCommands(program);\nregisterWorktreeCommands(program);\n\n// Register Linear integration commands\nregisterLinearCommands(program);\nregisterLinearTestCommand(program);\n\n// Register session management commands\nprogram.addCommand(createSessionCommands());\n\n// Register webhook command\nprogram.addCommand(webhookCommand());\n\n// Register enhanced CLI commands\nprogram.addCommand(createTaskCommands());\nprogram.addCommand(createSearchCommand());\nprogram.addCommand(createLogCommand());\nprogram.addCommand(createContextCommands());\nprogram.addCommand(createConfigCommand());\nprogram.addCommand(createAgentCommand());\nprogram.addCommand(createHandoffCommand());\n\n// Auto-detect current project on startup\nif (process.argv.length > 2) {\n const manager = ProjectManager.getInstance();\n manager.detectProject().catch(() => {\n // Silently fail if not in a project directory\n });\n}\n\n// Only parse when running as main module (not when imported for testing)\nconst isMainModule =\n import.meta.url === `file://${process.argv[1]}` ||\n process.argv[1]?.endsWith('/stackmemory') ||\n process.argv[1]?.endsWith('index.ts') ||\n process.argv[1]?.includes('tsx');\n\nif (isMainModule) {\n program.parse();\n}\n\nexport { program };\n"],
|
|
4
|
+
"sourcesContent": ["#!/usr/bin/env node\n/**\n * StackMemory CLI\n * Command-line interface for StackMemory operations\n */\n\nimport { program } from 'commander';\nimport { logger } from '../core/monitoring/logger.js';\nimport { FrameManager } from '../core/context/frame-manager.js';\nimport { sessionManager, FrameQueryMode } from '../core/session/index.js';\nimport { PebblesTaskStore } from '../features/tasks/pebbles-task-store.js';\nimport {\n LinearAuthManager,\n LinearOAuthSetup,\n} from '../integrations/linear/auth.js';\nimport {\n LinearSyncEngine,\n DEFAULT_SYNC_CONFIG,\n} from '../integrations/linear/sync.js';\nimport {\n initializeAutoSync,\n getAutoSyncService,\n stopAutoSync,\n} from '../integrations/linear/auto-sync.js';\nimport { LinearConfigManager } from '../integrations/linear/config.js';\nimport { UpdateChecker } from '../core/utils/update-checker.js';\nimport { ProgressTracker } from '../core/monitoring/progress-tracker.js';\nimport { registerProjectCommands } from './commands/projects.js';\nimport { registerLinearCommands } from './commands/linear.js';\nimport { registerLinearTestCommand } from './commands/linear-test.js';\nimport { createSessionCommands } from './commands/session.js';\nimport { registerWorktreeCommands } from './commands/worktree.js';\nimport { registerOnboardingCommand } from './commands/onboard.js';\nimport { webhookCommand } from './commands/webhook.js';\nimport { createTaskCommands } from './commands/tasks.js';\nimport { createSearchCommand } from './commands/search.js';\nimport { createLogCommand } from './commands/log.js';\nimport { createContextCommands } from './commands/context.js';\nimport { createConfigCommand } from './commands/config.js';\nimport { createAgentCommand } from './commands/agent.js';\nimport { createHandoffCommand } from './commands/handoff.js';\nimport { ProjectManager } from '../core/projects/project-manager.js';\nimport Database from 'better-sqlite3';\nimport { join } from 'path';\nimport { existsSync, mkdirSync } from 'fs';\n\nconst VERSION = '0.3.1';\n\n// Check for updates on CLI startup\nUpdateChecker.checkForUpdates(VERSION, true).catch(() => {\n // Silently ignore errors\n});\n\nprogram\n .name('stackmemory')\n .description('Lossless memory runtime for AI coding tools')\n .version(VERSION);\n\nprogram\n .command('init')\n .description('Initialize StackMemory in current project')\n .action(async () => {\n try {\n const projectRoot = process.cwd();\n const dbDir = join(projectRoot, '.stackmemory');\n\n if (!existsSync(dbDir)) {\n mkdirSync(dbDir, { recursive: true });\n }\n\n const dbPath = join(dbDir, 'context.db');\n const db = new Database(dbPath);\n new FrameManager(db, 'cli-project');\n\n logger.info('StackMemory initialized successfully', { projectRoot });\n console.log('\u2705 StackMemory initialized in', projectRoot);\n\n db.close();\n } catch (error) {\n logger.error('Failed to initialize StackMemory', error as Error);\n console.error('\u274C Initialization failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nprogram\n .command('status')\n .description('Show current StackMemory status')\n .option('--all', 'Show all active frames across sessions')\n .option('--project', 'Show all active frames in current project')\n .option('--session <id>', 'Show frames for specific session')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n if (!existsSync(dbPath)) {\n console.log(\n '\u274C StackMemory not initialized. Run \"stackmemory init\" first.'\n );\n return;\n }\n\n // Check for updates and display if available\n await UpdateChecker.checkForUpdates(VERSION);\n\n // Initialize session manager\n await sessionManager.initialize();\n const session = await sessionManager.getOrCreateSession({\n projectPath: projectRoot,\n sessionId: options.session,\n });\n\n const db = new Database(dbPath);\n const frameManager = new FrameManager(db, session.projectId);\n\n // Set query mode based on options\n if (options.all) {\n frameManager.setQueryMode(FrameQueryMode.ALL_ACTIVE);\n } else if (options.project) {\n frameManager.setQueryMode(FrameQueryMode.PROJECT_ACTIVE);\n }\n\n const activeFrames = frameManager.getActiveFramePath();\n const stackDepth = frameManager.getStackDepth();\n\n // Always get total counts across all sessions\n const totalStats = db\n .prepare(\n `\n SELECT \n COUNT(*) as total_frames,\n SUM(CASE WHEN state = 'active' THEN 1 ELSE 0 END) as active_frames,\n SUM(CASE WHEN state = 'closed' THEN 1 ELSE 0 END) as closed_frames,\n COUNT(DISTINCT run_id) as total_sessions\n FROM frames\n WHERE project_id = ?\n `\n )\n .get(session.projectId) as any;\n\n const contextCount = db\n .prepare(\n `\n SELECT COUNT(*) as count FROM contexts\n `\n )\n .get() as any;\n\n const eventCount = db\n .prepare(\n `\n SELECT COUNT(*) as count FROM events\n `\n )\n .get() as any;\n\n console.log('\uD83D\uDCCA StackMemory Status:');\n console.log(\n ` Session: ${session.sessionId.slice(0, 8)} (${session.state}, ${Math.round((Date.now() - session.startedAt) / 1000 / 60)}min old)`\n );\n console.log(` Project: ${session.projectId}`);\n if (session.branch) {\n console.log(` Branch: ${session.branch}`);\n }\n\n // Show total database statistics\n console.log(`\\n Database Statistics:`);\n console.log(` Total contexts: ${contextCount.count}`);\n console.log(\n ` Total frames: ${totalStats.total_frames} (${totalStats.active_frames} active, ${totalStats.closed_frames} closed)`\n );\n console.log(` Total events: ${eventCount.count}`);\n console.log(` Total sessions: ${totalStats.total_sessions}`);\n\n // Show recent activity\n const recentFrames = db\n .prepare(\n `\n SELECT name, type, state, datetime(created_at, 'unixepoch') as created\n FROM frames\n WHERE project_id = ?\n ORDER BY created_at DESC\n LIMIT 3\n `\n )\n .all(session.projectId) as any[];\n\n if (recentFrames.length > 0) {\n console.log(`\\n Recent Activity:`);\n recentFrames.forEach((f: any) => {\n const stateIcon = f.state === 'active' ? '\uD83D\uDFE2' : '\u26AB';\n console.log(` ${stateIcon} ${f.name} [${f.type}] - ${f.created}`);\n });\n }\n\n console.log(`\\n Current Session:`);\n console.log(` Stack depth: ${stackDepth}`);\n console.log(` Active frames: ${activeFrames.length}`);\n\n if (activeFrames.length > 0) {\n activeFrames.forEach((frame, i) => {\n const indent = ' ' + ' '.repeat(frame.depth || i);\n const prefix = i === 0 ? '\u2514\u2500' : ' \u2514\u2500';\n console.log(`${indent}${prefix} ${frame.name} [${frame.type}]`);\n });\n }\n\n // Show other sessions if in default mode\n if (!options.all && !options.project) {\n const otherSessions = await sessionManager.listSessions({\n projectId: session.projectId,\n state: 'active',\n });\n\n const otherActive = otherSessions.filter(\n (s) => s.sessionId !== session.sessionId\n );\n if (otherActive.length > 0) {\n console.log(`\\n Other Active Sessions (same project):`);\n otherActive.forEach((s) => {\n const age = Math.round(\n (Date.now() - s.lastActiveAt) / 1000 / 60 / 60\n );\n console.log(\n ` - ${s.sessionId.slice(0, 8)}: ${s.branch || 'main'}, ${age}h old`\n );\n });\n console.log(`\\n Tip: Use --all to see frames across sessions`);\n }\n }\n\n db.close();\n } catch (error) {\n logger.error('Failed to get status', error as Error);\n console.error('\u274C Status check failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n// Linear Integration Commands\nconst linearCommand = program\n .command('linear')\n .description('Linear API integration commands');\n\nlinearCommand\n .command('setup')\n .description('Setup Linear OAuth integration')\n .action(async () => {\n try {\n const projectRoot = process.cwd();\n const linearSetup = new LinearOAuthSetup(projectRoot);\n\n const { authUrl, instructions } = await linearSetup.setupInteractive();\n\n console.log('\uD83D\uDD17 Linear OAuth Setup\\n');\n\n instructions.forEach((instruction) => {\n console.log(instruction);\n });\n\n if (authUrl) {\n console.log('\\n\uD83D\uDCCB Next step: Complete authorization and run:');\n console.log('stackmemory linear authorize <auth-code>');\n }\n } catch (error) {\n logger.error('Linear setup failed', error as Error);\n console.error('\u274C Setup failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('authorize')\n .description('Complete Linear OAuth authorization')\n .argument('<code>', 'Authorization code from Linear')\n .action(async (authCode: string) => {\n try {\n const projectRoot = process.cwd();\n const linearSetup = new LinearOAuthSetup(projectRoot);\n\n const success = await linearSetup.completeAuth(authCode);\n\n if (success) {\n console.log('\u2705 Linear integration authorized successfully!');\n console.log('\uD83E\uDDEA Testing connection...');\n\n const connectionOk = await linearSetup.testConnection();\n if (connectionOk) {\n console.log('\u2705 Linear connection test passed!');\n console.log('\\n\uD83D\uDE80 You can now use:');\n console.log('- stackmemory linear sync');\n console.log('- stackmemory linear status');\n } else {\n console.log(\n '\u26A0\uFE0F Linear connection test failed. Check your configuration.'\n );\n }\n } else {\n console.error('\u274C Authorization failed. Please try again.');\n process.exit(1);\n }\n } catch (error) {\n logger.error('Linear authorization failed', error as Error);\n console.error('\u274C Authorization failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('status')\n .description('Show Linear integration status')\n .action(async () => {\n try {\n const projectRoot = process.cwd();\n const authManager = new LinearAuthManager(projectRoot);\n\n const isConfigured = authManager.isConfigured();\n\n console.log('\uD83D\uDCCA Linear Integration Status:');\n console.log(` Configured: ${isConfigured ? '\u2705' : '\u274C'}`);\n\n if (isConfigured) {\n const config = authManager.loadConfig();\n const tokens = authManager.loadTokens();\n\n console.log(\n ` Client ID: ${config?.clientId ? config.clientId.substring(0, 8) + '...' : 'Not set'}`\n );\n console.log(` Tokens: ${tokens ? '\u2705 Valid' : '\u274C Missing'}`);\n\n if (tokens) {\n const expiresIn = Math.floor(\n (tokens.expiresAt - Date.now()) / 1000 / 60\n );\n console.log(\n ` Token expires: ${expiresIn > 0 ? `${expiresIn} minutes` : 'Expired'}`\n );\n }\n\n // Test connection\n console.log('\\n\uD83E\uDDEA Testing connection...');\n const linearSetup = new LinearOAuthSetup(projectRoot);\n const connectionOk = await linearSetup.testConnection();\n console.log(` Connection: ${connectionOk ? '\u2705 OK' : '\u274C Failed'}`);\n } else {\n console.log('\\n\uD83D\uDCA1 Run \"stackmemory linear setup\" to get started');\n }\n } catch (error) {\n logger.error('Linear status check failed', error as Error);\n console.error('\u274C Status check failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('sync')\n .description('Sync tasks with Linear')\n .option(\n '-d, --direction <direction>',\n 'Sync direction: bidirectional, to_linear, from_linear',\n 'bidirectional'\n )\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n if (!existsSync(dbPath)) {\n console.log(\n '\u274C StackMemory not initialized. Run \"stackmemory init\" first.'\n );\n return;\n }\n\n const authManager = new LinearAuthManager(projectRoot);\n\n // Check for API key from environment first\n if (!process.env.LINEAR_API_KEY && !authManager.isConfigured()) {\n console.log(\n '\u274C Linear not configured. Set LINEAR_API_KEY environment variable or run \"stackmemory linear setup\" first.'\n );\n return;\n }\n\n const db = new Database(dbPath);\n const taskStore = new PebblesTaskStore(projectRoot, db);\n\n const syncConfig = {\n ...DEFAULT_SYNC_CONFIG,\n enabled: true,\n direction: options.direction,\n };\n\n const linearSync = new LinearSyncEngine(\n taskStore,\n authManager,\n syncConfig\n );\n\n console.log(`\uD83D\uDD04 Starting ${options.direction} sync with Linear...`);\n\n const result = await linearSync.sync();\n\n // Track progress\n const progress = new ProgressTracker(projectRoot);\n\n if (result.success) {\n console.log('\u2705 Sync completed successfully!');\n console.log(` To Linear: ${result.synced.toLinear} created`);\n console.log(` From Linear: ${result.synced.fromLinear} created`);\n console.log(` Updated: ${result.synced.updated}`);\n\n // Update progress tracker\n progress.updateLinearStatus({\n lastSync: new Date().toISOString(),\n tasksSynced:\n result.synced.toLinear +\n result.synced.fromLinear +\n result.synced.updated,\n });\n\n if (result.conflicts.length > 0) {\n console.log(`\\n\u26A0\uFE0F Conflicts detected: ${result.conflicts.length}`);\n result.conflicts.forEach((conflict) => {\n console.log(` - ${conflict.taskId}: ${conflict.reason}`);\n });\n }\n } else {\n console.log('\u274C Sync failed');\n if (result.errors.length > 0) {\n result.errors.forEach((error) => {\n console.log(` Error: ${error}`);\n });\n }\n }\n\n db.close();\n } catch (error) {\n logger.error('Linear sync failed', error as Error);\n console.error('\u274C Sync failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n// Auto-sync commands\nlinearCommand\n .command('auto-sync')\n .description('Manage automatic synchronization')\n .option('--start', 'Start auto-sync service')\n .option('--stop', 'Stop auto-sync service')\n .option('--status', 'Show auto-sync status')\n .option('--interval <minutes>', 'Set sync interval in minutes', '5')\n .option(\n '--direction <direction>',\n 'Set sync direction: bidirectional, to_linear, from_linear',\n 'bidirectional'\n )\n .option('--quiet-start <hour>', 'Start of quiet hours (0-23)', '22')\n .option('--quiet-end <hour>', 'End of quiet hours (0-23)', '7')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n\n if (options.status) {\n const service = getAutoSyncService();\n if (service) {\n const status = service.getStatus();\n console.log('\uD83D\uDCCA Linear Auto-Sync Status:');\n console.log(` Running: ${status.running ? '\u2705' : '\u274C'}`);\n console.log(` Direction: ${status.config.direction}`);\n console.log(` Interval: ${status.config.interval} minutes`);\n console.log(\n ` Conflict Resolution: ${status.config.conflictResolution}`\n );\n\n if (status.lastSyncTime > 0) {\n const lastSync = new Date(status.lastSyncTime);\n console.log(` Last Sync: ${lastSync.toLocaleString()}`);\n }\n\n if (status.nextSyncTime) {\n const nextSync = new Date(status.nextSyncTime);\n console.log(` Next Sync: ${nextSync.toLocaleString()}`);\n }\n\n if (status.config.quietHours) {\n console.log(\n ` Quiet Hours: ${status.config.quietHours.start}:00 - ${status.config.quietHours.end}:00`\n );\n }\n\n if (status.retryCount > 0) {\n console.log(` \u26A0\uFE0F Retry Count: ${status.retryCount}`);\n }\n } else {\n console.log('\uD83D\uDCCA Linear Auto-Sync Status: \u274C Not running');\n }\n return;\n }\n\n if (options.start) {\n const authManager = new LinearAuthManager(projectRoot);\n if (!authManager.isConfigured()) {\n console.log(\n '\u274C Linear not configured. Run \"stackmemory linear setup\" first.'\n );\n return;\n }\n\n const config = {\n interval: parseInt(options.interval),\n direction: options.direction,\n quietHours: {\n start: parseInt(options.quietStart),\n end: parseInt(options.quietEnd),\n },\n };\n\n const service = initializeAutoSync(projectRoot, config);\n await service.start();\n\n console.log('\u2705 Linear auto-sync started');\n console.log(` Interval: ${config.interval} minutes`);\n console.log(` Direction: ${config.direction}`);\n console.log(\n ` Quiet Hours: ${config.quietHours.start}:00 - ${config.quietHours.end}:00`\n );\n console.log(\n '\\n\uD83D\uDCA1 Use \"stackmemory linear auto-sync --status\" to check status'\n );\n\n // Keep process alive for auto-sync\n process.on('SIGINT', () => {\n console.log('\\n\uD83D\uDED1 Stopping auto-sync service...');\n service.stop();\n process.exit(0);\n });\n\n console.log('\uD83D\uDD04 Auto-sync running... Press Ctrl+C to stop');\n // Keep the process running\n await new Promise(() => {}); // Intentionally never resolves\n }\n\n if (options.stop) {\n stopAutoSync();\n console.log('\uD83D\uDED1 Linear auto-sync stopped');\n }\n\n if (!options.start && !options.stop && !options.status) {\n console.log('\uD83D\uDCA1 Usage:');\n console.log(' --start Start auto-sync service');\n console.log(' --stop Stop auto-sync service');\n console.log(' --status Show current status');\n console.log(\n '\\nExample: stackmemory linear auto-sync --start --interval 10'\n );\n }\n } catch (error) {\n logger.error('Linear auto-sync command failed', error as Error);\n console.error('\u274C Auto-sync failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('force-sync')\n .description('Force immediate synchronization')\n .action(async () => {\n try {\n const service = getAutoSyncService();\n if (service) {\n console.log('\uD83D\uDD04 Forcing immediate sync...');\n await service.forceSync();\n console.log('\u2705 Sync completed');\n } else {\n console.log(\n '\u274C Auto-sync service not running. Use manual sync instead:'\n );\n console.log(' stackmemory linear sync');\n }\n } catch (error) {\n logger.error('Force sync failed', error as Error);\n console.error('\u274C Force sync failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('update <issueId>')\n .description('Update Linear task status')\n .option(\n '-s, --status <status>',\n 'New status (todo, in-progress, done, canceled)'\n )\n .option('-t, --title <title>', 'Update task title')\n .option('-d, --description <desc>', 'Update task description')\n .option(\n '-p, --priority <priority>',\n 'Set priority (1=urgent, 2=high, 3=medium, 4=low)'\n )\n .action(async (issueId, options) => {\n try {\n const projectRoot = process.cwd();\n const authManager = new LinearAuthManager(projectRoot);\n const tokens = authManager.loadTokens();\n\n if (!tokens) {\n console.error('\u274C Not authenticated. Run: stackmemory linear setup');\n process.exit(1);\n }\n\n const { LinearClient } = await import('../integrations/linear/client.js');\n const client = new LinearClient({\n apiKey: tokens.accessToken,\n });\n\n // Find the issue first\n let issue = await client.getIssue(issueId);\n if (!issue) {\n // Try finding by identifier\n issue = await client.findIssueByIdentifier(issueId);\n }\n\n if (!issue) {\n console.error(`\u274C Issue ${issueId} not found`);\n process.exit(1);\n }\n\n const updates: Record<string, unknown> = {};\n\n // Handle status update\n if (options.status) {\n const team = await client.getTeam();\n const states = await client.getWorkflowStates(team.id);\n\n const statusMap: Record<string, string> = {\n todo: 'unstarted',\n 'in-progress': 'started',\n done: 'completed',\n canceled: 'cancelled',\n };\n\n const targetType =\n statusMap[options.status.toLowerCase()] || options.status;\n const targetState = states.find(\n (s: { type: string }) => s.type === targetType\n );\n\n if (!targetState) {\n console.error(`\u274C Invalid status: ${options.status}`);\n console.log('Available states:');\n states.forEach((s: { name: string; type: string }) =>\n console.log(` - ${s.name} (${s.type})`)\n );\n process.exit(1);\n }\n\n updates.stateId = targetState.id;\n }\n\n if (options.title) updates.title = options.title;\n if (options.description) updates.description = options.description;\n if (options.priority) updates.priority = parseInt(options.priority);\n\n // Perform update\n const updatedIssue = await client.updateIssue(issue.id, updates);\n\n console.log(\n `\u2705 Updated ${updatedIssue.identifier}: ${updatedIssue.title}`\n );\n if (options.status) {\n console.log(` Status: ${updatedIssue.state.name}`);\n }\n console.log(` ${updatedIssue.url}`);\n\n // Auto-sync to local tasks after update\n console.log('\\n\uD83D\uDD04 Syncing to local tasks...');\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n if (existsSync(dbPath)) {\n const db = new Database(dbPath);\n const taskStore = new PebblesTaskStore(projectRoot, db);\n const { LinearSyncEngine, DEFAULT_SYNC_CONFIG } =\n await import('../integrations/linear/sync.js');\n const syncEngine = new LinearSyncEngine(\n taskStore,\n authManager,\n { ...DEFAULT_SYNC_CONFIG, enabled: true, direction: 'from_linear' },\n projectRoot\n );\n const syncResult = await syncEngine.sync();\n if (syncResult.success) {\n console.log(\n ` \u2705 Local tasks synced (${syncResult.synced.fromLinear} new, ${syncResult.synced.updated} updated)`\n );\n }\n db.close();\n }\n } catch (error) {\n logger.error('Failed to update Linear task', error as Error);\n console.error('\u274C Failed to update task:', (error as Error).message);\n process.exit(1);\n }\n });\n\nlinearCommand\n .command('config')\n .description('Configure auto-sync settings')\n .option('--show', 'Show current configuration')\n .option('--set-interval <minutes>', 'Set sync interval in minutes')\n .option(\n '--set-direction <direction>',\n 'Set sync direction: bidirectional, to_linear, from_linear'\n )\n .option(\n '--set-conflict-resolution <strategy>',\n 'Set conflict resolution: newest_wins, linear_wins, stackmemory_wins, manual'\n )\n .option('--set-quiet-start <hour>', 'Set start of quiet hours (0-23)')\n .option('--set-quiet-end <hour>', 'Set end of quiet hours (0-23)')\n .option('--enable', 'Enable auto-sync')\n .option('--disable', 'Disable auto-sync')\n .option('--reset', 'Reset to default configuration')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const configManager = new LinearConfigManager(projectRoot);\n\n if (options.reset) {\n configManager.resetConfig();\n console.log('\u2705 Configuration reset to defaults');\n return;\n }\n\n if (options.show) {\n const config = configManager.loadConfig();\n if (config) {\n console.log('\uD83D\uDCCA Linear Auto-Sync Configuration:');\n console.log(` Enabled: ${config.enabled ? '\u2705' : '\u274C'}`);\n console.log(` Interval: ${config.interval} minutes`);\n console.log(` Direction: ${config.direction}`);\n console.log(` Conflict Resolution: ${config.conflictResolution}`);\n console.log(` Retry Attempts: ${config.retryAttempts}`);\n console.log(` Retry Delay: ${config.retryDelay / 1000}s`);\n\n if (config.quietHours) {\n console.log(\n ` Quiet Hours: ${config.quietHours.start}:00 - ${config.quietHours.end}:00`\n );\n }\n\n const lastUpdated = new Date(config.lastUpdated);\n console.log(` Last Updated: ${lastUpdated.toLocaleString()}`);\n } else {\n console.log('\uD83D\uDCCA No configuration found. Using defaults.');\n const defaultConfig = configManager.getDefaultConfig();\n console.log(` Default interval: ${defaultConfig.interval} minutes`);\n console.log(` Default direction: ${defaultConfig.direction}`);\n }\n return;\n }\n\n // Update configuration\n const updates: Record<string, unknown> = {};\n\n if (options.setInterval) {\n const interval = parseInt(options.setInterval);\n if (isNaN(interval) || interval < 1) {\n console.error('\u274C Interval must be a positive number');\n process.exit(1);\n }\n updates.interval = interval;\n console.log(`\u2705 Set interval to ${interval} minutes`);\n }\n\n if (options.setDirection) {\n const validDirections = ['bidirectional', 'to_linear', 'from_linear'];\n if (!validDirections.includes(options.setDirection)) {\n console.error(\n `\u274C Invalid direction. Must be one of: ${validDirections.join(', ')}`\n );\n process.exit(1);\n }\n updates.direction = options.setDirection;\n console.log(`\u2705 Set direction to ${options.setDirection}`);\n }\n\n if (options.setConflictResolution) {\n const validStrategies = [\n 'newest_wins',\n 'linear_wins',\n 'stackmemory_wins',\n 'manual',\n ];\n if (!validStrategies.includes(options.setConflictResolution)) {\n console.error(\n `\u274C Invalid strategy. Must be one of: ${validStrategies.join(', ')}`\n );\n process.exit(1);\n }\n updates.conflictResolution = options.setConflictResolution;\n console.log(\n `\u2705 Set conflict resolution to ${options.setConflictResolution}`\n );\n }\n\n if (options.setQuietStart) {\n const hour = parseInt(options.setQuietStart);\n if (isNaN(hour) || hour < 0 || hour > 23) {\n console.error('\u274C Quiet start hour must be between 0 and 23');\n process.exit(1);\n }\n const currentConfig =\n configManager.loadConfig() || configManager.getDefaultConfig();\n updates.quietHours = {\n start: hour,\n end: currentConfig.quietHours?.end || 7,\n };\n console.log(`\u2705 Set quiet hours start to ${hour}:00`);\n }\n\n if (options.setQuietEnd) {\n const hour = parseInt(options.setQuietEnd);\n if (isNaN(hour) || hour < 0 || hour > 23) {\n console.error('\u274C Quiet end hour must be between 0 and 23');\n process.exit(1);\n }\n const currentConfig =\n configManager.loadConfig() || configManager.getDefaultConfig();\n updates.quietHours = {\n start: currentConfig.quietHours?.start || 22,\n end: hour,\n };\n console.log(`\u2705 Set quiet hours end to ${hour}:00`);\n }\n\n if (options.enable) {\n updates.enabled = true;\n console.log('\u2705 Auto-sync enabled');\n }\n\n if (options.disable) {\n updates.enabled = false;\n console.log('\u274C Auto-sync disabled');\n }\n\n if (Object.keys(updates).length > 0) {\n configManager.saveConfig(updates);\n console.log(\n '\\n\uD83D\uDCA1 Configuration updated. Restart auto-sync service to apply changes.'\n );\n } else if (!options.show) {\n console.log('\uD83D\uDCA1 Use --show to view current configuration');\n console.log('\uD83D\uDCA1 Use --help to see all configuration options');\n }\n } catch (error) {\n logger.error('Linear config command failed', error as Error);\n console.error('\u274C Config failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nprogram\n .command('update-check')\n .description('Check for StackMemory updates')\n .action(async () => {\n try {\n console.log('\uD83D\uDD0D Checking for updates...');\n await UpdateChecker.forceCheck(VERSION);\n } catch (error) {\n logger.error('Update check failed', error as Error);\n console.error('\u274C Update check failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nprogram\n .command('analytics')\n .description('Launch task analytics dashboard')\n .option('-p, --port <port>', 'Port for dashboard server', '3000')\n .option('-o, --open', 'Open dashboard in browser')\n .option('--export <format>', 'Export metrics (json|csv)')\n .option('--sync', 'Sync with Linear before launching')\n .option('--view', 'Show analytics in terminal')\n .action(async (options) => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n if (!existsSync(dbPath)) {\n console.log(\n '\u274C StackMemory not initialized. Run \"stackmemory init\" first.'\n );\n return;\n }\n\n if (options.view) {\n const { displayAnalyticsDashboard } = await import('./utils/viewer.js');\n await displayAnalyticsDashboard(projectRoot);\n return;\n }\n\n if (options.export) {\n const { AnalyticsService } =\n await import('../features/analytics/index.js');\n const service = new AnalyticsService(projectRoot);\n\n if (options.sync) {\n console.log('\uD83D\uDD04 Syncing with Linear...');\n await service.syncLinearTasks();\n }\n\n const state = await service.getDashboardState();\n\n if (options.export === 'csv') {\n console.log('\uD83D\uDCCA Exporting metrics as CSV...');\n // Convert to CSV format\n const tasks = state.recentTasks;\n const headers = [\n 'ID',\n 'Title',\n 'State',\n 'Priority',\n 'Created',\n 'Completed',\n ];\n const rows = tasks.map((t) => [\n t.id,\n t.title,\n t.state,\n t.priority,\n t.createdAt.toISOString(),\n t.completedAt?.toISOString() || '',\n ]);\n console.log(headers.join(','));\n rows.forEach((r) => console.log(r.join(',')));\n } else {\n console.log(JSON.stringify(state, null, 2));\n }\n\n service.close();\n return;\n }\n\n // Launch dashboard server\n console.log(\n `\uD83D\uDE80 Launching analytics dashboard on port ${options.port}...`\n );\n\n const express = (await import('express')).default;\n const { AnalyticsAPI } = await import('../features/analytics/index.js');\n const { createServer } = await import('http');\n\n const app = express();\n\n // Add error handling middleware\n app.use(\n (\n err: Error,\n _req: import('express').Request,\n res: import('express').Response,\n _next: import('express').NextFunction\n ) => {\n console.error('Express error:', err);\n res.status(500).json({ error: err.message });\n }\n );\n\n const analyticsAPI = new AnalyticsAPI(projectRoot);\n\n if (options.sync) {\n console.log('\uD83D\uDD04 Syncing with Linear...');\n const service = new (\n await import('../features/analytics/index.js')\n ).AnalyticsService(projectRoot);\n await service.syncLinearTasks();\n service.close();\n }\n\n app.use('/api/analytics', analyticsAPI.getRouter());\n\n // Serve the HTML dashboard\n app.get('/', async (req, res) => {\n // Try multiple paths for the dashboard HTML\n const possiblePaths = [\n join(projectRoot, 'src/features/analytics/dashboard.html'),\n join(projectRoot, 'dist/features/analytics/dashboard.html'),\n ];\n\n for (const dashboardPath of possiblePaths) {\n if (existsSync(dashboardPath)) {\n res.sendFile(dashboardPath);\n return;\n }\n }\n\n // Inline fallback dashboard\n res.send(`<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>StackMemory Analytics</title>\n <script src=\"https://cdn.jsdelivr.net/npm/chart.js\"></script>\n <style>\n * { margin: 0; padding: 0; box-sizing: border-box; }\n body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #1a1a2e; color: #eee; padding: 20px; }\n .container { max-width: 1200px; margin: 0 auto; }\n h1 { color: #667eea; margin-bottom: 20px; }\n .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 30px; }\n .card { background: #16213e; border-radius: 12px; padding: 20px; }\n .metric-value { font-size: 2.5em; font-weight: bold; color: #667eea; }\n .metric-label { color: #888; text-transform: uppercase; font-size: 0.8em; }\n .task-list { max-height: 400px; overflow-y: auto; }\n .task-item { padding: 10px; border-left: 3px solid #667eea; margin-bottom: 8px; background: #1a1a2e; }\n .task-item.completed { border-color: #22c55e; }\n .task-item.in_progress { border-color: #f59e0b; }\n .status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.8em; margin-right: 8px; }\n .status.completed { background: #22c55e30; color: #22c55e; }\n .status.in_progress { background: #f59e0b30; color: #f59e0b; }\n .status.todo { background: #667eea30; color: #667eea; }\n </style>\n</head>\n<body>\n <div class=\"container\">\n <h1>\uD83D\uDCCA StackMemory Analytics</h1>\n <div class=\"grid\" id=\"metrics\"></div>\n <div class=\"card\"><h3>Recent Tasks</h3><div class=\"task-list\" id=\"tasks\">Loading...</div></div>\n </div>\n <script>\n async function load() {\n const metrics = await fetch('/api/analytics/metrics').then(r => r.json());\n const tasks = await fetch('/api/analytics/tasks').then(r => r.json());\n \n document.getElementById('metrics').innerHTML = \\`\n <div class=\"card\"><div class=\"metric-label\">Total</div><div class=\"metric-value\">\\${metrics.data.metrics.totalTasks}</div></div>\n <div class=\"card\"><div class=\"metric-label\">Completed</div><div class=\"metric-value\">\\${metrics.data.metrics.completedTasks}</div></div>\n <div class=\"card\"><div class=\"metric-label\">In Progress</div><div class=\"metric-value\">\\${metrics.data.metrics.inProgressTasks}</div></div>\n <div class=\"card\"><div class=\"metric-label\">Completion</div><div class=\"metric-value\">\\${metrics.data.metrics.completionRate.toFixed(0)}%</div></div>\n \\`;\n \n document.getElementById('tasks').innerHTML = tasks.data.tasks.slice(0, 10).map(t => \\`\n <div class=\"task-item \\${t.state}\">\n <span class=\"status \\${t.state}\">\\${t.state}</span>\n <strong>\\${t.title}</strong>\n </div>\n \\`).join('');\n }\n load();\n setInterval(load, 30000);\n </script>\n</body>\n</html>`);\n });\n\n const server = createServer(app);\n analyticsAPI.setupWebSocket(server);\n\n server.listen(options.port, async () => {\n console.log(\n `\u2705 Analytics dashboard running at http://localhost:${options.port}`\n );\n\n if (options.open) {\n const { exec } = await import('child_process');\n const url = `http://localhost:${options.port}`;\n const command =\n process.platform === 'darwin'\n ? `open ${url}`\n : process.platform === 'win32'\n ? `start ${url}`\n : `xdg-open ${url}`;\n exec(command);\n }\n });\n\n process.on('SIGINT', () => {\n console.log('\\n\uD83D\uDC4B Shutting down analytics dashboard...');\n analyticsAPI.close();\n server.close();\n process.exit(0);\n });\n\n // Keep the process alive\n await new Promise(() => {});\n } catch (error) {\n logger.error('Analytics command failed', error as Error);\n console.error('\u274C Analytics failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\nprogram\n .command('progress')\n .description('Show current progress and recent changes')\n .action(async () => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n if (!existsSync(dbPath)) {\n console.log(\n '\u274C StackMemory not initialized. Run \"stackmemory init\" first.'\n );\n return;\n }\n\n const progress = new ProgressTracker(projectRoot);\n console.log(progress.getSummary());\n } catch (error) {\n logger.error('Failed to show progress', error as Error);\n console.error('\u274C Failed to show progress:', (error as Error).message);\n process.exit(1);\n }\n });\n\nprogram\n .command('mcp-server')\n .description('Start StackMemory MCP server for Claude Desktop')\n .option('-p, --project <path>', 'Project root directory', process.cwd())\n .action(async (options) => {\n try {\n const { runMCPServer } = await import('../integrations/mcp/server.js');\n\n // Set project root\n process.env.PROJECT_ROOT = options.project;\n\n console.log('\uD83D\uDE80 Starting StackMemory MCP Server...');\n console.log(` Project: ${options.project}`);\n console.log(` Version: ${VERSION}`);\n\n // Check for updates silently\n UpdateChecker.checkForUpdates(VERSION, true).catch(() => {});\n\n // Start the MCP server\n await runMCPServer();\n } catch (error) {\n logger.error('Failed to start MCP server', error as Error);\n console.error('\u274C MCP server failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n// Add test context command\nprogram\n .command('context:test')\n .description('Test context persistence by creating sample frames')\n .action(async () => {\n try {\n const projectRoot = process.cwd();\n const dbPath = join(projectRoot, '.stackmemory', 'context.db');\n\n if (!existsSync(dbPath)) {\n console.log(\n '\u274C StackMemory not initialized. Run \"stackmemory init\" first.'\n );\n return;\n }\n\n const db = new Database(dbPath);\n const frameManager = new FrameManager(db, 'cli-project');\n\n // Create test frames\n console.log('\uD83D\uDCDD Creating test context frames...');\n\n const rootFrame = frameManager.createFrame({\n type: 'task',\n name: 'Test Session',\n inputs: { test: true, timestamp: new Date().toISOString() },\n });\n\n const taskFrame = frameManager.createFrame({\n type: 'subtask',\n name: 'Sample Task',\n inputs: { description: 'Testing context persistence' },\n parentFrameId: rootFrame,\n });\n\n const commandFrame = frameManager.createFrame({\n type: 'tool_scope',\n name: 'test-command',\n inputs: { args: ['--test'] },\n parentFrameId: taskFrame,\n });\n\n // Add some events\n frameManager.addEvent(\n 'observation',\n {\n message: 'Test event recorded',\n },\n commandFrame\n );\n\n console.log('\u2705 Test frames created!');\n console.log(`\uD83D\uDCCA Stack depth: ${frameManager.getStackDepth()}`);\n console.log(\n `\uD83D\uDD04 Active frames: ${frameManager.getActiveFramePath().length}`\n );\n\n // Close one frame to test state changes\n frameManager.closeFrame(commandFrame);\n console.log(\n `\uD83D\uDCCA After closing command frame: depth = ${frameManager.getStackDepth()}`\n );\n\n db.close();\n } catch (error) {\n logger.error('Test context failed', error as Error);\n console.error('\u274C Test failed:', (error as Error).message);\n process.exit(1);\n }\n });\n\n// Register project management commands\n// Register command modules\nregisterOnboardingCommand(program);\nregisterProjectCommands(program);\nregisterWorktreeCommands(program);\n\n// Register Linear integration commands\nregisterLinearCommands(program);\nregisterLinearTestCommand(program);\n\n// Register session management commands\nprogram.addCommand(createSessionCommands());\n\n// Register webhook command\nprogram.addCommand(webhookCommand());\n\n// Register enhanced CLI commands\nprogram.addCommand(createTaskCommands());\nprogram.addCommand(createSearchCommand());\nprogram.addCommand(createLogCommand());\nprogram.addCommand(createContextCommands());\nprogram.addCommand(createConfigCommand());\nprogram.addCommand(createAgentCommand());\nprogram.addCommand(createHandoffCommand());\n\n// Auto-detect current project on startup\nif (process.argv.length > 2) {\n const manager = ProjectManager.getInstance();\n manager.detectProject().catch(() => {\n // Silently fail if not in a project directory\n });\n}\n\n// Only parse when running as main module (not when imported for testing)\nconst isMainModule =\n import.meta.url === `file://${process.argv[1]}` ||\n process.argv[1]?.endsWith('/stackmemory') ||\n process.argv[1]?.endsWith('index.ts') ||\n process.argv[1]?.includes('tsx');\n\nif (isMainModule) {\n program.parse();\n}\n\nexport { program };\n"],
|
|
5
5
|
"mappings": ";AAMA,SAAS,eAAe;AACxB,SAAS,cAAc;AACvB,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB,sBAAsB;AAC/C,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,+BAA+B;AACxC,SAAS,8BAA8B;AACvC,SAAS,iCAAiC;AAC1C,SAAS,6BAA6B;AACtC,SAAS,gCAAgC;AACzC,SAAS,iCAAiC;AAC1C,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AACpC,SAAS,wBAAwB;AACjC,SAAS,6BAA6B;AACtC,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,4BAA4B;AACrC,SAAS,sBAAsB;AAC/B,OAAO,cAAc;AACrB,SAAS,YAAY;AACrB,SAAS,YAAY,iBAAiB;AAEtC,MAAM,UAAU;AAGhB,cAAc,gBAAgB,SAAS,IAAI,EAAE,MAAM,MAAM;AAEzD,CAAC;AAED,QACG,KAAK,aAAa,EAClB,YAAY,6CAA6C,EACzD,QAAQ,OAAO;AAElB,QACG,QAAQ,MAAM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AAGzC,IAAI,QAAQ,KAAK,SAAS,GAAG;AAC3B,QAAM,UAAU,eAAe,YAAY;AAC3C,UAAQ,cAAc,EAAE,MAAM,MAAM;AAAA,EAEpC,CAAC;AACH;AAGA,MAAM,eACJ,YAAY,QAAQ,UAAU,QAAQ,KAAK,CAAC,CAAC,MAC7C,QAAQ,KAAK,CAAC,GAAG,SAAS,cAAc,KACxC,QAAQ,KAAK,CAAC,GAAG,SAAS,UAAU,KACpC,QAAQ,KAAK,CAAC,GAAG,SAAS,KAAK;AAEjC,IAAI,cAAc;AAChB,UAAQ,MAAM;AAChB;",
|
|
6
6
|
"names": ["LinearSyncEngine", "DEFAULT_SYNC_CONFIG"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackmemoryai/stackmemory",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Lossless, project-scoped memory for AI tools",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.0.0",
|
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
"build:types": "tsc --emitDeclarationOnly --project tsconfig.build.json",
|
|
48
48
|
"lint": "eslint src/**/*.ts scripts/**/*.ts",
|
|
49
49
|
"lint:fix": "eslint src/**/*.ts scripts/**/*.ts --fix",
|
|
50
|
+
"lint:oxc": "oxlint src scripts",
|
|
51
|
+
"lint:fast": "oxlint src scripts && eslint src/**/*.ts scripts/**/*.ts",
|
|
50
52
|
"lint:autofix": "node scripts/development/fix-lint-loop.cjs",
|
|
51
53
|
"format": "prettier --write src/**/*.ts scripts/**/*.ts",
|
|
52
54
|
"test": "vitest",
|
|
@@ -126,6 +128,7 @@
|
|
|
126
128
|
"eslint-plugin-prettier": "^5.5.4",
|
|
127
129
|
"husky": "^9.1.7",
|
|
128
130
|
"lint-staged": "^16.2.7",
|
|
131
|
+
"oxlint": "^1.36.0",
|
|
129
132
|
"prettier": "^3.7.4",
|
|
130
133
|
"tsx": "^4.7.0",
|
|
131
134
|
"typescript": "^5.3.3",
|