whoami: new mcp tool returning name/role/pronouns/hyperhive_rev on both surfaces
This commit is contained in:
parent
4ec401a6c7
commit
3c66cb6707
9 changed files with 142 additions and 14 deletions
|
|
@ -236,7 +236,8 @@ async fn serve(
|
|||
| AgentResponse::Recent { .. }
|
||||
| AgentResponse::QuestionQueued { .. }
|
||||
| AgentResponse::OpenThreads { .. }
|
||||
| AgentResponse::PendingRemindersCount { .. },
|
||||
| AgentResponse::PendingRemindersCount { .. }
|
||||
| AgentResponse::Whoami { .. },
|
||||
) => {
|
||||
tracing::warn!("recv produced unexpected response kind");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,7 +204,8 @@ async fn serve(
|
|||
| ManagerResponse::Recent { .. }
|
||||
| ManagerResponse::Logs { .. }
|
||||
| ManagerResponse::OpenThreads { .. }
|
||||
| ManagerResponse::PendingRemindersCount { .. },
|
||||
| ManagerResponse::PendingRemindersCount { .. }
|
||||
| ManagerResponse::Whoami { .. },
|
||||
) => {
|
||||
tracing::warn!("recv produced unexpected response kind");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,12 @@ pub enum SocketReply {
|
|||
Logs(String),
|
||||
OpenThreads(Vec<hive_sh4re::OpenThread>),
|
||||
PendingRemindersCount(u64),
|
||||
Whoami {
|
||||
name: String,
|
||||
role: String,
|
||||
operator_pronouns: String,
|
||||
hyperhive_rev: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
impl From<hive_sh4re::AgentResponse> for SocketReply {
|
||||
|
|
@ -58,6 +64,17 @@ impl From<hive_sh4re::AgentResponse> for SocketReply {
|
|||
hive_sh4re::AgentResponse::PendingRemindersCount { count } => {
|
||||
Self::PendingRemindersCount(count)
|
||||
}
|
||||
hive_sh4re::AgentResponse::Whoami {
|
||||
name,
|
||||
role,
|
||||
operator_pronouns,
|
||||
hyperhive_rev,
|
||||
} => Self::Whoami {
|
||||
name,
|
||||
role,
|
||||
operator_pronouns,
|
||||
hyperhive_rev,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -77,6 +94,17 @@ impl From<hive_sh4re::ManagerResponse> for SocketReply {
|
|||
hive_sh4re::ManagerResponse::PendingRemindersCount { count } => {
|
||||
Self::PendingRemindersCount(count)
|
||||
}
|
||||
hive_sh4re::ManagerResponse::Whoami {
|
||||
name,
|
||||
role,
|
||||
operator_pronouns,
|
||||
hyperhive_rev,
|
||||
} => Self::Whoami {
|
||||
name,
|
||||
role,
|
||||
operator_pronouns,
|
||||
hyperhive_rev,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -156,6 +184,28 @@ pub fn format_open_threads(resp: Result<SocketReply, anyhow::Error>) -> String {
|
|||
out
|
||||
}
|
||||
|
||||
/// Format helper for `whoami`: renders the identity block as a short
|
||||
/// human-readable string. Skips fields that are `None` so the output
|
||||
/// doesn't carry dead placeholders.
|
||||
pub fn format_whoami(resp: Result<SocketReply, anyhow::Error>) -> String {
|
||||
match resp {
|
||||
Ok(SocketReply::Whoami {
|
||||
name,
|
||||
role,
|
||||
operator_pronouns,
|
||||
hyperhive_rev,
|
||||
}) => {
|
||||
let rev = hyperhive_rev.as_deref().unwrap_or("<unknown>");
|
||||
format!(
|
||||
"name: {name}\nrole: {role}\noperator_pronouns: {operator_pronouns}\nhyperhive_rev: {rev}"
|
||||
)
|
||||
}
|
||||
Ok(SocketReply::Err(m)) => format!("whoami failed: {m}"),
|
||||
Ok(other) => format!("whoami unexpected response: {other:?}"),
|
||||
Err(e) => format!("whoami transport error: {e:#}"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Common envelope around every MCP tool handler: pre-log → run →
|
||||
/// post-log. The inbox-status hint used to be appended to every tool
|
||||
/// result; that lives in the wake prompt + UI header now, so tool
|
||||
|
|
@ -395,6 +445,22 @@ impl AgentServer {
|
|||
.await
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Self-introspection: returns your own canonical agent name (the \
|
||||
socket-identity name, NOT the prompt-substituted label), role (`agent`), the \
|
||||
operator's pronouns, and the current hyperhive rev hive-c0re is running against. \
|
||||
No args. Useful when you want a trustworthy identity stamp for state files / \
|
||||
commit messages / cross-agent attribution that won't drift across renames or \
|
||||
session-continue boundaries where the system-prompt label could be stale."
|
||||
)]
|
||||
async fn whoami(&self) -> String {
|
||||
run_tool_envelope("whoami", String::new(), async move {
|
||||
let (resp, retries) = self.dispatch(hive_sh4re::AgentRequest::Whoami).await;
|
||||
annotate_retries(format_whoami(resp), retries)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Schedule a reminder that lands in this agent's own inbox at a future \
|
||||
time (sender will appear as `reminder`). Use for self-paced follow-ups: 'check task \
|
||||
|
|
@ -879,6 +945,20 @@ impl ManagerServer {
|
|||
.await
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Self-introspection for the manager: returns canonical name \
|
||||
(`manager`), role (`manager`), operator pronouns, and the current hyperhive rev. \
|
||||
Same shape as the agent flavour; useful for cross-agent attribution / boot \
|
||||
announcements / state-file headers without trusting prompt substitution."
|
||||
)]
|
||||
async fn whoami(&self) -> String {
|
||||
run_tool_envelope("whoami", String::new(), async move {
|
||||
let (resp, retries) = self.dispatch(hive_sh4re::ManagerRequest::Whoami).await;
|
||||
annotate_retries(format_whoami(resp), retries)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Fetch recent journal log lines for a sub-agent container. Useful \
|
||||
for diagnosing MCP server registration failures, startup crashes, plugin install \
|
||||
|
|
@ -923,8 +1003,9 @@ impl ManagerServer {
|
|||
sub-agent — non-blocking, answer arrives later as a `question_answered` event), \
|
||||
`answer` (respond to a `question_asked` event directed at you), \
|
||||
`get_open_threads` (hive-wide loose ends — pending approvals + unanswered \
|
||||
questions across the swarm). The manager's own config lives at \
|
||||
`/agents/hm1nd/config/agent.nix`."
|
||||
questions across the swarm), `whoami` (self-introspection — canonical name, \
|
||||
role, operator pronouns, current hyperhive rev). The manager's own config \
|
||||
lives at `/agents/hm1nd/config/agent.nix`."
|
||||
)]
|
||||
impl ServerHandler for ManagerServer {}
|
||||
|
||||
|
|
@ -958,7 +1039,15 @@ pub enum Flavor {
|
|||
#[must_use]
|
||||
pub fn allowed_mcp_tools(flavor: Flavor) -> Vec<String> {
|
||||
let names: &[&str] = match flavor {
|
||||
Flavor::Agent => &["send", "recv", "ask", "answer", "remind", "get_open_threads"],
|
||||
Flavor::Agent => &[
|
||||
"send",
|
||||
"recv",
|
||||
"ask",
|
||||
"answer",
|
||||
"remind",
|
||||
"get_open_threads",
|
||||
"whoami",
|
||||
],
|
||||
Flavor::Manager => &[
|
||||
"send",
|
||||
"recv",
|
||||
|
|
@ -973,6 +1062,7 @@ pub fn allowed_mcp_tools(flavor: Flavor) -> Vec<String> {
|
|||
"get_logs",
|
||||
"get_open_threads",
|
||||
"remind",
|
||||
"whoami",
|
||||
],
|
||||
};
|
||||
let mut out: Vec<String> = names
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue