@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
package/conventions.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * conventions.mjs — the single authority for code / doc / temp / aux path classification,
3
- * plus the project declaration surface (the three declaration families of the project's
4
- * `PROJECT-MANIFEST.json`: `codePaths` / `index.*` / `advisor.*`).
3
+ * plus the project declaration surface (the declaration families of the project's
4
+ * `PROJECT-MANIFEST.json`: `codePaths` / `index.*` — the `advisor` family is retired and
5
+ * dropped on write, so it is not part of this surface).
5
6
  *
6
7
  * Why one module: the write-domain gates and guards (design gate, review-doc gate,
7
8
  * mutation accounting, verify fast path) each carried their own copy of the
@@ -23,12 +24,13 @@
23
24
  * visible warning per load (existence check only — zero content parsing — KD-M1-34).
24
25
  *
25
26
  * Classification vocabulary (PORTABILITY design §3.2):
26
- * code — inside a declared code segment (default: the path segment `src`), or the
27
- * fallback; doc — documentation extension outside any code segment and not
28
- * scratch; temp — tmp-* name or .tmp/.temp extension; aux — a default
29
- * auxiliary-path segment sequence (test / tests / scripts / .thincoder/tmp — F9)
30
- * that matched no code segment and neither doc nor temp; state — a project state
31
- * file (`PROJECT-MANIFEST.json` basename ∥ `.thincoder/conventions.json` pair — #941).
27
+ * code — inside a declared code segment (none by default: a project declares
28
+ * `codePaths`), or the fallback; doc — documentation extension outside any
29
+ * code segment and not scratch; temp — tmp-* name or .tmp/.temp extension;
30
+ * aux — a default auxiliary-path segment sequence (test / tests / scripts /
31
+ * .thincoder/tmp — F9) that matched no code segment and neither doc nor temp;
32
+ * state — a project state file (`PROJECT-MANIFEST.json` basename ∥
33
+ * `.thincoder/conventions.json` pair — #941).
32
34
  * Precedence: code segment → temp → doc → aux → state → fallback code.
33
35
  *
34
36
  * Segment matching runs on the PROJECT-ROOT-RELATIVE FACE of a path (D17 · 2026-09-28): the
@@ -189,4 +191,4 @@ export function isStatePath(p, conv) {
189
191
  // 迁出面(2026-10-01 拆分批 · #755 ∥ #786):声明装载面外提 `declaration.mjs`——本档经
190
192
  // 转口保名(消费面 / 单元测试档 import 面零改;`DEFAULT_DECLARATION` 另供本档分类裁判缺省取用)。
191
193
  // ─────────────────────────────────────────────────────────────────────────────
192
- export { loadProjectDeclaration, declarationForTarget, DEFAULT_DECLARATION, isExcludedRelPath, declaredIndexScope, isInDeclaredScope, declaredPublicRoots, clearDeclarationCache } from "./declaration.mjs"
194
+ export { loadProjectDeclaration, declarationForTarget, DEFAULT_DECLARATION, isExcludedRelPath, declaredIndexScope, isInDeclaredScope, declaredPublicRoots, declaredWritableRoots, clearDeclarationCache, docLayers, docLayerOf } from "./declaration.mjs"
package/declaration.mjs CHANGED
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { existsSync, readdirSync, statSync } from "node:fs"
9
9
  import { basename, dirname, isAbsolute, join, parse, relative, resolve } from "node:path"
10
- import { DEFAULT_MANIFEST, MANIFEST_REL, docRootPaths, manifestFilePath, onManifestInit, owningProject, readManifest } from "./manifest.mjs"
10
+ import { DEFAULT_MANIFEST, MANIFEST_REL, docRootBase, docRootPaths, manifestFilePath, onManifestInit, owningProject, readManifest } from "./manifest.mjs"
11
11
  import { isSkippedRelPath } from "./memory/file-walk.mjs" // 面⑦ 子目录扫描的跳过段谓词单源(零环:file-walk 不引本档)
12
12
  import { logEvent } from "./log.mjs"
13
13
 
@@ -49,8 +49,10 @@ function normalizeCodePaths(v) {
49
49
  return out
50
50
  }
51
51
 
52
- /** 路径列表归一(单源——`index.excludePaths` §6.14 ∥ `index.publicRepos` §6.15 同款):首部 `./` 剥离 · `\`→`/` · 去尾斜杠 · 空 ∕ 非串剔除 · 去重保序。 */
53
- function normalizePathList(v) {
52
+ /** 路径列表归一(单源——`index.excludePaths` §6.14 ∥ `index.publicRepos` §6.15 同款):首部 `./` 剥离 · `\`→`/` · 去尾斜杠 · 空 ∕ 非串剔除 · 去重保序。
53
+ * **导出**:第三个消费面 = `doc_check` 的排除面(`index.docCheckExcludePaths`——机制见 `docs/core/design/DOC-CHECK.md` §10)。
54
+ * 两个键各写一份归一,语义必然漂;差别只该在「谁吃这个清单」,不应在「怎么认路径」。 */
55
+ export function normalizePathList(v) {
54
56
  if (!Array.isArray(v)) return []
55
57
  const out = []
56
58
  for (const e of v) {
@@ -75,7 +77,9 @@ function buildDeclaration(m, root = null) {
75
77
  const docExtensions = normalizeExtensions(m?.index?.docExtensions)
76
78
  const excludePaths = normalizePathList(m?.index?.excludePaths)
77
79
  const publicRepos = normalizePathList(m?.index?.publicRepos)
80
+ const writableRepos = normalizePathList(m?.index?.writableRepos)
78
81
  const batchRecords = batchSegments(m?.docRoot?.batches) // §6.14 面⑥ 声明值投影(`declared` 旗不涉——docRoot 族现状零改)
82
+ const docRoot = docRootTables(m?.docRoot, root) // 层投影(机制 = `docs/core/design/DOC-SYSTEM.md` §3.1「层标识」)
79
83
  const defaults = normalizeCodePaths(DEFAULT_MANIFEST.codePaths) ?? []
80
84
  const pathsDiffer = codePaths.length !== defaults.length || codePaths.some((p, i) => p !== defaults[i])
81
85
  const declared = pathsDiffer || codeExtensions.length > 0 || docExtensions.length > 0 || excludePaths.length > 0 || publicRepos.length > 0
@@ -83,11 +87,15 @@ function buildDeclaration(m, root = null) {
83
87
  declared,
84
88
  codePaths: Object.freeze(codePaths),
85
89
  batchRecords: Object.freeze(batchRecords.map((s) => Object.freeze(s))),
90
+ docRoot,
86
91
  index: Object.freeze({
87
92
  codeExtensions: Object.freeze(codeExtensions),
88
93
  docExtensions: Object.freeze(docExtensions),
89
94
  excludePaths: Object.freeze(excludePaths),
90
95
  publicRepos: Object.freeze(publicRepos),
96
+ // 写权声明(机制 = `docs/core/design/CROSS-REPO-WRITE.md` §2.1):投影值,`declared` 旗不涉——
97
+ // 与 `docCheckExcludePaths` 族同款;写名单本身不是「本仓声明偏离默认」的证据。
98
+ writableRepos: Object.freeze(writableRepos),
91
99
  }),
92
100
  root,
93
101
  })
@@ -108,6 +116,29 @@ function batchSegments(v) {
108
116
  return out
109
117
  }
110
118
 
119
+ /** `docRoot` 六键 → 每键一张**根相对路径表**(`null` = 本仓没有这一层,原样保留;空表 = 声明了但展开为空)。
120
+ * 键序 = 模式表键序(`DEFAULT_MANIFEST.docRoot`),与声明文件里的书写序无关——层的出场序由此定。
121
+ * 展开单源 = `docRootPaths`(F7:归一 / 去重 / 禁 `..` 值都在那一处);本函数只把绝对形折回根相对
122
+ * 并剔除越根值,不另写路径运算——索引范围面与层投影吃同一张表(不各自再展开一次声明)。 */
123
+ function docRootTables(docRoot, root) {
124
+ const base = docRootBase(root ?? undefined)
125
+ const src = docRoot !== null && typeof docRoot === "object" && !Array.isArray(docRoot) ? docRoot : {}
126
+ const out = {}
127
+ for (const key of Object.keys(DEFAULT_MANIFEST.docRoot)) {
128
+ // 「本面无」是声明值(#944),不是缺键:原样保留 null,不折成空表、不补默认根。
129
+ if (src[key] === null) { out[key] = null; continue }
130
+ const rels = []
131
+ for (const abs of docRootPaths(src[key], root ?? undefined)) {
132
+ const rel = relative(base, abs).replace(/\\/g, "/")
133
+ const norm = rel === "" ? "." : rel
134
+ if (norm === ".." || norm.startsWith("../") || isAbsolute(norm)) continue // 越根值:条目子树内永不可命中
135
+ if (!rels.includes(norm)) rels.push(norm)
136
+ }
137
+ out[key] = Object.freeze(rels)
138
+ }
139
+ return Object.freeze(out)
140
+ }
141
+
111
142
  /** 约定段(面⑥——`DEFAULT_MANIFEST.docRoot.batches` 单源派生;默认值改名/迁移两处同动)。 */
112
143
  const DEFAULT_BATCH_SEGMENTS = batchSegments(DEFAULT_MANIFEST.docRoot.batches)
113
144
 
@@ -141,6 +172,62 @@ export function isExcludedRelPath(rel, decl, base = null) {
141
172
  return list.some((p) => p && (s === p || s.startsWith(`${p}/`)))
142
173
  }
143
174
 
175
+ // ─────────────────────────────────────────────────────────────────────────────
176
+ // 文档层投影(机制 = `docs/core/design/DOC-SYSTEM.md` §3.1「层标识」;接口 = `docs/core/design/MANIFEST.md` §2.13):
177
+ // 输入 = `loadProjectDeclaration` 回执的 `docRoot` 表,本族不读 manifest、不碰盘。键名逐字即层名。
178
+ // ─────────────────────────────────────────────────────────────────────────────
179
+
180
+ /** 层的权威属性(逐键:这层算不算权威层,仅供读者取用;层表本体由声明投影得出,不住本表)。
181
+ * 成员正文单源 = `docs/core/design/DOC-SYSTEM.md` §3.1「权威层 = `standards` ∪ `requirements` ∪ `design`。
182
+ * 其余层不享受检索注入的保底名额。」——消费者读 `docLayers` 的 `authority` 标志,不另持一份名单。 */
183
+ const LAYER_AUTHORITY = Object.freeze({ requirements: true, specs: false, design: true, modules: false, batches: false, standards: true })
184
+
185
+ /** 层表(有序 = `docRoot` 键序):`[{ layer, authority, roots }]`;`roots` = 根相对声明根表。
186
+ * `null` 或缺失的键不出行(声明了「本仓没有这一层」,不产出空层名);空表同理。
187
+ * @param {Readonly<object>|null} decl `loadProjectDeclaration` 回执
188
+ * @returns {Array<{layer: string, authority: boolean, roots: string[]}>}
189
+ */
190
+ export function docLayers(decl) {
191
+ const tables = decl?.docRoot
192
+ if (!tables || typeof tables !== "object") return []
193
+ const out = []
194
+ for (const layer of Object.keys(tables)) {
195
+ const roots = tables[layer]
196
+ if (!Array.isArray(roots) || roots.length === 0) continue
197
+ out.push({ layer, authority: LAYER_AUTHORITY[layer] === true, roots: [...roots] })
198
+ }
199
+ return out
200
+ }
201
+
202
+ /** 出辖 / 未入任何声明根的层标识(显式一档,不是空串)。 */
203
+ const UNLAYERED = Object.freeze({ layer: "unlayered", authority: false })
204
+
205
+ /** 档 → 层:`absPath` 按 `decl.root` 折成根相对,再按**最长**声明根前缀判层——`modules` 根嵌在
206
+ * `design` 根之内,按声明序或最短前缀判会把模块档判成权威层。
207
+ * 出辖(`decl` 缺 ∥ 根未知 ∥ 路径在该根之外)与未落入该声明的任何声明根 ⇒ `unlayered`、非权威。
208
+ * `decl` = 该路径的**属辖声明**(调用面经 `declarationForTarget` 取):声明公共源里的档因此按那个仓
209
+ * 自己的 `docRoot` 判层,不借会话项目的根。
210
+ * @param {string} absPath 档的绝对路径
211
+ * @param {Readonly<object>|null} decl `absPath` 的属辖声明
212
+ * @returns {{layer: string, authority: boolean}}
213
+ */
214
+ export function docLayerOf(absPath, decl) {
215
+ if (!decl || typeof decl.root !== "string" || decl.root === "") return UNLAYERED
216
+ let rel = relative(decl.root, resolve(String(absPath ?? ""))).replace(/\\/g, "/")
217
+ if (rel === "") rel = "."
218
+ if (rel === ".." || rel.startsWith("../") || isAbsolute(rel)) return UNLAYERED
219
+ let best = null
220
+ for (const { layer, authority, roots } of docLayers(decl)) {
221
+ for (const p of roots) {
222
+ const hit = p === "." || rel === p || rel.startsWith(`${p}/`)
223
+ if (!hit) continue
224
+ const depth = p === "." ? 0 : p.length
225
+ if (!best || depth > best.depth) best = { layer, authority, depth }
226
+ }
227
+ }
228
+ return best ? { layer: best.layer, authority: best.authority } : UNLAYERED
229
+ }
230
+
144
231
  // ─────────────────────────────────────────────────────────────────────────────
145
232
  // §6.14 面⑦ 索引范围声明化(结构门——2026-10-13 · 台账 #1367):范围 = 锚的**管辖 manifest**
146
233
  // 声明目录 ∪ **一级子目录**(带档者)声明目录——「未声明 ⇒ 不进」;条目集空 ⇒ 零索引
@@ -148,20 +235,15 @@ export function isExcludedRelPath(rel, decl, base = null) {
148
235
  // (本规 = 新增消费点,键值语义零改)。写面(收录)∥ 读面(存量行准入)共用本谓词族。
149
236
  // ─────────────────────────────────────────────────────────────────────────────
150
237
 
151
- /** 文档面前缀集合(条目根相对——`docRoot.*` 五子键合并展开;解析单源 = `docRootPaths`,F7):
238
+ /** 文档面前缀集合(条目根相对):读 `loadProjectDeclaration` 回执的 `docRoot` 表(层投影与索引范围面
239
+ * 共用同一张表——本函数不再自己展开一次声明,也没有第二次读 manifest 的入口)。
152
240
  * 值 = 根相对字面前缀(恰等 ∨ 后随 `/`——路径及子树;文件值如 `docs/RELEASE.md` ⇒ 恰该文件);
153
- * `"."` = 该条目根自身(整根面);越根值(`../` 形)剔除——条目子树内的文件永不可命中它。
154
- * 去重保序。 */
155
- function entryDocPaths(docRoot, root) {
241
+ * `"."` = 该条目根自身(整根面)。去重保序(序 = `docRoot` 键序)。 */
242
+ function entryDocPaths(tables) {
156
243
  const out = []
157
- if (docRoot === null || typeof docRoot !== "object" || Array.isArray(docRoot)) return out
158
- for (const key of Object.keys(DEFAULT_MANIFEST.docRoot)) {
159
- for (const abs of docRootPaths(docRoot[key], root)) {
160
- const rel = relative(root, abs).replace(/\\/g, "/")
161
- if (rel === "" || rel === ".") { if (!out.includes(".")) out.push("."); continue }
162
- if (rel === ".." || rel.startsWith("../") || isAbsolute(rel)) continue
163
- if (!out.includes(rel)) out.push(rel)
164
- }
244
+ if (!tables || typeof tables !== "object") return out
245
+ for (const key of Object.keys(tables)) {
246
+ for (const rel of tables[key] ?? []) if (!out.includes(rel)) out.push(rel)
165
247
  }
166
248
  return out
167
249
  }
@@ -182,12 +264,10 @@ function hasSegmentRun(face, seq) {
182
264
  * (坏 JSON ∥ 形态错)⇒ 两族按默认值参与 + 既有可见告警(声明链 KD-M1-32——`loadProjectDeclaration`
183
265
  * 的降级告警单源,本档零第二实现)——不静默成零。 */
184
266
  function scopeEntryOf(root) {
185
- const decl = loadProjectDeclaration(root)
186
- const r = readManifest(root)
187
- const docRoot = r.ok ? r.manifest.docRoot : DEFAULT_MANIFEST.docRoot // 档在场才补默认(无档 = 无条目,不走本函数)
267
+ const decl = loadProjectDeclaration(root) // 声明的**一次**读取(层投影与文档面同吃回执的 `docRoot`)
188
268
  return Object.freeze({
189
269
  root,
190
- docPaths: Object.freeze(entryDocPaths(docRoot, root)),
270
+ docPaths: Object.freeze(entryDocPaths(decl.docRoot)),
191
271
  codePaths: Object.freeze([...decl.codePaths]),
192
272
  })
193
273
  }
@@ -258,9 +338,15 @@ export function isInDeclaredScope(rel, scope, base = null) {
258
338
  */
259
339
  export function declaredPublicRoots(cwd) {
260
340
  const decl = loadProjectDeclaration(cwd)
261
- const list = decl?.index?.publicRepos
341
+ return absoluteDeclaredRoots(decl?.index?.publicRepos, decl, cwd)
342
+ }
343
+
344
+ /** 声明项 → 绝对根集(`declaredPublicRoots` ∥ `declaredWritableRoots` 共用的**取基法**,只有一份):
345
+ * 值形层逐项 `resolve(声明项目的项目根, p)` ⇒ 绝对根集(去重保序);存在性判归消费面(本层不判)。
346
+ * 两键不同族(读名单 / 写名单),但「从哪个根解析、怎么去重」是同一条规则——写第二份就会漂。 */
347
+ function absoluteDeclaredRoots(list, decl, cwd) {
262
348
  if (!Array.isArray(list) || list.length === 0) return []
263
- const base = typeof decl.root === "string" && decl.root !== "" ? decl.root : resolve(cwd ?? ".")
349
+ const base = typeof decl?.root === "string" && decl.root !== "" ? decl.root : resolve(cwd ?? ".")
264
350
  const out = []
265
351
  for (const p of list) {
266
352
  const abs = resolve(base, p)
@@ -269,6 +355,19 @@ export function declaredPublicRoots(cwd) {
269
355
  return out
270
356
  }
271
357
 
358
+ /**
359
+ * 声明**可写外部目录**的绝对根集(机制 = `docs/core/design/CROSS-REPO-WRITE.md` §2.1 解析层):
360
+ * 写门的跨仓判据用它回答「这个目标在写方声明的授权面里吗」——基数 = 声明项目的项目根,
361
+ * 缺省 `[]` ⇒ `[]`(零行为)。与 `declaredPublicRoots` 同形同基,但两键**不互派**(读名单 ≠ 写名单)。
362
+ * 不判存在性:声明根不在盘时它的前缀含不住任何真实目标,存在性归消费面。
363
+ * @param {string} [cwd] 会话锚(项目根经 manifest.mjs 解析)
364
+ * @returns {string[]} 绝对路径(去重保序)
365
+ */
366
+ export function declaredWritableRoots(cwd) {
367
+ const decl = loadProjectDeclaration(cwd)
368
+ return absoluteDeclaredRoots(decl?.index?.writableRepos, decl, cwd)
369
+ }
370
+
272
371
  /** 引用解析单点(§6.1 口径 4/5——写门 ∥ 迁移旗同消费,不得二写):① 仓根解析 `resolve(base, part)`
273
372
  * 为存在的档 ⇒ 命中;② 声明源前缀解析序:首段命中声明公共仓目录名(消费既有 `declaredPublicRoots`
274
373
  * ——同名多仓 ⇒ 声明序首者)⇒ 于该声明根解析余段;未声明 ∥ 声明根缺位 ∥ 目标档缺 ⇒ `{ ok: false, abs }`。
@@ -324,9 +423,14 @@ function warnRetiredCarrier(root) {
324
423
  * read error) → defaults + `console.warn` + a log event (visible degradation, never a throw).
325
424
  * A retired `.thincoder/conventions.json` at the manifest's project root → one warning
326
425
  * per cache miss (content zero-parsed, zero effect on the readings — KD-M1-34).
426
+ * `docRoot` = the layer projection (ONE place: the six keys → one root-relative table each;
427
+ * `null` = "this repository has no such layer", kept as `null`). It is the single input of
428
+ * `docLayers` / `docLayerOf` and of the index-scope face — neither re-expands the declaration.
327
429
  * @param {string} cwd — project dir / anchor (root resolved by manifest.mjs)
328
430
  * @returns {Readonly<{declared: boolean, codePaths: readonly string[], batchRecords: readonly (readonly string[])[],
329
- * index: {codeExtensions: string[], docExtensions: string[], excludePaths: string[], publicRepos: string[]},
431
+ * docRoot: Readonly<Record<string, readonly string[]|null>>,
432
+ * index: {codeExtensions: string[], docExtensions: string[], excludePaths: string[], publicRepos: string[],
433
+ * writableRepos: string[]},
330
434
  * root: string|null}>}
331
435
  */
332
436
  export function loadProjectDeclaration(cwd) {
@@ -0,0 +1,94 @@
1
+ /**
2
+ * declared-repos.mjs — **声明出边图 + 环走查**(叶档:只 import `node:*` 与 `manifest.mjs` / `declaration.mjs`)。
3
+ *
4
+ * 判据单源 = `docs/core/design/PATH-RESOLUTION.md` §2.7「声明仓引用」与「环检」两段(本档只实现,不重述口径)。
5
+ * 两件事:
6
+ * · `declaredOutEdges(root)` = 本仓的**出边**(`index.publicRepos` 各项)——根集单源 = `declaration.mjs` 的
7
+ * `declaredPublicRoots`,本档只补它不出的三件:**目录名**(首段匹配用)· **声明项原文**(报面用)· **本机在盘与否**。
8
+ * 同一份声明表逐项对位,不重建第二张表。
9
+ * · `declaredCycles(root)` = 沿出边 DFS 的回边走查:只报**穿过起点**的环(每个仓的门报自己的环,不为别人的环背红)。
10
+ * 无 `PROJECT-MANIFEST.json` 的目录是**叶仓**——没有出边(规则 = `docs/core/design/PATH-RESOLUTION.md` §2.7「叶仓」)。
11
+ * 走查撞到**声明根不在本机**的节点 ⇒ 该节点止步,并记入 `stopped`——「没找到环」与「没看过去」因此在报面上分得开。
12
+ *
13
+ * 不缓存(§2.7 边界:同一份声明表逐项现读——`loadProjectDeclaration` 自带按档路径的同轮缓存,那是读取面相而非本档)。
14
+ */
15
+ import { statSync } from "node:fs"
16
+ import { basename, join, resolve } from "node:path"
17
+
18
+ import { declaredPublicRoots, loadProjectDeclaration } from "./declaration.mjs"
19
+ import { MANIFEST_REL } from "./manifest.mjs"
20
+
21
+ /** 路径同一性(`win32` 大小写不敏感——同 `path-resolve.mjs` 的基根去重口径)。 */
22
+ const pathKey = (p) => (process.platform === "win32" ? p.toLowerCase() : p)
23
+
24
+ const isDir = (p) => { try { return statSync(p).isDirectory() } catch { return false } }
25
+ const isFile = (p) => { try { return statSync(p).isFile() } catch { return false } }
26
+
27
+ /**
28
+ * 本仓的声明出边(声明序;同名多仓各自一条,调用面取首者)。
29
+ * @param {string} [root] 会话锚 / 项目根(项目根经 `manifest.mjs` 解析——深 cwd 等义)
30
+ * @returns {{root:string, name:string, entry:string, onDisk:boolean, hasManifest:boolean}[]}
31
+ * `root` = 声明根绝对路径 · `name` = 其目录名(首段匹配用)· `entry` = `index.publicRepos` 里的声明项原文 ·
32
+ * `onDisk` = 该根在本机是否是目录 · `hasManifest` = 其下是否有 `PROJECT-MANIFEST.json`(决定它有没有出边)
33
+ */
34
+ export function declaredOutEdges(root) {
35
+ const start = resolve(root ?? ".")
36
+ const roots = declaredPublicRoots(start)
37
+ if (roots.length === 0) return []
38
+ let decl = null
39
+ try { decl = loadProjectDeclaration(start) } catch { decl = null }
40
+ const list = Array.isArray(decl?.index?.publicRepos) ? decl.index.publicRepos : []
41
+ const base = typeof decl?.root === "string" && decl.root !== "" ? decl.root : start
42
+ const entryOf = new Map() // 声明根绝对路径 → 声明项原文(同一根重复声明 ⇒ 取首个)
43
+ for (const p of list) {
44
+ const abs = resolve(base, p)
45
+ if (!entryOf.has(pathKey(abs))) entryOf.set(pathKey(abs), p)
46
+ }
47
+ return roots.map((abs) => ({
48
+ root: abs,
49
+ name: basename(abs),
50
+ entry: entryOf.get(pathKey(abs)) ?? "",
51
+ onDisk: isDir(abs),
52
+ hasManifest: isFile(join(abs, MANIFEST_REL)),
53
+ }))
54
+ }
55
+
56
+ /**
57
+ * 环走查(从被判根出发,只报穿过它的环)。
58
+ * 终止性由 `expanded` 集保证(路径同一性;`win32` 大小写不敏感)⇒ 不设深度帽。
59
+ * @param {string} root 被判档的组根(环的起点——节点 = 仓根绝对路径)
60
+ * @returns {{cycles:{names:string[]}[], stopped:{root:string, name:string, entry:string}[]}}
61
+ * `cycles` = 每条环的链(目录名全写:起点 → … → 起点)· `stopped` = 走查在「声明根不在本机」处止步的节点
62
+ * (报面按声明根各出一行 `未核`;去重按路径同一性)
63
+ */
64
+ export function declaredCycles(root) {
65
+ const start = resolve(root ?? ".")
66
+ const startKey = pathKey(start)
67
+ const cycles = []
68
+ const stopped = []
69
+ const seenCycle = new Set()
70
+ const seenStop = new Set()
71
+ const expanded = new Set([startKey])
72
+ const visit = (node, names) => {
73
+ for (const edge of declaredOutEdges(node)) {
74
+ if (!edge.onDisk) { // 读不到对方 manifest ⇒ 该节点止步(记入列报,不静默)
75
+ const key = pathKey(edge.root)
76
+ if (!seenStop.has(key)) { seenStop.add(key); stopped.push({ root: edge.root, name: edge.name, entry: edge.entry }) }
77
+ continue
78
+ }
79
+ const key = pathKey(edge.root)
80
+ if (key === startKey) { // 走回起点 ⇒ 一条环(链按目录名写全)
81
+ const chain = [...names, basename(start)]
82
+ const id = chain.map(pathKey).join("\u0000")
83
+ if (!seenCycle.has(id)) { seenCycle.add(id); cycles.push({ names: chain }) }
84
+ continue
85
+ }
86
+ if (!edge.hasManifest) continue // 叶仓:没有出边
87
+ if (expanded.has(key)) continue
88
+ expanded.add(key)
89
+ visit(edge.root, [...names, edge.name])
90
+ }
91
+ }
92
+ visit(start, [basename(start)])
93
+ return { cycles, stopped }
94
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * doc-check/doc-names.mjs — **档名豁免与 CANON 操作数**族:哪些「看起来像档名」的名字**不算指针**。
3
+ *
4
+ * 判据单源 = `docs/core/design/DOC-DISCIPLINE.md` §3.24 条目 X(档名豁免)∥ `docs/core/design/PROMPT-SYSTEM.md` §6.6
5
+ * 「判保留面」(操作数);本档只实现,不重述口径。
6
+ * **为什么单独立档**:这一族与识别面(`./doc-tokens.mjs` 的「哪些 token 算候选」)是同一层的两条腿——
7
+ * 一条说「这个后缀算本项目的档」,另一条说「这个名字不是指针」;判定件(解析序 ∥ 节在盘 ∥ 环走查)不因它而变。
8
+ * `./anchors.mjs` 再导出本档 ⇒ `./line-refs.mjs` 与 `scripts/prompt-refs-check.mjs` 的 import 行零改。
9
+ */
10
+ import { TOKEN_LEFT_GUARD, TOKEN_RIGHT_GUARD, isExtension } from "./doc-tokens.mjs"
11
+
12
+ /** 约定文件名(**类名**——文档在描述「会读哪些文件」、黑名单名字、`files` 字段值、测试数据):不抽。
13
+ * 依据 = 这些名字在仓根 / 兄弟目录不一定存在,它们指的不是「某个仓内档」。 */
14
+ const FILENAME_CLASSES = new Set([
15
+ "agents.md", "claude.md", "skill.md", "project_rules.md",
16
+ "changelog.md", "agent.md", "advisor.md", "todo.md", "todo-archive.md",
17
+ ])
18
+
19
+ /** 占位符词干(示例写法 / 反例样本——`X.md` / `file.md` / `docs/batches/x.md` 类):不抽。 */
20
+ const PLACEHOLDER_STEMS = new Set([
21
+ "x", "a", "b", "file", "out", "foo", "bar", "example", "sample", "name", "path",
22
+ ])
23
+
24
+ /**
25
+ * 档名豁免判定(**唯一一处** · 判据单源 = `docs/core/design/DOC-DISCIPLINE.md` §3.24 条目 X):
26
+ * 三处消费同一个谓词——锚判(`./anchors.mjs`)∥ `scripts/prompt-refs-check.mjs`(J1 ∥ J3 命中过滤)∥ 行号坐标清单(`./line-refs.mjs`)。
27
+ * **入参 = 写出来的那个 token**(可含目录段),大小写不敏感。**豁免只免裸名**:带目录段的 token 一律按真路径判
28
+ * (`docs/batches/x.md` 不是示例;`tools/file.mjs` 是真档,不能因末段名 `file` 落占位表而整类放过)——
29
+ * 旧式按末段名判(消费面各自 `basename`)就是「真档被当示例」那条漏报的口子。
30
+ * @param {string} token 写出来的档 token(裸名 ∥ `目录段/名`)
31
+ * @returns {null|"filename-class"|"placeholder"} `"filename-class"` = 约定的类名(整名判,不剥后缀);
32
+ * `"placeholder"` = 占位词干(按清单剥后缀后取词干——剥法单源 = `isExtension`;词干 ≤ 1 字符或命中占位表);`null` = 不是豁免名
33
+ */
34
+ export function docNameExemption(token) {
35
+ const bn = String(token ?? "").replace(/\\/g, "/").toLowerCase()
36
+ if (bn.includes("/")) return null // 带目录段 ⇒ 按真路径判(豁免只免裸名)
37
+ if (FILENAME_CLASSES.has(bn)) return "filename-class"
38
+ const dot = bn.lastIndexOf(".")
39
+ const ext = dot > 0 ? bn.slice(dot + 1) : ""
40
+ const stem = isExtension(ext) ? bn.slice(0, dot) : bn
41
+ if (stem.length <= 1 || PLACEHOLDER_STEMS.has(stem)) return "placeholder"
42
+ return null
43
+ }
44
+
45
+ /** CANON 操作数族(**规范豁免串** · 判据单源 = `docs/core/design/PROMPT-SYSTEM.md` §6.6「判保留面」):
46
+ * 七个名字在模型面是**模型要写出来 / 读写的文件名**(行为操作数 · 路径操作数),不是「去读这个档」的指针——
47
+ * 换个目录解析必然 `档缺`。**只对提示词面剥**(面判据 = `isPromptFace`,单源住 `./paragraph.mjs`):`docs/` 面不会因本条多放行一个名——
48
+ * `README.md` / `MANIFEST.md` / `RTM.md` / `.thincoder/advisor.md` 在那里仍按指针判(其余三名早已走 `FILENAME_CLASSES` 类名免,
49
+ * 非本条引入;末名带目录段 ⇒ 类名免够不到它——免的是裸名,口径 = `docs/core/design/DOC-DISCIPLINE.md` §3.24「入参契约」)。
50
+ * **一处定义、两处消费**:`scripts/prompt-refs-check.mjs` 的 J3 豁免从本档 import 本表与剥除函数(不复制);
51
+ * 反方向零 import——判据链自持 = `docs/core/design/DOC-DISCIPLINE.md` A-DD29 ⑤(`thincoder-core/**` 对
52
+ * `scripts/**` 的 import 点 = 0)。闭集外的同形 token(非操作数)照报。 */
53
+ export const CANON_OPERANDS = [
54
+ "AGENTS.md", "SKILL.md", "README.md", "MANIFEST.md",
55
+ ".thincoder/advisor.md", "project_rules.md",
56
+ "RTM.md",
57
+ ]
58
+
59
+ /** 操作数剥除:提示词面逐行先删 `CANON_OPERANDS` 的**整 token** 再抽(与 `scripts/prompt-refs-check.mjs` 的 J3 豁免同式)。
60
+ * **剥除面 = 整 token 边界**(与锚抽取共用同一对边界):只有左右界都成立的操作数名才被吞——名字只是更长 token
61
+ * 的尾段(`test/RTM.md` 里的末段名)⇒ **不剥**,该指针照常抽出、照常判存在性。
62
+ * 改前是子串整串删除(`out.split(s).join("")`):路径前缀留下、末段名被吃,剩下的半截不构成 token,
63
+ * 该指针在提示词面**不被判**(漏报方向)。 */
64
+ const OPERAND_STRIP_RES = CANON_OPERANDS.map((name) => new RegExp(
65
+ `${TOKEN_LEFT_GUARD}${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}${TOKEN_RIGHT_GUARD}`,
66
+ "gu",
67
+ ))
68
+
69
+ export function stripCanonOperands(line) {
70
+ let out = String(line)
71
+ for (const re of OPERAND_STRIP_RES) out = out.replace(re, "")
72
+ return out
73
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * doc-check/doc-tokens.mjs — **识别面一族**:档名 / 扩展名的常量、谓词与三条抽取式的拼装。
3
+ *
4
+ * 机制单源 = `docs/core/design/DOC-CHECK.md` §2.6(判据句与取形六条住那一节,本档只实现,不重述)。
5
+ * **为什么单独立档**:这一族是「哪些 token 算候选」的唯一落点,判据面(解析序 ∥ 节在盘 ∥ 环走查 ∥ 豁免谓词)
6
+ * 住 `./anchors.mjs`;两族之间只通过本档的导出相接,所以它能整族搬走而不动判法一字。
7
+ * `anchors.mjs` 再导出本档的导出面 ⇒ 既有消费面(`./line-refs.mjs` ∥ `./graph-tokens.mjs` ∥
8
+ * `thincoder-core/doc-check/index.mjs` ∥ `scripts/prompt-refs-check.mjs`)的 import 行零改。
9
+ *
10
+ * 叶档:只 import `node:*`(无内部依赖——`ANCHOR_RE` 在模块求值时就要这份常量,反向 import 会成环)。
11
+ */
12
+ /** 档 token 的**一对边界**(**一处定义、四处抽取式加剥除式同吃**——转导出面):
13
+ * 左界不接名字字符类 ∣ 路径分隔符 ∣ `@` ∣ `<>`(排除更长 token 的尾段)、右界不接字母数字
14
+ * (扩展名之后紧邻字母数字 ⇒ 非完整 token)。锚(`ANCHOR_RE`)∥ 花括号组 ∥ 依据行(`CITE_RE_SRC`)∥
15
+ * 行号面(`./line-refs.mjs` 的 `NAME_RE`)与操作数剥除(`stripCanonOperands`)同取这一对。
16
+ * **四条抽取式与剥除式一律 `gu` 标志**:`\p{…}` 不带 `u` 是字面量 `p{…}`,整条式会静默变成另一种式;
17
+ * `u` 下过度的转义在模块求值时抛错(fail-loud 在载入面,比抽出错字好)。
18
+ * **收敛带来的一处行为差(如实)**:行号面的左界改用本对(含 `<>`)⇒ 名字前紧贴 `<` ∥ `>` 的 token 不再被抽,
19
+ * 方向是漏报(§2.6「收敛带来的一处行为差」)。 */
20
+ export const TOKEN_LEFT_GUARD = "(?<![\\p{L}\\p{N}_.\\-\\\\/@<>])"
21
+ export const TOKEN_RIGHT_GUARD = "(?![\\p{L}\\p{N}_])"
22
+
23
+ /** 名字字符类(**一处定义,四条抽取式同吃**):Unicode 字母与数字(含中日韩)+ 原 ASCII 符号集。
24
+ * 空白与全角标点都不在内 ⇒ 中文句读 `。,、;:?!「」『』()《》【】` 一律截断名字,既做不成名字的一段,
25
+ * 也做不成扩展名的首字符(§2.6「为什么中文句读吞不进来」)。 */
26
+ export const NAME_CH = "[\\p{L}\\p{N}_.\\-]"
27
+
28
+ /** 扩展名的**形护**(判「这个后缀长得像不像后缀」;清单判「算不算本项目的档」——两道都过才是候选):
29
+ * ASCII 点 + 首字符字母 + 长度 1–10 ⇒ `1.5` ∥ `v2.0` ∥ `192.168.1.1` 的候选扩展名首字符是数字,抽都抽不出来。
30
+ * 形护进正则而不进谓词:抽出再丢会动归属窗——`1.5` 先被抽出再被丢掉,那一行里其余 token 的行号坐标归属跟着变(KD-R1)。 */
31
+ export const EXT_PART = "\\.[A-Za-z][A-Za-z0-9]{0,9}"
32
+
33
+ /** 缺省扩展名清单(**物理单源**;退役件 `DOC_EXTS` 的**改名 + 改值**——位置与消费面不变):
34
+ * 取形六条(§2.6):改前认得的 12 项全留(扔掉即零回归面破)· F19 点名的五项(AC-17 钉在这几个后缀上)·
35
+ * 真实文件类型补入 · 代码表达式 ∥ 字段访问的末段一律不进 · 单字符后缀不入(`.x` 是 `20.x/22.x` 的来源)·
36
+ * 归档内层不入(`build/app.tar.gz` 的末段是 `gz`,不在清单 ⇒ 整串不当档名)。 */
37
+ export const DEFAULT_DOC_EXTS = [
38
+ // 改前认得的 12 项
39
+ "md", "mjs", "cjs", "js", "json", "css", "html", "svg", "yml", "yaml", "sh", "ps1",
40
+ // F19 点名的五项
41
+ "py", "csv", "txt", "sql", "xml",
42
+ // 真实文件类型补入(认对了而盘上没有 = 真悬空,照报;不与「认错了东西」混为一谈)
43
+ "ts", "tsx", "jsx", "vue", "rb", "go", "rs", "java", "kt", "toml", "ini", "conf", "proto",
44
+ "ico", "git", "db", "pem", "pub",
45
+ ]
46
+
47
+ /** 扩展名是否落在清单内(**扩展名定义只此一处**——豁免谓词的词干判定与候选谓词同取它,§3.24 条目 X / F12 单源):
48
+ * 比较不折叠点、不分大小写(`JSON` 与 `json` 同项、`.md` 与 `md` 同项——书写面允许带前导点)。
49
+ * `exts` 缺省 = `DEFAULT_DOC_EXTS`(引擎装配好的生效清单由调用方传入)。 */
50
+ export function isExtension(ext, exts = DEFAULT_DOC_EXTS) {
51
+ const e = String(ext ?? "").replace(/^\./, "").toLowerCase()
52
+ if (e === "") return false
53
+ return (exts ?? DEFAULT_DOC_EXTS).some((x) => String(x ?? "").trim().replace(/^\./, "").toLowerCase() === e)
54
+ }
55
+
56
+ /** 文档名族(**裸名可判的扩展名族** · 判据句单源 = `docs/core/design/DOC-CHECK.md` §2.10.3):
57
+ * 裸名(不带目录段)的 token 后缀落在这张表里才是候选;后缀只在代码族里 ⇒ 不是候选,按散文提及处置(不解析、不判)。
58
+ * **与生效清单不是一件事**:`DEFAULT_DOC_EXTS` 是后缀清单、不是族划分面——清单内的代码族后缀在裸名位不成为候选;
59
+ * 要按文档名族判,改这张表(走评审),不新增第二个可配面(`docs/core/design/DOC-DISCIPLINE.md` §3.20 F3「判据不分适用面」)。
60
+ * **带目录段的 token 不吃这张表**:路径本身给出了定位,代码族与文档名族在这一形上没有差别。 */
61
+ export const BARE_NAME_EXTS = Object.freeze(["md", "markdown"])
62
+
63
+ /** 候选谓词(**两条腿的判定落点** · 清单腿 = §2.6「清单落在哪一层」,形分档腿 = §2.10.3):
64
+ * ① 后缀落在生效清单内(只看 token 末段最后一个点之后那一段,这一步不分有没有目录段);
65
+ * ② 形分档:带目录段 ⇒ 候选,一族同判;裸名 ⇒ 后缀须落在文档名族 `BARE_NAME_EXTS` 内。
66
+ * **两条腿同坐一处**:锚 ∥ 花括号组 ∥ 依据行 ∥ 行号面四条分支都只调本谓词,不存在绕过形分档的第二条判路。
67
+ * 清单由引擎按该档所属项目根装配好再传进来,本谓词只按字面查已过滤的表、不逐条列被挡下的 token
68
+ * (数量大,列出来正是真命中被淹没的成因)。 */
69
+ export function isDocToken(token, exts = DEFAULT_DOC_EXTS) {
70
+ const raw = String(token ?? "")
71
+ const base = raw.split("/").pop()
72
+ const dot = base.lastIndexOf(".")
73
+ if (dot <= 0 || dot === base.length - 1) return false
74
+ if (!isExtension(base.slice(dot + 1), exts)) return false
75
+ if (raw.includes("/")) return true
76
+ return isExtension(base.slice(dot + 1), BARE_NAME_EXTS)
77
+ }
78
+ /** 档名 token(不带 `§N` / `:N` 尾——判据 ③「在不在盘」要的就是路径本身):
79
+ * 目录段可选。与下面几条抽取式共用同一对边界常量,不另立一份。 */
80
+ export const NAME_RE = new RegExp(`${TOKEN_LEFT_GUARD}((?:${NAME_CH}+\\/)*${NAME_CH}+${EXT_PART})${TOKEN_RIGHT_GUARD}`, "gu")
81
+
82
+ /** 文档指针 token:`(目录段/)*名<扩展名的形护>` + 可选行号坐标尾 + 可选节指示(`§` + 编号)——两界取自上面那一对;
83
+ * 后缀算不算数由 `isDocToken` 在消费点判(形护在这里,清单在那里——两条各坐一处)。 */
84
+ export const ANCHOR_RE = new RegExp(
85
+ `${TOKEN_LEFT_GUARD}((?:${NAME_CH}+\\/)*${NAME_CH}+${EXT_PART})(?::\\d+(?:-\\d+)?)?(?:\\s*§\\s*(\\d+(?:\\.\\d+)*))?${TOKEN_RIGHT_GUARD}`,
86
+ "gu",
87
+ )
88
+
89
+ /** 花括号组形的抽取式(判据见 `./anchors.mjs` 头注「花括号组形」条):目录段照常、末段 = 前缀 `{` 成员 `,` 成员 `}` 后缀 `.` 扩展名。
90
+ * 三支走不到的守卫**不写成判据**(写成判据就是给没人走的路修栅栏):
91
+ * · 组内含 `/` ∥ `*`(取值枚举 `{ running / queued / done }`)——成员字符类(`NAME_CH`)本就不含这两个字符,匹配不上;
92
+ * · 成员 < 2(`${count}` ∥ `📁 {name}` 这类模板占位)——成员后的 `(?:,…)+` 必带一个逗号;
93
+ * · 嵌套形(`i18n-{zh,en}-{shell,me}.mjs`:后缀里再出现 `{`)——后缀位(`NAME_CH`)不含 `{`,外层匹配不成;
94
+ * 内层组则由消费点那条「紧跟在 `}` 之后的那一组不展开」挡住(左界守卫放它过:`}` 不在排除类内)。
95
+ * 嵌套那一形因此今天不入判、明天仍不入判——本支不假装治了它。 */
96
+ export const BRACE_GROUP_RE = new RegExp(
97
+ `${TOKEN_LEFT_GUARD}((?:${NAME_CH}+\\/)*${NAME_CH}*\\{${NAME_CH}+(?:,${NAME_CH}+)+\\}${NAME_CH}*${EXT_PART})${TOKEN_RIGHT_GUARD}`,
98
+ "gu",
99
+ )
100
+
101
+ /** 依据行标记(口径单源 = `docs/core/design/DOC-DISCIPLINE.md` §3.25 条目 Y「写法」表):
102
+ * `依据` + 可选分隔符(`:` ∥ `:` ∥ `=`)+ 档路径(可带反引号)+ `「引文」`。
103
+ * 「相邻」行 = 路径 token 与 `「` 之间**只允许分隔符与反引号**——夹进别的字符(散文词 ∥ 标点 ∥ 空白)
104
+ * 就**不构成标记**,不判:讲写法的档里本就有「`依据` = 判据契约(…)+用户裁定「…」」这类散文句,
105
+ * 松判会把它们读成标记形,而批档恒在收口判域,一次假命中就拦一次合法收口。
106
+ * (`依据` 与路径之间、以及那个分隔符是否带空白不限——那一段不是判据要防的那一处。)
107
+ * 扩展名族 = 生效扩展名清单(与行号坐标族同组,单源;后缀算不算数由 `isDocToken` 在消费点判)。
108
+ * **导出面说明**:源串导出只作**量法扫串的单一源**(改面单测档的「存量读数」用它,不再自建第二份字面)——
109
+ * 生产行为不变,别处不去拼它。 */
110
+ export const CITE_RE_SRC = `依据\\s*[::=]?\\s*\`?((?:${NAME_CH}+/)*${NAME_CH}+${EXT_PART})\`?[::=]?「([^」]*)」`