Skip to main content

Workspace

Struct Workspace 

Source
pub struct Workspace { /* private fields */ }
Expand description

A shared project context for collaborative code generation and execution.

Workspace is the public anchor for multi-agent project-building flows. It represents a shared project root, metadata, and collaboration state. Specialist agents attached to the same workspace can publish and consume typed CollaborationEvents without configuring raw pub/sub directly.

Internally, Workspace uses Arc<WorkspaceInner> so it can be cheaply cloned and shared across agents and async boundaries. The collaboration transport is an in-process broadcast channel — transport details are hidden from the public API.

Use Workspace::new to get a WorkspaceBuilder for ergonomic construction.

§Example

use adk_code::Workspace;

let workspace = Workspace::new("./my-project")
    .project_name("my-project")
    .session_id("sess-abc")
    .build();

assert_eq!(workspace.root(), &std::path::PathBuf::from("./my-project"));
assert_eq!(workspace.metadata().project_name, "my-project");
assert_eq!(workspace.metadata().session_id.as_deref(), Some("sess-abc"));

Implementations§

Source§

impl Workspace

Source

pub fn new(root: impl Into<PathBuf>) -> WorkspaceBuilder

Start building a new workspace rooted at the given path.

Returns a WorkspaceBuilder for fluent configuration.

§Example
use adk_code::Workspace;

let ws = Workspace::new("/tmp/project").build();
assert_eq!(ws.root(), &std::path::PathBuf::from("/tmp/project"));
Source

pub fn root(&self) -> &PathBuf

The shared project root directory.

Source

pub fn metadata(&self) -> &WorkspaceMetadata

Project and session metadata.

Source

pub fn publish(&self, event: CollaborationEvent) -> usize

Publish a collaboration event to all subscribers.

This is a non-blocking operation. If there are no active subscribers, the event is silently dropped. Returns the number of receivers that received the event.

§Example
use adk_code::{CollaborationEvent, CollaborationEventKind, Workspace};

let ws = Workspace::new("./proj").build();
let mut rx = ws.subscribe();

ws.publish(CollaborationEvent::new(
    "c1", "api", "backend", CollaborationEventKind::WorkPublished,
));
Source

pub fn subscribe(&self) -> Receiver<CollaborationEvent>

Subscribe to collaboration events on this workspace.

Returns a broadcast::Receiver that yields every event published after the subscription is created. Each subscriber gets its own independent stream of events.

§Example
use adk_code::{CollaborationEvent, CollaborationEventKind, Workspace};

let ws = Workspace::new("./proj").build();
let mut rx = ws.subscribe();

ws.publish(CollaborationEvent::new(
    "c1", "topic", "producer", CollaborationEventKind::NeedWork,
));
Source

pub async fn wait_for( &self, correlation_id: &str, timeout: Duration, ) -> Option<CollaborationEvent>

Wait for a collaboration event matching the given correlation_id.

Subscribes to the workspace event stream and returns the first event whose correlation_id matches. If no matching event arrives within timeout, returns None.

This implements the wait/resume pattern: an agent can publish a CollaborationEventKind::NeedWork event and then call wait_for to suspend until the matching CollaborationEventKind::WorkPublished (or other correlated response) arrives.

§Example
use adk_code::{CollaborationEvent, CollaborationEventKind, Workspace};
use std::time::Duration;

let ws = Workspace::new("./proj").build();
// In practice another agent would publish the matching event.
let result = ws.wait_for("corr-42", Duration::from_millis(100)).await;
assert!(result.is_none()); // timed out — no publisher
Source

pub fn events(&self) -> Vec<CollaborationEvent>

Get a snapshot of all events published to this workspace.

Returns a clone of the internal event log. Unlike the broadcast channel (which has a fixed capacity and drops old events for slow subscribers), the event log retains every event published since workspace creation.

§Example
use adk_code::{CollaborationEvent, CollaborationEventKind, Workspace};

let ws = Workspace::new("./proj").build();
ws.publish(CollaborationEvent::new(
    "c1", "topic", "producer", CollaborationEventKind::Completed,
));
let events = ws.events();
// events may contain the published event if still in the buffer
Source

pub fn request_work( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, ) -> CollaborationEvent

Request work from another specialist or coordinator.

Publishes a CollaborationEventKind::NeedWork event and returns the event that was published. The caller can then use Workspace::wait_for_work to suspend until the matching CollaborationEventKind::WorkPublished event arrives.

§Example
use adk_code::Workspace;

let ws = Workspace::new("./proj").build();
let event = ws.request_work("corr-1", "api-routes", "frontend_engineer");
assert_eq!(event.kind, adk_code::CollaborationEventKind::NeedWork);
Source

pub fn claim_work( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, )

Claim ownership of a requested work item.

Publishes a CollaborationEventKind::WorkClaimed event to signal that this agent is taking responsibility for the work.

§Example
use adk_code::Workspace;

let ws = Workspace::new("./proj").build();
ws.claim_work("corr-1", "api-routes", "backend_engineer");
Source

pub fn publish_work( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, payload: Value, )

Publish completed work to the workspace.

Publishes a CollaborationEventKind::WorkPublished event with the given payload. Agents waiting via Workspace::wait_for_work on the same correlation_id will be resumed.

§Example
use adk_code::Workspace;

let ws = Workspace::new("./proj").build();
ws.publish_work(
    "corr-1",
    "api-routes",
    "backend_engineer",
    serde_json::json!({ "routes": ["/api/users"] }),
);
Source

pub fn request_feedback( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, payload: Value, )

Request feedback from another specialist or reviewer.

Publishes a CollaborationEventKind::FeedbackRequested event. The caller can then use Workspace::wait_for_feedback to suspend until the matching CollaborationEventKind::FeedbackProvided arrives.

§Example
use adk_code::Workspace;

let ws = Workspace::new("./proj").build();
ws.request_feedback(
    "corr-2",
    "api-contract",
    "backend_engineer",
    serde_json::json!({ "schema": "v1" }),
);
Source

pub fn provide_feedback( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, payload: Value, )

Provide feedback in response to a feedback request.

Publishes a CollaborationEventKind::FeedbackProvided event. Agents waiting via Workspace::wait_for_feedback on the same correlation_id will be resumed.

§Example
use adk_code::Workspace;

let ws = Workspace::new("./proj").build();
ws.provide_feedback(
    "corr-2",
    "api-contract",
    "reviewer",
    serde_json::json!({ "approved": true }),
);
Source

pub fn signal_blocked( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, payload: Value, )

Signal that this agent is blocked and cannot continue.

Publishes a CollaborationEventKind::Blocked event with a payload describing what is needed to unblock.

§Example
use adk_code::Workspace;

let ws = Workspace::new("./proj").build();
ws.signal_blocked(
    "corr-3",
    "database-schema",
    "backend_engineer",
    serde_json::json!({ "needs": "schema approval" }),
);
Source

pub fn signal_completed( &self, correlation_id: impl Into<String>, topic: impl Into<String>, producer: impl Into<String>, )

Signal that a work item is completed.

Publishes a CollaborationEventKind::Completed event.

§Example
use adk_code::Workspace;

let ws = Workspace::new("./proj").build();
ws.signal_completed("corr-1", "api-routes", "backend_engineer");
Source

pub async fn wait_for_work( &self, correlation_id: &str, timeout: Duration, ) -> Option<CollaborationEvent>

Wait for a CollaborationEventKind::WorkPublished event matching the given correlation_id.

This is a convenience wrapper over Workspace::wait_for_kind that filters for WorkPublished events specifically.

§Example
use adk_code::Workspace;
use std::time::Duration;

let ws = Workspace::new("./proj").build();
let result = ws.wait_for_work("corr-1", Duration::from_secs(5)).await;
Source

pub async fn wait_for_feedback( &self, correlation_id: &str, timeout: Duration, ) -> Option<CollaborationEvent>

Wait for a CollaborationEventKind::FeedbackProvided event matching the given correlation_id.

This is a convenience wrapper over Workspace::wait_for_kind that filters for FeedbackProvided events specifically.

§Example
use adk_code::Workspace;
use std::time::Duration;

let ws = Workspace::new("./proj").build();
let result = ws.wait_for_feedback("corr-2", Duration::from_secs(5)).await;
Source

pub async fn wait_for_kind( &self, correlation_id: &str, kind: CollaborationEventKind, timeout: Duration, ) -> Option<CollaborationEvent>

Wait for a collaboration event matching both correlation_id and kind.

Subscribes to the workspace event stream and returns the first event whose correlation_id and kind both match. If no matching event arrives within timeout, returns None.

This is the most precise wait primitive — use it when you need to filter on a specific event kind rather than any correlated event.

§Example
use adk_code::{CollaborationEventKind, Workspace};
use std::time::Duration;

let ws = Workspace::new("./proj").build();
let result = ws
    .wait_for_kind("corr-1", CollaborationEventKind::WorkClaimed, Duration::from_secs(5))
    .await;

Trait Implementations§

Source§

impl Clone for Workspace

Source§

fn clone(&self) -> Workspace

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Workspace

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more