P6A-8: Source Reference Bundle and harness profile aji_source
- source bundle: a /docs directory with QUICK.md (Quick Reference plus a where-to-read table), language/*.md, diagnostics/errors.md and the AIR bundle only under air/; built from docs/agent/source-bundle.txt (> output files, @manifest includes) by zig build agent-reference - Quick Reference examples are checked: every aji block must be an excerpt of a conformance program in tests/conformance/source/quickref (zig build test fails otherwise); QR fixes found by the check (mut d = data, region not auto-borrowed, statement/borrow blocks that could not verify, io_error match) - frontend: task.*/channel.*/mutex.* are not-yet-implemented, not E7006 - aji lower --stats: mechanical_air_eliminated_raw and _normalized (each byte-string materialization counted as one constant; spec 15 §11) - harness: profile aji_source (doc_groups), per-file and per-group docs metrics on distinctive lines, profile columns (tool calls, lowered AIR raw/normalized, docs files read, IR-form and type-mismatch counts), dev-echo aji_source variant, scripted run and test, source token report - plan: P6A-8 done, P6A-9 criteria; Q-021/Q-022 resolved; unsafe block deferred
This commit is contained in:
1 parent
61be766634
commit
3e2d9b63a7
35 files changed
+1170
-106
No files matched your search
@@ -167,7 +167,7 @@ def _diagnostic_codes(r, run_dir):
|
||||
outputs = [json.loads(l).get("output") or "" for l in open(os.path.join(run_dir, "events.jsonl")) if '"event": "command"' in l]
|
||||
lang = r["language"]["name"]
|
||||
for o in outputs:
|
||||
if lang == "aji_air":
|
||||
if lang in ("aji_air", "aji_source"):
|
||||
counts.update(re.findall(r'"code":"([ET]\d{4})"', o))
|
||||
elif lang == "rust":
|
||||
counts.update(re.findall(r"error\[(E\d{4})\]", o))
|
||||
@@ -177,14 +177,43 @@ def _diagnostic_codes(r, run_dir):
|
||||
return dict(counts.most_common())
|
||||
|
||||
|
||||
# Diagnostics about the textual form of AIR (syntax, names, module header,
|
||||
# SSA, CFG): the classes the source frontend is meant to remove. Type
|
||||
# mismatches (E1001 from AIR, E7005 from source) are semantic and counted
|
||||
# separately, so relabeling cannot make the IR-form count look better.
|
||||
IR_FORM = {"E0001", "E0002", "E0003", "E0004", "E0005", "E0006", "E5001", "E5002"}
|
||||
TYPE_MISMATCH = {"E1001", "E7005"}
|
||||
|
||||
|
||||
def _lowered_size(run_dir):
|
||||
"""`aji lower --stats` summed over the workspace's .aji files: raw and
|
||||
normalized lowered AIR bytes (spec 15 §11); None when nothing lowers."""
|
||||
import subprocess
|
||||
|
||||
aji = os.path.join(util.REPO, "zig-out", "bin", "aji")
|
||||
raw = norm = 0
|
||||
found = False
|
||||
for root, dirs, names in os.walk(os.path.join(run_dir, "workspace")):
|
||||
dirs[:] = [d for d in dirs if d not in ("zig-out", ".zig-cache", ".git")]
|
||||
for n in names:
|
||||
if not n.endswith(".aji"):
|
||||
continue
|
||||
r = subprocess.run([aji, "lower", "--stats", os.path.join(root, n)], capture_output=True, text=True)
|
||||
if r.returncode != 0:
|
||||
continue
|
||||
st = json.loads(r.stdout)
|
||||
raw, norm, found = raw + st["air_bytes"], norm + st["air_bytes_normalized"], True
|
||||
return (raw, norm) if found else None
|
||||
|
||||
|
||||
def profile(paths):
|
||||
"""Per-run cost profile for failure and cost analysis (protocol §27,
|
||||
§38): termination, output tokens, solution size and diagnostic codes.
|
||||
Shareable: numbers and diagnostic codes only."""
|
||||
from . import languages
|
||||
|
||||
out = ["| task | language | agent | termination | output tokens | source files / lines / bytes | diagnostic codes (count) |",
|
||||
"|---|---|---|---|---|---|---|"]
|
||||
out = ["| task | language | agent | termination | output tokens | tool calls | source files / lines / bytes | lowered AIR bytes raw / normalized | docs files read | IR-form diagnostics | type mismatches | diagnostic codes (count) |",
|
||||
"|---|---|---|---|---|---|---|---|---|---|---|---|"]
|
||||
for p in paths:
|
||||
for f in sorted(glob.glob(os.path.join(p, "**", "run.json"), recursive=True)):
|
||||
if "/superseded/" in f:
|
||||
@@ -195,6 +224,11 @@ def profile(paths):
|
||||
files, lines, nbytes = _source_size(d, exts)
|
||||
codes = _diagnostic_codes(r, d)
|
||||
m = r["metrics"]
|
||||
out.append(f"| {r['task']['id']} | {r['language']['name']} | {_agent_key(r)} | {m.get('termination')} | {m.get('output_tokens')} | "
|
||||
f"{files} / {lines} / {nbytes} | {', '.join(f'{k} {v}' for k, v in codes.items()) or '-'} |")
|
||||
lowered = _lowered_size(d) if r["language"]["name"] == "aji_source" else None
|
||||
docs = (m.get("context") or {}).get("docs") or {}
|
||||
ir = sum(v for k, v in codes.items() if k in IR_FORM)
|
||||
ty = sum(v for k, v in codes.items() if k in TYPE_MISMATCH)
|
||||
out.append(f"| {r['task']['id']} | {r['language']['name']} | {_agent_key(r)} | {m.get('termination')} | {m.get('output_tokens')} | {m.get('tool_calls')} | "
|
||||
f"{files} / {lines} / {nbytes} | {f'{lowered[0]} / {lowered[1]}' if lowered else '-'} | "
|
||||
f"{docs.get('unique_docs_read', '-')} | {ir} | {ty} | {', '.join(f'{k} {v}' for k, v in codes.items()) or '-'} |")
|
||||
return "\n".join(out)
|
||||
Reference in new issue
Block a user