sillyspec 3.24.1 → 3.24.2
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/package.json +1 -1
- package/src/run.js +39 -8
- package/src/stage-review.js +1 -1
- package/src/stages/brainstorm.js +2 -0
- package/src/stages/plan.js +12 -11
- package/src/task-review.js +15 -2
- package/src/worktree-apply.js +33 -13
package/package.json
CHANGED
package/src/run.js
CHANGED
|
@@ -607,7 +607,7 @@ async function getStageSteps(stageName, cwd, progress, specDir = null) {
|
|
|
607
607
|
/**
|
|
608
608
|
* 确保阶段的 steps 已初始化到 progress
|
|
609
609
|
*/
|
|
610
|
-
async function ensureStageSteps(progress, stageName, cwd, specDir = null) {
|
|
610
|
+
export async function ensureStageSteps(progress, stageName, cwd, specDir = null) {
|
|
611
611
|
if (!progress.stages) progress.stages = {}
|
|
612
612
|
|
|
613
613
|
const steps = await getStageSteps(stageName, cwd, progress, specDir)
|
|
@@ -628,7 +628,15 @@ async function ensureStageSteps(progress, stageName, cwd, specDir = null) {
|
|
|
628
628
|
const oldSteps = progress.stages[stageName].steps
|
|
629
629
|
progress.stages[stageName].steps = steps.map(s => {
|
|
630
630
|
const old = oldSteps.find(step => step.name === s.name)
|
|
631
|
-
if (old) return old
|
|
631
|
+
if (old) return old // 精确名命中 → 保留旧状态
|
|
632
|
+
// migratedFrom:新步骤是合并/重命名来的(如 brainstorm 13→8 折叠)。
|
|
633
|
+
// 吸收的旧步骤全部 completed → 新步骤标 completed,避免 completed 丢失导致 currentIdx 回跳。
|
|
634
|
+
if (Array.isArray(s.migratedFrom) && s.migratedFrom.length > 0) {
|
|
635
|
+
const migrated = oldSteps.filter(step => s.migratedFrom.includes(step.name))
|
|
636
|
+
if (migrated.length > 0 && migrated.every(step => step.status === 'completed')) {
|
|
637
|
+
return { name: s.name, status: 'completed', migratedFrom: true }
|
|
638
|
+
}
|
|
639
|
+
}
|
|
632
640
|
return { name: s.name, status: 'pending' }
|
|
633
641
|
})
|
|
634
642
|
return true
|
|
@@ -916,7 +924,8 @@ async function outputStep(stageName, stepIndex, steps, cwd, changeName, dbProjec
|
|
|
916
924
|
if (stageName === 'execute' && promptText.includes('{EXECUTE_RUN_ID}')) {
|
|
917
925
|
let runId = ''
|
|
918
926
|
const execSpecBase = platformOpts?.specRoot || join(cwd, '.sillyspec')
|
|
919
|
-
const
|
|
927
|
+
const runtimeRoot = platformOpts?.runtimeRoot || join(execSpecBase, '.runtime')
|
|
928
|
+
const runIdFile = join(runtimeRoot, `current-execute-run-id-${changeName}`)
|
|
920
929
|
try {
|
|
921
930
|
if (existsSync(runIdFile)) {
|
|
922
931
|
runId = readFileSync(runIdFile, 'utf8').trim()
|
|
@@ -925,6 +934,8 @@ async function outputStep(stageName, stepIndex, steps, cwd, changeName, dbProjec
|
|
|
925
934
|
if (!runId) {
|
|
926
935
|
const { generateExecuteRunId } = await import('./task-review.js')
|
|
927
936
|
runId = generateExecuteRunId()
|
|
937
|
+
// 落盘(与启动站点一致),保证 agent 收到的 ID == gate/checkbox 读取的 ID
|
|
938
|
+
try { mkdirSync(runtimeRoot, { recursive: true }); writeFileSync(runIdFile, runId + '\n') } catch {}
|
|
928
939
|
}
|
|
929
940
|
promptText = promptText.replace(/\{EXECUTE_RUN_ID\}/g, runId)
|
|
930
941
|
}
|
|
@@ -1609,13 +1620,31 @@ export async function runCommand(args, cwd, specDir = null) {
|
|
|
1609
1620
|
if (autoChange) {
|
|
1610
1621
|
progress = await pm.initChange(cwd, autoChange)
|
|
1611
1622
|
} else if (isAuxiliary) {
|
|
1612
|
-
|
|
1613
|
-
|
|
1623
|
+
let autoName = changeName || resolveChangeNameAuto(cwd, specRoot) || 'default'
|
|
1624
|
+
// archive 特例:归档后变更从活跃列表排除(listChanges WHERE status='active'),
|
|
1625
|
+
// 不带 --change 回退 default 会读错变更。无活跃变更时取最新归档变更,读其现有 progress。
|
|
1626
|
+
if (stageName === 'archive' && autoName === 'default') {
|
|
1627
|
+
try {
|
|
1628
|
+
const archiveDir = join(specBase, 'changes', 'archive')
|
|
1629
|
+
if (existsSync(archiveDir)) {
|
|
1630
|
+
const latest = readdirSync(archiveDir)
|
|
1631
|
+
.filter(d => /^\d{4}-\d{2}-\d{2}-.+/.test(d))
|
|
1632
|
+
.sort()
|
|
1633
|
+
.pop()
|
|
1634
|
+
if (latest) {
|
|
1635
|
+
autoName = latest.replace(/^\d{4}-\d{2}-\d{2}-/, '')
|
|
1636
|
+
progress = await pm.read(cwd, autoName)
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
} catch {}
|
|
1640
|
+
}
|
|
1614
1641
|
changeName = autoName
|
|
1615
|
-
progress = await pm.initChange(cwd, autoName)
|
|
1616
|
-
// initChange 可能因 project 表为空返回 null
|
|
1617
1642
|
if (!progress) {
|
|
1618
|
-
progress =
|
|
1643
|
+
progress = await pm.initChange(cwd, autoName)
|
|
1644
|
+
// initChange 可能因 project 表为空返回 null
|
|
1645
|
+
if (!progress) {
|
|
1646
|
+
progress = { currentStage: stageName, stages: {}, lastActive: new Date().toLocaleString('zh-CN', { hour12: false }), project: '' }
|
|
1647
|
+
}
|
|
1619
1648
|
}
|
|
1620
1649
|
} else {
|
|
1621
1650
|
// brainstorm 作为流程入口,自动生成变更名并初始化
|
|
@@ -3547,6 +3576,8 @@ async function completeStep(pm, progress, stageName, cwd, outputText, inputText
|
|
|
3547
3576
|
if (!executeRunId) {
|
|
3548
3577
|
const { generateExecuteRunId } = await import('./task-review.js')
|
|
3549
3578
|
executeRunId = generateExecuteRunId()
|
|
3579
|
+
// 落盘(marker 缺失时 fallback 生成后写盘,保证后续 checkbox/gate 读到同一 ID)
|
|
3580
|
+
try { mkdirSync(runtimeRoot, { recursive: true }); writeFileSync(runIdFile, executeRunId + '\n') } catch {}
|
|
3550
3581
|
}
|
|
3551
3582
|
|
|
3552
3583
|
// git 真实性校验目录:worktree 存在则用 worktree(base/head commit 在其中),否则主仓库
|
package/src/stage-review.js
CHANGED
|
@@ -134,7 +134,7 @@ export function verifyStageReviewDocHash(review, searchDirs) {
|
|
|
134
134
|
const actual = computeDocHash(abs)
|
|
135
135
|
if (actual === null) continue
|
|
136
136
|
// 找到主文档,比对 hash
|
|
137
|
-
if (review.docHash !== actual) {
|
|
137
|
+
if (review.docHash.toLowerCase() !== actual.toLowerCase()) {
|
|
138
138
|
errors.push(`docHash 与主审查文档 ${primaryRel} 的实际内容不匹配 — review.json 疑似伪造(未真正读取文档)`)
|
|
139
139
|
return { ok: false, errors, warnings }
|
|
140
140
|
}
|
package/src/stages/brainstorm.js
CHANGED
|
@@ -71,6 +71,7 @@ export const definition = {
|
|
|
71
71
|
},
|
|
72
72
|
{
|
|
73
73
|
name: '对话式探索与需求澄清',
|
|
74
|
+
migratedFrom: ['协作与复用检查', '原型/设计图分析', '需求范围评估', '对话式探索', '需求澄清 Grill'],
|
|
74
75
|
conditionalWait: true,
|
|
75
76
|
repeatableWait: true,
|
|
76
77
|
maxWaitRounds: 8,
|
|
@@ -211,6 +212,7 @@ export const definition = {
|
|
|
211
212
|
},
|
|
212
213
|
{
|
|
213
214
|
name: '分段展示设计',
|
|
215
|
+
migratedFrom: ['HTML 原型生成'],
|
|
214
216
|
requiresWait: true,
|
|
215
217
|
waitReason: '等待用户确认设计方案',
|
|
216
218
|
waitOptions: ['确认', '需要修改', '推翻重来'],
|
package/src/stages/plan.js
CHANGED
|
@@ -384,16 +384,16 @@ tier: {REVIEW_TIER}({REVIEW_TIER_REASON})
|
|
|
384
384
|
* 每个 task 生成 20~40 行紧凑可执行卡片
|
|
385
385
|
*/
|
|
386
386
|
export function buildCoordinatorStep(changeDir, taskNames) {
|
|
387
|
-
const taskList = taskNames.map(
|
|
388
|
-
const num =
|
|
389
|
-
return `- task-${num}: ${name}`
|
|
387
|
+
const taskList = taskNames.map(t => {
|
|
388
|
+
const num = t.num
|
|
389
|
+
return `- task-${num}: ${t.name}`
|
|
390
390
|
}).join('\n')
|
|
391
391
|
|
|
392
|
-
const subagentPrompts = taskNames.map(
|
|
393
|
-
const num =
|
|
392
|
+
const subagentPrompts = taskNames.map(t => {
|
|
393
|
+
const num = t.num
|
|
394
394
|
return `\`\`\`
|
|
395
395
|
任务编号:task-${num}
|
|
396
|
-
任务名称:${name}
|
|
396
|
+
任务名称:${t.name}
|
|
397
397
|
文件路径:${changeDir}/tasks/task-${num}.md
|
|
398
398
|
当前时间:<now-datetime>(frontmatter 的 created_at 使用此值)
|
|
399
399
|
当前用户:<git-user>(frontmatter 的 author 使用此值)
|
|
@@ -405,7 +405,7 @@ export function buildCoordinatorStep(changeDir, taskNames) {
|
|
|
405
405
|
|
|
406
406
|
---
|
|
407
407
|
id: task-${num}
|
|
408
|
-
title: ${name}
|
|
408
|
+
title: ${t.name}
|
|
409
409
|
title_zh: <任务中文标题>
|
|
410
410
|
author: <git-user>
|
|
411
411
|
created_at: <now-datetime>
|
|
@@ -551,13 +551,14 @@ function parseTaskCount(planContent) {
|
|
|
551
551
|
* 从 plan.md 解析任务名列表
|
|
552
552
|
*/
|
|
553
553
|
function parseTaskNames(planContent) {
|
|
554
|
-
|
|
554
|
+
// 返回 [{name, num}]:保留 plan.md 原始编号,避免 buildCoordinatorStep 按 i+1 重编号与 execute 原始编号错位
|
|
555
|
+
const tasks = []
|
|
555
556
|
const lines = planContent.split('\n')
|
|
556
557
|
for (const line of lines) {
|
|
557
|
-
const m = line.match(/^[-*]\s*\[[ x]\]\s*task
|
|
558
|
-
if (m)
|
|
558
|
+
const m = line.match(/^[-*]\s*\[[ x]\]\s*task-(\d+):\s*(.+)/i)
|
|
559
|
+
if (m) tasks.push({ num: String(m[1]).padStart(2, '0'), name: m[2].trim() })
|
|
559
560
|
}
|
|
560
|
-
return
|
|
561
|
+
return tasks
|
|
561
562
|
}
|
|
562
563
|
|
|
563
564
|
/**
|
package/src/task-review.js
CHANGED
|
@@ -337,9 +337,22 @@ export function verifyReviewGitEvidence(review, gitDir) {
|
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
const emptyDiff = diffFiles.length === 0
|
|
340
|
+
// emptyDiff 回退:子代理可能未 commit,base..head 无 commit diff 但 working-tree 有改动。
|
|
341
|
+
// 对齐 checkExecuteCodeEvidence(stage-contract.js 同时查 working-tree)语义,避免误判零改动伪造。
|
|
342
|
+
let workingTreeChanged = false
|
|
343
|
+
if (emptyDiff) {
|
|
344
|
+
try {
|
|
345
|
+
const wtStatus = runGit(gitDir, ['status', '--porcelain'])
|
|
346
|
+
workingTreeChanged = !!wtStatus && wtStatus.trim().length > 0
|
|
347
|
+
} catch {}
|
|
348
|
+
if (workingTreeChanged) {
|
|
349
|
+
warnings.push(`base..head 无 commit diff(${review.base.slice(0, 8)}..${review.head.slice(0, 8)}),但 working-tree 有未提交改动 —— 按有效改动处理,不判零改动伪造`)
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const effectiveEmptyDiff = emptyDiff && !workingTreeChanged
|
|
340
353
|
|
|
341
354
|
// changedFiles 交叉比对:完全不相交 = review 描述的改动与实际 diff 无关
|
|
342
|
-
if (!
|
|
355
|
+
if (!effectiveEmptyDiff && Array.isArray(review.changedFiles) && review.changedFiles.length > 0) {
|
|
343
356
|
const normalize = (p) => String(p).replace(/^\.\//, '')
|
|
344
357
|
const diffSet = new Set(diffFiles.map(normalize))
|
|
345
358
|
const hasOverlap = review.changedFiles.some(f => {
|
|
@@ -352,7 +365,7 @@ export function verifyReviewGitEvidence(review, gitDir) {
|
|
|
352
365
|
}
|
|
353
366
|
}
|
|
354
367
|
|
|
355
|
-
return { ok: errors.length === 0, emptyDiff, errors, warnings, unavailable: false }
|
|
368
|
+
return { ok: errors.length === 0, emptyDiff: effectiveEmptyDiff, errors, warnings, unavailable: false }
|
|
356
369
|
}
|
|
357
370
|
|
|
358
371
|
/**
|
package/src/worktree-apply.js
CHANGED
|
@@ -343,20 +343,15 @@ export function applyWorktree(changeName, { cwd, checkOnly = false, merge = fals
|
|
|
343
343
|
* @returns {object} result(merged=true 表示走了 merge 降级)
|
|
344
344
|
*/
|
|
345
345
|
function applyByMerge(result, changeName, projectRoot, wm) {
|
|
346
|
+
const meta = wm.getMeta(changeName);
|
|
347
|
+
const changedFiles = result.changedFiles || [];
|
|
348
|
+
// 用 meta.branch(native-worktree 模式分支名可能不是 sillyspec/<change>),不硬编码。
|
|
349
|
+
const branch = meta.branch || `sillyspec/${changeName}`;
|
|
350
|
+
|
|
346
351
|
try {
|
|
347
|
-
git(projectRoot, `merge --no-ff
|
|
348
|
-
result.merged = true;
|
|
349
|
-
result.ok = true;
|
|
350
|
-
try { result.mergeSummary = git(projectRoot, `log --oneline -1`); } catch {}
|
|
351
|
-
// 成功后自动 cleanup(与 patch 路径步骤 8 一致;分支已合并,删除安全)
|
|
352
|
-
try {
|
|
353
|
-
wm.cleanup(changeName);
|
|
354
|
-
} catch (cleanupErr) {
|
|
355
|
-
result.warnings = result.warnings || [];
|
|
356
|
-
result.warnings.push(`cleanup 失败(不影响 merge 结果): ${cleanupErr.message}`);
|
|
357
|
-
}
|
|
352
|
+
git(projectRoot, `merge --no-ff ${branch}`);
|
|
358
353
|
} catch (e) {
|
|
359
|
-
// merge
|
|
354
|
+
// merge 冲突:取冲突文件列表 + abort 回滚(不 cleanup,保留 worktree)
|
|
360
355
|
let conflictFiles = [];
|
|
361
356
|
try {
|
|
362
357
|
const cf = gitQuiet(projectRoot, `diff --name-only --diff-filter=U`);
|
|
@@ -364,10 +359,35 @@ function applyByMerge(result, changeName, projectRoot, wm) {
|
|
|
364
359
|
} catch {}
|
|
365
360
|
try { gitQuiet(projectRoot, `merge --abort`); } catch {}
|
|
366
361
|
result.errors.push(
|
|
367
|
-
`git merge
|
|
362
|
+
`git merge ${branch} 冲突,请手动解决。冲突文件:\n` +
|
|
368
363
|
(conflictFiles.length ? ` ${conflictFiles.join('\n ')}\n` : ` (未能获取冲突文件列表)\n`) +
|
|
369
364
|
`已执行 git merge --abort 回滚到合并前状态。`
|
|
370
365
|
);
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// 落地校验:merge 报成功(exit 0)不代表交付物真进 main——
|
|
370
|
+
// 分支可能只含 baseline checkpoint(子代理改动未 commit),merge 产生空内容合并,文件零落地。
|
|
371
|
+
// 逐个确认 changedFiles 在 main HEAD 存在。任一缺失 → 不 cleanup(fail-open:保留 worktree 唯一副本)。
|
|
372
|
+
result.merged = true;
|
|
373
|
+
const notLanded = changedFiles.filter(f => gitQuiet(projectRoot, `cat-file -e HEAD:${f}`) === null);
|
|
374
|
+
if (notLanded.length > 0) {
|
|
375
|
+
result.ok = false;
|
|
376
|
+
result.errors.push(
|
|
377
|
+
`git merge ${branch} 报成功,但 ${notLanded.length}/${changedFiles.length} 个交付文件未出现在 main HEAD` +
|
|
378
|
+
`(分支可能只含 baseline checkpoint,子代理改动未 commit)。worktree 已保留(未 cleanup),` +
|
|
379
|
+
`请用 git cherry-pick 或手动 cp 落地:\n ${notLanded.join('\n ')}`
|
|
380
|
+
);
|
|
381
|
+
return result;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
result.ok = true;
|
|
385
|
+
try { result.mergeSummary = git(projectRoot, `log --oneline -1`); } catch {}
|
|
386
|
+
try {
|
|
387
|
+
wm.cleanup(changeName);
|
|
388
|
+
} catch (cleanupErr) {
|
|
389
|
+
result.warnings = result.warnings || [];
|
|
390
|
+
result.warnings.push(`cleanup 失败(不影响 merge 结果): ${cleanupErr.message}`);
|
|
371
391
|
}
|
|
372
392
|
return result;
|
|
373
393
|
}
|