feat: Phase 4 — Dream safety net (snapshot, diff, doctor, rollback, hygiene)#6
Merged
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
All Phase 4 thresholds (dream_doctor disk/file/line limits, snapshot retention, hygiene regex extras) loaded from optional ~/.cc-janitor/config.toml. Missing or malformed file → DEFAULTS. Partial overrides preserve unspecified defaults. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Lock-file observer with NO_LOCK/LOCK_HELD transitions. snapshot_pre
and snapshot_post copy ~/.claude/projects/<slug>/memory/ trees to
~/.cc-janitor/backups/dream/<pair_id>-{pre,post}/. record_pair writes
one JSONL record with file_count_delta, line_count_delta, has_diff,
dream_pid_in_lock. Storage starts as "raw"; tar compaction (Task 10)
flips it to "tar" later.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extends the Phase 3 watcher daemon to optionally observe per-project .consolidate-lock files. On lock-appears: write pre-snapshot to ~/.cc-janitor/backups/dream/<pair_id>-pre/. On lock-gone: write post-snapshot and record a DreamSnapshotPair to dream-snapshots.jsonl. Opt-in via `cc-janitor watch start --dream`. mtime reinject watch remains the default; add --no-memory to disable it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
DreamFileDelta classifies each path as added/removed/changed/unchanged, counts +/- lines, embeds difflib.unified_diff body. Summary dict aggregates counts. No semantic grouping (Phase 5). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
stale_lock (Issue #50694), autodream_enabled, server_gate (Issue #38461), last_dream_ts, backup_dir_health, memory_md_cap, disk_usage, memory_file_count, duplicate_summary. All thresholds from config.toml; cross-file dup check reuses Phase 1 find_duplicate_lines. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
memory_md_size_lines, relative_date_density (en+ru regex over 12 default terms, user-extensible via config.toml), cross_file_dup_count (reuses Phase 1 find_duplicate_lines), contradicting_pairs (NEG/POS regex + Jaccard token overlap, threshold from config.toml). LLM-based semantic analysis explicitly deferred to Phase 5. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Read-only: history (list pairs), diff (file-level + unified diff), doctor (9 checks). Mutating: rollback (soft-deletes current state to trash, copies pre-mirror back; --apply gated by require_confirmed + audit_action), prune (removes artifacts older than N days). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Surfaces the 4 keyword/regex/dup metrics from core.sleep_hygiene as a per-project summary table or JSON document. Read-only; safe to invoke from inside a Claude Code session. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
DreamScreen lays out a DataTable (snapshot history) beside a Static diff viewer. Row highlight triggers compute_diff() for the selected pair_id and renders summary + per-file deltas + unified diff body. Read-only; future TUI-driven rollback will route through ConfirmModal from tui/_confirm.py (Phase 4 task 11 stretch / Phase 5). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
cc-janitor backups tar-compact --kind dream --older-than-days 7 --apply groups <pair_id>-pre / <pair_id>-post dirs into <pair_id>.tar.gz and removes raw mirrors. New scheduler template `dream-tar-compact` runs this weekly (Sunday 05:00). Audit-logged via audit_action; --apply gated behind require_confirmed(); default mode is dry-run. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Caches last-seen autoDreamEnabled value at ~/.cc-janitor/state/autodream-last-seen.json. On every dream doctor invocation, compares with current ~/.claude/settings.json and appends an audit-log entry (cmd=settings-observe, mode=observer) on flip. Surfaces as a "settings autoDream toggled" WARN row in dream doctor output, warning users to verify backups are configured before the next Dream cycle. Closes Phase 4 Task 11. +5 tests, total 267. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
i18n: new [dream] and [sleep_hygiene] tables in en.toml + ru.toml covering the new screens. Cookbook: three new recipes (#11 diff/rollback after Dream, #12 stale lock diagnosis via dream doctor, #13 scheduled snapshot setup with dream-tar-compact + config.toml override). CC_USAGE.md: Phase 4 section listing five read-only commands safe for Claude to call, plus five mutating ones that require CC_JANITOR_USER_CONFIRMED=1. CHANGELOG: [0.4.0] block above [0.3.3] documenting all six Phase 4 features and the closed upstream Issues (#47959, #50694, #38493, #38461). Version bumped to 0.4.0 in pyproject.toml + cli/__init__.py; CLI skeleton test assertion updated. README gains a Phase 4 hero section and marks Phase 2/3/4 done in the roadmap. Also drops 33 pre-existing ruff lints (RUF010 / UP017 / I001) across Phase 4 modules now that the suite is being shipped. Closes Phase 4 Task 12. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 4 = the "sleep safety net" around Anthropic's Auto Dream. Six features, 13 TDD tasks, 0.3.3 -> 0.4.0.
cc-janitor dream history|diff|doctor|rollback|prune. Pre/post snapshots stored at~/.cc-janitor/backups/dream/<pair_id>-{pre,post}/, recorded to~/.cc-janitor/dream-snapshots.jsonl.--dreammode —cc-janitor watch start --dreampolls every~/.claude/projects/*/memory/.consolidate-lockand writes a raw mirror around each Dream cycle.cc-janitor dream doctor(10 checks) — stale lock, autoDream flag state, server-gate inference, last-dream ts, backup dir health + disk usage, MEMORY.md cap, memory file count, cross-file duplicate summary, settings-audit toggle warning.cc-janitor stats sleep-hygiene— four keyword/regex/dup metrics (MEMORY.md size, relative-date density, cross-file duplicates, contradicting-feedback pairs).cc-janitor backups tar-compact --kind dream+ new scheduler templatedream-tar-compact(7d raw / 30d tar retention, configurable via~/.cc-janitor/config.toml).~/.claude/settings.json:autoDreamEnabledat~/.cc-janitor/state/autodream-last-seen.json; on flip, writes audit-log entry (cmd=settings-observe) and surfaces a WARN row incc-janitor dream doctor.Plus: 8th TUI tab (
Dream) with snapshot list + diff viewer panes, optional~/.cc-janitor/config.toml, i18n[dream]+[sleep_hygiene]tables (en + ru), three new cookbook recipes.Closes upstream Issues
.consolidate-locksilently disables Auto Dream.dream-log.mdTest plan
uv run pytest -v— 267 passed (was 262; +5 fromtest_settings_observer.py)uv run ruff check src tests— clean (33 pre-existing lints auto-fixed across Phase 4 modules)cc-janitor dream history,cc-janitor dream doctor,cc-janitor stats sleep-hygiene,cc-janitor watch statusDreamtab renders snapshot list and diff viewer🤖 Generated with Claude Code