zcode-agent 1.3.1 → 1.4.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/lib/workspace.js CHANGED
@@ -40,6 +40,22 @@ function workspaceRoot(cwd) {
40
40
  return top ? fs.realpathSync(top) : real;
41
41
  }
42
42
 
43
+ // `abs` with its longest existing prefix resolved through symlinks (the
44
+ // rest, e.g. a glob or a file not created yet, is kept as written).
45
+ function realPrefix(abs) {
46
+ const tail = [];
47
+ for (let head = abs; ; ) {
48
+ try {
49
+ return path.join(fs.realpathSync(head), ...tail);
50
+ } catch {
51
+ const up = path.dirname(head);
52
+ if (up === head) return abs;
53
+ tail.unshift(path.basename(head));
54
+ head = up;
55
+ }
56
+ }
57
+ }
58
+
43
59
  // Ownership patterns arrive relative to --cwd; store them relative to the
44
60
  // workspace root, posix-style, so every session compares like with like.
45
61
  function normalizeOwns(patterns, cwd, root, flag = '--owns') {
@@ -47,7 +63,9 @@ function normalizeOwns(patterns, cwd, root, flag = '--owns') {
47
63
  return patterns.map((raw) => {
48
64
  const pattern = String(raw).trim();
49
65
  if (!pattern) throw new OwnershipError(`${flag} pattern must not be empty`);
50
- const abs = path.isAbsolute(pattern) ? pattern : path.join(realCwd, pattern);
66
+ // An absolute pattern may come through a symlinked path ("$PWD/src");
67
+ // the root is a real path.
68
+ const abs = path.isAbsolute(pattern) ? realPrefix(pattern) : path.join(realCwd, pattern);
51
69
  const rel = toPosix(path.relative(root, abs));
52
70
  if (rel === '' || rel === '.') return '**';
53
71
  if (rel.startsWith('../') || rel === '..' || path.isAbsolute(rel)) {
@@ -79,13 +97,16 @@ function globToRegExp(glob) {
79
97
  re += c.replace(/[.+^${}()|[\]\\]/g, '\\$&');
80
98
  }
81
99
  }
82
- return new RegExp(`^${re}$`);
100
+ // A match owns what lies beneath it, as a plain path does ("packages/*"
101
+ // owns packages/a/src/x.ts).
102
+ return new RegExp(`^${re}(?:/.*)?$`);
83
103
  }
84
104
 
85
105
  const hasWildcard = (p) => /[*?]/.test(p);
86
106
 
87
- // A plain path owns itself and everything beneath it; a glob owns its
88
- // matches. Empty ownership = the whole workspace.
107
+ // A plain path owns itself and everything beneath it; so does each match of
108
+ // a glob (*, **, ?; braces and brackets are literal, as in "app/[id]").
109
+ // Empty ownership = the whole workspace.
89
110
  function isOwned(relPath, owns) {
90
111
  if (!owns || owns.length === 0) return true;
91
112
  return owns.some((pattern) => {
@@ -204,7 +225,10 @@ const HASH_LIMIT = 8 * 1024 * 1024;
204
225
 
205
226
  function fileSignature(abs) {
206
227
  try {
207
- const st = fs.statSync(abs);
228
+ // lstat: a symlink is the link itself (git's view), not whatever changes
229
+ // inside the directory it points at.
230
+ const st = fs.lstatSync(abs);
231
+ if (st.isSymbolicLink()) return `link:${fs.readlinkSync(abs)}`;
208
232
  if (!st.isFile()) return `other:${st.mtimeMs}`;
209
233
  if (st.size > HASH_LIMIT) return `big:${st.size}:${st.mtimeMs}`;
210
234
  return crypto.createHash('sha1').update(fs.readFileSync(abs)).digest('hex');
@@ -218,7 +242,9 @@ function fileSignature(abs) {
218
242
  function gitStatus(root) {
219
243
  const raw = execFileSync(
220
244
  'git',
221
- ['-C', root, 'status', '--porcelain=v1', '-z', '--untracked-files=all'],
245
+ // --no-optional-locks: a snapshot must never hold index.lock against a
246
+ // `git add` the executor, a parallel session or the user runs meanwhile.
247
+ ['--no-optional-locks', '-C', root, 'status', '--porcelain=v1', '-z', '--untracked-files=all'],
222
248
  { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 15000, maxBuffer: 64 * 1024 * 1024 }
223
249
  );
224
250
  const fields = raw.split('\0');
@@ -324,6 +350,8 @@ function diffSnapshots(before, after) {
324
350
  } else if (a) {
325
351
  if (a.code.includes('D') || a.sig === 'missing') change = 'deleted';
326
352
  else if (!b && (a.code === '??' || a.code[0] === 'A')) change = 'added';
353
+ } else if (b && b.code === '??') {
354
+ change = 'deleted'; // an untracked file that is gone, not one that went back to clean
327
355
  }
328
356
  out.push({ path: rel, change });
329
357
  }
@@ -371,7 +399,6 @@ module.exports = {
371
399
  OwnershipError,
372
400
  workspaceRoot,
373
401
  normalizeOwns,
374
- globToRegExp,
375
402
  isOwned,
376
403
  isZcodePath,
377
404
  ownsOverlap,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zcode-agent",
3
- "version": "1.3.1",
4
- "description": "Cheap, verified execution for Claude Code and Codex: your orchestrator decides, GLM-5.3 builds and tests, and a GLM-5.3-Flash verifier checks the screenshots in headless ZCode sessions (parallel sessions, subagents, dependency plans) and hands back a compact result. Also an ACP agent for T3 Code, Zed and any Agent Client Protocol client. Uses your ZCode app's key, MCP servers and skills, or runs standalone.",
3
+ "version": "1.4.0",
4
+ "description": "Cheap, verified execution for Claude Code and Codex: your orchestrator decides, GLM-5.4 builds and tests, and a GLM-5.3-Flash verifier checks the screenshots in headless ZCode sessions (parallel sessions, subagents, dependency plans) and hands back a compact result. Also an ACP agent for T3 Code, Zed and any Agent Client Protocol client. Uses your ZCode app's key, MCP servers and skills, or runs standalone.",
5
5
  "license": "MIT",
6
6
  "bin": {
7
7
  "zcode-agent": "bin/zcode-agent.js",
@@ -25,12 +25,14 @@
25
25
  "test": "node --test --test-concurrency=1 \"test/unit/*.test.js\"",
26
26
  "test:live": "node --test --test-concurrency=1 \"test/live/*.test.js\"",
27
27
  "prepack": "node ../../scripts/sync-package-docs.mjs",
28
+ "accept:54": "node scripts/accept.js glm54",
28
29
  "accept:flash": "node scripts/accept.js flash",
29
30
  "accept:subagent": "node scripts/accept.js subagent",
30
31
  "accept:53": "node scripts/accept.js glm53"
31
32
  },
32
33
  "keywords": [
33
34
  "glm",
35
+ "glm-5.4",
34
36
  "glm-5.3",
35
37
  "zai",
36
38
  "zcode",
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  name: zcode-agent
3
- description: Delegate scoped implementation work to the zcode-agent CLI (cheap GLM-5.3 executor with Playwright; an independent GLM-5.3-Flash 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.
3
+ description: Delegate scoped implementation work to the zcode-agent CLI (cheap GLM-5.4 executor with Playwright; an independent GLM-5.3-Flash 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
4
  ---
5
5
 
6
6
  # Operating zcode-agent as an executor
7
7
 
8
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
9
 
10
- **The point is cost.** Your tokens are the expensive ones; GLM-5.3'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.
10
+ **The point is cost.** Your tokens are the expensive ones; GLM'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
11
 
12
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
13
 
@@ -77,11 +77,11 @@ Parallel sessions cost you nothing extra while they run: one background `wait` o
77
77
  | files | `--file path` | files to read first (don't also pass them as `--context @`) |
78
78
  | context | `--context "…"` / `--context @file` | background that isn't a decision |
79
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 |
80
+ | everything | `--task contract.json` | keys: objective, scope, constraints, decisions, design, acceptance, checks, visual, viewports, units, serve, files, references, context, owns, touch, limits, model, effort |
81
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.
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`, plus the Playwright browser (`--no-browser` drops that). Leave the default unless a run needs to be reproducible on another machine.
83
83
 
84
- Model and effort: don't pass `--model` or `--effort`. Everything runs on GLM-5.3 at effort `high` by default: sessions, units and plans. The visual verifier always runs on GLM-5.3-Flash, because only Flash can see images. Use `--model flash` when the user asks for it, or when the executor itself should look at screenshots or attached images (GLM-5.3 can't); it is cheaper and faster too. `--effort low|high|max`. Other values are refused before anything starts.
84
+ Model and effort: don't pass `--model` or `--effort`. Everything runs on GLM-5.4 at effort `high` by default: sessions, units and plans; it can look at screenshots and attached images itself. The independent visual verifier runs on GLM-5.3-Flash, the cheapest model that sees images. Use `--model flash` when the user asks for it (cheaper and faster), and `--model glm-5.3` only when asked. `--effort low|high|max`. Other values are refused before anything starts.
85
85
 
86
86
  ## Running
87
87
 
@@ -90,7 +90,7 @@ zcode-agent task --detach --id <id> --cwd <repo> [flags] "<objective>" # print
90
90
  zcode-agent wait <id…> --timeout-ms 7000000 --json --quiet # in the background; 124 = still running: wait again
91
91
  zcode-agent wait <id…> --any --timeout-ms 7000000 --json --quiet # return on the first that finishes
92
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
93
+ zcode-agent result <id> --json [--full] # brief again, or the full record
94
94
  zcode-agent cancel <id>
95
95
  ```
96
96
 
@@ -98,9 +98,10 @@ Plans:
98
98
 
99
99
  ```sh
100
100
  zcode-agent plan check plan.json
101
- zcode-agent plan run plan.json --detach [--preflight]
102
- zcode-agent plan wait <name> --timeout-ms 7000000 --json # in the background; one line per session, details only for non-completed
103
- zcode-agent plan resume <name> ["<message>"] # resume failed/partial, relaunch skipped
101
+ zcode-agent plan run plan.json --detach
102
+ zcode-agent plan run plan.json --preflight # foreground; prints only the questions
103
+ zcode-agent plan wait <name> --timeout-ms 7000000 --json # in the background; one summary line, briefs only for non-completed sessions
104
+ zcode-agent plan resume <name> ["<message>"] # resume every non-completed session, relaunch skipped
104
105
  zcode-agent plan resume <name> --session <id> "<answer>" # answer one blocked session
105
106
  ```
106
107
 
@@ -122,7 +123,7 @@ Wait once, in the background: run `zcode-agent plan wait <name> --timeout-ms 700
122
123
  | `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
124
  | `partial` | 8 | read `issues` / `unresolved` / unmet `visual` / `scopeViolations`; resume with one-line guidance or re-scope |
124
125
  | `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
+ | `unverified` | 9 | nothing confirmed it: no checks ran, or the executor gave no usable "done" report. Resume with a check added |
126
127
  | `cancelled` | 130 | resume if wanted |
127
128
 
128
129
  ## Hard rules after dispatch
@@ -130,7 +131,7 @@ Wait once, in the background: run `zcode-agent plan wait <name> --timeout-ms 700
130
131
  - Don't open files a `completed` session changed. Don't re-run checks it ran. Don't look at its screenshots.
131
132
  - Don't poll `status`; use `wait` (or `plan wait`) once, in the background if you like, and act on its exit.
132
133
  - 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
+ - Need to know something about the result? `zcode-agent result <id> --json --full` first; read code only as a last resort.
134
135
  - 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
 
136
137
  ## Example: a marketing one-pager with an application form
@@ -166,4 +167,4 @@ You read the empty repo, decide the design system, copy, motion, form logic and
166
167
 
167
168
  ## Exit codes
168
169
 
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.
170
+ 0 completed · 2 usage (bad flag, contract, plan, effort, duplicate id, or a mistyped command) · 3 no key · 4 no engine · 5 failed · 6 `agent` had no subagent · 7 workspace conflict / session busy / plan name taken · 8 partial or checks failing · 9 unverified · 10 blocked · 124 timeout (for `wait`: still running) · 130 cancelled. `plan run|wait`: 0 all completed · 10 a session is blocked · 8 otherwise · 124 still running.
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  name: zcode-agent
3
- description: Delegate scoped implementation work to the zcode-agent CLI (cheap GLM-5.3 executor with Playwright; an independent GLM-5.3-Flash 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.
3
+ description: Delegate scoped implementation work to the zcode-agent CLI (cheap GLM-5.4 executor with Playwright; an independent GLM-5.3-Flash 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
4
  ---
5
5
 
6
6
  # Operating zcode-agent as an executor
7
7
 
8
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
9
 
10
- **The point is cost.** Your tokens are the expensive ones; GLM-5.3'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.
10
+ **The point is cost.** Your tokens are the expensive ones; GLM'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
11
 
12
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
13
 
@@ -77,11 +77,11 @@ Parallel sessions cost you little extra while they run: one `wait` on all of the
77
77
  | files | `--file path` | files to read first (don't also pass them as `--context @`) |
78
78
  | context | `--context "…"` / `--context @file` | background that isn't a decision |
79
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 |
80
+ | everything | `--task contract.json` | keys: objective, scope, constraints, decisions, design, acceptance, checks, visual, viewports, units, serve, files, references, context, owns, touch, limits, model, effort |
81
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.
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`, plus the Playwright browser (`--no-browser` drops that). Leave the default unless a run needs to be reproducible on another machine.
83
83
 
84
- Model and effort: don't pass `--model` or `--effort`. Everything runs on GLM-5.3 at effort `high` by default: sessions, units and plans. The visual verifier always runs on GLM-5.3-Flash, because only Flash can see images. Use `--model flash` when the user asks for it, or when the executor itself should look at screenshots or attached images (GLM-5.3 can't); it is cheaper and faster too. `--effort low|high|max`. Other values are refused before anything starts.
84
+ Model and effort: don't pass `--model` or `--effort`. Everything runs on GLM-5.4 at effort `high` by default: sessions, units and plans; it can look at screenshots and attached images itself. The independent visual verifier runs on GLM-5.3-Flash, the cheapest model that sees images. Use `--model flash` when the user asks for it (cheaper and faster), and `--model glm-5.3` only when asked. `--effort low|high|max`. Other values are refused before anything starts.
85
85
 
86
86
  ## Running
87
87
 
@@ -90,7 +90,7 @@ zcode-agent task --detach --id <id> --cwd <repo> [flags] "<objective>" # print
90
90
  zcode-agent wait <id…> --timeout-ms 540000 --json --quiet # 124 = still running (one line each): wait again
91
91
  zcode-agent wait <id…> --any --timeout-ms 540000 --json --quiet # return on the first that finishes
92
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
93
+ zcode-agent result <id> --json [--full] # brief again, or the full record
94
94
  zcode-agent cancel <id>
95
95
  ```
96
96
 
@@ -98,9 +98,10 @@ Plans:
98
98
 
99
99
  ```sh
100
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
101
+ zcode-agent plan run plan.json --detach
102
+ zcode-agent plan run plan.json --preflight # foreground; prints only the questions
103
+ zcode-agent plan wait <name> --timeout-ms 540000 --json # one summary line; briefs only for non-completed sessions
104
+ zcode-agent plan resume <name> ["<message>"] # resume every non-completed session, relaunch skipped
104
105
  zcode-agent plan resume <name> --session <id> "<answer>" # answer one blocked session
105
106
  ```
106
107
 
@@ -122,7 +123,7 @@ Real tasks outlast a single shell call; always wait in bounded slices. zcode-age
122
123
  | `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
124
  | `partial` | 8 | read `issues` / `unresolved` / unmet `visual` / `scopeViolations`; resume with one-line guidance or re-scope |
124
125
  | `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
+ | `unverified` | 9 | nothing confirmed it: no checks ran, or the executor gave no usable "done" report. Resume with a check added |
126
127
  | `cancelled` | 130 | resume if wanted |
127
128
 
128
129
  ## Hard rules after dispatch
@@ -130,7 +131,7 @@ Real tasks outlast a single shell call; always wait in bounded slices. zcode-age
130
131
  - Don't open files a `completed` session changed. Don't re-run checks it ran. Don't look at its screenshots.
131
132
  - Don't poll `status`; use `wait` (or `plan wait`) once, in the background if you like, and act on its exit.
132
133
  - 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
+ - Need to know something about the result? `zcode-agent result <id> --json --full` first; read code only as a last resort.
134
135
  - 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
 
136
137
  ## Example: a marketing one-pager with an application form
@@ -166,4 +167,4 @@ You read the empty repo, decide the design system, copy, motion, form logic and
166
167
 
167
168
  ## Exit codes
168
169
 
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.
170
+ 0 completed · 2 usage (bad flag, contract, plan, effort, duplicate id, or a mistyped command) · 3 no key · 4 no engine · 5 failed · 6 `agent` had no subagent · 7 workspace conflict / session busy / plan name taken · 8 partial or checks failing · 9 unverified · 10 blocked · 124 timeout (for `wait`: still running) · 130 cancelled. `plan run|wait`: 0 all completed · 10 a session is blocked · 8 otherwise · 124 still running.