返回 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
8 #[derive(Debug, Clone, PartialEq, Eq)]
9 pub enum DebugReceiptError {
10 ApprovalLog(String),
11 Build(String),
12 }
13
14 pub trait CommandDebugReceiptsContext {
15 fn receipt(&self, turn: Option<&str>) -> Result<Receipt, DebugReceiptError>;
16 }
17
18 #[derive(Debug, Clone, PartialEq, Eq)]
19 pub struct DebugChangeProjection {
20 pub changelog: &'static str,
21 pub is_english: bool,
22 pub translation_available: bool,
23 pub translation_target: &'static str,
24 }
25
26 pub trait CommandDebugChangeContext {
27 fn change_projection(&self) -> DebugChangeProjection;
28 }
29
30 pub trait CommandDebugHistoryContext {
31 fn last_user_input(&self) -> Option<String>;
32 fn load_composer(&mut self, input: String);
33 /// Prepare a last-exchange rollback without mutating the live transcript.
34 /// The host applies it only after the Engine acknowledges the truncated
35 /// conversation; retry additionally waits for durable persistence (#6788).
36 fn undo_conversation(&mut self) -> DebugConversationUndo;
37 }
38
39 /// Prepared conversation-only undo: display cells to remove after Engine
40 /// acknowledgement, and the conversation to install as its history.
41 #[derive(Debug, Clone, PartialEq)]
42 pub struct DebugConversationUndo {
43 pub removed: usize,
44 pub sync: SessionSyncPayload,
45 }
46
47 #[derive(Debug, Clone, PartialEq, Eq)]
48 pub enum DebugDiffObservation {
49 GitUnavailable,
50 /// Nothing to compare against: the session has saved no restore point
51 /// for this workspace and the workspace is not a git repository.
52 NoBaseline,
53 Output {
54 names: String,
55 stat: String,
56 /// The unified patch behind `names` and `stat`, bounded by the host.
57 patch: String,
58 /// The host cut `patch` at its bound; `names` and `stat` are whole.
59 patch_truncated: bool,
60 },
61 Failed(String),
62 }
63
64 pub trait CommandDebugDiffContext {
65 fn diff(&self) -> DebugDiffObservation;
66 }
67
68 pub trait CommandDebugUndoContext {}
69
69 lines RUST