@thincoder/core 0.11.2 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/advisor/compaction.mjs +7 -5
- package/advisor/history.mjs +24 -11
- package/advisor/loop.mjs +13 -8
- package/advisor/messages.mjs +72 -8
- package/advisor/run.mjs +24 -13
- package/advisor.mjs +7 -3
- package/agent/chat-call.mjs +14 -9
- package/agent/completion.mjs +28 -40
- package/agent/continue-decision.mjs +14 -8
- package/agent/digest-account.mjs +133 -59
- package/agent/dispatch-run.mjs +1 -1
- package/agent/dispatch.mjs +2 -1
- package/agent/family-tools.mjs +12 -13
- package/agent/helpers.mjs +17 -72
- package/agent/image-heal.mjs +18 -4
- package/agent/post-turn.mjs +13 -26
- package/agent/record-results.mjs +21 -6
- package/agent/run-stages.mjs +72 -37
- package/agent/run-start.mjs +148 -113
- package/agent/setup-reminders.mjs +187 -91
- package/agent/setup.mjs +204 -138
- package/agent/spawn-child.mjs +2 -2
- package/agent/suspension.mjs +43 -15
- package/agent/timers.mjs +4 -1
- package/agent/turn-domain-text.mjs +105 -0
- package/agent/turn-loop.mjs +54 -22
- package/agent/turn-projection.mjs +127 -227
- package/agent/turn-tool-process.mjs +32 -37
- package/agent-tools/advisor-async.mjs +6 -3
- package/agent-tools/advisor-launch.mjs +5 -5
- package/agent-tools/advisor.mjs +1 -1
- package/agent-tools/async-discard.mjs +7 -2
- package/agent-tools/async-settle.mjs +18 -12
- package/agent-tools/bash-async.mjs +5 -2
- package/agent-tools/batch-closeout.mjs +12 -62
- package/agent-tools/batch-ledger-bind.mjs +19 -8
- package/agent-tools/batch-lifecycle.mjs +37 -11
- package/agent-tools/batch-read.mjs +151 -4
- package/agent-tools/batch-record-write.mjs +5 -5
- package/agent-tools/batch-segment-vocab.mjs +84 -4
- package/agent-tools/batch-skeleton.mjs +18 -14
- package/agent-tools/batch-supersede.mjs +1 -1
- package/agent-tools/batch-tier-gate.mjs +36 -119
- package/agent-tools/batch.mjs +30 -20
- package/agent-tools/browser-async.mjs +5 -2
- package/agent-tools/consult.mjs +10 -7
- package/agent-tools/context.mjs +47 -31
- package/agent-tools/digest-budget.mjs +10 -9
- package/agent-tools/eng.mjs +3 -4
- package/agent-tools/escalate-async.mjs +3 -3
- package/agent-tools/goal.mjs +5 -2
- package/agent-tools/judge-domain.mjs +347 -0
- package/agent-tools/manifest.mjs +2 -2
- package/agent-tools/parent-channel.mjs +6 -3
- package/agent-tools/plan.mjs +11 -10
- package/agent-tools/review-facts.mjs +9 -3
- package/agent-tools/skill.mjs +7 -8
- package/agent-tools/spawn-gates.mjs +5 -16
- package/agent-tools/ssh-session.mjs +6 -3
- package/agent-tools/ssh-transfer.mjs +1 -1
- package/agent-tools/subagent-actions.mjs +2 -2
- package/agent-tools/subagent-async.mjs +11 -8
- package/agent-tools/subagent-scheduler.mjs +9 -9
- package/agent-tools/subagent-spawn.mjs +2 -2
- package/agent-tools/subagent.mjs +5 -18
- package/agent-tools/task.mjs +0 -8
- package/agent.mjs +15 -15
- package/auto-think.mjs +5 -2
- package/compaction-work-state.mjs +230 -0
- package/compress-form.mjs +41 -6
- package/config-defaults.mjs +5 -2
- package/config.mjs +53 -17
- package/context-degrade.mjs +79 -48
- package/context-echo.mjs +6 -26
- package/context-push.mjs +328 -31
- package/context.mjs +203 -141
- package/conventions.mjs +1 -1
- package/declaration.mjs +95 -17
- package/escape.mjs +6 -5
- package/explore-distill.mjs +35 -8
- package/generate-title.mjs +10 -1
- package/knowledge/prompt-resources.md +5 -1
- package/ledger-tools.mjs +50 -50
- package/ledger-write-ops.mjs +43 -16
- package/memory/docs.mjs +51 -15
- package/memory/file-list.mjs +6 -0
- package/model-specs.mjs +87 -21
- package/origin-guard.mjs +190 -0
- package/package.json +1 -1
- package/prompt-files.mjs +33 -11
- package/prompt-overlays.mjs +12 -5
- package/prompts/advisor-design.md +55 -36
- package/prompts/advisor-round1.md +18 -7
- package/prompts/advisor-round2.md +18 -7
- package/prompts/advisor-round3.md +18 -7
- package/prompts/common.md +89 -51
- package/prompts/consult-base.md +2 -3
- package/prompts/discipline-engineering.md +474 -440
- package/prompts/discipline-normal.md +107 -31
- package/prompts/knowledge/business-gates.md +23 -15
- package/prompts/knowledge/decision-quality.md +16 -18
- package/prompts/knowledge/doc-lookup.md +22 -27
- package/prompts/knowledge/document-writing.md +31 -49
- package/prompts/knowledge/documentation-evaluation.md +37 -45
- package/prompts/knowledge/evidence-discipline.md +36 -55
- package/prompts/knowledge/normal-coding-workflow.md +27 -21
- package/prompts/knowledge/normal-delivery-collaboration.md +33 -17
- package/prompts/knowledge/normal-work-management.md +10 -7
- package/prompts/knowledge/product-security.md +22 -17
- package/prompts/knowledge/project-records.md +63 -52
- package/prompts/knowledge/tool-apply-patch.md +12 -13
- package/prompts/knowledge/tool-bash.md +13 -4
- package/prompts/knowledge/tool-batch-eng-coder.md +13 -6
- package/prompts/knowledge/tool-batch-eng-designer.md +14 -6
- package/prompts/knowledge/tool-batch-review.md +12 -6
- package/prompts/knowledge/tool-batch.md +76 -62
- package/prompts/knowledge/tool-browser.md +45 -34
- package/prompts/knowledge/tool-context.md +2 -2
- package/prompts/knowledge/tool-delete.md +5 -1
- package/prompts/knowledge/tool-doc-check.md +25 -24
- package/prompts/knowledge/tool-doc-graph-read.md +3 -3
- package/prompts/knowledge/tool-doc-graph.md +15 -15
- package/prompts/knowledge/tool-edit.md +26 -23
- package/prompts/knowledge/tool-execute.md +9 -4
- package/prompts/knowledge/tool-fetch.md +7 -1
- package/prompts/knowledge/tool-file-ops.md +6 -1
- package/prompts/knowledge/tool-git-read.md +3 -1
- package/prompts/knowledge/tool-git.md +1 -1
- package/prompts/knowledge/tool-glob.md +3 -1
- package/prompts/knowledge/tool-grep.md +5 -2
- package/prompts/knowledge/tool-hashline-edit.md +4 -2
- package/prompts/knowledge/tool-insert-after.md +3 -1
- package/prompts/knowledge/tool-ledger-read.md +6 -13
- package/prompts/knowledge/tool-ledger.md +14 -10
- package/prompts/knowledge/tool-ls.md +2 -0
- package/prompts/knowledge/tool-manifest.md +10 -7
- package/prompts/knowledge/tool-memory.md +15 -11
- package/prompts/knowledge/tool-operations.md +59 -71
- package/prompts/knowledge/tool-plan.md +1 -2
- package/prompts/knowledge/tool-process.md +1 -1
- package/prompts/knowledge/tool-read-history.md +6 -7
- package/prompts/knowledge/tool-read.md +1 -0
- package/prompts/knowledge/tool-settings.md +6 -7
- package/prompts/knowledge/tool-ssh.md +37 -15
- package/prompts/knowledge/tool-subagent.md +37 -39
- package/prompts/knowledge/tool-task.md +3 -1
- package/prompts/knowledge/tool-team-ledger.md +5 -1
- package/prompts/knowledge/tool-tree.md +2 -0
- package/prompts/knowledge/tool-wait-for.md +16 -16
- package/prompts/knowledge/tool-write.md +4 -1
- package/prompts/knowledge/upstream-protocol.md +39 -37
- package/prompts/persona-coder.md +1 -3
- package/prompts/persona-eng-coder.md +5 -5
- package/prompts/persona-eng-designer.md +34 -17
- package/prompts/persona-engineering.md +532 -501
- package/prompts/persona-explore.md +0 -2
- package/prompts/persona-normal.md +17 -9
- package/prompts/persona-plan.md +0 -2
- package/prompts/persona-tester.md +0 -2
- package/prompts/subagent-base.md +0 -2
- package/provider/anthropic.mjs +4 -2
- package/provider/core.mjs +5 -3
- package/provider/errors.mjs +41 -7
- package/provider/google.mjs +5 -3
- package/provider/reasoning-echo.mjs +16 -0
- package/provider/responses.mjs +4 -2
- package/provider/sse.mjs +11 -6
- package/rules.mjs +11 -10
- package/session-lifecycle.mjs +115 -81
- package/session-slot-write.mjs +1 -1
- package/session.mjs +23 -20
- package/shell-identity.mjs +129 -22
- package/skip-dirs.mjs +24 -0
- package/team-ledger.mjs +22 -22
- package/text-budget.mjs +1 -1
- package/think-off.mjs +27 -0
- package/token-ttl.mjs +1 -1
- package/token-window.mjs +278 -88
- package/tool-docs/bash.md +0 -2
- package/tool-docs/consult_start.md +2 -2
- package/tool-docs/consult_stop.md +2 -2
- package/tools/browser.mjs +8 -8
- package/tools/execute.mjs +2 -2
- package/tools/file.mjs +17 -11
- package/tools/git.mjs +12 -12
- package/tools/ops.mjs +2 -2
- package/tools/patch.mjs +1 -1
- package/tools/process-doc-mark.mjs +33 -4
- package/tools/repomap.mjs +25 -3
- package/tools/search.mjs +74 -26
- package/tools/shared.mjs +4 -3
- package/tools/ssh.mjs +5 -5
- package/tools/tree.mjs +32 -10
- package/tools/web-deepseek.mjs +1 -1
- package/tools/web.mjs +2 -2
- package/tools/write-gate-params.mjs +3 -3
- package/window-policy.mjs +118 -78
package/agent/completion.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* agent/completion.mjs — handle model response with no tool calls
|
|
3
3
|
*
|
|
4
|
-
* Checks:
|
|
4
|
+
* Checks: verify guard, advisor guard.
|
|
5
5
|
* Returns { action: 'continue' | 'done', content?, guardPushbacks, honestReminderInjected, advisorPushbacks }
|
|
6
6
|
* 子回合边界(#628):六推回点各触 `callbacks.onSubTurnBreak?.()` —— 零参可选(缺省 no-op);`onTurnEnd` 超集语义零改。
|
|
7
7
|
*/
|
|
8
8
|
import { hasCodeMutations } from "../advisor/repos.mjs"
|
|
9
|
-
import { pushReal } from "../context.mjs"
|
|
9
|
+
import { pushReal, pushInject } from "../context.mjs"
|
|
10
|
+
import { specForModel, assistantTextMessage, isThinkingRequest } from "../config.mjs"
|
|
10
11
|
import { advisorReviewPending, effectiveAdvisorRound } from "../agent-tools/advisor-async.mjs"
|
|
11
|
-
import { poolLive } from "./suspension.mjs"
|
|
12
12
|
|
|
13
13
|
const MAX_VERIFY_PUSHBACKS = 2
|
|
14
14
|
const MAX_VERIFY_RETRIES = 3
|
|
@@ -19,7 +19,7 @@ const MAX_ADVISOR_REMINDERS = 5
|
|
|
19
19
|
const MAX_EMPTY_RETRIES = 2
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* 响应「有实质」判据(单源——判空面与清零面读同一份;AGENT-LOOP.md §6
|
|
22
|
+
* 响应「有实质」判据(单源——判空面与清零面读同一份;AGENT-LOOP.md §6 完成守卫 · D-AL28):有非空正文
|
|
23
23
|
* **或** 有工具调用 ⇒ 实质,两种形都证明「刚才那次空是瞬时的」。此处也是唯一判空式,不另写
|
|
24
24
|
* `.trim() === ""`——两份一漂,判空与清零就不再是同一件事(判空加宽、清零面漏跟)。
|
|
25
25
|
* 「或」不是「且」:带工具调用但正文为空(提供端常见形态)必须判为实质——写成「且」,工具轮就不清零,
|
|
@@ -31,7 +31,17 @@ export function isSubstantiveResponse(response) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* 纯文本收尾入线(#2647 · 回声键的写面):assistant 消息带上 `reasoning_content`——有原文写原文,
|
|
35
|
+
* 无原文在思考模式下写空串。旧写法只 push `content`,服务端给的原文与「没有原文」都进不了机读历史,
|
|
36
|
+
* 下一次以工具结果结尾的请求就缺键 400(真机读数:同一失败体补键 200、缺键 400)。
|
|
37
|
+
*/
|
|
38
|
+
function pushAssistantText(agent, response) {
|
|
39
|
+
const spec = specForModel(agent.provider?.model)
|
|
40
|
+
pushReal(agent, assistantTextMessage(response, spec, isThinkingRequest(agent.provider ?? null, spec), agent.provider ?? null))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Handle a model turn with zero tool calls. May push back (verify/advisor)
|
|
35
45
|
* or accept the completion.
|
|
36
46
|
*
|
|
37
47
|
* @param {object} agent
|
|
@@ -53,7 +63,7 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
|
|
|
53
63
|
const retries = agent._emptyRetries ?? 0
|
|
54
64
|
if (retries < MAX_EMPTY_RETRIES) {
|
|
55
65
|
agent._emptyRetries = retries + 1
|
|
56
|
-
agent
|
|
66
|
+
pushInject(agent, {
|
|
57
67
|
role: "user",
|
|
58
68
|
content: "[System reminder: your last response was empty — the provider returned no content (likely reasoning was exhausted or output was truncated). Respond again, continuing your work from where you left off.]",
|
|
59
69
|
})
|
|
@@ -68,28 +78,6 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
|
|
|
68
78
|
)
|
|
69
79
|
}
|
|
70
80
|
|
|
71
|
-
// Pending tasks: remind the model ONCE before it declares itself done.
|
|
72
|
-
// Deliberately capped at one pushback (reported pain: unbounded looping when a
|
|
73
|
-
// pending item can't be resolved). After the single reminder the model is free
|
|
74
|
-
// to finish — updating the task list (task tool) resets the budget, so a fresh
|
|
75
|
-
// list state earns one fresh reminder.
|
|
76
|
-
// F10(催更门连带):工程模式下 task 工具机械停用(装配摘除 + execute 拒)⇒ 不再发指向被拒
|
|
77
|
-
// 工具的提醒(死胡同提醒防线);列表本体与 `_taskPushbacks` 预算语义零改。
|
|
78
|
-
// TIMEOUT-DIGEST.md §2.3(#29):后台池 live 时不推回——池在飞时回合本就还会被 settle 唤醒,
|
|
79
|
-
// 此时催 task 只会拖回合;判据复用 `poolLive`(与挂起尾巴同一口径,不立第二处)。
|
|
80
|
-
if (depth === 0 && !agent.config?.agent?.engineering && !poolLive(agent) && agent.tasks.some((t) => t.status === "pending") && (agent._taskPushbacks ?? 0) < 1) {
|
|
81
|
-
agent._taskPushbacks = (agent._taskPushbacks ?? 0) + 1
|
|
82
|
-
const pending = agent.tasks.filter((t) => t.status === "pending").map((t) => t.title).join(", ")
|
|
83
|
-
pushReal(agent, { role: "assistant", content: response.content })
|
|
84
|
-
agent.history.push({
|
|
85
|
-
role: "user",
|
|
86
|
-
content: `[System reminder: you still have pending tasks: ${pending}. Update their status with the task tool before finishing — if they're done, mark them done; if they're not applicable, remove them. (This is your only reminder — if you choose not to, finish anyway.)]`,
|
|
87
|
-
})
|
|
88
|
-
callbacks.onSubTurnBreak?.()
|
|
89
|
-
callbacks.onTurnEnd?.(agent, turn)
|
|
90
|
-
return { action: "continue", guardPushbacks, honestReminderInjected, advisorPushbacks }
|
|
91
|
-
}
|
|
92
|
-
|
|
93
81
|
// --- verify guard: push model to verify mutated files before completion ---
|
|
94
82
|
// OPT-IN ONLY (verifyGuard: true). Engineering mode is excluded because it
|
|
95
83
|
// uses flow-driven review, not per-turn mechanical pushback (ENGINEERING-MODE.md §2.3).
|
|
@@ -99,8 +87,8 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
|
|
|
99
87
|
// Not verified yet → pushback to run verify
|
|
100
88
|
if (agent._mutatedThisRun && !agent._verifiedThisRun && hasCodeMutations(agent) && guardPushbacks < MAX_VERIFY_PUSHBACKS) {
|
|
101
89
|
guardPushbacks++
|
|
102
|
-
|
|
103
|
-
agent
|
|
90
|
+
pushAssistantText(agent, response)
|
|
91
|
+
pushInject(agent, {
|
|
104
92
|
role: "user",
|
|
105
93
|
content: "[System reminder: you modified files in this run but have not verified the changes. Before finishing: run the project's verification yourself (per its AGENTS.md test method), then call verify declaring the outcome via verification.status. verify mechanically gates on your declaration. If verification is genuinely impossible here, say so explicitly in your reply.]",
|
|
106
94
|
})
|
|
@@ -113,8 +101,8 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
|
|
|
113
101
|
// reason, or not declared — not necessarily that a test failed.
|
|
114
102
|
if (agent._verifiedThisRun && agent._verifyPassed === false && agent._verifyRetries < MAX_VERIFY_RETRIES) {
|
|
115
103
|
agent._verifyRetries++
|
|
116
|
-
|
|
117
|
-
agent
|
|
104
|
+
pushAssistantText(agent, response)
|
|
105
|
+
pushInject(agent, {
|
|
118
106
|
role: "user",
|
|
119
107
|
content: `[System reminder: (retry ${agent._verifyRetries}/${MAX_VERIFY_RETRIES}) verify was not passed — either your verification declared failed, was skipped without a reason, or was not declared. Fix or complete your verification, then call verify again declaring the outcome. If you cannot fix after ${MAX_VERIFY_RETRIES} attempts, explain honestly what's blocking you.]`,
|
|
120
108
|
})
|
|
@@ -125,12 +113,12 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
|
|
|
125
113
|
// Exhausted retries — inject honesty reminder once
|
|
126
114
|
if (agent._verifiedThisRun && agent._verifyPassed === false && agent._verifyRetries >= MAX_VERIFY_RETRIES) {
|
|
127
115
|
if (honestReminderInjected) {
|
|
128
|
-
|
|
116
|
+
pushAssistantText(agent, response)
|
|
129
117
|
return { action: "done", content: response.content, guardPushbacks, honestReminderInjected, advisorPushbacks }
|
|
130
118
|
}
|
|
131
119
|
honestReminderInjected = true
|
|
132
|
-
|
|
133
|
-
agent
|
|
120
|
+
pushAssistantText(agent, response)
|
|
121
|
+
pushInject(agent, {
|
|
134
122
|
role: "user",
|
|
135
123
|
content: `[System reminder: ${MAX_VERIFY_RETRIES} verify attempts exhausted. You have not passed verification. Either state explicitly that your verification could not be completed, or run verify again once it is. If your verification could not be completed, say so explicitly in your reply to the user — state what you tried and what you believe is blocking you, and do not present the work as complete; the user needs to know it is unfinished.]`,
|
|
136
124
|
})
|
|
@@ -164,8 +152,8 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
|
|
|
164
152
|
if (unreviewed && (agent._advisorReminders ?? 0) < MAX_ADVISOR_REMINDERS && advisorPushbacks < MAX_ADVISOR_PUSHBACKS) {
|
|
165
153
|
agent._advisorReminders = (agent._advisorReminders ?? 0) + 1
|
|
166
154
|
advisorPushbacks++
|
|
167
|
-
|
|
168
|
-
agent
|
|
155
|
+
pushAssistantText(agent, response)
|
|
156
|
+
pushInject(agent, {
|
|
169
157
|
role: "user",
|
|
170
158
|
content: `[System reminder: you changed code in this run and MUST get an advisor review before finishing (round ${rounds + 1}). Call the \`advisor\` tool now. This is required, not optional — do not skip it even if you believe the changes are trivial — the review will be quick either way. After the review, produce a response table for every issue found (see discipline rules for format).${
|
|
171
159
|
agent._advisorReminders >= MAX_ADVISOR_REMINDERS
|
|
@@ -196,8 +184,8 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
|
|
|
196
184
|
&& !agent._advisorHonestySent
|
|
197
185
|
) {
|
|
198
186
|
agent._advisorHonestySent = true
|
|
199
|
-
|
|
200
|
-
agent
|
|
187
|
+
pushAssistantText(agent, response)
|
|
188
|
+
pushInject(agent, {
|
|
201
189
|
role: "user",
|
|
202
190
|
content: `[System reminder: ${agent._advisorReminders ?? 0} advisor reminders sent. You have not had this code reviewed. Either call the \`advisor\` tool now, or state explicitly in your reply that this code has not been reviewed — do not present the work as reviewed. The user needs to know it is unreviewed.]`,
|
|
203
191
|
})
|
|
@@ -207,6 +195,6 @@ export function handleCompletion(agent, response, depth, turn, guardPushbacks, h
|
|
|
207
195
|
}
|
|
208
196
|
}
|
|
209
197
|
|
|
210
|
-
|
|
198
|
+
pushAssistantText(agent, response)
|
|
211
199
|
return { action: "done", content: response.content, guardPushbacks, honestReminderInjected, advisorPushbacks }
|
|
212
200
|
}
|
|
@@ -3,23 +3,29 @@
|
|
|
3
3
|
* 同形重复族 #127 ④(续跑循环双写——CLI `thincoder-cli/src/tui/agent-turn.mjs` ∥ VSC
|
|
4
4
|
* `thincoder-vscode/src/extension/panel-turn-loop.mjs`)收口:端壳循环只接线本函数,
|
|
5
5
|
* 零第二分支;判定口径改一处 ⇒ 两端同轮生效(原双改纪律退役)。
|
|
6
|
-
* 三格判定(口径 = TURN-CAP-CONTINUE.md D-
|
|
7
|
-
* ① ContinueError
|
|
8
|
-
*
|
|
6
|
+
* 三格判定(口径 = `docs/core/design/TURN-CAP-CONTINUE.md` §2 ∥ §6 D-TC20):
|
|
7
|
+
* ① ContinueError(撞帽)——`autoApprove` 真(AUTO 档:用户已授权无人值守继续)⇒ "resume",
|
|
8
|
+
* 续期不再询问;假(手动档)⇒ "ask"(问「Continue?」,与用户回合问出同一句话)。
|
|
9
|
+
* 轮次类型不进这一支,此刻有没有人可问也不进——判据轴是批准档。
|
|
9
10
|
* ② 中止(AbortError ∥ reason 在场)——带注入消息的 interrupt(Ctrl+I)⇒ "resume";其余 ⇒ "stop"。
|
|
10
11
|
* ③ 其余错误 ⇒ "error";无错误(正常完成)⇒ "done"。
|
|
11
12
|
* `reason` = 调用方解析后的中止 reason(两端同式 = 回合 controller `signal.reason` 单源——#677 修正轮对齐;
|
|
12
13
|
* 核不臆测宿主 signal 源)。
|
|
13
|
-
* `autoApprove` =
|
|
14
|
+
* `autoApprove` = 必填布尔(本端批准档):缺参 ∥ 非布尔在边界拒收并点名参数——缺省 false 会让
|
|
15
|
+
* 无人值守回合静默停在无人可见的询问上。它是主 agent 回合的判定点;异步子执行体的续跑走父侧
|
|
16
|
+
* 检查点,同步子执行体撞帽由用户卡裁定,都不经本函数(`docs/core/design/TURN-CAP-CONTINUE.md` §2)。
|
|
14
17
|
*/
|
|
15
18
|
import { ContinueError } from "./helpers.mjs"
|
|
16
19
|
|
|
17
|
-
/** @returns {"done"|"
|
|
18
|
-
export function continueDecision(error, {
|
|
20
|
+
/** @returns {"done"|"resume"|"ask"|"stop"|"error"} */
|
|
21
|
+
export function continueDecision(error, { autoApprove, reason = null } = {}) {
|
|
22
|
+
if (typeof autoApprove !== "boolean") {
|
|
23
|
+
throw new Error("continueDecision: autoApprove is required and must be a boolean — pass this end's approval tier (the caller's `autoApprove`); an absent default would park an unattended turn on a question nobody sees")
|
|
24
|
+
}
|
|
19
25
|
if (error == null) return "done"
|
|
20
|
-
if (error instanceof ContinueError) return
|
|
26
|
+
if (error instanceof ContinueError) return autoApprove ? "resume" : "ask"
|
|
21
27
|
if (error.name === "AbortError" || reason != null) {
|
|
22
28
|
return reason?.interrupt && reason?.message ? "resume" : "stop"
|
|
23
29
|
}
|
|
24
30
|
return "error"
|
|
25
|
-
}
|
|
31
|
+
}
|
package/agent/digest-account.mjs
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* agent/digest-account.mjs — 消化账务单件(AGENT-LOOP-ASYNC-POOL.md §
|
|
3
|
-
* 台账 #930;批 digest-retry-amplify · 台账 #1850
|
|
2
|
+
* agent/digest-account.mjs — 消化账务单件(AGENT-LOOP-ASYNC-POOL.md §8 · 批 digest-accounting ·
|
|
3
|
+
* 台账 #930;批 digest-retry-amplify · 台账 #1850:**投递恒一次**——模型明写 `deferred` 与沉默同判,
|
|
4
|
+
* 两者都只计未签收轮、都不触发第二次投递):投递 ≠ 销账——报告不许无声消失。
|
|
4
5
|
*
|
|
5
|
-
* 三角色(§
|
|
6
|
+
* 三角色(§8.1):**投递**(注入但留容器——每条恒一次)/ **见账**(消化轮收尾逐条机检账目覆盖)/
|
|
6
7
|
* **销账**(覆盖才离容器 + 释放 report;未覆盖计一个未签收轮,达 `DA_MISS_LIMIT` ⇒ 升级)。本档承载:
|
|
7
|
-
* 常量(`DA_MISS_LIMIT`)/ 回合分类(`isDigestRound`)/ 投递门控(`shouldDeliverEntry`)/
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* 常量(`DA_MISS_LIMIT`)/ 回合分类(`isDigestRound`)/ 投递门控(`shouldDeliverEntry`)/
|
|
9
|
+
* 账目合同(`digestDisposition` 处置词解析 ∥ `coversDigestId` 薄壳 ∥ `digestAccountRequirement` 要求行)/
|
|
10
|
+
* 见账 pass(`accountDigestRound`——销账 ∥ 未签收轮)/ 升级四步(`escalateUndigested`——满上限 ∥
|
|
11
|
+
* 会话 idle 退出两支共用,终局披露含在内)/
|
|
12
|
+
* 读面(`unsettledRows` · `unsettledRow` · `unsettledCount`)/ 落痕清位 ∕ 取件助手
|
|
13
|
+
* (`armAccountRound` · `harvestAccountOutput`)。
|
|
11
14
|
*
|
|
12
|
-
* 载体(§
|
|
15
|
+
* 载体(§8.1):`_daSession`(会话标记——挂起会话置 / 复位,`agent/suspension.mjs`)与
|
|
13
16
|
* `_unsettledDigests`(升级账本——经 `async-settle.mjs` 写助手);账目态挂条目字段
|
|
14
|
-
* (`_daDelivered`
|
|
15
|
-
* 直连 `runAgent`)零账目动作(不销账 / 不计未签收轮 /
|
|
16
|
-
*
|
|
17
|
+
* (`_daDelivered` = 内容已在历史 ∥ `_daMissRounds` = 未签收轮数)。
|
|
18
|
+
* **fallback 面**(无 `_daSession`——headless / 直连 `runAgent`)零账目动作(不销账 / 不计未签收轮 /
|
|
19
|
+
* 不升级):缺省条逐字沿用取尽语义(先离容后注入);
|
|
20
|
+
* 已投递未销账条同判据跳过且留容器(§8 出口缝② · 父侧裁定 2026-10-05)。
|
|
17
21
|
*
|
|
18
|
-
* 边界(§
|
|
22
|
+
* 边界(§8.2):不做处理质量机检(只保「不许无声」);升级账本无 TTL(会话期面——
|
|
19
23
|
* 中止清、idle 存续)。
|
|
20
24
|
*/
|
|
21
25
|
import { logEvent, errText } from "../log.mjs"
|
|
22
|
-
import {
|
|
26
|
+
import { pushInject, pushRecord } from "../context.mjs"
|
|
23
27
|
import { carrierField, releaseSettledEntry, appendUnsettledDigest } from "../agent-tools/async-settle.mjs"
|
|
24
28
|
import { DIGEST_ACCOUNT_DOMAIN } from "./helpers.mjs"
|
|
25
29
|
|
|
26
|
-
/** 同条未签收上限(§
|
|
30
|
+
/** 同条未签收上限(§8.3):积满 DA_MISS_LIMIT 个未签收消化轮 ⇒ 升级(离容器 + 账本 + 提醒 + 终局披露一次)。
|
|
27
31
|
* 依据 = 「连空 3 轮仍须在容器、第 4 轮补签仍能销账」的**下界**(N = 4——无额外余量;可复算;不取观测值——
|
|
28
32
|
* 修前观测受「总投递 ≤3」删失)。 */
|
|
29
33
|
export const DA_MISS_LIMIT = 4
|
|
30
34
|
|
|
31
35
|
/**
|
|
32
|
-
* 回合分类单点(§
|
|
36
|
+
* 回合分类单点(§8.1):账目只属**消化轮**(autoTurn ∧ 非上行唤醒轮 ∧ 非 timer 轮)——
|
|
33
37
|
* timer / 上行轮投递不销账(其账目在后续消化轮)。
|
|
34
38
|
*/
|
|
35
39
|
export function isDigestRound(opts) {
|
|
@@ -37,53 +41,82 @@ export function isDigestRound(opts) {
|
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
/**
|
|
40
|
-
* 投递门控(§
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
+
* 投递门控(§9.1 单点谓词 · 批 digest-retry-amplify 收为单门):未投递 ∧ 本回合 = 系统轮(`autoTurn`)
|
|
45
|
+
* ⇒ 投(首次投递——**用户回合零投递**);已投递 ⇒ 恒跳过(**每条只投一次**——重投回路退场,§9.1)。
|
|
46
|
+
* 模型明写 `deferred` 不换一次重投:推迟与沉默同判,两者都只计未签收轮;内容靠满 `DA_MISS_LIMIT` 的
|
|
47
|
+
* 升级终局披露回会话(`accountDigestRound` 的 ④)。本谓词只读一条事实——`_daDelivered`(内容已在历史)。
|
|
48
|
+
* 注入抛错 ⇒ `_daDelivered` 未置 ⇒ 下一系统轮重试注入(注入失败的再试,不属投递回路)。
|
|
44
49
|
* 注:`autoTurn` 判据由调用方(`run-start.mjs` 会话态支)传入;回退面(非会话态支)不经本谓词。
|
|
45
50
|
*/
|
|
46
51
|
export function shouldDeliverEntry(entry, autoTurn) {
|
|
47
|
-
if (
|
|
48
|
-
return
|
|
52
|
+
if (autoTurn !== true) return false
|
|
53
|
+
return entry?._daDelivered !== true
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
/** 账目要求行(§
|
|
56
|
+
/** 账目要求行(§8.2):核常量(helpers.mjs)+ 两个占位动态代换——未销账 id 清单 `<ids>` ∥
|
|
57
|
+
* 未签收上限 `<limit>`(数的一处真身 = 本档 `DA_MISS_LIMIT`;helpers 反向 import 本档成环)。 */
|
|
52
58
|
export function digestAccountRequirement(ids) {
|
|
53
|
-
return DIGEST_ACCOUNT_DOMAIN
|
|
59
|
+
return DIGEST_ACCOUNT_DOMAIN
|
|
60
|
+
.replace("<ids>", ids.map((id) => `#${id}`).join(", "))
|
|
61
|
+
.replace("<limit>", String(DA_MISS_LIMIT))
|
|
54
62
|
}
|
|
55
63
|
|
|
56
64
|
/**
|
|
57
|
-
*
|
|
58
|
-
* (id 词界 = 后随非数字)⇒
|
|
59
|
-
*
|
|
65
|
+
* 处置词解析单点(§8.2):输出文本内**存在一行**同时含标记 `[digest-ack` 与 `#<id>`
|
|
66
|
+
* (id 词界 = 后随非数字)⇒ 读标记方括号后第一个词:`digested` 归「已处理」、
|
|
67
|
+
* `deferred` 归「本轮未处理」;别的词 ∥ 缺词 ⇒ null(与零痕迹同判:计轮、不重投)。
|
|
68
|
+
* 要点 ∥ 原因仍是散文,不参与机检。
|
|
69
|
+
* 多行 ∥ 同一行多处同 id 出现:任一处 `deferred` ⇒ deferred(两个相反信号只能取保守侧,
|
|
70
|
+
* 机检读不到散文);否则任一处 `digested` ⇒ digested;否则 null。
|
|
71
|
+
* 词形按 ACK 约定的原样小写比对——大小写变体落到 null 一侧(不销账,保守);
|
|
72
|
+
* 零工具轮可满足(纯文本判据)。
|
|
60
73
|
* 注:行内扫**全部**出现位(长 id 首现不吻合不弃行——如 id=1 行内先见 `#12` 后见 `#1`)。
|
|
61
74
|
*/
|
|
62
|
-
export function
|
|
75
|
+
export function digestDisposition(output, id) {
|
|
63
76
|
const key = `#${id}`
|
|
77
|
+
let digested = false
|
|
64
78
|
for (const line of String(output ?? "").split(/\r?\n/)) {
|
|
65
79
|
const marker = line.indexOf("[digest-ack")
|
|
66
80
|
if (marker < 0) continue
|
|
67
81
|
for (let from = marker; ;) {
|
|
68
82
|
const at = line.indexOf(key, from)
|
|
69
83
|
if (at < 0) break
|
|
84
|
+
from = at + 1 // 无论判成与否都续扫下一出现位(同长 id 前缀不吞后随正例)
|
|
70
85
|
const after = line[at + key.length]
|
|
71
|
-
if (after
|
|
72
|
-
|
|
86
|
+
if (after !== undefined && /[0-9]/.test(after)) continue
|
|
87
|
+
const word = dispositionWord(line, at + key.length)
|
|
88
|
+
if (word === "deferred") return "deferred"
|
|
89
|
+
if (word === "digested") digested = true
|
|
73
90
|
}
|
|
74
91
|
}
|
|
75
|
-
return
|
|
92
|
+
return digested ? "digested" : null
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 处置词取词(§8.2):标记 `]`(自 id 之后最近的那一个)之后第一个词;不是两个词之一 ⇒ null。 */
|
|
96
|
+
function dispositionWord(line, from) {
|
|
97
|
+
const close = line.indexOf("]", from)
|
|
98
|
+
if (close < 0) return null
|
|
99
|
+
const word = /^[A-Za-z]+/.exec(line.slice(close + 1).trimStart())?.[0]
|
|
100
|
+
return word === "digested" || word === "deferred" ? word : null
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** 账目覆盖机检(§8.2 薄壳):处置词为 `digested` 才算覆盖——导出名与签名照旧,
|
|
104
|
+
* 三值语义由 `digestDisposition` 承载。当前无生产调用者(见账 pass 直调 `digestDisposition`):
|
|
105
|
+
* 保留导出只为导出面兼容,不为新增调用点。 */
|
|
106
|
+
export function coversDigestId(output, id) {
|
|
107
|
+
return digestDisposition(output, id) === "digested"
|
|
76
108
|
}
|
|
77
109
|
|
|
78
110
|
/**
|
|
79
|
-
* 见账 pass(§
|
|
111
|
+
* 见账 pass(§8.3——消化轮收尾 `finalizeAgentTurn` 单点调用;调用方已判 `isDigestRound ∧
|
|
80
112
|
* `_daSession` ∧ 非会话停止径):
|
|
81
|
-
* - 投递账 = pending ∩ `_daDelivered
|
|
82
|
-
* -
|
|
83
|
-
*
|
|
84
|
-
*
|
|
113
|
+
* - 投递账 = pending ∩ `_daDelivered`;处置词 `digested` ⇒ 离容器(splice)+ `releaseSettledEntry`(含 report 释放);
|
|
114
|
+
* - `deferred` 与沉默同判 ⇒ 两者都只 `_daMissRounds += 1`(缺痕 = output == null——抛错 / 撞帽 / 未收口 /
|
|
115
|
+
* 整 run 零非空正文),都不换第二次投递:推迟不兑换成重投,内容靠满上限的升级终局披露回会话(§9.1)。
|
|
116
|
+
* 未覆盖支 < `DA_MISS_LIMIT` ⇒ 条留容器、**零投递动作**;达上限 ⇒ **升级**
|
|
117
|
+
* (四步固定先后:账本 → 提醒 → 离容器 → 终局披露——实现见 `escalateUndigested`),与处置词无关。
|
|
85
118
|
*
|
|
86
|
-
* async(§
|
|
119
|
+
* async(§8.3 升级支 ④):披露复用首投注入器 ⇒ pass 变 async——唯一调用点 = `run-stages.mjs` 的
|
|
87
120
|
* finalize 单点(已 await)。披露逐条 try/catch:判据 = **披露失败不得使报告离开可见面**
|
|
88
121
|
* (账本 + 提醒 + status 面 `preview` 已在披露之前落定,失败降级可见性、留痕不静默)。
|
|
89
122
|
*/
|
|
@@ -95,8 +128,11 @@ export async function accountDigestRound(carrier) {
|
|
|
95
128
|
const upgraded = []
|
|
96
129
|
for (const entry of [...pending]) {
|
|
97
130
|
if (entry?._daDelivered !== true) continue
|
|
98
|
-
|
|
131
|
+
const disposition = output == null ? null : digestDisposition(output, entry.id)
|
|
132
|
+
if (disposition === "digested") { covered.push(entry); continue }
|
|
99
133
|
entry._daMissRounds = (entry._daMissRounds ?? 0) + 1
|
|
134
|
+
// 未覆盖(含显式 `deferred`)只计未签收轮,不记第二次投递:推迟与沉默同判(§9.1)。
|
|
135
|
+
// 投递账保持为真——它只说「内容已在历史」,起跑回退支 ∥ 退出 idle 清场 ∥ 本 pass 跳过条件都照旧读它(§8.2)。
|
|
100
136
|
if (entry._daMissRounds >= DA_MISS_LIMIT) upgraded.push(entry)
|
|
101
137
|
}
|
|
102
138
|
for (const entry of covered) {
|
|
@@ -105,36 +141,60 @@ export async function accountDigestRound(carrier) {
|
|
|
105
141
|
releaseSettledEntry(entry)
|
|
106
142
|
}
|
|
107
143
|
if (upgraded.length === 0) return { covered: covered.length, unsettled: 0 }
|
|
108
|
-
//
|
|
109
|
-
|
|
144
|
+
// 升级四步(§8.3——与周期终点支共用 `escalateUndigested`,本支 reason = "limit")。
|
|
145
|
+
await escalateUndigested(carrier, "limit", upgraded)
|
|
146
|
+
return { covered: covered.length, unsettled: upgraded.length }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 升级四步(§8.3——两支共用、先到者为准:满 `DA_MISS_LIMIT` 个未签收轮(reason `"limit"`,调用点 =
|
|
151
|
+
* 本档 `accountDigestRound`)∥ 会话进入 idle 退出前结账(reason `"idle"`,调用点 =
|
|
152
|
+
* `thincoder-core/agent/suspension.mjs` 的 `startSuspension` 收尾、`finishSuspension` 之前)。
|
|
153
|
+
* 固定先后:① 账本 → ② 提醒 → ③ 离容器 → ④ 终局披露——纯内存的两面先落、披露最后:披露是四步里唯一
|
|
154
|
+
* 的 I/O,抛错会中断余下条目判定并越过 `run-stages.mjs` 的 `_inAutoTurn = false` 与 guard 快照。
|
|
155
|
+
* 升级不开任何回合:四步都是机械动作,不需要模型轮——会话沉寂后再没有消化轮,保底也不交给运气。
|
|
156
|
+
*
|
|
157
|
+
* @param {object} carrier 载体(容器 `_pendingAsyncResults` ∥ 升级账本 `_unsettledDigests`)
|
|
158
|
+
* @param {"limit"|"idle"} reason 起因——必填、无缺省(缺省会把「会话沉寂」说成「满 4 轮」)
|
|
159
|
+
* @param {object[]} entries 本次升级的条目——必填,选择面各在调用点:上限支 = 达上限集,终点支 =
|
|
160
|
+
* 容器内 `_daDelivered === true` 的条;空集 / 非数组 ⇒ 零动作
|
|
161
|
+
* @returns {Promise<number>} 升级条数
|
|
162
|
+
*/
|
|
163
|
+
export async function escalateUndigested(carrier, reason, entries) {
|
|
164
|
+
if (!Array.isArray(entries) || entries.length === 0) return 0
|
|
165
|
+
const pending = carrierField(carrier, "_pendingAsyncResults")
|
|
110
166
|
// ① 入账本(纯内存):账本记录 = **快照**,只喂 status 面与 `preview`——被注入的对象是原条目(见 ④)。
|
|
111
|
-
for (const entry of
|
|
167
|
+
for (const entry of entries) {
|
|
112
168
|
appendUnsettledDigest(carrier, {
|
|
113
169
|
id: String(entry.id),
|
|
114
170
|
role: entry.role ?? "subagent",
|
|
115
|
-
missRounds: entry._daMissRounds,
|
|
171
|
+
missRounds: entry._daMissRounds ?? 0,
|
|
116
172
|
report: entry.report ?? null,
|
|
117
173
|
at: Date.now(),
|
|
118
174
|
})
|
|
119
175
|
}
|
|
120
|
-
// ②
|
|
176
|
+
// ② 提醒:恰一条(待发队 + 人读线——`pushInject` + `pushRecord`)+ 恰一条留痕(字段单源 = LOGGING.md §6.2)。
|
|
121
177
|
// 注:`ids` 以 join 串落盘——`logEvent` 只收标量(数组字段会被静默丢弃——先例 `ev:discarded`)。
|
|
122
178
|
{
|
|
123
|
-
const ids =
|
|
124
|
-
|
|
125
|
-
|
|
179
|
+
const ids = entries.map((entry) => String(entry.id))
|
|
180
|
+
const msg = { role: "user", content: unsettledReminder(entries.length, ids, reason) }
|
|
181
|
+
pushInject(carrier, msg)
|
|
182
|
+
pushRecord(carrier, msg)
|
|
183
|
+
logEvent("ev:unsettled", { n: entries.length, ids: ids.join(", ") })
|
|
126
184
|
}
|
|
127
185
|
// ③ 离容器(纯结构):至此条目定态「已升级」,不再参与判定 ⇒ 披露结构上至多一次。
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
186
|
+
if (Array.isArray(pending)) {
|
|
187
|
+
for (const entry of entries) {
|
|
188
|
+
const i = pending.indexOf(entry)
|
|
189
|
+
if (i >= 0) pending.splice(i, 1)
|
|
190
|
+
}
|
|
131
191
|
}
|
|
132
192
|
// ④ 终局披露:**按 role 与首投同分流**(consult → `injectConsultResult`;其余 → `injectAsyncResult`——
|
|
133
193
|
// 内部已分派 bg / browser);不新造第二投递形。注入的对象 = **原条目**(墓碑值
|
|
134
194
|
// `error != null ? "failed" : "consumed"` 与评审族投递水印 `entry.run` 都按原条目字段才成立)。
|
|
135
195
|
const { injectAsyncResult } = await import("../agent-tools/subagent.mjs")
|
|
136
196
|
const { injectConsultResult } = await import("../agent-tools/consult.mjs")
|
|
137
|
-
for (const entry of
|
|
197
|
+
for (const entry of entries) {
|
|
138
198
|
try {
|
|
139
199
|
if (entry.role === "consult") await injectConsultResult(carrier, entry)
|
|
140
200
|
else await injectAsyncResult(carrier, entry)
|
|
@@ -144,16 +204,30 @@ export async function accountDigestRound(carrier) {
|
|
|
144
204
|
logEvent("ev:unsettled-disclose-failed", { id: String(entry.id), err: errText(e, 200) })
|
|
145
205
|
}
|
|
146
206
|
}
|
|
147
|
-
return
|
|
207
|
+
return entries.length
|
|
148
208
|
}
|
|
149
209
|
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
210
|
+
/** 升级提醒行的起因句(§8.3 引文块的两支):值即「被升级成未处理」的那一刻。 */
|
|
211
|
+
const UNSETTLED_CAUSE = {
|
|
212
|
+
limit: `after ${DA_MISS_LIMIT} digest rounds`,
|
|
213
|
+
idle: "before this session went idle",
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** 升级提醒行(§8.3——含 n / 起因 / id 清单与接手指引)。两支(满上限 ∥ 会话 idle 退出)措辞只在
|
|
217
|
+
* 起因那一句不同,其余逐字相同。`reason` 必填、无缺省:缺省会静默借用另一支措辞,把「会话沉寂」
|
|
218
|
+
* 说成「满 4 轮」;两个取值之外的 reason 当场抛(枚举闭合,不落回任一支)。 */
|
|
219
|
+
export function unsettledReminder(n, ids, reason) {
|
|
220
|
+
const cause = typeof reason === "string" && Object.prototype.hasOwnProperty.call(UNSETTLED_CAUSE, reason)
|
|
221
|
+
? UNSETTLED_CAUSE[reason]
|
|
222
|
+
: null
|
|
223
|
+
if (cause === null) {
|
|
224
|
+
throw new Error(`unsettledReminder: unknown reason ${JSON.stringify(reason)} — "limit" | "idle" is required (no default)`)
|
|
225
|
+
}
|
|
226
|
+
return `[System reminder: ${n} background report(s) were delivered but never accounted ${cause} — they are marked UNSETTLED: ${ids.map((id) => `#${id}`).join(", ")}. Their content was delivered once in this conversation and is re-delivered once right below as the final delivery — if that copy is missing, the delivery failed and the full text stays readable via subagent action:'status'. Process it there or re-spawn the work.]`
|
|
153
227
|
}
|
|
154
228
|
|
|
155
229
|
/**
|
|
156
|
-
* 读面(§
|
|
230
|
+
* 读面(§8.4——status 段 ∥ 端面残余行共用单点):行 = `{ id, role, state, attempts }`;
|
|
157
231
|
* state ∈ `awaiting-digest`(在途未投递 ∥ 已投递未判 = `attempts == 0`)/ `unaccounted`(判过未签收 =
|
|
158
232
|
* `attempts > 0`)/ `unsettled`(已升级——随携 `preview` ≤400 字符);`attempts` = 未签收轮数 `_daMissRounds`。
|
|
159
233
|
*/
|
|
@@ -182,13 +256,13 @@ export function unsettledRows(carrier) {
|
|
|
182
256
|
return rows
|
|
183
257
|
}
|
|
184
258
|
|
|
185
|
-
/** 单查 id 同解析(§
|
|
259
|
+
/** 单查 id 同解析(§8.4 单查序第三 / 四站):命中 pending / 升级账本 ⇒ 行形同上;未命中 ⇒ null。 */
|
|
186
260
|
export function unsettledRow(carrier, id) {
|
|
187
261
|
const key = String(id)
|
|
188
262
|
return unsettledRows(carrier).find((row) => row.id === key) ?? null
|
|
189
263
|
}
|
|
190
264
|
|
|
191
|
-
/** 端面残余行判据(§
|
|
265
|
+
/** 端面残余行判据(§8.4):pending 中 `_daMissRounds > 0` 条数(与状态面 `unaccounted` 同判据;
|
|
192
266
|
* 升级条已离容器——由升级提醒承载)。 */
|
|
193
267
|
export function unsettledCount(carrier) {
|
|
194
268
|
const pending = carrierField(carrier, "_pendingAsyncResults")
|
|
@@ -197,17 +271,17 @@ export function unsettledCount(carrier) {
|
|
|
197
271
|
return n
|
|
198
272
|
}
|
|
199
273
|
|
|
200
|
-
/** 落痕清位(§
|
|
274
|
+
/** 落痕清位(§8.3——`run-start.mjs` 会话态起跑即清;fallback 零动作):父字段 ∥ history 双清。
|
|
201
275
|
* 注:核内写点落**父字段**(`turn-loop.mjs` 的 `agent._lastRunOutput`——逐轮追加,本批 #939
|
|
202
276
|
* 收正;抗 `history` 整体替换——`context.mjs` `applyCompression`);`history` 级为兼容读形
|
|
203
|
-
* (`harvestAccountOutput` 回退分支)——该痕不属跨 run 字段集,§
|
|
277
|
+
* (`harvestAccountOutput` 回退分支)——该痕不属跨 run 字段集,§8.3 边界句。 */
|
|
204
278
|
export function armAccountRound(carrier) {
|
|
205
279
|
if (!carrier || typeof carrier !== "object") return
|
|
206
280
|
carrier._lastRunOutput = null
|
|
207
281
|
if (carrier.history && typeof carrier.history === "object") carrier.history._lastRunOutput = null
|
|
208
282
|
}
|
|
209
283
|
|
|
210
|
-
/** 落痕取件(§
|
|
284
|
+
/** 落痕取件(§8.3——载体吸收读:父字段优先 / 回退 `history`);读值 = 本 run 多轮累积文本(#939);
|
|
211
285
|
* 缺痕(本 run 零输出落痕——零模型轮 / 起跑即断 / 每轮正文皆空)⇒ null。 */
|
|
212
286
|
export function harvestAccountOutput(carrier) {
|
|
213
287
|
const own = carrier?._lastRunOutput
|
package/agent/dispatch-run.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import { snapshotForUndo } from "../undo-stack.mjs"
|
|
|
13
13
|
import { PEER_WRITE_TOOLS, peerCollabNote, recordPeerWrites, markClaimNoted } from "../peer-domains.mjs"
|
|
14
14
|
import { logToolError, noteExecutedMutation } from "./dispatch-gates.mjs"
|
|
15
15
|
|
|
16
|
-
/** console 回显预算(AGENT-LOOP.md §
|
|
16
|
+
/** console 回显预算(AGENT-LOOP.md §5.3 结果 · #863):采集端 cap = 与 helpers.mjs `TOOL_RESULT_OFFLOAD_LIMIT`
|
|
17
17
|
* 同值(65536 字符)——累计到限停收(超出丢弃);发生丢弃 ⇒ 回显段尾恰一行截断标记(逐字——两路径同款)。 */
|
|
18
18
|
const CONSOLE_CAPTURE_LIMIT = 64 * 1024
|
|
19
19
|
const CONSOLE_TRUNCATED_MARK = "[console truncated at 65536 chars]"
|
package/agent/dispatch.mjs
CHANGED
|
@@ -258,8 +258,9 @@ export async function executeToolCalls(agent, toolByName, toolCalls, callbacks,
|
|
|
258
258
|
// ---- B7 3a JIT 缝(相位一末 ∕ 相位二前——原 VSC「派发前」语义;`depth === 0` 门)--------
|
|
259
259
|
// 作用域规则注入:打点 = `prepared` 非拒项 `{tool, args}`(即将执行集);注入源 = 本 run 尾块
|
|
260
260
|
// 读点缓存 `agent._rules.scoped`(核 `prepareRun` 同点写入),去重域 = 会话。子代不注入。
|
|
261
|
+
// 暂停注入(设计档 §7.1「暂停注入」):注入本体不再执行;`history` 形参已退场(线上不再有可写处)。
|
|
261
262
|
if (depth === 0) {
|
|
262
|
-
injectScopedRules(agent,
|
|
263
|
+
injectScopedRules(agent, prepared.filter((p) => p.tool && p.args).map(({ tool, args }) => ({ tool, args })))
|
|
263
264
|
}
|
|
264
265
|
|
|
265
266
|
// ---- Phase 2: order-preserving execution ----
|
package/agent/family-tools.mjs
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* (消灭「同一角色矩阵两份实现」= 本批缺陷的类根因);端差(VSC 装饰链 / settings 追加 /
|
|
7
7
|
* consult 池来源)经 `decorate` 注入——**不传 = 核默认形态**(CLI = 迁出前逐字)。
|
|
8
8
|
*
|
|
9
|
-
* 返回 = 家族段数组(**非**工程模式:`[task, plan, timer, ...depth 家族 / 角色段]
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* 返回 = 家族段数组(**非**工程模式:`[task, plan, timer, knowledge, ...depth 家族 / 角色段]`;
|
|
10
|
+
* 工程模式:`[timer, knowledge, ...depth 家族 / 角色段]`——plan 与 task 都不入表,两个深度同结论
|
|
11
|
+
* (plan:FR31 ① / KD8;task 的理由见 `docs/core/design/TOOLS.md` §1「装配」))——**不含** `agent.tools`
|
|
12
12
|
* 展开与 `extraTools`(调用点各自展开:核 `agent/setup.mjs` 两段式)。
|
|
13
13
|
*
|
|
14
14
|
* 登记册**动态**载入:`agent-tools.mjs` 静态图经 consult/subagent 族可达核 agent 栈
|
|
@@ -211,14 +211,13 @@ export async function assembleFamilyTools({
|
|
|
211
211
|
: role === "consult" ? [recentChangesTool, ledgerReadTool, teamLedgerReadTool, manifestReadTool, ...docTools]
|
|
212
212
|
: [parentChannelTool, ledgerReadTool, teamLedgerReadTool, manifestReadTool, ...docTools]
|
|
213
213
|
|
|
214
|
-
// 固定段(装配序 = agent.tools → 固定段 → 家族段 → extraTools):timer 全模式全深度;
|
|
215
|
-
// plan
|
|
216
|
-
// task
|
|
217
|
-
//
|
|
218
|
-
//
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
: [taskTool, planTool, timerTool, knowledgeTool, ...depthOnly]
|
|
214
|
+
// 固定段(装配序 = agent.tools → 固定段 → 家族段 → extraTools):timer ∥ knowledge 全模式全深度;
|
|
215
|
+
// plan 只进普通模式——ENG-PLAN-EXCLUSION(FR31 ① · KD8 卸载而非「注册 + 报错」· KD11 全深度两端);
|
|
216
|
+
// task 只进普通模式,工程模式不装配——理由见 `docs/core/design/TOOLS.md` §1「装配」。
|
|
217
|
+
// 普通模式固定段逐字不变(FR31 边界)。
|
|
218
|
+
// task 的门只在装配面这一处(`agent-tools/task.mjs` 的 `execute` 不再另判模式)。
|
|
219
|
+
if (engineering) {
|
|
220
|
+
return [timerTool, knowledgeTool, ...depthOnly]
|
|
221
|
+
}
|
|
222
|
+
return [taskTool, planTool, timerTool, knowledgeTool, ...depthOnly]
|
|
224
223
|
}
|