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
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: zcode-agent
|
|
3
|
+
description: Delegate scoped implementation work to the zcode-agent CLI (cheap GLM-5.3-Flash executor: sees images, has Playwright; an independent vision verifier judges UI) and consume its compact verified handback. Use when you are orchestrating: you make the product, design and logic decisions once, then zcode-agent implements, tests, visually verifies and repairs — in one session with subagent units, several parallel sessions, or a dependency plan — while you spend tokens only on decisions and exceptions.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Operating zcode-agent as an executor
|
|
7
|
+
|
|
8
|
+
zcode-agent is a CLI execution engine. You decide; it builds. It implements a scoped task in its own session, runs your checks itself, has a fresh, independent vision verifier screenshot and judge UI when you ask, repairs failures within a budget, and returns a small structured handback.
|
|
9
|
+
|
|
10
|
+
**The point is cost.** Your tokens are the expensive ones; GLM-5.3-Flash's are cheap. Your tokens go to decisions and exceptions. Everything mechanical — writing code, running builds and tests, reading diffs, looking at screenshots, fixing small failures — is zcode-agent's. If you are doing any of that after dispatch, you are paying twice.
|
|
11
|
+
|
|
12
|
+
Check readiness once per machine: `zcode-agent doctor` (exit 3 → no key: the user runs `zcode-agent login` or sets `ZAI_API_KEY`; with the ZCode app installed its key, MCP servers and skills are used automatically). Don't run `--help` or a bare `zcode-agent status`: everything you need is here.
|
|
13
|
+
|
|
14
|
+
## The workflow
|
|
15
|
+
|
|
16
|
+
1. **Read** the codebase as much as you need to plan. This is the one phase where reading files is expected.
|
|
17
|
+
2. **Decide** everything a user could see or a system depends on (checklists below). Write the decisions down once, as decisions — a file such as `docs/decisions.md` that sessions receive with `--decisions @file`.
|
|
18
|
+
3. **Shape** the work: one session, one session with units, parallel sessions, or a plan (see Parallelizing).
|
|
19
|
+
4. **Preflight** (optional): `--preflight` makes zcode-agent list every question it would otherwise guess; answer them all in one edit to the decisions file. It costs you a round trip, so use it only when your decisions have known gaps or the work is large and novel; skip it when the checklists below are fully covered.
|
|
20
|
+
5. **Dispatch and wait** with `--detach` + `zcode-agent wait`, or `zcode-agent plan run` + `zcode-agent plan wait`.
|
|
21
|
+
6. **Handle exceptions only.** `completed` → move on. Anything else → read only what the brief shows, answer or adjust in one line with `zcode-agent resume`.
|
|
22
|
+
|
|
23
|
+
## Deciding: leave nothing open-ended
|
|
24
|
+
|
|
25
|
+
The executor implements binding decisions exactly and is told not to invent anything user-visible or behavioural. Gaps either block it (a round trip for you) or get the most conservative default. Close them up front.
|
|
26
|
+
|
|
27
|
+
**Front end:** palette (exact values), type families and scale, spacing scale, radii, iconography/illustration style; every section's layout and hierarchy at each breakpoint you care about; exact copy; component states (hover, focus, active, disabled, loading, empty, error); motion (what moves, property, distance, duration, easing, stagger, trigger, reduced-motion behaviour); accessibility (focus order, traps, labels, contrast floor); stack and libraries; performance budget.
|
|
28
|
+
|
|
29
|
+
**Back end / logic:** data shapes and storage keys; API routes, payloads, status codes and errors; validation rules (exact regexes, ranges); state machines (steps, transitions, what persists, what resets); auth and permissions; idempotency and retries; what is mocked vs real; side effects that are forbidden.
|
|
30
|
+
|
|
31
|
+
**Boundaries:** what the executor may choose freely (internal names, file structure, helpers) and what it must ask about.
|
|
32
|
+
|
|
33
|
+
Keep the decisions file dense: tables and one-line statements, no prose, no rationale the executor doesn't need (aim for a few thousand tokens for a one-page site). Write decisions as statements, not wishes: "Reveal: opacity 0→1 and translateY 16px→0, 400 ms, cubic-bezier(.2,.7,.2,1), 60 ms stagger, at 20% visibility; reduced motion: opacity only."
|
|
34
|
+
|
|
35
|
+
## Parallelizing
|
|
36
|
+
|
|
37
|
+
Parallel work can cut wall time a lot, but it is optional: one well-specified session is always correct. Split only when the work really splits, and never at the cost of a session finishing without you. Two levels, cheapest first:
|
|
38
|
+
|
|
39
|
+
1. **Units inside one session** (`--unit "name: objective [owns a,b]"`). The executor runs one subagent per unit and integrates the result. One engine, one verifier pass, shared context, no extra briefs for you to read. Use it when the pieces share decisions and context but write separate files: one page's sections, one module's functions, a component set.
|
|
40
|
+
2. **Several sessions** (`--detach` each, then one `wait` on all ids), or a **plan** when there are dependencies. Each session is a separate executor with its own context, port, verifier and brief. Use it when the pieces are independent deliverables.
|
|
41
|
+
|
|
42
|
+
| the work | shape |
|
|
43
|
+
|---|---|
|
|
44
|
+
| one deliverable, small or tightly coupled | one session, no units |
|
|
45
|
+
| one deliverable with 3–6 separable parts that share decisions | one session + units |
|
|
46
|
+
| 2+ independent deliverables that own disjoint paths | parallel sessions |
|
|
47
|
+
| a shared base first (scaffold, schema, design tokens), then parallel features | a plan with `after` |
|
|
48
|
+
|
|
49
|
+
**Split only when all of these hold:**
|
|
50
|
+
- Every concurrent session (and every unit) owns disjoint paths. Overlap is refused (exit 7; `plan check` catches it).
|
|
51
|
+
- Shared files have one owner: `package.json`, lockfiles, router, app shell, global styles, config. Give them to a scaffold session that runs first and mounts a stub for every feature, so feature sessions need no wiring. A later session may `--touch` a shared file only for a tiny edit no running session owns.
|
|
52
|
+
- Dependencies are decided and installed up front, by one session. Parallel sessions must not add packages: concurrent installs race on the lockfile.
|
|
53
|
+
- No piece needs a decision another piece will make. Put every shared decision in the decisions file all sessions receive.
|
|
54
|
+
- Each piece is big enough to pay for itself: a session costs startup plus its own verifier round (minutes) on the critical path. A 5-minute fix is one session.
|
|
55
|
+
|
|
56
|
+
**Keep it bounded.** 2–4 concurrent sessions is the useful range; past that they contend for the GLM rate limit and the machine (each runs its own engine, MCP servers, builds and browser), and sessions beyond `ZAI_CODE_MAX_ACTIVE` (8) queue. Units: 2–6 per session.
|
|
57
|
+
|
|
58
|
+
**Keep the critical path short.** Each `after` stage waits for a whole session (tens of minutes). Prefer one wide stage over a chain. Integration, if you need one at all, is a small pass (cross-feature checks, fix only what breaks between features), not a rebuild.
|
|
59
|
+
|
|
60
|
+
Visual criteria cost a verifier round (minutes of Flash time on the critical path), so put them where finished UI is built. A scaffold of stubs gets checks only; an integration session gets only cross-cutting criteria (the whole page in order, anchors, the dialog opening from every button), not a re-check of what the feature sessions' verifiers already passed.
|
|
61
|
+
|
|
62
|
+
Parallel safety is automatic: each session gets `ZCODE_PORT`, `ZCODE_OUT`, `ZCODE_TMP` and `ZCODE_SESSION_ID`. Tell the first (scaffold) session to make dev-server ports, build output dirs and test artifacts honour them. zcode-agent keeps `.zcode/` and `.playwright-mcp/` out of git via the repo's local `.git/info/exclude`; you don't need to touch `.gitignore` for them.
|
|
63
|
+
|
|
64
|
+
Parallel sessions cost you little extra while they run: one `wait` on all of them (or `plan wait`) covers every session, and you read one brief per session at the end.
|
|
65
|
+
|
|
66
|
+
## The handoff
|
|
67
|
+
|
|
68
|
+
| field | flag | give it when |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| objective | positional text | always: the outcome, not the steps |
|
|
71
|
+
| decisions | `--decision "…"`, `--decisions @file` | always for anything user-visible or behavioural |
|
|
72
|
+
| checks | `--check "cmd"` | always: build, typecheck, tests, lint, greps — zcode-agent runs them itself |
|
|
73
|
+
| visual | `--visual "criterion"`, `--viewport WxH`, `--serve "cmd"` | any UI work: after the build, a fresh vision verifier serves on $ZCODE_PORT, waits for animations to finish, screenshots each viewport, quotes the text it can actually see, judges each criterion (plus "all intended text is readable"), and unmet ones go back to the implementer for repair. Phrase criteria as what must be visible: "hero headline 'Your money, simplified' is fully readable at 390 and 1440" |
|
|
74
|
+
| units | `--unit "name: objective [owns a,b]"` | one session should fan out to subagents (see Parallelizing) |
|
|
75
|
+
| owns | `--owns path/glob` | always when other sessions may run in the same repo; must be disjoint from every concurrent session |
|
|
76
|
+
| touch | `--touch path` | a small edit to a shared file no running session owns |
|
|
77
|
+
| files | `--file path` | files to read first (don't also pass them as `--context @`) |
|
|
78
|
+
| context | `--context "…"` / `--context @file` | background that isn't a decision |
|
|
79
|
+
| acceptance | `--accept "…"` | criteria beyond checks and visuals |
|
|
80
|
+
| everything | `--task contract.json` | keys: objective, scope, constraints, decisions, design, acceptance, checks, visual, viewports, units, files, references, context, owns, touch, limits, model, effort |
|
|
81
|
+
|
|
82
|
+
Environment: by default the executor gets the ZCode app's MCP servers and user skills (OAuth-only remote servers excluded) plus zcode-agent's own executor instructions; `--hermetic` gives it only your `--mcp` servers and `--skills`. Leave the default unless a run needs to be reproducible on another machine.
|
|
83
|
+
|
|
84
|
+
Model and effort: don't pass `--model`. Everything runs on GLM-5.3-Flash by default (it sees images): sessions, units, plans, the verifier. Use `--model glm-5.3` only when the user asks for it; it can't see images. `--effort low|high|max` (default `max`). Other values are refused before anything starts.
|
|
85
|
+
|
|
86
|
+
## Running
|
|
87
|
+
|
|
88
|
+
```sh
|
|
89
|
+
zcode-agent task --detach --id <id> --cwd <repo> [flags] "<objective>" # prints the id, returns at once
|
|
90
|
+
zcode-agent wait <id…> --timeout-ms 540000 --json --quiet # 124 = still running (one line each): wait again
|
|
91
|
+
zcode-agent wait <id…> --any --timeout-ms 540000 --json --quiet # return on the first that finishes
|
|
92
|
+
zcode-agent resume <id> "<answer or follow-up>" --detach # same session, context intact
|
|
93
|
+
zcode-agent result <id> [--full] # brief again, or the full record
|
|
94
|
+
zcode-agent cancel <id>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Plans:
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
zcode-agent plan check plan.json
|
|
101
|
+
zcode-agent plan run plan.json --detach [--preflight]
|
|
102
|
+
zcode-agent plan wait <name> --timeout-ms 540000 --json # one summary line per session; details only for non-completed
|
|
103
|
+
zcode-agent plan resume <name> ["<message>"] # resume failed/partial, relaunch skipped
|
|
104
|
+
zcode-agent plan resume <name> --session <id> "<answer>" # answer one blocked session
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`plan.json`: `{"cwd"?, "decisions"?, "context"?, "files"?, "model"?, "effort"?, "limits"?, "sessions": [{"id", "after"?: [ids], "label"?, ...contract keys}]}`. Top-level decisions/context/files/limits go to every session; `@` entries resolve against the plan file's directory, then the plan's cwd. Don't also list the decisions file under `files`: it is already inlined. The plan name is the file basename (or `--id`). Sessions that can run at the same time must own disjoint paths; `plan check` enforces it. When an upstream session ends non-completed, its dependants are `skipped` until you `plan resume`.
|
|
108
|
+
|
|
109
|
+
Session ids are global and permanent: give every new run a fresh prefix (`wc3-scaffold`, …) so `plan check` passes first time. A task session may run 2 h by default; a big session (a whole page, a whole flow) can set `"limits": {"timeoutMs": 10800000}`. If one still times out, `zcode-agent plan resume <name> "continue"` picks up from the files it already wrote.
|
|
110
|
+
|
|
111
|
+
While sessions run, the user can watch them with `zcode-agent watch` (live phase, last tool, model requests, GLM cost so far, `STALLED?` after 8 idle minutes) and total a directory with `zcode-agent cost`; you never run either. `wait` timeout lines carry `idleMs`/`stalled`: a stalled session is the one case to `cancel` + `resume` early.
|
|
112
|
+
|
|
113
|
+
Real tasks outlast a single shell call; always wait in bounded slices. zcode-agent needs network access (the GLM API) and write access to `~/.zcode-agent` and the target repo: in a sandboxed Codex session, if a command fails with a sandbox or network error, re-run the same command with escalated permissions instead of changing it.
|
|
114
|
+
|
|
115
|
+
## Reading the brief
|
|
116
|
+
|
|
117
|
+
`--json` prints one compact line: `status`, `summary`, `files`, failing `checks` with tails (`checksPassed` counts the rest), `questions`, `issues`, `unresolved`, `scopeViolations`, `touched`, the first `decisions` (`decisionsMore` counts the rest), unmet `visual` with what the verifier actually `seen` (`visualMet` is "met/total"), `units`, and `result` (path to the full record). Read it straight from the command output; don't pipe it through jq, python or tail.
|
|
118
|
+
|
|
119
|
+
| status | exit | do |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| `completed` | 0 | nothing. Skim `decisions` (the executor's own in-scope choices); veto with `resume` only if one is wrong |
|
|
122
|
+
| `blocked` | 10 | answer `questions` (they come with options and a recommendation) via `zcode-agent resume <id> "<answer>"`, and add the answer to your decisions file |
|
|
123
|
+
| `partial` | 8 | read `issues` / `unresolved` / unmet `visual` / `scopeViolations`; resume with one-line guidance or re-scope |
|
|
124
|
+
| `failed` | 8/5/124 | read the failing check `tail` or `error`; resume with guidance |
|
|
125
|
+
| `unverified` | 9 | you forgot checks: resume with a check added |
|
|
126
|
+
| `cancelled` | 130 | resume if wanted |
|
|
127
|
+
|
|
128
|
+
## Hard rules after dispatch
|
|
129
|
+
|
|
130
|
+
- Don't open files a `completed` session changed. Don't re-run checks it ran. Don't look at its screenshots.
|
|
131
|
+
- Don't poll `status`; use `wait` (or `plan wait`) once, in the background if you like, and act on its exit.
|
|
132
|
+
- Don't fix code yourself; `resume` the session with one line.
|
|
133
|
+
- Need to know something about the result? `zcode-agent result <id> --full` first; read code only as a last resort.
|
|
134
|
+
- Don't ask zcode-agent to commit, push, publish or deploy unless the user asked; when they did, make it its own final session gated on everything else being `completed`.
|
|
135
|
+
|
|
136
|
+
## Example: a marketing one-pager with an application form
|
|
137
|
+
|
|
138
|
+
You read the empty repo, decide the design system, copy, motion, form logic and demo constraints, and write `docs/decisions.md`. Then `plan.json`:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"decisions": ["@docs/decisions.md"],
|
|
143
|
+
"effort": "high",
|
|
144
|
+
"sessions": [
|
|
145
|
+
{"id": "scaffold", "owns": ["package.json", "package-lock.json", "index.html", "*.config.*", "tsconfig*.json", "src/app/**", "src/styles/**", "src/components/**", "e2e/smoke.spec.ts", ".gitignore"],
|
|
146
|
+
"objective": "Vite + React + TS scaffold, tokens, shared shell, stubs for src/landing and src/apply; dev/preview/e2e honour ZCODE_PORT and ZCODE_OUT",
|
|
147
|
+
"checks": ["npm run build", "npm test", "npm run e2e"]},
|
|
148
|
+
{"id": "landing", "after": ["scaffold"], "owns": ["src/landing/**", "e2e/landing.spec.ts"],
|
|
149
|
+
"objective": "All landing sections per the decisions",
|
|
150
|
+
"units": ["hero: …", "highlights: …", "products: …", "how: …", "charges: …", "faqs: …", "about-cta: …"],
|
|
151
|
+
"checks": ["npm run build", "npx playwright test e2e/landing.spec.ts"],
|
|
152
|
+
"visual": ["hero headline fits on two lines at 390px", "product cards align on one row at 1440px", "no text overlaps any circle motif"]},
|
|
153
|
+
{"id": "apply", "after": ["scaffold"], "owns": ["src/apply/**", "e2e/apply.spec.ts"],
|
|
154
|
+
"objective": "Application dialog: demo OTP, four steps, local draft, thank-you",
|
|
155
|
+
"checks": ["npm run build", "npm test -- apply", "npx playwright test e2e/apply.spec.ts"],
|
|
156
|
+
"visual": ["OTP code is visible on screen after entering a number", "step indicator shows the current step at 390px"]},
|
|
157
|
+
{"id": "integration", "after": ["landing", "apply"], "owns": ["src/App.tsx", "e2e/**"],
|
|
158
|
+
"objective": "Full-page pass across landing and apply: fix only what breaks between them",
|
|
159
|
+
"checks": ["npm run build", "npm test", "npm run e2e"],
|
|
160
|
+
"visual": ["every section heading is readable in page order at 390 and 1440", "the apply dialog opens readable from the hero and closing buttons"]}
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
`zcode-agent plan check plan.json` → `zcode-agent plan run plan.json --preflight` (read-only `<id>.pre` sessions, all at once; downstream sessions are told their upstream hasn't run yet; prints only the questions) → answer them once in the decisions file → `zcode-agent plan run plan.json --detach` → `zcode-agent plan wait plan --timeout-ms 540000 --json`. Your total involvement: the decisions, one answer pass, one summary.
|
|
166
|
+
|
|
167
|
+
## Exit codes
|
|
168
|
+
|
|
169
|
+
0 completed · 2 usage (bad flag, contract, plan, effort, or duplicate id) · 3 no key · 4 no engine · 5 failed · 6 `agent` had no subagent · 7 workspace conflict / session busy · 8 partial or checks failing · 9 unverified · 10 blocked · 124 timeout (for `wait`: still running) · 130 cancelled.
|