nikivdev/code · error

Agent '{}' not found

Error message

Agent '{}' not found

What it means

edit_agent looks up an agent spec file by name via find_agent_spec and throws this error when no spec matches the given name. It is thrown before launching $EDITOR so the editor is never opened for a nonexistent agent.

Source

Thrown at src/hive.rs:399

#
# Rules:
# - <rule 1>
# - <rule 2>
#
# Tools:
# - bash
"#,
        name
    );

    fs::write(&path, template)?;
    Ok(path)
}

/// Edit an agent spec file
pub fn edit_agent(name: &str) -> Result<()> {
    let (path, _source) =
        find_agent_spec(name).ok_or_else(|| anyhow::anyhow!("Agent '{}' not found", name))?;

    let editor = std::env::var("EDITOR").unwrap_or_else(|_| "vim".to_string());
    let status = Command::new(&editor)
        .arg(&path)
        .stdin(Stdio::inherit())
        .stdout(Stdio::inherit())
        .stderr(Stdio::inherit())
        .status()
        .context(format!("Failed to open editor '{}'", editor))?;

    if !status.success() {
        anyhow::bail!("Editor exited with status {:?}", status.code());
    }

    Ok(())
}

/// List agents in a formatted table

View on GitHub (pinned to a747e741ae)

Solutions

  1. List available agents (hive agent list or inspect the specs dir) and use the exact name
  2. Create the agent spec first, then edit it
  3. Run from the project root where the agent spec is defined

Example fix

// before
f hive agent edit myagent   # Agent 'myagent' not found
// after
f hive agent list           # shows: my-agent
f hive agent edit my-agent
Defensive patterns

Strategy: validation

Validate before calling

fn agent_exists(name: &str) -> bool { find_agent_spec(name).is_some() }
if !agent_exists(name) {
    eprintln!("unknown agent '{}'; list agents first", name);
    return Ok(());
}

Try / catch

if let Err(e) = edit_agent(name) {
    if e.to_string().starts_with("Agent '") {
        eprintln!("{} — create it with `f hive agent new {}`", e, name);
    } else { return Err(e.into()); }
}

Prevention

When it happens

Trigger: Calling edit_agent (the hive agent-edit command) with a name that matches no agent spec file in any search location (local project, global specs).

Common situations: Typo in agent name, agent spec deleted or renamed, running from a directory where the agent isn't defined, expecting fuzzy matching that doesn't exist.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of nikivdev/code@a747e741ae (2026-09-01). Data as JSON: /api/errors/6b1a839d49622217. Report an issue: GitHub.