openbutler-protocol 0.0.2

The wire contract between the OpenButler daemon and its clients: frame encoding, action envelopes, and the shared state types.
Documentation
//! Session search over the host's derived index: the request a client sends
//! and the answer the host composes.
//!
//! The index itself never leaves the host. A client asks a question and gets
//! finished rows plus the screen the host built from them, exactly like
//! `session.list`: `matches` is for a surface that wants the data (a table it
//! styles itself, a list it filters), `lines` is for one that prints.

use serde::{Deserialize, Serialize};

use crate::screen::ScreenLine;

/// What to search for, and how much of the answer to return.
///
/// The query is keywords, not a sentence: matching is prefix-based and the
/// host drops the keywords that appear all over the corpus. The answer names
/// both lists, so a caller can see what was actually searched.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SessionSearchRequest {
    /// Two to four distinctive keywords. Empty is refused.
    pub query: String,
    /// Maximum matches to return; the host's default when absent.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Matches to skip, for paging.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub offset: Option<i64>,
    /// Include text that came from tool output; off by default because it is
    /// the noisiest part of a transcript.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "includeOutputs"
    )]
    pub include_outputs: Option<bool>,
}

/// One place that matched: the ids a client needs to open it, plus the tier
/// that produced the row so a weaker hit can be told apart from a stronger
/// one.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SessionSearchMatch {
    /// The session the row belongs to.
    #[serde(rename = "sessionId")]
    pub session_id: String,
    /// 1-based display entry number, the same numbering `session.load` and
    /// the transcript window use.
    pub entry: i64,
    /// Which piece of the entry matched: user, assistant, notice, divider,
    /// command or output.
    pub kind: String,
    /// A window around the match, with the matched words bracketed.
    pub snippet: String,
    /// Relevance, higher is better.
    pub score: f64,
    /// The tier that produced the row: `phrase`, `strict` or `relaxed`.
    pub tier: String,
    /// The session's title, so a row reads on its own.
    pub title: String,
    /// The directory the session ran in, when it had one.
    #[serde(
        default,
        skip_serializing_if = "Option::is_none",
        rename = "workspaceRoot"
    )]
    pub workspace_root: Option<String>,
    /// The session's last update, as the record carries it.
    #[serde(rename = "updatedAt")]
    pub updated_at: String,
}

/// Answer to `session.search`: the rows plus the screen the host composed.
///
/// `total` is what the host found and capped, not a count of every possible
/// hit; `truncated` says the host stopped at its own fetch bound, so the
/// number is a floor.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SessionSearchAnswer {
    /// The rows, best first.
    pub matches: Vec<SessionSearchMatch>,
    /// How many rows the host is reporting.
    pub total: i64,
    /// The keywords that were actually searched.
    pub terms: Vec<String>,
    /// The keywords the corpus-frequency check threw away.
    pub dropped: Vec<String>,
    /// The host stopped at its fetch bound: `total` is a floor.
    pub truncated: bool,
    /// The finished screen: a header, one line per row, and a footer.
    pub lines: Vec<ScreenLine>,
}