diff --git a/Cargo.lock b/Cargo.lock index fd3ccf16..00ab1e83 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2242,7 +2242,7 @@ dependencies = [ [[package]] name = "harness-gateway-client" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "bytes", "reqwest", @@ -2256,7 +2256,7 @@ dependencies = [ [[package]] name = "harness-plugin-loader" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "libloading 0.8.9", "runvil-plugin", @@ -2267,7 +2267,7 @@ dependencies = [ [[package]] name = "harness-runner" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "futures-util", "harness-plugin-loader", @@ -4058,7 +4058,7 @@ dependencies = [ [[package]] name = "plugin-mcp" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "reqwest", "rmcp", @@ -4726,7 +4726,7 @@ dependencies = [ [[package]] name = "runvil" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "harness-plugin-loader", "harness-runner", @@ -4737,7 +4737,7 @@ dependencies = [ [[package]] name = "runvil-engine" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "runvil-lua", "runvil-model-client", @@ -4750,7 +4750,7 @@ dependencies = [ [[package]] name = "runvil-lua" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "mlua", "runvil-markdown", @@ -4764,7 +4764,7 @@ dependencies = [ [[package]] name = "runvil-markdown" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "pulldown-cmark", "serde_json", @@ -4774,7 +4774,7 @@ dependencies = [ [[package]] name = "runvil-model-client" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "runvil-types", "serde", @@ -4784,7 +4784,7 @@ dependencies = [ [[package]] name = "runvil-plugin" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "runvil-types", "runvil-vfs", @@ -4807,7 +4807,7 @@ source = "git+https://github.com/cppalliance/runvil-plugin-api?rev=74f9e08ba9cc5 [[package]] name = "runvil-prompt" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "pulldown-cmark", "runvil-lua", @@ -4820,7 +4820,7 @@ dependencies = [ [[package]] name = "runvil-runtime" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "mlua", "regex", @@ -4838,7 +4838,7 @@ dependencies = [ [[package]] name = "runvil-types" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" dependencies = [ "serde", "serde_json", @@ -4848,7 +4848,7 @@ dependencies = [ [[package]] name = "runvil-vfs" version = "0.3.0" -source = "git+https://github.com/cppalliance/runvil-harness?rev=6efe4ad7c4d801adebb5b292e4ee7690581c5d35#6efe4ad7c4d801adebb5b292e4ee7690581c5d35" +source = "git+https://github.com/cppalliance/runvil-harness?rev=ee89d0882ec8cecfcd0159c7f61c6741fceef612#ee89d0882ec8cecfcd0159c7f61c6741fceef612" [[package]] name = "rust-embed" diff --git a/Cargo.toml b/Cargo.toml index 8a0ce04f..5ee04d15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,9 +25,9 @@ repository = "https://github.com/cppalliance/runvil-workshop" # Workshop links in. All three name one commit, because two commits would # be two copies of every type the crates share. `version` beside `git` # keeps cargo-deny's wildcard check quiet. -runvil = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "6efe4ad7c4d801adebb5b292e4ee7690581c5d35" } -harness-gateway-client = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "6efe4ad7c4d801adebb5b292e4ee7690581c5d35" } -plugin-mcp = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "6efe4ad7c4d801adebb5b292e4ee7690581c5d35" } +runvil = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "ee89d0882ec8cecfcd0159c7f61c6741fceef612" } +harness-gateway-client = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "ee89d0882ec8cecfcd0159c7f61c6741fceef612" } +plugin-mcp = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "ee89d0882ec8cecfcd0159c7f61c6741fceef612" } # The safe layer over the C Plugin contract, version 0.6, from its own # repository, pinned by commit. Only the library Plugin crates under # `crates/workshop/` name it, for `export_plugin!`. The commit is the one diff --git a/crates/workshop/agents/src/conversation-run.rs b/crates/workshop/agents/src/conversation-run.rs index e5cc07d8..dfce171d 100644 --- a/crates/workshop/agents/src/conversation-run.rs +++ b/crates/workshop/agents/src/conversation-run.rs @@ -5,7 +5,7 @@ use std::sync::Arc; -use runvil::harness::{RunRecorder, display_chain}; +use runvil::harness::{IntoShared, RunRecorder, display_chain}; use runvil::ids::RoundId; use runvil::{Error, Harness, Host, Prompt, RunReport, RunSetup}; @@ -20,10 +20,12 @@ const CANCELED: &str = "the agent run was canceled"; impl Conversation { /// The recorder the run writes through: every call goes on to /// `inner`, and each event `inner` accepted reaches this - /// conversation. + /// conversation. `inner` is taken in each form in which a run's + /// setup takes a recorder: the recorder itself, an `Arc` of it, or + /// an `Arc`. #[must_use] - pub fn recorder(&self, inner: Arc) -> Arc { - Arc::new(ConversationRecorder::new(self.clone(), inner)) + pub fn recorder(&self, inner: impl IntoShared) -> Arc { + Arc::new(ConversationRecorder::new(self.clone(), inner.into_shared())) } /// Parses the agent `name` on `host` on the blocking pool, then runs diff --git a/crates/workshop/agents/src/tee-tests.rs b/crates/workshop/agents/src/tee-tests.rs index 284a60ae..92b33b9f 100644 --- a/crates/workshop/agents/src/tee-tests.rs +++ b/crates/workshop/agents/src/tee-tests.rs @@ -47,6 +47,8 @@ fn record(kind: RecordKind, event: &Event) -> Record { /// An inner recorder that notes, at each append, how many entries the /// conversation's transcript already held, and refuses appends on demand. +/// It leaves `append_event` at its default, so the record of an event +/// reaches its `append` as every other record does. struct Watching { inner: MemoryRecorder, conversation: Conversation, @@ -96,7 +98,8 @@ async fn the_tee_adds_an_event_to_the_transcript_after_the_inner_recorder_accept let (conversation, inner, tee) = watched(false); let mut live = conversation.subscribe_events(); let run = tee.begin_run(meta()).await.unwrap(); - tee.append(run, record(RecordKind::Event, §ion_started())) + let event = section_started(); + tee.append_event(run, record(RecordKind::Event, &event), &event) .await .unwrap(); assert_eq!( @@ -123,8 +126,9 @@ async fn the_tee_returns_the_inner_recorders_refusal_and_keeps_the_event_out() { let (conversation, _inner, tee) = watched(true); let mut live = conversation.subscribe_events(); let run = tee.begin_run(meta()).await.unwrap(); + let event = section_started(); let refusal = tee - .append(run, record(RecordKind::Event, §ion_started())) + .append_event(run, record(RecordKind::Event, &event), &event) .await .expect_err("the inner recorder's refusal is the tee's"); assert_eq!( @@ -179,7 +183,7 @@ async fn recorded_turn_failures_report_their_kind_and_section() { provenance: provenance(), }; for event in [&model, &tool] { - tee.append(run, record(RecordKind::Event, event)) + tee.append_event(run, record(RecordKind::Event, event), event) .await .unwrap(); } diff --git a/crates/workshop/agents/src/tee.rs b/crates/workshop/agents/src/tee.rs index d7551203..1e0c7087 100644 --- a/crates/workshop/agents/src/tee.rs +++ b/crates/workshop/agents/src/tee.rs @@ -2,15 +2,17 @@ //! to the inner recorder, and what the inner recorder accepted also //! reaches the conversation. //! -//! The tee notes the run the inner recorder begins and hands each event -//! record the inner recorder accepted to the conversation, so the record, -//! the live broadcast, and the transcript agree event for event. A refused write +//! The tee notes the run the inner recorder begins. The Harness hands it +//! each event with the event's record. The tee passes both on to the +//! inner recorder, and it hands the event to the conversation once the +//! inner recorder has accepted the record, so the record, the live +//! broadcast, and the transcript agree event for event. A refused write //! is returned as the inner recorder's own, and its event reaches no one. use std::sync::Arc; use runvil::event::Event; -use runvil::harness::{Record, RecordKind, RunId, RunMeta, RunRecorder}; +use runvil::harness::{Record, RunId, RunMeta, RunRecorder}; use runvil::{BoxFuture, Error}; use crate::conversation::Conversation; @@ -41,22 +43,18 @@ impl RunRecorder for ConversationRecorder { } fn append(&self, run: RunId, record: Record) -> BoxFuture<'_, Result<(), Error>> { + self.inner.append(run, record) + } + + fn append_event<'a>( + &'a self, + run: RunId, + record: Record, + event: &'a Event, + ) -> BoxFuture<'a, Result<(), Error>> { Box::pin(async move { - let event = (record.kind == RecordKind::Event).then(|| record.payload.clone()); - self.inner.append(run, record).await?; - if let Some(payload) = event { - // The run serialized this event for the record a moment - // ago, so it reads back; a payload that does not is - // logged and left out of the transcript. - match serde_json::from_value::(payload) { - Ok(event) => self.conversation.observe(&event), - Err(error) => tracing::error!( - conversation = %self.conversation.id(), - %error, - "a recorded event did not read back; the transcript skips it" - ), - } - } + self.inner.append_event(run, record, event).await?; + self.conversation.observe(event); Ok(()) }) } diff --git a/crates/workshop/agents/tests/it/support.rs b/crates/workshop/agents/tests/it/support.rs index 37bca3e6..62eff50a 100644 --- a/crates/workshop/agents/tests/it/support.rs +++ b/crates/workshop/agents/tests/it/support.rs @@ -29,11 +29,7 @@ pub(crate) fn run_for( source: String, ) -> (Arc, RunSetup) { let host = Host::builder(FindTextPrompt::new(AGENT, source)).build(); - let setup = RunSetup::new( - conversation.recorder(recorder), - Arc::new(OfflineBroker), - Arc::new(TokioTimer), - ) - .has_user(true); + let setup = + RunSetup::new(conversation.recorder(recorder), OfflineBroker, TokioTimer).has_user(true); (host, setup) } diff --git a/crates/workshop/server/src/agents.rs b/crates/workshop/server/src/agents.rs index 4aae213b..68e912ce 100644 --- a/crates/workshop/server/src/agents.rs +++ b/crates/workshop/server/src/agents.rs @@ -466,14 +466,9 @@ impl AgentSessions { /// the stock tokio timer, its filesystem, and a user, since every /// conversation has an operator. fn setup_for(&self, conversation: &Conversation) -> RunSetup { - let recorder = conversation.recorder(Arc::new( - self.inner.recorder.for_agent(conversation.agent()), - )); - let broker = Arc::new(RunBroker::new( - self.inner.broker.clone(), - conversation.clone(), - )); - RunSetup::new(recorder, broker, Arc::new(TokioTimer)) + let recorder = conversation.recorder(self.inner.recorder.for_agent(conversation.agent())); + let broker = RunBroker::new(self.inner.broker.clone(), conversation.clone()); + RunSetup::new(recorder, broker, TokioTimer) .vfs(language_guide::run_vfs()) .has_user(true) } diff --git a/crates/workshop/server/src/agents/bindings-tests.rs b/crates/workshop/server/src/agents/bindings-tests.rs index 68a3480a..da56da06 100644 --- a/crates/workshop/server/src/agents/bindings-tests.rs +++ b/crates/workshop/server/src/agents/bindings-tests.rs @@ -1,7 +1,5 @@ //! Host binding tests: a run's setup takes the menu's selection. -use std::sync::Arc; - use harness_gateway_client::TokioTimer; use runvil::harness::{MemoryRecorder, OfflineBroker}; use workshop_menu::{CatalogBus, MenuBus}; @@ -10,11 +8,7 @@ use super::*; /// A setup with nothing selected. fn empty_setup() -> RunSetup { - RunSetup::new( - Arc::new(MemoryRecorder::new()), - Arc::new(OfflineBroker), - Arc::new(TokioTimer), - ) + RunSetup::new(MemoryRecorder::new(), OfflineBroker, TokioTimer) } #[test] diff --git a/crates/workshop/server/src/agents/tests.rs b/crates/workshop/server/src/agents/tests.rs index 29729c21..30e61c11 100644 --- a/crates/workshop/server/src/agents/tests.rs +++ b/crates/workshop/server/src/agents/tests.rs @@ -118,8 +118,8 @@ async fn run_agent_on( let mut errors = conversation.subscribe_errors(); let setup = RunSetup::new( conversation.recorder(recorder.clone()), - Arc::new(OfflineBroker), - Arc::new(TokioTimer), + OfflineBroker, + TokioTimer, ) .vfs(vfs) .has_user(true);