sillyspec 3.17.9 → 3.17.11
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 +10 -20
package/package.json
CHANGED
package/src/run.js
CHANGED
|
@@ -95,10 +95,6 @@ function loadModuleContextIndex(specBase, projectName) {
|
|
|
95
95
|
* @param {string} projectName - 项目名
|
|
96
96
|
* @returns {string} 上下文注入文本,空字符串表示无匹配模块
|
|
97
97
|
*/
|
|
98
|
-
const MAX_MODULE_CONTEXT_CHARS = 4096 // 上下文注入硬限制(字节),防止 prompt 膨胀
|
|
99
|
-
const MAX_MODULES_PER_INJECTION = 3 // 最多注入的模块数
|
|
100
|
-
const MAX_FILES_PER_MODULE = 8 // 每个模块最多展示的文件数
|
|
101
|
-
|
|
102
98
|
function buildModuleContextInjection(taskDescription, moduleIndex, specBase, projectName) {
|
|
103
99
|
if (!moduleIndex || !taskDescription) return ''
|
|
104
100
|
const { existsSync } = require('fs')
|
|
@@ -117,7 +113,7 @@ function buildModuleContextInjection(taskDescription, moduleIndex, specBase, pro
|
|
|
117
113
|
// core_files 路径匹配
|
|
118
114
|
const coreFiles = data.paths || data.core_files || []
|
|
119
115
|
for (const p of coreFiles) {
|
|
120
|
-
if (taskLower.includes(p.toLowerCase())) { score += 1; matchReasons.push(`file:${p}`); break }
|
|
116
|
+
if (taskLower.includes(p.toLowerCase())) { score += 1; matchReasons.push(`file:${p}`); break }
|
|
121
117
|
}
|
|
122
118
|
if (score > 0) matched.push({ moduleId, data, score, matchReasons })
|
|
123
119
|
}
|
|
@@ -125,19 +121,18 @@ function buildModuleContextInjection(taskDescription, moduleIndex, specBase, pro
|
|
|
125
121
|
if (matched.length === 0) return ''
|
|
126
122
|
|
|
127
123
|
matched.sort((a, b) => b.score - a.score)
|
|
128
|
-
const top = matched.slice(0, MAX_MODULES_PER_INJECTION)
|
|
129
124
|
|
|
130
125
|
let injection = '\n### 📦 模块上下文(按相关性排序,来自 Module Context Index)\n\n'
|
|
131
126
|
injection += `> 以下模块上下文由 scan 阶段生成的 _module-map.yaml 自动匹配。\n`
|
|
132
|
-
injection += `> Matched modules: ${
|
|
133
|
-
injection += `> Reasons: ${
|
|
127
|
+
injection += `> Matched modules: ${matched.map(m => m.moduleId).join(', ')}\n`
|
|
128
|
+
injection += `> Reasons: ${matched.map(m => m.matchReasons.join(', ')).join('; ')}\n\n`
|
|
134
129
|
|
|
135
|
-
for (const { moduleId, data } of
|
|
130
|
+
for (const { moduleId, data } of matched) {
|
|
136
131
|
injection += `#### ${moduleId}\n`
|
|
137
132
|
if (data.role) injection += `- **职责**: ${String(data.role).slice(0, 100)}\n`
|
|
138
133
|
const riskLevel = data.risk_level || 'medium'
|
|
139
134
|
injection += `- **风险等级**: ${riskLevel}\n`
|
|
140
|
-
const coreFiles =
|
|
135
|
+
const coreFiles = data.paths || data.core_files || []
|
|
141
136
|
if (coreFiles.length > 0) injection += `- **核心文件**: ${coreFiles.join(', ')}\n`
|
|
142
137
|
if (data.doc) {
|
|
143
138
|
const docPath = join(specBase, 'docs', projectName, data.doc)
|
|
@@ -145,16 +140,10 @@ function buildModuleContextInjection(taskDescription, moduleIndex, specBase, pro
|
|
|
145
140
|
injection += `- **模块文档**: ${data.doc}${exists ? ' ✅' : ' ⚠️ 不存在'}\n`
|
|
146
141
|
}
|
|
147
142
|
const deps = data.depends_on || []
|
|
148
|
-
if (deps.length > 0) injection += `- **依赖**: ${deps.
|
|
143
|
+
if (deps.length > 0) injection += `- **依赖**: ${deps.join(', ')}\n`
|
|
149
144
|
const usedBy = data.used_by || []
|
|
150
|
-
if (usedBy.length > 0) injection += `- **被引用**: ${usedBy.
|
|
145
|
+
if (usedBy.length > 0) injection += `- **被引用**: ${usedBy.join(', ')}\n`
|
|
151
146
|
injection += '\n'
|
|
152
|
-
|
|
153
|
-
// 长度硬限制:超过阈值截断
|
|
154
|
-
if (injection.length > MAX_MODULE_CONTEXT_CHARS) {
|
|
155
|
-
injection += `<!-- Module context truncated: exceeded ${MAX_MODULE_CONTEXT_CHARS} chars -->\n`
|
|
156
|
-
break
|
|
157
|
-
}
|
|
158
147
|
}
|
|
159
148
|
|
|
160
149
|
return injection
|
|
@@ -643,11 +632,12 @@ async function outputStep(stageName, stepIndex, steps, cwd, changeName, dbProjec
|
|
|
643
632
|
|
|
644
633
|
// 注入模块上下文(brainstorm/plan/execute 阶段,基于 Module Context Index)
|
|
645
634
|
if (['brainstorm', 'plan', 'execute'].includes(stageName) && projectName) {
|
|
646
|
-
const
|
|
635
|
+
const effectiveSpecBase = platformOpts?.specRoot || join(cwd, '.sillyspec')
|
|
636
|
+
const moduleIndex = loadModuleContextIndex(effectiveSpecBase, projectName)
|
|
647
637
|
if (moduleIndex && Object.keys(moduleIndex).length > 0) {
|
|
648
638
|
// 尝试从 step prompt / changeName 匹配模块
|
|
649
639
|
const taskDesc = step.prompt || changeName || ''
|
|
650
|
-
const injection = buildModuleContextInjection(taskDesc, moduleIndex,
|
|
640
|
+
const injection = buildModuleContextInjection(taskDesc, moduleIndex, effectiveSpecBase, projectName)
|
|
651
641
|
if (injection) {
|
|
652
642
|
promptText = injection + '\n' + promptText
|
|
653
643
|
}
|