zcode-supervisor 0.0.1__py3-none-any.whl

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.
@@ -0,0 +1,928 @@
1
+ Metadata-Version: 2.4
2
+ Name: zcode-supervisor
3
+ Version: 0.0.1
4
+ Summary: Codex-side supervisor tooling for safely delegating bounded coding tasks to ZCode.
5
+ Author: ZCode-supervisor contributors
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/AkiGarage/ZCode-supervisor
8
+ Project-URL: Source, https://github.com/AkiGarage/ZCode-supervisor
9
+ Project-URL: Issues, https://github.com/AkiGarage/ZCode-supervisor/issues
10
+ Project-URL: Documentation, https://github.com/AkiGarage/ZCode-supervisor#readme
11
+ Requires-Python: >=3.11
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ ![ZCode Supervisor Toolkit hero](assets/images/zcode-supervisor-toolkit-hero.png)
17
+
18
+ <p align="center">
19
+ <strong>Language / 言語</strong><br>
20
+ <a href="./README.md"><kbd>English</kbd></a>
21
+ <a href="./README.ja.md"><kbd>日本語で読む</kbd></a>
22
+ </p>
23
+
24
+ # ZCode-supervisor
25
+
26
+ ![Version](https://img.shields.io/badge/version-v0.0.1-blue)
27
+ ![License](https://img.shields.io/badge/license-MIT-green)
28
+ ![Node](https://img.shields.io/badge/node-%3E%3D22-339933)
29
+ ![Python](https://img.shields.io/badge/python-%3E%3D3.11-3776AB)
30
+
31
+ Codex-side tooling for using ZCode as a bounded coding worker while Codex stays
32
+ the orchestrator and final auditor.
33
+
34
+ **日本語版はこちら:** [README.ja.md を開く](./README.ja.md)
35
+
36
+ This repository is not affiliated with Z.AI or ZCode.
37
+
38
+ ## Quick Start
39
+
40
+ The current public setup path is `uvx` from this GitHub repo:
41
+
42
+ ```bash
43
+ uvx --from git+https://github.com/AkiGarage/ZCode-supervisor.git \
44
+ zcode-install-repo /ABSOLUTE/PATH/TO/YOUR/TARGET_REPO
45
+ ```
46
+
47
+ After the first PyPI release, the shorter package command will be:
48
+
49
+ ```bash
50
+ uvx --from zcode-supervisor zcode-install-repo /ABSOLUTE/PATH/TO/YOUR/TARGET_REPO
51
+ ```
52
+
53
+ Then check the routing decision before the first delegated task:
54
+
55
+ ```bash
56
+ zcode-auto-route \
57
+ --workspace /ABSOLUTE/PATH/TO/YOUR/TARGET_REPO \
58
+ --objective "setup smoke check"
59
+ ```
60
+
61
+ For development from source, clone this repo and run the underlying Python
62
+ command directly:
63
+
64
+ ```bash
65
+ git clone https://github.com/AkiGarage/ZCode-supervisor.git
66
+ cd ZCode-supervisor
67
+ python3 tools/zcode_supervisor/zcode_supervisor.py install-repo \
68
+ --repo /ABSOLUTE/PATH/TO/YOUR/TARGET_REPO \
69
+ --write-agents
70
+ ```
71
+
72
+ The Homebrew tap is archived for now; clone `AkiGarage/ZCode-supervisor` for
73
+ source work.
74
+
75
+ Release details and verification commands are in
76
+ [docs/distribution.md](docs/distribution.md).
77
+
78
+ ## Ask Codex To Set It Up
79
+
80
+ If you want Codex to do the setup for you, copy this whole prompt into Codex.
81
+ GitHub shows a copy button on the code block. Replace
82
+ `/ABSOLUTE/PATH/TO/YOUR/TARGET_REPO` with the absolute path to the repo you want
83
+ ZCode to help edit.
84
+
85
+ ```text
86
+ You are Codex. Please set up ZCode-supervisor for this target repo:
87
+
88
+ TARGET_REPO=/ABSOLUTE/PATH/TO/YOUR/TARGET_REPO
89
+
90
+ Goal:
91
+ Make this target repo ready for the ZCode-supervisor workflow where Codex keeps
92
+ planning, orchestration, validation, audit, recovery, and final acceptance, and
93
+ ZCode only performs bounded implementation through zcodectl run-packet.
94
+
95
+ Rules:
96
+ - Be careful and non-destructive.
97
+ - Do not read or print secrets, .env files, credentials, API keys, private keys,
98
+ or token files.
99
+ - Do not edit application source code in the target repo during setup.
100
+ - If TARGET_REPO is still a placeholder, stop and ask me for the real absolute
101
+ path.
102
+ - If a required app or tool is missing, stop with the exact missing prerequisite
103
+ and the next command or official link I should use.
104
+ - Do not push, commit, delete branches, or change production behavior.
105
+
106
+ Steps:
107
+ 1. Confirm TARGET_REPO exists and is a git repository.
108
+ 2. Prefer the public GitHub-backed `uvx` path. If `uvx --version` works, set
109
+ INSTALLER_MODE=uvx and do not clone anything. If `uvx` is missing, show this
110
+ official install link and continue with the source fallback:
111
+ https://docs.astral.sh/uv/getting-started/installation/
112
+ 3. For source fallback only, find this ZCode-supervisor repo locally. Prefer
113
+ ~/dev/ZCode-supervisor if it exists. Set SUPERVISOR_REPO to the real absolute
114
+ path. If it is not present, clone it with:
115
+ mkdir -p ~/dev
116
+ git clone https://github.com/AkiGarage/ZCode-supervisor.git ~/dev/ZCode-supervisor
117
+ If clone fails, stop and report the exact error.
118
+ 4. Verify local basics:
119
+ - node --version must be >= 22
120
+ - python3 --version must be >= 3.11
121
+ - git --version must work
122
+ 5. Verify ZCode is installed or give me this official install link:
123
+ https://zcode.z.ai/en/docs/install
124
+ 6. Run the target repo installer from Terminal or shell. If INSTALLER_MODE=uvx:
125
+ uvx --from git+https://github.com/AkiGarage/ZCode-supervisor.git \
126
+ zcode-install-repo "$TARGET_REPO"
127
+ Otherwise run the source fallback:
128
+ python3 "$SUPERVISOR_REPO/tools/zcode_supervisor/zcode_supervisor.py" install-repo \
129
+ --repo "$TARGET_REPO" \
130
+ --write-agents
131
+ 7. Verify these files now exist inside TARGET_REPO:
132
+ - .codex/zcode-routing.json
133
+ - .codex/ZCODE_DELEGATION.md
134
+ - .agents/mcp.json
135
+ - AGENTS.md
136
+ 8. Run a dry route check. If INSTALLER_MODE=uvx:
137
+ uvx --from git+https://github.com/AkiGarage/ZCode-supervisor.git \
138
+ zcode-auto-route \
139
+ --workspace "$TARGET_REPO" \
140
+ --objective "setup smoke check"
141
+ Otherwise run:
142
+ python3 "$SUPERVISOR_REPO/tools/zcode_supervisor/zcode_supervisor.py" auto-route \
143
+ --workspace "$TARGET_REPO" \
144
+ --objective "setup smoke check"
145
+ 9. If possible, run preflight. If INSTALLER_MODE=uvx:
146
+ uvx --from git+https://github.com/AkiGarage/ZCode-supervisor.git \
147
+ zcodectl cli-preflight
148
+ uvx --from git+https://github.com/AkiGarage/ZCode-supervisor.git \
149
+ zcodectl vision-preflight --workspace "$TARGET_REPO"
150
+ Otherwise run:
151
+ node "$SUPERVISOR_REPO/tools/zcode_control/zcodectl.mjs" cli-preflight
152
+ node "$SUPERVISOR_REPO/tools/zcode_control/zcodectl.mjs" vision-preflight --workspace "$TARGET_REPO"
153
+ 10. Report:
154
+ - what was written
155
+ - commands run
156
+ - pass/fail result for each check
157
+ - anything I still need to do manually
158
+ - the exact command I should use for the first real delegated task
159
+
160
+ Success means the target repo has routing files installed, a dry route check
161
+ works, and I understand any remaining manual prerequisite.
162
+ ```
163
+
164
+ ## Setup Guide: Set Up One Target Repo
165
+
166
+ Use this section when you are starting from zero. The goal is to mark one
167
+ existing repository as a place where Codex can plan and audit while ZCode does
168
+ bounded implementation work.
169
+
170
+ ### 0. Know The Two Repositories
171
+
172
+ - **This repo:** `ZCode-supervisor`. It contains the supervisor tools.
173
+ - **Target repo:** the repo you want ZCode to help edit. This is the path you
174
+ pass to `zcode-install-repo`.
175
+
176
+ `/path/to/target-repo` is a placeholder. Replace it with the absolute path to
177
+ your own target repo, such as:
178
+
179
+ ```bash
180
+ ~/work/my-app
181
+ ```
182
+
183
+ You can get the absolute path by opening Terminal, moving into the target repo,
184
+ and running:
185
+
186
+ ```bash
187
+ pwd
188
+ ```
189
+
190
+ ### 1. Put This Supervisor Repo On Disk
191
+
192
+ If you are reading this on GitHub and do not have the repo locally yet, clone
193
+ it first:
194
+
195
+ ```bash
196
+ git clone https://github.com/AkiGarage/ZCode-supervisor.git
197
+ cd ZCode-supervisor
198
+ pwd
199
+ ```
200
+
201
+ The `pwd` output is the absolute path to this supervisor repo. If your clone is
202
+ not at `~/dev/ZCode-supervisor`, replace that path in examples with
203
+ your own supervisor repo path.
204
+
205
+ ### 2. Install The Required Apps And Tools
206
+
207
+ Install and sign in to ZCode first:
208
+
209
+ - ZCode install docs: https://zcode.z.ai/en/docs/install
210
+
211
+ Minimum local tools:
212
+
213
+ - ZCode desktop app installed and connected to a model provider.
214
+ - Node.js `>=22`.
215
+ - Python `>=3.11`.
216
+ - Git.
217
+ - A POSIX-like shell such as the default macOS Terminal shell.
218
+ - Network access to the configured model provider.
219
+
220
+ Check the local basics:
221
+
222
+ ```bash
223
+ node --version
224
+ python3 --version
225
+ git --version
226
+ ```
227
+
228
+ ### 3. Run The Installer From Terminal
229
+
230
+ Run this in Terminal. You may run it from any current folder, because the
231
+ target repo is provided as an absolute path:
232
+
233
+ ```bash
234
+ zcode-install-repo /ABSOLUTE/PATH/TO/YOUR/TARGET_REPO
235
+ ```
236
+
237
+ Example:
238
+
239
+ ```bash
240
+ zcode-install-repo ~/work/my-app
241
+ ```
242
+
243
+ This command is setup only. Run it once per target repo; it is not a per-task
244
+ command.
245
+
246
+ If `zcode-install-repo` is not found, run the supervisor command directly from
247
+ this repo:
248
+
249
+ ```bash
250
+ python3 /absolute/path/to/ZCode-supervisor/tools/zcode_supervisor/zcode_supervisor.py install-repo \
251
+ --repo /ABSOLUTE/PATH/TO/YOUR/TARGET_REPO \
252
+ --write-agents
253
+ ```
254
+
255
+ If your supervisor repo lives somewhere else, replace
256
+ `/absolute/path/to/ZCode-supervisor` with the absolute path from `pwd` in step 1.
257
+
258
+ ### Primary Install Path
259
+
260
+ The current public setup path is `uvx` from this GitHub repo:
261
+
262
+ ```bash
263
+ uvx --from git+https://github.com/AkiGarage/ZCode-supervisor.git \
264
+ zcode-install-repo /ABSOLUTE/PATH/TO/YOUR/TARGET_REPO
265
+ ```
266
+
267
+ After the first PyPI release, the shorter package command will be:
268
+
269
+ ```bash
270
+ uvx --from zcode-supervisor zcode-install-repo /ABSOLUTE/PATH/TO/YOUR/TARGET_REPO
271
+ ```
272
+
273
+ The PyPI package is published through Trusted Publishing, without long-lived
274
+ PyPI tokens. High-assurance users can also download the GitHub Release archive,
275
+ verify `SHA256SUMS`, and run `gh attestation verify` before using it. Homebrew
276
+ is archived for now; see [docs/distribution.md](docs/distribution.md).
277
+
278
+ ### 4. Confirm What Was Written
279
+
280
+ The installer writes these files inside the target repo:
281
+
282
+ - `.codex/zcode-routing.json`
283
+ - `.codex/ZCODE_DELEGATION.md`
284
+ - `.agents/mcp.json`
285
+ - `AGENTS.md` pointer text, when `--write-agents` is used
286
+
287
+ The important rule is simple: Codex keeps planning, orchestration, validation,
288
+ audit, recovery, and final acceptance. ZCode only handles bounded
289
+ implementation through `zcodectl run-packet`.
290
+
291
+ ### 5. Check The Route Before Editing
292
+
293
+ Use a dry run before implementation work:
294
+
295
+ ```bash
296
+ zcode-auto-route \
297
+ --workspace /ABSOLUTE/PATH/TO/YOUR/TARGET_REPO \
298
+ --objective "Fix the failing ledger summary test."
299
+ ```
300
+
301
+ Typical results:
302
+
303
+ - `needs_codex_planning`: Codex should choose allowed files and validation.
304
+ - `delegate_zcode`: the task is ready to run through ZCode.
305
+ - `codex_direct`: Codex can handle it directly.
306
+ - `ask_user`: pause because the task is high risk.
307
+
308
+ ### 6. Run A Real Delegated Task
309
+
310
+ After Codex has chosen a tight edit scope and validation command:
311
+
312
+ ```bash
313
+ zcode-auto-route \
314
+ --workspace /ABSOLUTE/PATH/TO/YOUR/TARGET_REPO \
315
+ --objective "Fix the failing ledger summary test." \
316
+ --allowed src/ledger.js \
317
+ --validation "npm test" \
318
+ --execute
319
+ ```
320
+
321
+ Use `--allowed` for files ZCode may edit. Use `--validation` for the command
322
+ Codex will trust as the first safety check. Keep both narrow.
323
+
324
+ ### Troubleshooting The First Run
325
+
326
+ - `command not found: zcode-install-repo`: use the direct `python3 ... install-repo`
327
+ command shown above, or add this repo's `scripts/` directory to your PATH.
328
+ - `repo does not exist`: replace the placeholder with the exact absolute path
329
+ from `pwd`.
330
+ - ZCode cannot run prompts: open ZCode once, sign in, configure the provider,
331
+ then run `node tools/zcode_control/zcodectl.mjs cli-preflight` from this repo.
332
+ - Vision or screenshot tasks fail preflight: run
333
+ `node tools/zcode_control/zcodectl.mjs vision-preflight --workspace /ABSOLUTE/PATH/TO/YOUR/TARGET_REPO`.
334
+
335
+ ## Repository Snapshot
336
+
337
+ - **Current version:** `v0.0.1`
338
+ - **Primary use case:** delegate bounded coding tasks to ZCode/GLM while Codex
339
+ keeps planning, guardrails, validation, and final review.
340
+ - **Main command path:** `node tools/zcode_control/zcodectl.mjs run-packet`
341
+ - **Responsibility split:** isolate workspaces, snapshot before execution, audit
342
+ changes after execution, and reject unsafe or out-of-scope diffs.
343
+ - **Best for:** low-babysitting AI coding workflows, reproducible tool
344
+ comparisons, token/quota-aware delegation, and supervised benchmark runs.
345
+
346
+ ## Start Here
347
+
348
+ - New user? Read [Setup Guide](#setup-guide-set-up-one-target-repo), then
349
+ [How Codex And ZCode Share Responsibility](#how-codex-and-zcode-share-responsibility).
350
+ - Running ZCode headlessly? Read
351
+ [Requirements And Control Surfaces](#requirements-and-control-surfaces) and
352
+ [ZCode Desktop Control](#zcode-desktop-control).
353
+ - Comparing tools or tracking usage? Read
354
+ [Usage, Token, And Quota Logging](#usage-token-and-quota-logging).
355
+ - Planning future work? See [ROADMAP.md](ROADMAP.md) and
356
+ [CHANGELOG.md](CHANGELOG.md).
357
+
358
+ ## What This Provides
359
+
360
+ - `zcode_supervisor`: creates task packets, snapshots workspaces, and audits
361
+ ZCode changes after execution.
362
+ - `zcodectl`: CLI-first controller for the bundled ZCode headless CLI, with
363
+ optional Electron CDP helpers for desktop inspection.
364
+ - Workspace-local ZCode templates for `AGENTS.md`, quality gates, parallel
365
+ work, and Skill-friendly operating playbooks.
366
+ - Small benchmark fixtures and tests for the supervisor/audit workflow.
367
+ - A GLM-5.2/ZCode operating playbook for long-horizon coding, root-cause
368
+ analysis, production-grade standards checks, and token-efficient delegation.
369
+ - Optional repo-local Codex usage hook shim that records session starts/stops
370
+ through `codex-usage-ledger` when configured, with local pending JSONL
371
+ fallback when the central ledger is unavailable.
372
+
373
+ ## Version
374
+
375
+ Current release: `v0.0.1`
376
+
377
+ Distribution and release preparation: [docs/distribution.md](docs/distribution.md)
378
+
379
+ ## How Codex And ZCode Share Responsibility
380
+
381
+ This project is built around a simple responsibility split:
382
+
383
+ - Codex decides the plan, allowed files, validation command, audit result, and
384
+ final acceptance.
385
+ - ZCode does only the bounded implementation work Codex explicitly delegates.
386
+
387
+ The intended workflow is:
388
+
389
+ 1. Codex creates a compact task packet.
390
+ 2. Codex snapshots the workspace.
391
+ 3. ZCode works inside an isolated workspace or worktree.
392
+ 4. Codex runs the supervisor audit.
393
+ 5. Codex independently reviews and accepts or rejects the result.
394
+
395
+ `Full access` should only be used in disposable workspaces or isolated
396
+ worktrees. Packet creation blocks regular-workspace `Full access` by default
397
+ and rejects obviously destructive validation commands. The supervisor audit
398
+ rejects forbidden edits, changes outside the allowed file set, optional changed
399
+ file count overages, validation failures, workspace mismatches, and secret-like
400
+ content in changed files.
401
+
402
+ ## Command Reference After Setup
403
+
404
+ The examples in this section use shorter placeholder paths. Replace every
405
+ `/path/to/target-repo` or `/path/to/repo` with the absolute path to your real
406
+ target repo, just like in the Setup Guide above.
407
+
408
+ Install repo-local routing hints in a target repository:
409
+
410
+ ```bash
411
+ zcode-install-repo /path/to/target-repo
412
+ ```
413
+
414
+ Run this once per target repo. It is setup, not a per-task command.
415
+
416
+ This writes `.codex/zcode-routing.json`, `.codex/ZCODE_DELEGATION.md`, and
417
+ `.agents/mcp.json` in the target repo. It also adds a small `AGENTS.md` pointer
418
+ so Codex knows the default split: Codex plans, orchestrates, audits, validates,
419
+ and final-accepts; ZCode handles only bounded implementation through
420
+ `zcodectl run-packet`. The MCP file enables the recommended `zai-mcp-server`
421
+ stdio entry for vision packets without writing API keys into the repository.
422
+ Re-run with `--force` only when you intentionally want to refresh generated
423
+ files or replace an existing `zai-mcp-server` entry.
424
+
425
+ If the PATH wrapper is unavailable, use the underlying command:
426
+
427
+ ```bash
428
+ python3 /path/to/ZCode-supervisor/tools/zcode_supervisor/zcode_supervisor.py install-repo \
429
+ --repo /path/to/target-repo \
430
+ --write-agents
431
+ ```
432
+
433
+ ## Auto Routing
434
+
435
+ Installed repos default to `routing_mode: auto`. Future Codex sessions should
436
+ run the route check before implementation edits:
437
+
438
+ ```bash
439
+ zcode-auto-route \
440
+ --workspace /path/to/target-repo \
441
+ --objective "Fix the failing ledger summary test."
442
+ ```
443
+
444
+ This check is optional when you already know the task should run through ZCode;
445
+ it is mainly a dry-run for inspecting the route decision. You do not need to run
446
+ all three setup/check/execute commands for every task:
447
+
448
+ - First-time setup: run `zcode-install-repo /path/to/target-repo` once.
449
+ - Route inspection: run `zcode-auto-route --workspace ... --objective ...`
450
+ when you want to see the JSON decision.
451
+ - Real delegated implementation: run `zcode-auto-route ... --allowed ...
452
+ --validation ... --execute` after Codex has selected the file scope and
453
+ validation command.
454
+
455
+ If the user explicitly says "use ZCode", "have ZCode do it", or similar, Codex should
456
+ treat that as an instruction to use this ZCode-supervisor flow for bounded
457
+ implementation work. Codex still owns planning, orchestration, validation,
458
+ audit, recovery, and final acceptance.
459
+
460
+ The router returns JSON so Codex can proceed without asking for routine
461
+ decisions:
462
+
463
+ - `delegate_zcode`: create a packet and run ZCode.
464
+ - `needs_codex_planning`: Codex must choose a tight allowed-file set and
465
+ validation command, then rerun with `--execute`.
466
+ - `codex_direct`: Codex may handle the task directly because it is read-only,
467
+ trivial, missing routing config, or explicitly marked `no-zcode`.
468
+ - `ask_user`: pause for a short plan because the task matches a high-risk
469
+ category such as destructive changes, migrations, credentials, production, or
470
+ money-sensitive work.
471
+
472
+ For normal implementation after Codex has selected allowed files and validation:
473
+
474
+ ```bash
475
+ zcode-auto-route \
476
+ --workspace /path/to/target-repo \
477
+ --objective "Fix the failing ledger summary test." \
478
+ --allowed src/ledger.js \
479
+ --validation "npm test" \
480
+ --execute
481
+ ```
482
+
483
+ `--execute` creates the packet, calls `zcodectl run-packet`, writes run results
484
+ under `.codex/zcode/runs/`, and keeps Codex responsible for final acceptance.
485
+ This is intentionally a smart default rather than a hard lock: high-risk,
486
+ read-only, trivial, and `no-zcode` tasks do not get forced through ZCode.
487
+
488
+ Create a task packet:
489
+
490
+ ```bash
491
+ python3 tools/zcode_supervisor/zcode_supervisor.py packet \
492
+ --workspace benchmarks/zcode-goal-mode \
493
+ --objective "Fix summarizeLedger so npm test passes." \
494
+ --allowed src/ledger.js \
495
+ --forbidden test/ledger.test.js \
496
+ --validation "npm test" \
497
+ --effort max \
498
+ --task-class root-cause \
499
+ --risk-budget low \
500
+ --max-changed-files 1 \
501
+ --goal \
502
+ --out .local/packets/ledger.json \
503
+ --prompt-out .local/packets/ledger.prompt.txt
504
+ ```
505
+
506
+ Snapshot the workspace:
507
+
508
+ ```bash
509
+ python3 tools/zcode_supervisor/zcode_supervisor.py snapshot \
510
+ --workspace benchmarks/zcode-goal-mode \
511
+ --out .local/snapshots/ledger.before.json
512
+ ```
513
+
514
+ After ZCode runs, audit the result:
515
+
516
+ ```bash
517
+ python3 tools/zcode_supervisor/zcode_supervisor.py audit \
518
+ --workspace benchmarks/zcode-goal-mode \
519
+ --snapshot .local/snapshots/ledger.before.json \
520
+ --packet .local/packets/ledger.json
521
+ ```
522
+
523
+ ## Requirements And Control Surfaces
524
+
525
+ This toolkit does not require Codex Computer Use. The preferred automation path
526
+ is the ZCode headless CLI bundled inside the ZCode desktop app:
527
+
528
+ ```text
529
+ Codex or a normal terminal
530
+ -> node tools/zcode_control/zcodectl.mjs
531
+ -> ZCode bundled CLI
532
+ -> ZCode / GLM task execution
533
+ ```
534
+
535
+ Control surface priority:
536
+
537
+ 1. **ZCode bundled headless CLI, recommended and required for headless
538
+ delegation.** `cli-prompt` and `run-packet` use this path. It is the path
539
+ validated by this project on macOS with ZCode 3.1.2.
540
+ 2. **`cua-driver` plus Electron CDP, optional.** `cua-driver` is an MIT-licensed
541
+ background computer-use driver from the Cua project:
542
+ https://cua.ai/docs/cua-driver/guide/getting-started/introduction
543
+ When available, GUI helpers can use this kind of desktop-control surface to
544
+ inspect visible text, take screenshots, click buttons, and read visible
545
+ Usage Stats without making it the primary delegation path. Thanks to the Cua
546
+ authors for the computer-use driver work; this project uses that capability
547
+ only as an optional diagnostic/control surface.
548
+ 3. **Codex Computer Use, optional fallback only.** It can operate the GUI when
549
+ available, but this repository does not depend on it and does not require it
550
+ for the primary workflow.
551
+
552
+ Minimum local tooling:
553
+
554
+ - ZCode desktop app installed and connected to a model provider.
555
+ - Node.js `>=22`.
556
+ - Python `>=3.11`.
557
+ - Git and a POSIX-like shell for `scripts/check.sh`.
558
+ - Network access to the configured model provider.
559
+
560
+ The latest official ZCode install docs list these supported platforms:
561
+
562
+ - macOS on Apple Silicon and Intel.
563
+ - Windows.
564
+ - Linux through the Linux beta group.
565
+
566
+ See the official ZCode install docs:
567
+ https://zcode.z.ai/en/docs/install
568
+
569
+ Project support status:
570
+
571
+ | Platform | Status | Notes |
572
+ | --- | --- | --- |
573
+ | macOS | Tested | ZCode 3.1.2, bundled CLI path `/Applications/ZCode.app/Contents/Resources/glm/zcode.cjs`, bundled CLI version `0.14.8`, GUI config path `~/.zcode/v2/config.json`, CLI config path `~/.zcode/cli/config.json`. |
574
+ | Windows | Expected, not verified | ZCode is officially supported and 3.1.2 adds Windows shell selection, but this project still needs Windows-specific CLI path discovery and shell validation. Set `ZCODE_CLI_PATH` if auto-detection does not find the bundled CLI. |
575
+ | Linux | Expected/beta, not verified | ZCode Linux packages are distributed through the official beta group, but this project has not validated Linux CLI paths, desktop launch, or config discovery yet. Set `ZCODE_CLI_PATH`, `--source-config`, and `--cli-config` as needed. |
576
+
577
+ `bootstrap-cli-config` can copy a local ZCode GUI Coding Plan API key into the
578
+ ZCode CLI config with `0600` permissions and redacted output. On non-macOS
579
+ systems, pass explicit config paths if the defaults do not match the installed
580
+ ZCode layout:
581
+
582
+ ```bash
583
+ node tools/zcode_control/zcodectl.mjs bootstrap-cli-config \
584
+ --provider zai \
585
+ --model glm-5.2 \
586
+ --source-config /path/to/gui/config.json \
587
+ --cli-config /path/to/cli/config.json
588
+ ```
589
+
590
+ ## ZCode Desktop Control
591
+
592
+ `zcodectl` is intentionally small and experimental. Its primary path is the
593
+ bundled ZCode headless CLI. Its GUI helpers expect ZCode to be available as a
594
+ desktop app and use Electron CDP after launch.
595
+
596
+ For ZCode 3.1.2 and later, prefer the bundled headless CLI when it is available:
597
+
598
+ ```bash
599
+ node tools/zcode_control/zcodectl.mjs cli-path
600
+ node tools/zcode_control/zcodectl.mjs cli-preflight
601
+ node tools/zcode_control/zcodectl.mjs bootstrap-cli-config \
602
+ --provider zai \
603
+ --model glm-5.2
604
+ node tools/zcode_control/zcodectl.mjs cli-doctor
605
+ node tools/zcode_control/zcodectl.mjs run-packet \
606
+ --packet .local/packets/ledger.json \
607
+ --mode plan \
608
+ --max-attempts 2 \
609
+ --retry-delay-ms 60000 \
610
+ --usage-snapshot-source auto \
611
+ --out .local/runs/ledger.zcode.json
612
+ ```
613
+
614
+ `run-packet` sends the supervisor-generated packet prompt to the bundled
615
+ ZCode CLI with the packet workspace as `--cwd`. It avoids GUI/CDP fragility and
616
+ is the preferred Codex control path for headless delegation. If the CLI config
617
+ is not ready, `cli-prompt` and `run-packet` try to bootstrap it from the local
618
+ ZCode desktop GUI config before sending the prompt. Pass `--no-bootstrap` to
619
+ disable that behavior. Use `cli-prompt` for ad-hoc prompts:
620
+
621
+ `run-packet` treats ZCode provider overload as structured supervisor state. It
622
+ classifies `ProviderBusinessError`, provider code `1305`, temporary overload
623
+ messages, and CLI exit code `143`. Every attempt is audited by the Codex-side
624
+ supervisor after the ZCode turn, so validation does not depend on ZCode's
625
+ internal Bash/tool permission client. The result returns `supervisor_state`:
626
+
627
+ - `success`: CLI completed normally and supervisor audit plus validation passed.
628
+ - `audit_failed`: CLI completed normally, but supervisor audit or validation
629
+ failed.
630
+ - `partial_success`: provider error happened after scoped changes, and audit
631
+ plus validation passed.
632
+ - `retryable_provider_error`: provider error happened with no file changes.
633
+ - `unsafe_partial`: provider error happened with changed files that failed
634
+ scope, validation, or safety checks.
635
+
636
+ Safe no-change provider errors retry up to `--max-attempts` with
637
+ `--retry-delay-ms` cooldown. Changed files are never blindly retried; they are
638
+ audited first. The JSON result includes `cli_ok`, `provider_error`,
639
+ `provider_code`, `provider_message`, `provider_id`, `provider_kind`,
640
+ `usage_available`, `attempts`, `retry_count`, `retry_delays_ms`,
641
+ `safe_to_retry_later`, `partial_artifacts_possible`, `audit`, `validation`,
642
+ `validation_ok`, and compact `attempt_results`.
643
+
644
+ `run-packet` also captures before/after usage snapshots. The default
645
+ `--usage-snapshot-source auto` first calls the Z.AI quota API directly using
646
+ `ZAI_API_KEY`, `launchctl getenv ZAI_API_KEY`, or the local redacted ZCode CLI
647
+ config as the credential source. The API key is never written to result JSON or
648
+ logs. If the direct API snapshot is unavailable, `auto` falls back to the
649
+ CodexBar CLI:
650
+
651
+ ```bash
652
+ codexbar usage --provider zai --format json
653
+ ```
654
+
655
+ CodexBar.app does not need to be running for either path. The snapshot is
656
+ non-fatal: if both direct API and CodexBar CLI capture are missing or
657
+ unavailable, task execution continues and the JSON records the snapshot error.
658
+ When capture succeeds, the JSON includes:
659
+
660
+ - `usage_snapshots.before` and `usage_snapshots.after`: raw provider snapshots
661
+ plus normalized quota windows. Direct Z.AI API snapshots use `source:
662
+ "zai-api"`; CodexBar snapshots use `source: "codexbar"`.
663
+ - `usage_accounting.tokens_*`: consumed token fields normalized from the ZCode
664
+ CLI JSON `usage` payload for this run.
665
+ - `usage_accounting.quota_percent_*`: before, after, and delta for the primary
666
+ used-percent quota window. `quota_percent_direction` is `used`.
667
+ - Direct Z.AI `TOKENS_LIMIT.percentage` is treated as the measured used-percent
668
+ value even when the same window omits finite `usage` and `remaining` token
669
+ counts. The normalized window records `token_counts_available` separately, so
670
+ percent deltas remain available without inventing token-count deltas.
671
+ - `usage_accounting.quota_windows`: per-window deltas, including reset-change
672
+ detection so a quota-window reset is not misreported as negative usage.
673
+
674
+ Use `--usage-snapshot-source zai-api` to require direct Z.AI API capture,
675
+ `--usage-snapshot-source codexbar` to require CodexBar CLI capture, or
676
+ `--usage-snapshot-source none` to disable snapshot capture. Use
677
+ `--usage-provider zai` to make the provider explicit. `--zai-quota-url` can
678
+ point at a custom Z.AI-compatible quota endpoint for tests. `--codexbar-path`
679
+ or the `CODEXBAR_PATH` environment variable can point at a custom CodexBar CLI
680
+ path.
681
+
682
+ ```bash
683
+ node tools/zcode_control/zcodectl.mjs cli-prompt \
684
+ --workspace benchmarks/zcode-goal-mode \
685
+ --mode plan \
686
+ --text "Review this fixture and report the failing test cause." \
687
+ --out .local/runs/review.json
688
+ ```
689
+
690
+ `bootstrap-cli-config` reads the local ZCode GUI config, finds an existing
691
+ Coding Plan API key, and writes the CLI-native config at
692
+ `~/.zcode/cli/config.json` with `0600` permissions. Secret values are copied
693
+ locally and are not printed in command output. The default provider is `zai`
694
+ and the default model is `glm-5.2`.
695
+
696
+ `cli-preflight` checks the CLI binary, model selection, and whether a Coding
697
+ Plan API key is configured. It redacts secret values and reports
698
+ `prompt_ready=true` when headless prompts can run.
699
+
700
+ ## Image And Vision Tasks
701
+
702
+ GLM-5.2 is treated as text-only in this supervisor. For image understanding,
703
+ use ZCode's built-in image service through the recommended `zai-mcp-server`
704
+ MCP service, then attach workspace-local images through the packet:
705
+
706
+ ```bash
707
+ python3 tools/zcode_supervisor/zcode_supervisor.py packet \
708
+ --workspace benchmarks/zcode-goal-mode \
709
+ --objective "Implement the UI state shown in the screenshot." \
710
+ --allowed src/ledger.js \
711
+ --validation "npm test" \
712
+ --vision-image screenshots/state.png \
713
+ --vision-color-sample primary=screenshots/state.png@240,420 \
714
+ --out .local/packets/vision.json
715
+ ```
716
+
717
+ `--vision-image` marks image understanding as required and stores the image
718
+ paths in the packet. `run-packet` automatically forwards those paths to the
719
+ ZCode CLI as repeated `--attach` arguments. Before running a required vision
720
+ packet, `run-packet` checks redacted ZCode MCP configuration for the preferred
721
+ image service and stops with `vision_service_unavailable` if it is missing,
722
+ instead of letting the worker guess from filenames or text.
723
+
724
+ Use `--vision-color-sample name=image.png@x,y` when a task needs pixel-exact
725
+ hex colors. The supervisor reads that PNG pixel locally and injects the exact
726
+ uppercase `#RRGGBB` value into the worker prompt, while ZCode still handles the
727
+ broader image understanding. The sampler is intentionally narrow: workspace
728
+ local, non-secret, non-interlaced 8-bit RGB/RGBA PNG files.
729
+
730
+ You can check the image-service setup directly:
731
+
732
+ ```bash
733
+ node tools/zcode_control/zcodectl.mjs vision-preflight \
734
+ --workspace benchmarks/zcode-goal-mode
735
+ ```
736
+
737
+ `zcode-install-repo /path/to/repo` writes `.agents/mcp.json` with the
738
+ recommended stdio server:
739
+
740
+ ```json
741
+ {
742
+ "mcpServers": {
743
+ "zai-mcp-server": {
744
+ "args": ["-y", "@z_ai/mcp-server"],
745
+ "command": "npx",
746
+ "enable": true,
747
+ "type": "stdio"
748
+ }
749
+ }
750
+ }
751
+ ```
752
+
753
+ The relevant ZCode docs describe `zai-mcp-server` as the recommended MCP server
754
+ for visual understanding of images, screenshots, and interface context:
755
+ https://zcode.z.ai/en/docs/mcp-services
756
+
757
+ The npm package that provides the `zai-mcp-server` binary is
758
+ `@z_ai/mcp-server`. It expects `Z_AI_API_KEY`; for required vision packets,
759
+ `run-packet` passes an available key to the ZCode child process from the current
760
+ environment, `ZAI_API_KEY`, or the local ZCode CLI config without printing the
761
+ secret value. Pixel-exact color sampling should still be verified with a
762
+ deterministic image tool when exact hex values matter; generic vision can be
763
+ close but not always exact.
764
+
765
+ The GUI/CDP helpers remain available for inspecting the desktop app and reading
766
+ visible Settings usage when CDP is exposed:
767
+
768
+ Example:
769
+
770
+ ```bash
771
+ node tools/zcode_control/zcodectl.mjs launch --port 9223
772
+ node tools/zcode_control/zcodectl.mjs targets --port 9223
773
+ node tools/zcode_control/zcodectl.mjs goal --port 9223 --text-file .local/packets/ledger.prompt.txt
774
+ ```
775
+
776
+ If ZCode is already running without a debug port, use
777
+ `node tools/zcode_control/zcodectl.mjs launch --port 9223 --new-instance` and
778
+ check that the launch output includes `"cdp": {"ok": true, ...}` before running
779
+ `targets`, `usage`, or `goal`.
780
+
781
+ Do not send secrets through `zcodectl eval` or prompt files.
782
+
783
+ ## Usage, Token, And Quota Logging
784
+
785
+ For every delegated ZCode task, capture Usage Stats before and after the run,
786
+ then append the result to the evaluation ledger.
787
+
788
+ The current ZCode Usage Stats docs split usage into App Usage for local session
789
+ records and Coding Plan for remote Z.ai / BigModel quota, GLM-5.2 and
790
+ GLM-5-Turbo model usage, and MCP tool-call usage. Treat quota snapshots as
791
+ time-sensitive evidence and keep the raw snapshot beside the normalized eval
792
+ record.
793
+
794
+ ```bash
795
+ node tools/zcode_control/zcodectl.mjs open-usage --port 9223
796
+ node tools/zcode_control/zcodectl.mjs usage --port 9223 --out .local/usage/ledger.before.json
797
+
798
+ # Run the ZCode task.
799
+
800
+ node tools/zcode_control/zcodectl.mjs open-usage --port 9223
801
+ node tools/zcode_control/zcodectl.mjs usage --port 9223 --out .local/usage/ledger.after.json
802
+
803
+ python3 tools/zcode_eval/zcode_eval.py append-result \
804
+ --run-id zcode-ledger-001 \
805
+ --tool zcode \
806
+ --task-id ledger \
807
+ --task-name "Ledger fixture" \
808
+ --status pass \
809
+ --validation "npm test: pass" \
810
+ --usage-before .local/usage/ledger.before.json \
811
+ --usage-after .local/usage/ledger.after.json
812
+ ```
813
+
814
+ `append-result` records `tokens_before`, `tokens_after`, `tokens_used`,
815
+ `quota_percent_before`, `quota_percent_after`, and `quota_percent_used`. By
816
+ default, quota percent is treated as remaining quota, so consumed quota is
817
+ derived as before minus after. If the visible UI is a used-percent counter, pass
818
+ `--quota-percent-direction used`.
819
+
820
+ When recording a provider-error run, `append-result` also accepts optional
821
+ metadata: `--supervisor-state`, `--provider-error`, `--provider-code`,
822
+ `--provider-message`, `--provider-id`, `--provider-kind`, `--attempts`,
823
+ `--retry-count`, `--retryable-provider-error`,
824
+ `--partial-artifacts-possible`, `--safe-to-retry-later`, and
825
+ `--usage-available` / `--no-usage-available`.
826
+
827
+ If ZCode does not expose CDP in the current session, you can still record the
828
+ same fields explicitly:
829
+
830
+ ```bash
831
+ python3 tools/zcode_eval/zcode_eval.py append-result \
832
+ --run-id zcode-ledger-001 \
833
+ --tool zcode \
834
+ --task-id ledger \
835
+ --task-name "Ledger fixture" \
836
+ --status pass \
837
+ --tokens-before 1000 \
838
+ --tokens-after 1450 \
839
+ --quota-percent-before 88.5 \
840
+ --quota-percent-after 87.0
841
+ ```
842
+
843
+ Review logs later with:
844
+
845
+ ```bash
846
+ python3 tools/zcode_eval/zcode_eval.py show-log
847
+ python3 tools/zcode_eval/zcode_eval.py summarize
848
+ ```
849
+
850
+ External duel runs can be imported into the same JSONL ledger. The importer
851
+ reads `results.json` plus adjacent `_control/zcode/*/zcode-result.json` files
852
+ when available, so provider overload rows keep `provider_code`, retryability,
853
+ partial-artifact status, usage availability, and quota unavailable reasons:
854
+
855
+ ```bash
856
+ python3 tools/zcode_eval/zcode_eval.py import-duel-results \
857
+ --source /path/to/ClaudeCodeGLM-supervisor/work/supervisor_duel_eval/runs/20260617-153042/results.json \
858
+ --path artifacts/evals/zcode-vs-claude.jsonl
859
+ ```
860
+
861
+ ## ZCode Release Monitoring
862
+
863
+ ZCode compatibility is pinned against `config/zcode-release-baseline.json`.
864
+ Check the official changelog manually with:
865
+
866
+ ```bash
867
+ python3 tools/zcode_eval/zcode_release.py check \
868
+ --baseline config/zcode-release-baseline.json \
869
+ --include-installed
870
+ ```
871
+
872
+ The GitHub Actions workflow `.github/workflows/zcode-release-monitor.yml` runs
873
+ the same release check on a schedule. When the official ZCode version is newer
874
+ than the baseline, it runs `bash scripts/check.sh` and opens or updates a GitHub
875
+ Issue with the release notes and follow-up checklist.
876
+
877
+ ## Templates
878
+
879
+ Copy `templates/zcode-codex-system/` into a disposable workspace or worktree to
880
+ give ZCode:
881
+
882
+ - a bounded worker contract via `AGENTS.md`
883
+ - Skill-friendly playbooks and a quality gate
884
+ - a parallel-work playbook
885
+ - a GLM-5.2 operating profile for choosing task class, effort, and context
886
+ strategy
887
+
888
+ Current ZCode docs say user-defined custom subagents are not supported yet.
889
+ Use the built-in read-only Explore subagent for broad code research, and use
890
+ Skills or Commands for reusable worker behavior. The legacy
891
+ `.zcode/cli/agents/` template files are retained only as draft role prompts,
892
+ not as an advertised ZCode runtime feature.
893
+
894
+ ## GLM-5.2 Operating Defaults
895
+
896
+ - Use `effort=max` for long-horizon implementation, cross-module debugging,
897
+ architecture mapping, production-grade standards checks, and mobile/debugging
898
+ loops.
899
+ - Use `effort=high` for cheap probes, narrow reviews, and small repairs where
900
+ speed matters more than deep search.
901
+ - Treat 1M context as durable architectural memory, not a reason to dump every
902
+ file into every task.
903
+ - Use `/goal` only with objective acceptance criteria and an exact validation
904
+ command.
905
+ - Use `--max-changed-files` when the expected diff is small, so broad edits fail
906
+ the audit automatically.
907
+ - Use `--workspace-kind fixture|worktree|disposable` before `Full Access`;
908
+ regular workspaces are blocked by default.
909
+ - Keep Codex as final auditor even when ZCode completes the task.
910
+
911
+ See the GLM-5.2 ZCode Operator Guide:
912
+ [English](docs/glm-5.2-zcode-operator-guide.md) /
913
+ [日本語](docs/glm-5.2-zcode-operator-guide.ja.md).
914
+
915
+ ## Development
916
+
917
+ Run the full local check:
918
+
919
+ ```bash
920
+ bash scripts/check.sh
921
+ ```
922
+
923
+ The project uses only the Python and Node standard libraries for its core
924
+ checks.
925
+
926
+ ## Roadmap
927
+
928
+ See [ROADMAP.md](ROADMAP.md) for planned benchmark work.