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
mod commands;
mod db;
mod output;
use clap::error::ErrorKind;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser)]
#[command(
name = "agent-kanban",
about = "Kanban board for concurrent LLM agents",
version
)]
struct Cli {
/// Indent JSON output.
#[arg(long, global = true, conflicts_with = "table")]
pretty: bool,
/// Render output as a human-readable table instead of JSON.
#[arg(long, global = true)]
table: bool,
/// Use this exact database file instead of discovering `.kanban/` by
/// walking up from the current directory. For `init`, creates the
/// database here (making parent directories as needed) instead of at
/// the default `.kanban/board.db`.
#[arg(long, global = true, value_name = "PATH")]
db: Option<PathBuf>,
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
/// Create `.kanban/board.db` in the current directory.
Init,
/// Manage registered agents.
Agent {
#[command(subcommand)]
action: AgentAction,
},
/// Create a task. `--test` may be repeated; each is a JSON object
/// `{"describe","input","output"}`. At least one `--test` is required.
Add {
#[arg(long)]
title: String,
#[arg(long)]
priority: String,
#[arg(long = "tag")]
tags: Vec<String>,
#[arg(long = "test", required = true)]
tests: Vec<String>,
},
/// List tasks, optionally filtered and sorted.
List {
#[arg(long)]
status: Option<String>,
#[arg(long)]
tag: Option<String>,
#[arg(long)]
executor: Option<String>,
#[arg(long)]
priority: Option<String>,
#[arg(long)]
sort: Option<String>,
},
/// Show a single task.
Show { id: i64 },
/// Claim a task for a registered agent (atomic; fails if already claimed).
Claim {
id: i64,
#[arg(long)]
agent: String,
},
/// Move a task to a new status.
Move {
id: i64,
#[arg(long)]
status: String,
},
/// Un-claim a task.
Release { id: i64 },
/// Edit a task's fields in place. Blocked while claimed or done.
Edit {
id: i64,
#[arg(long)]
title: Option<String>,
#[arg(long)]
priority: Option<String>,
#[arg(long = "tag")]
tags: Option<Vec<String>>,
#[arg(long = "test")]
tests: Option<Vec<String>>,
},
/// Hard-delete a task. Blocked while claimed or done.
Remove { id: i64 },
/// Board overview: task counts per status column plus each registered
/// agent's current claimed-task count.
Status,
}
#[derive(Subcommand)]
enum AgentAction {
/// Register a new agent name.
Register { name: String },
/// List registered agents.
List,
/// Remove an agent, auto-releasing any tasks it holds.
Remove { name: String },
}
fn main() {
let cli = match Cli::try_parse() {
Ok(cli) => cli,
Err(err) => {
// --help/--version aren't errors -- print them exactly as clap
// normally would (human-readable, exit 0), not as JSON.
if matches!(
err.kind(),
ErrorKind::DisplayHelp
| ErrorKind::DisplayVersion
| ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand
) {
err.exit();
}
// Every other parse failure (bad flag, non-numeric id, missing
// required argument, unknown subcommand) must still honor this
// tool's JSON error contract -- `Cli::parse()` would otherwise
// print clap's own multi-line human-readable text here instead,
// which the rest of this program's error handling deliberately
// avoids everywhere else.
output::fail_with_code(&err.to_string(), err.exit_code(), output::Format::Compact);
}
};
if let Some(path) = cli.db.clone() {
db::set_path_override(path);
}
let result = match cli.command {
Command::Init => commands::init(),
Command::Agent { action } => match action {
AgentAction::Register { name } => commands::agent::register(&name),
AgentAction::List => commands::agent::list(),
AgentAction::Remove { name } => commands::agent::remove(&name),
},
Command::Add {
title,
priority,
tags,
tests,
} => commands::task::add(&title, &priority, &tags, &tests),
Command::List {
status,
tag,
executor,
priority,
sort,
} => commands::task::list(status, tag, executor, priority, sort.as_deref()),
Command::Show { id } => commands::task::show(id),
Command::Claim { id, agent } => commands::lifecycle::claim(id, &agent),
Command::Move { id, status } => commands::lifecycle::move_status(id, &status),
Command::Release { id } => commands::lifecycle::release(id),
Command::Edit {
id,
title,
priority,
tags,
tests,
} => commands::task::edit(id, title, priority, tags, tests.as_deref()),
Command::Remove { id } => commands::task::remove(id),
Command::Status => commands::status::status(),
};
let format = if cli.table {
output::Format::Table
} else if cli.pretty {
output::Format::Pretty
} else {
output::Format::Compact
};
match result {
Ok(value) => output::print(&value, format),
Err(err) => output::fail(&err, format),
}
}