Skip to main content

kernel/event/kind/
window.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4// Copyright (c) 2026 2youg1 and the sprawling contributors
5
6//! The window partition: which kinds decide model-request bytes.
7
8use super::EventKind;
9
10/// The two-way partition; the sole criterion is "does the payload decide
11/// model-request bytes" (C16). There is no third class.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum WindowClass {
14    InWindow,
15    RecordOnly,
16}
17
18impl EventKind {
19    /// The partition authority. Exhaustive on purpose: adding a variant
20    /// without deciding its class is a compile error, not a default.
21    pub fn window_class(&self) -> WindowClass {
22        match self {
23            EventKind::PromptAssembled
24            | EventKind::ModelCalled
25            | EventKind::ModelReturned
26            | EventKind::ToolCalled
27            | EventKind::ToolResult
28            | EventKind::ResultOffloaded
29            | EventKind::SteerReceived
30            | EventKind::SignalConsumed
31            | EventKind::AdviserAnswered
32            // The run under way appends one sentence about the new policy
33            // to its next message, so the line decides request bytes.
34            | EventKind::RunPolicyChanged
35            // The next call is told whether a reply or the deadline woke
36            // the run, so both lines decide request bytes (kernel D32).
37            | EventKind::SignalWaitStarted
38            | EventKind::SignalWaitEnded => WindowClass::InWindow,
39            EventKind::CityInitialized
40            | EventKind::BuildingCreated
41            | EventKind::BuildingConfigured
42            | EventKind::BuildingRemoved
43            | EventKind::RunStarted
44            // Starting a session decides what the next run is given, and
45            // the bytes it is given are recorded by `prompt_assembled`;
46            // nothing here belongs to a window already on the wire.
47            | EventKind::SessionOpened
48            // The cache shape measures what a request carries; it never
49            // decides any of those bytes.
50            | EventKind::PromptShapeCompared
51            | EventKind::RunForked
52            | EventKind::GateChecked
53            | EventKind::GateDenied
54            | EventKind::CheckpointCommitted
55            | EventKind::HandoffWritten
56            | EventKind::CancelReceived
57            | EventKind::WatchdogFired
58            | EventKind::BudgetLimit
59            | EventKind::RunFrozen
60            | EventKind::LogTruncated
61            | EventKind::SignalEnqueued
62            | EventKind::DraftHeld
63            | EventKind::DraftResolved
64            | EventKind::GoalRegistered
65            | EventKind::GoalConflict
66            | EventKind::ArbitrationVerdict
67            | EventKind::RepairStarted
68            | EventKind::RepairReused
69            | EventKind::WorktreeOpened
70            | EventKind::PrOpened
71            | EventKind::PrMerged
72            | EventKind::PrRejected
73            | EventKind::RoadmapClaimed
74            | EventKind::RoadmapFinished
75            | EventKind::RoadmapReleased
76            | EventKind::RoadmapSplit
77            | EventKind::RoadmapBlocked
78            | EventKind::PursuitChanged
79            | EventKind::ApprovalRequested
80            | EventKind::ApprovalResolved
81            | EventKind::PolicyCreated
82            | EventKind::PolicyRevoked
83            | EventKind::TaintPromoted
84            | EventKind::CrossBuildingTransfer
85            | EventKind::CityHalted
86            | EventKind::BackpressureShed
87            | EventKind::DigestInvalidated
88            | EventKind::EndpointAttached
89            | EventKind::EndpointProbed
90            | EventKind::EndpointLost
91            | EventKind::ModelSelected
92            | EventKind::ProviderDegraded
93            | EventKind::LoginStarted
94            | EventKind::EvalRun
95            | EventKind::AssetArchived
96            | EventKind::CredentialLent
97            | EventKind::SecretCaptured
98            | EventKind::SecretEgressBlocked
99            | EventKind::FileDiscarded
100            | EventKind::DiscardRestored
101            | EventKind::AutonomyChanged
102            | EventKind::WentBack
103            | EventKind::FileRestored
104            // Connecting an application changes which tools a later run
105            // is offered, and the tool table is assembled from the
106            // configuration rather than from this line, so nothing here
107            // decides model-request bytes.
108            | EventKind::ToolkitLinkOpened
109            // An embedding or a rerank is a call for a derived value,
110            // not a turn of the conversation: the window's bytes are
111            // recorded by `prompt_assembled`, and the answer here is
112            // recorded so a cost can be read off the history.
113            | EventKind::EmbeddingCalled
114            | EventKind::RerankCalled
115            | EventKind::AdviserAsked
116            // The fallback records that the city's own policy answered
117            // instead; the move it made is already written where the
118            // move itself is written.
119            | EventKind::AdviserFellBack
120            | EventKind::GovernedDocumentWritten
121            | EventKind::SpineDocumentWritten
122            | EventKind::RulesChanged
123            // A renewal resends a prefix already on the wire and changes
124            // no byte of any later request; the line records its cost.
125            | EventKind::CacheRenewed
126            // What a harness said or answered never decides a request
127            // this city sends.
128            | EventKind::HarnessReported
129            | EventKind::HarnessAnswered
130            // Who may reach the city from outside its machine decides no
131            // byte a model is sent.
132            | EventKind::RemoteOpened
133            | EventKind::RemoteClosed
134            | EventKind::DevicePaired
135            | EventKind::DeviceRevoked
136            | EventKind::RemoteSessionStarted
137            // A save, and a person's verdicts on a suggestion, change a
138            // file on disk; a later run reads that file, never this line.
139            | EventKind::DocumentWritten
140            | EventKind::ProposalOffered
141            | EventKind::ProposalDecided
142            | EventKind::ProposalWithdrawn
143            // A session's name is what a page shows, and an audit is what
144            // an auditor said about a skill; neither reaches a request.
145            | EventKind::SessionNamed
146            | EventKind::SkillAudited
147            // The sender already read its tool's answer; where the letter
148            // landed is what a page draws (kernel D38).
149            | EventKind::SignalLanded
150            // Who put which version of a skill on a shelf is what the
151            // skill page shows; a run reads the skill, never this line.
152            | EventKind::SkillShelved => WindowClass::RecordOnly,
153        }
154    }
155}