- AGENTS.md - CLAUDE.md I think we need this because I know many or most of contributors is using AI for contributing This is not excessive
5.8 KiB
5.8 KiB
To Clankers
IRIS - Shell Auto-Completion Tool
IRIS is a lightweight, TTY-native shell auto-completion tool written in Go. No Electron, no GUI, no telemetry-runs on macOS and Linux with terminal emulators supporting ANSI colors.
Product Language
- Core value: Real-time command suggestions rendered directly in the terminal (like IntelliSense for shells)
- Alternative to Fig (sunset Sept 2024): Lighter, open-source, multi-shell (bash/zsh/fish), runs on any terminal
- Design principle: Native Go binary, pure TTY, one process per session
- Two suggestion modes: "spec" (command specs/flags) or "history" (shell history + frecency)
Key Architectural Files
PTY & Input Handling
root/wrapper.go:124-1230- Core event loop: PTY setup, terminal raw mode, keystroke interception, signal handling. Dense and critical.- Signal handling: SIGWINCH (resize), SIGUSR1 (reload)
- Input parsing: Enter, Tab, Shift+Tab, arrow keys, Ctrl+shortcuts
- Output bridging: Shell stdout to real stdout
- IPC listening: shell-to-iris communication via FD13
Suggestion Engine
root/suggestions.go:18-111- MergeResults: dedupes, scores, and ranks suggestions from history/spec/AI- Two paths: history mode (confidence-based) vs spec mode (frecency scoring)
- Frecency: uses
internal/scoringpackage with context signals (cwd, prev command, etc.) - AI injection: optional LLM suggestions via
internal/ai
Configuration & Themes
internal/config/config.go- Config struct, TOML parsing, hot-reload on file change- Default keybindings: Ctrl+R (toggle mode), Shift+Tab (toggle menu), Tab (select)
- Validation rules: modes (last/spec/history), shells (bash/zsh/fish), channels (stable/nightly)
- AutoDetectConfigChange: polls every 1s for config/theme changes
Terminal Rendering
integration/overlay.go- Overlay struct, menu rendering, ghost text, cursor tracking- ComputeCursorCol: parses ANSI escape sequences to track cursor position
- Renders using lipgloss v2 (charm.sh)
Data Structures
spec/spec.go:1-59- Suggestion, Spec, Subcommand, Option types- Suggestion: Cmd, Desc, Icon, Source ("history"/"spec"/"ai"), Confidence (0-100), Priority
- Registry: global map of spec definitions
Shell Integration
integration/shell/- Adapters for bash/zsh/fish- GetEnv: constructs shell environment with FD13 for IPC
- RecordSessionCommand: captures executed commands
Process Lifecycle
root/root.go:81-192- Watchdog parent process- Monitors child stderr for panics/crashes
- Restores terminal state on crash
- Triggers rescue shell and logs to
~/.iris/crash.log
Commands
root/config_cmd.go-iris config init/showroot/theme_cmd.go-iris theme initroot/uninstall.go-iris uninstall(cleanup)root/update.go- Background version check
Common Flows
User Types Character
- Shell process sends query via FD13 to iris
wrapper.go:480-582receives on IPC scannerMergeResultsscores suggestions (history or spec mode)overlay.Render()outputs menu to stdout- Terminal displays overlay above prompt
User Presses Tab (Select Suggestion)
wrapper.go:813-843intercepts Tab- Gets current selection from overlay
- If spec mode: adds trailing space
- Writes to PTY (
0x15= Ctrl+U clears, then new text) - Clears overlay, triggers render
User Presses Ctrl+R (Toggle Mode)
wrapper.go:773-795intercepts Ctrl+R- Swaps
activeModebetween "spec" and "history" - Saves mode to state file for next session
- Re-renders menu with new scoring
Terminal Resizes (SIGWINCH)
wrapper.go:213-215catches signalpty.InheritSizesyncs PTY to new size- Overlay re-renders with new width
Config Reloads
- User edits
~/.config/iris/config.toml config.AutoDetectConfigChangepolls, detects mtime change- Calls
config.Load(), updates global config - Callback triggers overlay re-render if visible
Design Patterns
- Mutex-protected state: naiveBuffer, cursorOffset, activeMode (avoid races in goroutines)
- Atomic flags: isCommandActive, userNavigated, disableGhostText (fast checks without locks)
- Debounced rendering: 20ms timer on keystroke to batch render calls
- AI suggestions: separate debounce (400ms default), cancellable context
- Ghost text: faded hint of next completion, cleared on user navigation
- Frecency scoring: combines frequency + recency + context signals (cwd, prev command, exit code)
Comments
- NO FUNCTION COMMENTS UNLESS IT'S TOO COMPLEX TO UNDERSTAND
- NO TOP FILE COMMENTS
- NO COMMENT LONGER THAN 2 LINES UNLESS ASKED EXPLICITLY
- ONLY COMMENT WHERE IT'S IMPORTANT TO UNDERSTAND
- THE COMMENT SHOULD EXPLAIN "WHY" OR "WHY WE NEED THIS" INSTEAD OF TELLING "WHAT IT DOES"
Configuration Paths
- Config:
~/.config/iris/config.toml - Theme:
~/.config/iris/theme.toml - State:
~/.local/share/iris/state.toml(or XDG_DATA_HOME) - Logs:
~/.local/share/iris/iris.log(or XDG_CACHE_HOME) - Crash:
~/.iris/crash.log
Testing
- Test files match source:
*_test.go(unit tests, no integration tests yet) - Mocks for git provider in
root/mock_git_provider_test.go spec/cobra_complete_test.gotests command completion
Verify
- Run
just testorgo test ./... -vto make sure all tests passed - Run
just lintorgolangci-lint run ./...to make sure zero linter problems - Run
go vet ./...to make sure there is no suspicious constructs, structural mistakes, and high-probability bugs - Run
go fix ./...to modernize all Go code
Commits
- If the agent is the one who commits, make sure follow the conventional commits style
- The commit should be as short as possible, but enough to describe changes
Minimal reference for rapid navigation. Read files directly-do not fabricate code from this index.