sillyspec 3.33.0 → 3.33.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.
Files changed (72) hide show
  1. package/.claude/skills/sillyspec-flow/SKILL.md +18 -10
  2. package/.github/workflows/ci.yml +11 -3
  3. package/AGENTS.md +3 -3
  4. package/README.md +2 -2
  5. package/assets/command-cards/flow.md +9 -5
  6. package/package.json +1 -1
  7. package/src/archive-delta.js +4 -3
  8. package/src/change-delete.js +6 -5
  9. package/src/contract-matrix.js +2 -1
  10. package/src/cross-placement.js +5 -1
  11. package/src/cross-repo-reconcile.js +4 -1
  12. package/src/db.js +8 -2
  13. package/src/decision-distill.js +22 -8
  14. package/src/decision-values.js +34 -0
  15. package/src/decisions-io.js +5 -2
  16. package/src/deleted-ledger.js +2 -1
  17. package/src/doctor-diagnostics.js +8 -3
  18. package/src/flow-draft.js +17 -10
  19. package/src/flow-parity.js +93 -5
  20. package/src/flow-review-pack.js +183 -0
  21. package/src/flow-review.js +45 -3
  22. package/src/flow.js +365 -109
  23. package/src/friction-ledger.js +2 -1
  24. package/src/friction-tally.js +8 -4
  25. package/src/handoff.js +2 -1
  26. package/src/hooks/worktree-guard.js +5 -5
  27. package/src/index.js +62 -21
  28. package/src/init.js +7 -30
  29. package/src/knowledge-hits.js +2 -1
  30. package/src/knowledge-vector.js +2 -1
  31. package/src/progress/consistency-doctor.js +5 -2
  32. package/src/progress/stage-machine.js +6 -2
  33. package/src/progress.js +19 -8
  34. package/src/quicklog.js +194 -9
  35. package/src/review-dispatch.js +4 -3
  36. package/src/review-tier.js +2 -1
  37. package/src/route-hindsight.js +4 -3
  38. package/src/run/bg-sync.js +10 -3
  39. package/src/run/command.js +14 -12
  40. package/src/run/complete-handlers.js +40 -37
  41. package/src/run/complete.js +12 -8
  42. package/src/run/gate-snapshot-ledger.js +2 -1
  43. package/src/run/gate-snapshot.js +102 -23
  44. package/src/run/gates.js +32 -8
  45. package/src/run/prompt.js +6 -5
  46. package/src/run/scan-profile.js +2 -1
  47. package/src/run/shared.js +109 -5
  48. package/src/run/stage.js +5 -4
  49. package/src/run/test-ledger.js +2 -1
  50. package/src/run/verify-quality-scan.js +11 -5
  51. package/src/runtime-paths.js +189 -0
  52. package/src/scan-refresh.js +4 -3
  53. package/src/scope-audit.js +13 -7
  54. package/src/sentinel-assertions.js +37 -0
  55. package/src/spec-sync.js +38 -22
  56. package/src/stage-contract.js +24 -2
  57. package/src/stage-review.js +3 -2
  58. package/src/stage-templates.js +3 -2
  59. package/src/stages/brainstorm.js +6 -5
  60. package/src/sync-noise.js +3 -2
  61. package/src/sync.js +71 -15
  62. package/src/task-done.js +2 -1
  63. package/src/task-review.js +7 -5
  64. package/src/task-tick.js +45 -1
  65. package/src/validate-artifacts.js +2 -1
  66. package/src/verify-draft.js +2 -1
  67. package/src/verify-postcheck.js +11 -10
  68. package/src/verify-probes.js +157 -52
  69. package/src/watcher.js +15 -9
  70. package/src/worktree-apply.js +2 -1
  71. package/src/write-audit.js +2 -1
  72. package/templates/agents-instruction.md +3 -3
@@ -31,6 +31,7 @@
31
31
  * 本模块自身不打印任何输出。
32
32
  */
33
33
  import { readFileSync, mkdirSync } from 'fs'
34
+ import { runtimeStatePath } from './runtime-paths.js'
34
35
  import { dirname, join } from 'path'
35
36
  import { writeAtomicSync } from './fs-atomic.js'
36
37
  import { withFileLock } from './quicklog.js'
@@ -45,7 +46,7 @@ const LEDGER_CAP = 200
45
46
  const LEDGER_FILENAME = 'friction-ledger.json'
46
47
 
47
48
  function ledgerFilePath(runtimeRoot) {
48
- return join(runtimeRoot, LEDGER_FILENAME)
49
+ return runtimeStatePath(runtimeRoot, LEDGER_FILENAME)
49
50
  }
50
51
 
51
52
  /**
@@ -24,6 +24,7 @@
24
24
  * 不打印任何输出,提示何时打印由调用方决定。
25
25
  */
26
26
  import { existsSync, mkdirSync, readFileSync, rmSync } from 'fs'
27
+ import { runtimeStatePath } from './runtime-paths.js'
27
28
  import { dirname, join } from 'path'
28
29
  import { writeAtomicSync } from './fs-atomic.js'
29
30
  import { withFileLock } from './quicklog.js'
@@ -76,7 +77,7 @@ function frictionTallyPath({ cwd, platformOpts, changeName }) {
76
77
  if (QUICK_SESSION_ID_RE.test(changeName)) {
77
78
  return join(resolveQuickSessionsDir(platformOpts, specBase), changeName, 'friction-tally.json')
78
79
  }
79
- return join(resolveRuntimeRoot(platformOpts, specBase), `friction-tally-${changeName}.json`)
80
+ return runtimeStatePath(resolveRuntimeRoot(platformOpts, specBase), `friction-tally-${changeName}.json`)
80
81
  }
81
82
 
82
83
  /** YAML 布尔值宽松解析:仅显式 false(含引号形态)为关,其余值一律默认开(R-05) */
@@ -174,10 +175,12 @@ export function renderFrictionHintLine(counts) {
174
175
  export async function recordFrictionEvent({ cwd, platformOpts, changeName, type, detail }) {
175
176
  try {
176
177
  if (!FRICTION_TYPES.has(type)) return null
178
+ // enabled=false 直通:record/consume 双 no-op,.runtime 零写入(D-003 一键全关)。
179
+ // 必须先于 frictionTallyPath(2026-10-18 起路径助手带 mkdir-p 目录保证,关闭态
180
+ // 构造路径即建 state/ 目录=破坏零写入契约)
181
+ if (!readFrictionHintEnabled(deriveSpecBase(cwd, platformOpts))) return null
177
182
  const tallyPath = frictionTallyPath({ cwd, platformOpts, changeName })
178
183
  if (!tallyPath) return null
179
- // enabled=false 直通:record/consume 双 no-op,.runtime 零写入(D-003 一键全关)
180
- if (!readFrictionHintEnabled(deriveSpecBase(cwd, platformOpts))) return null
181
184
  return await withFileLock(tallyPath + ".lock", async () => {
182
185
  const tally = readFrictionTally(tallyPath)
183
186
  const at = new Date().toISOString()
@@ -207,9 +210,10 @@ export async function recordFrictionEvent({ cwd, platformOpts, changeName, type,
207
210
  */
208
211
  export async function consumeFrictionHint({ cwd, platformOpts, changeName }) {
209
212
  try {
213
+ // enabled 检查先于路径构造(同 record:关闭态零写入,路径助手 mkdir-p 不触发)
214
+ if (!readFrictionHintEnabled(deriveSpecBase(cwd, platformOpts))) return { hint: null, counts: {} }
210
215
  const tallyPath = frictionTallyPath({ cwd, platformOpts, changeName })
211
216
  if (!tallyPath || !existsSync(tallyPath)) return { hint: null, counts: {} }
212
- if (!readFrictionHintEnabled(deriveSpecBase(cwd, platformOpts))) return { hint: null, counts: {} }
213
217
  return await withFileLock(tallyPath + ".lock", async () => {
214
218
  const tally = readFrictionTally(tallyPath)
215
219
  const counts = {}
package/src/handoff.js CHANGED
@@ -15,6 +15,7 @@
15
15
  * 整块 80 行帽(HANDOFF_LINE_CAP),超限从上下文段尾截,粘贴块与警示行永不动。
16
16
  */
17
17
  import { ProgressManager, resolveSpecDir } from './progress.js';
18
+ import { runtimeStatePath } from './runtime-paths.js'
18
19
  import { MAIN_FLOW_ORDER, STAGE_LABELS } from './progress/shared.js';
19
20
  import { readFileSync, existsSync } from 'node:fs';
20
21
  import { join } from 'node:path';
@@ -199,7 +200,7 @@ export async function buildHandoff({ cwd, specBase, changeName } = {}) {
199
200
  // 保持不变——SESSION_ID 相同不能当硬续证据)。本命令执行即切割:best-effort 给
200
201
  // stage-session ledger 盖 handoffAt 章,墙据此放行新会话的 execute/verify 首入。
201
202
  try {
202
- const ledgerPath = join(specRoot, '.runtime', `stage-session-ledger-${target}.json`);
203
+ const ledgerPath = runtimeStatePath(join(specRoot, '.runtime'), `stage-session-ledger-${target}.json`);
203
204
  let ledger = null;
204
205
  try { ledger = JSON.parse(readFileSync(ledgerPath, 'utf8')); } catch { /* 无账本(阶段未收口)→ 无墙可放行,零动作 */ }
205
206
  if (ledger && typeof ledger === 'object') {
@@ -61,7 +61,7 @@ const STAGE_HINTS = {
61
61
  '你需要先启动一个任务流程才能修改源码(调用对应的 sillyspec skill):',
62
62
  '',
63
63
  ' 轻量变更/BUG修复(默认快道,skill sillyspec-flow)——--input 引号内换行合法,下例可照抄:',
64
- ' sillyspec flow start --change <YYYY-MM-DD-名> --input "<一句中文概括(首行即变更标题);随后动机与背景',
64
+ ' sillyspec flow start --change <YYYY-MM-DD-名> --input "<一句 10-30 字中文概括(首行即变更标题,硬区间 10-30 必须、建议 ~20 字);随后动机与背景',
65
65
  '',
66
66
  ' 成功标准:',
67
67
  ' - <可验证标准>"',
@@ -80,7 +80,7 @@ const STAGE_HINTS = {
80
80
  'verify': [
81
81
  '当前在 verify(验证)阶段,只做代码审查和测试验证,不修改源码。',
82
82
  '如需修改,请先回到 execute 阶段,或收口后开轻量变更(--input 引号内换行合法,可照抄):',
83
- ' sillyspec flow start --change <YYYY-MM-DD-名> --input "<一句中文概括(首行即变更标题);随后动机与背景',
83
+ ' sillyspec flow start --change <YYYY-MM-DD-名> --input "<一句 10-30 字中文概括(首行即变更标题,硬区间 10-30 必须、建议 ~20 字);随后动机与背景',
84
84
  '',
85
85
  ' 成功标准:',
86
86
  ' - <可验证标准>"',
@@ -88,7 +88,7 @@ const STAGE_HINTS = {
88
88
  'archive': [
89
89
  '当前在 archive(归档)阶段,不修改源码。',
90
90
  '如需修改,请开启新变更(--input 引号内换行合法,可照抄):',
91
- ' sillyspec flow start --change <YYYY-MM-DD-名> --input "<一句中文概括(首行即变更标题);随后动机与背景',
91
+ ' sillyspec flow start --change <YYYY-MM-DD-名> --input "<一句 10-30 字中文概括(首行即变更标题,硬区间 10-30 必须、建议 ~20 字);随后动机与背景',
92
92
  '',
93
93
  ' 成功标准:',
94
94
  ' - <可验证标准>"',
@@ -190,8 +190,8 @@ function getScanDocInfo(filePath) {
190
190
 
191
191
  function readScanGuard(scanDocInfo, projectRoot) {
192
192
  const candidates = [
193
- path.join(scanDocInfo.specRoot, '.runtime', 'scan-guard.json'),
194
- path.join(projectRoot, '.sillyspec', '.runtime', 'scan-guard.json'),
193
+ path.join(scanDocInfo.specRoot, '.runtime', 'state', 'scan-guard.json'),
194
+ path.join(projectRoot, '.sillyspec', '.runtime', 'state', 'scan-guard.json'),
195
195
  ]
196
196
  for (const p of candidates) {
197
197
  if (!existsSync(p)) continue
package/src/index.js CHANGED
@@ -7,6 +7,7 @@
7
7
  * 状态管理通过 sillyspec.db(SQLite)完成,使用 `sillyspec progress` 命令。
8
8
  */
9
9
  import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync, unlinkSync } from 'fs';
10
+ import { runtimeStatePath } from './runtime-paths.js'
10
11
  import { writeAtomicSync } from './fs-atomic.js';
11
12
  import { basename, dirname, extname, join, resolve, isAbsolute, sep, relative } from 'path';
12
13
  import { safeGit, git, gitQuiet } from './git-helper.js';
@@ -173,7 +174,7 @@ SillySpec CLI — 规范驱动开发工具包
173
174
  示例:
174
175
  sillyspec init
175
176
  sillyspec run brainstorm --change 2026-07-03-add-login
176
- sillyspec flow start --change 2026-07-03-my-fix --input "<一句中文概括(首行即变更标题)+动机与背景详述+独立一行『成功标准:』+每行一条『- 可验证标准』>" # 轻量变更(默认快道,2 次调用;变更名须 YYYY-MM-DD-<简短描述> 日期前缀)
177
+ sillyspec flow start --change 2026-07-03-my-fix --input "<一句 10-30 字中文概括(首行即变更标题,硬区间 10-30 必须、建议 ~20 字)+动机与背景详述+独立一行『成功标准:』+每行一条『- 可验证标准』>" # 轻量变更(默认快道,2 次调用;变更名须 YYYY-MM-DD-<简短描述> 日期前缀)
177
178
  sillyspec run verify --done --output "验证通过,测试全绿"
178
179
  sillyspec run archive --done --confirm --output "归档完成"
179
180
  sillyspec run plan --reopen --from-step 2 # 修订 plan,从第 2 步重做
@@ -228,7 +229,7 @@ function refuseRetiredQuickFreshStart(stageArgs) {
228
229
  console.error('❌ quick 通道已退役,不再接受新会话(v3.30.0 起)。')
229
230
  // 可照抄实例(2026-10-05-input-teach-copyable):引号内换行合法,行级 trim 容忍缩进
230
231
  console.error(' 新工作请走轻量变更(--input 引号内换行合法,下例可照抄):')
231
- console.error(' sillyspec flow start --change <YYYY-MM-DD-名> --input "<一句中文概括(首行即变更标题);随后动机与背景')
232
+ console.error(' sillyspec flow start --change <YYYY-MM-DD-名> --input "<一句 10-30 字中文概括(首行即变更标题,硬区间 10-30 必须、建议 ~20 字);随后动机与背景')
232
233
  console.error('')
233
234
  console.error(' 成功标准:')
234
235
  console.error(' - <可验证标准>"')
@@ -323,6 +324,26 @@ async function main() {
323
324
  process.exit(2);
324
325
  }
325
326
 
327
+ // ── 旧布局迁移(2026-10-18 runtime-relayout):per-change 散文件入 state/、可删产物入 temp/。
328
+ // 每次入口跑一遍(幂等:已收敛后 readdir 一轮零写入);fail-open 绝不阻断命令。
329
+ // init 除外——目标仓尚无 .sillyspec 可迁。resolveEffectiveDir 是函数声明(提升后可调)。
330
+ if (filteredArgs[0] !== 'init') {
331
+ try {
332
+ const { migrateRuntimeLayout } = await import('./runtime-paths.js')
333
+ const roots = new Set()
334
+ const direct = join(specDir || join(targetDir, '.sillyspec'), '.runtime')
335
+ roots.add(direct)
336
+ if (!existsSync(direct)) {
337
+ try { roots.add(join(resolveEffectiveDir(targetDir), '.sillyspec', '.runtime')) } catch { /* cwd 无仓 = 无可迁 */ }
338
+ }
339
+ try {
340
+ const po = resolvePlatformOpts(targetDir)
341
+ if (po && po.runtimeRoot) roots.add(po.runtimeRoot)
342
+ } catch { /* 平台指针不可达 = 无平台侧可迁 */ }
343
+ for (const rt of roots) migrateRuntimeLayout(rt)
344
+ } catch { /* 迁移失败不阻断任何命令 */ }
345
+ }
346
+
326
347
  const command = filteredArgs[0];
327
348
  // 支持 sillyspec init /path/to/project 语法:如果第二个参数看起来像路径,当作 targetDir
328
349
  if (command === 'init' && filteredArgs[1] && !filteredArgs[1].startsWith('-')) {
@@ -373,25 +394,32 @@ async function main() {
373
394
  process.exit(1);
374
395
  }
375
396
 
376
- // ── worktree cwd 硬拦(坑 worktree-cwd-silent-split,2026-08-29 用户实证)──
377
- // Bash cwd 残留让 agent 两次误在 worktree 内跑 sillyspec:status 类完全静默、进度写进
378
- // worktree 副本 .sillyspec 与主仓进度库分裂。守卫在命令分发前拦截,--dir 显式指向主仓
379
- // 或 --allow-worktree-cwd 逃生门放行;wt-commit 命令豁免(子代理 workdir=worktree 内合法)。
397
+ // ── worktree cwd 锚定(坑 worktree-cwd-silent-split 硬拦 → 坑 cli-cwd-coupling 拦→导,
398
+ // 2026-10-20-cli-worktree-cwd-anchor)──
399
+ // Bash cwd 残留让 agent 误在 worktree 内跑 sillyspec(生产实证会话 47e2ff1a 三次被拦、每次
400
+ // 1-2 个交互来回)。守卫建议的事(cd 回主仓根重跑)自动做掉:⚠️警告 + 重锚定主仓根执行——
401
+ // 写入恒落主仓(单源不变量延续,worktree 副本零 CLI 写入);刻意以本 worktree 作独立实例跑
402
+ // 的显式路径(--allow-worktree-cwd --spec-dir)在警告中原样保留;wt-commit 豁免不变。
380
403
  if (!args.includes('--allow-worktree-cwd') && command !== 'wt-commit') {
381
404
  const guardDir = args.includes('--dir') ? dir : process.cwd();
382
405
  const wtInfo = detectCwdInsideWorktree(guardDir);
383
406
  if (wtInfo) {
384
- console.error(`\n❌ 当前在隔离 worktree 内(${wtInfo.changeName}):${guardDir}`);
385
- console.error(` 主仓根:${wtInfo.mainRepoRoot}`);
386
- console.error(' SillySpec 进度库只存在于主仓,worktree 内跑会产生分裂进度(坑 worktree-cwd-silent-split)。');
387
- console.error(' 修复:cd 到主仓根后重跑,或用 --dir <主仓根>,或用 --allow-worktree-cwd 强制放行。');
388
- // 一键放行整行(R4-S-Q 实证:agent 试 3 次才拼对组合——worktree 守卫要 --allow-worktree-cwd,
389
- // 而 worktree 嵌套在主仓 .sillyspec/.runtime/ 下又触发 monorepo 多实例拦,需再补 --spec-dir
390
- // 指向 worktree 自己的 .sillyspec,两 flag 缺一不可。给整行可贴命令,不再让调用方试错拼装。)
391
407
  const wtSpecDir = (ancestorSpecDirs(guardDir)[0]) || join(guardDir, '.sillyspec');
392
- console.error(` 一键放行(本 worktree 作独立实例跑,整行照贴):`);
393
- console.error(` sillyspec ${args.join(' ')} --allow-worktree-cwd --spec-dir "${wtSpecDir}"`);
394
- process.exit(2);
408
+ console.warn(`\n⚠️ cwd 在隔离 worktree 内(${wtInfo.changeName}):${guardDir}`);
409
+ console.warn(` 已自动锚定主仓根执行:${wtInfo.mainRepoRoot}(进度库/变更状态以主仓单源为准——坑 worktree-cwd-silent-split / cli-cwd-coupling 拦→导)。`);
410
+ console.warn(` 如确需以本 worktree 作独立实例跑(整行照贴):`);
411
+ console.warn(` sillyspec ${args.join(' ')} --allow-worktree-cwd --spec-dir "${wtSpecDir}"`);
412
+ dir = wtInfo.mainRepoRoot;
413
+ // 评审 P2 清偿:显式 --spec-dir 指进同一 worktree(无逃生 flag)时一并锚定——否则警告
414
+ // 「已锚定主仓根」半真,写入仍可落 worktree 副本 .sillyspec(旧硬拦对该组合是全拦的,
415
+ // 锚定语义必须覆盖同款面);刻意独立实例跑走 --allow-worktree-cwd(跳过整个守卫)。
416
+ if (specDir) {
417
+ const sdInfo = detectCwdInsideWorktree(specDir);
418
+ if (sdInfo && sdInfo.worktreeRoot === wtInfo.worktreeRoot) {
419
+ console.warn(` ⚠️ --spec-dir 指向同一 worktree(${specDir})——已一并锚定主仓 spec 根。`);
420
+ specDir = join(wtInfo.mainRepoRoot, '.sillyspec');
421
+ }
422
+ }
395
423
  }
396
424
  }
397
425
 
@@ -5371,10 +5399,10 @@ SillySpec config — local.yaml 配置键速查
5371
5399
  'sillyspec.db': '进度库 SQLite(stages/steps/changes 表)',
5372
5400
  'sillyspec.db.bak': '进度库备份(sql.js 时代写前快照遗留,node:sqlite 不再写入,仅 _openWithFallback 向后兼容恢复用)',
5373
5401
  'sillyspec.db.schema-version': '进度库 schema 版本标记',
5374
- 'doctor-diagnosis.json': 'doctor --json 结构化诊断快照',
5402
+ 'doctor-diagnosis.json': 'doctor --json 结构化诊断快照(可再生,落 temp/ 子目录)',
5375
5403
  'doctor-dumps': 'doctor --dump-db 取证输出目录',
5376
5404
  'workflow-runs': 'workflow check --save 归档目录',
5377
- 'scan-guard.json': 'scan 覆盖保护记录',
5405
+ 'scan-guard.json': 'scan 覆盖保护记录(2026-10-18 起落 state/ 子目录)',
5378
5406
  'quick-sessions': 'quick 会话记录目录',
5379
5407
  'quick-guard.json': 'quick baseline 守卫(旧位置)',
5380
5408
  'worktrees': 'worktree meta(hooks 侧)',
@@ -5388,6 +5416,8 @@ SillySpec config — local.yaml 配置键速查
5388
5416
  'history': '历史记录目录(init 预建)',
5389
5417
  'logs': '日志目录(init 预建)',
5390
5418
  'templates': '工作流模板目录(init 预建)',
5419
+ 'state': '按 change 命名的派生状态目录(watcher 事件流/账本/冲突标记等,归档时随变更精确回收)',
5420
+ 'temp': '可随时整体删除的临时产物(日志/db 备份/锁残留 tmp——删后自动重建,无状态语义)',
5391
5421
  };
5392
5422
  let entries;
5393
5423
  try {
@@ -5429,7 +5459,7 @@ SillySpec config — local.yaml 配置键速查
5429
5459
  SillySpec pull — 拉取服务器 spec 快照到本地(X2 / FR-07)
5430
5460
 
5431
5461
  用法:
5432
- sillyspec pull --spec [--force]
5462
+ sillyspec pull --spec [--force] [--restore-deleted]
5433
5463
 
5434
5464
  说明:
5435
5465
  从 SillyHub 平台拉取当前工作区的 .sillyspec 整树快照(tar 解压到 specDir,
@@ -5444,6 +5474,10 @@ SillySpec pull — 拉取服务器 spec 快照到本地(X2 / FR-07)
5444
5474
  本命令不自动同步、不在会话中自动刷新;拉取后本地的改动仍需正常推送。
5445
5475
  daemon 模式下任务/会话开始时会按 spec_version 自动取新,无需手动跑本命令。
5446
5476
 
5477
+ 防复活抑制(默认开启):本地已删除、但删除尚未同步到服务器的文件(基线快照有、
5478
+ 盘面无),不会从快照写回本地(防「同步失败窗口内删除的任务卡被服务器旧文件复活」);
5479
+ 确要从快照恢复这类文件用 --restore-deleted(纯快照回放语义)。
5480
+
5447
5481
  拉取进度六表(多机进度同步)请用:sillyspec platform pull [--change <name>]
5448
5482
  `);
5449
5483
  if (pullWantsHelp || !pullWantsSpec) {
@@ -5456,6 +5490,10 @@ SillySpec pull — 拉取服务器 spec 快照到本地(X2 / FR-07)
5456
5490
  }
5457
5491
 
5458
5492
  const pullSpecForce = pullSpecArgs.includes('--force');
5493
+ // 防复活抑制(坑 spec-tree-file-resurrect)的显式恢复通道:默认把「基线有、盘面无」的
5494
+ // 本地已删文件挡在快照回放外(删除 op 未上行成功时不被服务器旧文件复活);
5495
+ // --restore-deleted = 用户显式意志优先,恢复纯快照回放语义。
5496
+ const pullSpecRestoreDeleted = pullSpecArgs.includes('--restore-deleted');
5459
5497
  const syncModule = await import('./sync.js');
5460
5498
  // 未连接明确提示不崩(对齐 platform pull :2289 先例)
5461
5499
  const smForSpecPull = new syncModule.SyncManager(dir);
@@ -5463,10 +5501,13 @@ SillySpec pull — 拉取服务器 spec 快照到本地(X2 / FR-07)
5463
5501
  console.error('❌ 未连接平台,请先 sillyspec platform connect');
5464
5502
  process.exit(1);
5465
5503
  }
5466
- const specR = await syncModule.pullSpecBundle(dir, { force: pullSpecForce, specDir });
5504
+ const specR = await syncModule.pullSpecBundle(dir, { force: pullSpecForce, specDir, restoreDeleted: pullSpecRestoreDeleted });
5467
5505
  if (specR.ok && specR.pulled) {
5468
5506
  console.log(`✅ 已拉取 spec 快照 → ${specR.specDir}${specR.specVersion ? `(平台 spec_version: ${specR.specVersion})` : ''}`);
5469
5507
  console.log(' 快照语义:打包时刻快照非实时,无自动同步;本地后续改动仍需正常推送。');
5508
+ if (Array.isArray(specR.resurrectSkipped) && specR.resurrectSkipped.length > 0) {
5509
+ console.log(' 防复活抑制已生效:本地已删除文件未从快照恢复(基线有、盘面无=本地删除尚未上行成功,抑制防被服务器旧文件复活);确要从快照恢复用 --restore-deleted。');
5510
+ }
5470
5511
  } else if (/非空/.test(specR.reason || '')) {
5471
5512
  console.error(`❌ ${specR.reason}`);
5472
5513
  console.error(' 确认整树替换请加 --force(先删除本地 .sillyspec 整树再解包,进度 DB 等本地文件一并丢失;连接凭据 local.yaml 保留,无需重新 connect)');
@@ -5529,7 +5570,7 @@ SillySpec pull — 拉取服务器 spec 快照到本地(X2 / FR-07)
5529
5570
  }
5530
5571
  if (!tRes.exists) {
5531
5572
  console.error(`📭 ${tChange} 无事件流(未跑过 watcher),无从合成时间线`);
5532
- console.error(` 事件流路径:${join(tRuntimeRoot, `watcher-events-${tChange}.jsonl`)};活跃变更跑任意 flow/run 命令会拉起 watcher`);
5573
+ console.error(` 事件流路径:${runtimeStatePath(tRuntimeRoot, `watcher-events-${tChange}.jsonl`)};活跃变更跑任意 flow/run 命令会拉起 watcher`);
5533
5574
  process.exit(2);
5534
5575
  }
5535
5576
  const { changeDir, tasksMd, tickLog } = loadChangeTasks(tSpecBase, tChange);
package/src/init.js CHANGED
@@ -85,18 +85,8 @@ const TOOL_LABELS = {
85
85
  cursor: 'Cursor',
86
86
  openclaw: 'OpenClaw',
87
87
  codex: 'OpenAI Codex (通过 AGENTS.md)',
88
- gemini: 'Gemini CLI (通过 GEMINI.md)',
89
- opencode: 'OpenCode (通过 INSTRUCTIONS.md)',
90
- };
91
-
92
- // 指令文件工具(gemini/opencode)。codex/claude/zcode 共用 AGENTS.md(跨工具通用标准内容源);
93
- // gemini/opencode 写各自指令文件,内容与 AGENTS.md 同源同全文(改 @AGENTS.md 指针需先验证
94
- // 两家对 @ 导入语法的支持,留待后续变更)。
95
- const INSTRUCTION_TOOLS = ['gemini', 'opencode'];
96
-
97
- const INSTRUCTION_FILE_MAP = {
98
- gemini: 'GEMINI.md',
99
- opencode: 'INSTRUCTIONS.md',
88
+ gemini: 'Gemini CLI',
89
+ opencode: 'OpenCode',
100
90
  };
101
91
 
102
92
  // ── 注入指令文件(全量方案,2026-10-10-init-full-injection:完整模板是唯一注入源)──
@@ -145,7 +135,7 @@ function stripLegacySmallBlock(content) {
145
135
 
146
136
  /**
147
137
  * 向指引文件注入完整模板(版本感知幂等,三态四分支 + 旧标记迁移)。
148
- * AGENTS.md / GEMINI.md / INSTRUCTIONS.md 共用;完整模板(templates/agents-instruction.md)
138
+ * AGENTS.md 专用(GEMINI.md/INSTRUCTIONS.md 专属注入面 2026-10-19 下线);完整模板(templates/agents-instruction.md)
149
139
  * 是唯一注入源。取代 design: 2026-08-02-init-claude-md 的 CLAUDE.md 单文件方案与
150
140
  * v≤3.32.3 的追加态小段方案(其 D-004 预留的「marker 方案迁移」即彼方案)。
151
141
  * - 不存在:写完整模板 + 顶部版本注释
@@ -210,12 +200,6 @@ export function injectAgentsInstructions(projectDir) {
210
200
  injectFullInstructions(join(projectDir, 'AGENTS.md'));
211
201
  }
212
202
 
213
- export function injectInstructions(tool, projectDir) {
214
- const fileName = INSTRUCTION_FILE_MAP[tool];
215
- if (!fileName) return;
216
- injectFullInstructions(join(projectDir, fileName));
217
- }
218
-
219
203
  /**
220
204
  * 为 Claude Code 写 CLAUDE.md 指针(@AGENTS.md 导入,薄文件)。
221
205
  * - 不存在:写指针文件(版本头注释 + @AGENTS.md)
@@ -438,17 +422,10 @@ async function doInstall(projectDir, tools, subprojects = [], specDir = null, op
438
422
  }
439
423
  }
440
424
 
441
- // 注入指令文件(gemini/opencode:与 AGENTS.md 同源同全文,共用全量注入器)
442
- for (let i = 0; i < tools.length; i++) {
443
- const toolName = tools[i];
444
- if (INSTRUCTION_TOOLS.includes(toolName)) {
445
- injectInstructions(toolName, projectDir);
446
- }
447
- }
448
-
449
- // 注入 AGENTS.md 完整指引(claude/codex/zcode 共用:版本感知幂等三态四分支 + 旧 ## SillySpec 小段迁移;
450
- // zcode 2026-09-21-flow-command-cards FR-05 入面——AGENTS.md 是跨工具通用标准内容源)
451
- if (tools.includes('claude') || tools.includes('codex') || tools.includes('zcode')) {
425
+ // 注入 AGENTS.md 完整指引(版本感知幂等三态四分支 + 旧 ## SillySpec 小段迁移)。
426
+ // 2026-10-19 起全工具统一落 AGENTS.md:gemini/opencode 不再产 GEMINI.md/INSTRUCTIONS.md
427
+ // (OpenCode 原生读 AGENTS.md;Gemini CLI 现默认 GEMINI.md,需自行引用 AGENTS.md,边界见 file-lifecycle)
428
+ if (tools.some((t) => ['claude', 'codex', 'zcode', 'gemini', 'opencode'].includes(t))) {
452
429
  injectAgentsInstructions(projectDir);
453
430
  }
454
431
 
@@ -12,12 +12,13 @@
12
12
  */
13
13
 
14
14
  import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'fs'
15
+ import { runtimeStatePath } from './runtime-paths.js'
15
16
  import { join } from 'path'
16
17
 
17
18
  const HITS_FILENAME = 'knowledge-hits.jsonl'
18
19
 
19
20
  function hitsFilePath(runtimeDir) {
20
- return join(runtimeDir, HITS_FILENAME)
21
+ return runtimeStatePath(runtimeDir, HITS_FILENAME)
21
22
  }
22
23
 
23
24
  /**
@@ -35,6 +35,7 @@
35
35
  * 404 另有进程级死信短路(端点死信不再空转探测)。
36
36
  */
37
37
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs'
38
+ import { runtimeStatePath } from './runtime-paths.js'
38
39
  import { join, dirname } from 'path'
39
40
  import { readPlatformConfig } from './sync.js'
40
41
  import { matchByRouting, fallbackByQueryShingles, parseDecisionEntries } from './knowledge-match.js'
@@ -49,7 +50,7 @@ const CAPABILITY_RETRY_MS = 60 * 60 * 1000
49
50
  // 机器态的标准落点(knowledge-hits 同款)。写盘全 fail-soft;按平台 URL 匹配(换平台即失效)。
50
51
 
51
52
  function capabilityCachePath(cwd) {
52
- return join(cwd, '.sillyspec', '.runtime', 'vector-capability.json')
53
+ return runtimeStatePath(join(cwd, '.sillyspec', '.runtime'), 'vector-capability.json')
53
54
  }
54
55
 
55
56
  function readCapabilityCache(cwd) {
@@ -1,7 +1,9 @@
1
1
  // W6 Step9a: Revision v1 状态一致性检查 + 修复 + --force 审计日志。
2
2
  // 从 src/progress.js 单体 ProgressManager 抽出。持有 pm 引用(构造注入),调 pm.read / pm._write /
3
3
  // pm._ensureRuntimeDir / pm._runtimePath(persistence-core 留 facade 本体)。
4
- import { appendFileSync, existsSync, readFileSync, readdirSync } from 'fs';
4
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync } from 'fs';
5
+ import { dirname } from 'path';
6
+ import { RUNTIME_TEMP_DIRNAME } from '../runtime-paths.js'
5
7
  import { join, resolve } from 'path';
6
8
  import { DB } from '../db.js';
7
9
  import { openDatabase } from '../db-engine.js';
@@ -122,8 +124,9 @@ export class ConsistencyDoctor {
122
124
  _appendAuditLog(cwd, entry) {
123
125
  try {
124
126
  this.pm._ensureRuntimeDir(cwd);
125
- const auditPath = this.pm._runtimePath(cwd, 'audit.log');
127
+ const auditPath = this.pm._runtimePath(cwd, RUNTIME_TEMP_DIRNAME, 'audit.log');
126
128
  const line = JSON.stringify({ at: new Date().toISOString(), ...entry });
129
+ try { mkdirSync(dirname(auditPath), { recursive: true }); } catch { /* fail-open */ }
127
130
  appendFileSync(auditPath, line + '\n');
128
131
  } catch (e) {
129
132
  console.warn(`⚠️ 审计日志写入失败: ${e.message}`);
@@ -361,8 +361,12 @@ export class StageMachine {
361
361
  /** 未决同步冲突列表(overview 数据源;与 sync.js listConflictFiles 同前缀同字段,fs-only) */
362
362
  _listPendingConflicts(specDir) {
363
363
  const runtimeDir = join(specDir, '.runtime');
364
+ // 2026-10-18 布局分层:冲突文件落 state/;根目录扫描保留旧布局兜底
364
365
  let files = [];
365
- try { files = readdirSync(runtimeDir); } catch { return []; }
366
+ for (const dir of [join(runtimeDir, 'state'), runtimeDir]) {
367
+ try { files.push(...readdirSync(dir)); } catch { /* 可选层缺失跳过 */ }
368
+ }
369
+ const fileDir = (f) => (existsSync(join(runtimeDir, 'state', f)) ? join(runtimeDir, 'state') : runtimeDir)
366
370
  const conflicts = [];
367
371
  for (const f of files) {
368
372
  const isProgress = f.startsWith('sync-conflict-');
@@ -371,7 +375,7 @@ export class StageMachine {
371
375
  let createdAt = null;
372
376
  let kind = null;
373
377
  try {
374
- const cf = JSON.parse(readFileSync(join(runtimeDir, f), 'utf8'));
378
+ const cf = JSON.parse(readFileSync(join(fileDir(f), f), 'utf8'));
375
379
  change = cf.change || change;
376
380
  createdAt = cf.created_at || null;
377
381
  kind = typeof cf.kind === 'string' ? cf.kind : null;
package/src/progress.js CHANGED
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, unlinkSync, appendFileSync, copyFileSync, readdirSync, statSync, realpathSync } from 'fs';
14
+ import { RUNTIME_TEMP_DIRNAME, runtimeTempPath } from './runtime-paths.js'
14
15
  import { join, basename, dirname, resolve, sep } from 'path';
15
16
  import { tmpdir, hostname } from 'os';
16
17
  import { writeAtomicSync } from './fs-atomic.js';
@@ -122,7 +123,7 @@ export function resolveSessionIdentity({ flagSession = null, quickChangeName = n
122
123
  try {
123
124
  const markerDir = join(cwd, SPEC_DIR_NAME, RUNTIME_SUBDIR);
124
125
  mkdirSync(markerDir, { recursive: true });
125
- const markerPath = join(markerDir, ANON_SESSION_WARN_MARKER);
126
+ const markerPath = runtimeTempPath(markerDir, ANON_SESSION_WARN_MARKER);
126
127
  const now = Date.now();
127
128
  try {
128
129
  const m = JSON.parse(readFileSync(markerPath, 'utf8'));
@@ -348,7 +349,7 @@ export class ProgressManager {
348
349
  const runtimeDir = this._runtimePath(cwd);
349
350
  if (!existsSync(runtimeDir)) {
350
351
  mkdirSync(runtimeDir, { recursive: true });
351
- for (const d of ['artifacts', 'history', 'logs', 'templates']) {
352
+ for (const d of ['artifacts', 'history', 'logs', 'templates', 'state', 'temp']) {
352
353
  mkdirSync(join(runtimeDir, d), { recursive: true });
353
354
  }
354
355
  }
@@ -746,7 +747,8 @@ export class ProgressManager {
746
747
  throw new Error(`本地进度库不存在,无法 import:${dbPath}`);
747
748
  }
748
749
  const bakTs = new Date().toISOString().replace(/[:.]/g, '-');
749
- const bakPath = this._runtimePath(cwd, `sillyspec.db.pre-import-${bakTs}.bak`);
750
+ const bakPath = this._runtimePath(cwd, RUNTIME_TEMP_DIRNAME, `sillyspec.db.pre-import-${bakTs}.bak`);
751
+ try { mkdirSync(dirname(bakPath), { recursive: true }); } catch { /* import 主流程 fail-open */ }
750
752
  // 体检 BUG-18:WAL 模式下最近已提交事务可能仍在 -wal 侧车,直接 copy 主库文件会拿到
751
753
  // 缺尾部提交的快照(恢复时静默回退进度)。先尽力 checkpoint(TRUNCATE) 把 WAL 合并回主库;
752
754
  // 他进程持连接致 checkpoint 不完全时,把 -wal 侧车一并备份,恢复侧才有完整提交
@@ -880,17 +882,25 @@ export class ProgressManager {
880
882
  let keep = Number(process.env.SILLYSPEC_PREIMPORT_BAK_KEEP);
881
883
  if (!Number.isInteger(keep) || keep < 1) keep = PRE_IMPORT_BAK_KEEP_DEFAULT;
882
884
 
883
- const runtimeDir = this._runtimePath(cwd);
884
- const baks = readdirSync(runtimeDir).filter(f => PRE_IMPORT_BAK_RE.test(f)).sort();
885
+ // 快照 2026-10-18 起落 temp/;根目录扫描保留旧布局兜底(迁移幂等收敛后清零)。
886
+ // 契约:根 runtime 目录缺失仍如实抛 ENOENT(fail-loud 不静默假成功);temp/ 是可选
887
+ // 层(迁移前不存在),缺失按空集处理。
888
+ const rootDir = this._runtimePath(cwd)
889
+ const scanDirs = [this._runtimePath(cwd, RUNTIME_TEMP_DIRNAME), rootDir]
890
+ const baks = [...new Set([
891
+ ...(() => { try { return readdirSync(scanDirs[0]) } catch { return [] } })(),
892
+ ...readdirSync(rootDir),
893
+ ])].filter(f => PRE_IMPORT_BAK_RE.test(f)).sort();
885
894
  const keepName = keepPath ? basename(keepPath) : null;
886
895
  const doomed = baks.slice(0, Math.max(0, baks.length - keep)).filter(f => f !== keepName);
887
896
 
888
897
  let removed = 0;
889
898
  for (const f of doomed) {
890
899
  // 单份删除失败(他进程持句柄 / 权限)不连坐其余份:跳过即可,下次 import 再收。
891
- try { unlinkSync(join(runtimeDir, f)); } catch { continue; }
900
+ const fDir = scanDirs.find(d => { try { return existsSync(join(d, f)) } catch { return false } }) || scanDirs[0]
901
+ try { unlinkSync(join(fDir, f)); } catch { continue; }
892
902
  removed++;
893
- const wal = join(runtimeDir, `${f}-wal`);
903
+ const wal = join(fDir, `${f}-wal`);
894
904
  if (existsSync(wal)) {
895
905
  try { unlinkSync(wal); } catch { /* 侧车残留无害:不参与恢复链,下次裁剪再收 */ }
896
906
  }
@@ -937,7 +947,8 @@ export class ProgressManager {
937
947
  _maybeSnapshotBak(cwd) {
938
948
  try {
939
949
  const dbPath = this._runtimePath(cwd, 'sillyspec.db');
940
- const bakPath = dbPath + '.bak';
950
+ // 2026-10-18 布局分层:可删备份归 temp/(db.js _openWithFallback 双路径回读)
951
+ const bakPath = runtimeTempPath(dirname(dbPath), 'sillyspec.db.bak');
941
952
  const st = existsSync(bakPath) ? statSync(bakPath) : null;
942
953
  if (st && Date.now() - st.mtimeMs < ProgressManager.SNAPSHOT_INTERVAL_MS) return;
943
954
  const tmpPath = bakPath + '.tmp';