@thincoder/core 0.11.4 → 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 +33 -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 +22 -41
- 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/agent/planning-step.mjs
CHANGED
|
@@ -1,25 +1,63 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* agent/planning-step.mjs — Harness 驱动的独立「Planning next moves」规划步(AGENT-LOOP.md §7.3)。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* 目标:补齐轻量推理模型在长链路/复杂任务中容易隧道视野、盲从评审或过度工程的短板——由 Harness 在高价值节点
|
|
5
|
+
* (开局 / 评审结论核实 / 设计席交付复查 / 异步消化与阶段复盘 / 压缩重定锚 / 连续报错 / 连续排障探测 / 长循环防跑偏 / 用户插话重定锚)
|
|
6
|
+
* 主动插入 1 轮受控规划调用:
|
|
6
7
|
* - 请求参数与常规 `callModelTurn` 保持 100% 一致(同 `provider`、同 `tools`、不发 `tool_choice: "none"`,避免服务端切换模板分裂 KV 前缀缓存),
|
|
7
|
-
* 经 `prompts/planning-next-moves.md`
|
|
8
|
+
* 经 `prompts/planning-next-moves.md` 禁调任何工具并在代码层忽略一切返回的 `toolCalls`(零工具调用副作用);主会话普通模式下仅解析并剥离规划正文末尾的 `<task_sync>{...}</task_sync>` 标签静默同步内存任务清单;
|
|
8
9
|
* - 默认复用当前会话 provider 与 `assembleRequestMessages` 完整前缀(KV Prefix Cache 高命中);
|
|
9
10
|
* - 支持通过 `agent.planningNextMoves.model` / `reasoningEffort` 单独配置更强规划模型或更高思考力度;
|
|
10
11
|
* - 输出(含思考流与最终规划正文)经 `onReasoning(chunk, { phase: "planning", trigger })` 实时流向三端独立「Planning next moves」块,
|
|
11
12
|
* 并通过 B 段 `pushInject` 注入紧随其后的执行轮(不污染永久历史,失败时优雅降级不阻断主循环)。
|
|
12
13
|
*/
|
|
13
|
-
import {
|
|
14
|
-
import { join } from "node:path"
|
|
14
|
+
import { isAbsolute, join } from "node:path"
|
|
15
15
|
|
|
16
|
-
import { PROMPTS_DIR } from "../prompt-files.mjs"
|
|
17
16
|
import { chat } from "../provider/index.mjs"
|
|
18
17
|
import { parseModelRef, DEFAULTS } from "../config.mjs"
|
|
19
|
-
import { assembleRequestMessages, pushInject } from "../context.mjs"
|
|
18
|
+
import { assembleRequestMessages, flattenHistory, pushInject } from "../context.mjs"
|
|
20
19
|
import { FILE_MUTATORS } from "./helpers.mjs"
|
|
21
20
|
import { isWebSearchTool, preferredWebSearchTool } from "./setup-reminders.mjs"
|
|
22
|
-
import {
|
|
21
|
+
import { createTaskSyncStreamFilter, extractAndApplyPlanningTaskSync } from "./task-lifecycle.mjs"
|
|
22
|
+
import { addGoalTokens } from "./goal-state.mjs"
|
|
23
|
+
import { isBashCodeFragmentCommand } from "../tools/bash.mjs"
|
|
24
|
+
import {
|
|
25
|
+
CODE_FILE_RE,
|
|
26
|
+
DOC_FILE_RE,
|
|
27
|
+
GRAPH_PASSIVE_SEARCH_TOOLS,
|
|
28
|
+
MAX_GRAPH_SEED_FILES,
|
|
29
|
+
filterGraphMissing,
|
|
30
|
+
filterSeedsByLayer,
|
|
31
|
+
graphRawSignature,
|
|
32
|
+
mergedGraphFullRead,
|
|
33
|
+
normalizeRelPath,
|
|
34
|
+
noteReadFootprint,
|
|
35
|
+
resultCodePaths,
|
|
36
|
+
} from "./planning-graph-guardrail.mjs"
|
|
37
|
+
import {
|
|
38
|
+
PLAN_DRIFT_WARN_STRIDE,
|
|
39
|
+
PLAN_DRIFT_WARN_TURN,
|
|
40
|
+
TRIGGER_LABELS,
|
|
41
|
+
buildPlanningPromptMessage,
|
|
42
|
+
buildToolRouting,
|
|
43
|
+
capPlanTextForInject,
|
|
44
|
+
describeAdvisorScope,
|
|
45
|
+
loadPlanningChecklist,
|
|
46
|
+
summarizeGoalForAnchor,
|
|
47
|
+
} from "./planning-prompt.mjs"
|
|
48
|
+
|
|
49
|
+
// 公开面原样再导出:既有 importer(`turn-loop.mjs` / `post-turn.mjs` / `run-stages.mjs` / `run-start.mjs`)不变。
|
|
50
|
+
export {
|
|
51
|
+
PLAN_INJECT_MAX_CHARS,
|
|
52
|
+
PLAN_REASONING_FALLBACK_MAX_CHARS,
|
|
53
|
+
PLAN_DRIFT_WARN_TURN,
|
|
54
|
+
buildPlanningPromptMessage,
|
|
55
|
+
buildToolRouting,
|
|
56
|
+
capPlanTextForInject,
|
|
57
|
+
loadPlanningChecklist,
|
|
58
|
+
summarizeGoalForAnchor,
|
|
59
|
+
} from "./planning-prompt.mjs"
|
|
60
|
+
export { injectPassiveGraphReadingPack } from "./planning-graph-guardrail.mjs"
|
|
23
61
|
|
|
24
62
|
/**
|
|
25
63
|
* 规划步默认值。源单点 = `config-defaults.mjs` 的 `DEFAULTS.agent.planningNextMoves`(经 `config.mjs` re-export);
|
|
@@ -27,64 +65,68 @@ import { buildPlanningTaskHint } from "./task-lifecycle.mjs"
|
|
|
27
65
|
*/
|
|
28
66
|
export const PLANNING_DEFAULTS = Object.freeze({ ...DEFAULTS.agent.planningNextMoves })
|
|
29
67
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
68
|
+
const SYNTHETIC_USER_PREFIX_RE = /^\s*\[(?:System reminder:|Async result:|User interrupt:)/i
|
|
69
|
+
|
|
70
|
+
/** 从历史中逆向提取最近一条真实用户输入(跳过系统提醒/异步结果注入),供异步消化轮与定时唤醒轮锚定主目标。 */
|
|
71
|
+
export function extractLastRealUserGoal(history) {
|
|
72
|
+
const flat = flattenHistory(history)
|
|
73
|
+
for (let i = flat.length - 1; i >= 0; i--) {
|
|
74
|
+
const m = flat[i]
|
|
75
|
+
if (m?.role !== "user") continue
|
|
76
|
+
const text = typeof m.content === "string"
|
|
77
|
+
? m.content
|
|
78
|
+
: Array.isArray(m.content)
|
|
79
|
+
? m.content.map((p) => (typeof p?.text === "string" ? p.text : "")).join("\n")
|
|
80
|
+
: ""
|
|
81
|
+
const clean = text.trim()
|
|
82
|
+
if (!clean || SYNTHETIC_USER_PREFIX_RE.test(clean)) continue
|
|
83
|
+
return clean
|
|
84
|
+
}
|
|
85
|
+
return ""
|
|
41
86
|
}
|
|
42
87
|
|
|
43
88
|
/** 诊断/探针类工具集合(`ssh` 仅 `send`/`read`/缺省算探针,`connect`/`put`/`get`/`disconnect` 不计入)。 */
|
|
44
89
|
export const DIAG_PROBE_TOOLS = new Set(["ssh", "bash", "read_history", "process"])
|
|
45
90
|
const SSH_NON_PROBE_ACTIONS = new Set(["connect", "put", "get", "disconnect", "close", "list"])
|
|
46
91
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
milestone: "上一轮刚收回子代理/分叉调研的结果:不要照单全收也不要草率略过,先对照原目标、项目文档与实盘核验关键结论、挑出尚未闭环的分歧或遗漏,再定下一步是修偏还是推进。",
|
|
61
|
-
error: "同一方向已连续失败:禁止微调参数盲目重试——先从报错原文判断是前提错了、状态变了还是用法不对;需要时立刻查项目文档核对约束或上网查该报错/工具的一手文档与已知 bug,再换路径推进。",
|
|
62
|
-
probe: "已连续多轮跑本地探针却仍未定根因或改盘——警惕隧道视野!先跳出当前命令链做两件事:① 立刻查本项目相关文档核对前置约定,并上网搜外部软件/引擎/硬件/驱动的已知 issue 与官方文档(不要从零硬猜);② 设计能一次区分两个竞争假设的对照实验,而不是继续打同类探针。",
|
|
63
|
-
compaction: "上下文刚经过压缩,细节可能已被折叠:先重新对齐用户原始目标、已证伪的死路(避免重踩)以及尚未核查的项目文档或未落盘/未验证挂账,再定接下来最关键的推进动作。",
|
|
64
|
-
interval: "本回合已连续执行多轮工具:先对照用户原始任务检查有没有被支线技术细节带偏,只补会直接推进核心交付的关键缺口,非阻塞旁枝只记备忘不深挖。",
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
let _cachedChecklist = null
|
|
68
|
-
/** 读取 `prompts/planning-next-moves.md` 检查单(允许单测传入覆写路径)。 */
|
|
69
|
-
export function loadPlanningChecklist(filePath = join(PROMPTS_DIR, "planning-next-moves.md")) {
|
|
70
|
-
if (filePath === join(PROMPTS_DIR, "planning-next-moves.md") && _cachedChecklist !== null) return _cachedChecklist
|
|
71
|
-
const text = readFileSync(filePath, "utf8").trim()
|
|
72
|
-
if (filePath === join(PROMPTS_DIR, "planning-next-moves.md")) _cachedChecklist = text
|
|
73
|
-
return text
|
|
92
|
+
function parseToolArgs(rawArgs) {
|
|
93
|
+
if (!rawArgs) return null
|
|
94
|
+
if (typeof rawArgs === "string") {
|
|
95
|
+
try { return JSON.parse(rawArgs) } catch { return null }
|
|
96
|
+
}
|
|
97
|
+
return typeof rawArgs === "object" ? rawArgs : null
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** 判定单条工具执行结果是否属于「用 bash 切片抓源码碎片」。 */
|
|
101
|
+
export function isBashCodeFragmentCall(result) {
|
|
102
|
+
if ((result?.toolCall?.name ?? "") !== "bash") return false
|
|
103
|
+
const parsed = parseToolArgs(result?.toolCall?.arguments)
|
|
104
|
+
return isBashCodeFragmentCommand(parsed?.command ?? "")
|
|
74
105
|
}
|
|
75
106
|
|
|
76
|
-
|
|
107
|
+
const ROUTINE_VERIFY_CMD_RE = /^(?:(?:cd\s+(?:"[^"]+"|'[^']+'|\S+)\s*(?:&&|;)\s*)|(?:[A-Za-z_][A-Za-z0-9_]*=(?:"[^"]*"|'[^']*'|\S+)\s+))*(?:node\s+--test\b|(?:npm|pnpm|yarn|bun)\s+(?:test|run\s+(?:test|build|lint|check|typecheck|verify)\b)|(?:npx|pnpm\s+exec)\s+(?:vitest|jest|mocha|tsc|eslint)\b|(?:vitest|jest|mocha|pytest|tsc|eslint)\b|go\s+test\b|cargo\s+(?:test|check|build|clippy)\b|dotnet\s+(?:test|build)\b|(?:mvn|gradle|gradlew)\s+(?:test|check|build)\b|git\s+(?:status|diff|log|show|rev-parse|branch)\b)/i
|
|
108
|
+
|
|
109
|
+
/** 判定 bash 命令是否属于常规本地测试/构建/只读校验(非外部环境排障探针)。 */
|
|
110
|
+
export function isRoutineVerificationCommand(command) {
|
|
111
|
+
const s = String(command ?? "").trim()
|
|
112
|
+
if (!s) return false
|
|
113
|
+
return ROUTINE_VERIFY_CMD_RE.test(s)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 判定单条工具执行结果是否属于「诊断探针类调用」(`ssh` 连接/文件传输/断开、用 `bash` 切片读源码、常规本地测试/构建/git 状态均不计入)。 */
|
|
77
117
|
export function isDiagnosticProbeCall(result) {
|
|
78
118
|
const name = result?.toolCall?.name ?? ""
|
|
79
119
|
if (!DIAG_PROBE_TOOLS.has(name)) return false
|
|
80
|
-
if (name
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
try { parsed = JSON.parse(rawArgs) } catch { return true }
|
|
120
|
+
if (name === "bash") {
|
|
121
|
+
if (isBashCodeFragmentCall(result)) return false
|
|
122
|
+
const parsed = parseToolArgs(result?.toolCall?.arguments)
|
|
123
|
+
if (isRoutineVerificationCommand(parsed?.command)) return false
|
|
124
|
+
return true
|
|
86
125
|
}
|
|
87
|
-
|
|
126
|
+
if (name !== "ssh") return true
|
|
127
|
+
const parsed = parseToolArgs(result?.toolCall?.arguments)
|
|
128
|
+
if (!parsed) return true
|
|
129
|
+
const action = typeof parsed.action === "string" ? parsed.action.trim().toLowerCase() : ""
|
|
88
130
|
return !SSH_NON_PROBE_ACTIONS.has(action)
|
|
89
131
|
}
|
|
90
132
|
|
|
@@ -92,7 +134,10 @@ export function isDiagnosticProbeCall(result) {
|
|
|
92
134
|
export function isToolResultError(result) {
|
|
93
135
|
if (!result) return false
|
|
94
136
|
if (result.ok === false) return true
|
|
95
|
-
|
|
137
|
+
const text = typeof result.result === "string"
|
|
138
|
+
? result.result
|
|
139
|
+
: (typeof result.output === "string" ? result.output : "")
|
|
140
|
+
if (text && /^Error:/i.test(text.trim())) return true
|
|
96
141
|
return false
|
|
97
142
|
}
|
|
98
143
|
|
|
@@ -100,15 +145,14 @@ export function isToolResultError(result) {
|
|
|
100
145
|
export function extractAdvisorReviewType(result) {
|
|
101
146
|
if (!result || isToolResultError(result)) return null
|
|
102
147
|
if ((result?.toolCall?.name ?? "") !== "advisor") return null
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (typeof rawArgs === "string") {
|
|
110
|
-
try { parsed = JSON.parse(rawArgs) } catch { parsed = null }
|
|
148
|
+
const text = typeof result.result === "string"
|
|
149
|
+
? result.result
|
|
150
|
+
: (typeof result.output === "string" ? result.output : "")
|
|
151
|
+
if (text) {
|
|
152
|
+
if (/^\s*Advisor:\s*(?:launch refused|async is required|async reviews are only available|review failure)/i.test(text)) return null
|
|
153
|
+
if (/review started in the background|launched in background/i.test(text)) return null
|
|
111
154
|
}
|
|
155
|
+
const parsed = parseToolArgs(result?.toolCall?.arguments)
|
|
112
156
|
if (parsed?.async === true) return null
|
|
113
157
|
const t = typeof parsed?.type === "string" ? parsed.type.trim().toLowerCase() : ""
|
|
114
158
|
return t === "design" || t === "code" ? t : "unknown"
|
|
@@ -119,40 +163,73 @@ export function isAdvisorReviewCall(result) {
|
|
|
119
163
|
return extractAdvisorReviewType(result) !== null
|
|
120
164
|
}
|
|
121
165
|
|
|
122
|
-
/**
|
|
166
|
+
/** 判定单条工具执行结果是否属于同步阻塞的 `eng-designer` 交付返回(异步 ack 与报错不计)。 */
|
|
167
|
+
export function isEngDesignerToolCall(result) {
|
|
168
|
+
if (!result || isToolResultError(result)) return false
|
|
169
|
+
if ((result?.toolCall?.name ?? "") !== "subagent") return false
|
|
170
|
+
const parsed = parseToolArgs(result?.toolCall?.arguments)
|
|
171
|
+
const action = typeof parsed?.action === "string" && parsed.action.trim() ? parsed.action.trim().toLowerCase() : "spawn"
|
|
172
|
+
const role = typeof parsed?.role === "string" ? parsed.role.trim().toLowerCase() : ""
|
|
173
|
+
return action === "spawn" && role === "eng-designer" && parsed?.async === false
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** 判定单条工具执行结果是否属于非评审/非设计席类阶段拐点(`step` / 其余同步阻塞 `subagent`;异步启动 ack 不算)。 */
|
|
123
177
|
export function isMilestoneToolCall(result) {
|
|
124
178
|
if (!result || isToolResultError(result)) return false
|
|
125
179
|
const name = result?.toolCall?.name ?? ""
|
|
126
180
|
if (name === "step") return true
|
|
127
181
|
if (name !== "subagent") return false
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (typeof rawArgs === "string") {
|
|
131
|
-
try { parsed = JSON.parse(rawArgs) } catch { parsed = null }
|
|
132
|
-
}
|
|
182
|
+
if (isEngDesignerToolCall(result)) return false
|
|
183
|
+
const parsed = parseToolArgs(result?.toolCall?.arguments)
|
|
133
184
|
const action = typeof parsed?.action === "string" && parsed.action.trim() ? parsed.action.trim().toLowerCase() : "spawn"
|
|
134
185
|
return (action === "spawn" || action === "escalate") && parsed?.async === false
|
|
135
186
|
}
|
|
136
187
|
|
|
137
188
|
/**
|
|
138
|
-
*
|
|
189
|
+
* 分类一条真正投递进模型上下文的异步结果条目(调用点 = `deliverSettledAsync` / `collectSettledAsync`):
|
|
190
|
+
* - 已取消条目返回 `null`(未交付);
|
|
191
|
+
* - 有效 `advisor` 评审(非报错、非 `Advisor: review failure`)→ `{ kind: "advisor", role: "advisor", reviewType }`;
|
|
192
|
+
* - 有效 `eng-designer` 交付(非报错)→ `{ kind: "engDesigner", role: "eng-designer" }`;
|
|
193
|
+
* - 其余异步结果(`explore`/`eng-coder`/`escalate`/`consult`/`bg`/`browser` 或失败的评审/设计席)→ `{ kind: "async", role, ok }`。
|
|
194
|
+
*/
|
|
195
|
+
export function classifyDeliveredAsync(entry) {
|
|
196
|
+
if (!entry || entry.cancelled === true) return null
|
|
197
|
+
const role = typeof entry.role === "string" && entry.role.trim() ? entry.role.trim() : "subagent"
|
|
198
|
+
const hasErr = entry.error != null
|
|
199
|
+
if (role === "advisor") {
|
|
200
|
+
const isReviewFailure = typeof entry.report === "string" && /^\s*Advisor:\s*review failure/i.test(entry.report)
|
|
201
|
+
if (!hasErr && !isReviewFailure) {
|
|
202
|
+
const t = entry.reviewType === "design" || entry.reviewType === "code" ? entry.reviewType : "unknown"
|
|
203
|
+
return { kind: "advisor", role: "advisor", reviewType: t }
|
|
204
|
+
}
|
|
205
|
+
return { kind: "async", role: "advisor", ok: false }
|
|
206
|
+
}
|
|
207
|
+
if (role === "eng-designer") {
|
|
208
|
+
if (!hasErr) return { kind: "engDesigner", role: "eng-designer" }
|
|
209
|
+
return { kind: "async", role: "eng-designer", ok: false }
|
|
210
|
+
}
|
|
211
|
+
return { kind: "async", role, ok: !hasErr }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 解析当前回合生效的规划步配置;不适用(未显式配置、已禁用、子代理、plan 模式、子代理上行问询轮 `upstreamTurn`)返回 `null`。
|
|
216
|
+
* `tiny` / `normal` / `engineering` 三档主会话(`depth === 0`)均默认启用规划步。
|
|
139
217
|
* 注意:真实会话经 `loadConfig()` 合并 `DEFAULTS.agent.planningNextMoves`(默认 `enabled: true`);
|
|
140
218
|
* 手工拼装极简 `config: { agent: { maxTurns } }` 的测试夹具未带该键 ⇒ 返回 `null`,不打乱脚本化桩序列。
|
|
141
|
-
*
|
|
219
|
+
* 常规异步消化轮(`autoTurn: true, upstreamTurn: false`)与定时唤醒轮(`timerTurn: true`)均完整放行(不再锁死在 `advisorOnly`),
|
|
220
|
+
* 首轮按投递来源单列触发,后续工具轮正常享有压缩/里程碑/连错/连探针/周期防跑偏规划。
|
|
142
221
|
*/
|
|
143
|
-
export function resolvePlanningConfig(agent, {
|
|
222
|
+
export function resolvePlanningConfig(agent, {
|
|
223
|
+
depth = 0, autoTurn = false, upstreamTurn = false, timerTurn = false,
|
|
224
|
+
} = {}) {
|
|
144
225
|
if (depth !== 0 || upstreamTurn) return null
|
|
145
|
-
if (
|
|
226
|
+
if (agent?.planMode === true) return null
|
|
146
227
|
const raw = agent?.config?.agent?.planningNextMoves
|
|
147
228
|
if (!raw || raw === false) return null
|
|
148
229
|
const obj = typeof raw === "object" && !Array.isArray(raw) ? raw : {}
|
|
149
230
|
const merged = { ...PLANNING_DEFAULTS, ...obj }
|
|
150
231
|
if (merged.enabled !== true) return null
|
|
151
|
-
|
|
152
|
-
if (!hasAdvisorDelivery || merged.onAdvisor !== true) return null
|
|
153
|
-
return { ...merged, advisorOnly: true }
|
|
154
|
-
}
|
|
155
|
-
return merged
|
|
232
|
+
return { ...merged, autoTurn: Boolean(autoTurn), timerTurn: Boolean(timerTurn) }
|
|
156
233
|
}
|
|
157
234
|
|
|
158
235
|
/** 开局规划判据:不再按任务复杂度筛选,任意非空用户输入在首轮前一律先做开局规划。 */
|
|
@@ -165,17 +242,30 @@ export function shouldPlanOnStart(input) {
|
|
|
165
242
|
export function isTimerSetCall(result) {
|
|
166
243
|
if (!result || isToolResultError(result)) return false
|
|
167
244
|
if ((result?.toolCall?.name ?? "") !== "timer") return false
|
|
168
|
-
const
|
|
169
|
-
let parsed = rawArgs
|
|
170
|
-
if (typeof rawArgs === "string") {
|
|
171
|
-
try { parsed = JSON.parse(rawArgs) } catch { parsed = null }
|
|
172
|
-
}
|
|
245
|
+
const parsed = parseToolArgs(result?.toolCall?.arguments)
|
|
173
246
|
if (parsed && (parsed.list === true || parsed.cancel !== undefined)) return false
|
|
174
247
|
return true
|
|
175
248
|
}
|
|
176
249
|
|
|
177
|
-
/**
|
|
178
|
-
export function createPlanningState({ advisorReviewTypes = [] } = {}) {
|
|
250
|
+
/** 创建单次回合(run)内的规划步追踪状态;从投递清单 `deliveredAsync` 初始化评审/设计席/异步消化触发位。 */
|
|
251
|
+
export function createPlanningState({ deliveredAsync = [], advisorReviewTypes = [] } = {}) {
|
|
252
|
+
const advisorTypes = []
|
|
253
|
+
let engDesignerHit = false
|
|
254
|
+
const asyncDeliveredRoles = []
|
|
255
|
+
const addAdvisor = (t) => {
|
|
256
|
+
const norm = t === "design" || t === "code" ? t : "unknown"
|
|
257
|
+
if (!advisorTypes.includes(norm)) advisorTypes.push(norm)
|
|
258
|
+
}
|
|
259
|
+
for (const t of Array.isArray(advisorReviewTypes) ? advisorReviewTypes : []) addAdvisor(t)
|
|
260
|
+
for (const item of Array.isArray(deliveredAsync) ? deliveredAsync : []) {
|
|
261
|
+
if (!item) continue
|
|
262
|
+
if (item.kind === "advisor") addAdvisor(item.reviewType)
|
|
263
|
+
else if (item.kind === "engDesigner") engDesignerHit = true
|
|
264
|
+
else if (item.kind === "async") {
|
|
265
|
+
const role = typeof item.role === "string" && item.role.trim() ? item.role.trim() : "subagent"
|
|
266
|
+
if (!asyncDeliveredRoles.includes(role)) asyncDeliveredRoles.push(role)
|
|
267
|
+
}
|
|
268
|
+
}
|
|
179
269
|
return {
|
|
180
270
|
runsUsed: 0,
|
|
181
271
|
turnsSincePlan: 0,
|
|
@@ -184,15 +274,54 @@ export function createPlanningState({ advisorReviewTypes = [] } = {}) {
|
|
|
184
274
|
searched: false,
|
|
185
275
|
justCompacted: false,
|
|
186
276
|
milestoneHit: false,
|
|
187
|
-
|
|
277
|
+
engDesignerHit,
|
|
278
|
+
advisorReviewTypes: advisorTypes,
|
|
279
|
+
asyncDeliveredRoles,
|
|
280
|
+
bashCodeReadCount: 0,
|
|
281
|
+
keyholeReadCount: 0,
|
|
282
|
+
fullReadFiles: new Set(),
|
|
283
|
+
touchedCodeFiles: new Set(),
|
|
284
|
+
primaryTargetFiles: new Set(),
|
|
285
|
+
guardSuggestedPaths: new Set(),
|
|
286
|
+
graphRemindedCounts: new Map(),
|
|
287
|
+
graphPassivePending: false,
|
|
288
|
+
graphLastPassiveSignature: "",
|
|
289
|
+
hasReadDocs: false,
|
|
290
|
+
hasReadCode: false,
|
|
291
|
+
hasMutatedFiles: false,
|
|
292
|
+
mutatedCodeFiles: false,
|
|
293
|
+
usedSsh: false,
|
|
188
294
|
justSetTimer: false,
|
|
295
|
+
// 用户在回合进行中被步边界 pickup 到一条排队消息 ⇒ 下一轮规划步按「插话」触发一次(只清本次消费)。
|
|
296
|
+
queuedInputHit: false,
|
|
189
297
|
// 上一次规划步失败的轮号(-1 = 未失败);轮头据此跳过后紧随其后的那一轮,避免连打注定失败的调用。
|
|
190
298
|
lastPlanFailTurn: -1,
|
|
299
|
+
// 上一次附带长偏航核对提醒的轮号(-1 = 未提醒),防止长任务里每次规划重复刷屏同一段提醒。
|
|
300
|
+
lastDriftWarnTurn: -1,
|
|
191
301
|
}
|
|
192
302
|
}
|
|
193
303
|
|
|
194
|
-
/**
|
|
195
|
-
export function
|
|
304
|
+
/** 撞帽续跑段(`resume: true`)沿用上一段规划步记忆,只合并本段新投递的异步结果并复位段内局部轮计数。 */
|
|
305
|
+
export function mergePlanningContinuationState(state, { deliveredAsync = [], advisorReviewTypes = [] } = {}) {
|
|
306
|
+
if (!state) return createPlanningState({ deliveredAsync, advisorReviewTypes })
|
|
307
|
+
const fresh = createPlanningState({ deliveredAsync, advisorReviewTypes })
|
|
308
|
+
if (!Array.isArray(state.advisorReviewTypes)) state.advisorReviewTypes = []
|
|
309
|
+
for (const t of fresh.advisorReviewTypes) {
|
|
310
|
+
if (!state.advisorReviewTypes.includes(t)) state.advisorReviewTypes.push(t)
|
|
311
|
+
}
|
|
312
|
+
if (fresh.engDesignerHit) state.engDesignerHit = true
|
|
313
|
+
if (!Array.isArray(state.asyncDeliveredRoles)) state.asyncDeliveredRoles = []
|
|
314
|
+
for (const r of fresh.asyncDeliveredRoles) {
|
|
315
|
+
if (!state.asyncDeliveredRoles.includes(r)) state.asyncDeliveredRoles.push(r)
|
|
316
|
+
}
|
|
317
|
+
state.turnsSincePlan = 0
|
|
318
|
+
state.justSetTimer = false
|
|
319
|
+
state.lastPlanFailTurn = -1
|
|
320
|
+
return state
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** 每轮工具执行后更新规划步状态(累计轮数、纯探针连击、连续报错、评审结论、设计席交付、阶段拐点与定时唤醒让出)。 */
|
|
324
|
+
export function recordPlanningTurnOutcome(state, { results = [], toolByName = null, tools = [], cwd = null, sessionFullReadFiles = null } = {}) {
|
|
196
325
|
if (!state) return
|
|
197
326
|
const list = Array.isArray(results) ? results : []
|
|
198
327
|
if (list.length === 0) {
|
|
@@ -203,15 +332,81 @@ export function recordPlanningTurnOutcome(state, { results = [], toolByName = nu
|
|
|
203
332
|
|
|
204
333
|
let allProbe = true
|
|
205
334
|
let hadError = false
|
|
335
|
+
let hitEngDesigner = false
|
|
206
336
|
let hitMilestone = false
|
|
207
337
|
let setTimer = false
|
|
338
|
+
let usedBashCodeRead = false
|
|
339
|
+
let usedKeyholeRead = false
|
|
340
|
+
let usedFullCodeRead = false
|
|
341
|
+
let usedProperLookup = false
|
|
342
|
+
if (!(state.fullReadFiles instanceof Set)) state.fullReadFiles = new Set()
|
|
343
|
+
if (!(state.touchedCodeFiles instanceof Set)) state.touchedCodeFiles = new Set()
|
|
344
|
+
if (!(state.primaryTargetFiles instanceof Set)) state.primaryTargetFiles = new Set()
|
|
345
|
+
if (!(state.guardSuggestedPaths instanceof Set)) state.guardSuggestedPaths = new Set()
|
|
346
|
+
if (!(state.graphRemindedCounts instanceof Map)) state.graphRemindedCounts = new Map()
|
|
208
347
|
for (const r of list) {
|
|
209
348
|
const name = r?.toolCall?.name ?? ""
|
|
210
|
-
|
|
349
|
+
const errored = isToolResultError(r)
|
|
350
|
+
if (errored) hadError = true
|
|
351
|
+
if (name === "ssh") state.usedSsh = true
|
|
352
|
+
if (isBashCodeFragmentCall(r)) usedBashCodeRead = true
|
|
353
|
+
if (GRAPH_PASSIVE_SEARCH_TOOLS.has(name) || name === "repo_graph") {
|
|
354
|
+
usedProperLookup = true
|
|
355
|
+
const parsed = parseToolArgs(r?.toolCall?.arguments)
|
|
356
|
+
const addSeed = (rawPath, { primary = false } = {}) => {
|
|
357
|
+
const norm = normalizeRelPath(rawPath, cwd)
|
|
358
|
+
if (!norm || state.guardSuggestedPaths.has(norm)) return
|
|
359
|
+
if (!state.touchedCodeFiles.has(norm) && state.touchedCodeFiles.size >= MAX_GRAPH_SEED_FILES) return
|
|
360
|
+
const isNew = !state.touchedCodeFiles.has(norm)
|
|
361
|
+
if (primary) state.primaryTargetFiles.add(norm)
|
|
362
|
+
state.touchedCodeFiles.add(norm)
|
|
363
|
+
if (isNew && GRAPH_PASSIVE_SEARCH_TOOLS.has(name)) state.graphPassivePending = true
|
|
364
|
+
}
|
|
365
|
+
const rawGp = String(parsed?.path ?? (name === "repo_graph" ? parsed?.query : "") ?? "").trim()
|
|
366
|
+
if (rawGp && CODE_FILE_RE.test(rawGp)) {
|
|
367
|
+
const joinedGp = (name === "repo_graph" && parsed?.target && !isAbsolute(rawGp))
|
|
368
|
+
? join(String(parsed.target), rawGp)
|
|
369
|
+
: rawGp
|
|
370
|
+
addSeed(joinedGp, { primary: name === "repo_graph" })
|
|
371
|
+
}
|
|
372
|
+
if (!errored && GRAPH_PASSIVE_SEARCH_TOOLS.has(name)) {
|
|
373
|
+
const resText = typeof r?.result === "string" ? r.result : ""
|
|
374
|
+
for (const rawPath of resultCodePaths(name, parsed, resText)) addSeed(rawPath)
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (name === "read" && !errored) {
|
|
378
|
+
usedProperLookup = true
|
|
379
|
+
const parsed = parseToolArgs(r?.toolCall?.arguments)
|
|
380
|
+
const rawPath = String(parsed?.path ?? parsed?.filePath ?? "").trim()
|
|
381
|
+
if (rawPath) {
|
|
382
|
+
// 规则本体(已读判定 + 种子采集 + 被动待发位)住 `planning-graph-guardrail.mjs` 的 noteReadFootprint。
|
|
383
|
+
const foot = noteReadFootprint(state, rawPath, parsed, { cwd, sessionFullReadFiles })
|
|
384
|
+
if (foot.usedFullCodeRead) usedFullCodeRead = true
|
|
385
|
+
if (foot.usedKeyholeRead) usedKeyholeRead = true
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (FILE_MUTATORS.has(name) && !errored) {
|
|
389
|
+
state.hasMutatedFiles = true
|
|
390
|
+
const parsed = parseToolArgs(r?.toolCall?.arguments)
|
|
391
|
+
const directPath = String(parsed?.path ?? parsed?.filePath ?? parsed?.file ?? "").trim()
|
|
392
|
+
const targetText = String(directPath || parsed?.patch || "")
|
|
393
|
+
if (CODE_FILE_RE.test(targetText)) {
|
|
394
|
+
state.mutatedCodeFiles = true
|
|
395
|
+
if (directPath && CODE_FILE_RE.test(directPath)) {
|
|
396
|
+
const normMut = normalizeRelPath(directPath, cwd)
|
|
397
|
+
if (normMut) {
|
|
398
|
+
state.primaryTargetFiles.add(normMut)
|
|
399
|
+
state.touchedCodeFiles.add(normMut)
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
211
404
|
const advisorType = extractAdvisorReviewType(r)
|
|
212
405
|
if (advisorType) {
|
|
213
406
|
if (!Array.isArray(state.advisorReviewTypes)) state.advisorReviewTypes = []
|
|
214
407
|
if (!state.advisorReviewTypes.includes(advisorType)) state.advisorReviewTypes.push(advisorType)
|
|
408
|
+
} else if (isEngDesignerToolCall(r)) {
|
|
409
|
+
hitEngDesigner = true
|
|
215
410
|
} else if (isMilestoneToolCall(r)) {
|
|
216
411
|
hitMilestone = true
|
|
217
412
|
}
|
|
@@ -229,10 +424,17 @@ export function recordPlanningTurnOutcome(state, { results = [], toolByName = nu
|
|
|
229
424
|
state.turnsSincePlan = setTimer ? 0 : state.turnsSincePlan + 1
|
|
230
425
|
state.probeStreak = allProbe ? state.probeStreak + 1 : 0
|
|
231
426
|
state.errorStreak = hadError ? state.errorStreak + 1 : 0
|
|
427
|
+
state.bashCodeReadCount = usedBashCodeRead
|
|
428
|
+
? (state.bashCodeReadCount ?? 0) + 1
|
|
429
|
+
: (usedFullCodeRead || usedProperLookup ? 0 : (state.bashCodeReadCount ?? 0))
|
|
430
|
+
state.keyholeReadCount = usedKeyholeRead
|
|
431
|
+
? (state.keyholeReadCount ?? 0) + 1
|
|
432
|
+
: (usedFullCodeRead ? 0 : (state.keyholeReadCount ?? 0))
|
|
433
|
+
if (hitEngDesigner) state.engDesignerHit = true
|
|
232
434
|
if (hitMilestone) state.milestoneHit = true
|
|
233
435
|
}
|
|
234
436
|
|
|
235
|
-
/** 判定当前轮头是否应触发一次规划步;返回触发键(`advisor|start|compaction|milestone|error|probe|interval`)或 `null`。 */
|
|
437
|
+
/** 判定当前轮头是否应触发一次规划步;返回触发键(`queuedInput|advisor|engDesigner|start|compaction|milestone|error|probe|interval`)或 `null`。 */
|
|
236
438
|
export function pickPlanningTrigger(state, cfg, { turn = 0, input = "" } = {}) {
|
|
237
439
|
if (!state || !cfg) return null
|
|
238
440
|
if (state.runsUsed >= cfg.maxPerRun) return null
|
|
@@ -240,17 +442,24 @@ export function pickPlanningTrigger(state, cfg, { turn = 0, input = "" } = {}) {
|
|
|
240
442
|
if (turn > 0 && turn - (state.lastPlanFailTurn ?? -1) <= 1) return null
|
|
241
443
|
|
|
242
444
|
const hasAdvisor = Array.isArray(state.advisorReviewTypes) && state.advisorReviewTypes.length > 0
|
|
445
|
+
const hasAsyncDelivery = Array.isArray(state.asyncDeliveredRoles) && state.asyncDeliveredRoles.length > 0
|
|
243
446
|
if (turn === 0) {
|
|
447
|
+
if (state.queuedInputHit && cfg.onQueuedInput !== false) return "queuedInput"
|
|
244
448
|
if (hasAdvisor && cfg.onAdvisor !== false) return "advisor"
|
|
245
|
-
if (
|
|
449
|
+
if (state.engDesignerHit) return "engDesigner"
|
|
450
|
+
if (hasAsyncDelivery && cfg.onMilestone !== false) return "milestone"
|
|
451
|
+
if (cfg.timerTurn && cfg.onStart) return "start"
|
|
452
|
+
if (cfg.autoTurn) return null
|
|
246
453
|
return cfg.onStart && shouldPlanOnStart(input) ? "start" : null
|
|
247
454
|
}
|
|
455
|
+
// 用户插话优先于一切机器信号:人当下说的话比评审结论、timer 等待态与冷却节拍都新,也不该被它们压住。
|
|
456
|
+
if (state.queuedInputHit && cfg.onQueuedInput !== false) return "queuedInput"
|
|
248
457
|
// 刚设完非阻塞 timer 唤醒时让出本轮收口机会,不插入规划步打断等待态(防诱导模型 sleep 阻塞轮询)
|
|
249
458
|
if (state.justSetTimer) return null
|
|
250
459
|
if (hasAdvisor && cfg.onAdvisor !== false) return "advisor"
|
|
251
|
-
if (cfg.advisorOnly) return null
|
|
252
460
|
if (state.justCompacted && cfg.onCompaction) return "compaction"
|
|
253
|
-
if (state.
|
|
461
|
+
if (state.engDesignerHit) return "engDesigner"
|
|
462
|
+
if ((state.milestoneHit || hasAsyncDelivery) && cfg.onMilestone) return "milestone"
|
|
254
463
|
if (state.turnsSincePlan < cfg.minCooldownTurns) return null
|
|
255
464
|
if (cfg.errorThreshold > 0 && state.errorStreak >= cfg.errorThreshold) return "error"
|
|
256
465
|
if (cfg.probeThreshold > 0 && !state.searched && state.probeStreak >= cfg.probeThreshold) return "probe"
|
|
@@ -273,74 +482,38 @@ export function resolvePlanningProvider(agent, cfg) {
|
|
|
273
482
|
if (parsed.ok) resolved = { ...parsed.provider, model: parsed.model }
|
|
274
483
|
else resolved = { ...base, model: rawModel }
|
|
275
484
|
}
|
|
276
|
-
|
|
485
|
+
// 2026-12-03 批(台账 #133):`effort` 不再写到 provider 克隆上——由 `resolvePlanningModelParams` 单独交出,
|
|
486
|
+
// 逐调用经 `chatFn(provider, { modelParams })` 下发(用户裁定「不应该有任何 provider 级别的模型参数」)。
|
|
277
487
|
return resolved
|
|
278
488
|
}
|
|
279
489
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
/** 构造规划步尾部指令消息(挂在现有对话前缀之后,保前缀缓存)。 */
|
|
290
|
-
export function buildPlanningPromptMessage({
|
|
291
|
-
trigger, searched, preferredSearch, canAskUser = false, pendingTimerCount = 0,
|
|
292
|
-
goal = "", turn = 0, tasks = [], turnsSinceTaskUpdate = 0, advisorReviewTypes = [], checklist, everyTurn = false, shortCadence = false,
|
|
293
|
-
}) {
|
|
294
|
-
const reason = (trigger === "interval" && (everyTurn || shortCadence))
|
|
295
|
-
? "先对照主任务检查自己是在推进核心交付还是被支线细节吸引走;只看自上次规划之后这 1–2 轮刚返回的新结果(严禁复述旧发现或重列已核文档清单),非阻塞旁枝只记备忘,基线/侦察够用即切入实质行动。"
|
|
296
|
-
: (TRIGGER_REASONS[trigger] ?? TRIGGER_REASONS.interval)
|
|
297
|
-
const cleanGoal = summarizeGoalForAnchor(goal)
|
|
298
|
-
const goalHint = turn > 0 && cleanGoal
|
|
299
|
-
? `\n主任务锚点(本回合已执行 ${turn} 轮工具):「${cleanGoal}」${turn >= PLAN_DRIFT_WARN_TURN ? "——已运行较多轮,请优先核对是否仍停留在基线复核或支线技术细节里而尚未推进核心交付;非阻塞旁枝只记备忘,立刻回到主线,或用 `question` 让用户决定是否改道。" : ""}`
|
|
300
|
-
: ""
|
|
301
|
-
const advisorHint = trigger === "advisor"
|
|
302
|
-
? `\n评审核实专项(${describeAdvisorScope(advisorReviewTypes).scope}):严禁未核原文就直接照评审意见大改!请先在下一步列出每条关键评审意见的实盘核查动作(用 \`read\`/\`grep\`/\`peek\` 或实跑命令核对被指代码行、权威需求/设计档与真实行为),逐条判清「成立(改) / 待核(先查) / 误判或越界(据实反驳不盲改)」,再动手修改或回复评审表。`
|
|
303
|
-
: ""
|
|
304
|
-
const taskHint = buildPlanningTaskHint(tasks, turnsSinceTaskUpdate)
|
|
305
|
-
const searchHint = !searched && preferredSearch
|
|
306
|
-
? `\n当前环境可用的首选联网搜索工具为 \`${preferredSearch}\`(如问题涉及外部系统/框架/引擎/工具异常且本轮尚未搜过,请在下一步第 1 项直接指明调用它及具体查询词)。`
|
|
307
|
-
: ""
|
|
308
|
-
const askHint = canAskUser
|
|
309
|
-
? "\n当前为交互会话且 `question` 工具可用:若缺关键用户业务约束或互斥路线取舍,或发现值得深挖但会明显偏离原目标/耗时较长的支线需要用户拍板要不要切换,可在下一步直接调 `question` 一次表单问清 1–3 个高杠杆分叉问题(每题均自带自由输入),不必盲跑完再反问。"
|
|
310
|
-
: ""
|
|
311
|
-
const timerHint = pendingTimerCount > 0
|
|
312
|
-
? `\n当前已有 ${pendingTimerCount} 个在途 \`timer\` 定时唤醒:等待长任务结果时应直接以等待态文字收尾让定时器唤醒,严禁用 \`sleep\` 或超长 \`ssh\`/\`bash\` 命令阻塞干等。`
|
|
313
|
-
: ""
|
|
314
|
-
return `[Planning next moves — trigger: ${trigger}]\n场景提示:${reason}${goalHint}${advisorHint}${taskHint}${searchHint}${askHint}${timerHint}\n\n${checklist}`
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/** 截断注入 B 段的规划文本,防止过长规划或数千字空正文回退思考灌爆下一轮上下文。 */
|
|
318
|
-
export function capPlanTextForInject(text, { fromReasoning = false, maxChars = PLAN_INJECT_MAX_CHARS } = {}) {
|
|
319
|
-
const clean = typeof text === "string" ? text.trim() : ""
|
|
320
|
-
if (!clean) return ""
|
|
321
|
-
const limit = fromReasoning ? Math.min(maxChars, PLAN_REASONING_FALLBACK_MAX_CHARS) : maxChars
|
|
322
|
-
if (clean.length <= limit) return clean
|
|
323
|
-
// 原始思考流保留尾部(结论通常在尾段),正式规划正文保留头部核心条目
|
|
324
|
-
return fromReasoning
|
|
325
|
-
? `…(已截断前段思考)\n${clean.slice(-limit)}`
|
|
326
|
-
: `${clean.slice(0, limit)}\n…(已截断)`
|
|
490
|
+
/** 规划步的模型语义参数(2026-12-03 批,台账 #133):会话设置(`agent.modelParams`)叠加规划步自己的
|
|
491
|
+
* `cfg.reasoningEffort` 覆写;不再是 provider 克隆上的字段。未配置覆写 ⇒ 会话设置原样(与 `resolvePlanningProvider`
|
|
492
|
+
* 「未配置就原样返回 base」同形)。 */
|
|
493
|
+
export function resolvePlanningModelParams(agent, cfg) {
|
|
494
|
+
const out = { ...(agent?.modelParams ?? {}) }
|
|
495
|
+
const effort = typeof cfg?.reasoningEffort === "string" && cfg.reasoningEffort.trim() ? cfg.reasoningEffort.trim() : null
|
|
496
|
+
if (effort) out.reasoningEffort = effort
|
|
497
|
+
return out
|
|
327
498
|
}
|
|
328
499
|
|
|
329
500
|
/**
|
|
330
501
|
* 执行一次独立的 Harness「Planning next moves」规划步:
|
|
331
502
|
* - 不修改 `agent.history`(只读现有上下文 + 尾部单条规划检查单);
|
|
332
503
|
* - 透传与 `callModelTurn` 100% 一致的 `tools`(不发 `toolChoice:"none"`,避免服务端切换模板击穿 KV 前缀缓存),
|
|
333
|
-
* 代码层不执行任何 `response.toolCalls
|
|
334
|
-
* - 实时流式把思考流与规划正文经 `callbacks.onReasoning(chunk, { phase: "planning", trigger })`
|
|
504
|
+
* 代码层不执行任何 `response.toolCalls`;主会话普通模式下仅解析并剥离规划正文末尾的 `<task_sync>{...}</task_sync>` 标签静默同步 `agent.tasks`(零外部副作用);
|
|
505
|
+
* - 实时流式把思考流与规划正文经 `callbacks.onReasoning(chunk, { phase: "planning", trigger })` 送到三端;
|
|
335
506
|
* - 完成后将规划结论经 B 段 `pushInject` 交给紧随其后的执行轮;
|
|
336
|
-
* -
|
|
507
|
+
* - 仅清除本次实际消费的触发位(不误吞同批并发到达的其余触发证据),非用户中止异常优雅降级。
|
|
337
508
|
*/
|
|
338
509
|
export async function runPlanningStep(agent, {
|
|
339
510
|
trigger, cfg, state, systemPrompt, toolSchemas, toolByName, callbacks, signal, depth = 0, turn = 0, input = "",
|
|
340
|
-
chatFn = chat, checklist = null,
|
|
511
|
+
goal: explicitGoal = "", chatFn = chat, checklist = null,
|
|
341
512
|
}) {
|
|
342
513
|
const provider = resolvePlanningProvider(agent, cfg)
|
|
343
514
|
if (!provider) return null
|
|
515
|
+
// 规划步的模型语义参数(2026-12-03 批,台账 #133):会话设置 + `cfg.reasoningEffort` 覆写,随每次调用下发。
|
|
516
|
+
const planningModelParams = resolvePlanningModelParams(agent, cfg)
|
|
344
517
|
|
|
345
518
|
const intervalNum = Number(cfg?.intervalTurns)
|
|
346
519
|
const shortCadence = Number.isFinite(intervalNum) && intervalNum > 0 && intervalNum <= 2
|
|
@@ -350,14 +523,84 @@ export async function runPlanningStep(agent, {
|
|
|
350
523
|
(toolByName?.has?.("question") || tools.some((t) => t?.name === "question"))
|
|
351
524
|
&& typeof callbacks?.onQuestion === "function",
|
|
352
525
|
)
|
|
526
|
+
const taskTool = (depth === 0 && agent?.config?.agent?.engineering !== true)
|
|
527
|
+
? (toolByName?.get?.("task") ?? tools.find((t) => t?.name === "task") ?? null)
|
|
528
|
+
: null
|
|
529
|
+
const canSyncTask = Boolean(taskTool)
|
|
353
530
|
const pendingTimerCount = Array.isArray(agent?._pendingTimers) ? agent._pendingTimers.length : 0
|
|
354
531
|
const advisorReviewTypes = Array.isArray(state?.advisorReviewTypes) ? [...state.advisorReviewTypes] : []
|
|
355
|
-
const
|
|
532
|
+
const asyncDeliveredRoles = Array.isArray(state?.asyncDeliveredRoles) ? [...state.asyncDeliveredRoles] : []
|
|
533
|
+
const goal = summarizeGoalForAnchor(
|
|
534
|
+
explicitGoal || input || agent?.goal?.condition || extractLastRealUserGoal(agent?.history),
|
|
535
|
+
)
|
|
356
536
|
const guide = checklist ?? loadPlanningChecklist()
|
|
537
|
+
let graphMissing = null
|
|
538
|
+
const mergedFullRead = mergedGraphFullRead(agent, state)
|
|
539
|
+
// 跨轮/异步消化轮继承会话级整档已读状态,避免刚评审返回再修两行就误报「未核原有文档即改源码」
|
|
540
|
+
let sessionReadDocs = false
|
|
541
|
+
let sessionReadCode = false
|
|
542
|
+
for (const p of mergedFullRead) {
|
|
543
|
+
if (DOC_FILE_RE.test(p)) sessionReadDocs = true
|
|
544
|
+
if (CODE_FILE_RE.test(p)) sessionReadCode = true
|
|
545
|
+
}
|
|
546
|
+
const effectiveHasReadDocs = Boolean(state.hasReadDocs || sessionReadDocs)
|
|
547
|
+
const effectiveHasReadCode = Boolean(state.hasReadCode || sessionReadCode)
|
|
548
|
+
|
|
549
|
+
if (!(state.guardSuggestedPaths instanceof Set)) state.guardSuggestedPaths = new Set()
|
|
550
|
+
if (!(state.graphRemindedCounts instanceof Map)) state.graphRemindedCounts = new Map()
|
|
551
|
+
const pinnedPack = Array.isArray(agent?._graphReadingPack) ? agent._graphReadingPack : []
|
|
552
|
+
for (const item of pinnedPack) {
|
|
553
|
+
if ((item?.role === "caller" || item?.role === "sibling") && item?.path) {
|
|
554
|
+
const k = normalizeRelPath(item.path, agent?.cwd)
|
|
555
|
+
if (k) state.guardSuggestedPaths.add(k)
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
const seedTargets = [
|
|
559
|
+
...(state?.primaryTargetFiles instanceof Set ? state.primaryTargetFiles : []),
|
|
560
|
+
...(state?.touchedCodeFiles instanceof Set ? state.touchedCodeFiles : []),
|
|
561
|
+
]
|
|
562
|
+
const hasGraphSeed = seedTargets.length > 0 || pinnedPack.length > 0
|
|
563
|
+
if (agent?.cwd && trigger !== "compaction") {
|
|
564
|
+
try {
|
|
565
|
+
let rawMissing = null
|
|
566
|
+
if (turn === 0 && trigger === "start") {
|
|
567
|
+
const rawInput = explicitGoal || input || goal
|
|
568
|
+
if (rawInput) {
|
|
569
|
+
const { getTurnZeroGraphPack } = await import("../doc-graph.mjs")
|
|
570
|
+
rawMissing = await getTurnZeroGraphPack(agent.cwd, rawInput, mergedFullRead)
|
|
571
|
+
}
|
|
572
|
+
} else if (turn > 0 && hasGraphSeed) {
|
|
573
|
+
const { getMissingReadingPack } = await import("../doc-graph.mjs")
|
|
574
|
+
// 与注入侧同一道层标识闸(Q4 裁定):规划步的「图谱必读核对」也不能把 unlayered 文档当档来算。
|
|
575
|
+
rawMissing = await getMissingReadingPack(agent.cwd, {
|
|
576
|
+
targetFiles: await filterSeedsByLayer(seedTargets, agent.cwd),
|
|
577
|
+
fullReadFiles: mergedFullRead,
|
|
578
|
+
pinnedPack,
|
|
579
|
+
})
|
|
580
|
+
}
|
|
581
|
+
// 搜索后的确定性注入已覆盖同一份原始清单时,规划步不再重复消费每路径提醒预算。
|
|
582
|
+
if (rawMissing && turn > 0 && graphRawSignature(rawMissing) === state.graphLastPassiveSignature) rawMissing = null
|
|
583
|
+
graphMissing = filterGraphMissing(agent, state, rawMissing, {
|
|
584
|
+
suppressSiblings: Boolean(state.mutatedCodeFiles || trigger === "advisor"),
|
|
585
|
+
})
|
|
586
|
+
} catch { /* 图谱护栏尽力而为,不阻断规划步 */ }
|
|
587
|
+
}
|
|
588
|
+
const lastDrift = Number.isFinite(state.lastDriftWarnTurn) ? state.lastDriftWarnTurn : -1
|
|
589
|
+
const driftWarnDue = turn >= PLAN_DRIFT_WARN_TURN && (lastDrift < 0 || turn - lastDrift >= PLAN_DRIFT_WARN_STRIDE)
|
|
590
|
+
if (driftWarnDue) state.lastDriftWarnTurn = turn
|
|
357
591
|
const promptMsg = buildPlanningPromptMessage({
|
|
358
|
-
trigger, searched: state.searched, preferredSearch, canAskUser, pendingTimerCount,
|
|
592
|
+
trigger, searched: state.searched, preferredSearch, canAskUser, canSyncTask, pendingTimerCount,
|
|
359
593
|
goal, turn, tasks: agent?.tasks ?? [], turnsSinceTaskUpdate: agent?._turnsSinceTaskUpdate ?? 0,
|
|
360
|
-
advisorReviewTypes,
|
|
594
|
+
advisorReviewTypes, asyncDeliveredRoles, autoTurn: Boolean(cfg?.autoTurn), timerTurn: Boolean(cfg?.timerTurn),
|
|
595
|
+
bashCodeReadCount: state.bashCodeReadCount ?? 0,
|
|
596
|
+
keyholeReadCount: state.keyholeReadCount ?? 0,
|
|
597
|
+
hasReadDocs: effectiveHasReadDocs,
|
|
598
|
+
hasReadCode: effectiveHasReadCode,
|
|
599
|
+
hasMutatedFiles: Boolean(state.hasMutatedFiles),
|
|
600
|
+
mutatedCodeFiles: Boolean(state.mutatedCodeFiles),
|
|
601
|
+
usedSsh: Boolean(state.usedSsh),
|
|
602
|
+
graphMissing, checklist: guide, shortCadence, driftWarnDue,
|
|
603
|
+
toolRouting: buildToolRouting(toolSchemas),
|
|
361
604
|
})
|
|
362
605
|
const toolsDeclared = Array.isArray(toolSchemas) && toolSchemas.length > 0
|
|
363
606
|
const baseMessages = assembleRequestMessages(agent, { systemPrompt, toolsDeclared })
|
|
@@ -365,34 +608,38 @@ export async function runPlanningStep(agent, {
|
|
|
365
608
|
|
|
366
609
|
const label = trigger === "advisor"
|
|
367
610
|
? describeAdvisorScope(advisorReviewTypes).label
|
|
368
|
-
: (trigger === "
|
|
611
|
+
: (trigger === "start" && cfg?.timerTurn)
|
|
612
|
+
? "定时唤醒规划"
|
|
613
|
+
: (trigger === "milestone" && asyncDeliveredRoles.length > 0)
|
|
614
|
+
? "异步结果消化复盘"
|
|
615
|
+
: (trigger === "interval" && shortCadence) ? "下一步规划" : (TRIGGER_LABELS[trigger] ?? trigger)
|
|
369
616
|
const meta = { phase: "planning", trigger }
|
|
370
|
-
let emittedHeader = false
|
|
371
617
|
let streamedReasoning = false
|
|
372
618
|
let streamedContent = false
|
|
373
619
|
const emitPlanChunk = (chunk) => {
|
|
374
620
|
if (!chunk) return
|
|
375
|
-
if (!emittedHeader) {
|
|
376
|
-
emittedHeader = true
|
|
377
|
-
callbacks?.onReasoning?.(`**[${label}]**\n`, meta)
|
|
378
|
-
}
|
|
379
621
|
callbacks?.onReasoning?.(chunk, meta)
|
|
380
622
|
}
|
|
381
623
|
|
|
382
|
-
// 立即点亮三端「Planning next moves…」态,并实时透传思考流与正文,避免静默卡顿
|
|
383
|
-
emittedHeader = true
|
|
384
624
|
callbacks?.onReasoning?.(`**[${label}]**\n`, meta)
|
|
385
625
|
|
|
626
|
+
const tokenFilter = createTaskSyncStreamFilter((chunk) => {
|
|
627
|
+
if (!chunk) return
|
|
628
|
+
if (streamedReasoning && !streamedContent) emitPlanChunk("\n\n")
|
|
629
|
+
streamedContent = true
|
|
630
|
+
emitPlanChunk(chunk)
|
|
631
|
+
})
|
|
632
|
+
|
|
386
633
|
let response
|
|
387
634
|
try {
|
|
388
635
|
response = await chatFn(provider, {
|
|
636
|
+
// 规划步的模型语义参数(2026-12-03 批,台账 #133)——不再是 provider 克隆上的字段。
|
|
637
|
+
modelParams: planningModelParams,
|
|
389
638
|
messages,
|
|
390
639
|
tools: toolSchemas,
|
|
391
640
|
onToken: (tok) => {
|
|
392
641
|
if (!tok) return
|
|
393
|
-
|
|
394
|
-
streamedContent = true
|
|
395
|
-
emitPlanChunk(tok)
|
|
642
|
+
tokenFilter.push(tok)
|
|
396
643
|
},
|
|
397
644
|
onReasoning: (r) => {
|
|
398
645
|
if (!r) return
|
|
@@ -414,40 +661,80 @@ export async function runPlanningStep(agent, {
|
|
|
414
661
|
})
|
|
415
662
|
} catch (err) {
|
|
416
663
|
if (err?.name === "AbortError" || signal?.aborted) throw err
|
|
417
|
-
// 规划步自身非中止异常优雅降级,不阻断主任务执行。
|
|
418
|
-
// 只复位节拍并记失败轮号供下一轮退避;**不清**任何一次性触发证据与连击:
|
|
419
|
-
// - probeStreak / errorStreak 记的是工具侧事实,规划失败不等于工具已恢复;
|
|
420
|
-
// - advisorReviewTypes / milestoneHit / justCompacted 是「该做一次规划」的证据,
|
|
421
|
-
// 清掉会让 advisor 消化轮的核实规划被一次瞬时失败静默吞掉(advisorOnly 在 turn>0 不再触发)。
|
|
422
|
-
// 重打由退避(lastPlanFailTurn)与 maxPerRun 兜住,不靠清证据。
|
|
423
664
|
state.turnsSincePlan = 0
|
|
424
665
|
state.lastPlanFailTurn = turn
|
|
425
666
|
return null
|
|
426
667
|
}
|
|
668
|
+
tokenFilter.flush()
|
|
669
|
+
|
|
670
|
+
// 规划步真实消耗同样计入 usage、缓存统计与 goal token 预算(不改 `_lastPromptTokens`/`_usageAt`:
|
|
671
|
+
// 规划步额外追加了一条规划指令,不覆盖主执行轮的上下文窗口基线)。
|
|
672
|
+
if (response?.usage) {
|
|
673
|
+
callbacks?.onUsage?.(response.usage)
|
|
674
|
+
agent._cacheHitTokens = (agent._cacheHitTokens ?? 0) + (response.usage.prompt_cache_hit_tokens ?? 0)
|
|
675
|
+
agent._cacheMissTokens = (agent._cacheMissTokens ?? 0) + (response.usage.prompt_cache_miss_tokens ?? 0)
|
|
676
|
+
if (agent.goal?.status === "active") addGoalTokens(agent, response.usage)
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const rawContent = typeof response?.content === "string" ? response.content : ""
|
|
680
|
+
const taskSync = await extractAndApplyPlanningTaskSync(agent, rawContent, { taskTool, depth, signal })
|
|
427
681
|
|
|
428
|
-
let planText =
|
|
682
|
+
let planText = taskSync.cleanedText
|
|
429
683
|
let fromReasoning = false
|
|
430
684
|
if (!planText && typeof response?.reasoning === "string" && response.reasoning.trim()) {
|
|
431
685
|
fromReasoning = true
|
|
432
686
|
planText = response.reasoning.trim()
|
|
433
687
|
if (!streamedReasoning) emitPlanChunk(planText)
|
|
434
688
|
}
|
|
689
|
+
if (!planText && taskSync.synced && !streamedReasoning) {
|
|
690
|
+
emitPlanChunk(`[task 已同步] ${taskSync.receipt}`)
|
|
691
|
+
}
|
|
435
692
|
|
|
436
693
|
state.runsUsed += 1
|
|
437
694
|
state.turnsSincePlan = 0
|
|
438
695
|
state.lastPlanFailTurn = -1
|
|
439
|
-
|
|
440
|
-
if (trigger === "
|
|
441
|
-
state.
|
|
442
|
-
state.
|
|
443
|
-
state.
|
|
696
|
+
// 仅清除本次实际消费掉的触发位,避免并发到达的其他高优证据(如 advisor + engDesigner)被误吞
|
|
697
|
+
if (trigger === "advisor") state.advisorReviewTypes = []
|
|
698
|
+
else if (trigger === "engDesigner") state.engDesignerHit = false
|
|
699
|
+
else if (trigger === "compaction") state.justCompacted = false
|
|
700
|
+
else if (trigger === "milestone") { state.milestoneHit = false; state.asyncDeliveredRoles = [] }
|
|
701
|
+
else if (trigger === "queuedInput") state.queuedInputHit = false
|
|
702
|
+
else if (trigger === "probe") state.probeStreak = 0
|
|
703
|
+
else if (trigger === "error") state.errorStreak = 0
|
|
704
|
+
state.bashCodeReadCount = 0
|
|
705
|
+
state.keyholeReadCount = 0
|
|
444
706
|
|
|
445
707
|
const injectText = capPlanTextForInject(planText, { fromReasoning })
|
|
708
|
+
const taskSyncPassthrough = taskSync.synced
|
|
709
|
+
? `\n[task 已在规划步静默同步:${taskSync.receipt};主循环无需重复执行相同 task 更新]`
|
|
710
|
+
: ""
|
|
446
711
|
if (injectText) {
|
|
712
|
+
// 直透高关联未读文件清单,避免规划模型压缩总结时把精确文件路径和行数转述丢掉
|
|
713
|
+
let graphPassthrough = ""
|
|
714
|
+
if (graphMissing) {
|
|
715
|
+
const fmtMissing = (arr) => arr
|
|
716
|
+
.filter((x) => x?.path && !injectText.includes(x.path))
|
|
717
|
+
.map((x) => `${x.path}${x.lines ? ` (${x.lines}行)` : ""}`)
|
|
718
|
+
const docsPart = fmtMissing(graphMissing.missingDocs ?? []).slice(0, 2)
|
|
719
|
+
const targetsPart = fmtMissing(graphMissing.missingTargets ?? []).slice(0, 2)
|
|
720
|
+
const callersPart = fmtMissing(graphMissing.missingCallers ?? []).slice(0, 2)
|
|
721
|
+
const segs = []
|
|
722
|
+
if (docsPart.length) segs.push(`需求/设计:${docsPart.join("、")}`)
|
|
723
|
+
if (targetsPart.length) segs.push(`目标源码:${targetsPart.join("、")}`)
|
|
724
|
+
if (callersPart.length) segs.push(`直接上游:${callersPart.join("、")}`)
|
|
725
|
+
if (segs.length) {
|
|
726
|
+
graphPassthrough = `\n[图谱未读必读清单(请先并发整档 read):${segs.join(";")}]`
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
pushInject(agent, {
|
|
730
|
+
role: "user",
|
|
731
|
+
content: `[System reminder: Planning next moves (${trigger}) completed — follow the concrete next moves below directly (do not mention any checkpoint/planning step or repeat the preamble to the user):\n${injectText}${graphPassthrough}${taskSyncPassthrough}]`,
|
|
732
|
+
})
|
|
733
|
+
} else if (taskSync.synced) {
|
|
447
734
|
pushInject(agent, {
|
|
448
735
|
role: "user",
|
|
449
|
-
content: `[System reminder: Planning next moves (${trigger})
|
|
736
|
+
content: `[System reminder: Planning next moves (${trigger}) synced the task list (${taskSync.receipt}) — continue executing directly without repeating the same task update or mentioning any planning step.]`,
|
|
450
737
|
})
|
|
451
738
|
}
|
|
452
|
-
return injectText || null
|
|
739
|
+
return injectText || (taskSync.synced ? taskSync.receipt : null)
|
|
453
740
|
}
|