@andresmassello/uscha 1.73.0 → 1.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +1 -1
- package/uscha-kit/.claude/skills/uscha-devloop/qa_ledger.py +387 -0
- package/uscha-kit/.claude-plugin/plugin.json +2 -2
- package/uscha-kit/.codex-plugin/plugin.json +1 -1
- package/uscha-kit/README.md +1 -1
- package/uscha-kit/VERSION +1 -1
- package/uscha-kit/reports/junit/.bench-cases.json +1 -0
- package/uscha-kit/reports/junit/.bootstrap-cases.json +1 -0
- package/uscha-kit/skills/uscha-devloop/qa_ledger.py +387 -0
- package/uscha-kit/uscha.config.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Requires **Python 3.8+** on the machine (the engine is Python stdlib — no pip
|
|
|
40
40
|
runtime dependencies). The npm package is a thin router; the canonical installer is
|
|
41
41
|
`uscha-kit/install-uscha.py`.
|
|
42
42
|
|
|
43
|
-
**Kit v1.
|
|
43
|
+
**Kit v1.75.0** <!-- uscha:version --> · [uscha.dev](https://uscha.dev) ·
|
|
44
44
|
[changelog](https://github.com/andresmassello/uscha/blob/main/uscha-kit/CHANGELOG.md)
|
|
45
45
|
(the per-release changelogs live in the repo, not in the npm tarball)
|
|
46
46
|
|
|
@@ -76,7 +76,7 @@ and see which file, which test, and when.
|
|
|
76
76
|
| `/uscha-mirador` | Bird's-eye HTML dashboard: readiness, trail, acceptance, loops |
|
|
77
77
|
| `/uscha-status` | One-line progress readout, in chat |
|
|
78
78
|
|
|
79
|
-
**A measurement engine** (`qa_ledger.py`,
|
|
79
|
+
**A measurement engine** (`qa_ledger.py`, 47 subcommands, Python stdlib) that ingests
|
|
80
80
|
evidence from **11 language stacks** — maven, gradle, ant, python, node, go, rust, dotnet,
|
|
81
81
|
cpp, swift, flutter — and computes a readiness score with hard caps and visible provenance.
|
|
82
82
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andresmassello/uscha",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.75.0",
|
|
4
4
|
"description": "Spec-driven development for LLM coding agents: 9 skills + a stdlib evidence engine. Facts block, guesses advise; the human approves.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Andres Massello",
|
|
@@ -5298,6 +5298,362 @@ def cmd_compile_ingest(args):
|
|
|
5298
5298
|
sys.exit(0)
|
|
5299
5299
|
|
|
5300
5300
|
|
|
5301
|
+
# --------------------------------------------------------------------------- #
|
|
5302
|
+
# bootstrap (Diamond M4: a bounded subsystem's identity is carried by its
|
|
5303
|
+
# canonical package + a WITHHELD oracle, not by its implementation. The oracle
|
|
5304
|
+
# runner is a measured fact and decides "same system"; variance is advisory
|
|
5305
|
+
# evidence that the implementations genuinely differ. ADR-017.)
|
|
5306
|
+
# --------------------------------------------------------------------------- #
|
|
5307
|
+
_BOOTSTRAP_CASE_TIMEOUT = 15 # a compiled hook must decide fast
|
|
5308
|
+
|
|
5309
|
+
|
|
5310
|
+
def _run_oracle_case(impl_path, case):
|
|
5311
|
+
"""Run ONE withheld oracle case against a compiled implementation: feed the case's stdin
|
|
5312
|
+
(raw_stdin verbatim if present, else json.dumps(payload)) to `python <impl>`, and check its
|
|
5313
|
+
result against whichever expectations the case declares. Deterministic execution -- the
|
|
5314
|
+
oracle is a `measured` fact, never an LLM judgment. Returns a per-case result dict.
|
|
5315
|
+
|
|
5316
|
+
A case may assert any of: `expected_exit` (process exit code -- the M4 guard's contract),
|
|
5317
|
+
`expected_stdout` (the program's stdout, compared stripped -- for archetypes that COMPUTE an
|
|
5318
|
+
output, e.g. a parser or transformer), and `expected_json` (stdout parsed as JSON and
|
|
5319
|
+
compared structurally, so an output whose formatting is free but whose value is fixed is not
|
|
5320
|
+
penalised for whitespace or key order). The case passes iff EVERY declared expectation holds;
|
|
5321
|
+
a case that declares none proves nothing and fails."""
|
|
5322
|
+
if "raw_stdin" in case:
|
|
5323
|
+
stdin = case["raw_stdin"]
|
|
5324
|
+
else:
|
|
5325
|
+
stdin = json.dumps(case.get("payload"))
|
|
5326
|
+
try:
|
|
5327
|
+
r = subprocess.run([sys.executable, impl_path], input=stdin, capture_output=True,
|
|
5328
|
+
text=True, encoding="utf-8", errors="replace",
|
|
5329
|
+
timeout=_BOOTSTRAP_CASE_TIMEOUT)
|
|
5330
|
+
got, out, err = r.returncode, r.stdout, None
|
|
5331
|
+
except subprocess.TimeoutExpired:
|
|
5332
|
+
got, out, err = None, "", "timeout"
|
|
5333
|
+
except OSError as exc:
|
|
5334
|
+
got, out, err = None, "", "could not run impl: %s" % exc
|
|
5335
|
+
want = case.get("expected_exit")
|
|
5336
|
+
asserted = [k for k in ("expected_exit", "expected_stdout", "expected_json") if k in case]
|
|
5337
|
+
ok = err is None and bool(asserted)
|
|
5338
|
+
if ok and "expected_exit" in case:
|
|
5339
|
+
ok = got == want
|
|
5340
|
+
if ok and "expected_stdout" in case:
|
|
5341
|
+
ok = (out or "").strip() == str(case["expected_stdout"]).strip()
|
|
5342
|
+
if ok and "expected_json" in case:
|
|
5343
|
+
try:
|
|
5344
|
+
ok = json.loads(out) == case["expected_json"]
|
|
5345
|
+
except (ValueError, TypeError):
|
|
5346
|
+
ok = False
|
|
5347
|
+
return {"name": case.get("name"), "expected": want, "got": got, "ok": ok, "error": err}
|
|
5348
|
+
|
|
5349
|
+
|
|
5350
|
+
def cmd_bootstrap_oracle(args):
|
|
5351
|
+
"""Run a WITHHELD oracle suite (ADR-017) against a compiled implementation. The oracle
|
|
5352
|
+
predates and is physically separate from every compiler input; this runner is the
|
|
5353
|
+
maker!=checker wall made executable. Exit 0 iff every case matches its expected exit,
|
|
5354
|
+
else 1 -- a measured behavioural fact about whether this implementation is the same
|
|
5355
|
+
system. It runs the implementation as a subprocess and consults no model."""
|
|
5356
|
+
try:
|
|
5357
|
+
with open(args.oracle, encoding="utf-8-sig") as fh:
|
|
5358
|
+
oracle = json.load(fh)
|
|
5359
|
+
except (OSError, ValueError) as exc:
|
|
5360
|
+
print("[qa_ledger] bootstrap-oracle: unreadable oracle %s: %s" % (args.oracle, exc),
|
|
5361
|
+
file=sys.stderr)
|
|
5362
|
+
sys.exit(2)
|
|
5363
|
+
cases = oracle.get("cases")
|
|
5364
|
+
if not isinstance(cases, list) or not cases:
|
|
5365
|
+
print("[qa_ledger] bootstrap-oracle: oracle has no cases", file=sys.stderr)
|
|
5366
|
+
sys.exit(2)
|
|
5367
|
+
if not os.path.isfile(args.impl):
|
|
5368
|
+
print("[qa_ledger] bootstrap-oracle: no implementation at %s" % args.impl,
|
|
5369
|
+
file=sys.stderr)
|
|
5370
|
+
sys.exit(2)
|
|
5371
|
+
results = [_run_oracle_case(args.impl, c) for c in cases]
|
|
5372
|
+
passed = sum(1 for r in results if r["ok"])
|
|
5373
|
+
failed = [r for r in results if not r["ok"]]
|
|
5374
|
+
report = {"impl": args.impl, "oracle": args.oracle, "total": len(results),
|
|
5375
|
+
"passed": passed, "failed": len(failed),
|
|
5376
|
+
"oracle_green": not failed, "results": results}
|
|
5377
|
+
if args.ledger and args.repo:
|
|
5378
|
+
ledger = _load(args.ledger)
|
|
5379
|
+
_repo_node(ledger, args.repo)
|
|
5380
|
+
rec = {"impl": os.path.basename(args.impl), "oracle": os.path.basename(args.oracle),
|
|
5381
|
+
"total": len(results), "passed": passed, "failed": len(failed),
|
|
5382
|
+
"oracle_green": not failed,
|
|
5383
|
+
"failing": [r["name"] for r in failed], "at": _now()}
|
|
5384
|
+
ledger.setdefault("bootstrap_oracle", []).append(rec)
|
|
5385
|
+
_save(args.ledger, ledger)
|
|
5386
|
+
if args.json:
|
|
5387
|
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
|
5388
|
+
else:
|
|
5389
|
+
print("BOOTSTRAP-ORACLE %s: %d/%d cases pass -- %s"
|
|
5390
|
+
% (os.path.basename(args.impl), passed, len(results),
|
|
5391
|
+
"ORACLE GREEN (same system on this suite)" if not failed
|
|
5392
|
+
else "ORACLE RED (%d divergence(s))" % len(failed)))
|
|
5393
|
+
for r in failed:
|
|
5394
|
+
print(" x %s: expected exit %s, got %s%s"
|
|
5395
|
+
% (r["name"], r["expected"], r["got"],
|
|
5396
|
+
" (%s)" % r["error"] if r["error"] else ""))
|
|
5397
|
+
sys.exit(0 if not failed else 1)
|
|
5398
|
+
|
|
5399
|
+
|
|
5400
|
+
def _impl_metrics(path):
|
|
5401
|
+
"""Structural fingerprint of one implementation: physical LOC, AST node count, function
|
|
5402
|
+
and class counts, and the set of imported top-level modules. Deterministic; no judgment."""
|
|
5403
|
+
try:
|
|
5404
|
+
with open(path, encoding="utf-8", errors="replace") as fh:
|
|
5405
|
+
src = fh.read()
|
|
5406
|
+
except OSError as exc:
|
|
5407
|
+
return {"path": path, "error": "unreadable: %s" % exc}
|
|
5408
|
+
loc = sum(1 for ln in src.splitlines() if ln.strip())
|
|
5409
|
+
try:
|
|
5410
|
+
tree = ast.parse(src)
|
|
5411
|
+
except SyntaxError as exc:
|
|
5412
|
+
return {"path": path, "loc": loc, "error": "unparseable: %s" % exc}
|
|
5413
|
+
funcs = classes = nodes = 0
|
|
5414
|
+
imports = set()
|
|
5415
|
+
for nd in ast.walk(tree):
|
|
5416
|
+
nodes += 1
|
|
5417
|
+
if isinstance(nd, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
5418
|
+
funcs += 1
|
|
5419
|
+
elif isinstance(nd, ast.ClassDef):
|
|
5420
|
+
classes += 1
|
|
5421
|
+
elif isinstance(nd, ast.Import):
|
|
5422
|
+
for a in nd.names:
|
|
5423
|
+
imports.add(a.name.split(".")[0])
|
|
5424
|
+
elif isinstance(nd, ast.ImportFrom):
|
|
5425
|
+
if nd.module:
|
|
5426
|
+
imports.add(nd.module.split(".")[0])
|
|
5427
|
+
return {"path": path, "loc": loc, "ast_nodes": nodes, "functions": funcs,
|
|
5428
|
+
"classes": classes, "imports": sorted(imports),
|
|
5429
|
+
"sha256": hashlib.sha256(src.encode("utf-8")).hexdigest()}
|
|
5430
|
+
|
|
5431
|
+
|
|
5432
|
+
def cmd_bootstrap_variance(args):
|
|
5433
|
+
"""Prove independent compilations of the same canonical package genuinely DIFFER (ADR-017).
|
|
5434
|
+
Reports per-implementation structural metrics and pairwise divergence. ADVISORY: variance
|
|
5435
|
+
is evidence the implementations differ, never a certificate of 'same system' (only the
|
|
5436
|
+
oracle certifies that) and never a gate -- it cannot change an exit code."""
|
|
5437
|
+
metrics = [_impl_metrics(p) for p in args.impls]
|
|
5438
|
+
pairs = []
|
|
5439
|
+
good = [m for m in metrics if "error" not in m]
|
|
5440
|
+
for i in range(len(good)):
|
|
5441
|
+
for j in range(i + 1, len(good)):
|
|
5442
|
+
a, b = good[i], good[j]
|
|
5443
|
+
ia, ib = set(a["imports"]), set(b["imports"])
|
|
5444
|
+
jac = (len(ia & ib) / len(ia | ib)) if (ia or ib) else 1.0
|
|
5445
|
+
pairs.append({"a": os.path.basename(a["path"]), "b": os.path.basename(b["path"]),
|
|
5446
|
+
"byte_identical": a["sha256"] == b["sha256"],
|
|
5447
|
+
"loc_delta": abs(a["loc"] - b["loc"]),
|
|
5448
|
+
"ast_node_delta": abs(a["ast_nodes"] - b["ast_nodes"]),
|
|
5449
|
+
"function_delta": abs(a["functions"] - b["functions"]),
|
|
5450
|
+
"import_jaccard": round(jac, 3)})
|
|
5451
|
+
all_distinct = all(not p["byte_identical"] for p in pairs) if pairs else None
|
|
5452
|
+
report = {"implementations": metrics, "pairs": pairs, "all_distinct": all_distinct,
|
|
5453
|
+
"advisory": True}
|
|
5454
|
+
if args.json:
|
|
5455
|
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
|
5456
|
+
else:
|
|
5457
|
+
for m in metrics:
|
|
5458
|
+
if "error" in m:
|
|
5459
|
+
print("VARIANCE %s: %s" % (os.path.basename(m["path"]), m["error"]))
|
|
5460
|
+
else:
|
|
5461
|
+
print("VARIANCE %s: %d loc, %d ast-nodes, %d fn, %d cls, imports=%s"
|
|
5462
|
+
% (os.path.basename(m["path"]), m["loc"], m["ast_nodes"],
|
|
5463
|
+
m["functions"], m["classes"], ",".join(m["imports"]) or "-"))
|
|
5464
|
+
for p in pairs:
|
|
5465
|
+
print(" %s vs %s: %s | dloc=%d dnodes=%d import_jaccard=%.2f"
|
|
5466
|
+
% (p["a"], p["b"], "IDENTICAL" if p["byte_identical"] else "distinct",
|
|
5467
|
+
p["loc_delta"], p["ast_node_delta"], p["import_jaccard"]))
|
|
5468
|
+
if all_distinct is not None:
|
|
5469
|
+
print(" all implementations distinct: %s (advisory, never gates)"
|
|
5470
|
+
% ("yes" if all_distinct else "NO -- convergence, a weak result"))
|
|
5471
|
+
sys.exit(0)
|
|
5472
|
+
|
|
5473
|
+
|
|
5474
|
+
# --------------------------------------------------------------------------- #
|
|
5475
|
+
# bench (Diamond M5: the Diamond Bench aggregates the M3/M4 primitives over a
|
|
5476
|
+
# set of bounded systems and emits a per-archetype verdict table. It measures
|
|
5477
|
+
# REGENERATION FIDELITY of canonical representations, not "which model codes
|
|
5478
|
+
# better" -- model identities are anonymized in the headline. Deterministic, no
|
|
5479
|
+
# LLM. ADR-018.)
|
|
5480
|
+
# --------------------------------------------------------------------------- #
|
|
5481
|
+
# min oracle pass-rate for a non-green compilation to still count as PARTIAL (core identity).
|
|
5482
|
+
_BENCH_PARTIAL_FLOOR = 0.8
|
|
5483
|
+
|
|
5484
|
+
|
|
5485
|
+
def _bench_oracle_all(impl_path, cases):
|
|
5486
|
+
results = [_run_oracle_case(impl_path, c) for c in cases]
|
|
5487
|
+
passed = sum(1 for r in results if r["ok"])
|
|
5488
|
+
return {"passed": passed, "total": len(results), "green": passed == len(results),
|
|
5489
|
+
"failing": [r["name"] for r in results if not r["ok"]]}
|
|
5490
|
+
|
|
5491
|
+
|
|
5492
|
+
def _bench_entry(entry_dir, name):
|
|
5493
|
+
"""Run compile-validate + the withheld oracle + variance over ONE bench entry and compute
|
|
5494
|
+
its verdict. Reuses the M3/M4 organs unchanged; consults no model. A PASS is >=3 oracle-green
|
|
5495
|
+
compilations that genuinely differ; PARTIAL is core identity with the divergence isolated;
|
|
5496
|
+
FAIL is no green, convergence to near-identical code, or an oracle a degenerate stub can
|
|
5497
|
+
satisfy (non-discriminating); PENDING is an entry not yet fully compiled."""
|
|
5498
|
+
ir_graph, ir_errors = _load_ir_at(os.path.join(entry_dir, IR_FILE))
|
|
5499
|
+
try:
|
|
5500
|
+
with open(os.path.join(entry_dir, "oracle", "ORACLE.json"), encoding="utf-8-sig") as fh:
|
|
5501
|
+
cases = (json.load(fh) or {}).get("cases") or []
|
|
5502
|
+
except (OSError, ValueError):
|
|
5503
|
+
cases = []
|
|
5504
|
+
rec = {"archetype": name, "oracle_cases": len(cases), "compilations": [],
|
|
5505
|
+
"variance": None, "discrimination": None, "verdict": "PENDING", "reason": None}
|
|
5506
|
+
if ir_graph is None or ir_errors or not cases:
|
|
5507
|
+
rec["reason"] = "entry incomplete (missing/invalid IR or oracle)"
|
|
5508
|
+
return rec
|
|
5509
|
+
comp_dirs = sorted(d for d in os.listdir(entry_dir)
|
|
5510
|
+
if d.startswith("c-") and
|
|
5511
|
+
os.path.isfile(os.path.join(entry_dir, d, "COMPILATION.json")))
|
|
5512
|
+
for d in comp_dirs:
|
|
5513
|
+
cd = os.path.join(entry_dir, d)
|
|
5514
|
+
cj = os.path.join(cd, "COMPILATION.json")
|
|
5515
|
+
errors, _adv = _validate_compilation(cj, ir_graph)
|
|
5516
|
+
unit, model = None, None
|
|
5517
|
+
try:
|
|
5518
|
+
with open(cj, encoding="utf-8-sig") as fh:
|
|
5519
|
+
c = json.load(fh)
|
|
5520
|
+
src = c.get("source") or []
|
|
5521
|
+
unit = src[0].get("unit") if src else None
|
|
5522
|
+
model = (c.get("compilation_report") or {}).get("model")
|
|
5523
|
+
except (OSError, ValueError, AttributeError, IndexError):
|
|
5524
|
+
pass
|
|
5525
|
+
impl = os.path.join(cd, unit.replace("/", os.sep)) if unit else None
|
|
5526
|
+
ores = (_bench_oracle_all(impl, cases) if impl and os.path.isfile(impl)
|
|
5527
|
+
else {"passed": 0, "total": len(cases), "green": False, "failing": ["<no impl>"]})
|
|
5528
|
+
rec["compilations"].append({"dir": d, "model": model, "impl": impl,
|
|
5529
|
+
"compile_valid": not errors, "oracle": ores})
|
|
5530
|
+
impls = rec["compilations"]
|
|
5531
|
+
impl_paths = [i["impl"] for i in impls if i["impl"] and os.path.isfile(i["impl"])]
|
|
5532
|
+
if len(impl_paths) >= 2:
|
|
5533
|
+
metrics = [_impl_metrics(p) for p in impl_paths]
|
|
5534
|
+
shas = [m.get("sha256") for m in metrics if "error" not in m and m.get("sha256")]
|
|
5535
|
+
rec["variance"] = {"all_distinct": len(set(shas)) == len(shas) and len(shas) >= 2,
|
|
5536
|
+
"metrics": metrics}
|
|
5537
|
+
stub_dir = os.path.join(entry_dir, "stub")
|
|
5538
|
+
stub_green = False
|
|
5539
|
+
if os.path.isdir(stub_dir):
|
|
5540
|
+
stubs = sorted(f for f in os.listdir(stub_dir) if f.endswith(".py"))
|
|
5541
|
+
if stubs:
|
|
5542
|
+
sres = _bench_oracle_all(os.path.join(stub_dir, stubs[0]), cases)
|
|
5543
|
+
stub_green = sres["green"]
|
|
5544
|
+
rec["discrimination"] = {"stub_passed": sres["passed"], "total": sres["total"],
|
|
5545
|
+
"stub_green": stub_green}
|
|
5546
|
+
n = len(impls)
|
|
5547
|
+
if n == 0:
|
|
5548
|
+
rec["reason"] = "no compilations yet"
|
|
5549
|
+
return rec # PENDING
|
|
5550
|
+
all_valid = all(i["compile_valid"] for i in impls)
|
|
5551
|
+
greens = sum(1 for i in impls if i["oracle"]["green"])
|
|
5552
|
+
min_rate = min((i["oracle"]["passed"] / i["oracle"]["total"]) if i["oracle"]["total"]
|
|
5553
|
+
else 0.0 for i in impls)
|
|
5554
|
+
distinct = rec["variance"]["all_distinct"] if rec["variance"] else (n == 1)
|
|
5555
|
+
if stub_green:
|
|
5556
|
+
rec["verdict"], rec["reason"] = "FAIL", ("oracle satisfied by a degenerate stub -- not "
|
|
5557
|
+
"discriminating; the entry proves nothing")
|
|
5558
|
+
elif not all_valid:
|
|
5559
|
+
rec["verdict"], rec["reason"] = "FAIL", "a compilation does not validate against the pinned IR"
|
|
5560
|
+
elif n < 3:
|
|
5561
|
+
rec["verdict"], rec["reason"] = "PENDING", "fewer than 3 compilations (have %d)" % n
|
|
5562
|
+
elif not distinct:
|
|
5563
|
+
rec["verdict"], rec["reason"] = "FAIL", ("implementations converged to a byte-identical "
|
|
5564
|
+
"pair -- a disguised implementation")
|
|
5565
|
+
elif greens == n:
|
|
5566
|
+
rec["verdict"], rec["reason"] = "PASS", ("all %d compilations oracle-green and genuinely "
|
|
5567
|
+
"different -- the same system" % n)
|
|
5568
|
+
elif min_rate >= _BENCH_PARTIAL_FLOOR:
|
|
5569
|
+
rec["verdict"], rec["reason"] = "PARTIAL", ("core identity (min %.0f%% of cases); "
|
|
5570
|
+
"divergence isolated" % (min_rate * 100))
|
|
5571
|
+
else:
|
|
5572
|
+
rec["verdict"], rec["reason"] = "FAIL", ("a compilation below the core-identity floor "
|
|
5573
|
+
"(min %.0f%%)" % (min_rate * 100))
|
|
5574
|
+
return rec
|
|
5575
|
+
|
|
5576
|
+
|
|
5577
|
+
def _render_bench_md(table, anon, recs):
|
|
5578
|
+
lines = ["<!-- GENERATED by qa_ledger.py bench (ADR-018) -- every number is a measured run; "
|
|
5579
|
+
"do not hand-edit. -->", "", "# DIAMOND-BENCH", "",
|
|
5580
|
+
"Regeneration fidelity of canonical representations across archetypes. Each row is a "
|
|
5581
|
+
"bounded system compiled blind by independent models through the M3 contract and "
|
|
5582
|
+
"judged by a WITHHELD oracle (M4). Model identities are anonymized here; the mapping "
|
|
5583
|
+
"is published below.", "",
|
|
5584
|
+
"| Archetype | Verdict | Compilers (oracle pass / total) | Distinct | Oracle cases |",
|
|
5585
|
+
"|-----------|---------|--------------------------------|----------|--------------|"]
|
|
5586
|
+
for t in table:
|
|
5587
|
+
dist = "—" if t["distinct"] is None else ("yes" if t["distinct"] else "NO")
|
|
5588
|
+
lines.append("| %s | %s | %s | %s | %d |" % (t["archetype"], t["verdict"],
|
|
5589
|
+
t["compilers"], dist, t["oracle_cases"]))
|
|
5590
|
+
counts = {}
|
|
5591
|
+
for t in table:
|
|
5592
|
+
counts[t["verdict"]] = counts.get(t["verdict"], 0) + 1
|
|
5593
|
+
lines += ["", "**Coverage:** " + ", ".join("%d %s" % (v, k) for k, v in sorted(counts.items()))
|
|
5594
|
+
+ " (of %d entries)." % len(table), "",
|
|
5595
|
+
"**Model map (published, not the headline):** "
|
|
5596
|
+
+ (", ".join("%s = %s" % (a, m) for m, a in sorted(anon.items(), key=lambda x: x[1]))
|
|
5597
|
+
or "none yet") + ".", "",
|
|
5598
|
+
"## Per-entry detail", ""]
|
|
5599
|
+
for r in recs:
|
|
5600
|
+
lines.append("### %s — %s" % (r["archetype"], r["verdict"]))
|
|
5601
|
+
lines.append("*%s*" % (r["reason"] or ""))
|
|
5602
|
+
if r["compilations"]:
|
|
5603
|
+
for i in r["compilations"]:
|
|
5604
|
+
lines.append("- `%s` (%s): oracle %d/%d%s%s" % (
|
|
5605
|
+
i["dir"], anon.get(i["model"], i["model"] or "?"),
|
|
5606
|
+
i["oracle"]["passed"], i["oracle"]["total"],
|
|
5607
|
+
" GREEN" if i["oracle"]["green"] else "",
|
|
5608
|
+
"" if i["compile_valid"] else " [does not compile-validate]"))
|
|
5609
|
+
if r["discrimination"]:
|
|
5610
|
+
dsc = r["discrimination"]
|
|
5611
|
+
lines.append("- discrimination stub: %d/%d (%s)" % (
|
|
5612
|
+
dsc["stub_passed"], dsc["total"],
|
|
5613
|
+
"NON-DISCRIMINATING" if dsc["stub_green"] else "oracle rejects the stub"))
|
|
5614
|
+
lines.append("")
|
|
5615
|
+
return "\n".join(lines)
|
|
5616
|
+
|
|
5617
|
+
|
|
5618
|
+
def cmd_bench(args):
|
|
5619
|
+
if not os.path.isdir(args.dir):
|
|
5620
|
+
print("[qa_ledger] bench: no directory %s" % args.dir, file=sys.stderr)
|
|
5621
|
+
sys.exit(2)
|
|
5622
|
+
entries = sorted(d for d in os.listdir(args.dir)
|
|
5623
|
+
if os.path.isfile(os.path.join(args.dir, d, IR_FILE)))
|
|
5624
|
+
if not entries:
|
|
5625
|
+
print("[qa_ledger] bench: no entries under %s (an entry is a subdir with %s)"
|
|
5626
|
+
% (args.dir, IR_FILE), file=sys.stderr)
|
|
5627
|
+
sys.exit(2)
|
|
5628
|
+
recs = [_bench_entry(os.path.join(args.dir, e), e) for e in entries]
|
|
5629
|
+
models = sorted({i["model"] for r in recs for i in r["compilations"] if i.get("model")})
|
|
5630
|
+
anon = {m: "M%d" % (k + 1) for k, m in enumerate(models)}
|
|
5631
|
+
table = []
|
|
5632
|
+
for r in recs:
|
|
5633
|
+
cols = ", ".join("%s %d/%d" % (anon.get(i["model"], "?"), i["oracle"]["passed"],
|
|
5634
|
+
i["oracle"]["total"]) for i in r["compilations"])
|
|
5635
|
+
table.append({"archetype": r["archetype"], "verdict": r["verdict"],
|
|
5636
|
+
"compilers": cols or "(none yet)",
|
|
5637
|
+
"distinct": (r["variance"] or {}).get("all_distinct"),
|
|
5638
|
+
"oracle_cases": r["oracle_cases"], "reason": r["reason"]})
|
|
5639
|
+
md = _render_bench_md(table, anon, recs)
|
|
5640
|
+
if args.out:
|
|
5641
|
+
with open(args.out, "w", encoding="utf-8", newline="\n") as fh:
|
|
5642
|
+
fh.write(md)
|
|
5643
|
+
if args.json:
|
|
5644
|
+
print(json.dumps({"entries": len(recs), "model_map": anon, "table": table,
|
|
5645
|
+
"raw": recs}, indent=2, ensure_ascii=False))
|
|
5646
|
+
else:
|
|
5647
|
+
print("BENCH: %d entries" % len(recs))
|
|
5648
|
+
for t in table:
|
|
5649
|
+
dist = "" if t["distinct"] is None else (" | distinct" if t["distinct"]
|
|
5650
|
+
else " | CONVERGED")
|
|
5651
|
+
print(" %-14s %-8s | %s%s" % (t["archetype"], t["verdict"], t["compilers"], dist))
|
|
5652
|
+
if args.out:
|
|
5653
|
+
print(" -> %s" % args.out)
|
|
5654
|
+
sys.exit(0)
|
|
5655
|
+
|
|
5656
|
+
|
|
5301
5657
|
# --------------------------------------------------------------------------- #
|
|
5302
5658
|
# facts (T0 / SYSTEM-FACTS: public claims become compiled artifacts of repo
|
|
5303
5659
|
# facts -- Diamond applied to Diamond. ADR-012.)
|
|
@@ -9390,6 +9746,37 @@ def build_parser():
|
|
|
9390
9746
|
pcmi.add_argument("--json", action="store_true")
|
|
9391
9747
|
pcmi.set_defaults(func=cmd_compile_ingest)
|
|
9392
9748
|
|
|
9749
|
+
pbo = sub.add_parser(
|
|
9750
|
+
"bootstrap-oracle",
|
|
9751
|
+
help="run a WITHHELD oracle suite against a compiled implementation (ADR-017); exit 0 "
|
|
9752
|
+
"iff every case matches its expected exit -- the maker!=checker wall, executable")
|
|
9753
|
+
pbo.add_argument("--impl", required=True, help="the compiled implementation to run")
|
|
9754
|
+
pbo.add_argument("--oracle", required=True, help="the withheld ORACLE.json case suite")
|
|
9755
|
+
pbo.add_argument("--ledger", default=None, help="optional: persist the measured result")
|
|
9756
|
+
pbo.add_argument("--repo", default=None, help="repo scope when --ledger is given")
|
|
9757
|
+
pbo.add_argument("--json", action="store_true")
|
|
9758
|
+
pbo.set_defaults(func=cmd_bootstrap_oracle)
|
|
9759
|
+
|
|
9760
|
+
pbv = sub.add_parser(
|
|
9761
|
+
"bootstrap-variance",
|
|
9762
|
+
help="structural metrics + pairwise divergence proving independent compilations "
|
|
9763
|
+
"genuinely differ (ADR-017); ADVISORY evidence, never a gate")
|
|
9764
|
+
pbv.add_argument("--impls", required=True, nargs="+",
|
|
9765
|
+
help="two or more compiled implementations to compare")
|
|
9766
|
+
pbv.add_argument("--json", action="store_true")
|
|
9767
|
+
pbv.set_defaults(func=cmd_bootstrap_variance)
|
|
9768
|
+
|
|
9769
|
+
pbn = sub.add_parser(
|
|
9770
|
+
"bench",
|
|
9771
|
+
help="the Diamond Bench (ADR-018): per-archetype verdict table over a set of bounded "
|
|
9772
|
+
"systems, aggregating compile-validate + bootstrap-oracle + bootstrap-variance; "
|
|
9773
|
+
"model identities anonymized in the headline; deterministic, no LLM")
|
|
9774
|
+
pbn.add_argument("--dir", required=True,
|
|
9775
|
+
help="the bench directory; each subdir with an IR.json is an entry")
|
|
9776
|
+
pbn.add_argument("--out", default=None, help="write DIAMOND-BENCH.md here")
|
|
9777
|
+
pbn.add_argument("--json", action="store_true")
|
|
9778
|
+
pbn.set_defaults(func=cmd_bench)
|
|
9779
|
+
|
|
9393
9780
|
pcr = sub.add_parser("cleanroom",
|
|
9394
9781
|
help="run a command against a CLEAN checkout of one commit in a throwaway worktree (ADR-008)")
|
|
9395
9782
|
pcr.add_argument("--ledger", default="QA-LEDGER.json")
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/claude-code-plugin-manifest.json",
|
|
3
3
|
"name": "uscha",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.75.0",
|
|
5
5
|
"displayName": "Uscha",
|
|
6
|
-
"description": "Spec-driven development for LLM coding agents: 9 skills (discovery, adr-refine, reverse-discovery, characterize, devloop, sysdoc, rubric, mirador, status) + a stdlib measurement engine (qa_ledger.py,
|
|
6
|
+
"description": "Spec-driven development for LLM coding agents: 9 skills (discovery, adr-refine, reverse-discovery, characterize, devloop, sysdoc, rubric, mirador, status) + a stdlib measurement engine (qa_ledger.py, 47 subcommands + universal installer + npm/npx router). Facts block, guesses advise; the human approves.",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Andres Massello",
|
|
9
9
|
"url": "https://github.com/andresmassello"
|
package/uscha-kit/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# uscha-kit
|
|
2
2
|
|
|
3
|
-
**Kit version:** v1.
|
|
3
|
+
**Kit version:** v1.75.0 <!-- uscha:version --> · **[uscha.dev](https://uscha.dev)**
|
|
4
4
|
|
|
5
5
|
Spec-driven orchestrator + multi-repo QA for Claude Code, with a deterministic ledger.
|
|
6
6
|
**Nine skills** (`uscha-discovery`, `uscha-adr-refine`, `uscha-devloop`, `uscha-sysdoc`, `uscha-reverse-discovery`,
|
package/uscha-kit/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
uscha-kit 1.
|
|
1
|
+
uscha-kit 1.75.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"AC-DB-01": true, "AC-DB-02": true, "AC-DB-03": true, "AC-DB-05": true, "AC-DB-04": true, "AC-DB-06": true}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"AC-BS-01": true, "AC-BS-02": true, "AC-BS-03": true, "AC-BS-04": true, "AC-BS-05": true, "AC-BS-06": true}
|
|
@@ -5298,6 +5298,362 @@ def cmd_compile_ingest(args):
|
|
|
5298
5298
|
sys.exit(0)
|
|
5299
5299
|
|
|
5300
5300
|
|
|
5301
|
+
# --------------------------------------------------------------------------- #
|
|
5302
|
+
# bootstrap (Diamond M4: a bounded subsystem's identity is carried by its
|
|
5303
|
+
# canonical package + a WITHHELD oracle, not by its implementation. The oracle
|
|
5304
|
+
# runner is a measured fact and decides "same system"; variance is advisory
|
|
5305
|
+
# evidence that the implementations genuinely differ. ADR-017.)
|
|
5306
|
+
# --------------------------------------------------------------------------- #
|
|
5307
|
+
_BOOTSTRAP_CASE_TIMEOUT = 15 # a compiled hook must decide fast
|
|
5308
|
+
|
|
5309
|
+
|
|
5310
|
+
def _run_oracle_case(impl_path, case):
|
|
5311
|
+
"""Run ONE withheld oracle case against a compiled implementation: feed the case's stdin
|
|
5312
|
+
(raw_stdin verbatim if present, else json.dumps(payload)) to `python <impl>`, and check its
|
|
5313
|
+
result against whichever expectations the case declares. Deterministic execution -- the
|
|
5314
|
+
oracle is a `measured` fact, never an LLM judgment. Returns a per-case result dict.
|
|
5315
|
+
|
|
5316
|
+
A case may assert any of: `expected_exit` (process exit code -- the M4 guard's contract),
|
|
5317
|
+
`expected_stdout` (the program's stdout, compared stripped -- for archetypes that COMPUTE an
|
|
5318
|
+
output, e.g. a parser or transformer), and `expected_json` (stdout parsed as JSON and
|
|
5319
|
+
compared structurally, so an output whose formatting is free but whose value is fixed is not
|
|
5320
|
+
penalised for whitespace or key order). The case passes iff EVERY declared expectation holds;
|
|
5321
|
+
a case that declares none proves nothing and fails."""
|
|
5322
|
+
if "raw_stdin" in case:
|
|
5323
|
+
stdin = case["raw_stdin"]
|
|
5324
|
+
else:
|
|
5325
|
+
stdin = json.dumps(case.get("payload"))
|
|
5326
|
+
try:
|
|
5327
|
+
r = subprocess.run([sys.executable, impl_path], input=stdin, capture_output=True,
|
|
5328
|
+
text=True, encoding="utf-8", errors="replace",
|
|
5329
|
+
timeout=_BOOTSTRAP_CASE_TIMEOUT)
|
|
5330
|
+
got, out, err = r.returncode, r.stdout, None
|
|
5331
|
+
except subprocess.TimeoutExpired:
|
|
5332
|
+
got, out, err = None, "", "timeout"
|
|
5333
|
+
except OSError as exc:
|
|
5334
|
+
got, out, err = None, "", "could not run impl: %s" % exc
|
|
5335
|
+
want = case.get("expected_exit")
|
|
5336
|
+
asserted = [k for k in ("expected_exit", "expected_stdout", "expected_json") if k in case]
|
|
5337
|
+
ok = err is None and bool(asserted)
|
|
5338
|
+
if ok and "expected_exit" in case:
|
|
5339
|
+
ok = got == want
|
|
5340
|
+
if ok and "expected_stdout" in case:
|
|
5341
|
+
ok = (out or "").strip() == str(case["expected_stdout"]).strip()
|
|
5342
|
+
if ok and "expected_json" in case:
|
|
5343
|
+
try:
|
|
5344
|
+
ok = json.loads(out) == case["expected_json"]
|
|
5345
|
+
except (ValueError, TypeError):
|
|
5346
|
+
ok = False
|
|
5347
|
+
return {"name": case.get("name"), "expected": want, "got": got, "ok": ok, "error": err}
|
|
5348
|
+
|
|
5349
|
+
|
|
5350
|
+
def cmd_bootstrap_oracle(args):
|
|
5351
|
+
"""Run a WITHHELD oracle suite (ADR-017) against a compiled implementation. The oracle
|
|
5352
|
+
predates and is physically separate from every compiler input; this runner is the
|
|
5353
|
+
maker!=checker wall made executable. Exit 0 iff every case matches its expected exit,
|
|
5354
|
+
else 1 -- a measured behavioural fact about whether this implementation is the same
|
|
5355
|
+
system. It runs the implementation as a subprocess and consults no model."""
|
|
5356
|
+
try:
|
|
5357
|
+
with open(args.oracle, encoding="utf-8-sig") as fh:
|
|
5358
|
+
oracle = json.load(fh)
|
|
5359
|
+
except (OSError, ValueError) as exc:
|
|
5360
|
+
print("[qa_ledger] bootstrap-oracle: unreadable oracle %s: %s" % (args.oracle, exc),
|
|
5361
|
+
file=sys.stderr)
|
|
5362
|
+
sys.exit(2)
|
|
5363
|
+
cases = oracle.get("cases")
|
|
5364
|
+
if not isinstance(cases, list) or not cases:
|
|
5365
|
+
print("[qa_ledger] bootstrap-oracle: oracle has no cases", file=sys.stderr)
|
|
5366
|
+
sys.exit(2)
|
|
5367
|
+
if not os.path.isfile(args.impl):
|
|
5368
|
+
print("[qa_ledger] bootstrap-oracle: no implementation at %s" % args.impl,
|
|
5369
|
+
file=sys.stderr)
|
|
5370
|
+
sys.exit(2)
|
|
5371
|
+
results = [_run_oracle_case(args.impl, c) for c in cases]
|
|
5372
|
+
passed = sum(1 for r in results if r["ok"])
|
|
5373
|
+
failed = [r for r in results if not r["ok"]]
|
|
5374
|
+
report = {"impl": args.impl, "oracle": args.oracle, "total": len(results),
|
|
5375
|
+
"passed": passed, "failed": len(failed),
|
|
5376
|
+
"oracle_green": not failed, "results": results}
|
|
5377
|
+
if args.ledger and args.repo:
|
|
5378
|
+
ledger = _load(args.ledger)
|
|
5379
|
+
_repo_node(ledger, args.repo)
|
|
5380
|
+
rec = {"impl": os.path.basename(args.impl), "oracle": os.path.basename(args.oracle),
|
|
5381
|
+
"total": len(results), "passed": passed, "failed": len(failed),
|
|
5382
|
+
"oracle_green": not failed,
|
|
5383
|
+
"failing": [r["name"] for r in failed], "at": _now()}
|
|
5384
|
+
ledger.setdefault("bootstrap_oracle", []).append(rec)
|
|
5385
|
+
_save(args.ledger, ledger)
|
|
5386
|
+
if args.json:
|
|
5387
|
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
|
5388
|
+
else:
|
|
5389
|
+
print("BOOTSTRAP-ORACLE %s: %d/%d cases pass -- %s"
|
|
5390
|
+
% (os.path.basename(args.impl), passed, len(results),
|
|
5391
|
+
"ORACLE GREEN (same system on this suite)" if not failed
|
|
5392
|
+
else "ORACLE RED (%d divergence(s))" % len(failed)))
|
|
5393
|
+
for r in failed:
|
|
5394
|
+
print(" x %s: expected exit %s, got %s%s"
|
|
5395
|
+
% (r["name"], r["expected"], r["got"],
|
|
5396
|
+
" (%s)" % r["error"] if r["error"] else ""))
|
|
5397
|
+
sys.exit(0 if not failed else 1)
|
|
5398
|
+
|
|
5399
|
+
|
|
5400
|
+
def _impl_metrics(path):
|
|
5401
|
+
"""Structural fingerprint of one implementation: physical LOC, AST node count, function
|
|
5402
|
+
and class counts, and the set of imported top-level modules. Deterministic; no judgment."""
|
|
5403
|
+
try:
|
|
5404
|
+
with open(path, encoding="utf-8", errors="replace") as fh:
|
|
5405
|
+
src = fh.read()
|
|
5406
|
+
except OSError as exc:
|
|
5407
|
+
return {"path": path, "error": "unreadable: %s" % exc}
|
|
5408
|
+
loc = sum(1 for ln in src.splitlines() if ln.strip())
|
|
5409
|
+
try:
|
|
5410
|
+
tree = ast.parse(src)
|
|
5411
|
+
except SyntaxError as exc:
|
|
5412
|
+
return {"path": path, "loc": loc, "error": "unparseable: %s" % exc}
|
|
5413
|
+
funcs = classes = nodes = 0
|
|
5414
|
+
imports = set()
|
|
5415
|
+
for nd in ast.walk(tree):
|
|
5416
|
+
nodes += 1
|
|
5417
|
+
if isinstance(nd, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
5418
|
+
funcs += 1
|
|
5419
|
+
elif isinstance(nd, ast.ClassDef):
|
|
5420
|
+
classes += 1
|
|
5421
|
+
elif isinstance(nd, ast.Import):
|
|
5422
|
+
for a in nd.names:
|
|
5423
|
+
imports.add(a.name.split(".")[0])
|
|
5424
|
+
elif isinstance(nd, ast.ImportFrom):
|
|
5425
|
+
if nd.module:
|
|
5426
|
+
imports.add(nd.module.split(".")[0])
|
|
5427
|
+
return {"path": path, "loc": loc, "ast_nodes": nodes, "functions": funcs,
|
|
5428
|
+
"classes": classes, "imports": sorted(imports),
|
|
5429
|
+
"sha256": hashlib.sha256(src.encode("utf-8")).hexdigest()}
|
|
5430
|
+
|
|
5431
|
+
|
|
5432
|
+
def cmd_bootstrap_variance(args):
|
|
5433
|
+
"""Prove independent compilations of the same canonical package genuinely DIFFER (ADR-017).
|
|
5434
|
+
Reports per-implementation structural metrics and pairwise divergence. ADVISORY: variance
|
|
5435
|
+
is evidence the implementations differ, never a certificate of 'same system' (only the
|
|
5436
|
+
oracle certifies that) and never a gate -- it cannot change an exit code."""
|
|
5437
|
+
metrics = [_impl_metrics(p) for p in args.impls]
|
|
5438
|
+
pairs = []
|
|
5439
|
+
good = [m for m in metrics if "error" not in m]
|
|
5440
|
+
for i in range(len(good)):
|
|
5441
|
+
for j in range(i + 1, len(good)):
|
|
5442
|
+
a, b = good[i], good[j]
|
|
5443
|
+
ia, ib = set(a["imports"]), set(b["imports"])
|
|
5444
|
+
jac = (len(ia & ib) / len(ia | ib)) if (ia or ib) else 1.0
|
|
5445
|
+
pairs.append({"a": os.path.basename(a["path"]), "b": os.path.basename(b["path"]),
|
|
5446
|
+
"byte_identical": a["sha256"] == b["sha256"],
|
|
5447
|
+
"loc_delta": abs(a["loc"] - b["loc"]),
|
|
5448
|
+
"ast_node_delta": abs(a["ast_nodes"] - b["ast_nodes"]),
|
|
5449
|
+
"function_delta": abs(a["functions"] - b["functions"]),
|
|
5450
|
+
"import_jaccard": round(jac, 3)})
|
|
5451
|
+
all_distinct = all(not p["byte_identical"] for p in pairs) if pairs else None
|
|
5452
|
+
report = {"implementations": metrics, "pairs": pairs, "all_distinct": all_distinct,
|
|
5453
|
+
"advisory": True}
|
|
5454
|
+
if args.json:
|
|
5455
|
+
print(json.dumps(report, indent=2, ensure_ascii=False))
|
|
5456
|
+
else:
|
|
5457
|
+
for m in metrics:
|
|
5458
|
+
if "error" in m:
|
|
5459
|
+
print("VARIANCE %s: %s" % (os.path.basename(m["path"]), m["error"]))
|
|
5460
|
+
else:
|
|
5461
|
+
print("VARIANCE %s: %d loc, %d ast-nodes, %d fn, %d cls, imports=%s"
|
|
5462
|
+
% (os.path.basename(m["path"]), m["loc"], m["ast_nodes"],
|
|
5463
|
+
m["functions"], m["classes"], ",".join(m["imports"]) or "-"))
|
|
5464
|
+
for p in pairs:
|
|
5465
|
+
print(" %s vs %s: %s | dloc=%d dnodes=%d import_jaccard=%.2f"
|
|
5466
|
+
% (p["a"], p["b"], "IDENTICAL" if p["byte_identical"] else "distinct",
|
|
5467
|
+
p["loc_delta"], p["ast_node_delta"], p["import_jaccard"]))
|
|
5468
|
+
if all_distinct is not None:
|
|
5469
|
+
print(" all implementations distinct: %s (advisory, never gates)"
|
|
5470
|
+
% ("yes" if all_distinct else "NO -- convergence, a weak result"))
|
|
5471
|
+
sys.exit(0)
|
|
5472
|
+
|
|
5473
|
+
|
|
5474
|
+
# --------------------------------------------------------------------------- #
|
|
5475
|
+
# bench (Diamond M5: the Diamond Bench aggregates the M3/M4 primitives over a
|
|
5476
|
+
# set of bounded systems and emits a per-archetype verdict table. It measures
|
|
5477
|
+
# REGENERATION FIDELITY of canonical representations, not "which model codes
|
|
5478
|
+
# better" -- model identities are anonymized in the headline. Deterministic, no
|
|
5479
|
+
# LLM. ADR-018.)
|
|
5480
|
+
# --------------------------------------------------------------------------- #
|
|
5481
|
+
# min oracle pass-rate for a non-green compilation to still count as PARTIAL (core identity).
|
|
5482
|
+
_BENCH_PARTIAL_FLOOR = 0.8
|
|
5483
|
+
|
|
5484
|
+
|
|
5485
|
+
def _bench_oracle_all(impl_path, cases):
|
|
5486
|
+
results = [_run_oracle_case(impl_path, c) for c in cases]
|
|
5487
|
+
passed = sum(1 for r in results if r["ok"])
|
|
5488
|
+
return {"passed": passed, "total": len(results), "green": passed == len(results),
|
|
5489
|
+
"failing": [r["name"] for r in results if not r["ok"]]}
|
|
5490
|
+
|
|
5491
|
+
|
|
5492
|
+
def _bench_entry(entry_dir, name):
|
|
5493
|
+
"""Run compile-validate + the withheld oracle + variance over ONE bench entry and compute
|
|
5494
|
+
its verdict. Reuses the M3/M4 organs unchanged; consults no model. A PASS is >=3 oracle-green
|
|
5495
|
+
compilations that genuinely differ; PARTIAL is core identity with the divergence isolated;
|
|
5496
|
+
FAIL is no green, convergence to near-identical code, or an oracle a degenerate stub can
|
|
5497
|
+
satisfy (non-discriminating); PENDING is an entry not yet fully compiled."""
|
|
5498
|
+
ir_graph, ir_errors = _load_ir_at(os.path.join(entry_dir, IR_FILE))
|
|
5499
|
+
try:
|
|
5500
|
+
with open(os.path.join(entry_dir, "oracle", "ORACLE.json"), encoding="utf-8-sig") as fh:
|
|
5501
|
+
cases = (json.load(fh) or {}).get("cases") or []
|
|
5502
|
+
except (OSError, ValueError):
|
|
5503
|
+
cases = []
|
|
5504
|
+
rec = {"archetype": name, "oracle_cases": len(cases), "compilations": [],
|
|
5505
|
+
"variance": None, "discrimination": None, "verdict": "PENDING", "reason": None}
|
|
5506
|
+
if ir_graph is None or ir_errors or not cases:
|
|
5507
|
+
rec["reason"] = "entry incomplete (missing/invalid IR or oracle)"
|
|
5508
|
+
return rec
|
|
5509
|
+
comp_dirs = sorted(d for d in os.listdir(entry_dir)
|
|
5510
|
+
if d.startswith("c-") and
|
|
5511
|
+
os.path.isfile(os.path.join(entry_dir, d, "COMPILATION.json")))
|
|
5512
|
+
for d in comp_dirs:
|
|
5513
|
+
cd = os.path.join(entry_dir, d)
|
|
5514
|
+
cj = os.path.join(cd, "COMPILATION.json")
|
|
5515
|
+
errors, _adv = _validate_compilation(cj, ir_graph)
|
|
5516
|
+
unit, model = None, None
|
|
5517
|
+
try:
|
|
5518
|
+
with open(cj, encoding="utf-8-sig") as fh:
|
|
5519
|
+
c = json.load(fh)
|
|
5520
|
+
src = c.get("source") or []
|
|
5521
|
+
unit = src[0].get("unit") if src else None
|
|
5522
|
+
model = (c.get("compilation_report") or {}).get("model")
|
|
5523
|
+
except (OSError, ValueError, AttributeError, IndexError):
|
|
5524
|
+
pass
|
|
5525
|
+
impl = os.path.join(cd, unit.replace("/", os.sep)) if unit else None
|
|
5526
|
+
ores = (_bench_oracle_all(impl, cases) if impl and os.path.isfile(impl)
|
|
5527
|
+
else {"passed": 0, "total": len(cases), "green": False, "failing": ["<no impl>"]})
|
|
5528
|
+
rec["compilations"].append({"dir": d, "model": model, "impl": impl,
|
|
5529
|
+
"compile_valid": not errors, "oracle": ores})
|
|
5530
|
+
impls = rec["compilations"]
|
|
5531
|
+
impl_paths = [i["impl"] for i in impls if i["impl"] and os.path.isfile(i["impl"])]
|
|
5532
|
+
if len(impl_paths) >= 2:
|
|
5533
|
+
metrics = [_impl_metrics(p) for p in impl_paths]
|
|
5534
|
+
shas = [m.get("sha256") for m in metrics if "error" not in m and m.get("sha256")]
|
|
5535
|
+
rec["variance"] = {"all_distinct": len(set(shas)) == len(shas) and len(shas) >= 2,
|
|
5536
|
+
"metrics": metrics}
|
|
5537
|
+
stub_dir = os.path.join(entry_dir, "stub")
|
|
5538
|
+
stub_green = False
|
|
5539
|
+
if os.path.isdir(stub_dir):
|
|
5540
|
+
stubs = sorted(f for f in os.listdir(stub_dir) if f.endswith(".py"))
|
|
5541
|
+
if stubs:
|
|
5542
|
+
sres = _bench_oracle_all(os.path.join(stub_dir, stubs[0]), cases)
|
|
5543
|
+
stub_green = sres["green"]
|
|
5544
|
+
rec["discrimination"] = {"stub_passed": sres["passed"], "total": sres["total"],
|
|
5545
|
+
"stub_green": stub_green}
|
|
5546
|
+
n = len(impls)
|
|
5547
|
+
if n == 0:
|
|
5548
|
+
rec["reason"] = "no compilations yet"
|
|
5549
|
+
return rec # PENDING
|
|
5550
|
+
all_valid = all(i["compile_valid"] for i in impls)
|
|
5551
|
+
greens = sum(1 for i in impls if i["oracle"]["green"])
|
|
5552
|
+
min_rate = min((i["oracle"]["passed"] / i["oracle"]["total"]) if i["oracle"]["total"]
|
|
5553
|
+
else 0.0 for i in impls)
|
|
5554
|
+
distinct = rec["variance"]["all_distinct"] if rec["variance"] else (n == 1)
|
|
5555
|
+
if stub_green:
|
|
5556
|
+
rec["verdict"], rec["reason"] = "FAIL", ("oracle satisfied by a degenerate stub -- not "
|
|
5557
|
+
"discriminating; the entry proves nothing")
|
|
5558
|
+
elif not all_valid:
|
|
5559
|
+
rec["verdict"], rec["reason"] = "FAIL", "a compilation does not validate against the pinned IR"
|
|
5560
|
+
elif n < 3:
|
|
5561
|
+
rec["verdict"], rec["reason"] = "PENDING", "fewer than 3 compilations (have %d)" % n
|
|
5562
|
+
elif not distinct:
|
|
5563
|
+
rec["verdict"], rec["reason"] = "FAIL", ("implementations converged to a byte-identical "
|
|
5564
|
+
"pair -- a disguised implementation")
|
|
5565
|
+
elif greens == n:
|
|
5566
|
+
rec["verdict"], rec["reason"] = "PASS", ("all %d compilations oracle-green and genuinely "
|
|
5567
|
+
"different -- the same system" % n)
|
|
5568
|
+
elif min_rate >= _BENCH_PARTIAL_FLOOR:
|
|
5569
|
+
rec["verdict"], rec["reason"] = "PARTIAL", ("core identity (min %.0f%% of cases); "
|
|
5570
|
+
"divergence isolated" % (min_rate * 100))
|
|
5571
|
+
else:
|
|
5572
|
+
rec["verdict"], rec["reason"] = "FAIL", ("a compilation below the core-identity floor "
|
|
5573
|
+
"(min %.0f%%)" % (min_rate * 100))
|
|
5574
|
+
return rec
|
|
5575
|
+
|
|
5576
|
+
|
|
5577
|
+
def _render_bench_md(table, anon, recs):
|
|
5578
|
+
lines = ["<!-- GENERATED by qa_ledger.py bench (ADR-018) -- every number is a measured run; "
|
|
5579
|
+
"do not hand-edit. -->", "", "# DIAMOND-BENCH", "",
|
|
5580
|
+
"Regeneration fidelity of canonical representations across archetypes. Each row is a "
|
|
5581
|
+
"bounded system compiled blind by independent models through the M3 contract and "
|
|
5582
|
+
"judged by a WITHHELD oracle (M4). Model identities are anonymized here; the mapping "
|
|
5583
|
+
"is published below.", "",
|
|
5584
|
+
"| Archetype | Verdict | Compilers (oracle pass / total) | Distinct | Oracle cases |",
|
|
5585
|
+
"|-----------|---------|--------------------------------|----------|--------------|"]
|
|
5586
|
+
for t in table:
|
|
5587
|
+
dist = "—" if t["distinct"] is None else ("yes" if t["distinct"] else "NO")
|
|
5588
|
+
lines.append("| %s | %s | %s | %s | %d |" % (t["archetype"], t["verdict"],
|
|
5589
|
+
t["compilers"], dist, t["oracle_cases"]))
|
|
5590
|
+
counts = {}
|
|
5591
|
+
for t in table:
|
|
5592
|
+
counts[t["verdict"]] = counts.get(t["verdict"], 0) + 1
|
|
5593
|
+
lines += ["", "**Coverage:** " + ", ".join("%d %s" % (v, k) for k, v in sorted(counts.items()))
|
|
5594
|
+
+ " (of %d entries)." % len(table), "",
|
|
5595
|
+
"**Model map (published, not the headline):** "
|
|
5596
|
+
+ (", ".join("%s = %s" % (a, m) for m, a in sorted(anon.items(), key=lambda x: x[1]))
|
|
5597
|
+
or "none yet") + ".", "",
|
|
5598
|
+
"## Per-entry detail", ""]
|
|
5599
|
+
for r in recs:
|
|
5600
|
+
lines.append("### %s — %s" % (r["archetype"], r["verdict"]))
|
|
5601
|
+
lines.append("*%s*" % (r["reason"] or ""))
|
|
5602
|
+
if r["compilations"]:
|
|
5603
|
+
for i in r["compilations"]:
|
|
5604
|
+
lines.append("- `%s` (%s): oracle %d/%d%s%s" % (
|
|
5605
|
+
i["dir"], anon.get(i["model"], i["model"] or "?"),
|
|
5606
|
+
i["oracle"]["passed"], i["oracle"]["total"],
|
|
5607
|
+
" GREEN" if i["oracle"]["green"] else "",
|
|
5608
|
+
"" if i["compile_valid"] else " [does not compile-validate]"))
|
|
5609
|
+
if r["discrimination"]:
|
|
5610
|
+
dsc = r["discrimination"]
|
|
5611
|
+
lines.append("- discrimination stub: %d/%d (%s)" % (
|
|
5612
|
+
dsc["stub_passed"], dsc["total"],
|
|
5613
|
+
"NON-DISCRIMINATING" if dsc["stub_green"] else "oracle rejects the stub"))
|
|
5614
|
+
lines.append("")
|
|
5615
|
+
return "\n".join(lines)
|
|
5616
|
+
|
|
5617
|
+
|
|
5618
|
+
def cmd_bench(args):
|
|
5619
|
+
if not os.path.isdir(args.dir):
|
|
5620
|
+
print("[qa_ledger] bench: no directory %s" % args.dir, file=sys.stderr)
|
|
5621
|
+
sys.exit(2)
|
|
5622
|
+
entries = sorted(d for d in os.listdir(args.dir)
|
|
5623
|
+
if os.path.isfile(os.path.join(args.dir, d, IR_FILE)))
|
|
5624
|
+
if not entries:
|
|
5625
|
+
print("[qa_ledger] bench: no entries under %s (an entry is a subdir with %s)"
|
|
5626
|
+
% (args.dir, IR_FILE), file=sys.stderr)
|
|
5627
|
+
sys.exit(2)
|
|
5628
|
+
recs = [_bench_entry(os.path.join(args.dir, e), e) for e in entries]
|
|
5629
|
+
models = sorted({i["model"] for r in recs for i in r["compilations"] if i.get("model")})
|
|
5630
|
+
anon = {m: "M%d" % (k + 1) for k, m in enumerate(models)}
|
|
5631
|
+
table = []
|
|
5632
|
+
for r in recs:
|
|
5633
|
+
cols = ", ".join("%s %d/%d" % (anon.get(i["model"], "?"), i["oracle"]["passed"],
|
|
5634
|
+
i["oracle"]["total"]) for i in r["compilations"])
|
|
5635
|
+
table.append({"archetype": r["archetype"], "verdict": r["verdict"],
|
|
5636
|
+
"compilers": cols or "(none yet)",
|
|
5637
|
+
"distinct": (r["variance"] or {}).get("all_distinct"),
|
|
5638
|
+
"oracle_cases": r["oracle_cases"], "reason": r["reason"]})
|
|
5639
|
+
md = _render_bench_md(table, anon, recs)
|
|
5640
|
+
if args.out:
|
|
5641
|
+
with open(args.out, "w", encoding="utf-8", newline="\n") as fh:
|
|
5642
|
+
fh.write(md)
|
|
5643
|
+
if args.json:
|
|
5644
|
+
print(json.dumps({"entries": len(recs), "model_map": anon, "table": table,
|
|
5645
|
+
"raw": recs}, indent=2, ensure_ascii=False))
|
|
5646
|
+
else:
|
|
5647
|
+
print("BENCH: %d entries" % len(recs))
|
|
5648
|
+
for t in table:
|
|
5649
|
+
dist = "" if t["distinct"] is None else (" | distinct" if t["distinct"]
|
|
5650
|
+
else " | CONVERGED")
|
|
5651
|
+
print(" %-14s %-8s | %s%s" % (t["archetype"], t["verdict"], t["compilers"], dist))
|
|
5652
|
+
if args.out:
|
|
5653
|
+
print(" -> %s" % args.out)
|
|
5654
|
+
sys.exit(0)
|
|
5655
|
+
|
|
5656
|
+
|
|
5301
5657
|
# --------------------------------------------------------------------------- #
|
|
5302
5658
|
# facts (T0 / SYSTEM-FACTS: public claims become compiled artifacts of repo
|
|
5303
5659
|
# facts -- Diamond applied to Diamond. ADR-012.)
|
|
@@ -9390,6 +9746,37 @@ def build_parser():
|
|
|
9390
9746
|
pcmi.add_argument("--json", action="store_true")
|
|
9391
9747
|
pcmi.set_defaults(func=cmd_compile_ingest)
|
|
9392
9748
|
|
|
9749
|
+
pbo = sub.add_parser(
|
|
9750
|
+
"bootstrap-oracle",
|
|
9751
|
+
help="run a WITHHELD oracle suite against a compiled implementation (ADR-017); exit 0 "
|
|
9752
|
+
"iff every case matches its expected exit -- the maker!=checker wall, executable")
|
|
9753
|
+
pbo.add_argument("--impl", required=True, help="the compiled implementation to run")
|
|
9754
|
+
pbo.add_argument("--oracle", required=True, help="the withheld ORACLE.json case suite")
|
|
9755
|
+
pbo.add_argument("--ledger", default=None, help="optional: persist the measured result")
|
|
9756
|
+
pbo.add_argument("--repo", default=None, help="repo scope when --ledger is given")
|
|
9757
|
+
pbo.add_argument("--json", action="store_true")
|
|
9758
|
+
pbo.set_defaults(func=cmd_bootstrap_oracle)
|
|
9759
|
+
|
|
9760
|
+
pbv = sub.add_parser(
|
|
9761
|
+
"bootstrap-variance",
|
|
9762
|
+
help="structural metrics + pairwise divergence proving independent compilations "
|
|
9763
|
+
"genuinely differ (ADR-017); ADVISORY evidence, never a gate")
|
|
9764
|
+
pbv.add_argument("--impls", required=True, nargs="+",
|
|
9765
|
+
help="two or more compiled implementations to compare")
|
|
9766
|
+
pbv.add_argument("--json", action="store_true")
|
|
9767
|
+
pbv.set_defaults(func=cmd_bootstrap_variance)
|
|
9768
|
+
|
|
9769
|
+
pbn = sub.add_parser(
|
|
9770
|
+
"bench",
|
|
9771
|
+
help="the Diamond Bench (ADR-018): per-archetype verdict table over a set of bounded "
|
|
9772
|
+
"systems, aggregating compile-validate + bootstrap-oracle + bootstrap-variance; "
|
|
9773
|
+
"model identities anonymized in the headline; deterministic, no LLM")
|
|
9774
|
+
pbn.add_argument("--dir", required=True,
|
|
9775
|
+
help="the bench directory; each subdir with an IR.json is an entry")
|
|
9776
|
+
pbn.add_argument("--out", default=None, help="write DIAMOND-BENCH.md here")
|
|
9777
|
+
pbn.add_argument("--json", action="store_true")
|
|
9778
|
+
pbn.set_defaults(func=cmd_bench)
|
|
9779
|
+
|
|
9393
9780
|
pcr = sub.add_parser("cleanroom",
|
|
9394
9781
|
help="run a command against a CLEAN checkout of one commit in a throwaway worktree (ADR-008)")
|
|
9395
9782
|
pcr.add_argument("--ledger", default="QA-LEDGER.json")
|