@thincoder/core 0.11.1 → 0.11.3

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 (382) hide show
  1. package/CHANGELOG.md +64 -2
  2. package/advisor/compaction.mjs +7 -5
  3. package/advisor/convergence.mjs +34 -3
  4. package/advisor/history.mjs +24 -11
  5. package/advisor/loop.mjs +49 -12
  6. package/advisor/messages.mjs +114 -33
  7. package/advisor/project-context.mjs +171 -42
  8. package/advisor/run.mjs +24 -10
  9. package/advisor.mjs +36 -46
  10. package/agent/batch-attribution.mjs +87 -0
  11. package/agent/batch-changed-surface.mjs +129 -0
  12. package/agent/chat-call.mjs +14 -9
  13. package/agent/completion.mjs +70 -41
  14. package/agent/continue-decision.mjs +14 -8
  15. package/agent/digest-account.mjs +133 -59
  16. package/agent/dispatch-gates.mjs +6 -0
  17. package/agent/dispatch-run.mjs +1 -1
  18. package/agent/dispatch.mjs +10 -4
  19. package/agent/family-tools.mjs +37 -23
  20. package/agent/helpers.mjs +139 -73
  21. package/agent/image-heal.mjs +18 -4
  22. package/agent/offload.mjs +25 -29
  23. package/agent/post-turn.mjs +36 -35
  24. package/agent/record-results.mjs +39 -7
  25. package/agent/run-stages.mjs +132 -52
  26. package/agent/run-start.mjs +150 -78
  27. package/agent/setup-reminders.mjs +194 -91
  28. package/agent/setup.mjs +219 -140
  29. package/agent/spawn-child.mjs +40 -3
  30. package/agent/suspension.mjs +43 -15
  31. package/agent/timers.mjs +9 -4
  32. package/agent/turn-domain-text.mjs +105 -0
  33. package/agent/turn-loop.mjs +84 -27
  34. package/agent/turn-projection.mjs +286 -0
  35. package/agent/turn-task-state.mjs +274 -0
  36. package/agent/turn-tool-process.mjs +163 -0
  37. package/agent/write-gate-ledger.mjs +569 -0
  38. package/agent/write-gate.mjs +29 -352
  39. package/agent-tools/advisor-async.mjs +35 -172
  40. package/agent-tools/advisor-launch.mjs +178 -0
  41. package/agent-tools/advisor-settle.mjs +28 -1
  42. package/agent-tools/advisor.mjs +37 -48
  43. package/agent-tools/async-discard.mjs +7 -2
  44. package/agent-tools/async-settle.mjs +18 -12
  45. package/agent-tools/audit-block.mjs +6 -6
  46. package/agent-tools/bash-async.mjs +5 -2
  47. package/agent-tools/batch-closeout.mjs +223 -35
  48. package/agent-tools/batch-gate.mjs +142 -342
  49. package/agent-tools/batch-ledger-bind.mjs +240 -20
  50. package/agent-tools/batch-ledger-view.mjs +109 -0
  51. package/agent-tools/batch-lifecycle.mjs +197 -48
  52. package/agent-tools/batch-paths.mjs +29 -8
  53. package/agent-tools/batch-read.mjs +151 -4
  54. package/agent-tools/batch-record-write.mjs +417 -0
  55. package/agent-tools/batch-regions.mjs +215 -0
  56. package/agent-tools/batch-reopen.mjs +23 -11
  57. package/agent-tools/batch-segment-vocab.mjs +459 -0
  58. package/agent-tools/batch-skeleton.mjs +196 -239
  59. package/agent-tools/batch-supersede.mjs +232 -0
  60. package/agent-tools/batch-tier-gate.mjs +214 -0
  61. package/agent-tools/batch.mjs +192 -439
  62. package/agent-tools/browser-async.mjs +5 -2
  63. package/agent-tools/consult.mjs +17 -11
  64. package/agent-tools/context.mjs +76 -33
  65. package/agent-tools/design-review-record.mjs +225 -0
  66. package/agent-tools/design-slots.mjs +1 -1
  67. package/agent-tools/design-token.mjs +279 -81
  68. package/agent-tools/digest-budget.mjs +10 -9
  69. package/agent-tools/doc-check.mjs +43 -33
  70. package/agent-tools/doc-graph.mjs +140 -0
  71. package/agent-tools/eng.mjs +12 -12
  72. package/agent-tools/escalate-async.mjs +5 -5
  73. package/agent-tools/goal.mjs +5 -2
  74. package/agent-tools/judge-domain.mjs +347 -0
  75. package/agent-tools/manifest.mjs +34 -18
  76. package/agent-tools/parent-channel.mjs +6 -3
  77. package/agent-tools/plan.mjs +11 -10
  78. package/agent-tools/read-history.mjs +112 -11
  79. package/agent-tools/review-facts.mjs +19 -6
  80. package/agent-tools/settings.mjs +23 -2
  81. package/agent-tools/skill.mjs +7 -8
  82. package/agent-tools/spawn-gates.mjs +14 -24
  83. package/agent-tools/ssh-session.mjs +8 -5
  84. package/agent-tools/ssh-text.mjs +155 -0
  85. package/agent-tools/ssh-transfer.mjs +1 -1
  86. package/agent-tools/ssh-transport.mjs +19 -148
  87. package/agent-tools/subagent-actions-query.mjs +10 -6
  88. package/agent-tools/subagent-actions.mjs +2 -2
  89. package/agent-tools/subagent-async.mjs +19 -17
  90. package/agent-tools/subagent-brief.mjs +76 -0
  91. package/agent-tools/subagent-design-token.mjs +168 -0
  92. package/agent-tools/subagent-run.mjs +1 -1
  93. package/agent-tools/subagent-scheduler.mjs +13 -13
  94. package/agent-tools/subagent-spawn.mjs +92 -112
  95. package/agent-tools/subagent.mjs +16 -28
  96. package/agent-tools/task.mjs +0 -8
  97. package/agent-tools/taskbook-block.mjs +94 -0
  98. package/agent-tools/timer.mjs +12 -8
  99. package/agent-tools/verify.mjs +13 -4
  100. package/agent-tools.mjs +7 -3
  101. package/agent.mjs +26 -7
  102. package/attachments.mjs +3 -3
  103. package/auto-think.mjs +5 -2
  104. package/browser/actions.mjs +9 -3
  105. package/browser/cdp.mjs +45 -17
  106. package/browser/launch.mjs +25 -43
  107. package/browser/pool.mjs +299 -0
  108. package/browser/queue.mjs +2 -0
  109. package/browser/session-state.mjs +450 -0
  110. package/browser/session.mjs +127 -151
  111. package/browser/snapshot.mjs +89 -0
  112. package/client-identity.mjs +1 -1
  113. package/compaction-work-state.mjs +230 -0
  114. package/compress-form.mjs +41 -6
  115. package/config-defaults.mjs +7 -3
  116. package/config-migrate.mjs +40 -0
  117. package/config-normalize.mjs +28 -2
  118. package/config-reload.mjs +59 -0
  119. package/config.mjs +110 -110
  120. package/context-degrade.mjs +93 -34
  121. package/context-echo.mjs +6 -15
  122. package/context-push.mjs +328 -31
  123. package/context.mjs +298 -170
  124. package/conventions.mjs +11 -9
  125. package/declaration.mjs +126 -22
  126. package/declared-repos.mjs +94 -0
  127. package/doc-check/doc-names.mjs +73 -0
  128. package/doc-check/doc-tokens.mjs +110 -0
  129. package/doc-check/existence.mjs +160 -0
  130. package/doc-check/index.mjs +309 -213
  131. package/doc-check/line-refs.mjs +27 -101
  132. package/doc-check/paragraph.mjs +218 -102
  133. package/doc-graph/anchors.mjs +474 -0
  134. package/doc-graph/doc-batch-face.mjs +59 -0
  135. package/doc-graph/doc-suffix.mjs +27 -0
  136. package/doc-graph/graph-tokens.mjs +160 -0
  137. package/doc-graph.mjs +778 -0
  138. package/escape.mjs +6 -5
  139. package/explore-distill.mjs +41 -8
  140. package/generate-title.mjs +10 -1
  141. package/i18n.mjs +1 -1
  142. package/instance-inbox-watch.mjs +272 -0
  143. package/instance-inbox.mjs +218 -0
  144. package/instance-registry.mjs +179 -0
  145. package/knowledge/README.md +3 -0
  146. package/knowledge/prompt-resources.md +10 -0
  147. package/ledger-close-proof.mjs +100 -49
  148. package/ledger-close.mjs +188 -0
  149. package/ledger-cmd.mjs +47 -91
  150. package/ledger-consistency.mjs +113 -0
  151. package/ledger-db.mjs +47 -15
  152. package/ledger-executors.mjs +1 -1
  153. package/ledger-tools.mjs +121 -62
  154. package/ledger-write-ops.mjs +162 -46
  155. package/ledger.mjs +1 -1
  156. package/manifest-discovery.mjs +3 -1
  157. package/manifest-schema.mjs +27 -5
  158. package/memory/docs.mjs +51 -15
  159. package/memory/file-list.mjs +6 -0
  160. package/memory/schema.mjs +2 -2
  161. package/model-specs.mjs +87 -21
  162. package/origin-guard.mjs +190 -0
  163. package/package.json +3 -1
  164. package/path-resolve.mjs +338 -57
  165. package/prompt-files.mjs +114 -2
  166. package/prompt-overlays.mjs +21 -11
  167. package/prompts/advisor-design.md +96 -36
  168. package/prompts/advisor-round1.md +48 -4
  169. package/prompts/advisor-round2.md +54 -10
  170. package/prompts/advisor-round3.md +53 -9
  171. package/prompts/common.md +99 -434
  172. package/prompts/consult-base.md +7 -4
  173. package/prompts/discipline-engineering.md +504 -295
  174. package/prompts/discipline-normal.md +106 -281
  175. package/prompts/knowledge/business-gates.md +30 -0
  176. package/prompts/knowledge/decision-quality.md +21 -0
  177. package/prompts/knowledge/doc-lookup.md +30 -0
  178. package/prompts/knowledge/document-writing.md +33 -0
  179. package/prompts/knowledge/documentation-evaluation.md +48 -0
  180. package/prompts/knowledge/evidence-discipline.md +38 -0
  181. package/prompts/knowledge/normal-coding-workflow.md +110 -0
  182. package/prompts/knowledge/normal-delivery-collaboration.md +124 -0
  183. package/prompts/knowledge/normal-work-management.md +60 -0
  184. package/prompts/knowledge/product-security.md +28 -0
  185. package/prompts/knowledge/project-records.md +73 -0
  186. package/prompts/knowledge/tool-advisor.md +29 -0
  187. package/prompts/knowledge/tool-apply-patch.md +17 -0
  188. package/prompts/knowledge/tool-bash.md +48 -0
  189. package/prompts/knowledge/tool-batch-eng-coder.md +19 -0
  190. package/prompts/knowledge/tool-batch-eng-designer.md +20 -0
  191. package/prompts/knowledge/tool-batch-review.md +18 -0
  192. package/prompts/knowledge/tool-batch.md +94 -0
  193. package/prompts/knowledge/tool-browser.md +68 -0
  194. package/prompts/knowledge/tool-code-search.md +4 -0
  195. package/prompts/knowledge/tool-consult-start.md +12 -0
  196. package/prompts/knowledge/tool-consult-stop.md +6 -0
  197. package/prompts/knowledge/tool-context.md +6 -0
  198. package/prompts/knowledge/tool-delete.md +21 -0
  199. package/prompts/knowledge/tool-doc-check.md +71 -0
  200. package/prompts/knowledge/tool-doc-graph-read.md +20 -0
  201. package/prompts/knowledge/tool-doc-graph.md +49 -0
  202. package/prompts/knowledge/tool-doc-search.md +6 -0
  203. package/prompts/knowledge/tool-edit.md +41 -0
  204. package/prompts/knowledge/tool-eng.md +2 -0
  205. package/prompts/knowledge/tool-execute.md +21 -0
  206. package/prompts/knowledge/tool-fetch.md +18 -0
  207. package/prompts/knowledge/tool-file-ops.md +21 -0
  208. package/prompts/knowledge/tool-get-current-time.md +7 -0
  209. package/prompts/knowledge/tool-git-read.md +21 -0
  210. package/prompts/knowledge/tool-git.md +29 -0
  211. package/prompts/knowledge/tool-glob.md +17 -0
  212. package/prompts/knowledge/tool-goal.md +8 -0
  213. package/prompts/knowledge/tool-grep.md +21 -0
  214. package/prompts/knowledge/tool-hashline-edit.md +16 -0
  215. package/prompts/knowledge/tool-insert-after.md +17 -0
  216. package/prompts/knowledge/tool-instance-list.md +6 -0
  217. package/prompts/knowledge/tool-instance-send.md +10 -0
  218. package/prompts/knowledge/tool-knowledge.md +18 -0
  219. package/prompts/knowledge/tool-ledger-read.md +28 -0
  220. package/prompts/knowledge/tool-ledger.md +46 -0
  221. package/prompts/knowledge/tool-lint.md +16 -0
  222. package/prompts/knowledge/tool-ls.md +15 -0
  223. package/prompts/knowledge/tool-lsp.md +11 -0
  224. package/prompts/knowledge/tool-main-history.md +2 -0
  225. package/prompts/knowledge/tool-manifest-read.md +14 -0
  226. package/prompts/knowledge/tool-manifest.md +34 -0
  227. package/prompts/knowledge/tool-memory-read.md +20 -0
  228. package/prompts/knowledge/tool-memory.md +19 -0
  229. package/prompts/knowledge/tool-notify-parent.md +12 -0
  230. package/prompts/knowledge/tool-operations.md +102 -0
  231. package/prompts/knowledge/tool-peer-instances.md +2 -0
  232. package/prompts/knowledge/tool-plan.md +5 -0
  233. package/prompts/knowledge/tool-process-read.md +13 -0
  234. package/prompts/knowledge/tool-process.md +15 -0
  235. package/prompts/knowledge/tool-question.md +16 -0
  236. package/prompts/knowledge/tool-read-history-batch.md +22 -0
  237. package/prompts/knowledge/tool-read-history.md +35 -0
  238. package/prompts/knowledge/tool-read-image.md +11 -0
  239. package/prompts/knowledge/tool-read.md +22 -0
  240. package/prompts/knowledge/tool-recent-changes.md +6 -0
  241. package/prompts/knowledge/tool-repo-outline.md +4 -0
  242. package/prompts/knowledge/tool-settings-read.md +12 -0
  243. package/prompts/knowledge/tool-settings.md +17 -0
  244. package/prompts/knowledge/tool-skill.md +6 -0
  245. package/prompts/knowledge/tool-ssh.md +74 -0
  246. package/prompts/knowledge/tool-subagent.md +57 -0
  247. package/prompts/knowledge/tool-task.md +14 -0
  248. package/prompts/knowledge/tool-team-ledger-read.md +11 -0
  249. package/prompts/knowledge/tool-team-ledger.md +15 -0
  250. package/prompts/knowledge/tool-timer.md +23 -0
  251. package/prompts/knowledge/tool-tree.md +16 -0
  252. package/prompts/knowledge/tool-verify.md +19 -0
  253. package/prompts/knowledge/tool-wait-for.md +25 -0
  254. package/prompts/knowledge/tool-websearch.md +19 -0
  255. package/prompts/knowledge/tool-write.md +12 -0
  256. package/prompts/knowledge/upstream-protocol.md +45 -0
  257. package/prompts/persona-coder.md +1 -3
  258. package/prompts/persona-eng-coder.md +24 -6
  259. package/prompts/persona-eng-designer.md +150 -171
  260. package/prompts/persona-engineering.md +531 -442
  261. package/prompts/persona-explore.md +1 -3
  262. package/prompts/persona-normal.md +17 -9
  263. package/prompts/persona-plan.md +5 -3
  264. package/prompts/persona-tester.md +0 -2
  265. package/prompts/subagent-base.md +2 -2
  266. package/provider/anthropic.mjs +10 -6
  267. package/provider/core.mjs +8 -5
  268. package/provider/errors.mjs +63 -4
  269. package/provider/google.mjs +29 -10
  270. package/provider/reasoning-echo.mjs +16 -0
  271. package/provider/responses.mjs +7 -3
  272. package/provider/sse.mjs +11 -6
  273. package/provider-flows.mjs +2 -2
  274. package/rules.mjs +11 -10
  275. package/session-index-build.mjs +1 -1
  276. package/session-index-pass.mjs +1 -1
  277. package/session-index-query.mjs +1 -1
  278. package/session-index.mjs +1 -1
  279. package/session-lifecycle.mjs +131 -42
  280. package/session-slot-write.mjs +38 -6
  281. package/session.mjs +30 -11
  282. package/shell-identity.mjs +129 -22
  283. package/skip-dirs.mjs +26 -2
  284. package/team-ledger.mjs +34 -30
  285. package/text-budget.mjs +1 -1
  286. package/think-off.mjs +27 -0
  287. package/token-ttl.mjs +74 -5
  288. package/token-window.mjs +371 -47
  289. package/tool-docs/advisor.md +2 -27
  290. package/tool-docs/apply_patch.md +1 -15
  291. package/tool-docs/bash.md +2 -43
  292. package/tool-docs/batch-eng-coder.md +3 -0
  293. package/tool-docs/batch-eng-designer.md +3 -0
  294. package/tool-docs/batch-review.md +3 -0
  295. package/tool-docs/batch.md +2 -84
  296. package/tool-docs/browser.md +2 -49
  297. package/tool-docs/code_search.md +2 -2
  298. package/tool-docs/consult_start.md +2 -8
  299. package/tool-docs/consult_stop.md +2 -4
  300. package/tool-docs/context.md +1 -5
  301. package/tool-docs/delete.md +2 -17
  302. package/tool-docs/doc_check.md +2 -107
  303. package/tool-docs/doc_graph-read.md +3 -0
  304. package/tool-docs/doc_graph.md +3 -0
  305. package/tool-docs/doc_search.md +2 -4
  306. package/tool-docs/edit.md +1 -38
  307. package/tool-docs/eng.md +3 -1
  308. package/tool-docs/execute.md +2 -18
  309. package/tool-docs/fetch.md +2 -14
  310. package/tool-docs/file_ops.md +2 -18
  311. package/tool-docs/get_current_time.md +1 -6
  312. package/tool-docs/git-read.md +3 -0
  313. package/tool-docs/git.md +2 -35
  314. package/tool-docs/glob.md +2 -10
  315. package/tool-docs/goal.md +1 -6
  316. package/tool-docs/grep.md +2 -18
  317. package/tool-docs/hashline_edit.md +2 -15
  318. package/tool-docs/insert_after.md +2 -16
  319. package/tool-docs/instance_list.md +3 -0
  320. package/tool-docs/instance_send.md +3 -0
  321. package/tool-docs/knowledge.md +3 -0
  322. package/tool-docs/ledger-read.md +3 -0
  323. package/tool-docs/ledger.md +3 -8
  324. package/tool-docs/lint.md +2 -10
  325. package/tool-docs/ls.md +2 -11
  326. package/tool-docs/lsp.md +2 -9
  327. package/tool-docs/main_history.md +3 -1
  328. package/tool-docs/manifest-read.md +2 -8
  329. package/tool-docs/manifest.md +2 -35
  330. package/tool-docs/memory-read.md +3 -0
  331. package/tool-docs/memory.md +2 -20
  332. package/tool-docs/notify_parent.md +2 -13
  333. package/tool-docs/peer_instances.md +3 -1
  334. package/tool-docs/plan.md +1 -5
  335. package/tool-docs/process-read.md +3 -0
  336. package/tool-docs/process.md +2 -13
  337. package/tool-docs/question.md +3 -17
  338. package/tool-docs/read.md +2 -19
  339. package/tool-docs/read_history-batch.md +3 -0
  340. package/tool-docs/read_history.md +2 -18
  341. package/tool-docs/read_image.md +2 -9
  342. package/tool-docs/recent_changes.md +2 -2
  343. package/tool-docs/repo_outline.md +2 -2
  344. package/tool-docs/settings-read.md +3 -0
  345. package/tool-docs/settings.md +1 -12
  346. package/tool-docs/skill.md +2 -6
  347. package/tool-docs/ssh.md +1 -62
  348. package/tool-docs/subagent.md +2 -100
  349. package/tool-docs/task.md +1 -7
  350. package/tool-docs/team_ledger-read.md +3 -0
  351. package/tool-docs/team_ledger.md +3 -9
  352. package/tool-docs/timer.md +2 -19
  353. package/tool-docs/tree.md +2 -13
  354. package/tool-docs/verify.md +2 -12
  355. package/tool-docs/wait_for.md +2 -32
  356. package/tool-docs/websearch.md +2 -19
  357. package/tool-docs/write.md +2 -12
  358. package/tools/browser.mjs +54 -9
  359. package/tools/doc-write-gate.mjs +73 -0
  360. package/tools/edit-batch.mjs +170 -92
  361. package/tools/edit-diff.mjs +78 -62
  362. package/tools/edit-receipt.mjs +39 -0
  363. package/tools/execute.mjs +3 -3
  364. package/tools/file.mjs +28 -14
  365. package/tools/git.mjs +36 -21
  366. package/tools/index.mjs +6 -0
  367. package/tools/knowledge.mjs +143 -0
  368. package/tools/linter.mjs +3 -3
  369. package/tools/ops.mjs +5 -3
  370. package/tools/patch.mjs +124 -44
  371. package/tools/process-doc-mark.mjs +33 -4
  372. package/tools/repomap.mjs +25 -3
  373. package/tools/search.mjs +74 -26
  374. package/tools/shared.mjs +29 -27
  375. package/tools/ssh.mjs +5 -5
  376. package/tools/tree.mjs +32 -10
  377. package/tools/web-deepseek.mjs +1 -1
  378. package/tools/web.mjs +2 -2
  379. package/tools/write-gate-params.mjs +31 -0
  380. package/tools/write-path.mjs +16 -4
  381. package/window-policy.mjs +243 -0
  382. package/doc-check/anchors.mjs +0 -235
@@ -1,5 +1,6 @@
1
1
  /**
2
- * process-doc-mark.mjs — 工具输出里的过程档标记(单源小档;机制 = `docs/core/design/TOOLS.md` §6.28)。
2
+ * process-doc-mark.mjs — 工具输出里的过程档标记与文档层标识(单源小档;过程层排除的机制 = `docs/core/design/TOOLS.md` §7.1
3
+ * 「检索与浏览类工具的过程层默认排除」,层标识的机制 = `docs/core/design/DOC-SYSTEM.md` §3.1「层标识」)。
3
4
  *
4
5
  * 依赖面说清楚:本档**不**是零依赖叶档——谓词都来自判据单源 `../declaration.mjs`,而它的静态闭包
5
6
  * 经 `memory/file-walk.mjs` 达 `memory/schema.mjs`(`node:sqlite`)。因此端壳里静态引本档 = 把那条链拉进静态闭包;
@@ -8,7 +9,8 @@
8
9
  *
9
10
  * 一句话:输出里**判定得出**来源档落在索引排除集(batches 段 ∥ `_archive` 前缀)的行,
10
11
  * 行首加 `[process doc: not a design basis]`(原行整体后随);其余行一个字节不动。**不是门**——
11
- * 不拦、不筛、不改命中集,只加可读信息。
12
+ * 不拦、不筛、不改命中集,只加可读信息。文档层标识(`[<层键>]`)也住这一档:两者都是“这一行来自哪份档”的
13
+ * 可读信息,共用同一次属辖声明查找。
12
14
  *
13
15
  * 两套判据、一份文案、一个谓词、一个 helper:
14
16
  * - `grep` 面按命中行的**档**判(消费面直调 `isProcessDocPath`——grep 自己已有 `h.file`,本档不参与拼装);
@@ -18,13 +20,14 @@
18
20
  * 判据单源 = `../declaration.mjs` 的 `isExcludedRelPath`(面① 前缀 ∪ 面⑥ 段序列):本档零新排除名单、
19
21
  * 零新谓词。第三参必须传 `decl.root`——`isExcludedRelPath` 内 `resolve(base, s)` 对绝对参恒等,
20
22
  * 再由 `relative(root, …)` 换成根相对面,面① 前缀才判得住(只被面① 命中的 `_archive` 靠这一点)。
23
+ * 层标识的判据单源 = `docLayerOf`(同一个属辖声明、同一次按档记忆)。
21
24
  *
22
25
  * 零 console 噪声:本档不调用 `console`。判据只走 `declarationForTarget` → `loadProjectDeclaration`,
23
26
  * 后者按档缓存,只在声明档不可用 / 读不出时 warn(既有降级面,非本档新增)。
24
27
  */
25
28
  import { existsSync } from "node:fs"
26
29
  import { isAbsolute, resolve } from "node:path"
27
- import { declarationForTarget, isExcludedRelPath } from "../declaration.mjs"
30
+ import { declarationForTarget, docLayerOf, isExcludedRelPath } from "../declaration.mjs"
28
31
 
29
32
  /** 逐字文案(33 字符 · 全 ASCII · 方括号闭合):工具输出面全英文,同一行混中英破坏「一词一物」。 */
30
33
  export const PROCESS_DOC_MARK = "[process doc: not a design basis]"
@@ -33,6 +36,32 @@ export const PROCESS_DOC_MARK = "[process doc: not a design basis]"
33
36
  export const processDocSummary = (n) =>
34
37
  `[process doc: ${n} of this output's lines come from process docs — not a design basis]`
35
38
 
39
+ /** 检索与浏览类工具的报数行(逐字文案 · 全 ASCII):`n` = 本次输出里被判为过程档的条目 / 行数。
40
+ * 两式共用一条规则——`included` 说清这一批是被排除还是按请求取回;`n = 0` 时调用面不加行。 */
41
+ export const processDocsReport = (n, included) =>
42
+ included
43
+ ? `[process docs: ${n} of this output's rows come from process docs — included by request]`
44
+ : `[process docs: ${n} of this output's rows come from process docs — excluded by default; pass includeProcessDocs=true to include them]`
45
+
46
+ /**
47
+ * 文档层标识(一次调用内按档记忆:`Map<absoluteFile, string>`)——工具输出面的唯一算点。
48
+ * 层判定单源 = `../declaration.mjs` 的 `docLayerOf`,属辖声明由 `declarationForTarget` 取(与
49
+ * `isProcessDocPath` 同一形,不新建机制):声明公共源里的档因此按那个仓自己的 `docRoot` 判层。
50
+ * @param {string} absFile 档的绝对路径
51
+ * @param {Map<string, string>} [cache] 记忆表(缺省自建——不传就没有跳调用的记忆)
52
+ * @returns {string} 层名(`docRoot` 键名逐字);出辖 ∥ 未落入声明根 ⇒ `"unlayered"`
53
+ */
54
+ export function docLayerName(absFile, cache) {
55
+ const key = String(absFile ?? "")
56
+ if (!key) return "unlayered"
57
+ const memo = cache instanceof Map ? cache : new Map()
58
+ if (memo.has(key)) return memo.get(key)
59
+ const decl = declarationForTarget(key) // null = 出辖(祖先链无 manifest)
60
+ const layer = decl ? docLayerOf(key, decl).layer : "unlayered"
61
+ memo.set(key, layer)
62
+ return layer
63
+ }
64
+
36
65
  /** 行首 token 的字符帽(步骤 ①):超过即成不了路径,该行跳过不解析。 */
37
66
  const MAX_TOKEN_CHARS = 260
38
67
 
@@ -104,7 +133,7 @@ function resolveOnDisk(token, base) {
104
133
  }
105
134
 
106
135
  /**
107
- * 命令面打标(§6.28「命令输出面」六步,`bash` ∥ `execute` ∥ VSC 端 `bash` 共用):
136
+ * 命令面打标(`TOOLS.md` §7.1「命令输出面」六步,`bash` ∥ `execute` ∥ VSC 端 `bash` 共用):
108
137
  * 逐行取行首 token → 真解析到盘上 → 判归属 → 命中者行首加前缀(行其余部分原样)。
109
138
  * N > 0 ⇒ 正文之后追加一行汇总;N = 0 ⇒ **原样返回入参**(一个字节不动,无空汇总行)。
110
139
  *
package/tools/repomap.mjs CHANGED
@@ -8,6 +8,23 @@ import { readFile, stat } from "node:fs/promises"
8
8
  import { join } from "node:path"
9
9
  import { DESC, normalizeEOL } from "./shared.mjs" // #15 描述外置:文本单点 = tool-docs/repo_outline.md(DESC 单解析面)
10
10
  import { INDEX_ORIGIN_ROW_WARN } from "../memory/schema.mjs" // §6.14 B4 文件数上界(WARN 值复用)
11
+ import { BUILD_ARTIFACT_DIRS, BUILD_ARTIFACT_DIR_PAIRS, BUILD_ARTIFACT_DIR_PREFIXES } from "../skip-dirs.mjs" // 大纲去噪族(单源 = 名单旁;机制 = `docs/core/design/MEMORY.md` §4)
12
+
13
+ /**
14
+ * 大纲编撰面的去噪判据:行 `path`(相对 origin 根,`/` 分隔)是否命中构建产物族。
15
+ * 只跳过大纲的建图行——索引准入与库里那些行一处不改(删除走维护面,`ENOENT` 判死)。
16
+ * **前缀族只判目录段**:末段是文件名,`dist-resource-face.mjs` 一类产品代码照进大纲。
17
+ */
18
+ function isBuildArtifactPath(rel) {
19
+ const segs = String(rel ?? "").split("/").filter(Boolean)
20
+ for (let i = 0; i < segs.length; i++) {
21
+ const isDirSegment = i < segs.length - 1
22
+ if (BUILD_ARTIFACT_DIRS.has(segs[i])) return true
23
+ if (isDirSegment && BUILD_ARTIFACT_DIR_PREFIXES.some((p) => segs[i].startsWith(p))) return true
24
+ if (i + 1 < segs.length && BUILD_ARTIFACT_DIR_PAIRS.some(([a, b]) => segs[i] === a && segs[i + 1] === b)) return true
25
+ }
26
+ return false
27
+ }
11
28
 
12
29
  /** Extract JS/TS file import paths (normalize by stripping .ts/.js/.mjs suffixes) */
13
30
  function parseImports(lines, ext) {
@@ -129,11 +146,16 @@ async function _buildDepGraph(db, cwd, { origin = null } = {}) {
129
146
  if (allFiles.length === 0) return null
130
147
  if (allFiles.length >= limit) return { overLimit: true, fileCount: allFiles.length }
131
148
 
149
+ // 读取面去噪(`docs/core/design/MEMORY.md` §4「文件发现与范围」):构建产物族的行不进大纲——
150
+ // 目录依赖 ∥ Hub files ∥ Entry points 三段同一次干净(不含构建产物与缓存)。
151
+ const files = allFiles.filter((rel) => !isBuildArtifactPath(rel))
152
+ if (files.length === 0) return null
153
+
132
154
  const deps = new Map() // path → { imports: Set, exports: Set, size: number, dir: string }
133
155
  const importers = new Map() // importee → Set<importer>
134
156
 
135
- for (let i = 0; i < allFiles.length; i++) {
136
- const rel = allFiles[i]
157
+ for (let i = 0; i < files.length; i++) {
158
+ const rel = files[i]
137
159
  const abs = join(cwd, ...rel.split("/"))
138
160
  if (!existsSync(abs)) continue
139
161
  // Large file guard: skip files over 10MB to prevent OOM
@@ -181,7 +203,7 @@ async function _buildDepGraph(db, cwd, { origin = null } = {}) {
181
203
  if (i % 20 === 19) await new Promise(r => setImmediate(r))
182
204
  }
183
205
 
184
- return { deps, importers, fileCount: allFiles.length }
206
+ return { deps, importers, fileCount: files.length }
185
207
  }
186
208
 
187
209
  /**
package/tools/search.mjs CHANGED
@@ -10,8 +10,9 @@ import {
10
10
  // 排除名单单源(零依赖叶档 `../skip-dirs.mjs`——2026-10-27 四份名单合一):旧名 `IGNORED_DIRS`
11
11
  // 退场,本档三处直接引 `SKIP_DIRS`(一词一物)。
12
12
  import { SKIP_DIRS } from "../skip-dirs.mjs";
13
- // 过程档标记(TOOLS.md §6.28):命中行的**档**在索引排除集内 ⇒ 行首逐字前缀。只加可读信息,不改命中集。
14
- import { PROCESS_DOC_MARK, isProcessDocPath } from "./process-doc-mark.mjs";
13
+ // 过程档标记 + 文档层标识(机制 = `docs/core/design/TOOLS.md` §7.1):命中行的**档**在索引排除集内 ⇒ 行首逐字前缀;
14
+ // 每行再带它自己的层标识。只加可读信息,不改命中集。
15
+ import { PROCESS_DOC_MARK, isProcessDocPath, docLayerName, processDocsReport } from "./process-doc-mark.mjs";
15
16
  import { readFile, readdir, stat, lstat } from "node:fs/promises";
16
17
  import { join } from "node:path";
17
18
 
@@ -20,6 +21,11 @@ function escapeRegExp(s) {
20
21
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
21
22
  }
22
23
 
24
+ /** 四个检索与浏览工具的同一个参数:省略即排除、`true` 取回。schema 上**不写 `default` 键**——
25
+ * 省略即排除是规则的语义,不是代码替调用方选值(`docs/core/design/TOOL-PARAM-ZERO-DEFAULTS.md` §1)。
26
+ * `description` 的最短语义是 tiny 档唯一的参数面(那里看不见知识主题)。 */
27
+ const INCLUDE_PROCESS_DOCS_DESC = "Include process-layer docs (batch records, archived material) — omitted = excluded by default; true = include them"
28
+
23
29
  // ---------------------------------------------------------------- glob
24
30
 
25
31
  export const globTool = {
@@ -30,12 +36,14 @@ export const globTool = {
30
36
  properties: {
31
37
  pattern: { type: "string", description: "Glob pattern — supports **, *, ?, [..], {a,b} braces, and space-separated exclusion (\"**/*.js !test/**\")" },
32
38
  path: { type: "string", description: "Directory to search in (default cwd)" },
39
+ includeProcessDocs: { type: "boolean", description: INCLUDE_PROCESS_DOCS_DESC },
33
40
  },
34
41
  required: ["pattern"],
35
42
  },
36
43
  readonly: true,
37
44
  async execute(args, ctx) {
38
45
  const base = resolveInCwd(ctx, args.path ?? ".")
46
+ const includeProcessDocs = args.includeProcessDocs === true
39
47
  // TOOLS.md §6.7 调用侧拆分(评审 #5 职责分层):空格分隔 include !exclude 多模式在这里拆;
40
48
  // globToRegex 只收单个模式(数组由 compileGlobMatchers 收)。
41
49
  let match
@@ -47,6 +55,9 @@ export const globTool = {
47
55
  return `glob error: invalid pattern "${args.pattern}": ${e.message}`
48
56
  }
49
57
  const results = []
58
+ const procCache = new Map()
59
+ const layerCache = new Map()
60
+ let excluded = 0
50
61
  // §2.5 #65 并入(VSC「路径不存在明确报错」):目标路径缺失不再静默空清单。
51
62
  try {
52
63
  await stat(base)
@@ -54,13 +65,17 @@ export const globTool = {
54
65
  return `glob error: path not found: ${base}`
55
66
  }
56
67
  for await (const relPath of walkFiles(base)) {
57
- if (match(relPath)) {
58
- results.push(relPath)
59
- if (results.length >= 1000) break
60
- }
68
+ if (!match(relPath)) continue
69
+ // 默认排除在截断之前生效:被排除的档不占 1000 条配额(否则只堆过程档的目录会把输出挤成空)。
70
+ if (!includeProcessDocs && isProcessDocPath(join(base, relPath), procCache)) { excluded += 1; continue }
71
+ results.push(relPath)
72
+ if (results.length >= 1000) break
61
73
  }
62
- if (results.length === 0) return "(no matches)"
63
- return truncate(results.sort().join("\n"))
74
+ const n = includeProcessDocs ? results.filter((p) => isProcessDocPath(join(base, p), procCache)).length : excluded
75
+ const body = results.length === 0
76
+ ? "(no matches)"
77
+ : truncate(results.sort().map((p) => `[${docLayerName(join(base, p), layerCache)}] ${p}`).join("\n"))
78
+ return n > 0 ? `${body}\n${processDocsReport(n, includeProcessDocs)}` : body
64
79
  },
65
80
  }
66
81
 
@@ -100,6 +115,7 @@ export const grepTool = {
100
115
  literal: { type: "boolean", description: "Literal string match — no regex interpretation (default false)" },
101
116
  before: { type: "integer", description: "Lines of context to show before each match (grep -B). Default 0" },
102
117
  after: { type: "integer", description: "Lines of context to show after each match (grep -A). Default 0" },
118
+ includeProcessDocs: { type: "boolean", description: INCLUDE_PROCESS_DOCS_DESC },
103
119
  },
104
120
  required: ["pattern"],
105
121
  },
@@ -132,8 +148,11 @@ export const grepTool = {
132
148
  const before = Math.max(0, Math.floor(args.before ?? 0))
133
149
  const after = Math.max(0, Math.floor(args.after ?? 0))
134
150
  const wantCtx = before > 0 || after > 0
151
+ const includeProcessDocs = args.includeProcessDocs === true
135
152
  const hits = [] // { file, line(1-based), text }
136
153
  const fileLines = new Map() // file -> string[] (cached only when context lines requested)
154
+ const procCache = new Map() // 档 → 是否过程档(一次调用一个记忆表)
155
+ let excludedRows = 0 // 被默认排除的命中行数(报数用;N = 0 不加行)
137
156
 
138
157
  async function search(file) {
139
158
  let content
@@ -145,13 +164,17 @@ export const grepTool = {
145
164
  } catch {
146
165
  return // Skip unreadable files; binary files will be read as UTF-8 and searched (may produce garbled matches)
147
166
  }
167
+ // 默认排除在**命中处**生效:被排除的档不占 200 条配额,也不进上下文区。
168
+ // 首次命中时才判定(整仓 grep 不必为每个扫到的档付一次属辖声明探测)。
169
+ let skipProcess = null
148
170
  const lines = content.split("\n")
149
171
  if (wantCtx) fileLines.set(file, lines)
150
172
  for (let i = 0; i < lines.length; i++) {
151
- if (regex.test(lines[i])) {
152
- hits.push({ file, line: i + 1, text: lines[i] })
153
- if (hits.length >= 200) return
154
- }
173
+ if (!regex.test(lines[i])) continue
174
+ if (skipProcess === null) skipProcess = !includeProcessDocs && isProcessDocPath(file, procCache)
175
+ if (skipProcess) { excludedRows += 1; continue }
176
+ hits.push({ file, line: i + 1, text: lines[i] })
177
+ if (hits.length >= 200) break
155
178
  }
156
179
  }
157
180
 
@@ -179,16 +202,22 @@ export const grepTool = {
179
202
  }
180
203
 
181
204
  await walk(base, "")
182
- if (hits.length === 0) return "(no matches)"
183
205
 
184
- // §6.28:一次调用一个档记忆表;命中行与上下文行都在原有文案前镀前缀(判据是**档**不是行——
185
- // 不标则同一档的上下文行读起来像普通档的内容)。打标在 `truncate` 之前,不新增截断点。
206
+ // §7.1:一次调用一个档记忆表;命中行与上下文行都在原有文案前镀前缀(判据是**档**不是行——
207
+ // 不标则同一档的上下文行读起来像普通档的内容)。层标识紧随既有过程档前缀之后:
208
+ // `[process doc: not a design basis] [design] path:line: text`。打标在 `truncate` 之前,不新增截断点。
186
209
  const markCache = new Map()
210
+ const layerCache = new Map()
187
211
  const mark = (f) => (isProcessDocPath(f, markCache) ? `${PROCESS_DOC_MARK} ` : "")
212
+ const lead = (f) => `${mark(f)}[${docLayerName(f, layerCache)}] `
213
+ // 报数 N = 本次输出里被判为过程档的行(排除模式 = 被排掉的行;取回模式 = 进来的行)。
214
+ const reported = includeProcessDocs ? hits.filter((h) => isProcessDocPath(h.file, markCache)).length : excludedRows
215
+ const withReport = (body) => (reported > 0 ? `${body}\n${processDocsReport(reported, includeProcessDocs)}` : body)
216
+ if (hits.length === 0) return withReport("(no matches)")
188
217
 
189
- // No context: keep original path:line: content format
218
+ // No context: one line per hit — layer label first, then the original path:line: content shape.
190
219
  if (!wantCtx) {
191
- return truncate(hits.map((h) => `${mark(h.file)}${h.file}:${h.line}: ${h.text}`).join("\n"))
220
+ return withReport(truncate(hits.map((h) => `${lead(h.file)}${h.file}:${h.line}: ${h.text}`).join("\n")))
192
221
  }
193
222
 
194
223
  // With context: matching lines use ':', context lines use '-' (like ripgrep); overlapping ranges in same file are merged and de-duplicated
@@ -206,10 +235,10 @@ export const grepTool = {
206
235
  }
207
236
  for (const l of [...lineSet].sort((a, b) => a - b)) {
208
237
  const sep = matchedLines.has(l) ? ":" : "-"
209
- out.push(`${mark(file)}${file}${sep}${l}${sep} ${lines[l - 1]}`)
238
+ out.push(`${lead(file)}${file}${sep}${l}${sep} ${lines[l - 1]}`)
210
239
  }
211
240
  }
212
- return truncate(out.join("\n"))
241
+ return withReport(truncate(out.join("\n")))
213
242
  },
214
243
  }
215
244
 
@@ -221,6 +250,7 @@ export const lsTool = {
221
250
  properties: {
222
251
  path: { type: "string", description: "Directory path (default cwd)" },
223
252
  filter: { type: "string", description: "Only list entries matching this glob (e.g. '*.mjs', '*test*')" },
253
+ includeProcessDocs: { type: "boolean", description: INCLUDE_PROCESS_DOCS_DESC },
224
254
  },
225
255
  },
226
256
  readonly: true,
@@ -234,24 +264,42 @@ export const lsTool = {
234
264
  if (e.code === "ENOENT" || e.code === "ENOTDIR") throw new Error(`ls: ${args.path ?? "."} — ${e.code === "ENOTDIR" ? "not a directory" : "not found"}`, { cause: e })
235
265
  throw e
236
266
  }
267
+ // 默认排除只判**档结果**、不判目录节点(目录不是档;否则过程层目录自身从上一级列表消失)。
268
+ // 名额窗口 = 能渲染到的那 500 条:扫到第 500 条就停,两种模式因此在**同一批条目**上计数——
269
+ // 否则排除式数全目录、取回式只数前 500,报数字描述的就不是同一批条目。
270
+ const includeProcessDocs = args.includeProcessDocs === true
271
+ const procCache = new Map()
272
+ const layerCache = new Map()
273
+ let excluded = 0
274
+ const kept = []
275
+ for (const e of entries) {
276
+ if (filterRe && !filterRe.test(e.name)) continue
277
+ if (kept.length >= 500) break
278
+ if (!includeProcessDocs && !e.isDirectory() && isProcessDocPath(join(abs, e.name), procCache)) { excluded += 1; continue }
279
+ kept.push(e)
280
+ }
237
281
  const rows = await Promise.all(
238
- entries
239
- .filter((e) => !filterRe || filterRe.test(e.name))
240
- .slice(0, 500)
241
- .map(async (e) => {
282
+ kept.map(async (e) => {
242
283
  const s = await stat(join(abs, e.name)).catch(() => null)
243
284
  const isDir = e.isDirectory()
285
+ const proc = isDir ? false : isProcessDocPath(join(abs, e.name), procCache)
286
+ // 层标识跟在条目名之后——本行的字形与列宽本身是结构,行首留给 `d`/`-` 与尺寸列。
287
+ const label = isDir ? "" : ` [${docLayerName(join(abs, e.name), layerCache)}]`
244
288
  return {
245
289
  dir: isDir,
246
- name: e.name + (isDir ? "/" : ""),
290
+ proc,
291
+ name: e.name + (isDir ? "/" : "") + label,
247
292
  size: s?.size ?? 0,
248
293
  mtime: s ? s.mtime.toISOString().slice(0, 16).replace("T", " ") : "?",
249
294
  }
250
295
  }),
251
296
  )
252
297
  rows.sort((a, b) => (a.dir === b.dir ? a.name.localeCompare(b.name) : a.dir ? -1 : 1))
253
- if (rows.length === 0) return "(no entries)"
298
+ // 报数 N = 本次输出里被判为过程档的条目(排除模式 = 被排掉的条目;取回模式 = 进来的条目)。
299
+ const reported = includeProcessDocs ? rows.filter((r) => r.proc).length : excluded
300
+ if (rows.length === 0) return reported > 0 ? `(no entries)\n${processDocsReport(reported, includeProcessDocs)}` : "(no entries)"
254
301
  const out = rows.map((r) => `${r.dir ? "d" : "-"} ${r.name.padEnd(40)} ${String(r.size).padStart(10)} ${r.mtime}`)
255
- return truncate(out.join("\n"))
302
+ const body = truncate(out.join("\n"))
303
+ return reported > 0 ? `${body}\n${processDocsReport(reported, includeProcessDocs)}` : body
256
304
  },
257
305
  }
package/tools/shared.mjs CHANGED
@@ -7,7 +7,8 @@ import { execFile } from "node:child_process"
7
7
  import { readFileSync, existsSync, realpathSync, readdirSync, statSync, openSync, readSync, closeSync } from "node:fs"
8
8
  import { dirname, join, resolve } from "node:path"
9
9
  import { fileURLToPath } from "node:url"
10
- import { loadToolDoc, applyPromptInjections } from "../prompt-files.mjs"
10
+ import { loadToolDoc, applyPromptInjections, expandKnowledgeTopics } from "../prompt-files.mjs"
11
+ import { WORK_MODES } from "../config-migrate.mjs"
11
12
  import { spawnGit, gitTimeoutNote, GIT_TIMEOUT_MS } from "./git-run.mjs"
12
13
 
13
14
  const __dirname = dirname(fileURLToPath(import.meta.url))
@@ -21,27 +22,9 @@ export const DESC = (name) => loadToolDoc(name)
21
22
  export const MAX_READ_LINES = 2000
22
23
  export const MAX_OUTPUT_CHARS = 200_000
23
24
 
24
- // ─── 写门 `ledger` 参数(2026-11-03 笔-账绑定批 · 设计档 §2.3「工具 schema 面」)───────────────
25
- // 描述单源:十二把入口工具的 `parameters.properties.ledger` 共用下面这一条(文面逐字 = 设计档 §2.3)。
26
- // 为什么放这里:同一个参数在十二处各写一遍 = 同一机制十二份描述,措辞一旦漂移,模型读到的规则就有十二版;
27
- // 而 `git` ∥ `manifest` ∥ `memory` 的差异只是各接一句「本工具的哪一径要号」——差异走后缀,不复制全文。
28
- // 为什么不进 `required`(决策 35):`required` 是静态字面,而这十二把工具在两模式、子代理、出辖目标下共用;
29
- // 静态必填会让普通模式读到一条不成立的强制(写锁仅工程模式),也让子代理读到一条没人核的要求。
30
- // 机械强制在门(缺号即拒),schema 只负责让模型知道有这个参数;拒文因此是唯一教学面(决策 38)。
31
- export const LEDGER_PARAM_DESC = '本笔调用服务的在途台账号,`"#N"` 或 `"N"`;工程模式下父侧不带 = 拒'
32
- /** `git`:写型 action 要号、只读 action 不要(决策 37——枚举可判,不猜命令字面)。 */
33
- export const LEDGER_PARAM_DESC_GIT = LEDGER_PARAM_DESC
34
- + ';只读 action(`diff` ∥ `status` ∥ `log` ∥ `show` ∥ `ls-remote` ∥ `blame` ∥ 各 `*Action:"list"`)不需传号'
35
- /** `manifest`:只有 `init` ∥ `write` 写项目内档(决策 39)。 */
36
- export const LEDGER_PARAM_DESC_MANIFEST = LEDGER_PARAM_DESC + ';仅 `init` ∥ `write` 要号,`read` 不要'
37
- /** `memory`:只有 `layer:"project"` 写项目内 `.thincoder/memory/**`(决策 39;`put` 缺省 `personal`)。 */
38
- export const LEDGER_PARAM_DESC_MEMORY = LEDGER_PARAM_DESC
39
- + ';仅落 project 层的写型 action 要号:`layer:"project"`,或省略 `layer`、单条删除且 id 以 `project:` 开头(此时层由前缀定;`personal` ∥ `team` 落用户数据目录,不要号)'
40
- /** 写门 `project` 参数(2026-11-03 项目声明面批 · 设计档 §2.3「工具 schema 面」/ 决策 40):项目根路径(带
41
- * `PROJECT-MANIFEST.json` 的那个目录)—— 台账按项目根算键,所以「传项目」就是把这个根传进来,零映射表。
42
- * 五把可能缺定位参数的工具(`bash` ∥ `memory` ∥ `execute` ∥ `git` ∥ `manifest`)共用这一条(文面逐字 = 设计档
43
- * §2.3);写盘七件不加——目标路径恒在。定位参数在场时以它为准,`project` 只补位;纯声明,不改执行目录。 */
44
- export const PROJECT_PARAM_DESC = '本笔调用服务的项目根——带 `PROJECT-MANIFEST.json` 的那个目录(绝对路径,或相对会话 cwd);工程模式下父侧 `bash` ∥ `memory` 必带,`execute` ∥ `git` ∥ `manifest` 在定位参数缺位时必带。纯声明:不改执行目录(`bash` 仍在会话 cwd 执行,`workdir` 才是改执行目录的那个)。'
25
+ // 写门两参的说明文本已搬出本档(设计 TOOLS §1.2):文本单点 = `./write-gate-params.mjs`,这里只转出同一常量,
26
+ // 八处导入档的导入面(`from "./shared.mjs"`)一个字不改。
27
+ export { LEDGER_PARAM_DESC, LEDGER_PARAM_DESC_MEMORY, PROJECT_PARAM_DESC } from "./write-gate-params.mjs"
45
28
 
46
29
  const ENCODING_DETECT_MAX_TRIM = 3
47
30
  const SYNTAX_CHECK_TIMEOUT = 10000
@@ -185,16 +168,35 @@ export function findCandidates(lines, oldString, topN = 3, threshold = 0.5) {
185
168
  /** Appended to hashline_edit results when the file contains U+FFFD (encoding-corruption probe). */
186
169
  export const FFFD_WARNING = "⚠ file contains U+FFFD (replacement char) — encoding may be corrupted; hash-based addressing may be unreliable. Consider fixing the file encoding first."
187
170
 
171
+ /**
172
+ * 工具描述分档展开薄壳(设计 TOOLS §1 ∥ PROMPT-SYSTEM 设计档 §2 §7):锚**独占一行**才算锚——完整档把那一行
173
+ * 换成主题正文,极简档把那一行原样留下;句子里夹着的同形文字两档都按正文原样进模型可见文本,既不展开也不删。
174
+ * 展开体一律交 `prompt-files.mjs` 的 `expandKnowledgeTopics`——壳只校验 mode 并选极简支,不复刻锚文法
175
+ * (另起一套展开器 = 整行锚定那条规则写在两处,漂一处查不出)。
176
+ * mode **必填、不给缺省**:缺省会让一次运行悄悄用上另一档的文本,而错处要到模型按错文本行事时才显形。
177
+ * 非字符串描述恒等过(无锚可展开——与下方 `applyPromptInjections` 同一判据)。
178
+ */
179
+ export function expandToolDescription(text, mode) {
180
+ if (mode === undefined) throw new Error(`tool description: mode is required — pass one of ${WORK_MODES.join(" / ")}; no default is applied (a missing mode silently renders another tier's text)`)
181
+ if (!WORK_MODES.includes(mode)) throw new Error(`tool description: mode must be one of ${WORK_MODES.join(" / ")} — got ${JSON.stringify(mode)}`)
182
+ if (typeof text !== "string") return text
183
+ return expandKnowledgeTopics(text, { tiny: mode === "tiny" })
184
+ }
185
+
188
186
  /** Convert to OpenAI tools parameter format.
189
- * 锚替换缝(CORE-UNIFICATION §2.13.8——U0):`description` 经 `applyPromptInjections`
190
- * (未配置 = 恒等);两个调用点(`agent/setup.mjs` · `advisor/loop.mjs`)同经本函数。
191
- * 非字符串 description 恒等过(无锚可替换)。*/
192
- export function toOpenAISchema(tool) {
187
+ * 分档缝 + 锚替换缝:`description` 先按 mode 展开知识锚(`expandToolDescription`)、再跑
188
+ * `applyPromptInjections`。顺序不可倒——注入值由端侧提供,倒过来会把注入值当主题锚再展开一次。
189
+ * 调用点与各自传的档见设计 TOOLS §1 的表:主链按会话现读的 mode,其余五面取完整档 `"normal"`。
190
+ * 非字符串 description 恒等过(无锚可替换)。
191
+ * `descriptionPostProcess`(可选钩子)跑在两者之后:宿主端对某端不存在的动作做行级剔除,剔的必须是
192
+ * **装配完的那份描述**(设计 TOOLS §1.1)——锚展开在装配期,剔除点放在展开之前就看不到展开面的内容。*/
193
+ export function toOpenAISchema(tool, mode) {
194
+ const assembled = applyPromptInjections(expandToolDescription(tool.description, mode))
193
195
  return {
194
196
  type: "function",
195
197
  function: {
196
198
  name: tool.name,
197
- description: applyPromptInjections(tool.description),
199
+ description: typeof tool.descriptionPostProcess === "function" ? tool.descriptionPostProcess(assembled) : assembled,
198
200
  parameters: tool.parameters,
199
201
  },
200
202
  }
package/tools/ssh.mjs CHANGED
@@ -65,24 +65,24 @@ export const sshTool = {
65
65
  parameters: {
66
66
  type: "object",
67
67
  properties: {
68
- action: { type: "string", enum: SSH_ACTIONS, description: "Action to run (one per call): connect | send | read | secret_input | close | list | credentials | forget | put | get." },
68
+ action: { type: "string", enum: SSH_ACTIONS, description: "The action to run (one per call)." },
69
69
  host: { type: "string", description: "connect / forget: target host (IP or name)." },
70
70
  user: { type: "string", description: "connect: login user (optional: your local ssh config decides, else the user recorded for this host locally)." },
71
71
  port: { type: "number", description: "connect / forget: TCP port (optional, default 22)." },
72
72
  label: { type: "string", description: "connect: short human label for this session (optional); secret_input: label for the value being sent." },
73
- promptPattern: { type: "string", description: "connect: regex that marks the shell prompt as ready (optional; the default recognises lines ending in # > $ %): without a hit, send/read on a slow device wait out the full timeout instead of returning early." },
73
+ promptPattern: { type: "string", description: "connect: regex marking the shell prompt as ready (optional; the default matches lines ending in # > $ %). Without a hit, send/read on a slow device waits out the full timeout instead of returning early." },
74
74
  id: { type: "string", description: "send / read / secret_input / close / put / get: session id from connect (`ssh#N`)." },
75
75
  data: { type: "string", description: "send: text to type into the session (a trailing newline is passed as-is; otherwise Enter is sent as `\\r`)." },
76
76
  settle: { type: "boolean", description: "send: wait for the ready verdict before returning (default true); false returns right after the bytes are written." },
77
- timeoutMs: { type: "number", description: "send / read: wait budget override (default 60000) — a return happens the moment the device is waiting for input (prompt, `--More--`, a y/n or password prompt); on expiry the call returns partial output plus a line naming what was not seen. put / get: transfer budget override (default 600000) — on expiry the process tree is killed." },
77
+ timeoutMs: { type: "number", description: "send / read: wait budget override (default 60000). The call returns as soon as the device waits for input (prompt, `--More--`, a y/n or password prompt); on expiry you get partial output plus a line naming what was not seen. put / get: transfer budget override (default 600000); on expiry the process tree is killed." },
78
78
  maxChars: { type: "number", description: "read: return-window override (default 8000) — head 60% + a note + tail 40%; the omitted middle is kept in the session, so the next read collects it." },
79
79
  identityFile: { type: "string", description: "connect: private-key path to offer (`-i`, `~` expands); remembered for this host and reused when omitted (optional)." },
80
80
  localPath: { type: "string", description: "put / get: local file path (`~` expands; a file, never a directory)." },
81
81
  remotePath: { type: "string", description: "put / get: path of the file on the session host (`/flash/img.bin`)." },
82
- overwrite: { type: "boolean", description: "get only: replace an existing local file (default false — an existing target is refused, never overwritten silently). put follows scp's own semantics: a same-named remote file is replaced." },
82
+ overwrite: { type: "boolean", description: "get only: replace an existing local file (default false — an existing target is refused, never overwritten silently). `put` follows scp's own semantics: a same-named remote file is replaced." },
83
83
  protocol: { type: "string", enum: ["scp", "sftp"], description: "put / get: `scp` = classic SCP protocol, the default and what network devices speak; `sftp` = the SFTP subsystem, for hosts that only offer that. No automatic fallback between them." },
84
84
  // 写门接面(⑬ ④):`get` 往项目内落盘 ⇒ 与 `write` 同一道门——那一道门读的就是本参数。
85
- ledger: { type: "string", description: LEDGER_PARAM_DESC + ";仅 `get` 要号,`put` 写的是远端主机,不要" },
85
+ ledger: { type: "string", description: LEDGER_PARAM_DESC + "; only `get` needs one — `put` writes the remote host." },
86
86
  },
87
87
  required: ["action"],
88
88
  },
package/tools/tree.mjs CHANGED
@@ -11,6 +11,8 @@ import { join, basename, extname } from "node:path"
11
11
  // 两项旧值随之退场:`turbo`(无点,笔误——另三份都是 `.turbo`)、`bin`(`thincoder-cli/bin/**`
12
12
  // 是 CLI 入口、产品代码,不该从任何面上被剪掉)。
13
13
  import { SKIP_DIRS } from "../skip-dirs.mjs"
14
+ // 过程档默认排除 + 层标识(机制 = `docs/core/design/TOOLS.md` §7.1):只对**档结果**判,目录节点照留。
15
+ import { isProcessDocPath, docLayerName, processDocsReport } from "./process-doc-mark.mjs"
14
16
 
15
17
  const MAX_ENTRIES = 200
16
18
  const DEFAULT_DEPTH = 3
@@ -38,6 +40,7 @@ export const treeTool = {
38
40
  properties: {
39
41
  path: { type: "string", description: "Root directory (default cwd)" },
40
42
  depth: { type: "integer", description: `Tree depth (default ${DEFAULT_DEPTH}, max 6)` },
43
+ includeProcessDocs: { type: "boolean", description: "Include process-layer docs (batch records, archived material) — omitted = excluded by default; true = include them" },
41
44
  },
42
45
  required: [],
43
46
  },
@@ -51,13 +54,22 @@ export const treeTool = {
51
54
  const d = Number(args.depth)
52
55
  const maxDepth = Number.isInteger(d) && d > 0 ? Math.min(d, 6) : DEFAULT_DEPTH
53
56
  const lines = [basename(root) + "/"]
54
- const state = { count: 1, capped: false }
55
- await walk(root, 0, maxDepth, "", lines, state)
56
- return truncate(lines.join("\n"))
57
+ // 被排除的档先移出 `items`,再算 `├──` ∥ `└──` 与 `state.count`:末项字形不落在被排除的条目上,
58
+ // 「…(更多项已省略)」也落在存活条目之后。`MAX_ENTRIES` 与 `truncate` 都不变。
59
+ const opts = {
60
+ includeProcessDocs: args.includeProcessDocs === true,
61
+ procCache: new Map(),
62
+ layerCache: new Map(),
63
+ }
64
+ const state = { count: 1, capped: false, excluded: 0, included: 0 }
65
+ await walk(root, 0, maxDepth, "", lines, state, opts)
66
+ const body = truncate(lines.join("\n"))
67
+ const n = opts.includeProcessDocs ? state.included : state.excluded
68
+ return n > 0 ? `${body}\n${processDocsReport(n, opts.includeProcessDocs)}` : body
57
69
  },
58
70
  }
59
71
 
60
- async function walk(dir, depth, maxDepth, prefix, lines, state) {
72
+ async function walk(dir, depth, maxDepth, prefix, lines, state, opts) {
61
73
  if (state.capped) return
62
74
  let entries
63
75
  try { entries = await readdir(dir, { withFileTypes: true }) } catch { return }
@@ -68,17 +80,27 @@ async function walk(dir, depth, maxDepth, prefix, lines, state) {
68
80
  if (isDir) { if (SKIP_DIRS.has(e.name)) continue; items.push({ name: e.name, isDir: true }) }
69
81
  else if (!BINARY_EXTS.has(extname(e.name).toLowerCase())) items.push({ name: e.name, isDir: false })
70
82
  }
71
- items.sort((a, b) => (a.isDir === b.isDir ? a.name.localeCompare(b.name) : a.isDir ? -1 : 1))
83
+ const kept = []
84
+ for (const it of items) {
85
+ if (it.isDir) { kept.push(it); continue }
86
+ const proc = isProcessDocPath(join(dir, it.name), opts.procCache)
87
+ if (proc && !opts.includeProcessDocs) { state.excluded += 1; continue }
88
+ if (proc) state.included += 1
89
+ kept.push(it)
90
+ }
91
+ kept.sort((a, b) => (a.isDir === b.isDir ? a.name.localeCompare(b.name) : a.isDir ? -1 : 1))
72
92
 
73
- for (let i = 0; i < items.length; i++) {
93
+ for (let i = 0; i < kept.length; i++) {
74
94
  if (state.capped) return
75
95
  if (state.count >= MAX_ENTRIES) { state.capped = true; lines.push(prefix + "…(更多项已省略)"); return }
76
- const { name, isDir } = items[i]
77
- const isLast = i === items.length - 1
78
- lines.push(prefix + (isLast ? "└── " : "├── ") + (isDir ? name + "/" : name))
96
+ const { name, isDir } = kept[i]
97
+ const isLast = i === kept.length - 1
98
+ // 层标识跟在条目名之后(本行字形是结构);目录行不带——目录不是档。
99
+ const text = isDir ? name + "/" : `${name} [${docLayerName(join(dir, name), opts.layerCache)}]`
100
+ lines.push(prefix + (isLast ? "└── " : "├── ") + text)
79
101
  state.count++
80
102
  if (isDir && depth + 1 < maxDepth) {
81
- await walk(join(dir, name), depth + 1, maxDepth, prefix + (isLast ? " " : "│ "), lines, state)
103
+ await walk(join(dir, name), depth + 1, maxDepth, prefix + (isLast ? " " : "│ "), lines, state, opts)
82
104
  }
83
105
  }
84
106
  }
@@ -54,7 +54,7 @@ export function backendMode(cfg, key) {
54
54
  }
55
55
 
56
56
  /** First qualifying channel in stored order → `{ apiKey }` | null. Never throws. */
57
- function deepseekChannel(cfg) {
57
+ export function deepseekChannel(cfg) {
58
58
  const list = Array.isArray(cfg?.providersList) ? cfg.providersList
59
59
  : Array.isArray(cfg?.providers) ? cfg.providers : []
60
60
  for (const entry of list) {
package/tools/web.mjs CHANGED
@@ -102,7 +102,7 @@ export const websearchTool = {
102
102
  limit: { type: "number", description: "Max results (default 8, max 20)" },
103
103
  engine: { type: "string", enum: ENGINE_NAMES, description: "Specific engine — \"bing\" (Bing). Omit to search all engines concurrently." },
104
104
  page: { type: "number", description: "Page number for pagination (1-based, default 1). Only used when engine is specified." },
105
- proxy: { type: "string", description: "http://host:port explicit proxy (optional) — use ONLY when passed; no proxy = direct. config.json proxy is NOT auto-applied (2026-08-31 ruling: fixed config breaks domestic sites)" },
105
+ proxy: { type: "string", description: "`http://host:port` explicit proxy. Use ONLY when passed; no proxy = direct. config.json's proxy is NOT auto-applied — pick per target (github and foreign sites usually need one, domestic ones do not)." },
106
106
  },
107
107
  required: ["query"],
108
108
  },
@@ -207,7 +207,7 @@ export const fetchTool = {
207
207
  type: "object",
208
208
  properties: {
209
209
  url: { type: "string", description: "http/https URL" },
210
- proxy: { type: "string", description: "http://host:port explicit proxy (optional) — use ONLY when passed; no proxy = direct. config.json proxy is NOT auto-applied (2026-08-31 ruling); pick per target (github/foreign sites need a proxy, gitee/domestic don't)" },
210
+ proxy: { type: "string", description: "`http://host:port` explicit proxy. Use ONLY when passed; no proxy = direct. config.json's proxy is NOT auto-applied — pick per target (github and foreign sites usually need one, domestic ones do not)." },
211
211
  },
212
212
  required: ["url"],
213
213
  },
@@ -0,0 +1,31 @@
1
+ /**
2
+ * write-gate-params.mjs — 写门两参的说明文本单点(设计 TOOLS §1.2)。
3
+ *
4
+ * 为什么单独一档:`tools/shared.mjs` 越过了 500 行设计时线(`docs/core/standards/CODE-TIER.md` §7 的量法),
5
+ * 而这三条常量是它里面唯一能整块搬走、且搬走不动任何调用语义的部分。`tools/shared.mjs` 仍转出同一常量,
6
+ * 八处导入档的导入面一个字不改——文本单点与导入面分开,改口径只改一处,消费面不跟着改名。
7
+ *
8
+ * 两条身份句只答「这一笔该传什么」;完整口径(哪一档生效 ∥ 哪些工具必带 ∥ 缺什么怎么被拒)只讲一次,
9
+ * 在 `prompts/discipline-engineering.md` 的写门参数一节。参数行不重述它:每个入口工具各带一份近乎逐字的
10
+ * 副本,改一处口径要改每一处,漏一处就是两套规则在跑。
11
+ */
12
+
13
+ // ─── 写门 `ledger` 参数(2026-11-03 笔-账绑定批 · 设计档 §2.3「工具 schema 面」)───────────────
14
+ // 描述单源:入口集十一把工具的 `parameters.properties.ledger` 共用下面这一条。
15
+ // 为什么放一处:同一个参数在十一处各写一遍 = 同一机制十一份描述,措辞一旦漂移,模型读到的规则就有十一版;
16
+ // 而 `memory` 的差异只是各接一句「本工具的哪一径要号」——差异走后缀,不复制全文。
17
+ // 为什么不进 `required`(决策 35):`required` 是静态字面,而这十一把工具在两模式、子代理、出辖目标下共用;
18
+ // 静态必填会让普通模式读到一条不成立的强制(写锁仅工程模式),也让子代理读到一条没人核的要求。
19
+ // 机械强制在门(缺号即拒),schema 只负责让模型知道有这个参数;拒文因此是唯一教学面(决策 38)。
20
+ export const LEDGER_PARAM_DESC = 'In-flight ledger row this call serves: `"#N"` or `"N"`'
21
+ /** `memory`:只有 `layer:"project"` 写项目内 `.thincoder/memory/**`(决策 39;`put` 缺省 `personal`)。 */
22
+ export const LEDGER_PARAM_DESC_MEMORY = LEDGER_PARAM_DESC
23
+ + '; only write actions landing in the `project` layer need one. Pass `layer:"project"`, or omit `layer` on a single delete whose id starts `project:` — the prefix picks the layer. `personal` and `team` land in the user data directory and need none.'
24
+ /** 写门 `project` 参数(2026-11-03 项目声明面批 · 设计档 §2.3「工具 schema 面」/ 决策 40):项目根路径(带
25
+ * `PROJECT-MANIFEST.json` 的那个目录)—— 台账按项目根算键,所以「传项目」就是把这个根传进来,零映射表。
26
+ * 定位参数在场时以它为准,`project` 只补位;纯声明,不改执行目录(第二句因此是语义,不是「何时必带」)。
27
+ * 为什么写盘七件也各带一格(2026-11-08 工作区根窄口批 · 设计档 §2.3.1):它们的定位参数是一支支目标路径,
28
+ * 而「目标取不到项目根」真会发生(工作区根的文件)——那时 `project` 是唯一可用的判据点,schema 不给
29
+ * 这一格,门里的口子就永远触发不了(模型不知道有这个参数,第一次撞的还是拒文)。何时必带那条口径
30
+ * 在工程纪律段的写门参数一节,参数行只留身份。 */
31
+ export const PROJECT_PARAM_DESC = 'Project root: the directory holding `PROJECT-MANIFEST.json` (absolute or cwd-relative). Declaration only — `workdir` changes cwd.'