Files
Drew T 827295e241 tools+docs(phase-33.5): task 13.5 — the tools audit + the two dictionaries: tools/tool_census.py (two agreeing enumerations of 327 tool files; docstring/SETUP row/consumers/class derived from the tree; the authored half in config/tool_dictionary.tsv — phase · portability · the NEED each tool answers · what · adapts · verdict — with coverage asserted both ways) → docs/tool-index.md (need-keyed, KEEP-GEN, Reference-index row, wiki + how-to pointers), the kit's tools/MANIFEST.md regenerated (header states live 293 + superseded 28 = 321 rows), and the two verbatim corpora in-tree (Drew, confirmed S91): decomp-architect/corpus/tools/<phase>/ (302 copies + 28 superseded pointers + INDEX) and corpus/cookbook/ (the cookbook, its symptom index, the codegen map, a front page stating what transfers per compiler) — sha1-equal to their sources by tool_census --check in tools-health, regenerated by make kit-corpus; kit_lint exempts the corpus dirs (verbatim evidence) but syntax-checks them; G66 (consult the tool dictionary first) + G67 (translate an inherited idiom through its pass) + two memory seeds (34 at install); SETUP Step 6 installs docs/knowledge-corpus.md and checks the manifest against its own stated total; the ops-setup dictionary rows; the intake's Phase 7 cites G66/G67 and Phase 10 + Part C name the raw-cast → declared-symbol step; templates/layout-contract.md (the five-tool probe, a draft for the split). The review under Drew's criterion: 93 no-consumer tools (one Opus agent's draft, verified: 0 defects, every successor live, 0 live consumers, 0 collisions; four one-off verdicts overturned to STILL-NEEDED) → 34 retired by git mv to tools/sunset/ (28 superseded, 6 one-offs; README review table; SETUP rows moved; Archive-index group). Run 4 (fresh throwaway, the final kit): stopped on my Step-6 check (321 vs the live 293) → both sides derived → resumed → PASS 10/10, manifest 56 == 56, 4 commits, guardrails held (the one foreign path was the timeline regenerated by the detached tools-health). tools-health OK; doc_links --strict rc 0; audit_public OK over 6,842 paths; the purge probe PASSED (Phase 34's gate open). decision-log "P33.5 S91" + accelerators "P33.5 S91" banked; log + checkpoint (NEXT = task 14, xHigh, fresh session)
2026-09-07 22:09:15 -06:00

115 lines
7.6 KiB
Python

#!/usr/bin/env python3
"""tools/t5_distill_args.py — build the R16 distill slate for a Claude wave (P31 S63 T5).
Usage: t5_distill_args.py --wave .run/t5a --wfdir <dir> [--wave .run/t5b --wfdir <dir> ...]
[--label 'P31 S63'] [--all-arms] [--out <path>]
--wave/--wfdir may be repeated and are paired POSITIONALLY (the Nth wave with the Nth wfdir), so one
distill run can cover several waves; the slates are concatenated and de-duplicated by (binary, fn).
Only BYTE-PROVEN transcripts are distilled (the distiller's contract: "the whole-binary byte-gate
ACCEPTED the final draft, so the final body is ground truth"), so the slate = the wave's banked set
from `<wave>/judge.json`, joined to the drafting agents' transcripts via the workflow's
`journal.jsonl` (result rows carry fn/arm/note; the transcript is `agent-<agentId>.jsonl`).
By default only the arm that BANKED each fn is distilled (--all-arms keeps every arm's attempt).
Coverage is asserted (R32): a banked fn with no transcript is reported and counted, never skipped
silently. Writes <wave>/distill_args.json for
Workflow(scriptPath=tools/workflows/claude_wave_distill.js, args=<that file's content>)."""
import argparse, json, os, sys
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__))); os.chdir(REPO)
def main():
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument('--wave', required=True, action='append',
help='wave dir; repeatable, paired positionally with --wfdir')
ap.add_argument('--wfdir', required=True, action='append',
help="the drafting run's transcript dir (holds journal.jsonl + agent-*.jsonl); repeatable")
ap.add_argument('--label', default='', help="provenance string for the cookbook header, e.g. 'P31 S63 t5a'")
ap.add_argument('--all-arms', action='store_true')
ap.add_argument('--with-unbanked', action='store_true',
help="ALSO consider drafts that did NOT bank. The richest idiom notes come from "
"the hardest functions, which are the least likely to bank (cookbook §52: a "
"model that FAILS to crack a wall still distills the idiom that cracks its "
"siblings). Each such row carries banked=False so the distilling agent knows "
"the lever is UNPROVEN by the byte gate (R14/G3).")
ap.add_argument('--novel-only', action='store_true',
help="select only transcripts whose agent NOTE carries a novelty signal (says the "
"cookbook lacks the lever, or names a lever/negative result). The t5a run measured "
"the base rate: 34 distilled -> 16 trivial, 5 novelty claims -> 1 ADDENDUM, so "
"distilling every banked transcript spends ~30x the tokens for the same book. "
"The FULL denominator is always printed (R41); this filter is reported, not hidden.")
ap.add_argument('--out', default='')
a = ap.parse_args()
if len(a.wave) != len(a.wfdir):
sys.exit('REFUSED: %d --wave but %d --wfdir; they pair positionally' % (len(a.wave), len(a.wfdir)))
out, missing, seen, tot_banked, tot_union = [], [], set(), 0, 0
for wave, wfdir in zip(a.wave, a.wfdir):
jp = os.path.join(wave, 'judge.json')
if not os.path.exists(jp):
print('SKIP %s: no judge.json (wave not gated yet)' % wave); continue
jd = json.load(open(jp))
banked_by_arm = {arm: set(v.get('banked', [])) for arm, v in jd.get('arms', {}).items()}
banked = set().union(*banked_by_arm.values()) if banked_by_arm else set()
union = set(jd.get('union', {}).get('banked', []))
picked = jd.get('union', {}).get('picked', {})
tot_banked += len(banked); tot_union += len(union)
T = {t['name']: t for t in json.load(open(os.path.join(wave, 'targets.json')))}
jl = os.path.join(wfdir, 'journal.jsonl')
if not os.path.exists(jl):
sys.exit('no journal.jsonl in %s' % wfdir)
tr = {}
for line in open(jl):
if '"result"' not in line: continue
r = json.loads(line); res = r.get('result') or {}
if isinstance(res, dict) and res.get('fn'):
tr[(res['fn'], res.get('arm'))] = (os.path.join(wfdir, 'agent-%s.jsonl' % r['agentId']), res.get('note', ''))
for fn in sorted(banked):
arms = sorted(banked_by_arm) if a.all_arms else [picked.get(fn) or next(x for x in banked_by_arm if fn in banked_by_arm[x])]
for arm in arms:
if fn not in banked_by_arm.get(arm, ()): continue
key = (T.get(fn, {}).get('binary', '?'), fn, arm)
if key in seen: continue # the same fn can be drawn by two waves (R48: key by binary too)
seen.add(key)
hit = tr.get((fn, arm))
if not hit or not os.path.exists(hit[0]):
missing.append('%s/%s/%s' % (os.path.basename(wave), arm, fn)); continue
out.append({'fn': fn, 'arm': arm, 'transcript': hit[0], 'note': hit[1],
'banked': True})
if a.with_unbanked: # every result the journal holds that the gate refused
for (fn, arm), (path, note) in sorted(tr.items()):
if fn in banked or not os.path.exists(path):
continue
key = (T.get(fn, {}).get('binary', '?'), fn, arm)
if key in seen:
continue
seen.add(key)
out.append({'fn': fn, 'arm': arm, 'transcript': path, 'note': note,
'banked': False})
# 'no cookbook lever' was REMOVED (P31 S65): it matched "…MATCH on first compile, no cookbook
# lever needed" — a note reporting a TRIVIAL function — and that false positive was the ONLY
# selection out of 24 in the t5s run, while three genuine multi-lever notes went unpicked.
# A selector whose single hit is the one note that says "nothing to learn here" is inverted.
NOVEL = ('not in the cookbook', 'not in cookbook', 'cookbook did not have', "cookbook does not",
'NEW IDIOM', 'NEW:', 'NEW fact', 'the cookbook does not cover', 'does not yet cover',
'negative result', 'addendum', 'Cookbook-worthy', 'unlocked it',
'cookbook lacks', 'new lever', 'levers not in', 'lever the cookbook',
'worth banking', 'not in the cookbook and')
# A note that explicitly says no lever was needed is NEVER novel, whatever else it matched.
NOT_NOVEL = ('no cookbook lever needed', 'no cookbook lookup needed', 'no cookbook lever was needed')
n_all = len(out)
if a.novel_only:
out = [r for r in out
if any(k.lower() in (r['note'] or '').lower() for k in NOVEL)
and not any(k in (r['note'] or '').lower() for k in NOT_NOVEL)]
print('waves %d; banked %d (union-gated %d); transcripts found %d; selected %d%s; label %r'
% (len(a.wave), tot_banked, tot_union, n_all, len(out),
' by novelty signal (%d NOT distilled — no signal in their note)' % (n_all - len(out)) if a.novel_only else '',
a.label))
if missing:
print('NO TRANSCRIPT for %d banked draft(s) — NOT distilled (R32, reported not skipped): %s'
% (len(missing), ' '.join(missing[:20])))
p = a.out or os.path.join(a.wave[0], 'distill_args.json')
json.dump({'targets': out, 'label': a.label or os.path.basename(a.wave[0].rstrip('/'))}, open(p, 'w'), indent=1)
print('wrote %s' % p)
if __name__ == '__main__':
main()