@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.
- package/CHANGELOG.md +74 -1
- package/advisor/convergence.mjs +34 -3
- package/advisor/loop.mjs +42 -10
- package/advisor/messages.mjs +46 -27
- package/advisor/notice.mjs +1 -1
- package/advisor/project-context.mjs +253 -14
- 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 +57 -4
- package/agent/digest-account.mjs +73 -46
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +35 -22
- package/agent/family-tools.mjs +36 -17
- package/agent/helpers.mjs +123 -95
- package/agent/offload.mjs +84 -0
- package/agent/post-turn.mjs +24 -10
- package/agent/record-results.mjs +19 -7
- package/agent/run-stages.mjs +127 -61
- package/agent/run-start.mjs +45 -8
- package/agent/setup-reminders.mjs +9 -2
- package/agent/setup.mjs +27 -22
- package/agent/spawn-child.mjs +38 -1
- package/agent/suspension.mjs +1 -1
- package/agent/timers.mjs +5 -3
- package/agent/turn-loop.mjs +60 -6
- 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-face.mjs +99 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +39 -13
- 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 +136 -31
- package/agent-tools/async-settle.mjs +2 -2
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +8 -2
- package/agent-tools/batch-closeout.mjs +444 -0
- package/agent-tools/batch-gate.mjs +152 -138
- package/agent-tools/batch-ledger-bind.mjs +392 -0
- package/agent-tools/batch-ledger-link.mjs +73 -0
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +245 -376
- package/agent-tools/batch-paths.mjs +73 -47
- package/agent-tools/batch-read.mjs +1 -1
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +154 -0
- package/agent-tools/batch-segment-vocab.mjs +379 -0
- package/agent-tools/batch-skeleton.mjs +344 -196
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +297 -0
- package/agent-tools/batch.mjs +189 -253
- package/agent-tools/consult.mjs +7 -4
- package/agent-tools/context.mjs +47 -17
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +24 -24
- package/agent-tools/design-token.mjs +318 -39
- package/agent-tools/doc-check.mjs +55 -29
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +10 -9
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/manifest.mjs +34 -15
- package/agent-tools/read-history.mjs +115 -14
- package/agent-tools/review-facts.mjs +40 -15
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/spawn-gates.mjs +19 -22
- package/agent-tools/ssh-session.mjs +120 -111
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +210 -0
- package/agent-tools/ssh-transport.mjs +183 -81
- package/agent-tools/subagent-actions-query.mjs +11 -7
- package/agent-tools/subagent-actions.mjs +1 -1
- package/agent-tools/subagent-async.mjs +11 -11
- 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 +45 -11
- package/agent-tools/subagent-spawn.mjs +143 -104
- package/agent-tools/subagent.mjs +26 -23
- 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 +22 -6
- package/config-defaults.mjs +2 -1
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-presets.mjs +5 -3
- 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 +165 -68
- package/conventions.mjs +11 -9
- package/declaration.mjs +33 -7
- 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 +312 -163
- package/doc-check/line-refs.mjs +38 -0
- package/doc-check/paragraph.mjs +220 -91
- 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 +12 -6
- package/i18n.mjs +2 -2
- package/index-discover.mjs +4 -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 +95 -62
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +76 -244
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +70 -37
- package/ledger-executors.mjs +1 -1
- package/ledger-migrate.mjs +4 -4
- package/ledger-read.mjs +10 -8
- package/ledger-surface.mjs +1 -1
- package/ledger-tools.mjs +83 -24
- package/ledger-variant-notice.mjs +1 -1
- package/ledger-write-ops.mjs +462 -0
- package/ledger.mjs +2 -2
- package/manifest-discovery.mjs +5 -3
- package/manifest-schema.mjs +28 -2
- package/memory/memory-tool.mjs +5 -2
- package/memory/schema.mjs +6 -27
- package/package.json +3 -1
- package/path-resolve.mjs +498 -0
- package/permission.mjs +4 -0
- package/prompt-files.mjs +91 -1
- package/prompt-overlays.mjs +14 -6
- package/prompts/advisor-design.md +66 -22
- package/prompts/advisor-round1.md +37 -3
- package/prompts/advisor-round2.md +44 -10
- package/prompts/advisor-round3.md +43 -9
- package/prompts/common.md +15 -375
- package/prompts/consult-base.md +6 -1
- package/prompts/discipline-engineering.md +251 -95
- package/prompts/discipline-normal.md +4 -250
- 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 +29 -3
- package/prompts/persona-eng-designer.md +131 -159
- package/prompts/persona-engineering.md +202 -131
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-plan.md +6 -1
- package/prompts/persona-tester.md +55 -0
- package/prompts/subagent-base.md +2 -0
- package/provider/anthropic.mjs +6 -4
- package/provider/core.mjs +5 -4
- package/provider/errors.mjs +29 -4
- package/provider/google.mjs +39 -12
- package/provider/rate.mjs +11 -3
- package/provider/responses.mjs +3 -1
- package/provider/sse.mjs +15 -4
- package/provider-flows.mjs +2 -2
- package/session-identity.mjs +21 -0
- 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 +79 -19
- package/session-slot-write.mjs +37 -5
- package/session-slots.mjs +9 -14
- package/session.mjs +29 -8
- package/skip-dirs.mjs +48 -0
- package/team-ledger.mjs +17 -13
- package/text-budget.mjs +4 -0
- package/token-ttl.mjs +73 -4
- package/token-window.mjs +244 -34
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -13
- package/tool-docs/bash.md +2 -37
- 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 +3 -1
- package/tool-docs/browser.md +2 -47
- package/tool-docs/code_search.md +3 -1
- package/tool-docs/consult_start.md +2 -4
- package/tool-docs/consult_stop.md +2 -2
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -14
- package/tool-docs/doc_check.md +2 -72
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +3 -1
- package/tool-docs/edit.md +2 -18
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -12
- package/tool-docs/fetch.md +2 -12
- package/tool-docs/file_ops.md +2 -16
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -27
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +2 -5
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -13
- package/tool-docs/insert_after.md +2 -14
- 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 -9
- 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 -7
- package/tool-docs/manifest.md +2 -28
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +3 -11
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +2 -4
- 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 -6
- package/tool-docs/read_image.md +2 -7
- package/tool-docs/recent_changes.md +3 -1
- package/tool-docs/repo_outline.md +3 -1
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +2 -5
- package/tool-docs/skill.md +3 -5
- package/tool-docs/ssh.md +2 -50
- package/tool-docs/subagent.md +2 -63
- package/tool-docs/task.md +2 -6
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +3 -13
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +3 -1
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -17
- package/tool-docs/write.md +2 -10
- package/tools/bash.mjs +12 -2
- package/tools/browser.mjs +52 -7
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +176 -91
- package/tools/edit-diff.mjs +129 -45
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +11 -5
- package/tools/file.mjs +32 -34
- package/tools/git.mjs +43 -2
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +4 -1
- package/tools/patch.mjs +127 -38
- package/tools/process-doc-mark.mjs +139 -0
- package/tools/search.mjs +15 -6
- package/tools/shared.mjs +31 -7
- package/tools/ssh.mjs +48 -7
- package/tools/tree.mjs +4 -1
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +79 -6
- package/traces/trace-store.mjs +4 -3
- package/window-policy.mjs +203 -0
- package/agent/light-round.mjs +0 -63
- package/agent/unbooked-pen.mjs +0 -62
- package/doc-check/anchors.mjs +0 -135
|
@@ -1,38 +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
|
-
*
|
|
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
|
-
* `
|
|
15
|
+
* **判域带时点**(判据句单源 = `docs/core/design/DOC-CHECK.md` §9):两个 `scope` 各站一个时点,判域一律由
|
|
16
|
+
* 引擎的 `judgedDomainDocs` 算——写时点原样交回,收口时点移出批档面。两处各写一份「批档免不免」,就会让
|
|
17
|
+
* `范围 N 档` 与 `doc_check` 的 `checkFiles` 迟早不同数,而 `CLI 7-7` 断的就是两数相等。
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* **判域 = 本批变更区**(§6):一份档进了判域不等于它整份进来判——只判量出的那几行,区内照判三件、区外一字不出。
|
|
20
|
+
* 两个时点取法不同源:收口读 `git diff -U0 <批起 sha>`(`changedRegionsOf`);写时点读盘上现文与这一笔要写的候选
|
|
21
|
+
* 全文两份(`changedRegionOf`),表里只装这一笔在写的那一档。
|
|
22
|
+
* 取区之前,收口臂自己把要判的档 `git add` 掉(`stageDocs`,按路径限定、不 `git add -A`)——索引外的档
|
|
23
|
+
* `git diff` 看不见,那不是「没改」(§6「收口门自己把要判的档 `git add` 掉」)。写时点不动索引。
|
|
24
|
+
* 不拦的那一层不出声:门内没有「判了但不阻断」的读数行(用户令:不拦截的就不要报数)。
|
|
23
25
|
*/
|
|
24
|
-
import { execFileSync } from "node:child_process"
|
|
25
26
|
import { readFileSync } from "node:fs"
|
|
26
|
-
import {
|
|
27
|
+
import { resolve } from "node:path"
|
|
27
28
|
|
|
28
29
|
import { owningProject, readManifest } from "../manifest.mjs"
|
|
29
|
-
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"
|
|
30
33
|
import { sectionHeaderRe } from "./batch-skeleton.mjs"
|
|
31
34
|
import { batchProjectRoot } from "./batch-paths.mjs"
|
|
32
35
|
|
|
33
|
-
/** 平台路径键(win32 大小写不敏感——只作集比对,非判据面)。 */
|
|
34
|
-
const pathKey = (p) => (process.platform === "win32" ? p.toLowerCase() : p)
|
|
35
|
-
|
|
36
36
|
/** 文档档谓词 + 绝对化(触达账 / 提交 diff 同形;非 `.md` 不进范围)。 */
|
|
37
37
|
const isDocPath = (p) => typeof p === "string" && p.trim() !== "" && p.toLowerCase().endsWith(".md")
|
|
38
38
|
function docPaths(list, base) {
|
|
@@ -41,13 +41,15 @@ function docPaths(list, base) {
|
|
|
41
41
|
return out
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/** 路径键(比较用:win32 折小写)。 */
|
|
45
|
+
const pathKey = (p) => (process.platform === "win32" ? String(p).toLowerCase() : String(p))
|
|
46
|
+
|
|
44
47
|
/**
|
|
45
48
|
* `<批起 sha>` 的取法(唯一)= 批档 §1 的记入行 `批起 sha = <sha>`:段界消费 `sectionHeaderRe(1)`
|
|
46
49
|
* (段头形态单源——`## §10` 不误命中 `§1`),取段内该行行内首个 40 位十六进制串。
|
|
47
|
-
* 无该行 ∥ 形态不合 ∥ 读不到 ⇒ `null`——调用面按「基 sha
|
|
48
|
-
* (记入行只认 §1:取法与写入义务单源 = 规范「② 的范围」)。
|
|
50
|
+
* 无该行 ∥ 形态不合 ∥ 读不到 ⇒ `null`——调用面按「基 sha 未定」明示,不静默。
|
|
49
51
|
*/
|
|
50
|
-
function baseShaOf(abs) {
|
|
52
|
+
export function baseShaOf(abs) {
|
|
51
53
|
let src
|
|
52
54
|
try { src = readFileSync(abs, "utf8") } catch { return null }
|
|
53
55
|
const hdr = sectionHeaderRe(1).exec(src)
|
|
@@ -58,148 +60,160 @@ function baseShaOf(abs) {
|
|
|
58
60
|
const body = src.slice(hdr.index + hdr[0].length, next ? next.index : src.length)
|
|
59
61
|
for (const line of body.split(/\r?\n/)) {
|
|
60
62
|
if (!line.includes("批起 sha")) continue
|
|
61
|
-
const sha = /[0-9a-f]{40}/i.exec(line)?.[0]
|
|
63
|
+
const sha = /[0-9a-f]{40,64}/i.exec(line)?.[0]
|
|
62
64
|
if (sha) return sha
|
|
63
65
|
}
|
|
64
66
|
return null
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
/**
|
|
68
|
-
|
|
69
|
-
* (`rev-parse --show-toplevel`)为基还原——项目根住大仓子目录时条目不丢(清单相对仓根)。
|
|
70
|
-
* `-c core.quotepath=false`:不关此开关时 git 把含非 ASCII 字节的路径整串加引号转义,
|
|
71
|
-
* 下流 `endsWith(".md")` 判据会判假 ⇒ 非 ASCII 档名的档静默掉出范围(正是本批要关的「范围跑偏」)。
|
|
72
|
-
* 跑不出(非仓 / sha 不可解析)⇒ `ok: false` + 空集(调用面按「基 sha 未定」明示,不静默)。
|
|
73
|
-
*/
|
|
74
|
-
function committedDocs(root, sha) {
|
|
75
|
-
const run = (cwd, argv) => execFileSync("git", ["-C", cwd, "-c", "core.quotepath=false", ...argv], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 8000 })
|
|
76
|
-
try {
|
|
77
|
-
const top = run(root, ["rev-parse", "--show-toplevel"]).trim() || root
|
|
78
|
-
const files = run(top, ["diff", "--name-only", sha, "HEAD"]).split(/\r?\n/).filter(Boolean)
|
|
79
|
-
return { ok: true, base: top, files }
|
|
80
|
-
} catch {
|
|
81
|
-
return { ok: false, base: root, files: [] }
|
|
82
|
-
}
|
|
83
|
-
}
|
|
69
|
+
/** 空范围返回形(`range` 恒在场——回执要读 `范围 N 档`)。 */
|
|
70
|
+
const emptyRange = (basis) => ({ count: 0, k: 0, basis })
|
|
84
71
|
|
|
85
|
-
/**
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const lines = res.report.split("\n").filter((l) => l.startsWith("✗ "))
|
|
89
|
-
const hits = [...res.anchorHits, ...res.paragraphHits]
|
|
90
|
-
const aligned = lines.length === hits.length
|
|
91
|
-
const entries = hits.map((h, i) => ({
|
|
92
|
-
file: h.file,
|
|
93
|
-
line: aligned ? lines[i] : `✗ ${relative(root, h.file).replace(/\\/g, "/")}:${h.line}`,
|
|
94
|
-
}))
|
|
95
|
-
return { aligned, entries }
|
|
96
|
-
}
|
|
72
|
+
/** 门自身异常态(不产 PASS:这一轮没判完,不能读成判过)。 */
|
|
73
|
+
const errorState = (first, range = emptyRange("none")) =>
|
|
74
|
+
({ state: "error", first, report: first, hitLines: [], noteLines: [], unjudged: [], range })
|
|
97
75
|
|
|
98
|
-
/**
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
else lines.push(...notes)
|
|
106
|
-
}
|
|
107
|
-
return lines.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}`
|
|
108
83
|
}
|
|
109
84
|
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
|
|
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
|
+
}
|
|
113
104
|
|
|
114
105
|
/**
|
|
115
|
-
*
|
|
116
|
-
* @param {{abs:string, cwd?:string, agent?:object, scope?:'writer'|'close'
|
|
117
|
-
*
|
|
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`)。
|
|
118
111
|
* @returns {{state:'pass'|'refused'|'error'|'not-applicable', first:string|null, report:string,
|
|
119
|
-
* hitLines:string[], noteLines:string[], range:{count:number, k:number, basis:string}}}
|
|
120
|
-
* `
|
|
112
|
+
* hitLines:string[], noteLines:string[], unjudged:string[], range:{count:number, k:number, basis:string}}}
|
|
113
|
+
* `unjudged` = 判不成的档(逐行「不在盘,未判」∥「读不到,未判」)——回执行把它附在 `范围 N 档` 之后,
|
|
114
|
+
* 且 `range.count` 只数真判过的(没判的档不算进范围、也不算干净)。
|
|
121
115
|
*/
|
|
122
|
-
export function runBatchGate({ abs, cwd, agent = {}, scope = "writer" } = {}) {
|
|
123
|
-
// `scope` 两取值、无第三值(设计「`scope` 语义」)——未知值不静默降级(降级即 ② 变 fail-open)
|
|
116
|
+
export function runBatchGate({ abs, cwd, agent = {}, scope = "writer", pending = null } = {}) {
|
|
124
117
|
if (scope !== "writer" && scope !== "close") {
|
|
125
118
|
return errorState(`DOC-CHECK GATE: ERROR(未知 scope:${JSON.stringify(scope)}——取值只有 "writer" ∥ "close")`)
|
|
126
119
|
}
|
|
127
120
|
try {
|
|
128
|
-
return evaluate({ abs, cwd, agent, scope })
|
|
121
|
+
return evaluate({ abs, cwd, agent, scope, pending })
|
|
129
122
|
} catch (e) {
|
|
130
|
-
|
|
131
|
-
return errorState(first)
|
|
123
|
+
return errorState(`DOC-CHECK GATE: ERROR(门自身异常:${e?.message ?? String(e)})`)
|
|
132
124
|
}
|
|
133
125
|
}
|
|
134
126
|
|
|
135
127
|
/** 门体(正常路径——异常由上抛给 `runBatchGate` 收口)。 */
|
|
136
|
-
function evaluate({ abs, cwd, agent, scope }) {
|
|
137
|
-
const base = resolve(cwd
|
|
138
|
-
const
|
|
128
|
+
function evaluate({ abs, cwd, agent, scope, pending }) {
|
|
129
|
+
const base = resolve(cwd)
|
|
130
|
+
const selfAbs = resolve(abs)
|
|
131
|
+
const root = owningProject(selfAbs, base) ?? batchProjectRoot(base)
|
|
139
132
|
const close = scope === "close"
|
|
140
133
|
|
|
141
|
-
|
|
142
|
-
try { read = readManifest(root) } catch (e) {
|
|
143
|
-
return errorState(`DOC-CHECK GATE: ERROR(manifest 不可读 —— ${e?.message ?? String(e)})`)
|
|
144
|
-
}
|
|
145
|
-
// 适用面(声明面驱动):无 manifest ⇒ 不适用 + 回执明示;**不是豁免清单**——判据参数 = 引擎内置常量。
|
|
134
|
+
const read = readManifest(root)
|
|
146
135
|
if (!read.ok && read.reason === "missing") {
|
|
147
|
-
return { state: "not-applicable", first: null, report: "[doc-check gate] 未跑(本项目无声明面)", hitLines: [], noteLines: [], range: emptyRange("none") }
|
|
136
|
+
return { state: "not-applicable", first: null, report: "[doc-check gate] 未跑(本项目无声明面)", hitLines: [], noteLines: [], unjudged: [], range: emptyRange("none") }
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 取材:writer = 触达账 ∪ 批档自身;close = 触达账 ∪ 本批提交 diff ∪ 批档自身(单集,范围外的档不入判域)。
|
|
140
|
+
const touched = docPaths(agent?._touchedFiles, base)
|
|
141
|
+
const baseSha = close ? baseShaOf(selfAbs) : null
|
|
142
|
+
const diff = close && baseSha ? committedDocs(root, baseSha) : { ok: false, base: root, files: [] }
|
|
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 })
|
|
148
|
+
|
|
149
|
+
// 本次写入的判定输入(写时点):`edit` = 改写后整档视图;`append` = 候选全文。
|
|
150
|
+
const viewBody = !close && pending && typeof pending.recordView === "string" ? pending.recordView : null
|
|
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()
|
|
148
171
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
const touched = docPaths(agent?._touchedFiles, base).filter((p) => pathKey(p) !== selfKey)
|
|
154
|
-
const baseSha = close ? baseShaOf(abs) : null
|
|
155
|
-
const diff = baseSha ? committedDocs(root, baseSha) : { ok: false, base: root, files: [] }
|
|
156
|
-
const diffDocs = docPaths(diff.ok ? diff.files : [], diff.base).filter((p) => pathKey(p) !== selfKey)
|
|
157
|
-
const docs = close ? [...new Set([...touched, ...diffDocs])] : touched
|
|
158
|
-
const basis = !close ? "touched" : diff.ok ? "touched+diff" : "touched(基 sha 未定)"
|
|
159
|
-
const res = runDocCheck(root, { mode: "gate", docs, docsSource: close ? "explicit" : "session" })
|
|
160
|
-
|
|
161
|
-
const { aligned, entries } = hitEntries(res, root)
|
|
162
|
-
const k = entries.length // 单集:命中数即 K(没有第二集可排除)
|
|
163
|
-
const first = k >= 1
|
|
164
|
-
? `DOC-CHECK GATE: REFUSED(命中 ${k} 条)`
|
|
165
|
-
: (res.checkFiles.length ? "DOC-CHECK GATE: PASS" : "DOC-CHECK GATE: PASS(0 档)")
|
|
166
|
-
|
|
167
|
-
// 附加行(不静默面):命中行不可对齐(判定面自述)+ 收口面取不到基(只认触达账)。
|
|
172
|
+
|
|
173
|
+
const planned = plannedPathsOf(root)
|
|
174
|
+
const hits = []
|
|
175
|
+
const hitLines = []
|
|
168
176
|
const notes = []
|
|
169
|
-
|
|
170
|
-
|
|
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
|
|
192
|
+
}
|
|
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
|
|
201
|
+
}
|
|
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("本次写入尚未落盘——一个字没写(档字节逐字不变)。")
|
|
171
208
|
|
|
209
|
+
const first = hits.length ? "DOC-CHECK GATE: REFUSED" : "DOC-CHECK GATE: PASS"
|
|
172
210
|
return {
|
|
173
|
-
state:
|
|
211
|
+
state: hits.length ? "refused" : "pass",
|
|
174
212
|
first,
|
|
175
|
-
report:
|
|
176
|
-
hitLines
|
|
213
|
+
report: [first, ...hitLines, ...unjudged, ...notes].join("\n"),
|
|
214
|
+
hitLines,
|
|
177
215
|
noteLines: notes,
|
|
178
|
-
|
|
216
|
+
unjudged,
|
|
217
|
+
range: { count: judged, k: hits.length, basis: close ? (baseSha === null ? "touched(基 sha 未定)" : diff.ok ? "touched+diff" : "touched(提交 diff 腿未取到)") : "touched+pending" },
|
|
179
218
|
}
|
|
180
219
|
}
|
|
181
|
-
|
|
182
|
-
/** 成功回执行(append / close / status 三面同形;`null` 门 ⇒ 零改——非挂门路径回执逐字旧形)。
|
|
183
|
-
* 两件 = verdict + `范围 N 档` 事实行;附注行(「基 sha 未定」∥ 命中行不可对齐)紧随其后**逐字**列出——
|
|
184
|
-
* 不静默吞掉可见性。 */
|
|
185
|
-
export function gateReceiptLine(gate) {
|
|
186
|
-
if (!gate) return ""
|
|
187
|
-
if (gate.state === "not-applicable") return "\n[doc-check gate] 未跑(本项目无声明面)"
|
|
188
|
-
const head = `\n[doc-check gate] ${gate.first} · 范围 ${gate.range?.count ?? 0} 档`
|
|
189
|
-
return [head, ...(gate.noteLines ?? []).map((l) => `\n${l}`)].join("")
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* 拒绝串(throw 载荷;两机械点同源措辞):`batch:` 前缀 + verdict 首行 + 逐条 `✗` 行 + 处置句;
|
|
194
|
-
* ① 追加同路既有句「失败 ⇒ 勿 close」(字面同 append 既有拒因,不新造措辞)。
|
|
195
|
-
*/
|
|
196
|
-
export function gateRefusalMessage(gate, action = "append") {
|
|
197
|
-
const lead = action === "append"
|
|
198
|
-
? "batch: 文档机检门拒写(doc-check gate · 结构兜底 ①)—— 本次段写入未落盘,档字节不变。"
|
|
199
|
-
: `batch: 文档机检门拒收口(doc-check gate · 结构兜底 ②)—— ${action === "close" ? "close" : "status → 已收口"} 被拒绝,§1 状态行字节不变。`
|
|
200
|
-
const detail = gate.state === "error" ? String(gate.report ?? "").split("\n").slice(1) : gate.hitLines
|
|
201
|
-
const tail = action === "append"
|
|
202
|
-
? "处置:同轮修正后复跑(改文档 ∥ 修引擎);不转台账;拿不准 ⇒ 上抛主 agent 裁决(主 agent 拿不准 ⇒ 转呈用户)。Nothing was written. Do NOT close the record after a refused append — nothing landed, and closing freezes the missing section for good (失败 ⇒ 勿 close)."
|
|
203
|
-
: "处置:同轮修正后复跑(改文档 ∥ 修引擎);不转台账;拿不准 ⇒ 上抛主 agent 裁决(主 agent 拿不准 ⇒ 转呈用户)。Nothing was written."
|
|
204
|
-
return [lead, gate.first, ...(detail ?? []), ...(gate.noteLines ?? []), tail].join("\n")
|
|
205
|
-
}
|