|
| 1 | +--- |
| 2 | +description: Project instructions imported from Claude Code CLAUDE.md |
| 3 | +alwaysApply: true |
| 4 | +--- |
| 5 | +# acplugin 项目规范 |
| 6 | + |
| 7 | +## 项目概述 |
| 8 | + |
| 9 | +acplugin 是一个 CLI 工具,将 Claude Code 插件(Skills、Instructions、MCP、Agents、Commands、Hooks)转换为 Codex CLI、OpenCode 和 Cursor 格式。 |
| 10 | + |
| 11 | +## 技术栈 |
| 12 | + |
| 13 | +- TypeScript + Node.js (CommonJS) |
| 14 | +- Commander.js (CLI) |
| 15 | +- @inquirer/prompts + chalk (TUI) |
| 16 | +- gray-matter (YAML frontmatter) |
| 17 | +- @iarna/toml (TOML 序列化) |
| 18 | +- vitest (测试) |
| 19 | + |
| 20 | +## 项目结构 |
| 21 | + |
| 22 | +``` |
| 23 | +src/ |
| 24 | +├── index.ts # CLI 入口 + 交互式 wizard |
| 25 | +├── types.ts # 所有类型定义 |
| 26 | +├── github.ts # GitHub 仓库下载 |
| 27 | +├── tui.ts # TUI 交互(wizard、checkbox、彩色输出) |
| 28 | +├── scanner/ |
| 29 | +│ ├── claude.ts # .claude/ 项目结构扫描(导出可复用函数) |
| 30 | +│ └── plugin.ts # .claude-plugin/ 插件格式扫描 |
| 31 | +├── converter/ |
| 32 | +│ ├── skill.ts # SKILL.md 转换 |
| 33 | +│ ├── instructions.ts # CLAUDE.md → AGENTS.md / .mdc |
| 34 | +│ ├── mcp.ts # .mcp.json → TOML / JSON |
| 35 | +│ ├── agent.ts # Agent 定义转换(含降级策略) |
| 36 | +│ ├── command.ts # Command 转换 |
| 37 | +│ └── hooks.ts # Hooks 转换(含兼容性报告) |
| 38 | +├── writer/ |
| 39 | +│ ├── codex.ts # Codex 输出编排 |
| 40 | +│ ├── opencode.ts # OpenCode 输出编排 |
| 41 | +│ └── cursor.ts # Cursor 输出编排 |
| 42 | +└── utils/ |
| 43 | + ├── frontmatter.ts # YAML frontmatter 解析/序列化 |
| 44 | + ├── toml.ts # TOML 工具 |
| 45 | + └── fs.ts # 文件系统工具 |
| 46 | +``` |
| 47 | + |
| 48 | +## 架构设计原则 |
| 49 | + |
| 50 | +- **三阶段 Pipeline**: Scanner → Converter → Writer |
| 51 | +- **Scanner 提取可复用函数**: `scanSkillsDir()`, `scanAgentsDir()` 等被 claude.ts 和 plugin.ts 共用 |
| 52 | +- **Converter 无副作用**: 接收数据,返回 `ConvertedFile`,不直接写文件 |
| 53 | +- **Writer 负责编排**: 调用多个 converter,处理合并逻辑(如多个 instruction 合并为一个 AGENTS.md) |
| 54 | +- **降级策略**: 目标平台不支持的功能降级为文档/规则,并输出 warning |
| 55 | + |
| 56 | +## 开发规范 |
| 57 | + |
| 58 | +### 添加新资源类型 |
| 59 | +1. 在 `types.ts` 添加类型定义 |
| 60 | +2. 在 `scanner/claude.ts` 添加扫描函数(导出为可复用) |
| 61 | +3. 在 `scanner/plugin.ts` 集成 |
| 62 | +4. 创建 `converter/xxx.ts`,实现三个平台的转换 |
| 63 | +5. 在三个 `writer/*.ts` 中调用 converter |
| 64 | +6. 添加测试 |
| 65 | + |
| 66 | +### 添加新目标平台 |
| 67 | +1. 在 `types.ts` 的 `Platform` 联合类型添加新值 |
| 68 | +2. 每个 `converter/*.ts` 添加新平台的转换逻辑 |
| 69 | +3. 创建 `writer/newplatform.ts` |
| 70 | +4. 在 `index.ts` 注册 |
| 71 | +5. 在 `tui.ts` 的 `selectPlatforms()` 添加选项 |
| 72 | +6. 添加测试 |
| 73 | + |
| 74 | +### Frontmatter 解析容错 |
| 75 | +- 社区插件的 YAML frontmatter 可能格式不规范 |
| 76 | +- `scanSkillsDir()` 和 `scanAgentsDir()` 已加 try-catch |
| 77 | +- 解析失败时保留原始内容,frontmatter 设为空对象 |
| 78 | + |
| 79 | +### 测试 |
| 80 | +- 测试文件在 `src/__tests__/` |
| 81 | +- test-fixture/ 目录提供完整的 Claude Code 项目示例 |
| 82 | +- 运行: `npm test` 或 `npx vitest run` |
| 83 | +- 每个 converter 模块有独立测试文件 |
| 84 | + |
| 85 | +### npm 发布 |
| 86 | +- 包名: `@disdjj/acplugin` |
| 87 | +- 账号有 2FA,发布需要 OTP: `npm publish --access=public` |
| 88 | +- `prepublishOnly` 自动编译 |
| 89 | +- `files` 字段排除了 `dist/__tests__/` |
| 90 | + |
| 91 | +## Git 规范 |
| 92 | + |
| 93 | +- commit message 使用 conventional commits 格式 |
| 94 | +- 仓库: https://github.com/TokenRollAI/acplugin |
| 95 | +- 主分支: main |
0 commit comments