From d20ba5784a7e1d170e5f7d0b03c1e0679fd0abc6 Mon Sep 17 00:00:00 2001 From: Alex Kesling Date: Wed, 13 May 2026 14:18:34 -0400 Subject: [PATCH] fix(publish): embed agent and session-context resources inside the clash crate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The published clash crate referenced files via include_str! that lived outside the package boundary (docs/, clash-amazonq/, clash-codex/, clash-copilot/, clash-gemini-ext/, clash-opencode/) and were reached at build time through symlinks inside clash/. cargo package skips symlinks pointing outside the package, so the v0.7.1 tarball on crates.io was missing every include_str! target and `cargo install clash` failed. Move the embedded assets to where they belong: alongside the code that embeds them. Per-agent install templates now live at clash/src/agent_templates//, and session-context.md sits next to the handler that returns it. The five workspace-root clash-/ directories existed only as sources for include_str! — no script, package, or CI step consumed them — so they're removed entirely. The top-level docs/ directory keeps its workspace-level content intact; only session-context.md (the one file the clash binary actually embeds) moves into the crate. No symlinks remain. No package include allowlist changes are needed — everything ships via the existing src/**/* glob. Prose references in AGENTS.md and docs/multi-agent.md are updated to point at the new location. --- AGENTS.md | 6 +----- .../src/agent_templates/amazonq}/agent.json | 0 .../src/agent_templates/codex}/hooks.toml | 0 .../src/agent_templates/copilot}/pre-tool-use.json | 0 .../src/agent_templates/gemini}/GEMINI.md | 0 .../agent_templates/gemini}/gemini-extension.json | 0 .../src/agent_templates/gemini}/hooks.json | 0 .../src/agent_templates/opencode}/plugin.ts | 0 clash/src/cmd/init.rs | 13 ++++++------- clash/src/handlers.rs | 2 +- {docs => clash/src}/session-context.md | 0 docs/multi-agent.md | 14 +++++++------- 12 files changed, 15 insertions(+), 20 deletions(-) rename {clash-amazonq => clash/src/agent_templates/amazonq}/agent.json (100%) rename {clash-codex => clash/src/agent_templates/codex}/hooks.toml (100%) rename {clash-copilot/.github/hooks => clash/src/agent_templates/copilot}/pre-tool-use.json (100%) rename {clash-gemini-ext => clash/src/agent_templates/gemini}/GEMINI.md (100%) rename {clash-gemini-ext => clash/src/agent_templates/gemini}/gemini-extension.json (100%) rename {clash-gemini-ext/hooks => clash/src/agent_templates/gemini}/hooks.json (100%) rename {clash-opencode => clash/src/agent_templates/opencode}/plugin.ts (100%) rename {docs => clash/src}/session-context.md (100%) diff --git a/AGENTS.md b/AGENTS.md index 6ebe160..c10d324 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -69,11 +69,7 @@ * *clash-policy* Policy language: parsing, IR, compilation, and evaluation (extracted from `clash` to break circular dep with `clash-lsp`) * *clash_starlark* Starlark policy evaluator — compiles `.star` files to JSON policy format * *clash-plugin* Claude Code plugin (hooks.json, .claude-plugin definitions) -* *clash-gemini-ext* Gemini CLI extension package -* *clash-codex* Codex CLI hook configuration -* *clash-amazonq* Amazon Q CLI agent hook configuration -* *clash-opencode* OpenCode TypeScript plugin -* *clash-copilot* Copilot CLI hook configuration +* *clash/src/agent_templates* Embedded per-agent install assets (Gemini extension, Codex/Amazon Q/Copilot hooks, OpenCode plugin) — shipped inside the `clash` binary and written out by `clash init --agent ` * *clash_notify* Helper crate for extended notifications outside of the terminal * *claude_settings* Helper crate for interacting with a user's ".claude" settings directories * *clash-brush-parser* Shell command parser diff --git a/clash-amazonq/agent.json b/clash/src/agent_templates/amazonq/agent.json similarity index 100% rename from clash-amazonq/agent.json rename to clash/src/agent_templates/amazonq/agent.json diff --git a/clash-codex/hooks.toml b/clash/src/agent_templates/codex/hooks.toml similarity index 100% rename from clash-codex/hooks.toml rename to clash/src/agent_templates/codex/hooks.toml diff --git a/clash-copilot/.github/hooks/pre-tool-use.json b/clash/src/agent_templates/copilot/pre-tool-use.json similarity index 100% rename from clash-copilot/.github/hooks/pre-tool-use.json rename to clash/src/agent_templates/copilot/pre-tool-use.json diff --git a/clash-gemini-ext/GEMINI.md b/clash/src/agent_templates/gemini/GEMINI.md similarity index 100% rename from clash-gemini-ext/GEMINI.md rename to clash/src/agent_templates/gemini/GEMINI.md diff --git a/clash-gemini-ext/gemini-extension.json b/clash/src/agent_templates/gemini/gemini-extension.json similarity index 100% rename from clash-gemini-ext/gemini-extension.json rename to clash/src/agent_templates/gemini/gemini-extension.json diff --git a/clash-gemini-ext/hooks/hooks.json b/clash/src/agent_templates/gemini/hooks.json similarity index 100% rename from clash-gemini-ext/hooks/hooks.json rename to clash/src/agent_templates/gemini/hooks.json diff --git a/clash-opencode/plugin.ts b/clash/src/agent_templates/opencode/plugin.ts similarity index 100% rename from clash-opencode/plugin.ts rename to clash/src/agent_templates/opencode/plugin.ts diff --git a/clash/src/cmd/init.rs b/clash/src/cmd/init.rs index e1c8478..13de1e1 100644 --- a/clash/src/cmd/init.rs +++ b/clash/src/cmd/init.rs @@ -22,13 +22,12 @@ const HOOK_CMD_PREFIX: &str = "clash hook"; /// Embedded agent plugin files — compiled into the binary so `clash init --agent ` /// can install them without needing the source repo. -const OPENCODE_PLUGIN_TS: &str = include_str!("../../clash-opencode/plugin.ts"); -const COPILOT_HOOKS_JSON: &str = - include_str!("../../clash-copilot/.github/hooks/pre-tool-use.json"); -const CODEX_HOOKS_TOML: &str = include_str!("../../clash-codex/hooks.toml"); -const AMAZONQ_AGENT_JSON: &str = include_str!("../../clash-amazonq/agent.json"); -const GEMINI_EXTENSION_JSON: &str = include_str!("../../clash-gemini-ext/gemini-extension.json"); -const GEMINI_HOOKS_JSON: &str = include_str!("../../clash-gemini-ext/hooks/hooks.json"); +const OPENCODE_PLUGIN_TS: &str = include_str!("../agent_templates/opencode/plugin.ts"); +const COPILOT_HOOKS_JSON: &str = include_str!("../agent_templates/copilot/pre-tool-use.json"); +const CODEX_HOOKS_TOML: &str = include_str!("../agent_templates/codex/hooks.toml"); +const AMAZONQ_AGENT_JSON: &str = include_str!("../agent_templates/amazonq/agent.json"); +const GEMINI_EXTENSION_JSON: &str = include_str!("../agent_templates/gemini/gemini-extension.json"); +const GEMINI_HOOKS_JSON: &str = include_str!("../agent_templates/gemini/hooks.json"); /// Initialize clash at the chosen scope. /// diff --git a/clash/src/handlers.rs b/clash/src/handlers.rs index 07f285c..ef632c4 100644 --- a/clash/src/handlers.rs +++ b/clash/src/handlers.rs @@ -261,7 +261,7 @@ pub fn handle_session_start( /// This text is returned as `additional_context` in the SessionStart hook response, /// giving Claude the knowledge it needs to use clash skills and manage policies. fn clash_session_context() -> &'static str { - include_str!("../docs/session-context.md") + include_str!("session-context.md") } /// Check sandbox support, init session, and symlink — shared by both paths. diff --git a/docs/session-context.md b/clash/src/session-context.md similarity index 100% rename from docs/session-context.md rename to clash/src/session-context.md diff --git a/docs/multi-agent.md b/docs/multi-agent.md index c532780..45fe248 100644 --- a/docs/multi-agent.md +++ b/docs/multi-agent.md @@ -4,14 +4,14 @@ Clash supports 6 coding agents: Claude Code, Gemini CLI, Codex CLI, Amazon Q CLI ## Supported Agents -| Agent | Hook Command | Extension Package | -|-------|-------------|-------------------| +| Agent | Hook Command | Install Assets | +|-------|-------------|----------------| | Claude Code | `clash hook pre-tool-use` (default) | `clash-plugin/` | -| Gemini CLI | `clash hook --agent gemini pre-tool-use` | `clash-gemini-ext/` | -| Codex CLI | `clash hook --agent codex pre-tool-use` | `clash-codex/` | -| Amazon Q CLI | `clash hook --agent amazonq pre-tool-use` | `clash-amazonq/` | -| OpenCode | `clash hook --agent opencode pre-tool-use` | `clash-opencode/` | -| Copilot CLI | `clash hook --agent copilot pre-tool-use` | `clash-copilot/` | +| Gemini CLI | `clash hook --agent gemini pre-tool-use` | `clash/src/agent_templates/gemini/` | +| Codex CLI | `clash hook --agent codex pre-tool-use` | `clash/src/agent_templates/codex/` | +| Amazon Q CLI | `clash hook --agent amazonq pre-tool-use` | `clash/src/agent_templates/amazonq/` | +| OpenCode | `clash hook --agent opencode pre-tool-use` | `clash/src/agent_templates/opencode/` | +| Copilot CLI | `clash hook --agent copilot pre-tool-use` | `clash/src/agent_templates/copilot/` | ## Setup