feat: shell output pagination and optimized read_file with seek

- Shell outputs > 8KB are truncated to first 500 chars
- Full output saved to .g3/sessions/<session_id>/tools/shell_stdout_<id>.txt
- LLM can use read_file with start/end to paginate through large outputs
- read_file now uses seek() for O(1) random access instead of reading entire file
- UTF-8 safe: reads extra bytes at boundaries to find valid char positions
- Falls back to lossy conversion for binary files (no panics)

Files changed:
- paths.rs: get_tools_output_dir(), generate_short_id()
- shell.rs: truncate_large_output() integration
- file_ops.rs: seek-based read_file_range() helper
- New test: read_file_utf8_test.rs
This commit is contained in:
Dhanji R. Prasanna
2026-01-16 09:16:16 +05:30
parent ce5183b296
commit 6bd9c51e8e
4 changed files with 396 additions and 99 deletions

View File

@@ -110,6 +110,17 @@ pub fn get_context_summary_file(session_id: &str) -> PathBuf {
get_session_logs_dir(session_id).join("context_summary.txt")
}
/// Get the tools output directory for a session.
/// Returns .g3/sessions/<session_id>/tools/
pub fn get_tools_output_dir(session_id: &str) -> PathBuf {
get_session_logs_dir(session_id).join("tools")
}
/// Generate a short unique ID (first 8 chars of UUID v4).
pub fn generate_short_id() -> String {
uuid::Uuid::new_v4().to_string()[..8].to_string()
}
#[cfg(test)]
mod tests {
use super::*;