Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
dbd8efe
test(storage): cover running turn call records and legacy snapshots
senamakel Nov 25, 2026
0228117
feat(storage): record identified calls on running turns
senamakel Nov 25, 2026
b84b6a9
test(storage): qualify BTreeMap path in retention test
senamakel Nov 25, 2026
f74d14d
test(storage): rename running turn test to describe empty calls
senamakel Nov 25, 2026
eafc9a7
test(coordinator): add tests for hive call handling
senamakel Nov 25, 2026
1a403f6
test(coordinator): simplify retry test setup and teardown
senamakel Nov 25, 2026
d393ed3
refactor(coordinator): extract state mutation helpers from coordinato…
senamakel Nov 25, 2026
5472a78
refactor(coordinator): remove redundant reference in hive comparison
senamakel Nov 25, 2026
830dac3
refactor(coordinator): extract message admission and acceptance helpers
senamakel Nov 25, 2026
73d6b48
feat(coordinator): add identified turn calls with replay and reuse ch…
senamakel Nov 25, 2026
8c3ed09
feat(coordinator): add calls module for coordinator hive
senamakel Nov 25, 2026
fcd536e
test(coordinator): import CallRecord in calls test module
senamakel Nov 25, 2026
ad3aa26
test(coordinator): hold only the first turn in the holding helper
senamakel Nov 25, 2026
7343964
refactor(storage): add constructor for freshly claimed running turns
senamakel Nov 25, 2026
94e0cdf
test(coordinator): use assert_eq for empty collection checks
senamakel Nov 25, 2026
a26a2fb
docs(hives): document identified turn calls
senamakel Nov 25, 2026
5dd0c26
feat(host): add identified tool test module
senamakel Nov 25, 2026
31dc4e3
test(tools): register identified test module
senamakel Nov 25, 2026
a8354ed
feat(tools): route identified tool calls through coordinator turn calls
senamakel Nov 25, 2026
33e3a7f
test(hook): cover tool matcher lookups on a runner
senamakel Nov 25, 2026
c665df3
feat(hook): add matches_tool to check whether a tool has hooks
senamakel Nov 25, 2026
39f77b8
feat(mcp): add tinyhivemind-mcp crate to the workspace
senamakel Nov 25, 2026
b1f750d
test(mcp): add shared support module for integration tests
senamakel Nov 25, 2026
56ce235
test(mcp): add http transport integration tests
senamakel Nov 25, 2026
997a70b
test(mcp): add settle and written helpers to the hive test support
senamakel Nov 25, 2026
3175248
test(mcp): add tool and hook fixture builders
senamakel Nov 25, 2026
6d52c48
test(mcp): add end-to-end tests for programs and seats
senamakel Nov 25, 2026
5a1ab56
test(tinyhivemind-mcp): drop unused request receiver in test harness
senamakel Nov 25, 2026
cf904e1
feat(mcp): add error type for the MCP server
senamakel Nov 25, 2026
3a4fccd
feat(seat): add bearer token seat authentication
senamakel Nov 25, 2026
87cfb3e
feat(seat): add seat module for MCP server
senamakel Nov 25, 2026
ed659d2
feat(mcp): add tools module
senamakel Nov 25, 2026
6159f3a
feat(mcp): add ledger tool for recording and querying entries
senamakel Nov 25, 2026
f532fe4
feat(mcp): add gate tool for approval checkpoints
senamakel Nov 25, 2026
9e96d5e
feat(mcp): add tool dispatch module
senamakel Nov 25, 2026
fb385a5
feat(mcp): add server module
senamakel Nov 25, 2026
16e4855
refactor(mcp): read header timeout from shared options
senamakel Nov 25, 2026
43967b2
feat(mcp): add http server module for mcp transport
senamakel Nov 25, 2026
60809be
feat(mcp): add rpc module for server request handling
senamakel Nov 25, 2026
cad73d7
feat(mcp): add seat-scoped tool server with HTTP transport
senamakel Nov 25, 2026
8f60877
test(http): cover host header validation with multiple headers
senamakel Nov 25, 2026
ff71a88
fix(mcp): reject requests carrying more than one Host header
senamakel Nov 25, 2026
e5c88a8
feat(mcp): add tinyhivemind-mcp crate to the workspace
senamakel Nov 25, 2026
36ef0cc
docs: document the mcp crate and in-turn tool calls
senamakel Nov 25, 2026
7d54319
docs(specs): record what the MCP server settled and how calls are rec…
senamakel Nov 25, 2026
56999f3
refactor(mcp): flatten admission result handling in http server
senamakel Nov 25, 2026
0b562ca
test(mcp): build tool fixture args after json literal
senamakel Nov 25, 2026
b8b0e34
chore(deps): refresh unused patch entries in lockfile
senamakel Nov 25, 2026
0f31431
chore(deps): refresh lockfile patch entries
senamakel Nov 25, 2026
930afb5
test(seat): add unit and policy tests for bearer and send policy
senamakel Nov 26, 2026
a9d91d1
test(policy): rename local variable in send policy test
senamakel Nov 26, 2026
86835ee
test(host): cover send and management policy refusals
senamakel Nov 26, 2026
cdc93b6
feat(tools): authorize tool calls before running package hooks
senamakel Nov 26, 2026
47d5fa3
chore: document new test modules and reformat dispatch signature
senamakel Nov 26, 2026
18a970e
test(mcp): add helper to hold a second turn for agent a
senamakel Nov 26, 2026
a38c9d1
test(mcp): cover approval-time turn changes and idle socket handling
senamakel Nov 26, 2026
a7a26c0
feat(host): skip re-authorization for recorded identified calls
senamakel Nov 26, 2026
7410814
feat(mcp): add schema tool for exposing tool input schemas
senamakel Nov 26, 2026
2d0a0bb
feat(ledger): bound per-seat records and reject stale turns
senamakel Nov 26, 2026
6607b53
fix(tools): validate arguments before running and record pending call…
senamakel Nov 26, 2026
570f6f0
feat(seat): honour tools.allow and reject unsupported schemas
senamakel Nov 26, 2026
cfac434
docs(tinyhivemind-mcp): document call bounds, schema checks and ledge…
senamakel Nov 26, 2026
dcb60b9
docs(error): add README for the error module
senamakel Nov 26, 2026
05bee5b
refactor(ledger): rename Turn struct to Records
senamakel Nov 26, 2026
239ec55
test(review): borrow call arguments instead of moving them
senamakel Nov 26, 2026
e50ade1
test(mcp): cover absent and unknown arguments on read tools
senamakel Nov 26, 2026
bb54fae
Merge tinyhivemind-host into hive-tool-server
sanil-23 Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/scripts/assert-pure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ set -euo pipefail
# whose vocabulary dependency includes `anyhow` and `async-trait`.
pure_crates=("tinyhivemind-core" "tinyhivemind-lang")
tool_crates=("tinyhivemind-tools")
# Host runs harnesses as processes (ADR 0035), so it may hold a runtime, but it
# must never link one.
host_crates=("tinyhivemind-host")
# Host runs harnesses as processes (ADR 0035), and the MCP server serves them
# hive tools over loopback (ADR 0036), so both may hold a runtime and a
# listener, but neither may link a harness.
host_crates=("tinyhivemind-host" "tinyhivemind-mcp")

forbidden_pure='tokio|futures|async-trait|axum|hyper|reqwest|ureq|curl|anyhow|rusqlite|git2|openhuman|tinyagents|tinytools'
# Whole families: `openhuman-embed`, `tinyagents-harness` and so on.
Expand Down
11 changes: 8 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ is not advisory — do not add an exception to it to land a change.

## Project Structure

This is a Rust 2024 virtual Cargo workspace with seven packages. Core owns all
This is a Rust 2024 virtual Cargo workspace with eight packages. Core owns all
host-neutral behavior; lang is where a hive mind is defined, integrations
included; tools renders native tool definitions and records calls; exec runs a
package's executable tools and hooks; host is the harness-neutral
half of running seats; OpenHuman is the only crate that links an agent harness,
half of running seats; mcp serves hive tools to seats that run as processes;
OpenHuman is the only crate that links an agent harness,
and it deploys hive packages.

```text
Expand All @@ -75,6 +76,7 @@ crates/
├── tinyhivemind-tools/ # native TinyTools specs and episode call record
├── tinyhivemind-exec/ # runs a package's executable tools and script hooks
├── tinyhivemind-host/ # hive tool belt, policies, package plans, harness processes
├── tinyhivemind-mcp/ # hive and package tools served to harness processes over loopback MCP
├── tinyhivemind-openhuman/ # package deployment, seat runners, host integration
├── tinyhivemind-hives/ # durable cross-hive coordinator
└── tinyhivemind-lang/ # pure hive packages: structure, integrations, edits, lineage
Expand All @@ -100,7 +102,10 @@ process. `tinyhivemind-exec` runs those executable tools and hooks
`tinyhivemind-host` depends on core, hives and lang, and owns what every harness
shares: the hive tools and their dispatch, the send and management policy ports,
turn scope and prompt, package loading, the deployment plan, and supervised
harness processes. It links no harness, and `assert-pure.sh` checks that. The
harness processes. It links no harness, and `assert-pure.sh` checks that.
`tinyhivemind-mcp` depends on host, hives, lang and exec, and serves those
tools, a package's executable tools and its hooks over Streamable HTTP on
127.0.0.1, one bearer per seat (ADR 0036); it links no harness either. The
OpenHuman adapter depends on core, hives, lang, exec and host, re-exports the
host's types under its own paths, and deploys packages
with `HiveDeployment::from_packages`; its former `HiveConfig` manifest format is
Expand Down
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ resolver = "3"
# package, each directory named for the package it holds. There is no root
# package: the crate a host links is `crates/tinyhivemind-core`, the same as any
# other member. Keeping the root virtual is what makes that uniform.
members = ["crates/tinyhivemind-core", "crates/tinyhivemind-tools", "crates/tinyhivemind-openhuman", "crates/tinyhivemind-hives", "crates/tinyhivemind-lang", "crates/tinyhivemind-exec", "crates/tinyhivemind-host"]
members = ["crates/tinyhivemind-core", "crates/tinyhivemind-tools", "crates/tinyhivemind-openhuman", "crates/tinyhivemind-hives", "crates/tinyhivemind-lang", "crates/tinyhivemind-exec", "crates/tinyhivemind-host", "crates/tinyhivemind-mcp"]
# `worktrees/` holds `git worktree` checkouts of this same repository; each
# contains a full copy of this manifest. Keep them excluded from Cargo
# workspace discovery.
Expand All @@ -31,6 +31,23 @@ tinyhivemind-exec = { path = "crates/tinyhivemind-exec" }
sha2 = "0.10"
# Harness-neutral tool belt, policies, package plans and process supervision.
tinyhivemind-host = { path = "crates/tinyhivemind-host" }
# The HTTP/1.1 server under `tinyhivemind-mcp`, which serves hive tools to
# harness processes over Streamable HTTP on loopback (ADR 0036). hyper 1 is a
# protocol implementation and no framework: no router, no TLS, no HTTP/2, no
# middleware stack, so the server's whole request surface (Host, Origin,
# bearer, body bound) is the crate's own code and nothing else is listening.
# It is already in this lockfile through the vendored harness, MIT licensed,
# and builds on 1.96. Server and HTTP/1 only; a test adds `client`.
hyper = { version = "1", default-features = false, features = ["server", "http1"] }
# hyper's tokio I/O adapter, its timer (for the header read timeout) and the
# graceful-shutdown watcher. Nothing else: no client, no auto-HTTP/2.
hyper-util = { version = "0.1", default-features = false, features = ["tokio", "http1", "server-graceful"] }
# Bounded request bodies (`Limited`) and fixed response bodies (`Full`).
http-body-util = "0.1"
# Constant-time comparison of a presented bearer with each seat's.
subtle = { version = "2", default-features = false, features = ["std"] }
# Random per-seat bearers, from the operating system.
getrandom = "0.3"
# Durable cross-hive coordinator used at the harness boundary.
tinyhivemind-hives = { path = "crates/tinyhivemind-hives" }
# Concurrent owned runner futures in the coordinator, outside core.
Expand Down
2 changes: 1 addition & 1 deletion crates/tinyhivemind-exec/src/hook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A seat's hooks: executable tools bound to an event.

| File | Holds |
| --- | --- |
| `mod.rs` | `HookRunner` (`pre_tool_use`, `post_tool_use`, `stop`, `is_empty`) and `Verdict` |
| `mod.rs` | `HookRunner` (`pre_tool_use`, `post_tool_use`, `stop`, `is_empty`, `matches_tool`) and `Verdict` |
| `matcher.rs` | `*` wildcard matching of a hook's matcher against a tool name |
| [`test/`](test/README.md) | Verdicts, matchers, order, failing hooks and event objects |

Expand Down
10 changes: 10 additions & 0 deletions crates/tinyhivemind-exec/src/hook/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ impl HookRunner {
self.hooks.is_empty()
}

/// Whether a `pre_tool_use` or `post_tool_use` hook names `tool`, so that
/// a call of it would run a hook.
#[must_use]
pub fn matches_tool(&self, tool: &str) -> bool {
self.bound(HookEvent::PreToolUse, Some(tool))
.chain(self.bound(HookEvent::PostToolUse, Some(tool)))
.next()
.is_some()
}

/// Ask the `pre_tool_use` hooks whether a call of `tool` with
/// `arguments` may run. The first refusal wins and later hooks do not run.
pub async fn pre_tool_use(&self, tool: &str, arguments: &Value) -> Verdict {
Expand Down
29 changes: 29 additions & 0 deletions crates/tinyhivemind-exec/src/hook/test/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,32 @@ fn a_star_matches_any_run_of_characters() {
assert!(!matches(Some("a*b*c"), "a__c__b"));
assert!(matches(Some("**"), "x"));
}

#[test]
fn a_runner_says_whether_a_tool_hook_names_a_tool() {
use super::support::{hook, runner};
use serde_json::json;
let dir = std::env::temp_dir();
let hooks = runner(
vec![
hook(
"guard",
"pre_tool_use",
"allow",
json!({"matcher": "git_*"}),
),
hook(
"audit",
"post_tool_use",
"record",
json!({"matcher": "deploy"}),
),
hook("end", "stop", "record", json!({})),
],
&dir,
);
assert!(hooks.matches_tool("git_push"));
assert!(hooks.matches_tool("deploy"));
// A stop hook is bound to no tool.
assert!(!hooks.matches_tool("read_file"));
}
5 changes: 5 additions & 0 deletions crates/tinyhivemind-hives/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ The host reads everything with `read_transcript`, including replies to
episode without hiding the message, and `release_with` hands a parked agent
a note on its next turn.

A host serving tools out of process identifies each state-changing call with
a `TurnCall` and uses the `*_in_turn` entry points: a retry is answered from a
record written with the effect, and a call naming a turn that is not running is
refused.

Direct sends return durable receipts without awaiting peers. `read_direct`
exposes only the caller/peer pair, including returned replies, and starts no
turn. Hive reads enforce membership and private thread audiences.
Expand Down
17 changes: 17 additions & 0 deletions crates/tinyhivemind-hives/src/coordinator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ same input. `release_with` remains the host's manual release operation.
| `settings.rs` | Per-hive native policy and retained roles, frozen at acceptance |
| `types.rs` | Host runner port and public payloads |
| `messaging.rs` | Atomic acceptance, retry IDs, starters, attribution, and private reads |
| `calls.rs` | Identified calls of a running turn: the `*_in_turn` entry points and `running_turn` |
| `observe.rs` | Host transcript, committed-revision watch, episode status |
| `conduct.rs` | Actual `CompletionDriver`/`Conductor` checkpoint lifecycle |
| `scheduler.rs` | FIFO reservations, concurrent futures, shutdown, cancellation |
Expand Down Expand Up @@ -98,3 +99,19 @@ use the driver's deterministic single-owner fallback. Native routing policy and
roles reach the routing request, and widths remain bounded, but confidence,
clarification and high-impact thresholds cannot change fallback selection.
Configuring these thresholds does not activate a model client.

## Identified calls

A host that serves tools out of process cannot tell a transport retry from a
second intended action, so a state-changing call carries a `TurnCall`: the
agent, the turn it says it belongs to, a caller-chosen `call`, and the tool and
arguments. `submit_action_in_turn`, `send_in_turn`, `create_hive_in_turn`,
`join_hive_in_turn` and `leave_hive_in_turn` check in one transaction that the
turn is the agent's running one (`StaleTurn` otherwise), answer a known `call`
with the same tool and arguments from its record without committing, refuse
any other reuse (`CallReused`), or act and record the call with its result on
the `RunningTurn`. A failed commit leaves neither. The record ends with its
turn, and a restart interrupts every running turn, so a retry after one is
refused as stale. `send_in_turn` refuses a sender other than the caller and
still checks `message_id` after `call`. The unidentified entry points are
unchanged.
158 changes: 158 additions & 0 deletions crates/tinyhivemind-hives/src/coordinator/calls.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
//! Identified calls: an action taken from a running turn, recorded with it.
//!
//! Each `*_in_turn` entry point checks the call's turn, answers a known call
//! from its record, or acts and records the call, all inside one transaction:
//! a commit holds both the effect and its record, or neither. The record lives
//! on the [`crate::RunningTurn`] and goes when the turn ends. A coordinator
//! restart interrupts every running turn, so a retry after one is refused as
//! stale rather than answered.
use super::{
Coordinator, EpisodeAction, HiveInfo, Receipt, SendMessage, TurnCall, create_hive_state,
identifier, join_hive_state, leave_hive_state,
messaging::{accept_state, admissible},
stage_action,
};
use crate::{CallRecord, Error, Result, StoredState};
use serde::{Serialize, de::DeserializeOwned};

impl Coordinator {
/// The id of `agent_id`'s running turn, if it has one.
/// # Errors
/// Returns a poisoned shared lock error.
pub fn running_turn(&self, agent_id: &str) -> Result<Option<String>> {
Ok(self
.lock()?
.durable
.running
.get(agent_id)
.map(|running| running.request.turn_id.clone()))
}
/// Whether `call` is recorded on its agent's running turn with the same
/// tool and arguments, so that an `*_in_turn` retry of it would be
/// answered from the record rather than act.
/// # Errors
/// Returns a poisoned shared lock error.
pub fn call_recorded(&self, call: &TurnCall) -> Result<bool> {
Ok(self
.lock()?
.durable
.running
.get(&call.agent_id)
.filter(|running| running.request.turn_id == call.turn_id)
.and_then(|running| running.calls.get(&call.call))
.is_some_and(|record| record.tool == call.tool && record.arguments == call.arguments))
}
/// [`Self::submit_action`] as an identified call of the caller's running turn.
/// # Errors
/// [`Error::StaleTurn`], [`Error::CallReused`], an empty identity, or the
/// errors of [`Self::submit_action`].
pub async fn submit_action_in_turn(
&self,
call: &TurnCall,
episode_id: &str,
action: EpisodeAction,
) -> Result<()> {
self.in_turn(call, |state| {
stage_action(state, &call.agent_id, episode_id, &action)
})
.await
}
/// [`Self::send`] as an identified call; the sender must be the caller.
///
/// The send's `message_id` is still checked, after `call`: two calls that
/// send one `message_id` with one payload are one message.
/// # Errors
/// [`Error::StaleTurn`], [`Error::CallReused`], an empty identity, a
/// sender other than the caller, or the errors of [`Self::send`].
pub async fn send_in_turn(&self, call: &TurnCall, request: SendMessage) -> Result<Receipt> {
if request.sender != call.agent_id {
return Err(Error::InvalidIdentifier("sender"));
}
admissible(&request)?;
let retention = self.inner.options.retention;
self.in_turn(call, |state| accept_state(state, &request, None, retention))
.await
}
/// [`Self::create_hive`] as an identified call.
/// # Errors
/// [`Error::StaleTurn`], [`Error::CallReused`], an empty identity, or the
/// errors of [`Self::create_hive`].
pub async fn create_hive_in_turn(&self, call: &TurnCall, hive: HiveInfo) -> Result<()> {
identifier(&hive.hive_id, "hive id")?;
identifier(&hive.name, "hive name")?;
self.in_turn(call, |state| create_hive_state(state, &hive))
.await
}
/// [`Self::join_hive`] as an identified call.
/// # Errors
/// [`Error::StaleTurn`], [`Error::CallReused`], an empty identity, or the
/// errors of [`Self::join_hive`].
pub async fn join_hive_in_turn(
&self,
call: &TurnCall,
hive_id: &str,
agent_id: &str,
) -> Result<()> {
self.in_turn(call, |state| join_hive_state(state, hive_id, agent_id))
.await
}
/// [`Self::leave_hive`] as an identified call.
/// # Errors
/// [`Error::StaleTurn`], [`Error::CallReused`], an empty identity, or the
/// errors of [`Self::leave_hive`].
pub async fn leave_hive_in_turn(
&self,
call: &TurnCall,
hive_id: &str,
agent_id: &str,
) -> Result<()> {
self.in_turn(call, |state| leave_hive_state(state, hive_id, agent_id))
.await
}
/// Check `call`'s turn, then answer it from its record or run `act` and
/// record it, in one transaction. A recorded answer commits nothing.
async fn in_turn<T: Serialize + DeserializeOwned>(
&self,
call: &TurnCall,
mut act: impl FnMut(&mut StoredState) -> Result<T>,
) -> Result<T> {
identifier(&call.agent_id, "agent id")?;
identifier(&call.turn_id, "turn id")?;
identifier(&call.call, "call")?;
let stale = || Error::StaleTurn {
agent_id: call.agent_id.clone(),
turn_id: call.turn_id.clone(),
};
let gate = self.inner.writer.lock().await;
let value = self
.transact(&gate, |state| {
let running = state
.running
.get(&call.agent_id)
.filter(|running| running.request.turn_id == call.turn_id)
.ok_or_else(stale)?;
if let Some(record) = running.calls.get(&call.call) {
if record.tool != call.tool || record.arguments != call.arguments {
return Err(Error::CallReused(call.call.clone()));
}
return Ok((false, serde_json::from_value(record.result.clone())?));
}
let value = act(state)?;
let record = CallRecord {
tool: call.tool.clone(),
arguments: call.arguments.clone(),
result: serde_json::to_value(&value)?,
};
state
.running
.get_mut(&call.agent_id)
.ok_or_else(stale)?
.calls
.insert(call.call.clone(), record);
Ok((true, value))
})
.await?;
self.inner.notify.notify_one();
Ok(value)
}
}
Loading
Loading