stemedb/applications/aphoria/src/cli/governance.rs
jordan 8af9b48ac7 feat: Complete Aphoria Phase 14 - Governance Workflows
Implement structured approval workflows for pattern promotion with full
audit trails for SOC 2 compliance.

Core Components:
- governance/types.rs: ApprovalRequest, ApprovalStatus, ApprovalDecision
- governance/workflow.rs: ApprovalWorkflow, ApprovalStage with escalation
- governance/store.rs: JSONL persistence for requests and decisions
- governance/state_machine.rs: Approval state transitions with auto-advance
- governance/audit.rs: AuditTrail with JSON/CSV/Markdown export

CLI Commands:
- aphoria governance pending/approve/reject/escalate/status/create
- aphoria audit trail/export/summary

Integration:
- Pipeline gate blocks promotion until governance approval
- Auto-creates approval requests when governance enabled
- Evidence-based auto-approval for high-confidence patterns

Also includes:
- Phase 11-13: Evidence, Lifecycle, Scope modules
- 62+ governance-specific tests (946 total passing)
- Clippy clean with -D warnings
- Refactored cli.rs into submodules (governance, lifecycle, scope, etc.)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-07 05:16:26 -07:00

136 lines
3.7 KiB
Rust

//! Governance CLI command definitions.
use clap::Subcommand;
#[derive(Subcommand)]
pub enum GovernanceCommands {
/// List pending approval requests
///
/// Shows all patterns awaiting approval, grouped by workflow and stage.
Pending {
/// Filter by workflow name
#[arg(long)]
workflow: Option<String>,
/// Output format: table or json
#[arg(short, long, default_value = "table")]
format: String,
},
/// Approve the current stage of a request
///
/// Advances the request to the next stage, or completes approval
/// if this was the final stage.
Approve {
/// Request ID (UUID format)
id: String,
/// Optional comment explaining the approval
#[arg(short, long)]
comment: Option<String>,
},
/// Reject a pending request
///
/// Marks the request as rejected. The pattern will not be promoted
/// until a new approval request is created.
Reject {
/// Request ID (UUID format)
id: String,
/// Reason for rejection (required)
#[arg(short, long)]
reason: String,
},
/// Escalate a request to the next stage
///
/// Manually escalates a request to its configured escalation target.
/// Use this when a stage is taking too long or needs higher-level review.
Escalate {
/// Request ID (UUID format)
id: String,
},
/// Show approval request status
///
/// Display detailed status for approval requests, including
/// decisions made and current stage.
Status {
/// Show status for a specific pattern (UUID format)
#[arg(long)]
pattern: Option<String>,
/// Show all requests (including completed)
#[arg(long)]
all: bool,
/// Output format: table or json
#[arg(short, long, default_value = "table")]
format: String,
},
/// Check for timed-out requests and process them
///
/// Scans for requests past their stage deadline and either
/// escalates or expires them based on workflow configuration.
CheckTimeouts,
/// Create an approval request for a pattern
///
/// Manually create an approval request for a pattern. Normally
/// requests are created automatically during promotion.
Create {
/// Pattern ID (UUID format)
pattern_id: String,
/// Workflow to use (defaults to config default_workflow)
#[arg(short, long)]
workflow: Option<String>,
},
}
#[derive(Subcommand)]
pub enum AuditCommands {
/// Show audit trail for a pattern
///
/// Displays all governance events for a pattern in chronological order.
Trail {
/// Pattern ID (UUID format)
#[arg(long)]
pattern: String,
/// Output format: table or json
#[arg(short, long, default_value = "table")]
format: String,
},
/// Export governance audit history
///
/// Export all governance events and requests to a file for
/// compliance reporting or external analysis.
Export {
/// Output file path
#[arg(short, long)]
output: std::path::PathBuf,
/// Export format: json, csv, or markdown
#[arg(short, long, default_value = "json")]
format: String,
/// Filter by date range (YYYY-MM-DD..YYYY-MM-DD)
#[arg(long)]
date_range: Option<String>,
},
/// Show audit summary statistics
///
/// Display summary of governance activity including
/// approval rates, average times, and pending counts.
Summary {
/// Output format: table or json
#[arg(short, long, default_value = "table")]
format: String,
},
}