Skip to content

feat(cli): v1 audit subcommand refactor — unified flow with canonical paths#106

Merged
montfort merged 1 commit intomainfrom
feat/audit-cli-refactor-canonical-paths
May 5, 2026
Merged

feat(cli): v1 audit subcommand refactor — unified flow with canonical paths#106
montfort merged 1 commit intomainfrom
feat/audit-cli-refactor-canonical-paths

Conversation

@montfort
Copy link
Copy Markdown
Contributor

@montfort montfort commented May 5, 2026

Summary

Fourth of 8 PRs implementing the integrated v1 audit-skills iteration described in `Propuesta/devtrail-audit-cli-flow.md` v0.2. This is the largest refactor of the rollout — switches `devtrail charter audit` from the v0 three-step subcommand to the v1 unified flow + introduces canonical paths under `.devtrail/audits/` + deprecates the legacy templates (already replaced by the unified one in PR #105).

Subcommand changes

  • NEW `--prepare` (default action): generates the unified audit-prompt.
  • NEW `--merge-reports`: reads N `report-*.md` files, validates each, emits/merges YAML.
  • `--merge-into`: now combines with `--merge-reports` (or deprecated `--finalize`). Removed strict `requires = "finalize"`.
  • DEPRECATED `--calibrate` (hidden in --help): emits warning explaining v1 has no separate calibrate step and exits with error.
  • DEPRECATED `--finalize` (hidden in --help): aliases to `--merge-reports`. Emits warning, routes through new path. Functional equivalent when reports exist at canonical location.

Canonical path migration

  • audit_dir is now `.devtrail/audits//` (was `audit/charters//`). Per propuesta D13: namespaced under `.devtrail/` to avoid collisions; structure leaves the door open for future audit-unit categories (MODULE-, RELEASE-, EPIC-) without restructuring.
  • Resolved prompt: `<audit_dir>/audit-prompt.md` (single file).
  • Reports: `<audit_dir>/report-.md` (PR 5's `audit-execute` skill produces these; manual paste also supported).

Resolver simplification

  • `run_prepare` reads ONE template, writes ONE resolved file. Two-pass loop gone.
  • `run_calibrate` REMOVED (deprecation shim emits warning and exits).
  • `run_finalize` REPLACED by `run_merge_reports` (globs `report-*.md` instead of reading two fixed paths).
  • `AuditContext`: dropped `auditor_primary_findings` / `auditor_secondary_findings`; added `project_context` (D12).
  • `resolve_audit_template` pairs: 12 → 11 placeholders.

Templates deleted (PR #105 shipped the unified replacement)

  • `dist/.devtrail/audit-prompts/auditor-primary.md` (154 lines)
  • `dist/.devtrail/audit-prompts/auditor-secondary.md` (131 lines)
  • `dist/.devtrail/audit-prompts/calibrator-reconciler.md` (173 lines)

Only `audit-prompt.md` remains.

Tests

10 new v1 tests + 7 v0-tests-ported-to-v1 = 17 total in `charter_audit_test`. Highlights:

  • `audit_merge_reports_handles_n_reports_with_unified_role` (exercises N=3 reports with `audit_role: auditor`).
  • `audit_merge_reports_warns_on_single_report_but_proceeds` (heterogeneity warning).
  • `audit_deprecated_calibrate_emits_warning_and_exits`.
  • `audit_deprecated_finalize_redirects_to_merge_reports`.
  • `audit_action_flags_are_mutually_exclusive` (covers all 4 action flags vs each other).
  • `audit_prepare_writes_unified_prompt_to_canonical_location` (R10 regression assertions ported + asserts v0 paths NOT created).

Test plan

  • `cargo test --test charter_audit_test` → 17/17 green
  • `cargo test` (full suite) → all suites green, no regressions in `audit_skill_test` (8) / `audit_template_test` (9) / any other test binary
  • `cargo build` → 1.44s
  • No version bump (lands with PRs 5-8 in integrated v1 release)

Phase v1 progress

PR Title Status
1 R10 resolver fix merged (#103)
2 `git_range` default → `origin/main..HEAD` with fallback merged (#104)
3 Unified `audit-prompt.md` template (Sentinel skill lift) merged (#105)
4 CLI subcommand refactor + canonical paths + deprecation shims + delete v0 templates this PR
5 New skill `devtrail-audit-execute` (3 platforms) pending
6 Updated `audit-prompt` and `audit-review` skills (review.md consolidated) pending
7 Adopter docs (3 langs) pending
8 Bump `fw-4.9.0` / `cli-3.10.0` + CHANGELOG + tag release pending

🤖 Generated with Claude Code

… paths

Closes the CLI side of the v1 audit-skills iteration described in
Propuesta/devtrail-audit-cli-flow.md v0.2 §3.2 + §5.1 PR 4. This is
the largest refactor of the rollout: switches `devtrail charter audit`
from the v0 three-step subcommand (PREPARE/CALIBRATE/FINALIZE with
two auditor templates + calibrator template) to the v1 unified flow
(PREPARE writes one prompt; the operator runs N auditors via the new
audit-execute skill in PR 5; merge-reports validates N reports and
emits/merges the YAML; the calibrator role moves to the main agent
via the audit-review skill in PR 6).

Subcommand changes (cli/src/main.rs):

  - NEW flag --prepare (default action): generates the unified
    audit-prompt at the canonical path. Mutually exclusive with the
    other action flags via clap's conflicts_with_all.
  - NEW flag --merge-reports: reads N report-*.md from the canonical
    audit dir, validates each against audit-output.schema.v0.json,
    emits the external_audit YAML (or merges into telemetry with
    --merge-into).
  - --merge-into now combines with --merge-reports (or the deprecated
    --finalize for backwards compat). Removed `requires = "finalize"`.
  - DEPRECATED --calibrate: kept for backwards compat (hidden in
    --help via #[arg(hide = true)]). Emits a warning explaining the
    v1 flow has no separate calibrate step (the main agent fills the
    calibrator role inline via /devtrail-audit-review skill) and
    exits with error.
  - DEPRECATED --finalize: hidden alias for --merge-reports. Emits a
    warning and routes through the new path. Functional equivalent
    when reports exist at the canonical location.

Canonical path migration (cli/src/commands/charter/audit.rs):

  - audit_dir is now .devtrail/audits/<CHARTER-ID>/ (was
    audit/charters/<CHARTER-ID>/). Per Propuesta D13: the new
    location is namespaced under .devtrail/ to avoid collisions
    with adopter-defined audit/ folders, and the structure leaves
    the door open for future audit-unit categories beyond Charter
    (MODULE-, RELEASE-, EPIC-, etc.) without restructuring.
  - The unified audit-prompt is written to <audit_dir>/audit-prompt.md
    (single file, not a prompts/ subdirectory with two files).
  - Reports land at <audit_dir>/report-<sluggified-model-id>.md (the
    v1 audit-execute skill in PR 5 will produce these; manual paste
    is also supported).

Resolver simplification:

  - run_prepare reads ONE template (audit-prompt.md) and writes ONE
    resolved file. The two-pass loop over auditor-primary/secondary
    is gone.
  - run_calibrate REMOVED (replaced by deprecation shim that emits
    a warning and exits).
  - run_finalize REPLACED by run_merge_reports, which globs
    report-*.md instead of reading two fixed paths. Iterates over
    N>=1 reports; warns when only one is present (heterogeneity
    inter-family is the discovery mechanism); errors when none
    found with helpful message about running --prepare first or
    invoking the audit-execute skill.
  - AuditContext: dropped auditor_primary_findings and
    auditor_secondary_findings (only used by the now-deleted
    calibrator template). NEW field project_context (D12) for the
    {{project_context}} placeholder; default empty until adopters
    fill it manually or a future release derives it from
    CLAUDE.md / config.yml.
  - resolve_audit_template's pairs array shrunk by 2 placeholders
    (auditor_primary_findings, auditor_secondary_findings) and
    grew by 1 ({{project_context}}). Net: 12 → 11 placeholders.

Templates deleted (PR 3 already shipped the unified replacement):

  - dist/.devtrail/audit-prompts/auditor-primary.md (154 lines)
  - dist/.devtrail/audit-prompts/auditor-secondary.md (131 lines)
  - dist/.devtrail/audit-prompts/calibrator-reconciler.md (173 lines)

Only audit-prompt.md remains in dist/.devtrail/audit-prompts/.

Tests (cli/tests/charter_audit_test.rs): rewritten extensively.

  - setup_devtrail simplified: writes only audit-prompt.md (no
    primary/secondary/calibrator).
  - NEW helper audit_dir(dir, charter_id) returns the v1 canonical
    path.
  - setup_finalized_audit writes two reports under the canonical
    path with audit_role: auditor (v1 unified).
  - REMOVED tests that assumed the v0 three-step flow:
    audit_calibrate_requires_auditor_outputs,
    audit_calibrate_validates_outputs_against_schema,
    audit_full_three_step_cycle_succeeds,
    audit_calibrate_and_finalize_are_mutually_exclusive.
  - REPLACED with v1 equivalents:
    audit_merge_reports_with_no_reports_fails_helpfully,
    audit_merge_reports_validates_against_schema,
    audit_merge_reports_handles_n_reports_with_unified_role
    (exercises N=3 reports with audit_role: auditor),
    audit_merge_reports_warns_on_single_report_but_proceeds,
    audit_deprecated_calibrate_emits_warning_and_exits,
    audit_deprecated_finalize_redirects_to_merge_reports,
    audit_action_flags_are_mutually_exclusive (covers all 4 action
    flags vs each other),
    audit_prepare_writes_unified_prompt_to_canonical_location
    (R10 regression assertions ported to single-file shape, plus
    asserts v0 paths under audit/charters/ are NOT created).
  - UPDATED merge-into tests for v1 paths (--merge-reports instead
    of --finalize, .devtrail/audits/ canonical paths).
  - UPDATED R11(A) default-range tests to read from the v1 prompt
    location.

Test plan:
  - cargo test --test charter_audit_test → 17/17 green (10 of these
    are new v1 tests; 7 are R10/R11(A)/merge-into ported to v1
    paths).
  - cargo test (full suite) → all suites green, no regressions in
    audit_skill_test (8), audit_template_test (9), or any other
    test binary.
  - cargo build → 1.44s (with target preserved).
  - No version bump (lands together with PRs 5-8 in the integrated
    v1 release per Propuesta v0.2 §5).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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