@thincoder/core 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -2
- package/advisor/convergence.mjs +34 -3
- package/advisor/loop.mjs +42 -10
- package/advisor/messages.mjs +42 -25
- package/advisor/project-context.mjs +171 -42
- package/advisor/run.mjs +7 -4
- package/advisor.mjs +29 -43
- package/agent/batch-attribution.mjs +87 -0
- package/agent/batch-changed-surface.mjs +129 -0
- package/agent/completion.mjs +44 -3
- package/agent/dispatch-gates.mjs +6 -0
- package/agent/dispatch.mjs +8 -3
- package/agent/family-tools.mjs +27 -12
- package/agent/helpers.mjs +122 -1
- package/agent/offload.mjs +25 -29
- package/agent/post-turn.mjs +24 -10
- package/agent/record-results.mjs +18 -1
- package/agent/run-stages.mjs +77 -32
- package/agent/run-start.mjs +37 -0
- package/agent/setup-reminders.mjs +9 -2
- package/agent/setup.mjs +24 -11
- package/agent/spawn-child.mjs +38 -1
- package/agent/timers.mjs +5 -3
- package/agent/turn-loop.mjs +30 -5
- package/agent/turn-projection.mjs +386 -0
- package/agent/turn-task-state.mjs +274 -0
- package/agent/turn-tool-process.mjs +168 -0
- package/agent/write-gate-ledger.mjs +569 -0
- package/agent/write-gate.mjs +29 -352
- package/agent-tools/advisor-async.mjs +29 -169
- package/agent-tools/advisor-launch.mjs +178 -0
- package/agent-tools/advisor-settle.mjs +28 -1
- package/agent-tools/advisor.mjs +36 -47
- package/agent-tools/audit-block.mjs +6 -6
- package/agent-tools/batch-closeout.mjs +273 -35
- package/agent-tools/batch-gate.mjs +142 -342
- package/agent-tools/batch-ledger-bind.mjs +226 -17
- package/agent-tools/batch-ledger-view.mjs +109 -0
- package/agent-tools/batch-lifecycle.mjs +169 -46
- package/agent-tools/batch-paths.mjs +29 -8
- package/agent-tools/batch-record-write.mjs +417 -0
- package/agent-tools/batch-regions.mjs +215 -0
- package/agent-tools/batch-reopen.mjs +23 -11
- package/agent-tools/batch-segment-vocab.mjs +379 -0
- package/agent-tools/batch-skeleton.mjs +192 -239
- package/agent-tools/batch-supersede.mjs +232 -0
- package/agent-tools/batch-tier-gate.mjs +297 -0
- package/agent-tools/batch.mjs +182 -439
- package/agent-tools/consult.mjs +7 -4
- package/agent-tools/context.mjs +44 -17
- package/agent-tools/design-review-record.mjs +225 -0
- package/agent-tools/design-slots.mjs +1 -1
- package/agent-tools/design-token.mjs +279 -81
- package/agent-tools/doc-check.mjs +43 -33
- package/agent-tools/doc-graph.mjs +140 -0
- package/agent-tools/eng.mjs +9 -8
- package/agent-tools/escalate-async.mjs +2 -2
- package/agent-tools/manifest.mjs +34 -18
- package/agent-tools/read-history.mjs +112 -11
- package/agent-tools/review-facts.mjs +10 -3
- package/agent-tools/settings.mjs +23 -2
- package/agent-tools/spawn-gates.mjs +9 -8
- package/agent-tools/ssh-session.mjs +2 -2
- package/agent-tools/ssh-text.mjs +155 -0
- package/agent-tools/ssh-transport.mjs +19 -148
- package/agent-tools/subagent-actions-query.mjs +10 -6
- package/agent-tools/subagent-async.mjs +8 -9
- package/agent-tools/subagent-brief.mjs +76 -0
- package/agent-tools/subagent-design-token.mjs +168 -0
- package/agent-tools/subagent-run.mjs +1 -1
- package/agent-tools/subagent-scheduler.mjs +4 -4
- package/agent-tools/subagent-spawn.mjs +90 -110
- package/agent-tools/subagent.mjs +11 -10
- package/agent-tools/taskbook-block.mjs +94 -0
- package/agent-tools/timer.mjs +12 -8
- package/agent-tools/verify.mjs +13 -4
- package/agent-tools.mjs +7 -3
- package/agent.mjs +20 -1
- package/attachments.mjs +3 -3
- package/browser/actions.mjs +9 -3
- package/browser/cdp.mjs +45 -17
- package/browser/launch.mjs +25 -43
- package/browser/pool.mjs +299 -0
- package/browser/queue.mjs +2 -0
- package/browser/session-state.mjs +450 -0
- package/browser/session.mjs +127 -151
- package/browser/snapshot.mjs +89 -0
- package/client-identity.mjs +1 -1
- package/config-defaults.mjs +2 -1
- package/config-migrate.mjs +40 -0
- package/config-normalize.mjs +28 -2
- package/config-reload.mjs +59 -0
- package/config.mjs +62 -98
- package/context-degrade.mjs +38 -10
- package/context-echo.mjs +11 -0
- package/context.mjs +149 -83
- package/conventions.mjs +11 -9
- package/declaration.mjs +31 -5
- package/declared-repos.mjs +94 -0
- package/doc-check/doc-names.mjs +73 -0
- package/doc-check/doc-tokens.mjs +110 -0
- package/doc-check/existence.mjs +160 -0
- package/doc-check/index.mjs +309 -213
- package/doc-check/line-refs.mjs +27 -101
- package/doc-check/paragraph.mjs +218 -102
- package/doc-graph/anchors.mjs +474 -0
- package/doc-graph/doc-batch-face.mjs +59 -0
- package/doc-graph/doc-suffix.mjs +27 -0
- package/doc-graph/graph-tokens.mjs +160 -0
- package/doc-graph.mjs +778 -0
- package/explore-distill.mjs +11 -5
- package/i18n.mjs +1 -1
- package/instance-inbox-watch.mjs +272 -0
- package/instance-inbox.mjs +218 -0
- package/instance-registry.mjs +179 -0
- package/knowledge/README.md +3 -0
- package/knowledge/prompt-resources.md +6 -0
- package/ledger-close-proof.mjs +100 -49
- package/ledger-close.mjs +188 -0
- package/ledger-cmd.mjs +47 -91
- package/ledger-consistency.mjs +113 -0
- package/ledger-db.mjs +47 -15
- package/ledger-executors.mjs +1 -1
- package/ledger-tools.mjs +78 -19
- package/ledger-write-ops.mjs +130 -41
- package/ledger.mjs +1 -1
- package/manifest-discovery.mjs +3 -1
- package/manifest-schema.mjs +27 -5
- package/memory/schema.mjs +2 -2
- package/package.json +3 -1
- package/path-resolve.mjs +338 -57
- package/prompt-files.mjs +91 -1
- package/prompt-overlays.mjs +9 -6
- package/prompts/advisor-design.md +62 -21
- package/prompts/advisor-round1.md +34 -1
- package/prompts/advisor-round2.md +40 -7
- package/prompts/advisor-round3.md +39 -6
- package/prompts/common.md +14 -387
- package/prompts/consult-base.md +5 -1
- package/prompts/discipline-engineering.md +226 -51
- package/prompts/discipline-normal.md +4 -255
- package/prompts/knowledge/business-gates.md +22 -0
- package/prompts/knowledge/decision-quality.md +23 -0
- package/prompts/knowledge/doc-lookup.md +35 -0
- package/prompts/knowledge/document-writing.md +51 -0
- package/prompts/knowledge/documentation-evaluation.md +56 -0
- package/prompts/knowledge/evidence-discipline.md +57 -0
- package/prompts/knowledge/normal-coding-workflow.md +104 -0
- package/prompts/knowledge/normal-delivery-collaboration.md +108 -0
- package/prompts/knowledge/normal-work-management.md +57 -0
- package/prompts/knowledge/product-security.md +23 -0
- package/prompts/knowledge/project-records.md +62 -0
- package/prompts/knowledge/tool-advisor.md +29 -0
- package/prompts/knowledge/tool-apply-patch.md +18 -0
- package/prompts/knowledge/tool-bash.md +39 -0
- package/prompts/knowledge/tool-batch-eng-coder.md +12 -0
- package/prompts/knowledge/tool-batch-eng-designer.md +12 -0
- package/prompts/knowledge/tool-batch-review.md +12 -0
- package/prompts/knowledge/tool-batch.md +80 -0
- package/prompts/knowledge/tool-browser.md +57 -0
- package/prompts/knowledge/tool-code-search.md +4 -0
- package/prompts/knowledge/tool-consult-start.md +12 -0
- package/prompts/knowledge/tool-consult-stop.md +6 -0
- package/prompts/knowledge/tool-context.md +6 -0
- package/prompts/knowledge/tool-delete.md +17 -0
- package/prompts/knowledge/tool-doc-check.md +70 -0
- package/prompts/knowledge/tool-doc-graph-read.md +20 -0
- package/prompts/knowledge/tool-doc-graph.md +49 -0
- package/prompts/knowledge/tool-doc-search.md +6 -0
- package/prompts/knowledge/tool-edit.md +38 -0
- package/prompts/knowledge/tool-eng.md +2 -0
- package/prompts/knowledge/tool-execute.md +16 -0
- package/prompts/knowledge/tool-fetch.md +12 -0
- package/prompts/knowledge/tool-file-ops.md +16 -0
- package/prompts/knowledge/tool-get-current-time.md +7 -0
- package/prompts/knowledge/tool-git-read.md +19 -0
- package/prompts/knowledge/tool-git.md +29 -0
- package/prompts/knowledge/tool-glob.md +15 -0
- package/prompts/knowledge/tool-goal.md +8 -0
- package/prompts/knowledge/tool-grep.md +18 -0
- package/prompts/knowledge/tool-hashline-edit.md +14 -0
- package/prompts/knowledge/tool-insert-after.md +15 -0
- package/prompts/knowledge/tool-instance-list.md +6 -0
- package/prompts/knowledge/tool-instance-send.md +10 -0
- package/prompts/knowledge/tool-knowledge.md +18 -0
- package/prompts/knowledge/tool-ledger-read.md +35 -0
- package/prompts/knowledge/tool-ledger.md +42 -0
- package/prompts/knowledge/tool-lint.md +16 -0
- package/prompts/knowledge/tool-ls.md +13 -0
- package/prompts/knowledge/tool-lsp.md +11 -0
- package/prompts/knowledge/tool-main-history.md +2 -0
- package/prompts/knowledge/tool-manifest-read.md +14 -0
- package/prompts/knowledge/tool-manifest.md +31 -0
- package/prompts/knowledge/tool-memory-read.md +20 -0
- package/prompts/knowledge/tool-memory.md +15 -0
- package/prompts/knowledge/tool-notify-parent.md +12 -0
- package/prompts/knowledge/tool-operations.md +114 -0
- package/prompts/knowledge/tool-peer-instances.md +2 -0
- package/prompts/knowledge/tool-plan.md +6 -0
- package/prompts/knowledge/tool-process-read.md +13 -0
- package/prompts/knowledge/tool-process.md +15 -0
- package/prompts/knowledge/tool-question.md +16 -0
- package/prompts/knowledge/tool-read-history-batch.md +22 -0
- package/prompts/knowledge/tool-read-history.md +36 -0
- package/prompts/knowledge/tool-read-image.md +11 -0
- package/prompts/knowledge/tool-read.md +21 -0
- package/prompts/knowledge/tool-recent-changes.md +6 -0
- package/prompts/knowledge/tool-repo-outline.md +4 -0
- package/prompts/knowledge/tool-settings-read.md +12 -0
- package/prompts/knowledge/tool-settings.md +18 -0
- package/prompts/knowledge/tool-skill.md +6 -0
- package/prompts/knowledge/tool-ssh.md +52 -0
- package/prompts/knowledge/tool-subagent.md +59 -0
- package/prompts/knowledge/tool-task.md +12 -0
- package/prompts/knowledge/tool-team-ledger-read.md +11 -0
- package/prompts/knowledge/tool-team-ledger.md +11 -0
- package/prompts/knowledge/tool-timer.md +23 -0
- package/prompts/knowledge/tool-tree.md +14 -0
- package/prompts/knowledge/tool-verify.md +19 -0
- package/prompts/knowledge/tool-wait-for.md +25 -0
- package/prompts/knowledge/tool-websearch.md +19 -0
- package/prompts/knowledge/tool-write.md +9 -0
- package/prompts/knowledge/upstream-protocol.md +43 -0
- package/prompts/persona-eng-coder.md +21 -3
- package/prompts/persona-eng-designer.md +131 -169
- package/prompts/persona-engineering.md +142 -84
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-plan.md +5 -1
- package/prompts/subagent-base.md +2 -0
- package/provider/anthropic.mjs +6 -4
- package/provider/core.mjs +3 -2
- package/provider/errors.mjs +29 -4
- package/provider/google.mjs +24 -7
- package/provider/responses.mjs +3 -1
- package/provider-flows.mjs +2 -2
- package/session-index-build.mjs +1 -1
- package/session-index-pass.mjs +1 -1
- package/session-index-query.mjs +1 -1
- package/session-index.mjs +1 -1
- package/session-lifecycle.mjs +72 -17
- package/session-slot-write.mjs +37 -5
- package/session.mjs +24 -8
- package/skip-dirs.mjs +2 -2
- package/team-ledger.mjs +13 -9
- package/token-ttl.mjs +73 -4
- package/token-window.mjs +167 -33
- package/tool-docs/advisor.md +2 -27
- package/tool-docs/apply_patch.md +1 -15
- package/tool-docs/bash.md +2 -41
- package/tool-docs/batch-eng-coder.md +3 -0
- package/tool-docs/batch-eng-designer.md +3 -0
- package/tool-docs/batch-review.md +3 -0
- package/tool-docs/batch.md +2 -84
- package/tool-docs/browser.md +2 -49
- package/tool-docs/code_search.md +2 -2
- package/tool-docs/consult_start.md +2 -8
- package/tool-docs/consult_stop.md +2 -4
- package/tool-docs/context.md +1 -5
- package/tool-docs/delete.md +2 -17
- package/tool-docs/doc_check.md +2 -107
- package/tool-docs/doc_graph-read.md +3 -0
- package/tool-docs/doc_graph.md +3 -0
- package/tool-docs/doc_search.md +2 -4
- package/tool-docs/edit.md +1 -38
- package/tool-docs/eng.md +3 -1
- package/tool-docs/execute.md +2 -18
- package/tool-docs/fetch.md +2 -14
- package/tool-docs/file_ops.md +2 -18
- package/tool-docs/get_current_time.md +1 -6
- package/tool-docs/git-read.md +3 -0
- package/tool-docs/git.md +2 -35
- package/tool-docs/glob.md +2 -10
- package/tool-docs/goal.md +1 -6
- package/tool-docs/grep.md +2 -18
- package/tool-docs/hashline_edit.md +2 -15
- package/tool-docs/insert_after.md +2 -16
- package/tool-docs/instance_list.md +3 -0
- package/tool-docs/instance_send.md +3 -0
- package/tool-docs/knowledge.md +3 -0
- package/tool-docs/ledger-read.md +3 -0
- package/tool-docs/ledger.md +3 -8
- package/tool-docs/lint.md +2 -10
- package/tool-docs/ls.md +2 -11
- package/tool-docs/lsp.md +2 -9
- package/tool-docs/main_history.md +3 -1
- package/tool-docs/manifest-read.md +2 -8
- package/tool-docs/manifest.md +2 -35
- package/tool-docs/memory-read.md +3 -0
- package/tool-docs/memory.md +2 -20
- package/tool-docs/notify_parent.md +2 -13
- package/tool-docs/peer_instances.md +3 -1
- package/tool-docs/plan.md +1 -5
- package/tool-docs/process-read.md +3 -0
- package/tool-docs/process.md +2 -13
- package/tool-docs/question.md +3 -17
- package/tool-docs/read.md +2 -19
- package/tool-docs/read_history-batch.md +3 -0
- package/tool-docs/read_history.md +2 -18
- package/tool-docs/read_image.md +2 -9
- package/tool-docs/recent_changes.md +2 -2
- package/tool-docs/repo_outline.md +2 -2
- package/tool-docs/settings-read.md +3 -0
- package/tool-docs/settings.md +1 -12
- package/tool-docs/skill.md +2 -6
- package/tool-docs/ssh.md +1 -62
- package/tool-docs/subagent.md +2 -100
- package/tool-docs/task.md +1 -7
- package/tool-docs/team_ledger-read.md +3 -0
- package/tool-docs/team_ledger.md +3 -9
- package/tool-docs/timer.md +2 -19
- package/tool-docs/tree.md +2 -13
- package/tool-docs/verify.md +2 -12
- package/tool-docs/wait_for.md +2 -32
- package/tool-docs/websearch.md +2 -19
- package/tool-docs/write.md +2 -12
- package/tools/browser.mjs +52 -7
- package/tools/doc-write-gate.mjs +73 -0
- package/tools/edit-batch.mjs +170 -92
- package/tools/edit-diff.mjs +78 -62
- package/tools/edit-receipt.mjs +39 -0
- package/tools/execute.mjs +1 -1
- package/tools/file.mjs +16 -8
- package/tools/git.mjs +24 -9
- package/tools/index.mjs +6 -0
- package/tools/knowledge.mjs +143 -0
- package/tools/linter.mjs +3 -3
- package/tools/ops.mjs +3 -1
- package/tools/patch.mjs +123 -43
- package/tools/shared.mjs +28 -27
- package/tools/write-gate-params.mjs +31 -0
- package/tools/write-path.mjs +16 -4
- package/window-policy.mjs +203 -0
- package/doc-check/anchors.mjs +0 -235
|
@@ -14,14 +14,18 @@
|
|
|
14
14
|
* and unfixable by the user). Missing pieces now say so, and the reviewer is told
|
|
15
15
|
* to state the limitation in its findings. The document map is derived from the
|
|
16
16
|
* manifest's `docRoot` (the one place that says where the docs live); the standards face
|
|
17
|
-
* is the project's OWN declaration too (`docRoot.standards`
|
|
18
|
-
*
|
|
17
|
+
* is the project's OWN declaration too (`docRoot.standards` — a document LAYER: a directory
|
|
18
|
+
* whose `.md` files, subdirectories included, are the standards) — the probe was retired, the declaration
|
|
19
|
+
* replaced guessing — and it degrades in three machine-distinguishable states:
|
|
19
20
|
* undeclared (no path), declared but unreadable (the declared path is named), and injected.
|
|
20
21
|
*/
|
|
21
|
-
import { readFileSync, existsSync } from "node:fs"
|
|
22
|
+
import { readFileSync, readdirSync, existsSync, statSync } from "node:fs"
|
|
22
23
|
import { resolve, join, relative, dirname, sep } from "node:path"
|
|
23
24
|
import { providerSpec } from "../config.mjs"
|
|
24
|
-
import { DEFAULT_MANIFEST, docRootPaths, manifestFilePath, readManifest } from "../manifest.mjs"
|
|
25
|
+
import { DEFAULT_MANIFEST, docRootPaths, manifestFilePath, projectRootView, readManifest } from "../manifest.mjs"
|
|
26
|
+
// 去重键的折大小写尺子(本档私有):同一目录的两种大小写写法在 win32 上是同一个目录,
|
|
27
|
+
// 不折就同一份档注入两次。
|
|
28
|
+
const pathKey = (p) => (process.platform === "win32" ? p.toLowerCase() : p)
|
|
25
29
|
|
|
26
30
|
/** Project guide (AGENTS.md) injection budget — decision 2026-08-08:
|
|
27
31
|
* NO fixed truncation; long-context models (1M+) get up to 5% of their context
|
|
@@ -40,10 +44,11 @@ export const NO_STANDARDS_NOTICE = "(No project standards document — nothing i
|
|
|
40
44
|
export const NO_GIT_NOTICE = "(No git repository detected — change-set context is unavailable; read the review-scope files directly.)"
|
|
41
45
|
|
|
42
46
|
/**
|
|
43
|
-
* 态 2 ——
|
|
47
|
+
* 态 2 —— 声明了标准层,但一份都读不到(文案单源 = `docs/core/design/MANIFEST.md` §2.12)。
|
|
44
48
|
* 与 `NO_STANDARDS_NOTICE` **不得同形**:那句说的是「没有任何东西声明」,而这里恰好是「声明了但
|
|
45
49
|
* 读不到」。同形会让作者以为自己没声明过,回头去补一个其实已经有的声明——所以本句必带声明路径;
|
|
46
|
-
* `reason`
|
|
50
|
+
* `reason` 五值分列,对应三类可修面(KD-M1-65):`no such directory` 改路径 ∥ `not a directory`
|
|
51
|
+
* 改形态 ∥ `no .md file` 往层里放档;`read failed: <code>` ∥ `manifest read failed: <code>` 修权限 / 修档。
|
|
47
52
|
* @param {{path: string, reason: string}} p — 声明路径(绝对形)+ 读不到的原因
|
|
48
53
|
* @returns {string}
|
|
49
54
|
*/
|
|
@@ -53,8 +58,9 @@ export const STANDARDS_UNREADABLE_NOTICE = ({ path, reason }) =>
|
|
|
53
58
|
"Fix the path or the file — do NOT declare it again. State the limitation in your findings.)"
|
|
54
59
|
|
|
55
60
|
/**
|
|
56
|
-
* 半读句 ——
|
|
57
|
-
* = 静默丢声明,与需求档 §5.1 验收
|
|
61
|
+
* 半读句 —— 一个层里(或声明的多个目录里)有几份读不到(态 3 的下半——零静默:余项既不注入也不报
|
|
62
|
+
* = 静默丢声明,与需求档 §5.1 验收 ③「任何一面都不得静默跳过」相抵;设计 = `MANIFEST.md` §2.12
|
|
63
|
+
* KD-M1-65 的原因分列)。
|
|
58
64
|
* @param {{unreadable: string[]}} p — 逐份 `"<路径>: <原因>"`(路径绝对形)
|
|
59
65
|
* @returns {string}
|
|
60
66
|
*/
|
|
@@ -100,6 +106,50 @@ export function findGuideRoot(cwd, scopeFiles) {
|
|
|
100
106
|
return null
|
|
101
107
|
}
|
|
102
108
|
|
|
109
|
+
/**
|
|
110
|
+
* 评审注入面的**项目根**推导(标准层与文档地图共用;判据 = `docs/core/design/MANIFEST.md`
|
|
111
|
+
* §2.12「判据」块的 `base` 行)。`findGuideRoot` 答的是另一问(最近的 `AGENTS.md`),不在此函数的
|
|
112
|
+
* 射程内。三段,按序、任一命中即止:
|
|
113
|
+
* ① 评审范围项的归属项目根 —— 逐项 `resolve(cwd, item)` → `projectRootView(item)`,首个 `state === "ok"` 的
|
|
114
|
+
* `root`;序 = 喂给 `findGuideRoot` 的同一个序(`[...pathList, ...docList]`)。判据用「数据档归属」而
|
|
115
|
+
* 不用「最近的 `AGENTS.md`」——本键的基数必须是项目根(`docRoot` 的值一律相对项目根解析)。
|
|
116
|
+
* ② 会话锚自身的归属项目根 —— `projectRootView(cwd).root`,仅 `state === "ok"` 时;`workspace` 不向下取
|
|
117
|
+
* 子项目(KD-M1-30),故工作区锚不会被猜成某个子项目。
|
|
118
|
+
* ③ 两腿皆空 ⇒ `null` —— 调用方落 `agent.cwd`(既有缺省;本函数不给项目指南的根,那仍归 `findGuideRoot`)。
|
|
119
|
+
* **护栏**:①② 的每一次 `projectRootView` 调用各自包 `try`(抛 ⇒ 跳过该项 / 该腿,其余照走;两腿全空 ⇒ ③)。
|
|
120
|
+
* 依据 `thincoder-core/manifest-discovery.mjs` 的契约行「I/O 异常照原样上抛」——`owningProject` 取根那一环
|
|
121
|
+
* 无护栏,同档明写调用点要自己包护栏;而注入器自己的 `try` 只包 `readManifest`,腿 ② 一抛就穿过去。
|
|
122
|
+
* **第三参零缺省**:`scopeFiles` 不是数组即当场拒(`undefined` 与 `null` 同拒),拒因点名该参数与收到的值;
|
|
123
|
+
* **不归一成 `[]`**——「忘了传」与「范围为空」语义相反(前者是调用方写错,后者是一次真空范围的评审)。
|
|
124
|
+
* @param {string} cwd — 会话锚(绝对路径)
|
|
125
|
+
* @param {string[]} scopeFiles — 评审范围路径(cwd 相对或绝对;**无缺省**,空评审传 `[]`)
|
|
126
|
+
* @returns {string|null} 被评审范围的归属项目根(绝对路径);无项目可指 ⇒ null
|
|
127
|
+
*/
|
|
128
|
+
export function findProjectContextRoot(cwd, scopeFiles) {
|
|
129
|
+
if (!Array.isArray(scopeFiles)) {
|
|
130
|
+
const got = scopeFiles === undefined ? "undefined" : scopeFiles === null ? "null" : typeof scopeFiles
|
|
131
|
+
throw new TypeError(`findProjectContextRoot: scopeFiles must be an array (got ${got}) — pass the review scope as a list of paths, or [] for an empty one`)
|
|
132
|
+
}
|
|
133
|
+
for (const f of scopeFiles) {
|
|
134
|
+
try {
|
|
135
|
+
const view = projectRootView(resolve(cwd, f))
|
|
136
|
+
if (view.state === "ok") return view.root
|
|
137
|
+
} catch (e) {
|
|
138
|
+
// 该项解析抛(参数值异常 ∥ 权限 ∥ 链接环)⇒ 只跳过这一项,其余照走。
|
|
139
|
+
// 留一行告警:空吞会让「走了 ③」与「范围项本就无项目」在盘上不可分(同档另两处降级同形)。
|
|
140
|
+
console.warn(`[advisor] project-context root probe failed at ${String(f)} (cwd ${cwd}): ${e?.code ?? e?.message ?? "unknown"}`)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const view = projectRootView(cwd)
|
|
145
|
+
if (view.state === "ok") return view.root
|
|
146
|
+
} catch (e) {
|
|
147
|
+
// 同 ①:护栏住推导函数,不中断评审消息组装;告警让这一步可追。
|
|
148
|
+
console.warn(`[advisor] project-context root probe failed at cwd ${cwd}: ${e?.code ?? e?.message ?? "unknown"}`)
|
|
149
|
+
}
|
|
150
|
+
return null
|
|
151
|
+
}
|
|
152
|
+
|
|
103
153
|
/**
|
|
104
154
|
* Inject the project guide (AGENTS.md) into the review message. AGENTS.md is the
|
|
105
155
|
* project's doc map — it defines the structure and where requirements/design
|
|
@@ -207,10 +257,14 @@ export function findDocumentMap(base) {
|
|
|
207
257
|
/**
|
|
208
258
|
* Inject the project document map (PO-1), derived from `docRoot`. Degrades visibly: the reviewer
|
|
209
259
|
* must know the Document-ownership criterion is unchecked — never a silent skip.
|
|
260
|
+
* @param {Object} agent — the parent agent
|
|
261
|
+
* @param {string[]} parts — message parts (mutated)
|
|
262
|
+
* @param {string[]} scopeFiles — 评审范围路径;base = 它们的归属项目根(`findProjectContextRoot`,与标准层同一条
|
|
263
|
+
* 推导;无根 ⇒ `agent.cwd`)。**无缺省**——非数组由该函数当场拒,拒因点名参数与收到的值。
|
|
210
264
|
* @returns {string|null} the injected map path, or null when degraded
|
|
211
265
|
*/
|
|
212
|
-
export function injectDocumentMap(agent, parts,
|
|
213
|
-
const base =
|
|
266
|
+
export function injectDocumentMap(agent, parts, scopeFiles) {
|
|
267
|
+
const base = findProjectContextRoot(agent.cwd, scopeFiles) ?? agent.cwd
|
|
214
268
|
const mapPath = findDocumentMap(base)
|
|
215
269
|
parts.push("## Document Map")
|
|
216
270
|
let text = null
|
|
@@ -235,30 +289,111 @@ export function injectDocumentMap(agent, parts, root) {
|
|
|
235
289
|
/** 消息里的路径书写(\ → /):与 `injectProjectGuide` 的根注记同款(`relative(...).split(sep).join("/")`),
|
|
236
290
|
* 且让「声明路径字面」在消息里可 grep(`docs/nope` 而非 `docs\nope`)。读盘仍用原样路径。 */
|
|
237
291
|
const displayPath = (p) => String(p).replaceAll("\\", "/")
|
|
292
|
+
/**
|
|
293
|
+
* 标准层成员收集(模块私有——遍历 ∥ 序 ∥ 去重的单源;判据 ∥ 序 = `docs/core/design/MANIFEST.md` §2.12「接口契约」)。
|
|
294
|
+
*
|
|
295
|
+
* 递归:只下潜 `ent.isDirectory()`;**符号链接一律不跟**(`ent.isSymbolicLink()` 跳过,既不判文件也不下潜)——
|
|
296
|
+
* 环保险只落在这条上:无深度帽(会静默漏档)、无跳过表 ∥ 无条数帽(那两者属索引面策略,搬进来同样静默漏档)。
|
|
297
|
+
* 成员按**名字**认 `.md`(大小写不敏);**文件侧**不按 dirent 类型预筛(目录必下潜、链接必跳):读得成 = 可读,读不成 = 不可读(带该档自己的原因)。
|
|
298
|
+
* 序 = 成员**收完后对整集排一次**:目录序(声明序)→ 层根相对路径(`/` 归一)码点序——不是逐层下潜各按名序
|
|
299
|
+
* (递归后裸文件名不再唯一;两种读法只在「子目录名是层根档名的前缀」时给出相反的序)。
|
|
300
|
+
* 嵌套根(一根本身在另一根之内)⇒ 同一份档按**解析后的绝对档路径**去重、保留首次出现(首次出现的层根定排序键);
|
|
301
|
+
* 去重键在 **win32 折小写**(尺子 = `pathKey`——同一目录的两种写法是同一个目录);折小写**只作用于去重键**,
|
|
302
|
+
* 排序键与定位注仍用盘上的原字符串。
|
|
303
|
+
* 不去重则同一份档进两次正文、吃两份预算。
|
|
304
|
+
* @param {string[]} dirs — 声明目录的绝对路径(声明序;`docRootPaths` 已去重)
|
|
305
|
+
* @returns {{readable: {path: string, text: string}[], unreadable: {path: string, reason: string}[]}}
|
|
306
|
+
*/
|
|
307
|
+
function collectStandardDocs(dirs) {
|
|
308
|
+
const members = [] // { path, dirIndex, rel, text }——收完统一排序
|
|
309
|
+
const unreadable = []
|
|
310
|
+
dirs.forEach((dir, dirIndex) => {
|
|
311
|
+
// 逐目录四臂(判据 = §2.12「判据」块,逐臂对应):路径不存在 ∥ stat 抛 ∥ 不是目录 ∥ 列不出来。
|
|
312
|
+
if (!existsSync(dir)) { unreadable.push({ path: dir, reason: "no such directory" }); return }
|
|
313
|
+
let st
|
|
314
|
+
try {
|
|
315
|
+
st = statSync(dir)
|
|
316
|
+
} catch (e) {
|
|
317
|
+
unreadable.push({ path: dir, reason: `read failed: ${e?.code ?? "unknown"}` })
|
|
318
|
+
return
|
|
319
|
+
}
|
|
320
|
+
if (!st.isDirectory()) { unreadable.push({ path: dir, reason: "not a directory" }); return }
|
|
321
|
+
let mdSeen = 0 // 整棵子树见过的 `.md` 名字数(零 ⇒ `no .md file`;被去重的那份也算见过——子树不是空的)
|
|
322
|
+
let listFailed = false // 有目录列不出来 ⇒ 子树内容未观察完,"零 `.md`" 就是一句没人观察到的事实
|
|
323
|
+
const stack = [[dir, ""]] // 显式栈:深处照样走(不限深度);项 = [绝对路径, 层根相对前缀]
|
|
324
|
+
while (stack.length > 0) {
|
|
325
|
+
const [here, prefix] = stack.pop()
|
|
326
|
+
let entries
|
|
327
|
+
try {
|
|
328
|
+
entries = readdirSync(here, { withFileTypes: true })
|
|
329
|
+
} catch (e) {
|
|
330
|
+
// 任一下潜目录列不出来 ⇒ 该目录进不可读集、其余照走(与层根同一臂,不另立原因词)。
|
|
331
|
+
unreadable.push({ path: here, reason: `read failed: ${e?.code ?? "unknown"}` })
|
|
332
|
+
listFailed = true
|
|
333
|
+
continue
|
|
334
|
+
}
|
|
335
|
+
for (const ent of entries) {
|
|
336
|
+
if (ent.isSymbolicLink()) continue // 一律不跟:既不判文件也不下潜(环保险)
|
|
337
|
+
const rel = prefix ? `${prefix}/${ent.name}` : ent.name
|
|
338
|
+
if (ent.isDirectory()) { stack.push([join(here, ent.name), rel]); continue }
|
|
339
|
+
if (!/\.md$/i.test(ent.name)) continue
|
|
340
|
+
mdSeen++
|
|
341
|
+
const p = join(here, ent.name)
|
|
342
|
+
try {
|
|
343
|
+
members.push({ path: p, dirIndex, rel, text: readFileSync(p, "utf8") })
|
|
344
|
+
} catch (e) {
|
|
345
|
+
unreadable.push({ path: p, reason: `read failed: ${e?.code ?? "unknown"}` })
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
// 全子树零 `.md` ⇒ 该层根不可读(态 2 的第三因:声明对了、层里没档)。
|
|
350
|
+
// 但「列不出来」与「层里没档」是两类可修面(KD-M1-65):目录列不完时子树内容未知,
|
|
351
|
+
// 再补一句 `no .md file` 就是拿没人观察到的事实指错方向(作者会去放档,该修的是权限)。
|
|
352
|
+
if (mdSeen === 0 && !listFailed) unreadable.push({ path: dir, reason: "no .md file" })
|
|
353
|
+
})
|
|
354
|
+
// 整集排一次:目录序 → 层根相对路径码点序(`a < b` 比较,不用 localeCompare——跨机器同序)
|
|
355
|
+
members.sort((a, b) => (a.dirIndex !== b.dirIndex ? a.dirIndex - b.dirIndex : a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0))
|
|
356
|
+
const seen = new Set()
|
|
357
|
+
const readable = []
|
|
358
|
+
for (const m of members) {
|
|
359
|
+
const key = pathKey(resolve(m.path).replaceAll("\\", "/")) // 嵌套根 ∥ 同目录大小写两种写法:同一份档(win32 折小写)
|
|
360
|
+
if (seen.has(key)) continue // 保留首次出现(先出现的层根排在前面 ⇒ 排序键取它的层根)
|
|
361
|
+
seen.add(key)
|
|
362
|
+
readable.push({ path: m.path, text: m.text })
|
|
363
|
+
}
|
|
364
|
+
return { readable, unreadable }
|
|
365
|
+
}
|
|
238
366
|
|
|
239
367
|
/**
|
|
240
368
|
* Inject the project standards section (PO-2 · 判据 ∥ 文案单源 = `docs/core/design/MANIFEST.md` §2.12).
|
|
241
369
|
*
|
|
370
|
+
* 标准层(`docRoot.standards`)= 一个**文档层(目录)**,不是一份档:层内成员 = 该目录**及其全部子目录**下的 `.md`
|
|
371
|
+
* (大小写不敏感),按**层根相对路径**码点序;符号链接一律不跟(KD-M1-63)。
|
|
372
|
+
*
|
|
242
373
|
* 三态(**可机判互异**,本面立身之本 = 用声明、不猜固定名):
|
|
243
|
-
* 态 1 未声明 —— `docRoot.standards` 缺键 / `null` /
|
|
374
|
+
* 态 1 未声明 —— `docRoot.standards` 缺键 / `null` / 一个目录都没得来 ⇒ `NO_STANDARDS_NOTICE`
|
|
244
375
|
* (零路径字面、零 `declared`)。
|
|
245
|
-
* 态 2 声明了但读不到 ——
|
|
246
|
-
*
|
|
247
|
-
*
|
|
376
|
+
* 态 2 声明了但读不到 —— 逐目录 / 逐档都不可读 ⇒ `STANDARDS_UNREADABLE_NOTICE`(点名该**目录或该档**的
|
|
377
|
+
* 绝对路径 + 原因)。绝不与态 1 同形。原因取值域 = `no such directory` ∥ `not a directory` ∥
|
|
378
|
+
* `no .md file` ∥ `read failed: <code>` ∥ `manifest read failed: <code>`——三类可修面不同
|
|
379
|
+
* (改路径 ∥ 改形态 ∥ 往层里放档;KD-M1-65)。
|
|
380
|
+
* 态 3 读到 —— 逐档「定位注 + 正文」(目录序 + 层根相对路径码点序);部分读不到时正文在前、半读句逐项点名不可读者。
|
|
248
381
|
*
|
|
249
382
|
* 取值源 = `read.ok && read.manifest ? read.manifest : DEFAULT_MANIFEST`(同 `declaredDocRoots` 先例,
|
|
250
|
-
* 不另立第二套判定)⇒ 整档缺失 / 非法一律 `std === null` ⇒ 态 1;`
|
|
383
|
+
* 不另立第二套判定)⇒ 整档缺失 / 非法一律 `std === null` ⇒ 态 1;`dirs.length === 0 ⇒ 态 1` 是硬不
|
|
251
384
|
* 变量——态 2 句永不含 `undefined` 路径。数据档本身读抛(非 ENOENT)收为态 2 族,不中断消息组装。
|
|
252
385
|
*
|
|
253
386
|
* @param {Object} agent — the parent agent(`cwd` / provider 取上下文窗口)
|
|
254
387
|
* @param {string[]} parts — message parts (mutated)
|
|
255
|
-
* @param {string
|
|
256
|
-
* `injectDocumentMap` 同一 base
|
|
388
|
+
* @param {string[]} scopeFiles — 评审范围路径;base = 它们的归属项目根(`findProjectContextRoot`;无根 ⇒
|
|
389
|
+
* `agent.cwd`)。与 `injectDocumentMap` 同一 base、同一条推导。**无缺省**——非数组由该函数当场拒,拒因点名
|
|
390
|
+
* 参数与收到的值。
|
|
257
391
|
* @returns {string|string[]|null} 注入的标准档绝对路径(单份 = 串,多份 = 数组);降级 ⇒ null
|
|
258
392
|
*/
|
|
259
|
-
export function injectProjectStandards(agent, parts,
|
|
393
|
+
export function injectProjectStandards(agent, parts, scopeFiles) {
|
|
394
|
+
// base 先算:第三参不合契约时在改动 parts 之前就抛(消息里不留半段)。
|
|
395
|
+
const base = findProjectContextRoot(agent.cwd, scopeFiles) ?? agent.cwd
|
|
260
396
|
parts.push("## Project Standards")
|
|
261
|
-
const base = root ?? agent.cwd
|
|
262
397
|
|
|
263
398
|
// 数据档本身读抛(权限 / 目录等——`readManifest` fail-closed 上抛):收为态 2 族,不冒 `undefined`。
|
|
264
399
|
let read
|
|
@@ -271,36 +406,30 @@ export function injectProjectStandards(agent, parts, root) {
|
|
|
271
406
|
}
|
|
272
407
|
|
|
273
408
|
const std = (read.ok && read.manifest ? read.manifest : DEFAULT_MANIFEST).docRoot.standards
|
|
274
|
-
// 态 1(两入口):未声明(缺键 / null / undefined)∥
|
|
409
|
+
// 态 1(两入口):未声明(缺键 / null / undefined)∥ 声明了但一个合法目录都没得来。
|
|
275
410
|
// 后者是硬不变量:宁可判「未声明」,也绝不发一句带 `undefined` 的「declared at …」。
|
|
276
|
-
const
|
|
277
|
-
if (
|
|
411
|
+
const dirs = std == null ? [] : docRootPaths(std, base)
|
|
412
|
+
if (dirs.length === 0) {
|
|
278
413
|
parts.push(NO_STANDARDS_NOTICE) // degraded — visible by contract
|
|
279
414
|
parts.push("")
|
|
280
415
|
return null
|
|
281
416
|
}
|
|
282
417
|
|
|
283
|
-
|
|
284
|
-
const unreadable =
|
|
285
|
-
|
|
286
|
-
if (!existsSync(p)) { unreadable.push({ path: p, reason: "no such file" }); continue }
|
|
287
|
-
try {
|
|
288
|
-
readable.push({ path: p, text: readFileSync(p, "utf8") })
|
|
289
|
-
} catch (e) {
|
|
290
|
-
unreadable.push({ path: p, reason: `read failed: ${e?.code ?? "unknown"}` })
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
// 态 2:声明了,一份都读不到。
|
|
418
|
+
// 遍历 ∥ 排序 ∥ 嵌套去重全在 `collectStandardDocs`(本函数只留三态组装与预算——可读单元不变)。
|
|
419
|
+
const { readable, unreadable } = collectStandardDocs(dirs)
|
|
420
|
+
// 态 2:声明了,一份都读不到(句中路径 = 不可读集第一项——目录项与文件项同形)。
|
|
294
421
|
if (readable.length === 0) {
|
|
295
422
|
parts.push(STANDARDS_UNREADABLE_NOTICE({ path: displayPath(unreadable[0].path), reason: unreadable[0].reason }))
|
|
296
423
|
parts.push("")
|
|
297
424
|
return null
|
|
298
425
|
}
|
|
299
426
|
|
|
300
|
-
// 态 3
|
|
301
|
-
|
|
427
|
+
// 态 3:正文(一个层的全部档共用一次注入的同一预算——按**注入序**(目录序 → 层根相对路径码点序)拼接后一次截断)。
|
|
428
|
+
// 逐档定位注先行(评审要知道读的是哪一份),多档多行、与正文同序。
|
|
429
|
+
parts.push("The documents below are the project's standards — the `.md` files of the declared standards layer. Judge methodology compliance against them.")
|
|
302
430
|
parts.push("")
|
|
303
|
-
const
|
|
431
|
+
const blocks = readable.map((r) => ({ path: r.path, text: `<!-- standards file: ${displayPath(r.path)} -->\n${r.text}` }))
|
|
432
|
+
const body = blocks.map((b) => b.text).join("\n\n")
|
|
304
433
|
// 预算算式复用同两条常量、**逐注入独立计算**(不与指南共享池——两面语义不同,不该互相记账)。
|
|
305
434
|
// providerSpec 取值在 body 之外算:上下文规格查不到也不得伪装成「没有标准档」。
|
|
306
435
|
const resolvedProvider = agent.provider ?? agent._provider
|
|
@@ -313,17 +442,17 @@ export function injectProjectStandards(agent, parts, root) {
|
|
|
313
442
|
if (chars.length > cap) {
|
|
314
443
|
// 被截断的那一份(拼接期已有逐份偏移;偏移同以码点计)——恢复指针必须指向它,否则评审拿着残缺规矩判。
|
|
315
444
|
let offset = 0
|
|
316
|
-
let cut =
|
|
317
|
-
for (const
|
|
318
|
-
const len = [...
|
|
319
|
-
if (cap < offset + len) { cut =
|
|
445
|
+
let cut = blocks[blocks.length - 1].path
|
|
446
|
+
for (const b of blocks) {
|
|
447
|
+
const len = [...b.text].length
|
|
448
|
+
if (cap < offset + len) { cut = b.path; break }
|
|
320
449
|
offset += len + 2 // +2 = 拼接分隔符 "\n\n"
|
|
321
450
|
}
|
|
322
|
-
//
|
|
451
|
+
// 截断的风险不在大小,在**静默**:指南截断丢的是指针,标准层截断丢的是判据本身。
|
|
323
452
|
shown = chars.slice(0, cap).join("") + `\n\n…(truncated at ${cap} of ${chars.length} chars — the standard set is PARTIAL;\nread the full file — ${displayPath(cut)} — for the rest)`
|
|
324
453
|
}
|
|
325
454
|
parts.push(shown)
|
|
326
|
-
//
|
|
455
|
+
// 半读句:正文在前,缺口逐项点名(零静默——KD-M1-65)。
|
|
327
456
|
if (unreadable.length > 0) {
|
|
328
457
|
parts.push(STANDARDS_PARTIAL_NOTICE({ unreadable: unreadable.map((u) => `${displayPath(u.path)}: ${u.reason}`) }))
|
|
329
458
|
}
|
package/advisor/run.mjs
CHANGED
|
@@ -132,10 +132,13 @@ export async function runAdvisorReview(agent, reviewType, callbacks, designToken
|
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
// BATCH-RECORD.md §4.3
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
|
|
135
|
+
// BATCH-RECORD.md §4.3 批次档写通道的绑定——**与评审轨无关**:携了可读 `batchDoc` 即绑定
|
|
136
|
+
// (判据单源 = `docs/core/design/BATCH-LEDGER-REVIEW-UNIFY.md` §2.15)。同步路径 = 调用方(advisor
|
|
137
|
+
// 工具)传入的 callbacks.batchDoc(本笔发起时点的绑定值);异步路径 = 池条目 `entry.start()` 传入的
|
|
138
|
+
// 同一逐笔快照(条目字段 `batchDoc`,不读活的实例字段)。
|
|
139
|
+
// 工具面批走代码轨,评审员靠这一绑定才拿得到写 §3 的手;按轨截断 ⇒ 那一轨永远没有写通道,
|
|
140
|
+
// `§3` 只能编或永远挂着(用户 2026-11-01 11:43 否掉的那件事)。
|
|
141
|
+
const boundBatchDoc = batchDocForReview(agent, documents, callbacks)
|
|
139
142
|
// F13/`ADVISOR-GUARDS.md §2` #3:压缩定锚简报(评审参数构建——压缩触发时由 compaction 重挂)。
|
|
140
143
|
const pinned = buildPinnedBrief(reviewType, documents, object, designToken, designId)
|
|
141
144
|
|
package/advisor.mjs
CHANGED
|
@@ -14,7 +14,8 @@
|
|
|
14
14
|
* { advisor: { enabled: true, provider: "deepseek", model: "deepseek-chat" } }
|
|
15
15
|
* provider + model are optional — defaults to the main agent's provider/model.
|
|
16
16
|
*
|
|
17
|
-
* Convergence protocol:
|
|
17
|
+
* Convergence protocol (CODE REVIEW — a design review has none: it takes
|
|
18
|
+
* `advisor-design.md` every round and never decays):
|
|
18
19
|
* Round 1: full review → produces a numbered issue table.
|
|
19
20
|
* Agent responds with a response table per issue (fix claims).
|
|
20
21
|
* Round 2: semi-convergence — verifies the prior table + can flag obvious new issues.
|
|
@@ -32,7 +33,7 @@
|
|
|
32
33
|
* counter only drives prompt decay and display; failure paths end in a
|
|
33
34
|
* settlement conclusion block, and repeated failures are reported to the user.
|
|
34
35
|
* Rounds 2+ also declare all earlier diffs STALE and require read-verified
|
|
35
|
-
* file:line evidence for any unfixed/new finding — see docs/design/ADVISOR-CONVERGENCE.md.
|
|
36
|
+
* file:line evidence for any unfixed/new finding — see docs/core/design/ADVISOR-CONVERGENCE.md.
|
|
36
37
|
*
|
|
37
38
|
* Session memory (agent._advisorSession):
|
|
38
39
|
* RETAINED for initialization compatibility but NEVER read (decision d698434):
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
* Project customisation: .thincoder/advisor.md in the project root.
|
|
46
47
|
*/
|
|
47
48
|
import { extractAgentResponseTable } from "./advisor/history.mjs"
|
|
48
|
-
import { buildAdvisorUserMessage, resolveScopeFiles, buildObjectDeclarationBlock
|
|
49
|
+
import { buildAdvisorUserMessage, resolveScopeFiles, buildObjectDeclarationBlock } from "./advisor/messages.mjs"
|
|
49
50
|
import { buildConvergenceBody } from "./advisor/convergence.mjs"
|
|
50
51
|
import { escapeLiteralEscapes } from "./escape.mjs"
|
|
51
52
|
import { applyPromptInjections, loadAdvisorPrompt } from "./prompt-files.mjs"
|
|
@@ -61,10 +62,11 @@ export { buildObjectDeclarationBlock, buildDesignApprovalBlock } from "./advisor
|
|
|
61
62
|
// 改经核内单一解析面 `loadAdvisorPrompt`(契约 8 / D-C13);缺档语义不变 = 抛错(契约 9)。
|
|
62
63
|
|
|
63
64
|
const ADVISOR_ROUND1 = loadAdvisorPrompt("advisor-round1.md")
|
|
64
|
-
// ROUND2/3 are used whenever a convergence round (round 2+) is being
|
|
65
|
-
// in-run session continuation replaces the system prompt with them, and a
|
|
65
|
+
// ROUND2/3 are used whenever a CODE-REVIEW convergence round (round 2+) is being
|
|
66
|
+
// built: in-run session continuation replaces the system prompt with them, and a
|
|
66
67
|
// rebuilt fresh session (e.g. after a failed review) also selects them via
|
|
67
|
-
// buildAdvisorSystemPrompt when _advisorRound > 0.
|
|
68
|
+
// buildAdvisorSystemPrompt when _advisorRound > 0. A design review never takes
|
|
69
|
+
// them — it re-applies the full criteria every round (ADVISOR_DESIGN).
|
|
68
70
|
const ADVISOR_ROUND2 = loadAdvisorPrompt("advisor-round2.md")
|
|
69
71
|
const ADVISOR_ROUND3 = loadAdvisorPrompt("advisor-round3.md")
|
|
70
72
|
// Design-review prompt — hard-loaded like the round prompts (decision
|
|
@@ -78,16 +80,16 @@ const ADVISOR_DESIGN = loadAdvisorPrompt("advisor-design.md")
|
|
|
78
80
|
// ────────────────────────────────────────
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
|
-
|
|
83
|
+
* Build the system prompt for an advisor review session.
|
|
82
84
|
* @param {Object} agent — the parent agent
|
|
83
85
|
* @param {Object|null} [prior] — prior review output (full text; decision 2026-08-08)
|
|
84
86
|
* @param {string} [reviewType] — "design" for design review, undefined/"code" for code review
|
|
85
87
|
* @returns {string} the system prompt
|
|
86
88
|
*/
|
|
87
89
|
|
|
88
|
-
// 锚替换缝(CORE-UNIFICATION §2.13.8——U0
|
|
89
|
-
// (未配置 =
|
|
90
|
-
//
|
|
90
|
+
// 锚替换缝(CORE-UNIFICATION §2.13.8——U0):本函数**每个 return 分支**都经 `applyPromptInjections`
|
|
91
|
+
// (未配置 = 恒等,现行行为零变);读取径(模块级常量缓存)不动。必须保持的不变量:每个 return
|
|
92
|
+
// 分支都经 `applyPromptInjections`,新增分支未挂即错。
|
|
91
93
|
export function buildAdvisorSystemPrompt(agent, prior, reviewType) {
|
|
92
94
|
// Round decision is DETERMINISTIC (decision 2026-08-08): _advisorRound > 0
|
|
93
95
|
// with a stored review output means convergence (round 2+); 0 means round 1.
|
|
@@ -95,16 +97,11 @@ export function buildAdvisorSystemPrompt(agent, prior, reviewType) {
|
|
|
95
97
|
// and the stored output are the only inputs. A restarted process has
|
|
96
98
|
// _advisorRound 0 → conservative full re-review.
|
|
97
99
|
const hasPrior = (agent._advisorRound || 0) > 0 && (prior ?? agent._lastAdvisorOutput)
|
|
98
|
-
// Design review: round
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
const round = (agent._advisorRound || 0) + 1
|
|
105
|
-
if (round === 2) return applyPromptInjections(ADVISOR_ROUND2)
|
|
106
|
-
return applyPromptInjections(ADVISOR_ROUND3)
|
|
107
|
-
}
|
|
100
|
+
// Design review: EVERY round takes the dedicated design-review prompt — the
|
|
101
|
+
// complete criteria, applied to a full re-read (decision 2026-11-16). Design
|
|
102
|
+
// review has no convergence decay: the round counter drives display and audit
|
|
103
|
+
// only, never which criteria are in force.
|
|
104
|
+
if (reviewType === "design") return applyPromptInjections(ADVISOR_DESIGN)
|
|
108
105
|
if (!hasPrior) return applyPromptInjections(ADVISOR_ROUND1)
|
|
109
106
|
const round = (agent._advisorRound || 0) + 1
|
|
110
107
|
if (round === 2) return applyPromptInjections(ADVISOR_ROUND2)
|
|
@@ -178,8 +175,10 @@ export { escapeLiteralEscapes }
|
|
|
178
175
|
/**
|
|
179
176
|
* Build the advisor conversation for this run.
|
|
180
177
|
* EVERY call builds a fresh [system, user] session (decision d698434) — no
|
|
181
|
-
* session reuse across rounds: round 1 = full scope (ROUND1
|
|
182
|
-
* 2+ = convergence (ROUND2/ROUND3 prompt + fix-claims
|
|
178
|
+
* session reuse across rounds. CODE REVIEW: round 1 = full scope (ROUND1
|
|
179
|
+
* prompt), rounds 2+ = convergence (ROUND2/ROUND3 prompt + fix-claims
|
|
180
|
+
* follow-up). DESIGN REVIEW: every round takes ADVISOR_DESIGN and the full
|
|
181
|
+
* review scope, with the prior output carried as a reference block (no decay).
|
|
183
182
|
* @param {Object} agent — the parent agent
|
|
184
183
|
* @param {string} [reviewType] — "design" or "code" (已由工具层类型门定轨——此处无缺省;F30)
|
|
185
184
|
* @param {string|null} [designToken] — design-review approval token (design only)
|
|
@@ -198,10 +197,13 @@ export function prepareAdvisorMessages(agent, reviewType, designToken = null, do
|
|
|
198
197
|
// as buildAdvisorSystemPrompt (single source of truth for round semantics).
|
|
199
198
|
const prior = (agent._advisorRound || 0) > 0 ? (priorParam ?? agent._lastAdvisorOutput) : null
|
|
200
199
|
|
|
201
|
-
// Design review round
|
|
202
|
-
// token (an
|
|
203
|
-
//
|
|
204
|
-
|
|
200
|
+
// Design review — EVERY round: the dedicated full-scope review, with the
|
|
201
|
+
// approval token re-injected (an async fix-round continuation must be able to
|
|
202
|
+
// re-approve) and the prior review carried as a REFERENCE block, never as the
|
|
203
|
+
// verification list (decision 2026-11-16: a design review has no convergence
|
|
204
|
+
// decay — each round re-reads the whole scope against the complete criteria).
|
|
205
|
+
// Fresh session, exactly like round 1.
|
|
206
|
+
if (reviewType === "design") {
|
|
205
207
|
return [
|
|
206
208
|
{ role: "system", content: buildAdvisorSystemPrompt(agent, prior, reviewType) },
|
|
207
209
|
{ role: "user", content: escapeLiteralEscapes(buildAdvisorUserMessage(agent, prior, reviewType, designToken, documents, paths, object, designId)) },
|
|
@@ -213,7 +215,7 @@ export function prepareAdvisorMessages(agent, reviewType, designToken = null, do
|
|
|
213
215
|
// re-review false reports (the model quoted pre-fix file content instead of
|
|
214
216
|
// re-reading) and a token sink. The agent response table (fix claims) is
|
|
215
217
|
// injected through buildAdvisorFollowUp instead; the system prompt carries
|
|
216
|
-
// the round (ROUND2/ROUND3) via buildAdvisorSystemPrompt.
|
|
218
|
+
// the round (ROUND2/ROUND3, code review only) via buildAdvisorSystemPrompt.
|
|
217
219
|
// No prior review output: reset ONLY when this run made no code changes (user
|
|
218
220
|
// decision 2026-08-05: any loop that modified code must NOT reset — the
|
|
219
221
|
// advisor guard WILL push back, so the convergence round must keep advancing
|
|
@@ -260,22 +262,6 @@ export function prepareAdvisorMessages(agent, reviewType, designToken = null, do
|
|
|
260
262
|
// review surface.
|
|
261
263
|
const scopeFiles = resolveScopeFiles(agent, paths)
|
|
262
264
|
const followUp = buildAdvisorFollowUp(agent, prior, scopeFiles, object)
|
|
263
|
-
// AGENT-LOOP-ASYNC-POOL.md §6.10 D-24b (design round 2+ — async fix-round continuations must be able to
|
|
264
|
-
// re-approve): re-anchor the review scope (the convergence follow-up carries no
|
|
265
|
-
// document list) and inject the round's design token with the approval signal.
|
|
266
|
-
if (reviewType === "design") {
|
|
267
|
-
const docList = Array.isArray(documents)
|
|
268
|
-
? documents.filter((d) => typeof d === "string" && d.trim())
|
|
269
|
-
: []
|
|
270
|
-
const scopeBlock = docList.length > 0
|
|
271
|
-
? `\n\n## Documents to Review\nThe documents below are the review scope. Review ONLY these files — do not scan git diff or read any other files.\n${docList.map((d) => `- ${d} — Read this file in full`).join("\n")}`
|
|
272
|
-
: ""
|
|
273
|
-
const tokenBlock = designToken ? `\n\n${buildDesignApprovalBlock(designToken, designId)}` : ""
|
|
274
|
-
return [
|
|
275
|
-
{ role: "system", content: buildAdvisorSystemPrompt(agent, prior, reviewType) },
|
|
276
|
-
{ role: "user", content: escapeLiteralEscapes(followUp + scopeBlock + tokenBlock) },
|
|
277
|
-
]
|
|
278
|
-
}
|
|
279
265
|
return [
|
|
280
266
|
{ role: "system", content: buildAdvisorSystemPrompt(agent, prior, reviewType) },
|
|
281
267
|
{ role: "user", content: escapeLiteralEscapes(followUp) },
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agent/batch-attribution.mjs — 归属表:记录 / 查询 / 合入三个纯函数(本档零 fs、零 import)。
|
|
3
|
+
*
|
|
4
|
+
* 承载的东西 = 档位臂取材面的**判据一**(语义单源 = `docs/core/design/BATCH-RECORD.md` §4.18.1):
|
|
5
|
+
* 写的那一刻「这笔写服务哪一批」已知(`agent._batchDoc`——子代理由 spawn 绑定,见 `subagent-spawn.mjs`),
|
|
6
|
+
* 记账时把它连同路径一起写下;收口取「归属含本档」的那些路径。
|
|
7
|
+
*
|
|
8
|
+
* 为什么不加进 `agent._touchedFiles`:那个数组的读者有 `recent_changes`、`verify`、子代理调度、审计块四处,
|
|
9
|
+
* 改它的形状要同轮改四处;而归属只是多一列事实,于是另记一张表、`_touchedFiles` 的形状一字不动。
|
|
10
|
+
*
|
|
11
|
+
* 键 = 批档绝对路径(收口比对的正是批档本身;号→档还要多一次映射,而一笔写只知道它服务的批)。
|
|
12
|
+
* 值 = 该批改过的绝对路径集。
|
|
13
|
+
*
|
|
14
|
+
* 路径只做**存放**,不在这里归一:比较口径(win32 折小写、分隔符归一)归收口面那一次比对,本档不持第二把尺。
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** 表的取法:`agent._batchAttribution` 是 Map 就用它,否则当场建一张(首笔记账与后续读取同一形)。 */
|
|
18
|
+
function tableOf(agent) {
|
|
19
|
+
if (!agent || typeof agent !== "object") return null
|
|
20
|
+
if (agent._batchAttribution instanceof Map) return agent._batchAttribution
|
|
21
|
+
const table = new Map()
|
|
22
|
+
agent._batchAttribution = table
|
|
23
|
+
return table
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 批档键(只有非空串才算一个批;`null` ∥ 空串 = 这笔写没有绑定批档)。 */
|
|
27
|
+
const batchKeyOf = (batchDoc) => (typeof batchDoc === "string" && batchDoc.trim() !== "" ? batchDoc.trim() : null)
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 记账:把 `paths` 记到 `batchDoc` 名下(一档一批一条,重复记账幂等)。
|
|
31
|
+
* 没有绑定批档的写**不入表**——收口面对没有归属的路径按本批判(fail-closed),这里不替它猜一个批。
|
|
32
|
+
* @param {object} agent — 记账的载体(`agent._batchAttribution` 挂在它上面)
|
|
33
|
+
* @param {string[]} paths — 这笔写落下的绝对路径
|
|
34
|
+
* @param {string|null} batchDoc — 这笔写服务的批档(`agent._batchDoc`)
|
|
35
|
+
* @returns {boolean} 真有新路径入表 ⇒ `true`
|
|
36
|
+
*/
|
|
37
|
+
export function recordAttribution(agent, paths, batchDoc) {
|
|
38
|
+
const batch = batchKeyOf(batchDoc)
|
|
39
|
+
if (batch === null) return false
|
|
40
|
+
const list = Array.isArray(paths) ? paths : []
|
|
41
|
+
if (list.length === 0) return false
|
|
42
|
+
const table = tableOf(agent)
|
|
43
|
+
if (!table) return false
|
|
44
|
+
let set = table.get(batch)
|
|
45
|
+
if (!(set instanceof Set)) {
|
|
46
|
+
set = new Set()
|
|
47
|
+
table.set(batch, set)
|
|
48
|
+
}
|
|
49
|
+
let added = false
|
|
50
|
+
for (const p of list) {
|
|
51
|
+
if (typeof p !== "string" || p === "" || set.has(p)) continue
|
|
52
|
+
set.add(p)
|
|
53
|
+
added = true
|
|
54
|
+
}
|
|
55
|
+
return added
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 查询:`batchDoc` 这一批的路径集(**副本**——调用方排序 ∥ 过滤都不改表本体)。
|
|
60
|
+
* @param {object} agent — 载体
|
|
61
|
+
* @param {string} batchDoc — 批档(绝对路径)
|
|
62
|
+
* @returns {string[]} 该批的路径(无记录 ⇒ 空集,不是 `null`:空集与「这一批一笔没记」同判)
|
|
63
|
+
*/
|
|
64
|
+
export function attributedTo(agent, batchDoc) {
|
|
65
|
+
const batch = batchKeyOf(batchDoc)
|
|
66
|
+
const table = agent?._batchAttribution
|
|
67
|
+
if (batch === null || !(table instanceof Map)) return []
|
|
68
|
+
const set = table.get(batch)
|
|
69
|
+
return set instanceof Set ? [...set] : []
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 合入:子代理的归属表并回父侧(并集;子代理记在它自己的 `agent` 上,父侧不靠路径再猜)。
|
|
74
|
+
* @param {object} parent — 父侧载体(并进去的一方)
|
|
75
|
+
* @param {object} child — 子代理载体(被并的一方;没有表 ⇒ 什么都不做)
|
|
76
|
+
* @returns {boolean} 真并入了新路径 ⇒ `true`
|
|
77
|
+
*/
|
|
78
|
+
export function mergeAttribution(parent, child) {
|
|
79
|
+
const src = child?._batchAttribution
|
|
80
|
+
if (!(src instanceof Map) || src.size === 0) return false
|
|
81
|
+
let merged = false
|
|
82
|
+
for (const [batch, paths] of src) {
|
|
83
|
+
const list = paths instanceof Set ? [...paths] : []
|
|
84
|
+
if (recordAttribution(parent, list, batch)) merged = true
|
|
85
|
+
}
|
|
86
|
+
return merged
|
|
87
|
+
}
|