@thincoder/core 0.11.1 → 0.11.3
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 +64 -2
- package/advisor/compaction.mjs +7 -5
- package/advisor/convergence.mjs +34 -3
- package/advisor/history.mjs +24 -11
- package/advisor/loop.mjs +49 -12
- package/advisor/messages.mjs +114 -33
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +24 -10
- package/advisor.mjs +36 -46
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/chat-call.mjs +14 -9
- package/agent/completion.mjs +70 -41
- package/agent/continue-decision.mjs +14 -8
- package/agent/digest-account.mjs +133 -59
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +10 -4
- package/agent/family-tools.mjs +37 -23
- package/agent/helpers.mjs +139 -73
- package/agent/image-heal.mjs +18 -4
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +36 -35
- package/agent/record-results.mjs +39 -7
- package/agent/run-stages.mjs +132 -52
- package/agent/run-start.mjs +150 -78
- package/agent/setup-reminders.mjs +194 -91
- package/agent/setup.mjs +219 -140
- package/agent/spawn-child.mjs +40 -3
- package/agent/suspension.mjs +43 -15
- package/agent/timers.mjs +9 -4
- package/agent/turn-domain-text.mjs +105 -0
- package/agent/turn-loop.mjs +84 -27
- package/agent/turn-projection.mjs +286 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +163 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +35 -172
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +37 -48
- package/agent-tools/async-discard.mjs +7 -2
- package/agent-tools/async-settle.mjs +18 -12
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +5 -2
- package/agent-tools/batch-closeout.mjs +223 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +240 -20
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +197 -48
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-read.mjs +151 -4
- 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 +459 -0
- package/agent-tools/batch-skeleton.mjs +196 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +214 -0
- package/agent-tools/batch.mjs +192 -439
- package/agent-tools/browser-async.mjs +5 -2
- package/agent-tools/consult.mjs +17 -11
- package/agent-tools/context.mjs +76 -33
- 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/digest-budget.mjs +10 -9
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +12 -12
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/goal.mjs +5 -2
- package/agent-tools/judge-domain.mjs +347 -0
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/parent-channel.mjs +6 -3
- package/agent-tools/plan.mjs +11 -10
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +19 -6
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/skill.mjs +7 -8
- package/agent-tools/spawn-gates.mjs +14 -24
- package/agent-tools/ssh-session.mjs +8 -5
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +1 -1
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-actions.mjs +2 -2
- package/agent-tools/subagent-async.mjs +19 -17
- 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 +13 -13
- package/agent-tools/subagent-spawn.mjs +92 -112
- package/agent-tools/subagent.mjs +16 -28
- package/agent-tools/task.mjs +0 -8
- 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 +26 -7
- package/attachments.mjs +3 -3
- package/auto-think.mjs +5 -2
- 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/compaction-work-state.mjs +230 -0
- package/compress-form.mjs +41 -6
- package/config-defaults.mjs +7 -3
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +110 -110
- package/context-degrade.mjs +93 -34
- package/context-echo.mjs +6 -15
- package/context-push.mjs +328 -31
- package/context.mjs +298 -170
- package/conventions.mjs +11 -9
- package/declaration.mjs +126 -22
- 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/escape.mjs +6 -5
- package/explore-distill.mjs +41 -8
- package/generate-title.mjs +10 -1
- 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 +10 -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 +121 -62
- package/ledger-write-ops.mjs +162 -46
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/docs.mjs +51 -15
- package/memory/file-list.mjs +6 -0
- package/memory/schema.mjs +2 -2
- package/model-specs.mjs +87 -21
- package/origin-guard.mjs +190 -0
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +114 -2
- package/prompt-overlays.mjs +21 -11
- package/prompts/advisor-design.md +96 -36
- package/prompts/advisor-round1.md +48 -4
- package/prompts/advisor-round2.md +54 -10
- package/prompts/advisor-round3.md +53 -9
- package/prompts/common.md +99 -434
- package/prompts/consult-base.md +7 -4
- package/prompts/discipline-engineering.md +504 -295
- package/prompts/discipline-normal.md +106 -281
- package/prompts/knowledge/business-gates.md +30 -0
- package/prompts/knowledge/decision-quality.md +21 -0
- package/prompts/knowledge/doc-lookup.md +30 -0
- package/prompts/knowledge/document-writing.md +33 -0
- package/prompts/knowledge/documentation-evaluation.md +48 -0
- package/prompts/knowledge/evidence-discipline.md +38 -0
- package/prompts/knowledge/normal-coding-workflow.md +110 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +124 -0
- package/prompts/knowledge/normal-work-management.md +60 -0
- package/prompts/knowledge/product-security.md +28 -0
- package/prompts/knowledge/project-records.md +73 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +17 -0
- package/prompts/knowledge/tool-bash.md +48 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +19 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +20 -0
- package/prompts/knowledge/tool-batch-review.md +18 -0
- package/prompts/knowledge/tool-batch.md +94 -0
- package/prompts/knowledge/tool-browser.md +68 -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 +21 -0
- package/prompts/knowledge/tool-doc-check.md +71 -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 +41 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +21 -0
- package/prompts/knowledge/tool-fetch.md +18 -0
- package/prompts/knowledge/tool-file-ops.md +21 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +21 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +17 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +21 -0
- package/prompts/knowledge/tool-hashline-edit.md +16 -0
- package/prompts/knowledge/tool-insert-after.md +17 -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 +28 -0
- package/prompts/knowledge/tool-ledger.md +46 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +15 -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 +34 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +19 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +102 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +5 -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 +35 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +22 -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 +17 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +74 -0
- package/prompts/knowledge/tool-subagent.md +57 -0
- package/prompts/knowledge/tool-task.md +14 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +15 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +16 -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 +12 -0
- package/prompts/knowledge/upstream-protocol.md +45 -0
- package/prompts/persona-coder.md +1 -3
- package/prompts/persona-eng-coder.md +24 -6
- package/prompts/persona-eng-designer.md +150 -171
- package/prompts/persona-engineering.md +531 -442
- package/prompts/persona-explore.md +1 -3
- package/prompts/persona-normal.md +17 -9
- package/prompts/persona-plan.md +5 -3
- package/prompts/persona-tester.md +0 -2
- package/prompts/subagent-base.md +2 -2
- package/provider/anthropic.mjs +10 -6
- package/provider/core.mjs +8 -5
- package/provider/errors.mjs +63 -4
- package/provider/google.mjs +29 -10
- package/provider/reasoning-echo.mjs +16 -0
- package/provider/responses.mjs +7 -3
- package/provider/sse.mjs +11 -6
- package/provider-flows.mjs +2 -2
- package/rules.mjs +11 -10
- 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 +131 -42
- package/session-slot-write.mjs +38 -6
- package/session.mjs +30 -11
- package/shell-identity.mjs +129 -22
- package/skip-dirs.mjs +26 -2
- package/team-ledger.mjs +34 -30
- package/text-budget.mjs +1 -1
- package/think-off.mjs +27 -0
- package/token-ttl.mjs +74 -5
- package/token-window.mjs +371 -47
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -43
- 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 +54 -9
- 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 +3 -3
- package/tools/file.mjs +28 -14
- package/tools/git.mjs +36 -21
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +5 -3
- package/tools/patch.mjs +124 -44
- package/tools/process-doc-mark.mjs +33 -4
- package/tools/repomap.mjs +25 -3
- package/tools/search.mjs +74 -26
- package/tools/shared.mjs +29 -27
- package/tools/ssh.mjs +5 -5
- package/tools/tree.mjs +32 -10
- package/tools/web-deepseek.mjs +1 -1
- package/tools/web.mjs +2 -2
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +243 -0
- package/doc-check/anchors.mjs +0 -235
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* agent-tools/batch-lifecycle.mjs — 批次档生命周期 action 面(KD-4 拆分中段;2026-10-27 第二次拆分)。
|
|
3
3
|
*
|
|
4
|
-
* 本档只留 **status / close 两条 action
|
|
5
|
-
* `skeleton ← closeout ← bind ← reopen ← lifecycle`):
|
|
4
|
+
* 本档只留 **status / close 两条 action 与在飞批定位**。四条支线住各自的新档(依赖单向:
|
|
5
|
+
* `skeleton ← closeout ← ledger-view ← bind ← reopen ← lifecycle`):
|
|
6
6
|
* - 建档 = 建台账行 → `batch-ledger-bind.mjs`(§2.4);
|
|
7
|
-
* -
|
|
7
|
+
* - 收口判据与重锚回执 → `batch-closeout.mjs`;
|
|
8
|
+
* - 台账侧只读视图(一致性读数 ¶ 收口预检 ¶ 补关分流)→ `batch-ledger-view.mjs`(P2-5 拆出);
|
|
8
9
|
* - 重开写盘 + 台账回收 → `batch-reopen.mjs`(§2.13)。
|
|
9
10
|
*
|
|
10
11
|
* 判定字面全部单源自 batch-skeleton.mjs(SEGMENT_BY_ROLE / STATUS_WORDS /
|
|
@@ -13,20 +14,31 @@
|
|
|
13
14
|
* `resolveBatchCreatePath`——住 `batch-paths.mjs`)与 #84 记账缝住 batch.mjs 主档——本档不回 import 主档(防环)。
|
|
14
15
|
*
|
|
15
16
|
* 身份判据(D-BR17/D-BR18/D-BR21):主 agent 的工具调用 ctx 带 `depth === 0`(dispatch 装配);
|
|
16
|
-
* eng 子代理 `ctx.depth > 0`;评审实例 ctx 无 depth 但工具以 `review: true`
|
|
17
|
+
* eng 子代理 `ctx.depth > 0`;评审实例 ctx 无 depth 但工具以 `review: true` 绑定(`reviewTrack` = 评审轨——
|
|
18
|
+
* 工程**设计轨**的 `§3` 只由结算写、本面拒,§4.4)。create/close
|
|
17
19
|
* 仅 depth-0 放行(BR-19/BR-24);status 写域 = 调用者自己段(eng-designer → §2 · 评审 → §3 ·
|
|
18
20
|
* eng-coder → §5 · coder → §5【普通模式分支增表】· 主 agent → 工程 §1 ∥ 普通 §1/§2/§5【取段——§4.16】)。
|
|
19
21
|
*
|
|
20
22
|
* 四道门(2026-10-27 · 设计档 §2.6):写锁 = `agent/write-gate.mjs`(不在本档);§5 写入门 =
|
|
21
23
|
* `batch.mjs` append 面;**收口门** = `batch-closeout.mjs`(链门 + §3 状态词臂 + 单测档门 + 机检门);
|
|
22
|
-
*
|
|
24
|
+
* 核销工作证据门 = `ledger-close-proof.mjs`(只判应用本笔后的 evidence 非空白)。
|
|
23
25
|
*
|
|
24
26
|
* 收口重锚(§6.2 · C · AC-M2-30):收口有两条通路——`close` ∥ `status` 写 §1「已收口」——两路都冻结档、
|
|
25
27
|
* 都让批「收口了」,故**两路同调**单源 `reanchorOnClose`(本档下方),调点均在状态行写盘之后。
|
|
26
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]`,台账行零改写。
|
|
27
36
|
*
|
|
28
37
|
* 重开回收(§2.13 · E13):`status` 写 §1 `进行中` 而前态 `closed` ⇒ 重开;写盘后同调 `reclaimOnReopen`
|
|
29
|
-
* (`待核销 →
|
|
38
|
+
* (`待核销 → 在途`),失败同样回滚档 + 抛拒(「档已开、行仍 待核销」会让写锁拒每一笔写盘)。
|
|
39
|
+
* **其余 status 用法零台账写**——尤其「§3 写评审通过」不动台账。
|
|
40
|
+
* 两路回执末尾**恒带一行** `[ledger consistency]`(半状态查询面单源 = `batchLedgerConsistency`);
|
|
41
|
+
* `check` action 是同一读数的完整打印面。
|
|
30
42
|
*
|
|
31
43
|
* 收口自动消费本批设计凭证(DESIGN-TOKEN-SETTLEMENT §10 · 2026-10-26):同一两路在**写状态行之前**
|
|
32
44
|
* 调 `consumeBatchDesignTokens`(判据 = 槽的批次归属旁列;口径单源见该档 §10)。消费失败 ⇒ 原样上抛、
|
|
@@ -37,12 +49,14 @@ import { dirname, relative, resolve } from "node:path"
|
|
|
37
49
|
|
|
38
50
|
import {
|
|
39
51
|
DEPTH0_SEGMENTS, SEGMENT_BY_ROLE, SEGMENT_BY_ROLE_NORMAL, STATUS_WORDS, TEMPLATE_PLACEHOLDERS,
|
|
40
|
-
findPlaceholderResidue, placeholderResidueError, readBatchStatusLine, sectionHasStatusLine,
|
|
41
|
-
updateSectionStatusLine,
|
|
52
|
+
findPlaceholderResidue, placeholderResidueError, readBatchStatusLine, reviewWritableSegment, sectionHasStatusLine,
|
|
53
|
+
sectionThreeDesignTrackError, updateSectionStatusLine, zoneStatusCount,
|
|
54
|
+
GO_AHEAD_REASON_CLOSE, goAheadEndLine, goAheadReceiptLine, readGoAheadState,
|
|
42
55
|
} from "./batch-skeleton.mjs"
|
|
43
|
-
import { assertCloseoutGates, newDebtReasonOf, newDebtReasonReceiptLine, readCloseoutSource, reanchorReceiptLine } from "./batch-closeout.mjs"
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
56
|
+
import { assertCloseoutGates, changedSurfaceReceiptLine, checkReceipt, closeHalfStateError, closeLedgerFailedError, consistencyReceiptLine, newDebtReasonOf, newDebtReasonReceiptLine, readCloseoutSource, reanchorReceiptLine, repairReceiptLine, repairTraceLine } from "./batch-closeout.mjs"
|
|
57
|
+
import { assertCloseDisposition, consistencyOf, repairDecisionOf } from "./batch-ledger-view.mjs"
|
|
58
|
+
import { appendLineToSection, assertSingleLineNote, reclaimOnReopen, reopenHalfStateError, reopenLedgerFailedError, reopenReasonError, reopenReceiptLine, rewriteAsReopen, todayLocal } from "./batch-reopen.mjs"
|
|
59
|
+
import { gateReceiptLine } from "./batch-gate.mjs"
|
|
46
60
|
import { batchPathKey, executeConsumeDesignAction, unionBatches, unionSlots } from "./design-slots.mjs"
|
|
47
61
|
|
|
48
62
|
/** 可读文件判据(存在且为文件——目录/缺失同判不可读;与主档同名 helper 同型——KD-4 单向依赖下各自持有,
|
|
@@ -56,14 +70,17 @@ function isDepthZero(ctx) {
|
|
|
56
70
|
return ctx?.depth === 0
|
|
57
71
|
}
|
|
58
72
|
|
|
59
|
-
/** 段号解析(`§2` / `2` / `§2 批次任务` 均可;无法解析 → null——与主档 append 面同型三行谓词)。
|
|
60
|
-
|
|
73
|
+
/** 段号解析(`§2` / `2` / `§2 批次任务` 均可;无法解析 → null——与主档 append 面同型三行谓词)。
|
|
74
|
+
* **导出面** = 只读 `read` 动作(`batch-read.mjs`)取用同一条判据——三行谓词已有两份副本,
|
|
75
|
+
* `read` 取其一而不造第三种(`BATCH-RECORD.md` §4.25「段号与 `offset` 的取法」)。 */
|
|
76
|
+
export function segmentNumber(raw) {
|
|
61
77
|
const m = /^§?\s*(\d+)/.exec(String(raw ?? "").trim())
|
|
62
78
|
return m ? Number(m[1]) : null
|
|
63
79
|
}
|
|
64
80
|
|
|
65
|
-
/** main-agent-only 门(BR-19/BR-24):close 仅 depth-0 放行(eng 子代理 / 评审皆拒)。
|
|
66
|
-
|
|
81
|
+
/** main-agent-only 门(BR-19/BR-24):close / supersede 仅 depth-0 放行(eng 子代理 / 评审皆拒)。
|
|
82
|
+
* 导出面 = `batch-supersede.mjs`(第三条收口边同一身份门——同一条判据只有这一个函数)。 */
|
|
83
|
+
export function assertMainAgentOnly(ctx, action, review) {
|
|
67
84
|
if (review || !isDepthZero(ctx)) {
|
|
68
85
|
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).`)
|
|
69
86
|
}
|
|
@@ -72,16 +89,16 @@ function assertMainAgentOnly(ctx, action, review) {
|
|
|
72
89
|
/** 递归收集目录下全部 `*.md`(#369 · KD-4:显式嵌套路径为合法 create 面 ⇒ 顶层平扫会欠计 ⇒ 复数情形
|
|
73
90
|
* 漏判、默认定位可落非预期档)。只认真目录(symlink 不入,防环);单目录读错按无候选处理(尽力面)。
|
|
74
91
|
* **转导出**(read-data-interface 批——`batch/list` 读面文件集同源复用;零行为变)。
|
|
75
|
-
*
|
|
76
|
-
* `
|
|
77
|
-
*
|
|
92
|
+
* **只收批档**(`*.md` 且不以点开头——两条判):其它扩展名(与批档同目录并存的同名单测档 `<批档名>.test.mjs`)
|
|
93
|
+
* 与隐藏档都不是批档;只有「点开头」一条挡不住那份测档,挡住它的是扩展名那一条(`docs/core/design/DOC-CHECK.md` §2.10.2)。
|
|
94
|
+
* **不为任何残档设支**:盘上没有片段档这回事——两条判据描述的是「什么算批档」,不是「谁要排掉」。 */
|
|
78
95
|
export function collectMarkdownFiles(dir, out = []) {
|
|
79
96
|
let entries = []
|
|
80
97
|
try { entries = readdirSync(dir, { withFileTypes: true }) } catch { return out }
|
|
81
98
|
for (const e of entries) {
|
|
82
99
|
const abs = resolve(dir, e.name)
|
|
83
100
|
if (e.isDirectory()) collectMarkdownFiles(abs, out)
|
|
84
|
-
else if (e.isFile() && e.name.endsWith(".md") && !e.name.startsWith(
|
|
101
|
+
else if (e.isFile() && e.name.endsWith(".md") && !e.name.startsWith(".")) out.push(abs)
|
|
85
102
|
}
|
|
86
103
|
return out
|
|
87
104
|
}
|
|
@@ -119,7 +136,7 @@ export function findInFlightBatch(cwd, bases) {
|
|
|
119
136
|
* append 面同字面(「已收口档不回改」/「状态行不可解析或缺失」)。
|
|
120
137
|
* unknown 串多两句:段级状态行的取值区已收窄到 §1 **段头区**,行落在区外(段体 / 轮次块)就读不成值
|
|
121
138
|
* ——拒文点名这条终态与唯一出路(把行移进段头区),否则被卡住的人在界面上无路可走(设计档 §5 R26)。 */
|
|
122
|
-
function assertGateOpen(src) {
|
|
139
|
+
export function assertGateOpen(src) {
|
|
123
140
|
const gate = readBatchStatusLine(src)
|
|
124
141
|
if (gate === "closed") {
|
|
125
142
|
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.")
|
|
@@ -129,6 +146,23 @@ function assertGateOpen(src) {
|
|
|
129
146
|
}
|
|
130
147
|
}
|
|
131
148
|
|
|
149
|
+
/**
|
|
150
|
+
* **收口落行**(`BATCH-RECORD.md` §4.24;设计 `E8`「收口自己落这条行」):`status` 写 §1「已收口」∥ `close` 两条
|
|
151
|
+
* 收口通路**同源调本助手**,在该笔里给 §1 段尾追加一条
|
|
152
|
+
* `- **自动推进**:未授权 · 结束原因 = 该批收口 · 时间 = <日期>`。三条纪律:
|
|
153
|
+
* - 末条已是 `未授权` ⇒ 零写(幂等)。这条行**只会把授权往下压**,永远写不出 `已授权`——工具在这里只是执行
|
|
154
|
+
* 需求已写明的失效条件(该批收口),不是第二个授权写者;
|
|
155
|
+
* - 两路必须同调:不同调就会有一路收口后盘上还写着 `已授权`;
|
|
156
|
+
* - 落点 = §1 段尾追加一行(既有拼接面 `appendLineToSection`,既有字节零变)。
|
|
157
|
+
* @param {string} src — 状态行已改写的全文
|
|
158
|
+
* @param {string} date — 日期戳(`todayLocal()`——日期口径仍只一处)
|
|
159
|
+
* @returns {string} 写盘全文(零写 = 逐字原样)
|
|
160
|
+
*/
|
|
161
|
+
function appendGoAheadRevokedLine(src, date) {
|
|
162
|
+
if (readGoAheadState(src) === "none") return src
|
|
163
|
+
return appendLineToSection(src, 1, `- **自动推进**:未授权 · 结束原因 = ${GO_AHEAD_REASON_CLOSE} · 时间 = ${date}`)
|
|
164
|
+
}
|
|
165
|
+
|
|
132
166
|
/** 全词表去重并集(各段项——value 命中判据与 note 零命判据共用同一口径)。 */
|
|
133
167
|
function statusVocabulary() {
|
|
134
168
|
return [...new Set(Object.values(STATUS_WORDS).flatMap((w) => Object.values(w)))]
|
|
@@ -180,6 +214,17 @@ function assertStatusNote(note) {
|
|
|
180
214
|
}
|
|
181
215
|
}
|
|
182
216
|
|
|
217
|
+
/** 拒串:目标段段头区内**两条以上**状态行(§4.21.4 写面第二道——让这个歧义状态不再产生)。
|
|
218
|
+
* 修复句按段分两支:非 §1 = 先 `edit` 删多余那条(区内回到 1 ⇒ 可读行重新出现)再 `status` 改写余下那条
|
|
219
|
+
* (记录全程 open,通道可达);§1 = 主 agent 普通文档写(`edit` / `status` 在不可解析面上全部 fail-closed,
|
|
220
|
+
* 不许借重开绕)。顺序不能反:歧义时 `status` 拒,而 `edit` 不读该段的词面。 */
|
|
221
|
+
function STATUS_LINE_AMBIGUOUS_ERROR(seg, count) {
|
|
222
|
+
const repair = Number(seg) === 1
|
|
223
|
+
? "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."
|
|
224
|
+
: `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.`
|
|
225
|
+
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}`
|
|
226
|
+
}
|
|
227
|
+
|
|
183
228
|
/**
|
|
184
229
|
* status——状态行流转(§4.12,段属主;§4.16 模式感知)。写域 = 调用者自己段内 `**状态行**:`
|
|
185
230
|
* 行(评审 → §3 · eng-designer → §2 · eng-coder / coder → §5 · 主 agent:工程 §1 ∥ 普通
|
|
@@ -187,18 +232,28 @@ function assertStatusNote(note) {
|
|
|
187
232
|
* 字段(落状态行括注);冻结真值不变(gate 只读 §1)。
|
|
188
233
|
* path 参数 = 仅 depth-0(D-BR21)——子代理/评审传 path ⇒ 拒。F11-C 挂点 = 写盘前(档头结构行含骨架
|
|
189
234
|
* 死占位 ⇒ 拒;段体引用豁免;close 不拦——收口是主 agent 终态动作)。
|
|
235
|
+
* **段头区歧义拒写**(§4.21.4 写面第二道):目标段段头区两条以上状态行 ⇒ 拒并给修复句(非 §1 = 先
|
|
236
|
+
* `edit` 删多余那条再 `status`;§1 = 普通文档写)——位次 = 读档之后、重开合取之前(两路都是拒)。
|
|
190
237
|
* **收口第二通路**:值余核 = §1「已收口」时本 action 同样收口(收口门 + 单测档门 + 机检门 + 冻结与
|
|
191
|
-
* close 同序)⇒ 状态行写盘后同调 `reanchorOnClose`,回执携同一 `[ledger reanchor]`
|
|
238
|
+
* close 同序)⇒ 状态行写盘后同调 `reanchorOnClose`,回执携同一 `[ledger reanchor]` 段;`completed` 与
|
|
239
|
+
* `closeEvidence` 与 `close` 同两条必填,台账失败同样回滚档并抛拒。与 close 同门同分派:全归档批走补关
|
|
240
|
+
* (§4.18-C,只绕开内容门与 §3 pass 臂,§1 段尾落一行 `**补关记录**`)。
|
|
192
241
|
* **重开径**(§4.18-B · §2.13):前态 closed ∧ 值 = 进行中 ∧ note 非空 ⇒ 重开;写盘后同调
|
|
193
|
-
* `reclaimOnReopen`(`待核销 → 在途`),回执携 `[ledger reopen]`
|
|
242
|
+
* `reclaimOnReopen`(`待核销 → 在途`),回执携 `[ledger reopen]` 段;回收失败 ⇒ 档回滚到冻结态并抛拒。
|
|
243
|
+
* **其余一切用法零台账写**;本 action 的回执末尾恒带一行 `[ledger consistency]`。
|
|
194
244
|
* @returns {Promise<string>} 成功消息
|
|
195
245
|
*/
|
|
196
|
-
export async function statusBatchRecord({ args, ctx, review, pickTarget, onWritten }) {
|
|
246
|
+
export async function statusBatchRecord({ args, ctx, review, reviewTrack, pickTarget, onWritten }) {
|
|
197
247
|
const depth0 = isDepthZero(ctx)
|
|
198
248
|
// 模式位执行期实读(§4.16——同款先例 = task.mjs execute 门;翻转即时生效——D-BR26)。
|
|
199
249
|
const engineering = !!ctx?.agent?.config?.agent?.engineering
|
|
200
|
-
|
|
250
|
+
// 段域与 append/edit 同一道闸、同一判据(§4.1 ∥ §4.4):工程**设计轨**的 `§3` 对一切工具通道只读——
|
|
251
|
+
// `status` 也在其中(那条路的状态行由结算随块同笔写,没有手写口)。判据单源 = `reviewWritableSegment`。
|
|
252
|
+
let seg = review
|
|
253
|
+
? reviewWritableSegment(engineering, reviewTrack)
|
|
254
|
+
: depth0 ? 1 : SEGMENT_BY_ROLE[ctx?.agent?._role] ?? (engineering ? null : SEGMENT_BY_ROLE_NORMAL[ctx?.agent?._role] ?? null)
|
|
201
255
|
if (seg === null) {
|
|
256
|
+
if (review) throw new Error(sectionThreeDesignTrackError("batch"))
|
|
202
257
|
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).")
|
|
203
258
|
}
|
|
204
259
|
// 段域判据(BR-22「eng-designer 对 §1 调 status ⇒ 段白名单拒」——镜像 append 面):
|
|
@@ -234,6 +289,10 @@ export async function statusBatchRecord({ args, ctx, review, pickTarget, onWritt
|
|
|
234
289
|
assertStatusValue(seg, value)
|
|
235
290
|
const abs = pickTarget(args?.path)
|
|
236
291
|
const src = readFileSync(abs, "utf8")
|
|
292
|
+
// 段头区状态行歧义(§4.21.4 写面第二道)——位次 = 读档之后、重开合取与冻结门之前(§1 歧义面拿到的
|
|
293
|
+
// 是「修法 = 普通文档写」这一句,比冻结门的「不可解析」更贴现场;两路都是拒)。
|
|
294
|
+
const zoneCount = zoneStatusCount(src, seg)
|
|
295
|
+
if (zoneCount > 1) throw new Error(STATUS_LINE_AMBIGUOUS_ERROR(seg, zoneCount))
|
|
237
296
|
// 重开合取(§4.18-B):段 = §1 · depth-0(非评审)· 值关键词 = 进行中 · 门态 = closed——
|
|
238
297
|
// 先于冻结拒写判定(门②的唯一例外);note = 重开理由(J4 缺则拒)。**台账联动只由本合取触发**。
|
|
239
298
|
const reopen = seg === 1 && depth0 && !review && stripDecorations(value) === STATUS_WORDS[1].open && readBatchStatusLine(src) === "closed"
|
|
@@ -249,25 +308,54 @@ export async function statusBatchRecord({ args, ctx, review, pickTarget, onWritt
|
|
|
249
308
|
// 重开(§4.18-B · §2.13):一次写盘、两处落笔(状态行改写 + §1 段尾追记行)——不跑收口门
|
|
250
309
|
//(值非「已收口」;写后门态 = open,后续 append/status 恢复放行)。
|
|
251
310
|
writeFileSync(abs, rewriteAsReopen(src, note))
|
|
311
|
+
// 记账口径同 status 径(记「落过盘」,回档不回退)——见 `statusBatchRecord` 写盘处的注释。
|
|
312
|
+
if (ctx?.agent) ctx.agent._batchWrites = (ctx.agent._batchWrites ?? 0) + 1 // §7.1 `wrote` 判据(写盘成功才增)
|
|
252
313
|
onWritten?.(ctx?.agent ?? {}, abs)
|
|
253
|
-
// ② 台账回收(§2.
|
|
254
|
-
|
|
255
|
-
|
|
314
|
+
// ② 台账回收(§2.17 重开步序 3–4 · 写序:档先写、台账后写):失败 ⇒ 用写前全文(冻结态)补偿回滚档,
|
|
315
|
+
// 然后抛拒——「档已开、行仍 待核销」的残态会让写锁拒每一笔写盘且没有任何提示,正是本批要消掉的那一形。
|
|
316
|
+
const reclaim = await ledgerAfterRecordWrite({
|
|
317
|
+
side: "reopen", abs, src, run: () => reclaimOnReopen(abs, ctx?.agent?.cwd),
|
|
318
|
+
})
|
|
319
|
+
// 回执附带当前授权行(§4.24):重开径不改授权行(它只改写状态行 + 追记行)⇒ 读写前全文同值。
|
|
320
|
+
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.${goAheadReceiptLine(src)}${reopenReceiptLine(reclaim)}${consistencyReceiptLine(await consistencyOf(abs, ctx?.agent?.cwd))}`
|
|
256
321
|
}
|
|
257
322
|
// 收口门(§2.6——链门 + §3 状态词臂 + 单测档门 + 机检门):本笔把 §1 写成「已收口」⇒ 四道同判。
|
|
258
323
|
// 段号守卫只写这一次(`STATUS_WORDS[1].closed` 只属 §1 项,`assertStatusValue` 亦拒他段该值)。
|
|
259
324
|
const closingValue = seg === 1 && stripDecorations(value) === STATUS_WORDS[1].closed
|
|
260
|
-
|
|
261
|
-
|
|
325
|
+
if (!closingValue && args?.completed !== undefined) {
|
|
326
|
+
throw new Error("batch: completed is accepted only by close or by status writing §1 已收口. Nothing was written.")
|
|
327
|
+
}
|
|
328
|
+
if (!closingValue && args?.closeEvidence !== undefined) {
|
|
329
|
+
throw new Error("batch: closeEvidence is accepted only by close or by status writing §1 已收口. Nothing was written.")
|
|
330
|
+
}
|
|
331
|
+
// 收口分流(§4.18-C):链门之前读一致性——全归档批走补关,其余走完整链门。
|
|
332
|
+
const repair = closingValue ? await repairDecisionOf(abs, ctx?.agent?.cwd) : null
|
|
333
|
+
const gate = closingValue ? assertCloseoutGates({ abs, cwd: ctx?.agent?.cwd, agent: ctx?.agent ?? {}, src, action: "status", mode: repair.repair ? "repair" : "normal" }) : null
|
|
334
|
+
// 完成清单预检位于既有收口门之后、凭证消费与批档写盘之前;拒绝时令牌、档、账均不变。
|
|
335
|
+
// `closeEvidence` 与 `completed` 同一格(收口即结算:证据由本笔给,机器不代写)。
|
|
336
|
+
if (closingValue) await assertCloseDisposition(abs, ctx?.agent?.cwd, args?.completed, args?.closeEvidence, true)
|
|
262
337
|
const designTokens = closingValue ? consumeBatchDesignTokens(ctx?.agent ?? {}, abs) : null
|
|
263
|
-
|
|
338
|
+
// 补关(§4.18-C)= 冻结之外在 §1 段尾追加一行追记(一次写盘、两处落笔);正常收口只改状态行。
|
|
339
|
+
// 补关只在 `closingValue` 下成立,而 `closingValue` 蕴含 `seg === 1` ⇒ 追记行恒落 §1。
|
|
340
|
+
const statusWritten = updateSectionStatusLine(src, seg, lineValue)
|
|
341
|
+
const repairWritten = repair?.repair ? appendLineToSection(statusWritten, 1, repairTraceLine(todayLocal(), repair.rows)) : statusWritten
|
|
342
|
+
// 收口即失效(§4.24):写 §1「已收口」这一笔同源落 `未授权` 行——不靠谁事后记得补一笔。
|
|
343
|
+
const written = closingValue ? appendGoAheadRevokedLine(repairWritten, todayLocal()) : repairWritten
|
|
264
344
|
writeFileSync(abs, written)
|
|
345
|
+
// 记账口径(明示,不改行为):`_batchWrites` 与端侧记账记的是「本笔**落过盘**」,位次 = 写盘成功那一刻;
|
|
346
|
+
// 台账失败由 `ledgerAfterRecordWrite` 把档回档后本计数不回退(档字节净变 = 零,而写盘事实发生过)。
|
|
347
|
+
// 它不进任何判据(§7.1 `wrote` 只问「有没有写过」),故不以回档为准重算。
|
|
348
|
+
if (ctx?.agent) ctx.agent._batchWrites = (ctx.agent._batchWrites ?? 0) + 1 // §7.1 `wrote` 判据(写盘成功才增)
|
|
265
349
|
onWritten?.(ctx?.agent ?? {}, abs)
|
|
266
350
|
// 收口重锚(§6.2 · C · AC-M2-30):值余核 = §1「已收口」⇒ 本 action 就是收口 ⇒ 同调单源
|
|
267
|
-
// `reanchorOnClose`(不复制 close 径逻辑);次序位 =
|
|
268
|
-
//
|
|
269
|
-
|
|
270
|
-
|
|
351
|
+
// `reanchorOnClose`(不复制 close 径逻辑);次序位 = 状态行写盘之后(写序单源 = §2.17)。
|
|
352
|
+
// 本笔被任一拒因拒 ⇒ 上面各门早 throw,台账零写(被拒的收口没有收口)。一次收口只出一份清单。
|
|
353
|
+
// 台账失败 ⇒ 用写前全文回滚档并抛拒——冻结与结账要么一起成,要么一个都不成(除非回滚本身也失败,
|
|
354
|
+
// 那时第二条串点名半状态与查询面)。
|
|
355
|
+
const reanchor = closingValue && readBatchStatusLine(src) !== "closed"
|
|
356
|
+
? await ledgerAfterRecordWrite({ side: "close", abs, src, run: () => reanchorOnClose(abs, ctx?.agent?.cwd, args?.completed, args?.closeEvidence, true) })
|
|
357
|
+
: null
|
|
358
|
+
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)}${seg === 1 ? `${goAheadReceiptLine(written)}${goAheadEndLine(src, written)}` : ""}${repairReceiptLine(repair?.repair ? { rows: repair.rows, date: todayLocal() } : null)}${reanchorReceiptLine(reanchor)}${newDebtReasonReceiptLine(reanchor)}${consistencyReceiptLine(await consistencyOf(abs, ctx?.agent?.cwd))}`
|
|
271
359
|
}
|
|
272
360
|
|
|
273
361
|
/**
|
|
@@ -276,7 +364,7 @@ export async function statusBatchRecord({ args, ctx, review, pickTarget, onWritt
|
|
|
276
364
|
* 不代写 §6 内容、不替代台账核销事务。
|
|
277
365
|
* 前提规则(#422 + §4.18-A + §2.6 四道门):① 收口门(链门 ∧ §3 状态词臂;§6 唯一缺段时拒串 = 旧 §6 串
|
|
278
366
|
* 逐字零回归);② 本批批内单测档门;③ 文档机检门;④ 无状态行档 ⇒ 自建机读位(「有行但不可解析」仍
|
|
279
|
-
* fail-closed
|
|
367
|
+
* fail-closed)。**全归档补关**(§4.18-C)只绕开 ① 的两臂,②③ 与完成清单预检、凭证消费、重锚全保留。
|
|
280
368
|
* @returns {Promise<string>} 成功消息
|
|
281
369
|
*/
|
|
282
370
|
export async function closeBatchRecord({ args, ctx, review, pickTarget, onWritten }) {
|
|
@@ -286,17 +374,33 @@ export async function closeBatchRecord({ args, ctx, review, pickTarget, onWritte
|
|
|
286
374
|
// #422③:§1 无状态行档 ⇒ 自建机读位(下行走 updateSectionStatusLine 缺失即插——同路收口);
|
|
287
375
|
// 「有行但不可解析」维持 fail-closed(assertGateOpen 拒——防误冻结)。
|
|
288
376
|
if (readBatchStatusLine(src) !== "open" && sectionHasStatusLine(src, 1)) assertGateOpen(src)
|
|
289
|
-
//
|
|
290
|
-
const
|
|
291
|
-
//
|
|
377
|
+
// 收口分流(§4.18-C):链门之前读一致性——全归档批走补关,其余走完整链门。
|
|
378
|
+
const repair = await repairDecisionOf(abs, ctx?.agent?.cwd)
|
|
379
|
+
// 收口门(§2.6):链门 → §3 状态词臂 → 单测档门 → 机检门(位次 = 既有拒因之后、写盘之前);
|
|
380
|
+
// 补关分派 ⇒ 只跳过前两臂(repair.repair)。
|
|
381
|
+
const gate = assertCloseoutGates({ abs, cwd: ctx?.agent?.cwd, agent: ctx?.agent ?? {}, src, action: "close", mode: repair.repair ? "repair" : "normal" })
|
|
382
|
+
// 完成清单预检位于既有收口门之后、凭证消费与批档写盘之前;拒绝时令牌、档、账均不变。
|
|
383
|
+
// `closeEvidence` 与 `completed` 同一格(收口即结算:证据由本笔给,机器不代写——代写一句就把核销门
|
|
384
|
+
// 变成摆设)。
|
|
385
|
+
await assertCloseDisposition(abs, ctx?.agent?.cwd, args?.completed, args?.closeEvidence, true)
|
|
292
386
|
const designTokens = consumeBatchDesignTokens(ctx?.agent ?? {}, abs)
|
|
293
387
|
const date = todayLocal()
|
|
294
|
-
|
|
388
|
+
// 补关(§4.18-C)= 冻结之外在 §1 段尾追加一行追记(一次写盘、两处落笔);正常收口只改状态行。
|
|
389
|
+
const statusWritten = updateSectionStatusLine(src, 1, `已收口 ${date}`)
|
|
390
|
+
const repairWritten = repair.repair ? appendLineToSection(statusWritten, 1, repairTraceLine(date, repair.rows)) : statusWritten
|
|
391
|
+
// 收口即失效(§4.24):与 status 收口通路同源(`appendGoAheadRevokedLine`)——两路不同调就会有一路收口后
|
|
392
|
+
// 盘上还写着 `已授权`。
|
|
393
|
+
const written = appendGoAheadRevokedLine(repairWritten, date)
|
|
295
394
|
writeFileSync(abs, written)
|
|
395
|
+
// 记账口径同 status 径(记「落过盘」,回档不回退)——见 `statusBatchRecord` 写盘处的注释。
|
|
396
|
+
if (ctx?.agent) ctx.agent._batchWrites = (ctx.agent._batchWrites ?? 0) + 1 // §7.1 `wrote` 判据(写盘成功才增)
|
|
296
397
|
onWritten?.(ctx?.agent ?? {}, abs)
|
|
297
398
|
// 收口重锚(§6.2 · C · AC-M2-30):顺序位 = 全部拒因通过、§1 状态行写盘**之后**——close 被拒 ⇒ 台账零写。
|
|
298
|
-
|
|
299
|
-
|
|
399
|
+
// 台账失败 ⇒ 用写前全文回滚档 + 抛拒(§2.17 写序;不可逆的一方排最后)。
|
|
400
|
+
const reanchor = await ledgerAfterRecordWrite({
|
|
401
|
+
side: "close", abs, src, run: () => reanchorOnClose(abs, ctx?.agent?.cwd, args?.completed, args?.closeEvidence, true),
|
|
402
|
+
})
|
|
403
|
+
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)}${goAheadReceiptLine(written)}${goAheadEndLine(src, written)}${repairReceiptLine(repair.repair ? { rows: repair.rows, date } : null)}${reanchorReceiptLine(reanchor)}${newDebtReasonReceiptLine(reanchor)}${consistencyReceiptLine(await consistencyOf(abs, ctx?.agent?.cwd))}`
|
|
300
404
|
}
|
|
301
405
|
|
|
302
406
|
// ─── 收口自动消费本批设计凭证(DESIGN-TOKEN-SETTLEMENT §10——单源,close ∥ status 两通路同调)──
|
|
@@ -334,27 +438,54 @@ export function consumeBatchDesignTokens(agent, abs) {
|
|
|
334
438
|
return { consumed, unattributed: unattributedSlotCount(agent, batches) }
|
|
335
439
|
}
|
|
336
440
|
|
|
337
|
-
/** 收口回执的凭证段(§10 回执形:单列 `[design tokens]` 一行);`null`(普通模式 no-op)⇒ 无该段。
|
|
338
|
-
|
|
441
|
+
/** 收口回执的凭证段(§10 回执形:单列 `[design tokens]` 一行);`null`(普通模式 no-op)⇒ 无该段。
|
|
442
|
+
* 导出面 = 第三条收口边(`batch-supersede.mjs`)同用:凭证消费是「从未实施」也**不豁免**的环节。
|
|
443
|
+
* 单源在此——两个入口各写一句就会成为两个格式。 */
|
|
444
|
+
export function designTokensReceiptLine(result) {
|
|
339
445
|
if (!result) return ""
|
|
340
446
|
return `\n[design tokens] 消费 ${result.consumed} 枚 · 留槽无归属 ${result.unattributed} 枚`
|
|
341
447
|
}
|
|
342
448
|
|
|
449
|
+
/**
|
|
450
|
+
* 写序第 4 步(设计档 §2.17「写序」):**档先写、台账后写,台账失败即用写前全文补偿回滚档**——
|
|
451
|
+
* 不可逆的一方(核销)排最后。`run()` 返回的那一笔台账写失败(返回形 `failed`)⇒ 覆盖回写前字节并抛拒;
|
|
452
|
+
* **补偿本身也失败** ⇒ 出那一侧的第二条串(不得复用第一条——第一条声称已回滚,此时事实相反),
|
|
453
|
+
* 它是唯一允许半状态成立的时点,且必须喊出来(含 `batch({action:"check"})` 指路)。
|
|
454
|
+
* 两条串的单源:收口侧 = `batch-closeout.mjs`,重开侧 = `batch-reopen.mjs`。
|
|
455
|
+
* 导出面 = 第三条收口边(`batch-supersede.mjs`)同调:写序与失败补偿属「不豁免」的环节(§4.18-D「保留门与写序」)。
|
|
456
|
+
*/
|
|
457
|
+
export async function ledgerAfterRecordWrite({ side, abs, src, run }) {
|
|
458
|
+
const result = await run()
|
|
459
|
+
if (!result?.failed) return result
|
|
460
|
+
try {
|
|
461
|
+
writeFileSync(abs, src)
|
|
462
|
+
} catch (rollbackErr) {
|
|
463
|
+
const rollbackCause = String(rollbackErr?.message ?? rollbackErr)
|
|
464
|
+
throw new Error(side === "close"
|
|
465
|
+
? closeHalfStateError(abs, result.failed, rollbackCause)
|
|
466
|
+
: reopenHalfStateError(abs, result.failed, rollbackCause))
|
|
467
|
+
}
|
|
468
|
+
throw new Error(side === "close" ? closeLedgerFailedError(result.failed) : reopenLedgerFailedError(result.failed))
|
|
469
|
+
}
|
|
470
|
+
|
|
343
471
|
/** 收口重锚(设计档 §6.2 · C · §2.7 分流)——收口两条通路共调(同一单源,不复制逻辑);写入单源 =
|
|
344
|
-
* `ledgerReanchorBatch`(本档只供 `cwd`
|
|
472
|
+
* `ledgerReanchorBatch`(本档只供 `cwd` 基准与完成清单;工具层零 SQL)。
|
|
345
473
|
* `cwd` = **批档所属项目根** = `resolveLedgerRoot(dirname(<batchDoc>), boundary)?.root`——**不用会话锚**
|
|
346
474
|
* (多根工作区锚会收到别的项目根 ⇒ 选行零命中 ⇒ 唯一的机器写静默失效)。
|
|
347
475
|
* `boundary` = 上溯上界 = **会话锚**(**必传**——缺值即当场失败,回执以 `failed` 点名;不落进程 cwd)。无根 ⇒ 传 `null`(核心不取行、不重锚,`failed` 点名)。
|
|
348
|
-
* `batch` = 项目根相对路径(复启句的 `<批名>`
|
|
476
|
+
* `batch` = 项目根相对路径(复启句的 `<批名>` 即其文件部分)。失败**不抛**(本档的 `failed` 由调用方
|
|
477
|
+
* `ledgerAfterRecordWrite` 转成「回滚档 + 抛拒」——收口要么一起成、要么一个都不成)。
|
|
478
|
+
* `requireAllInFlight` = 完成清单那一条元判据(**无缺省**,§4.18-D「③ 的实现面」):正常两路传 `true`,
|
|
479
|
+
* 被取代的收口传 `false`(未点名的在途行走退回边)。
|
|
349
480
|
* **返回形** = `ledgerReanchorBatch` 返回形 + `newDebtReasons`(本批行中 `evidence` 带 `新事理由:` 前缀者;
|
|
350
481
|
* 取不到本批行 ⇒ 空集)——**只取不写**,格式化成回执段的是 `newDebtReasonReceiptLine`。 */
|
|
351
|
-
async function reanchorOnClose(abs, boundary) {
|
|
482
|
+
export async function reanchorOnClose(abs, boundary, completed, closeEvidence, requireAllInFlight) {
|
|
352
483
|
try {
|
|
353
484
|
const { ledgerBatchRows, ledgerReanchorBatch, resolveLedgerRoot } = await import("../ledger.mjs") // 动态 import:ledger-db 静态引 node:sqlite(W8 契约②)
|
|
354
485
|
const root = resolveLedgerRoot(dirname(abs), boundary)?.root ?? null
|
|
355
486
|
// 句内路径统一正斜杠(与 `task_book` 列值同形——`<批名>` 是给人读的事实句,不是平台路径)
|
|
356
487
|
const batch = root ? relative(root, abs).replace(/\\/g, "/") : abs
|
|
357
|
-
const result = ledgerReanchorBatch({ cwd: root, batch, boundary })
|
|
488
|
+
const result = ledgerReanchorBatch({ cwd: root, batch, boundary, completed, closeEvidence, requireAllInFlight })
|
|
358
489
|
// 新事理由读面(设计档 §6.3):本批行(任意状态)中 `evidence` 带 `新事理由:` 前缀者随返回形带回——
|
|
359
490
|
// **只引不写**(行改写语义零动);取不到本批行 ⇒ 空集(不出该段、收口不被否决,同 `failed` 降级口径)
|
|
360
491
|
let newDebtReasons = []
|
|
@@ -366,6 +497,24 @@ async function reanchorOnClose(abs, boundary) {
|
|
|
366
497
|
return { ...result, newDebtReasons }
|
|
367
498
|
} catch (e) {
|
|
368
499
|
// 非预期异常(模块加载失败 ∥ 根推导内读声明抛)同样不得否决收口——降为同一返回形(台账零写)
|
|
369
|
-
return { batch: abs,
|
|
500
|
+
return { batch: abs, settled: [], conditioned: [], alreadyAnchored: [], failed: String(e?.message ?? e), newDebtReasons: [] }
|
|
370
501
|
}
|
|
371
502
|
}
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* check——半状态查询(设计档 §2.17「暴露面两处」第一条;**只读动作,depth-0 only**):回执逐行打印
|
|
506
|
+
* `batchLedgerConsistency` 的读数——`record` 三态 ∥ 本批行集 ∥ 半状态五类与各自出路 ∥ `consistent`。
|
|
507
|
+
* 这就是「明确的半状态查询面」:人不必靠一次失败的写去猜,半状态可查、可照着出路恢复。
|
|
508
|
+
* **零写**:不改行、不改档(半状态自动修复被拒——修复要走人裁的那一步:重开 ∥ 收口 ∥ 改指针)。
|
|
509
|
+
* @returns {Promise<string>} 回执(含 `[ledger consistency]` 行)
|
|
510
|
+
*/
|
|
511
|
+
export async function checkBatchRecord({ args, ctx, review, pickTarget }) {
|
|
512
|
+
if (review || !isDepthZero(ctx)) {
|
|
513
|
+
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).")
|
|
514
|
+
}
|
|
515
|
+
const abs = pickTarget(args?.path)
|
|
516
|
+
const { batchLedgerConsistency, resolveLedgerRoot } = await import("../ledger.mjs")
|
|
517
|
+
const root = resolveLedgerRoot(dirname(abs), ctx?.agent?.cwd)?.root ?? null
|
|
518
|
+
const batch = root ? relative(root, abs).replace(/\\/g, "/") : abs
|
|
519
|
+
return checkReceipt(batchLedgerConsistency({ cwd: root, batch, boundary: ctx?.agent?.cwd }), abs)
|
|
520
|
+
}
|
|
@@ -52,12 +52,22 @@ function declaredBases(cwd) {
|
|
|
52
52
|
return man.ok ? docRootPaths(man.manifest?.docRoot?.batches, base) : []
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* 批次档基底根数组(**声明面单源**——create / 在飞扫描 / 锚判的面判共用):manifest `docRoot.batches`
|
|
56
57
|
* (串 | 多根数组)→ 声明基底;缺失 / 非法 ⇒ 回退默认基底 `"docs/batches"`(恒返回非空数组)。
|
|
57
58
|
* **工作区锚**(条 5)⇒ 候选项目基底**并集**(候选按名排序、并集保序)——在飞扫描 / 写门基底集同取此值。
|
|
59
|
+
* **注入形**(`{ manifest }` 可选——`thincoder-core/doc-check/index.mjs` 的组根调用吃它):引擎已按组根
|
|
60
|
+
* 读过一次 manifest,这里不再重读(每根一次读);缺省仍自读,既有调用零改。注入只换读取来源,
|
|
61
|
+
* 形态判据与回退支零改(manifest 是 `readManifest` 的返回值,`ok:false` 照走缺省回退——降级不静默)。
|
|
58
62
|
* @param {string} cwd
|
|
63
|
+
* @param {{manifest?:{ok:boolean, manifest?:object|null}}} [injected] 引擎已读的那份(可选)
|
|
59
64
|
* @returns {string[]} */
|
|
60
|
-
export function batchDocBases(cwd) {
|
|
65
|
+
export function batchDocBases(cwd, injected = {}) {
|
|
66
|
+
const man = injected?.manifest
|
|
67
|
+
if (man) {
|
|
68
|
+
const roots = man.ok ? docRootPaths(man.manifest?.docRoot?.batches, cwd) : []
|
|
69
|
+
return roots.length ? roots : [resolve(docRootBase(cwd), "docs/batches")]
|
|
70
|
+
}
|
|
61
71
|
const ws = workspaceCandidates(cwd)
|
|
62
72
|
if (ws) {
|
|
63
73
|
const union = []
|
|
@@ -86,14 +96,25 @@ function anchoredPrefix(p, prefixes) {
|
|
|
86
96
|
return null
|
|
87
97
|
}
|
|
88
98
|
|
|
89
|
-
/**
|
|
90
|
-
|
|
99
|
+
/** 落在哪个基底根之内(不落任何一个 ⇒ null)——**判据单源**:create 面的越基底判据(`insideBases`)与
|
|
100
|
+
* doc-check 的面判(`thincoder-core/doc-graph/anchors.mjs` 的 `isBatchFaceRef`——「同一基底根」要的正是**哪一根**)
|
|
101
|
+
* 同取本函数。按**路径段**判(`docs/batches-old/` 不算落在 `docs/batches` 内),win32 大小写不敏感。
|
|
102
|
+
* @param {string} abs 绝对路径
|
|
103
|
+
* @param {string[]} bases 基底根数组(`batchDocBases`——已是绝对路径)
|
|
104
|
+
* @returns {string|null} 命中的那个基底根(原值,不归一大小写)∥ null */
|
|
105
|
+
export function baseContaining(abs, bases) {
|
|
91
106
|
const norm = (p) => (process.platform === "win32" ? p.toLowerCase() : p)
|
|
92
107
|
const target = norm(abs)
|
|
93
|
-
|
|
108
|
+
for (const b of bases) {
|
|
94
109
|
const root = norm(b)
|
|
95
|
-
|
|
96
|
-
}
|
|
110
|
+
if (target === root || target.startsWith(root.endsWith(sep) ? root : root + sep)) return b
|
|
111
|
+
}
|
|
112
|
+
return null
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 越基底判据(create 面):解析后须落在某一基底根之内(判定单源 = 同档 `baseContaining`)。 */
|
|
116
|
+
function insideBases(abs, bases) {
|
|
117
|
+
return baseContaining(abs, bases) !== null
|
|
97
118
|
}
|
|
98
119
|
|
|
99
120
|
/** create 越基底(原文案逐字——零变面)。 */
|
|
@@ -107,7 +128,7 @@ const ambiguousLandingError = (raw, landings) => new Error(`batch: create path r
|
|
|
107
128
|
|
|
108
129
|
/**
|
|
109
130
|
* **读面**解析的四态本体(候选序 + 判态全部经统一解析层——本面只声明自己的参数:
|
|
110
|
-
* `order:"near-first"`(近基根 = cwd / 会话锚 先)+ `kind:"file"
|
|
131
|
+
* `order:"near-first"`(近基根 = cwd / 会话锚 先)+ `kind:"file"`,本面**不传 `declaredRepos`**(不放宽跨仓形:
|
|
111
132
|
* `bases` = `docRoot.batches` 声明面(读面无 manifest ⇒ 无这一级))。锚定串只解析项目根形
|
|
112
133
|
* (不二次拼接——§4.15 判据,见 `resolveBatchReadPath`)。
|
|
113
134
|
* 导出面供 spawn 门拼「追加同名候选」(§2.6:既有文案逐字在前,新信息追加在后)。
|