How rsrohan99/tig works
Project type and purpose
• Tig is an open-source, terminal-based autonomous AI coding agent.
• It orchestrates multiple LLMs (via LlamaIndex workflows), analyzes and mutates a local codebase (using Tree-sitter, ripgrep, diff-match-patch), executes shell commands, and writes or updates files.
File structure
• Top-level: configuration (.env, pyproject.toml), README, CLI entry point.
• src/tig/modes.py: defines high-level modes (architect, code).
• src/tig/prompts: static prompt templates (system, task, environment, objectives, rules) and per-tool prompt docs.
• src/tig/services: integrations and wrappers
• llms.py → LLM provider adapter
• command_runner.py → shell execution
• tree_sitter/ → code parsing and syntax checking
• src/tig/tools: concrete implementations of “actions” (list_files, read_file, write_to_file, apply_diff, etc.) invoked by the agent.
• src/tig/utils: helper functions (intro messaging, verbose logging, XML templating, syntax checker utilities).
• src/tig/workflows/tig.py: orchestrates the overall LlamaIndex Workflow, bringing together modes, prompts, services, and tools.
README for insights
• Supported LLMs: Google Gemini, OpenAI, Claude, etc. → LLM abstraction layer.
• Dependencies: ripgrep, Tree-sitter, diff-match-patch.
• Two primary modes: Architect (design step) vs Code (implementation step).
• Interaction flow: user issues task → agent loops prompt→LLM→tool execution→update code.
Main components
a. CLI Interface
• Entry point “tig” CLI
• Parses flags (mode, auto-approve)
b. Workflow Orchestrator
• LlamaIndex Workflow defined in workflows/tig.py
• Controls conversation loop and task state
c. Prompt Manager
• Loads and renders prompt templates (src/tig/prompts/*)
• Supplies context (environment, objectives, rules)
d. LLM Provider Adapter
• Abstracts calls to different LLM providers (llms.py)
e. Tool Executor
• Exposes standardized tool API for codebase operations
• Tools: list_files, read_file, write_to_file, apply_diff, execute_command, etc.
f. Codebase Analyzers
• Tree-sitter parser & queries for function/class definitions, syntax checks
• Ripgrep for regex searches
g. Diff Engine
• Google diff-match-patch for computing and displaying deltas
h. Local File System & Shell
• Underlying resources: file read/write, shell command execution
i. External Services
• LLM endpoints (OpenAI, Google, Claude, etc.)
Relationships and data flows
• User CLI input → Workflow Orchestrator
• Orchestrator pulls prompt templates → Prompt Manager → renders full prompt
• Rendered prompt → LLM Adapter → external LLM → returns response
• Response → parsed by Orchestrator → decides tool to invoke
• Tool Executor → invokes Codebase Analyzer or Shell Command
• Analyzer/Command → returns result → Orchestrator
• Diff Engine computes changes → File System updated via Tool → Orchestrator loops or terminates
Architectural patterns & design principles
• Modular “tool” pattern: separates LLM reasoning from actionable code operations
• Dependency inversion: service interfaces (LLM, command runner, parser) abstract implementations
• Workflow orchestration: single coordinator managing state and multi-turn interactions
• Template-driven prompts for consistency and maintainability