mj_controller/
server_runtime.rs1use std::net::{Ipv4Addr, SocketAddr};
5use std::path::PathBuf;
6use std::sync::Arc;
7use std::sync::atomic::{AtomicBool, Ordering};
8use std::time::{Duration, Instant};
9
10use anyhow::{Context, Result, bail};
11mod api;
12mod api_activity;
13mod profile_catalog;
14
15use mj_core::config::{Config, HarnessProfile, PhoneConfig, is_bare_project_target};
16use mj_core::remote_git::{default_branch, display_url, resolve_repository};
17use mj_core::state::{MaterializedSession, ProjectSourceIdentity, SessionRecord, State};
18
19use crate::controller::Controller;
20use crate::quota::ProfileQuota;
21use crate::server::{
22 ActionOutcome, BackgroundTaskStopFailure, BackgroundTaskStopRequest, BrowserTranscript,
23 ControllerAction, ControllerRequest, MovePreparationRequest, PreflightFailure,
24 ReadReceiptRequest, ResumeQueueDisposition, ServerOptions, ViewerActivityDetails,
25 ViewerActivityKind, ViewerBackgroundTask, ViewerMoveRecovery, ViewerQueuedPrompt, ViewerQuota,
26 ViewerSnapshot, ViewerUserShell,
27};
28use crate::session_manager::{SessionManagerChannels, SessionManagerControl, new_command_id};
29use crate::tailscale::TailscaleTls;
30#[cfg(test)]
31use crate::targets::ProcessExecutor;
32use crate::targets::{CancellableProcessExecutor, CommandExecutor};
33use crate::worker_client::CredentialSyncCoordinator;
34use mj_core::relay::RelayCommand;
35use mj_core::workspace::WorkspaceRecord;
36
37use crate::controller::config_only_controller;
38use crate::daemon::{
39 CreateSessionControl, CreateSessionRequest, ResumeSessionRequest, RuntimeState,
40};
41use crate::pollers::{
42 CredentialSyncNotices, CredentialSyncSignalTracker, QUOTA_STALE_AFTER, QuotaRefreshBatch,
43 QuotaUpdate, apply_worker_record_update, credential_sync_targets, dashboard_worker_targets,
44 projected_queued_prompts, queued_prompt_projection, quota_refresh_profiles,
45 schedule_due_credential_syncs, spawn_quota_refresher,
46};
47
48#[derive(Debug, Clone)]
49pub struct ServerArgs {
50 bind: String,
51 tailscale_detect: bool,
52 tls_cert: Option<PathBuf>,
53 tls_key: Option<PathBuf>,
54}
55
56impl From<&PhoneConfig> for ServerArgs {
57 fn from(config: &PhoneConfig) -> Self {
58 Self {
59 bind: config.bind.clone(),
60 tailscale_detect: config.tailscale_detect,
61 tls_cert: config.tls_cert.clone(),
62 tls_key: config.tls_key.clone(),
63 }
64 }
65}
66
67const TAILSCALE_COMMAND_TIMEOUT: Duration = Duration::from_secs(120);
68const TAILSCALE_RENEW_INTERVAL: Duration = Duration::from_secs(24 * 60 * 60);
69
70mod projection;
71use projection::*;
72mod args;
73use args::*;
74mod phone_actions;
75use phone_actions::*;
76mod run;
77pub use run::*;
78mod support;
79use support::*;
80mod preflight;
81use preflight::*;
82mod actions;
83use actions::*;
84mod project_sources;
85use project_sources::*;
86mod snapshot;
87use snapshot::*;
88
89#[cfg(test)]
90mod tests;