计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
build-cli-plugin【效率与协作】Build a plugin or adapter for a CLI tool using the abstract base class pattern. Covers defining the contract (static fields, required methods), choosing an installation strategy (symlink, copy, append-to-file), implementing detection, install/uninstall with idempotency, listing, auditing, and registering the plugin. Use when adding support for a new …
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
以抽象基類之式加新插件或適配於 CLI 工具之可插架。
symlink、copy、file-per-item、或 append-to-file基類立諸插件必施之介:
export class FrameworkAdapter {
static id = 'base'; // Unique identifier
static displayName = 'Base'; // Human-readable name
static strategy = 'symlink'; // Installation strategy
static contentTypes = ['skill']; // What this adapter handles
async detect(projectDir) { return false; }
getTargetPath(projectDir, scope) { throw new Error('Not implemented'); }
async install(item, projectDir, scope, options) { throw new Error('Not implemented'); }
async uninstall(item, projectDir, scope, options) { throw new Error('Not implemented'); }
async listInstalled(projectDir, scope) { return []; }
async audit(projectDir, scope) { return { framework: this.constructor.displayName, ok: [], warnings: [], errors: [] }; }
supports(contentType) { return this.constructor.contentTypes.includes(contentType); }
}
靜態欄定插件之身與能:
id:用於 --framework <id> 選與果報displayName:人讀之輸出所見strategy:定內容達標之法contentTypes:篩此適配所收之項若基類未建,先建之。此式可擴至任數之插件。
得: 基類備,含靜身欄與抽象法。
敗則: 若基類有法不適諸插件(如諸框架未皆支 audit),供默實為合理之無作。
| Strategy | When to use | Example |
|---|---|---|
| symlink | Target reads source files directly. Cheapest, stays in sync. | Claude Code reads .claude/skills/<name>/ symlinks |
| copy | Target needs files in its own directory. Modifications don't propagate. | Some IDEs index only their own dirs |
| file-per-item | Target expects one file per item with specific format. | Cursor .mdc rules files |
| append-to-file | Target reads a single instructions file. | Aider CONVENTIONS.md, Codex AGENTS.md |
略決施之形:
symlinkSync(source, target) — 理相對與絕對之路cpSync(source, target, { recursive: true }) — 理覆寫writeFileSync(target, transform(content)) — 或須格式轉得: 已擇略,附清由,據標框架如何察內容。
敗則: 若不定,察框架之文如何察設或指檔。若框架讀任目,默為 symlink。
察告 CLI 項目中何框架存:
// In detector.js — each rule checks for a filesystem marker
const RULES = [
{
id: 'my-framework',
displayName: 'My Framework',
check: (dir) => existsSync(resolve(dir, '.myframework/')),
marker: '.myframework/',
scope: 'project',
},
];
察之略:
.claude/、.cursor/、.gemini/opencode.json、.aider.conf.ymlAGENTS.md、CONVENTIONS.md~/.openclaw/、~/.hermes/恆於察果中返標,令用者知框架何以被察。
得: 察律穩識框架而無誤報。
敗則: 若框架無獨標(泛目名),合諸標用之,或須明之 --framework 指。
async install(item, projectDir, scope, options) {
const targetDir = this.getTargetPath(projectDir, scope);
const targetPath = resolve(targetDir, item.id);
// Idempotency: skip if already installed (unless force)
if (existsSync(targetPath) && !options.force) {
return { action: 'skipped', path: targetPath };
}
if (options.dryRun) {
return { action: 'created', path: targetPath, details: 'dry-run' };
}
// Ensure parent directory exists
mkdirSync(targetDir, { recursive: true });
// Strategy-specific installation
if (this.constructor.strategy === 'symlink') {
const relPath = relative(targetDir, item.sourceDir);
symlinkSync(relPath, targetPath);
} else if (this.constructor.strategy === 'copy') {
cpSync(item.sourceDir, targetPath, { recursive: true });
}
return { action: 'created', path: targetPath };
}
冪等之律:
--force:略--force:覆(先刪而後裝)action: 'created'{ action, path, details? }得: 裝於標路建內容,若存則略,敬 --force 與 --dry-run。
敗則: Windows/NTFS 上 symlink 建敗者,降為目 junction 或 copy。記降級。
async uninstall(item, projectDir, scope, options) {
const targetDir = this.getTargetPath(projectDir, scope);
const targetPath = resolve(targetDir, item.id);
if (!existsSync(targetPath)) {
return { action: 'skipped', path: targetPath };
}
if (options.dryRun) {
return { action: 'removed', path: targetPath };
}
// Remove the installed content
rmSync(targetPath, { recursive: true });
return { action: 'removed', path: targetPath };
}
清之考:
得: 卸只刪插件之內容,他無損。
敗則: 若刪敗(權、鎖),返錯果而非拋。
async listInstalled(projectDir, scope) {
const targetDir = this.getTargetPath(projectDir, scope);
if (!existsSync(targetDir)) return [];
const entries = readdirSync(targetDir);
return entries.map(name => {
const fullPath = resolve(targetDir, name);
const broken = lstatSync(fullPath).isSymbolicLink()
&& !existsSync(fullPath);
return { id: name, type: 'skill', broken };
});
}
async audit(projectDir, scope) {
const items = await this.listInstalled(projectDir, scope);
const ok = items.filter(i => !i.broken);
const broken = items.filter(i => i.broken);
return {
framework: this.constructor.displayName,
ok: [`${ok.length} skills installed`],
warnings: [],
errors: broken.map(i => `Broken: ${i.id}`),
};
}
得: 列返諸裝項,含斷鏈之察。察總其康。
敗則: 若標目不存,返空果(非錯——乃框架未裝)。
// In adapters/index.js
import { MyFrameworkAdapter } from './my-framework.js';
register(MyFrameworkAdapter);
註令適配可用於:
detectFrameworks() → getAdaptersForDetections())--framework my-framework)listAdapters())得: 適配見於 tool detect 之輸出,可以 --framework 指之。
敗則: 若適配不現,驗 static id 合察律之 id 且 register() 已呼。
describe('adapter: my-framework (dry-run)', () => {
it('targets the correct path', () => {
const out = run('install create-skill --framework my-framework --dry-run');
assert.match(out, /\.myframework/i);
});
});
至少測:乾行之路、察之存、內容類之支。
得: 適配特測證裝之路與行。
敗則: CI 中無標目而框架不察者,測中明用 --framework。
id、displayName、strategy、contentTypes)已設install() 冪等(若存則略,敬 --force)uninstall() 只刪插件所建者listInstalled() 察斷 symlinkaudit() 準報康tool detectmkdirSync(dir, { recursive: true }) 於建內容前<!-- start:id --> / <!-- end:id -->),反覆裝重內容。恆以標裹附之內容.config/)或合多框架。用目內之特檔標supports() 察:裝器於派前呼 supports(item.type)。若 contentTypes 誤,適配默略項scaffold-cli-command — 建用此插件之 CLI 命test-cli-application — CLI 工具之測模式,含適配測design-cli-output — 裝卸果之終端輸出