@thincoder/core 0.11.5 → 0.12.1
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 +27 -0
- package/abort-provenance.mjs +23 -0
- package/advisor/citations.mjs +5 -1
- package/advisor/compaction.mjs +13 -10
- package/advisor/history.mjs +6 -1
- package/advisor/loop.mjs +35 -10
- package/advisor/messages.mjs +31 -43
- package/advisor/project-context.mjs +49 -45
- package/advisor/run.mjs +82 -26
- package/advisor.mjs +40 -11
- package/agent/assemble.mjs +5 -5
- package/agent/chat-call.mjs +21 -1
- package/agent/completion.mjs +1 -20
- package/agent/dispatch-gates.mjs +8 -3
- package/agent/dispatch-run.mjs +131 -20
- package/agent/dispatch.mjs +23 -22
- package/agent/family-tools.mjs +4 -7
- package/agent/goal-judge.mjs +99 -0
- package/agent/goal-state.mjs +96 -0
- package/agent/helpers.mjs +13 -4
- package/agent/offload.mjs +1 -1
- package/agent/planning-graph-guardrail.mjs +224 -0
- package/agent/planning-prompt.mjs +179 -0
- package/agent/planning-step.mjs +460 -173
- package/agent/post-turn.mjs +23 -33
- package/agent/record-results.mjs +8 -5
- package/agent/run-stages.mjs +18 -38
- package/agent/run-start.mjs +26 -19
- package/agent/setup-reminders.mjs +16 -14
- package/agent/setup.mjs +3 -2
- package/agent/spawn-child.mjs +17 -4
- package/agent/suspension.mjs +42 -21
- package/agent/task-lifecycle.mjs +165 -52
- package/agent/timers.mjs +9 -1
- package/agent/turn-loop.mjs +160 -69
- package/agent/turn-projection.mjs +26 -15
- package/agent/turn-task-state.mjs +4 -4
- package/agent/write-gate-ledger.mjs +1 -1
- package/agent/write-gate.mjs +14 -11
- package/agent-tools/advisor-async.mjs +2 -0
- package/agent-tools/advisor-launch.mjs +27 -13
- package/agent-tools/advisor-settle.mjs +19 -18
- package/agent-tools/advisor.mjs +90 -13
- package/agent-tools/bash-async.mjs +3 -3
- package/agent-tools/batch-ledger-bind.mjs +8 -5
- package/agent-tools/batch-read.mjs +42 -0
- package/agent-tools/batch-record-write.mjs +20 -12
- package/agent-tools/batch-segment-vocab.mjs +6 -4
- package/agent-tools/batch-skeleton.mjs +43 -12
- package/agent-tools/consult.mjs +5 -1
- package/agent-tools/context.mjs +5 -4
- package/agent-tools/design-slots.mjs +7 -4
- package/agent-tools/design-token.mjs +3 -2
- package/agent-tools/doc-graph.mjs +257 -95
- package/agent-tools/escalate-async.mjs +4 -1
- package/agent-tools/goal.mjs +28 -95
- package/agent-tools/plan.mjs +1 -1
- package/agent-tools/review-facts.mjs +56 -7
- package/agent-tools/settings.mjs +35 -1
- package/agent-tools/ssh-transport.mjs +23 -22
- package/agent-tools/step.mjs +24 -4
- package/agent-tools/subagent-actions.mjs +6 -2
- package/agent-tools/subagent-async.mjs +4 -2
- package/agent-tools/subagent.mjs +1 -1
- package/agent-tools/task.mjs +73 -65
- package/agent-tools.mjs +3 -3
- package/agent.mjs +12 -3
- package/auto-think.mjs +16 -3
- package/browser/actions.mjs +5 -1
- package/browser/cdp.mjs +1 -1
- package/browser/pool.mjs +110 -17
- package/compaction-work-state.mjs +103 -13
- package/compress-form.mjs +29 -3
- package/config-defaults.mjs +27 -3
- package/config-io.mjs +3 -14
- package/config-normalize.mjs +24 -4
- package/config-presets.mjs +40 -26
- package/config-warn.mjs +30 -0
- package/config.mjs +139 -63
- package/context-degrade.mjs +4 -4
- package/context-push.mjs +20 -9
- package/context.mjs +65 -20
- package/doc-graph/anchors.mjs +39 -40
- package/doc-graph/clusters.mjs +49 -0
- package/doc-graph/code-parsers.mjs +494 -0
- package/doc-graph/context-pack.mjs +392 -0
- package/doc-graph/dir-signals.mjs +228 -0
- package/doc-graph/edges.mjs +231 -0
- package/doc-graph/format.mjs +70 -0
- package/doc-graph/gc-cmd.mjs +104 -0
- package/doc-graph/gc.mjs +112 -0
- package/doc-graph/glob-work-graph.mjs +307 -0
- package/doc-graph/golden-set.mjs +131 -0
- package/doc-graph/ls-work-graph.mjs +534 -0
- package/doc-graph/outline.mjs +377 -0
- package/doc-graph/output-annotations.mjs +85 -0
- package/doc-graph/process-docs.mjs +68 -0
- package/doc-graph/read-work-graph.mjs +91 -0
- package/doc-graph/rebuild-cmd.mjs +75 -0
- package/doc-graph/resolvers.mjs +322 -0
- package/doc-graph/roots.mjs +86 -0
- package/doc-graph/schema.mjs +110 -0
- package/doc-graph/search-augment.mjs +418 -0
- package/doc-graph/store.mjs +231 -0
- package/doc-graph/target-resolve.mjs +352 -0
- package/doc-graph/walk.mjs +87 -0
- package/doc-graph.mjs +583 -707
- package/explore-distill.mjs +52 -17
- package/generate-title.mjs +7 -4
- package/ledger-close.mjs +6 -6
- package/ledger-cmd.mjs +3 -3
- package/ledger-consistency.mjs +8 -6
- package/ledger-db.mjs +45 -10
- package/ledger-migrate.mjs +25 -10
- package/ledger-read.mjs +1 -1
- package/ledger-write-ops.mjs +6 -6
- package/ledger.mjs +2 -2
- package/model-context.mjs +54 -18
- package/model-specs.mjs +86 -67
- package/package.json +1 -1
- package/prompt-overlays.mjs +3 -3
- package/prompts/advisor-round1.md +6 -5
- package/prompts/common.md +16 -6
- package/prompts/consult-base.md +2 -1
- package/prompts/discipline-engineering.md +1 -1
- package/prompts/discipline-normal.md +12 -8
- package/prompts/knowledge/doc-lookup.md +2 -2
- package/prompts/knowledge/normal-batch-discipline.md +2 -2
- package/prompts/knowledge/normal-delivery-collaboration.md +3 -3
- package/prompts/knowledge/tool-advisor.md +2 -2
- package/prompts/knowledge/tool-apply-patch.md +1 -1
- package/prompts/knowledge/tool-bash.md +2 -2
- package/prompts/knowledge/tool-batch.md +4 -4
- package/prompts/knowledge/tool-glob.md +9 -2
- package/prompts/knowledge/tool-goal.md +9 -6
- package/prompts/knowledge/tool-grep.md +7 -2
- package/prompts/knowledge/tool-ls.md +11 -5
- package/prompts/knowledge/tool-lsp.md +1 -1
- package/prompts/knowledge/tool-operations.md +3 -2
- package/prompts/knowledge/tool-plan.md +1 -1
- package/prompts/knowledge/tool-read.md +7 -6
- package/prompts/knowledge/tool-repo-graph-read.md +12 -0
- package/prompts/knowledge/tool-repo-graph.md +12 -0
- package/prompts/knowledge/tool-step.md +1 -1
- package/prompts/knowledge/tool-subagent.md +2 -2
- package/prompts/knowledge/tool-task.md +10 -9
- package/prompts/knowledge/tool-tree.md +7 -1
- package/prompts/persona-eng-coder.md +1 -1
- package/prompts/persona-eng-designer.md +1 -1
- package/prompts/persona-engineering.md +2 -1
- package/prompts/persona-explore.md +1 -1
- package/prompts/persona-normal.md +7 -6
- package/prompts/persona-plan.md +2 -2
- package/prompts/planning-next-moves.md +7 -8
- package/provider/anthropic.mjs +53 -51
- package/provider/core.mjs +85 -34
- package/provider/errors.mjs +33 -10
- package/provider/google.mjs +244 -37
- package/provider/list-models.mjs +28 -14
- package/provider/responses-request.mjs +15 -9
- package/provider/responses.mjs +10 -8
- package/provider/sse.mjs +3 -6
- package/proxy-transport.mjs +228 -119
- package/rules-file.mjs +79 -0
- package/rules.mjs +13 -51
- package/session-lifecycle.mjs +32 -20
- package/team-ledger.mjs +7 -7
- package/think-off.mjs +37 -18
- package/token-window.mjs +48 -31
- package/tool-args.mjs +8 -8
- package/tool-docs/bash.md +1 -1
- package/tool-docs/glob.md +3 -1
- package/tool-docs/goal.md +2 -2
- package/tool-docs/grep.md +3 -1
- package/tool-docs/ls.md +7 -1
- package/tool-docs/read.md +1 -1
- package/tool-docs/repo_graph-read.md +3 -0
- package/tool-docs/repo_graph.md +3 -0
- package/tool-docs/tree.md +1 -1
- package/tools/bash.mjs +53 -8
- package/tools/browser.mjs +4 -4
- package/tools/file.mjs +34 -7
- package/tools/glob-dialect.mjs +57 -7
- package/tools/index.mjs +3 -7
- package/tools/patch.mjs +8 -7
- package/tools/process-doc-mark.mjs +13 -0
- package/tools/search.mjs +152 -37
- package/tools/shared.mjs +6 -0
- package/tools/tree.mjs +211 -8
- package/window-policy.mjs +205 -126
- package/prompts/knowledge/tool-doc-graph-read.md +0 -20
- package/prompts/knowledge/tool-doc-graph.md +0 -49
- package/prompts/knowledge/tool-peek.md +0 -10
- package/prompts/knowledge/tool-repo-outline.md +0 -4
- package/tool-docs/doc_graph-read.md +0 -3
- package/tool-docs/doc_graph.md +0 -3
- package/tool-docs/peek.md +0 -3
- package/tool-docs/repo_outline.md +0 -3
- package/tools/peek.mjs +0 -447
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
All notable changes to the core package are documented here.
|
|
4
4
|
Format: Keep a Changelog · 中文 · 号在发布时定(CalVer——见 `docs/RELEASE.md` §4)。
|
|
5
5
|
|
|
6
|
+
## [0.12.1] — 2026-12-03
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **task 只读查询**:`action:"list"` 返回带当前 1 起编号的清单,`action:"get"` 按编号或标题子串取单项;查询不改状态、不刷新面板、不注入提醒。
|
|
11
|
+
- **`read` 就地图谱头**:层标识之后、正文之前附一段独立元信息(该档的未读关联面),与 `glob` / `ls` / `tree` / `grep` 同一规矩;「图谱没用成」(冷仓超阈值 ∥ 根不存在 ∥ 查询出错)出一条可见降级行,「确实无关联面」静默。
|
|
12
|
+
- **Gemini 搜索接地发送面**:`providers[].grounding` 入请求,响应侧解析搜索结果元数据(三端开关与读数行随各端发布)。
|
|
13
|
+
- **文档标题检索**:文档 H1–H4 标题进入检索面。
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- **task 收尾不再强制续跑**:删除未闭清单的轮末 sweep 提醒与额外模型轮;全员 `done` 自动清表保留,确未完成的项按实际状态保留。
|
|
18
|
+
- **task 更新去轻推**:更新与清表不再附 context nudge;goal 自身的方向提醒不变。
|
|
19
|
+
- **图谱注记降噪与消歧**:glob 的命中集内部出度改标 `→hits N`,不再据此判定全仓孤立;grep 冷仓提示删除非法 `maxColdFiles` 参数;glob/grep/ls 的测试注记只承诺直接导入关系;`ls byDirectory` 不再输出文件级关系区。
|
|
20
|
+
- **工具路由与簇计算边界收敛**:glob/grep/ls 的模型可见描述按内容定位、文件名发现、目录浏览和结构查询分工;glob 簇划分与内部边计数拆入无 I/O 的 `clusters.mjs`,输出口径不变。
|
|
21
|
+
- **Turn 0 图谱操作内同步复用**:候选预热与后续必读包按项目根共享当次同步 lease,多目标同根不重复扫描并统一关库;不同外部调用不复用完成结果,freshness check 不省略。
|
|
22
|
+
- **搜索后确定性补未读清单**:grep/glob/ls/code_search 的真实源码命中统一进入种子采集,取消仅前 40 行或最多两个路径的漏检;下一次模型执行前直接复用 `getMissingReadingPack` 注入精确未读路径,不增加规划模型调用,不设硬写门。
|
|
23
|
+
- **整档阅读判据修正**:只有未传 `offset` / `limit` 的默认整档 `read` 或此前完整阅读才解除提醒;源码与文档的显式窗口读取不再误记为 full-read。
|
|
24
|
+
- **搜索被动上下文覆盖补齐**:grep 的全部命中文件都带直接权威/配对文档与直接导入测试及仓内相对路径,完整展开仍限前三个锚点;glob 的 13–100 档保留直接契约、配对文档与直接测试,仅 >100 档过滤共享契约。
|
|
25
|
+
- **`outline` 基准与根包含**:父工作区相对形与其余入口同基准;只报目标根之下的档,绝对 `glob` 明确拒绝而不静默零匹配。
|
|
26
|
+
- **搜索类工具的图谱融合延续**:glob 汇总前移、ls 融合、tree 目录行带图信号、SQL 裸名入图;撤掉 `knowledge` 开关与末尾推荐段。
|
|
27
|
+
- **图谱没用成时的可见降级**:冷仓超阈值、项目根不存在、查询出错均出 `[graph] …` 行,不再把「图谱没用成」读成「没有关联」。
|
|
28
|
+
|
|
29
|
+
### Removed
|
|
30
|
+
|
|
31
|
+
- **task 精简为标题与状态**:删除 `targets` / `evidence` / `verify` / `result` 字段及顶层 `result`;实测读数留在工具输出、交付与验证声明中。
|
|
32
|
+
|
|
6
33
|
## [0.11.5] — 2026-11-28
|
|
7
34
|
|
|
8
35
|
### Fixed
|
package/abort-provenance.mjs
CHANGED
|
@@ -31,6 +31,29 @@ export function triggerOf(signal) {
|
|
|
31
31
|
return "unknown"
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/** 用户中断判定(catch 面单源):**信号的权威高于错误形态**。
|
|
35
|
+
* 2026-12-01 实测:abort 在底层可能以 `signal.reason` 对象本身、而非 `AbortError` 的形态上抛(代理 ∥ 网关路径)——
|
|
36
|
+
* 按 `e.name === "AbortError"` 判会漏掉,用户按停会被当成普通失败。四条 transport 的 catch 一律引本函数。 */
|
|
37
|
+
export function isUserInterrupt(signal) {
|
|
38
|
+
return signal?.aborted === true && signal?.reason?.interrupt === true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** 中断标记(四条 transport 与请求出口共用):`interrupted` 置位,**有 message 才带** `interruptMessage`
|
|
42
|
+
* (CLI Ctrl+C 首按的「停回合」就是无 message 形)。四处共用本函数,字段形状才一致。 */
|
|
43
|
+
export function markInterrupted(result, signal) {
|
|
44
|
+
result.interrupted = true
|
|
45
|
+
const msg = typeof signal?.reason?.message === "string" ? signal.reason.message : ""
|
|
46
|
+
if (msg) result.interruptMessage = msg
|
|
47
|
+
return result
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 中断行的**唯一拼装点**:有 message ⇒ `[User interrupt: <msg>]`;无 message ⇒ `[User interrupt]`。
|
|
51
|
+
* 三处消费面(`turn-loop` 的两支、`chat-call` 的 AbortError 兜底)共引,不各自拼字串。 */
|
|
52
|
+
export function interruptLine(message) {
|
|
53
|
+
const text = typeof message === "string" ? message.trim() : ""
|
|
54
|
+
return text ? `[User interrupt: ${text}]` : "[User interrupt]"
|
|
55
|
+
}
|
|
56
|
+
|
|
34
57
|
/**
|
|
35
58
|
* 产生点错误(abort 面):AbortError + `reason` 透传 + `abortInfo` 标注。
|
|
36
59
|
* message 取既有通用文案(既有前缀断言零回归——死亡行前缀逐字保留)。
|
package/advisor/citations.mjs
CHANGED
|
@@ -61,6 +61,10 @@ function resolveCitation(citation, roots, base) {
|
|
|
61
61
|
let mismatch = null
|
|
62
62
|
let traversal = false
|
|
63
63
|
for (const root of roots) {
|
|
64
|
+
const candidate = resolve(root, citation.file)
|
|
65
|
+
// P2-9:越界判定先于存在性——越界且不存在的路径不该报成 `file unreadable`
|
|
66
|
+
// (设计 §3 的四类失败分类里,越界就是 path traversal)。
|
|
67
|
+
if (!candidate.startsWith(fence)) { traversal = true; continue }
|
|
64
68
|
let real
|
|
65
69
|
try {
|
|
66
70
|
// Path confinement: citation paths are LLM-generated — never trust them.
|
|
@@ -68,7 +72,7 @@ function resolveCitation(citation, roots, base) {
|
|
|
68
72
|
// report) files outside the project, including API-key configs.
|
|
69
73
|
// realpathSync resolves symlinks too — a link inside the project that
|
|
70
74
|
// points outside must not pass the prefix check.
|
|
71
|
-
real = realpathSync(
|
|
75
|
+
real = realpathSync(candidate)
|
|
72
76
|
} catch {
|
|
73
77
|
continue // 该候选无此文件(或不可解析)——试下一候选
|
|
74
78
|
}
|
package/advisor/compaction.mjs
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* advisor-loop-split 批:loop 的压缩检查点归位本档(`compactContextIfNeeded`——`context_limit` 尾串生成点同迁;时间线面 ⇒ `advisor/timeline.mjs`)。
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { policyBudget } from "../config.mjs" // 预算派生单源(`providerSpec` ∥ `outputReserve` ∥ `usableWindow` 都经 `budgetOf` 这一处合流);`policyBudget` = 主链同一个出口(有效窗口 + `threshold`),评审席不自带比例
|
|
15
15
|
// B4(群 B 批,ADVISOR-GUARDS.md §9——F32):CJK 加权单源(provider/rate.mjs 叶子向无环)
|
|
16
16
|
import { estimateText } from "../provider/rate.mjs"
|
|
17
17
|
|
|
@@ -25,19 +25,22 @@ export const MAX_ADVISOR_TURNS = 100
|
|
|
25
25
|
// 上下文预算(第 25 批——120K 硬编码退场):预算跟随评审模型窗口(providerSpec:
|
|
26
26
|
// 模型规格表 × provider 级 context 覆盖)**扣完成预留**(2026-10-06 裁定——预留坐在窗口里 ⇒
|
|
27
27
|
// 压缩先行、不判死;基数 = 可用窗口,见 advisorContextBudget)。头寸用途 = chars/4 估算误差 +
|
|
28
|
-
// 响应/协议开销(内存不构成约束——`ADVISOR-GUARDS.md §8
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
// 响应/协议开销(内存不构成约束——`ADVISOR-GUARDS.md §8`);判死线 = 物理上限,服务端窗口约束不变。
|
|
29
|
+
//
|
|
30
|
+
// 2026-11-30 用户裁定「一个窗口只能有一条压缩线」:原 `CONTEXT_LIMIT_RATIO` / `COMPACT_TRIGGER_RATIO`
|
|
31
|
+
// 两颗 0.8 退役(第 25 批把 120K 硬编码换成跟随模型窗口时原样留下的「既有关系零改」——既非裁定、
|
|
32
|
+
// 也无测试,结果是同一模型在主会话 559,718 才压、在评审席 425,328 就压)。两个数现在直接取
|
|
33
|
+
// `policyBudget`:判死线 = `limit`、压缩触发 = `threshold`,与主链逐位相同。
|
|
31
34
|
|
|
32
35
|
/** 评审上下文预算(纯函数——两档阈值可机测;provider 为 null 时退化默认规格)。
|
|
36
|
+
* **与主链同一组数**:两个出口都取 `policyBudget(provider)`(`window-policy.mjs` 单源,
|
|
37
|
+
* `CONTEXT-COMPACTION.md` §2.2)——`limit` = 窗口 − 完成预留 = 物理上限,`compactAt` = 主链压缩线。
|
|
33
38
|
* 基数 = **可用窗口 = 窗口 − 完成预留**(#975/用户 2026-10-06 裁定——预留坐在窗口里 ⇒
|
|
34
39
|
* 先压缩、不许 provider 先拒:provider 口径 = 输入 + max_tokens ≤ 窗口;预留 = `outputReserve`)。
|
|
35
|
-
*
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const limit = Math.floor(requestBudget(provider).limit * CONTEXT_LIMIT_RATIO)
|
|
40
|
-
return { limit, compactAt: Math.floor(limit * COMPACT_TRIGGER_RATIO) }
|
|
40
|
+
* 派生链没有无解格(`reserve` 已封在半窗以下),`limit` 恒为正,评审面按正常预算判。 */
|
|
41
|
+
export function advisorContextBudget(provider, settings) {
|
|
42
|
+
const { limit, threshold } = policyBudget(provider, undefined, undefined, settings)
|
|
43
|
+
return { limit, compactAt: threshold }
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
export const TOOL_TIMEOUT_MS = 30_000 // single tool timeout
|
package/advisor/history.mjs
CHANGED
|
@@ -38,7 +38,12 @@ export function extractAgentResponseTable(history, since) {
|
|
|
38
38
|
const entries = flattenHistory(turns)
|
|
39
39
|
let start
|
|
40
40
|
if (since && typeof since === "object") {
|
|
41
|
-
|
|
41
|
+
// 位置越过线尾的两种形态都要回落 0:① 那个轮元素已被摘要切走(`since.turn` 越界);
|
|
42
|
+
// ② 该轮内层因压缩变短(`since.msg` 越界)。只判 turn 不够——`flatIndexOf` 对 msg 越界是
|
|
43
|
+
// 抱错不夹取,一个过时水位就会把评审子代理当场打挂(实测形态:`invalid msg 20 in turn 7 (0..15)`)。
|
|
44
|
+
const turnMsgs = Array.isArray(turns[since.turn]?.messages) ? turns[since.turn].messages.length : 0
|
|
45
|
+
const stale = since.turn >= turns.length || !Number.isInteger(since.msg) || since.msg > turnMsgs
|
|
46
|
+
start = stale ? 0 : flatIndexOf(turns, since)
|
|
42
47
|
} else if (typeof since === "number") {
|
|
43
48
|
start = since
|
|
44
49
|
}
|
package/advisor/loop.mjs
CHANGED
|
@@ -13,10 +13,10 @@ import { providerSpec, assistantEchoMessage, isThinkingRequest } from "../config
|
|
|
13
13
|
import { toOpenAISchema } from "../tools/index.mjs"
|
|
14
14
|
import { truncateAdvisorResult } from "./truncate.mjs"
|
|
15
15
|
import { batchTool } from "../agent-tools/batch.mjs"
|
|
16
|
-
//
|
|
17
|
-
//
|
|
16
|
+
// 文档与项目图谱工具面(`docs/core/design/AGENT-LOOP-SUBAGENT.md` · 需求 `docs/core/requirements/REPO-GRAPH.md`):
|
|
17
|
+
// 评审段拿到两件只读工具:`doc_check` 本体 ∥ `repo_graph`(六动作全只读)。
|
|
18
18
|
// **工具在场 ≠ 义务**:评审的判据来自文档本体(读那一节、与代码和需求对出来),机检的 PASS 只说明锚点与段长
|
|
19
|
-
// 合规、`
|
|
19
|
+
// 合规、`repo_graph` 只回答「谁引了谁」——两者都不是判据面。拿到它们是为了「核一个锚在不在盘」这类局部事实时
|
|
20
20
|
// 不必上抛,而不是给它一条结论捷径;没有机制禁止它调用,也不该有。静态 import(同 `batchTool` 那条):
|
|
21
21
|
// `doc-graph.mjs` 的静态闭包不达 `node:sqlite`(机制档只在 execute 里动态 import);`doc-check.mjs` 的静态闭包
|
|
22
22
|
// 经 `doc-check/index.mjs → declaration.mjs → memory/file-walk.mjs` 到达 `node:sqlite`。而本档**原有**的 `batchTool`
|
|
@@ -25,6 +25,15 @@ import { batchTool } from "../agent-tools/batch.mjs"
|
|
|
25
25
|
// 通路;本批只按同一条静态 import 先例接入,模块域零新增 TLA(两档都不是 TLA import)。
|
|
26
26
|
import { docCheckTool } from "../agent-tools/doc-check.mjs"
|
|
27
27
|
import { docGraphReadTool } from "../agent-tools/doc-graph.mjs"
|
|
28
|
+
// `manifest` 只读变体:`common.md` 的「先问 `manifest`」与「## 项目状态用 `manifest` 工具」两节都点名它,
|
|
29
|
+
// 而 `common.md` 自本批起装配进评审系统提示词——按 `PROMPT-SYSTEM.md` §8.2,提示词点名的工具必须在表内。
|
|
30
|
+
// 取只读变体(`manifestReadTool`,action 枚举只剩 `read`):评审不改项目声明。
|
|
31
|
+
import { manifestReadTool } from "../agent-tools/manifest.mjs"
|
|
32
|
+
// `knowledge`(只读主题库):`common.md` 写着「需要正文时用 `knowledge get <id>` 取回」,而 `common.md` 自
|
|
33
|
+
// 本批起装配进评审系统提示词——按 `PROMPT-SYSTEM.md` §8.2,提示词要求读者做一件只有某个工具能做的事时,
|
|
34
|
+
// 读这段文字的每个读者都必须有这个工具。它的 `expand=lazy` 锚行因此是**主题清单**,不是死文本。
|
|
35
|
+
// 静态 import:`tools/knowledge.mjs → prompt-files.mjs ∥ tools/shared.mjs`,两条都不达 `node:sqlite`。
|
|
36
|
+
import { knowledgeTool } from "../tools/knowledge.mjs"
|
|
28
37
|
import {
|
|
29
38
|
shouldBudgetNudge, budgetNudgeText, timeoutTail, renderTimeline, compactContextIfNeeded,
|
|
30
39
|
stripProcessNarration,
|
|
@@ -42,7 +51,8 @@ const { lspTool } = await import("../tools/lsp.mjs")
|
|
|
42
51
|
const { codeSearchTool } = await import("../memory/code-sync.mjs")
|
|
43
52
|
|
|
44
53
|
/**
|
|
45
|
-
* Advisor tool set — ZERO git, every round
|
|
54
|
+
* Advisor tool set — ZERO git, every round:十件只读工具(`read` / `glob` / `grep` / `ls` / `lsp` /
|
|
55
|
+
* `code_search` / `knowledge` / `manifest` / `doc_check` / `repo_graph`)
|
|
46
56
|
* + 绑定档时追加 `batch`(写面限 `§3`;工程设计轨不追加——`BATCH-RECORD.md` §4.3)。
|
|
47
57
|
* The change surface comes from the
|
|
48
58
|
* review scope (paths / _touchedFiles injected by the caller), never from git: git output misled
|
|
@@ -69,7 +79,7 @@ function advisorCodeSearchTool(agent) {
|
|
|
69
79
|
* @returns {{schemas: object[], byName: Map<string, object>}}
|
|
70
80
|
*/
|
|
71
81
|
function advisorToolsFor(agent, reviewType, batchDoc = null) {
|
|
72
|
-
const tools = [readTool, globTool, grepTool, lsTool, lspTool, advisorCodeSearchTool(agent), docCheckTool, docGraphReadTool]
|
|
82
|
+
const tools = [readTool, globTool, grepTool, lsTool, lspTool, advisorCodeSearchTool(agent), docCheckTool, docGraphReadTool, knowledgeTool, manifestReadTool]
|
|
73
83
|
// BATCH-RECORD.md §4.3:挂载判据 = 绑定 ∧ ¬(工程模式 ∧ 设计轨)——具名谓词在 `messages.mjs`
|
|
74
84
|
// (`reviewHoldsBatchWrite`,同一事实也决定运行期 Approval Signal 说哪一支)。工程设计轨的 §3 对一切
|
|
75
85
|
// 工具通道只读、轮次块由结算写,工具给了它也只会收到一条拒——不发(fail-closed)。代码轨与普通模式照旧
|
|
@@ -80,7 +90,7 @@ function advisorToolsFor(agent, reviewType, batchDoc = null) {
|
|
|
80
90
|
const ordered = [...tools].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
81
91
|
return { schemas: ordered.map((tool) => toOpenAISchema(tool, "normal")), byName: new Map(ordered.map((t) => [t.name, t])) }
|
|
82
92
|
}
|
|
83
|
-
// Test seam: the tool set is pure
|
|
93
|
+
// Test seam: the tool set is pure(恒在十件只读工具 + 批次档绑定條件)。
|
|
84
94
|
export { advisorToolsFor, advisorToolsFor as _advisorToolsFor }
|
|
85
95
|
|
|
86
96
|
/**
|
|
@@ -92,12 +102,15 @@ export { advisorToolsFor, advisorToolsFor as _advisorToolsFor }
|
|
|
92
102
|
* frozen through every tool-call phase and the review appears to have stalled.
|
|
93
103
|
*
|
|
94
104
|
* @param {string|null} [pinned] — 第 11 批:压缩定锚简报(评审参数构建——F13/`ADVISOR-GUARDS.md §2` #3)。
|
|
95
|
-
* @param {{now?: Function, chat?: Function, describeArgs?: Function}} [seams] — 测试缝 + ④ 端差注入点
|
|
105
|
+
* @param {{now?: Function, chat?: Function, describeArgs?: Function, onUsage?: Function}} [seams] — 测试缝 + ④ 端差注入点
|
|
96
106
|
* (默认 Date.now / chat / 无进度行——生产调用不传时进度行由端装配层补齐)。
|
|
107
|
+
* `seams.onUsage(usage)` 是同一注入面:每轮模型响应一到就交一次,供状态行按整会话读数(docs/cli/design/TUI.md §4)。
|
|
108
|
+
* 缺省零行为(headless 嵌入没有这个读者)。
|
|
97
109
|
*/
|
|
98
110
|
async function runAdvisorToolLoop(provider, messages, onOutput, signal, agent, cwd, toolsOverride = null, reviewType, batchDoc = null, pinned = null, seams = {}) {
|
|
99
111
|
const now = seams.now ?? Date.now
|
|
100
112
|
const chatCall = seams.chat ?? chat
|
|
113
|
+
const onUsage = seams.onUsage ?? null
|
|
101
114
|
// ④ 端差注入点(CORE-UNIFICATION §2.5 #109「进度行按端注入」):工具进度行的参数摘要
|
|
102
115
|
// 是**展示面**(单源 = 核 `tool-args.mjs` `describeToolArgs`(B7 1a);CLI 取核件转口,VSC = 卡片头),不进核。
|
|
103
116
|
// 未注入 ⇒ 不发进度行(核内零端名分支——契约 5 / 10)。端在装配层传入自己的格式化器。
|
|
@@ -120,7 +133,7 @@ async function runAdvisorToolLoop(provider, messages, onOutput, signal, agent, c
|
|
|
120
133
|
const startTime = now()
|
|
121
134
|
// 第 25 批(`ADVISOR-GUARDS.md §8`):上下文预算跟随评审模型窗口——`providerSpec`(模型规格表 × provider 级
|
|
122
135
|
// context 覆盖)派生;函数体内、while 轮次外一次性(provider 全场不变),两档消费见下守卫。
|
|
123
|
-
const budget = advisorContextBudget(provider)
|
|
136
|
+
const budget = advisorContextBudget(provider, agent?.config)
|
|
124
137
|
// #934(零落笔看门狗——AGENT-LOOP-UPSTREAM.md §6.32.2 ②):阈值单源(叶档 agent-tools/zero-write-watch.mjs)——
|
|
125
138
|
// 函数域动态 import:模块域会与既有环(叶 → parent-channel → async-settle ↔ advisor-async → 本档)
|
|
126
139
|
// 互锁(加载期 TLA 死锁);函数运行时图已就绪,模块缓存 ⇒ 每次评审一次代价。
|
|
@@ -190,6 +203,11 @@ async function runAdvisorToolLoop(provider, messages, onOutput, signal, agent, c
|
|
|
190
203
|
messages,
|
|
191
204
|
tools: toolSchemas,
|
|
192
205
|
signal: callSignal,
|
|
206
|
+
// 模型语义参数(2026-12-03 批,台账 #133):advisor 的 thinking ∥ reasoningEffort 经 `config.advisor`
|
|
207
|
+
// 算出、由 `run.mjs` 经 `seams.modelParams` 透传——不再挂在 provider 克隆上。
|
|
208
|
+
modelParams: seams.modelParams,
|
|
209
|
+
// 会话设置(模型窗口声明 ∥ 档位上限)——评审窗口封顶与会话同源(2026-12-03 批)。
|
|
210
|
+
settings: agent?.config,
|
|
193
211
|
onToken: (t) => { if (String(t ?? "").trim()) { reviewTextProduced = true; silentRounds = 0; roundHadText = true } onText(t) },
|
|
194
212
|
onReasoning: onThink,
|
|
195
213
|
// LOGGING(vscode advisor/run.mjs parity——按 stage 可 grep)
|
|
@@ -223,6 +241,13 @@ async function runAdvisorToolLoop(provider, messages, onOutput, signal, agent, c
|
|
|
223
241
|
return renderTimeline(timeline, timeoutTail(timeoutMs, turns, toolCallCount, reviewTextProduced))
|
|
224
242
|
}
|
|
225
243
|
|
|
244
|
+
// 状态行整会话总流量(docs/cli/design/TUI.md §4,用户 2026-11-28 23:21):评审是主会话里跑得最久的一族模型会话,
|
|
245
|
+
// 它不交 usage,状态行标着「整会话」而读数少了它。转发挂在「响应已拿到、尚未分派」这一点上:工具轮与收尾轮各算一 resp;
|
|
246
|
+
// 缺 usage(夹具 / 旧 provider)就不交,不造一个 0(TUI.md §4「所有读数缺失时不伪造」)。
|
|
247
|
+
if (response?.usage) {
|
|
248
|
+
try { onUsage?.(response.usage) } catch { /* 读数转发不得把一次评审上抛成 failed 面 */ }
|
|
249
|
+
}
|
|
250
|
+
|
|
226
251
|
// No tool calls — this is the final review text. The report is this round's
|
|
227
252
|
// own output, shaped through the same report-defining strip; the timeline
|
|
228
253
|
// (every earlier round's exploration) is only the fallback when this round
|
|
@@ -243,8 +268,8 @@ async function runAdvisorToolLoop(provider, messages, onOutput, signal, agent, c
|
|
|
243
268
|
// tool-call assistant history lacks it — the observed "reasoning stops
|
|
244
269
|
// after the first tool call, returns only at the final answer" symptom.
|
|
245
270
|
// Mirrors the main agent's push (agent.mjs).
|
|
246
|
-
const echoSpec = providerSpec(provider)
|
|
247
|
-
messages.push(assistantEchoMessage(response, echoSpec, isThinkingRequest(
|
|
271
|
+
const echoSpec = providerSpec(provider, agent?.config)
|
|
272
|
+
messages.push(assistantEchoMessage(response, echoSpec, isThinkingRequest(seams.modelParams ?? null, echoSpec), provider ?? null))
|
|
248
273
|
|
|
249
274
|
// B1: the SAME LLM reply's multiple read-only
|
|
250
275
|
// tool calls run in PARALLEL (Promise.all) — results are backfilled in
|
package/advisor/messages.mjs
CHANGED
|
@@ -6,10 +6,9 @@
|
|
|
6
6
|
* ENGINEERING-MODE.md §2.26.3); the pre-split surface is re-exported below.
|
|
7
7
|
*/
|
|
8
8
|
import { join, relative, sep } from "node:path"
|
|
9
|
-
import { findReviewRepos, collectRepoSnapshots, collectChangedFiles } from "./repos.mjs"
|
|
10
9
|
import { buildConvergenceBody, buildConvergenceInstructions, buildPriorReviewBlock } from "./convergence.mjs"
|
|
11
10
|
import { loadAdvisorMd, extractConversationBackground, extractAgentResponseTable } from "./history.mjs"
|
|
12
|
-
import { injectProjectGuide, injectDocumentMap, injectProjectStandards
|
|
11
|
+
import { injectProjectGuide, injectDocumentMap, injectProjectStandards } from "./project-context.mjs"
|
|
13
12
|
// 拍平投影:背景段收拍平视图(响应表由 `extractAgentResponseTable` 自己拍平)。
|
|
14
13
|
import { flattenHistory } from "../context-push.mjs"
|
|
15
14
|
|
|
@@ -183,13 +182,7 @@ function buildAdvisorUserMessageInner(agent, prior, reviewType, designToken = nu
|
|
|
183
182
|
// round re-reads the whole scope against the complete criteria). Round 2+ adds
|
|
184
183
|
// the prior review output as a REFERENCE block below.
|
|
185
184
|
if (reviewType === "design") {
|
|
186
|
-
const repos = findReviewRepos(agent)
|
|
187
185
|
parts.push("## Design Review")
|
|
188
|
-
// FR15/P8: no git → change-set context is unavailable. Say it (never silent).
|
|
189
|
-
if (repos.length === 0) {
|
|
190
|
-
parts.push(NO_GIT_NOTICE)
|
|
191
|
-
parts.push("")
|
|
192
|
-
}
|
|
193
186
|
if (docList.length > 0) {
|
|
194
187
|
// Explicit review scope (engineering mode, FR2): the caller hands over the
|
|
195
188
|
// doc list — the advisor reviews ONLY these. No git-diff change-set
|
|
@@ -201,39 +194,35 @@ function buildAdvisorUserMessageInner(agent, prior, reviewType, designToken = nu
|
|
|
201
194
|
parts.push(docList.map((d) => `- ${d} — Read this file in full`).join("\n"))
|
|
202
195
|
parts.push("")
|
|
203
196
|
} else {
|
|
204
|
-
//
|
|
205
|
-
|
|
197
|
+
// 工具面已拒发(`agent-tools/advisor.mjs` 的文档范围门)——直接调用方仍可能走到这里:
|
|
198
|
+
// 可见降级,不猜 git diff(F36/N2)。评审席据此报「范围未给出」而不是去扫变更集。
|
|
199
|
+
parts.push("No review scope was given — the caller supplied no `documents`. Do not scan git diff or guess a scope; state in your findings that the review scope is missing.")
|
|
206
200
|
parts.push("")
|
|
207
|
-
|
|
208
|
-
// List changed file paths explicitly — new design docs are untracked,
|
|
209
|
-
// so git diff HEAD won't show their content; the advisor must read the file itself
|
|
210
|
-
const changedFiles = collectChangedFiles(repos, agent.cwd)
|
|
211
|
-
if (changedFiles.length > 0) {
|
|
212
|
-
parts.push("## Changed Files")
|
|
213
|
-
parts.push(changedFiles.map((f) => `- ${f}`).join("\n"))
|
|
214
|
-
parts.push("")
|
|
215
|
-
parts.push("Read each changed file in full — untracked files are not shown in the diff below.")
|
|
216
|
-
parts.push("")
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Pre-collected changes — the design doc diff.
|
|
220
|
-
const snapshots = collectRepoSnapshots(repos, agent.cwd)
|
|
221
|
-
if (snapshots.length > 0) {
|
|
222
|
-
parts.push("## Design Document (git diff)")
|
|
223
|
-
parts.push(...snapshots)
|
|
224
|
-
parts.push("")
|
|
225
|
-
}
|
|
226
201
|
}
|
|
227
202
|
|
|
228
|
-
//
|
|
229
|
-
//
|
|
230
|
-
// undeclared / declared-but-unreadable /
|
|
203
|
+
// The project standards section — read from the project's own declaration
|
|
204
|
+
// (`docRoot.standards`); three states, each machine-distinguishable:
|
|
205
|
+
// undeclared / declared-but-unreadable / listed-for-reading. Never a probed convention name (PO-2).
|
|
206
|
+
// **Unconditional**: the standards layer is a PROJECT DOCUMENT face, not a mode feature — a
|
|
207
|
+
// normal-mode review needs it exactly as much as an engineering-mode one. The mode gate that
|
|
208
|
+
// used to sit here made ordinary reviews judge methodology compliance blind.
|
|
231
209
|
// The base is derived inside the injector from this review's scope (the owning project of
|
|
232
210
|
// those paths) — NOT from `guideRoot`: the guide's root is the nearest AGENTS.md, which is a
|
|
233
211
|
// different question, and under a workspace anchor it is the anchor (no manifest ⇒ state 1).
|
|
234
|
-
|
|
235
|
-
|
|
212
|
+
// P1-4:对话背景与项目评审准则——设计评审判「需求覆盖」必须看到用户原话,
|
|
213
|
+
// 判「方法论合规」必须看到项目自己的准则(`.thincoder/advisor.md`)。与 code 分支同源同序。
|
|
214
|
+
const background = extractConversationBackground(flattenHistory(agent.history))
|
|
215
|
+
if (background) {
|
|
216
|
+
parts.push("## Conversation Background (recent turns)")
|
|
217
|
+
parts.push(background)
|
|
218
|
+
parts.push("")
|
|
236
219
|
}
|
|
220
|
+
const criteria = loadAdvisorMd(agent.cwd)
|
|
221
|
+
parts.push("## Review Criteria")
|
|
222
|
+
parts.push(criteria)
|
|
223
|
+
parts.push("")
|
|
224
|
+
|
|
225
|
+
injectProjectStandards(agent, parts, scopeFiles)
|
|
237
226
|
|
|
238
227
|
// Document map: derived from the manifest `docRoot` (declared roots' README, then their common
|
|
239
228
|
// ancestor); neither → explicit degradation sentence (never a silent skip). Same base as the
|
|
@@ -244,11 +233,11 @@ function buildAdvisorUserMessageInner(agent, prior, reviewType, designToken = nu
|
|
|
244
233
|
if (docList.length > 0) {
|
|
245
234
|
parts.push("1. Read every document in the Documents to Review list in full — review ONLY those files.")
|
|
246
235
|
} else {
|
|
247
|
-
parts.push("1.
|
|
236
|
+
parts.push("1. No review scope was given — state that in your findings instead of reading a guessed scope.")
|
|
248
237
|
}
|
|
249
|
-
parts.push("2. Review against: completeness (all requirements covered?), feasibility (can this be built?), methodology compliance (
|
|
238
|
+
parts.push("2. Review against: completeness (all requirements covered?), feasibility (can this be built?), methodology compliance (read the files listed under `## Project Standards` first, then judge against them?), clarity (specific enough?), acceptance criteria (verifiable?).")
|
|
250
239
|
parts.push("3. If the ## Project Guide (AGENTS.md) section above is present, also check requirement fit: does the design match what the requirements documents it points to actually ask for?")
|
|
251
|
-
parts.push("4. Do NOT run git diff or
|
|
240
|
+
parts.push("4. Do NOT run git diff or hunt for code changes — there are none at this stage. Reading code is allowed where a criterion needs it (feasibility, affected-file size).")
|
|
252
241
|
parts.push("5. If you find issues, produce your review table with the format: | # | Category | Severity | Issue | Suggestion |. If the design passes, no table is needed.")
|
|
253
242
|
// Round 2+: the prior review output and the agent's fix claims travel as
|
|
254
243
|
// REFERENCE — they keep the reviewer from re-reporting what is already fixed,
|
|
@@ -329,12 +318,11 @@ function buildAdvisorUserMessageInner(agent, prior, reviewType, designToken = nu
|
|
|
329
318
|
}
|
|
330
319
|
parts.push("")
|
|
331
320
|
|
|
332
|
-
//
|
|
333
|
-
//
|
|
334
|
-
// project
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
321
|
+
// Project standards (declaration-only, same helper as the design path) — undeclared degrades
|
|
322
|
+
// visibly (PO-2). **Unconditional**, for the same reason as the design path: the standards layer
|
|
323
|
+
// is a project-document face, not a mode feature. Base = this review's scope's owning project
|
|
324
|
+
// (same derivation as the document map), not `guideRoot`.
|
|
325
|
+
injectProjectStandards(agent, parts, scopeFiles)
|
|
338
326
|
|
|
339
327
|
// Instructions — round-aware: re-reviews skip convention discovery entirely.
|
|
340
328
|
// These are SUPPLEMENTARY reminders to the system prompt's numbered workflow —
|
|
@@ -40,6 +40,9 @@ export const NO_GUIDE_NOTICE = "(No AGENTS.md found — neither at the working d
|
|
|
40
40
|
|
|
41
41
|
/** Explicit degradation sentences (PORTABILITY design §4.4 — verbatim). */
|
|
42
42
|
export const NO_DOC_MAP_NOTICE = "(No document map found — no README.md under the declared document roots and none at their common ancestor — the Document ownership criterion is degraded: check placement against the Project Guide where present, and state the limitation in your findings.)"
|
|
43
|
+
/** 态 2 —— 数据档本身读抛(权限 / 目录等):与 `NO_DOC_MAP_NOTICE` 不同形,点名路径与原因(KD-M1-65 同族)。 */
|
|
44
|
+
export const DOC_MAP_UNREADABLE_NOTICE = ({ path, reason }) =>
|
|
45
|
+
`(The manifest at ${path} could not be read — ${reason}; the document map is unavailable and the Document ownership criterion is degraded. Fix the manifest — do NOT declare it again. State the limitation in your findings.)`
|
|
43
46
|
export const NO_STANDARDS_NOTICE = "(No project standards document — nothing in the project declares one — judge methodology compliance from the Project Guide (when present) and the review criteria above; state the limitation in your findings.)"
|
|
44
47
|
export const NO_GIT_NOTICE = "(No git repository detected — change-set context is unavailable; read the review-scope files directly.)"
|
|
45
48
|
|
|
@@ -66,7 +69,7 @@ export const STANDARDS_UNREADABLE_NOTICE = ({ path, reason }) =>
|
|
|
66
69
|
*/
|
|
67
70
|
export const STANDARDS_PARTIAL_NOTICE = ({ unreadable }) =>
|
|
68
71
|
`(Of the standards declared in the manifest, these could not be read — ${unreadable.join("; ")};\n` +
|
|
69
|
-
"the standard set above is INCOMPLETE. Fix them — do NOT declare them again. State the limitation in your findings.)"
|
|
72
|
+
"the standard set listed above is INCOMPLETE. Fix them — do NOT declare them again. State the limitation in your findings.)"
|
|
70
73
|
|
|
71
74
|
/**
|
|
72
75
|
* Discover the project root for the review — user decision 2026-08-08:
|
|
@@ -189,7 +192,7 @@ export function injectProjectGuide(agent, parts, scopeFiles = []) {
|
|
|
189
192
|
// 字段名归一:解析后的 provider 挂点两端其一(`provider` 本体字段 / `_provider` 运载字段)
|
|
190
193
|
// ——取在场者,两形态同语义(都指本回合生效的 provider 对象)。
|
|
191
194
|
const resolvedProvider = agent.provider ?? agent._provider
|
|
192
|
-
const ctx = providerSpec(resolvedProvider).context
|
|
195
|
+
const ctx = providerSpec(resolvedProvider, agent.config).context
|
|
193
196
|
const cap = Math.max(PROJECT_GUIDE_MIN, Math.floor(ctx * PROJECT_GUIDE_FRACTION))
|
|
194
197
|
const shown = text.length <= cap
|
|
195
198
|
? text
|
|
@@ -207,13 +210,24 @@ const DOC_ROOT_ORDER = ["design", "requirements", "specs", "modules", "batches"]
|
|
|
207
210
|
|
|
208
211
|
/** Declared document roots as ABSOLUTE paths, in declaration order (`null` / missing face ⇒ no root). */
|
|
209
212
|
function declaredDocRoots(base) {
|
|
210
|
-
|
|
213
|
+
// P1-6:数据档读抛(权限 / 目录等)⇒ 降级到默认声明,不中断消息组装。
|
|
214
|
+
// 可见降级由调用方(`injectDocumentMap` 的 `DOC_MAP_UNREADABLE_NOTICE`)承担——点名原因,
|
|
215
|
+
// 不与「没有任何东西声明」的 `NO_DOC_MAP_NOTICE` 同形。
|
|
216
|
+
let read
|
|
217
|
+
let readError = null
|
|
218
|
+
try {
|
|
219
|
+
read = readManifest(base)
|
|
220
|
+
} catch (e) {
|
|
221
|
+
readError = `manifest read failed: ${e?.code ?? "unknown"}`
|
|
222
|
+
console.warn(`[advisor] document-map manifest read failed at ${base}: ${e?.code ?? e?.message ?? "unknown"}`)
|
|
223
|
+
read = { ok: false, manifest: null }
|
|
224
|
+
}
|
|
211
225
|
const docRoot = (read.ok && read.manifest ? read.manifest : DEFAULT_MANIFEST).docRoot ?? {}
|
|
212
226
|
const out = []
|
|
213
227
|
for (const key of DOC_ROOT_ORDER) {
|
|
214
228
|
for (const p of docRootPaths(docRoot[key], base)) if (!out.includes(p)) out.push(p)
|
|
215
229
|
}
|
|
216
|
-
return out
|
|
230
|
+
return { roots: out, readError }
|
|
217
231
|
}
|
|
218
232
|
|
|
219
233
|
/** Common ancestor of every root (segment-wise — `docs/design` and `docs/designX` are not siblings).
|
|
@@ -243,15 +257,16 @@ function commonAncestor(paths) {
|
|
|
243
257
|
* @returns {string|null} absolute path of the map file, or null when degraded
|
|
244
258
|
*/
|
|
245
259
|
export function findDocumentMap(base) {
|
|
246
|
-
const roots = declaredDocRoots(base)
|
|
260
|
+
const { roots, readError } = declaredDocRoots(base)
|
|
261
|
+
if (readError) return { path: null, readError }
|
|
247
262
|
for (const r of roots) {
|
|
248
263
|
const p = join(r, "README.md")
|
|
249
|
-
if (existsSync(p)) return p
|
|
264
|
+
if (existsSync(p)) return { path: p, readError: null }
|
|
250
265
|
}
|
|
251
266
|
const ancestor = commonAncestor(roots)
|
|
252
|
-
if (!ancestor) return null
|
|
267
|
+
if (!ancestor) return { path: null, readError: null }
|
|
253
268
|
const p = join(ancestor, "README.md")
|
|
254
|
-
return existsSync(p) ? p : null
|
|
269
|
+
return { path: existsSync(p) ? p : null, readError: null }
|
|
255
270
|
}
|
|
256
271
|
|
|
257
272
|
/**
|
|
@@ -265,8 +280,13 @@ export function findDocumentMap(base) {
|
|
|
265
280
|
*/
|
|
266
281
|
export function injectDocumentMap(agent, parts, scopeFiles) {
|
|
267
282
|
const base = findProjectContextRoot(agent.cwd, scopeFiles) ?? agent.cwd
|
|
268
|
-
const mapPath = findDocumentMap(base)
|
|
283
|
+
const { path: mapPath, readError } = findDocumentMap(base)
|
|
269
284
|
parts.push("## Document Map")
|
|
285
|
+
if (readError) {
|
|
286
|
+
parts.push(DOC_MAP_UNREADABLE_NOTICE({ path: displayPath(manifestFilePath(base)), reason: readError }))
|
|
287
|
+
parts.push("")
|
|
288
|
+
return null
|
|
289
|
+
}
|
|
270
290
|
let text = null
|
|
271
291
|
if (mapPath) {
|
|
272
292
|
try {
|
|
@@ -299,13 +319,13 @@ const displayPath = (p) => String(p).replaceAll("\\", "/")
|
|
|
299
319
|
* (递归后裸文件名不再唯一;两种读法只在「子目录名是层根档名的前缀」时给出相反的序)。
|
|
300
320
|
* 嵌套根(一根本身在另一根之内)⇒ 同一份档按**解析后的绝对档路径**去重、保留首次出现(首次出现的层根定排序键);
|
|
301
321
|
* 去重键在 **win32 折小写**(尺子 = `pathKey`——同一目录的两种写法是同一个目录);折小写**只作用于去重键**,
|
|
302
|
-
*
|
|
303
|
-
*
|
|
322
|
+
* 排序键仍用盘上的原字符串(显示面另经 `displayPath` 归一 `/`)。
|
|
323
|
+
* 不去重则同一份档在路径清单里出现两次。
|
|
304
324
|
* @param {string[]} dirs — 声明目录的绝对路径(声明序;`docRootPaths` 已去重)
|
|
305
|
-
* @returns {{readable: {path: string
|
|
325
|
+
* @returns {{readable: {path: string}[], unreadable: {path: string, reason: string}[]}}
|
|
306
326
|
*/
|
|
307
327
|
function collectStandardDocs(dirs) {
|
|
308
|
-
const members = [] // { path, dirIndex, rel
|
|
328
|
+
const members = [] // { path, dirIndex, rel }——收完统一排序
|
|
309
329
|
const unreadable = []
|
|
310
330
|
dirs.forEach((dir, dirIndex) => {
|
|
311
331
|
// 逐目录四臂(判据 = §2.12「判据」块,逐臂对应):路径不存在 ∥ stat 抛 ∥ 不是目录 ∥ 列不出来。
|
|
@@ -340,7 +360,8 @@ function collectStandardDocs(dirs) {
|
|
|
340
360
|
mdSeen++
|
|
341
361
|
const p = join(here, ent.name)
|
|
342
362
|
try {
|
|
343
|
-
|
|
363
|
+
readFileSync(p, "utf8") // 只判可读性:态 3 只消费路径,正文读进来即弃(不保留 ⇒ 大层不占内存)
|
|
364
|
+
members.push({ path: p, dirIndex, rel })
|
|
344
365
|
} catch (e) {
|
|
345
366
|
unreadable.push({ path: p, reason: `read failed: ${e?.code ?? "unknown"}` })
|
|
346
367
|
}
|
|
@@ -359,7 +380,7 @@ function collectStandardDocs(dirs) {
|
|
|
359
380
|
const key = pathKey(resolve(m.path).replaceAll("\\", "/")) // 嵌套根 ∥ 同目录大小写两种写法:同一份档(win32 折小写)
|
|
360
381
|
if (seen.has(key)) continue // 保留首次出现(先出现的层根排在前面 ⇒ 排序键取它的层根)
|
|
361
382
|
seen.add(key)
|
|
362
|
-
readable.push({ path: m.path
|
|
383
|
+
readable.push({ path: m.path })
|
|
363
384
|
}
|
|
364
385
|
return { readable, unreadable }
|
|
365
386
|
}
|
|
@@ -370,6 +391,11 @@ function collectStandardDocs(dirs) {
|
|
|
370
391
|
* 标准层(`docRoot.standards`)= 一个**文档层(目录)**,不是一份档:层内成员 = 该目录**及其全部子目录**下的 `.md`
|
|
371
392
|
* (大小写不敏感),按**层根相对路径**码点序;符号链接一律不跟(KD-M1-63)。
|
|
372
393
|
*
|
|
394
|
+
* **态 3 是「按需读」,不是「贴正文」。** 标准层是**项目文档**,不是提示词:把它的正文拼进评审消息,等于把
|
|
395
|
+
* 「这个项目的规矩」烧进「产品对模型说的话」——换一个项目,那段正文全是错的,而它还会被当成产品的通用规则。
|
|
396
|
+
* 评审席手里有 `read`,指路即可(`PROMPT-SYSTEM.md` §8.7 三层落点:能由运行时送达的信息不靠常驻文本)。
|
|
397
|
+
* 不贴正文就没有截断:旧态 3 的预算帽与截断指针一并删去。
|
|
398
|
+
*
|
|
373
399
|
* 三态(**可机判互异**,本面立身之本 = 用声明、不猜固定名):
|
|
374
400
|
* 态 1 未声明 —— `docRoot.standards` 缺键 / `null` / 一个目录都没得来 ⇒ `NO_STANDARDS_NOTICE`
|
|
375
401
|
* (零路径字面、零 `declared`)。
|
|
@@ -377,7 +403,8 @@ function collectStandardDocs(dirs) {
|
|
|
377
403
|
* 绝对路径 + 原因)。绝不与态 1 同形。原因取值域 = `no such directory` ∥ `not a directory` ∥
|
|
378
404
|
* `no .md file` ∥ `read failed: <code>` ∥ `manifest read failed: <code>`——三类可修面不同
|
|
379
405
|
* (改路径 ∥ 改形态 ∥ 往层里放档;KD-M1-65)。
|
|
380
|
-
* 态 3 读到 ——
|
|
406
|
+
* 态 3 读到 —— 逐档一行绝对路径 + 一句读指令(目录序 + 层根相对路径码点序);部分读不到时路径清单在前、
|
|
407
|
+
* 半读句逐项点名不可读者。**正文不在场**——评审自己去读。
|
|
381
408
|
*
|
|
382
409
|
* 取值源 = `read.ok && read.manifest ? read.manifest : DEFAULT_MANIFEST`(同 `declaredDocRoots` 先例,
|
|
383
410
|
* 不另立第二套判定)⇒ 整档缺失 / 非法一律 `std === null` ⇒ 态 1;`dirs.length === 0 ⇒ 态 1` 是硬不
|
|
@@ -415,7 +442,7 @@ export function injectProjectStandards(agent, parts, scopeFiles) {
|
|
|
415
442
|
return null
|
|
416
443
|
}
|
|
417
444
|
|
|
418
|
-
// 遍历 ∥ 排序 ∥ 嵌套去重全在 `collectStandardDocs
|
|
445
|
+
// 遍历 ∥ 排序 ∥ 嵌套去重全在 `collectStandardDocs`(本函数只留三态组装与路径清单——可读单元不变)。
|
|
419
446
|
const { readable, unreadable } = collectStandardDocs(dirs)
|
|
420
447
|
// 态 2:声明了,一份都读不到(句中路径 = 不可读集第一项——目录项与文件项同形)。
|
|
421
448
|
if (readable.length === 0) {
|
|
@@ -424,36 +451,13 @@ export function injectProjectStandards(agent, parts, scopeFiles) {
|
|
|
424
451
|
return null
|
|
425
452
|
}
|
|
426
453
|
|
|
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.")
|
|
454
|
+
// 态 3:**按需读**——只给路径与读指令,不贴正文(理由见函数头注)。
|
|
455
|
+
parts.push("The project declares a standards layer — the `.md` files listed below are the project's own rules. Read them before judging methodology compliance; their text is not repeated here.")
|
|
430
456
|
parts.push("")
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
// 预算算式复用同两条常量、**逐注入独立计算**(不与指南共享池——两面语义不同,不该互相记账)。
|
|
434
|
-
// providerSpec 取值在 body 之外算:上下文规格查不到也不得伪装成「没有标准档」。
|
|
435
|
-
const resolvedProvider = agent.provider ?? agent._provider
|
|
436
|
-
const ctx = providerSpec(resolvedProvider).context
|
|
437
|
-
const cap = Math.max(PROJECT_GUIDE_MIN, Math.floor(ctx * PROJECT_GUIDE_FRACTION))
|
|
438
|
-
let shown = body
|
|
439
|
-
// 计量与切片**同一单位**(码点):两条口径混用会让含星平面字符(emoji / 生僻字)的标准档在
|
|
440
|
-
// 「其实全给了」时也报 PARTIAL、并给出 truncated at N of M 的假读数(M 是 UTF-16 长度)。
|
|
441
|
-
const chars = [...body]
|
|
442
|
-
if (chars.length > cap) {
|
|
443
|
-
// 被截断的那一份(拼接期已有逐份偏移;偏移同以码点计)——恢复指针必须指向它,否则评审拿着残缺规矩判。
|
|
444
|
-
let offset = 0
|
|
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 }
|
|
449
|
-
offset += len + 2 // +2 = 拼接分隔符 "\n\n"
|
|
450
|
-
}
|
|
451
|
-
// 截断的风险不在大小,在**静默**:指南截断丢的是指针,标准层截断丢的是判据本身。
|
|
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)`
|
|
453
|
-
}
|
|
454
|
-
parts.push(shown)
|
|
455
|
-
// 半读句:正文在前,缺口逐项点名(零静默——KD-M1-65)。
|
|
457
|
+
for (const r of readable) parts.push(`- ${displayPath(r.path)}`)
|
|
458
|
+
// 半读句:路径清单在前,缺口逐项点名(零静默——KD-M1-65)。
|
|
456
459
|
if (unreadable.length > 0) {
|
|
460
|
+
parts.push("")
|
|
457
461
|
parts.push(STANDARDS_PARTIAL_NOTICE({ unreadable: unreadable.map((u) => `${displayPath(u.path)}: ${u.reason}`) }))
|
|
458
462
|
}
|
|
459
463
|
parts.push("")
|