Skip to content

M60 (TASK-117-FREE): JSONC-Safe verity mcp install, AtomicBackupManager & Durable Command Resolution

1. Purpose & Architectural Decisions

  • Problem: verity init --register-mcp and python -m verity.mcp_server.manage install are two divergent install paths; both destroy JSONC comments/formatting, write a broken bare "command": "verity" that GUI MCP hosts cannot resolve, and verity fix mutates disk by default.
  • Decision (P0.5): unify both into verity mcp install + verity mcp rollback, patch JSONC losslessly, resolve a durable absolute command, wire OnboardingController + AtomicBackupManager, and make verity fix non-destructive by default with client-aware strategies.
  • Deterministic truth invariant: applying the same patch twice to the same file yields byte-identical output (idempotent); verity mcp rollback restores the exact pre-install bytes recorded in .verity/backups/<ts>/manifest.json SHA-256 digests.
  • Free/Pro boundary: Free owns install/rollback, the JSONC patcher, AtomicBackupManager, resolve_durable_mcp_command(), and the three client-aware Free verity fix strategies. Pro owns the AST/GitOps strategies (ast-sql, ast-guard, remediate-pr) and PR generation.

2. Target Files & Technical Deliverables

File Deliverable
src/verity/onboarding/jsonc_patcher.py tokenize_jsonc + set_top_level_jsonc_key preserving // and /* */ comments, trailing commas, URLs, and indentation; round-trip parse validation before commit.
src/verity/onboarding/backup.py AtomicBackupManager writes .verity/backups/<ts>/manifest.json with SHA-256 digests, os.fsync(), and atomic os.replace(); supports restoration.
src/verity/onboarding/controller.py resolve_durable_mcp_command(): .venv/pipx -> sys.executable + ["-m", "verity.mcp_server"]; persistent PATH binary -> absolute path; uvx -> explicit warning (never a bare fragile "verity").
src/verity/mcp_server/manage.py Delegate install/remove to the unified commands; remove duplicate config writer.
src/verity/remediation/__init__.py Non-destructive default; deterministic-only pin-versions; host-native externalize-secrets (${env:VAR} for VS Code, .env auto-source warning, .gitignore verification before write).
src/verity/cli.py verity mcp install [--client ...] [--scope project|user], verity mcp rollback, and verity fix --dry-run default with --write alias for --apply.
tests/unit/test_mcp_install_and_rollback.py New ATDD suite (below).

Scope default: --scope project writes only .mcp.json, .cursor/mcp.json, .vscode/mcp.json; --scope user is the explicit opt-in for installed desktop/CLI hosts. Default transport is stdio.

3. ATDD Traceability Matrix

AC ID Acceptance Criterion Paired Benign / Negative Control Verification Tier Test Target
AC-60.1 verity mcp install preserves JSONC comments/formatting/URLs via tokenize_jsonc/set_top_level_jsonc_key and creates .verity/backups/<ts>/manifest.json with valid SHA-256 before atomic os.replace(); verity mcp rollback restores byte-for-byte. Repeated verity mcp install is idempotent (byte-identical file, no second entry). unit tests/unit/test_mcp_install_and_rollback.py::test_jsonc_install_preserves_comments_and_rollback
AC-60.2 resolve_durable_mcp_command emits an absolute sys.executable + ["-m", "verity.mcp_server"] inside .venv/pipx environments and warns on ephemeral uvx. A bare "command": "verity" is never written when the binary is not on the GUI PATH. unit tests/unit/test_mcp_install_and_rollback.py::test_resolve_durable_mcp_command
AC-60.3 --scope project writes only project-local .mcp.json/.cursor/mcp.json/.vscode/mcp.json. No $HOME file is touched unless --scope user is passed. unit tests/unit/test_mcp_install_and_rollback.py::test_project_scope_never_writes_home
AC-60.4 verity fix defaults to non-mutating --dry-run; --apply requires deterministic version resolution for pin-versions and checks .gitignore + host-native ${env:VAR} for externalize-secrets. Dry-run leaves the config file byte-identical on disk. unit tests/unit/test_mcp_install_and_rollback.py::test_fix_dry_run_and_client_aware_strategies
AC-60.5 Lint and the full unit suite pass. Clean workspace yields zero lint errors. ruff uv run ruff check src tests scripts && uv run pytest tests/

4. Verification Commands

uv run pytest tests/unit/test_mcp_install_and_rollback.py
uv run pytest tests/
uv run ruff check src tests scripts

5. Execution Checklist

  • [ ] AC-60.1 verified green
  • [ ] AC-60.2 verified green
  • [ ] AC-60.3 verified green
  • [ ] AC-60.4 verified green
  • [ ] AC-60.5 verified green
  • [ ] Board #5 item PVTI_lAHOD-xmQM4Br351zhOMDUc synced & status updated