exomonad_core/protocol/mod.rs
1//! Protocol types for the control envelope.
2//!
3//! Defines message types for hook events and MCP tool calls that flow
4//! between exomonad subcommands and the Haskell control socket server.
5//!
6//! ## Message Flow
7//!
8//! ```text
9//! Claude Code hooks exomonad hook <event> Control Socket
10//! (stdin JSON) --> (parse & forward) --> (Haskell server)
11//! <-- (response JSON) <--
12//! ```
13//!
14//! Message formats match Claude Code's hook stdin/stdout schemas exactly
15//! to allow passthrough with minimal transformation.
16
17pub mod hook;
18pub mod mcp;
19pub mod service;
20
21use clap::ValueEnum;
22use serde::{Deserialize, Serialize};
23
24// Re-export commonly used types
25pub use hook::{
26 ClaudePreToolUseOutput, ClaudeStopHookOutput, GeminiStopDecision, GeminiStopHookOutput,
27 HookInput, HookSpecificOutput, InternalStopHookOutput, PermissionDecision, StopDecision,
28};
29pub use mcp::{McpError, ToolDefinition};
30pub use service::{
31 ChatMessage, ContentBlock, GitHubAuthorRef, GitHubDiscussionComment, GitHubIssueRef,
32 GitHubLabelRef, GitHubPRRef, GitHubReviewComment, IssueState, ServiceRequest, ServiceResponse,
33 StopReason, Tool, Usage,
34};
35
36// ============================================================================
37// Protocol-level types
38// ============================================================================
39
40/// The runtime environment for the agent.
41#[derive(
42 Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, ValueEnum, Default, strum::Display,
43)]
44#[serde(rename_all = "lowercase")]
45#[strum(serialize_all = "lowercase")]
46pub enum Runtime {
47 /// Anthropic's Claude Code CLI.
48 #[default]
49 Claude,
50 /// Google's Gemini CLI.
51 Gemini,
52}
53
54/// Hook event type for CLI hooks.
55/// Includes both Claude-specific and Gemini-specific hook types.
56#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, strum::Display)]
57#[strum(serialize_all = "kebab-case")]
58pub enum HookEventType {
59 /// Before tool execution (can allow/deny/modify)
60 PreToolUse,
61 /// After tool completion
62 PostToolUse,
63 /// When a notification is shown
64 Notification,
65 /// When Claude Code wants to stop (main agent)
66 Stop,
67 /// When a subagent (Task tool) starts
68 SubagentStart,
69 /// When a subagent (Task tool) finishes
70 SubagentStop,
71 /// Before a compact operation
72 PreCompact,
73 /// When a session starts or resumes
74 SessionStart,
75 /// When a session ends
76 SessionEnd,
77 /// When permission dialog is shown
78 PermissionRequest,
79 /// When user submits a prompt
80 UserPromptSubmit,
81 /// Gemini: After agent finishes (equivalent to Claude's Stop for main agent)
82 AfterAgent,
83}