1pub mod agents;
60pub mod browser;
62pub mod cli;
64pub mod customization;
66pub mod daemon;
68pub mod debugger;
70pub mod development;
72pub mod experiments;
74pub mod external_agents;
76pub mod fim;
78pub mod git;
80pub mod github;
82pub mod harness;
84pub mod intelligence;
86pub mod kernels;
88pub mod lsp;
90pub mod mcp;
92pub mod pi_runtime;
94pub mod tasks;
96pub mod testing;
98pub mod todos;
100pub mod tools;
102pub mod trust;
104pub mod tui;
106pub mod workspace;
108
109use glass_browser::cli::args::Cli;
110
111pub use agents::{
113 AgentEvent, AgentId, AgentRegistry, AgentSnapshot, AgentSpec, AgentStatus, ResidentAgentBroker,
114};
115pub use browser::{BrowserRuntimeState, BrowserService, BrowserStartConfig};
117pub use customization::{Customization, GlassConfig, Skill};
119pub use experiments::{
121 ExperimentComparison, ExperimentEvidence, ExperimentManager, ExperimentRanking,
122 ExperimentSnapshot, ExperimentState, ExperimentTrustPolicy, ExperimentWeights,
123};
124pub use intelligence::{
126 CausalPath, DevelopmentEdge, DevelopmentIntelligence, DevelopmentNode, DevelopmentNodeKind,
127 ObservableDevelopmentEvent, ObservableEventInput, ReplayDiff,
128};
129pub use lsp::{LanguageServerConfig, LanguageService, LanguageServiceEvent};
131pub use pi_runtime::{
133 PINNED_PI_SDK_VERSION, PiReadiness, PiReadinessComponent, PiReadinessState, PiSessionRequest,
134};
135pub use tasks::{
137 CrewWake, CrewWakeLiveEvidence, CrewWakeMember, RetryPolicy, TaskBudget, TaskEvidence, TaskId,
138 TaskScheduler, TaskSnapshot, TaskSpec, TaskState, VerificationRequirement,
139 load_latest_crew_wake, persist_crew_wake,
140};
141pub use todos::{SessionTodo, SessionTodoList, TodoStatus};
143pub use tools::{DevelopmentToolContext, DevelopmentToolRouter};
145pub use trust::{LocalTrustDecision, WorkspaceIdentity, WorkspaceTrust, WorkspaceTrustStore};
147pub use workspace::{AgentTurnMode, DevelopmentWorkspace, SharedDevelopmentWorkspace};
149
150pub async fn dispatch(cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
155 if cli.mcp {
156 let backend = std::sync::Arc::new(mcp::DevelopmentMcpBackend::open(
157 std::env::current_dir()?,
158 cli.yolo,
159 )?);
160 return glass_browser::mcp::server::run_mcp_server_with_backend(&cli, backend).await;
161 }
162 if let Some(glass_browser::cli::args::Commands::Agent { action }) = &cli.command
163 && matches!(
164 action,
165 glass_browser::cli::args::AgentCommand::Tool { .. }
166 | glass_browser::cli::args::AgentCommand::ToolFile { .. }
167 )
168 {
169 let result = dispatch_external_tool(action, cli.yolo).await?;
170 println!("{}", serde_json::to_string_pretty(&result)?);
171 return Ok(());
172 }
173 if let Some(glass_browser::cli::args::Commands::Agent { action }) = &cli.command {
174 enforce_legacy_development_trust(&cli)?;
175 return cli::dispatch_agent(action, cli.yolo);
176 }
177 if let Some(glass_browser::cli::args::Commands::Harness { action }) = &cli.command {
178 enforce_legacy_development_trust(&cli)?;
179 return cli::dispatch_harness(action);
180 }
181 if let Some(glass_browser::cli::args::Commands::Daemon { action }) = &cli.command {
182 return daemon::dispatch(action).await;
183 }
184 if let Some(glass_browser::cli::args::Commands::Project { action }) = &cli.command {
185 enforce_legacy_development_trust(&cli)?;
186 return cli::dispatch_project(action);
187 }
188 if cli.prompt.is_none()
189 && matches!(
190 cli.command.as_ref(),
191 Some(glass_browser::cli::args::Commands::Tui)
192 )
193 {
194 return run_development_tui(&cli);
195 }
196 if cli.command.is_none() && cli.prompt.is_none() && !cli.mcp {
197 return run_development_tui(&cli);
198 }
199 enforce_legacy_development_trust(&cli)?;
200 glass_browser::cli::runner::dispatch(cli).await
201}
202
203fn run_development_tui(cli: &Cli) -> Result<(), Box<dyn std::error::Error>> {
204 let visual_options = tui::TuiVisualOptions {
205 mode: cli.tui_live,
206 backend: cli.tui_live_backend,
207 quality: cli.tui_live_quality,
208 fit: cli.tui_live_fit,
209 };
210 tui::run(
211 std::env::current_dir()?,
212 cli.tui_layout,
213 visual_options,
214 cli.yolo,
215 cli.policy,
216 )
217}
218
219fn enforce_legacy_development_trust(cli: &Cli) -> Result<(), Box<dyn std::error::Error>> {
220 use glass_browser::cli::args::{
221 AgentCommand, AgentHarness, Commands, HarnessCommand, ProjectCommand,
222 };
223
224 let (root, safe_static) = match cli.command.as_ref() {
225 Some(Commands::Project { action }) => {
226 let root = match action {
227 ProjectCommand::Inspect { root }
228 | ProjectCommand::Files { root }
229 | ProjectCommand::Search { root, .. }
230 | ProjectCommand::Read { root, .. }
231 | ProjectCommand::Edit { root, .. }
232 | ProjectCommand::Mkdir { root, .. }
233 | ProjectCommand::Rename { root, .. }
234 | ProjectCommand::Delete { root, .. }
235 | ProjectCommand::Diagnostics { root, .. }
236 | ProjectCommand::Run { root, .. }
237 | ProjectCommand::Test { root }
238 | ProjectCommand::Lint { root }
239 | ProjectCommand::Process { root, .. }
240 | ProjectCommand::Diff { root }
241 | ProjectCommand::Link { root, .. }
242 | ProjectCommand::Graph { root, .. }
243 | ProjectCommand::Breakpoint { root, .. }
244 | ProjectCommand::Timeline { root }
245 | ProjectCommand::Replay { root, .. }
246 | ProjectCommand::Neovim { root, .. }
247 | ProjectCommand::Experiment { root, .. }
248 | ProjectCommand::Attach { root, .. } => root,
249 };
250 let safe = matches!(
251 action,
252 ProjectCommand::Inspect { .. }
253 | ProjectCommand::Files { .. }
254 | ProjectCommand::Search { .. }
255 | ProjectCommand::Read { .. }
256 | ProjectCommand::Diff { .. }
257 | ProjectCommand::Graph { .. }
258 | ProjectCommand::Breakpoint { .. }
259 | ProjectCommand::Timeline { .. }
260 | ProjectCommand::Replay { .. }
261 );
262 (root, safe)
263 }
264 Some(Commands::Harness { action }) => match action {
265 HarnessCommand::List => return Ok(()),
266 HarnessCommand::Start { root, .. } => (root, false),
267 },
268 Some(Commands::Agent { action }) => {
269 let (root, safe) = match action {
270 AgentCommand::Doctor | AgentCommand::Setup { .. } | AgentCommand::Status => {
271 return Ok(());
272 }
273 AgentCommand::Hello { root, harness } => {
274 (root, matches!(harness, AgentHarness::Local))
275 }
276 AgentCommand::Prompt { root, harness, .. } => {
277 (root, matches!(harness, AgentHarness::Local))
278 }
279 AgentCommand::Delegate { root, sandbox, .. } => (
280 root,
281 matches!(
282 sandbox,
283 glass_browser::cli::args::ExternalAgentSandbox::ReadOnly
284 ),
285 ),
286 AgentCommand::Tool { .. } | AgentCommand::ToolFile { .. } => return Ok(()),
287 AgentCommand::Steer { root, .. }
288 | AgentCommand::FollowUp { root, .. }
289 | AgentCommand::Models { root }
290 | AgentCommand::SetModel { root, .. }
291 | AgentCommand::Thinking { root, .. }
292 | AgentCommand::Abort { root }
293 | AgentCommand::NewSession { root } => (root, false),
294 };
295 (root, safe)
296 }
297 _ => return Ok(()),
298 };
299 let workspace = DevelopmentWorkspace::open(root)?;
300 if workspace.trust() == WorkspaceTrust::Untrusted && !safe_static {
301 return Err(format!(
302 "repository-controlled development execution is blocked for {}; open the TUI to inspect and trust this workspace",
303 workspace.root().display()
304 )
305 .into());
306 }
307 Ok(())
308}
309
310async fn dispatch_external_tool(
311 action: &glass_browser::cli::args::AgentCommand,
312 unrestricted: bool,
313) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
314 use crate::development::{Actor, ToolAuthorization, ToolCall};
315 use glass_browser::cli::args::AgentCommand;
316
317 let (call, root, allow_mutation, confirmed) = match action {
318 AgentCommand::Tool {
319 call,
320 root,
321 allow_mutation,
322 yes,
323 } => (
324 serde_json::from_str::<ToolCall>(call)?,
325 root,
326 *allow_mutation || unrestricted,
327 *yes || unrestricted,
328 ),
329 AgentCommand::ToolFile {
330 path,
331 root,
332 allow_mutation,
333 yes,
334 } if std::env::var_os("GLASS_DEV_DAEMON_SOCKET").is_some() => {
335 return daemon::forward_resident_tool_file(
336 path,
337 root,
338 *allow_mutation || unrestricted,
339 *yes || unrestricted,
340 )
341 .await;
342 }
343 AgentCommand::ToolFile {
344 path,
345 root,
346 allow_mutation,
347 yes,
348 } => (
349 daemon::read_private_tool_call(path)?,
350 root,
351 *allow_mutation || unrestricted,
352 *yes || unrestricted,
353 ),
354 _ => return Err("expected an external agent tool action".into()),
355 };
356 let mut workspace = DevelopmentWorkspace::open(root)?;
357 let context = DevelopmentToolContext {
358 authorization: ToolAuthorization {
359 actor: Actor::external("cli"),
360 allow_mutation,
361 confirmed,
362 unrestricted: allow_mutation && confirmed,
363 },
364 initiator: None,
365 expected_generation: workspace.generation(),
366 expected_project_revision: workspace.project().revision(),
367 };
368 Ok(workspace.execute_tool(&call, &context)?)
369}