Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 14 additions & 14 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "f75aadb2b45d9624ca576b516307a32991f361e5" }
harness-gateway-client = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "f75aadb2b45d9624ca576b516307a32991f361e5" }
plugin-mcp = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "f75aadb2b45d9624ca576b516307a32991f361e5" }
runvil = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "fb29b8a29131ca298d517a2e40e9801c7bd6d694" }
harness-gateway-client = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "fb29b8a29131ca298d517a2e40e9801c7bd6d694" }
plugin-mcp = { version = "0.3.0", git = "https://github.com/cppalliance/runvil-harness", rev = "fb29b8a29131ca298d517a2e40e9801c7bd6d694" }
# 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
Expand Down
12 changes: 5 additions & 7 deletions crates/workshop/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
//! announce itself.
//!
//! The runtime links the subsystem-named seams carry: the gateway
//! drives the menu through [`MenuPush`], publishing a model catalog
//! forces a menu reconcile through [`Push::push_models_catalog`], and
//! agent sessions read the workspace's granted roots through
//! [`WorkspaceRoots`].
//! drives the menu through [`MenuPush`], and publishing a model catalog
//! forces a menu reconcile through [`Push::push_models_catalog`].
//!
//! ## Invariants
//!
Expand All @@ -21,8 +19,8 @@
//! only this crate implements them: registrants plug in through the
//! adapters provided here, never by implementing a trait downstream.
//! - Subsystem names live in the sealed traits ([`MenuSink`],
//! [`CatalogSink`], [`StatusChannel`], [`StatusSink`],
//! [`WorkspaceRoots`]) and in the [`MenuPush`] struct behind
//! [`CatalogSink`], [`StatusChannel`], [`StatusSink`]) and in the
//! [`MenuPush`] struct behind
//! [`Push::menu`], the facade's one per-subsystem accessor; the
//! collections stay keyed by type, never by a per-subsystem field. A
//! new subsystem adds its trait and adapter here, a compose helper in
Expand All @@ -46,5 +44,5 @@ pub use registry::{MissingContribution, Registration, Registry};
pub use traits::{
BackgroundTask, BackgroundTaskAdapter, CatalogSink, CatalogSinkAdapter, MenuSink,
MenuSinkAdapter, RouteRegistrar, RouteRegistrarAdapter, ShutdownHandle, StatusChannel,
StatusChannelAdapter, StatusSink, StatusSinkAdapter, WorkspaceRoots, WorkspaceRootsAdapter,
StatusChannelAdapter, StatusSink, StatusSinkAdapter,
};
67 changes: 2 additions & 65 deletions crates/workshop/registry/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
//! The sealed subsystem traits: one per contribution kind in the
//! decomposition's inventory (routes, background tasks, push channels
//! and sinks, shared views).
//! and sinks).
//!
//! All are sealed behind a private supertrait, so only this crate can
//! implement them. A registrant plugs its subsystem in through an
//! adapter this crate provides, never by implementing a trait
//! downstream.

use std::fmt;
use std::path::PathBuf;
use std::pin::Pin;

use axum::Router;
use tokio::sync::{broadcast, watch};
use tokio::sync::broadcast;

use workshop_protocol::StatusBarUpdate;

Expand Down Expand Up @@ -245,68 +244,6 @@ impl<P> fmt::Debug for CatalogSinkAdapter<P> {
}
}

/// The workspace subsystem's granted-root view: the narrow state handle
/// the server's agent-session bindings read through the registry.
/// Registered by `workshop-workspace`'s `handles.rs`.
pub trait WorkspaceRoots: Sealed + Send + Sync {
/// The granted workspace roots in stable sorted order.
fn granted_roots(&self) -> Vec<PathBuf>;
/// A watch on the grant-set generation: it changes on every grant,
/// revoke, and workspace switch, so a consumer re-reads
/// [`WorkspaceRoots::granted_roots`] when it wakes.
fn subscribe(&self) -> watch::Receiver<u64>;
}

/// A [`WorkspaceRoots`] backed by two closures over the workspace's grant
/// set, one reading the roots and one subscribing to its generation: the
/// registration adapter for the workspace subsystem. The registry's
/// traits are sealed, so the registrant plugs its state in through this
/// adapter rather than implementing the trait itself.
pub struct WorkspaceRootsAdapter<F, S> {
roots: F,
subscribe: S,
}

impl<F, S> WorkspaceRootsAdapter<F, S>
where
F: Fn() -> Vec<PathBuf> + Send + Sync,
S: Fn() -> watch::Receiver<u64> + Send + Sync,
{
/// Builds the adapter from the workspace's granted-roots closure and
/// its grant-set generation subscribe closure.
#[must_use]
pub fn new(roots: F, subscribe: S) -> Self {
Self { roots, subscribe }
}
}

impl<F, S> Sealed for WorkspaceRootsAdapter<F, S>
where
F: Fn() -> Vec<PathBuf> + Send + Sync,
S: Fn() -> watch::Receiver<u64> + Send + Sync,
{
}

impl<F, S> WorkspaceRoots for WorkspaceRootsAdapter<F, S>
where
F: Fn() -> Vec<PathBuf> + Send + Sync,
S: Fn() -> watch::Receiver<u64> + Send + Sync,
{
fn granted_roots(&self) -> Vec<PathBuf> {
(self.roots)()
}

fn subscribe(&self) -> watch::Receiver<u64> {
(self.subscribe)()
}
}

impl<F, S> fmt::Debug for WorkspaceRootsAdapter<F, S> {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.debug_struct("WorkspaceRootsAdapter").finish()
}
}

/// A [`RouteRegistrar`] backed by one closure building the subsystem's
/// router: the registration adapter for a subsystem's routes. The
/// registry's traits are sealed, so the registrant plugs its routes in
Expand Down
55 changes: 1 addition & 54 deletions crates/workshop/registry/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::sync::{Arc, Mutex, PoisonError};

use tokio::sync::{broadcast, watch};
use tokio::sync::broadcast;

use workshop_protocol::{Activity, Severity, StatusBarUpdate};
use workshop_registry::{Registry, StatusChannel, StatusChannelAdapter};
Expand Down Expand Up @@ -130,59 +130,6 @@ fn registry_clones_share_the_same_collections() {
);
}

#[test]
fn the_workspace_roots_handle_serves_the_registrants_grants() {
use std::path::PathBuf;

use workshop_registry::{WorkspaceRoots, WorkspaceRootsAdapter};

let registry = Registry::new();
assert!(
registry.state::<dyn WorkspaceRoots>().is_none(),
"an unregistered roots handle is a graceful no-op"
);
let registration = registry.register_state::<dyn WorkspaceRoots>(Arc::new(
WorkspaceRootsAdapter::new(|| vec![PathBuf::from("/granted")], || watch::channel(0).1),
));
let roots = registry
.state::<dyn WorkspaceRoots>()
.expect("the registered roots handle is served");
assert_eq!(roots.granted_roots(), vec![PathBuf::from("/granted")]);
drop(registration);
assert!(
registry.state::<dyn WorkspaceRoots>().is_none(),
"the key empties when the guard drops"
);
}

#[test]
fn the_workspace_roots_handle_serves_the_registrants_change_signal() {
use std::path::PathBuf;

use workshop_registry::{WorkspaceRoots, WorkspaceRootsAdapter};

let registry = Registry::new();
let generation = watch::Sender::new(0_u64);
let _registration = registry.register_state::<dyn WorkspaceRoots>(Arc::new(
WorkspaceRootsAdapter::new(Vec::<PathBuf>::new, {
let generation = generation.clone();
move || generation.subscribe()
}),
));
let mut receiver = registry
.state::<dyn WorkspaceRoots>()
.expect("the registered roots handle is served")
.subscribe();
generation.send_modify(|value| *value += 1);
assert!(
receiver
.has_changed()
.expect("the registrant's sender is alive"),
"a bump through the registrant's sender reaches the subscriber"
);
assert_eq!(*receiver.borrow_and_update(), 1);
}

#[test]
fn route_registrants_build_their_routers_in_registration_order() {
use workshop_registry::RouteRegistrarAdapter;
Expand Down
11 changes: 5 additions & 6 deletions crates/workshop/server/src/agents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ pub struct AgentSessions {

/// The shared state behind the cloneable handle.
struct Inner {
/// The subsystem registry: the gateway and menu handles, the
/// workspace roots, and the push facade are read through it.
/// The subsystem registry: the gateway and menu handles and the push
/// facade are read through it.
registry: Registry,
/// Reset on completed replies: an agent reply is useful gateway work.
backoff: ReconnectBackoff,
Expand Down Expand Up @@ -478,10 +478,9 @@ impl AgentSessions {
}

/// Runs `conversation`'s one run of its agent. The setup's selected
/// model and workspace roots are read once the menu's catalog holds a
/// chat-capable model, so a pick made while the catalog was empty is
/// the one the run binds; a close during that wait ends the run before
/// it begins.
/// model is read once the menu's catalog holds a chat-capable model,
/// so a pick made while the catalog was empty is the one the run
/// binds; a close during that wait ends the run before it begins.
async fn drive(self, conversation: Conversation) {
tokio::select! {
() = conversation.closing() => {}
Expand Down
Loading
Loading