Files
archy/core/archipelago/src/assistant/backends/scripted.rs
T
archipelagoandClaude Opus 5 fe6ccff73c feat(13-01): Rust assistant spine — one curated tool, one backend, one RPC surface
D-01/D-02/D-06 tracer slice: a new crate::assistant module (CallerScope,
PermissionCategory, ToolExecCtx, chat()) runs a multi-turn tool-calling loop
(run_loop/execute_tool, MAX_TURNS=8) against a curated single-tool registry
(system_disk_status, hand-written JSON Schema — no schemars) via a Claude
Messages API backend. execute_tool is the single choke point: unknown tools
are refused not ignored, D-16 category grants are re-checked even though the
system prompt already omits ungranted tools, and every real tool dispatches
through the SAME handle_system_disk_status RPC handler every other
authenticated caller uses (assistant_dispatch_tool bridge in
api/rpc/assistant_chat.rs) — never an AI-only backdoor.

assistant.chat is registered in dispatcher.rs as a single guarded
`m if m.starts_with("assistant.")` arm reached only after the existing
session-cookie + CSRF + role.can_access() gate in api/rpc/mod.rs — asserted
directly by assistant_methods_require_session against the live
UNAUTHENTICATED_METHODS list (visibility only widened to pub(crate) for that
assertion; the list's contents are untouched, per the Phase-10 hard
constraint).

Key read from data_dir/secrets/claude-api-key — the same path
mesh/rpc/mesh/assistant.rs already probes — never a second key location.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-03 14:37:16 -04:00

45 lines
1.2 KiB
Rust

//! Test-only backend that replays a canned sequence of turns. Never
//! compiles into the shipped binary — gated by `#![cfg(test)]` here AND by
//! `#[cfg(test)] pub mod scripted;` in `backends/mod.rs`.
#![cfg(test)]
use std::sync::Mutex;
use anyhow::Result;
use async_trait::async_trait;
use super::{Backend, BackendTurn};
use crate::assistant::tools::{ChatMessage, ToolDef};
pub struct ScriptedBackend {
turns: Mutex<Vec<BackendTurn>>,
}
impl ScriptedBackend {
/// `turns` are consumed in the order given — the first call to `send()`
/// returns `turns[0]`, the second `turns[1]`, and so on.
pub fn new(turns: Vec<BackendTurn>) -> Self {
let mut turns = turns;
turns.reverse();
Self {
turns: Mutex::new(turns),
}
}
}
#[async_trait]
impl Backend for ScriptedBackend {
async fn send(
&self,
_system: &str,
_tools: &[ToolDef],
_history: &[ChatMessage],
) -> Result<BackendTurn> {
let mut turns = self.turns.lock().expect("ScriptedBackend mutex poisoned");
turns
.pop()
.ok_or_else(|| anyhow::anyhow!("ScriptedBackend exhausted — no more turns queued"))
}
}