@thincoder/core 0.11.1 → 0.11.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 (333) hide show
  1. package/CHANGELOG.md +46 -2
  2. package/advisor/convergence.mjs +34 -3
  3. package/advisor/loop.mjs +42 -10
  4. package/advisor/messages.mjs +42 -25
  5. package/advisor/project-context.mjs +171 -42
  6. package/advisor/run.mjs +7 -4
  7. package/advisor.mjs +29 -43
  8. package/agent/batch-attribution.mjs +87 -0
  9. package/agent/batch-changed-surface.mjs +129 -0
  10. package/agent/completion.mjs +44 -3
  11. package/agent/dispatch-gates.mjs +6 -0
  12. package/agent/dispatch.mjs +8 -3
  13. package/agent/family-tools.mjs +27 -12
  14. package/agent/helpers.mjs +122 -1
  15. package/agent/offload.mjs +25 -29
  16. package/agent/post-turn.mjs +24 -10
  17. package/agent/record-results.mjs +18 -1
  18. package/agent/run-stages.mjs +77 -32
  19. package/agent/run-start.mjs +37 -0
  20. package/agent/setup-reminders.mjs +9 -2
  21. package/agent/setup.mjs +24 -11
  22. package/agent/spawn-child.mjs +38 -1
  23. package/agent/timers.mjs +5 -3
  24. package/agent/turn-loop.mjs +30 -5
  25. package/agent/turn-projection.mjs +386 -0
  26. package/agent/turn-task-state.mjs +274 -0
  27. package/agent/turn-tool-process.mjs +168 -0
  28. package/agent/write-gate-ledger.mjs +569 -0
  29. package/agent/write-gate.mjs +29 -352
  30. package/agent-tools/advisor-async.mjs +29 -169
  31. package/agent-tools/advisor-launch.mjs +178 -0
  32. package/agent-tools/advisor-settle.mjs +28 -1
  33. package/agent-tools/advisor.mjs +36 -47
  34. package/agent-tools/audit-block.mjs +6 -6
  35. package/agent-tools/batch-closeout.mjs +273 -35
  36. package/agent-tools/batch-gate.mjs +142 -342
  37. package/agent-tools/batch-ledger-bind.mjs +226 -17
  38. package/agent-tools/batch-ledger-view.mjs +109 -0
  39. package/agent-tools/batch-lifecycle.mjs +169 -46
  40. package/agent-tools/batch-paths.mjs +29 -8
  41. package/agent-tools/batch-record-write.mjs +417 -0
  42. package/agent-tools/batch-regions.mjs +215 -0
  43. package/agent-tools/batch-reopen.mjs +23 -11
  44. package/agent-tools/batch-segment-vocab.mjs +379 -0
  45. package/agent-tools/batch-skeleton.mjs +192 -239
  46. package/agent-tools/batch-supersede.mjs +232 -0
  47. package/agent-tools/batch-tier-gate.mjs +297 -0
  48. package/agent-tools/batch.mjs +182 -439
  49. package/agent-tools/consult.mjs +7 -4
  50. package/agent-tools/context.mjs +44 -17
  51. package/agent-tools/design-review-record.mjs +225 -0
  52. package/agent-tools/design-slots.mjs +1 -1
  53. package/agent-tools/design-token.mjs +279 -81
  54. package/agent-tools/doc-check.mjs +43 -33
  55. package/agent-tools/doc-graph.mjs +140 -0
  56. package/agent-tools/eng.mjs +9 -8
  57. package/agent-tools/escalate-async.mjs +2 -2
  58. package/agent-tools/manifest.mjs +34 -18
  59. package/agent-tools/read-history.mjs +112 -11
  60. package/agent-tools/review-facts.mjs +10 -3
  61. package/agent-tools/settings.mjs +23 -2
  62. package/agent-tools/spawn-gates.mjs +9 -8
  63. package/agent-tools/ssh-session.mjs +2 -2
  64. package/agent-tools/ssh-text.mjs +155 -0
  65. package/agent-tools/ssh-transport.mjs +19 -148
  66. package/agent-tools/subagent-actions-query.mjs +10 -6
  67. package/agent-tools/subagent-async.mjs +8 -9
  68. package/agent-tools/subagent-brief.mjs +76 -0
  69. package/agent-tools/subagent-design-token.mjs +168 -0
  70. package/agent-tools/subagent-run.mjs +1 -1
  71. package/agent-tools/subagent-scheduler.mjs +4 -4
  72. package/agent-tools/subagent-spawn.mjs +90 -110
  73. package/agent-tools/subagent.mjs +11 -10
  74. package/agent-tools/taskbook-block.mjs +94 -0
  75. package/agent-tools/timer.mjs +12 -8
  76. package/agent-tools/verify.mjs +13 -4
  77. package/agent-tools.mjs +7 -3
  78. package/agent.mjs +20 -1
  79. package/attachments.mjs +3 -3
  80. package/browser/actions.mjs +9 -3
  81. package/browser/cdp.mjs +45 -17
  82. package/browser/launch.mjs +25 -43
  83. package/browser/pool.mjs +299 -0
  84. package/browser/queue.mjs +2 -0
  85. package/browser/session-state.mjs +450 -0
  86. package/browser/session.mjs +127 -151
  87. package/browser/snapshot.mjs +89 -0
  88. package/client-identity.mjs +1 -1
  89. package/config-defaults.mjs +2 -1
  90. package/config-migrate.mjs +40 -0
  91. package/config-normalize.mjs +28 -2
  92. package/config-reload.mjs +59 -0
  93. package/config.mjs +62 -98
  94. package/context-degrade.mjs +38 -10
  95. package/context-echo.mjs +11 -0
  96. package/context.mjs +149 -83
  97. package/conventions.mjs +11 -9
  98. package/declaration.mjs +31 -5
  99. package/declared-repos.mjs +94 -0
  100. package/doc-check/doc-names.mjs +73 -0
  101. package/doc-check/doc-tokens.mjs +110 -0
  102. package/doc-check/existence.mjs +160 -0
  103. package/doc-check/index.mjs +309 -213
  104. package/doc-check/line-refs.mjs +27 -101
  105. package/doc-check/paragraph.mjs +218 -102
  106. package/doc-graph/anchors.mjs +474 -0
  107. package/doc-graph/doc-batch-face.mjs +59 -0
  108. package/doc-graph/doc-suffix.mjs +27 -0
  109. package/doc-graph/graph-tokens.mjs +160 -0
  110. package/doc-graph.mjs +778 -0
  111. package/explore-distill.mjs +11 -5
  112. package/i18n.mjs +1 -1
  113. package/instance-inbox-watch.mjs +272 -0
  114. package/instance-inbox.mjs +218 -0
  115. package/instance-registry.mjs +179 -0
  116. package/knowledge/README.md +3 -0
  117. package/knowledge/prompt-resources.md +6 -0
  118. package/ledger-close-proof.mjs +100 -49
  119. package/ledger-close.mjs +188 -0
  120. package/ledger-cmd.mjs +47 -91
  121. package/ledger-consistency.mjs +113 -0
  122. package/ledger-db.mjs +47 -15
  123. package/ledger-executors.mjs +1 -1
  124. package/ledger-tools.mjs +78 -19
  125. package/ledger-write-ops.mjs +130 -41
  126. package/ledger.mjs +1 -1
  127. package/manifest-discovery.mjs +3 -1
  128. package/manifest-schema.mjs +27 -5
  129. package/memory/schema.mjs +2 -2
  130. package/package.json +3 -1
  131. package/path-resolve.mjs +338 -57
  132. package/prompt-files.mjs +91 -1
  133. package/prompt-overlays.mjs +9 -6
  134. package/prompts/advisor-design.md +62 -21
  135. package/prompts/advisor-round1.md +34 -1
  136. package/prompts/advisor-round2.md +40 -7
  137. package/prompts/advisor-round3.md +39 -6
  138. package/prompts/common.md +14 -387
  139. package/prompts/consult-base.md +5 -1
  140. package/prompts/discipline-engineering.md +226 -51
  141. package/prompts/discipline-normal.md +4 -255
  142. package/prompts/knowledge/business-gates.md +22 -0
  143. package/prompts/knowledge/decision-quality.md +23 -0
  144. package/prompts/knowledge/doc-lookup.md +35 -0
  145. package/prompts/knowledge/document-writing.md +51 -0
  146. package/prompts/knowledge/documentation-evaluation.md +56 -0
  147. package/prompts/knowledge/evidence-discipline.md +57 -0
  148. package/prompts/knowledge/normal-coding-workflow.md +104 -0
  149. package/prompts/knowledge/normal-delivery-collaboration.md +108 -0
  150. package/prompts/knowledge/normal-work-management.md +57 -0
  151. package/prompts/knowledge/product-security.md +23 -0
  152. package/prompts/knowledge/project-records.md +62 -0
  153. package/prompts/knowledge/tool-advisor.md +29 -0
  154. package/prompts/knowledge/tool-apply-patch.md +18 -0
  155. package/prompts/knowledge/tool-bash.md +39 -0
  156. package/prompts/knowledge/tool-batch-eng-coder.md +12 -0
  157. package/prompts/knowledge/tool-batch-eng-designer.md +12 -0
  158. package/prompts/knowledge/tool-batch-review.md +12 -0
  159. package/prompts/knowledge/tool-batch.md +80 -0
  160. package/prompts/knowledge/tool-browser.md +57 -0
  161. package/prompts/knowledge/tool-code-search.md +4 -0
  162. package/prompts/knowledge/tool-consult-start.md +12 -0
  163. package/prompts/knowledge/tool-consult-stop.md +6 -0
  164. package/prompts/knowledge/tool-context.md +6 -0
  165. package/prompts/knowledge/tool-delete.md +17 -0
  166. package/prompts/knowledge/tool-doc-check.md +70 -0
  167. package/prompts/knowledge/tool-doc-graph-read.md +20 -0
  168. package/prompts/knowledge/tool-doc-graph.md +49 -0
  169. package/prompts/knowledge/tool-doc-search.md +6 -0
  170. package/prompts/knowledge/tool-edit.md +38 -0
  171. package/prompts/knowledge/tool-eng.md +2 -0
  172. package/prompts/knowledge/tool-execute.md +16 -0
  173. package/prompts/knowledge/tool-fetch.md +12 -0
  174. package/prompts/knowledge/tool-file-ops.md +16 -0
  175. package/prompts/knowledge/tool-get-current-time.md +7 -0
  176. package/prompts/knowledge/tool-git-read.md +19 -0
  177. package/prompts/knowledge/tool-git.md +29 -0
  178. package/prompts/knowledge/tool-glob.md +15 -0
  179. package/prompts/knowledge/tool-goal.md +8 -0
  180. package/prompts/knowledge/tool-grep.md +18 -0
  181. package/prompts/knowledge/tool-hashline-edit.md +14 -0
  182. package/prompts/knowledge/tool-insert-after.md +15 -0
  183. package/prompts/knowledge/tool-instance-list.md +6 -0
  184. package/prompts/knowledge/tool-instance-send.md +10 -0
  185. package/prompts/knowledge/tool-knowledge.md +18 -0
  186. package/prompts/knowledge/tool-ledger-read.md +35 -0
  187. package/prompts/knowledge/tool-ledger.md +42 -0
  188. package/prompts/knowledge/tool-lint.md +16 -0
  189. package/prompts/knowledge/tool-ls.md +13 -0
  190. package/prompts/knowledge/tool-lsp.md +11 -0
  191. package/prompts/knowledge/tool-main-history.md +2 -0
  192. package/prompts/knowledge/tool-manifest-read.md +14 -0
  193. package/prompts/knowledge/tool-manifest.md +31 -0
  194. package/prompts/knowledge/tool-memory-read.md +20 -0
  195. package/prompts/knowledge/tool-memory.md +15 -0
  196. package/prompts/knowledge/tool-notify-parent.md +12 -0
  197. package/prompts/knowledge/tool-operations.md +114 -0
  198. package/prompts/knowledge/tool-peer-instances.md +2 -0
  199. package/prompts/knowledge/tool-plan.md +6 -0
  200. package/prompts/knowledge/tool-process-read.md +13 -0
  201. package/prompts/knowledge/tool-process.md +15 -0
  202. package/prompts/knowledge/tool-question.md +16 -0
  203. package/prompts/knowledge/tool-read-history-batch.md +22 -0
  204. package/prompts/knowledge/tool-read-history.md +36 -0
  205. package/prompts/knowledge/tool-read-image.md +11 -0
  206. package/prompts/knowledge/tool-read.md +21 -0
  207. package/prompts/knowledge/tool-recent-changes.md +6 -0
  208. package/prompts/knowledge/tool-repo-outline.md +4 -0
  209. package/prompts/knowledge/tool-settings-read.md +12 -0
  210. package/prompts/knowledge/tool-settings.md +18 -0
  211. package/prompts/knowledge/tool-skill.md +6 -0
  212. package/prompts/knowledge/tool-ssh.md +52 -0
  213. package/prompts/knowledge/tool-subagent.md +59 -0
  214. package/prompts/knowledge/tool-task.md +12 -0
  215. package/prompts/knowledge/tool-team-ledger-read.md +11 -0
  216. package/prompts/knowledge/tool-team-ledger.md +11 -0
  217. package/prompts/knowledge/tool-timer.md +23 -0
  218. package/prompts/knowledge/tool-tree.md +14 -0
  219. package/prompts/knowledge/tool-verify.md +19 -0
  220. package/prompts/knowledge/tool-wait-for.md +25 -0
  221. package/prompts/knowledge/tool-websearch.md +19 -0
  222. package/prompts/knowledge/tool-write.md +9 -0
  223. package/prompts/knowledge/upstream-protocol.md +43 -0
  224. package/prompts/persona-eng-coder.md +21 -3
  225. package/prompts/persona-eng-designer.md +131 -169
  226. package/prompts/persona-engineering.md +142 -84
  227. package/prompts/persona-explore.md +1 -1
  228. package/prompts/persona-plan.md +5 -1
  229. package/prompts/subagent-base.md +2 -0
  230. package/provider/anthropic.mjs +6 -4
  231. package/provider/core.mjs +3 -2
  232. package/provider/errors.mjs +29 -4
  233. package/provider/google.mjs +24 -7
  234. package/provider/responses.mjs +3 -1
  235. package/provider-flows.mjs +2 -2
  236. package/session-index-build.mjs +1 -1
  237. package/session-index-pass.mjs +1 -1
  238. package/session-index-query.mjs +1 -1
  239. package/session-index.mjs +1 -1
  240. package/session-lifecycle.mjs +72 -17
  241. package/session-slot-write.mjs +37 -5
  242. package/session.mjs +24 -8
  243. package/skip-dirs.mjs +2 -2
  244. package/team-ledger.mjs +13 -9
  245. package/token-ttl.mjs +73 -4
  246. package/token-window.mjs +167 -33
  247. package/tool-docs/advisor.md +2 -27
  248. package/tool-docs/apply_patch.md +1 -15
  249. package/tool-docs/bash.md +2 -41
  250. package/tool-docs/batch-eng-coder.md +3 -0
  251. package/tool-docs/batch-eng-designer.md +3 -0
  252. package/tool-docs/batch-review.md +3 -0
  253. package/tool-docs/batch.md +2 -84
  254. package/tool-docs/browser.md +2 -49
  255. package/tool-docs/code_search.md +2 -2
  256. package/tool-docs/consult_start.md +2 -8
  257. package/tool-docs/consult_stop.md +2 -4
  258. package/tool-docs/context.md +1 -5
  259. package/tool-docs/delete.md +2 -17
  260. package/tool-docs/doc_check.md +2 -107
  261. package/tool-docs/doc_graph-read.md +3 -0
  262. package/tool-docs/doc_graph.md +3 -0
  263. package/tool-docs/doc_search.md +2 -4
  264. package/tool-docs/edit.md +1 -38
  265. package/tool-docs/eng.md +3 -1
  266. package/tool-docs/execute.md +2 -18
  267. package/tool-docs/fetch.md +2 -14
  268. package/tool-docs/file_ops.md +2 -18
  269. package/tool-docs/get_current_time.md +1 -6
  270. package/tool-docs/git-read.md +3 -0
  271. package/tool-docs/git.md +2 -35
  272. package/tool-docs/glob.md +2 -10
  273. package/tool-docs/goal.md +1 -6
  274. package/tool-docs/grep.md +2 -18
  275. package/tool-docs/hashline_edit.md +2 -15
  276. package/tool-docs/insert_after.md +2 -16
  277. package/tool-docs/instance_list.md +3 -0
  278. package/tool-docs/instance_send.md +3 -0
  279. package/tool-docs/knowledge.md +3 -0
  280. package/tool-docs/ledger-read.md +3 -0
  281. package/tool-docs/ledger.md +3 -8
  282. package/tool-docs/lint.md +2 -10
  283. package/tool-docs/ls.md +2 -11
  284. package/tool-docs/lsp.md +2 -9
  285. package/tool-docs/main_history.md +3 -1
  286. package/tool-docs/manifest-read.md +2 -8
  287. package/tool-docs/manifest.md +2 -35
  288. package/tool-docs/memory-read.md +3 -0
  289. package/tool-docs/memory.md +2 -20
  290. package/tool-docs/notify_parent.md +2 -13
  291. package/tool-docs/peer_instances.md +3 -1
  292. package/tool-docs/plan.md +1 -5
  293. package/tool-docs/process-read.md +3 -0
  294. package/tool-docs/process.md +2 -13
  295. package/tool-docs/question.md +3 -17
  296. package/tool-docs/read.md +2 -19
  297. package/tool-docs/read_history-batch.md +3 -0
  298. package/tool-docs/read_history.md +2 -18
  299. package/tool-docs/read_image.md +2 -9
  300. package/tool-docs/recent_changes.md +2 -2
  301. package/tool-docs/repo_outline.md +2 -2
  302. package/tool-docs/settings-read.md +3 -0
  303. package/tool-docs/settings.md +1 -12
  304. package/tool-docs/skill.md +2 -6
  305. package/tool-docs/ssh.md +1 -62
  306. package/tool-docs/subagent.md +2 -100
  307. package/tool-docs/task.md +1 -7
  308. package/tool-docs/team_ledger-read.md +3 -0
  309. package/tool-docs/team_ledger.md +3 -9
  310. package/tool-docs/timer.md +2 -19
  311. package/tool-docs/tree.md +2 -13
  312. package/tool-docs/verify.md +2 -12
  313. package/tool-docs/wait_for.md +2 -32
  314. package/tool-docs/websearch.md +2 -19
  315. package/tool-docs/write.md +2 -12
  316. package/tools/browser.mjs +52 -7
  317. package/tools/doc-write-gate.mjs +73 -0
  318. package/tools/edit-batch.mjs +170 -92
  319. package/tools/edit-diff.mjs +78 -62
  320. package/tools/edit-receipt.mjs +39 -0
  321. package/tools/execute.mjs +1 -1
  322. package/tools/file.mjs +16 -8
  323. package/tools/git.mjs +24 -9
  324. package/tools/index.mjs +6 -0
  325. package/tools/knowledge.mjs +143 -0
  326. package/tools/linter.mjs +3 -3
  327. package/tools/ops.mjs +3 -1
  328. package/tools/patch.mjs +123 -43
  329. package/tools/shared.mjs +28 -27
  330. package/tools/write-gate-params.mjs +31 -0
  331. package/tools/write-path.mjs +16 -4
  332. package/window-policy.mjs +203 -0
  333. package/doc-check/anchors.mjs +0 -235
@@ -0,0 +1,59 @@
1
+ /**
2
+ * config-reload.mjs — 运行中重读盘上渠道表(`docs/core/design/PROVIDER.md` §6.30)。
3
+ *
4
+ * 从 `thincoder-core/config.mjs` 抽出:该档落盘后越过 `docs/core/design/DOC-DISCIPLINE.md` §3.10 所定的 500 行,
5
+ * 抽法沿 §6.30 指的候选线——`reloadProviders` 整段移出,`config.mjs` 以
6
+ * re-export 保持导入面(形态同 `config-migrate.mjs` ∥ `config-io.mjs` 两次既有拆分)。
7
+ *
8
+ * 环:本档 import `config.mjs` 的 `loadConfig` ∥ `proxy.mjs` 的 `injectProxy`,而两者都反向指向
9
+ * `config.mjs`——两处都只在调用期取活绑定,模块求值期不触碰,故环安全(同 `proxy.mjs` 既有形态)。
10
+ */
11
+ import { loadConfig } from "./config.mjs"
12
+ import { injectProxy } from "./proxy.mjs"
13
+
14
+ /**
15
+ * 运行中重读盘上渠道表——`/model` 打开边界调用:「切的时候读」,不必重启。四步:
16
+ * ① 读盘(`loadConfig`,含它自带的老字段迁移写回——既有行为,本批不新增写盘);
17
+ * ② 准入判据由装载路径本身施加(`isUsableProviderEntry`,见 `thincoder-core/config-normalize.mjs`);
18
+ * 本档不重复应用谓词、也不造第二份丢弃记录——判据单源、丢弃载体单源都在装载那一步;
19
+ * ③ `injectProxy` 按当前 `config.proxy` 重算派生值 `proxyUri`;
20
+ * ④ 按 name 把会话态的 `_unavailable` 从旧表带到新表,再把**同一数组**赋给三个读点。
21
+ *
22
+ * **同一数组同赋值**:启动时 `agent.config.providersList` 与 `agent.config.providers` 本就是
23
+ * `loadConfig` 里那个数组(整表别名);只换一边就分叉——`thincoder-core/advisor/run.mjs` ∥
24
+ * `thincoder-core/agent-tools/subagent-async.mjs` 读的是 `providersList` 那一侧。
25
+ *
26
+ * **读失败 ⇒ `{ ok:false, error }`,绝不 throw、绝不退回旧表**:拿旧表当现况正是本缺陷的形状
27
+ * (盘上改了不生效,就是因为读的不是盘),所以调用方必须拒开列表并报错,内存态保持原样。
28
+ *
29
+ * 不动面(半量新鲜度,§6.30「前置」):`defaultModel` ∥ `agent.provider` ∥ `providerState` 仍是
30
+ * 启动时 `resolveProviderPlan` 解析的那份——替换运行态属运行面变更,不在本批暗改。
31
+ *
32
+ * @param agent 会话 agent(读 `agent.providers` 取会话态,写 `agent.providers` ∥ `agent.config.*`)
33
+ * @returns {{ ok: boolean, dropped: string[], error?: string }} dropped = 本次丢弃记录(一句一条)
34
+ */
35
+ export function reloadProviders(agent) {
36
+ let fresh
37
+ try {
38
+ fresh = loadConfig()
39
+ } catch (error) {
40
+ return { ok: false, error: error?.message ?? String(error), dropped: [] }
41
+ }
42
+ const dropped = Array.isArray(fresh.providersDropped) ? fresh.providersDropped : []
43
+ const providers = fresh.providersList
44
+ // 会话态按 name 合并且只带 truthy 标记:`_unavailable` 是探针写在内存里的
45
+ // (`thincoder-cli/src/tui/provider-admin.mjs`),盘上没有它,整表替换会把它冲掉——用户会看到
46
+ // 刚标过不可用的渠道又变回可用。
47
+ const previous = new Map((Array.isArray(agent.providers) ? agent.providers : []).filter((p) => p?.name).map((p) => [p.name, p]))
48
+ for (const provider of providers) {
49
+ if (previous.get(provider.name)?._unavailable) provider._unavailable = true
50
+ }
51
+ injectProxy(providers, fresh)
52
+ agent.providers = providers
53
+ agent.config ??= {}
54
+ agent.config.providersList = providers
55
+ agent.config.providers = providers
56
+ // 载体跟新:盘上改好了就没有丢弃 ⇒ 清掉(`/model` 表头据此消失);同一键、同形(string[])。
57
+ agent.config.providersDropped = dropped.length ? dropped : undefined
58
+ return { ok: true, dropped }
59
+ }
package/config.mjs CHANGED
@@ -14,7 +14,7 @@
14
14
  import { existsSync, readFileSync } from "node:fs"
15
15
  import { parseModelRef, resolveChannelModel, resolveProviderPlan, resolveRuntimeProvider, defaultModelReason } from "./model-ref.mjs"
16
16
  // 老形态迁移核(M7 v2——纯函数零依赖——本文件超 500 行硬限拆分,VSC 同构文件)
17
- import { migrateLegacyModelFields } from "./config-migrate.mjs"
17
+ import { migrateLegacyModelFields, resolveWorkMode } from "./config-migrate.mjs"
18
18
  import { expandHome } from "./expand-home.mjs"
19
19
  // 核内单一读写面 + 预设表(§2.5 #129 / #131——拆档以容纳 500 行硬限)
20
20
  import {
@@ -23,6 +23,7 @@ import {
23
23
  } from "./config-io.mjs"
24
24
 
25
25
  export { parseModelRef, resolveChannelModel, resolveProviderPlan, resolveRuntimeProvider, defaultModelReason, migrateLegacyModelFields }
26
+ export { WORK_MODES, resolveWorkMode, resolveSessionWorkMode, setConfigWorkMode } from "./config-migrate.mjs"
26
27
  export { PROVIDER_PRESETS, presetToEntry, configDir, configPath, _setConfigPathForTest, _resetConfigPathForTest }
27
28
  // 核内单一写盘执行体(已迁 `config-io.mjs`)——本档 re-export 保持既有导入面(§2.5 #131)。
28
29
  export { writeConfigAtomic }
@@ -43,94 +44,15 @@ export { specForModel, providerSpec, providerSpecResolution, specMatch, formatCo
43
44
  import { positiveInt, warnContextOnce } from "./model-context.mjs"
44
45
 
45
46
 
46
- // Window utilization ratio (CONTEXT-COMPACTION.md §6.2 / D-CC30 / §6.17 / D-CC32): auto threshold =
47
- // min(usableWindow(window, reserve), ⌊window × COMPACT_RATIO⌋) — reserve is the output budget
48
- // ACTUALLY sent as max_tokens (uncapped; §6.17 requestBudget is the single source). Rows with
49
- // reserve < 40% of the window land on the ratio term (line = 60.0% of the window); larger
50
- // reservations pull the line down to window − reserve — overflow-free outranks the ratio (the two
51
- // are mathematically exclusive once reserve ≥ 40%, §6.2). Headroom above the line absorbs injected
52
- // context (directory tree, git context, outline, project instructions, memory/doc search — 30–50K).
53
- const COMPACT_RATIO = 0.6
54
-
55
- /** Output reservation counted against the window: the value ACTUALLY sent as max_tokens —
56
- * explicit `provider.maxTokens` when set (the transport faces send it verbatim), else the spec
57
- * `maxOutput`, else 0. NOT capped: the old 25% cap reopened a residual band between the counted
58
- * reservation and the real output budget — messages could cross the true window while still below
59
- * the compaction line (2026-10-18 overflow 400: budget counted 250_000, 393_216 actually sent).
60
- * Single source = §6.17 requestBudget; this is its reserve face (advisor budget reuses it). */
61
- export function outputReserve(provider, spec) {
62
- const explicit = provider?.maxTokens
63
- return Number.isFinite(explicit) && explicit > 0 ? explicit : spec?.maxOutput ?? 0
64
- }
65
-
66
- /** Usable input window = window − output reservation. Degenerate guard: a reservation
67
- * ≥ the window is non-physical (no input could ever fit — e.g. `doubao-seed-2-1-turbo-260628`:
68
- * 256_000 window / 256_000 `maxOutput` (官方口径) ∥ the test harness&apos;s 1K window vs the
69
- * default spec); collapsing the budget to 0 would be instant `context_limit` death — the very
70
- * failure the reservation fold exists to prevent. Fall back to half the window.
71
- * (2026-10-06——收口核验捕获:advisor-loop-split B5a 红。) */
72
- export function usableWindow(context, reserve) {
73
- const ctx = context ?? 0
74
- const usable = ctx - reserve
75
- return usable > 0 ? usable : Math.floor(ctx / 2)
76
- }
77
-
78
- /** Request budget — single source for window ∥ actually-sent max_tokens ∥ compaction threshold ∥
79
- * overflow guard (CONTEXT-COMPACTION.md §6.17 / D-CC32). One formula, four consumer faces:
80
- * threshold (resolveCompactThreshold / per-run setup), the four transport faces (read ONLY
81
- * maxTokens), the stats budget line (agent-tools/context.mjs), the pre-send guard
82
- * (agent/run-stages.mjs). transport derives from provider.format ("anthropic" | "google" |
83
- * "responses" | default = OpenAI-compatible). Fields:
84
- * - window / windowSource: spec.context (the §6.15 chain — modelContext / legacy context /
85
- * /models self-report / static table / default — already resolved by providerSpec);
86
- * source = providerSpecResolution(provider).source — closed set { modelContext |
87
- * provider-override | list | spec | default }, passed through verbatim (no class merging).
88
- * - maxTokens / maxTokensSource: the value THIS transport writes into the request body —
89
- * anthropic always sends it (explicit ?? spec.maxOutput); the other three faces send only an
90
- * explicit provider.maxTokens, absent ⇒ undefined / "absent". Never a guard criterion
91
- * (undefined ⇒ NaN — §6.17 guard); the guard reads limit instead.
92
- * - reserve: maxTokens ?? spec.maxOutput — uncapped, always a number.
93
- * - usable: usableWindow(window, reserve) (degenerate half-window guard).
94
- * - threshold: min(usable, ⌊window × COMPACT_RATIO⌋) — the compaction trigger line.
95
- * - limit: window − reserve — hard prompt ceiling; the guard's ONLY numeric criterion field
96
- * (always a number; negative = any prompt overflows). `absent` rows (the transport sends no
97
- * max_tokens) take the floor max(window − reserve, threshold): only the degenerate
98
- * reserve ≥ window rows move (bare value 0 ⇒ every prompt would be rejected), and for
99
- * reserve < window threshold ≤ usable = window − reserve makes the floor a no-op. */
100
- export function requestBudget(provider, spec) {
101
- // windowSource = 五级链的同一次遍历出口(§6.15)——L1 / L3 命中也会如实报来源,不再二值猜。
102
- // 调用方传 spec(core.mjs 已算过 providerSpec)时窗口值用它,来源仍读 resolution(恒等映射,不并类)。
103
- const resolution = providerSpecResolution(provider)
104
- const resolved = spec ?? resolution.spec
105
- const window = resolved?.context ?? 0
106
- const windowSource = resolution.source
107
- const explicitRaw = Number(provider?.maxTokens)
108
- const explicit = Number.isFinite(explicitRaw) && explicitRaw > 0 ? explicitRaw : undefined
109
- const anthropicAlwaysSends = provider?.format === "anthropic"
110
- const maxTokens = explicit ?? (anthropicAlwaysSends ? resolved?.maxOutput ?? 0 : undefined)
111
- const maxTokensSource = explicit != null ? "explicit" : anthropicAlwaysSends ? "spec" : "absent"
112
- const reserve = maxTokens ?? resolved?.maxOutput ?? 0
113
- const usable = usableWindow(window, reserve)
114
- const threshold = Math.min(usable, Math.floor(window * COMPACT_RATIO))
115
- const bare = window - reserve
116
- return {
117
- window, windowSource, maxTokens, maxTokensSource, reserve, usable, threshold,
118
- // §6.17 地板:absent 档 reserve 可能 ≥ window(退化行,bare ≤ 0)——裸式下任何 prompt 都判真、
119
- // 该档永久发不出去;地板把它抬到 ≤ ⌊w/2⌋。非 absent 档逐位不变(仍是 bare)。
120
- limit: maxTokensSource === "absent" ? Math.max(bare, threshold) : bare,
121
- }
122
- }
123
-
124
- /** Derive compaction threshold; explicit is the value explicitly set in config file (takes priority),
125
- * otherwise auto = requestBudget().threshold (§6.17 single source — min(usable, ⌊window × 0.6⌋),
126
- * reserve uncapped). Second param accepts EITHER a model name string (pure spec lookup — compat shape,
127
- * no caller passes a string today) OR a provider object (providerSpec — the providers[].context
128
- * override in K units is honored, PROVIDER.md §15 T-C2). */
129
- export function resolveCompactThreshold(explicit, modelOrProvider) {
130
- if (explicit != null) return { value: explicit, auto: false }
131
- const provider = typeof modelOrProvider === "string" ? { model: modelOrProvider } : (modelOrProvider ?? {})
132
- return { value: requestBudget(provider).threshold, auto: true }
133
- }
47
+ // 预算族(`outputReserve` ∥ `usableWindow` ∥ `requestBudget` ∥ `policyBudget` ∥ `effectiveWindow` ∥
48
+ // `resolveCompactThreshold` ∥ `INJECT_HEADROOM_TOKENS` ∥ `RETAIN_CAP_TOKENS`)居 `window-policy.mjs`——`CONTEXT-COMPACTION.md` §2.1 ∥
49
+ // §2.2 把「窗口事实」与「窗口策略」两件事分开,本档越 500 行硬限按设计给的候选线抽出;以下 re-export
50
+ // 保既有导入面(同 `model-specs.mjs` 拆分形态)。`resolveCompactThreshold` 在本档装载期自用
51
+ // (auto 档派生 `compactThresholdResolved`——按本会话档位现算,tiny 档随之落在有效窗口上),故先 import 再转口。
52
+ import { resolveCompactThreshold } from "./window-policy.mjs"
53
+ export {
54
+ TINY_WINDOW_CAP, INJECT_HEADROOM_TOKENS, RETAIN_CAP_TOKENS, effectiveWindow, outputReserve, usableWindow, requestBudget, policyBudget, resolveCompactThreshold,
55
+ } from "./window-policy.mjs"
134
56
 
135
57
  /**
136
58
  * Bailian (阿里云百炼) host check — enable_thinking is a Bailian-only extension parameter;
@@ -142,7 +64,7 @@ export function isBailianHost(baseURL) {
142
64
  }
143
65
 
144
66
  /**
145
- * Resolve the Bailian `enable_thinking` switch for qwen hybrid-thinking models (PROVIDER.md §12).
67
+ * Resolve the Bailian `enable_thinking` switch for qwen hybrid-thinking models (`docs/core/design/PROVIDER.md` §6.12).
146
68
  * qwen3.x on Bailian defaults to thinking ON, so an explicit off must send enable_thinking:false
147
69
  * or the server silently keeps thinking. Whitelist: model name starts with "qwen" (excluding the
148
70
  * non-thinking qwen3-coder line) AND the provider points at a Bailian host.
@@ -160,7 +82,7 @@ export function resolveEnableThinking(provider, spec) {
160
82
  if (!isBailianHost(provider?.baseURL)) return undefined
161
83
  // 一致性分支(#1659):effort 档位有值且非 "none" ⇒ effort 赢(thinking on)。
162
84
  // 百炼约束:enable_thinking:false 时 reasoning_effort 必须为 "none",互斥即 400。
163
- // 压缩下行(context.mjs:203)显式 thinking:null 但继承 effort(v3 同源裁定)——
85
+ // 压缩下行(context.mjs 的 compressIfNeeded)显式 thinking:null 但继承 effort(v3 同源裁定)——
164
86
  // 无此分支则发出 {enable_thinking:false, reasoning_effort:"medium"} ⇒ 400 ⇒ 压缩三连败。
165
87
  if (provider.reasoningEffort && provider.reasoningEffort !== "none") return true
166
88
  if (provider.thinking === null) return false
@@ -169,11 +91,12 @@ export function resolveEnableThinking(provider, spec) {
169
91
  }
170
92
 
171
93
  // 加载期归一 / 清洗纯函数族已迁 `config-normalize.mjs`(§6.16.9 —— C1)——四个公共函数经本档
172
- // re-export 保持既有导入面;其余四个(sanitizeProviderHeaders ∥ sanitizeConsultModels ∥ 两枚
173
- // 一次性警告旗)只由 loadConfig 消费。
94
+ // re-export 保持既有导入面;其余六个(sanitizeProviderHeaders ∥ sanitizeConsultModels ∥
95
+ // isUsableProviderEntry ∥ providerDropReason ∥ 两枚一次性警告旗)只由 loadConfig 消费
96
+ // (`reloadProviders` 经 loadConfig 共用同一次判定,本档只转交,不另调)。
174
97
  import {
175
98
  sanitizeConsultModels, warnConsultModelsFiltered, sanitizeSubagentModel, sanitizeSubagentModels,
176
- warnSubagentModelsFiltered, sanitizeProviderHeaders, normalizeProxy, normalizeTeamSection,
99
+ warnSubagentModelsFiltered, sanitizeProviderHeaders, normalizeProxy, normalizeTeamSection, isUsableProviderEntry, providerDropReason,
177
100
  } from "./config-normalize.mjs"
178
101
  export { sanitizeSubagentModel, sanitizeSubagentModels, normalizeProxy, normalizeTeamSection }
179
102
 
@@ -209,6 +132,17 @@ export function promoteAgentViews(config) {
209
132
  return config
210
133
  }
211
134
 
135
+ /**
136
+ * 丢弃记录一句一条(`docs/core/design/PROVIDER.md` §6.29「丢弃要看得见」):`providers[18]: null`。
137
+ * 只有盘上下标 + 原因闭集四值之一——**绝不带条目内容**:载体是数据层,会进日志 ∥ 报错 ∥ 调试输出,
138
+ * 一条「有 apiKey 却缺 name」的条目若取 JSON,`sk-…` 就原样写进不需要它的地方。原因由
139
+ * `providerDropReason`(`thincoder-core/config-normalize.mjs`)给出——与准入判据同源,同一条目不会
140
+ * 在这里和装载分支各判出一种说法;下标让用户能找到要改的那一条。
141
+ */
142
+ function providerDropLine(index, reason) {
143
+ return `providers[${index}]: ${reason}`
144
+ }
145
+
212
146
  /**
213
147
  * Load configuration.
214
148
  * No env-var overrides — config.json is the single source of truth
@@ -237,13 +171,28 @@ export function loadConfig() {
237
171
  }
238
172
  }
239
173
 
174
+ // 渠道条目准入过滤(`docs/core/design/PROVIDER.md` §6.29):无名条目不进使用面——`name` 是渠道
175
+ // 唯一句柄(findProvider ∥ parseModelRef ∥ 会话槽 ∥ 选择器全按 name 匹配),无名条目既不可寻址
176
+ // 也不可被发送,留着只会让读它的地方失真:`/model` 的 `${p.name.padEnd(12)}` 直接抛
177
+ // `Cannot read properties of undefined (reading 'padEnd')`,19 个正常渠道被 1 条空条目连累。
178
+ // 过滤在整表别名 `merged.providersList = merged.providers` **之前**:别名之后没有第二个汇聚点,
179
+ // 漏一处就留一条不可寻址的条目在运行面。判据单源 = `isUsableProviderEntry`(装载 ∥ 重读共用)。
180
+ // 盘面处置 = 不重写被丢弃的那条(同节「零写盘」:它可能携用户已填的 apiKey ∥ baseURL)。
181
+ // 丢弃记录只写盘上下标 + 原因闭集(条目内容不进载体——载体是数据层,会进日志与调试输出)。
182
+ const droppedProviders = []
183
+ const providers = Array.isArray(config.providers)
184
+ ? config.providers.flatMap((p, index) => {
185
+ if (isUsableProviderEntry(p)) return [sanitizeProviderHeaders({ ...p })]
186
+ droppedProviders.push(providerDropLine(index, providerDropReason(p)))
187
+ return []
188
+ })
189
+ : []
190
+
240
191
  const merged = {
241
192
  ...DEFAULTS,
242
193
  ...config,
243
194
  defaultModel: typeof config.defaultModel === "string" && config.defaultModel.trim() ? config.defaultModel : null,
244
- providers: Array.isArray(config.providers)
245
- ? config.providers.map((p) => sanitizeProviderHeaders({ ...p }))
246
- : [],
195
+ providers,
247
196
  agent: { ...DEFAULTS.agent, ...config.agent },
248
197
  memory: { ...DEFAULTS.memory, ...config.memory },
249
198
  embedding: { ...DEFAULTS.embedding, ...config.embedding },
@@ -252,6 +201,17 @@ export function loadConfig() {
252
201
  diagnostics: { ...DEFAULTS.diagnostics },
253
202
  }
254
203
 
204
+ // Work mode is normalized from the raw input: a valid mode wins; legacy engineering is read
205
+ // only when mode is absent. The old boolean remains a derived runtime view, never a second authority.
206
+ merged.agent.mode = resolveWorkMode(config.agent)
207
+ merged.agent.engineering = merged.agent.mode === "engineering"
208
+
209
+ // 丢弃要看得见(同节「丢弃要看得见 · 数据面载体」):载体只在有丢弃时有值(无丢弃 ⇒ undefined,
210
+ // 与 `[]` 同义)。一条一句挂数据层;出词归消费面——本批唯一消费方 = `/model` L1 列表首行
211
+ // (`thincoder-cli/src/tui/provider-entries.mjs`),故不走 console。无条件写一次:载体是派生值,
212
+ // 而 `merged` 先摊平了盘上原文(`...config`),条件赋值会把盘上手写的同名键原样放进数据层。
213
+ merged.providersDropped = droppedProviders.length ? droppedProviders : undefined
214
+
255
215
  // 家目录展开(第 29 批):config 路径字段单一规范化点——只读归一(磁盘原文保留)
256
216
  merged.memory.dbPath = expandHome(merged.memory.dbPath)
257
217
  merged.memory.projectDir = expandHome(merged.memory.projectDir)
@@ -362,7 +322,7 @@ export function loadConfig() {
362
322
  merged.agent.compactThresholdAuto = false
363
323
  } else {
364
324
  merged.agent.compactThreshold = undefined
365
- merged.agent.compactThresholdResolved = resolveCompactThreshold(null, merged.provider).value
325
+ merged.agent.compactThresholdResolved = resolveCompactThreshold(null, merged.provider, merged.agent.mode).value
366
326
  merged.agent.compactThresholdAuto = true
367
327
  }
368
328
 
@@ -380,6 +340,10 @@ export function loadConfig() {
380
340
  return merged
381
341
  }
382
342
 
343
+ // 运行中重读盘上渠道表本体居 `config-reload.mjs`(`docs/core/design/PROVIDER.md` §6.30)——本档已过
344
+ // 500 行后按设计指的候选线抽出,以下 re-export 保持既有导入面(同 config-io.mjs 拆分形态)。
345
+ export { reloadProviders } from "./config-reload.mjs"
346
+
383
347
  /**
384
348
  * MCP.md §5 D-3 (2026-09-01): re-read config.json and replace ONLY the agent's mcp section
385
349
  * — the agent 代配 closed loop (agent edits config.json with its edit tool, /mcp picks it
@@ -5,20 +5,34 @@
5
5
  * 原档 `context.mjs` 经 `export { … } from` 转口保名(消费面 / 单元测试档 import 面零改);
6
6
  * 跨档被引的原私有面(`shrinkOversized`)补 `export` 关键字。
7
7
  */
8
- import { collectStaleToolOutputs } from "./token-window.mjs"
8
+ import { collectStaleToolOutputs, contextUsage, estimateTokens, rebaseMeasured, tokenRatioOf } from "./token-window.mjs"
9
+ // 保护尾跟着**有效窗口**走(`CONTEXT-COMPACTION.md` §2.1 / §4):档位自 agent 现取,不靠参数透传。
10
+ import { resolveWorkMode } from "./config.mjs"
11
+ // 保留窗起点(#2431):prune 的合格集与压缩同一个切点——保留窗内那几轮的工具输出不被选中(§1.2)。
12
+ import { retentionWindowStart } from "./agent/turn-projection.mjs"
9
13
 
10
14
  /** prune stub 逐字(§6.16.3):只给「已清理 + 原长度 + 重跑路径」——prune 是**删**不是摘要,不声称可复原。 */
11
15
  const pruneStub = (chars) => `[pruned: stale tool output dropped (${chars} chars) — re-run the tool if you need it again.]`
12
16
 
17
+ /** 本档两处编辑都量到「旧前缀里被改动的那一段」为止:`_usageAtLen` 之后的消息从没被量过,减它们就是减错账。 */
18
+ function measuredEndOf(agent, history) {
19
+ return Number.isInteger(agent?._usageAtLen) ? agent._usageAtLen : history.length
20
+ }
21
+
13
22
  /**
14
23
  * 陈旧工具输出清理(F-CC3 · §6.16.3):合格集 = `token-window.mjs` 单源(保护尾外 ∧ `role:"tool"` ∧ ≥ 门槛);
15
24
  * 命中项**原位换「内容」**(`history[i] = { ...m, content: stub }`——数组引用 / 长度 / 索引 / `tool_call_id` 全不变
16
- * ⇒ 配对**结构上不可能被拆**)。记录面零改(copy-on-write:消息对象与人读线共享);基线失效同 `shrinkOversized` 先例。
25
+ * ⇒ 配对**结构上不可能被拆**)。记录面零改(copy-on-write:消息对象与人读线共享)。
26
+ * 基线按 §3.1 **重定,不归零**:原位替换 ⇒ `_usageAtLen` 原样,`_lastPromptTokens` 只扣那一截的估算差。
27
+ * `fixedOverhead` ∥ `ratio` 的来处 = §2.3 表(`contextUsage(agent).overhead` · `tokenRatioOf(agent)`)。
17
28
  * @returns {{pruned:number, freed:number, candidates:number, tailKept:number, belowMin:number}}
18
29
  */
19
30
  export function pruneStaleToolOutputs(agent) {
20
31
  const history = agent.history
21
- const stale = collectStaleToolOutputs(history, agent.provider)
32
+ const stale = collectStaleToolOutputs(
33
+ history, agent.provider, resolveWorkMode(agent.config?.agent), retentionWindowStart(agent),
34
+ contextUsage(agent).overhead, tokenRatioOf(agent),
35
+ )
22
36
  const counts = {
23
37
  pruned: stale.indexes.length,
24
38
  freed: stale.tokens,
@@ -27,14 +41,21 @@ export function pruneStaleToolOutputs(agent) {
27
41
  belowMin: stale.belowMin,
28
42
  }
29
43
  if (counts.pruned === 0) return counts
44
+ const measuredEnd = measuredEndOf(agent, history)
45
+ let estBefore = 0
46
+ let estAfter = 0
30
47
  for (const i of stale.indexes) {
31
48
  const m = history[i]
49
+ const before = i < measuredEnd ? estimateTokens([m]) : 0
32
50
  // 多模态 tool 结果(content 数组)整体替换为 stub ⇒ 图像 part 丢弃(不可再取——prune 是删;回执只给重跑路径)
33
51
  const chars = typeof m.content === "string" ? m.content.length : JSON.stringify(m.content ?? "").length
34
52
  history[i] = { ...m, content: pruneStub(chars) }
53
+ if (i < measuredEnd) {
54
+ estBefore += before
55
+ estAfter += estimateTokens([history[i]])
56
+ }
35
57
  }
36
- agent._lastPromptTokens = null
37
- agent._usageAtLen = null
58
+ rebaseMeasured(agent, estBefore, estAfter, { inPlace: true })
38
59
  return counts
39
60
  }
40
61
 
@@ -51,31 +72,38 @@ const OVERSIZE_CONTENT_LIMIT = 8_000
51
72
  */
52
73
  export function shrinkOversized(agent, limit = OVERSIZE_CONTENT_LIMIT) {
53
74
  let shrunk = false
75
+ const measuredEnd = measuredEndOf(agent, agent.history)
76
+ let estBefore = 0
77
+ let estAfter = 0
54
78
  // Copy-on-write: build a NEW array and replace only truncated entries. pushReal stores the SAME
55
79
  // message object in both `agent.history` (machine line) and `agent._fullHistory` (human/persistence
56
80
  // line), so in-place `m.content = ...` would ALSO truncate the never-compacted human line and lose
57
81
  // the original pasted content on session persist (session.mjs persists _fullHistory). VS Code port
58
82
  // already copies (`history.map(m => ({ ...m }))`); this brings CLI to parity.
59
- const next = agent.history.map((m) => {
83
+ const next = agent.history.map((m, i) => {
60
84
  if ((m.role !== "user" && m.role !== "tool") || typeof m.content !== "string") return m
61
85
  if (m.content.length <= limit) return m
62
86
  // Truncate keeping head + tail, insert stub in between; keepHead/keepTail proportional but not exceeding 50%/25% of limit
63
87
  const keepHead = Math.min(Math.floor(limit * 0.5), 4000)
64
88
  const keepTail = Math.min(Math.floor(limit * 0.25), 2000)
65
89
  shrunk = true
66
- return {
90
+ const truncated = {
67
91
  ...m,
68
92
  content:
69
93
  m.content.slice(0, keepHead) +
70
94
  `\n[... ${m.content.length - keepHead - keepTail} chars truncated — single message too large for context window ...]\n` +
71
95
  m.content.slice(-keepTail),
72
96
  }
97
+ if (i < measuredEnd) {
98
+ estBefore += estimateTokens([m])
99
+ estAfter += estimateTokens([truncated])
100
+ }
101
+ return truncated
73
102
  })
74
103
  if (shrunk) {
75
104
  agent.history = next
76
- // Same as compaction: measured token baseline is invalidated by the changed history, fall back to estimation until next response
77
- agent._lastPromptTokens = null
78
- agent._usageAtLen = null
105
+ // 基线按 §3.1 **重定,不归零**:截断是原位替换(数组长度与下标不变)⇒ `_usageAtLen` 原样。
106
+ rebaseMeasured(agent, estBefore, estAfter, { inPlace: true })
79
107
  }
80
108
  return shrunk
81
109
  }
package/context-echo.mjs CHANGED
@@ -9,6 +9,17 @@
9
9
  /** Placeholder assistant reply committed right after compaction (D9); D-CC18 merges it into an adjacent tail assistant instead of emitting it as a separate message */
10
10
  export const COMPACTION_PLACEHOLDER = "Understood. I'll continue from these notes, re-verifying anything transient."
11
11
 
12
+ /**
13
+ * 压缩注记的前缀(`context.mjs` 的 `applyCompression` 拼在摘要正文之前)。
14
+ * 住在本档的理由:它是压缩产物那对固定文本之一,另一条就是上面的占位句;两条一起被
15
+ * `token-window.mjs` 的 `NOTE_ESTIMATE` 量一次(§4 的减法链要扣注记与占位),分住两档就得让
16
+ * `token-window.mjs` 反向 import `context.mjs`(成环)。
17
+ */
18
+ export const COMPACTION_PREFIX =
19
+ "[Context was automatically compacted. Below is a summary of earlier work. " +
20
+ "Treat it as notes, not proof — trust its conclusions (don't redo what it reports as done) " +
21
+ "but re-verify transient state with tools. Check memory search for any missing decisions.]\n\n"
22
+
12
23
  /**
13
24
  * Content-shape-safe prefixing (D-CC18, generalized for D-CC19 merge reuse):
14
25
  * string → text + blank line + original; multimodal array → text part prepended;