Agent skill

Zhin Plugin Refactoring

by zhinjs in zhinjs/zhin

Refactor existing Zhin.js plugins into a cleaner standard structure.

MITAuto-check passedDevelopment

Install Zhin Plugin Refactoring

skills CLI
$ npx skills add zhinjs/zhin --skill zhin-plugin-refactoring -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install zhinjs/zhin zhin-plugin-refactoring --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/zhinjs/zhin.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.github/skills/zhin-plugin-refactoring .claude/skills/zhin-plugin-refactoring && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
zhin-plugin-refactoring
GitHub stars
137
Token cost
~1.1k tokens
SKILL.md length
245 words
Files
5 (incl. references, assets)
Skills in repo
11
Repo updated
First seen
Licence
MIT

At a glance

Refactor existing Zhin.js plugins into a cleaner standard structure.

  • Works in 6 steps: 配置与 Schema → 模型定义 → 数据访问与共享服务 → …
  • Asked to reorganize plugin files
  • SKILL.md covers 何时使用, 不适用场景, 完成标准 and 重构步骤, plus 5 more sections
  • Calls pnpm

What it does

Zhin Plugin Refactoring is an agent skill from zhinjs/zhin. Refactor existing Zhin.js plugins into a cleaner standard structure. Use when asked to reorganize plugin files, split commands or services, migrate a messy plugin to standard layout, reduce coupling, clean lifecycle logic, or standardize plugin structure without changing behavior. 适用于已有 Zhin 插件重构、结构整理、职责拆分与标准化迁移。

Its SKILL.md is about 1.1k tokens, which your agent loads only when the skill is triggered. The skill folder holds 6 other files, including reference files and assets (for example `assets/refactor-target-layout.md`, `references/refactor-before-after-example.md` and `references/refactor-decision-guide.md`).

It sits in Development, covering Refactoring and Hooks and plugins. The repository describes itself as: AI-native TypeScript bot framework — one codebase for 20+ chat platforms (QQ, Discord, Telegram, Slack, WeChat…). Opt-in AI agent with MCP, tools & security policies. <10MB core. The licence is MIT.

When your agent uses it

  • Asked to reorganize plugin files
  • Migrate a messy plugin to standard layout
  • Reduce coupling
  • Clean lifecycle logic

Example prompts

  • “/zhin-plugin-refactoring”

Workflow steps

6 steps, taken from the first numbered list in SKILL.md.

  1. 配置与 Schema
  2. 模型定义
  3. 数据访问与共享服务
  4. 命令与中间件
  5. 事件、定时任务、AI 工具
  6. HTTP Host 与 Console 页面入口

What it can do on your machine

Read from SKILL.md and the folder at commit fd5029a. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • pnpm

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use pnpm, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Zhin Plugin Refactoring loads about 1.1k tokens when it runs, and up to ~2.2k if it reads all its reference files. Until then it costs about 85 tokens; SKILL.md has 245 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~85
When it runs · the whole SKILL.md, loaded when a task matches
~1.1k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~2.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from zhinjs/zhin at commit fd5029a, republished under its MIT licence (© zhinjs). 245 words, ~1,140 tokens.

Download SKILL.mdSave it as .claude/skills/zhin-plugin-refactoring/SKILL.md (or your agent's skills folder). This skill also uses 4 other files; get the full folder from GitHub.
name
zhin-plugin-refactoring
description
Refactor existing Zhin.js plugins into a cleaner standard structure. Use when asked to reorganize plugin files, split commands or services, migrate a messy plugin to standard layout, reduce coupling, clean lifecycle logic, or standardize plugin structure without changing behavior. 适用于已有 Zhin 插件重构、结构整理、职责拆分与标准化迁移。
argument-hint
Describe the plugin to refactor, current problems such as mixed responsibilities or duplicated logic, and the target outcome such as split modules, cleaner…
user-invocable
true

Zhin 插件重构工作流

把已经存在但结构混乱的 Zhin 插件,整理成更清晰、更符合仓库约定的结构,同时尽量不改变现有行为。

配套参考按需加载:

何时使用

  • 一个插件把命令、数据库、路由、页面逻辑都堆在一个文件里
  • 需要拆分约定能力目录、src/services/、src/models/ 或 pages/
  • 想减少重复逻辑、生命周期混乱、Context 使用散乱
  • 想把旧插件迁移到更标准的 Zhin 插件结构
  • 用户明确要求“重构插件”“整理插件结构”“拆模块但别改行为”

不适用场景

  • 从零新建插件:改用 zhin-plugin-standard-development
  • 平台接入、Bot 生命周期、消息格式转换:改用适配器工作流
  • 主要是页面视觉和交互优化:改用前端优化工作流

完成标准

  • 行为保持不变或仅做用户明确允许的最小改动
  • 目录和职责边界更清晰
  • 生命周期和资源清理更稳定
  • 配置、模型、Context、路由、页面入口不再散落在无关模块中
  • 至少完成关键路径验证

重构步骤

第 1 步:冻结当前行为

先识别:

  • 这个插件当前对外有哪些命令、路由、页面、事件或周期任务
  • 哪些行为是用户可见的,不能随意改
  • 哪些问题是结构问题,哪些是功能缺陷

不要一上来就拆文件。先把当前行为面画清楚。

第 2 步:盘点能力与职责

把现有代码按能力分类:

  • 命令
  • 中间件
  • 事件监听
  • 定时任务
  • 组件
  • AI 工具
  • 数据模型
  • 数据访问逻辑
  • HTTP / Web 集成
  • 配置声明

如果不知道怎么分类,先看 重构决策参考。

如果你需要一个“单文件旧插件如何拆成标准结构”的直观参考,直接看 重构前后对照示例。

第 3 步:确定目标结构

根据当前复杂度选择目标结构,而不是追求最完整目录:

  • 小型插件:保留最小 plugin.ts,只创建实际存在的命名能力目录
  • 中型插件:能力进入约定目录,共享实现拆到 src/services/、src/models/
  • 含控制台页面:使用 pages/<name>/index.tsx
  • 含 AI 工具:按最窄归属放入根、Agent、Skill 或 Agent-Skill 的 tools/<name>/index.ts

目标结构可直接参考 目标结构草图。

第 4 步:按稳定边界迁移

迁移优先顺序:

  1. 配置与 Schema
  2. 模型定义
  3. 数据访问与共享服务
  4. 命令与中间件
  5. 事件、定时任务、AI 工具
  6. HTTP Host 与 Console 页面入口

优先移动低耦合代码,再移动依赖较多的装配代码。

如果你不确定某段旧代码该落到哪个目录,先对照 重构前后对照示例 再迁移。

第 5 步:收口到入口文件

重构后的入口文件(plugin.ts)应只负责:

  • default-export definePlugin()(Plugin Runtime 形态;不要再用 usePlugin() / MessageCommand)
  • 装配子模块与 Host 资源(context.resources.has/use,如 databaseHostToken / scheduleHostToken / httpHostToken)
  • 注册随 generation 回收的资源(context.lifecycle.add(...))

配置由 schema.json + context.config.get() 声明/读取(不再有 declareConfig())。能力放入明确的约定目录:命令用 commands/**/index.ts,中间件用 middlewares/<name>/index.ts,Handler 用 handlers/<name>/index.ts,Hook 用 hooks/<name>/index.ts,通用工具用 tools/<name>/index.ts,Skill 用 skills/<name>/SKILL.md,Agent 用 agents/<name>/agent.json;专用工具继续放在所属 Skill 或 Agent 的 tools/<name>/index.ts。运行时按目录装配,不要在入口手写注册,也不要把业务细节继续留在入口文件里。

第 6 步:校验生命周期与清理

检查以下问题:

  • 监听器是否在销毁时可清理(优先 context.lifecycle.add 挂反注册)
  • 定时任务是否通过 scheduleHostToken 注册并随 generation 回收(不再有 addCron())
  • HTTP 路由是否经 httpHostToken 注册并有对应释放路径
  • 数据库逻辑是否只在拿到 databaseHostToken 后挂载
第 7 步:验证行为未回退

至少验证:

  • 命令还能正常触发
  • 路由或页面入口还能注册
  • 定时任务和事件没有丢失
  • 关键配置读取仍然正确

验证命令(按插件包名替换 <pkg>):

bash
pnpm --filter <pkg> build
pnpm --filter <pkg> test
pnpm check:plugin-capability-publish
pnpm check:agent-tool-authoring-boundaries
pnpm check:skill-authoring-boundaries
pnpm check:agent-authoring-boundaries
pnpm check:hook-authoring-boundaries
# 手测:Sandbox 或 test-bot 触发原命令 / 访问原控制台路由

输出验证报告:

markdown
## 重构验证
- [ ] build 通过
- [ ] test 通过
- [ ] 命令 A:通过 / 未测
- [ ] 路由/页面 B:通过 / 未测
- 回滚风险:(仅列未覆盖路径)

失败与兜底

触发条件一线处理仍失败
重构后命令不触发对比重构前后 commands/ 约定目录的 defineCommand 导出与文件路径回滚该模块,逐文件迁移
测试大面积失败先恢复行为再谈结构;用 git 对比入口装配🔴 暂停拆文件,只修回归
Host 资源未装配确认 context.resources.has(token) 守卫与 lifecycle 清理对照 重构迁移清单

🔴 CHECKPOINT · 行为冻结

第 1 步「冻结当前行为」完成前,不得删除或改写用户可见命令/路由/页面逻辑。

不要做什么

  • 不要在重构中顺带改功能或「优化」业务语义
  • 不要一次性拆出空目录填满占位文件
  • 不要把适配器协议逻辑迁入普通插件
  • 不要在未跑测试前大规模移动 pages/ 或 Console RPC 契约
  • 不要用本 skill 从零新建插件

输出要求

最终输出应包含:

  1. 当前结构问题:混乱点和耦合点是什么
  2. 目标结构:准备拆成什么样
  3. 迁移策略:先迁什么,后迁什么
  4. 已完成改动:哪些模块已重构
  5. 验证结果:哪些路径已验证
  6. 风险说明:还有哪些行为敏感点

延伸阅读

文档路径
标准开发(新建功能).github/skills/zhin-plugin-standard-development/SKILL.md
迁移清单./references/refactor-migration-checklist.md
前后对照./references/refactor-before-after-example.md

© zhinjs, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 4 other files (references, assets) in .github/skills/zhin-plugin-refactoring of zhinjs/zhin.

  • SKILL.md
  • assets/refactor-target-layout.md
  • references/refactor-before-after-example.md
  • references/refactor-decision-guide.md
  • references/refactor-migration-checklist.md

Open the folder on GitHubat commit fd5029a

Compare with similar skills

Zhin Plugin Refactoring next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Zhin Plugin Refactoring compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Zhin Plugin Refactoring this skillzhinjs/zhin137—~1.1kAutomated safety check: PassMIT
Tsh Writing HooksTheSoftwareHouse/copilot-collections284—~3kAutomated safety check: PassMIT
Plate Plugin Creatorudecode/plate17k—~2.3kAutomated safety check: PassCustom licence
Guidelinesakash-network/node1.1k22 repos~577Automated safety check: PassMIT
Component Refactoringlangflow-ai/langflow156k—~3.5kAutomated safety check: PassMIT
Migrate Core Code to Submodulestinyhumansai/openhuman42k—~2.6kAutomated safety check: PassGPL-3.0

Similar skills

  • Tsh Writing Hooks

    TheSoftwareHouse/copilot-collections

    Custom hook and composable patterns — naming, composition, stable return shapes, lifecycle cleanup, and testing strategies.

    284 GitHub stars~3k tokensUpdated 3 days ago
    DevelopmentAuto-check passed
  • Build new Plate plugins with Slate-first architecture, sane typing, and explicit React/Plate wrapper boundaries.

    17k GitHub stars~2.3k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Guidelines

    akash-network/node

    Behavioral guidelines to reduce common LLM coding mistakes. An agent skill from akash-network/node.

    1.1k GitHub starsUsed in 22 repos~577 tokens
    DevelopmentAuto-check passed
  • Component Refactoring

    langflow-ai/langflow

    Refactor high-complexity React components in Langflow frontend.

    156k GitHub stars~3.5k tokensUpdated today
    DevelopmentAuto-check passed
  • Migrate Core Code to Submodules

    tinyhumansai/openhuman

    Plans and carries out moving non-host-specific code and its tests from the OpenHuman core into vendored tiny submodule libraries, then releases the submodule and re-pins the host.

    42k GitHub stars~2.6k tokensUpdated today
    DevelopmentAuto-check passed
  • Systematic Code Refactoring

    luongnv89/claude-howto

    Guides refactoring in phases based on Martin Fowler's method: research, test coverage check, planning and small tested steps, with your approval at each phase.

    42k GitHub stars~3k tokensUpdated 8 days ago
    DevelopmentAuto-check passed

More from zhinjs/zhin

All 11 skills in this repo
  • Migrate legacy Zhin.js plugins and projects to the convention-based Plugin Runtime — from usePlugin/getPlugin/addCommand/addMiddleware/addComponent/addTool/addCron/declareConfig/useContext and…

    137 GitHub stars~1.6k tokensUpdated 15 days ago
    Auto-check passed
  • Zhin Audit

    zhinjs/zhin

    Audit Zhin.js changes for security, performance, lifecycle, and architecture regressions.

    137 GitHub stars~596 tokensUpdated 15 days ago
    Auto-check: notes
  • Implement Zhin.js plugins with Plugin Runtime. An agent skill from zhinjs/zhin.

    137 GitHub stars~1.6k tokensUpdated 15 days ago
    Auto-check passed
  • GitHub CLI

    zhinjs/zhin

    使用 gh CLI 处理内置 GitHub Tool 未覆盖的 Issue、PR、Release、Workflow、搜索和 API 操作。

    137 GitHub stars~366 tokensUpdated 15 days ago
    Auto-check passed
  • Wecom

    zhinjs/zhin

    企业微信平台管理能力。当用户在企业微信中请求用户信息查询、部门架构查询、 发送文本消息时使用。即使用户没有提到企业微信,只要上下文是企业微信/WeCom 场景且涉及用户查询、部门管理或消息发送,就应触发。

    137 GitHub stars~297 tokensUpdated 15 days ago
    Auto-check passed
  • Checkin

    zhinjs/zhin

    签到积分系统查询能力。当用户想查看自己的积分、签到排行榜、连签天数、 或了解签到奖励时使用。日常签到通过聊天命令触发,此技能提供积分查询的 AI 工具。

    137 GitHub stars~167 tokensUpdated 15 days ago
    Auto-check passed

Categories

Questions about Zhin Plugin Refactoring

What does Zhin Plugin Refactoring do?

Refactor existing Zhin.js plugins into a cleaner standard structure. Zhin Plugin Refactoring is an agent skill from zhinjs/zhin.js plugins into a cleaner standard structure.

When should I use Zhin Plugin Refactoring?

Zhin Plugin Refactoring fits situations like: asked to reorganize plugin files; migrate a messy plugin to standard layout; reduce coupling; clean lifecycle logic.

How do I install Zhin Plugin Refactoring in Claude Code?

Run `npx skills add zhinjs/zhin --skill zhin-plugin-refactoring -a claude-code`. Or copy the skill folder (.github/skills/zhin-plugin-refactoring in zhinjs/zhin) into .claude/skills/zhin-plugin-refactoring in your project. Claude Code loads it when a task matches its description.

How do I install Zhin Plugin Refactoring in Codex?

Run `npx skills add zhinjs/zhin --skill zhin-plugin-refactoring -a codex`. Or copy the skill folder (.github/skills/zhin-plugin-refactoring in zhinjs/zhin) into .agents/skills/zhin-plugin-refactoring in your project. Codex loads it when a task matches its description.

Can I use Zhin Plugin Refactoring in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add zhinjs/zhin --skill zhin-plugin-refactoring -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/zhin-plugin-refactoring, .gemini/skills/zhin-plugin-refactoring, .github/skills/zhin-plugin-refactoring and .opencode/skills/zhin-plugin-refactoring in your project.

What does Zhin Plugin Refactoring need to run?

Going by SKILL.md and its folder, Zhin Plugin Refactoring needs the command-line tools its instructions call (pnpm).

Does Zhin Plugin Refactoring access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Zhin Plugin Refactoring safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Zhin Plugin Refactoring use?

Zhin Plugin Refactoring is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Zhin Plugin Refactoring use?

About 1.1k tokens (SKILL.md is roughly 4.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 1.1k tokens, read only when the agent opens those files.

What are the alternatives to Zhin Plugin Refactoring?

Skills that share tags, products or a category with Zhin Plugin Refactoring: Tsh Writing Hooks (TheSoftwareHouse/copilot-collections, 284 stars), Plate Plugin Creator (udecode/plate, 17k stars), Guidelines (akash-network/node, 1.1k stars) and Component Refactoring (langflow-ai/langflow, 156k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Zhin Plugin Refactoring?

zhinjs (a GitHub organization) maintains it in zhinjs/zhin, which has 137 GitHub stars. The repository holds 11 skills in this directory. The repository was last updated on September 23, 2026.

Source: zhinjs/zhin on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.