Skip to main content

ConversationWatcher

Struct ConversationWatcher 

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

Watches a conversation for new entries.

Tracks which entries have been seen (by UUID) and only returns new entries on subsequent polls.

§Example

use toolpath_claude::{ClaudeConvo, ConversationWatcher};

let manager = ClaudeConvo::new();
let mut watcher = ConversationWatcher::new(
    manager,
    "/path/to/project".to_string(),
    "session-uuid".to_string(),
);

// First poll returns all existing entries
let entries = watcher.poll().unwrap();
println!("Initial entries: {}", entries.len());

// Subsequent polls return only new entries
loop {
    std::thread::sleep(std::time::Duration::from_secs(1));
    let new_entries = watcher.poll().unwrap();
    for entry in new_entries {
        println!("New entry: {:?}", entry.uuid);
    }
}

Implementations§

Source§

impl ConversationWatcher

Source

pub fn new(manager: ClaudeConvo, project: String, session_id: String) -> Self

Creates a new watcher for the given conversation.

Source

pub fn with_role_filter(self, role: MessageRole) -> Self

Sets a role filter - only entries with this role will be returned.

Source

pub fn project(&self) -> &str

Returns the project path being watched.

Source

pub fn session_id(&self) -> &str

Returns the session ID being watched.

Source

pub fn seen_count(&self) -> usize

Returns the number of entries that have been seen.

Source

pub fn poll(&mut self) -> Result<Vec<ConversationEntry>>

Polls for new conversation entries.

On the first call, returns all existing entries (optionally filtered by role). On subsequent calls, returns only entries that haven’t been seen before.

Source

pub fn poll_with_full( &mut self, ) -> Result<(Conversation, Vec<ConversationEntry>)>

Polls and returns the full conversation along with just the new entries.

Useful when you need both the full state and the delta.

Source

pub fn reset(&mut self)

Resets the watcher, clearing all seen UUIDs.

The next poll will return all entries as if it were the first call.

Source

pub fn mark_seen(&mut self, entries: &[ConversationEntry])

Pre-marks entries as seen without returning them.

Useful for initializing the watcher to only return future entries.

Source

pub fn skip_existing(&mut self) -> Result<usize>

Skips existing entries - next poll will only return new entries.

Trait Implementations§

Source§

impl Debug for ConversationWatcher

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.