@graypark/loophaus 2.0.0

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.
Files changed (39) hide show
  1. package/.claude-plugin/plugin.json +11 -0
  2. package/LICENSE +21 -0
  3. package/README.ko.md +358 -0
  4. package/README.md +282 -0
  5. package/bin/install.mjs +10 -0
  6. package/bin/loophaus.mjs +192 -0
  7. package/bin/uninstall.mjs +233 -0
  8. package/codex/commands/cancel-ralph.md +30 -0
  9. package/codex/commands/ralph-loop.md +73 -0
  10. package/commands/cancel-ralph.md +23 -0
  11. package/commands/help.md +96 -0
  12. package/commands/loop-plan.md +55 -0
  13. package/commands/loop-pulse.md +38 -0
  14. package/commands/loop-stop.md +29 -0
  15. package/commands/loop.md +17 -0
  16. package/commands/ralph-loop.md +18 -0
  17. package/core/engine.mjs +84 -0
  18. package/core/event-logger.mjs +37 -0
  19. package/core/loop.schema.json +29 -0
  20. package/hooks/hooks.json +15 -0
  21. package/hooks/stop-hook.mjs +79 -0
  22. package/lib/paths.mjs +91 -0
  23. package/lib/state.mjs +46 -0
  24. package/lib/stop-hook-core.mjs +162 -0
  25. package/package.json +57 -0
  26. package/platforms/claude-code/adapter.mjs +20 -0
  27. package/platforms/claude-code/installer.mjs +165 -0
  28. package/platforms/codex-cli/adapter.mjs +20 -0
  29. package/platforms/codex-cli/installer.mjs +131 -0
  30. package/platforms/kiro-cli/adapter.mjs +21 -0
  31. package/platforms/kiro-cli/installer.mjs +115 -0
  32. package/scripts/setup-ralph-loop.sh +145 -0
  33. package/skills/ralph-claude-cancel/SKILL.md +23 -0
  34. package/skills/ralph-claude-interview/SKILL.md +178 -0
  35. package/skills/ralph-claude-loop/SKILL.md +101 -0
  36. package/skills/ralph-claude-orchestrator/SKILL.md +129 -0
  37. package/skills/ralph-interview/SKILL.md +275 -0
  38. package/skills/ralph-orchestrator/SKILL.md +254 -0
  39. package/store/state-store.mjs +80 -0
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: ralph-claude-cancel
3
+ description: "Cancel the active Loop in Claude Code"
4
+ ---
5
+
6
+ # Cancel Loop (Claude Code)
7
+
8
+ To cancel the loop:
9
+
10
+ 1. Check if `.loophaus/state.json` exists using Bash: `test -f .loophaus/state.json && echo "EXISTS" || echo "NOT_FOUND"`
11
+ - If not found, also check legacy path: `test -f .claude/ralph-loop.local.md && echo "LEGACY" || echo "NOT_FOUND"`
12
+
13
+ 2. **If NOT_FOUND** on both: Say "No active loop found."
14
+
15
+ 3. **If EXISTS** (.loophaus/state.json):
16
+ - Read `.loophaus/state.json` to get the current iteration number from `currentIteration`
17
+ - Remove the file using Bash: `rm .loophaus/state.json`
18
+ - Report: "Stopped loop at iteration N."
19
+
20
+ 4. **If LEGACY** (.claude/ralph-loop.local.md):
21
+ - Read `.claude/ralph-loop.local.md` to get the iteration number from the `iteration:` field
22
+ - Remove the file using Bash: `rm .claude/ralph-loop.local.md`
23
+ - Report: "Stopped loop at iteration N. (migrated from legacy path)"
@@ -0,0 +1,178 @@
1
+ ---
2
+ name: ralph-claude-interview
3
+ description: "Claude Code interview that generates PRD, activates the official loop stop hook, and starts working immediately. Uses Skill tool for loop invocation."
4
+ ---
5
+
6
+ # Loop Interview (Claude Code)
7
+
8
+ You are an expert at generating PRD-driven Loop tasks for Claude Code.
9
+ Interview the user, generate prd.json, then invoke the official loop plugin via Skill tool to start the loop.
10
+
11
+ ## Core Principles
12
+
13
+ - **PRD-driven**: prd.json (ralph-skills compatible) tracks all stories
14
+ - **progress.txt**: Append-only log with Codebase Patterns section
15
+ - **One story per iteration**: Each loop cycle implements ONE story
16
+ - **Self-contained stop hook**: Uses loophaus's own bash stop hook
17
+ - **Skill tool invocation**: Start the loop via the Skill tool (`loophaus:ralph-loop`)
18
+
19
+ ## Interview Process
20
+
21
+ Ask **concise questions** for missing items. Max 3-5 per round, one round only.
22
+
23
+ | Category | What to confirm |
24
+ | ------------------------- | ---------------------------------------------------- |
25
+ | **Scope** | Single feature? Multi-file? Full refactor? |
26
+ | **Success criteria** | What counts as "done"? |
27
+ | **Verification commands** | `npx tsc --noEmit`, `npm test`, `npm run lint`, etc. |
28
+ | **References** | Existing code, files, or patterns to follow? |
29
+ | **Priority** | P1/P2 or other tiers? |
30
+ | **Constraints** | Must not break existing tests? Library restrictions? |
31
+ | **When stuck** | Document? Skip? Suggest alternative? |
32
+ | **Parallelism potential** | Multiple services? Independent file groups? |
33
+
34
+ ## Phase Design
35
+
36
+ - **Research needed** → Phase 1: Analysis, Phase 2: Implementation
37
+ - **8+ items** → Split by nature (P1/P2, frontend/backend)
38
+ - **Dependencies** → Prerequisite work first
39
+ - **5 or fewer** → Single phase fine
40
+
41
+ ### Parallelism (ralph-claude-orchestrator)
42
+
43
+ | Factor | Score |
44
+ | ------------------------------- | ----- |
45
+ | Files span 3+ dirs | +2 |
46
+ | Items independent | +2 |
47
+ | Need full context | -2 |
48
+ | Order matters | -2 |
49
+ | 10+ similar items | +1 |
50
+ | Cross-file understanding needed | -1 |
51
+ | Multiple services | +3 |
52
+
53
+ Score >= 3: Use parallel Agent tool subagents in the prompt.
54
+
55
+ ### max-iterations
56
+
57
+ | Task | Iterations |
58
+ | ---------------- | ---------- |
59
+ | Research only | 3-5 |
60
+ | 1-3 simple fixes | 5-10 |
61
+ | 4-7 medium items | 10-20 |
62
+ | 8+ large items | 20-30 |
63
+ | TDD feature | 15-30 |
64
+
65
+ Formula: `story_count x 2 + 5`
66
+
67
+ ## PRD Format: prd.json
68
+
69
+ ralph-skills compatible format:
70
+
71
+ ```json
72
+ {
73
+ "project": "[Name]",
74
+ "description": "[Description]",
75
+ "userStories": [
76
+ {
77
+ "id": "US-001",
78
+ "title": "[Title]",
79
+ "description": "As a [user], I want [feature] so that [benefit]",
80
+ "acceptanceCriteria": ["Criterion 1", "Typecheck passes"],
81
+ "priority": 1,
82
+ "passes": false,
83
+ "notes": ""
84
+ }
85
+ ]
86
+ }
87
+ ```
88
+
89
+ ### Story Rules
90
+
91
+ - Each story completable in ONE iteration
92
+ - Dependencies ordered by priority (schema → backend → UI)
93
+ - Acceptance criteria must be verifiable, not vague
94
+ - Always include "Typecheck passes" or equivalent
95
+
96
+ ## Rules
97
+
98
+ - No subjective criteria ("works well", "looks clean")
99
+ - At least one automated verification check per prompt
100
+ - Every prompt has a "When Stuck" section
101
+ - Max 8 items per phase
102
+ - Always use prd.json format
103
+ - Default promise: COMPLETE
104
+ - Always overwrite existing prd.json/progress.txt without asking
105
+
106
+ ## Conversation Flow
107
+
108
+ ```
109
+ [User] → /loop-plan "build X"
110
+ [Assistant] → Interview questions (skip if enough context)
111
+ [User] → Answers
112
+ [Assistant] → Shows PRD briefly, asks "Ready?"
113
+ [User] → "y"
114
+ [Assistant] → Writes files + invokes loop via Skill tool
115
+ ```
116
+
117
+ ### Quick-Run
118
+
119
+ If user includes "run immediately", "just do it", "바로 실행", "바로 시작", "--run":
120
+ Skip "Ready?" prompt. Write files and invoke immediately.
121
+
122
+ ## Activation Sequence
123
+
124
+ When user confirms, execute ALL steps in ONE response:
125
+
126
+ ### Step 1: Write prd.json via Bash
127
+
128
+ Always overwrite. Do NOT ask about existing files.
129
+
130
+ ```bash
131
+ cat > prd.json << 'EOF'
132
+ { ... generated PRD ... }
133
+ EOF
134
+ ```
135
+
136
+ ### Step 2: Write progress.txt via Bash
137
+
138
+ ```bash
139
+ cat > progress.txt << 'EOF'
140
+ ## Codebase Patterns
141
+ (none yet)
142
+ EOF
143
+ ```
144
+
145
+ ### Step 3: Invoke loop via Skill tool
146
+
147
+ This is the critical step. You MUST use the Skill tool to start the loop:
148
+
149
+ ```
150
+ Skill tool call:
151
+ skill: "loophaus:ralph-loop"
152
+ args: "Read prd.json for task plan. Read progress.txt for status (Codebase Patterns first). Pick highest priority story where passes is false. Implement that ONE story. Run verification: <VERIFY_CMD>. On failure: fix and retry, max 3. On success: commit 'feat: [Story ID] - [Title]'. Update prd.json passes to true. DISCOVERY PHASE: Review what you just built — did you find hidden complexity, missing edge cases, new dependencies, or broken assumptions? If YES: add new stories to prd.json (next sequential ID, passes: false), log discovery in progress.txt under Discoveries section, and increase maxIterations in .loophaus/state.json if needed (formula: current_iteration + remaining*2 + 3). If NO: just append learnings to progress.txt. If ALL stories (including new ones) pass: <promise>COMPLETE</promise>. When stuck: set notes in prd.json, skip to next." --max-iterations <N> --completion-promise "COMPLETE"
153
+ ```
154
+
155
+ Replace `<VERIFY_CMD>` and `<N>` with actual values.
156
+
157
+ ### IMPORTANT: Actually invoke the Skill tool
158
+
159
+ After writing prd.json and progress.txt, you MUST make a real Skill tool call.
160
+
161
+ WRONG:
162
+
163
+ - Printing the /loop command as text
164
+ - Writing files and saying "ready"
165
+ - Describing what would happen
166
+
167
+ RIGHT:
168
+
169
+ - Use the Skill tool with skill="loophaus:ralph-loop" and the generated args
170
+ - This starts the loop — loophaus's stop hook takes over from there
171
+
172
+ loophaus will:
173
+
174
+ 1. Run the setup script (creates `.loophaus/state.json`)
175
+ 2. Inject the prompt into the session
176
+ 3. You start working on US-001
177
+ 4. When you finish and try to exit, the stop hook re-injects the prompt
178
+ 5. You pick US-002, and so on until `<promise>COMPLETE</promise>`
@@ -0,0 +1,101 @@
1
+ ---
2
+ name: ralph-claude-loop
3
+ description: "Start a PRD-driven Loop in Claude Code. Reads prd.json + progress.txt each iteration. Uses the official loop stop hook."
4
+ ---
5
+
6
+ # Loop (Claude Code)
7
+
8
+ Start a Loop optimized for Claude Code. This skill sets up the loop state, activates the official stop hook, and begins working on the first pending story from prd.json.
9
+
10
+ ## Prerequisites
11
+
12
+ - The `loophaus` plugin must be installed
13
+ - A `prd.json` file must exist in the project root (generate one with `/loop-plan`)
14
+
15
+ ## How It Works
16
+
17
+ 1. This skill writes `.loophaus/state.json` (the state file)
18
+ 2. loophaus's stop hook reads this file and intercepts session exits
19
+ 3. Each iteration follows the **Implement → Discover → Plan → Continue** cycle
20
+ 4. When all stories pass: output `<promise>COMPLETE</promise>`
21
+
22
+ ### Iteration Cycle (per story)
23
+
24
+ ```
25
+ ┌─ IMPLEMENT ─────────────────────────────┐
26
+ │ Pick next story → implement → verify │
27
+ └─────────────────────┬───────────────────┘
28
+
29
+ ┌─ DISCOVER ──────────────────────────────┐
30
+ │ Review what you just built. │
31
+ │ Did you find: │
32
+ │ - Hidden complexity? │
33
+ │ - Missing edge cases? │
34
+ │ - New dependencies? │
35
+ │ - Broken assumptions from the PRD? │
36
+ └─────────────────────┬───────────────────┘
37
+
38
+ ┌─ UPDATE PRD ────────────────────────────┐
39
+ │ If discoveries found: │
40
+ │ 1. Add new stories to prd.json │
41
+ │ 2. Log discoveries in progress.txt │
42
+ │ 3. Adjust max_iterations if needed │
43
+ │ If nothing new: skip │
44
+ └─────────────────────┬───────────────────┘
45
+
46
+ ┌─ CONTINUE ──────────────────────────────┐
47
+ │ Mark current story done → next story │
48
+ └─────────────────────────────────────────┘
49
+ ```
50
+
51
+ ## Activation
52
+
53
+ Run the setup script to create the state file:
54
+
55
+ ```!
56
+ mkdir -p .loophaus && cat > .loophaus/state.json << 'LOOP_STATE'
57
+ {
58
+ "active": true,
59
+ "prompt": "Read prd.json for the task plan. Read progress.txt for current status (check Codebase Patterns section first). Pick the highest priority user story where passes is false. Implement that ONE story. Run verification: $VERIFY_CMD. On failure: read error, fix, retry up to 3 times. On success: commit with message feat: [Story ID] - [Story Title]. Update prd.json: set passes to true for the completed story. DISCOVERY PHASE — After completing the story, review what you just built: did implementation reveal hidden complexity not covered by existing stories? Are there missing edge cases, error handling, or integration points? Did you discover new dependencies or broken assumptions? Are there follow-up tasks needed for what you just built? If YES to any: add new user stories to prd.json with the next available ID (e.g. US-010), set passes: false, and set priority appropriately. Log the discovery in progress.txt under Discoveries section with rationale. If NO: skip, just append progress to progress.txt with learnings. If ALL stories (including newly added ones) have passes true, output <promise>COMPLETE</promise>. When stuck after 3 retries: set notes field in prd.json with error details, move to next story.",
60
+ "completionPromise": "COMPLETE",
61
+ "maxIterations": $MAX_ITERATIONS,
62
+ "currentIteration": 0,
63
+ "sessionId": ""
64
+ }
65
+ LOOP_STATE
66
+ ```
67
+
68
+ Replace `$MAX_ITERATIONS` with the desired limit and `$VERIFY_CMD` with the project's verification command.
69
+
70
+ After setup, immediately begin working:
71
+
72
+ 1. Read prd.json
73
+ 2. Pick the first story with `passes: false`
74
+ 3. Implement it — write real code, make real changes
75
+ 4. Run verification
76
+ 5. Commit
77
+ 6. **Discovery Phase** — review what you just built for hidden complexity, missing cases, new dependencies
78
+ 7. If discoveries found: add new stories to prd.json, log in progress.txt
79
+ 8. Update prd.json (mark current story done) and progress.txt
80
+ 9. The stop hook will re-inject this prompt for the next story
81
+
82
+ ### Discovery Phase Rules
83
+
84
+ - New stories MUST follow the same format (id, title, description, acceptanceCriteria, priority, passes: false)
85
+ - Use next sequential ID (if last is US-007, new ones start at US-008)
86
+ - Set priority relative to remaining work (urgent discoveries get lower priority number)
87
+ - Do NOT add trivial or cosmetic items — only genuinely missing functionality
88
+ - Log each discovery in progress.txt: what was found, why it matters, which story revealed it
89
+ - If adding stories increases scope significantly, update `maxIterations` in `.loophaus/state.json`
90
+
91
+ ### max_iterations Auto-Adjustment
92
+
93
+ When adding N new stories, update maxIterations:
94
+
95
+ ```
96
+ new_max = current_iteration + (remaining_stories + new_stories) * 2 + 3
97
+ ```
98
+
99
+ Only increase, never decrease. Update the value in `.loophaus/state.json`.
100
+
101
+ CRITICAL RULE: Only output `<promise>COMPLETE</promise>` when ALL stories in prd.json (including dynamically added ones) have `passes: true`. Do not output it prematurely.
@@ -0,0 +1,129 @@
1
+ ---
2
+ name: ralph-claude-orchestrator
3
+ description: "Multi-agent orchestration patterns for Loop in Claude Code. Uses the Agent tool for parallel subagent spawning."
4
+ ---
5
+
6
+ # Loop Orchestrator — Multi-Agent Patterns (Claude Code)
7
+
8
+ Orchestration patterns optimized for Claude Code's Agent tool. Analyzes tasks and recommends the best combination of sequential loops and parallel subagents.
9
+
10
+ ## Subagent Configuration (Claude Code Agent Tool)
11
+
12
+ ```
13
+ Agent tool parameters:
14
+ - description: "short task description"
15
+ - prompt: "detailed instructions"
16
+ - subagent_type: "general-purpose" | "Explore" | "Plan" | "coder-fe" | "coder-be"
17
+ - isolation: "worktree" (gives agent an isolated repo copy)
18
+ - run_in_background: true (for parallel execution)
19
+ ```
20
+
21
+ **Best practices:**
22
+
23
+ - Use `subagent_type: "Explore"` for read-only scanning — faster and safer
24
+ - Use `isolation: "worktree"` when agents write to files — prevents merge conflicts
25
+ - Launch parallel agents in a single message with multiple Agent tool calls
26
+ - Use `run_in_background: true` for truly independent work streams
27
+
28
+ ## Orchestration Patterns
29
+
30
+ ### Pattern 1: Parallel Explore then Sequential Implement
31
+
32
+ Best for: Large codebases where you need to understand before you change.
33
+
34
+ ```
35
+ Phase 1 (Parallel Subagents via Agent tool):
36
+ ├── Agent "fe-scan" (Explore, background): Scan src/frontend/** → .loophaus/reports/frontend.md
37
+ ├── Agent "be-scan" (Explore, background): Scan src/backend/** → .loophaus/reports/backend.md
38
+ └── Agent "db-scan" (Explore, background): Scan src/db/** → .loophaus/reports/db.md
39
+
40
+ Phase 2 (Loop):
41
+ └── Read merged reports → implement fixes story by story via prd.json
42
+ ```
43
+
44
+ ### Pattern 2: Divide by Ownership
45
+
46
+ Best for: Multi-service changes where files do not overlap.
47
+
48
+ ```
49
+ Spawn agents with isolation: "worktree":
50
+ ├── Agent "fe-dev" (worktree): ONLY touch src/frontend/** → commit per item
51
+ ├── Agent "be-dev" (worktree): ONLY touch src/backend/** → commit per item
52
+ └── Agent "auth-dev" (worktree): ONLY touch src/auth/** → commit per item
53
+
54
+ After all complete: merge branches, run integration tests
55
+ ```
56
+
57
+ ### Pattern 3: Fan-Out / Fan-In Research
58
+
59
+ Best for: Comprehensive analysis before any action.
60
+
61
+ ```
62
+ Fan-Out (parallel Agent calls in single message):
63
+ ├── Agent "security" (Explore): Audit for OWASP top 10 → findings.md
64
+ ├── Agent "perf" (Explore): Profile and benchmark → findings.md
65
+ └── Agent "a11y" (Explore): Check accessibility → findings.md
66
+
67
+ Fan-In (Loop):
68
+ └── Synthesize all findings → create action plan → implement
69
+ ```
70
+
71
+ ### Pattern 4: Scout-Then-Execute
72
+
73
+ Best for: Unfamiliar codebases or risky changes.
74
+
75
+ ```
76
+ Scout (single Agent, Explore type):
77
+ └── Map codebase, trace dependencies, identify risks → scout-report.md
78
+
79
+ Execute (Loop):
80
+ └── Use scout report as reference, implement changes
81
+ ```
82
+
83
+ ### Pattern 5: Pipeline with Checkpoints
84
+
85
+ Best for: Complex multi-stage transformations.
86
+
87
+ ```
88
+ Stage 1 (Loop): Parse + validate → intermediate output
89
+ checkpoint: verify schema
90
+ Stage 2 (Loop): Transform → draft output
91
+ checkpoint: run regression tests
92
+ Stage 3 (Parallel Agents): Apply to multiple files
93
+ checkpoint: final integration test
94
+ ```
95
+
96
+ ## Decision Matrix
97
+
98
+ | Factor | Score |
99
+ | ------------------------------ | ----- |
100
+ | Files span 3+ directories | +2 |
101
+ | Items are independent | +2 |
102
+ | Need full context to decide | -2 |
103
+ | Order matters | -2 |
104
+ | 10+ similar items | +1 |
105
+ | Needs cross-file understanding | -1 |
106
+ | Multiple services/repos | +3 |
107
+
108
+ - **Score >= 3**: Recommend parallel subagents
109
+ - **Score 0-2**: Sequential loop, optional scout phase
110
+ - **Score < 0**: Single sequential Loop
111
+
112
+ ## Report Convention
113
+
114
+ ```
115
+ .loophaus/
116
+ └── reports/
117
+ ├── {agent-name}.md # Individual agent output
118
+ ├── merged.md # Combined findings
119
+ └── plan.md # Action plan
120
+ ```
121
+
122
+ ## Integration with Loop Interview
123
+
124
+ When `/loop-plan` invokes this skill, provide:
125
+
126
+ 1. Recommended pattern
127
+ 2. Agent breakdown with roles and file boundaries
128
+ 3. Phase structure and checkpoints
129
+ 4. Ready-to-embed Agent tool call instructions for the loop prompt