Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
60d8a62
feat: add usage tracking, budget control, and provider health monitor…
john-zhh Feb 18, 2026
674c5a2
feat: add default pricing for OpenAI, DeepSeek, MiniMax, GLM, Gemini,…
john-zhh Feb 18, 2026
ed83c82
feat: add context compression and middleware pipeline (v3.0.0)
john-zhh Feb 18, 2026
fb60a82
feat: add agent infrastructure for multi-agent coordination (v4.0.0)
john-zhh Feb 18, 2026
1c4dedf
test: improve test coverage for proxy and web packages
john-zhh Feb 18, 2026
0b9b3dd
fix: address race conditions and resource leaks across packages
john-zhh Feb 18, 2026
cdebd95
fix: additional bug fixes for nil checks and error handling
john-zhh Feb 18, 2026
2db9da4
fix: handle unchecked errors in random ID generation and webhooks
john-zhh Feb 18, 2026
3c7701c
fix: add explicit error ignoring for best-effort operations
john-zhh Feb 18, 2026
e7b64ae
fix: type assertion safety and resource cleanup improvements
john-zhh Feb 18, 2026
7872938
fix: improve transaction and context cleanup handling
john-zhh Feb 18, 2026
0e8f4aa
fix: add explicit error ignoring and resource cleanup
john-zhh Feb 18, 2026
c5a94eb
fix: improve web test coverage and add usage disclaimer
john-zhh Feb 18, 2026
5109a46
test: improve daemon test coverage to 53% with focus on resource cleanup
john-zhh Feb 18, 2026
9144899
chore: unify version to 3.0.0 and consolidate release plan
john-zhh Feb 18, 2026
50fdfc4
docs: add v3.0 documentation and Japanese/Korean i18n support
john-zhh Feb 19, 2026
d930c6b
docs: add TDD workflow rule and release checklist to CLAUDE.md
john-zhh Feb 19, 2026
9cfac8b
docs: update all README files for v3.0 release
john-zhh Feb 19, 2026
8cb79d8
feat(web): upgrade Web UI to React + Vite + shadcn/ui + TypeScript
john-zhh Feb 19, 2026
32b5a5f
chore: bump version to 3.0.0-alpha.2
john-zhh Feb 19, 2026
1d7e36b
feat: add bot gateway for remote monitoring via chat platforms
john-zhh Feb 19, 2026
c35bb11
feat(web): add bot configuration page for chat platform integrations
john-zhh Feb 19, 2026
77c4fba
test(bot): improve test coverage from 30% to 86%
john-zhh Feb 19, 2026
aa45769
ci: add bot package 80% coverage threshold
john-zhh Feb 19, 2026
5de36fa
test(daemon): add bot gateway initialization tests
john-zhh Feb 19, 2026
07f6a0f
fix: include all fields in OpenCCConfig.UnmarshalJSON
john-zhh Feb 19, 2026
02d2e09
docs: add Bot Gateway documentation and bump version to 3.0.0-alpha.3
john-zhh Feb 19, 2026
3ff5cd3
fix: daemon restart fails after upgrade due to premature PID file rem…
john-zhh Feb 19, 2026
6d30642
test: add daemon integration tests
john-zhh Feb 19, 2026
40fd109
ci: add integration tests to CI pipeline
john-zhh Feb 19, 2026
a4421db
test: add proxy and web integration tests
john-zhh Feb 19, 2026
9e15e38
fix: ensure PID file is removed before daemon process exits
john-zhh Feb 19, 2026
c9be121
feat: add dev environment for frontend development
john-zhh Feb 19, 2026
abbcb8f
fix: CI test flakiness and add Nunito font
john-zhh Feb 19, 2026
6d2e671
chore(website): hide releases page temporarily
john-zhh Feb 19, 2026
43ab230
fix(web): improve Settings page and fix Bot page issues
john-zhh Feb 19, 2026
11bbb5d
feat(web): enhance Bot and Settings pages
john-zhh Feb 20, 2026
962b123
feat: enhance Usage page and refine Config Sync
john-zhh Feb 20, 2026
638ac62
feat(web): add dedicated edit pages for providers and profiles
john-zhh Feb 21, 2026
7a09d25
feat(web): make env var hints clickable in provider edit page
john-zhh Feb 21, 2026
7c9194e
fix(web): reuse empty row when clicking env var hint
john-zhh Feb 21, 2026
a019700
feat(web): sync tab and filter state to URL
john-zhh Feb 21, 2026
89cffe1
refactor(web): rename tab query param from 'tab' to 's'
john-zhh Feb 21, 2026
b4e0ef6
chore(web): rename page title to GoZen Settings
john-zhh Feb 21, 2026
6db59b2
build: move web UI build output to internal/web/dist
john-zhh Feb 21, 2026
9dd3fee
refactor(web): split large page components into smaller modules
john-zhh Feb 21, 2026
2667927
test: increase coverage for proxy and web packages
john-zhh Feb 21, 2026
65b9c08
test(web): add Vitest testing framework with 70% coverage threshold
john-zhh Feb 21, 2026
264240e
fix(web): correct type errors in test files
john-zhh Feb 21, 2026
986e7df
chore: bump version to 3.0.0-alpha.5
john-zhh Feb 21, 2026
c82e0b6
fix(web): add SPA fallback for client-side routing
john-zhh Feb 21, 2026
954ffa4
chore: bump version to 3.0.0-alpha.6
john-zhh Feb 21, 2026
73d1437
fix(daemon): detect orphaned daemon when PID file is missing
john-zhh Feb 21, 2026
973478c
chore: bump version to 3.0.0-alpha.7
john-zhh Feb 21, 2026
0454c91
test(daemon): add comprehensive lifecycle scenario tests
john-zhh Feb 21, 2026
59d574a
chore: bump version to 3.0.0-alpha.8
john-zhh Feb 21, 2026
fdb3dff
fix(daemon): restart daemon after upgrade instead of just stopping
john-zhh Feb 21, 2026
55fd80b
chore: bump version to 3.0.0-alpha.9
john-zhh Feb 21, 2026
c5dabda
feat(web): add middleware configuration page
john-zhh Feb 24, 2026
835c7db
feat(web): show auth token in plain text in provider settings
john-zhh Feb 24, 2026
351f757
feat(web): show existing auth token when editing provider
john-zhh Feb 24, 2026
dc1c25e
feat(api): return unmasked auth token when getting single provider
john-zhh Feb 24, 2026
79959dc
fix(web): update env var hints to exclude API keys and models
john-zhh Feb 24, 2026
3cdf4ed
feat(web): add middleware plugin install/remove functionality
john-zhh Feb 24, 2026
3886d7f
feat(web): add middleware plugin file upload support
john-zhh Feb 24, 2026
37679d7
feat: add bidirectional OpenAI/Anthropic API format transformation
john-zhh Feb 24, 2026
afc6e6e
fix: address code review findings for concurrency and safety
john-zhh Feb 24, 2026
4217243
fix(web): remove socket path from bot settings UI
john-zhh Feb 24, 2026
99477f0
test(web): improve API test coverage to meet CI thresholds
john-zhh Feb 24, 2026
540d888
fix(web): remove unused imports in api.test.ts
john-zhh Feb 24, 2026
efbfd27
test: improve Go coverage for transform and web packages
john-zhh Feb 24, 2026
411c710
fix(web): show bot tokens in plain text instead of masking
john-zhh Feb 24, 2026
2269510
fix(daemon): use HTTP shutdown API for reliable daemon stop/restart
john-zhh Feb 24, 2026
855d41e
feat(daemon): reinitialize bot gateway on config reload
john-zhh Feb 24, 2026
f4f1795
fix(web): send full config on bot tab save to prevent data loss
john-zhh Feb 24, 2026
02ad4ed
feat(web): replace timezone text input with select dropdown
john-zhh Feb 24, 2026
b38270a
refactor(bot): implement LLM-first architecture for query intents
john-zhh Feb 24, 2026
8d1a72d
feat(bot): improve system prompt, add configurable model, SSE chat en…
john-zhh Feb 25, 2026
ee36515
feat(bot): add beta label to bot feature
john-zhh Feb 25, 2026
0f4e3f7
feat: v3.0 platform features — bot adapters, chat UI, session bridge,…
john-zhh Feb 25, 2026
7b47436
chore: bump version to 3.0.0-alpha.10
john-zhh Feb 25, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22

- name: Build Web UI
working-directory: web
run: |
npm ci
npm run build

- name: Test Web UI
working-directory: web
run: npm run test:coverage

- name: Read Go version
id: goversion
run: echo "version=$(grep '^go ' go.mod | awk '{print $2}')" >> "$GITHUB_OUTPUT"
Expand All @@ -29,6 +43,9 @@ jobs:
- name: Test
run: go test -race -count=1 ./...

- name: Integration Tests
run: go test -tags=integration -race -count=1 -timeout 180s ./test/integration/...

- name: Check coverage thresholds
run: |
check_pkg() {
Expand All @@ -53,7 +70,8 @@ jobs:
check_pkg "internal/proxy" 80 || failed=1
check_pkg "internal/proxy/transform" 80 || failed=1
check_pkg "internal/web" 80 || failed=1
check_pkg "internal/daemon" 40 || failed=1
check_pkg "internal/bot" 80 || failed=1
check_pkg "internal/daemon" 50 || failed=1
check_pkg "internal/update" 50 || failed=1
check_pkg "internal/sync" 50 || failed=1

Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 22

- name: Build Web UI
working-directory: web
run: |
npm ci
npm run build

- uses: actions/setup-go@v5
with:
go-version-file: go.mod
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
/dist/
/temp-docs/
/.dev/
web/node_modules/
web/dist/
internal/web/dist/
bin/
web/coverage/
38 changes: 38 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ go build ./...
go test ./...
```

## Dev Environment

Dev daemon runs on separate ports to avoid interfering with production:

- **Dev Web UI**: `http://localhost:29840`
- **Dev Proxy**: `http://localhost:29841`
- **Dev Config**: `~/.zen-dev/zen.json`
- **Production ports (19840/19841)**: NEVER touch during development

```sh
./scripts/dev.sh # Start dev daemon (builds + starts)
./scripts/dev.sh stop # Stop dev daemon
./scripts/dev.sh restart # Rebuild and restart dev daemon
./scripts/dev.sh status # Check dev daemon status
./scripts/dev.sh web # Start frontend dev server (Vite)
```

After modifying Go code, always run `./scripts/dev.sh restart` to rebuild and restart the dev daemon.

## Release Process

Push a git tag to trigger GitHub Actions release workflow:
Expand All @@ -56,6 +75,24 @@ Do NOT use `gh release create` — the CI pipeline handles release creation auto
- **No example files**: Do NOT create example config files (*.json, *.yaml, etc.) in the repository root. Examples belong in README.md or `docs/`.
- **Minimal test files**: Only add tests for new public APIs or complex logic. Do not create excessive test files for simple functions. Prefer table-driven tests in existing *_test.go files.
- **No unnecessary files**: Before committing, review `git status` and remove any generated, temporary, or example files that should not be in the repository.
- **TDD for new features**: Use Test-Driven Development (TDD) for new feature development to ensure code quality. Write tests first, then implement the feature to make tests pass.

## Release Checklist

Before tagging a release, complete the following checklist:

1. **Bug check**: Review all code for unresolved bugs. Run `go test ./...` and ensure all tests pass.
2. **Version number**: Verify `Version` in `cmd/root.go` matches the release tag.
3. **Website documentation**:
- Ensure website contains documentation for the release version
- Verify documentation is accurate and complete
- Confirm all new features are documented
- Remove or update documentation for changed/removed features
4. **README files**: Update all README files to reflect the latest version:
- `README.md` (English)
- `docs/README.zh-CN.md` (简体中文)
- `docs/README.zh-TW.md` (繁體中文)
- `docs/README.es.md` (Español)

## Config Migration Rules

Expand Down Expand Up @@ -108,3 +145,4 @@ Background (Light): `#f8fafc` → `#ffffff` → `#f1f5f9` → `#e2e8f0`
- v1.5.2: Allow reinstalling same version in upgrade command
- v1.5.3: Per-binary PID files to avoid multi-binary conflicts
- v2.0.0: Rename to GoZen (opencc → zen), config migration from ~/.opencc/ to ~/.zen/, non-blocking version update check
- v3.0.0: Usage tracking & budget control, provider health monitoring, smart load balancing, webhooks, context compression, middleware pipeline, agent infrastructure
196 changes: 189 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ Multi-CLI environment switcher for Claude Code, Codex, and OpenCode with API pro
- **Self-Update** — One-command upgrade via `zen upgrade` with semver version matching (supports prerelease versions)
- **Shell Completion** — Supports zsh / bash / fish

### v3.0 New Features

- **Usage Tracking** — Track token usage and costs per provider, model, and project
- **Budget Control** — Set daily/weekly/monthly spending limits with warn/downgrade/block actions
- **Provider Health Monitoring** — Real-time health checks with latency and error rate tracking
- **Smart Load Balancing** — Multiple strategies: failover, round-robin, least-latency, least-cost
- **Webhooks** — Notifications for budget alerts, provider status changes, and daily summaries (Slack/Discord/Generic)
- **Context Compression** — Automatic context compression when token count exceeds threshold
- **Middleware Pipeline** — Pluggable middleware for request/response transformation
- **Agent Infrastructure** — Built-in support for agent-based workflows with session management
- **Bot Gateway** — Monitor and control Claude Code sessions remotely via Telegram, Discord, Slack, Lark, or Facebook Messenger

## Installation

```sh
Expand Down Expand Up @@ -89,7 +101,7 @@ zen --cli codex

## Daemon Architecture

In v2.1, GoZen uses a unified daemon process (`zend`) that hosts both the HTTP proxy and the Web UI:
In v3.0, GoZen uses a unified daemon process (`zend`) that hosts both the HTTP proxy and the Web UI:

- **Proxy server** runs on port `19841` (configurable via `proxy_port`)
- **Web UI** runs on port `19840` (configurable via `web_port`)
Expand Down Expand Up @@ -330,6 +342,176 @@ Configuration example:
}
```

## Usage Tracking & Budget Control

Track API usage and set spending limits:

```json
{
"pricing": {
"claude-sonnet-4-20250514": {"input_per_million": 3.0, "output_per_million": 15.0},
"claude-opus-4-20250514": {"input_per_million": 15.0, "output_per_million": 75.0}
},
"budgets": {
"daily": {"amount": 10.0, "action": "warn"},
"monthly": {"amount": 100.0, "action": "block"},
"per_project": true
}
}
```

Budget actions: `warn` (log warning), `downgrade` (switch to cheaper model), `block` (reject requests).

## Provider Health Monitoring

Automatic health checks with metrics tracking:

```json
{
"health_check": {
"enabled": true,
"interval_secs": 60,
"timeout_secs": 10
}
}
```

View provider health via Web UI or API: `GET /api/v1/health/providers`

## Smart Load Balancing

Configure load balancing strategy per profile:

```json
{
"profiles": {
"balanced": {
"providers": ["provider-a", "provider-b", "provider-c"],
"strategy": "least-latency"
}
}
}
```

Strategies:
- `failover` — Try providers in order (default)
- `round-robin` — Distribute requests evenly
- `least-latency` — Route to fastest provider
- `least-cost` — Route to cheapest provider for the model

## Webhooks

Get notified about important events:

```json
{
"webhooks": [
{
"name": "slack-alerts",
"url": "https://hooks.slack.com/services/xxx",
"events": ["budget_warning", "budget_exceeded", "provider_down", "provider_up"],
"enabled": true
}
]
}
```

Events: `budget_warning`, `budget_exceeded`, `provider_down`, `provider_up`, `failover`, `daily_summary`

## Context Compression

Automatically compress context when it exceeds a threshold:

```json
{
"compression": {
"enabled": true,
"threshold_tokens": 100000,
"target_ratio": 0.5
}
}
```

## Middleware Pipeline

Transform requests and responses with pluggable middleware:

```json
{
"middleware": {
"enabled": true,
"middlewares": [
{"name": "context-injection", "enabled": true, "config": {"inject_cursorrules": true}},
{"name": "rate-limiter", "enabled": true, "config": {"requests_per_minute": 60}}
]
}
}
```

Built-in middleware: `context-injection`, `request-logger`, `rate-limiter`, `compression`

## Bot Gateway

Monitor and control your Claude Code sessions remotely via chat platforms. The bot connects to running `zen` processes via IPC and lets you:

- View connected processes and their status
- Send tasks to specific processes
- Receive notifications for approvals, errors, and completions
- Control tasks (pause/resume/cancel)

### Supported Platforms

| Platform | Setup Required |
|----------|----------------|
| Telegram | BotFather token |
| Discord | Bot application token |
| Slack | Bot + App tokens (Socket Mode) |
| Lark/Feishu | App ID + Secret |
| Facebook Messenger | Page token + Verify token |

### Bot Commands

| Command | Description |
|---------|-------------|
| `list` | List all connected processes |
| `status [name]` | Show process status |
| `bind <name>` | Bind to a process for subsequent commands |
| `pause/resume/cancel [name]` | Control tasks |
| `<name> <task>` | Send a task to a process |
| `help` | Show available commands |

The bot also understands natural language queries like "帮我看看 gozen 的状态" (show me gozen's status).

### Configuration

```json
{
"bot": {
"enabled": true,
"socket_path": "/tmp/zen-bot.sock",
"platforms": {
"telegram": {
"enabled": true,
"token": "123456:ABC-DEF...",
"allowed_users": ["your_username"]
}
},
"interaction": {
"require_mention": true,
"mention_keywords": ["@zen", "/zen"],
"direct_message_mode": "always",
"channel_mode": "mention"
},
"aliases": {
"api": "/path/to/api-project",
"web": "/path/to/web-project"
}
}
}
```

See the [Bot Gateway documentation](https://gozen.dev/docs/bot) for detailed platform setup guides.

## Config Files

| File | Description |
Expand All @@ -343,7 +525,7 @@ Configuration example:

```json
{
"version": 7,
"version": 8,
"default_profile": "default",
"default_client": "claude",
"proxy_port": 19841,
Expand Down Expand Up @@ -379,11 +561,11 @@ Configuration example:
zen upgrade

# Specific version
zen upgrade 2.1
zen upgrade 2.1.0
zen upgrade 3.0
zen upgrade 3.0.0

# Prerelease version
zen upgrade 2.1.0-alpha.1
zen upgrade 3.0.0-alpha.1
```

## Migrating from Older Versions
Expand All @@ -405,8 +587,8 @@ go test ./...
Release: Push a tag and GitHub Actions will build automatically.

```sh
git tag v2.1.0
git push origin v2.1.0
git tag v3.0.0
git push origin v3.0.0
```

## License
Expand Down
Loading
Loading