Skip to main content

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_fallback with 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, and repeat_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 a request_approval callback. 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 promptingexplain, debug, refactor, implement, and plan modes each carry different system instructions and tool permissions. Read-only modes (explain, plan) never receive mutating tools in their schema.


Features

  • Five task modesexplain, 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, /help with 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

pip install comet-code
# The first run will prompt for your OpenRouter API key.
# You can also set it later via `/key set <key>` or the `OPENROUTER_API_KEY` environment variable.
comet

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

comet_code-0.1.1.tar.gz (73.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

comet_code-0.1.1-py3-none-any.whl (43.0 kB view details)

Uploaded Python 3

File details

Details for the file comet_code-0.1.1.tar.gz.

File metadata

  • Download URL: comet_code-0.1.1.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

Hashes for comet_code-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b3fddc110acb505f732cf2d66eb07ac1593f5badfda170a3001b1839aa050df6
MD5 fa8c706c31a001c2795d15fae8ea7488
BLAKE2b-256 8ca9b5efdb17b9668063b6d520fc7e4f0f3e8aeb2a83f84ad0e76a4c9f1d4eb7

See more details on using hashes here.

File details

Details for the file comet_code-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: comet_code-0.1.1-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

Hashes for comet_code-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 812ca85ab0167bda78203d344456e99d0e5fef7ecc29f3a13c54e5ed2242b7dc
MD5 6d26413a3248b0e85fdf3a40a0d88b11
BLAKE2b-256 f8ad13557b57ed1ab4e27873bea1064966b1d1809008fe25c7643ec135bf8bc3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page