ralphflow 0.1.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.
- package/LICENSE +21 -0
- package/README.md +205 -0
- package/dist/ralphflow.js +575 -0
- package/package.json +68 -0
- package/src/templates/claude-md.template.md +33 -0
- package/src/templates/code-implementation/loops/00-story-loop/loop.md +21 -0
- package/src/templates/code-implementation/loops/00-story-loop/prompt.md +135 -0
- package/src/templates/code-implementation/loops/00-story-loop/stories.md +3 -0
- package/src/templates/code-implementation/loops/00-story-loop/tracker.md +16 -0
- package/src/templates/code-implementation/loops/01-tasks-loop/loop.md +60 -0
- package/src/templates/code-implementation/loops/01-tasks-loop/phases/.gitkeep +0 -0
- package/src/templates/code-implementation/loops/01-tasks-loop/prompt.md +162 -0
- package/src/templates/code-implementation/loops/01-tasks-loop/tasks.md +3 -0
- package/src/templates/code-implementation/loops/01-tasks-loop/testing/.gitkeep +0 -0
- package/src/templates/code-implementation/loops/01-tasks-loop/tracker.md +18 -0
- package/src/templates/code-implementation/loops/02-delivery-loop/loop.md +21 -0
- package/src/templates/code-implementation/loops/02-delivery-loop/prompt.md +105 -0
- package/src/templates/code-implementation/loops/02-delivery-loop/tracker.md +13 -0
- package/src/templates/code-implementation/ralphflow.yaml +71 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Story Loop — Break Stories into Structured Tasks
|
|
2
|
+
|
|
3
|
+
Read `.ralph-flow/00-story-loop/tracker.md` FIRST to determine where you are.
|
|
4
|
+
|
|
5
|
+
> **Describe the destination, not the route.** Focus on what the user will experience, not how you'll build it. Surface anything that could go wrong — broken flows, overlooked edge cases, data at risk.
|
|
6
|
+
|
|
7
|
+
> **READ-ONLY FOR SOURCE CODE.** Only write to: `01-tasks-loop/tasks.md`, `01-tasks-loop/tracker.md`, `00-story-loop/tracker.md`, `00-story-loop/stories.md`.
|
|
8
|
+
|
|
9
|
+
**Pipeline:** `stories.md → YOU → tasks.md → 01-tasks-loop → code`
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## No Stories? Collect Them
|
|
14
|
+
|
|
15
|
+
If `stories.md` has no unprocessed stories and the tracker queue is empty/all done:
|
|
16
|
+
1. Tell the user: *"No stories queued. Tell me what you want to build — describe features, problems, or goals in your own words."*
|
|
17
|
+
2. Use `AskUserQuestion` to prompt: "What do you want to build or fix next?" (open-ended)
|
|
18
|
+
3. As the user narrates, capture each distinct idea as a `## STORY-{N}: {Title}` in `stories.md` with description and `**Depends on:** None` (or dependencies if mentioned)
|
|
19
|
+
4. **Confirm stories & dependencies** — present all captured stories back. Use `AskUserQuestion` (up to 5 questions) to validate: correct stories? right dependency order? any to split/merge? priority adjustments?
|
|
20
|
+
5. Apply corrections, finalize `stories.md`, proceed to normal flow
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## State Machine (3 stages per story)
|
|
25
|
+
|
|
26
|
+
Pick the lowest-numbered `ready` story. NEVER process a `blocked` story. If none are `ready`: `<promise>ALL STORIES PROCESSED</promise>`.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
ANALYZE → Read story, explore codebase, map scope → stage: clarify
|
|
30
|
+
CLARIFY → Ask user up to 20 questions (5 at a time) → stage: decompose
|
|
31
|
+
DECOMPOSE → Break into TASK-GROUP(s) + tasks, append to tasks.md, mark done → kill
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## First-Run Handling
|
|
35
|
+
|
|
36
|
+
If Stories Queue in tracker is empty: read `stories.md`, scan `## STORY-{N}:` headers + `**Depends on:**` tags, populate queue as `- [ ] STORY-{N}: {title}`, build Dependency Graph.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## STAGE 1: ANALYZE
|
|
41
|
+
|
|
42
|
+
1. Read tracker → pick lowest-numbered `ready` story
|
|
43
|
+
2. Read the story from `stories.md` (+ any referenced screenshots)
|
|
44
|
+
3. **Explore the codebase** — read `CLAUDE.md` for project context, then **20+ key files** across the areas this story touches. Understand current behavior, patterns, conventions, and what needs to change.
|
|
45
|
+
4. Update tracker: `active_story: STORY-{N}`, `stage: clarify`, log entry
|
|
46
|
+
|
|
47
|
+
## STAGE 2: CLARIFY
|
|
48
|
+
|
|
49
|
+
1. Formulate questions about scope, priorities, edge cases, design choices
|
|
50
|
+
2. **Ask up to 20 questions, 5 at a time** via `AskUserQuestion` (with options where possible):
|
|
51
|
+
- Round 1: Scope, intent, must-haves
|
|
52
|
+
- Round 2+: Design choices, edge cases, preferences — based on prior answers
|
|
53
|
+
- Stop early if clear enough
|
|
54
|
+
3. Save Q&A summary in tracker log
|
|
55
|
+
4. Update tracker: `stage: decompose`, log entry with key decisions
|
|
56
|
+
|
|
57
|
+
## STAGE 3: DECOMPOSE
|
|
58
|
+
|
|
59
|
+
1. Find next TASK-GROUP and TASK numbers (check existing in `01-tasks-loop/tasks.md`)
|
|
60
|
+
2. **Read already-written tasks** — if sibling tasks exist, read them to align scope boundaries
|
|
61
|
+
3. Break story into TASK-GROUP(s) — one per distinct functional area, 2-6 tasks each
|
|
62
|
+
4. For each task, ask yourself: *What does success look like? How would someone confirm? What could silently break?*
|
|
63
|
+
5. **Sanity-check:** Do NOT embed specific file paths in tasks — describe *what* changes, not *where*. The tasks loop will explore the codebase itself.
|
|
64
|
+
6. Append to `01-tasks-loop/tasks.md` (format below)
|
|
65
|
+
7. **Update `01-tasks-loop/tracker.md` (with lock protocol):**
|
|
66
|
+
1. Acquire `.ralph-flow/01-tasks-loop/.tracker-lock`:
|
|
67
|
+
- Exists + < 60s old → sleep 2s, retry up to 5 times
|
|
68
|
+
- Exists + ≥ 60s old → stale, delete it
|
|
69
|
+
- Not exists → continue
|
|
70
|
+
- Write lock: `echo "story-loop $(date -u +%Y-%m-%dT%H:%M:%SZ)" > .ralph-flow/01-tasks-loop/.tracker-lock`
|
|
71
|
+
- Sleep 500ms, re-read lock, verify `story-loop` is in it
|
|
72
|
+
2. Add new Task Groups to `## Task Groups`
|
|
73
|
+
3. Add new tasks to `## Tasks Queue` with multi-agent metadata:
|
|
74
|
+
- Compute status: check if each task's `**Depends on:**` targets are all in `completed_tasks`
|
|
75
|
+
- All deps satisfied or `Depends on: None` → `{agent: -, status: pending}`
|
|
76
|
+
- Any dep not satisfied → `{agent: -, status: blocked}`
|
|
77
|
+
- Example: `- [ ] TASK-15: New Task Title {agent: -, status: pending}`
|
|
78
|
+
4. Add dependency entries to `## Dependencies` section (for tasks with dependencies only):
|
|
79
|
+
- Example: `- TASK-15: [TASK-12]`
|
|
80
|
+
- Tasks with `Depends on: None` are NOT added to Dependencies
|
|
81
|
+
5. Release lock: `rm .ralph-flow/01-tasks-loop/.tracker-lock`
|
|
82
|
+
8. Mark done in tracker: check off queue, completed mapping, `active_story: none`, `stage: analyze`, update Dependency Graph, log
|
|
83
|
+
9. Exit: `kill -INT $PPID`
|
|
84
|
+
|
|
85
|
+
**TASK-GROUP header:**
|
|
86
|
+
```markdown
|
|
87
|
+
# TASK-GROUP-{X}: {Title}
|
|
88
|
+
|
|
89
|
+
**Source:** STORY-{N}
|
|
90
|
+
**Goal:** {1-3 sentences — the outcome, not the implementation}
|
|
91
|
+
**Milestones:**
|
|
92
|
+
- [ ] {Checkpoint} (TASK-{A}, TASK-{B})
|
|
93
|
+
**Shared Context:**
|
|
94
|
+
{Domain knowledge, constraints, relationships between tasks in this group}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Task format:**
|
|
98
|
+
```markdown
|
|
99
|
+
## TASK-{N}: {Concise title}
|
|
100
|
+
|
|
101
|
+
**Source:** STORY-{M}
|
|
102
|
+
**Task-Group:** TASK-GROUP-{X}
|
|
103
|
+
**Depends on:** {TASK-{Y} or "None"}
|
|
104
|
+
|
|
105
|
+
### Intent
|
|
106
|
+
{The purpose — the problem being solved and who benefits. 2-4 sentences.}
|
|
107
|
+
|
|
108
|
+
### Today
|
|
109
|
+
{How things work right now. Reference behavior, not file paths.}
|
|
110
|
+
|
|
111
|
+
### After
|
|
112
|
+
{The end-user experience once delivered. Describe the outcome, not the implementation.}
|
|
113
|
+
|
|
114
|
+
### Verification
|
|
115
|
+
{Concrete steps to confirm the change works — navigate here, do this, expect that.}
|
|
116
|
+
|
|
117
|
+
### Acceptance Criteria
|
|
118
|
+
- [ ] {Specific, observable condition — at least 3}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Rules
|
|
124
|
+
|
|
125
|
+
- One story at a time. All 3 stages run in one iteration, one `kill` at the end.
|
|
126
|
+
- Read tracker first, update tracker last.
|
|
127
|
+
- Append to `tasks.md` — never overwrite. Numbers globally unique and sequential.
|
|
128
|
+
- Tasks must be self-contained — the tasks loop never reads `stories.md`.
|
|
129
|
+
- Split into multiple groups when story spans distinct areas.
|
|
130
|
+
- Each task ≈ one implementable unit. No Scope or Risks sections — the tasks loop handles those in phase plans.
|
|
131
|
+
- Mark inter-task dependencies explicitly.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
Read `.ralph-flow/00-story-loop/tracker.md` now and begin.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Tasks Loop — Execution
|
|
2
|
+
|
|
3
|
+
## Using RalphFlow CLI
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# Single agent
|
|
7
|
+
npx ralphflow run tasks
|
|
8
|
+
|
|
9
|
+
# Multi-agent (3 parallel agents)
|
|
10
|
+
npx ralphflow run tasks --agents 3
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Manual (without CLI)
|
|
14
|
+
|
|
15
|
+
### Single Agent
|
|
16
|
+
|
|
17
|
+
#### Option 1: ralph-loop slash command
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
/ralph-loop "$(cat .ralph-flow/01-tasks-loop/prompt.md)" --max-iterations 50 --completion-promise "ALL TASKS COMPLETE"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
#### Option 2: while loop
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
while :; do cat .ralph-flow/01-tasks-loop/prompt.md | claude --dangerously-skip-permissions --model claude-opus-4-6; done
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### Multi-Agent (2+ terminals)
|
|
32
|
+
|
|
33
|
+
Each terminal runs a named agent. `{{AGENT_NAME}}` is injected via `sed`.
|
|
34
|
+
|
|
35
|
+
#### Terminal 1
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
AGENT=agent-1 && while :; do sed "s/{{AGENT_NAME}}/$AGENT/g" .ralph-flow/01-tasks-loop/prompt.md | claude --dangerously-skip-permissions --model claude-opus-4-6; done
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### Terminal 2
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
AGENT=agent-2 && while :; do sed "s/{{AGENT_NAME}}/$AGENT/g" .ralph-flow/01-tasks-loop/prompt.md | claude --dangerously-skip-permissions --model claude-opus-4-6; done
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
#### Terminal 3 (optional)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
AGENT=agent-3 && while :; do sed "s/{{AGENT_NAME}}/$AGENT/g" .ralph-flow/01-tasks-loop/prompt.md | claude --dangerously-skip-permissions --model claude-opus-4-6; done
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Notes
|
|
56
|
+
|
|
57
|
+
- Single agent mode uses `cat` — no `{{AGENT_NAME}}` substitution needed (prompt defaults to `agent-1`)
|
|
58
|
+
- Multi-agent mode uses `sed` to inject the agent name into the prompt
|
|
59
|
+
- Each agent gets its own terminal — they coordinate via `tracker.md`
|
|
60
|
+
- Up to 4 agents can run concurrently depending on task dependency chains
|
|
File without changes
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# Tasks Loop — Implement Tasks
|
|
2
|
+
|
|
3
|
+
**You are agent `{{AGENT_NAME}}`.** Multiple agents may work in parallel.
|
|
4
|
+
Coordinate via `tracker.md` — the single source of truth.
|
|
5
|
+
*(If you see the literal text `{{AGENT_NAME}}` above — i.e., it was not substituted — treat your name as `agent-1`.)*
|
|
6
|
+
|
|
7
|
+
Read `.ralph-flow/01-tasks-loop/tracker.md` FIRST to determine where you are.
|
|
8
|
+
|
|
9
|
+
> **PROJECT CONTEXT.** Read `CLAUDE.md` for architecture, stack, conventions, commands, and URLs.
|
|
10
|
+
|
|
11
|
+
**Pipeline:** `tasks.md → YOU → code changes + skills`
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Tracker Lock Protocol
|
|
16
|
+
|
|
17
|
+
Before ANY write to `tracker.md`, you MUST acquire the lock:
|
|
18
|
+
|
|
19
|
+
**Lock file:** `.ralph-flow/01-tasks-loop/.tracker-lock`
|
|
20
|
+
|
|
21
|
+
### Acquire Lock
|
|
22
|
+
1. Check if `.tracker-lock` exists
|
|
23
|
+
- Exists AND file is < 60 seconds old → sleep 2s, retry (up to 5 retries)
|
|
24
|
+
- Exists AND file is ≥ 60 seconds old → stale lock, delete it (agent crashed mid-write)
|
|
25
|
+
- Does not exist → continue
|
|
26
|
+
2. Write lock: `echo "{{AGENT_NAME}} $(date -u +%Y-%m-%dT%H:%M:%SZ)" > .ralph-flow/01-tasks-loop/.tracker-lock`
|
|
27
|
+
3. Sleep 500ms (`sleep 0.5`)
|
|
28
|
+
4. Re-read `.tracker-lock` — verify YOUR agent name (`{{AGENT_NAME}}`) is in it
|
|
29
|
+
- Your name → you own the lock, proceed to write `tracker.md`
|
|
30
|
+
- Other name → you lost the race, retry from step 1
|
|
31
|
+
5. Write your changes to `tracker.md`
|
|
32
|
+
6. Delete `.tracker-lock` immediately: `rm .ralph-flow/01-tasks-loop/.tracker-lock`
|
|
33
|
+
7. Never leave a lock held — if your write fails, delete the lock in your error handler
|
|
34
|
+
|
|
35
|
+
### When to Lock
|
|
36
|
+
- Claiming a task (pending → in_progress)
|
|
37
|
+
- Completing a task (in_progress → completed, unblocking dependents)
|
|
38
|
+
- Updating stage transitions (understand → execute → verify)
|
|
39
|
+
- Heartbeat updates (bundled with other writes, not standalone)
|
|
40
|
+
|
|
41
|
+
### When NOT to Lock
|
|
42
|
+
- Reading `tracker.md` — read-only access needs no lock
|
|
43
|
+
- Reading `tasks.md` — always read-only
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Task Selection Algorithm
|
|
48
|
+
|
|
49
|
+
Instead of "pick next unchecked task", follow this algorithm:
|
|
50
|
+
|
|
51
|
+
1. **Parse tracker** — read `completed_tasks`, `## Dependencies`, Tasks Queue metadata `{agent, status}`, Agent Status table
|
|
52
|
+
2. **Update blocked→pending** — for each task with `status: blocked`, check if ALL its dependencies (from `## Dependencies`) are in `completed_tasks`. If yes, acquire lock and update to `status: pending`
|
|
53
|
+
3. **Resume own work** — if any task has `{agent: {{AGENT_NAME}}, status: in_progress}`, resume it (skip to the current stage)
|
|
54
|
+
4. **Find claimable** — filter tasks where `status: pending` AND `agent: -`
|
|
55
|
+
5. **Apply task-group affinity** — prefer tasks in groups where `{{AGENT_NAME}}` already completed work (preserves codebase context). If no affinity match, pick any claimable task
|
|
56
|
+
6. **Claim** — acquire lock, set `{agent: {{AGENT_NAME}}, status: in_progress}`, update your Agent Status row, update `last_heartbeat`, release lock, log the claim
|
|
57
|
+
7. **Nothing available:**
|
|
58
|
+
- All tasks completed → emit `<promise>ALL TASKS COMPLETE</promise>`
|
|
59
|
+
- All remaining tasks are blocked or claimed by others → log "{{AGENT_NAME}}: waiting — all tasks blocked or claimed", exit: `kill -INT $PPID` (the `while` loop restarts and re-checks)
|
|
60
|
+
|
|
61
|
+
### New Task Discovery
|
|
62
|
+
|
|
63
|
+
If you find a task in the Tasks Queue without `{agent, status}` metadata (e.g., added by the story loop while agents were running):
|
|
64
|
+
1. Read the task's `**Depends on:**` field in `tasks.md`
|
|
65
|
+
2. Add the dependency to `## Dependencies` section if not already there (skip if `Depends on: None`)
|
|
66
|
+
3. Set status to `pending` (all deps in `completed_tasks`) or `blocked` (deps incomplete)
|
|
67
|
+
4. Set agent to `-`
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Anti-Hijacking Rules
|
|
72
|
+
|
|
73
|
+
1. **Never touch another agent's `in_progress` task** — do not modify, complete, or reassign it
|
|
74
|
+
2. **Respect task-group ownership** — if another agent has an active `in_progress` task in a group, leave remaining group tasks for them (affinity will naturally guide this). Only claim from that group if the other agent has finished all their group tasks
|
|
75
|
+
3. **Note file overlap conflicts** — if your task modifies files that another agent's active task also modifies, log a WARNING in the tracker and coordinate carefully
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## Heartbeat Protocol
|
|
80
|
+
|
|
81
|
+
Every tracker write includes updating your `last_heartbeat` to current ISO 8601 timestamp in the Agent Status table. If another agent's heartbeat is **30+ minutes stale**, log a WARNING in the tracker log but do NOT auto-reclaim their task — user must manually reset.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Crash Recovery (Self)
|
|
86
|
+
|
|
87
|
+
On fresh start, if your agent name has an `in_progress` task but you have no memory of it:
|
|
88
|
+
- Code committed for that task → resume at VERIFY stage
|
|
89
|
+
- No commits found → restart from UNDERSTAND stage
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## State Machine (2 stages per task)
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
UNDERSTAND & EXECUTE → Read task, explore, implement, deploy, commit → stage: verify
|
|
97
|
+
VERIFY & DOCUMENT → Check logs/health, update CLAUDE.md, skills, mark done → next task
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
When ALL done: `<promise>ALL TASKS COMPLETE</promise>`
|
|
101
|
+
|
|
102
|
+
After completing ANY stage, exit: `kill -INT $PPID`
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## STAGE 1: UNDERSTAND & EXECUTE
|
|
107
|
+
|
|
108
|
+
1. Read tracker → **run task selection algorithm** (see above)
|
|
109
|
+
2. Read task in `tasks.md` + its TASK-GROUP header
|
|
110
|
+
3. If sibling tasks are done, read their commits/diffs to align
|
|
111
|
+
4. Read `CLAUDE.md` for project context
|
|
112
|
+
5. Explore codebase — **40+ files:** affected areas, dependencies, patterns
|
|
113
|
+
6. Acquire lock → update tracker: your Agent Status row `active_task: TASK-{N}`, `stage: execute`, `last_heartbeat`, log entry → release lock
|
|
114
|
+
7. Implement changes. Match existing patterns per `CLAUDE.md`.
|
|
115
|
+
8. Deploy/rebuild (commands in `CLAUDE.md`)
|
|
116
|
+
9. **Quick verify:** check container logs for errors, hit health endpoints, confirm no crashes
|
|
117
|
+
10. Commit with a clear message
|
|
118
|
+
11. Acquire lock → update tracker: `stage: verify`, `last_heartbeat`, log entry → release lock
|
|
119
|
+
|
|
120
|
+
## STAGE 2: VERIFY & DOCUMENT
|
|
121
|
+
|
|
122
|
+
1. Deploy if not already running. Check container logs, hit health endpoints (commands in `CLAUDE.md`)
|
|
123
|
+
2. Run lint/type checks if applicable (see `CLAUDE.md`)
|
|
124
|
+
3. **Functional verify:** test the actual change — hit new/modified endpoints, check DB state, verify expected behavior through CLI/curl/API calls
|
|
125
|
+
4. **FAIL** → fix the issue, re-deploy, re-verify. If stuck, log details in tracker and move on
|
|
126
|
+
5. **PASS** → continue to documentation
|
|
127
|
+
6. Update `CLAUDE.md` (≤150 words net). Commit separately.
|
|
128
|
+
7. Create/update `.claude/skills/` if this task produced reusable knowledge. Skip if nothing reusable.
|
|
129
|
+
8. **Mark done & unblock dependents:**
|
|
130
|
+
- Acquire lock
|
|
131
|
+
- Add task to `completed_tasks` list
|
|
132
|
+
- Check off task in Tasks Queue: `[x]`, set `{completed}`
|
|
133
|
+
- Add commit hash to Completed Mapping
|
|
134
|
+
- **Unblock dependents:** for each task in `## Dependencies` that lists the just-completed task, check if ALL its dependencies are now in `completed_tasks`. If yes, update that task's status from `blocked` → `pending` in the Tasks Queue
|
|
135
|
+
- Update your Agent Status row: clear `active_task`
|
|
136
|
+
- Update `last_heartbeat`
|
|
137
|
+
- Log entry
|
|
138
|
+
- Release lock
|
|
139
|
+
9. **Run task selection algorithm again:**
|
|
140
|
+
- Claimable task found → claim it, set `stage: understand`, exit: `kill -INT $PPID`
|
|
141
|
+
- All tasks completed → `<promise>ALL TASKS COMPLETE</promise>`
|
|
142
|
+
- All blocked/claimed → log "waiting", exit: `kill -INT $PPID`
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## First-Run Handling
|
|
147
|
+
|
|
148
|
+
If Tasks Queue in tracker is empty: read `tasks.md`, scan `## TASK-{N}:` headers, populate queue with `{agent: -, status: pending|blocked}` metadata (compute from Dependencies), then start.
|
|
149
|
+
|
|
150
|
+
## Rules
|
|
151
|
+
|
|
152
|
+
- One task at a time per agent. One stage per iteration.
|
|
153
|
+
- Read tracker first, update tracker last. Always use lock protocol for writes.
|
|
154
|
+
- Read `CLAUDE.md` for all project-specific context.
|
|
155
|
+
- Align with sibling tasks via TASK-GROUP context.
|
|
156
|
+
- Thorough exploration: 40+ files (Stage 1).
|
|
157
|
+
- Create skills in `.claude/skills/` for reusable patterns.
|
|
158
|
+
- **Multi-agent: never touch another agent's in_progress task. Coordinate via tracker.md.**
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
Read `.ralph-flow/01-tasks-loop/tracker.md` now and begin.
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Tasks Loop — Tracker
|
|
2
|
+
|
|
3
|
+
- completed_tasks: []
|
|
4
|
+
|
|
5
|
+
## Agent Status
|
|
6
|
+
|
|
7
|
+
| agent | active_task | stage | last_heartbeat |
|
|
8
|
+
|-------|-------------|-------|----------------|
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Dependencies
|
|
13
|
+
|
|
14
|
+
## Task Groups
|
|
15
|
+
|
|
16
|
+
## Tasks Queue
|
|
17
|
+
|
|
18
|
+
## Log
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Delivery Loop — Execution
|
|
2
|
+
|
|
3
|
+
## Using RalphFlow CLI
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx ralphflow run delivery
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Manual (without CLI)
|
|
10
|
+
|
|
11
|
+
### Option 1: ralph-loop slash command
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
/ralph-loop "$(cat .ralph-flow/02-delivery-loop/prompt.md)" --max-iterations 20 --completion-promise "ALL DELIVERABLES PRESENTED"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Option 2: while loop
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
while :; do cat .ralph-flow/02-delivery-loop/prompt.md | claude --dangerously-skip-permissions --model claude-opus-4-6; done
|
|
21
|
+
```
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Delivery Loop — Present Completed Stories for Feedback
|
|
2
|
+
|
|
3
|
+
Read `.ralph-flow/02-delivery-loop/tracker.md` FIRST to determine where you are.
|
|
4
|
+
|
|
5
|
+
> **You are a service delivery agent. The user is your client.** Your job is to present completed work, gather structured feedback, and resolve it. Small bugs are fixed on the spot. Everything else becomes a new story.
|
|
6
|
+
|
|
7
|
+
> Only write to: `02-delivery-loop/tracker.md`, `00-story-loop/stories.md`. Source code is writable ONLY for small bug fixes during RESOLUTION.
|
|
8
|
+
|
|
9
|
+
**Pipeline:** `completed STORYs → YOU → feedback → small fixes + new stories`
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## First-Run Handling
|
|
14
|
+
|
|
15
|
+
If Delivery Queue is empty, build it by scanning the task tracker:
|
|
16
|
+
|
|
17
|
+
1. Read `00-story-loop/tracker.md` → find the **Completed Mapping** section. This maps each STORY to its TASK-GROUPs and their TASKs.
|
|
18
|
+
2. Read `01-tasks-loop/tracker.md` → find the `completed_tasks` list AND the Tasks Queue (look for cancelled tasks marked with `~~strikethrough~~`).
|
|
19
|
+
3. For each STORY in the Completed Mapping:
|
|
20
|
+
- Gather ALL non-cancelled tasks across ALL its task-groups
|
|
21
|
+
- Check that every non-cancelled task appears in `completed_tasks`
|
|
22
|
+
- **Cancellation rule:** Cancelled tasks (strikethrough in tasks queue) count as "done" for readiness. A story with some cancelled task-groups is still deliverable if all remaining tasks are complete.
|
|
23
|
+
4. Skip stories that already appear in the Delivered list in `02-delivery-loop/tracker.md`
|
|
24
|
+
5. Add ready stories to Delivery Queue in story-number order
|
|
25
|
+
|
|
26
|
+
Pick the next undelivered STORY from the queue. If none remain: `<promise>ALL DELIVERABLES PRESENTED</promise>`.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## State Machine (3 phases per STORY)
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
PHASE 1: REVIEW → Agent reviews independently (no user interaction)
|
|
34
|
+
PHASE 2: PRESENT-AND-FEEDBACK → Combined walkthrough + 3-4 questions in one pass
|
|
35
|
+
PHASE 3: RESOLUTION → Fix small bugs, create stories for changes → kill
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Phase 1 → Phase 2 flows continuously in one iteration (no kill between them). Only one `kill` per story at the end of Phase 3.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## PHASE 1: REVIEW (agent-driven, no user interaction)
|
|
43
|
+
|
|
44
|
+
1. Read all task-groups and tasks for this story from `01-tasks-loop/tasks.md`
|
|
45
|
+
2. Read phase plans from `01-tasks-loop/phases/`
|
|
46
|
+
3. Read `CLAUDE.md` for project context
|
|
47
|
+
4. **Review independently:** Walk through each task's verification steps. Note anything wrong, broken, or inconsistent. Build a presentation narrative.
|
|
48
|
+
5. For cancelled tasks/groups: note what was superseded and why
|
|
49
|
+
6. Record review notes in tracker log
|
|
50
|
+
7. Update tracker: `active_story: STORY-{N}`, `stage: present-and-feedback`
|
|
51
|
+
8. **Flow directly into Phase 2** (no stop)
|
|
52
|
+
|
|
53
|
+
## PHASE 2: PRESENT-AND-FEEDBACK (combined, one AskUserQuestion call)
|
|
54
|
+
|
|
55
|
+
1. **Present structured walkthrough** of ALL task-groups in the story:
|
|
56
|
+
- Per task-group: what was built (plain language), how to verify it
|
|
57
|
+
- Any issues the agent found during Phase 1 review
|
|
58
|
+
- Cancelled tasks/groups with brief explanation of what was superseded
|
|
59
|
+
2. **Ask 3-4 questions in ONE `AskUserQuestion` call:**
|
|
60
|
+
- **Q1: Working correctly?** Does everything work as expected? Note any specific issues.
|
|
61
|
+
- **Q2: Behavior or appearance?** Anything to change about look, feel, or behavior?
|
|
62
|
+
- **Q3: Missing or new ideas?** Anything missing, or new ideas sparked by what you see?
|
|
63
|
+
- **Q4: Priority?** *(optional — drop for simple stories with no issues)* What matters most?
|
|
64
|
+
3. **Categorize feedback:**
|
|
65
|
+
- **BUG** — something is broken or wrong (fix it now)
|
|
66
|
+
- **CHANGE** — works but needs adjustment, or entirely new functionality (new story)
|
|
67
|
+
4. Record feedback with categories in tracker log
|
|
68
|
+
5. Update tracker: `stage: resolution`
|
|
69
|
+
|
|
70
|
+
## PHASE 3: RESOLUTION
|
|
71
|
+
|
|
72
|
+
For each feedback item, route appropriately:
|
|
73
|
+
|
|
74
|
+
**BUG (small fix):** Fix it right now. Read `CLAUDE.md` for conventions, make the code change, deploy, verify, commit. Log what was fixed.
|
|
75
|
+
|
|
76
|
+
**CHANGE (any size):** Create a new story in `00-story-loop/stories.md` with:
|
|
77
|
+
- User-experience-level description (not implementation details)
|
|
78
|
+
- `**Origin:** STORY-{M} delivery feedback — relates to TASK-GROUP-{X}`
|
|
79
|
+
- `**Depends on:** STORY-{M}`
|
|
80
|
+
- Do NOT create task-groups or tasks (the story loop handles decomposition)
|
|
81
|
+
|
|
82
|
+
Log the story number created.
|
|
83
|
+
|
|
84
|
+
**No feedback (user approves everything):** Move to Delivered, log "approved with no changes".
|
|
85
|
+
|
|
86
|
+
After resolving all feedback:
|
|
87
|
+
1. Move STORY to Delivered list in tracker with summary of fixes made and stories created
|
|
88
|
+
2. Update tracker: `active_story: none`, `stage: review`
|
|
89
|
+
3. Exit: `kill -INT $PPID`
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Rules
|
|
94
|
+
|
|
95
|
+
- One STORY at a time. All 3 phases run in one iteration, one `kill` at the end.
|
|
96
|
+
- Phase 1 → Phase 2 flows continuously (no kill between them).
|
|
97
|
+
- Read tracker first, update tracker last.
|
|
98
|
+
- **Only modify source code for small bug fixes** identified during RESOLUTION. Read `CLAUDE.md` for patterns.
|
|
99
|
+
- Anything beyond a quick fix → new story. When in doubt, make it a story.
|
|
100
|
+
- Present work in user-friendly language — no jargon, no implementation details unless asked.
|
|
101
|
+
- Handle cancelled tasks/groups honestly — explain what was superseded and why.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
Read `.ralph-flow/02-delivery-loop/tracker.md` now and begin.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
name: code-implementation
|
|
2
|
+
description: "Story → Task → Delivery pipeline for code projects"
|
|
3
|
+
version: 1
|
|
4
|
+
dir: .ralph-flow
|
|
5
|
+
|
|
6
|
+
entities:
|
|
7
|
+
STORY:
|
|
8
|
+
prefix: STORY
|
|
9
|
+
data_file: 00-story-loop/stories.md
|
|
10
|
+
TASK:
|
|
11
|
+
prefix: TASK
|
|
12
|
+
data_file: 01-tasks-loop/tasks.md
|
|
13
|
+
TASK-GROUP:
|
|
14
|
+
prefix: TASK-GROUP
|
|
15
|
+
data_file: 01-tasks-loop/tasks.md
|
|
16
|
+
|
|
17
|
+
loops:
|
|
18
|
+
story-loop:
|
|
19
|
+
order: 0
|
|
20
|
+
name: "Story Loop"
|
|
21
|
+
prompt: 00-story-loop/prompt.md
|
|
22
|
+
tracker: 00-story-loop/tracker.md
|
|
23
|
+
data_files:
|
|
24
|
+
- 00-story-loop/stories.md
|
|
25
|
+
entities: [STORY]
|
|
26
|
+
stages: [analyze, clarify, decompose]
|
|
27
|
+
completion: "ALL STORIES PROCESSED"
|
|
28
|
+
feeds: [tasks-loop]
|
|
29
|
+
multi_agent: false
|
|
30
|
+
cadence: 0
|
|
31
|
+
|
|
32
|
+
tasks-loop:
|
|
33
|
+
order: 1
|
|
34
|
+
name: "Tasks Loop"
|
|
35
|
+
prompt: 01-tasks-loop/prompt.md
|
|
36
|
+
tracker: 01-tasks-loop/tracker.md
|
|
37
|
+
data_files:
|
|
38
|
+
- 01-tasks-loop/tasks.md
|
|
39
|
+
directories:
|
|
40
|
+
- 01-tasks-loop/phases/
|
|
41
|
+
- 01-tasks-loop/testing/
|
|
42
|
+
entities: [TASK, TASK-GROUP]
|
|
43
|
+
stages: [understand-execute, verify-document]
|
|
44
|
+
completion: "ALL TASKS COMPLETE"
|
|
45
|
+
fed_by: [story-loop]
|
|
46
|
+
feeds: [delivery-loop]
|
|
47
|
+
multi_agent:
|
|
48
|
+
enabled: true
|
|
49
|
+
max_agents: 4
|
|
50
|
+
strategy: tracker-lock
|
|
51
|
+
agent_placeholder: "{{AGENT_NAME}}"
|
|
52
|
+
lock:
|
|
53
|
+
file: 01-tasks-loop/.tracker-lock
|
|
54
|
+
type: echo
|
|
55
|
+
stale_seconds: 60
|
|
56
|
+
worktree:
|
|
57
|
+
strategy: shared
|
|
58
|
+
auto_merge: true
|
|
59
|
+
cadence: 0
|
|
60
|
+
|
|
61
|
+
delivery-loop:
|
|
62
|
+
order: 2
|
|
63
|
+
name: "Delivery Loop"
|
|
64
|
+
prompt: 02-delivery-loop/prompt.md
|
|
65
|
+
tracker: 02-delivery-loop/tracker.md
|
|
66
|
+
entities: [STORY]
|
|
67
|
+
stages: [review, present-and-feedback, resolution]
|
|
68
|
+
completion: "ALL DELIVERABLES PRESENTED"
|
|
69
|
+
fed_by: [tasks-loop]
|
|
70
|
+
multi_agent: false
|
|
71
|
+
cadence: 0
|