1pub mod agents;
8pub mod browser;
9pub mod cli;
10pub mod customization;
11pub mod daemon;
12pub mod debugger;
13pub mod development;
14pub mod experiments;
15pub mod git;
16pub mod intelligence;
17pub mod kernels;
18pub mod lsp;
19pub mod mcp;
20pub mod pi_runtime;
21pub mod tasks;
22pub mod testing;
23pub mod tools;
24pub mod trust;
25pub mod tui;
26pub mod workspace;
27
28use glass_browser::cli::args::Cli;
29
30pub use agents::{
31 AgentEvent, AgentId, AgentRegistry, AgentSnapshot, AgentSpec, AgentStatus, ResidentAgentBroker,
32};
33pub use browser::{BrowserRuntimeState, BrowserService, BrowserStartConfig};
34pub use customization::{Customization, GlassConfig, Skill};
35pub use experiments::{
36 ExperimentComparison, ExperimentEvidence, ExperimentManager, ExperimentRanking,
37 ExperimentSnapshot, ExperimentState, ExperimentTrustPolicy, ExperimentWeights,
38};
39pub use intelligence::{
40 CausalPath, DevelopmentEdge, DevelopmentIntelligence, DevelopmentNode, DevelopmentNodeKind,
41 ObservableDevelopmentEvent, ObservableEventInput, ReplayDiff,
42};
43pub use lsp::{LanguageServerConfig, LanguageService, LanguageServiceEvent};
44pub use pi_runtime::{
45 PINNED_PI_SDK_VERSION, PiReadiness, PiReadinessComponent, PiReadinessState, PiSessionRequest,
46};
47pub use tasks::{
48 RetryPolicy, TaskBudget, TaskEvidence, TaskId, TaskScheduler, TaskSnapshot, TaskSpec,
49 TaskState, VerificationRequirement,
50};
51pub use tools::{DevelopmentToolContext, DevelopmentToolRouter};
52pub use trust::{LocalTrustDecision, WorkspaceIdentity, WorkspaceTrust, WorkspaceTrustStore};
53pub use workspace::{DevelopmentWorkspace, SharedDevelopmentWorkspace};
54
55pub async fn dispatch(cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
60 if cli.mcp {
61 let backend = std::sync::Arc::new(mcp::DevelopmentMcpBackend::open(
62 std::env::current_dir()?,
63 cli.yolo,
64 )?);
65 return glass_browser::mcp::server::run_mcp_server_with_backend(&cli, backend).await;
66 }
67 if let Some(glass_browser::cli::args::Commands::Agent { action }) = &cli.command
68 && matches!(
69 action,
70 glass_browser::cli::args::AgentCommand::Tool { .. }
71 | glass_browser::cli::args::AgentCommand::ToolFile { .. }
72 )
73 {
74 let result = dispatch_external_tool(action, cli.yolo).await?;
75 println!("{}", serde_json::to_string_pretty(&result)?);
76 return Ok(());
77 }
78 if let Some(glass_browser::cli::args::Commands::Agent { action }) = &cli.command {
79 enforce_legacy_development_trust(&cli)?;
80 return cli::dispatch_agent(action, cli.yolo);
81 }
82 if let Some(glass_browser::cli::args::Commands::Daemon { action }) = &cli.command {
83 return daemon::dispatch(action).await;
84 }
85 if let Some(glass_browser::cli::args::Commands::Project { action }) = &cli.command {
86 enforce_legacy_development_trust(&cli)?;
87 return cli::dispatch_project(action);
88 }
89 if cli.command.is_none() && cli.prompt.is_none() && !cli.mcp {
90 return tui::run(std::env::current_dir()?, cli.tui_layout);
91 }
92 enforce_legacy_development_trust(&cli)?;
93 glass_browser::cli::runner::dispatch(cli).await
94}
95
96fn enforce_legacy_development_trust(cli: &Cli) -> Result<(), Box<dyn std::error::Error>> {
97 use glass_browser::cli::args::{AgentCommand, AgentHarness, Commands, ProjectCommand};
98
99 let (root, safe_static) = match cli.command.as_ref() {
100 Some(Commands::Project { action }) => {
101 let root = match action {
102 ProjectCommand::Inspect { root }
103 | ProjectCommand::Files { root }
104 | ProjectCommand::Search { root, .. }
105 | ProjectCommand::Read { root, .. }
106 | ProjectCommand::Edit { root, .. }
107 | ProjectCommand::Mkdir { root, .. }
108 | ProjectCommand::Rename { root, .. }
109 | ProjectCommand::Delete { root, .. }
110 | ProjectCommand::Diagnostics { root, .. }
111 | ProjectCommand::Run { root, .. }
112 | ProjectCommand::Test { root }
113 | ProjectCommand::Lint { root }
114 | ProjectCommand::Process { root, .. }
115 | ProjectCommand::Diff { root }
116 | ProjectCommand::Link { root, .. }
117 | ProjectCommand::Graph { root, .. }
118 | ProjectCommand::Breakpoint { root, .. }
119 | ProjectCommand::Timeline { root }
120 | ProjectCommand::Replay { root, .. }
121 | ProjectCommand::Neovim { root, .. }
122 | ProjectCommand::Experiment { root, .. }
123 | ProjectCommand::Attach { root, .. } => root,
124 };
125 let safe = matches!(
126 action,
127 ProjectCommand::Inspect { .. }
128 | ProjectCommand::Files { .. }
129 | ProjectCommand::Search { .. }
130 | ProjectCommand::Read { .. }
131 | ProjectCommand::Diff { .. }
132 | ProjectCommand::Graph { .. }
133 | ProjectCommand::Breakpoint { .. }
134 | ProjectCommand::Timeline { .. }
135 | ProjectCommand::Replay { .. }
136 );
137 (root, safe)
138 }
139 Some(Commands::Agent { action }) => {
140 let (root, safe) = match action {
141 AgentCommand::Doctor | AgentCommand::Setup { .. } | AgentCommand::Status => {
142 return Ok(());
143 }
144 AgentCommand::Hello { root, harness } => {
145 (root, matches!(harness, AgentHarness::Local))
146 }
147 AgentCommand::Prompt { root, harness, .. } => {
148 (root, matches!(harness, AgentHarness::Local))
149 }
150 AgentCommand::Tool { .. } | AgentCommand::ToolFile { .. } => return Ok(()),
151 AgentCommand::Steer { root, .. }
152 | AgentCommand::FollowUp { root, .. }
153 | AgentCommand::Models { root }
154 | AgentCommand::SetModel { root, .. }
155 | AgentCommand::Thinking { root, .. }
156 | AgentCommand::Abort { root }
157 | AgentCommand::NewSession { root } => (root, false),
158 };
159 (root, safe)
160 }
161 _ => return Ok(()),
162 };
163 let workspace = DevelopmentWorkspace::open(root)?;
164 if workspace.trust() == WorkspaceTrust::Untrusted && !safe_static {
165 return Err(format!(
166 "repository-controlled development execution is blocked for {}; open the TUI to inspect and trust this workspace",
167 workspace.root().display()
168 )
169 .into());
170 }
171 Ok(())
172}
173
174async fn dispatch_external_tool(
175 action: &glass_browser::cli::args::AgentCommand,
176 unrestricted: bool,
177) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
178 use crate::development::{Actor, ToolAuthorization, ToolCall};
179 use glass_browser::cli::args::AgentCommand;
180
181 let (call, root, allow_mutation, confirmed) = match action {
182 AgentCommand::Tool {
183 call,
184 root,
185 allow_mutation,
186 yes,
187 } => (
188 serde_json::from_str::<ToolCall>(call)?,
189 root,
190 *allow_mutation || unrestricted,
191 *yes || unrestricted,
192 ),
193 AgentCommand::ToolFile {
194 path,
195 root,
196 allow_mutation,
197 yes,
198 } if std::env::var_os("GLASS_DEV_DAEMON_SOCKET").is_some() => {
199 return daemon::forward_resident_tool_file(
200 path,
201 root,
202 *allow_mutation || unrestricted,
203 *yes || unrestricted,
204 )
205 .await;
206 }
207 AgentCommand::ToolFile {
208 path,
209 root,
210 allow_mutation,
211 yes,
212 } => (
213 daemon::read_private_tool_call(path)?,
214 root,
215 *allow_mutation || unrestricted,
216 *yes || unrestricted,
217 ),
218 _ => return Err("expected an external agent tool action".into()),
219 };
220 let mut workspace = DevelopmentWorkspace::open(root)?;
221 let context = DevelopmentToolContext {
222 authorization: ToolAuthorization {
223 actor: Actor::external("cli"),
224 allow_mutation,
225 confirmed,
226 },
227 initiator: None,
228 expected_generation: workspace.generation(),
229 expected_project_revision: workspace.project().revision(),
230 };
231 Ok(workspace.execute_tool(&call, &context)?)
232}