Agent skill

Migrate Zhin Plugin Runtime

by zhinjs in zhinjs/zhin

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

MITAuto-check passedProductivity & Automation

Install Migrate Zhin Plugin Runtime

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

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

GitHub CLI
$ gh skill install zhinjs/zhin migrate-zhin-plugin-runtime --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/migrate-zhin-plugin-runtime .claude/skills/migrate-zhin-plugin-runtime && 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
migrate-zhin-plugin-runtime
GitHub stars
136
Token cost
~1.6k tokens
SKILL.md length
345 words
Files
3 (incl. references)
Skills in repo
11
Repo updated
First seen
Licence
MIT

At a glance

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

  • Works in 8 steps: 盘点:读目标包的… → 看计划:zhin runtime migrate extract… → 搬能力:zhin runtime migrate extract… → …
  • Tasks that involve Scheduled and recurring tasks
  • SKILL.md covers 先建立事实,再动手, 工作流, 目标写法 and 硬性规则, plus 3 more sections
  • Calls pnpm and rg

What it does

Migrate Zhin Plugin Runtime is an agent skill from zhinjs/zhin. Migrate legacy Zhin.js plugins and projects to the convention-based Plugin Runtime — from usePlugin/getPlugin/addCommand/addMiddleware/addComponent/addTool/addCron/declareConfig/useContext and mutable registries to definePlugin + capability directories + Scope/Token resources. Use this whenever a Zhin plugin fails to load under zhin runtime start, errors with "does not default-export a Plugin definition", still imports zhin.js/@zhin.js/core/@zhin.js/kernel, or when asked to upgrade, port, modernize, or migrate a…

Its SKILL.md is about 1.6k tokens, which your agent loads only when the skill is triggered. The skill folder holds 3 other files, including reference files (for example `references/manual-diagnostics.md` and `references/migration-map.md`).

It sits in Productivity & Automation, covering Scheduled and recurring tasks. It works with npm and TypeScript. 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

  • Tasks that involve Scheduled and recurring tasks

Example prompts

  • “does not default-export a Plugin definition”
  • “migrate”
  • “/migrate-zhin-plugin-runtime”

Workflow steps

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

  1. 盘点:读目标包的 README、最近的测试、旧入口,弄清用户可见行为(命令、消息、定时、
  2. 看计划:zhin runtime migrate extract --check,逐条读 changes 与 diagnostics。
  3. 搬能力:zhin runtime migrate extract --write。它只搬模块顶层、且闭包干净的注册,
  4. 清诊断:每条 manual 都要人工处理,见 人工诊断处理。
  5. 装配:zhin runtime migrate cutover --write 生成 package.json#zhin 与 plugin.ts,
  6. 迁移剩余配置:schema.json(只声明本包字段)、Feature mounts、child plugin mounts。
  7. 删旧:删掉旧注册代码、旧入口、compat 依赖。
  8. 验证:构建 + 测试 + 行为验证(命令路由、消息发送、配置默认值、热更新)。

What it can do on your machine

Read from SKILL.md and the folder at commit f38698f. 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
    • rg

    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

Migrate Zhin Plugin Runtime loads about 1.6k tokens when it runs, and up to ~4.3k if it reads all its reference files. Until then it costs about 182 tokens; SKILL.md has 345 words of instructions outside code blocks.

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

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 f38698f, republished under its MIT licence (© zhinjs). 345 words, ~1,572 tokens.

Download SKILL.mdSave it as .claude/skills/migrate-zhin-plugin-runtime/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
migrate-zhin-plugin-runtime
description
Migrate legacy Zhin.js plugins and projects to the convention-based Plugin Runtime — from usePlugin/getPlugin/addCommand/addMiddleware/addComponent/addTool/addCron/declareConfig/useContext and mutable registries to definePlugin + capability directories + Scope/Token resources. Use this whenever a Zhin plugin fails to load under `zhin runtime start`, errors with "does not default-export a Plugin definition", still imports zhin.js/@zhin.js/core/@zhin.js/kernel, or when asked to upgrade, port, modernize, or migrate a Zhin plugin, command, middleware, component, tool, cron job, config schema, or package manifest — even if the user does not say the word "migrate". 适用于旧 Zhin 插件向约定式目录与快照运行时的破坏性迁移。

迁移 Zhin Plugin Runtime

目标是产出纯新架构代码:plugin.ts 只做装配,能力按目录发现,共享状态走 Resource/Token。 不保留 compat runtime,不双写。

先建立事实,再动手

迁移最容易翻车的地方是凭印象改代码。zhin runtime migrate status 会静态分析整个项目并 返回一个状态机,它比任何猜测都准 —— 每一步都以它的输出为准:

bash
zhin runtime migrate status        # 输出 JSON;state 为 ready 时退出码 0,否则 1
state含义下一步
blocked有 error 或 manual 诊断,自动迁移无法证明语义等价人工清掉诊断,见 人工诊断处理
extraction-required还有能自动搬运的注册(automatic > 0)zhin runtime migrate extract --write
cutover-required能力已就位,但 package.json#zhin / plugin.ts 还没生成zhin runtime migrate cutover --write
dual-run仍在从 zhin.js 导入经典 API(usePlugin / MessageCommand 等),或直接 import @zhin.js/core / @zhin.js/kernel改用门面约定 API(definePlugin / defineCommand 等),删掉旧入口
compat仍在 import @zhin.js/next-compat移除 compat 依赖
ready完成跑构建与测试

状态是从上往下判定的:只要还有 manual/error 诊断就一直是 blocked,先清诊断再谈其它。

工作流

  1. 盘点:读目标包的 README、最近的测试、旧入口,弄清用户可见行为(命令、消息、定时、 持久化)。迁移的验收标准是行为不变,不是编译通过。
  2. 看计划:zhin runtime migrate extract --check,逐条读 changes 与 diagnostics。 --check 与 --write 必须二选一,同时给或都不给会直接报错。
  3. 搬能力:zhin runtime migrate extract --write。它只搬模块顶层、且闭包干净的注册, 已存在的目标文件不会被覆盖。
  4. 清诊断:每条 manual 都要人工处理,见 人工诊断处理。 最常见的是 action 捕获了模块级变量 —— 把它提升为 owner Resource,能力文件再从执行上下文读。
  5. 装配:zhin runtime migrate cutover --write 生成 package.json#zhin 与 plugin.ts, 并补齐 zhin.js、@zhin.js/runtime;Stable Features 可由 Root 继承,不必再装 @zhin.js/command|middleware|component(cutover 仍可能按约定目录写入 features 挂载)。启动脚本统一是 zhin runtime start,不要再写失效的 zhin dev / zhin start / zhin build。
    • package.json#private: true 的本地 TS root 使用 entry: "./plugin.ts",直接执行 pnpm dev 或 zhin runtime start。
    • 非 private 的发布包使用 entry: "./plugin.js";cutover 生成独立的 tsconfig.zhin.json、zhin:build 与 prepack / prepublishOnly,以便 pnpm pack 和 npm publish 前把 plugin.ts、约定目录和 src/ 编译成可发布 JS。不要把 plugin.ts 作为发布 manifest 的入口。 已有合法 manifest 会被补齐到相应模式;其它 zhin 字段形态仍需人工处理。
  6. 迁移剩余配置:schema.json(只声明本包字段)、Feature mounts、child plugin mounts。
  7. 删旧:删掉旧注册代码、旧入口、compat 依赖。
  8. 验证:构建 + 测试 + 行为验证(命令路由、消息发送、配置默认值、热更新)。

第 2–5 步之间反复跑 status 是最省事的做法 —— 它会告诉你还差什么。

目标写法

plugin.ts 只装配;能力一个文件一个,default export。完整对照见 迁移映射。

ts
// plugin.ts
import { createToken, definePlugin, databaseHostToken } from 'zhin.js';

export const storeToken = createToken<Store>('my-plugin.store');

export default definePlugin({
  name: 'my-plugin',                       // /^[a-z][a-z0-9-]*$/
  setup(context) {
    // Host 资源都是可选的:先 has 再 use,否则精简安装会装配失败
    if (!context.resources.has(databaseHostToken)) return;
    const db = context.resources.use(databaseHostToken);
    context.resources.provide(storeToken, createStore(db));
    return () => { /* disposer;HMR 回滚时调用 */ };
  },
});
ts
// commands/profile/index.ts —— 目录路径即路由;参数写在目录名里
import { defineCommand } from 'zhin.js/command';
import { storeToken } from '../../plugin.js';

export default defineCommand({
  description: 'Show current user profile',
  async execute(context) {
    const store = context.use(storeToken);   // 能力上下文直接 use,不 import 单例
    return store.describe(context.input.sender.id);
  },
});

两个 context 不是同一个东西,别混用: setup(context) 里 context.resources 是 Scope —— provide / use / has 都挂在它上面。 能力的 execute(context) 拿到的是 CapabilityContext —— 直接 context.use(token) / context.config,没有 context.resources,写成 context.resources.use(...) 会在运行期 报 Cannot read properties of undefined。

硬性规则

这些不是风格偏好,违反会让迁移在运行期而不是编译期爆炸:

  • usePlugin() / getPlugin() 不得出现在能力执行路径。 新运行时不建立 AsyncLocalStorage 上下文,调用它只会拿到一个挂空的孤儿 Plugin,注册的东西永远不生效。
  • 不双写。 同一能力不要既留旧 registry 又建新目录,status 会一直停在 dual-run。
  • 不引入 @zhin.js/next-* 或 legacy callback adapter。
  • Command 参数只由文件名表达,不要在 metadata 里维护第二套路由。
  • 消息发送必须走统一 render/send 链路,不要在能力里直连 endpoint。
  • 自动迁移无法证明语义等价时,保留 diagnostic 人工改写,不要做猜测性替换。
  • 每个 register / 订阅都要有 disposer 交给 context.lifecycle,否则热更新会重复注册。

完成标准

bash
zhin runtime migrate status                  # state 必须是 ready(退出码 0)
rg -n "usePlugin\(|getPlugin\(|add(Command|Middleware|Component|Tool|Cron)\(|@zhin.js/next-" .
pnpm --filter <plugin-package> build
pnpm --filter <plugin-package> test
pnpm check:plugin-runtime-migration-readiness
pnpm check:plugin-runtime-migration-verify

公开插件还必须验证 tarball,而不是只验证源码类型检查:

bash
pnpm --filter <plugin-package> run build
pnpm --filter <plugin-package> pack
# 解开 tarball,确认 package/plugin.js、package/plugin.d.ts 和已编译的能力目录存在

rg 只允许命中文档与迁移测试。ready 意味着静态检查通过,不等于行为等价 —— 平台相关 行为(真实适配器收发、定时触发)要么实测,要么在交付说明里写清未验证项,不要用"编译通过" 替代运行时验证。

仓库门禁

仓库内声明 zhin.type: "plugin" 的包会由 check:plugin-runtime-migration-readiness 做确定性检查。 它只扫描当前 checkout,不读取 cwd 之外的用户项目;tests/、test/、fixtures/、__fixtures__/ 和带 zhin-migration-gate: legacy-fixture 标记的源码会被排除。因此迁移示例可以保留旧 API, 但 native Plugin Runtime 的生产源码不能在函数体内调用 usePlugin() 或 getPlugin()。

离线 Verify

pnpm check:plugin-runtime-migration-verify 是 migration 的离线 E2E verify:先确认 cutover 已经无变更,再用不触发 install 的 pnpm run build 验证构建。私有 development root 额外要求 scripts.dev 与 scripts.start 都是 zhin runtime start;公开 publish package 会执行 pnpm pack,解读 tarball 后确认 package.json#zhin.entry、 plugin.js、plugin.d.ts 和每个已发现能力目录的 JS 产物一致。它不执行 install,也不会访问网络。

© 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 2 other files (references) in .github/skills/migrate-zhin-plugin-runtime of zhinjs/zhin.

  • SKILL.md
  • references/manual-diagnostics.md
  • references/migration-map.md

Open the folder on GitHubat commit f38698f

Compare with similar skills

Migrate Zhin Plugin Runtime 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.

Migrate Zhin Plugin Runtime compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Migrate Zhin Plugin Runtime this skillzhinjs/zhin136—~1.6kAutomated safety check: PassMIT
Daily Briefleiting-eric/DailyBrief367—~3kAutomated safety check: NotesMIT
Env Doctorcat-xierluo/legal-skills720—~756Automated safety check: PassMIT
Nextclaw AutostartPeiiii/nextclaw260—~943Automated safety check: NotesMIT
Golem Recurring Task TSgolemcloud/golem1.5k—~1.8kAutomated safety check: PassCustom licence
Trigger.dev Background Taskspapermark/papermark9.2k—~2.1kAutomated safety check: PassCustom licence

Similar skills

  • Daily Brief

    leiting-eric/DailyBrief

    Operational knowledge for the daily-brief digest pipeline (this project).

    367 GitHub stars~3k tokensUpdated today
    Productivity & AutomationAuto-check: notes
  • Env Doctor

    cat-xierluo/legal-skills

    本机开发环境与全局包的体检、账本与安装纪律,覆盖所有包管理器(npm/npx、nvm、pip/pipx、uv、brew、bun)与运行时环境面(~/.local/bin 垫片、PATH、python 解释器版图、LaunchAgents、cron、shell rc 漂移对照)。当用户问「node/python 为什么是这个版本」「npm/pip…

    720 GitHub stars~756 tokensUpdated today
    Productivity & AutomationAuto-check passed
  • Nextclaw Autostart

    Peiiii/nextclaw

    A skill your agent uses when the user asks about NextClaw autostart, auto-start on login or reboot, daemon/service registration, LaunchAgent, systemd, Windows Scheduled Task, service autostart…

    260 GitHub stars~943 tokensUpdated today
    Productivity & AutomationAuto-check: notes
  • Golem Recurring Task TS

    golemcloud/golem

    Implementing a recurring (cron-like) task in a TypeScript Golem agent by self-scheduling future invocations.

    1.5k GitHub stars~1.8k tokensUpdated today
    Productivity & AutomationAuto-check passed
  • Trigger.dev Background Tasks

    papermark/papermark

    Guides building durable background tasks, scheduled jobs and queues with Trigger.dev, including retries, waits, idempotency and concurrency limits.

    9.2k GitHub stars~2.1k tokensUpdated 1 mo ago
    Backend & APIsAuto-check passed
  • Bun 1.4 Builtins Guide

    code-yeongyu/senpi

    Points the agent at Bun 1.4 built-in APIs before it installs an npm package, so image, browser, markdown, cron, PTY and test work uses what Bun already ships.

    474 GitHub stars~1.3k tokensUpdated today
    DevelopmentAuto-check passed

More from zhinjs/zhin

All 11 skills in this repo
  • Refactor existing Zhin.js plugins into a cleaner standard structure.

    136 GitHub stars~1.1k tokensUpdated today
    Auto-check passed
  • Zhin Audit

    zhinjs/zhin

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

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

    136 GitHub stars~1.8k tokensUpdated today
    Auto-check passed
  • GitHub CLI

    zhinjs/zhin

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

    136 GitHub stars~366 tokensUpdated today
    Auto-check passed
  • Wecom

    zhinjs/zhin

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

    136 GitHub stars~297 tokensUpdated today
    Auto-check passed
  • Checkin

    zhinjs/zhin

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

    136 GitHub stars~167 tokensUpdated today
    Auto-check passed

Works with

Questions about Migrate Zhin Plugin Runtime

What does Migrate Zhin Plugin Runtime do?

Migrate legacy Zhin.js plugins and projects to the convention-based Plugin Runtime — from usePlugin/getPlugin/addCommand/addMiddleware/addComponent/addTool/addCron/declareConfig/useContext and…. Migrate Zhin Plugin Runtime is an agent skill from zhinjs/zhin.js plugins and projects to the convention-based Plugin Runtime — from usePlugin/getPlugin/addCommand/addMiddleware/addComponent/addTool/addCron/declareConfig/useContext and mutable registries to definePlugin + capability directories + Scope/Token resources.

When should I use Migrate Zhin Plugin Runtime?

Migrate Zhin Plugin Runtime fits situations like: tasks that involve Scheduled and recurring tasks.

How do I install Migrate Zhin Plugin Runtime in Claude Code?

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

How do I install Migrate Zhin Plugin Runtime in Codex?

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

Can I use Migrate Zhin Plugin Runtime 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 migrate-zhin-plugin-runtime -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/migrate-zhin-plugin-runtime, .gemini/skills/migrate-zhin-plugin-runtime, .github/skills/migrate-zhin-plugin-runtime and .opencode/skills/migrate-zhin-plugin-runtime in your project.

What does Migrate Zhin Plugin Runtime need to run?

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

Does Migrate Zhin Plugin Runtime 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 Migrate Zhin Plugin Runtime 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 Migrate Zhin Plugin Runtime use?

Migrate Zhin Plugin Runtime 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 Migrate Zhin Plugin Runtime use?

About 1.6k tokens (SKILL.md is roughly 6.3k 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 2.8k tokens, read only when the agent opens those files.

What are the alternatives to Migrate Zhin Plugin Runtime?

Skills that share tags, products or a category with Migrate Zhin Plugin Runtime: Daily Brief (leiting-eric/DailyBrief, 367 stars), Env Doctor (cat-xierluo/legal-skills, 720 stars), Nextclaw Autostart (Peiiii/nextclaw, 260 stars) and Golem Recurring Task TS (golemcloud/golem, 1.5k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Migrate Zhin Plugin Runtime?

zhinjs (a GitHub organization) maintains it in zhinjs/zhin, which has 136 GitHub stars. The repository holds 11 skills in this directory. The repository was last updated on October 10, 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.