GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - stefandevo/glm-acp-agent: ACP agent in TypeScript that uses the Z.AI / Zhipu AI GLM Coding Plan models (GLM-5.3, GLM-5 Turbo, GLM-4.7) as the reasoning core

BranchesTags
Open more actions menu

Latest commit

 

History

175 Commits
175 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
registry
registry
 
 
scripts
scripts
 
 
src
src
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
RELEASING.md
RELEASING.md
 
 
eslint.config.js
eslint.config.js
 
 
icon.svg
icon.svg
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

glm-acp-agent

An Agent Client Protocol (ACP) agent written in TypeScript that uses the Z.AI / Zhipu AI GLM model family (GLM-5.4, GLM-5.3, GLM-5.3 Flash, GLM-5 Turbo, GLM-4.7) as its reasoning core.

The agent connects to any ACP-compatible IDE or client over stdio, streams responses back in real time, and can call a rich set of tools to interact with the user's file system, terminal, and the web.

Streaming responses must include a supported terminal finish reason. An early connection close is reported as an interrupted response, with received text retained for session replay. Tool calls run only after a complete tool_calls response; calls in output-limit (length) or filtered (content_filter) responses are discarded and the corresponding stop reason is preserved.

Completed provider reasoning is retained unchanged in conversation history and saved sessions for subsequent model calls, even when thought display is disabled. ACP_GLM_STREAM_THINKING=false controls client display only. Reasoning from cancelled, incomplete, or output-limited responses is not replayed as a completed reasoning chain.


Coding Plan Only

glm-acp-agent is intentionally built for the Z.AI GLM Coding Plan. It is not a general-purpose Z.AI Open Platform API client.

By default, model calls use the Coding Plan endpoint:

https://api.z.ai/api/coding/paas/v4

The same Coding Plan API key is used for the agent's GLM model calls and supported Coding Plan tools. General Z.AI API/resource-package billing surfaces, such as direct /api/paas/v4 Tool API calls, are intentionally out of scope for this ACP agent.

Built-in web tools use Coding Plan-compatible MCP endpoints, not the general /api/paas/v4 Tool API. If you need general Z.AI API billing, separate resource packages, or non-Coding Plan endpoints, use a different provider configuration or fork this agent for that purpose.


Features

  • Full ACP compliance – implements initialize, authenticate, session/new, session/set_mode, session/prompt, session/cancel, session/close, session/list, session/load, session/fork, session/resume, and session/set_model, and pushes session_info_update, config_option_update, current_mode_update, and available_commands_update notifications
  • Streaming – assistant text and reasoning tokens are forwarded as incremental ACP chunks
  • Tool calling – agentic loop with a configurable cap of GLM function-calling turns (default 100; see ACP_GLM_MAX_TURNS / --max-turns). Reaching the cap finishes the turn's tool calls and saves their real results. A user abort keeps only calls that had started.
  • Thinking mode – GLM's reasoning_content tokens are surfaced as agent_thought_chunk blocks so the client can show the model's chain of thought
  • Session permission modes – supports default, accept_edits, and bypass_permissions via session/set_mode. Clients like DevFlow can use this to toggle between prompting for every edit, auto-approving edits while prompting for commands, or bypassing permissions entirely.
  • Per-session model switching – session/set_model lets clients change the active GLM model mid-conversation; session/new returns the curated availableModels list
  • Slash commands – commands and skills found under the session's .claude/ directory are advertised to the client with available_commands_update, so / autocomplete is populated (see Slash commands)
  • Goals (/goal) – /goal <condition> keeps the agent working across turns until a separate evaluator model confirms the condition is met, judges it impossible, or you pause it; the round budget, a round's turn limit, a no-progress streak, a cancel, or an evaluator outage pause the goal instead of running unbounded (see Goals)
  • Image input via Coding Plan-native vision or Vision MCP – promptCapabilities.image is advertised; glm-5.4 and glm-5.3-flash send supported pasted ACP image blocks directly as native image_url content parts, while glm-5.3, glm-5-turbo and glm-4.7 route them through Z.AI Vision MCP (@z_ai/mcp-server). glm-5v-turbo keeps the same native-vision path when re-added via ACP_GLM_AVAILABLE_MODELS — it is no longer on the Coding Plan allowlist. Direct chat-image-only models (e.g. glm-4v-plus) are intentionally not used.
  • Session persistence – conversations are written to ~/.local/state/glm-acp-agent/sessions/ and can be reloaded via session/load, branched via session/fork, or resumed without replay via session/resume
  • Ten built-in tools (see below)
  • Structured questions – ask_user_question renders in the client's own UI as an ACP form elicitation (or permission buttons when the client has no form support); session modes never bypass a question
  • Self-sufficient local tools – directory listings and shell commands always run in the agent process; file tools fall back to local filesystem access when ACP client fs capabilities are unavailable
  • Configurable permissions – write_file, run_command, web_reader, and non-local image_analysis behavior depends on the active session mode (prompts by default)
  • Protocol-correct stop reasons – maps model and runtime conditions to ACP end_turn, max_tokens, max_turn_requests, refusal, and cancelled
  • Protocol-correct tool statuses – pending → in_progress → completed / failed
  • Token usage reporting – aggregated usage is returned on the session/prompt response; after each model request the agent also sends a usage_update (used = that request's prompt + completion tokens, size = the model's context window) so clients can show how full the context is
  • Coding Plan quota – built-in /usage reports account allowance and reset times without a model call; clients can query the advertised _glm/usage extension

Architecture

ACP Client (IDE plugin, CLI, …)
        │  stdio (ndjson)
        ▼
  GlmAcpAgent          ← ACP protocol layer  (src/protocol/)
        │
        ├─ GlmClient   ← Z.AI / Zhipu AI Coding Plan Chat Completions  (src/llm/)
        │
        ├─ ToolExecutor ← executes tool calls  (src/tools/)
        │    ├─ read_file / list_files        → ACP client fs for read_file when reads are advertised, else Agent process (Node fs); read_file and list_files workspace-confined, read_file paginated (offset/limit)
        │    ├─ write_file / edit_file        → ACP client fs when advertised (editor-buffer diffs), else Agent process (Node fs)
        │    ├─ list_files / run_command     → Agent process (Node fs / child_process)
        │    ├─ web_search / web_reader      → Z.AI Coding Plan Web MCP (HTTP)
        │    ├─ image_analysis               → Z.AI Coding Plan Vision MCP (stdio)
        │    ├─ todowrite                    → Agent process (per-session task list; replaces chat narration)
        │    └─ ask_user_question            → ACP client (elicitation/create form; permission buttons without form support)
        │
        └─ VisionMcpClient ← spawns `npx @z_ai/mcp-server` on demand

The agent process needs network access to api.z.ai for chat completions and Web MCP, plus npx available on PATH so it can launch @z_ai/mcp-server for vision. Filesystem and shell operations use paths resolved against the ACP session working directory. read_file and list_files are confined to the session workspace: paths and symlink targets resolving outside are rejected, and a rejected list_files enumerates nothing. It uses the editor buffer when fs.readTextFile is advertised, including new buffers whose parent directory exists inside the workspace; otherwise it uses the agent process filesystem. When the client advertises fs.writeTextFile, writes and edits are routed through the ACP client so they render as native diffs. Edit-file reads still require both fs.readTextFile and fs.writeTextFile to use the editor buffer; otherwise they fall back to the agent process filesystem. Writes and arbitrary shell commands still go through ACP session/request_permission, as do web_reader calls and image_analysis calls whose image_source is a non-local source, and the permission payload is always the full tool arguments — the user approves exactly what will run.

Agent-side list_files and local image_analysis always use an existing canonical target, even when the client advertises file reads. Only editor-backed read_file preserves the caller's absolute alias and allows a missing file for a new editor buffer; those exceptions do not apply to agent-side tools.

Even ACP-backed read_file requests use the agent filesystem for canonicalized confinement checks. The workspace and existing parent directories must be visible to the agent with matching path and symlink semantics. If canonicalization is unavailable, the read fails closed; client-only paths do not bypass the containment check. Containment is canonicalization-based hardening, not a race-proof sandbox: a concurrent symlink swap between the check and the open can still redirect a local read, and on client-backed reads the editor's fs/read_text_file receives the caller's alias, so a symlink swapped in between the check and the editor read is likewise followed by the editor. On case-insensitive filesystems (the default on macOS APFS and Windows), realpath may not normalize letter case consistently between the session workspace and a target path, so the likely failure mode is a false rejection — the safe direction; a cross-platform assertion for this is not feasible in the test suite (Linux CI is case-sensitive, macOS and Windows are not), which is why it is documented here rather than tested.

Client-facing tool cards stay compact: long strings in rawInput/rawOutput are elided to a short head plus a character count, and every completed or failed card's visible text — including the read_file content preview — is bounded to an aggregate 16 KiB UTF-8 budget; oversized previews end with [… N bytes elided in preview; full result sent to model] and card titles are elided to 240 characters. The model still receives the full tool result, capped at 256 KiB by ACP_GLM_TOOL_RESULT_LIMIT_BYTES; write payloads and permission requests remain complete. Progress narration lives in the todowrite task list rather than prose, and reasoning tokens are only forwarded as agent_thought_chunk when ACP_GLM_STREAM_THINKING is not false (the default preserves streaming).

Client MCP, context, and trust boundary

All MCP transports share an 8 MiB response cap (MCP_RESPONSE_LIMIT_BYTES): HTTP response bodies are read incrementally and a larger body cancels the read and fails the tool call, while an oversized or newline-less stdio JSON-RPC frame fails the connection, rejecting pending requests and terminating the child process. The cap applies to client-provided servers and to the built-in Web MCP and Vision MCP clients.

Client-provided MCP servers

ACP clients may attach MCP server definitions when creating or loading a session. The agent supports client-configured stdio and HTTP MCP servers. SSE is unsupported and rejected when the agent tries to connect. In the ACP SDK capability schema, mcpCapabilities.http advertises HTTP support and mcpCapabilities.sse advertises SSE support. This agent advertises only http: true and does not advertise SSE; the capability object has no stdio flag.

A stdio MCP child starts with a copy of the agent process environment, then the server's configured environment entries override matching inherited values. This can pass credentials such as Z_AI_API_KEY to that child. Review client-supplied MCP commands and environment values as trusted code/configuration.

Context compaction

Before provider requests, the agent estimates context use with a heuristic rather than the provider's tokenizer. When history exceeds the model budget, it can remove older complete exchanges and shorten tool results; the system context and latest user request are retained. If those, the tool schemas, and reserved output/safety space still exceed the model's context window, the request fails with guidance to narrow it or choose a larger-context model. Earlier conversation details may therefore not remain verbatim in model context. An active /goal is not affected: every continuation message restates the condition, so the model keeps working toward it even after the original directive has been compacted away.

Trust boundary

The agent does not run tools inside an OS or container sandbox. Shell commands and local filesystem fallbacks run with the agent process's OS-user permissions; shell children inherit its environment, and commands can access the network available to that user. ACP permission prompts and session modes govern consent behavior but do not provide process isolation. Built-in network tools follow that consent model: web_search is deliberately silent because its query goes only to Z.AI's service (there is no attacker-chosen host), web_reader fetches only the approved initial URL (redirects followed by the reader service are not re-prompted), and image_analysis passes non-local sources to Vision only after approval. Treat workspaces, prompts, and MCP configurations as trusted, and use external OS/container isolation when you need a stronger boundary.


Available Tools

Tool Runs on Permission behavior Description
read_file ACP client when fs read capability is advertised, otherwise agent process Always silent Read a text file or editor buffer, paginated by offset/limit (default 2000 lines, capped at 5000). Paths and symlink targets resolving outside the workspace are rejected. Local scans are byte-bounded; totals can be unknown and an incomplete line is never given a next offset.
write_file Agent process (ACP client fs when advertised) Mode-dependent Write or overwrite a text file. Silent in accept_edits and bypass_permissions.
edit_file Agent process (ACP client fs when advertised) Mode-dependent Replace one exact, unique snippet in an existing file. It refuses an input or editor buffer over the read/edit budget, and re-validates after permission and progress notification delivery to preserve changes present at the final read. Silent in accept_edits and bypass_permissions.
todowrite Agent process Always silent Create or replace the session's structured task list so multi-step progress is tracked instead of narrated in chat. Each call replaces the list; the tool result renders it back to the model.
list_files Agent process Always silent List a directory through a bounded iterator; paths or symlink targets resolving outside the workspace are rejected with no enumeration, and a truncated result is a disclosed subset.
run_command Agent process Mode-dependent Run an arbitrary shell command; cancelling a turn terminates its shell process group, while intentionally backgrounded processes survive a normal shell exit. Silent only in bypass_permissions.
web_search Agent (Z.AI Coding Plan MCP) Always silent Search the web — returns titles, URLs, and summaries. Deliberately silent egress: the query goes to Z.AI's service only; there is no attacker-chosen host.
web_reader Agent (Z.AI Coding Plan MCP) Mode-dependent Fetch and parse a web page (markdown or plain text). The approval prompt carries the full URL; rejection, cancellation, or permission transport errors make no network request. The approval covers the initial URL — redirects followed by the reader service are not re-prompted. Silent only in bypass_permissions.
ask_user_question ACP client (form elicitation, else permission buttons) Never gated Ask the user structured multiple-choice questions (1–4 questions of 2–4 options, per-question free-text "Other"). With clientCapabilities.elicitation.form the client renders an inline form; otherwise a single single-select question renders as permission buttons plus a "None of these" decline. A question is user input, not an operation, so no session mode bypasses it: declining completes with empty answers, dismissing the form aborts the tool call and no later call in the batch runs.
image_analysis Agent (Z.AI Vision MCP, stdio) Mode-dependent (non-local) Analyze a local image path or remote URL using @z_ai/mcp-server. A non-local source requires approval first: the prompt carries the full image_source, and rejection, cancellation, or permission transport errors make no Vision MCP call. Non-local sources are silent only in bypass_permissions; clearly local paths stay silent in all modes and are workspace-confined — a local image_source whose path or symlink target resolves outside the workspace is rejected before any Vision MCP call.

Editor edits use an optimistic read followed by a full-buffer write. ACP's fs/write_text_file request has no version precondition, so edits made during that write RPC can still race with the replacement. The final read preserves unrelated changes already present and rejects a target snippet that has disappeared or become ambiguous.

Session Modes

Clients can use session/set_mode to drive the permission policy:

Mode ID Name write_file run_command web_reader image_analysis (non-local)
default Ask for permission Prompt Prompt Prompt Prompt
accept_edits Auto-approve edits Silent Prompt Prompt Prompt
bypass_permissions Bypass all permissions Silent Silent Silent Silent

Reads, listings, web_search, and session MCP tool calls are always silent across all modes, while web_reader and image_analysis with a non-local source follow the mode-dependent approval above. Local image_analysis paths stay silent in every mode and are confined to the session workspace.

After the existing leading/trailing whitespace trimming, image_analysis skips approval only for clearly local paths: ordinary relative/absolute paths and absolute Windows drive paths such as C:/images/cat.png. Scheme-bearing sources (including nonstandard HTTP forms and file:/data:), network-style paths (//host/... or UNC paths), and sources with remaining ASCII control characters require approval. This conservative classification performs no further normalization and does not add format support to the Vision MCP. Local analysis still announces an in_progress tool card before dispatch; silent means no permission prompt, not no progress card.

Permission prompts always carry the full, unelided tool arguments, so the user approves exactly what will run. The prompt offers exactly allow and reject, and a tool runs only when the response selects allow with outcome selected; anything else — a missing or unrecognised option id, an unknown outcome string, or a null/absent response — is treated as reject. An explicit cancelled outcome remains distinct from rejection.


Slash commands

After session/new, session/load, session/fork, and session/resume, the agent sends an ACP available_commands_update notification. Clients such as Zed and Paseo use it to populate their / autocomplete. Each notification is a full snapshot that replaces the previous list.

The snapshot always includes the built-in /usage and /goal commands. Other commands use the same on-disk layout Claude Code uses, read from the session's working directory and from ~/.claude for user-level definitions:

Path Command name
<cwd>/.claude/commands/commit.md /commit
<cwd>/.claude/commands/review/pr.md /review:pr
<cwd>/.claude/skills/audit/SKILL.md /audit

Project definitions shadow user-level ones with the same name. The description and argument-hint keys of a file's YAML frontmatter become the menu entry's description and input hint; without a description, the first heading (then the first line) of the body is used instead.

Advertised names are sent without a leading slash — the client prepends it for display and invokes the command by sending /name … as ordinary prompt text. When that text names an advertised command, the agent injects the definition's body into the user message, substituting $ARGUMENTS where the file asks for it and otherwise appending the typed arguments. Unknown /foo is left untouched and reaches the model as prose, so typing a slash by accident never fails the turn.

Coding Plan usage and quota

Send /usage by itself to see the account's Coding Plan quota windows, percentage used, remaining allowance, and reset times when the provider supplies them. The command runs locally in the agent: it makes a quota API request but no model or tool calls, and its request and output are not added to model history or saved session replay. /usage is reserved and takes precedence over a file-backed command or skill with that name. Arguments and attachments produce usage guidance.

Quota queries use the existing Z_AI_API_KEY / --setup credentials and GET /api/monitor/usage/quota/limit, the endpoint used by Z.AI's official usage plugin. The origin follows ACP_GLM_BASE_URL: only HTTPS on api.z.ai, open.bigmodel.cn, and dev.bigmodel.cn is supported. Custom proxies, custom ports, and redirects are rejected for quota lookup; no key is sent to them. This does not change model endpoint configuration.

Team-seat API keys

A key issued for a Z.AI team seat has no personal Coding Plan, so the default lookup fails (the provider reports that the user has no coding plan). When that happens, the agent discovers the team seat automatically with the same key: it calls GET /api/biz/customer/getCustomerInfo on the same origin, picks the account's single active project with "projectType": 2, and retries with GET /api/monitor/usage/quota/limit?type=2 plus bigmodel-organization: <organization ID> and bigmodel-project: <project ID>, matching Z.AI's own desktop client. All three requests share the refresh's deadline and response cap. A discovered seat is remembered in memory until the key or origin changes or a lookup with it fails, so later refreshes make one request. Personal keys still make exactly one request, and authentication, HTTP, network, or malformed-response failures never trigger discovery. Only the two IDs are read from the account reply; names, contact details, and IDs are never included in errors. If discovery fails or finds no team project, the original "no coding plan" error is reported.

If the account belongs to more than one active team project (or lists more than 64 organizations or projects), the agent does not guess: quota is reported as requestFailed and asks you to choose the seat. Set the team's organization ID and project ID explicitly to override discovery:

export Z_AI_ORGANIZATION_ID=org-xxxxxxxxxxxxxxxx
export Z_AI_PROJECT_ID=proj-xxxxxxxxxxxxxxxx

…or enter both when glm-acp-agent --setup asks for them (stored as z_ai_organization_id / z_ai_project_id in credentials.json). When either environment variable is set (including to a blank value to clear a stored seat), the environment pair wins over the file as a unit. With both set, discovery is skipped and the lookup goes straight to ?type=2 with those IDs. If only one is set, or a value contains whitespace or control characters, quota is reported as missingCredentials and no request is sent. These settings only affect quota lookup; model requests are unchanged.

Results are cached in memory for 60 seconds and concurrent lookups share one request per account. Failed attempts are also cached for 60 seconds. A refresh has a 10-second deadline and a 256 KiB response cap. A transient failure retains the previous values with an explicit stale notice and their last successful timestamp. Authentication failures clear previous values; changing credentials, team seat, or origin invalidates the cache. Cancelling /usage stops waiting immediately; a shared request can finish and populate the cache for another caller. Disconnecting the ACP transport aborts the request.

The reader accepts both CREDIT_LIMIT and legacy TOKENS_LIMIT entries, plus TIME_LIMIT MCP allowances. It uses returned percentages and counts, deriving percentages or remaining counts only when the necessary totals are present. Unknown quota types are ignored; missing or unrecognized data is reported as unavailable rather than zero. No fixed plan allowances are assumed. Duration units known to the reader are hours, days, and weeks (a team seat's unit: 6, number: 1 window is reported as 1-week, kind: "weekly", windowDurationMins: 10080); other units retain an unspecified duration. The monitoring endpoint is not a versioned public quota contract, so provider changes or account restrictions may make quota unavailable.

Goals (/goal)

/goal sets one condition for the session and keeps the agent working toward it across turns, so you state an outcome once instead of sending "keep going" after every premature stop. It follows the /goal commands of Claude Code, Codex CLI, Kimi Code, and Hermes Agent, adapted to ACP: the agent cannot start a turn on its own, so the loop runs inside the session/prompt call. The client sees one long turn, and session/cancel (the stop button) is the escape hatch.

/goal all tests in test/auth pass and the lint step is clean

Setting a goal starts working immediately. When the model ends a turn, a separate evaluator model — a plain, tool-less completion on the session's model by default — reads the condition and a bounded window of the recent transcript and returns one verdict:

Verdict What happens
met The goal is marked achieved and the loop ends.
impossible The goal is marked blocked and paused; re-scope it with /goal <condition> or override with /goal resume.
not_met The evaluator's reason is fed back as the next round's instructions and the agent continues.
needs_input The round ended with a question for you. The goal pauses as paused (awaiting input) and shows the question; your reply resumes it. No round is spent.

The evaluator never runs tools, so it can only judge what the agent has surfaced: the directive tells the model to run the verification the condition names (tests, lint, a build) and show the output before stopping. The agent's own goal directives are replaced by one-line markers in the evaluator's window, so instructions are never mistaken for evidence. Write conditions with one measurable end state and a stated check, as you would for the other agents' /goal commands.

To confirm which model actually judged, /goal status reports the model the provider says served the last evaluation next to the configured one: - Evaluator: glm-5.3-flash (last verdict answered by glm-5.3-flash). The provider stamps every response with the serving model, so a routed alias shows up as such (glm-5.2 … answered by glm-5.3). With ACP_GLM_DEBUG=1 the agent also logs every provider call to stderr; the evaluator is the streamChat: model=<id> … tools=0 line. Zed forwards only warnings and errors from an agent's stderr to its log, so inside Zed the status line is the check.

Command Action
/goal <condition> Set or replace the goal (up to 4,000 characters) and start the first round.
/goal --judge <model> <condition> Same, with this goal evaluated by <model> instead of the agent-wide default. <model> is an advertised model id (the session/set_model list, matched case-insensitively); an unknown id is rejected with the list.
/goal --turns <n> <condition> Same, with each round allowed up to <n> model/tool turns instead of the agent-wide default.
/goal --turns unlimited <condition> Same, with no turn limit at all; a round ends only when the model stops, you cancel, or a request fails.
/goal or /goal status Show the condition, status, rounds used, running time, turn limit, evaluator, token spend, and the last verdict with its reason. Sent while a round is running, it answers and the round picks back up — as does /usage, or any other command the agent answers itself.
/goal pause Stop auto-continuation and keep the goal.
/goal resume Continue a paused or blocked goal with a fresh round budget. --turns <n|unlimited> and --judge <model> update the paused goal before it continues, so a turn-limit pause is fixable without retyping the condition; invalid values are errors that leave the goal untouched.
/goal clear Drop the goal (stop, off, reset, cancel, and none are aliases).

Options may come before or after the condition, in any order, and both are optional: /goal --turns 300 --judge glm-5.3-flash fix the build and /goal fix the build --judge glm-5.3-flash are equivalent. A control word counts only as the whole command: /goal pause after verification is an error (/goal pause takes no arguments), never a goal with that text, and /goal resume accepts nothing but its two options. Any --word in the input is read as an option and rejected if it is not one of the two above, so a mistyped --judge Uncle Bob is an error rather than goal text; a trailing option's value runs to the end of the input. Use -- before the condition to turn option parsing off entirely, for a condition that contains --word prose or starts with a control word.

Two independent budgets bound a goal. The round budget (ACP_GLM_GOAL_MAX_ROUNDS, 20) counts how many times the evaluator sends the agent back to work. The turn limit bounds each round's own tool-calling loop, exactly as it bounds an ordinary prompt (ACP_GLM_MAX_TURNS, 100 by default). A long round — a big migration, a full test-suite fix-up — can therefore stop with [stopped: reached the 100-turn limit] and pause the goal before the evaluator ever runs. --turns <n> raises (or lowers) that limit for one goal and --turns unlimited removes it; ACP_GLM_GOAL_MAX_TURNS changes the default for every goal. /goal resume starts a fresh round with the goal's limit intact, so a goal paused on its turn limit hits the same wall again unless you set a new goal with a higher --turns.

The loop pauses itself — keeping the goal, so /goal resume continues it — when:

  • the round budget is used up (ACP_GLM_GOAL_MAX_ROUNDS, default 20 continuation rounds per activation);
  • three rounds in a row without progress — no tool call, or only questions you declined and calls you rejected (the model is answering the evaluator instead of working);
  • a round uses up its turn limit, or ends on another stop reason such as max_tokens;
  • a round dies on a thrown error — a dropped provider connection, a failed request — so the next ordinary message does not quietly restart autonomous work;
  • the evaluator cannot be reached or does not answer in the verdict format (one retry, then pause);
  • you dismiss an ask_user_question form the agent opened mid-round (paused (question dismissed): answer in a message, then /goal resume);
  • the agent ends a round with a question for you (paused (awaiting input)): reply to continue, with a fresh round budget;
  • you cancel the turn. A newer prompt sent while a round is running does not pause the goal: it supersedes the round, its own turn is judged when it ends, and the loop continues from there.

The directive tells the model not to ask you what to do next, but not to avoid questions: when a decision only you can make is blocking the work, it asks with ask_user_question when the client offers it (see Available Tools), and otherwise ends its turn with the question — the evaluator then returns needs_input, the goal waits, and your reply continues it. A question you decline completes the round — the model may proceed on a stated assumption — but it does not count as progress, and neither does a tool call you reject at the permission prompt, so a model that keeps asking or retrying a rejected edit instead of working stops after three rounds. Token spend counts every call, including failed evaluator attempts, and the usage reported for a goal prompt covers all of its rounds.

Your messages steer the goal: a plain message sent while a round is running aborts that round, runs your message's turn, judges it, and continues the loop; a reply while the goal is awaiting input resumes it with a fresh budget. Every other pause keeps needing /goal resume. Because ACP makes every prompt a turn, a command the agent answers itself — /goal status, /usage, even a mistyped /goal command — also interrupts the running round; it answers and the round then picks back up ([goal] Continuing after /usage — picking up the interrupted round), costing no round. Only /goal pause and /goal clear stop the goal. A new thread started with /goal <condition> is titled by the condition, not the command.

A goal does not change the permission mode. In default mode every edit and command of every round still prompts, so run a goal under accept_edits or bypass_permissions if you want it unattended. Each round is a normal user-role message (the client shows it as [goal 3/20] Continuing — not met yet: <reason>), which keeps the system prompt untouched and lets the goal survive context compaction. Goals are persisted with the session and restored by session/load, session/resume, and session/fork with their round counter, no-progress streak, and timer reset; the condition, status, and token spend carry over.

ACP quota extension (version 1)

Initialization advertises this custom capability in agentCapabilities._meta:

{
  "glm-acp-agent/usage": { "version": 1, "method": "_glm/usage" }
}

Clients can then send an account-level request, without creating a session:

{ "jsonrpc": "2.0", "id": 1, "method": "_glm/usage", "params": {} }

The response's result has this shape (illustrative values):

{
  "version": 1,
  "checkedAt": "2026-10-24T12:00:00.000Z",
  "stale": false,
  "windows": [{
    "id": "credit_limit-3-5",
    "label": "5-hour Model quota",
    "kind": "session",
    "windowDurationMins": 300,
    "usedPercent": 25,
    "used": 500,
    "limit": 2000,
    "remaining": 1500,
    "unit": "credits",
    "resetsAt": "2026-10-24T17:00:00.000Z"
  }]
}

kind is session, weekly, monthly, or other. usedPercent is bounded to 0–100. Duration, counts, count unit (credits or calls), and reset timestamp are optional; legacy counts intentionally have no asserted unit. checkedAt and resetsAt are UTC ISO timestamps. Window IDs identify the provider's quota type and duration; clients should replace the window list on each response.

Unavailable results include unavailable: { "reason": "…", "message": "…" }. Reasons are missingCredentials, unsupportedEndpoint, authenticationFailed, requestFailed, and invalidResponse. With cached data, stale is true and checkedAt remains the time of the last successful read; otherwise windows is empty, stale is false, and checkedAt is the attempt time. Provider bodies, keys, and raw network errors are never returned. Nonempty or invalid parameters produce JSON-RPC -32602; unknown methods produce -32601.

This extension describes account quota, not the model's context window or per-prompt token usage. It does not emit ACP usage_update. Clients such as T3 Code must explicitly implement the extension to populate native plan-limit bars; the built-in /usage command works without that integration. There is no quota request during initialization or ordinary model prompts, and no background poller.


Prerequisites

  • Node.js 20.19.0+, 22.13.0+, or 24+ (native fetch and Web Streams required)
  • npm 9 or later
  • A Z.AI API key — obtain one at https://z.ai/manage-apikey/apikey-list

Installation

Quick Start

Install the published package globally to get the glm-acp-agent command on your PATH:

npm install -g glm-acp-agent@latest

Then either export your Z.AI API key and run it directly:

export Z_AI_API_KEY=your_key_here
glm-acp-agent

…or run the interactive setup once to persist the key to disk (see One-time setup) and point any ACP-compatible client at the glm-acp-agent command.

From Source (Development)

Clone the repository if you want to hack on the agent or pin a specific commit:

git clone https://github.com/stefandevo/glm-acp-agent.git
cd glm-acp-agent
npm install
npm run build

The build output lands in dist/; the rest of this README uses node dist/index.js whenever it refers to the source-build entry point.


Configuration

The agent reads its configuration from environment variables, plus an optional credentials file written by glm-acp-agent --setup.

Variable Required Default Description
Z_AI_API_KEY One of env / --setup — API key for the Z.AI / Zhipu AI service. If unset, the credentials file is consulted.
Z_AI_ORGANIZATION_ID No — Team-seat organization ID override, used only for quota lookup (team seats are normally discovered automatically). Set together with Z_AI_PROJECT_ID; see Team-seat API keys. Falls back to the credentials file.
Z_AI_PROJECT_ID No — Team-seat project ID override (projectType: 2), used only for quota lookup. Set together with Z_AI_ORGANIZATION_ID.
ACP_GLM_MODEL No glm-5.4 Default GLM model for new sessions
ACP_GLM_AVAILABLE_MODELS No built-in list Comma-separated list of model ids advertised in session/set_model
ACP_GLM_BASE_URL No https://api.z.ai/api/coding/paas/v4 Override the API base URL
ACP_GLM_MAX_TOKENS No 32768 Cap on max_tokens for each completion. Invalid values fall back to the default with a stderr warning.
ACP_GLM_MAX_TURNS No 100 Max model turns per prompt (also settable via --max-turns). The final turn's tool calls still run and their results are saved
ACP_GLM_GOAL_MAX_ROUNDS No 20 Continuation rounds a /goal may run per activation before it pauses itself. Invalid values fall back to the default with a stderr warning.
ACP_GLM_GOAL_MAX_TURNS No ACP_GLM_MAX_TURNS (100) Model/tool turns each /goal round may take before it pauses on its turn limit; a positive integer or unlimited. A goal's --turns flag takes precedence. Invalid values fall back to the default with a stderr warning.
ACP_GLM_GOAL_JUDGE_MODEL No session model Model that evaluates /goal; must be an advertised model id. A goal's --judge <model> flag takes precedence. Invalid values are ignored with a stderr warning.
ACP_GLM_COMMAND_TIMEOUT_MS No 120000 Deadline for each run_command, in milliseconds. Invalid values fall back to the default with a stderr warning.
ACP_GLM_COMMAND_OUTPUT_LIMIT_BYTES No 65536 Maximum combined bytes captured from each run_command stdout and stderr. Further output is drained and reported as truncated. Invalid values fall back to the default with a stderr warning.
ACP_GLM_TOOL_RESULT_LIMIT_BYTES No 262144 Inclusive UTF-8 byte limit for every model-facing tool result. It preserves a prefix and suffix with an omitted-bytes marker; values below 128 fall back with a stderr warning.
ACP_GLM_READ_FILE_LIMIT_BYTES No 8388608 Maximum local bytes consumed while reading a page or whole file for edit_file. A bounded scan may not know the total line count.
ACP_GLM_LIST_FILES_MAX_ENTRIES No 2000 Maximum entries collected by list_files; larger directories return a disclosed subset.
ACP_GLM_LIST_FILES_LIMIT_BYTES No 262144 Maximum bytes assembled for a list_files result before its truncation marker.
ACP_GLM_THINKING No auto-detected Force thinking mode true / false
ACP_GLM_STREAM_THINKING No true Forward reasoning tokens to the client as agent_thought_chunk; set false to keep reasoning off the wire (the model still thinks — only the client-side stream is silenced)
ACP_GLM_STREAM_IDLE_TIMEOUT_MS No 300000 Idle deadline in milliseconds for a stalled model-provider stream read; invalid values fall back to the default with a stderr warning.
ACP_GLM_SESSION_DIR No $XDG_STATE_HOME/glm-acp-agent/sessions Where session JSON files are persisted
ACP_GLM_DEBUG No — Set to true or 1 to enable verbose debug logging to stderr (shows model selection, API key resolution, tool calls, and usage stats)
XDG_CONFIG_HOME No ~/.config Where the credentials file is read/written

One-time setup

If you'd rather not pass Z_AI_API_KEY through your ACP client's environment block, run the interactive setup once and the agent will read the key from disk on subsequent launches:

glm-acp-agent --setup

If you're working from a source clone instead of the published package, use the build output directly:

node dist/index.js --setup

The key is written to $XDG_CONFIG_HOME/glm-acp-agent/credentials.json (default: ~/.config/glm-acp-agent/credentials.json) with 0600 permissions. The Z_AI_API_KEY environment variable, when set, always wins over the file.

Setup then asks for an optional team-seat organization ID and project ID; leave both blank for a personal key or to let the agent discover the team seat. Entering only one aborts setup. See Team-seat API keys.

Supported models

The agent advertises only the models on the current Z.AI Coding Plan allowlist:

Model Notes
glm-5.4 Default. Newest flagship. Native-vision 1M-context model; thinking mode always on; 128K maximum output
glm-5.3 Previous default. 1M-context coding model; thinking mode always on; text-only (images go through Vision MCP)
glm-5.3-flash Native-vision 1M-context model; cheaper Coding Plan quota
glm-5-turbo Faster Coding Plan reasoning model; 128K context
glm-4.7 200K-context reasoning model

New sessions start on glm-5.4. Set ACP_GLM_MODEL=glm-5.3 to start them on the previous default. A loaded or resumed session keeps the model it was saved with.

The Coding Plan endpoint serves glm-5.4 under its own name. A request for it comes back with "model": "glm-5.4". Its 1M context, 128K maximum output and image input come from Z.AI's GLM-5.4 model page. Use the plain id in ACP_GLM_MODEL and ACP_GLM_AVAILABLE_MODELS. Z.AI's Claude Code guide writes the model as glm-5.4[1m], but the OpenAI-compatible Coding Plan endpoint rejects that form with business code 1211 ("Unknown Model").

Only models the Coding Plan endpoint serves under their own name are advertised. Several ids that used to be listed are now aliases: a request for glm-5.2 or glm-5.1 comes back with "model": "glm-5.3", and glm-4.5-air comes back as glm-4.7. They still work, but advertising them would report a model you are not actually talking to. Z.AI's Coding Plan overview currently also claims glm-5-turbo and glm-4.7 requests are routed to GLM-5.3-Flash; that has not been confirmed by a live probe here, so both ids stay in the picker. glm-5v-turbo is no longer on the Coding Plan allowlist — selecting it fails with business code 1311 ("subscription plan does not yet include access").

The usage_update context size comes from a built-in per-model table; ids outside it (for example custom ACP_GLM_AVAILABLE_MODELS entries) report a 128K window, so the size can be wrong for them.

ACP_GLM_AVAILABLE_MODELS lets you advertise any id you like, including the ones above. Custom ids sit outside the supported Coding Plan list — the endpoint rejects any model code Z.AI hasn't whitelisted (business code 1211). The native-vision path is unchanged, so if your plan does include glm-5v-turbo, add it back with ACP_GLM_AVAILABLE_MODELS and image blocks still reach it as native image_url content parts.

Vision-only chat models (glm-4v-plus etc.) are not advertised. glm-5.4 and glm-5.3-flash are the built-in native-vision Coding Plan models (image_url content parts). glm-5.3, glm-5-turbo, and glm-4.7 still use the Vision MCP path. glm-5v-turbo, when re-added via the override above, keeps native image_url handling as an opt-in exception.

When the model name matches glm-4.5, glm-4.6, glm-4.7, or the glm-5 family, the agent enables Z.AI's thinking: { type: "enabled" } extension and forwards reasoning tokens to the client as agent_thought_chunk blocks. This includes glm-5.3-flash and glm-5v-turbo. ACP_GLM_THINKING=false asks for plain completions on models that still accept thinking.type: "disabled" (GLM-4.7, GLM-5 Turbo). On GLM-5.4, GLM-5.3 and GLM-5.3-Flash the flag is a no-op: GLM-5.3 and Flash reject disabled, and GLM-5.4 accepts it but keeps reasoning, so the agent leaves thinking enabled rather than sending it (see Thought level below).

The provider stream itself is guarded against stalls. The Z.AI SDK's HTTP timeout only covers waiting for response headers — a response whose body stops mid-stream would otherwise hang the turn forever. The agent therefore aborts a provider stream read that produces no data for ACP_GLM_STREAM_IDLE_TIMEOUT_MS milliseconds (default 300000; invalid values for the variable fall back to the default with a stderr warning). On timeout, whatever partial output already reached the user is kept, an [error] message is appended as an agent message, the turn ends, and the last valid on-disk session checkpoint is preserved. A slow ACP client back-pressuring chunks it already received does not trip the watchdog — only silence from the provider between reads does.

A dropped network connection is handled separately from a stall. Each provider client has its own connection pool. When a request fails before an HTTP status arrives (APIConnectionError, including a connection timeout, or a socket error such as ECONNRESET), the agent closes that pool once nothing is still sending on it, and later requests open another. A retry another session already started follows that replacement, so closing the old pool does not fail the retry locally. The OpenAI client retries a failed open twice (maxRetries: 2). Those same two retries cover HTTP 408, 409, 429, and 5xx. The agent does not wrap the client in a second retry loop. If the link is still down after that budget, the turn ends with stopReason: "cancelled" instead of a JSON-RPC internal error, and the session stays open. ACP's stop reasons have no transport-failure value. cancelled is the incomplete turn: refusal would tell the client to leave this prompt out of the next one, and a thrown JSON-RPC error is what makes some clients reuse the dead connection. The user message stays in the session. When the turn produced no assistant text and no tool result, the agent also stores Connection lost before a reply was saved. Your message is still in the session. Send another message to continue. as an assistant message, and sends that same sentence as the live notice. That note is the record of the failed turn. It is not a retry id: sending the same text again appends a second user message, and sending different text continues with the original prompt still in context. Assistant text or a tool result that already arrived is kept unchanged, with no extra note. The next message continues the same session on a new connection. An HTTP status such as 400 or 401 fails the turn.

A socket reset after response bytes have started is not retried. That turn still ends with stopReason: "cancelled" and a connection-lost notice, and the text or tool result already in the session stays there. The idle-stream watchdog and an incomplete tool-call stream still fail the turn with an error and leave the previous checkpoint in place.

Cancelling a turn keeps the user's prompt whether or not the history was compacted for that request. When compaction already ran and the turn produced no assistant text or tool result, a cancel and a dropped connection both restore the pre-compaction messages and keep the prompt, so the saved checkpoint still contains the earlier exchange. A drop that already produced assistant text or a tool result keeps that shortened transcript, because the output was generated against it.

ACP_GLM_MAX_TURNS (default 100, also --max-turns) counts model turns, not tool calls. Reaching it does not cancel the turn in progress. Every tool call the model already issued in that final turn runs to completion, its real result is saved, and the prompt stops with max_turn_requests. The client notice is [stopped: reached the N-turn limit — send a message to continue (the last turn's tool results were saved)].

A user abort is a different path: session/cancel, a new session/prompt on the same session, the connection closing, or session/load / session/resume / session/close while a prompt is still draining. The executor reports each call as not started, interrupted, or completed. History keeps only calls that actually started, in their original order. A call that never ran — including one aborted while it was waiting for permission — is removed from the assistant message, and its tool card is marked failed if the client already showed it. The transcript does not gain Tool call cancelled before execution. or cancelled by turn placeholders for those calls. A call that was running when the abort arrived is saved with an explicit result: Interrupted: the user cancelled this turn while this tool was running. Its outcome is unknown and may be partial; inspect state before relying on or repeating it. A command killed mid-run keeps the output captured so far and then that marker. Every remaining tool_call has a matching tool message. If that list is shorter than the model requested, reasoning_content on that assistant message is dropped. If the abort arrives while the model is still streaming, the assistant tool_calls message is not saved; assistant text already received is kept as a plain assistant message. A tool that fails on its own, before any abort, still records Tool call not started because an earlier tool's outcome is unknown. for the calls after it.

Thought level (reasoning effort)

The agent advertises a thought_level SessionConfigOption so clients that support config options (e.g. a "Thinking" selector) can control reasoning effort per session. The available levels depend on the active model:

Model Levels Mapping to the Z.AI request
glm-5.3 (and glm-5.2 / glm-5.1, which route to 5.3) Minimal / Low / Medium / High / X-High / Max thinking: { type: "enabled" } + reasoning_effort set to the matching value
glm-5.4 Minimal / Low / Medium / High / X-High / Max Same mapping
glm-5.3-flash Low / High / Max Same mapping; Z.AI only documents these three levels for Flash
other thinking-capable models Off / On Off → thinking: { type: "disabled" }; On → thinking: { type: "enabled" }

GLM-5.4, GLM-5.3 and GLM-5.3-Flash have no Off level, because thinking cannot be turned off on them. On GLM-5.3 and GLM-5.3-Flash, sending thinking: { type: "disabled" } now errors (it is no longer a silent no-op). GLM-5.4 accepts disabled and reasoning_effort: "none" without an error, but still reasons at about its Low level. On all three the agent leaves thinking enabled rather than sending disabled, so ACP_GLM_THINKING=false is a no-op. Use glm-4.7 if you need non-reasoning completions — with the caveat that if Coding Plan really routes turbo/4.7 to Flash, a session that picks glm-4.7 + thought level Off may 4xx.

reasoning_effort takes effect on GLM-5.4 and the GLM-5.3 family; glm-5-turbo and glm-4.7 accept the field without validating it and answer identically either way, so the agent omits it for them. New sessions default to Max, which is also Z.AI's default when the field is omitted, so out-of-the-box behaviour is unchanged. Switching models re-clamps the level (an effort-ladder selection reverts to On when you move to GLM-4.7; an Off selection becomes Max on GLM-5.4 / GLM-5.3 / Flash; switching from GLM-5.3 onto Flash maps minimal→low, medium→high, xhigh→max) and pushes a config_option_update. Clients that don't support config options simply ignore the advertised option and get the default behaviour.

The endpoint validates reasoning_effort against none | minimal | low | medium | high | xhigh | max on GLM-5.3. GLM-5.3-Flash's documented values are only low | high | max, so the agent advertises that shorter ladder for Flash. none is never offered on either model.

GLM-5.4 does not validate reasoning_effort. An unknown value returns HTTP 200 and runs at the default level, max. A probe on 2026-11-23 with 16 samples per level found that GLM-5.4 and GLM-5.3 respond to the ladder the same way: minimal behaved like low, xhigh like max, and low, medium and high each produced a distinct reasoning budget. The agent therefore advertises the full ladder for GLM-5.4 too.

ACP_GLM_PROMPT_IMAGES=false still hides the image-attachment capability at session startup. With that flag set, clients should not offer image attachments at all.

Switching to a text-only model is rejected while retained conversation history contains native images. Keep an image-capable model or start a text-only session with a textual description; images are never silently discarded or analyzed as part of a model switch. During an active prompt on a native-image model, wait for the turn to finish before switching to text-only capability. Other compatible selections affect subsequent model calls, while an in-flight call keeps its captured model and reasoning level. Restored histories receive the same compatibility check before a provider request.

Vision MCP

For glm-5.4 and glm-5.3-flash (built-in) and glm-5v-turbo (opt-in via ACP_GLM_AVAILABLE_MODELS), pasted ACP image blocks with image/jpeg, image/jpg, or image/png are sent directly to chat completions as image_url content parts. A prompt without a supported image is sent as plain text, the same as on every other model. HTTPS image URLs are forwarded as URLs; inline base64 data is sent as a data:<mime>;base64,... URI. Unsupported image MIME types are rejected client-side with an inline <image_unsupported_format> annotation so the prompt can continue without a provider 4xx.

For non-native models (glm-5.3, glm-5-turbo and glm-4.7), pasted ACP image blocks are not sent to the chat-completions endpoint. Instead, the agent boots @z_ai/mcp-server over stdio (via npx -y @z_ai/mcp-server@latest) and calls its image_analysis tool. The text result is spliced into the user message as <image_analysis index="N">…</image_analysis> so the regular Coding Plan model can reason about it.

Prerequisites:

  • npx on PATH (Node 18+ / npm 9+).
  • The same Z_AI_API_KEY used for chat completions; the agent forwards it to the MCP server as Z_AI_API_KEY plus Z_AI_MODE=ZAI.

The model can also call image_analysis explicitly with { image_source: "/path/or/url", prompt?: "…" }. A non-local source requires the same ACP permission approval as web_reader before the Vision MCP call — the prompt carries the full image_source, and only bypass_permissions skips it — while local paths stay silent and are workspace-confined: a local image_source whose path or symlink target resolves outside the session workspace is rejected before any Vision MCP call. Vision failures (missing npx, MCP startup, quota) are surfaced as actionable errors but never abort the prompt; an inline <image_analysis_error> annotation is used so the conversation can continue.


Running

Standalone (stdio)

If you installed the published package globally, just run the CLI:

export Z_AI_API_KEY=your_key_here
glm-acp-agent

If you built from source, invoke the entry point directly:

export Z_AI_API_KEY=your_key_here
node dist/index.js

The agent speaks the ACP newline-delimited JSON protocol over stdin/stdout. You can connect any ACP-compatible client to it.

Development mode (watch)

When working from a source clone, run tsc in watch mode so dist/ rebuilds on every save:

export Z_AI_API_KEY=your_key_here
npm run dev        # tsc --watch

Connecting to an ACP Client

Zed (recommended for local testing)

Zed is currently the most polished editor for trying out ACP agents locally — it spawns the agent process over stdio and surfaces it in the agent panel. This is the fastest way to iterate on glm-acp-agent before publishing it to the ACP registry or to npm.

1. Prerequisites

  • A recent build of Zed that supports the agent_servers setting
  • Node.js 20.19.0+, 22.13.0+, or 24+ on your PATH (node --version)
  • A Z.AI API key — create one at https://z.ai/manage-apikey/apikey-list

2. Install the agent

Follow either path from the Installation section above:

  • Quick Start — npm install -g glm-acp-agent@latest. Zed can then spawn the agent with "command": "glm-acp-agent".

  • From source — clone, npm install, npm run build. Zed needs the absolute path to the built entry point (no ~, no $HOME shortcuts):

    echo "$(pwd)/dist/index.js"

3. Wire it into Zed

Open (or create) ~/.config/zed/settings.json and add an agent_servers entry. Pick one of the two API-key strategies below.

Option A — inline env block (simplest):

{
  "agent_servers": {
    "glm": {
      "command": "glm-acp-agent",
      "env": { "Z_AI_API_KEY": "sk-…" }
    }
  }
}

If you installed from source instead of the published package, replace command / args with the absolute path to the build output:

{
  "agent_servers": {
    "glm": {
      "command": "node",
      "args": ["/absolute/path/to/glm-acp-agent/dist/index.js"],
      "env": { "Z_AI_API_KEY": "sk-…" }
    }
  }
}

Option B — credentials file (no key in your editor settings):

Run the interactive setup once:

glm-acp-agent --setup

If you're working from a source clone, use the build output directly: node dist/index.js --setup.

The key is written to ~/.config/glm-acp-agent/credentials.json with 0600 permissions. Then drop the env block from the Zed entry — the agent will read the file on launch:

{
  "agent_servers": {
    "glm": {
      "command": "glm-acp-agent"
    }
  }
}

If Z_AI_API_KEY is set in the environment and a credentials file exists, the environment variable wins.

4. Verify it works

  1. Save settings.json. Zed reloads settings automatically.
  2. Open the agent panel (use the command palette: agent panel: toggle focus).
  3. In the agent picker, select glm — Zed labels external agents by their agent_servers key.
  4. Start a new thread and send a small prompt that exercises a tool, e.g. Read package.json and tell me the project name.
  5. You should see streaming text, a read_file tool call that runs without a permission prompt, and (with a thinking-capable model like glm-5.3) reasoning surfaced as a separate thought block. Writes and shell commands require approval in the default mode.

5. Iterating on the agent

After editing the source, rebuild:

npm run build

Zed spawns a fresh agent process per thread, so the easiest way to pick up changes is to start a new thread with the glm agent. If you see stale behavior, fully quit and reopen Zed — that guarantees no in-flight process is reused.

For a tighter inner loop, run npm run dev in a terminal so dist/ rebuilds on every save; you only need to start a new Zed thread to test the latest code.

6. Troubleshooting

  • The "glm" agent doesn't appear in the picker. — settings.json likely has a JSON parse error, or your Zed build is older than agent_servers support. Open the Zed log via the command palette (zed: open log) and look for settings errors.
  • Error: Cannot find module '/.../dist/index.js' — you skipped npm run build, or the path in args is wrong. It must be absolute and point at a file that exists.
  • No API key found. — neither Z_AI_API_KEY nor ~/.config/glm-acp-agent/credentials.json is set. Use Option A or Option B in step 3.
  • HTTP 401: Invalid API key — your key is wrong, expired, or for the wrong region. Rotate it on https://z.ai/manage-apikey/apikey-list.
  • A write or command did not run. — approve the ACP permission prompt for that tool call. Rejected or cancelled prompts are reported back to the model as skipped operations.

Neovim / VS Code / JetBrains / any ACP client

Any client that supports configuring an ACP agent via a command + args invocation works the same way:

  • If you installed via npm install -g glm-acp-agent@latest, set command to glm-acp-agent (no args required).
  • If you built from source, set command to node and args to ["/absolute/path/to/glm-acp-agent/dist/index.js"].

Supply Z_AI_API_KEY in the environment, or run glm-acp-agent --setup once so the agent reads the key from disk on launch.

Authentication

The agent advertises two authentication methods at initialize time:

  1. An agent-default method — the agent will read the API key itself, either from the Z_AI_API_KEY environment variable or from the credentials file written by glm-acp-agent --setup.
  2. An env_var method (experimental SDK extension) describing the Z_AI_API_KEY variable so capable clients can prompt the user and inject it.

ACP clients that support the auth-methods proposal will use whichever method they recognise; clients that don't handle auth methods should set Z_AI_API_KEY themselves before launching the agent (or run glm-acp-agent --setup once and let the agent read it from disk).


Project Structure

src/
├── index.ts                  # Entry point – starts stdio connection or --setup flow
├── setup.ts                  # Interactive credential setup (`--setup`)
├── llm/
│   ├── glm-client.ts         # OpenAI-compatible client for Z.AI / Zhipu AI
│   └── credentials.ts        # API-key resolution (env var > credentials.json)
├── protocol/
│   ├── connection.ts         # Sets up the ACP stdio connection
│   ├── agent.ts              # GlmAcpAgent – ACP protocol implementation
│   ├── slash-commands.ts     # Discovers .claude commands/skills; expands `/name`
│   ├── goal.ts               # /goal state, command grammar, and prompt rendering
│   ├── goal-evaluator.ts     # Tool-less evaluator model call behind /goal
│   └── session-store.ts      # On-disk persistence for load/fork/resume
├── tools/
│   ├── definitions.ts        # Tool JSON schemas (function-calling format)
│   └── executor.ts           # ToolExecutor – dispatches tool calls
└── tests/
    ├── agent.test.ts         # Protocol-level tests for GlmAcpAgent
    ├── credentials.test.ts   # Credential resolution and --setup persistence
    ├── executor.test.ts      # Tests for ToolExecutor
    ├── glm-client.test.ts    # Tests for streaming / tool-call assembly
    ├── transport-recovery.test.ts # Connection-loss retry and session recovery
    ├── slash-commands.test.ts # Command discovery and `/name` expansion
    ├── goal.test.ts          # /goal grammar, state, and rendering
    ├── goal-evaluator.test.ts # Evaluator prompt, transcript window, and verdict parsing
    ├── goal-agent.test.ts    # The /goal loop end to end through GlmAcpAgent
    └── integration.test.ts   # End-to-end tests over the real ACP ndjson transport

Building & Testing

npm run build   # one-shot TypeScript compilation → dist/
npm run dev     # watch mode
npm test        # build + run unit tests with the node:test runner

The test suite covers:

  • ACP protocol-version negotiation, capability advertising, and auth method shape
  • Session lifecycle (new / list / close, filter by cwd)
  • Prompt loop streaming, tool-call assembly, max-turn cap, cancellation, stop-reason mapping (stop → end_turn, length → max_tokens, content_filter → refusal, tool_calls exhausted → max_turn_requests)
  • Content-block conversion (text, resource_link, embedded resource)
  • Token usage reporting on the PromptResponse
  • Per-request usage_update context usage, including skipped updates and cancellation during delivery
  • Coding Plan quota parsing, cache and stale behavior, bounded failures, /usage cancellation, and extension requests over the real ACP transport
  • Tool call lifecycle (pending → in_progress → completed / failed)
  • Agent-owned local file and shell tools that work without ACP fs / terminal client capabilities
  • Permission flows for write_file and run_command (allow / reject / cancel)
  • Shell-quoted argument handling for list_files and run_command
  • GLM streaming: text deltas, reasoning_content deltas, multi-chunk tool-call assembly, and trailing usage
  • Connection loss: one retry budget for a dropped open and for HTTP 408/409/429/5xx, a cancelled turn, an unanswered prompt kept with a connection-lost note, an identical resend kept as a second user turn, partial text or a tool result kept, and the same session accepting the next prompt
  • Image preprocessing through a mocked Vision MCP client and graceful degradation on Vision MCP failures

Troubleshooting

  • No API key found. — either set Z_AI_API_KEY in the environment, or run glm-acp-agent --setup (or node dist/index.js --setup from a source clone) once to store the key on disk.
  • HTTP 401: Invalid API key — your key is wrong or expired; rotate it on https://z.ai/manage-apikey/apikey-list.
  • Connection lost before a reply was saved. Your message is still in the session. Send another message to continue. — the link to Z.AI dropped before this turn produced assistant text or a tool result. The prompt response is stopReason: "cancelled". Your message is still in the session, and this sentence is saved as an assistant note so a later load or fork shows it too. Send another message to continue. Sending the same text again adds a second copy of that prompt; it does not replace or collapse the one that was kept. Sending different text continues with the original prompt still in context.
  • Connection lost. Send a message to continue. — the link dropped after this turn already produced assistant text or a tool result. That work is still in the session, with no extra note added. Send another message to continue.
  • Writes or commands never get to run. — make sure your ACP client supports session/request_permission and that you approve the prompt for the specific tool call.

License

Apache 2.0 – see LICENSE.

About

ACP agent in TypeScript that uses the Z.AI / Zhipu AI GLM Coding Plan models (GLM-5.3, GLM-5 Turbo, GLM-4.7) as the reasoning core

www.npmjs.com/package/glm-acp-agent

Topics

acpagent-client-protocolai-agentcoding-agentglmtypescriptzaizhipu

Resources

Readme
Apache-2.0 license
Activity

Stars

84 stars

Watchers

0 watching

Forks

29 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.