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//!
7//! The interactive TUI separates terminal rendering from workspace work. A
8//! snapshot worker hydrates resident projections and executes governed browser,
9//! Git, agent, and project operations off the input loop. The UI applies
10//! versioned snapshots, keeps drafts and modal state local, and restores the
11//! terminal without waiting for an active bounded job.
12//!
13//! Desktop destinations are Agent, Code, App, Terminal, Tasks, Git, Debug, and
14//! More. The shared composer dock is available on every surface. Per-turn
15//! [`AgentTurnMode`] is Ask, Plan, or Agent (default Agent). Ask and Plan are
16//! fail-closed for mutations. [`SessionTodoList`] is the workspace-local Agent
17//! checklist persisted at `.glass/todos/session.json`; it is not the overnight
18//! task DAG.
19//!
20//! ## Public API
21//!
22//! [`DevelopmentWorkspace`] owns the resident project runtime and its trust
23//! boundary. [`SharedDevelopmentWorkspace`] is the thread-safe handle used by
24//! the TUI, daemon, MCP, and agent services. [`DevelopmentToolRouter`] exposes
25//! governed tool execution, while [`PiReadiness`] and [`PiSessionRequest`]
26//! describe the managed Pi runtime surface.
27//!
28//! The focused browser-only API lives in
29//! [`glass_browser`](https://docs.rs/glass-browser).
30//!
31//! The docs.rs page documents the Rust library API. Published pages match the
32//! crate version they were built from. Installed command behavior is specified
33//! in the [CLI reference](https://github.com/wanazhar/glass/blob/main/docs/cli.md).
34//! Current-checkout TUI behavior is specified in the
35//! [Development TUI architecture](https://github.com/wanazhar/glass/blob/main/docs/architecture/development-tui.md)
36//! guide.
37//!
38//! ## Quick start
39//!
40//! ```rust,no_run
41//! use glass_dev::DevelopmentWorkspace;
42//!
43//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
44//! let workspace = DevelopmentWorkspace::open(".")?;
45//! println!("{}", workspace.root().display());
46//! # Ok(())
47//! # }
48//! ```
49//!
50//! ## Modules
51//!
52//! [`agents`] owns resident Pi scheduling and evidence. [`browser`] provides
53//! the development browser service. [`development`] contains files, editors,
54//! processes, language services, and project execution. [`tools`] and
55//! [`trust`] enforce governed operations, while [`tui`] and [`workspace`]
56//! connect those services to the interactive product.
57
58/// Resident Pi agent scheduling, evidence, and lifecycle control.
59pub mod agents;
60/// Development-browser service owned by the resident workspace worker.
61pub mod browser;
62/// Command-line argument and dispatch support for Glass Dev.
63pub mod cli;
64/// User and project customization loading.
65pub mod customization;
66/// Resident development daemon integration.
67pub mod daemon;
68/// Debugging and semantic breakpoint support.
69pub mod debugger;
70/// Files, editors, processes, language services, and project execution.
71pub mod development;
72/// Experiment orchestration and comparison.
73pub mod experiments;
74/// One-shot adapters for installed external coding agents.
75pub mod external_agents;
76/// Configured fill-in-the-middle provider for editor ghosts.
77pub mod fim;
78/// Governed Git workspace operations.
79pub mod git;
80/// GitHub status, review, and pull-request shipping operations.
81pub mod github;
82/// Discovery and safe handoff of installed coding harnesses.
83pub mod harness;
84/// Development graph and causal intelligence projections.
85pub mod intelligence;
86/// Kernel process and runtime integration.
87pub mod kernels;
88/// LSP-facing language service integration.
89pub mod lsp;
90/// MCP server and tool integration.
91pub mod mcp;
92/// Managed Pi runtime readiness and sessions.
93pub mod pi_runtime;
94/// Task scheduling, evidence, and verification requirements.
95pub mod tasks;
96/// Test execution and result collection.
97pub mod testing;
98/// Workspace-local Agent todos persisted at `.glass/todos/session.json` (not the overnight task DAG).
99pub mod todos;
100/// Governed development-tool routing.
101pub mod tools;
102/// Workspace trust decisions and persistence.
103pub mod trust;
104/// Interactive Glass Dev terminal application.
105pub mod tui;
106/// Workspace ownership and shared handles.
107pub mod workspace;
108
109use glass_browser::cli::args::Cli;
110
111/// Resident Pi agent types and scheduler handles.
112pub use agents::{
113    AgentEvent, AgentId, AgentRegistry, AgentSnapshot, AgentSpec, AgentStatus, ResidentAgentBroker,
114};
115/// Development browser configuration, state, and service handle.
116pub use browser::{BrowserRuntimeState, BrowserService, BrowserStartConfig};
117/// User-facing customization and skill configuration.
118pub use customization::{Customization, GlassConfig, Skill};
119/// Experiment management and comparison types.
120pub use experiments::{
121    ExperimentComparison, ExperimentEvidence, ExperimentManager, ExperimentRanking,
122    ExperimentSnapshot, ExperimentState, ExperimentTrustPolicy, ExperimentWeights,
123};
124/// Development intelligence graph and replay types.
125pub use intelligence::{
126    CausalPath, DevelopmentEdge, DevelopmentIntelligence, DevelopmentNode, DevelopmentNodeKind,
127    ObservableDevelopmentEvent, ObservableEventInput, ReplayDiff,
128};
129/// Language-service configuration and event types.
130pub use lsp::{LanguageServerConfig, LanguageService, LanguageServiceEvent};
131/// Pi readiness and managed-session request types.
132pub use pi_runtime::{
133    PINNED_PI_SDK_VERSION, PiReadiness, PiReadinessComponent, PiReadinessState, PiSessionRequest,
134};
135/// Task scheduling, retry, evidence, and verification types.
136pub 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};
141/// Workspace-local Agent todos persisted at `.glass/todos/session.json` (not the overnight task DAG).
142pub use todos::{SessionTodo, SessionTodoList, TodoStatus};
143/// Governed tool execution context and router.
144pub use tools::{DevelopmentToolContext, DevelopmentToolRouter};
145/// Workspace trust identities, decisions, and persistence.
146pub use trust::{LocalTrustDecision, WorkspaceIdentity, WorkspaceTrust, WorkspaceTrustStore};
147/// Shared workspace handle and per-turn Ask, Plan, or Agent composer mode.
148pub use workspace::{AgentTurnMode, DevelopmentWorkspace, SharedDevelopmentWorkspace};
149
150/// Dispatch the full Glass Development Environment.
151///
152/// Resident development commands are handled here. Browser-only commands use
153/// the public browser runtime through the one-way crate dependency.
154pub 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}