@thincoder/core 0.11.3 → 0.11.5

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 (183) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/advisor/compaction.mjs +40 -17
  3. package/advisor/loop.mjs +14 -6
  4. package/advisor/notice.mjs +1 -1
  5. package/advisor/timeline.mjs +4 -4
  6. package/agent/completion.mjs +19 -0
  7. package/agent/dispatch-gates.mjs +2 -0
  8. package/agent/dispatch.mjs +2 -2
  9. package/agent/family-tools.mjs +13 -9
  10. package/agent/helpers.mjs +10 -6
  11. package/agent/planning-step.mjs +453 -0
  12. package/agent/post-turn.mjs +70 -2
  13. package/agent/run-stages.mjs +22 -50
  14. package/agent/run-start.mjs +17 -0
  15. package/agent/setup-reminders.mjs +71 -8
  16. package/agent/setup.mjs +8 -39
  17. package/agent/spawn-child.mjs +6 -2
  18. package/agent/task-lifecycle.mjs +146 -0
  19. package/agent/turn-loop.mjs +73 -11
  20. package/agent-tools/batch-closeout.mjs +21 -34
  21. package/agent-tools/batch-gate.mjs +7 -5
  22. package/agent-tools/batch-ledger-bind.mjs +21 -1
  23. package/agent-tools/batch-lifecycle.mjs +7 -7
  24. package/agent-tools/batch-record-write.mjs +237 -280
  25. package/agent-tools/batch-supersede.mjs +3 -3
  26. package/agent-tools/batch.mjs +42 -9
  27. package/agent-tools/context.mjs +0 -13
  28. package/agent-tools/escalate-async.mjs +7 -1
  29. package/agent-tools/parent-channel.mjs +7 -6
  30. package/agent-tools/plan.mjs +103 -67
  31. package/agent-tools/review-facts.mjs +3 -3
  32. package/agent-tools/settings.mjs +2 -0
  33. package/agent-tools/spawn-gates.mjs +37 -11
  34. package/agent-tools/ssh-session.mjs +68 -25
  35. package/agent-tools/ssh-transfer.mjs +7 -2
  36. package/agent-tools/ssh-transport.mjs +2 -2
  37. package/agent-tools/ssh-vault.mjs +2 -2
  38. package/agent-tools/step.mjs +462 -0
  39. package/agent-tools/subagent-actions.mjs +6 -1
  40. package/agent-tools/subagent-run.mjs +7 -0
  41. package/agent-tools/subagent-spawn.mjs +1 -1
  42. package/agent-tools/subagent.mjs +17 -11
  43. package/agent-tools/task.mjs +178 -26
  44. package/agent-tools.mjs +1 -0
  45. package/agent.mjs +2 -0
  46. package/config-defaults.mjs +17 -1
  47. package/config-migrate.mjs +8 -5
  48. package/config.mjs +7 -0
  49. package/context.mjs +5 -4
  50. package/declaration.mjs +4 -4
  51. package/generate-title.mjs +0 -6
  52. package/i18n.mjs +4 -0
  53. package/ledger-cmd.mjs +11 -1
  54. package/ledger-tools.mjs +15 -4
  55. package/manifest-schema.mjs +1 -0
  56. package/model-context.mjs +34 -11
  57. package/model-specs.mjs +5 -2
  58. package/package.json +1 -1
  59. package/prompt-files.mjs +48 -11
  60. package/prompt-overlays.mjs +79 -8
  61. package/prompts/advisor-design.md +253 -206
  62. package/prompts/advisor-round1.md +151 -145
  63. package/prompts/advisor-round2.md +136 -130
  64. package/prompts/advisor-round3.md +140 -134
  65. package/prompts/common.md +244 -96
  66. package/prompts/consult-base.md +29 -30
  67. package/prompts/discipline-engineering.md +73 -519
  68. package/prompts/discipline-normal.md +28 -136
  69. package/prompts/knowledge/batch-before-write.md +8 -0
  70. package/prompts/knowledge/batch-cycle-register.md +15 -0
  71. package/prompts/knowledge/batch-progress-ledger.md +29 -0
  72. package/prompts/knowledge/business-gates.md +24 -24
  73. package/prompts/knowledge/decision-quality.md +8 -19
  74. package/prompts/knowledge/doc-discipline-d-rules.md +63 -0
  75. package/prompts/knowledge/doc-lookup.md +25 -24
  76. package/prompts/knowledge/document-writing.md +11 -32
  77. package/prompts/knowledge/documentation-evaluation.md +42 -42
  78. package/prompts/knowledge/eng-dispatch-ops.md +34 -0
  79. package/prompts/knowledge/eng-ledger-ops.md +26 -0
  80. package/prompts/knowledge/evidence-discipline.md +10 -32
  81. package/prompts/knowledge/normal-batch-discipline.md +13 -0
  82. package/prompts/knowledge/normal-coding-workflow.md +97 -99
  83. package/prompts/knowledge/normal-delivery-collaboration.md +107 -112
  84. package/prompts/knowledge/normal-work-management.md +44 -44
  85. package/prompts/knowledge/product-security.md +7 -26
  86. package/prompts/knowledge/project-records.md +69 -64
  87. package/prompts/knowledge/tool-advisor.md +17 -17
  88. package/prompts/knowledge/tool-apply-patch.md +14 -14
  89. package/prompts/knowledge/tool-bash.md +32 -31
  90. package/prompts/knowledge/tool-batch-eng-coder.md +19 -13
  91. package/prompts/knowledge/tool-batch-eng-designer.md +21 -14
  92. package/prompts/knowledge/tool-batch-review.md +18 -12
  93. package/prompts/knowledge/tool-batch.md +93 -85
  94. package/prompts/knowledge/tool-browser.md +59 -59
  95. package/prompts/knowledge/tool-code-search.md +2 -2
  96. package/prompts/knowledge/tool-consult-start.md +6 -6
  97. package/prompts/knowledge/tool-consult-stop.md +3 -3
  98. package/prompts/knowledge/tool-context.md +4 -4
  99. package/prompts/knowledge/tool-delete.md +16 -16
  100. package/prompts/knowledge/tool-doc-check.md +39 -39
  101. package/prompts/knowledge/tool-doc-graph-read.md +11 -11
  102. package/prompts/knowledge/tool-doc-graph.md +48 -48
  103. package/prompts/knowledge/tool-doc-search.md +3 -3
  104. package/prompts/knowledge/tool-edit.md +30 -30
  105. package/prompts/knowledge/tool-eng.md +1 -1
  106. package/prompts/knowledge/tool-execute.md +16 -16
  107. package/prompts/knowledge/tool-fetch.md +15 -15
  108. package/prompts/knowledge/tool-file-ops.md +15 -15
  109. package/prompts/knowledge/tool-get-current-time.md +3 -3
  110. package/prompts/knowledge/tool-git-read.md +15 -15
  111. package/prompts/knowledge/tool-git.md +26 -26
  112. package/prompts/knowledge/tool-glob.md +14 -14
  113. package/prompts/knowledge/tool-goal.md +5 -5
  114. package/prompts/knowledge/tool-grep.md +19 -18
  115. package/prompts/knowledge/tool-hashline-edit.md +13 -13
  116. package/prompts/knowledge/tool-insert-after.md +14 -14
  117. package/prompts/knowledge/tool-instance-list.md +3 -3
  118. package/prompts/knowledge/tool-instance-send.md +5 -5
  119. package/prompts/knowledge/tool-knowledge.md +12 -12
  120. package/prompts/knowledge/tool-ledger-read.md +20 -20
  121. package/prompts/knowledge/tool-ledger.md +44 -44
  122. package/prompts/knowledge/tool-lint.md +10 -10
  123. package/prompts/knowledge/tool-ls.md +11 -11
  124. package/prompts/knowledge/tool-lsp.md +8 -8
  125. package/prompts/knowledge/tool-main-history.md +1 -1
  126. package/prompts/knowledge/tool-manifest-read.md +7 -7
  127. package/prompts/knowledge/tool-manifest.md +43 -32
  128. package/prompts/knowledge/tool-memory-read.md +12 -12
  129. package/prompts/knowledge/tool-memory.md +14 -14
  130. package/prompts/knowledge/tool-notify-parent.md +10 -10
  131. package/prompts/knowledge/tool-operations.md +88 -88
  132. package/prompts/knowledge/tool-peek.md +10 -0
  133. package/prompts/knowledge/tool-peer-instances.md +1 -1
  134. package/prompts/knowledge/tool-plan.md +6 -3
  135. package/prompts/knowledge/tool-process-read.md +8 -8
  136. package/prompts/knowledge/tool-process.md +11 -11
  137. package/prompts/knowledge/tool-question.md +11 -13
  138. package/prompts/knowledge/tool-read-history-batch.md +13 -13
  139. package/prompts/knowledge/tool-read-history.md +19 -19
  140. package/prompts/knowledge/tool-read-image.md +8 -8
  141. package/prompts/knowledge/tool-read.md +17 -17
  142. package/prompts/knowledge/tool-recent-changes.md +4 -4
  143. package/prompts/knowledge/tool-repo-outline.md +2 -2
  144. package/prompts/knowledge/tool-settings-read.md +5 -7
  145. package/prompts/knowledge/tool-settings.md +10 -10
  146. package/prompts/knowledge/tool-skill.md +4 -4
  147. package/prompts/knowledge/tool-ssh.md +66 -66
  148. package/prompts/knowledge/tool-step.md +26 -0
  149. package/prompts/knowledge/tool-subagent.md +52 -50
  150. package/prompts/knowledge/tool-task.md +14 -11
  151. package/prompts/knowledge/tool-team-ledger-read.md +7 -7
  152. package/prompts/knowledge/tool-team-ledger.md +13 -13
  153. package/prompts/knowledge/tool-timer.md +14 -14
  154. package/prompts/knowledge/tool-tree.md +11 -11
  155. package/prompts/knowledge/tool-verify.md +11 -11
  156. package/prompts/knowledge/tool-wait-for.md +20 -20
  157. package/prompts/knowledge/tool-websearch.md +16 -14
  158. package/prompts/knowledge/tool-write.md +10 -10
  159. package/prompts/knowledge/upstream-protocol.md +37 -38
  160. package/prompts/persona-coder.md +22 -22
  161. package/prompts/persona-eng-coder.md +87 -81
  162. package/prompts/persona-eng-designer.md +173 -153
  163. package/prompts/persona-engineering.md +53 -554
  164. package/prompts/persona-explore.md +18 -15
  165. package/prompts/persona-normal.md +62 -63
  166. package/prompts/persona-plan.md +36 -32
  167. package/prompts/persona-tester.md +39 -39
  168. package/prompts/planning-next-moves.md +9 -0
  169. package/prompts/subagent-base.md +4 -16
  170. package/provider/errors.mjs +0 -24
  171. package/provider/list-models.mjs +20 -2
  172. package/session-lifecycle.mjs +4 -3
  173. package/tool-args.mjs +25 -0
  174. package/tool-docs/peek.md +3 -0
  175. package/tool-docs/plan.md +1 -1
  176. package/tool-docs/question.md +1 -1
  177. package/tool-docs/step.md +3 -0
  178. package/tools/edit-diff.mjs +4 -4
  179. package/tools/index.mjs +3 -2
  180. package/tools/peek.mjs +447 -0
  181. package/tools/question.mjs +87 -9
  182. package/tools/ssh.mjs +1 -1
  183. package/window-policy.mjs +107 -80
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thincoder/core",
3
- "version": "0.11.3",
3
+ "version": "0.11.5",
4
4
  "description": "ThinCoder shared core — shared mechanism modules + shared prompt content (CLI ↔ VS Code extension).",
5
5
  "keywords": [
6
6
  "ai",
package/prompt-files.mjs CHANGED
@@ -103,19 +103,54 @@ export function listKnowledgeTopics(sources = KNOWLEDGE_SOURCES) {
103
103
  return readKnowledgeEntries(sources).map(({ id, title }) => ({ id, title }))
104
104
  }
105
105
 
106
- // A knowledge anchor owns a whole line: the line holds the anchor and nothing else. Both tiers read that
107
- // one grammar — full mode swaps the line for the topic body, tiny mode hands the line back verbatim (the
108
- // anchor line is that tier's only topic inventory), and the residual check looks at the standalone marker
109
- // lines full mode did not consume. A marker inside a sentence is not an anchor; it reaches the model
110
- // verbatim. Reason: the sentence that states the grammar is itself carrying the marker shape, so judging
106
+ // A knowledge anchor owns a whole line: the line holds the anchor and nothing else. Both tiers read that one
107
+ // grammar — full mode swaps the line for the topic body unless the line writes `expand=lazy`, tiny mode hands the
108
+ // line back verbatim (the anchor line is that tier's only topic inventory), and the residual check looks at the
109
+ // standalone marker lines full mode did not consume. A marker inside a sentence is not an anchor; it reaches the
110
+ // model verbatim. Reason: the sentence that states the grammar is itself carrying the marker shape, so judging
111
111
  // an in-sentence marker as a broken anchor would make the prompt unable to describe its own anchor grammar.
112
- const KNOWLEDGE_ANCHOR_LINE_RE = /^[ \t]*\{\{knowledge:([a-z0-9-]+)\}\}[ \t]*(\r?\n|$)/gm
113
- const KNOWLEDGE_ANCHOR_RESIDUAL_LINE_RE = /^[ \t]*\{\{knowledge:[^{}\n]*\}\}[ \t]*$/gm
112
+ // 同理,`{{knowledge:<id>}}` 是**讲形态**的占位写法:`<>` 里的东西是模板位,不是主题 id。带键的同形写法
113
+ // (`{{knowledge:<id> expand=lazy}}`)同样只是形态。真锚的 id 正则只收 `[a-z0-9-]`,尖括号进不来;残留检测这条也照
114
+ // 同一条界线排除含 `<>` 的行 —— 否则把占位形态单独写一行(不加反引号)就会被判成坏锚,整档装配失败。
115
+ const KNOWLEDGE_ANCHOR_LINE_RE = /^[ \t]*\{\{knowledge:([a-z0-9-]+)([ \t][^{}\n]*?)?[ \t]*\}\}[ \t]*(\r?\n|$)/gm
116
+ // 残留面只接住形不成锚行的独占行:装配有意原样放回的锚行(极简档留下的、`expand=lazy` 的)由回调登记的
117
+ // 集合跳过——豁免绑「文法成立的锚」,不绑行内出现 `expand=lazy` 这串字;否则 id 笔误加 lazy 的独占行会静默通过。
118
+ const KNOWLEDGE_ANCHOR_RESIDUAL_LINE_RE = /^[ \t]*\{\{knowledge:(?![^{}\n]*[<>])[^{}\n]*\}\}[ \t]*$/gm
119
+
120
+ /** 键段的闭集:键名只收 `expand`,取值只收 `inline` 与 `lazy`;省了键段就等于 `expand=inline`。 */
121
+ const KNOWLEDGE_ANCHOR_KEY_NAME = "expand"
122
+ const KNOWLEDGE_ANCHOR_KEY_VALUES = Object.freeze(["inline", "lazy"])
123
+
124
+ /**
125
+ * 读一行的键段,返回 `"inline"` 或 `"lazy"`。键段至多一对键值;键名或取值不在闭集里就抛错,错误文本带上
126
+ * 作者写的那一行。键段校验只在完整档跑:极简档不展开主题正文,因此不校验键段,锚行原样交回。
127
+ */
128
+ function parseKnowledgeAnchorKey(line, keySegment) {
129
+ const segment = (keySegment ?? "").trim()
130
+ if (!segment) return "inline"
131
+ // 至多一对键值:`expand=inline expand=lazy` 不静默选边,也不读成「未知取值」——那种报文会把作者领偏。
132
+ if (/[ \t]/.test(segment)) {
133
+ throw new Error(`prompt knowledge anchor key segment must be a single key=value pair — got ${JSON.stringify(segment)} on the line ${JSON.stringify(line.trim())}; write "expand=inline" or "expand=lazy"`)
134
+ }
135
+ const separator = segment.indexOf("=")
136
+ const name = separator < 0 ? segment : segment.slice(0, separator)
137
+ const value = separator < 0 ? "" : segment.slice(separator + 1)
138
+ if (name !== KNOWLEDGE_ANCHOR_KEY_NAME) {
139
+ throw new Error(`prompt knowledge anchor has an unknown key name ${JSON.stringify(name)} on the line ${JSON.stringify(line.trim())} — the only key this grammar carries is "${KNOWLEDGE_ANCHOR_KEY_NAME}"`)
140
+ }
141
+ if (!KNOWLEDGE_ANCHOR_KEY_VALUES.includes(value)) {
142
+ throw new Error(`prompt knowledge anchor has an unknown expand value ${JSON.stringify(value)} on the line ${JSON.stringify(line.trim())} — write "expand=inline" or "expand=lazy"`)
143
+ }
144
+ return value
145
+ }
114
146
 
115
147
  /** Expand the shared master for full mode; tiny keeps every standalone anchor line verbatim. */
116
148
  export function expandKnowledgeTopics(text, { tiny = false } = {}) {
117
149
  const seen = new Set()
118
- const result = text.replace(KNOWLEDGE_ANCHOR_LINE_RE, (line, id, terminator) => {
150
+ const kept = new Set()
151
+ const result = text.replace(KNOWLEDGE_ANCHOR_LINE_RE, (line, id, keySegment, terminator) => {
152
+ // 键段先解析,再照旧解析主题与重复标识。极简档整条跳过键段校验:它不展开主题正文,锚行原样交回。
153
+ const lazy = !tiny && parseKnowledgeAnchorKey(line, keySegment) === "lazy"
119
154
  if (seen.has(id)) throw new Error(`prompt knowledge anchor duplicated: ${id}`)
120
155
  seen.add(id)
121
156
  // Both tiers resolve the topic first: tiny does not inline the body, but an anchor on its own line
@@ -127,14 +162,16 @@ export function expandKnowledgeTopics(text, { tiny = false } = {}) {
127
162
  } catch (error) {
128
163
  throw new Error(`prompt knowledge anchor cannot be resolved: {{knowledge:${id}}} — ${error.message}`, { cause: error })
129
164
  }
130
- return tiny ? line : body + terminator
165
+ // 写 `expand=lazy` 的锚行与极简档一样整行放回:主题正文不内联,模型按需经 `knowledge get` 取回。
166
+ if (tiny || lazy) { kept.add(line.trim()); return line }
167
+ return body + terminator
131
168
  })
132
169
  // Tiny hands every anchor line back, so scanning there would judge each kept line a broken anchor and
133
170
  // fail the whole tier; the scan exists for the anchors full mode left behind. A standalone line whose id
134
171
  // breaks the anchor grammar stays verbatim in tiny mode, unremarked — the tier's accepted cost.
135
172
  if (!tiny) {
136
- const unresolved = result.match(KNOWLEDGE_ANCHOR_RESIDUAL_LINE_RE)
137
- if (unresolved) throw new Error(`prompt knowledge anchor cannot be resolved: ${unresolved[0].trim()}`)
173
+ const leftover = (result.match(KNOWLEDGE_ANCHOR_RESIDUAL_LINE_RE) ?? []).filter((marker) => !kept.has(marker.trim()))
174
+ if (leftover.length) throw new Error(`prompt knowledge anchor cannot be resolved: ${leftover[0].trim()}`)
138
175
  }
139
176
  return result
140
177
  }
@@ -28,10 +28,10 @@ const SLOT_CONTENTS = {
28
28
 
29
29
  // ── G1 六件导出(评审 #1 计数口径:人格 2 + 公共 1 + 纪律 2 + consult 自含基底;
30
30
  // persona-{role} 三件由 SLOT_CONTENTS 承载、不设独立常量导出——装配表唯一消费面)──
31
- export const PERSONA_ENGINEERING = SLOT_CONTENTS["persona-engineering.md"]
32
- export const PERSONA_NORMAL = SLOT_CONTENTS["persona-normal.md"]
31
+ export const PERSONA_ENGINEERING = expandKnowledgeTopics(SLOT_CONTENTS["persona-engineering.md"])
32
+ export const PERSONA_NORMAL = expandKnowledgeTopics(SLOT_CONTENTS["persona-normal.md"])
33
33
  export const COMMON = expandKnowledgeTopics(SLOT_CONTENTS["common.md"])
34
- export const DISCIPLINE_ENGINEERING = SLOT_CONTENTS["discipline-engineering.md"]
34
+ export const DISCIPLINE_ENGINEERING = expandKnowledgeTopics(SLOT_CONTENTS["discipline-engineering.md"])
35
35
  export const DISCIPLINE_NORMAL = expandKnowledgeTopics(SLOT_CONTENTS["discipline-normal.md"])
36
36
  export const CONSULT_BASE = loadSlot("consult-base.md")
37
37
 
@@ -70,7 +70,79 @@ export function slotWarning(fileName) {
70
70
  * (槽位拼接结果 / consult 基底)——未配置 = 恒等,现行行为零变;读取径(模块级缓存)不动。
71
71
  * 必须保持的不变量:每个 return 分支都经 `applyPromptInjections`,新增分支未挂即错。
72
72
  */
73
- export function assemblePrompt(scenario, mode = "normal") {
73
+ /**
74
+ * 按本轮实际装配的工具表裁剪 `## 工具路由` 中的失效工具指引(不改母版单源):
75
+ * - 未挂 `step`(如子代理)⇒ 整行删去分叉微步路由,避免诱导调用不存在的工具;
76
+ * - 挂只读版 `step`(工程主代理 `stepReadTool`)⇒ 替换为只读分叉路由句,不提 `verify`/改码;
77
+ * - 未挂写/删/执行/联网工具(如只读 `explore`)⇒ 同步裁剪对应子句或整行。
78
+ * `tools` 缺省时原样返回(不破坏不传工具表的历史调用点)。
79
+ */
80
+ export function filterToolRouting(prompt, tools) {
81
+ if (!prompt || !tools) return prompt
82
+ const byName = tools instanceof Map
83
+ ? tools
84
+ : new Map((Array.isArray(tools) ? tools : []).map((t) => [typeof t === "string" ? t : t?.name, typeof t === "string" ? { name: t } : t]))
85
+ if (byName.size === 0) return prompt
86
+
87
+ const has = (n) => byName.has(n)
88
+ const hasAny = (...names) => names.some((n) => byName.has(n))
89
+ const joinMounted = (names) => names.filter((n) => byName.has(n)).map((n) => `\`${n}\``).join(" / ")
90
+
91
+ const STEP_RO_LINE = "- **分叉微步隔离(只读)**:跨 2+ 独立区域/来源做接触面核查、漂移比对或收口抽检,或主会话已连探 2 轮仍需深挖时,**直接并发派 1–3 个只读 `step(goal=...)`**——分叉复用主会话 KV 前缀缓存、过程噪音留在分叉内且机械禁写盘。"
92
+
93
+ return prompt.replace(/(## 工具路由\n[\s\S]*?)(\n\n|$)/, (_m, section, tail) => {
94
+ const lines = section.split("\n")
95
+ const out = []
96
+ for (const line of lines) {
97
+ if (line.startsWith("- **读写与查找**:")) {
98
+ const parts = []
99
+ if (has("read")) parts.push("读用 `read`")
100
+ if (has("peek")) parts.push("批量扫文档/代码骨架或按节/按符号抽取优先用 `peek`(毫秒级、低 token)")
101
+ const editList = joinMounted(["edit", "write", "apply_patch", "hashline_edit"])
102
+ if (editList) parts.push(`改用 ${editList}`)
103
+ const opsList = joinMounted(["delete", "file_ops"])
104
+ if (opsList) parts.push(`删改移用 ${opsList}`)
105
+ const findList = joinMounted(["ls", "glob", "grep", "tree", "doc_search", "code_search", "repo_outline"])
106
+ if (findList) parts.push(`找文件与内容用 ${findList}`)
107
+ if (parts.length > 0) out.push(`- **读写与查找**:${parts.join(",")}。`)
108
+ continue
109
+ }
110
+ if (line.startsWith("- **分叉微步隔离")) {
111
+ if (!has("step")) continue
112
+ out.push(byName.get("step")?.readonly === true ? STEP_RO_LINE : line)
113
+ continue
114
+ }
115
+ if (line.startsWith("- **执行与版本**:")) {
116
+ const parts = []
117
+ if (has("git")) parts.push("所有 git 操作走 `git` 工具(自动打快照)")
118
+ if (has("execute")) parts.push("JS 执行走 `execute`")
119
+ if (has("bash")) parts.push("其余 CLI/包管理才走 `bash`")
120
+ if (parts.length > 0) out.push(`- **执行与版本**:${parts.join(",")}。`)
121
+ continue
122
+ }
123
+ if (line.startsWith("- **联网与并行**:")) {
124
+ const parts = []
125
+ const webList = joinMounted(["websearch", "fetch"])
126
+ if (webList) parts.push(`外网核实优先 MCP 搜索工具,其次 ${webList}(追第一手官方来源,不手工 \`curl\` 刮取)`)
127
+ const parallel = has("subagent")
128
+ ? "独立只读调用并行发出;异步子代理完成后会自动回传,不用 `wait_for` 轮询"
129
+ : "独立只读调用并行发出"
130
+ parts.push(parallel)
131
+ out.push(`- **联网与并行**:${parts.join("。")}。`)
132
+ continue
133
+ }
134
+ if (line.startsWith("- **删除与不可逆**:")) {
135
+ if (!hasAny("delete", "edit", "write", "apply_patch", "hashline_edit", "file_ops", "bash", "execute")) continue
136
+ out.push(line)
137
+ continue
138
+ }
139
+ out.push(line)
140
+ }
141
+ return out.join("\n") + tail
142
+ })
143
+ }
144
+
145
+ export function assemblePrompt(scenario, mode = "normal", { tools = null } = {}) {
74
146
  // 未登记的场景名在入口拒绝(PROMPT-SYSTEM.md §5.1 装配入口):判「登记过」看键在不在,不看值真假——
75
147
  // 键在场而值为 `null` 是 `consult` 一支,键不在场就是未登记名;两条路不共用返回路径。
76
148
  if (!Object.hasOwn(SCENARIO_SLOT_FILES, scenario)) {
@@ -84,11 +156,10 @@ export function assemblePrompt(scenario, mode = "normal") {
84
156
  const warnings = []
85
157
  for (const file of files) {
86
158
  const content = SLOT_CONTENTS[file]
87
- const expanded = file === "common.md" || file === "discipline-normal.md"
88
- ? expandKnowledgeTopics(content, { tiny: mode === "tiny" })
89
- : content
159
+ const expanded = content ? expandKnowledgeTopics(content, { tiny: mode === "tiny" }) : content
90
160
  if (expanded) parts.push(expanded)
91
161
  else warnings.push(slotWarning(file))
92
162
  }
93
- return { prompt: applyPromptInjections(parts.join("\n\n")), warnings }
163
+ const assembled = filterToolRouting(parts.join("\n\n"), tools)
164
+ return { prompt: applyPromptInjections(assembled), warnings }
94
165
  }