@thincoder/core 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -2
- package/advisor/convergence.mjs +34 -3
- package/advisor/loop.mjs +42 -10
- package/advisor/messages.mjs +42 -25
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +7 -4
- package/advisor.mjs +29 -43
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/completion.mjs +44 -3
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch.mjs +8 -3
- package/agent/family-tools.mjs +27 -12
- package/agent/helpers.mjs +122 -1
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +24 -10
- package/agent/record-results.mjs +18 -1
- package/agent/run-stages.mjs +77 -32
- package/agent/run-start.mjs +37 -0
- package/agent/setup-reminders.mjs +9 -2
- package/agent/setup.mjs +24 -11
- package/agent/spawn-child.mjs +38 -1
- package/agent/timers.mjs +5 -3
- package/agent/turn-loop.mjs +30 -5
- package/agent/turn-projection.mjs +386 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +168 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +29 -169
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +36 -47
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/batch-closeout.mjs +273 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +226 -17
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +169 -46
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +23 -11
- package/agent-tools/batch-segment-vocab.mjs +379 -0
- package/agent-tools/batch-skeleton.mjs +192 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +297 -0
- package/agent-tools/batch.mjs +182 -439
- package/agent-tools/consult.mjs +7 -4
- package/agent-tools/context.mjs +44 -17
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +1 -1
- package/agent-tools/design-token.mjs +279 -81
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +9 -8
- package/agent-tools/escalate-async.mjs +2 -2
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +10 -3
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/spawn-gates.mjs +9 -8
- package/agent-tools/ssh-session.mjs +2 -2
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-async.mjs +8 -9
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +4 -4
- package/agent-tools/subagent-spawn.mjs +90 -110
- package/agent-tools/subagent.mjs +11 -10
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +20 -1
- package/attachments.mjs +3 -3
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +1 -1
- package/config-defaults.mjs +2 -1
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +62 -98
- package/context-degrade.mjs +38 -10
- package/context-echo.mjs +11 -0
- package/context.mjs +149 -83
- package/conventions.mjs +11 -9
- package/declaration.mjs +31 -5
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +309 -213
- package/doc-check/line-refs.mjs +27 -101
- package/doc-check/paragraph.mjs +218 -102
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/explore-distill.mjs +11 -5
- package/i18n.mjs +1 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +6 -0
- package/ledger-close-proof.mjs +100 -49
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +47 -91
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +47 -15
- package/ledger-executors.mjs +1 -1
- package/ledger-tools.mjs +78 -19
- package/ledger-write-ops.mjs +130 -41
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/schema.mjs +2 -2
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +91 -1
- package/prompt-overlays.mjs +9 -6
- package/prompts/advisor-design.md +62 -21
- package/prompts/advisor-round1.md +34 -1
- package/prompts/advisor-round2.md +40 -7
- package/prompts/advisor-round3.md +39 -6
- package/prompts/common.md +14 -387
- package/prompts/consult-base.md +5 -1
- package/prompts/discipline-engineering.md +226 -51
- package/prompts/discipline-normal.md +4 -255
- package/prompts/knowledge/business-gates.md +22 -0
- package/prompts/knowledge/decision-quality.md +23 -0
- package/prompts/knowledge/doc-lookup.md +35 -0
- package/prompts/knowledge/document-writing.md +51 -0
- package/prompts/knowledge/documentation-evaluation.md +56 -0
- package/prompts/knowledge/evidence-discipline.md +57 -0
- package/prompts/knowledge/normal-coding-workflow.md +104 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +108 -0
- package/prompts/knowledge/normal-work-management.md +57 -0
- package/prompts/knowledge/product-security.md +23 -0
- package/prompts/knowledge/project-records.md +62 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +18 -0
- package/prompts/knowledge/tool-bash.md +39 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +12 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +12 -0
- package/prompts/knowledge/tool-batch-review.md +12 -0
- package/prompts/knowledge/tool-batch.md +80 -0
- package/prompts/knowledge/tool-browser.md +57 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +17 -0
- package/prompts/knowledge/tool-doc-check.md +70 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +38 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +16 -0
- package/prompts/knowledge/tool-fetch.md +12 -0
- package/prompts/knowledge/tool-file-ops.md +16 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +19 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +15 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +18 -0
- package/prompts/knowledge/tool-hashline-edit.md +14 -0
- package/prompts/knowledge/tool-insert-after.md +15 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +35 -0
- package/prompts/knowledge/tool-ledger.md +42 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +13 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +31 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +15 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +114 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +6 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +36 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +21 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +18 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +52 -0
- package/prompts/knowledge/tool-subagent.md +59 -0
- package/prompts/knowledge/tool-task.md +12 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +11 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +14 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +9 -0
- package/prompts/knowledge/upstream-protocol.md +43 -0
- package/prompts/persona-eng-coder.md +21 -3
- package/prompts/persona-eng-designer.md +131 -169
- package/prompts/persona-engineering.md +142 -84
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-plan.md +5 -1
- package/prompts/subagent-base.md +2 -0
- package/provider/anthropic.mjs +6 -4
- package/provider/core.mjs +3 -2
- package/provider/errors.mjs +29 -4
- package/provider/google.mjs +24 -7
- package/provider/responses.mjs +3 -1
- package/provider-flows.mjs +2 -2
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +72 -17
- package/session-slot-write.mjs +37 -5
- package/session.mjs +24 -8
- package/skip-dirs.mjs +2 -2
- package/team-ledger.mjs +13 -9
- package/token-ttl.mjs +73 -4
- package/token-window.mjs +167 -33
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -41
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +2 -84
- package/tool-docs/browser.md +2 -49
- package/tool-docs/code_search.md +2 -2
- package/tool-docs/consult_start.md +2 -8
- package/tool-docs/consult_stop.md +2 -4
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -17
- package/tool-docs/doc_check.md +2 -107
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +2 -4
- package/tool-docs/edit.md +1 -38
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -18
- package/tool-docs/fetch.md +2 -14
- package/tool-docs/file_ops.md +2 -18
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -35
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +1 -6
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -15
- package/tool-docs/insert_after.md +2 -16
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -10
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -8
- package/tool-docs/manifest.md +2 -35
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +2 -20
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +1 -5
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -18
- package/tool-docs/read_image.md +2 -9
- package/tool-docs/recent_changes.md +2 -2
- package/tool-docs/repo_outline.md +2 -2
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +1 -12
- package/tool-docs/skill.md +2 -6
- package/tool-docs/ssh.md +1 -62
- package/tool-docs/subagent.md +2 -100
- package/tool-docs/task.md +1 -7
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +2 -19
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +2 -12
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -19
- package/tool-docs/write.md +2 -12
- package/tools/browser.mjs +52 -7
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +170 -92
- package/tools/edit-diff.mjs +78 -62
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +1 -1
- package/tools/file.mjs +16 -8
- package/tools/git.mjs +24 -9
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +3 -1
- package/tools/patch.mjs +123 -43
- package/tools/shared.mjs +28 -27
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +203 -0
- package/doc-check/anchors.mjs +0 -235
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent-tools/batch-segment-vocab.mjs — 批次档的**段词表 / 段白名单 / 状态行读写面**单源
|
|
3
|
+
* (2026-11-05 拆档族从 `batch-skeleton.mjs` 迁出;原档改再导出,导出面零变)。
|
|
4
|
+
*
|
|
5
|
+
* 本档是整条批次档依赖链的**最底叶**(零 import、零副作用、零 fs):词表(STATUS_WORDS ∥ 别名表)、
|
|
6
|
+
* 段白名单(SEGMENT_BY_ROLE ∥ 普通模式增表 ∥ DEPTH0_SEGMENTS)、段头与状态行形态、段解析
|
|
7
|
+
* (`sectionBodyLines` ∥ `sectionHeaderZoneEntries`)、以及状态行读写三件(`readBatchStatusLine` ∥
|
|
8
|
+
* `updateSectionStatusLine` ∥ `readSectionStatusWord`)+ 位置/计数三件(`zoneStatusLines` ∥
|
|
9
|
+
* `zoneStatusCount` ∥ `firstZoneStatusLineRange`)。
|
|
10
|
+
*
|
|
11
|
+
* 为什么段解析也住这里:上面几件状态行函数都要「取某段的段头区行集」,而取行集只有一份实现
|
|
12
|
+
* (`sectionHeaderZoneEntries` → `sectionBodyLines`)。把它留在原档,本档就得反向 import 原档 ⇒ 两档
|
|
13
|
+
* 互 import 成环;复制一份解析 ⇒ 判据有了第二份字面。所以段解析随其最低位读者下沉,原档按名 import 回来
|
|
14
|
+
* ——这是本批唯一一处与设计档落点表述不同的地方(**单向依赖优先于同档偏好**)。
|
|
15
|
+
*
|
|
16
|
+
* 依赖单向:`batch-segment-vocab ← batch-skeleton ← 其余批次档`——本档不 import 任何档。
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* 段标题定位(`## §N` 独立标题——`## §20` 不误命中 §2)。
|
|
20
|
+
*/
|
|
21
|
+
export const sectionHeaderRe = (seg) => new RegExp(`^## §${seg}(?=\\s|$)`, "m")
|
|
22
|
+
|
|
23
|
+
/** §1 段头正则(单源——`readBatchStatusLine` 与 `isBatchRecord` 共用;`## §10` 不误命中 §1)。 */
|
|
24
|
+
const SECTION_1_HEADER_RE = /^## §1(?=\s|$)/m
|
|
25
|
+
/** 批档谓词(只读 · 零 fs):档内有 §1 段头 ⇒ 批次档——判别式 = 上面那条同一正则(「是不是批档」与
|
|
26
|
+
* 「§1 状态行是什么」两问不各持一份);消费面 = 台账核销机检(`ledger-close-proof.mjs`)。 */
|
|
27
|
+
export function isBatchRecord(src) {
|
|
28
|
+
return typeof src === "string" && SECTION_1_HEADER_RE.test(src)
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* STATUS_WORDS——状态行合法关键字**分段词表常量单源**(D-BR19 / fix 轮 #1;轮 2 #3 裁定②):
|
|
32
|
+
* - §1 项 = gate 词表 `{ open: 进行中, closed: 已收口 }`——**gate 只消费 §1 项**(单源仍成立);
|
|
33
|
+
* - §2/§3/§5 各带段内生命周期词表(`done` 词 = 段属主的完成态关键字);
|
|
34
|
+
* - §4/§6 无项——主 agent 的 status 写域**仅 §1**(§4/§6 状态面走普通文档写,与 D-BR18 分工一致)。
|
|
35
|
+
* 词面纪律(最小词面):一条状态行值只带**一个**关键字——校验面(batch 工具 status)拒绝内嵌另一冻结词的
|
|
36
|
+
* 值(含「进行中…已收口」双词 ⇒ 已收口优先误冻结——2026-09-20 词面纪律)。emoji / 括注 / 日期后缀容忍
|
|
37
|
+
* (**读侧** gate 判定 = 子串包含,同 gate——写入面 value 谓词自本批起收紧为「剥装饰白名单后余核 = 关键词」,
|
|
38
|
+
* 见 batch-lifecycle.mjs);全词表并集 = 各段项去重集合(note 字段零命中的判据——括注永不误触 gate)。
|
|
39
|
+
*/
|
|
40
|
+
export const STATUS_WORDS = Object.freeze({
|
|
41
|
+
1: Object.freeze({ open: "进行中", closed: "已收口" }),
|
|
42
|
+
2: Object.freeze({ open: "进行中", done: "设计完成" }),
|
|
43
|
+
3: Object.freeze({ open: "进行中", done: "评审通过" }),
|
|
44
|
+
5: Object.freeze({ open: "进行中", done: "实施完成" }),
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
/** 段状态行**旧字面兼容别名表**(只用于**读侧**:写侧词表零别名——旧字面写不进去,词表外拒)。
|
|
48
|
+
* §3 自 2026-10-27 起只留一个完成词 `评审通过`(只有 pass 叫完成;`changes-required` 不写状态词——
|
|
49
|
+
* 「评审没通过」= 评审未完成)。存量批档里的旧字面 `评审完成` 读侧等义于 `评审通过`(存量档**不回填**
|
|
50
|
+
* ——已冻结档不改字节)。**退场条件**:盘上再无该字面(判据 = `grep -r '评审完成' docs/batches`)。 */
|
|
51
|
+
export const STATUS_WORD_ALIASES = Object.freeze({
|
|
52
|
+
3: Object.freeze({ "评审完成": "评审通过" }),
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
/** 身份 → 可写段号(append 段白名单的**子代理面**——原 batch-segment.mjs 逐字迁移;主 agent
|
|
56
|
+
* 的 depth-0 白名单(模式感知——工程 §1/§4/§6 · §1 ∥ 普通 §1/§2/§4/§5/§6 · §1/§2/§5,§4.16)
|
|
57
|
+
* 由身份判据在 batch.mjs / batch-lifecycle.mjs 分支,不经本表。旧 batch-segment.mjs 导出面等价
|
|
58
|
+
* 保持——本符号经 batch.mjs re-export(过渡 shim 面零触)。**表零字面改**——普通模式另立增表
|
|
59
|
+
* `SEGMENT_BY_ROLE_NORMAL`(合并查只在普通模式分支);工程面「逐字不变」判据据此成立。 */
|
|
60
|
+
export const SEGMENT_BY_ROLE = { "eng-designer": 2, "eng-coder": 5 }
|
|
61
|
+
|
|
62
|
+
/** 普通模式增表(§4.16——**合并查只在普通模式分支**,工程模式分支不消费本表):coder 承办 ⇒ §5
|
|
63
|
+
* 实施记录(可选绑定自写——未绑定由主 agent 代记、行内注明来源)。 */
|
|
64
|
+
export const SEGMENT_BY_ROLE_NORMAL = { "coder": 5 }
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 评审实例的可写段(`BATCH-RECORD.md` §4.1 ∥ §4.4,按「模式 × 评审轨」分岔):
|
|
68
|
+
* 工程模式的**设计轨** ⇒ `null`(`§3` 对那一路的一切工具通道只读——轮次块只由设计评审结算写);
|
|
69
|
+
* 工程模式的**代码轨**与**普通模式** ⇒ `3`(那两条路没有设计结算可代写,而收口门读的是 `§3` 的段级状态行)。
|
|
70
|
+
* 两个输入(模式 × 评审轨)缺一即判不出,故不许用默认值顶替:`reviewTrack` 未给 ⇒ 按设计轨处置
|
|
71
|
+
* (这一面是拒面,判不出就不放行——fail-closed)。
|
|
72
|
+
* 消费面两处、同一判据:`batch-record-write.mjs` 的段白名单(`append` ∥ `edit`)∥
|
|
73
|
+
* `batch-lifecycle.mjs` 的 `status` 段域。
|
|
74
|
+
* @param {boolean} engineering 模式位(执行期实读)
|
|
75
|
+
* @param {string|null|undefined} reviewTrack 评审轨(`"design"` ∥ `"code"`)
|
|
76
|
+
* @returns {3|null} 可写段号 / 不可写
|
|
77
|
+
*/
|
|
78
|
+
export function reviewWritableSegment(engineering, reviewTrack) {
|
|
79
|
+
return engineering && reviewTrack !== "code" ? null : 3
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 工程设计轨 §3 写面拒串(`BATCH-RECORD.md` §4.4——评审席与批工具的任何席位通道都不写它)。
|
|
83
|
+
* 前缀由调用面给(`append` = `batch_segment:`,`edit` ∥ `status` = `batch:`——三面各自既有前缀零改)。 */
|
|
84
|
+
export function sectionThreeDesignTrackError(prefix) {
|
|
85
|
+
return `${prefix}: §3 is closed to this caller — in engineering mode the design-track round block is written by the settlement: the tool stamps the round heading, adds the settlement header line and the review's report verbatim, in the same stroke that decides the token. §3 is read-only for every tool channel on that track (a block you add would sit beside the settlement's and the record would read as two rounds). The code track and normal mode keep the §3 channel. Nothing was written.`
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** depth-0 段白名单(§4.16——**模式键两集**;工程面判定字面逐字保持、普通面新增):
|
|
89
|
+
* append:工程 = §1/§4/§6 ∥ 普通 = §1/§2/§4/§5/§6(§2 = 设计师席并入主 agent;§5 = 直做实施记录);
|
|
90
|
+
* status:工程 = §1 ∥ 普通 = §1/§2/§5(写域仍「调用者自己段」;`segment` 缺省 = §1)。 */
|
|
91
|
+
export const DEPTH0_SEGMENTS = Object.freeze({
|
|
92
|
+
append: Object.freeze({ engineering: Object.freeze([1, 4, 6]), normal: Object.freeze([1, 2, 4, 5, 6]) }),
|
|
93
|
+
status: Object.freeze({ engineering: Object.freeze([1]), normal: Object.freeze([1, 2, 5]) }),
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
/** §1 状态行前缀形态(`**状态行**:` 独立行——表格行 / 块引用行不命中;判定只认关键字)。 */
|
|
97
|
+
export const STATUS_LINE_RE = /^\s*\*\*状态行\*\*[::]\s*(.*)$/
|
|
98
|
+
|
|
99
|
+
/** 段头区界(任意 `##` / `###` 起的行——写面与触发读面同一条判据;`updateSectionStatusLine` 与
|
|
100
|
+
* `sectionHeaderZoneEntries` 读它,随段解析下沉本档)。 */
|
|
101
|
+
const ZONE_END_RE = /^#{2,}/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 骨架死占位**枚举单源**(F11-C 判据——create 骨架产出过的全部死占位字面):
|
|
105
|
+
* - `#<编号>` / `<板块>` = 现行骨架仍在产出的两处(台账行——填充人 = 主 agent,时点 =
|
|
106
|
+
* 建档后、本档首个 append/status 之前);
|
|
107
|
+
* - `<BATCH-ID>` / `<讨论来源>` = 改形**删除**的两处旧占位(create 不再产出;旧档残留同判)。
|
|
108
|
+
* 判据 = 枚举而非泛形正则:`<[^>]{1,40}>` 一类泛形会误杀正文合法尖括号(`Error: <message>` /
|
|
109
|
+
* 泛型 `Array<T>` / 讨论字面本身)与 `<§N 模板占位:…>` 合法暂存行(append 不删行——段内留存
|
|
110
|
+
* 是常态)——设计档 `TOOLS.md` 6.15 裁定点④。
|
|
111
|
+
*/
|
|
112
|
+
export const TEMPLATE_PLACEHOLDERS = ["<BATCH-ID>", "<讨论来源>", "#<编号>", "<板块>"]
|
|
113
|
+
|
|
114
|
+
/** 档头结构行值形(骨架三类——标题行 `# …` / 编制行 `> 编制` / 台账行 `> 台账`):判据可辨性收正
|
|
115
|
+
* (`TOOLS.md` §6.20)后只有这三类行参与死占位判定;骨架↔结构行不变量 = `batchSkeleton` 产出中
|
|
116
|
+
* 枚举字面 ⊆ 本三类行(骨架改形与判据同拍——结构行外新增占位 = 静默漏检)。 */
|
|
117
|
+
const HEADER_STRUCTURAL_RE = [/^#\s/, /^>\s*编制/, /^>\s*台账/]
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 死占位残留扫描(F11-C——append/status 落笔前的机检;**纯函数 · 零 fs**)。
|
|
121
|
+
* 判定域 = **档头结构行**(区域 = 档首至首个 `## §N` 段头前;值形 = 骨架三类结构行:标题行 `# …` / 编制行
|
|
122
|
+
* `> 编制` / 台账行 `> 台账`)——行内出现枚举字面 ⇒ 残留;段体(首段头起)任意位置出现字面 = 正文引用 ⇒
|
|
123
|
+
* **豁免**(引用非未填——2026-10-05 判据可辨性收正,`TOOLS.md` §6.20;原全域子串扫描分不清两者——本批 §1 首投实害)。
|
|
124
|
+
* @param {string} src — 档全文
|
|
125
|
+
* @returns {Array<{line: number, text: string}>} 残留列表(空 = 无残留);
|
|
126
|
+
* `line` = 档头域内 1-based 行号(档头域自档首行起——便于定位),`text` = 命中行 trim 原文
|
|
127
|
+
*/
|
|
128
|
+
export function findPlaceholderResidue(src) {
|
|
129
|
+
const firstSection = /^## §\d/m.exec(src)
|
|
130
|
+
const out = []
|
|
131
|
+
src.slice(0, firstSection ? firstSection.index : 0).split("\n").forEach((line, i) => {
|
|
132
|
+
if (!HEADER_STRUCTURAL_RE.some((re) => re.test(line))) return
|
|
133
|
+
if (TEMPLATE_PLACEHOLDERS.some((ph) => line.includes(ph))) out.push({ line: i + 1, text: line.trim() })
|
|
134
|
+
})
|
|
135
|
+
return out
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 占位残留拒绝句(F11-C——append / status 两个挂点共用单源文案;逐行列残留:行号 + 原文)。
|
|
140
|
+
* 错误句前缀 = `batch:`(本批新增错误面——与 append 迁移面的 `batch_segment:` 旧面不混)。
|
|
141
|
+
* 逐字 = `TOOLS.md` §6.20 拒句表(「or your target section」半句随判定域收正退场)。
|
|
142
|
+
* @param {Array<{line:number,text:string}>} residues — findPlaceholderResidue 的返回值(非空)
|
|
143
|
+
* @returns {string} 完整拒绝句(调用方 throw new Error(...))
|
|
144
|
+
*/
|
|
145
|
+
export function placeholderResidueError(residues) {
|
|
146
|
+
const list = residues.map((r) => ` 档头 line ${r.line}: ${r.text}`).join("\n")
|
|
147
|
+
return "batch: 骨架死占位残留 — the batch record's header still carries skeleton placeholders. " +
|
|
148
|
+
"Fill them before writing: create with ledger / board fills the 台账 line at creation; otherwise the main agent fills the header by file edit ⇒ the record's first append/status opens. " +
|
|
149
|
+
`Nothing was written. Residue:\n${list}`
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** §N 段体行集(段头缺失 ⇒ null——create 是骨架唯一权威入口;行切分 = /\r?\n/——EOL 形态无关)。
|
|
153
|
+
* 读数面广:本档的 `sectionHeaderZoneEntries` 与 `batch-skeleton.mjs` 的 `countRoundBlocks` /
|
|
154
|
+
* `lastRoundBlock` / `sectionContentState` / `malformedInapplicableLine` 同读这一份(故导出)。 */
|
|
155
|
+
export function sectionBodyLines(src, seg) {
|
|
156
|
+
const hdr = sectionHeaderRe(seg).exec(src)
|
|
157
|
+
if (!hdr) return null
|
|
158
|
+
const nextRe = /^## §\d/gm
|
|
159
|
+
nextRe.lastIndex = hdr.index + hdr[0].length
|
|
160
|
+
const next = nextRe.exec(src)
|
|
161
|
+
const body = src.slice(hdr.index + hdr[0].length, next ? next.index : src.length)
|
|
162
|
+
const nl = body.indexOf("\n") // 跳过段头行余文(`## §N …` 的标题部分)
|
|
163
|
+
return (nl >= 0 ? body.slice(nl + 1) : "").split(/\r?\n/)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** §N **段头区行项**(行文 + 档内绝对字符区间;段级状态行的唯一住所:`## §N` 标题行之后、下一个
|
|
167
|
+
* `##` / `###` 起行之前;段头缺失 ⇒ null)。**段头区定位的单源实现**——两个读面(`readBatchStatusLine` ∥
|
|
168
|
+
* `readSectionStatusWord`)与三个位置/计数导出(`zoneStatusLines` ∥ `zoneStatusCount` ∥
|
|
169
|
+
* `firstZoneStatusLineRange`)都从这里取,不另写第二份区界判断。 */
|
|
170
|
+
function sectionHeaderZoneEntries(src, seg) {
|
|
171
|
+
const hdr = sectionHeaderRe(seg).exec(src)
|
|
172
|
+
if (!hdr) return null
|
|
173
|
+
const nextRe = /^## §\d/gm
|
|
174
|
+
nextRe.lastIndex = hdr.index + hdr[0].length
|
|
175
|
+
const next = nextRe.exec(src)
|
|
176
|
+
const end = next ? next.index : src.length
|
|
177
|
+
const nl = src.indexOf("\n", hdr.index + hdr[0].length) // 跳过段头行余文(`## §N …` 的标题部分)
|
|
178
|
+
const out = []
|
|
179
|
+
let at = nl < 0 || nl + 1 > end ? end : nl + 1
|
|
180
|
+
while (at < end) {
|
|
181
|
+
const nlAt = src.indexOf("\n", at)
|
|
182
|
+
const lineEnd = nlAt < 0 || nlAt > end ? end : nlAt
|
|
183
|
+
const raw = src.slice(at, lineEnd)
|
|
184
|
+
const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw
|
|
185
|
+
if (ZONE_END_RE.test(line)) break
|
|
186
|
+
out.push({ line, start: at, end: at + line.length })
|
|
187
|
+
at = lineEnd + 1
|
|
188
|
+
}
|
|
189
|
+
return out
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** 段头区内**全部** `**状态行**:` 形态行(设计档 §4.21.2「列举面」;段头缺失 ∥ 区内零条 ⇒ 空集)。
|
|
193
|
+
* 与 `firstZoneStatusLineRange` 同一份区界——列举与定位不各判一次。 */
|
|
194
|
+
export function zoneStatusLines(src, seg) {
|
|
195
|
+
return (sectionHeaderZoneEntries(src, seg) ?? [])
|
|
196
|
+
.filter((e) => STATUS_LINE_RE.test(e.line))
|
|
197
|
+
.map((e) => e.line)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** 段头区内状态行**条数**(§4.21.2——`edit` 的「改写后不多于改写前」单调性判据的唯一读数)。 */
|
|
201
|
+
export function zoneStatusCount(src, seg) {
|
|
202
|
+
return zoneStatusLines(src, seg).length
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** **受保护行**的字符区间(§4.21.2「位置义」):段头区内**第一个** `**状态行**:` 形态行——`edit` 不许碰、
|
|
206
|
+
* `status` / `close` / 重开径改写的那一行。区内零条 ⇒ null(没有保护对象,`edit` 面据此不拦)。
|
|
207
|
+
* @param {string} src — 档全文
|
|
208
|
+
* @param {number|string} seg — 段号
|
|
209
|
+
* @returns {{start:number,end:number}|null} 档内绝对字符区间(不含行尾) */
|
|
210
|
+
export function firstZoneStatusLineRange(src, seg) {
|
|
211
|
+
const hit = (sectionHeaderZoneEntries(src, seg) ?? []).find((e) => STATUS_LINE_RE.test(e.line))
|
|
212
|
+
return hit ? { start: hit.start, end: hit.end } : null
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* §1 状态行解析(冻结门与 lifecycle 共用的**单源解析器**——原 batch-segment.mjs 逐字迁移,
|
|
217
|
+
* 字面「已收口/进行中」改为消费 STATUS_WORDS[1],行为零变):解析对象 = §1 **段头区**内
|
|
218
|
+
* `**状态行**:` 前缀行(`## §1` 标题之后、下一 `^#{2,}` 之前——与写面同一条定位面;
|
|
219
|
+
* 段体 / 轮次块里引述的状态行不参与判定)。判定只认关键字(emoji / 括号装饰 / 日期后缀容忍):含「已收口」→ "closed"
|
|
220
|
+
* (冻结优先)、含「进行中」→ "open";无 §1 / 无该行 / **区内两条以上** / 两关键字皆不命中 → "unknown"
|
|
221
|
+
* (fail-closed 视为冻结)。
|
|
222
|
+
* **取值面 = 可读行(计数义,§4.21.4)**:区内**恰一条**形态行才读——两条以上时机器不猜哪一条是结论。
|
|
223
|
+
*/
|
|
224
|
+
export function readBatchStatusLine(src) {
|
|
225
|
+
const hits = zoneStatusLines(src, 1) // 段头单源(段头缺失 ⇒ 空集;与 isBatchRecord 同一段头正则)
|
|
226
|
+
if (hits.length !== 1) return "unknown" // 零条 = 无该行 ∥ 两条以上 = 可读行不存在(同判 unknown)
|
|
227
|
+
const m = STATUS_LINE_RE.exec(hits[0])
|
|
228
|
+
if (!m) return "unknown"
|
|
229
|
+
const value = m[1].trim()
|
|
230
|
+
if (value.includes(STATUS_WORDS[1].closed)) return "closed"
|
|
231
|
+
if (value.includes(STATUS_WORDS[1].open)) return "open"
|
|
232
|
+
return "unknown"
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** 机读清单的**块名**(块头两形共同的名字;**字面单源**——块头判据与收口拒文的触发判据同取它)。 */
|
|
236
|
+
export const MACHINE_LIST_HEAD_NAME = "受影响文件(机读清单)"
|
|
237
|
+
/** 块头形 ①(**行首粗体**):行首即认,尾随标点不计。 */
|
|
238
|
+
const MACHINE_LIST_BOLD_RE = new RegExp(`^\\s*\\*\\*${MACHINE_LIST_HEAD_NAME}\\*\\*`)
|
|
239
|
+
/** 表行判据(与 `doc-check/paragraph.mjs` 的 `isTableRow` 同形)。 */
|
|
240
|
+
const MACHINE_LIST_ROW_RE = /^\s*\|.*\|\s*$/
|
|
241
|
+
/** 标题行判据(块界;块头形 ② 也是标题行,认不认由标题文字定——见 `machineListHeadOf`)。 */
|
|
242
|
+
const MACHINE_LIST_HEADING_RE = /^\s*#{1,6}\s/
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* 块头识别(三值 · 纯函数):`"bold"` ∥ `"heading"` ∥ `null`。**形单源** = `docs/core/design/DOC-CHECK.md` §8.1。
|
|
246
|
+
* - `bold`:行首 `**<块名>**`(尾随文字不计);
|
|
247
|
+
* - `heading`:标题行,标题文字剥掉粗体符 ∥ 行内代码符 ∥ 句末冒号与空白后**以块名结尾**——
|
|
248
|
+
* `### 受影响文件(机读清单)` ∥ `### 3. 受影响文件(机读清单)` 算;
|
|
249
|
+
* `### 受影响文件(机读清单)的写法` 不算:那一行是在提它,不是在开这一块(收进来就会把紧随其后的
|
|
250
|
+
* 无关表读成机读清单)。
|
|
251
|
+
* **不设参数缺省**:判据只收一行字符串,给什么判什么。「缺省按粗体算」一类兜底不写——块头判错的后果正是
|
|
252
|
+
* 静默零行,兜底只会把错误藏得更深。
|
|
253
|
+
* @param {string} line — 档内一行(不含行尾)
|
|
254
|
+
* @returns {"bold"|"heading"|null} 块头形 ∥ `null`(不是块头)
|
|
255
|
+
*/
|
|
256
|
+
export function machineListHeadOf(line) {
|
|
257
|
+
const s = String(line)
|
|
258
|
+
if (MACHINE_LIST_BOLD_RE.test(s)) return "bold"
|
|
259
|
+
if (!MACHINE_LIST_HEADING_RE.test(s)) return null
|
|
260
|
+
const title = s.replace(/^\s*#{1,6}\s+/, "").replace(/[`*]/g, "").trim().replace(/[::]+\s*$/, "").trim()
|
|
261
|
+
return title.endsWith(MACHINE_LIST_HEAD_NAME) ? "heading" : null
|
|
262
|
+
}
|
|
263
|
+
/** 占位格判据(`<仓根相对路径>` 这类模板 token):模板示例行不是记录。 */
|
|
264
|
+
const MACHINE_LIST_PLACEHOLDER_RE = /^<.*>$/
|
|
265
|
+
/** 分隔行判据(`|---|---|`)。 */
|
|
266
|
+
const MACHINE_LIST_SEPARATOR_RE = /^:?-{3,}:?$/
|
|
267
|
+
/** 表头首格(`| 档 | 分拆方案 |`)——只用来跳过表头行。 */
|
|
268
|
+
const MACHINE_LIST_HEADER_CELLS = Object.freeze(["档", "file"])
|
|
269
|
+
|
|
270
|
+
/** 格内文本(去首尾空白与 markdown 装饰符——写手会写成 `` `x` `` ∥ `**x**`)。 */
|
|
271
|
+
const cellTextOf = (s) => String(s ?? "").replace(/[`*]/g, "").trim()
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* 解析 §2 的机读清单(纯函数 · 零 fs):逐个块头(两形,判据见 `machineListHeadOf`),取它**之后的第一张表**;
|
|
275
|
+
* 找表范围止于下一个标题行 ∥ 下一个块头。看头不看行——同一份档里块头可能出现不止一次(先举例、再写真清单
|
|
276
|
+
* 是正常写法),逐行跟读会把示例当档案。读不成 2–3 格的行跳过而不抛:那三个消费面都只为「点名哪些档」。
|
|
277
|
+
* **2 格 ∥ 3 格都收,加列不移位**:第三列「行数」是追加的读数格,两格旧行照旧解得开(`reading` = 空串,
|
|
278
|
+
* 由消费面按「该列没有数」判);4 格以上仍跳过(多出来的列没有判据,读了就是替写手猜)。
|
|
279
|
+
* @param {string} src 档全文
|
|
280
|
+
* @returns {{path:string, plan:string, reading:string}[]} `path` 去装饰符;`plan` = 第二列原值去首尾空白;
|
|
281
|
+
* `reading` = 第三列原值去首尾空白(**两格行 = 空串**——不是 `null`:缺列与空格在这里同判「缺读数」)
|
|
282
|
+
*/
|
|
283
|
+
export function machineListRowsOf(src) {
|
|
284
|
+
const lines = String(src ?? "").split(/\r?\n/)
|
|
285
|
+
const rows = []
|
|
286
|
+
lines.forEach((l, at) => {
|
|
287
|
+
if (machineListHeadOf(l) === null) return
|
|
288
|
+
const table = firstMachineListTable(lines, at)
|
|
289
|
+
if (table === null) return
|
|
290
|
+
table.forEach((raw, k) => {
|
|
291
|
+
const cells = raw.trim().replace(/^\|/, "").replace(/\|$/, "").split("|")
|
|
292
|
+
if (cells.length < 2 || cells.length > 3) return
|
|
293
|
+
if (cells.every((c) => MACHINE_LIST_SEPARATOR_RE.test(c.trim()))) return
|
|
294
|
+
if (k === 0 && MACHINE_LIST_HEADER_CELLS.includes(cellTextOf(cells[0]).toLowerCase())) return
|
|
295
|
+
const path = cellTextOf(cells[0])
|
|
296
|
+
if (MACHINE_LIST_PLACEHOLDER_RE.test(path)) return
|
|
297
|
+
rows.push({ path, plan: cells[1].trim(), reading: cells.length === 3 ? cells[2].trim() : "" })
|
|
298
|
+
})
|
|
299
|
+
})
|
|
300
|
+
return rows
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** 块头之后的第一张表(连续表行;找不到 ⇒ `null`)——扫描**自块头行的下一行**起,止于下一个标题行 ∥ 下一个块头。
|
|
304
|
+
* 为什么从下一行起:标题形的块头自己也是标题行,把块头行当块界,每一份小标题形清单都会读成零行。
|
|
305
|
+
* 前一块无表、后一块有表时前一块得 `null`、后一块得那一张表——不串块,同一张表不被两块各算一遍。 */
|
|
306
|
+
function firstMachineListTable(lines, at) {
|
|
307
|
+
for (let i = at + 1; i < lines.length; i++) {
|
|
308
|
+
const raw = lines[i]
|
|
309
|
+
if (MACHINE_LIST_HEADING_RE.test(raw) || machineListHeadOf(raw) !== null) return null
|
|
310
|
+
if (!MACHINE_LIST_ROW_RE.test(raw)) continue // 空行 ∥ 围栏行 ∥ 散文:都不划块界
|
|
311
|
+
const table = []
|
|
312
|
+
for (let j = i; j < lines.length && MACHINE_LIST_ROW_RE.test(lines[j]); j++) table.push(lines[j])
|
|
313
|
+
return table
|
|
314
|
+
}
|
|
315
|
+
return null
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* 段内状态行**单行改写**(status / close / 重开三处共用——改写面之一,域限状态行;另两处 = §2 段体区间改写
|
|
320
|
+
* (`edit`,§4.19)∥ 重开追记行(§4.18-B),三处都不动其余字节):定位 `## §N` 段
|
|
321
|
+
* (sectionHeaderRe 单源),**段头区**(标题行之后、下一 `##` / `###` 起行之前)内首命中行原位替换(行尾随命中行
|
|
322
|
+
* 自身);区内无该行 ⇒ 沿用既有插入形(状态行 + 两空行,段头后原有空行不动;插入块行尾 = 标题行自身行尾)。
|
|
323
|
+
* 区外正文(轮次块引述的 `**状态行**:…` 行)字节零变——住所只有段头区,§1–§5 同一规则,无按段分支。
|
|
324
|
+
* 字节零变(行切分 = /\r?\n/:EOL 形态无关);段标题缺失 ⇒ throw(create 是骨架唯一权威入口);纯字符串变换(零 fs)。
|
|
325
|
+
* @param {string} src — 档全文
|
|
326
|
+
* @param {number|string} seg — 段号
|
|
327
|
+
* @param {string} value — 状态行值(`**状态行**:<value>`)
|
|
328
|
+
* @returns {string} 改写后全文
|
|
329
|
+
*/
|
|
330
|
+
export function updateSectionStatusLine(src, seg, value) {
|
|
331
|
+
const hdr = sectionHeaderRe(seg).exec(src)
|
|
332
|
+
if (!hdr) {
|
|
333
|
+
throw new Error(`batch: the batch record has no "## §${seg}" section header — cannot update its status line (create is the skeleton's only authoritative entry; append/status never add one). Nothing was written.`)
|
|
334
|
+
}
|
|
335
|
+
const nextRe = /^## §\d/gm
|
|
336
|
+
nextRe.lastIndex = hdr.index + hdr[0].length
|
|
337
|
+
const next = nextRe.exec(src)
|
|
338
|
+
const endIdx = next ? next.index : src.length
|
|
339
|
+
const line = `**状态行**:${value}`
|
|
340
|
+
const parts = src.slice(hdr.index, endIdx).split(/(\r?\n)/) // 保留分隔符(奇数下标 = 行尾)——替换只动命中行
|
|
341
|
+
const zoneEnd = parts.findIndex((p, i) => i >= 2 && ZONE_END_RE.test(p)) // 段头区界下标(0 = 段头行自身,不判)
|
|
342
|
+
const limit = zoneEnd < 0 ? parts.length : zoneEnd
|
|
343
|
+
const idx = parts.findIndex((p, i) => i < limit && STATUS_LINE_RE.test(p))
|
|
344
|
+
if (idx >= 0) { parts[idx] = line } else {
|
|
345
|
+
const eol = parts[1] === "\r\n" ? "\r\n" : "\n" // 缺行插入块行尾 = 标题行自身行尾
|
|
346
|
+
if (parts.length === 1) parts.splice(1, 0, eol, line, eol, "", eol, "")
|
|
347
|
+
else parts.splice(2, 0, line, eol, "", eol, "", eol)
|
|
348
|
+
}
|
|
349
|
+
return src.slice(0, hdr.index) + parts.join("") + src.slice(endIdx)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* §N 段状态词解析(读面单源,设计档 §2.5 的单源表):段头(sectionHeaderRe)/ 状态行正则(STATUS_LINE_RE)/
|
|
354
|
+
* 词表(STATUS_WORDS)全消费既有单源常量——与冻结门字面零漂移。**取值区只有一个 = 段头区**(`## §N` 标题行
|
|
355
|
+
* 之后、下一 `^#{2,}` 之前,与写面 `updateSectionStatusLine` 同一条定位面);区外正文引述的 `**状态行**:…`
|
|
356
|
+
* 既不被改写,也不构成结论。区内**恰一条**(可读行,计数义 §4.21.4)时按**终态词优先**(closed / done 先于 open
|
|
357
|
+
* ——镜像冻结门取值序)⇒ 返回该关键词;段头缺失 / 无该行 / **区内两条以上** / 无命中 ⇒ null。
|
|
358
|
+
* `§4` / `§6` 无词条 ⇒ 字面 `无状态词`(不造词)。
|
|
359
|
+
* @param {string} src — 档全文
|
|
360
|
+
* @param {number|string} seg — 段号(`2` / `"2"`——同 sectionHeaderRe 消费形)
|
|
361
|
+
* @returns {string|null} 已识别关键词 / null / 字面「无状态词」(§4 / §6)
|
|
362
|
+
*/
|
|
363
|
+
export function readSectionStatusWord(src, seg) {
|
|
364
|
+
const words = STATUS_WORDS[seg]
|
|
365
|
+
if (!words) return "无状态词"
|
|
366
|
+
const hits = zoneStatusLines(src, seg)
|
|
367
|
+
if (hits.length !== 1) return null // 零条 = 无该行 ∥ 两条以上 = 可读行不存在(§4.21.4 同判 null)
|
|
368
|
+
const m = STATUS_LINE_RE.exec(hits[0])
|
|
369
|
+
if (!m) return null
|
|
370
|
+
const value = m[1].trim()
|
|
371
|
+
// 旧字面先映到规范词(读侧等义——写侧词表零别名)
|
|
372
|
+
for (const [alias, canonical] of Object.entries(STATUS_WORD_ALIASES[seg] ?? {})) {
|
|
373
|
+
if (value.includes(alias)) return canonical
|
|
374
|
+
}
|
|
375
|
+
for (const w of [words.closed, words.done, words.open]) {
|
|
376
|
+
if (w !== undefined && value.includes(w)) return w
|
|
377
|
+
}
|
|
378
|
+
return null
|
|
379
|
+
}
|