@jhlee0619/codexloop 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,177 @@
1
+ ---
2
+ name: cloop
3
+ description: Drive iterative improvement loops through the `cloop` shell command (CodexLoop). Use ONLY when the user's request explicitly contains one of `cloop`, `codexloop`, `CodexLoop`, or `CODEXLOOP` by name (case-insensitive match). Do NOT activate this skill for generic iterative phrasing like "iteratively fix X", "keep trying until tests pass", or "loop until it works". When activated, walk the user through goal clarification + plan approval BEFORE invoking `cloop start`.
4
+ metadata:
5
+ short-description: Iterate with CodexLoop when the user asks for it by name
6
+ ---
7
+
8
+ # CodexLoop (cloop)
9
+
10
+ `cloop` is a shell command that drives Codex through strict evaluate →
11
+ suggest → rank → apply → validate → record iterations until a goal is met,
12
+ the loop converges, or a budget limit fires. It spawns its own `codex exec`
13
+ child processes, so every iteration runs in an independent ephemeral Codex
14
+ session with a fresh context window.
15
+
16
+ ## When to use this skill
17
+
18
+ **Only** activate when the user's request explicitly contains one of these
19
+ tokens (case-insensitive): `cloop`, `codexloop`, `CodexLoop`, or
20
+ `CODEXLOOP`. Examples of valid triggers:
21
+
22
+ - "Use cloop to fix the failing auth tests"
23
+ - "codexloop this failing build"
24
+ - "Run a CodexLoop on src/add.js"
25
+ - "CODEXLOOP — fix the broken add test"
26
+ - "cloop --max-iter 5 for the adds function"
27
+ - "start cloop with goal X and budget 30 minutes"
28
+
29
+ **Do NOT activate** for any of these:
30
+
31
+ - "iteratively fix X" / "keep iterating on this"
32
+ - "loop on this until tests pass"
33
+ - "try a few approaches and pick the best one"
34
+ - any iterative-task phrasing that does NOT name cloop
35
+
36
+ If the user describes an iterative task WITHOUT naming cloop, you may
37
+ **suggest** the tool by name ("you could use cloop for this — it's the
38
+ iterative loop driver installed on this machine; run it with `cloop start`")
39
+ and ask whether they want to use it. Never invoke cloop unilaterally.
40
+
41
+ ## Prerequisites
42
+
43
+ Verify before proceeding:
44
+
45
+ 1. `cloop --version` succeeds (the shell wrapper is on PATH).
46
+ 2. `codex --version` succeeds.
47
+ 3. Current directory is a git repository (`git rev-parse --show-toplevel`).
48
+ 4. Working tree is clean (`git status --porcelain` is empty). If dirty, stop and tell the user to commit or stash.
49
+
50
+ If `cloop` is missing, **do not try to install it yourself**. Tell the user:
51
+
52
+ > "Install with `npm install -g @jhlee0619/codexloop` or run the one-liner:
53
+ > `curl -fsSL https://raw.githubusercontent.com/jhlee0619/CodexLoop/main/install.sh | sh`"
54
+
55
+ Then stop.
56
+
57
+ ## Workflow
58
+
59
+ When activated, run the interview BEFORE calling `cloop start`. The
60
+ interview mirrors the Claude Code `/cloop:start` flow so behavior is
61
+ consistent across platforms.
62
+
63
+ ### Step 1 — goal capture and clarification
64
+
65
+ Assemble the goal in this priority order:
66
+
67
+ 1. If the user's message already contains a clear one-sentence goal, use it as the seed.
68
+ 2. Otherwise read `TASK.md`, `GOAL.md`, `PRD.md`, or `AGENTS.md` from the repo root if any exist and offer the contents as a seed.
69
+ 3. Otherwise ask the user directly what they want to achieve.
70
+
71
+ Rewrite the seed into **one concrete sentence** that names the files,
72
+ symbols, or behaviors involved. Show the rewritten sentence back and ask
73
+ the user to confirm or rephrase. Iterate once more if they rephrase.
74
+
75
+ The final goal text is immutable — `cloop` hashes it on first iteration and
76
+ asserts no drift across subsequent iterations, so get it right now.
77
+
78
+ ### Step 2 — plan assembly
79
+
80
+ Walk these slots in order. For each, infer plausible values from the repo
81
+ (read `package.json`, `Makefile`, `pyproject.toml`, `go.mod`, etc.) so the
82
+ user only confirms or adjusts instead of typing from scratch.
83
+
84
+ 1. **Acceptance criteria** — 1–3 concrete, verifiable signals of success. Examples: "`npm test -- tests/auth` exits 0", "no new type errors introduced", "ESLint reports 0 errors". If the user cannot name any, default to `<testCmd> exits 0` once you have a test command.
85
+ 2. **Test command** (`--test-cmd`) — propose 2–3 candidates from the repo (npm scripts, Makefile targets, `node --test tests/`, `pytest`, `cargo test`, `go test ./...`). Ask the user to pick one or provide a custom command. Skippable only if the user explicitly says no tests.
86
+ 3. **Lint command** (`--lint-cmd`) — optional. Propose `npm run lint` / `eslint .` / `ruff check .` / `golangci-lint run` based on what you see.
87
+ 4. **Type command** (`--type-cmd`) — optional. Propose `npm run typecheck` / `tsc --noEmit` / `mypy .` / `go vet ./...`.
88
+ 5. **Budget** — defaults are `--max-iter 20 --max-time 1h --max-calls 200`. Ask only if the user hinted at a specific budget in their request.
89
+ 6. **Model + reasoning effort** — defaults are `gpt-5.4` / `xhigh` and are usually fine. Ask only if the user mentioned cost, speed, or a specific model.
90
+ 7. **Execution mode** — recommend `--wait` when the loop is short (max-iter ≤ 2) or `--dry-run`, otherwise recommend `--background`. Background spawns a detached Node worker via `spawnDetached({ detached: true, stdio: "ignore" }).unref()` that survives the current Codex session — closing Codex does NOT kill the worker. Foreground blocks the current shell turn until the loop exits.
91
+
92
+ ### Step 3 — approval
93
+
94
+ Print the complete plan in one block and ask the user to approve it
95
+ explicitly. Example format:
96
+
97
+ ```
98
+ CodexLoop plan:
99
+ Goal: fix src/add.js so all tests in tests/add.test.js pass
100
+ Acceptance criteria:
101
+ - node --test tests/ exits 0
102
+ - no test files are deleted or skipped
103
+ Test command: node --test tests/
104
+ Lint command: (skip)
105
+ Type command: (skip)
106
+ Budget: 5 iter / 30m / 200 calls
107
+ Model: gpt-5.4 (xhigh reasoning)
108
+ Mode: background
109
+ ```
110
+
111
+ Then ask: **"Start the loop with this plan?"** with clear choices:
112
+
113
+ - `Start loop`
114
+ - `Edit the goal`
115
+ - `Edit plan details`
116
+ - `Cancel`
117
+
118
+ Wait for an explicit answer. Never auto-approve. The one exception is when
119
+ the user's original message already said something unambiguous like
120
+ "…start the loop right away" or included `--yes` — in that case still
121
+ print the plan summary but skip the confirmation dialog.
122
+
123
+ ### Step 4 — invoke cloop
124
+
125
+ Build a single `cloop start` command with every confirmed flag. Quote
126
+ strings with spaces. Include `--yes` so the runtime knows the approval
127
+ step already happened.
128
+
129
+ ```bash
130
+ cloop start --background --yes \
131
+ --goal "fix src/add.js so all tests in tests/add.test.js pass" \
132
+ --test-cmd "node --test tests/" \
133
+ --max-iter 5 \
134
+ --max-time 30m
135
+ ```
136
+
137
+ Defaults are `--model gpt-5.4 --effort xhigh` — only pass them if the user
138
+ chose something different.
139
+
140
+ Run the command as a regular shell tool call. In background mode, `cloop`
141
+ spawns its own detached Node worker and returns immediately with the
142
+ `loopId`, `pid`, and log path. **Forward that output to the user verbatim**;
143
+ do not paraphrase.
144
+
145
+ Then tell the user:
146
+
147
+ > "CodexLoop started in the background. Check progress with `cloop status`
148
+ > or `cloop result`, and stop it with `cloop stop` if needed."
149
+
150
+ ## Related commands
151
+
152
+ Offer these when relevant but do NOT run them without being asked:
153
+
154
+ - `cloop status` — current loop state, iteration history, quality scores, budget consumption.
155
+ - `cloop status --json` — same as above, JSON output.
156
+ - `cloop result` — full iteration history with ranking breakdowns and validation results.
157
+ - `cloop result --iteration N` — zoom in on a single iteration.
158
+ - `cloop result --json` — JSON dump of `.loop/state.json` plus every iteration file.
159
+ - `cloop stop` — SIGTERM the background worker (graceful shutdown at next iteration boundary).
160
+ - `cloop stop --force` — SIGKILL. Only use on explicit second confirmation from the user.
161
+ - `cloop iterate` — run exactly one iteration synchronously. Useful for step-through debugging or to advance a paused loop.
162
+ - `cloop iterate --dry-run` — same but skip apply + validate.
163
+ - `cloop model` — show the loop's current model + reasoning effort.
164
+ - `cloop model <name>` — change the model (e.g. `cloop model gpt-5.4-mini`).
165
+ - `cloop model --effort <level>` — change reasoning effort (one of `none`, `minimal`, `low`, `medium`, `high`, `xhigh`).
166
+ - `cloop model --clear` — reset model + effort to the codex CLI default.
167
+ - `cloop model --list` — list known model aliases and valid effort levels.
168
+
169
+ ## Hard rules
170
+
171
+ 1. **Never** invoke `cloop start` without explicit user approval in this session. Skipping step 3 is not allowed even if the user seems impatient.
172
+ 2. **Never** modify the confirmed goal text after step 3. `cloop` will detect drift via its goalHash check and refuse to run.
173
+ 3. **Never** use `cloop stop --force` without a second, explicit confirmation from the user. SIGKILL loses the in-flight iteration.
174
+ 4. **Never** run `cloop start` if the working tree is dirty. Tell the user to commit or stash.
175
+ 5. **Never** try to install `cloop` yourself. If it is missing, give the user install instructions and stop.
176
+ 6. **Never** `cloop start` a second loop in the same repo while one is already running. The runtime refuses anyway via the `.loop/loop.lock` advisory lock — respect it and tell the user to `cloop status` or `cloop stop` first.
177
+ 7. If the user says "stop" mid-loop without specifying force, call `cloop stop` (SIGTERM) and wait up to 60 seconds for graceful shutdown before even mentioning `--force`.