phase 8 step 3: needs-login partial-run mode + dashboard badge

This commit is contained in:
müde 2026-05-15 12:57:06 +02:00
parent c59fa8541c
commit 78fae44ee5
7 changed files with 191 additions and 11 deletions

View file

@ -4,10 +4,12 @@
//! plus a `serve` loop that logs the manager's inbox.
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::time::Duration;
use anyhow::{Result, bail};
use clap::{Parser, Subcommand};
use hive_ag3nt::login::{self, LoginState};
use hive_ag3nt::{DEFAULT_SOCKET, DEFAULT_WEB_PORT, client, web_ui};
use hive_sh4re::{HelperEvent, ManagerRequest, ManagerResponse, SYSTEM_SENDER};
@ -59,12 +61,26 @@ async fn main() -> Result<()> {
.and_then(|s| s.parse::<u16>().ok())
.unwrap_or(DEFAULT_WEB_PORT);
let label = std::env::var("HIVE_LABEL").unwrap_or_else(|_| "hm1nd".into());
let claude_dir = PathBuf::from(login::DEFAULT_CLAUDE_DIR);
let initial = LoginState::from_dir(&claude_dir);
tracing::info!(state = ?initial, claude_dir = %claude_dir.display(), "hm1nd boot");
let login_state = Arc::new(Mutex::new(initial));
let ui_state = login_state.clone();
tokio::spawn(async move {
if let Err(e) = web_ui::serve(label, port).await {
if let Err(e) = web_ui::serve(label, port, ui_state).await {
tracing::error!(error = ?e, "web ui failed");
}
});
serve(&cli.socket, Duration::from_millis(poll_ms)).await
match initial {
LoginState::Online => serve(&cli.socket, Duration::from_millis(poll_ms)).await,
LoginState::NeedsLogin => {
tracing::warn!(
claude_dir = %claude_dir.display(),
"manager has no claude session — staying in partial-run mode"
);
needs_login_loop(&cli.socket, &claude_dir, login_state, poll_ms).await
}
}
}
Cmd::Send { to, body } => one_shot(&cli.socket, ManagerRequest::Send { to, body }).await,
Cmd::Recv => one_shot(&cli.socket, ManagerRequest::Recv).await,
@ -91,6 +107,25 @@ async fn one_shot(socket: &Path, req: ManagerRequest) -> Result<()> {
Ok(())
}
/// Manager-side mirror of hive-ag3nt's needs-login loop: keep the web UI
/// alive, poll the claude dir, enter `serve` once login lands.
async fn needs_login_loop(
socket: &Path,
claude_dir: &Path,
state: Arc<Mutex<LoginState>>,
poll_ms: u64,
) -> Result<()> {
let probe = Duration::from_millis(poll_ms.max(2000));
loop {
tokio::time::sleep(probe).await;
if login::has_session(claude_dir) {
tracing::info!("manager claude session detected — entering inbox loop");
*state.lock().unwrap() = LoginState::Online;
return serve(socket, Duration::from_millis(poll_ms)).await;
}
}
}
async fn serve(socket: &Path, interval: Duration) -> Result<()> {
tracing::info!(socket = %socket.display(), "hive-m1nd serve");
loop {