Agentic CLI coding assistant
Project description
CometCode
An agentic coding assistant for the terminal. Give it a task — it reads your codebase, reasons about what to change, proposes edits, and applies them only after you approve.
Built from scratch on LangGraph and OpenRouter, with a streaming Rich terminal UI.
Demo
mode → implement
╭────────────────────────────────────────────────────────────╮
│ add a /clear command that resets conversation history │
╰────────────────────────────────────────────────────────────╯
tool
● Read src/cli/commands.py done
└ def handle_command(text, console, state, orchestrator):
● Edit src/cli/commands.py done
└ [ok] replaced 1 occurrence(s)
╭──────────────────────────── response ──────────────────────╮
│ Added `/clear` — it calls `orchestrator.reset_history()` │
│ and clears `state.last_tool_history`. │
╰────────────────────────────────────────────────────────────╯
↓ ~3.2k tokens Cooked for 8s
Architecture
CometCode is structured as a LangGraph state machine where each node receives the full AgentState and returns state updates. The graph has two nodes — call_llm and execute_tools — connected by conditional edges that route based on the model's response type.
START → call_llm ──→ execute_tools ──┐
↑ │
└────────────────────────┘
(loops until final answer or budget exhausted)
Key design decisions:
-
AgentState as the single source of truth — conversation history, token budgets, tool-call counters, evidence notes, and attempt metadata all live in one typed dict that flows through the graph. Nodes are pure: they receive state, return a patch.
-
Dual invocation paths — models that support native function calling stream through
_invoke_native; models that don't fall back to_invoke_json_fallbackwith a structured Pydantic output schema. The rest of the system is unaware of the difference. -
Explicit budget enforcement — the graph tracks
tool_calls_used,consecutive_no_signal, andrepeat_call_streak. Hitting any limit triggers a soft-stop: the model is forced into a final answer using whatever evidence it collected, rather than erroring. -
Human-in-the-loop approval — mutating tools (
write_file,replace_text) are gated behind arequest_approvalcallback. After approval and execution, the loop returns to the LLM so it sees the updated file state before proposing the next edit — preventing duplicate proposals. -
Mode-scoped prompting —
explain,debug,refactor,implement, andplanmodes each carry different system instructions and tool permissions. Read-only modes (explain,plan) never receive mutating tools in their schema.
Features
- Five task modes —
explain,debug,refactor,implement,plan - Multi-model support — route to any OpenRouter model; native tool calling used when available, JSON schema fallback otherwise
- Streaming terminal UI — live spinner with real-time token count and elapsed timer; tool history with colored unified diffs for proposed changes
- Persistent conversation history — context carries across turns within a session; mode switches are surfaced to the model explicitly
- Slash command interface —
/mode,/model,/tools,/clear,/helpwith tab-completion - Self-limiting agent — budget caps on tool calls, no-signal streaks, and repeated identical calls; graceful degradation to best-effort answers
Stack
| Layer | Technology |
|---|---|
| Agent orchestration | LangGraph |
| LLM routing | OpenRouter via LangChain ChatOpenAI |
| Terminal UI | Rich + prompt_toolkit |
| Schema validation | Pydantic v2 |
| Python | 3.12+ |
Getting Started
git clone https://github.com/pritivi03/comet-code
cd comet-code
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
# Add your OpenRouter API key
echo "OPENROUTER_API_KEY=your_key_here" > .env
python -m main
Slash commands
| Command | Description |
|---|---|
/mode <name> |
Switch task mode (explain, debug, refactor, implement, plan) |
/model <name> |
Switch model (by alias, slug, or label) |
/tools |
Show last run tool history |
/clear |
Reset conversation history |
/help |
List all commands |
Project Layout
src/
cli/ # Terminal UI, input handling, rendering, slash commands
core/ # LangGraph graph, nodes, orchestrator, state schema
llm/ # OpenRouter client, model catalog, prompt builder
schemas/ # Pydantic models (events, tasks, state, tools)
tools/ # Tool implementations (read_file, search_text, replace_text, …)
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file comet_code-0.1.0.tar.gz.
File metadata
- Download URL: comet_code-0.1.0.tar.gz
- Upload date:
- Size: 73.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5901451769f00331e92ba70eab8eb774a3f76e664e182f42b26e294f4cf37e33
|
|
| MD5 |
1c5a5a38ad2f80c7edc12ad710fba0ff
|
|
| BLAKE2b-256 |
f6f186c0bad7517418a9f7c2bf1a33892b3914c0d065868c0955c56684d1c14a
|
File details
Details for the file comet_code-0.1.0-py3-none-any.whl.
File metadata
- Download URL: comet_code-0.1.0-py3-none-any.whl
- Upload date:
- Size: 43.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87af96649236c4237423759ffa48ff3c3b53e085fe89847a16f12958539cf5d1
|
|
| MD5 |
f9460e2b5912b4467cf74a441e112bba
|
|
| BLAKE2b-256 |
007e29fbbfbeaf691e9377c7dd9f286cab91d6dcafd0b2dd628421bc4af8f909
|