1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Where turn review actually runs.
//!
//! The review driver is a pure state machine (`mj_core::review::driver`); this is the
//! process that feeds it. It lives in the controller daemon, which is the one
//! process that owns every session whether or not anyone is watching: it pumps
//! each session's relay every 150 ms, it is the only SQLite writer, and it
//! hosts the phone server. That is why review lives here and not in a UI. A
//! review started from the terminal survives the terminal closing; a session
//! driven only from a phone is reviewed on the same terms; a session nobody is
//! attached to is reviewed too.
//!
//! Every surface is a projection: the terminal and the phone both render
//! [`RuntimeReviewView`] and both resolve a review by asking the host. Neither
//! owns any part of the review.
//!
//! Shape: one task owns all review state and processes [`HostEvent`]s in
//! order. Everything slow -- capturing a delta, staging a reviewer profile,
//! reading a role's journal -- happens in a spawned task that sends its result
//! back as another event. Nothing here holds a lock across an await, and no
//! two reviews can interleave their state.
use std::collections::{BTreeMap, BTreeSet};
use std::path::PathBuf;
use std::sync::{Arc, LazyLock, Mutex};
use std::time::Duration;
use tokio::sync::{mpsc, oneshot};
use crate::database::TurnReviewState;
use crate::session_manager::{
ManagedSessionHandle, ManagedSessionView, ReviewDeliveryAdmission, ReviewerAction,
ReviewerOutcome, SessionManagerControl, new_command_id,
};
use mj_core::config::ReviewConfig;
use mj_core::state::{MaterializedExecutionState, MaterializedSession};
use mj_core::relay::{RelayCommand, RelayEvent, RelayObservation};
use mj_core::review::lanes::{ReviewTier, UserMessage};
use mj_core::review::verdict::ReviewVerdict;
use mj_review::driver::{
INTENT_ROLE, PendingForward, Resolution, ReviewRequest, SUPERVISOR_ROLE, TurnReviewDriver,
TurnReviewPhase, TurnReviewSeed,
};
pub use mj_client::review::{RuntimeReviewView, VerdictKind, VerdictView, role_session_id};
mod prompts;
pub use prompts::*;
mod environment;
pub use environment::*;
mod host;
pub use host::*;
mod events;
use events::*;
mod begin;
mod dispatch;
mod notices;
mod persist;
mod resolve;
mod roles;
mod slots;
use slots::*;
mod reviewer;
pub use reviewer::*;
#[cfg(test)]
mod tests;