@thincoder/core 0.11.1 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -2
- package/advisor/compaction.mjs +7 -5
- package/advisor/convergence.mjs +34 -3
- package/advisor/history.mjs +24 -11
- package/advisor/loop.mjs +49 -12
- package/advisor/messages.mjs +114 -33
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +24 -10
- package/advisor.mjs +36 -46
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/chat-call.mjs +14 -9
- package/agent/completion.mjs +70 -41
- package/agent/continue-decision.mjs +14 -8
- package/agent/digest-account.mjs +133 -59
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +10 -4
- package/agent/family-tools.mjs +37 -23
- package/agent/helpers.mjs +139 -73
- package/agent/image-heal.mjs +18 -4
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +36 -35
- package/agent/record-results.mjs +39 -7
- package/agent/run-stages.mjs +132 -52
- package/agent/run-start.mjs +150 -78
- package/agent/setup-reminders.mjs +194 -91
- package/agent/setup.mjs +219 -140
- package/agent/spawn-child.mjs +40 -3
- package/agent/suspension.mjs +43 -15
- package/agent/timers.mjs +9 -4
- package/agent/turn-domain-text.mjs +105 -0
- package/agent/turn-loop.mjs +84 -27
- package/agent/turn-projection.mjs +286 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +163 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +35 -172
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +37 -48
- package/agent-tools/async-discard.mjs +7 -2
- package/agent-tools/async-settle.mjs +18 -12
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +5 -2
- package/agent-tools/batch-closeout.mjs +223 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +240 -20
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +197 -48
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-read.mjs +151 -4
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +23 -11
- package/agent-tools/batch-segment-vocab.mjs +459 -0
- package/agent-tools/batch-skeleton.mjs +196 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +214 -0
- package/agent-tools/batch.mjs +192 -439
- package/agent-tools/browser-async.mjs +5 -2
- package/agent-tools/consult.mjs +17 -11
- package/agent-tools/context.mjs +76 -33
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +1 -1
- package/agent-tools/design-token.mjs +279 -81
- package/agent-tools/digest-budget.mjs +10 -9
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +12 -12
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/goal.mjs +5 -2
- package/agent-tools/judge-domain.mjs +347 -0
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/parent-channel.mjs +6 -3
- package/agent-tools/plan.mjs +11 -10
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +19 -6
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/skill.mjs +7 -8
- package/agent-tools/spawn-gates.mjs +14 -24
- package/agent-tools/ssh-session.mjs +8 -5
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +1 -1
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-actions.mjs +2 -2
- package/agent-tools/subagent-async.mjs +19 -17
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +13 -13
- package/agent-tools/subagent-spawn.mjs +92 -112
- package/agent-tools/subagent.mjs +16 -28
- package/agent-tools/task.mjs +0 -8
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +26 -7
- package/attachments.mjs +3 -3
- package/auto-think.mjs +5 -2
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +1 -1
- package/compaction-work-state.mjs +230 -0
- package/compress-form.mjs +41 -6
- package/config-defaults.mjs +7 -3
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +110 -110
- package/context-degrade.mjs +93 -34
- package/context-echo.mjs +6 -15
- package/context-push.mjs +328 -31
- package/context.mjs +298 -170
- package/conventions.mjs +11 -9
- package/declaration.mjs +126 -22
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +309 -213
- package/doc-check/line-refs.mjs +27 -101
- package/doc-check/paragraph.mjs +218 -102
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/escape.mjs +6 -5
- package/explore-distill.mjs +41 -8
- package/generate-title.mjs +10 -1
- package/i18n.mjs +1 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +10 -0
- package/ledger-close-proof.mjs +100 -49
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +47 -91
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +47 -15
- package/ledger-executors.mjs +1 -1
- package/ledger-tools.mjs +121 -62
- package/ledger-write-ops.mjs +162 -46
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/docs.mjs +51 -15
- package/memory/file-list.mjs +6 -0
- package/memory/schema.mjs +2 -2
- package/model-specs.mjs +87 -21
- package/origin-guard.mjs +190 -0
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +114 -2
- package/prompt-overlays.mjs +21 -11
- package/prompts/advisor-design.md +96 -36
- package/prompts/advisor-round1.md +48 -4
- package/prompts/advisor-round2.md +54 -10
- package/prompts/advisor-round3.md +53 -9
- package/prompts/common.md +99 -434
- package/prompts/consult-base.md +7 -4
- package/prompts/discipline-engineering.md +504 -295
- package/prompts/discipline-normal.md +106 -281
- package/prompts/knowledge/business-gates.md +30 -0
- package/prompts/knowledge/decision-quality.md +21 -0
- package/prompts/knowledge/doc-lookup.md +30 -0
- package/prompts/knowledge/document-writing.md +33 -0
- package/prompts/knowledge/documentation-evaluation.md +48 -0
- package/prompts/knowledge/evidence-discipline.md +38 -0
- package/prompts/knowledge/normal-coding-workflow.md +110 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +124 -0
- package/prompts/knowledge/normal-work-management.md +60 -0
- package/prompts/knowledge/product-security.md +28 -0
- package/prompts/knowledge/project-records.md +73 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +17 -0
- package/prompts/knowledge/tool-bash.md +48 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +19 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +20 -0
- package/prompts/knowledge/tool-batch-review.md +18 -0
- package/prompts/knowledge/tool-batch.md +94 -0
- package/prompts/knowledge/tool-browser.md +68 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +21 -0
- package/prompts/knowledge/tool-doc-check.md +71 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +41 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +21 -0
- package/prompts/knowledge/tool-fetch.md +18 -0
- package/prompts/knowledge/tool-file-ops.md +21 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +21 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +17 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +21 -0
- package/prompts/knowledge/tool-hashline-edit.md +16 -0
- package/prompts/knowledge/tool-insert-after.md +17 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +28 -0
- package/prompts/knowledge/tool-ledger.md +46 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +15 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +34 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +19 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +102 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +5 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +35 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +22 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +17 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +74 -0
- package/prompts/knowledge/tool-subagent.md +57 -0
- package/prompts/knowledge/tool-task.md +14 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +15 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +16 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +12 -0
- package/prompts/knowledge/upstream-protocol.md +45 -0
- package/prompts/persona-coder.md +1 -3
- package/prompts/persona-eng-coder.md +24 -6
- package/prompts/persona-eng-designer.md +150 -171
- package/prompts/persona-engineering.md +531 -442
- package/prompts/persona-explore.md +1 -3
- package/prompts/persona-normal.md +17 -9
- package/prompts/persona-plan.md +5 -3
- package/prompts/persona-tester.md +0 -2
- package/prompts/subagent-base.md +2 -2
- package/provider/anthropic.mjs +10 -6
- package/provider/core.mjs +8 -5
- package/provider/errors.mjs +63 -4
- package/provider/google.mjs +29 -10
- package/provider/reasoning-echo.mjs +16 -0
- package/provider/responses.mjs +7 -3
- package/provider/sse.mjs +11 -6
- package/provider-flows.mjs +2 -2
- package/rules.mjs +11 -10
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +131 -42
- package/session-slot-write.mjs +38 -6
- package/session.mjs +30 -11
- package/shell-identity.mjs +129 -22
- package/skip-dirs.mjs +26 -2
- package/team-ledger.mjs +34 -30
- package/text-budget.mjs +1 -1
- package/think-off.mjs +27 -0
- package/token-ttl.mjs +74 -5
- package/token-window.mjs +371 -47
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -43
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +2 -84
- package/tool-docs/browser.md +2 -49
- package/tool-docs/code_search.md +2 -2
- package/tool-docs/consult_start.md +2 -8
- package/tool-docs/consult_stop.md +2 -4
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -17
- package/tool-docs/doc_check.md +2 -107
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +2 -4
- package/tool-docs/edit.md +1 -38
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -18
- package/tool-docs/fetch.md +2 -14
- package/tool-docs/file_ops.md +2 -18
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -35
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +1 -6
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -15
- package/tool-docs/insert_after.md +2 -16
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -10
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -8
- package/tool-docs/manifest.md +2 -35
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +2 -20
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +1 -5
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -18
- package/tool-docs/read_image.md +2 -9
- package/tool-docs/recent_changes.md +2 -2
- package/tool-docs/repo_outline.md +2 -2
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +1 -12
- package/tool-docs/skill.md +2 -6
- package/tool-docs/ssh.md +1 -62
- package/tool-docs/subagent.md +2 -100
- package/tool-docs/task.md +1 -7
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +2 -19
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +2 -12
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -19
- package/tool-docs/write.md +2 -12
- package/tools/browser.mjs +54 -9
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +170 -92
- package/tools/edit-diff.mjs +78 -62
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +3 -3
- package/tools/file.mjs +28 -14
- package/tools/git.mjs +36 -21
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +5 -3
- package/tools/patch.mjs +124 -44
- package/tools/process-doc-mark.mjs +33 -4
- package/tools/repomap.mjs +25 -3
- package/tools/search.mjs +74 -26
- package/tools/shared.mjs +29 -27
- package/tools/ssh.mjs +5 -5
- package/tools/tree.mjs +32 -10
- package/tools/web-deepseek.mjs +1 -1
- package/tools/web.mjs +2 -2
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +243 -0
- package/doc-check/anchors.mjs +0 -235
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* agent/helpers.mjs(escapeXml)· context.mjs(pushReal)——叶子向、无环。
|
|
23
23
|
*/
|
|
24
24
|
import { escapeXml } from "../agent/helpers.mjs"
|
|
25
|
-
import {
|
|
25
|
+
import { pushInject, pushRecord } from "../context.mjs"
|
|
26
26
|
import { runAction } from "../browser/session.mjs"
|
|
27
27
|
import {
|
|
28
28
|
bindChildController, buildChildSignal, carrierField, getAsyncPool, parkAsyncPending,
|
|
@@ -167,7 +167,10 @@ export async function injectBrowserResult(parent, entry) {
|
|
|
167
167
|
: "ok"
|
|
168
168
|
const head = `[System reminder: background browser#${entry.id} finished — ${label} (${status}, ${seconds}s)]`
|
|
169
169
|
const body = escapeXml(String(entry.receipt ?? entry.error ?? "(no result)"))
|
|
170
|
-
|
|
170
|
+
const msg = { role: "user", content: `${head}\n${body}` }
|
|
171
|
+
// B 段:一次性投递走待发队,持久写入只落人读线(机读线零触)。
|
|
172
|
+
pushInject(parent, msg)
|
|
173
|
+
pushRecord(parent, msg)
|
|
171
174
|
writeTombstone(parent, entry.id, entry.error != null || entry.failed != null ? "failed" : "consumed", "browser")
|
|
172
175
|
}
|
|
173
176
|
|
package/agent-tools/consult.mjs
CHANGED
|
@@ -23,20 +23,23 @@
|
|
|
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
|
-
import {
|
|
31
|
+
import { pushInject, pushRecord } from "../context.mjs"
|
|
29
32
|
import { offloadToolResult, escapeXml } from "../agent/helpers.mjs"
|
|
30
33
|
import { logEvent, errText } from "../log.mjs"
|
|
31
34
|
import { deathLine } from "../abort-provenance.mjs"
|
|
32
35
|
import { makeRelay, wrapChildCallbacks, runWithContinue, ensureChildApiKey, clampEffort } from "../agent/spawn-child.mjs"
|
|
33
|
-
// TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §
|
|
36
|
+
// TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §9.2:子代理人读线窗口常量(单源——store 零依赖)。
|
|
34
37
|
import { RECORD_WINDOW_MESSAGES } from "../session-store.mjs"
|
|
35
38
|
// ASYNC-RESULT-CONTAINER.md D2/D3/D6:pending 单容器停靠 + settle 公共收尾 + child signal 单点
|
|
36
39
|
import { bindChildController, buildChildSignal, settleAsyncEntry } from "./async-settle.mjs"
|
|
37
40
|
import { registerTurnCapCheckpoint } from "./checkpoint.mjs"
|
|
38
41
|
import { drainInjectedQueue } from "./subagent-run.mjs"
|
|
39
|
-
import { digestBudgetOver, persistOverflowReport } from "./digest-budget.mjs" // B5(群 B 批 AGENT-LOOP.md §
|
|
42
|
+
import { digestBudgetOver, persistOverflowReport } from "./digest-budget.mjs" // B5(群 B 批 AGENT-LOOP.md §9 D-DG2):digest 注入预算单源
|
|
40
43
|
// #15 描述外置:描述文本单点 = tool-docs/{consult_start,consult_stop,main_history}.md(DESC 单解析面,缺档抛错语义不变)
|
|
41
44
|
import { DESC } from "../tools/shared.mjs"
|
|
42
45
|
|
|
@@ -185,7 +188,7 @@ export function composeConsultDigest(session) {
|
|
|
185
188
|
*/
|
|
186
189
|
export async function injectConsultResult(agent, entry) {
|
|
187
190
|
const full = String(entry?.report ?? "(no consultation result)")
|
|
188
|
-
// §
|
|
191
|
+
// §9 D-DG3(群 B 批 B5):计入预算的 raw = 报告正文(标签行不计)——首行标签拆出;超限
|
|
189
192
|
// 路径保留族标签行(与 VSC 镜像同形);落盘内容 = raw(与其余三族同口径)。
|
|
190
193
|
const at = full.indexOf("\n")
|
|
191
194
|
const label = at === -1 ? "" : full.slice(0, at + 1)
|
|
@@ -193,10 +196,13 @@ export async function injectConsultResult(agent, entry) {
|
|
|
193
196
|
const over = digestBudgetOver(agent, raw.length)
|
|
194
197
|
const saved = over ? await persistOverflowReport(raw, { tag: `consult-${entry?.id ?? "session"}` }) : null
|
|
195
198
|
const preview = saved ? `${label}${saved}` : await offloadToolResult(full, `consult-${entry?.id ?? "session"}`)
|
|
196
|
-
|
|
199
|
+
const msg = {
|
|
197
200
|
role: "user",
|
|
198
201
|
content: escapeXml(preview),
|
|
199
|
-
}
|
|
202
|
+
}
|
|
203
|
+
// B 段:一次性投递走待发队,持久写入只落人读线(机读线零触)。
|
|
204
|
+
pushInject(agent, msg)
|
|
205
|
+
pushRecord(agent, msg)
|
|
200
206
|
}
|
|
201
207
|
|
|
202
208
|
/** Per-child settle 路由(consult 同族收齐批 · 2026-09-30 · 台账 #748):settle 一律发
|
|
@@ -273,9 +279,9 @@ async function runConsultChild(ctx, session, id, m, problem, ctrl) {
|
|
|
273
279
|
clampEffort(provider, m.model, m.effort)
|
|
274
280
|
|
|
275
281
|
// Read-only consultant: filter the parent tool set down to readonly tools + main_history.
|
|
276
|
-
|
|
282
|
+
// B4(TOOLS.md §6.29 ①):整把只读集 ∪ action 级只读变体(与 core 派单面同一派生面、同一判据)。
|
|
277
283
|
const tools = [
|
|
278
|
-
...excludeSubagentTools((agent.tools ?? []
|
|
284
|
+
...excludeSubagentTools(deriveReadonlyTools(agent.tools ?? [], readonlyActionTest)), // TOOLS.md §6.16:继承面过谓词
|
|
279
285
|
makeMainHistoryTool(agent),
|
|
280
286
|
]
|
|
281
287
|
|
|
@@ -289,7 +295,7 @@ async function runConsultChild(ctx, session, id, m, problem, ctrl) {
|
|
|
289
295
|
// role "consult" (overlay + base would concatenate it twice).
|
|
290
296
|
role: "consult",
|
|
291
297
|
})
|
|
292
|
-
// TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §
|
|
298
|
+
// TUI-OOM-ROOTCAUSE·AGENT-LOOP.md §9.2:子代理人读线窗口(四处创建点同置)——consult 会话跨回合驻留,
|
|
293
299
|
// 不置窗则 _fullHistory 仍无界(F-O1 覆盖 depth>0 全部创建点)
|
|
294
300
|
child._historyWindow = RECORD_WINDOW_MESSAGES
|
|
295
301
|
// SUBAGENT-UPSTREAM-CHANNEL 补赋(TURN-CAP-CONTINUE.md §3.1):会诊 = 后台族(consult_start
|
|
@@ -404,7 +410,7 @@ export const consultStartTool = {
|
|
|
404
410
|
type: "object",
|
|
405
411
|
properties: {
|
|
406
412
|
problem: { type: "string", description: "Problem brief (symptom + failure trail + entry files)" },
|
|
407
|
-
models: { type: "array", items: { type: "string" }, description: 'Optional subset
|
|
413
|
+
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
414
|
},
|
|
409
415
|
required: ["problem"],
|
|
410
416
|
},
|
package/agent-tools/context.mjs
CHANGED
|
@@ -3,11 +3,15 @@
|
|
|
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 行)走核 `contextReading`——与 CLI ∥ VSC 同源:一个实现点,端侧零自算式);`prune` = 合格集(`token-window.mjs` 单源)+「原位换内容」应用面(`context-degrade.mjs`);`compact` **当次零执行**(只登记 `agent._pendingCompact`,由下一安全点消费——§6.16.2)。
|
|
7
7
|
*/
|
|
8
|
-
import { contextUsage, estimateTokens, collectStaleToolOutputs,
|
|
9
|
-
|
|
10
|
-
import {
|
|
8
|
+
import { contextUsage, estimateTokens, collectStaleToolOutputs, contextReading, overheadSegments, tokenRatioOf, PRUNE_MIN_TOKENS } from "../token-window.mjs"
|
|
9
|
+
// 预算面 = **有效窗口**(`CONTEXT-COMPACTION.md` §2.2:stats ∥ 守卫 ∥ 压缩同一个预算对象)
|
|
10
|
+
import { policyBudget } from "../config.mjs"
|
|
11
|
+
import { pruneStaleToolOutputs } from "../context.mjs"
|
|
12
|
+
import { flattenHistory, flatIndexOf, pushInject } from "../context.mjs"
|
|
13
|
+
// 保留窗起点(#2431):stats 的 prunable 读数与 prune 本体同一个合格集——两处传同一值,不自成第二套(§1.2)。
|
|
14
|
+
import { retentionWindowStart } from "../agent/turn-projection.mjs"
|
|
11
15
|
import { slotPath } from "../session-slots.mjs"
|
|
12
16
|
// #15 描述外置:描述文本单点 = tool-docs/context.md(DESC 单解析面,缺档抛错语义不变)
|
|
13
17
|
import { DESC } from "../tools/shared.mjs"
|
|
@@ -23,9 +27,40 @@ export function compactNoopNote() {
|
|
|
23
27
|
return `${CONTEXT_NOTE_PREFIX} did nothing right now (no middle section — the history is too short to summarize). The context is unchanged.]`
|
|
24
28
|
}
|
|
25
29
|
|
|
26
|
-
/**
|
|
30
|
+
/** 压缩 no-op 注记——非对话面单独越线(`CONTEXT-COMPACTION.md` §5):与守卫抛出的 typed error **同一个原因**,
|
|
31
|
+
* 回执里带 `reason`、六项分段(`systemPrompt` ∥ `tools` ∥ `_retained` ∥ `_inject` ∥ `_sessionHead` ∥ `_pendingInject`,并点名最大那一段)、
|
|
32
|
+
* `fixedFloor`、limit 与 window,并说清压缩解不了——不把方向指到会话内容上。
|
|
33
|
+
* `usage` = `contextUsage(...)` 的返回面(六项与 `fixedFloor` 都从它取,本函数不自己累加)。
|
|
34
|
+
*/
|
|
35
|
+
export function compactOverheadNote(usage, limit, window) {
|
|
36
|
+
const segments = overheadSegments(usage)
|
|
37
|
+
const listed = segments.map(([name, tokens]) => `${name} ${tokens}`).join(" · ")
|
|
38
|
+
const [largest, largestTokens] = segments.reduce((a, b) => (b[1] > a[1] ? b : a))
|
|
39
|
+
return `${CONTEXT_NOTE_PREFIX} did nothing right now: the non-conversation face alone ~${usage.fixedFloor} tokens` +
|
|
40
|
+
` exceeds the limit ${limit} (window ${window}) — reason: overhead_exceeds_limit.` +
|
|
41
|
+
` Segments ~: ${listed} — largest is ${largest} (${largestTokens}).` +
|
|
42
|
+
` Compaction cannot help (that face stays after the history is summarized): lower max_tokens,` +
|
|
43
|
+
` switch to a larger-window model, or trim ${largest}.]`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 压缩 no-op 注记——配置矛盾(`CONTEXT-COMPACTION.md` §2.4):与守卫抛出的 typed error **同一个原因**,
|
|
47
|
+
* 回执带 `reason: budget_contradiction` 与矛盾三数(window ∥ reserve ∥ 差值),并把方向指到配置上(不指向会话内容——那个方向是错的)。
|
|
48
|
+
* `contradiction` = 预算对象上的 `{ window, reserve, usable }`(`window-policy.mjs` 的 `budgetOf` 夹点时算出的三个数)。
|
|
49
|
+
*/
|
|
50
|
+
export function compactContradictionNote(contradiction) {
|
|
51
|
+
const c = contradiction ?? {}
|
|
52
|
+
const numbers = `window ${c.window} · reserve ${c.reserve} · difference ${c.usable}`
|
|
53
|
+
return `${CONTEXT_NOTE_PREFIX} did nothing right now: this channel's configuration has no solution — ${numbers} —` +
|
|
54
|
+
` reason: budget_contradiction. Compaction cannot help: no request can be sent until the configuration changes` +
|
|
55
|
+
` (raise the window via providers[].modelContext / a larger-context model, lower provider.maxTokens,` +
|
|
56
|
+
` or use a model whose maxOutput is smaller than its window). The context is unchanged.]`
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 压缩失败注记(§6.16.2 回执面②——模型面告知缺口)。§5.1 之后**没有「第 N 次 / 共 3 次」**:摘要在失败当次
|
|
60
|
+
* 就转确定性丢弃,计数不再是一道降级门的输入。这条注记只在整条链没留下任何产物时才落(摘要失败且无中段可丢),
|
|
61
|
+
* 所以它说的是「这一次没压成」,不是「已经压过一次」。 */
|
|
27
62
|
export function compactFailureNote(message, attempt) {
|
|
28
|
-
return `${CONTEXT_NOTE_PREFIX} failed (attempt ${attempt}
|
|
63
|
+
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
64
|
}
|
|
30
65
|
|
|
31
66
|
/** 轻推锚(§6.16.5):active goal 目标 ⇒ in_progress 任务标题 ⇒ 首个 pending 标题 ⇒ `(none set)`。 */
|
|
@@ -41,44 +76,47 @@ function nudgeAnchor(agent) {
|
|
|
41
76
|
|
|
42
77
|
/**
|
|
43
78
|
* 方向转换轻推(F-CC4 · §6.16.5):task/goal 变更后直推**一行**机器行(`transient: true`,非命令)。
|
|
44
|
-
* 去重 =
|
|
45
|
-
* 数组引用——VSC 面板持同一数组:`agent.history = <新数组>` 会让端侧局部引用失效,先例 = D-CC24
|
|
46
|
-
* 同一顾虑)。压缩重建时该行无特殊处理(一次建议——落入中段即随摘要退场、落入 tail 则保留,良性)。
|
|
79
|
+
* 去重 = **单活体行**:同前缀旧条先从待发队(B 段)摘掉再推一行 ⇒ 任意次数变更后恒**恰一行**。
|
|
47
80
|
* 深度门由调用方落(`ctx.depth === 0`——子代理拿不到 `context`,提示它拿不到的工具即噪音)。
|
|
48
81
|
*/
|
|
49
82
|
export function pushContextNudge(agent) {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
history.push({
|
|
83
|
+
const queue = Array.isArray(agent._pendingInject) ? agent._pendingInject : []
|
|
84
|
+
agent._pendingInject = queue.filter(
|
|
85
|
+
(m) => !(m?.role === "user" && typeof m.content === "string" && m.content.startsWith(CONTEXT_NUDGE_PREFIX)),
|
|
86
|
+
)
|
|
87
|
+
pushInject(agent, {
|
|
58
88
|
role: "user",
|
|
59
89
|
content: `${CONTEXT_NUDGE_PREFIX} current objective: ${nudgeAnchor(agent)}. ` +
|
|
60
90
|
`If the earlier context no longer serves this direction, you may compact it (context tool, action="compact" with a focus) — the decision is yours.]`,
|
|
61
|
-
transient: true,
|
|
62
91
|
})
|
|
63
92
|
}
|
|
64
93
|
|
|
65
94
|
/** stats 报面(§6.16.4 逐行定稿——机判可解析;三段 / 工具输出小计 / 状态行百分比 / 压缩履历)。 */
|
|
66
95
|
function statsReport(agent) {
|
|
67
96
|
const usage = contextUsage(agent, agent?._ctxBasis?.overhead ?? {})
|
|
68
|
-
const
|
|
97
|
+
const flat = flattenHistory(agent?.history ?? [])
|
|
98
|
+
const protectFrom = retentionWindowStart(agent)
|
|
99
|
+
// 合格集与 prune 本体同一组实参(§2.3 表):`fixedOverhead` ∥ `ratio` 都当场现算,没有一处落盘。
|
|
100
|
+
const stale = collectStaleToolOutputs(
|
|
101
|
+
flat, agent?.provider, protectFrom ? flatIndexOf(agent.history, protectFrom) : flat.length,
|
|
102
|
+
usage.fixed - usage.compactionSummary, tokenRatioOf(agent),
|
|
103
|
+
)
|
|
69
104
|
let toolOut = 0
|
|
70
105
|
let toolCount = 0
|
|
71
|
-
for (const m of
|
|
106
|
+
for (const m of flat) {
|
|
72
107
|
if (m?.role !== "tool") continue
|
|
73
108
|
toolCount++
|
|
74
109
|
toolOut += estimateTokens([m])
|
|
75
110
|
}
|
|
76
|
-
|
|
111
|
+
// 预算取一次,全行共用(§7.1「从同一 contextUsage ∥ policyBudget ∥ historyReading 取数,各自具名,不混用分母」)。
|
|
112
|
+
const budget = policyBudget(agent?.provider)
|
|
113
|
+
// 分母 = `limit`(用户实际可填的量,§2.5 / §7.1):与状态行第 6 行同一个数,`window` 只作具名读数出现。
|
|
114
|
+
const pct = Math.round((usage.total / budget.limit) * 100)
|
|
77
115
|
const toGo = Math.max(0, usage.threshold - usage.total) // 已越阈值 ⇒ 0(自动压缩将在下一安全点接手)
|
|
78
116
|
const info = agent?._lastCompressInfo
|
|
79
117
|
const compaction = !info ? "none"
|
|
80
118
|
: info.mode === "summary" ? `last summary freed ${info.tokensFreed} tokens`
|
|
81
|
-
:
|
|
119
|
+
: `last fallback discard: dropped ${info.discardedMessages ?? 0} msg / ${info.discardedTurns ?? 0} turn(s), kept ${info.tailMessages ?? 0} tail msg`
|
|
82
120
|
// Cache line (batch 2026-10-18-context-cache-visibility): the provider reports
|
|
83
121
|
// prompt_cache_hit/miss per response; the core now tallies them so the question
|
|
84
122
|
// "is the prefix cache actually helping?" is answered by a reading, not a guess.
|
|
@@ -89,31 +127,35 @@ function statsReport(agent) {
|
|
|
89
127
|
const cacheLine = cacheTurns === 0
|
|
90
128
|
? "Cache: no provider usage readings yet (hit/miss arrive with the first response)"
|
|
91
129
|
: `Cache: hit ${cacheHit} · miss ${cacheMiss} tokens (${Math.round((cacheHit / cacheTotal) * 100)}% hit) across ${cacheTurns} response(s)`
|
|
92
|
-
// 第 6 行 =
|
|
93
|
-
//
|
|
94
|
-
|
|
130
|
+
// 第 6 行 = 核整量读数的投影(§7.1):与状态行同一个 `contextReading`——同屏两值同尺;
|
|
131
|
+
// 括号内的口径词按 `basis` 取(`measured` / `estimated`),`calibrated history estimate` 随之退场——
|
|
132
|
+
// 声称「状态行的投影」却报另一个量,就是一句不实的话。
|
|
133
|
+
const statusReading = contextReading(agent, agent?._ctxBasis?.overhead ?? {})
|
|
95
134
|
return [
|
|
96
|
-
`Context ≈${usage.total} tokens (${pct}% of ${usage.window}
|
|
97
|
-
// §6.16.4 字面单源(该行为唯一字面,逐字;预算面同源
|
|
135
|
+
`Context ≈${usage.total} tokens (${pct}% of ${budget.limit} fillable limit; window ${usage.window}, compaction line ${usage.threshold} (${toGo} to the line))`,
|
|
136
|
+
// §6.16.4 字面单源(该行为唯一字面,逐字;预算面同源 policyBudget——不自算第二套):
|
|
98
137
|
// window {window} ({modelContext|provider-override|list|spec|default}) · max_tokens {maxTokens|not sent} ({explicit|spec|absent})
|
|
99
138
|
// · prompt {total} · to compaction line {threshold − total} · to window limit {limit − total}
|
|
100
|
-
// 两距离带符号(负 = 已越);maxTokens 未发写 not sent、来源写 absent
|
|
139
|
+
// 两距离带符号(负 = 已越);maxTokens 未发写 not sent、来源写 absent。
|
|
101
140
|
(() => {
|
|
102
|
-
const budget = requestBudget(agent?.provider)
|
|
103
141
|
const mt = budget.maxTokens === undefined ? "not sent" : String(budget.maxTokens)
|
|
104
142
|
return `Request budget: window ${budget.window} (${budget.windowSource}) · max_tokens ${mt} (${budget.maxTokensSource})`
|
|
143
|
+
+ ` · input limit ${budget.limit} (window − reserve ${budget.reserve})`
|
|
105
144
|
+ ` · prompt ${usage.total} · to compaction line ${usage.threshold - usage.total}`
|
|
106
145
|
+ ` · to window limit ${budget.limit - usage.total}`
|
|
107
146
|
})(),
|
|
108
147
|
`Segments ≈: system ${usage.system} · tools ${usage.tools} · history ${usage.history} (basis: ${usage.basis})`,
|
|
109
148
|
`History: tool outputs ${toolOut} tokens in ${toolCount} msgs · prunable stale ${stale.tokens} tokens in ${stale.indexes.length} msgs · protected tail ${stale.tailCount} msgs`,
|
|
110
149
|
cacheLine,
|
|
111
|
-
`Status line: context ${statusReading.pct}% (${statusReading.tokens}
|
|
112
|
-
`Compaction so far: ${compaction} ·
|
|
150
|
+
`Status line: context ${statusReading.pct}% (${statusReading.tokens} ${statusReading.basis === "measured" ? "measured" : "estimated"} prompt tokens / ${statusReading.limit} fillable limit, compaction line ${statusReading.threshold})`,
|
|
151
|
+
`Compaction so far: ${compaction} · failed attempts ${agent?._compressFailures ?? 0}`,
|
|
113
152
|
].join("\n")
|
|
114
153
|
}
|
|
115
154
|
|
|
116
|
-
/** prune 回执(§6.16.3:计数 + 扫过候选 / 保护尾内保留 / 门槛下跳过 + 记录面零改)。
|
|
155
|
+
/** prune 回执(§6.16.3:计数 + 扫过候选 / 保护尾内保留 / 门槛下跳过 + 记录面零改)。
|
|
156
|
+
* 可回查面(`CONTEXT-COMPACTION.md` §7.2):只报释放量与跳过项、请模型需要时重跑工具,**不指向任何回查位置**——
|
|
157
|
+
* 落盘的只有人读线那一份、且长工具结果只留 slim 后的前段(射程见 `SESSION.md` §5),写「全文仍在盘上」是一句
|
|
158
|
+
* 兑现不了的话;内存里的全史随进程走,重启之后没有第二条通道。 */
|
|
117
159
|
function pruneReceipt(agent) {
|
|
118
160
|
const r = pruneStaleToolOutputs(agent)
|
|
119
161
|
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 +163,8 @@ function pruneReceipt(agent) {
|
|
|
121
163
|
return `Nothing to prune — no stale tool output matched ${scan}. The context and the session record are unchanged.`
|
|
122
164
|
}
|
|
123
165
|
return `Pruned ${r.pruned} stale tool output(s) ≈${r.freed} tokens freed ${scan}. ` +
|
|
124
|
-
`Tool pairing is intact and the session record is unchanged
|
|
166
|
+
`Tool pairing is intact and the session record is unchanged. The record keeps only the front segment of a long tool result, ` +
|
|
167
|
+
`so this text is not retrievable from it — re-run the tool if you need that output again.`
|
|
125
168
|
}
|
|
126
169
|
|
|
127
170
|
/**
|
|
@@ -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
|