chcode 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- chcode-0.1.0/.github/workflows/publish.yml +28 -0
- chcode-0.1.0/.github/workflows/test.yml +32 -0
- chcode-0.1.0/.gitignore +14 -0
- chcode-0.1.0/LICENSE +21 -0
- chcode-0.1.0/PKG-INFO +275 -0
- chcode-0.1.0/README.md +231 -0
- chcode-0.1.0/README_zh.md +239 -0
- chcode-0.1.0/assets/chagent.png +0 -0
- chcode-0.1.0/assets/chcode.png +0 -0
- chcode-0.1.0/assets/test.mp4 +0 -0
- chcode-0.1.0/chcode/__init__.py +0 -0
- chcode-0.1.0/chcode/__main__.py +5 -0
- chcode-0.1.0/chcode/agent_setup.py +395 -0
- chcode-0.1.0/chcode/agents/__init__.py +0 -0
- chcode-0.1.0/chcode/agents/definitions.py +158 -0
- chcode-0.1.0/chcode/agents/loader.py +104 -0
- chcode-0.1.0/chcode/agents/runner.py +159 -0
- chcode-0.1.0/chcode/chat.py +1630 -0
- chcode-0.1.0/chcode/cli.py +142 -0
- chcode-0.1.0/chcode/config.py +571 -0
- chcode-0.1.0/chcode/display.py +325 -0
- chcode-0.1.0/chcode/prompts.py +640 -0
- chcode-0.1.0/chcode/session.py +149 -0
- chcode-0.1.0/chcode/skill_manager.py +165 -0
- chcode-0.1.0/chcode/utils/__init__.py +3 -0
- chcode-0.1.0/chcode/utils/enhanced_chat_openai.py +368 -0
- chcode-0.1.0/chcode/utils/git_checker.py +38 -0
- chcode-0.1.0/chcode/utils/git_manager.py +261 -0
- chcode-0.1.0/chcode/utils/modelscope_ratelimit.py +65 -0
- chcode-0.1.0/chcode/utils/multimodal.py +268 -0
- chcode-0.1.0/chcode/utils/shell/__init__.py +17 -0
- chcode-0.1.0/chcode/utils/shell/output.py +63 -0
- chcode-0.1.0/chcode/utils/shell/provider.py +128 -0
- chcode-0.1.0/chcode/utils/shell/result.py +14 -0
- chcode-0.1.0/chcode/utils/shell/semantics.py +55 -0
- chcode-0.1.0/chcode/utils/shell/session.py +159 -0
- chcode-0.1.0/chcode/utils/skill_loader.py +565 -0
- chcode-0.1.0/chcode/utils/text_utils.py +14 -0
- chcode-0.1.0/chcode/utils/tool_result_pipeline.py +244 -0
- chcode-0.1.0/chcode/utils/tools.py +1724 -0
- chcode-0.1.0/chcode/vision_config.py +371 -0
- chcode-0.1.0/docs/plans/2026-04-23-vision-tool.md +66 -0
- chcode-0.1.0/pyproject.toml +82 -0
- chcode-0.1.0/tests/__init__.py +0 -0
- chcode-0.1.0/tests/conftest.py +19 -0
- chcode-0.1.0/tests/test_agent_setup.py +54 -0
- chcode-0.1.0/tests/test_agent_setup_extended.py +262 -0
- chcode-0.1.0/tests/test_chat_helpers.py +130 -0
- chcode-0.1.0/tests/test_chat_repl.py +2282 -0
- chcode-0.1.0/tests/test_chat_repl_extended.py +2484 -0
- chcode-0.1.0/tests/test_cli.py +32 -0
- chcode-0.1.0/tests/test_cli_extended.py +414 -0
- chcode-0.1.0/tests/test_config.py +116 -0
- chcode-0.1.0/tests/test_config_extended.py +1077 -0
- chcode-0.1.0/tests/test_config_pure.py +61 -0
- chcode-0.1.0/tests/test_coverage_gaps.py +2979 -0
- chcode-0.1.0/tests/test_definitions.py +29 -0
- chcode-0.1.0/tests/test_display.py +102 -0
- chcode-0.1.0/tests/test_display_extended.py +737 -0
- chcode-0.1.0/tests/test_enhanced_chat_openai.py +90 -0
- chcode-0.1.0/tests/test_enhanced_chat_openai_extended.py +732 -0
- chcode-0.1.0/tests/test_git_checker.py +34 -0
- chcode-0.1.0/tests/test_git_manager.py +114 -0
- chcode-0.1.0/tests/test_git_manager_extended.py +584 -0
- chcode-0.1.0/tests/test_loader.py +131 -0
- chcode-0.1.0/tests/test_multimodal.py +412 -0
- chcode-0.1.0/tests/test_multimodal_middleware.py +141 -0
- chcode-0.1.0/tests/test_output.py +60 -0
- chcode-0.1.0/tests/test_prompt_toolkit_ui.py +2271 -0
- chcode-0.1.0/tests/test_prompts.py +389 -0
- chcode-0.1.0/tests/test_provider.py +73 -0
- chcode-0.1.0/tests/test_result.py +27 -0
- chcode-0.1.0/tests/test_runner.py +51 -0
- chcode-0.1.0/tests/test_runner_extended.py +174 -0
- chcode-0.1.0/tests/test_semantics.py +78 -0
- chcode-0.1.0/tests/test_session.py +123 -0
- chcode-0.1.0/tests/test_shell_session.py +41 -0
- chcode-0.1.0/tests/test_shell_session_extended.py +353 -0
- chcode-0.1.0/tests/test_skill_loader.py +140 -0
- chcode-0.1.0/tests/test_skill_loader_extended.py +353 -0
- chcode-0.1.0/tests/test_skill_manager_extended.py +262 -0
- chcode-0.1.0/tests/test_tool_result_pipeline.py +319 -0
- chcode-0.1.0/tests/test_tools.py +91 -0
- chcode-0.1.0/tests/test_tools_extended.py +2538 -0
- chcode-0.1.0/tests/test_vision.py +486 -0
- chcode-0.1.0/tests/test_vision_config.py +577 -0
- chcode-0.1.0/uv.lock +1818 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
environment: pypi
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v4
|
|
20
|
+
|
|
21
|
+
- name: Set up Python
|
|
22
|
+
run: uv python install 3.13
|
|
23
|
+
|
|
24
|
+
- name: Build package
|
|
25
|
+
run: uv build
|
|
26
|
+
|
|
27
|
+
- name: Publish to PyPI
|
|
28
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
strategy:
|
|
8
|
+
matrix:
|
|
9
|
+
os: [ubuntu-latest, windows-latest]
|
|
10
|
+
python-version: ["3.13"]
|
|
11
|
+
runs-on: ${{ matrix.os }}
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Install uv
|
|
16
|
+
uses: astral-sh/setup-uv@v4
|
|
17
|
+
|
|
18
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
19
|
+
run: uv python install ${{ matrix.python-version }}
|
|
20
|
+
|
|
21
|
+
- name: Install dependencies
|
|
22
|
+
run: uv sync --extra test
|
|
23
|
+
|
|
24
|
+
- name: Run tests with coverage
|
|
25
|
+
run: uv run pytest --cov=chcode --cov-report=term-missing --cov-report=xml
|
|
26
|
+
|
|
27
|
+
- name: Upload coverage
|
|
28
|
+
if: matrix.os == 'ubuntu-latest'
|
|
29
|
+
uses: actions/upload-artifact@v4
|
|
30
|
+
with:
|
|
31
|
+
name: coverage-report
|
|
32
|
+
path: coverage.xml
|
chcode-0.1.0/.gitignore
ADDED
chcode-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Flymo Han
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
chcode-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chcode
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Terminal-based AI coding agent with typer+rich
|
|
5
|
+
Project-URL: Homepage, https://github.com/ScarletMercy/chcode
|
|
6
|
+
Project-URL: Repository, https://github.com/ScarletMercy/chcode
|
|
7
|
+
Project-URL: Issues, https://github.com/ScarletMercy/chcode/issues
|
|
8
|
+
Author-email: Flymo Han <minimizeball@foxmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai,cli,coding-agent,langchain,rich,typer
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
19
|
+
Requires-Python: >=3.13
|
|
20
|
+
Requires-Dist: aiofiles>=25.1.0
|
|
21
|
+
Requires-Dist: aiosqlite>=0.22.1
|
|
22
|
+
Requires-Dist: bs4>=0.0.2
|
|
23
|
+
Requires-Dist: charset-normalizer>=3.4.0
|
|
24
|
+
Requires-Dist: httpx>=0.28.0
|
|
25
|
+
Requires-Dist: langchain-openai>=1.1.10
|
|
26
|
+
Requires-Dist: langchain>=1.2.10
|
|
27
|
+
Requires-Dist: langgraph-checkpoint-sqlite>=3.0.3
|
|
28
|
+
Requires-Dist: markdownify>=0.14.0
|
|
29
|
+
Requires-Dist: pillow>=12.2.0
|
|
30
|
+
Requires-Dist: prompt-toolkit>=3.0.0
|
|
31
|
+
Requires-Dist: psutil>=6.0.0
|
|
32
|
+
Requires-Dist: pyyaml>=6.0.0
|
|
33
|
+
Requires-Dist: questionary>=2.1.0
|
|
34
|
+
Requires-Dist: rich>=13.9.0
|
|
35
|
+
Requires-Dist: tavily>=1.1.0
|
|
36
|
+
Requires-Dist: typer>=0.15.0
|
|
37
|
+
Provides-Extra: test
|
|
38
|
+
Requires-Dist: pytest-asyncio>=0.25.0; extra == 'test'
|
|
39
|
+
Requires-Dist: pytest-cov>=6.0.0; extra == 'test'
|
|
40
|
+
Requires-Dist: pytest-mock>=3.14.0; extra == 'test'
|
|
41
|
+
Requires-Dist: pytest-timeout>=2.3.0; extra == 'test'
|
|
42
|
+
Requires-Dist: pytest>=8.0.0; extra == 'test'
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
|
|
45
|
+
# ChCode
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
███████╗ ██╗ ██╗ ███████╗ ██████╗ █████╗ ████████╗
|
|
49
|
+
██╔═════╝ ██║ ██║ ██╔═════╝ ██╔═══██╗ ██╔══██╗ ██╔═════╝
|
|
50
|
+
██║ ████████║ ██║ ██║ ██║ ██║ ██╗ ████████╗
|
|
51
|
+
██║ ██╔═══██║ ██║ ██║ ██║ ██║ ██╔╝ ██╔═════╝
|
|
52
|
+
████████╗ ██║ ██║ ████████╗ ╚██████╔╝ █████╔═╝ ████████╗
|
|
53
|
+
╚══════╝ ╚═╝ ╚═╝ ╚══════╝ ╚═════╝ ╚════╝ ╚══════╝
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Terminal-based AI coding agent, built with LangChain + Typer + Rich.
|
|
57
|
+
|
|
58
|
+
> **Why "ChCode"?** The original prototype was a tkinter + LangChain app called **chat-agent** (chagent). When it evolved into a CLI tool, the name became **ChCode** — chat-agent, meet code.
|
|
59
|
+
|
|
60
|
+
<details>
|
|
61
|
+
<summary>📸 chagent — the original tkinter prototype</summary>
|
|
62
|
+
<img src="https://raw.githubusercontent.com/ScarletMercy/chcode/main/assets/chagent.png" alt="chagent prototype" width="600"/>
|
|
63
|
+
</details>
|
|
64
|
+
|
|
65
|
+
> 6000+ lines of Python, 14 built-in tools, full session persistence, git-aware workflow.
|
|
66
|
+
|
|
67
|
+

|
|
68
|
+

|
|
69
|
+
|
|
70
|
+
[中文文档](README_zh.md)
|
|
71
|
+
|
|
72
|
+
<img src="https://raw.githubusercontent.com/ScarletMercy/chcode/main/assets/chcode.png" alt="ChCode main interface" width="800"/>
|
|
73
|
+
|
|
74
|
+
## Features
|
|
75
|
+
|
|
76
|
+
### Model Management
|
|
77
|
+
|
|
78
|
+
- Compatible with **all OpenAI-compatible APIs** (OpenAI, DeepSeek, Qwen, GLM, Claude via proxy, etc.)
|
|
79
|
+
- Built-in quick setup for **ModelScope**, **LongCat**, and major providers
|
|
80
|
+
- **ModelScope**: 2000 free model calls/day
|
|
81
|
+
- **LongCat**: 50M+ free tokens/day minimum
|
|
82
|
+
- First-run wizard with **env auto-detection** (scans `OPENAI_API_KEY`, `DEEPSEEK_API_KEY`, `ZHIPU_API_KEY`, `ModelScopeToken`, etc.)
|
|
83
|
+
- Native **reasoning/thinking model** support — thinking tokens displayed in real time
|
|
84
|
+
- Create / edit / switch models at runtime
|
|
85
|
+
- Per-model hyperparameter tuning (temperature, top_p, top_k, max_completion_tokens, stop_sequences, etc.)
|
|
86
|
+
- Automatic **retry with exponential backoff** (3/10/30/60s) and fallback model switching on persistent failure
|
|
87
|
+
|
|
88
|
+
### Vision & Multimodal
|
|
89
|
+
|
|
90
|
+
- Dedicated vision model configuration via `/vision` command (independent from main model)
|
|
91
|
+
- Image analysis with **automatic media encoding** and base64 embedding
|
|
92
|
+
- **Video support** — send videos directly to vision models for analysis (MP4, MOV, AVI, MKV, WebM)
|
|
93
|
+
- Automatic image resizing for oversized inputs
|
|
94
|
+
- Supported image formats: PNG, JPG, JPEG, GIF, BMP, WebP, TIFF
|
|
95
|
+
|
|
96
|
+
### Session & History
|
|
97
|
+
|
|
98
|
+
- **Persistent sessions** with SQLite-backed checkpoints (LangGraph)
|
|
99
|
+
- Session list, switch, rename, delete
|
|
100
|
+
- **Context compression** — auto-summarize when approaching token limit
|
|
101
|
+
- Real-time **context usage display** in status bar
|
|
102
|
+
|
|
103
|
+
### Git Integration
|
|
104
|
+
|
|
105
|
+
- Working directory **rolls back with message edits**
|
|
106
|
+
- Create **branches from any message** (fork)
|
|
107
|
+
- Edit / fork / delete history messages via `/messages`
|
|
108
|
+
- Checkpoint counter in status bar
|
|
109
|
+
|
|
110
|
+
### Human-in-the-Loop
|
|
111
|
+
|
|
112
|
+
- **Common mode** — every tool call requires approval, with diff preview for edits
|
|
113
|
+
- **YOLO mode** — auto-approve everything
|
|
114
|
+
- Toggle with `Tab` key or `/mode` command
|
|
115
|
+
|
|
116
|
+
### Work Environment Isolation
|
|
117
|
+
|
|
118
|
+
- Per-project `.chat/` directory for sessions, skills, agents
|
|
119
|
+
- Global `~/.chat/` for shared skills and settings
|
|
120
|
+
- `/workdir` to switch project root
|
|
121
|
+
|
|
122
|
+
### Cross-Platform
|
|
123
|
+
|
|
124
|
+
- **Windows** — defaults to Git Bash, falls back to PowerShell
|
|
125
|
+
- **Linux / Mac** — native bash/zsh
|
|
126
|
+
- Persistent shell sessions with **automatic CWD tracking**
|
|
127
|
+
|
|
128
|
+
### Rich Terminal UI
|
|
129
|
+
|
|
130
|
+
- Real-time **status bar** — context usage %, git checkpoint count, ModelScope API quota
|
|
131
|
+
- **Streaming output** with token-by-token rendering
|
|
132
|
+
- Slash command auto-completion
|
|
133
|
+
- Color-coded tool approval UI with **inline diff preview** for file edits
|
|
134
|
+
|
|
135
|
+
### Observability
|
|
136
|
+
|
|
137
|
+
- **LangSmith tracing** — toggle on/off via `/langsmith` command
|
|
138
|
+
- Auto-disable tracing on 429 rate limit with user notification
|
|
139
|
+
|
|
140
|
+
### Sub-Agent System
|
|
141
|
+
|
|
142
|
+
- Three built-in agent types: **Explore** (codebase search, read-only), **Plan** (architecture design), **General** (full-capability coding)
|
|
143
|
+
- **Parallel execution** — launch multiple agents concurrently for independent tasks
|
|
144
|
+
- Sub-agents run with **isolated context**, protecting the main conversation from context pollution
|
|
145
|
+
- **Custom agents** — define your own agent types in `.chat/agents/` with dedicated tools and instructions
|
|
146
|
+
|
|
147
|
+
### Skill System
|
|
148
|
+
|
|
149
|
+
- Install / delete / manage skills via `/skill`
|
|
150
|
+
- Skills are injected into system prompt via LangChain middleware
|
|
151
|
+
- Supports project-level and global skill directories
|
|
152
|
+
|
|
153
|
+
### ModelScope Rate Limit
|
|
154
|
+
|
|
155
|
+
- Real-time **API quota display** in status bar (daily limit remaining, per-model remaining)
|
|
156
|
+
- Auto-enabled when using ModelScope models
|
|
157
|
+
|
|
158
|
+
## Built-in Tools (14)
|
|
159
|
+
|
|
160
|
+
| Tool | Description |
|
|
161
|
+
|------|-------------|
|
|
162
|
+
| `read` | Read file content with line numbers and offset |
|
|
163
|
+
| `write` | Create or overwrite files |
|
|
164
|
+
| `edit` | Surgical string replacement in existing files |
|
|
165
|
+
| `glob` | Find files by name pattern |
|
|
166
|
+
| `grep` | Search file contents with regex |
|
|
167
|
+
| `list_dir` | Browse directory structure |
|
|
168
|
+
| `bash` | Execute shell commands (Git Bash / PowerShell / bash) |
|
|
169
|
+
| `load_skill` | Dynamically load skill instructions via middleware |
|
|
170
|
+
| `web_fetch` | Fetch and convert URL content to markdown |
|
|
171
|
+
| `web_search` | Web search via [Tavily](https://tavily.com) |
|
|
172
|
+
| `ask_user` | Single-select, multi-select, batch questions for user interaction |
|
|
173
|
+
| `agent` | Launch sub-agents (explore, plan, general-purpose, custom), supports parallel execution |
|
|
174
|
+
| `todo_write` | Structured task tracking for complex multi-step work |
|
|
175
|
+
| `vision` | Analyze images and videos via ModelScope vision models |
|
|
176
|
+
|
|
177
|
+
## Quick Start
|
|
178
|
+
|
|
179
|
+
### Install
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
# Option 1: Install with pip
|
|
183
|
+
pip install chcode
|
|
184
|
+
|
|
185
|
+
# Option 2: Install with uv (recommended)
|
|
186
|
+
uv tool install chcode
|
|
187
|
+
|
|
188
|
+
# Option 3: Install with pipx
|
|
189
|
+
pipx install chcode
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Run
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Start interactive session
|
|
196
|
+
chcode
|
|
197
|
+
|
|
198
|
+
# Start in YOLO mode
|
|
199
|
+
chcode --yolo
|
|
200
|
+
|
|
201
|
+
# Model management
|
|
202
|
+
chcode config new # add new model
|
|
203
|
+
chcode config edit # edit current model
|
|
204
|
+
chcode config switch # switch model
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### First Run
|
|
208
|
+
|
|
209
|
+
On first launch, ChCode will:
|
|
210
|
+
|
|
211
|
+
1. Scan environment variables for known API keys
|
|
212
|
+
2. Guide you through model configuration
|
|
213
|
+
3. Optionally configure Tavily for web search
|
|
214
|
+
|
|
215
|
+
## Commands
|
|
216
|
+
|
|
217
|
+
| Command | Description |
|
|
218
|
+
|---------|-------------|
|
|
219
|
+
| `/new` | Start new session |
|
|
220
|
+
| `/history` | Browse and switch sessions |
|
|
221
|
+
| `/model` | Model management (new / edit / switch) |
|
|
222
|
+
| `/vision` | Visual model configuration |
|
|
223
|
+
| `/messages` | Edit / fork / delete history messages |
|
|
224
|
+
| `/compress` | Compress current session |
|
|
225
|
+
| `/skill` | Manage skills |
|
|
226
|
+
| `/search` | Configure Tavily API key |
|
|
227
|
+
| `/workdir` | Switch working directory |
|
|
228
|
+
| `/mode` | Toggle Common / YOLO mode |
|
|
229
|
+
| `/git` | Show git status |
|
|
230
|
+
| `/langsmith` | Toggle LangSmith tracing |
|
|
231
|
+
| `/tools` | List built-in tools |
|
|
232
|
+
| `/quit` | Exit |
|
|
233
|
+
|
|
234
|
+
## Keybindings
|
|
235
|
+
|
|
236
|
+
| Key | Action |
|
|
237
|
+
|-----|--------|
|
|
238
|
+
| `Enter` | Send message |
|
|
239
|
+
| `Ctrl+Enter` | New line |
|
|
240
|
+
| `Tab` | Toggle Common/YOLO mode (when input empty) |
|
|
241
|
+
| `Ctrl+C` | Interrupt generation |
|
|
242
|
+
|
|
243
|
+
## Why No MCP?
|
|
244
|
+
|
|
245
|
+
ChCode intentionally does not integrate MCP (Model Context Protocol). The combination of **Skills + CLI tools** covers 95%+ of real-world coding agent scenarios. Skills provide structured, reusable instructions injected via middleware — simpler, faster, and more portable than MCP servers.
|
|
246
|
+
|
|
247
|
+
## Architecture
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
chcode/
|
|
251
|
+
├── cli.py # Typer CLI entry
|
|
252
|
+
├── chat.py # REPL main loop, slash commands, HITL
|
|
253
|
+
├── agent_setup.py # Agent construction, middleware, model retry with fallback
|
|
254
|
+
├── config.py # Model config, Tavily, env detection
|
|
255
|
+
├── display.py # Rich rendering, streaming, status bar
|
|
256
|
+
├── prompts.py # Interactive prompts (select/confirm/text)
|
|
257
|
+
├── session.py # Session manager (SQLite)
|
|
258
|
+
├── skill_manager.py # Skill install/delete UI
|
|
259
|
+
├── agents/
|
|
260
|
+
│ ├── definitions.py # Agent types (explore, plan, general)
|
|
261
|
+
│ ├── loader.py # Load custom agents from .chat/agents/
|
|
262
|
+
│ └── runner.py # Sub-agent execution with middleware
|
|
263
|
+
└── utils/
|
|
264
|
+
├── tools.py # 14 built-in tools
|
|
265
|
+
├── shell/ # Shell abstraction (Bash/PowerShell providers)
|
|
266
|
+
├── enhanced_chat_openai.py # Extended ChatOpenAI with reasoning support
|
|
267
|
+
├── git_manager.py # Git checkpoint management
|
|
268
|
+
├── skill_loader.py # Skill discovery and loading
|
|
269
|
+
├── modelscope_ratelimit.py # ModelScope API rate limit monitor
|
|
270
|
+
└── tool_result_pipeline.py # Output truncation and budget enforcement
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT
|
chcode-0.1.0/README.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# ChCode
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
███████╗ ██╗ ██╗ ███████╗ ██████╗ █████╗ ████████╗
|
|
5
|
+
██╔═════╝ ██║ ██║ ██╔═════╝ ██╔═══██╗ ██╔══██╗ ██╔═════╝
|
|
6
|
+
██║ ████████║ ██║ ██║ ██║ ██║ ██╗ ████████╗
|
|
7
|
+
██║ ██╔═══██║ ██║ ██║ ██║ ██║ ██╔╝ ██╔═════╝
|
|
8
|
+
████████╗ ██║ ██║ ████████╗ ╚██████╔╝ █████╔═╝ ████████╗
|
|
9
|
+
╚══════╝ ╚═╝ ╚═╝ ╚══════╝ ╚═════╝ ╚════╝ ╚══════╝
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Terminal-based AI coding agent, built with LangChain + Typer + Rich.
|
|
13
|
+
|
|
14
|
+
> **Why "ChCode"?** The original prototype was a tkinter + LangChain app called **chat-agent** (chagent). When it evolved into a CLI tool, the name became **ChCode** — chat-agent, meet code.
|
|
15
|
+
|
|
16
|
+
<details>
|
|
17
|
+
<summary>📸 chagent — the original tkinter prototype</summary>
|
|
18
|
+
<img src="https://raw.githubusercontent.com/ScarletMercy/chcode/main/assets/chagent.png" alt="chagent prototype" width="600"/>
|
|
19
|
+
</details>
|
|
20
|
+
|
|
21
|
+
> 6000+ lines of Python, 14 built-in tools, full session persistence, git-aware workflow.
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+

|
|
25
|
+
|
|
26
|
+
[中文文档](README_zh.md)
|
|
27
|
+
|
|
28
|
+
<img src="https://raw.githubusercontent.com/ScarletMercy/chcode/main/assets/chcode.png" alt="ChCode main interface" width="800"/>
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
### Model Management
|
|
33
|
+
|
|
34
|
+
- Compatible with **all OpenAI-compatible APIs** (OpenAI, DeepSeek, Qwen, GLM, Claude via proxy, etc.)
|
|
35
|
+
- Built-in quick setup for **ModelScope**, **LongCat**, and major providers
|
|
36
|
+
- **ModelScope**: 2000 free model calls/day
|
|
37
|
+
- **LongCat**: 50M+ free tokens/day minimum
|
|
38
|
+
- First-run wizard with **env auto-detection** (scans `OPENAI_API_KEY`, `DEEPSEEK_API_KEY`, `ZHIPU_API_KEY`, `ModelScopeToken`, etc.)
|
|
39
|
+
- Native **reasoning/thinking model** support — thinking tokens displayed in real time
|
|
40
|
+
- Create / edit / switch models at runtime
|
|
41
|
+
- Per-model hyperparameter tuning (temperature, top_p, top_k, max_completion_tokens, stop_sequences, etc.)
|
|
42
|
+
- Automatic **retry with exponential backoff** (3/10/30/60s) and fallback model switching on persistent failure
|
|
43
|
+
|
|
44
|
+
### Vision & Multimodal
|
|
45
|
+
|
|
46
|
+
- Dedicated vision model configuration via `/vision` command (independent from main model)
|
|
47
|
+
- Image analysis with **automatic media encoding** and base64 embedding
|
|
48
|
+
- **Video support** — send videos directly to vision models for analysis (MP4, MOV, AVI, MKV, WebM)
|
|
49
|
+
- Automatic image resizing for oversized inputs
|
|
50
|
+
- Supported image formats: PNG, JPG, JPEG, GIF, BMP, WebP, TIFF
|
|
51
|
+
|
|
52
|
+
### Session & History
|
|
53
|
+
|
|
54
|
+
- **Persistent sessions** with SQLite-backed checkpoints (LangGraph)
|
|
55
|
+
- Session list, switch, rename, delete
|
|
56
|
+
- **Context compression** — auto-summarize when approaching token limit
|
|
57
|
+
- Real-time **context usage display** in status bar
|
|
58
|
+
|
|
59
|
+
### Git Integration
|
|
60
|
+
|
|
61
|
+
- Working directory **rolls back with message edits**
|
|
62
|
+
- Create **branches from any message** (fork)
|
|
63
|
+
- Edit / fork / delete history messages via `/messages`
|
|
64
|
+
- Checkpoint counter in status bar
|
|
65
|
+
|
|
66
|
+
### Human-in-the-Loop
|
|
67
|
+
|
|
68
|
+
- **Common mode** — every tool call requires approval, with diff preview for edits
|
|
69
|
+
- **YOLO mode** — auto-approve everything
|
|
70
|
+
- Toggle with `Tab` key or `/mode` command
|
|
71
|
+
|
|
72
|
+
### Work Environment Isolation
|
|
73
|
+
|
|
74
|
+
- Per-project `.chat/` directory for sessions, skills, agents
|
|
75
|
+
- Global `~/.chat/` for shared skills and settings
|
|
76
|
+
- `/workdir` to switch project root
|
|
77
|
+
|
|
78
|
+
### Cross-Platform
|
|
79
|
+
|
|
80
|
+
- **Windows** — defaults to Git Bash, falls back to PowerShell
|
|
81
|
+
- **Linux / Mac** — native bash/zsh
|
|
82
|
+
- Persistent shell sessions with **automatic CWD tracking**
|
|
83
|
+
|
|
84
|
+
### Rich Terminal UI
|
|
85
|
+
|
|
86
|
+
- Real-time **status bar** — context usage %, git checkpoint count, ModelScope API quota
|
|
87
|
+
- **Streaming output** with token-by-token rendering
|
|
88
|
+
- Slash command auto-completion
|
|
89
|
+
- Color-coded tool approval UI with **inline diff preview** for file edits
|
|
90
|
+
|
|
91
|
+
### Observability
|
|
92
|
+
|
|
93
|
+
- **LangSmith tracing** — toggle on/off via `/langsmith` command
|
|
94
|
+
- Auto-disable tracing on 429 rate limit with user notification
|
|
95
|
+
|
|
96
|
+
### Sub-Agent System
|
|
97
|
+
|
|
98
|
+
- Three built-in agent types: **Explore** (codebase search, read-only), **Plan** (architecture design), **General** (full-capability coding)
|
|
99
|
+
- **Parallel execution** — launch multiple agents concurrently for independent tasks
|
|
100
|
+
- Sub-agents run with **isolated context**, protecting the main conversation from context pollution
|
|
101
|
+
- **Custom agents** — define your own agent types in `.chat/agents/` with dedicated tools and instructions
|
|
102
|
+
|
|
103
|
+
### Skill System
|
|
104
|
+
|
|
105
|
+
- Install / delete / manage skills via `/skill`
|
|
106
|
+
- Skills are injected into system prompt via LangChain middleware
|
|
107
|
+
- Supports project-level and global skill directories
|
|
108
|
+
|
|
109
|
+
### ModelScope Rate Limit
|
|
110
|
+
|
|
111
|
+
- Real-time **API quota display** in status bar (daily limit remaining, per-model remaining)
|
|
112
|
+
- Auto-enabled when using ModelScope models
|
|
113
|
+
|
|
114
|
+
## Built-in Tools (14)
|
|
115
|
+
|
|
116
|
+
| Tool | Description |
|
|
117
|
+
|------|-------------|
|
|
118
|
+
| `read` | Read file content with line numbers and offset |
|
|
119
|
+
| `write` | Create or overwrite files |
|
|
120
|
+
| `edit` | Surgical string replacement in existing files |
|
|
121
|
+
| `glob` | Find files by name pattern |
|
|
122
|
+
| `grep` | Search file contents with regex |
|
|
123
|
+
| `list_dir` | Browse directory structure |
|
|
124
|
+
| `bash` | Execute shell commands (Git Bash / PowerShell / bash) |
|
|
125
|
+
| `load_skill` | Dynamically load skill instructions via middleware |
|
|
126
|
+
| `web_fetch` | Fetch and convert URL content to markdown |
|
|
127
|
+
| `web_search` | Web search via [Tavily](https://tavily.com) |
|
|
128
|
+
| `ask_user` | Single-select, multi-select, batch questions for user interaction |
|
|
129
|
+
| `agent` | Launch sub-agents (explore, plan, general-purpose, custom), supports parallel execution |
|
|
130
|
+
| `todo_write` | Structured task tracking for complex multi-step work |
|
|
131
|
+
| `vision` | Analyze images and videos via ModelScope vision models |
|
|
132
|
+
|
|
133
|
+
## Quick Start
|
|
134
|
+
|
|
135
|
+
### Install
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Option 1: Install with pip
|
|
139
|
+
pip install chcode
|
|
140
|
+
|
|
141
|
+
# Option 2: Install with uv (recommended)
|
|
142
|
+
uv tool install chcode
|
|
143
|
+
|
|
144
|
+
# Option 3: Install with pipx
|
|
145
|
+
pipx install chcode
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Run
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Start interactive session
|
|
152
|
+
chcode
|
|
153
|
+
|
|
154
|
+
# Start in YOLO mode
|
|
155
|
+
chcode --yolo
|
|
156
|
+
|
|
157
|
+
# Model management
|
|
158
|
+
chcode config new # add new model
|
|
159
|
+
chcode config edit # edit current model
|
|
160
|
+
chcode config switch # switch model
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### First Run
|
|
164
|
+
|
|
165
|
+
On first launch, ChCode will:
|
|
166
|
+
|
|
167
|
+
1. Scan environment variables for known API keys
|
|
168
|
+
2. Guide you through model configuration
|
|
169
|
+
3. Optionally configure Tavily for web search
|
|
170
|
+
|
|
171
|
+
## Commands
|
|
172
|
+
|
|
173
|
+
| Command | Description |
|
|
174
|
+
|---------|-------------|
|
|
175
|
+
| `/new` | Start new session |
|
|
176
|
+
| `/history` | Browse and switch sessions |
|
|
177
|
+
| `/model` | Model management (new / edit / switch) |
|
|
178
|
+
| `/vision` | Visual model configuration |
|
|
179
|
+
| `/messages` | Edit / fork / delete history messages |
|
|
180
|
+
| `/compress` | Compress current session |
|
|
181
|
+
| `/skill` | Manage skills |
|
|
182
|
+
| `/search` | Configure Tavily API key |
|
|
183
|
+
| `/workdir` | Switch working directory |
|
|
184
|
+
| `/mode` | Toggle Common / YOLO mode |
|
|
185
|
+
| `/git` | Show git status |
|
|
186
|
+
| `/langsmith` | Toggle LangSmith tracing |
|
|
187
|
+
| `/tools` | List built-in tools |
|
|
188
|
+
| `/quit` | Exit |
|
|
189
|
+
|
|
190
|
+
## Keybindings
|
|
191
|
+
|
|
192
|
+
| Key | Action |
|
|
193
|
+
|-----|--------|
|
|
194
|
+
| `Enter` | Send message |
|
|
195
|
+
| `Ctrl+Enter` | New line |
|
|
196
|
+
| `Tab` | Toggle Common/YOLO mode (when input empty) |
|
|
197
|
+
| `Ctrl+C` | Interrupt generation |
|
|
198
|
+
|
|
199
|
+
## Why No MCP?
|
|
200
|
+
|
|
201
|
+
ChCode intentionally does not integrate MCP (Model Context Protocol). The combination of **Skills + CLI tools** covers 95%+ of real-world coding agent scenarios. Skills provide structured, reusable instructions injected via middleware — simpler, faster, and more portable than MCP servers.
|
|
202
|
+
|
|
203
|
+
## Architecture
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
chcode/
|
|
207
|
+
├── cli.py # Typer CLI entry
|
|
208
|
+
├── chat.py # REPL main loop, slash commands, HITL
|
|
209
|
+
├── agent_setup.py # Agent construction, middleware, model retry with fallback
|
|
210
|
+
├── config.py # Model config, Tavily, env detection
|
|
211
|
+
├── display.py # Rich rendering, streaming, status bar
|
|
212
|
+
├── prompts.py # Interactive prompts (select/confirm/text)
|
|
213
|
+
├── session.py # Session manager (SQLite)
|
|
214
|
+
├── skill_manager.py # Skill install/delete UI
|
|
215
|
+
├── agents/
|
|
216
|
+
│ ├── definitions.py # Agent types (explore, plan, general)
|
|
217
|
+
│ ├── loader.py # Load custom agents from .chat/agents/
|
|
218
|
+
│ └── runner.py # Sub-agent execution with middleware
|
|
219
|
+
└── utils/
|
|
220
|
+
├── tools.py # 14 built-in tools
|
|
221
|
+
├── shell/ # Shell abstraction (Bash/PowerShell providers)
|
|
222
|
+
├── enhanced_chat_openai.py # Extended ChatOpenAI with reasoning support
|
|
223
|
+
├── git_manager.py # Git checkpoint management
|
|
224
|
+
├── skill_loader.py # Skill discovery and loading
|
|
225
|
+
├── modelscope_ratelimit.py # ModelScope API rate limit monitor
|
|
226
|
+
└── tool_result_pipeline.py # Output truncation and budget enforcement
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## License
|
|
230
|
+
|
|
231
|
+
MIT
|