cc-continuity 0.3.53__tar.gz → 0.3.55__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 (117) hide show
  1. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/PKG-INFO +1 -1
  2. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/README.md +2 -2
  3. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/__init__.py +1 -1
  4. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/cli.py +13 -1
  5. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/doctor.py +36 -7
  6. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/install.py +181 -3
  7. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity.egg-info/PKG-INFO +1 -1
  8. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/pyproject.toml +1 -1
  9. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_cli.py +50 -0
  10. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_doctor.py +54 -7
  11. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_install.py +105 -0
  12. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/LICENSE +0 -0
  13. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/__main__.py +0 -0
  14. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/atomic.py +0 -0
  15. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/blink.py +0 -0
  16. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/blink_watch.py +0 -0
  17. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/bootstrap.py +0 -0
  18. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/checkpoint.py +0 -0
  19. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/config.py +0 -0
  20. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/daemon_supervisor.py +0 -0
  21. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/gitsnap.py +0 -0
  22. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/hooks/__init__.py +0 -0
  23. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/hooks/common.py +0 -0
  24. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/hooks/pre_compact.py +0 -0
  25. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/hooks/pre_tool_use.py +0 -0
  26. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/hooks/session_end.py +0 -0
  27. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/hooks/session_start.py +0 -0
  28. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/hooks/stop.py +0 -0
  29. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/hooks/task.py +0 -0
  30. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/hooks/tool_use.py +0 -0
  31. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/hooks/user_prompt.py +0 -0
  32. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/hosting.py +0 -0
  33. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/launch.py +0 -0
  34. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/ledger.py +0 -0
  35. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/lock.py +0 -0
  36. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/managed.py +0 -0
  37. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/naming.py +0 -0
  38. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/notify.py +0 -0
  39. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/paths.py +0 -0
  40. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/power_plug.py +0 -0
  41. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/progress_pane.py +0 -0
  42. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/project.py +0 -0
  43. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/redact.py +0 -0
  44. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/rotator.py +0 -0
  45. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/settings_merge.py +0 -0
  46. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/skills.py +0 -0
  47. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/state.py +0 -0
  48. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/statusline.py +0 -0
  49. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/thresholds.py +0 -0
  50. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/transcript.py +0 -0
  51. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/validate.py +0 -0
  52. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/watchdog.py +0 -0
  53. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/watchdog_digest.py +0 -0
  54. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity/watchdogd.py +0 -0
  55. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity.egg-info/SOURCES.txt +0 -0
  56. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity.egg-info/dependency_links.txt +0 -0
  57. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity.egg-info/entry_points.txt +0 -0
  58. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/cc_continuity.egg-info/top_level.txt +0 -0
  59. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/setup.cfg +0 -0
  60. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_atomic.py +0 -0
  61. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_blink.py +0 -0
  62. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_blink_watch.py +0 -0
  63. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_bootstrap.py +0 -0
  64. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_changelog_notes.py +0 -0
  65. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_checkpoint.py +0 -0
  66. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_cli_ledger.py +0 -0
  67. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_cli_log.py +0 -0
  68. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_config.py +0 -0
  69. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_daemon_supervisor.py +0 -0
  70. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_gitsnap.py +0 -0
  71. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_hooks_common.py +0 -0
  72. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_hooks_pre_compact.py +0 -0
  73. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_hooks_pre_tool_use.py +0 -0
  74. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_hooks_session_end.py +0 -0
  75. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_hooks_session_start.py +0 -0
  76. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_hooks_stop.py +0 -0
  77. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_hooks_task.py +0 -0
  78. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_hooks_tool_use.py +0 -0
  79. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_hooks_user_prompt.py +0 -0
  80. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_hosting.py +0 -0
  81. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_hygiene.py +0 -0
  82. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_integration_phase5.py +0 -0
  83. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_integration_phase6.py +0 -0
  84. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_integration_phase7.py +0 -0
  85. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_launch.py +0 -0
  86. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_ledger.py +0 -0
  87. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_lock.py +0 -0
  88. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_managed.py +0 -0
  89. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_naming.py +0 -0
  90. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_notify.py +0 -0
  91. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_notify_integration.py +0 -0
  92. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_paths.py +0 -0
  93. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_power_plug.py +0 -0
  94. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_progress_pane.py +0 -0
  95. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_project.py +0 -0
  96. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_readme_badges.py +0 -0
  97. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_readme_gif.py +0 -0
  98. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_redact.py +0 -0
  99. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_rotator.py +0 -0
  100. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_settings_merge.py +0 -0
  101. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_skills.py +0 -0
  102. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_state.py +0 -0
  103. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_status.py +0 -0
  104. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_statusline.py +0 -0
  105. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_statusline_cache.py +0 -0
  106. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_thresholds.py +0 -0
  107. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_tmux_host.py +0 -0
  108. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_transcript.py +0 -0
  109. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_transcript_finalize.py +0 -0
  110. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_uninstall.py +0 -0
  111. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_validate.py +0 -0
  112. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_watchdog.py +0 -0
  113. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_watchdog_digest.py +0 -0
  114. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_watchdog_integration.py +0 -0
  115. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_watchdogd.py +0 -0
  116. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/tests/test_wsl_doctor.py +0 -0
  117. {cc_continuity-0.3.53 → cc_continuity-0.3.55}/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.53
3
+ Version: 0.3.55
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-21**: The `stale-locks` warning is gone for good. Doctor keeps a last-holder diagnostic file per project (dead PID, released flock) forever after the last hook event, so every abandoned project left a leftover that made `! stale-locks` a permanent line on long-lived machines; doctor now proves the flock free at the kernel level and removes the leftover itself (reported as `removed <names>`), while a lock whose flock is still actually held (the inherited-fd edge case) survives and is reported as `held: <names>` instead of being silently deleted ([commit](https://github.com/pqant/claude-continuity/commit/49862af)).
45
+ - **2026-11-21**: Install now shows its plan before touching anything. `cc-continuity install --dry-run` prints every managed target (app copy, launcher stub, `~/.local/bin` symlink, `settings.json`, `~/.claude/CLAUDE.md`, the six skills, the login-shell rc block, `config.json`) with a create/update/unchanged/replace status and indented `+` bullets spelling out exactly what a merge would add (hook events, the chained user status line, env keys, permission rules, config keys), and it aborts with the same messages and a non-zero exit as a real run on missing prerequisites or a corrupt `settings.json`, while writing nothing ([commit](https://github.com/pqant/claude-continuity/commit/dede72d)).
44
46
  - **2026-11-21**: A reply you only glanced at keeps asking. The focus dwell used to consume the reply blink on the first look, so reading an answer and backgrounding the window without replying left the tab quiet with the answer pending; the poller and the pane animator now catch the window losing focus again while the reply is still unanswered and re-light the tab after a fresh settle window, until the user actually replies ([commit](https://github.com/pqant/claude-continuity/commit/8c17eb9)).
45
47
  - **2026-11-21**: The status line now runs its heavy work only at tool boundaries. Idle re-renders reuse the cached facts (session lookup, ledger reads, transcript parse, pane capture) while the shimmer sweep, the reply settle marker and the HUD ratio keep moving, the mode-1 pane feed only rewrites when the data changes, and a corrupt or missing cache always falls back to the full render ([commit](https://github.com/pqant/claude-continuity/commit/7601949)).
46
48
  - **2026-11-20**: The README now shows the product in motion. A short GIF sits in the How it works section: the animated context-usage segment sweeps while live, then the rotation handoff moments (`HANDOFF!`, `ROTATING`) and the fresh successor session follow, every frame drawn by the real status line code ([commit](https://github.com/pqant/claude-continuity/commit/73ede6c)).
47
- - **2026-11-19**: A warned session no longer idles on its own handoff. After the c1 rotation warning the model could write its `handoff.draft.md`, but drafts were only ever read in HANDOFF_REQUESTED, so the session waited at the prompt with a finished handoff on disk; the Stop hook now consumes a WARNED draft at turn end through the normal handoff path - a valid draft finalizes silently, an invalid one gets the usual guidance - and sessions that were never warned never rotate on a self-written draft ([commit](https://github.com/pqant/claude-continuity/commit/330d4db)).
48
- - **2026-11-19**: Two small observability wins for the push layer. `notify stop|notification --dry-run` renders the exact push (enabled state, title, priority and body) without sending anything or burning the one-push-per-minute bucket, and `watchdog status` now ends with a `last heartbeat: <local time> (<N>s ago)` line so a stalled daemon is visible at a glance; a missing or corrupt stamp reads `last heartbeat: never` ([commit](https://github.com/pqant/claude-continuity/commit/eb93cc1)).
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.53"
7
+ __version__ = "0.3.55"
@@ -162,6 +162,8 @@ def build_parser() -> argparse.ArgumentParser:
162
162
  p_inst.add_argument("--ntfy", default=None,
163
163
  help="ntfy endpoint URL (or 'off' to disable; "
164
164
  "prompts on a TTY when omitted)")
165
+ p_inst.add_argument("--dry-run", action="store_true",
166
+ help="print the managed-change plan, write nothing")
165
167
  p_un = sub.add_parser("uninstall",
166
168
  help="remove cc-continuity (PRD §17)")
167
169
  p_un.add_argument("--purge", action="store_true",
@@ -1296,13 +1298,23 @@ Uninstall: cc-continuity uninstall
1296
1298
 
1297
1299
  def cmd_install(args: argparse.Namespace) -> int:
1298
1300
  from . import install # local import keeps cli import light
1301
+ dry = getattr(args, "dry_run", False)
1299
1302
  try:
1300
1303
  ntfy = install.resolve_ntfy(
1301
1304
  args.ntfy, is_tty=sys.stdin.isatty() and sys.stdout.isatty())
1302
- install.install(Path.home(), window=args.window, ntfy=ntfy)
1305
+ if dry:
1306
+ plan = install.plan_install(Path.home(), window=args.window,
1307
+ ntfy=ntfy)
1308
+ else:
1309
+ install.install(Path.home(), window=args.window, ntfy=ntfy)
1303
1310
  except install.InstallError as e:
1304
1311
  print(f"cc-continuity install: {e}", file=sys.stderr)
1305
1312
  return 1
1313
+ if dry:
1314
+ print("cc-continuity install: dry run (nothing written)")
1315
+ for line in plan:
1316
+ print(" " + line)
1317
+ return 0
1306
1318
  print("cc-continuity installed.")
1307
1319
  for line in USAGE_SUMMARY.splitlines():
1308
1320
  print(" " + line)
@@ -1,5 +1,7 @@
1
1
  """Health checks (PRD §16/§17). Read-only except deletion of
2
- ``checkpoint.tmp-*`` older than 1 h (PRD §18: ".tmp cleaned by doctor").
2
+ ``checkpoint.tmp-*`` older than 1 h (PRD §18: ".tmp cleaned by doctor")
3
+ and removal of stale project ``lock`` files whose flock the kernel has
4
+ already released (dead PID, old ts - issue #79).
3
5
 
4
6
  Exit code (CLI): 0 iff no check is not-ok; warnings do not fail.
5
7
  A half-installed or uninstalled machine must never raise — every check
@@ -9,6 +11,7 @@ guards its own read errors.
9
11
  from __future__ import annotations
10
12
 
11
13
  import dataclasses
14
+ import fcntl
12
15
  import json
13
16
  import os
14
17
  import plistlib
@@ -281,8 +284,14 @@ def run_doctor(home: Path, runner=subprocess.run,
281
284
  f"config {cfg_tokens} vs observed {observed}",
282
285
  warning=mismatch)
283
286
 
284
- # 14: stale locks (warning)
285
- stale = []
287
+ # 14: stale locks - clean up leftover last-holder files of dead runs.
288
+ # The flock is the authority: an old ts + dead PID + kernel-released
289
+ # flock means nobody can still be holding it (a crashed holder's flock
290
+ # died with the process), so the retained diagnostic file is pure
291
+ # residue and doctor removes it (same cleanup precedent as tmp-residue).
292
+ # If the flock is STILL held (inherited-fd edge case) the file survives
293
+ # and the check warns instead - deleting it would lie about the state.
294
+ removed, held = [], []
286
295
  for lf in (store / "projects").glob("*/lock"):
287
296
  info = _safe_json(lf)
288
297
  if not isinstance(info, dict):
@@ -291,10 +300,30 @@ def run_doctor(home: Path, runner=subprocess.run,
291
300
  if (isinstance(ts, (int, float)) and not isinstance(ts, bool)
292
301
  and time.time() - ts > LOCK_STALE_AFTER
293
302
  and isinstance(pid, int) and not pid_alive(pid)):
294
- stale.append(lf.parent.name)
295
- add("stale-locks", True,
296
- "none" if not stale else f"stale: {', '.join(stale)}",
297
- warning=bool(stale))
303
+ try:
304
+ fd = os.open(lf, os.O_RDWR)
305
+ except OSError:
306
+ continue
307
+ try:
308
+ try:
309
+ fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
310
+ except OSError:
311
+ held.append(lf.parent.name)
312
+ else:
313
+ fcntl.flock(fd, fcntl.LOCK_UN)
314
+ try:
315
+ lf.unlink()
316
+ except FileNotFoundError:
317
+ pass
318
+ removed.append(lf.parent.name)
319
+ finally:
320
+ os.close(fd)
321
+ detail = "none"
322
+ if removed:
323
+ detail = "removed " + ", ".join(removed)
324
+ if held:
325
+ detail += ("; " if removed else "") + "held: " + ", ".join(held)
326
+ add("stale-locks", True, detail, warning=bool(removed or held))
298
327
 
299
328
  # 15: tmp residue — delete > 1 h, warn about the rest
300
329
  deleted, recent = [], []
@@ -30,9 +30,10 @@ import time
30
30
  from pathlib import Path
31
31
 
32
32
  from . import __version__, atomic, config, managed, skills
33
- from .settings_merge import (ENV_OVERRIDE_KEY, ENV_OVERRIDE_VALUE,
34
- detect_format, dump_settings,
35
- merge_settings, unmerge_settings)
33
+ from .settings_merge import (ENV_KEYS, ENV_OVERRIDE_KEY, ENV_OVERRIDE_VALUE,
34
+ HOOK_EVENTS, detect_format, dump_settings,
35
+ is_ours, merge_settings, our_hook_entry,
36
+ unmerge_settings)
36
37
 
37
38
  MIN_CLAUDE = (2, 1, 209) # Phase 0 verified floor (VERIFICATION.md)
38
39
 
@@ -428,6 +429,183 @@ def install(home: Path, *, window: int | None = None,
428
429
  return manifest
429
430
 
430
431
 
432
+ # ------------------------------------------------------------- dry-run plan
433
+
434
+
435
+ def plan_install(home: Path, *, window: int | None = None,
436
+ ntfy: str | None = None,
437
+ runner=subprocess.run) -> list[str]:
438
+ """Render the managed-change plan without writing anything (issue #41).
439
+
440
+ Walks ``install`` step for step - same prerequisite checks, same
441
+ abort conditions (each raises ``InstallError`` with the exact message
442
+ a real run would die on), but read-only throughout. Returns one line
443
+ per managed target: ``<path> <status>: <detail>`` with indented
444
+ ``+`` bullets for what a merge would add. The CLI owns the banner.
445
+ """
446
+ home = Path(home)
447
+ missing = check_prerequisites(home, runner=runner)
448
+ if missing:
449
+ raise InstallError("missing prerequisites: " + "; ".join(missing))
450
+
451
+ lines: list[str] = []
452
+ store = home / ".claude-continuity"
453
+
454
+ # app copy + launcher stub (same self-destruct guard as copy_app)
455
+ pkg_src = Path(__file__).resolve().parent
456
+ pkg_dst = store / "app" / "cc_continuity"
457
+ if pkg_src == pkg_dst.resolve():
458
+ raise InstallError(
459
+ "refusing to install from the installed app dir "
460
+ f"({pkg_src}) - run install from the dev tree")
461
+ lines.append(f"{pkg_dst} replace: package copy of {pkg_src} "
462
+ "(replaced on every install)")
463
+ lines.append(f"{store / 'app' / 'bin' / 'cc-continuity'} write: "
464
+ "launcher stub, mode 0755")
465
+
466
+ # ~/.local/bin symlink (same refuse rule as make_symlink)
467
+ bin_link = home / ".local" / "bin" / "cc-continuity"
468
+ launcher = store / "app" / "bin" / "cc-continuity"
469
+ if bin_link.is_symlink():
470
+ if os.path.realpath(bin_link) == os.path.realpath(launcher):
471
+ lines.append(f"{bin_link} unchanged: already -> {launcher}")
472
+ else:
473
+ lines.append(f"{bin_link} replace: symlink retargeted -> "
474
+ f"{launcher}")
475
+ elif bin_link.exists():
476
+ raise InstallError(
477
+ f"refusing to replace existing non-symlink file: {bin_link}")
478
+ else:
479
+ lines.append(f"{bin_link} create: symlink -> {launcher}")
480
+
481
+ # settings.json (merge-never-replace diffed against the current file)
482
+ claude_dir = home / ".claude"
483
+ settings_path = claude_dir / "settings.json"
484
+ win = int(window) if window is not None else 262144
485
+ sm: dict | None = None
486
+ if settings_path.is_file():
487
+ raw = settings_path.read_bytes()
488
+ try:
489
+ existing = json.loads(raw)
490
+ except ValueError as e:
491
+ raise InstallError(f"invalid JSON in {settings_path}: {e}") from e
492
+ if not isinstance(existing, dict):
493
+ raise InstallError(
494
+ f"settings.json must be a JSON object: {settings_path}")
495
+ merged, sm = merge_settings(existing, launcher=str(bin_link),
496
+ window=win)
497
+ if merged == existing:
498
+ lines.append(f"{settings_path} unchanged: our entries already "
499
+ "in place")
500
+ else:
501
+ lines.append(f"{settings_path} update: merge-never-replace "
502
+ "(backup settings.json.bak-<timestamp> first)")
503
+ n_ev = sum(1 for ev in HOOK_EVENTS
504
+ if [e for e in (existing.get("hooks") or {})
505
+ .get(ev, []) if isinstance(e, dict) and is_ours(e)]
506
+ != [our_hook_entry(ev, str(bin_link))])
507
+ if n_ev:
508
+ lines.append(f" + hooks: {n_ev} event(s) -> "
509
+ f"'{bin_link} hook <event>'")
510
+ if sm["status_line_changed"]:
511
+ prev = (sm.get("previous_status_line") or {}).get("command")
512
+ lines.append(f" + statusLine: chain user command {prev}")
513
+ env_vals = {ENV_KEYS[0]: str(win),
514
+ ENV_OVERRIDE_KEY: ENV_OVERRIDE_VALUE}
515
+ added = [f"{k}={env_vals[k]}" for k, old in sm["env_prev"].items()
516
+ if old is None]
517
+ if added:
518
+ lines.append(" + env: " + ", ".join(added))
519
+ if sm["allow_added"]:
520
+ lines.append(" + permissions.allow: "
521
+ + ", ".join(sm["allow_added"]))
522
+ if sm["dirs_added"]:
523
+ lines.append(" + permissions.additionalDirectories: "
524
+ + ", ".join(sm["dirs_added"]))
525
+ else:
526
+ lines.append(f"{settings_path} create: new file (hooks, statusLine, "
527
+ "env, permissions)")
528
+
529
+ # ~/.claude/CLAUDE.md managed block
530
+ claude_md = claude_dir / "CLAUDE.md"
531
+ if claude_md.is_file():
532
+ prev_md = claude_md.read_text(encoding="utf-8")
533
+ new_md = managed.upsert_block(
534
+ prev_md, CLAUDE_MD_BEGIN, CLAUDE_MD_END,
535
+ CLAUDE_MD_CONTENT.rstrip("\n"))
536
+ status = "update" if new_md != prev_md else "unchanged"
537
+ lines.append(f"{claude_md} {status}: managed continuity block")
538
+ else:
539
+ lines.append(f"{claude_md} create: managed continuity block")
540
+
541
+ # user skills
542
+ skills_dir = claude_dir / "skills"
543
+ stale = [f for f in skills.skill_files(skills_dir)
544
+ if not f.is_file()
545
+ or f.read_text(encoding="utf-8") != skills.skill_text(
546
+ f.parent.name)]
547
+ total = len(skills.skill_names())
548
+ if stale:
549
+ lines.append(f"{skills_dir} update: write {len(stale)} of {total} "
550
+ "SKILL.md files")
551
+ else:
552
+ lines.append(f"{skills_dir} unchanged: all {total} SKILL.md files "
553
+ "current")
554
+
555
+ # login-shell rc managed block (symlink-aware, same target as install)
556
+ from . import hosting # lazy: hosting imports this module (T4 note)
557
+ if hosting.kind() == "macos":
558
+ zshrc = home / ".zshrc"
559
+ is_link = zshrc.is_symlink()
560
+ rc_path = zshrc.resolve() if is_link else zshrc
561
+ else:
562
+ rc_link = rc_target(home) # unsupported login shell: same abort
563
+ is_link = rc_link.is_symlink()
564
+ rc_path = rc_link.resolve() if is_link else rc_link
565
+ if rc_path.is_file():
566
+ rtext = rc_path.read_text(encoding="utf-8")
567
+ new_rc = managed.upsert_block(rtext, ZSHRC_BEGIN, ZSHRC_END,
568
+ ZSHRC_CONTENT.rstrip("\n"))
569
+ status = "update" if new_rc != rtext else "unchanged"
570
+ lines.append(f"{rc_path} {status}: managed launcher block"
571
+ + (" (symlink-aware)" if is_link else ""))
572
+ else:
573
+ lines.append(f"{rc_path} create: managed launcher block"
574
+ + (" (via symlink)" if is_link else ""))
575
+
576
+ # config.json (user-visible keys only; the installer manifest is
577
+ # restamped by any real run and is not reported as a user change)
578
+ cfg_path = store / "config.json"
579
+ cfg: dict = {}
580
+ if cfg_path.is_file():
581
+ try:
582
+ loaded = json.loads(cfg_path.read_text(encoding="utf-8"))
583
+ if isinstance(loaded, dict):
584
+ cfg = loaded
585
+ except (ValueError, OSError):
586
+ pass # corrupt config: install tolerates, doctor flags
587
+ diffs: list[str] = []
588
+ if window is not None and cfg.get("window_tokens") != win:
589
+ diffs.append(f"window_tokens={win}")
590
+ if ntfy is not None:
591
+ if cfg.get("notify_endpoint") != ntfy:
592
+ diffs.append(f"notify_endpoint={ntfy or '(off)'}")
593
+ if cfg.get("notify_enabled") != bool(ntfy):
594
+ diffs.append(f"notify_enabled={bool(ntfy)}")
595
+ chained = ((sm or {}).get("previous_status_line") or {}).get("command")
596
+ if chained and cfg.get("chained_statusline") != chained:
597
+ diffs.append(f"chained_statusline={chained}")
598
+ if not cfg_path.is_file():
599
+ lines.append(f"{cfg_path} create: defaults"
600
+ + (", " + ", ".join(diffs) if diffs else ""))
601
+ elif diffs:
602
+ lines.append(f"{cfg_path} update: " + ", ".join(diffs))
603
+ else:
604
+ lines.append(f"{cfg_path} unchanged: user keys current "
605
+ "(installer manifest restamped)")
606
+ return lines
607
+
608
+
431
609
  # ------------------------------------------- generic-hook migration (issue #7)
432
610
 
433
611
  # The three user-level generic curls (spec B6) are matched by signature,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cc-continuity
3
- Version: 0.3.53
3
+ Version: 0.3.55
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.53"
7
+ version = "0.3.55"
8
8
  description = "Zero-touch session rotation for Claude Code (local large-context model)"
9
9
  requires-python = ">=3.11"
10
10
  classifiers = [
@@ -1378,3 +1378,53 @@ def test_completion_scripts_match_parse_args(capsys):
1378
1378
  except SystemExit:
1379
1379
  err = capsys.readouterr().err
1380
1380
  assert "invalid choice" not in err
1381
+
1382
+
1383
+ # ------------------------------------------------- install --dry-run (issue #41)
1384
+
1385
+
1386
+ def test_install_dry_run_parser_flag():
1387
+ p = cli.build_parser()
1388
+ args = p.parse_args(["install", "--dry-run"])
1389
+ assert args.command == "install" and args.dry_run is True
1390
+ assert p.parse_args(["install"]).dry_run is False
1391
+
1392
+
1393
+ def _install_ns(**kw):
1394
+ ns = dict(ntfy=None, window=None, dry_run=False)
1395
+ ns.update(kw)
1396
+ return argparse.Namespace(**ns)
1397
+
1398
+
1399
+ def test_cmd_install_dry_run_prints_plan_writes_nothing(tmp_path, monkeypatch,
1400
+ capsys):
1401
+ from cc_continuity import install
1402
+ home = tmp_path / "home"
1403
+ (home / ".local" / "bin").mkdir(parents=True)
1404
+ monkeypatch.setenv("HOME", str(home))
1405
+ monkeypatch.setenv("CC_CONTINUITY_HOME", str(home / ".claude-continuity"))
1406
+ monkeypatch.setattr(install, "check_prerequisites",
1407
+ lambda h, **kw: [])
1408
+ rc = cli.cmd_install(_install_ns(dry_run=True))
1409
+ out = capsys.readouterr().out
1410
+ assert rc == 0
1411
+ assert "dry run" in out
1412
+ assert "settings.json" in out and "CLAUDE.md" in out and ".zshrc" in out
1413
+ # the real run touches none of these in dry-run mode
1414
+ assert not (home / ".claude").exists()
1415
+ assert not (home / ".claude-continuity" / "app").exists()
1416
+ assert not (home / ".local" / "bin" / "cc-continuity").exists()
1417
+
1418
+
1419
+ def test_cmd_install_dry_run_nonzero_on_missing_prereqs(tmp_path, monkeypatch,
1420
+ capsys):
1421
+ from cc_continuity import install
1422
+ home = tmp_path / "home"
1423
+ home.mkdir()
1424
+ monkeypatch.setenv("HOME", str(home))
1425
+ monkeypatch.setenv("CC_CONTINUITY_HOME", str(home / ".cc"))
1426
+ monkeypatch.setattr(install, "check_prerequisites",
1427
+ lambda h, **kw: ["tmux on PATH"])
1428
+ rc = cli.cmd_install(_install_ns(dry_run=True))
1429
+ assert rc == 1
1430
+ assert "tmux" in capsys.readouterr().err
@@ -1,6 +1,7 @@
1
1
  """doctor.py: PRD §16 health checks on a fake HOME."""
2
2
 
3
3
  import dataclasses
4
+ import fcntl
4
5
  import json
5
6
  import os
6
7
  import time
@@ -194,17 +195,63 @@ def test_config_sanity_warns_on_bad_endpoint_scheme(fake_home):
194
195
  assert "notify_endpoint" in c.detail
195
196
 
196
197
 
197
- def test_stale_lock_warns(fake_home, cc_home):
198
- h = fake_home
199
- install.install(h, window=262144, runner=FakeRun())
198
+ def _seed_stale_lock(h, pid, ts):
200
199
  proj = h / ".claude-continuity" / "projects" / "p-1"
201
200
  (proj / "sessions").mkdir(parents=True)
202
- (proj / "lock").write_text(json.dumps(
203
- {"pid": 999999, "ts": time.time() - 600, "rotation_id": None}),
204
- encoding="utf-8")
201
+ lf = proj / "lock"
202
+ lf.write_text(json.dumps({"pid": pid, "ts": ts,
203
+ "rotation_id": None}), encoding="utf-8")
204
+ return lf
205
+
206
+
207
+ def test_stale_lock_removed(fake_home, cc_home):
208
+ # dead PID + old ts + kernel-released flock: doctor removes the
209
+ # leftover file (last-holder diagnostic of a dead run), like tmp-residue
210
+ h = fake_home
211
+ install.install(h, window=262144, runner=FakeRun())
212
+ lf = _seed_stale_lock(h, 999999, time.time() - 600)
205
213
  checks = doctor.run_doctor(h, runner=FakeRun(), which=_which_ok)
206
214
  c = next(x for x in checks if x.name == "stale-locks")
207
- assert c.warning
215
+ assert c.ok and c.warning and "removed" in c.detail
216
+ assert not lf.exists()
217
+
218
+
219
+ def test_stale_lock_held_warns_and_survives(fake_home, cc_home):
220
+ # dead PID + old ts but the flock is still held (inherited fd): the
221
+ # file must survive and the check must flag it - deletion would lie
222
+ h = fake_home
223
+ install.install(h, window=262144, runner=FakeRun())
224
+ lf = _seed_stale_lock(h, 999999, time.time() - 600)
225
+ fd = os.open(lf, os.O_RDWR)
226
+ try:
227
+ fcntl.flock(fd, fcntl.LOCK_EX)
228
+ checks = doctor.run_doctor(h, runner=FakeRun(), which=_which_ok)
229
+ finally:
230
+ fcntl.flock(fd, fcntl.LOCK_UN)
231
+ os.close(fd)
232
+ c = next(x for x in checks if x.name == "stale-locks")
233
+ assert c.warning and "held" in c.detail
234
+ assert lf.exists()
235
+
236
+
237
+ def test_live_lock_untouched(fake_home, cc_home):
238
+ h = fake_home
239
+ install.install(h, window=262144, runner=FakeRun())
240
+ lf = _seed_stale_lock(h, os.getpid(), time.time() - 600)
241
+ checks = doctor.run_doctor(h, runner=FakeRun(), which=_which_ok)
242
+ c = next(x for x in checks if x.name == "stale-locks")
243
+ assert c.ok and not c.warning and c.detail == "none"
244
+ assert lf.exists()
245
+
246
+
247
+ def test_fresh_dead_lock_untouched(fake_home, cc_home):
248
+ h = fake_home
249
+ install.install(h, window=262144, runner=FakeRun())
250
+ lf = _seed_stale_lock(h, 999999, time.time())
251
+ checks = doctor.run_doctor(h, runner=FakeRun(), which=_which_ok)
252
+ c = next(x for x in checks if x.name == "stale-locks")
253
+ assert c.ok and not c.warning and c.detail == "none"
254
+ assert lf.exists()
208
255
 
209
256
 
210
257
  def test_old_tmp_residue_deleted_and_warned(fake_home):
@@ -470,3 +470,108 @@ def test_migrate_leaves_others(fake_home):
470
470
  res = install.migrate_generic_hooks(plain, now="20261105-150000")
471
471
  assert res == {"backed_up": None, "replaced": 0}
472
472
  assert not list((plain / ".claude").glob("settings.json.bak-*"))
473
+
474
+
475
+ # ------------------------------------------------- dry-run plan (issue #41)
476
+
477
+
478
+ def _tree_bytes(home: Path) -> dict:
479
+ """path -> bytes for every file under home (write-nothing checks)."""
480
+ out = {}
481
+ for p in sorted(Path(home).rglob("*")):
482
+ if p.is_file():
483
+ out[str(p.relative_to(home))] = p.read_bytes()
484
+ return out
485
+
486
+
487
+ def _line_for(text: str, target: str) -> str:
488
+ return next(l for l in text.splitlines() if target in l)
489
+
490
+
491
+ def test_plan_install_fresh_home_lists_every_managed_file(fake_home):
492
+ text = "\n".join(install.plan_install(fake_home, window=262144,
493
+ runner=FakeRun()))
494
+ for target in (".claude-continuity/app/cc_continuity",
495
+ "app/bin/cc-continuity",
496
+ ".local/bin/cc-continuity",
497
+ ".claude/settings.json",
498
+ ".claude/CLAUDE.md",
499
+ ".claude/skills",
500
+ ".zshrc",
501
+ ".claude-continuity/config.json"):
502
+ assert target in text, target
503
+ assert "unchanged" not in text # fresh home: everything is new
504
+
505
+
506
+ def test_plan_install_writes_nothing(fake_home):
507
+ before = _tree_bytes(fake_home)
508
+ install.plan_install(fake_home, window=262144, runner=FakeRun())
509
+ assert _tree_bytes(fake_home) == before
510
+
511
+
512
+ def test_plan_install_fresh_home_reports_creates(fake_home):
513
+ text = "\n".join(install.plan_install(fake_home, window=262144,
514
+ runner=FakeRun()))
515
+ for target in (".claude/settings.json", ".claude/CLAUDE.md",
516
+ ".zshrc", ".claude-continuity/config.json"):
517
+ assert "create" in _line_for(text, target), target
518
+
519
+
520
+ def test_plan_install_after_real_install_reports_unchanged(fake_home):
521
+ install.install(fake_home, window=262144, runner=FakeRun())
522
+ text = "\n".join(install.plan_install(fake_home, window=262144,
523
+ runner=FakeRun()))
524
+ for target in (".claude/settings.json", ".claude/CLAUDE.md",
525
+ ".zshrc", ".claude/skills", ".local/bin/cc-continuity",
526
+ ".claude-continuity/config.json"):
527
+ assert "unchanged" in _line_for(text, target), target
528
+ assert "create" not in text and "update" not in text
529
+
530
+
531
+ def test_plan_install_lists_additions_on_merge(fake_home):
532
+ (fake_home / ".claude").mkdir()
533
+ (fake_home / ".claude" / "settings.json").write_text(
534
+ json.dumps({"statusLine": {"type": "command",
535
+ "command": "~/my-status.sh"},
536
+ "env": {"KEEP": "1"}}),
537
+ encoding="utf-8")
538
+ text = "\n".join(install.plan_install(fake_home, window=131072,
539
+ runner=FakeRun()))
540
+ assert "update" in _line_for(text, ".claude/settings.json")
541
+ assert "~/my-status.sh" in text # the user line gets chained
542
+ assert "CLAUDE_CODE_MAX_CONTEXT_TOKENS" in text
543
+ assert "131072" in text
544
+ assert "Bash(cc-continuity *)" in text # permission addition listed
545
+ assert "settings.json.bak-" in text # backup is part of the plan
546
+
547
+
548
+ def test_plan_install_missing_prereqs_raises(fake_home, monkeypatch):
549
+ monkeypatch.setattr(
550
+ install.shutil, "which",
551
+ lambda name: None if name == "tmux" else f"/usr/bin/{name}")
552
+ with pytest.raises(install.InstallError, match="tmux"):
553
+ install.plan_install(fake_home, runner=FakeRun())
554
+
555
+
556
+ def test_plan_install_corrupt_settings_raises(fake_home):
557
+ (fake_home / ".claude").mkdir()
558
+ (fake_home / ".claude" / "settings.json").write_text("{nope",
559
+ encoding="utf-8")
560
+ with pytest.raises(install.InstallError, match="settings.json"):
561
+ install.plan_install(fake_home, runner=FakeRun())
562
+
563
+
564
+ def test_plan_install_non_symlink_bin_raises(fake_home):
565
+ (fake_home / ".local" / "bin" / "cc-continuity").write_text(
566
+ "x", encoding="utf-8")
567
+ with pytest.raises(install.InstallError, match="non-symlink"):
568
+ install.plan_install(fake_home, runner=FakeRun())
569
+
570
+
571
+ def test_plan_install_refuses_app_dir(fake_home, monkeypatch):
572
+ # same self-destruct guard as copy_app: planning from the app dir aborts
573
+ app_pkg = fake_home / ".claude-continuity" / "app" / "cc_continuity"
574
+ app_pkg.mkdir(parents=True)
575
+ monkeypatch.setattr(install, "__file__", str(app_pkg / "install.py"))
576
+ with pytest.raises(install.InstallError, match="app dir"):
577
+ install.plan_install(fake_home, runner=FakeRun())
File without changes
File without changes