Skip to content

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

Open
innocarpe wants to merge 3 commits into
stablyai:mainfrom
innocarpe:fix/zcode-first-class-agent
Open

feat(agents): add ZCode as first-class supported agent#10654
innocarpe wants to merge 3 commits into
stablyai:mainfrom
innocarpe:fix/zcode-first-class-agent

Conversation

@innocarpe

@innocarpe innocarpe commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Register ZCode as a TuiAgent (detect/launch zcode, catalog, labels, telemetry).
  • Managed hook bridge: install zcode-hook.sh and wire ZCode local process hooks to Orca's HTTP listener (POST /hook/zcode).
  • Claude-compatible lifecycle events normalize to agentType: 'zcode'.

Fixes

Closes #10564

Notes / residual

  • ZCode only supports local subprocess hooks; native HTTP hooks do not exist.
  • Upstream Z.ai bug may prevent native-agent hook fire (zai-org/feedback#32).
  • Desktop app installs may lack zcode on PATH — use cmd override if needed.

Test plan

  • zcode hook-service / agent-hook-listener / agent-hooks IPC / selection tests
  • Manual: install zcode CLI, select ZCode agent, confirm launch + status if hooks fire

ELI5

ZCode is registered as a first-class Orca agent with detection, launch, hooks, and telemetry so ZCode users can run it managed like Claude or Codex.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: feac5eca-1ab4-4cb1-ace8-80b019207a12

📥 Commits

Reviewing files that changed from the base of the PR and between 4b8066a and 1c9de90.

📒 Files selected for processing (2)
  • src/main/agent-hooks/remote-hook-service-installers.test.ts
  • src/shared/agent-session-resume.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/shared/agent-session-resume.ts
  • src/main/agent-hooks/remote-hook-service-installers.test.ts

📝 Walkthrough

Walkthrough

Added ZCode to shared agent types, labels, catalog metadata, selection order, telemetry mappings, mobile configuration, and translated documentation. Implemented ZCode lifecycle event normalization and /hook/zcode routing. Added local, remote, and removal hook management with configuration preservation and idempotency tests. Registered ZCode in managed hook controls, IPC status handlers, preload APIs, web fallbacks, and remote installer coverage.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary, testing, and notes, but misses required Screenshots, AI Review Report, and Security Audit sections. Add the missing template sections, or state 'No visual change' for Screenshots, plus AI Review Report and Security Audit details.
Docstring Coverage ⚠️ Warning Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the change: ZCode is added as a first-class supported agent.
Linked Issues check ✅ Passed [#10564] ZCode is added to agent selection, hook bridging, lifecycle normalization, and status reporting as requested.
Out of Scope Changes check ✅ Passed The changes stay focused on ZCode agent support; docs, locales, tests, IPC, and hook updates all align with the stated objectives.

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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 698af32e-ec42-4583-9a4e-19e4fa1eaac1

📥 Commits

Reviewing files that changed from the base of the PR and between daba81e and b6bd952.

📒 Files selected for processing (43)
  • README.md
  • 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/agent-hook-memory-sftp.test-fixture.ts
  • src/main/agent-hooks/managed-agent-hook-controls.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.test.ts
  • 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/telemetry-events.ts
  • src/shared/tui-agent-config.ts
  • src/shared/tui-agent-display-names.ts
  • src/shared/tui-agent-selection.ts
  • src/shared/types.ts

Comment thread src/main/zcode/zcode-hook-config.ts
Comment thread src/main/zcode/zcode-hook-config.ts
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (d9edc515b)

Address CodeRabbit: SessionStart event + restore hooks.enabled on remove

@nwparker nwparker added the enhancement New feature or request label Jul 27, 2026
@innocarpe
innocarpe force-pushed the fix/zcode-first-class-agent branch 2 times, most recently from c31b485 to 83fa941 Compare July 28, 2026 13:12
Register Z.ai ZCode (GLM) as a launchable TuiAgent with PATH detection
(`zcode`), agent catalog / labels, telemetry agent_kind, and managed
status hooks that POST to /hook/zcode.

Hook installer writes zcode-hook.sh under ~/.orca/agent-hooks and
registers Claude-compatible lifecycle events in
~/.zcode/cli/config.json (hooks.enabled + hooks.events), bridging
ZCode's local subprocess hook protocol to Orca's HTTP endpoint.

Residual blockers (documented for follow-up; not fixed here):
- ZCode hooks are process/command only (no native HTTP/webhook). The
  managed script is the bridge; status only works when ZCode actually
  fires configured hooks.
- zai-org/feedback#32: native/built-in ZCode agent may not fire
  hooks.events; only external CLI sub-agents currently trigger them.
- Desktop installs often lack a standalone `zcode` binary on PATH
  (app-only); detection then leaves the agent available but not
  auto-picked until the CLI is present or a cmd override is set.

Closes stablyai#10564
CodeRabbit: SessionStart is a documented ZCode lifecycle event, and
remove() left hooks.enabled forced true after managed install. Stash
the pre-install value and restore it when managed hooks are removed.
@innocarpe
innocarpe force-pushed the fix/zcode-first-class-agent branch from 83fa941 to 4b8066a Compare July 29, 2026 01:03
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (4b8066a59)

Rebase onto upstream/main to clear merge conflicts

@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/agent-hooks/remote-hook-service-installers.test.ts (1)

425-426: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert SessionStart is installed.

SessionStart is a required lifecycle event and was called out as a prior regression; this test currently cannot catch its removal.

Proposed fix
+    expect(config.hooks?.events?.SessionStart).toBeDefined()
     expect(config.hooks?.events?.UserPromptSubmit).toBeDefined()

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 174907a1-12b9-49fe-961f-125d34f32ac7

📥 Commits

Reviewing files that changed from the base of the PR and between c31b485 and 4b8066a.

📒 Files selected for processing (12)
  • README.md
  • 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/agent-hook-memory-sftp.test-fixture.ts
  • src/main/agent-hooks/managed-agent-hook-controls.ts
  • src/main/agent-hooks/remote-hook-service-installers.test.ts
  • src/main/agent-hooks/remote-managed-hook-installers.ts
🚧 Files skipped from review as they are similar to previous changes (8)
  • docs/readme/README.zh-CN.md
  • src/main/agent-hooks/remote-managed-hook-installers.ts
  • docs/readme/README.es.md
  • docs/readme/README.ko.md
  • docs/readme/README.pt.md
  • docs/readme/README.ja.md
  • mobile/src/tasks/mobile-tui-agents.ts
  • src/main/agent-hooks/agent-hook-memory-sftp.test-fixture.ts

Comment thread src/main/agent-hooks/remote-hook-service-installers.test.ts Outdated
Comment thread src/main/agent-hooks/remote-hook-service-installers.test.ts Outdated
Comment thread src/shared/agent-session-resume.ts
@greptile-apps

greptile-apps Bot commented Jul 29, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds ZCode (Z.ai) as a first-class TuiAgent in Orca — registering it alongside Claude, Codex, Kimi, etc. with detection, launch config, hook installation, lifecycle event normalization, and telemetry. The implementation follows the same pattern as the recently-added Kimi integration and takes the opportunity to refactor agent-hooks.ts from 14 copy-pasted IPC handlers into a single data-driven loop.

  • Hook service (src/main/zcode/): Installs zcode-hook.sh into ~/.zcode/cli/config.json under hooks.events, forces hooks.enabled = true (stashing the prior value for restore on remove()), and exposes install / remove / installRemote / getStatus.
  • Lifecycle normalization (agent-hook-listener.ts): Extracts shared normalizeClaudeCompatibleAgentEvent for both kimi and zcode, wires /hook/zcode endpoint, and dispatches UserPromptSubmit → working, PermissionRequest → waiting, Stop → done.
  • Registration: TuiAgent, WellKnownAgentType, AGENT_HOOK_TARGETS, agent-catalog, display names, telemetry schema, selection order, and preload API are all updated consistently.

Confidence Score: 5/5

Safe to merge. The ZCode integration follows the identical pattern as all other recently-added TUI agents, and the concurrent refactor of agent-hooks.ts reduces copy-paste risk going forward.

All shared registration points (TuiAgent, WellKnownAgentType, AGENT_HOOK_TARGETS, telemetry schema, display names, selection order, preload API) are updated consistently. The hook service is well-tested with idempotency, user-config preservation, and enabled-flag restoration covered. The IPC refactor is a mechanical extraction with no logic change. The two findings are style nits with no user-visible impact.

Files Needing Attention: No files require special attention. The new src/main/zcode/ files are the most novel code but have good test coverage.

Important Files Changed

Filename Overview
src/main/zcode/hook-service.ts New ZCode hook service: install/remove/getStatus/installRemote, generates zcode-hook.sh. Dead-code duplicate in buildStatus() for present.size===0 (both branches set state='not_installed').
src/main/zcode/zcode-hook-config.ts New ZCode hook config: apply/remove/read managed hooks into hooks.events JSON. Well-tested idempotent logic; preserves user hooks and restores pre-install enabled flag.
src/shared/agent-hook-listener.ts Refactors normalizeKimiEvent into shared normalizeClaudeCompatibleAgentEvent; adds normalizeZcodeEvent and /hook/zcode endpoint. Logic is clean and consistent with kimi path.
src/main/ipc/agent-hooks.ts Replaces 14 copy-pasted IPC handler blocks with a data-driven AGENT_HOOK_STATUS_HANDLERS table and shared registerAgentHookStatusHandler; adds zcode entry. Cleaner and removes ~200 LOC of duplication.
src/main/zcode/hook-service.test.ts New test file: covers not_installed, install, reinstall idempotency, user-config preservation, and remove with enabled-flag restoration. Solid coverage.
src/main/agent-hooks/remote-hook-service-installers.test.ts Extracts inline FakeFs/createFakeSftp to shared fixture (createAgentHookMemorySftp); adds ZcodeHookService to invariant checks. Reduces duplication.
src/shared/agent-status-types.ts Adds kimi (pre-existing omission) and zcode to WellKnownAgentType; straightforward type extension.
src/shared/agent-session-resume.ts Adds zcode to the switch case that reads Claude-compatible session_id; uses falls-through pattern consistent with kimi.
src/main/agent-hooks/agent-hook-memory-sftp.test-fixture.ts Promotes inline FakeFs / createFakeSftp to a shared test fixture with failRenameTo; no logic changes.

Sequence Diagram

sequenceDiagram
    participant ZCode as ZCode CLI Process
    participant Script as zcode-hook.sh
    participant HTTP as Orca HTTP Listener /hook/zcode
    participant Listener as agent-hook-listener normalizeZcodeEvent
    participant IPC as IPC agentHooks:zcodeStatus
    participant UI as Renderer / Sidebar

    Note over ZCode,Script: On each hook event (UserPromptSubmit, PreToolUse, etc.)
    ZCode->>Script: executes managed script via hooks.events
    Script->>HTTP: POST /hook/zcode with paneKey, payload, token
    HTTP->>Listener: "normalizeHookPayload(source='zcode', ...)"
    Listener->>Listener: normalizeZcodeEvent() → normalizeClaudeCompatibleAgentEvent()
    Listener-->>UI: AgentStatusEntry (state: working/waiting/done)

    Note over IPC,UI: On sidebar open / refresh
    UI->>IPC: agentHooks:zcodeStatus IPC
    IPC->>IPC: zcodeHookService.getStatus() reads ~/.zcode/cli/config.json
    IPC-->>UI: AgentHookInstallStatus (installed/partial/not_installed/error)
Loading

Reviews (2): Last reviewed commit: "fix(zcode): repair broken openclaude imp..." | Re-trigger Greptile

CodeRabbit/Greptile: unterminated string on openClaudeHookService import
broke the whole test file; indent falls-through comment for kimi→zcode.

Co-Authored-By: Grok Companion <noreply@x.ai>
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (1c9de9065)

Address review: fix unterminated import + falls-through indent

@guanbear

Copy link
Copy Markdown

Fresh empirical validation against ZCode Desktop 3.7.5 / bundled CLI 0.16.1 / macOS arm64:

Hooks and subagent lifecycle do work

A user-level ~/.zcode/cli/config.json hook using the PR's shell-command form fired these events in a new native ZCode headless session:

SessionStart
UserPromptSubmit
PreToolUse   tool_name=Agent
PostToolUse  tool_name=Agent
Stop

For an internally dispatched Explore subagent, PreToolUse.tool_input included description, prompt, and subagent_type; PostToolUse.tool_response included status, agentId, agentType, description, totalDurationMs, totalTokens, usage, and final content. This is sufficient for Orca to surface a bounded subagent running/completed row. ZCode does not emit the child's individual tool/model events through the parent hook, so live child transcript/pane rendering is not available through this hook bridge alone.

Launch remains blocked for desktop-only installs

The app does not install zcode on PATH, and invoking its exact bundled entry point either bare or with tui fails with:

Cannot find package '@zcode/tui' imported from /Applications/ZCode.app/Contents/Resources/glm/zcode.cjs\n```\n\nHeadless `--prompt --json --cwd --mode --resume` works, but it is not an interactive TUI. Also, the comment in `tui-agent-config.ts` saying there is no stable headless prompt flag is now stale. The bundle advertises `--settings` and `--max-turns`, though 0.16.1 currently rejects both as unknown options. Upstream packaging evidence is tracked in zai-org/feedback#51.\n\nThe PR is currently conflicting and its manual launch checkbox is still open. I recommend rebasing and keeping detection conservative: do not report ZCode as launchable merely because `ZCode.app` exists; require a working `zcode` TUI executable/self-check. If headless execution is desired, it should be a separate runner path rather than `TuiAgent.launchCmd = zcode`. The hook bridge itself matches the current runtime contract.

@guanbear

Copy link
Copy Markdown

I opened #13965 as a current-main refresh of this ZCode integration. It preserves the original first-class-agent intent from @innocarpe's work here, while adapting it to Orca's newer managed hook registry, agent-status listener, SSH installer, IPC/preload, mobile, and localization architecture. Thank you for establishing the original direction.

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

Labels

enhancement New feature or request

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

4 participants