cc-devflow 1.0.3 → 2.4.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/.claude/CLAUDE.md +123 -4
- package/.claude/agents/code-quality-reviewer.md +205 -0
- package/.claude/agents/spec-reviewer.md +221 -0
- package/.claude/commands/cancel-ralph.md +59 -0
- package/.claude/commands/flow-dev.md +202 -21
- package/.claude/commands/flow-epic.md +33 -0
- package/.claude/commands/flow-fix.md +138 -20
- package/.claude/commands/flow-init.md +104 -15
- package/.claude/commands/flow-new.md +84 -35
- package/.claude/commands/flow-prd.md +16 -3
- package/.claude/commands/flow-release.md +33 -0
- package/.claude/commands/flow-review.md +257 -0
- package/.claude/docs/templates/ATTEMPT_TEMPLATE.md +156 -0
- package/.claude/docs/templates/BRAINSTORM_TEMPLATE.md +148 -0
- package/.claude/docs/templates/ERROR_LOG_TEMPLATE.md +80 -0
- package/.claude/docs/templates/INIT_FLOW_TEMPLATE.md +22 -14
- package/.claude/guides/workflow-guides/flow-orchestrator.md +2 -2
- package/.claude/hooks/hooks.json +15 -0
- package/.claude/hooks/ralph-stop-hook.sh +190 -0
- package/.claude/rules/devflow-conventions.md +3 -1
- package/.claude/rules/project-constitution.md +256 -2
- package/.claude/rules/rationalization-library.md +282 -0
- package/.claude/scripts/create-requirement.sh +19 -6
- package/.claude/scripts/setup-ralph-loop.sh +155 -0
- package/.claude/scripts/verify-gate.sh +269 -0
- package/.claude/skills/cc-devflow-orchestrator/SKILL.md +70 -20
- package/.claude/skills/file-header-guardian/SKILL.md +56 -0
- package/.claude/skills/flow-attention-refresh/SKILL.md +170 -0
- package/.claude/skills/flow-brainstorming/SKILL.md +161 -0
- package/.claude/skills/flow-debugging/SKILL.md +221 -0
- package/.claude/skills/flow-finishing-branch/SKILL.md +189 -0
- package/.claude/skills/flow-receiving-review/SKILL.md +153 -0
- package/.claude/skills/flow-tdd/SKILL.md +218 -0
- package/.claude/skills/fractal-docs-generator/SKILL.md +45 -0
- package/.claude/skills/skill-rules.json +75 -0
- package/.claude/skills/verification-before-completion/SKILL.md +158 -0
- package/README.md +104 -19
- package/README.zh-CN.md +79 -1
- package/docs/commands/flow-init.md +3 -1
- package/docs/commands/flow-init.zh-CN.md +3 -1
- package/package.json +1 -1
- package/.claude/tsc-cache/777aa1de-497e-411b-a40f-13b74efcec58/affected-repos.txt +0 -1
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
# CC-DevFlow Rationalization Library
|
|
2
|
+
|
|
3
|
+
> **Version**: 1.0.0
|
|
4
|
+
> **Purpose**: Centralized defense against AI Agent rationalization attempts
|
|
5
|
+
> **Source**: Extracted from superpowers TDD skill + CC-DevFlow operational experience
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## How to Use This Library
|
|
10
|
+
|
|
11
|
+
When an agent is about to violate a Constitutional Article, they will often produce
|
|
12
|
+
rationalizations. This library provides pre-crafted responses.
|
|
13
|
+
|
|
14
|
+
**Pattern**:
|
|
15
|
+
1. Agent produces excuse
|
|
16
|
+
2. Lookup excuse in relevant Article section
|
|
17
|
+
3. Respond with "Reality" column
|
|
18
|
+
4. If not found, add new rationalization to library
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Article I: Quality First - Rationalization Table
|
|
23
|
+
|
|
24
|
+
### Iron Law
|
|
25
|
+
```
|
|
26
|
+
NO PARTIAL IMPLEMENTATION - COMPLETE OR NOTHING
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Rationalizations
|
|
30
|
+
|
|
31
|
+
| Excuse | Reality |
|
|
32
|
+
|--------|---------|
|
|
33
|
+
| "This is simplified for now" | CONSTITUTIONAL VIOLATION. Complete it or don't ship it. |
|
|
34
|
+
| "Will complete in v2" | Future versions don't exist. Implement fully now. |
|
|
35
|
+
| "Core logic works, edge cases later" | Edge cases ARE the implementation. No later. |
|
|
36
|
+
| "Time constraint" | Ship later, ship complete. Never ship incomplete. |
|
|
37
|
+
| "MVP approach" | MVP = Minimum VIABLE. Viable means works completely. |
|
|
38
|
+
| "Placeholder for now" | Placeholders = technical debt = future bugs. |
|
|
39
|
+
| "I'll fix it before PR" | Fix it NOW. Not later. Now. |
|
|
40
|
+
| "80% is good enough" | 80% = broken for 20% of users. Not good enough. |
|
|
41
|
+
| "Works on my machine" | Production is not your machine. Test properly. |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Article II: Architectural Consistency - Rationalization Table
|
|
46
|
+
|
|
47
|
+
### Iron Law
|
|
48
|
+
```
|
|
49
|
+
REUSE EXISTING CODE - NO DUPLICATION
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Rationalizations
|
|
53
|
+
|
|
54
|
+
| Excuse | Reality |
|
|
55
|
+
|--------|---------|
|
|
56
|
+
| "Faster to rewrite" | Faster now = slower forever. Find and reuse. |
|
|
57
|
+
| "That code is messy" | Refactor it. Don't duplicate it. |
|
|
58
|
+
| "Slightly different use case" | Extract common, parameterize difference. |
|
|
59
|
+
| "I don't have time to search" | Searching takes 5 min. Maintaining duplicates takes forever. |
|
|
60
|
+
| "The other code might change" | Good. Your copy will be outdated. Use shared version. |
|
|
61
|
+
| "It's just a small function" | Small duplications compound. No exceptions. |
|
|
62
|
+
| "I understand my version better" | Understand the shared version. That's your job. |
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Article III: Security First - Rationalization Table
|
|
67
|
+
|
|
68
|
+
### Iron Law
|
|
69
|
+
```
|
|
70
|
+
NO HARDCODED SECRETS - ENVIRONMENT VARIABLES ONLY
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Rationalizations
|
|
74
|
+
|
|
75
|
+
| Excuse | Reality |
|
|
76
|
+
|--------|---------|
|
|
77
|
+
| "It's just for testing" | Commits are forever. Use env vars even for tests. |
|
|
78
|
+
| "I'll remove it before commit" | You won't. You'll forget. Use env vars. |
|
|
79
|
+
| "It's not a real secret" | Any credential is a real secret. Treat it as such. |
|
|
80
|
+
| "Local development only" | Local becomes production. Start secure. |
|
|
81
|
+
| "Nobody will see the repo" | Repos get shared. Git history is permanent. |
|
|
82
|
+
| "I'll rotate it later" | Rotation doesn't erase history. Never commit secrets. |
|
|
83
|
+
| "It's encrypted" | Encrypted secrets in code are still secrets in code. |
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Article IV: Performance Accountability - Rationalization Table
|
|
88
|
+
|
|
89
|
+
### Iron Law
|
|
90
|
+
```
|
|
91
|
+
NO RESOURCE LEAKS - ALWAYS CLEANUP
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Rationalizations
|
|
95
|
+
|
|
96
|
+
| Excuse | Reality |
|
|
97
|
+
|--------|---------|
|
|
98
|
+
| "Garbage collector will handle it" | GC doesn't close files/connections. Explicit cleanup. |
|
|
99
|
+
| "Small leak, won't matter" | Small leaks become big crashes. Fix now. |
|
|
100
|
+
| "It's a short-lived process" | Process lifetime is not your decision. Always cleanup. |
|
|
101
|
+
| "I'll add cleanup later" | Later = never. Add cleanup with creation. |
|
|
102
|
+
| "Framework handles it" | Verify that. Don't assume. |
|
|
103
|
+
| "Only happens in edge case" | Edge cases run in production. Handle them. |
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Article V: Maintainability - Rationalization Table
|
|
108
|
+
|
|
109
|
+
### Iron Law
|
|
110
|
+
```
|
|
111
|
+
NO DEAD CODE - USE IT OR DELETE IT
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Rationalizations
|
|
115
|
+
|
|
116
|
+
| Excuse | Reality |
|
|
117
|
+
|--------|---------|
|
|
118
|
+
| "Might need it later" | Git history exists. Delete now, retrieve if needed. |
|
|
119
|
+
| "It's just commented out" | Commented code = noise. Delete it. |
|
|
120
|
+
| "Reference for future work" | Write docs. Don't keep dead code. |
|
|
121
|
+
| "Someone else might need it" | They'll write their own. Delete yours. |
|
|
122
|
+
| "Too risky to delete" | Tests exist. If tests pass after delete, it's safe. |
|
|
123
|
+
| "I worked hard on this" | Sunk cost fallacy. Delete it. |
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Article VI: Test-First Development - Rationalization Table
|
|
128
|
+
|
|
129
|
+
### Iron Law
|
|
130
|
+
```
|
|
131
|
+
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Rationalizations
|
|
135
|
+
|
|
136
|
+
| Excuse | Reality |
|
|
137
|
+
|--------|---------|
|
|
138
|
+
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
|
|
139
|
+
| "I'll test after" | Tests passing immediately prove nothing. |
|
|
140
|
+
| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
|
|
141
|
+
| "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
|
|
142
|
+
| "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
|
|
143
|
+
| "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
|
|
144
|
+
| "Need to explore first" | Fine. Throw away exploration, start with TDD. |
|
|
145
|
+
| "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
|
|
146
|
+
| "TDD slows me down" | TDD faster than debugging. Pragmatic = test-first. |
|
|
147
|
+
| "This is different because..." | No. This is rationalization. Follow the law. |
|
|
148
|
+
| "Spirit not letter" | Violating letter IS violating spirit. No loopholes. |
|
|
149
|
+
| "I'm being pragmatic, not dogmatic" | TDD IS pragmatic. Shortcuts = debugging in production = slower. |
|
|
150
|
+
| "Just this once" | No exceptions. Rules exist for this exact moment. |
|
|
151
|
+
| "Existing code has no tests" | You're improving it. Add tests for existing code. |
|
|
152
|
+
| "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## Article VII: Simplicity Gate - Rationalization Table
|
|
157
|
+
|
|
158
|
+
### Iron Law
|
|
159
|
+
```
|
|
160
|
+
MAXIMUM 3 PROJECTS - JUSTIFY ANY ADDITIONAL COMPLEXITY
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Rationalizations
|
|
164
|
+
|
|
165
|
+
| Excuse | Reality |
|
|
166
|
+
|--------|---------|
|
|
167
|
+
| "Microservices are better" | For your scale? Monolith is simpler. Start there. |
|
|
168
|
+
| "Future scalability" | YAGNI. Scale when you need to. |
|
|
169
|
+
| "Separation of concerns" | Modules separate concerns. Projects add overhead. |
|
|
170
|
+
| "Team autonomy" | Autonomy ≠ architectural chaos. Coordinate. |
|
|
171
|
+
| "Best practices say..." | Best practices assume scale you don't have. |
|
|
172
|
+
| "We might need it" | Might ≠ do. Build for now, refactor when needed. |
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Article VIII: Anti-Abstraction - Rationalization Table
|
|
177
|
+
|
|
178
|
+
### Iron Law
|
|
179
|
+
```
|
|
180
|
+
USE FRAMEWORKS DIRECTLY - NO UNNECESSARY WRAPPERS
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Rationalizations
|
|
184
|
+
|
|
185
|
+
| Excuse | Reality |
|
|
186
|
+
|--------|---------|
|
|
187
|
+
| "Abstraction for future flexibility" | YAGNI. You won't switch frameworks. |
|
|
188
|
+
| "Cleaner interface" | Framework interface IS clean. Learn it. |
|
|
189
|
+
| "Hide implementation details" | Framework IS implementation. Don't hide it. |
|
|
190
|
+
| "Consistent with other projects" | Consistency ≠ unnecessary abstraction. |
|
|
191
|
+
| "Easier testing" | Mock the framework. Don't wrap it. |
|
|
192
|
+
| "Best practice pattern" | Pattern ≠ always apply. Use judgment. |
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Article IX: Integration-First Testing - Rationalization Table
|
|
197
|
+
|
|
198
|
+
### Iron Law
|
|
199
|
+
```
|
|
200
|
+
CONTRACTS FIRST - REAL ENVIRONMENTS
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Rationalizations
|
|
204
|
+
|
|
205
|
+
| Excuse | Reality |
|
|
206
|
+
|--------|---------|
|
|
207
|
+
| "Unit tests are faster" | Fast wrong tests waste time. Integration tests catch real bugs. |
|
|
208
|
+
| "Mocks are simpler" | Mocks hide integration issues. Real databases find them. |
|
|
209
|
+
| "CI is slow" | CI is cheap. Production bugs are expensive. |
|
|
210
|
+
| "Docker is complex" | Docker is simpler than debugging integration issues. |
|
|
211
|
+
| "In-memory database works" | In-memory differs from production. Test with real DB. |
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Article X: Requirement Boundary - Rationalization Table
|
|
216
|
+
|
|
217
|
+
### Iron Law
|
|
218
|
+
```
|
|
219
|
+
IMPLEMENT WHAT'S REQUESTED, NOTHING MORE
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Rationalizations
|
|
223
|
+
|
|
224
|
+
| Excuse | Reality |
|
|
225
|
+
|--------|---------|
|
|
226
|
+
| "User might need this later" | User didn't ask. Don't add. YAGNI. |
|
|
227
|
+
| "It's just a small addition" | Small additions compound. Scope creep. |
|
|
228
|
+
| "This is a natural extension" | Extensions require explicit request. |
|
|
229
|
+
| "Would be nice to have" | Nice ≠ required. Focus on requirements. |
|
|
230
|
+
| "While I'm here anyway" | Stay on task. Create separate requirement. |
|
|
231
|
+
| "It's only 5 more lines" | 5 lines = testing + docs + maintenance. Not 5 lines. |
|
|
232
|
+
| "User will thank me" | User will thank you for ON-TIME, IN-SCOPE delivery. |
|
|
233
|
+
| "I'm being helpful" | Helpful = following spec. Unhelpful = scope creep. |
|
|
234
|
+
| "It's best practice" | Best practice: implement what's requested. |
|
|
235
|
+
| "Future-proofing" | Future-proofing = over-engineering = waste. |
|
|
236
|
+
| "Obvious feature" | If obvious, it should be in spec. Not in spec = don't do. |
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Cross-Article Rationalizations
|
|
241
|
+
|
|
242
|
+
These excuses appear across multiple Articles:
|
|
243
|
+
|
|
244
|
+
| Excuse | Reality | Articles |
|
|
245
|
+
|--------|---------|----------|
|
|
246
|
+
| "Just this once" | No exceptions. Rules exist for this exact moment. | All |
|
|
247
|
+
| "I'm being pragmatic" | Pragmatic = following rules. Shortcuts = technical debt. | All |
|
|
248
|
+
| "Time is tight" | Rushed work = bugs = more time spent debugging. | All |
|
|
249
|
+
| "It's obvious it works" | Nothing is obvious. Prove with tests. | I, VI |
|
|
250
|
+
| "Everyone does this" | Everyone is wrong. We do it right. | All |
|
|
251
|
+
| "Senior says skip it" | Constitution > authority. No skipping. | All |
|
|
252
|
+
| "Emergency situation" | Emergencies especially need rules. | III, VI |
|
|
253
|
+
| "This is different" | It's not different. Follow the rules. | All |
|
|
254
|
+
| "Spirit over letter" | Violating letter IS violating spirit. | VI |
|
|
255
|
+
| "Being practical" | Practical = disciplined. Shortcuts = impractical. | All |
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Adding New Rationalizations
|
|
260
|
+
|
|
261
|
+
When you encounter a new excuse not in this library:
|
|
262
|
+
|
|
263
|
+
1. **Capture verbatim** - Record exact words used
|
|
264
|
+
2. **Identify Article** - Which Constitutional Article does it violate?
|
|
265
|
+
3. **Craft Reality response** - Brief, direct, no compromise
|
|
266
|
+
4. **Add to library** - PR to update this document
|
|
267
|
+
5. **Update guardrails** - Add pattern to relevant skill if blocking needed
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Integration Points
|
|
272
|
+
|
|
273
|
+
This library is consumed by:
|
|
274
|
+
- `.claude/rules/project-constitution.md` (inline tables per Article)
|
|
275
|
+
- `.claude/agents/*.md` (relevant tables per agent role)
|
|
276
|
+
- `.claude/skills/devflow-tdd-enforcer/SKILL.md`
|
|
277
|
+
- `.claude/skills/constitution-guardian/SKILL.md`
|
|
278
|
+
- `tests/pressure-scenarios/` (test scenarios)
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
**[PROTOCOL]**: 变更时更新此头部,然后检查 CLAUDE.md
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
# Optional if --interactive mode is used
|
|
13
13
|
#
|
|
14
14
|
# OPTIONS:
|
|
15
|
-
# --title TITLE Requirement title (
|
|
15
|
+
# --title TITLE Requirement title (docs; branch fallback)
|
|
16
|
+
# --branch-title TITLE Branch title used for git branch naming (optional)
|
|
16
17
|
# --description DESC Brief description (optional)
|
|
17
18
|
# --skip-git Skip git branch creation
|
|
18
19
|
# --interactive, -i Interactive mode (prompts for inputs)
|
|
@@ -22,6 +23,7 @@
|
|
|
22
23
|
# EXAMPLES:
|
|
23
24
|
# # Create requirement with title
|
|
24
25
|
# ./create-requirement.sh REQ-123 --title "User authentication"
|
|
26
|
+
# ./create-requirement.sh REQ-123 --title "User authentication" --branch-title "Auth"
|
|
25
27
|
#
|
|
26
28
|
# # Interactive mode
|
|
27
29
|
# ./create-requirement.sh --interactive
|
|
@@ -37,6 +39,7 @@ set -e
|
|
|
37
39
|
# Parse command line arguments
|
|
38
40
|
REQ_ID=""
|
|
39
41
|
TITLE=""
|
|
42
|
+
BRANCH_TITLE=""
|
|
40
43
|
DESCRIPTION=""
|
|
41
44
|
SKIP_GIT=false
|
|
42
45
|
INTERACTIVE=false
|
|
@@ -49,6 +52,10 @@ while [[ $# -gt 0 ]]; do
|
|
|
49
52
|
TITLE="$2"
|
|
50
53
|
shift 2
|
|
51
54
|
;;
|
|
55
|
+
--branch-title)
|
|
56
|
+
BRANCH_TITLE="$2"
|
|
57
|
+
shift 2
|
|
58
|
+
;;
|
|
52
59
|
--description)
|
|
53
60
|
DESCRIPTION="$2"
|
|
54
61
|
shift 2
|
|
@@ -80,7 +87,8 @@ ARGUMENTS:
|
|
|
80
87
|
Optional if --interactive mode is used
|
|
81
88
|
|
|
82
89
|
OPTIONS:
|
|
83
|
-
--title TITLE Requirement title (
|
|
90
|
+
--title TITLE Requirement title (docs; branch fallback)
|
|
91
|
+
--branch-title TITLE Branch title used for git branch naming (optional)
|
|
84
92
|
--description DESC Brief description (optional)
|
|
85
93
|
--skip-git Skip git branch creation
|
|
86
94
|
--interactive, -i Interactive mode (prompts for inputs)
|
|
@@ -92,6 +100,9 @@ EXAMPLES:
|
|
|
92
100
|
# Create requirement with title
|
|
93
101
|
./create-requirement.sh REQ-123 --title "User authentication"
|
|
94
102
|
|
|
103
|
+
# Create requirement with custom branch title
|
|
104
|
+
./create-requirement.sh REQ-123 --title "User authentication" --branch-title "Auth"
|
|
105
|
+
|
|
95
106
|
# Interactive mode
|
|
96
107
|
./create-requirement.sh --interactive
|
|
97
108
|
|
|
@@ -353,14 +364,16 @@ fi
|
|
|
353
364
|
GIT_BRANCH=""
|
|
354
365
|
if ! $SKIP_GIT && has_git; then
|
|
355
366
|
# Generate branch name from title
|
|
356
|
-
if [[ -n "$
|
|
367
|
+
if [[ -n "$BRANCH_TITLE" ]]; then
|
|
368
|
+
BRANCH_SUFFIX=$(slugify "$BRANCH_TITLE")
|
|
369
|
+
elif [[ -n "$TITLE" ]]; then
|
|
357
370
|
BRANCH_SUFFIX=$(slugify "$TITLE")
|
|
358
|
-
if [[ -z "$BRANCH_SUFFIX" ]]; then
|
|
359
|
-
BRANCH_SUFFIX="new-requirement"
|
|
360
|
-
fi
|
|
361
371
|
else
|
|
362
372
|
BRANCH_SUFFIX="new-requirement"
|
|
363
373
|
fi
|
|
374
|
+
if [[ -z "$BRANCH_SUFFIX" ]]; then
|
|
375
|
+
BRANCH_SUFFIX="new-requirement"
|
|
376
|
+
fi
|
|
364
377
|
|
|
365
378
|
# Determine branch prefix based on type
|
|
366
379
|
if [[ "$REQ_TYPE" == "bug" ]]; then
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# CC-DevFlow Ralph Loop Setup Script
|
|
4
|
+
# Adapted from ralph-wiggum for cc-devflow integration
|
|
5
|
+
# Creates state file for Ralph autonomous loop
|
|
6
|
+
|
|
7
|
+
set -euo pipefail
|
|
8
|
+
|
|
9
|
+
# ========== Arguments ==========
|
|
10
|
+
|
|
11
|
+
REQ_ID=""
|
|
12
|
+
MAX_ITERATIONS=10
|
|
13
|
+
COMPLETION_PROMISE="RALPH_COMPLETE"
|
|
14
|
+
|
|
15
|
+
# Parse options
|
|
16
|
+
while [[ $# -gt 0 ]]; do
|
|
17
|
+
case $1 in
|
|
18
|
+
-h|--help)
|
|
19
|
+
cat << 'HELP_EOF'
|
|
20
|
+
CC-DevFlow Ralph Loop Setup
|
|
21
|
+
|
|
22
|
+
USAGE:
|
|
23
|
+
setup-ralph-loop.sh REQ_ID [OPTIONS]
|
|
24
|
+
|
|
25
|
+
ARGUMENTS:
|
|
26
|
+
REQ_ID Requirement ID (e.g., REQ-123)
|
|
27
|
+
|
|
28
|
+
OPTIONS:
|
|
29
|
+
--max-iterations <n> Maximum iterations (default: 10)
|
|
30
|
+
--completion-promise '<text>' Promise phrase (default: "RALPH_COMPLETE")
|
|
31
|
+
-h, --help Show this help
|
|
32
|
+
|
|
33
|
+
DESCRIPTION:
|
|
34
|
+
Sets up Ralph loop state for CC-DevFlow autonomous development.
|
|
35
|
+
Used by /flow-ralph command.
|
|
36
|
+
|
|
37
|
+
EXAMPLES:
|
|
38
|
+
setup-ralph-loop.sh REQ-123
|
|
39
|
+
setup-ralph-loop.sh REQ-123 --max-iterations 20
|
|
40
|
+
setup-ralph-loop.sh REQ-123 --completion-promise "ALL_TASKS_DONE"
|
|
41
|
+
|
|
42
|
+
OUTPUT:
|
|
43
|
+
Creates .claude/ralph-loop.local.md with loop state
|
|
44
|
+
HELP_EOF
|
|
45
|
+
exit 0
|
|
46
|
+
;;
|
|
47
|
+
--max-iterations)
|
|
48
|
+
if [[ -z "${2:-}" ]] || ! [[ "$2" =~ ^[0-9]+$ ]]; then
|
|
49
|
+
echo "❌ Error: --max-iterations requires a positive integer" >&2
|
|
50
|
+
exit 1
|
|
51
|
+
fi
|
|
52
|
+
MAX_ITERATIONS="$2"
|
|
53
|
+
shift 2
|
|
54
|
+
;;
|
|
55
|
+
--completion-promise)
|
|
56
|
+
if [[ -z "${2:-}" ]]; then
|
|
57
|
+
echo "❌ Error: --completion-promise requires a text argument" >&2
|
|
58
|
+
exit 1
|
|
59
|
+
fi
|
|
60
|
+
COMPLETION_PROMISE="$2"
|
|
61
|
+
shift 2
|
|
62
|
+
;;
|
|
63
|
+
*)
|
|
64
|
+
if [[ -z "$REQ_ID" ]]; then
|
|
65
|
+
REQ_ID="$1"
|
|
66
|
+
shift
|
|
67
|
+
else
|
|
68
|
+
echo "❌ Error: Unknown argument: $1" >&2
|
|
69
|
+
exit 1
|
|
70
|
+
fi
|
|
71
|
+
;;
|
|
72
|
+
esac
|
|
73
|
+
done
|
|
74
|
+
|
|
75
|
+
# Validate REQ_ID
|
|
76
|
+
if [[ -z "$REQ_ID" ]]; then
|
|
77
|
+
echo "❌ Error: REQ_ID is required" >&2
|
|
78
|
+
echo "" >&2
|
|
79
|
+
echo " Usage: setup-ralph-loop.sh REQ-123 [OPTIONS]" >&2
|
|
80
|
+
echo " For help: setup-ralph-loop.sh --help" >&2
|
|
81
|
+
exit 1
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
if ! [[ "$REQ_ID" =~ ^(REQ|BUG)-[0-9]+$ ]]; then
|
|
85
|
+
echo "❌ Error: Invalid REQ_ID format: $REQ_ID" >&2
|
|
86
|
+
echo " Expected format: REQ-123 or BUG-456" >&2
|
|
87
|
+
exit 1
|
|
88
|
+
fi
|
|
89
|
+
|
|
90
|
+
# Check if requirement directory exists
|
|
91
|
+
REQ_DIR="devflow/requirements/${REQ_ID}"
|
|
92
|
+
if [[ ! -d "$REQ_DIR" ]]; then
|
|
93
|
+
echo "❌ Error: Requirement directory not found: $REQ_DIR" >&2
|
|
94
|
+
echo " Run /flow-init first to create the requirement structure" >&2
|
|
95
|
+
exit 1
|
|
96
|
+
fi
|
|
97
|
+
|
|
98
|
+
# Check if TASKS.md exists
|
|
99
|
+
if [[ ! -f "${REQ_DIR}/TASKS.md" ]]; then
|
|
100
|
+
echo "❌ Error: TASKS.md not found in $REQ_DIR" >&2
|
|
101
|
+
echo " Run /flow-epic first to generate tasks" >&2
|
|
102
|
+
exit 1
|
|
103
|
+
fi
|
|
104
|
+
|
|
105
|
+
# Create state file for stop hook
|
|
106
|
+
mkdir -p .claude
|
|
107
|
+
|
|
108
|
+
# Quote completion promise for YAML if needed
|
|
109
|
+
if [[ -n "$COMPLETION_PROMISE" ]] && [[ "$COMPLETION_PROMISE" != "null" ]]; then
|
|
110
|
+
COMPLETION_PROMISE_YAML="\"$COMPLETION_PROMISE\""
|
|
111
|
+
else
|
|
112
|
+
COMPLETION_PROMISE_YAML="null"
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
# Initial prompt for Ralph loop
|
|
116
|
+
INITIAL_PROMPT="Continue working on ${REQ_ID}. Use {SKILL:attention} Protocol 3 to refresh attention, then execute the next task in TASKS.md using TDD approach ({SKILL:tdd}). Record errors in ERROR_LOG.md. Output <promise>$COMPLETION_PROMISE</promise> when all tasks are complete."
|
|
117
|
+
|
|
118
|
+
cat > .claude/ralph-loop.local.md <<EOF
|
|
119
|
+
---
|
|
120
|
+
active: true
|
|
121
|
+
iteration: 1
|
|
122
|
+
max_iterations: $MAX_ITERATIONS
|
|
123
|
+
completion_promise: $COMPLETION_PROMISE_YAML
|
|
124
|
+
req_id: "$REQ_ID"
|
|
125
|
+
started_at: "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
$INITIAL_PROMPT
|
|
129
|
+
EOF
|
|
130
|
+
|
|
131
|
+
# Output setup message
|
|
132
|
+
cat <<EOF
|
|
133
|
+
🔄 Ralph loop activated for $REQ_ID!
|
|
134
|
+
|
|
135
|
+
Iteration: 1
|
|
136
|
+
Max iterations: $(if [[ $MAX_ITERATIONS -gt 0 ]]; then echo $MAX_ITERATIONS; else echo "unlimited"; fi)
|
|
137
|
+
Completion promise: $COMPLETION_PROMISE
|
|
138
|
+
|
|
139
|
+
The stop hook is now active. When you try to exit, the loop will:
|
|
140
|
+
1. Check if all tasks in TASKS.md are complete
|
|
141
|
+
2. Check if completion promise is detected
|
|
142
|
+
3. If not complete, continue to next iteration
|
|
143
|
+
|
|
144
|
+
To monitor: head -10 .claude/ralph-loop.local.md
|
|
145
|
+
To cancel: /cancel-ralph
|
|
146
|
+
|
|
147
|
+
⚠️ WARNING: Loop runs until max iterations or all tasks complete.
|
|
148
|
+
|
|
149
|
+
🔄 Starting autonomous development...
|
|
150
|
+
EOF
|
|
151
|
+
|
|
152
|
+
# Set environment variable for scripts
|
|
153
|
+
export RALPH_REQ_ID="$REQ_ID"
|
|
154
|
+
|
|
155
|
+
exit 0
|