Skip to main content

max / quasi

Give probe round 2 a sampling frame and a harness Round 1 probed 5.1% of the population and found a new blocking class every 1.4 probes without the rate flattening, so the form is not closed and a second round has to be both bigger and aimed at the holes round 1 left. Neither the draw nor the round had anything written down. probe-sample.py is the frame: seeded, reproducible, reading the population from population.py so the two cannot drift. Four strata, each one a hole section 7 of the record names by hand. population.py gains a `lines` field to stratify on. Additive, so the count is still 514 and --selftest still passes 17 of 17. scripts/workflows/probe-round.js runs the round: sample, then a probe per batch with the four-part bar applied to a probe's new classes as it returns, and two residue agents for R4(b) and the grammar's over-admissions. Read-only, and it files nothing. Plan: wiki quasi-phase-1-plan. GoingsOn 87a32c44, e951ab96.
Co-Authored-By
Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session
https://claude.ai/code/session_01MptwXZ8k65v19rFmdGAyki
Author: Max Johnson <me@maxj.phd> · 2026-09-03 16:05 UTC
Signed with PGP, not checked
Commit: 6341d740af4f1b989935d6b251260eda5e76be32
Parent: 3aab432
3 files changed, +680 insertions, -2 deletions
@@ -286,6 +286,25 @@
286 286 return -1
287 287
288 288
289 + def match_brace(src: str, start: int) -> int:
290 + """Index just past the `}` closing the `{` at `start`, or -1.
291 +
292 + `src` must already be through `blank_noncode`, so a brace inside a string
293 + or a comment cannot unbalance the count.
294 + """
295 + depth = 0
296 + i = start
297 + while i < len(src):
298 + if src[i] == "{":
299 + depth += 1
300 + elif src[i] == "}":
301 + depth -= 1
302 + if depth == 0:
303 + return i + 1
304 + i += 1
305 + return -1
306 +
307 +
289 308 def shapes_in(path: Path) -> list[dict]:
290 309 raw = path.read_text(encoding="utf-8", errors="replace")
291 310 src = strip_cfg_test(blank_noncode(raw))
@@ -342,9 +361,15 @@
342 361 # Reached by path (`quasi_router::Node`) rather than by import.
343 362 if "quasi_router" not in ret and "quasi_webview" not in ret:
344 363 continue
364 + end = match_brace(src, j)
365 + start_line = src.count("\n", 0, m.start()) + 1
366 + # Body length in lines, signature included. Used to stratify a probe
367 + # sample (`scripts/probe-sample.py`); it does not enter the predicate,
368 + # so the count is unaffected.
369 + lines = (src.count("\n", m.start(), end) + 1) if end > 0 else 1
345 370 found.append(
346 - {"file": str(path), "line": src.count("\n", 0, m.start()) + 1,
347 - "fn": name, "returns": " ".join(ret.split())}
371 + {"file": str(path), "line": start_line,
372 + "fn": name, "returns": " ".join(ret.split()), "lines": lines}
348 373 )
349 374 return found
350 375
@@ -1,0 +1,239 @@
1 + #!/usr/bin/env python3
2 + """Draw a stratified, reproducible probe sample from the shape population.
3 +
4 + A probe is a full re-authoring of a real shape function into the `declare!`
5 + form, checked production by production against the grammar in wiki
6 + `quasi-declare-form`. Round 1 ran 15 probes over 26 functions (5.1% of 514) and
7 + found one new blocking class per 1.4 probes without the rate flattening, which
8 + is why the form is not closed. Round 2 has to be big enough that coming back
9 + clean means something, and aimed at the holes round 1 left rather than at
10 + another uniform draw.
11 +
12 + This script is the sampling frame, written down so a round can be re-run and
13 + argued with. It reads the population from `population.py`, so the two cannot
14 + drift.
15 +
16 + THE STRATA, each one a hole section 7 of the record names by hand:
17 +
18 + conceded The three goingson forms conceded to the `Field::refilled`
19 + deferral and never re-authored. The concession covers 4 sites
20 + while the closure weight in those functions is far larger, so the
21 + concession itself is untested. Always drawn, never sampled.
22 + af-cold audiofiles outside the five files round 1 touched. That tree
23 + carries 43 of the 66 carried containers, 89 of the owned
24 + parameters and 22 of the 25 `Type::Variant.method()` sites, so it
25 + is where the twelve amendments have the most to prove.
26 + fallible Shapes returning `Result<_, RouteError>`. Amendment 1 (`take`) is
27 + the highest-site-count gap in the record: 54 fallible shapes, 106
28 + `?`, 13 of them mixing converted and bare reads. Its failure mode
29 + is a 404 rendered as a 500, so it is the amendment worth the most
30 + evidence.
31 + rest Everything else, drawn uniformly, so the round is not purely
32 + adversarial and a clean result can speak for the population
33 + rather than only for its hard corners.
34 +
35 + Round 1's targets are excluded by (file, function) rather than by line, since
36 + lines have moved. `project_content.rs` is excluded whole: its probe covered a
37 + five-function cluster the record does not name.
38 +
39 + python3 scripts/probe-sample.py # the default round-2 draw
40 + python3 scripts/probe-sample.py --json # machine-readable batches
41 + python3 scripts/probe-sample.py --seed 8 --probes 20
42 + python3 scripts/probe-sample.py --show-frame # strata sizes, no draw
43 +
44 + The seed is printed with every draw. Record it on the task: it is what makes a
45 + round reproducible, and a round nobody can re-run is not evidence.
46 + """
47 +
48 + from __future__ import annotations
49 +
50 + import argparse
51 + import importlib.util
52 + import json
53 + import random
54 + import sys
55 + from pathlib import Path
56 +
57 + HERE = Path(__file__).resolve().parent
58 +
59 +
60 + def load_population():
61 + """Import `population.py` as a module, so the predicate has one home."""
62 + spec = importlib.util.spec_from_file_location("population", HERE / "population.py")
63 + mod = importlib.util.module_from_spec(spec)
64 + spec.loader.exec_module(mod)
65 + return mod
66 +
67 +
68 + # Round 1, from the evidence table of wiki `quasi-declare-form` section 7.
69 + # By path and function name, never by line: the lines have moved since
70 + # 2026-09-02, and a stem alone would exclude a same-named function in another
71 + # tree that round 1 never touched.
72 + M = "MNW/server/src/quasi"
73 + G = "Apps/goingson/src-tauri/src/quasi"
74 + A = "Apps/audiofiles/crates/audiofiles-browser/src/quasi"
75 +
76 + PROBED = {
77 + (f"{G}/tasks.rs", "screen"),
78 + (f"{G}/data.rs", "confirm_form"),
79 + (f"{G}/data.rs", "import_form"),
80 + (f"{G}/settings.rs", "setting"),
81 + (f"{G}/settings.rs", "screen"),
82 + (f"{G}/sharing.rs", "invitation_rows"),
83 + (f"{A}/importing.rs", "flow"),
84 + (f"{A}/export.rs", "naming_field"),
85 + (f"{A}/export.rs", "setting_route"),
86 + (f"{A}/export.rs", "picker"),
87 + (f"{A}/sync.rs", "screen"),
88 + (f"{A}/files.rs", "row"),
89 + (f"{M}/git_nav.rs", "region"),
90 + (f"{M}/git_nav.rs", "breadcrumb"),
91 + (f"{M}/project.rs", "screen"),
92 + (f"{M}/feeds.rs", "row"),
93 + (f"{M}/git_commit.rs", "body_field"),
94 + (f"{M}/git_commit.rs", "signature"),
95 + (f"{M}/auth_pages.rs", "forgot_password"),
96 + (f"{M}/user.rs", "screen"),
97 + }
98 +
99 + # Probe 9 covered an unnamed five-function cluster in this file.
100 + PROBED_FILES = {"MNW/server/src/quasi/project_content.rs"}
101 +
102 + # Read in round 1 and conceded to the `Field::refilled` deferral without being
103 + # re-authored. The concession is what round 2 has to test, so these are drawn
104 + # rather than sampled.
105 + CONCEDED = [
106 + (f"{G}/events.rs", "form_fields"),
107 + (f"{G}/settings/email.rs", "fields"),
108 + (f"{G}/tasks.rs", "edit_fields"),
109 + ]
110 +
111 + AF_TREE = A
112 + # The five audiofiles files round 1 reached.
113 + AF_WARM = {"sync.rs", "files.rs", "export.rs", "importing.rs", "toolbar.rs"}
114 +
115 + # How the draw is split, after the conceded three. Weighted at the holes.
116 + WEIGHTS = {"af-cold": 0.30, "fallible": 0.30, "rest": 0.40}
117 +
118 +
119 + def stratify(shapes: list[dict]) -> dict[str, list[dict]]:
120 + conceded_keys = set(CONCEDED)
121 + strata: dict[str, list[dict]] = {"conceded": [], "af-cold": [], "fallible": [], "rest": []}
122 + for s in shapes:
123 + key = (s["file"], s["fn"])
124 + stem = Path(s["file"]).name
125 + if key in conceded_keys:
126 + strata["conceded"].append(s)
127 + continue
128 + if s["file"] in PROBED_FILES or key in PROBED:
129 + continue # round 1 covered it
130 + if s["file"].startswith(AF_TREE) and stem not in AF_WARM:
131 + strata["af-cold"].append(s)
132 + elif "Result" in s["returns"]:
133 + strata["fallible"].append(s)
134 + else:
135 + strata["rest"].append(s)
136 + return strata
137 +
138 +
139 + def draw(strata: dict[str, list[dict]], want: int, rng: random.Random) -> list[dict]:
140 + """Draw `want` shapes beyond the conceded three, per WEIGHTS."""
141 + picked = list(strata["conceded"])
142 + remaining = max(0, want - len(picked))
143 + for name, weight in WEIGHTS.items():
144 + pool = strata[name]
145 + n = min(round(remaining * weight), len(pool))
146 + picked.extend(rng.sample(pool, n))
147 + # Weight rounding can leave the draw a shape or two short; top up from the
148 + # largest untouched pool so the requested size is the size delivered.
149 + chosen = {(s["file"], s["fn"]) for s in picked}
150 + if len(picked) < want:
151 + spare = [s for name in WEIGHTS for s in strata[name]
152 + if (s["file"], s["fn"]) not in chosen]
153 + rng.shuffle(spare)
154 + picked.extend(spare[: want - len(picked)])
155 + return picked
156 +
157 +
158 + def batch(picked: list[dict], per: int) -> list[list[dict]]:
159 + """Group into probes, keeping same-file shapes together where possible.
160 +
161 + A probe that re-authors two functions from one file re-reads one context
162 + rather than two, and round 1's clean probes 3 and 4 were both clusters.
163 + """
164 + by_file: dict[str, list[dict]] = {}
165 + for s in picked:
166 + by_file.setdefault(s["file"], []).append(s)
167 + ordered = [s for _, group in sorted(by_file.items()) for s in group]
168 + return [ordered[i : i + per] for i in range(0, len(ordered), per)]
169 +
170 +
171 + def main() -> int:
172 + ap = argparse.ArgumentParser(
173 + description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
174 + )
175 + ap.add_argument("--root", default=str(Path.home() / "Code"))
176 + ap.add_argument("--seed", type=int, default=2, help="the round's seed; printed with the draw")
177 + ap.add_argument("--probes", type=int, default=14, help="number of probe batches")
178 + ap.add_argument("--per-probe", type=int, default=3, help="shapes per batch")
179 + ap.add_argument("--json", action="store_true")
180 + ap.add_argument("--show-frame", action="store_true", help="strata sizes only, no draw")
181 + args = ap.parse_args()
182 +
183 + pop = load_population()
184 + root = Path(args.root)
185 + shapes: list[dict] = []
186 + for rel in pop.SHAPE_DIRS:
187 + d = root / rel
188 + if not d.is_dir():
189 + print(f"missing: {rel}", file=sys.stderr)
190 + return 1
191 + for f in sorted(d.rglob("*.rs")):
192 + parts = f.relative_to(root).parts
193 + if f.name in ("tests.rs", "parity.rs") or "tests" in parts:
194 + continue
195 + for h in pop.shapes_in(f):
196 + h["file"] = str(Path(h["file"]).relative_to(root))
197 + shapes.append(h)
198 +
199 + strata = stratify(shapes)
200 + if args.show_frame:
201 + print(f"population {len(shapes)}")
202 + for name, pool in strata.items():
203 + print(f"{len(pool):5} {name}")
204 + print(f"{len(shapes) - sum(len(v) for v in strata.values()):5} excluded (round 1)")
205 + return 0
206 +
207 + want = args.probes * args.per_probe
208 + picked = draw(strata, want, random.Random(args.seed))
209 + batches = batch(picked, args.per_probe)
210 + coverage = 100.0 * len(picked) / len(shapes)
211 +
212 + if args.json:
213 + json.dump(
214 + {
215 + "seed": args.seed,
216 + "population": len(shapes),
217 + "sampled": len(picked),
218 + "coverage_pct": round(coverage, 1),
219 + "batches": [
220 + {"probe": i + 1, "targets": b} for i, b in enumerate(batches)
221 + ],
222 + },
223 + sys.stdout,
224 + indent=1,
225 + )
226 + print()
227 + return 0
228 +
229 + print(f"seed {args.seed}: {len(picked)} shapes of {len(shapes)} ({coverage:.1f}%), "
230 + f"{len(batches)} probes")
231 + for i, b in enumerate(batches, 1):
232 + print(f"\nprobe {i}")
233 + for s in b:
234 + print(f" {s['file']}:{s['line']} {s['fn']} -> {s['returns']} ({s['lines']} lines)")
235 + return 0
236 +
237 +
238 + if __name__ == "__main__":
239 + raise SystemExit(main())
@@ -1,0 +1,414 @@
1 + export const meta = {
2 + name: 'quasi-probe-round',
3 + description: 'Probe round against the amended declare! form: re-author sampled shapes, adjudicate every new failure class against the four-part bar',
4 + whenToUse: 'Phase 1 of the quasi declaration transition (GoingsOn 65d99281). Run when the form has been amended and the closure claim needs evidence. Read-only: it edits nothing and commits nothing.',
5 + phases: [
6 + { title: 'Sample', detail: 'draw the stratified batch list from probe-sample.py' },
7 + { title: 'Probe', detail: 'one agent per batch, each re-authoring its shapes in the amended form' },
8 + { title: 'Residue', detail: 'R4(b) reproduction and the grammar over-admission check' },
9 + { title: 'Adjudicate', detail: 'four-part bar applied to every class not already in the record' },
10 + { title: 'Synthesize', detail: 'verdict, coverage, and the hit-rate comparison against round 1' },
11 + ],
12 + }
13 +
14 + // ---------------------------------------------------------------------------
15 + // Round 1 is the thing this round is measured against: 15 probes over 26
16 + // functions (5.1% of 514), 4 clean, one new blocking class per 1.4 probes, and
17 + // the rate never flattened. A round that does not beat that coverage cannot
18 + // settle the closure claim however clean it comes back.
19 + // ---------------------------------------------------------------------------
20 + const ROUND_1 = { probes: 15, functions: 26, clean: 4, coverage: 5.1, classes_per_probe: 1 / 1.4 }
21 +
22 + const seed = (args && args.seed) || 2
23 + const probes = (args && args.probes) || 15
24 + const perProbe = (args && args.perProbe) || 3
25 +
26 + const READING = `
27 + Read these before writing a single production. They are the contract:
28 +
29 + - \`~/Wiki/quasi-declare-form.md\` -- the grammar (EBNF), the twelve amendments
30 + each with its measurement, the eleven static rules, three worked examples,
31 + the deferred table in section 6, and the four-part bar in section 8. This is
32 + the form you are probing. It is long; read sections 4, 6 and 8 in full.
33 + - \`~/Wiki/construction-holds-the-invariant.md\` -- the companion.
34 + - \`~/Code/quasi/crates/quasi-router/src/screen.rs\` -- the constructors a
35 + declaration has to emit. A production that cannot name a real constructor is
36 + not a production.
37 +
38 + You are READ-ONLY. Do not edit, create or commit any file, in any repo. A probe
39 + is a re-authoring on paper, checked production by production. Its output is
40 + evidence, not a patch.
41 + `
42 +
43 + const PROBE_SCHEMA = {
44 + type: 'object',
45 + required: ['targets', 'verdict', 'classes'],
46 + properties: {
47 + targets: {
48 + type: 'array',
49 + items: {
50 + type: 'object',
51 + required: ['file', 'fn', 'reauthored'],
52 + properties: {
53 + file: { type: 'string' },
54 + fn: { type: 'string' },
55 + reauthored: {
56 + type: 'boolean',
57 + description: 'true only if EVERY construct in the function was expressible in the amended form',
58 + },
59 + declaration: {
60 + type: 'string',
61 + description: 'the declaration you wrote, verbatim; empty if it could not be written',
62 + },
63 + },
64 + },
65 + },
66 + verdict: {
67 + type: 'string',
68 + enum: ['clean', 'failed'],
69 + description: 'clean only if every target re-authored with no residue',
70 + },
71 + classes: {
72 + type: 'array',
73 + description: 'one entry per distinct construct the form could not say. Empty when clean.',
74 + items: {
75 + type: 'object',
76 + required: ['name', 'construct', 'site', 'in_record', 'remedy_available'],
77 + properties: {
78 + name: { type: 'string', description: 'short name for the class' },
79 + construct: { type: 'string', description: 'the Rust that could not be said' },
80 + site: { type: 'string', description: 'file:line of a real occurrence' },
81 + in_record: {
82 + type: 'boolean',
83 + description: 'true if this class is already one of the twelve amendments or on section 6 deferred table',
84 + },
85 + record_ref: { type: 'string', description: 'which amendment or deferred row, when in_record' },
86 + remedy_available: {
87 + type: 'boolean',
88 + description: 'true if outcome A applies -- the deferred table names a remedy that covers it',
89 + },
90 + effect: {
91 + type: 'string',
92 + description: 'what a user sees, or the compile error, or the status code that changes',
93 + },
94 + },
95 + },
96 + },
97 + },
98 + }
99 +
100 + const BAR_SCHEMA = {
101 + type: 'object',
102 + required: ['classes'],
103 + properties: {
104 + classes: {
105 + type: 'array',
106 + items: {
107 + type: 'object',
108 + required: ['name', 'site_count', 'count_command', 'outcome', 'reasoning'],
109 + properties: {
110 + name: { type: 'string' },
111 + site_count: { type: 'integer', description: 'measured across all three shape directories' },
112 + count_command: {
113 + type: 'string',
114 + description: 'the command that produced site_count, runnable as written, with tests.rs / parity.rs / inline #[cfg(test)] excluded and comments and string literals blanked',
115 + },
116 + alternative: { type: 'string', description: 'the named alternative, priced: signature change + call sites, or N new suppliers' },
117 + failing_screen: { type: 'string', description: 'file:line of a screen that currently fails, not a hypothetical' },
118 + cannot_be_used_for: { type: 'string', description: 'what the proposed production must not admit' },
119 + outcome: {
120 + type: 'string',
121 + enum: ['A-remedy', 'B-production', 'C-refuse'],
122 + description: 'A: the deferred table already covers it. B: it clears all four parts of the bar and the threshold. C: refuse it and rewrite the Rust.',
123 + },
124 + reasoning: { type: 'string' },
125 + },
126 + },
127 + },
128 + },
129 + }
130 +
131 + // --------------------------------------------------------------- Sample ----
132 + phase('Sample')
133 + const sample = await agent(
134 + `Run this, from \`~/Code/quasi\`, and return exactly what it prints:
135 +
136 + python3 scripts/probe-sample.py --seed ${seed} --probes ${probes} --per-probe ${perProbe} --json
137 +
138 + Run \`python3 scripts/population.py --selftest\` first and report its result in
139 + \`selftest\`; the draw is worthless if the predicate is broken. Do not edit
140 + anything. Return the parsed JSON, not a description of it.`,
141 + {
142 + label: `sample seed ${seed}`,
143 + phase: 'Sample',
144 + effort: 'low',
145 + schema: {
146 + type: 'object',
147 + required: ['seed', 'population', 'sampled', 'coverage_pct', 'selftest', 'batches'],
148 + properties: {
149 + seed: { type: 'integer' },
150 + population: { type: 'integer' },
151 + sampled: { type: 'integer' },
152 + coverage_pct: { type: 'number' },
153 + selftest: { type: 'string' },
154 + batches: {
155 + type: 'array',
156 + items: {
157 + type: 'object',
158 + required: ['probe', 'targets'],
159 + properties: {
160 + probe: { type: 'integer' },
161 + targets: {
162 + type: 'array',
163 + items: {
164 + type: 'object',
165 + properties: {
166 + file: { type: 'string' },
167 + line: { type: 'integer' },
168 + fn: { type: 'string' },
169 + returns: { type: 'string' },
170 + lines: { type: 'integer' },
171 + },
172 + },
173 + },
174 + },
175 + },
176 + },
177 + },
178 + },
179 + }
180 + )
181 +
182 + if (!sample || !sample.batches || !sample.batches.length) {
183 + log('Sampling returned nothing. Nothing to probe; check probe-sample.py by hand.')
184 + return { error: 'no sample', sample }
185 + }
186 +
187 + log(`seed ${sample.seed}: ${sample.sampled} of ${sample.population} shapes (${sample.coverage_pct}%), ${sample.batches.length} probes. Round 1 covered ${ROUND_1.coverage}%.`)
188 + if (sample.coverage_pct <= ROUND_1.coverage) {
189 + log(`WARNING: this round covers no more than round 1 did. A clean result at this coverage settles nothing.`)
190 + }
191 +
192 + // -------------------------------------------------------------- Residue ----
193 + // Two of the four conditions in section 8 that reopen the closure claim are not
194 + // probe findings at all. They get one agent each, started HERE so they run
195 + // alongside the probes rather than queueing behind them.
196 + const residuePromise = parallel([
197 + () => agent(
198 + `Reproduce or refute R4(b), the owned-payload double move.
199 + ${READING}
200 +
201 + R4(b) is the one residue in the record with NO site count. It was reported as a
202 + defect and never reproduced, and its failure mode is a compile error in generated
203 + code with no source line to point at -- the worst thing to discover 400 functions
204 + into the mass phase. Section 8 names "R4(b) reproduced" as one of the four things
205 + that reopen the closure claim.
206 +
207 + Construct the minimal case from the rule as written in section 4, decide whether
208 + the double move actually occurs, and if it does, measure its incidence across the
209 + three shape directories with a command you write down and run. If it does not
210 + occur, say what in the rule prevents it and what the original report probably saw.
211 + Read-only.`,
212 + { label: 'R4(b)', phase: 'Residue', effort: 'high', schema: {
213 + type: 'object',
214 + required: ['reproduced', 'evidence'],
215 + properties: {
216 + reproduced: { type: 'boolean' },
217 + incidence: { type: 'integer', description: 'measured site count when reproduced, -1 when not' },
218 + count_command: { type: 'string' },
219 + evidence: { type: 'string' },
220 + },
221 + } }
222 + ),
223 + () => agent(
224 + `Test what the grammar OVER-admits.
225 + ${READING}
226 +
227 + Section 7 lists this as untested against any implementation: \`node\`'s body accepts
228 + any emission so \`act "Delete" { region .. }\` parses; prepositions carry no meaning
229 + so \`field from H\`, \`field to H\` and \`field by H\` are one declaration; \`arg*\` has
230 + no arity rule so \`image cover "{title}"\` cannot tell \`src\` from \`alt\`; and 24
231 + grammar terminals are live function names in these directories (region, page,
232 + section, text, act, image, empty, form, list, table, row, column, stats, screen,
233 + across, include, read, require, unless, of, from, get, delete, leaving).
234 +
235 + Every case traced was said to be decidable on one token of lookahead. Check that
236 + claim properly: work the grammar by hand, find every place two productions share a
237 + prefix, and say which are decidable on one token, which need more, and which are
238 + genuinely ambiguous. For the 24 terminals, measure how many are actually called as
239 + functions inside a declaration body rather than merely defined, since that is what
240 + decides whether the collision bites.
241 +
242 + An ambiguity here is a finding about the form, not about the emitter. Read-only.`,
243 + { label: 'over-admission', phase: 'Residue', effort: 'high', schema: {
244 + type: 'object',
245 + required: ['ambiguities', 'verdict'],
246 + properties: {
247 + verdict: { type: 'string', enum: ['one-token-lookahead-holds', 'needs-more-lookahead', 'genuinely-ambiguous'] },
248 + ambiguities: {
249 + type: 'array',
250 + items: {
251 + type: 'object',
252 + required: ['productions', 'lookahead', 'note'],
253 + properties: {
254 + productions: { type: 'string' },
255 + lookahead: { type: 'string' },
256 + note: { type: 'string' },
257 + },
258 + },
259 + },
260 + terminal_collisions: { type: 'integer', description: 'of the 24, how many are called inside a declaration body' },
261 + },
262 + } }
263 + ),
264 + ])
265 +
266 + // ------------------------------------------------- Probe -> Adjudicate ----
267 + // Pipeline, not a barrier: a probe's new classes go to the bar the moment that
268 + // probe returns, while the other fourteen are still re-authoring. The
269 + // adjudicator is spawned only when a probe reports a class the record does not
270 + // already hold, so a clean-ish round costs almost nothing beyond the probes.
271 + const probed = await pipeline(
272 + sample.batches,
273 +
274 + (b) => agent(
275 + `You are probe ${b.probe} of a round-2 probe against the amended \`declare!\` form.
276 + ${READING}
277 +
278 + YOUR TARGETS -- re-author every one of them:
279 +
280 + ${b.targets.map((t) => ` ${t.file}:${t.line} fn ${t.fn} -> ${t.returns} (${t.lines} lines)`).join('\n')}
281 +
282 + HOW TO PROBE. Read the real function first. Then write the whole thing as a
283 + declaration in the amended form, production by production, checking each against
284 + the grammar in section 4 and against the constructor it has to emit in
285 + \`screen.rs\`. Do not skim and pronounce; a probe that did not write the
286 + declaration out is not a probe. Put what you wrote in \`declaration\`.
287 +
288 + WHAT COUNTS AS A FAILURE. Any construct in the function that the amended form
289 + cannot say. Before you call it a failure, check two things:
290 +
291 + 1. Is it already one of the twelve amendments? Those are specified but unprobed,
292 + so exercising one is the POINT of this round. Set \`in_record: true\` and
293 + \`record_ref\`, and say in \`effect\` whether the amendment as specified actually
294 + covers the site or falls short of it. An amendment that does not cover its own
295 + motivating case is the most valuable thing you can find.
296 + 2. Is it on the deferred table in section 6? Then the named remedy applies --
297 + a \`-> impl Display\` supplier, a \`-> Vec<T>\` payload supplier, a named
298 + predicate, a domain accessor. Set \`remedy_available: true\`. That is outcome
299 + A, the expected one, and it is not a failure of the form.
300 +
301 + A target re-authors (\`reauthored: true\`) when every construct in it is either
302 + expressible or covered by a stated remedy. \`verdict\` is \`clean\` only when all
303 + of your targets re-authored.
304 +
305 + Be exact and be honest. A false clean is worse here than a false failure: this
306 + round decides whether 289 more functions get re-authored against this form.`,
307 + { label: `probe ${b.probe}`, phase: 'Probe', schema: PROBE_SCHEMA }
308 + ),
309 +
310 + (r, b) => {
311 + if (!r) return null
312 + const fresh = (r.classes || []).filter((c) => !c.in_record && !c.remedy_available)
313 + if (!fresh.length) return { probe: b.probe, result: r, bar: null }
314 + return agent(
315 + `Apply section 8's four-part bar to each class below. They came out of probe
316 + ${b.probe} and none is in the record, so each one either earns a production, takes
317 + a remedy, or is refused.
318 + ${READING}
319 +
320 + THE CLASSES:
321 +
322 + ${fresh.map((c) => `- ${c.name}: ${c.construct}\n seen at ${c.site}; effect: ${c.effect || 'unstated'}`).join('\n')}
323 +
324 + For each one, all four parts, and no shortcuts:
325 +
326 + 1. A SITE COUNT for the whole class across all three shape directories, produced
327 + by a command you write down and actually run, with \`tests.rs\`, \`parity.rs\` and
328 + inline \`#[cfg(test)]\` excluded and comments and string literals blanked before
329 + matching. A count off \`Type::method(\` alone is NOT a count -- three of the four
330 + members this record had to rescue are reached by a chained builder or a field
331 + assignment. Put the command in \`count_command\`, runnable as written.
332 + 2. THE NAMED ALTERNATIVE, PRICED. Either the signature change and its call-site
333 + count, or the number of new supplier functions. "Move it upstream" with no
334 + number is not an alternative.
335 + 3. A FAILING SCREEN, by file and line. It must currently produce something a user
336 + sees that the declaration cannot produce, or force a compile error, or change a
337 + status code. Convenience is not a reason.
338 + 4. WHAT THE PRODUCTION CANNOT THEN BE USED FOR. A production admitting an
339 + expression, a block in argument position, a closure, or a \`Type { .. }\`
340 + aggregate is refused whatever its site count.
341 +
342 + THE THRESHOLD. Under 10 sites earns no production -- outcome A or C. Between 10
343 + and 30 it earns one only if part 2's alternative touches more call sites than the
344 + construct has, or part 3's failure is a status-code or data-loss failure rather
345 + than a rendering one. Over 30 it earns one.
346 +
347 + Default to refusing. The form already refuses \`impl Trait\` at 4 sites and
348 + \`Repeating\` at 7. You are read-only: measure and rule, change nothing.`,
349 + { label: `bar: probe ${b.probe}`, phase: 'Adjudicate', effort: 'high', schema: BAR_SCHEMA }
350 + ).then((bar) => ({ probe: b.probe, result: r, bar }))
351 + }
352 + )
353 +
354 + const residue = await residuePromise
355 +
356 + // ----------------------------------------------------------- Synthesize ----
357 + phase('Synthesize')
358 + const ok = probed.filter(Boolean)
359 + const results = ok.map((p) => p.result)
360 + const cleanProbes = results.filter((r) => r.verdict === 'clean').length
361 + const allClasses = results.flatMap((r) => r.classes || [])
362 + const newClasses = allClasses.filter((c) => !c.in_record && !c.remedy_available)
363 + const amendmentHits = allClasses.filter((c) => c.in_record)
364 + const rulings = ok.flatMap((p) => (p.bar && p.bar.classes) || [])
365 +
366 + // Dedupe by name: several probes hitting one class is one class, and the
367 + // hit-rate comparison against round 1 is meaningless if it is counted twice.
368 + const distinctNew = [...new Map(newClasses.map((c) => [c.name.toLowerCase(), c])).values()]
369 + const productions = rulings.filter((r) => r.outcome === 'B-production')
370 + const over30 = rulings.filter((r) => r.site_count > 30 && r.outcome !== 'B-production')
371 +
372 + if (ok.length < sample.batches.length) {
373 + log(`${sample.batches.length - ok.length} probe(s) returned nothing and are NOT counted as clean.`)
374 + }
375 +
376 + const rate = distinctNew.length / Math.max(1, ok.length)
377 + const [r4b, overAdmit] = residue
378 +
379 + const closed =
380 + distinctNew.length === 0 &&
381 + productions.length === 0 &&
382 + over30.length === 0 &&
383 + r4b && r4b.reproduced === false &&
384 + ok.length === sample.batches.length
385 +
386 + log(`${cleanProbes}/${ok.length} probes clean. ${distinctNew.length} new classes (round 1: ~${(ROUND_1.classes_per_probe).toFixed(2)}/probe, this round ${rate.toFixed(2)}/probe).`)
387 + log(closed
388 + ? 'Every reopening condition in section 8 is unmet. The closure record can be filed.'
389 + : 'At least one reopening condition is met. The form is not closed; amend and run round 3.')
390 +
391 + return {
392 + round: 2,
393 + seed: sample.seed,
394 + population: sample.population,
395 + sampled: sample.sampled,
396 + coverage_pct: sample.coverage_pct,
397 + selftest: sample.selftest,
398 + probes_run: ok.length,
399 + probes_requested: sample.batches.length,
400 + probes_clean: cleanProbes,
401 + round_1: ROUND_1,
402 + new_class_rate_per_probe: Number(rate.toFixed(2)),
403 + amendments_exercised: amendmentHits.map((c) => ({ ref: c.record_ref, site: c.site, note: c.effect })),
404 + new_classes: distinctNew,
405 + rulings,
406 + productions_earned: productions,
407 + unruled_over_30: over30,
408 + r4b,
409 + over_admission: overAdmit,
410 + closed,
411 + next: closed
412 + ? 'File the closure record as wiki `quasi-description-vocabulary-closed`, then close GoingsOn 65d99281 and start the emitter (6873a26c).'
413 + : 'Amend the form for each earned production, update wiki `quasi-declare-form`, and run another round. Do not file a closure record.',
414 + }