@thincoder/core 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -2
- package/advisor/convergence.mjs +34 -3
- package/advisor/loop.mjs +42 -10
- package/advisor/messages.mjs +42 -25
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +7 -4
- package/advisor.mjs +29 -43
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/completion.mjs +44 -3
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch.mjs +8 -3
- package/agent/family-tools.mjs +27 -12
- package/agent/helpers.mjs +122 -1
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +24 -10
- package/agent/record-results.mjs +18 -1
- package/agent/run-stages.mjs +77 -32
- package/agent/run-start.mjs +37 -0
- package/agent/setup-reminders.mjs +9 -2
- package/agent/setup.mjs +24 -11
- package/agent/spawn-child.mjs +38 -1
- package/agent/timers.mjs +5 -3
- package/agent/turn-loop.mjs +30 -5
- package/agent/turn-projection.mjs +386 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +168 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +29 -169
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +36 -47
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/batch-closeout.mjs +273 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +226 -17
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +169 -46
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +23 -11
- package/agent-tools/batch-segment-vocab.mjs +379 -0
- package/agent-tools/batch-skeleton.mjs +192 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +297 -0
- package/agent-tools/batch.mjs +182 -439
- package/agent-tools/consult.mjs +7 -4
- package/agent-tools/context.mjs +44 -17
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +1 -1
- package/agent-tools/design-token.mjs +279 -81
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +9 -8
- package/agent-tools/escalate-async.mjs +2 -2
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +10 -3
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/spawn-gates.mjs +9 -8
- package/agent-tools/ssh-session.mjs +2 -2
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-async.mjs +8 -9
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +4 -4
- package/agent-tools/subagent-spawn.mjs +90 -110
- package/agent-tools/subagent.mjs +11 -10
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +20 -1
- package/attachments.mjs +3 -3
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +1 -1
- package/config-defaults.mjs +2 -1
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +62 -98
- package/context-degrade.mjs +38 -10
- package/context-echo.mjs +11 -0
- package/context.mjs +149 -83
- package/conventions.mjs +11 -9
- package/declaration.mjs +31 -5
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +309 -213
- package/doc-check/line-refs.mjs +27 -101
- package/doc-check/paragraph.mjs +218 -102
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/explore-distill.mjs +11 -5
- package/i18n.mjs +1 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +6 -0
- package/ledger-close-proof.mjs +100 -49
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +47 -91
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +47 -15
- package/ledger-executors.mjs +1 -1
- package/ledger-tools.mjs +78 -19
- package/ledger-write-ops.mjs +130 -41
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/schema.mjs +2 -2
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +91 -1
- package/prompt-overlays.mjs +9 -6
- package/prompts/advisor-design.md +62 -21
- package/prompts/advisor-round1.md +34 -1
- package/prompts/advisor-round2.md +40 -7
- package/prompts/advisor-round3.md +39 -6
- package/prompts/common.md +14 -387
- package/prompts/consult-base.md +5 -1
- package/prompts/discipline-engineering.md +226 -51
- package/prompts/discipline-normal.md +4 -255
- package/prompts/knowledge/business-gates.md +22 -0
- package/prompts/knowledge/decision-quality.md +23 -0
- package/prompts/knowledge/doc-lookup.md +35 -0
- package/prompts/knowledge/document-writing.md +51 -0
- package/prompts/knowledge/documentation-evaluation.md +56 -0
- package/prompts/knowledge/evidence-discipline.md +57 -0
- package/prompts/knowledge/normal-coding-workflow.md +104 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +108 -0
- package/prompts/knowledge/normal-work-management.md +57 -0
- package/prompts/knowledge/product-security.md +23 -0
- package/prompts/knowledge/project-records.md +62 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +18 -0
- package/prompts/knowledge/tool-bash.md +39 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +12 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +12 -0
- package/prompts/knowledge/tool-batch-review.md +12 -0
- package/prompts/knowledge/tool-batch.md +80 -0
- package/prompts/knowledge/tool-browser.md +57 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +17 -0
- package/prompts/knowledge/tool-doc-check.md +70 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +38 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +16 -0
- package/prompts/knowledge/tool-fetch.md +12 -0
- package/prompts/knowledge/tool-file-ops.md +16 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +19 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +15 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +18 -0
- package/prompts/knowledge/tool-hashline-edit.md +14 -0
- package/prompts/knowledge/tool-insert-after.md +15 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +35 -0
- package/prompts/knowledge/tool-ledger.md +42 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +13 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +31 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +15 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +114 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +6 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +36 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +21 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +18 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +52 -0
- package/prompts/knowledge/tool-subagent.md +59 -0
- package/prompts/knowledge/tool-task.md +12 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +11 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +14 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +9 -0
- package/prompts/knowledge/upstream-protocol.md +43 -0
- package/prompts/persona-eng-coder.md +21 -3
- package/prompts/persona-eng-designer.md +131 -169
- package/prompts/persona-engineering.md +142 -84
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-plan.md +5 -1
- package/prompts/subagent-base.md +2 -0
- package/provider/anthropic.mjs +6 -4
- package/provider/core.mjs +3 -2
- package/provider/errors.mjs +29 -4
- package/provider/google.mjs +24 -7
- package/provider/responses.mjs +3 -1
- package/provider-flows.mjs +2 -2
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +72 -17
- package/session-slot-write.mjs +37 -5
- package/session.mjs +24 -8
- package/skip-dirs.mjs +2 -2
- package/team-ledger.mjs +13 -9
- package/token-ttl.mjs +73 -4
- package/token-window.mjs +167 -33
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -41
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +2 -84
- package/tool-docs/browser.md +2 -49
- package/tool-docs/code_search.md +2 -2
- package/tool-docs/consult_start.md +2 -8
- package/tool-docs/consult_stop.md +2 -4
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -17
- package/tool-docs/doc_check.md +2 -107
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +2 -4
- package/tool-docs/edit.md +1 -38
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -18
- package/tool-docs/fetch.md +2 -14
- package/tool-docs/file_ops.md +2 -18
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -35
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +1 -6
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -15
- package/tool-docs/insert_after.md +2 -16
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -10
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -8
- package/tool-docs/manifest.md +2 -35
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +2 -20
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +1 -5
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -18
- package/tool-docs/read_image.md +2 -9
- package/tool-docs/recent_changes.md +2 -2
- package/tool-docs/repo_outline.md +2 -2
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +1 -12
- package/tool-docs/skill.md +2 -6
- package/tool-docs/ssh.md +1 -62
- package/tool-docs/subagent.md +2 -100
- package/tool-docs/task.md +1 -7
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +2 -19
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +2 -12
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -19
- package/tool-docs/write.md +2 -12
- package/tools/browser.mjs +52 -7
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +170 -92
- package/tools/edit-diff.mjs +78 -62
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +1 -1
- package/tools/file.mjs +16 -8
- package/tools/git.mjs +24 -9
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +3 -1
- package/tools/patch.mjs +123 -43
- package/tools/shared.mjs +28 -27
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +203 -0
- package/doc-check/anchors.mjs +0 -235
|
@@ -1,53 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* agent-tools/batch-gate.mjs — 文档机检门(`batch`
|
|
2
|
+
* agent-tools/batch-gate.mjs — 文档机检门(`batch` 工具两机械点的单源门)。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 判据与报面句子全部来自引擎 `../doc-check/index.mjs`(判据源唯一);本门只决定**判哪几份档**与**何时强制**。
|
|
5
|
+
* 判据句单源 = `docs/core/design/DOC-CHECK.md`:一段太长 ∥ 拿行号做锚 ∥ 悬空指针,三件之外不判。
|
|
6
6
|
*
|
|
7
|
-
* 调用面(`scope`
|
|
8
|
-
* ① `batch
|
|
9
|
-
*
|
|
10
|
-
* 放行 + 回执明示(子代理无法重启会话,卡死写账 =
|
|
11
|
-
* ② `
|
|
12
|
-
*
|
|
13
|
-
* `REFUSED
|
|
14
|
-
* **单集**:范围内不设第二集——工作树里范围外的档不入判、不入报面(用户 2026-10-25 裁定「只判指定文件」)。
|
|
7
|
+
* 调用面(`scope` 两取值、无第三值):
|
|
8
|
+
* ① `writer`——`batch` 的 `append` ∥ `edit` 两路:判**写者本轮碰过的档**(触达账)∪ 批档自身。
|
|
9
|
+
* `append` 交候选全文、`edit` 交改写后的整档视图——那些字节还没落盘,所以直接从文本判,不造临时档。
|
|
10
|
+
* `REFUSED` ⇒ 调用面 throw(零字节);门自身异常 ⇒ 放行 + 回执明示(子代理无法重启会话,卡死写账 = 无账之笔)。
|
|
11
|
+
* ② `close`——收口 ∥ `status → 已收口`:笔域集 = **触达账 ∪ 本批提交 diff ∪ 批档自身**,判域 = 其中
|
|
12
|
+
* **收口时点要判的那几档**(`judgedDomainDocs`:批档面整份移出——批档只在写的那一刻判)。
|
|
13
|
+
* `REFUSED` ∥ 门自身异常 ⇒ 调用面 throw(fail-closed)。
|
|
15
14
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* `append` ⇒ 只入回执、不阻本次写——追加不碰既有行,拒一个改不动的人只会让这一段永远写不进
|
|
20
|
-
* (无账之笔);本次追加文(片段档)与触达账命中当场拒。
|
|
21
|
-
* `edit`(携 `pending.recordView` = **改写后的整档**)⇒ **判集两类**:段长类(段落过长 · 行过长)只判
|
|
22
|
-
* `newText`(片段档)——一条早先就在的超长段不拦本段的无关改动;**锚类判整档、当场拒**——引用完整性
|
|
23
|
-
* 是档级属性,且这一段的作者改得动那一行。盘上旧字节不参判(拿改写前的档判,#2021 那条死引文
|
|
24
|
-
* 永远过不去);
|
|
25
|
-
* · ② 面命中即 K,且命中落在批档内时逐条带 `§N(作者:<角色>)`(答「谁该改」;作者取自档头
|
|
26
|
-
* 「一段一作者」映射,取不到 ⇒ 只出 `§N`,不猜)。
|
|
15
|
+
* **判域带时点**(判据句单源 = `docs/core/design/DOC-CHECK.md` §9):两个 `scope` 各站一个时点,判域一律由
|
|
16
|
+
* 引擎的 `judgedDomainDocs` 算——写时点原样交回,收口时点移出批档面。两处各写一份「批档免不免」,就会让
|
|
17
|
+
* `范围 N 档` 与 `doc_check` 的 `checkFiles` 迟早不同数,而 `CLI 7-7` 断的就是两数相等。
|
|
27
18
|
*
|
|
28
|
-
*
|
|
29
|
-
* `
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* 所在档切强制集 / 明示集,回执把片段档显示成「本次写入文本」。片段档 `finally` 删;同目录的
|
|
35
|
-
* `.gate-*` 残留**只明示、不代删**(并发进程的活片段是别人正在判的档)。
|
|
36
|
-
* ② **提交 diff 腿的基 sha 只读批档 §1 的记入行**(`批起 sha = <sha>`——取行内首个 40 位十六进制串);
|
|
37
|
-
* 取不到(无该行 ∥ 形态不合 ∥ git 跑不出该 diff)⇒ 只认触达账 + 回执明示「基 sha 未定」(不静默)。
|
|
19
|
+
* **判域 = 本批变更区**(§6):一份档进了判域不等于它整份进来判——只判量出的那几行,区内照判三件、区外一字不出。
|
|
20
|
+
* 两个时点取法不同源:收口读 `git diff -U0 <批起 sha>`(`changedRegionsOf`);写时点读盘上现文与这一笔要写的候选
|
|
21
|
+
* 全文两份(`changedRegionOf`),表里只装这一笔在写的那一档。
|
|
22
|
+
* 取区之前,收口臂自己把要判的档 `git add` 掉(`stageDocs`,按路径限定、不 `git add -A`)——索引外的档
|
|
23
|
+
* `git diff` 看不见,那不是「没改」(§6「收口门自己把要判的档 `git add` 掉」)。写时点不动索引。
|
|
24
|
+
* 不拦的那一层不出声:门内没有「判了但不阻断」的读数行(用户令:不拦截的就不要报数)。
|
|
38
25
|
*/
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import { dirname, join, relative, resolve } from "node:path"
|
|
26
|
+
import { readFileSync } from "node:fs"
|
|
27
|
+
import { resolve } from "node:path"
|
|
42
28
|
|
|
43
29
|
import { owningProject, readManifest } from "../manifest.mjs"
|
|
44
|
-
import {
|
|
30
|
+
import { changedRegionOf, displayPath, hitLine, judgeText, judgedDomainDocs, MOMENT } from "../doc-check/index.mjs"
|
|
31
|
+
import { plannedPathsOf } from "../doc-check/existence.mjs"
|
|
32
|
+
import { changedRegionsOf, committedDocs, stageDocs } from "./batch-regions.mjs"
|
|
45
33
|
import { sectionHeaderRe } from "./batch-skeleton.mjs"
|
|
46
34
|
import { batchProjectRoot } from "./batch-paths.mjs"
|
|
47
35
|
|
|
48
|
-
/** 平台路径键(win32 大小写不敏感——只作集比对,非判据面)。 */
|
|
49
|
-
const pathKey = (p) => (process.platform === "win32" ? p.toLowerCase() : p)
|
|
50
|
-
|
|
51
36
|
/** 文档档谓词 + 绝对化(触达账 / 提交 diff 同形;非 `.md` 不进范围)。 */
|
|
52
37
|
const isDocPath = (p) => typeof p === "string" && p.trim() !== "" && p.toLowerCase().endsWith(".md")
|
|
53
38
|
function docPaths(list, base) {
|
|
@@ -56,92 +41,15 @@ function docPaths(list, base) {
|
|
|
56
41
|
return out
|
|
57
42
|
}
|
|
58
43
|
|
|
59
|
-
/**
|
|
60
|
-
|
|
61
|
-
const ANCHOR_CLASSES = new Set(["档缺", "节缺", "引缺"])
|
|
62
|
-
|
|
63
|
-
/** 片段档名前缀(与批档同目录的隐藏档——锚解析序 ② 与批档本体同源)。**导出面**:`batch-lifecycle.mjs` 的在飞
|
|
64
|
-
* 扫描要靠它把两类片段档排除在外——`edit` 面的 `recordView` 是**整档副本**(`## §1` 段头 + `进行中` 都在),
|
|
65
|
-
* 不排除就会被当成第二本在飞批(假拒),进程被杀则残留一本永久 open 的幽灵档。 */
|
|
66
|
-
export const FRAGMENT_PREFIX = ".gate-"
|
|
67
|
-
|
|
68
|
-
/** 片段档路径(每次一个随机名:并发两次门不撞名,也不互删)。 */
|
|
69
|
-
function fragmentPathOf(abs) {
|
|
70
|
-
return join(dirname(abs), `${FRAGMENT_PREFIX}${process.pid}-${Math.random().toString(36).slice(2, 10)}.md`)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** 同目录 `.gate-*` 残留(进程在写片段后、清理前被杀):**只扫不删**——并发进程的活片段是别人正在判的档。 */
|
|
74
|
-
function strayFragmentsOf(dir, ownAbs) {
|
|
75
|
-
let names
|
|
76
|
-
try { names = readdirSync(dir) } catch { return [] }
|
|
77
|
-
const skip = ownAbs ? pathKey(ownAbs) : null
|
|
78
|
-
return names.filter((n) => n.startsWith(FRAGMENT_PREFIX) && n.endsWith(".md") && pathKey(join(dir, n)) !== skip)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** 读档(读不到 ⇒ 空串:归属标注取不到就只出 `§N`,不猜)。 */
|
|
82
|
-
function safeRead(abs) {
|
|
83
|
-
try { return readFileSync(abs, "utf8") } catch { return "" }
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/** 批档档头骨架行的「一段一作者」映射(`batch` create 落骨架时写入)——取不到 ⇒ 空表。 */
|
|
87
|
-
function authorMapOf(src) {
|
|
88
|
-
const map = new Map()
|
|
89
|
-
for (const line of String(src ?? "").split("\n")) {
|
|
90
|
-
if (!line.includes("一段一作者")) continue
|
|
91
|
-
for (const m of line.matchAll(/§\s*(\d+)\s*[^((]*[((]([^))]+)[))]/g)) {
|
|
92
|
-
const n = Number(m[1])
|
|
93
|
-
if (!map.has(n)) map.set(n, m[2].trim())
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return map
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** 行号 → 所属段号(`## §N` 段头分段;首个段头之前 ⇒ null)。 */
|
|
100
|
-
function sectionOfLine(src, line) {
|
|
101
|
-
const lines = String(src ?? "").split("\n")
|
|
102
|
-
const end = Math.min(line, lines.length)
|
|
103
|
-
let cur = null
|
|
104
|
-
for (let i = 0; i < end; i++) {
|
|
105
|
-
const m = /^## §(\d+)(?=\s|$)/.exec(lines[i])
|
|
106
|
-
if (m) cur = Number(m[1])
|
|
107
|
-
}
|
|
108
|
-
return cur
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** 命中行落在批档内时的归属标注:` §N(作者:<角色>)`;作者取不到 ⇒ 只出 ` §N`(不猜)。 */
|
|
112
|
-
function attributionOf(src, line, authors) {
|
|
113
|
-
const seg = sectionOfLine(src, line)
|
|
114
|
-
if (seg === null) return ""
|
|
115
|
-
const who = authors.get(seg)
|
|
116
|
-
return who ? ` §${seg}(作者:${who})` : ` §${seg}`
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** 明示集的单条摘要(`§N 第 M 行(作者:<角色>)`)。 */
|
|
120
|
-
function landedSummary(src, entry, authors) {
|
|
121
|
-
const seg = sectionOfLine(src, entry.line)
|
|
122
|
-
const at = seg === null ? `第 ${entry.line} 行` : `§${seg} 第 ${entry.line} 行`
|
|
123
|
-
const who = seg === null ? null : authors.get(seg)
|
|
124
|
-
return who ? `${at}(作者:${who})` : at
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** 命中集按类分列(`锚 A 条 · P 处<类名>`)——引擎报面行形不动,只在这里做计数。 */
|
|
128
|
-
function classifyCounts(entries) {
|
|
129
|
-
const parts = []
|
|
130
|
-
const anchor = entries.filter((e) => ANCHOR_CLASSES.has(e.clazz)).length
|
|
131
|
-
if (anchor) parts.push(`锚 ${anchor} 条`)
|
|
132
|
-
const byClass = new Map()
|
|
133
|
-
for (const e of entries) if (!ANCHOR_CLASSES.has(e.clazz)) byClass.set(e.clazz, (byClass.get(e.clazz) ?? 0) + 1)
|
|
134
|
-
for (const [clazz, n] of byClass) parts.push(`${n} 处${clazz}`)
|
|
135
|
-
return parts.join(" · ")
|
|
136
|
-
}
|
|
44
|
+
/** 路径键(比较用:win32 折小写)。 */
|
|
45
|
+
const pathKey = (p) => (process.platform === "win32" ? String(p).toLowerCase() : String(p))
|
|
137
46
|
|
|
138
47
|
/**
|
|
139
48
|
* `<批起 sha>` 的取法(唯一)= 批档 §1 的记入行 `批起 sha = <sha>`:段界消费 `sectionHeaderRe(1)`
|
|
140
49
|
* (段头形态单源——`## §10` 不误命中 `§1`),取段内该行行内首个 40 位十六进制串。
|
|
141
|
-
* 无该行 ∥ 形态不合 ∥ 读不到 ⇒ `null`——调用面按「基 sha
|
|
142
|
-
* (记入行只认 §1:取法与写入义务单源 = 规范「② 的范围」)。
|
|
50
|
+
* 无该行 ∥ 形态不合 ∥ 读不到 ⇒ `null`——调用面按「基 sha 未定」明示,不静默。
|
|
143
51
|
*/
|
|
144
|
-
function baseShaOf(abs) {
|
|
52
|
+
export function baseShaOf(abs) {
|
|
145
53
|
let src
|
|
146
54
|
try { src = readFileSync(abs, "utf8") } catch { return null }
|
|
147
55
|
const hdr = sectionHeaderRe(1).exec(src)
|
|
@@ -152,85 +60,67 @@ function baseShaOf(abs) {
|
|
|
152
60
|
const body = src.slice(hdr.index + hdr[0].length, next ? next.index : src.length)
|
|
153
61
|
for (const line of body.split(/\r?\n/)) {
|
|
154
62
|
if (!line.includes("批起 sha")) continue
|
|
155
|
-
const sha = /[0-9a-f]{40}/i.exec(line)?.[0]
|
|
63
|
+
const sha = /[0-9a-f]{40,64}/i.exec(line)?.[0]
|
|
156
64
|
if (sha) return sha
|
|
157
65
|
}
|
|
158
66
|
return null
|
|
159
67
|
}
|
|
160
68
|
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
* (`rev-parse --show-toplevel`)为基还原——项目根住大仓子目录时条目不丢(清单相对仓根)。
|
|
164
|
-
* `-c core.quotepath=false`:不关此开关时 git 把含非 ASCII 字节的路径整串加引号转义,
|
|
165
|
-
* 下流 `endsWith(".md")` 判据会判假 ⇒ 非 ASCII 档名的档静默掉出范围(正是本批要关的「范围跑偏」)。
|
|
166
|
-
* 跑不出(非仓 / sha 不可解析)⇒ `ok: false` + 空集(调用面按「基 sha 未定」明示,不静默)。
|
|
167
|
-
*/
|
|
168
|
-
function committedDocs(root, sha) {
|
|
169
|
-
const run = (cwd, argv) => execFileSync("git", ["-C", cwd, "-c", "core.quotepath=false", ...argv], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 8000 })
|
|
170
|
-
try {
|
|
171
|
-
const top = run(root, ["rev-parse", "--show-toplevel"]).trim() || root
|
|
172
|
-
const files = run(top, ["diff", "--name-only", sha, "HEAD"]).split(/\r?\n/).filter(Boolean)
|
|
173
|
-
return { ok: true, base: top, files }
|
|
174
|
-
} catch {
|
|
175
|
-
return { ok: false, base: root, files: [] }
|
|
176
|
-
}
|
|
177
|
-
}
|
|
69
|
+
/** 空范围返回形(`range` 恒在场——回执要读 `范围 N 档`)。 */
|
|
70
|
+
const emptyRange = (basis) => ({ count: 0, k: 0, basis })
|
|
178
71
|
|
|
179
|
-
/**
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
function hitEntries(res, root, translate) {
|
|
183
|
-
const lines = res.report.split("\n").filter((l) => l.startsWith("✗ "))
|
|
184
|
-
const hits = [...res.anchorHits, ...res.paragraphHits]
|
|
185
|
-
const aligned = lines.length === hits.length
|
|
186
|
-
const entries = hits.map((h, i) => ({
|
|
187
|
-
file: h.file,
|
|
188
|
-
line: h.line,
|
|
189
|
-
clazz: h.clazz,
|
|
190
|
-
text: translate(aligned ? lines[i] : `✗ ${relative(root, h.file).replace(/\\/g, "/")}:${h.line}`),
|
|
191
|
-
}))
|
|
192
|
-
return { aligned, entries }
|
|
193
|
-
}
|
|
72
|
+
/** 门自身异常态(不产 PASS:这一轮没判完,不能读成判过)。 */
|
|
73
|
+
const errorState = (first, range = emptyRange("none")) =>
|
|
74
|
+
({ state: "error", first, report: first, hitLines: [], noteLines: [], unjudged: [], range })
|
|
194
75
|
|
|
195
|
-
/**
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
out.push(...notes)
|
|
204
|
-
if (disposePara) out.push(...PARA_DISPOSE)
|
|
205
|
-
return out.join("\n")
|
|
76
|
+
/** 成功回执行(append ∥ close ∥ status 三面同形):verdict + `范围 N 档`。 */
|
|
77
|
+
export function gateReceiptLine(gate) {
|
|
78
|
+
if (!gate) return ""
|
|
79
|
+
if (gate.state === "not-applicable") return "\n[doc-check gate] 未跑(本项目无声明面)"
|
|
80
|
+
// 「没判」照实说:判不成的档逐行点名——`范围 N 档` 只数真判过的,不把它算成干净(假绿防线)。
|
|
81
|
+
const unjudged = (gate.unjudged ?? []).map((l) => `\n ${l}`).join("")
|
|
82
|
+
return `\n[doc-check gate] ${gate.first} · 范围 ${gate.range?.count ?? 0} 档${unjudged}`
|
|
206
83
|
}
|
|
207
84
|
|
|
208
|
-
/**
|
|
209
|
-
|
|
210
|
-
|
|
85
|
+
/**
|
|
86
|
+
* 拒绝串(throw 载荷):`batch:` 前缀 + verdict 首行 + 逐条命中行 + 零字节声明。
|
|
87
|
+
* 处置面不在这里:命中行说的是哪一处、为什么,改法归作者;本门只拒、不代改。
|
|
88
|
+
*/
|
|
89
|
+
export function gateRefusalMessage(gate, action = "append") {
|
|
90
|
+
const writeFace = action === "append" || action === "edit"
|
|
91
|
+
const lead = action === "edit"
|
|
92
|
+
? "batch: 文档机检门拒写(doc-check gate)—— 本次段内就地改未落盘,档字节不变。"
|
|
93
|
+
: writeFace
|
|
94
|
+
? "batch: 文档机检门拒写(doc-check gate)—— 本次段写入未落盘,档字节不变。"
|
|
95
|
+
: `batch: 文档机检门拒收口(doc-check gate)—— ${action === "close" ? "close" : "status → 已收口"} 被拒绝,§1 状态行字节不变。`
|
|
96
|
+
const detail = gate.state === "error" ? String(gate.report ?? "").split("\n").slice(1) : gate.hitLines
|
|
97
|
+
const noBytes = writeFace
|
|
98
|
+
? action === "edit"
|
|
99
|
+
? "Nothing was written — the target range and every other byte of the record are unchanged."
|
|
100
|
+
: "Nothing was written. Do NOT close the record after a refused append — nothing landed, and closing freezes the missing section for good (失败 ⇒ 勿 close)."
|
|
101
|
+
: "Nothing was written."
|
|
102
|
+
return [lead, gate.first, ...(detail ?? []), `处置:同轮修正后复跑(改文档 ∥ 修引擎);不转台账;拿不准 ⇒ 上抛主 agent 裁决。${noBytes}`].join("\n")
|
|
103
|
+
}
|
|
211
104
|
|
|
212
105
|
/**
|
|
213
|
-
*
|
|
214
|
-
* @param {{abs:string, cwd?:string, agent?:object, scope?:'writer'|'close',
|
|
215
|
-
*
|
|
216
|
-
* `
|
|
217
|
-
* `body` =
|
|
218
|
-
* `recordView` = **改写后的整档全文**(仅 `edit` 面传:锚类判这个视图,盘上旧字节不参判)。
|
|
106
|
+
* 跑一次门(**非抛错**:门自身异常收为 `error` 态,由调用面按 `scope` 消费)。
|
|
107
|
+
* @param {{abs:string, cwd?:string, agent?:object, scope?:'writer'|'close',
|
|
108
|
+
* pending?:{section?:number, body?:string, recordView?:string}|null}} o
|
|
109
|
+
* `abs` = 目标批次档绝对路径(**笔域集恒含它**;收口时点它是批档面 ⇒ 不进判域,见 `judgedDomainDocs`);`agent._touchedFiles` = 触达记账;
|
|
110
|
+
* `pending.body` = 本次写进来的文本(`append` 候选全文);`pending.recordView` = 改写后的整档全文(`edit`)。
|
|
219
111
|
* @returns {{state:'pass'|'refused'|'error'|'not-applicable', first:string|null, report:string,
|
|
220
|
-
* hitLines:string[], noteLines:string[],
|
|
221
|
-
* `
|
|
222
|
-
* `
|
|
112
|
+
* hitLines:string[], noteLines:string[], unjudged:string[], range:{count:number, k:number, basis:string}}}
|
|
113
|
+
* `unjudged` = 判不成的档(逐行「不在盘,未判」∥「读不到,未判」)——回执行把它附在 `范围 N 档` 之后,
|
|
114
|
+
* 且 `range.count` 只数真判过的(没判的档不算进范围、也不算干净)。
|
|
223
115
|
*/
|
|
224
116
|
export function runBatchGate({ abs, cwd, agent = {}, scope = "writer", pending = null } = {}) {
|
|
225
|
-
// `scope` 两取值、无第三值(设计「`scope` 语义」)——未知值不静默降级(降级即 ② 变 fail-open)
|
|
226
117
|
if (scope !== "writer" && scope !== "close") {
|
|
227
118
|
return errorState(`DOC-CHECK GATE: ERROR(未知 scope:${JSON.stringify(scope)}——取值只有 "writer" ∥ "close")`)
|
|
228
119
|
}
|
|
229
120
|
try {
|
|
230
121
|
return evaluate({ abs, cwd, agent, scope, pending })
|
|
231
122
|
} catch (e) {
|
|
232
|
-
|
|
233
|
-
return errorState(first)
|
|
123
|
+
return errorState(`DOC-CHECK GATE: ERROR(门自身异常:${e?.message ?? String(e)})`)
|
|
234
124
|
}
|
|
235
125
|
}
|
|
236
126
|
|
|
@@ -241,179 +131,89 @@ function evaluate({ abs, cwd, agent, scope, pending }) {
|
|
|
241
131
|
const root = owningProject(selfAbs, base) ?? batchProjectRoot(base)
|
|
242
132
|
const close = scope === "close"
|
|
243
133
|
|
|
244
|
-
|
|
245
|
-
try { read = readManifest(root) } catch (e) {
|
|
246
|
-
return errorState(`DOC-CHECK GATE: ERROR(manifest 不可读 —— ${e?.message ?? String(e)})`)
|
|
247
|
-
}
|
|
248
|
-
// 适用面(声明面驱动):无 manifest ⇒ 不适用 + 回执明示;**不是豁免清单**——判据参数 = 引擎内置常量。
|
|
134
|
+
const read = readManifest(root)
|
|
249
135
|
if (!read.ok && read.reason === "missing") {
|
|
250
|
-
return { state: "not-applicable", first: null, report: "[doc-check gate] 未跑(本项目无声明面)", hitLines: [], noteLines: [],
|
|
136
|
+
return { state: "not-applicable", first: null, report: "[doc-check gate] 未跑(本项目无声明面)", hitLines: [], noteLines: [], unjudged: [], range: emptyRange("none") }
|
|
251
137
|
}
|
|
252
138
|
|
|
253
|
-
//
|
|
254
|
-
// close = 本批笔域集 = 触达账 ∪ 本批提交 diff ∪ 批档自身(**单集**——范围外的档不入判、不入报面)。
|
|
139
|
+
// 取材:writer = 触达账 ∪ 批档自身;close = 触达账 ∪ 本批提交 diff ∪ 批档自身(单集,范围外的档不入判域)。
|
|
255
140
|
const touched = docPaths(agent?._touchedFiles, base)
|
|
256
141
|
const baseSha = close ? baseShaOf(selfAbs) : null
|
|
257
|
-
const diff = baseSha ? committedDocs(root, baseSha) : { ok: false, base: root, files: [] }
|
|
142
|
+
const diff = close && baseSha ? committedDocs(root, baseSha) : { ok: false, base: root, files: [] }
|
|
258
143
|
const diffDocs = docPaths(diff.ok ? diff.files : [], diff.base)
|
|
144
|
+
// 笔域集 = 取材两面 ∪ 批档自身;判域 = 其中这一刻真判的档(§9)。收口时点批档面整份移出——
|
|
145
|
+
// 判它量的是几小时前的记录与现态的距离,不是缺陷;写时点原样交回(§9 表第一行)。
|
|
146
|
+
const penDomain = [...new Map([...touched, ...diffDocs, selfAbs].map((p) => [pathKey(p), p])).values()]
|
|
147
|
+
const docs = judgedDomainDocs(penDomain, { moment: close ? MOMENT.close : MOMENT.writer, root })
|
|
259
148
|
|
|
260
|
-
|
|
261
|
-
const pendingBody = !close && pending && typeof pending.body === "string" && pending.body.trim() ? pending.body : null
|
|
262
|
-
const fragAbs = pendingBody ? fragmentPathOf(selfAbs) : null
|
|
263
|
-
// 改写后的整档视图(`edit` 面——锚类判它,不判盘上旧字节:本批要消的正是「死引文那行改不动」那个死锁)。
|
|
149
|
+
// 本次写入的判定输入(写时点):`edit` = 改写后整档视图;`append` = 候选全文。
|
|
264
150
|
const viewBody = !close && pending && typeof pending.recordView === "string" ? pending.recordView : null
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const viewRel = viewAbs ? relative(root, viewAbs).replace(/\\/g, "/") : null
|
|
287
|
-
const translate = (text) => {
|
|
288
|
-
let out = fragRel ? text.split(fragRel).join("本次写入文本") : text
|
|
289
|
-
return viewRel ? out.split(viewRel).join(selfRel) : out // 视图档显示成批档自身的相对路径(读者不必知道临时档名)
|
|
290
|
-
}
|
|
291
|
-
const { aligned, entries } = hitEntries(res, root, translate)
|
|
292
|
-
|
|
293
|
-
const selfSrc = viewBody ?? safeRead(selfAbs)
|
|
294
|
-
const authors = authorMapOf(selfSrc)
|
|
295
|
-
const labeled = entries.map((e) => {
|
|
296
|
-
const inSelf = pathKey(e.file) === selfKey
|
|
297
|
-
return { ...e, inSelf, text: inSelf ? `${e.text}${attributionOf(selfSrc, e.line, authors)}` : e.text }
|
|
298
|
-
})
|
|
299
|
-
// ① 面(**按动作分两种**——判集单源 = `BATCH-RECORD.md` §4.9 门 ④ 判集两句):
|
|
300
|
-
// append(无视图)⇒ 批档已落段命中只明示、不阻写(追加不碰既有行,拒一个改不动的人 = 无账之笔);其余当场拒。
|
|
301
|
-
// edit(有视图)⇒ **判集两类**:档内**锚类**命中当场拒(引用完整性是档级属性);档内**段长类**命中只明示
|
|
302
|
-
// (段长类只判 `newText`——那条在片段档里判,不在这里)。
|
|
303
|
-
// ② 面:范围内全部命中即 K。
|
|
304
|
-
const blocks = (e) => !e.inSelf || (viewAbs !== null && ANCHOR_CLASSES.has(e.clazz))
|
|
305
|
-
const disclosed = close ? [] : labeled.filter((e) => !blocks(e))
|
|
306
|
-
const forced = close ? labeled : labeled.filter(blocks)
|
|
307
|
-
const k = forced.length
|
|
308
|
-
const forcedLines = forced.map((e) => e.text)
|
|
309
|
-
const disclosedLines = disclosed.map((e) => e.text)
|
|
310
|
-
|
|
311
|
-
const inFrag = (e) => !!fragAbs && pathKey(e.file) === pathKey(fragAbs)
|
|
312
|
-
const textHits = forced.filter(inFrag)
|
|
313
|
-
const recordHits = forced.filter((e) => e.inSelf) // 仅 edit 面可达:整档锚类命中
|
|
314
|
-
const touchHits = forced.filter((e) => !inFrag(e) && !e.inSelf)
|
|
315
|
-
let first = "DOC-CHECK GATE: PASS"
|
|
316
|
-
if (k >= 1) {
|
|
317
|
-
if (close) {
|
|
318
|
-
first = `DOC-CHECK GATE: REFUSED(命中 ${k} 条)`
|
|
319
|
-
} else {
|
|
320
|
-
const parts = []
|
|
321
|
-
if (textHits.length) parts.push(`本次写入文本(${classifyCounts(textHits)})`)
|
|
322
|
-
if (recordHits.length) parts.push(`批档整档(${classifyCounts(recordHits)})`)
|
|
323
|
-
if (touchHits.length) parts.push(`触达账(${classifyCounts(touchHits)})`)
|
|
324
|
-
first = `DOC-CHECK GATE: REFUSED(命中 ${k} 条——${parts.join(" · ")})`
|
|
325
|
-
}
|
|
326
|
-
}
|
|
151
|
+
const body = !close && pending && typeof pending.body === "string" && pending.body.trim() ? pending.body : null
|
|
152
|
+
const fromCandidate = viewBody === null && body !== null
|
|
153
|
+
const inputBody = viewBody ?? body
|
|
154
|
+
|
|
155
|
+
// 判哪几行(§6):两个时点取法不同源。
|
|
156
|
+
// 收口:按**本批变更区**收窄到行(取不到基线 ∥ 旧形批 ∥ 非 git 目录 ⇒ 空表 ⇒ 每一档都没有要判的行)。
|
|
157
|
+
// 收口门自己把要判的档 add 掉再取区:索引外的档 `git diff` 看不见,那不是「没改」;没有基线就没有要取的区 ⇒ 索引也不动。
|
|
158
|
+
// 写时点:表**只装这一笔在写的那一档**——该档区间 = 盘上现文与候选全文两份直接求(`changedRegionOf`),
|
|
159
|
+
// 与写门同一句;盘上读不到该档现文 ⇒ 那一格 `null` = 整份判(新档同一条);本笔没有候选文本 ⇒ 不进表 ⇒ 零输出。
|
|
160
|
+
// 其余进笔域集的档本笔一字未写 ⇒ 不在表里 ⇒ 不判、不数(走下面 `region === undefined ⇒ continue`)。
|
|
161
|
+
if (close && baseSha) stageDocs(root, docs)
|
|
162
|
+
let regions = null
|
|
163
|
+
if (close) {
|
|
164
|
+
regions = changedRegionsOf(root, baseSha, docs).regions
|
|
165
|
+
} else if (inputBody !== null) {
|
|
166
|
+
let current = null
|
|
167
|
+
try { current = readFileSync(selfAbs, "utf8") } catch { current = null }
|
|
168
|
+
regions = new Map([[resolve(selfAbs), current === null ? null : changedRegionOf(current, inputBody)]])
|
|
169
|
+
} else {
|
|
170
|
+
regions = new Map()
|
|
171
|
+
}
|
|
327
172
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
: `已落段命中 ${disclosed.length} 条:${list}—— 不属本次笔面,不阻本次写;收口面 fail-closed 会拦`)
|
|
173
|
+
const planned = plannedPathsOf(root)
|
|
174
|
+
const hits = []
|
|
175
|
+
const hitLines = []
|
|
176
|
+
const notes = []
|
|
177
|
+
const unjudged = []
|
|
178
|
+
let judged = 0
|
|
179
|
+
const selfKey = pathKey(selfAbs)
|
|
180
|
+
for (const doc of docs) {
|
|
181
|
+
const isSelf = pathKey(doc) === selfKey
|
|
182
|
+
// 没有要判的行 ⇒ 这一档一行也不出(不点名、不解释,也不计入 `范围 N 档`)。
|
|
183
|
+
const region = regions === null ? null : regions.get(resolve(doc))
|
|
184
|
+
if (regions !== null && region === undefined) continue
|
|
185
|
+
if (isSelf && inputBody !== null) {
|
|
186
|
+
const given = judgeText(inputBody, { file: selfAbs, root, planned, region })
|
|
187
|
+
hits.push(...given)
|
|
188
|
+
const at = `${displayPath(root, selfAbs)}(${fromCandidate ? "候选文本" : "改写后整档"})`
|
|
189
|
+
for (const h of given) hitLines.push(hitLine(root, h).replace(displayPath(root, selfAbs), at))
|
|
190
|
+
judged += 1
|
|
191
|
+
continue
|
|
348
192
|
}
|
|
349
|
-
|
|
350
|
-
|
|
193
|
+
let text
|
|
194
|
+
try { text = readFileSync(doc, "utf8") } catch (e) {
|
|
195
|
+
// 区间面、区内只有纯删的缝、且盘上真没了(ENOENT)= 这一档在建档之后被删掉整份 ⇒ 不出一行(§6)。
|
|
196
|
+
// 还在地盘上却读不到 ⇒ 它不是那个情形,照实点名(否则一条读失败就被吞成零输出了)。
|
|
197
|
+
// `region === null`(这一档判整份)不是那个情形——那一格走的是读盘后的整份判。
|
|
198
|
+
if (regions !== null && region !== null && (region.rows ?? []).length === 0 && e?.code === "ENOENT") continue
|
|
199
|
+
unjudged.push(e?.code === "ENOENT" ? `${displayPath(root, doc)} 不在盘,未判` : `${displayPath(root, doc)} 读不到,未判`)
|
|
200
|
+
continue
|
|
351
201
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
disclosedHeader: viewAbs !== null ? "—— 档内段长类命中(只明示、不阻本次写;段长类判集 = 本次写入文本):" : undefined,
|
|
369
|
-
}),
|
|
370
|
-
hitLines: forcedLines,
|
|
371
|
-
noteLines: notes,
|
|
372
|
-
// 处置面分形用(拒串读它:段命中 ⇒ 五行块 ∥ 仅锚·仅行 ⇒ 照旧一句处置)
|
|
373
|
-
disposePara,
|
|
374
|
-
range: { count: res.checkFiles.length, k, basis },
|
|
375
|
-
}
|
|
376
|
-
} finally {
|
|
377
|
-
if (viewAbs) { try { unlinkSync(viewAbs) } catch { /* 清理失败不覆盖判定结果——残留由下一次门明示 */ } }
|
|
378
|
-
if (fragAbs) { try { unlinkSync(fragAbs) } catch { /* 清理失败不覆盖判定结果——残留由下一次门明示 */ } }
|
|
202
|
+
judged += 1
|
|
203
|
+
const given = judgeText(text, { file: doc, root, planned, region })
|
|
204
|
+
hits.push(...given)
|
|
205
|
+
for (const h of given) hitLines.push(hitLine(root, h))
|
|
206
|
+
}
|
|
207
|
+
if (fromCandidate) notes.push("本次写入尚未落盘——一个字没写(档字节逐字不变)。")
|
|
208
|
+
|
|
209
|
+
const first = hits.length ? "DOC-CHECK GATE: REFUSED" : "DOC-CHECK GATE: PASS"
|
|
210
|
+
return {
|
|
211
|
+
state: hits.length ? "refused" : "pass",
|
|
212
|
+
first,
|
|
213
|
+
report: [first, ...hitLines, ...unjudged, ...notes].join("\n"),
|
|
214
|
+
hitLines,
|
|
215
|
+
noteLines: notes,
|
|
216
|
+
unjudged,
|
|
217
|
+
range: { count: judged, k: hits.length, basis: close ? (baseSha === null ? "touched(基 sha 未定)" : diff.ok ? "touched+diff" : "touched(提交 diff 腿未取到)") : "touched+pending" },
|
|
379
218
|
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
/** 成功回执行(append / close / status 三面同形;`null` 门 ⇒ 零改——非挂门路径回执逐字旧形)。
|
|
383
|
-
* 两件 = verdict + `范围 N 档` 事实行;附注行(「基 sha 未定」∥ 命中行不可对齐 ∥ 已落段命中 ∥ 片段档残留)紧随其后
|
|
384
|
-
* **逐字**列出——不静默吞掉可见性。 */
|
|
385
|
-
export function gateReceiptLine(gate) {
|
|
386
|
-
if (!gate) return ""
|
|
387
|
-
if (gate.state === "not-applicable") return "\n[doc-check gate] 未跑(本项目无声明面)"
|
|
388
|
-
const head = `\n[doc-check gate] ${gate.first} · 范围 ${gate.range?.count ?? 0} 档`
|
|
389
|
-
return [head, ...(gate.noteLines ?? []).map((l) => `\n${l}`)].join("")
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* 拒绝串(throw 载荷;两机械点同源措辞):`batch:` 前缀 + verdict 首行 + 逐条 `✗` 行 + 附注行 + 处置面。
|
|
394
|
-
* **处置面按命中类分形**(本批裁定):
|
|
395
|
-
* · 段命中 ⇒ **空行 + 五行处置块**(字面单源 = 引擎的 `PARA_DISPOSE`)。块末行逐字就是「同轮修正后复跑;不转台账」,
|
|
396
|
-
* 故旧尾句那一截删去——留着就是两句「处置:」+ 一句重复;收尾的裁决指引与「Nothing was written」两句不重复,随原因面照出。
|
|
397
|
-
* · 仅锚 ∥ 仅行命中 ⇒ **照旧一句**(那五条出路是给「段」的,对错误的面对动手比不给方向更贵)。
|
|
398
|
-
* ① 写盘面两路(`append` 段尾 ∥ `edit` 段内区间)同路既有句「失败 ⇒ 勿 close」(字面同 append 既有拒因,不新造措辞)。
|
|
399
|
-
*/
|
|
400
|
-
export function gateRefusalMessage(gate, action = "append") {
|
|
401
|
-
const writeFace = action === "append" || action === "edit" // 写盘面两路:段尾追加 ∥ 段内区间改写
|
|
402
|
-
const lead = action === "edit"
|
|
403
|
-
? "batch: 文档机检门拒写(doc-check gate · 结构兜底 ①)—— 本次段内就地改未落盘,档字节不变。"
|
|
404
|
-
: writeFace
|
|
405
|
-
? "batch: 文档机检门拒写(doc-check gate · 结构兜底 ①)—— 本次段写入未落盘,档字节不变。"
|
|
406
|
-
: `batch: 文档机检门拒收口(doc-check gate · 结构兜底 ②)—— ${action === "close" ? "close" : "status → 已收口"} 被拒绝,§1 状态行字节不变。`
|
|
407
|
-
const detail = gate.state === "error" ? String(gate.report ?? "").split("\n").slice(1) : gate.hitLines
|
|
408
|
-
const routing = "拿不准 ⇒ 上抛主 agent 裁决(主 agent 拿不准 ⇒ 转呈用户)。"
|
|
409
|
-
// 尾句按动作取形:`edit` 拒后段里本就有内容,劝「勿 close」把两件事说成一件(那句防的是收口冻结一个空段)。
|
|
410
|
-
const noBytes = writeFace
|
|
411
|
-
? action === "edit"
|
|
412
|
-
? "Nothing was written — the target range and every other byte of the record are unchanged."
|
|
413
|
-
: "Nothing was written. Do NOT close the record after a refused append — nothing landed, and closing freezes the missing section for good (失败 ⇒ 勿 close)."
|
|
414
|
-
: "Nothing was written."
|
|
415
|
-
const head = [lead, gate.first, ...(detail ?? []), ...(gate.noteLines ?? [])]
|
|
416
|
-
// 段命中:原因面 + 空行 + 五行块(处置面 = 块,不再另起一句「处置:同轮修正后复跑…」)
|
|
417
|
-
if (gate.disposePara) return [...head, `${routing}${noBytes}`, "", ...PARA_DISPOSE].join("\n")
|
|
418
|
-
return [...head, `处置:同轮修正后复跑(改文档 ∥ 修引擎);不转台账;${routing}${noBytes}`].join("\n")
|
|
419
219
|
}
|