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
@@ -11,6 +11,17 @@
|
||||
reference_coverage for a single-file reference (the Aji Agent
|
||||
Reference Bundle): the fraction of its
|
||||
non-empty lines that appeared in those outputs
|
||||
docs for a directory of documentation (the Source
|
||||
Reference Bundle), per file and per group of
|
||||
the profile's `doc_groups`:
|
||||
<group>_tokens size of the group (e.g. quick_reference_tokens,
|
||||
source_docs_tokens, air_docs_tokens)
|
||||
full_source_docs_tokens every group except air_docs
|
||||
read_tokens_by_group tokens of the group's lines the agent saw
|
||||
coverage_by_section per file: fraction of its distinctive lines
|
||||
(in no other file of the mount) seen
|
||||
files_opened files whose /docs path occurs in a tool input
|
||||
unique_docs_read how many files were opened
|
||||
|
||||
The gap between them shows where context is amplified: rereading the same
|
||||
documentation, verbose tool output, or the provider resending history.
|
||||
@@ -86,9 +97,76 @@ def tool_events_native(agent_name, transcript_path):
|
||||
return out
|
||||
|
||||
|
||||
def metrics(tool_events, task_message, docs, provider):
|
||||
def _doc_files(docs):
|
||||
"""[(path under /docs, host path)] of every file in the mounts."""
|
||||
out = []
|
||||
for name, p in docs:
|
||||
if os.path.isfile(p):
|
||||
out.append((name or os.path.basename(p), p))
|
||||
continue
|
||||
for d, _, files in os.walk(p):
|
||||
for f in sorted(files):
|
||||
hp = os.path.join(d, f)
|
||||
rel = os.path.relpath(hp, p)
|
||||
out.append((os.path.join(name, rel) if name else rel, hp))
|
||||
return sorted(out)
|
||||
|
||||
|
||||
def _group_of(rel, groups):
|
||||
for g, prefixes in groups.items():
|
||||
for pre in prefixes:
|
||||
if rel == pre or (pre.endswith("/") and rel.startswith(pre)):
|
||||
return g
|
||||
return "other"
|
||||
|
||||
|
||||
def doc_metrics(tool_events, docs, groups, seen, count):
|
||||
"""Per-file and per-group reading of a documentation directory.
|
||||
|
||||
Only distinctive lines count: a line contributes to a file's coverage
|
||||
only if no other file in the mount contains it, and to a group's read
|
||||
tokens only if every file containing it is in that group. Table rules,
|
||||
fences and sections copied into several files (the error-code table is
|
||||
in diagnostics/ and in air/) would otherwise be credited to files the
|
||||
agent never opened."""
|
||||
files = _doc_files(docs)
|
||||
inputs = "\n".join(i for i, _ in tool_events)
|
||||
texts, owners = {}, {}
|
||||
for rel, hp in files:
|
||||
with open(hp, encoding="utf-8", errors="replace") as f:
|
||||
texts[rel] = f.read()
|
||||
for x in {_norm(x) for x in texts[rel].splitlines() if _norm(x)}:
|
||||
owners.setdefault(x, set()).add(rel)
|
||||
own = {}
|
||||
for x, fs in owners.items():
|
||||
if len(fs) == 1:
|
||||
own.setdefault(next(iter(fs)), set()).add(x)
|
||||
coverage, opened, size, read_lines = {}, [], {}, {}
|
||||
for rel, _ in files:
|
||||
mine = own.get(rel, set())
|
||||
coverage[rel] = round(len(mine & seen) / len(mine), 4) if mine else 0.0
|
||||
if "/docs/" + rel in inputs:
|
||||
opened.append(rel)
|
||||
g = _group_of(rel, groups)
|
||||
size[g] = size.get(g, 0) + count(texts[rel])
|
||||
read_lines.setdefault(g, set())
|
||||
for x in seen:
|
||||
gs = {_group_of(f, groups) for f in owners.get(x, ())}
|
||||
if len(gs) == 1:
|
||||
read_lines[gs.pop()].add(x)
|
||||
out = {f"{g}_tokens": n for g, n in sorted(size.items())}
|
||||
out["full_source_docs_tokens"] = sum(n for g, n in size.items() if g != "air_docs")
|
||||
out["read_tokens_by_group"] = {g: (count("\n".join(sorted(ls))) if ls else 0) for g, ls in sorted(read_lines.items())}
|
||||
out["coverage_by_section"] = coverage
|
||||
out["files_opened"] = opened
|
||||
out["unique_docs_read"] = len(opened)
|
||||
return out
|
||||
|
||||
|
||||
def metrics(tool_events, task_message, docs, provider, groups=None):
|
||||
"""`docs` is [(mount name, host path)]; `provider` holds input, output,
|
||||
cached_input as counted by the provider (None when unknown)."""
|
||||
cached_input as counted by the provider (None when unknown); `groups` is
|
||||
the profile's `doc_groups` ({name: [file or "dir/" prefix]})."""
|
||||
name, count = _tokenizer()
|
||||
cumulative = count(task_message) + sum(count(o) for _, o in tool_events)
|
||||
seen = set()
|
||||
@@ -106,6 +184,8 @@ def metrics(tool_events, task_message, docs, provider):
|
||||
ref = {_norm(x) for x in f.read().splitlines() if _norm(x)}
|
||||
coverage = round(len(ref & seen) / len(ref), 4) if ref else None
|
||||
inp, cached = provider.get("input"), provider.get("cached_input")
|
||||
dirs = [p for _, p in docs if os.path.isdir(p)]
|
||||
extra = {"docs": doc_metrics(tool_events, docs, groups or {}, seen, count)} if dirs else {}
|
||||
return {
|
||||
"tokenizer": name,
|
||||
"provider_input_tokens": {"total": inp, "cached": cached, "uncached": None if inp is None or cached is None else inp - cached, "output": provider.get("output")},
|
||||
@@ -113,4 +193,5 @@ def metrics(tool_events, task_message, docs, provider):
|
||||
"unique_reference_tokens": unique,
|
||||
"reference_coverage": coverage,
|
||||
"tool_outputs": len(tool_events),
|
||||
**extra,
|
||||
}
|
||||
Reference in new issue
Block a user