sillyspec 3.26.14 → 3.27.1
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/.claude/skills/sillyspec-archive/SKILL.md +2 -0
- package/.claude/skills/sillyspec-brainstorm/SKILL.md +1 -1
- package/.claude/skills/sillyspec-commit/SKILL.md +18 -60
- package/.claude/skills/sillyspec-continue/SKILL.md +2 -0
- package/.claude/skills/sillyspec-execute/SKILL.md +10 -4
- package/.claude/skills/sillyspec-explore/SKILL.md +10 -3
- package/.claude/skills/sillyspec-plan/SKILL.md +10 -2
- package/.claude/skills/sillyspec-quick/SKILL.md +2 -2
- package/.claude/skills/sillyspec-resume/SKILL.md +2 -0
- package/.claude/skills/sillyspec-verify/SKILL.md +4 -0
- package/.claude/skills/sillyspec-workspace/SKILL.md +7 -1
- package/README.md +1 -1
- package/package.json +1 -1
- package/packages/dashboard/server/index.js +22 -6
- package/src/change-risk-profile.js +21 -6
- package/src/commit-suggest.js +202 -0
- package/src/config-cat.js +88 -0
- package/src/db.js +14 -3
- package/src/docs-check.js +598 -534
- package/src/doctor-diagnostics.js +102 -1
- package/src/endpoint-extractor.js +21 -2
- package/src/fs-atomic.js +4 -2
- package/src/git-helper.js +73 -5
- package/src/hooks/claude-pre-tool-use.cjs +10 -5
- package/src/hooks/worktree-guard.js +42 -4
- package/src/index.js +557 -12
- package/src/init.js +1 -1
- package/src/local-register.js +98 -0
- package/src/module-impact.js +166 -0
- package/src/module-resolve.js +211 -0
- package/src/modules.js +82 -2
- package/src/progress/change-registry.js +43 -4
- package/src/progress/stage-machine.js +10 -5
- package/src/progress/step-store.js +12 -8
- package/src/progress.js +19 -3
- package/src/quicklog.js +106 -1
- package/src/run/command.js +95 -1
- package/src/run/complete-handlers.js +73 -5
- package/src/run/complete.js +47 -14
- package/src/run/gates.js +144 -17
- package/src/run/multi-repo-context.js +3 -1
- package/src/run/next.js +128 -0
- package/src/run/prompt.js +36 -4
- package/src/run/quick-audit.js +5 -2
- package/src/run/shared.js +48 -20
- package/src/run/stage.js +37 -3
- package/src/scan-postcheck.js +142 -2
- package/src/stage-contract-spec.js +1 -1
- package/src/stage-contract.js +14 -1
- package/src/stage-review.js +15 -6
- package/src/stages/archive.js +4 -2
- package/src/stages/brainstorm.js +1 -0
- package/src/stages/execute.js +275 -44
- package/src/stages/explore.js +11 -2
- package/src/stages/knowledge.js +3 -2
- package/src/stages/quick.js +18 -9
- package/src/stages/scan.js +1 -0
- package/src/stages/verify.js +16 -51
- package/src/sync.js +44 -3
- package/src/task-review.js +273 -11
- package/src/taskcard.js +52 -22
- package/src/verify-postcheck.js +223 -6
- package/src/verify-probes.js +264 -0
- package/src/workspace.js +125 -0
- package/src/worktree-apply.js +43 -11
- package/src/worktree-deps.js +59 -5
- package/src/worktree.js +128 -14
- package/templates/claude-instruction.md +1 -1
- package/templates/prompts/taskcard-rules.md +1 -1
- package/templates/prompts/verify-probes.md +13 -47
package/src/taskcard.js
CHANGED
|
@@ -14,7 +14,8 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
|
|
|
14
14
|
import { join } from 'path'
|
|
15
15
|
import { git } from './git-helper.js'
|
|
16
16
|
import { assertSafeChangeName, resolveSpecDir } from './run/shared.js'
|
|
17
|
-
import { parseTaskNames } from './stages/plan.js'
|
|
17
|
+
import { parseTaskNames, readTaskRegistryContent } from './stages/plan.js'
|
|
18
|
+
import { parseTaskRegistry } from './stages/execute.js'
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* 任务号归一:接受 task-01 / task-1 / 01 / 1,统一为 task-NN(两位补零,与任务卡文件名一致)。
|
|
@@ -52,21 +53,44 @@ function yamlScalar(v) {
|
|
|
52
53
|
* 字符串只含 \n:writeFileSync 直写不经任何行尾转换,Windows 下天然 LF 安全。
|
|
53
54
|
* title/title_zh/author 经 yamlScalar 转义(自由文本防 YAML 指示符炸解析)。
|
|
54
55
|
*
|
|
55
|
-
* @param {{ taskId: string, title: string, titleZh: string, author: string, now: string
|
|
56
|
+
* @param {{ taskId: string, title: string, titleZh: string, author: string, now: string,
|
|
57
|
+
* dependsOn?: string[], sets?: Record<string,string> }} p
|
|
58
|
+
* dependsOn:tasks.md 行内注解反填(坑 taskcard-design-field-conflicts,2026-08-21 实证)——
|
|
59
|
+
* "(depends_on: task-01,02)" 注解由 CLI 解析进 frontmatter,省主代理逐卡裁决
|
|
60
|
+
* sets:--set key=value 覆盖(yamlScalar 转义;仅覆盖已存在的标量键,防注入任意结构)
|
|
56
61
|
* @returns {string}
|
|
57
62
|
*/
|
|
58
|
-
export function buildTaskcardSkeleton({ taskId, title, titleZh, author, now }) {
|
|
63
|
+
export function buildTaskcardSkeleton({ taskId, title, titleZh, author, now, dependsOn = [], sets = {} }) {
|
|
64
|
+
const fm = {
|
|
65
|
+
id: taskId,
|
|
66
|
+
title: yamlScalar(title),
|
|
67
|
+
title_zh: yamlScalar(titleZh),
|
|
68
|
+
author: yamlScalar(author),
|
|
69
|
+
created_at: now,
|
|
70
|
+
priority: 'P0',
|
|
71
|
+
depends_on: (Array.isArray(dependsOn) && dependsOn.length > 0)
|
|
72
|
+
? `[${dependsOn.map(d => `'${d}'`).join(', ')}]`
|
|
73
|
+
: '[]',
|
|
74
|
+
blocks: '[]',
|
|
75
|
+
requirement_ids: '[FR-XX]',
|
|
76
|
+
decision_ids: '[D-XXX@vN]',
|
|
77
|
+
}
|
|
78
|
+
// --set 覆盖(白名单键 + yamlScalar 转义值;depends_on 数组形态单独拼不进标量 map,跳过)
|
|
79
|
+
const SETTABLE_KEYS = new Set(['id', 'title', 'title_zh', 'author', 'priority', 'created_at', 'requirement_ids', 'decision_ids', 'blocks', 'goal'])
|
|
80
|
+
for (const [k, v] of Object.entries(sets || {})) {
|
|
81
|
+
if (SETTABLE_KEYS.has(k)) fm[k] = yamlScalar(v)
|
|
82
|
+
}
|
|
59
83
|
return `---
|
|
60
|
-
id: ${
|
|
61
|
-
title: ${
|
|
62
|
-
title_zh: ${
|
|
63
|
-
author: ${
|
|
64
|
-
created_at: ${
|
|
65
|
-
priority:
|
|
66
|
-
depends_on:
|
|
67
|
-
blocks:
|
|
68
|
-
requirement_ids:
|
|
69
|
-
decision_ids:
|
|
84
|
+
id: ${fm.id}
|
|
85
|
+
title: ${fm.title}
|
|
86
|
+
title_zh: ${fm.title_zh}
|
|
87
|
+
author: ${fm.author}
|
|
88
|
+
created_at: ${fm.created_at}
|
|
89
|
+
priority: ${fm.priority}
|
|
90
|
+
depends_on: ${fm.depends_on}
|
|
91
|
+
blocks: ${fm.blocks}
|
|
92
|
+
requirement_ids: ${fm.requirement_ids}
|
|
93
|
+
decision_ids: ${fm.decision_ids}
|
|
70
94
|
allowed_paths:
|
|
71
95
|
- src/example/file.ts
|
|
72
96
|
goal: >
|
|
@@ -105,7 +129,7 @@ constraints:
|
|
|
105
129
|
* @returns {{ created: string[], skipped: string[], tasksDir: string }}
|
|
106
130
|
*/
|
|
107
131
|
export function cmdTaskcard(changeName, opts = {}) {
|
|
108
|
-
const { cwd, specDir = null, taskIds, title = null, titleZh = null, force = false } = opts
|
|
132
|
+
const { cwd, specDir = null, taskIds, title = null, titleZh = null, force = false, sets = {} } = opts
|
|
109
133
|
assertSafeChangeName(changeName, '变更名')
|
|
110
134
|
|
|
111
135
|
const changeDir = join(resolveSpecDir(cwd, { specDir }), 'changes', changeName)
|
|
@@ -114,25 +138,27 @@ export function cmdTaskcard(changeName, opts = {}) {
|
|
|
114
138
|
}
|
|
115
139
|
|
|
116
140
|
// 任务注册表 tasks.md(2026-08-20-task-truth-unify 唯一真相;CRLF 归一后解析,
|
|
117
|
-
// --all 时强依赖)。tasks.md 缺失回退 plan.md
|
|
118
|
-
|
|
141
|
+
// --all 时强依赖)。tasks.md 缺失回退 plan.md(旧归档变更兼容读侧)。
|
|
142
|
+
// parseTaskRegistry(坑 taskcard-design-field-conflicts,2026-08-21):除编号/标题外还带出
|
|
143
|
+
// 行内注解([model:xxx] / (depends_on: task-01,02))——depends_on 直接反填进骨架 frontmatter。
|
|
144
|
+
let registry = []
|
|
119
145
|
const tasksMdPath = join(changeDir, 'tasks.md')
|
|
120
146
|
const planPath = join(changeDir, 'plan.md')
|
|
121
147
|
const registryPath = existsSync(tasksMdPath) ? tasksMdPath : planPath
|
|
122
148
|
if (existsSync(registryPath)) {
|
|
123
149
|
const registryContent = readFileSync(registryPath, 'utf8').replace(/\r\n/g, '\n')
|
|
124
|
-
|
|
150
|
+
registry = parseTaskRegistry(registryContent)
|
|
125
151
|
}
|
|
126
152
|
|
|
127
153
|
let ids
|
|
128
154
|
if (taskIds === 'all') {
|
|
129
|
-
if (
|
|
155
|
+
if (registry.length === 0) {
|
|
130
156
|
throw new Error(
|
|
131
157
|
`--all 需要 tasks.md 中存在 checkbox 任务行(格式 "- [ ] task-XX: 任务名")` +
|
|
132
158
|
(existsSync(registryPath) ? ',当前任务清单未解析到任何任务行' : ',且变更目录下未找到 tasks.md/plan.md')
|
|
133
159
|
)
|
|
134
160
|
}
|
|
135
|
-
ids =
|
|
161
|
+
ids = registry.map(t => t.id)
|
|
136
162
|
} else if (Array.isArray(taskIds) && taskIds.length > 0) {
|
|
137
163
|
ids = taskIds
|
|
138
164
|
} else {
|
|
@@ -161,9 +187,9 @@ export function cmdTaskcard(changeName, opts = {}) {
|
|
|
161
187
|
const created = []
|
|
162
188
|
const skipped = []
|
|
163
189
|
for (const id of ids) {
|
|
164
|
-
const
|
|
165
|
-
const finalTitle = title || (
|
|
166
|
-
const finalTitleZh = titleZh || (
|
|
190
|
+
const reg = registry.find(t => t.id === id)
|
|
191
|
+
const finalTitle = title || (reg ? reg.name : null) || `${id} fill-english-title`
|
|
192
|
+
const finalTitleZh = titleZh || (reg ? reg.name : null) || finalTitle
|
|
167
193
|
const filePath = join(tasksDir, `${id}.md`)
|
|
168
194
|
if (existsSync(filePath) && !force) {
|
|
169
195
|
skipped.push(filePath)
|
|
@@ -171,6 +197,10 @@ export function cmdTaskcard(changeName, opts = {}) {
|
|
|
171
197
|
}
|
|
172
198
|
writeFileSync(filePath, buildTaskcardSkeleton({
|
|
173
199
|
taskId: id, title: finalTitle, titleZh: finalTitleZh, author, now,
|
|
200
|
+
// depends_on 从 tasks.md 行内注解反填(坑 taskcard-design-field-conflicts):注册表
|
|
201
|
+
// 注解与 plan/design 的依赖声明同源,骨架直接带上省主代理逐卡转录
|
|
202
|
+
dependsOn: reg ? reg.dependsOn : [],
|
|
203
|
+
sets,
|
|
174
204
|
}), 'utf8')
|
|
175
205
|
created.push(filePath)
|
|
176
206
|
}
|
package/src/verify-postcheck.js
CHANGED
|
@@ -60,6 +60,104 @@ export function extractTestCommand(yamlText) {
|
|
|
60
60
|
return null
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* 从 local.yaml 文本提取 commands.lint(2026-08-21 审查 CLI-1:lint 对账)。
|
|
65
|
+
* 与 extractTestCommand 同风格同容错(带引号/不带引号/unavailable)。
|
|
66
|
+
* 模块内私有(runVerifyLintCheck 消费;extractTestCommand 系 export 供 test)。
|
|
67
|
+
*/
|
|
68
|
+
function extractLintCommand(yamlText) {
|
|
69
|
+
if (!yamlText) return null
|
|
70
|
+
const doubleQuoted = yamlText.match(/^\s*lint:\s*"([^"]+)"\s*(?:#.*)?$/m)
|
|
71
|
+
const singleQuoted = yamlText.match(/^\s*lint:\s*'([^']+)'\s*(?:#.*)?$/m)
|
|
72
|
+
const quoted = doubleQuoted || singleQuoted
|
|
73
|
+
if (quoted && quoted[1]) {
|
|
74
|
+
return quoted[1].toLowerCase() === 'unavailable' ? null : quoted[1].trim()
|
|
75
|
+
}
|
|
76
|
+
const bare = yamlText.match(/^\s*lint:\s*([^\n#"']+?)\s*(?:#.*)?$/m)
|
|
77
|
+
if (bare && bare[1]) {
|
|
78
|
+
const cmd = bare[1].trim()
|
|
79
|
+
return cmd.toLowerCase() === 'unavailable' ? null : cmd
|
|
80
|
+
}
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* verify --done 实测跑 local.yaml commands.lint(2026-08-21 审查 CLI-1)。
|
|
86
|
+
* 此前 lint 全靠 agent 自跑自报("我跑过 lint 了"纯口头),与 test 侧的对账不对称——
|
|
87
|
+
* agent 偷懒漏跑时格式债被推迟到用户 commit 才被 pre-commit hook 炸出。
|
|
88
|
+
* advisory 起步:失败只打印不阻断(test 门已 fail-closed,lint 门观察期后再升级)。
|
|
89
|
+
* 信任边界与 runVerifyTestCheck 一致:命令只来源于主仓 .sillyspec/local.yaml。
|
|
90
|
+
*/
|
|
91
|
+
export function runVerifyLintCheck({ cwd, specBase }) {
|
|
92
|
+
const localYamlPath = join(specBase, 'local.yaml')
|
|
93
|
+
const yamlText = existsSync(localYamlPath) ? readFileSync(localYamlPath, 'utf8') : null
|
|
94
|
+
const command = extractLintCommand(yamlText)
|
|
95
|
+
|
|
96
|
+
if (!command) {
|
|
97
|
+
return {
|
|
98
|
+
status: 'skipped',
|
|
99
|
+
command: null,
|
|
100
|
+
exitCode: null,
|
|
101
|
+
durationMs: null,
|
|
102
|
+
outputTail: null,
|
|
103
|
+
reason: yamlText
|
|
104
|
+
? 'local.yaml 未配置 commands.lint(或标记 unavailable)'
|
|
105
|
+
: `local.yaml 不存在(${localYamlPath})`,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const LINT_TIMEOUT_MS = Number(process.env.SILLYSPEC_LINT_TIMEOUT_MS) || 3 * 60 * 1000
|
|
110
|
+
const startedAt = Date.now()
|
|
111
|
+
let exitCode = 0
|
|
112
|
+
let output = ''
|
|
113
|
+
let reason = null
|
|
114
|
+
try {
|
|
115
|
+
output = execSync(command, {
|
|
116
|
+
cwd,
|
|
117
|
+
encoding: 'utf8',
|
|
118
|
+
timeout: LINT_TIMEOUT_MS,
|
|
119
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
120
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
121
|
+
})
|
|
122
|
+
} catch (e) {
|
|
123
|
+
exitCode = typeof e.status === 'number' ? e.status : 1
|
|
124
|
+
output = [e.stdout, e.stderr].filter(Boolean).join('\n') || e.message
|
|
125
|
+
reason = e.signal === 'SIGTERM' && Date.now() - startedAt >= LINT_TIMEOUT_MS
|
|
126
|
+
? `lint 命令超时(>${LINT_TIMEOUT_MS / 1000}s)`
|
|
127
|
+
: `lint 命令退出码 ${exitCode}`
|
|
128
|
+
}
|
|
129
|
+
const durationMs = Date.now() - startedAt
|
|
130
|
+
const outputTail = output.length > OUTPUT_TAIL_CHARS ? '…' + output.slice(-OUTPUT_TAIL_CHARS) : output
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
status: exitCode === 0 ? 'passed' : 'failed',
|
|
134
|
+
command,
|
|
135
|
+
exitCode,
|
|
136
|
+
durationMs,
|
|
137
|
+
outputTail,
|
|
138
|
+
reason: exitCode === 0 ? null : reason,
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** 打印 lint 实测结果(advisory:失败不阻断,只把口头汇报对上账) */
|
|
143
|
+
export function printVerifyLintCheck(result) {
|
|
144
|
+
if (result.status === 'skipped') {
|
|
145
|
+
console.warn(`\n⚠️ Verify lint 实测跳过:${result.reason}`)
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
if (result.status === 'passed') {
|
|
149
|
+
console.log(`\n✅ Verify lint 实测通过:\`${result.command}\` 退出码 0(${(result.durationMs / 1000).toFixed(1)}s)`)
|
|
150
|
+
return
|
|
151
|
+
}
|
|
152
|
+
console.error(`\n⚠️ Verify lint 实测失败(advisory,不阻断本次完成):\`${result.command}\` — ${result.reason}`)
|
|
153
|
+
console.error(' agent 的 lint 自报告与实测不符时以实测为准;请修复后重跑,避免格式债推迟到 commit 被 pre-commit hook 拦截。')
|
|
154
|
+
if (result.outputTail) {
|
|
155
|
+
const tail = result.outputTail.split('\n').slice(-15).join('\n')
|
|
156
|
+
console.error(' 输出(末尾):')
|
|
157
|
+
for (const line of tail.split('\n')) console.error(` | ${line}`)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
63
161
|
/**
|
|
64
162
|
* 从 local.yaml 文本提取顶层 test_strategy。
|
|
65
163
|
* 轻量正则(与 extractTestCommand 同风格,不引 yaml 依赖)。
|
|
@@ -207,15 +305,30 @@ export function pickHitModules(changedFiles, modules) {
|
|
|
207
305
|
|
|
208
306
|
const files = changedFiles.map(f => String(f).replace(/\\/g, '/'))
|
|
209
307
|
const hits = []
|
|
308
|
+
const looseHits = []
|
|
210
309
|
for (const [name, mod] of Object.entries(modules)) {
|
|
211
310
|
if (!mod || !mod.path) continue
|
|
212
311
|
const modPath = String(mod.path).replace(/\\/g, '/')
|
|
213
312
|
const prefix = modPath.endsWith('/') ? modPath : modPath + '/'
|
|
214
313
|
// path 本身被改 或 path/ 下任意文件被改
|
|
215
314
|
const hit = files.some(f => f === modPath || f.startsWith(prefix))
|
|
216
|
-
if (hit) hits.push({ name, path: modPath, test: mod.test })
|
|
315
|
+
if (hit) { hits.push({ name, path: modPath, test: mod.test }); continue }
|
|
316
|
+
// 宽松段匹配 fallback(坑 module-path-layout-mismatch,2026-08-22 实证:pnpm monorepo
|
|
317
|
+
// 常见 packages/frontend 布局 vs modules 配 frontend/ 前缀——严格前缀 0 命中时按
|
|
318
|
+
// 「路径段等于模块首段」兜底(packages/frontend/src/x → 命中 frontend),多测不漏测。
|
|
319
|
+
// 首段去斜杠后比对,防 frontend-guide 之类前缀误蹭)
|
|
320
|
+
const firstSeg = prefix.split('/')[0]
|
|
321
|
+
if (firstSeg && files.some(f => ('/' + f + '/').includes('/' + firstSeg + '/'))) {
|
|
322
|
+
looseHits.push({ name, path: modPath, test: mod.test, looseMatch: true })
|
|
323
|
+
}
|
|
217
324
|
}
|
|
218
|
-
|
|
325
|
+
// 严格命中优先;全部严格 0 命中才用宽松兜底(并 warn 可见——宽松规则可能多命中)
|
|
326
|
+
if (hits.length > 0) return hits
|
|
327
|
+
if (looseHits.length > 0) {
|
|
328
|
+
console.warn(`⚠️ 模块命中用宽松段匹配(modules path 前缀与 diff 布局不一致,如 packages/<name> vs <name>/):命中 ${looseHits.map(h => h.name).join(', ')}——建议 local.yaml modules 的 path 对齐实际目录布局`)
|
|
329
|
+
return looseHits
|
|
330
|
+
}
|
|
331
|
+
return []
|
|
219
332
|
}
|
|
220
333
|
|
|
221
334
|
/**
|
|
@@ -360,6 +473,7 @@ function runOneModule(name, testCommand, cwd, knownFailures = []) {
|
|
|
360
473
|
let exitCode = 0
|
|
361
474
|
let output = ''
|
|
362
475
|
let reason = null
|
|
476
|
+
warnPortRaceBeforeRun(testCommand)
|
|
363
477
|
try {
|
|
364
478
|
output = execSync(testCommand, {
|
|
365
479
|
cwd,
|
|
@@ -374,6 +488,10 @@ function runOneModule(name, testCommand, cwd, knownFailures = []) {
|
|
|
374
488
|
reason = e.signal === 'SIGTERM' && Date.now() - startedAt >= TEST_TIMEOUT_MS
|
|
375
489
|
? `模块 ${name} 测试超时(>${TEST_TIMEOUT_MS / 1000}s)`
|
|
376
490
|
: `模块 ${name} 测试退出码 ${exitCode}`
|
|
491
|
+
// 资源竞争鉴别提示(坑 verify-devserver-port-race,同 runFullCommand)
|
|
492
|
+
if (/EADDRINUSE|address already in use|端口.*被占用|port.*already/i.test(output)) {
|
|
493
|
+
reason += '。⚠️ 输出含端口占用信号(EADDRINUSE)——极可能是与你自留 dev server 的资源竞争而非代码问题:停掉占用服务后重跑 verify 再定论'
|
|
494
|
+
}
|
|
377
495
|
}
|
|
378
496
|
const durationMs = Date.now() - startedAt
|
|
379
497
|
const outputTail = output.length > OUTPUT_TAIL_CHARS ? '…' + output.slice(-OUTPUT_TAIL_CHARS) : output
|
|
@@ -475,9 +593,35 @@ function gitChangedFiles(cwd) {
|
|
|
475
593
|
* @param {object|null} [ctx] - MultiRepoContext 实例(可选,缺省/null 走单仓原逻辑)
|
|
476
594
|
* @returns {string[]|null} 变更文件列表;git 不可用返回 null(调用方按 hitCount=-1 处理)
|
|
477
595
|
*/
|
|
478
|
-
export function resolveVerifyChangedFiles(cwd, changeName, ctx = null) {
|
|
596
|
+
export function resolveVerifyChangedFiles(cwd, changeName, ctx = null, opts = {}) {
|
|
597
|
+
const { includeWorkingTree = false } = opts
|
|
479
598
|
// 主仓 diff(原逻辑不动,单仓零回归)
|
|
480
|
-
|
|
599
|
+
let mainFiles = resolveMainChangedFiles(cwd, changeName)
|
|
600
|
+
|
|
601
|
+
// 并入 worktree 未提交改动(坑 module-subset-zero-hit-uncommitted,2026-08-21 实证:
|
|
602
|
+
// 子代理默认不 commit,真实改动全在 worktree working-tree——只看 base..HEAD commit diff
|
|
603
|
+
// 时 module 映射 0 命中直接跳过(frontend/** 变更未命中 frontend 模块)。与
|
|
604
|
+
// generateTaskReviewDrafts 的并入口径同源:meta.worktreePath 下 status --porcelain 文件
|
|
605
|
+
// (排除 .sillyspec/ 运行时产物)。opt-in(默认关):d drafts 有自己的并入点,避免双并。
|
|
606
|
+
if (includeWorkingTree && mainFiles !== null) {
|
|
607
|
+
try {
|
|
608
|
+
const metaPath = join(cwd, '.sillyspec', '.runtime', 'worktrees', changeName, 'meta.json')
|
|
609
|
+
if (changeName && existsSync(metaPath)) {
|
|
610
|
+
const meta = JSON.parse(readFileSync(metaPath, 'utf8'))
|
|
611
|
+
const wtGitDir = (meta.worktreePath && meta.mode !== 'in-place-fallback' && existsSync(meta.worktreePath))
|
|
612
|
+
? meta.worktreePath
|
|
613
|
+
: cwd
|
|
614
|
+
const wtStatus = gitQuiet(wtGitDir, ['status', '--porcelain'], { timeout: 30000, trim: false })
|
|
615
|
+
const wtFiles = String(wtStatus || '').split('\n')
|
|
616
|
+
.map(l => l.slice(3).trim().split(' -> ').pop() || '')
|
|
617
|
+
.map(p => p.replace(/^"|"$/g, '').replace(/\\/g, '/'))
|
|
618
|
+
.filter(p => p && p !== '.sillyspec' && !p.startsWith('.sillyspec/'))
|
|
619
|
+
if (wtFiles.length > 0) {
|
|
620
|
+
mainFiles = [...new Set([...(mainFiles || []), ...wtFiles])]
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
} catch { /* working-tree 并入失败退回 commit diff 口径(fail-open) */ }
|
|
624
|
+
}
|
|
481
625
|
|
|
482
626
|
// 无 ctx / ctx 无跨仓 entry → 主仓 diff 即结果(零回归)
|
|
483
627
|
if (!ctx || typeof ctx.repos !== 'object' || ctx.repos === null) return mainFiles
|
|
@@ -581,11 +725,15 @@ export function runVerifyTestCheck({ cwd, specBase, changeName = null, ctx = nul
|
|
|
581
725
|
let modulesPresent = false
|
|
582
726
|
let hitCount = 0
|
|
583
727
|
let hits = []
|
|
728
|
+
let lastChangedFiles = [] // 0 命中诊断用(diff 文件样例可见性,坑 module-path-layout-mismatch)
|
|
584
729
|
if (strategy === 'module') {
|
|
585
730
|
const modules = extractModules(yamlText)
|
|
586
731
|
if (modules) {
|
|
587
732
|
modulesPresent = true
|
|
588
|
-
|
|
733
|
+
// includeWorkingTree(坑 module-subset-zero-hit-uncommitted):子代理不 commit 的改动
|
|
734
|
+
// 也参与 module 命中判定,0 命中跳过不再误伤 worktree 未提交的真实变更
|
|
735
|
+
const changedFiles = resolveVerifyChangedFiles(cwd, changeName, null, { includeWorkingTree: true })
|
|
736
|
+
lastChangedFiles = Array.isArray(changedFiles) ? changedFiles : []
|
|
589
737
|
if (changedFiles === null) {
|
|
590
738
|
hitCount = -1 // git 不可用 / 非仓库
|
|
591
739
|
} else {
|
|
@@ -602,13 +750,24 @@ export function runVerifyTestCheck({ cwd, specBase, changeName = null, ctx = nul
|
|
|
602
750
|
} else if (action === 'module-zero-hit-skip') {
|
|
603
751
|
// module 模式 0 命中:不静默回退注定超时/含预存失败的全量(坑 verify-worktree-... 修复方向 3)。
|
|
604
752
|
// 据 verify-result.md 自报告判定;想跑全量请显式设 test_strategy: full。
|
|
753
|
+
// 诊断可见性(坑 module-path-layout-mismatch,2026-08-22 实证:0 命中「靠第一次跑过的
|
|
754
|
+
// 记录兜底」——为何没命中完全黑箱):落 modules 配置 path vs diff 文件样例,配置前缀
|
|
755
|
+
// 对不上(如 packages/frontend vs frontend/)一眼可见
|
|
756
|
+
const modules_ = extractModules(yamlText) || {}
|
|
757
|
+
const diagLines = [
|
|
758
|
+
`已配置 modules(${Object.keys(modules_).length} 个): ${Object.entries(modules_).map(([k, m]) => `${k}→${m.path}`).join('、') || '(无)'}`,
|
|
759
|
+
`本次 diff(${lastChangedFiles.length} 个文件,前 5): ${lastChangedFiles.slice(0, 5).join(', ') || '(空)'}`,
|
|
760
|
+
]
|
|
761
|
+
console.warn(`⚠️ 模块 0 命中诊断(对照 path 前缀与 diff 布局是否一致,如 packages/<name> vs <name>/):`)
|
|
762
|
+
for (const l of diagLines) console.warn(` ${l}`)
|
|
605
763
|
mainResult = {
|
|
606
764
|
status: 'skipped',
|
|
607
765
|
command: null,
|
|
608
766
|
exitCode: null,
|
|
609
767
|
durationMs: null,
|
|
610
768
|
outputTail: null,
|
|
611
|
-
reason: 'test_strategy: module 但本次变更未命中任何已配置 modules(0 命中)。为避免回退到注定超时/含预存失败的全量 commands.test,CLI 未自动跑全量——据 verify-result.md 自报告判定测试。若需全量覆盖,显式设 test_strategy: full。'
|
|
769
|
+
reason: 'test_strategy: module 但本次变更未命中任何已配置 modules(0 命中)。为避免回退到注定超时/含预存失败的全量 commands.test,CLI 未自动跑全量——据 verify-result.md 自报告判定测试。若需全量覆盖,显式设 test_strategy: full。' +
|
|
770
|
+
` 诊断:${diagLines.join(';')}`,
|
|
612
771
|
resultPath: null,
|
|
613
772
|
mode: 'module-zero-hit',
|
|
614
773
|
fallbackReason: null,
|
|
@@ -794,6 +953,53 @@ function mergeResultInfo(mainResult, crossResults) {
|
|
|
794
953
|
/**
|
|
795
954
|
* 全量跑 commands.test(现有逻辑,brownfield 行为不变)。
|
|
796
955
|
*/
|
|
956
|
+
/**
|
|
957
|
+
* 从测试命令文本提取疑似服务端口(坑 verify-devserver-port-race,2026-08-22 实证:CLI 全量
|
|
958
|
+
* 对账与用户自留 dev server 资源竞争——端口被占导致测试失败,差点误报 FAIL 成代码问题)。
|
|
959
|
+
* 认 --port=N / --port N / PORT=N。
|
|
960
|
+
* @param {string} cmd
|
|
961
|
+
* @returns {number[]}
|
|
962
|
+
*/
|
|
963
|
+
function extractPortsFromCommand(cmd) {
|
|
964
|
+
const s = String(cmd || '')
|
|
965
|
+
const ports = new Set()
|
|
966
|
+
for (const m of s.matchAll(/--port[=\s]+(\d{2,5})/gi)) ports.add(Number(m[1]))
|
|
967
|
+
for (const m of s.matchAll(/\bPORT=(\d{2,5})/gi)) ports.add(Number(m[1]))
|
|
968
|
+
return [...ports]
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* 端口占用探测(同步 spawnSync node 试连——verify 实测是同步 execSync 流,无法 await)。
|
|
973
|
+
* @param {number} port
|
|
974
|
+
* @returns {boolean} true=已被占用(疑似自留 dev server/长驻服务在跑)
|
|
975
|
+
*/
|
|
976
|
+
function isPortOccupiedSync(port) {
|
|
977
|
+
try {
|
|
978
|
+
const { spawnSync } = require('node:child_process')
|
|
979
|
+
const r = spawnSync(process.execPath, ['-e',
|
|
980
|
+
`const n=require('node:net');const s=n.connect(${port},'127.0.0.1',()=>{console.log('Y');s.end()});s.on('error',()=>console.log('N'));setTimeout(()=>{console.log('N');process.exit(0)},1500)`],
|
|
981
|
+
{ encoding: 'utf8', timeout: 4000 })
|
|
982
|
+
return (r.stdout || '').trim().endsWith('Y')
|
|
983
|
+
} catch { return false }
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* 实测前资源竞争预警(坑 verify-devserver-port-race):测试命令涉及的端口已被占用 →
|
|
988
|
+
* 显著 warn「疑似自留 dev server」+ 建议停服务重跑——防把资源竞争误判成代码问题报 FAIL。
|
|
989
|
+
* best-effort:探测失败静默。
|
|
990
|
+
*/
|
|
991
|
+
function warnPortRaceBeforeRun(command) {
|
|
992
|
+
try {
|
|
993
|
+
const ports = extractPortsFromCommand(command)
|
|
994
|
+
for (const p of ports) {
|
|
995
|
+
if (isPortOccupiedSync(p)) {
|
|
996
|
+
console.warn(`⚠️ 端口 ${p} 已被占用(测试命令 ${command.slice(0, 50)}… 引用)——疑似你自留的 dev server/长驻服务。`)
|
|
997
|
+
console.warn(` 测试若因此失败(端口冲突/EADDRINUSE),是资源竞争而非代码问题——停掉占用服务(或换端口)后重跑 verify 再定论,勿直接报 FAIL。`)
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
} catch { /* 探测失败不阻断实测 */ }
|
|
1001
|
+
}
|
|
1002
|
+
|
|
797
1003
|
function runFullCommand({ yamlText, localYamlPath, cwd, specBase, changeName, fallbackReason = null, knownFailures = [] }) {
|
|
798
1004
|
const command = extractTestCommand(yamlText)
|
|
799
1005
|
|
|
@@ -817,6 +1023,7 @@ function runFullCommand({ yamlText, localYamlPath, cwd, specBase, changeName, fa
|
|
|
817
1023
|
let exitCode = 0
|
|
818
1024
|
let output = ''
|
|
819
1025
|
let reason = null
|
|
1026
|
+
warnPortRaceBeforeRun(command)
|
|
820
1027
|
try {
|
|
821
1028
|
output = execSync(command, {
|
|
822
1029
|
cwd,
|
|
@@ -831,6 +1038,11 @@ function runFullCommand({ yamlText, localYamlPath, cwd, specBase, changeName, fa
|
|
|
831
1038
|
reason = e.signal === 'SIGTERM' && Date.now() - startedAt >= TEST_TIMEOUT_MS
|
|
832
1039
|
? `测试命令超时(>${TEST_TIMEOUT_MS / 1000}s)`
|
|
833
1040
|
: `测试命令退出码 ${exitCode}`
|
|
1041
|
+
// 资源竞争鉴别提示(坑 verify-devserver-port-race):EADDRINUSE/端口占用类失败极可能是
|
|
1042
|
+
// 自留 dev server 竞争而非代码问题——输出里明示鉴别路径,防误报 FAIL
|
|
1043
|
+
if (/EADDRINUSE|address already in use|端口.*被占用|port.*already/i.test(output)) {
|
|
1044
|
+
reason += '。⚠️ 输出含端口占用信号(EADDRINUSE)——极可能是与你自留 dev server 的资源竞争而非代码问题:停掉占用服务后重跑 verify 再定论'
|
|
1045
|
+
}
|
|
834
1046
|
}
|
|
835
1047
|
const durationMs = Date.now() - startedAt
|
|
836
1048
|
const outputTail = output.length > OUTPUT_TAIL_CHARS ? '…' + output.slice(-OUTPUT_TAIL_CHARS) : output
|
|
@@ -873,6 +1085,11 @@ function runModuleSubset({ cwd, specBase, changeName, hits, knownFailures = [] }
|
|
|
873
1085
|
const reason = status === 'passed'
|
|
874
1086
|
? null
|
|
875
1087
|
: `模块子集测试失败:${perModule.filter(r => r.status === 'failed').map(r => r.name).join(', ')}`
|
|
1088
|
+
// 失败模块的 reason 明细透传(坑 verify-devserver-port-race:EADDRINUSE 资源竞争鉴别
|
|
1089
|
+
// 提示在 runOneModule 的 reason 里,不透传会被顶层 reason 吞掉)
|
|
1090
|
+
+ (perModule.filter(r => r.status === 'failed' && r.reason).some(r => /EADDRINUSE|资源竞争/.test(r.reason))
|
|
1091
|
+
? '。' + perModule.filter(r => r.status === 'failed' && r.reason && /EADDRINUSE|资源竞争/.test(r.reason)).map(r => r.reason).join(';')
|
|
1092
|
+
: '')
|
|
876
1093
|
|
|
877
1094
|
const result = {
|
|
878
1095
|
status,
|