cc-continuity 0.3.64__tar.gz → 0.3.66__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 (119) hide show
  1. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/PKG-INFO +1 -1
  2. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/README.md +2 -2
  3. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/__init__.py +1 -1
  4. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/bootstrap.py +54 -12
  5. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/cli.py +80 -0
  6. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/rotator.py +16 -3
  7. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/skills.py +13 -1
  8. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity.egg-info/PKG-INFO +1 -1
  9. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/pyproject.toml +1 -1
  10. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_bootstrap.py +39 -0
  11. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_cli.py +127 -0
  12. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_rotator.py +34 -0
  13. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_skills.py +10 -0
  14. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/LICENSE +0 -0
  15. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/__main__.py +0 -0
  16. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/atomic.py +0 -0
  17. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/blink.py +0 -0
  18. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/blink_watch.py +0 -0
  19. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/checkpoint.py +0 -0
  20. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/config.py +0 -0
  21. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/daemon_supervisor.py +0 -0
  22. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/doctor.py +0 -0
  23. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/gitsnap.py +0 -0
  24. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/hooks/__init__.py +0 -0
  25. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/hooks/common.py +0 -0
  26. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/hooks/pre_compact.py +0 -0
  27. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/hooks/pre_tool_use.py +0 -0
  28. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/hooks/session_end.py +0 -0
  29. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/hooks/session_start.py +0 -0
  30. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/hooks/stop.py +0 -0
  31. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/hooks/task.py +0 -0
  32. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/hooks/tool_use.py +0 -0
  33. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/hooks/user_prompt.py +0 -0
  34. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/hosting.py +0 -0
  35. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/install.py +0 -0
  36. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/launch.py +0 -0
  37. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/ledger.py +0 -0
  38. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/lock.py +0 -0
  39. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/managed.py +0 -0
  40. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/naming.py +0 -0
  41. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/notify.py +0 -0
  42. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/overflow.py +0 -0
  43. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/paths.py +0 -0
  44. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/power_plug.py +0 -0
  45. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/progress_pane.py +0 -0
  46. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/project.py +0 -0
  47. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/redact.py +0 -0
  48. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/settings_merge.py +0 -0
  49. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/state.py +0 -0
  50. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/statusline.py +0 -0
  51. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/thresholds.py +0 -0
  52. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/transcript.py +0 -0
  53. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/validate.py +0 -0
  54. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/watchdog.py +0 -0
  55. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/watchdog_digest.py +0 -0
  56. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity/watchdogd.py +0 -0
  57. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity.egg-info/SOURCES.txt +0 -0
  58. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity.egg-info/dependency_links.txt +0 -0
  59. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity.egg-info/entry_points.txt +0 -0
  60. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/cc_continuity.egg-info/top_level.txt +0 -0
  61. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/setup.cfg +0 -0
  62. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_atomic.py +0 -0
  63. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_blink.py +0 -0
  64. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_blink_watch.py +0 -0
  65. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_changelog_notes.py +0 -0
  66. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_checkpoint.py +0 -0
  67. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_cli_ledger.py +0 -0
  68. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_cli_log.py +0 -0
  69. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_config.py +0 -0
  70. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_daemon_supervisor.py +0 -0
  71. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_doctor.py +0 -0
  72. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_gitsnap.py +0 -0
  73. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_hooks_common.py +0 -0
  74. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_hooks_pre_compact.py +0 -0
  75. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_hooks_pre_tool_use.py +0 -0
  76. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_hooks_session_end.py +0 -0
  77. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_hooks_session_start.py +0 -0
  78. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_hooks_stop.py +0 -0
  79. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_hooks_task.py +0 -0
  80. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_hooks_tool_use.py +0 -0
  81. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_hooks_user_prompt.py +0 -0
  82. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_hosting.py +0 -0
  83. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_hygiene.py +0 -0
  84. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_install.py +0 -0
  85. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_integration_phase5.py +0 -0
  86. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_integration_phase6.py +0 -0
  87. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_integration_phase7.py +0 -0
  88. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_launch.py +0 -0
  89. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_ledger.py +0 -0
  90. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_lock.py +0 -0
  91. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_managed.py +0 -0
  92. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_naming.py +0 -0
  93. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_notify.py +0 -0
  94. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_notify_integration.py +0 -0
  95. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_overflow.py +0 -0
  96. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_paths.py +0 -0
  97. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_power_plug.py +0 -0
  98. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_progress_pane.py +0 -0
  99. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_project.py +0 -0
  100. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_readme_badges.py +0 -0
  101. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_readme_gif.py +0 -0
  102. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_redact.py +0 -0
  103. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_settings_merge.py +0 -0
  104. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_state.py +0 -0
  105. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_status.py +0 -0
  106. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_statusline.py +0 -0
  107. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_statusline_cache.py +0 -0
  108. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_thresholds.py +0 -0
  109. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_tmux_host.py +0 -0
  110. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_transcript.py +0 -0
  111. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_transcript_finalize.py +0 -0
  112. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_uninstall.py +0 -0
  113. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_validate.py +0 -0
  114. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_watchdog.py +0 -0
  115. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_watchdog_digest.py +0 -0
  116. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_watchdog_integration.py +0 -0
  117. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_watchdogd.py +0 -0
  118. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/tests/test_wsl_doctor.py +0 -0
  119. {cc_continuity-0.3.64 → cc_continuity-0.3.66}/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.64
3
+ Version: 0.3.66
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**: `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)).
45
+ - **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)).
44
46
  - **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)).
45
47
  - **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)).
46
48
  - **2026-11-23**: Sessions stuck in `CHECKPOINT_VERIFIED` are now actually dispatched to context-400 recovery. The recovery gate accepted `CHECKPOINT_VERIFIED` since v0.3.61, but the watchdog still only reached that gate through screen classification: records outside `ACTIVE`/`WARNED` are skipped as not live, and recovery ran only for sessions classified as alive, turn-dead, stalled or frozen, so a stalled verified checkpoint was never scanned and stayed parked on the oversized prompt; the tick loop now also runs recovery for a skipped verified-checkpoint session while its turn is still in flight, the recovery gate itself (full-auto, one attempt, transcript-tail scan, fresh-prompt check) stays the single source of truth, and three tick-loop integration tests written first pin the dispatch ([commit](https://github.com/pqant/claude-continuity/commit/ff58ebc)).
47
- - **2026-11-23**: Sessions stuck in `CHECKPOINT_VERIFIED` now recover from context-400 too. A rotation that verifies its checkpoint and then fails partway leaves the session in `CHECKPOINT_VERIFIED` with the stale oversized prompt still in the pane: the recovery gate only accepted the pre-rotation states and `recover_400` refused to re-attach a session that already had a fresh prompt, so these sessions stayed stuck and 400ed every request. `CHECKPOINT_VERIFIED` now joins the recovery gate, `recover_400` re-attaches such sessions with the fresh prompt, and a scan that skips a session leaves the one-shot recovery gate unarmed so the recovery still fires when the user returns ([commit](https://github.com/pqant/claude-continuity/commit/f9a1e1a)).
48
- - **2026-11-23**: Context-400 recovery now pushes to your phone. The recovery path fired a `context400` event, but the push message builder had no branch for it, so the notification was silently dropped and nobody saw recoveries from the phone; the `context400` branch now builds the high-priority message with a scrubbed detail line, and a wire-contract test pins the event name on the recovery call so the push cannot silently vanish again ([commit](https://github.com/pqant/claude-continuity/commit/945d1b4)).
49
49
  ## How it works
50
50
 
51
51
  The whole flow in one picture: the automatic session loop, the optional
@@ -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.64"
7
+ __version__ = "0.3.66"
@@ -230,6 +230,30 @@ def _new_work_since_handoff(cp_dir: Path, key: str,
230
230
  return out[-5:]
231
231
 
232
232
 
233
+ def _find_reusable_successor(pref: dict, key: str, old_name: str) -> dict | None:
234
+ """BUG-10: the BOOTSTRAPPING record this claim minted earlier but never
235
+ attached (predecessor == ``old_name``, ``successor`` unset, older than
236
+ ``REUSE_MIN_AGE_S``). Liveness is not probed: a live session is ACTIVE,
237
+ never BOOTSTRAPPING, so adoption cannot hijack a running pane."""
238
+ for s in reversed(pref.get("sessions") or []):
239
+ try:
240
+ rec = state.load_state(key, int(s["nnn"]))
241
+ except (state.StateNotFoundError, ValueError, KeyError):
242
+ continue
243
+ if (rec.get("predecessor") != old_name
244
+ or rec["state"] != "BOOTSTRAPPING"
245
+ or rec.get("successor")):
246
+ continue
247
+ try:
248
+ created = datetime.fromisoformat(rec["created"])
249
+ except (KeyError, TypeError, ValueError):
250
+ continue
251
+ if (datetime.now(timezone.utc) - created).total_seconds() < REUSE_MIN_AGE_S:
252
+ continue
253
+ return rec
254
+ return None
255
+
256
+
233
257
  def try_claim(key: str, *, new_session_id: str, cfg: dict,
234
258
  states: frozenset[str] | None = None,
235
259
  source: str = "clear") -> dict | None:
@@ -243,7 +267,9 @@ def try_claim(key: str, *, new_session_id: str, cfg: dict,
243
267
  a second claim sees ``successor`` set). On success returns
244
268
  ``{"old_name", "old_nnn", "new_name", "new_nnn", "validation",
245
269
  "details", "bootstrap_text"}`` and has: created the successor state
246
- (BOOTSTRAPPING, predecessor = old name, nnn = old+1 at least), set
270
+ (BOOTSTRAPPING, predecessor = old name, nnn = old+1 at least) - or,
271
+ when this predecessor's BOOTSTRAPPING successor already exists but was
272
+ never attached, adopted it at the same index (BUG-10, ``reused``) - set
247
273
  the old session's ``successor`` and moved it to ROTATED, cleared
248
274
  ``pending_consumption`` on the matching latest_checkpoint, appended
249
275
  one ``session_start`` ledger entry to the successor, and updated
@@ -256,11 +282,24 @@ def try_claim(key: str, *, new_session_id: str, cfg: dict,
256
282
  pref = json.loads(pfile.read_text(encoding="utf-8"))
257
283
  root = Path(pref["root"])
258
284
  old_nnn = int(old["nnn"])
259
- nnn_new = max(int(pref["counter"]), old_nnn) + 1
260
- name_new = naming.logical_name(naming.split_name(old["name"])[0], nnn_new)
261
- state.create_session_state(key, name_new, nnn_new, new_session_id,
262
- predecessor=old["name"],
263
- initial_state="BOOTSTRAPPING")
285
+ reuse = _find_reusable_successor(pref, key, old["name"])
286
+ if reuse is not None:
287
+ # BUG-10 (connector 258/259 live): this claim's own never-attached
288
+ # successor already sits at its index - adopt it (standing "no
289
+ # session index jumping" rule) instead of minting a second name.
290
+ nnn_new = int(reuse["nnn"])
291
+ name_new = reuse["name"]
292
+ state.update_fields_unlocked(key, nnn_new, session_id=new_session_id)
293
+ entry = next((s for s in pref["sessions"]
294
+ if int(s.get("nnn", -1)) == nnn_new), None)
295
+ if entry is not None:
296
+ entry["session_id"] = new_session_id
297
+ else:
298
+ nnn_new = max(int(pref["counter"]), old_nnn) + 1
299
+ name_new = naming.logical_name(naming.split_name(old["name"])[0], nnn_new)
300
+ state.create_session_state(key, name_new, nnn_new, new_session_id,
301
+ predecessor=old["name"],
302
+ initial_state="BOOTSTRAPPING")
264
303
  state.update_fields_unlocked(key, old_nnn, successor=name_new)
265
304
  state._transition_unlocked(key, old_nnn, "ROTATED")
266
305
  cp = pref.get("latest_checkpoint")
@@ -270,9 +309,10 @@ def try_claim(key: str, *, new_session_id: str, cfg: dict,
270
309
  cp["pending_consumption"] = False
271
310
  cp["consumed_by"] = name_new
272
311
  pref["latest_checkpoint"] = cp
273
- pref["counter"] = nnn_new
274
- pref["sessions"].append({"name": name_new, "session_id": new_session_id,
275
- "nnn": nnn_new, "created": _now()})
312
+ pref["counter"] = max(int(pref["counter"]), nnn_new)
313
+ if reuse is None:
314
+ pref["sessions"].append({"name": name_new, "session_id": new_session_id,
315
+ "nnn": nnn_new, "created": _now()})
276
316
  atomic.atomic_write_json(pfile, pref)
277
317
  cp_dir = paths.session_dir(key, old_nnn) / "checkpoint"
278
318
  status, details = validate.validate_checkpoint(cp_dir, cfg, root=root)
@@ -286,9 +326,11 @@ def try_claim(key: str, *, new_session_id: str, cfg: dict,
286
326
  details=details, handoff=handoff, handoff_path=str(handoff_file),
287
327
  inline_max=int(cfg.get("inline_handoff_max_chars", 12000)),
288
328
  new_work=_new_work_since_handoff(cp_dir, key, old_nnn))
289
- ledger.append(paths.session_dir(key, nnn_new),
290
- {"type": "session_start", "source": source,
291
- "claimed": old["name"], "validation": status})
329
+ start_entry = {"type": "session_start", "source": source,
330
+ "claimed": old["name"], "validation": status}
331
+ if reuse is not None:
332
+ start_entry["reused"] = True
333
+ ledger.append(paths.session_dir(key, nnn_new), start_entry)
292
334
  return {"old_name": old["name"], "old_nnn": old_nnn,
293
335
  "new_name": name_new, "new_nnn": nnn_new,
294
336
  "validation": status, "details": details,
@@ -69,6 +69,14 @@ def build_parser() -> argparse.ArgumentParser:
69
69
  help="show at most N most recent sessions (default 20)")
70
70
  p_hist.add_argument("--json", action="store_true",
71
71
  help="print the session chain as one JSON array")
72
+ p_hist.add_argument("query", nargs="?",
73
+ help="search this literal substring in checkpoint handoffs")
74
+ p_hist.add_argument("--nnn", type=int, default=None,
75
+ help="with a query: only this session number")
76
+ p_hist.add_argument("--since", default=None,
77
+ help="with a query: sessions created on/after YYYY-MM-DD")
78
+ p_hist.add_argument("--until", default=None,
79
+ help="with a query: sessions created on/before YYYY-MM-DD")
72
80
 
73
81
  p_ratio = sub.add_parser("ratio",
74
82
  help="print the live context ratio of a project")
@@ -622,6 +630,8 @@ def cmd_history(args: argparse.Namespace) -> int:
622
630
  print(f"cc-continuity history: unreadable project record: {e}",
623
631
  file=sys.stderr)
624
632
  return 1
633
+ if getattr(args, "query", None):
634
+ return _history_search(args, key, record)
625
635
  if getattr(args, "json", False):
626
636
  rows = []
627
637
  for s in (record.get("sessions") or [])[-args.n:]:
@@ -648,6 +658,76 @@ def cmd_history(args: argparse.Namespace) -> int:
648
658
  return 0
649
659
 
650
660
 
661
+ def _clip(text: str, limit: int) -> str:
662
+ return text if len(text) <= limit else text[: limit - 3] + "..."
663
+
664
+
665
+ def _history_search(args: argparse.Namespace, key: str,
666
+ record: dict) -> int:
667
+ """Issue #84: read-only literal search over the checkpoint handoffs.
668
+
669
+ Scans sessions/<nnn>/checkpoint/handoff.md only; never touches the
670
+ checkpoint write path, the rotator or the session index. Unreadable
671
+ handoffs are skipped silently; the command is display-only.
672
+ """
673
+ try:
674
+ since = (datetime.strptime(args.since, "%Y-%m-%d").date()
675
+ if args.since else None)
676
+ until = (datetime.strptime(args.until, "%Y-%m-%d").date()
677
+ if args.until else None)
678
+ except ValueError:
679
+ print("cc-continuity history: --since/--until need YYYY-MM-DD",
680
+ file=sys.stderr)
681
+ return 2
682
+ needle = args.query.lower()
683
+ rows = []
684
+ for s in (record.get("sessions") or []):
685
+ if not isinstance(s, dict):
686
+ continue
687
+ nnn = s.get("nnn") if isinstance(s.get("nnn"), int) else 0
688
+ if args.nnn is not None and nnn != args.nnn:
689
+ continue
690
+ date_str = "-"
691
+ created = s.get("created")
692
+ if isinstance(created, str):
693
+ try:
694
+ created_d = datetime.fromisoformat(created).date()
695
+ date_str = created_d.isoformat()
696
+ if since and created_d < since:
697
+ continue
698
+ if until and created_d > until:
699
+ continue
700
+ except ValueError:
701
+ pass
702
+ hpath = paths.session_dir(key, nnn) / "checkpoint" / "handoff.md"
703
+ try:
704
+ lines = hpath.read_text(encoding="utf-8").splitlines()
705
+ except OSError:
706
+ continue
707
+ match = next((ln.strip() for ln in lines if needle in ln.lower()),
708
+ None)
709
+ if match is None:
710
+ continue
711
+ objective = "-"
712
+ after = False
713
+ for ln in lines:
714
+ if not after:
715
+ after = ln.strip().startswith("## Objective")
716
+ continue
717
+ if ln.strip():
718
+ objective = ln.strip()
719
+ break
720
+ rows.append((f"{nnn:03d}", date_str, objective, match))
721
+ if not rows:
722
+ print(f"history search: no matches for {args.query!r}")
723
+ return 0
724
+ print(f"{'NNN':<4} {'DATE':<10} {'OBJECTIVE':<40} MATCH")
725
+ for nnn_str, date_str, objective, match in rows:
726
+ print(f"{nnn_str:<4} {date_str:<10} {_clip(objective, 40):<40} "
727
+ f"{_clip(match, 100)}")
728
+ return 0
729
+
730
+
651
731
  def _project_record(key: str) -> dict | None:
652
732
  pfile = paths.project_dir(key) / "project.json"
653
733
  try:
@@ -304,6 +304,8 @@ def spawn_successor_detached(key: str, nnn: int, session_id: str, cfg: dict,
304
304
  old_name = rec["name"]
305
305
  if verify(key, nnn, f"cp-{nnn:03d}", old_name):
306
306
  succ = _find_successor_rec(key, old_name)
307
+ if succ and succ.get("name"):
308
+ name_new = succ["name"] # BUG-10: ledger/log carry the claim's name
307
309
  r1 = None
308
310
  sid_new = (succ or {}).get("session_id")
309
311
  if sid_new:
@@ -402,11 +404,18 @@ def _find_successor_rec(key: str, old_name: str) -> dict | None:
402
404
 
403
405
  def _successor_name(key: str, nnn: int, old_name: str) -> str:
404
406
  """The name the successor has: the claimed record when the claim already
405
- ran, else the naming successor of the old name (F14 path)."""
407
+ ran, else the claim allocator's next name (F14 path). The fallback
408
+ mirrors bootstrap.try_claim's mint exactly — max(counter, nnn) + 1 — or
409
+ the pane title and ledger freeze a prediction the claim never mints
410
+ (BUG-10: pane said connector-259, real session was 267)."""
406
411
  rec = _find_successor_rec(key, old_name)
407
412
  if rec is not None:
408
413
  return rec["name"]
409
- return naming.successor_name(old_name)
414
+ pref = json.loads((paths.project_dir(key) / "project.json")
415
+ .read_text(encoding="utf-8"))
416
+ counter = int(pref.get("counter") or 0)
417
+ return naming.logical_name(naming.split_name(old_name)[0],
418
+ max(counter, nnn) + 1)
410
419
 
411
420
 
412
421
  def _handoff_path(key: str, nnn: int) -> str:
@@ -649,13 +658,17 @@ def _defer_to_checkpoint(key: str, nnn: int, reason: str) -> None:
649
658
  def _complete(key: str, nnn: int, rec: dict, name_new: str,
650
659
  cfg: dict) -> int:
651
660
  """§11.9 success bookkeeping, shared by attempt 1 and escalation ticks."""
661
+ # BUG-10: the claim is the name's owner - reconcile the predicted name
662
+ # with the real claimed record BEFORE ledger/log see it.
663
+ succ = _find_successor_rec(key, rec["name"])
664
+ if succ and succ.get("name"):
665
+ name_new = succ["name"]
652
666
  state.transition(key, nnn, "ROTATED")
653
667
  delete_pending_prompt(key, nnn) # consumed by the C.8 note
654
668
  ledger.append(paths.session_dir(key, nnn),
655
669
  {"type": "rotation_completed", "successor": name_new})
656
670
  log_event(f"rotator: ROTATION_COMPLETED key={key} {nnn:03d} "
657
671
  f"-> {name_new}")
658
- succ = _find_successor_rec(key, rec["name"])
659
672
  r1 = None
660
673
  sid_new = (succ or {}).get("session_id")
661
674
  if sid_new:
@@ -46,8 +46,20 @@ SKILLS: dict[str, dict] = {
46
46
  },
47
47
  "continuity-history": {
48
48
  "command": "cc-continuity history",
49
- "description": "Show the cc-continuity session chain (history) for the current project.",
49
+ "description": ("Show the cc-continuity session chain (history) for "
50
+ "the current project, or search checkpoint handoffs "
51
+ "for a keyword."),
50
52
  "disable_model_invocation": False,
53
+ "body": (
54
+ "Run the exact command below and report its output verbatim to "
55
+ "the user. Do not paraphrase or add commentary.\n\n```bash\n"
56
+ "cc-continuity history\n```\n\nTo search this project's "
57
+ "checkpoint handoffs (issue #84), run the same command with a "
58
+ "literal keyword (case-insensitive substring), optionally "
59
+ "filtered by session number or date range:\n\n```bash\n"
60
+ "cc-continuity history <query> [--nnn N] "
61
+ "[--since YYYY-MM-DD] [--until YYYY-MM-DD]\n```\n"
62
+ ),
51
63
  },
52
64
  "continuity-excellence": {
53
65
  "body": (
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cc-continuity
3
- Version: 0.3.64
3
+ Version: 0.3.66
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cc-continuity"
7
- version = "0.3.64"
7
+ version = "0.3.66"
8
8
  description = "Zero-touch session rotation for Claude Code (local large-context model)"
9
9
  requires-python = ">=3.11"
10
10
  classifiers = [
@@ -452,3 +452,42 @@ def test_try_reuse_stalled_same_sid_optin_reannounces(cc_home, tmp_path,
452
452
  starts = [e for e in ledger.read(paths.session_dir(key, 2))
453
453
  if e["type"] == "session_start"]
454
454
  assert starts[-1]["reused"] and starts[-1]["source"] == "resume"
455
+
456
+
457
+ def test_try_claim_reuses_never_attached_successor(cc_home, tmp_path):
458
+ # BUG-10 (connector 258/259 live): the claimed session's own
459
+ # never-attached BOOTSTRAPPING successor must be re-adopted at the SAME
460
+ # index by the next claim - minting max+1 and leaving the orphan behind
461
+ # violates the standing "no session index jumping" rule.
462
+ import datetime as _dt
463
+ repo, key, nnn = _verified(cc_home, tmp_path)
464
+ state.transition(key, nnn, "ROTATING", rotation_id="r1")
465
+ orphan_name = "spike-repo-042"
466
+ state.create_session_state(key, orphan_name, 42, "sid-orphan",
467
+ predecessor="spike-repo-001",
468
+ initial_state="BOOTSTRAPPING")
469
+ pfile = paths.project_dir(key) / "project.json"
470
+ pref = json.loads(pfile.read_text())
471
+ pref["sessions"].append({"name": orphan_name, "session_id": "sid-orphan",
472
+ "nnn": 42,
473
+ "created": _dt.datetime.now(
474
+ _dt.timezone.utc).isoformat()})
475
+ pref["counter"] = 42
476
+ pfile.write_text(json.dumps(pref))
477
+ state.update_fields(key, 42, created=(_dt.datetime.now(
478
+ _dt.timezone.utc) - _dt.timedelta(hours=1)).isoformat())
479
+ with lock.held(key):
480
+ res = bootstrap.try_claim(key, new_session_id=_NEW_SID,
481
+ cfg=config.load_config(cwd=repo))
482
+ assert res is not None
483
+ assert res["new_nnn"] == 42 and res["new_name"] == "spike-repo-042"
484
+ new = state.load_state(key, 42)
485
+ assert new["session_id"] == _NEW_SID
486
+ assert new["predecessor"] == "spike-repo-001"
487
+ assert state.load_state(key, nnn)["successor"] == "spike-repo-042"
488
+ pref2 = json.loads(pfile.read_text())
489
+ assert sum(1 for s in pref2["sessions"] if s["nnn"] == 42) == 1
490
+ assert pref2["counter"] == 42
491
+ entries = ledger.read(paths.session_dir(key, 42))
492
+ assert entries[-1]["type"] == "session_start"
493
+ assert entries[-1].get("reused") is True
@@ -1428,3 +1428,130 @@ def test_cmd_install_dry_run_nonzero_on_missing_prereqs(tmp_path, monkeypatch,
1428
1428
  rc = cli.cmd_install(_install_ns(dry_run=True))
1429
1429
  assert rc == 1
1430
1430
  assert "tmux" in capsys.readouterr().err
1431
+
1432
+
1433
+ # ------------------------------------------------ history search (issue #84)
1434
+
1435
+
1436
+ def _write_handoff(key, nnn, objective, body_lines):
1437
+ """Minimal handoff.md for the read-only #84 search (checkpoint dir)."""
1438
+ cdir = paths.session_dir(key, nnn) / "checkpoint"
1439
+ cdir.mkdir(parents=True, exist_ok=True)
1440
+ text = (f"# Handoff cp-{nnn:03d}\n\n"
1441
+ "## Objective\n\n"
1442
+ f"{objective}\n\n"
1443
+ "## Current Task and Exact Stopping Point\n\n"
1444
+ + "\n".join(body_lines) + "\n")
1445
+ (cdir / "handoff.md").write_text(text, encoding="utf-8")
1446
+
1447
+
1448
+ def _set_created(key, nnn, iso):
1449
+ pfile = paths.project_dir(key) / "project.json"
1450
+ pref = json.loads(pfile.read_text(encoding="utf-8"))
1451
+ for s in pref["sessions"]:
1452
+ if s["nnn"] == nnn:
1453
+ s["created"] = iso
1454
+ pfile.write_text(json.dumps(pref), encoding="utf-8")
1455
+
1456
+
1457
+ def test_history_search_finds_match_and_shows_table(cc_home, tmp_path,
1458
+ monkeypatch, capsys):
1459
+ repo = make_repo(tmp_path)
1460
+ key, nnn = register_session(repo)
1461
+ key2, nnn2 = register_session(
1462
+ repo, session_id="22222222-2222-2222-2222-222222222222")
1463
+ _write_handoff(key, 1, "Ship the rotation threshold fix.",
1464
+ ["thresholds raised to warn 0.65 yesterday"])
1465
+ _write_handoff(key2, 2, "Unrelated docs work.",
1466
+ ["nothing interesting here"])
1467
+ monkeypatch.chdir(repo)
1468
+ assert cli.main(["history", "0.65"]) == 0
1469
+ lines = [l for l in capsys.readouterr().out.splitlines() if l.strip()]
1470
+ assert lines[0].startswith("NNN") and "MATCH" in lines[0]
1471
+ assert len(lines) == 2 # only session 1 matched
1472
+ row = lines[1]
1473
+ assert row.startswith("001")
1474
+ assert "Ship the rotation threshold fix." in row # objective column
1475
+ assert "warn 0.65" in row # matched-line snippet
1476
+
1477
+
1478
+ def test_history_search_is_case_insensitive(cc_home, tmp_path, monkeypatch,
1479
+ capsys):
1480
+ repo = make_repo(tmp_path)
1481
+ key, nnn = register_session(repo)
1482
+ _write_handoff(key, 1, "Ship the rotation threshold fix.",
1483
+ ["thresholds raised to warn 0.65 yesterday"])
1484
+ monkeypatch.chdir(repo)
1485
+ assert cli.main(["history", "WARN"]) == 0
1486
+ lines = [l for l in capsys.readouterr().out.splitlines() if l.strip()]
1487
+ assert len(lines) == 2 and lines[1].startswith("001")
1488
+
1489
+
1490
+ def test_history_search_nnn_filter(cc_home, tmp_path, monkeypatch, capsys):
1491
+ repo = make_repo(tmp_path)
1492
+ key, nnn = register_session(repo)
1493
+ key2, nnn2 = register_session(
1494
+ repo, session_id="22222222-2222-2222-2222-222222222222")
1495
+ _write_handoff(key, 1, "Ship the rotation threshold fix.", ["x"])
1496
+ _write_handoff(key2, 2, "Rotation cleanup.", ["y"])
1497
+ monkeypatch.chdir(repo)
1498
+ assert cli.main(["history", "rotation", "--nnn", "2"]) == 0
1499
+ lines = [l for l in capsys.readouterr().out.splitlines() if l.strip()]
1500
+ assert len(lines) == 2
1501
+ assert lines[1].startswith("002")
1502
+ assert "Rotation cleanup." in lines[1]
1503
+
1504
+
1505
+ def test_history_search_date_range(cc_home, tmp_path, monkeypatch, capsys):
1506
+ repo = make_repo(tmp_path)
1507
+ key, nnn = register_session(repo)
1508
+ key2, nnn2 = register_session(
1509
+ repo, session_id="22222222-2222-2222-2222-222222222222")
1510
+ _write_handoff(key, 1, "Old work.", ["threshold note one"])
1511
+ _write_handoff(key2, 2, "New work.", ["threshold note two"])
1512
+ _set_created(key, 1, "2026-11-01T10:00:00+00:00")
1513
+ _set_created(key, 2, "2026-11-20T10:00:00+00:00")
1514
+ monkeypatch.chdir(repo)
1515
+ assert cli.main(["history", "threshold", "--since", "2026-11-10"]) == 0
1516
+ lines = [l for l in capsys.readouterr().out.splitlines() if l.strip()]
1517
+ assert len(lines) == 2 and lines[1].startswith("002")
1518
+ capsys.readouterr()
1519
+ assert cli.main(["history", "threshold",
1520
+ "--until", "2026-11-10"]) == 0
1521
+ lines = [l for l in capsys.readouterr().out.splitlines() if l.strip()]
1522
+ assert len(lines) == 2 and lines[1].startswith("001")
1523
+
1524
+
1525
+ def test_history_search_no_match_message(cc_home, tmp_path, monkeypatch,
1526
+ capsys):
1527
+ repo = make_repo(tmp_path)
1528
+ key, nnn = register_session(repo)
1529
+ _write_handoff(key, 1, "Ship the rotation threshold fix.", ["x"])
1530
+ monkeypatch.chdir(repo)
1531
+ assert cli.main(["history", "zebra-not-there"]) == 0
1532
+ assert "no matches" in capsys.readouterr().out
1533
+
1534
+
1535
+ def test_history_search_unreadable_handoff_skipped(cc_home, tmp_path,
1536
+ monkeypatch, capsys):
1537
+ repo = make_repo(tmp_path)
1538
+ key, nnn = register_session(repo)
1539
+ key2, nnn2 = register_session(
1540
+ repo, session_id="22222222-2222-2222-2222-222222222222")
1541
+ _write_handoff(key, 1, "Ship the rotation threshold fix.", ["x"])
1542
+ # session 2: handoff.md is a directory -> unreadable, must be skipped
1543
+ (paths.session_dir(key2, nnn2) / "checkpoint").mkdir(parents=True,
1544
+ exist_ok=True)
1545
+ (paths.session_dir(key2, nnn2) / "checkpoint" / "handoff.md").mkdir()
1546
+ monkeypatch.chdir(repo)
1547
+ assert cli.main(["history", "threshold"]) == 0
1548
+ lines = [l for l in capsys.readouterr().out.splitlines() if l.strip()]
1549
+ assert len(lines) == 2 and lines[1].startswith("001")
1550
+
1551
+
1552
+ def test_history_search_without_project(cc_home, tmp_path, monkeypatch,
1553
+ capsys):
1554
+ repo = make_repo(tmp_path)
1555
+ monkeypatch.chdir(repo)
1556
+ assert cli.main(["history", "anything"]) == 0
1557
+ assert "No cc-continuity project" in capsys.readouterr().out
@@ -1303,3 +1303,37 @@ def test_paneless_spawn_unattended_adds_skip_permissions(
1303
1303
  assert outcome == "deferred" # no claim; we only inspect the cmd
1304
1304
  ns = next(c for c in _calls(fake_tmux) if c[0] == "new-session")
1305
1305
  assert "--dangerously-skip-permissions" in ns[6]
1306
+
1307
+
1308
+ def test_complete_uses_claimed_successor_name(cc_home, tmp_path, monkeypatch):
1309
+ # BUG-10 (connector-258 live): rotation_completed was written with the
1310
+ # rotator's PREDICTED name even though the real claimed record had
1311
+ # already been fetched in the same function - the old ledger then
1312
+ # contradicted state.successor forever (ledger 259 vs state 267).
1313
+ repo = make_repo(tmp_path)
1314
+ key, nnn = register_session(repo)
1315
+ walk_to(key, nnn, "ROTATING")
1316
+ state.update_fields(key, nnn, rotation_id="r1")
1317
+ monkeypatch.setattr(rotator, "_find_successor_rec",
1318
+ lambda k, n: {"name": "spike-repo-777", "nnn": 777,
1319
+ "session_id": None})
1320
+ monkeypatch.setattr(rotator.notify, "safe_send", lambda *a, **k: None)
1321
+ rec = state.load_state(key, nnn)
1322
+ rotator._complete(key, nnn, rec, "spike-repo-002", {})
1323
+ evs = [e for e in ledger.read(paths.session_dir(key, nnn))
1324
+ if e["type"] == "rotation_completed"]
1325
+ assert evs[-1]["successor"] == "spike-repo-777"
1326
+
1327
+
1328
+ def test_successor_name_fallback_follows_project_counter(cc_home, tmp_path):
1329
+ # BUG-10: the prediction must equal the CLAIM allocator
1330
+ # (max(counter, old_nnn) + 1), not strict nnn+1 - when stale records
1331
+ # advanced the counter the pane title and ledger froze the stale
1332
+ # prediction (live: pane said connector-259, real session was 267).
1333
+ repo = make_repo(tmp_path)
1334
+ key, nnn = register_session(repo)
1335
+ pfile = paths.project_dir(key) / "project.json"
1336
+ pref = json.loads(pfile.read_text())
1337
+ pref["counter"] = nnn + 9
1338
+ pfile.write_text(json.dumps(pref))
1339
+ assert rotator._successor_name(key, nnn, "spike-repo-001") == "spike-repo-011"
@@ -95,3 +95,13 @@ def test_all_descriptions_carry_the_continuity_keyword():
95
95
  # skill must carry "cc-continuity" so it stays discoverable (issue 82)
96
96
  for name in skills.skill_names():
97
97
  assert "cc-continuity" in skills.SKILLS[name]["description"]
98
+
99
+
100
+ def test_history_skill_pins_search_usage():
101
+ # issue #84: the skill text must teach the keyword search so the /cc
102
+ # filter and the invoking agent both see it.
103
+ text = skills.skill_text("continuity-history")
104
+ assert "cc-continuity history <query>" in text
105
+ assert "search" in text.lower()
106
+ # the plain-chain command fence (test_command_mapping) still holds
107
+ assert "```bash\ncc-continuity history\n```" in text
File without changes
File without changes