export const meta = { name: 'quasi-probe-round', description: 'Probe round against the amended declare! form: re-author sampled shapes, adjudicate every new failure class against the four-part bar', 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.', phases: [ { title: 'Sample', detail: 'draw the stratified batch list from probe-sample.py' }, { title: 'Probe', detail: 'one agent per batch, each re-authoring its shapes in the amended form' }, { title: 'Residue', detail: 'R4(b) reproduction and the grammar over-admission check' }, { title: 'Adjudicate', detail: 'four-part bar applied to every class not already in the record' }, { title: 'Synthesize', detail: 'verdict, coverage, and the hit-rate comparison against round 1' }, ], } // --------------------------------------------------------------------------- // Round 1 is the thing this round is measured against: 15 probes over 26 // functions (5.1% of 514), 4 clean, one new blocking class per 1.4 probes, and // the rate never flattened. A round that does not beat that coverage cannot // settle the closure claim however clean it comes back. // --------------------------------------------------------------------------- const ROUND_1 = { probes: 15, functions: 26, clean: 4, coverage: 5.1, classes_per_probe: 1 / 1.4 } const seed = (args && args.seed) || 2 const probes = (args && args.probes) || 15 const perProbe = (args && args.perProbe) || 3 const READING = ` Read these before writing a single production. They are the contract: - \`~/Wiki/quasi-declare-form.md\` -- the grammar (EBNF), the twelve amendments each with its measurement, the eleven static rules, three worked examples, the deferred table in section 6, and the four-part bar in section 8. This is the form you are probing. It is long; read sections 4, 6 and 8 in full. - \`~/Wiki/construction-holds-the-invariant.md\` -- the companion. - \`~/Code/quasi/crates/quasi-router/src/screen.rs\` -- the constructors a declaration has to emit. A production that cannot name a real constructor is not a production. You are READ-ONLY. Do not edit, create or commit any file, in any repo. A probe is a re-authoring on paper, checked production by production. Its output is evidence, not a patch. ` const PROBE_SCHEMA = { type: 'object', required: ['targets', 'verdict', 'classes'], properties: { targets: { type: 'array', items: { type: 'object', required: ['file', 'fn', 'reauthored'], properties: { file: { type: 'string' }, fn: { type: 'string' }, reauthored: { type: 'boolean', description: 'true only if EVERY construct in the function was expressible in the amended form', }, declaration: { type: 'string', description: 'the declaration you wrote, verbatim; empty if it could not be written', }, }, }, }, verdict: { type: 'string', enum: ['clean', 'failed'], description: 'clean only if every target re-authored with no residue', }, classes: { type: 'array', description: 'one entry per distinct construct the form could not say. Empty when clean.', items: { type: 'object', required: ['name', 'construct', 'site', 'in_record', 'remedy_available'], properties: { name: { type: 'string', description: 'short name for the class' }, construct: { type: 'string', description: 'the Rust that could not be said' }, site: { type: 'string', description: 'file:line of a real occurrence' }, in_record: { type: 'boolean', description: 'true if this class is already one of the twelve amendments or on section 6 deferred table', }, record_ref: { type: 'string', description: 'which amendment or deferred row, when in_record' }, remedy_available: { type: 'boolean', description: 'true if outcome A applies -- the deferred table names a remedy that covers it', }, effect: { type: 'string', description: 'what a user sees, or the compile error, or the status code that changes', }, }, }, }, }, } const BAR_SCHEMA = { type: 'object', required: ['classes'], properties: { classes: { type: 'array', items: { type: 'object', required: ['name', 'site_count', 'count_command', 'outcome', 'reasoning'], properties: { name: { type: 'string' }, site_count: { type: 'integer', description: 'measured across all three shape directories' }, count_command: { type: 'string', 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', }, alternative: { type: 'string', description: 'the named alternative, priced: signature change + call sites, or N new suppliers' }, failing_screen: { type: 'string', description: 'file:line of a screen that currently fails, not a hypothetical' }, cannot_be_used_for: { type: 'string', description: 'what the proposed production must not admit' }, outcome: { type: 'string', enum: ['A-remedy', 'B-production', 'C-refuse'], 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.', }, reasoning: { type: 'string' }, }, }, }, }, } // --------------------------------------------------------------- Sample ---- phase('Sample') const sample = await agent( `Run this, from \`~/Code/quasi\`, and return exactly what it prints: python3 scripts/probe-sample.py --seed ${seed} --probes ${probes} --per-probe ${perProbe} --json Run \`python3 scripts/population.py --selftest\` first and report its result in \`selftest\`; the draw is worthless if the predicate is broken. Do not edit anything. Return the parsed JSON, not a description of it.`, { label: `sample seed ${seed}`, phase: 'Sample', effort: 'low', schema: { type: 'object', required: ['seed', 'population', 'sampled', 'coverage_pct', 'selftest', 'batches'], properties: { seed: { type: 'integer' }, population: { type: 'integer' }, sampled: { type: 'integer' }, coverage_pct: { type: 'number' }, selftest: { type: 'string' }, batches: { type: 'array', items: { type: 'object', required: ['probe', 'targets'], properties: { probe: { type: 'integer' }, targets: { type: 'array', items: { type: 'object', properties: { file: { type: 'string' }, line: { type: 'integer' }, fn: { type: 'string' }, returns: { type: 'string' }, lines: { type: 'integer' }, }, }, }, }, }, }, }, }, } ) if (!sample || !sample.batches || !sample.batches.length) { log('Sampling returned nothing. Nothing to probe; check probe-sample.py by hand.') return { error: 'no sample', sample } } log(`seed ${sample.seed}: ${sample.sampled} of ${sample.population} shapes (${sample.coverage_pct}%), ${sample.batches.length} probes. Round 1 covered ${ROUND_1.coverage}%.`) if (sample.coverage_pct <= ROUND_1.coverage) { log(`WARNING: this round covers no more than round 1 did. A clean result at this coverage settles nothing.`) } // -------------------------------------------------------------- Residue ---- // Two of the four conditions in section 8 that reopen the closure claim are not // probe findings at all. They get one agent each, started HERE so they run // alongside the probes rather than queueing behind them. const residuePromise = parallel([ () => agent( `Reproduce or refute R4(b), the owned-payload double move. ${READING} R4(b) is the one residue in the record with NO site count. It was reported as a defect and never reproduced, and its failure mode is a compile error in generated code with no source line to point at -- the worst thing to discover 400 functions into the mass phase. Section 8 names "R4(b) reproduced" as one of the four things that reopen the closure claim. Construct the minimal case from the rule as written in section 4, decide whether the double move actually occurs, and if it does, measure its incidence across the three shape directories with a command you write down and run. If it does not occur, say what in the rule prevents it and what the original report probably saw. Read-only.`, { label: 'R4(b)', phase: 'Residue', effort: 'high', schema: { type: 'object', required: ['reproduced', 'evidence'], properties: { reproduced: { type: 'boolean' }, incidence: { type: 'integer', description: 'measured site count when reproduced, -1 when not' }, count_command: { type: 'string' }, evidence: { type: 'string' }, }, } } ), () => agent( `Test what the grammar OVER-admits. ${READING} Section 7 lists this as untested against any implementation: \`node\`'s body accepts any emission so \`act "Delete" { region .. }\` parses; prepositions carry no meaning so \`field from H\`, \`field to H\` and \`field by H\` are one declaration; \`arg*\` has no arity rule so \`image cover "{title}"\` cannot tell \`src\` from \`alt\`; and 24 grammar terminals are live function names in these directories (region, page, section, text, act, image, empty, form, list, table, row, column, stats, screen, across, include, read, require, unless, of, from, get, delete, leaving). Every case traced was said to be decidable on one token of lookahead. Check that claim properly: work the grammar by hand, find every place two productions share a prefix, and say which are decidable on one token, which need more, and which are genuinely ambiguous. For the 24 terminals, measure how many are actually called as functions inside a declaration body rather than merely defined, since that is what decides whether the collision bites. An ambiguity here is a finding about the form, not about the emitter. Read-only.`, { label: 'over-admission', phase: 'Residue', effort: 'high', schema: { type: 'object', required: ['ambiguities', 'verdict'], properties: { verdict: { type: 'string', enum: ['one-token-lookahead-holds', 'needs-more-lookahead', 'genuinely-ambiguous'] }, ambiguities: { type: 'array', items: { type: 'object', required: ['productions', 'lookahead', 'note'], properties: { productions: { type: 'string' }, lookahead: { type: 'string' }, note: { type: 'string' }, }, }, }, terminal_collisions: { type: 'integer', description: 'of the 24, how many are called inside a declaration body' }, }, } } ), ]) // ------------------------------------------------- Probe -> Adjudicate ---- // Pipeline, not a barrier: a probe's new classes go to the bar the moment that // probe returns, while the other fourteen are still re-authoring. The // adjudicator is spawned only when a probe reports a class the record does not // already hold, so a clean-ish round costs almost nothing beyond the probes. const probed = await pipeline( sample.batches, (b) => agent( `You are probe ${b.probe} of a round-2 probe against the amended \`declare!\` form. ${READING} YOUR TARGETS -- re-author every one of them: ${b.targets.map((t) => ` ${t.file}:${t.line} fn ${t.fn} -> ${t.returns} (${t.lines} lines)`).join('\n')} HOW TO PROBE. Read the real function first. Then write the whole thing as a declaration in the amended form, production by production, checking each against the grammar in section 4 and against the constructor it has to emit in \`screen.rs\`. Do not skim and pronounce; a probe that did not write the declaration out is not a probe. Put what you wrote in \`declaration\`. WHAT COUNTS AS A FAILURE. Any construct in the function that the amended form cannot say. Before you call it a failure, check two things: 1. Is it already one of the twelve amendments? Those are specified but unprobed, so exercising one is the POINT of this round. Set \`in_record: true\` and \`record_ref\`, and say in \`effect\` whether the amendment as specified actually covers the site or falls short of it. An amendment that does not cover its own motivating case is the most valuable thing you can find. 2. Is it on the deferred table in section 6? Then the named remedy applies -- a \`-> impl Display\` supplier, a \`-> Vec\` payload supplier, a named predicate, a domain accessor. Set \`remedy_available: true\`. That is outcome A, the expected one, and it is not a failure of the form. A target re-authors (\`reauthored: true\`) when every construct in it is either expressible or covered by a stated remedy. \`verdict\` is \`clean\` only when all of your targets re-authored. Be exact and be honest. A false clean is worse here than a false failure: this round decides whether 289 more functions get re-authored against this form.`, { label: `probe ${b.probe}`, phase: 'Probe', schema: PROBE_SCHEMA } ), (r, b) => { if (!r) return null const fresh = (r.classes || []).filter((c) => !c.in_record && !c.remedy_available) if (!fresh.length) return { probe: b.probe, result: r, bar: null } return agent( `Apply section 8's four-part bar to each class below. They came out of probe ${b.probe} and none is in the record, so each one either earns a production, takes a remedy, or is refused. ${READING} THE CLASSES: ${fresh.map((c) => `- ${c.name}: ${c.construct}\n seen at ${c.site}; effect: ${c.effect || 'unstated'}`).join('\n')} For each one, all four parts, and no shortcuts: 1. A SITE COUNT for the whole class across all three shape directories, produced by a command you write down and actually run, with \`tests.rs\`, \`parity.rs\` and inline \`#[cfg(test)]\` excluded and comments and string literals blanked before matching. A count off \`Type::method(\` alone is NOT a count -- three of the four members this record had to rescue are reached by a chained builder or a field assignment. Put the command in \`count_command\`, runnable as written. 2. THE NAMED ALTERNATIVE, PRICED. Either the signature change and its call-site count, or the number of new supplier functions. "Move it upstream" with no number is not an alternative. 3. A FAILING SCREEN, by file and line. It must currently produce something a user sees that the declaration cannot produce, or force a compile error, or change a status code. Convenience is not a reason. 4. WHAT THE PRODUCTION CANNOT THEN BE USED FOR. A production admitting an expression, a block in argument position, a closure, or a \`Type { .. }\` aggregate is refused whatever its site count. THE THRESHOLD. Under 10 sites earns no production -- outcome A or C. Between 10 and 30 it earns one only if part 2's alternative touches more call sites than the construct has, or part 3's failure is a status-code or data-loss failure rather than a rendering one. Over 30 it earns one. Default to refusing. The form already refuses \`impl Trait\` at 4 sites and \`Repeating\` at 7. You are read-only: measure and rule, change nothing.`, { label: `bar: probe ${b.probe}`, phase: 'Adjudicate', effort: 'high', schema: BAR_SCHEMA } ).then((bar) => ({ probe: b.probe, result: r, bar })) } ) const residue = await residuePromise // ----------------------------------------------------------- Synthesize ---- phase('Synthesize') const ok = probed.filter(Boolean) const results = ok.map((p) => p.result) const cleanProbes = results.filter((r) => r.verdict === 'clean').length const allClasses = results.flatMap((r) => r.classes || []) const newClasses = allClasses.filter((c) => !c.in_record && !c.remedy_available) const amendmentHits = allClasses.filter((c) => c.in_record) const rulings = ok.flatMap((p) => (p.bar && p.bar.classes) || []) // Dedupe by name: several probes hitting one class is one class, and the // hit-rate comparison against round 1 is meaningless if it is counted twice. const distinctNew = [...new Map(newClasses.map((c) => [c.name.toLowerCase(), c])).values()] const productions = rulings.filter((r) => r.outcome === 'B-production') const over30 = rulings.filter((r) => r.site_count > 30 && r.outcome !== 'B-production') if (ok.length < sample.batches.length) { log(`${sample.batches.length - ok.length} probe(s) returned nothing and are NOT counted as clean.`) } const rate = distinctNew.length / Math.max(1, ok.length) const [r4b, overAdmit] = residue const closed = distinctNew.length === 0 && productions.length === 0 && over30.length === 0 && r4b && r4b.reproduced === false && ok.length === sample.batches.length 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).`) log(closed ? 'Every reopening condition in section 8 is unmet. The closure record can be filed.' : 'At least one reopening condition is met. The form is not closed; amend and run round 3.') return { round: 2, seed: sample.seed, population: sample.population, sampled: sample.sampled, coverage_pct: sample.coverage_pct, selftest: sample.selftest, probes_run: ok.length, probes_requested: sample.batches.length, probes_clean: cleanProbes, round_1: ROUND_1, new_class_rate_per_probe: Number(rate.toFixed(2)), amendments_exercised: amendmentHits.map((c) => ({ ref: c.record_ref, site: c.site, note: c.effect })), new_classes: distinctNew, rulings, productions_earned: productions, unruled_over_30: over30, r4b, over_admission: overAdmit, closed, next: closed ? 'File the closure record as wiki `quasi-description-vocabulary-closed`, then close GoingsOn 65d99281 and start the emitter (6873a26c).' : 'Amend the form for each earned production, update wiki `quasi-declare-form`, and run another round. Do not file a closure record.', }