@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,112 +1,101 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* agent-tools/batch-lifecycle.mjs — 批次档生命周期 action 面(KD-4
|
|
2
|
+
* agent-tools/batch-lifecycle.mjs — 批次档生命周期 action 面(KD-4 拆分中段;2026-10-27 第二次拆分)。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* ← 主档**,主档把解析后的 cwd/bases/目标闭包传进来,本档不回 import 主档(防环)。
|
|
4
|
+
* 本档只留 **status / close 两条 action 与在飞批定位**。四条支线住各自的新档(依赖单向:
|
|
5
|
+
* `skeleton ← closeout ← ledger-view ← bind ← reopen ← lifecycle`):
|
|
6
|
+
* - 建档 = 建台账行 → `batch-ledger-bind.mjs`(§2.4);
|
|
7
|
+
* - 收口判据与重锚回执 → `batch-closeout.mjs`;
|
|
8
|
+
* - 台账侧只读视图(一致性读数 ¶ 收口预检 ¶ 补关分流)→ `batch-ledger-view.mjs`(P2-5 拆出);
|
|
9
|
+
* - 重开写盘 + 台账回收 → `batch-reopen.mjs`(§2.13)。
|
|
11
10
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* 工程 §1 ∥ 普通 §1/§2/§5【取段——§4.16】——§4/§6 状态面走普通文档写);depth-0 的 status/path 面
|
|
17
|
-
* 按 D-BR21(可选 path,缺省 = 在飞批唯一时取)。
|
|
18
|
-
*
|
|
19
|
-
* 文档机检门(§3.20「结构兜底」②):`close` 与 `status` 值余核「已收口」两路写盘前跑
|
|
20
|
-
* `runBatchGate({ scope: "close" })`——`REFUSED`(K ≥ 1)∥ `ERROR` ⇒ throw(§1 状态行字节不变);
|
|
21
|
-
* `PASS` / 未跑(无声明面)⇒ 落盘 + 回执明示。门单源住 `batch-gate.mjs`(判据零改)。
|
|
22
|
-
*
|
|
23
|
-
* 链完整性门(§4.18-A):`close` ∥ `status` 写「已收口」两路在写盘前同过 `assertCloseoutChainComplete`
|
|
24
|
-
* ——§2/§3/§4/§6 各段有内容 ∥ §1 声明不适用(仅 §2/§3/§4 可声明;§6 不可声明 · §5 段号豁免);
|
|
25
|
-
* 缺段 ⇒ 点名拒(门位 = 冻结拒写之后、文档机检门之前)。
|
|
11
|
+
* 判定字面全部单源自 batch-skeleton.mjs(SEGMENT_BY_ROLE / STATUS_WORDS /
|
|
12
|
+
* readBatchStatusLine / sectionHasStatusLine / updateSectionStatusLine / batchSkeleton / TEMPLATE_PLACEHOLDERS /
|
|
13
|
+
* findPlaceholderResidue / placeholderResidueError);路径解析单源(`resolveBatchDocPath` / `batchDocBases` /
|
|
14
|
+
* `resolveBatchCreatePath`——住 `batch-paths.mjs`)与 #84 记账缝住 batch.mjs 主档——本档不回 import 主档(防环)。
|
|
26
15
|
*
|
|
27
|
-
*
|
|
28
|
-
* `
|
|
29
|
-
* `
|
|
16
|
+
* 身份判据(D-BR17/D-BR18/D-BR21):主 agent 的工具调用 ctx 带 `depth === 0`(dispatch 装配);
|
|
17
|
+
* eng 子代理 `ctx.depth > 0`;评审实例 ctx 无 depth 但工具以 `review: true` 绑定(`reviewTrack` = 评审轨——
|
|
18
|
+
* 工程**设计轨**的 `§3` 只由结算写、本面拒,§4.4)。create/close
|
|
19
|
+
* 仅 depth-0 放行(BR-19/BR-24);status 写域 = 调用者自己段(eng-designer → §2 · 评审 → §3 ·
|
|
20
|
+
* eng-coder → §5 · coder → §5【普通模式分支增表】· 主 agent → 工程 §1 ∥ 普通 §1/§2/§5【取段——§4.16】)。
|
|
30
21
|
*
|
|
31
|
-
*
|
|
32
|
-
* `
|
|
22
|
+
* 四道门(2026-10-27 · 设计档 §2.6):写锁 = `agent/write-gate.mjs`(不在本档);§5 写入门 =
|
|
23
|
+
* `batch.mjs` append 面;**收口门** = `batch-closeout.mjs`(链门 + §3 状态词臂 + 单测档门 + 机检门);
|
|
24
|
+
* 核销工作证据门 = `ledger-close-proof.mjs`(只判应用本笔后的 evidence 非空白)。
|
|
33
25
|
*
|
|
34
26
|
* 收口重锚(§6.2 · C · AC-M2-30):收口有两条通路——`close` ∥ `status` 写 §1「已收口」——两路都冻结档、
|
|
35
27
|
* 都让批「收口了」,故**两路同调**单源 `reanchorOnClose`(本档下方),调点均在状态行写盘之后。
|
|
36
28
|
* 一次收口只出一份 `[ledger reanchor]` 回执段(判据 = 前态未冻结:已冻结档在两路都被冻结门早拒)。
|
|
29
|
+
* **写序与补偿**(设计档 `docs/core/design/BATCH-LEDGER-REVIEW-UNIFY.md` §2.17):只读预检 → 档写盘 →
|
|
30
|
+
* 台账单事务 →(台账失败 ⇒ 用**写前全文**回滚档 + 抛拒)。两路都过 `ledgerAfterRecordWrite`,失败不静默;
|
|
31
|
+
* 回滚本身也失败时出第二条串(点名半状态与 `batch({action:"check"})`)。
|
|
32
|
+
*
|
|
33
|
+
* **全归档补关**(§4.18-C · `docs/core/design/LEDGER.md` §11.2):两路在链门前读 `batchLedgerConsistency`——
|
|
34
|
+
* 行集非空、每行均已归档、且 `halfStates` 恰为唯一 `open-but-settled` ⇒ 补关(只跳过链内容门与 §3 pass 臂,
|
|
35
|
+
* 不补写 §3/§4/§6);补关成功在 §1 段尾追加一行 `**补关记录**`、回执另出 `[ledger repair]`,台账行零改写。
|
|
36
|
+
*
|
|
37
|
+
* 重开回收(§2.13 · E13):`status` 写 §1 `进行中` 而前态 `closed` ⇒ 重开;写盘后同调 `reclaimOnReopen`
|
|
38
|
+
* (`待核销 → 在途`),失败同样回滚档 + 抛拒(「档已开、行仍 待核销」会让写锁拒每一笔写盘)。
|
|
39
|
+
* **其余 status 用法零台账写**——尤其「§3 写评审通过」不动台账。
|
|
40
|
+
* 两路回执末尾**恒带一行** `[ledger consistency]`(半状态查询面单源 = `batchLedgerConsistency`);
|
|
41
|
+
* `check` action 是同一读数的完整打印面。
|
|
37
42
|
*
|
|
38
43
|
* 收口自动消费本批设计凭证(DESIGN-TOKEN-SETTLEMENT §10 · 2026-10-26):同一两路在**写状态行之前**
|
|
39
44
|
* 调 `consumeBatchDesignTokens`(判据 = 槽的批次归属旁列;口径单源见该档 §10)。消费失败 ⇒ 原样上抛、
|
|
40
45
|
* close 被拒、档零字节变——位次与重锚(写盘之后)相反,这是机制本体(KD-BG3)。
|
|
41
46
|
*/
|
|
42
|
-
import { existsSync,
|
|
47
|
+
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "node:fs"
|
|
43
48
|
import { dirname, relative, resolve } from "node:path"
|
|
44
49
|
|
|
45
50
|
import {
|
|
46
|
-
SEGMENT_BY_ROLE, SEGMENT_BY_ROLE_NORMAL,
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
DEPTH0_SEGMENTS, SEGMENT_BY_ROLE, SEGMENT_BY_ROLE_NORMAL, STATUS_WORDS, TEMPLATE_PLACEHOLDERS,
|
|
52
|
+
findPlaceholderResidue, placeholderResidueError, readBatchStatusLine, reviewWritableSegment, sectionHasStatusLine,
|
|
53
|
+
sectionThreeDesignTrackError, updateSectionStatusLine, zoneStatusCount,
|
|
49
54
|
} from "./batch-skeleton.mjs"
|
|
50
|
-
import {
|
|
51
|
-
import {
|
|
52
|
-
import {
|
|
55
|
+
import { assertCloseoutGates, changedSurfaceReceiptLine, checkReceipt, closeHalfStateError, closeLedgerFailedError, consistencyReceiptLine, newDebtReasonOf, newDebtReasonReceiptLine, readCloseoutSource, reanchorReceiptLine, repairReceiptLine, repairTraceLine } from "./batch-closeout.mjs"
|
|
56
|
+
import { assertCloseDisposition, consistencyOf, repairDecisionOf } from "./batch-ledger-view.mjs"
|
|
57
|
+
import { appendLineToSection, assertSingleLineNote, reclaimOnReopen, reopenHalfStateError, reopenLedgerFailedError, reopenReasonError, reopenReceiptLine, rewriteAsReopen, todayLocal } from "./batch-reopen.mjs"
|
|
58
|
+
import { gateReceiptLine } from "./batch-gate.mjs"
|
|
53
59
|
import { batchPathKey, executeConsumeDesignAction, unionBatches, unionSlots } from "./design-slots.mjs"
|
|
54
60
|
|
|
55
|
-
/** 可读文件判据(存在且为文件——目录/缺失同判不可读;与主档同名 helper 同型——KD-4
|
|
56
|
-
*
|
|
61
|
+
/** 可读文件判据(存在且为文件——目录/缺失同判不可读;与主档同名 helper 同型——KD-4 单向依赖下各自持有,
|
|
62
|
+
* 三行谓词不构成第二权威源)。 */
|
|
57
63
|
function readableFile(abs) {
|
|
58
64
|
try { return existsSync(abs) && statSync(abs).isFile() } catch { return false }
|
|
59
65
|
}
|
|
60
66
|
|
|
61
|
-
/** 本地今天(YYYY-MM-DD)——close 收口日期戳。 */
|
|
62
|
-
function todayLocal() {
|
|
63
|
-
const d = new Date()
|
|
64
|
-
const p = (n) => String(n).padStart(2, "0")
|
|
65
|
-
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`
|
|
66
|
-
}
|
|
67
|
-
|
|
68
67
|
/** depth-0 身份判据。 */
|
|
69
68
|
function isDepthZero(ctx) {
|
|
70
69
|
return ctx?.depth === 0
|
|
71
70
|
}
|
|
72
71
|
|
|
73
|
-
/** 段号解析(`§2` / `2` / `§2 批次任务` 均可;无法解析 → null——与主档 append
|
|
74
|
-
* 谓词,KD-4 单向依赖下各自持有,不构成第二权威源)。 */
|
|
72
|
+
/** 段号解析(`§2` / `2` / `§2 批次任务` 均可;无法解析 → null——与主档 append 面同型三行谓词)。 */
|
|
75
73
|
function segmentNumber(raw) {
|
|
76
74
|
const m = /^§?\s*(\d+)/.exec(String(raw ?? "").trim())
|
|
77
75
|
return m ? Number(m[1]) : null
|
|
78
76
|
}
|
|
79
77
|
|
|
80
|
-
/**
|
|
81
|
-
*
|
|
82
|
-
|
|
83
|
-
function normalizeHeaderParam(name, raw) {
|
|
84
|
-
const v = typeof raw === "string" ? raw.trim() : ""
|
|
85
|
-
if (!v) return null
|
|
86
|
-
if (/\r?\n/.test(v)) {
|
|
87
|
-
throw new Error("batch: create ledger / board must be single lines — a multi-line value would break the header's 台账 line. Nothing was written.")
|
|
88
|
-
}
|
|
89
|
-
return name === "ledger" && !v.startsWith("#") ? `#${v}` : v
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** main-agent-only 门(BR-19/BR-24):create/close 仅 depth-0 放行(eng 子代理 / 评审皆拒)。 */
|
|
93
|
-
function assertMainAgentOnly(ctx, action, review) {
|
|
78
|
+
/** main-agent-only 门(BR-19/BR-24):close / supersede 仅 depth-0 放行(eng 子代理 / 评审皆拒)。
|
|
79
|
+
* 导出面 = `batch-supersede.mjs`(第三条收口边同一身份门——同一条判据只有这一个函数)。 */
|
|
80
|
+
export function assertMainAgentOnly(ctx, action, review) {
|
|
94
81
|
if (review || !isDepthZero(ctx)) {
|
|
95
82
|
throw new Error(`batch: ${action} is main-agent-only — ${action} manages the record lifecycle and is depth-0 only (eng sub-agents and design reviews are refused).`)
|
|
96
83
|
}
|
|
97
84
|
}
|
|
98
85
|
|
|
99
|
-
/** 递归收集目录下全部 `*.md`(#369 · KD-4:显式嵌套路径为合法 create 面 ⇒ 顶层平扫会欠计
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* `
|
|
86
|
+
/** 递归收集目录下全部 `*.md`(#369 · KD-4:显式嵌套路径为合法 create 面 ⇒ 顶层平扫会欠计 ⇒ 复数情形
|
|
87
|
+
* 漏判、默认定位可落非预期档)。只认真目录(symlink 不入,防环);单目录读错按无候选处理(尽力面)。
|
|
88
|
+
* **转导出**(read-data-interface 批——`batch/list` 读面文件集同源复用;零行为变)。
|
|
89
|
+
* **只收批档**(`*.md` 且不以点开头——两条判):其它扩展名(与批档同目录并存的同名单测档 `<批档名>.test.mjs`)
|
|
90
|
+
* 与隐藏档都不是批档;只有「点开头」一条挡不住那份测档,挡住它的是扩展名那一条(`docs/core/design/DOC-CHECK.md` §2.10.2)。
|
|
91
|
+
* **不为任何残档设支**:盘上没有片段档这回事——两条判据描述的是「什么算批档」,不是「谁要排掉」。 */
|
|
103
92
|
export function collectMarkdownFiles(dir, out = []) {
|
|
104
93
|
let entries = []
|
|
105
94
|
try { entries = readdirSync(dir, { withFileTypes: true }) } catch { return out }
|
|
106
95
|
for (const e of entries) {
|
|
107
96
|
const abs = resolve(dir, e.name)
|
|
108
97
|
if (e.isDirectory()) collectMarkdownFiles(abs, out)
|
|
109
|
-
else if (e.isFile() && e.name.endsWith(".md")) out.push(abs)
|
|
98
|
+
else if (e.isFile() && e.name.endsWith(".md") && !e.name.startsWith(".")) out.push(abs)
|
|
110
99
|
}
|
|
111
100
|
return out
|
|
112
101
|
}
|
|
@@ -115,7 +104,8 @@ export function collectMarkdownFiles(dir, out = []) {
|
|
|
115
104
|
* depth-0 目标定位(D-BR21):扫描全部基底根下 `*.md`(**递归**——#369),逐档读 §1 状态行判定 open
|
|
116
105
|
* (readBatchStatusLine === "open")。0 个 ⇒ throw(无在飞批);恰 1 个 ⇒ 返回该档绝对路径;
|
|
117
106
|
* ≥2 ⇒ throw(复数在飞批——必传 path,错误消息列出候选)。
|
|
118
|
-
*
|
|
107
|
+
* 多本在飞批并存合法(2026-10-27 用户裁定「当然是允许多个」)——本函数的「≥2 ⇒ 拒」是**默认定位的歧义门**
|
|
108
|
+
* (D-BR21),不是禁止并存:写锁只问「台账里有没有在途行」(设计档决策 7)。
|
|
119
109
|
* @param {string} cwd
|
|
120
110
|
* @param {string[]} bases — 已解析的批次档基底根数组
|
|
121
111
|
* @returns {string} 唯一在飞批绝对路径
|
|
@@ -139,209 +129,20 @@ export function findInFlightBatch(cwd, bases) {
|
|
|
139
129
|
return candidates[0]
|
|
140
130
|
}
|
|
141
131
|
|
|
142
|
-
/** create 路径越界判据已迁 `batch-paths.mjs`(`resolveBatchCreatePath` 内含——§4.15 单源)。 */
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* create——建档(§4.11,仅 depth-0)。六段骨架一次预齐(骨架模板单源 = batchSkeleton),
|
|
146
|
-
* 建档即过 gate(§1 占位状态行含「进行中」);fail-closed:非 .md / 越基底 / 目标已存在 ⇒ throw
|
|
147
|
-
* (不覆盖既有批档,BR-20);目录缺失 ⇒ mkdir -p 后落位(BR-25)。不代建台账条目。
|
|
148
|
-
* 路径解析 = `resolveBatchCreatePath`(§4.15 单源:候选序首个落基底内者 / 锚定串只解析项目根形)。
|
|
149
|
-
* F11-B:`source` **必填**(topic 同款空拒——骨架编制行实参化;不传 = 死占位残留必被 F11-C 拒
|
|
150
|
-
* ⇒ create 即拒,不留死锁);`prev` 传入值**幂等剥**「前情 = 」前缀(值规范化;默认值零变)。
|
|
151
|
-
* 2026-10-05(A-2):`ledger` / `board` 可选参**建即填**台账行(归一契约 = §4.11;回执两态 =
|
|
152
|
-
* 两参皆给 ⇒ 标注已填 ∥ 未给(任一)⇒ 填法句)。
|
|
153
|
-
* 2026-10-09(§4.16):骨架**按模式位取形**(`batchSkeleton({…, mode})`——执行期实读;普通面
|
|
154
|
-
* 作者标签四处替换,工程面骨架产出逐字不变)。
|
|
155
|
-
* @returns {string} 成功消息(含落盘绝对路径)
|
|
156
|
-
*/
|
|
157
|
-
export function createBatchRecord({ args, ctx, review, cwd, bases, onWritten }) {
|
|
158
|
-
assertMainAgentOnly(ctx, "create", review)
|
|
159
|
-
const raw = typeof args?.path === "string" ? args.path.trim() : ""
|
|
160
|
-
if (!raw) {
|
|
161
|
-
throw new Error("batch: create requires path — the new batch record's location (a .md path under the batch base roots, relative or absolute). Nothing was written.")
|
|
162
|
-
}
|
|
163
|
-
if (!/\.md$/.test(raw)) {
|
|
164
|
-
throw new Error(`batch: create path must end in .md — got ${JSON.stringify(raw)} (fail-closed: non-markdown targets are refused). Nothing was written.`)
|
|
165
|
-
}
|
|
166
|
-
const primary = bases?.[0]
|
|
167
|
-
if (!primary) {
|
|
168
|
-
throw new Error("batch: no batch-record base root is available — fix PROJECT-MANIFEST.json docRoot.batches (or its default) before creating a record. Nothing was written.")
|
|
169
|
-
}
|
|
170
|
-
const abs = resolveBatchCreatePath(cwd, raw, bases)
|
|
171
|
-
if (readableFile(abs)) {
|
|
172
|
-
throw new Error(`batch: create target already exists — refusing to overwrite an existing batch record (fail-closed, BR-20): ${raw}`)
|
|
173
|
-
}
|
|
174
|
-
const topic = typeof args?.topic === "string" && args.topic.trim() ? args.topic.trim() : null
|
|
175
|
-
if (!topic) {
|
|
176
|
-
throw new Error("batch: create requires topic — the batch subject word shared by the record header (档名与档头共用——keep the file name aligned with it). Nothing was written.")
|
|
177
|
-
}
|
|
178
|
-
const source = typeof args?.source === "string" ? args.source.trim() : ""
|
|
179
|
-
if (!source) {
|
|
180
|
-
throw new Error("batch: create requires source — the record's origin line (来源 = …). Pass where this batch came from (the request / discussion that started it); it lands in the header's 编制 line. Nothing was written.")
|
|
181
|
-
}
|
|
182
|
-
if (/\r?\n/.test(source)) {
|
|
183
|
-
throw new Error("batch: create source must be a single line — a multi-line source would break the header's 编制 line. Nothing was written.")
|
|
184
|
-
}
|
|
185
|
-
// 档头两可选参(§4.11 契约——给则建即填台账行;未给任一 ⇒ 占位留存 + 回执填法句)
|
|
186
|
-
const ledger = normalizeHeaderParam("ledger", args?.ledger)
|
|
187
|
-
const board = normalizeHeaderParam("board", args?.board)
|
|
188
|
-
const date = typeof args?.date === "string" && args.date.trim() ? args.date.trim() : todayLocal()
|
|
189
|
-
// F11-B:prev 幂等 strip——调用方自带「前情 = 」前缀(单或重复)一并剥净(`+` 量词;归一化目的
|
|
190
|
-
// = 值规范化,无前缀值原样通过)。默认值形态「无(独立批)」零变。
|
|
191
|
-
const prevRaw = typeof args?.prev === "string" ? args.prev.trim() : ""
|
|
192
|
-
const prev = prevRaw ? (prevRaw.replace(/^(?:前情\s*[=::]\s*)+/g, "").trim() || "无(独立批)") : "无(独立批)"
|
|
193
|
-
mkdirSync(dirname(abs), { recursive: true })
|
|
194
|
-
// 模式位执行期实读(§4.16——骨架取形时点 = 建档即固;翻转不回写既有骨架)
|
|
195
|
-
const mode = ctx?.agent?.config?.agent?.engineering ? "engineering" : "normal"
|
|
196
|
-
writeFileSync(abs, batchSkeleton({ date, topic, source, prev, ledger, board, mode }))
|
|
197
|
-
onWritten?.(ctx?.agent ?? {}, abs)
|
|
198
|
-
// 回执两态(`TOOLS.md` §6.20 逐字):两参皆给 ⇒ 标注已填;未给(任一)⇒ 填法句(填法 = 文件编辑)
|
|
199
|
-
const headerNote = ledger !== null && board !== null
|
|
200
|
-
? `header 台账 line filled (${ledger} · ${board})`
|
|
201
|
-
: "header 台账 placeholder(s) remain — fill them by file edit before the record's first append/status opens"
|
|
202
|
-
return `batch: created ${abs} — six-section skeleton written (§1 status line carries the gate-legal 「进行中」 placeholder; register the ledger entry yourself — create does not). ${headerNote}`
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* 段内状态行单行改写(status/close 共用——append-only 的唯一豁免,域限状态行):
|
|
207
|
-
* 定位 `## §N` 段(sectionHeaderRe 单源),段内逐行扫描 STATUS_LINE_RE 首命中行原位替换
|
|
208
|
-
* (行尾随命中行自身);缺失则标题行后偏移插入状态行 + 空行(插入块行尾 = 标题行自身
|
|
209
|
-
* 行尾——锚行后首二字节判读)。段界外字节零变(行切分 = /\r?\n/:EOL 形态无关)。
|
|
210
|
-
* 段标题缺失 ⇒ throw(create 是骨架唯一权威入口)。
|
|
211
|
-
*/
|
|
212
|
-
function updateSectionStatusLine(src, seg, value) {
|
|
213
|
-
const hdr = sectionHeaderRe(seg).exec(src)
|
|
214
|
-
if (!hdr) {
|
|
215
|
-
throw new Error(`batch: the batch record has no "## §${seg}" section header — cannot update its status line (create is the skeleton's only authoritative entry; append/status never add one). Nothing was written.`)
|
|
216
|
-
}
|
|
217
|
-
const nextRe = /^## §\d/gm
|
|
218
|
-
nextRe.lastIndex = hdr.index + hdr[0].length
|
|
219
|
-
const next = nextRe.exec(src)
|
|
220
|
-
const endIdx = next ? next.index : src.length
|
|
221
|
-
const line = `**状态行**:${value}`
|
|
222
|
-
const parts = src.slice(hdr.index, endIdx).split(/(\r?\n)/) // 保留分隔符(奇数下标 = 行尾)——替换只动命中行
|
|
223
|
-
const idx = parts.findIndex((p) => STATUS_LINE_RE.test(p))
|
|
224
|
-
if (idx >= 0) { parts[idx] = line } else {
|
|
225
|
-
const eol = parts[1] === "\r\n" ? "\r\n" : "\n" // 缺行插入块行尾 = 标题行自身行尾
|
|
226
|
-
if (parts.length === 1) parts.splice(1, 0, eol, line, eol, "", eol, "")
|
|
227
|
-
else parts.splice(2, 0, line, eol, "", eol, "", eol)
|
|
228
|
-
}
|
|
229
|
-
return src.slice(0, hdr.index) + parts.join("") + src.slice(endIdx)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/** §6 空闸拒句(#422①——空 ⇒ 拒 + 提示先写 §6;防「append 被拒 ⇒ close 照常 ⇒ §6 永久为空」
|
|
233
|
-
* 复发——2026-09-26 dispatch-sizing 批实证):**§6 为唯一缺段时**拒串取本函数(§4.18-A J2——
|
|
234
|
-
* 「非空门」文案逐字零回归);判据本体 = 单源谓词 `sectionContentState(src, 6)`(`batch-skeleton.mjs`),
|
|
235
|
-
* 旧谓词函数已随判据单源退场(不留第二套)。 */
|
|
236
|
-
function emptySectionSixError() {
|
|
237
|
-
return "batch: §6 收口段为空(non-empty gate)— close refuses: the closeout section (§6) has no content, and closing would freeze the record with that section permanently empty. Write the section first (append §6: the closeout / verification summary), then call close again. Nothing was written."
|
|
238
|
-
}
|
|
239
|
-
|
|
240
132
|
/** 冻结门(§4.9——append/status 同门;close 视为写同样过门):closed/unknown 的错误串与
|
|
241
|
-
* append 面同字面(「已收口档不回改」/「状态行不可解析或缺失」)。
|
|
242
|
-
|
|
133
|
+
* append 面同字面(「已收口档不回改」/「状态行不可解析或缺失」)。
|
|
134
|
+
* unknown 串多两句:段级状态行的取值区已收窄到 §1 **段头区**,行落在区外(段体 / 轮次块)就读不成值
|
|
135
|
+
* ——拒文点名这条终态与唯一出路(把行移进段头区),否则被卡住的人在界面上无路可走(设计档 §5 R26)。 */
|
|
136
|
+
export function assertGateOpen(src) {
|
|
243
137
|
const gate = readBatchStatusLine(src)
|
|
244
138
|
if (gate === "closed") {
|
|
245
139
|
throw new Error("batch: 已收口档不回改 — the record's §1 status line contains 「已收口」, so the record is frozen: its body is never written to again (整档冻结;改 = 新批新档). Nothing was written.")
|
|
246
140
|
}
|
|
247
141
|
if (gate === "unknown") {
|
|
248
|
-
throw new Error("batch: 状态行不可解析或缺失 — the record has no §1 `**状态行**:` line whose value contains 已收口 or 进行中 (fail-closed: the write is refused as if frozen). Nothing was written. Do NOT close the record after a refused append — nothing landed, and closing freezes the missing section for good (失败 ⇒ 勿 close).")
|
|
142
|
+
throw new Error("batch: 状态行不可解析或缺失 — the record has no §1 `**状态行**:` line inside the section header zone whose value contains 已收口 or 进行中 (fail-closed: the write is refused as if frozen). If the record does carry such a line further down — in a round block or in the section body — move it up under `## §1`: a status line outside the header zone is never read. Nothing was written. Do NOT close the record after a refused append — nothing landed, and closing freezes the missing section for good (失败 ⇒ 勿 close).")
|
|
249
143
|
}
|
|
250
144
|
}
|
|
251
145
|
|
|
252
|
-
// ─── 链完整性门(§4.18-A——close ∥ status 写「已收口」两路收口前置;D-BR30)──────────
|
|
253
|
-
|
|
254
|
-
/** 链判段集(§2/§3/§4/§6——§5 段号豁免恒不判;§1 主 agent 自述段不设前置)。 */
|
|
255
|
-
const CHAIN_SEGMENTS = [2, 3, 4, 6]
|
|
256
|
-
|
|
257
|
-
/** 链门拒绝句(§4.18-A J1——缺段非仅 §6 时;逐字文本 = `TOOLS.md` §6.24 J1。`missing` = 点名串,
|
|
258
|
-
* 形如 `§2 / §3 / §4`——按段号升序列出)。 */
|
|
259
|
-
function closeoutChainError(missing) {
|
|
260
|
-
return "batch: 收口链未跑完(closeout chain gate)— close refuses: the record's closeout chain has not run, and closing would freeze it that way. " +
|
|
261
|
-
`Missing: ${missing}. Each named section must carry content (append it) or be declared inapplicable in §1 as ` +
|
|
262
|
-
"`> 不适用:§N —— <reason>` (§2 / §3 / §4 only). §6 must carry its verification (never declarable) and §5 is exempt (a light-channel round has no implementation section). " +
|
|
263
|
-
"Nothing was written."
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* 链完整性门(§4.18-A——**收口前置**):`close` ∥ `status` 写「已收口」两路在写盘前同过本门。
|
|
268
|
-
* 判据:§2 / §3 / §4 / §6 每段须 `sectionContentState(src, seg) !== "empty"`(有内容 ∥ 声明不适用);
|
|
269
|
-
* 不满足 ⇒ throw 并点名缺段(拒串 = J1——点名串按段号升序 `§2 / §3 / §4` 形)。**§6 为唯一缺段时
|
|
270
|
-
* 拒串 = 旧串逐字**(`emptySectionSixError()`——J2,零回归)。门位 = 既有拒因之后、文档机检门之前
|
|
271
|
-
* (§4.9 门清单第 ③ 道);门不判内容质量、不做自动修复、不判 §1 / §5。
|
|
272
|
-
* @param {string} src — 档全文(写盘前只读)
|
|
273
|
-
*/
|
|
274
|
-
function assertCloseoutChainComplete(src) {
|
|
275
|
-
// 声明形不合先行(J3——不静默当作无声明):§1 内「不适用」打头而完整形不合 ⇒ 拒
|
|
276
|
-
const badDecl = malformedInapplicableLine(src)
|
|
277
|
-
if (badDecl !== null) throw new Error(inapplicableDeclarationError(badDecl))
|
|
278
|
-
const missing = CHAIN_SEGMENTS.filter((n) => sectionContentState(src, n) === "empty")
|
|
279
|
-
if (missing.length === 0) return
|
|
280
|
-
if (missing.length === 1 && missing[0] === 6) throw new Error(emptySectionSixError()) // J2——零回归
|
|
281
|
-
throw new Error(closeoutChainError(missing.map((n) => `§${n}`).join(" / "))) // J1
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// ─── 重开路径(§4.18-B——已收口档带审计的逆向流转;D-BR31)─────────────────────────
|
|
285
|
-
|
|
286
|
-
/** 重开缺理由拒绝句(§4.18-B J4——触发合取缺 note;逐字文本 = `TOOLS.md` §6.24 J4)。 */
|
|
287
|
-
function reopenReasonError() {
|
|
288
|
-
return "batch: 重开需理由(reopen requires a reason)— reopening a frozen record reverses a recorded decision, so the reason must be stated: pass it as `note` (it lands verbatim in the §1 reopen record). Nothing was written."
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* 重开(§4.18-B——已收口档 status(进行中, note 非空)):一次写盘、两处落笔——
|
|
293
|
-
* ① §1 状态行 → `进行中(重开 <YYYY-MM-DD>)`(updateSectionStatusLine 既有单行豁免);
|
|
294
|
-
* ② §1 **段尾追加**追记行 `**重开记录**:<日期> · 原收口 <旧日期> · 理由 = <note> · 操作者 = 主 agent`
|
|
295
|
-
* (appendLineToSection——只追加;原收口 = 改写前状态行的收口日期字面,无日期字面 ⇒ `未标日期`)。
|
|
296
|
-
* 只追加判据:行数 +1、仅状态行原位替换、余行逐字节不变。EOL = §1 段头行自身行尾(CRLF 档 ⇒ CRLF)。
|
|
297
|
-
* @param {string} src — 档全文(closed 态)
|
|
298
|
-
* @param {string} note — 重开理由(调用面已验非空单行)
|
|
299
|
-
* @returns {string} 写盘用新全文
|
|
300
|
-
*/
|
|
301
|
-
function rewriteAsReopen(src, note) {
|
|
302
|
-
// 原收口 = 改写前 §1 状态行的收口日期字面(先取后改——重开后该行不再携带它)
|
|
303
|
-
const prevLine = (readBatchStatusLineRaw(src) ?? "").trim()
|
|
304
|
-
const prevDate = /已收口\s*(\d{4}-\d{2}-\d{2})/.exec(prevLine)?.[1] ?? "未标日期"
|
|
305
|
-
const date = todayLocal()
|
|
306
|
-
const withStatus = updateSectionStatusLine(src, 1, `进行中(重开 ${date})`)
|
|
307
|
-
return appendLineToSection(withStatus, 1, `**重开记录**:${date} · 原收口 ${prevDate} · 理由 = ${note} · 操作者 = 主 agent`)
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/** §1 状态行值原文(改写前的读取面——readBatchStatusLine 只给三态,日期字面须自己读)。 */
|
|
311
|
-
function readBatchStatusLineRaw(src) {
|
|
312
|
-
const s1 = /^## §1(?=\s|$)/m.exec(src)
|
|
313
|
-
if (!s1) return null
|
|
314
|
-
const nextRe = /^## §\d/gm
|
|
315
|
-
nextRe.lastIndex = s1.index + s1[0].length
|
|
316
|
-
const next = nextRe.exec(src)
|
|
317
|
-
const body = src.slice(s1.index + s1[0].length, next ? next.index : src.length)
|
|
318
|
-
return body.split(/\r?\n/).map((line) => STATUS_LINE_RE.exec(line)).find(Boolean)?.[1] ?? null
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* §N 段尾追加一行(§4.18-B——重开追记行载体;append-only:只追加,既有行字节零变)。
|
|
323
|
-
* 位置 = 段体尾部(下一 `## §` 段头之前 ∥ 文末);追加行 EOL = §1 段头行自身行尾
|
|
324
|
-
* (`\r\n` ⇒ CRLF ∥ 其余 ⇒ `\n`——探测窗 = 段头行整体〔含行尾〕,`/^## §N[^\r\n]*\r?\n/` 一次取形)。
|
|
325
|
-
* 段标题缺失 ⇒ throw(create 是骨架唯一权威入口——同 append 面 fail-closed)。
|
|
326
|
-
*/
|
|
327
|
-
function appendLineToSection(src, seg, line) {
|
|
328
|
-
const hdr = sectionHeaderRe(seg).exec(src)
|
|
329
|
-
if (!hdr) {
|
|
330
|
-
throw new Error(`batch: the batch record has no "## §${seg}" section header — cannot append to its tail (create is the skeleton's only authoritative entry). Nothing was written.`)
|
|
331
|
-
}
|
|
332
|
-
const headerLine = /^## §\d[^\r\n]*\r?\n/m.exec(src.slice(hdr.index))
|
|
333
|
-
const eol = headerLine?.[0].endsWith("\r\n") ? "\r\n" : "\n"
|
|
334
|
-
const nextRe = /^## §\d/gm
|
|
335
|
-
nextRe.lastIndex = hdr.index + hdr[0].length
|
|
336
|
-
const next = nextRe.exec(src)
|
|
337
|
-
const endIdx = next ? next.index : src.length
|
|
338
|
-
let before = src.slice(0, endIdx)
|
|
339
|
-
const after = src.slice(endIdx)
|
|
340
|
-
// 只保证「行自成行」:段尾无换行 ⇒ 补一个段头行行尾;已有换行零补(不插空行——只追加判据 = 行数 +1)
|
|
341
|
-
if (!before.endsWith(eol)) before += eol
|
|
342
|
-
return before + line + eol + after
|
|
343
|
-
}
|
|
344
|
-
|
|
345
146
|
/** 全词表去重并集(各段项——value 命中判据与 note 零命判据共用同一口径)。 */
|
|
346
147
|
function statusVocabulary() {
|
|
347
148
|
return [...new Set(Object.values(STATUS_WORDS).flatMap((w) => Object.values(w)))]
|
|
@@ -359,10 +160,11 @@ function stripDecorations(value) {
|
|
|
359
160
|
return value.replace(LEAD_DECOR_RE, "").replace(ISO_TAIL_RE, "").replace(TAIL_DECOR_RE, "")
|
|
360
161
|
}
|
|
361
162
|
|
|
362
|
-
/** status 值域校验(fix 轮 #1 + 词面纪律 +
|
|
163
|
+
/** status 值域校验(fix 轮 #1 + 词面纪律 + F11-A 谓词收紧):值在**全词表 union**中必须恰
|
|
363
164
|
* 命中一个关键字(判读序不动:≥2 命中 ⇒ 混词拒在前;0 命中 / 唯一命中不属本段 ⇒ 词表外拒),
|
|
364
165
|
* 且剥装饰白名单后**余核逐字 = 该关键词**(余核 ≠ 关键词 = 散文内嵌 ⇒ 词表外拒同串)。
|
|
365
|
-
*
|
|
166
|
+
* 「进行中…已收口」双词无论写哪段皆拒(最小词面:已收口优先误冻结防线)。
|
|
167
|
+
* 2026-10-27 起 §3 的完成词 = `评审通过`——旧字面 `评审完成` 不在词表 ⇒ 写它即词表外拒(读侧仍等义)。 */
|
|
366
168
|
function assertStatusValue(seg, value) {
|
|
367
169
|
const words = Object.values(STATUS_WORDS[seg] ?? {})
|
|
368
170
|
if (!words.length) {
|
|
@@ -377,15 +179,6 @@ function assertStatusValue(seg, value) {
|
|
|
377
179
|
}
|
|
378
180
|
}
|
|
379
181
|
|
|
380
|
-
/** note 单行判据(两径共用——非重开径落状态行括注、重开径落 §1 追记行,两者都是一行;
|
|
381
|
-
* 重开径不取 `assertStatusNote` 的另两条判据〔词表零命中 / 死占位〕——理由允许携词表关键字,
|
|
382
|
-
* 而追记行不是状态行形态、不参与 gate 判读(§4.18-B 理由校验)。 */
|
|
383
|
-
function assertSingleLineNote(note) {
|
|
384
|
-
if (/\r?\n/.test(note)) {
|
|
385
|
-
throw new Error("batch: status note must be a single line — a multi-line note would break the one-line status-line form. Nothing was written.")
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
|
|
389
182
|
/** status `note` 字段校验(F11-A——落盘形态 = 状态行行内括注):单行 + **全词表零命中**
|
|
390
183
|
* (括注永不误触冻结门——§1 判定是子串包含;已收口优先误冻结防线的第二道)+ 死占位判据零命中
|
|
391
184
|
* (括注不得成为骨架占位的新驻留面)。 */
|
|
@@ -401,33 +194,52 @@ function assertStatusNote(note) {
|
|
|
401
194
|
}
|
|
402
195
|
}
|
|
403
196
|
|
|
197
|
+
/** 拒串:目标段段头区内**两条以上**状态行(§4.21.4 写面第二道——让这个歧义状态不再产生)。
|
|
198
|
+
* 修复句按段分两支:非 §1 = 先 `edit` 删多余那条(区内回到 1 ⇒ 可读行重新出现)再 `status` 改写余下那条
|
|
199
|
+
* (记录全程 open,通道可达);§1 = 主 agent 普通文档写(`edit` / `status` 在不可解析面上全部 fail-closed,
|
|
200
|
+
* 不许借重开绕)。顺序不能反:歧义时 `status` 拒,而 `edit` 不读该段的词面。 */
|
|
201
|
+
function STATUS_LINE_AMBIGUOUS_ERROR(seg, count) {
|
|
202
|
+
const repair = Number(seg) === 1
|
|
203
|
+
? "The §1 zone cannot be repaired through this tool: edit and status are both fail-closed on an unreadable §1 (reopening is not a way around it) — the main agent repairs it with an ordinary document write, deleting the surplus line so the zone holds exactly one."
|
|
204
|
+
: `Repair order (the record stays open throughout): first batch({action:"edit", segment:"§${seg}"}) on the non-protected line with newText "" — deleting it leaves the zone with one status line, so a readable line exists again — then batch({action:"status", segment:"§${seg}"}) rewrites that remaining (protected) line.`
|
|
205
|
+
return `batch: §${seg} carries ${count} \`**状态行**\` lines in its section header zone — a section's status is read only when the zone holds exactly one, so this one reads as unset (§2/§3/§5 word face = null; §1 = unknown ⇒ fail-closed). Nothing was written. ${repair}`
|
|
206
|
+
}
|
|
207
|
+
|
|
404
208
|
/**
|
|
405
209
|
* status——状态行流转(§4.12,段属主;§4.16 模式感知)。写域 = 调用者自己段内 `**状态行**:`
|
|
406
210
|
* 行(评审 → §3 · eng-designer → §2 · eng-coder / coder → §5 · 主 agent:工程 §1 ∥ 普通
|
|
407
|
-
* §1/§2/§5 取段——缺省 §1);值域 = STATUS_WORDS
|
|
408
|
-
*
|
|
409
|
-
* path 参数 = 仅 depth-0(D-BR21)——子代理/评审传 path ⇒
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
211
|
+
* §1/§2/§5 取段——缺省 §1);值域 = STATUS_WORDS 该段项恰一词(余核 = 关键词),散文说明走 `note`
|
|
212
|
+
* 字段(落状态行括注);冻结真值不变(gate 只读 §1)。
|
|
213
|
+
* path 参数 = 仅 depth-0(D-BR21)——子代理/评审传 path ⇒ 拒。F11-C 挂点 = 写盘前(档头结构行含骨架
|
|
214
|
+
* 死占位 ⇒ 拒;段体引用豁免;close 不拦——收口是主 agent 终态动作)。
|
|
215
|
+
* **段头区歧义拒写**(§4.21.4 写面第二道):目标段段头区两条以上状态行 ⇒ 拒并给修复句(非 §1 = 先
|
|
216
|
+
* `edit` 删多余那条再 `status`;§1 = 普通文档写)——位次 = 读档之后、重开合取之前(两路都是拒)。
|
|
217
|
+
* **收口第二通路**:值余核 = §1「已收口」时本 action 同样收口(收口门 + 单测档门 + 机检门 + 冻结与
|
|
218
|
+
* close 同序)⇒ 状态行写盘后同调 `reanchorOnClose`,回执携同一 `[ledger reanchor]` 段;`completed` 与
|
|
219
|
+
* `closeEvidence` 与 `close` 同两条必填,台账失败同样回滚档并抛拒。与 close 同门同分派:全归档批走补关
|
|
220
|
+
* (§4.18-C,只绕开内容门与 §3 pass 臂,§1 段尾落一行 `**补关记录**`)。
|
|
221
|
+
* **重开径**(§4.18-B · §2.13):前态 closed ∧ 值 = 进行中 ∧ note 非空 ⇒ 重开;写盘后同调
|
|
222
|
+
* `reclaimOnReopen`(`待核销 → 在途`),回执携 `[ledger reopen]` 段;回收失败 ⇒ 档回滚到冻结态并抛拒。
|
|
223
|
+
* **其余一切用法零台账写**;本 action 的回执末尾恒带一行 `[ledger consistency]`。
|
|
414
224
|
* @returns {Promise<string>} 成功消息
|
|
415
225
|
*/
|
|
416
|
-
export async function statusBatchRecord({ args, ctx, review, pickTarget, onWritten }) {
|
|
226
|
+
export async function statusBatchRecord({ args, ctx, review, reviewTrack, pickTarget, onWritten }) {
|
|
417
227
|
const depth0 = isDepthZero(ctx)
|
|
418
228
|
// 模式位执行期实读(§4.16——同款先例 = task.mjs execute 门;翻转即时生效——D-BR26)。
|
|
419
|
-
// 写域:评审 → §3 · 子代理 → 身份段(普通模式分支合并 coder 增表——工程模式分支不查)·
|
|
420
|
-
// depth-0 工程 → §1 ∥ 普通 → §1/§2/§5(取段——缺省 §1)。
|
|
421
229
|
const engineering = !!ctx?.agent?.config?.agent?.engineering
|
|
422
|
-
|
|
230
|
+
// 段域与 append/edit 同一道闸、同一判据(§4.1 ∥ §4.4):工程**设计轨**的 `§3` 对一切工具通道只读——
|
|
231
|
+
// `status` 也在其中(那条路的状态行由结算随块同笔写,没有手写口)。判据单源 = `reviewWritableSegment`。
|
|
232
|
+
let seg = review
|
|
233
|
+
? reviewWritableSegment(engineering, reviewTrack)
|
|
234
|
+
: depth0 ? 1 : SEGMENT_BY_ROLE[ctx?.agent?._role] ?? (engineering ? null : SEGMENT_BY_ROLE_NORMAL[ctx?.agent?._role] ?? null)
|
|
423
235
|
if (seg === null) {
|
|
236
|
+
if (review) throw new Error(sectionThreeDesignTrackError("batch"))
|
|
424
237
|
throw new Error("batch: no segment is writable by this caller — status writes the caller's OWN section (eng-designer → §2, design review → §3, eng-coder → §5, main agent → §1).")
|
|
425
238
|
}
|
|
426
239
|
// 段域判据(BR-22「eng-designer 对 §1 调 status ⇒ 段白名单拒」——镜像 append 面):
|
|
427
240
|
// depth-0 普通面(§4.16)= **取段**——写域集 §1/§2/§5、缺省 §1、越出集合 ⇒ 拒(模式化新串);
|
|
428
241
|
// depth-0 工程面 ∥ 子代理 ∥ 评审 = **声明段核对**(声明段 ≠ 身份写域段 ⇒ 拒;身份写域段可省略)。
|
|
429
242
|
const declared = args?.segment === undefined || args?.segment === null ? null : segmentNumber(args.segment)
|
|
430
|
-
// 传值而解析不可得 ⇒ 显式拒(#1116——镜像 append 面「unknown segment」串形;未传 = 缺省语义零变)。
|
|
431
243
|
if (declared === null && args?.segment !== undefined && args?.segment !== null) {
|
|
432
244
|
throw new Error(`batch: unknown segment ${JSON.stringify(args?.segment ?? null)} — pass the section number you write (e.g. "§${seg}"), or omit it. Nothing was written.`)
|
|
433
245
|
}
|
|
@@ -452,102 +264,123 @@ export async function statusBatchRecord({ args, ctx, review, pickTarget, onWritt
|
|
|
452
264
|
}
|
|
453
265
|
// note(可选):散文说明的承载面——落状态行行内括注(value 内散文不再容忍);缺省 / 空串 = 无括注。
|
|
454
266
|
// **重开径例外(§4.18-B)**:值关键词 = 进行中 ∧ §1 门态 = closed ⇒ note = 重开理由(J4 缺则拒),
|
|
455
|
-
// 不进状态行括注(落 §1 追记行);`assertStatusNote`
|
|
267
|
+
// 不进状态行括注(落 §1 追记行);`assertStatusNote` 不取——理由允许携词表关键字。
|
|
456
268
|
const note = typeof args?.note === "string" ? args.note.trim() : ""
|
|
457
269
|
assertStatusValue(seg, value)
|
|
458
270
|
const abs = pickTarget(args?.path)
|
|
459
271
|
const src = readFileSync(abs, "utf8")
|
|
272
|
+
// 段头区状态行歧义(§4.21.4 写面第二道)——位次 = 读档之后、重开合取与冻结门之前(§1 歧义面拿到的
|
|
273
|
+
// 是「修法 = 普通文档写」这一句,比冻结门的「不可解析」更贴现场;两路都是拒)。
|
|
274
|
+
const zoneCount = zoneStatusCount(src, seg)
|
|
275
|
+
if (zoneCount > 1) throw new Error(STATUS_LINE_AMBIGUOUS_ERROR(seg, zoneCount))
|
|
460
276
|
// 重开合取(§4.18-B):段 = §1 · depth-0(非评审)· 值关键词 = 进行中 · 门态 = closed——
|
|
461
|
-
// 先于冻结拒写判定(门②的唯一例外);note = 重开理由(J4
|
|
277
|
+
// 先于冻结拒写判定(门②的唯一例外);note = 重开理由(J4 缺则拒)。**台账联动只由本合取触发**。
|
|
462
278
|
const reopen = seg === 1 && depth0 && !review && stripDecorations(value) === STATUS_WORDS[1].open && readBatchStatusLine(src) === "closed"
|
|
463
279
|
if (reopen && !note) throw new Error(reopenReasonError()) // J4——重开必须带理由
|
|
464
|
-
//
|
|
465
|
-
// 允许携状态词表关键字(常写「误标已收口」:追记行不是状态行形态、不参与 gate 判读)。
|
|
466
|
-
if (reopen) assertSingleLineNote(note)
|
|
280
|
+
if (reopen) assertSingleLineNote(note) // 单行 + 非空(非空已由 J4 判)
|
|
467
281
|
else if (note) assertStatusNote(note)
|
|
468
282
|
const lineValue = note && !reopen ? `${value}(${note})` : value
|
|
469
283
|
if (!reopen) assertGateOpen(src) // 冻结拒写——重开合取是唯一越过点(§4.9 门②例外;其余逐字零变)
|
|
470
|
-
// F11-C(写盘前):档头结构行死占位残留 ⇒
|
|
284
|
+
// F11-C(写盘前):档头结构行死占位残留 ⇒ 拒(段体引用豁免)
|
|
471
285
|
const residues = findPlaceholderResidue(src)
|
|
472
286
|
if (residues.length) throw new Error(placeholderResidueError(residues))
|
|
473
287
|
if (reopen) {
|
|
474
|
-
// 重开(§4.18-B):一次写盘、两处落笔(状态行改写 + §1
|
|
288
|
+
// 重开(§4.18-B · §2.13):一次写盘、两处落笔(状态行改写 + §1 段尾追记行)——不跑收口门
|
|
475
289
|
//(值非「已收口」;写后门态 = open,后续 append/status 恢复放行)。
|
|
476
290
|
writeFileSync(abs, rewriteAsReopen(src, note))
|
|
291
|
+
// 记账口径同 status 径(记「落过盘」,回档不回退)——见 `statusBatchRecord` 写盘处的注释。
|
|
292
|
+
if (ctx?.agent) ctx.agent._batchWrites = (ctx.agent._batchWrites ?? 0) + 1 // §6.6 `wrote` 判据(写盘成功才增)
|
|
477
293
|
onWritten?.(ctx?.agent ?? {}, abs)
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
294
|
+
// ② 台账回收(§2.17 重开步序 3–4 · 写序:档先写、台账后写):失败 ⇒ 用写前全文(冻结态)补偿回滚档,
|
|
295
|
+
// 然后抛拒——「档已开、行仍 待核销」的残态会让写锁拒每一笔写盘且没有任何提示,正是本批要消掉的那一形。
|
|
296
|
+
const reclaim = await ledgerAfterRecordWrite({
|
|
297
|
+
side: "reopen", abs, src, run: () => reclaimOnReopen(abs, ctx?.agent?.cwd),
|
|
298
|
+
})
|
|
299
|
+
return `batch: §1 reopened — status line → 「进行中(重开 ${todayLocal()})」 + reopen record appended to §1 (reason lands verbatim in the record line). Append/status are writable again (BR-64); the closeout chain gate still applies at the next close.${reopenReceiptLine(reclaim)}${consistencyReceiptLine(await consistencyOf(abs, ctx?.agent?.cwd))}`
|
|
300
|
+
}
|
|
301
|
+
// 收口门(§2.6——链门 + §3 状态词臂 + 单测档门 + 机检门):本笔把 §1 写成「已收口」⇒ 四道同判。
|
|
302
|
+
// 段号守卫只写这一次(`STATUS_WORDS[1].closed` 只属 §1 项,`assertStatusValue` 亦拒他段该值)。
|
|
483
303
|
const closingValue = seg === 1 && stripDecorations(value) === STATUS_WORDS[1].closed
|
|
484
|
-
if (closingValue)
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
if (closingValue
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
304
|
+
if (!closingValue && args?.completed !== undefined) {
|
|
305
|
+
throw new Error("batch: completed is accepted only by close or by status writing §1 已收口. Nothing was written.")
|
|
306
|
+
}
|
|
307
|
+
if (!closingValue && args?.closeEvidence !== undefined) {
|
|
308
|
+
throw new Error("batch: closeEvidence is accepted only by close or by status writing §1 已收口. Nothing was written.")
|
|
309
|
+
}
|
|
310
|
+
// 收口分流(§4.18-C):链门之前读一致性——全归档批走补关,其余走完整链门。
|
|
311
|
+
const repair = closingValue ? await repairDecisionOf(abs, ctx?.agent?.cwd) : null
|
|
312
|
+
const gate = closingValue ? assertCloseoutGates({ abs, cwd: ctx?.agent?.cwd, agent: ctx?.agent ?? {}, src, action: "status", mode: repair.repair ? "repair" : "normal" }) : null
|
|
313
|
+
// 完成清单预检位于既有收口门之后、凭证消费与批档写盘之前;拒绝时令牌、档、账均不变。
|
|
314
|
+
// `closeEvidence` 与 `completed` 同一格(收口即结算:证据由本笔给,机器不代写)。
|
|
315
|
+
if (closingValue) await assertCloseDisposition(abs, ctx?.agent?.cwd, args?.completed, args?.closeEvidence, true)
|
|
493
316
|
const designTokens = closingValue ? consumeBatchDesignTokens(ctx?.agent ?? {}, abs) : null
|
|
494
|
-
|
|
317
|
+
// 补关(§4.18-C)= 冻结之外在 §1 段尾追加一行追记(一次写盘、两处落笔);正常收口只改状态行。
|
|
318
|
+
// 补关只在 `closingValue` 下成立,而 `closingValue` 蕴含 `seg === 1` ⇒ 追记行恒落 §1。
|
|
319
|
+
const statusWritten = updateSectionStatusLine(src, seg, lineValue)
|
|
320
|
+
const written = repair?.repair ? appendLineToSection(statusWritten, 1, repairTraceLine(todayLocal(), repair.rows)) : statusWritten
|
|
495
321
|
writeFileSync(abs, written)
|
|
322
|
+
// 记账口径(明示,不改行为):`_batchWrites` 与端侧记账记的是「本笔**落过盘**」,位次 = 写盘成功那一刻;
|
|
323
|
+
// 台账失败由 `ledgerAfterRecordWrite` 把档回档后本计数不回退(档字节净变 = 零,而写盘事实发生过)。
|
|
324
|
+
// 它不进任何判据(§6.6 `wrote` 只问「有没有写过」),故不以回档为准重算。
|
|
325
|
+
if (ctx?.agent) ctx.agent._batchWrites = (ctx.agent._batchWrites ?? 0) + 1 // §6.6 `wrote` 判据(写盘成功才增)
|
|
496
326
|
onWritten?.(ctx?.agent ?? {}, abs)
|
|
497
|
-
// 收口重锚(§6.2 · C · AC-M2-30):值余核 = §1「已收口」⇒ 本 action
|
|
498
|
-
//
|
|
499
|
-
//
|
|
500
|
-
//
|
|
501
|
-
//
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
327
|
+
// 收口重锚(§6.2 · C · AC-M2-30):值余核 = §1「已收口」⇒ 本 action 就是收口 ⇒ 同调单源
|
|
328
|
+
// `reanchorOnClose`(不复制 close 径逻辑);次序位 = 状态行写盘之后(写序单源 = §2.17)。
|
|
329
|
+
// 本笔被任一拒因拒 ⇒ 上面各门早 throw,台账零写(被拒的收口没有收口)。一次收口只出一份清单。
|
|
330
|
+
// 台账失败 ⇒ 用写前全文回滚档并抛拒——冻结与结账要么一起成,要么一个都不成(除非回滚本身也失败,
|
|
331
|
+
// 那时第二条串点名半状态与查询面)。
|
|
332
|
+
const reanchor = closingValue && readBatchStatusLine(src) !== "closed"
|
|
333
|
+
? await ledgerAfterRecordWrite({ side: "close", abs, src, run: () => reanchorOnClose(abs, ctx?.agent?.cwd, args?.completed, args?.closeEvidence, true) })
|
|
334
|
+
: null
|
|
335
|
+
return `batch: §${seg} status line updated to ${JSON.stringify(lineValue)} — the freeze gate (§1) is a read-only domain for non-§1 writes (frozen truth stays = the §1 line).${gateReceiptLine(gate)}${changedSurfaceReceiptLine(gate?.changedSurface)}${designTokensReceiptLine(designTokens)}${repairReceiptLine(repair?.repair ? { rows: repair.rows, date: todayLocal() } : null)}${reanchorReceiptLine(reanchor)}${newDebtReasonReceiptLine(reanchor)}${consistencyReceiptLine(await consistencyOf(abs, ctx?.agent?.cwd))}`
|
|
505
336
|
}
|
|
506
337
|
|
|
507
338
|
/**
|
|
508
|
-
* close——收口冻结(§4.13,仅 depth-0)。§1 状态行 →「已收口 <YYYY-MM-DD>」;此后该档
|
|
509
|
-
*
|
|
510
|
-
*
|
|
511
|
-
* 前提规则(#422 +
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
* 缺失即插——同路收口;「有行但不可解析」仍 fail-closed)。
|
|
339
|
+
* close——收口冻结(§4.13,仅 depth-0)。§1 状态行 →「已收口 <YYYY-MM-DD>」;此后该档 append/status 全拒
|
|
340
|
+
* (冻结判据唯一真值 = §1 行——§4.9 零语义变;唯一例外 = 重开合取 §4.18-B)。对已收口档再 close ⇒ 拒。
|
|
341
|
+
* 不代写 §6 内容、不替代台账核销事务。
|
|
342
|
+
* 前提规则(#422 + §4.18-A + §2.6 四道门):① 收口门(链门 ∧ §3 状态词臂;§6 唯一缺段时拒串 = 旧 §6 串
|
|
343
|
+
* 逐字零回归);② 本批批内单测档门;③ 文档机检门;④ 无状态行档 ⇒ 自建机读位(「有行但不可解析」仍
|
|
344
|
+
* fail-closed)。**全归档补关**(§4.18-C)只绕开 ① 的两臂,②③ 与完成清单预检、凭证消费、重锚全保留。
|
|
515
345
|
* @returns {Promise<string>} 成功消息
|
|
516
346
|
*/
|
|
517
347
|
export async function closeBatchRecord({ args, ctx, review, pickTarget, onWritten }) {
|
|
518
348
|
assertMainAgentOnly(ctx, "close", review)
|
|
519
349
|
const abs = pickTarget(args?.path)
|
|
520
|
-
const src =
|
|
350
|
+
const src = readCloseoutSource(abs)
|
|
521
351
|
// #422③:§1 无状态行档 ⇒ 自建机读位(下行走 updateSectionStatusLine 缺失即插——同路收口);
|
|
522
352
|
// 「有行但不可解析」维持 fail-closed(assertGateOpen 拒——防误冻结)。
|
|
523
353
|
if (readBatchStatusLine(src) !== "open" && sectionHasStatusLine(src, 1)) assertGateOpen(src)
|
|
524
|
-
//
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
//
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
//
|
|
531
|
-
//
|
|
532
|
-
|
|
533
|
-
if (gate.state === "refused" || gate.state === "error") throw new Error(gateRefusalMessage(gate, "close"))
|
|
534
|
-
// 收口自动消费本批设计凭证(§10——位次 = 全部拒因之后、写盘之前;失败 ⇒ 原样上抛、本函数拒)
|
|
354
|
+
// 收口分流(§4.18-C):链门之前读一致性——全归档批走补关,其余走完整链门。
|
|
355
|
+
const repair = await repairDecisionOf(abs, ctx?.agent?.cwd)
|
|
356
|
+
// 收口门(§2.6):链门 → §3 状态词臂 → 单测档门 → 机检门(位次 = 既有拒因之后、写盘之前);
|
|
357
|
+
// 补关分派 ⇒ 只跳过前两臂(repair.repair)。
|
|
358
|
+
const gate = assertCloseoutGates({ abs, cwd: ctx?.agent?.cwd, agent: ctx?.agent ?? {}, src, action: "close", mode: repair.repair ? "repair" : "normal" })
|
|
359
|
+
// 完成清单预检位于既有收口门之后、凭证消费与批档写盘之前;拒绝时令牌、档、账均不变。
|
|
360
|
+
// `closeEvidence` 与 `completed` 同一格(收口即结算:证据由本笔给,机器不代写——代写一句就把核销门
|
|
361
|
+
// 变成摆设)。
|
|
362
|
+
await assertCloseDisposition(abs, ctx?.agent?.cwd, args?.completed, args?.closeEvidence, true)
|
|
535
363
|
const designTokens = consumeBatchDesignTokens(ctx?.agent ?? {}, abs)
|
|
536
364
|
const date = todayLocal()
|
|
537
|
-
|
|
365
|
+
// 补关(§4.18-C)= 冻结之外在 §1 段尾追加一行追记(一次写盘、两处落笔);正常收口只改状态行。
|
|
366
|
+
const statusWritten = updateSectionStatusLine(src, 1, `已收口 ${date}`)
|
|
367
|
+
const written = repair.repair ? appendLineToSection(statusWritten, 1, repairTraceLine(date, repair.rows)) : statusWritten
|
|
538
368
|
writeFileSync(abs, written)
|
|
369
|
+
// 记账口径同 status 径(记「落过盘」,回档不回退)——见 `statusBatchRecord` 写盘处的注释。
|
|
370
|
+
if (ctx?.agent) ctx.agent._batchWrites = (ctx.agent._batchWrites ?? 0) + 1 // §6.6 `wrote` 判据(写盘成功才增)
|
|
539
371
|
onWritten?.(ctx?.agent ?? {}, abs)
|
|
540
|
-
// 收口重锚(§6.2 · C · AC-M2-30):顺序位 = 全部拒因通过、§1
|
|
541
|
-
|
|
542
|
-
const reanchor = await
|
|
543
|
-
|
|
372
|
+
// 收口重锚(§6.2 · C · AC-M2-30):顺序位 = 全部拒因通过、§1 状态行写盘**之后**——close 被拒 ⇒ 台账零写。
|
|
373
|
+
// 台账失败 ⇒ 用写前全文回滚档 + 抛拒(§2.17 写序;不可逆的一方排最后)。
|
|
374
|
+
const reanchor = await ledgerAfterRecordWrite({
|
|
375
|
+
side: "close", abs, src, run: () => reanchorOnClose(abs, ctx?.agent?.cwd, args?.completed, args?.closeEvidence, true),
|
|
376
|
+
})
|
|
377
|
+
return `batch: §1 status line → 「已收口 ${date}」 — the record is frozen: append is refused from now on, and status is refused except the reopen conjunction (§1 → 进行中 with a note) (整档冻结;改 = 新批新档; §6 内容与台账核销仍走既有通道).${gateReceiptLine(gate)}${changedSurfaceReceiptLine(gate?.changedSurface)}${designTokensReceiptLine(designTokens)}${repairReceiptLine(repair.repair ? { rows: repair.rows, date } : null)}${reanchorReceiptLine(reanchor)}${newDebtReasonReceiptLine(reanchor)}${consistencyReceiptLine(await consistencyOf(abs, ctx?.agent?.cwd))}`
|
|
544
378
|
}
|
|
545
379
|
|
|
546
380
|
// ─── 收口自动消费本批设计凭证(DESIGN-TOKEN-SETTLEMENT §10——单源,close ∥ status 两通路同调)──
|
|
547
381
|
|
|
548
|
-
/** 「留槽无归属」枚数(§10
|
|
549
|
-
*
|
|
550
|
-
* (旧槽不猜归属——KD-BG4)。 */
|
|
382
|
+
/** 「留槽无归属」枚数(§10 观测量):并集视图里在旁列**无归属行**的槽数——含过期项(清点面照列;过期槽
|
|
383
|
+
* 同样撑开写门,正是敞口本身)。只认旁列:注册表反查是显示面兜底、不是消费判据(旧槽不猜归属——KD-BG4)。 */
|
|
551
384
|
function unattributedSlotCount(agent, batches) {
|
|
552
385
|
let n = 0
|
|
553
386
|
for (const id of unionSlots(agent).keys()) if (!batches.has(id)) n++
|
|
@@ -556,14 +389,11 @@ function unattributedSlotCount(agent, batches) {
|
|
|
556
389
|
|
|
557
390
|
/**
|
|
558
391
|
* 收口自动消费(DESIGN-TOKEN-SETTLEMENT §10——两通路共调本函数,不复制逻辑)。四步:
|
|
559
|
-
* ①非工程模式 ⇒ no-op
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
* (KD-BG6:不新写落盘 / 回滚逻辑,否则同一份语义写第二遍、两处必漂)。
|
|
565
|
-
* **失败语义**:④抛 ⇒ **原样上抛**(消费核已把内存槽整体回滚)⇒ 调用方被拒、档零字节变、可重试——
|
|
566
|
-
* 「已收口而凭证仍在」正是本节要消掉的窗口,不把它降级成一句回执。
|
|
392
|
+
* ①非工程模式 ⇒ no-op(普通模式批无设计槽);②反查 = 内存 Map ∪ 槽文件旁列(**严格读**——旁列读不到即抛
|
|
393
|
+
* ⇒ close 被拒,「没有」= 空集不抛)取该 `abs` 名下的 designId 集;③空集 ⇒ no-op(重开后再 close 走这条);
|
|
394
|
+
* ④调既有 `executeConsumeDesignAction({ designIds })`——单次落盘 + 内存整体回滚 + 逐枚回执全复用。
|
|
395
|
+
* **失败语义**:④抛 ⇒ **原样上抛**(消费核已把内存槽整体回滚)⇒ 调用方被拒、档零字节变、可重试。
|
|
396
|
+
* `§3` 状态词自 2026-10-27 起 = `评审通过`,本函数**零改**——凭证消费的判据是批次归属,不是评审词面。
|
|
567
397
|
* @param {object} agent — 含 `config.agent.engineering` 与槽状态图
|
|
568
398
|
* @param {string} abs — 本批批档绝对路径(收口目标,`pickTarget` 解析所得)
|
|
569
399
|
* @returns {{consumed: number, unattributed: number}|null} 消费枚数 ∥ 留槽无归属枚数;`null` = no-op(非工程模式)
|
|
@@ -576,50 +406,89 @@ export function consumeBatchDesignTokens(agent, abs) {
|
|
|
576
406
|
.filter(([, b]) => typeof b === "string" && batchPathKey(b) === target)
|
|
577
407
|
.map(([id]) => id)
|
|
578
408
|
if (ids.length === 0) return { consumed: 0, unattributed: unattributedSlotCount(agent, batches) }
|
|
579
|
-
const held = unionSlots(agent)
|
|
409
|
+
const held = unionSlots(agent)
|
|
580
410
|
const consumed = ids.filter((id) => held.has(id)).length
|
|
581
411
|
executeConsumeDesignAction({ designIds: ids }, { agent })
|
|
582
412
|
return { consumed, unattributed: unattributedSlotCount(agent, batches) }
|
|
583
413
|
}
|
|
584
414
|
|
|
585
|
-
/** 收口回执的凭证段(§10 回执形:单列 `[design tokens]`
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
function designTokensReceiptLine(result) {
|
|
415
|
+
/** 收口回执的凭证段(§10 回执形:单列 `[design tokens]` 一行);`null`(普通模式 no-op)⇒ 无该段。
|
|
416
|
+
* 导出面 = 第三条收口边(`batch-supersede.mjs`)同用:凭证消费是「从未实施」也**不豁免**的环节。
|
|
417
|
+
* 单源在此——两个入口各写一句就会成为两个格式。 */
|
|
418
|
+
export function designTokensReceiptLine(result) {
|
|
589
419
|
if (!result) return ""
|
|
590
420
|
return `\n[design tokens] 消费 ${result.consumed} 枚 · 留槽无归属 ${result.unattributed} 枚`
|
|
591
421
|
}
|
|
592
422
|
|
|
593
|
-
/**
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
*
|
|
599
|
-
*
|
|
600
|
-
|
|
601
|
-
async function
|
|
423
|
+
/**
|
|
424
|
+
* 写序第 4 步(设计档 §2.17「写序」):**档先写、台账后写,台账失败即用写前全文补偿回滚档**——
|
|
425
|
+
* 不可逆的一方(核销)排最后。`run()` 返回的那一笔台账写失败(返回形 `failed`)⇒ 覆盖回写前字节并抛拒;
|
|
426
|
+
* **补偿本身也失败** ⇒ 出那一侧的第二条串(不得复用第一条——第一条声称已回滚,此时事实相反),
|
|
427
|
+
* 它是唯一允许半状态成立的时点,且必须喊出来(含 `batch({action:"check"})` 指路)。
|
|
428
|
+
* 两条串的单源:收口侧 = `batch-closeout.mjs`,重开侧 = `batch-reopen.mjs`。
|
|
429
|
+
* 导出面 = 第三条收口边(`batch-supersede.mjs`)同调:写序与失败补偿属「不豁免」的环节(§4.18-D「保留门与写序」)。
|
|
430
|
+
*/
|
|
431
|
+
export async function ledgerAfterRecordWrite({ side, abs, src, run }) {
|
|
432
|
+
const result = await run()
|
|
433
|
+
if (!result?.failed) return result
|
|
434
|
+
try {
|
|
435
|
+
writeFileSync(abs, src)
|
|
436
|
+
} catch (rollbackErr) {
|
|
437
|
+
const rollbackCause = String(rollbackErr?.message ?? rollbackErr)
|
|
438
|
+
throw new Error(side === "close"
|
|
439
|
+
? closeHalfStateError(abs, result.failed, rollbackCause)
|
|
440
|
+
: reopenHalfStateError(abs, result.failed, rollbackCause))
|
|
441
|
+
}
|
|
442
|
+
throw new Error(side === "close" ? closeLedgerFailedError(result.failed) : reopenLedgerFailedError(result.failed))
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** 收口重锚(设计档 §6.2 · C · §2.7 分流)——收口两条通路共调(同一单源,不复制逻辑);写入单源 =
|
|
446
|
+
* `ledgerReanchorBatch`(本档只供 `cwd` 基准与完成清单;工具层零 SQL)。
|
|
447
|
+
* `cwd` = **批档所属项目根** = `resolveLedgerRoot(dirname(<batchDoc>), boundary)?.root`——**不用会话锚**
|
|
448
|
+
* (多根工作区锚会收到别的项目根 ⇒ 选行零命中 ⇒ 唯一的机器写静默失效)。
|
|
449
|
+
* `boundary` = 上溯上界 = **会话锚**(**必传**——缺值即当场失败,回执以 `failed` 点名;不落进程 cwd)。无根 ⇒ 传 `null`(核心不取行、不重锚,`failed` 点名)。
|
|
450
|
+
* `batch` = 项目根相对路径(复启句的 `<批名>` 即其文件部分)。失败**不抛**(本档的 `failed` 由调用方
|
|
451
|
+
* `ledgerAfterRecordWrite` 转成「回滚档 + 抛拒」——收口要么一起成、要么一个都不成)。
|
|
452
|
+
* `requireAllInFlight` = 完成清单那一条元判据(**无缺省**,§4.18-D「③ 的实现面」):正常两路传 `true`,
|
|
453
|
+
* 被取代的收口传 `false`(未点名的在途行走退回边)。
|
|
454
|
+
* **返回形** = `ledgerReanchorBatch` 返回形 + `newDebtReasons`(本批行中 `evidence` 带 `新事理由:` 前缀者;
|
|
455
|
+
* 取不到本批行 ⇒ 空集)——**只取不写**,格式化成回执段的是 `newDebtReasonReceiptLine`。 */
|
|
456
|
+
export async function reanchorOnClose(abs, boundary, completed, closeEvidence, requireAllInFlight) {
|
|
602
457
|
try {
|
|
603
|
-
const { ledgerReanchorBatch, resolveLedgerRoot } = await import("../ledger.mjs") // 动态 import:ledger-db 静态引 node:sqlite(W8 契约②)
|
|
458
|
+
const { ledgerBatchRows, ledgerReanchorBatch, resolveLedgerRoot } = await import("../ledger.mjs") // 动态 import:ledger-db 静态引 node:sqlite(W8 契约②)
|
|
604
459
|
const root = resolveLedgerRoot(dirname(abs), boundary)?.root ?? null
|
|
605
460
|
// 句内路径统一正斜杠(与 `task_book` 列值同形——`<批名>` 是给人读的事实句,不是平台路径)
|
|
606
|
-
|
|
461
|
+
const batch = root ? relative(root, abs).replace(/\\/g, "/") : abs
|
|
462
|
+
const result = ledgerReanchorBatch({ cwd: root, batch, boundary, completed, closeEvidence, requireAllInFlight })
|
|
463
|
+
// 新事理由读面(设计档 §6.3):本批行(任意状态)中 `evidence` 带 `新事理由:` 前缀者随返回形带回——
|
|
464
|
+
// **只引不写**(行改写语义零动);取不到本批行 ⇒ 空集(不出该段、收口不被否决,同 `failed` 降级口径)
|
|
465
|
+
let newDebtReasons = []
|
|
466
|
+
try {
|
|
467
|
+
newDebtReasons = ledgerBatchRows({ cwd: root, batch, boundary })
|
|
468
|
+
.map((r) => ({ id: Number(r.id), reason: newDebtReasonOf(r.evidence) }))
|
|
469
|
+
.filter((r) => r.reason !== null)
|
|
470
|
+
} catch { newDebtReasons = [] }
|
|
471
|
+
return { ...result, newDebtReasons }
|
|
607
472
|
} catch (e) {
|
|
608
473
|
// 非预期异常(模块加载失败 ∥ 根推导内读声明抛)同样不得否决收口——降为同一返回形(台账零写)
|
|
609
|
-
return { batch: abs,
|
|
474
|
+
return { batch: abs, settled: [], conditioned: [], alreadyAnchored: [], failed: String(e?.message ?? e), newDebtReasons: [] }
|
|
610
475
|
}
|
|
611
476
|
}
|
|
612
477
|
|
|
613
|
-
/**
|
|
614
|
-
*
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
478
|
+
/**
|
|
479
|
+
* check——半状态查询(设计档 §2.17「暴露面两处」第一条;**只读动作,depth-0 only**):回执逐行打印
|
|
480
|
+
* `batchLedgerConsistency` 的读数——`record` 三态 ∥ 本批行集 ∥ 半状态五类与各自出路 ∥ `consistent`。
|
|
481
|
+
* 这就是「明确的半状态查询面」:人不必靠一次失败的写去猜,半状态可查、可照着出路恢复。
|
|
482
|
+
* **零写**:不改行、不改档(半状态自动修复被拒——修复要走人裁的那一步:重开 ∥ 收口 ∥ 改指针)。
|
|
483
|
+
* @returns {Promise<string>} 回执(含 `[ledger consistency]` 行)
|
|
484
|
+
*/
|
|
485
|
+
export async function checkBatchRecord({ args, ctx, review, pickTarget }) {
|
|
486
|
+
if (review || !isDepthZero(ctx)) {
|
|
487
|
+
throw new Error("batch: check is main-agent-only — the half-state query face is depth-0 only (eng sub-agents and design reviews are refused).")
|
|
488
|
+
}
|
|
489
|
+
const abs = pickTarget(args?.path)
|
|
490
|
+
const { batchLedgerConsistency, resolveLedgerRoot } = await import("../ledger.mjs")
|
|
491
|
+
const root = resolveLedgerRoot(dirname(abs), ctx?.agent?.cwd)?.root ?? null
|
|
492
|
+
const batch = root ? relative(root, abs).replace(/\\/g, "/") : abs
|
|
493
|
+
return checkReceipt(batchLedgerConsistency({ cwd: root, batch, boundary: ctx?.agent?.cwd }), abs)
|
|
625
494
|
}
|