@thincoder/core 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -2
- package/advisor/convergence.mjs +34 -3
- package/advisor/loop.mjs +42 -10
- package/advisor/messages.mjs +42 -25
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +7 -4
- package/advisor.mjs +29 -43
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/completion.mjs +44 -3
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch.mjs +8 -3
- package/agent/family-tools.mjs +27 -12
- package/agent/helpers.mjs +122 -1
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +24 -10
- package/agent/record-results.mjs +18 -1
- package/agent/run-stages.mjs +77 -32
- package/agent/run-start.mjs +37 -0
- package/agent/setup-reminders.mjs +9 -2
- package/agent/setup.mjs +24 -11
- package/agent/spawn-child.mjs +38 -1
- package/agent/timers.mjs +5 -3
- package/agent/turn-loop.mjs +30 -5
- package/agent/turn-projection.mjs +386 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +168 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +29 -169
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +36 -47
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/batch-closeout.mjs +273 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +226 -17
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +169 -46
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +23 -11
- package/agent-tools/batch-segment-vocab.mjs +379 -0
- package/agent-tools/batch-skeleton.mjs +192 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +297 -0
- package/agent-tools/batch.mjs +182 -439
- package/agent-tools/consult.mjs +7 -4
- package/agent-tools/context.mjs +44 -17
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +1 -1
- package/agent-tools/design-token.mjs +279 -81
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +9 -8
- package/agent-tools/escalate-async.mjs +2 -2
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +10 -3
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/spawn-gates.mjs +9 -8
- package/agent-tools/ssh-session.mjs +2 -2
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-async.mjs +8 -9
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +4 -4
- package/agent-tools/subagent-spawn.mjs +90 -110
- package/agent-tools/subagent.mjs +11 -10
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +20 -1
- package/attachments.mjs +3 -3
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +1 -1
- package/config-defaults.mjs +2 -1
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +62 -98
- package/context-degrade.mjs +38 -10
- package/context-echo.mjs +11 -0
- package/context.mjs +149 -83
- package/conventions.mjs +11 -9
- package/declaration.mjs +31 -5
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +309 -213
- package/doc-check/line-refs.mjs +27 -101
- package/doc-check/paragraph.mjs +218 -102
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/explore-distill.mjs +11 -5
- package/i18n.mjs +1 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +6 -0
- package/ledger-close-proof.mjs +100 -49
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +47 -91
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +47 -15
- package/ledger-executors.mjs +1 -1
- package/ledger-tools.mjs +78 -19
- package/ledger-write-ops.mjs +130 -41
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/schema.mjs +2 -2
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +91 -1
- package/prompt-overlays.mjs +9 -6
- package/prompts/advisor-design.md +62 -21
- package/prompts/advisor-round1.md +34 -1
- package/prompts/advisor-round2.md +40 -7
- package/prompts/advisor-round3.md +39 -6
- package/prompts/common.md +14 -387
- package/prompts/consult-base.md +5 -1
- package/prompts/discipline-engineering.md +226 -51
- package/prompts/discipline-normal.md +4 -255
- package/prompts/knowledge/business-gates.md +22 -0
- package/prompts/knowledge/decision-quality.md +23 -0
- package/prompts/knowledge/doc-lookup.md +35 -0
- package/prompts/knowledge/document-writing.md +51 -0
- package/prompts/knowledge/documentation-evaluation.md +56 -0
- package/prompts/knowledge/evidence-discipline.md +57 -0
- package/prompts/knowledge/normal-coding-workflow.md +104 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +108 -0
- package/prompts/knowledge/normal-work-management.md +57 -0
- package/prompts/knowledge/product-security.md +23 -0
- package/prompts/knowledge/project-records.md +62 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +18 -0
- package/prompts/knowledge/tool-bash.md +39 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +12 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +12 -0
- package/prompts/knowledge/tool-batch-review.md +12 -0
- package/prompts/knowledge/tool-batch.md +80 -0
- package/prompts/knowledge/tool-browser.md +57 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +17 -0
- package/prompts/knowledge/tool-doc-check.md +70 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +38 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +16 -0
- package/prompts/knowledge/tool-fetch.md +12 -0
- package/prompts/knowledge/tool-file-ops.md +16 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +19 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +15 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +18 -0
- package/prompts/knowledge/tool-hashline-edit.md +14 -0
- package/prompts/knowledge/tool-insert-after.md +15 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +35 -0
- package/prompts/knowledge/tool-ledger.md +42 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +13 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +31 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +15 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +114 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +6 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +36 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +21 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +18 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +52 -0
- package/prompts/knowledge/tool-subagent.md +59 -0
- package/prompts/knowledge/tool-task.md +12 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +11 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +14 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +9 -0
- package/prompts/knowledge/upstream-protocol.md +43 -0
- package/prompts/persona-eng-coder.md +21 -3
- package/prompts/persona-eng-designer.md +131 -169
- package/prompts/persona-engineering.md +142 -84
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-plan.md +5 -1
- package/prompts/subagent-base.md +2 -0
- package/provider/anthropic.mjs +6 -4
- package/provider/core.mjs +3 -2
- package/provider/errors.mjs +29 -4
- package/provider/google.mjs +24 -7
- package/provider/responses.mjs +3 -1
- package/provider-flows.mjs +2 -2
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +72 -17
- package/session-slot-write.mjs +37 -5
- package/session.mjs +24 -8
- package/skip-dirs.mjs +2 -2
- package/team-ledger.mjs +13 -9
- package/token-ttl.mjs +73 -4
- package/token-window.mjs +167 -33
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -41
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +2 -84
- package/tool-docs/browser.md +2 -49
- package/tool-docs/code_search.md +2 -2
- package/tool-docs/consult_start.md +2 -8
- package/tool-docs/consult_stop.md +2 -4
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -17
- package/tool-docs/doc_check.md +2 -107
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +2 -4
- package/tool-docs/edit.md +1 -38
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -18
- package/tool-docs/fetch.md +2 -14
- package/tool-docs/file_ops.md +2 -18
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -35
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +1 -6
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -15
- package/tool-docs/insert_after.md +2 -16
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -10
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -8
- package/tool-docs/manifest.md +2 -35
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +2 -20
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +1 -5
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -18
- package/tool-docs/read_image.md +2 -9
- package/tool-docs/recent_changes.md +2 -2
- package/tool-docs/repo_outline.md +2 -2
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +1 -12
- package/tool-docs/skill.md +2 -6
- package/tool-docs/ssh.md +1 -62
- package/tool-docs/subagent.md +2 -100
- package/tool-docs/task.md +1 -7
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +2 -19
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +2 -12
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -19
- package/tool-docs/write.md +2 -12
- package/tools/browser.mjs +52 -7
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +170 -92
- package/tools/edit-diff.mjs +78 -62
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +1 -1
- package/tools/file.mjs +16 -8
- package/tools/git.mjs +24 -9
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +3 -1
- package/tools/patch.mjs +123 -43
- package/tools/shared.mjs +28 -27
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +203 -0
- package/doc-check/anchors.mjs +0 -235
|
@@ -1,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,13 @@ 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,
|
|
42
54
|
} from "./batch-skeleton.mjs"
|
|
43
|
-
import { assertCloseoutGates, newDebtReasonOf, newDebtReasonReceiptLine, readCloseoutSource, reanchorReceiptLine } from "./batch-closeout.mjs"
|
|
44
|
-
import {
|
|
45
|
-
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"
|
|
46
59
|
import { batchPathKey, executeConsumeDesignAction, unionBatches, unionSlots } from "./design-slots.mjs"
|
|
47
60
|
|
|
48
61
|
/** 可读文件判据(存在且为文件——目录/缺失同判不可读;与主档同名 helper 同型——KD-4 单向依赖下各自持有,
|
|
@@ -62,8 +75,9 @@ function segmentNumber(raw) {
|
|
|
62
75
|
return m ? Number(m[1]) : null
|
|
63
76
|
}
|
|
64
77
|
|
|
65
|
-
/** main-agent-only 门(BR-19/BR-24):close 仅 depth-0 放行(eng 子代理 / 评审皆拒)。
|
|
66
|
-
|
|
78
|
+
/** main-agent-only 门(BR-19/BR-24):close / supersede 仅 depth-0 放行(eng 子代理 / 评审皆拒)。
|
|
79
|
+
* 导出面 = `batch-supersede.mjs`(第三条收口边同一身份门——同一条判据只有这一个函数)。 */
|
|
80
|
+
export function assertMainAgentOnly(ctx, action, review) {
|
|
67
81
|
if (review || !isDepthZero(ctx)) {
|
|
68
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).`)
|
|
69
83
|
}
|
|
@@ -72,16 +86,16 @@ function assertMainAgentOnly(ctx, action, review) {
|
|
|
72
86
|
/** 递归收集目录下全部 `*.md`(#369 · KD-4:显式嵌套路径为合法 create 面 ⇒ 顶层平扫会欠计 ⇒ 复数情形
|
|
73
87
|
* 漏判、默认定位可落非预期档)。只认真目录(symlink 不入,防环);单目录读错按无候选处理(尽力面)。
|
|
74
88
|
* **转导出**(read-data-interface 批——`batch/list` 读面文件集同源复用;零行为变)。
|
|
75
|
-
*
|
|
76
|
-
* `
|
|
77
|
-
*
|
|
89
|
+
* **只收批档**(`*.md` 且不以点开头——两条判):其它扩展名(与批档同目录并存的同名单测档 `<批档名>.test.mjs`)
|
|
90
|
+
* 与隐藏档都不是批档;只有「点开头」一条挡不住那份测档,挡住它的是扩展名那一条(`docs/core/design/DOC-CHECK.md` §2.10.2)。
|
|
91
|
+
* **不为任何残档设支**:盘上没有片段档这回事——两条判据描述的是「什么算批档」,不是「谁要排掉」。 */
|
|
78
92
|
export function collectMarkdownFiles(dir, out = []) {
|
|
79
93
|
let entries = []
|
|
80
94
|
try { entries = readdirSync(dir, { withFileTypes: true }) } catch { return out }
|
|
81
95
|
for (const e of entries) {
|
|
82
96
|
const abs = resolve(dir, e.name)
|
|
83
97
|
if (e.isDirectory()) collectMarkdownFiles(abs, out)
|
|
84
|
-
else if (e.isFile() && e.name.endsWith(".md") && !e.name.startsWith(
|
|
98
|
+
else if (e.isFile() && e.name.endsWith(".md") && !e.name.startsWith(".")) out.push(abs)
|
|
85
99
|
}
|
|
86
100
|
return out
|
|
87
101
|
}
|
|
@@ -119,7 +133,7 @@ export function findInFlightBatch(cwd, bases) {
|
|
|
119
133
|
* append 面同字面(「已收口档不回改」/「状态行不可解析或缺失」)。
|
|
120
134
|
* unknown 串多两句:段级状态行的取值区已收窄到 §1 **段头区**,行落在区外(段体 / 轮次块)就读不成值
|
|
121
135
|
* ——拒文点名这条终态与唯一出路(把行移进段头区),否则被卡住的人在界面上无路可走(设计档 §5 R26)。 */
|
|
122
|
-
function assertGateOpen(src) {
|
|
136
|
+
export function assertGateOpen(src) {
|
|
123
137
|
const gate = readBatchStatusLine(src)
|
|
124
138
|
if (gate === "closed") {
|
|
125
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.")
|
|
@@ -180,6 +194,17 @@ function assertStatusNote(note) {
|
|
|
180
194
|
}
|
|
181
195
|
}
|
|
182
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
|
+
|
|
183
208
|
/**
|
|
184
209
|
* status——状态行流转(§4.12,段属主;§4.16 模式感知)。写域 = 调用者自己段内 `**状态行**:`
|
|
185
210
|
* 行(评审 → §3 · eng-designer → §2 · eng-coder / coder → §5 · 主 agent:工程 §1 ∥ 普通
|
|
@@ -187,18 +212,28 @@ function assertStatusNote(note) {
|
|
|
187
212
|
* 字段(落状态行括注);冻结真值不变(gate 只读 §1)。
|
|
188
213
|
* path 参数 = 仅 depth-0(D-BR21)——子代理/评审传 path ⇒ 拒。F11-C 挂点 = 写盘前(档头结构行含骨架
|
|
189
214
|
* 死占位 ⇒ 拒;段体引用豁免;close 不拦——收口是主 agent 终态动作)。
|
|
215
|
+
* **段头区歧义拒写**(§4.21.4 写面第二道):目标段段头区两条以上状态行 ⇒ 拒并给修复句(非 §1 = 先
|
|
216
|
+
* `edit` 删多余那条再 `status`;§1 = 普通文档写)——位次 = 读档之后、重开合取之前(两路都是拒)。
|
|
190
217
|
* **收口第二通路**:值余核 = §1「已收口」时本 action 同样收口(收口门 + 单测档门 + 机检门 + 冻结与
|
|
191
|
-
* close 同序)⇒ 状态行写盘后同调 `reanchorOnClose`,回执携同一 `[ledger reanchor]`
|
|
218
|
+
* close 同序)⇒ 状态行写盘后同调 `reanchorOnClose`,回执携同一 `[ledger reanchor]` 段;`completed` 与
|
|
219
|
+
* `closeEvidence` 与 `close` 同两条必填,台账失败同样回滚档并抛拒。与 close 同门同分派:全归档批走补关
|
|
220
|
+
* (§4.18-C,只绕开内容门与 §3 pass 臂,§1 段尾落一行 `**补关记录**`)。
|
|
192
221
|
* **重开径**(§4.18-B · §2.13):前态 closed ∧ 值 = 进行中 ∧ note 非空 ⇒ 重开;写盘后同调
|
|
193
|
-
* `reclaimOnReopen`(`待核销 → 在途`),回执携 `[ledger reopen]`
|
|
222
|
+
* `reclaimOnReopen`(`待核销 → 在途`),回执携 `[ledger reopen]` 段;回收失败 ⇒ 档回滚到冻结态并抛拒。
|
|
223
|
+
* **其余一切用法零台账写**;本 action 的回执末尾恒带一行 `[ledger consistency]`。
|
|
194
224
|
* @returns {Promise<string>} 成功消息
|
|
195
225
|
*/
|
|
196
|
-
export async function statusBatchRecord({ args, ctx, review, pickTarget, onWritten }) {
|
|
226
|
+
export async function statusBatchRecord({ args, ctx, review, reviewTrack, pickTarget, onWritten }) {
|
|
197
227
|
const depth0 = isDepthZero(ctx)
|
|
198
228
|
// 模式位执行期实读(§4.16——同款先例 = task.mjs execute 门;翻转即时生效——D-BR26)。
|
|
199
229
|
const engineering = !!ctx?.agent?.config?.agent?.engineering
|
|
200
|
-
|
|
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)
|
|
201
235
|
if (seg === null) {
|
|
236
|
+
if (review) throw new Error(sectionThreeDesignTrackError("batch"))
|
|
202
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).")
|
|
203
238
|
}
|
|
204
239
|
// 段域判据(BR-22「eng-designer 对 §1 调 status ⇒ 段白名单拒」——镜像 append 面):
|
|
@@ -234,6 +269,10 @@ export async function statusBatchRecord({ args, ctx, review, pickTarget, onWritt
|
|
|
234
269
|
assertStatusValue(seg, value)
|
|
235
270
|
const abs = pickTarget(args?.path)
|
|
236
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))
|
|
237
276
|
// 重开合取(§4.18-B):段 = §1 · depth-0(非评审)· 值关键词 = 进行中 · 门态 = closed——
|
|
238
277
|
// 先于冻结拒写判定(门②的唯一例外);note = 重开理由(J4 缺则拒)。**台账联动只由本合取触发**。
|
|
239
278
|
const reopen = seg === 1 && depth0 && !review && stripDecorations(value) === STATUS_WORDS[1].open && readBatchStatusLine(src) === "closed"
|
|
@@ -249,25 +288,51 @@ export async function statusBatchRecord({ args, ctx, review, pickTarget, onWritt
|
|
|
249
288
|
// 重开(§4.18-B · §2.13):一次写盘、两处落笔(状态行改写 + §1 段尾追记行)——不跑收口门
|
|
250
289
|
//(值非「已收口」;写后门态 = open,后续 append/status 恢复放行)。
|
|
251
290
|
writeFileSync(abs, rewriteAsReopen(src, note))
|
|
291
|
+
// 记账口径同 status 径(记「落过盘」,回档不回退)——见 `statusBatchRecord` 写盘处的注释。
|
|
292
|
+
if (ctx?.agent) ctx.agent._batchWrites = (ctx.agent._batchWrites ?? 0) + 1 // §6.6 `wrote` 判据(写盘成功才增)
|
|
252
293
|
onWritten?.(ctx?.agent ?? {}, abs)
|
|
253
|
-
// ② 台账回收(§2.
|
|
254
|
-
|
|
255
|
-
|
|
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))}`
|
|
256
300
|
}
|
|
257
301
|
// 收口门(§2.6——链门 + §3 状态词臂 + 单测档门 + 机检门):本笔把 §1 写成「已收口」⇒ 四道同判。
|
|
258
302
|
// 段号守卫只写这一次(`STATUS_WORDS[1].closed` 只属 §1 项,`assertStatusValue` 亦拒他段该值)。
|
|
259
303
|
const closingValue = seg === 1 && stripDecorations(value) === STATUS_WORDS[1].closed
|
|
260
|
-
|
|
261
|
-
|
|
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)
|
|
262
316
|
const designTokens = closingValue ? consumeBatchDesignTokens(ctx?.agent ?? {}, abs) : null
|
|
263
|
-
|
|
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
|
|
264
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` 判据(写盘成功才增)
|
|
265
326
|
onWritten?.(ctx?.agent ?? {}, abs)
|
|
266
327
|
// 收口重锚(§6.2 · C · AC-M2-30):值余核 = §1「已收口」⇒ 本 action 就是收口 ⇒ 同调单源
|
|
267
|
-
// `reanchorOnClose`(不复制 close 径逻辑);次序位 =
|
|
268
|
-
//
|
|
269
|
-
|
|
270
|
-
|
|
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))}`
|
|
271
336
|
}
|
|
272
337
|
|
|
273
338
|
/**
|
|
@@ -276,7 +341,7 @@ export async function statusBatchRecord({ args, ctx, review, pickTarget, onWritt
|
|
|
276
341
|
* 不代写 §6 内容、不替代台账核销事务。
|
|
277
342
|
* 前提规则(#422 + §4.18-A + §2.6 四道门):① 收口门(链门 ∧ §3 状态词臂;§6 唯一缺段时拒串 = 旧 §6 串
|
|
278
343
|
* 逐字零回归);② 本批批内单测档门;③ 文档机检门;④ 无状态行档 ⇒ 自建机读位(「有行但不可解析」仍
|
|
279
|
-
* fail-closed
|
|
344
|
+
* fail-closed)。**全归档补关**(§4.18-C)只绕开 ① 的两臂,②③ 与完成清单预检、凭证消费、重锚全保留。
|
|
280
345
|
* @returns {Promise<string>} 成功消息
|
|
281
346
|
*/
|
|
282
347
|
export async function closeBatchRecord({ args, ctx, review, pickTarget, onWritten }) {
|
|
@@ -286,17 +351,30 @@ export async function closeBatchRecord({ args, ctx, review, pickTarget, onWritte
|
|
|
286
351
|
// #422③:§1 无状态行档 ⇒ 自建机读位(下行走 updateSectionStatusLine 缺失即插——同路收口);
|
|
287
352
|
// 「有行但不可解析」维持 fail-closed(assertGateOpen 拒——防误冻结)。
|
|
288
353
|
if (readBatchStatusLine(src) !== "open" && sectionHasStatusLine(src, 1)) assertGateOpen(src)
|
|
289
|
-
//
|
|
290
|
-
const
|
|
291
|
-
//
|
|
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)
|
|
292
363
|
const designTokens = consumeBatchDesignTokens(ctx?.agent ?? {}, abs)
|
|
293
364
|
const date = todayLocal()
|
|
294
|
-
|
|
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
|
|
295
368
|
writeFileSync(abs, written)
|
|
369
|
+
// 记账口径同 status 径(记「落过盘」,回档不回退)——见 `statusBatchRecord` 写盘处的注释。
|
|
370
|
+
if (ctx?.agent) ctx.agent._batchWrites = (ctx.agent._batchWrites ?? 0) + 1 // §6.6 `wrote` 判据(写盘成功才增)
|
|
296
371
|
onWritten?.(ctx?.agent ?? {}, abs)
|
|
297
372
|
// 收口重锚(§6.2 · C · AC-M2-30):顺序位 = 全部拒因通过、§1 状态行写盘**之后**——close 被拒 ⇒ 台账零写。
|
|
298
|
-
|
|
299
|
-
|
|
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))}`
|
|
300
378
|
}
|
|
301
379
|
|
|
302
380
|
// ─── 收口自动消费本批设计凭证(DESIGN-TOKEN-SETTLEMENT §10——单源,close ∥ status 两通路同调)──
|
|
@@ -334,27 +412,54 @@ export function consumeBatchDesignTokens(agent, abs) {
|
|
|
334
412
|
return { consumed, unattributed: unattributedSlotCount(agent, batches) }
|
|
335
413
|
}
|
|
336
414
|
|
|
337
|
-
/** 收口回执的凭证段(§10 回执形:单列 `[design tokens]` 一行);`null`(普通模式 no-op)⇒ 无该段。
|
|
338
|
-
|
|
415
|
+
/** 收口回执的凭证段(§10 回执形:单列 `[design tokens]` 一行);`null`(普通模式 no-op)⇒ 无该段。
|
|
416
|
+
* 导出面 = 第三条收口边(`batch-supersede.mjs`)同用:凭证消费是「从未实施」也**不豁免**的环节。
|
|
417
|
+
* 单源在此——两个入口各写一句就会成为两个格式。 */
|
|
418
|
+
export function designTokensReceiptLine(result) {
|
|
339
419
|
if (!result) return ""
|
|
340
420
|
return `\n[design tokens] 消费 ${result.consumed} 枚 · 留槽无归属 ${result.unattributed} 枚`
|
|
341
421
|
}
|
|
342
422
|
|
|
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
|
+
|
|
343
445
|
/** 收口重锚(设计档 §6.2 · C · §2.7 分流)——收口两条通路共调(同一单源,不复制逻辑);写入单源 =
|
|
344
|
-
* `ledgerReanchorBatch`(本档只供 `cwd`
|
|
446
|
+
* `ledgerReanchorBatch`(本档只供 `cwd` 基准与完成清单;工具层零 SQL)。
|
|
345
447
|
* `cwd` = **批档所属项目根** = `resolveLedgerRoot(dirname(<batchDoc>), boundary)?.root`——**不用会话锚**
|
|
346
448
|
* (多根工作区锚会收到别的项目根 ⇒ 选行零命中 ⇒ 唯一的机器写静默失效)。
|
|
347
449
|
* `boundary` = 上溯上界 = **会话锚**(**必传**——缺值即当场失败,回执以 `failed` 点名;不落进程 cwd)。无根 ⇒ 传 `null`(核心不取行、不重锚,`failed` 点名)。
|
|
348
|
-
* `batch` = 项目根相对路径(复启句的 `<批名>`
|
|
450
|
+
* `batch` = 项目根相对路径(复启句的 `<批名>` 即其文件部分)。失败**不抛**(本档的 `failed` 由调用方
|
|
451
|
+
* `ledgerAfterRecordWrite` 转成「回滚档 + 抛拒」——收口要么一起成、要么一个都不成)。
|
|
452
|
+
* `requireAllInFlight` = 完成清单那一条元判据(**无缺省**,§4.18-D「③ 的实现面」):正常两路传 `true`,
|
|
453
|
+
* 被取代的收口传 `false`(未点名的在途行走退回边)。
|
|
349
454
|
* **返回形** = `ledgerReanchorBatch` 返回形 + `newDebtReasons`(本批行中 `evidence` 带 `新事理由:` 前缀者;
|
|
350
455
|
* 取不到本批行 ⇒ 空集)——**只取不写**,格式化成回执段的是 `newDebtReasonReceiptLine`。 */
|
|
351
|
-
async function reanchorOnClose(abs, boundary) {
|
|
456
|
+
export async function reanchorOnClose(abs, boundary, completed, closeEvidence, requireAllInFlight) {
|
|
352
457
|
try {
|
|
353
458
|
const { ledgerBatchRows, ledgerReanchorBatch, resolveLedgerRoot } = await import("../ledger.mjs") // 动态 import:ledger-db 静态引 node:sqlite(W8 契约②)
|
|
354
459
|
const root = resolveLedgerRoot(dirname(abs), boundary)?.root ?? null
|
|
355
460
|
// 句内路径统一正斜杠(与 `task_book` 列值同形——`<批名>` 是给人读的事实句,不是平台路径)
|
|
356
461
|
const batch = root ? relative(root, abs).replace(/\\/g, "/") : abs
|
|
357
|
-
const result = ledgerReanchorBatch({ cwd: root, batch, boundary })
|
|
462
|
+
const result = ledgerReanchorBatch({ cwd: root, batch, boundary, completed, closeEvidence, requireAllInFlight })
|
|
358
463
|
// 新事理由读面(设计档 §6.3):本批行(任意状态)中 `evidence` 带 `新事理由:` 前缀者随返回形带回——
|
|
359
464
|
// **只引不写**(行改写语义零动);取不到本批行 ⇒ 空集(不出该段、收口不被否决,同 `failed` 降级口径)
|
|
360
465
|
let newDebtReasons = []
|
|
@@ -366,6 +471,24 @@ async function reanchorOnClose(abs, boundary) {
|
|
|
366
471
|
return { ...result, newDebtReasons }
|
|
367
472
|
} catch (e) {
|
|
368
473
|
// 非预期异常(模块加载失败 ∥ 根推导内读声明抛)同样不得否决收口——降为同一返回形(台账零写)
|
|
369
|
-
return { batch: abs,
|
|
474
|
+
return { batch: abs, settled: [], conditioned: [], alreadyAnchored: [], failed: String(e?.message ?? e), newDebtReasons: [] }
|
|
370
475
|
}
|
|
371
476
|
}
|
|
477
|
+
|
|
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)
|
|
494
|
+
}
|
|
@@ -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:既有文案逐字在前,新信息追加在后)。
|