@thincoder/core 0.10.13 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -1
- package/advisor/convergence.mjs +34 -3
- package/advisor/loop.mjs +42 -10
- package/advisor/messages.mjs +46 -27
- package/advisor/notice.mjs +1 -1
- package/advisor/project-context.mjs +253 -14
- package/advisor/run.mjs +7 -4
- package/advisor.mjs +29 -43
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/completion.mjs +57 -4
- package/agent/digest-account.mjs +73 -46
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +35 -22
- package/agent/family-tools.mjs +36 -17
- package/agent/helpers.mjs +123 -95
- package/agent/offload.mjs +84 -0
- package/agent/post-turn.mjs +24 -10
- package/agent/record-results.mjs +19 -7
- package/agent/run-stages.mjs +127 -61
- package/agent/run-start.mjs +45 -8
- package/agent/setup-reminders.mjs +9 -2
- package/agent/setup.mjs +27 -22
- package/agent/spawn-child.mjs +38 -1
- package/agent/suspension.mjs +1 -1
- package/agent/timers.mjs +5 -3
- package/agent/turn-loop.mjs +60 -6
- package/agent/turn-projection.mjs +386 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +168 -0
- package/agent/write-face.mjs +99 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +39 -13
- package/agent-tools/advisor-async.mjs +29 -169
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +136 -31
- package/agent-tools/async-settle.mjs +2 -2
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/bash-async.mjs +8 -2
- package/agent-tools/batch-closeout.mjs +444 -0
- package/agent-tools/batch-gate.mjs +152 -138
- package/agent-tools/batch-ledger-bind.mjs +392 -0
- package/agent-tools/batch-ledger-link.mjs +73 -0
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +245 -376
- package/agent-tools/batch-paths.mjs +73 -47
- package/agent-tools/batch-read.mjs +1 -1
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +154 -0
- package/agent-tools/batch-segment-vocab.mjs +379 -0
- package/agent-tools/batch-skeleton.mjs +344 -196
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +297 -0
- package/agent-tools/batch.mjs +189 -253
- package/agent-tools/consult.mjs +7 -4
- package/agent-tools/context.mjs +47 -17
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +24 -24
- package/agent-tools/design-token.mjs +318 -39
- package/agent-tools/doc-check.mjs +55 -29
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +10 -9
- package/agent-tools/escalate-async.mjs +5 -5
- package/agent-tools/manifest.mjs +34 -15
- package/agent-tools/read-history.mjs +115 -14
- package/agent-tools/review-facts.mjs +40 -15
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/spawn-gates.mjs +19 -22
- package/agent-tools/ssh-session.mjs +120 -111
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transfer.mjs +210 -0
- package/agent-tools/ssh-transport.mjs +183 -81
- package/agent-tools/subagent-actions-query.mjs +11 -7
- package/agent-tools/subagent-actions.mjs +1 -1
- package/agent-tools/subagent-async.mjs +11 -11
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +45 -11
- package/agent-tools/subagent-spawn.mjs +143 -104
- package/agent-tools/subagent.mjs +26 -23
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +20 -1
- package/attachments.mjs +3 -3
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +22 -6
- package/config-defaults.mjs +2 -1
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-presets.mjs +5 -3
- package/config-reload.mjs +59 -0
- package/config.mjs +62 -98
- package/context-degrade.mjs +38 -10
- package/context-echo.mjs +11 -0
- package/context.mjs +165 -68
- package/conventions.mjs +11 -9
- package/declaration.mjs +33 -7
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +312 -163
- package/doc-check/line-refs.mjs +38 -0
- package/doc-check/paragraph.mjs +220 -91
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/explore-distill.mjs +12 -6
- package/i18n.mjs +2 -2
- package/index-discover.mjs +4 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +6 -0
- package/ledger-close-proof.mjs +95 -62
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +76 -244
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +70 -37
- package/ledger-executors.mjs +1 -1
- package/ledger-migrate.mjs +4 -4
- package/ledger-read.mjs +10 -8
- package/ledger-surface.mjs +1 -1
- package/ledger-tools.mjs +83 -24
- package/ledger-variant-notice.mjs +1 -1
- package/ledger-write-ops.mjs +462 -0
- package/ledger.mjs +2 -2
- package/manifest-discovery.mjs +5 -3
- package/manifest-schema.mjs +28 -2
- package/memory/memory-tool.mjs +5 -2
- package/memory/schema.mjs +6 -27
- package/package.json +3 -1
- package/path-resolve.mjs +498 -0
- package/permission.mjs +4 -0
- package/prompt-files.mjs +91 -1
- package/prompt-overlays.mjs +14 -6
- package/prompts/advisor-design.md +66 -22
- package/prompts/advisor-round1.md +37 -3
- package/prompts/advisor-round2.md +44 -10
- package/prompts/advisor-round3.md +43 -9
- package/prompts/common.md +15 -375
- package/prompts/consult-base.md +6 -1
- package/prompts/discipline-engineering.md +251 -95
- package/prompts/discipline-normal.md +4 -250
- package/prompts/knowledge/business-gates.md +22 -0
- package/prompts/knowledge/decision-quality.md +23 -0
- package/prompts/knowledge/doc-lookup.md +35 -0
- package/prompts/knowledge/document-writing.md +51 -0
- package/prompts/knowledge/documentation-evaluation.md +56 -0
- package/prompts/knowledge/evidence-discipline.md +57 -0
- package/prompts/knowledge/normal-coding-workflow.md +104 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +108 -0
- package/prompts/knowledge/normal-work-management.md +57 -0
- package/prompts/knowledge/product-security.md +23 -0
- package/prompts/knowledge/project-records.md +62 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +18 -0
- package/prompts/knowledge/tool-bash.md +39 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +12 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +12 -0
- package/prompts/knowledge/tool-batch-review.md +12 -0
- package/prompts/knowledge/tool-batch.md +80 -0
- package/prompts/knowledge/tool-browser.md +57 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +17 -0
- package/prompts/knowledge/tool-doc-check.md +70 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +38 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +16 -0
- package/prompts/knowledge/tool-fetch.md +12 -0
- package/prompts/knowledge/tool-file-ops.md +16 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +19 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +15 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +18 -0
- package/prompts/knowledge/tool-hashline-edit.md +14 -0
- package/prompts/knowledge/tool-insert-after.md +15 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +35 -0
- package/prompts/knowledge/tool-ledger.md +42 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +13 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +31 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +15 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +114 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +6 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +36 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +21 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +18 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +52 -0
- package/prompts/knowledge/tool-subagent.md +59 -0
- package/prompts/knowledge/tool-task.md +12 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +11 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +14 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +9 -0
- package/prompts/knowledge/upstream-protocol.md +43 -0
- package/prompts/persona-eng-coder.md +29 -3
- package/prompts/persona-eng-designer.md +131 -159
- package/prompts/persona-engineering.md +202 -131
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-plan.md +6 -1
- package/prompts/persona-tester.md +55 -0
- package/prompts/subagent-base.md +2 -0
- package/provider/anthropic.mjs +6 -4
- package/provider/core.mjs +5 -4
- package/provider/errors.mjs +29 -4
- package/provider/google.mjs +39 -12
- package/provider/rate.mjs +11 -3
- package/provider/responses.mjs +3 -1
- package/provider/sse.mjs +15 -4
- package/provider-flows.mjs +2 -2
- package/session-identity.mjs +21 -0
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +79 -19
- package/session-slot-write.mjs +37 -5
- package/session-slots.mjs +9 -14
- package/session.mjs +29 -8
- package/skip-dirs.mjs +48 -0
- package/team-ledger.mjs +17 -13
- package/text-budget.mjs +4 -0
- package/token-ttl.mjs +73 -4
- package/token-window.mjs +244 -34
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -13
- package/tool-docs/bash.md +2 -37
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +3 -1
- package/tool-docs/browser.md +2 -47
- package/tool-docs/code_search.md +3 -1
- package/tool-docs/consult_start.md +2 -4
- package/tool-docs/consult_stop.md +2 -2
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -14
- package/tool-docs/doc_check.md +2 -72
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +3 -1
- package/tool-docs/edit.md +2 -18
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -12
- package/tool-docs/fetch.md +2 -12
- package/tool-docs/file_ops.md +2 -16
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -27
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +2 -5
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -13
- package/tool-docs/insert_after.md +2 -14
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -9
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -7
- package/tool-docs/manifest.md +2 -28
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +3 -11
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +2 -4
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -6
- package/tool-docs/read_image.md +2 -7
- package/tool-docs/recent_changes.md +3 -1
- package/tool-docs/repo_outline.md +3 -1
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +2 -5
- package/tool-docs/skill.md +3 -5
- package/tool-docs/ssh.md +2 -50
- package/tool-docs/subagent.md +2 -63
- package/tool-docs/task.md +2 -6
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +3 -13
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +3 -1
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -17
- package/tool-docs/write.md +2 -10
- package/tools/bash.mjs +12 -2
- package/tools/browser.mjs +52 -7
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +176 -91
- package/tools/edit-diff.mjs +129 -45
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +11 -5
- package/tools/file.mjs +32 -34
- package/tools/git.mjs +43 -2
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +4 -1
- package/tools/patch.mjs +127 -38
- package/tools/process-doc-mark.mjs +139 -0
- package/tools/search.mjs +15 -6
- package/tools/shared.mjs +31 -7
- package/tools/ssh.mjs +48 -7
- package/tools/tree.mjs +4 -1
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +79 -6
- package/traces/trace-store.mjs +4 -3
- package/window-policy.mjs +203 -0
- package/agent/light-round.mjs +0 -63
- package/agent/unbooked-pen.mjs +0 -62
- package/doc-check/anchors.mjs +0 -135
package/agent/write-gate.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* agent/write-gate.mjs — M4 写权门禁(评审目标解析 + D5
|
|
2
|
+
* agent/write-gate.mjs — M4 写权门禁(评审目标解析 + D5 冻结窗口判据组装 + 写锁)。
|
|
3
3
|
*
|
|
4
4
|
* v2 唯一增量(模块设计 §2.1):评审对象 / 被审文件路径来源改读 manifest `docRoot`
|
|
5
5
|
* (去硬编码 `docs/`),token 门(`anyLiveDesignSlot`)与冻结窗口谓词本体继承 v1 零改
|
|
6
|
-
* (KD-M4-3
|
|
6
|
+
* (KD-M4-3)——本档承载四个单点:
|
|
7
7
|
*
|
|
8
8
|
* 1. `resolveReviewTargetPaths(agent)` —— 评审目标解析单点:读 manifest `docRoot`
|
|
9
9
|
* 产出评审对象 / 被审文件的绝对路径集合(目录级;子键值形态 = 串 | 多根数组)。
|
|
@@ -25,17 +25,48 @@
|
|
|
25
25
|
* `AGENT-LOOP-SUBAGENT.md` §6.29.1):判据与拒绝文案同址(文案字面只出本档)。
|
|
26
26
|
* 2026-09-29 收窄(台账 #545):自身批次伴随件(非 `.md` · 同目录 · 词干族 = 三合取)放行——
|
|
27
27
|
* 批次档本体 ∕ 他批伴随件 ∕ 异目录伴随件照拒;两端取用 = 核 `agent/dispatch.mjs` Phase 1(两端同径)。
|
|
28
|
+
* 4. `ledgerBindWriteConflict(agent, depth, tool, toolName, args)` —— 写锁(第三道门 · 设计档 §2.3):
|
|
29
|
+
* 判据 = 「**本笔报的** `#N` 是目标所属项目台账里一条 `status = 在途` 的行」(笔-账绑定——用户
|
|
30
|
+
* 2026-11-03 02:02 裁「甲 · 逐笔带号」)。**实现面住 `agent/write-gate-ledger.mjs`**(2026-11-05
|
|
31
|
+
* 拆档族整段外移:判据体 `ledgerRowAt` 仍不导出、拒文组装与项目根取法同上)——本档 import 回来
|
|
32
|
+
* 原样 re-export,`dispatch.mjs` 挂点零改;判据与理由的说法见该档档头。
|
|
33
|
+
* 2026-11-03 不分面批:文档面 / 项目状态档 / 产品面 / 产品测面读同一条判据;面在判据里退场。
|
|
34
|
+
* 2026-11-03 笔-账绑定批:入口集扩到十二把(写盘七件 + `bash` ∥ `execute` + `manifest` ∥ `memory` + `git`),
|
|
35
|
+
* 拒文成为唯一教学面(`ledger` 不进 `required`)。
|
|
36
|
+
* 2026-11-03 项目声明面批:**判据点从会话锚换成调用方声明的项目**(决策 40 ∥ 41)——定位参数优先,
|
|
37
|
+
* `project` 补位;会话锚不作判据点,**只作定界**(`no project on this call` ∥ `declared project is not a project`)。
|
|
38
|
+
* (定界不是新的:声明相关性那一支一直靠它;2026-11-08 窄口批把定界面从「声明」扩到「目标」——
|
|
39
|
+
* 此前没有任何一句问过「写盘目标在不在这一层工作区」。)
|
|
40
|
+
* 2026-11-04 ssh 传输面批:入口集扩到十三把(+ `ssh`——只有 `get` 往本地落盘,按 action 判要号:
|
|
41
|
+
* `connect` / `send` / `read` / `list` 不写项目内档,不得被本门问到)。
|
|
42
|
+
* 2026-11-05 `git` 免号批:`git` **整把退出入口集**(十三把 ⇒ 十二把)——提交不落新字节,它记录的
|
|
43
|
+
* 是已被本门缴过账的内容;同一件活被收两次费,而给提交加门等于让人少提交(把兜底做成了阻力)。
|
|
44
|
+
* 判据与理由全文 = 设计档 §2.3「`git` 不进写门」(决策 37 改判)。
|
|
45
|
+
* 2026-11-08 工作区根窄口批(设计档 §2.3.1):写盘七件的目标沿祖先链取不到项目根时,四条同时成立
|
|
46
|
+
* (目标在会话锚子树内 ∧ 锚下有带 manifest 的直接子目录 ∧ 本笔显式声明 `project` ∧ 声明解析得出根)
|
|
47
|
+
* ⇒ 判据点换成声明根、号照原样判。**多一格不是放宽**:无声明 ∥ 目标在锚外 ∥ 锚下无子项目 各落自己那句拒,
|
|
48
|
+
* 锚外照拒;`bash` ∥ `execute` ∥ `memory` 的声明支零改(它们本就没有目标路径这个定位参数,
|
|
49
|
+
* 窄口对它们无意义)。
|
|
50
|
+
* 2026-11-10 `manifest` 出集批:`manifest` **整把退出入口集**(十二把 ⇒ 十一把)——本门的判据要读它
|
|
51
|
+
* (取根 ∥ `index.writableRepos`),把写这份档放在门后就成环:档缺失建不出项目、档坏修不回来。
|
|
52
|
+
* `init` 原那条「取根豁免」随之退场。判据与理由全文 = 设计档 §2.3「`manifest` 不进写门」(决策 44)。
|
|
28
53
|
*
|
|
29
54
|
* 继承零改面(本档不碰):token 门资格判据(anyLiveDesignSlot / validateDesignToken)、
|
|
30
55
|
* 代码路径判定(conventions.mjs 单一权威分类——KD-M4-1 保留为代码路径判定用)。
|
|
31
56
|
*/
|
|
32
|
-
import { basename, dirname
|
|
57
|
+
import { basename, dirname } from "node:path"
|
|
33
58
|
// advisor-settle 无上游依赖本簇(dispatch → write-gate → advisor-settle 单向)。normAbs
|
|
34
59
|
// 权威本体 = review-facts.mjs(第 33 批迁入),advisor-settle re-export;本档再 re-export
|
|
35
60
|
// (指针链非副本),M6 经本档一行 import 取齐。
|
|
36
61
|
import { inflightDesignReviewConflict, normAbs } from "../agent-tools/advisor-settle.mjs"
|
|
37
62
|
// 批次档路径单源(叶档——`BATCH-RECORD.md` §4.15):批次档写门基底集取 `batchDocBases`。
|
|
38
63
|
import { batchDocBases } from "../agent-tools/batch-paths.mjs"
|
|
64
|
+
// 写锁(第三道门)实现面:2026-11-05 拆档族整段搬进 `agent/write-gate-ledger.mjs`(判据体 ∥ 拒文组装 ∥
|
|
65
|
+
// 项目根取法 ∥ 入口集枚举)。本档 import 回来原样 re-export——`ledgerBindWriteConflict` 的名字、参数表、
|
|
66
|
+
// 返回值、拒文逐字不变,`dispatch.mjs` 挂点零改;`gateKey` 是两档共用的比较键坐标系(本档 `underBase` /
|
|
67
|
+
// `batchRecordWriteConflict` 反向取它),单向依赖 `ledger ← 本档`。
|
|
68
|
+
import { gateKey, ledgerBindWriteConflict } from "./write-gate-ledger.mjs"
|
|
69
|
+
export { ledgerBindWriteConflict }
|
|
39
70
|
export { normAbs }
|
|
40
71
|
// 2026-10-04(工具路径基面根治批 · #921 · KD-2 同名再出口):REVIEW_ROOT_KEYS +
|
|
41
72
|
// resolveReviewRootsFor 判定本体迁 `review-facts.mjs`(评审事实面——advisor-async 既有
|
|
@@ -56,7 +87,7 @@ import { resolveReviewRootsFor } from "../agent-tools/review-facts.mjs"
|
|
|
56
87
|
* @returns {string[]} 评审目标目录的绝对路径(去重)
|
|
57
88
|
*/
|
|
58
89
|
export function resolveReviewTargetPaths(agent) {
|
|
59
|
-
return resolveReviewRootsFor(agent?.cwd
|
|
90
|
+
return resolveReviewRootsFor(agent?.cwd)
|
|
60
91
|
}
|
|
61
92
|
|
|
62
93
|
/**
|
|
@@ -82,7 +113,9 @@ export function freezeWindowConflict(agent, absPaths) {
|
|
|
82
113
|
for (const entry of pool.values()) {
|
|
83
114
|
if (!entry || entry.reviewType !== "design") continue
|
|
84
115
|
if (entry.status !== "running" || entry.cancelled || entry.done) continue
|
|
85
|
-
|
|
116
|
+
// 逐笔绑定快照(发起时点):同实例的后一笔发起会覆盖 `run.batchDoc`,冻结窗要护的是
|
|
117
|
+
// **本条目被指派的那本档**(判据单源 = `docs/core/design/BATCH-LEDGER-REVIEW-UNIFY.md` §2.15)。
|
|
118
|
+
const batchDoc = entry.batchDoc ?? entry.run?.batchDoc
|
|
86
119
|
if (typeof batchDoc !== "string" || batchDoc.length === 0) continue
|
|
87
120
|
const batchAbs = normAbs(batchDoc, agent?.cwd)
|
|
88
121
|
if (wantedSet.has(batchAbs)) return { id: String(entry.id), path: batchAbs }
|
|
@@ -95,12 +128,6 @@ export function freezeWindowConflict(agent, absPaths) {
|
|
|
95
128
|
* **歧义锚**(多项目并存 · #828)⇒ 基底 = 候选项目基底**并集**(`batchDocBases` 解析单点——覆盖随之对齐)。 */
|
|
96
129
|
const batchGateBasesMemo = new WeakMap()
|
|
97
130
|
|
|
98
|
-
/** 比较键(绝对形态归一:`.` 段归位 + 分隔符归一 `/` + win32 大小写归一——§6.29.1 判据)。 */
|
|
99
|
-
const gateKey = (p) => {
|
|
100
|
-
const s = resolve(String(p)).replace(/\\/g, "/")
|
|
101
|
-
return process.platform === "win32" ? s.toLowerCase() : s
|
|
102
|
-
}
|
|
103
|
-
|
|
104
131
|
function memoizedBatchBases(agent, cwd) {
|
|
105
132
|
const memo = agent && typeof agent === "object" ? batchGateBasesMemo.get(agent) : null
|
|
106
133
|
if (memo && memo.cwd === cwd) return memo.bases
|
|
@@ -151,7 +178,7 @@ export function batchRecordWriteConflict(agent, depth, absPaths) {
|
|
|
151
178
|
if (typeof bound !== "string" || bound.length === 0) return null
|
|
152
179
|
const wanted = (absPaths ?? []).filter((p) => typeof p === "string" && p.length > 0)
|
|
153
180
|
if (wanted.length === 0) return null
|
|
154
|
-
const cwd =
|
|
181
|
+
const cwd = agent.cwd
|
|
155
182
|
const bases = memoizedBatchBases(agent, cwd)
|
|
156
183
|
const boundAbs = normAbs(bound, cwd)
|
|
157
184
|
const boundKey = gateKey(boundAbs)
|
|
@@ -169,4 +196,3 @@ export function batchRecordWriteConflict(agent, depth, absPaths) {
|
|
|
169
196
|
}
|
|
170
197
|
return null
|
|
171
198
|
}
|
|
172
|
-
|
|
@@ -7,17 +7,14 @@
|
|
|
7
7
|
* delivers the report (AGENT-LOOP-ASYNC-POOL.md §6.8 consumption machinery — role-agnostic; entries carry
|
|
8
8
|
* role "advisor" and ride the subagent panel as a pseudo-role, ruling ②-4 A).
|
|
9
9
|
*
|
|
10
|
-
* This module owns
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* a fix loop) and CLOSE at normal user-run ends once no review is in flight
|
|
19
|
-
* (a converged/abandoned thread must not burn the cap of later tasks);
|
|
20
|
-
* 3. the async pool (agent._asyncAdvisors — ADVISOR_POOL_LIMIT = 4 default,
|
|
10
|
+
* This module owns the WRITE half — launch ∥ queue ∥ cancel ∥ close. The READ half
|
|
11
|
+
* (which instance a launch continues, and whether the pool admits a start: the
|
|
12
|
+
* per-review INSTANCE registry agent._advisorRuns + launch resolution + pool limits
|
|
13
|
+
* + the same-scope guard) lives in `advisor-launch.mjs`, split out 2026-11-12 when
|
|
14
|
+
* this file crossed the 500-line design line; its exports are re-exported below, so
|
|
15
|
+
* the existing import face is unchanged.
|
|
16
|
+
*
|
|
17
|
+
* 1. the async pool (agent._asyncAdvisors — ADVISOR_POOL_LIMIT = 4 default,
|
|
21
18
|
* agent.poolLimits.advisor configurable — POOL-CONFIG-UNIFIED; same-scope
|
|
22
19
|
* running launches are refused at once — never queued (F-5); over-limit +
|
|
23
20
|
* DIFFERENT scope launches QUEUE (ED-4 2026-09-16 — AGENT-LOOP-ASYNC-POOL.md §6.10:
|
|
@@ -25,7 +22,7 @@
|
|
|
25
22
|
* queued cancel dequeue+renumber — the former over-limit refusal ②-6a is
|
|
26
23
|
* retired); cancel (ruling ②-6b — directed abort → cancelled settle: no
|
|
27
24
|
* pending entry, no token, a "评审已取消——token 未签发" reminder);
|
|
28
|
-
*
|
|
25
|
+
* 2. SETTLE accounting (fixes #2/#4 — moved from the tool-result commit): a
|
|
29
26
|
* review whose targets mutated after launch settles STALE — it marks no
|
|
30
27
|
* _calledAdvisorThisRun and issues no token (the guard pushes back); a
|
|
31
28
|
* non-stale code review marks _calledAdvisorThisRun; a passing design review
|
|
@@ -37,7 +34,15 @@
|
|
|
37
34
|
* the same instance resolution (rounds/prior/cap) — its accounting still lands
|
|
38
35
|
* in recordToolResults (agent.mjs run loop), marker-keyed by toolCall id.
|
|
39
36
|
*/
|
|
40
|
-
|
|
37
|
+
// 实例与池判定一族(只读:哪条实例接这一轮、池让不让起)2026-11-12 迁 advisor-launch.mjs——
|
|
38
|
+
// 本档过 500 设计器硬线,分拆方案 = `docs/core/design/DESIGN-TOKEN-SETTLEMENT.md` §10(本批内实施)。
|
|
39
|
+
// 既有 import 面(completion.mjs ∥ advisor.mjs ∥ design-slots.mjs ∥ record-results.mjs ∥ 测试)
|
|
40
|
+
// 经此 re-export 不变。
|
|
41
|
+
import { advisorRunsRead, advisorPoolLimitFor, runningAdvisorOfScope, runningAdvisorCount } from "./advisor-launch.mjs"
|
|
42
|
+
export {
|
|
43
|
+
ADVISOR_POOL_LIMIT, advisorRuns, advisorReviewPending, advisorPoolLimitFor, effectiveAdvisorRound,
|
|
44
|
+
openCodeRun, resolveAdvisorLaunch, resolveAdvisorPoolLimit, runningAdvisorCount, runningAdvisorOfScope,
|
|
45
|
+
} from "./advisor-launch.mjs"
|
|
41
46
|
// design-token 工具组(2026-09-08 自本文件迁至 design-token.mjs——再越 500 行硬限)——
|
|
42
47
|
// 既有 import 面(advisor.mjs / 测试)不变:原导出全部经此 re-export 保留。
|
|
43
48
|
export {
|
|
@@ -52,8 +57,8 @@ export {
|
|
|
52
57
|
mutationSeqOf, noteMutations, reviewIsStale, settleAdvisorRun, inflightDesignReviewConflict,
|
|
53
58
|
} from "./advisor-settle.mjs"
|
|
54
59
|
// 第 33 批(评审失败护栏):doc-set 键迁事实面档(实例续跑与陈旧判定同锚单源;原为私有——零 import 面)。
|
|
55
|
-
//
|
|
56
|
-
import {
|
|
60
|
+
// 实例解析随 2026-11-12 拆分迁 advisor-launch.mjs;本文件只剩池 entries 的 docAbs 产出面消费它。
|
|
61
|
+
import { resolveReviewDocPaths, scopeAdvisorMirror } from "./review-facts.mjs"
|
|
57
62
|
// F31(2026-09-18 顾问面治理批):拒回文案对象标识行单源。
|
|
58
63
|
import { withIdentityLine, scopeSummary } from "../advisor/notice.mjs"
|
|
59
64
|
import { runAdvisorReview, resolveAdvisorProvider, ADVISOR_THINKING_PLACEHOLDER } from "../advisor/run.mjs"
|
|
@@ -68,159 +73,6 @@ import { nextSubagentId, consumeSubagentToken, assertPoolKeyFree, entryTerminal
|
|
|
68
73
|
// #934(零落笔看门狗——AGENT-LOOP-UPSTREAM.md §6.32.6 触发接线②):评审族推送单源(叶档——恒零抛)。
|
|
69
74
|
import { pushAdvisorAlert } from "./zero-write-watch.mjs"
|
|
70
75
|
|
|
71
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
72
|
-
// Review-instance registry (_advisorRuns — per-review rounds/prior/cap)
|
|
73
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
74
|
-
|
|
75
|
-
/** 载体吸收后的只读读取(不创建):父对象字段优先、缺字段回退跨 run 载体
|
|
76
|
-
* (`history` 数组——agent 逐 run 重建的形态靠它跨 run 存活)。无 ⇒ null。 */
|
|
77
|
-
function advisorRunsRead(agent) {
|
|
78
|
-
const m = carrierField(agent, "_advisorRuns")
|
|
79
|
-
return m instanceof Map ? m : null
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function advisorRuns(agent) {
|
|
83
|
-
// 实例注册表读取吸收(与 #94 载体口径同源):既有形态(字段挂 agent)零变;
|
|
84
|
-
// 注册表已挂跨 run 载体的形态直接沿用(不另建分叉)。
|
|
85
|
-
const existing = advisorRunsRead(agent)
|
|
86
|
-
if (existing) return existing
|
|
87
|
-
// 缺省创建:落在跨 run 载体上(有 history 时)——与其余载体字段同口径。
|
|
88
|
-
const holder = agent?.history ?? agent
|
|
89
|
-
if (!holder) return new Map()
|
|
90
|
-
if (!(holder._advisorRuns instanceof Map)) holder._advisorRuns = new Map()
|
|
91
|
-
return holder._advisorRuns
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** The newest OPEN code instance (the thread a fix-round launch continues), or null. */
|
|
95
|
-
export function openCodeRun(agent) {
|
|
96
|
-
const runs = advisorRunsRead(agent)
|
|
97
|
-
if (!(runs instanceof Map) || runs.size === 0) return null
|
|
98
|
-
for (const r of [...runs.values()].reverse()) {
|
|
99
|
-
if (r.reviewType === "code" && r.open) return r
|
|
100
|
-
}
|
|
101
|
-
return null
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** The newest OPEN design instance for the given document set, or null. */
|
|
105
|
-
function openDesignRun(agent, key) {
|
|
106
|
-
const runs = advisorRunsRead(agent)
|
|
107
|
-
if (!(runs instanceof Map) || runs.size === 0) return null
|
|
108
|
-
for (const r of [...runs.values()].reverse()) {
|
|
109
|
-
if (r.reviewType === "design" && r.open && r.docSetKey === key) return r
|
|
110
|
-
}
|
|
111
|
-
return null
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Resolve the review instance a launch continues (AGENT-LOOP-ASYNC-POOL.md §6.10 ③ — per-review
|
|
116
|
-
* rounds/prior; reviewId = designId for design reviews, a random id for code).
|
|
117
|
-
* - design: continue the OPEN instance of the same document set (fix rounds of
|
|
118
|
-
* a review thread keep its designId and its round/prior); none → new instance.
|
|
119
|
-
* - code: continue the newest OPEN code instance (guard-driven fix loops);
|
|
120
|
-
* none → new instance.
|
|
121
|
-
* The legacy agent._advisorRound/_lastAdvisorOutput fields are SCOPED to the
|
|
122
|
-
* instance before the launch (message building + the run.mjs cap read them) —
|
|
123
|
-
* prior-less continuation degrades to round 1 semantics (fresh full review).
|
|
124
|
-
* @returns {{run: object, isNew: boolean, reviewId: string, designId: string|null}}
|
|
125
|
-
*/
|
|
126
|
-
export function resolveAdvisorLaunch(agent, reviewType, { documents = null } = {}) {
|
|
127
|
-
const runs = advisorRuns(agent)
|
|
128
|
-
let run = null
|
|
129
|
-
if (reviewType === "design") {
|
|
130
|
-
const key = docSetKey(documents, agent.cwd)
|
|
131
|
-
run = openDesignRun(agent, key)
|
|
132
|
-
if (!run) {
|
|
133
|
-
const reviewId = randomUUID()
|
|
134
|
-
// F2h (§29.1 2026-09-07): a same-scope re-review reuses the session's
|
|
135
|
-
// designId for this doc-set (any prior instance of the scope — open OR
|
|
136
|
-
// closed — the newest wins). A passed re-review overwrites the slot under
|
|
137
|
-
// the same id (no slot residue — T14: the old token is then rejected at
|
|
138
|
-
// the gate); old slots die at TTL only, kept as the fail-safe fallback.
|
|
139
|
-
const prior = [...runs.values()].reverse().find((r) => r.reviewType === "design" && r.docSetKey === key)
|
|
140
|
-
// #863 实例回收(§6.10):同 docSetKey 保最新一条 closed(= prior——F2h 只取 newest,语义零变);
|
|
141
|
-
// 余者去重回收(实例随删释放——closed 零消费面)。
|
|
142
|
-
for (const r of [...runs.values()]) {
|
|
143
|
-
if (r !== prior && r.reviewType === "design" && !r.open && r.docSetKey === key) runs.delete(r.reviewId)
|
|
144
|
-
}
|
|
145
|
-
run = {
|
|
146
|
-
reviewId, reviewType, designId: prior?.designId ?? reviewId,
|
|
147
|
-
round: 0, priorOutput: null, stale: false, open: true, docSetKey: key,
|
|
148
|
-
}
|
|
149
|
-
runs.set(reviewId, run)
|
|
150
|
-
}
|
|
151
|
-
} else {
|
|
152
|
-
run = openCodeRun(agent)
|
|
153
|
-
if (!run) {
|
|
154
|
-
// #863 实例回收(§6.10):新 code 实例创建 ⇒ closed 实例清除(openCodeRun 仅取 open——零消费)。
|
|
155
|
-
for (const r of [...runs.values()]) {
|
|
156
|
-
if (r.reviewType === "code" && !r.open) runs.delete(r.reviewId)
|
|
157
|
-
}
|
|
158
|
-
const reviewId = randomUUID()
|
|
159
|
-
run = {
|
|
160
|
-
reviewId, reviewType, designId: null,
|
|
161
|
-
round: 0, priorOutput: null, stale: false, open: true, docSetKey: null,
|
|
162
|
-
}
|
|
163
|
-
runs.set(reviewId, run)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
// Scope the mirror fields to THIS instance (message builder + run.mjs cap +
|
|
167
|
-
// displays; #949 ① — the queued-launch window is re-secured at entry.start).
|
|
168
|
-
scopeAdvisorMirror(agent, run)
|
|
169
|
-
return { run, isNew: run.round === 0 && !run.priorOutput, reviewId: run.reviewId, designId: run.designId }
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/** Guard round — the OPEN CODE instance only (2026-09-07 §8 F2): the design-written
|
|
173
|
-
* mirror never gates the code guard — no open code instance → 0. */
|
|
174
|
-
export function effectiveAdvisorRound(agent) {
|
|
175
|
-
return openCodeRun(agent)?.round ?? 0
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
179
|
-
// Async pool (agent._asyncAdvisors — pool 上限 F-1/F-2:常量 = 运行时回退权威(2 → 4),
|
|
180
|
-
// config.mjs DEFAULTS.agent.poolLimits.advisor = config 层镜像——耦合锁 config-pool
|
|
181
|
-
// .test.mjs 逐键断言——勿单侧改默认)
|
|
182
|
-
// ─────────────────────────────────────────────────────────────────────────────
|
|
183
|
-
|
|
184
|
-
export const ADVISOR_POOL_LIMIT = 4
|
|
185
|
-
|
|
186
|
-
/** AGENT-LOOP-ASYNC-POOL.md §6.10 advisor 池生效上限(纯——读 agent.poolLimits.advisor——合法 ≥1 整数生效——
|
|
187
|
-
* 非法/缺省回退 ADVISOR_POOL_LIMIT——与 subagent 域 resolvePoolLimits 独立不共享
|
|
188
|
-
* (subagent 两键表不含本键——键表语义不同——POOL-CONFIG-UNIFIED F-2))。 */
|
|
189
|
-
export function resolveAdvisorPoolLimit(raw) {
|
|
190
|
-
const v = raw?.advisor
|
|
191
|
-
return Number.isInteger(v) && v >= 1 ? v : ADVISOR_POOL_LIMIT
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/** launch 判定点每次读 agent.config(/config 热应用——变更即生效下个 launch——文案
|
|
195
|
-
* 如实报本值)。 */
|
|
196
|
-
export function advisorPoolLimitFor(agent) {
|
|
197
|
-
return resolveAdvisorPoolLimit(agent?.config?.agent?.poolLimits)
|
|
198
|
-
}
|
|
199
|
-
/** §6.10 同 scope 守卫(F-5——用户裁①):同 reviewType+scope 有 running 评审 → true
|
|
200
|
-
* (拒——running 并行多实例歧义放大——settled 续跑语义不变)。design scope = 文档集键
|
|
201
|
-
* (docSetKey);code = 单 code 线程(记录不记路径键——与 openCodeRun 语义一致)。
|
|
202
|
-
* 与池容量守卫独立:容量 = 全局 ≤N——scope = 同 scope ≤1——两关都过才启动。 */
|
|
203
|
-
export function runningAdvisorOfScope(agent, reviewType, docSetKey) {
|
|
204
|
-
const pool = getAsyncPool(agent, "advisor")
|
|
205
|
-
if (!(pool instanceof Map)) return false
|
|
206
|
-
for (const e of pool.values()) {
|
|
207
|
-
if (e.status !== "running" || e.reviewType !== reviewType) continue
|
|
208
|
-
if (reviewType === "design" && e.run?.docSetKey !== docSetKey) continue
|
|
209
|
-
return true
|
|
210
|
-
}
|
|
211
|
-
return false
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
export function runningAdvisorCount(agent) {
|
|
215
|
-
return [...(getAsyncPool(agent, "advisor")?.values() ?? [])].filter((e) => e.status === "running").length
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/** Any in-flight (non-done) async advisor review? — the completion guard skips
|
|
219
|
-
* its push-back while a review is pending (T-24b4: 未决不算未评审). */
|
|
220
|
-
export function advisorReviewPending(agent) {
|
|
221
|
-
return [...(getAsyncPool(agent, "advisor")?.values() ?? [])].some((e) => !e.done)
|
|
222
|
-
}
|
|
223
|
-
|
|
224
76
|
/** Directed cancel (ruling ②-6b — ⏹/cancel): abort the running review's
|
|
225
77
|
* controller (run.mjs signal chain) → the settle callback runs the cancelled
|
|
226
78
|
* branch (no pending entry / no token / "评审已取消——token 未签发" reminder).
|
|
@@ -367,7 +219,7 @@ export function refillAdvisorQueue(parent, onToken) {
|
|
|
367
219
|
* or invalid ctx.
|
|
368
220
|
*/
|
|
369
221
|
export function launchAsyncAdvisor(parent, ctx, launch) {
|
|
370
|
-
const { reviewType, documents, paths, object, designToken, designId, run } = launch
|
|
222
|
+
const { reviewType, documents, paths, object, designToken, designId, run, batchDoc = null } = launch
|
|
371
223
|
const limit = advisorPoolLimitFor(parent)
|
|
372
224
|
// §6.10 same-scope guard(F-5——用户裁①):同 type+scope 有 running → 拒——与池容量
|
|
373
225
|
// 守卫独立两关都过才启动——同 scope 不等不排(settled 续跑不变;排队仅异 scope 面)。
|
|
@@ -391,6 +243,10 @@ export function launchAsyncAdvisor(parent, ctx, launch) {
|
|
|
391
243
|
const entry = {
|
|
392
244
|
id, role: "advisor", reviewType, run,
|
|
393
245
|
reviewId: run.reviewId, designId, designToken, documents, paths, object,
|
|
246
|
+
// 批次档绑定 = 逐笔快照(发起时点的值,与 reviewId / designToken 同族):排队条目若在启动时读活的
|
|
247
|
+
// `run.batchDoc`,读到的是后一笔发起覆盖后的值 ⇒ 评审把裁定写进别人的档(判据单源 =
|
|
248
|
+
// `docs/core/design/BATCH-LEDGER-REVIEW-UNIFY.md` §2.15)。
|
|
249
|
+
batchDoc,
|
|
394
250
|
launchSeq: mutationSeqOf(parent),
|
|
395
251
|
// docAbs 产出面同源归一(2026-10-04 · #921 · A 随件):四分支单源 resolved(裸形/前缀形
|
|
396
252
|
// 命中候选项目根即归一为绝对路径)——冻结窗/陈旧判定对**裸形受理档**照护成立(否则 A
|
|
@@ -431,6 +287,10 @@ export function launchAsyncAdvisor(parent, ctx, launch) {
|
|
|
431
287
|
onOutput: (chunk) => relayAdvisorOutput(ctx?.callbacks, entry.relayPrefix, chunk),
|
|
432
288
|
signal: entry.controller.signal,
|
|
433
289
|
onStall: (rounds) => pushAdvisorAlert(parent, `advisor#${id}`, rounds), // #934:连续无产出越阈 ⇒ 自动上行提醒(只推——§6.32)
|
|
290
|
+
// 本笔发起时点的绑定快照(入口条目字段),与评审轨无关(判据单源 =
|
|
291
|
+
// `docs/core/design/BATCH-LEDGER-REVIEW-UNIFY.md` §2.15)。不读活的 `run.batchDoc`:
|
|
292
|
+
// 排队条目启动时那个字段已被后一笔发起覆盖。
|
|
293
|
+
batchDoc: entry.batchDoc,
|
|
434
294
|
}, designToken, documents, paths, object, designId)
|
|
435
295
|
.then((report) => { entry.report = report })
|
|
436
296
|
// §6.12 第 3 条合成器(第 24 批):原 message 前缀逐字保留 + 来源后缀
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* advisor-launch.mjs — 实例与池判定一族:哪条评审实例接这一轮、池让不让起。
|
|
3
|
+
*
|
|
4
|
+
* 2026-11-12 自 advisor-async.mjs 拆出(分拆方案 = `docs/core/design/DESIGN-TOKEN-SETTLEMENT.md`
|
|
5
|
+
* §10「分拆方案(`advisor-async.mjs`,本批内实施)」——该档过 500 设计器硬线,规则要求本批内拆完)。
|
|
6
|
+
* 切点 = 原档「Review-instance registry」分节起、`cancelAsyncAdvisor` 之前整段。
|
|
7
|
+
* 本档对**池与队列**只读(不碰队列、不碰控制器、不写池);实例注册表按既有语义懒建与回收,故
|
|
8
|
+
* `advisorRuns` ∥ `resolveAdvisorLaunch` 会写 `_advisorRuns` 与镜像字段。留下的族是「起 ∥ 停 ∥ 排 ∥ 关」写动作。
|
|
9
|
+
* 依赖方向单一:本档只依赖 `carrierField` ∥ `getAsyncPool`(async-settle.mjs)∥ `docSetKey` ∥
|
|
10
|
+
* `resolveReviewDocPaths` ∥ `scopeAdvisorMirror`(review-facts.mjs)∥ `randomUUID`(node:crypto);
|
|
11
|
+
* advisor-async.mjs 反向 import 本档的判定函数——两档之间是单向边。与 async-settle.mjs 之间
|
|
12
|
+
* 存在**既有的**一环(该档静态 import `refillAdvisorQueue`,本档 import `carrierField` ∥ `getAsyncPool`):
|
|
13
|
+
* 拆分前是 advisor-async ↔ async-settle 的一环,拆分后同一环多经本档一格——环数不变、本笔未新增环,
|
|
14
|
+
* 环上无模块级求值(两侧都只在函数体内调用)。
|
|
15
|
+
* 既有 import 面零改:原档 re-export 本档的全部既有导出(同 design-token.mjs ∥ advisor-settle.mjs 的先例)。
|
|
16
|
+
*/
|
|
17
|
+
import { randomUUID } from "node:crypto"
|
|
18
|
+
import { docSetKey, resolveReviewDocPaths, scopeAdvisorMirror } from "./review-facts.mjs"
|
|
19
|
+
import { carrierField, getAsyncPool } from "./async-settle.mjs"
|
|
20
|
+
|
|
21
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
22
|
+
// Review-instance registry (_advisorRuns — per-review rounds/prior/cap)
|
|
23
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
24
|
+
|
|
25
|
+
/** 载体吸收后的只读读取(不创建):父对象字段优先、缺字段回退跨 run 载体
|
|
26
|
+
* (`history` 数组——agent 逐 run 重建的形态靠它跨 run 存活)。无 ⇒ null。
|
|
27
|
+
* 导出面:写动作一族(`closeOpenCodeAdvisorRuns`)要用它,故跨档可见;它不是原档的既有导出,
|
|
28
|
+
* 故原档的 re-export 名单**不含**它(import 面与拆分前逐字同)。 */
|
|
29
|
+
export function advisorRunsRead(agent) {
|
|
30
|
+
const m = carrierField(agent, "_advisorRuns")
|
|
31
|
+
return m instanceof Map ? m : null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function advisorRuns(agent) {
|
|
35
|
+
// 实例注册表读取吸收(与 #94 载体口径同源):既有形态(字段挂 agent)零变;
|
|
36
|
+
// 注册表已挂跨 run 载体的形态直接沿用(不另建分叉)。
|
|
37
|
+
const existing = advisorRunsRead(agent)
|
|
38
|
+
if (existing) return existing
|
|
39
|
+
// 缺省创建:落在跨 run 载体上(有 history 时)——与其余载体字段同口径。
|
|
40
|
+
const holder = agent?.history ?? agent
|
|
41
|
+
if (!holder) return new Map()
|
|
42
|
+
if (!(holder._advisorRuns instanceof Map)) holder._advisorRuns = new Map()
|
|
43
|
+
return holder._advisorRuns
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The newest OPEN code instance (the thread a fix-round launch continues), or null. */
|
|
47
|
+
export function openCodeRun(agent) {
|
|
48
|
+
const runs = advisorRunsRead(agent)
|
|
49
|
+
if (!(runs instanceof Map) || runs.size === 0) return null
|
|
50
|
+
for (const r of [...runs.values()].reverse()) {
|
|
51
|
+
if (r.reviewType === "code" && r.open) return r
|
|
52
|
+
}
|
|
53
|
+
return null
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The newest OPEN design instance for the given document set, or null. */
|
|
57
|
+
function openDesignRun(agent, key) {
|
|
58
|
+
const runs = advisorRunsRead(agent)
|
|
59
|
+
if (!(runs instanceof Map) || runs.size === 0) return null
|
|
60
|
+
for (const r of [...runs.values()].reverse()) {
|
|
61
|
+
if (r.reviewType === "design" && r.open && r.docSetKey === key) return r
|
|
62
|
+
}
|
|
63
|
+
return null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Resolve the review instance a launch continues (AGENT-LOOP-ASYNC-POOL.md §6.10 ③ — per-review
|
|
68
|
+
* rounds/prior; reviewId = designId for design reviews, a random id for code).
|
|
69
|
+
* - design: continue the OPEN instance of the same document set (fix rounds of
|
|
70
|
+
* a review thread keep its designId and its round/prior); none → new instance.
|
|
71
|
+
* - code: continue the newest OPEN code instance (guard-driven fix loops);
|
|
72
|
+
* none → new instance.
|
|
73
|
+
* The legacy agent._advisorRound/_lastAdvisorOutput fields are SCOPED to the
|
|
74
|
+
* instance before the launch (message building + the run.mjs cap read them) —
|
|
75
|
+
* prior-less continuation degrades to round 1 semantics (fresh full review).
|
|
76
|
+
* @returns {{run: object, isNew: boolean, reviewId: string, designId: string|null}}
|
|
77
|
+
*/
|
|
78
|
+
export function resolveAdvisorLaunch(agent, reviewType, { documents = null } = {}) {
|
|
79
|
+
const runs = advisorRuns(agent)
|
|
80
|
+
let run = null
|
|
81
|
+
if (reviewType === "design") {
|
|
82
|
+
const key = docSetKey(documents, agent.cwd)
|
|
83
|
+
run = openDesignRun(agent, key)
|
|
84
|
+
if (!run) {
|
|
85
|
+
const reviewId = randomUUID()
|
|
86
|
+
// F2h (§29.1 2026-09-07): a same-scope re-review reuses the session's
|
|
87
|
+
// designId for this doc-set (any prior instance of the scope — open OR
|
|
88
|
+
// closed — the newest wins). A passed re-review overwrites the slot under
|
|
89
|
+
// the same id (no slot residue — T14: the old token is then rejected at
|
|
90
|
+
// the gate); old slots die at TTL only, kept as the fail-safe fallback.
|
|
91
|
+
const prior = [...runs.values()].reverse().find((r) => r.reviewType === "design" && r.docSetKey === key)
|
|
92
|
+
// #863 实例回收(§6.10):同 docSetKey 保最新一条 closed(= prior——F2h 只取 newest,语义零变);
|
|
93
|
+
// 余者去重回收(实例随删释放——closed 零消费面)。
|
|
94
|
+
for (const r of [...runs.values()]) {
|
|
95
|
+
if (r !== prior && r.reviewType === "design" && !r.open && r.docSetKey === key) runs.delete(r.reviewId)
|
|
96
|
+
}
|
|
97
|
+
run = {
|
|
98
|
+
reviewId, reviewType, designId: prior?.designId ?? reviewId,
|
|
99
|
+
round: 0, priorOutput: null, stale: false, open: true, docSetKey: key,
|
|
100
|
+
// 被审文档集的**受理绝对路径**(单源 = `resolveReviewDocPaths`——与受理面同一把尺):
|
|
101
|
+
// §10.2 封印按这一组算。`docSetKey` 是实例键(`normAbs` 的 cwd 拼法),cwd 非项目根时
|
|
102
|
+
// 它与受理路径不是同一组——拿实例键当封印清单会把封印盖到另一条路径上。
|
|
103
|
+
docAbs: [...resolveReviewDocPaths(documents, agent.cwd).resolved.values()],
|
|
104
|
+
}
|
|
105
|
+
runs.set(reviewId, run)
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
run = openCodeRun(agent)
|
|
109
|
+
if (!run) {
|
|
110
|
+
// #863 实例回收(§6.10):新 code 实例创建 ⇒ closed 实例清除(openCodeRun 仅取 open——零消费)。
|
|
111
|
+
for (const r of [...runs.values()]) {
|
|
112
|
+
if (r.reviewType === "code" && !r.open) runs.delete(r.reviewId)
|
|
113
|
+
}
|
|
114
|
+
const reviewId = randomUUID()
|
|
115
|
+
run = {
|
|
116
|
+
reviewId, reviewType, designId: null,
|
|
117
|
+
round: 0, priorOutput: null, stale: false, open: true, docSetKey: null,
|
|
118
|
+
}
|
|
119
|
+
runs.set(reviewId, run)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Scope the mirror fields to THIS instance (message builder + run.mjs cap +
|
|
123
|
+
// displays; #949 ① — the queued-launch window is re-secured at entry.start).
|
|
124
|
+
scopeAdvisorMirror(agent, run)
|
|
125
|
+
return { run, isNew: run.round === 0 && !run.priorOutput, reviewId: run.reviewId, designId: run.designId }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Guard round — the OPEN CODE instance only (2026-09-07 §8 F2): the design-written
|
|
129
|
+
* mirror never gates the code guard — no open code instance → 0. */
|
|
130
|
+
export function effectiveAdvisorRound(agent) {
|
|
131
|
+
return openCodeRun(agent)?.round ?? 0
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
135
|
+
// Async pool (agent._asyncAdvisors — pool 上限 F-1/F-2:常量 = 运行时回退权威(2 → 4),
|
|
136
|
+
// config.mjs DEFAULTS.agent.poolLimits.advisor = config 层镜像——耦合锁 config-pool
|
|
137
|
+
// .test.mjs 逐键断言——勿单侧改默认)
|
|
138
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
export const ADVISOR_POOL_LIMIT = 4
|
|
141
|
+
|
|
142
|
+
/** AGENT-LOOP-ASYNC-POOL.md §6.10 advisor 池生效上限(纯——读 agent.poolLimits.advisor——合法 ≥1 整数生效——
|
|
143
|
+
* 非法/缺省回退 ADVISOR_POOL_LIMIT——与 subagent 域 resolvePoolLimits 独立不共享
|
|
144
|
+
* (subagent 两键表不含本键——键表语义不同——POOL-CONFIG-UNIFIED F-2))。 */
|
|
145
|
+
export function resolveAdvisorPoolLimit(raw) {
|
|
146
|
+
const v = raw?.advisor
|
|
147
|
+
return Number.isInteger(v) && v >= 1 ? v : ADVISOR_POOL_LIMIT
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** launch 判定点每次读 agent.config(/config 热应用——变更即生效下个 launch——文案
|
|
151
|
+
* 如实报本值)。 */
|
|
152
|
+
export function advisorPoolLimitFor(agent) {
|
|
153
|
+
return resolveAdvisorPoolLimit(agent?.config?.agent?.poolLimits)
|
|
154
|
+
}
|
|
155
|
+
/** §6.10 同 scope 守卫(F-5——用户裁①):同 reviewType+scope 有 running 评审 → true
|
|
156
|
+
* (拒——running 并行多实例歧义放大——settled 续跑语义不变)。design scope = 文档集键
|
|
157
|
+
* (docSetKey);code = 单 code 线程(记录不记路径键——与 openCodeRun 语义一致)。
|
|
158
|
+
* 与池容量守卫独立:容量 = 全局 ≤N——scope = 同 scope ≤1——两关都过才启动。 */
|
|
159
|
+
export function runningAdvisorOfScope(agent, reviewType, docSetKey) {
|
|
160
|
+
const pool = getAsyncPool(agent, "advisor")
|
|
161
|
+
if (!(pool instanceof Map)) return false
|
|
162
|
+
for (const e of pool.values()) {
|
|
163
|
+
if (e.status !== "running" || e.reviewType !== reviewType) continue
|
|
164
|
+
if (reviewType === "design" && e.run?.docSetKey !== docSetKey) continue
|
|
165
|
+
return true
|
|
166
|
+
}
|
|
167
|
+
return false
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function runningAdvisorCount(agent) {
|
|
171
|
+
return [...(getAsyncPool(agent, "advisor")?.values() ?? [])].filter((e) => e.status === "running").length
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Any in-flight (non-done) async advisor review? — the completion guard skips
|
|
175
|
+
* its push-back while a review is pending (T-24b4: 未决不算未评审). */
|
|
176
|
+
export function advisorReviewPending(agent) {
|
|
177
|
+
return [...(getAsyncPool(agent, "advisor")?.values() ?? [])].some((e) => !e.done)
|
|
178
|
+
}
|
|
@@ -112,6 +112,9 @@ export function inflightDesignReviewConflict(agent, absPaths) {
|
|
|
112
112
|
* mirror retired per DESIGN-TOKEN-SETTLEMENT D3) + D1 settle-time slot persist
|
|
113
113
|
* (persistEngTokens — write failure = settle failure: no registration, no
|
|
114
114
|
* Approved echo, re-review — 评审 #1);
|
|
115
|
+
* **轮次块与状态行同成一笔,再与落盘同成败**(先写块、后落盘;落盘失败 ⇒ 档字节回写写前原文
|
|
116
|
+
* ⇒ 块与状态行一并撤销 + 槽 Map 回 `preMap`)
|
|
117
|
+
* —— 一笔的范围、顺序与回退 = `docs/core/design/BATCH-RECORD.md` §4.23。
|
|
115
118
|
* 4. fix B — branch-shaped report output (the caller writes it back to
|
|
116
119
|
* entry.report; digest injects the CLEANED form): pass → stripped +
|
|
117
120
|
* Approved/designId suffix (sync 参照形态); persist-failed → stripped +
|
|
@@ -147,6 +150,10 @@ export function settleAdvisorRun(agent, entry) {
|
|
|
147
150
|
const launchRefused = result != null && String(result).startsWith(ADVISOR_LAUNCH_REFUSAL_PREFIX)
|
|
148
151
|
if (!stale) {
|
|
149
152
|
if (run.reviewType === "design" && entry.designToken && result) {
|
|
153
|
+
// 结算面只认本笔快照(判据单源 = `docs/core/design/BATCH-LEDGER-REVIEW-UNIFY.md` §2.15):`run` 是
|
|
154
|
+
// 实例级对象,排队窗口里 `batchDoc` 被同一实例的后一笔发起覆盖过 ⇒ 不写回的话,本轮块会落进别人的档、
|
|
155
|
+
// token 归属也落到别人的档。
|
|
156
|
+
run.batchDoc = entry.batchDoc
|
|
150
157
|
// settle 前 Map 快照——落盘失败时回滚用(settle 失败 = 结算未发生,不留半结算态:
|
|
151
158
|
// 重评覆盖旧槽的边角(F2h 复用 designId)也原样恢复旧 token——内存与盘一致)。
|
|
152
159
|
const preMap = agent._engDesignTokens instanceof Map
|
|
@@ -175,9 +182,25 @@ export function settleAdvisorRun(agent, entry) {
|
|
|
175
182
|
else delete agent._engDesignTokens
|
|
176
183
|
run.approvedSuffix = null
|
|
177
184
|
persistFailed = true
|
|
185
|
+
// §4.23 ③(回退两处):档字节写回**写前原文**——只回退 Map 会在档上留一块没有 token 的轮次块,
|
|
186
|
+
// 下一轮读 §3 以为本轮已评过(轮次计数也虚增一块)。回退写也失败 ⇒ 两处并报、不静默
|
|
187
|
+
// (token 才是 spawn 的凭据,残留的块不授予假授权)。
|
|
188
|
+
// 范围如实 = **两处**(档字节 ∥ 槽 Map):`settleDesignReview` 同拍翻的实例态(`run.open` ∥
|
|
189
|
+
// `priorOutput`)不回退 ⇒ 失败后重跑是全新一轮评审,不是同一实例重评(同档 §4.23 ③ 的两处口径)。
|
|
190
|
+
let rollbackErr = null
|
|
191
|
+
if (settled.sign) {
|
|
192
|
+
try {
|
|
193
|
+
settled.sign.rollback()
|
|
194
|
+
} catch (e) {
|
|
195
|
+
rollbackErr = e?.message ?? String(e)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
178
198
|
logEvent("advisor:error", { id: `advisor#${entry.id}`, err: "engDesignTokens slot persist failed — settle failed (re-review)" })
|
|
179
199
|
const stripped = stripDesignTokenEcho(String(result), entry.designToken).trim()
|
|
180
|
-
|
|
200
|
+
const rollbackNote = rollbackErr
|
|
201
|
+
? `\n\n并报:块回写也失败了——批档 §3 上留着一条没有 token 的评审记录 (the block rollback failed too; the record keeps a round block that grants no authorization; reason: ${rollbackErr})。直接重跑评审即可。`
|
|
202
|
+
: ""
|
|
203
|
+
report = `${stripped}\n\nD1: the design review passed but the token could NOT be durably written to the session ledger (slot persist failed) — re-run advisor(type='design') to re-issue; no eng-coder spawn is authorized for this review (评审通过但 token 未能持久化——需重评;整笔未签发)。${rollbackNote}`.trim()
|
|
181
204
|
}
|
|
182
205
|
} else {
|
|
183
206
|
report = settled.output
|
|
@@ -205,6 +228,10 @@ export function settleAdvisorRun(agent, entry) {
|
|
|
205
228
|
)) || launchRefused
|
|
206
229
|
if (!failureVerdict) {
|
|
207
230
|
agent._calledAdvisorThisRun = true
|
|
231
|
+
// ADVISOR-CONVERGENCE.md §6.4 B 复位点 2(异步面):非陈旧且非失败结算 ⇒ 评审真的覆盖了这份代码
|
|
232
|
+
// ⇒ 本未评审周期结束,下一周期起于完整预算。
|
|
233
|
+
agent._advisorReminders = 0
|
|
234
|
+
agent._advisorHonestySent = false
|
|
208
235
|
}
|
|
209
236
|
} else if (run.reviewType === "design" && entry.designToken && result != null) {
|
|
210
237
|
// fix B(stale 分支):陈旧评审不签发——digest 不得展示未注册 token——先剥
|