tokenblame 2.1.2__tar.gz → 2.2.1__tar.gz
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.
- {tokenblame-2.1.2 → tokenblame-2.2.1}/PKG-INFO +7 -7
- {tokenblame-2.1.2 → tokenblame-2.2.1}/README.md +6 -6
- {tokenblame-2.1.2 → tokenblame-2.2.1}/pyproject.toml +1 -1
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tests/test_observatory.py +218 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame/harvesters.py +220 -11
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame/joiner.py +58 -14
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame/provenance.py +6 -1
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame/render.py +16 -2
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame/survival.py +262 -33
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame.egg-info/PKG-INFO +7 -7
- {tokenblame-2.1.2 → tokenblame-2.2.1}/LICENSE +0 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/setup.cfg +0 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame/__init__.py +0 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame/cli.py +0 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame/hooks.py +0 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame/redact.py +0 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame/schema.py +0 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame/store.py +0 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame.egg-info/SOURCES.txt +0 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame.egg-info/dependency_links.txt +0 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame.egg-info/entry_points.txt +0 -0
- {tokenblame-2.1.2 → tokenblame-2.2.1}/tokenblame.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tokenblame
|
|
3
|
-
Version: 2.1
|
|
3
|
+
Version: 2.2.1
|
|
4
4
|
Summary: Offline AI coding token ledger with out-of-repo Git commit provenance, Squash-Merge-resilient HEAD line retention, and allowlisted burn forensics
|
|
5
5
|
Author: espressolee
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -23,10 +23,10 @@ Description-Content-Type: text/markdown
|
|
|
23
23
|
License-File: LICENSE
|
|
24
24
|
Dynamic: license-file
|
|
25
25
|
|
|
26
|
-
# TokenBlame (`v2.
|
|
26
|
+
# TokenBlame (`v2.2`)
|
|
27
27
|
|
|
28
28
|
**Don't just count AI coding tokens — blame them.**
|
|
29
|
-
*Zero-config, 100% offline multi-agent token ledger with out-of-repo Git commit provenance, Squash-Merge-resilient
|
|
29
|
+
*Zero-config, 100% offline multi-agent token ledger with out-of-repo Git commit provenance, fixed-horizon (`t+30/60/90d`) & Squash-Merge-resilient line retention, and exit-code-aware burn forensics.*
|
|
30
30
|
|
|
31
31
|

|
|
32
32
|
|
|
@@ -42,12 +42,12 @@ Token accounting, commit attribution, and code survival each have strong existin
|
|
|
42
42
|
| **`Git AI` (OSS / Teams)** | Line-level AI authorship + Teams PR cost, rework & churn analytics | Yes (spec covers buckets & 90d DB; team analytics in Teams tier) | Line-level authorship + PR cost/churn | Git notes / metadata | Rust / Cloud |
|
|
43
43
|
| **`Entire`** | Session checkpoints & token hotspot diagnostics | Yes (`fresh` / `cache` / `output` / `subagent`) | Session checkpoints linked to commits | Checkpoint metadata | Go |
|
|
44
44
|
| **`survived`** | Fixed-horizon `t+30/60/90d` code survival (with `notYet` cohort separation) | No | Fixed-horizon commit survival | None | TypeScript |
|
|
45
|
-
| **`TokenBlame` (`v2.
|
|
45
|
+
| **`TokenBlame` (`v2.2`)** | **Local offline multi-agent cost + commit provenance + `t+30/60/90d` cohorts & HEAD retention + exit-code burn loops** | **Yes** (4-bucket + strict unbucketed separation) | **Out-of-repo `record-hook` spool + revert, HEAD retention & matured cohorts (`notYet` separated)** | **None** | **Python 3.11+ stdlib only** |
|
|
46
46
|
|
|
47
47
|
> **Honest measurement scope:**
|
|
48
|
-
> - **HEAD Line Retention (`
|
|
48
|
+
> - **HEAD Line Retention vs. Fixed-Horizon Cohorts (`t+30/60/90d`):** `line_survival_30d_pct` tracks HEAD retention of lines from the recent 30-day window (with Squash-Merge / Rebase fallback and `unobserved_lines` kept separate on `git blame` errors). Alongside it, `durability.cohorts` (`t30d`, `t60d`, `t90d`) measures **matured** fixed-horizon cohorts explicitly separated from immature `notYet` commits.
|
|
49
49
|
> - **Pre-Indexed Query Latency (`3.5ms`):** Refers specifically to filtered `tokenblame summary` reads against an already-built `observatory.sqlite`, not cold full-history harvesting or `git blame` scans.
|
|
50
|
-
> - **Diagnostic Signals ≠ Causal Proof:** `
|
|
50
|
+
> - **Diagnostic Signals ≠ Causal Proof:** `FAILURE_LOOP` (nonzero exit/error streaks), `ITERATION_LOOP` (zero-error verification repeats), uncommitted high-burn sessions, and line retention are investigative signals — not automatic proofs of wasted effort, code correctness, or causal ROI.
|
|
51
51
|
|
|
52
52
|
---
|
|
53
53
|
|
|
@@ -55,7 +55,7 @@ Token accounting, commit attribution, and code survival each have strong existin
|
|
|
55
55
|
|
|
56
56
|

|
|
57
57
|
|
|
58
|
-
- **Allowlisted Tool Forensics (Zero Leakage):** Extracts peak turn spikes (`Peak #T: Out / Fresh`) and
|
|
58
|
+
- **Allowlisted Tool Forensics (Zero Leakage):** Extracts peak turn spikes (`Peak #T: Out / Fresh`) and exit-code-aware loop classifications (`FAILURE_LOOP(Bash:pytest x6, err=4)` vs normal `ITERATION_LOOP(Bash:pytest x4)`) using an allowlist of tool/command basenames — **never** storing command arguments, stdout/stderr, file paths, or prompts.
|
|
59
59
|
- **Privacy-Sealed `--shareable` Mode:** `tokenblame build --shareable` produces a standalone offline HTML dashboard (`shareable-observatory.html`) with salted SHA-256 aliases (`repo-01`, `c-9a4f1b2c`) and **zero** local paths, usernames, or commit subjects.
|
|
60
60
|
|
|
61
61
|
---
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
# TokenBlame (`v2.
|
|
1
|
+
# TokenBlame (`v2.2`)
|
|
2
2
|
|
|
3
3
|
**Don't just count AI coding tokens — blame them.**
|
|
4
|
-
*Zero-config, 100% offline multi-agent token ledger with out-of-repo Git commit provenance, Squash-Merge-resilient
|
|
4
|
+
*Zero-config, 100% offline multi-agent token ledger with out-of-repo Git commit provenance, fixed-horizon (`t+30/60/90d`) & Squash-Merge-resilient line retention, and exit-code-aware burn forensics.*
|
|
5
5
|
|
|
6
6
|

|
|
7
7
|
|
|
@@ -17,12 +17,12 @@ Token accounting, commit attribution, and code survival each have strong existin
|
|
|
17
17
|
| **`Git AI` (OSS / Teams)** | Line-level AI authorship + Teams PR cost, rework & churn analytics | Yes (spec covers buckets & 90d DB; team analytics in Teams tier) | Line-level authorship + PR cost/churn | Git notes / metadata | Rust / Cloud |
|
|
18
18
|
| **`Entire`** | Session checkpoints & token hotspot diagnostics | Yes (`fresh` / `cache` / `output` / `subagent`) | Session checkpoints linked to commits | Checkpoint metadata | Go |
|
|
19
19
|
| **`survived`** | Fixed-horizon `t+30/60/90d` code survival (with `notYet` cohort separation) | No | Fixed-horizon commit survival | None | TypeScript |
|
|
20
|
-
| **`TokenBlame` (`v2.
|
|
20
|
+
| **`TokenBlame` (`v2.2`)** | **Local offline multi-agent cost + commit provenance + `t+30/60/90d` cohorts & HEAD retention + exit-code burn loops** | **Yes** (4-bucket + strict unbucketed separation) | **Out-of-repo `record-hook` spool + revert, HEAD retention & matured cohorts (`notYet` separated)** | **None** | **Python 3.11+ stdlib only** |
|
|
21
21
|
|
|
22
22
|
> **Honest measurement scope:**
|
|
23
|
-
> - **HEAD Line Retention (`
|
|
23
|
+
> - **HEAD Line Retention vs. Fixed-Horizon Cohorts (`t+30/60/90d`):** `line_survival_30d_pct` tracks HEAD retention of lines from the recent 30-day window (with Squash-Merge / Rebase fallback and `unobserved_lines` kept separate on `git blame` errors). Alongside it, `durability.cohorts` (`t30d`, `t60d`, `t90d`) measures **matured** fixed-horizon cohorts explicitly separated from immature `notYet` commits.
|
|
24
24
|
> - **Pre-Indexed Query Latency (`3.5ms`):** Refers specifically to filtered `tokenblame summary` reads against an already-built `observatory.sqlite`, not cold full-history harvesting or `git blame` scans.
|
|
25
|
-
> - **Diagnostic Signals ≠ Causal Proof:** `
|
|
25
|
+
> - **Diagnostic Signals ≠ Causal Proof:** `FAILURE_LOOP` (nonzero exit/error streaks), `ITERATION_LOOP` (zero-error verification repeats), uncommitted high-burn sessions, and line retention are investigative signals — not automatic proofs of wasted effort, code correctness, or causal ROI.
|
|
26
26
|
|
|
27
27
|
---
|
|
28
28
|
|
|
@@ -30,7 +30,7 @@ Token accounting, commit attribution, and code survival each have strong existin
|
|
|
30
30
|
|
|
31
31
|

|
|
32
32
|
|
|
33
|
-
- **Allowlisted Tool Forensics (Zero Leakage):** Extracts peak turn spikes (`Peak #T: Out / Fresh`) and
|
|
33
|
+
- **Allowlisted Tool Forensics (Zero Leakage):** Extracts peak turn spikes (`Peak #T: Out / Fresh`) and exit-code-aware loop classifications (`FAILURE_LOOP(Bash:pytest x6, err=4)` vs normal `ITERATION_LOOP(Bash:pytest x4)`) using an allowlist of tool/command basenames — **never** storing command arguments, stdout/stderr, file paths, or prompts.
|
|
34
34
|
- **Privacy-Sealed `--shareable` Mode:** `tokenblame build --shareable` produces a standalone offline HTML dashboard (`shareable-observatory.html`) with salted SHA-256 aliases (`repo-01`, `c-9a4f1b2c`) and **zero** local paths, usernames, or commit subjects.
|
|
35
35
|
|
|
36
36
|
---
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tokenblame"
|
|
7
|
-
version = "2.1
|
|
7
|
+
version = "2.2.1"
|
|
8
8
|
description = "Offline AI coding token ledger with out-of-repo Git commit provenance, Squash-Merge-resilient HEAD line retention, and allowlisted burn forensics"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -1319,6 +1319,224 @@ class TestObservatoryAdversarial(unittest.TestCase):
|
|
|
1319
1319
|
self.assertEqual(res["unobserved_lines"], 3)
|
|
1320
1320
|
self.assertEqual(res["unobserved_files"], ["mod.py"])
|
|
1321
1321
|
|
|
1322
|
+
def test_fixed_horizon_cohort_survival_t30_t60_t90_and_not_yet(self):
|
|
1323
|
+
import os
|
|
1324
|
+
import subprocess
|
|
1325
|
+
from tokenblame.survival import measure_30d_line_survival, measure_cohort_line_survival
|
|
1326
|
+
|
|
1327
|
+
with tempfile.TemporaryDirectory() as td:
|
|
1328
|
+
repo = Path(td) / "cohort-repo"
|
|
1329
|
+
repo.mkdir()
|
|
1330
|
+
def git(*args: str, ep: int | None = None) -> str:
|
|
1331
|
+
env = os.environ.copy()
|
|
1332
|
+
if ep is not None:
|
|
1333
|
+
dstr = f"{ep} +0000"
|
|
1334
|
+
env["GIT_AUTHOR_DATE"] = dstr
|
|
1335
|
+
env["GIT_COMMITTER_DATE"] = dstr
|
|
1336
|
+
return subprocess.run(
|
|
1337
|
+
["git", "-C", str(repo), *args],
|
|
1338
|
+
check=True, capture_output=True, text=True, env=env,
|
|
1339
|
+
).stdout.strip()
|
|
1340
|
+
|
|
1341
|
+
git("init", "-b", "main")
|
|
1342
|
+
git("config", "user.name", "Dev")
|
|
1343
|
+
git("config", "user.email", "dev@example.com")
|
|
1344
|
+
|
|
1345
|
+
# Audit counterexample: Day 0 add 10 lines -> Day 50 delete all 10 lines -> Day 100 eval
|
|
1346
|
+
# True historical fixed-horizon survival MUST be: t+30d=100%, t+60d=0%, t+90d=0%, HEAD=0%!
|
|
1347
|
+
day0 = 1_750_000_000
|
|
1348
|
+
day50 = day0 + 50 * 86400
|
|
1349
|
+
day100 = day0 + 100 * 86400
|
|
1350
|
+
(repo / "ephemeral.py").write_text("".join(f"val_{i} = {i}\n" for i in range(10)), encoding="utf-8")
|
|
1351
|
+
git("add", ".")
|
|
1352
|
+
git("commit", "-m", "day0 add 10 lines", ep=day0)
|
|
1353
|
+
oid_day0 = git("rev-parse", "HEAD")
|
|
1354
|
+
|
|
1355
|
+
git("rm", "ephemeral.py")
|
|
1356
|
+
git("commit", "-m", "day50 delete all 10 lines", ep=day50)
|
|
1357
|
+
|
|
1358
|
+
cohorts_ce = measure_cohort_line_survival(
|
|
1359
|
+
str(repo),
|
|
1360
|
+
[{"oid": oid_day0, "epoch_sec": float(day0), "committer_epoch": float(day0)}],
|
|
1361
|
+
as_of_epoch=float(day100),
|
|
1362
|
+
)
|
|
1363
|
+
self.assertEqual(cohorts_ce["t30d"]["retention_pct"], 100.0)
|
|
1364
|
+
self.assertEqual(cohorts_ce["t30d"]["surviving_lines"], 10)
|
|
1365
|
+
self.assertEqual(cohorts_ce["t60d"]["retention_pct"], 0.0)
|
|
1366
|
+
self.assertEqual(cohorts_ce["t90d"]["retention_pct"], 0.0)
|
|
1367
|
+
head_ce = measure_30d_line_survival(str(repo), [oid_day0])
|
|
1368
|
+
self.assertEqual(head_ce["surviving_lines"], 0)
|
|
1369
|
+
|
|
1370
|
+
# Working-tree isolation counterexample: file exists in HEAD but deleted on disk (uncommitted)
|
|
1371
|
+
(repo / "keep.py").write_text("k1 = 1\nk2 = 2\nk3 = 3\n", encoding="utf-8")
|
|
1372
|
+
git("add", "keep.py")
|
|
1373
|
+
git("commit", "-m", "add keep.py", ep=day100 - 5 * 86400)
|
|
1374
|
+
oid_keep = git("rev-parse", "HEAD")
|
|
1375
|
+
(repo / "keep.py").unlink() # Delete ONLY in working tree, NOT committed!
|
|
1376
|
+
head_wt = measure_30d_line_survival(str(repo), [oid_keep])
|
|
1377
|
+
self.assertEqual(head_wt["added_lines"], 3)
|
|
1378
|
+
self.assertEqual(head_wt["surviving_lines"], 3)
|
|
1379
|
+
|
|
1380
|
+
# Multi-commit matured vs notYet partition check (5d, 35d, 70d, 100d -> 3/1, 2/2, 1/3)
|
|
1381
|
+
recs = [
|
|
1382
|
+
{"oid": oid_day0, "epoch_sec": float(day0), "committer_epoch": float(day0)},
|
|
1383
|
+
{"oid": oid_keep, "epoch_sec": float(day100 - 5 * 86400), "committer_epoch": float(day100 - 5 * 86400)},
|
|
1384
|
+
]
|
|
1385
|
+
c_mix = measure_cohort_line_survival(str(repo), recs, as_of_epoch=float(day100))
|
|
1386
|
+
self.assertEqual(c_mix["t30d"]["matured_commits"], 1)
|
|
1387
|
+
self.assertEqual(c_mix["t30d"]["not_yet_commits"], 1)
|
|
1388
|
+
|
|
1389
|
+
def test_recency_single_quiet_commit_never_claims_exact_hook_oid(self):
|
|
1390
|
+
import subprocess
|
|
1391
|
+
from tokenblame.provenance import record_hook_invocation
|
|
1392
|
+
|
|
1393
|
+
with tempfile.TemporaryDirectory() as td:
|
|
1394
|
+
repo = Path(td) / "single-quiet-repo"
|
|
1395
|
+
repo.mkdir()
|
|
1396
|
+
def git(*args: str) -> str:
|
|
1397
|
+
return subprocess.run(["git", "-C", str(repo), *args], check=True, capture_output=True, text=True).stdout.strip()
|
|
1398
|
+
|
|
1399
|
+
git("init", "-b", "main")
|
|
1400
|
+
git("config", "user.name", "Dev")
|
|
1401
|
+
git("config", "user.email", "dev@example.com")
|
|
1402
|
+
(repo / "x.py").write_text("x = 1\n", encoding="utf-8")
|
|
1403
|
+
git("add", ".")
|
|
1404
|
+
git("commit", "-m", "only commit")
|
|
1405
|
+
oid1 = git("rev-parse", "HEAD")
|
|
1406
|
+
|
|
1407
|
+
now_ep = dt.datetime.now(dt.timezone.utc).timestamp()
|
|
1408
|
+
recs = record_hook_invocation(
|
|
1409
|
+
json.dumps({
|
|
1410
|
+
"session_id": "sess-single-quiet",
|
|
1411
|
+
"cwd": str(repo),
|
|
1412
|
+
"tool_name": "Bash",
|
|
1413
|
+
"tool_input": {"command": "git commit -q -m 'only commit'"},
|
|
1414
|
+
"tool_response": {"exitCode": 0, "stdout": ""},
|
|
1415
|
+
}),
|
|
1416
|
+
provider="claude",
|
|
1417
|
+
spool_path=Path(td) / "prov.jsonl",
|
|
1418
|
+
now_epoch=now_ep,
|
|
1419
|
+
)
|
|
1420
|
+
self.assertEqual(len(recs), 1)
|
|
1421
|
+
self.assertEqual(recs[0]["oid_source"], "recency_single")
|
|
1422
|
+
self.assertTrue(recs[0]["ambiguous"])
|
|
1423
|
+
|
|
1424
|
+
s = SessionRecord(
|
|
1425
|
+
session_id="sess-single-quiet", provider="claude", model="claude-opus-5-5",
|
|
1426
|
+
status="MEASURED", bucket_fidelity="4_bucket",
|
|
1427
|
+
day=dt.datetime.now(dt.timezone.utc).strftime("%Y-%m-%d"),
|
|
1428
|
+
timestamp=dt.datetime.now(dt.timezone.utc).isoformat(),
|
|
1429
|
+
epoch_sec=now_ep - 5, cwd=str(repo.resolve()),
|
|
1430
|
+
buckets=TokenBuckets(uncached_input=200, cached_read=400, visible_output=500),
|
|
1431
|
+
)
|
|
1432
|
+
ir = build_observatory_ir(
|
|
1433
|
+
sessions=[s],
|
|
1434
|
+
commits=[{
|
|
1435
|
+
"oid": oid1, "short_oid": oid1[:8], "day": s.day,
|
|
1436
|
+
"epoch_sec": now_ep, "clock_ts": s.timestamp,
|
|
1437
|
+
"lanes": ["Projects"], "repos": ["single-quiet-repo"],
|
|
1438
|
+
"repo_root": str(repo.resolve()), "subject": "only commit",
|
|
1439
|
+
}],
|
|
1440
|
+
episodes=[],
|
|
1441
|
+
repo_map={str(repo.resolve()): ("Projects", "single-quiet-repo")},
|
|
1442
|
+
harvest_stats={},
|
|
1443
|
+
provenance_records=recs,
|
|
1444
|
+
discover_repos=False,
|
|
1445
|
+
)
|
|
1446
|
+
self.assertEqual(ir["totals"]["causality_breakdown"]["EXACT_HOOK_OID"], 0)
|
|
1447
|
+
self.assertEqual(s.causality_tier, "TIME_WINDOW_HEURISTIC")
|
|
1448
|
+
|
|
1449
|
+
def test_exit_code_aware_failure_loop_vs_iteration_loop_without_arg_leaks(self):
|
|
1450
|
+
from tokenblame.harvesters import _classify_tool_outcome, parse_claude_jsonl
|
|
1451
|
+
from tokenblame.store import write_observatory_store
|
|
1452
|
+
|
|
1453
|
+
# Numeric HTTP status=200 must NEVER be misclassified as a non-zero process exit code
|
|
1454
|
+
self.assertEqual(_classify_tool_outcome({"status": 200}), "unknown")
|
|
1455
|
+
self.assertEqual(_classify_tool_outcome({"exitCode": 200}), "error")
|
|
1456
|
+
|
|
1457
|
+
def _write_claude(path: Path, outcomes: list[bool | None], *, reverse_results: bool = False) -> None:
|
|
1458
|
+
lines = []
|
|
1459
|
+
pending_res = []
|
|
1460
|
+
for idx, is_err in enumerate(outcomes, start=1):
|
|
1461
|
+
tid = f"toolu_{idx}"
|
|
1462
|
+
lines.append(json.dumps({
|
|
1463
|
+
"sessionId": path.stem,
|
|
1464
|
+
"requestId": f"req_{idx}",
|
|
1465
|
+
"timestamp": f"2026-11-26T05:0{idx}:00Z",
|
|
1466
|
+
"cwd": "/tmp/demo",
|
|
1467
|
+
"message": {
|
|
1468
|
+
"model": "claude-opus-5-5",
|
|
1469
|
+
"content": [{
|
|
1470
|
+
"type": "tool_use",
|
|
1471
|
+
"id": tid,
|
|
1472
|
+
"name": "Bash",
|
|
1473
|
+
"input": {"command": "pytest tests/secret_case.py --token=SUPER_SECRET_ARG"},
|
|
1474
|
+
}],
|
|
1475
|
+
"usage": {"input_tokens": 500, "cache_read_input_tokens": 2000, "output_tokens": 1200},
|
|
1476
|
+
},
|
|
1477
|
+
}))
|
|
1478
|
+
if is_err is not None:
|
|
1479
|
+
res_line = json.dumps({
|
|
1480
|
+
"sessionId": path.stem,
|
|
1481
|
+
"timestamp": f"2026-11-26T05:0{idx}:05Z",
|
|
1482
|
+
"message": {
|
|
1483
|
+
"role": "user",
|
|
1484
|
+
"content": [{
|
|
1485
|
+
"type": "tool_result",
|
|
1486
|
+
"tool_use_id": tid,
|
|
1487
|
+
"is_error": is_err,
|
|
1488
|
+
"content": "SECRET_STDOUT_LEAK_CANARY exit code 1" if is_err else "SECRET_STDOUT_LEAK_CANARY ok",
|
|
1489
|
+
}],
|
|
1490
|
+
},
|
|
1491
|
+
})
|
|
1492
|
+
if reverse_results:
|
|
1493
|
+
pending_res.append(res_line)
|
|
1494
|
+
else:
|
|
1495
|
+
lines.append(res_line)
|
|
1496
|
+
if reverse_results:
|
|
1497
|
+
lines.extend(reversed(pending_res))
|
|
1498
|
+
path.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
|
1499
|
+
|
|
1500
|
+
with tempfile.TemporaryDirectory() as td:
|
|
1501
|
+
fail_p = Path(td) / "sess-fail.jsonl"
|
|
1502
|
+
ok_p = Path(td) / "sess-iter.jsonl"
|
|
1503
|
+
unk_p = Path(td) / "sess-unknown.jsonl"
|
|
1504
|
+
# Out-of-order parallel results still pair accurately by call ID
|
|
1505
|
+
_write_claude(fail_p, [True, True, True, True, True, False], reverse_results=True)
|
|
1506
|
+
_write_claude(ok_p, [False, False, False, False, False, False], reverse_results=True)
|
|
1507
|
+
# Missing / unobserved results (None) MUST NOT be classified as iteration/success!
|
|
1508
|
+
_write_claude(unk_p, [None, None, None, None, None, False])
|
|
1509
|
+
|
|
1510
|
+
rec_fail = parse_claude_jsonl(fail_p)[0]
|
|
1511
|
+
rec_iter = parse_claude_jsonl(ok_p)[0]
|
|
1512
|
+
rec_unk = parse_claude_jsonl(unk_p)[0]
|
|
1513
|
+
|
|
1514
|
+
self.assertEqual(rec_fail.forensics["loop_kind"], "failure")
|
|
1515
|
+
self.assertIn("FAILURE_LOOP(Bash:pytest x6, err=5/6)", rec_fail.forensics["loop_warning"])
|
|
1516
|
+
self.assertEqual(rec_fail.forensics["loop_outcomes"]["observed_error"], 5)
|
|
1517
|
+
self.assertEqual(rec_fail.forensics["loop_outcomes"]["observed_success"], 1)
|
|
1518
|
+
|
|
1519
|
+
self.assertEqual(rec_iter.forensics["loop_kind"], "iteration")
|
|
1520
|
+
self.assertIn("ITERATION_LOOP(Bash:pytest x6, ok=6/6)", rec_iter.forensics["loop_warning"])
|
|
1521
|
+
|
|
1522
|
+
# 5 unknown + 1 ok -> coverage 1/6 (< 50%) -> MUST stay unclassified, NOT iteration!
|
|
1523
|
+
self.assertEqual(rec_unk.forensics["loop_kind"], "unclassified")
|
|
1524
|
+
self.assertEqual(rec_unk.forensics["loop_outcomes"]["unknown_outcome"], 5)
|
|
1525
|
+
|
|
1526
|
+
# End-to-end secret canary check across IR, HTML, and SQLite
|
|
1527
|
+
ir = build_observatory_ir(
|
|
1528
|
+
sessions=[rec_fail, rec_iter, rec_unk], commits=[], episodes=[],
|
|
1529
|
+
repo_map={}, harvest_stats={}, discover_repos=False,
|
|
1530
|
+
)
|
|
1531
|
+
html_out = render_observatory_html(ir)
|
|
1532
|
+
db_path = Path(td) / "obs.sqlite"
|
|
1533
|
+
write_observatory_store(db_path, ir, [rec_fail, rec_iter, rec_unk], [], [])
|
|
1534
|
+
db_raw = db_path.read_bytes().decode("utf-8", errors="ignore")
|
|
1535
|
+
for canary in ("SUPER_SECRET_ARG", "SECRET_STDOUT_LEAK_CANARY"):
|
|
1536
|
+
self.assertNotIn(canary, json.dumps(ir))
|
|
1537
|
+
self.assertNotIn(canary, html_out)
|
|
1538
|
+
self.assertNotIn(canary, db_raw)
|
|
1539
|
+
|
|
1322
1540
|
|
|
1323
1541
|
if __name__ == "__main__":
|
|
1324
1542
|
unittest.main()
|