Skip to content
Back to search

PolyArch

MarketplaceWorks with Claude CodeGitHub

From Automated Idea Factory to Realization

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/polyarch--humanize/badge.svg)](/listings/polyarch--humanize)

HTML

<a href="/listings/polyarch--humanize"><img src="/api/listings/polyarch--humanize/badge.svg" alt="findsafeskills safety rating" /></a>

Install

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

# Add PolyArch marketplace
/plugin marketplace add PolyArch/humanize
# If you want to use development branch for experimental features
/plugin marketplace add PolyArch/humanize#dev
# Then install humanize plugin
/plugin install humanize@PolyArch

Requires [codex CLI](https://github.com/openai/codex) for review. See the full [Installation Guide](docs/install-for-claude.md) for prerequisites and alternative setup options.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

.claude-plugin/marketplace.json · Manifest · 14 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. {
  2. "name": "PolyArch",
  3. "owner": {
  4. "name": "PolyArch"
  5. },
  6. "plugins": [
  7. {
  8. "name": "humanize",
  9. "source": "./",
  10. "description": "Humanize - An iterative development plugin that uses Codex to review Claude's work. Creates a feedback loop where Claude implements plans and Codex independently reviews progress, ensuring quality through continuous refinement.",
  11. "version": "1.16.0"
  12. }
  13. ]
  14. }
README.md · README · 99 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. * 🚀 [Humanize2](https://github.com/humanfia/humanize2) is under active developments and we are looking for your feedbacks!
  2. * ✨ Now humanize has a [cool homepage](https://humanfia.ai/)!
  3. # Humanize
  4. **Current Version: 1.16.0**
  5. > Derived from the [GAAC (GitHub-as-a-Context)](https://github.com/SihaoLiu/gaac) project.
  6. A Claude Code plugin that provides iterative development with independent AI review. Build with confidence through continuous feedback loops.
  7. ## What is RLCR?
  8. **RLCR** stands for **Ralph-Loop with Codex Review**, inspired by the official ralph-loop plugin and enhanced with independent Codex review. The name also reads as **Reinforcement Learning with Code Review** -- reflecting the iterative cycle where AI-generated code is continuously refined through external review feedback.
  9. ## Core Concepts
  10. - **Iteration over Perfection** -- Instead of expecting perfect output in one shot, Humanize leverages continuous feedback loops where issues are caught early and refined incrementally.
  11. - **One Build + One Review** -- Claude implements, Codex independently reviews. No blind spots.
  12. - **Ralph Loop with Swarm Mode** -- Iterative refinement continues until all acceptance criteria are met. Optionally parallelize with Agent Teams.
  13. - **Begin with the End in Mind** -- Before the loop starts, Humanize verifies that *you* understand the plan you are about to execute. The human must remain the architect. ([Details](docs/usage.md#begin-with-the-end-in-mind))
  14. ## How It Works
  15. <p align="center">
  16. <img src="docs/images/rlcr-workflow.svg" alt="RLCR Workflow" width="680"/>
  17. </p>
  18. The loop has two phases: **Implementation** (Claude works, Codex reviews summaries) and **Code Review** (Codex checks code quality with severity markers). Issues feed back into implementation until resolved.
  19. ## Install
  20. ```bash
  21. # Add PolyArch marketplace
  22. /plugin marketplace add PolyArch/humanize
  23. # If you want to use development branch for experimental features
  24. /plugin marketplace add PolyArch/humanize#dev
  25. # Then install humanize plugin
  26. /plugin install humanize@PolyArch
  27. ```
  28. Requires [codex CLI](https://github.com/openai/codex) for review. See the full [Installation Guide](docs/install-for-claude.md) for prerequisites and alternative setup options.
  29. ## Quick Start
  30. 1. **Generate an idea draft** from a loose thought (optional — skip if you already have a draft):
  31. ```bash
  32. /humanize:gen-idea "add undo/redo to the editor"
  33. ```
  34. Output goes to `.humanize/ideas/<slug>-<timestamp>.md` by default. Pass a `.md` path to expand existing rough notes. `--n` controls how many parallel directions explore the idea (default 6).
  35. 2. **Generate a plan** from your draft:
  36. ```bash
  37. /humanize:gen-plan --input draft.md --output docs/plan.md
  38. ```
  39. 3. **Refine an annotated plan** before implementation when reviewers add comments (`CMT:` ... `ENDCMT`, `<cmt>` ... `</cmt>`, or `<comment>` ... `</comment>`):
  40. ```bash
  41. /humanize:refine-plan --input docs/plan.md
  42. ```
  43. 4. **Run the loop**:
  44. ```bash
  45. /humanize:start-rlcr-loop docs/plan.md
  46. ```
  47. 5. **Consult Gemini** for deep web research (requires Gemini CLI):
  48. ```bash
  49. /humanize:ask-gemini What are the latest best practices for X?
  50. ```
  51. 6. **Monitor progress (in another terminal, not inside Claude Code)**:
  52. ```bash
  53. source <path/to/humanize>/scripts/humanize.sh # Or just add it into your .bashec or .zshrc
  54. humanize monitor rlcr # RLCR loop
  55. humanize monitor skill # All skill invocations (codex + gemini)
  56. humanize monitor codex # Codex invocations only
  57. humanize monitor gemini # Gemini invocations only
  58. ```
  59. ## Monitor Dashboard
  60. <p align="center">
  61. <img src="docs/images/monitor.png" alt="Humanize Monitor" width="680"/>
  62. </p>
  63. ## Documentation
  64. - [Usage Guide](docs/usage.md) -- Commands, options, environment variables
  65. - [Install for Claude Code](docs/install-for-claude.md) -- Full installation instructions
  66. - [Install for Codex](docs/install-for-codex.md) -- Codex skill runtime setup
  67. - [Install for Kimi](docs/install-for-kimi.md) -- Kimi CLI skill setup
  68. - [Configuration](docs/usage.md#configuration) -- Shared config hierarchy and override rules
  69. - [Bitter Lesson Workflow](docs/bitlesson.md) -- Project memory, selector routing, and delta validation
  70. ## License
  71. MIT
scripts/setup-rlcr-loop.sh · Bundled script · 1,541 lines · 1 finding marked
  1. #!/usr/bin/env bash
  2. #
  3. # Setup script for start-rlcr-loop
  4. #
  5. # Creates state files for the loop that uses Codex to review Claude's work.
  6. #
  7. # Usage:
  8. # setup-rlcr-loop.sh <path/to/plan.md> [--max N] [--codex-model MODEL:EFFORT]
  9. #
  10. set -euo pipefail
  11. # ========================================
  12. # Default Configuration
  13. # ========================================
  14. # DEFAULT_CODEX_MODEL and DEFAULT_CODEX_EFFORT are provided by loop-common.sh
  15. DEFAULT_CODEX_TIMEOUT=5400
  16. DEFAULT_MAX_ITERATIONS=42
  17. DEFAULT_FULL_REVIEW_ROUND=5
  18. # Default timeout for git operations (30 seconds)
  19. GIT_TIMEOUT=30
  20. # Source portable timeout wrapper
  21. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
  22. source "$SCRIPT_DIR/portable-timeout.sh"
  23. # Source shared loop library (provides runtime-aware DEFAULT_CODEX_MODEL and other constants)
  24. # Callers can override by exporting DEFAULT_CODEX_MODEL/DEFAULT_CODEX_EFFORT/DEFAULT_AGENT_TEAMS
  25. # before invoking this script.
  26. HOOKS_LIB_DIR="$(cd "$SCRIPT_DIR/../hooks/lib" && pwd)"
  27. source "$HOOKS_LIB_DIR/loop-common.sh"
  28. # ========================================
  29. # Parse Arguments
  30. # ========================================
  31. PLAN_FILE=""
  32. PLAN_FILE_EXPLICIT=""
  33. TRACK_PLAN_FILE="false"
  34. MAX_ITERATIONS="$DEFAULT_MAX_ITERATIONS"
  35. CODEX_MODEL="$DEFAULT_CODEX_MODEL"
  36. CODEX_EFFORT="$DEFAULT_CODEX_EFFORT"
  37. CODEX_TIMEOUT="$DEFAULT_CODEX_TIMEOUT"
  38. PUSH_EVERY_ROUND="false"
  39. BASE_BRANCH=""
  40. FULL_REVIEW_ROUND="$DEFAULT_FULL_REVIEW_ROUND"
  41. SKIP_IMPL="false"
  42. SKIP_IMPL_NO_PLAN="false"
  43. SKIP_IMPL_PLAN_ANCHORED="false"
  44. ASK_CODEX_QUESTION="true"
  45. AGENT_TEAMS="${DEFAULT_AGENT_TEAMS:-false}"
  46. BITLESSON_ALLOW_EMPTY_NONE="true"
  47. PRIVACY_MODE="false"
  48. extract_plan_goal_content() {
  49. local plan_path="$1"
  50. local goal_section=""
  51. goal_section=$({ sed -n '/^##[[:space:]]*[Gg]oal\|^##[[:space:]]*[Oo]bjective\|^##[[:space:]]*[Pp]urpose/,/^##/p' "$plan_path" 2>/dev/null || true; } | head -20 | tail -n +2 | head -10)
  52. if [[ -n "$goal_section" ]]; then
  53. printf '%s\n' "$goal_section"
  54. return
  55. fi
  56. awk '
  57. /^[[:space:]]*#/ { next }
  58. /^[[:space:]]*$/ {
  59. if (started) {
  60. exit
  61. }
  62. next
  63. }
  64. {
  65. print
  66. started=1
  67. lines++
  68. if (lines >= 5) {
  69. exit
  70. }
  71. }
  72. ' "$plan_path"
  73. }
  74. extract_plan_ac_content() {
  75. local plan_path="$1"
  76. { sed -n '/^##[[:space:]]*[Aa]cceptance\|^##[[:space:]]*[Cc]riteria\|^##[[:space:]]*[Rr]equirements/,/^##/p' "$plan_path" 2>/dev/null || true; } | head -30 | tail -n +2 | head -25
  77. }
  78. show_help() {
  79. cat <<HELP_EOF
  80. start-rlcr-loop - Iterative development with Codex review
  81. USAGE:
  82. /humanize:start-rlcr-loop <path/to/plan.md> [OPTIONS]
  83. ARGUMENTS:
  84. <path/to/plan.md> Path to a markdown file containing the implementation plan
  85. (must exist, have at least 5 lines, no spaces in path)
  86. OPTIONS:
  87. --plan-file <path> Explicit plan file path (alternative to positional arg)
  88. --track-plan-file Indicate plan file should be tracked in git (must be clean)
  89. --max <N> Maximum iterations before auto-stop (default: 42)
  90. --codex-model <MODEL:EFFORT>
  91. Codex model and reasoning effort for codex exec (default: ${DEFAULT_CODEX_MODEL}:${DEFAULT_CODEX_EFFORT})
  92. --codex-timeout <SECONDS>
  93. Timeout for each Codex review in seconds (default: 5400)
  94. --push-every-round Require git push after each round (default: commits stay local)
  95. --base-branch <BRANCH>
  96. Base branch for code review phase (default: auto-detect)
  97. Priority: user input > remote default > main > master
  98. --full-review-round <N>
  99. Interval for Full Alignment Check rounds (default: 5, min: 2)
  100. Full Alignment Checks occur at rounds N-1, 2N-1, 3N-1, etc.
  101. --skip-impl Skip implementation phase and go directly to code review
  102. Plan file is optional when using this flag
  103. --claude-answer-codex
  104. When Codex finds Open Questions, let Claude answer them
  105. directly instead of asking user via AskUserQuestion.
  106. NOT RECOMMENDED: Open Questions usually indicate gaps in
  107. your plan that deserve human clarification. By default,
  108. Claude asks user for clarification, which is preferred.
  109. --agent-teams Enable Claude Code Agent Teams mode for parallel development.
  110. Requires CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 environment variable.
  111. Claude acts as team leader, splitting tasks among team members.
  112. --yolo Skip Plan Understanding Quiz and let Claude answer Codex Open
  113. Questions directly. Convenience alias for --skip-quiz
  114. --claude-answer-codex. Use when you trust the plan and want
  115. maximum automation.
  116. --skip-quiz Skip the Plan Understanding Quiz only (without other behavioral
  117. changes). The quiz is an advisory pre-flight check that verifies
  118. you understand the plan before committing to an RLCR loop.
  119. --allow-empty-bitlesson-none
  120. Allow BitLesson delta with action:none even with no new entries (default)
  121. --require-bitlesson-entry-for-none
  122. Require at least one BitLesson entry when action is none
  123. --privacy Disable methodology analysis at loop exit (default: analysis enabled)
  124. -h, --help Show this help message
  125. DESCRIPTION:
  126. Starts an iterative loop with Codex review in your CURRENT session.
  127. This command:
  128. 1. Takes a markdown plan file as input (not a prompt string)
  129. 2. Uses Codex to independently review Claude's work each iteration
  130. 3. Has two phases: Implementation Phase and Review Phase
  131. The flow:
  132. 1. Claude executes plan tasks with tag-based routing (Implementation Phase)
  133. - \`coding\` tasks: Claude implements directly
  134. - \`analyze\` tasks: Claude delegates execution via \`/humanize:ask-codex\`
  135. 2. Claude writes a summary to round-N-summary.md
  136. 3. On exit attempt, Codex reviews the summary
  137. 4. If Codex finds issues, it blocks exit and sends feedback
  138. 5. If Codex outputs "COMPLETE", enters Review Phase
  139. 6. In Review Phase, codex review checks code quality with [P0-9] markers
  140. 7. If code review finds issues, Claude fixes them
  141. 8. When no issues found, enters Finalize Phase and loop ends
  142. EXAMPLES:
  143. /humanize:start-rlcr-loop docs/feature-plan.md
  144. /humanize:start-rlcr-loop docs/impl.md --max 20
  145. /humanize:start-rlcr-loop plan.md --codex-model ${DEFAULT_CODEX_MODEL}:${DEFAULT_CODEX_EFFORT}
  146. /humanize:start-rlcr-loop plan.md --codex-timeout 7200 # 2 hour timeout
  147. /humanize:start-rlcr-loop plan.md --yolo # skip quiz, full automation
  148. /humanize:start-rlcr-loop plan.md --skip-quiz # skip quiz only
  149. STOPPING:
  150. - /humanize:cancel-rlcr-loop Cancel the active loop
  151. - Reach --max iterations
  152. - Pass code review (no [P0-9] issues) after COMPLETE
  153. MONITORING:
  154. # View current state:
  155. cat .humanize/rlcr/*/state.md
  156. # View latest summary:
  157. cat .humanize/rlcr/*/round-*-summary.md | tail -50
  158. # View Codex review:
  159. cat .humanize/rlcr/*/round-*-review-result.md | tail -50
  160. HELP_EOF
  161. exit 0
  162. }
  163. while [[ $# -gt 0 ]]; do
  164. case $1 in
  165. -h|--help)
  166. show_help
  167. ;;
  168. --max)
  169. if [[ -z "${2:-}" ]]; then
  170. echo "Error: --max requires a number argument" >&2
  171. exit 1
  172. fi
  173. if ! [[ "$2" =~ ^[0-9]+$ ]]; then
  174. echo "Error: --max must be a positive integer, got: $2" >&2
  175. exit 1
  176. fi
  177. MAX_ITERATIONS="$2"
  178. shift 2
  179. ;;
  180. --codex-model)
  181. if [[ -z "${2:-}" ]]; then
  182. echo "Error: --codex-model requires a MODEL:EFFORT argument" >&2
  183. exit 1
  184. fi
  185. # Parse MODEL:EFFORT format (portable - works in bash and zsh)
  186. if [[ "$2" == *:* ]]; then
  187. CODEX_MODEL="${2%%:*}"
  188. CODEX_EFFORT="${2#*:}"
  189. else
  190. CODEX_MODEL="$2"
  191. CODEX_EFFORT="$DEFAULT_CODEX_EFFORT"
  192. fi
  193. shift 2
  194. ;;
  195. --codex-timeout)
  196. if [[ -z "${2:-}" ]]; then
  197. echo "Error: --codex-timeout requires a number argument (seconds)" >&2
  198. exit 1
  199. fi
  200. if ! [[ "$2" =~ ^[0-9]+$ ]]; then
  201. echo "Error: --codex-timeout must be a positive integer (seconds), got: $2" >&2
  202. exit 1
  203. fi
  204. CODEX_TIMEOUT="$2"
  205. shift 2
  206. ;;
  207. --push-every-round)
  208. PUSH_EVERY_ROUND="true"
  209. shift
  210. ;;
  211. --plan-file)
  212. if [[ -z "${2:-}" ]]; then
  213. echo "Error: --plan-file requires a file path" >&2
  214. exit 1
  215. fi
  216. PLAN_FILE_EXPLICIT="$2"
  217. shift 2
  218. ;;
  219. --track-plan-file)
  220. TRACK_PLAN_FILE="true"
  221. shift
  222. ;;
  223. --base-branch)
  224. if [[ -z "${2:-}" ]]; then
  225. echo "Error: --base-branch requires a branch name argument" >&2
  226. exit 1
  227. fi
  228. BASE_BRANCH="$2"
  229. shift 2
  230. ;;
  231. --full-review-round)
  232. if [[ -z "${2:-}" ]]; then
  233. echo "Error: --full-review-round requires a number argument" >&2
  234. exit 1
  235. fi
  236. if ! [[ "$2" =~ ^[0-9]+$ ]]; then
  237. echo "Error: --full-review-round must be a positive integer, got: $2" >&2
  238. exit 1
  239. fi
  240. if [[ "$2" -lt 2 ]]; then
  241. echo "Error: --full-review-round must be at least 2, got: $2" >&2
  242. exit 1
  243. fi
  244. FULL_REVIEW_ROUND="$2"
  245. shift 2
  246. ;;
  247. --skip-impl)
  248. SKIP_IMPL="true"
  249. shift
  250. ;;
  251. --claude-answer-codex)
  252. ASK_CODEX_QUESTION="false"
  253. shift
  254. ;;
  255. --agent-teams)
  256. AGENT_TEAMS="true"
  257. shift
  258. ;;
  259. --yolo)
  260. ASK_CODEX_QUESTION="false"
  261. shift
  262. ;;
  263. --skip-quiz)
  264. # No-op in setup script; quiz logic lives in command markdown
  265. shift
  266. ;;
  267. --allow-empty-bitlesson-none)
  268. BITLESSON_ALLOW_EMPTY_NONE="true"
  269. shift
  270. ;;
  271. --require-bitlesson-entry-for-none)
  272. BITLESSON_ALLOW_EMPTY_NONE="false"
  273. shift
  274. ;;
  275. --privacy)
  276. PRIVACY_MODE="true"
  277. shift
  278. ;;
  279. -*)
  280. echo "Unknown option: $1" >&2
  281. echo "Use --help for usage information" >&2
  282. exit 1
  283. ;;
  284. *)
  285. if [[ -z "$PLAN_FILE" ]]; then
  286. PLAN_FILE="$1"
  287. else
  288. echo "Error: Multiple plan files specified" >&2
  289. echo "Only one plan file is allowed" >&2
  290. exit 1
  291. fi
  292. shift
  293. ;;
  294. esac
  295. done
  296. # ========================================
  297. # Validate Prerequisites
  298. # ========================================
  299. PROJECT_ROOT="$(resolve_project_root)" || {
  300. echo "Error: Cannot determine humanize project root." >&2
  301. echo " Set CLAUDE_PROJECT_DIR or run inside a git repository." >&2
  302. exit 1
  303. }
  304. # loop-common.sh already sourced above (provides find_active_loop, etc.)
  305. # ========================================
  306. # Required Dependency Check
  307. # ========================================
  308. # Check all required external tools upfront so users get a single,
  309. # actionable error message instead of a cryptic mid-loop failure.
  310. MISSING_DEPS=()
  311. if ! command -v codex &>/dev/null; then
  312. MISSING_DEPS+=("codex - Install: https://github.com/openai/codex")
  313. fi
  314. if ! command -v jq &>/dev/null; then
  315. MISSING_DEPS+=("jq - Install: https://jqlang.github.io/jq/download/")
  316. fi
  317. if ! command -v git &>/dev/null; then
  318. MISSING_DEPS+=("git - Install: https://git-scm.com/downloads")
  319. fi
  320. if [[ ${#MISSING_DEPS[@]} -gt 0 ]]; then
  321. echo "Error: Missing required dependencies for RLCR loop" >&2
  322. echo "" >&2
  323. for dep in "${MISSING_DEPS[@]}"; do
  324. echo " - $dep" >&2
  325. done
  326. echo "" >&2
  327. echo "Please install the missing tools and try again." >&2
  328. exit 1
  329. fi
  330. # ========================================
  331. # Mutual Exclusion Check
  332. # ========================================
  333. # Check for existing active RLCR loop
  334. RLCR_LOOP_DIR=$(find_active_loop "$PROJECT_ROOT/.humanize/rlcr" 2>/dev/null || echo "")
  335. if [[ -n "$RLCR_LOOP_DIR" ]]; then
  336. echo "Error: An RLCR loop is already active" >&2
  337. echo " Active loop: $RLCR_LOOP_DIR" >&2
  338. echo "" >&2
  339. echo "Only one loop can be active at a time." >&2
  340. echo "Cancel the RLCR loop first with: /humanize:cancel-rlcr-loop" >&2
  341. exit 1
  342. fi
  343. # ========================================
  344. # Agent Teams Validation
  345. # ========================================
  346. if [[ "$AGENT_TEAMS" == "true" ]]; then
  347. if [[ "${CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS:-}" != "1" ]]; then
  348. echo "Error: --agent-teams requires the CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS environment variable to be set." >&2
  349. echo "" >&2
  350. echo "Claude Code Agent Teams is an experimental feature that must be enabled before use." >&2
  351. echo "To enable it, set the environment variable before starting Claude Code:" >&2
  352. echo "" >&2
  353. echo " export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1" >&2
  354. echo "" >&2
  355. echo "Or add it to your shell profile (~/.bashrc, ~/.zshrc) for persistent access." >&2
  356. exit 1
  357. fi
  358. fi
  359. # Merge explicit and positional plan file
  360. if [[ -n "$PLAN_FILE_EXPLICIT" && -n "$PLAN_FILE" ]]; then
  361. echo "Error: Cannot specify both --plan-file and positional plan file" >&2
  362. exit 1
  363. fi
  364. if [[ -n "$PLAN_FILE_EXPLICIT" ]]; then
  365. PLAN_FILE="$PLAN_FILE_EXPLICIT"
  366. fi
  367. # Check plan file is provided (optional when --skip-impl is used)
  368. if [[ -z "$PLAN_FILE" ]]; then
  369. if [[ "$SKIP_IMPL" == "true" ]]; then
  370. # Use internal placeholder for skip-impl mode
  371. PLAN_FILE=".humanize/skip-impl-placeholder.md"
  372. SKIP_IMPL_NO_PLAN="true"
  373. # Force TRACK_PLAN_FILE to false since there's no real plan file to track
  374. if [[ "$TRACK_PLAN_FILE" == "true" ]]; then
  375. echo "Warning: --track-plan-file ignored in skip-impl mode without a plan file" >&2
  376. TRACK_PLAN_FILE="false"
  377. fi
  378. else
  379. echo "Error: No plan file provided" >&2
  380. echo "" >&2
  381. echo "Usage: /humanize:start-rlcr-loop <path/to/plan.md> [OPTIONS]" >&2
  382. echo "" >&2
  383. echo "For help: /humanize:start-rlcr-loop --help" >&2
  384. exit 1
  385. fi
  386. fi
  387. # ========================================
  388. # Git Repository Validation
  389. # ========================================
  390. # Check git repo (with timeout)
  391. if ! run_with_timeout "$GIT_TIMEOUT" git rev-parse --git-dir &>/dev/null; then
  392. echo "Error: Project must be a git repository (or git command timed out)" >&2
  393. exit 1
  394. fi
  395. # Check at least one commit (with timeout)
  396. if ! run_with_timeout "$GIT_TIMEOUT" git rev-parse HEAD &>/dev/null 2>&1; then
  397. echo "Error: Git repository must have at least one commit (or git command timed out)" >&2
  398. exit 1
  399. fi
  400. # Plan File Path Validation
  401. # ========================================
  402. # Skip plan file validation in skip-impl mode with no plan provided
  403. if [[ "$SKIP_IMPL_NO_PLAN" == "true" ]]; then
  404. echo "Skip-impl mode: skipping plan file validation" >&2
  405. FULL_PLAN_PATH=""
  406. PLAN_IS_TRACKED="false"
  407. else
  408. # Reject absolute paths
  409. if [[ "$PLAN_FILE" = /* ]]; then
  410. echo "Error: Plan file must be a relative path, got: $PLAN_FILE" >&2
  411. exit 1
  412. fi
  413. # Reject paths with spaces (not supported for YAML serialization consistency)
  414. if [[ "$PLAN_FILE" =~ [[:space:]] ]]; then
  415. echo "Error: Plan file path cannot contain spaces" >&2
  416. echo " Got: $PLAN_FILE" >&2
  417. echo " Rename the file or directory to remove spaces" >&2
  418. exit 1
  419. fi
  420. # Reject paths with shell metacharacters (prevents injection when used in shell commands)
  421. # Use glob pattern matching (== *[...]*) instead of regex (=~) for portability
  422. if [[ "$PLAN_FILE" == *[\;\&\|\$\`\<\>\(\)\{\}\[\]\!\#\~\*\?\\]* ]]; then
  423. echo "Error: Plan file path contains shell metacharacters" >&2
  424. echo " Got: $PLAN_FILE" >&2
  425. echo " Rename the file to use only alphanumeric, dash, underscore, dot, and slash" >&2
  426. exit 1
  427. fi
  428. # Build full path
  429. FULL_PLAN_PATH="$PROJECT_ROOT/$PLAN_FILE"
  430. # Reject symlinks (file itself)
  431. if [[ -L "$FULL_PLAN_PATH" ]]; then
  432. echo "Error: Plan file cannot be a symbolic link" >&2
  433. exit 1
  434. fi
  435. # Check parent directory exists (provides clearer error for typos in path)
  436. PLAN_DIR="$(dirname "$FULL_PLAN_PATH")"
  437. if [[ ! -d "$PLAN_DIR" ]]; then
  438. echo "Error: Plan file directory not found: $(dirname "$PLAN_FILE")" >&2
  439. exit 1
  440. fi
  441. # Reject symlinks in parent directory path (walk each segment)
  442. # This prevents symlink-based path traversal attacks
  443. CHECK_PATH="$PROJECT_ROOT"
  444. # Split PLAN_FILE by / and check each parent directory segment
  445. # Use parameter expansion for portability (works in bash and zsh)
  446. REMAINING_PATH="${PLAN_FILE%/*}"
  447. if [[ "$REMAINING_PATH" != "$PLAN_FILE" ]]; then
  448. # There are parent directories to check
  449. IFS='/' read -ra PATH_SEGMENTS <<< "$REMAINING_PATH"
  450. for segment in "${PATH_SEGMENTS[@]}"; do
  451. if [[ -z "$segment" ]]; then
  452. continue
  453. fi
  454. CHECK_PATH="$CHECK_PATH/$segment"
  455. if [[ -L "$CHECK_PATH" ]]; then
  456. echo "Error: Plan file path contains a symbolic link in parent directory" >&2
  457. echo " Symlink found at: $segment" >&2
  458. echo " Plan file paths must not traverse symbolic links" >&2
  459. exit 1
  460. fi
  461. done
  462. fi
  463. # Check file exists
  464. if [[ ! -f "$FULL_PLAN_PATH" ]]; then
  465. echo "Error: Plan file not found: $PLAN_FILE" >&2
  466. exit 1
  467. fi
  468. # Check file is readable
  469. if [[ ! -r "$FULL_PLAN_PATH" ]]; then
  470. echo "Error: Plan file not readable: $PLAN_FILE" >&2
  471. exit 1
  472. fi
  473. # Check file is within project (no ../ escaping)
  474. # Resolve the real path by cd'ing to the directory and getting pwd
  475. # This handles symlinks in parent directories and ../ path components
  476. RESOLVED_PLAN_DIR=$(cd "$PLAN_DIR" 2>/dev/null && pwd) || {
  477. echo "Error: Cannot resolve plan file directory: $(dirname "$PLAN_FILE")" >&2
  478. echo " This may indicate permission issues or broken symlinks in the path" >&2
  479. exit 1
  480. }
  481. REAL_PLAN_PATH="$RESOLVED_PLAN_DIR/$(basename "$FULL_PLAN_PATH")"
  482. if [[ ! "$REAL_PLAN_PATH" = "$PROJECT_ROOT"/* ]]; then
  483. echo "Error: Plan file must be within project directory" >&2
  484. exit 1
  485. fi
  486. # Check not in submodule
  487. # Quick check: only run expensive git submodule status if .gitmodules exists
  488. if [[ -f "$PROJECT_ROOT/.gitmodules" ]]; then
  489. if run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" submodule status 2>/dev/null | grep -q .; then
  490. # Get list of submodule paths
  491. SUBMODULES=$(run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" submodule status | awk '{print $2}')
  492. for submod in $SUBMODULES; do
  493. if [[ "$PLAN_FILE" = "$submod"/* || "$PLAN_FILE" = "$submod" ]]; then
  494. echo "Error: Plan file cannot be inside a git submodule: $submod" >&2
  495. exit 1
  496. fi
  497. done
  498. fi
  499. fi
  500. # ========================================
  501. # Plan File Tracking Status Validation
  502. # ========================================
  503. # Check git status - fail closed on timeout
  504. # Use || true to capture exit code without triggering set -e
  505. PLAN_GIT_STATUS=$(run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" status --porcelain "$PLAN_FILE" 2>/dev/null) || STATUS_EXIT=$?
  506. STATUS_EXIT=${STATUS_EXIT:-0}
  507. if [[ $STATUS_EXIT -eq 124 ]]; then
  508. echo "Error: Git operation timed out while checking plan file status" >&2
  509. exit 1
  510. fi
  511. # Check if tracked - fail closed on timeout
  512. # ls-files --error-unmatch returns 1 for untracked files (expected behavior)
  513. # We need to distinguish between: 0 (tracked), 1 (not tracked), 124 (timeout)
  514. run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" ls-files --error-unmatch "$PLAN_FILE" &>/dev/null || LS_FILES_EXIT=$?
  515. LS_FILES_EXIT=${LS_FILES_EXIT:-0}
  516. if [[ $LS_FILES_EXIT -eq 124 ]]; then
  517. echo "Error: Git operation timed out while checking plan file tracking status" >&2
  518. exit 1
  519. fi
  520. PLAN_IS_TRACKED=$([[ $LS_FILES_EXIT -eq 0 ]] && echo "true" || echo "false")
  521. if [[ "$TRACK_PLAN_FILE" == "true" ]]; then
  522. # Must be tracked and clean
  523. if [[ "$PLAN_IS_TRACKED" != "true" ]]; then
  524. echo "Error: --track-plan-file requires plan file to be tracked in git" >&2
  525. echo " File: $PLAN_FILE" >&2
  526. echo " Run: git add $PLAN_FILE && git commit" >&2
  527. exit 1
  528. fi
  529. if [[ -n "$PLAN_GIT_STATUS" ]]; then
  530. echo "Error: --track-plan-file requires plan file to be clean (no modifications)" >&2
  531. echo " File: $PLAN_FILE" >&2
  532. echo " Status: $PLAN_GIT_STATUS" >&2
  533. echo " Commit or stash your changes first" >&2
  534. exit 1
  535. fi
  536. else
  537. # Must be gitignored (not tracked)
  538. if [[ "$PLAN_IS_TRACKED" == "true" ]]; then
  539. echo "Error: Plan file must be gitignored when not using --track-plan-file" >&2
  540. echo " File: $PLAN_FILE" >&2
  541. echo " Either:" >&2
  542. echo " 1. Add to .gitignore and remove from git: git rm --cached $PLAN_FILE" >&2
  543. echo " 2. Use --track-plan-file if you want to track the plan file" >&2
  544. exit 1
  545. fi
  546. fi
  547. fi # End of skip-impl plan file validation skip
  548. # ========================================
  549. # Plan File Content Validation
  550. # ========================================
  551. # Skip plan file content validation in skip-impl mode with no plan provided
  552. if [[ "$SKIP_IMPL_NO_PLAN" != "true" ]]; then
  553. # Check plan file has at least 5 lines
  554. LINE_COUNT=$(wc -l < "$FULL_PLAN_PATH" | tr -d ' ')
  555. if [[ "$LINE_COUNT" -lt 5 ]]; then
  556. echo "Error: Plan is too simple (only $LINE_COUNT lines, need at least 5)" >&2
  557. echo "" >&2
  558. echo "The plan file should contain enough detail for implementation." >&2
  559. echo "Consider adding more context, acceptance criteria, or steps." >&2
  560. exit 1
  561. fi
  562. # Check plan has actual content (not just whitespace/blank lines/comments)
  563. # Exclude: blank lines, shell/YAML comments (# ...), and HTML comments (<!-- ... -->)
  564. # Note: Lines starting with # are treated as comments, not markdown headings
  565. # A "content line" is any line that is not blank and not purely a comment
  566. # For multi-line HTML comments, we count lines inside them as non-content
  567. CONTENT_LINES=0
  568. IN_COMMENT=false
  569. while IFS= read -r line || [[ -n "$line" ]]; do
  570. # If inside multi-line comment, check for end marker
  571. if [[ "$IN_COMMENT" == "true" ]]; then
  572. if [[ "$line" =~ --\>[[:space:]]*$ ]]; then
  573. IN_COMMENT=false
  574. fi
  575. continue
  576. fi
  577. # Skip blank lines
  578. if [[ "$line" =~ ^[[:space:]]*$ ]]; then
  579. continue
  580. fi
  581. # Skip single-line HTML comments (must check BEFORE multi-line start)
  582. # Single-line: <!-- ... --> on same line
  583. if [[ "$line" =~ ^[[:space:]]*\<!--.*--\>[[:space:]]*$ ]]; then
  584. continue
  585. fi
  586. # Check for multi-line HTML comment start (<!-- without closing --> on same line)
  587. # Only trigger if the line contains <!-- but NOT -->
  588. if [[ "$line" =~ ^[[:space:]]*\<!-- ]] && ! [[ "$line" =~ --\> ]]; then
  589. IN_COMMENT=true
  590. continue
  591. fi
  592. # Skip shell/YAML style comments (lines starting with #)
  593. if [[ "$line" =~ ^[[:space:]]*# ]]; then
  594. continue
  595. fi
  596. # This is a content line
  597. CONTENT_LINES=$((CONTENT_LINES + 1))
  598. done < "$FULL_PLAN_PATH"
  599. if [[ "$CONTENT_LINES" -lt 3 ]]; then
  600. echo "Error: Plan file has insufficient content (only $CONTENT_LINES content lines)" >&2
  601. echo "" >&2
  602. echo "The plan file should contain meaningful content, not just blank lines or comments." >&2
  603. exit 1
  604. fi
  605. else
  606. # Skip-impl mode: set placeholder LINE_COUNT
  607. LINE_COUNT=0
  608. fi # End of skip-impl plan file content validation skip
  609. if [[ "$SKIP_IMPL" == "true" ]] && [[ "$SKIP_IMPL_NO_PLAN" != "true" ]]; then
  610. SKIP_IMPL_PLAN_ANCHORED="true"
  611. fi
  612. # ========================================
  613. # Record Branch
  614. # ========================================
  615. START_BRANCH=$(run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" rev-parse --abbrev-ref HEAD)
  616. if [[ -z "$START_BRANCH" ]]; then
  617. echo "Error: Failed to get current branch (git command timed out or failed)" >&2
  618. exit 1
  619. fi
  620. # Validate branch name for YAML safety (prevents injection in state.md)
  621. # Reject branches with YAML-unsafe characters: colon, hash, quotes, newlines
  622. if [[ "$START_BRANCH" == *[:\#\"\'\`]* ]] || [[ "$START_BRANCH" =~ $'\n' ]]; then
  623. echo "Error: Branch name contains YAML-unsafe characters" >&2
  624. echo " Branch: $START_BRANCH" >&2
  625. echo " Characters not allowed: : # \" ' \` newline" >&2
  626. echo " Please checkout a branch with a simpler name" >&2
  627. exit 1
  628. fi
  629. # Validate codex model for YAML safety
  630. # Only alphanumeric, hyphen, underscore, dot allowed
  631. if [[ ! "$CODEX_MODEL" =~ ^[a-zA-Z0-9._-]+$ ]]; then
  632. echo "Error: Codex model contains invalid characters" >&2
  633. echo " Model: $CODEX_MODEL" >&2
  634. echo " Only alphanumeric, hyphen, underscore, dot allowed" >&2
  635. exit 1
  636. fi
  637. # Validate codex effort matches allowed values (consistent with stop-hook validation)
  638. if [[ ! "$CODEX_EFFORT" =~ ^(xhigh|high|medium|low)$ ]]; then
  639. echo "Error: Invalid codex effort: $CODEX_EFFORT" >&2
  640. echo " Must be one of: xhigh, high, medium, low" >&2
  641. exit 1
  642. fi
  643. # ========================================
  644. # Git Working Tree Clean Check
  645. # ========================================
  646. # Placed after input validation so users see input errors first
  647. GIT_STATUS_OUTPUT=$(run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" status --porcelain --untracked-files=all 2>/dev/null) || GIT_STATUS_EXIT=$?
  648. GIT_STATUS_EXIT=${GIT_STATUS_EXIT:-0}
  649. if [[ $GIT_STATUS_EXIT -eq 124 ]]; then
  650. echo "Error: Git operation timed out while checking working tree status" >&2
  651. exit 1
  652. fi
  653. # Filter out untracked .humanize/ paths and .humanize-* dash-separated legacy variants.
  654. # These are gitignored runtime directories and do not indicate a dirty working tree.
  655. GIT_STATUS_OUTPUT=$(echo "$GIT_STATUS_OUTPUT" | grep -vE '^\?\? \.humanize[-/]' || true)
  656. if [[ -n "$GIT_STATUS_OUTPUT" ]]; then
  657. echo "Error: Git working tree is not clean" >&2
  658. echo "" >&2
  659. echo "RLCR loop can only be started on a clean git repository." >&2
  660. echo "Please commit or stash your changes before starting the loop." >&2
  661. echo "" >&2
  662. echo "Current status:" >&2
  663. echo "$GIT_STATUS_OUTPUT" >&2
  664. exit 1
  665. fi
  666. # ========================================
  667. # Determine Base Branch for Code Review
  668. # ========================================
  669. # Priority: user input > remote default > local main > local master
  670. if [[ -n "$BASE_BRANCH" ]]; then
  671. # User specified base branch - validate it exists LOCALLY
  672. # codex review --base requires a local ref, so remote-only branches won't work
  673. if run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" show-ref --verify --quiet "refs/heads/$BASE_BRANCH" 2>/dev/null; then
  674. : # Branch exists locally, good
  675. else
  676. # Check if it exists on remote but not locally
  677. if run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" ls-remote --heads origin "$BASE_BRANCH" 2>/dev/null | grep -q .; then
  678. echo "Error: Base branch '$BASE_BRANCH' exists on remote but not locally" >&2
  679. echo " codex review requires a local branch reference" >&2
  680. echo " Run: git fetch origin $BASE_BRANCH:$BASE_BRANCH" >&2
  681. exit 1
  682. else
  683. echo "Error: Specified base branch does not exist: $BASE_BRANCH" >&2
  684. echo " Not found locally or on any remote" >&2
  685. exit 1
  686. fi
  687. fi
  688. else
  689. # Auto-detect base branch
  690. # Note: codex review --base requires a LOCAL branch, so we must verify local existence
  691. # Priority 1: Remote default branch (if it exists locally)
  692. # Guard with || true to prevent pipefail from terminating script when origin is missing
  693. REMOTE_DEFAULT=$(run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" remote show origin 2>/dev/null | grep "HEAD branch:" | sed 's/.*HEAD branch:[[:space:]]*//' || true)
  694. if [[ -n "$REMOTE_DEFAULT" && "$REMOTE_DEFAULT" != "(unknown)" ]]; then
  695. # Verify the remote default branch exists locally
  696. if run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" show-ref --verify --quiet "refs/heads/$REMOTE_DEFAULT" 2>/dev/null; then
  697. BASE_BRANCH="$REMOTE_DEFAULT"
  698. fi
  699. fi
  700. # Priority 2: Local main branch (if not already set)
  701. if [[ -z "$BASE_BRANCH" ]] && run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" show-ref --verify --quiet refs/heads/main 2>/dev/null; then
  702. BASE_BRANCH="main"
  703. fi
  704. # Priority 3: Local master branch (if not already set)
  705. if [[ -z "$BASE_BRANCH" ]] && run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" show-ref --verify --quiet refs/heads/master 2>/dev/null; then
  706. BASE_BRANCH="master"
  707. fi
  708. # Error if no base branch found
  709. if [[ -z "$BASE_BRANCH" ]]; then
  710. echo "Error: Cannot determine base branch for code review" >&2
  711. echo " No local main or master branch found" >&2
  712. if [[ -n "$REMOTE_DEFAULT" && "$REMOTE_DEFAULT" != "(unknown)" ]]; then
  713. echo " Remote default '$REMOTE_DEFAULT' exists but not locally" >&2
  714. echo " Run: git fetch origin $REMOTE_DEFAULT:$REMOTE_DEFAULT" >&2
  715. fi
  716. echo " Use --base-branch to specify explicitly" >&2
  717. exit 1
  718. fi
  719. fi
  720. # Validate base branch name for YAML safety
  721. if [[ "$BASE_BRANCH" == *[:\#\"\'\`]* ]] || [[ "$BASE_BRANCH" =~ $'\n' ]]; then
  722. echo "Error: Base branch name contains YAML-unsafe characters" >&2
  723. echo " Branch: $BASE_BRANCH" >&2
  724. echo " Characters not allowed: : # \" ' \` newline" >&2
  725. exit 1
  726. fi
  727. # Capture the base commit SHA at loop start time
  728. # This prevents issues when working on the base branch itself (e.g., main)
  729. # where the branch ref advances with commits, making diff against itself empty
  730. BASE_COMMIT=$(run_with_timeout "$GIT_TIMEOUT" git -C "$PROJECT_ROOT" rev-parse "$BASE_BRANCH" 2>/dev/null)
  731. if [[ -z "$BASE_COMMIT" ]]; then
  732. echo "Error: Failed to get commit SHA for base branch: $BASE_BRANCH" >&2
  733. exit 1
  734. fi
  735. echo "Base commit SHA captured: $BASE_COMMIT" >&2
  736. # ========================================
  737. # Setup State Directory
  738. # ========================================
  739. LOOP_BASE_DIR="$PROJECT_ROOT/.humanize/rlcr"
  740. # Create timestamp for this loop session
  741. TIMESTAMP=$(date +%Y-%m-%d_%H-%M-%S)
  742. LOOP_DIR="$LOOP_BASE_DIR/$TIMESTAMP"
  743. mkdir -p "$LOOP_DIR"
  744. # Copy plan file to loop directory as backup (or create placeholder for skip-impl)
  745. if [[ "$SKIP_IMPL_NO_PLAN" == "true" ]]; then
  746. # Create placeholder plan file for skip-impl mode
  747. cat > "$LOOP_DIR/plan.md" << 'SKIP_IMPL_PLAN_EOF'
  748. # Skip Implementation Mode
  749. This RLCR loop was started with `--skip-impl` flag, which skips the implementation phase
  750. and goes directly to code review.
  751. No implementation plan was provided - this is expected for skip-impl mode.
  752. The loop will:
  753. 1. Run `codex review` on the current branch changes
  754. 2. If issues are found, Claude will fix them
  755. 3. When no issues remain, enter finalize phase
  756. SKIP_IMPL_PLAN_EOF
  757. # Update PLAN_FILE to point to the actual placeholder location (repo-relative path)
  758. # Using relative path because git ls-files requires repo-relative paths
  759. PLAN_FILE=".humanize/rlcr/$TIMESTAMP/plan.md"
  760. else
  761. cp "$FULL_PLAN_PATH" "$LOOP_DIR/plan.md"
  762. fi
  763. # Docs path default
  764. DOCS_PATH="docs"
  765. # ========================================
  766. # Initialize BitLesson File
  767. # ========================================
  768. BITLESSON_FILE_REL=".humanize/bitlesson.md"
  769. BITLESSON_FILE="$PROJECT_ROOT/$BITLESSON_FILE_REL"
  770. PLUGIN_BITLESSON_TEMPLATE="$SCRIPT_DIR/../templates/bitlesson.md"
  771. bash "$SCRIPT_DIR/bitlesson-init.sh" \
  772. --project-root "$PROJECT_ROOT" \
  773. --template "$PLUGIN_BITLESSON_TEMPLATE" \
  774. --bitlesson-relpath "$BITLESSON_FILE_REL" > /dev/null
  775. # ========================================
  776. # Create State File
  777. # ========================================
  778. # Determine initial review_started value based on skip-impl mode
  779. INITIAL_REVIEW_STARTED="$SKIP_IMPL"
  780. # Skip-impl mode does not use BitLesson-aware summary templates,
  781. # so disable enforcement to avoid blocking the review-only workflow.
  782. BITLESSON_STATE_VALUE="true"
  783. [[ "$SKIP_IMPL" == "true" ]] && BITLESSON_STATE_VALUE="false"
  784. cat > "$LOOP_DIR/state.md" << EOF
  785. ---
  786. current_round: 0
  787. max_iterations: $MAX_ITERATIONS
  788. codex_model: $CODEX_MODEL
  789. codex_effort: $CODEX_EFFORT
  790. codex_timeout: $CODEX_TIMEOUT
  791. push_every_round: $PUSH_EVERY_ROUND
  792. full_review_round: $FULL_REVIEW_ROUND
  793. plan_file: $PLAN_FILE
  794. plan_tracked: $TRACK_PLAN_FILE
  795. start_branch: $START_BRANCH
  796. base_branch: $BASE_BRANCH
  797. base_commit: $BASE_COMMIT
  798. review_started: $INITIAL_REVIEW_STARTED
  799. ask_codex_question: $ASK_CODEX_QUESTION
  800. session_id:
  801. agent_teams: $AGENT_TEAMS
  802. privacy_mode: $PRIVACY_MODE
  803. bitlesson_required: $BITLESSON_STATE_VALUE
  804. bitlesson_file: $BITLESSON_FILE_REL
  805. bitlesson_allow_empty_none: $BITLESSON_ALLOW_EMPTY_NONE
  806. mainline_stall_count: 0
  807. last_mainline_verdict: unknown
  808. drift_status: normal
  809. started_at: $(date -u +%Y-%m-%dT%H:%M:%SZ)
  810. ---
  811. EOF
  812. # Create signal file for PostToolUse hook to record session_id
  813. # The hook will read the session_id from its JSON input and patch state.md
  814. # Format: line 1 = state file path, line 2 = command marker for verification
  815. # The PostToolUse hook will only consume this signal when the Bash command
  816. # that triggered it matches the setup script marker, preventing other sessions
  817. # from accidentally claiming the signal.
  818. mkdir -p "$PROJECT_ROOT/.humanize"
  819. # Write full resolved script path as command signature for strict verification
  820. SCRIPT_SELF_PATH="$SCRIPT_DIR/$(basename "${BASH_SOURCE[0]:-$0}")"
  821. printf '%s\n%s\n' "$LOOP_DIR/state.md" "$SCRIPT_SELF_PATH" > "$PROJECT_ROOT/.humanize/.pending-session-id"
  822. # Create review phase marker file for skip-impl mode
  823. if [[ "$SKIP_IMPL" == "true" ]]; then
  824. echo "build_finish_round=0" > "$LOOP_DIR/.review-phase-started"
  825. fi
  826. # ========================================
  827. # Create Goal Tracker File
  828. # ========================================
  829. GOAL_TRACKER_FILE="$LOOP_DIR/goal-tracker.md"
  830. if [[ "$SKIP_IMPL" == "true" ]]; then
  831. if [[ "$SKIP_IMPL_PLAN_ANCHORED" == "true" ]]; then
  832. PLAN_GOAL_CONTENT=$(extract_plan_goal_content "$FULL_PLAN_PATH")
  833. PLAN_AC_CONTENT=$(extract_plan_ac_content "$FULL_PLAN_PATH")
  834. if [[ -z "$PLAN_GOAL_CONTENT" ]]; then
  835. PLAN_GOAL_CONTENT="Preserve the original plan scope from $PLAN_FILE while resolving code review findings on the current branch."
  836. fi
  837. if [[ -z "$PLAN_AC_CONTENT" ]]; then
  838. PLAN_AC_CONTENT=$(cat <<EOF
  839. - The current branch remains aligned with the original plan at $PLAN_FILE.
  840. - All blocking \`[P0-9]\` code review findings are resolved without widening scope beyond the original plan.
  841. - Non-blocking follow-up items are explicitly queued and do not block completion.
  842. EOF
  843. )
  844. fi
  845. cat > "$GOAL_TRACKER_FILE" << EOF
  846. # Goal Tracker (Skip Implementation Mode with Plan Anchor)
  847. This RLCR loop was started with \`--skip-impl\` flag. The implementation phase was skipped,
  848. but an explicit plan was provided and remains the scope anchor for review-only work.
  849. This tracker is still used to keep the review loop aligned around one mainline objective
  850. and to separate blocking issues from queued follow-up work.
  851. ## IMMUTABLE SECTION
  852. ### Ultimate Goal
  853. $PLAN_GOAL_CONTENT
  854. ### Acceptance Criteria
  855. $PLAN_AC_CONTENT
  856. ---
  857. ## MUTABLE SECTION
  858. ### Plan Version: Review-Only (Updated: Round 0)
  859. #### Plan Evolution Log
  860. | Round | Change | Reason | Impact on AC |
  861. |-------|--------|--------|--------------|
  862. | 0 | Skip implementation mode initialized around explicit plan anchor | Loop started with \`--skip-impl\` and retained @$PLAN_FILE as scope anchor | Review stays aligned with original plan |
  863. #### Active Tasks
  864. | Task | Target AC | Status | Notes |
  865. |------|-----------|--------|-------|
  866. | [mainline] Preserve original plan alignment while resolving blocking review findings | Plan ACs in scope | pending | Review-only mode with explicit plan anchor |
  867. ### Blocking Side Issues
  868. | Issue | Discovered Round | Blocking AC | Resolution Path |
  869. |-------|-----------------|-------------|-----------------|
  870. ### Queued Side Issues
  871. | Issue | Discovered Round | Why Not Blocking | Revisit Trigger |
  872. |-------|-----------------|------------------|-----------------|
  873. ### Completed and Verified
  874. | AC | Task | Completed Round | Verified Round | Evidence |
  875. |----|------|-----------------|----------------|----------|
  876. ### Explicitly Deferred
  877. | Task | Original AC | Deferred Since | Justification | When to Reconsider |
  878. |------|-------------|----------------|---------------|-------------------|
  879. EOF
  880. else
  881. # Create review-only goal tracker for skip-impl mode without a plan (no placeholder text)
  882. cat > "$GOAL_TRACKER_FILE" << 'GOAL_TRACKER_EOF'
  883. # Goal Tracker (Skip Implementation Mode)
  884. This RLCR loop was started with `--skip-impl` flag. The implementation phase was skipped,
  885. and the loop is running in code review mode only.
  886. This tracker is still used to keep the review loop aligned around one mainline objective
  887. and to separate blocking issues from queued follow-up work.
  888. ## IMMUTABLE SECTION
  889. ### Ultimate Goal
  890. Pass code review for the current branch without regressing existing behavior.
  891. ### Acceptance Criteria
  892. - AC-1: All blocking `[P0-9]` code review findings are resolved.
  893. - AC-2: Non-blocking follow-up items are explicitly queued and do not block completion.
  894. - AC-3: Finalize phase can complete without introducing new review regressions.
  895. ---
  896. ## MUTABLE SECTION
  897. ### Plan Version: Review-Only (Updated: Round 0)
  898. #### Plan Evolution Log
  899. | Round | Change | Reason | Impact on AC |
  900. |-------|--------|--------|--------------|
  901. | 0 | Skip implementation mode initialized | Loop started with `--skip-impl` | Focus on review-only objective |
  902. #### Active Tasks
  903. | Task | Target AC | Status | Notes |
  904. |------|-----------|--------|-------|
  905. | [mainline] Pass code review for current branch | AC-1 | pending | Review-only mode |
  906. ### Blocking Side Issues
  907. | Issue | Discovered Round | Blocking AC | Resolution Path |
  908. |-------|-----------------|-------------|-----------------|
  909. ### Queued Side Issues
  910. | Issue | Discovered Round | Why Not Blocking | Revisit Trigger |
  911. |-------|-----------------|------------------|-----------------|
  912. ### Completed and Verified
  913. | AC | Task | Completed Round | Verified Round | Evidence |
  914. |----|------|-----------------|----------------|----------|
  915. ### Explicitly Deferred
  916. | Task | Original AC | Deferred Since | Justification | When to Reconsider |
  917. |------|-------------|----------------|---------------|-------------------|
  918. GOAL_TRACKER_EOF
  919. fi
  920. else
  921. # Normal mode: create full goal tracker
  922. cat > "$GOAL_TRACKER_FILE" << 'GOAL_TRACKER_EOF'
  923. # Goal Tracker
  924. <!--
  925. This file tracks the ultimate goal, acceptance criteria, and plan evolution.
  926. It prevents goal drift by maintaining a persistent anchor across all rounds.
  927. RULES:
  928. - IMMUTABLE SECTION: Do not modify after initialization
  929. - MUTABLE SECTION: Update each round, but document all changes
  930. - Every task must be in one of: Active, Completed, or Deferred
  931. - Deferred items require explicit justification
  932. -->
  933. ## IMMUTABLE SECTION
  934. <!-- Do not modify after initialization -->
  935. ### Ultimate Goal
  936. GOAL_TRACKER_EOF
  937. # Extract goal from plan file (look for ## Goal, ## Objective, or first paragraph)
  938. # This is a heuristic - Claude will refine it in round 0
  939. # Use ^## without leading whitespace - markdown headers should start at column 0
  940. GOAL_SECTION=$(extract_plan_goal_content "$FULL_PLAN_PATH")
  941. if [[ -n "$GOAL_SECTION" ]]; then
  942. echo "$GOAL_SECTION" >> "$GOAL_TRACKER_FILE"
  943. else
  944. # Use first non-empty, non-heading paragraph as goal description
  945. echo "[To be extracted from plan by Claude in Round 0]" >> "$GOAL_TRACKER_FILE"
  946. echo "" >> "$GOAL_TRACKER_FILE"
  947. echo "Source plan: $PLAN_FILE" >> "$GOAL_TRACKER_FILE"
  948. fi
  949. cat >> "$GOAL_TRACKER_FILE" << 'GOAL_TRACKER_EOF'
  950. ### Acceptance Criteria
  951. <!-- Each criterion must be independently verifiable -->
  952. <!-- Claude must extract or define these in Round 0 -->
    • Dismissed after review: Gives the agent orders in an HTML comment, which the rendered page hides from a reader
    • Line 1,099 on GitHub
  953. GOAL_TRACKER_EOF
  954. # Extract acceptance criteria from plan file (look for ## Acceptance, ## Criteria, ## Requirements)
  955. # Use ^## without leading whitespace - markdown headers should start at column 0
  956. # Use || true after sed to ignore SIGPIPE when head closes the pipe early (pipefail mode)
  957. AC_SECTION=$(extract_plan_ac_content "$FULL_PLAN_PATH")
  958. if [[ -n "$AC_SECTION" ]]; then
  959. echo "$AC_SECTION" >> "$GOAL_TRACKER_FILE"
  960. else
  961. echo "[To be defined by Claude in Round 0 based on the plan]" >> "$GOAL_TRACKER_FILE"
  962. fi
  963. cat >> "$GOAL_TRACKER_FILE" << 'GOAL_TRACKER_EOF'
  964. ---
  965. ## MUTABLE SECTION
  966. <!-- Update each round with justification for changes -->
  967. ### Plan Version: 1 (Updated: Round 0)
  968. #### Plan Evolution Log
  969. <!-- Document any changes to the plan with justification -->
  970. | Round | Change | Reason | Impact on AC |
  971. |-------|--------|--------|--------------|
  972. | 0 | Initial plan | - | - |
  973. #### Active Tasks
  974. <!-- Mainline tasks only: each task must directly advance the current round objective and carry routing metadata -->
  975. | Task | Target AC | Status | Tag | Owner | Notes |
  976. |------|-----------|--------|-----|-------|-------|
  977. | [To be populated by Claude based on plan] | - | pending | coding or analyze | claude or codex | mainline task only |
  978. ### Blocking Side Issues
  979. <!-- Only issues that directly block current mainline progress belong here -->
  980. | Issue | Discovered Round | Blocking AC | Resolution Path |
  981. |-------|-----------------|-------------|-----------------|
  982. ### Queued Side Issues
  983. <!-- Non-blocking issues stay queued and must NOT replace the round objective -->
  984. | Issue | Discovered Round | Why Not Blocking | Revisit Trigger |
  985. |-------|-----------------|------------------|-----------------|
  986. ### Completed and Verified
  987. <!-- Only move tasks here after Codex verification -->
  988. | AC | Task | Completed Round | Verified Round | Evidence |
  989. |----|------|-----------------|----------------|----------|
  990. ### Explicitly Deferred
  991. <!-- Items here require strong justification -->
  992. | Task | Original AC | Deferred Since | Justification | When to Reconsider |
  993. |------|-------------|----------------|---------------|-------------------|
  994. GOAL_TRACKER_EOF
  995. fi # End of skip-impl goal tracker handling
  996. # ========================================
  997. # Summary Template Helper
  998. # ========================================
  999. write_summary_template() {
  1000. local summary_path="$1"
  1001. cat > "$summary_path" << 'SUMMARY_TMPL_EOF'
  1002. # Round 0 Summary
  1003. ## What Was Implemented
  1004. [Describe what was done]
  1005. ## Files Changed
  1006. [List files created/modified/deleted]
  1007. ## Validation
  1008. [List tests/commands run and outcomes]
  1009. ## Remaining Items
  1010. [List any deferred or pending items]
  1011. ## BitLesson Delta
  1012. Action: none
  1013. Lesson ID(s): NONE
  1014. Notes: [what changed and why]
  1015. SUMMARY_TMPL_EOF
  1016. }
  1017. # ========================================
  1018. # Create Initial Prompt
  1019. # ========================================
  1020. SUMMARY_PATH="$LOOP_DIR/round-0-summary.md"
  1021. ROUND_CONTRACT_PATH="$LOOP_DIR/round-0-contract.md"
  1022. # Create the round-0 summary scaffold before either mode starts so stop-hook
  1023. # validation and BitLesson Delta checks have a valid target file.
  1024. write_summary_template "$SUMMARY_PATH"
  1025. if [[ "$SKIP_IMPL" == "true" ]]; then
  1026. if [[ "$SKIP_IMPL_PLAN_ANCHORED" == "true" ]]; then
  1027. cat > "$ROUND_CONTRACT_PATH" << EOF
  1028. # Round 0 Contract
  1029. - Mainline Objective: Keep the current branch aligned with @$PLAN_FILE while resolving only review findings that block clean acceptance.
  1030. - Target ACs: The original plan acceptance criteria affected by the current branch changes.
  1031. - Blocking Side Issues In Scope: Any \`[P0-9]\` findings or regressions that block review acceptance or violate the original plan scope.
  1032. - Queued Side Issues Out of Scope: Non-blocking cleanup, follow-up refactors, or future improvements that do not block review acceptance or plan alignment.
  1033. - Success Criteria: Code review passes and the current branch still matches the original plan's intended scope.
  1034. EOF
  1035. else
  1036. cat > "$ROUND_CONTRACT_PATH" << 'ROUND_CONTRACT_EOF'
  1037. # Round 0 Contract
  1038. - Mainline Objective: Run code review for the current branch and resolve only findings that block clean acceptance.
  1039. - Target ACs: AC-1, AC-2
  1040. - Blocking Side Issues In Scope: Any `[P0-9]` findings from the active review cycle.
  1041. - Queued Side Issues Out of Scope: Non-blocking cleanup, follow-up refactors, or future improvements that do not block review acceptance.
  1042. - Success Criteria: Code review passes with no blocking findings, and any remaining non-blocking follow-up is explicitly queued.
  1043. ROUND_CONTRACT_EOF
  1044. fi
  1045. # Skip-impl mode: create a prompt for code review only
  1046. cat > "$LOOP_DIR/round-0-prompt.md" << EOF
  1047. # Skip Implementation Mode - Code Review Loop
  1048. This RLCR loop was started with \`--skip-impl\` flag.
  1049. **Mode**: Code Review Only (skipping implementation phase)
  1050. **Base Branch**: $BASE_BRANCH
  1051. **Current Branch**: $START_BRANCH
  1052. ## What This Means
  1053. The loop will automatically run \`codex review\` on your changes when you try to exit.
  1054. If issues are found (marked with [P0-9] priority), you'll need to fix them before the loop ends.
  1055. Do not try to execute anything to trigger the review - just stop and it will run automatically.
  1056. Before requesting review, read:
  1057. - @$PLAN_FILE
  1058. - @$GOAL_TRACKER_FILE
  1059. - @$ROUND_CONTRACT_PATH
  1060. ## Your Task
  1061. 1. Review your current work
  1062. 2. When ready, try to exit - Codex will review your code
  1063. 3. Fix any issues Codex finds
  1064. 4. Repeat until no issues remain
  1065. 5. Enter finalize phase for code simplification
  1066. ## Review Objective
  1067. Use the round contract as the current anchor:
  1068. - Keep one stable mainline objective and do not let it drift
  1069. - Treat review findings as \`[blocking]\` only if they block review acceptance
  1070. - Record non-blocking follow-up as \`[queued]\`
  1071. - Do not let queued work take over the round
  1072. EOF
  1073. if [[ "$SKIP_IMPL_PLAN_ANCHORED" == "true" ]]; then
  1074. cat >> "$LOOP_DIR/round-0-prompt.md" << EOF
  1075. - Keep review-only work aligned with the original plan at @$PLAN_FILE
  1076. Implementation phase is skipped, but the original plan still defines the intended branch scope.
  1077. EOF
  1078. else
  1079. cat >> "$LOOP_DIR/round-0-prompt.md" << 'EOF'
  1080. There is no explicit implementation plan for this loop, so the review-only contract is the primary anchor.
  1081. EOF
  1082. fi
  1083. cat >> "$LOOP_DIR/round-0-prompt.md" << EOF
  1084. Keep @$ROUND_CONTRACT_PATH updated if the blocking/queued split changes materially during review iterations.
  1085. When you're ready for review, write a brief summary of your changes and try to exit (do not try to execute anything, just stop).
  1086. Write your summary to: @$SUMMARY_PATH
  1087. EOF
  1088. else
  1089. # Normal mode: create full implementation prompt
  1090. # Write prompt header
  1091. cat > "$LOOP_DIR/round-0-prompt.md" << EOF
  1092. Read and execute below with ultrathink
  1093. ## Goal Tracker Setup (REQUIRED FIRST STEP)
  1094. Before starting implementation, you MUST initialize the Goal Tracker:
  1095. 1. Read @$GOAL_TRACKER_FILE
  1096. 2. If the "Ultimate Goal" section says "[To be extracted...]", extract a clear goal statement from the plan
  1097. 3. If the "Acceptance Criteria" section says "[To be defined...]", define 3-7 specific, testable criteria
  1098. 4. Populate the "Active Tasks" table with MAINLINE tasks from the plan, mapping each to an AC and filling Tag/Owner
  1099. 5. Record any already-known side issues in either "Blocking Side Issues" or "Queued Side Issues"
  1100. 6. Write the updated goal-tracker.md
  1101. ## Round Contract Setup (REQUIRED BEFORE CODING)
  1102. Before starting implementation, create @$ROUND_CONTRACT_PATH with:
  1103. 1. **One mainline objective** for this round
  1104. 2. **Target ACs** (1-2 ACs only)
  1105. 3. **Blocking side issues in scope** for this round
  1106. 4. **Queued side issues out of scope** for this round
  1107. 5. **Round success criteria**
  1108. Use this contract to keep the round focused. Do NOT let non-blocking bugs or cleanup work replace the mainline objective.
  1109. **IMPORTANT**: The IMMUTABLE SECTION can only be modified in Round 0. After this round, it becomes read-only.
  1110. ---
  1111. ## Implementation Plan
  1112. For all tasks that need to be completed, please use the Task system (TaskCreate, TaskUpdate, TaskList).
  1113. Every task MUST start with exactly one lane tag:
  1114. - \`[mainline]\` for plan-derived work that directly advances the round objective
  1115. - \`[blocking]\` for issues that prevent the mainline objective from succeeding safely
  1116. - \`[queued]\` for non-blocking bugs, cleanup, or follow-up work
  1117. Rules:
  1118. - \`[mainline]\` tasks are the primary success condition for the round
  1119. - \`[blocking]\` tasks may be resolved in the round only if they truly block mainline progress
  1120. - \`[queued]\` tasks must NOT become the round objective and do NOT need to be cleared before moving on
  1121. - If a new issue is not blocking the current objective, tag it \`[queued]\` and keep moving on the mainline
  1122. ## Task Tag Routing (MUST FOLLOW)
  1123. Each task must have one routing tag from the plan: \`coding\` or \`analyze\`.
  1124. - Tag \`coding\`: Claude executes the task directly.
  1125. - Tag \`analyze\`: Claude must execute via \`/humanize:ask-codex\`, then integrate Codex output.
  1126. - Keep Goal Tracker "Active Tasks" columns **Tag** and **Owner** aligned with execution (\`coding -> claude\`, \`analyze -> codex\`).
  1127. - If a task has no explicit tag, default to \`coding\` (Claude executes directly).
  1128. EOF
  1129. # Append plan content directly (avoids command substitution size limits for large files)
  1130. cat "$LOOP_DIR/plan.md" >> "$LOOP_DIR/round-0-prompt.md"
  1131. # Append BitLesson Selection section
  1132. cat >> "$LOOP_DIR/round-0-prompt.md" << EOF
  1133. ---
  1134. ## BitLesson Selection (REQUIRED FOR EACH TASK)
  1135. Before executing each task or sub-task, you MUST:
  1136. 1. Read @$BITLESSON_FILE
  1137. 2. Run \`bitlesson-selector\` for each task/sub-task to select relevant lesson IDs
  1138. 3. Follow the selected lesson IDs (or \`NONE\`) during implementation
  1139. Include a \`## BitLesson Delta\` section in your summary with:
  1140. - Action: none|add|update
  1141. - Lesson ID(s): NONE or comma-separated IDs
  1142. - Notes: what changed and why (required if action is add or update)
  1143. Reference: @$BITLESSON_FILE
  1144. EOF
  1145. # Inject agent-teams instructions if enabled (header + shared core)
  1146. if [[ "$AGENT_TEAMS" == "true" ]]; then
  1147. AGENT_TEAMS_HEADER="$TEMPLATE_DIR/claude/agent-teams-instructions.md"
  1148. AGENT_TEAMS_CORE="$TEMPLATE_DIR/claude/agent-teams-core.md"
  1149. if [[ -f "$AGENT_TEAMS_HEADER" ]] && [[ -f "$AGENT_TEAMS_CORE" ]]; then
  1150. echo "" >> "$LOOP_DIR/round-0-prompt.md"
  1151. cat "$AGENT_TEAMS_HEADER" >> "$LOOP_DIR/round-0-prompt.md"
  1152. echo "" >> "$LOOP_DIR/round-0-prompt.md"
  1153. cat "$AGENT_TEAMS_CORE" >> "$LOOP_DIR/round-0-prompt.md"
  1154. else
  1155. cat >> "$LOOP_DIR/round-0-prompt.md" << 'AGENT_TEAMS_EOF'
  1156. ## Agent Teams Mode
  1157. You are operating in **Agent Teams mode** as the **Team Leader**.
  1158. Split tasks into independent units, create agent teams to execute them, and coordinate team members.
  1159. Do NOT do implementation work yourself - delegate all coding to team members.
  1160. Prevent overlapping changes by assigning clear file ownership boundaries.
  1161. AGENT_TEAMS_EOF
  1162. fi
  1163. fi
  1164. # Write prompt footer
  1165. cat >> "$LOOP_DIR/round-0-prompt.md" << EOF
  1166. ---
  1167. ## Goal Tracker Rules
  1168. Throughout your work, you MUST maintain the Goal Tracker:
  1169. 1. **Before starting a round**: Re-anchor on the original plan and current round contract
  1170. 2. **Before starting a task**: Mark the relevant mainline task as "in_progress" in Active Tasks
  1171. - Confirm Tag/Owner routing is correct before execution
  1172. 3. **Active Tasks** are MAINLINE tasks only - side issues do not belong there
  1173. 4. **Blocking Side Issues** are reserved for issues that truly stop mainline progress
  1174. 5. **Queued Side Issues** are non-blocking and must not take over the round
  1175. 6. **After completing a mainline task**: Move it to "Completed and Verified" with evidence (but mark as "pending verification")
  1176. 7. **If you discover the plan has errors**:
  1177. - Do NOT silently change direction
  1178. - Add entry to "Plan Evolution Log" with justification
  1179. - Explain how the change still serves the Ultimate Goal
  1180. 8. **If you need to defer a task**:
  1181. - Move it to "Explicitly Deferred" section
  1182. - Provide strong justification
  1183. - Explain impact on Acceptance Criteria
  1184. 9. **If you discover new issues**:
  1185. - Add to "Blocking Side Issues" only if mainline progress is blocked
  1186. - Otherwise add to "Queued Side Issues" or keep them as \`[queued]\` tasks/backlog
  1187. ---
  1188. Note: You MUST NOT try to exit \`start-rlcr-loop\` loop by lying or edit loop state file or try to execute \`cancel-rlcr-loop\`
  1189. After completing the work, please:
  1190. 0. If you have access to the \`code-simplifier\` agent, use it to review and optimize the code you just wrote
  1191. 1. Finalize @$GOAL_TRACKER_FILE (this is Round 0, so you are initializing it - see "Goal Tracker Setup" above)
  1192. 2. Write your round contract into @$ROUND_CONTRACT_PATH
  1193. 3. Commit your changes with a descriptive commit message
  1194. 4. Write your work summary into @$SUMMARY_PATH
  1195. EOF
  1196. # Add push instruction only if push_every_round is true
  1197. if [[ "$PUSH_EVERY_ROUND" == "true" ]]; then
  1198. cat >> "$LOOP_DIR/round-0-prompt.md" << 'EOF'
  1199. Note: Since `--push-every-round` is enabled, you must push your commits to remote after each round.
  1200. EOF
  1201. fi
  1202. fi # End of skip-impl prompt handling
  1203. # ========================================
  1204. # Output Setup Message
  1205. # ========================================
  1206. # All important work is done. If output fails due to SIGPIPE (pipe closed), exit cleanly.
  1207. # This trap is set here (not at script start) to avoid affecting internal pipelines.
  1208. trap 'exit 0' PIPE
  1209. if [[ "$SKIP_IMPL" == "true" ]]; then
  1210. cat << EOF
  1211. === start-rlcr-loop activated (SKIP-IMPL MODE) ===
  1212. Mode: Code Review Only (--skip-impl)
  1213. Start Branch: $START_BRANCH
  1214. Base Branch: $BASE_BRANCH
  1215. Codex Model: $CODEX_MODEL
  1216. Codex Effort: $CODEX_EFFORT
  1217. Codex Timeout: ${CODEX_TIMEOUT}s
  1218. Loop Directory: $LOOP_DIR
  1219. Skip-impl mode is active. The implementation phase is skipped.
  1220. When you try to exit, codex review will run automatically by itself.
  1221. The loop will:
  1222. 1. Run codex review on changes between $BASE_BRANCH and $START_BRANCH
  1223. 2. If issues are found ([P0-9] markers), you'll need to fix them
  1224. 3. When no issues remain, enters Finalize Phase and loop ends
  1225. To cancel: /humanize:cancel-rlcr-loop
  1226. ---
  1227. EOF
  1228. else
  1229. cat << EOF
  1230. === start-rlcr-loop activated ===
  1231. Plan File: $PLAN_FILE ($LINE_COUNT lines)
  1232. Plan Tracked: $TRACK_PLAN_FILE
  1233. Start Branch: $START_BRANCH
  1234. Base Branch: $BASE_BRANCH
  1235. Max Iterations: $MAX_ITERATIONS
  1236. Codex Model: $CODEX_MODEL
  1237. Codex Effort: $CODEX_EFFORT
  1238. Codex Timeout: ${CODEX_TIMEOUT}s
  1239. Full Review Round: $FULL_REVIEW_ROUND (Full Alignment Checks at rounds $((FULL_REVIEW_ROUND - 1)), $((2 * FULL_REVIEW_ROUND - 1)), $((3 * FULL_REVIEW_ROUND - 1)), ...)
  1240. Ask User for Codex Questions: $ASK_CODEX_QUESTION
  1241. Agent Teams: $AGENT_TEAMS
  1242. Loop Directory: $LOOP_DIR
  1243. The loop is now active. When you try to exit:
  1244. 1. Codex will review your work summary
  1245. 2. If issues are found, you'll receive feedback and continue
  1246. 3. If Codex outputs "COMPLETE", enters Review Phase (code review)
  1247. 4. Code review checks for [P0-9] issues; if found, you fix them
  1248. 5. When no issues found, enters Finalize Phase and loop ends
  1249. To cancel: /humanize:cancel-rlcr-loop
  1250. ---
  1251. EOF
  1252. fi
  1253. # Output the initial prompt
  1254. cat "$LOOP_DIR/round-0-prompt.md"
  1255. echo ""
  1256. echo "==========================================="
  1257. echo "CRITICAL - Work Completion Requirements"
  1258. echo "==========================================="
  1259. echo ""
  1260. echo "When you complete your work, you MUST:"
  1261. echo ""
  1262. if [[ "$PUSH_EVERY_ROUND" == "true" ]]; then
  1263. echo "1. COMMIT and PUSH your changes:"
  1264. echo " - Create a commit with descriptive message"
  1265. echo " - Push to the remote repository"
  1266. else
  1267. echo "1. COMMIT your changes:"
  1268. echo " - Create a commit with descriptive message"
  1269. echo " - (Commits stay local - no push required)"
  1270. fi
  1271. echo ""
  1272. echo "2. Write a detailed summary to:"
  1273. echo " $SUMMARY_PATH"
  1274. echo ""
  1275. echo " The summary should include:"
  1276. echo " - What was implemented"
  1277. echo " - Files created/modified"
  1278. echo " - Tests added/passed"
  1279. echo " - Any remaining items"
  1280. echo " - ## BitLesson Delta section (Action: none|add|update)"
  1281. echo ""
  1282. echo "Codex will review this summary to determine if work is complete."
  1283. echo "==========================================="
  1284. # Explicit exit 0 to ensure clean exit code even if final output fails
  1285. exit 0

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.