cc-continuity 0.3.40__tar.gz → 0.3.41__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 (112) hide show
  1. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/PKG-INFO +1 -1
  2. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/README.md +1 -1
  3. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/__init__.py +1 -1
  4. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/hooks/common.py +3 -0
  5. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/statusline.py +95 -1
  6. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity.egg-info/PKG-INFO +1 -1
  7. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/pyproject.toml +1 -1
  8. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_hooks_common.py +31 -0
  9. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_statusline.py +132 -0
  10. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/LICENSE +0 -0
  11. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/__main__.py +0 -0
  12. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/atomic.py +0 -0
  13. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/blink.py +0 -0
  14. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/blink_watch.py +0 -0
  15. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/bootstrap.py +0 -0
  16. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/checkpoint.py +0 -0
  17. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/cli.py +0 -0
  18. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/config.py +0 -0
  19. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/daemon_supervisor.py +0 -0
  20. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/doctor.py +0 -0
  21. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/gitsnap.py +0 -0
  22. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/hooks/__init__.py +0 -0
  23. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/hooks/pre_compact.py +0 -0
  24. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/hooks/pre_tool_use.py +0 -0
  25. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/hooks/session_end.py +0 -0
  26. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/hooks/session_start.py +0 -0
  27. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/hooks/stop.py +0 -0
  28. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/hooks/task.py +0 -0
  29. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/hooks/tool_use.py +0 -0
  30. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/hooks/user_prompt.py +0 -0
  31. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/hosting.py +0 -0
  32. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/install.py +0 -0
  33. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/launch.py +0 -0
  34. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/ledger.py +0 -0
  35. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/lock.py +0 -0
  36. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/managed.py +0 -0
  37. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/naming.py +0 -0
  38. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/notify.py +0 -0
  39. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/paths.py +0 -0
  40. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/power_plug.py +0 -0
  41. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/progress_pane.py +0 -0
  42. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/project.py +0 -0
  43. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/redact.py +0 -0
  44. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/rotator.py +0 -0
  45. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/settings_merge.py +0 -0
  46. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/skills.py +0 -0
  47. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/state.py +0 -0
  48. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/thresholds.py +0 -0
  49. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/transcript.py +0 -0
  50. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/validate.py +0 -0
  51. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/watchdog.py +0 -0
  52. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/watchdog_digest.py +0 -0
  53. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity/watchdogd.py +0 -0
  54. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity.egg-info/SOURCES.txt +0 -0
  55. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity.egg-info/dependency_links.txt +0 -0
  56. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity.egg-info/entry_points.txt +0 -0
  57. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/cc_continuity.egg-info/top_level.txt +0 -0
  58. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/setup.cfg +0 -0
  59. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_atomic.py +0 -0
  60. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_blink.py +0 -0
  61. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_blink_watch.py +0 -0
  62. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_bootstrap.py +0 -0
  63. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_checkpoint.py +0 -0
  64. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_cli.py +0 -0
  65. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_cli_ledger.py +0 -0
  66. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_config.py +0 -0
  67. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_daemon_supervisor.py +0 -0
  68. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_doctor.py +0 -0
  69. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_gitsnap.py +0 -0
  70. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_hooks_pre_compact.py +0 -0
  71. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_hooks_pre_tool_use.py +0 -0
  72. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_hooks_session_end.py +0 -0
  73. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_hooks_session_start.py +0 -0
  74. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_hooks_stop.py +0 -0
  75. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_hooks_task.py +0 -0
  76. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_hooks_tool_use.py +0 -0
  77. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_hooks_user_prompt.py +0 -0
  78. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_hosting.py +0 -0
  79. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_hygiene.py +0 -0
  80. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_install.py +0 -0
  81. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_integration_phase5.py +0 -0
  82. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_integration_phase6.py +0 -0
  83. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_integration_phase7.py +0 -0
  84. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_launch.py +0 -0
  85. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_ledger.py +0 -0
  86. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_lock.py +0 -0
  87. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_managed.py +0 -0
  88. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_naming.py +0 -0
  89. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_notify.py +0 -0
  90. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_notify_integration.py +0 -0
  91. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_paths.py +0 -0
  92. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_power_plug.py +0 -0
  93. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_progress_pane.py +0 -0
  94. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_project.py +0 -0
  95. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_redact.py +0 -0
  96. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_rotator.py +0 -0
  97. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_settings_merge.py +0 -0
  98. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_skills.py +0 -0
  99. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_state.py +0 -0
  100. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_status.py +0 -0
  101. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_thresholds.py +0 -0
  102. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_tmux_host.py +0 -0
  103. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_transcript.py +0 -0
  104. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_transcript_finalize.py +0 -0
  105. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_uninstall.py +0 -0
  106. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_validate.py +0 -0
  107. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_watchdog.py +0 -0
  108. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_watchdog_digest.py +0 -0
  109. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_watchdog_integration.py +0 -0
  110. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_watchdogd.py +0 -0
  111. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_wsl_doctor.py +0 -0
  112. {cc_continuity-0.3.40 → cc_continuity-0.3.41}/tests/test_wsl_install.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cc-continuity
3
- Version: 0.3.40
3
+ Version: 0.3.41
4
4
  Summary: Zero-touch session rotation for Claude Code (local large-context model)
5
5
  Requires-Python: >=3.11
6
6
  License-File: LICENSE
@@ -26,11 +26,11 @@ The five most recent updates, newest first. Each line links to its
26
26
  commit, so you can see what changed lately without digging through the
27
27
  log:
28
28
 
29
+ - **2026-11-17**: Zombie panes are measured now too. After the 0.3.40 revival, Claude Code still rendered the status line with the abandoned startup session id, so the ratio metric kept landing on the dead id: the pane showed a ratio while the tracked session never moved (measurement without reaction). The hook entry now stamps a pane-scoped binding with the session id it actually runs as, and the status line writes its metric under it whenever that binding is fresh and names a different live session. Non-tmux runs and normal panes behave byte-for-byte exactly as before ([commit](https://github.com/pqant/claude-continuity/commit/361b7b1)).
29
30
  - **2026-11-16**: Zombie sessions are gone. Claude Code remembers the last conversation it opened per project (lastSessionId); a plain `claude` could reopen a conversation that died in a rotation and then run forever unmonitored (no ratio movement, no rotation, and the handoff chain silently broken). Now a resumed conversation whose session id is no longer alive is anchored onto the open chain tip under the same index, handed the bootstrap protocol, and taken over by the normal monitoring; live resumes behave exactly as before ([commit](https://github.com/pqant/claude-continuity/commit/dbaea33)).
30
31
  - **2026-11-16**: The transcript fold arrows are anchored: both triangles now share one slot at the true screen center of the header (the previous version centered against the controls row, which spans only the left half of the header grid, so the arrow sat off-center over the theme button), they carry a red tint (a deeper red in light theme, a lighter red in dark theme), and folding keeps the reopen arrow in the very same spot so the button never jumps ([commit](https://github.com/pqant/claude-continuity/commit/1ca6ad5), [commit](https://github.com/pqant/claude-continuity/commit/e33874d)).
31
32
  - **2026-11-16**: The transcript density view got its polish pass: the two panel toggles are plain filled triangles now (the up-triangle folds the header panel into the slim bar, the down-triangle brings it back, and the words live in the tooltips), the fold eases closed over 180 ms instead of snapping, and the folded bar only spans the left column when the 2-column mode is on, with the fold arrow sitting centered in the controls row in the theme's accent color. The "2-column · 75%" mode opens enabled by default now; unchecking it is still remembered in your browser ([commit](https://github.com/pqant/claude-continuity/commit/3959db9), [commit](https://github.com/pqant/claude-continuity/commit/7feba54)).
32
33
  - **2026-11-15**: The transcript header panel gets out of the way: "panel up" folds it into a slim one-line bar carrying the session name, "panel down" brings the full panel back, and a new "2-column · 75%" checkbox in the controls row re-flows the whole conversation into two balanced columns at reduced zoom, so a screen holds roughly twice the conversation. Both choices persist in your browser; search, theme, sessions switcher and the image lightbox behave exactly the same in every state ([commit](https://github.com/pqant/claude-continuity/commit/594820d), [commit](https://github.com/pqant/claude-continuity/commit/2450369)).
33
- - **2026-11-14**: The overlay's prev/next row now hides when there is nothing to navigate: it used to sit under the icon chip's note text and next to single-image galleries, because the row's author CSS rule overrode the [hidden] attribute. Both the CSS rule and a count-based toggle are in place now, so navigation appears only with two or more images and the i / n counter stays untouched ([commit](https://github.com/pqant/claude-continuity/commit/15ada27)).
34
34
 
35
35
  ## How it works
36
36
 
@@ -4,4 +4,4 @@ Spec: docs/PRD.md (v1.0). Platform facts verified in docs/VERIFICATION.md.
4
4
  Standard library only at runtime; pytest is dev-only.
5
5
  """
6
6
 
7
- __version__ = "0.3.40"
7
+ __version__ = "0.3.41"
@@ -156,6 +156,9 @@ def run_event(event: str, text: str | bytes, handlers: dict[str, Handler]) -> in
156
156
  if _is_disabled(cfg, session):
157
157
  return 0
158
158
  _export_session_env(payload.get("session_id"))
159
+ # issue #71: tell the status line which sid THIS pane's hooks run
160
+ # as (zombie panes keep rendering under the abandoned startup sid).
161
+ statusline.stamp_pane_binding(payload.get("session_id"))
159
162
  handler = handlers.get(event)
160
163
  if handler is None:
161
164
  return 0
@@ -28,6 +28,7 @@ import os
28
28
  import re
29
29
  import subprocess
30
30
  import time
31
+ from datetime import datetime
31
32
  from pathlib import Path
32
33
 
33
34
  from . import atomic, blink, config, ledger, naming, paths, transcript
@@ -376,6 +377,92 @@ def find_session_by_id(session_id: str | None) -> dict | None:
376
377
  return None
377
378
 
378
379
 
380
+ #: Issue #71: states where the pane's tracked session still consumes the
381
+ #: metric (BOOTSTRAPPING waiting for its claim, ACTIVE watched by gates).
382
+ _RETARGET_STATES = frozenset({"BOOTSTRAPPING", "ACTIVE"})
383
+
384
+
385
+ def _pane_binding():
386
+ """``(path, pane)`` of this process's pane binding, or ``(None, None)``."""
387
+ pane = os.environ.get("TMUX_PANE", "").strip()
388
+ if not pane:
389
+ return None, None
390
+ safe = re.sub(r"[^A-Za-z0-9%_.-]", "_", pane)[:64]
391
+ return paths.runtime_dir() / "panes" / f"pane-{safe}.json", pane
392
+
393
+
394
+ def stamp_pane_binding(session_id: object) -> None:
395
+ """Record which sid the current pane's hooks run as (issue #71).
396
+
397
+ After a dead-sid auto-resume (#42) CC's status line payload keeps the
398
+ abandoned startup sid while the hooks keep firing as the resumed
399
+ conversation's sid. ``hooks.common.run_event`` stamps this binding on
400
+ every hook event; ``run`` retargets the metric onto it so the gate
401
+ stops starving. Pane-scoped (TMUX_PANE), so panes can never hijack
402
+ each other's metric. Fail-open (the hook never notices).
403
+ """
404
+ if not isinstance(session_id, str) or not session_id:
405
+ return
406
+ path, pane = _pane_binding()
407
+ if path is None:
408
+ return
409
+ try:
410
+ path.parent.mkdir(parents=True, exist_ok=True)
411
+ atomic.atomic_write_json(path, {"pane": pane,
412
+ "session_id": session_id,
413
+ "ts": time.time()})
414
+ except OSError:
415
+ pass
416
+
417
+
418
+ def _pane_bound_sid(payload_sid):
419
+ """The bound sid to retarget this render's metric to, or None.
420
+
421
+ Redirect only when ALL of: we are in a tmux pane, the binding is fresh
422
+ (< STALE_SECONDS, same gate as metrics), it names a different sid, and
423
+ the bound record is BOOTSTRAPPING/ACTIVE and not off. The payload
424
+ record's state is deliberately NOT a gate: a plain startup registers
425
+ in ACTIVE (Phase 5), so the abandoned zombie record looks healthy
426
+ locally - the pane's hooks are the trusted authority on which
427
+ conversation is live (CC renders the status line with the stale sid,
428
+ issue #42 evidence). The binding must not predate the payload record's
429
+ creation (same-pane sequential claude must not inherit the previous
430
+ session's binding). Any doubt -> None -> today's byte-identical write.
431
+ """
432
+ if not payload_sid:
433
+ return None
434
+ path, _pane = _pane_binding()
435
+ if path is None:
436
+ return None
437
+ try:
438
+ binding = json.loads(path.read_text(encoding="utf-8"))
439
+ except (OSError, json.JSONDecodeError):
440
+ return None
441
+ if not isinstance(binding, dict):
442
+ return None
443
+ sid = binding.get("session_id")
444
+ ts = binding.get("ts")
445
+ if (not isinstance(sid, str) or not sid or sid == payload_sid
446
+ or not isinstance(ts, (int, float)) or isinstance(ts, bool)
447
+ or time.time() - ts > STALE_SECONDS):
448
+ return None
449
+ bound = find_session_by_id(sid)
450
+ if (not isinstance(bound, dict) or bound.get("off")
451
+ or bound.get("state") not in _RETARGET_STATES):
452
+ return None
453
+ payload_rec = find_session_by_id(payload_sid)
454
+ if isinstance(payload_rec, dict):
455
+ created = payload_rec.get("created")
456
+ if isinstance(created, str):
457
+ try:
458
+ created_ts = datetime.fromisoformat(created).timestamp()
459
+ except ValueError:
460
+ return None # unparseable: stay on today's behavior
461
+ if ts < created_ts:
462
+ return None
463
+ return sid
464
+
465
+
379
466
  def render_segment(ratio: float | None, record: dict | None,
380
467
  enabled: bool, blocked: str | None = None,
381
468
  *, ansi: bool = True,
@@ -654,10 +741,17 @@ def run(stdin_bytes: bytes, cfg: dict) -> str:
654
741
  if enabled:
655
742
  window = cfg.get("window_tokens") or 0
656
743
  metric = extract_metric(payload, window)
744
+ # issue #71: the pane's hook-stamped binding names the sid the
745
+ # session is actually tracked under; a zombie render (abandoned
746
+ # startup sid) must write under it, else the gate starves.
747
+ bound = (_pane_bound_sid(payload.get("session_id"))
748
+ if payload is not None else None)
657
749
  if metric is not None:
750
+ if bound is not None:
751
+ metric = dict(metric, session_id=bound)
658
752
  write_metric(metric)
659
753
  if payload is not None:
660
- record = find_session_by_id(payload.get("session_id"))
754
+ record = find_session_by_id(bound or payload.get("session_id"))
661
755
 
662
756
  ratio = metric["ratio"] if metric is not None else None
663
757
  blocked = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cc-continuity
3
- Version: 0.3.40
3
+ Version: 0.3.41
4
4
  Summary: Zero-touch session rotation for Claude Code (local large-context model)
5
5
  Requires-Python: >=3.11
6
6
  License-File: LICENSE
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cc-continuity"
7
- version = "0.3.40"
7
+ version = "0.3.41"
8
8
  description = "Zero-touch session rotation for Claude Code (local large-context model)"
9
9
  requires-python = ">=3.11"
10
10
  dependencies = [] # stdlib only at runtime (PRD §0.5)
@@ -240,3 +240,34 @@ def test_notify_claimed_rows_1_and_6(cc_home, monkeypatch):
240
240
  "validation": "MISMATCH"}
241
241
  common.notify_claimed(dict(notify.config.DEFAULTS), "k1", res)
242
242
  assert fired == ["session_started"]
243
+
244
+
245
+ # ------------------------------------------ issue #71: pane binding stamp
246
+
247
+
248
+ def test_hook_stamps_pane_binding(cc_home, tmp_path, monkeypatch):
249
+ from hookutil import SID, payload, run_hook
250
+ repo = make_repo(tmp_path)
251
+ monkeypatch.setenv("TMUX_PANE", "%7")
252
+ run_hook("PostToolUse", payload("PostToolUse", repo))
253
+ binding = json.loads(
254
+ (cc_home / "runtime" / "panes" / "pane-%7.json").read_text(
255
+ encoding="utf-8"))
256
+ assert binding["session_id"] == SID and binding["pane"] == "%7"
257
+ assert isinstance(binding["ts"], (int, float))
258
+
259
+
260
+ def test_disabled_hook_stamps_no_binding(cc_home, tmp_path, monkeypatch):
261
+ from hookutil import payload, run_hook
262
+ repo = make_repo(tmp_path)
263
+ monkeypatch.setenv("TMUX_PANE", "%7")
264
+ monkeypatch.setenv("CC_CONTINUITY", "0")
265
+ run_hook("PostToolUse", payload("PostToolUse", repo))
266
+ assert not (cc_home / "runtime" / "panes" / "pane-%7.json").exists()
267
+
268
+
269
+ def test_no_tmux_no_binding(cc_home, tmp_path):
270
+ from hookutil import payload, run_hook
271
+ repo = make_repo(tmp_path)
272
+ run_hook("PostToolUse", payload("PostToolUse", repo))
273
+ assert not (cc_home / "runtime" / "panes" / "pane-%7.json").exists()
@@ -1485,3 +1485,135 @@ def test_run_unreadable_transcript_omits_prev_task(cc_home):
1485
1485
  json.dumps(_payload(transcript_path="/nonexistent/x.jsonl")).encode(),
1486
1486
  _cfg(statusline_ansi=False, turn_clock=True))
1487
1487
  assert line == "◆ 9% Active Usage"
1488
+
1489
+
1490
+ # ------------------------------- issue #71: pane-bound metric retargeting
1491
+ #
1492
+ # Zombie pane (the #42 follow-up): after a dead-sid auto-resume the
1493
+ # statusline payload keeps the ABANDONED startup sid while the hooks keep
1494
+ # firing as the resumed conversation's sid; the hook entry stamps a
1495
+ # ``runtime/panes/pane-<TMUX_PANE>.json`` binding and the metric must be
1496
+ # written under the bound sid, else the gate starves (no reaction).
1497
+
1498
+ SID_BOUND = "11111111-7777-8888-9999-000000000071"
1499
+
1500
+
1501
+ def _write_binding(pane, session_id, ts):
1502
+ d = paths.runtime_dir() / "panes"
1503
+ d.mkdir(parents=True, exist_ok=True)
1504
+ (d / f"pane-{pane}.json").write_text(
1505
+ json.dumps({"pane": pane, "session_id": session_id, "ts": ts}),
1506
+ encoding="utf-8")
1507
+
1508
+
1509
+ def _zombie_payload(repo, session_id):
1510
+ return {
1511
+ "session_id": session_id,
1512
+ "cwd": str(repo),
1513
+ "context_window": {
1514
+ "context_window_size": 262144,
1515
+ "current_usage": {
1516
+ "input_tokens": 131072,
1517
+ "output_tokens": 0,
1518
+ "cache_creation_input_tokens": 0,
1519
+ "cache_read_input_tokens": 0,
1520
+ },
1521
+ },
1522
+ }
1523
+
1524
+
1525
+ def test_run_redirects_metric_to_pane_bound_sid(cc_home, tmp_path, monkeypatch):
1526
+ from cc_continuity import ledger
1527
+ from hookutil import SID, make_repo, register_session
1528
+ repo = make_repo(tmp_path)
1529
+ key, _n_start = register_session(repo) # abandoned startup record
1530
+ _key, n_bound = register_session(repo, SID_BOUND)
1531
+ state.transition(key, n_bound, "ACTIVE")
1532
+ # the blocked marker sits on the BOUND session only: the rendered line
1533
+ # proves the whole render switched to the bound record, not just the file.
1534
+ ledger.append(paths.session_dir(key, n_bound),
1535
+ {"type": "needs_human", "reason": "drop db?"})
1536
+ _write_binding("%1", SID_BOUND, time.time())
1537
+ monkeypatch.setenv("TMUX_PANE", "%1")
1538
+ line = statusline.run(
1539
+ json.dumps(_zombie_payload(repo, SID)).encode(),
1540
+ dict(config.DEFAULTS, statusline_ansi=False))
1541
+ assert line == "◆ 50% Active Usage ⛔ BLOCKED"
1542
+ assert (paths.runtime_dir() / f"{SID_BOUND}.json").exists()
1543
+ assert not (paths.runtime_dir() / f"{SID}.json").exists()
1544
+
1545
+
1546
+ def test_run_binding_same_sid_writes_under_payload_sid(cc_home, tmp_path,
1547
+ monkeypatch):
1548
+ from hookutil import SID, make_repo, register_session
1549
+ repo = make_repo(tmp_path)
1550
+ register_session(repo)
1551
+ _write_binding("%1", SID, time.time())
1552
+ monkeypatch.setenv("TMUX_PANE", "%1")
1553
+ statusline.run(json.dumps(_zombie_payload(repo, SID)).encode(),
1554
+ dict(config.DEFAULTS, statusline_ansi=False))
1555
+ assert (paths.runtime_dir() / f"{SID}.json").exists()
1556
+
1557
+
1558
+ def test_run_stale_binding_does_not_redirect(cc_home, tmp_path, monkeypatch):
1559
+ from hookutil import SID, make_repo, register_session
1560
+ repo = make_repo(tmp_path)
1561
+ key, _ = register_session(repo)
1562
+ _k2, n_bound = register_session(repo, SID_BOUND)
1563
+ state.transition(key, n_bound, "ACTIVE")
1564
+ _write_binding("%1", SID_BOUND, time.time() - 601.0)
1565
+ monkeypatch.setenv("TMUX_PANE", "%1")
1566
+ statusline.run(json.dumps(_zombie_payload(repo, SID)).encode(),
1567
+ dict(config.DEFAULTS, statusline_ansi=False))
1568
+ assert (paths.runtime_dir() / f"{SID}.json").exists()
1569
+ assert not (paths.runtime_dir() / f"{SID_BOUND}.json").exists()
1570
+
1571
+
1572
+ def test_run_binding_terminal_target_does_not_redirect(cc_home, tmp_path,
1573
+ monkeypatch):
1574
+ from hookutil import SID, make_repo, register_session
1575
+ repo = make_repo(tmp_path)
1576
+ key, _ = register_session(repo)
1577
+ _k2, n_bound = register_session(repo, SID_BOUND)
1578
+ state.close_dead(key, n_bound, "test")
1579
+ _write_binding("%1", SID_BOUND, time.time())
1580
+ monkeypatch.setenv("TMUX_PANE", "%1")
1581
+ statusline.run(json.dumps(_zombie_payload(repo, SID)).encode(),
1582
+ dict(config.DEFAULTS, statusline_ansi=False))
1583
+ assert (paths.runtime_dir() / f"{SID}.json").exists()
1584
+ assert not (paths.runtime_dir() / f"{SID_BOUND}.json").exists()
1585
+
1586
+
1587
+ def test_run_binding_to_bootstrapping_target_redirects(cc_home, tmp_path,
1588
+ monkeypatch):
1589
+ # plain startup registers in ACTIVE (Phase 5), so the payload record's
1590
+ # state is NOT the zombie signature - the pane binding is. A not-yet
1591
+ # claimed BOOTSTRAPPING target (the F2 shape) must accept the metric.
1592
+ from hookutil import SID, make_repo, register_session
1593
+ repo = make_repo(tmp_path)
1594
+ register_session(repo) # payload record: ACTIVE
1595
+ register_session(repo, SID_BOUND) # target: BOOTSTRAPPING
1596
+ _write_binding("%1", SID_BOUND, time.time())
1597
+ monkeypatch.setenv("TMUX_PANE", "%1")
1598
+ statusline.run(json.dumps(_zombie_payload(repo, SID)).encode(),
1599
+ dict(config.DEFAULTS, statusline_ansi=False))
1600
+ assert (paths.runtime_dir() / f"{SID_BOUND}.json").exists()
1601
+ assert not (paths.runtime_dir() / f"{SID}.json").exists()
1602
+
1603
+
1604
+ def test_run_binding_from_previous_session_does_not_redirect(cc_home,
1605
+ tmp_path,
1606
+ monkeypatch):
1607
+ # same-pane sequential claude: the fresh BOOTSTRAPPING record must not
1608
+ # inherit the previous session's (still fresh) binding.
1609
+ from hookutil import SID, make_repo, register_session
1610
+ repo = make_repo(tmp_path)
1611
+ key, _ = register_session(repo)
1612
+ _k2, n_bound = register_session(repo, SID_BOUND)
1613
+ state.transition(key, n_bound, "ACTIVE")
1614
+ _write_binding("%1", SID_BOUND, time.time() - 30.0) # predates the record
1615
+ monkeypatch.setenv("TMUX_PANE", "%1")
1616
+ statusline.run(json.dumps(_zombie_payload(repo, SID)).encode(),
1617
+ dict(config.DEFAULTS, statusline_ansi=False))
1618
+ assert (paths.runtime_dir() / f"{SID}.json").exists()
1619
+ assert not (paths.runtime_dir() / f"{SID_BOUND}.json").exists()
File without changes
File without changes