Community寫作與編輯github.com

TrueHOOHA/dsh-plugin-dev-skill

AI 技能,用于開發 DeepSeek Harness (dsh) 插件——基於 Cordis 的代理框架。協助創建與發布 tool、service、LLM adapter、event listener 等能力。

dsh-plugin-dev-skill 是什麼?

此 AI 技能專為開發 DeepSeek Harness (dsh) 插件而設計,dsh 是一個基於 Cordis 的代理框架。它覆蓋了建立和發布各種 plugin 功能的全流程,包括 tool、service、LLM adapter 與 event listener。技能文件提供了詳細的快速參考指南,涵蓋 plugin 結構(函式、物件、類別)、依賴注入(inject)、資源自動清理(ctx.effect)、子 plugin 管理(ctx.plugin)、以及 fiber 狀態機(PENDING→FAILED/ACTIVE→DISPOSED)的除錯。此外,它還說明了如何透過 defineTool 定義 tool、使用 Schemastery 定義 plugin Config、提供/消費服務(Service 類別與介面擴充)、使用事件模式(emit、parallel、serial、bail、waterfall)、實作 LLM adapter(stream 方法與錯誤處理),以及採用三層能力設計模式。技能同時支援本地開發與 npm 發布,並包含 HMR(熱模組替換)設定方法與 PENDING 狀態的診斷技巧。此技能適用於 Claude Code、Codex、Cline、Cursor 等 AI 代理開發工具,旨在讓 AI 代理能精準協助開發者在其專案中撰寫和除錯 dsh plugin。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add TrueHOOHA/dsh-plugin-dev-skill

Installed? Explore more 寫作與編輯 skills: steipete/notion, langchain-ai/langchain, bytedance/podcast-generation · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

dsh Plugin Development

為 DeepSeek Harness (dsh) 開發插件,這是一個基於 Cordis 的代理框架。插件是 TypeScript 模組,匯出 apply(ctx: Context),並透過 cordis.yml 進行組合。

快速參考

Plugin 結構

import type { Context } from '@deepseek-ai/cordis'
export const name = 'my-plugin'
export function apply(ctx: Context) { /* 註冊能力 */ }

三種形式:函式(預設)、物件({ name, inject, apply })、類別 (extends Service — 僅在為其他 plugin 提供服務時使用)。

依賴:export const inject = ['tools', 'llm'] — 框架會保持 plugin 狀態為 PENDING,直到所有注入的服務都已就緒。

自動清理:所有透過 ctx 註冊的內容都是 effect — 卸載時會自動清理。對於自訂資源(計時器、連線),請包裝在 ctx.effect(() => { ... return () => cleanup }) 中。

子 Plugin:const fiber = ctx.plugin(childPlugin) — 子 plugin 繼承父 context; await fiber.dispose() 會遞迴卸載。

Fiber 狀態

PENDING → LOADING → ACTIVE → UNLOADING → DISPOSED
                 ↘ FAILED

PENDING → 缺少服務依賴。FAILED → apply 拋出錯誤或設定驗證失敗。服務在執行期間消失會自動卸載依賴的 plugin。

工具 (Tools)

import { defineTool } from '@deepseek-ai/dsh-tools'
export const inject = ['tools']
export function apply(ctx: Context) {
  ctx.tools.register(defineTool({
    name: 'greet', description: '...',
    parameters: { name: { type: 'string', required: true } },
    output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] },
    async execute(args) { return `Hello, ${args.name}!` },
  }))
}

defineTool 會將參數轉換為 JSON Schema,驗證參數,並在卸載時自動取消註冊。 詳見 references/basic/tool.md。

設定 (Configuration)

import Schema from '@deepseek-ai/schemastery'
export interface Config { greeting: string; maxRetries: number }
export const Config: Schema<Config> = Schema.object({
  greeting: Schema.string().default('Hello'),
  maxRetries: Schema.number().default(3),
})
export function apply(ctx: Context, config: Config) { /* 已驗證的設定 */ }

必須同時匯出 interface Config 和 const Config: Schema<Config>。 無效的設定會導致 FAILED 狀態並顯示清楚的錯誤訊息。在 YAML 中使用 !!js 來表示動態 值:config: { apiKey: !!js process.env.API_KEY }。 詳見 references/basic/config.md。

服務 (Services)

提供:class extends Service { constructor(ctx) { super(ctx, 'name') } }

  • declare module '@deepseek-ai/cordis' { interface Context { name: NameService } }

消費:export const inject = ['name'] → ctx.name.method()。

可選:ctx.get('name') → 當不存在時回傳 undefined。

服務隔離:group: true + isolate: { shell: true } 會為每個群組提供自己的 provider 實例。詳見 references/framework/service.md。

事件 (Events)

模式呼叫方式用途
emitctx.emit(n, ...args)同步廣播,忽略回傳值
parallelawait ctx.parallel(n, ...args)並行監聽器
serialawait ctx.serial(n, ...args)順序執行,第一個非 null 的值獲勝
bailctx.bail(n, ...args)同步順序
waterfallctx.waterfall(n, ...args, next)中介軟體鏈

Waterfall 監聽器必須呼叫 next(),除非有意提前短路。 關鍵 harness 事件:agent/step、tools/result、session/event。 詳見 references/framework/events.md。

LLM 轉接器 (Adapters)

class MyAdapter extends LlmAdapter {
  async *stream(options: GenerateOptions): AsyncIterable<StreamChunk> {
    // 轉換 → provider API → yield StreamChunk
  }
}
ctx.llm.registerAdapter(['my-provider'], adapter)

每個區塊的 StreamChunk 順序:block-start → text-delta/tool-call-delta → block-end → usage → finish。拋出帶有穩定錯誤碼的 LlmError。 詳見 references/practice/llm-adapter.md。

三層能力設計

定義(Service 抽象類別)→ 提供者(實作)→ 消費者(工具)

三者都透過 inject 共用相同的服務名稱。僅在角色需要獨立演化時才拆分為獨立套件。 詳見 references/practice/index.md。

cordis.yml / 套件 (Bundles)

本地開發:--patch ./cordis.patch.yml

- insert:
    - id: my-plugin
      name: '/absolute/path/to/src/my-plugin.ts'
      config: { greeting: 'Hi' }

發布:包含 dsh.bundle 清單 + cordis.patch.yml 的 npm 套件。 安裝:dsh plugin --profile demo add ./hello-plugin。 層級順序:profile bundles → profile patch → home patch → --patch 覆蓋層。 後面的層級按行覆蓋(沒有深度合併)。 詳見 references/basic/publish.md。

HMR

載入 @deepseek-ai/cordis-plugin-hmr + @deepseek-ai/cordis-plugin-logger-console

  • @deepseek-ai/cordis-plugin-timer 以在檔案儲存時自動重新載入。

診斷 PENDING

import { FiberState, type Context } from '@deepseek-ai/cordis'
for (const fiber of ctx.registry.values().flatMap(r => r.fibers))
  if (fiber.state === FiberState.PENDING)
    console.log(`${fiber.name} is PENDING`)

參考文件

references/ 目錄中的詳細指南:

路徑涵蓋內容
references/basic/第一個 plugin、工具、設定、發布
references/framework/生命週期、服務、事件
references/practice/三層設計、LLM 轉接器
references/cordis-tutorial/Cordis 框架逐步教學

相關技能