System Architecture
Explore the internal pipeline that maps, stores, and compresses repository contexts locally.
MCP Server Transport
Handles Model Context Protocol messages over local stdio, registers the ten tools, and advertises the costwise-session guidance through the protocol instructions field so every client receives it automatically.
Relevant repository paths
- internal/mcpserver/server.go
- internal/mcpserver/tools.go
- internal/skill/
Pipeline Subcomponents
1. Tree-sitter AST Parser
Statically parses source code to compile tree nodes. Maps variables, structures, and function bounds to extract symbol-level boundaries.
2. SQLite Knowledge Store
Stores relational data maps including file hashes, tag names, call trees, and references. Optimized index triggers ensure query results return in microseconds.
3. Watchdog Daemon
Passive background file watcher using system notification boundaries. When files are saved, watchdog re-parses only the changed file paths in 8ms.
Execution Flow: Code Sync to Tool Query
This flowchart traces the lifecycle of a code edit and how it translates to token-saving context injection.
Relational Index Database Schema
CostWise maps directory relationships statically into four unified SQLite tables.
- • hash TEXT PRIMARY KEY
- • path TEXT UNIQUE
- • indexed_at TIMESTAMP
- • id INTEGER PRIMARY KEY
- • file_path TEXT
- • name TEXT
- • kind TEXT (func, struct, interface)
- • start_line INTEGER
- • end_line INTEGER