@jspg-ai/coding-bb 0.0.3-beta.6 → 0.0.3-beta.8
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.
- package/cbb/dev-standards/rules/cbb-ai-behavior.md +1 -1
- package/cbb/lib/install/claude-code.js +1 -3
- package/cbb/lib/install/codebuddy.js +0 -2
- package/cbb/lib/install/init.js +115 -85
- package/cbb/lib/install/opencode.js +1 -5
- package/cbb/lib/install/qoder.js +1 -3
- package/cbb/lib/install/trae.js +0 -2
- package/cbb/lib/openspec/index.js +337 -554
- package/cbb/lib/superpowers/index.js +246 -265
- package/cbb/lib/utils/tar.js +92 -0
- package/cbb/lib/utils/upstream.js +90 -0
- package/cbb/worktrees/skills/cbb-worktree-close/SKILL.md +31 -22
- package/cbb/worktrees/skills/cbb-worktree-init/SKILL.md +21 -22
- package/cbb/worktrees/skills/cbb-worktree-push/SKILL.md +66 -30
- package/config/openspec/schemas/spec-driven/schema.yaml +21 -30
- package/config/openspec/schemas/spec-driven/templates/design.md +0 -18
- package/config/openspec/schemas/spec-driven/templates/proposal.md +4 -3
- package/config/upstream-mirrors.json +12 -0
- package/config/workspace-agents.sample.md +6 -6
- package/openspec/.version +2 -3
- package/openspec/commands/apply.md +189 -175
- package/openspec/commands/archive.md +237 -216
- package/openspec/commands/bulk-archive.md +355 -327
- package/openspec/commands/continue.md +116 -105
- package/openspec/commands/explore.md +230 -199
- package/openspec/commands/ff.md +115 -104
- package/openspec/commands/new.md +74 -63
- package/openspec/commands/onboard.md +557 -548
- package/openspec/commands/propose.md +161 -150
- package/openspec/commands/sync.md +277 -249
- package/openspec/commands/update.md +92 -80
- package/openspec/commands/verify.md +175 -162
- package/openspec/skills/openspec-apply-change/SKILL.md +20 -5
- package/openspec/skills/openspec-archive-change/SKILL.md +30 -8
- package/openspec/skills/openspec-bulk-archive-change/SKILL.md +36 -6
- package/openspec/skills/openspec-continue-change/SKILL.md +14 -2
- package/openspec/skills/openspec-explore/SKILL.md +21 -9
- package/openspec/skills/openspec-ff-change/SKILL.md +14 -2
- package/openspec/skills/openspec-new-change/SKILL.md +13 -1
- package/openspec/skills/openspec-onboard/SKILL.md +49 -39
- package/openspec/skills/openspec-propose/SKILL.md +15 -3
- package/openspec/skills/openspec-sync-specs/SKILL.md +31 -2
- package/openspec/skills/openspec-update-change/SKILL.md +27 -14
- package/openspec/skills/openspec-verify-change/SKILL.md +17 -3
- package/package.json +1 -1
- package/superpowers/.version +4 -4
- package/superpowers/skills/brainstorming/SKILL.md +47 -12
- package/superpowers/skills/brainstorming/scripts/frame-template.html +213 -213
- package/superpowers/skills/brainstorming/scripts/server.cjs +723 -723
- package/superpowers/skills/brainstorming/visual-companion.md +6 -6
- package/superpowers/skills/diagnosing-superpowers/SKILL.md +120 -0
- package/superpowers/skills/diagnosing-superpowers/prompts/analyst-common.md +38 -0
- package/superpowers/skills/diagnosing-superpowers/prompts/cost-and-time.md +28 -0
- package/superpowers/skills/diagnosing-superpowers/prompts/plan-adherence.md +29 -0
- package/superpowers/skills/diagnosing-superpowers/prompts/quality-evidence.md +26 -0
- package/superpowers/skills/diagnosing-superpowers/prompts/repeated-work.md +30 -0
- package/superpowers/skills/diagnosing-superpowers/prompts/request-conflicts.md +20 -0
- package/superpowers/skills/diagnosing-superpowers/prompts/scrub-audit.md +33 -0
- package/superpowers/skills/diagnosing-superpowers/prompts/scrub.md +29 -0
- package/superpowers/skills/diagnosing-superpowers/prompts/similar-session.md +38 -0
- package/superpowers/skills/diagnosing-superpowers/prompts/skill-timeline.md +30 -0
- package/superpowers/skills/diagnosing-superpowers/prompts/stumbles.md +28 -0
- package/superpowers/skills/diagnosing-superpowers/references/context-safety.md +22 -0
- package/superpowers/skills/diagnosing-superpowers/references/github-issues.md +47 -0
- package/superpowers/skills/diagnosing-superpowers/references/redaction-policy.md +34 -0
- package/superpowers/skills/diagnosing-superpowers/references/session-discovery.md +31 -0
- package/superpowers/skills/diagnosing-superpowers/templates/bundle-README.md +77 -0
- package/superpowers/skills/diagnosing-superpowers/templates/case.md +64 -0
- package/superpowers/skills/diagnosing-superpowers/templates/issue.md +51 -0
- package/superpowers/skills/diagnosing-superpowers/templates/report.md +82 -0
- package/superpowers/skills/executing-plans/SKILL.md +350 -41
- package/superpowers/skills/executing-plans/scripts/task-done +52 -0
- package/superpowers/skills/executing-plans/scripts/task-start +28 -0
- package/superpowers/skills/requesting-code-review/SKILL.md +1 -1
- package/superpowers/skills/requesting-code-review/code-reviewer.md +17 -0
- package/superpowers/skills/subagent-driven-development/SKILL.md +18 -18
- package/superpowers/skills/subagent-driven-development/re-review-prompt.md +1 -1
- package/superpowers/skills/subagent-driven-development/scripts/review-package +53 -46
- package/superpowers/skills/subagent-driven-development/scripts/sdd-workspace +82 -40
- package/superpowers/skills/subagent-driven-development/scripts/task-brief +43 -41
- package/superpowers/skills/subagent-driven-development/task-reviewer-prompt.md +2 -2
- package/superpowers/skills/systematic-debugging/root-cause-tracing.md +1 -1
- package/superpowers/skills/test-driven-development/SKILL.md +10 -0
- package/superpowers/skills/using-superpowers/SKILL.md +2 -0
- package/superpowers/skills/using-superpowers/references/claude-code-tools.md +29 -0
- package/superpowers/skills/using-superpowers/references/muse-tools.md +35 -0
- package/superpowers/skills/writing-plans/SKILL.md +30 -9
- package/superpowers/skills/writing-skills/SKILL.md +4 -2
- package/superpowers/skills/writing-skills/graphviz-conventions.dot +171 -171
- package/cbb/worktrees/commands/worktree-close.md +0 -63
- package/cbb/worktrees/commands/worktree-init.md +0 -50
- package/cbb/worktrees/commands/worktree-push.md +0 -42
|
@@ -1,265 +1,246 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Superpowers Skills 管理模块
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* 提供 cbbm update --upstream-superpowers 选项,以及 init 时的自动部署能力。
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
'
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'
|
|
40
|
-
'
|
|
41
|
-
'
|
|
42
|
-
'
|
|
43
|
-
'
|
|
44
|
-
'
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
await
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// ── 导出 ──────────────────────────────────────────────────────────
|
|
250
|
-
|
|
251
|
-
module.exports = {
|
|
252
|
-
// 常量
|
|
253
|
-
SUPERPOWERS_DIR,
|
|
254
|
-
SUPERPOWERS_SKILLS_DIR,
|
|
255
|
-
VERSION_FILE,
|
|
256
|
-
EXPECTED_SKILLS,
|
|
257
|
-
GITHUB_REPO,
|
|
258
|
-
GITHUB_BRANCH,
|
|
259
|
-
|
|
260
|
-
// 核心函数
|
|
261
|
-
fetchLatestSkills,
|
|
262
|
-
getLocalVersion,
|
|
263
|
-
validateSkills,
|
|
264
|
-
getSkillCount,
|
|
265
|
-
};
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Superpowers Skills 管理模块
|
|
5
|
+
*
|
|
6
|
+
* 负责按 pin 的 release tag 从 GitHub 下载 obra/superpowers 的 skills 并部署到本项目。
|
|
7
|
+
* 提供 cbbm update --upstream-superpowers 选项,以及 init 时的自动部署能力。
|
|
8
|
+
*
|
|
9
|
+
* 网络:GitHub 直连可能被墙,走 config/upstream-mirrors.json 的镜像前缀列表
|
|
10
|
+
* (按顺序尝试,首个成功即用;空字符串 = 直连)。
|
|
11
|
+
*
|
|
12
|
+
* 升级方式:cbbm update --upstream-superpowers(按 .version 的 tag 幂等重拉)
|
|
13
|
+
* 版本检查:cbbm check-upstream
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
const os = require('os');
|
|
19
|
+
|
|
20
|
+
const SHARED_STANDARDS_DIR = path.join(__dirname, '..', '..', '..');
|
|
21
|
+
|
|
22
|
+
// Superpowers 本地存储目录
|
|
23
|
+
const SUPERPOWERS_DIR = path.join(SHARED_STANDARDS_DIR, 'superpowers');
|
|
24
|
+
const SUPERPOWERS_SKILLS_DIR = path.join(SUPERPOWERS_DIR, 'skills');
|
|
25
|
+
const VERSION_FILE = path.join(SUPERPOWERS_DIR, '.version');
|
|
26
|
+
|
|
27
|
+
// GitHub 配置
|
|
28
|
+
const GITHUB_REPO = 'obra/superpowers';
|
|
29
|
+
|
|
30
|
+
// 预期的 skill 列表(15 个)
|
|
31
|
+
const EXPECTED_SKILLS = [
|
|
32
|
+
'brainstorming',
|
|
33
|
+
'diagnosing-superpowers',
|
|
34
|
+
'dispatching-parallel-agents',
|
|
35
|
+
'executing-plans',
|
|
36
|
+
'finishing-a-development-branch',
|
|
37
|
+
'receiving-code-review',
|
|
38
|
+
'requesting-code-review',
|
|
39
|
+
'subagent-driven-development',
|
|
40
|
+
'systematic-debugging',
|
|
41
|
+
'test-driven-development',
|
|
42
|
+
'using-git-worktrees',
|
|
43
|
+
'using-superpowers',
|
|
44
|
+
'verification-before-completion',
|
|
45
|
+
'writing-plans',
|
|
46
|
+
'writing-skills',
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const { log } = require('../utils/output');
|
|
50
|
+
const { extractTarGz } = require('../utils/tar');
|
|
51
|
+
const { loadMirrors, fetchWithMirrors } = require('../utils/upstream');
|
|
52
|
+
|
|
53
|
+
// ── 版本管理(pin)────────────────────────────────────────────
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 读取本地 pin(.version 的 tag 字段)。
|
|
57
|
+
* 兼容旧格式:无 tag 时回退 sha。
|
|
58
|
+
* @returns {string|null}
|
|
59
|
+
*/
|
|
60
|
+
function getLocalVersion() {
|
|
61
|
+
if (!fs.existsSync(VERSION_FILE)) return null;
|
|
62
|
+
try {
|
|
63
|
+
const content = fs.readFileSync(VERSION_FILE, 'utf-8').trim();
|
|
64
|
+
if (content.startsWith('{')) {
|
|
65
|
+
const data = JSON.parse(content);
|
|
66
|
+
return data.tag || data.sha || null;
|
|
67
|
+
}
|
|
68
|
+
return content || null;
|
|
69
|
+
} catch (_) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 写入版本信息到 .version 文件。
|
|
76
|
+
* @param {string} tag
|
|
77
|
+
* @param {string} sha
|
|
78
|
+
*/
|
|
79
|
+
function writeVersion(tag, sha) {
|
|
80
|
+
const data = {
|
|
81
|
+
tag,
|
|
82
|
+
sha,
|
|
83
|
+
repo: GITHUB_REPO,
|
|
84
|
+
updatedAt: new Date().toISOString(),
|
|
85
|
+
};
|
|
86
|
+
fs.writeFileSync(VERSION_FILE, JSON.stringify(data, null, 2) + '\n');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ── 上游拉取 ──────────────────────────────────────────────────
|
|
90
|
+
|
|
91
|
+
/** tarball 下载地址(按镜像前缀拼接) */
|
|
92
|
+
function tarballUrl(mirror, tag) {
|
|
93
|
+
return `${mirror}https://api.github.com/repos/${GITHUB_REPO}/tarball/${tag}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** tag → commit sha(走镜像) */
|
|
97
|
+
async function fetchTagSha(tag) {
|
|
98
|
+
const mirrors = loadMirrors('superpowers');
|
|
99
|
+
const { buffer } = await fetchWithMirrors(
|
|
100
|
+
mirrors,
|
|
101
|
+
m => `${m}https://api.github.com/repos/${GITHUB_REPO}/git/ref/tags/${tag}`
|
|
102
|
+
);
|
|
103
|
+
const data = JSON.parse(buffer.toString('utf-8'));
|
|
104
|
+
// annotated tag 指向 tag 对象(需再解一层);lightweight tag 直接是 commit
|
|
105
|
+
return (data.object && data.object.sha) || null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** 最新 release tag(走镜像,用于 check-upstream) */
|
|
109
|
+
async function fetchLatestTag() {
|
|
110
|
+
const mirrors = loadMirrors('superpowers');
|
|
111
|
+
const { buffer } = await fetchWithMirrors(
|
|
112
|
+
mirrors,
|
|
113
|
+
m => `${m}https://api.github.com/repos/${GITHUB_REPO}/releases/latest`
|
|
114
|
+
);
|
|
115
|
+
const data = JSON.parse(buffer.toString('utf-8'));
|
|
116
|
+
return data.tag_name || null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ── 下载与部署 ────────────────────────────────────────────────
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 按 pin 的 tag 下载 tarball,解压出 skills/ 覆盖到 superpowers/skills/。
|
|
123
|
+
* 幂等:重复执行结果一致。
|
|
124
|
+
* @returns {Promise<{tag: string, skillCount: number, skipped: boolean}>}
|
|
125
|
+
*/
|
|
126
|
+
async function fetchLatestSkills() {
|
|
127
|
+
const pin = getLocalVersion();
|
|
128
|
+
if (!pin) {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`未找到 superpowers 版本 pin(${path.relative(SHARED_STANDARDS_DIR, VERSION_FILE)} 缺失或损坏)。\n` +
|
|
131
|
+
`请先写入 { "tag": "vX.Y.Z" } 再执行。`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// pin 一致且 skills 齐全 → 幂等跳过
|
|
136
|
+
const validation = validateSkills();
|
|
137
|
+
if (validation.valid) {
|
|
138
|
+
log(`superpowers 内容已按 pin ${pin} 就位,跳过重拉`, 'success');
|
|
139
|
+
return { tag: pin, skillCount: getSkillCount(), skipped: true };
|
|
140
|
+
}
|
|
141
|
+
log(`检测到 skills 不完整,按 pin ${pin} 重新拉取...`, 'info');
|
|
142
|
+
|
|
143
|
+
const mirrors = loadMirrors('superpowers');
|
|
144
|
+
log(`正在获取 superpowers ${pin}(${mirrors.map(m => m || '直连').join(' → ')})...`, 'info');
|
|
145
|
+
const { buffer, mirror } = await fetchWithMirrors(mirrors, m => tarballUrl(m, pin));
|
|
146
|
+
log(`已从 ${mirror || '(直连)'} 下载 ${(buffer.length / 1024).toFixed(0)} KB`, 'info');
|
|
147
|
+
|
|
148
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cbb-sp-'));
|
|
149
|
+
try {
|
|
150
|
+
log('正在解压...', 'info');
|
|
151
|
+
extractTarGz(buffer, tmpDir);
|
|
152
|
+
|
|
153
|
+
// GitHub tarball 顶层目录名格式:obra-superpowers-<short-sha>
|
|
154
|
+
const entries = fs.readdirSync(tmpDir).filter(f => {
|
|
155
|
+
const p = path.join(tmpDir, f);
|
|
156
|
+
return fs.statSync(p).isDirectory() && f.startsWith('obra-superpowers');
|
|
157
|
+
});
|
|
158
|
+
if (entries.length === 0) throw new Error('解压后未找到 superpowers 目录');
|
|
159
|
+
|
|
160
|
+
const extractedSkills = path.join(tmpDir, entries[0], 'skills');
|
|
161
|
+
if (!fs.existsSync(extractedSkills)) throw new Error('解压后未找到 skills 目录');
|
|
162
|
+
|
|
163
|
+
// 覆盖 skills/
|
|
164
|
+
fs.rmSync(SUPERPOWERS_SKILLS_DIR, { recursive: true, force: true });
|
|
165
|
+
fs.mkdirSync(SUPERPOWERS_SKILLS_DIR, { recursive: true });
|
|
166
|
+
fs.cpSync(extractedSkills, SUPERPOWERS_SKILLS_DIR, { recursive: true });
|
|
167
|
+
|
|
168
|
+
// 记录版本(tag + 其指向的 sha)
|
|
169
|
+
let sha = null;
|
|
170
|
+
try { sha = await fetchTagSha(pin); } catch (_) { /* sha 记录失败不阻塞 */ }
|
|
171
|
+
writeVersion(pin, sha);
|
|
172
|
+
|
|
173
|
+
const skillCount = getSkillCount();
|
|
174
|
+
log(`superpowers skills 已更新: ${pin}(${skillCount} 个)`, 'success');
|
|
175
|
+
return { tag: pin, skillCount, skipped: false };
|
|
176
|
+
} finally {
|
|
177
|
+
try { fs.rmSync(tmpDir, { recursive: true, force: true }); } catch (_) { /* ignore */ }
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 检查上游是否有新版本(不改动任何文件)。
|
|
183
|
+
* @returns {Promise<{current: string|null, latest: string|null, outdated: boolean}>}
|
|
184
|
+
*/
|
|
185
|
+
async function checkUpstream() {
|
|
186
|
+
const current = getLocalVersion();
|
|
187
|
+
const latest = await fetchLatestTag();
|
|
188
|
+
const outdated = Boolean(current && latest && current !== latest);
|
|
189
|
+
return { current, latest, outdated };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ── Skills 校验 ───────────────────────────────────────────────
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* 获取本地 skills 目录中的 skill 数量。
|
|
196
|
+
*/
|
|
197
|
+
function getSkillCount() {
|
|
198
|
+
if (!fs.existsSync(SUPERPOWERS_SKILLS_DIR)) return 0;
|
|
199
|
+
return fs.readdirSync(SUPERPOWERS_SKILLS_DIR)
|
|
200
|
+
.filter(f => {
|
|
201
|
+
const p = path.join(SUPERPOWERS_SKILLS_DIR, f);
|
|
202
|
+
return fs.statSync(p).isDirectory();
|
|
203
|
+
}).length;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 校验本地 skills 完整性:所有预期的 skill 目录存在且包含 SKILL.md。
|
|
208
|
+
* @returns {{valid: boolean, missing: string[], incomplete: string[]}}
|
|
209
|
+
*/
|
|
210
|
+
function validateSkills() {
|
|
211
|
+
const missing = [];
|
|
212
|
+
const incomplete = [];
|
|
213
|
+
|
|
214
|
+
for (const skill of EXPECTED_SKILLS) {
|
|
215
|
+
const skillDir = path.join(SUPERPOWERS_SKILLS_DIR, skill);
|
|
216
|
+
if (!fs.existsSync(skillDir)) {
|
|
217
|
+
missing.push(skill);
|
|
218
|
+
} else if (!fs.existsSync(path.join(skillDir, 'SKILL.md'))) {
|
|
219
|
+
incomplete.push(skill);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return {
|
|
224
|
+
valid: missing.length === 0 && incomplete.length === 0,
|
|
225
|
+
missing,
|
|
226
|
+
incomplete,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// ── 导出 ──────────────────────────────────────────────────────
|
|
231
|
+
|
|
232
|
+
module.exports = {
|
|
233
|
+
// 常量
|
|
234
|
+
SUPERPOWERS_DIR,
|
|
235
|
+
SUPERPOWERS_SKILLS_DIR,
|
|
236
|
+
VERSION_FILE,
|
|
237
|
+
EXPECTED_SKILLS,
|
|
238
|
+
GITHUB_REPO,
|
|
239
|
+
|
|
240
|
+
// 核心函数
|
|
241
|
+
fetchLatestSkills,
|
|
242
|
+
checkUpstream,
|
|
243
|
+
getLocalVersion,
|
|
244
|
+
validateSkills,
|
|
245
|
+
getSkillCount,
|
|
246
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 跨平台 .tar.gz 解压工具。
|
|
5
|
+
*
|
|
6
|
+
* 用 zlib + 手写 tar parser,避开 OS shell tar(Windows 上是 bsdtar、行为不完全一致),
|
|
7
|
+
* 与仓库「脚本语言统一 Node.js、禁止平台绑定脚本」的约定一致。
|
|
8
|
+
*
|
|
9
|
+
* 支持:
|
|
10
|
+
* - gzip 压缩的 tar(GitHub tarball / npm registry tgz 都是这种)
|
|
11
|
+
* - 目录项(type '5' 或名字以 '/' 结尾)
|
|
12
|
+
* - 跳过 pax 扩展头('g'/'x')等元数据伪条目
|
|
13
|
+
* - 路径穿越防护(拒绝 ../ 逃逸 destDir)
|
|
14
|
+
*
|
|
15
|
+
* 不支持(上游 tarball 均不使用,遇到时跳过而非静默损坏):
|
|
16
|
+
* - GNU longname/longlink('L'/'K')—— 超过 100 字符的路径
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const fs = require('fs');
|
|
20
|
+
const path = require('path');
|
|
21
|
+
const zlib = require('zlib');
|
|
22
|
+
|
|
23
|
+
// 非文件、非目录的 tar 条目类型(pax 扩展头、GNU 长名等)
|
|
24
|
+
const META_TYPE_FLAGS = new Set(['g', 'x', 'L', 'K', 'V', 'N']);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 解析 tar buffer,返回条目列表(不落盘)。
|
|
28
|
+
* @param {Buffer} data - 已解压的 tar 数据
|
|
29
|
+
* @returns {Array<{name: string, size: number, typeFlag: string, dataStart: number}>}
|
|
30
|
+
*/
|
|
31
|
+
function listTar(data) {
|
|
32
|
+
const entries = [];
|
|
33
|
+
let off = 0;
|
|
34
|
+
while (off + 512 <= data.length) {
|
|
35
|
+
const header = data.subarray(off, off + 512);
|
|
36
|
+
off += 512;
|
|
37
|
+
|
|
38
|
+
// 连续两个 512 字节零块 = tar 终止
|
|
39
|
+
if (header.every(b => b === 0)) break;
|
|
40
|
+
|
|
41
|
+
// 文件名 header[0..100](NUL 终止)
|
|
42
|
+
let nameEnd = 0;
|
|
43
|
+
while (nameEnd < 100 && header[nameEnd] !== 0) nameEnd++;
|
|
44
|
+
const name = header.subarray(0, nameEnd).toString('utf-8');
|
|
45
|
+
|
|
46
|
+
// 文件大小 header[124..136](八进制 ASCII)
|
|
47
|
+
const size = parseInt(header.subarray(124, 136).toString('utf-8').trim(), 8) || 0;
|
|
48
|
+
|
|
49
|
+
// 类型标志 header[156]('0'/NUL = 普通文件,'5' = 目录)
|
|
50
|
+
const typeFlag = String.fromCharCode(header[156]);
|
|
51
|
+
|
|
52
|
+
entries.push({ name, size, typeFlag, dataStart: off });
|
|
53
|
+
off += Math.ceil(size / 512) * 512;
|
|
54
|
+
}
|
|
55
|
+
return entries;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 解压 .tar.gz buffer 到目标目录。
|
|
60
|
+
* @param {Buffer} compressed - .tar.gz 文件内容
|
|
61
|
+
* @param {string} destDir - 解压目标根目录(不存在则创建)
|
|
62
|
+
* @returns {{files: number, dirs: number}} 落盘计数
|
|
63
|
+
*/
|
|
64
|
+
function extractTarGz(compressed, destDir) {
|
|
65
|
+
const data = zlib.gunzipSync(compressed);
|
|
66
|
+
const root = path.resolve(destDir);
|
|
67
|
+
let files = 0;
|
|
68
|
+
let dirs = 0;
|
|
69
|
+
|
|
70
|
+
for (const entry of listTar(data)) {
|
|
71
|
+
if (!entry.name) continue;
|
|
72
|
+
// 跳过 pax 扩展头等元数据伪条目
|
|
73
|
+
if (META_TYPE_FLAGS.has(entry.typeFlag)) continue;
|
|
74
|
+
|
|
75
|
+
const target = path.resolve(root, entry.name);
|
|
76
|
+
// 路径穿越防护:解压目标必须落在 destDir 内
|
|
77
|
+
if (target !== root && !target.startsWith(root + path.sep)) continue;
|
|
78
|
+
|
|
79
|
+
if (entry.typeFlag === '5' || entry.name.endsWith('/')) {
|
|
80
|
+
fs.mkdirSync(target, { recursive: true });
|
|
81
|
+
dirs += 1;
|
|
82
|
+
} else {
|
|
83
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
84
|
+
fs.writeFileSync(target, data.subarray(entry.dataStart, entry.dataStart + entry.size));
|
|
85
|
+
files += 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return { files, dirs };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = { extractTarGz, listTar };
|