tokenblame 2.2.1__tar.gz → 2.2.2__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.
Files changed (22) hide show
  1. {tokenblame-2.2.1 → tokenblame-2.2.2}/PKG-INFO +1 -1
  2. {tokenblame-2.2.1 → tokenblame-2.2.2}/pyproject.toml +1 -1
  3. {tokenblame-2.2.1 → tokenblame-2.2.2}/tests/test_observatory.py +36 -1
  4. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame/harvesters.py +12 -8
  5. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame/joiner.py +13 -6
  6. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame.egg-info/PKG-INFO +1 -1
  7. {tokenblame-2.2.1 → tokenblame-2.2.2}/LICENSE +0 -0
  8. {tokenblame-2.2.1 → tokenblame-2.2.2}/README.md +0 -0
  9. {tokenblame-2.2.1 → tokenblame-2.2.2}/setup.cfg +0 -0
  10. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame/__init__.py +0 -0
  11. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame/cli.py +0 -0
  12. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame/hooks.py +0 -0
  13. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame/provenance.py +0 -0
  14. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame/redact.py +0 -0
  15. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame/render.py +0 -0
  16. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame/schema.py +0 -0
  17. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame/store.py +0 -0
  18. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame/survival.py +0 -0
  19. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame.egg-info/SOURCES.txt +0 -0
  20. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame.egg-info/dependency_links.txt +0 -0
  21. {tokenblame-2.2.1 → tokenblame-2.2.2}/tokenblame.egg-info/entry_points.txt +0 -0
  22. {tokenblame-2.2.1 → tokenblame-2.2.2}/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.2.1
3
+ Version: 2.2.2
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tokenblame"
7
- version = "2.2.1"
7
+ version = "2.2.2"
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"
@@ -1386,6 +1386,38 @@ class TestObservatoryAdversarial(unittest.TestCase):
1386
1386
  self.assertEqual(c_mix["t30d"]["matured_commits"], 1)
1387
1387
  self.assertEqual(c_mix["t30d"]["not_yet_commits"], 1)
1388
1388
 
1389
+ # Survival cache in build_observatory_ir MUST recompute when as_of_epoch day changes on same HEAD
1390
+ cache_db = Path(td) / "surv_cache.sqlite"
1391
+ s_day0 = SessionRecord(
1392
+ session_id="sess-day0", provider="claude", model="claude-opus-5-5",
1393
+ status="MEASURED", bucket_fidelity="4_bucket", day="2025-06-15",
1394
+ timestamp="2025-06-15T00:00:00+00:00", epoch_sec=float(day0),
1395
+ cwd=str(repo.resolve()), git_sha=oid_day0,
1396
+ buckets=TokenBuckets(uncached_input=100, cached_read=200, visible_output=300),
1397
+ )
1398
+ c_list = [{
1399
+ "oid": oid_day0, "short_oid": oid_day0[:8], "day": "2025-06-15",
1400
+ "epoch_sec": float(day0), "committer_epoch": float(day0),
1401
+ "clock_ts": "2025-06-15T00:00:00+00:00", "lanes": ["Projects"],
1402
+ "repos": ["cohort-repo"], "repo_root": str(repo.resolve()),
1403
+ "subject": "day0 add 10 lines",
1404
+ }]
1405
+ ir_early = build_observatory_ir(
1406
+ sessions=[s_day0], commits=c_list, episodes=[],
1407
+ repo_map={str(repo.resolve()): ("Projects", "cohort-repo")},
1408
+ harvest_stats={}, cache_db=cache_db, discover_repos=False,
1409
+ compute_survival=True, as_of_epoch=float(day0 + 10 * 86400),
1410
+ )
1411
+ ir_matured = build_observatory_ir(
1412
+ sessions=[s_day0], commits=c_list, episodes=[],
1413
+ repo_map={str(repo.resolve()): ("Projects", "cohort-repo")},
1414
+ harvest_stats={}, cache_db=cache_db, discover_repos=False,
1415
+ compute_survival=True, as_of_epoch=float(day100),
1416
+ )
1417
+ self.assertEqual(ir_early["totals"]["durability"]["cohorts"]["t30d"]["matured_commits"], 0)
1418
+ self.assertEqual(ir_matured["totals"]["durability"]["cohorts"]["t30d"]["matured_commits"], 1)
1419
+ self.assertEqual(ir_matured["totals"]["durability"]["cohorts"]["t30d"]["retention_pct"], 100.0)
1420
+
1389
1421
  def test_recency_single_quiet_commit_never_claims_exact_hook_oid(self):
1390
1422
  import subprocess
1391
1423
  from tokenblame.provenance import record_hook_invocation
@@ -1450,9 +1482,12 @@ class TestObservatoryAdversarial(unittest.TestCase):
1450
1482
  from tokenblame.harvesters import _classify_tool_outcome, parse_claude_jsonl
1451
1483
  from tokenblame.store import write_observatory_store
1452
1484
 
1453
- # Numeric HTTP status=200 must NEVER be misclassified as a non-zero process exit code
1485
+ # Numeric HTTP status=200 and plain strings without explicit exit status MUST stay "unknown"
1454
1486
  self.assertEqual(_classify_tool_outcome({"status": 200}), "unknown")
1455
1487
  self.assertEqual(_classify_tool_outcome({"exitCode": 200}), "error")
1488
+ self.assertEqual(_classify_tool_outcome("some output without exit code"), "unknown")
1489
+ self.assertEqual(_classify_tool_outcome({"type": "tool_result", "content": "plain text"}), "unknown")
1490
+ self.assertEqual(_classify_tool_outcome("Exit code 0: ok"), "success")
1456
1491
 
1457
1492
  def _write_claude(path: Path, outcomes: list[bool | None], *, reverse_results: bool = False) -> None:
1458
1493
  lines = []
@@ -16,7 +16,7 @@ from tokenblame.schema import SessionRecord, TokenBuckets, resolve_local_tz
16
16
 
17
17
  SEOUL_TZ = ZoneInfo("Asia/Seoul")
18
18
  CACHE_SCHEMA_VERSION = 2
19
- PARSER_REVISION = "v2.1"
19
+ PARSER_REVISION = "v2.2"
20
20
  COMMIT_STDOUT_RE = re.compile(
21
21
  r"\[(?:[\w./-]+(?:\s+\(root-commit\))?|detached HEAD)\s+([0-9a-f]{7,40})\]\s+\S"
22
22
  )
@@ -156,17 +156,21 @@ def _classify_tool_outcome(text_or_obj: Any, *, explicit_result_present: bool =
156
156
  return _classify_tool_outcome(text_or_obj[tk], explicit_result_present=True)
157
157
  return "unknown"
158
158
  if isinstance(text_or_obj, list):
159
- saw_text = False
159
+ saw_explicit_ok = False
160
160
  for item in text_or_obj:
161
161
  if isinstance(item, dict) and isinstance(item.get("text"), str):
162
- saw_text = True
163
- if _classify_tool_outcome(item["text"], explicit_result_present=True) == "error":
162
+ sub = _classify_tool_outcome(item["text"], explicit_result_present=True)
163
+ if sub == "error":
164
164
  return "error"
165
+ if sub == "success":
166
+ saw_explicit_ok = True
165
167
  elif isinstance(item, str):
166
- saw_text = True
167
- if _classify_tool_outcome(item, explicit_result_present=True) == "error":
168
+ sub = _classify_tool_outcome(item, explicit_result_present=True)
169
+ if sub == "error":
168
170
  return "error"
169
- return "success" if saw_text else "unknown"
171
+ if sub == "success":
172
+ saw_explicit_ok = True
173
+ return "success" if saw_explicit_ok else "unknown"
170
174
  if isinstance(text_or_obj, str):
171
175
  m = _EXIT_CODE_RE.search(text_or_obj[:400])
172
176
  if m:
@@ -174,7 +178,7 @@ def _classify_tool_outcome(text_or_obj: Any, *, explicit_result_present: bool =
174
178
  return "error" if int(m.group(1)) != 0 else "success"
175
179
  except ValueError:
176
180
  return "unknown"
177
- return "success"
181
+ return "unknown"
178
182
  return "unknown"
179
183
 
180
184
 
@@ -465,6 +465,7 @@ def build_observatory_ir(
465
465
  discover_repos: bool = True,
466
466
  compute_survival: Optional[bool] = None,
467
467
  nocheat_verdicts: Optional[list[dict[str, Any]]] = None,
468
+ as_of_epoch: Optional[float] = None,
468
469
  ) -> dict[str, Any]:
469
470
  """Perform full local Git discovery + 3-way attribution join with 4-tier classification."""
470
471
  # Merge Orca worktree paths + provenance repo paths into full repo_map if enabled
@@ -748,7 +749,9 @@ def build_observatory_ir(
748
749
  ai_oids_by_repo: dict[str, list[str]] = {}
749
750
  ai_commits_all_by_repo: dict[str, list[dict[str, Any]]] = {}
750
751
  max_commit_ep = max((float(c.get("epoch_sec") or 0.0) for c in all_commits), default=0.0)
751
- cutoff_30d_ep = max_commit_ep - (30.0 * 86400.0) if max_commit_ep > 0 else 0.0
752
+ eff_as_of_ep = float(as_of_epoch) if as_of_epoch is not None else dt.datetime.now(dt.timezone.utc).timestamp()
753
+ as_of_day = dt.datetime.fromtimestamp(eff_as_of_ep, tz=dt.timezone.utc).strftime("%Y-%m-%d")
754
+ cutoff_30d_ep = eff_as_of_ep - (30.0 * 86400.0) if eff_as_of_ep > 0 else 0.0
752
755
 
753
756
  for s in sessions:
754
757
  if s.status == "MEASURED":
@@ -809,21 +812,25 @@ def build_observatory_ir(
809
812
  continue
810
813
  if not head_oid:
811
814
  continue
812
- cached_surv = scache.get_repo_survival(rroot, head_oid) if scache else None
815
+ recent_ai = ai_oids_by_repo.get(rroot, [])
816
+ all_ai_repo = ai_commits_all_by_repo.get(rroot, [])
817
+ oids_sig_src = "|".join(sorted(recent_ai)) + "||" + "|".join(sorted(str(x.get("oid") or "") for x in all_ai_repo))
818
+ oids_digest = hashlib.sha256(oids_sig_src.encode("utf-8")).hexdigest()[:12]
819
+ surv_cache_key = f"{head_oid}|asof:{as_of_day}|oids:{oids_digest}"
820
+ cached_surv = scache.get_repo_survival(rroot, surv_cache_key) if scache else None
813
821
  if cached_surv is None or cached_surv.get("cohort_schema") != "historical_v2":
814
822
  rev_map = (cached_surv or {}).get("reverts") if cached_surv else scan_repo_reverts(rroot, commits_grouped_by_repo[rroot])
815
- recent_ai = ai_oids_by_repo.get(rroot, [])
816
823
  lsurv = (
817
824
  measure_30d_line_survival(rroot, recent_ai, snapshot_oid=head_oid)
818
825
  if recent_ai
819
826
  else {"added_lines": 0, "surviving_lines": 0, "unobserved_lines": 0}
820
827
  )
821
828
  cohorts_r = measure_cohort_line_survival(
822
- rroot, ai_commits_all_by_repo.get(rroot, []), as_of_epoch=max_commit_ep, ref=head_oid
829
+ rroot, all_ai_repo, as_of_epoch=eff_as_of_ep, ref=head_oid
823
830
  )
824
- cached_surv = {"cohort_schema": "historical_v2", "reverts": rev_map, "line_survival": lsurv, "cohorts": cohorts_r}
831
+ cached_surv = {"cohort_schema": "historical_v2", "as_of_day": as_of_day, "reverts": rev_map, "line_survival": lsurv, "cohorts": cohorts_r}
825
832
  if scache is not None:
826
- scache.put_repo_survival(rroot, head_oid, cached_surv)
833
+ scache.put_repo_survival(rroot, surv_cache_key, cached_surv)
827
834
  global_reverts.update(cached_surv.get("reverts") or {})
828
835
  ls = cached_surv.get("line_survival") or {}
829
836
  r_add = int(ls.get("added_lines") or 0)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tokenblame
3
- Version: 2.2.1
3
+ Version: 2.2.2
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
File without changes
File without changes
File without changes
File without changes