Starshine pass implementation

From jtenner/starshine-mb · View interactive version

Starshine pass implementation is an AI agent skill from the GitHub repository jtenner/starshine-mb. Implement, port, or sign off Starshine optimizer passes with the repo-standard TDD, registry, Binaryen semantic parity, performance, validity, and documentation workflow. Use when working on pass creation, pass porting, pass parity, pass fuzz compare failures, optimizer registry wiring, preset chang

How to use this skill

Skill file

Starshine Pass Implementation

Use this skill for optimizer pass creation, IR2 pass ports, pass parity fixes, registry/preset wiring, and pass signoff reports.

This skill is the detailed workflow referenced by AGENTS.md for pass work. Treat it as the pass-specific extension of the repo-wide rules, not as a replacement for them.

Source of Truth

Read the relevant sources before substantial pass work:

Non-Negotiables

Implementation Workflow

  1. Frame the pass.
  1. Classify the execution shape.
  1. Write tests first.
  1. Implement through shared helpers.
  1. Wire all public surfaces.
  1. Handle mismatches and gaps deliberately.

Signoff Ladder

Run Moon commands serially because _build/.moon-lock is shared.

Focused pass signoff

Use during the implementation loop:

  1. moon test src/passes
  2. moon test src/cmd when CLI, registry, flags, or pass dispatch changed
  3. Focused replay for saved repros or reduced cases
  4. Any package-specific Moon test touched by the change

Standard pass signoff

Use during implementation and before ordinary commit-sized parity slices:

  1. moon info
  2. moon fmt
  3. moon test
  4. moon build --target native --release src/cmd
  5. Run the required pass-fuzz signoff matrix below.

Compare-pass generates GenValid inputs by default. Add --wasm-smith only for the separate external-generator lane. Compare-pass has no persistent input, oracle, or semantic-result cache. Each new run executes generation and comparison afresh; do not pass the retired --cache-dir or --no-cache flags. The harness cleans each case's consumed inputs, successful reports and temporary outputs. Keep failure bundles and all observed semantic differences, including Binaryen-only differences, even when the structural mismatch artifact cap is zero. Only interrupted runs retain pending inputs for --resume; finalized cutoff runs discard unused inputs.

Required pass-fuzz signoff matrix

A proper pass signoff must run and report these four separate lanes unless the user explicitly approves a smaller replacement for that pass:

  1. Regular GenValid lane: 100000 requested cases, seed 0x5eed, no --gen-valid-profile.

```sh

bun scripts/pass-fuzz-compare.ts --count 100000 --seed 0x5eed --pass <canonical-name> --out-dir .tmp/pass-fuzz-<name>-genvalid-100000 --jobs auto --max-subprocesses 8 --max-mismatch-artifacts 20 --starshine-bin _build/native/release/build/cmd/cmd.exe --max-failures 2000 --keep-going-after-command-failures

```

  1. Explicit wasm-smith lane: 10000 requested cases, seed 0x5eed, with --wasm-smith.

```sh

bun scripts/pass-fuzz-compare.ts --wasm-smith --count 10000 --seed 0x5eed --pass <canonical-name> --out-dir .tmp/pass-fuzz-<name>-wasm-smith-10000 --jobs auto --max-subprocesses 8 --max-mismatch-artifacts 20 --starshine-bin _build/native/release/build/cmd/cmd.exe --max-failures 2000 --keep-going-after-command-failures

```

  1. Specific pass GenValid profile lane: 10000 requested cases, seed 0x5eed, with the pass-owned profile that generates random examples expected to be optimized by this pass.

```sh

bun scripts/pass-fuzz-compare.ts --count 10000 --seed 0x5eed --pass <canonical-name> --gen-valid-profile <pass-specific-profile> --out-dir .tmp/pass-fuzz-<name>-genvalid-<pass-specific-profile>-10000 --jobs auto --max-subprocesses 8 --max-mismatch-artifacts 20 --starshine-bin _build/native/release/build/cmd/cmd.exe --max-failures 2000 --keep-going-after-command-failures

```

  1. Random all-profiles GenValid lane: 10000 requested cases, seed 0x5555, with the random all-profiles composite profile.

```sh

bun scripts/pass-fuzz-compare.ts --count 10000 --seed 0x5555 --pass <canonical-name> --gen-valid-profile <random-all-profiles-profile> --out-dir .tmp/pass-fuzz-<name>-genvalid-all-profiles-10000 --jobs auto --max-subprocesses 8 --max-mismatch-artifacts 20 --starshine-bin _build/native/release/build/cmd/cmd.exe --max-failures 2000 --keep-going-after-command-failures

```

Report the four lanes separately. Include requested count, compared count, normalized matches, cleanup-normalized matches, raw mismatches, validation/generator/property failures, command-failure classes, profile name, and selected subprofile counts when the manifest has selected_profile.

Final pass closeout signoff

Use before declaring a pass closed, audit-complete, or behavior-parity complete. This is stronger than ordinary focused signoff:

  1. moon info
  2. moon fmt
  3. focused pass tests, e.g. moon test --package jtenner/starshine/passes --file <pass>_test.mbt
  4. moon test src/passes
  5. moon test
  6. moon build --target native --release src/cmd
  7. Run the full required pass-fuzz signoff matrix: 100000 regular GenValid at seed 0x5eed, 10000 explicit --wasm-smith at seed 0x5eed, 10000 pass-specific GenValid profile at seed 0x5eed, and 10000 random all-profiles GenValid at seed 0x5555.

Final closeout must use the full four-lane matrix unless the user explicitly approves a smaller run for that specific closeout.

Pass-specific generator fuzz lanes

Every new pass must add a GenValid profile that generates random examples expected to be optimized by that pass. The profile should produce meaningful trigger shapes, not merely valid modules that the pass usually leaves unchanged. It may be a singleton profile or a pass aggregate/composite profile, but the required signoff matrix needs one stable profile name that agents can pass as --gen-valid-profile <pass-specific-profile>.

Existing passes should add or refresh their pass-specific profile when a parity slice exposes an important shape family that ordinary GenValid under-samples. If the pass has a composite/aggregate profile documented in docs/wiki/binaryen/passes/<pass>/fuzzing.md, use that aggregate for the required pass-specific lane; keep singleton profiles for targeted reproduction, feature-floor narrowing, and development probes.

Pass-specific profile requirements:

Current dedicated pass-profile examples:

Report dedicated-profile lanes separately from the general compare lane: requested profile, selected subprofile counts when the manifest has selected_profile, requested count, compared count, normalized matches, cleanup-normalized matches, raw mismatches, command failures, and any profile-specific feature-floor or generation failures.

For DAE / dae-optimizing generated cleanup-debris lanes, add the documented compare normalizer so generated dropped-constant debris does not consume the mismatch budget:

bun scripts/pass-fuzz-compare.ts --count 10000 --seed 0x5eed --pass dae-optimizing --normalize drop-consts --normalize unreachable-control-debris --out-dir .tmp/pass-fuzz-dae-optimizing --jobs auto --max-subprocesses 8 --max-mismatch-artifacts 20 --starshine-bin _build/native/release/build/cmd/cmd.exe

Report exact normalizedMatchCount, cleanupNormalizedMatchCount, remaining mismatchCount, and command-failure classes separately.

Required result:

Performance and artifact signoff

Add when the pass affects hot paths, a preset, or a known artifact:

  1. Record pass-local Starshine and Binaryen timings where the harness reports them.
  2. Treat pass-local performance as acceptable when Starshine is at least 50% as fast as Binaryen (starshine_time <= 2 * binaryen_time), unless the user sets a stricter target for the pass.
  3. Attribute aggregate whole-command wall-time gaps to the top-level [WALL]001 backlog slice unless the root cause is clearly inside the pass implementation.
  4. Compare the relevant artifact, ordered prefix, or preset run when the pass participates in a documented optimize path; prefer semantic/canonical equality over raw wasm/text equality unless raw bytes are explicitly in scope.
  5. Ask before running long self-optimize commands, especially:
bun scripts/self-optimize-compare.ts tests/node/dist/starshine-debug-wasi.wasm --optimize

Preset signoff

Use when changing optimize, shrink, or pass order:

  1. Prove each directly touched pass under its own --pass <name> run first.
  2. Add tests that lock the new preset expansion or ordering.
  3. Compare the documented artifact or ordered-prefix path that motivated the preset change.
  4. Document repeated cleanup slots; do not collapse repeated Binaryen slots unless the divergence is intentional and recorded.

Commit-ready signoff

Use before committing pass work:

  1. Update relevant docs.
  2. Prune completed pass items from agent-todo.md; keep active blockers visible.
  3. Prefer bun validate before commit when the change needs repository-wide confidence.
  4. Use bun validate readme-api-sync for README/API drift.
  5. Use bun validate full --profile ci --target wasm-gc for the local full gate when requested or warranted.
  6. Forward-moving test or expectation updates do not require a test run unless the intent is to fix related behavior.
  7. Positive behavior changes may be committed even if they temporarily leave some tests failing, as long as the commit records the progress and failure state.
  8. Review the staged diff, including .mbti changes.
  9. Commit with a <kind>: <title> title and a detailed body that includes changed files plus reasons; split worktree changes into separate commits by top-level unit of change.

Signoff Report Template

When reporting pass signoff, include:

Done Definition

A pass is done only when:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.