cc-continuity 0.3.2__tar.gz → 0.3.4__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 (111) hide show
  1. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/PKG-INFO +1 -1
  2. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/README.md +13 -7
  3. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/__init__.py +1 -1
  4. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/hooks/pre_tool_use.py +30 -9
  5. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/hooks/stop.py +16 -12
  6. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/thresholds.py +24 -0
  7. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity.egg-info/PKG-INFO +1 -1
  8. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/pyproject.toml +1 -1
  9. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_hooks_pre_tool_use.py +72 -7
  10. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_hooks_stop.py +41 -1
  11. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_integration_phase5.py +11 -5
  12. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/LICENSE +0 -0
  13. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/__main__.py +0 -0
  14. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/atomic.py +0 -0
  15. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/blink.py +0 -0
  16. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/blink_watch.py +0 -0
  17. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/bootstrap.py +0 -0
  18. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/checkpoint.py +0 -0
  19. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/cli.py +0 -0
  20. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/config.py +0 -0
  21. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/daemon_supervisor.py +0 -0
  22. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/doctor.py +0 -0
  23. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/gitsnap.py +0 -0
  24. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/hooks/__init__.py +0 -0
  25. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/hooks/common.py +0 -0
  26. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/hooks/pre_compact.py +0 -0
  27. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/hooks/session_end.py +0 -0
  28. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/hooks/session_start.py +0 -0
  29. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/hooks/task.py +0 -0
  30. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/hooks/tool_use.py +0 -0
  31. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/hooks/user_prompt.py +0 -0
  32. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/hosting.py +0 -0
  33. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/install.py +0 -0
  34. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/launch.py +0 -0
  35. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/ledger.py +0 -0
  36. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/lock.py +0 -0
  37. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/managed.py +0 -0
  38. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/naming.py +0 -0
  39. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/notify.py +0 -0
  40. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/paths.py +0 -0
  41. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/power_plug.py +0 -0
  42. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/progress_pane.py +0 -0
  43. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/project.py +0 -0
  44. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/redact.py +0 -0
  45. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/rotator.py +0 -0
  46. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/settings_merge.py +0 -0
  47. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/skills.py +0 -0
  48. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/state.py +0 -0
  49. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/statusline.py +0 -0
  50. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/transcript.py +0 -0
  51. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/validate.py +0 -0
  52. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/watchdog.py +0 -0
  53. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/watchdog_digest.py +0 -0
  54. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity/watchdogd.py +0 -0
  55. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity.egg-info/SOURCES.txt +0 -0
  56. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity.egg-info/dependency_links.txt +0 -0
  57. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity.egg-info/entry_points.txt +0 -0
  58. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/cc_continuity.egg-info/top_level.txt +0 -0
  59. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/setup.cfg +0 -0
  60. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_atomic.py +0 -0
  61. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_blink.py +0 -0
  62. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_blink_watch.py +0 -0
  63. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_bootstrap.py +0 -0
  64. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_checkpoint.py +0 -0
  65. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_cli.py +0 -0
  66. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_config.py +0 -0
  67. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_daemon_supervisor.py +0 -0
  68. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_doctor.py +0 -0
  69. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_gitsnap.py +0 -0
  70. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_hooks_common.py +0 -0
  71. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_hooks_pre_compact.py +0 -0
  72. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_hooks_session_end.py +0 -0
  73. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_hooks_session_start.py +0 -0
  74. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_hooks_task.py +0 -0
  75. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_hooks_tool_use.py +0 -0
  76. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_hooks_user_prompt.py +0 -0
  77. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_hosting.py +0 -0
  78. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_hygiene.py +0 -0
  79. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_install.py +0 -0
  80. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_integration_phase6.py +0 -0
  81. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_integration_phase7.py +0 -0
  82. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_launch.py +0 -0
  83. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_ledger.py +0 -0
  84. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_lock.py +0 -0
  85. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_managed.py +0 -0
  86. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_naming.py +0 -0
  87. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_notify.py +0 -0
  88. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_notify_integration.py +0 -0
  89. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_paths.py +0 -0
  90. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_power_plug.py +0 -0
  91. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_progress_pane.py +0 -0
  92. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_project.py +0 -0
  93. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_redact.py +0 -0
  94. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_rotator.py +0 -0
  95. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_settings_merge.py +0 -0
  96. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_skills.py +0 -0
  97. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_state.py +0 -0
  98. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_status.py +0 -0
  99. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_statusline.py +0 -0
  100. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_thresholds.py +0 -0
  101. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_tmux_host.py +0 -0
  102. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_transcript.py +0 -0
  103. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_transcript_finalize.py +0 -0
  104. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_uninstall.py +0 -0
  105. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_validate.py +0 -0
  106. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_watchdog.py +0 -0
  107. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_watchdog_digest.py +0 -0
  108. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_watchdog_integration.py +0 -0
  109. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_watchdogd.py +0 -0
  110. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/tests/test_wsl_doctor.py +0 -0
  111. {cc_continuity-0.3.2 → cc_continuity-0.3.4}/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.2
3
+ Version: 0.3.4
4
4
  Summary: Zero-touch session rotation for Claude Code (local large-context model)
5
5
  Requires-Python: >=3.11
6
6
  License-File: LICENSE
@@ -26,6 +26,19 @@ The five most recent updates, newest first. Each line links to its
26
26
  commit, so you can see what changed lately without digging through the
27
27
  log:
28
28
 
29
+ - **2026-11-09**: The turn-end rotation gate no longer blocks a routine
30
+ rotation when the handoff draft is already valid: the rotation now
31
+ finishes silently, so the built-in "Stop hook error" line only appears
32
+ when the model genuinely fails to produce a draft after being told
33
+ ([commit](https://github.com/pqant/claude-continuity/commit/2c9d2bf)).
34
+ - **2026-11-09**: Routine rotations no longer print a red error: at the
35
+ hard context limit the in-flight tool call now passes and the handoff
36
+ instruction arrives as a neutral notice, so the pane stays clean
37
+ ([commit](https://github.com/pqant/claude-continuity/commit/d8e015c)).
38
+ - **2026-11-09**: When the gate does deny a tool (only after the model
39
+ was told to write the handoff and kept working), the full guidance
40
+ shows as an informational message instead of a red error line
41
+ ([commit](https://github.com/pqant/claude-continuity/commit/f8a6cc9)).
29
42
  - **2026-11-09**: Exported transcript pages now carry a session
30
43
  switcher: a header dropdown lists the newest exports of the project
31
44
  (the top ten plus the current page) and loads them over plain
@@ -39,13 +52,6 @@ log:
39
52
  (modules, dependencies and data flows) now ships in `docs/diagrams` as a
40
53
  self-contained HTML page with guided views and export
41
54
  ([commit](https://github.com/pqant/claude-continuity/commit/5ae9011)).
42
- - **2026-11-08**: The waiting tab blink now starts after a 5 s settle
43
- window instead of 15 s, so a finished turn reaches your tab faster
44
- ([commit](https://github.com/pqant/claude-continuity/commit/a9a295d)).
45
- - **2026-11-08**: Progress frames are padded by rendered cells, so wide
46
- glyphs never wrap into the next line
47
- ([commit](https://github.com/pqant/claude-continuity/commit/581fe93)).
48
-
49
55
  ## How it works
50
56
 
51
57
  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.2"
7
+ __version__ = "0.3.4"
@@ -1,8 +1,10 @@
1
1
  """PreToolUse hook (PRD §9) — the hard ceiling (Phase 5).
2
2
 
3
3
  Ratio gate: fresh ratio >= hard_ratio with a pre-handoff state ->
4
- ``advance`` to HANDOFF_REQUESTED first, then the deny decision. State gate
5
- (no metric needed): HANDOFF_REQUESTED/HANDOFF_FAILED deny with C.3;
4
+ ``advance`` to HANDOFF_REQUESTED, let the in-flight call through and inject
5
+ the C.2 handoff instruction as neutral additionalContext (issue #25: CC
6
+ renders denials as red Errors; routine rotation is not an error). State
7
+ gate (no metric needed): HANDOFF_REQUESTED/HANDOFF_FAILED deny with C.3;
6
8
  CHECKPOINT_WRITING/VERIFIED/ROTATING (handoff accepted) deny with C.9, so
7
9
  the model cannot keep working and make the handoff stale. AWAITING_MANUAL_
8
10
  CLEAR / ROTATED allow (checkpoint final, user in control). The allowlist
@@ -38,21 +40,40 @@ def handle(ctx: HookContext) -> dict | None:
38
40
  if s in PRE_HANDOFF:
39
41
  ratio = thresholds.read_ratio(ctx)
40
42
  if ratio is not None and ratio >= cfg["hard_ratio"]:
41
- rec, _ = thresholds.advance(key, nnn, "HANDOFF_REQUESTED",
42
- ratio=ratio, cfg=cfg)
43
- s = rec["state"]
43
+ thresholds.advance(key, nnn, "HANDOFF_REQUESTED", ratio=ratio,
44
+ cfg=cfg)
45
+ # Guidance-first (issue #25): this call was queued before the
46
+ # model could learn rotation started, and CC renders any denial
47
+ # as a red "Error:" line - routine rotation is not an error.
48
+ # Let the in-flight call through and inject the C.2 instruction
49
+ # as neutral context instead; denial is reserved for calls the
50
+ # model makes AFTER seeing the guidance.
51
+ return {"systemMessage": thresholds.c2_note(ratio),
52
+ "hookSpecificOutput": {
53
+ "hookEventName": "PreToolUse",
54
+ "additionalContext": thresholds.c2_text(
55
+ ratio, draft_path,
56
+ blocked=ledger.blocked_reason(ctx.session_dir)),
57
+ }}
44
58
  if s in DENY_C3:
45
- reason = thresholds.c3_text(ratio, cfg["hard_ratio"], draft_path,
46
- blocked=ledger.blocked_reason(ctx.session_dir))
59
+ blocked = ledger.blocked_reason(ctx.session_dir)
60
+ guidance = thresholds.c3_text(ratio, cfg["hard_ratio"], draft_path,
61
+ blocked=blocked)
62
+ reason = thresholds.c3_brief(ratio, cfg["hard_ratio"], draft_path,
63
+ blocked=blocked)
47
64
  elif s in DENY_C9:
48
- reason = thresholds.c9_text()
65
+ guidance = thresholds.c9_text()
66
+ reason = thresholds.c9_brief()
49
67
  else:
50
68
  return None
51
69
  tool = ctx.payload.get("tool_name")
52
70
  tool_input = _dict(ctx.payload.get("tool_input"))
53
71
  if thresholds.is_allowed_tool(tool, tool_input, draft_path):
54
72
  return None
55
- return {"hookSpecificOutput": {
73
+ # The full gate guidance rides in systemMessage so the UI shows an
74
+ # informational note, not a red error; the model still acts on the
75
+ # brief deny reason.
76
+ return {"systemMessage": guidance, "hookSpecificOutput": {
56
77
  "hookEventName": "PreToolUse",
57
78
  "permissionDecision": "deny",
58
79
  "permissionDecisionReason": reason,
@@ -1,10 +1,13 @@
1
1
  """Stop hook (PRD §9) — turn-end enforcement (Phase 5, spec §6.4).
2
2
 
3
3
  State-based (never ratio-based): ROTATION_PENDING -> advance to
4
- HANDOFF_REQUESTED + attempt/block; HANDOFF_REQUESTED -> validate the
4
+ HANDOFF_REQUESTED and fall through; HANDOFF_REQUESTED -> validate the
5
5
  draft file DIRECTLY (a Bash-written draft was never seen by
6
- PostToolUse) -> finalize or attempt/block; 3 accumulated failed
7
- attempts -> degrade (HANDOFF_FAILED -> deterministic checkpoint, C.7);
6
+ PostToolUse) -> finalize (SILENTLY when valid, issue #26 - a block
7
+ would render as a hardcoded red "Stop hook error:" line) or
8
+ attempt/block (missing/invalid draft = genuine violation);
9
+ 3 accumulated failed attempts -> degrade (HANDOFF_FAILED ->
10
+ deterministic checkpoint, C.7);
8
11
  CHECKPOINT_WRITING -> finalize; CHECKPOINT_VERIFIED -> AMCL without
9
12
  re-running finalize; everything else: ``turn_active=False`` +
10
13
  ``last_stop_ts`` only. After a verified checkpoint the session rotates
@@ -163,16 +166,17 @@ def handle(ctx: HookContext) -> dict | None:
163
166
  s = rec["state"]
164
167
  tool_calls = rec.get("tool_calls", 0)
165
168
  if s == "ROTATION_PENDING":
169
+ # Issue #26: C.2 already reached the model as PostToolUse
170
+ # additionalContext at the crossing (guide-first). The old blind
171
+ # block re-sent the full instruction even when the draft was
172
+ # already written - and every Stop block renders as a red
173
+ # "Stop hook error:" line (prefix hardcoded in the CC binary),
174
+ # so a routine rotation showed "Error" for no effect. Advance
175
+ # and fall through to the shared HR validation below: it blocks
176
+ # only on a missing/invalid draft (a genuine violation after
177
+ # guidance) and rotates silently when the draft is valid.
166
178
  rec, _ = thresholds.advance(key, nnn, "HANDOFF_REQUESTED", cfg=cfg)
167
- attempts = state.update_fields(key, nnn,
168
- handoff_attempts=rec.get("handoff_attempts", 0) + 1,
169
- ctx_emitted_at=tool_calls)["handoff_attempts"]
170
- if attempts >= 3:
171
- return _degrade(ctx, key, nnn)
172
- return {"decision": "block",
173
- "reason": thresholds.c2_text(thresholds.display_ratio(ctx, cfg),
174
- draft_path,
175
- blocked=ledger.blocked_reason(sdir))}
179
+ s = "HANDOFF_REQUESTED"
176
180
  if s == "HANDOFF_REQUESTED":
177
181
  draft = sdir / "handoff.draft.md"
178
182
  report = None
@@ -103,6 +103,14 @@ def c2_text(ratio: float, draft_path: str,
103
103
  "turn." + _blocked_suffix(blocked))
104
104
 
105
105
 
106
+ def c2_note(ratio: float) -> str:
107
+ """User-facing neutral note for a hard-ratio crossing (issue #25):
108
+ informational only - routine rotation is never rendered as an error."""
109
+ return (f"cc-continuity: context at {pct_of(ratio)}% - rotation handoff "
110
+ "requested. The model finishes the current step, writes the "
111
+ "handoff, and ends its turn.")
112
+
113
+
106
114
  def c3_text(ratio: float | None, hard_ratio: float, draft_path: str,
107
115
  blocked: str | None = None) -> str:
108
116
  shown = ratio if ratio is not None else hard_ratio
@@ -114,6 +122,17 @@ def c3_text(ratio: float | None, hard_ratio: float, draft_path: str,
114
122
  + _blocked_suffix(blocked))
115
123
 
116
124
 
125
+ def c3_brief(ratio: float | None, hard_ratio: float, draft_path: str,
126
+ blocked: str | None = None) -> str:
127
+ """Model-facing short reason for the C.3 deny (full guidance travels
128
+ in the hook's systemMessage, not the red deny reason)."""
129
+ shown = ratio if ratio is not None else hard_ratio
130
+ return (f"CONTINUITY: context at {pct_of(shown)}% (hard limit). Write the "
131
+ f"handoff to {draft_path} with the required level-2 headings "
132
+ f"(format '## Heading'), then end your turn."
133
+ + _blocked_suffix(blocked))
134
+
135
+
117
136
  def c6_text(problems: list, draft_path: str) -> str:
118
137
  return ("CONTINUITY: handoff draft invalid: " + "; ".join(problems)
119
138
  + f". Fix {draft_path} and end your turn.")
@@ -126,6 +145,11 @@ def c9_text() -> str:
126
145
  "this session. End your turn now.")
127
146
 
128
147
 
148
+ def c9_brief() -> str:
149
+ """Model-facing short reason for the C.9 deny (full text in systemMessage)."""
150
+ return "CONTINUITY: handoff accepted. End your turn now."
151
+
152
+
129
153
  # -------------------------------------------------------------- state walk
130
154
 
131
155
  #: Path to ROTATION_PENDING, by current state (each step is
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cc-continuity
3
- Version: 0.3.2
3
+ Version: 0.3.4
4
4
  Summary: Zero-touch session rotation for Claude Code (local large-context model)
5
5
  Requires-Python: >=3.11
6
6
  License-File: LICENSE
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cc-continuity"
7
- version = "0.3.2"
7
+ version = "0.3.4"
8
8
  description = "Zero-touch session rotation for Claude Code (local large-context model)"
9
9
  requires-python = ">=3.11"
10
10
  dependencies = [] # stdlib only at runtime (PRD §0.5)
@@ -1,9 +1,12 @@
1
1
  """hooks/pre_tool_use.py: hard ceiling (PRD §9, spec §6.3).
2
2
 
3
3
  Ratio gate: ratio >= hard with a pre-handoff state -> walk to
4
- HANDOFF_REQUESTED, then deny. State gate: pre-checkpoint states deny C.3,
5
- handoff-accepted states deny C.9, always with the same allowlist. Silent
6
- allow otherwise.
4
+ HANDOFF_REQUESTED, let the in-flight call through and inject the C.2
5
+ handoff instruction as neutral additionalContext (CC renders denials as
6
+ red "Error:" lines; routine rotation is not an error - issue #25).
7
+ State gate: handoff-requested states deny C.3 (only after the model saw
8
+ the guidance), handoff-accepted states deny C.9, always with the same
9
+ allowlist. Silent allow otherwise.
7
10
  """
8
11
 
9
12
  import pytest
@@ -33,6 +36,10 @@ def _reason(out):
33
36
  return out["hookSpecificOutput"]["permissionDecisionReason"]
34
37
 
35
38
 
39
+ def _system(out):
40
+ return out.get("systemMessage", "")
41
+
42
+
36
43
  def test_below_hard_allows_silently(cc_home, capsys, tmp_path):
37
44
  repo, key, nnn = _setup(cc_home, tmp_path, s="ACTIVE", ratio=0.60)
38
45
  _pretool(repo, "Bash", {"command": "rm -rf x"})
@@ -40,20 +47,78 @@ def test_below_hard_allows_silently(cc_home, capsys, tmp_path):
40
47
  assert state.load_state(key, nnn)["state"] == "ACTIVE"
41
48
 
42
49
 
43
- def test_hard_ratio_walks_to_handoff_and_denies(cc_home, capsys, tmp_path):
50
+ def test_hard_ratio_crossing_guides_without_denying(cc_home, capsys, tmp_path):
51
+ # Routine crossing (issue #25): CC renders denials as red "Error:"
52
+ # lines, but rotation is routine - the in-flight call passes and the
53
+ # handoff instruction arrives as neutral additionalContext.
44
54
  repo, key, nnn = _setup(cc_home, tmp_path, s="ROTATION_PENDING", ratio=0.73)
45
55
  _pretool(repo, "Bash", {"command": "rm -rf x"})
46
56
  out = stdout_json(capsys)
47
57
  assert out["hookSpecificOutput"]["hookEventName"] == "PreToolUse"
48
- assert out["hookSpecificOutput"]["permissionDecision"] == "deny"
49
- assert "hard limit" in _reason(out)
58
+ assert "permissionDecision" not in out["hookSpecificOutput"]
59
+ assert "Rotation pending" in out["hookSpecificOutput"]["additionalContext"]
60
+ assert "handoff.draft.md" in out["hookSpecificOutput"]["additionalContext"]
61
+ assert "cc-continuity" in _system(out)
50
62
  assert state.load_state(key, nnn)["state"] == "HANDOFF_REQUESTED"
51
63
 
52
64
 
65
+ def test_second_work_tool_after_crossing_denies(cc_home, capsys, tmp_path):
66
+ # Only AFTER the model saw the guidance may a work tool be denied.
67
+ repo, key, nnn = _setup(cc_home, tmp_path, s="ROTATION_PENDING", ratio=0.73)
68
+ _pretool(repo, "Bash", {"command": "rm -rf x"}) # crossing: allow + guide
69
+ stdout_json(capsys)
70
+ _pretool(repo, "Bash", {"command": "pytest"})
71
+ out = stdout_json(capsys)
72
+ assert out["hookSpecificOutput"]["permissionDecision"] == "deny"
73
+ assert "hard limit" in _system(out)
74
+
75
+
76
+ def test_handoff_requested_deny_routes_guidance_to_system_message(cc_home,
77
+ capsys,
78
+ tmp_path):
79
+ # A post-guidance denial renders its full guidance as an informational
80
+ # systemMessage, not only as the red error in the deny reason.
81
+ repo, key, nnn = _setup(cc_home, tmp_path, s="HANDOFF_REQUESTED")
82
+ _pretool(repo, "Bash", {"command": "rm -rf x"})
83
+ out = stdout_json(capsys)
84
+ assert "hard limit" in _system(out)
85
+ assert "Allowed now" in _system(out)
86
+
87
+
88
+ def test_handoff_requested_deny_reason_omits_allowed_tools_guidance(cc_home,
89
+ capsys,
90
+ tmp_path):
91
+ repo, key, nnn = _setup(cc_home, tmp_path, s="HANDOFF_REQUESTED")
92
+ _pretool(repo, "Bash", {"command": "rm -rf x"})
93
+ out = stdout_json(capsys)
94
+ assert "Allowed now" not in _reason(out)
95
+ assert "handoff.draft.md" in _reason(out)
96
+ assert "end your turn" in _reason(out)
97
+
98
+
99
+ def test_handoff_accepted_deny_routes_guidance_to_system_message(cc_home,
100
+ capsys,
101
+ tmp_path):
102
+ repo, key, nnn = _setup(cc_home, tmp_path, s="CHECKPOINT_WRITING")
103
+ _pretool(repo, "Bash", {"command": "pytest"})
104
+ out = stdout_json(capsys)
105
+ assert "Do not start any more work" in _system(out)
106
+
107
+
108
+ def test_handoff_accepted_deny_reason_is_brief(cc_home, capsys, tmp_path):
109
+ repo, key, nnn = _setup(cc_home, tmp_path, s="CHECKPOINT_WRITING")
110
+ _pretool(repo, "Bash", {"command": "pytest"})
111
+ out = stdout_json(capsys)
112
+ assert "handoff accepted" in _reason(out)
113
+ assert "Do not start any more work" not in _reason(out)
114
+
115
+
53
116
  def test_hard_ratio_walks_even_when_tool_allowed(cc_home, capsys, tmp_path):
54
117
  repo, key, nnn = _setup(cc_home, tmp_path, s="ACTIVE", ratio=0.75)
55
118
  _pretool(repo, "Read", {"file_path": "/x"})
56
- assert stdout_json(capsys) is None # Read passes the allowlist
119
+ # The allowlisted call also receives the crossing guidance.
120
+ out = stdout_json(capsys)
121
+ assert "Rotation pending" in out["hookSpecificOutput"]["additionalContext"]
57
122
  assert state.load_state(key, nnn)["state"] == "HANDOFF_REQUESTED"
58
123
 
59
124
 
@@ -1,6 +1,9 @@
1
1
  """hooks/stop.py: turn-end enforcement (PRD §9, spec §6.4).
2
2
 
3
- Attempt ladder: RP -> HR + block C.2; HR without a valid draft -> block
3
+ Attempt ladder (issue #26 unified): RP advances to HR, then both states
4
+ validate the draft directly - a valid draft finalizes and rotates
5
+ SILENTLY (no block: any Stop block renders as a red "Stop hook error:"
6
+ line, which CC hardcodes); a missing/invalid draft blocks
4
7
  (C.6 when the draft exists and is invalid, else C.2); 3 accumulated
5
8
  failed attempts -> degraded checkpoint (C.7), NO block, systemMessage.
6
9
  A valid draft (even one Stop itself discovers, e.g. Bash-written) ->
@@ -141,6 +144,43 @@ def test_handoff_requested_valid_draft_finalizes(cc_home, capsys, tmp_path):
141
144
  assert "## Next Atomic Action" in (cp / "handoff.md").read_text()
142
145
 
143
146
 
147
+ def test_rotation_pending_valid_draft_finalizes_without_block(cc_home,
148
+ capsys,
149
+ tmp_path):
150
+ # issue #26: a routine rotation where the draft is already valid must
151
+ # rotate silently - any Stop block renders as a red "Stop hook error:"
152
+ # line (prefix hardcoded in CC 2.1.209), which must never appear for a
153
+ # valid routine case.
154
+ repo, key, nnn = _setup(cc_home, tmp_path, s="ROTATION_PENDING")
155
+ (paths.session_dir(key, nnn) / "handoff.draft.md").write_text(
156
+ _valid_draft(), encoding="utf-8")
157
+ run_hook("Stop", payload("Stop", repo))
158
+ out = stdout_json(capsys)
159
+ assert "decision" not in out # NO block
160
+ assert out == {"systemMessage": AMCL}
161
+ rec = state.load_state(key, nnn)
162
+ assert rec["state"] == "AWAITING_MANUAL_CLEAR"
163
+ assert rec["degraded"] is False
164
+ assert rec.get("handoff_attempts", 0) == 0 # silent success is not an attempt
165
+ cp = paths.session_dir(key, nnn) / "checkpoint"
166
+ assert (cp / "handoff.md").is_file()
167
+
168
+
169
+ def test_rotation_pending_invalid_draft_blocks_c6(cc_home, capsys, tmp_path):
170
+ # enforcement stays reserved for genuine violations: after guidance,
171
+ # an invalid draft still blocks (the red line is justified there).
172
+ repo, key, nnn = _setup(cc_home, tmp_path, s="ROTATION_PENDING")
173
+ (paths.session_dir(key, nnn) / "handoff.draft.md").write_text(
174
+ "## Objective\nshort\n", encoding="utf-8")
175
+ run_hook("Stop", payload("Stop", repo))
176
+ out = stdout_json(capsys)
177
+ assert out["decision"] == "block"
178
+ assert "handoff draft invalid" in out["reason"]
179
+ rec = state.load_state(key, nnn)
180
+ assert rec["state"] == "HANDOFF_REQUESTED"
181
+ assert rec["handoff_attempts"] == 1
182
+
183
+
144
184
  def test_checkpoint_writing_finalizes(cc_home, capsys, tmp_path):
145
185
  repo, key, nnn = _setup(cc_home, tmp_path, s="CHECKPOINT_WRITING")
146
186
  run_hook("Stop", payload("Stop", repo))
@@ -1,7 +1,7 @@
1
1
  """Phase 5 end-to-end chain without a model (spec §8/§9): warn ->
2
- pending -> hard (PreToolUse ceiling) -> deny -> draft -> C.9 -> Stop ->
3
- finalized checkpoint -> AMCL. Locks the cross-hook sequence; a failure
4
- here is an integration regression (all parts land in Tasks 4-9)."""
2
+ pending -> hard (PreToolUse ceiling) -> guide -> deny -> draft -> C.9 ->
3
+ Stop -> finalized checkpoint -> AMCL. Locks the cross-hook sequence; a
4
+ failure here is an integration regression (all parts land in Tasks 4-9)."""
5
5
 
6
6
  from cc_continuity import config, ledger, paths, state, validate
7
7
  from cc_continuity.hooks import stop
@@ -67,10 +67,16 @@ def test_full_threshold_to_checkpoint_chain(cc_home, capsys, tmp_path,
67
67
 
68
68
  set_metric(0.73) # >= hard_ratio 0.72
69
69
  out = pretool("Bash", {"command": "rm -rf /tmp/whatever"})
70
- # The PreToolUse ratio gate (spec 6.3) walks RP -> HR, then denies.
70
+ # Guidance-first (issue #25): the PreToolUse ratio gate (spec 6.3)
71
+ # walks RP -> HR, lets the in-flight call through and injects C.2 as
72
+ # neutral context - no red "Error:" denial for a routine crossing.
73
+ assert "permissionDecision" not in out["hookSpecificOutput"]
74
+ assert "Rotation pending" in out["hookSpecificOutput"]["additionalContext"]
75
+ assert state.load_state(key, nnn)["state"] == "HANDOFF_REQUESTED"
76
+ # Only AFTER the guidance may a work call be denied.
77
+ out = pretool("Bash", {"command": "echo more"})
71
78
  assert out["hookSpecificOutput"]["permissionDecision"] == "deny"
72
79
  assert "hard limit" in out["hookSpecificOutput"]["permissionDecisionReason"]
73
- assert state.load_state(key, nnn)["state"] == "HANDOFF_REQUESTED"
74
80
  assert pretool("Read", {"file_path": "/x"}) is None # allowlist passes
75
81
 
76
82
  draft.write_text(_draft_text(), encoding="utf-8")
File without changes
File without changes