@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
package/agent-tools/consult.mjs
CHANGED
|
@@ -23,7 +23,10 @@
|
|
|
23
23
|
* 同族收齐批 · #748; a cancelled session's children emit ⟦ev⟧stopped — R17: the old
|
|
24
24
|
* in-turn check consumption is gone; consumed blocks archive at the consumption window).
|
|
25
25
|
*/
|
|
26
|
-
import { createAgent, runAgent,
|
|
26
|
+
import { createAgent, runAgent, excludeSubagentTools } from "../agent.mjs"
|
|
27
|
+
// B4(TOOLS.md §6.29 ①):会诊席与派单面同一只读派生面(构造器 ∥ 判据各一处单源)。
|
|
28
|
+
import { deriveReadonlyTools } from "../agent/helpers.mjs"
|
|
29
|
+
import { readonlyActionTest } from "../agent/dispatch-gates.mjs"
|
|
27
30
|
import { resolveChildProvider } from "./subagent.mjs"
|
|
28
31
|
import { pushReal } from "../context.mjs"
|
|
29
32
|
import { offloadToolResult, escapeXml } from "../agent/helpers.mjs"
|
|
@@ -273,9 +276,9 @@ async function runConsultChild(ctx, session, id, m, problem, ctrl) {
|
|
|
273
276
|
clampEffort(provider, m.model, m.effort)
|
|
274
277
|
|
|
275
278
|
// Read-only consultant: filter the parent tool set down to readonly tools + main_history.
|
|
276
|
-
|
|
279
|
+
// B4(TOOLS.md §6.29 ①):整把只读集 ∪ action 级只读变体(与 core 派单面同一派生面、同一判据)。
|
|
277
280
|
const tools = [
|
|
278
|
-
...excludeSubagentTools((agent.tools ?? []
|
|
281
|
+
...excludeSubagentTools(deriveReadonlyTools(agent.tools ?? [], readonlyActionTest)), // TOOLS.md §6.16:继承面过谓词
|
|
279
282
|
makeMainHistoryTool(agent),
|
|
280
283
|
]
|
|
281
284
|
|
|
@@ -404,7 +407,7 @@ export const consultStartTool = {
|
|
|
404
407
|
type: "object",
|
|
405
408
|
properties: {
|
|
406
409
|
problem: { type: "string", description: "Problem brief (symptom + failure trail + entry files)" },
|
|
407
|
-
models: { type: "array", items: { type: "string" }, description: 'Optional subset
|
|
410
|
+
models: { type: "array", items: { type: "string" }, description: 'Optional subset to narrow the pool — omit to run the whole pool. Each entry is "provider:model", a bare provider, or a bare model name (case-insensitive).' },
|
|
408
411
|
},
|
|
409
412
|
required: ["problem"],
|
|
410
413
|
},
|
package/agent-tools/context.mjs
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
* 单一工具三操作(用户定形 F-CC5):`stats`(感知 F-CC1)· `prune`(噪声清理 F-CC3)· `compact`(主动压缩 F-CC2,携 focus + 自动附任务/目标 + 可回查锚——裁令 A/D)。
|
|
4
4
|
* 描述外置(tool-docs/context.md——#15 统一面:文本单点 = tool-docs,DESC 加载);装配面 = 登记册 `agent-tools.mjs`(#83)+ `agent/family-tools.mjs` 的 depth-0 段(`depthOnly`)——两端自动同表;**depth>0 不给**(§6.16.6)。
|
|
5
5
|
* 本档同时是**注记文案 / 轻推行 / 回执文案的单源**(核与 VSC 的 run-stages 消费点经动态 import 取用——零新增静态边)。
|
|
6
|
-
* 机械面:`stats` 不新增第三口径(首行主口径 =
|
|
6
|
+
* 机械面:`stats` 不新增第三口径(首行主口径 = 可填量占用 total / `limit`,窗口与压缩线各以具名数值呈现;状态行行(第 6 行)走核 `historyReading`——与 CLI ∥ VSC 同源:一个实现点,端侧零自算式);`prune` = 合格集(`token-window.mjs` 单源)+「原位换内容」应用面(`context-degrade.mjs`);`compact` **当次零执行**(只登记 `agent._pendingCompact`,由下一安全点消费——§6.16.2)。
|
|
7
7
|
*/
|
|
8
8
|
import { contextUsage, estimateTokens, collectStaleToolOutputs, historyReading, tokenRatioOf, PRUNE_MIN_TOKENS } from "../token-window.mjs"
|
|
9
|
-
|
|
10
|
-
import {
|
|
9
|
+
// 预算面 = **有效窗口**(`CONTEXT-COMPACTION.md` §2.2:stats ∥ 守卫 ∥ 压缩同一个预算对象)
|
|
10
|
+
import { policyBudget, resolveWorkMode } from "../config.mjs"
|
|
11
|
+
import { pruneStaleToolOutputs } from "../context.mjs"
|
|
12
|
+
// 保留窗起点(#2431):stats 的 prunable 读数与 prune 本体同一个合格集——两处传同一值,不自成第二套(§1.2)。
|
|
13
|
+
import { retentionWindowStart } from "../agent/turn-projection.mjs"
|
|
11
14
|
import { slotPath } from "../session-slots.mjs"
|
|
12
15
|
// #15 描述外置:描述文本单点 = tool-docs/context.md(DESC 单解析面,缺档抛错语义不变)
|
|
13
16
|
import { DESC } from "../tools/shared.mjs"
|
|
@@ -23,9 +26,20 @@ export function compactNoopNote() {
|
|
|
23
26
|
return `${CONTEXT_NOTE_PREFIX} did nothing right now (no middle section — the history is too short to summarize). The context is unchanged.]`
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
/**
|
|
29
|
+
/** 压缩 no-op 注记——固定开销单独越线(`CONTEXT-COMPACTION.md` §5):与守卫抛出的 typed error **同一个原因**,
|
|
30
|
+
* 回执里带 `reason`、固定开销、limit 与 window 三数,并说清压缩解不了——不把方向指到会话内容上。 */
|
|
31
|
+
export function compactOverheadNote(fixedFloor, limit, window) {
|
|
32
|
+
return `${CONTEXT_NOTE_PREFIX} did nothing right now: the fixed overhead (system + tools) ~${fixedFloor} tokens alone` +
|
|
33
|
+
` exceeds the limit ${limit} (window ${window}) — reason: overhead_exceeds_limit.` +
|
|
34
|
+
` Compaction cannot help (the overhead stays after the history is summarized): lower max_tokens,` +
|
|
35
|
+
` switch to a larger-window model, or trim the system prompt / tools declaration.]`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 压缩失败注记(§6.16.2 回执面②——模型面告知缺口)。§5.1 之后**没有「第 N 次 / 共 3 次」**:摘要在失败当次
|
|
39
|
+
* 就转确定性丢弃,计数不再是一道降级门的输入。这条注记只在整条链没留下任何产物时才落(摘要失败且无中段可丢),
|
|
40
|
+
* 所以它说的是「这一次没压成」,不是「已经压过一次」。 */
|
|
27
41
|
export function compactFailureNote(message, attempt) {
|
|
28
|
-
return `${CONTEXT_NOTE_PREFIX} failed (attempt ${attempt}
|
|
42
|
+
return `${CONTEXT_NOTE_PREFIX} failed (attempt ${attempt}): ${message} — the context is unchanged: the summary call failed and there was no middle section to drop.]`
|
|
29
43
|
}
|
|
30
44
|
|
|
31
45
|
/** 轻推锚(§6.16.5):active goal 目标 ⇒ in_progress 任务标题 ⇒ 首个 pending 标题 ⇒ `(none set)`。 */
|
|
@@ -64,8 +78,14 @@ export function pushContextNudge(agent) {
|
|
|
64
78
|
|
|
65
79
|
/** stats 报面(§6.16.4 逐行定稿——机判可解析;三段 / 工具输出小计 / 状态行百分比 / 压缩履历)。 */
|
|
66
80
|
function statsReport(agent) {
|
|
81
|
+
// 档位自 agent 现取(§2.3 握有 agent 的面自取):本档三处读数(有效窗口预算 ∥ 保护尾 ∥ 状态行分母)同取它。
|
|
82
|
+
const workMode = resolveWorkMode(agent?.config?.agent)
|
|
67
83
|
const usage = contextUsage(agent, agent?._ctxBasis?.overhead ?? {})
|
|
68
|
-
|
|
84
|
+
// 合格集与 prune 本体同一组实参(§2.3 表):`fixedOverhead` ∥ `ratio` 都当场现算,没有一处落盘。
|
|
85
|
+
const stale = collectStaleToolOutputs(
|
|
86
|
+
agent?.history ?? [], agent?.provider, workMode, retentionWindowStart(agent),
|
|
87
|
+
usage.overhead, tokenRatioOf(agent),
|
|
88
|
+
)
|
|
69
89
|
let toolOut = 0
|
|
70
90
|
let toolCount = 0
|
|
71
91
|
for (const m of agent?.history ?? []) {
|
|
@@ -73,12 +93,15 @@ function statsReport(agent) {
|
|
|
73
93
|
toolCount++
|
|
74
94
|
toolOut += estimateTokens([m])
|
|
75
95
|
}
|
|
76
|
-
|
|
96
|
+
// 预算取一次,全行共用(§7.1「从同一 contextUsage ∥ policyBudget ∥ historyReading 取数,各自具名,不混用分母」)。
|
|
97
|
+
const budget = policyBudget(agent?.provider, undefined, workMode)
|
|
98
|
+
// 分母 = `limit`(用户实际可填的量,§2.5 / §7.1):与状态行第 6 行同一个数,`window` 只作具名读数出现。
|
|
99
|
+
const pct = Math.round((usage.total / budget.limit) * 100)
|
|
77
100
|
const toGo = Math.max(0, usage.threshold - usage.total) // 已越阈值 ⇒ 0(自动压缩将在下一安全点接手)
|
|
78
101
|
const info = agent?._lastCompressInfo
|
|
79
102
|
const compaction = !info ? "none"
|
|
80
103
|
: info.mode === "summary" ? `last summary freed ${info.tokensFreed} tokens`
|
|
81
|
-
:
|
|
104
|
+
: `last fallback discard: dropped ${info.discardedMessages ?? 0} msg / ${info.discardedTurns ?? 0} turn(s), kept ${info.tailMessages ?? 0} tail msg`
|
|
82
105
|
// Cache line (batch 2026-10-18-context-cache-visibility): the provider reports
|
|
83
106
|
// prompt_cache_hit/miss per response; the core now tallies them so the question
|
|
84
107
|
// "is the prefix cache actually helping?" is answered by a reading, not a guess.
|
|
@@ -91,29 +114,32 @@ function statsReport(agent) {
|
|
|
91
114
|
: `Cache: hit ${cacheHit} · miss ${cacheMiss} tokens (${Math.round((cacheHit / cacheTotal) * 100)}% hit) across ${cacheTurns} response(s)`
|
|
92
115
|
// 第 6 行 = 核读数投影(§6.16.4):`pct` 与括号内的 `calibratedHistory` 是同一次调用的两个返回值——同屏两值同尺;
|
|
93
116
|
// 标记 `calibrated history estimate` 把它与 `Segments ≈` 行的裸估算 `history`(核 `estimateTokens`,未乘比)分名。
|
|
94
|
-
const statusReading = historyReading(agent?.history ?? [], agent?.provider, tokenRatioOf(agent))
|
|
117
|
+
const statusReading = historyReading(agent?.history ?? [], agent?.provider, tokenRatioOf(agent), workMode)
|
|
95
118
|
return [
|
|
96
|
-
`Context ≈${usage.total} tokens (${pct}% of ${usage.window}
|
|
97
|
-
// §6.16.4 字面单源(该行为唯一字面,逐字;预算面同源
|
|
119
|
+
`Context ≈${usage.total} tokens (${pct}% of ${budget.limit} fillable limit; window ${usage.window}, compaction line ${usage.threshold} (${toGo} to the line))`,
|
|
120
|
+
// §6.16.4 字面单源(该行为唯一字面,逐字;预算面同源 policyBudget——不自算第二套):
|
|
98
121
|
// window {window} ({modelContext|provider-override|list|spec|default}) · max_tokens {maxTokens|not sent} ({explicit|spec|absent})
|
|
99
122
|
// · prompt {total} · to compaction line {threshold − total} · to window limit {limit − total}
|
|
100
|
-
// 两距离带符号(负 = 已越);maxTokens 未发写 not sent、来源写 absent
|
|
123
|
+
// 两距离带符号(负 = 已越);maxTokens 未发写 not sent、来源写 absent。
|
|
101
124
|
(() => {
|
|
102
|
-
const budget = requestBudget(agent?.provider)
|
|
103
125
|
const mt = budget.maxTokens === undefined ? "not sent" : String(budget.maxTokens)
|
|
104
126
|
return `Request budget: window ${budget.window} (${budget.windowSource}) · max_tokens ${mt} (${budget.maxTokensSource})`
|
|
127
|
+
+ ` · input limit ${budget.limit} (window − reserve ${budget.reserve})`
|
|
105
128
|
+ ` · prompt ${usage.total} · to compaction line ${usage.threshold - usage.total}`
|
|
106
129
|
+ ` · to window limit ${budget.limit - usage.total}`
|
|
107
130
|
})(),
|
|
108
131
|
`Segments ≈: system ${usage.system} · tools ${usage.tools} · history ${usage.history} (basis: ${usage.basis})`,
|
|
109
132
|
`History: tool outputs ${toolOut} tokens in ${toolCount} msgs · prunable stale ${stale.tokens} tokens in ${stale.indexes.length} msgs · protected tail ${stale.tailCount} msgs`,
|
|
110
133
|
cacheLine,
|
|
111
|
-
`Status line: context ${statusReading.pct}% (${statusReading.tokens} calibrated history estimate / ${statusReading.
|
|
112
|
-
`Compaction so far: ${compaction} ·
|
|
134
|
+
`Status line: context ${statusReading.pct}% (${statusReading.tokens} calibrated history estimate / ${statusReading.limit} fillable limit, compaction line ${statusReading.threshold})`,
|
|
135
|
+
`Compaction so far: ${compaction} · failed attempts ${agent?._compressFailures ?? 0}`,
|
|
113
136
|
].join("\n")
|
|
114
137
|
}
|
|
115
138
|
|
|
116
|
-
/** prune 回执(§6.16.3:计数 + 扫过候选 / 保护尾内保留 / 门槛下跳过 + 记录面零改)。
|
|
139
|
+
/** prune 回执(§6.16.3:计数 + 扫过候选 / 保护尾内保留 / 门槛下跳过 + 记录面零改)。
|
|
140
|
+
* 可回查面(`CONTEXT-COMPACTION.md` §7.2):只报释放量与跳过项、请模型需要时重跑工具,**不指向任何回查位置**——
|
|
141
|
+
* 落盘的只有人读线那一份、且长工具结果只留 slim 后的前段(射程见 `SESSION.md` §5),写「全文仍在盘上」是一句
|
|
142
|
+
* 兑现不了的话;内存里的全史随进程走,重启之后没有第二条通道。 */
|
|
117
143
|
function pruneReceipt(agent) {
|
|
118
144
|
const r = pruneStaleToolOutputs(agent)
|
|
119
145
|
const scan = `(scanned ${r.candidates} tool result(s): ${r.tailKept} inside the protected tail, ${r.belowMin} below the ${PRUNE_MIN_TOKENS}-token floor)`
|
|
@@ -121,7 +147,8 @@ function pruneReceipt(agent) {
|
|
|
121
147
|
return `Nothing to prune — no stale tool output matched ${scan}. The context and the session record are unchanged.`
|
|
122
148
|
}
|
|
123
149
|
return `Pruned ${r.pruned} stale tool output(s) ≈${r.freed} tokens freed ${scan}. ` +
|
|
124
|
-
`Tool pairing is intact and the session record is unchanged
|
|
150
|
+
`Tool pairing is intact and the session record is unchanged. The record keeps only the front segment of a long tool result, ` +
|
|
151
|
+
`so this text is not retrievable from it — re-run the tool if you need that output again.`
|
|
125
152
|
}
|
|
126
153
|
|
|
127
154
|
/**
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* design-review-record.mjs — 设计评审结算的轮次块成形(**纯函数 · 零 import · 零 fs**)。
|
|
3
|
+
*
|
|
4
|
+
* 单源 = `docs/core/design/BATCH-RECORD.md` §4.4「块形三件,按序」:工具戳 `### 轮次 N(评审子代理)`
|
|
5
|
+
* → 结算头一行 `**结算**:<已签发|未签发>(<原因>)· <日期>` → 本轮结论三件,按序:结论表行 → 裁定行
|
|
6
|
+
* → 计数行。评审的推理正文不进块——它留在评审报告里,整份仍随本轮报告回父侧。
|
|
7
|
+
*
|
|
8
|
+
* 为什么单独成叶档:`design-token.mjs` 的成形逻辑再加进去就越 500 软线;而本档零 import
|
|
9
|
+
* 也就零环(它在批次档依赖链之外,结算引它不把任何档拉进 `design-token.mjs` 的静态闭包)。
|
|
10
|
+
*
|
|
11
|
+
* 成形与写盘分开:本档只产文本,写仍归结算的单通道(`design-token.mjs` 的 `recordWriter`)——一条写路,
|
|
12
|
+
* 一次回读,失败一次回退。
|
|
13
|
+
*
|
|
14
|
+
* 缩进四格的两条理由(同 §4.4):整块成为缩进代码块,文档检查的段长判据不计它;裁定锚允许前导空白,
|
|
15
|
+
* 缩进后照旧命中,故状态行计划与 `§5` 门读的是同一份正文,零新解析。段标题锚 `^## §N` 与轮次块锚
|
|
16
|
+
* `ROUND_HEADING_RE` 只认行首,而块内三类行(表行、裁定行、计数行)都不以 `## §` 或 `### 轮次` 起头
|
|
17
|
+
* ——两枚锚不会命中块内内容。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** 结算头的两个结局词(§4.4 逐字——机器可 grep)。 */
|
|
21
|
+
export const SETTLEMENT_SIGNED = "已签发"
|
|
22
|
+
export const SETTLEMENT_UNSIGNED = "未签发"
|
|
23
|
+
|
|
24
|
+
/** 结算处置四词(§4.4「结算头的原因两个族」逐字):裁定闸三格 + 回显失败支。宿主不完整族另占同一格,
|
|
25
|
+
* 取该 kind 词(哪一轮的正文可能缺半,处置词读不出可信的结论)。本档另担两件文本:结算头与裁定行——
|
|
26
|
+
* 四个词与它们对应的裁定行同住,块的每一行文本单源在一处。 */
|
|
27
|
+
export const DISPOSITION_PASS = "pass"
|
|
28
|
+
export const DISPOSITION_CHANGES_REQUIRED = "changes-required"
|
|
29
|
+
export const DISPOSITION_NO_PASS_LINE = "no-pass-line"
|
|
30
|
+
export const DISPOSITION_NO_ECHO = "no-valid-echo"
|
|
31
|
+
|
|
32
|
+
const VERDICT_LINES = new Map([
|
|
33
|
+
[DISPOSITION_PASS, "VERDICT: pass"],
|
|
34
|
+
[DISPOSITION_CHANGES_REQUIRED, "VERDICT: changes-required"],
|
|
35
|
+
[DISPOSITION_NO_PASS_LINE, "本轮无裁定行(评审未给出 VERDICT 行)"],
|
|
36
|
+
[DISPOSITION_NO_ECHO, "本轮未回显有效 token(评审回执不完整)"],
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 本轮裁定行(§4.4「裁定行」):由结算按本轮处置取,**不从评审体里挑**——块内裁定、结算头与凭证结局
|
|
41
|
+
* 三处必须同源;挑出来的裁定会造出「块说 pass、结算头说未签发」的第三态。
|
|
42
|
+
* 后三行是恒定说明行,不命中任何裁定锚:未签发的轮次不许在 `§5` 门那一面读成一个裁定。
|
|
43
|
+
* @param {string} disposition 处置四词之一,或宿主不完整族的 kind 词
|
|
44
|
+
* @returns {string} 单行裁定行
|
|
45
|
+
*/
|
|
46
|
+
export function verdictLineOf(disposition) {
|
|
47
|
+
const known = VERDICT_LINES.get(disposition)
|
|
48
|
+
if (known) return known
|
|
49
|
+
// 处置四词之外只有一个来源 = 宿主不完整族的 kind 词(§4.4 该族一段):那一轮没有裁定,行内点名该 kind。
|
|
50
|
+
return `本轮评审不完整(${disposition}),不产生裁定`
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** 结论表认不出时的块内恒定标记与计数行(§4.4——逐字,机器可 grep)。 */
|
|
54
|
+
export const NO_CONCLUSION_MARK = "本轮无结论表"
|
|
55
|
+
export const COUNTS_UNAVAILABLE = "计数:不可得出"
|
|
56
|
+
|
|
57
|
+
/** 结论表四个列名(§4.4 归一后逐字比对;顺序即规范字面形的顺序)。 */
|
|
58
|
+
const CONCLUSION_COLUMNS = ["#", "severity", "status", "evidence"]
|
|
59
|
+
|
|
60
|
+
/** 严重度三标记(§4.4 计数行;顺序即计数行的输出顺序)。 */
|
|
61
|
+
const SEVERITY_MARKS = ["🔴", "🟡", "🔵"]
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 结算头一行(§4.4 第 2 件):`**结算**:<已签发|未签发>(<原因>)· <日期>`。
|
|
65
|
+
* 原因取处置四词,或宿主不完整族的 kind 词(评审完整时取前者——那一轮的正文可能缺半,
|
|
66
|
+
* 处置词读不出可信的结论)。
|
|
67
|
+
* 它说的是引擎怎样处置本轮,不是评审的裁定——两者在拒签轮恰好相反,故分成两处写。
|
|
68
|
+
* @param {{signed: boolean, reason: string, date: string}} p
|
|
69
|
+
* @returns {string} 单行结算头
|
|
70
|
+
*/
|
|
71
|
+
export function settlementHeaderLine({ signed, reason, date }) {
|
|
72
|
+
return `**结算**:${signed ? SETTLEMENT_SIGNED : SETTLEMENT_UNSIGNED}(${reason})· ${date}`
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** 一行是不是表行:行首允许前导空白,首字符 `|`。 */
|
|
76
|
+
const isTableLine = (line) => /^[ \t]*\|/.test(line)
|
|
77
|
+
|
|
78
|
+
/** 一行的切格(去掉行首尾的 `|` 再按 `|` 切)。表行与分隔行同一切法。 */
|
|
79
|
+
function cellsOf(line) {
|
|
80
|
+
const t = line.trim()
|
|
81
|
+
const inner = t.startsWith("|") ? t.slice(1) : t
|
|
82
|
+
const body = inner.endsWith("|") ? inner.slice(0, -1) : inner
|
|
83
|
+
return body.split("|")
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** 表头归一只做三件(§4.4):去两侧空白、去两侧反引号、小写化。三条都是格式噪声,不改语义。 */
|
|
87
|
+
function normalizeHeaderCell(cell) {
|
|
88
|
+
return cell.replace(/^[\s`]+/, "").replace(/[\s`]+$/, "").toLowerCase()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 每行是否参与认表(§4.4):围栏代码块与四空格缩进块里的行不参与——报告里复述块形、举出表头样例
|
|
93
|
+
* 都不构成结论表。围栏按成对开合标记切(``` ∥ ~~~,开合标记同类才算闭合)。
|
|
94
|
+
* @param {string[]} lines
|
|
95
|
+
* @returns {boolean[]}
|
|
96
|
+
*/
|
|
97
|
+
function tableEligibility(lines) {
|
|
98
|
+
const out = []
|
|
99
|
+
let fence = null
|
|
100
|
+
for (const line of lines) {
|
|
101
|
+
const opener = /^ {0,3}(`{3,}|~{3,})/.exec(line)
|
|
102
|
+
if (fence === null) {
|
|
103
|
+
if (opener) {
|
|
104
|
+
fence = opener[1][0]
|
|
105
|
+
out.push(false)
|
|
106
|
+
continue
|
|
107
|
+
}
|
|
108
|
+
out.push(!/^(?: {4,}|\t)/.test(line))
|
|
109
|
+
continue
|
|
110
|
+
}
|
|
111
|
+
if (opener && opener[1][0] === fence) fence = null
|
|
112
|
+
out.push(false)
|
|
113
|
+
}
|
|
114
|
+
return out
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** 一段文本里最先出现的严重度标记(没有 ⇒ `null`)。 */
|
|
118
|
+
function firstSeverityMark(text) {
|
|
119
|
+
let best = null
|
|
120
|
+
let at = -1
|
|
121
|
+
for (const mark of SEVERITY_MARKS) {
|
|
122
|
+
const i = text.indexOf(mark)
|
|
123
|
+
if (i < 0) continue
|
|
124
|
+
if (at < 0 || i < at) {
|
|
125
|
+
at = i
|
|
126
|
+
best = mark
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return best
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 结论表行(§4.4「结论表行」一段):取评审体里**最后一块**连续表行(行首允许前导空白、首字符 `|`,
|
|
134
|
+
* 块内每行同形不中断);该块首行切格、逐格归一后须逐字等于 `#` ∥ `severity` ∥ `status` ∥ `evidence`
|
|
135
|
+
* 四格,第二行须是分隔行(每格只含 `-`、`:` 与空白)。命中 ⇒ 整块原样返回(一字不改、列不增删)。
|
|
136
|
+
*
|
|
137
|
+
* 为什么取最后一块:契约把结论表放在 findings 之后、裁定行之前,最后一块就是它——取首块会把推理里的
|
|
138
|
+
* 对照表当结论。为什么按四列认表:只按首格认表挡不住报告结尾另起的无关表(核对记录那类),块里看着
|
|
139
|
+
* 有表、内容却是别人的记录,比空着更坏。
|
|
140
|
+
* @param {string} body 评审原文(凭证已剥)
|
|
141
|
+
* @returns {string|null} 结论表整块(表头 + 分隔 + 表体)∥ `null`(认不出)
|
|
142
|
+
*/
|
|
143
|
+
export function conclusionOf(body) {
|
|
144
|
+
const lines = String(body ?? "").replace(/\r\n?/g, "\n").split("\n")
|
|
145
|
+
const eligible = tableEligibility(lines)
|
|
146
|
+
let end = -1
|
|
147
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
148
|
+
if (eligible[i] && isTableLine(lines[i])) {
|
|
149
|
+
end = i
|
|
150
|
+
break
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (end < 0) return null
|
|
154
|
+
let start = end
|
|
155
|
+
while (start > 0 && eligible[start - 1] && isTableLine(lines[start - 1])) start--
|
|
156
|
+
const block = lines.slice(start, end + 1)
|
|
157
|
+
if (block.length < 2) return null
|
|
158
|
+
const header = cellsOf(block[0]).map(normalizeHeaderCell)
|
|
159
|
+
if (header.length !== CONCLUSION_COLUMNS.length) return null
|
|
160
|
+
if (!CONCLUSION_COLUMNS.every((name, i) => header[i] === name)) return null
|
|
161
|
+
const separator = cellsOf(block[1])
|
|
162
|
+
if (separator.length !== header.length || !separator.every((cell) => /^[-:\s]+$/.test(cell))) return null
|
|
163
|
+
return block.join("\n")
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* 计数行(§4.4「计数行」一段):由结算按取到的表体算,不取评审自己写的统计句。
|
|
168
|
+
* 表体 = 表头行与分隔行之后的行,这两行不计。逐行一次:先取 `severity` 那一格,格内命中的标记即该行
|
|
169
|
+
* 档位;该格为空才落到行内最先命中的标记;三者皆无记「未标」。
|
|
170
|
+
*
|
|
171
|
+
* 为什么先取 `severity` 一格:那一格就是档位列,证据格里引用的档位标记(引判据、复述上一轮那类)不该
|
|
172
|
+
* 改这一行的计数。格子空着是表没写全,那时才退回扫行。
|
|
173
|
+
* @param {string} table 结论表整块(`conclusionOf` 的返回值)
|
|
174
|
+
* @returns {string} 单行计数行
|
|
175
|
+
*/
|
|
176
|
+
export function conclusionCounts(table) {
|
|
177
|
+
const lines = table.split("\n")
|
|
178
|
+
const severityAt = CONCLUSION_COLUMNS.indexOf("severity")
|
|
179
|
+
const tally = new Map([...SEVERITY_MARKS.map((m) => [m, 0]), [null, 0]])
|
|
180
|
+
for (const row of lines.slice(2)) {
|
|
181
|
+
const cells = cellsOf(row)
|
|
182
|
+
const raw = cells[severityAt]
|
|
183
|
+
const cell = typeof raw === "string" ? raw.trim() : ""
|
|
184
|
+
// 格里有字 ⇒ 只看这一格(命中不了就是「未标」,不回退扫行);格空 ∥ 该格缺位 ⇒ 才退回扫行。
|
|
185
|
+
const hit = cell ? firstSeverityMark(cell) : firstSeverityMark(row)
|
|
186
|
+
tally.set(hit, tally.get(hit) + 1)
|
|
187
|
+
}
|
|
188
|
+
const parts = SEVERITY_MARKS.map((m) => `${m} ${tally.get(m)}`)
|
|
189
|
+
parts.push(`未标 ${tally.get(null)}`)
|
|
190
|
+
return `计数:${parts.join(" · ")}`
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* 轮次块全文(§4.4 三件,按序)——与 `batch-record-write.mjs` 的 `insertIntoSection` 同形
|
|
195
|
+
* (工具戳 + 空行 + 正文),故两条写路落进 §3 的块读起来一样。
|
|
196
|
+
* 前导空行 = 与上一块 / 段标题分开:段尾本来已有空行时多一行空白,markdown 渲染与判据都无差别。
|
|
197
|
+
* @param {Object} p
|
|
198
|
+
* @param {number} p.roundN 本轮 N(单源 = `nextRoundNumber`,不另立计数)
|
|
199
|
+
* @param {boolean} p.signed 已签发 ∥ 未签发
|
|
200
|
+
* @param {string} p.reason 结算头原因(处置四词之一,或宿主不完整族的 kind 词)
|
|
201
|
+
* @param {string} p.date `YYYY-MM-DD`
|
|
202
|
+
* @param {string} p.body 评审原文(凭证已剥——凭证不落档):取的是它末尾那张结论表
|
|
203
|
+
* @param {string} p.verdictLine 本轮裁定行(结算按处置写,不从评审体里挑——必填,无默认)
|
|
204
|
+
* @param {string} [p.eol] 目标档的行尾形(`\n` ∥ `\r\n`)——块随档的 EOL 走,不混行尾
|
|
205
|
+
* @returns {string} 块全文(首行与末行都是空行——块自成一段)
|
|
206
|
+
*/
|
|
207
|
+
export function designReviewBlock({ roundN, signed, reason, date, body, verdictLine, eol = "\n" }) {
|
|
208
|
+
// 参数默认是替调用方做决定:裁定行只能由结算按本轮处置给,缺了就在三层之外现形。
|
|
209
|
+
if (typeof verdictLine !== "string" || !verdictLine.trim()) {
|
|
210
|
+
throw new Error("designReviewBlock: verdictLine is required — the settlement derives it from this round's disposition; it has no default, because a default would decide for the caller which verdict the round carries")
|
|
211
|
+
}
|
|
212
|
+
const conclusion = conclusionOf(body)
|
|
213
|
+
const rows = conclusion
|
|
214
|
+
? [...conclusion.split("\n"), verdictLine, conclusionCounts(conclusion)]
|
|
215
|
+
: [NO_CONCLUSION_MARK, verdictLine, COUNTS_UNAVAILABLE]
|
|
216
|
+
const head = [
|
|
217
|
+
`### 轮次 ${roundN}(评审子代理)`,
|
|
218
|
+
"",
|
|
219
|
+
settlementHeaderLine({ signed, reason, date }),
|
|
220
|
+
"",
|
|
221
|
+
]
|
|
222
|
+
// 尾随空行:块自成一段,后面的 `## §N` 段标题不被上一行的缩进内容紧贴(与 `insertIntoSection` 落块后
|
|
223
|
+
// 再补一个空行同形)。前导空行 = 与上一块 / 段标题分开。
|
|
224
|
+
return ["", ...head, ...rows.map((line) => ` ${line}`), ""].join(eol)
|
|
225
|
+
}
|
|
@@ -106,7 +106,7 @@ export function batchAbsPath(docSetKey) {
|
|
|
106
106
|
* `advisor.mjs` 落在实例上)优先;② 否则 `batchAbsPath(run.docSetKey)` 兜底(批档写进 `documents`
|
|
107
107
|
* 的调用形)。两源同时有值**不是取舍**——主源在手就不查兜底(派生不改写声明)。两者皆无 ⇒ `null`
|
|
108
108
|
* (归属 = 无,不猜)。设计单源 = `docs/core/design/DESIGN-TOKEN-SETTLEMENT.md` §10「批次标识的来源」;
|
|
109
|
-
*
|
|
109
|
+
* 兜底源可得归属、而结算的 §3 记录只认 `run.batchDoc` 这一残余(缺则程序不变量 throw),登记在
|
|
110
110
|
* `docs/core/design/ADVISOR-GUARDS.md` §1.2。 */
|
|
111
111
|
export function batchAbsPathOfRun(run) {
|
|
112
112
|
const bound = run?.batchDoc
|