| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
pub mod admin; |
| 6 |
pub mod agent; |
| 7 |
pub mod brief; |
| 8 |
pub mod connect; |
| 9 |
pub mod format; |
| 10 |
pub mod human; |
| 11 |
pub mod identity; |
| 12 |
pub mod marks; |
| 13 |
pub mod mcp; |
| 14 |
pub mod open; |
| 15 |
pub mod project; |
| 16 |
pub mod serve; |
| 17 |
pub mod setup; |
| 18 |
pub mod ui; |
| 19 |
|
| 20 |
use anyhow::{bail, Context, Result}; |
| 21 |
use clap::{Parser, Subcommand}; |
| 22 |
use std::path::PathBuf; |
| 23 |
|
| 24 |
#[derive(Parser)] |
| 25 |
#[command(name = "spectra", version = env!("SPECTRA_VERSION_LONG"), about = "A control plane for AI coding agents")] |
| 26 |
pub struct Cli { |
| 27 |
|
| 28 |
#[arg(long, global = true)] |
| 29 |
pub plain: bool, |
| 30 |
|
| 31 |
#[arg(long, global = true, env = "SPECTRA_DATA")] |
| 32 |
pub data: Option<PathBuf>, |
| 33 |
#[command(subcommand)] |
| 34 |
pub command: Command, |
| 35 |
} |
| 36 |
|
| 37 |
#[derive(Subcommand)] |
| 38 |
pub enum Command { |
| 39 |
|
| 40 |
Version { |
| 41 |
|
| 42 |
#[arg(long)] |
| 43 |
json: bool, |
| 44 |
}, |
| 45 |
|
| 46 |
|
| 47 |
Init { |
| 48 |
|
| 49 |
#[arg(long)] |
| 50 |
owner_home: Option<PathBuf>, |
| 51 |
|
| 52 |
#[arg(long)] |
| 53 |
name: Option<String>, |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
#[arg(long, value_name = "KEYID", conflicts_with = "owner_home")] |
| 58 |
owner: Option<String>, |
| 59 |
}, |
| 60 |
|
| 61 |
|
| 62 |
Connect { |
| 63 |
|
| 64 |
url: String, |
| 65 |
|
| 66 |
#[arg(long, value_name = "KEYID-PREFIX")] |
| 67 |
expect: Option<String>, |
| 68 |
|
| 69 |
#[arg(long, short = 'y')] |
| 70 |
yes: bool, |
| 71 |
|
| 72 |
#[arg(long)] |
| 73 |
owner_home: Option<PathBuf>, |
| 74 |
}, |
| 75 |
|
| 76 |
Status { |
| 77 |
#[arg(long)] |
| 78 |
json: bool, |
| 79 |
}, |
| 80 |
|
| 81 |
Probe { |
| 82 |
|
| 83 |
url: String, |
| 84 |
#[arg(long)] |
| 85 |
json: bool, |
| 86 |
}, |
| 87 |
|
| 88 |
|
| 89 |
Bridge { |
| 90 |
#[arg(long, default_value_t = 0)] |
| 91 |
port: u16, |
| 92 |
#[arg(long)] |
| 93 |
owner_home: Option<PathBuf>, |
| 94 |
}, |
| 95 |
|
| 96 |
Brief { |
| 97 |
#[command(subcommand)] |
| 98 |
command: BriefCmd, |
| 99 |
}, |
| 100 |
|
| 101 |
Identity { |
| 102 |
#[command(subcommand)] |
| 103 |
command: IdentityCmd, |
| 104 |
}, |
| 105 |
|
| 106 |
Serve { |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
#[arg(long)] |
| 111 |
bind: Option<String>, |
| 112 |
|
| 113 |
|
| 114 |
#[arg(long)] |
| 115 |
tls: Option<String>, |
| 116 |
|
| 117 |
#[arg(long)] |
| 118 |
insecure: bool, |
| 119 |
|
| 120 |
#[arg(long)] |
| 121 |
open: bool, |
| 122 |
}, |
| 123 |
|
| 124 |
Open { |
| 125 |
#[arg(long)] |
| 126 |
owner_home: Option<PathBuf>, |
| 127 |
|
| 128 |
#[arg(long)] |
| 129 |
no_browser: bool, |
| 130 |
|
| 131 |
|
| 132 |
#[arg(long, default_value_t = 7350)] |
| 133 |
port: u16, |
| 134 |
}, |
| 135 |
|
| 136 |
Mcp { |
| 137 |
|
| 138 |
#[arg(long)] |
| 139 |
agent: String, |
| 140 |
|
| 141 |
#[arg(long)] |
| 142 |
home: Option<PathBuf>, |
| 143 |
}, |
| 144 |
|
| 145 |
Say { |
| 146 |
|
| 147 |
body: String, |
| 148 |
|
| 149 |
#[arg(short, long)] |
| 150 |
channel: Option<String>, |
| 151 |
|
| 152 |
#[arg(long)] |
| 153 |
reply_to: Option<String>, |
| 154 |
#[arg(long)] |
| 155 |
json: bool, |
| 156 |
#[arg(long)] |
| 157 |
owner_home: Option<PathBuf>, |
| 158 |
}, |
| 159 |
|
| 160 |
Inbox { |
| 161 |
#[arg(long)] |
| 162 |
follow: bool, |
| 163 |
#[arg(long)] |
| 164 |
json: bool, |
| 165 |
#[arg(long)] |
| 166 |
owner_home: Option<PathBuf>, |
| 167 |
}, |
| 168 |
|
| 169 |
Search { |
| 170 |
query: String, |
| 171 |
#[arg(long)] |
| 172 |
channel: Option<String>, |
| 173 |
#[arg(long)] |
| 174 |
author: Option<String>, |
| 175 |
|
| 176 |
#[arg(long)] |
| 177 |
since: Option<String>, |
| 178 |
#[arg(long, default_value_t = 20)] |
| 179 |
limit: u32, |
| 180 |
#[arg(long)] |
| 181 |
json: bool, |
| 182 |
}, |
| 183 |
|
| 184 |
Api { |
| 185 |
method: String, |
| 186 |
path: String, |
| 187 |
|
| 188 |
#[arg(short = 'd', long = "body")] |
| 189 |
body: Option<String>, |
| 190 |
#[arg(long)] |
| 191 |
owner_home: Option<PathBuf>, |
| 192 |
}, |
| 193 |
|
| 194 |
Project { |
| 195 |
#[command(subcommand)] |
| 196 |
command: ProjectCmd, |
| 197 |
}, |
| 198 |
|
| 199 |
Agent { |
| 200 |
#[command(subcommand)] |
| 201 |
command: AgentCmd, |
| 202 |
}, |
| 203 |
|
| 204 |
Admin { |
| 205 |
#[command(subcommand)] |
| 206 |
command: Admin, |
| 207 |
}, |
| 208 |
} |
| 209 |
|
| 210 |
#[derive(Subcommand)] |
| 211 |
pub enum IdentityCmd { |
| 212 |
|
| 213 |
Create { |
| 214 |
|
| 215 |
#[arg(long)] |
| 216 |
name: String, |
| 217 |
|
| 218 |
#[arg(long, default_value = "")] |
| 219 |
contact: String, |
| 220 |
|
| 221 |
#[arg(long)] |
| 222 |
home: Option<PathBuf>, |
| 223 |
#[arg(long)] |
| 224 |
json: bool, |
| 225 |
}, |
| 226 |
|
| 227 |
Show { |
| 228 |
#[arg(long)] |
| 229 |
json: bool, |
| 230 |
}, |
| 231 |
|
| 232 |
Refresh { |
| 233 |
#[arg(long)] |
| 234 |
owner_home: Option<PathBuf>, |
| 235 |
}, |
| 236 |
} |
| 237 |
|
| 238 |
#[derive(Subcommand)] |
| 239 |
pub enum BriefCmd { |
| 240 |
|
| 241 |
Show { |
| 242 |
#[arg(long)] |
| 243 |
project: Option<String>, |
| 244 |
#[arg(long)] |
| 245 |
json: bool, |
| 246 |
}, |
| 247 |
|
| 248 |
Set { |
| 249 |
#[arg(long)] |
| 250 |
project: Option<String>, |
| 251 |
|
| 252 |
text: Option<String>, |
| 253 |
|
| 254 |
#[arg(long, short = 'f')] |
| 255 |
file: Option<PathBuf>, |
| 256 |
#[arg(long)] |
| 257 |
owner_home: Option<PathBuf>, |
| 258 |
}, |
| 259 |
|
| 260 |
Edit { |
| 261 |
#[arg(long)] |
| 262 |
project: Option<String>, |
| 263 |
#[arg(long)] |
| 264 |
owner_home: Option<PathBuf>, |
| 265 |
}, |
| 266 |
} |
| 267 |
|
| 268 |
#[derive(Subcommand)] |
| 269 |
pub enum ProjectCmd { |
| 270 |
|
| 271 |
Add { |
| 272 |
|
| 273 |
target: String, |
| 274 |
|
| 275 |
#[arg(long)] |
| 276 |
name: Option<String>, |
| 277 |
|
| 278 |
#[arg(long)] |
| 279 |
path: Option<PathBuf>, |
| 280 |
|
| 281 |
#[arg(long, short = 'd', default_value = "")] |
| 282 |
description: String, |
| 283 |
|
| 284 |
#[arg(long)] |
| 285 |
url: Option<String>, |
| 286 |
#[arg(long)] |
| 287 |
owner_home: Option<PathBuf>, |
| 288 |
}, |
| 289 |
|
| 290 |
Link { |
| 291 |
project: String, |
| 292 |
#[arg(long)] |
| 293 |
depends_on: String, |
| 294 |
|
| 295 |
#[arg(long)] |
| 296 |
remove: bool, |
| 297 |
#[arg(long)] |
| 298 |
owner_home: Option<PathBuf>, |
| 299 |
}, |
| 300 |
|
| 301 |
List { |
| 302 |
#[arg(long)] |
| 303 |
json: bool, |
| 304 |
}, |
| 305 |
} |
| 306 |
|
| 307 |
#[derive(Subcommand)] |
| 308 |
pub enum AgentCmd { |
| 309 |
|
| 310 |
Add { |
| 311 |
|
| 312 |
name: String, |
| 313 |
|
| 314 |
#[arg(long)] |
| 315 |
kind: String, |
| 316 |
|
| 317 |
#[arg(long)] |
| 318 |
project: String, |
| 319 |
|
| 320 |
#[arg(long)] |
| 321 |
home: PathBuf, |
| 322 |
|
| 323 |
#[arg(long)] |
| 324 |
uid: Option<u32>, |
| 325 |
|
| 326 |
#[arg(long, conflicts_with = "uid")] |
| 327 |
learn_uid: bool, |
| 328 |
|
| 329 |
#[arg(long)] |
| 330 |
expires: Option<String>, |
| 331 |
|
| 332 |
#[arg(long, short = 'y')] |
| 333 |
yes: bool, |
| 334 |
|
| 335 |
#[arg(long)] |
| 336 |
owner_home: Option<PathBuf>, |
| 337 |
}, |
| 338 |
|
| 339 |
Renew { |
| 340 |
name: String, |
| 341 |
|
| 342 |
#[arg(long)] |
| 343 |
expires: String, |
| 344 |
#[arg(long)] |
| 345 |
owner_home: Option<PathBuf>, |
| 346 |
}, |
| 347 |
|
| 348 |
List { |
| 349 |
#[arg(long)] |
| 350 |
json: bool, |
| 351 |
}, |
| 352 |
|
| 353 |
Disable { |
| 354 |
name: String, |
| 355 |
#[arg(long)] |
| 356 |
owner_home: Option<PathBuf>, |
| 357 |
}, |
| 358 |
} |
| 359 |
|
| 360 |
#[derive(Subcommand)] |
| 361 |
pub enum Admin { |
| 362 |
|
| 363 |
Verify { |
| 364 |
|
| 365 |
#[arg(long)] |
| 366 |
json: bool, |
| 367 |
}, |
| 368 |
|
| 369 |
Check, |
| 370 |
|
| 371 |
Rebuild, |
| 372 |
} |
| 373 |
|
| 374 |
|
| 375 |
pub struct Ctx { |
| 376 |
pub data: PathBuf, |
| 377 |
} |
| 378 |
|
| 379 |
impl Ctx { |
| 380 |
|
| 381 |
pub fn db(&self) -> Result<PathBuf> { |
| 382 |
let db = self.data.join("spectra.db"); |
| 383 |
if !db.exists() { |
| 384 |
bail!("no Spectra in {} (run `spectra init`, or pass --data)", self.data.display()); |
| 385 |
} |
| 386 |
Ok(db) |
| 387 |
} |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
pub async fn writer(&self) -> Result<spectra_core::ledger::Ledger> { |
| 392 |
let db = self.db()?; |
| 393 |
let instance = spectra_core::keys::KeyPair::instance(&self.data, "spectra")?; |
| 394 |
spectra_core::ledger::Ledger::open(&db, Some(instance)).await |
| 395 |
} |
| 396 |
|
| 397 |
|
| 398 |
pub fn socket(&self) -> PathBuf { |
| 399 |
self.data.join("spectra.sock") |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
pub fn remote(&self) -> Result<Option<connect::ClientCfg>> { |
| 404 |
connect::load() |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
pub fn endpoint(&self) -> Result<spectra_mcp::client::Endpoint> { |
| 409 |
Ok(match self.remote()? { |
| 410 |
Some(c) => c.endpoint()?, |
| 411 |
None => spectra_mcp::client::Endpoint::Unix(self.socket()), |
| 412 |
}) |
| 413 |
} |
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
pub async fn owner_client(&self, owner_home: &std::path::Path) -> Result<Option<spectra_mcp::client::Client>> { |
| 420 |
use spectra_mcp::client::Client; |
| 421 |
if let Some(cfg) = self.remote()? { |
| 422 |
let ep = cfg.endpoint()?; |
| 423 |
let pair = remote_owner(&ep, owner_home).await?; |
| 424 |
return Ok(Some(Client::at(ep, Some(pair)))); |
| 425 |
} |
| 426 |
if !self.data.join("spectra.db").exists() || !Client::alive(&self.socket()).await { |
| 427 |
return Ok(None); |
| 428 |
} |
| 429 |
let ledger = spectra_core::ledger::Ledger::open_read_only(&self.db()?).await?; |
| 430 |
Ok(Some(Client::new(&self.socket(), Some(identity::recorded_owner(&ledger, owner_home).await?)))) |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
pub async fn owner_writer(&self, owner_home: &std::path::Path) -> Result<Writer> { |
| 437 |
if let Some(cfg) = self.remote()? { |
| 438 |
let ep = cfg.endpoint()?; |
| 439 |
let pair = remote_owner(&ep, owner_home).await?; |
| 440 |
let recorded = pair.identity.clone(); |
| 441 |
return Ok(Writer::Remote { client: Box::new(spectra_mcp::client::Client::at(ep, Some(pair))), recorded }); |
| 442 |
} |
| 443 |
let db = self.db()?; |
| 444 |
if spectra_mcp::client::Client::alive(&self.socket()).await { |
| 445 |
let ledger = spectra_core::ledger::Ledger::open_read_only(&db).await?; |
| 446 |
let transport = identity::recorded_owner(&ledger, owner_home).await?; |
| 447 |
return Ok(Writer::Daemon { ledger, client: Box::new(spectra_mcp::client::Client::new(&self.socket(), Some(transport))) }); |
| 448 |
} |
| 449 |
Ok(Writer::Direct(self.writer().await?)) |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
pub fn local_only(&self, what: &str) -> Result<()> { |
| 454 |
if self.remote()?.is_some() { |
| 455 |
bail!("{what} runs on the server, which holds the ledger (this machine uses {})", connect::path().display()); |
| 456 |
} |
| 457 |
Ok(()) |
| 458 |
} |
| 459 |
|
| 460 |
|
| 461 |
pub fn config_owner_home(&self) -> Option<PathBuf> { |
| 462 |
let text = std::fs::read_to_string(self.data.join("spectra.toml")).ok()?; |
| 463 |
let t: toml::Table = text.parse().ok()?; |
| 464 |
t.get("owner")?.get("home")?.as_str().map(PathBuf::from) |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
pub enum Writer { |
| 470 |
Direct(spectra_core::ledger::Ledger), |
| 471 |
Daemon { |
| 472 |
ledger: spectra_core::ledger::Ledger, |
| 473 |
client: Box<spectra_mcp::client::Client>, |
| 474 |
}, |
| 475 |
|
| 476 |
Remote { |
| 477 |
client: Box<spectra_mcp::client::Client>, |
| 478 |
recorded: spectra_core::identity::Identity, |
| 479 |
}, |
| 480 |
} |
| 481 |
|
| 482 |
impl Writer { |
| 483 |
|
| 484 |
pub fn ledger(&self) -> Option<&spectra_core::ledger::Ledger> { |
| 485 |
match self { |
| 486 |
Writer::Direct(l) | Writer::Daemon { ledger: l, .. } => Some(l), |
| 487 |
Writer::Remote { .. } => None, |
| 488 |
} |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
pub fn client(&self) -> Option<&spectra_mcp::client::Client> { |
| 493 |
match self { |
| 494 |
Writer::Daemon { client, .. } | Writer::Remote { client, .. } => Some(client), |
| 495 |
Writer::Direct(_) => None, |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
pub async fn refresh_event(&self, home: &std::path::Path) -> Result<Option<spectra_core::event::NewEvent>> { |
| 502 |
match self { |
| 503 |
Writer::Direct(l) | Writer::Daemon { ledger: l, .. } => identity::refresh_event(l, home).await, |
| 504 |
Writer::Remote { recorded, .. } => identity::rotation(recorded, home), |
| 505 |
} |
| 506 |
} |
| 507 |
|
| 508 |
|
| 509 |
pub async fn append(&self, events: Vec<spectra_core::event::NewEvent>) -> Result<()> { |
| 510 |
match self { |
| 511 |
Writer::Direct(l) => { |
| 512 |
l.append(events).await?; |
| 513 |
l.checkpoint().await?; |
| 514 |
} |
| 515 |
Writer::Daemon { client, .. } | Writer::Remote { client, .. } => { |
| 516 |
let wire: Vec<_> = events.iter().map(spectra_core::daemon::WireEvent::from_new).collect(); |
| 517 |
let r = client.send("POST", "/api/v1/ledger/events", &[], serde_json::to_vec(&wire)?).await?; |
| 518 |
if r.status != 200 { |
| 519 |
let why = r |
| 520 |
.json() |
| 521 |
.ok() |
| 522 |
.and_then(|v| v.get("title").and_then(|t| t.as_str()).map(String::from)) |
| 523 |
.unwrap_or_else(|| String::from_utf8_lossy(&r.body).into()); |
| 524 |
bail!("the daemon refused: {why}"); |
| 525 |
} |
| 526 |
} |
| 527 |
} |
| 528 |
Ok(()) |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
async fn remote_owner(ep: &spectra_mcp::client::Endpoint, home: &std::path::Path) -> Result<spectra_core::keys::KeyPair> { |
| 535 |
let r = spectra_mcp::client::Client::at(ep.clone(), None).send("GET", "/api/v1/instance", &[], vec![]).await?; |
| 536 |
let info = r.json()?; |
| 537 |
let key = info.get("owner").and_then(|o| o.as_str()).context("the server has no owner yet: spectra connect claims it")?; |
| 538 |
let keys = home.join("keys"); |
| 539 |
spectra_core::keys::KeyPair::load(&keys.join(format!("{key}.secret")), &keys.join(format!("{key}.identity"))) |
| 540 |
.with_context(|| format!("the server's owner {} is not an identity in {}", &key[..12.min(key.len())], home.display())) |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
pub async fn call(c: &spectra_mcp::client::Client, method: &str, path: &str, body: Option<serde_json::Value>) -> Result<serde_json::Value> { |
| 545 |
let r = c.send(method, path, &[], body.map(|b| serde_json::to_vec(&b)).transpose()?.unwrap_or_default()).await?; |
| 546 |
let v: serde_json::Value = r.json().unwrap_or(serde_json::Value::Null); |
| 547 |
if r.status >= 400 { |
| 548 |
let why = v |
| 549 |
.get("detail") |
| 550 |
.or(v.get("title")) |
| 551 |
.and_then(serde_json::Value::as_str) |
| 552 |
.map(String::from) |
| 553 |
.unwrap_or_else(|| String::from_utf8_lossy(&r.body).into()); |
| 554 |
bail!("{why}"); |
| 555 |
} |
| 556 |
Ok(v) |
| 557 |
} |
| 558 |
|
| 559 |
|
| 560 |
pub fn encode(s: &str) -> String { |
| 561 |
s.bytes() |
| 562 |
.map(|b| match b { |
| 563 |
b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => (b as char).to_string(), |
| 564 |
_ => format!("%{b:02X}"), |
| 565 |
}) |
| 566 |
.collect() |
| 567 |
} |
| 568 |
|
| 569 |
fn init_logging() { |
| 570 |
let filter = tracing_subscriber::EnvFilter::try_from_env("SPECTRA_LOG").unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("warn")); |
| 571 |
tracing_subscriber::fmt().with_env_filter(filter).with_writer(std::io::stderr).init(); |
| 572 |
} |
| 573 |
|
| 574 |
fn default_data() -> PathBuf { |
| 575 |
if let Ok(x) = std::env::var("XDG_DATA_HOME") { |
| 576 |
return PathBuf::from(x).join("spectra"); |
| 577 |
} |
| 578 |
let home = std::env::var("HOME").unwrap_or_else(|_| ".".into()); |
| 579 |
PathBuf::from(home).join(".local").join("share").join("spectra") |
| 580 |
} |
| 581 |
|
| 582 |
fn runtime() -> Result<tokio::runtime::Runtime> { |
| 583 |
Ok(tokio::runtime::Builder::new_multi_thread().enable_all().build()?) |
| 584 |
} |
| 585 |
|
| 586 |
pub fn run() -> Result<i32> { |
| 587 |
let cli = Cli::parse(); |
| 588 |
ui::init(cli.plain); |
| 589 |
let ctx = Ctx { data: cli.data.unwrap_or_else(default_data) }; |
| 590 |
match cli.command { |
| 591 |
Command::Version { json } => version(json), |
| 592 |
Command::Status { json } => runtime()?.block_on(setup::status(&ctx, json)), |
| 593 |
Command::Probe { url, json } => runtime()?.block_on(setup::probe(&url, json)), |
| 594 |
Command::Bridge { port, owner_home } => runtime()?.block_on(setup::bridge(&ctx, port, owner_home)), |
| 595 |
Command::Brief { command } => runtime()?.block_on(async { |
| 596 |
match command { |
| 597 |
BriefCmd::Show { project, json } => brief::show(&ctx, project, json).await, |
| 598 |
BriefCmd::Set { project, text, file, owner_home } => { |
| 599 |
brief::set(&ctx, project, brief::text_of(text, file)?, owner_home).await |
| 600 |
} |
| 601 |
BriefCmd::Edit { project, owner_home } => brief::edit(&ctx, project, owner_home).await, |
| 602 |
} |
| 603 |
}), |
| 604 |
Command::Connect { url, owner_home, expect, yes } => runtime()?.block_on(connect::connect(&ctx, &url, owner_home, expect, yes)), |
| 605 |
Command::Init { owner_home, name, owner: Some(key) } => { |
| 606 |
let _ = owner_home; |
| 607 |
runtime()?.block_on(identity::init_for(&ctx, &key, name)) |
| 608 |
} |
| 609 |
Command::Init { owner_home, name, owner: None } => runtime()?.block_on(identity::init(&ctx, owner_home, name)), |
| 610 |
Command::Identity { command } => runtime()?.block_on(async { |
| 611 |
match command { |
| 612 |
IdentityCmd::Create { name, contact, home, json } => identity::create(&name, &contact, home, json), |
| 613 |
IdentityCmd::Show { json } => identity::show(&ctx, json).await, |
| 614 |
IdentityCmd::Refresh { owner_home } => identity::refresh(&ctx, owner_home).await, |
| 615 |
} |
| 616 |
}), |
| 617 |
Command::Serve { bind, tls, insecure, open } => { |
| 618 |
init_logging(); |
| 619 |
runtime()?.block_on(serve::serve(&ctx, bind, tls, insecure, open)) |
| 620 |
} |
| 621 |
Command::Open { owner_home, no_browser, port } => runtime()?.block_on(async { |
| 622 |
if ctx.remote()?.is_some() { |
| 623 |
open::open_remote(&ctx, owner_home, !no_browser, port).await |
| 624 |
} else { |
| 625 |
open::open(&ctx, owner_home, !no_browser).await |
| 626 |
} |
| 627 |
}), |
| 628 |
Command::Mcp { agent, home } => runtime()?.block_on(mcp::run(&ctx, &agent, home)), |
| 629 |
Command::Say { body, channel, reply_to, json, owner_home } => { |
| 630 |
runtime()?.block_on(human::say(&ctx, channel, reply_to, body, owner_home, json)) |
| 631 |
} |
| 632 |
Command::Inbox { follow, json, owner_home } => runtime()?.block_on(human::inbox(&ctx, follow, owner_home, json)), |
| 633 |
Command::Search { query, channel, author, since, limit, json } => { |
| 634 |
runtime()?.block_on(human::search(&ctx, &query, channel, author, since, limit, json)) |
| 635 |
} |
| 636 |
Command::Api { method, path, body, owner_home } => runtime()?.block_on(human::raw(&ctx, &method, &path, body, owner_home)), |
| 637 |
Command::Project { command } => runtime()?.block_on(async { |
| 638 |
match command { |
| 639 |
ProjectCmd::Add { target, name, path, description, url, owner_home } => { |
| 640 |
project::add(&ctx, project::Add { target, name, path, description, url }, owner_home).await |
| 641 |
} |
| 642 |
ProjectCmd::Link { project, depends_on, remove, owner_home } => { |
| 643 |
project::link(&ctx, &project, &depends_on, remove, owner_home).await |
| 644 |
} |
| 645 |
ProjectCmd::List { json } => project::list(&ctx, json).await, |
| 646 |
} |
| 647 |
}), |
| 648 |
Command::Agent { command } => runtime()?.block_on(async { |
| 649 |
match command { |
| 650 |
AgentCmd::Add { name, kind, project, home, uid, learn_uid, expires, yes, owner_home } => { |
| 651 |
agent::add(&ctx, agent::Add { name, kind, project, home, uid, learn_uid, expires, yes, owner_home }).await |
| 652 |
} |
| 653 |
AgentCmd::Renew { name, expires, owner_home } => agent::renew(&ctx, &name, &expires, owner_home).await, |
| 654 |
AgentCmd::List { json } => agent::list(&ctx, json).await, |
| 655 |
AgentCmd::Disable { name, owner_home } => agent::disable(&ctx, &name, owner_home).await, |
| 656 |
} |
| 657 |
}), |
| 658 |
Command::Admin { command } => runtime()?.block_on(async { |
| 659 |
match command { |
| 660 |
Admin::Verify { json } => admin::verify(&ctx, json).await, |
| 661 |
Admin::Check => admin::check(&ctx).await, |
| 662 |
Admin::Rebuild => admin::rebuild(&ctx).await, |
| 663 |
} |
| 664 |
}), |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
fn version(as_json: bool) -> Result<i32> { |
| 669 |
if as_json { |
| 670 |
println!( |
| 671 |
"{}", |
| 672 |
serde_json::json!({ |
| 673 |
"version": env!("CARGO_PKG_VERSION"), |
| 674 |
"build": env!("SPECTRA_BUILD_ID"), |
| 675 |
"mcp_protocol_versions": spectra_mcp::PROTOCOL_VERSIONS, |
| 676 |
"ledger_format": spectra_core::LEDGER_FORMAT, |
| 677 |
}) |
| 678 |
); |
| 679 |
} else { |
| 680 |
println!("spectra {}", env!("SPECTRA_VERSION_LONG")); |
| 681 |
} |
| 682 |
Ok(0) |
| 683 |
} |