cc-continuity 0.3.8__tar.gz → 0.3.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/PKG-INFO +1 -1
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/README.md +10 -9
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/__init__.py +1 -1
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/hooks/pre_tool_use.py +9 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/hooks/stop.py +8 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/install.py +4 -2
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/ledger.py +21 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/settings_merge.py +10 -1
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity.egg-info/PKG-INFO +1 -1
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/pyproject.toml +1 -1
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_doctor.py +7 -1
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_hooks_pre_tool_use.py +51 -1
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_hooks_stop.py +36 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_install.py +36 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_ledger.py +28 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_settings_merge.py +36 -2
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/LICENSE +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/__main__.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/atomic.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/blink.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/blink_watch.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/bootstrap.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/checkpoint.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/cli.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/config.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/daemon_supervisor.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/doctor.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/gitsnap.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/hooks/__init__.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/hooks/common.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/hooks/pre_compact.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/hooks/session_end.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/hooks/session_start.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/hooks/task.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/hooks/tool_use.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/hooks/user_prompt.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/hosting.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/launch.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/lock.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/managed.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/naming.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/notify.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/paths.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/power_plug.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/progress_pane.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/project.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/redact.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/rotator.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/skills.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/state.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/statusline.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/thresholds.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/transcript.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/validate.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/watchdog.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/watchdog_digest.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity/watchdogd.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity.egg-info/SOURCES.txt +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity.egg-info/dependency_links.txt +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity.egg-info/entry_points.txt +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/cc_continuity.egg-info/top_level.txt +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/setup.cfg +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_atomic.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_blink.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_blink_watch.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_bootstrap.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_checkpoint.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_cli.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_config.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_daemon_supervisor.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_gitsnap.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_hooks_common.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_hooks_pre_compact.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_hooks_session_end.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_hooks_session_start.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_hooks_task.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_hooks_tool_use.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_hooks_user_prompt.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_hosting.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_hygiene.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_integration_phase5.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_integration_phase6.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_integration_phase7.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_launch.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_lock.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_managed.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_naming.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_notify.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_notify_integration.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_paths.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_power_plug.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_progress_pane.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_project.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_redact.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_rotator.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_skills.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_state.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_status.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_statusline.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_thresholds.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_tmux_host.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_transcript.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_transcript_finalize.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_uninstall.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_validate.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_watchdog.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_watchdog_digest.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_watchdog_integration.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_watchdogd.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_wsl_doctor.py +0 -0
- {cc_continuity-0.3.8 → cc_continuity-0.3.10}/tests/test_wsl_install.py +0 -0
|
@@ -26,6 +26,16 @@ 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-10**: Rotation gate decisions (guide/deny/block/silent) now
|
|
30
|
+
land in the session ledger with their ratio and C-text variant, so a
|
|
31
|
+
strange rotation is debugged from disk instead of reverse-engineering
|
|
32
|
+
the renderer
|
|
33
|
+
([commit](https://github.com/pqant/claude-continuity/commit/5392666)).
|
|
34
|
+
- **2026-11-10**: `cc-continuity install` now pins
|
|
35
|
+
`CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=95` next to the context-window pin, so
|
|
36
|
+
a fresh install always starts the rotation gate ahead of native
|
|
37
|
+
auto-compact (a user-set value is never overwritten)
|
|
38
|
+
([commit](https://github.com/pqant/claude-continuity/commit/708237d)).
|
|
29
39
|
- **2026-11-10**: `cc-continuity signal --dry-run` now prints the exact
|
|
30
40
|
push (title, priority, body, enabled state) without sending it -
|
|
31
41
|
formatting checks are silent now
|
|
@@ -38,15 +48,6 @@ log:
|
|
|
38
48
|
context ratio of a project on one line - the manual metric-file read
|
|
39
49
|
in trial bookkeeping is gone
|
|
40
50
|
([commit](https://github.com/pqant/claude-continuity/commit/c0e6cdc)).
|
|
41
|
-
- **2026-11-10**: `cc-continuity doctor` now verifies the rotation
|
|
42
|
-
prerequisites in `settings.json` (auto-compact override + context
|
|
43
|
-
window pin) and flags drift with the exact recommended values
|
|
44
|
-
([commit](https://github.com/pqant/claude-continuity/commit/9462064)).
|
|
45
|
-
- **2026-11-09**: The turn-end rotation gate no longer blocks a routine
|
|
46
|
-
rotation when the handoff draft is already valid: the rotation now
|
|
47
|
-
finishes silently, so the built-in "Stop hook error" line only appears
|
|
48
|
-
when the model genuinely fails to produce a draft after being told
|
|
49
|
-
([commit](https://github.com/pqant/claude-continuity/commit/2c9d2bf)).
|
|
50
51
|
## How it works
|
|
51
52
|
|
|
52
53
|
The whole flow in one picture: the automatic session loop, the optional
|
|
@@ -48,6 +48,9 @@ def handle(ctx: HookContext) -> dict | None:
|
|
|
48
48
|
# Let the in-flight call through and inject the C.2 instruction
|
|
49
49
|
# as neutral context instead; denial is reserved for calls the
|
|
50
50
|
# model makes AFTER seeing the guidance.
|
|
51
|
+
ledger.gate(ctx.session_dir, action="guide", state_from=s,
|
|
52
|
+
state_to="HANDOFF_REQUESTED", ratio=ratio,
|
|
53
|
+
variant="c2")
|
|
51
54
|
return {"systemMessage": thresholds.c2_note(ratio),
|
|
52
55
|
"hookSpecificOutput": {
|
|
53
56
|
"hookEventName": "PreToolUse",
|
|
@@ -61,15 +64,21 @@ def handle(ctx: HookContext) -> dict | None:
|
|
|
61
64
|
blocked=blocked)
|
|
62
65
|
reason = thresholds.c3_brief(ratio, cfg["hard_ratio"], draft_path,
|
|
63
66
|
blocked=blocked)
|
|
67
|
+
variant = "c3"
|
|
64
68
|
elif s in DENY_C9:
|
|
65
69
|
guidance = thresholds.c9_text()
|
|
66
70
|
reason = thresholds.c9_brief()
|
|
71
|
+
variant = "c9"
|
|
67
72
|
else:
|
|
68
73
|
return None
|
|
69
74
|
tool = ctx.payload.get("tool_name")
|
|
70
75
|
tool_input = _dict(ctx.payload.get("tool_input"))
|
|
71
76
|
if thresholds.is_allowed_tool(tool, tool_input, draft_path):
|
|
72
77
|
return None
|
|
78
|
+
# Only REAL denials are gate decisions (allowlisted calls pass
|
|
79
|
+
# silently); the record exists for post-hoc rotation debugging (#39).
|
|
80
|
+
ledger.gate(ctx.session_dir, action="deny", state_from=s, state_to=s,
|
|
81
|
+
ratio=ratio, variant=variant, tool=str(tool))
|
|
73
82
|
# The full gate guidance rides in systemMessage so the UI shows an
|
|
74
83
|
# informational note, not a red error; the model still acts on the
|
|
75
84
|
# brief deny reason.
|
|
@@ -184,6 +184,10 @@ def handle(ctx: HookContext) -> dict | None:
|
|
|
184
184
|
report = checkpoint.validate_draft(draft.read_text(encoding="utf-8"),
|
|
185
185
|
cfg)
|
|
186
186
|
if report is not None and report.ok:
|
|
187
|
+
# Decision recorded for post-hoc rotation debugging (#39):
|
|
188
|
+
# valid draft -> silent finalize + rotate, no Stop block.
|
|
189
|
+
ledger.gate(sdir, action="silent", state_from="HANDOFF_REQUESTED",
|
|
190
|
+
state_to="CHECKPOINT_VERIFIED")
|
|
187
191
|
state.transition(key, nnn, "CHECKPOINT_WRITING")
|
|
188
192
|
if not _finalize(ctx, key, nnn):
|
|
189
193
|
return None
|
|
@@ -196,6 +200,10 @@ def handle(ctx: HookContext) -> dict | None:
|
|
|
196
200
|
text = (thresholds.c6_text(report.problems, draft_path) if report is not None
|
|
197
201
|
else thresholds.c2_text(thresholds.display_ratio(ctx, cfg), draft_path,
|
|
198
202
|
blocked=ledger.blocked_reason(sdir)))
|
|
203
|
+
ledger.gate(sdir, action="block", state_from="HANDOFF_REQUESTED",
|
|
204
|
+
state_to="HANDOFF_REQUESTED",
|
|
205
|
+
variant="c6" if report is not None else "c2",
|
|
206
|
+
attempts=attempts)
|
|
199
207
|
return {"decision": "block", "reason": text}
|
|
200
208
|
if s == "CHECKPOINT_WRITING":
|
|
201
209
|
if not _finalize(ctx, key, nnn):
|
|
@@ -30,7 +30,8 @@ import time
|
|
|
30
30
|
from pathlib import Path
|
|
31
31
|
|
|
32
32
|
from . import __version__, atomic, config, managed, skills
|
|
33
|
-
from .settings_merge import (
|
|
33
|
+
from .settings_merge import (ENV_OVERRIDE_KEY, ENV_OVERRIDE_VALUE,
|
|
34
|
+
detect_format, dump_settings,
|
|
34
35
|
merge_settings, unmerge_settings)
|
|
35
36
|
|
|
36
37
|
MIN_CLAUDE = (2, 1, 209) # Phase 0 verified floor (VERIFICATION.md)
|
|
@@ -279,7 +280,8 @@ def _carry_over_manifest(manifest: dict, prev: dict, win: int) -> None:
|
|
|
279
280
|
prev.get("status_line_changed"):
|
|
280
281
|
manifest["status_line_changed"] = True
|
|
281
282
|
manifest["previous_status_line"] = prev.get("previous_status_line")
|
|
282
|
-
ours = {"CLAUDE_CODE_MAX_CONTEXT_TOKENS": str(win)
|
|
283
|
+
ours = {"CLAUDE_CODE_MAX_CONTEXT_TOKENS": str(win),
|
|
284
|
+
ENV_OVERRIDE_KEY: ENV_OVERRIDE_VALUE}
|
|
283
285
|
prev_env = prev.get("env_prev") or {}
|
|
284
286
|
env_prev = manifest.get("env_prev") or {}
|
|
285
287
|
for key, our_value in ours.items():
|
|
@@ -48,6 +48,27 @@ def read(session_dir: str | Path) -> list[dict]:
|
|
|
48
48
|
return out
|
|
49
49
|
|
|
50
50
|
|
|
51
|
+
def gate(session_dir: str | Path, *, action: str, state_from: str,
|
|
52
|
+
state_to: str, ratio: float | None = None,
|
|
53
|
+
variant: str | None = None, **extra) -> dict | None:
|
|
54
|
+
"""Append a compact gate-decision record (issue #39): which decision
|
|
55
|
+
fired, its state transition, ratio and the C-text variant used.
|
|
56
|
+
Read-only for the model; consumed by logs and post-hoc debugging.
|
|
57
|
+
A failed append must never change hook behaviour, so OSError is
|
|
58
|
+
swallowed here and None is returned (blink-style discipline)."""
|
|
59
|
+
entry: dict = {"type": "gate", "action": action,
|
|
60
|
+
"from": state_from, "to": state_to}
|
|
61
|
+
if ratio is not None:
|
|
62
|
+
entry["ratio"] = round(float(ratio), 4)
|
|
63
|
+
if variant:
|
|
64
|
+
entry["variant"] = variant
|
|
65
|
+
entry.update(extra)
|
|
66
|
+
try:
|
|
67
|
+
return append(session_dir, entry)
|
|
68
|
+
except OSError:
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
|
|
51
72
|
def blocked_reason(session_dir: str | Path) -> str | None:
|
|
52
73
|
"""P9-P5: reason of the latest UNCONSUMED ``needs_human`` entry, or
|
|
53
74
|
None. A later main-session ``user_prompt`` entry (no ``agent_id``)
|
|
@@ -21,7 +21,14 @@ ALLOW_RULES = ("Read(~/.claude-continuity/**)",
|
|
|
21
21
|
"Edit(~/.claude-continuity/**)",
|
|
22
22
|
"Bash(cc-continuity *)")
|
|
23
23
|
ADDITIONAL_DIRS = ("~/.claude-continuity",)
|
|
24
|
-
|
|
24
|
+
# Issue #31: install pins the native auto-compact override so a fresh
|
|
25
|
+
# install starts the rotation race from the right position (the gate at
|
|
26
|
+
# 0.75 must always fire before auto-compact at 0.95; doctor's
|
|
27
|
+
# rotation-env check flags drift). Written only when absent - a
|
|
28
|
+
# user-set value always wins.
|
|
29
|
+
ENV_OVERRIDE_KEY = "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"
|
|
30
|
+
ENV_OVERRIDE_VALUE = "95"
|
|
31
|
+
ENV_KEYS = ("CLAUDE_CODE_MAX_CONTEXT_TOKENS", ENV_OVERRIDE_KEY)
|
|
25
32
|
# NOTE (F-P9-4, 2026-09-21 user decision): CLAUDE_CODE_AUTO_COMPACT_WINDOW
|
|
26
33
|
# is user-owned and never written or removed by the installer — PCT
|
|
27
34
|
# override + ACW together would enable native auto-compact, which the
|
|
@@ -70,6 +77,8 @@ def merge_settings(existing: dict, *, launcher: str, window: int) -> tuple[dict,
|
|
|
70
77
|
for key in ENV_KEYS:
|
|
71
78
|
manifest["env_prev"][key] = env.get(key)
|
|
72
79
|
env["CLAUDE_CODE_MAX_CONTEXT_TOKENS"] = str(window)
|
|
80
|
+
if not str(env.get(ENV_OVERRIDE_KEY, "")).strip():
|
|
81
|
+
env[ENV_OVERRIDE_KEY] = ENV_OVERRIDE_VALUE
|
|
73
82
|
perms = s.setdefault("permissions", {})
|
|
74
83
|
allow = perms.get("allow")
|
|
75
84
|
if not isinstance(allow, list):
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cc-continuity"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.10"
|
|
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)
|
|
@@ -120,9 +120,15 @@ def test_rotation_env_warns_on_drift(fake_home):
|
|
|
120
120
|
|
|
121
121
|
|
|
122
122
|
def test_rotation_env_warns_when_env_missing(fake_home):
|
|
123
|
-
#
|
|
123
|
+
# missing rotation-env keys are a warning, not a failure. The pins
|
|
124
|
+
# exist since #31, so the gap state must be created explicitly.
|
|
124
125
|
h = fake_home
|
|
125
126
|
install.install(h, window=262144, runner=FakeRun())
|
|
127
|
+
sp = h / ".claude" / "settings.json"
|
|
128
|
+
s = json.loads(sp.read_text(encoding="utf-8"))
|
|
129
|
+
del s["env"]["CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"]
|
|
130
|
+
del s["env"]["CLAUDE_CODE_MAX_CONTEXT_TOKENS"]
|
|
131
|
+
sp.write_text(json.dumps(s), encoding="utf-8")
|
|
126
132
|
checks = doctor.run_doctor(h, runner=FakeRun(), which=_which_ok)
|
|
127
133
|
c = next(x for x in checks if x.name == "rotation-env")
|
|
128
134
|
assert c.ok and c.warning
|
|
@@ -11,7 +11,7 @@ allowlist. Silent allow otherwise.
|
|
|
11
11
|
|
|
12
12
|
import pytest
|
|
13
13
|
|
|
14
|
-
from cc_continuity import paths, state
|
|
14
|
+
from cc_continuity import ledger, paths, state
|
|
15
15
|
|
|
16
16
|
from hookutil import (draft_path_for, make_repo, payload, register_session,
|
|
17
17
|
run_hook, set_metric, stdout_json, walk_to)
|
|
@@ -40,6 +40,11 @@ def _system(out):
|
|
|
40
40
|
return out.get("systemMessage", "")
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
def _gates(key, nnn):
|
|
44
|
+
return [e for e in ledger.read(paths.session_dir(key, nnn))
|
|
45
|
+
if e.get("type") == "gate"]
|
|
46
|
+
|
|
47
|
+
|
|
43
48
|
def test_below_hard_allows_silently(cc_home, capsys, tmp_path):
|
|
44
49
|
repo, key, nnn = _setup(cc_home, tmp_path, s="ACTIVE", ratio=0.60)
|
|
45
50
|
_pretool(repo, "Bash", {"command": "rm -rf x"})
|
|
@@ -188,3 +193,48 @@ def test_unregistered_session_silent(cc_home, capsys, tmp_path):
|
|
|
188
193
|
tool_input={"command": "x"})
|
|
189
194
|
assert run_hook("PreToolUse", p) == 0
|
|
190
195
|
assert capsys.readouterr().out == ""
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
# ------------------------------------------------------- gate ledger (#39)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def test_crossing_records_guide_gate_entry(cc_home, capsys, tmp_path):
|
|
202
|
+
repo, key, nnn = _setup(cc_home, tmp_path, s="WARNED", ratio=0.80)
|
|
203
|
+
_pretool(repo, "Bash", {"command": "rm -rf x"})
|
|
204
|
+
stdout_json(capsys)
|
|
205
|
+
g = _gates(key, nnn)
|
|
206
|
+
assert len(g) == 1
|
|
207
|
+
e = g[0]
|
|
208
|
+
assert e["action"] == "guide" and e["variant"] == "c2"
|
|
209
|
+
assert e["from"] == "WARNED" and e["to"] == "HANDOFF_REQUESTED"
|
|
210
|
+
assert e["ratio"] == 0.8
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def test_denies_record_gate_entries(cc_home, capsys, tmp_path):
|
|
214
|
+
repo, key, nnn = _setup(cc_home, tmp_path, s="ROTATION_PENDING", ratio=0.80)
|
|
215
|
+
_pretool(repo, "Bash", {"command": "rm -rf x"}) # crossing: guide
|
|
216
|
+
stdout_json(capsys)
|
|
217
|
+
_pretool(repo, "Bash", {"command": "pytest"}) # deny C.3
|
|
218
|
+
stdout_json(capsys)
|
|
219
|
+
g = _gates(key, nnn)
|
|
220
|
+
assert [(e["action"], e["variant"], e["from"], e["to"]) for e in g] == [
|
|
221
|
+
("guide", "c2", "ROTATION_PENDING", "HANDOFF_REQUESTED"),
|
|
222
|
+
("deny", "c3", "HANDOFF_REQUESTED", "HANDOFF_REQUESTED")]
|
|
223
|
+
assert g[1]["tool"] == "Bash" and "ratio" not in g[1]
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def test_allowed_tool_in_deny_state_records_nothing(cc_home, capsys, tmp_path):
|
|
227
|
+
# Only REAL denials are gate decisions: allowlisted calls pass silently.
|
|
228
|
+
repo, key, nnn = _setup(cc_home, tmp_path, s="HANDOFF_REQUESTED")
|
|
229
|
+
_pretool(repo, "Read", {"file_path": "x"})
|
|
230
|
+
assert stdout_json(capsys) is None
|
|
231
|
+
assert _gates(key, nnn) == []
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def test_c9_deny_records_gate_entry(cc_home, capsys, tmp_path):
|
|
235
|
+
repo, key, nnn = _setup(cc_home, tmp_path, s="CHECKPOINT_VERIFIED")
|
|
236
|
+
_pretool(repo, "Bash", {"command": "pytest"})
|
|
237
|
+
stdout_json(capsys)
|
|
238
|
+
g = _gates(key, nnn)
|
|
239
|
+
assert [(e["action"], e["variant"], e["from"], e["to"]) for e in g] == [
|
|
240
|
+
("deny", "c9", "CHECKPOINT_VERIFIED", "CHECKPOINT_VERIFIED")]
|
|
@@ -627,3 +627,39 @@ def test_stop_reply_flag_failure_never_blocks(cc_home, capsys, tmp_path,
|
|
|
627
627
|
run_hook("Stop", payload("Stop", repo))
|
|
628
628
|
# the hook swallows flag-arm failures: blink never blocks a stop
|
|
629
629
|
assert "reply_ready" in _types(paths.session_dir(key, nnn))
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
# ------------------------------------------------------- gate ledger (#39)
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
def test_valid_draft_rotation_records_silent_gate_entry(cc_home, capsys,
|
|
636
|
+
tmp_path):
|
|
637
|
+
repo, key, nnn = _setup(cc_home, tmp_path, s="ROTATION_PENDING")
|
|
638
|
+
(paths.session_dir(key, nnn) / "handoff.draft.md").write_text(
|
|
639
|
+
_valid_draft(), encoding="utf-8")
|
|
640
|
+
run_hook("Stop", payload("Stop", repo))
|
|
641
|
+
stdout_json(capsys)
|
|
642
|
+
g = [e for e in ledger.read(paths.session_dir(key, nnn))
|
|
643
|
+
if e.get("type") == "gate"]
|
|
644
|
+
assert [(e["action"], e["from"], e["to"]) for e in g] == [
|
|
645
|
+
("silent", "HANDOFF_REQUESTED", "CHECKPOINT_VERIFIED")]
|
|
646
|
+
assert "variant" not in g[0] and "ratio" not in g[0]
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
def test_blocks_record_gate_entries_with_variant_and_attempts(cc_home,
|
|
650
|
+
capsys,
|
|
651
|
+
tmp_path):
|
|
652
|
+
repo, key, nnn = _setup(cc_home, tmp_path, s="HANDOFF_REQUESTED")
|
|
653
|
+
(paths.session_dir(key, nnn) / "handoff.draft.md").write_text(
|
|
654
|
+
"## Objective\nshort\n", encoding="utf-8")
|
|
655
|
+
run_hook("Stop", payload("Stop", repo))
|
|
656
|
+
out = stdout_json(capsys)
|
|
657
|
+
assert out["decision"] == "block"
|
|
658
|
+
(paths.session_dir(key, nnn) / "handoff.draft.md").unlink()
|
|
659
|
+
run_hook("Stop", payload("Stop", repo))
|
|
660
|
+
out = stdout_json(capsys)
|
|
661
|
+
assert out["decision"] == "block"
|
|
662
|
+
g = [e for e in ledger.read(paths.session_dir(key, nnn))
|
|
663
|
+
if e.get("type") == "gate"]
|
|
664
|
+
assert [(e["action"], e["variant"], e["attempts"]) for e in g] == [
|
|
665
|
+
("block", "c6", 1), ("block", "c2", 2)]
|
|
@@ -59,6 +59,42 @@ def test_install_fresh_home_creates_all(fake_home):
|
|
|
59
59
|
assert "install" in cfg
|
|
60
60
|
|
|
61
61
|
|
|
62
|
+
def test_install_writes_override_when_absent(fake_home):
|
|
63
|
+
"""Issue #31: a fresh install must pin native auto-compact behind the
|
|
64
|
+
rotation gate (doctor #27 flags the gap otherwise); foreign env
|
|
65
|
+
values are preserved."""
|
|
66
|
+
h = fake_home
|
|
67
|
+
(h / ".claude").mkdir()
|
|
68
|
+
(h / ".claude" / "settings.json").write_text(
|
|
69
|
+
json.dumps({"env": {"CLAUDE_CODE_MAX_OUTPUT_TOKENS": "32000"}},
|
|
70
|
+
indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
71
|
+
install.install(h, window=262144, runner=FakeRun())
|
|
72
|
+
s = _settings(h)
|
|
73
|
+
assert s["env"]["CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"] == "95"
|
|
74
|
+
assert s["env"]["CLAUDE_CODE_MAX_OUTPUT_TOKENS"] == "32000"
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_install_keeps_existing_user_override(fake_home):
|
|
78
|
+
h = fake_home
|
|
79
|
+
(h / ".claude").mkdir()
|
|
80
|
+
(h / ".claude" / "settings.json").write_text(
|
|
81
|
+
json.dumps({"env": {"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "90"}},
|
|
82
|
+
indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
83
|
+
install.install(h, window=262144, runner=FakeRun())
|
|
84
|
+
assert _settings(h)["env"]["CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"] == "90"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_reinstall_then_uninstall_removes_override(fake_home):
|
|
88
|
+
"""Carry-over (F-G7-2) must cover the override too: two installs plus
|
|
89
|
+
one uninstall on a fresh home restores the pre-install env exactly."""
|
|
90
|
+
install.install(fake_home, window=262144, runner=FakeRun())
|
|
91
|
+
install.install(fake_home, window=262144, runner=FakeRun())
|
|
92
|
+
install.uninstall(fake_home)
|
|
93
|
+
s = _settings(fake_home)
|
|
94
|
+
assert "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE" not in s.get("env", {})
|
|
95
|
+
assert "CLAUDE_CODE_MAX_CONTEXT_TOKENS" not in s.get("env", {})
|
|
96
|
+
|
|
97
|
+
|
|
62
98
|
def test_hook_commands_use_absolute_launcher_path(fake_home):
|
|
63
99
|
install.install(fake_home, window=262144, runner=FakeRun())
|
|
64
100
|
s = _settings(fake_home)
|
|
@@ -154,3 +154,31 @@ def test_reply_pending_non_work_entries_do_not_consume(tmp_path):
|
|
|
154
154
|
assert ledger.reply_pending(sdir, settle=0, now=300.0) == 100.0
|
|
155
155
|
ledger.append(sdir, {"type": "tool_failure", "tool": "Bash", "ts": 103.0})
|
|
156
156
|
assert ledger.reply_pending(sdir, settle=0, now=300.0) is None
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
# ---------------------------------------------------------------- gate (#39)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def test_gate_entry_shape(tmp_path):
|
|
163
|
+
e = ledger.gate(tmp_path, action="guide", state_from="WARNED",
|
|
164
|
+
state_to="HANDOFF_REQUESTED", ratio=0.81234,
|
|
165
|
+
variant="c2", tool="Bash")
|
|
166
|
+
assert e["type"] == "gate" and e["action"] == "guide"
|
|
167
|
+
assert e["from"] == "WARNED" and e["to"] == "HANDOFF_REQUESTED"
|
|
168
|
+
assert e["ratio"] == 0.8123 and e["variant"] == "c2" and e["tool"] == "Bash"
|
|
169
|
+
assert ledger.read(tmp_path)[-1]["ts"] == e["ts"]
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def test_gate_omits_none_ratio_and_variant(tmp_path):
|
|
173
|
+
e = ledger.gate(tmp_path, action="silent", state_from="HANDOFF_REQUESTED",
|
|
174
|
+
state_to="CHECKPOINT_VERIFIED")
|
|
175
|
+
assert "ratio" not in e and "variant" not in e
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def test_gate_never_raises_on_write_failure(tmp_path, monkeypatch):
|
|
179
|
+
def boom(*a, **k):
|
|
180
|
+
raise OSError("disk gone")
|
|
181
|
+
monkeypatch.setattr(ledger.os, "write", boom)
|
|
182
|
+
assert ledger.gate(tmp_path, action="deny",
|
|
183
|
+
state_from="HANDOFF_REQUESTED",
|
|
184
|
+
state_to="HANDOFF_REQUESTED") is None
|
|
@@ -56,7 +56,8 @@ def test_merge_realistic_seed():
|
|
|
56
56
|
assert s["theme"] == "dark" # foreign keys survive
|
|
57
57
|
assert m["previous_status_line"] == HUD
|
|
58
58
|
assert m["status_line_changed"] is True
|
|
59
|
-
assert m["env_prev"] == {"CLAUDE_CODE_MAX_CONTEXT_TOKENS": "262144"
|
|
59
|
+
assert m["env_prev"] == {"CLAUDE_CODE_MAX_CONTEXT_TOKENS": "262144",
|
|
60
|
+
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "95"}
|
|
60
61
|
|
|
61
62
|
|
|
62
63
|
def test_merge_fresh_empty_settings():
|
|
@@ -115,11 +116,44 @@ def test_merge_preserves_user_acw():
|
|
|
115
116
|
orig = {"env": {"CLAUDE_CODE_AUTO_COMPACT_WINDOW": "30000"}}
|
|
116
117
|
merged, m = sm.merge_settings(orig, launcher=LAUNCHER, window=262144)
|
|
117
118
|
assert merged["env"]["CLAUDE_CODE_AUTO_COMPACT_WINDOW"] == "30000"
|
|
118
|
-
assert m["env_prev"] == {"CLAUDE_CODE_MAX_CONTEXT_TOKENS": None
|
|
119
|
+
assert m["env_prev"] == {"CLAUDE_CODE_MAX_CONTEXT_TOKENS": None,
|
|
120
|
+
"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": None}
|
|
119
121
|
out = sm.unmerge_settings(merged, m)
|
|
120
122
|
assert out["env"]["CLAUDE_CODE_AUTO_COMPACT_WINDOW"] == "30000"
|
|
121
123
|
|
|
122
124
|
|
|
125
|
+
def test_merge_pins_override_when_absent():
|
|
126
|
+
"""Issue #31: install pins native auto-compact behind the rotation
|
|
127
|
+
gate (doctor #27 flags the gap otherwise); the pin is only added when
|
|
128
|
+
absent - an existing user value always wins."""
|
|
129
|
+
merged, m = sm.merge_settings({}, launcher=LAUNCHER, window=262144)
|
|
130
|
+
assert merged["env"]["CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"] == "95"
|
|
131
|
+
assert m["env_prev"]["CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"] is None
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_merge_preserves_existing_user_override():
|
|
135
|
+
orig = {"env": {"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": "90"}}
|
|
136
|
+
merged, m = sm.merge_settings(orig, launcher=LAUNCHER, window=262144)
|
|
137
|
+
assert merged["env"]["CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"] == "90"
|
|
138
|
+
assert m["env_prev"]["CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"] == "90"
|
|
139
|
+
assert sm.unmerge_settings(merged, m) == orig
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_merge_treats_empty_override_as_absent():
|
|
143
|
+
orig = {"env": {"CLAUDE_AUTOCOMPACT_PCT_OVERRIDE": ""}}
|
|
144
|
+
merged, m = sm.merge_settings(orig, launcher=LAUNCHER, window=262144)
|
|
145
|
+
assert merged["env"]["CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"] == "95"
|
|
146
|
+
out = sm.unmerge_settings(merged, m)
|
|
147
|
+
assert out["env"]["CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"] == ""
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def test_unmerge_removes_override_when_we_added_it():
|
|
151
|
+
merged, m = sm.merge_settings({"theme": "dark"}, launcher=LAUNCHER,
|
|
152
|
+
window=262144)
|
|
153
|
+
out = sm.unmerge_settings(merged, m)
|
|
154
|
+
assert "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE" not in out.get("env", {})
|
|
155
|
+
|
|
156
|
+
|
|
123
157
|
def test_unmerge_env_prev_value_restored():
|
|
124
158
|
orig = {"env": {"CLAUDE_CODE_MAX_CONTEXT_TOKENS": "123456"}}
|
|
125
159
|
merged, m = sm.merge_settings(orig, launcher=LAUNCHER, window=262144)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|