generated from nhcarrigan/template
feat: handle PostCompact hook event (#225)
Parses [PostCompact Hook] from stderr, emits claude:post-compact, shows a toast notification, and briefly sets the character to success state.
This commit is contained in:
@@ -310,6 +310,14 @@ pub struct StopFailureEvent {
|
||||
pub conversation_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PostCompactEvent {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub session_id: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub conversation_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct AgentStartEvent {
|
||||
pub tool_use_id: String,
|
||||
@@ -697,4 +705,40 @@ mod tests {
|
||||
assert!(!serialized.contains("error_type"));
|
||||
assert!(!serialized.contains("conversation_id"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_post_compact_event_serialization() {
|
||||
let event = PostCompactEvent {
|
||||
session_id: Some("sess-abc".to_string()),
|
||||
conversation_id: Some("conv-123".to_string()),
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_string(&event).unwrap();
|
||||
assert!(serialized.contains("\"session_id\":\"sess-abc\""));
|
||||
assert!(serialized.contains("\"conversation_id\":\"conv-123\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_post_compact_event_omits_none_fields() {
|
||||
let event = PostCompactEvent {
|
||||
session_id: None,
|
||||
conversation_id: None,
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_string(&event).unwrap();
|
||||
assert!(!serialized.contains("session_id"));
|
||||
assert!(!serialized.contains("conversation_id"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_post_compact_event_partial_fields() {
|
||||
let event = PostCompactEvent {
|
||||
session_id: Some("sess-xyz".to_string()),
|
||||
conversation_id: None,
|
||||
};
|
||||
|
||||
let serialized = serde_json::to_string(&event).unwrap();
|
||||
assert!(serialized.contains("\"session_id\":\"sess-xyz\""));
|
||||
assert!(!serialized.contains("conversation_id"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user