Skip to content

feat(agents): add ZCode as a first-class supported agent - #13965

Open
guanbear wants to merge 6 commits into
stablyai:mainfrom
guanbear:codex/zcode-first-class
Open

feat(agents): add ZCode as a first-class supported agent#13965
guanbear wants to merge 6 commits into
stablyai:mainfrom
guanbear:codex/zcode-first-class

Conversation

@guanbear

@guanbear guanbear commented Aug 12, 2026

Copy link
Copy Markdown

ELI5

Orca can now run ZCode as a first-class agent from the agent picker and as a supervised orchestration worker, while showing its running/waiting/completed lifecycle instead of treating it as an opaque terminal process.

On macOS, Orca does not require a personal shim or the community zcode-app-cli package. It can launch the official signed ZCode Desktop runtime directly for prompted one-shot work.

When the user has independently installed an interactive zcode-app-cli on PATH, Orca detects that capability and uses its persistent TUI for supervised workers. The official Desktop runtime, remote hosts, and custom command overrides stay on the supported one-shot --prompt path.

What Changed

  • Added ZCode to desktop, web, and mobile agent catalogs, detection, launch, labels, telemetry, and process recognition.
  • Added capability-adaptive macOS launch: prefer a user-installed PATH zcode, then fall back to the official app-bundled runtime at Resources/glm/zcode.cjs for dependency-free one-shot execution.
  • Added capability-adaptive orchestration:
    • A detected local zcode-app-cli starts as a persistent TUI, receives the complete Dispatch contract as agent input, and remains observable.
    • The official runtime, remote hosts, and command overrides receive the same contract through bounded one-shot --prompt execution.
  • Added managed ZCode hook installation for local and remote SSH hosts through ~/.zcode/cli/config.json.
  • Added /hook/zcode ingestion and normalized ZCode's Claude-compatible lifecycle/tool events into Orca agent status.
  • Preserved user-authored ZCode hooks and restored the user's previous hooks.enabled value on removal.
  • Added status IPC/preload wiring, localized catalog labels, README support entries, and focused unit coverage.
  • Fixed preflight handling so unresolved absolute executable aliases are not mistaken for installed agents.

Why

ZCode users currently cannot select ZCode as a first-class Orca agent or see its lifecycle in Orca. A command-only plugin would not cover native agent selection, process detection, managed hooks, SSH installation, shared status types, or mobile support; Orca's experimental plugin manifest reserves contributes.agents, but there is no runtime Agent Provider extension point yet.

This is increasingly relevant to Orca's user base: Z.ai recently reported that ZCode reached one million users (official announcement). The number is cited as Z.ai's reported figure rather than an independently audited active-user metric.

This refreshes the intent of #10654 against current main and credits @innocarpe's earlier implementation. The current hook and agent-status architecture has moved enough that a fresh patch is easier to review than reviving the conflicting branch.

Linked Issue

Fixes #10564

Visual Behavior

Before: ZCode is absent from Orca's agent picker and its hook events are not recognized.

After: ZCode is a catalog option when either a PATH-based executable or the macOS ZCode Desktop bundle is detected. Interactive supervised workers expose their task display label and live TUI/model activity. Without an interactive PATH client, the official Desktop bundle remains the transparent one-shot fallback.

The production renderer and web client build successfully. An automated screenshot is not attached because macOS Accessibility permission is unavailable to the isolated local Electron validation process.

How To Test

macOS Desktop bundle

  1. With only /Applications/ZCode.app available, select ZCode with an initial prompt and confirm the official one-shot runtime completes without a shim or community package.
  2. Start a supervised worker with --agent zcode and confirm the one-shot worker receives the Dispatch contract and exits normally after worker_done.

Optional interactive PATH client

  1. Install an interactive zcode-app-cli on PATH and verify zcode --version includes the zcode-app-cli marker.
  2. Launch ZCode without an initial prompt and confirm its persistent TUI accepts multiple turns and supports session resume.
  3. Start a supervised worker with --agent zcode and confirm it reaches ready / input_accepted, shows the task label and live TUI activity, and keeps the zcode-cli process alive.
  4. Define a same-name shell alias or function and confirm orchestration still launches the detected executable rather than the shell override.

Other platforms and SSH

  1. Ensure a working zcode executable is on PATH.
  2. Repeat the supported PATH-client launch and orchestration checks.
  3. For SSH, install managed agent hooks on a remote host and verify ~/.zcode/cli/config.json retains existing user hook definitions.

Validation

  • Interactive zcode-app-cli PATH launch tested through a real multi-turn-capable TUI, including a completed GLM-5.2 turn and resumable session.
  • Native ZCode Desktop one-shot launch tested on macOS without relying on ~/.local/bin/zcode.
  • Official one-shot Orca orchestration smoke reached completed after worker_done.
  • Interactive Orca orchestration smoke reached ready / input_accepted, kept zcode-cli alive, exposed live model activity, and was explicitly stopped afterward.
  • Focused startup, preflight, path-resolution, current-worktree, and new-worktree orchestration tests pass.
  • Current interactive-orchestration suite: 182 tests pass.
  • Node main-process TypeScript check passes.
  • Formatting and git diff --check pass.
  • Electron/Vite production build passes.
  • TruffleHog reports the earlier review bundle clean; independent Kiro/Claude Opus 5 High review reported no actionable findings and used no fallback.

The repository-wide Vitest suite was also attempted earlier. It reaches unrelated local-environment failures in existing Zsh shell-ready, native node-pty, 7za, Electron rebuild, and performance tests; focused affected suites are green and CI remains the authoritative full matrix.

Security And Compatibility

  • Hook payloads are piped over stdin and form-encoded; the loopback endpoint requires Orca's token, and no credentials are logged or stored by this integration.
  • Installation is idempotent, removes only Orca-managed commands, preserves user hook definitions, and restores the previous global hook-enabled state.
  • macOS prefers the user's PATH executable, then falls back to the signed app bundle. Other platforms use their PATH client. Remote SSH installation uses the existing SFTP atomic config writer.
  • Interactive client detection fails closed. This PR does not bundle or require zcode-app-cli; it only uses a client the user independently placed on PATH.

Known External Limitation

ZCode Desktop 3.7.5's bundled interactive TUI currently fails because @zcode/tui is missing (zai-org/feedback#51). Orca therefore uses the official bundle for one-shot --prompt execution and only enables persistent TUI behavior when it positively detects the optional interactive PATH distribution.

AI Disclosure

Implemented with OpenAI Codex. The earlier full patch was independently reviewed by Kiro CLI using Claude Opus 5 with high reasoning; no GLM or Codex fallback was used.

Checklist

  • This PR is focused on first-class ZCode integration.
  • Adaptive interactive orchestration and the official-bundle one-shot fallback are documented.
  • No third-party ZCode CLI is bundled or made mandatory.
  • Visual behavior and the screenshot limitation are documented.
  • Self-reviewed for correctness, security, performance, and cleanup behavior.
  • Cross-platform, SSH/remote, and shell alias/function behavior considered.
  • Focused tests, typecheck, formatting, and Electron/Vite build pass; CI covers the full platform matrix.

Author

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bb150da9-3570-4566-9b27-0bd0f212ff61

📥 Commits

Reviewing files that changed from the base of the PR and between cd3772b and ad419d3.

📒 Files selected for processing (2)
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-startup.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/shared/tui-agent-startup.test.ts
  • src/shared/tui-agent-config.ts

📝 Walkthrough

Walkthrough

The pull request adds ZCode as a supported TUI and CLI agent. It defines ZCode launch, detection, labeling, telemetry, session, and hook-event behavior. It adds managed hook configuration, platform-specific scripts, local and remote installation, removal, refresh, and status reporting. Desktop, preload, and web APIs expose ZCode hook status. It adds ZCode rate-limit fetching and status-bar usage controls. It adds deferred orchestration startup for ZCode workers. Tests cover startup, lifecycle normalization, configuration preservation, installation, removal, remote setup, rate-limit handling, UI migration, and IPC status handling. Documentation and localized agent catalogs include ZCode.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also adds trae and kimi registry or API entries that are not part of #10564 or the stated ZCode objectives. Remove the unrelated trae and kimi changes, or explain why they are required dependencies and link the relevant issues.
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning No pull request description was provided, so the required change summary, rationale, linked issue, testing, visual proof, and checklist details are missing. Add a complete description using the repository template, including the linked issue, testing results, visual proof or N/A justification, AI disclosure, review notes, and checklist status.
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes cover ZCode registration, launch, lifecycle hooks, status reporting, orchestration, and user-hook preservation required by #10564.
Title check ✅ Passed The title clearly and concisely summarizes the primary change: adding ZCode as a supported agent across the application.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 698ae131-54f9-459b-9792-1959fa4825fa

📥 Commits

Reviewing files that changed from the base of the PR and between 5ea7df1 and 77a2a5f.

📒 Files selected for processing (45)
  • README.md
  • config/tsconfig.cli.json
  • docs/readme/README.es.md
  • docs/readme/README.fr.md
  • docs/readme/README.ja.md
  • docs/readme/README.ko.md
  • docs/readme/README.pt.md
  • docs/readme/README.zh-CN.md
  • mobile/src/tasks/mobile-tui-agents.ts
  • src/main/agent-hooks/managed-agent-hook-registry.ts
  • src/main/agent-hooks/managed-hook-local-filesystem.test.ts
  • src/main/agent-hooks/remote-hook-service-installers.test.ts
  • src/main/agent-hooks/remote-managed-hook-installers.ts
  • src/main/ipc/agent-hooks.test.ts
  • src/main/ipc/agent-hooks.ts
  • src/main/zcode/hook-service.test.ts
  • src/main/zcode/hook-service.ts
  • src/main/zcode/zcode-hook-config.test.ts
  • src/main/zcode/zcode-hook-config.ts
  • src/preload/api-types.ts
  • src/preload/index.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/lib/agent-catalog.tsx
  • src/renderer/src/lib/agent-status.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/shared/agent-hook-listener.test.ts
  • src/shared/agent-hook-listener.ts
  • src/shared/agent-hook-relay.ts
  • src/shared/agent-hook-types.ts
  • src/shared/agent-kind.ts
  • src/shared/agent-name-token-match.ts
  • src/shared/agent-session-resume.ts
  • src/shared/agent-status-types.ts
  • src/shared/agent-type-label.ts
  • src/shared/skills-cli-agent-keys.ts
  • src/shared/telemetry-events.ts
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-display-names.ts
  • src/shared/tui-agent-selection.ts
  • src/shared/tui-agent-startup.test.ts
  • src/shared/types.ts

Comment thread src/main/zcode/hook-service.test.ts Outdated
Comment thread src/main/zcode/zcode-hook-config.ts Outdated
Comment thread src/shared/agent-name-token-match.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.ts (1)

21919-21941: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract the repeated deferred-agent-terminal creation block into a shared helper.

The try/catch block that calls createDeferredAgentTerminal and records the startup terminal fields repeats three times, once per creation branch (folder-repo, local-git, remote). Each copy differs only in the target worktreeSelector/worktreePath and in whether the result is stored in a startupTerminal object or in separate startupTerminalHandle/startupTerminalTabId/startupTerminalPaneKey/startupTerminalPtyId variables.

Extract a private helper that takes the worktree id, path, agent, launch preferences, and a warning-message template, and returns either the created terminal or a warning string. Call it from all three sites to keep the failure-warning wording and spawn logic in one place.

♻️ Sketch of a shared helper
private async spawnDeferredAgentTerminal(
  worktreeSelector: string,
  worktreePath: string,
  args: { startupAgent: TuiAgent; startupLaunchPreferences?: AgentLaunchPreferences }
): Promise<
  | { terminal: RuntimeTerminalCreate; warning?: undefined }
  | { terminal?: undefined; warning: string }
> {
  try {
    const terminal = await this.createDeferredAgentTerminal(worktreeSelector, {
      agent: args.startupAgent,
      ...(args.startupLaunchPreferences
        ? { launchPreferences: args.startupLaunchPreferences }
        : {}),
      surfaceOwner: false
    })
    return { terminal }
  } catch (err) {
    const message = err instanceof Error ? err.message : String(err)
    return {
      warning: `Failed to create the deferred agent terminal for ${worktreePath}: ${message}`
    }
  }
}

Also applies to: 22694-22714, 23064-23083


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3e815c5b-fb1e-4d7b-8b3f-d592627e7cc8

📥 Commits

Reviewing files that changed from the base of the PR and between bdb38ac and cd3772b.

📒 Files selected for processing (11)
  • src/main/ipc/preflight.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orchestration/preamble.test.ts
  • src/main/runtime/orchestration/preamble.ts
  • src/main/runtime/rpc/methods/orchestration-worker-topology.ts
  • src/main/runtime/rpc/methods/orchestration-workers-new-worktree.test.ts
  • src/main/runtime/rpc/methods/orchestration-workers.ts
  • src/main/runtime/rpc/methods/orchestration.test.ts
  • src/shared/local-agent-install-dir-detection.ts
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-startup.test.ts

)
}
let terminalHandle = params.terminal
let promptDelivery: 'agent-input' | 'startup-command' = 'agent-input'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Handle explicit ZCode terminals with startup-command delivery.

If params.terminal is set for ZCode, promptDelivery remains 'agent-input'. Lines 241-248 then call sendTerminalAgentPrompt instead of sendTerminalAgentStartupPrompt.

Select the delivery mode from requiresOrchestrationStartupPrompt(agent) before the explicit-terminal branch. If an existing terminal cannot support startup-command delivery, reject --terminal for this agent instead of marking a worker ready with an undeliverable dispatch. Add a regression test for agent: 'zcode' with terminal set.

Also applies to: 241-248

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Add ZCode (Z.ai / GLM-5.2) as a first-class supported agent

1 participant