Utils Module
220 files · ~60K linesThe Foundation — 220 files depended on by everything. No inbound dependencies. Contains files large enough to be standalone npm packages: a full Bash AST parser, a Claude message library, and more.
The Dependency Paradox
The 'Everything Depends on Me' Diagram
7 modules point inward. Utils points at nothing. This is the rarest shape in software — a true foundation layer.
The Giant Files — Bar Chart
Several utils files are larger than most npm packages. Each bar is proportional to actual line count.
utils/messages.ts5,512 linesClaude API message construction and transformation — the entire message pipeline in one file
utils/sessionStorage.ts5,105 linesSession persistence, YAML serialization, eval replay support
utils/hooks.ts5,022 linesReact hooks for terminal state, streaming, and input handling
utils/bash/bashParser.ts4,436 linesTree-sitter Bash AST parser for security analysis
utils/attachments.ts3,997 linesAttachment prefetch, image resize, PDF/notebook handling
utils/messages.ts — 5512 Lines Explained
The entire Claude API message pipeline lives in one file. Here's what those 5512 lines contain.
buildUserMessage(), buildAssistantMessage(), buildToolResultMessage() — factories for every message type
trimMessages(), projectToWindow() — how conversation is trimmed to fit the context limit
mergeMessages() — combines consecutive same-role messages (Anthropic API requires alternating roles)
Converts tool outputs into the format the LLM expects next turn — text, JSON, error messages
Injects image/PDF content into message turns using multi-content blocks
Message, ContentBlock, SDKMessage — TypeScript types for the entire message system
Bash AST Pipeline — From Command to Security Decision
bashParser.ts isn't regex — it's a full Tree-sitter AST parser. Here's the pipeline from raw string to allow/deny.
rm -rf /tmp/../etc['rm', '-rf', '/tmp/../etc']AST via Tree-sitter (not regex)recursive_delete=true, path_traversal=trueBLOCK: recursive delete detectedDetects rm -r, rm -rf, find -delete patterns and flags them HIGH_RISK regardless of path.
Identifies curl, wget, nc, ncat, ssh, scp — flags commands that exfiltrate data or establish connections.
Detects $(cmd), `cmd`, and heredoc patterns that could hide injected commands from simple string analysis.
Understands && and || chains — 'safe_cmd && rm -rf ~' is still flagged despite the leading safe command.
Identifies ../../../ traversal patterns and absolute paths pointing outside the project root.
Flags sudo, su, chmod 777, and similar privilege escalation commands for explicit user approval.
Key Files
utils/messages.ts5512 linesMessage creation, formatting, Claude API message manipulation
utils/sessionStorage.ts5105 linesSession persistence, YAML serialization, replay support
utils/hooks.ts5022 linesReact hooks for state, terminal input, streaming
utils/bash/bashParser.ts4436 linesTree-sitter Bash AST parser for security analysis
utils/attachments.ts3997 linesAttachment prefetch, image resize, PDF/notebook handling
utils/git.ts~800 linesGit helpers: branch detection, diff, staging, repo root resolution
BashTool calls bashParser.ts (which lives in Utils) for every command it runs.
The entire permissions system (yoloClassifier, rule matching, path checks) lives in utils/permissions/.
utils/messages.ts is the foundation for every message the query loop sends and receives.