Skip to main content

ClaudeCodeStorage

Struct ClaudeCodeStorage 

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

Storage layer for ClaudeCode sessions

Implementations§

Source§

impl ClaudeCodeStorage

Source

pub async fn new( config: ClaudeCodeStorageConfig, arbor: Arc<ArborStorage>, ) -> Result<Self, ClaudeCodeError>

Create a new ClaudeCode storage instance with a shared Arbor storage

Source

pub fn arbor(&self) -> &ArborStorage

Get access to the underlying arbor storage

Source

pub async fn session_create( &self, name: String, working_dir: String, model: Model, system_prompt: Option<String>, mcp_config: Option<Value>, loopback_enabled: bool, metadata: Option<Value>, ) -> Result<ClaudeCodeConfig, ClaudeCodeError>

Create a new ClaudeCode session with a new conversation tree

Source

pub async fn session_get( &self, session_id: &ClaudeCodeId, ) -> Result<ClaudeCodeConfig, ClaudeCodeError>

Get a session by ID

Source

pub async fn session_get_by_name( &self, name: &str, ) -> Result<ClaudeCodeConfig, ClaudeCodeError>

Get a session by name (supports partial matching)

Source

pub async fn session_list(&self) -> Result<Vec<ClaudeCodeInfo>, ClaudeCodeError>

List all sessions

Source

pub async fn session_update_head( &self, session_id: &ClaudeCodeId, new_head: NodeId, claude_session_id: Option<String>, ) -> Result<(), ClaudeCodeError>

Update session’s canonical head and optionally the Claude session ID

Source

pub async fn session_update( &self, session_id: &ClaudeCodeId, name: Option<String>, model: Option<Model>, system_prompt: Option<Option<String>>, mcp_config: Option<Value>, metadata: Option<Value>, ) -> Result<(), ClaudeCodeError>

Update session configuration

Source

pub async fn session_delete( &self, session_id: &ClaudeCodeId, ) -> Result<(), ClaudeCodeError>

Delete a session (does not delete the arbor tree)

Source

pub async fn message_create( &self, session_id: &ClaudeCodeId, role: MessageRole, content: String, model_id: Option<String>, input_tokens: Option<i64>, output_tokens: Option<i64>, cost_usd: Option<f64>, ) -> Result<Message, ClaudeCodeError>

Create a message and return it

Source

pub async fn message_create_ephemeral( &self, session_id: &ClaudeCodeId, role: MessageRole, content: String, model_id: Option<String>, input_tokens: Option<i64>, output_tokens: Option<i64>, cost_usd: Option<f64>, ) -> Result<Message, ClaudeCodeError>

Create an ephemeral message (marked for deletion) and return it

Source

pub async fn message_get( &self, message_id: &MessageId, ) -> Result<Message, ClaudeCodeError>

Get a message by ID

Source

pub async fn resolve_message_handle( &self, identifier: &str, ) -> Result<Message, ClaudeCodeError>

Resolve a message handle identifier to a Message Handle format: “msg-{message_id}:{role}:{name}”

Source

pub fn message_to_handle(message: &Message, name: &str) -> Handle

Create a handle for a message

Format: {plugin_id}@1.0.0::chat:msg-{id}:{role}:{name} Uses ClaudeCodeHandle enum for type-safe handle creation.

Source

pub async fn unknown_event_store( &self, session_id: Option<&ClaudeCodeId>, event_type: &str, data: &Value, ) -> Result<String, ClaudeCodeError>

Store an unknown event and return its ID (handle)

Source

pub async fn unknown_event_get( &self, id: &str, ) -> Result<(String, Value), ClaudeCodeError>

Retrieve an unknown event by ID

Source

pub async fn unknown_events_by_type( &self, event_type: &str, ) -> Result<Vec<(String, Value)>, ClaudeCodeError>

List unknown events by type (for analysis/debugging)

Source

pub async fn stream_create( &self, session_id: ClaudeCodeId, ) -> Result<StreamId, ClaudeCodeError>

Create a new stream buffer for async chat

Source

pub async fn stream_set_user_position( &self, stream_id: &StreamId, position: Position, ) -> Result<(), ClaudeCodeError>

Set the user position for a stream (called after user message is created)

Source

pub async fn stream_push_event( &self, stream_id: &StreamId, event: ChatEvent, ) -> Result<u64, ClaudeCodeError>

Push an event to a stream buffer

Source

pub async fn stream_set_status( &self, stream_id: &StreamId, status: StreamStatus, error: Option<String>, ) -> Result<(), ClaudeCodeError>

Update stream status

Source

pub async fn stream_get_info( &self, stream_id: &StreamId, ) -> Result<StreamInfo, ClaudeCodeError>

Get stream info

Source

pub async fn stream_poll( &self, stream_id: &StreamId, from_seq: Option<u64>, limit: Option<usize>, ) -> Result<(StreamInfo, Vec<BufferedEvent>), ClaudeCodeError>

Poll events from a stream Returns events starting from from_seq up to limit events

Source

pub async fn stream_list(&self) -> Vec<StreamInfo>

List all active streams

Source

pub async fn stream_list_for_session( &self, session_id: &ClaudeCodeId, ) -> Vec<StreamInfo>

List active streams for a session

Source

pub async fn stream_cleanup(&self, stream_id: &StreamId) -> Option<StreamInfo>

Remove a completed/failed stream from memory Returns the final stream info if found

Source

pub async fn stream_exists(&self, stream_id: &StreamId) -> bool

Check if a stream exists

Source

pub async fn render_messages( &self, tree_id: &TreeId, start: &NodeId, end: &NodeId, ) -> Result<Vec<ClaudeMessage>, ClaudeCodeError>

Render arbor tree path into Claude API messages format

Walks from start to end node, parsing NodeEvent JSON from each node, and groups into Claude messages array.

§Algorithm
  1. Get path from start to end via arbor
  2. Parse each node’s content as NodeEvent
  3. Group into messages based on event type
  4. Return messages array

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> MaybeSend for T
where T: Send,