Skip to content

feat(zero): add Zero target - #3992

Merged
dyoshikawa merged 6 commits into
mainfrom
resolve-issue-3807-zero-target
Nov 26, 2026
Merged

dyoshikawa merged 6 commits into
mainfrom
resolve-issue-3807-zero-target

Conversation

@dyoshikawa

@dyoshikawa dyoshikawa commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a zero target for Zero (Twigpine/zero, MIT, Go terminal coding agent). It covers rules, MCP, subagents (Zero's "specialists"), hooks and skills (global only). Paths and formats were checked against docs/EXTENDING.md, docs/SPECIALISTS.md and the Go source: internal/agent/system_prompt.go, internal/config/paths.go, internal/mcp/config.go, internal/hooks/hooks.go, internal/agent/loop.go, internal/specialist/manifest.go, internal/skills/skills.go and internal/tools/*.

Changes

Feature Project Global (--global)
rules ZERO.md ~/.config/zero/ZERO.md
mcp .zero/config.json → mcp.servers ~/.config/zero/config.json
subagents .zero/specialists/<name>.md ~/.config/zero/specialists/<name>.md
hooks .zero/hooks.json ~/.config/zero/hooks.json
skills — (Zero has no project skills) ~/.local/share/zero/skills/<name>/SKILL.md

On Windows the user config dir is %AppData%\zero (~/AppData/Roaming/zero). Zero uses ~/.config on macOS as well. The skills root is ~/.local/share/zero/skills on every platform.

  • New src/constants/zero-paths.ts, plus zero-rule.ts, zero-mcp.ts, zero-subagent.ts, zero-hooks.ts and zero-skill.ts, each with unit tests.
  • The target is registered in the tool tuples, the display table, the processors, types/hooks.ts (event map and the zero.hooks override key), the shared-config ownership table and SHARED_USER_MANAGED_CONFIG_PATHS.
  • E2E happy paths are added for every Tool × Feature pair: rules (generate, global, import), MCP (generate, global, import), subagents (generate, global, import, orphan), hooks (generate, global, import) and skills (global).
  • Docs: Zero notes in file-formats.md. The README / supported-tools tables, the docs content, .gitignore and cspell are regenerated.

Design decisions

  • Hook matchers are translated, so a shared Bash guard does not fail open. In Zero a matcher is an exact, case-sensitive name or a * glob, with no regex and no alternation (matchesHookMatcher in internal/hooks/hooks.go). It is checked against Zero's lowercase tool names. The translations are:

    • Bash → bash + exec_command + write_stdin (all of Zero's default shell tools)
    • Read → read_file + read_minified_file
    • Write → write_file
    • Edit / MultiEdit → edit_file + apply_patch
    • Glob / Grep → glob / grep
    • LS → list_directory
    • WebFetch / WebSearch → web_fetch / web_search
    • Skill → skill
    • AskUserQuestion → ask_user
    • mcp__srv__tool → mcp_srv_tool
    • .* → *, and a glob is expanded over the canonical names (Bash.* covers the same shell tools)

    An alternation such as Write|Edit becomes one Zero hook per name, and import folds those back into one matcher. A preToolUse guard fails closed: when its matcher needs regex syntax Zero cannot express, or is a glob matching no Zero tool, it is written without a matcher (so it runs before every tool call), with a warning. On other events such a matcher is skipped with a warning. An exact name with no Zero counterpart is written as-is with a warning.

  • Hook commands are written as command: "sh", args: ["-c", <cmd>], because Zero hands command/args to exec.CommandContext without a shell. Import unwraps them.

  • Hook ids are rulesync-<project|user>-<event>-<NNN>. Zero merges the user and project layers by id, and the project wins (mergeLayers), so identical ids would let a project hook silently replace a user hook. Zero also runs hooks in id order, and the zero-padded counter keeps that order equal to the authored order.

  • hooks.json is merged, never deleted. zero hooks writes the same file, so generation keeps every entry whose id does not start with rulesync-, and it does not generate an entry identical (event, matcher, command line, enabled) to one of them, so import followed by generate never runs a hand-written hook twice. The top-level enabled is kept as found and never added, because a layer that states it overrides the other layer. It refuses to rewrite unparseable JSON, and isDeletable() is false in both scopes. The project file is listed as user-managed, so it is not gitignored.

  • localRoot folds into ZERO.md, not .zero/AGENTS.md (refines the triage plan). Zero reads only the first of AGENTS.md, ZERO.md and .zero/AGENTS.md per directory (findProjectContextFile). A .zero/AGENTS.md next to the generated ZERO.md would never be read.

  • Root ZERO.md is always written. Generation warns when an AGENTS.md already sits next to it, because Zero would read that file instead. An 8 KiB projectInstructionBudget matches Zero's per-file cap.

  • MCP: rulesync owns the mcp key of config.json (siblings are carried over) and keeps every other key. The file is never deleted. Only the documented transports (stdio, http) are written; SSE and WebSocket servers are skipped with a warning. Names outside Zero's ^[A-Za-z0-9._-]+$ are skipped too, because one invalid server makes Zero refuse all of them. ${VAR} references get a "written literally" warning, since Zero does no env expansion. auth: "oauth" and disabled round-trip; a server's oauth block is imported as the namespaced zeroOauth key (stripped from other tools, like zcodeOauth) and written back as oauth, and unmanaged keys of a same-named existing server are carried over.

  • Subagents: only name, description and the zero: section's extends, model, reasoningEffort and tools are written. A shared model is not passed through, because Zero rejects unknown models. Zero's frontmatter parser is line-based and accepts tools only as a list. The tools: read-only,plan example in EXTENDING.md would actually fail with "tools must be an array". So values are kept on one line, and a comma string in zero.tools is split into a list. rulesync warns when a name is not a lowercase id or a required description is missing.

  • Skills: global-only (supportsProject: false), reusing AgentsSkillsSkill. The skills processor writes one-line frontmatter for zero, as it does for Cursor, because Zero's skill frontmatter parser is line-based.

Skipped

  • .zero/plugins/<id>/plugin.json bundles: possibly a later zero-plugin target.
  • commands, ignore, permissions: Zero documents no file surface for them.
  • Hook timeout: Zero has no per-hook timeout, so it is ignored with a warning.
  • Zero's undocumented sse MCP transport (it exists in internal/mcp/config.go): skipped to stay on documented surfaces.
  • $XDG_CONFIG_HOME / $XDG_DATA_HOME / $ZERO_SKILLS_DIR overrides are not followed; global output goes to the default locations.

Closes #3807

🤖 Generated with Claude Code

https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4

dyoshikawa and others added 6 commits November 26, 2026 16:59
Add a `zero` target for Zero (Twigpine/zero) covering rules, MCP,
subagents (specialists), hooks and global-only skills, following the
documented `.zero/` / `~/.config/zero/` layout and Zero's source.

- rules: `ZERO.md` at the project root and `<user config dir>/zero/ZERO.md`;
  topic and localRoot rules fold into it, with a warning when an
  `AGENTS.md` shadows it and an 8 KiB budget warning.
- mcp: `mcp.servers` of `.zero/config.json` / the user `config.json`,
  merged without touching other keys (stdio and http only).
- subagents: `.zero/specialists/*.md` with one-line frontmatter and
  `tools` always written as a list.
- hooks: flat `hooks.json` list with `sh -c` commands, matchers
  translated to Zero's lowercase tool names (`Bash` -> `bash`,
  alternations split per tool), scope-prefixed ids, and hand-written
  entries kept.
- skills: `~/.local/share/zero/skills/` (Zero has no project skills).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
- Map `Bash` to all of Zero's default shell tools (`bash`,
  `exec_command`, `write_stdin`) so a shared guard is not bypassed.
- Expand `*` globs over the canonical names; a `preToolUse` guard whose
  matcher Zero cannot express or whose glob matches no Zero tool is
  written without a matcher (runs on every tool) instead of skipped.
- Do not generate an entry identical to a kept hand-written hook, so
  import followed by generate does not run it twice.
- Never add a top-level `enabled` to hooks.json, which would override
  the user layer's flag.
- Round-trip Zero's MCP `oauth` as the namespaced `zeroOauth` key and
  keep unmanaged keys of existing servers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…ro-target

# Conflicts:
#	src/generated/docs-content.ts
- Cover `terminal_session` with `Bash` and map `Agent` to `Task`.
- Fail closed for a `preToolUse` guard naming an exact tool Zero lacks.
- Warn that a native `bash` guard leaves the other shell tools uncovered.
- Keep a lowercase glob beside its canonical expansion.
- Drop an existing MCP `oauth` block when the server url changed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…ro-target

# Conflicts:
#	src/generated/docs-content.ts
…ro-target

# Conflicts:
#	src/generated/docs-content.ts
@dyoshikawa
dyoshikawa merged commit e6b1525 into main Nov 26, 2026
10 checks passed
@dyoshikawa
dyoshikawa deleted the resolve-issue-3807-zero-target branch November 26, 2026 09:23
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.

Propose a Zero target: .zero/ hooks.json, config.json MCP, specialists, ZERO.md

1 participant