1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
//! Command-line interface for the makima CLI.
pub mod config;
pub mod contract;
pub mod daemon;
pub mod monitor;
pub mod red_team;
pub mod server;
pub mod supervisor;
pub mod view;
use clap::{Args, Parser, Subcommand};
use uuid::Uuid;
pub use config::CliConfig;
pub use contract::ContractArgs;
pub use daemon::DaemonArgs;
pub use monitor::MonitorArgs;
pub use red_team::handle_notify;
pub use server::ServerArgs;
pub use supervisor::SupervisorArgs;
pub use view::ViewArgs;
/// Makima - unified CLI for server, daemon, and task management.
#[derive(Parser, Debug)]
#[command(name = "makima")]
#[command(version, about = "Makima CLI - server, daemon, and task management", long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
/// Run the makima server
Server(ServerArgs),
/// Run the daemon (connect to server, manage tasks)
Daemon(DaemonArgs),
/// Supervisor commands for contract orchestration
#[command(subcommand)]
Supervisor(SupervisorCommand),
/// Contract commands for task-contract interaction
#[command(subcommand)]
Contract(ContractCommand),
/// Interactive TUI browser for contracts and tasks
///
/// Provides a drill-down interface for browsing contracts, viewing their
/// tasks, and streaming real-time task output.
///
/// Keyboard shortcuts:
/// ↑/k: Move up ↓/j: Move down Enter/l: Drill in
/// Esc/h: Go back /: Search q: Quit
/// e: Edit d: Delete c: cd to worktree
/// n: New contract
View(ViewArgs),
/// Configure CLI settings (API key, server URL)
///
/// Saves configuration to ~/.makima/config.toml for use by CLI commands.
#[command(subcommand)]
Config(ConfigCommand),
/// Red team commands for adversarial monitoring
#[command(name = "red-team", subcommand)]
RedTeam(RedTeamCommand),
/// Commands for monitoring and managing multiple contracts
#[command(subcommand)]
Contracts(ContractsCommand),
}
/// Config subcommands for CLI configuration.
#[derive(Subcommand, Debug)]
pub enum ConfigCommand {
/// Set the API key
///
/// Saves the API key to ~/.makima/config.toml
SetKey(config::SetKeyArgs),
/// Set the API URL
///
/// Saves the API URL to ~/.makima/config.toml
SetUrl(config::SetUrlArgs),
/// Show current configuration
Show,
/// Show the config file path
Path,
}
/// Supervisor subcommands for contract orchestration.
#[derive(Subcommand, Debug)]
pub enum SupervisorCommand {
/// List all tasks in the contract
Tasks(SupervisorArgs),
/// Get the task tree structure
Tree(SupervisorArgs),
/// Create and start a new task
Spawn(supervisor::SpawnArgs),
/// Wait for a task to complete
Wait(supervisor::WaitArgs),
/// Read a file from a task's worktree
ReadFile(supervisor::ReadFileArgs),
/// Create a git branch
Branch(supervisor::BranchArgs),
/// Merge a task's changes to a branch
Merge(supervisor::MergeArgs),
/// Create a pull request
Pr(supervisor::PrArgs),
/// View task diff
Diff(supervisor::DiffArgs),
/// Create a checkpoint
Checkpoint(supervisor::CheckpointArgs),
/// List checkpoints
Checkpoints(SupervisorArgs),
/// Get contract status
Status(SupervisorArgs),
/// Advance the contract to the next phase
AdvancePhase(supervisor::AdvancePhaseArgs),
/// Ask a question and wait for user feedback
Ask(supervisor::AskArgs),
/// Get individual task details
Task(supervisor::GetTaskArgs),
/// Get task output/claude log
Output(supervisor::GetTaskOutputArgs),
/// View task conversation history
TaskHistory(supervisor::TaskHistoryArgs),
/// List task checkpoints (with optional diff)
TaskCheckpoints(supervisor::TaskCheckpointsArgs),
/// Resume supervisor after interruption
Resume(supervisor::ResumeArgs),
/// Resume task from checkpoint
TaskResumeFrom(supervisor::TaskResumeFromArgs),
/// Rewind task code to checkpoint
TaskRewind(supervisor::TaskRewindArgs),
/// Fork task from historical point
TaskFork(supervisor::TaskForkArgs),
/// Rewind supervisor conversation
RewindConversation(supervisor::ConversationRewindArgs),
/// Mark the contract as complete and stop the supervisor
Complete(supervisor::CompleteArgs),
/// Resume a completed contract (reactivate it)
ResumeContract(supervisor::ResumeContractArgs),
/// Mark a deliverable as complete
MarkDeliverable(supervisor::MarkDeliverableArgs),
}
/// Contract subcommands for task-contract interaction.
#[derive(Subcommand, Debug)]
pub enum ContractCommand {
/// Get contract status
Status(ContractArgs),
/// Get the phase checklist
Checklist(ContractArgs),
/// Get contract goals
Goals(ContractArgs),
/// List contract files
Files(ContractArgs),
/// Get a specific file's content
File(contract::FileArgs),
/// Report progress on the contract
Report(contract::ReportArgs),
/// Get suggested next action
SuggestAction(ContractArgs),
/// Get completion recommendation
CompletionAction(contract::CompletionActionArgs),
/// Update a file (reads content from stdin)
UpdateFile(contract::UpdateFileArgs),
/// Create a new file (reads content from stdin)
CreateFile(contract::CreateFileArgs),
}
/// Red team subcommands for adversarial monitoring.
#[derive(Subcommand, Debug)]
pub enum RedTeamCommand {
/// Send a notification to the supervisor about a detected issue.
/// Only available to red team tasks.
Notify(RedTeamNotifyArgs),
}
/// Contracts subcommands for monitoring and managing multiple contracts.
#[derive(Subcommand, Debug)]
pub enum ContractsCommand {
/// Real-time monitoring of contracts
///
/// Polls for contract changes and displays updates in real-time.
/// Supports filtering by contract IDs, status, and staleness.
///
/// Examples:
/// makima contracts monitor # Monitor all active contracts
/// makima contracts monitor abc-123 def-456 # Monitor specific contracts
/// makima contracts monitor --stale # Only show stale contracts
/// makima contracts monitor --format json # JSON output for scripting
Monitor(MonitorArgs),
}
/// Arguments for red-team notify command.
#[derive(Args, Debug)]
pub struct RedTeamNotifyArgs {
/// API URL
#[arg(long, env = "MAKIMA_API_URL", default_value = "https://api.makima.jp")]
pub api_url: String,
/// API key for authentication
#[arg(long, env = "MAKIMA_API_KEY")]
pub api_key: String,
/// Current task ID (must be a red team task)
#[arg(long, env = "MAKIMA_TASK_ID")]
pub task_id: Uuid,
/// Contract ID
#[arg(long, env = "MAKIMA_CONTRACT_ID")]
pub contract_id: Uuid,
/// The notification message
#[arg(index = 1)]
pub message: String,
/// Severity level: low, medium, high, critical
#[arg(long, default_value = "medium")]
pub severity: String,
/// Related task ID (optional)
#[arg(long)]
pub task: Option<Uuid>,
/// Related file path (optional)
#[arg(long)]
pub file: Option<String>,
/// Additional context (optional)
#[arg(long)]
pub context: Option<String>,
}
impl Cli {
/// Parse command-line arguments
pub fn parse_args() -> Self {
Self::parse()
}
}
|