forked from vhaudiquet/rhema-claw
build: move the claw to rhema 0.4.0
The framework 0.4.0 split the toolkit: rhema-agent-tools becomes rhema-bash plus rhema-prompt, and the facade crate is deleted from the workspace this time, so the 0.3 facades never publish. The driver changes name with its types: rhema-coding-agent and its CodingAgent, CodingAgentConfig, and CodingAgentError become rhema-host-agent with HostAgent, HostAgentConfig, and HostAgentError. The claw imports the split crates directly, which drops its own vision once-lock: rhema-bash's wire already caches the process-wide answer. The paste expansion moved off the provider seam. Chips travel as the message's spans note now, and ExpandPastes is deleted: the dispatch input migrates its embedded form into plain text plus the note at run_turn, and a restashed session migrates the same way on restore, one rewrite on the way in exactly as the driver's from_session does. The transcript events keep the raw chip form, the record the web UI owns, and a migration test pins the restore path. max_turn_steps is NonZeroU32, the engine's own budget shape: a config naming zero is refused at load instead of cutting every round dead. The engine's Event and the sandbox error enum are non-exhaustive now, so the hub sink and the protocol error map carry wildcard arms that drop and fail in-band the way their neighbors do. The claw's own version travels with the framework, as the 0.3.0 move carried 0.2.3 to 0.3.0: the workspace and the chart base become 0.4.0, so the edge channel's pre-releases order above the 0.3.x line. fmt, clippy with -D warnings over all features and targets, the workspace tests, and the doc build pass.
This commit is contained in:
1 parent
dc71ac224e
commit
22c502a9eb
18 files changed
+318
-173
No files matched your search
@@ -26,33 +26,36 @@ mock = ["rhema-core/mock"]
|
||||
|
||||
[dependencies]
|
||||
# The shared toolkit: the resident agent assembles its agent from the
|
||||
# shell, the approval seam, paste expansion, and revive-on-resume
|
||||
rhema-agent-tools = "0.3.0"
|
||||
rhema-autonomous-agent = "0.3.0"
|
||||
rhema-coding-agent = "0.3.0"
|
||||
rhema-config = "0.3.0"
|
||||
rhema-core = "0.3.0"
|
||||
# shell, the approval seam, and revive-on-resume (rhema-bash), the
|
||||
# system-prompt renderer (rhema-prompt), and the driver that turns a
|
||||
# provider into a host-operating agent (rhema-host-agent)
|
||||
rhema-bash = "0.4.0"
|
||||
rhema-prompt = "0.4.0"
|
||||
rhema-host-agent = "0.4.0"
|
||||
rhema-autonomous-agent = "0.4.0"
|
||||
rhema-config = "0.4.0"
|
||||
rhema-core = "0.4.0"
|
||||
# The bounded request view over the claw sessions, on by default here
|
||||
rhema-transcript = "0.3.0"
|
||||
rhema-transcript = "0.4.0"
|
||||
rhema-calendar-integration = { path = "../../integrations/rhema-calendar-integration" }
|
||||
rhema-forge-integration = { path = "../../integrations/rhema-forge-integration" }
|
||||
# The accounts layer: identities hold the forge tokens the watches poll
|
||||
# with, and the identity tools manage them over chat
|
||||
rhema-identity = "0.3.0"
|
||||
rhema-rsd = "0.3.0"
|
||||
rhema-identity = "0.4.0"
|
||||
rhema-rsd = "0.4.0"
|
||||
# The sandbox seam: where `bash` runs, local process or a daemon speaking
|
||||
# the wire protocol over HTTP
|
||||
rhema-sandbox = "0.3.0"
|
||||
rhema-sandbox-http = "0.3.0"
|
||||
rhema-sandbox = "0.4.0"
|
||||
rhema-sandbox-http = "0.4.0"
|
||||
# The tool contract: the agent-token allowlist and version the auth
|
||||
# middleware enforces (rhema-tools spec). The arrow runs claw ->
|
||||
# contract only — never the reverse.
|
||||
rhema-claw-tools-contract = { path = "../../tools/contract" }
|
||||
# The resident tier's durable memory: its tools join the resolver chain
|
||||
rhema-memory = "0.3.0"
|
||||
rhema-memory = "0.4.0"
|
||||
# The shared ModelCard the backend registry's listings return
|
||||
rhema-provider = "0.3.0"
|
||||
rhema-provider-registry = "0.3.0"
|
||||
rhema-provider = "0.4.0"
|
||||
rhema-provider-registry = "0.4.0"
|
||||
# Args for the two-flag binary surface
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
serde = { workspace = true }
|
||||
@@ -77,7 +80,7 @@ time = { version = "0.3", default-features = false, features = ["parsing"] }
|
||||
# Inbound chat images ride base64; the dispatch decodes them into the
|
||||
# attachment store
|
||||
base64 = "0.22"
|
||||
rhema-mcp = "0.3.0"
|
||||
rhema-mcp = "0.4.0"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3"
|
||||
@@ -89,7 +92,7 @@ reqwest = { version = "0.12", features = ["json", "stream"] }
|
||||
bytes = "1"
|
||||
# The scripted provider for turn-level tests; mirrors rhema-code's mock
|
||||
# feature without a feature of our own — tests are the only consumer
|
||||
rhema-core = { version = "0.3.0", features = ["mock"] }
|
||||
rhema-core = { version = "0.4.0", features = ["mock"] }
|
||||
tokio = { workspace = true, features = ["rt-multi-thread", "macros", "sync", "time"] }
|
||||
|
||||
[lints]
|
||||
|
||||
@@ -26,9 +26,9 @@ use std::collections::BTreeMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use rhema_agent_tools::render_template;
|
||||
use rhema_autonomous_agent::{ToolError, ToolOp, ToolRegistry, async_trait};
|
||||
use rhema_core::ToolSpec;
|
||||
use rhema_prompt::render_template;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
/// The built-in system prompt, kept as data next to the code and read
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
//! binary's startup, not here — the daemon library takes the built
|
||||
//! provider, so tests can inject a mock.
|
||||
|
||||
use std::num::NonZeroU32;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -22,10 +23,13 @@ use serde::{Deserialize, Serialize};
|
||||
pub const DEFAULT_POLL_INTERVAL_SECS: u64 = 60;
|
||||
|
||||
/// How many tool rounds one chat turn may run, when
|
||||
/// [`ClawConfig::max_turn_steps`] is unset — the coding driver's own
|
||||
/// budget shape and its default: deep enough that a cap is a runaway
|
||||
/// guard for an agent meant to work unattended, not a work timer.
|
||||
pub const DEFAULT_MAX_TURN_STEPS: u32 = 2048;
|
||||
/// [`ClawConfig::max_turn_steps`] is unset — the host agent driver's
|
||||
/// own budget shape and its default: deep enough that a cap is a
|
||||
/// runaway guard for an agent meant to work unattended, not a work
|
||||
/// timer. `NonZeroU32`, the driver's own spelling: a turn cannot have
|
||||
/// no step budget at all, and a config that names zero is refused at
|
||||
/// load instead of cutting every round dead.
|
||||
pub const DEFAULT_MAX_TURN_STEPS: NonZeroU32 = NonZeroU32::new(2048).unwrap();
|
||||
|
||||
/// Where the HTTP surface listens when [`ClawConfig::listen`] is unset:
|
||||
/// loopback only — the surface is for the machine's resident user.
|
||||
@@ -130,7 +134,7 @@ pub struct ClawConfig {
|
||||
/// How many tool rounds one chat turn may run before it is cut off
|
||||
/// with a failed outcome, the conversation intact. A follow-up
|
||||
/// message keeps going. [`DEFAULT_MAX_TURN_STEPS`] when unset.
|
||||
pub max_turn_steps: u32,
|
||||
pub max_turn_steps: NonZeroU32,
|
||||
/// The handler's model backend: `google`, `llama-cpp`, `openrouter`,
|
||||
/// `anthropic`, `openai`, or `zai`; google when unset. Keys resolve
|
||||
/// through the stored rhema config's default profile, env vars
|
||||
@@ -443,7 +447,7 @@ sandbox:
|
||||
";
|
||||
let config: ClawConfig = serde_yaml::from_str(raw).expect("parses");
|
||||
assert_eq!(config.poll_interval_secs, 30);
|
||||
assert_eq!(config.max_turn_steps, 512);
|
||||
assert_eq!(config.max_turn_steps, NonZeroU32::new(512).unwrap());
|
||||
assert_eq!(config.provider.as_deref(), Some("anthropic"));
|
||||
assert_eq!(config.model.as_deref(), Some("claude-sonnet-4-5"));
|
||||
assert_eq!(config.listen.as_deref(), Some("192.168.1.10:7800"));
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
//!
|
||||
//! Session continuity rides the dispatcher, not the filesystem: the
|
||||
//! agent's session JSON is stashed into `ctx.session.core.driver_state`
|
||||
//! before the run returns and restored with [`CodingAgent::from_session`]
|
||||
//! before the run returns and restored with [`HostAgent::from_session`]
|
||||
//! on the next dispatch of the same key, so a resumed thread keeps its
|
||||
//! conversation. Commit-before-execute rides it too: the run installs the
|
||||
//! context's commit hook, so the intent is in the store before the first
|
||||
@@ -25,9 +25,8 @@ use std::sync::{Arc, Mutex, PoisonError};
|
||||
|
||||
use crate::forge::{WatchCredential, record_client, resolve_watch_credential};
|
||||
use crate::watch_store::ClawStore;
|
||||
use rhema_agent_tools::{AllowAll, ShellTools};
|
||||
use rhema_autonomous_agent::{Handler, SessionContext, async_trait};
|
||||
use rhema_coding_agent::{CodingAgent, CodingAgentConfig};
|
||||
use rhema_bash::{AllowAll, ShellTools};
|
||||
use rhema_core::{Content, Event as ModelEvent, EventSink, Message, Session};
|
||||
use rhema_forge_integration::ForgeKind;
|
||||
use rhema_forge_integration::triage::Role;
|
||||
@@ -35,6 +34,7 @@ use rhema_forge_integration::{
|
||||
EventKind, Forge, ForgeError, ForgeEvent, Notification, RepoRef, Snapshot, ThreadState, decode,
|
||||
parse_key,
|
||||
};
|
||||
use rhema_host_agent::{HostAgent, HostAgentConfig};
|
||||
use rhema_identity::IdentityStore;
|
||||
use rhema_rsd::{InboxItem, Outcome, ResourceKey};
|
||||
use tokio::sync::OnceCell;
|
||||
@@ -342,16 +342,16 @@ impl ClawHandler {
|
||||
ctx: &SessionContext,
|
||||
workspace: &Path,
|
||||
key: &str,
|
||||
) -> Result<CodingAgent, String> {
|
||||
) -> Result<HostAgent, String> {
|
||||
let (provider, model) = self.backends.current();
|
||||
let config = self.agent_config(provider, &model, workspace);
|
||||
let agent = match &ctx.session.core.driver_state {
|
||||
// A never-dispatched key carries no stash: start clean.
|
||||
serde_json::Value::Null => CodingAgent::new(config),
|
||||
serde_json::Value::Null => HostAgent::new(config),
|
||||
stashed => {
|
||||
let session: Session = serde_json::from_value(stashed.clone())
|
||||
.map_err(|err| format!("stashed session for {key} does not parse: {err}"))?;
|
||||
CodingAgent::from_session(config, session)
|
||||
HostAgent::from_session(config, session)
|
||||
}
|
||||
};
|
||||
agent.map_err(|err| format!("cannot start the coding agent for {key}: {err}"))
|
||||
@@ -367,12 +367,12 @@ impl ClawHandler {
|
||||
provider: Arc<dyn rhema_core::ModelProvider>,
|
||||
model: &str,
|
||||
workspace: &Path,
|
||||
) -> CodingAgentConfig {
|
||||
) -> HostAgentConfig {
|
||||
let display = match &self.sandbox {
|
||||
Some(sandbox) => sandbox.workspace_for(workspace),
|
||||
None => workspace.to_path_buf(),
|
||||
};
|
||||
let mut config = CodingAgentConfig::new(provider, model, &display, AllowAll);
|
||||
let mut config = HostAgentConfig::new(provider, model, &display, AllowAll);
|
||||
// Write the resolved value, not an override: the coding agent's
|
||||
// own default is on now, and the config's `false` must win.
|
||||
config.transcript = self
|
||||
@@ -1100,6 +1100,7 @@ mod tests {
|
||||
Content::Text("on it".into()),
|
||||
Content::Text(" — closing.".into()),
|
||||
],
|
||||
annotations: Default::default(),
|
||||
};
|
||||
assert_eq!(final_text(&message).as_deref(), Some("on it — closing."));
|
||||
let tool_only = Message {
|
||||
@@ -1110,6 +1111,7 @@ mod tests {
|
||||
args: serde_json::json!({}),
|
||||
provider_data: serde_json::Value::Null,
|
||||
})],
|
||||
annotations: Default::default(),
|
||||
};
|
||||
assert_eq!(final_text(&tool_only), None, "no text, no reply");
|
||||
}
|
||||
|
||||
@@ -64,16 +64,18 @@
|
||||
//! rhema-code's UI draws for a steered turn.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::num::NonZeroU32;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use rhema_agent_tools::{AllowAll, ExpandPastes, ShellTools, revive_dangling_calls};
|
||||
use rhema_autonomous_agent::{Allowlist, Handler, ResolverChain, SessionContext, async_trait};
|
||||
use rhema_bash::{AllowAll, ShellTools};
|
||||
use rhema_core::{
|
||||
Agent, ChatParams, Content, Event as ModelEvent, EventSink, Image, ImageMediaType, Message,
|
||||
ModelProvider, Role, Session, ToolContext, ToolResolver, close_orphaned_calls, run_turn,
|
||||
ModelProvider, Role, Session, ToolContext, ToolResolver, close_orphaned_calls,
|
||||
revive_dangling_calls, run_turn,
|
||||
};
|
||||
use rhema_memory::{MemoryResolver, MemoryStore, Scope};
|
||||
use rhema_rsd::{Dispatcher, Event, KeyFn, Outcome, ResourceKey};
|
||||
@@ -234,7 +236,7 @@ pub struct InteractiveHandler {
|
||||
/// How many tool rounds one turn may run before it is cut off — the
|
||||
/// config's runaway guard for an agent meant to work unattended; a
|
||||
/// follow-up message keeps going.
|
||||
max_turn_steps: u32,
|
||||
max_turn_steps: NonZeroU32,
|
||||
/// The extension set the tool half of the chain is cut from, per
|
||||
/// dispatch, in the standard set's order — the same set whose
|
||||
/// sources the daemon's tick drives and whose boot pass runs first.
|
||||
@@ -243,7 +245,7 @@ pub struct InteractiveHandler {
|
||||
/// decorator refreshes it per request, `zoom` reads it, and it
|
||||
/// lives here — the agent rebuilds per dispatch, the log must not.
|
||||
transcript_mirror: Option<Arc<std::sync::Mutex<rhema_transcript::Transcript>>>,
|
||||
/// The wired [`vision`](rhema_agent_tools::vision) section for the
|
||||
/// The wired [`vision`](rhema_bash::vision) section for the
|
||||
/// prompt, when provisioning succeeded — the same wiring whose env
|
||||
/// map lights the shell's inbox up.
|
||||
vision: Option<String>,
|
||||
@@ -271,7 +273,7 @@ impl InteractiveHandler {
|
||||
hub: Arc<EventHub>,
|
||||
notifications: Arc<NotificationStore>,
|
||||
attachments: Arc<crate::attachments::AttachmentStore>,
|
||||
max_turn_steps: u32,
|
||||
max_turn_steps: NonZeroU32,
|
||||
extensions: Arc<crate::extension::Extensions>,
|
||||
transcript: bool,
|
||||
) -> Self {
|
||||
@@ -280,7 +282,7 @@ impl InteractiveHandler {
|
||||
// chat's commands, and its staged images attach to their
|
||||
// results. Local shells only — the interactive handler's
|
||||
// executor is this host's by construction.
|
||||
let vision = rhema_agent_tools::vision::wire(std::env::var_os("BASH_ENV"));
|
||||
let vision = rhema_bash::vision::wire(std::env::var_os("BASH_ENV"));
|
||||
let tools = Arc::new(match vision {
|
||||
Some(wiring) => ShellTools::with_env(&workspace, &wiring.shell_env),
|
||||
None => ShellTools::new(&workspace),
|
||||
@@ -328,12 +330,7 @@ impl InteractiveHandler {
|
||||
/// request advertises.
|
||||
fn agent(&self, key: &ResourceKey) -> Result<Agent, String> {
|
||||
let (provider, model) = self.backends.current();
|
||||
// Chat input may carry embedded pastes — the compact chip form
|
||||
// the UIs mint and the session keeps — so the provider wraps in
|
||||
// the same expansion the coding driver wraps its own with: the
|
||||
// model sees plain text, the transcript keeps the chips.
|
||||
let provider: Arc<dyn ModelProvider> = Arc::new(ExpandPastes::new(provider));
|
||||
// The view rides outside the expansion: stubs, whole messages,
|
||||
// The view rides outside the engine: stubs, whole messages,
|
||||
// and zoom output all show the text the model would have seen.
|
||||
let provider: Arc<dyn ModelProvider> = match &self.transcript_mirror {
|
||||
Some(mirror) => Arc::new(rhema_transcript::TranscriptView::new(
|
||||
@@ -575,10 +572,17 @@ impl InteractiveHandler {
|
||||
// future at its current await — a streaming request, or a
|
||||
// running shell command, whose child dies with the drop. The
|
||||
// next round revives whatever committed before the drop.
|
||||
// Chat input may carry embedded pastes — the compact chip form
|
||||
// the UIs mint — migrated here into the plain record the engine
|
||||
// and its providers read: the payload sits in the text, its span
|
||||
// note survives the checkpoint, and the model never sees a mark.
|
||||
let mut turn_input = [Message::text_with_images(Role::User, input, core_images)];
|
||||
rhema_core::paste::migrate(&mut turn_input);
|
||||
let [turn_input] = turn_input;
|
||||
let mut turn = Box::pin(run_turn(
|
||||
&mut agent,
|
||||
&mut session,
|
||||
Message::text_with_images(Role::User, input, core_images),
|
||||
turn_input,
|
||||
&mut sink,
|
||||
&tools,
|
||||
self.max_turn_steps,
|
||||
@@ -722,8 +726,16 @@ enum Round {
|
||||
fn restore_session(stashed: &Value, key: &str) -> Result<Session, String> {
|
||||
match stashed {
|
||||
Value::Null => Ok(Session::default()),
|
||||
stashed => serde_json::from_value(stashed.clone())
|
||||
.map_err(|err| format!("stashed session for {key} does not parse: {err}")),
|
||||
stashed => {
|
||||
let mut session: Session = serde_json::from_value(stashed.clone())
|
||||
.map_err(|err| format!("stashed session for {key} does not parse: {err}"))?;
|
||||
// A session stashed before paste spans existed carries the
|
||||
// embedded form in its prompts; the provider must never see
|
||||
// a mark. One rewrite on the way in, chips survive as the
|
||||
// span note — the same pass the driver's from_session runs.
|
||||
rhema_core::paste::migrate(&mut session.history);
|
||||
Ok(session)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -837,6 +849,10 @@ impl EventSink for HubSink {
|
||||
| ModelEvent::Usage(_)
|
||||
| ModelEvent::RetryWait { .. }
|
||||
| ModelEvent::StepEnd { .. } => return,
|
||||
// The engine's event enum is non-exhaustive: a future
|
||||
// event arrives here, dropped like the rest of the engine's
|
||||
// own bookkeeping until a turn-event shape exists for it.
|
||||
_ => return,
|
||||
};
|
||||
self.hub.emit(&self.key, turn);
|
||||
}
|
||||
@@ -1186,6 +1202,7 @@ mod tests {
|
||||
args,
|
||||
provider_data: serde_json::Value::Null,
|
||||
})],
|
||||
annotations: Default::default(),
|
||||
},
|
||||
stop_reason: StopReason::ToolUse,
|
||||
usage: Usage::default(),
|
||||
@@ -1387,11 +1404,13 @@ mod tests {
|
||||
Content::Text("on it".into()),
|
||||
Content::Text(" — done.".into()),
|
||||
],
|
||||
annotations: Default::default(),
|
||||
};
|
||||
assert_eq!(final_text(&message).as_deref(), Some("on it — done."));
|
||||
let empty = Message {
|
||||
role: Role::Assistant,
|
||||
content: vec![Content::Text(" ".into())],
|
||||
annotations: Default::default(),
|
||||
};
|
||||
assert_eq!(final_text(&empty), None);
|
||||
}
|
||||
@@ -1502,6 +1521,42 @@ mod tests {
|
||||
assert!(err.contains("does not parse"), "{err}");
|
||||
}
|
||||
|
||||
/// A session stashed before paste spans existed carries the embedded
|
||||
/// form in its prompts; the restore pass rewrites it so a provider
|
||||
/// never sees a mark, and the chip rides as the span note instead.
|
||||
#[test]
|
||||
fn a_legacy_stash_is_migrated_on_restore() {
|
||||
let payload = "l1\nl2\nl3";
|
||||
let embedded = format!("review this:\u{FFFC}{payload}\u{FFFC} please");
|
||||
let stashed = json!({
|
||||
"history": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": [embedded]
|
||||
}
|
||||
],
|
||||
"driver_state": serde_json::Value::Null
|
||||
});
|
||||
let session = restore_session(&stashed, "interactive:web").expect("the legacy stash loads");
|
||||
assert_eq!(
|
||||
final_text(&session.history[0]),
|
||||
Some(format!("review this:{payload} please")),
|
||||
"the mark and its payload land as plain text"
|
||||
);
|
||||
let text = final_text(&session.history[0]).expect("the prompt is text");
|
||||
// The chip rides as the span note: one span, over exactly the
|
||||
// payload's range, and no mark survives the restore.
|
||||
assert_eq!(
|
||||
rhema_core::paste::spans(&session.history[0]).as_slice(),
|
||||
&[rhema_core::paste::PasteSpan {
|
||||
start: "review this:".len(),
|
||||
end: "review this:".len() + payload.len(),
|
||||
lines: 3,
|
||||
}]
|
||||
);
|
||||
assert!(!text.contains('\u{FFFC}'), "no mark survives the restore");
|
||||
}
|
||||
|
||||
/// The full dispatch, in-process: one message in, one scripted reply
|
||||
/// out, the turn streamed through the hub, the conversation stashed.
|
||||
#[tokio::test]
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
//! instance and job resolve through the store, the workspace is the
|
||||
//! instance's path, the session blob (or a fresh agent) is loaded, the
|
||||
//! allowlist is permissive exactly as the forge path's — and then one
|
||||
//! `CodingAgent` turn runs. The final text lands in the job row and
|
||||
//! `HostAgent` turn runs. The final text lands in the job row and
|
||||
//! the user's notifications; the turn itself streams nowhere, its
|
||||
//! observability is the stderr tool log.
|
||||
//!
|
||||
@@ -22,12 +22,13 @@
|
||||
//! fails before any model call. The trust boundary is unchanged from
|
||||
//! the forge path — the bearer-gated surface and the instance list.
|
||||
|
||||
use std::num::NonZeroU32;
|
||||
use std::sync::Arc;
|
||||
|
||||
use rhema_agent_tools::ShellTools;
|
||||
use rhema_autonomous_agent::{Handler, SessionContext, Source, SourceError, async_trait};
|
||||
use rhema_coding_agent::{AllowAll, CodingAgent, CodingAgentConfig};
|
||||
use rhema_bash::{AllowAll, ShellTools};
|
||||
use rhema_core::{Event as ModelEvent, EventSink};
|
||||
use rhema_host_agent::{HostAgent, HostAgentConfig};
|
||||
use rhema_rsd::{Dispatcher, Event, KeyFn, Outcome, ResourceKey};
|
||||
|
||||
use crate::backends::BackendRegistry;
|
||||
@@ -139,7 +140,7 @@ pub struct CodingJobHandler {
|
||||
backends: Arc<BackendRegistry>,
|
||||
store: Arc<CodingJobStore>,
|
||||
notifications: Arc<NotificationStore>,
|
||||
max_turn_steps: u32,
|
||||
max_turn_steps: NonZeroU32,
|
||||
/// Whether the jobs run the bounded request view (the config's
|
||||
/// `transcript`, on unless set false).
|
||||
transcript: bool,
|
||||
@@ -156,7 +157,7 @@ impl CodingJobHandler {
|
||||
backends: Arc<BackendRegistry>,
|
||||
store: Arc<CodingJobStore>,
|
||||
notifications: Arc<NotificationStore>,
|
||||
max_turn_steps: u32,
|
||||
max_turn_steps: NonZeroU32,
|
||||
transcript: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
@@ -229,7 +230,7 @@ impl CodingJobHandler {
|
||||
Some(sandbox) => sandbox.workspace_for(&workspace),
|
||||
None => workspace.clone(),
|
||||
};
|
||||
let mut config = CodingAgentConfig::new(provider, model, &display, AllowAll);
|
||||
let mut config = HostAgentConfig::new(provider, model, &display, AllowAll);
|
||||
config.max_turn_steps = self.max_turn_steps;
|
||||
// A job's stashed session carries across runs and only ever
|
||||
// grows; the view is what keeps a repeat run's steps cheap.
|
||||
@@ -263,9 +264,9 @@ impl CodingJobHandler {
|
||||
self.fail(job_id, &instance_name, &reason);
|
||||
reason
|
||||
})?;
|
||||
CodingAgent::from_session(config, session)
|
||||
HostAgent::from_session(config, session)
|
||||
}
|
||||
None => CodingAgent::new(config),
|
||||
None => HostAgent::new(config),
|
||||
}
|
||||
.map_err(|err| {
|
||||
let reason = format!("cannot start the coding agent for {instance_name:?}: {err}");
|
||||
@@ -275,7 +276,7 @@ impl CodingJobHandler {
|
||||
// Commit-before-execute rides the dispatcher exactly as the
|
||||
// forge handler's does: the intent is in the store before the
|
||||
// first tool runs, and a crash-left dangling call revives at
|
||||
// turn entry (CodingAgent::turn's own revive, over the resumed
|
||||
// turn entry (HostAgent::turn's own revive, over the resumed
|
||||
// session).
|
||||
agent.set_commit_hook(Some(ctx.commit_hook()));
|
||||
|
||||
@@ -307,7 +308,7 @@ impl CodingJobHandler {
|
||||
Ok(Outcome::Handled)
|
||||
}
|
||||
|
||||
fn save_session(&self, instance: &str, agent: &CodingAgent) {
|
||||
fn save_session(&self, instance: &str, agent: &HostAgent) {
|
||||
match serde_json::to_string(agent.session()) {
|
||||
Ok(blob) => {
|
||||
let _ = self.store.save_session(instance, &blob);
|
||||
@@ -387,7 +388,13 @@ mod tests {
|
||||
BackendRegistry::new(vec![Backend::headless("mock", provider)], None)
|
||||
.expect("a single mock backend always constructs"),
|
||||
);
|
||||
CodingJobHandler::new(backends, store, notifications, 16, true)
|
||||
CodingJobHandler::new(
|
||||
backends,
|
||||
store,
|
||||
notifications,
|
||||
NonZeroU32::new(16).unwrap(),
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
fn reply(text: &str) -> ModelOutput {
|
||||
|
||||
@@ -74,9 +74,9 @@ async fn main() {
|
||||
}
|
||||
if let Some(Command::Vision { args: rest }) = &args.command {
|
||||
let mut argv = Vec::with_capacity(rest.len() + 1);
|
||||
argv.push(std::ffi::OsString::from(rhema_agent_tools::vision::MODE));
|
||||
argv.push(std::ffi::OsString::from(rhema_bash::vision::MODE));
|
||||
argv.extend(rest.iter().cloned());
|
||||
std::process::exit(rhema_agent_tools::vision::cli_run(&argv));
|
||||
std::process::exit(rhema_bash::vision::cli_run(&argv));
|
||||
}
|
||||
if let Err(err) = run(args).await {
|
||||
eprintln!("error: {err}");
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
use std::collections::BTreeSet;
|
||||
use std::sync::{Arc, OnceLock};
|
||||
|
||||
use rhema_coding_agent::CodingAgentConfig;
|
||||
use rhema_host_agent::HostAgentConfig;
|
||||
|
||||
/// What one wiring produced, held for the process.
|
||||
struct Wired {
|
||||
@@ -61,7 +61,7 @@ fn wired() -> Option<&'static Wired> {
|
||||
/// init file, the socket, the token), the prompt's `mcp` lines, and
|
||||
/// the persisted off switch. A frontend without wiring changes
|
||||
/// nothing.
|
||||
pub(crate) fn apply(config: &mut CodingAgentConfig) {
|
||||
pub(crate) fn apply(config: &mut HostAgentConfig) {
|
||||
let Some(wired) = wired() else {
|
||||
return;
|
||||
};
|
||||
@@ -82,11 +82,11 @@ mod tests {
|
||||
/// same map).
|
||||
#[test]
|
||||
fn apply_without_any_wiring_leaves_the_config_alone() {
|
||||
let mut config = CodingAgentConfig::new(
|
||||
let mut config = HostAgentConfig::new(
|
||||
rhema_core::mock::MockProvider::new([]),
|
||||
"m",
|
||||
std::path::Path::new("/tmp"),
|
||||
rhema_agent_tools::AllowAll,
|
||||
rhema_bash::AllowAll,
|
||||
);
|
||||
let before = config.shell_env.clone();
|
||||
apply(&mut config);
|
||||
|
||||
@@ -65,6 +65,7 @@ impl ModelProvider for MockLoop {
|
||||
message: Message {
|
||||
role: Role::Assistant,
|
||||
content: vec![Content::Text(text)],
|
||||
annotations: Default::default(),
|
||||
},
|
||||
stop_reason: StopReason::EndTurn,
|
||||
usage: Usage::default(),
|
||||
|
||||
@@ -22,7 +22,7 @@ use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use base64::Engine as _;
|
||||
use rhema_agent_tools::exec::{Executed, ShellError, ShellExecutor, default_executor_with};
|
||||
use rhema_bash::exec::{Executed, ShellError, ShellExecutor, default_executor_with};
|
||||
use rhema_sandbox::{ExecRequest, Sandbox, ShellSandbox, WorkspaceSeed};
|
||||
use rhema_sandbox_http::HttpSandbox;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -373,6 +373,9 @@ fn protocol_error(err: rhema_sandbox::SandboxError) -> ShellError {
|
||||
rhema_sandbox::SandboxError::Timeout(secs) => ShellError::Timeout(secs),
|
||||
rhema_sandbox::SandboxError::Unavailable(message)
|
||||
| rhema_sandbox::SandboxError::Failed(message) => ShellError::Failed(message),
|
||||
// The error enum is non-exhaustive: an unknown failure is still
|
||||
// a failure, reported in-band with its own text.
|
||||
_ => ShellError::Failed(err.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,21 +9,15 @@
|
||||
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
use std::sync::{Arc, OnceLock};
|
||||
use std::sync::Arc;
|
||||
|
||||
use rhema_coding_agent::CodingAgentConfig;
|
||||
use rhema_host_agent::HostAgentConfig;
|
||||
|
||||
static WIRED: OnceLock<Option<Arc<rhema_agent_tools::vision::Wiring>>> = OnceLock::new();
|
||||
|
||||
/// The daemon's wiring, established at first use and kept for the
|
||||
/// process's life. `None` only when provisioning failed, cached like
|
||||
/// every answer this static gives.
|
||||
pub(crate) fn wired() -> Option<&'static Arc<rhema_agent_tools::vision::Wiring>> {
|
||||
WIRED
|
||||
.get_or_init(|| {
|
||||
rhema_agent_tools::vision::wire(std::env::var_os("BASH_ENV")).map(Arc::clone)
|
||||
})
|
||||
.as_ref()
|
||||
/// The daemon's wiring, provisioned at first use and kept for the
|
||||
/// process's life — the toolkit's own process-wide cache holds it, so
|
||||
/// `None` only when provisioning failed, and a failure does not retry.
|
||||
pub(crate) fn wired() -> Option<&'static Arc<rhema_bash::vision::Wiring>> {
|
||||
rhema_bash::vision::wire(std::env::var_os("BASH_ENV"))
|
||||
}
|
||||
|
||||
/// The init file a later provisioner chains through — `None` when the
|
||||
@@ -36,7 +30,7 @@ pub(crate) fn init_path() -> Option<std::ffi::OsString> {
|
||||
/// Layers the wiring onto one agent config: the shell env map (the
|
||||
/// init file, the binary, the staging directory) and the prompt's
|
||||
/// vision section. A frontend without wiring changes nothing.
|
||||
pub(crate) fn apply(config: &mut CodingAgentConfig) {
|
||||
pub(crate) fn apply(config: &mut HostAgentConfig) {
|
||||
let Some(wired) = wired() else {
|
||||
return;
|
||||
};
|
||||
@@ -52,11 +46,11 @@ mod tests {
|
||||
/// values are constants, so extending twice is the same map.
|
||||
#[test]
|
||||
fn apply_twice_is_apply_once() {
|
||||
let mut config = CodingAgentConfig::new(
|
||||
let mut config = HostAgentConfig::new(
|
||||
rhema_core::mock::MockProvider::new([]),
|
||||
"m",
|
||||
std::path::Path::new("/tmp"),
|
||||
rhema_agent_tools::AllowAll,
|
||||
rhema_bash::AllowAll,
|
||||
);
|
||||
apply(&mut config);
|
||||
let once = config.shell_env.clone();
|
||||
|
||||
@@ -34,6 +34,7 @@ fn reply(text: &str) -> ModelOutput {
|
||||
fn tool_call(id: &str, name: &str, args: Value) -> ModelOutput {
|
||||
ModelOutput {
|
||||
message: Message {
|
||||
annotations: Default::default(),
|
||||
role: Role::Assistant,
|
||||
content: vec![Content::ToolCall(rhema_core::ToolCall {
|
||||
id: id.to_owned(),
|
||||
|
||||
Reference in new issue
Block a user