@thincoder/core 0.11.4 → 0.12.1

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 (199) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/abort-provenance.mjs +23 -0
  3. package/advisor/citations.mjs +5 -1
  4. package/advisor/compaction.mjs +13 -10
  5. package/advisor/history.mjs +6 -1
  6. package/advisor/loop.mjs +35 -10
  7. package/advisor/messages.mjs +31 -43
  8. package/advisor/project-context.mjs +49 -45
  9. package/advisor/run.mjs +82 -26
  10. package/advisor.mjs +40 -11
  11. package/agent/assemble.mjs +5 -5
  12. package/agent/chat-call.mjs +21 -1
  13. package/agent/completion.mjs +1 -20
  14. package/agent/dispatch-gates.mjs +8 -3
  15. package/agent/dispatch-run.mjs +131 -20
  16. package/agent/dispatch.mjs +23 -22
  17. package/agent/family-tools.mjs +4 -7
  18. package/agent/goal-judge.mjs +99 -0
  19. package/agent/goal-state.mjs +96 -0
  20. package/agent/helpers.mjs +13 -4
  21. package/agent/offload.mjs +1 -1
  22. package/agent/planning-graph-guardrail.mjs +224 -0
  23. package/agent/planning-prompt.mjs +179 -0
  24. package/agent/planning-step.mjs +460 -173
  25. package/agent/post-turn.mjs +23 -33
  26. package/agent/record-results.mjs +8 -5
  27. package/agent/run-stages.mjs +22 -41
  28. package/agent/run-start.mjs +26 -19
  29. package/agent/setup-reminders.mjs +16 -14
  30. package/agent/setup.mjs +3 -2
  31. package/agent/spawn-child.mjs +17 -4
  32. package/agent/suspension.mjs +42 -21
  33. package/agent/task-lifecycle.mjs +165 -52
  34. package/agent/timers.mjs +9 -1
  35. package/agent/turn-loop.mjs +160 -69
  36. package/agent/turn-projection.mjs +26 -15
  37. package/agent/turn-task-state.mjs +4 -4
  38. package/agent/write-gate-ledger.mjs +1 -1
  39. package/agent/write-gate.mjs +14 -11
  40. package/agent-tools/advisor-async.mjs +2 -0
  41. package/agent-tools/advisor-launch.mjs +27 -13
  42. package/agent-tools/advisor-settle.mjs +19 -18
  43. package/agent-tools/advisor.mjs +90 -13
  44. package/agent-tools/bash-async.mjs +3 -3
  45. package/agent-tools/batch-ledger-bind.mjs +8 -5
  46. package/agent-tools/batch-read.mjs +42 -0
  47. package/agent-tools/batch-record-write.mjs +20 -12
  48. package/agent-tools/batch-segment-vocab.mjs +6 -4
  49. package/agent-tools/batch-skeleton.mjs +43 -12
  50. package/agent-tools/consult.mjs +5 -1
  51. package/agent-tools/context.mjs +5 -4
  52. package/agent-tools/design-slots.mjs +7 -4
  53. package/agent-tools/design-token.mjs +3 -2
  54. package/agent-tools/doc-graph.mjs +257 -95
  55. package/agent-tools/escalate-async.mjs +4 -1
  56. package/agent-tools/goal.mjs +28 -95
  57. package/agent-tools/plan.mjs +1 -1
  58. package/agent-tools/review-facts.mjs +56 -7
  59. package/agent-tools/settings.mjs +35 -1
  60. package/agent-tools/ssh-transport.mjs +23 -22
  61. package/agent-tools/step.mjs +24 -4
  62. package/agent-tools/subagent-actions.mjs +6 -2
  63. package/agent-tools/subagent-async.mjs +4 -2
  64. package/agent-tools/subagent.mjs +1 -1
  65. package/agent-tools/task.mjs +73 -65
  66. package/agent-tools.mjs +3 -3
  67. package/agent.mjs +12 -3
  68. package/auto-think.mjs +16 -3
  69. package/browser/actions.mjs +5 -1
  70. package/browser/cdp.mjs +1 -1
  71. package/browser/pool.mjs +110 -17
  72. package/compaction-work-state.mjs +103 -13
  73. package/compress-form.mjs +29 -3
  74. package/config-defaults.mjs +27 -3
  75. package/config-io.mjs +3 -14
  76. package/config-normalize.mjs +24 -4
  77. package/config-presets.mjs +40 -26
  78. package/config-warn.mjs +30 -0
  79. package/config.mjs +139 -63
  80. package/context-degrade.mjs +4 -4
  81. package/context-push.mjs +20 -9
  82. package/context.mjs +65 -20
  83. package/doc-graph/anchors.mjs +39 -40
  84. package/doc-graph/clusters.mjs +49 -0
  85. package/doc-graph/code-parsers.mjs +494 -0
  86. package/doc-graph/context-pack.mjs +392 -0
  87. package/doc-graph/dir-signals.mjs +228 -0
  88. package/doc-graph/edges.mjs +231 -0
  89. package/doc-graph/format.mjs +70 -0
  90. package/doc-graph/gc-cmd.mjs +104 -0
  91. package/doc-graph/gc.mjs +112 -0
  92. package/doc-graph/glob-work-graph.mjs +307 -0
  93. package/doc-graph/golden-set.mjs +131 -0
  94. package/doc-graph/ls-work-graph.mjs +534 -0
  95. package/doc-graph/outline.mjs +377 -0
  96. package/doc-graph/output-annotations.mjs +85 -0
  97. package/doc-graph/process-docs.mjs +68 -0
  98. package/doc-graph/read-work-graph.mjs +91 -0
  99. package/doc-graph/rebuild-cmd.mjs +75 -0
  100. package/doc-graph/resolvers.mjs +322 -0
  101. package/doc-graph/roots.mjs +86 -0
  102. package/doc-graph/schema.mjs +110 -0
  103. package/doc-graph/search-augment.mjs +418 -0
  104. package/doc-graph/store.mjs +231 -0
  105. package/doc-graph/target-resolve.mjs +352 -0
  106. package/doc-graph/walk.mjs +87 -0
  107. package/doc-graph.mjs +583 -707
  108. package/explore-distill.mjs +52 -17
  109. package/generate-title.mjs +7 -4
  110. package/ledger-close.mjs +6 -6
  111. package/ledger-cmd.mjs +3 -3
  112. package/ledger-consistency.mjs +8 -6
  113. package/ledger-db.mjs +45 -10
  114. package/ledger-migrate.mjs +25 -10
  115. package/ledger-read.mjs +1 -1
  116. package/ledger-write-ops.mjs +6 -6
  117. package/ledger.mjs +2 -2
  118. package/model-context.mjs +54 -18
  119. package/model-specs.mjs +86 -67
  120. package/package.json +1 -1
  121. package/prompt-overlays.mjs +3 -3
  122. package/prompts/advisor-round1.md +6 -5
  123. package/prompts/common.md +16 -6
  124. package/prompts/consult-base.md +2 -1
  125. package/prompts/discipline-engineering.md +1 -1
  126. package/prompts/discipline-normal.md +12 -8
  127. package/prompts/knowledge/doc-lookup.md +2 -2
  128. package/prompts/knowledge/normal-batch-discipline.md +2 -2
  129. package/prompts/knowledge/normal-delivery-collaboration.md +3 -3
  130. package/prompts/knowledge/tool-advisor.md +2 -2
  131. package/prompts/knowledge/tool-apply-patch.md +1 -1
  132. package/prompts/knowledge/tool-bash.md +2 -2
  133. package/prompts/knowledge/tool-batch.md +4 -4
  134. package/prompts/knowledge/tool-glob.md +9 -2
  135. package/prompts/knowledge/tool-goal.md +9 -6
  136. package/prompts/knowledge/tool-grep.md +7 -2
  137. package/prompts/knowledge/tool-ls.md +11 -5
  138. package/prompts/knowledge/tool-lsp.md +1 -1
  139. package/prompts/knowledge/tool-operations.md +3 -2
  140. package/prompts/knowledge/tool-plan.md +1 -1
  141. package/prompts/knowledge/tool-read.md +7 -6
  142. package/prompts/knowledge/tool-repo-graph-read.md +12 -0
  143. package/prompts/knowledge/tool-repo-graph.md +12 -0
  144. package/prompts/knowledge/tool-step.md +1 -1
  145. package/prompts/knowledge/tool-subagent.md +2 -2
  146. package/prompts/knowledge/tool-task.md +10 -9
  147. package/prompts/knowledge/tool-tree.md +7 -1
  148. package/prompts/persona-eng-coder.md +1 -1
  149. package/prompts/persona-eng-designer.md +1 -1
  150. package/prompts/persona-engineering.md +2 -1
  151. package/prompts/persona-explore.md +1 -1
  152. package/prompts/persona-normal.md +7 -6
  153. package/prompts/persona-plan.md +2 -2
  154. package/prompts/planning-next-moves.md +7 -8
  155. package/provider/anthropic.mjs +53 -51
  156. package/provider/core.mjs +85 -34
  157. package/provider/errors.mjs +33 -10
  158. package/provider/google.mjs +244 -37
  159. package/provider/list-models.mjs +28 -14
  160. package/provider/responses-request.mjs +15 -9
  161. package/provider/responses.mjs +10 -8
  162. package/provider/sse.mjs +3 -6
  163. package/proxy-transport.mjs +228 -119
  164. package/rules-file.mjs +79 -0
  165. package/rules.mjs +13 -51
  166. package/session-lifecycle.mjs +32 -20
  167. package/team-ledger.mjs +7 -7
  168. package/think-off.mjs +37 -18
  169. package/token-window.mjs +48 -31
  170. package/tool-args.mjs +8 -8
  171. package/tool-docs/bash.md +1 -1
  172. package/tool-docs/glob.md +3 -1
  173. package/tool-docs/goal.md +2 -2
  174. package/tool-docs/grep.md +3 -1
  175. package/tool-docs/ls.md +7 -1
  176. package/tool-docs/read.md +1 -1
  177. package/tool-docs/repo_graph-read.md +3 -0
  178. package/tool-docs/repo_graph.md +3 -0
  179. package/tool-docs/tree.md +1 -1
  180. package/tools/bash.mjs +53 -8
  181. package/tools/browser.mjs +4 -4
  182. package/tools/file.mjs +34 -7
  183. package/tools/glob-dialect.mjs +57 -7
  184. package/tools/index.mjs +3 -7
  185. package/tools/patch.mjs +8 -7
  186. package/tools/process-doc-mark.mjs +13 -0
  187. package/tools/search.mjs +152 -37
  188. package/tools/shared.mjs +6 -0
  189. package/tools/tree.mjs +211 -8
  190. package/window-policy.mjs +205 -126
  191. package/prompts/knowledge/tool-doc-graph-read.md +0 -20
  192. package/prompts/knowledge/tool-doc-graph.md +0 -49
  193. package/prompts/knowledge/tool-peek.md +0 -10
  194. package/prompts/knowledge/tool-repo-outline.md +0 -4
  195. package/tool-docs/doc_graph-read.md +0 -3
  196. package/tool-docs/doc_graph.md +0 -3
  197. package/tool-docs/peek.md +0 -3
  198. package/tool-docs/repo_outline.md +0 -3
  199. package/tools/peek.mjs +0 -447
package/model-context.mjs CHANGED
@@ -1,14 +1,15 @@
1
1
  /**
2
- * model-context.mjs — 模型上下文解析的运行时事实面(`PROVIDER.md` §6.15 · 五级链 L1/L3 两层来源)。
2
+ * model-context.mjs — 模型上下文解析的运行时事实面(`PROVIDER.md` §6.15 · 解析链 L1/L2 两层来源)。
3
3
  *
4
4
  * 组成三件:模块级 `baseURL → (归一 id → 条目表)` 只读缓存 · 键归一(末段 + 小写)· 值域校验
5
- * (`positiveInt`)。零本地 import(只碰运行时内建)⇒ 零 import 环。
5
+ * (`positiveInt` 只认 number;`nonNegativeIntValue` / `positiveIntValue` 另收十进制整数文本,供配置计数值与 `config.modelContext` 归一用)。
6
+ * 本地 import 只有一个零依赖档 `config-warn.mjs`(告警出口闸)——它零 import,所以本档不成环。
6
7
  *
7
- * - L1 `providers[].modelContext[模型]`(人工声明,**K** 单位)→ `manualContextK`(返 K)
8
- * - L3 `/models` 自报窗口(**token**)→ `listedContextTokens`(返 token)
9
- * - L3 `/models` 自报输出上限(**token**)→ `listedOutputTokens`(返 token)
8
+ * - L1 `config.modelContext[模型]`(人工声明,**K** 单位)→ `manualContextK`(返 K)
9
+ * - L2 `/models` 自报窗口(**token**)→ `listedContextTokens`(返 token)
10
+ * - L2 `/models` 自报输出上限(**token**)→ `listedOutputTokens`(返 token)
10
11
  * 同一份自报里的两个量(窗口预算 / 单次输出天花板)住两张表、两条读面,一个端报窗口不代它报输出上限。
11
- * 单位进函数名:乘点唯一在 `model-specs.mjs`(L1 ∥ L2 ×1024,L3 不乘)——读函数名即知单位。
12
+ * 单位进函数名:乘点唯一在 `model-specs.mjs`(L1 ×1024,L2 不乘)——读函数名即知单位。
12
13
  *
13
14
  * 缓存触发 = 既有列表拉取(写面只在 `provider/list-models.mjs` 成功返回时调 `recordListedContext`):
14
15
  * 六个消费面本来就要拉列表,顺带把窗口留在核里,**零新增请求**(D2)。读面是同步纯查表:未命中返
@@ -20,12 +21,44 @@
20
21
  * 不比较;R29④)——不拒、不告警、不落下一层。
21
22
  */
22
23
 
23
- /** 值域校验单点(L1 K ∥ L3 token 共用谓词):正整数才收,其余一律 `null`(= 未提供)。
24
+ import { warnConfig } from "./config-warn.mjs"
25
+
26
+ /** 值域校验单点(L1 K ∥ L2 token 共用谓词):正整数才收,其余一律 `null`(= 未提供)。
24
27
  * 只认 `number`——写面交互输入是字符串,须先 `Number(String(v).trim())` 再判(调用侧责任)。 */
25
28
  export function positiveInt(v) {
26
29
  return typeof v === "number" && Number.isInteger(v) && v > 0 ? v : null
27
30
  }
28
31
 
32
+ /**
33
+ * 配置计数值的**唯一**取值域谓词(`CONTEXT-COMPACTION.md` §1「保留窗与跨轮清理」∥ §2.2):
34
+ * 数字或数字串、有限非负整数 ⇒ 该数;其余(负数 ∥ 小数 ∦ 非数字 ∥ 布尔 ∥ 对象 ∥ `null` ∥ 空串)⇒ `null`。
35
+ * `agent.compactThreshold` / `agent.keepToolTurns` / `config.modelContext` 与三端输入面共用这一份,另写一个
36
+ * 等价判断就是同一规则的第二个实现(改一处、别处不跟,正是不一致的老路)。
37
+ * 数字串按十进制整数文本收(`"1e3"` ∥ `"0x10"` ∥ `"+5"` 一律 `null`):配置里手写的这两种形是笔误,
38
+ * 静默转数会把「想写哪个量」藏起来。空串先返回 `null`——`Number("")` 是 0,不先判就变成一个合法的 0。
39
+ *
40
+ * **本体的家为什么是本档**(2026-11-29,批 `2026-11-29-providers-context-predicate` / 台账 #52):
41
+ * 调用面已经跨到 `config-io.mjs`(装载期的 `resolveProviders`)与 `model-specs.mjs`(L1 读面),
42
+ * 而 `config-io` **不能** import `window-policy`——`window-policy` → `config-defaults` → `config-io` 是现存的
43
+ * 导入环,`config-defaults` 在顶层读 `configDir`,config-io 作为入口时该绑定还在 TDZ。本档唯一的本地 import 是零依赖的 `config-warn.mjs`(告警出口),
44
+ * 两侧引它都不会成环;`window-policy.mjs` 以 import + re-export 转口,既有导入面(`config.mjs` 第 56 行等)逐字不变。
45
+ */
46
+ export function nonNegativeIntValue(raw) {
47
+ if (typeof raw === "number") return Number.isFinite(raw) && Number.isInteger(raw) && raw >= 0 ? raw : null
48
+ if (typeof raw !== "string") return null
49
+ const text = raw.trim()
50
+ if (!/^\d+$/.test(text)) return null
51
+ const num = Number(text)
52
+ return Number.isFinite(num) && Number.isInteger(num) && num >= 0 ? num : null
53
+ }
54
+
55
+ /** 计数值的正整谓词(同上,`> 0` 一支):`"0"` ∥ 负数 ∥ 小数 ∥ `"1e3"` ∥ `"0x10"` ∥ 空串 ⇒ `null`。
56
+ * 装载期 `agent.contextCaps` 循环、`/config` 写支、`resolveContextCaps`、`contextCapTokens`、`config.modelContext` 归一五处共调这一份。 */
57
+ export function positiveIntValue(raw) {
58
+ const n = nonNegativeIntValue(raw)
59
+ return n === null || n <= 0 ? null : n
60
+ }
61
+
29
62
  /** 模型名归一(末段 + 小写——§6.9 三面同一把尺子)。非串归一等价空串(脏载不抛)。 */
30
63
  export function normalizeModelKey(name) {
31
64
  const m = (typeof name === "string" ? name : "").toLowerCase()
@@ -37,15 +70,16 @@ function normalizeBaseURL(baseURL) {
37
70
  return (typeof baseURL === "string" ? baseURL : "").replace(/\/+$/, "")
38
71
  }
39
72
 
40
- /** 告警一次(模块级去重键)——本模块唯一告警出口;去重键决定「一次」的射程。 */
73
+ /** 告警一次(模块级去重键)——本模块唯一告警出口;去重键决定「一次」的射程。
74
+ * 出词经 `config-warn.mjs` 的 `warnConfig`:stderr 不是终端时静默(出口判据见 `CONFIG.md` §2.4)。 */
41
75
  const warned = new Set()
42
76
  export function warnContextOnce(key, message) {
43
77
  if (warned.has(key)) return
44
78
  warned.add(key)
45
- console.warn(message)
79
+ warnConfig(message)
46
80
  }
47
81
 
48
- // ─── L3 缓存:归一 baseURL → (归一 id → 条目表) ───────────────────────────────────
82
+ // ─── L2 缓存:归一 baseURL → (归一 id → 条目表) ───────────────────────────────────
49
83
  // 键 = 归一后的 baseURL(列表是端点的事实,不是本地别名的事实——探针目标常缺 name)。
50
84
  // 写 = 每次成功拉取**整条替换**(不合并):列表不再报某模型 ⇒ 该模型回到 L4;拉取失败不写、
51
85
  // 不清空上次成功值(上次自报比静态表更接近事实)。归一索引在写时建好 ⇒ 读面是一次 `Map` 查表
@@ -71,7 +105,7 @@ function indexOf(entries) {
71
105
  return index
72
106
  }
73
107
 
74
- /** L3 写面(唯一入口):记录一个端点的列表自报表。`windows` / `outputs` 都是 `Map<id, tokens>`
108
+ /** L2 写面(唯一入口):记录一个端点的列表自报表。`windows` / `outputs` 都是 `Map<id, tokens>`
75
109
  * 或 `[id, tokens]` 可迭代(Map ∥ 数组);非法值当场丢弃(= 该模型列表未报)。空表也写入
76
110
  * ——「这次一条都没报」是事实;传 `undefined` 与传空表同判(两表都落成空索引,读面落下一层)。 */
77
111
  export function recordListedContext(baseURL, windows, outputs) {
@@ -81,7 +115,7 @@ export function recordListedContext(baseURL, windows, outputs) {
81
115
  listedOutputByEndpoint.set(base, indexOf(outputs))
82
116
  }
83
117
 
84
- /** L3 读面:列表自报窗口(token,不乘)。未报 ⇒ `null`(落下一层);同端点两 id 末段相撞
118
+ /** L2 读面:列表自报窗口(token,不乘)。未报 ⇒ `null`(落下一层);同端点两 id 末段相撞
85
119
  * ⇒ 取列表序第一条即用(同一模型,R29④——不排序、不比较、不告警)。 */
86
120
  export function listedContextTokens(provider) {
87
121
  const base = normalizeBaseURL(provider?.baseURL)
@@ -91,7 +125,7 @@ export function listedContextTokens(provider) {
91
125
  return bucket ? positiveInt(bucket[0].tokens) : null
92
126
  }
93
127
 
94
- /** L3 读面(输出上限):列表自报的单次输出天花板(token,不乘)。未报 ⇒ `null`(落回静态表档)。
128
+ /** L2 读面(输出上限):列表自报的单次输出天花板(token,不乘)。未报 ⇒ `null`(落回静态表档)。
95
129
  * 与 `listedContextTokens` 同形但**不同表**:一个端报窗口不代它报输出上限。 */
96
130
  export function listedOutputTokens(provider) {
97
131
  const base = normalizeBaseURL(provider?.baseURL)
@@ -101,11 +135,13 @@ export function listedOutputTokens(provider) {
101
135
  return bucket ? positiveInt(bucket[0].tokens) : null
102
136
  }
103
137
 
104
- /** L1 读面:`providers[].modelContext[模型]` 人工声明(K 单位)。未声明 ∥ 值非法 ⇒ `null`
138
+ /** L1 读面:`config.modelContext[模型]` 人工声明(K 单位)。未声明 ∥ 值非法 ⇒ `null`
105
139
  * (落下一层);两条键归一后相同 = 同一模型的两种写法 ⇒ 取对象键序第一条即用(R29④——
106
- * 不排序、不比较、不告警)。值非法在装载期已告警一次(`config.mjs`),此处只判不告(热路径)。 */
107
- export function manualContextK(provider) {
108
- const table = provider?.modelContext
140
+ * 不排序、不比较、不告警)。值非法在装载期已告警一次(`config.mjs`),此处只判不告(热路径)。
141
+ * `settings` = 整份 config(读 `modelContext`;缺 ⇒ 未声明)。声明住设置层顶层,不随渠道条目走
142
+ * (用户 2026-12-03 裁定:模型窗口声明不属于渠道)。 */
143
+ export function manualContextK(provider, settings) {
144
+ const table = settings?.modelContext
109
145
  if (!table || typeof table !== "object" || Array.isArray(table)) return null
110
146
  const target = normalizeModelKey(provider?.model)
111
147
  if (!target) return null
@@ -113,7 +149,7 @@ export function manualContextK(provider) {
113
149
  return null
114
150
  }
115
151
 
116
- /** 测试缝:清空 L3 缓存 + 告警去重(单元档用;生产零调用)。 */
152
+ /** 测试缝:清空 L2 缓存 + 告警去重(单元档用;生产零调用)。 */
117
153
  export function _resetModelContextForTest() {
118
154
  listedByEndpoint.clear()
119
155
  listedOutputByEndpoint.clear()
package/model-specs.mjs CHANGED
@@ -9,6 +9,8 @@
9
9
 
10
10
  import { listedContextTokens, manualContextK, warnContextOnce } from "./model-context.mjs"
11
11
  import { logEvent } from "./log.mjs"
12
+ // 值告警的唯一出口(`CONFIG.md` §2.4):stderr 不是终端时静默。
13
+ import { warnConfig } from "./config-warn.mjs"
12
14
 
13
15
  /**
14
16
  * Known model capability spec table (prefix match within the model's last "/"-segment, longer first).
@@ -22,7 +24,7 @@ import { logEvent } from "./log.mjs"
22
24
  * multimodal: whether multimodal (image/vision input supported)
23
25
  * thinkApi: thinking API type: "type"=thinking.type field / "effort"=reasoning_effort field
24
26
  * thinkEnabledValue: when thinkApi is "type", the value used to enable thinking (default "enabled"; MiniMax uses "adaptive")
25
- * thinkAlwaysOn: server-enforced thinking (true = always on — no off path; single source = MODEL-SPECS.md §16.3)
27
+ * thinkAlwaysOn: server-enforced thinking (true = always on — no off path; single source = MODEL-SPECS.md §4)
26
28
  * reasoningEcho: reasoning_content cross-turn echo strategy: "required"=must echo (error if missing) / "optional"=echo optional (default: don't echo)
27
29
  * reasoningEffortEnum: valid reasoning_effort enum values (if undeclared, no validation — passed through as-is)
28
30
  * tempRange: valid temperature range [min, max] (if undeclared, no clamping)
@@ -133,10 +135,17 @@ const MODEL_SPECS = [
133
135
  // reasoningEcho undeclared (cross-turn echo unverified — R-4). The server also takes audio, this
134
136
  // repo's call path sends images only ⇒ multimodal below = image intake (no `modalities` field, §2.7).
135
137
  ["qwen3.8-omni-flash",{ context: 1_000_000, maxOutput: 131_072, thinking: true, partialMode: true, multimodal: true, thinkApi: "effort", reasoningEffortEnum: ["none", "minimal", "low", "medium", "high", "xhigh", "max"], tempRange: [0, 2] }],
136
- // 27b: context 262_144 = doc/web statement, the native value (1M is YaRN extrapolation, local
137
- // deploy only); partialMode / thinkApi / tempRange same-family carry-over; reasoningEcho
138
+ // 27b: **基础(原生)规格**——context 262_144 ∥ maxOutput 32_768。口径 = 用户 2026-12-03 裁定(原话四条):
139
+ // 「模型规格要按基础规格!」·「不能按扩展后的!」·「应该是32K输出,256K上下文」·
140
+ // 「你按在线服务的写,用在其他场景比如私有部署时就会错」。
141
+ // 原生 262,144 有一手面:`max_position_embeddings` = 262,144,多源同述「原生支持 262,144,通过 YaRN 可扩展至约 1M」
142
+ // (官方在线服务页 `https://help.aliyun.com/zh/model-studio/qwen3-8-27b` 的「上下文长度 1000000 / 最大输出长度 131072」是**服务口径**,按上述规矩不采用)。
143
+ // `32_768` = **用户裁定值**(本行**无独立一手源**——如实标级,不冒充官方口径)。
144
+ // 旧注(2026-12-03 前)写 context 262_144 = "the native value (1M is YaRN extrapolation, local deploy only)"
145
+ // 口径本就正确,本次把同一条规矩写清楚。
146
+ // partialMode / thinkApi / tempRange same-family carry-over; reasoningEcho
138
147
  // undeclared (cross-turn echo unverified — R-4).
139
- ["qwen3.8-27b", { context: 262_144, maxOutput: 131_072, thinking: true, partialMode: true, multimodal: true, thinkApi: "effort", reasoningEffortEnum: ["none", "minimal", "low", "medium", "high", "xhigh", "max"], tempRange: [0, 2] }],
148
+ ["qwen3.8-27b", { context: 262_144, maxOutput: 32_768, thinking: true, partialMode: true, multimodal: true, thinkApi: "effort", reasoningEffortEnum: ["none", "minimal", "low", "medium", "high", "xhigh", "max"], tempRange: [0, 2] }],
140
149
  // No generic "qwen" fallback row: unlisted qwen names deliberately resolve to DEFAULT_SPEC
141
150
  // (256K / 32K, no vision) — per-name disposition in docs/core/design/MODEL-SPECS.md §3.
142
151
  // Do not re-add a blanket prefix row (silent inheritance is how missing rows stayed invisible).
@@ -151,8 +160,12 @@ const MODEL_SPECS = [
151
160
  ["qwen3.6-flash", { context: 1_000_000, maxOutput: 65_536, thinking: true, partialMode: true, multimodal: true, thinkApi: "effort", reasoningEffortEnum: ["none", "minimal", "low", "medium", "high", "xhigh"], tempRange: [0, 2] }],
152
161
  // qwen3.6-plus:同形行(共享证据块见 flash 行上)——校验级 maxOutput / 六档枚举、官方口径 context、族沿用机制位。
153
162
  ["qwen3.6-plus", { context: 1_000_000, maxOutput: 65_536, thinking: true, partialMode: true, multimodal: true, thinkApi: "effort", reasoningEffortEnum: ["none", "minimal", "low", "medium", "high", "xhigh"], tempRange: [0, 2] }],
154
- // qwen3.6-27b:同形行——校验级 maxOutput / 六档枚举、官方口径 context(未探边)、族沿用机制位。
155
- ["qwen3.6-27b", { context: 1_000_000, maxOutput: 65_536, thinking: true, partialMode: true, multimodal: true, thinkApi: "effort", reasoningEffortEnum: ["none", "minimal", "low", "medium", "high", "xhigh"], tempRange: [0, 2] }],
163
+ // qwen3.6-27b:校验级 maxOutput / 六档枚举、族沿用机制位。**context 262_144**(2026-12-03 收正——
164
+ // 原写 1_000_000 是错的):官方模型信息页原文「上下文长度 262144 · 最大输入长度 260096 ·
165
+ // 最大输入长度(思考模式下)258048」,`https://help.aliyun.com/zh/model-studio/qwen3-6-27b`
166
+ // (页内更新日 2026-10-10,2026-12-03 实读)。同族 flash ∥ plus ∥ 35b-a3b 各自官方页均为 1M——
167
+ // 27B Dense 与其余档的窗口本来就不同,故本行不跟族值。
168
+ ["qwen3.6-27b", { context: 262_144, maxOutput: 65_536, thinking: true, partialMode: true, multimodal: true, thinkApi: "effort", reasoningEffortEnum: ["none", "minimal", "low", "medium", "high", "xhigh"], tempRange: [0, 2] }],
156
169
  // qwen3.5-27b(2026-09-24 bench 名单批):context 262_144 = **官方口径(定价页分档佐证——[128K, 256K) 档在售;规格页未逐名核)**;
157
170
  // maxOutput / 机制位 = **族沿用 qwen3.6-27b 行**;枚举 / 视觉面 = **未探**(不声明)。
158
171
  ["qwen3.5-27b", { context: 262_144, maxOutput: 65_536, thinking: true, partialMode: true, thinkApi: "effort", tempRange: [0, 2] }],
@@ -208,19 +221,33 @@ const MODEL_SPECS = [
208
221
  // (多源网络转述级,本机无该渠道——行值 + 行注即标级);thinking「always-on adaptive」= 弱源读数 ⇒ 零口径不落字段(§14.3)。
209
222
  ["claude-fable-5.1", { context: 1_000_000, maxOutput: 128_000 }],
210
223
  // Gemini series (Google)
224
+ // off 面(2026-12-01 批 google-thinking-off-form):「有无 off 路径」与 wire 形态一律单源 `think-off.mjs`
225
+ // 的 `thinkOffPath` / `googleThinkingOff`。这三行**未**声明 `thinkAlwaysOn`,也未取到 `thinkingBudget:0` 的
226
+ // 读数(`gemini-2.5-pro` ∥ `gemini-3-pro` 在 2026-12-01 当期 key 下 404——不可达;`thinkingLevel:"none"`
227
+ // 则一律 400)⇒ off 面 = **未探**,待可达时重测(现下它们会发 `thinkingBudget:0`)。
211
228
  ["gemini-3-pro", { context: 1_000_000, maxOutput: 64_000, thinking: true, multimodal: true, format: "google", noUsageStream: true }],
212
229
  ["gemini-2.5-pro", { context: 2_000_000, maxOutput: 64_000, thinking: true, multimodal: true, format: "google", noUsageStream: true }],
213
230
  ["gemini-2.5-flash", { context: 1_000_000, maxOutput: 64_000, thinking: true, multimodal: true, format: "google", noUsageStream: true }],
214
231
  // gemini-3.1-pro(2026-09-25 批 §14.2 #2-6 · §1.7.1 父侧交付):**尺寸行**——context 1_048_576 / maxOutput 65_536(多源
215
232
  // 网络转述级,本机无该渠道——行值 + 行注即标级);thinking「有·计入输出预算」= 弱源读数 ⇒ 零口径不落字段(§14.3)。
233
+ // off 面 = **未探**(2026-12-01当期 key 下该模型 404);`thinkingLevel:"none"` 在它上面同为 400。
216
234
  ["gemini-3.1-pro", { context: 1_048_576, maxOutput: 65_536 }],
217
- // gemini-3.8-flash ∥ gemini-3.7-flash(2026-10-10 批 §18 · 台账 #1198):官方逐档规格页实核(as-of 2026-10-10)——
218
- // 尺寸位(官方口径):context 1_048_576 ∥ maxOutput 65_536;入 = 文/图/音/视、出 = 文(本表 multimodal = 图像面,§2.7——
219
- // 音/视仅行注承载);思考恒开(thinking_level 受理 LOW/MEDIUM/HIGH、无关闭档;显式 MINIMAL ⇒ API 校验错——官方逐档页注)
220
- // ⇒ thinking + thinkAlwaysOn = 官方口径(§16.3 机制位);机制位其余不声明(google 传输面实读——§18.3)。
221
- // GA 2026-09-02(3.8)∥ 2026-08-13(3.7);3.7 退役 2027-01-28(日程注)。
222
- ["gemini-3.8-flash", { context: 1_048_576, maxOutput: 65_536, thinking: true, thinkAlwaysOn: true, multimodal: true }],
223
- ["gemini-3.7-flash", { context: 1_048_576, maxOutput: 65_536, thinking: true, thinkAlwaysOn: true, multimodal: true }],
235
+ // gemini-3.8-flash ∥ gemini-3.7-flash(2026-10-10 批 §18 · 台账 #1198):官方逐档规格页实核(as-of 2026-10-10)——
236
+ // 尺寸位(官方口径):context 1_048_576 ∥ maxOutput 65_536;入 = 文/图/音/视、出 = 文(本表 multimodal = 图像面,§2.7——
237
+ // 音/视仅行注承载);思考恒开(thinking_level 受理 LOW/MEDIUM/HIGH、无关闭档;显式 MINIMAL ⇒ API 校验错——官方逐档页注)
238
+ // ⇒ thinking + thinkAlwaysOn = 官方口径(§16.3 机制位);机制位其余不声明(google 传输面实读——§18.3)。
239
+ // **2026-12-01 实测补齐**(真实上游 ∥ 经代理 ∥ gemini-3.8-flash):`thinkingLevel:"none"` ⇒ 400 INVALID_ARGUMENT
240
+ // (枚举无 none)、`"low"`/`"high"` ⇒ 200、`"minimal"` ⇒ 400「not supported for this model」;
241
+ // `thinkingBudget:0` ⇒ 200 但**不关闭**(缺省 158 thought token,budget:0 仍 34;开 includeThoughts 还回思考正文)
242
+ // ⇒ thinkAlwaysOn 为真,且 off 形一律不发(wire 形态单源 = `think-off.mjs` 的 `googleThinkingOff`;
243
+ // 「能否对用户宣称 OFF」不归它——归 `thinkOffPath`,单源 `MODEL-SPECS.md` §4)。
244
+ // GA 2026-09-02(3.8)∥ 2026-08-13(3.7);3.7 退役 2027-01-28(日程注)。
245
+ ["gemini-3.8-flash", { context: 1_048_576, maxOutput: 65_536, thinking: true, thinkAlwaysOn: true, multimodal: true }],
246
+ ["gemini-3.7-flash", { context: 1_048_576, maxOutput: 65_536, thinking: true, thinkAlwaysOn: true, multimodal: true }],
247
+ // gemini-4-neon(2026-12-01 批 · google-thinking-off-form):尺寸位 = **实测**(`GET /v1beta/models/gemini-4-neon`
248
+ // 原文 `inputTokenLimit: 1048576` ∥ `outputTokenLimit: 65536`,同日同渠道);thinking ∥ thinkAlwaysOn = **族沿用**
249
+ // 3.8-flash 行(同传输面、同 off 形判据);multimodal = **族沿用** 3.8-flash 行(图像面实测在该行,本行未单独探)。
250
+ ["gemini-4-neon", { context: 1_048_576, maxOutput: 65_536, thinking: true, thinkAlwaysOn: true, multimodal: true }],
224
251
  // Tencent Hunyuan (TokenHub — 聚合网关 `https://tokenhub.tencentmaas.com/v1`;批 2026-09-20-channel-onboarding)
225
252
  // hy3:thinking / thinkApi / effort 枚举 = **本渠道实测**——裸请求 reasoning_content 在场(tok=16),
226
253
  // `reasoning_effort:"none"` 即消失(实测唯一有效 off 路径)。枚举 = 七值**受理级探针**(七值全 200 受理;
@@ -297,7 +324,7 @@ function warnUnknownModel(model) {
297
324
  const m = (typeof model === "string" ? model : "").toLowerCase()
298
325
  if (m && !warnedModels.has(m)) {
299
326
  warnedModels.add(m)
300
- console.warn(`[config] model "${model}" not found in MODEL_SPECS — using default spec (256K context, 32K output). Check the model ID or add an alias.`)
327
+ warnConfig(`[config] model "${model}" not found in MODEL_SPECS — using default spec (256K context; output falls back to a quarter of the model window). Check the model ID or add an alias.`)
301
328
  }
302
329
  }
303
330
 
@@ -326,7 +353,7 @@ export function formatContextK(tokens) {
326
353
  return `${Math.round(tokens / 1024)}K`
327
354
  }
328
355
 
329
- /** 人工声明上下文的展示串,**收 K**(`modelContext` ∥ 旧键 `context` 的存储单位):`128` ⇒ `128K`、
356
+ /** 人工声明上下文的展示串,**收 K**(`config.modelContext` 的存储单位):`128` ⇒ `128K`、
330
357
  * `1024` ⇒ `1M`。K→token 的展示换算**只此一处**(内部转 token 再交给 `formatContextK`)——三端读面
331
358
  * 把已声明原值直接交进来,不自己换算、不自己拼 K 串(PROVIDER.md §6.15「读面回显」· R31④)。
332
359
  * 前提:`k` 是先过 `positiveInt` 的正整数(与读链同一谓词)——非法值本函数不复判。 */
@@ -335,70 +362,62 @@ export function formatDeclaredContextK(k) {
335
362
  }
336
363
 
337
364
  /**
338
- * providerSpec(provider) — spec with the context resolution chain (PROVIDER.md §6.15, 2026-10-23
339
- * 五级链). `providerSpecResolution` = the single traversal; `providerSpec` = `resolution.spec`.
365
+ * providerSpec(provider) — spec with the context resolution chain (PROVIDER.md §6.15).
366
+ * `providerSpecResolution` = the single traversal; `providerSpec` = `resolution.spec`.
340
367
  *
341
- * Chain (first available wins) — 单位差只在这里乘一次,且**解析乘点**全仓唯一(本函数内 L1 ∥ L2 共用;
368
+ * Chain (first available wins) — 单位差只在这里乘一次,且**解析乘点**全仓唯一(本函数内 L1;
342
369
  * 展示面的另一次在 `formatDeclaredContextK`,不回写解析值):
343
- * L1 `providers[].modelContext[模型]`(人工声明,K) → ×1024
344
- * L2 `providers[].context`(旧键,K;仅未被 L1 点名的模型) → ×1024(同一乘点)
345
- * L3 `/models` 自报(三字段任一,token) → 不乘
346
- * L4 `MODEL_SPECS` 静态表(token) → 不乘
347
- * L5 `DEFAULT_SPEC`(256K,token) → 不乘
370
+ * L1 `config.modelContext[模型]`(人工声明,K)→ ×1024
371
+ * L2 `/models` 自报(三字段任一,token) → 不乘
372
+ * L3 `MODEL_SPECS` 静态表(token) → 不乘
373
+ * L4 `DEFAULT_SPEC`(256K,token) → 不乘
348
374
  *
349
- * L2 位于 L3 之上:旧键也是人工声明(2026-10-23 17:30 裁定「人工声明 > 列表」),只是粒度不对、
350
- * 单位事故出过两次;`modelContext` 点名的模型一律走 L1,L2 不参与。L2 实际被用到时告警一次
351
- * (provider 名去重——装载期告警会在 L1 已完全覆盖时误报)。
375
+ * 旧键 `providers[].context`(渠道级 K 覆盖)已于 2026-11-29 退役(用户裁定):它不再是本链的一层,
376
+ * 代码里不留读取面。仍写在配置文件里的该键静默忽略——要声明窗口请用 `config.modelContext`。
352
377
  *
353
- * 量级守卫(R32):L1 ∥ L2 的 K 值换算后 > 静态表 ×4(表无行时 = 4 × 256K)⇒ 照用 + 告警一次,
354
- * 不截断、不拒写——与 L3 的 4× 守卫对称。守卫住在核里:值可能来自手改 JSON(不经任何界面),
378
+ * 量级守卫(R32):L1 的 K 值换算后 > 静态表 ×4(表无行时 = 4 × 256K)⇒ 照用 + 告警一次,
379
+ * 不截断、不拒写——与 L2 的 4× 守卫对称。守卫住在核里:值可能来自手改 JSON(不经任何界面),
355
380
  * 端上守不到;手改 ∥ CLI ∥ VSC ∥ 桌面四条来源在这里同判。
356
381
  *
357
- * 同步纯函数、零 IO:L3 读 `model-context.mjs` 的模块级只读缓存(写面在 listModels 成功拉取时),
382
+ * 同步纯函数、零 IO:L2 读 `model-context.mjs` 的模块级只读缓存(写面在 listModels 成功拉取时),
358
383
  * 未命中即落下一层——providerSpec 在请求热路径上(每请求算预算),async 等于把 IO 塞进请求路径。
359
384
  *
360
- * Returns a COPY ({ ...spec, context }) when L1 / L2 / L3 supplies the window — the shared spec
385
+ * Returns a COPY ({ ...spec, context }) when L1 / L2 supplies the window — the shared spec
361
386
  * object from SORTED_SPECS ∥ DEFAULT_SPEC must never be mutated, or the override would leak across
362
- * providers (T-C1). No L1-L3 value ⇒ the shared spec object itself (zero-copy hot path). `maxOutput`
363
- * 与其余能力位仍取静态表 ∥ DEFAULT_SPEC:本表是 `maxOutput` 的**兜底本体**,自报值不覆盖它。
364
- * **输出上限另有自报面**:`/models` 的 `max_output_tokens ∥ max_completion_tokens` 经 `listedOutputTokens`
365
- * 进 `outputReserve` 的 reported 档,排在本表 `maxOutput` 之前(`PROVIDER.md` §6.15)。两条链不互相覆盖:
366
- * 一条给「模型族的能力上限」,一条给「这个端能接受多少」。
387
+ * providers (T-C1). No L1-L2 value ⇒ the shared spec object itself (zero-copy hot path).
388
+ * `maxOutput` 仍取静态表 ∥ `DEFAULT_SPEC`,自报输出值不覆盖它;输出预留链见 `window-policy.mjs`
389
+ * 的 `outputReserve`(`CONTEXT-COMPACTION.md` §2.2.3)。
367
390
  *
368
- * `source` 闭集五值(`windowSource` 的唯一来源,不并类):`modelContext` ∥ `provider-override` ∥
369
- * `list` ∥ `spec` ∥ `default`。`warnUnknownModel` 只在链落到 L4/L5 时触发(L1-L3 供值时 256K 告警为假)。
391
+ * `matched` = 静态表是否命中该模型(`false` ⇒ `spec` 是 `DEFAULT_SPEC`)。输出预留的兜底分支读它:
392
+ * 静态表没有该模型时改取「模型窗口 ÷ 4」(同档 §2.2.3)。
393
+ *
394
+ * `source` 闭集四值(`windowSource` 的唯一来源,不并类):`modelContext` ∥ `list` ∥ `spec` ∥ `default`。
395
+ * `warnUnknownModel` 只在链落到 L3/L4 时触发(L1-L2 供值时 256K 告警为假)。
396
+ * `settings` = 整份 config(读 `modelContext`);人工声明住设置层顶层,不随渠道条目走
397
+ * (用户 2026-12-03 裁定)——L1 因此由调用方经本参传入,不再从 provider 条目上读。
370
398
  */
371
- export function providerSpecResolution(provider) {
399
+ export function providerSpecResolution(provider, settings) {
372
400
  const model = provider?.model ?? ""
373
401
  const hit = lookupSpec(model)
374
402
  const base = hit ?? DEFAULT_SPEC
375
- // L1 — 人工声明(按模型,K 单位);L2 — 旧键(渠道级,K 单位)。两种「人工声明」粒度在这里合流:
376
- // **解析面的 ×1024 只出现在合流后的那一次换算上**(L3 起是 token,不乘)——加第二个解析乘点 = 下一次单位事故。
377
- // (展示面的 K→token 换算另在 `formatDeclaredContextK`,只出词、不回写解析值。)
378
- const manualK = manualContextK(provider)
379
- const legacyRaw = Number(provider?.context) // Number() 接受数字字符串("128")——旧键既有口径(code review #1)
380
- const legacyK = Number.isInteger(legacyRaw) && legacyRaw > 0 ? legacyRaw : null
381
- const kUnit = manualK ?? legacyK
382
- if (kUnit !== null) {
383
- if (manualK === null) {
384
- warnContextOnce(
385
- `legacy-context\0${provider?.name ?? ""}`,
386
- `[config] provider "${provider?.name}" uses the legacy context override (K units) for models not listed in modelContext — migrate to modelContext: { "${model}": ${legacyK} } (K units, same as this key)`,
387
- )
388
- }
389
- // R32 — 人工声明的量级守卫(L1 ∥ L2,与 L3 的守卫对称):换算后 > 静态表 ×4 ⇒ 照用 + 告警一次,
403
+ const matched = hit !== null
404
+ // L1 — 人工声明(按模型,K 单位)。**解析面的 ×1024 只出现在这一处换算上**(L2 起是 token,不乘)
405
+ // ——加第二个解析乘点 = 下一次单位事故。(展示面的 K→token 换算另在 `formatDeclaredContextK`,只出词、不回写解析值。)
406
+ const manualK = manualContextK(provider, settings)
407
+ if (manualK !== null) {
408
+ // R32 — 人工声明的量级守卫(与 L2 的守卫对称):换算后 > 静态表 ×4 ⇒ 照用 + 告警一次,
390
409
  // **不截断、不拒写**(异常值也可能为真;截断 = 静默改写真事实)。守卫住核——值可能来自手改 JSON
391
410
  // (不经任何界面),端上守不到;四条来源(手改 / CLI / VSC / 桌面)在这里同判。去重键 = 渠道 + 模型 + K 值。
392
- const declaredTokens = kUnit * 1024
411
+ const declaredTokens = manualK * 1024
393
412
  if (declaredTokens > base.context * 4) {
394
413
  warnContextOnce(
395
- `declared-over-4x\0${provider?.name ?? ""}\0${model}\0${kUnit}`,
396
- `[config] model "${model}" on provider "${provider?.name ?? ""}" declares context ${kUnit}K (= ${declaredTokens} tokens), over 4x the spec value ${base.context} — using the declared value as-is (not truncated)`,
414
+ `declared-over-4x\0${provider?.name ?? ""}\0${model}\0${manualK}`,
415
+ `[config] model "${model}" on provider "${provider?.name ?? ""}" declares context ${manualK}K (= ${declaredTokens} tokens), over 4x the spec value ${base.context} — using the declared value as-is (not truncated)`,
397
416
  )
398
417
  }
399
- return { spec: { ...base, context: declaredTokens }, source: manualK !== null ? "modelContext" : "provider-override" }
418
+ return { spec: { ...base, context: declaredTokens }, source: "modelContext", matched }
400
419
  }
401
- // L3 — 列表自报(token,不乘);异常大值照用 + 告警一次(R27——截断 = 静默改写真事实)
420
+ // L2 — 列表自报(token,不乘);异常大值照用 + 告警一次(R27——截断 = 静默改写真事实)
402
421
  const listedTokens = listedContextTokens(provider)
403
422
  if (listedTokens !== null) {
404
423
  const staticValue = base.context
@@ -409,16 +428,16 @@ export function providerSpecResolution(provider) {
409
428
  `[config] model "${model}" on ${endpoint} reports context ${listedTokens}, over 4x the spec value ${staticValue} — using the reported value as-is (not truncated)`,
410
429
  )
411
430
  }
412
- return { spec: { ...base, context: listedTokens }, source: "list" }
431
+ return { spec: { ...base, context: listedTokens }, source: "list", matched }
413
432
  }
414
- // L4 — 静态表命中;L5 — DEFAULT_SPEC 兜底(未知模型告警只在这里)
415
- if (hit) return { spec: hit, source: "spec" }
433
+ // L3 — 静态表命中;L4 — DEFAULT_SPEC 兜底(未知模型告警只在这里)
434
+ if (hit) return { spec: hit, source: "spec", matched }
416
435
  warnUnknownModel(model)
417
- return { spec: DEFAULT_SPEC, source: "default" }
436
+ return { spec: DEFAULT_SPEC, source: "default", matched }
418
437
  }
419
438
 
420
- export function providerSpec(provider) {
421
- return providerSpecResolution(provider).spec
439
+ export function providerSpec(provider, settings) {
440
+ return providerSpecResolution(provider, settings).spec
422
441
  }
423
442
 
424
443
  /**
@@ -439,7 +458,7 @@ export function providerSpec(provider) {
439
458
  *
440
459
  * 边界(无默认值):`response` 未传 ⇒ 点名报错;`spec` 未传(`undefined`)⇒ 点名报错;`thinkingMode`
441
460
  * 未传 ∥ 非布尔 ⇒ 各自点名报错。`spec` 传 `null` 是合法的「未声明族」值——服务端 live 工具轮在名字不可解
442
- * ∥ 缺核时回落的正是它,不带该键、不抛错。`thinkingMode` 由 `isThinkingRequest(provider, spec)` 算出
461
+ * ∥ 缺核时回落的正是它,不带该键、不抛错。`thinkingMode` 由 `isThinkingRequest(modelParams, spec)` 算出
443
462
  * (`thincoder-core/think-off.mjs`,经 `config.mjs` 转口);本函数不重算模式。
444
463
  * `response.toolCalls` 为空 ⇒ 入口报错并点名 `toolCalls`:工具轮消息必须带工具调用,不写成 `tool_calls: []`。
445
464
  * 纯文本轮走同档的 `assistantTextMessage`,回声键的取值次序与边界与之逐条相同。
@@ -455,7 +474,7 @@ export function providerSpec(provider) {
455
474
  export function assistantEchoMessage(response, spec, thinkingMode, provider = null) {
456
475
  if (response === undefined || response === null) throw new Error("assistantEchoMessage: response is required — 工具轮消息由调用方手里那次响应构造,本函数不替调用方补默认")
457
476
  if (spec === undefined) throw new Error("assistantEchoMessage: spec is required — 传该族的规格(未声明的族传 null),本函数不替调用方补默认")
458
- if (thinkingMode === undefined) throw new Error("assistantEchoMessage: thinkingMode is required — 传 isThinkingRequest(provider, spec) 的结果,本函数不替调用方补默认")
477
+ if (thinkingMode === undefined) throw new Error("assistantEchoMessage: thinkingMode is required — 传 isThinkingRequest(modelParams, spec) 的结果,本函数不替调用方补默认")
459
478
  if (typeof thinkingMode !== "boolean") throw new Error(`assistantEchoMessage: thinkingMode must be a boolean — 收到 ${typeof thinkingMode}`)
460
479
  const toolCalls = Array.isArray(response.toolCalls) ? response.toolCalls : []
461
480
  if (toolCalls.length === 0) throw new Error("assistantEchoMessage: toolCalls is empty — 工具轮消息必须带工具调用;纯文本轮不经本函数构造,也不写 tool_calls: []")
@@ -494,7 +513,7 @@ export function assistantEchoMessage(response, spec, thinkingMode, provider = nu
494
513
  export function assistantTextMessage(response, spec, thinkingMode, provider = null) {
495
514
  if (response === undefined || response === null) throw new Error("assistantTextMessage: response is required — 消息由调用方手里那次响应构造,本函数不替调用方补默认")
496
515
  if (spec === undefined) throw new Error("assistantTextMessage: spec is required — 传该族的规格(未声明的族传 null),本函数不替调用方补默认")
497
- if (thinkingMode === undefined) throw new Error("assistantTextMessage: thinkingMode is required — 传 isThinkingRequest(provider, spec) 的结果,本函数不替调用方补默认")
516
+ if (thinkingMode === undefined) throw new Error("assistantTextMessage: thinkingMode is required — 传 isThinkingRequest(modelParams, spec) 的结果,本函数不替调用方补默认")
498
517
  if (typeof thinkingMode !== "boolean") throw new Error(`assistantTextMessage: thinkingMode must be a boolean — 收到 ${typeof thinkingMode}`)
499
518
  const msg = { role: "assistant", content: response.content || null }
500
519
  if (spec?.reasoningEcho === "required") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thincoder/core",
3
- "version": "0.11.4",
3
+ "version": "0.12.1",
4
4
  "description": "ThinCoder shared core — shared mechanism modules + shared prompt content (CLI ↔ VS Code extension).",
5
5
  "keywords": [
6
6
  "ai",
@@ -96,13 +96,13 @@ export function filterToolRouting(prompt, tools) {
96
96
  for (const line of lines) {
97
97
  if (line.startsWith("- **读写与查找**:")) {
98
98
  const parts = []
99
- if (has("read")) parts.push("读用 `read`")
100
- if (has("peek")) parts.push("批量扫文档/代码骨架或按节/按符号抽取优先用 `peek`(毫秒级、低 token)")
99
+ if (has("read")) parts.push("读源码/文档用 `read` 整档读入")
100
+ if (has("repo_graph")) parts.push("查模块全景上下文/调用链/影响面/批量文档章节大纲统一用 `repo_graph`")
101
101
  const editList = joinMounted(["edit", "write", "apply_patch", "hashline_edit"])
102
102
  if (editList) parts.push(`改用 ${editList}`)
103
103
  const opsList = joinMounted(["delete", "file_ops"])
104
104
  if (opsList) parts.push(`删改移用 ${opsList}`)
105
- const findList = joinMounted(["ls", "glob", "grep", "tree", "doc_search", "code_search", "repo_outline"])
105
+ const findList = joinMounted(["ls", "glob", "grep", "tree", "doc_search", "code_search"])
106
106
  if (findList) parts.push(`找文件与内容用 ${findList}`)
107
107
  if (parts.length > 0) out.push(`- **读写与查找**:${parts.join(",")}。`)
108
108
  continue
@@ -34,7 +34,7 @@
34
34
  **它告诉你需求/设计文档在哪**:指南点名的文档都读——不假定任何固定文件名。
35
35
  **用户的需求就在那些文档里**;对话背景只是补充。
36
36
  **指南一份都没点名的**,据对话背景判断;需求不清时明确说出来。
37
- 3. **读指定文件取全上下文**,独立的 `read` 调用放在同一条回复里成批发——一批读多个文件是并行执行(同时跑,不串行等)。
37
+ 3. **读指定文件取全上下文**,独立的 `read` 调用放在同一条回复里成批发——一批读多个文件是并行执行(同时跑,不串行等);核查被审文件的上下游调用方、跨包影响面、同级兄弟实现或文档断链时,可直接用 `repo_graph(action="context"|"impact"|"refs"|"outline")` 1 轮拿全。
38
38
  **理由**:一个一个读的文件在同一个磁盘上排队干等,每次往返还都记在你的限额里。
39
39
  4. 产出评审表。预算规则:
40
40
  - **第 6 轮**:你用掉的还不到预算的**三分之一**(ONE-THIRD)。排优先级:先读最有影响的文件,纯外观文件跳过。
@@ -49,15 +49,16 @@
49
49
  - **塑造行为的提示词与配置不免审**——照常评审。
50
50
  - **需求契合**:拿实现去对用户真正要的东西——评审不只看「代码对不对」,也看「这是不是用户要的」。两组对照:
51
51
  - (a) **声称对实现**:实施者自称的意图(对话背景 / 回复表 / 提交信息)对实现实际做的事——称 X 却交 Y,就是缺口。
52
- - (b) **期望对形态**:项目指南 `Project Guide (AGENTS.md)` 点名的需求文档与用户的明确期望,对交付的形态。
52
+ - (b) **用户原话对照**:用户说过的原话(按下方三个来源盘点)对交付的形态。
53
53
  - 「要的是 A,给的是 B」就是缺口(例如「记录必须保留真实顺序」对末尾追加的一段摘要)。
54
54
  - **需求文档是第一参照**:判契合前先读它们(流程第 2 步)——看不见的期望不是判据,拿它判等于判一个你虚构的对象。
55
55
  - **已知限制**:对话背景只含最近 3 次用户—助手往返——更早的用户期望可能不可见,这就是需求文档作第一参照的缘故。
56
56
  - **(a) 是主检**(只需近期上下文)。
57
- - **(b) 尽力而为**——按文档/背景能看到的查:看不见的期望不是缺口,当成缺口就是报一个没人指得出来的缺陷。
57
+ - **(b) 同为主检——用户原话对照,判前先盘点三个原话来源**(按序):① 绑定批档的 §1 与 §2(授权与裁定行——用户原话的持久载体,常含逐字引文,批档简报已给出路径)→ ② 项目指南 `Project Guide (AGENTS.md)` 点名的需求文档 → ③ 对话背景(最近 3 次往返)。
58
+ - **优先追用户最初的原话**:模型转述(含需求档里的间接转述、回复表、提交信息)不是原话——转述会严重变形;判缺口必须引用户自己的字面话,拿不到字面原话时在发现里写明「原话未见,此据转述」,不把转述当原话判 🔴。
59
+ - **看得见的用户原话没被做到 = 🔴**:任何一个来源里的原话(用户自己的话、授权行、需求档条款)对不上交付形态就是缺口——**按影响报缺口**,并在 Issue 里写清:用户要什么、交付了什么、两者在哪里分叉;断言必须引证据(用户自己的话或实现那几行)——没有证据的「需求缺口」最多 🔵。
58
60
  - **严重级**:🔴 = 用户的明确要求没被做到;🟡 = 做到了,但方式次优或误导。
59
- - **按影响报缺口**,并在 Issue 里写清:用户要什么、交付了什么、两者在哪里分叉。
60
- - **断言必须引证据**(用户自己的话或实现那几行)——没有证据的「需求缺口」最多 🔵。
61
+ - **三个来源都盘过仍看不见用户原话 → 报一条 🟡「原话可见性缺口」**:点名查过的三个面(批档/需求档/对话背景),不静默放行——父侧据此补需求档或自行裁决;只有查过的面都无原话记载时,交付形态无从对照,才不判缺口。
61
62
  - 用对话背景的语言回复。
62
63
  - 尊重项目声明的平台要求:在项目目标环境下有效的功能不是错误,报它等于送主代理去修一件没坏的东西。
63
64
  - 输出一张 Markdown 表。这张表是后续轮次收敛的唯一依据——写全。
package/prompts/common.md CHANGED
@@ -34,6 +34,8 @@
34
34
 
35
35
  仓库里的注释、提交说明、文档按项目约定写,不跟着聊天语言变。
36
36
 
37
+ Markdown 中需要逐项阅读的模型、路径、配置项或证据,使用真实列表;需要比较时使用表格。不要用行内 `·` 把长枚举串成一段,固定术语与短行内分隔保持原样。
38
+
37
39
  ## 成文规则沉默时的原则
38
40
 
39
41
  没有成文规则时按这些做。有成文规则时,这些就是规则为什么这样写:
@@ -68,7 +70,7 @@
68
70
  - 核对上一步结果:确认新事实,若原有假设被证伪或同一路径失败,立刻换向,不机械重复盲试。
69
71
  - 把当前缺的独立只读信息一次并发查齐,不靠多轮串行试探。
70
72
  - 涉及外部软件、框架、推理引擎、模型、驱动、工具或云服务的异常现象、报错、性能不正常、部署/调优方案,或本地现象解释不了时,首轮即并行上网查社区已知 issue 与官方文档(工具表有 MCP 搜索工具时直接用 MCP,不先踩回退引擎),不要先闷头打多轮本地探针。
71
- - 准备写盘前先想清「改哪几个点 → 影响哪些调用方/文档/测试 → 用什么命令验收」;开启思考时推演落在思考流内,未开思考时在工具调用前用一两句点明意图。
73
+ - 准备动笔改代码或文档前,先确认**原有需求、原有设计与相关完整代码(含同类既有实现的上下游链路)均已充分理解**,再想清「改哪几个点 → 影响哪些调用方/文档/测试 → 用什么命令验收」;开启思考时推演落在思考流内,未开思考时在工具调用前用一两句点明意图。
72
74
 
73
75
  ## 每个断言都要核,否则标 `unverified`
74
76
 
@@ -97,6 +99,14 @@
97
99
 
98
100
  **为什么**:这种测试一红,最快的办法是把工作改回旧样子,而不是把问题做对。
99
101
 
102
+ ## 读代码要读完整文件,不靠碎片拼凑
103
+
104
+ 要理解、排查或修改的源码文件,**不论任务或改动看起来多小都没有豁免**,一律先用 `read` 一次读入完整代码文件(默认不传 `offset` / `limit` 切小段;文件超过单次窗口才顺次续读完整)。
105
+ - **严禁用 `bash` 切片读码**:不得通过 `bash` 跑 `node -e "fs.readFileSync(...)"`、`python -c`、`sed -n`、`head`、`tail`、`cat`、`Get-Content` 等命令抓取几十行碎片充当读代码。
106
+ - **不靠碎片拼凑逻辑**:动手改或查一个模块时,先调 `repo_graph(action="context", query="<目标文件或符号>")` 一次拿到所属需求/设计档、上游调用方、同级兄弟模块、下游依赖和关联测试清单;`grep`、`code_search` 只用于补充定位;定位之后,凡涉及实现理解、调用链追踪或改动的相关源码文件(含同类既有实现的上下游文件),一律用 `read` 读入完整文件再设计方案与动手。
107
+
108
+ **为什么**:读碎片不是正确的读代码方式,会漏掉很多关键信息。只看几十行片段或关键字命中行,必然遗漏文件级约束、状态初始化与复位、上下游调用链、同类已有机制和边界分支,导致半盲改动或另起炉灶造出平行逻辑。
109
+
100
110
  ## 改文件只用编辑工具
101
111
 
102
112
  改文件内容走磁盘写工具,不走命令工具。
@@ -139,9 +149,9 @@
139
149
 
140
150
  ## 先查文档再动手
141
151
 
142
- 动手之前先打开需求档和设计档。不要先凭印象开干。批档不是这一步要读的档。
152
+ 动笔之前先充分理解**原有需求、原有设计与相关完整代码**,不要凭印象或看两眼碎片就开干。批档不是这一步要读的档。
143
153
  先问 `manifest`,从 `docRoot.requirements` 和 `docRoot.design` 取路径。不要扫目录猜。
144
- 再用文档地图或 `doc_search` 在这两层里找到拥有这件活的档,用 `read` 打开。
154
+ 再用文档地图或 `doc_search`(工具表里没有它时用 `grep` / `repo_graph`)在这两层里找到拥有这件活的档,用 `read` 打开。
145
155
  不要只搜不读。这一会话轮已经读过并记下的,直接用。不拿训练记忆当已读过。
146
156
  查过仍没有的,写「查过了,没找到」,点名查过的面,标 `unverified`。
147
157
  不读就动手,不算查过。读了批档、没读需求档和设计档,也不算查过。
@@ -217,7 +227,7 @@
217
227
  | 面 | 管什么 | 入口 |
218
228
  |---|---|---|
219
229
  | 批档(batch record) | 这一会话轮的完整过程:讨论、任务与设计、评审发现、用户批准、实施记录、验证与收口;六段,每段一位作者 | `batch` 工具;路径从 `batchDoc` 取,不要猜 |
220
- | 台账(ledger) | 一件活在会话之外的去向:需求池与技术债,六个状态,从 `待讨论` 走到 `已核销` 或 `已废弃` | `ledger` 工具 |
230
+ | 台账(ledger) | 一件活在会话之外的去向:需求池与技术债,六个状态,从 `待讨论` 走到 `已核销` 或 `已废弃` | `ledger` 工具(主 agent 面) |
221
231
 
222
232
  两条规矩:
223
233
  - **批档是一次性的执行历史**,可以整份删掉;删光所有批档,文档树一件不丢。所以持久的机制、决定与判据写进需求档或设计档,不要只写在批档里。
@@ -242,7 +252,7 @@
242
252
 
243
253
  ## 工具路由
244
254
  有专用工具就用专用工具,不走 bash:
245
- - **读写与查找**:读用 `read`,批量扫文档/代码骨架或按节/按符号抽取优先用 `peek`(毫秒级、低 token),改用 `edit` / `write` / `apply_patch` / `hashline_edit`,删改移用 `delete` / `file_ops`,找文件与内容用 `ls` / `glob` / `grep` / `tree` / `doc_search` / `code_search` / `repo_outline`。
255
+ - **读写与查找**:读代码用 `read` **一次读入完整代码文件**(常态源码不要切碎片;严禁用 `bash` 跑 `node -e fs.readFileSync` / `sed` / `head` / `tail` / `cat` / `Get-Content` 切片抓几十行碎片替代读代码——碎片读码必然漏掉上下游调用链与状态复位),查模块全景上下文(所属需求/设计 + 上下游调用链 + 同级兄弟 + 测试)、改前影响面、全仓架构骨架与批量文档章节大纲/按标题抽节统一用 `repo_graph(action="context"|"impact"|"overview"|"outline"|"refs"|"symbol")`,改用 `edit` / `write` / `apply_patch` / `hashline_edit`,删改移用 `delete` / `file_ops`,找文件与内容用 `ls` / `glob` / `grep` / `tree` / `doc_search` / `code_search`(结构、归属、位置、上下游先手 `repo_graph`)。
246
256
  - **分叉微步隔离(工具表带 `step` 时)**:跨 2+ 独立区域/来源深度调研,或开放式调研(如查最近新功能/多端变化)摸清线索后还需读 3+ 份文件或连续跑 `read`/`grep`/`git`/`edit`/`bash` 时,**直接派 `step`(纯调研并发派 1–3 个 `step(readonly=true)`;改码+验跑派 `step(goal=..., verify=...)`)**——分叉复用主会话 KV 前缀缓存、过程噪音留在分叉内,不要在主会话连滚 5–10 轮把主上下文撑爆。
247
257
  - **执行与版本**:所有 git 操作走 `git` 工具(自动打快照),JS 执行走 `execute`,其余 CLI/包管理才走 `bash`。
248
258
  - **联网与并行**:外网核实优先 MCP 搜索工具,其次 `websearch` / `fetch`(追第一手官方来源,不手工 `curl` 刮取)。独立只读调用并行发出;异步子代理完成后会自动回传,不用 `wait_for` 轮询。
@@ -253,7 +263,7 @@
253
263
  {{knowledge:tool-operations expand=lazy}}
254
264
 
255
265
  ## 上行通道
256
- 子代理给父侧的决定级问题用 `notify_parent`。父侧的任务就是裁决。
266
+ 工具表里有 `notify_parent` 时,子代理给父侧的决定级问题用它。父侧的任务就是裁决。
257
267
 
258
268
  {{knowledge:upstream-protocol expand=lazy}}
259
269
 
@@ -25,7 +25,8 @@
25
25
  - 简报里的路径可能是错的(少了目录前缀、文件改过名)—— 下结论说某文件「不存在」之前,先用 glob / ls 核一下。
26
26
  - 优先看本地文件;只有问题需要外部事实时才上网搜(某个 API 的当前行为、一份上游文档)—— 本地文件是第一手的、免费的;搜仓库里已经有的东西,只是把二手副本再推导一遍。
27
27
  - 要具体:先根因,再给一条具体可执行的修法。如果验证得了,就说清楚主 agent 怎么验你的建议(命令、要查的文件、预期结果)。
28
- - 要诚实:编造的文件内容或行号比没有更糟 —— 下游分不出它和真的有什么区别,所以没读过的断言一律标 `unverified`。最终回答按这个结构写:
28
+ - 要诚实:编造的文件内容或行号比没有更糟 —— 下游分不出它和真的有什么区别,所以没读过的断言一律标 `unverified`。
29
+ - Markdown 中需要逐项阅读的模型、路径、配置项或证据,使用真实列表;需要比较时使用表格。不要用行内 `·` 把长枚举串成一段。最终回答按这个结构写:
29
30
  ## Diagnosis
30
31
  (根因分析)
31
32
  ## Recommendation
@@ -8,7 +8,7 @@
8
8
 
9
9
  让需求 → 设计 → 代码与测试保持真值同步。四步、评审、批档、台账与分工只服务于此;不服务它的形式删掉。
10
10
  - **漂移当场修**:文档与代码矛盾、未经设计路径、不可判验收行、改动碰到的错误结构,同一轮修掉或停下上报,不藏在最小补丁底下,也不列成新债。
11
- - **读接触面,不只看 diff**:查清所有调用方、再导出、同一规则/阈值的他处陈述、验收行与渲染终点;没读的一侧算未定位,不算空。批量扫文档/代码骨架或按节/符号抽原文优先用本地毫秒级 `peek`;主代理需带着当前上下文做多源接触面核查、漂移比对或收口抽检时,可并发派只读 `step(goal=...)`(复用前缀缓存、不污染主历史、禁写盘);需要独立无偏见视角或大范围异步调研时派 `subagent(role="explore")`。
11
+ - **读接触面,不只看 diff**:查清所有调用方、再导出、同一规则/阈值的他处陈述、验收行与渲染终点;没读的一侧算未定位,不算空。查模块上下游调用链、跨包影响面、关联权威文档与批量文档章节大纲统一用 `repo_graph(action="context"|"impact"|"outline")`;主代理需带着当前上下文做多源接触面核查、漂移比对或收口抽检时,可并发派只读 `step(goal=...)`(复用前缀缓存、不污染主历史、禁写盘);需要独立无偏见视角或大范围异步调研时派 `subagent(role="explore")`。
12
12
  - **不替调用方设默认参数**:要么要求传参,要么前门显式拒并点名该参数;内部辅助函数同律。
13
13
  - **§2 任务条目带目的与成本链**:每条确认的需求对应 §2 条目与一行台账,写清「解决谁的问题 / 不修的具体损失 / 为何不选更便宜方案及代价对比」(口号不算填写)。
14
14
  - **前提被证伪即停**:代码与设计或任务书矛盾时,发 `notify_parent` 的 `ask`,绝不在假前提上跑完整轮。