levi-gear 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ # Codex runner
2
+
3
+ Run from the project root and persist the workflow after intake derives the slug:
4
+
5
+ ```bash
6
+ node <this skill folder>/scripts/codex-run-state.mjs status docs/levi/<slug>
7
+ node <this skill folder>/scripts/codex-run-state.mjs init docs/levi/<slug> design <slug> context references draw decide check finalize
8
+ ```
9
+
10
+ ```bash
11
+ node <this skill folder>/scripts/codex-run-state.mjs begin docs/levi/<slug> <stage>
12
+ node <this skill folder>/scripts/codex-run-state.mjs complete docs/levi/<slug> <stage> <artifact>...
13
+ node <this skill folder>/scripts/codex-run-state.mjs wait docs/levi/<slug> <stage> "<questions>"
14
+ node <this skill folder>/scripts/codex-run-state.mjs block docs/levi/<slug> <stage> "<blocker>"
15
+ node <this skill folder>/scripts/codex-run-state.mjs resume docs/levi/<slug>
16
+ ```
17
+
18
+ Read `status` first after an interruption. Begin the active stage, complete it only after the listed output is present, and use `wait`, `block`, and `resume` for user decisions and external prerequisites. Do not redo a completed stage or rewrite a user upload.
19
+
20
+ - `context`: select the target design folder and optional read-only spec.
21
+ - `references`: make only the permitted reference descriptions and video frames. If ffmpeg is missing, mark this stage `block` with the request for screenshots or ffmpeg; do not guess the video.
22
+ - `draw`: dispatch `levi-designer` with exact input/output paths. Complete only when the output folder contains its SVG files.
23
+ - `decide`: run the initial checker/render needed to make an informed decision, then preserve the designer's material questions with `wait`. After an answer, `resume` and make the permitted final design change; otherwise complete with the recorded assumptions. Do not mark final verification complete here.
24
+ - `check`: run the final SVG checker and, when available, render the final files. If a repair is needed, keep this stage active while the designer gets the exact findings once, then check again. Record the render/check artifacts.
25
+ - `finalize`: report verified SVG files, then remove frames, reference descriptions, renders and `run.json`. Never delete uploads or the read-only spec.
26
+
27
+ Only `levi-designer` writes SVG files. The coordinator runs checks and advances state.
@@ -14,7 +14,7 @@ Fix a bug with the team: `levi-developer` clarifies, investigates and fixes, `le
14
14
  The work has two halves:
15
15
 
16
16
  - **Clarify** (steps 1 to 5), here in the conversation, because it needs the user. The developer lists what is unclear and the user confirms it.
17
- - **Fix** (step 6), without the user. With a Workflow tool (Claude Code) it runs as `workflow.js`: every agent call is a fresh subagent that sees only the files it is given, and the developer and QA work at the same time without reading each other's work. Without one, you run the same steps one by one.
17
+ - **Fix** (step 6), without the user. Claude Code runs `workflow.js`; Codex uses the durable runner in [`references/codex-runner.md`](references/codex-runner.md). Every agent call is a fresh subagent that sees only the files it is given, and the developer and QA work at the same time without reading each other's work.
18
18
 
19
19
  ## The rules that never bend
20
20
 
@@ -67,14 +67,15 @@ The work has two halves:
67
67
  ```
68
68
 
69
69
  Set `allMerged` to false when step 2 found unmerged work.
70
- - *Without a Workflow tool:* run the steps under [Workflow](#workflow) below yourself, in order, each agent call as a new subagent call that gets only the paths and instructions written there.
70
+ - *On Codex:* follow [`references/codex-runner.md`](references/codex-runner.md), which persists `docs/levi/<slug>/run.json`, then run the steps under [Workflow](#workflow) through that runner.
71
+ - *Other tools without a Workflow tool:* run the steps under [Workflow](#workflow) below yourself, in order, each agent call as a new subagent call that gets only the paths and instructions written there.
71
72
  7. **Act on the result.**
72
73
  - `done`: go to step 8.
73
74
  - `questions`: an agent found a point that is still open. Ask the user, append the answers to `confirmed.md`, and run step 6 again.
74
75
  - `not_a_bug`: the developer found that the code does what the spec and the confirmed points expect. Tell the user why, clean up (step 8) and stop.
75
76
  - `unmerged`: the root cause is in code that is not merged into the base branch. Tell the user it is a revision of unmerged work, not a bug, with the root cause and its locations. Clean up and stop. The code was not changed.
76
77
  - `blocked`: something outside the code stops the work (the app cannot start, a service or credential is missing, no test could be made to fail on the bug). Tell the user the stage, the detail and what they need to provide. Keep `docs/levi/<slug>/` and run step 6 again when they say to.
77
- - `stalled`: the rounds ran out (10 by default) and something still fails. Tell the user what failed last. If they want to go on, in the same session call the Workflow tool again with `resumeFromRunId` and a higher `maxRounds`. Tests and test cases still do not change.
78
+ - `stalled`: the rounds ran out (10 by default) and something still fails. Tell the user what failed last. On Claude Code, continue in the same session with `resumeFromRunId` and a higher `maxRounds`; on Codex, keep `run.json` and resume the active `build` stage when the user asks to continue. Tests and test cases still do not change.
78
79
  8. **Clean up.** Delete `docs/levi/<slug>/`, then `docs/levi` if it is empty. Keep everything else.
79
80
  9. **Report.** Tell the user: the root cause and where it was; the tests that cover the bug (written now, or existing ones) and the command that runs them; the test case files with their result (for example `4/4 PASS`); how many rounds it took; the review outcome and the suggestions left open; the files changed (from `git status`); and that nothing was committed.
80
81
 
@@ -91,6 +92,6 @@ The steps `workflow.js` runs, and the ones you run when there is no Workflow too
91
92
  5. **Rounds** (at most 10 unless raised), each starting with a fresh `levi-developer` call:
92
93
  1. *Fix.* The developer fixes the code: first as planned in `investigation.md`, later what the last round sent back. It fixes the cause, not the symptom.
93
94
  2. *Tests.* `lock-tests.mjs verify` on the tests (any changed test is restored and the developer is told), then the bug's tests, then the whole suite. A failure goes back to the developer.
94
- 3. *Review.* Once the tests pass, a fresh `levi-teamlead` call reviews the change since the baseline: the root cause fixed everywhere, what the spec, designs and confirmed points expect, nothing else broken, security, performance, fit, following `levi-code-review/references/review-guide.md` and its checklists. It writes `review.md`. Critical or warning findings go back to the developer.
95
+ 3. *Review.* Once the tests pass, a fresh `levi-teamlead` call reviews the change since the baseline: the root cause fixed everywhere, what the spec, designs and confirmed points expect, nothing else broken, security, performance, fit, following `levi-code-review/references/review-guide.md` and its checklists. It writes `review.md`. A change of more than 100 reviewable files is reviewed in slices by several fresh `levi-teamlead` calls and merged by a lead call, as `levi-code-review/references/large-changes.md` says. Critical or warning findings go back to the developer.
95
96
  4. *E2E.* Once the review approves, `lock-tests.mjs verify` on the test cases undoes any change made outside QA. Then `levi-qa` runs every case in a headless browser (the project's E2E runner such as Playwright, or a browser tool; through the API or CLI when there is no UI) and records PASS or FAIL as its test case guide says; the snapshot is then taken again. Failing cases go back to the developer, and the next round runs tests, review and E2E again.
96
97
  5. The run is done when the review approves and every case passes.
@@ -0,0 +1,32 @@
1
+ # Codex runner
2
+
3
+ Use this durable runner on Codex instead of the Claude-only `workflow.js`. Run every command below from the project root. After clarification is complete, first inspect `docs/levi/<slug>/run.json`. If absent, initialize it:
4
+
5
+ ```bash
6
+ node <this skill folder>/scripts/codex-run-state.mjs init docs/levi/<slug> fix-bug <slug> baseline tests merge-check lock build
7
+ ```
8
+
9
+ For each current stage, call `begin` before dispatching the named Levi agent and `complete` only after its artifacts exist. `status` is the source of truth after an interruption; completed stages are never repeated. Use `wait` for questions that need the user, `block` for an external dependency, and `resume` after it is resolved. Do not use the Claude-only `resumeFromRunId`.
10
+
11
+ ```bash
12
+ node <this skill folder>/scripts/codex-run-state.mjs begin docs/levi/<slug> <stage>
13
+ node <this skill folder>/scripts/codex-run-state.mjs complete docs/levi/<slug> <stage> <artifact>...
14
+ node <this skill folder>/scripts/codex-run-state.mjs wait docs/levi/<slug> <stage> "<questions>"
15
+ node <this skill folder>/scripts/codex-run-state.mjs block docs/levi/<slug> <stage> "<blocker>"
16
+ node <this skill folder>/scripts/codex-run-state.mjs resume docs/levi/<slug>
17
+ ```
18
+
19
+ For a valid terminal result that does not build a fix, use `finish` before cleanup:
20
+
21
+ ```bash
22
+ node <this skill folder>/scripts/codex-run-state.mjs finish docs/levi/<slug> tests
23
+ node <this skill folder>/scripts/codex-run-state.mjs finish docs/levi/<slug> merge-check
24
+ ```
25
+
26
+ - `baseline`: record the baseline commit and dirty paths for the later review.
27
+ - `tests`: QA writes and PM-approved scenarios while the developer investigates and produces a failing test. Both tracks are separate; complete only with `investigation.md`, `test-cases.json`, and the rendered scenario files. When the code already does what is expected, use `finish` at this stage and report `not_a_bug`; do not build a change.
28
+ - `merge-check`: run the existing blame/ancestor check when the initial check did not prove all code merged. For unmerged root-cause code, use `finish` at this stage, report `unmerged`, and do not fix it.
29
+ - `lock`: lock the developer tests and QA cases with the existing lock script. Require both lock manifests.
30
+ - `build`: run the existing code → test gate → teamlead review → QA E2E loop (a review of more than 100 reviewable files follows `levi-code-review/references/large-changes.md`: split, parallel slice reviews, one merge). Keep the stage active across all rounds. Complete only after approved review and all cases PASS.
31
+
32
+ Use installed named roles for every subagent call. The coordinator owns the checkpoint and stages; subagents only read/write their assigned artifacts. Keep dependent work sequential and use parallel calls only for the independent QA and investigation tracks.
@@ -193,6 +193,101 @@ if (!lockedTests || lockedTests.exitCode !== 0) return { status: 'blocked', stag
193
193
 
194
194
  const RULES = `The test cases in ${SCENARIO_FILES.join(' and ')} belong to QA: do not edit them; a change by anyone else is undone. Locked files: the tests ${inv.bugTests.join(', ')}. They are the definition of done. Never edit, delete, rename, skip or weaken any of them, and never change test configuration to leave them out. A locked file you change is restored automatically and your work is wasted. When a test fails, the code is wrong: fix the code, at the root cause, without special-casing test inputs.`
195
195
 
196
+ const REVIEW_PHASE = 'Fix'
197
+ // ---- review of the change: one teamlead, or slices merged by a lead when the change is large ----
198
+ // levi-code-review/references/large-changes.md explains why: one reviewer skims a big change and finds problems a few at a time.
199
+
200
+ const LARGE_CHANGE = 100 // reviewable files; more than this is reviewed in slices
201
+ const LARGE_GUIDE = `${A.skillDir}/../levi-code-review/references/large-changes.md`
202
+ const FINDING = CODE_REVIEW.properties.findings.items
203
+ const CHANGED = obj({ files: { type: 'array', items: obj({ path: { type: 'string' }, lines: { type: 'integer' } }) } })
204
+ const SLICES = obj({ slices: { type: 'array', items: obj({ title: { type: 'string' }, files: STRINGS, shares: { type: 'string' } }) } })
205
+ const SLICE_REVIEW = obj({ summary: { type: 'string' }, findings: { type: 'array', items: FINDING }, crossSlice: STRINGS, notChecked: STRINGS })
206
+
207
+ // What is wrong with a split: a slice over the limit, a file in no slice, a file in two slices or not in the change.
208
+ const splitProblems = (slices, paths) => {
209
+ const placed = slices.flatMap((s) => s.files)
210
+ return [
211
+ ...slices.filter((s) => s.files.length > LARGE_CHANGE).map((s) => `slice "${s.title}" has ${s.files.length} files, more than ${LARGE_CHANGE}`),
212
+ ...paths.filter((p) => !placed.includes(p)).map((p) => `${p} is in no slice`),
213
+ ...placed.filter((p, i) => placed.indexOf(p) !== i || !paths.includes(p)).map((p) => `${p} is in two slices or not part of the change`),
214
+ ]
215
+ }
216
+
217
+ async function splitChange(round, files) {
218
+ const paths = files.map((f) => f.path)
219
+ const ask = (note) =>
220
+ agent(
221
+ `${CONTEXT}
222
+
223
+ This change is too large for one reviewer (${paths.length} reviewable files). Split it into slices that are reviewed at the same time, as the "Steps" of ${LARGE_GUIDE} say: at most ${LARGE_CHANGE} files per slice and as few slices as that allows, grouped by what belongs together (a module or feature with its tests, callers, schema and migrations; never by alphabet), every file in exactly one slice. For each slice return a title, its files, and one line on what it shares with the other slices (an interface, a schema, a config). Change nothing and write no file.
224
+ The files, with their changed lines:
225
+ ${files.map((f) => `${f.path} (${f.lines})`).join('\n')}${note}`,
226
+ { label: `teamlead:split-${round}`, phase: REVIEW_PHASE, agentType: 'levi-teamlead', schema: SLICES },
227
+ )
228
+ let split = await ask('')
229
+ let problems = split ? splitProblems(split.slices, paths) : ['no split was returned']
230
+ if (problems.length) {
231
+ split = await ask(`\n\nYour previous split was not valid: ${problems.slice(0, 20).join('; ')}. Return the whole corrected split.`)
232
+ problems = split ? splitProblems(split.slices, paths) : ['no split was returned']
233
+ }
234
+ if (!problems.length) return split.slices
235
+ log(`the lead's split was not usable (${problems[0]}); cutting the file list by path`)
236
+ const sorted = [...paths].sort()
237
+ return Array.from({ length: Math.ceil(sorted.length / LARGE_CHANGE) }, (_, i) => ({
238
+ title: `Files ${i * LARGE_CHANGE + 1}-${Math.min((i + 1) * LARGE_CHANGE, sorted.length)} by path`,
239
+ files: sorted.slice(i * LARGE_CHANGE, (i + 1) * LARGE_CHANGE),
240
+ shares: 'unknown: read the other slices as needed',
241
+ }))
242
+ }
243
+
244
+ // `brief` says what the review is for and what to check; `output` says where the review goes and what blocks.
245
+ async function reviewChange(round, brief, output) {
246
+ const changed = await guard(
247
+ `changed-files-${round}`,
248
+ `List the reviewable files of the change: every file that differs from commit ${base.head} (git diff --name-only ${base.head}) and every untracked file (git status --porcelain), leaving out files that were already modified before the run (${base.dirty.join(', ') || 'none'}), generated files, lock files, vendored code and build output. Give each path with its number of changed lines (git diff --numstat ${base.head}; the line count for an untracked file).`,
249
+ CHANGED,
250
+ )
251
+ if (!changed) return null
252
+ const prompt = `${CONTEXT}\n\n${brief}\nFollow ${REVIEW_GUIDE} and the two checklists next to it (security by OWASP Top 10, performance and correctness), but write the findings where and how this prompt says.`
253
+ if (changed.files.length <= LARGE_CHANGE) {
254
+ return agent(`${prompt}\n${output}`, { label: `teamlead:review-${round}`, phase: REVIEW_PHASE, agentType: 'levi-teamlead', schema: CODE_REVIEW })
255
+ }
256
+
257
+ log(`round ${round}: ${changed.files.length} reviewable files, so the review is split into slices (${LARGE_GUIDE})`)
258
+ const slices = await splitChange(round, changed.files)
259
+ const others = (i) => slices.map((s, j) => (j === i ? null : `- ${s.title} (${s.files.length} files): shares ${s.shares}`)).filter(Boolean).join('\n')
260
+ const reviewSlice = (s, i) =>
261
+ agent(
262
+ `${prompt}
263
+
264
+ This change is large (${changed.files.length} reviewable files), so ${slices.length} reviewers each review one slice at the same time, and a lead merges their reports. You review slice ${i + 1}: ${s.title}. It shares: ${s.shares}.
265
+ Your files, to review in full:
266
+ ${s.files.join('\n')}
267
+ The other slices:
268
+ ${others(i)}
269
+ Report every finding you can make a case for in your files, in one pass, whatever the severity: nothing is held for a later round, because the author fixes the whole list at once. When a change in your files breaks or relies on code in another slice, report it on your file and name the other location; what only another slice's reviewer can settle goes in crossSlice. Do not write ${REVIEW} or any other file and change nothing: your reply is the review of this slice. Give no verdict for the whole change. Findings carry the same fields as in a full review.`,
270
+ { label: `teamlead:review-${round}-slice-${i + 1}`, phase: REVIEW_PHASE, agentType: 'levi-teamlead', schema: SLICE_REVIEW },
271
+ )
272
+ const reports = [...(await parallel(slices.map((s, i) => () => reviewSlice(s, i))))]
273
+ const failed = slices.map((_, i) => i).filter((i) => !reports[i])
274
+ if (failed.length) {
275
+ const again = await parallel(failed.map((i) => () => reviewSlice(slices[i], i)))
276
+ failed.forEach((i, k) => (reports[i] = again[k]))
277
+ }
278
+ if (reports.some((r) => !r)) return null
279
+
280
+ return agent(
281
+ `${prompt}
282
+
283
+ You are the lead teamlead. ${slices.length} reviewers reviewed this large change in slices; ${LARGE_GUIDE} ("Steps", the merge) says how to combine them. Their reports:
284
+ ${JSON.stringify(slices.map((s, i) => ({ slice: s.title, files: s.files.length, report: reports[i] })))}
285
+ Merge them into the one review: join findings that have one cause (list every location), give equal problems equal severity, settle each crossSlice item by reading the code on both sides, re-read the location of every critical finding before you keep it, keep every valid finding and add nothing else. Do not approve while any slice lists something in notChecked that matters to the verdict.
286
+ ${output}`,
287
+ { label: `teamlead:review-${round}-merge`, phase: REVIEW_PHASE, agentType: 'levi-teamlead', schema: CODE_REVIEW },
288
+ )
289
+ }
290
+
196
291
  // ---- Fix: fix, tests, review, E2E, until the review approves and every scenario passes ----
197
292
 
198
293
  phase('Fix')
@@ -231,15 +326,14 @@ for (let round = 1; round <= MAX_ROUNDS; round++) {
231
326
  continue
232
327
  }
233
328
 
234
- const review = await agent(
235
- `${CONTEXT}\nInvestigation: ${INVESTIGATION}
329
+ const review = await reviewChange(
330
+ round,
331
+ `Investigation: ${INVESTIGATION}
236
332
 
237
333
  Review the developer's fix of this bug. The change is everything that differs from commit ${base.head} (git diff and untracked files), leaving out files that were already modified before the run: ${base.dirty.join(', ') || 'none'}.
238
334
  The unit and feature tests pass. They are locked: do not propose changing them.
239
- Check that the fix removes the root cause rather than the symptom, everywhere it occurs; that it does what the spec, the designs and the confirmed points expect; that it breaks nothing else; and its security (input validation, authorization, secrets), performance and fit with the architecture and conventions.
240
- Follow ${REVIEW_GUIDE} and the two checklists next to it (security by OWASP Top 10, performance and correctness), but write the findings where and how this prompt says.
241
- Write ${REVIEW}: findings graded critical / warning / suggestion, each with the file, the problem and a concrete fix. Approve only when no critical or warning finding remains; suggestions alone do not block.`,
242
- { label: `teamlead:review-${round}`, phase: 'Fix', agentType: 'levi-teamlead', schema: CODE_REVIEW },
335
+ Check that the fix removes the root cause rather than the symptom, everywhere it occurs; that it does what the spec, the designs and the confirmed points expect; that it breaks nothing else; and its security (input validation, authorization, secrets), performance and fit with the architecture and conventions.`,
336
+ `Write ${REVIEW}: findings graded critical / warning / suggestion, each with the file, the problem and a concrete fix. Approve only when no critical or warning finding remains; suggestions alone do not block.`,
243
337
  )
244
338
  if (!review) return { status: 'blocked', stage: 'review', detail: 'the review did not complete' }
245
339
  const blocking = review.findings.filter((f) => f.severity !== 'suggestion')
@@ -26,6 +26,7 @@ skill-guide: references/test-case-guide.md
26
26
  | `docs/tests/<base>.xlsx` | QA | **Deliverable**: one sheet, one row per case, columns `ID, Title, Category, Priority, Preconditions, Steps, Expected Result, Notes` |
27
27
  | `docs/levi/test-cases/<FeatureID>-analysis.md` | QA | Scratch: spec items, coverage plan, ambiguities, readiness |
28
28
  | `docs/levi/test-cases/<FeatureID>.json` | QA | Scratch: the cases the two deliverables are rendered from |
29
+ | `docs/levi/test-cases/selection.md` | Workflow | Scratch: the confirmed feature list, output bases and overwrite choices for a resumable Codex run |
29
30
  | `references/test-case-guide.md` | - | How QA analyzes the spec and writes the cases |
30
31
  | `scripts/render-test-cases.mjs` | - | Checks the cases and renders both deliverables from them, so they always agree. The cases are also embedded in the `.md`, so QA can change them later |
31
32
 
@@ -40,6 +41,10 @@ A feature is one spec file, or one folder of spec files, under `docs/specs/` (se
40
41
  | Output `<base>` | `<FeatureID>-<slug>` when the spec has a code (`F001-login`); `<slug>-test-cases` when it has none (`export-orders-csv-test-cases`) |
41
42
  | Case ID | `TC-<FeatureID>-<3 digits>`, for example `TC-F001-001` |
42
43
 
44
+ ## Codex runner
45
+
46
+ On Codex, use [`references/codex-runner.md`](references/codex-runner.md). It checkpoints selection, per-feature QA work and verification in `docs/levi/test-cases/run.json` so a stopped run does not silently regenerate finished outputs.
47
+
43
48
  ## Steps
44
49
 
45
50
  1. **Intake.** From the request, take the feature codes (`F001`, `F002`, ...) and the spec files or folders it names. Anything else in it (a focus such as "only permissions") is passed to QA as written.
@@ -0,0 +1,32 @@
1
+ # Codex runner
2
+
3
+ Run from the project root with one durable state per invocation:
4
+
5
+ ```bash
6
+ node <this skill folder>/scripts/codex-run-state.mjs status docs/levi/test-cases
7
+ node <this skill folder>/scripts/codex-run-state.mjs init docs/levi/test-cases generate-test-scenarios test-cases select analyze report generate verify
8
+ ```
9
+
10
+ ```bash
11
+ node <this skill folder>/scripts/codex-run-state.mjs begin docs/levi/test-cases <stage>
12
+ node <this skill folder>/scripts/codex-run-state.mjs complete docs/levi/test-cases <stage> <artifact>...
13
+ node <this skill folder>/scripts/codex-run-state.mjs wait docs/levi/test-cases <stage> "<questions>"
14
+ node <this skill folder>/scripts/codex-run-state.mjs block docs/levi/test-cases <stage> "<blocker>"
15
+ node <this skill folder>/scripts/codex-run-state.mjs resume docs/levi/test-cases
16
+ ```
17
+
18
+ When a valid branch ends before the last stage, use `finish` rather than pretending later stages completed:
19
+
20
+ ```bash
21
+ node <this skill folder>/scripts/codex-run-state.mjs finish docs/levi/test-cases report
22
+ ```
23
+
24
+ Use `status` before continuing a stopped run. Begin the current stage, complete it only after its outputs exist, and use `wait`, `block`, and `resume` for user choices and dependencies. Record the selected feature list and output bases in `docs/levi/test-cases/selection.md`, then pass that file to `complete` for `select`. Do not regenerate a feature whose verify stage completed.
25
+
26
+ - `select`: find requested specs, report missing ones, and preserve required choices (all features, ambiguous codes, overwrite/versioned output) with `wait`. Complete when exact features and output bases are fixed in `selection.md`.
27
+ - `analyze`: dispatch one `levi-qa` agent per selected feature only. They may run in parallel because each owns `docs/levi/test-cases/<FeatureID>-analysis.md`. Complete only when every selected analysis exists.
28
+ - `report`: report `Generate: no` and ambiguities before any writing. If every selected feature is skipped, use `finish docs/levi/test-cases report` and clean up; otherwise continue.
29
+ - `generate`: dispatch QA only for features marked `Generate: yes`. Complete only when each `json` case source and both requested output files exist.
30
+ - `verify`: run `render-test-cases.mjs check` for every generated feature. QA may repair each failing feature once; a remaining failure marks this stage `block` with its errors. Complete only after all selected outputs validate, then cleanup removes the scratch state.
31
+
32
+ Only `levi-qa` writes analysis, case sources and deliverables. The coordinator does not edit those files.
@@ -22,6 +22,10 @@ A spec is a promise to the rest of the team: **a line goes into the spec only wh
22
22
 
23
23
  `<slug>` is a short kebab-case name for the subject, in English (for example `export-orders-csv`). Create folders as needed. Pass the PM the exact paths it should read and write. Only the PM touches either file.
24
24
 
25
+ ## Codex runner
26
+
27
+ On Codex, use [`references/codex-runner.md`](references/codex-runner.md). It persists question rounds and the selected output in `docs/levi/<slug>/run.json`, allowing the run to continue after an interruption.
28
+
25
29
  ## Steps
26
30
 
27
31
  1. **Intake.** The request is the subject. If it is empty, ask what the spec is about and stop. Derive the slug. Note every file or link the user mentioned: they are sources.
@@ -55,5 +59,5 @@ A spec is a promise to the rest of the team: **a line goes into the spec only wh
55
59
  - The user says to write now, or the three rounds are used up: go to step 6 with what is confirmed. Say what is still open.
56
60
  - The goal, the users or the core scope are still unconfirmed: do not write a spec. Tell the user exactly what is missing and stop. Keep `ledger.md` so a later run can continue; do not delete it.
57
61
  6. **PM writes the spec.** Call `levi-pm` with the ledger path and the spec path. It writes `docs/specs/<slug>.md` following `references/spec-guide.md`, using only Confirmed facts, in the language of the request. In update mode it changes only what a confirmed fact touches and leaves the rest as it was. Every unresolved question goes into the spec's Open questions; a section that depends on one says so instead of being filled in.
58
- 7. **Clean up.** Delete `ledger.md`, then remove `docs/levi/<slug>/` if empty, and `docs/levi` if that is empty. Delete only after the spec is written. The spec's Source column keeps the traceability.
62
+ 7. **Clean up.** Read `choices/` for the report if it exists, then delete it and `ledger.md`, then remove `docs/levi/<slug>/` if empty, and `docs/levi` if that is empty. Delete only after the spec is written. The spec's Source column keeps the traceability.
59
63
  8. **Report.** Tell the user the spec path, whether it is new or updated, its Status, how many stories and acceptance criteria it holds, the open questions still in it (one line each).
@@ -0,0 +1,25 @@
1
+ # Codex runner
2
+
3
+ Run this workflow from the project root with a durable checkpoint. Initialize it immediately after intake:
4
+
5
+ ```bash
6
+ node <this skill folder>/scripts/codex-run-state.mjs status docs/levi/<slug>
7
+ node <this skill folder>/scripts/codex-run-state.mjs init docs/levi/<slug> spec-writing <slug> discover decide write verify
8
+ ```
9
+
10
+ ```bash
11
+ node <this skill folder>/scripts/codex-run-state.mjs begin docs/levi/<slug> <stage>
12
+ node <this skill folder>/scripts/codex-run-state.mjs complete docs/levi/<slug> <stage> <artifact>...
13
+ node <this skill folder>/scripts/codex-run-state.mjs wait docs/levi/<slug> <stage> "<questions>"
14
+ node <this skill folder>/scripts/codex-run-state.mjs block docs/levi/<slug> <stage> "<blocker>"
15
+ node <this skill folder>/scripts/codex-run-state.mjs resume docs/levi/<slug>
16
+ ```
17
+
18
+ On a resumed run, `status` is authoritative. Begin the current stage, complete it only after the stated artifact exists, and never repeat a completed stage. Use `wait` to preserve unanswered user questions, `block` for an external dependency, and `resume` after it is resolved.
19
+
20
+ - `discover`: select update/new mode and dispatch `levi-pm` to write `ledger.md`. Complete with that ledger.
21
+ - `decide`: run the up-to-three user-answer rounds. Before each question round use `wait`; after the answer use `resume` and have the PM update `ledger.md`. Complete when it is ready to write, when the user explicitly asks to write with remaining questions, or mark `block` when the goal/users/core scope cannot be confirmed.
22
+ - `write`: dispatch `levi-pm` once with the ledger and selected spec path. Complete only when `docs/specs/<slug>.md` exists.
23
+ - `verify`: confirm the PM-owned spec is the requested new/update output and report its status. Cleanup can remove the state and ledger only after this stage completes.
24
+
25
+ The coordinator never edits the ledger or spec. Only `levi-pm` writes them.