rec/replay/mod.rs
1//! Replay module for executing recorded terminal sessions.
2//!
3//! Provides safety detection, command execution, interactive prompts,
4//! and configuration for session replay.
5
6pub mod engine;
7pub mod executor;
8pub mod prompt;
9pub mod safety;
10
11pub use engine::ReplayEngine;
12
13use std::collections::HashSet;
14
15/// Policy for handling dangerous (destructive) commands during replay.
16///
17/// Used by CI/CD pipelines and non-interactive environments to control
18/// how destructive commands are handled without requiring TTY interaction.
19///
20/// When `None` is used in `ReplayOptions`, the existing interactive behavior
21/// is preserved (prompt in TTY, auto-skip in non-interactive).
22#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
23pub enum DangerPolicy {
24 /// Skip dangerous commands with warnings
25 Skip,
26 /// Scan for dangerous commands and abort without executing
27 Abort,
28 /// Execute all commands including dangerous ones
29 Allow,
30}
31
32/// Options controlling replay behavior.
33///
34/// All indices are 0-based internally. Conversion from 1-based
35/// user input happens at the CLI boundary.
36#[derive(Debug, Clone, Default)]
37pub struct ReplayOptions {
38 /// Preview commands without executing
39 pub dry_run: bool,
40 /// Execute one command at a time with confirmation
41 pub step: bool,
42 /// Set of command indices to skip (0-based)
43 pub skip_indices: HashSet<usize>,
44 /// Glob patterns — commands matching any pattern are skipped
45 pub skip_patterns: Vec<glob::Pattern>,
46 /// Start execution from this command index (0-based)
47 pub from_index: Option<usize>,
48 /// Bypass destructive command prompts
49 pub force: bool,
50 /// Replay in each command's original working directory
51 pub use_original_cwd: bool,
52 /// Policy for handling dangerous commands (None = use existing interactive behavior)
53 pub danger_policy: Option<DangerPolicy>,
54}
55
56/// Summary of a replay execution.
57#[derive(Debug, Clone)]
58pub struct ReplaySummary {
59 /// Total number of commands in the session
60 pub total: usize,
61 /// Number of commands successfully executed
62 pub executed: usize,
63 /// Number of commands skipped
64 pub skipped: usize,
65 /// Number of commands that failed
66 pub failed: usize,
67 /// Whether the replay was aborted (Ctrl+C or user choice)
68 pub aborted: bool,
69}