import Foundation

/// One collapsed tool-call summary line, synced from the Mac that ran the session to peer Macs
/// viewing it (mesh session sync). Keyed by `toolCallID` — the stable identifier the agent
/// assigns each tool call, identical on every device — so a viewer drops the line straight onto
/// the matching card without recomputing anything.
///
/// Only Bash *blocks* are carried: a block's id IS a `toolCallID` (its first call), which is
/// portable across Macs. The non-Bash "family" summaries are keyed by a per-process randomized
/// hash (`TranscriptProjection.toolGroupSignature`) that differs on every device, so they can't
/// be addressed across the wire and stay a local-only concern.
public struct ToolSummaryLine: Sendable, Codable, Equatable {
    /// The Bash block's id — the first (and keying) tool call of the collapsed block.
    public let toolCallID: String
    /// The AI (or heuristic) one-line gist the collapsed card shows in place of the raw command.
    public let line: String

    public init(toolCallID: String, line: String) {
        self.toolCallID = toolCallID
        self.line = line
    }
}

/// Owner→viewer push of a session's current collapsed Bash summaries (mesh session sync). The
/// owner sends it as it (re)computes lines for the session it has open, and seeds the same set
/// up front via `SessionSnapshot.toolSummaries` on subscribe. A viewer applies each line to its
/// matching card, resolving the loading placeholder that would otherwise spin forever — the owner
/// already did the model work, so the peer never re-runs it.
///
/// Delivered as `HostMsg.toolSummaries`, gated to a connection's session subscriptions exactly
/// like `HostMsg.events`. A peer that predates this tag decodes it as `HostMsg.unknown` and
/// harmlessly ignores it (SYNC §9 forward-compat).
public struct ToolSummaryBatch: Sendable, Codable, Equatable {
    public let sessionID: SessionID
    public let summaries: [ToolSummaryLine]

    public init(sessionID: SessionID, summaries: [ToolSummaryLine]) {
        self.sessionID = sessionID
        self.summaries = summaries
    }
}
