zcode-agent 0.0.0-stage → 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +418 -2
- package/assets/executor-agents.md +10 -0
- package/bin/zcode-agent.js +418 -0
- package/lib/appserver.js +516 -0
- package/lib/bootstrap.js +70 -0
- package/lib/brief.js +109 -0
- package/lib/checks.js +104 -0
- package/lib/commands/cost.js +67 -0
- package/lib/commands/doctor.js +179 -0
- package/lib/commands/exec.js +394 -0
- package/lib/commands/login.js +44 -0
- package/lib/commands/mcp-list.js +12 -0
- package/lib/commands/plan.js +302 -0
- package/lib/commands/sessions.js +329 -0
- package/lib/commands/skills.js +47 -0
- package/lib/contract.js +530 -0
- package/lib/cost.js +278 -0
- package/lib/engine.js +212 -0
- package/lib/executor.js +914 -0
- package/lib/help.js +128 -0
- package/lib/isolation.js +621 -0
- package/lib/key.js +81 -0
- package/lib/models.js +179 -0
- package/lib/plan.js +459 -0
- package/lib/ports.js +45 -0
- package/lib/skills.js +92 -0
- package/lib/store.js +340 -0
- package/lib/taskspec.js +114 -0
- package/lib/ui.js +249 -0
- package/lib/verify.js +100 -0
- package/lib/workspace.js +383 -0
- package/package.json +52 -4
- package/skills/README.md +40 -0
- package/skills/claude-code/zcode-agent/SKILL.md +169 -0
- package/skills/codex/zcode-agent/SKILL.md +169 -0
- package/skills/codex/zcode-agent/agents/openai.yaml +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 The zai-code authors
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,419 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/0xgeorgemathew/zcode-agent/main/docs/assets/hero-dark.svg">
|
|
4
|
+
<img src="https://raw.githubusercontent.com/0xgeorgemathew/zcode-agent/main/docs/assets/hero-light.svg" width="960" alt="Your agent (Claude Code, Codex or any agent with a shell) writes the decisions and a task contract. zcode-agent runs parallel GLM-5.3-Flash sessions that build, run their own checks, repair failures and have a fresh session judge screenshots. One handback line returns to your agent.">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
2
7
|
|
|
3
|
-
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://www.npmjs.com/package/zcode-agent"><img src="https://img.shields.io/npm/v/zcode-agent.svg?color=2E2A7A&label=npm" alt="npm version"></a>
|
|
10
|
+
<img src="https://img.shields.io/badge/node-%E2%89%A522.13-2E2A7A" alt="node 22.13 or later">
|
|
11
|
+
<img src="https://img.shields.io/badge/model-GLM--5.3--Flash-1C7C54" alt="runs on GLM-5.3-Flash">
|
|
12
|
+
<a href="https://github.com/0xgeorgemathew/zcode-agent/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-2E2A7A" alt="MIT license"></a>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
# zcode-agent
|
|
16
|
+
|
|
17
|
+
zcode-agent is a command-line executor for any agent that can run a shell command: Claude Code, Codex, or your own. Your agent writes the decisions and a task contract. zcode-agent builds it with GLM-5.3-Flash, runs your checks itself, repairs what fails, and has a separate Flash session that never saw the code look at screenshots of the result. It returns one line of JSON. Your agent never reads the diff, re-runs the tests or opens a screenshot, so its expensive tokens go to decisions and exceptions.
|
|
18
|
+
|
|
19
|
+
| | does | never does |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| **Your agent** | product, design and logic decisions; splits the work; answers questions | writes code, re-runs checks, looks at screenshots |
|
|
22
|
+
| **zcode-agent** (GLM-5.3-Flash) | builds inside the paths it owns, runs subagents in parallel, runs the checks, fixes failures | invents anything user-visible the decisions left open, commits, deploys |
|
|
23
|
+
| **The verifier** (a fresh Flash session) | serves the app, screenshots every viewport, quotes the text it can read, judges each criterion | edits files, trusts the DOM over the pixels |
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
# check engine, key, MCP, browser
|
|
31
|
+
npx zcode-agent doctor
|
|
32
|
+
|
|
33
|
+
# teach Claude Code and Codex
|
|
34
|
+
npx zcode-agent skills install
|
|
35
|
+
|
|
36
|
+
# or hand it a task yourself
|
|
37
|
+
npx zcode-agent task \
|
|
38
|
+
--check "npm test" \
|
|
39
|
+
"Fix the off-by-one in paginate.ts"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
To skip `npx`, install it once with `npm install -g zcode-agent`. It needs Node 22.13 or later.
|
|
43
|
+
|
|
44
|
+
**With the ZCode app installed, there is nothing to configure.** zcode-agent reads the app's Z.ai API key where it is stored (it never copies or prints it) and gives every session the app's MCP servers and skills. It leaves out remote MCP servers that sign in with OAuth, because a headless session can't complete the sign-in, and it skips a server that failed to connect for the next six hours. The app's plugins, agent profiles and your global `AGENTS.md` stay out unless you pass `--inherit-desktop`. `--hermetic` leaves out the app's MCP servers and skills as well.
|
|
45
|
+
|
|
46
|
+
**Without the app**, set an API key and install a browser for visual checks:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
# the key, in the environment
|
|
50
|
+
export ZAI_API_KEY=...
|
|
51
|
+
# or stored once
|
|
52
|
+
printf %s "$KEY" \
|
|
53
|
+
| npx zcode-agent login
|
|
54
|
+
|
|
55
|
+
# Chromium for visual checks
|
|
56
|
+
npx zcode-agent doctor \
|
|
57
|
+
--install-browser
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The engine comes with the package. `@zcode-agent/engine` is the headless ZCode engine, built unmodified from the Apache-2.0 source of [zai-org/ZCode](https://github.com/zai-org/ZCode) and pinned to the version zcode-agent is tested with.
|
|
61
|
+
|
|
62
|
+
`zcode-agent skills install` copies the Claude Code skill to `~/.claude/skills/zcode-agent` and the Codex skill to `${CODEX_HOME:-~/.codex}/skills/zcode-agent`, and removes a pre-1.0 `zcode` skill if it finds one. Pass `claude` or `codex` to install one of them. `zcode-agent skills` shows what is installed and `zcode-agent skills uninstall` removes both. The package runs no install scripts. The skills themselves are in [`packages/cli/skills`](https://github.com/0xgeorgemathew/zcode-agent/blob/main/packages/cli/skills/README.md).
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## How a task runs
|
|
67
|
+
|
|
68
|
+
With the skill installed, your agent works in four steps. Only the first one costs much.
|
|
69
|
+
|
|
70
|
+
1. **Decide.** Read the repo, then write down every user-visible and behavioural decision once, as short statements in a file such as `docs/decisions.md`: palette, copy, motion, validation rules, storage keys.
|
|
71
|
+
2. **Shape.** Pick one session, one session with units, parallel sessions, or a plan. The next section says which.
|
|
72
|
+
3. **Dispatch and wait.** One background `zcode-agent wait` or `zcode-agent plan wait`, with no polling.
|
|
73
|
+
4. **Handle exceptions.** A `completed` session needs nothing. Any other status comes with the questions, the tail of the failing check, or the unmet criterion, and your agent answers with a one-line `zcode-agent resume`.
|
|
74
|
+
|
|
75
|
+
You can watch sessions while they run. Your agent doesn't need to.
|
|
76
|
+
|
|
77
|
+
```text
|
|
78
|
+
$ zcode-agent watch
|
|
79
|
+
api-auth completed 22m last: Bash 3m ago req 61 sub 0 $0.09
|
|
80
|
+
settings-page running verifying round 1 31m last: Read 4s ago req 84 sub 2 $0.14
|
|
81
|
+
billing-page running executing 31m last: Edit 12s ago req 77 sub 3 $0.12
|
|
82
|
+
total $0.35 (3 sessions, Z.ai list price)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
The line says `thinking` while a model request streams, so a long request doesn't look stuck. A running session with no engine event for 8 minutes gets `STALLED?` (`--stall-min` changes the threshold). Nothing happens automatically.
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## Split work only when it splits
|
|
90
|
+
|
|
91
|
+
Parallel work can cut wall time, and it is always optional. One well-specified session is correct for most tasks.
|
|
92
|
+
|
|
93
|
+
| the work | shape |
|
|
94
|
+
|---|---|
|
|
95
|
+
| small, or tightly coupled | **one session** |
|
|
96
|
+
| one deliverable with separable parts that share decisions | **one session with units**: a `--unit` per part, each run by a subagent, integrated by the session |
|
|
97
|
+
| independent deliverables that own different paths | **parallel sessions**: `--detach` each, then one `wait` on all of them |
|
|
98
|
+
| a shared base first, then parallel features | **a plan**: `plan run plan.json`, with `after` for the order |
|
|
99
|
+
|
|
100
|
+
Split only when every concurrent session owns different paths, one session owns the shared files (`package.json`, lockfiles, router, global styles) and installs every dependency up front, and no piece waits on a decision another piece will make. Two to four sessions at a time is the useful range. More sessions compete for the API rate limit and your machine. zcode-agent refuses overlapping ownership with exit 7, and every session gets its own `ZCODE_PORT`, `ZCODE_OUT` and `ZCODE_TMP` so dev servers and build output don't collide.
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
## Hand off a task
|
|
105
|
+
|
|
106
|
+
```sh
|
|
107
|
+
zcode-agent task --cwd ./site --id pricing \
|
|
108
|
+
--owns src/pages/pricing/ \
|
|
109
|
+
--check "npm run build" --check "npm test -- pricing" \
|
|
110
|
+
--decisions @docs/decisions.md \
|
|
111
|
+
--visual "all three plan cards are readable side by side at 1440 and stacked at 390" \
|
|
112
|
+
"Build the pricing page"
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
zcode-agent turns the flags into a task contract and runs a fresh engine session with `--cwd` as the limit of what it may touch. The executor may split the work across subagents. When it finishes, zcode-agent runs the checks itself and feeds any failure back for up to two repair turns (`--max-repairs`). With `--visual`, a fresh session then serves the app, screenshots it and judges each criterion. The summary looks like this:
|
|
116
|
+
|
|
117
|
+
```text
|
|
118
|
+
✓ completed pricing 552.3s
|
|
119
|
+
Pricing page with three plan cards; the middle card is highlighted.
|
|
120
|
+
changed 3 files
|
|
121
|
+
A src/pages/pricing/index.tsx
|
|
122
|
+
A src/pages/pricing/PlanCard.tsx
|
|
123
|
+
M src/pages/pricing/styles.css
|
|
124
|
+
checks 2/2 passed
|
|
125
|
+
✓ npm run build
|
|
126
|
+
✓ npm test -- pricing
|
|
127
|
+
visual
|
|
128
|
+
- met all three plan cards are readable side by side at 1440 and stacked at 390 @1440x900
|
|
129
|
+
- met all three plan cards are readable side by side at 1440 and stacked at 390 @390x844
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The summary goes to stdout and the live feed (phases, tools, subagents, check results) to stderr. With `--json` you get one machine-readable result line instead (see [Machine interface](#machine-interface)). For a small fix the objective alone is enough: `zcode-agent task "Fix the typo in the README heading"`.
|
|
133
|
+
|
|
134
|
+
### What a status means
|
|
135
|
+
|
|
136
|
+
| status | meaning | exit |
|
|
137
|
+
|---|---|---|
|
|
138
|
+
| `completed` | zcode-agent's own checks passed, the executor reports done, no criterion is unmet and nothing changed outside `--owns` | 0 |
|
|
139
|
+
| `unverified` | the executor reports done, but there were no checks to run, so nothing confirms it | 9 |
|
|
140
|
+
| `partial` | work remains: the executor says so, a criterion is unmet, or files changed outside the owned paths | 8 |
|
|
141
|
+
| `blocked` | the executor needs an answer; `questions` lists them with options and a recommendation | 10 |
|
|
142
|
+
| `failed` | checks still fail after the repair turns (8), the engine or turn failed (5), or it timed out (124) | 5, 8, 124 |
|
|
143
|
+
| `cancelled` | stopped by `zcode-agent cancel`, Ctrl-C or SIGTERM | 130 |
|
|
144
|
+
|
|
145
|
+
zcode-agent derives the status from what it observed, not from what the model claims. The model's own report is kept as `handback`, and `notVerified` lists anything zcode-agent could not check itself.
|
|
146
|
+
|
|
147
|
+
### The contract
|
|
148
|
+
|
|
149
|
+
Flags cover the common fields. For a larger handoff, pass `--task contract.json`, `--task brief.md`, or `--task -` to read stdin. Only `objective` is required, and zcode-agent rejects unknown keys so a typo never drops a requirement silently.
|
|
150
|
+
|
|
151
|
+
```json
|
|
152
|
+
{
|
|
153
|
+
"objective": "Implement the Team page per the design spec",
|
|
154
|
+
"decisions": ["Grid of 3 columns at 1024px and wider, 1 column below", "Use tokens from src/theme.ts only"],
|
|
155
|
+
"constraints": ["No new dependencies"],
|
|
156
|
+
"acceptance": ["Every member card shows name, role and avatar"],
|
|
157
|
+
"checks": ["npm run build", "npm test -- team"],
|
|
158
|
+
"visual": ["every member's name and role is readable at 390 and 1440"],
|
|
159
|
+
"files": ["src/theme.ts"],
|
|
160
|
+
"context": ["Copy lives in content/team.json"],
|
|
161
|
+
"owns": ["src/pages/team/**", "content/team.json"],
|
|
162
|
+
"units": [{ "name": "cards", "objective": "Member card component", "owns": ["src/pages/team/Card.tsx"] }],
|
|
163
|
+
"limits": { "timeoutMs": 7200000, "maxRepairs": 2 },
|
|
164
|
+
"effort": "high"
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
<details>
|
|
169
|
+
<summary><b>Decisions, preflight, units and the verifier in detail</b></summary>
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
**Decisions** (`--decision "…"`, repeatable, or `--decisions @file`) are binding. The executor implements them and does not revisit them. When something user-visible or behavioural is still open, the executor does not guess. If the gap blocks the work, it reports `blocked` with a structured question `{"q", "options", "recommend"}`. Otherwise it takes the most conservative choice and lists it under `decisions: [{what, why}]` in the handback, so your agent can overrule it. `@file` entries in contract `decisions` and `context` are read relative to the contract file, then to `--cwd`.
|
|
174
|
+
|
|
175
|
+
**Preflight.** `--preflight` runs a read-only turn over the same contract. The executor lists every question it would otherwise guess and changes no files. The result is `blocked` with `questions`, or `completed` with the summary `no open questions`. `zcode-agent resume <id> "<answers>"` then switches the session to execution. It costs your agent a round trip, so use it when the decisions have known gaps.
|
|
176
|
+
|
|
177
|
+
**Units.** `--unit "name: objective [owns a,b]"` (repeatable, or contract `units`) makes the executor give each unit its own subagent inside the one session, in parallel where they are independent, then integrate and verify the whole. Unit paths must lie inside the session's `--owns` and must not overlap each other (exit 2 otherwise).
|
|
178
|
+
|
|
179
|
+
**Visual verification.** `--visual "criterion"` (repeatable), `--viewport WxH` (repeatable, default `390x844` and `1440x900`) and `--serve "cmd"` (must honour `$ZCODE_PORT`; by default the verifier reads `package.json`) hand the judgement to a fresh session that did not build the result. After the checks pass, it serves the app, waits for fonts and animations, scrolls one window height at a time to the bottom at every viewport, saves the screenshots under `$ZCODE_OUT/verify/<round>/`, and answers with what it can read (`seen`) for each criterion. It always judges one more criterion: all text the page means to show is readable after animations finish. Unmet criteria go back to the executor as repair turns with the verifier's notes and screenshot paths. A verifier that fails twice gives `met: null` and status `partial`. Write criteria as what must be visible: "the headline 'Plans for every team' is fully readable at 390 and 1440".
|
|
180
|
+
|
|
181
|
+
</details>
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
## Models and effort
|
|
186
|
+
|
|
187
|
+
Every command runs on GLM-5.3-Flash at effort `max` unless you pass a flag. Flash reads images, so the executor can check its own UI and the verifier can judge screenshots. `--model glm-5.3` is an override for work that needs the larger model, and it cannot read images.
|
|
188
|
+
|
|
189
|
+
| flag | values | default |
|
|
190
|
+
|---|---|---|
|
|
191
|
+
| `--model` | `glm-5.3-flash`, `glm-5.3` | Flash |
|
|
192
|
+
| `--effort` | `low`, `high`, `max` | `max` |
|
|
193
|
+
|
|
194
|
+
`--model` also takes the short names `flash`, `5.3-flash` and `53f` for Flash, and `5.3` and `53` for GLM-5.3. A contract can set `"model"` and `"effort"`, and flags override it. A resumed session keeps its model and effort unless you pass the flags again. Any other model or an unsupported effort exits 2 before anything starts.
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
## Sessions
|
|
199
|
+
|
|
200
|
+
Every run is a session, named with `--id` or given a `zc-xxxxxxxx` id. Each session has its own engine home under `~/.zcode-agent/sessions/<id>/`, so conversations, MCP servers and skills never leak between sessions. zcode-agent never re-runs an existing id, so a retried start fails fast instead of doing the work twice.
|
|
201
|
+
|
|
202
|
+
```sh
|
|
203
|
+
zcode-agent task --detach --id home --owns src/pages/home/ --check "npm run build" "Build the home page"
|
|
204
|
+
zcode-agent task --detach --id team --owns src/pages/team/ --check "npm run build" "Build the team page"
|
|
205
|
+
zcode-agent wait home team # block until both finish, print each handback
|
|
206
|
+
zcode-agent wait home team --any # return when the first one finishes
|
|
207
|
+
zcode-agent status home --json # state, phase, recent events, result
|
|
208
|
+
zcode-agent result home # a finished session's handback
|
|
209
|
+
zcode-agent resume team "Use the 2-column variant below 1024px."
|
|
210
|
+
zcode-agent cancel home
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
A session goes from `queued` to `running` to `finished`. If the process that owns it dies, it shows as `interrupted` and can be resumed. `resume` sends your message into the same engine conversation. For task sessions the executor is told the earlier work is already on disk, and zcode-agent runs the checks and repairs again and writes a fresh handback. zcode-agent retries only engine start-up, before anything reaches the model. It never re-sends a prompt on its own.
|
|
214
|
+
|
|
215
|
+
<details>
|
|
216
|
+
<summary><b>Ownership and concurrency</b></summary>
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
`--owns` declares what a session may change. A path owns its subtree, globs work, and patterns are relative to `--cwd`. A session without `--owns` owns the whole workspace.
|
|
221
|
+
|
|
222
|
+
- zcode-agent refuses to start a session whose ownership overlaps a running session in the same git repo (exit 7). `--allow-overlap` starts it anyway.
|
|
223
|
+
- After the work, zcode-agent diffs the workspace. Changes outside the session's paths are listed in `scopeViolations` and make a task `partial`. Files in a concurrent session's paths count against that session, not this one.
|
|
224
|
+
- `--touch <path>` allows a small edit outside `--owns` without claiming the path. Touched files are listed in `touched`. Starting is refused if a running session owns a matching path.
|
|
225
|
+
- Every session and every check gets `ZCODE_SESSION_ID`, `ZCODE_PORT` (a free port from 41000 to 48999), `ZCODE_OUT` (`<cwd>/.zcode/out/<id>`) and `ZCODE_TMP`. Files under `.zcode/` never count as changes, and zcode-agent adds `.zcode/` and `.playwright-mcp/` to the repo's `.git/info/exclude`, never to `.gitignore`.
|
|
226
|
+
- `ZAI_CODE_MAX_ACTIVE` (default 8) caps running sessions per machine. Extra sessions wait in `queued`.
|
|
227
|
+
- For risky parallel work, give each session its own git worktree with `--cwd`.
|
|
228
|
+
|
|
229
|
+
</details>
|
|
230
|
+
|
|
231
|
+
### Plans
|
|
232
|
+
|
|
233
|
+
A plan runs several task sessions in dependency order and returns one summary.
|
|
234
|
+
|
|
235
|
+
```json
|
|
236
|
+
{
|
|
237
|
+
"decisions": ["@decisions.md"],
|
|
238
|
+
"effort": "high",
|
|
239
|
+
"sessions": [
|
|
240
|
+
{ "id": "base", "objective": "Scaffold, tokens and a stub for every page",
|
|
241
|
+
"owns": ["package.json", "src/app/**", "src/theme/**"], "checks": ["npm run build"] },
|
|
242
|
+
{ "id": "home", "after": ["base"], "objective": "Home page", "owns": ["src/pages/home/**"] },
|
|
243
|
+
{ "id": "team", "after": ["base"], "objective": "Team page", "owns": ["src/pages/team/**"] }
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
```sh
|
|
249
|
+
zcode-agent plan check plan.json # validate: one line per problem, exit 2
|
|
250
|
+
zcode-agent plan run plan.json --preflight # read-only questions for every session
|
|
251
|
+
zcode-agent plan run plan.json --detach # run it in the background
|
|
252
|
+
zcode-agent plan wait plan --json # one summary line when it ends
|
|
253
|
+
zcode-agent plan resume plan "answers" # resume failed, partial or blocked sessions
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
A session starts when every session it is `after` has completed. Sessions that can run at the same time must own different paths, and `plan check` enforces it. When a session ends without completing, the sessions after it are `skipped` and the rest carry on. Top-level `decisions`, `context`, `files`, `model`, `effort` and `limits` apply to every session. Keep the chain short: each `after` waits for a whole session, and visual criteria belong on the sessions that build finished UI.
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
## Cost
|
|
261
|
+
|
|
262
|
+
`zcode-agent cost [<dir>]` totals every session whose workspace is `<dir>` or below it, one row per session, priced at Z.ai's API list price in USD per million tokens.
|
|
263
|
+
|
|
264
|
+
| model | input | cached input | output |
|
|
265
|
+
|---|---|---|---|
|
|
266
|
+
| GLM-5.3-Flash | 0.15 | 0.03 | 0.50 |
|
|
267
|
+
| GLM-5.3 | 1.40 | 0.26 | 4.40 |
|
|
268
|
+
|
|
269
|
+
The counts come from each session's own engine database and include the executor, its subagents and the verifier, across every resume. `--app` adds the ZCode app's own sessions in that directory, and `--json` prints one object. Set `ZCODE_PRICES='{"GLM-5.3-Flash":{"input":0.15,"cached":0.03,"output":0.5}}'` to use other rates. On a Z.ai coding plan, this is what the work would cost at API rates, not what you pay.
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
## Machine interface
|
|
274
|
+
|
|
275
|
+
With `--json`, stdout carries NDJSON events and then exactly one `{"type":"result",…}` line. With `--quiet`, the result line is the only output. Task sessions leave text deltas out of the events unless you pass `--stream`, so your agent pays only for the lifecycle events.
|
|
276
|
+
|
|
277
|
+
The result line is the compact brief (`zcode.brief/1`). Empty keys are left out:
|
|
278
|
+
|
|
279
|
+
```json
|
|
280
|
+
{"type":"result","schema":"zcode.brief/1","status":"failed","ok":false,"id":"pricing",
|
|
281
|
+
"summary":"…","files":["src/pages/pricing/index.tsx"],
|
|
282
|
+
"checks":[{"command":"npm test","ok":false,"exitCode":1,"tail":"…last 1500 characters…"}],"checksPassed":1,
|
|
283
|
+
"questions":[],"issues":["…"],"scopeViolations":[],"error":{"kind":"checks_failed"},
|
|
284
|
+
"result":"/…/sessions/pricing/result.json"}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
<details>
|
|
288
|
+
<summary><b>Brief fields, the full record and events</b></summary>
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
The brief lists only failing checks (`checksPassed` counts the rest), unmet visual criteria (`visualMet` is `met/total`), up to 6 `decisions` (`decisionsMore` counts the rest) and 40 `files` (`filesMore`). `run` and `agent` briefs also carry `response`, because the answer is the product there. `result` is the path to the full record. `result.json` on disk is always the full `zcode.result/1` record, and `--full` prints it instead of the brief on `task`, `run`, `agent`, `resume`, `wait` and `result`.
|
|
293
|
+
|
|
294
|
+
| `type` | meaning |
|
|
295
|
+
|---|---|
|
|
296
|
+
| `session` | the active session and its scope: id, kind, cwd, owns, checks, model, effort |
|
|
297
|
+
| `phase` | what is running: starting, executing, reporting, checking, repairing, verifying or queued |
|
|
298
|
+
| `tool` | a tool call was scheduled, started, returned or failed |
|
|
299
|
+
| `subagent` | a subagent started, returned or failed |
|
|
300
|
+
| `check` | a check zcode-agent ran, with its exit code and duration |
|
|
301
|
+
| `mcp` | an MCP server connected or failed |
|
|
302
|
+
| `stream` | live text or reasoning (run and agent, or task with `--stream`) |
|
|
303
|
+
|
|
304
|
+
`zcode-agent status <id> --json` returns state, phase, pid, recent events and the result. `zcode-agent wait --json` prints one brief per session as each finishes. When `--timeout-ms` runs out first, it prints one `{"type":"pending","id","state","phase","elapsedMs","idleMs"}` line per running session and exits 124. `zcode-agent <command> --help` prints only that command's usage. Usage errors are always one line.
|
|
305
|
+
|
|
306
|
+
</details>
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
<details>
|
|
311
|
+
<summary><b>All options</b></summary>
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
| option | what it does |
|
|
316
|
+
|---|---|
|
|
317
|
+
| `--id`, `--label` | name the session (run, task, agent). Default id: `zc-<random>` |
|
|
318
|
+
| `--detach` | run in the background and print the id (run, task, agent, resume) |
|
|
319
|
+
| `--cwd` | the workspace, and the limit of what the session may touch. Default: the current directory |
|
|
320
|
+
| `--owns` | repeatable path or glob the session may change. Default: the whole workspace |
|
|
321
|
+
| `--touch` | task: repeatable small edits outside `--owns` |
|
|
322
|
+
| `--allow-overlap` | start despite overlapping ownership |
|
|
323
|
+
| `--task` | task: a JSON contract, a markdown brief, or `-` for stdin |
|
|
324
|
+
| `--accept` | task: repeatable acceptance criterion |
|
|
325
|
+
| `--check` | task: repeatable shell check that zcode-agent runs itself |
|
|
326
|
+
| `--file` | task: repeatable file to read first |
|
|
327
|
+
| `--context` | task: repeatable background; `@file` reads a file |
|
|
328
|
+
| `--decision` | task: repeatable binding decision |
|
|
329
|
+
| `--decisions` | task: binding decisions, usually `@file` |
|
|
330
|
+
| `--preflight` | task and plan run: a read-only turn that returns the open questions |
|
|
331
|
+
| `--unit` | task: repeatable `"name: objective [owns a,b]"`, one subagent per unit |
|
|
332
|
+
| `--visual` | task: repeatable criterion a fresh session judges from screenshots |
|
|
333
|
+
| `--viewport` | task: repeatable `WxH` for `--visual`. Default: `390x844` and `1440x900` |
|
|
334
|
+
| `--serve` | task: the command that serves the app on `$ZCODE_PORT` |
|
|
335
|
+
| `--max-repairs` | task and resume: repair turns after failures. Default: 2 |
|
|
336
|
+
| `--check-timeout-ms` | task and resume: time limit per check. Default: 300000 |
|
|
337
|
+
| `--model` | `glm-5.3-flash` (default) or `glm-5.3` |
|
|
338
|
+
| `--effort` | `low`, `high` or `max` (default) |
|
|
339
|
+
| `--timeout-ms` | the whole run, checks and repairs included. Default: 10 min for run, 2 h for task |
|
|
340
|
+
| `--session` | run: continue by zcode-agent id or engine `sess_` id |
|
|
341
|
+
| `--profile` | agent: the subagent profile. Default: `general-purpose` |
|
|
342
|
+
| `--mcp` | add MCP servers, as inline JSON or `@file` |
|
|
343
|
+
| `--mcp-list` | print the effective MCP server set and exit |
|
|
344
|
+
| `--hermetic` | leave out the ZCode app's MCP servers and skills |
|
|
345
|
+
| `--no-browser` | drop the Playwright MCP server |
|
|
346
|
+
| `--skills` | add skills: one skill directory, or a directory of them |
|
|
347
|
+
| `--no-skills` | run with no skills at all |
|
|
348
|
+
| `--inherit-desktop` | also give the executor the app's `AGENTS.md`, plugins and agent profiles |
|
|
349
|
+
| `--install-browser` | doctor: install the Chromium build the default Playwright server uses |
|
|
350
|
+
| `--json` | NDJSON events, then one result line |
|
|
351
|
+
| `--full` | with `--json`, and on result and wait: the full record instead of the brief |
|
|
352
|
+
| `--quiet` | no progress output |
|
|
353
|
+
| `--any` | wait: return when the first session finishes |
|
|
354
|
+
| `--app` | cost: also count the ZCode app's sessions |
|
|
355
|
+
| `--thinking` | mirror reasoning to stderr (on for run, off for task; `--no-thinking` turns it off) |
|
|
356
|
+
| `--stream` | task: include text deltas in the events |
|
|
357
|
+
| `--include-reasoning` | put the full reasoning in the result |
|
|
358
|
+
|
|
359
|
+
</details>
|
|
360
|
+
|
|
361
|
+
<details>
|
|
362
|
+
<summary><b>Exit codes</b></summary>
|
|
363
|
+
|
|
364
|
+
| code | meaning |
|
|
365
|
+
|---|---|
|
|
366
|
+
| 0 | completed |
|
|
367
|
+
| 1 | unexpected internal error |
|
|
368
|
+
| 2 | usage error: bad flag, model, effort, contract, or a session id that exists |
|
|
369
|
+
| 3 | no API key (`ZAI_API_KEY`, `zcode-agent login`, or a key in the ZCode app) |
|
|
370
|
+
| 4 | engine not found (reinstall; the engine comes with the package) |
|
|
371
|
+
| 5 | failed: engine or turn error |
|
|
372
|
+
| 6 | `agent`: no subagent ran, or none ended `success` |
|
|
373
|
+
| 7 | overlapping ownership, or the session is already running |
|
|
374
|
+
| 8 | partial, or checks still failing after repairs |
|
|
375
|
+
| 9 | unverified |
|
|
376
|
+
| 10 | blocked |
|
|
377
|
+
| 124 | `--timeout-ms` ran out |
|
|
378
|
+
| 130 | cancelled |
|
|
379
|
+
|
|
380
|
+
</details>
|
|
381
|
+
|
|
382
|
+
<details>
|
|
383
|
+
<summary><b>Under the hood</b></summary>
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
**The API key.** zcode-agent takes the key from `ZAI_API_KEY`, then from `zcode-agent login` (stored in `~/.zcode-agent/credentials.json`, mode 600), then from the ZCode app's own Z.ai API key, read where the app stores it. `ZCODE_NO_DESKTOP_KEY=1` turns the last one off. zcode-agent never reads the app's OAuth tokens, never prints or logs the key, and scrubs it from engine messages and check output. The only file it writes the key to is each session's own provider config, which the engine needs.
|
|
388
|
+
|
|
389
|
+
**Isolation.** zcode-agent keeps its state in `~/.zcode-agent` and never writes to `~/.zcode`, which belongs to the ZCode app. On first run it moves a pre-1.0 `~/.zcode-cli` there and leaves a symlink. Each session's engine runs with `HOME` set to the session's own directory. On every run zcode-agent rewrites that directory's config: the provider with your key, the app's MCP servers (minus OAuth servers and those in `~/.zcode-agent/mcp-health.json` that failed in the last six hours), and the app's user skills, including symlinked ones. Every session gets zcode-agent's executor instructions as its `AGENTS.md`: headless rules, the session's port and output directories, and when to split work across subagents. The Playwright server runs with a fresh browser profile per engine, so the executor's and the verifier's browsers never share a lock or a cache. zcode-agent never touches the engine's database, so sessions stay resumable.
|
|
390
|
+
|
|
391
|
+
**The engine.** `@zcode-agent/engine` is the headless ZCode engine (`zcode.cjs`), built by `npm run build:engine` from the tag in `packages/engine/engine.json`, with the content plugins and bundled skills the app ships and upstream's `LICENSE`, `NOTICE.md` and third-party notices. `ZAI_CODE_ENGINE` points at another `zcode.cjs`. Without the package, zcode-agent uses the ZCode app's engine. `zcode-agent doctor` shows which engine runs and warns when its version differs from the tested one.
|
|
392
|
+
|
|
393
|
+
**Yolo mode.** The engine approves tool calls on its own, as in its headless default, and `--cwd` limits where they run. A headless turn that asks for input ends as `blocked` instead of hanging. The executor instructions forbid commits, pushes, deploys and other outside effects unless the task asks for them.
|
|
394
|
+
|
|
395
|
+
**Environment.** `ZAI_API_KEY`, `ZAI_CODE_HOME` (state directory), `ZAI_CODE_ENGINE`, `ZAI_CODE_NODE` (the engine's Node), `ZAI_CODE_BUILTIN_PROVIDER_CONFIG`, `ZAI_CODE_LIVE_DIR` (the app's directory, default `~/.zcode`), `ZCODE_HERMETIC=1`, `ZCODE_INHERIT_DESKTOP=1`, `ZCODE_NO_DESKTOP_KEY=1`, `ZAI_CODE_MAX_ACTIVE`, `ZCODE_PRICES`, `ZCODE_APP_DB` (the app's database for `cost --app`), `NO_COLOR`.
|
|
396
|
+
|
|
397
|
+
</details>
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
## Development
|
|
402
|
+
|
|
403
|
+
The repo is an npm workspace with two packages. [`packages/cli`](https://github.com/0xgeorgemathew/zcode-agent/tree/main/packages/cli) is `zcode-agent`: plain CommonJS, no build step, and no dependency except the engine. [`packages/engine`](https://github.com/0xgeorgemathew/zcode-agent/tree/main/packages/engine) is `@zcode-agent/engine`, built from upstream.
|
|
404
|
+
|
|
405
|
+
```sh
|
|
406
|
+
npm install # link the workspace
|
|
407
|
+
npm run build:engine # build the engine from the pinned zai-org/ZCode tag
|
|
408
|
+
npm test # unit tests: in-process fake engine, no API calls
|
|
409
|
+
npm run test:live # live tests: the real engine and the GLM API
|
|
410
|
+
npm run release:check # verify the engine pin, run the tests, pack both packages
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
Live tests read the key from the repo's `.env`, which is never committed or published. `DESIGN.md` records the design decisions and the engine protocol facts.
|
|
414
|
+
|
|
415
|
+
## License
|
|
416
|
+
|
|
417
|
+
zcode-agent is MIT. The bundled engine is Apache-2.0, and upstream's license and notices ship inside `@zcode-agent/engine`.
|
|
418
|
+
|
|
419
|
+
zcode-agent is an independent project. It is not affiliated with, endorsed by or sponsored by Zhipu AI or Z.ai. ZCode and GLM belong to Z.ai.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# zcode-agent executor
|
|
2
|
+
|
|
3
|
+
You run headless inside zcode-agent. No human watches this session: an orchestrator reads only your final answer or handback, so never wait for input or approval.
|
|
4
|
+
|
|
5
|
+
- Commands must not block on input: pass non-interactive flags (`--yes`, `CI=1`, `--no-open`); no editors, pagers or watch modes. Run servers in the background and stop them when done.
|
|
6
|
+
- Bind only `$ZCODE_PORT`. Build output and test artifacts go under `$ZCODE_OUT`, scratch files under `$ZCODE_TMP`. Other sessions may be running in the same repo at the same time.
|
|
7
|
+
- Change only files inside the workspace that your task lets you change. Don't commit, push, publish, deploy or install global packages unless the task says so.
|
|
8
|
+
- Be fast: a short todo list, then batched tool calls. Don't draft files in your reasoning or re-read files you just wrote.
|
|
9
|
+
- Parallelize independent work: when parts of the task touch disjoint files, start one subagent per part in a single batch, each with a bounded objective and an explicit list of files it may change. Keep work that shares files or needs shared context in one agent. Check the integrated result yourself.
|
|
10
|
+
- Drive browsers only through the Playwright MCP tools.
|