1pub mod agent;
20pub mod cockpit;
22pub mod collaboration;
24pub mod debug;
26pub mod diff;
28pub mod editor;
30pub mod events;
32pub mod experiment;
34pub mod graph;
36pub mod language;
38pub mod neovim;
40pub mod process;
42pub mod project;
44pub mod remote_view;
46pub mod replay;
48pub mod search;
50
51pub use agent::{
53 AgentAuthorityContext, AgentContextPacket, AgentToolGateway, BrowserAgentContext, HarnessEvent,
54 HarnessRequest, LocalHarness, PiHarness, PiHarnessOptions, ToolAuthorization, ToolCall,
55 ToolDescriptor, ToolRegistry, resolve_context, resolve_context_with_browser,
56};
57pub use cockpit::{
59 AttentionItem, AttentionState, LocalCockpit, ReconnectCapsule, ReconnectCapsuleStore,
60 ResidentDevelopmentSessions, VerificationCard, VerificationCheck, attention_inbox,
61};
62pub use collaboration::{CollaborationBus, CollaborationEvent, EditAccess, EditClaim};
64pub use debug::{
66 SemanticBreakpoint, SemanticBreakpointHit, SemanticEntityState, SemanticSnapshot,
67 evaluate_breakpoints,
68};
69pub use diff::{ProjectDiff, build_diff};
71pub use editor::{
73 EditorCheckpoint, EditorComment, EditorCommentState, EditorProposal, EditorProposalState,
74 FoldRegion, SyntaxKind, SyntaxSpan, TextPosition, TextSelection, fold_regions,
75 matching_bracket, syntax_spans,
76};
77pub use events::{
79 Actor, ActorAuthority, ActorConnection, ActorKind, DevelopmentEvent, DevelopmentEventKind,
80 DevelopmentEventPage, Timeline,
81};
82pub use experiment::{
84 ExperimentComparison, ExperimentEvidence, ExperimentManager, ExperimentWorkspace,
85};
86pub use graph::{DevelopmentGraph, LinkEvidence, LinkProvenance, RuntimeLink, SourceLocation};
88pub use language::{
90 DiagnosticPosition, LanguageDiagnostic, LanguageDocument, LanguageResponse, LspClient,
91};
92pub use neovim::{NeovimCapability, probe_neovim, start_neovim};
94pub use process::{ProcessHealth, ProcessManager, ProcessSnapshot, ProcessState};
96pub use project::{
98 CommandConfig, EditorBuffer, FileEntry, FileKind, GlassProjectConfig, ProjectDetection,
99 ProjectTreeResult, ProjectWorkspace, detect_project,
100};
101pub use remote_view::{RemoteFrame, RemoteInput, RemoteView};
103pub use replay::{DevelopmentRevision, ReplayWindow, replay};
105pub use search::{SearchHit, SearchKind, fuzzy_score, rank};
107use std::{
108 fmt,
109 fs::OpenOptions,
110 io::{self, Read},
111 path::{Path, PathBuf},
112};
113
114pub const DEVELOPMENT_SCHEMA_VERSION: &str = "glass.development.v1";
116pub const DEVELOPMENT_EVENT_SCHEMA_VERSION: u32 = 1;
118pub const DEVELOPMENT_COCKPIT_SCHEMA_VERSION: u32 = 2;
120pub const MAX_FILE_BYTES: usize = 512 * 1024;
122pub const MAX_BUFFER_BYTES: usize = 1024 * 1024;
124pub const MAX_FILE_ENTRIES: usize = 2_048;
126pub const MAX_TIMELINE_EVENTS: usize = 512;
128pub const MAX_PROCESS_OUTPUT_BYTES: usize = 32 * 1024;
130
131pub(crate) fn read_bounded_utf8(
132 path: &Path,
133 limit: usize,
134 description: &str,
135) -> DevelopmentResult<String> {
136 let mut options = OpenOptions::new();
137 options.read(true);
138 #[cfg(unix)]
139 {
140 use std::os::unix::fs::OpenOptionsExt;
141 options.custom_flags(libc::O_NOFOLLOW);
142 }
143 let file = options.open(path)?;
144 let metadata = file.metadata()?;
145 if !metadata.is_file() {
146 return Err(DevelopmentError::InvalidInput(format!(
147 "{description} is not a regular file"
148 )));
149 }
150 if metadata.len() > limit as u64 {
151 return Err(DevelopmentError::InvalidInput(format!(
152 "{description} exceeds the {limit} byte limit"
153 )));
154 }
155 let mut bytes = Vec::with_capacity(metadata.len().min(limit as u64) as usize);
156 file.take(limit as u64 + 1).read_to_end(&mut bytes)?;
157 if bytes.len() > limit {
158 return Err(DevelopmentError::InvalidInput(format!(
159 "{description} exceeds the {limit} byte limit"
160 )));
161 }
162 String::from_utf8(bytes)
163 .map_err(|_| DevelopmentError::InvalidInput(format!("{description} is not valid UTF-8")))
164}
165
166pub type DevelopmentResult<T> = Result<T, DevelopmentError>;
168
169#[derive(Debug)]
171pub enum DevelopmentError {
172 Io(io::Error),
174 InvalidInput(String),
176 PathOutsideWorkspace(PathBuf),
178 NotFound(String),
180 Config(String),
182 Conflict(String),
184 Process(String),
186 Serialization(String),
188}
189
190impl fmt::Display for DevelopmentError {
191 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
192 match self {
193 Self::Io(error) => write!(formatter, "development I/O error: {error}"),
194 Self::InvalidInput(message) => {
195 write!(formatter, "invalid development input: {message}")
196 }
197 Self::PathOutsideWorkspace(path) => write!(
198 formatter,
199 "path escapes the project workspace: {}",
200 path.display()
201 ),
202 Self::NotFound(value) => write!(formatter, "development resource not found: {value}"),
203 Self::Config(message) => write!(formatter, "invalid glass.toml: {message}"),
204 Self::Conflict(message) => write!(formatter, "development conflict: {message}"),
205 Self::Process(message) => write!(formatter, "development process error: {message}"),
206 Self::Serialization(message) => {
207 write!(formatter, "development serialization error: {message}")
208 }
209 }
210 }
211}
212
213impl std::error::Error for DevelopmentError {}
214
215impl From<io::Error> for DevelopmentError {
216 fn from(error: io::Error) -> Self {
217 Self::Io(error)
218 }
219}
220
221impl From<serde_json::Error> for DevelopmentError {
222 fn from(error: serde_json::Error) -> Self {
223 Self::Serialization(error.to_string())
224 }
225}
226
227#[cfg(test)]
228mod tests {
229 use super::*;
230
231 #[test]
232 fn bounded_utf8_reader_rejects_oversized_and_invalid_files() {
233 let root =
234 std::env::temp_dir().join(format!("glass-bounded-reader-{}", std::process::id()));
235 let _ = std::fs::remove_dir_all(&root);
236 std::fs::create_dir_all(&root).unwrap();
237 let path = root.join("input");
238
239 std::fs::write(&path, b"bounded").unwrap();
240 assert_eq!(read_bounded_utf8(&path, 7, "fixture").unwrap(), "bounded");
241 std::fs::write(&path, b"oversized").unwrap();
242 assert!(read_bounded_utf8(&path, 8, "fixture").is_err());
243 std::fs::write(&path, [0xff]).unwrap();
244 assert!(read_bounded_utf8(&path, 1, "fixture").is_err());
245 #[cfg(unix)]
246 {
247 use std::os::unix::fs::symlink;
248 let target = root.join("target");
249 let link = root.join("link");
250 std::fs::write(&target, b"bounded").unwrap();
251 symlink(&target, &link).unwrap();
252 assert!(read_bounded_utf8(&link, 7, "fixture").is_err());
253 }
254
255 let _ = std::fs::remove_dir_all(root);
256 }
257}