feat(ai): name agents after their model, not hardcoded "oracle"

Agents now join under their model tag (e.g. "qwen2.5:3b" — model name +
parameter size) or profile label, derived at /ai start and tracked on
App.agent_name, so the roster shows what's actually answering. Updates the
broker re-grant + /ai stop revoke paths, the Python --name default
(falls back to provider.model), and the demo/bootstrap/README/docs refs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
leetcrypt
2026-06-06 17:26:17 -07:00
parent 3a54578f0a
commit 9222fa8ad7
8 changed files with 44 additions and 32 deletions
+18 -12
View File
@@ -161,9 +161,6 @@ pub struct PendingVm {
pub needs_install: bool,
}
/// Display handle the summoned Python agent joins under (see `spawn_agent`).
const AGENT_NAME: &str = "oracle";
pub struct App {
pub me: String,
pub lines: Vec<ChatLine>,
@@ -212,6 +209,11 @@ pub struct App {
/// (`/ai start <name> allow`). Re-applied in the broker Ready handler, since
/// launching a sandbox resets the ACL back to just the owner.
pub agent_sbx_allow: bool,
/// Display name the summoned agent joined under — derived from its model or
/// profile at `/ai start` (e.g. "qwen2.5:3b", model name + parameter size).
/// Tracked so the broker Ready handler can re-grant its drive and `/ai stop`
/// can revoke the right ACL entry.
pub agent_name: Option<String>,
}
impl App {
@@ -244,6 +246,7 @@ impl App {
ai_stream: std::collections::HashMap::new(),
spin: 0,
agent_sbx_allow: false,
agent_name: None,
}
}
@@ -1085,7 +1088,9 @@ pub async fn run(params: net::ConnParams, mut session: Session, mut theme: Theme
app.sudoers.insert(app.me.clone()); // owner = superuser
if app.agent_sbx_allow {
// Re-apply a `/ai start … allow` grant the launch reset.
app.drivers.insert(AGENT_NAME.to_string());
if let Some(n) = &app.agent_name {
app.drivers.insert(n.clone());
}
}
send_frame(&out_tx, &session.room, json!({
"_sbx":"status","state":"ready","backend": backend.label(), "rows": rows, "cols": cols
@@ -1722,7 +1727,10 @@ fn handle_command(
app.sys("⛧ dismissed the AI agent");
// Drop any sandbox drive the agent held so a dead handle can't act.
app.agent_sbx_allow = false;
let revoked = app.drivers.remove(AGENT_NAME) | app.sudoers.remove(AGENT_NAME);
let revoked = app
.agent_name
.take()
.is_some_and(|n| app.drivers.remove(&n) | app.sudoers.remove(&n));
if revoked && app.sandbox.is_some() {
broadcast_acl(out_tx, room, app);
}
@@ -1749,12 +1757,6 @@ fn handle_command(
Some(head) if head.is_empty() || head.ends_with(' ') => (head.trim(), true),
_ => (raw, false),
};
// Tolerate a leading agent-name token (`/ai start oracle allow`):
// there's only one agent, so treat it as addressing, not a profile.
let raw = match raw.strip_prefix(AGENT_NAME) {
Some(rest) if rest.is_empty() || rest.starts_with(' ') => rest.trim(),
_ => raw,
};
// A bare name (no ':' tag, no '/' path) is a models.toml profile;
// anything else is treated as a literal Ollama model tag.
let (profile, model): (Option<&str>, &str) = if raw.is_empty() {
@@ -1764,10 +1766,14 @@ fn handle_command(
} else {
(Some(raw), raw)
};
let name = AGENT_NAME;
// Name the agent after what it runs, for clarity in the roster: a
// profile keeps its label; a direct Ollama model uses its tag
// (e.g. "qwen2.5:3b" — model name + parameter size).
let name = profile.unwrap_or(model);
match spawn_agent(params, &app.password, name, profile, model) {
Ok(child) => {
*agent = Some(child);
app.agent_name = Some(name.to_string());
app.agent_sbx_allow = grant_sbx;
let desc = match profile {
Some(p) => format!("profile {p}"),
+2 -1
View File
@@ -567,7 +567,8 @@ fn draw_roster(f: &mut Frame, area: ratatui::layout::Rect, app: &App, theme: &Th
f.render_widget(roster, area);
}
/// Animated "⠋ oracle is thinking…" title shown while AI agents generate a reply.
/// Animated "⠋ <agent> is thinking…" title shown while AI agents generate a
/// reply. The name(s) come from `app.ai_typing`, i.e. each agent's own handle.
fn ai_thinking_title(app: &App) -> String {
const FRAMES: [&str; 10] = ["", "", "", "", "", "", "", "", "", ""];
let glyph = FRAMES[(app.spin / 2) % FRAMES.len()];