返回 CodeWhale
debug_operations.rs
根目录 / crates / command-contract / src / facets / debug_operations.rs
1 //! Typed host boundaries replacing direct App access in the remaining debug
2 //! commands. Read-only receipts/diff/change cannot acquire mutation authority.
3 //! Snapshot planning, safe restoration and history updates remain host-owned;
4 //! command parsing, fallback decisions and report rendering remain portable.
5
6 use super::{Receipt, SessionSyncPayload};
7 use std::path::PathBuf;
8
9 #[derive(Debug, Clone, PartialEq, Eq)]
10 pub enum DebugReceiptError {
11 ApprovalLog(String),
12 Build(String),
13 }
14
15 pub trait CommandDebugReceiptsContext {
16 fn receipt(&self, turn: Option<&str>) -> Result<Receipt, DebugReceiptError>;
17 }
18
19 #[derive(Debug, Clone, PartialEq, Eq)]
20 pub struct DebugChangeProjection {
21 pub changelog: &'static str,
22 pub is_english: bool,
23 pub translation_available: bool,
24 pub translation_target: &'static str,
25 }
26
27 pub trait CommandDebugChangeContext {
28 fn change_projection(&self) -> DebugChangeProjection;
29 }
30
31 pub trait CommandDebugHistoryContext {
32 fn last_user_input(&self) -> Option<String>;
33 fn load_composer(&mut self, input: String);
34 /// Prepare a last-exchange rollback without mutating the live transcript.
35 /// The host applies it only after the Engine acknowledges the truncated
36 /// conversation; retry additionally waits for durable persistence (#6788).
37 fn undo_conversation(&mut self) -> DebugConversationUndo;
38 }
39
40 /// Prepared conversation-only undo: display cells to remove after Engine
41 /// acknowledgement, and the conversation to install as its history.
42 #[derive(Debug, Clone, PartialEq)]
43 pub struct DebugConversationUndo {
44 pub removed: usize,
45 pub sync: SessionSyncPayload,
46 }
47
48 #[derive(Debug, Clone, PartialEq, Eq)]
49 pub enum DebugDiffObservation {
50 GitUnavailable,
51 Output { names: String, stat: String },
52 Failed(String),
53 }
54
55 pub trait CommandDebugDiffContext {
56 fn diff(&self) -> DebugDiffObservation;
57 }
58
59 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
60 pub enum DebugRestoreAction {
61 Modified,
62 Recreated,
63 Removed,
64 }
65
66 #[derive(Debug, Clone, PartialEq, Eq)]
67 pub struct DebugRestoredFile {
68 pub action: DebugRestoreAction,
69 pub path: PathBuf,
70 }
71
72 #[derive(Debug, Clone, PartialEq)]
73 pub struct DebugUndoRestored {
74 pub label: String,
75 pub snapshot_id: String,
76 pub files: Vec<DebugRestoredFile>,
77 pub skipped: Vec<PathBuf>,
78 pub sync: SessionSyncPayload,
79 }
80
81 #[derive(Debug, Clone, PartialEq)]
82 pub enum DebugUndoOutcome {
83 RepoUnavailable { workspace: PathBuf, error: String },
84 SnapshotPending,
85 NoSnapshots,
86 NoSession,
87 NoOwnedSteps,
88 NoDifference,
89 Untrusted,
90 CompareFailed(String),
91 SnapshotFailed(String),
92 ChangedSince { label: String, paths: Vec<String> },
93 ListFailed(String),
94 RestoreBlocked(String),
95 RestoreFailed(String),
96 Restored(DebugUndoRestored),
97 }
98
99 pub trait CommandDebugUndoContext {
100 /// Preserves snapshot ownership, trust, regular-file checks, backup,
101 /// preflight, pruning and transcript receipt. Never falls back to chat
102 /// truncation: the portable handler decides that from the typed outcome.
103 fn undo_files(&mut self) -> DebugUndoOutcome;
104 }
105
105 lines RUST