@wwkit/harness 1.0.33 → 1.0.34
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/LICENSE +21 -21
- package/README.md +128 -128
- package/agents/scrum.md +206 -186
- package/agents/sprint.md +130 -121
- package/bin/index.js +291 -226
- package/commands/fix.md +87 -87
- package/commands/git-sync.md +217 -217
- package/commands/net-port.md +364 -364
- package/commands/pytest.md +10 -10
- package/commands/resume.md +104 -104
- package/commands/tl.md +11 -11
- package/commands/tsl.md +12 -0
- package/package.json +5 -4
- package/plugin.js +19 -19
- package/readme/development.md +39 -39
- package/readme/publish.md +41 -41
- package/readme/testing.md +44 -44
- package/scripts/postinstall.js +58 -58
- package/skills/better-skill/SKILL.md +192 -124
- package/skills/blame-skill/SKILL.md +148 -201
- package/skills/blame-skill/references/scoring-rules.md +190 -0
- package/skills/blame-sprint-agent/SKILL.md +167 -0
- package/skills/blame-sprint-agent/references/scoring-rules.md +113 -0
- package/skills/blame-sprint-skill/SKILL.md +154 -0
- package/skills/blame-sprint-skill/references/scoring-rules.md +101 -0
- package/skills/extract/SKILL.md +119 -119
- package/skills/extract/references/build-xpath.js +30 -30
- package/skills/extract/references/clean-html.js +90 -90
- package/skills/extract/references/detail.md +54 -54
- package/skills/extract/references/detail.schema.json5 +48 -48
- package/skills/extract/references/extract-detail.js +71 -71
- package/skills/extract/references/extract-regex.js +81 -81
- package/skills/extract/references/extract-sample.js +48 -48
- package/skills/extract/references/list-rule-gen.md +109 -109
- package/skills/extract/references/list.md +134 -134
- package/skills/extract/references/list.schema.json5 +33 -33
- package/skills/extract/references/navi.md +44 -44
- package/skills/extract/references/navi.schema.json5 +23 -23
- package/skills/extract/references/text.md +40 -40
- package/skills/extract/references/text.schema.json5 +21 -21
- package/skills/extract/references/to-text.js +20 -20
- package/skills/extract/references/validate-schema.js +39 -39
- package/skills/jstest/SKILL.md +561 -561
- package/skills/jstest/references/case-create.md +327 -327
- package/skills/jstest/references/case-fix.md +273 -273
- package/skills/jstest/references/config.md +148 -148
- package/skills/jstest/references/coverage-analyze.md +247 -247
- package/skills/jstest/references/env-ensure.md +210 -210
- package/skills/jstest/references/execute.md +168 -168
- package/skills/jstest/references/sample.md +166 -166
- package/skills/jstest/references/scoring-rules.md +75 -75
- package/skills/jstest/references/src/jstest-sample/Calculator.js +80 -80
- package/skills/jstest/references/src/jstest-sample/ConfigManager.js +72 -72
- package/skills/jstest/references/src/jstest-sample/FileProcessor.js +57 -57
- package/skills/jstest/references/src/jstest-sample/OrderService.js +98 -98
- package/skills/jstest/references/src/jstest-sample/TokenGenerator.js +60 -60
- package/skills/jstest/references/src/jstest-sample/UserService.js +56 -56
- package/skills/jstest/references/src/jstest-sample/index.js +6 -6
- package/skills/jstest/references/suitability-check.md +232 -232
- package/skills/jstest/references/test-standards.md +288 -288
- package/skills/lint/SKILL.md +440 -440
- package/skills/lint/references/ai-fix.md +137 -137
- package/skills/lint/references/config-setup.md +102 -102
- package/skills/lint/references/config.md +65 -65
- package/skills/lint/references/detect-language.js +65 -65
- package/skills/lint/references/env-ensure.md +88 -88
- package/skills/lint/references/language-detect.md +75 -75
- package/skills/lint/references/languages/js.md +110 -110
- package/skills/lint/references/languages/py.md +89 -89
- package/skills/lint/references/rules-analyze.md +125 -125
- package/skills/lint/references/suitability-check.md +81 -81
- package/skills/lint/references/tool-fix.md +90 -90
- package/skills/new-skill/SKILL.md +193 -227
- package/skills/pytest/SKILL.md +555 -555
- package/skills/pytest/references/case-create.md +324 -324
- package/skills/pytest/references/case-fix.md +271 -271
- package/skills/pytest/references/config.md +145 -145
- package/skills/pytest/references/coverage-analyze.md +223 -223
- package/skills/pytest/references/env-ensure.md +195 -195
- package/skills/pytest/references/execute.md +152 -152
- package/skills/pytest/references/sample.md +159 -159
- package/skills/pytest/references/scoring-rules.md +57 -57
- package/skills/pytest/references/src/pytest-sample/Calculator.py +67 -67
- package/skills/pytest/references/src/pytest-sample/ConfigManager.py +68 -68
- package/skills/pytest/references/src/pytest-sample/FileProcessor.py +53 -53
- package/skills/pytest/references/src/pytest-sample/OrderService.py +82 -82
- package/skills/pytest/references/src/pytest-sample/TokenGenerator.py +50 -50
- package/skills/pytest/references/src/pytest-sample/UserService.py +45 -45
- package/skills/pytest/references/suitability-check.md +220 -220
- package/skills/pytest/references/test-standards.md +244 -244
- package/skills/query/SKILL.md +71 -71
- package/skills/read-docs/SKILL.md +134 -134
- package/skills/read-docs/references/opencode/agents/cases.md +206 -206
- package/skills/read-docs/references/opencode/agents/design-pattern.md +47 -47
- package/skills/read-docs/references/opencode/agents/detail.md +191 -191
- package/skills/read-docs/references/opencode/agents/examples.md +100 -100
- package/skills/read-docs/references/opencode/agents/index.md +309 -309
- package/skills/read-docs/references/opencode/agents/parallel-dispatch.md +149 -149
- package/skills/read-docs/references/opencode/agents/subagent-internals.md +217 -217
- package/skills/read-docs/references/opencode/agents/workflow.md +161 -161
- package/skills/read-docs/references/opencode/cli/commands/acp.md +31 -31
- package/skills/read-docs/references/opencode/cli/commands/agent.md +16 -16
- package/skills/read-docs/references/opencode/cli/commands/attach.md +20 -20
- package/skills/read-docs/references/opencode/cli/commands/mcp.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/others.md +48 -48
- package/skills/read-docs/references/opencode/cli/commands/plugin.md +12 -12
- package/skills/read-docs/references/opencode/cli/commands/provider.md +43 -43
- package/skills/read-docs/references/opencode/cli/commands/run.md +81 -81
- package/skills/read-docs/references/opencode/cli/commands/serve.md +84 -84
- package/skills/read-docs/references/opencode/cli/commands/session.md +37 -37
- package/skills/read-docs/references/opencode/cli/commands/web.md +14 -14
- package/skills/read-docs/references/opencode/cli/env.md +38 -38
- package/skills/read-docs/references/opencode/cli/index.md +18 -18
- package/skills/read-docs/references/opencode/cli/tui.md +35 -35
- package/skills/read-docs/references/opencode/commands/examples.md +42 -42
- package/skills/read-docs/references/opencode/commands/index.md +185 -185
- package/skills/read-docs/references/opencode/config/provider.md +151 -151
- package/skills/read-docs/references/opencode/formatter/index.md +70 -70
- package/skills/read-docs/references/opencode/guide/config.md +419 -419
- package/skills/read-docs/references/opencode/guide/formatters.md +70 -70
- package/skills/read-docs/references/opencode/guide/index.md +37 -37
- package/skills/read-docs/references/opencode/guide/providers.md +31 -31
- package/skills/read-docs/references/opencode/guide/rules.md +63 -63
- package/skills/read-docs/references/opencode/plugins/examples.md +75 -75
- package/skills/read-docs/references/opencode/plugins/index.md +188 -188
- package/skills/read-docs/references/opencode/reference/index.md +118 -118
- package/skills/read-docs/references/opencode/rule/index.md +77 -77
- package/skills/read-docs/references/opencode/skills/detail.md +113 -113
- package/skills/read-docs/references/opencode/skills/examples.md +141 -141
- package/skills/read-docs/references/opencode/skills/index.md +126 -126
- package/skills/read-docs/references/opencode/skills/workflow.md +146 -146
- package/skills/read-docs/references/opencode/tests/agent.md +9 -9
- package/skills/read-docs/references/opencode/tests/config.md +59 -59
- package/skills/read-docs/references/opencode/tests/file.md +11 -11
- package/skills/read-docs/references/opencode/tests/serve.md +17 -17
- package/skills/read-docs/references/opencode/tests/session.md +30 -30
- package/skills/read-docs/references/opencode/tests/web.md +16 -16
- package/skills/read-docs/references/opencode/tools/arguments.md +305 -305
- package/skills/read-docs/references/opencode/tools/context.md +17 -17
- package/skills/read-docs/references/opencode/tools/custom.md +110 -110
- package/skills/read-docs/references/opencode/tools/detail.md +104 -104
- package/skills/read-docs/references/opencode/tools/examples.md +71 -71
- package/skills/read-docs/references/opencode/tools/index.md +56 -56
- package/skills/read-docs/references/opencode/tools/lsp.md +25 -25
- package/skills/read-docs/references/opencode/tools/mcp.md +132 -132
- package/skills/read-docs/references/opencode/train/README.md +134 -134
- package/skills/read-docs/references/opencode/train/agent-basic.md +771 -771
- package/skills/read-docs/references/opencode/train/command-basic.md +667 -667
- package/skills/read-docs/references/opencode/train/config-basic.md +508 -508
- package/skills/read-docs/references/opencode/train/index.md +163 -163
- package/skills/read-docs/references/opencode/train/practice.md +872 -872
- package/skills/read-docs/references/opencode/train/skill-basic.md +607 -607
- package/skills/read-docs/references/opencode/tui/commands/config.md +31 -31
- package/skills/read-docs/references/opencode/tui/commands/editor.md +46 -46
- package/skills/read-docs/references/opencode/tui/commands/index.md +124 -124
- package/skills/read-docs/references/opencode/tui/commands/init.md +4 -4
- package/skills/read-docs/references/opencode/tui/index.md +26 -26
- package/skills/read-docs/references/superpowers/bootstrap.md +107 -107
- package/skills/read-docs/references/superpowers/comparison.md +77 -77
- package/skills/read-docs/references/superpowers/context.md +71 -71
- package/skills/read-docs/references/superpowers/index.md +58 -58
- package/skills/read-docs/references/superpowers/parallel.md +49 -49
- package/skills/read-docs/references/superpowers/sdd.md +183 -183
- package/skills/read-docs/references/superpowers/skills.md +68 -68
- package/skills/read-docs/references/superpowers/workflow.md +83 -83
- package/skills/revise/SKILL.md +121 -121
- package/skills/revise/references/article.md +36 -36
- package/skills/revise/references/article.schema.json5 +40 -40
- package/skills/revise/references/gallery.md +34 -34
- package/skills/revise/references/gallery.schema.json5 +40 -40
- package/skills/revise/references/question.md +32 -32
- package/skills/revise/references/question.schema.json5 +31 -31
- package/skills/revise/references/status.md +31 -31
- package/skills/revise/references/status.schema.json5 +27 -27
- package/skills/revise/references/validate-schema.js +39 -39
- package/skills/step-extract/SKILL.md +205 -0
- package/skills/tsl/SKILL.md +393 -0
- package/skills/tsl/package.json +10 -0
- package/skills/tsl/references/global-review-rules.md +25 -0
- package/skills/tsl/references/prepare-prompt.md +150 -0
- package/skills/tsl/references/terminology-rules.md +93 -0
- package/skills/tsl/references/translation-guide.md +23 -0
- package/skills/tsl/references/translation-prompt.md +115 -0
- package/skills/tsl/references/translation-rules.md +48 -0
- package/skills/tsl/references/verification-rules.md +58 -0
- package/skills/tsl/scripts/check-boundaries.js +140 -0
- package/skills/tsl/scripts/chunk-text.js +144 -0
- package/skills/tsl/scripts/clean-text.js +121 -0
- package/skills/tsl/scripts/cleanup-glossary.js +160 -0
- package/skills/tsl/scripts/extract-pdf.js +94 -0
- package/skills/tsl/scripts/generate-review.js +179 -0
- package/skills/tsl/scripts/merge-result.js +164 -0
- package/skills/tsl/scripts/verify-chunk.js +170 -0
- package/skills/tsl-format/SKILL.md +298 -0
- package/skills/tsl-format/references/format-prompt.md +103 -0
- package/skills/tsl-format/references/format-rules.md +58 -0
- package/skills/tsl-format/scripts/chunk-bilingual.js +96 -0
- package/skills/tsl-format/scripts/merge-format.js +105 -0
- package/src/config.js +29 -29
- package/src/config.json5 +19 -19
- package/skills/new-skill/references/template.md +0 -53
- package/skills/new-skill/references/workflow-patterns.md +0 -104
package/bin/index.js
CHANGED
|
@@ -1,226 +1,291 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { execSync } from 'node:child_process'
|
|
4
|
-
import { readFileSync, readdirSync, existsSync } from 'node:fs'
|
|
5
|
-
import path from 'node:path'
|
|
6
|
-
import { fileURLToPath } from 'node:url'
|
|
7
|
-
import { getConfigPath, mergeBuiltinConfig } from '../src/config.js'
|
|
8
|
-
|
|
9
|
-
// Lazy-init: if user config doesn't exist (postinstall skipped), create it now
|
|
10
|
-
if (!existsSync(getConfigPath())) {
|
|
11
|
-
if (mergeBuiltinConfig()) {
|
|
12
|
-
console.log(`harness: config initialized at ${getConfigPath()}`)
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
17
|
-
const pkgRoot = path.resolve(__dirname, '..')
|
|
18
|
-
const pkgVersion = JSON.parse(readFileSync(path.join(pkgRoot, 'package.json'), 'utf8')).version
|
|
19
|
-
|
|
20
|
-
// ─── helpers ───
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 从 markdown frontmatter 中提取字段
|
|
24
|
-
* 支持 YAML 简单值(description: xxx)和多行值(description: |\n line1\n line2)
|
|
25
|
-
* @param {string} filePath
|
|
26
|
-
* @returns {Record<string,string>}
|
|
27
|
-
*/
|
|
28
|
-
function parseFrontmatter(filePath) {
|
|
29
|
-
const text = readFileSync(filePath, 'utf8')
|
|
30
|
-
const m = text.match(/^---\n([\s\S]*?)\n---/)
|
|
31
|
-
if (!m) return {}
|
|
32
|
-
const block = m[1]
|
|
33
|
-
const result = {}
|
|
34
|
-
let currentKey = null
|
|
35
|
-
for (const line of block.split('\n')) {
|
|
36
|
-
const kv = line.match(/^(\w[\w-]*)\s*:\s*(.*)$/)
|
|
37
|
-
if (kv) {
|
|
38
|
-
const [, key, val] = kv
|
|
39
|
-
if (val === '|' || val === '>') {
|
|
40
|
-
currentKey = key
|
|
41
|
-
result[key] = ''
|
|
42
|
-
} else {
|
|
43
|
-
currentKey = null
|
|
44
|
-
result[key] = val.replace(/^["']|["']$/g, '')
|
|
45
|
-
}
|
|
46
|
-
} else if (currentKey && line.startsWith(' ')) {
|
|
47
|
-
result[currentKey] += (result[currentKey] ? ' ' : '') + line.trim()
|
|
48
|
-
} else {
|
|
49
|
-
currentKey = null
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return result
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 列出目录下的 .md 文件,提取 name + description
|
|
57
|
-
* @param {string} dir
|
|
58
|
-
* @param {(name: string) => string} [nameTransform]
|
|
59
|
-
* @returns {{ name: string, description: string }[]}
|
|
60
|
-
*/
|
|
61
|
-
function listItems(dir, nameTransform) {
|
|
62
|
-
const fullDir = path.join(pkgRoot, dir)
|
|
63
|
-
if (!existsSync(fullDir)) return []
|
|
64
|
-
return readdirSync(fullDir, { withFileTypes: true })
|
|
65
|
-
.filter((e) => e.isFile() && e.name.endsWith('.md'))
|
|
66
|
-
.map((e) => {
|
|
67
|
-
const fm = parseFrontmatter(path.join(fullDir, e.name))
|
|
68
|
-
const name = nameTransform ? nameTransform(e.name) : e.name.replace(/\.md$/, '')
|
|
69
|
-
return { name, description: fm.description || '' }
|
|
70
|
-
})
|
|
71
|
-
.sort((a, b) => a.name.localeCompare(b.name))
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 列出 skills 目录(每个 skill 是子目录,含 SKILL.md)
|
|
76
|
-
* @returns {{ name: string, description: string }[]}
|
|
77
|
-
*/
|
|
78
|
-
function listSkills() {
|
|
79
|
-
const dir = path.join(pkgRoot, 'skills')
|
|
80
|
-
if (!existsSync(dir)) return []
|
|
81
|
-
return readdirSync(dir, { withFileTypes: true })
|
|
82
|
-
.filter((e) => e.isDirectory())
|
|
83
|
-
.map((e) => {
|
|
84
|
-
const skillFile = path.join(dir, e.name, 'SKILL.md')
|
|
85
|
-
const fm = existsSync(skillFile) ? parseFrontmatter(skillFile) : {}
|
|
86
|
-
return { name: fm.name || e.name, description: fm.description || '' }
|
|
87
|
-
})
|
|
88
|
-
.sort((a, b) => a.name.localeCompare(b.name))
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function truncate(str, max) {
|
|
92
|
-
if (!str) return ''
|
|
93
|
-
return str.length > max ? str.slice(0, max - 3) + '...' : str
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// ─── commands ───
|
|
97
|
-
|
|
98
|
-
function cmdVersion() {
|
|
99
|
-
console.log(pkgVersion)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function cmdStatus() {
|
|
103
|
-
console.log(`@wwkit/harness v${pkgVersion}`)
|
|
104
|
-
console.log(` 安装目录: ${pkgRoot}`)
|
|
105
|
-
|
|
106
|
-
const envDir = process.env.OPENCODE_CONFIG_DIR || ''
|
|
107
|
-
if (envDir) {
|
|
108
|
-
const ok = path.resolve(envDir) === pkgRoot
|
|
109
|
-
console.log(` OPENCODE_CONFIG_DIR: ${envDir} ${ok ? '✓' : '✗ (与安装目录不匹配)'}`)
|
|
110
|
-
} else {
|
|
111
|
-
console.log(' OPENCODE_CONFIG_DIR: 未设置(请重新安装或运行 postinstall)')
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const agents = listItems('agents')
|
|
115
|
-
const skills = listSkills()
|
|
116
|
-
const commands = listItems('commands')
|
|
117
|
-
console.log(` agents: ${agents.length} 个`)
|
|
118
|
-
console.log(` skills: ${skills.length} 个`)
|
|
119
|
-
console.log(` commands: ${commands.length} 个`)
|
|
120
|
-
|
|
121
|
-
// 检查 opencode 是否在 PATH
|
|
122
|
-
let opencodeOk = false
|
|
123
|
-
try {
|
|
124
|
-
const which = process.platform === 'win32' ? 'where' : 'which'
|
|
125
|
-
execSync(`${which} opencode`, { stdio: 'pipe', shell: true })
|
|
126
|
-
opencodeOk = true
|
|
127
|
-
} catch {}
|
|
128
|
-
console.log(` opencode: ${opencodeOk ? '✓ 在 PATH 中' : '✗ 不在 PATH 中'}`)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function cmdList(filter) {
|
|
132
|
-
if (filter === 'agents') {
|
|
133
|
-
printList('Agents', listItems('agents'))
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
if (filter === 'skills') {
|
|
137
|
-
printList('Skills', listSkills())
|
|
138
|
-
return
|
|
139
|
-
}
|
|
140
|
-
if (filter === 'commands') {
|
|
141
|
-
printList('Commands', listItems('commands'))
|
|
142
|
-
return
|
|
143
|
-
}
|
|
144
|
-
// 全部
|
|
145
|
-
printList('Agents', listItems('agents'))
|
|
146
|
-
console.log()
|
|
147
|
-
printList('Skills', listSkills())
|
|
148
|
-
console.log()
|
|
149
|
-
printList('Commands', listItems('commands'))
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function printList(title, items) {
|
|
153
|
-
console.log(`${title} (${items.length}):`)
|
|
154
|
-
if (items.length === 0) {
|
|
155
|
-
console.log(' (无)')
|
|
156
|
-
return
|
|
157
|
-
}
|
|
158
|
-
const maxName = Math.max(...items.map((i) => i.name.length), 4)
|
|
159
|
-
for (const item of items) {
|
|
160
|
-
console.log(` ${item.name.padEnd(maxName)} ${truncate(item.description, 80)}`)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* 查询 npm 主版本号(缓存),用于判断是否支持 --dangerously-allow-all-scripts
|
|
166
|
-
* npm < 11 默认放行 lifecycle scripts;npm >= 11 默认阻止,需显式放行 postinstall。
|
|
167
|
-
* @returns {number}
|
|
168
|
-
*/
|
|
169
|
-
function npmMajor() {
|
|
170
|
-
try {
|
|
171
|
-
return parseInt(execSync('npm --version', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim().split('.')[0], 10) || 0
|
|
172
|
-
} catch {
|
|
173
|
-
return 0
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function cmdUpgrade() {
|
|
178
|
-
const proxy = process.env.npm_config_proxy || ''
|
|
179
|
-
const npmArgs = ['install', '-g', '@wwkit/harness@latest']
|
|
180
|
-
if (proxy) npmArgs.push('--proxy', proxy)
|
|
181
|
-
// npm >= 11 默认阻止 lifecycle scripts,需显式放行 postinstall(设置 OPENCODE_CONFIG_DIR)
|
|
182
|
-
if (npmMajor() >= 11) npmArgs.push('--dangerously-allow-all-scripts')
|
|
183
|
-
execSync(`npm ${npmArgs.join(' ')}`, { stdio: 'inherit', shell: true })
|
|
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
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { execSync, spawn } from 'node:child_process'
|
|
4
|
+
import { readFileSync, readdirSync, existsSync } from 'node:fs'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { getConfigPath, mergeBuiltinConfig } from '../src/config.js'
|
|
8
|
+
|
|
9
|
+
// Lazy-init: if user config doesn't exist (postinstall skipped), create it now
|
|
10
|
+
if (!existsSync(getConfigPath())) {
|
|
11
|
+
if (mergeBuiltinConfig()) {
|
|
12
|
+
console.log(`harness: config initialized at ${getConfigPath()}`)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
17
|
+
const pkgRoot = path.resolve(__dirname, '..')
|
|
18
|
+
const pkgVersion = JSON.parse(readFileSync(path.join(pkgRoot, 'package.json'), 'utf8')).version
|
|
19
|
+
|
|
20
|
+
// ─── helpers ───
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 从 markdown frontmatter 中提取字段
|
|
24
|
+
* 支持 YAML 简单值(description: xxx)和多行值(description: |\n line1\n line2)
|
|
25
|
+
* @param {string} filePath
|
|
26
|
+
* @returns {Record<string,string>}
|
|
27
|
+
*/
|
|
28
|
+
function parseFrontmatter(filePath) {
|
|
29
|
+
const text = readFileSync(filePath, 'utf8')
|
|
30
|
+
const m = text.match(/^---\n([\s\S]*?)\n---/)
|
|
31
|
+
if (!m) return {}
|
|
32
|
+
const block = m[1]
|
|
33
|
+
const result = {}
|
|
34
|
+
let currentKey = null
|
|
35
|
+
for (const line of block.split('\n')) {
|
|
36
|
+
const kv = line.match(/^(\w[\w-]*)\s*:\s*(.*)$/)
|
|
37
|
+
if (kv) {
|
|
38
|
+
const [, key, val] = kv
|
|
39
|
+
if (val === '|' || val === '>') {
|
|
40
|
+
currentKey = key
|
|
41
|
+
result[key] = ''
|
|
42
|
+
} else {
|
|
43
|
+
currentKey = null
|
|
44
|
+
result[key] = val.replace(/^["']|["']$/g, '')
|
|
45
|
+
}
|
|
46
|
+
} else if (currentKey && line.startsWith(' ')) {
|
|
47
|
+
result[currentKey] += (result[currentKey] ? ' ' : '') + line.trim()
|
|
48
|
+
} else {
|
|
49
|
+
currentKey = null
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 列出目录下的 .md 文件,提取 name + description
|
|
57
|
+
* @param {string} dir
|
|
58
|
+
* @param {(name: string) => string} [nameTransform]
|
|
59
|
+
* @returns {{ name: string, description: string }[]}
|
|
60
|
+
*/
|
|
61
|
+
function listItems(dir, nameTransform) {
|
|
62
|
+
const fullDir = path.join(pkgRoot, dir)
|
|
63
|
+
if (!existsSync(fullDir)) return []
|
|
64
|
+
return readdirSync(fullDir, { withFileTypes: true })
|
|
65
|
+
.filter((e) => e.isFile() && e.name.endsWith('.md'))
|
|
66
|
+
.map((e) => {
|
|
67
|
+
const fm = parseFrontmatter(path.join(fullDir, e.name))
|
|
68
|
+
const name = nameTransform ? nameTransform(e.name) : e.name.replace(/\.md$/, '')
|
|
69
|
+
return { name, description: fm.description || '' }
|
|
70
|
+
})
|
|
71
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 列出 skills 目录(每个 skill 是子目录,含 SKILL.md)
|
|
76
|
+
* @returns {{ name: string, description: string }[]}
|
|
77
|
+
*/
|
|
78
|
+
function listSkills() {
|
|
79
|
+
const dir = path.join(pkgRoot, 'skills')
|
|
80
|
+
if (!existsSync(dir)) return []
|
|
81
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
82
|
+
.filter((e) => e.isDirectory())
|
|
83
|
+
.map((e) => {
|
|
84
|
+
const skillFile = path.join(dir, e.name, 'SKILL.md')
|
|
85
|
+
const fm = existsSync(skillFile) ? parseFrontmatter(skillFile) : {}
|
|
86
|
+
return { name: fm.name || e.name, description: fm.description || '' }
|
|
87
|
+
})
|
|
88
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function truncate(str, max) {
|
|
92
|
+
if (!str) return ''
|
|
93
|
+
return str.length > max ? str.slice(0, max - 3) + '...' : str
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ─── commands ───
|
|
97
|
+
|
|
98
|
+
function cmdVersion() {
|
|
99
|
+
console.log(pkgVersion)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function cmdStatus() {
|
|
103
|
+
console.log(`@wwkit/harness v${pkgVersion}`)
|
|
104
|
+
console.log(` 安装目录: ${pkgRoot}`)
|
|
105
|
+
|
|
106
|
+
const envDir = process.env.OPENCODE_CONFIG_DIR || ''
|
|
107
|
+
if (envDir) {
|
|
108
|
+
const ok = path.resolve(envDir) === pkgRoot
|
|
109
|
+
console.log(` OPENCODE_CONFIG_DIR: ${envDir} ${ok ? '✓' : '✗ (与安装目录不匹配)'}`)
|
|
110
|
+
} else {
|
|
111
|
+
console.log(' OPENCODE_CONFIG_DIR: 未设置(请重新安装或运行 postinstall)')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const agents = listItems('agents')
|
|
115
|
+
const skills = listSkills()
|
|
116
|
+
const commands = listItems('commands')
|
|
117
|
+
console.log(` agents: ${agents.length} 个`)
|
|
118
|
+
console.log(` skills: ${skills.length} 个`)
|
|
119
|
+
console.log(` commands: ${commands.length} 个`)
|
|
120
|
+
|
|
121
|
+
// 检查 opencode 是否在 PATH
|
|
122
|
+
let opencodeOk = false
|
|
123
|
+
try {
|
|
124
|
+
const which = process.platform === 'win32' ? 'where' : 'which'
|
|
125
|
+
execSync(`${which} opencode`, { stdio: 'pipe', shell: true })
|
|
126
|
+
opencodeOk = true
|
|
127
|
+
} catch {}
|
|
128
|
+
console.log(` opencode: ${opencodeOk ? '✓ 在 PATH 中' : '✗ 不在 PATH 中'}`)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function cmdList(filter) {
|
|
132
|
+
if (filter === 'agents') {
|
|
133
|
+
printList('Agents', listItems('agents'))
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
if (filter === 'skills') {
|
|
137
|
+
printList('Skills', listSkills())
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
if (filter === 'commands') {
|
|
141
|
+
printList('Commands', listItems('commands'))
|
|
142
|
+
return
|
|
143
|
+
}
|
|
144
|
+
// 全部
|
|
145
|
+
printList('Agents', listItems('agents'))
|
|
146
|
+
console.log()
|
|
147
|
+
printList('Skills', listSkills())
|
|
148
|
+
console.log()
|
|
149
|
+
printList('Commands', listItems('commands'))
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function printList(title, items) {
|
|
153
|
+
console.log(`${title} (${items.length}):`)
|
|
154
|
+
if (items.length === 0) {
|
|
155
|
+
console.log(' (无)')
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
const maxName = Math.max(...items.map((i) => i.name.length), 4)
|
|
159
|
+
for (const item of items) {
|
|
160
|
+
console.log(` ${item.name.padEnd(maxName)} ${truncate(item.description, 80)}`)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 查询 npm 主版本号(缓存),用于判断是否支持 --dangerously-allow-all-scripts
|
|
166
|
+
* npm < 11 默认放行 lifecycle scripts;npm >= 11 默认阻止,需显式放行 postinstall。
|
|
167
|
+
* @returns {number}
|
|
168
|
+
*/
|
|
169
|
+
function npmMajor() {
|
|
170
|
+
try {
|
|
171
|
+
return parseInt(execSync('npm --version', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim().split('.')[0], 10) || 0
|
|
172
|
+
} catch {
|
|
173
|
+
return 0
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function cmdUpgrade() {
|
|
178
|
+
const proxy = process.env.npm_config_proxy || ''
|
|
179
|
+
const npmArgs = ['install', '-g', '@wwkit/harness@latest']
|
|
180
|
+
if (proxy) npmArgs.push('--proxy', proxy)
|
|
181
|
+
// npm >= 11 默认阻止 lifecycle scripts,需显式放行 postinstall(设置 OPENCODE_CONFIG_DIR)
|
|
182
|
+
if (npmMajor() >= 11) npmArgs.push('--dangerously-allow-all-scripts')
|
|
183
|
+
execSync(`npm ${npmArgs.join(' ')}`, { stdio: 'inherit', shell: true })
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 启动 opencode,自动设置 OPENCODE_CONFIG_DIR 为 harness 包根目录。
|
|
188
|
+
*
|
|
189
|
+
* 支持参数:
|
|
190
|
+
* -d, --dir <dir> 工作目录(默认 cwd)
|
|
191
|
+
* 其余参数 透传给 opencode
|
|
192
|
+
*
|
|
193
|
+
* 开发场景:pnpm run opencode → node bin/index.js opencode
|
|
194
|
+
* 正式场景:harness opencode(全局安装后,__dirname 始终指向真实包根目录)
|
|
195
|
+
*
|
|
196
|
+
* @param {string[]} args - process.argv.slice(3)
|
|
197
|
+
*/
|
|
198
|
+
function cmdOpencode(args) {
|
|
199
|
+
let workDir = process.cwd()
|
|
200
|
+
const passThrough = []
|
|
201
|
+
for (let i = 0; i < args.length; i++) {
|
|
202
|
+
const arg = args[i]
|
|
203
|
+
if (arg === '-d' || arg === '--dir') {
|
|
204
|
+
const next = args[i + 1]
|
|
205
|
+
if (next !== undefined && !next.startsWith('-')) {
|
|
206
|
+
workDir = next
|
|
207
|
+
i++
|
|
208
|
+
} else {
|
|
209
|
+
passThrough.push(arg)
|
|
210
|
+
}
|
|
211
|
+
} else if (arg.startsWith('-d=') || arg.startsWith('--dir=')) {
|
|
212
|
+
workDir = arg.slice(arg.indexOf('=') + 1)
|
|
213
|
+
} else {
|
|
214
|
+
passThrough.push(arg)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const resolved = path.resolve(workDir)
|
|
219
|
+
if (!existsSync(resolved)) {
|
|
220
|
+
console.error(`Directory not found: ${resolved}`)
|
|
221
|
+
process.exit(1)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const env = {
|
|
225
|
+
...process.env,
|
|
226
|
+
OPENCODE_CONFIG_DIR: pkgRoot,
|
|
227
|
+
OPENCODE_EXPERIMENTAL_LSP_TOOL: 'true',
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const child = spawn('opencode', passThrough, {
|
|
231
|
+
cwd: resolved,
|
|
232
|
+
stdio: 'inherit',
|
|
233
|
+
env,
|
|
234
|
+
shell: process.platform === 'win32',
|
|
235
|
+
})
|
|
236
|
+
child.on('error', (err) => {
|
|
237
|
+
console.error(`Failed to start opencode: ${err.message}`)
|
|
238
|
+
console.error('Is opencode installed and on PATH? (npm install -g opencode-ai)')
|
|
239
|
+
process.exit(1)
|
|
240
|
+
})
|
|
241
|
+
child.on('close', (code) => {
|
|
242
|
+
process.exit(code ?? 0)
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function printHelp() {
|
|
247
|
+
console.log(`harness - WebWork abilities for opencode
|
|
248
|
+
|
|
249
|
+
用法:
|
|
250
|
+
harness version 显示版本号
|
|
251
|
+
harness status 显示安装状态(环境变量、agents/skills/commands 数量)
|
|
252
|
+
harness list 列出所有 agents/skills/commands 及描述
|
|
253
|
+
harness list agents 仅列出 agents
|
|
254
|
+
harness list skills 仅列出 skills
|
|
255
|
+
harness list commands 仅列出 commands
|
|
256
|
+
harness upgrade 升级 harness 自身(npm install -g @wwkit/harness@latest)
|
|
257
|
+
harness opencode [args] 启动 opencode(自动设置 OPENCODE_CONFIG_DIR)
|
|
258
|
+
harness opencode -d <dir> 在指定目录启动 opencode
|
|
259
|
+
harness help 显示本帮助
|
|
260
|
+
|
|
261
|
+
安装目录: ${pkgRoot}
|
|
262
|
+
配置: OPENCODE_CONFIG_DIR 环境变量(由 postinstall 或 harness opencode 自动设置)
|
|
263
|
+
`)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// ─── main ───
|
|
267
|
+
|
|
268
|
+
const cmd = process.argv[2] ?? 'help'
|
|
269
|
+
|
|
270
|
+
switch (cmd) {
|
|
271
|
+
case 'version':
|
|
272
|
+
cmdVersion()
|
|
273
|
+
break
|
|
274
|
+
case 'status':
|
|
275
|
+
cmdStatus()
|
|
276
|
+
break
|
|
277
|
+
case 'list':
|
|
278
|
+
cmdList(process.argv[3])
|
|
279
|
+
break
|
|
280
|
+
case 'upgrade':
|
|
281
|
+
cmdUpgrade()
|
|
282
|
+
break
|
|
283
|
+
case 'opencode':
|
|
284
|
+
cmdOpencode(process.argv.slice(3))
|
|
285
|
+
break
|
|
286
|
+
case 'help':
|
|
287
|
+
case '-h':
|
|
288
|
+
case '--help':
|
|
289
|
+
default:
|
|
290
|
+
printHelp()
|
|
291
|
+
}
|