@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
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-tools/batch-supersede.mjs — 第三条收口边:**被取代的收口**(`batch({action:"supersede"})`,2026-11-11)。
|
|
3
|
+
*
|
|
4
|
+
* 权威规格 = `docs/core/design/BATCH-RECORD.md` §4.18-D(机制判据单源;本档只实现,不重述口径)。
|
|
5
|
+
* 要修的那一个死局:一份「设计在、实施没做、对象已消失」的批档两条收口路都走不了(正常收口要链门齐全,
|
|
6
|
+
* 补关要行集全归档)⇒ 它名下已完成的 `待核销` 行永远结不掉。这条边靠一句人给的事实冻结它:**谁取代了它**。
|
|
7
|
+
*
|
|
8
|
+
* 这条边不许伪造的部分(用户 2026-11-11 11:54 的裁定,§1「这条边不许伪造的部分」):冻结的记录**不许出现**
|
|
9
|
+
* §3 评审结论 / §4 批准 / §6 验证这些从未发生过的东西;也**不许把这些段留成空白**了事——空白读起来像
|
|
10
|
+
* 「还没来得及写」,而事实是「这批永远不会实施了」。故三条必带内容:① 谁取代了它(§1 追记行)② 它自己
|
|
11
|
+
* 从未实施(§1 追记行逐字 `本批无实施记录(§5 未写)`)③ 行的去向(台账重锚事务)。
|
|
12
|
+
*
|
|
13
|
+
* 五条放行合取(每条都能拒):D-1 §1 = `open` ∥ D-2 台账读得出 ∥ D-3 行集**未**全归档 ∥ D-4 §5 空 ∥
|
|
14
|
+
* D-5 取代者解得出在盘落点且不指回本档。
|
|
15
|
+
*
|
|
16
|
+
* 保留门(「从未实施」不是「环节全免」):本批批内单测档门、文档机检门、完成清单预检(`requireAllInFlight=false`
|
|
17
|
+
* 那一支)、设计凭证消费、写序与失败补偿、`[ledger consistency]` 回执行——全部保留,只跳过链门的内容门与
|
|
18
|
+
* `§3` 状态词臂(`assertCloseoutGates({ mode: "supersede" })`)。
|
|
19
|
+
*
|
|
20
|
+
* 依赖单向:`skeleton ← closeout ← ledger-view ← lifecycle ← 本档 ← batch.mjs`(本档 import lifecycle 的四个
|
|
21
|
+
* 出口而不反向——lifecycle 不 import 本档,无环)。
|
|
22
|
+
*/
|
|
23
|
+
import { execFileSync } from "node:child_process"
|
|
24
|
+
import { readFileSync, writeFileSync } from "node:fs"
|
|
25
|
+
import { dirname } from "node:path"
|
|
26
|
+
|
|
27
|
+
import { readBatchStatusLine, sectionContentState, updateSectionStatusLine } from "./batch-skeleton.mjs"
|
|
28
|
+
import { resolveBatchReadPath } from "./batch-paths.mjs"
|
|
29
|
+
import {
|
|
30
|
+
assertCloseoutGates, consistencyReceiptLine, newDebtReasonReceiptLine, readCloseoutSource,
|
|
31
|
+
} from "./batch-closeout.mjs"
|
|
32
|
+
import { archivedStateOf, assertCloseDisposition, consistencyOf } from "./batch-ledger-view.mjs"
|
|
33
|
+
import {
|
|
34
|
+
assertGateOpen, assertMainAgentOnly, consumeBatchDesignTokens, designTokensReceiptLine, ledgerAfterRecordWrite,
|
|
35
|
+
reanchorOnClose,
|
|
36
|
+
} from "./batch-lifecycle.mjs"
|
|
37
|
+
import { appendLineToSection, todayLocal } from "./batch-reopen.mjs"
|
|
38
|
+
import { gateReceiptLine } from "./batch-gate.mjs"
|
|
39
|
+
|
|
40
|
+
// ─── 取代者的语法(§4.18-D「取代者的语法」三形——每形都有机读判据)────────────────────────
|
|
41
|
+
|
|
42
|
+
/** commit 形 = 40 位十六进制(design 逐字「40 位十六进制」)。短 sha 不在闭集里:三形是给出的语法,
|
|
43
|
+
* 不是「看起来像哈希的都算」——解不出的形与没给的形要分别点名(R1 两种拒面)。 */
|
|
44
|
+
const COMMIT_RE = /^[0-9a-f]{40}$/i
|
|
45
|
+
/** 文档 + 节号形:`<文档路径> §<N[.M…]>`(节号 = `§` 后到空白前的数字段)。 */
|
|
46
|
+
const DOC_SECTION_RE = /^(.+?)\s*§\s*(\d+(?:\.\d+)*)$/
|
|
47
|
+
|
|
48
|
+
/** 路径同一性比较(win32 大小写不敏感——与 `batch-paths.mjs` 同口径)。 */
|
|
49
|
+
function samePath(a, b) {
|
|
50
|
+
const norm = (p) => (process.platform === "win32" ? p.toLowerCase() : p)
|
|
51
|
+
return norm(a) === norm(b)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** commit 可达判据(§4.18-D 逐字「`git cat-file -e <sha>`」):判的是**版本库可达**,不是文件在盘。
|
|
55
|
+
* `cwd` = 批档所在目录——版本库从那里上溯,即该批档所属的那个库(不借会话锚猜)。 */
|
|
56
|
+
function commitReachable(sha, nearDir) {
|
|
57
|
+
try {
|
|
58
|
+
execFileSync("git", ["cat-file", "-e", sha], { cwd: nearDir, stdio: "ignore" })
|
|
59
|
+
return true
|
|
60
|
+
} catch { return false }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 节号命中判据(§4.18-D 逐字「节号的数字段(`§` 后到空白前的 `N[.M…]`)在该档命中一个标题行(`^#{1,6}\s`)」):
|
|
64
|
+
* 标题行里须出现该号,且**号的两边都不是数字或点**(`11` 不命中 `11.2` 也不命中 `4.11`;`11.2` 不命中 `11.2.3`)——
|
|
65
|
+
* 左侧那半与右侧同等重要:只卡右边时,`§3` 会命中 `## 13`,机器就替人写了一条并不存在的取代事实。 */
|
|
66
|
+
function headingMatchesNumber(abs, num) {
|
|
67
|
+
let src = ""
|
|
68
|
+
try { src = readFileSync(abs, "utf8") } catch { return false }
|
|
69
|
+
const esc = num.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")
|
|
70
|
+
const re = new RegExp(`(?<![0-9.])(?:§\\s*)?${esc}(?![0-9.])`)
|
|
71
|
+
return src.split(/\r?\n/).some((line) => /^#{1,6}\s/.test(line) && re.test(line))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ─── 五条拒面(语域同 `batch` 族:点名 + 下一步 + `Nothing was written.`)──────────────
|
|
75
|
+
|
|
76
|
+
/** D-5 / R1a:`supersededBy` 空白——机器不代写这条事实(§4.18-D「不存在就拒」)。 */
|
|
77
|
+
const successorMissingError = () => "batch: supersede refused (successor) — `supersededBy` is empty, and this closeout's whole basis is the fact of who replaced the work. The machine never invents it: name a batch record (`docs/batches/<x>.md`), a document plus a section (`docs/<area>/<name>.md §<N>`), or a commit (40 hex). Nothing was written."
|
|
78
|
+
|
|
79
|
+
/** D-5 / R1:形合法而解不到——拒文点名解不到的是哪一段(档案不在盘 ∥ 节号不命中 ∥ commit 不可达)。 */
|
|
80
|
+
const successorUnresolvedError = (piece, raw, hint) => `batch: supersede refused (successor unresolved) — the ${piece} of \`supersededBy\` does not resolve: ${raw}. ${hint} \`supersededBy\` must name a place that already did the same work — "not done yet" cannot be written as a successor (§4.18-D R1). Nothing was written.`
|
|
81
|
+
|
|
82
|
+
/** D-5 / R2:解析回本档自身——续命走重开,不是取代。 */
|
|
83
|
+
const successorSelfError = (raw) => `batch: supersede refused (self) — \`supersededBy\` resolves back to this very record (${raw}): a record cannot be the thing that replaced itself. Keeping it alive is the reopen path (§4.18-B): \`status\` §1 → 进行中 with a note. Nothing was written.`
|
|
84
|
+
|
|
85
|
+
/** D-3 / R3:行集全归档——补关本来就免费覆盖它,指回另一条路。 */
|
|
86
|
+
const allArchivedError = () => "batch: supersede refused (ledger supersede) — every ledger row of this record is already archived (已核销 / 已废弃), so freezing it belongs to the closeout path that already covers it. Use `close` (all-archived records take the repair path, §4.18-C): it freezes the same record without claiming a successor. Nothing was written."
|
|
87
|
+
|
|
88
|
+
/** D-4 / R4:§5 有内容 = 确实实施过——「本批无实施记录」即为假话。 */
|
|
89
|
+
const implementedError = () => "batch: supersede refused (implemented record) — §5 carries content, so this batch was actually implemented: the successor record would have to say 「本批无实施记录(§5 未写)」, which is false on its face. If the work is done, complete the chain and `close` it; if it is unfinished, reopen it (§4.18-B) and return its rows to 待讨论 with a reason. Nothing was written."
|
|
90
|
+
|
|
91
|
+
// ─── 取代者解析(D-5)────────────────────────────────────────────────────────────
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* `supersededBy` → 三形之一 + 逐字原值(落 §1 追记行的那一段)。
|
|
95
|
+
* 批档路径形与文档 + 节号形都走**批档同一解析器**(`resolveBatchReadPath`——不另造解析序);
|
|
96
|
+
* commit 形的判据是版本库可达。三支解不到各自点名(R1),解回本档自身 ⇒ R2。
|
|
97
|
+
* @param {string} cwd — 会话锚(路径解析的候选起点)
|
|
98
|
+
* @param {unknown} raw — 参数原值
|
|
99
|
+
* @param {string} selfAbs — 本批批档绝对路径(R2 的比较对象)
|
|
100
|
+
* @returns {{form:"record"|"document"|"commit", label:string, abs:string|null}}
|
|
101
|
+
*/
|
|
102
|
+
export function resolveSupersededBy(cwd, raw, selfAbs) {
|
|
103
|
+
const text = typeof raw === "string" ? raw.trim() : ""
|
|
104
|
+
if (!text) throw new Error(successorMissingError())
|
|
105
|
+
if (COMMIT_RE.test(text)) {
|
|
106
|
+
if (!commitReachable(text, dirname(selfAbs))) {
|
|
107
|
+
throw new Error(successorUnresolvedError("commit", text, "The version store cannot reach it (`git cat-file -e` refused)."))
|
|
108
|
+
}
|
|
109
|
+
return { form: "commit", label: text, abs: null }
|
|
110
|
+
}
|
|
111
|
+
const docSection = DOC_SECTION_RE.exec(text)
|
|
112
|
+
if (docSection) {
|
|
113
|
+
const docRaw = docSection[1].trim(), num = docSection[2]
|
|
114
|
+
const abs = resolveBatchReadPath(cwd, docRaw)
|
|
115
|
+
if (!abs) throw new Error(successorUnresolvedError("document", docRaw, "No readable file resolves from that path."))
|
|
116
|
+
if (!headingMatchesNumber(abs, num)) {
|
|
117
|
+
throw new Error(successorUnresolvedError("section", `§${num} of ${docRaw}`, "The document is on disk but no heading line carries that number."))
|
|
118
|
+
}
|
|
119
|
+
if (samePath(abs, selfAbs)) throw new Error(successorSelfError(text))
|
|
120
|
+
return { form: "document", label: text, abs }
|
|
121
|
+
}
|
|
122
|
+
const abs = resolveBatchReadPath(cwd, text)
|
|
123
|
+
if (!abs) throw new Error(successorUnresolvedError("path", text, "No readable batch record resolves from that path."))
|
|
124
|
+
if (samePath(abs, selfAbs)) throw new Error(successorSelfError(text))
|
|
125
|
+
return { form: "record", label: text, abs }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ─── 档面两处落笔(§1 追记行 + 回执段)──────────────────────────────────────────────
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* §1 段尾追记行(逐字 = `docs/core/design/BATCH-RECORD.md` §4.18-D「§1 追记行」):
|
|
132
|
+
* 三条必带内容里前两条在这一行上(谁取代了它 ∥ 它自己从未实施),第三条在台账重锚事务里。
|
|
133
|
+
* 载体 = `appendLineToSection`(与补关 / 重开同一条:一次写盘两处落笔、只追加不改写)。
|
|
134
|
+
* 为什么不能只靠瞬时回执:§3 / §4 / §6 空着、状态行又已冻结,不落一行,下一位读者就看不出这个档为何能冻结。
|
|
135
|
+
* @param {string} date — 本地日期(与状态行同一枚)
|
|
136
|
+
* @param {string} successor — `supersededBy` 原值
|
|
137
|
+
* @param {{settled:number, conditioned:number}} counts — 结算行数 / 改挂条件行数(写盘前从同一份读数算出)
|
|
138
|
+
*/
|
|
139
|
+
export const supersedeTraceLine = (date, successor, counts) => `**取代记录**:${date} · 由 ${successor} 取代 · 本批无实施记录(§5 未写)· §3/§4/§6 未补写 · 结算 ${counts.settled} 行 · 改挂条件 ${counts.conditioned} 行 · 操作者 = 主 agent`
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 回执段 `[ledger supersede]`(§4.18-D「回执另出 `[ledger supersede]` 一段,逐行点名结算与改挂」):
|
|
143
|
+
* 结算行沿用收口的两种起点写法(`在途 → 待核销 → 已核销` ∥ ` 待核销 → 已核销`),退回边另起一句——
|
|
144
|
+
* 退回不是结算,报成一笔会把「没做完」写成「做完了」。
|
|
145
|
+
* **两个计数与档面同一源**(`settledCount` / `conditionedCount` 由调用方传写前那份读数):档已冻结、
|
|
146
|
+
* 回执是瞬时面,两者对同一笔收口说不同的数,账就对不上;逐行明细仍取事务回执(那是实际落账的行)。
|
|
147
|
+
* @param {{successor:string, date:string, settled?:Array, retreated?:Array, conditioned?:Array,
|
|
148
|
+
* settledCount?:number, conditionedCount?:number}|null} result
|
|
149
|
+
*/
|
|
150
|
+
export function supersedeReceiptLine(result) {
|
|
151
|
+
if (!result) return ""
|
|
152
|
+
const face = (r) => `#${r.id} 「${r.title}」`
|
|
153
|
+
const settled = result.settled ?? []
|
|
154
|
+
const retreated = result.retreated ?? []
|
|
155
|
+
const conditioned = result.conditioned ?? []
|
|
156
|
+
const lines = [
|
|
157
|
+
`\n[ledger supersede] 被取代收口:由 ${result.successor} 取代 · 结算 ${result.settledCount ?? settled.length} 行 · 改挂条件 ${result.conditionedCount ?? 0} 行 · 本批无实施记录(§5 未写)· §3/§4/§6 未补写 · §1 段尾已追加一行 取代记录(${result.date})`,
|
|
158
|
+
]
|
|
159
|
+
for (const r of settled) {
|
|
160
|
+
lines.push(`\n[ledger supersede] ${face(r)} ${r.from === "在途" ? "在途 → 待核销 → 已核销" : "待核销 → 已核销"}`)
|
|
161
|
+
}
|
|
162
|
+
if (retreated.length) {
|
|
163
|
+
lines.push(`\n[ledger supersede] 未点名的在途行 → 待讨论 + 条件 ${retreated.length} 行:${retreated.map(face).join(";")}` +
|
|
164
|
+
" —— 已清 task_book / executor,续启句已落,由下一批接手")
|
|
165
|
+
}
|
|
166
|
+
if (conditioned.length) {
|
|
167
|
+
lines.push(`\n[ledger supersede] 本批未动行 → 条件 ${conditioned.length} 行:${conditioned.map(face).join(";")}`)
|
|
168
|
+
}
|
|
169
|
+
return lines.join("")
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ─── 动作本体 ───────────────────────────────────────────────────────────────────
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 写盘**之前**从同一份台账读数算出的两格计数(§1 追记行的 `结算 N 行` / `改挂条件 M 行`)。
|
|
176
|
+
* 为什么要预读:写序是「档先写、台账后写」,而追记行随档一起落——台账事务的逐行回执那时还没有。
|
|
177
|
+
* 判据与 `ledgerReanchorBatch` 同一条(`待核销` 恒结清;`在途` 点名的结清、未点名的退回;
|
|
178
|
+
* 等待态里 `条件` / `认账不排期` 不算改挂),不另立一条统计口径。
|
|
179
|
+
*/
|
|
180
|
+
function supersedeCountsOf(rows, completed) {
|
|
181
|
+
const named = new Set(Array.isArray(completed) ? completed : [])
|
|
182
|
+
const settled = rows.filter((r) => r.status === "待核销" || (r.status === "在途" && named.has(Number(r.id)))).length
|
|
183
|
+
const retreated = rows.filter((r) => r.status === "在途" && !named.has(Number(r.id))).length
|
|
184
|
+
const conditioned = rows.filter((r) =>
|
|
185
|
+
(r.status === "待讨论" || r.status === "待设计") && r.trigger !== "条件" && r.trigger !== "认账不排期").length
|
|
186
|
+
return { settled, conditioned: retreated + conditioned }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* `supersede`——被取代的收口(§4.18-D,仅 depth-0,与 `close` 同一身份门)。
|
|
191
|
+
* 判序 = D-1 §1 状态 → D-2/D-3 归档态读数 → D-4 §5 空 → D-5 取代者 → 保留门(单测档门 + 文档机检门)
|
|
192
|
+
* → 完成清单预检(`requireAllInFlight=false`)→ 凭证消费 → 档写盘(状态行 + §1 追记行,一次写盘两处落笔)
|
|
193
|
+
* → 台账重锚事务(未点名的在途行走退回边)→ 台账失败则用写前全文回滚档并抛拒。
|
|
194
|
+
* @param {{args:object, ctx:object, review:boolean, pickTarget:Function, onWritten?:Function}} o
|
|
195
|
+
* @returns {Promise<string>} 成功回执
|
|
196
|
+
*/
|
|
197
|
+
export async function supersedeBatchRecord({ args, ctx, review, pickTarget, onWritten }) {
|
|
198
|
+
assertMainAgentOnly(ctx, "supersede", review) // 与 close 同一身份门(depth-0 only)
|
|
199
|
+
const cwd = ctx?.agent?.cwd
|
|
200
|
+
const abs = pickTarget(args?.path)
|
|
201
|
+
const src = readCloseoutSource(abs)
|
|
202
|
+
// D-1:§1 必须 open。非 open 由既有冻结门早拒(串逐字不变——同一函数,不复制文案)。
|
|
203
|
+
if (readBatchStatusLine(src) !== "open") assertGateOpen(src)
|
|
204
|
+
const completed = args?.completed === undefined ? [] : args.completed
|
|
205
|
+
// D-2 ∥ D-3:归档态读数(读不出 ⇒ 拒,不降级放行);行集全归档 ⇒ 拒并指回 close / 补关。
|
|
206
|
+
const archived = await archivedStateOf(abs, cwd)
|
|
207
|
+
if (archived.allArchived) throw new Error(allArchivedError())
|
|
208
|
+
// D-4:§5 空(有内容 = 确实实施过)
|
|
209
|
+
if (sectionContentState(src, 5) !== "empty") throw new Error(implementedError())
|
|
210
|
+
// D-5:取代者三形(解不到 ⇒ 拒;解析回本档 ⇒ 拒,走重开径)
|
|
211
|
+
const successor = resolveSupersededBy(cwd, args?.supersededBy, abs)
|
|
212
|
+
// 保留门:只跳过链内容门与 §3 状态词臂(本批批内单测档门 ∥ 文档机检门照跑)
|
|
213
|
+
const gate = assertCloseoutGates({ abs, cwd, agent: ctx?.agent ?? {}, src, action: "close", mode: "supersede" })
|
|
214
|
+
// 完成清单预检:本路传 false——未点名的在途行走退回边,故「漏列在途行」那一臂不触发;
|
|
215
|
+
// closeEvidence 这一格不随结算行数放宽(同一判据在三条路上不能两套)。
|
|
216
|
+
await assertCloseDisposition(abs, cwd, completed, args?.closeEvidence, false)
|
|
217
|
+
const designTokens = consumeBatchDesignTokens(ctx?.agent ?? {}, abs)
|
|
218
|
+
const date = todayLocal()
|
|
219
|
+
const counts = supersedeCountsOf(archived.rows, completed)
|
|
220
|
+
// 一次写盘、两处落笔:状态行 → `已收口 <日期>(被取代)`(仍读作 closed——冻结真值的读取器只有一枚),
|
|
221
|
+
// 再加 §1 段尾追记行。§3 / §4 / §6 一个字节不动(本路不补写它们)。
|
|
222
|
+
const statusWritten = updateSectionStatusLine(src, 1, `已收口 ${date}(被取代)`)
|
|
223
|
+
writeFileSync(abs, appendLineToSection(statusWritten, 1, supersedeTraceLine(date, successor.label, counts)))
|
|
224
|
+
// 记账口径同 close 径(记「落过盘」,回档不回退)——见 `batch-lifecycle.mjs` 写盘处的注释。
|
|
225
|
+
if (ctx?.agent) ctx.agent._batchWrites = (ctx.agent._batchWrites ?? 0) + 1 // §6.6 `wrote` 判据(写盘成功才增)
|
|
226
|
+
onWritten?.(ctx?.agent ?? {}, abs)
|
|
227
|
+
// 写序:档先写、台账后写;台账失败 ⇒ 用写前全文回滚档并抛拒(与 close 同一单源)。
|
|
228
|
+
const reanchor = await ledgerAfterRecordWrite({
|
|
229
|
+
side: "close", abs, src, run: () => reanchorOnClose(abs, cwd, completed, args?.closeEvidence, false),
|
|
230
|
+
})
|
|
231
|
+
return `batch: §1 status line → 「已收口 ${date}(被取代)」 — the record is frozen as superseded: append is refused from now on, and status is refused except the reopen conjunction (§4.18-D). 本条未补写 §3 / §4 / §6 — 本批从未实施。${supersedeReceiptLine({ ...reanchor, successor: successor.label, date, settledCount: counts.settled, conditionedCount: counts.conditioned })}${gateReceiptLine(gate)}${designTokensReceiptLine(designTokens)}${newDebtReasonReceiptLine(reanchor)}${consistencyReceiptLine(await consistencyOf(abs, cwd))}`
|
|
232
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-tools/batch-tier-gate.mjs — 收口面的第 ⑤ 臂:**档位臂**(单源叶档)。
|
|
3
|
+
*
|
|
4
|
+
* 权威规格(语义单源)= `docs/core/standards/CODE-TIER.md` §2.2:收口面判的是 **§2 的记录缺件**,分两半,
|
|
5
|
+
* 同一臂里一遍判完、两半的发现拼成一条拒文。读数那一半的判法、三值分流与拒文措辞 =
|
|
6
|
+
* `docs/core/design/DOC-CHECK.md` §8;量法的定义单源 = 同档 §1。位次与跳过集 =
|
|
7
|
+
* `batch-closeout.mjs` 的 `assertCloseoutGates` 第 ⑤ 臂。本档只实现,不重述口径(D2)。
|
|
8
|
+
*
|
|
9
|
+
* 两节,触发物不同,谁都不替谁启动:
|
|
10
|
+
* ① **读数支**(触发物 = 本批改动面里有在盘的码档——几乎每批都有):每个这样的档,§2 机读清单里它那一行的
|
|
11
|
+
* 第三列须带行读数,且 = 该档**在批起快照上**的内容行数(不是收口时盘上的长度:本批实施就是要改它)。
|
|
12
|
+
* 快照里没有这一档 ⇒ 那一格只认 `新`;写数即拒。
|
|
13
|
+
* **读数之前先判表形**:档全文出现块名、清单却解析出零行 ⇒ 一条专门拒文(`tierListUnreadableError`),
|
|
14
|
+
* 不逐档报缺行——「表形不对」与「漏写行」的下一步动作不同(口径 = `docs/core/design/DOC-CHECK.md` §8.4)。
|
|
15
|
+
* ② **越线方案支**(触发物 = 收口时盘上的实测越过收口线):越线档须带正向形分拆方案。
|
|
16
|
+
*
|
|
17
|
+
* **读数支的实质是「与基线一致」,不是「有没有数」**:只查有没有数,写个 1 也能过。
|
|
18
|
+
* **「§2 缺块」仍不是拒因**:块缺时拒的是「每个在盘码档都缺它那一行读数」,不是「格式没写对」。
|
|
19
|
+
* 而「档里有它的名字、清单零行」不是缺行——那是表形不对,另出一条拒文(见 ①)。
|
|
20
|
+
*
|
|
21
|
+
* 入参 `(src, root, changed, baseTextOf)`:`src` = 调用方已读的**写盘前全文**;
|
|
22
|
+
* `root` = 仓根(清单第一列是仓根相对路径);`changed` = 本批改动面——**调用方交的现成两面**
|
|
23
|
+
* (写工具触达账 ∪ 提交 diff,绝对路径);`baseTextOf` = **基线内容取值函数**(收仓根相对路径),
|
|
24
|
+
* 三值三判:串 = 该档在快照里的内容 ∥ `null` = 快照里没有这一档 ∥ `undefined` = 基线不可判(整批一条拒)。
|
|
25
|
+
* **本档不读 git**:基线内容由调用方交进来,缺了按入参缺件拒——判据才保持「一段 §2 文本 + 一个仓根 +
|
|
26
|
+
* 一份改动面 + 一个取值函数」的可直取形,单测不必装一个 git 仓。
|
|
27
|
+
*
|
|
28
|
+
* 依赖:只取段词表叶档的 §2 机读清单解析(`batch-segment-vocab.mjs`——**形单源**,与文档门的计划件判据同一份);
|
|
29
|
+
* 它零 import,无环;本档不 import 任何批次判序档(`batch-closeout.mjs` 单向调本档,本档不回头)。
|
|
30
|
+
*/
|
|
31
|
+
import { readFileSync, statSync } from "node:fs"
|
|
32
|
+
import { isAbsolute, relative, resolve } from "node:path"
|
|
33
|
+
|
|
34
|
+
import { MACHINE_LIST_HEAD_NAME, machineListRowsOf } from "./batch-segment-vocab.mjs"
|
|
35
|
+
|
|
36
|
+
/** 收口线(> 即越线):语义与时点的单源 = `docs/core/standards/CODE-TIER.md` §2.2。 */
|
|
37
|
+
const FILE_CLOSE_MAX = 800
|
|
38
|
+
|
|
39
|
+
/** 内容行数(末行换行不计)——本档是它唯一的消费面,量法随消费面走。 */
|
|
40
|
+
export function countContentLines(text) {
|
|
41
|
+
const parts = String(text).split("\n")
|
|
42
|
+
if (parts.length && parts[parts.length - 1] === "") parts.pop()
|
|
43
|
+
return parts.length
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 源码 / 单测档后缀闭集。 */
|
|
47
|
+
const CODE_EXTS = Object.freeze([".mjs", ".cjs", ".js"])
|
|
48
|
+
|
|
49
|
+
/** 读数格的值形之一:纯十进制整数(剥装饰符与首尾空白后)。 */
|
|
50
|
+
const READING_NUM_RE = /^\d+$/
|
|
51
|
+
|
|
52
|
+
/** 读数格的另一个值形:快照里没有这一档。写 0 会被读成「量过、是空的」;写别的数就是编。 */
|
|
53
|
+
const NEW_TOKEN = "新"
|
|
54
|
+
|
|
55
|
+
/** 正向形 ①:目标档 token 须**带目录段**(至少一个 `/`)与档后缀——只点名一个光秃名字不算点名目标。 */
|
|
56
|
+
const TARGET_TOKEN_RE = /[A-Za-z0-9_.@-]+\/[A-Za-z0-9_.@/-]*\.[A-Za-z0-9]{1,8}/
|
|
57
|
+
|
|
58
|
+
/** 正向形 ②:本批落步词闭集——方案须说出本批哪一步把它落成。闭集住本档(判据面),文档面不复述。 */
|
|
59
|
+
const STEP_WORDS = Object.freeze(["实施轮", "§5"])
|
|
60
|
+
|
|
61
|
+
/** 路径归一(比较用:win32 大小写不敏感,分隔符统一成 `/`)——改动面是绝对路径、清单第一列是仓根相对路径,
|
|
62
|
+
* 两边的基不同,只能靠「路径段对齐的尾巴」认同一档。 */
|
|
63
|
+
const normPath = (p) => {
|
|
64
|
+
const s = String(p ?? "").replace(/\\/g, "/")
|
|
65
|
+
return process.platform === "win32" ? s.toLowerCase() : s
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** 该路径是不是源码 / 单测档(后缀闭集单源 = `CODE_EXTS`)。 */
|
|
69
|
+
const isCodePath = (p) => typeof p === "string" && CODE_EXTS.some((e) => p.toLowerCase().endsWith(e))
|
|
70
|
+
|
|
71
|
+
/** 格内文本(去首尾空白与 markdown 装饰符——写手会写成 `` `x` `` ∥ `**x**`)。 */
|
|
72
|
+
const cellText = (s) => String(s ?? "").replace(/[`*]/g, "").trim()
|
|
73
|
+
|
|
74
|
+
/** 拒文公共两件(下一步 ∥ 零写声明):本门只拒、不代改。 */
|
|
75
|
+
const TIER_PLAN_DISPOSAL =
|
|
76
|
+
"要写什么:在本批 §2 的「受影响文件(机读清单)」为每个越线档补一行——第二列写正向形方案" +
|
|
77
|
+
"(点名目标档,带目录段;并写出本批落步 `实施轮` ∥ `§5`);未越线的档不受此约束。本门只拒、不代改。Nothing was written."
|
|
78
|
+
|
|
79
|
+
/** 读数那一半的「要写什么」(据 `docs/core/design/DOC-CHECK.md` §8 拒文块**改写**:设计档写「本档 §1」∥
|
|
80
|
+
* 「本节「快照怎么取」」,而运行时串里没有「本档 ∥ 本节」可指,所以把两个家的路径写全;逐档发现句 ∥ 首句 ∥
|
|
81
|
+
* `Nothing was written.` 三处与设计档同字面)。 */
|
|
82
|
+
const TIER_READING_DISPOSAL =
|
|
83
|
+
"要写什么:在 §2「受影响文件(机读清单)」的第三列写该档的原始行数——量法 = `countContentLines`" +
|
|
84
|
+
"(定义单源 = `docs/core/design/DOC-CHECK.md` §1);取数 = 该档在**批起快照**上的内容" +
|
|
85
|
+
"(快照怎么取 = 同档 §8);快照里没有这一档就写 `新`。只报这一个数:不写增量 ∥ 百分比 ∥ 超了多少行。" +
|
|
86
|
+
"本门只拒、不代改。Nothing was written."
|
|
87
|
+
|
|
88
|
+
/** 拒文(门自身入参缺件):改动面与基线取值都是判据的输入,缺省由调用方决定,不由本档猜。 */
|
|
89
|
+
function tierInputMissingError(what) {
|
|
90
|
+
return "batch: tier-plan gate is missing its input(收口前置门 · tier-plan gate)— close refuses: " +
|
|
91
|
+
`${what}. 触发物是本批改动面的实测长度、比对基准是批起快照——不知道改了哪几档、基线是什么,就没有可判的东西;` +
|
|
92
|
+
"猜一个等于替调用方决定。Nothing was written."
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 逐档读数那一半的节首句(`tier-reading gate` 是 A1 ∥ A7 认的那一句)。 */
|
|
96
|
+
function tierReadingHeader() {
|
|
97
|
+
return "batch: 码档缺原始行数 ∥ 读数与基线不符(收口前置门 · tier-reading gate)— close refuses: " +
|
|
98
|
+
"a code file this batch changed carries no usable line reading in §2's 受影响文件(机读清单)" +
|
|
99
|
+
"(判的是记录缺件,不是代码长短):"
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 越线方案那一半的节首句(`tier-plan gate` 是 A2 认的那一句)。 */
|
|
103
|
+
function tierPlanHeader() {
|
|
104
|
+
return "batch: 越了收口线却没有分拆方案(收口前置门 · tier-plan gate)— close refuses: a source/test file this batch changed " +
|
|
105
|
+
`crosses the closeout line (> ${FILE_CLOSE_MAX}) and §2 carries no usable split plan for it(判的是记录缺件:§2 有没有可用方案):`
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** 拒文(基线不可判):它不是逐档读数的问题,是整批的比对基准缺件——整批一条,不逐档点名。 */
|
|
109
|
+
function tierBaselineError() {
|
|
110
|
+
return "batch: 批起基线不可判(收口前置门 · tier-reading gate)— close refuses: " +
|
|
111
|
+
"§1 has no usable `批起 sha`(缺记入行 ∥ 该对象读不到),读数的比对基准不存在,这一半无从核起:\n" +
|
|
112
|
+
"要写什么:在 §1 记入行写 `批起 sha = <批起快照 sha>`(快照怎么取 = `docs/core/design/DOC-CHECK.md` §8)。" +
|
|
113
|
+
"本门只拒、不代改。Nothing was written."
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 一条拒文装两节(KD-5):两节各带自己的「要写什么」,设计席一次改完再收口。 */
|
|
117
|
+
function tierRefusalError(readingFindings, planFindings) {
|
|
118
|
+
const blocks = []
|
|
119
|
+
if (readingFindings.length) blocks.push([tierReadingHeader(), ...readingFindings, TIER_READING_DISPOSAL].join("\n"))
|
|
120
|
+
if (planFindings.length) {
|
|
121
|
+
blocks.push([tierPlanHeader(), ...planFindings, TIER_PLAN_DISPOSAL].join("\n"))
|
|
122
|
+
}
|
|
123
|
+
return blocks.join("\n")
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 正向形判据(纯函数):`null` = 满足 ∥ 一句说缺什么。
|
|
128
|
+
* 正向形 = **两件同时在场的合取**,不是词表:① 点名一个带目录段的档 token;② 说出本批哪一步落成
|
|
129
|
+
* (`实施轮` ∥ `§5`)。缺一即视同未填——「另起一批」「留到下批」「下批拆」点名不了目标,全不命中;
|
|
130
|
+
* 点名了目标却把落地推给下一批的,不命中落步词,同样不命中。黑名单挡不住下一种说法,正向形挡得住
|
|
131
|
+
* 还没进词表的那一种。**它只在「确实越线」之后才被查**,不是每次收口都查。
|
|
132
|
+
*/
|
|
133
|
+
function planGapOf(plan) {
|
|
134
|
+
const cell = cellText(plan)
|
|
135
|
+
if (cell === "" || /^[—–-]+$/.test(cell)) return "方案为空 ∥ 只有 `—`"
|
|
136
|
+
if (!TARGET_TOKEN_RE.test(cell)) return "方案不满足正向形:缺目标档 token(要点名一个带目录段的档路径)"
|
|
137
|
+
if (!STEP_WORDS.some((w) => cell.includes(w))) return "方案不满足正向形:缺本批落步(`实施轮` ∥ `§5`)"
|
|
138
|
+
return null
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 该档在 §2 清单里的那一行(按「路径段对齐的尾巴」认,最长者胜):改动面是绝对路径、清单第一列是
|
|
143
|
+
* 仓根相对路径,两边基不同;`null` = 清单里没有它。
|
|
144
|
+
*/
|
|
145
|
+
function rowFor(absPath, rows) {
|
|
146
|
+
const target = normPath(absPath)
|
|
147
|
+
let best = null
|
|
148
|
+
for (const row of rows) {
|
|
149
|
+
const key = normPath(row.path)
|
|
150
|
+
if (key === "") continue
|
|
151
|
+
if (target !== key && !target.endsWith(`/${key}`) && !key.endsWith(`/${target}`)) continue
|
|
152
|
+
if (best === null || key.length > normPath(best.path).length) best = row
|
|
153
|
+
}
|
|
154
|
+
return best
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** 拒文里的档名(**仓根相对**——那正是写手要填进 §2 清单那格的值;盘到仓外就照原值点名,不猜)。 */
|
|
158
|
+
function displayPath(p, root) {
|
|
159
|
+
const abs = isAbsolute(p) ? p : resolve(root, p)
|
|
160
|
+
const rel = relative(root, abs).replace(/\\/g, "/")
|
|
161
|
+
return rel === "" || rel.startsWith("../") || isAbsolute(rel) ? p : rel
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 逐档实测内容行数(**读数尺 = `countContentLines`**,收口面自己量——不采信任何抄来的数)。
|
|
166
|
+
* 量不到 ⇒ `null`:本批删掉 / 搬走的档在盘上没有长度可量,跳过(不是「干净的档」,是**没有这一档**)。
|
|
167
|
+
* @param {string} changedPath — 改动面条目(绝对路径 ∥ 仓根相对路径)
|
|
168
|
+
* @param {string} root — 仓根
|
|
169
|
+
* @returns {number|null} 内容行数 ∥ `null`(不在盘 ⇒ 无长度)
|
|
170
|
+
*/
|
|
171
|
+
function contentLinesOf(changedPath, root) {
|
|
172
|
+
const abs = isAbsolute(changedPath) ? changedPath : resolve(root, changedPath)
|
|
173
|
+
try {
|
|
174
|
+
if (!statSync(abs).isFile()) return null
|
|
175
|
+
return countContentLines(readFileSync(abs, "utf8"))
|
|
176
|
+
} catch {
|
|
177
|
+
return null
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 判域 = 本批改动面里**在盘**的码档(同一档去重后只量一次——触达账与提交清单会重叠)。
|
|
183
|
+
* @returns {{abs:string, len:number}[]} 绝对路径 + 盘上内容行数(`len` 只喂越线方案支;读数支按快照比)
|
|
184
|
+
*/
|
|
185
|
+
function codeFilesOf(changed, root) {
|
|
186
|
+
const out = []
|
|
187
|
+
const seen = new Set()
|
|
188
|
+
for (const p of changed) {
|
|
189
|
+
if (!isCodePath(p)) continue
|
|
190
|
+
const abs = isAbsolute(p) ? p : resolve(root, p)
|
|
191
|
+
const key = normPath(abs)
|
|
192
|
+
if (seen.has(key)) continue
|
|
193
|
+
seen.add(key)
|
|
194
|
+
const len = contentLinesOf(abs, root)
|
|
195
|
+
if (len === null) continue // 本批删掉 / 搬走的档:盘上没有长度可量,也不进判域(判域 = 在盘的码档)
|
|
196
|
+
out.push({ abs, len })
|
|
197
|
+
}
|
|
198
|
+
return out
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** 一个码档那一格缺什么:`null` = 读数成立 ∥ 一句「哪一格不对、写的是什么、基线是什么」。 */
|
|
202
|
+
function readingGapOf(row, baseLines) {
|
|
203
|
+
const cell = cellText(row?.reading)
|
|
204
|
+
if (baseLines === null) {
|
|
205
|
+
if (cell === NEW_TOKEN) return null
|
|
206
|
+
if (READING_NUM_RE.test(cell)) return `写的是 ${Number(cell)},而批起快照里没有这一档;本批期间建的档写 \`新\``
|
|
207
|
+
return "该列没有数(空 ∥ `—`);批起快照里也没有这一档,该格写 `新`"
|
|
208
|
+
}
|
|
209
|
+
if (cell === NEW_TOKEN) return `写的是 \`新\`,而批起快照里这一档有 ${baseLines} 行`
|
|
210
|
+
if (!READING_NUM_RE.test(cell)) return `该列没有数(空 ∥ \`—\`);基线是 ${baseLines}`
|
|
211
|
+
const n = Number(cell)
|
|
212
|
+
return n === baseLines ? null : `写的是 ${n},基线是 ${baseLines}`
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 读数支(在盘的每个码档逐档核):三值分流全部在这里,`undefined` ⇒ 抛整批一条「批起基线不可判」
|
|
217
|
+
* (放行等于没核,静默退回头更坏)。
|
|
218
|
+
* @returns {string[]} 逐档发现(空 = 这一半成立)
|
|
219
|
+
*/
|
|
220
|
+
function readingFindingsOf(files, rows, root, baseTextOf) {
|
|
221
|
+
const findings = []
|
|
222
|
+
for (const f of files) {
|
|
223
|
+
const rel = displayPath(f.abs, root)
|
|
224
|
+
const base = baseTextOf(rel)
|
|
225
|
+
if (base === undefined || (base !== null && typeof base !== "string")) throw new Error(tierBaselineError())
|
|
226
|
+
const baseLines = base === null ? null : countContentLines(base)
|
|
227
|
+
const row = rowFor(f.abs, rows)
|
|
228
|
+
const gap = row === null
|
|
229
|
+
? baseLines === null
|
|
230
|
+
? "§2 清单里没有这一档的行;批起快照里也没有这一档,该格写 `新`"
|
|
231
|
+
: `§2 清单里没有这一档的行;基线是 ${baseLines}`
|
|
232
|
+
: readingGapOf(row, baseLines)
|
|
233
|
+
if (gap === null) continue
|
|
234
|
+
findings.push(` ${rel} — ${gap}`)
|
|
235
|
+
}
|
|
236
|
+
return findings
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** 拒文(清单读不出行):档里明明写着块名,解析面却一行都没有——那是表形不对,不是漏写行。
|
|
240
|
+
* 形单源 = `docs/core/design/DOC-CHECK.md` §8.4;块名取解析器那一份字面(`MACHINE_LIST_HEAD_NAME`)。 */
|
|
241
|
+
function tierListUnreadableError(files, root) {
|
|
242
|
+
// 逐个一行、与逐档发现同形(` <仓根相对> — <gap>`):这一份的 gap 对每档相同——清单读不出行,就没有它的行可读
|
|
243
|
+
const list = files.map((f) => ` ${displayPath(f.abs, root)} — 清单读不出行,无行可读`).join("\n")
|
|
244
|
+
return "batch: §2 的机读清单读不出行(收口前置门 · tier-reading gate)— close refuses: " +
|
|
245
|
+
"the batch record carries the block name in its text, yet §2's machine-readable list parses to zero rows — " +
|
|
246
|
+
`档里有它的名字,清单却解析出零行,本批每个在盘码档就没有行可读:` +
|
|
247
|
+
`\n${list}\n` +
|
|
248
|
+
"为什么零行(三者任一不满足都读不出):① 块头形态不在两种之内——可接受的两形 = 行首粗体 " +
|
|
249
|
+
"`**受影响文件(机读清单)**`,或同名标题行(`#{1,6}` 起头、标题文字以这个名字结尾,如 " +
|
|
250
|
+
"`### 受影响文件(机读清单)` ∥ `### 3. 受影响文件(机读清单)`);" +
|
|
251
|
+
"`### 受影响文件(机读清单)的写法` 这类「在提它」的标题不在两形之内。" +
|
|
252
|
+
"② 表不在 2–3 列(4 格以上的行跳过)。" +
|
|
253
|
+
"③ 表行不连续——中间夹一个空行即截断,其后的行读不到;只剩表头行或全是 `<…>` 占位行同样是零行。" +
|
|
254
|
+
"要写什么:把块头改成两形之一,其下紧跟一张连续的 2–3 列表(`| 档 | 分拆方案 | 行数 |`),一行一档。" +
|
|
255
|
+
"本门只拒、不代改。Nothing was written."
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* 收口前置门(第 ⑤ 臂 · 档位臂):**两节一趟判完,一条拒文**。
|
|
260
|
+
* 判序:读数支在前(缺数是更前一件缺件),越线方案支在后;两节的触发物不同,各自启动。
|
|
261
|
+
* 放行零回执(与其余收口前置同形:不写回执段、不改回执字面)。
|
|
262
|
+
* @param {string} src — 写盘前的档全文
|
|
263
|
+
* @param {string} root — 仓根(**必填**:清单第一列与改动面条目都按它落盘,缺省由调用方决定而不是本档猜)
|
|
264
|
+
* @param {string[]} changed — 本批改动面(触达账 ∪ 提交 diff;**必填**——它就是触发物的取材)
|
|
265
|
+
* @param {(relPath:string) => string|null|undefined} baseTextOf — 基线内容取值函数(**必填**:串 ∥ `null` ∥ `undefined`)
|
|
266
|
+
* @throws 入参缺件 ∥ 基线不可判 ∥ 读数缺件 ∥ 越线而缺方案
|
|
267
|
+
*/
|
|
268
|
+
export function assertTierPlan(src, root, changed, baseTextOf) {
|
|
269
|
+
if (typeof root !== "string" || root.trim() === "") {
|
|
270
|
+
throw new Error(tierInputMissingError("the repo root was not given — the affected-file list's first column is repo-root-relative, and a guessed base measures the wrong files"))
|
|
271
|
+
}
|
|
272
|
+
if (!Array.isArray(changed)) {
|
|
273
|
+
throw new Error(tierInputMissingError("the changed-file list was not given — the trigger is the measured length of this batch's own changed files, so the gate cannot guess it"))
|
|
274
|
+
}
|
|
275
|
+
if (typeof baseTextOf !== "function") {
|
|
276
|
+
throw new Error(tierInputMissingError("the baseline reader (`baseTextOf`) was not given as a function — the reading column is compared against each file's content in the batch-start snapshot, and this gate does not read git itself; a guessed baseline measures the wrong thing"))
|
|
277
|
+
}
|
|
278
|
+
const files = codeFilesOf(changed, root)
|
|
279
|
+
// ① 读数支:没有在盘码档 ⇒ 这一半不启动(连 §2 都不解析)。
|
|
280
|
+
const rows = files.length ? machineListRowsOf(src) : []
|
|
281
|
+
// ①-前 表形自诊断:先判表形再判读数——整份读不出行时,每一条逐档比对都只是同一个原因的回声。
|
|
282
|
+
// 三条件全从既有入参算得(码档非空 ∥ 清单零行 ∥ 档全文出现块名),不新增参数、不设开关。
|
|
283
|
+
if (files.length && rows.length === 0 && String(src ?? "").includes(MACHINE_LIST_HEAD_NAME)) {
|
|
284
|
+
throw new Error(tierListUnreadableError(files, root))
|
|
285
|
+
}
|
|
286
|
+
const readingFindings = files.length ? readingFindingsOf(files, rows, root, baseTextOf) : []
|
|
287
|
+
// ② 越线方案支:只在收口时的实测越过收口线时才查(`§2 缺块本身不是拒因` 照旧成立)。
|
|
288
|
+
const planFindings = []
|
|
289
|
+
for (const f of files) {
|
|
290
|
+
if (f.len <= FILE_CLOSE_MAX) continue
|
|
291
|
+
const row = rowFor(f.abs, rows)
|
|
292
|
+
const gap = row === null ? "§2 清单里没有这一档的方案行" : planGapOf(row.plan)
|
|
293
|
+
if (gap === null) continue
|
|
294
|
+
planFindings.push(` ${displayPath(f.abs, root)} — ${f.len} > ${FILE_CLOSE_MAX};${gap}`)
|
|
295
|
+
}
|
|
296
|
+
if (readingFindings.length || planFindings.length) throw new Error(tierRefusalError(readingFindings, planFindings))
|
|
297
|
+
}
|