Skip to main content

scv_protocol/
lib.rs

1//! Dependency-light wire types shared by SCV clients and the server.
2//!
3//! [`ClientMessage`] is everything a client sends and [`ServerEvent`]
4//! everything the server answers, one JSON object per line ([`FrameDecoder`]
5//! bounds each line). Additive fields, and new values of the enums that
6//! parse unknown values as `Unknown` ([`ErrorCode`], [`ToolErrorKind`],
7//! [`ServerEvent`]), keep [`PROTOCOL_VERSION`]; a breaking change bumps it.
8//! This crate holds no runtime policy and does no I/O.
9
10#![forbid(unsafe_code)]
11#![warn(missing_docs)]
12
13mod attachment;
14mod background;
15mod client;
16mod daemon;
17mod error;
18mod frame;
19mod review;
20mod server;
21
22use serde::{Deserialize, Serialize};
23
24pub use attachment::{Attachment, ReplyAttachment, reply_attachment};
25pub use background::{
26    JobChange, JobReport, JobStatus, OriginKind, TurnOrigin, describe_reports, job_agent,
27};
28pub use client::{ChatLog, ClientMessage};
29pub use daemon::{
30    ComponentHealth, ComponentState, ConfirmInfo, ConfirmState, DEFAULT_CONFIRM_SECONDS,
31    DaemonCommand, DaemonStatus, DelegationInfo, DelegationSummary, MAX_CONFIRM_SECONDS,
32    MailAction, MailCounts, ProjectEvent, ProjectPhase, ProjectReport, ProjectResponse, ProjectRun,
33    ProjectRunStatus, ProjectStatus, ProjectSummary, ProjectTask, ProjectTaskStatus, Purpose,
34    RemoteTools, RestartInfo, Senders,
35};
36pub use error::{ErrorCode, ToolErrorKind};
37pub use frame::{Frame, FrameDecoder, Overflow, Step, encode_frame, trim_line};
38pub use review::{
39    JobOutcome, LandMode, LandingEvidence, LandingStatus, LandingSummary, OpenFinding, Refusal,
40    ReviewOutcome, ReviewSummary, ReviewerResult, TriedReviewer, describe_outcome, outcome_notice,
41};
42pub use server::ServerEvent;
43
44/// The protocol version. Client and server must speak the same one.
45pub const PROTOCOL_VERSION: u32 = 3;
46
47/// The longest `session.start` channel name.
48pub const MAX_CHANNEL_NAME_BYTES: usize = 32;
49/// Longest `session.start` `system_prompt`, in bytes.
50pub const MAX_SYSTEM_PROMPT_BYTES: usize = 16 * 1024;
51/// Files one `turn.start` may attach.
52pub const MAX_TURN_ATTACHMENTS: usize = 16;
53/// The tool a chat session's model calls to send a file with its reply.
54pub const CHAT_ATTACH_TOOL: &str = "chat_attach";
55
56/// A prompt waiting for the running turn to finish.
57#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
58pub struct QueueEntry {
59    /// Stable ID of this queued prompt.
60    pub queue_id: String,
61    /// Bumped on every change; edits must name the current revision.
62    pub revision: u64,
63    /// The prompt text.
64    pub prompt: String,
65    /// The client that queued it.
66    pub submitter: String,
67    /// Files the queued `turn.start` attached; they run with its prompt.
68    #[serde(default, skip_serializing_if = "Vec::is_empty")]
69    pub attachments: Vec<Attachment>,
70}
71
72/// A client's or server's name and version, exchanged at `initialize`.
73#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
74pub struct PeerInfo {
75    /// Program name, such as `scv-tui`.
76    pub name: String,
77    /// Its release.
78    pub version: String,
79}
80
81/// Tokens a turn used, as the provider reported them.
82#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
83pub struct Usage {
84    /// Prompt tokens, when reported.
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub input_tokens: Option<u64>,
87    /// Answer tokens, when reported.
88    #[serde(skip_serializing_if = "Option::is_none")]
89    pub output_tokens: Option<u64>,
90}
91
92#[cfg(test)]
93mod tests;