Skip to main content

glass_dev/
lib.rs

1//! Glass Development Environment runtime.
2//!
3//! This crate owns the resident software-development workspace used by the
4//! `glass` product. Browser intelligence remains provided by the one-way
5//! `glass-browser` dependency.
6
7pub mod agents;
8pub mod browser;
9pub mod customization;
10pub mod daemon;
11pub mod debugger;
12pub mod experiments;
13pub mod git;
14pub mod intelligence;
15pub mod kernels;
16pub mod lsp;
17pub mod mcp;
18pub mod testing;
19pub mod tools;
20pub mod tui;
21pub mod workspace;
22
23use glass_browser::cli::args::Cli;
24
25pub use agents::{
26    AgentEvent, AgentId, AgentRegistry, AgentSnapshot, AgentSpec, AgentStatus, ResidentAgentBroker,
27};
28pub use browser::{BrowserRuntimeState, BrowserService, BrowserStartConfig};
29pub use customization::{Customization, GlassConfig, Skill};
30pub use experiments::{
31    ExperimentComparison, ExperimentEvidence, ExperimentManager, ExperimentRanking,
32    ExperimentSnapshot, ExperimentState,
33};
34pub use intelligence::{
35    CausalPath, DevelopmentEdge, DevelopmentIntelligence, DevelopmentNode, DevelopmentNodeKind,
36    ObservableDevelopmentEvent, ObservableEventInput, ReplayDiff,
37};
38pub use lsp::{LanguageServerConfig, LanguageService, LanguageServiceEvent};
39pub use tools::{DevelopmentToolContext, DevelopmentToolRouter};
40pub use workspace::{DevelopmentWorkspace, SharedDevelopmentWorkspace};
41
42/// Dispatch the full Glass Development Environment.
43///
44/// Command-surface extraction from the browser crate is incremental during
45/// the 0.3.4 ownership migration. The product entry point lives here so each
46/// resident service can move without changing the installed `glass` binary.
47pub async fn dispatch(cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
48    if cli.mcp {
49        let backend = std::sync::Arc::new(mcp::DevelopmentMcpBackend::open(
50            std::env::current_dir()?,
51            cli.yolo,
52        )?);
53        return glass_browser::mcp::server::run_mcp_server_with_backend(&cli, backend).await;
54    }
55    if let Some(glass_browser::cli::args::Commands::Agent { action }) = &cli.command
56        && matches!(
57            action,
58            glass_browser::cli::args::AgentCommand::Tool { .. }
59                | glass_browser::cli::args::AgentCommand::ToolFile { .. }
60        )
61    {
62        let result = dispatch_external_tool(action, cli.yolo).await?;
63        println!("{}", serde_json::to_string_pretty(&result)?);
64        return Ok(());
65    }
66    if let Some(glass_browser::cli::args::Commands::Daemon { action }) = &cli.command {
67        return daemon::dispatch(action).await;
68    }
69    if cli.command.is_none() && cli.prompt.is_none() && !cli.mcp {
70        return tui::run(std::env::current_dir()?, cli.tui_layout);
71    }
72    glass_browser::cli::runner::dispatch(cli).await
73}
74
75async fn dispatch_external_tool(
76    action: &glass_browser::cli::args::AgentCommand,
77    unrestricted: bool,
78) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
79    use glass_browser::cli::args::AgentCommand;
80    use glass_browser::development::{Actor, ToolAuthorization, ToolCall};
81
82    let (call, root, allow_mutation, confirmed) = match action {
83        AgentCommand::Tool {
84            call,
85            root,
86            allow_mutation,
87            yes,
88        } => (
89            serde_json::from_str::<ToolCall>(call)?,
90            root,
91            *allow_mutation || unrestricted,
92            *yes || unrestricted,
93        ),
94        AgentCommand::ToolFile {
95            path,
96            root,
97            allow_mutation,
98            yes,
99        } if std::env::var_os("GLASS_DEV_DAEMON_SOCKET").is_some() => {
100            return daemon::forward_resident_tool_file(
101                path,
102                root,
103                *allow_mutation || unrestricted,
104                *yes || unrestricted,
105            )
106            .await;
107        }
108        AgentCommand::ToolFile {
109            path,
110            root,
111            allow_mutation,
112            yes,
113        } => (
114            daemon::read_private_tool_call(path)?,
115            root,
116            *allow_mutation || unrestricted,
117            *yes || unrestricted,
118        ),
119        _ => return Err("expected an external agent tool action".into()),
120    };
121    let mut workspace = DevelopmentWorkspace::open(root)?;
122    let context = DevelopmentToolContext {
123        authorization: ToolAuthorization {
124            actor: Actor::external("cli"),
125            allow_mutation,
126            confirmed,
127        },
128        expected_generation: workspace.generation(),
129        expected_project_revision: workspace.project().revision(),
130    };
131    Ok(workspace.execute_tool(&call, &context)?)
132}