agentic-loop 3.4.6 → 3.5.1

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.
@@ -1,234 +1,186 @@
1
- # Development Session
1
+ # Ralph Autonomous Loop
2
2
 
3
- You are an autonomous coding agent working on a feature using the Ralph workflow.
3
+ You're implementing a story from `.ralph/prd.json`. This file contains everything you need.
4
4
 
5
- ## Session Startup Checklist
6
-
7
- Before writing any code, verify:
8
- 1. Run `pwd` to confirm you're in the correct directory
9
- 2. Read `.ralph/progress.txt` for recent session history
10
- 3. Run `git status` to check for uncommitted work
11
- 4. Review the current story details below
12
-
13
- ## Your Task
14
-
15
- For each story, you must:
16
-
17
- ### 1. Implement the Feature
18
-
19
- - Follow existing patterns in the codebase
20
- - Handle ALL error cases defined in the story
21
- - Implement loading states for async operations
22
-
23
- ### 2. Write Tests
24
-
25
- **Every new code file MUST have a corresponding test file.**
26
-
27
- For **Python** backend stories:
28
- - New file `foo.py` → create `tests/test_foo.py`
29
- - Test each public function/method
30
- - Test error cases (invalid input, missing data, API failures)
31
- - Test edge cases (empty lists, None values, boundary conditions)
32
- - Use pytest fixtures for database/API mocking
33
-
34
- For **Go** projects:
35
- - New file `foo.go` → create `foo_test.go` in same directory
36
- - Use table-driven tests for multiple cases
37
- - Test error paths and edge cases
38
-
39
- For **frontend** stories (TypeScript/React):
40
- - New component `Foo.tsx` → create `Foo.test.tsx`
41
- - Test rendering, user interactions, error states
42
- - Test loading states and empty states
5
+ ---
43
6
 
44
- **Do NOT skip tests.** If test enforcement is enabled, verification will fail without tests.
7
+ ## Step 1: Orient (MANDATORY)
45
8
 
46
- ### 3. Verify It Actually Works
9
+ Before writing any code, run these commands:
47
10
 
48
- **You have browser tools - USE THEM to verify your work:**
11
+ ```bash
12
+ git log --oneline -5 # Recent commits
13
+ cat .ralph/progress.txt | tail -30 # Recent activity
14
+ ```
49
15
 
50
- **Playwright MCP** (testing & automation):
51
- - Navigate to URLs and verify page content
52
- - Take screenshots to verify UI renders correctly
53
- - Click elements and fill forms to test interactions
54
- - Get accessibility snapshots for a11y testing
16
+ Then read these files:
17
+ - `.ralph/prd.json` - Find your story, note `techStack`, `globalConstraints`
18
+ - `CLAUDE.md` - Project conventions and coding standards
19
+ - Files listed in `story.contextFiles[]` - Idea files, styleguides, ASCII mockups
20
+ - `~/.claude/DNA.md` - Personal coding preferences (if exists)
55
21
 
56
- **Chrome DevTools MCP** (debugging & inspection):
57
- - Inspect DOM elements and check console for errors
58
- - Debug network requests and responses
59
- - Check element styles and computed properties
22
+ ---
60
23
 
61
- **Do NOT say you're done until:**
62
- - All unit tests pass
63
- - You've opened the browser and visually verified the feature works
64
- - Console has no errors
65
- - Error states are handled gracefully
24
+ ## Step 2: Check for Failures
66
25
 
67
- ## Rules
26
+ If `.ralph/last_failure.txt` exists, read it carefully. Understand what went wrong. Don't repeat that mistake.
68
27
 
69
- 1. **Focus**: Implement ONLY the current story. Do not work on other stories.
70
- 2. **Test first**: Write failing tests before implementation when possible.
71
- 3. **Test frequently**: Run tests after each significant change.
72
- 4. **Error handling is required**: Every story defines error cases - implement them all.
73
- 5. **Verification**: Never complete until browser validation passes.
74
- 6. **NEVER edit prd.json**: Do NOT modify `.ralph/prd.json`. Ralph handles story completion automatically after verification. You only write code and tests.
75
- 7. **Update notes**: After completing work, log what you did in `.ralph/progress.txt` including files created/modified and key decisions made. This helps the next session.
28
+ ---
76
29
 
77
- ## Verification Checklist
30
+ ## Step 3: Read Learned Patterns
78
31
 
79
- Before considering any story complete:
32
+ Read `.ralph/signs.json` - these are patterns learned from past failures. Follow them strictly.
80
33
 
81
- - [ ] All acceptance criteria are met
82
- - [ ] All error handling from story is implemented
83
- - [ ] TypeScript/code compiles without errors
84
- - [ ] Unit tests written and passing
85
- - [ ] **Browser verified** - used Playwright MCP to visually confirm it works
86
- - [ ] No console errors
87
- - [ ] Linting passes
88
- - [ ] Updated `.ralph/progress.txt` with files created/modified
34
+ ---
89
35
 
90
- ## If Verification Fails
36
+ ## Step 4: Verify Prerequisites
91
37
 
92
- If any check fails:
93
- 1. Read the error message carefully
94
- 2. Fix the issue
95
- 3. Re-run verification
96
- 4. Iterate until ALL checks pass
38
+ Check `story.prerequisites[]` in your story. Ensure:
39
+ - Required servers are running (check `.ralph/config.json` for URLs)
40
+ - Database is seeded if needed
41
+ - Dependencies are installed
97
42
 
98
- Do NOT give up. Keep iterating until it works.
43
+ ---
99
44
 
100
- ## If Blocked
45
+ ## Step 5: Implement
101
46
 
102
- If you encounter a blocker you cannot resolve:
103
- 1. Document the issue in `.ralph/progress.txt`
104
- 2. Note what you tried and why it didn't work
105
- 3. Suggest potential solutions for the next session
106
- 4. Do NOT mark the story as passing
47
+ Work on your story following these rules:
107
48
 
108
- ## Code Quality Standards
49
+ ### From Your Story
50
+ - **story.acceptanceCriteria** - What must be true when done
51
+ - **story.files** - Which files to create, modify, reuse (don't touch others)
52
+ - **story.testing** - Test types, approach (TDD/test-after), and test files to create
53
+ - **story.errorHandling** - How to handle failures
54
+ - **story.apiContract** - Expected request/response format (if applicable)
55
+ - **story.notes** - Human guidance and preferences
56
+ - **story.skills** - Read `.claude/commands/{skill}.md` for patterns
109
57
 
110
- ### Core Principles
111
- - **Readability First**: Code is read more than written. Prioritize clarity.
112
- - **KISS**: Keep it simple. Avoid over-engineering.
113
- - **DRY**: Don't repeat yourself. Extract reusable logic.
114
- - **YAGNI**: Don't build features you don't need yet.
58
+ ### From the PRD
59
+ - **prd.globalConstraints** - Rules that apply to ALL stories
60
+ - **prd.testing** - Testing strategy (TDD, tools, coverage)
115
61
 
116
- ### Naming Conventions
117
- - Variables: descriptive camelCase (`userProfile`, `isLoading`, `marketSearchQuery`)
118
- - Functions: verb-noun pattern (`fetchUserData`, `validateInput`, `handleSubmit`)
119
- - Components: PascalCase (`UserProfile`, `MarketCard`)
120
- - Constants: SCREAMING_SNAKE_CASE (`MAX_RETRIES`, `API_BASE_URL`)
62
+ ### From Config (.ralph/config.json)
63
+ - **config.urls.backend** - API base URL for curl tests
64
+ - **config.urls.frontend** - Frontend URL for browser tests
65
+ - **config.directories** - Where frontend/backend code lives
121
66
 
122
- ### Immutability (CRITICAL)
123
- Always use spread operators. Never mutate directly:
124
- ```typescript
125
- // Bad - mutation
126
- user.name = 'new name';
127
- items.push(newItem);
67
+ ### Code Quality
68
+ - **Readability First** - Code is read more than written
69
+ - **KISS** - Keep it simple, avoid over-engineering
70
+ - **DRY** - Don't repeat yourself
71
+ - **YAGNI** - Don't build features you don't need yet
128
72
 
129
- // Good - immutable
130
- const updatedUser = { ...user, name: 'new name' };
131
- const updatedItems = [...items, newItem];
132
- ```
73
+ ### Removing UI? Update Tests!
74
+ When removing or modifying UI elements:
75
+ 1. `grep -r "element text or testid" tests/` to find related tests
76
+ 2. Update or remove tests that reference removed elements
77
+ 3. Verify with: `grep -r "removed text" tests/ && exit 1 || echo "clean"`
133
78
 
134
79
  ### Error Handling
135
80
  Every async operation needs proper error handling:
136
81
  ```typescript
137
- // ✅ Good
138
82
  try {
139
83
  const data = await fetchData();
140
84
  return { success: true, data };
141
85
  } catch (error) {
142
- console.error('Failed to fetch data:', error);
86
+ console.error('Failed to fetch:', error);
143
87
  return { success: false, error: error.message };
144
88
  }
145
89
  ```
146
90
 
147
- ### Type Safety
148
- - Use TypeScript interfaces for all data shapes
149
- - Never use `any` - use `unknown` if type is truly unknown
150
- - Define return types for functions
151
-
152
- ### Functions
153
- - Max 50 lines per function (split if longer)
154
- - Single responsibility - one function does one thing
155
- - Early returns for guard clauses
156
-
157
- ### React Specific
158
- - Functional components with typed props
159
- - Custom hooks for reusable stateful logic
160
- - Use `prev =>` for state updates that depend on previous state
161
- - Avoid excessive ternaries - extract to variables or early returns
162
-
163
- ### General
164
- - Follow existing code patterns in the codebase
165
- - Handle ALL error cases defined in the story
166
- - Implement loading states for async operations
167
- - Use meaningful variable and function names
168
- - Add data-testid attributes for Playwright
169
-
170
- ## Architecture Rules
171
-
172
- - **Put files in the right place**: Follow the directories specified in the PRD
173
- - **Reuse existing code**: Check for existing components/utils before creating new ones
174
- - **Don't duplicate**: If something exists, import and use it
175
- - **Max 300 lines per file**: Split large files into smaller, focused modules
176
- - **Scripts in scripts/**: Shell scripts and CLI tools go in scripts/ or bin/
177
- - **Docs in docs/**: Documentation files go in docs/
178
- - **Single responsibility**: Each file/function does one thing well
179
-
180
- ## Scalability Rules
181
-
182
- For list/query endpoints:
183
- - **Always paginate**: Never return unbounded arrays
184
- - **Use cursor-based pagination**: When specified in the PRD
185
- - **Add database indexes**: For frequently queried fields
186
- - **Implement caching**: As specified in the PRD (TTL, invalidation)
187
- - **Eager load relationships**: To avoid N+1 queries
188
-
189
- For all endpoints:
190
- - **Rate limit public endpoints**: As specified in the PRD
191
- - **Set sensible limits**: Max page size, max request body size
192
- - **Batch operations**: Use bulk inserts when creating many records
193
-
194
- ## AI/LLM Configuration
195
-
196
- **NEVER hardcode AI model names, API keys, or endpoints.** Always use environment variables or settings.
197
-
198
- ```python
199
- # ❌ Bad - hardcoded model
200
- model = "gpt-4"
201
- client = OpenAI(api_key="sk-...")
202
-
203
- # ✅ Good - from environment/settings
204
- model = os.environ.get("OPENAI_MODEL", "gpt-4")
205
- client = OpenAI() # Uses OPENAI_API_KEY env var
206
- ```
91
+ ### Testing (Follow story.testing)
207
92
 
208
- ```python
209
- # Bad - hardcoded in code
210
- response = openai.chat.completions.create(
211
- model="gpt-4-turbo",
212
- max_tokens=4096,
213
- )
214
-
215
- # ✅ Good - from settings/config
216
- from django.conf import settings
217
- response = openai.chat.completions.create(
218
- model=settings.AI_MODEL,
219
- max_tokens=settings.AI_MAX_TOKENS,
220
- )
221
- ```
93
+ **Check `story.testing.approach`:**
94
+ - **TDD**: Write failing test FIRST, then implement to make it pass
95
+ - **test-after**: Implement first, then write tests
222
96
 
223
- If the project has an AI gateway or wrapper, use it:
224
- ```python
225
- # ✅ Best - use project's AI abstraction
226
- from myapp.ai import get_completion
227
- response = get_completion(prompt)
97
+ **Test Types** (from `story.testing.types`):
98
+ | Type | What to Test |
99
+ |------|--------------|
100
+ | `unit` | Individual functions/components in isolation |
101
+ | `integration` | How pieces work together (API + DB, Component + Hook) |
102
+ | `e2e` | Full user flows in browser |
103
+
104
+ **Test Files** (from `story.testing.files`):
105
+ Create the exact test files specified in the story.
106
+
107
+ **TDD Workflow:**
108
+ ```
109
+ 1. Write test for first acceptance criterion → FAIL
110
+ 2. Write minimum code to pass → PASS
111
+ 3. Refactor if needed
112
+ 4. Repeat for next criterion
228
113
  ```
229
114
 
230
115
  ---
231
116
 
117
+ ## Step 6: Verify
118
+
119
+ ### Run Test Steps
120
+ Execute each command in `story.testSteps[]`. All must pass.
121
+
122
+ ### Browser Verification (if story.mcp includes browser tools)
123
+ Use the MCP tools specified in `story.mcp[]`:
124
+
125
+ **Playwright MCP** (`playwright`):
126
+ - Navigate to `story.testUrl`
127
+ - Take screenshots to verify UI
128
+ - Click elements and fill forms
129
+ - Check accessibility
130
+
131
+ **Chrome DevTools MCP** (`devtools`):
132
+ - Check console for errors
133
+ - Inspect network requests
134
+ - Debug DOM issues
135
+
136
+ **Do NOT mark complete until:**
137
+ - All test steps pass
138
+ - Browser verification confirms it works
139
+ - Console has no errors
140
+
141
+ ---
142
+
143
+ ## Step 7: End Clean
144
+
145
+ After completing the story:
146
+
147
+ 1. **Update progress notes**
148
+ ```bash
149
+ echo "$(date): Completed TASK-XXX - [brief summary]" >> .ralph/progress.txt
150
+ ```
151
+
152
+ 2. **Note files changed**
153
+ - List files created/modified in progress.txt
154
+ - Note any key decisions made
155
+
156
+ 3. **Leave code ready for commit**
157
+ - No console.log or debug statements
158
+ - No commented-out code
159
+ - All tests passing
160
+
161
+ ---
162
+
163
+ ## Rules
164
+
165
+ 1. **Focus** - Implement ONLY the current story
166
+ 2. **Follow the PRD** - It has all the context you need
167
+ 3. **Read before coding** - Understand existing patterns first
168
+ 4. **Test frequently** - Run tests after each significant change
169
+ 5. **NEVER edit prd.json** - Ralph handles story completion
170
+ 6. **Don't give up** - If verification fails, fix and retry
171
+
172
+ ---
173
+
174
+ ## If Blocked
175
+
176
+ If you encounter a blocker you cannot resolve:
177
+ 1. Document the issue in `.ralph/progress.txt`
178
+ 2. Note what you tried and why it didn't work
179
+ 3. Suggest potential solutions
180
+ 4. Do NOT mark the story as passing
181
+
182
+ ---
183
+
232
184
  ## Current Story
233
185
 
234
- (Story details will be injected below by ralph.sh)
186
+ (Story ID will be provided below - read full details from .ralph/prd.json)
@@ -16,7 +16,7 @@
16
16
  "execPrefix": "docker compose exec -T"
17
17
  },
18
18
 
19
- "paths": {
19
+ "directories": {
20
20
  "frontend": "frontend",
21
21
  "backend": ".",
22
22
  "tests": "tests",
@@ -19,8 +19,9 @@
19
19
  - **Constants**: `SCREAMING_SNAKE` — e.g., `MAX_RETRIES`
20
20
 
21
21
  ## Tech Stack
22
- - **Frontend**: React 18, TypeScript, Vite, TailwindCSS
23
- - **Backend**: Django 5, Django REST Framework
22
+ <!-- Customize these for your project - detect from package.json/pyproject.toml -->
23
+ - **Frontend**: React, TypeScript, Vite, TailwindCSS
24
+ - **Backend**: Django, Django REST Framework
24
25
  - **Database**: PostgreSQL
25
26
  - **Cache/Queue**: Redis, Celery
26
27
  - **Testing**: pytest (backend), Vitest (frontend), Playwright (E2E)
@@ -9,7 +9,8 @@
9
9
  - **API endpoints**: `kebab-case` — e.g., `/api/user-profile`, `/api/auth/sign-in`
10
10
 
11
11
  ## Tech Stack
12
- - **Runtime**: Node.js 20+
12
+ <!-- Customize these for your project - detect from package.json -->
13
+ - **Runtime**: Node.js
13
14
  - **Framework**: Express.js / Fastify
14
15
  - **Language**: TypeScript
15
16
  - **Database**: PostgreSQL with Prisma
@@ -10,7 +10,8 @@
10
10
  - **CSS classes**: `kebab-case` (TailwindCSS utility classes are standard)
11
11
 
12
12
  ## Tech Stack
13
- - **Frontend**: React 18, TypeScript, Vite
13
+ <!-- Customize these for your project - detect from package.json -->
14
+ - **Frontend**: React, TypeScript, Vite
14
15
  - **Styling**: TailwindCSS
15
16
  - **State**: React Query for server state, Zustand for client state
16
17
  - **Testing**: Vitest, React Testing Library, Playwright
@@ -1,97 +1,34 @@
1
1
  # Nightly comprehensive test suite
2
- # Runs full tests + all PRD testSteps
2
+ # This is a minimal template. Run `npx agentic-loop ci install` to generate
3
+ # a workflow customized for your project structure.
3
4
 
4
5
  name: Nightly Tests
5
6
 
6
7
  on:
7
8
  schedule:
8
- # Run at 3am UTC every day
9
- - cron: '0 3 * * *'
10
- workflow_dispatch: # Allow manual trigger
9
+ - cron: '0 3 * * *' # 3am UTC daily
10
+ workflow_dispatch:
11
11
 
12
12
  jobs:
13
13
  test:
14
14
  runs-on: ubuntu-latest
15
-
16
- services:
17
- # Add postgres if your project needs it
18
- postgres:
19
- image: postgres:15
20
- env:
21
- POSTGRES_USER: test
22
- POSTGRES_PASSWORD: test
23
- POSTGRES_DB: test
24
- ports:
25
- - 5432:5432
26
- options: >-
27
- --health-cmd pg_isready
28
- --health-interval 10s
29
- --health-timeout 5s
30
- --health-retries 5
31
-
32
- env:
33
- DATABASE_URL: postgresql://test:test@localhost:5432/test
34
-
35
15
  steps:
36
16
  - uses: actions/checkout@v4
37
17
 
38
- # Python setup
39
- - name: Set up Python
40
- if: hashFiles('pyproject.toml') != '' || hashFiles('requirements.txt') != ''
41
- uses: actions/setup-python@v5
42
- with:
43
- python-version: '3.11'
44
-
45
- - name: Install Python dependencies
46
- if: hashFiles('pyproject.toml') != ''
47
- run: |
48
- pip install uv
49
- uv pip install -e ".[dev]" --system 2>/dev/null || pip install -e ".[dev]" 2>/dev/null || pip install -e . 2>/dev/null || true
50
-
51
- # Node.js setup
52
18
  - name: Set up Node.js
53
- if: hashFiles('package.json') != ''
54
19
  uses: actions/setup-node@v4
55
20
  with:
56
21
  node-version: '20'
57
- cache: 'npm'
58
22
 
59
- - name: Install Node dependencies
60
- if: hashFiles('package.json') != ''
61
- run: npm ci
23
+ - name: Install dependencies
24
+ run: npm ci 2>/dev/null || true
62
25
 
63
- # Run database migrations if needed
64
- - name: Run migrations
65
- if: hashFiles('alembic.ini') != ''
66
- run: alembic upgrade head
67
- continue-on-error: true
68
-
69
- # Python tests
70
- - name: Python tests
71
- if: hashFiles('pyproject.toml') != '' || hashFiles('pytest.ini') != ''
72
- run: |
73
- pytest -v --tb=short 2>/dev/null || python -m pytest -v --tb=short 2>/dev/null || true
74
-
75
- # Node tests
76
- - name: Node tests
77
- if: hashFiles('package.json') != ''
26
+ - name: Run tests
78
27
  run: npm test 2>/dev/null || true
79
28
 
80
- # PRD testSteps (if ralph is set up)
81
- - name: Install ralph
82
- run: npm install -g agentic-loop 2>/dev/null || true
83
-
84
29
  - name: Run PRD tests
85
30
  if: hashFiles('.ralph/prd.json') != ''
86
- run: ralph test prd 2>/dev/null || true
87
- continue-on-error: true
88
-
89
- # Coverage report
90
- - name: Coverage report
91
- if: hashFiles('pyproject.toml') != ''
92
- run: |
93
- pip install pytest-cov
94
- pytest --cov --cov-report=term-missing 2>/dev/null || true
31
+ run: npx agentic-loop test prd 2>/dev/null || true
95
32
  continue-on-error: true
96
33
 
97
34
  notify:
@@ -100,6 +37,4 @@ jobs:
100
37
  if: failure()
101
38
  steps:
102
39
  - name: Notify on failure
103
- run: |
104
- echo "Nightly tests failed! Check the workflow run for details."
105
- # Add Slack/Discord notification here if desired
40
+ run: echo "Nightly tests failed!"
@@ -1,5 +1,6 @@
1
1
  # Fast PR checks - lint only, no tests
2
- # Tests run in nightly workflow to keep PRs fast
2
+ # This is a minimal template. Run `npx agentic-loop ci install` to generate
3
+ # a workflow customized for your project structure.
3
4
 
4
5
  name: PR Check
5
6
 
@@ -13,44 +14,19 @@ jobs:
13
14
  steps:
14
15
  - uses: actions/checkout@v4
15
16
 
16
- # Python linting
17
- - name: Set up Python
18
- if: hashFiles('pyproject.toml') != '' || hashFiles('requirements.txt') != ''
19
- uses: actions/setup-python@v5
20
- with:
21
- python-version: '3.11'
22
-
23
- - name: Install Python dependencies
24
- if: hashFiles('pyproject.toml') != ''
25
- run: |
26
- pip install ruff
27
- pip install -e . 2>/dev/null || true
28
-
29
- - name: Ruff lint
30
- if: hashFiles('pyproject.toml') != '' || hashFiles('ruff.toml') != ''
31
- run: ruff check .
32
-
33
- # Node.js linting
34
17
  - name: Set up Node.js
35
- if: hashFiles('package.json') != ''
36
18
  uses: actions/setup-node@v4
37
19
  with:
38
20
  node-version: '20'
39
- cache: 'npm'
40
21
 
41
- - name: Install Node dependencies
42
- if: hashFiles('package.json') != ''
43
- run: npm ci
22
+ - name: Install dependencies
23
+ run: npm ci 2>/dev/null || true
44
24
 
45
- - name: ESLint
46
- if: hashFiles('package.json') != ''
47
- run: npm run lint 2>/dev/null || npx eslint . 2>/dev/null || true
25
+ - name: Lint
26
+ run: npm run lint 2>/dev/null || true
48
27
 
49
28
  - name: TypeScript check
50
- if: hashFiles('tsconfig.json') != ''
51
- run: npx tsc --noEmit
29
+ run: npx tsc --noEmit 2>/dev/null || true
52
30
 
53
- # Build check (catches import/bundling errors)
54
31
  - name: Build
55
- if: hashFiles('package.json') != ''
56
32
  run: npm run build 2>/dev/null || true
@@ -41,6 +41,13 @@
41
41
  "category": "frontend",
42
42
  "learnedFrom": null,
43
43
  "createdAt": "2026-01-20T00:00:00-08:00"
44
+ },
45
+ {
46
+ "id": "sign-007",
47
+ "pattern": "When removing or modifying UI elements, grep for related tests and update them - stale tests that check for removed elements will fail",
48
+ "category": "testing",
49
+ "learnedFrom": null,
50
+ "createdAt": "2026-01-25T00:00:00-08:00"
44
51
  }
45
52
  ]
46
53
  }