Repository navigation
Expand file tree
/
Copy pathprobe_arg_forms.py
More file actions
645 lines (579 loc) · 31 KB
/
Copy pathprobe_arg_forms.py
File metadata and controls
645 lines (579 loc) · 31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
#!/usr/bin/env python3
"""Probe VDJScript verb tails: which trailing tokens a verb actually recognizes.
A verb's tail is whatever follows its name (`get_bpm absolute ghost`). VirtualDJ
receives the whole line as one string and each `ACTION_` class parses its own
remainder, so there is no signature anywhere to read — the only way to learn a
tail's grammar is to compare answers.
Two things make that comparison hard, and this tool is built around both:
1. **A bad tail is silently ignored** (`loaded bogusword` -> `yes`), so "it
answered" proves nothing. Every candidate is therefore measured against
NONSENSE CONTROLS. A token that answers differently from garbage is
recognized; a token that matches garbage is not a token at all. Two
independent controls must agree with each other, or the reading is discarded
as unstable rather than reported.
**Not every verb ignores a bad tail, and on the ones that do not, this test
is weaker than it looks.** The sampler family ERRORS on an unrecognized slot
token (`get_sample_name zzqqx` -> `error:1`), so separating from the controls
is satisfied by any token the parser merely accepts — which is how `all`
came to be scored `recognized` on 26 verbs while returning the bare value
everywhere and doing nothing at all in execute position (2026-09-07, tracker
"`all`: Recognized By The Sweep, Inert Where It Was Tested"). When the
controls ERROR rather than answer, read `same_as_bare_everywhere` as the
real verdict: separation from junk is then evidence of parsing, and only
separation from BARE is evidence of meaning.
2. **A form can only be told from another in a state where they would
disagree.** `loaded opposite` says nothing with both decks empty. So every
probe runs inside each named state from tools/fixtures.py, and a candidate
counts as recognized if it separates from the controls in ANY state.
Read-only: /query alone, never /execute. Fixture setup is the only thing that
writes, and it restores what it changed.
python3 tools/probe_arg_forms.py --dry-run # plan and request count
python3 tools/probe_arg_forms.py --out tests/verb-arg-forms.json
python3 tools/probe_arg_forms.py --verbs loaded,get_bpm --fixtures one_deck_loaded
Forms are recorded as TOKEN LISTS, never a single argument string, because
whether a verb accepts more than one token is exactly what is unknown.
For lexical hypotheses, --grammar-cases FILE uses an exact-script suite instead:
delimiter bytes, quoting and prefixes are preserved. See runtime_grammar_probes.py.
Each prediction needs an explicit contrasting result and a named read-only fixture.
Separating from nonsense is NOT enough for a two-token form: `is_using loop
zzqqx` separates from garbage purely because `loop` does, with the tail
discarded. So each recognized pair is additionally compared against its own
single-token forms and labelled `first-token-wins`, `last-token-wins`,
`beyond-singles` (a value neither token produces alone — the only real evidence
of two-token grammar) or `singles-agree` (both singles read the same, so the
pair cannot discriminate).
Caveat this design does not fix: a verb whose value drifts on its own — CPU
load, position, level meters — can separate from a control by measurement noise
alone. `--repeat N` reads every form N times and demands agreement; the run
recorded in tests/verb-arg-forms.json used the default of 1, so treat
time-varying verbs (`get_cpu` is the type case) as unproven.
"""
from __future__ import annotations
import argparse
import json
import sys
from itertools import permutations
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from fixtures import (Channel, FixtureError, build_fixtures, ensure_audio, # noqa: E402
establish, is_error, teardown)
CONTRACTS = "tests/action-contracts.json"
VERB_TABLE = "tests/verb-table.json"
# Two unrelated junk tokens. They must agree with each other for a reading to
# count: if garbage A and garbage B disagree, the verb's answer is unstable
# (time-varying, say) and nothing can be concluded from it.
CONTROLS = ("zzqqx", "vfnrbq")
# Sentinel written when --repeat reads disagree: the verb answers differently to
# identical questions, so no comparison against it can mean anything.
DRIFTING = "\0drifting"
# Fixtures worth sweeping, cheapest first. sampler_slot_loaded asserts a state
# it does not create, so it is a free extra reading rather than a setup step.
DEFAULT_FIXTURES = ("sampler_slot_loaded", "one_deck_loaded", "both_decks_loaded",
"deck2_playing", "loop_active", "fx_slot_1_on")
def targets(contracts: dict, table: dict, want: list[str] | None) -> dict[str, list[str]]:
"""verb -> candidate tokens, for every verb worth probing."""
verbs, summary = contracts["verbs"], contracts["summary"]
optional = set(summary.get("optional_arg_queries", []))
real = set(table["verbs"])
out = {}
for name, rec in verbs.items():
if name not in real:
continue
cands = [c for c in (rec.get("keyword_candidates") or [])
if not _looks_like_symbol_fragment(c, verbs)]
if name in optional or cands:
out[name] = sorted(dict.fromkeys(cands))
if want:
missing = [w for w in want if w not in out]
if missing:
sys.exit(f"not probe targets: {', '.join(missing)}")
out = {k: v for k, v in out.items() if k in want}
return out
def _looks_like_symbol_fragment(token: str, verbs: dict) -> bool:
"""Drop candidates that are a tail of some `ACTION_<verb>` symbol.
String recovery off a method body picks up fragments of neighbouring
symbols: `param_equal` was credited with a keyword `TION_get_text`, which is
`ACTION_get_text` with the head sheared off. These are never real tokens.
"""
# The token must reach back INTO the `ACTION_` prefix to be a fragment.
# A token that merely equals a verb name (`left`, `loop`, `top`) is a
# perfectly good keyword and must survive.
return any(f"ACTION_{name}".endswith(token) and len(token) > len(name)
for name in verbs)
def shared_lexicon(artifact: Path, limit: int) -> list[str]:
"""Tokens already proven real for more than one verb.
A token that separates from nonsense on two unrelated verbs is part of a
shared vocabulary, not a quirk of one parser — the best guess available for
verbs whose own candidates were never recovered.
"""
if not artifact.exists():
sys.exit(f"--lexicon needs {artifact}; run the probe first")
counts: dict[str, int] = {}
for rec in json.load(open(artifact))["verbs"].values():
for form in rec["forms"]:
if len(form["tokens"]) == 1 and form["verdict"] == "recognized":
counts[form["tokens"][0]] = counts.get(form["tokens"][0], 0) + 1
shared = [tok for tok, n in sorted(counts.items(), key=lambda kv: (-kv[1], kv[0])) if n > 1]
return shared[:limit]
def forms_for(tokens: list[str], pairs: bool) -> list[tuple[str, ...]]:
"""Bare, each token alone, then ordered pairs — as token tuples."""
forms: list[tuple[str, ...]] = [()]
forms += [(t,) for t in tokens]
if pairs and len(tokens) > 1:
forms += list(permutations(tokens, 2))
return forms
def script_for(verb: str, form: tuple[str, ...]) -> str:
return " ".join((verb,) + form)
def read_form(channel: Channel, script: str, repeat: int) -> str:
"""Read a form, demanding agreement across `repeat` reads.
A verb that answers differently to two identical reads is time-varying, and
no comparison against it means anything — say so rather than record one of
the values.
"""
first = channel.query(script)
for _ in range(repeat - 1):
if channel.query(script) != first:
return DRIFTING
return first
def probe_fixture(channel: Channel, plan: dict[str, list[tuple[str, ...]]],
fixture_name: str, readings: dict, verbose: bool,
repeat: int = 1) -> None:
"""Read every form of every verb, in the state currently established."""
for i, (verb, forms) in enumerate(plan.items(), 1):
for form in forms:
readings[verb][form][fixture_name] = read_form(
channel, script_for(verb, form), repeat)
for control in CONTROLS:
readings[verb][("\0control", control)][fixture_name] = read_form(
channel, script_for(verb, (control,)), repeat)
if verbose and i % 50 == 0:
print(f" {fixture_name}: {i}/{len(plan)} verbs", file=sys.stderr)
def classify(verb_readings: dict, fixtures: list[str]) -> dict:
"""Per form: does it separate from garbage, and where?"""
control_keys = [("\0control", c) for c in CONTROLS]
out_forms = []
for form, by_fixture in verb_readings.items():
if form in control_keys:
continue
separates, unstable, matches_bare = [], [], []
for fx in fixtures:
value = by_fixture.get(fx)
controls = [verb_readings[k].get(fx) for k in control_keys]
bare = verb_readings.get((), {}).get(fx)
if value is None or any(c is None for c in controls):
continue
if value == DRIFTING or DRIFTING in controls:
unstable.append(fx)
continue
if controls[0] != controls[1]:
unstable.append(fx)
continue
if value != controls[0]:
separates.append(fx)
if bare is not None and value == bare:
matches_bare.append(fx)
if form == ():
verdict = "bare"
elif separates:
verdict = "recognized"
elif unstable and len(unstable) == len(fixtures):
verdict = "unstable"
else:
verdict = "indistinguishable-from-nonsense"
rec = {
"tokens": list(form),
"verdict": verdict,
"values": {fx: by_fixture.get(fx) for fx in fixtures if fx in by_fixture},
}
if separates:
rec["separates_in"] = separates
if unstable:
rec["unstable_in"] = unstable
if form != () and matches_bare and len(matches_bare) == len(rec["values"]):
rec["same_as_bare_everywhere"] = True
out_forms.append(rec)
_label_pairs(out_forms)
out_forms.sort(key=lambda r: (len(r["tokens"]), r["tokens"]))
recognized = [r for r in out_forms if r["verdict"] == "recognized"]
beyond = [r for r in recognized if r.get("pair_shape") in ("beyond-singles",
"last-token-wins")]
return {
"forms": out_forms,
"controls": {c: {fx: verb_readings[("\0control", c)].get(fx) for fx in fixtures
if fx in verb_readings[("\0control", c)]} for c in CONTROLS},
"recognized_tokens": [list(t) for t in sorted(
{tuple(r["tokens"]) for r in recognized}, key=lambda t: (len(t), t))],
"two_token_grammar": bool(beyond),
"two_token_forms": [r["tokens"] for r in beyond],
}
UNDISCERNING_SHARE = 0.5
def _flag_undiscerning(verbs_out: dict) -> set:
"""Strip verbs that "recognize" most of an arbitrary vocabulary.
The shared lexicon is not tailored to any one verb, so a verb separating
from nonsense on half of it is not speaking that vocabulary — its answer is
drifting under the probe (`record_vu` matched 24 of 25 tokens, `pioneer_cue`
15) and every hit is measurement noise. Same failure as get_cpu, one level
up: --repeat catches a value that moves between two reads, this catches one
that moves between a token read and its control.
"""
flagged = set()
for verb, rec in verbs_out.items():
singles = [f for f in rec["forms"] if len(f["tokens"]) == 1]
hits = [f for f in singles if f["verdict"] == "recognized"]
if len(singles) >= 10 and len(hits) > UNDISCERNING_SHARE * len(singles):
flagged.add(verb)
for form in hits:
form["verdict"] = "undiscerning"
form["undiscerning"] = f"{len(hits)}/{len(singles)} of an arbitrary lexicon"
rec["recognized_tokens"] = []
rec["two_token_grammar"] = False
rec["two_token_forms"] = []
return flagged
def _pair_shape_counts(verbs_out: dict) -> dict:
from collections import Counter
c = Counter(f["pair_shape"] for r in verbs_out.values() for f in r["forms"]
if "pair_shape" in f)
return dict(sorted(c.items(), key=lambda kv: -kv[1]))
def _totals(verbs_out: dict) -> dict:
"""Recount the summary's size fields from the records under it.
Every path that rewrites `verbs` must call this. A merge unions form lists,
so the header's totals drift the moment they are carried over — they sat at
the 2026-09-02 sweep's figures while the records grew to more than twice as many forms.
"""
return {"verbs": len(verbs_out),
"forms": sum(len(r["forms"]) for r in verbs_out.values())}
def _label_pairs(out_forms: list[dict]) -> None:
"""A recognized pair means nothing until compared with its own singles."""
single = {tuple(r["tokens"]): r for r in out_forms if len(r["tokens"]) == 1}
for rec in out_forms:
if len(rec["tokens"]) != 2 or rec["verdict"] != "recognized":
continue
a, b = (single.get((rec["tokens"][0],)), single.get((rec["tokens"][1],)))
def same(other):
return other is not None and all(
rec["values"].get(fx) == other["values"].get(fx) for fx in rec["values"])
eq_a, eq_b = same(a), same(b)
if eq_a and eq_b:
rec["pair_shape"] = "singles-agree"
elif eq_a:
rec["pair_shape"] = "first-token-wins"
elif eq_b:
rec["pair_shape"] = "last-token-wins"
else:
rec["pair_shape"] = "beyond-singles"
def main() -> int:
p = argparse.ArgumentParser()
p.add_argument("--dry-run", action="store_true")
p.add_argument("--grammar-playing", type=Path,
help="silent fixture playback on empty decks 3/4, with a different master pinned")
p.add_argument("--grammar-scopes", type=Path,
help="selected-deck fixture with query-only scope hypotheses")
p.add_argument("--grammar-actions", type=Path,
help="allowlisted zoom/beatlock or prepared Phaser-slot stateful grammar suite")
p.add_argument("--grammar-cases", type=Path,
help="exact-script hypothesis suite; preserves delimiters and prefixes")
p.add_argument("--rounds", type=int, default=2,
help="independent passes for --grammar-cases (minimum 2)")
p.add_argument("--verbs", help="comma-separated subset")
p.add_argument("--fixtures", default=",".join(DEFAULT_FIXTURES))
p.add_argument("--no-pairs", action="store_true", help="skip ordered two-token forms")
p.add_argument("--from-corpus", action="store_true",
help="take candidates from tails Atomix actually wrote in shipped scripts "
"(tests/attested-tails.json) — attested forms, so a miss means the "
"fixtures cannot see it, not that the token is unreal")
p.add_argument("--from-catalog", action="store_true",
help="take each verb's candidates from the Button Editor catalog's own "
"prose (tests/action-catalog.json) instead of the binary — these are "
"documented parameters, so a hit confirms and a miss is a real gap")
p.add_argument("--lexicon", type=int, metavar="N", nargs="?", const=25,
help="probe the N most cross-verb tokens already proven real against the "
"verbs whose own candidates were never recovered (default 25)")
p.add_argument("--check", action="store_true")
p.add_argument("--merge", metavar="FILE",
help="fold a targeted re-probe into the artifact, replacing "
"those verbs and recording how many reads backed them")
p.add_argument("--reclassify", action="store_true",
help="recompute verdicts from the stored artifact values, "
"without touching VirtualDJ")
p.add_argument("--get", metavar="NAME", help="report one verb from the artifact")
p.add_argument("--quiet", action="store_true")
p.add_argument("--out", metavar="FILE",
help="write the run's artifact here (atomically) instead of stdout; "
"--dry-run, --check, --get and --merge never write it")
p.add_argument("--repeat", type=int, default=1, metavar="N",
help="read each form N times and keep the value only if every read "
"agrees; guards against verbs whose value drifts on its own")
args = p.parse_args()
if sum(bool(x) for x in (args.grammar_actions,args.grammar_cases,args.grammar_scopes,args.grammar_playing)) > 1:
p.error("choose one grammar mode")
if args.grammar_playing:
from runtime_grammar_playing import run_suite
return run_suite(args)
if args.grammar_scopes:
from runtime_grammar_scopes import run_suite
return run_suite(args)
if args.grammar_actions:
if args.grammar_cases:
p.error("choose one grammar mode")
from runtime_grammar_actions import run_suite
return run_suite(args)
if args.grammar_cases:
from runtime_grammar_probes import run_suite
return run_suite(args)
contracts = json.load(open(CONTRACTS))
table = json.load(open(VERB_TABLE))
want = [v.strip() for v in args.verbs.split(",")] if args.verbs else None
cands = targets(contracts, table, want)
if args.from_corpus:
attested = json.load(open("tests/attested-tails.json"))["tails"]
real = set(table["verbs"])
cands = {v: sorted(toks) for v, toks in attested.items()
if v in real and (not want or v in want)}
if not args.quiet:
print(f"corpus-attested tails on {len(cands)} verbs", file=sys.stderr)
if args.from_catalog:
catalog = json.load(open("tests/action-catalog.json"))["actions"]
documented = {v: r["documented_parameters"] for v, r in catalog.items()
if r["documented_parameters"]}
real = set(table["verbs"])
cands = {v: toks for v, toks in documented.items()
if v in real and (not want or v in want)}
if not args.quiet:
print(f"catalog-documented parameters on {len(cands)} verbs", file=sys.stderr)
if args.lexicon:
lexicon = shared_lexicon(Path("tests/verb-arg-forms.json"), args.lexicon)
# Only verbs with no vocabulary of their own — the ones the first sweep
# could do nothing for beyond reading them bare.
cands = {v: lexicon for v, own in cands.items() if not own} if not want else \
{v: lexicon for v in cands}
if not args.quiet:
print(f"lexicon ({len(lexicon)}): {' '.join(lexicon)}", file=sys.stderr)
plan = {v: forms_for(t, not args.no_pairs) for v, t in cands.items()}
fixture_names = [f.strip() for f in args.fixtures.split(",") if f.strip()]
if args.merge:
artifact = Path("tests/verb-arg-forms.json")
base = json.load(open(artifact))
add = json.load(open(args.merge))
# More states is more evidence and merges cleanly; a DIFFERENT set does
# not, because a verdict computed under states the base never saw is not
# comparable with one it did.
base_fixtures, add_fixtures = set(base["summary"]["fixtures"]), set(add["summary"]["fixtures"])
if not base_fixtures <= add_fixtures:
sys.exit(f"merge refused: the incoming run is missing fixtures the artifact used "
f"({sorted(base_fixtures - add_fixtures)}); re-run with a superset")
base["summary"]["fixtures"] = sorted(add_fixtures, key=lambda f: (f not in base_fixtures, f))
if add["summary"].get("build") != base["summary"].get("build"):
# A merged artifact can span builds, including unstamped legacy
# measurements. Never stamp old observations with the incoming build.
base["summary"].pop("build", None)
base["summary"]["build_scope"] = "mixed or legacy; inspect per-form provenance"
repeat = add["summary"].get("repeat_reads", 1)
disputed = set(base["summary"].get("disputed_verbs", []))
undiscerning = _flag_undiscerning(add["verbs"])
for verb, rec in add["verbs"].items():
prior = base["verbs"].get(verb)
if prior is None:
rec["repeat_reads"] = repeat
base["verbs"][verb] = rec
continue
# UNION the form lists, never replace. A targeted re-probe covers a
# narrower set of forms than the sweep it refines (--from-catalog
# skips pairs entirely), so replacing would silently delete
# measurements and turn "not probed this time" into "not a token".
by_tokens = {tuple(f["tokens"]): f for f in prior["forms"]}
reprobed = {tuple(f["tokens"]): f for f in rec["forms"]}
# A verdict that flips on a form BOTH runs measured is a real
# dispute; one the new run never sent is not.
for tokens, form in reprobed.items():
was = by_tokens.get(tokens)
# Separation is positive evidence; failing to separate is not
# evidence of absence — it usually means this run's states did
# not discriminate. So a token recognized in ANY run stays
# recognized, with a note that a later run did not reproduce it.
if was and was["verdict"] == "recognized" and form["verdict"] != "recognized":
was.setdefault("not_reproduced_in", []).append(
{"fixtures": add["summary"]["fixtures"],
"verdict": form["verdict"]})
continue
if (was and prior.get("repeat_reads", 1) > 1
and was.get("pair_shape") and form.get("pair_shape")
and was["pair_shape"] != form["pair_shape"]):
disputed.add(verb)
form["disputed"] = (f"pair shape for {' '.join(tokens)} differed between "
f"runs: {was['pair_shape']} vs {form['pair_shape']}")
by_tokens[tokens] = form
merged_forms = sorted(by_tokens.values(),
key=lambda f: (len(f["tokens"]), f["tokens"]))
recognized = [f for f in merged_forms if f["verdict"] == "recognized"
and "disputed" not in f]
prior.update({
"forms": merged_forms,
"controls": {**prior.get("controls", {}), **rec.get("controls", {})},
"recognized_tokens": [list(x) for x in sorted(
{tuple(f["tokens"]) for f in recognized}, key=lambda x: (len(x), x))],
"two_token_grammar": any(
f.get("pair_shape") in ("beyond-singles", "last-token-wins")
for f in recognized),
"repeat_reads": max(prior.get("repeat_reads", 1), repeat),
})
prior["two_token_forms"] = [f["tokens"] for f in recognized
if f.get("pair_shape") in ("beyond-singles",
"last-token-wins")]
recognized = sum(1 for r in base["verbs"].values()
for f in r["forms"] if f["verdict"] == "recognized")
base["summary"].update({
**_totals(base["verbs"]),
"recognized_forms": recognized,
"verbs_with_recognized_token": sum(1 for r in base["verbs"].values()
if r["recognized_tokens"]),
"two_token_grammar_verbs": sorted(v for v, r in base["verbs"].items()
if r["two_token_grammar"]),
"pair_shapes": _pair_shape_counts(base["verbs"]),
"confirmed_with_repeat": sorted(v for v, r in base["verbs"].items()
if r.get("repeat_reads", 1) > 1),
"disputed_verbs": sorted(disputed),
"undiscerning_verbs": sorted(
set(base["summary"].get("undiscerning_verbs", [])) | undiscerning),
})
artifact.write_text(json.dumps(base, indent=1) + "\n")
print(f"merged {len(add['verbs'])} verbs read {repeat}x: "
f"two-token grammar now {base['summary']['two_token_grammar_verbs']}",
file=sys.stderr)
return 0
if args.reclassify:
artifact = Path("tests/verb-arg-forms.json")
data = json.load(open(artifact))
fixtures_done = data["summary"]["fixtures"]
rebuilt = {}
for verb, rec in data["verbs"].items():
readings = {tuple(f["tokens"]): dict(f["values"]) for f in rec["forms"]}
for control, values in rec["controls"].items():
readings[("\0control", control)] = dict(values)
rebuilt[verb] = classify(readings, fixtures_done)
recognized = sum(1 for r in rebuilt.values()
for f in r["forms"] if f["verdict"] == "recognized")
data["verbs"] = rebuilt
data["summary"].update({
**_totals(rebuilt),
"recognized_forms": recognized,
"verbs_with_recognized_token": sum(1 for r in rebuilt.values()
if r["recognized_tokens"]),
"two_token_grammar_verbs": sorted(v for v, r in rebuilt.items()
if r["two_token_grammar"]),
"pair_shapes": _pair_shape_counts(rebuilt),
})
data["summary"].pop("multi_token_verbs", None)
artifact.write_text(json.dumps(data, indent=1) + "\n")
print(f"reclassified {len(rebuilt)} verbs from stored values: "
f"{data['summary']['pair_shapes']}", file=sys.stderr)
return 0
if args.get:
artifact = Path("tests/verb-arg-forms.json")
if not artifact.exists():
sys.exit("tests/verb-arg-forms.json not collected yet — run "
"`just probe-arg-forms` with VirtualDJ up")
rec = json.load(open(artifact))["verbs"].get(args.get)
if rec is None:
# A verb with no keyword candidates may still take arguments: the
# corpus attests literal shapes (`fadeout DUR DUR BT`) that the
# keyword sources never see. Say so instead of "needs no args".
shapes = {}
tails = Path("tests/attested-tails.json")
if tails.exists():
shapes = json.load(open(tails)).get("shapes", {}).get(args.get, {})
if shapes:
hint = ("not probed: no keyword candidates, but the corpus attests literal "
"argument shapes — probe by shape (`just attested-tails --verb`)")
else:
hint = "not an arg-form target (no candidates, no attested shapes)"
print(json.dumps({"name": args.get, "probed": False, "hint": hint,
"attested_shapes": sorted(shapes)}, indent=1))
return 0
print(json.dumps({"name": args.get, **rec}, indent=1))
return 0
if args.check:
artifact = Path("tests/verb-arg-forms.json")
if not artifact.exists():
print("arg-form probe check skipped: tests/verb-arg-forms.json not collected yet")
return 0
data = json.load(open(artifact))
s = data["summary"]
if s["controls"] != list(CONTROLS):
sys.exit(f"arg-form probe check FAILED: controls changed {s['controls']}")
print(f"arg-form probe check passed: {s['verbs']} verbs, {s['forms']} forms, "
f"{s['recognized_forms']} recognized, fixtures {s['fixtures']}")
return 0
forms_total = sum(len(f) for f in plan.values())
requests = (forms_total + len(plan) * len(CONTROLS)) * len(fixture_names)
if args.dry_run or not args.quiet:
print(f"targets: {len(plan)} verbs, {forms_total} forms "
f"({sum(1 for f in plan.values() for x in f if len(x) == 1)} single-token, "
f"{sum(1 for f in plan.values() for x in f if len(x) == 2)} ordered pairs)\n"
f"fixtures: {', '.join(fixture_names)}\n"
f"requests: {requests} (+ {len(fixture_names)} fixture setups)",
file=sys.stderr)
if args.dry_run:
return 0
channel = Channel()
if not channel.reachable():
raise FixtureError("HTTP channel unreachable on localhost:80 — is VirtualDJ running?")
provenance = channel.provenance()
track = ensure_audio(verbose=not args.quiet)
fixtures = build_fixtures(track)
readings = {v: {f: {} for f in forms} for v, forms in plan.items()}
for v in readings:
for c in CONTROLS:
readings[v][("\0control", c)] = {}
done: list[str] = []
for name in fixture_names:
fixture = fixtures[name]
if not args.quiet:
print(f" establishing {name}", file=sys.stderr)
before = establish(channel, fixture, verbose=False)
try:
probe_fixture(channel, plan, name, readings, verbose=not args.quiet,
repeat=args.repeat)
done.append(name)
finally:
teardown(channel, fixture, before, verbose=False)
verbs_out = {v: classify(readings[v], done) for v in plan}
for record in verbs_out.values():
record["provenance"] = provenance
for form in record["forms"]:
form["provenance"] = provenance
recognized = sum(1 for v in verbs_out.values()
for f in v["forms"] if f["verdict"] == "recognized")
multi = sorted(v for v, r in verbs_out.items() if r["two_token_grammar"])
result = {
"summary": {
**provenance,
"verbs": len(verbs_out),
"forms": forms_total,
"recognized_forms": recognized,
"verbs_with_recognized_token": sum(1 for r in verbs_out.values()
if r["recognized_tokens"]),
"two_token_grammar_verbs": multi,
"pair_shapes": _pair_shape_counts(verbs_out),
"repeat_reads": args.repeat,
"fixtures": done,
"controls": list(CONTROLS),
},
"verbs": verbs_out,
}
if args.out:
# Write beside the target and rename, so an aborted run or an empty
# result can never truncate the evidence already on disk.
target = Path(args.out)
tmp = target.with_suffix(target.suffix + ".tmp")
tmp.write_text(json.dumps(result, indent=1) + "\n")
tmp.replace(target)
print(f"wrote {target}", file=sys.stderr)
else:
json.dump(result, sys.stdout, indent=1)
print(file=sys.stdout)
return 0
if __name__ == "__main__":
try:
raise SystemExit(main())
except FixtureError as exc:
raise SystemExit(f"fixture error: {exc}")