ccsetup 1.2.0 → 1.2.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.
- package/README.md +93 -24
- package/bin/create-project.js +373 -773
- package/lib/templates/README.md +2 -2
- package/lib/templates/metadata/agents.json +1 -1
- package/package.json +3 -2
- package/template/.claude/settings.json +18 -1
- package/template/.claude/skills/codex-review/SKILL.md +139 -0
- package/template/.claude/skills/secops/SKILL.md +259 -0
- package/template/.codex/skills/codex-review/SKILL.md +139 -0
- package/template/.codex/skills/prd/SKILL.md +343 -0
- package/template/.codex/skills/ralph/SKILL.md +339 -0
- package/template/AGENTS.md +43 -0
- package/template/CLAUDE.md +106 -4
- package/template/docs/codex-setup.md +32 -0
- package/template/hooks/codex-review/index.js +105 -0
- package/template/scripts/codex-review/codex-review.sh +266 -0
- package/template/scripts/ralph/CODEX.md +76 -0
- package/template/scripts/ralph/ralph.sh +32 -9
- package/bin/lib/contextGenerator.js +0 -287
- package/bin/lib/scanner/index.js +0 -28
- package/bin/scan.js +0 -367
- package/lib/aiMergeHelper.js +0 -112
- package/lib/contextGenerator.js +0 -574
- package/lib/contextMerger.js +0 -812
- package/lib/progressReporter.js +0 -88
- package/lib/scanConfig.js +0 -200
- package/lib/scanner/fileAnalyzer.js +0 -605
- package/lib/scanner/index.js +0 -164
- package/lib/scanner/patterns.js +0 -277
- package/lib/scanner/projectDetector.js +0 -147
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Codex Project Instructions
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
|
|
5
|
+
[Brief description of your project goes here]
|
|
6
|
+
|
|
7
|
+
## Primary Working Files
|
|
8
|
+
|
|
9
|
+
- `AGENTS.md` — project-specific guidance for Codex
|
|
10
|
+
- `.codex/skills/` — project-local Codex skills for this project (`prd`, `ralph`, `codex-review`)
|
|
11
|
+
- `docs/codex-setup.md` — Codex setup notes for this repo
|
|
12
|
+
- `docs/ROADMAP.md` — project goals and status
|
|
13
|
+
- `tickets/` — task tracking
|
|
14
|
+
- `plans/` — implementation and architecture plans
|
|
15
|
+
|
|
16
|
+
## Working Expectations
|
|
17
|
+
|
|
18
|
+
- Read this file before making changes.
|
|
19
|
+
- Check `docs/ROADMAP.md` and relevant tickets before starting non-trivial work.
|
|
20
|
+
- Prefer small, reviewable changes.
|
|
21
|
+
- Run the project quality checks before finishing.
|
|
22
|
+
|
|
23
|
+
## Repo Workflow
|
|
24
|
+
|
|
25
|
+
- Use plans in `plans/` for larger features.
|
|
26
|
+
- Track implementation work in `tickets/`.
|
|
27
|
+
- Use `scripts/codex-review/codex-review.sh` when you want a second-opinion review from Codex CLI.
|
|
28
|
+
- Use `scripts/ralph/ralph.sh --tool codex` for Ralph runs through Codex CLI.
|
|
29
|
+
|
|
30
|
+
## Codex Skills
|
|
31
|
+
|
|
32
|
+
This project ships project-local Codex skills in `.codex/skills/`, mirroring the Claude skill set:
|
|
33
|
+
|
|
34
|
+
- `prd`
|
|
35
|
+
- `ralph`
|
|
36
|
+
- `codex-review`
|
|
37
|
+
|
|
38
|
+
Keep these skills in the repository alongside `AGENTS.md` and the project docs.
|
|
39
|
+
|
|
40
|
+
## Project Conventions
|
|
41
|
+
|
|
42
|
+
- Update this file when you discover project-wide rules that future Codex sessions should know.
|
|
43
|
+
- Keep project-specific conventions here, and put reusable workflow guidance into project-local skills.
|
package/template/CLAUDE.md
CHANGED
|
@@ -17,10 +17,12 @@
|
|
|
17
17
|
├── CLAUDE.md # This file - project instructions for Claude
|
|
18
18
|
├── .claude/
|
|
19
19
|
│ ├── agents/ # 8 core agents (backend, blockchain, checker, coder, frontend, planner, researcher, shadcn)
|
|
20
|
-
│
|
|
20
|
+
│ ├── skills/ # /prd, /ralph, and /codex-review slash commands
|
|
21
|
+
│ └── hooks/ # Workflow selector and codex-review hooks
|
|
21
22
|
├── agents/ # Documentation only — see .claude/agents/ for active agents
|
|
22
23
|
├── scripts/
|
|
23
|
-
│
|
|
24
|
+
│ ├── ralph/ # Autonomous agent loop (ralph.sh + Claude/Codex instructions)
|
|
25
|
+
│ └── codex-review/ # Codex CLI review script (plans, implementations, code changes)
|
|
24
26
|
├── docs/ # Project documentation
|
|
25
27
|
├── plans/ # Project plans and architectural documents
|
|
26
28
|
└── tickets/ # Task tickets and issues
|
|
@@ -67,19 +69,24 @@
|
|
|
67
69
|
|
|
68
70
|
- **/prd** — Scans the codebase, then generates a structured PRD with real file paths and auto-detected quality criteria. Saves to `tasks/prd-[feature-name].md`.
|
|
69
71
|
- **/ralph** — Converts a PRD into `scripts/ralph/prd.json` for autonomous execution with quality checks and file hints per story.
|
|
72
|
+
- **/codex-review** — Reviews plans, validates implementations against plans, or reviews code changes. Auto-detects what to review based on context. Iterates up to 3 times.
|
|
73
|
+
- **/secops** — **NEVER install packages without running this first.** Scans dependencies for vulnerabilities using OSV Scanner. Use before any `pip`, `npm`, `cargo`, `gem`, or other package manager install.
|
|
70
74
|
|
|
71
75
|
## Ralph — Autonomous Agent Loop
|
|
72
76
|
|
|
73
77
|
Ralph implements user stories from a PRD one at a time in a loop, with subagent verification after each story.
|
|
74
78
|
|
|
75
79
|
```bash
|
|
76
|
-
./scripts/ralph/ralph.sh # Default: 10 iterations with
|
|
77
|
-
./scripts/ralph/ralph.sh --tool claude
|
|
80
|
+
./scripts/ralph/ralph.sh # Default: 10 iterations with Claude Code
|
|
81
|
+
./scripts/ralph/ralph.sh --tool claude # Use Claude Code explicitly
|
|
82
|
+
./scripts/ralph/ralph.sh --tool codex # Use Codex CLI
|
|
78
83
|
./scripts/ralph/ralph.sh --tool claude --model opus 20 # Specify model + iterations
|
|
79
84
|
```
|
|
80
85
|
|
|
81
86
|
Typical workflow: `/prd` → `/ralph` → `./scripts/ralph/ralph.sh`
|
|
82
87
|
|
|
88
|
+
Prerequisites: `jq` plus the CLI for whichever runner you use (`claude` by default, or `codex` for `--tool codex`).
|
|
89
|
+
|
|
83
90
|
## Agent Orchestration
|
|
84
91
|
|
|
85
92
|
See @docs/agent-orchestration.md for detailed workflow patterns on how to chain agents effectively.
|
|
@@ -95,6 +102,17 @@ export CCSETUP_WORKFLOW=1
|
|
|
95
102
|
|
|
96
103
|
When unset, the hook is inactive and Claude uses its default behavior. Install the hook with `npx ccsetup --install-hooks`.
|
|
97
104
|
|
|
105
|
+
## Codex Review Hook (Optional)
|
|
106
|
+
|
|
107
|
+
An optional hook that suggests running `/codex-review` when a plan file is modified or code changes are detected. Triggers on the `Stop` event.
|
|
108
|
+
|
|
109
|
+
To activate:
|
|
110
|
+
```bash
|
|
111
|
+
export CCSETUP_CODEX_REVIEW=1
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
When unset, the hook is inactive and produces no output.
|
|
115
|
+
|
|
98
116
|
## Tickets
|
|
99
117
|
|
|
100
118
|
See @tickets/README.md for ticket format and management approach
|
|
@@ -118,3 +136,87 @@ See @plans/README.md for planning documents and architectural decisions
|
|
|
118
136
|
## Additional Notes
|
|
119
137
|
|
|
120
138
|
[Any other important information for Claude to know about this project]
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
# 🔒 CRITICAL SECURITY - OSV-Scanner Requirement
|
|
143
|
+
|
|
144
|
+
> **MANDATORY SECOPS POLICY**: All dependency installations MUST be scanned with `osv-scanner` BEFORE installation. **NEVER install packages without scanning first. No exceptions.**
|
|
145
|
+
|
|
146
|
+
### Security Workflow - ALWAYS Follow This Order
|
|
147
|
+
|
|
148
|
+
**BEFORE installing ANY dependencies:**
|
|
149
|
+
|
|
150
|
+
1. **Query the OSV API to check the package before installing:**
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
curl -s -X POST "https://api.osv.dev/v1/query" \
|
|
154
|
+
-H "Content-Type: application/json" \
|
|
155
|
+
-d '{"package": {"name": "PACKAGE_NAME", "ecosystem": "ECOSYSTEM"}, "version": "VERSION"}'
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
| Package Manager | Ecosystem |
|
|
159
|
+
|---|---|
|
|
160
|
+
| pip | `PyPI` |
|
|
161
|
+
| npm/yarn/pnpm | `npm` |
|
|
162
|
+
| cargo | `crates.io` |
|
|
163
|
+
| go get | `Go` |
|
|
164
|
+
| gem | `RubyGems` |
|
|
165
|
+
| composer | `Packagist` |
|
|
166
|
+
| nuget | `NuGet` |
|
|
167
|
+
| maven | `Maven` |
|
|
168
|
+
|
|
169
|
+
- Empty `{}` = no known vulnerabilities → proceed
|
|
170
|
+
- Response contains `vulns` = **STOP**. Report to user, suggest safe version.
|
|
171
|
+
|
|
172
|
+
2. **Prepare the lockfile for scanning:**
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
osv-scanner scan -r .
|
|
176
|
+
|
|
177
|
+
# Or specific lockfile:
|
|
178
|
+
osv-scanner scan -L requirements.txt
|
|
179
|
+
osv-scanner scan -L package-lock.json
|
|
180
|
+
osv-scanner scan -L Cargo.lock
|
|
181
|
+
osv-scanner scan -L go.sum
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
3. **Review the scan results:**
|
|
185
|
+
|
|
186
|
+
- ❌ **If vulnerabilities are found:** STOP - Do NOT install. Report findings to the user and discuss mitigation options.
|
|
187
|
+
- ✅ **If scan is clean:** Proceed with installation.
|
|
188
|
+
|
|
189
|
+
4. **Only after clean scan, install dependencies.**
|
|
190
|
+
|
|
191
|
+
5. **After installation, rescan the entire project:**
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
osv-scanner scan -r .
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Critical Rules
|
|
198
|
+
|
|
199
|
+
1. **NEVER bypass osv-scanner** - This is a security requirement, not a suggestion
|
|
200
|
+
2. **NEVER install packages without scanning first** - No exceptions
|
|
201
|
+
3. **NEVER ignore osv-scanner warnings** - Always report vulnerabilities to the user
|
|
202
|
+
4. **ALWAYS rescan after installation** - Verify the installed state is secure
|
|
203
|
+
|
|
204
|
+
### Reporting Format
|
|
205
|
+
|
|
206
|
+
When vulnerabilities are found, present them clearly and block installation:
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
⚠️ Found 2 vulnerabilities — installation blocked pending review:
|
|
210
|
+
|
|
211
|
+
CRITICAL: lodash@4.17.20
|
|
212
|
+
- GHSA-35jh-r3h4-6jhm: Prototype Pollution
|
|
213
|
+
- Fix: upgrade to 4.17.21
|
|
214
|
+
|
|
215
|
+
HIGH: axios@0.21.1
|
|
216
|
+
- CVE-2021-3749: SSRF
|
|
217
|
+
- Fix: upgrade to 0.21.2
|
|
218
|
+
|
|
219
|
+
Upgrade affected packages?
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Use `/secops` for the full workflow including lockfile generation and vulnerability ignoring.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Codex Setup
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This project can be used with Codex CLI as well as Claude Code.
|
|
6
|
+
|
|
7
|
+
The Codex-facing project instructions live in `AGENTS.md`.
|
|
8
|
+
|
|
9
|
+
## Project-Local Skills
|
|
10
|
+
|
|
11
|
+
Project-local Codex skills are stored in:
|
|
12
|
+
|
|
13
|
+
```text
|
|
14
|
+
.codex/skills/
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The project-local skill set mirrors the Claude template:
|
|
18
|
+
|
|
19
|
+
- `prd`
|
|
20
|
+
- `ralph`
|
|
21
|
+
- `codex-review`
|
|
22
|
+
|
|
23
|
+
Keep these files in the project so Codex has project-specific workflow context alongside `AGENTS.md`.
|
|
24
|
+
|
|
25
|
+
## Suggested Workflow
|
|
26
|
+
|
|
27
|
+
1. Read `AGENTS.md`
|
|
28
|
+
2. Review `docs/ROADMAP.md`
|
|
29
|
+
3. Check relevant tickets and plans
|
|
30
|
+
4. Implement the change
|
|
31
|
+
5. Run the quality checks
|
|
32
|
+
6. Use `scripts/codex-review/codex-review.sh` for review when useful
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { execSync } = require('child_process');
|
|
6
|
+
|
|
7
|
+
// Environment variable toggle — exit early if not enabled
|
|
8
|
+
// Enable with: export CCSETUP_CODEX_REVIEW=1
|
|
9
|
+
const enabled = process.env.CCSETUP_CODEX_REVIEW;
|
|
10
|
+
if (!enabled || (enabled !== '1' && enabled.toLowerCase() !== 'true')) {
|
|
11
|
+
console.log('{}');
|
|
12
|
+
process.exit(0);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const PLAN_DIRS = ['plans'];
|
|
16
|
+
const PLAN_PATTERN = /plan.*\.md$/i;
|
|
17
|
+
const RECENCY_THRESHOLD_MS = 60 * 1000;
|
|
18
|
+
|
|
19
|
+
function findRecentlyModifiedPlans() {
|
|
20
|
+
const now = Date.now();
|
|
21
|
+
const recentPlans = [];
|
|
22
|
+
|
|
23
|
+
for (const dir of PLAN_DIRS) {
|
|
24
|
+
const fullDir = path.join(process.cwd(), dir);
|
|
25
|
+
if (!fs.existsSync(fullDir)) continue;
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const files = fs.readdirSync(fullDir);
|
|
29
|
+
for (const file of files) {
|
|
30
|
+
if (!file.endsWith('.md')) continue;
|
|
31
|
+
const filePath = path.join(fullDir, file);
|
|
32
|
+
const stats = fs.statSync(filePath);
|
|
33
|
+
if (now - stats.mtimeMs < RECENCY_THRESHOLD_MS) {
|
|
34
|
+
recentPlans.push(filePath);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
} catch (err) {
|
|
38
|
+
// Skip directories we can't read
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Also check for *plan*.md files in the project root
|
|
43
|
+
try {
|
|
44
|
+
const rootFiles = fs.readdirSync(process.cwd());
|
|
45
|
+
for (const file of rootFiles) {
|
|
46
|
+
if (PLAN_PATTERN.test(file)) {
|
|
47
|
+
const filePath = path.join(process.cwd(), file);
|
|
48
|
+
const stats = fs.statSync(filePath);
|
|
49
|
+
if (stats.isFile() && now - stats.mtimeMs < RECENCY_THRESHOLD_MS) {
|
|
50
|
+
recentPlans.push(filePath);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} catch (err) {
|
|
55
|
+
// Skip if we can't read root
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return recentPlans;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function hasGitChanges() {
|
|
62
|
+
try {
|
|
63
|
+
execSync('git diff HEAD --quiet', { stdio: 'pipe' });
|
|
64
|
+
return false;
|
|
65
|
+
} catch (err) {
|
|
66
|
+
// Exit code 1 = diff found changes; other codes = command failed (e.g., no HEAD, not a repo)
|
|
67
|
+
if (err.status === 1) return true;
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Main — reads from stdin as Claude Code provides
|
|
73
|
+
let inputData = '';
|
|
74
|
+
|
|
75
|
+
process.stdin.on('data', (chunk) => {
|
|
76
|
+
inputData += chunk;
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
process.stdin.on('end', () => {
|
|
80
|
+
try {
|
|
81
|
+
const recentPlans = findRecentlyModifiedPlans();
|
|
82
|
+
const gitChanges = hasGitChanges();
|
|
83
|
+
let output = {};
|
|
84
|
+
|
|
85
|
+
if (recentPlans.length > 0 && gitChanges) {
|
|
86
|
+
const planNames = recentPlans.map(p => path.basename(p)).join(', ');
|
|
87
|
+
output = {
|
|
88
|
+
message: `Plan updated with code changes. Run /codex-review to validate implementation. (${planNames})`
|
|
89
|
+
};
|
|
90
|
+
} else if (recentPlans.length > 0) {
|
|
91
|
+
const planNames = recentPlans.map(p => path.basename(p)).join(', ');
|
|
92
|
+
output = {
|
|
93
|
+
message: `Plan created. Run /codex-review for a second opinion from Codex CLI. (${planNames})`
|
|
94
|
+
};
|
|
95
|
+
} else if (gitChanges) {
|
|
96
|
+
output = {
|
|
97
|
+
message: `Code changes detected. Run /codex-review for a code review from Codex CLI.`
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
console.log(JSON.stringify(output));
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.log('{}');
|
|
104
|
+
}
|
|
105
|
+
});
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# codex-review.sh — Review plans, implementations, or code changes via Codex CLI
|
|
3
|
+
# Usage: codex-review.sh [plan-file-or--] [--model <model>]
|
|
4
|
+
# No arguments: reviews git changes (code review)
|
|
5
|
+
# With plan file: reviews plan, or plan+implementation if git changes exist
|
|
6
|
+
#
|
|
7
|
+
# Exit codes:
|
|
8
|
+
# 0 = success
|
|
9
|
+
# 1 = codex CLI not installed / nothing to review
|
|
10
|
+
# 2 = auth/API error
|
|
11
|
+
# 3 = timeout
|
|
12
|
+
|
|
13
|
+
set -euo pipefail
|
|
14
|
+
|
|
15
|
+
PLAN_FILE=""
|
|
16
|
+
PLAN_CONTENT=""
|
|
17
|
+
DIFF_CONTENT=""
|
|
18
|
+
MODEL="${CODEX_REVIEW_MODEL:-}"
|
|
19
|
+
TIMEOUT=120
|
|
20
|
+
MAX_DIFF_CHARS=50000
|
|
21
|
+
|
|
22
|
+
if command -v timeout &>/dev/null; then
|
|
23
|
+
TIMEOUT_CMD="timeout"
|
|
24
|
+
elif command -v gtimeout &>/dev/null; then
|
|
25
|
+
TIMEOUT_CMD="gtimeout"
|
|
26
|
+
else
|
|
27
|
+
TIMEOUT_CMD=""
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
while [[ $# -gt 0 ]]; do
|
|
31
|
+
case $1 in
|
|
32
|
+
--model)
|
|
33
|
+
MODEL="$2"
|
|
34
|
+
shift 2
|
|
35
|
+
;;
|
|
36
|
+
--model=*)
|
|
37
|
+
MODEL="${1#*=}"
|
|
38
|
+
shift
|
|
39
|
+
;;
|
|
40
|
+
-)
|
|
41
|
+
PLAN_FILE="-"
|
|
42
|
+
shift
|
|
43
|
+
;;
|
|
44
|
+
*)
|
|
45
|
+
if [[ -z "$PLAN_FILE" ]]; then
|
|
46
|
+
PLAN_FILE="$1"
|
|
47
|
+
fi
|
|
48
|
+
shift
|
|
49
|
+
;;
|
|
50
|
+
esac
|
|
51
|
+
done
|
|
52
|
+
|
|
53
|
+
# Check prerequisites
|
|
54
|
+
if ! command -v codex &>/dev/null; then
|
|
55
|
+
echo "Error: codex CLI is not installed. Install it with: npm install -g @openai/codex" >&2
|
|
56
|
+
exit 1
|
|
57
|
+
fi
|
|
58
|
+
|
|
59
|
+
# Read plan content (optional — only when a plan file is provided)
|
|
60
|
+
if [[ "$PLAN_FILE" == "-" ]]; then
|
|
61
|
+
PLAN_CONTENT=$(cat)
|
|
62
|
+
elif [[ -n "$PLAN_FILE" && -f "$PLAN_FILE" ]]; then
|
|
63
|
+
PLAN_CONTENT=$(cat "$PLAN_FILE")
|
|
64
|
+
elif [[ -n "$PLAN_FILE" ]]; then
|
|
65
|
+
echo "Error: Plan file not found: $PLAN_FILE" >&2
|
|
66
|
+
exit 1
|
|
67
|
+
fi
|
|
68
|
+
|
|
69
|
+
# Gather git diff (silently skips if git unavailable or not in a repo)
|
|
70
|
+
gather_git_diff() {
|
|
71
|
+
if ! command -v git &>/dev/null; then return; fi
|
|
72
|
+
if ! git rev-parse --is-inside-work-tree &>/dev/null 2>&1; then return; fi
|
|
73
|
+
|
|
74
|
+
DIFF_CONTENT=$(git diff HEAD 2>/dev/null || true)
|
|
75
|
+
|
|
76
|
+
if [[ -z "$DIFF_CONTENT" ]]; then
|
|
77
|
+
DIFF_CONTENT=$(git diff HEAD~1..HEAD 2>/dev/null || true)
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
# Fallback for initial commit (no HEAD yet) or staged-only changes
|
|
81
|
+
if [[ -z "$DIFF_CONTENT" ]]; then
|
|
82
|
+
DIFF_CONTENT=$(git diff --cached 2>/dev/null || true)
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
if [[ -n "$DIFF_CONTENT" && ${#DIFF_CONTENT} -gt $MAX_DIFF_CHARS ]]; then
|
|
86
|
+
DIFF_CONTENT="${DIFF_CONTENT:0:$MAX_DIFF_CHARS}
|
|
87
|
+
|
|
88
|
+
[... diff truncated at ${MAX_DIFF_CHARS} characters ...]"
|
|
89
|
+
fi
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
gather_git_diff
|
|
93
|
+
|
|
94
|
+
# Must have at least a plan or git changes to review
|
|
95
|
+
if [[ -z "$PLAN_CONTENT" && -z "$DIFF_CONTENT" ]]; then
|
|
96
|
+
echo "Error: No plan file or git changes found. Nothing to review." >&2
|
|
97
|
+
echo "Usage: codex-review.sh [plan-file-or--] [--model <model>]" >&2
|
|
98
|
+
exit 1
|
|
99
|
+
fi
|
|
100
|
+
|
|
101
|
+
CMD_ARGS=()
|
|
102
|
+
if [[ -n "$MODEL" ]]; then
|
|
103
|
+
CMD_ARGS+=(--model "$MODEL")
|
|
104
|
+
fi
|
|
105
|
+
|
|
106
|
+
# Build prompt based on available inputs
|
|
107
|
+
if [[ -n "$PLAN_CONTENT" && -n "$DIFF_CONTENT" ]]; then
|
|
108
|
+
# Implementation review: validate code changes against the plan
|
|
109
|
+
REVIEW_PROMPT="You are a senior architect reviewing an implementation against its plan. Validate that the code changes correctly fulfill the plan requirements.
|
|
110
|
+
|
|
111
|
+
## Plan
|
|
112
|
+
|
|
113
|
+
$PLAN_CONTENT
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Implementation (git diff)
|
|
118
|
+
|
|
119
|
+
$DIFF_CONTENT
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
Provide a structured review covering:
|
|
124
|
+
|
|
125
|
+
## Plan Compliance
|
|
126
|
+
- Which plan requirements are correctly implemented?
|
|
127
|
+
- Which plan requirements are missing or incomplete?
|
|
128
|
+
- Any divergence from the planned approach?
|
|
129
|
+
|
|
130
|
+
## Acceptance Criteria
|
|
131
|
+
- For each acceptance criterion in the plan, is it met by the implementation?
|
|
132
|
+
- List any unmet criteria explicitly
|
|
133
|
+
|
|
134
|
+
## Code Quality
|
|
135
|
+
- Are there bugs or logic errors in the implementation?
|
|
136
|
+
- Security concerns in the changed code?
|
|
137
|
+
- Performance issues?
|
|
138
|
+
|
|
139
|
+
## Suggestions
|
|
140
|
+
- Specific issues to fix before merging
|
|
141
|
+
- Missing tests or validation
|
|
142
|
+
- Improvements to better match the plan
|
|
143
|
+
|
|
144
|
+
Be direct and specific. Reference exact file paths and line ranges from the diff."
|
|
145
|
+
|
|
146
|
+
elif [[ -n "$PLAN_CONTENT" ]]; then
|
|
147
|
+
# Plan review: architectural review of the plan itself
|
|
148
|
+
REVIEW_PROMPT="You are a senior architect reviewing this plan. Provide a structured review covering:
|
|
149
|
+
|
|
150
|
+
## Architecture Review
|
|
151
|
+
- Are the technical choices sound?
|
|
152
|
+
- Are there simpler alternatives?
|
|
153
|
+
- Any missing dependencies or integration concerns?
|
|
154
|
+
|
|
155
|
+
## Risk Assessment
|
|
156
|
+
- What could go wrong?
|
|
157
|
+
- What edge cases are unhandled?
|
|
158
|
+
- Any security or performance concerns?
|
|
159
|
+
|
|
160
|
+
## Suggestions
|
|
161
|
+
- Specific improvements with rationale
|
|
162
|
+
- Missing acceptance criteria
|
|
163
|
+
- Implementation order concerns
|
|
164
|
+
|
|
165
|
+
Be direct and specific. Reference exact sections of the plan.
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
Plan to review:
|
|
170
|
+
|
|
171
|
+
$PLAN_CONTENT"
|
|
172
|
+
|
|
173
|
+
else
|
|
174
|
+
# Code review: standalone review of git changes
|
|
175
|
+
REVIEW_PROMPT="You are a senior engineer performing a code review. Review the following code changes for quality, correctness, and best practices.
|
|
176
|
+
|
|
177
|
+
## Code Changes (git diff)
|
|
178
|
+
|
|
179
|
+
$DIFF_CONTENT
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
Provide a structured review covering:
|
|
184
|
+
|
|
185
|
+
## Bugs and Correctness
|
|
186
|
+
- Logic errors or incorrect behavior
|
|
187
|
+
- Missing null/error handling
|
|
188
|
+
- Off-by-one errors or boundary conditions
|
|
189
|
+
|
|
190
|
+
## Security
|
|
191
|
+
- Injection vulnerabilities
|
|
192
|
+
- Exposed secrets or credentials
|
|
193
|
+
- Missing input validation
|
|
194
|
+
|
|
195
|
+
## Performance
|
|
196
|
+
- Unnecessary computations or allocations
|
|
197
|
+
- Inefficient patterns
|
|
198
|
+
- Missing caching opportunities
|
|
199
|
+
|
|
200
|
+
## Code Quality
|
|
201
|
+
- Naming and readability
|
|
202
|
+
- Adherence to existing code conventions
|
|
203
|
+
- Dead code or unnecessary complexity
|
|
204
|
+
|
|
205
|
+
## Suggestions
|
|
206
|
+
- Specific improvements with rationale
|
|
207
|
+
- Missing tests
|
|
208
|
+
- Documentation gaps
|
|
209
|
+
|
|
210
|
+
Be direct and specific. Reference exact file paths and line ranges from the diff."
|
|
211
|
+
fi
|
|
212
|
+
|
|
213
|
+
# Run codex exec with timeout (if available)
|
|
214
|
+
# Temporarily disable exit-on-error to capture the actual exit code before
|
|
215
|
+
# checking it. Using "if ! OUTPUT=$(cmd)" sets $? to 0 inside the then-block
|
|
216
|
+
# (the negated result), making timeout detection (exit 124) impossible.
|
|
217
|
+
set +e
|
|
218
|
+
if [[ -n "$TIMEOUT_CMD" ]]; then
|
|
219
|
+
OUTPUT=$($TIMEOUT_CMD "${TIMEOUT}s" codex exec ${CMD_ARGS[@]+"${CMD_ARGS[@]}"} "$REVIEW_PROMPT" 2>&1)
|
|
220
|
+
else
|
|
221
|
+
OUTPUT=$(codex exec ${CMD_ARGS[@]+"${CMD_ARGS[@]}"} "$REVIEW_PROMPT" 2>&1)
|
|
222
|
+
fi
|
|
223
|
+
EXIT_CODE=$?
|
|
224
|
+
set -e
|
|
225
|
+
|
|
226
|
+
if [[ $EXIT_CODE -ne 0 ]]; then
|
|
227
|
+
if [[ $EXIT_CODE -eq 124 ]]; then
|
|
228
|
+
echo "Error: Codex review timed out after ${TIMEOUT}s. Try a shorter plan or increase TIMEOUT." >&2
|
|
229
|
+
exit 3
|
|
230
|
+
fi
|
|
231
|
+
|
|
232
|
+
if echo "$OUTPUT" | grep -qi "login\|log in\|sign in\|authenticate first"; then
|
|
233
|
+
echo "Error: Codex CLI requires login. Run 'codex login' first." >&2
|
|
234
|
+
exit 2
|
|
235
|
+
fi
|
|
236
|
+
|
|
237
|
+
if echo "$OUTPUT" | grep -qi "auth\|unauthorized\|api.key\|invalid.*key\|forbidden\|permission denied"; then
|
|
238
|
+
echo "Error: Codex authentication failed. Check your OpenAI API key." >&2
|
|
239
|
+
echo "$OUTPUT" >&2
|
|
240
|
+
exit 2
|
|
241
|
+
fi
|
|
242
|
+
|
|
243
|
+
if echo "$OUTPUT" | grep -qi "rate.limit\|too many requests\|429\|quota\|exceeded.*limit"; then
|
|
244
|
+
echo "Error: Rate limited by OpenAI API. Wait a moment and try again." >&2
|
|
245
|
+
echo "$OUTPUT" >&2
|
|
246
|
+
exit 2
|
|
247
|
+
fi
|
|
248
|
+
|
|
249
|
+
if echo "$OUTPUT" | grep -qi "network\|connect\|ECONNREFUSED\|ENOTFOUND\|DNS\|resolve\|unreachable\|timed out"; then
|
|
250
|
+
echo "Error: Network error. Check your internet connection." >&2
|
|
251
|
+
echo "$OUTPUT" >&2
|
|
252
|
+
exit 2
|
|
253
|
+
fi
|
|
254
|
+
|
|
255
|
+
if echo "$OUTPUT" | grep -qi "model.*not found\|does not exist\|invalid.*model\|unknown model"; then
|
|
256
|
+
echo "Error: Invalid model '${MODEL:-default}'. Check available models with 'codex --help'." >&2
|
|
257
|
+
echo "$OUTPUT" >&2
|
|
258
|
+
exit 2
|
|
259
|
+
fi
|
|
260
|
+
|
|
261
|
+
echo "Error: Codex review failed (exit code $EXIT_CODE)" >&2
|
|
262
|
+
echo "$OUTPUT" >&2
|
|
263
|
+
exit 2
|
|
264
|
+
fi
|
|
265
|
+
|
|
266
|
+
echo "$OUTPUT"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Ralph Agent Instructions for Codex
|
|
2
|
+
|
|
3
|
+
You are an autonomous coding agent working on a software project through the Codex CLI.
|
|
4
|
+
|
|
5
|
+
## Your Task
|
|
6
|
+
|
|
7
|
+
1. Read the PRD at `prd.json` in this directory.
|
|
8
|
+
2. Read the progress log at `progress.txt` and check the `## Codebase Patterns` section first.
|
|
9
|
+
3. Check out or create the branch named in `prd.json` under `branchName`.
|
|
10
|
+
4. Pick the highest-priority user story where `passes` is `false`.
|
|
11
|
+
5. Read the story's `notes` for file hints and context.
|
|
12
|
+
6. Implement exactly that one story.
|
|
13
|
+
7. Run every exact quality check command from `prd.json` → `qualityChecks`.
|
|
14
|
+
8. Independently verify the implementation against the acceptance criteria.
|
|
15
|
+
9. If verification passes, commit all changes with `feat: [Story ID] - [Story Title]`.
|
|
16
|
+
10. If verification fails, fix the issues, rerun quality checks, and verify again.
|
|
17
|
+
11. Update `prd.json` to set `passes: true` and replace `notes` with what was actually done.
|
|
18
|
+
12. Add reusable learnings to nearby `AGENTS.md` files when they would help future work.
|
|
19
|
+
13. Append a progress entry to `progress.txt`.
|
|
20
|
+
|
|
21
|
+
## Quality Checks
|
|
22
|
+
|
|
23
|
+
- Use the exact commands in `qualityChecks`. Do not guess or substitute.
|
|
24
|
+
- If `qualityChecks` is missing, detect commands from project config files before proceeding.
|
|
25
|
+
- All quality checks must pass before verification.
|
|
26
|
+
|
|
27
|
+
## Verification
|
|
28
|
+
|
|
29
|
+
Verification must be independent from implementation. Review your changes against:
|
|
30
|
+
|
|
31
|
+
- every acceptance criterion in the selected story
|
|
32
|
+
- the exact files changed in the working tree
|
|
33
|
+
- the results of all quality checks
|
|
34
|
+
|
|
35
|
+
Report verification in your reasoning and in `progress.txt` as either:
|
|
36
|
+
|
|
37
|
+
- `APPROVED`
|
|
38
|
+
- `CHANGES_REQUESTED`
|
|
39
|
+
|
|
40
|
+
If changes are requested, fix them and repeat. Stop after 3 review cycles for one story. If it still fails, log the issues in `progress.txt` and leave `passes` as `false`.
|
|
41
|
+
|
|
42
|
+
For UI stories that include "Verify in browser using dev-browser skill", perform that verification if browser tools are available. Otherwise note that manual browser verification is still needed.
|
|
43
|
+
|
|
44
|
+
## Progress Entry Format
|
|
45
|
+
|
|
46
|
+
Append to `progress.txt`:
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
## [Date/Time] - [Story ID]
|
|
50
|
+
- What was implemented
|
|
51
|
+
- Files changed
|
|
52
|
+
- Review result: [APPROVED / CHANGES_REQUESTED → fixed → APPROVED]
|
|
53
|
+
- Review cycles: [1-3]
|
|
54
|
+
- Learnings for future iterations:
|
|
55
|
+
- Patterns discovered
|
|
56
|
+
- Gotchas encountered
|
|
57
|
+
- Useful context
|
|
58
|
+
- Reviewer catches
|
|
59
|
+
---
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
If you discover a reusable rule for future iterations, add it to the `## Codebase Patterns` section at the top of `progress.txt`.
|
|
63
|
+
|
|
64
|
+
## Stop Condition
|
|
65
|
+
|
|
66
|
+
After completing one story, check whether all stories in `prd.json` have `passes: true`.
|
|
67
|
+
|
|
68
|
+
- If all stories pass, output exactly `<promise>COMPLETE</promise>`.
|
|
69
|
+
- Otherwise end normally so the next iteration can continue.
|
|
70
|
+
|
|
71
|
+
## Important
|
|
72
|
+
|
|
73
|
+
- Work on one story per iteration.
|
|
74
|
+
- Commit only after verification approves the changes.
|
|
75
|
+
- Keep the repository green with the exact quality check commands.
|
|
76
|
+
- Read both `progress.txt` patterns and story `notes` before making changes.
|