diff --git a/external_plugins/zcode-automation-recommender/.zcode-plugin/plugin.json b/external_plugins/zcode-automation-recommender/.zcode-plugin/plugin.json new file mode 100644 index 00000000..9d0b087f --- /dev/null +++ b/external_plugins/zcode-automation-recommender/.zcode-plugin/plugin.json @@ -0,0 +1,25 @@ +{ + "name": "zcode-automation-recommender", + "version": "0.2.0", + "description": "Analyze the current codebase and recommend ZCode automations tailored to the project: hooks, skills, commands, subagents, plugins and MCP servers. Read-only: outputs a report and never creates or modifies files.", + "description_i18n": { + "en": "Analyze the current codebase and recommend ZCode automations tailored to the project: hooks, skills, commands, subagents, plugins and MCP servers. Read-only: outputs a report and never creates or modifies files.", + "zh-CN": "分析当前代码库,推荐适配 ZCode 的自动化配置(Hooks、Skills、Commands、Subagents、Plugins、MCP),只读输出报告。" + }, + "author": { + "name": "taohouchao", + "url": "https://github.com/taohouchao-new" + }, + "license": "Apache-2.0", + "keywords": [ + "zcode-setup", + "automation", + "hooks", + "skills", + "commands", + "subagents", + "mcp", + "onboarding" + ], + "skills": "./skills" +} diff --git a/external_plugins/zcode-automation-recommender/LICENSE b/external_plugins/zcode-automation-recommender/LICENSE new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/external_plugins/zcode-automation-recommender/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/external_plugins/zcode-automation-recommender/README.md b/external_plugins/zcode-automation-recommender/README.md new file mode 100644 index 00000000..f8116eab --- /dev/null +++ b/external_plugins/zcode-automation-recommender/README.md @@ -0,0 +1,40 @@ +# zcode-automation-recommender + +Analyzes the current codebase and recommends ZCode automations tailored to the project: hooks, skills, commands, subagents, plugins and MCP servers. Adapted from Anthropic's `claude-code-setup` plugin for ZCode's extension model. + +## What it does + +- Ships one skill, `zcode-automation-recommender`. When you ask for automation recommendations or ZCode setup advice for a project, it: + 1. profiles the codebase — language, frameworks, dependencies, tests, CI, lint / format tooling, sensitive files; + 2. inventories what is already installed or enabled (plugins, skills, subagents, commands, MCP servers, hooks) so nothing already present is recommended twice, and "installed but disabled" is reported as *enable* rather than *install*; + 3. picks the top 1–2 recommendations per category and skips categories that do not apply (3–5 when you ask about a single category); + 4. prints a report that leads with the 2–3 most valuable items, then lists each recommendation with the codebase signal behind it, the exact ZCode location or setting to implement it, and its current status. +- Prefers a marketplace plugin over a hand-configured MCP server whenever a plugin already covers the capability, and points to `AGENTS.md` (via `/init`) for project conventions. +- The report is written in the user's language. The skill prose itself is Chinese. + +## Setup + +1. Install the plugin and start a new session. +2. Open a project and ask, for example: + - "recommend ZCode automations for this project" + - "给这个项目推荐 ZCode 自动化配置" + - "which hooks should I use?" / "这个项目该用什么 hook?" +3. The skill triggers automatically from these requests; you can also pick `zcode-automation-recommender` from the skill picker in the composer. + +## Network access, dependencies, and side effects + +- **Read-only.** The skill writes no files and changes no configuration; implementing a recommendation is always a separate, user-initiated step. +- It runs read-only shell commands in the open project (`ls`, `head`, `grep`, `find`) and reads ZCode metadata under `~/.zcode/` and `~/.agents/`: plugin manifests and enable state, installed skill / subagent / command names, and marketplace catalogs. From `~/.zcode/cli/config.json` it reads key names and booleans only and is instructed never to surface `env` / `headers` values. +- It may call `WebSearch` to check whether a plugin or MCP server exists for a stack the reference tables do not cover, and to confirm package names before recommending an MCP server. No code or file content is sent anywhere. +- The plugin registers no hooks and no MCP servers and needs no API keys. Hook templates it suggests rely on `bash` and `jq` (macOS / Linux); on Windows, implement them as `type: "process"` scripts instead. +- ZCode configuration facts in the bundled references follow the official `zcode-guide` plugin. + +## Third-party components + +| Component | License | Source | +| --- | --- | --- | +| Recommendation workflow and signal tables | adapted from `claude-code-setup` by Anthropic (Apache-2.0) | [anthropics/claude-plugins-official](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/claude-code-setup) | + +Changes from upstream: every landing location rewritten for ZCode (`.zcode/` skill / command / hook / MCP config, `~/.zcode/agents/`, Settings → MCP / Plugin Management); Claude Code–only concepts removed (`disable-model-invocation`, `context: fork`, headless CLI); a Commands category added; an inventory step added; hooks follow ZCode's seven events and require `hooks.enabled: true`; marketplace plugins take precedence over hand-configured MCP servers. + +The plugin itself is Apache-2.0 (see [LICENSE](./LICENSE)). diff --git a/external_plugins/zcode-automation-recommender/README_CN.md b/external_plugins/zcode-automation-recommender/README_CN.md new file mode 100644 index 00000000..7d229ee9 --- /dev/null +++ b/external_plugins/zcode-automation-recommender/README_CN.md @@ -0,0 +1,40 @@ +# zcode-automation-recommender + +分析当前代码库,推荐适配 ZCode 的自动化配置:Hooks、Skills、Commands、Subagents、Plugins、MCP。改编自 Anthropic 的 `claude-code-setup` 插件,按 ZCode 的扩展模型重写。 + +## 功能 + +- 内置一个 skill `zcode-automation-recommender`。当你为某个项目要自动化推荐或 ZCode 配置建议时,它会: + 1. 给代码库画像——语言、框架、依赖、测试、CI、lint / 格式化工具、敏感文件; + 2. 盘点已安装或已启用的扩展(插件、skill、subagent、命令、MCP server、hook),已有的不重复推荐,"已装未启用"的建议动作是启用而不是再装; + 3. 每类挑 1~2 条最高价值的推荐,与代码库无关的类别跳过(点名某一类时给 3~5 条); + 4. 输出报告:开头列最值得先做的 2~3 条,然后每条附上背后的代码库信号、落地到 ZCode 的确切位置或设置项、当前状态。 +- 能力已被市场插件覆盖时,优先推荐插件而不是手配 MCP;项目约定类内容指向 `AGENTS.md`(`/init`)。 +- 报告语言跟随用户;skill 正文为中文。 + +## 安装与使用 + +1. 安装插件,开一个新会话。 +2. 打开一个项目,直接提问,例如: + - "recommend ZCode automations for this project" + - "给这个项目推荐 ZCode 自动化配置" + - "which hooks should I use?" / "这个项目该用什么 hook?" +3. 这类请求会自动触发该 skill;也可以在输入框的 skill 选择器里直接选 `zcode-automation-recommender`。 + +## 网络访问、依赖与副作用 + +- **只读。** skill 不写文件、不改配置;落地任何一条推荐都是你另行发起的独立步骤。 +- 它会在当前项目里执行只读 shell 命令(`ls`、`head`、`grep`、`find`),并读取 `~/.zcode/` 与 `~/.agents/` 下的 ZCode 元数据:插件清单与启用状态、已安装的 skill / subagent / 命令名、市场目录。对 `~/.zcode/cli/config.json` 只读键名与布尔值,并被明确要求不得输出 `env` / `headers` 的值。 +- 参考表没覆盖的技术栈,它可能调用 `WebSearch` 查证是否存在对应的插件或 MCP server,推荐 MCP 前也会核对包名。不会把代码或文件内容发送到任何地方。 +- 插件自身不注册 hook、不声明 MCP server、不需要 API key。它给出的 hook 模板依赖 `bash` 与 `jq`(macOS / Linux);Windows 上请改用 `type: "process"` 脚本实现。 +- 内置参考中的 ZCode 配置事实以官方 `zcode-guide` 插件为准。 + +## 第三方组件 + +| 组件 | 许可证 | 来源 | +| --- | --- | --- | +| 推荐工作流与信号对照表 | 改编自 Anthropic 的 `claude-code-setup`(Apache-2.0) | [anthropics/claude-plugins-official](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/claude-code-setup) | + +相对上游的改动:所有落地位置改为 ZCode 的(`.zcode/` 下的 skill / 命令 / hook / MCP 配置、`~/.zcode/agents/`、Settings → MCP / Plugin Management);删除 Claude Code 专有概念(`disable-model-invocation`、`context: fork`、headless CLI);新增 Commands 类别;新增盘点步骤;hooks 按 ZCode 的 7 个事件书写并要求 `hooks.enabled: true`;市场插件优先于手配 MCP。 + +本插件自身采用 Apache-2.0 许可证(见 [LICENSE](./LICENSE))。 diff --git a/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/SKILL.md b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/SKILL.md new file mode 100644 index 00000000..0e47f207 --- /dev/null +++ b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/SKILL.md @@ -0,0 +1,125 @@ +--- +name: zcode-automation-recommender +description: 分析当前代码库并推荐适配 ZCode 的自动化配置。用户要自动化推荐、想优化或初始化项目的 ZCode 配置、问该用什么 hook / skill / 命令 / subagent / 插件 / MCP、或新项目接入 ZCode 时使用。只读,输出推荐报告。Also for asks like: recommend automations, set up ZCode for this project, which hooks / skills / MCP servers to add. +--- + +# ZCode 自动化推荐器 + + + +读代码库 → 按信号推荐 ZCode 扩展(Hooks、Skills、Commands、Subagents、Plugins、MCP),每类 1~2 条最高价值的。本 skill 只读:产出是一份报告,落地由用户另行发起。 + +## 第 1 步:代码库画像 + +```bash +ls -la package.json pyproject.toml requirements.txt Cargo.toml go.mod pom.xml build.gradle* 2>/dev/null +head -60 package.json 2>/dev/null +ls -la src app lib tests test components pages api internal 2>/dev/null +ls -la .github/workflows .gitlab-ci.yml Dockerfile docker-compose* .env* package-lock.json pnpm-lock.yaml yarn.lock 2>/dev/null +ls -la AGENTS.md .zcode .agents 2>/dev/null +``` + +再按需 grep:依赖里的框架与 SDK(react / vue / next / express / fastapi / mybatis…)、测试配置(jest / vitest / pytest / junit…)、lint 与格式化配置(eslint / prettier / ruff / checkstyle…)。 + +画像字段,每项填上或标"无",本步才算完成: + +| 字段 | 看什么 | +|---|---| +| 语言 / 运行时 | pom.xml、package.json、pyproject.toml、go.mod… | +| 前端栈 | React / Vue / Angular / Next / 小程序 | +| 后端栈 | Spring Boot、Express、FastAPI、Django… | +| 数据库 | Prisma、MyBatis / JPA、SQL 文件、migrations 目录 | +| 外部服务 | 支付、云 SDK、消息队列 | +| 测试 | 框架 + 配置文件 + 测试目录 | +| Lint / Format | eslint / prettier / ruff / checkstyle 配置 | +| CI/CD | .github/workflows、.gitlab-ci.yml | +| 敏感文件 | .env*、*.pem、密钥目录 | +| 规模 | 源码文件数(排除 node_modules、build、dist) | +| 已有 ZCode 配置 | AGENTS.md、.zcode/、.agents/ | + +## 第 2 步:盘点已有扩展 + +已存在的东西换一种推荐方式,不再重复推荐。逐项查看,把每个候选记成三栏之一:**已有且启用 / 已有未启用 / 没有**。 + +| 位置 | 看什么 | +|---|---| +| `/.zcode/`、`/.agents/`、`/AGENTS.md` | 项目级 skill、command、config(mcp、hooks) | +| `~/.agents/skills/`、`~/.zcode/skills/` | 用户级 skill 目录名 | +| `~/.zcode/agents/` | 用户级 subagent | +| `~/.zcode/commands/` | 用户级命令 | +| `~/.zcode/cli/plugins/marketplaces/*/marketplace.json` | 各市场的插件清单;条目带 `cachePath` = 已安装(内置插件也在这里,不进 `installed_plugins.json`) | +| `~/.zcode/cli/plugins/installed_plugins.json` | 用户安装的插件(`plugins[].id`) | +| `~/.zcode/cli/config.json` | `plugins.enabledPlugins`(`false` = 未启用,未列出 = 启用;装了 ≠ 启用了)、`mcp.servers`、`hooks` | + +读 `config.json` 时只看键名和布尔值:`enabledPlugins` 的键、`mcp.servers` 的 server 名、`hooks.events` 的事件名。`env` / `headers` 里可能有密钥,不读出值,也不写进报告。 + +完成标准:第 3 步的每条候选,都能说出它落在三栏里的哪一栏。 + +## 第 3 步:出推荐 + +默认每类 1~2 条,与代码库无关的类别整类跳过。用户点名了某一类时只讲这一类,给 3~5 条。 + +选型原则: + +- **先插件、后手配**:能力已被市场插件覆盖的(GitHub、浏览器、文档…),优先推荐插件,再考虑手配 MCP。 +- **已有未启用 → 推荐"启用"**,而不是再装一个同类。 +- **项目约定进 AGENTS.md**:目录结构、编码规范、命令约定这类常驻内容,正解是 `/AGENTS.md`,没有就建议 `/init`。 +- **信号要具体**:每条"为什么"都引用画像里的一个事实。 +- **冷门栈查证**:参考表没覆盖的框架或工具,用 WebSearch 查有没有对应的 ZCode 插件或 MCP,核实后再推荐;推荐具体 MCP 前同样核对包名与地址是否仍有效。 + +各类的信号对照表与可直接粘贴的配置片段按需读取,只读要推荐的那几类: + +| 要推荐的类别 | 读取 | +|---|---| +| Hooks | [references/hooks-patterns.md](references/hooks-patterns.md) | +| Skills、Commands | [references/skills-commands-reference.md](references/skills-commands-reference.md) | +| Subagents | [references/subagent-templates.md](references/subagent-templates.md) | +| Plugins | [references/plugins-reference.md](references/plugins-reference.md) | +| MCP | [references/mcp-servers.md](references/mcp-servers.md) | + +## 第 4 步:输出报告 + +报告语言跟随用户——用户用中文就写中文,用英文就写英文,下面模板里的标题按用户语言改写;标识符保留英文。结论先行:开头列最值得先做的 2~3 条,再按类别展开。 + +```markdown +## ZCode 自动化配置推荐 + +**最值得先做的**: +1. <类别 · 名称>——一句话理由 +2. <类别 · 名称>——一句话理由 + +### 代码库画像 +- **类型 / 框架**: +- **关键依赖**: +- **测试 / CI**: +- **已有 ZCode 配置**:AGENTS.md 有/无;项目级 skill/命令;已启用的插件 + +### 基线 +AGENTS.md:<有,已覆盖 … / 无,建议 /init 生成项目约定> + +### 🔌 MCP Servers +#### <名称> +**为什么**:<画像里的具体信号> +**落地**:<配置文件与字段,或 Settings → MCP> +**现状**:已有 / 已装未启用 / 未装 + +### 🎯 Skills · ⌨️ Commands · ⚡ Hooks · 🤖 Subagents · 📦 Plugins +(同上结构;与代码库无关的类别整节省略) + +--- +想看某一类的更多选项,直接说(如"多推荐几个 hook")。想落地其中某一条,告诉我,我再按对应规范帮你建。 +``` + +## 决策速查 + +| 信号 | 优先考虑 | +|---|---| +| 改完文件要格式化 / lint / 类型检查 | Hook(PostToolUse) | +| 要拦截敏感文件、锁文件的改动 | Hook(PreToolUse,exit 2) | +| 会话开始要带上项目约定 | Hook(SessionStart 注入 additionalContext)或 AGENTS.md | +| 需要专项审查(安全、性能、UI)且量大 | Subagent | +| 固定流程要带参数反复跑 | Command | +| 可复用的领域知识或模板 | Skill | +| 外部系统集成(Git 平台、数据库、浏览器) | 先插件,后 MCP | +| 项目约定、目录规则 | AGENTS.md | +| 多个 skill 要打包分发 | Plugin | diff --git a/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/hooks-patterns.md b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/hooks-patterns.md new file mode 100644 index 00000000..b39ee746 --- /dev/null +++ b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/hooks-patterns.md @@ -0,0 +1,130 @@ +# ZCode Hooks 参考 + + + +Hook:在工具事件的特定时机自动执行脚本。配置来源两处,形状略有不同: + +| 来源 | 位置 | 形状 | +|---|---|---| +| 配置文件(用户级 / 项目级) | `~/.zcode/cli/config.json`、`/.zcode/config.json` 的 `hooks` 键 | `hooks: { enabled, events: { : [...] } }` | +| 插件 | `/hooks/hooks.json` | 外层再包一层 `hooks`,没有 `enabled` / `events` | + +## 配置文件示例 + +```json +{ + "hooks": { + "enabled": true, + "events": { + "PostToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { + "type": "command", + "command": "bash \"$ZCODE_PROJECT_DIR/.zcode/hooks/format.sh\"", + "timeout": 30, + "statusMessage": "格式化中…" + } + ] + } + ] + } + } +} +``` + +## 规则 + +- **`enabled: true` 必须显式写**。配置文件 hook 默认关闭;只有插件贡献了 hook,runner 才自动开启。漏掉这一项,hook 静默不跑。 +- **事件只有 7 个**:`SessionStart`、`UserPromptSubmit`、`PreToolUse`、`PermissionRequest`、`PostToolUse`、`PostToolUseFailure`、`Stop`。`SubagentStop`、`PreCompact`、`Notification` 不存在,写了就是死配置。 +- **`matcher` 是区分大小写的正则**,工具事件拿它匹配工具名:`"Edit|Write"`、`"Bash"`;省略则全匹配;写错的表达式永远不匹配且无报错。别名:`Task` ≡ `Agent`,`ApplyPatch` ≡ `Write` / `Edit`。 +- **两种类型的字段不能混用**:`type: "command"` 用 `command`(shell 字符串)、`shell`、`timeout`(**秒**)、`timeoutMs`(毫秒,优先);`type: "process"` 用 `command` + `args[]` + `timeoutMs`,不经 shell,跨平台首选。 +- **模板变量**:`${ZCODE_PROJECT_DIR}`、`${ZCODE_SESSION_ID}`,同时以环境变量注入;`${ZCODE_PLUGIN_ROOT}` 仅插件 hook 可用。 +- **脚本必须消费 stdin**,否则可能挂起。 +- **退出码**:`0` 放行;`2` 阻断(`PreToolUse` / `PermissionRequest` 的拒绝);其他非零按错误处理。 +- **stdout JSON**(可选;schema 严格,多一个键就校验失败,不输出也行): + + ```json + { "hookSpecificOutput": { "hookEventName": "SessionStart", "additionalContext": "注入对话的文字" } } + ``` + + `additionalContext` 会注入对话——`SessionStart` / `UserPromptSubmit` 用它带项目约定最省事。`{"suppressOutput": true}` 可抑制输出。 +- `async` 字段无运行时效果,hook 一律同步执行。 +- **hooks 在会话开始时快照**:改完配置要开新会话才生效。 +- **stdin 是一个 JSON 事件对象**,工具事件形如 `{"hook_event_name":"PreToolUse","tool_name":"Write","tool_input":{"file_path":"…"}}`,`SessionStart` 带 `source`(`startup` / `resume` / `clear` / `compact`)与 `session_id`(与官方 `example-plugin` 的 `hooks/pre-tool-use.mjs` 一致)。 + +## 信号 → Hook + +| 画像信号 | 推荐 | 事件 | +|---|---|---| +| prettier 配置 | 改完自动格式化 | PostToolUse `Edit\|Write` | +| eslint / ruff / checkstyle | 改完自动 `--fix` | PostToolUse `Edit\|Write` | +| tsconfig.json | 改完类型检查 | PostToolUse `Edit\|Write` | +| 测试目录 | 改完跑相关测试 | PostToolUse `Edit\|Write` | +| `.env*`、`*.pem`、密钥目录 | 拦截敏感文件写入 | PreToolUse `Edit\|Write` | +| lock 文件 | 拦截手改 lock 文件 | PreToolUse `Edit\|Write` | +| AGENTS.md / docs 有约定 | 会话开始注入约定摘要 | SessionStart | +| 要求任务结束前测试通过 | 结束前检查 | Stop | + +## 模板:拦截敏感文件写入 + +下面的模板依赖 bash + jq(macOS / Linux);Windows 或没有 jq 的环境改用 `type: "process"` 配 node / python 脚本。 + +`/.zcode/hooks/block-sensitive-files.sh`: + +```bash +#!/usr/bin/env bash +# PreToolUse:命中敏感路径则 exit 2 阻断,否则放行;模板文件(.env.example 等)允许编辑 +path=$(jq -r '.tool_input.file_path // ""') +case "$path" in + */.env.example|*/.env.sample|*/.env.template) exit 0 ;; + */.env|*/.env.*|*/id_rsa*|/*.pem|*/secrets/*) + echo "拒绝写入敏感文件:$path" >&2 + exit 2 ;; +esac +exit 0 +``` + +对应的 `events` 条目: + +```json +"PreToolUse": [ + { + "matcher": "Edit|Write", + "hooks": [ + { "type": "command", "command": "bash \"$ZCODE_PROJECT_DIR/.zcode/hooks/block-sensitive-files.sh\"", "timeout": 10 } + ] + } +] +``` + +## 模板:改完自动格式化 + +`/.zcode/hooks/format.sh`,按后缀分发给项目已有的工具(Java、Go 等按项目实际工具补分支);任何失败都不阻断编辑: + +```bash +#!/usr/bin/env bash +# PostToolUse:格式化刚被改动的文件 +cd "$ZCODE_PROJECT_DIR" || exit 0 +path=$(jq -r '.tool_input.file_path // ""') +[ -f "$path" ] || exit 0 +case "$path" in + *.js|*.ts|*.jsx|*.tsx|*.vue|*.json|*.css|*.scss|*.md) npx --no-install prettier --write "$path" >/dev/null 2>&1 ;; + *.py) ruff format "$path" >/dev/null 2>&1 ;; +esac +exit 0 +``` + +## 模板:会话开始注入约定 + +`/.zcode/hooks/inject-conventions.sh`: + +```bash +#!/usr/bin/env bash +# SessionStart:把 docs/conventions.md 全文注入对话 +cat >/dev/null # 消费 stdin +file="$ZCODE_PROJECT_DIR/docs/conventions.md" +[ -f "$file" ] || exit 0 +printf '{"hookSpecificOutput":{"hookEventName":"SessionStart","additionalContext":%s}}' "$(jq -Rs . < "$file")" +``` diff --git a/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/mcp-servers.md b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/mcp-servers.md new file mode 100644 index 00000000..a7229dc9 --- /dev/null +++ b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/mcp-servers.md @@ -0,0 +1,57 @@ +# ZCode MCP 参考 + + + +MCP server 给模型接外部工具。ZCode 里每个 scope 的 server 在会话启动时**自动连接**,同名时**用户级覆盖项目级**。 + +## 配置位置 + +| scope | 文件 | 字段 | +|---|---|---| +| 用户级 | `~/.zcode/cli/config.json` | `mcp.servers` | +| 项目级(随仓库共享) | `/.zcode/config.json` | `mcp.servers` | +| 同 scope 回退 | `~/.agents/mcp.json`、`/.agents/mcp.json` | 顶层 `mcpServers`;仅当同 scope 的 `.zcode` 没有任何 server 时才读 | +| 插件 | `/.mcp.json` 或 manifest `mcpServers` | 名字空间 `plugin::` | + +图形界面:**Settings → MCP**(状态、报错、编辑都在这里)。 + +## 配置形状 + +```json +{ + "mcp": { + "servers": { + "context7": { "type": "stdio", "command": "npx", "args": ["-y", "@upstash/context7-mcp"] }, + "playwright": { "type": "stdio", "command": "npx", "args": ["-y", "@playwright/mcp@latest"] }, + "remote-reader": { "type": "http", "url": "https://example.com/mcp", "headers": { "Authorization": "Bearer " } } + } + } +} +``` + +规则: + +- stdio:`command`(**字符串**)、`args[]`、`cwd`、`env`、`enabled`、`timeoutMs`;http / sse:`url`、`headers`。`type` 省略时按有无 `command` / `url` 推断。 +- schema **严格**:出现未知键、`command` 写成数组、`type` 与字段不配,整个 server 被静默丢弃。 +- 配置文件里的 server **不展开 `${...}` 模板**(仅插件 server 支持),路径一律写绝对路径;`command` 要在 `PATH` 上,否则写绝对路径。 +- 密钥放 `env` / `headers`,项目级配置用环境变量引用,不进版本库。 +- 默认超时 30000 ms,启动慢的 server 加 `"timeoutMs": 60000`。 +- 改完重启会话;状态看 Settings → MCP。 + +## 信号 → MCP + +先看插件是否已覆盖(见 [plugins-reference.md](plugins-reference.md)),没有再手配 MCP: + +| 画像信号 | 先看插件 | 否则 MCP | +|---|---|---| +| GitHub 仓库、PR 流程 | `github` | — | +| GitLab | `gitlab` | — | +| 前端页面验证、E2E | `browser-use` | Playwright:`npx -y @playwright/mcp@latest` | +| 主流框架 / SDK 的最新文档 | — | context7:`npx -y @upstash/context7-mcp` | +| MySQL / PostgreSQL | — | 社区 database MCP,如 `npx -y @benborla29/mcp-server-mysql`(官方文档示例) | +| 飞书 / 钉钉 / 企微 | `lark-cli` / `dingtalk-cli` / `wecom-cli` | — | +| 阿里云 / 腾讯云 CloudBase | `alibaba-cloud-cli` / `cloudbase-skills` | — | +| 金融数据 | `hexin` / `wind` / `tianyancha` | — | +| Sentry、Linear、Jira、Slack | — | 对应厂商的官方 MCP,用 WebSearch 核对当前地址与鉴权方式 | + +推荐具体 MCP 时附上配置片段,并提醒:这是社区或第三方 server,装前看一眼它的仓库与权限范围。 diff --git a/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/plugins-reference.md b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/plugins-reference.md new file mode 100644 index 00000000..816a1264 --- /dev/null +++ b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/plugins-reference.md @@ -0,0 +1,47 @@ +# ZCode Plugins 参考 + + + +Plugin 是打包好的扩展集合:一个 `.zcode-plugin/plugin.json` 加上若干 skills / commands / hooks / mcpServers / agents。装一个插件等于一次接入多个扩展,所以**能力已被插件覆盖时优先推荐插件**,再考虑手配。 + +## 获取与管理 + +- **Settings → Plugin Management**:Installed 管已装,Discover 浏览市场;Discover 页 `+` 可添加市场(GitHub 仓库、Git URL、本地目录、文件)。 +- 市场:`zcode-plugins-official`(ZCode 官方)、`claude-plugins-official`(Anthropic 官方,ZCode 兼容其格式,可直接安装)、用户自建。 +- **装了 ≠ 启用了**:`~/.zcode/cli/config.json` → `plugins.enabledPlugins["@"]`。已装未启用的,推荐动作是"启用"而不是再装同类。内置插件只能禁用、不能卸载。 +- 实时清单:`~/.zcode/cli/plugins/marketplaces//marketplace.json`(`name`、`description_i18n["zh-CN"]`、`category`)。推荐前查一遍,清单会变,别凭记忆报名字。 +- 自己做插件:官方 `plugin-creator`;装不上、组件缺失:`zcode-guide` 的 `diagnosing-plugins`。 + +## 信号 → 官方市场插件(`zcode-plugins-official`) + +| 画像信号 | 插件 | 提供什么 | +|---|---|---| +| `.github/`、PR 流程 | `github` | 基于 gh CLI 的 PR / Issue / Actions 工作流 | +| `.gitlab-ci.yml` | `gitlab` | MR / Issue / CI 工作流 | +| 前端项目、要点页面验证 | `browser-use`、`design` | 内置浏览器操作;设计稿与原型 | +| Web 项目要部署 | `zcode-site` | 改造成云端一键部署包 | +| 支付、鉴权等安全敏感代码 | `mimosa` | 写入前 Hook、Git 门禁、安全扫描 skill | +| 文档产出 | `documents`、`pdf`、`presentations`、`spreadsheets` | Word / PDF / PPT / Excel | +| 交互图表、白板 | `visualize`、`excalidraw` | 对话内交互视图;手绘风格图 | +| Notebook / 数据分析 | `jupyter-notebook` | 侧栏运行 cell | +| Android / iOS | `android-emulator`、`ios-simulator` | 模拟器自动化 | +| 游戏引擎、3D | `godot`、`unity`、`unreal-engine`、`blender` | 对应引擎的开发与调试 | +| 云服务 | `cloudbase-skills`、`alibaba-cloud-cli` | CloudBase;阿里云 CLI | +| 协作工具 | `lark-cli`、`dingtalk-cli`、`wecom-cli`、`tencent-meeting-cli` | 飞书 / 钉钉 / 企微 / 腾讯会议 | +| 金融数据 | `hexin`、`wind`、`tianyancha` | 行情、宏观、企业信息 MCP | +| 要做插件 / 技能本身 | `plugin-creator`、`skill-creator`、`zcode-guide` | 创建、校验、诊断 | +| 要自动迭代实验 | `autoresearch` | 目标 + 度量的自主实验循环 | + +Java、Python、Go 等语言专用插件官方市场暂无:语言规范走 skill(例如 `java-rules`、`python-rules` 这类语言规则 skill),代码审查走 subagent。 + +## 信号 → `claude-plugins-official`(第二来源) + +| 画像信号 | 插件 | +|---|---| +| 功能规划、spec 驱动开发 | `feature-dev` | +| 前端设计 | `frontend-design` | +| 提交规范 | `commit-commands` | +| 用自然语言写自动化规则 | `hookify` | +| 写 Claude 兼容插件 | `plugin-dev` | + +这些插件按 Claude Code 的约定编写,在 ZCode 里靠格式兼容运行;推荐时提醒用户装后先试一下核心 skill 是否正常触发,不正常的按 `diagnosing-plugins` / `diagnosing-skills` 排查。 diff --git a/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/skills-commands-reference.md b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/skills-commands-reference.md new file mode 100644 index 00000000..a1934295 --- /dev/null +++ b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/skills-commands-reference.md @@ -0,0 +1,75 @@ +# ZCode Skills 与 Commands 参考 + + + +两者都是 Markdown 文件,差别在触发方式:**Skill** 由模型按 description 自动触发,也可手输名字;**Command** 是用户在输入框敲 `/名字` 才跑的固定流程。ZCode 的 skill frontmatter 没有"禁止模型调用"的开关——带 description 的 skill 模型都能自动触发,所以只该由用户发起的流程(部署、提交、发消息这类有副作用的)做成 Command。 + +## Skill + +`<目录>/SKILL.md`,frontmatter 是扁平的 `key: value`: + +```markdown +--- +name: gen-test +description: 为指定源码文件生成单元测试时使用。读取项目的测试框架与既有用例风格,生成同目录下的测试文件。 +--- + +# 生成测试 + +(流程、模板、检查清单) +``` + +| 项 | 规则 | +|---|---| +| 识别键 | `name`、`description`、`when_to_use`、`license`、`metadata`;其他键被忽略 | +| 必填 | `name`、`description` 缺一即不加载;`description` ≤ 1024 字符 | +| 触发 | 模型看到的是 `name` + `description` 前 ~250 字符——触发条件写在 description 开头 | +| 位置 | 项目级 `/.zcode/skills/`、`/.agents/skills/`;用户级 `~/.zcode/skills/`、`~/.agents/skills/` | +| 优先级 | 用户级 > 项目级 > 插件;同级别 `.zcode` > `.agents`;同名只加载优先级最高的那个 | +| 调用 | 按 `name` 或 `plugin:skill`,不带前导 `/` | +| 附带文件 | 同目录可放 `references/`、`scripts/`、模板,按需读取 | +| 创建工具 | 官方 `skill-creator` 插件 | + +放哪里:只在这个仓库用 → `/.zcode/skills/`,随仓库共享给团队;个人跨项目用 → `~/.agents/skills/`(其他读这个目录的 agent 也能用)。 + +## Command + +`<目录>/<名字>.md`,**文件名就是命令名**: + +```markdown +--- +description: 按清单检查当前分支的改动,输出 PR 前必须处理的问题 +argument-hint: [base=main] +allowed-tools: Read, Bash +--- + +# PR 前检查 + +对比基准分支:$1(缺省 main) +(流程) +``` + +| 项 | 规则 | +|---|---| +| 名字 | `^[a-z0-9][a-z0-9_:-]{0,63}$`;子目录 `review/code.md` → `/review:code` | +| frontmatter | `description`、`argument-hint`、`allowed-tools`、`model`、`skills`、`disable-noninteractive`,全部单行、连字符 | +| 必填 | `description` 或非空正文至少有一样 | +| 参数 | `$ARGUMENTS` 全部参数;`$1`、`$2` 位置参数 | +| 位置 | 与 skill 同一套目录:`~/.zcode/commands/`、`~/.agents/commands/`、`/.zcode/commands/`、`/.agents/commands/` | +| 优先级 | 同名命令先到先得:用户级 > 项目级 > 插件 | +| 保留名 | 与内置命令(含 `compress`)同名的会被 `/` 菜单过滤,换个名字 | + +## 信号 → Skill / Command + +市场里现成的 skill 插件(`claude-plugins-official`,ZCode 可直接装):`feature-dev`(功能规划)、`frontend-design`(前端设计)、`commit-commands`(提交规范)、`hookify`(用自然语言写自动化规则)、`plugin-dev`(写插件)。先查用户是否已装,再决定推荐安装还是启用。 + +| 画像信号 | 建议新建 | 类型 | 名字 | +|---|---|---|---| +| API 路由(controller、router) | 生成 OpenAPI 文档 | Skill | `api-doc` | +| 数据库 migrations 目录 | 带校验的迁移脚本 | Command | `/create-migration` | +| 测试套件 | 按既有风格生成测试 | Skill + Command | `gen-test` / `/gen-test` | +| 组件库、`components/` | 按模板新建组件 | Command | `/new-component` | +| PR 流程(CONTRIBUTING、PR 模板) | PR 前检查清单 | Command | `/pr-check` | +| 有 release / tag 规范 | 从 git 历史生成发布说明 | Command | `/release-notes` | +| 项目约定、目录规则 | 写进 AGENTS.md | AGENTS.md | `/init` | +| 新人上手成本高 | 环境检查 + 启动指引 | Command | `/setup-dev` | diff --git a/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/subagent-templates.md b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/subagent-templates.md new file mode 100644 index 00000000..4d2506bb --- /dev/null +++ b/external_plugins/zcode-automation-recommender/skills/zcode-automation-recommender/references/subagent-templates.md @@ -0,0 +1,53 @@ +# ZCode Subagent 参考 + + + +Subagent 是带独立上下文的专职 agent:主会话用 Agent 工具按 `subagent_type` 派发,可并行,只有最终报告回到主会话。适合专项审查、大体量分析、需要隔离上下文的活。 + +## 文件与位置 + +- 用户级:`~/.zcode/agents/.md`;插件可带 agents(manifest `agents` 字段)。图形界面:**Settings → Subagents**。 +- frontmatter 字段:`name`、`description`(写成触发条件)、`tools`(白名单,支持 `Bash(git diff *)` 这类带模式的项)、`model`(`provider/model`,省略用默认)、`thoughtLevel`、`color`。 + +## 模板:security-reviewer + +`~/.zcode/agents/security-reviewer.md`: + +```markdown +--- +name: security-reviewer +description: 审查涉及鉴权、支付、敏感数据的改动时使用。只读安全审查,输出分级报告,不修改代码。 +tools: + - Read + - Grep + - Glob + - Bash(git diff *) +--- + +# 安全审查 + +审查范围由派发指令给出:只看本次改动涉及的文件及其直接调用方。 + +## 检查项 +- 鉴权与授权:接口是否校验身份与权限,有无越权路径 +- 注入:SQL 拼接、命令拼接、模板注入 +- 敏感数据:日志与响应里是否泄露密钥、token、个人数据;有无硬编码密钥 +- 支付与金额:幂等、签名校验、金额精度 +- 新增依赖的已知漏洞 + +## 输出 +🔴 阻断 / 🟠 重要 / 💡 建议三级,每条给出 `文件:行号`、问题、修复建议。只读,不改代码。 +``` + +## 信号 → Subagent + +| 画像信号 | 推荐 | 关注点 | +|---|---|---| +| 鉴权、支付代码 | `security-reviewer` | 注入、越权、敏感数据 | +| 源码文件 > 500 | `code-reviewer` | 并行审查大 diff | +| API 项目 | `api-documenter` | OpenAPI 与实现是否一致 | +| 性能敏感(缓存、批处理、实时) | `performance-reviewer` | N+1、锁竞争、热点循环 | +| 前端占比高 | `ui-reviewer` | 可访问性、响应式、状态泄漏 | +| 测试覆盖率低 | `test-writer` | 按既有风格补测试 | + +先查 `~/.zcode/agents/` 已有哪些:已有的(如语言 reviewer)不重复推荐,缺的专项才建。 diff --git a/marketplace.json b/marketplace.json index 32e8c8ef..31f3adb3 100644 --- a/marketplace.json +++ b/marketplace.json @@ -1673,6 +1673,31 @@ "把上一个 Hi3D 任务生成的模型按角色拆分成部件" ] } + }, + { + "name": "zcode-automation-recommender", + "source": "./external_plugins/zcode-automation-recommender", + "description": "Analyze the current codebase and recommend ZCode automations tailored to the project: hooks, skills, commands, subagents, plugins and MCP servers. Read-only: outputs a report and never creates or modifies files.", + "description_i18n": { + "en": "Analyze the current codebase and recommend ZCode automations tailored to the project: hooks, skills, commands, subagents, plugins and MCP servers. Read-only: outputs a report and never creates or modifies files.", + "zh-CN": "分析当前代码库,推荐适配 ZCode 的自动化配置(Hooks、Skills、Commands、Subagents、Plugins、MCP),只读输出报告。" + }, + "version": "0.2.0", + "author": { + "name": "taohouchao", + "url": "https://github.com/taohouchao-new" + }, + "category": "developer-tools", + "keywords": [ + "zcode-setup", + "automation", + "hooks", + "skills", + "commands", + "subagents", + "mcp", + "onboarding" + ] } ] } \ No newline at end of file