@zhouhao4221/devflow-skills 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +289 -0
  3. package/install.js +152 -0
  4. package/package.json +17 -0
package/LICENSE ADDED
@@ -0,0 +1,191 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ Copyright 2026 Haiqing
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,289 @@
1
+ # DevFlow Skills
2
+
3
+ DevFlow 插件技能集合 —— 独立技能包,包含 [DevFlow](https://github.com/zhouhao4221/devflow-claude) 所有插件的 AI 执行指令(SKILL.md)。支持 OpenCode、Claude Code、Codex 三大 AI 工具。
4
+
5
+ ## 快速开始
6
+
7
+ 使用 CLI 工具一键安装技能到目标 AI 工具目录:
8
+
9
+ ```bash
10
+ # 安装全部技能到 OpenCode
11
+ npx devflow-skills install --tool opencode --all
12
+
13
+ # 安装指定技能
14
+ npx devflow-skills install --tool opencode --skill req-dev --skill req-review
15
+
16
+ # 列出所有可用技能
17
+ npx devflow-skills list
18
+
19
+ # 卸载技能
20
+ npx devflow-skills uninstall --tool opencode --all
21
+ ```
22
+
23
+ 首次运行 `npx` 时会自动下载对应平台 Go 二进制,也可通过 Go install 安装:
24
+
25
+ ```bash
26
+ go install github.com/zhouhao4221/devflow-skills@latest
27
+ devflow-skills install --tool claude --all
28
+ ```
29
+
30
+ ## 概述
31
+
32
+ 本仓库从 [devflow-claude](https://github.com/zhouhao4221/devflow-claude) 主仓库中提取所有 SKILL.md 文件,作为独立的技能包提供给 CI 校验、版本管理和跨工具分发。每个 SKILL.md 文件定义了 AI 工具在执行对应命令时的行为指引。
33
+
34
+ ### CLI 命令速览
35
+
36
+ | 命令 | 说明 |
37
+ |------|------|
38
+ | `install` | 安装技能到目标 AI 工具目录 |
39
+ | `list` | 列出所有可用技能,支持按插件过滤和 JSON 输出 |
40
+ | `uninstall` | 从目标 AI 工具目录卸载技能 |
41
+
42
+ | 参数 | 说明 |
43
+ |------|------|
44
+ | `--tool opencode\|claude\|codex` | 目标 AI 工具(必填) |
45
+ | `--skill <NAME>` | 要操作的技能名,支持重复指定多个 |
46
+ | `--all` | 操作所有技能(与 `--skill` 互斥) |
47
+ | `--dir <PATH>` | 目标项目根目录(默认 `.`) |
48
+ | `--plugin <NAME>` | 按插件过滤(`list` 命令) |
49
+ | `--format text\|json` | 输出格式(`list` 命令) |
50
+
51
+ ### CLI 安装示例
52
+
53
+ ```bash
54
+ # OpenCode: 安装到 .agents/skills/(扁平命名,如 req-dev)
55
+ npx devflow-skills install --tool opencode --skill req-dev
56
+
57
+ # Claude Code: 安装到 plugins/req/skills/dev/(分层目录)
58
+ npx devflow-skills install --tool claude --all
59
+
60
+ # Codex: 安装到 .agents/skills/(扁平命名,同上)
61
+ npx devflow-skills install --tool codex --all
62
+
63
+ # 指定目标目录
64
+ npx devflow-skills install --tool opencode --all --dir ../my-project
65
+ ```
66
+
67
+ ## 仓库结构
68
+
69
+ ```
70
+ plugins/
71
+ ├── req/skills/ # 需求管理技能(46 个)
72
+ ├── api/skills/ # API 对接技能(8 个)
73
+ ├── pm/skills/ # 项目管理技能(14 个)
74
+ ├── diag/skills/ # 生产诊断技能(5 个)
75
+ └── uat/skills/ # 验收测试技能(7 个)
76
+ skill-bindings.json # 命令-技能映射关系
77
+ ```
78
+
79
+ ## 技能分类
80
+
81
+ ### req — 需求全流程管理
82
+ 覆盖从需求分析、评审、开发、测试到归档的完整生命周期,包括智能开发(`dev`)、规范提交(`commit`)、版本发布(`release`)、代码审查(`review-pr`)、自然语言调度(`natural-language-dispatcher`)等 46 个技能。
83
+
84
+ **自动触发技能**:
85
+ | 技能 | 触发场景 |
86
+ |------|---------|
87
+ | `requirement-analyzer` | 创建/编辑需求时自动分析 |
88
+ | `dev-guide` | 开发阶段按分层架构引导 |
89
+ | `quick-fix-guide` | 快速修复时引导 |
90
+ | `test-guide` | 测试阶段引导回归和新建 |
91
+ | `prd-analyzer` | PRD 编辑时辅助完善 |
92
+ | `code-impact-analyzer` | 需求变更时分析代码影响 |
93
+ | `changelog-generator` | 自动生成版本变更说明 |
94
+ | `version-bumper` | 发版时自动推导版本号 |
95
+
96
+ ### api — API 对接
97
+ 支持 Swagger/OpenAPI 解析、字段映射、代码生成、接口搜索等 8 个技能。
98
+
99
+ ### pm — 项目管理助手
100
+ 从 PRD、需求文档和 Git 记录中提取数据,生成汇报、统计、方案等 14 个技能。
101
+
102
+ ### diag — 生产诊断
103
+ 只读诊断 + 修复建议,包含审计、堆栈分析等 5 个技能,含安全风控 Hook。
104
+
105
+ ### uat — 用户验收测试
106
+ UI 验收测试工作流,含测试执行器、报告生成等 7 个技能。
107
+
108
+ ## skill-bindings.json
109
+
110
+ `skill-bindings.json` 声明了命令与技能之间的映射关系:
111
+
112
+ ```json
113
+ {
114
+ "plugins": {
115
+ "req": {
116
+ "commands": {
117
+ "dev": {
118
+ "primarySkill": "dev",
119
+ "additionalSkills": ["dev-guide"]
120
+ }
121
+ }
122
+ }
123
+ },
124
+ "allSkills": {
125
+ "req": ["dev", "dev-guide", ...]
126
+ }
127
+ }
128
+ ```
129
+
130
+ - `commands.<name>.primarySkill`: 命令直接对应的技能
131
+ - `commands.<name>.additionalSkills`: 命令执行过程中自动触发的辅助技能
132
+ - `allSkills`: 各插件拥有的全部技能清单
133
+
134
+ CI 会验证:
135
+ 1. `allSkills` 中声明的技能都有对应的 `SKILL.md` 文件
136
+ 2. 实际存在的 `SKILL.md` 文件都在 `allSkills` 中有声明
137
+ 3. 命令中引用的技能名都在 `allSkills` 中存在
138
+
139
+ ## CI 校验
140
+
141
+ 每次 push 或 PR 时自动运行 CI(`.github/workflows/ci.yml`),包含:
142
+
143
+ | 检查项 | 说明 |
144
+ |--------|------|
145
+ | validate-source | 全量校验 80 个 SKILL.md 是否符合 agentskills.io 规范(name 正则、description 长度) |
146
+ | validate-claude | setup-claude 脚本输出完整性检查 |
147
+ | validate-opencode | setup-opencode 输出 frontmatter 格式 + 计数 |
148
+ | validate-codex | setup-codex + openai.yaml 输出完整性 |
149
+
150
+ 本地手动运行:`./scripts/validate-skills.sh --ci`
151
+
152
+ ---
153
+
154
+ ## 手动安装(适配器脚本)
155
+
156
+ CLI 工具(上节)已覆盖所有常见场景。如需在不同环境分配不同路径、或嵌入 CI 流程,可通过适配器脚本手动生成。
157
+
158
+ devflow-skills 作为唯一起源,通过适配器脚本生成各工具兼容的技能目录。以下分别说明 Claude Code、OpenCode、Codex 三工具的安装方式。
159
+
160
+ ### 前置条件
161
+
162
+ - 已 clone 本仓库
163
+ - Python 3 可用(用于 `_get-description.py`)
164
+
165
+ ### Claude Code
166
+
167
+ Claude Code 通过插件 marketplace 加载技能,使用分层目录结构(`plugins/<plugin>/skills/<name>/SKILL.md`)。
168
+
169
+ ```bash
170
+ # 同步技能到 devflow-claude 仓库
171
+ ./scripts/setup-claude.sh . ../devflow-claude
172
+ # 参数: <devflow-skills路径> [devflow-claude路径]
173
+ ```
174
+
175
+ 产物路径:`../devflow-claude/plugins/<plugin>/skills/<name>/SKILL.md`(80 个文件,与源结构一致)。由 devflow-claude 的 `plugin.json` 加载。
176
+
177
+ ### OpenCode
178
+
179
+ OpenCode 从 `.agents/skills/` 发现技能,使用扁平化命名(`<plugin>-<name>`)。
180
+
181
+ ```bash
182
+ # 生成 OpenCode 兼容的技能目录
183
+ ./scripts/setup-opencode.sh . ~/.agents/skills
184
+ # 参数: <devflow-skills路径> [输出路径,默认 .agents/skills/]
185
+ ```
186
+
187
+ 产物路径:`~/.agents/skills/<plugin>-<name>/SKILL.md`(80 个目录,name 已自动更新为扁平化前缀)。OpenCode 启动时自动发现所有技能。
188
+
189
+ ### Codex
190
+
191
+ Codex 同样从 `.agents/skills/` 发现技能,兼容 agentskills.io 规范。
192
+
193
+ ```bash
194
+ # 基础安装(仅技能目录)
195
+ ./scripts/setup-codex.sh . ~/.agents/skills
196
+
197
+ # 附加生成 UI 元数据清单(agents/openai.yaml)
198
+ ./scripts/setup-codex.sh . ~/.agents/skills --gen-openai-yaml
199
+ ```
200
+
201
+ 产物路径:`~/.agents/skills/<plugin>-<name>/SKILL.md`(80 个目录)。`--gen-openai-yaml` 额外生成 `agents/openai.yaml`,提供 display_name、description 等 UI 元数据。
202
+
203
+ ### 验证安装
204
+
205
+ 安装完成后运行校验脚本确认一切正常:
206
+
207
+ ```bash
208
+ ./scripts/validate-skills.sh --ci
209
+ ```
210
+
211
+ 通过后输出 `SUCCESS: all validations passed`,共 8 项检查全部 PASS。
212
+
213
+ ---
214
+
215
+ ## 设计理念
216
+
217
+ ### 为什么做跨工具 Skill 通用化
218
+
219
+ 当前 80 个 SKILL.md 以 Claude Code marketplace 为原生格式(`plugins/<plugin>/skills/<name>/SKILL.md`),在 Codex、OpenCode 等工具中无法直接加载。各工具的 skill 发现机制不同:
220
+
221
+ | 工具 | 发现路径 | 命名方式 |
222
+ |------|---------|----------|
223
+ | Claude Code | `plugins/<plugin>/skills/<name>/SKILL.md` | 插件层作用域 |
224
+ | OpenCode | `.agents/skills/<name>/SKILL.md` | 全局扁平 |
225
+ | Codex | `.agents/skills/<name>/SKILL.md` | 全局扁平 |
226
+
227
+ **核心思路**:devflow-skills 作为唯一起源(single source of truth),不修改 80 个 SKILL.md 正文内容,通过适配层脚本(adapter scripts)为各工具生成各自的兼容产物。
228
+
229
+ ### 关键设计决策
230
+
231
+ #### D1:统一标准 — 采用 agentskills.io 规范
232
+
233
+ [agentskills.io](https://agentskills.io/specification) 是 Open Agent Skills Standard,Codex 原生内置、OpenCode 兼容支持。格式要求为 YAML frontmatter(`name` + `description` 必填)+ Markdown 正文。当前 80 个 SKILL.md 全部使用此格式,零修改即兼容核心要求。
234
+
235
+ 选择理由:
236
+ - 已被业界采纳(Codex 原生、OpenCode 兼容),非私有标准
237
+ - 格式简洁(两个必填字段 + 可选扩展),与现有 SKILL.md 完全兼容
238
+ - 有明确的命名正则约束(`^[a-z0-9]+(-[a-z0-9]+)*$`),保证跨工具一致性
239
+
240
+ #### D2:命名策略 — `<plugin>-<name>` 扁平化
241
+
242
+ Claude Code 按插件分层(`req/dev`、`api/search`),名字无需全局唯一。但 OpenCode/Codex 是全局扁平名字空间。采用 `<plugin>-<name>` 前缀方案(如 `req-dev`、`api-search`):
243
+
244
+ - **全局唯一**:多个插件下的重名技能(如 `help`、`init`、`new`)加上前缀后自然去重(`req-help` vs `api-help` vs `pm-help`)
245
+ - **可读性强**:一眼可知技能所属插件
246
+ - **符合 agentskills.io 正则**:全部由小写字母、数字、连字符组成
247
+
248
+ 命名变更在适配层处理(复制时通过 `sed` 更新 frontmatter `name` 字段),源头 SKILL.md 正文不动。
249
+
250
+ #### D3:适配路径 — `.agents/skills/` 作为三工具最大公约数
251
+
252
+ OpenCode 和 Codex 均原生扫描 `.agents/skills/`,且 OpenCode 也兼容 `.claude/skills/`。选择 `.agents/skills/` 作为适配器统一输出路径,确保:
253
+ - OpenCode 和 Codex 零配置可用
254
+ - Claude Code 仍通过 `plugins/*/skills/` 加载(setup-claude.sh 直接 copy,不使用 `.agents/skills/`)
255
+
256
+ #### D4:不修改源头 SKILL.md
257
+
258
+ 80 个 SKILL.md 始终保持原样,所有跨工具适配(name 扁平化、路径重组)都在适配器脚本的复制过程中完成。好处:
259
+ - 源头文件干净、可独立维护
260
+ - 各工具适配逻辑独立,互不干扰
261
+ - CI 校验只需对源头文件生效
262
+
263
+ ### 架构总览
264
+
265
+ ```
266
+ ┌────────────────────┐
267
+ │ devflow-skills │ ← 唯一起源
268
+ │ plugins/<plugin>/ │ 80 个 SKILL.md
269
+ │ skills/<name>/ │ 零修改
270
+ │ SKILL.md │
271
+ │ skill-bindings.json│
272
+ └────────┬───────────┘
273
+
274
+ ┌─────────────┼─────────────┐
275
+ ▼ ▼ ▼
276
+ ┌───────────┐ ┌───────────┐ ┌───────────┐
277
+ │ Claude │ │ OpenCode │ │ Codex │
278
+ │ Adapter │ │ Adapter │ │ Adapter │
279
+ └─────┬─────┘ └─────┬─────┘ └─────┬─────┘
280
+ ▼ ▼ ▼
281
+ plugins/*/skills/ .agents/skills/ .agents/skills/
282
+ (分层插件结构) (扁平前缀命名) (扁平前缀命名)
283
+ ```
284
+
285
+ ---
286
+
287
+ ## 许可证
288
+
289
+ [Apache License 2.0](LICENSE)
package/install.js ADDED
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawnSync, execSync } = require('child_process');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const os = require('os');
7
+ const https = require('https');
8
+
9
+ const VERSION = require('./package.json').version;
10
+ const BINARY_NAME = process.platform === 'win32' ? 'devflow-skills.exe' : 'devflow-skills';
11
+
12
+ function getPlatform() {
13
+ const platform = os.platform();
14
+ const arch = os.arch();
15
+
16
+ const archMap = { x64: 'amd64', arm64: 'arm64', ia32: '386' };
17
+ const mappedArch = archMap[arch] || arch;
18
+
19
+ let platformName;
20
+ switch (platform) {
21
+ case 'linux':
22
+ platformName = 'linux';
23
+ break;
24
+ case 'darwin':
25
+ platformName = 'darwin';
26
+ break;
27
+ case 'win32':
28
+ platformName = 'windows';
29
+ break;
30
+ default:
31
+ console.error('不支持的平台: ' + platform);
32
+ process.exit(1);
33
+ }
34
+
35
+ return `${platformName}_${mappedArch}`;
36
+ }
37
+
38
+ function getCacheDir() {
39
+ const dir = path.join(os.homedir(), '.devflow-skills', VERSION);
40
+ if (!fs.existsSync(dir)) {
41
+ fs.mkdirSync(dir, { recursive: true });
42
+ }
43
+ return dir;
44
+ }
45
+
46
+ function downloadBinary(url, dest) {
47
+ return new Promise((resolve, reject) => {
48
+ const file = fs.createWriteStream(dest, { mode: 0o755 });
49
+ https
50
+ .get(url, (response) => {
51
+ if (response.statusCode === 302 || response.statusCode === 301) {
52
+ https.get(response.headers.location, (redirectRes) => {
53
+ redirectRes.pipe(file);
54
+ file.on('finish', () => {
55
+ file.close();
56
+ resolve();
57
+ });
58
+ }).on('error', reject);
59
+ return;
60
+ }
61
+ if (response.statusCode !== 200) {
62
+ reject(new Error(`下载失败 (HTTP ${response.statusCode}): ${url}`));
63
+ return;
64
+ }
65
+ response.pipe(file);
66
+ file.on('finish', () => {
67
+ file.close();
68
+ resolve();
69
+ });
70
+ })
71
+ .on('error', reject);
72
+ });
73
+ }
74
+
75
+ function getPackageDir() {
76
+ return path.dirname(require.resolve('./package.json'));
77
+ }
78
+
79
+ async function getBinary() {
80
+ const cacheDir = getCacheDir();
81
+ const binaryPath = path.join(cacheDir, BINARY_NAME);
82
+
83
+ if (fs.existsSync(binaryPath)) {
84
+ return binaryPath;
85
+ }
86
+
87
+ const pkgDir = getPackageDir();
88
+ const localBinary = path.join(pkgDir, BINARY_NAME);
89
+ if (fs.existsSync(localBinary)) {
90
+ process.stderr.write('使用本地构建的二进制。\n');
91
+ return localBinary;
92
+ }
93
+
94
+ const platform = getPlatform();
95
+ const suffix = process.platform === 'win32' ? '.exe' : '';
96
+ const url = `https://github.com/zhouhao4221/devflow-skills/releases/download/v${VERSION}/devflow-skills_${platform}${suffix}`;
97
+
98
+ process.stderr.write(`首次运行,正在下载 devflow-skills v${VERSION} (${platform})...\n`);
99
+
100
+ try {
101
+ await downloadBinary(url, binaryPath);
102
+ process.stderr.write('下载完成。\n');
103
+ } catch (e) {
104
+ process.stderr.write('下载失败,尝试本地构建...\n');
105
+ try {
106
+ const goBuild = spawnSync('go', ['build', '-o', binaryPath, pkgDir], {
107
+ cwd: pkgDir,
108
+ stdio: 'inherit',
109
+ });
110
+ if (goBuild.status === 0 && fs.existsSync(binaryPath)) {
111
+ return binaryPath;
112
+ }
113
+ } catch (_) {}
114
+
115
+ process.stderr.write('本地构建失败,尝试使用 go install...\n');
116
+ try {
117
+ const goInstall = spawnSync('go', ['install', `github.com/zhouhao4221/devflow-skills@v${VERSION}`], {
118
+ stdio: 'inherit',
119
+ });
120
+ if (goInstall.status !== 0) {
121
+ console.error('go install 失败。请确保已安装 Go 1.21+ 或手动下载二进制。');
122
+ console.error(`GitHub Releases: https://github.com/zhouhao4221/devflow-skills/releases/tag/v${VERSION}`);
123
+ process.exit(1);
124
+ }
125
+ const goBinPath = path.join(os.homedir(), 'go', 'bin', BINARY_NAME);
126
+ if (fs.existsSync(goBinPath)) {
127
+ fs.copyFileSync(goBinPath, binaryPath);
128
+ fs.chmodSync(binaryPath, 0o755);
129
+ return binaryPath;
130
+ }
131
+ } catch (e2) {
132
+ console.error('go install 失败:', e2.message);
133
+ process.exit(1);
134
+ }
135
+ }
136
+
137
+ fs.chmodSync(binaryPath, 0o755);
138
+ return binaryPath;
139
+ }
140
+
141
+ async function main() {
142
+ const binaryPath = await getBinary();
143
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
144
+ stdio: 'inherit',
145
+ });
146
+ process.exit(result.status || 0);
147
+ }
148
+
149
+ main().catch((err) => {
150
+ console.error('运行失败:', err.message);
151
+ process.exit(1);
152
+ });
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@zhouhao4221/devflow-skills",
3
+ "version": "0.2.0",
4
+ "description": "一键安装/管理 devflow-skills AI 技能包",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/zhouhao4221/devflow-skills.git"
9
+ },
10
+ "bin": {
11
+ "devflow-skills": "install.js"
12
+ },
13
+ "files": [
14
+ "install.js",
15
+ "package.json"
16
+ ]
17
+ }