Skip to content

feat: Phase 4 — Dream safety net (snapshot, diff, doctor, rollback, hygiene)#6

Merged
CreatmanCEO merged 13 commits into
mainfrom
feat/phase4-mvp
May 11, 2026
Merged

feat: Phase 4 — Dream safety net (snapshot, diff, doctor, rollback, hygiene)#6
CreatmanCEO merged 13 commits into
mainfrom
feat/phase4-mvp

Conversation

@CreatmanCEO
Copy link
Copy Markdown
Owner

Summary

Phase 4 = the "sleep safety net" around Anthropic's Auto Dream. Six features, 13 TDD tasks, 0.3.3 -> 0.4.0.

  • Dream snapshot harnesscc-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.
  • Watcher --dream modecc-janitor watch start --dream polls every ~/.claude/projects/*/memory/.consolidate-lock and 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 template dream-tar-compact (7d raw / 30d tar retention, configurable via ~/.cc-janitor/config.toml).
  • Settings-audit hook — caches ~/.claude/settings.json:autoDreamEnabled at ~/.cc-janitor/state/autodream-last-seen.json; on flip, writes audit-log entry (cmd=settings-observe) and surfaces a WARN row in cc-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

  • #47959 — silent Auto Dream memory deletion
  • #50694 — stale .consolidate-lock silently disables Auto Dream
  • #38493 — missing .dream-log.md
  • #38461 — server-gate inference for Auto Dream flag

Test plan

  • uv run pytest -v — 267 passed (was 262; +5 from test_settings_observer.py)
  • uv run ruff check src tests — clean (33 pre-existing lints auto-fixed across Phase 4 modules)
  • CLI surface manually verified: cc-janitor dream history, cc-janitor dream doctor, cc-janitor stats sleep-hygiene, cc-janitor watch status
  • TUI Dream tab renders snapshot list and diff viewer

🤖 Generated with Claude Code

CreatmanCEO and others added 13 commits May 11, 2026 10:15
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>
@CreatmanCEO CreatmanCEO merged commit 583603b into main May 11, 2026
4 checks passed
@CreatmanCEO CreatmanCEO deleted the feat/phase4-mvp branch May 11, 2026 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant