@stackmemoryai/stackmemory 1.9.0 → 1.10.3
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/src/cli/commands/orchestrator.js +27 -6
- package/dist/src/cli/commands/ralph.js +43 -0
- package/dist/src/cli/commands/rules.js +250 -0
- package/dist/src/cli/commands/skill.js +406 -0
- package/dist/src/cli/index.js +64 -0
- package/dist/src/core/config/config-manager.js +2 -1
- package/dist/src/core/rules/built-in-rules.js +289 -0
- package/dist/src/core/rules/pr-review-rule.js +87 -0
- package/dist/src/core/rules/rule-engine.js +85 -0
- package/dist/src/core/rules/rule-store.js +99 -0
- package/dist/src/core/rules/types.js +4 -0
- package/dist/src/core/skills/index.js +21 -0
- package/dist/src/core/skills/skill-matcher.js +178 -0
- package/dist/src/core/skills/skill-registry.js +646 -0
- package/dist/src/core/skills/types.js +1 -47
- package/dist/src/core/storage/obsidian-vault-adapter.js +392 -0
- package/dist/src/integrations/mcp/handlers/skill-handlers.js +67 -167
- package/dist/src/integrations/mcp/server.js +2 -6
- package/dist/src/integrations/ralph/loopmax.js +488 -0
- package/package.json +2 -2
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
2
|
+
import { dirname as __pathDirname } from 'path';
|
|
3
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
4
|
+
const __dirname = __pathDirname(__filename);
|
|
5
|
+
import { spawn, execSync } from "child_process";
|
|
6
|
+
import { existsSync, mkdirSync, writeFileSync, appendFileSync } from "fs";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
import { tmpdir } from "os";
|
|
9
|
+
import { logger } from "../../core/monitoring/logger.js";
|
|
10
|
+
const STUCK_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
11
|
+
const LOOP_COOLDOWN_MS = 3e3;
|
|
12
|
+
const TMP_DRAFT_DIR = join(tmpdir(), "loopmax-drafts");
|
|
13
|
+
class LoopMaxRunner {
|
|
14
|
+
config;
|
|
15
|
+
state;
|
|
16
|
+
stateFile;
|
|
17
|
+
logFile;
|
|
18
|
+
activeProcess = null;
|
|
19
|
+
stopped = false;
|
|
20
|
+
workDir;
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.config = {
|
|
23
|
+
task: config.task,
|
|
24
|
+
criteria: config.criteria,
|
|
25
|
+
cwd: config.cwd || process.cwd(),
|
|
26
|
+
useWorktree: config.useWorktree ?? true,
|
|
27
|
+
maxStuckBeforeRespawn: config.maxStuckBeforeRespawn ?? 3,
|
|
28
|
+
maxLoops: config.maxLoops ?? 0,
|
|
29
|
+
commitEvery: config.commitEvery ?? 25,
|
|
30
|
+
model: config.model || "sonnet",
|
|
31
|
+
verbose: config.verbose ?? true
|
|
32
|
+
};
|
|
33
|
+
if (!existsSync(TMP_DRAFT_DIR)) {
|
|
34
|
+
mkdirSync(TMP_DRAFT_DIR, { recursive: true });
|
|
35
|
+
}
|
|
36
|
+
this.workDir = this.config.cwd;
|
|
37
|
+
this.stateFile = join(TMP_DRAFT_DIR, `state-${Date.now()}.json`);
|
|
38
|
+
this.logFile = join(TMP_DRAFT_DIR, `log-${Date.now()}.jsonl`);
|
|
39
|
+
this.state = {
|
|
40
|
+
task: this.config.task,
|
|
41
|
+
criteria: this.config.criteria,
|
|
42
|
+
startedAt: Date.now(),
|
|
43
|
+
loop: 0,
|
|
44
|
+
totalCommits: 0,
|
|
45
|
+
iterations: [],
|
|
46
|
+
status: "running"
|
|
47
|
+
};
|
|
48
|
+
this.saveState();
|
|
49
|
+
this.writeHookState();
|
|
50
|
+
}
|
|
51
|
+
/** Main entry — runs forever until criteria met or stopped */
|
|
52
|
+
async run() {
|
|
53
|
+
this.log(`LoopMax starting: ${this.config.task}`);
|
|
54
|
+
this.log(`Criteria: ${this.config.criteria}`);
|
|
55
|
+
this.log(`State: ${this.stateFile}`);
|
|
56
|
+
this.log(`Log: ${this.logFile}`);
|
|
57
|
+
if (this.config.useWorktree) {
|
|
58
|
+
await this.setupWorktree();
|
|
59
|
+
}
|
|
60
|
+
const cleanup = () => {
|
|
61
|
+
this.stopped = true;
|
|
62
|
+
this.commitAndSummarize("SIGINT received \u2014 saving progress");
|
|
63
|
+
if (this.activeProcess) {
|
|
64
|
+
this.activeProcess.kill("SIGTERM");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
process.on("SIGINT", cleanup);
|
|
68
|
+
process.on("SIGTERM", cleanup);
|
|
69
|
+
let consecutiveStuck = 0;
|
|
70
|
+
while (!this.stopped) {
|
|
71
|
+
if (this.config.maxLoops > 0 && this.state.loop >= this.config.maxLoops) {
|
|
72
|
+
this.log(`Max loops (${this.config.maxLoops}) reached. Stopping.`);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
this.state.loop++;
|
|
76
|
+
this.log(`
|
|
77
|
+
${"=".repeat(60)}`);
|
|
78
|
+
this.log(`LOOP ${this.state.loop} starting`);
|
|
79
|
+
this.log(`${"=".repeat(60)}`);
|
|
80
|
+
const iteration = await this.runOneLoop();
|
|
81
|
+
this.state.iterations.push(iteration);
|
|
82
|
+
if (iteration.stuck) {
|
|
83
|
+
consecutiveStuck++;
|
|
84
|
+
this.log(
|
|
85
|
+
`Stuck count: ${consecutiveStuck}/${this.config.maxStuckBeforeRespawn}`
|
|
86
|
+
);
|
|
87
|
+
if (consecutiveStuck >= this.config.maxStuckBeforeRespawn) {
|
|
88
|
+
this.log(
|
|
89
|
+
"Max stuck reached \u2014 committing, summarizing, respawning fresh"
|
|
90
|
+
);
|
|
91
|
+
this.commitAndSummarize(
|
|
92
|
+
`Stuck after ${consecutiveStuck} loops \u2014 saving checkpoint`
|
|
93
|
+
);
|
|
94
|
+
consecutiveStuck = 0;
|
|
95
|
+
}
|
|
96
|
+
} else {
|
|
97
|
+
consecutiveStuck = 0;
|
|
98
|
+
}
|
|
99
|
+
if (await this.checkCriteria()) {
|
|
100
|
+
this.log("ALL CRITERIA MET \u2014 loop complete!");
|
|
101
|
+
this.state.status = "completed";
|
|
102
|
+
this.commitAndSummarize("LoopMax complete \u2014 all criteria met");
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
this.saveState();
|
|
106
|
+
if (!this.stopped) {
|
|
107
|
+
this.log(
|
|
108
|
+
`Cooling down ${LOOP_COOLDOWN_MS / 1e3}s before next loop...`
|
|
109
|
+
);
|
|
110
|
+
await sleep(LOOP_COOLDOWN_MS);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (this.stopped) {
|
|
114
|
+
this.state.status = "stopped";
|
|
115
|
+
}
|
|
116
|
+
this.saveState();
|
|
117
|
+
this.printSummary();
|
|
118
|
+
process.removeListener("SIGINT", cleanup);
|
|
119
|
+
process.removeListener("SIGTERM", cleanup);
|
|
120
|
+
}
|
|
121
|
+
/** Run a single Claude Code loop iteration */
|
|
122
|
+
async runOneLoop() {
|
|
123
|
+
const iteration = {
|
|
124
|
+
loop: this.state.loop,
|
|
125
|
+
pid: 0,
|
|
126
|
+
startedAt: Date.now(),
|
|
127
|
+
exitCode: null,
|
|
128
|
+
commitsMade: 0,
|
|
129
|
+
stuck: false
|
|
130
|
+
};
|
|
131
|
+
const prompt = this.buildPrompt();
|
|
132
|
+
const draftFile = join(TMP_DRAFT_DIR, `prompt-loop-${this.state.loop}.md`);
|
|
133
|
+
writeFileSync(draftFile, prompt);
|
|
134
|
+
this.log(`Prompt saved to ${draftFile}`);
|
|
135
|
+
try {
|
|
136
|
+
const result = await this.spawnClaude(prompt);
|
|
137
|
+
iteration.pid = result.pid;
|
|
138
|
+
iteration.exitCode = result.exitCode;
|
|
139
|
+
iteration.stuck = result.stuck;
|
|
140
|
+
iteration.endedAt = Date.now();
|
|
141
|
+
iteration.commitsMade = this.autoCommit(
|
|
142
|
+
`loopmax: loop ${this.state.loop} (exit=${result.exitCode})`
|
|
143
|
+
);
|
|
144
|
+
this.state.totalCommits += iteration.commitsMade;
|
|
145
|
+
} catch (err) {
|
|
146
|
+
this.log(`Loop ${this.state.loop} error: ${err.message}`);
|
|
147
|
+
iteration.exitCode = -1;
|
|
148
|
+
iteration.endedAt = Date.now();
|
|
149
|
+
iteration.stuck = true;
|
|
150
|
+
iteration.commitsMade = this.autoCommit(
|
|
151
|
+
`loopmax: loop ${this.state.loop} crashed \u2014 saving progress`
|
|
152
|
+
);
|
|
153
|
+
this.state.totalCommits += iteration.commitsMade;
|
|
154
|
+
}
|
|
155
|
+
appendFileSync(this.logFile, JSON.stringify(iteration) + "\n");
|
|
156
|
+
return iteration;
|
|
157
|
+
}
|
|
158
|
+
/** Spawn claude -p with --dangerously-skip-permissions */
|
|
159
|
+
spawnClaude(prompt) {
|
|
160
|
+
return new Promise((resolve, reject) => {
|
|
161
|
+
const args = [
|
|
162
|
+
"-p",
|
|
163
|
+
prompt,
|
|
164
|
+
"--dangerously-skip-permissions",
|
|
165
|
+
"--output-format",
|
|
166
|
+
"text",
|
|
167
|
+
"--model",
|
|
168
|
+
this.config.model
|
|
169
|
+
];
|
|
170
|
+
this.log(`Spawning: claude ${args.slice(0, 4).join(" ")} ...`);
|
|
171
|
+
const child = spawn("claude", args, {
|
|
172
|
+
cwd: this.workDir,
|
|
173
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
174
|
+
env: {
|
|
175
|
+
...process.env,
|
|
176
|
+
LOOPMAX: "1",
|
|
177
|
+
LOOPMAX_LOOP: String(this.state.loop),
|
|
178
|
+
LOOPMAX_STATE: this.stateFile,
|
|
179
|
+
LOOPMAX_TASK: this.config.task,
|
|
180
|
+
LOOPMAX_CRITERIA: this.config.criteria,
|
|
181
|
+
LOOPMAX_MODEL: this.config.model
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
this.activeProcess = child;
|
|
185
|
+
let lastOutputAt = Date.now();
|
|
186
|
+
let stuck = false;
|
|
187
|
+
let output = "";
|
|
188
|
+
const stuckCheck = setInterval(() => {
|
|
189
|
+
if (Date.now() - lastOutputAt > STUCK_TIMEOUT_MS) {
|
|
190
|
+
this.log("Stuck detected (no output for 5min) \u2014 killing agent");
|
|
191
|
+
stuck = true;
|
|
192
|
+
child.kill("SIGTERM");
|
|
193
|
+
setTimeout(() => {
|
|
194
|
+
if (!child.killed) child.kill("SIGKILL");
|
|
195
|
+
}, 5e3);
|
|
196
|
+
}
|
|
197
|
+
}, 3e4);
|
|
198
|
+
child.stdout?.on("data", (data) => {
|
|
199
|
+
lastOutputAt = Date.now();
|
|
200
|
+
const text = data.toString();
|
|
201
|
+
output += text;
|
|
202
|
+
if (this.config.verbose) {
|
|
203
|
+
process.stdout.write(text);
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
child.stderr?.on("data", (data) => {
|
|
207
|
+
lastOutputAt = Date.now();
|
|
208
|
+
const text = data.toString();
|
|
209
|
+
if (this.config.verbose) {
|
|
210
|
+
process.stderr.write(text);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
child.on("error", (err) => {
|
|
214
|
+
clearInterval(stuckCheck);
|
|
215
|
+
this.activeProcess = null;
|
|
216
|
+
reject(err);
|
|
217
|
+
});
|
|
218
|
+
child.on("close", (code) => {
|
|
219
|
+
clearInterval(stuckCheck);
|
|
220
|
+
this.activeProcess = null;
|
|
221
|
+
const outputFile = join(
|
|
222
|
+
TMP_DRAFT_DIR,
|
|
223
|
+
`output-loop-${this.state.loop}.txt`
|
|
224
|
+
);
|
|
225
|
+
writeFileSync(outputFile, output);
|
|
226
|
+
resolve({
|
|
227
|
+
pid: child.pid || 0,
|
|
228
|
+
exitCode: code ?? -1,
|
|
229
|
+
stuck
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
/** Build the prompt for Claude Code */
|
|
235
|
+
buildPrompt() {
|
|
236
|
+
const priorContext = this.getPriorContext();
|
|
237
|
+
return [
|
|
238
|
+
`# Task`,
|
|
239
|
+
``,
|
|
240
|
+
this.config.task,
|
|
241
|
+
``,
|
|
242
|
+
`# Completion Criteria`,
|
|
243
|
+
``,
|
|
244
|
+
this.config.criteria,
|
|
245
|
+
``,
|
|
246
|
+
`# Mode: LoopMax`,
|
|
247
|
+
``,
|
|
248
|
+
`You are in LoopMax mode. Rules:`,
|
|
249
|
+
`1. DO NOT PLAN. Just start coding immediately.`,
|
|
250
|
+
`2. Run tests often. Fix what breaks. Repeat.`,
|
|
251
|
+
`3. Commit to git frequently to preserve your work.`,
|
|
252
|
+
`4. If tests pass and lint is clean, you're done.`,
|
|
253
|
+
`5. If you get stuck, commit what you have and describe the blocker.`,
|
|
254
|
+
`6. Save any drafts or experiments to /tmp/loopmax-drafts/`,
|
|
255
|
+
`7. Be aggressive \u2014 try things, break things, fix things.`,
|
|
256
|
+
`8. Do NOT ask for permission. Do NOT explain your reasoning at length.`,
|
|
257
|
+
`9. Prefer action over analysis. Code over comments.`,
|
|
258
|
+
``,
|
|
259
|
+
`# Working Directory`,
|
|
260
|
+
``,
|
|
261
|
+
this.workDir,
|
|
262
|
+
``,
|
|
263
|
+
priorContext ? `# Prior Context (from previous loops)
|
|
264
|
+
|
|
265
|
+
${priorContext}
|
|
266
|
+
` : "",
|
|
267
|
+
`# GO. No planning. Just start.`
|
|
268
|
+
].filter(Boolean).join("\n");
|
|
269
|
+
}
|
|
270
|
+
/** Get summary of what happened in prior loops */
|
|
271
|
+
getPriorContext() {
|
|
272
|
+
if (this.state.iterations.length === 0) return "";
|
|
273
|
+
const recent = this.state.iterations.slice(-3);
|
|
274
|
+
const lines = recent.map((it) => {
|
|
275
|
+
const duration = it.endedAt ? Math.round((it.endedAt - it.startedAt) / 1e3) : "?";
|
|
276
|
+
const status = it.stuck ? "STUCK" : it.exitCode === 0 ? "OK" : `EXIT=${it.exitCode}`;
|
|
277
|
+
return `- Loop ${it.loop}: ${status}, ${duration}s, ${it.commitsMade} commits${it.summary ? ` \u2014 ${it.summary}` : ""}`;
|
|
278
|
+
});
|
|
279
|
+
try {
|
|
280
|
+
const log = execSync("git log --oneline -5", {
|
|
281
|
+
cwd: this.workDir,
|
|
282
|
+
encoding: "utf-8",
|
|
283
|
+
timeout: 5e3
|
|
284
|
+
}).trim();
|
|
285
|
+
lines.push("", "Recent commits:", log);
|
|
286
|
+
} catch {
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
execSync("npm run test:run", {
|
|
290
|
+
cwd: this.workDir,
|
|
291
|
+
stdio: "pipe",
|
|
292
|
+
timeout: 12e4
|
|
293
|
+
});
|
|
294
|
+
lines.push("", "Tests: ALL PASSING");
|
|
295
|
+
} catch (err) {
|
|
296
|
+
const stderr = (err instanceof Error && "stderr" in err && err.stderr != null ? String(err.stderr) : "") || "";
|
|
297
|
+
const lastLines = stderr.split("\n").slice(-10).join("\n");
|
|
298
|
+
lines.push("", "Tests: FAILING", lastLines);
|
|
299
|
+
}
|
|
300
|
+
return lines.join("\n");
|
|
301
|
+
}
|
|
302
|
+
/** Check if completion criteria are met */
|
|
303
|
+
async checkCriteria() {
|
|
304
|
+
try {
|
|
305
|
+
execSync("npm run test:run", {
|
|
306
|
+
cwd: this.workDir,
|
|
307
|
+
stdio: "pipe",
|
|
308
|
+
timeout: 12e4
|
|
309
|
+
});
|
|
310
|
+
execSync("npm run lint", {
|
|
311
|
+
cwd: this.workDir,
|
|
312
|
+
stdio: "pipe",
|
|
313
|
+
timeout: 6e4
|
|
314
|
+
});
|
|
315
|
+
execSync("npm run build", {
|
|
316
|
+
cwd: this.workDir,
|
|
317
|
+
stdio: "pipe",
|
|
318
|
+
timeout: 6e4
|
|
319
|
+
});
|
|
320
|
+
return true;
|
|
321
|
+
} catch {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/** Auto-commit any changes in the working directory */
|
|
326
|
+
autoCommit(message) {
|
|
327
|
+
try {
|
|
328
|
+
const status = execSync("git status --porcelain", {
|
|
329
|
+
cwd: this.workDir,
|
|
330
|
+
encoding: "utf-8",
|
|
331
|
+
timeout: 1e4
|
|
332
|
+
}).trim();
|
|
333
|
+
if (!status) return 0;
|
|
334
|
+
execSync("git add -A", {
|
|
335
|
+
cwd: this.workDir,
|
|
336
|
+
stdio: "pipe",
|
|
337
|
+
timeout: 1e4
|
|
338
|
+
});
|
|
339
|
+
execSync(`git commit -m "${message.replace(/"/g, '\\"')}"`, {
|
|
340
|
+
cwd: this.workDir,
|
|
341
|
+
stdio: "pipe",
|
|
342
|
+
timeout: 1e4,
|
|
343
|
+
env: {
|
|
344
|
+
...process.env,
|
|
345
|
+
GIT_AUTHOR_NAME: "LoopMax",
|
|
346
|
+
GIT_COMMITTER_NAME: "LoopMax"
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
this.log(`Committed: ${message}`);
|
|
350
|
+
return 1;
|
|
351
|
+
} catch {
|
|
352
|
+
return 0;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
/** Commit current state and write a summary */
|
|
356
|
+
commitAndSummarize(reason) {
|
|
357
|
+
this.log(`Checkpoint: ${reason}`);
|
|
358
|
+
const summaryFile = join(
|
|
359
|
+
TMP_DRAFT_DIR,
|
|
360
|
+
`summary-loop-${this.state.loop}.md`
|
|
361
|
+
);
|
|
362
|
+
const summary = [
|
|
363
|
+
`# LoopMax Checkpoint`,
|
|
364
|
+
``,
|
|
365
|
+
`**Reason:** ${reason}`,
|
|
366
|
+
`**Loop:** ${this.state.loop}`,
|
|
367
|
+
`**Total commits:** ${this.state.totalCommits}`,
|
|
368
|
+
`**Elapsed:** ${Math.round((Date.now() - this.state.startedAt) / 1e3)}s`,
|
|
369
|
+
``,
|
|
370
|
+
`## Task`,
|
|
371
|
+
this.config.task,
|
|
372
|
+
``,
|
|
373
|
+
`## Status`,
|
|
374
|
+
this.state.iterations.slice(-3).map((it) => {
|
|
375
|
+
const status = it.stuck ? "STUCK" : it.exitCode === 0 ? "OK" : `EXIT=${it.exitCode}`;
|
|
376
|
+
return `- Loop ${it.loop}: ${status}`;
|
|
377
|
+
}).join("\n")
|
|
378
|
+
].join("\n");
|
|
379
|
+
writeFileSync(summaryFile, summary);
|
|
380
|
+
this.autoCommit(`loopmax: checkpoint \u2014 ${reason}`);
|
|
381
|
+
this.saveState();
|
|
382
|
+
}
|
|
383
|
+
/** Set up a git worktree for isolated work */
|
|
384
|
+
async setupWorktree() {
|
|
385
|
+
const branch = `loopmax/${Date.now()}`;
|
|
386
|
+
const worktreePath = join(tmpdir(), `loopmax-wt-${Date.now()}`);
|
|
387
|
+
this.log(`Creating worktree at ${worktreePath} on branch ${branch}`);
|
|
388
|
+
try {
|
|
389
|
+
execSync(`git worktree add -b "${branch}" "${worktreePath}"`, {
|
|
390
|
+
cwd: this.config.cwd,
|
|
391
|
+
stdio: "pipe",
|
|
392
|
+
timeout: 3e4
|
|
393
|
+
});
|
|
394
|
+
this.workDir = worktreePath;
|
|
395
|
+
this.state.worktreePath = worktreePath;
|
|
396
|
+
this.state.worktreeBranch = branch;
|
|
397
|
+
if (existsSync(join(worktreePath, "package.json"))) {
|
|
398
|
+
this.log("Installing dependencies in worktree...");
|
|
399
|
+
try {
|
|
400
|
+
execSync("npm install", {
|
|
401
|
+
cwd: worktreePath,
|
|
402
|
+
stdio: "pipe",
|
|
403
|
+
timeout: 12e4
|
|
404
|
+
});
|
|
405
|
+
} catch {
|
|
406
|
+
this.log("npm install failed \u2014 continuing anyway");
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
this.log(`Worktree ready: ${worktreePath}`);
|
|
410
|
+
} catch (err) {
|
|
411
|
+
this.log(`Worktree creation failed: ${err.message}`);
|
|
412
|
+
this.log("Falling back to working in current directory");
|
|
413
|
+
this.config.useWorktree = false;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
/** Clean up worktree */
|
|
417
|
+
async cleanup() {
|
|
418
|
+
if (this.state.worktreePath && existsSync(this.state.worktreePath)) {
|
|
419
|
+
this.log(`Cleaning up worktree: ${this.state.worktreePath}`);
|
|
420
|
+
try {
|
|
421
|
+
execSync(`git worktree remove "${this.state.worktreePath}" --force`, {
|
|
422
|
+
cwd: this.config.cwd,
|
|
423
|
+
stdio: "pipe",
|
|
424
|
+
timeout: 3e4
|
|
425
|
+
});
|
|
426
|
+
} catch {
|
|
427
|
+
this.log("Worktree cleanup failed \u2014 may need manual cleanup");
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
/** Save state to /tmp */
|
|
432
|
+
saveState() {
|
|
433
|
+
writeFileSync(this.stateFile, JSON.stringify(this.state, null, 2));
|
|
434
|
+
}
|
|
435
|
+
/** Write hook state so the Stop hook can respawn independently */
|
|
436
|
+
writeHookState() {
|
|
437
|
+
const hookState = {
|
|
438
|
+
task: this.config.task,
|
|
439
|
+
criteria: this.config.criteria,
|
|
440
|
+
cwd: this.workDir,
|
|
441
|
+
loop: this.state.loop,
|
|
442
|
+
startedAt: this.state.startedAt,
|
|
443
|
+
iterations: this.state.iterations,
|
|
444
|
+
model: this.config.model,
|
|
445
|
+
status: this.state.status
|
|
446
|
+
};
|
|
447
|
+
const hookStateFile = join(TMP_DRAFT_DIR, "hook-state.json");
|
|
448
|
+
writeFileSync(hookStateFile, JSON.stringify(hookState, null, 2));
|
|
449
|
+
}
|
|
450
|
+
/** Print final summary */
|
|
451
|
+
printSummary() {
|
|
452
|
+
const elapsed = Math.round((Date.now() - this.state.startedAt) / 1e3);
|
|
453
|
+
const successLoops = this.state.iterations.filter(
|
|
454
|
+
(i) => i.exitCode === 0
|
|
455
|
+
).length;
|
|
456
|
+
const stuckLoops = this.state.iterations.filter((i) => i.stuck).length;
|
|
457
|
+
console.log("\n" + "=".repeat(60));
|
|
458
|
+
console.log("LoopMax Summary");
|
|
459
|
+
console.log("=".repeat(60));
|
|
460
|
+
console.log(`Status: ${this.state.status}`);
|
|
461
|
+
console.log(`Total loops: ${this.state.loop}`);
|
|
462
|
+
console.log(`Successful: ${successLoops}`);
|
|
463
|
+
console.log(`Stuck: ${stuckLoops}`);
|
|
464
|
+
console.log(`Commits: ${this.state.totalCommits}`);
|
|
465
|
+
console.log(`Elapsed: ${elapsed}s`);
|
|
466
|
+
console.log(`State file: ${this.stateFile}`);
|
|
467
|
+
console.log(`Log file: ${this.logFile}`);
|
|
468
|
+
if (this.state.worktreePath) {
|
|
469
|
+
console.log(`Worktree: ${this.state.worktreePath}`);
|
|
470
|
+
console.log(`Branch: ${this.state.worktreeBranch}`);
|
|
471
|
+
}
|
|
472
|
+
console.log("=".repeat(60));
|
|
473
|
+
}
|
|
474
|
+
log(msg) {
|
|
475
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString().substring(11, 19);
|
|
476
|
+
const line = `[${ts}] [loopmax] ${msg}`;
|
|
477
|
+
if (this.config.verbose) {
|
|
478
|
+
console.log(line);
|
|
479
|
+
}
|
|
480
|
+
logger.info(msg, { component: "loopmax", loop: this.state.loop });
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
function sleep(ms) {
|
|
484
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
485
|
+
}
|
|
486
|
+
export {
|
|
487
|
+
LoopMaxRunner
|
|
488
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackmemoryai/stackmemory",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.3",
|
|
4
4
|
"description": "Lossless, project-scoped memory for AI coding tools. Durable context across sessions with 56 MCP tools, FTS5 search, conductor orchestrator, loop/watch monitoring, snapshot capture, pre-flight overlap checks, Claude/Codex/OpenCode wrappers, Linear sync, and automatic hooks.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.0.0",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"postinstall": "node scripts/install-claude-hooks-auto.js || true",
|
|
101
101
|
"init": "node dist/scripts/initialize.js",
|
|
102
102
|
"build": "rm -rf dist && node esbuild.config.js",
|
|
103
|
-
"typecheck": "
|
|
103
|
+
"typecheck": "node --max-old-space-size=8192 ./node_modules/.bin/tsc --project tsconfig.check.json",
|
|
104
104
|
"lint": "eslint 'src/**/*.ts' 'scripts/**/*.ts'",
|
|
105
105
|
"lint:fix": "eslint 'src/**/*.ts' 'scripts/**/*.ts' --fix --max-warnings=-1",
|
|
106
106
|
"lint:fast": "oxlint src scripts",
|