ABC refactoring policies

Bullet-form one-pager for converting raw C into ABC idioms. Each section states the goal it serves, then the concrete moves. References the canonical docs — read them for full coverage:

Slice / buffer primitives

Goal: express every read and write as a typed slice/buffer op so data consumption is tracked and no pointer ever escapes into arithmetic.

BASS scratch — a_carve and friends

Goal: take per-call scratch from the BASS arena so it dies at the call()/try() boundary, never leaking via heap or a fixed stack buffer. Prefer BASS over heap u8bAllocate or fixed a_pad() for scratch.

Rules (PRO.h §"BASS-implicit arena macros"):

Paths

Goal: keep paths as owned, NUL-terminated buffers built with the PATH helpers, never a hand-assembled char[N].

Hashes / hashlets

Goal: carry SHAs in the typed records and accept any 6–40 hex hashlet prefix, never a raw byte array plus a manual length.

Zero-init

Goal: zero structs with the typed helpers so intent is explicit and never a hand-rolled memset.

Don't copy if you can pass the slice

Goal: when a callee only reads bytes, change its signature to take a slice and pass it directly, killing the copy-into-scratch dance.

Never ever do manual parsing in C

Goal: route all parsing through a ragel machine; hand-written byte scanners are forbidden.

Never ever do manual parsing in C Never ever do manual parsing in C Never ever do manual parsing in C Never ever do manual parsing in C Use ragel parsers for that

Resource lifecycle (CLAUDE.md §5)

Goal: allocate, map, and open at the top of the call chain; worker functions borrow resources and never own them.

    static ok64 xxxcli_inner(cli *c) { /* call(...)/done; throughout */ }

    ok64 xxxcli() {
        sane(1);
        cli c = {};
        call(PATHu8bAlloc, c.repo);
        try(xxxcli_inner, &c);
        PATHu8bFree(c.repo);
        done;
    }

PRO.h flow (CLAUDE.md §1, §16)

Goal: drive control flow and error propagation through the sane()/call()/try()/done cycle, confined to .c files.

Naming (CLAUDE.md §2)

Goal: names follow MOD typ8 VerbStuff, record types end in their bit width, and error codes are RON60-encoded.

When refactoring (workflow)

Goal: reuse before you add — check the INDEX.md files first, fix bugs repro-first, and keep the indexes current.