cc-continuity 0.3.39__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.
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/PKG-INFO +1 -1
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/README.md +2 -2
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/__init__.py +1 -1
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/bootstrap.py +14 -6
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/hooks/common.py +3 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/hooks/session_start.py +52 -1
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/statusline.py +95 -1
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity.egg-info/PKG-INFO +1 -1
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/pyproject.toml +1 -1
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_bootstrap.py +56 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_hooks_common.py +31 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_hooks_session_start.py +142 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_statusline.py +132 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/LICENSE +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/__main__.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/atomic.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/blink.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/blink_watch.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/checkpoint.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/cli.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/config.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/daemon_supervisor.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/doctor.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/gitsnap.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/hooks/__init__.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/hooks/pre_compact.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/hooks/pre_tool_use.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/hooks/session_end.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/hooks/stop.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/hooks/task.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/hooks/tool_use.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/hooks/user_prompt.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/hosting.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/install.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/launch.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/ledger.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/lock.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/managed.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/naming.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/notify.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/paths.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/power_plug.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/progress_pane.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/project.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/redact.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/rotator.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/settings_merge.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/skills.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/state.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/thresholds.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/transcript.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/validate.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/watchdog.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/watchdog_digest.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity/watchdogd.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity.egg-info/SOURCES.txt +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity.egg-info/dependency_links.txt +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity.egg-info/entry_points.txt +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/cc_continuity.egg-info/top_level.txt +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/setup.cfg +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_atomic.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_blink.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_blink_watch.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_checkpoint.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_cli.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_cli_ledger.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_config.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_daemon_supervisor.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_doctor.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_gitsnap.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_hooks_pre_compact.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_hooks_pre_tool_use.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_hooks_session_end.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_hooks_stop.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_hooks_task.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_hooks_tool_use.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_hooks_user_prompt.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_hosting.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_hygiene.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_install.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_integration_phase5.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_integration_phase6.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_integration_phase7.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_launch.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_ledger.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_lock.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_managed.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_naming.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_notify.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_notify_integration.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_paths.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_power_plug.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_progress_pane.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_project.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_redact.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_rotator.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_settings_merge.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_skills.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_state.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_status.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_thresholds.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_tmux_host.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_transcript.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_transcript_finalize.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_uninstall.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_validate.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_watchdog.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_watchdog_digest.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_watchdog_integration.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_watchdogd.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_wsl_doctor.py +0 -0
- {cc_continuity-0.3.39 → cc_continuity-0.3.41}/tests/test_wsl_install.py +0 -0
|
@@ -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)).
|
|
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)).
|
|
29
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)).
|
|
30
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)).
|
|
31
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)).
|
|
32
|
-
- **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)).
|
|
33
|
-
- **2026-11-14**: The dark icon chip now speaks: clicking it opens a small note that says why the image is missing (removed from disk, over the 4 MB embed cap, or an unsupported format), never an image - the note branch clears any previous gallery selection and hides the image row while it is up. The chip stays the same dark pulsing icon, and numbered thumbnails still open at the clicked index ([commit](https://github.com/pqant/claude-continuity/commit/614ddf8)).
|
|
34
34
|
|
|
35
35
|
## How it works
|
|
36
36
|
|
|
@@ -304,7 +304,8 @@ REUSE_MIN_AGE_S = 60.0
|
|
|
304
304
|
|
|
305
305
|
|
|
306
306
|
def try_reuse_stalled(key: str, *, new_session_id: str, cfg: dict,
|
|
307
|
-
source: str = "startup"
|
|
307
|
+
source: str = "startup",
|
|
308
|
+
allow_same_sid: bool = False) -> dict | None:
|
|
308
309
|
"""Re-attach a fresh startup to a STALLED successor — same index.
|
|
309
310
|
|
|
310
311
|
The 2026-11-03 connector incident: the rotator's RESUME Enter was
|
|
@@ -318,6 +319,10 @@ def try_reuse_stalled(key: str, *, new_session_id: str, cfg: dict,
|
|
|
318
319
|
dead (statusline metric absent/stale — never reported / long silent). A
|
|
319
320
|
live successor (fresh metric) is left alone; a plain register follows.
|
|
320
321
|
|
|
322
|
+
``allow_same_sid`` (issue #42): CC's native auto-resume can bring back
|
|
323
|
+
the stalled successor's OWN dead sid; with the opt-in the sid-equality
|
|
324
|
+
refusal is lifted and the record is re-announced (sid unchanged).
|
|
325
|
+
|
|
321
326
|
On success the record keeps its nnn/name; only the sid changes (state +
|
|
322
327
|
project.json), one ``session_start`` ledger entry is appended, and the
|
|
323
328
|
predecessor's C.4 bootstrap text is rebuilt (idempotent re-delivery of
|
|
@@ -336,7 +341,8 @@ def try_reuse_stalled(key: str, *, new_session_id: str, cfg: dict,
|
|
|
336
341
|
rec = state.load_state(key, nnn)
|
|
337
342
|
if (rec is None or rec["state"] != "BOOTSTRAPPING"
|
|
338
343
|
or rec.get("successor")
|
|
339
|
-
or rec.get("session_id") == new_session_id
|
|
344
|
+
or (rec.get("session_id") == new_session_id
|
|
345
|
+
and not allow_same_sid)):
|
|
340
346
|
return None
|
|
341
347
|
try:
|
|
342
348
|
created = datetime.fromisoformat(rec["created"])
|
|
@@ -351,10 +357,12 @@ def try_reuse_stalled(key: str, *, new_session_id: str, cfg: dict,
|
|
|
351
357
|
if not pred_name or pred is None:
|
|
352
358
|
return None
|
|
353
359
|
old_nnn = int(pred["nnn"])
|
|
354
|
-
# Re-attach: same nnn/name, new sid everywhere.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
360
|
+
# Re-attach: same nnn/name, new sid everywhere. A re-announce (issue
|
|
361
|
+
# #42, own sid) has nothing to move: same guards, C.4 rebuilt below.
|
|
362
|
+
if rec.get("session_id") != new_session_id:
|
|
363
|
+
state.update_fields_unlocked(key, nnn, session_id=new_session_id)
|
|
364
|
+
last["session_id"] = new_session_id
|
|
365
|
+
atomic.atomic_write_json(pfile, pref)
|
|
358
366
|
cp_dir = paths.session_dir(key, old_nnn) / "checkpoint"
|
|
359
367
|
root = Path(pref["root"])
|
|
360
368
|
status, details = validate.validate_checkpoint(cp_dir, cfg, root=root)
|
|
@@ -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
|
|
@@ -82,7 +82,17 @@ def handle(ctx: HookContext) -> dict | None:
|
|
|
82
82
|
# the field stays stale (dead pane) and every nudge/digest
|
|
83
83
|
# CAPTURE_FAILED while the session looks fine.
|
|
84
84
|
if ctx.session is not None:
|
|
85
|
-
#
|
|
85
|
+
# LIVE conversations: re-attach only (no registration, no state
|
|
86
|
+
# change, no output). Issue #42: when the resolved record's sid
|
|
87
|
+
# is DEAD (native auto-resume of a dead lastSessionId) the
|
|
88
|
+
# conversation instead anchors to the stalled chain tip and
|
|
89
|
+
# (re)receives the C.4 handoff.
|
|
90
|
+
revived = _revive_dead_anchor(ctx)
|
|
91
|
+
if revived is not None:
|
|
92
|
+
rkey, rnnn, text = revived
|
|
93
|
+
bootstrap.record_tmux_session(rkey, rnnn)
|
|
94
|
+
_spawn_watch(ctx, key=rkey, nnn=rnnn)
|
|
95
|
+
return session_start_output(text)
|
|
86
96
|
bootstrap.record_tmux_session(ctx.session["project_key"],
|
|
87
97
|
int(ctx.session["nnn"]))
|
|
88
98
|
_spawn_watch(ctx)
|
|
@@ -160,6 +170,47 @@ def handle(ctx: HookContext) -> dict | None:
|
|
|
160
170
|
return None
|
|
161
171
|
|
|
162
172
|
|
|
173
|
+
def _revive_dead_anchor(ctx: HookContext) -> "tuple[str, int, str] | None":
|
|
174
|
+
"""Issue #42: CC's native auto-resume can bring back a DEAD conversation
|
|
175
|
+
(dead lastSessionId after a rotation edge). Re-attaching such a
|
|
176
|
+
conversation to its dead record leaves it unmonitored forever; instead,
|
|
177
|
+
anchor it to the stalled BOOTSTRAPPING chain tip (the same-index reuse
|
|
178
|
+
guards of ``try_reuse_stalled``, including its age gate: a rotator-
|
|
179
|
+
driven young successor is never stolen, a fresh metric is left alone)
|
|
180
|
+
and (re)deliver C.4. Self-resume has no rotator to drive the successor
|
|
181
|
+
home, so the legal BOOTSTRAPPING -> ACTIVE edge hands it to the normal
|
|
182
|
+
monitoring. Returns ``(key, nnn, bootstrap_text)`` or None (= today's
|
|
183
|
+
re-attach behavior; every failure path fails open to None).
|
|
184
|
+
"""
|
|
185
|
+
try:
|
|
186
|
+
sid = ctx.payload.get("session_id")
|
|
187
|
+
if not isinstance(sid, str) or not sid:
|
|
188
|
+
return None
|
|
189
|
+
if not statusline.is_stale(statusline.read_metric(sid)):
|
|
190
|
+
return None # live conversation: ordinary re-attach
|
|
191
|
+
key = ctx.session["project_key"]
|
|
192
|
+
old_nnn = int(ctx.session["nnn"])
|
|
193
|
+
with lock.held(key):
|
|
194
|
+
res = bootstrap.try_reuse_stalled(
|
|
195
|
+
key, new_session_id=sid, cfg=ctx.cfg,
|
|
196
|
+
source="fork" if ctx.event == "fork" else "resume",
|
|
197
|
+
allow_same_sid=True)
|
|
198
|
+
if res is None:
|
|
199
|
+
return None
|
|
200
|
+
rnnn = int(res["new_nnn"])
|
|
201
|
+
if rnnn != old_nnn:
|
|
202
|
+
# The terminal record must not keep claiming the live sid
|
|
203
|
+
# (find_session_by_id would become ambiguous).
|
|
204
|
+
state.update_fields_unlocked(key, old_nnn, session_id=None)
|
|
205
|
+
try:
|
|
206
|
+
state.transition(key, rnnn, "ACTIVE")
|
|
207
|
+
except state.InvalidTransitionError:
|
|
208
|
+
pass
|
|
209
|
+
return key, rnnn, res["bootstrap_text"]
|
|
210
|
+
except Exception:
|
|
211
|
+
return None
|
|
212
|
+
|
|
213
|
+
|
|
163
214
|
def _clear(ctx: HookContext) -> dict | None:
|
|
164
215
|
"""PRD §9 SessionStart/clear: claim a rotation, else plain register.
|
|
165
216
|
|
|
@@ -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
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cc-continuity"
|
|
7
|
-
version = "0.3.
|
|
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)
|
|
@@ -396,3 +396,59 @@ def test_write_started_marker(cc_home):
|
|
|
396
396
|
p = bootstrap.write_started("sid-marker")
|
|
397
397
|
assert p == paths.runtime_dir() / "sid-marker.started"
|
|
398
398
|
assert p.is_file()
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
# --- issue #42: stalled-successor re-announce (same-sid auto-resume) -------
|
|
402
|
+
# CC native auto-resume can bring back the stalled successor's OWN dead sid;
|
|
403
|
+
# try_reuse_stalled refuses that (sid equality), so the hook opt-in
|
|
404
|
+
# (allow_same_sid=True) re-announces: same index, sid unchanged, C.4 again.
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def _stalled_successor(repo, key, nnn):
|
|
408
|
+
"""001 -> ROTATING, claim into 002 BOOTSTRAPPING (sid 'sid-stuck')."""
|
|
409
|
+
state.transition(key, nnn, "ROTATING", rotation_id="r1")
|
|
410
|
+
cfg = config.load_config(cwd=repo)
|
|
411
|
+
with lock.held(key):
|
|
412
|
+
res = bootstrap.try_claim(key, new_session_id="sid-stuck", cfg=cfg,
|
|
413
|
+
source="startup")
|
|
414
|
+
assert res is not None
|
|
415
|
+
return res
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
def test_try_reuse_stalled_same_sid_refused_by_default(cc_home, tmp_path,
|
|
419
|
+
monkeypatch):
|
|
420
|
+
from hookutil import set_metric
|
|
421
|
+
monkeypatch.setattr(bootstrap, "REUSE_MIN_AGE_S", 0.0)
|
|
422
|
+
repo, key, nnn = _verified(cc_home, tmp_path)
|
|
423
|
+
_stalled_successor(repo, key, nnn)
|
|
424
|
+
set_metric(0.0, "sid-stuck", stale=True)
|
|
425
|
+
cfg = config.load_config(cwd=repo)
|
|
426
|
+
with lock.held(key):
|
|
427
|
+
assert bootstrap.try_reuse_stalled(key, new_session_id="sid-stuck",
|
|
428
|
+
cfg=cfg, source="startup") is None
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
def test_try_reuse_stalled_same_sid_optin_reannounces(cc_home, tmp_path,
|
|
432
|
+
monkeypatch):
|
|
433
|
+
from hookutil import set_metric
|
|
434
|
+
monkeypatch.setattr(bootstrap, "REUSE_MIN_AGE_S", 0.0)
|
|
435
|
+
repo, key, nnn = _verified(cc_home, tmp_path)
|
|
436
|
+
_stalled_successor(repo, key, nnn)
|
|
437
|
+
set_metric(0.0, "sid-stuck", stale=True)
|
|
438
|
+
cfg = config.load_config(cwd=repo)
|
|
439
|
+
with lock.held(key):
|
|
440
|
+
res = bootstrap.try_reuse_stalled(key, new_session_id="sid-stuck",
|
|
441
|
+
cfg=cfg, source="resume",
|
|
442
|
+
allow_same_sid=True)
|
|
443
|
+
assert res is not None and res["reused"]
|
|
444
|
+
assert res["new_name"] == "spike-repo-002"
|
|
445
|
+
rec2 = state.load_state(key, 2)
|
|
446
|
+
assert rec2["session_id"] == "sid-stuck" # unchanged (own sid)
|
|
447
|
+
assert rec2["state"] == "BOOTSTRAPPING" # hook advances ACTIVE
|
|
448
|
+
assert "CONTINUITY BOOTSTRAP" in res["bootstrap_text"]
|
|
449
|
+
pref = json.loads((paths.project_dir(key) / "project.json")
|
|
450
|
+
.read_text(encoding="utf-8"))
|
|
451
|
+
assert pref["counter"] == 2 # no index minted
|
|
452
|
+
starts = [e for e in ledger.read(paths.session_dir(key, 2))
|
|
453
|
+
if e["type"] == "session_start"]
|
|
454
|
+
assert starts[-1]["reused"] and starts[-1]["source"] == "resume"
|
|
@@ -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()
|
|
@@ -782,6 +782,148 @@ def test_restart_does_not_reuse_fresh_bootstrap(cc_home, capsys, tmp_path):
|
|
|
782
782
|
assert _project_record(repo)["counter"] == 3
|
|
783
783
|
|
|
784
784
|
|
|
785
|
+
# --- issue #42: dead-sid auto-resume must revive the stalled successor ----
|
|
786
|
+
# plain `claude` (CC native auto-resume on lastSessionId) can bring back a
|
|
787
|
+
# DEAD conversation after a rotation edge: the rotated-away one (zombie A) or
|
|
788
|
+
# the stalled successor itself (zombie B, the a1b1e9bf shape). The resume/
|
|
789
|
+
# fork branch must not silently re-attach onto a dead record; it routes
|
|
790
|
+
# through the stalled-successor machinery (same index, C.4, monitoring
|
|
791
|
+
# takeover). Live records keep today's re-attach behavior byte-identical.
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
def test_resume_dead_old_sid_revives_stalled_successor(cc_home, capsys,
|
|
795
|
+
tmp_path, monkeypatch):
|
|
796
|
+
# Zombie A: lastSessionId == the rotated-away conversation while the
|
|
797
|
+
# project carries a stalled BOOTSTRAPPING successor. The live
|
|
798
|
+
# conversation anchors to the chain tip (same index, no bump), gets the
|
|
799
|
+
# C.4 handoff, and leaves no duplicate sid behind.
|
|
800
|
+
from cc_continuity import bootstrap
|
|
801
|
+
monkeypatch.setattr(bootstrap, "REUSE_MIN_AGE_S", 0.0)
|
|
802
|
+
repo = make_repo(tmp_path)
|
|
803
|
+
key, nnn = _verified_session(repo)
|
|
804
|
+
old_sid = state.load_state(key, nnn)["session_id"]
|
|
805
|
+
_stuck_successor(repo, key, nnn)
|
|
806
|
+
set_metric(0.0, "sid-stuck", stale=True)
|
|
807
|
+
capsys.readouterr()
|
|
808
|
+
assert run_hook("SessionStart", payload("SessionStart", repo,
|
|
809
|
+
session_id=old_sid,
|
|
810
|
+
source="resume")) == 0
|
|
811
|
+
out = _stdout_json(capsys)
|
|
812
|
+
ctx = out["hookSpecificOutput"]["additionalContext"]
|
|
813
|
+
assert ctx.startswith("CONTINUITY BOOTSTRAP: you are spike-repo-002, "
|
|
814
|
+
"continuing spike-repo-001. VALIDATION: OK")
|
|
815
|
+
pref = _project_record(repo)
|
|
816
|
+
assert pref["counter"] == 2 # NO index minted
|
|
817
|
+
rec2 = state.load_state(key, 2)
|
|
818
|
+
assert rec2["session_id"] == old_sid # anchored to the tip
|
|
819
|
+
assert rec2["state"] == "ACTIVE" # monitoring takes over
|
|
820
|
+
assert state.load_state(key, 1)["state"] == "ROTATED"
|
|
821
|
+
assert state.load_state(key, 1)["session_id"] is None # no duplicate sid
|
|
822
|
+
starts = [e for e in ledger.read(paths.session_dir(key, 2))
|
|
823
|
+
if e["type"] == "session_start"]
|
|
824
|
+
assert starts[-1]["reused"] and starts[-1]["source"] == "resume"
|
|
825
|
+
|
|
826
|
+
|
|
827
|
+
def test_resume_dead_successor_own_sid_redelivers_c4(cc_home, capsys,
|
|
828
|
+
tmp_path, monkeypatch):
|
|
829
|
+
# Zombie B (a1b1e9bf): the stalled successor's OWN dead sid is
|
|
830
|
+
# auto-resumed. Same index, sid unchanged, C.4 (re)delivered, ACTIVE.
|
|
831
|
+
from cc_continuity import bootstrap
|
|
832
|
+
monkeypatch.setattr(bootstrap, "REUSE_MIN_AGE_S", 0.0)
|
|
833
|
+
repo = make_repo(tmp_path)
|
|
834
|
+
key, nnn = _verified_session(repo)
|
|
835
|
+
_stuck_successor(repo, key, nnn)
|
|
836
|
+
set_metric(0.0, "sid-stuck", stale=True)
|
|
837
|
+
capsys.readouterr()
|
|
838
|
+
assert run_hook("SessionStart", payload("SessionStart", repo,
|
|
839
|
+
session_id="sid-stuck",
|
|
840
|
+
source="resume")) == 0
|
|
841
|
+
out = _stdout_json(capsys)
|
|
842
|
+
assert "VALIDATION: OK" in out["hookSpecificOutput"]["additionalContext"]
|
|
843
|
+
pref = _project_record(repo)
|
|
844
|
+
assert pref["counter"] == 2 # no re-registration
|
|
845
|
+
rec2 = state.load_state(key, 2)
|
|
846
|
+
assert rec2["session_id"] == "sid-stuck" # same sid re-announced
|
|
847
|
+
assert rec2["state"] == "ACTIVE"
|
|
848
|
+
starts = [e for e in ledger.read(paths.session_dir(key, 2))
|
|
849
|
+
if e["type"] == "session_start"]
|
|
850
|
+
assert starts[-1]["reused"]
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
def test_fork_dead_successor_own_sid_redelivers_c4(cc_home, capsys,
|
|
854
|
+
tmp_path, monkeypatch):
|
|
855
|
+
# Same contract for source=fork (CC forks share the dead-sid exposure).
|
|
856
|
+
from cc_continuity import bootstrap
|
|
857
|
+
monkeypatch.setattr(bootstrap, "REUSE_MIN_AGE_S", 0.0)
|
|
858
|
+
repo = make_repo(tmp_path)
|
|
859
|
+
key, nnn = _verified_session(repo)
|
|
860
|
+
_stuck_successor(repo, key, nnn)
|
|
861
|
+
set_metric(0.0, "sid-stuck", stale=True)
|
|
862
|
+
capsys.readouterr()
|
|
863
|
+
assert run_hook("SessionStart", payload("SessionStart", repo,
|
|
864
|
+
session_id="sid-stuck",
|
|
865
|
+
source="fork")) == 0
|
|
866
|
+
out = _stdout_json(capsys)
|
|
867
|
+
assert "VALIDATION: OK" in out["hookSpecificOutput"]["additionalContext"]
|
|
868
|
+
assert state.load_state(key, 2)["state"] == "ACTIVE"
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
def test_resume_live_successor_not_revived(cc_home, capsys, tmp_path,
|
|
872
|
+
monkeypatch):
|
|
873
|
+
# Guard (regression vector 1): a LIVE successor (fresh metric) resumed
|
|
874
|
+
# by its own sid keeps today's silent re-attach: no C.4 re-delivery, no
|
|
875
|
+
# state change, no extra session_start entry.
|
|
876
|
+
from cc_continuity import bootstrap
|
|
877
|
+
monkeypatch.setattr(bootstrap, "REUSE_MIN_AGE_S", 0.0)
|
|
878
|
+
repo = make_repo(tmp_path)
|
|
879
|
+
key, nnn = _verified_session(repo)
|
|
880
|
+
_stuck_successor(repo, key, nnn)
|
|
881
|
+
set_metric(0.0, "sid-stuck", stale=False) # rotator-driven, alive
|
|
882
|
+
capsys.readouterr()
|
|
883
|
+
assert run_hook("SessionStart", payload("SessionStart", repo,
|
|
884
|
+
session_id="sid-stuck",
|
|
885
|
+
source="resume")) == 0
|
|
886
|
+
assert _stdout_json(capsys) is None
|
|
887
|
+
rec2 = state.load_state(key, 2)
|
|
888
|
+
assert rec2["state"] == "BOOTSTRAPPING"
|
|
889
|
+
starts = [e for e in ledger.read(paths.session_dir(key, 2))
|
|
890
|
+
if e["type"] == "session_start"]
|
|
891
|
+
assert len(starts) == 1 # only the claim entry
|
|
892
|
+
|
|
893
|
+
|
|
894
|
+
def test_resume_young_stalled_successor_left_alone(cc_home, capsys, tmp_path):
|
|
895
|
+
# Guard (regression vector 3): a just-spawned BOOTSTRAPPING successor
|
|
896
|
+
# (production REUSE_MIN_AGE_S) may be mid-rotation; a dead-sid resume
|
|
897
|
+
# must not steal it.
|
|
898
|
+
repo = make_repo(tmp_path)
|
|
899
|
+
key, nnn = _verified_session(repo)
|
|
900
|
+
_stuck_successor(repo, key, nnn)
|
|
901
|
+
set_metric(0.0, "sid-stuck", stale=True)
|
|
902
|
+
capsys.readouterr()
|
|
903
|
+
assert run_hook("SessionStart", payload("SessionStart", repo,
|
|
904
|
+
session_id="sid-stuck",
|
|
905
|
+
source="resume")) == 0
|
|
906
|
+
assert _stdout_json(capsys) is None
|
|
907
|
+
assert state.load_state(key, 2)["state"] == "BOOTSTRAPPING"
|
|
908
|
+
|
|
909
|
+
|
|
910
|
+
def test_resume_terminal_without_successor_stays_reattach(cc_home, capsys,
|
|
911
|
+
tmp_path):
|
|
912
|
+
# Documented residual: a terminal record with no stalled successor
|
|
913
|
+
# (admin close_dead shape, not a rotation) keeps today's re-attach-only
|
|
914
|
+
# behavior; no registration, no index minted.
|
|
915
|
+
repo = make_repo(tmp_path)
|
|
916
|
+
key, nnn = register_session(repo)
|
|
917
|
+
state.close_dead(key, nnn, "test")
|
|
918
|
+
capsys.readouterr()
|
|
919
|
+
assert run_hook("SessionStart", payload("SessionStart", repo,
|
|
920
|
+
session_id=SID,
|
|
921
|
+
source="resume")) == 0
|
|
922
|
+
assert _stdout_json(capsys) is None
|
|
923
|
+
assert _project_record(repo)["counter"] == 1
|
|
924
|
+
assert state.load_state(key, nnn)["state"] == "ROTATED"
|
|
925
|
+
|
|
926
|
+
|
|
785
927
|
# ---------- blink_watch spawn wiring (live bug 2026-11-07)
|
|
786
928
|
|
|
787
929
|
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|