pi-web-ui 0.119.0 → 0.120.0
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 +79 -0
- package/bin/hub-upgrade.mjs +33 -15
- package/bin/lib/atomic-file.mjs +90 -0
- package/dist/server/agent-service-daemon.js +44 -10
- package/dist/server/agent-service.js +803 -106
- package/dist/server/atomic-file.js +130 -5
- package/dist/server/bash-timeout.js +15 -0
- package/dist/server/bash-tool.js +68 -4
- package/dist/server/bg-servers.js +19 -13
- package/dist/server/canvas/canvas-dispatch.js +12 -1
- package/dist/server/client-state.js +56 -14
- package/dist/server/conversation-tool.js +3 -2
- package/dist/server/delegate-task.js +8 -8
- package/dist/server/device-center/group-router-runtime.js +2 -0
- package/dist/server/device-center/hub-upgrade.js +5 -10
- package/dist/server/dispatch-domain-handlers.js +96 -22
- package/dist/server/dispatch-plugin-handlers.js +10 -0
- package/dist/server/dsh/dsh-agent-service.js +9 -9
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/files-service.js +41 -19
- package/dist/server/fs-copy.js +93 -0
- package/dist/server/goal-review-gate.js +2 -2
- package/dist/server/index.js +15 -0
- package/dist/server/job-runner.js +345 -0
- package/dist/server/marker-service.js +42 -26
- package/dist/server/model-session.js +16 -0
- package/dist/server/phone-tool.js +167 -0
- package/dist/server/plan-mode.js +2 -2
- package/dist/server/plugin-api-catalog.js +1 -1
- package/dist/server/plugin-bundled.js +35 -28
- package/dist/server/plugin-installer.js +15 -0
- package/dist/server/plugin-manifest-validate.js +10 -0
- package/dist/server/plugin-materialize.js +161 -0
- package/dist/server/plugin-paths.js +60 -0
- package/dist/server/plugin-removal.js +16 -3
- package/dist/server/plugin-schedule.js +8 -7
- package/dist/server/plugin-secrets.js +7 -3
- package/dist/server/plugin-updater.js +2 -4
- package/dist/server/plugins.js +74 -38
- package/dist/server/preset-fields.js +9 -9
- package/dist/server/process-utils.js +11 -0
- package/dist/server/project-scripts.js +38 -0
- package/dist/server/prompt-composer.js +40 -21
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/quick-ask.js +3 -0
- package/dist/server/remote-ssh-service.js +39 -0
- package/dist/server/scm-commitmsg.js +2 -1
- package/dist/server/serialize.js +8 -0
- package/dist/server/session-list-index.js +246 -0
- package/dist/server/session-list-scan.js +5 -0
- package/dist/server/session-parser.js +16 -0
- package/dist/server/settings-service.js +39 -6
- package/dist/server/subagent-budget.js +68 -0
- package/dist/server/subagent-evidence.js +297 -0
- package/dist/server/subagent-helpers.js +12 -0
- package/dist/server/subagent-ledger.js +401 -0
- package/dist/server/subagent-notify.js +6 -2
- package/dist/server/subagent-security-gate.js +2 -2
- package/dist/server/subagent-settle.js +71 -0
- package/dist/server/subagents.js +497 -79
- package/dist/server/tabs.js +8 -1
- package/dist/server/terminals.js +0 -1
- package/dist/server/tool-manager.js +90 -16
- package/dist/server/tool-prompts.js +5 -1
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +45 -7
- package/dist/server/vision-bridge.js +2 -0
- package/dist/server/workspace-handle.js +119 -17
- package/dist/server/workspace-queue.js +37 -0
- package/docs/README.md +25 -23
- package/docs/architecture-plugins.md +23 -3
- package/docs/device-center.md +1 -1
- package/package.json +15 -3
- package/plugins/catalog.json +13 -2
- package/themes/bases/flow-base.css +7 -16
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BdOJ19Hj.js +1 -0
- package/web/dist/assets/BgTasksModal-SAH2XCkY.js +1 -0
- package/web/dist/assets/{CanvasStudio-2ydYbnpW.js → CanvasStudio-BB_Iq7pl.js} +3 -3
- package/web/dist/assets/{CanvasStudio-DizWvRjn.js → CanvasStudio-DU6O3N4u.js} +3 -3
- package/web/dist/assets/DeviceCenter-By1zVTSY.js +3 -0
- package/web/dist/assets/DeviceCenter-Cnm0Tjrx.js +3 -0
- package/web/dist/assets/{DeviceExecutionSettings-B7R9ONaq.js → DeviceExecutionSettings-qJzbI0Cf.js} +1 -1
- package/web/dist/assets/{DeviceGroups-DFU4cv5b.js → DeviceGroups-DPrQxW6B.js} +1 -1
- package/web/dist/assets/{DeviceGroups-DoaQcxKj.js → DeviceGroups-DoucyUjI.js} +1 -1
- package/web/dist/assets/{Dropdown-Btjt6Dzh.js → Dropdown-kj_NIj6e.js} +1 -1
- package/web/dist/assets/FilePreview-Bub8Y9uq.js +2 -0
- package/web/dist/assets/FilePreview-CC76Z6an.js +2 -0
- package/web/dist/assets/GlobalSearchModal-01nkgw4X.js +1 -0
- package/web/dist/assets/GlobalSearchModal-CiT6wBmR.js +1 -0
- package/web/dist/assets/{GroupConversation-DwZZrMuE.js → GroupConversation-1-lsPO1f.js} +3 -3
- package/web/dist/assets/{GroupConversation-KOi8sa5b.js → GroupConversation-HeiyW_O_.js} +3 -3
- package/web/dist/assets/{GroupWorkItems-FqAL74bC.js → GroupWorkItems-BYJv2XFj.js} +1 -1
- package/web/dist/assets/{HintTip-BOwPzBGR.js → HintTip-DFhoclDw.js} +1 -1
- package/web/dist/assets/{ModelConfigModal-DLIfWKdB.js → ModelConfigModal-D2Ro-jUZ.js} +2 -2
- package/web/dist/assets/{ModelConfigModal-B140kWrs.js → ModelConfigModal-DPc9R1pq.js} +2 -2
- package/web/dist/assets/{NativeCliPanel-BwiLazSq.js → NativeCliPanel-B108d697.js} +3 -3
- package/web/dist/assets/{NativeCliPanel-U0F_EfAU.js → NativeCliPanel-DupvGwQM.js} +3 -3
- package/web/dist/assets/{PiSetupModal-Dc7EQ4L3.js → PiSetupModal-D0HitBfd.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-C3opmPhu.js → ProviderOAuthControls-BLKUEDde.js} +1 -1
- package/web/dist/assets/{SCMPanel-BBxQfmq9.js → SCMPanel-DDbWrUHR.js} +1 -1
- package/web/dist/assets/{SCMPanel-D2t97Vvr.js → SCMPanel-DluNcd2-.js} +1 -1
- package/web/dist/assets/SettingsModal-Cy5lRC97.css +1 -0
- package/web/dist/assets/SettingsModal-DQu18366.js +33 -0
- package/web/dist/assets/SettingsModal-Dm_haPme.js +33 -0
- package/web/dist/assets/{TermXterm-B6nCtO2b.js → TermXterm-SYc-MUk2.js} +1 -1
- package/web/dist/assets/{TerminalPanel-BWB3iSeN.js → TerminalPanel-CgA_lhVT.js} +1 -1
- package/web/dist/assets/{TerminalPanel-CAV2SosY.js → TerminalPanel-vdSIOPjD.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-B0jBPOMc.js → TuiOverlayModal-Cy1jYYIw.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-DGd6fzU6.js → TuiOverlayModal-kXY_4hV8.js} +1 -1
- package/web/dist/assets/{app-globals-CR8Ls9nE.js → app-globals-CBEscsYP.js} +9 -9
- package/web/dist/assets/{canvas-client-B0lkqTtF.js → canvas-client-Clsypfs6.js} +1 -1
- package/web/dist/assets/{desktop-BME3DkyE.js → desktop-C6D9a8HZ.js} +1 -1
- package/web/dist/assets/index-BD29OL9L.js +404 -0
- package/web/dist/assets/index-BlCxbqqr.js +404 -0
- package/web/dist/assets/index-DB55rbKC.css +1 -0
- package/web/dist/assets/{plugin-host-CVgcdBOk.js → plugin-host-VWBcq-LQ.js} +1 -1
- package/web/dist/assets/remote-ssh-client-C2eab5Kw.js +1 -0
- package/web/dist/assets/theme-CpQk_Agp.js +1 -0
- package/web/dist/index.html +10 -10
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/BgTasksModal-CVHW1lRA.js +0 -1
- package/web/dist/assets/BgTasksModal-t5hxW1H6.js +0 -1
- package/web/dist/assets/DeviceCenter-CPaZNBJE.js +0 -3
- package/web/dist/assets/DeviceCenter-DsVakAYR.js +0 -3
- package/web/dist/assets/FilePreview-QGQfD2lV.js +0 -2
- package/web/dist/assets/FilePreview-qez9walH.js +0 -2
- package/web/dist/assets/GlobalSearchModal-B-cnTDJ5.js +0 -1
- package/web/dist/assets/GlobalSearchModal-BvbafjdU.js +0 -1
- package/web/dist/assets/SettingsModal-BqPQNUwF.js +0 -34
- package/web/dist/assets/SettingsModal-l7eeV-Rq.js +0 -34
- package/web/dist/assets/index-BBAQNi6v.js +0 -404
- package/web/dist/assets/index-BYW9d61A.js +0 -404
- package/web/dist/assets/index-BYWs88H2.css +0 -1
- package/web/dist/assets/remote-ssh-client-DEpvwgqG.js +0 -1
- package/web/dist/assets/theme-DVa7Z5Zu.js +0 -1
package/dist/server/subagents.js
CHANGED
|
@@ -3,11 +3,16 @@ import { Type } from "typebox";
|
|
|
3
3
|
import { pick } from "./i18n.js";
|
|
4
4
|
import { resolveSecurityMode } from "./subagent-security-gate.js";
|
|
5
5
|
import { THINKING_LEVELS } from "./subagent-templates.js";
|
|
6
|
+
import { evidenceVerdictLabel, formatEvidenceSummary, normalizeEvidenceInput, } from "./subagent-evidence.js";
|
|
6
7
|
import { CONVERSATION_TOOL_NAME } from "./tool-manager.js";
|
|
7
8
|
import { richQuestionsSchema } from "./question-params.js";
|
|
8
9
|
import { questionsFromMessage } from "./conversation-communication.js";
|
|
9
10
|
import { Value } from "typebox/value";
|
|
10
11
|
export { CONVERSATION_TOOL_NAME } from "./tool-manager.js";
|
|
12
|
+
/** 单次派发的扇出上限:超过就分多次调用,避免一次调用把并发预算挤爆。 */
|
|
13
|
+
export const SUBAGENT_FANOUT_MAX = 16;
|
|
14
|
+
/** 运行键长度与形状:模型给的短名,映射到真实运行身份。 */
|
|
15
|
+
export const SUBAGENT_KEY_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,39}$/;
|
|
11
16
|
export function computeWaitCapMs(watchdogMs) {
|
|
12
17
|
const customSecs = Number(process.env.PI_WEB_SUBAGENT_WAIT_CAP_SECONDS);
|
|
13
18
|
if (Number.isFinite(customSecs) && customSecs > 0) {
|
|
@@ -72,11 +77,13 @@ export const SUBAGENT_ACTIONS = [
|
|
|
72
77
|
"consult",
|
|
73
78
|
"answer",
|
|
74
79
|
"escalate",
|
|
80
|
+
"resume",
|
|
75
81
|
];
|
|
76
82
|
/** Compact action signature: the single place documenting parameters, so field schemas stay prose-free. */
|
|
77
|
-
export const MANAGEMENT_ACTION_SIGNATURE = "spawn(prompt,type?
|
|
78
|
-
"
|
|
79
|
-
"
|
|
83
|
+
export const MANAGEMENT_ACTION_SIGNATURE = "spawn(prompt,type?,key? | tasks[{key,prompt,type?,template?,model?,thinking?,isolation?,persist?,notifyOnDone?}]) | " +
|
|
84
|
+
"steer/answer(runId,message,requestId?) | complete(summary,evidence{files[],commands[],none?,blocked?}) | consult(message) | " +
|
|
85
|
+
"escalate(runId,requestId) | get_result/stop/resume(runId,message?) | wait_all/dismiss(runIds? keys accepted) | " +
|
|
86
|
+
"handoff(toRunId,payload) | list(kind?) | templates";
|
|
80
87
|
export function makeSubagentTool(host, lang, selfConvId) {
|
|
81
88
|
const selfIdOf = () => (typeof selfConvId === "function" ? selfConvId() : selfConvId);
|
|
82
89
|
const executionOf = (snapshot) => snapshot.executionId ?? snapshot.convId;
|
|
@@ -89,6 +96,133 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
89
96
|
});
|
|
90
97
|
const deliveredConsults = new Set();
|
|
91
98
|
const consultKey = (parentId, runId, requestId) => JSON.stringify([parentId, runId, requestId]);
|
|
99
|
+
// 扇出键表:模型给短 key,工具映射成稳定运行身份(有界,旧的先丢)。
|
|
100
|
+
const RUN_KEY_CAP = 256;
|
|
101
|
+
const runKeys = new Map();
|
|
102
|
+
const rememberRunKey = (key, convId) => {
|
|
103
|
+
if (!key)
|
|
104
|
+
return;
|
|
105
|
+
runKeys.delete(key);
|
|
106
|
+
runKeys.set(key, convId);
|
|
107
|
+
while (runKeys.size > RUN_KEY_CAP) {
|
|
108
|
+
const oldest = runKeys.keys().next().value;
|
|
109
|
+
if (oldest === undefined)
|
|
110
|
+
break;
|
|
111
|
+
runKeys.delete(oldest);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
/** `key` 与真实 id 都接受:命中键表就换成运行身份,否则原样返回。 */
|
|
115
|
+
const resolveRunRef = (ref) => runKeys.get(ref.trim()) ?? ref;
|
|
116
|
+
const normalizeSpawnRequest = (request, ordinal) => {
|
|
117
|
+
const lang = getLang();
|
|
118
|
+
const zh = lang === "zh";
|
|
119
|
+
const rawKey = typeof request.key === "string" ? request.key.trim() : "";
|
|
120
|
+
const label = rawKey ? `[${rawKey}]` : zh ? `[第 ${ordinal} 项]` : `[task ${ordinal}]`;
|
|
121
|
+
const prompt = typeof request.prompt === "string" ? request.prompt : "";
|
|
122
|
+
if (!prompt.trim()) {
|
|
123
|
+
return {
|
|
124
|
+
error: pick(lang, `${label} 缺少 prompt。`, `${label} is missing a prompt.`, "subagents.spawn.task.missing.prompt", { label }),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (rawKey && !SUBAGENT_KEY_PATTERN.test(rawKey)) {
|
|
128
|
+
return {
|
|
129
|
+
error: pick(lang, `${label} 的 key 不合法:只用字母/数字/下划线/点/横线,最长 40 字符。`, `${label} has an invalid key: use letters/digits/\`_.-\`, max 40 chars.`, "subagents.spawn.task.bad.key", { label }),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const type = typeof request.type === "string" && request.type.trim() ? request.type.trim() : "general";
|
|
133
|
+
const requestedTemplate = typeof request.template === "string" && request.template.trim() ? request.template.trim() : undefined;
|
|
134
|
+
let templateName;
|
|
135
|
+
if (requestedTemplate) {
|
|
136
|
+
if (!host.isTemplateUsable(requestedTemplate)) {
|
|
137
|
+
return {
|
|
138
|
+
error: pick(lang, `${label} 的子代理模板不可用:${requestedTemplate}(不存在或已停用)。用 conversation(action="templates") 看清单。`, `${label} requests an unavailable template: ${requestedTemplate} (missing or disabled). Use conversation(action="templates") to list them.`, "subagents.spawn.template.unavailable", { label, "p.template": requestedTemplate }),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
templateName = requestedTemplate;
|
|
142
|
+
}
|
|
143
|
+
else if (host.isTemplateUsable(type)) {
|
|
144
|
+
templateName = type;
|
|
145
|
+
}
|
|
146
|
+
const thinking = typeof request.thinking === "string" && request.thinking.trim() ? request.thinking.trim() : undefined;
|
|
147
|
+
if (thinking && !THINKING_LEVELS.includes(thinking)) {
|
|
148
|
+
return {
|
|
149
|
+
error: pick(lang, `${label} 非法思考强度:${thinking}。可选档位:${THINKING_LEVELS.join(", ")}。`, `${label} has an invalid thinking level: ${thinking}. Allowed levels: ${THINKING_LEVELS.join(", ")}.`, "subagents.spawn.thinking.invalid", { label, thinking, levels: THINKING_LEVELS.join(", ") }),
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const rawIsolation = typeof request.isolation === "string" ? request.isolation.trim().toLowerCase() : "";
|
|
153
|
+
if (rawIsolation && rawIsolation !== "worktree" && rawIsolation !== "none") {
|
|
154
|
+
return {
|
|
155
|
+
error: pick(lang, `${label} 不支持的隔离模式:${rawIsolation}(可选 worktree / none)。`, `${label} uses an unsupported isolation mode: ${rawIsolation} (worktree / none).`, "subagents.spawn.isolation.invalid", { label, isolation: rawIsolation }),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const model = typeof request.model === "string" && request.model.trim() ? request.model.trim() : undefined;
|
|
159
|
+
// schema 里不再给 notifyOnDone 写 enum(联合类型 + enum 会被 Moonshot 等供应商判成非法 schema,
|
|
160
|
+
// 整轮请求 400),约束落到这里:只有 false / "manual" 有意义,其余一律按默认(通知)处理。
|
|
161
|
+
const rawNotify = request.notifyOnDone;
|
|
162
|
+
const notifyOnDone = typeof rawNotify === "boolean" ? rawNotify : rawNotify === "manual" ? "manual" : undefined;
|
|
163
|
+
return {
|
|
164
|
+
spec: {
|
|
165
|
+
key: rawKey || undefined,
|
|
166
|
+
prompt,
|
|
167
|
+
type,
|
|
168
|
+
templateName,
|
|
169
|
+
model,
|
|
170
|
+
thinking,
|
|
171
|
+
isolationMode: rawIsolation === "worktree" || rawIsolation === "none" ? rawIsolation : undefined,
|
|
172
|
+
persist: request.persist,
|
|
173
|
+
notifyOnDone,
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
/** 单次启动:校验完的 spec → 真实子代理。错误以结果返回,不抛(扇出时其它项照常跑)。 */
|
|
178
|
+
const spawnSpec = async (spec, cwd, signal) => {
|
|
179
|
+
const matchedTemplate = spec.templateName
|
|
180
|
+
? host.listTemplates().find((t) => t.name === spec.templateName)
|
|
181
|
+
: undefined;
|
|
182
|
+
const securityMode = resolveSecurityMode(spec.type, matchedTemplate);
|
|
183
|
+
const extra = securityMode !== "normal" ? { securityMode } : undefined;
|
|
184
|
+
const spawnArgs = [
|
|
185
|
+
spec.prompt,
|
|
186
|
+
spec.type,
|
|
187
|
+
cwd,
|
|
188
|
+
spec.templateName,
|
|
189
|
+
spec.model,
|
|
190
|
+
undefined,
|
|
191
|
+
spec.persist,
|
|
192
|
+
spec.thinking,
|
|
193
|
+
spec.notifyOnDone,
|
|
194
|
+
];
|
|
195
|
+
if (spec.isolationMode === "worktree" || extra !== undefined || signal !== undefined) {
|
|
196
|
+
spawnArgs.push(spec.isolationMode === "worktree" ? "worktree" : undefined);
|
|
197
|
+
}
|
|
198
|
+
if (extra !== undefined || signal !== undefined)
|
|
199
|
+
spawnArgs.push(extra);
|
|
200
|
+
if (signal !== undefined)
|
|
201
|
+
spawnArgs.push(signal);
|
|
202
|
+
try {
|
|
203
|
+
signal?.throwIfAborted();
|
|
204
|
+
const convId = await host.spawnSubagent(...spawnArgs);
|
|
205
|
+
rememberRunKey(spec.key, convId);
|
|
206
|
+
return { ok: true, convId, executionId: host.getSubagent(convId)?.executionId };
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
/** 扇出时的有限并发:避免与并发上限抢名额,又不至于串行等每个子代理初始化完。 */
|
|
213
|
+
const SPAWN_FANOUT_CONCURRENCY = 4;
|
|
214
|
+
const mapLimited = async (items, limit, fn) => {
|
|
215
|
+
const out = new Array(items.length);
|
|
216
|
+
let cursor = 0;
|
|
217
|
+
const worker = async () => {
|
|
218
|
+
while (cursor < items.length) {
|
|
219
|
+
const index = cursor++;
|
|
220
|
+
out[index] = await fn(items[index]);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
224
|
+
return out;
|
|
225
|
+
};
|
|
92
226
|
const expandDescendants = (roots) => {
|
|
93
227
|
if (roots instanceof Set ? roots.size === 0 : roots.length === 0)
|
|
94
228
|
return [];
|
|
@@ -163,8 +297,26 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
163
297
|
description: MANAGEMENT_ACTION_SIGNATURE,
|
|
164
298
|
}),
|
|
165
299
|
prompt: Type.Optional(Type.String()),
|
|
300
|
+
key: Type.Optional(Type.String()),
|
|
301
|
+
tasks: Type.Optional(Type.Array(Type.Object({
|
|
302
|
+
key: Type.Optional(Type.String()),
|
|
303
|
+
prompt: Type.Optional(Type.String()),
|
|
304
|
+
type: Type.Optional(Type.String()),
|
|
305
|
+
template: Type.Optional(Type.String()),
|
|
306
|
+
model: Type.Optional(Type.String()),
|
|
307
|
+
thinking: Type.Optional(Type.String({ enum: [...THINKING_LEVELS] })),
|
|
308
|
+
isolation: Type.Optional(Type.String({ enum: ["worktree", "none"] })),
|
|
309
|
+
persist: Type.Optional(Type.Boolean()),
|
|
310
|
+
notifyOnDone: Type.Optional(Type.Unsafe({ type: ["boolean", "string"] })),
|
|
311
|
+
}))),
|
|
166
312
|
message: Type.Optional(Type.String({ description: "Steer instruction, consult question, or answer text." })),
|
|
167
313
|
summary: Type.Optional(Type.String()),
|
|
314
|
+
evidence: Type.Optional(Type.Object({
|
|
315
|
+
files: Type.Optional(Type.Array(Type.String())),
|
|
316
|
+
commands: Type.Optional(Type.Array(Type.String())),
|
|
317
|
+
none: Type.Optional(Type.Boolean()),
|
|
318
|
+
blocked: Type.Optional(Type.String()),
|
|
319
|
+
})),
|
|
168
320
|
payload: Type.Optional(Type.String()),
|
|
169
321
|
runId: Type.Optional(Type.String()),
|
|
170
322
|
runIds: Type.Optional(Type.Array(Type.String())),
|
|
@@ -173,7 +325,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
173
325
|
type: Type.Optional(Type.String({ description: "Role/template (explore, implement, review, general)." })),
|
|
174
326
|
model: Type.Optional(Type.String()),
|
|
175
327
|
thinking: Type.Optional(Type.String({ enum: [...THINKING_LEVELS] })),
|
|
176
|
-
notifyOnDone: Type.Optional(Type.Unsafe({ type: ["boolean", "string"]
|
|
328
|
+
notifyOnDone: Type.Optional(Type.Unsafe({ type: ["boolean", "string"] })),
|
|
177
329
|
cwd: Type.Optional(Type.String()),
|
|
178
330
|
persist: Type.Optional(Type.Boolean()),
|
|
179
331
|
isolation: Type.Optional(Type.String({ enum: ["worktree", "none"] })),
|
|
@@ -188,7 +340,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
188
340
|
// Text-first compatibility: the schema exposes `message` only; legacy/undocumented fields pass through.
|
|
189
341
|
const legacy = p;
|
|
190
342
|
if (!action) {
|
|
191
|
-
return text(pick(getLang(), `
|
|
343
|
+
return text(pick(getLang(), `conversation 工具缺少 action 参数(可选:${SUBAGENT_ACTIONS.join(", ")})。`, `conversation tool requires an action parameter (one of: ${SUBAGENT_ACTIONS.join(", ")}).`, "subagents.action.missing"));
|
|
192
344
|
}
|
|
193
345
|
switch (action) {
|
|
194
346
|
case "complete": {
|
|
@@ -199,13 +351,24 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
199
351
|
const summary = (p.summary ?? p.message ?? "").trim();
|
|
200
352
|
if (!summary)
|
|
201
353
|
throw new Error("complete requires a nonempty summary or message.");
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
204
|
-
|
|
354
|
+
const normalized = normalizeEvidenceInput(p.evidence);
|
|
355
|
+
if (!normalized.ok) {
|
|
356
|
+
return text(pick(getLang(), 'evidence 形状不对:要么给 {files:[], commands:[]},要么 {none:true}(只读任务),要么 {blocked:"原因"};空对象不算证据。', 'Malformed evidence: pass {files:[], commands:[]}, {none:true} for read-only work, or {blocked:"reason"}. An empty object is not evidence.', "subagents.complete.evidence.invalid"), { status: "evidence_invalid" });
|
|
357
|
+
}
|
|
358
|
+
const result = await host.completeSubagent(selfId, summary, normalized.value);
|
|
359
|
+
if (result.ok === false) {
|
|
360
|
+
const issues = result.issues && result.issues.length > 0 ? result.issues : [result.error ?? "unspecified"];
|
|
361
|
+
throw new Error(pick(getLang(), `完成被驳回:证据与本会话转录不符。\n- ${issues.join("\n- ")}\n先修正再 complete:声称跑过的命令必须真的在本会话里跑过且成功;没改文件就写 {none:true};做不完就写 {blocked:"原因"}。不要把口供改成能过的样子。`, `Completion rejected: the evidence does not match this session's transcript.\n- ${issues.join("\n- ")}\nFix the work, then complete again: commands must actually have run and succeeded; use {none:true} if you changed no files; use {blocked:"reason"} if you could not finish. Do not restate claims just to pass.`, "subagents.complete.rejected"));
|
|
205
362
|
}
|
|
206
|
-
|
|
363
|
+
const evidence = result.evidence;
|
|
364
|
+
const evidenceLine = evidence ? formatEvidenceSummary(evidence, getLang()) : "";
|
|
365
|
+
return text(evidence
|
|
366
|
+
? pick(getLang(), `完成意图已登记。证据:${evidenceLine}\n结算会等空闲与依赖收口。`, `Completion intent recorded. Evidence: ${evidenceLine}\nSettlement waits for idle state and pending dependencies.`, "subagents.complete.recorded", { evidence: evidenceLine })
|
|
367
|
+
: "Completion intent recorded; settlement waits for idle state and pending dependencies.", {
|
|
207
368
|
status: "completion_requested",
|
|
208
369
|
runId: selfId,
|
|
370
|
+
verdict: evidence?.verdict,
|
|
371
|
+
evidence,
|
|
209
372
|
});
|
|
210
373
|
}
|
|
211
374
|
case "consult": {
|
|
@@ -276,42 +439,103 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
276
439
|
return text(JSON.stringify(result) ?? `Consult ${action} submitted.`, result);
|
|
277
440
|
}
|
|
278
441
|
case "spawn": {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
let templateName;
|
|
283
|
-
if (legacy.template) {
|
|
284
|
-
if (!host.isTemplateUsable(legacy.template)) {
|
|
285
|
-
return text(pick(getLang(), `子代理模板不可用:${legacy.template}(不存在或已停用)。用 subagent(action="templates") 查看当前可用模板清单;不传 template 则按默认配置运行。`, `Subagent template unavailable: ${legacy.template} (missing or disabled). Use subagent(action="templates") to list available templates; omit template to run with defaults.`, "subagents.spawn.template.unavailable", { "p.template": legacy.template }));
|
|
286
|
-
}
|
|
287
|
-
templateName = legacy.template.trim();
|
|
442
|
+
const batchTasks = Array.isArray(p.tasks) && p.tasks.length > 0 ? p.tasks : undefined;
|
|
443
|
+
if (!batchTasks && (!p.prompt || typeof p.prompt !== "string" || !p.prompt.trim())) {
|
|
444
|
+
return text(pick(getLang(), 'conversation(action="spawn") 缺少 prompt 参数(也可用 tasks[] 一次派多个)。', 'conversation(action="spawn") requires prompt (or tasks[] for a fan-out).', "subagents.spawn.missing.prompt"));
|
|
288
445
|
}
|
|
289
|
-
|
|
290
|
-
|
|
446
|
+
const requests = batchTasks
|
|
447
|
+
? batchTasks.map((task) => ({ ...task }))
|
|
448
|
+
: [
|
|
449
|
+
{
|
|
450
|
+
key: p.key,
|
|
451
|
+
prompt: p.prompt,
|
|
452
|
+
type: p.type,
|
|
453
|
+
template: legacy.template,
|
|
454
|
+
model: p.model,
|
|
455
|
+
thinking: p.thinking,
|
|
456
|
+
isolation: p.isolation,
|
|
457
|
+
persist: p.persist,
|
|
458
|
+
notifyOnDone: p.notifyOnDone,
|
|
459
|
+
},
|
|
460
|
+
];
|
|
461
|
+
if (requests.length > SUBAGENT_FANOUT_MAX) {
|
|
462
|
+
return text(pick(getLang(), `一次最多派发 ${SUBAGENT_FANOUT_MAX} 个(收到 ${requests.length} 个)。分批调用或先等一批收口。`, `At most ${SUBAGENT_FANOUT_MAX} tasks per call (got ${requests.length}). Split the batch or wait for a round to settle first.`, "subagents.spawn.batch.too.many", { limit: SUBAGENT_FANOUT_MAX, count: requests.length }), { status: "rejected", reason: "fanout_limit", limit: SUBAGENT_FANOUT_MAX });
|
|
291
463
|
}
|
|
292
|
-
|
|
293
|
-
|
|
464
|
+
// 整批先校验再启动:一个不合法就一个都不启动,避免半批运行后预算/工作树无法回收。
|
|
465
|
+
const prepared = [];
|
|
466
|
+
const problems = [];
|
|
467
|
+
const usedKeys = new Set();
|
|
468
|
+
requests.forEach((request, index) => {
|
|
469
|
+
const normalized = normalizeSpawnRequest(request, index + 1);
|
|
470
|
+
if ("error" in normalized) {
|
|
471
|
+
problems.push(normalized.error);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
const key = normalized.spec.key;
|
|
475
|
+
if (key && usedKeys.has(key)) {
|
|
476
|
+
problems.push(pick(getLang(), `key 重复:${key}(同一批里必须唯一)。`, `Duplicate key: ${key} (keys must be unique within a batch).`, "subagents.spawn.batch.duplicate.key", { key }));
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (key)
|
|
480
|
+
usedKeys.add(key);
|
|
481
|
+
prepared.push(normalized.spec);
|
|
482
|
+
});
|
|
483
|
+
if (problems.length > 0) {
|
|
484
|
+
const head = pick(getLang(), "派发被驳回(整批都未启动):\n", "Fan-out rejected (nothing launched):\n", "subagents.spawn.batch.rejected");
|
|
485
|
+
return text(`${head}${problems.map((problem) => `- ${problem}`).join("\n")}`, {
|
|
486
|
+
status: "rejected",
|
|
487
|
+
problems,
|
|
488
|
+
});
|
|
294
489
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
490
|
+
if (batchTasks) {
|
|
491
|
+
const results = await mapLimited(prepared, SPAWN_FANOUT_CONCURRENCY, (spec) => spawnSpec(spec, p.cwd ?? ctx.cwd, signal));
|
|
492
|
+
const lines = results.map((result, index) => {
|
|
493
|
+
const spec = prepared[index];
|
|
494
|
+
const label = spec.key ?? `#${index + 1}`;
|
|
495
|
+
if (!result.ok)
|
|
496
|
+
return `- ${label} ✗ ${result.error}`;
|
|
497
|
+
const address = result.executionId ? ` · runId: ${result.executionId}` : "";
|
|
498
|
+
const tpl = spec.templateName ? ` · ${spec.templateName}` : "";
|
|
499
|
+
return `- ${label} → ${result.convId}${address} · ${spec.type}${tpl}`;
|
|
500
|
+
});
|
|
501
|
+
const startedKeys = prepared
|
|
502
|
+
.filter((spec, index) => spec.key && results[index]?.ok)
|
|
503
|
+
.map((spec) => spec.key);
|
|
504
|
+
const okCount = results.filter((result) => result.ok).length;
|
|
505
|
+
const head = pick(getLang(), `已派发 ${okCount}/${results.length} 个(key → 运行):\n`, `Started ${okCount}/${results.length} task(s) (key → run):\n`, "subagents.spawn.batch.started", { okCount, "results.length": results.length });
|
|
506
|
+
const keyHint = startedKeys.length > 0
|
|
507
|
+
? pick(getLang(), `\n用 conversation(action="wait_all", runIds=${JSON.stringify(startedKeys)}) 一次等这批收口(key 与 runId 都接受)。`, `\nUse conversation(action="wait_all", runIds=${JSON.stringify(startedKeys)}) to collect this batch (keys and runIds both work).`, "subagents.spawn.batch.wait.hint", { keys: JSON.stringify(startedKeys) })
|
|
508
|
+
: "";
|
|
509
|
+
return text(`${head}${lines.join("\n")}${keyHint}`, {
|
|
510
|
+
status: "spawned",
|
|
511
|
+
tasks: results.map((result, index) => ({
|
|
512
|
+
key: prepared[index].key,
|
|
513
|
+
ok: result.ok,
|
|
514
|
+
convId: result.ok ? result.convId : undefined,
|
|
515
|
+
executionId: result.ok ? result.executionId : undefined,
|
|
516
|
+
error: result.ok ? undefined : result.error,
|
|
517
|
+
})),
|
|
518
|
+
});
|
|
298
519
|
}
|
|
520
|
+
const single = prepared[0];
|
|
521
|
+
const templateName = single.templateName;
|
|
522
|
+
const isolationMode = single.isolationMode;
|
|
299
523
|
let convId;
|
|
300
|
-
const subagentType =
|
|
524
|
+
const subagentType = single.type;
|
|
301
525
|
const matchedTemplate = templateName ? host.listTemplates().find((t) => t.name === templateName) : undefined;
|
|
302
526
|
const securityMode = resolveSecurityMode(subagentType, matchedTemplate);
|
|
303
527
|
const extra = securityMode !== "normal" ? { securityMode } : undefined;
|
|
304
528
|
try {
|
|
305
529
|
const spawnArgs = [
|
|
306
|
-
|
|
530
|
+
single.prompt,
|
|
307
531
|
subagentType,
|
|
308
532
|
p.cwd ?? ctx.cwd,
|
|
309
533
|
templateName,
|
|
310
|
-
|
|
534
|
+
single.model,
|
|
311
535
|
undefined,
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
536
|
+
single.persist,
|
|
537
|
+
single.thinking,
|
|
538
|
+
single.notifyOnDone,
|
|
315
539
|
];
|
|
316
540
|
if (isolationMode === "worktree" || extra !== undefined || signal !== undefined) {
|
|
317
541
|
spawnArgs.push(isolationMode === "worktree" ? "worktree" : undefined);
|
|
@@ -330,9 +554,12 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
330
554
|
error: msg,
|
|
331
555
|
}));
|
|
332
556
|
}
|
|
557
|
+
rememberRunKey(single.key, convId);
|
|
333
558
|
const executionId = host.getSubagent(convId)?.executionId;
|
|
559
|
+
const keyLineZh = single.key ? `\nkey:${single.key}` : "";
|
|
560
|
+
const keyLineEn = single.key ? `\nkey: ${single.key}` : "";
|
|
334
561
|
const addressLine = executionId ? `\nrunId: ${executionId}` : "";
|
|
335
|
-
const subagentTitleText = subagentTitle(
|
|
562
|
+
const subagentTitleText = subagentTitle(single.prompt);
|
|
336
563
|
const templateLineZh = templateName ? `\n模板:${templateName}` : "";
|
|
337
564
|
const templateLineEn = templateName ? `\nTemplate: ${templateName}` : "";
|
|
338
565
|
const modelLineZh = p.model ? `\n模型:${p.model}` : "";
|
|
@@ -345,9 +572,9 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
345
572
|
const isolationLineEn = isolationMode === "worktree" ? "\nWorktree isolation: enabled (dedicated Git worktree & branch)" : "";
|
|
346
573
|
const kindLabelZh = p.persist ? "普通持久化对话" : "子代理";
|
|
347
574
|
const kindLabelEn = p.persist ? "Persistent conversation" : "Subagent";
|
|
348
|
-
return text(pick(getLang(), `${kindLabelZh}已启动(运行列表可见):${convId}\n类型:${subagentType} · 标题:${subagentTitleText}${templateLineZh}${modelLineZh}${thinkingLineZh}${notifyLineZh}${isolationLineZh}${addressLine}` +
|
|
349
|
-
`\n用
|
|
350
|
-
`\nUse
|
|
575
|
+
return text(pick(getLang(), `${kindLabelZh}已启动(运行列表可见):${convId}\n类型:${subagentType} · 标题:${subagentTitleText}${keyLineZh}${templateLineZh}${modelLineZh}${thinkingLineZh}${notifyLineZh}${isolationLineZh}${addressLine}` +
|
|
576
|
+
`\n用 conversation(action="wait_all") 一次等全部完成(事件驱动,不再轮询),conversation(action="get_result") 取单个结果,conversation(action="list") 看运行态,conversation(action="steer") 改向,conversation(action="stop") 停止。`, `${kindLabelEn} started (visible in the running list): ${convId}\nType: ${subagentType} · Title: ${subagentTitleText}${keyLineEn}${templateLineEn}${modelLineEn}${thinkingLineEn}${notifyLineEn}${isolationLineEn}${addressLine}` +
|
|
577
|
+
`\nUse conversation(action="wait_all") to wait for all at once (event-driven, no polling), conversation(action="get_result") for a single result, conversation(action="list") for live status, conversation(action="steer") to redirect, conversation(action="stop") to stop.`, "subagents.spawn.started", {
|
|
351
578
|
convId,
|
|
352
579
|
subagentType,
|
|
353
580
|
subagentTitleText,
|
|
@@ -371,7 +598,8 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
371
598
|
}), {
|
|
372
599
|
convId,
|
|
373
600
|
executionId,
|
|
374
|
-
|
|
601
|
+
key: single.key,
|
|
602
|
+
template: templateName,
|
|
375
603
|
model: p.model,
|
|
376
604
|
thinking: p.thinking,
|
|
377
605
|
persisted: !!p.persist,
|
|
@@ -381,10 +609,20 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
381
609
|
}
|
|
382
610
|
case "get_result": {
|
|
383
611
|
if (!p.runId || typeof p.runId !== "string" || !p.runId.trim()) {
|
|
384
|
-
return text(pick(getLang(), '
|
|
612
|
+
return text(pick(getLang(), 'conversation(action="get_result") 缺少 runId 参数。', 'conversation(action="get_result") requires runId parameter.', "subagents.get.missing.runId"));
|
|
385
613
|
}
|
|
386
|
-
|
|
614
|
+
const requestedRun = resolveRunRef(p.runId);
|
|
615
|
+
let r = host.getSubagent(requestedRun);
|
|
387
616
|
const missingId = shortId(p.runId);
|
|
617
|
+
if (!r && host.getLedgerRun) {
|
|
618
|
+
// 进程里没有 → 回落运行账本:重启/移出后仍能拿回结论、证据与工作树。
|
|
619
|
+
const recorded = await host.getLedgerRun(requestedRun).catch(() => undefined);
|
|
620
|
+
if (recorded) {
|
|
621
|
+
const timeline = (await host.getLedgerEvents?.(requestedRun, 8).catch(() => [])) ?? [];
|
|
622
|
+
const formatted = formatLedgerRunResult(recorded, getLang(), timeline);
|
|
623
|
+
return text(formatted, { ...recorded, timeline });
|
|
624
|
+
}
|
|
625
|
+
}
|
|
388
626
|
if (!r)
|
|
389
627
|
return text(pick(getLang(), `未找到子代理 ${missingId}(可能已移出)。`, `Subagent ${missingId} not found (may have been dismissed).`, "subagents.get.not.found", { missingId }), undefined);
|
|
390
628
|
const verdict = subagentVerdict(r, getLang());
|
|
@@ -392,6 +630,10 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
392
630
|
const doneDetail = verdictText(r, getLang());
|
|
393
631
|
const doneOutput = r.output || (getLang() === "zh" ? "(无结果)" : "(no result)");
|
|
394
632
|
const modelTag = r.model ? ` · ${r.model}${r.thinkingLevel ? `:${r.thinkingLevel}` : ""}` : "";
|
|
633
|
+
const usageTag = formatUsageTag(r.usage, getLang());
|
|
634
|
+
const evidenceLine = r.evidence
|
|
635
|
+
? pick(getLang(), `\n证据:${formatEvidenceSummary(r.evidence, getLang())}`, `\nEvidence: ${formatEvidenceSummary(r.evidence, getLang())}`, "subagents.get.evidence", { evidence: formatEvidenceSummary(r.evidence, getLang()) })
|
|
636
|
+
: "";
|
|
395
637
|
if (!isSubagentTerminal(r)) {
|
|
396
638
|
const runningId = shortId(r.convId);
|
|
397
639
|
const runningOutput = r.output || (getLang() === "zh" ? "(暂无输出)" : "(no output yet)");
|
|
@@ -413,28 +655,112 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
413
655
|
worktreeDetail = pick(getLang(), `\n\n[工作树隔离] 代码改动已保留供审阅:\n- 路径:${wt.path}\n- 分支:${wt.branch}\n- 改动:${wt.uncommittedCount ?? 0} 个未提交文件修改,领先 ${wt.aheadCount ?? 0} 个提交\n(提示:可执行 git merge ${wt.branch} 合并,或调用 worktree(action="remove", path="${wt.path}", force=true) 放弃)`, `\n\n[Worktree isolation] Changes preserved for review:\n- Path: ${wt.path}\n- Branch: ${wt.branch}\n- Changes: ${wt.uncommittedCount ?? 0} uncommitted file(s), ${wt.aheadCount ?? 0} commit(s) ahead\n(Note: run git merge ${wt.branch} to merge, or worktree(action="remove", path="${wt.path}", force=true) to discard)`, "subagents.get.worktree.preserved", { path: wt.path, branch: wt.branch, uncommitted: wt.uncommittedCount ?? 0, ahead: wt.aheadCount ?? 0 });
|
|
414
656
|
}
|
|
415
657
|
}
|
|
416
|
-
return text(pick(getLang(), `子代理 ${doneId}(${r.type}${modelTag})状态:${verdict}\n${doneDetail}\n${doneOutput}${worktreeDetail}`, `Subagent ${doneId} (${r.type}${modelTag}) status: ${verdict}\n${doneDetail}\n${doneOutput}${worktreeDetail}`, "subagents.get.done", {
|
|
658
|
+
return text(pick(getLang(), `子代理 ${doneId}(${r.type}${modelTag}${usageTag})状态:${verdict}\n${doneDetail}${evidenceLine}\n${doneOutput}${worktreeDetail}`, `Subagent ${doneId} (${r.type}${modelTag}${usageTag}) status: ${verdict}\n${doneDetail}${evidenceLine}\n${doneOutput}${worktreeDetail}`, "subagents.get.done", {
|
|
659
|
+
doneId,
|
|
660
|
+
"r.type": r.type,
|
|
661
|
+
modelTag,
|
|
662
|
+
verdict,
|
|
663
|
+
doneDetail,
|
|
664
|
+
evidenceLine,
|
|
665
|
+
doneOutput: `${doneOutput}${worktreeDetail}`,
|
|
666
|
+
}), r);
|
|
667
|
+
}
|
|
668
|
+
case "resume": {
|
|
669
|
+
if (!host.resumeLedgerRun)
|
|
670
|
+
throw new Error("Run resume is unavailable on this engine.");
|
|
671
|
+
if (!p.runId || typeof p.runId !== "string" || !p.runId.trim()) {
|
|
672
|
+
return text(pick(getLang(), 'conversation(action="resume") 缺少 runId 参数。', 'conversation(action="resume") requires runId parameter.', "subagents.resume.missing.runId"));
|
|
673
|
+
}
|
|
674
|
+
const resumeSelf = selfIdOf();
|
|
675
|
+
if (!resumeSelf)
|
|
676
|
+
throw new Error("Resume requires a verified conversation identity.");
|
|
677
|
+
const resumeTarget = resolveRunRef(p.runId);
|
|
678
|
+
const resumeExtra = typeof p.message === "string" && p.message.trim() ? p.message.trim() : undefined;
|
|
679
|
+
const result = await host.resumeLedgerRun(resumeSelf, resumeTarget, resumeExtra);
|
|
680
|
+
if (!result.ok) {
|
|
681
|
+
const resumedId = result.runId ? shortId(result.runId) : "";
|
|
682
|
+
const reasons = {
|
|
683
|
+
not_found: [
|
|
684
|
+
'账本里没有这个运行(可能已被清理)。用 conversation(action="list") 看现有记录。',
|
|
685
|
+
'Not in the run ledger (it may have been pruned). Use conversation(action="list") to inspect records.',
|
|
686
|
+
],
|
|
687
|
+
running: [
|
|
688
|
+
"这个运行还在进程里跑着:先 wait_all / get_result,别重复派发。",
|
|
689
|
+
"This run is still live: use wait_all / get_result instead of relaunching it.",
|
|
690
|
+
],
|
|
691
|
+
already_resumed: [
|
|
692
|
+
`已经续跑过了${resumedId ? `(新运行 ${resumedId})` : ""},别重复续跑。`,
|
|
693
|
+
`It was already resumed${resumedId ? ` (new run ${resumedId})` : ""}; do not resume twice.`,
|
|
694
|
+
],
|
|
695
|
+
parent_missing: [
|
|
696
|
+
"原父对话已不可用,续跑挂不回去。请直接在当前对话里 spawn 一次。",
|
|
697
|
+
"The original parent is gone, so the relaunch cannot attach to it. Spawn from this conversation instead.",
|
|
698
|
+
],
|
|
699
|
+
};
|
|
700
|
+
const [zhReason, enReason] = reasons[result.error] ?? [
|
|
701
|
+
`续跑失败:${result.error}`,
|
|
702
|
+
`Resume failed: ${result.error}`,
|
|
703
|
+
];
|
|
704
|
+
return text(pick(getLang(), zhReason, enReason, "subagents.resume.failed", { reason: result.error }), result);
|
|
705
|
+
}
|
|
706
|
+
const newRunId = result.executionId ?? result.convId;
|
|
707
|
+
const transcript = result.sessionFile
|
|
708
|
+
? pick(getLang(), `旧会话记录 ${result.sessionFile} 可在历史对话里回看。`, `The old transcript ${result.sessionFile} stays readable from History.`, "subagents.resume.transcript", { file: result.sessionFile })
|
|
709
|
+
: pick(getLang(), "旧会话没有落盘,接不上原转录:这次是带上原任务与已知进度的重派。", "The old in-memory session was never persisted, so this is a relaunch carrying the original task and known progress.", "subagents.resume.no.transcript");
|
|
710
|
+
return text(pick(getLang(), `已续跑:旧运行 ${shortId(result.runId)}(${result.previousState})→ 新运行 ${newRunId}。${transcript}`, `Resumed: ${shortId(result.runId)} (${result.previousState}) → new run ${newRunId}. ${transcript}`, "subagents.resume.ok", { oldId: shortId(result.runId), state: result.previousState, newId: newRunId, transcript }), result);
|
|
417
711
|
}
|
|
418
712
|
case "steer": {
|
|
419
713
|
if (!p.runId || typeof p.runId !== "string" || !p.runId.trim()) {
|
|
420
|
-
return text(pick(getLang(), '
|
|
714
|
+
return text(pick(getLang(), 'conversation(action="steer") 缺少 runId 参数。', 'conversation(action="steer") requires runId parameter.', "subagents.steer.missing.runId"));
|
|
421
715
|
}
|
|
422
716
|
if (typeof p.message !== "string" || !p.message.trim()) {
|
|
423
|
-
return text(pick(getLang(), '
|
|
717
|
+
return text(pick(getLang(), 'conversation(action="steer") 缺少 message 参数。', 'conversation(action="steer") requires message parameter.', "subagents.steer.missing.message"));
|
|
424
718
|
}
|
|
425
|
-
|
|
719
|
+
const steerTarget = resolveRunRef(p.runId);
|
|
720
|
+
if (!host.getSubagent(steerTarget)) {
|
|
426
721
|
const missingSteerId = shortId(p.runId);
|
|
427
|
-
return text(pick(getLang(), `未找到子代理 ${missingSteerId}(可能已移出),消息未注入。请用
|
|
722
|
+
return text(pick(getLang(), `未找到子代理 ${missingSteerId}(可能已移出),消息未注入。请用 conversation(action="list") 确认仍在运行的子代理。`, `Subagent ${missingSteerId} not found (may have been dismissed); message not injected. Use conversation(action="list") to confirm running subagents.`, "subagents.steer.not.found", { missingSteerId }));
|
|
428
723
|
}
|
|
429
|
-
await host.steerSubagent(executionOfId(
|
|
724
|
+
const receipt = await host.steerSubagent(executionOfId(steerTarget), p.message);
|
|
725
|
+
const steerState = receipt && "state" in receipt ? receipt.state : "delivered";
|
|
430
726
|
const steerId = shortId(p.runId);
|
|
431
|
-
|
|
727
|
+
const stateText = steerState === "queued"
|
|
728
|
+
? pick(getLang(), "已排队,等当前回合结束再送。", "Queued; delivered when the current turn ends.", "subagents.steer.queued")
|
|
729
|
+
: steerState === "restarted"
|
|
730
|
+
? pick(getLang(), "它当时已空闲,已在同一会话里开新一轮。", "It was idle; a new round started in the same session.", "subagents.steer.restarted")
|
|
731
|
+
: steerState === "missed"
|
|
732
|
+
? pick(getLang(), "没能送达(运行已结束无可投递通道)。", "Not delivered (the run ended with no live route).", "subagents.steer.missed")
|
|
733
|
+
: pick(getLang(), "已送进当前回话上下文。", "Delivered into the live turn.", "subagents.steer.delivered");
|
|
734
|
+
return text(pick(getLang(), `已向子代理 ${steerId} 注入消息(${steerState}):${stateText}`, `Message injected into subagent ${steerId} (${steerState}): ${stateText}`, "subagents.steer.injected", { steerId, steerState, stateText }), { steerId, state: steerState });
|
|
432
735
|
}
|
|
433
736
|
case "list": {
|
|
434
737
|
const list = host.listSubagents(p.kind, selfIdOf());
|
|
435
|
-
if (list.length === 0)
|
|
436
|
-
return text(pick(getLang(), "当前没有运行中的对话/子代理。", "No managed conversations or subagents running.", "subagents.list.empty"));
|
|
437
738
|
const tLang = getLang();
|
|
739
|
+
// 账本追加:活运行永远以内存快照为准,账本只补「已经不在进程里」的那些。
|
|
740
|
+
const ledgerLines = [];
|
|
741
|
+
if (host.listLedgerRuns) {
|
|
742
|
+
try {
|
|
743
|
+
const recorded = await host.listLedgerRuns({ limit: 32 });
|
|
744
|
+
for (const rec of recorded) {
|
|
745
|
+
if (rec.state === "dismissed")
|
|
746
|
+
continue;
|
|
747
|
+
if (host.getSubagent(rec.runId))
|
|
748
|
+
continue;
|
|
749
|
+
const tag = rec.evidence ? ` · ${formatLedgerEvidence(rec, tLang)}` : "";
|
|
750
|
+
const resumed = rec.resumedBy
|
|
751
|
+
? pick(tLang, `,已续跑→${shortId(rec.resumedBy)}`, `, resumed→${shortId(rec.resumedBy)}`, "subagents.list.ledger.resumed", { id: shortId(rec.resumedBy) })
|
|
752
|
+
: "";
|
|
753
|
+
ledgerLines.push(pick(tLang, `- 账本 ${shortId(rec.runId)} · ${rec.type} · ${rec.state} · ${rec.title}${tag}${resumed}`, `- ledger ${shortId(rec.runId)} · ${rec.type} · ${rec.state} · ${rec.title}${tag}${resumed}`, "subagents.list.ledger.item", { id: shortId(rec.runId), type: rec.type, state: rec.state, title: rec.title, tag, resumed }));
|
|
754
|
+
if (ledgerLines.length >= 10)
|
|
755
|
+
break;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
catch {
|
|
759
|
+
// 账本读失败不影响活运行列表。
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
if (list.length === 0 && ledgerLines.length === 0)
|
|
763
|
+
return text(pick(getLang(), "当前没有运行中的对话/子代理(运行账本里也没有记录)。", "No managed conversations or subagents running (the run ledger is empty too).", "subagents.list.empty"));
|
|
438
764
|
const lines = list.map((r) => {
|
|
439
765
|
const tag = r.persisted
|
|
440
766
|
? tLang === "zh"
|
|
@@ -444,20 +770,26 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
444
770
|
? "子代理"
|
|
445
771
|
: "subagent";
|
|
446
772
|
const modelTag = r.model ? ` · ${r.model}${r.thinkingLevel ? `:${r.thinkingLevel}` : ""}` : "";
|
|
773
|
+
const evidenceTag = r.evidence ? ` · ${formatEvidenceSummary(r.evidence, tLang)}` : "";
|
|
447
774
|
return (`- ${r.convId}${r.executionId ? ` (runId: ${r.executionId})` : ""} · ${r.type}${modelTag} · ${subagentVerdict(r, tLang)} · ${r.title}` +
|
|
448
|
-
(tLang === "zh" ? `(${tag} · msg: ${r.messageCount})` : ` (${tag} · msg: ${r.messageCount})`)
|
|
775
|
+
(tLang === "zh" ? `(${tag} · msg: ${r.messageCount})` : ` (${tag} · msg: ${r.messageCount})`) +
|
|
776
|
+
evidenceTag);
|
|
449
777
|
});
|
|
450
|
-
|
|
778
|
+
const ledgerHead = ledgerLines.length > 0
|
|
779
|
+
? pick(tLang, "\n\n运行账本(不在进程里:get_result 取已产出的结论/证据,resume 续跑):\n", "\n\nRun ledger (no longer in-process; get_result for the recorded result, resume to relaunch):\n", "subagents.list.ledger.head")
|
|
780
|
+
: "";
|
|
781
|
+
return text(`${lines.join("\n")}${ledgerHead}${ledgerLines.join("\n")}`);
|
|
451
782
|
}
|
|
452
783
|
case "stop": {
|
|
453
784
|
if (!p.runId || typeof p.runId !== "string" || !p.runId.trim()) {
|
|
454
|
-
return text(pick(getLang(), '
|
|
785
|
+
return text(pick(getLang(), 'conversation(action="stop") 缺少 runId 参数。', 'conversation(action="stop") requires runId parameter.', "subagents.stop.missing.runId"));
|
|
455
786
|
}
|
|
456
|
-
|
|
787
|
+
const stopTarget = resolveRunRef(p.runId);
|
|
788
|
+
if (!host.getSubagent(stopTarget)) {
|
|
457
789
|
const missingStopId = shortId(p.runId);
|
|
458
|
-
return text(pick(getLang(), `未找到子代理 ${missingStopId}(可能已移出或已结束),无需停止。请用
|
|
790
|
+
return text(pick(getLang(), `未找到子代理 ${missingStopId}(可能已移出或已结束),无需停止。请用 conversation(action="list") 确认仍在运行的子代理。`, `Subagent ${missingStopId} not found (may have been dismissed or already finished); nothing to stop. Use conversation(action="list") to confirm running subagents.`, "subagents.stop.not.found", { missingStopId }));
|
|
459
791
|
}
|
|
460
|
-
await host.stopSubagent(
|
|
792
|
+
await host.stopSubagent(stopTarget);
|
|
461
793
|
const stopId = shortId(p.runId);
|
|
462
794
|
return text(pick(getLang(), `已请求停止子代理 ${stopId}。`, `Stop requested for subagent ${stopId}.`, "subagents.stop.requested", { stopId }));
|
|
463
795
|
}
|
|
@@ -483,7 +815,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
483
815
|
if (explicit) {
|
|
484
816
|
const seedRoots = [];
|
|
485
817
|
for (const requestedId of p.runIds) {
|
|
486
|
-
const id = executionOfId(requestedId);
|
|
818
|
+
const id = executionOfId(resolveRunRef(requestedId));
|
|
487
819
|
if (selfId && id === selfId)
|
|
488
820
|
continue;
|
|
489
821
|
if (selfAncestorIds.has(id))
|
|
@@ -547,13 +879,24 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
547
879
|
: currentWaitCapMs;
|
|
548
880
|
const liveCapSeconds = Math.floor(liveWaitCapMs / 1000);
|
|
549
881
|
const timeoutMs = Math.min(Math.max(p.timeoutSeconds ?? liveCapSeconds, 1), liveCapSeconds) * 1000;
|
|
882
|
+
// 已收口单源:`getSubagent` 拿不到(已移出/已结束并回收)与显式终态都算收口,
|
|
883
|
+
// 等待与「还剩谁」必须用同一判据,否则会出现「全都完成了却报还有人在跑」。
|
|
884
|
+
const isSettled = (id) => {
|
|
885
|
+
const r = host.getSubagent(id);
|
|
886
|
+
return r === undefined || isSubagentTerminal(r);
|
|
887
|
+
};
|
|
550
888
|
const startedAt = Date.now();
|
|
551
|
-
|
|
889
|
+
// 单次等待切片:上游在真实事件上唤醒;到点只是重新算一遍(新派生的后代、问卷),
|
|
890
|
+
// 不再用固定轮询去抢快照。
|
|
891
|
+
const SETTLE_SLICE_MS = 30_000;
|
|
552
892
|
try {
|
|
553
893
|
const waitingParentId = selfIdOf();
|
|
554
894
|
if (waitingParentId)
|
|
555
895
|
host.setConsultWaiting?.(waitingParentId, true);
|
|
556
|
-
while (!signal?.aborted
|
|
896
|
+
while (!signal?.aborted) {
|
|
897
|
+
const remainingMs = timeoutMs - (Date.now() - startedAt);
|
|
898
|
+
if (remainingMs <= 0)
|
|
899
|
+
break;
|
|
557
900
|
for (const descId of expandDescendants(wanted)) {
|
|
558
901
|
if (selfId && descId === selfId)
|
|
559
902
|
continue;
|
|
@@ -564,13 +907,15 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
564
907
|
const consults = collectConsults();
|
|
565
908
|
if (consults)
|
|
566
909
|
return consults;
|
|
567
|
-
const allDone = Array.from(wanted).every(
|
|
568
|
-
const r = host.getSubagent(id);
|
|
569
|
-
return r === undefined || isSubagentTerminal(r);
|
|
570
|
-
});
|
|
910
|
+
const allDone = Array.from(wanted).every(isSettled);
|
|
571
911
|
if (allDone)
|
|
572
912
|
break;
|
|
573
|
-
await
|
|
913
|
+
const wake = await host.waitForSubagentSettle(Array.from(wanted), {
|
|
914
|
+
timeoutMs: Math.min(remainingMs, SETTLE_SLICE_MS),
|
|
915
|
+
signal,
|
|
916
|
+
});
|
|
917
|
+
if (wake === "aborted")
|
|
918
|
+
break;
|
|
574
919
|
}
|
|
575
920
|
}
|
|
576
921
|
finally {
|
|
@@ -581,10 +926,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
581
926
|
const tLang = getLang();
|
|
582
927
|
const waitedSecs = Math.max(1, Math.round((Date.now() - startedAt) / 1000));
|
|
583
928
|
const timeoutSecs = Math.round(timeoutMs / 1000);
|
|
584
|
-
const finishedIds = Array.from(wanted).filter(
|
|
585
|
-
const r = host.getSubagent(id);
|
|
586
|
-
return r === undefined || isSubagentTerminal(r);
|
|
587
|
-
});
|
|
929
|
+
const finishedIds = Array.from(wanted).filter(isSettled);
|
|
588
930
|
if (finishedIds.length > 0) {
|
|
589
931
|
host.markSubagentsConsumed?.(finishedIds);
|
|
590
932
|
if (host.finalizeSubagentWorktree) {
|
|
@@ -600,6 +942,8 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
600
942
|
}
|
|
601
943
|
const verdict = subagentVerdict(r, tLang);
|
|
602
944
|
const detail = verdictText(r, tLang);
|
|
945
|
+
const usageTag = formatUsageTag(r.usage, tLang);
|
|
946
|
+
const evidenceTag = r.evidence ? ` · ${formatEvidenceSummary(r.evidence, tLang)}` : "";
|
|
603
947
|
const out = clipSubagentOutput(r.output || (tLang === "zh" ? "(无输出)" : "(no output)"), tLang);
|
|
604
948
|
let wtTag = "";
|
|
605
949
|
let wtPathInfo = "";
|
|
@@ -616,13 +960,10 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
616
960
|
tLang === "zh" ? `\n - 工作树路径:${r.worktree.path}` : `\n - Worktree path: ${r.worktree.path}`;
|
|
617
961
|
}
|
|
618
962
|
}
|
|
619
|
-
return `- ${sId}(${r.type} · ${verdict} · ${r.title}${wtTag})${detail ? ` · ${detail}` : ""}:\n${out}${wtPathInfo}`;
|
|
963
|
+
return `- ${sId}(${r.type} · ${verdict} · ${r.title}${wtTag}${usageTag})${detail ? ` · ${detail}` : ""}${evidenceTag}:\n${out}${wtPathInfo}`;
|
|
620
964
|
})
|
|
621
965
|
.join("\n\n");
|
|
622
|
-
const remaining = Array.from(wanted).filter((id) =>
|
|
623
|
-
const r = host.getSubagent(id);
|
|
624
|
-
return !isSubagentTerminal(r);
|
|
625
|
-
});
|
|
966
|
+
const remaining = Array.from(wanted).filter((id) => !isSettled(id));
|
|
626
967
|
const head = remaining.length === 0
|
|
627
968
|
? pick(tLang, `全部 ${wanted.size} 个子代理已收口:`, `All ${wanted.size} subagent(s) collected:`, "subagents.wait.collected", { "wanted.size": wanted.size })
|
|
628
969
|
: signal?.aborted
|
|
@@ -657,7 +998,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
657
998
|
});
|
|
658
999
|
const firstTemplateName = list[0]?.name;
|
|
659
1000
|
const templateLines = lines.join("\n");
|
|
660
|
-
return text(pick(getLang(), `可用的子代理模板(subagent 的 template 参数传名字,如
|
|
1001
|
+
return text(pick(getLang(), `可用的子代理模板(subagent 的 template 参数传名字,如 conversation(action="spawn", template="${firstTemplateName}")):\n${templateLines}`, `Available subagent templates (pass the name as subagent's template param, e.g. conversation(action="spawn", template="${firstTemplateName}")):\n${templateLines}`, "subagents.templates.list", { firstTemplateName, templateLines }));
|
|
661
1002
|
}
|
|
662
1003
|
case "handoff": {
|
|
663
1004
|
signal?.throwIfAborted();
|
|
@@ -668,10 +1009,10 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
668
1009
|
throw new Error("Handoff source must match the calling conversation.");
|
|
669
1010
|
}
|
|
670
1011
|
if (!p.toRunId || typeof p.toRunId !== "string" || !p.toRunId.trim()) {
|
|
671
|
-
return text(pick(getLang(), '
|
|
1012
|
+
return text(pick(getLang(), 'conversation(action="handoff") 缺少 toRunId 参数。', 'conversation(action="handoff") requires toRunId parameter.', "subagents.handoff.missing.toRunId"));
|
|
672
1013
|
}
|
|
673
1014
|
if (typeof p.payload !== "string" || !p.payload.trim()) {
|
|
674
|
-
return text(pick(getLang(), '
|
|
1015
|
+
return text(pick(getLang(), 'conversation(action="handoff") 缺少 payload 参数。', 'conversation(action="handoff") requires payload parameter.', "subagents.handoff.missing.payload"));
|
|
675
1016
|
}
|
|
676
1017
|
if (fromId === p.toRunId) {
|
|
677
1018
|
return text(pick(getLang(), `交接失败:不能交接给自身(${shortId(fromId)})。请指定其他同行子代理。`, `Handoff failed: cannot hand off to oneself (${shortId(fromId)}). Please specify a different peer subagent.`, "subagents.handoff.self", { id: shortId(fromId) }));
|
|
@@ -679,7 +1020,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
679
1020
|
const target = host.getSubagent(p.toRunId);
|
|
680
1021
|
if (!target) {
|
|
681
1022
|
const missingId = shortId(p.toRunId);
|
|
682
|
-
return text(pick(getLang(), `未找到目标子代理 ${missingId}(可能已移出或不存在)。请用
|
|
1023
|
+
return text(pick(getLang(), `未找到目标子代理 ${missingId}(可能已移出或不存在)。请用 conversation(action="list") 确认可用的子代理。`, `Target subagent ${missingId} not found (may have been dismissed or non-existent). Use conversation(action="list") to check available subagents.`, "subagents.handoff.not.found", { missingId }));
|
|
683
1024
|
}
|
|
684
1025
|
try {
|
|
685
1026
|
await host.handoffSubagent(fromId, executionOf(target), p.payload);
|
|
@@ -709,7 +1050,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
709
1050
|
}
|
|
710
1051
|
const isFinishedAll = p.scope === "finished_all";
|
|
711
1052
|
if (explicitIds.length === 0 && !isFinishedAll) {
|
|
712
|
-
return text(pick(getLang(), '
|
|
1053
|
+
return text(pick(getLang(), 'conversation(action="dismiss") 缺少目标参数:请指定 runId、runIds 或 scope="finished_all"。', 'conversation(action="dismiss") requires target parameter: specify runId, runIds, or scope="finished_all".', "subagents.dismiss.missing.target"));
|
|
713
1054
|
}
|
|
714
1055
|
const selfId = selfIdOf();
|
|
715
1056
|
const activeConvId = host.getActiveConversationId?.();
|
|
@@ -767,7 +1108,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
767
1108
|
const isRunning = snapshot.streaming || snapshot.state === "running";
|
|
768
1109
|
if (isRunning && !p.force) {
|
|
769
1110
|
const runningId = shortId(targetId);
|
|
770
|
-
return text(pick(getLang(), `子代理 ${runningId} 仍在运行中(状态:${snapshot.state})。请等待其完成、调用
|
|
1111
|
+
return text(pick(getLang(), `子代理 ${runningId} 仍在运行中(状态:${snapshot.state})。请等待其完成、调用 conversation(action="stop"),或指定 force=true 强行中止并移出。`, `Subagent ${runningId} is still running (state: ${snapshot.state}). Wait for it to finish, call conversation(action="stop"), or specify force=true to force abort and dismiss.`, "subagents.dismiss.running", { runningId, state: snapshot.state }));
|
|
771
1112
|
}
|
|
772
1113
|
if (host.finalizeSubagentWorktree) {
|
|
773
1114
|
await host.finalizeSubagentWorktree(targetId);
|
|
@@ -796,7 +1137,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
796
1137
|
return text(pick(getLang(), `移出子代理 ${failedId} 失败:${res.reason ?? "未知原因"}。`, `Failed to dismiss subagent ${failedId}: ${res.reason ?? "unknown reason"}.`, "subagents.dismiss.failed", { failedId, reason: res.reason ?? "unknown" }));
|
|
797
1138
|
}
|
|
798
1139
|
const doneId = shortId(targetId);
|
|
799
|
-
return text(pick(getLang(), `已移出子代理 ${doneId}。移出后不可逆(会话已从左栏移除并释放运行时与临时数据)。提示:如需获取产物,请在移出前调用
|
|
1140
|
+
return text(pick(getLang(), `已移出子代理 ${doneId}。移出后不可逆(会话已从左栏移除并释放运行时与临时数据)。提示:如需获取产物,请在移出前调用 conversation(action="get_result")。`, `Dismissed subagent ${doneId}. Dismissal is irreversible (session removed from panel, runtime and temporary data released). Note: call conversation(action="get_result") before dismissal if you need its output.`, "subagents.dismiss.success.single", { doneId }), { dismissed: [targetId], skipped: [] });
|
|
800
1141
|
}
|
|
801
1142
|
candidateIds.sort((a, b) => depthOf(b) - depthOf(a));
|
|
802
1143
|
const dismissed = [];
|
|
@@ -860,7 +1201,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
860
1201
|
const skippedCount = skipped.length;
|
|
861
1202
|
const skippedZh = skippedCount > 0 ? `(${skippedCount} 个已跳过)` : "";
|
|
862
1203
|
const skippedEn = skippedCount > 0 ? ` (${skippedCount} skipped)` : "";
|
|
863
|
-
return text(pick(getLang(), `已成功移出 ${dismissed.length} 个子代理${skippedZh}。移出后不可逆(会话已从左栏移除并释放运行时与临时数据)。提示:如需获取产物,请在移出前调用
|
|
1204
|
+
return text(pick(getLang(), `已成功移出 ${dismissed.length} 个子代理${skippedZh}。移出后不可逆(会话已从左栏移除并释放运行时与临时数据)。提示:如需获取产物,请在移出前调用 conversation(action="get_result")。`, `Successfully dismissed ${dismissed.length} subagent(s)${skippedEn}. Dismissal is irreversible (sessions removed from panel, runtimes and temporary data released). Note: call conversation(action="get_result") before dismissal if you need their outputs.`, "subagents.dismiss.success.batch", { count: dismissed.length, skippedZh, skippedEn }), { dismissed, skipped });
|
|
864
1205
|
}
|
|
865
1206
|
default:
|
|
866
1207
|
return text(pick(getLang(), `未知 action:${action}。支持的 action:${SUBAGENT_ACTIONS.join(", ")}。`, `Unknown action: ${action}. Supported actions: ${SUBAGENT_ACTIONS.join(", ")}.`, "subagents.action.unknown", { action }));
|
|
@@ -923,9 +1264,86 @@ function verdictText(r, lang = "en") {
|
|
|
923
1264
|
return pick(lang, "(被中止,未产出结论)", "(Aborted, no conclusion produced.)", "subagents.verdict.aborted");
|
|
924
1265
|
return "";
|
|
925
1266
|
}
|
|
1267
|
+
/** 账本证据摘要(记录里只有计数与裁决,没有原始 claims)。 */
|
|
1268
|
+
function formatLedgerEvidence(record, lang) {
|
|
1269
|
+
const ev = record.evidence;
|
|
1270
|
+
if (!ev)
|
|
1271
|
+
return "";
|
|
1272
|
+
const zh = lang === "zh";
|
|
1273
|
+
const label = evidenceVerdictLabel(ev.verdict, lang);
|
|
1274
|
+
const parts = [];
|
|
1275
|
+
if (ev.files > 0)
|
|
1276
|
+
parts.push(zh ? `${ev.matchedFiles}/${ev.files} 文件` : `${ev.matchedFiles}/${ev.files} files`);
|
|
1277
|
+
if (ev.commands > 0) {
|
|
1278
|
+
parts.push(zh ? `${ev.matchedCommands}/${ev.commands} 命令` : `${ev.matchedCommands}/${ev.commands} commands`);
|
|
1279
|
+
}
|
|
1280
|
+
if (ev.none)
|
|
1281
|
+
parts.push(zh ? "声明无改动" : "declared no changes");
|
|
1282
|
+
if (ev.blocked)
|
|
1283
|
+
parts.push(zh ? `受阻:${ev.blocked}` : `blocked: ${ev.blocked}`);
|
|
1284
|
+
if (parts.length === 0)
|
|
1285
|
+
return label;
|
|
1286
|
+
return `${label}${zh ? "(" : " ("}${parts.join(zh ? "、" : ", ")}${zh ? ")" : ")"}`;
|
|
1287
|
+
}
|
|
1288
|
+
/** `get_result` 的账本回落:进程里已经没有这个运行了,只能给出落盘的结论与证据。 */
|
|
1289
|
+
function formatLedgerRunResult(record, lang, timeline = []) {
|
|
1290
|
+
const zh = lang === "zh";
|
|
1291
|
+
const id = shortId(record.runId);
|
|
1292
|
+
const lines = [
|
|
1293
|
+
zh
|
|
1294
|
+
? `运行 ${id}(${record.type})已不在进程里;账本状态:${record.state}`
|
|
1295
|
+
: `Run ${id} (${record.type}) is no longer in process; ledger state: ${record.state}`,
|
|
1296
|
+
];
|
|
1297
|
+
if (record.title)
|
|
1298
|
+
lines.push(zh ? `目标:${record.title}` : `Goal: ${record.title}`);
|
|
1299
|
+
if (record.evidence)
|
|
1300
|
+
lines.push(zh ? `证据:${formatLedgerEvidence(record, lang)}` : `Evidence: ${formatLedgerEvidence(record, lang)}`);
|
|
1301
|
+
if (record.error)
|
|
1302
|
+
lines.push(zh ? `错误:${record.error}` : `Error: ${record.error}`);
|
|
1303
|
+
if (record.worktree) {
|
|
1304
|
+
const wt = record.worktree;
|
|
1305
|
+
lines.push(zh
|
|
1306
|
+
? `工作树:${wt.path}(分支 ${wt.branch}${wt.cleanedUp ? " · 已清理" : ""})`
|
|
1307
|
+
: `Worktree: ${wt.path} (branch ${wt.branch}${wt.cleanedUp ? " · cleaned" : ""})`);
|
|
1308
|
+
}
|
|
1309
|
+
if (record.sessionFile) {
|
|
1310
|
+
lines.push(zh
|
|
1311
|
+
? `会话记录:${record.sessionFile}(可在历史对话里打开回看)`
|
|
1312
|
+
: `Session file: ${record.sessionFile} (openable from History)`);
|
|
1313
|
+
}
|
|
1314
|
+
if (record.outputTail) {
|
|
1315
|
+
lines.push(zh ? `最后输出(尾部):\n${record.outputTail}` : `Last output (tail):\n${record.outputTail}`);
|
|
1316
|
+
}
|
|
1317
|
+
if (timeline.length > 0) {
|
|
1318
|
+
lines.push(zh ? `生命周期(最近 ${timeline.length} 条):` : `Lifecycle (last ${timeline.length}):`);
|
|
1319
|
+
for (const event of timeline) {
|
|
1320
|
+
const at = new Date(event.ts);
|
|
1321
|
+
const when = Number.isFinite(at.getTime()) ? at.toISOString().slice(11, 19) : "--:--:--";
|
|
1322
|
+
lines.push(`- ${when} ${event.event}`);
|
|
1323
|
+
}
|
|
1324
|
+
}
|
|
1325
|
+
if (record.resumedBy) {
|
|
1326
|
+
lines.push(zh ? `已续跑为:${record.resumedBy}` : `Resumed as: ${record.resumedBy}`);
|
|
1327
|
+
}
|
|
1328
|
+
else if (record.state === "running" || record.state === "interrupted") {
|
|
1329
|
+
lines.push(zh
|
|
1330
|
+
? `继续:conversation(action="resume", runId="${record.runId}")(带已知进度重派;旧会话不落盘,接不上原转录)`
|
|
1331
|
+
: `Continue: conversation(action="resume", runId="${record.runId}") (relaunch with known progress; the old in-memory session cannot be reattached)`);
|
|
1332
|
+
}
|
|
1333
|
+
return lines.join("\n");
|
|
1334
|
+
}
|
|
1335
|
+
function formatUsageTag(usage, lang) {
|
|
1336
|
+
if (!usage)
|
|
1337
|
+
return "";
|
|
1338
|
+
const zh = lang === "zh";
|
|
1339
|
+
const short = (n) => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n));
|
|
1340
|
+
return zh
|
|
1341
|
+
? ` · ${short(usage.input)}↓${short(usage.output)}↑`
|
|
1342
|
+
: ` · ${short(usage.input)}in/${short(usage.output)}out`;
|
|
1343
|
+
}
|
|
926
1344
|
function promptRemaining(remaining, lang = "en") {
|
|
927
1345
|
if (remaining.length === 0)
|
|
928
1346
|
return "";
|
|
929
1347
|
const pendingIds = remaining.map(shortId).join(", ");
|
|
930
|
-
return pick(lang, `\n未完成:${pendingIds}。可再次调用 subagent(action="wait_all")继续等待耗时任务,或使用 steer 补充指令 / stop 中止。`, `\nPending: ${pendingIds}. You may call
|
|
1348
|
+
return pick(lang, `\n未完成:${pendingIds}。可再次调用 subagent(action="wait_all")继续等待耗时任务,或使用 steer 补充指令 / stop 中止。`, `\nPending: ${pendingIds}. You may call conversation(action="wait_all") again to continue waiting for long tasks, or use steer to add instructions / stop to abort.`, "subagents.wait.pending", { pendingIds: pendingIds });
|
|
931
1349
|
}
|