Generous Lifecycle Mutation Implementation Plan
For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
Goal: Allow explicit lifecycle runs to start when almanac/ already has user edits, while still rejecting agent-created changes outside almanac/.
Architecture: LifecycleMutationPolicy remains the product boundary for mutation safety. Preflight records the before snapshot and verifies Git tracking is available; validation compares the before and after snapshots to find actual changes made during the run. PageRunWorkflow keeps the existing order: record harness output/events, validate mutation safety, validate harness status, refresh index, validate wiki, finish run.
Tech Stack: Python services/workflows, Pydantic workflow models, Git-backed workspace snapshots, pytest lifecycle workflow tests.
Task 1: Make Preflight Snapshot-Only#
Files:
- Modify:
src/codealmanac/workflows/lifecycle_mutation.py - Modify:
src/codealmanac/workflows/page_run/service.py - Test:
tests/test_ingest_workflow.py
Steps:
- Change
LifecycleMutationPolicy.preflight(...)so it no longer rejects dirty paths underalmanac/. - Keep
validate_snapshot_available(...); lifecycle runs still require readable Git status. - Keep
almanac_prefixinLifecycleMutationPreflight; validation still needs the allowed mutation boundary. - Change the preflight run event from "verified clean almanac preflight" to "captured almanac mutation preflight".
- Update any test assertion that depended on the old event text.
Task 2: Preserve Before/After Safety#
Files:
- Modify:
src/codealmanac/workflows/lifecycle_mutation.py - Test:
tests/test_ingest_workflow.py - Test:
tests/test_garden_workflow.py
Steps:
- Keep
changed_paths(before, after)as the source of truth. - Keep rejecting any path whose identity changed during the run and is not under
almanac/. - Keep validating harness-reported changed files are inside
almanac/; this catches providers that report an unsafe change even if Git status misses it. - Keep returning only changed
almanac/paths inLifecycleMutationReport.changed_files.
Task 3: Add Product Tests#
Files:
- Modify:
tests/test_ingest_workflow.py - Modify:
tests/test_garden_workflow.py
Steps:
- Replace the dirty-almanac rejection test with a test that pre-existing dirty
almanac/edits are allowed. - Assert the safety report includes both the pre-existing dirty page when the agent changes it and the new/changed wiki page.
- Keep the existing tests that pre-existing dirty source files are allowed when unchanged.
- Keep the existing tests that agent-created or agent-modified source files fail.
- Add or update a garden test so both lifecycle operations share the same policy.
Task 4: Verify#
Run:
uv run pytest tests/test_ingest_workflow.py tests/test_garden_workflow.py
uv run pytest tests/test_run_queue_workflow.py tests/test_validate.py
uv run ruff check .
uv run pytest
uv run codealmanac validate