Skip to content

Commit 2300035

Browse files
author
LoopMax
committed
loopmax: auto-save after loop 1
1 parent 6f65124 commit 2300035

7,834 files changed

Lines changed: 2732452 additions & 712 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# LoopMax + Board + Obsidian — Setup Guide
2+
3+
Use StackMemory's three power features in any repo.
4+
5+
## Prerequisites
6+
7+
```bash
8+
npm install -g @stackmemoryai/stackmemory
9+
```
10+
11+
---
12+
13+
## 1. Obsidian Vault (context as wiki)
14+
15+
Create or pick an existing Obsidian vault, then configure:
16+
17+
```bash
18+
cd /path/to/your/repo
19+
mkdir -p .stackmemory
20+
cat > .stackmemory/config.yaml << 'EOF'
21+
version: "1.10.2"
22+
23+
obsidian:
24+
vaultPath: /path/to/your/obsidian/vault
25+
subdir: stackmemory
26+
watchRaw: true
27+
autoIndex: true
28+
EOF
29+
```
30+
31+
**What happens:**
32+
- `vault/stackmemory/frames/` — every frame auto-serialized as `.md` with YAML frontmatter + `[[wiki-links]]`
33+
- `vault/stackmemory/index.md` — auto-maintained index (frame counts, recent frames)
34+
- `vault/stackmemory/raw/` — drop web clipper `.md` files here, auto-ingested as frames
35+
- `vault/stackmemory/sessions/` — session summaries with backlinks
36+
37+
**Web Clipper setup:**
38+
1. Install [Obsidian Web Clipper](https://obsidian.md/clipper)
39+
2. Set clip destination to `vault/stackmemory/raw/`
40+
3. Clipped articles auto-ingest into StackMemory
41+
42+
**Open vault:** just open the vault folder in Obsidian. Graph view shows frame relationships.
43+
44+
---
45+
46+
## 2. Board (interactive Claude Code in browser)
47+
48+
```bash
49+
cd /path/to/your/repo
50+
stackmemory board
51+
```
52+
53+
Opens http://localhost:3456 with:
54+
- **Sidebar:** active sessions + conductor agent status cards
55+
- **Terminal:** xterm.js rendering live Claude Code stream-json output
56+
- **Input bar:** send messages to running agent's stdin
57+
58+
**Usage:**
59+
1. Click **+ NEW**
60+
2. Enter a prompt (e.g., "fix the auth bug in src/auth.ts")
61+
3. Pick model (sonnet/opus/haiku)
62+
4. Click **START** — Claude Code spawns, output streams live
63+
5. Send follow-up messages via input bar
64+
6. Click **KILL** to stop
65+
66+
**API (for scripting):**
67+
```bash
68+
# Create session
69+
curl -X POST http://localhost:3456/api/sessions \
70+
-H 'Content-Type: application/json' \
71+
-d '{"prompt":"fix failing tests","model":"sonnet"}'
72+
73+
# Send message to session
74+
curl -X POST http://localhost:3456/api/sessions/SESSION_ID/message \
75+
-H 'Content-Type: application/json' \
76+
-d '{"message":"now run the linter"}'
77+
78+
# List sessions
79+
curl http://localhost:3456/api/sessions
80+
81+
# List conductor agents
82+
curl http://localhost:3456/api/agents
83+
```
84+
85+
**Options:**
86+
```bash
87+
stackmemory board --port 8080 # custom port
88+
stackmemory board --no-open # don't auto-open browser
89+
```
90+
91+
---
92+
93+
## 3. LoopMax (autonomous agent loop)
94+
95+
### Option A: CLI runner (manages its own loop)
96+
97+
```bash
98+
cd /path/to/your/repo
99+
stackmemory ralph loopmax "fix all failing tests and lint errors" \
100+
--criteria "All tests pass, lint clean, build succeeds" \
101+
--model sonnet
102+
```
103+
104+
**Options:**
105+
```
106+
-c, --criteria <text> Completion criteria (default: "All tests pass, lint clean, build succeeds")
107+
--no-worktree Work in current dir instead of isolated git worktree
108+
--max-loops <n> Max iterations, 0=infinite (default: 0)
109+
--max-stuck <n> Respawn fresh after N stuck loops (default: 3)
110+
--commit-every <n> Auto-commit frequency in tool calls (default: 25)
111+
--model <model> Claude model: sonnet, opus, haiku (default: sonnet)
112+
```
113+
114+
**What happens:**
115+
1. Creates git worktree in `/tmp/loopmax-wt-*` (isolated branch)
116+
2. Spawns `claude -p --dangerously-skip-permissions`
117+
3. Agent codes, tests, fixes — no planning, just execution
118+
4. Auto-commits after every loop
119+
5. If stuck for 5min → kills agent, 3 stuck in a row → checkpoint + respawn
120+
6. After each loop: runs `test:run + lint + build` — stops when all pass
121+
7. Drafts/logs saved to `/tmp/loopmax-drafts/`
122+
123+
### Option B: Hook-driven (each session is one loop)
124+
125+
Set env vars and run Claude directly — the Stop hook auto-respawns:
126+
127+
```bash
128+
LOOPMAX=1 \
129+
LOOPMAX_TASK="fix all tests" \
130+
LOOPMAX_CRITERIA="tests pass, lint clean, build succeeds" \
131+
LOOPMAX_MODEL=sonnet \
132+
claude -p "fix all failing tests" --dangerously-skip-permissions
133+
```
134+
135+
**Hooks (auto-installed in `~/.claude/settings.json`):**
136+
- `loopmax-respawn.js` (Stop): when session ends, checks criteria, respawns if not met
137+
- `loopmax-autocommit.js` (PostToolUse): auto-commits every 25 tool calls
138+
139+
**State files:**
140+
- `/tmp/loopmax-drafts/hook-state.json` — loop state for respawn
141+
- `/tmp/loopmax-drafts/prompt-loop-N.md` — prompt sent to each loop
142+
- `/tmp/loopmax-drafts/output-loop-N.txt` — output from each loop
143+
- `/tmp/loopmax-drafts/summary-loop-N.md` — checkpoint summaries
144+
145+
---
146+
147+
## All Three Together
148+
149+
```bash
150+
# 1. Configure Obsidian vault
151+
cat > .stackmemory/config.yaml << 'EOF'
152+
version: "1.10.2"
153+
obsidian:
154+
vaultPath: ~/obsidian-vault
155+
EOF
156+
157+
# 2. Start the board (background)
158+
stackmemory board &
159+
160+
# 3. Launch LoopMax
161+
stackmemory ralph loopmax "implement the user auth feature" \
162+
--criteria "All tests pass, lint clean, build succeeds" \
163+
--model sonnet
164+
```
165+
166+
- **Board** at http://localhost:3456 shows LoopMax progress
167+
- **Obsidian** vault fills with frame `.md` files as context is captured
168+
- **LoopMax** loops autonomously until criteria met, committing progress to git
169+
- **Web clipper** drops into `raw/` → auto-ingested as frames → visible in Obsidian graph
170+
171+
---
172+
173+
## Troubleshooting
174+
175+
| Issue | Fix |
176+
|---|---|
177+
| `Board server not found` | Run from repo root or install stackmemory globally |
178+
| Obsidian vault not initializing | Check `vaultPath` exists and is absolute path |
179+
| LoopMax not respawning | Verify `LOOPMAX=1` env var is set, check `/tmp/loopmax-drafts/hook-state.json` |
180+
| Hooks not firing | Run `cat ~/.claude/settings.json | grep loopmax` to verify hooks are registered |
181+
| Tests timing out in LoopMax | Add `--max-stuck 2` to respawn faster |

0 commit comments

Comments
 (0)