zcode-agent 1.0.0 → 1.1.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/README.md +50 -0
- package/assets/acp-agents.md +11 -0
- package/bin/zcode-agent-acp.js +11 -0
- package/bin/zcode-agent.js +26 -2
- package/lib/acp-map.js +543 -0
- package/lib/acp.js +763 -0
- package/lib/appserver.js +42 -12
- package/lib/bootstrap.js +2 -1
- package/lib/commands/acp.js +35 -0
- package/lib/commands/sessions.js +6 -2
- package/lib/help.js +15 -0
- package/lib/isolation.js +5 -1
- package/package.json +9 -4
package/lib/appserver.js
CHANGED
|
@@ -35,7 +35,7 @@ class TurnError extends Error {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
class AppServerClient {
|
|
38
|
-
constructor({ nodeBin, enginePath, env, cwd, scrub = (s) => s }) {
|
|
38
|
+
constructor({ nodeBin, enginePath, env, cwd, scrub = (s) => s, interactions = null }) {
|
|
39
39
|
this.nodeBin = nodeBin;
|
|
40
40
|
this.enginePath = enginePath;
|
|
41
41
|
this.env = env;
|
|
@@ -47,6 +47,9 @@ class AppServerClient {
|
|
|
47
47
|
this.onFrame = null; // (frame) => void for every notification
|
|
48
48
|
this.dead = false;
|
|
49
49
|
this.engineStderr = '';
|
|
50
|
+
// ACP (lib/acp.js): {permission(params), userInput(params)} → the
|
|
51
|
+
// engine's reply, asked of a person instead of the headless policy.
|
|
52
|
+
this.interactions = interactions;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
55
|
start() {
|
|
@@ -135,13 +138,21 @@ class AppServerClient {
|
|
|
135
138
|
reply(RUNTIME_PREFERENCES);
|
|
136
139
|
return;
|
|
137
140
|
}
|
|
141
|
+
if (this.interactions && (method === 'interaction/requestPermission' || method === 'interaction/requestUserInput')) {
|
|
142
|
+
const ask = method === 'interaction/requestPermission' ? this.interactions.permission : this.interactions.userInput;
|
|
143
|
+
Promise.resolve()
|
|
144
|
+
.then(() => ask(frame.params || {}))
|
|
145
|
+
.then(reply, (err) => replyError(-32000, `zcode-agent: ${err && err.message ? err.message : err}`));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
138
148
|
if (method === 'interaction/requestPermission') {
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
|
|
149
|
+
// The reply schema is strict ({decision, reason?, modifiedInput?,
|
|
150
|
+
// permissionUpdates?}; live-probed 1.1: an extra resolvedAt made the
|
|
151
|
+
// engine deny the tool). The request's own "allow once" option carries
|
|
152
|
+
// a reply in exactly that shape.
|
|
153
|
+
reply(allowOnce(frame.params) || {
|
|
142
154
|
decision: 'allow',
|
|
143
155
|
reason: 'zcode-agent: headless auto-approve (yolo mode; --cwd is the blast radius)',
|
|
144
|
-
resolvedAt: new Date().toISOString(),
|
|
145
156
|
});
|
|
146
157
|
return;
|
|
147
158
|
}
|
|
@@ -215,6 +226,13 @@ class AppServerClient {
|
|
|
215
226
|
}
|
|
216
227
|
}
|
|
217
228
|
|
|
229
|
+
// The engine's reply for a permission request's "allow once" option, or null.
|
|
230
|
+
function allowOnce(params) {
|
|
231
|
+
const options = (params && Array.isArray(params.options)) ? params.options : [];
|
|
232
|
+
const option = options.find((o) => o && o.kind === 'allow_once' && o.response);
|
|
233
|
+
return option ? option.response : null;
|
|
234
|
+
}
|
|
235
|
+
|
|
218
236
|
// --- turn orchestration -----------------------------------------------------
|
|
219
237
|
|
|
220
238
|
function workspaceKeyFor(workspacePath) {
|
|
@@ -297,10 +315,11 @@ async function openSession(client, {
|
|
|
297
315
|
effort,
|
|
298
316
|
resumeSessionId = null,
|
|
299
317
|
requiredMcp = [],
|
|
318
|
+
mode = 'yolo',
|
|
300
319
|
onEvent = () => {},
|
|
301
320
|
onMcpStatuses = () => {},
|
|
302
321
|
}) {
|
|
303
|
-
const session = { sessionId: null, resumed: false, mode: null };
|
|
322
|
+
const session = { sessionId: null, resumed: false, mode: null, created: null };
|
|
304
323
|
if (resumeSessionId) {
|
|
305
324
|
const resumed = await client.request(
|
|
306
325
|
'session/resume',
|
|
@@ -311,14 +330,15 @@ async function openSession(client, {
|
|
|
311
330
|
session.sessionId = s.sessionId || resumeSessionId;
|
|
312
331
|
session.resumed = true;
|
|
313
332
|
session.mode = s.mode || null;
|
|
314
|
-
|
|
315
|
-
session.mode
|
|
333
|
+
session.created = resumed;
|
|
334
|
+
await client.request('session/setMode', { sessionId: session.sessionId, mode }, { timeoutMs: 15000 });
|
|
335
|
+
session.mode = mode;
|
|
316
336
|
} else {
|
|
317
337
|
const created = await client.request(
|
|
318
338
|
'session/create',
|
|
319
339
|
{
|
|
320
340
|
workspace: { workspacePath, workspaceKey: workspaceKeyFor(workspacePath) },
|
|
321
|
-
mode
|
|
341
|
+
mode,
|
|
322
342
|
model: { providerId: 'zai-api', modelId, options: { reasoningLevel: effort } },
|
|
323
343
|
thoughtLevel: effort,
|
|
324
344
|
// Persist the session row NOW: the default (deferred) loses it to
|
|
@@ -330,11 +350,12 @@ async function openSession(client, {
|
|
|
330
350
|
const s = created.session || created.value || {};
|
|
331
351
|
session.sessionId = s.sessionId;
|
|
332
352
|
session.mode = s.mode || null;
|
|
353
|
+
session.created = created;
|
|
333
354
|
if (!session.sessionId) throw new TurnError('session/create returned no session.sessionId');
|
|
334
355
|
// §9.1 mode ladder: create's mode param is not honored (live-probed).
|
|
335
|
-
if (s.mode !==
|
|
336
|
-
await client.request('session/setMode', { sessionId: session.sessionId, mode
|
|
337
|
-
session.mode =
|
|
356
|
+
if (s.mode !== mode) {
|
|
357
|
+
await client.request('session/setMode', { sessionId: session.sessionId, mode }, { timeoutMs: 15000 });
|
|
358
|
+
session.mode = mode;
|
|
338
359
|
}
|
|
339
360
|
}
|
|
340
361
|
await client.request(
|
|
@@ -360,6 +381,7 @@ async function runTurn(client, session, {
|
|
|
360
381
|
signal = null,
|
|
361
382
|
keepReasoning = false,
|
|
362
383
|
onEvent = () => {},
|
|
384
|
+
onFrame = null,
|
|
363
385
|
}) {
|
|
364
386
|
const started = Date.now();
|
|
365
387
|
const turn = {
|
|
@@ -400,6 +422,13 @@ async function runTurn(client, session, {
|
|
|
400
422
|
client.onFrame = (frame) => {
|
|
401
423
|
const method = frame.method;
|
|
402
424
|
const params = frame.params || {};
|
|
425
|
+
if (onFrame) {
|
|
426
|
+
try {
|
|
427
|
+
onFrame(frame);
|
|
428
|
+
} catch {
|
|
429
|
+
/* a consumer's bug must not take down the engine reader */
|
|
430
|
+
}
|
|
431
|
+
}
|
|
403
432
|
if (method === 'session/event') {
|
|
404
433
|
const type = params.type;
|
|
405
434
|
const payload = params.payload;
|
|
@@ -513,4 +542,5 @@ module.exports = {
|
|
|
513
542
|
workspaceKeyFor,
|
|
514
543
|
waitForMcp,
|
|
515
544
|
RUNTIME_PREFERENCES,
|
|
545
|
+
allowOnce,
|
|
516
546
|
};
|
package/lib/bootstrap.js
CHANGED
|
@@ -57,13 +57,14 @@ function resolveRuntime(env = process.env) {
|
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function makeClient(runtime, { home, cwd, sessionEnv = {} }) {
|
|
60
|
+
function makeClient(runtime, { home, cwd, sessionEnv = {}, interactions = null }) {
|
|
61
61
|
return new AppServerClient({
|
|
62
62
|
nodeBin: runtime.nodeBin,
|
|
63
63
|
enginePath: runtime.enginePath,
|
|
64
64
|
env: engineEnv({ home, builtinProviderConfig: runtime.builtinConfig, sessionEnv }),
|
|
65
65
|
cwd,
|
|
66
66
|
scrub: runtime.scrub,
|
|
67
|
+
interactions,
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// lib/commands/acp.js — `zcode-agent acp`: serve the Agent Client Protocol
|
|
3
|
+
// on stdio (lib/acp.js) until the client closes stdin. Flags set the
|
|
4
|
+
// defaults of every session; clients change mode, model and effort per
|
|
5
|
+
// session through ACP config options.
|
|
6
|
+
const { serve } = require('../acp.js');
|
|
7
|
+
const { MODE_IDS } = require('../acp-map.js');
|
|
8
|
+
|
|
9
|
+
module.exports = function acpCommand(parsed) {
|
|
10
|
+
const { flags, given } = parsed;
|
|
11
|
+
if (parsed.prompts.length) {
|
|
12
|
+
process.stderr.write(`zcode-agent: acp takes no arguments (got "${parsed.prompts.join(' ')}"); it speaks ACP on stdio.\n`);
|
|
13
|
+
process.exit(2);
|
|
14
|
+
}
|
|
15
|
+
const mode = flags.mode || process.env.ZCODE_ACP_MODE || 'build';
|
|
16
|
+
if (!MODE_IDS.includes(mode)) {
|
|
17
|
+
process.stderr.write(`zcode-agent: unknown mode "${mode}". --mode accepts ${MODE_IDS.join(' | ')}.\n`);
|
|
18
|
+
process.exit(2);
|
|
19
|
+
}
|
|
20
|
+
serve({
|
|
21
|
+
version: require('../../package.json').version,
|
|
22
|
+
defaults: {
|
|
23
|
+
model: flags.model,
|
|
24
|
+
effort: flags.effort,
|
|
25
|
+
mode,
|
|
26
|
+
mcpSpecs: flags.mcpSpecs,
|
|
27
|
+
hermetic: flags.hermetic,
|
|
28
|
+
browser: !flags.noBrowser,
|
|
29
|
+
skillsDirs: flags.skillsDirs.map((d) => require('node:path').resolve(d)),
|
|
30
|
+
noSkills: flags.noSkills,
|
|
31
|
+
inheritDesktop: flags.inheritDesktop,
|
|
32
|
+
timeoutMs: given.has('timeoutMs') ? flags.timeoutMs : null,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
};
|
package/lib/commands/sessions.js
CHANGED
|
@@ -196,8 +196,12 @@ async function cancel(parsed) {
|
|
|
196
196
|
process.exit(0);
|
|
197
197
|
};
|
|
198
198
|
if (!view.live) return report('not running');
|
|
199
|
+
// An ACP session's pid is the `zcode-agent acp` host, which serves its
|
|
200
|
+
// client's other sessions too: stop only this session's engine. The turn
|
|
201
|
+
// fails in the client; its next prompt starts a new engine.
|
|
202
|
+
const acp = view.kind === 'acp';
|
|
199
203
|
try {
|
|
200
|
-
process.kill(view.pid, 'SIGTERM');
|
|
204
|
+
process.kill(acp ? -view.enginePid : view.pid, 'SIGTERM');
|
|
201
205
|
} catch {
|
|
202
206
|
/* exited in between */
|
|
203
207
|
}
|
|
@@ -207,7 +211,7 @@ async function cancel(parsed) {
|
|
|
207
211
|
view = store.viewSession(store.readSession(id));
|
|
208
212
|
if (!view.live) return report('cancelled');
|
|
209
213
|
}
|
|
210
|
-
for (const target of [view.pid, -view.enginePid]) {
|
|
214
|
+
for (const target of [acp ? null : view.pid, -view.enginePid]) {
|
|
211
215
|
if (!target) continue;
|
|
212
216
|
try {
|
|
213
217
|
process.kill(target, 'SIGKILL'); // negative = the engine's process group
|
package/lib/help.js
CHANGED
|
@@ -119,6 +119,21 @@ Engine, key, inherited MCP servers and skills, and browser report.
|
|
|
119
119
|
drives (needed only without the ZCode app's own Playwright server).`,
|
|
120
120
|
skills: `usage: zcode-agent skills [install|uninstall] [claude|codex]
|
|
121
121
|
Install the orchestrator skills (default: show status).`,
|
|
122
|
+
acp: `usage: zcode-agent acp [options]
|
|
123
|
+
Serve the Agent Client Protocol (ACP v1) on stdio: T3 Code, Zed and any ACP
|
|
124
|
+
client run GLM-5.3 through it. Each ACP session is a zcode-agent session
|
|
125
|
+
(status, watch, cost see it); clients switch mode, model and effort per session.
|
|
126
|
+
--mode <mode> default for new sessions: build (ask before edits and
|
|
127
|
+
commands) | edit (accept edits) | plan | yolo (full access)
|
|
128
|
+
default build (or $ZCODE_ACP_MODE)
|
|
129
|
+
--model <id> glm-5.3 | glm-5.3-flash (default glm-5.3-flash)
|
|
130
|
+
--effort <lvl> low | high | max (default max)
|
|
131
|
+
--timeout-ms <n> per prompt (default: none)
|
|
132
|
+
--mcp <json|@f> add MCP servers (repeatable) --hermetic --no-browser
|
|
133
|
+
--skills <dir> add skills (repeatable) --no-skills
|
|
134
|
+
--inherit-desktop also the desktop's AGENTS.md, plugins and agent profiles
|
|
135
|
+
T3 Code: an ACP Registry provider, source "Local command", executable
|
|
136
|
+
zcode-agent-acp (see the README). $ZCODE_ACP_LOG=<file> logs every frame.`,
|
|
122
137
|
};
|
|
123
138
|
|
|
124
139
|
function commandHelp(command) {
|
package/lib/isolation.js
CHANGED
|
@@ -358,6 +358,8 @@ const HOST_ONLY_SKILLS = new Set(['control-browser', 'zcode', 'zcode-agent']);
|
|
|
358
358
|
// The executor instructions every engine HOME gets as ~/.zcode/AGENTS.md.
|
|
359
359
|
// Named so that agents working on this repo don't read it as their own.
|
|
360
360
|
const EXECUTOR_AGENTS_MD = path.join(__dirname, '..', 'assets', 'executor-agents.md');
|
|
361
|
+
// `zcode-agent acp`: a person watches and approves in the client.
|
|
362
|
+
const ACP_AGENTS_MD = path.join(__dirname, '..', 'assets', 'acp-agents.md');
|
|
361
363
|
|
|
362
364
|
// Rewrites the frontmatter `model:` of an agent profile when it names
|
|
363
365
|
// GLM-5.3 / GLM-5.3-Flash (any prefix: "account:x/GLM-5.3",
|
|
@@ -385,6 +387,7 @@ function buildEngineHome({
|
|
|
385
387
|
inheritDesktop = false,
|
|
386
388
|
profile = null,
|
|
387
389
|
model = DEFAULT_MODEL,
|
|
390
|
+
instructions = EXECUTOR_AGENTS_MD,
|
|
388
391
|
}) {
|
|
389
392
|
const zdir = path.join(home, '.zcode');
|
|
390
393
|
const v2 = path.join(zdir, 'v2');
|
|
@@ -449,7 +452,7 @@ function buildEngineHome({
|
|
|
449
452
|
// minutes per session (0.7.1), so it is appended only with
|
|
450
453
|
// --inherit-desktop.
|
|
451
454
|
const agentsMd = path.join(zdir, 'AGENTS.md');
|
|
452
|
-
const parts = [fs.readFileSync(
|
|
455
|
+
const parts = [fs.readFileSync(instructions, 'utf8').trim()];
|
|
453
456
|
if (inheritDesktop && fs.existsSync(path.join(live, 'AGENTS.md'))) {
|
|
454
457
|
parts.push(fs.readFileSync(path.join(live, 'AGENTS.md'), 'utf8').trim());
|
|
455
458
|
}
|
|
@@ -609,6 +612,7 @@ module.exports = {
|
|
|
609
612
|
inheritableMcpServers,
|
|
610
613
|
needsOAuth,
|
|
611
614
|
EXECUTOR_AGENTS_MD,
|
|
615
|
+
ACP_AGENTS_MD,
|
|
612
616
|
DEFAULT_BROWSER_SERVER,
|
|
613
617
|
PLAYWRIGHT_MCP_VERSION,
|
|
614
618
|
readMcpHealth,
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zcode-agent",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Cheap, verified execution for Claude Code and Codex: your orchestrator decides, GLM-5.3-Flash builds, tests and visually verifies in headless ZCode sessions (parallel sessions, subagents, dependency plans) and hands back a compact result. Uses your ZCode app's key, MCP servers and skills, or runs standalone.",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Cheap, verified execution for Claude Code and Codex: your orchestrator decides, GLM-5.3-Flash builds, tests and visually verifies 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
|
-
"zcode-agent": "bin/zcode-agent.js"
|
|
7
|
+
"zcode-agent": "bin/zcode-agent.js",
|
|
8
|
+
"zcode-agent-acp": "bin/zcode-agent-acp.js"
|
|
8
9
|
},
|
|
9
10
|
"engines": {
|
|
10
11
|
"node": ">=22.13"
|
|
@@ -40,7 +41,11 @@
|
|
|
40
41
|
"coding-agent",
|
|
41
42
|
"subagent",
|
|
42
43
|
"headless",
|
|
43
|
-
"mcp"
|
|
44
|
+
"mcp",
|
|
45
|
+
"acp",
|
|
46
|
+
"agent-client-protocol",
|
|
47
|
+
"t3code",
|
|
48
|
+
"zed"
|
|
44
49
|
],
|
|
45
50
|
"repository": {
|
|
46
51
|
"type": "git",
|