@thincoder/core 0.10.13 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (366) hide show
  1. package/CHANGELOG.md +74 -1
  2. package/advisor/convergence.mjs +34 -3
  3. package/advisor/loop.mjs +42 -10
  4. package/advisor/messages.mjs +46 -27
  5. package/advisor/notice.mjs +1 -1
  6. package/advisor/project-context.mjs +253 -14
  7. package/advisor/run.mjs +7 -4
  8. package/advisor.mjs +29 -43
  9. package/agent/batch-attribution.mjs +87 -0
  10. package/agent/batch-changed-surface.mjs +129 -0
  11. package/agent/completion.mjs +57 -4
  12. package/agent/digest-account.mjs +73 -46
  13. package/agent/dispatch-gates.mjs +6 -0
  14. package/agent/dispatch-run.mjs +1 -1
  15. package/agent/dispatch.mjs +35 -22
  16. package/agent/family-tools.mjs +36 -17
  17. package/agent/helpers.mjs +123 -95
  18. package/agent/offload.mjs +84 -0
  19. package/agent/post-turn.mjs +24 -10
  20. package/agent/record-results.mjs +19 -7
  21. package/agent/run-stages.mjs +127 -61
  22. package/agent/run-start.mjs +45 -8
  23. package/agent/setup-reminders.mjs +9 -2
  24. package/agent/setup.mjs +27 -22
  25. package/agent/spawn-child.mjs +38 -1
  26. package/agent/suspension.mjs +1 -1
  27. package/agent/timers.mjs +5 -3
  28. package/agent/turn-loop.mjs +60 -6
  29. package/agent/turn-projection.mjs +386 -0
  30. package/agent/turn-task-state.mjs +274 -0
  31. package/agent/turn-tool-process.mjs +168 -0
  32. package/agent/write-face.mjs +99 -0
  33. package/agent/write-gate-ledger.mjs +569 -0
  34. package/agent/write-gate.mjs +39 -13
  35. package/agent-tools/advisor-async.mjs +29 -169
  36. package/agent-tools/advisor-launch.mjs +178 -0
  37. package/agent-tools/advisor-settle.mjs +28 -1
  38. package/agent-tools/advisor.mjs +136 -31
  39. package/agent-tools/async-settle.mjs +2 -2
  40. package/agent-tools/audit-block.mjs +6 -6
  41. package/agent-tools/bash-async.mjs +8 -2
  42. package/agent-tools/batch-closeout.mjs +444 -0
  43. package/agent-tools/batch-gate.mjs +152 -138
  44. package/agent-tools/batch-ledger-bind.mjs +392 -0
  45. package/agent-tools/batch-ledger-link.mjs +73 -0
  46. package/agent-tools/batch-ledger-view.mjs +109 -0
  47. package/agent-tools/batch-lifecycle.mjs +245 -376
  48. package/agent-tools/batch-paths.mjs +73 -47
  49. package/agent-tools/batch-read.mjs +1 -1
  50. package/agent-tools/batch-record-write.mjs +417 -0
  51. package/agent-tools/batch-regions.mjs +215 -0
  52. package/agent-tools/batch-reopen.mjs +154 -0
  53. package/agent-tools/batch-segment-vocab.mjs +379 -0
  54. package/agent-tools/batch-skeleton.mjs +344 -196
  55. package/agent-tools/batch-supersede.mjs +232 -0
  56. package/agent-tools/batch-tier-gate.mjs +297 -0
  57. package/agent-tools/batch.mjs +189 -253
  58. package/agent-tools/consult.mjs +7 -4
  59. package/agent-tools/context.mjs +47 -17
  60. package/agent-tools/design-review-record.mjs +225 -0
  61. package/agent-tools/design-slots.mjs +24 -24
  62. package/agent-tools/design-token.mjs +318 -39
  63. package/agent-tools/doc-check.mjs +55 -29
  64. package/agent-tools/doc-graph.mjs +140 -0
  65. package/agent-tools/eng.mjs +10 -9
  66. package/agent-tools/escalate-async.mjs +5 -5
  67. package/agent-tools/manifest.mjs +34 -15
  68. package/agent-tools/read-history.mjs +115 -14
  69. package/agent-tools/review-facts.mjs +40 -15
  70. package/agent-tools/settings.mjs +23 -2
  71. package/agent-tools/spawn-gates.mjs +19 -22
  72. package/agent-tools/ssh-session.mjs +120 -111
  73. package/agent-tools/ssh-text.mjs +155 -0
  74. package/agent-tools/ssh-transfer.mjs +210 -0
  75. package/agent-tools/ssh-transport.mjs +183 -81
  76. package/agent-tools/subagent-actions-query.mjs +11 -7
  77. package/agent-tools/subagent-actions.mjs +1 -1
  78. package/agent-tools/subagent-async.mjs +11 -11
  79. package/agent-tools/subagent-brief.mjs +76 -0
  80. package/agent-tools/subagent-design-token.mjs +168 -0
  81. package/agent-tools/subagent-run.mjs +1 -1
  82. package/agent-tools/subagent-scheduler.mjs +45 -11
  83. package/agent-tools/subagent-spawn.mjs +143 -104
  84. package/agent-tools/subagent.mjs +26 -23
  85. package/agent-tools/taskbook-block.mjs +94 -0
  86. package/agent-tools/timer.mjs +12 -8
  87. package/agent-tools/verify.mjs +13 -4
  88. package/agent-tools.mjs +7 -3
  89. package/agent.mjs +20 -1
  90. package/attachments.mjs +3 -3
  91. package/browser/actions.mjs +9 -3
  92. package/browser/cdp.mjs +45 -17
  93. package/browser/launch.mjs +25 -43
  94. package/browser/pool.mjs +299 -0
  95. package/browser/queue.mjs +2 -0
  96. package/browser/session-state.mjs +450 -0
  97. package/browser/session.mjs +127 -151
  98. package/browser/snapshot.mjs +89 -0
  99. package/client-identity.mjs +22 -6
  100. package/config-defaults.mjs +2 -1
  101. package/config-migrate.mjs +40 -0
  102. package/config-normalize.mjs +28 -2
  103. package/config-presets.mjs +5 -3
  104. package/config-reload.mjs +59 -0
  105. package/config.mjs +62 -98
  106. package/context-degrade.mjs +38 -10
  107. package/context-echo.mjs +11 -0
  108. package/context.mjs +165 -68
  109. package/conventions.mjs +11 -9
  110. package/declaration.mjs +33 -7
  111. package/declared-repos.mjs +94 -0
  112. package/doc-check/doc-names.mjs +73 -0
  113. package/doc-check/doc-tokens.mjs +110 -0
  114. package/doc-check/existence.mjs +160 -0
  115. package/doc-check/index.mjs +312 -163
  116. package/doc-check/line-refs.mjs +38 -0
  117. package/doc-check/paragraph.mjs +220 -91
  118. package/doc-graph/anchors.mjs +474 -0
  119. package/doc-graph/doc-batch-face.mjs +59 -0
  120. package/doc-graph/doc-suffix.mjs +27 -0
  121. package/doc-graph/graph-tokens.mjs +160 -0
  122. package/doc-graph.mjs +778 -0
  123. package/explore-distill.mjs +12 -6
  124. package/i18n.mjs +2 -2
  125. package/index-discover.mjs +4 -1
  126. package/instance-inbox-watch.mjs +272 -0
  127. package/instance-inbox.mjs +218 -0
  128. package/instance-registry.mjs +179 -0
  129. package/knowledge/README.md +3 -0
  130. package/knowledge/prompt-resources.md +6 -0
  131. package/ledger-close-proof.mjs +95 -62
  132. package/ledger-close.mjs +188 -0
  133. package/ledger-cmd.mjs +76 -244
  134. package/ledger-consistency.mjs +113 -0
  135. package/ledger-db.mjs +70 -37
  136. package/ledger-executors.mjs +1 -1
  137. package/ledger-migrate.mjs +4 -4
  138. package/ledger-read.mjs +10 -8
  139. package/ledger-surface.mjs +1 -1
  140. package/ledger-tools.mjs +83 -24
  141. package/ledger-variant-notice.mjs +1 -1
  142. package/ledger-write-ops.mjs +462 -0
  143. package/ledger.mjs +2 -2
  144. package/manifest-discovery.mjs +5 -3
  145. package/manifest-schema.mjs +28 -2
  146. package/memory/memory-tool.mjs +5 -2
  147. package/memory/schema.mjs +6 -27
  148. package/package.json +3 -1
  149. package/path-resolve.mjs +498 -0
  150. package/permission.mjs +4 -0
  151. package/prompt-files.mjs +91 -1
  152. package/prompt-overlays.mjs +14 -6
  153. package/prompts/advisor-design.md +66 -22
  154. package/prompts/advisor-round1.md +37 -3
  155. package/prompts/advisor-round2.md +44 -10
  156. package/prompts/advisor-round3.md +43 -9
  157. package/prompts/common.md +15 -375
  158. package/prompts/consult-base.md +6 -1
  159. package/prompts/discipline-engineering.md +251 -95
  160. package/prompts/discipline-normal.md +4 -250
  161. package/prompts/knowledge/business-gates.md +22 -0
  162. package/prompts/knowledge/decision-quality.md +23 -0
  163. package/prompts/knowledge/doc-lookup.md +35 -0
  164. package/prompts/knowledge/document-writing.md +51 -0
  165. package/prompts/knowledge/documentation-evaluation.md +56 -0
  166. package/prompts/knowledge/evidence-discipline.md +57 -0
  167. package/prompts/knowledge/normal-coding-workflow.md +104 -0
  168. package/prompts/knowledge/normal-delivery-collaboration.md +108 -0
  169. package/prompts/knowledge/normal-work-management.md +57 -0
  170. package/prompts/knowledge/product-security.md +23 -0
  171. package/prompts/knowledge/project-records.md +62 -0
  172. package/prompts/knowledge/tool-advisor.md +29 -0
  173. package/prompts/knowledge/tool-apply-patch.md +18 -0
  174. package/prompts/knowledge/tool-bash.md +39 -0
  175. package/prompts/knowledge/tool-batch-eng-coder.md +12 -0
  176. package/prompts/knowledge/tool-batch-eng-designer.md +12 -0
  177. package/prompts/knowledge/tool-batch-review.md +12 -0
  178. package/prompts/knowledge/tool-batch.md +80 -0
  179. package/prompts/knowledge/tool-browser.md +57 -0
  180. package/prompts/knowledge/tool-code-search.md +4 -0
  181. package/prompts/knowledge/tool-consult-start.md +12 -0
  182. package/prompts/knowledge/tool-consult-stop.md +6 -0
  183. package/prompts/knowledge/tool-context.md +6 -0
  184. package/prompts/knowledge/tool-delete.md +17 -0
  185. package/prompts/knowledge/tool-doc-check.md +70 -0
  186. package/prompts/knowledge/tool-doc-graph-read.md +20 -0
  187. package/prompts/knowledge/tool-doc-graph.md +49 -0
  188. package/prompts/knowledge/tool-doc-search.md +6 -0
  189. package/prompts/knowledge/tool-edit.md +38 -0
  190. package/prompts/knowledge/tool-eng.md +2 -0
  191. package/prompts/knowledge/tool-execute.md +16 -0
  192. package/prompts/knowledge/tool-fetch.md +12 -0
  193. package/prompts/knowledge/tool-file-ops.md +16 -0
  194. package/prompts/knowledge/tool-get-current-time.md +7 -0
  195. package/prompts/knowledge/tool-git-read.md +19 -0
  196. package/prompts/knowledge/tool-git.md +29 -0
  197. package/prompts/knowledge/tool-glob.md +15 -0
  198. package/prompts/knowledge/tool-goal.md +8 -0
  199. package/prompts/knowledge/tool-grep.md +18 -0
  200. package/prompts/knowledge/tool-hashline-edit.md +14 -0
  201. package/prompts/knowledge/tool-insert-after.md +15 -0
  202. package/prompts/knowledge/tool-instance-list.md +6 -0
  203. package/prompts/knowledge/tool-instance-send.md +10 -0
  204. package/prompts/knowledge/tool-knowledge.md +18 -0
  205. package/prompts/knowledge/tool-ledger-read.md +35 -0
  206. package/prompts/knowledge/tool-ledger.md +42 -0
  207. package/prompts/knowledge/tool-lint.md +16 -0
  208. package/prompts/knowledge/tool-ls.md +13 -0
  209. package/prompts/knowledge/tool-lsp.md +11 -0
  210. package/prompts/knowledge/tool-main-history.md +2 -0
  211. package/prompts/knowledge/tool-manifest-read.md +14 -0
  212. package/prompts/knowledge/tool-manifest.md +31 -0
  213. package/prompts/knowledge/tool-memory-read.md +20 -0
  214. package/prompts/knowledge/tool-memory.md +15 -0
  215. package/prompts/knowledge/tool-notify-parent.md +12 -0
  216. package/prompts/knowledge/tool-operations.md +114 -0
  217. package/prompts/knowledge/tool-peer-instances.md +2 -0
  218. package/prompts/knowledge/tool-plan.md +6 -0
  219. package/prompts/knowledge/tool-process-read.md +13 -0
  220. package/prompts/knowledge/tool-process.md +15 -0
  221. package/prompts/knowledge/tool-question.md +16 -0
  222. package/prompts/knowledge/tool-read-history-batch.md +22 -0
  223. package/prompts/knowledge/tool-read-history.md +36 -0
  224. package/prompts/knowledge/tool-read-image.md +11 -0
  225. package/prompts/knowledge/tool-read.md +21 -0
  226. package/prompts/knowledge/tool-recent-changes.md +6 -0
  227. package/prompts/knowledge/tool-repo-outline.md +4 -0
  228. package/prompts/knowledge/tool-settings-read.md +12 -0
  229. package/prompts/knowledge/tool-settings.md +18 -0
  230. package/prompts/knowledge/tool-skill.md +6 -0
  231. package/prompts/knowledge/tool-ssh.md +52 -0
  232. package/prompts/knowledge/tool-subagent.md +59 -0
  233. package/prompts/knowledge/tool-task.md +12 -0
  234. package/prompts/knowledge/tool-team-ledger-read.md +11 -0
  235. package/prompts/knowledge/tool-team-ledger.md +11 -0
  236. package/prompts/knowledge/tool-timer.md +23 -0
  237. package/prompts/knowledge/tool-tree.md +14 -0
  238. package/prompts/knowledge/tool-verify.md +19 -0
  239. package/prompts/knowledge/tool-wait-for.md +25 -0
  240. package/prompts/knowledge/tool-websearch.md +19 -0
  241. package/prompts/knowledge/tool-write.md +9 -0
  242. package/prompts/knowledge/upstream-protocol.md +43 -0
  243. package/prompts/persona-eng-coder.md +29 -3
  244. package/prompts/persona-eng-designer.md +131 -159
  245. package/prompts/persona-engineering.md +202 -131
  246. package/prompts/persona-explore.md +1 -1
  247. package/prompts/persona-plan.md +6 -1
  248. package/prompts/persona-tester.md +55 -0
  249. package/prompts/subagent-base.md +2 -0
  250. package/provider/anthropic.mjs +6 -4
  251. package/provider/core.mjs +5 -4
  252. package/provider/errors.mjs +29 -4
  253. package/provider/google.mjs +39 -12
  254. package/provider/rate.mjs +11 -3
  255. package/provider/responses.mjs +3 -1
  256. package/provider/sse.mjs +15 -4
  257. package/provider-flows.mjs +2 -2
  258. package/session-identity.mjs +21 -0
  259. package/session-index-build.mjs +1 -1
  260. package/session-index-pass.mjs +1 -1
  261. package/session-index-query.mjs +1 -1
  262. package/session-index.mjs +1 -1
  263. package/session-lifecycle.mjs +79 -19
  264. package/session-slot-write.mjs +37 -5
  265. package/session-slots.mjs +9 -14
  266. package/session.mjs +29 -8
  267. package/skip-dirs.mjs +48 -0
  268. package/team-ledger.mjs +17 -13
  269. package/text-budget.mjs +4 -0
  270. package/token-ttl.mjs +73 -4
  271. package/token-window.mjs +244 -34
  272. package/tool-docs/advisor.md +2 -27
  273. package/tool-docs/apply_patch.md +1 -13
  274. package/tool-docs/bash.md +2 -37
  275. package/tool-docs/batch-eng-coder.md +3 -0
  276. package/tool-docs/batch-eng-designer.md +3 -0
  277. package/tool-docs/batch-review.md +3 -0
  278. package/tool-docs/batch.md +3 -1
  279. package/tool-docs/browser.md +2 -47
  280. package/tool-docs/code_search.md +3 -1
  281. package/tool-docs/consult_start.md +2 -4
  282. package/tool-docs/consult_stop.md +2 -2
  283. package/tool-docs/context.md +1 -5
  284. package/tool-docs/delete.md +2 -14
  285. package/tool-docs/doc_check.md +2 -72
  286. package/tool-docs/doc_graph-read.md +3 -0
  287. package/tool-docs/doc_graph.md +3 -0
  288. package/tool-docs/doc_search.md +3 -1
  289. package/tool-docs/edit.md +2 -18
  290. package/tool-docs/eng.md +3 -1
  291. package/tool-docs/execute.md +2 -12
  292. package/tool-docs/fetch.md +2 -12
  293. package/tool-docs/file_ops.md +2 -16
  294. package/tool-docs/get_current_time.md +1 -6
  295. package/tool-docs/git-read.md +3 -0
  296. package/tool-docs/git.md +2 -27
  297. package/tool-docs/glob.md +2 -10
  298. package/tool-docs/goal.md +2 -5
  299. package/tool-docs/grep.md +2 -18
  300. package/tool-docs/hashline_edit.md +2 -13
  301. package/tool-docs/insert_after.md +2 -14
  302. package/tool-docs/instance_list.md +3 -0
  303. package/tool-docs/instance_send.md +3 -0
  304. package/tool-docs/knowledge.md +3 -0
  305. package/tool-docs/ledger-read.md +3 -0
  306. package/tool-docs/ledger.md +3 -8
  307. package/tool-docs/lint.md +2 -9
  308. package/tool-docs/ls.md +2 -11
  309. package/tool-docs/lsp.md +2 -9
  310. package/tool-docs/main_history.md +3 -1
  311. package/tool-docs/manifest-read.md +2 -7
  312. package/tool-docs/manifest.md +2 -28
  313. package/tool-docs/memory-read.md +3 -0
  314. package/tool-docs/memory.md +3 -11
  315. package/tool-docs/notify_parent.md +2 -13
  316. package/tool-docs/peer_instances.md +3 -1
  317. package/tool-docs/plan.md +2 -4
  318. package/tool-docs/process-read.md +3 -0
  319. package/tool-docs/process.md +2 -13
  320. package/tool-docs/question.md +3 -17
  321. package/tool-docs/read.md +2 -19
  322. package/tool-docs/read_history-batch.md +3 -0
  323. package/tool-docs/read_history.md +2 -6
  324. package/tool-docs/read_image.md +2 -7
  325. package/tool-docs/recent_changes.md +3 -1
  326. package/tool-docs/repo_outline.md +3 -1
  327. package/tool-docs/settings-read.md +3 -0
  328. package/tool-docs/settings.md +2 -5
  329. package/tool-docs/skill.md +3 -5
  330. package/tool-docs/ssh.md +2 -50
  331. package/tool-docs/subagent.md +2 -63
  332. package/tool-docs/task.md +2 -6
  333. package/tool-docs/team_ledger-read.md +3 -0
  334. package/tool-docs/team_ledger.md +3 -9
  335. package/tool-docs/timer.md +3 -13
  336. package/tool-docs/tree.md +2 -13
  337. package/tool-docs/verify.md +3 -1
  338. package/tool-docs/wait_for.md +2 -32
  339. package/tool-docs/websearch.md +2 -17
  340. package/tool-docs/write.md +2 -10
  341. package/tools/bash.mjs +12 -2
  342. package/tools/browser.mjs +52 -7
  343. package/tools/doc-write-gate.mjs +73 -0
  344. package/tools/edit-batch.mjs +176 -91
  345. package/tools/edit-diff.mjs +129 -45
  346. package/tools/edit-receipt.mjs +39 -0
  347. package/tools/execute.mjs +11 -5
  348. package/tools/file.mjs +32 -34
  349. package/tools/git.mjs +43 -2
  350. package/tools/index.mjs +6 -0
  351. package/tools/knowledge.mjs +143 -0
  352. package/tools/linter.mjs +3 -3
  353. package/tools/ops.mjs +4 -1
  354. package/tools/patch.mjs +127 -38
  355. package/tools/process-doc-mark.mjs +139 -0
  356. package/tools/search.mjs +15 -6
  357. package/tools/shared.mjs +31 -7
  358. package/tools/ssh.mjs +48 -7
  359. package/tools/tree.mjs +4 -1
  360. package/tools/write-gate-params.mjs +31 -0
  361. package/tools/write-path.mjs +79 -6
  362. package/traces/trace-store.mjs +4 -3
  363. package/window-policy.mjs +203 -0
  364. package/agent/light-round.mjs +0 -63
  365. package/agent/unbooked-pen.mjs +0 -62
  366. package/doc-check/anchors.mjs +0 -135
@@ -15,9 +15,11 @@
15
15
  * 依赖(KD-4 单向):本档为**叶档**——只 import `node:*` 与 `../manifest.mjs`;主档 re-export 保既有面。
16
16
  */
17
17
  import { existsSync, statSync } from "node:fs"
18
- import { isAbsolute, relative, resolve, sep } from "node:path"
18
+ import { isAbsolute, parse, relative, resolve, sep } from "node:path"
19
19
 
20
20
  import { docRootBase, docRootPaths, owningProject, projectRootView, readManifest, resolveProjectRoot } from "../manifest.mjs"
21
+ // 候选序单源 = 统一解析层(`docs/core/design/PATH-RESOLUTION.md` §2.2);本档只留本面参数与落位判据。
22
+ import { danglingSameNameHint, resolvePathTarget } from "../path-resolve.mjs"
21
23
 
22
24
  /** 可读文件判据(存在且为文件——目录 / 缺失同判不可读)。 */
23
25
  function readableFile(abs) {
@@ -26,7 +28,7 @@ function readableFile(abs) {
26
28
 
27
29
  /** 工作区锚候选(判定单点 = `projectRootView`——`workspace` 态 ⇒ 候选全列**按名排序**;余者 null)。 */
28
30
  function workspaceCandidates(cwd) {
29
- const view = projectRootView(cwd ?? process.cwd())
31
+ const view = projectRootView(cwd)
30
32
  return view.state === "workspace" ? view.candidates : null
31
33
  }
32
34
 
@@ -44,18 +46,28 @@ export function batchProjectRoot(cwd) {
44
46
 
45
47
  /** manifest **声明基底**(声明面;manifest 缺失 / 非法 / 读错 ⇒ 空集——v1 单基底语义零变)。 */
46
48
  function declaredBases(cwd) {
47
- const base = cwd ?? process.cwd()
49
+ const base = cwd
48
50
  let man = { ok: false }
49
51
  try { man = readManifest(base) } catch { /* 读错 → 按无 manifest 处理(回退默认基底) */ }
50
52
  return man.ok ? docRootPaths(man.manifest?.docRoot?.batches, base) : []
51
53
  }
52
54
 
53
- /** 批次档基底根数组(**声明面单源**——create / 在飞扫描 / 锚定判据共用):manifest `docRoot.batches`
55
+ /**
56
+ * 批次档基底根数组(**声明面单源**——create / 在飞扫描 / 锚判的面判共用):manifest `docRoot.batches`
54
57
  * (串 | 多根数组)→ 声明基底;缺失 / 非法 ⇒ 回退默认基底 `"docs/batches"`(恒返回非空数组)。
55
58
  * **工作区锚**(条 5)⇒ 候选项目基底**并集**(候选按名排序、并集保序)——在飞扫描 / 写门基底集同取此值。
59
+ * **注入形**(`{ manifest }` 可选——`thincoder-core/doc-check/index.mjs` 的组根调用吃它):引擎已按组根
60
+ * 读过一次 manifest,这里不再重读(每根一次读);缺省仍自读,既有调用零改。注入只换读取来源,
61
+ * 形态判据与回退支零改(manifest 是 `readManifest` 的返回值,`ok:false` 照走缺省回退——降级不静默)。
56
62
  * @param {string} cwd
63
+ * @param {{manifest?:{ok:boolean, manifest?:object|null}}} [injected] 引擎已读的那份(可选)
57
64
  * @returns {string[]} */
58
- export function batchDocBases(cwd) {
65
+ export function batchDocBases(cwd, injected = {}) {
66
+ const man = injected?.manifest
67
+ if (man) {
68
+ const roots = man.ok ? docRootPaths(man.manifest?.docRoot?.batches, cwd) : []
69
+ return roots.length ? roots : [resolve(docRootBase(cwd), "docs/batches")]
70
+ }
59
71
  const ws = workspaceCandidates(cwd)
60
72
  if (ws) {
61
73
  const union = []
@@ -84,14 +96,25 @@ function anchoredPrefix(p, prefixes) {
84
96
  return null
85
97
  }
86
98
 
87
- /** 越基底判据(create 面):解析后须落在某一基底根之内;win32 大小写不敏感比较。 */
88
- function insideBases(abs, bases) {
99
+ /** 落在哪个基底根之内(不落任何一个 ⇒ null)——**判据单源**:create 面的越基底判据(`insideBases`)与
100
+ * doc-check 的面判(`thincoder-core/doc-graph/anchors.mjs` 的 `isBatchFaceRef`——「同一基底根」要的正是**哪一根**)
101
+ * 同取本函数。按**路径段**判(`docs/batches-old/` 不算落在 `docs/batches` 内),win32 大小写不敏感。
102
+ * @param {string} abs 绝对路径
103
+ * @param {string[]} bases 基底根数组(`batchDocBases`——已是绝对路径)
104
+ * @returns {string|null} 命中的那个基底根(原值,不归一大小写)∥ null */
105
+ export function baseContaining(abs, bases) {
89
106
  const norm = (p) => (process.platform === "win32" ? p.toLowerCase() : p)
90
107
  const target = norm(abs)
91
- return bases.some((b) => {
108
+ for (const b of bases) {
92
109
  const root = norm(b)
93
- return target === root || target.startsWith(root.endsWith(sep) ? root : root + sep)
94
- })
110
+ if (target === root || target.startsWith(root.endsWith(sep) ? root : root + sep)) return b
111
+ }
112
+ return null
113
+ }
114
+
115
+ /** 越基底判据(create 面):解析后须落在某一基底根之内(判定单源 = 同档 `baseContaining`)。 */
116
+ function insideBases(abs, bases) {
117
+ return baseContaining(abs, bases) !== null
95
118
  }
96
119
 
97
120
  /** create 越基底(原文案逐字——零变面)。 */
@@ -103,53 +126,56 @@ const anchoredEscapeError = (raw) => new Error(`batch: create path is anchored a
103
126
  const workspaceCreateError = (raw, candidates) => new Error(`batch: create target "${raw}" belongs to no project — the session anchor holds ${candidates.length} project(s) below it: ${candidates.join(", ")}. Pass an explicit path under a project (e.g. "${candidates[0]}/docs/batches/<file>.md").`)
104
127
  const ambiguousLandingError = (raw, landings) => new Error(`batch: create path resolves under more than one declared batch-record base — refusing to pick one (fail-closed); pass an explicit path (absolute preferred). Path: ${raw}. Candidates: ${landings.join(", ")}`)
105
128
 
106
- /** 工作区锚读面候选分支(条 5):逐候选项目——项目根形(`resolve(candidate, p)`)∥ 声明基底形
107
- * (候选按名排序、并集保序——「首个可读」在此即为确定判读)。 */
108
- function workspaceReadLegs(cwd, p) {
109
- const ws = workspaceCandidates(cwd)
110
- if (!ws) return []
111
- const out = []
112
- for (const c of ws) {
113
- out.push(resolve(c, p))
114
- for (const b of declaredBases(c)) out.push(resolve(b, p))
129
+ /**
130
+ * **读面**解析的四态本体(候选序 + 判态全部经统一解析层——本面只声明自己的参数:
131
+ * `order:"near-first"`(近基根 = cwd / 会话锚 先)+ `kind:"file"`,本面**不传 `declaredRepos`**(不放宽跨仓形:
132
+ * `bases` = `docRoot.batches` 声明面(读面无 manifest ⇒ 无这一级))。锚定串只解析项目根形
133
+ * (不二次拼接——§4.15 判据,见 `resolveBatchReadPath`)。
134
+ * 导出面供 spawn 门拼「追加同名候选」(§2.6:既有文案逐字在前,新信息追加在后)。
135
+ * @returns {object} 统一解析层的四态结果(`docs/core/design/PATH-RESOLUTION.md` §2.1)
136
+ */
137
+ export function resolveBatchReadResult(cwd, given) {
138
+ const base = cwd
139
+ const raw = typeof given === "string" ? given.trim() : ""
140
+ if (!raw) return { state: "dangling", missing: String(given ?? ""), sameName: [], level: "path", tried: [] }
141
+ const p = raw.replace(/\\/g, "/")
142
+ if (anchoredPrefix(p, basePrefixes(base, batchDocBases(base)))) {
143
+ // 锚定形:只解析项目根形(已含基底相对前缀者不再二次拼接)
144
+ const root = batchProjectRoot(base)
145
+ return resolvePathTarget(root, p, { kind: "file", order: "root-first", bases: [root] })
115
146
  }
116
- return out
147
+ return resolvePathTarget(base, raw, { kind: "file", order: "near-first", bases: declaredBases(base) })
117
148
  }
118
149
 
119
150
  /**
120
- * **读面**解析(append / status / close 与评审门 / spawn 门共用):首个**可读**候选胜;无 ⇒ null
121
- * (调用方各自抛既有文案)。锚定串只解析项目根形(跳过 ①③——已含基底相对前缀者不再二次拼接)。
122
- * @param {string} cwd 会话锚(缺省 → 进程 cwd)
151
+ * **读面**解析(append / status / close 与评审门 / spawn 门共用):解析出唯一落点且可读 ⇒ 该绝对路径;
152
+ * 其余(无果 / 判不出唯一)⇒ null(调用方各自抛既有文案)。
153
+ * @param {string} cwd 会话锚
123
154
  * @param {string} given 参数原值(相对 / 绝对、`\` 与 `/` 混写均可)
124
155
  * @returns {string|null} 可读文件的绝对路径 / null
125
156
  */
126
157
  export function resolveBatchReadPath(cwd, given) {
127
- const base = cwd ?? process.cwd()
128
- const raw = typeof given === "string" ? given.trim() : ""
129
- if (!raw) return null
130
- const p = raw.replace(/\\/g, "/")
131
- if (anchoredPrefix(p, basePrefixes(base, batchDocBases(base)))) {
132
- const abs = resolve(batchProjectRoot(base), p)
133
- return readableFile(abs) ? abs : null
134
- }
135
- const candidates = [resolve(base, p), resolve(batchProjectRoot(base), p), ...declaredBases(base).map((b) => resolve(b, p)), ...workspaceReadLegs(base, p)]
136
- for (const abs of candidates) if (readableFile(abs)) return abs
137
- return null
158
+ const r = resolveBatchReadResult(cwd, given)
159
+ return r.state === "resolved" && readableFile(r.abs) ? r.abs : null
138
160
  }
139
161
 
140
162
  /**
141
163
  * 批次档路径门禁(评审侧 `BATCH-RECORD.md` §4.2 口径 = **「若传则须可读」**):空 / 非字符串 / 不可读 → throw。
142
- * 非空且可读 → 返回绝对路径(`\` 归一——照 `files` / `batchDoc` spawn 门先例)。错误文案逐字零变(零回归硬约束)。
164
+ * 非空且可读 → 返回绝对路径(`\` 归一——照 `files` / `batchDoc` spawn 门先例)。既有文案逐字在前,
165
+ * 层的同名候选 / 候选全列**追加在后**(§2.6:新信息只追加)。
143
166
  */
144
167
  export function resolveBatchDocPath(cwd, given) {
145
- const base = cwd ?? process.cwd()
168
+ const base = cwd
146
169
  const raw = typeof given === "string" ? given.trim() : ""
147
170
  if (!raw) {
148
171
  throw new Error("batchDoc must be a non-empty path to the batch record — pass the batch record currently in flight, or omit the parameter entirely when no batch record is in flight.")
149
172
  }
150
- const abs = resolveBatchReadPath(base, raw)
151
- if (abs) return abs
152
- throw new Error(`batchDoc is not a readable file: ${raw} — pass the path of the batch record currently in flight (a path that resolves to an existing file), or omit the parameter when no batch record is in flight.`)
173
+ const r = resolveBatchReadResult(base, raw)
174
+ if (r.state === "resolved" && readableFile(r.abs)) return r.abs
175
+ const hint = r.state === "dangling"
176
+ ? (danglingSameNameHint(r) ? ` ${danglingSameNameHint(r)}` : "")
177
+ : r.state === "ambiguous" ? ` Candidates: ${r.candidates.join(" ∥ ")}` : ""
178
+ throw new Error(`batchDoc is not a readable file: ${raw} — pass the path of the batch record currently in flight (a path that resolves to an existing file), or omit the parameter when no batch record is in flight.${hint ? `;${hint.trim()}` : ""}`)
153
179
  }
154
180
 
155
181
  /**
@@ -163,7 +189,7 @@ export function resolveBatchDocPath(cwd, given) {
163
189
  * @returns {string} 落位绝对路径
164
190
  */
165
191
  export function resolveBatchCreatePath(cwd, given, bases) {
166
- const base = cwd ?? process.cwd()
192
+ const base = cwd
167
193
  const raw = String(given ?? "").trim()
168
194
  const p = raw.replace(/\\/g, "/")
169
195
  let roots = bases
@@ -183,13 +209,15 @@ export function resolveBatchCreatePath(cwd, given, bases) {
183
209
  if (!insideBases(abs, roots)) throw anchoredEscapeError(raw)
184
210
  return abs
185
211
  }
186
- for (const abs of [resolve(base, p), resolve(batchProjectRoot(base), p)]) {
187
- if (insideBases(abs, roots)) return abs
212
+ // 候选序由统一解析层给(① 近基根 cwd/会话锚 → ② 项目根);落位判据(落基底内)在原地判
213
+ for (const anchor of [base, batchProjectRoot(base)]) {
214
+ const r = resolvePathTarget(anchor, p, { kind: "none", order: "near-first", bases: roots })
215
+ if (r.state === "resolved" && insideBases(r.abs, roots)) return r.abs
188
216
  }
189
217
  // ③ 基底自有项目根形(#942 条 6):owningProject 可判者逐基底取值;distinct 落点 ≥2 ⇒ 拒
190
218
  const owned = []
191
219
  for (const b of roots) {
192
- const ownRoot = owningProject(b)
220
+ const ownRoot = owningProject(b, parse(b).root)
193
221
  if (!ownRoot) continue
194
222
  const abs = resolve(ownRoot, p)
195
223
  if (insideBases(abs, roots) && !owned.some((x) => samePath(x, abs))) owned.push(abs)
@@ -199,10 +227,8 @@ export function resolveBatchCreatePath(cwd, given, bases) {
199
227
  // ④ 基底相对形收窄单段(归一后无 `/` 才走原基底分支——多段串不二次拼接)
200
228
  const leafRel = roots.length ? relative(roots[0], resolve(roots[0], p)) : ""
201
229
  if (leafRel && !leafRel.startsWith("..") && !leafRel.includes(sep)) {
202
- for (const b of roots) {
203
- const abs = resolve(b, p)
204
- if (insideBases(abs, roots)) return abs
205
- }
230
+ const r = resolvePathTarget(roots[0], p, { kind: "none", order: "near-first", bases: roots })
231
+ if (r.state === "resolved" && insideBases(r.abs, roots)) return r.abs
206
232
  }
207
233
  throw outsideBasesError(raw)
208
234
  }
@@ -20,7 +20,7 @@ const SEGMENTS = [1, 2, 3, 4, 5, 6]
20
20
  /** 批次档列举(只读):`{ batches: [{ file, path, sections }] }`——`path` = 绝对路径(`/` 归一)、
21
21
  * `file` = basename、`batches` 按路径升序;单档读错跳过(尽力面)。`bases` 缺省 = `batchDocBases(cwd)`。 */
22
22
  export function listBatchRecords({ cwd, bases } = {}) {
23
- const base = cwd ?? process.cwd()
23
+ const base = cwd
24
24
  const roots = bases ?? batchDocBases(base)
25
25
  const files = new Set()
26
26
  for (const root of roots) for (const abs of collectMarkdownFiles(root)) files.add(abs.replace(/\\/g, "/"))