zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

blob 7d2ea3e5 (5026B) - Raw


      1 ---
      2 name: port-astgen
      3 description: Iteratively port AstGen.zig to astgen.c by enabling skipped corpus tests, finding divergences, and mechanically copying upstream code.
      4 allowed-tools: Read, Write, Edit, Bash, Grep, Glob, Task
      5 disable-model-invocation: true
      6 ---
      7 
      8 # Port AstGen — Orchestrator
      9 
     10 You manage the iterative porting loop. For each iteration you either fix
     11 existing failures or enable a new disabled test, dispatch a worker agent,
     12 then verify and commit.
     13 
     14 **You do NOT**: analyze test output in detail, compare Zig/C code, or
     15 edit `astgen.c`. The worker handles all of that.
     16 
     17 **CRITICAL RULES:**
     18 1. **NEVER stop early.** Do not pause to ask the user if you should continue.
     19    Do not summarize remaining work and wait. Keep looping until every test is
     20    enabled and passing.
     21 2. **ALWAYS run the test command (in Phase 0, below) yourself before
     22    committing.** Never trust the worker's claim that tests pass — verify it. If
     23    the test run fails (non-zero exit) or it emits any output, do NOT commit and
     24    let the worker fix it.
     25 
     26 ## Phase 0: Check for leftovers
     27 
     28 Before enabling anything new, run the **full** test suite:
     29 
     30 ```sh
     31 cd ~/code/zig
     32 ./zig-out/bin/zig build all-zig0 -Dvalgrind > /dev/null 2>&1 ; echo "EXIT: $?"
     33 ```
     34 
     35 Also check for failures:
     36 
     37 ```sh
     38 ./zig-out/bin/zig build all-zig0 -Dvalgrind 2>&1 | grep -iE 'FAIL|error:' | head -5
     39 ```
     40 
     41 If EXIT is non-zero or any FAIL/error lines appear: dispatch a worker
     42 (Step 4 below) with context describing the failure — no test was
     43 "enabled", just paste the output and tell the worker existing tests are
     44 failing. After the worker returns, follow Steps 5–7 as normal. Re-run
     45 Phase 0 until the full test suite passes before proceeding to the main
     46 loop.
     47 
     48 If EXIT is 0 with no failures: proceed to the main loop.
     49 
     50 ## Main Loop
     51 
     52 Repeat until no `SkipZigTest` lines AND no commented corpus entries
     53 remain in `astgen_test.zig`.
     54 
     55 ### Step 1: Find the next disabled test
     56 
     57 Search `stage0/astgen_test.zig` in priority order:
     58 
     59 **Priority A — SkipZigTest lines:**
     60 Search for lines matching:
     61 ```
     62 if (true) return error.SkipZigTest
     63 ```
     64 Pick the first one. Note the test name (the `test "..."` header above
     65 the skip line) and the line number.
     66 
     67 **Priority B — Commented corpus entries:**
     68 If no SkipZigTest lines exist, search for lines matching `//"..\` inside
     69 the `corpus_files` tuple (between `const corpus_files = .{` and `};`).
     70 Pick the first one. Note the file name and line number.
     71 
     72 If neither is found, all tests are enabled — go to the final check.
     73 
     74 ### Step 2: Enable the test
     75 
     76 **For SkipZigTest:** Comment out the `if (true) return error.SkipZigTest;`
     77 line to enable the test.
     78 
     79 **For commented corpus entry:** Uncomment the line (remove the leading
     80 `//`).
     81 
     82 ### Step 3: Quick smoke test
     83 
     84 Run:
     85 ```sh
     86 ./zig-out/bin/zig build test-zig0 -Dzig0-cc=tcc 2>&1 | head -10
     87 ```
     88 Capture only the first ~10 lines. This tells you pass/fail at a glance
     89 without bloating your context. The worker will run the full test itself.
     90 
     91 ### Step 4: Dispatch worker
     92 
     93 1. Read the file `.claude/skills/port-astgen/worker-prompt.md`.
     94 2. Replace the placeholder `{{TEST_CONTEXT}}` with the actual context:
     95    - What was enabled: test name + line number (SkipZigTest) or
     96      corpus file name + line number (corpus entry)
     97    - Whether this is a SkipZigTest or a corpus entry
     98    - The first ~10 lines of test output from Step 3
     99 3. Launch via the Task tool:
    100    ```
    101    subagent_type=general-purpose
    102    prompt=<the worker prompt with context filled in>
    103    ```
    104 
    105 ### Step 5: Parse worker response
    106 
    107 The worker returns a structured result. Extract:
    108 - `STATUS`: one of `pass`, `progress`, or `no-progress`
    109 - `COMMIT_MSG`: a descriptive commit message
    110 
    111 ### Step 6: Handle by status
    112 
    113 **If STATUS is `pass` or `progress`:**
    114 
    115 **You MUST verify before committing.** Run:
    116 
    117 ```sh
    118 ./zig-out/bin/zig build all-zig0 -Dvalgrind |& grep -v Warning | head -10 ; echo "EXIT: $?"
    119 ```
    120 
    121 Check two things only: (1) EXIT is 0, (2) the ~10 lines of output
    122 contain no unexpected errors. If either check fails, do NOT commit —
    123 dispatch another worker to fix.
    124 
    125 Only if clean, commit:
    126 
    127 ```sh
    128 git add stage0/astgen.c stage0/astgen_test.zig
    129 git commit -m "<COMMIT_MSG from worker>
    130 
    131 Co-Authored-By: <whatever model is running this>"
    132 ```
    133 
    134 **If STATUS is `no-progress`:**
    135 
    136 Do NOT commit. The worker should have reverted the test file (re-added
    137 SkipZigTest or re-commented the corpus entry). Verify with:
    138 
    139 ```sh
    140 git diff stage0/astgen_test.zig
    141 ```
    142 
    143 If there are leftover changes (the entry is still enabled), re-comment
    144 the corpus entry or re-add the SkipZigTest yourself. Then:
    145 
    146 ```sh
    147 git checkout -- stage0/astgen.c stage0/astgen_test.zig
    148 ```
    149 
    150 Log that this test was skipped due to no progress and continue.
    151 
    152 ### Step 7: Repeat
    153 
    154 Go back to Step 1. **Never stop early** — continue until all
    155 `SkipZigTest` lines are gone AND all corpus entries are uncommented.
    156 
    157 ## Final Check
    158 
    159 When no disabled tests remain, run:
    160 
    161     ./zig-out/bin/zig build all-zig0 -Dvalgrind
    162 
    163 If that fails, go back to Phase 0 (treat it as a leftover).