sillyspec 3.19.1 → 3.19.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/.npmrc-tmp ADDED
@@ -0,0 +1 @@
1
+ //registry.npmjs.org/:_authToken=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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sillyspec",
3
- "version": "3.19.1",
3
+ "version": "3.19.2",
4
4
  "description": "SillySpec CLI — 流程状态机,让 AI 严格按步骤来",
5
5
  "icon": "logo.jpg",
6
6
  "homepage": "https://sillyspec.ppdmq.top/",
@@ -143,14 +143,13 @@ function warnMissingIds(warnings, ids, targetContent, targetName, sourceName) {
143
143
  */
144
144
  function validateScanOutputs(cwd, changeName, context = {}) {
145
145
  const { projectName, specRoot } = context
146
- // 平台模式使用 specRoot,本地模式使用 cwd
147
- const base = specRoot || cwd
148
- // 如果 base 已经是 specDir(有 docs/ 子目录),直接用 base/docs/
149
- // 否则按传统模式拼接 .sillyspec/docs/
150
- const isSpecDir = existsSync(join(base, 'docs'))
146
+ // 平台模式:specRoot 直接是规范目录(含 docs/)
147
+ // 本地模式:规范目录是 cwd/.sillyspec
148
+ // 不用 isSpecDir 启发式猜测——很多项目根目录有自己的 docs/,会误判
149
+ const specBase = specRoot || join(cwd, '.sillyspec')
151
150
  const docsRoot = projectName
152
- ? join(base, isSpecDir ? 'docs' : '.sillyspec/docs', projectName, 'scan')
153
- : join(base, isSpecDir ? 'docs' : '.sillyspec/docs', 'scan')
151
+ ? join(specBase, 'docs', projectName, 'scan')
152
+ : join(specBase, 'docs', 'scan')
154
153
 
155
154
  const requiredDocs = [
156
155
  'ARCHITECTURE.md',
@@ -173,8 +172,8 @@ function validateScanOutputs(cwd, changeName, context = {}) {
173
172
 
174
173
  // 检查 modules 目录
175
174
  const modulesRoot = projectName
176
- ? join(base, isSpecDir ? 'docs' : '.sillyspec/docs', projectName, 'modules')
177
- : join(base, isSpecDir ? 'docs' : '.sillyspec/docs', 'modules')
175
+ ? join(specBase, 'docs', projectName, 'modules')
176
+ : join(specBase, 'docs', 'modules')
178
177
  if (!existsSync(modulesRoot)) {
179
178
  warnings.push('modules 目录不存在')
180
179
  } else {
package/src/workflow.js CHANGED
@@ -154,7 +154,12 @@ function checkOutput(outputDef, projectName, cwd, specBase) {
154
154
  // 未传时回退 join(cwd, '.sillyspec'),等价于旧行为 resolve(cwd, '.sillyspec/...')
155
155
  const effectiveBase = specBase || join(cwd, '.sillyspec')
156
156
  // 将 <project> 替换为实际项目名
157
- const rawPath = (outputDef.path || '').replace(/<project>/g, projectName)
157
+ let rawPath = (outputDef.path || '').replace(/<project>/g, projectName)
158
+ // 旧版兼容:如果 path 以 .sillyspec/ 开头(相对路径),strip 前缀避免双拼接
159
+ // 新版 yaml 用 {SPEC_ROOT} 已在 runPostCheck 中替换为绝对路径,不会走这里
160
+ if (rawPath.startsWith('.sillyspec/')) {
161
+ rawPath = rawPath.slice('.sillyspec/'.length)
162
+ }
158
163
  const fullPath = resolve(effectiveBase, rawPath)
159
164
  const checks = outputDef.checks || []
160
165
  const results = []
@@ -204,7 +209,7 @@ function checkOutput(outputDef, projectName, cwd, specBase) {
204
209
  const patterns = check.patterns || ['待补充', 'TODO', 'TBD', '未分析', '根据项目情况', '根据实际情况', '按需填写']
205
210
  // 只匹配独立成行的占位文本,不匹配行内引用
206
211
  const lineMatches = patterns.filter(p => {
207
- const regex = new RegExp(`^\s*[-*]?\s*${p}\s*$`, 'm')
212
+ const regex = new RegExp(`^\\s*[-*]?\\s*${p}\\s*$`, 'm')
208
213
  return regex.test(content)
209
214
  })
210
215
  results.push({ passed: lineMatches.length === 0, check: 'no_placeholder', detail: lineMatches.length > 0 ? `包含占位文本: ${lineMatches.map(m => `"${m}"`).join(', ')} — ${rawPath}` : '' })
@@ -246,13 +251,20 @@ function checkOutput(outputDef, projectName, cwd, specBase) {
246
251
  */
247
252
  export function runPostCheck(wf, cwd, projectName, placeholders = {}, specBase) {
248
253
  let resolved = replaceProjectPlaceholder(wf, projectName)
249
- if (Object.keys(placeholders).length > 0) {
250
- let json = JSON.stringify(resolved)
251
- for (const [key, value] of Object.entries(placeholders)) {
252
- json = json.replace(new RegExp(`<${key}>`, 'g'), value)
253
- }
254
- resolved = JSON.parse(json)
254
+
255
+ // 自动注入 {SPEC_ROOT} 占位符(yaml 模板用 {SPEC_ROOT} 表示规范根目录)
256
+ // effectiveBase _checkWorkflow 内部一致:specBase || join(cwd, '.sillyspec')
257
+ const effectiveBase = specBase || join(cwd, '.sillyspec')
258
+ const allPlaceholders = { SPEC_ROOT: effectiveBase, ...placeholders }
259
+
260
+ let json = JSON.stringify(resolved)
261
+ for (const [key, value] of Object.entries(allPlaceholders)) {
262
+ // 支持 {key} 和 <key> 两种占位符语法
263
+ json = json.replace(new RegExp(`\{${key}\}`, 'g'), value)
264
+ json = json.replace(new RegExp(`<${key}>`, 'g'), value)
255
265
  }
266
+ resolved = JSON.parse(json)
267
+
256
268
  return _checkWorkflow(resolved, cwd, projectName, specBase)
257
269
  }
258
270
 
@@ -261,6 +273,7 @@ function _checkWorkflow(wf, cwd, projectName, specBase) {
261
273
  const workflowName = wf.name || 'unknown'
262
274
  const specVersion = wf.spec_version || wf.version || 0
263
275
  const workflowChecks = wf.checks?.workflow_level || []
276
+ const roleLevelChecks = wf.checks?.role_level || []
264
277
  const roles = []
265
278
  const failures = []
266
279
  const workflowCheckResults = []
@@ -274,7 +287,11 @@ function _checkWorkflow(wf, cwd, projectName, specBase) {
274
287
 
275
288
  for (const outputDef of outputDefs) {
276
289
  const rawPath = (outputDef.path || '').replace(/<project>/g, projectName)
277
- const checkResults = checkOutput(outputDef, projectName, cwd, effectiveBase)
290
+ // role_level checks: 全局施加到每个 output(与 output 自身的 checks 合并)
291
+ const mergedOutputDef = roleLevelChecks.length > 0
292
+ ? { ...outputDef, checks: [...(outputDef.checks || []), ...roleLevelChecks] }
293
+ : outputDef
294
+ const checkResults = checkOutput(mergedOutputDef, projectName, cwd, effectiveBase)
278
295
  const outputPassed = checkResults.every(c => c.passed)
279
296
 
280
297
  outputs.push({
@@ -355,8 +372,97 @@ function _checkWorkflow(wf, cwd, projectName, specBase) {
355
372
  }
356
373
  break
357
374
  }
375
+ case 'file_exists': {
376
+ // workflow_level file_exists: check.path 可以是目录或文件,相对 effectiveBase
377
+ let checkPath = check.path || ''
378
+ // 兼容 .sillyspec/ 前缀
379
+ if (checkPath.startsWith('.sillyspec/')) checkPath = checkPath.slice('.sillyspec/'.length)
380
+ // 替换 <change-name> 占位符(archive-impact 用)
381
+ checkPath = checkPath.replace(/<change-name>/g, wf._changeName || '')
382
+ const fullPath = join(effectiveBase, checkPath)
383
+ if (!existsSync(fullPath)) {
384
+ const detail = `文件不存在: ${checkPath}`
385
+ workflowCheckResults.push({ type: 'file_exists', status: 'fail', detail })
386
+ failures.push({ level: 'workflow', check: 'file_exists', message: detail })
387
+ } else {
388
+ workflowCheckResults.push({ type: 'file_exists', status: 'pass', detail: '' })
389
+ }
390
+ break
391
+ }
392
+ case 'min_lines': {
393
+ let checkPath = check.path || ''
394
+ if (checkPath.startsWith('.sillyspec/')) checkPath = checkPath.slice('.sillyspec/'.length)
395
+ checkPath = checkPath.replace(/<change-name>/g, wf._changeName || '')
396
+ const fullPath = join(effectiveBase, checkPath)
397
+ if (existsSync(fullPath)) {
398
+ const content = readFileSync(fullPath, 'utf8')
399
+ const lines = content.split('\n').length
400
+ const min = check.min || 1
401
+ if (lines < min) {
402
+ const detail = `文件只有 ${lines} 行,要求至少 ${min} 行: ${checkPath}`
403
+ workflowCheckResults.push({ type: 'min_lines', status: 'fail', detail })
404
+ failures.push({ level: 'workflow', check: 'min_lines', message: detail })
405
+ } else {
406
+ workflowCheckResults.push({ type: 'min_lines', status: 'pass', detail: '' })
407
+ }
408
+ } else {
409
+ const detail = `文件不存在: ${checkPath}`
410
+ workflowCheckResults.push({ type: 'min_lines', status: 'fail', detail })
411
+ failures.push({ level: 'workflow', check: 'min_lines', message: detail })
412
+ }
413
+ break
414
+ }
415
+ case 'contains_sections': {
416
+ let checkPath = check.path || ''
417
+ if (checkPath.startsWith('.sillyspec/')) checkPath = checkPath.slice('.sillyspec/'.length)
418
+ checkPath = checkPath.replace(/<change-name>/g, wf._changeName || '')
419
+ const fullPath = join(effectiveBase, checkPath)
420
+ if (existsSync(fullPath)) {
421
+ const content = readFileSync(fullPath, 'utf8')
422
+ const sections = check.sections || []
423
+ const missing = sections.filter(s => !content.includes(`## ${s}`))
424
+ if (missing.length > 0) {
425
+ const detail = `缺少章节: ${missing.join(', ')} — ${checkPath}`
426
+ workflowCheckResults.push({ type: 'contains_sections', status: 'fail', detail })
427
+ failures.push({ level: 'workflow', check: 'contains_sections', message: detail })
428
+ } else {
429
+ workflowCheckResults.push({ type: 'contains_sections', status: 'pass', detail: '' })
430
+ }
431
+ } else {
432
+ const detail = `文件不存在: ${checkPath}`
433
+ workflowCheckResults.push({ type: 'contains_sections', status: 'fail', detail })
434
+ failures.push({ level: 'workflow', check: 'contains_sections', message: detail })
435
+ }
436
+ break
437
+ }
438
+ case 'no_placeholder': {
439
+ let checkPath = check.path || ''
440
+ if (checkPath.startsWith('.sillyspec/')) checkPath = checkPath.slice('.sillyspec/'.length)
441
+ checkPath = checkPath.replace(/<change-name>/g, wf._changeName || '')
442
+ const fullPath = join(effectiveBase, checkPath)
443
+ if (existsSync(fullPath)) {
444
+ const content = readFileSync(fullPath, 'utf8')
445
+ const patterns = check.patterns || ['待补充', 'TODO', 'TBD', '未分析', '根据项目情况', '根据实际情况', '按需填写']
446
+ const lineMatches = patterns.filter(p => {
447
+ const regex = new RegExp(`^\\s*[-*]?\\s*${p}\\s*$`, 'm')
448
+ return regex.test(content)
449
+ })
450
+ if (lineMatches.length > 0) {
451
+ const detail = `包含占位文本: ${lineMatches.map(m => `"${m}"`).join(', ')} — ${checkPath}`
452
+ workflowCheckResults.push({ type: 'no_placeholder', status: 'fail', detail })
453
+ failures.push({ level: 'workflow', check: 'no_placeholder', message: detail })
454
+ } else {
455
+ workflowCheckResults.push({ type: 'no_placeholder', status: 'pass', detail: '' })
456
+ }
457
+ } else {
458
+ const detail = `文件不存在: ${checkPath}`
459
+ workflowCheckResults.push({ type: 'no_placeholder', status: 'fail', detail })
460
+ failures.push({ level: 'workflow', check: 'no_placeholder', message: detail })
461
+ }
462
+ break
463
+ }
358
464
  default:
359
- workflowCheckResults.push({ type: check.type, status: 'pass', detail: '' })
465
+ workflowCheckResults.push({ type: check.type, status: 'pass', detail: `未知检查类型,跳过: ${check.type}` })
360
466
  }
361
467
  }
362
468
 
@@ -108,14 +108,15 @@ const specRoot = mkdtempSync(join(tmpdir(), 'sillyspec-test-'))
108
108
  const sourceRoot = mkdtempSync(join(tmpdir(), 'sillyspec-source-'))
109
109
  const projectName = 'myaaa'
110
110
 
111
- // specRoot 下创建正确的 scan 文档
112
- const specDocsDir = join(specRoot, '.sillyspec', 'docs', projectName, 'scan')
111
+ // specRoot 在实际代码中等价于 .sillyspec 目录本身(run.js: join(specRoot, 'docs', ...))
112
+ // 所以 scan 文档路径为 specRoot/docs/<project>/scan/,不需要额外的 .sillyspec/ 前缀
113
+ const specDocsDir = join(specRoot, 'docs', projectName, 'scan')
113
114
  mkdirSync(specDocsDir, { recursive: true })
114
115
  for (const doc of ['ARCHITECTURE.md', 'CONVENTIONS.md', 'STRUCTURE.md', 'INTEGRATIONS.md', 'TESTING.md', 'CONCERNS.md', 'PROJECT.md']) {
115
116
  writeFileSync(join(specDocsDir, doc), '# ' + doc)
116
117
  }
117
- mkdirSync(join(specRoot, '.sillyspec', 'docs', projectName, 'modules'), { recursive: true })
118
- writeFileSync(join(specRoot, '.sillyspec', 'docs', projectName, 'modules', 'app.md'), '# app')
118
+ mkdirSync(join(specRoot, 'docs', projectName, 'modules'), { recursive: true })
119
+ writeFileSync(join(specRoot, 'docs', projectName, 'modules', 'app.md'), '# app')
119
120
 
120
121
  // 测试1:使用 specRoot 校验成功
121
122
  const specResult = runValidators('scan', sourceRoot, 'test', { projectName, specRoot })