vtcode_desktop_protocol/
goal.rs1use serde::{Deserialize, Serialize};
11use vtcode_exec_events::goal::GoalSnapshot;
12
13#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct GoalExecuteParams {
17 pub session_id: String,
19 pub args: String,
21}
22
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
25#[serde(rename_all = "camelCase")]
26pub struct GoalExecuteResult {
27 pub session_id: String,
29 pub lines: Vec<String>,
31 pub mutated: bool,
33 #[serde(default, skip_serializing_if = "Option::is_none")]
36 pub submit: Option<String>,
37 #[serde(default, skip_serializing_if = "Option::is_none")]
39 pub goal: Option<GoalSnapshot>,
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45 use vtcode_exec_events::goal::GoalState;
46
47 #[test]
48 fn goal_execute_params_use_camel_case_keys() {
49 let params = GoalExecuteParams { session_id: "s".into(), args: "pause".into() };
50 let json = serde_json::to_value(¶ms).unwrap();
51 assert_eq!(json["sessionId"], "s");
52 assert_eq!(json["args"], "pause");
53 }
54
55 #[test]
56 fn goal_execute_result_round_trips_and_omits_empty_fields() {
57 let full = GoalExecuteResult {
58 session_id: "s".into(),
59 lines: vec!["Goal set: Ship it".into()],
60 mutated: true,
61 submit: Some("Ship it".into()),
62 goal: Some(GoalSnapshot {
63 goal_id: "goal-1".into(),
64 state: GoalState::Active,
65 objective: "Ship it".into(),
66 elapsed_ms: 0,
67 tokens_used: 0,
68 token_budget: None,
69 pause_message: None,
70 }),
71 };
72 let json = serde_json::to_string(&full).unwrap();
73 let restored: GoalExecuteResult = serde_json::from_str(&json).unwrap();
74 assert_eq!(restored, full);
75
76 let minimal = GoalExecuteResult {
77 session_id: "s".into(),
78 lines: vec![],
79 mutated: false,
80 submit: None,
81 goal: None,
82 };
83 let json = serde_json::to_value(&minimal).unwrap();
84 assert_eq!(json["sessionId"], "s");
85 assert!(json.get("submit").is_none());
86 assert!(json.get("goal").is_none());
87 }
88}