Skip to content

Commit acf9fce

Browse files
committed
feat: add Anthropic Messages API + refactor server into clean handlers
Feat: Anthropic compatible - Add POST /v1/messages and /messages endpoints - Full SSE streaming (content_block_start/delta/stop + message_start/delta/stop) - Tool use blocks with input_json_delta streaming - Thinking blocks mapped to Anthropic format - Anthropic messages -> CC wire format conversion Refactor: server code split - server_controller.dart: HTTP server, routing, shared endpoints - openai_handler.dart: OpenAI-compatible handler - anthropic_handler.dart: Anthropic-compatible handler - Removed diagnostic/debug logging, production-level only Docs: split README into docs/ - README.md trimmed to preview; details moved to docs/ - New: INSTALL.md, API-REFERENCE.md, TUI.md, ARCHITECTURE.md - API-REFERENCE.md covers OpenCode, Zed client configs - AGENTS.md synced with new file structure
1 parent d6cda77 commit acf9fce

13 files changed

Lines changed: 2056 additions & 1598 deletions

AGENTS.md

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,60 @@
11
# CommandCode Bridge
22

3-
Single-account proxy bridge for Command Code CLI (`cmd` from `commandcode.ai`). TUI dashboard with progress bars + OpenAI-compatible HTTP proxy.
3+
Single-account proxy bridge for Command Code CLI (`cmd` from `commandcode.ai`).
4+
TUI dashboard with progress bars + OpenAI-compatible and Anthropic-compatible HTTP proxy.
45

56
## Auth
67

7-
Command Code auth is stored at `~/.commandcode/auth.json`. The bridge reads the API key from this file. Run `cmd login` to authenticate first. You can also press `[l]` in the bridge TUI for login instructions.
8+
Command Code auth is stored at `~/.commandcode/auth.json`. The bridge reads the
9+
API key from this file. Run `cmd login` to authenticate first. You can also
10+
press `[l]` in the bridge TUI for login instructions.
811

912
## Architecture
1013

1114
### Stack
1215
- Language: Dart 3.10+
1316
- TUI: `nocterm` v0.8.0 (ProgressBar for visualizations)
1417
- Server: `dart:io` `HttpServer`
15-
- HTTP client: `package:http`
18+
- HTTP client: `dart:io` `HttpClient`
1619
- Compile: `dart compile exe` -> single binary
1720
- Distribution: npm tarball with Node.js launcher wrapper
1821

1922
### File Structure
2023
```
2124
commandcode-bridge/
2225
├── bin/
23-
│ ├── commandcode_bridge.dart # Entry point
24-
│ └── commandcode-bridge.js # npm wrapper: OS detection + binary spawn
26+
│ ├── commandcode_bridge.dart # Entry point
27+
│ └── commandcode-bridge.js # npm wrapper: OS detection + binary spawn
2528
├── lib/
26-
│ ├── commandcode_bridge.dart # Barrel
29+
│ ├── commandcode_bridge.dart # Barrel
2730
│ └── src/
28-
│ ├── main.dart # CLI wiring (run, run --server, help)
31+
│ ├── main.dart # CLI wiring (run, run --server, help)
2932
│ ├── models/
30-
│ │ ├── account.dart # Account + config store (port persist)
31-
│ │ └── models_db.dart # 44 models with goAccessible field
33+
│ │ ├── account.dart # Account + config store (port persist)
34+
│ │ └── models_db.dart # 44 models with goAccessible field
3235
│ ├── services/
33-
│ │ ├── api_client.dart # HTTP client for api.commandcode.ai
34-
│ │ └── log_store.dart # JSONL activity log (2000 entries)
36+
│ │ ├── api_client.dart # HTTP client for api.commandcode.ai
37+
│ │ └── log_store.dart # JSONL activity log (2000 entries)
3538
│ ├── server/
36-
│ │ └── proxy.dart # OpenAI-compatible proxy
39+
│ │ ├── server_controller.dart # HTTP server + routing
40+
│ │ ├── openai_handler.dart # OpenAI-compatible proxy
41+
│ │ └── anthropic_handler.dart # Anthropic-compatible proxy
3742
│ └── tui/
38-
│ └── app.dart # Nocterm TUI (9 panels + log + bars)
43+
│ └── app.dart # Nocterm TUI (9 panels + log + bars)
44+
├── docs/
45+
│ ├── INSTALL.md # Install options, platform support
46+
│ ├── API-REFERENCE.md # Proxy endpoints, client configs
47+
│ ├── TUI.md # TUI pages, key bindings, plan access
48+
│ └── ARCHITECTURE.md # File structure, proxy flow, protocol translation
3949
├── scripts/
40-
│ └── stage-npm-package.mjs # CI packaging helper: assembles release tarball
50+
│ └── stage-npm-package.mjs # CI packaging helper: assembles release tarball
4151
├── .github/
4252
│ ├── ISSUE_TEMPLATE/
43-
│ │ └── bug-report.md # Bug report template
53+
│ │ └── bug-report.md # Bug report template
4454
│ └── workflows/
45-
│ ├── test.yml # Dart analyze + test + smoke
46-
│ ├── release.yml # Matrix build + tarball + GitHub release
47-
│ └── post-release.yml # Install simulation from real asset
55+
│ ├── test.yml # Dart analyze + test + smoke
56+
│ ├── release.yml # Matrix build + tarball + GitHub release
57+
│ └── post-release.yml # Install simulation from real asset
4858
├── test/
4959
├── AGENTS.md
5060
├── CHANGELOG.md
@@ -147,31 +157,52 @@ npm v11 has a bug installing global git deps: the install appears to succeed (`a
147157

148158
| Path | Method | Description |
149159
|------|--------|-------------|
150-
| `/v1/chat/completions` | POST | OpenAI-compatible chat (stream + non-stream) |
160+
| `/v1/chat/completions` | POST | OpenAI-compatible chat completions |
161+
| `/v1/messages` | POST | Anthropic-compatible Messages API |
162+
| `/messages` | POST | Anthropic-compatible Messages API (alt path) |
151163
| `/v1/models` | GET | List 44 available models |
152164
| `/v1/health` | GET | Health check |
153165
| `/v1/token` | GET | Get access token |
154166
| `/v1/info` | GET | Bridge info + config |
155167

156168
## OpenCode Configuration
157169

170+
### OpenAI Compatible
171+
158172
```jsonc
159-
"CommandCode": {
173+
"Khip01 - Command Code": {
160174
"name": "Command Code",
161175
"options": {
162176
"baseURL": "http://127.0.0.1:17077/v1",
163177
"apiKey": "anything"
164178
},
165179
"models": {
166-
"deepseek/deepseek-v4-flash": {
167-
"name": "DeepSeek V4 Flash",
180+
"deepseek/deepseek-v4-pro": {
181+
"name": "DeepSeek V4 Pro",
182+
"tool_call": true,
183+
"reasoning": true,
184+
"limit": { "context": 1048576, "input": 1048576, "output": 8192 }
185+
}
186+
}
187+
}
188+
```
189+
190+
### Anthropic Compatible
191+
192+
```jsonc
193+
"Khip01 - Command Code Anthropic": {
194+
"npm": "@ai-sdk/anthropic",
195+
"name": "Command Code Anthropic",
196+
"options": {
197+
"baseURL": "http://127.0.0.1:17077/v1",
198+
"apiKey": "anything"
199+
},
200+
"models": {
201+
"deepseek/deepseek-v4-pro": {
202+
"name": "DeepSeek V4 Pro",
168203
"tool_call": true,
169204
"reasoning": true,
170-
"limit": {
171-
"context": 1000000,
172-
"input": 1000000,
173-
"output": 8000
174-
}
205+
"limit": { "context": 1048576, "input": 1048576, "output": 8192 }
175206
}
176207
}
177208
}

CHANGELOG.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,41 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## v1.1.0 (unreleased)
6+
7+
### Features
8+
9+
- Anthropic-compatible Messages API (`/v1/messages` and `/messages`)
10+
- Full SSE streaming: content_block_start/delta/stop + message_start/delta/stop
11+
- Tool use blocks with input_json_delta streaming
12+
- Thinking blocks (reasoning mapped to Anthropic format)
13+
- Non-streaming endpoint with proper Anthropic response shape
14+
- Anthropic Messages protocol -> CC wire format conversion (system, tools, messages)
15+
- stop_reason mapping: tool-calls -> tool_use, length -> max_tokens
16+
17+
### Refactor
18+
19+
- Server code split into three clean files:
20+
- `server_controller.dart` — HTTP server, request routing, shared endpoints (/models, /health, /token, /info)
21+
- `openai_handler.dart` — OpenAI-compatible handler (streaming + non-streaming)
22+
- `anthropic_handler.dart` — Anthropic-compatible handler (streaming + non-streaming)
23+
- Common upstream body builder shared between handlers
24+
- Removed diagnostic/debug logging; production-level logging only
25+
- Renamed ProxyServer -> ServerController, extracted handlers to own classes
26+
- Update OpenCode protocol mapping for production upstream format
27+
- Fixed config.date field missing from OpenAI handler (was broken after refactor)
28+
29+
### Docs
30+
31+
- README.md trimmed to preview; detailed docs moved to `docs/`
32+
- New docs: INSTALL.md, API-REFERENCE.md, TUI.md, ARCHITECTURE.md
33+
- API-REFERENCE.md covers OpenAI, Anthropic, and Zed client configurations
34+
- AGENTS.md synced with new file structure and endpoints
35+
536
## v1.0.0 (2026-07-27)
637

7-
Initial stable release of CommandCode Bridge, a single-account proxy bridge for Command Code CLI with TUI dashboard.
38+
Initial stable release of CommandCode Bridge, a single-account proxy bridge for
39+
Command Code CLI with TUI dashboard.
840

941
### Features
1042

0 commit comments

Comments
 (0)