@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
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-tools/batch-ledger-bind.mjs — 建档 = 建台账行,另含「给现役档补挂一行」(两个入口,同一件事的两次落笔;
|
|
3
|
+
* 从 `batch-lifecycle.mjs` 拆出,2026-10-27;2026-11-05 增 `attach`)。
|
|
4
|
+
*
|
|
5
|
+
* 两个入口共用同一条五步事务形态(单源 = `ledgerBindBatch`),差在步 3 写什么:`create` 写整本骨架(`wx`),
|
|
6
|
+
* `attach` 只改**已有档头那一行**(§4.21.3——重开后的档承接新事时,`create` 走不通、已核销行没有回退边)。
|
|
7
|
+
*
|
|
8
|
+
* 权威规格 = `docs/core/design/BATCH-LEDGER-REVIEW-UNIFY.md` §2.4(建档)+ `docs/core/design/BATCH-RECORD.md` §4.21.3(补挂)。
|
|
9
|
+
* 用户裁定(2026-10-27 11:40):
|
|
10
|
+
* 「如果已有台账,可以在创建时把台帐号传进去,没有就要创建台账。」——建档与台账登记不再是两步靠自觉,
|
|
11
|
+
* 是同一个动作的两次落笔:`batch({action:"create"})` 一次调用,档与行同时成立,否则两边都不成立。
|
|
12
|
+
*
|
|
13
|
+
* **步序不能换**(§2.4,第 3 轮评审的 🔴):
|
|
14
|
+
* `BEGIN IMMEDIATE` → (新建)INSERT 一行 `待讨论`(无指针、`trigger` 不填)→ `writeRecord(#N)` 写批档
|
|
15
|
+
* (`wx` 独占创建)→ `applyRowUpdateTx` 迁 `在途` + 写 `task_book`(过写门)→ `COMMIT`。
|
|
16
|
+
* 写门两形都判「解析出的档在盘」(在册旧形 ∥ 新形臂②)——先写指针、后落档,会被自己的门当场拒。
|
|
17
|
+
* `在途` 行的 DDL 咬合 CHECK(`docs/core/design/LEDGER.md` §2.2)又封死「先 INSERT `在途`、后落档」,
|
|
18
|
+
* 所以第一笔只能是一条不带指针的 `待讨论`,`待讨论 → 在途` 因此是**必经一步**。
|
|
19
|
+
*
|
|
20
|
+
* 失败清理只删**本笔所建**的档:步 3 是 `wx` 独占创建,撞已有同名档时抛 EEXIST,无条件 unlink 会删掉
|
|
21
|
+
* 别人的档(第 4 轮评审 🟡2)。`created` 旗由写回调置位,清理只认它。
|
|
22
|
+
*
|
|
23
|
+
* **attach 的失败补偿**(A4 写序套到补挂路径;与收口 ∥ 重开同一条纪律):attach 的档是**既有档**、删不得,
|
|
24
|
+
* 台账那一半失败 ⇒ 用**写前全文**(函数开头那份 `src`)回写档头,再抛拒;回写本身也失败 ⇒ 出第二条串并
|
|
25
|
+
* 点名半状态(两条串各一个导出,互不复用)。零写的两支不回写:`already` 支(号本来就在列表里)与所有
|
|
26
|
+
* 写前拒(门态 / 同面 / `BEGIN IMMEDIATE` / 档头写本身失败)——那几处没有半状态,回写只会抹掉别人这一
|
|
27
|
+
* 窗口里加的号。
|
|
28
|
+
*
|
|
29
|
+
* 依赖单向(KD-4):`skeleton ← closeout ← bind ← reopen ← lifecycle`——本档不 import lifecycle。
|
|
30
|
+
*/
|
|
31
|
+
import { execFileSync } from "node:child_process"
|
|
32
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs"
|
|
33
|
+
import { tmpdir } from "node:os"
|
|
34
|
+
import { basename, dirname, join, relative, resolve } from "node:path"
|
|
35
|
+
|
|
36
|
+
import { appendLedgerNoToHeader, batchSkeleton, readBatchStatusLine } from "./batch-skeleton.mjs"
|
|
37
|
+
import { resolveBatchCreatePath } from "./batch-paths.mjs"
|
|
38
|
+
// B8(TOOLS.md §6.29 ④):父会话历史窗口起点(建批成功即记一次)
|
|
39
|
+
import { recordBatchHistoryStart } from "./read-history.mjs"
|
|
40
|
+
|
|
41
|
+
/** 可读文件判据(存在且为文件——目录/缺失同判不可读;与主档同名 helper 同型——KD-4 单向依赖下各自持有,
|
|
42
|
+
* 三行谓词不构成第二权威源)。 */
|
|
43
|
+
function readableFile(abs) {
|
|
44
|
+
try { return existsSync(abs) && statSync(abs).isFile() } catch { return false }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** main-agent-only 门(BR-19/BR-24):create 仅 depth-0 放行(eng 子代理 / 评审皆拒)。 */
|
|
48
|
+
function assertMainAgentOnly(ctx, action, review) {
|
|
49
|
+
if (review || ctx?.depth !== 0) {
|
|
50
|
+
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).`)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 档头可选参归一(`board`):trim ∥ 单行(拒句逐字)∥ 空串 ≡ 未给(null)。两个开户动作(create ∥ attach)
|
|
55
|
+
* 共用一份——同一件事不各写一个串;串内不点名动作(点名就把两个动作又分开写两份了)。 */
|
|
56
|
+
function normalizeBoard(raw) {
|
|
57
|
+
const v = typeof raw === "string" ? raw.trim() : ""
|
|
58
|
+
if (!v) return null
|
|
59
|
+
if (/\r?\n/.test(v)) {
|
|
60
|
+
throw new Error("batch: board must be a single line — a multi-line value would break the header's 台账 line. Nothing was written.")
|
|
61
|
+
}
|
|
62
|
+
return v
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** `ledger` 参解析:缺省 / 空 ⇒ `null`(新建一行);否则取行号(`#1830` ∥ `1830` ∥ 数字)。 */
|
|
66
|
+
function parseLedgerNo(raw) {
|
|
67
|
+
const v = typeof raw === "string" ? raw.trim() : raw
|
|
68
|
+
if (v == null || v === "") return null
|
|
69
|
+
const m = /^#?\s*(\d+)$/.exec(String(v).trim())
|
|
70
|
+
if (!m) {
|
|
71
|
+
throw new Error(`batch: ledger must be a ledger entry number (e.g. "#1830") — got ${JSON.stringify(raw)}. Pass an existing number, or omit ledger — with no unsettled row on the same face that opens a new row; otherwise pass newDebt:"<why this is a new debt>". Nothing was written.`)
|
|
72
|
+
}
|
|
73
|
+
return Number(m[1])
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** `newDebt` 参归一(设计档 §6.3「参数面」):trim;空串 / 全空白 ⇒ `null`(按未给判——没声明新事)。 */
|
|
77
|
+
function normalizeNewDebt(raw) {
|
|
78
|
+
const v = typeof raw === "string" ? raw.trim() : ""
|
|
79
|
+
return v || null
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 同面判回执增量(设计档 §6.3「回执增量(成功路径)」逐字):面名 + 本面未决数 + 他面未决读数。
|
|
83
|
+
* `n = 0` 半幅也打(免得把「本面无候选」读成「池子空」——他面读数同列);接手路径无此段(该径零判)。
|
|
84
|
+
* `declared` 缺省 ⇒ `—`(本仓「无值」的既有形,同档头 `台账 = #N(… · —)`)。 */
|
|
85
|
+
function sameFaceReceiptLine(check) {
|
|
86
|
+
if (!check) return ""
|
|
87
|
+
return `\nsame-face check: face = ${check.face ?? "no board"} · unsettled on this face = ${check.n} (n = 0 ⇒ nothing to take over; n > 0 ⇒ declared a new debt: ${check.declared ?? "—"}) · unsettled on other faces = ${check.m} (a reading; never blocks).`
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 批起快照的 ref 前缀(`refs/thincoder/baseline/<批档名>`):ref 只负责让那个游离提交不被 `git gc` 回收,
|
|
91
|
+
* 不是取内容的入口——收口读内容照旧走记入行的 sha(`docs/core/design/DOC-CHECK.md` §8)。 */
|
|
92
|
+
const BASELINE_REF_PREFIX = "refs/thincoder/baseline/"
|
|
93
|
+
|
|
94
|
+
/** 批档名 → ref 末段:去 `.md`;git ref 禁用字符(空白 ∥ 波浪号 ∥ 尖号 ∥ 冒号 ∥ 问号 ∥ 星号 ∥ 方括号 ∥ 反斜杠)换成 `-`,
|
|
95
|
+
* `..` 折叠,首尾的 `.` ∥ `-` 剔掉。 */
|
|
96
|
+
function baselineRefOf(abs) {
|
|
97
|
+
const name = basename(abs).replace(/\.md$/i, "")
|
|
98
|
+
const safe = name.replace(/[\s~^:?*[\\]/g, "-").replace(/\.\.+/g, ".").replace(/^[.-]+|[.-]+$/g, "")
|
|
99
|
+
return `${BASELINE_REF_PREFIX}${safe === "" ? "batch" : safe}`
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 批起快照(`docs/core/design/DOC-CHECK.md` §8「快照怎么取」)= 建档那一刻**工作树的形状**,不是「已提交的那一份」:
|
|
104
|
+
* `read-tree HEAD` → `add -A` → `write-tree` → `commit-tree -p HEAD`,全程走**临时索引**,不碰工作区、不动真索引。
|
|
105
|
+
* 临时索引住仓外(放仓里会被 `add -A` 自己收进树里,快照多出两个不存在的档)。
|
|
106
|
+
* `add -A` 只走**项目根那一段路径**(项目根住大仓子目录时):判域与 §2 清单都以项目根为界,根外那些脏档
|
|
107
|
+
* 进不进基线对判据没有意义,而全仓 `add -A` 会把无关改动整片扫一遍。
|
|
108
|
+
* 建好挂 `refs/thincoder/baseline/<批档名>`:`commit-tree` 产出的是**游离提交**,没有 ref 指着它,`gc` 一收就没了
|
|
109
|
+
* ——批档里写一个随时会消失的 sha,等于把基线建在沙上。
|
|
110
|
+
* 为什么不用 `git stash create`:它只收已跟踪的改动,未跟踪档不入快照 ⇒ 每个未跟踪码档都开一个「不必量」的口。
|
|
111
|
+
* @returns {{sha:string}|{error:string}} 提交号 ∥ 取不到的原因(调用方写进 §1,不伪造)
|
|
112
|
+
*/
|
|
113
|
+
function batchStartSnapshot(root, abs) {
|
|
114
|
+
// 身份显式给定:`commit-tree` 要它,而快照提交的作者不是本机制要记的事——不靠全局 git 配置(没有时会静默失败)。
|
|
115
|
+
const git = (cwd, argv, env) => execFileSync(
|
|
116
|
+
"git", ["-C", cwd, "-c", "user.name=thincoder-batch", "-c", "user.email=batch@thincoder.local", ...argv],
|
|
117
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], timeout: 30000, env },
|
|
118
|
+
)
|
|
119
|
+
const why = (e) => String(e?.stderr ?? e?.message ?? e).split(/\r?\n/).find((l) => l.trim() !== "") ?? "未知"
|
|
120
|
+
let tmpDir = null
|
|
121
|
+
try {
|
|
122
|
+
const top = git(root, ["rev-parse", "--show-toplevel"]).trim() || root
|
|
123
|
+
// 项目根在仓里的路径(`''` = 项目根就是仓根);仓根就是项目根时走 `.`。
|
|
124
|
+
const scope = relative(top, resolve(root)).replace(/\\/g, "/")
|
|
125
|
+
tmpDir = mkdtempSync(join(tmpdir(), "thincoder-batch-index-"))
|
|
126
|
+
const env = { ...process.env, GIT_INDEX_FILE: join(tmpDir, "index") }
|
|
127
|
+
git(top, ["read-tree", "HEAD"], env)
|
|
128
|
+
git(top, ["add", "-A", "--", scope === "" || scope.startsWith("..") ? "." : scope], env) // 未跟踪档一并入树:「上一批建好、还没提交」正是本仓的常见形状
|
|
129
|
+
const tree = git(top, ["write-tree"], env).trim()
|
|
130
|
+
if (!/^[0-9a-f]{40,64}$/i.test(tree)) return { error: "git write-tree 未返回树号" }
|
|
131
|
+
const sha = git(top, ["commit-tree", tree, "-p", "HEAD", "-m", "batch-start snapshot"], env).trim()
|
|
132
|
+
if (!/^[0-9a-f]{40,64}$/i.test(sha)) return { error: "git commit-tree 未返回提交号" }
|
|
133
|
+
git(top, ["update-ref", baselineRefOf(abs), sha], env)
|
|
134
|
+
return { sha }
|
|
135
|
+
} catch (e) {
|
|
136
|
+
return { error: why(e) }
|
|
137
|
+
} finally {
|
|
138
|
+
if (tmpDir !== null) {
|
|
139
|
+
try { rmSync(tmpDir, { recursive: true, force: true }) } catch { /* 临时索引清不掉不改业务结果 */ }
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* 建档前的基线 sha(`§1` 记入行 `批起 sha = <sha>` 的值):单源 = 全树快照(`docs/core/design/DOC-CHECK.md` §8)。
|
|
146
|
+
* 取不到 ⇒ `未取到(原因)`,**绝不退回 HEAD**:HEAD 只是一份提交,未跟踪 ∥ 未提交的改动不在其中;拿它当基线,
|
|
147
|
+
* 任何带着未提交改动的档读数都对不上——门会拒掉一个完全没错的设计席(§8 拒文样里那句「拿已提交的 HEAD
|
|
148
|
+
* 当(了)基线」正是这个错)。取不到就不给基准,收口按「批起基线不可判」拒:放行等于没核。
|
|
149
|
+
*/
|
|
150
|
+
function baseShaForCreate(root, abs) {
|
|
151
|
+
const snap = batchStartSnapshot(root, abs)
|
|
152
|
+
return snap.sha ?? `未取到(${snap.error})`
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* create——建档(§4.11 + §2.4,仅 depth-0):六段骨架一次预齐,台账行同拍成立。
|
|
157
|
+
* 不传 `ledger` ⇒ 新建一行(`在途` · `kind` = `board` 给则 `requirement` 否则 `tech_todo` · `title` = `topic` ·
|
|
158
|
+
* `task_book` = 本档相对指针 · `trigger` = 归批)——**同面(本笔 `board`)无未决行时如此;有则须 `newDebt:"<一句理由>"`,
|
|
159
|
+
* 两者皆无 ⇒ 拒并列候选**(设计档 `docs/core/design/LEDGER.md` §6.3);传 `#N` ⇒ 接管该行(`待讨论` / `待设计` → `在途`;
|
|
160
|
+
* `在途` 且指针指回本档 ⇒ 零台账写;其余 ⇒ 三形拒文,见 §2.4)。
|
|
161
|
+
* 档头 `台账` 行由**真实行号**填(`board` 未给 ⇒ 括注 `—`,不拒)。
|
|
162
|
+
* @returns {Promise<string>} 成功消息(含落盘绝对路径、行号与同面判读数)
|
|
163
|
+
*/
|
|
164
|
+
export async function createBatchRecord({ args, ctx, review, cwd, bases, onWritten }) {
|
|
165
|
+
assertMainAgentOnly(ctx, "create", review)
|
|
166
|
+
const raw = typeof args?.path === "string" ? args.path.trim() : ""
|
|
167
|
+
if (!raw) {
|
|
168
|
+
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.")
|
|
169
|
+
}
|
|
170
|
+
if (!/\.md$/.test(raw)) {
|
|
171
|
+
throw new Error(`batch: create path must end in .md — got ${JSON.stringify(raw)} (fail-closed: non-markdown targets are refused). Nothing was written.`)
|
|
172
|
+
}
|
|
173
|
+
const primary = bases?.[0]
|
|
174
|
+
if (!primary) {
|
|
175
|
+
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.")
|
|
176
|
+
}
|
|
177
|
+
const abs = resolveBatchCreatePath(cwd, raw, bases)
|
|
178
|
+
if (readableFile(abs)) {
|
|
179
|
+
throw new Error(`batch: create target already exists — refusing to overwrite an existing batch record (fail-closed, BR-20): ${raw}`)
|
|
180
|
+
}
|
|
181
|
+
const topic = typeof args?.topic === "string" && args.topic.trim() ? args.topic.trim() : null
|
|
182
|
+
if (!topic) {
|
|
183
|
+
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.")
|
|
184
|
+
}
|
|
185
|
+
const source = typeof args?.source === "string" ? args.source.trim() : ""
|
|
186
|
+
if (!source) {
|
|
187
|
+
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.")
|
|
188
|
+
}
|
|
189
|
+
if (/\r?\n/.test(source)) {
|
|
190
|
+
throw new Error("batch: create source must be a single line — a multi-line source would break the header's 编制 line. Nothing was written.")
|
|
191
|
+
}
|
|
192
|
+
const board = normalizeBoard(args?.board)
|
|
193
|
+
const ledgerNo = parseLedgerNo(args?.ledger)
|
|
194
|
+
const newDebt = normalizeNewDebt(args?.newDebt)
|
|
195
|
+
const date = typeof args?.date === "string" && args.date.trim() ? args.date.trim() : todayLocalIso()
|
|
196
|
+
// F11-B:prev 幂等 strip——调用方自带「前情 = 」前缀(单或重复)一并剥净;默认值形态「零变」。
|
|
197
|
+
const prevRaw = typeof args?.prev === "string" ? args.prev.trim() : ""
|
|
198
|
+
const prev = prevRaw ? (prevRaw.replace(/^(?:前情\s*[=::]\s*)+/g, "").trim() || "无(独立批)") : "无(独立批)"
|
|
199
|
+
// 模式位执行期实读(§4.16——骨架取形时点 = 建档即固;翻转不回写既有骨架)
|
|
200
|
+
const mode = ctx?.agent?.config?.agent?.engineering ? "engineering" : "normal"
|
|
201
|
+
const anchor = cwd ?? ctx?.agent?.cwd
|
|
202
|
+
const created = { flag: false }
|
|
203
|
+
|
|
204
|
+
// 台账链只经动态 import(ledger-db.mjs 静态引 node:sqlite ⇒ 消费侧静态 import 破 W8 契约②)
|
|
205
|
+
const { ledgerBindBatch, resolveLedgerRoot } = await import("../ledger.mjs")
|
|
206
|
+
const root = resolveLedgerRoot(dirname(abs), anchor)?.root ?? null
|
|
207
|
+
if (!root) {
|
|
208
|
+
throw new Error(`batch: the new record's project root cannot be derived — the ledger row cannot be opened without it (fail-closed). Path: ${abs}. Nothing was written.`)
|
|
209
|
+
}
|
|
210
|
+
const taskBook = relative(root, abs).replace(/\\/g, "/")
|
|
211
|
+
const baseSha = baseShaForCreate(root, abs)
|
|
212
|
+
// executor = 本会话(AC-M2-7「进入在途的迁移带 executor = 会话 sessionId」)——与 `ledger-tools.mjs` 同一取值面
|
|
213
|
+
let executorSessionId = null
|
|
214
|
+
try { executorSessionId = (await import("../session-slots.mjs")).getSessionId() } catch { executorSessionId = null }
|
|
215
|
+
mkdirSync(dirname(abs), { recursive: true })
|
|
216
|
+
const writeRecord = (id) => {
|
|
217
|
+
try {
|
|
218
|
+
writeFileSync(abs, batchSkeleton({ date, topic, source, prev, baseSha, ledger: `#${id}`, board, mode }), { flag: "wx" })
|
|
219
|
+
} catch (e) {
|
|
220
|
+
if (e?.code === "EEXIST") {
|
|
221
|
+
throw new Error(`batch: create target already exists — refusing to overwrite an existing batch record (fail-closed, BR-20): ${raw}`)
|
|
222
|
+
}
|
|
223
|
+
throw e
|
|
224
|
+
}
|
|
225
|
+
created.flag = true
|
|
226
|
+
if (ctx?.agent) ctx.agent._batchWrites = (ctx.agent._batchWrites ?? 0) + 1 // §6.6 `wrote` 判据(建档写盘成功才增)
|
|
227
|
+
onWritten?.(ctx?.agent ?? {}, abs)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
let result
|
|
231
|
+
try {
|
|
232
|
+
result = await ledgerBindBatch({
|
|
233
|
+
cwd: root,
|
|
234
|
+
ledgerNo,
|
|
235
|
+
newDebt,
|
|
236
|
+
targetAbs: abs,
|
|
237
|
+
taskBook,
|
|
238
|
+
title: topic,
|
|
239
|
+
kind: board ? "requirement" : "tech_todo",
|
|
240
|
+
board,
|
|
241
|
+
boundary: anchor,
|
|
242
|
+
executorSessionId,
|
|
243
|
+
agent: ctx?.agent ?? {},
|
|
244
|
+
}, writeRecord)
|
|
245
|
+
} catch (e) {
|
|
246
|
+
// 失败清理只删本笔所建的档(`created` 旗——撞同名档时我们什么都没建,不得 unlink 别人的档)。
|
|
247
|
+
// 拒文只写当场握有的事实:台账未走到 COMMIT;档那一半按 unlink 的实际结果报,不断言 ROLLBACK 成功。
|
|
248
|
+
let recordResult = ""
|
|
249
|
+
if (created.flag) {
|
|
250
|
+
try {
|
|
251
|
+
unlinkSync(abs)
|
|
252
|
+
recordResult = `本笔所建的档已删 ${abs}`
|
|
253
|
+
} catch (unlinkErr) {
|
|
254
|
+
recordResult = `档残留 ${abs}(清理失败:${unlinkErr?.message ?? unlinkErr})`
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (!recordResult) throw e // 写前拒保持原串;本笔尚未落档,不另加清理结果。
|
|
258
|
+
throw new Error(`${e?.message ?? e}\n(台账事务未提交:本笔未走到 COMMIT;${recordResult})`)
|
|
259
|
+
}
|
|
260
|
+
const took = result.claimed
|
|
261
|
+
? "claimed (a reserved row pointing at this path is now this record's row — no new row was opened)"
|
|
262
|
+
: result.tookOver === "new" ? "opened" : result.tookOver === "live" ? "taken over (already live — zero ledger write)" : "taken over"
|
|
263
|
+
// B8(TOOLS.md §6.29 ④):父会话历史窗口的起点 = 本批创建时刻(depth-0 根 agent 上按规范化批档存)。
|
|
264
|
+
// 旧批没有起点时由首次绑定 spawn 记一次(`subagent-spawn.mjs`)——那里不回填更早的消息。
|
|
265
|
+
recordBatchHistoryStart(ctx?.agent, abs, Date.now())
|
|
266
|
+
return `batch: created ${abs} — six-section skeleton written (§1 status line carries the gate-legal 「进行中」 placeholder); ledger row #${result.id} ${took} in the same call (row status = 在途 · task_book = ${taskBook} · trigger = 归批). header 台账 line filled (#${result.id} · ${board ?? "—"}).${sameFaceReceiptLine(result.sameFace)}`
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** 本地今天(YYYY-MM-DD)——create 的缺省 date。 */
|
|
270
|
+
function todayLocalIso() {
|
|
271
|
+
const d = new Date()
|
|
272
|
+
const p = (n) => String(n).padStart(2, "0")
|
|
273
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// ─── attach——给现役档补挂台账行(§4.21.3 · 仅 depth-0)──────────────────────────────────
|
|
277
|
+
|
|
278
|
+
/** 门态拒串(attach 前置 = 目标档门态 `进行中`):已收口 ⇒ 两条路(先重开再 attach ∥ 另起新批);
|
|
279
|
+
* §1 段头区不可解析 ⇒ fail-closed 同判(与其余写门一条口径——修 = 普通文档写)。 */
|
|
280
|
+
const attachClosedError = () => "batch: attach refused — the record is frozen (§1 status line carries 「已收口」). Two ways on: reopen it first (batch status §1 → 进行中 with note = the reason, which appends the reopen record) and then attach; or start a new batch record (create) instead. Nothing was written."
|
|
281
|
+
const attachUnresolvedError = () => "batch: attach refused — the record has no readable §1 status line inside its section header zone (zero lines or two or more; fail-closed, the same judgement every other write gate makes). Repair the §1 zone with an ordinary document write so it holds exactly one status line, then attach. Nothing was written."
|
|
282
|
+
/** attach 的台账失败拒文(第一条串,逐字——档头已回写到写前字节,故可原样重试):写序与收口 ∥ 重开同一条
|
|
283
|
+
* (档先写、台账后写;台账回滚由 `ledgerBindBatch` 自己做),本档只负责把档那一半回档并喊出来。 */
|
|
284
|
+
export function attachLedgerFailedError(cause) {
|
|
285
|
+
return `batch: attach failed — 台账事务未提交(${cause});档头已回滚到写前字节,可原样重试。Ledger: no committed change from this call (it never reached COMMIT).`
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** attach 的补偿也失败拒文(同节第二条串——**不得复用第一条**:第一条声称已回滚,此时事实相反):
|
|
289
|
+
* 残态 = 档头留着 `#N`、台账无该行;`check` 以第六类 `header-row-missing` 点名。 */
|
|
290
|
+
export function attachHalfStateError(abs, id, cause, rollbackCause) {
|
|
291
|
+
return `batch: attach failed — 台账事务未提交(${cause});档头回滚也失败(${rollbackCause})——半状态成立:档头留着 #${id},台账里没有这一行。` +
|
|
292
|
+
`Read it with batch({action:"check", path:"${abs}"}) — it names header-row-missing; repair by dropping #${id} from the header 台账 line (an ordinary document write), or run attach again.`
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** 开新行缺标题拒串(`title` 只在**开新行**时必填——接管既有行的标题已在行上)。 */
|
|
296
|
+
const attachTitleError = () => "batch: attach needs title when it opens a new ledger row — the row's title says what this new debt is: a reopened record takes on a new piece of work, and reusing the batch's own subject would make the ledger read it as a second copy of the original debt. Pass title:\"<one line>\", or take over an existing unsettled row with ledger:\"#<id>\". Nothing was written."
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* attach——给**已存在**的现役批档补挂台账行(设计档 §4.21.3;仅 depth-0,与 `create` / `close` 同一道身份判据)。
|
|
300
|
+
* 场景:档重开(§4.18-B)后承接一件新事——`create` 只对新档开放(目标已存在 ⇒ 拒),已核销行没有回退边 ⇒
|
|
301
|
+
* 今天只剩「另起一本新档」或「跑完一整轮而不记任何债」,两种都把重开的意义抽掉。
|
|
302
|
+
*
|
|
303
|
+
* 五步事务形态与 `create` 同一条(事务与同面判的单源 = `ledgerBindBatch`——本档只提供回调):
|
|
304
|
+
* `BEGIN IMMEDIATE` → (新建)INSERT 一行 `待讨论` → **回调写档头台账行**(步 3 与 create 的差别只在这里:
|
|
305
|
+
* 它改的是已有档头一行,不是整本档的模板)→ 迁 `在途` + 写 `task_book` → `COMMIT`。
|
|
306
|
+
*
|
|
307
|
+
* 两条与 create 不同的判据:
|
|
308
|
+
* - **不挂 F11-C 死占位门**(J1 的例外):档头仍带 `#<编号>` 占位的档,`edit` 被件① 挡着,而这本档在台账侧
|
|
309
|
+
* 已经是真档——`attach` 正是把死占位换成真编号的那条通道,⇒ 它必须放行并**填掉**占位,填完 `edit` 随之打开。
|
|
310
|
+
* - **不动已核销行**(J4):只开新行或接管未决行;核销过的行没有回退边(`ledgerBindBatch` 已拒归档 / 待核销行)。
|
|
311
|
+
*
|
|
312
|
+
* 幂等:行号已在档头列表 ⇒ 零写 + 回执点名「已在列表」——为的是同一个回调在 `ledgerBindBatch` 的
|
|
313
|
+
* 「行已 live、零台账写」分支上也安全(重放 `attach{ledger:"#N"}` 落到的就是那条)。
|
|
314
|
+
* 拒面(全 fail-closed:档零字节 / 台账零写):门态非 `进行中` · 档头 `台账` 行缺失 · 本面有未决行而无 `newDebt` ·
|
|
315
|
+
* 开新行而缺 `title` · 台账库不可达 ∥ 事务失败。
|
|
316
|
+
* **台账事务失败**(写档头之后那一半)⇒ 用写前全文回写档头再抛拒(第一条串);回写也失败 ⇒ 第二条串点名
|
|
317
|
+
* 半状态(档头留号 ∥ 台账无该行)。零写的两支不回写(`already` ∥ 写前拒)——见本档头注释。
|
|
318
|
+
* @returns {Promise<string>} 成功消息(含行号、改写后的档头行与同面判读数)
|
|
319
|
+
*/
|
|
320
|
+
export async function attachBatchRecord({ args, ctx, review, cwd, pickTarget, onWritten }) {
|
|
321
|
+
assertMainAgentOnly(ctx, "attach", review)
|
|
322
|
+
const abs = pickTarget(args?.path)
|
|
323
|
+
const src = readFileSync(abs, "utf8")
|
|
324
|
+
const gate = readBatchStatusLine(src)
|
|
325
|
+
if (gate === "closed") throw new Error(attachClosedError())
|
|
326
|
+
if (gate === "unknown") throw new Error(attachUnresolvedError())
|
|
327
|
+
const board = normalizeBoard(args?.board)
|
|
328
|
+
const ledgerNo = parseLedgerNo(args?.ledger)
|
|
329
|
+
const newDebt = normalizeNewDebt(args?.newDebt)
|
|
330
|
+
const title = typeof args?.title === "string" && args.title.trim() ? args.title.trim() : null
|
|
331
|
+
if (title && /\r?\n/.test(title)) {
|
|
332
|
+
throw new Error("batch: attach title must be a single line — the row title is one line, and a multi-line value would break the receipt and the ledger listing. Nothing was written.")
|
|
333
|
+
}
|
|
334
|
+
if (ledgerNo == null && !title) throw new Error(attachTitleError())
|
|
335
|
+
const anchor = cwd ?? ctx?.agent?.cwd
|
|
336
|
+
const { ledgerBindBatch, resolveLedgerRoot } = await import("../ledger.mjs")
|
|
337
|
+
const root = resolveLedgerRoot(dirname(abs), anchor)?.root ?? null
|
|
338
|
+
if (!root) {
|
|
339
|
+
throw new Error(`batch: the record's project root cannot be derived — the ledger row cannot be opened without it (fail-closed). Path: ${abs}. Nothing was written.`)
|
|
340
|
+
}
|
|
341
|
+
const taskBook = relative(root, abs).replace(/\\/g, "/")
|
|
342
|
+
// executor = 本会话(AC-M2-7,与 create 同一取值面)
|
|
343
|
+
let executorSessionId = null
|
|
344
|
+
try { executorSessionId = (await import("../session-slots.mjs")).getSessionId() } catch { executorSessionId = null }
|
|
345
|
+
/** `wrote` = 本笔**落过盘**(回档不回退——口径同 `batch-lifecycle.mjs` 的记账注释);`already` ⇒ 恒 `false`。 */
|
|
346
|
+
const header = { id: null, line: null, already: false, wrote: false }
|
|
347
|
+
/** 步 3(回调):把真实行号补进档头 `台账` 行。已在列表 ⇒ 零写(幂等);写盘成功才记 `_batchWrites`。 */
|
|
348
|
+
const writeHeader = (id) => {
|
|
349
|
+
const current = readFileSync(abs, "utf8")
|
|
350
|
+
const edited = appendLedgerNoToHeader(current, id)
|
|
351
|
+
header.id = id
|
|
352
|
+
header.line = edited.line
|
|
353
|
+
if (edited.already) { header.already = true; return }
|
|
354
|
+
writeFileSync(abs, edited.src)
|
|
355
|
+
header.wrote = true
|
|
356
|
+
if (ctx?.agent) ctx.agent._batchWrites = (ctx.agent._batchWrites ?? 0) + 1 // §6.6 `wrote` 判据(写盘成功才增)
|
|
357
|
+
onWritten?.(ctx?.agent ?? {}, abs)
|
|
358
|
+
}
|
|
359
|
+
let result
|
|
360
|
+
try {
|
|
361
|
+
result = await ledgerBindBatch({
|
|
362
|
+
cwd: root,
|
|
363
|
+
ledgerNo,
|
|
364
|
+
newDebt,
|
|
365
|
+
targetAbs: abs,
|
|
366
|
+
taskBook,
|
|
367
|
+
title: title ?? "",
|
|
368
|
+
kind: board ? "requirement" : "tech_todo",
|
|
369
|
+
board,
|
|
370
|
+
boundary: anchor,
|
|
371
|
+
executorSessionId,
|
|
372
|
+
agent: ctx?.agent ?? {},
|
|
373
|
+
}, writeHeader)
|
|
374
|
+
} catch (e) {
|
|
375
|
+
// 台账那一半由 `ledgerBindBatch` 自己 ROLLBACK;档这一半是本档的账——**既有档删不得,只能回写**。
|
|
376
|
+
// 回写用函数开头那份**全文**(`src`),不做「把号删掉」的局部手术:局部手术会碰坏档头其余字节。
|
|
377
|
+
// 零写的两支不回写:`already` 支(号本来就在列表里,回写等于把别的会话刚加的号抹掉)与所有写前拒
|
|
378
|
+
// (门态 / 同面 / `BEGIN IMMEDIATE` / 档头写本身失败)——那几处没有半状态可报,原样上抛。
|
|
379
|
+
if (!header.wrote) throw e
|
|
380
|
+
const cause = String(e?.message ?? e)
|
|
381
|
+
try {
|
|
382
|
+
writeFileSync(abs, src)
|
|
383
|
+
} catch (rollbackErr) {
|
|
384
|
+
throw new Error(attachHalfStateError(abs, header.id, cause, String(rollbackErr?.message ?? rollbackErr)))
|
|
385
|
+
}
|
|
386
|
+
throw new Error(attachLedgerFailedError(cause))
|
|
387
|
+
}
|
|
388
|
+
const head = header.already
|
|
389
|
+
? `batch: ledger row #${result.id} is already in the header 台账 line of ${abs} — zero write (idempotent: the row is live and already listed; nothing changed).`
|
|
390
|
+
: `batch: attached ledger row #${result.id} to ${abs} — header 台账 line is now \`${header.line}\` (row status = 在途 · task_book = ${taskBook} · trigger = 归批).`
|
|
391
|
+
return `${head}${sameFaceReceiptLine(result.sameFace)}`
|
|
392
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-tools/batch-ledger-link.mjs — 账链门判据(设计单源 = `docs/core/design/ADVISOR-GUARDS.md` §2 第 7 条):
|
|
3
|
+
* 一本已解析成绝对路径的批档,台账里还有没有**至少一行未决行**的 `task_book` 指着它。
|
|
4
|
+
*
|
|
5
|
+
* 为什么另立本档(设计档同条「三问(新档)」):
|
|
6
|
+
* - `resolveBatchRows`(`thincoder-core/ledger-write-ops.mjs`)= 选行判据**单源**,直接复用(判同址、不判串等值
|
|
7
|
+
* ——同一批档的三种指针写法并存,串等值会漏行);「未决」= `PENDING_STATUSES`(`thincoder-core/ledger-db.mjs`)
|
|
8
|
+
* ——产品的未决定义已存在一处,另立词表 = 第二份词表(漂移源);
|
|
9
|
+
* - `ledgerBindBatch`(`thincoder-core/agent-tools/batch-ledger-bind.mjs`)是**写面绑定**(入参 = 行号 + 批档,
|
|
10
|
+
* 出参 = 写入结果),把读判据塞进去会让「建档绑行」与「点火读账」两件事共用一个出口;
|
|
11
|
+
* - 读面包装 `ledgerBatchRows` 不能直接复用:无根即抛、库不在即返回空集——本门要在同一个出口把
|
|
12
|
+
* 「无根 ∥ 库不在盘 ∥ 坏档 ∥ 零行」四形分开报(`reason` 三值 + `db` 读数),且**四形全落「拒」**、
|
|
13
|
+
* 零路径落「放行」(`if (!db) 放行` 把「账读不到」判成「账不必看」,与本档用途相反)。
|
|
14
|
+
*
|
|
15
|
+
* 台账链一律**动态 import**(`thincoder-core/ledger-db.mjs` 静态引 `node:sqlite` ⇒ 消费侧静态 import 破 W8 契约②;
|
|
16
|
+
* 手法同 `thincoder-core/agent-tools/batch-ledger-bind.mjs`):本档零静态仓内依赖,可被工具层静态引用。
|
|
17
|
+
*
|
|
18
|
+
* 读面零写:只读开库(`readOnly: true` ⇒ 零 DDL / 零 ALTER / 零 `markSchemaVersion`)——门读账不建库、不改库。
|
|
19
|
+
* 零模式位:本档不读模式位、无模式分支、无豁免分支(判据是「做没做评审」,不是「什么模式」)。
|
|
20
|
+
*/
|
|
21
|
+
import { existsSync } from "node:fs"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 账链判据(**纯读**——一次根解析 → 只读开库 → 选行 → 未决过滤 → 关库;不抛业务异常)。
|
|
25
|
+
*
|
|
26
|
+
* 读序单源 = 设计档 §2 第 7 条「读序」五步:`resolveLedgerRoot(batchDocAbs, anchor)` →
|
|
27
|
+
* `openLedger(root, { readOnly: true, boundary: anchor })` → `resolveBatchRows(db, root, batchDocAbs)` →
|
|
28
|
+
* `PENDING_STATUSES` 过滤 → `db.close()`(finally)。
|
|
29
|
+
*
|
|
30
|
+
* @param {{batchDocAbs: string, anchor: string}} o `batchDocAbs` = 批档绝对路径(已由 `resolveBatchDocPath` 解析);
|
|
31
|
+
* `anchor` = 会话锚(`agent.cwd`——与 `openLedger` 同一枚上界:同一笔动作的判据不设两界)
|
|
32
|
+
* @returns {Promise<{ok: boolean, reason: string|null, root: string|null, dbFile: string|null,
|
|
33
|
+
* db: "open"|"not-on-disk"|"unreadable"|null, rows: number, unsettled: number}>}
|
|
34
|
+
* `ok` = 放行;`reason` = 三值之一(`ok` 时 null);`root` / `dbFile` / `db` / `rows` / `unsettled` = 拒文
|
|
35
|
+
* `Record:` 行的读数——`db` 一项决定修复路径能不能选(`not on disk` 时库里没有可改的行)
|
|
36
|
+
*/
|
|
37
|
+
export async function resolveBatchLedgerLink({ batchDocAbs, anchor }) {
|
|
38
|
+
// 台账族导出面(`thincoder-core/ledger.mjs` = 公共面单源)+ 选行单源(`resolveBatchRows` 只从拆分件导出——
|
|
39
|
+
// 族面只 re-export 了它的包装 `ledgerBatchRows`,那个包装把「无根 ∥ 库不在」两种成因并成抛 / 空集)
|
|
40
|
+
const { ledgerDbPath, openLedger, PENDING_STATUSES, resolveLedgerRoot } = await import("../ledger.mjs")
|
|
41
|
+
const { resolveBatchRows } = await import("../ledger-write-ops.mjs")
|
|
42
|
+
|
|
43
|
+
const derived = resolveLedgerRoot(batchDocAbs, anchor)
|
|
44
|
+
const root = derived?.root ?? null
|
|
45
|
+
let dbFile = null
|
|
46
|
+
if (root) { try { dbFile = ledgerDbPath(root, anchor) } catch { dbFile = null } }
|
|
47
|
+
/** 拒形(四形共用一处形状——读数缺省值集中在这里,不在每个 return 各写一遍)。
|
|
48
|
+
* `reason` 三值 = `no-pending-row` / `no-ledger-root` / `ledger-unreadable`(同一拒发口靠 reason 分叉,
|
|
49
|
+
* 不另立 criterion——单源 = 设计档 §2 第 7 条「失败路径全落拒」表)。 */
|
|
50
|
+
const refuse = (reason, extra = {}) => ({ ok: false, reason, root, dbFile, db: null, rows: 0, unsettled: 0, ...extra })
|
|
51
|
+
|
|
52
|
+
if (!root) return refuse("no-ledger-root") // 批档不在任何已注册项目内 ∥ 会话锚外 ⇒ 零行可判
|
|
53
|
+
|
|
54
|
+
let db = null
|
|
55
|
+
try {
|
|
56
|
+
db = openLedger(root, { readOnly: true, boundary: anchor })
|
|
57
|
+
} catch {
|
|
58
|
+
return refuse("ledger-unreadable", { db: "unreadable" }) // 坏档 ∥ 目录不在 ⇒ 门内 catch(不 throw 外逸)
|
|
59
|
+
}
|
|
60
|
+
// 库不在盘(`not on disk`)∥ 非台账库(档在盘、无 items 表 ⇒ 读不成台账 ⇒ `unreadable`):
|
|
61
|
+
// 两形同为 `no-pending-row`(零行可判 = 这条账不存在),`db` 读数把成因分开
|
|
62
|
+
if (!db) return refuse("no-pending-row", { db: dbFile && existsSync(dbFile) ? "unreadable" : "not-on-disk" })
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const rows = resolveBatchRows(db, root, batchDocAbs)
|
|
66
|
+
const unsettled = rows.filter((r) => PENDING_STATUSES.includes(r.status)).length
|
|
67
|
+
return { ok: unsettled > 0, reason: unsettled > 0 ? null : "no-pending-row", root, dbFile, db: "open", rows: rows.length, unsettled }
|
|
68
|
+
} catch {
|
|
69
|
+
return refuse("ledger-unreadable", { db: "unreadable" }) // 选行读失败同判:读不到账 ⇒ 拒
|
|
70
|
+
} finally {
|
|
71
|
+
try { db.close() } catch { /* 已关 / 未开 */ }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-tools/batch-ledger-view.mjs — 收口两路与 `check` 共用的**台账侧只读视图**(P2-5 拆出,2026-11-11)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么拆:收口分流(§4.18-C)往 `batch-lifecycle.mjs` 里加了「读一致性 → 判补关」这一步,当年该件因此过了 500 行;
|
|
5
|
+
* 设计档 `docs/core/design/LEDGER.md` §11.3 的失败侧点名两条出路,本条取「拆补关分流」。
|
|
6
|
+
* 四件同住本档,因为它们共一条口径:**批档绝对路径 → 项目根 + 项目相对指针**(`cwd` 基单一处),
|
|
7
|
+
* 再交给台账只读面;分住两处则同一条路径换算要写三遍(收口重锚已在 `batch-lifecycle.mjs` 用同一式)。
|
|
8
|
+
*
|
|
9
|
+
* 四件都是**读**或**只读预检**,不写盘、不写账:
|
|
10
|
+
* ① `consistencyOf` —— 回执末尾 `[ledger consistency]` 行的读数(读不出如实点名,不吞成「一致」);
|
|
11
|
+
* ② `repairDecisionOf` —— 全归档补关的分流判据(§4.18-C:判「正常收口」∥「补关」∥「拒」);
|
|
12
|
+
* ③ `assertCloseDisposition` —— 收口完成清单 + 本笔证据的只读预检(单源 = `assertLedgerCloseDisposition`);
|
|
13
|
+
* ④ `archivedStateOf` —— 被取代的收口(§4.18-D D-3)只要的那一问:本批行集是否**全归档**(薄封装,
|
|
14
|
+
* 与 ② 同一份 `batchLedgerConsistency` 读数,不另造归档判定)。
|
|
15
|
+
*
|
|
16
|
+
* 依赖单向(KD-4):`closeout ← 本档 ← lifecycle`——本档不 import `batch-lifecycle.mjs`(防环)。
|
|
17
|
+
*/
|
|
18
|
+
import { dirname, relative } from "node:path"
|
|
19
|
+
|
|
20
|
+
import { repairBlockedError } from "./batch-closeout.mjs"
|
|
21
|
+
|
|
22
|
+
/** 批档绝对路径 → 台账只读面要的两个坐标(`cwd` = 批档所属项目根 ∥ `batch` = 项目根相对指针)。
|
|
23
|
+
* 收口三处共用这一处换算:`resolveLedgerRoot(dirname(<批档>), boundary)` **不用会话锚**(多根工作区锚
|
|
24
|
+
* 会收到别的项目根 ⇒ 选行零命中 ⇒ 机器写静默失效);`boundary` = 上溯上界 = 会话锚。 */
|
|
25
|
+
async function ledgerCoordsOf(abs, boundary) {
|
|
26
|
+
const { resolveLedgerRoot } = await import("../ledger.mjs") // 动态 import:ledger-db 静态引 node:sqlite(W8 契约②)
|
|
27
|
+
const root = resolveLedgerRoot(dirname(abs), boundary)?.root ?? null
|
|
28
|
+
return { root, batch: root ? relative(root, abs).replace(/\\/g, "/") : abs }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 批-账半状态读数(设计档 §2.17「暴露面两处」——`batch({action:"check"})` 与回执末尾的
|
|
33
|
+
* `[ledger consistency]` 行读**同一份**):查询面单源 = `batchLedgerConsistency`,本档只供 `cwd` 基准。
|
|
34
|
+
* 读不出(台账库坏 / 打不开)⇒ 返回 `{ error }`,由回执如实点名——**不吞成「一致」**(那正是半状态面要
|
|
35
|
+
* 消掉的静默);`check` action 那一路不吞,直接抛。
|
|
36
|
+
*/
|
|
37
|
+
export async function consistencyOf(abs, boundary) {
|
|
38
|
+
try {
|
|
39
|
+
const { batchLedgerConsistency } = await import("../ledger.mjs")
|
|
40
|
+
const { root, batch } = await ledgerCoordsOf(abs, boundary)
|
|
41
|
+
return batchLedgerConsistency({ cwd: root, batch, boundary })
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return { error: String(e?.message ?? e) }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 收口分流(§4.18-C · `docs/core/design/LEDGER.md` §11.2):两路在**链门前**读 `batchLedgerConsistency`,
|
|
48
|
+
* 判「正常收口」∥「全归档补关」。判据 = `record = open` ∧ 行集非空 ∧ 每行均为 `已核销 / 已废弃` ∧
|
|
49
|
+
* `halfStates` 恰为唯一 `open-but-settled`。行集空或含任一非归档行 ⇒ 正常收口(不是补关:工作未结,
|
|
50
|
+
* 缺段必须继续触发 A 门);全归档但伴随其它半状态 ⇒ 拒(归属错误不得被冻成历史);`unknown` 由冻结门早拒。
|
|
51
|
+
* 复用 = `batchLedgerConsistency`(不另造归属或归档判定)。
|
|
52
|
+
* @returns {Promise<{repair:boolean, rows:number}>} `rows` = 本批行集行数(= 补关追记行的 <N>)
|
|
53
|
+
*/
|
|
54
|
+
export async function repairDecisionOf(abs, boundary) {
|
|
55
|
+
let read
|
|
56
|
+
try {
|
|
57
|
+
const { batchLedgerConsistency } = await import("../ledger.mjs")
|
|
58
|
+
const { root, batch } = await ledgerCoordsOf(abs, boundary)
|
|
59
|
+
read = batchLedgerConsistency({ cwd: root, batch, boundary })
|
|
60
|
+
} catch (e) {
|
|
61
|
+
// 读不出就判不了「补关 ∥ 正常收口」⇒ 拒(fail-closed),且仍走 `batch` 语域:工具面拒因必须点名原因与
|
|
62
|
+
// 「什么都没写」,不让核层原文直出。此处从未写盘,故那句是事实不是台词。
|
|
63
|
+
throw new Error(`batch: 收口分流不可判(ledger repair read failed)— ${String(e?.message ?? e)} Nothing was written.`)
|
|
64
|
+
}
|
|
65
|
+
const rows = read.rows.length
|
|
66
|
+
if (read.record !== "open" || rows === 0) return { repair: false, rows }
|
|
67
|
+
if (!read.rows.every((r) => r.status === "已核销" || r.status === "已废弃")) return { repair: false, rows }
|
|
68
|
+
const onlyOpenButSettled = read.halfStates.length === 1 && read.halfStates[0].name === "open-but-settled"
|
|
69
|
+
if (!onlyOpenButSettled) throw new Error(repairBlockedError(read.halfStates))
|
|
70
|
+
return { repair: true, rows }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** 收口完成清单只读预检(单源 = `assertLedgerCloseDisposition`):在凭证消费和批档写盘之前调用。
|
|
74
|
+
* `cwd`/`batch` 换算同上;拒因包一层 `batch:` 前缀(工具面语域)后上抛。
|
|
75
|
+
* `requireAllInFlight` = 完成清单的元判据(**无缺省**,§4.18-D「③ 的实现面」):正常两路传 `true`,
|
|
76
|
+
* 被取代的收口传 `false`——本档只透传,不另立一套。 */
|
|
77
|
+
export async function assertCloseDisposition(abs, boundary, completed, closeEvidence, requireAllInFlight) {
|
|
78
|
+
try {
|
|
79
|
+
const { assertLedgerCloseDisposition } = await import("../ledger.mjs")
|
|
80
|
+
const { root, batch } = await ledgerCoordsOf(abs, boundary)
|
|
81
|
+
return assertLedgerCloseDisposition({ cwd: root, batch, boundary, completed, closeEvidence, requireAllInFlight })
|
|
82
|
+
} catch (e) {
|
|
83
|
+
throw new Error(`batch: close disposition refused — ${String(e?.message ?? e)} Nothing was written.`)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 归档态读数(§4.18-D D-3——**只回答「行集是否全归档」这一问**):与 `repairDecisionOf` 同一份
|
|
89
|
+
* `batchLedgerConsistency` 读数、同一 `cwd` 换算,**不另造归属或归档判定**。
|
|
90
|
+
* 为什么不直接复用 `repairDecisionOf`:它的三态分派是补关口径(全归档 + 唯一 `open-but-settled` 才补关,
|
|
91
|
+
* 其余半状态 ⇒ 拒),而 D-3 只要「全归档」这一个判据——薄封装,不新造归档判定。
|
|
92
|
+
* **行集为空也算未全归档**(空集没有可归档的行 ⇒ 被取代仍可用);全归档 ⇒ 被取代一律拒(那条拒面同时封掉
|
|
93
|
+
* 最大的滥用面:把「活做完了、档冻不了」说成「被取代」)。读不出 ⇒ throw(D-2:判不了归档态就分不清那一条反例
|
|
94
|
+
* ——不降级放行)。
|
|
95
|
+
* @returns {Promise<{record:"open"|"closed"|"unknown", rows:object[], allArchived:boolean}>}
|
|
96
|
+
*/
|
|
97
|
+
export async function archivedStateOf(abs, boundary) {
|
|
98
|
+
let read
|
|
99
|
+
try {
|
|
100
|
+
const { batchLedgerConsistency } = await import("../ledger.mjs")
|
|
101
|
+
const { root, batch } = await ledgerCoordsOf(abs, boundary)
|
|
102
|
+
read = batchLedgerConsistency({ cwd: root, batch, boundary })
|
|
103
|
+
} catch (e) {
|
|
104
|
+
// 读不出 ⇒ 拒(fail-closed):判不了归档态就分不清「活做完了」与「活没人做」,宁可拒。
|
|
105
|
+
throw new Error(`batch: 取代前的归档态读不出(ledger supersede read failed)— ${String(e?.message ?? e)} Without that read the all-archived case cannot be told apart from a real supersede. Nothing was written.`)
|
|
106
|
+
}
|
|
107
|
+
const archived = read.rows.filter((r) => r.status === "已核销" || r.status === "已废弃")
|
|
108
|
+
return { record: read.record, rows: read.rows, allArchived: read.rows.length > 0 && archived.length === read.rows.length }
|
|
109
|
+
}
|