cc-continuity 0.3.67__tar.gz → 0.3.69__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.67 → cc_continuity-0.3.69}/PKG-INFO +1 -1
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/README.md +2 -2
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/__init__.py +1 -1
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/bootstrap.py +72 -6
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/thresholds.py +49 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity.egg-info/PKG-INFO +1 -1
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/pyproject.toml +1 -1
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_bootstrap.py +214 -2
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/LICENSE +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/__main__.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/atomic.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/blink.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/blink_watch.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/checkpoint.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/cli.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/config.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/daemon_supervisor.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/doctor.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/gitsnap.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/hooks/__init__.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/hooks/common.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/hooks/pre_compact.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/hooks/pre_tool_use.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/hooks/session_end.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/hooks/session_start.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/hooks/stop.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/hooks/task.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/hooks/tool_use.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/hooks/user_prompt.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/hosting.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/install.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/launch.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/ledger.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/lock.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/managed.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/naming.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/notify.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/overflow.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/paths.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/power_plug.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/progress_pane.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/project.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/redact.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/rotator.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/settings_merge.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/skills.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/state.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/statusline.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/transcript.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/validate.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/watchdog.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/watchdog_digest.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity/watchdogd.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity.egg-info/SOURCES.txt +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity.egg-info/dependency_links.txt +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity.egg-info/entry_points.txt +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/cc_continuity.egg-info/top_level.txt +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/setup.cfg +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_atomic.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_blink.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_blink_watch.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_changelog_notes.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_checkpoint.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_cli.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_cli_ledger.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_cli_log.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_config.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_daemon_supervisor.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_doctor.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_gitsnap.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_hooks_common.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_hooks_pre_compact.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_hooks_pre_tool_use.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_hooks_session_end.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_hooks_session_start.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_hooks_stop.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_hooks_task.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_hooks_tool_use.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_hooks_user_prompt.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_hosting.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_hygiene.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_install.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_integration_phase5.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_integration_phase6.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_integration_phase7.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_launch.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_ledger.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_lock.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_managed.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_naming.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_notify.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_notify_integration.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_overflow.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_paths.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_power_plug.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_progress_pane.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_project.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_readme_badges.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_readme_gif.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_redact.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_rotator.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_settings_merge.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_skills.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_state.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_status.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_statusline.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_statusline_cache.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_thresholds.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_tmux_host.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_transcript.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_transcript_finalize.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_uninstall.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_validate.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_watchdog.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_watchdog_digest.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_watchdog_integration.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_watchdogd.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/tests/test_wsl_doctor.py +0 -0
- {cc_continuity-0.3.67 → cc_continuity-0.3.69}/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.
|
|
3
|
+
Version: 0.3.69
|
|
4
4
|
Summary: Zero-touch session rotation for Claude Code (local large-context model)
|
|
5
5
|
Classifier: Development Status :: 5 - Production/Stable
|
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -41,11 +41,11 @@ The five most recent updates, newest first. Each line links to its
|
|
|
41
41
|
commit, so you can see what changed lately without digging through the
|
|
42
42
|
log:
|
|
43
43
|
|
|
44
|
+
- **2026-11-24**: A claim no longer skips a successor that died after attaching. The dead ACTIVE record used to force a fresh `max(counter)+1` name while the corpse kept looking live in the session list; the claim now probes the candidate's recorded pane (`tmux_session` against `tmux list-sessions`) and, only when that pane is gone, adopts the record at its same index and resets it to BOOTSTRAPPING so the SessionStart hook drives it like a fresh claim; the probe is conservative by construction (no recorded pane, tmux missing or any error means the candidate is treated as live), so a live pane is never hijacked, with eight tests written first ([commit](https://github.com/pqant/claude-continuity/commit/fa9b972)).
|
|
45
|
+
- **2026-11-24**: Resuming now opens with a one-line at-a-glance preview. The SessionStart bootstrap block starts with the checkpoint number, the predecessor session, the VALIDATION result and the first Next Atomic Action item, so you can see what is being resumed without waiting for the first reply; the line is parsed display-only from the handoff text, silently omitted when nothing parses, and the block otherwise stays exactly the old format, with six tests written first ([commit](https://github.com/pqant/claude-continuity/commit/96341cb)).
|
|
44
46
|
- **2026-11-24**: Handoff search is now a first-class surface. `cc-continuity search <query>` takes the search phrase directly, without typing `history` first, and the new `/continuity-search <phrase>` skill makes the invocation argument itself the query (invoked bare it asks for the keyword once); both reuse the read-only keyword engine from v0.3.66 verbatim, the `--nnn` and `--since`/`--until` filters keep working and `cc-continuity history <query>` continues to work unchanged, with four tests written first ([commit](https://github.com/pqant/claude-continuity/commit/b05b31c)).
|
|
45
47
|
- **2026-11-24**: `cc-continuity history` now searches the checkpoint archive. `cc-continuity history <query>` finds every handoff whose text contains the keyword (case-insensitive substring) and prints session number, creation date, the first objective line and the matched line; `--nnn` and `--since`/`--until` filter the result, and the `/continuity-history` skill teaches the same usage; the search is read-only and deterministic, the checkpoint write path and the session index are untouched, and eight tests were written first ([commit](https://github.com/pqant/claude-continuity/commit/be179fe)).
|
|
46
48
|
- **2026-11-24**: A rotation no longer splits the successor identity. The rotator predicted the next session name as strict `nnn+1` while the claim mints `max(counter, old_nnn) + 1`, so once stale records had advanced the counter the pane title and the old session's ledger froze a name the claim never minted (seen live: the ledger said connector-259 while the real successor session was connector-267); the prediction now mirrors the claim allocator, the completion paths reconcile the ledger entry and log line with the claimed record before writing them, and a claim whose own never-attached `BOOTSTRAPPING` successor already exists adopts it at the same index instead of minting a second name, with three tests written first to pin all three fixes ([commit](https://github.com/pqant/claude-continuity/commit/b60c518)).
|
|
47
|
-
- **2026-11-24**: A deferred rotation no longer buries the fresh-prompt recovery evidence. Recovery re-attaches a verified-checkpoint session only when the newest user prompt in the ledger post-dates the checkpoint verification stamp, but a deferred rotation used to append an out-of-band rollback (ROTATING -> CHECKPOINT_VERIFIED) that re-stamped the verification after the user came back: the prompt looked stale, the watchdog kept reporting the session as skipped and the context-400 rotation never dispatched; a rollback entering from ROTATING no longer counts as a new verification, the ledger stays the single source of truth, and a test written first pins that a deferred re-stamp neither buries the fresh prompt nor gates recovery out ([commit](https://github.com/pqant/claude-continuity/commit/203578b)).
|
|
48
|
-
- **2026-11-24**: Context-400 recovery now actually completes the rotation. The dispatch works since v0.3.62, but the spawned rotator kept deferring every time: the API 400 kills the turn without firing the Stop hook, so the turn flag was never cleared and the rotator's idle gate read the dead turn as live work, deferred and waited for a Stop that could never come; the recovery now records the finished turn itself (flag off, stop timestamp) right after logging the recovery, the rotator and its idle gate stay untouched, and two tests written first pin the field write and the unlocked idle gate ([commit](https://github.com/pqant/claude-continuity/commit/129422a)).
|
|
49
49
|
## How it works
|
|
50
50
|
|
|
51
51
|
The whole flow in one picture: the automatic session loop, the optional
|
|
@@ -254,6 +254,61 @@ def _find_reusable_successor(pref: dict, key: str, old_name: str) -> dict | None
|
|
|
254
254
|
return None
|
|
255
255
|
|
|
256
256
|
|
|
257
|
+
def _tmux_session_names(runner=subprocess.run) -> set | None:
|
|
258
|
+
"""Live tmux session names; None when tmux is unavailable or the probe
|
|
259
|
+
failed (unknown, never "empty")."""
|
|
260
|
+
try:
|
|
261
|
+
proc = runner(["tmux", "list-sessions", "-F", "#{session_name}"],
|
|
262
|
+
capture_output=True, timeout=5)
|
|
263
|
+
except (OSError, subprocess.SubprocessError):
|
|
264
|
+
return None
|
|
265
|
+
if proc.returncode != 0:
|
|
266
|
+
return None
|
|
267
|
+
return {ln.strip() for ln in proc.stdout.decode(errors="replace").splitlines()
|
|
268
|
+
if ln.strip()}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _pane_record_dead(rec: dict, *, runner=subprocess.run) -> bool:
|
|
272
|
+
"""Issue #98: liveness probe for a record's recorded pane. True ONLY
|
|
273
|
+
when the record recorded its own tmux pane and that pane is absent
|
|
274
|
+
from the live list. Conservative by construction: no recorded pane,
|
|
275
|
+
tmux unavailable or any probe error → False (treated as alive, today's
|
|
276
|
+
behavior; a live pane is never hijacked)."""
|
|
277
|
+
pane = rec.get("tmux_session")
|
|
278
|
+
if not pane:
|
|
279
|
+
return False
|
|
280
|
+
names = _tmux_session_names(runner=runner)
|
|
281
|
+
if names is None:
|
|
282
|
+
return False
|
|
283
|
+
return pane not in names
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _find_dead_successor(pref: dict, key: str, old_name: str) -> dict | None:
|
|
287
|
+
"""Issue #98 (the gap v0.3.65 left open): this predecessor's ACTIVE
|
|
288
|
+
successor (``predecessor == old_name``, ``successor`` unset, older than
|
|
289
|
+
``REUSE_MIN_AGE_S``) whose recorded pane is DEAD - the attached-then-
|
|
290
|
+
killed successor that ``_find_reusable_successor`` must skip because a
|
|
291
|
+
live session is ACTIVE. Adoption honors the no-index-jumping rule."""
|
|
292
|
+
for s in reversed(pref.get("sessions") or []):
|
|
293
|
+
try:
|
|
294
|
+
rec = state.load_state(key, int(s["nnn"]))
|
|
295
|
+
except (state.StateNotFoundError, ValueError, KeyError):
|
|
296
|
+
continue
|
|
297
|
+
if (rec.get("predecessor") != old_name
|
|
298
|
+
or rec["state"] != "ACTIVE"
|
|
299
|
+
or rec.get("successor")):
|
|
300
|
+
continue
|
|
301
|
+
try:
|
|
302
|
+
created = datetime.fromisoformat(rec["created"])
|
|
303
|
+
except (KeyError, TypeError, ValueError):
|
|
304
|
+
continue
|
|
305
|
+
if (datetime.now(timezone.utc) - created).total_seconds() < REUSE_MIN_AGE_S:
|
|
306
|
+
continue
|
|
307
|
+
if _pane_record_dead(rec):
|
|
308
|
+
return rec
|
|
309
|
+
return None
|
|
310
|
+
|
|
311
|
+
|
|
257
312
|
def try_claim(key: str, *, new_session_id: str, cfg: dict,
|
|
258
313
|
states: frozenset[str] | None = None,
|
|
259
314
|
source: str = "clear") -> dict | None:
|
|
@@ -283,13 +338,22 @@ def try_claim(key: str, *, new_session_id: str, cfg: dict,
|
|
|
283
338
|
root = Path(pref["root"])
|
|
284
339
|
old_nnn = int(old["nnn"])
|
|
285
340
|
reuse = _find_reusable_successor(pref, key, old["name"])
|
|
286
|
-
if reuse is
|
|
341
|
+
corpse = _find_dead_successor(pref, key, old["name"]) if reuse is None else None
|
|
342
|
+
if reuse is not None or corpse is not None:
|
|
287
343
|
# BUG-10 (connector 258/259 live): this claim's own never-attached
|
|
288
344
|
# successor already sits at its index - adopt it (standing "no
|
|
289
345
|
# session index jumping" rule) instead of minting a second name.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
346
|
+
# Issue #98 adds the attached-then-killed ACTIVE variant, adopted
|
|
347
|
+
# the same way after its recorded pane is probed dead.
|
|
348
|
+
nnn_new = int((reuse or corpse)["nnn"])
|
|
349
|
+
name_new = (reuse or corpse)["name"]
|
|
350
|
+
if corpse is not None:
|
|
351
|
+
state.update_fields_unlocked(key, nnn_new,
|
|
352
|
+
session_id=new_session_id,
|
|
353
|
+
state="BOOTSTRAPPING")
|
|
354
|
+
else:
|
|
355
|
+
state.update_fields_unlocked(key, nnn_new,
|
|
356
|
+
session_id=new_session_id)
|
|
293
357
|
entry = next((s for s in pref["sessions"]
|
|
294
358
|
if int(s.get("nnn", -1)) == nnn_new), None)
|
|
295
359
|
if entry is not None:
|
|
@@ -310,7 +374,7 @@ def try_claim(key: str, *, new_session_id: str, cfg: dict,
|
|
|
310
374
|
cp["consumed_by"] = name_new
|
|
311
375
|
pref["latest_checkpoint"] = cp
|
|
312
376
|
pref["counter"] = max(int(pref["counter"]), nnn_new)
|
|
313
|
-
if reuse is None:
|
|
377
|
+
if reuse is None and corpse is None:
|
|
314
378
|
pref["sessions"].append({"name": name_new, "session_id": new_session_id,
|
|
315
379
|
"nnn": nnn_new, "created": _now()})
|
|
316
380
|
atomic.atomic_write_json(pfile, pref)
|
|
@@ -328,8 +392,10 @@ def try_claim(key: str, *, new_session_id: str, cfg: dict,
|
|
|
328
392
|
new_work=_new_work_since_handoff(cp_dir, key, old_nnn))
|
|
329
393
|
start_entry = {"type": "session_start", "source": source,
|
|
330
394
|
"claimed": old["name"], "validation": status}
|
|
331
|
-
if reuse is not None:
|
|
395
|
+
if reuse is not None or corpse is not None:
|
|
332
396
|
start_entry["reused"] = True
|
|
397
|
+
if corpse is not None:
|
|
398
|
+
start_entry["reused_dead"] = True
|
|
333
399
|
ledger.append(paths.session_dir(key, nnn_new), start_entry)
|
|
334
400
|
return {"old_name": old["name"], "old_nnn": old_nnn,
|
|
335
401
|
"new_name": name_new, "new_nnn": nnn_new,
|
|
@@ -267,6 +267,47 @@ def advance(key: str, nnn: int, target: str, *,
|
|
|
267
267
|
return record, True
|
|
268
268
|
|
|
269
269
|
|
|
270
|
+
def _c4_preview(handoff: str, status: str) -> str | None:
|
|
271
|
+
"""One at-a-glance preview line for the user (issue #83): checkpoint
|
|
272
|
+
number, predecessor, the validation result and the first Next Atomic
|
|
273
|
+
Action item. Display-only: parsed from the handoff text already loaded
|
|
274
|
+
by the caller (no file read, no state change); None whenever nothing
|
|
275
|
+
useful is parseable, so the block then stays exactly the old format.
|
|
276
|
+
"""
|
|
277
|
+
try:
|
|
278
|
+
m = re.search(r"cp-(\d{1,4})", handoff)
|
|
279
|
+
cp = f"cp-{m.group(1)}" if m else None
|
|
280
|
+
pm = re.search(r"predecessor:\s*`?([^`\n]+)`?", handoff)
|
|
281
|
+
pred = pm.group(1).strip() if pm else None
|
|
282
|
+
next_item = None
|
|
283
|
+
in_naa = False
|
|
284
|
+
for line in handoff.splitlines():
|
|
285
|
+
stripped = line.strip()
|
|
286
|
+
if stripped.startswith("## "):
|
|
287
|
+
in_naa = stripped.startswith("## Next Atomic Action")
|
|
288
|
+
continue
|
|
289
|
+
if in_naa:
|
|
290
|
+
mi = re.match(r"\d+\.\s+(.*)", stripped)
|
|
291
|
+
if mi:
|
|
292
|
+
next_item = mi.group(1).strip()
|
|
293
|
+
break
|
|
294
|
+
if stripped:
|
|
295
|
+
break
|
|
296
|
+
if cp is None and next_item is None:
|
|
297
|
+
return None
|
|
298
|
+
parts = [cp or "cp-???"]
|
|
299
|
+
if pred:
|
|
300
|
+
parts.append(f"from {pred}")
|
|
301
|
+
parts.append(f"validation {status}")
|
|
302
|
+
if next_item:
|
|
303
|
+
if len(next_item) > 100:
|
|
304
|
+
next_item = next_item[:97].rstrip() + "..."
|
|
305
|
+
parts.append(f"next: {next_item}")
|
|
306
|
+
return "Preview: " + " | ".join(parts)
|
|
307
|
+
except Exception:
|
|
308
|
+
return None
|
|
309
|
+
|
|
310
|
+
|
|
270
311
|
def c4_text(*, new_name: str, old_name: str, status: str,
|
|
271
312
|
details: list, handoff: str, handoff_path: str,
|
|
272
313
|
inline_max: int, new_work: list | None = None) -> str:
|
|
@@ -279,10 +320,18 @@ def c4_text(*, new_name: str, old_name: str, status: str,
|
|
|
279
320
|
ledger AFTER the handoff was written (the rotation window) - they
|
|
280
321
|
are not in the handoff, so they are appended as a separate section
|
|
281
322
|
(empty/None → the text is exactly the old format).
|
|
323
|
+
|
|
324
|
+
When the handoff text is available (issue #83) a one-line ``Preview:``
|
|
325
|
+
(cp id, predecessor, validation, first next action) sits between the
|
|
326
|
+
details and the protocol directive; when nothing is parseable the
|
|
327
|
+
block is exactly the old format.
|
|
282
328
|
"""
|
|
283
329
|
lines = [f"CONTINUITY BOOTSTRAP: you are {new_name}, continuing "
|
|
284
330
|
f"{old_name}. VALIDATION: {status}"]
|
|
285
331
|
lines.extend(details)
|
|
332
|
+
preview = _c4_preview(handoff, status) if handoff else None
|
|
333
|
+
if preview:
|
|
334
|
+
lines.append(preview)
|
|
286
335
|
lines.append(
|
|
287
336
|
f"Protocol: read the handoff below (or at {handoff_path}) "
|
|
288
337
|
"fully; do not redo completed work; start with Next Atomic "
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cc-continuity
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.69
|
|
4
4
|
Summary: Zero-touch session rotation for Claude Code (local large-context model)
|
|
5
5
|
Classifier: Development Status :: 5 - Production/Stable
|
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -102,8 +102,11 @@ def test_c4_text_inlines_short_handoff():
|
|
|
102
102
|
assert lines[0] == ("CONTINUITY BOOTSTRAP: you are p-002, continuing "
|
|
103
103
|
"p-001. VALIDATION: OK")
|
|
104
104
|
assert lines[1] == "working tree unchanged since checkpoint"
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
# issue #83: the fixture carries a cp id, so the preview line slots in
|
|
106
|
+
# between the details and the protocol directive.
|
|
107
|
+
assert lines[2] == "Preview: cp-001 | validation OK"
|
|
108
|
+
assert "Protocol: read the handoff below (or at /x/handoff.md) fully" in lines[3]
|
|
109
|
+
assert lines[4] == "---"
|
|
107
110
|
assert t.endswith("# Handoff cp-001\n## Objective\n...")
|
|
108
111
|
|
|
109
112
|
|
|
@@ -491,3 +494,212 @@ def test_try_claim_reuses_never_attached_successor(cc_home, tmp_path):
|
|
|
491
494
|
entries = ledger.read(paths.session_dir(key, 42))
|
|
492
495
|
assert entries[-1]["type"] == "session_start"
|
|
493
496
|
assert entries[-1].get("reused") is True
|
|
497
|
+
|
|
498
|
+
# --- issue #83: at-a-glance preview line in the C.4 block (display-only) ---
|
|
499
|
+
|
|
500
|
+
_NAA_HANDOFF = (
|
|
501
|
+
"# Handoff cp-007 - claude-continuity-007\n\n"
|
|
502
|
+
"- session: `claude-continuity-007` (7)\n"
|
|
503
|
+
"- predecessor: `claude-continuity-006`\n\n"
|
|
504
|
+
"## Objective\n\nkeep it simple\n\n"
|
|
505
|
+
"## Next Atomic Action\n\n"
|
|
506
|
+
"1. run the full dev suite (uv run pytest -q)\n"
|
|
507
|
+
"2. write the docs\n\n"
|
|
508
|
+
"## Remaining Plan\n\n1. ship\n"
|
|
509
|
+
)
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def _c4(**over):
|
|
513
|
+
from cc_continuity import thresholds
|
|
514
|
+
kw = dict(new_name="p-002", old_name="p-001", status="OK", details=[],
|
|
515
|
+
handoff=_NAA_HANDOFF, handoff_path="/x/handoff.md",
|
|
516
|
+
inline_max=12000)
|
|
517
|
+
kw.update(over)
|
|
518
|
+
return thresholds.c4_text(**kw)
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
def test_c4_text_preview_line_at_a_glance():
|
|
522
|
+
# issue #83: cp id, predecessor, validation and the first next action
|
|
523
|
+
# must be visible at resume time, before the new session's first reply.
|
|
524
|
+
t = _c4()
|
|
525
|
+
lines = t.splitlines()
|
|
526
|
+
pv = next(l for l in lines if l.startswith("Preview:"))
|
|
527
|
+
assert "cp-007" in pv
|
|
528
|
+
assert "from claude-continuity-006" in pv
|
|
529
|
+
assert "validation OK" in pv
|
|
530
|
+
assert "next: run the full dev suite (uv run pytest -q)" in pv
|
|
531
|
+
# the preview precedes the protocol directive (at-a-glance first)
|
|
532
|
+
proto = next(i for i, l in enumerate(lines) if l.startswith("Protocol:"))
|
|
533
|
+
assert lines.index(pv) < proto
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
def test_c4_text_preview_first_action_only():
|
|
537
|
+
# only the first numbered item; the "1. " numbering is stripped
|
|
538
|
+
t = _c4()
|
|
539
|
+
pv = next(l for l in t.splitlines() if l.startswith("Preview:"))
|
|
540
|
+
assert "write the docs" not in pv
|
|
541
|
+
assert "next: 1." not in pv
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
def test_c4_text_preview_truncates_long_action():
|
|
545
|
+
long_action = "x" * 200
|
|
546
|
+
t = _c4(handoff=_NAA_HANDOFF.replace(
|
|
547
|
+
"run the full dev suite (uv run pytest -q)", long_action))
|
|
548
|
+
pv = next(l for l in t.splitlines() if l.startswith("Preview:"))
|
|
549
|
+
assert pv.endswith("...")
|
|
550
|
+
assert len(pv.split("next: ", 1)[1]) <= 100
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
def test_c4_text_preview_absent_without_sections():
|
|
554
|
+
# silent fallback: nothing parseable, block stays exactly the old format
|
|
555
|
+
t = _c4(handoff="# Handoff\nbody")
|
|
556
|
+
assert not any(l.startswith("Preview:") for l in t.splitlines())
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
def test_c4_text_preview_absent_when_not_inlined():
|
|
560
|
+
# the handoff text is too large to inline: no parse, no preview line
|
|
561
|
+
t = _c4(handoff="x" * 20, inline_max=10)
|
|
562
|
+
assert not any(l.startswith("Preview:") for l in t.splitlines())
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
def test_c4_text_preview_shows_mismatch_status():
|
|
566
|
+
# the validation summary rides the preview verbatim (one line)
|
|
567
|
+
t = _c4(status="MISMATCH: git tree differs from snapshot")
|
|
568
|
+
pv = next(l for l in t.splitlines() if l.startswith("Preview:"))
|
|
569
|
+
assert "validation MISMATCH: git tree differs from snapshot" in pv
|
|
570
|
+
|
|
571
|
+
# --- issue #98: liveness probe for dead ACTIVE successors -------------------
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
def _fake_runner(payload: bytes, rc: int = 0):
|
|
575
|
+
import types
|
|
576
|
+
calls: list = []
|
|
577
|
+
|
|
578
|
+
def run(cmd, **kw):
|
|
579
|
+
calls.append(cmd)
|
|
580
|
+
return types.SimpleNamespace(returncode=rc, stdout=payload,
|
|
581
|
+
stderr=b"")
|
|
582
|
+
run.calls = calls
|
|
583
|
+
return run
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
def _active_dead_successor(key):
|
|
587
|
+
"""001's claim minted 042, it attached (ACTIVE, pane recorded) and its
|
|
588
|
+
pane has since died; 001 is back in ROTATING with ``successor`` unset."""
|
|
589
|
+
import datetime as _dt
|
|
590
|
+
zombie = "spike-repo-042"
|
|
591
|
+
state.create_session_state(key, zombie, 42, "sid-zombie",
|
|
592
|
+
predecessor="spike-repo-001",
|
|
593
|
+
initial_state="ACTIVE")
|
|
594
|
+
state.update_fields(key, 42, tmux_session="cc-spike-repo-zz99")
|
|
595
|
+
pfile = paths.project_dir(key) / "project.json"
|
|
596
|
+
pref = json.loads(pfile.read_text())
|
|
597
|
+
pref["sessions"].append({"name": zombie, "session_id": "sid-zombie",
|
|
598
|
+
"nnn": 42,
|
|
599
|
+
"created": _dt.datetime.now(
|
|
600
|
+
_dt.timezone.utc).isoformat()})
|
|
601
|
+
pref["counter"] = 42
|
|
602
|
+
pfile.write_text(json.dumps(pref))
|
|
603
|
+
state.update_fields(key, 42, created=(_dt.datetime.now(
|
|
604
|
+
_dt.timezone.utc) - _dt.timedelta(hours=1)).isoformat())
|
|
605
|
+
return pfile
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
def test_try_claim_adopts_dead_active_successor_same_index(cc_home, tmp_path,
|
|
609
|
+
monkeypatch):
|
|
610
|
+
# issue #98: the attached-then-killed successor must be re-adopted at
|
|
611
|
+
# its own index; minting max+1 leaves the ACTIVE corpse behind.
|
|
612
|
+
repo, key, nnn = _verified(cc_home, tmp_path)
|
|
613
|
+
state.transition(key, nnn, "ROTATING", rotation_id="r1")
|
|
614
|
+
pfile = _active_dead_successor(key)
|
|
615
|
+
monkeypatch.setattr(bootstrap, "REUSE_MIN_AGE_S", 0.0)
|
|
616
|
+
monkeypatch.setattr(bootstrap, "_pane_record_dead",
|
|
617
|
+
lambda rec, **kw: True)
|
|
618
|
+
with lock.held(key):
|
|
619
|
+
res = bootstrap.try_claim(key, new_session_id=_NEW_SID,
|
|
620
|
+
cfg=config.load_config(cwd=repo))
|
|
621
|
+
assert res is not None
|
|
622
|
+
assert res["new_nnn"] == 42 and res["new_name"] == "spike-repo-042"
|
|
623
|
+
new = state.load_state(key, 42)
|
|
624
|
+
assert new["session_id"] == _NEW_SID
|
|
625
|
+
assert new["state"] == "BOOTSTRAPPING" # the hook drives it fresh
|
|
626
|
+
assert state.load_state(key, nnn)["successor"] == "spike-repo-042"
|
|
627
|
+
pref2 = json.loads(pfile.read_text())
|
|
628
|
+
assert pref2["counter"] == 42 # no index jump
|
|
629
|
+
assert sum(1 for s in pref2["sessions"] if s["nnn"] == 42) == 1
|
|
630
|
+
assert next(s for s in pref2["sessions"]
|
|
631
|
+
if s["nnn"] == 42)["session_id"] == _NEW_SID
|
|
632
|
+
entries = ledger.read(paths.session_dir(key, 42))
|
|
633
|
+
assert entries[-1]["type"] == "session_start"
|
|
634
|
+
assert entries[-1].get("reused") is True
|
|
635
|
+
assert entries[-1].get("reused_dead") is True
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
def test_try_claim_mints_new_name_when_successor_alive(cc_home, tmp_path,
|
|
639
|
+
monkeypatch):
|
|
640
|
+
# a live pane must never be hijacked: today's mint stays.
|
|
641
|
+
repo, key, nnn = _verified(cc_home, tmp_path)
|
|
642
|
+
state.transition(key, nnn, "ROTATING", rotation_id="r1")
|
|
643
|
+
_active_dead_successor(key)
|
|
644
|
+
monkeypatch.setattr(bootstrap, "REUSE_MIN_AGE_S", 0.0)
|
|
645
|
+
monkeypatch.setattr(bootstrap, "_pane_record_dead",
|
|
646
|
+
lambda rec, **kw: False)
|
|
647
|
+
with lock.held(key):
|
|
648
|
+
res = bootstrap.try_claim(key, new_session_id=_NEW_SID,
|
|
649
|
+
cfg=config.load_config(cwd=repo))
|
|
650
|
+
assert res is not None and res["new_nnn"] == 43
|
|
651
|
+
assert state.load_state(key, 42)["state"] == "ACTIVE"
|
|
652
|
+
assert state.load_state(key, 42)["session_id"] == "sid-zombie"
|
|
653
|
+
entries = ledger.read(paths.session_dir(key, 43))
|
|
654
|
+
assert entries[-1]["type"] == "session_start"
|
|
655
|
+
assert "reused" not in entries[-1]
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
def test_try_claim_skips_young_dead_successor(cc_home, tmp_path,
|
|
659
|
+
monkeypatch):
|
|
660
|
+
# REUSE_MIN_AGE_S still guards adoption: an in-flight successor is
|
|
661
|
+
# never stolen even if a probe says dead.
|
|
662
|
+
repo, key, nnn = _verified(cc_home, tmp_path)
|
|
663
|
+
state.transition(key, nnn, "ROTATING", rotation_id="r1")
|
|
664
|
+
_active_dead_successor(key)
|
|
665
|
+
monkeypatch.setattr(bootstrap, "REUSE_MIN_AGE_S", 1e18)
|
|
666
|
+
monkeypatch.setattr(bootstrap, "_pane_record_dead",
|
|
667
|
+
lambda rec, **kw: True)
|
|
668
|
+
with lock.held(key):
|
|
669
|
+
res = bootstrap.try_claim(key, new_session_id=_NEW_SID,
|
|
670
|
+
cfg=config.load_config(cwd=repo))
|
|
671
|
+
assert res is not None and res["new_nnn"] == 43
|
|
672
|
+
assert state.load_state(key, 42)["state"] == "ACTIVE"
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
def test_pane_record_dead_true_when_pane_gone():
|
|
676
|
+
rec = {"tmux_session": "cc-spike-repo-zz99"}
|
|
677
|
+
assert bootstrap._pane_record_dead(
|
|
678
|
+
rec, runner=_fake_runner(b"cc-other\n")) is True
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
def test_pane_record_dead_false_when_pane_listed():
|
|
682
|
+
rec = {"tmux_session": "cc-spike-repo-zz99"}
|
|
683
|
+
assert bootstrap._pane_record_dead(
|
|
684
|
+
rec, runner=_fake_runner(b"cc-spike-repo-zz99\ncc-other\n")) is False
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
def test_pane_record_dead_false_without_recorded_pane():
|
|
688
|
+
run = _fake_runner(b"")
|
|
689
|
+
assert bootstrap._pane_record_dead({}, runner=run) is False
|
|
690
|
+
assert run.calls == [] # no tmux call for a pane-less record
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
def test_pane_record_dead_false_when_tmux_fails():
|
|
694
|
+
rec = {"tmux_session": "cc-spike-repo-zz99"}
|
|
695
|
+
assert bootstrap._pane_record_dead(
|
|
696
|
+
rec, runner=_fake_runner(b"", rc=1)) is False
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
def test_pane_record_dead_false_on_probe_error():
|
|
700
|
+
import subprocess as _sp
|
|
701
|
+
|
|
702
|
+
def boom(cmd, **kw):
|
|
703
|
+
raise _sp.SubprocessError("tmux exploded")
|
|
704
|
+
rec = {"tmux_session": "cc-spike-repo-zz99"}
|
|
705
|
+
assert bootstrap._pane_record_dead(rec, runner=boom) is False
|
|
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
|
|
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
|