pi-web-ui 0.113.1 → 0.114.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 +43 -1
- package/README.md +117 -246
- package/README.zh-CN.md +145 -217
- package/README.zh-TW.md +145 -217
- package/bin/device-hub-cli.mjs +577 -0
- package/bin/pi-device-hub.mjs +9 -0
- package/bin/pi-web-ui.mjs +47 -15
- package/dist/server/agent-service-daemon.js +102 -24
- package/dist/server/agent-service.js +2289 -1120
- package/dist/server/approval-rules.js +29 -3
- package/dist/server/ask-user-question-tool.js +8 -8
- package/dist/server/atomic-file.js +35 -14
- package/dist/server/attachment-store.js +71 -35
- package/dist/server/attachments.js +18 -8
- package/dist/server/canvas/canvas-agent-tool.js +65 -15
- package/dist/server/canvas/canvas-dispatch.js +61 -20
- package/dist/server/canvas/canvas-orchestrator.js +516 -199
- package/dist/server/canvas/canvas-scheduler.js +99 -0
- package/dist/server/canvas/canvas-store.js +107 -54
- package/dist/server/canvas/canvas-validation.js +131 -0
- package/dist/server/canvas/canvas-workspace.js +284 -0
- package/dist/server/client-id-utils.js +8 -0
- package/dist/server/client-state.js +104 -22
- package/dist/server/communicate-tool.js +76 -0
- package/dist/server/compact-context-tool.js +2 -3
- package/dist/server/compaction-instructions.js +75 -0
- package/dist/server/compaction-markers.js +7 -2
- package/dist/server/compaction-state.js +84 -0
- package/dist/server/composer-drafts.js +43 -40
- package/dist/server/context-evidence.js +346 -0
- package/dist/server/conversation-communication.js +368 -0
- package/dist/server/conversation-read-tool.js +3 -4
- package/dist/server/conversation-tool-names.js +14 -0
- package/dist/server/conversation-tool.js +57 -0
- package/dist/server/delegate-mode.js +17 -4
- package/dist/server/device-center/bot-catalog.js +88 -0
- package/dist/server/device-center/bot-execution.js +106 -0
- package/dist/server/device-center/bots.js +170 -0
- package/dist/server/device-center/collab-service.js +153 -0
- package/dist/server/device-center/collab-tool.js +184 -0
- package/dist/server/device-center/connector.js +332 -0
- package/dist/server/device-center/desktop-linux.js +372 -0
- package/dist/server/device-center/desktop-native.js +413 -0
- package/dist/server/device-center/desktop-page.js +232 -0
- package/dist/server/device-center/desktop-setup.js +30 -0
- package/dist/server/device-center/desktop.js +387 -0
- package/dist/server/device-center/device-portals.js +241 -0
- package/dist/server/device-center/execution-failure.js +70 -0
- package/dist/server/device-center/executor.js +371 -0
- package/dist/server/device-center/file-sync.js +493 -0
- package/dist/server/device-center/hub-auth.js +69 -0
- package/dist/server/device-center/hub-page.js +68 -0
- package/dist/server/device-center/hub-setup.js +214 -0
- package/dist/server/device-center/hub.js +829 -0
- package/dist/server/device-center/local-page.js +17 -0
- package/dist/server/device-center/local.js +476 -0
- package/dist/server/device-center/main.js +118 -0
- package/dist/server/device-center/native-desktop/macos.js +192 -0
- package/dist/server/device-center/native-desktop/windows.js +118 -0
- package/dist/server/device-center/path-portal.js +120 -0
- package/dist/server/device-center/relay.js +959 -0
- package/dist/server/device-center/runtime.js +253 -0
- package/dist/server/device-center/smoke-preview.js +3 -0
- package/dist/server/device-center/store.js +122 -0
- package/dist/server/device-center/task-error.js +14 -0
- package/dist/server/device-center/transfers.js +293 -0
- package/dist/server/device-center/workspaces.js +45 -0
- package/dist/server/dispatch-domain-handlers.js +83 -27
- package/dist/server/dsh/dsh-agent-service.js +277 -158
- package/dist/server/dsh/dsh-client.js +12 -2
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/evidence-tool-hooks.js +49 -0
- package/dist/server/file-save.js +95 -0
- package/dist/server/file-transfer-routes.js +97 -47
- package/dist/server/files-service.js +38 -26
- package/dist/server/goal-review-gate.js +16 -6
- package/dist/server/goal-service.js +54 -30
- package/dist/server/http-proxy.js +120 -0
- package/dist/server/index.js +229 -223
- package/dist/server/load-timing.js +31 -0
- package/dist/server/mcp-bridge.js +219 -94
- package/dist/server/mcp-hot-reload.js +31 -5
- package/dist/server/mcp-manager.js +192 -93
- package/dist/server/mcp-oauth-login.js +169 -0
- package/dist/server/mcp-oauth-ui.js +137 -0
- package/dist/server/mcp-oauth.js +395 -0
- package/dist/server/mcp-project-runtime.js +207 -0
- package/dist/server/message-window.js +74 -21
- package/dist/server/net-guard.js +122 -20
- package/dist/server/payload-limits.js +17 -0
- package/dist/server/pending-question.js +82 -0
- package/dist/server/plan-mode.js +338 -137
- package/dist/server/plugin-assets.js +8 -4
- package/dist/server/plugin-chat-attachments.js +48 -0
- package/dist/server/plugin-facilities.js +67 -220
- package/dist/server/plugin-installer.js +2 -1
- package/dist/server/plugin-removal.js +49 -0
- package/dist/server/plugin-secrets.js +179 -0
- package/dist/server/plugins.js +262 -92
- package/dist/server/preset-fields.js +49 -0
- package/dist/server/preset-plugin-dependencies.js +57 -0
- package/dist/server/preset-share.js +112 -72
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/queue-modes.js +10 -0
- package/dist/server/remote-ssh-service.js +160 -67
- package/dist/server/request-context.js +164 -0
- package/dist/server/sandbox-data.js +655 -0
- package/dist/server/sandbox-engines.js +7 -0
- package/dist/server/sandbox-runtime-gate.js +41 -0
- package/dist/server/sandbox-service.js +139 -698
- package/dist/server/sandbox-tool.js +21 -4
- package/dist/server/scheduler-tasks.js +63 -48
- package/dist/server/serialize.js +48 -19
- package/dist/server/session-branch.js +25 -3
- package/dist/server/session-parser.js +28 -18
- package/dist/server/session-scan.js +130 -0
- package/dist/server/session-search.js +51 -37
- package/dist/server/settings-service.js +267 -111
- package/dist/server/setup-config.js +58 -0
- package/dist/server/skill-maintenance.js +112 -24
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagent-notify.js +4 -1
- package/dist/server/subagent-security-gate.js +52 -11
- package/dist/server/subagent-task.js +27 -0
- package/dist/server/subagents.js +217 -46
- package/dist/server/tabs.js +9 -1
- package/dist/server/terminals.js +467 -363
- package/dist/server/tool-guards.js +42 -6
- package/dist/server/tool-manager.js +47 -20
- package/dist/server/tool-overrides.js +13 -11
- package/dist/server/tool-prompt-overrides.js +32 -2
- package/dist/server/tool-prompts.js +1 -1
- package/dist/server/turn-timing.js +11 -0
- package/dist/server/universal/session-store.js +48 -6
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +334 -231
- package/dist/server/uploads.js +64 -5
- package/dist/server/worktree-service.js +32 -24
- package/dist/server/ws-pending-queue.js +73 -27
- package/docs/device-center.md +142 -0
- package/docs/device-desktop.md +48 -0
- package/package.json +4 -1
- package/plugin-sdk/index.d.ts +28 -6
- package/plugin-sdk/ssh-host-trust.mjs +225 -0
- package/plugins/catalog.json +1 -1
- package/themes/aetheris.css +1 -107
- package/themes/ayu-light.css +5 -29
- package/themes/bases/flow-base.css +0 -6
- package/themes/bases/statusbar-flat-base.css +112 -0
- package/themes/bases/zhujian-base.css +1 -0
- package/themes/bases/zhupi-base.css +1 -0
- package/themes/catppuccin-latte.css +4 -27
- package/themes/catppuccin.css +4 -35
- package/themes/claude-code-dark.css +1 -0
- package/themes/codex.css +4 -28
- package/themes/cyberpunk.css +3 -61
- package/themes/dark-teal.css +0 -1
- package/themes/dazzle.css +3 -73
- package/themes/everforest-light.css +4 -27
- package/themes/geist.css +4 -28
- package/themes/gruvbox-light.css +4 -27
- package/themes/kanagawa-lotus.css +4 -27
- package/themes/md-preview.css +3 -213
- package/themes/mist.css +4 -24
- package/themes/nord.css +4 -35
- package/themes/one-dark.css +4 -37
- package/themes/paper.css +4 -16
- package/themes/rose-pine-dawn.css +4 -28
- package/themes/sakura.css +4 -24
- package/themes/solarized-light.css +4 -27
- package/themes/tokyo-night.css +3 -34
- package/themes/white.css +4 -26
- package/themes/zhujian-dark.css +1 -0
- package/themes/zhupi-dark.css +1 -0
- package/web/dist/.build-assets.json +1 -0
- package/web/dist/assets/BgTasksModal-CS7UNzcw.js +1 -0
- package/web/dist/assets/BgTasksModal-Dk-tp78W.js +1 -0
- package/web/dist/assets/CanvasStudio-BEJZE5BI.js +1579 -0
- package/web/dist/assets/CanvasStudio-CgUNHqos.js +1579 -0
- package/web/dist/assets/DeviceCenter-C8_CbxQ3.js +3 -0
- package/web/dist/assets/DeviceCenter-CVblvhNX.js +3 -0
- package/web/dist/assets/Dropdown-Oug0DDte.js +1 -0
- package/web/dist/assets/FilePreview-CvdX6nr6.js +2 -0
- package/web/dist/assets/FilePreview-kCZhfBAF.js +2 -0
- package/web/dist/assets/GlobalSearchModal-BLH63yYP.js +1 -0
- package/web/dist/assets/GlobalSearchModal-DAkvlvp6.js +1 -0
- package/web/dist/assets/GroupConversation-Cgo4xbpa.js +1 -0
- package/web/dist/assets/GroupConversation-DZ71jEi8.js +1 -0
- package/web/dist/assets/ModelConfigModal-BpWdFdQC.js +2 -0
- package/web/dist/assets/PiSetupModal-mkWPSxMj.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-VK_jqXYS.js +1 -0
- package/web/dist/assets/SCMPanel-BP1TUT-V.js +2 -0
- package/web/dist/assets/SCMPanel-BscPm9kf.js +2 -0
- package/web/dist/assets/SettingsModal-C8UgMjVM.js +20 -0
- package/web/dist/assets/SettingsModal-VynB7jNb.js +20 -0
- package/web/dist/assets/TerminalPanel-D6cPRFei.js +3 -0
- package/web/dist/assets/TerminalPanel-DL20uKgU.js +3 -0
- package/web/dist/assets/TuiOverlayModal-Dst3BmT8.js +1 -0
- package/web/dist/assets/TuiOverlayModal-NCkpNtTp.js +1 -0
- package/web/dist/assets/UniversalPathPicker-CfQFc_c3.js +1 -0
- package/web/dist/assets/UniversalPathPicker-DwxwNcFw.js +1 -0
- package/web/dist/assets/app-globals-CnO6KlEM.js +325 -0
- package/web/dist/assets/desktop-DPyTy4M3.js +1 -0
- package/web/dist/assets/es-DWMIuDU2.js +2 -0
- package/web/dist/assets/index-CPgAH5q7.js +83 -0
- package/web/dist/assets/index-Cje8iugL.js +83 -0
- package/web/dist/assets/index-DnKeiDbj.css +1 -0
- package/web/dist/assets/markdown-BggnuQ4H.js +40 -0
- package/web/dist/assets/markdown-C8LL_u4z.css +1 -0
- package/web/dist/assets/math-1uRJCsA9.js +257 -0
- package/web/dist/assets/math-BorAY7qD.css +1 -0
- package/web/dist/assets/plugin-host-CqA4yW6w.js +1 -0
- package/web/dist/assets/shortcut-stack-hhrDyRBn.js +1 -0
- package/web/dist/assets/theme-BqdAjEjF.js +1 -0
- package/web/dist/assets/uuid-BzDIGCwP.js +1 -0
- package/web/dist/index.html +15 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/TerminalPanel-Ci55JtJL.js +0 -3
- package/web/dist/assets/index-ByiO9f-N.js +0 -2008
- package/web/dist/assets/index-ycGLh4a4.css +0 -1
- package/web/dist/assets/markdown-BJZlfvdP.js +0 -296
- package/web/dist/assets/markdown-DSNUiDzp.css +0 -1
package/dist/server/subagents.js
CHANGED
|
@@ -30,6 +30,8 @@ import { Type } from "typebox";
|
|
|
30
30
|
import { pick } from "./i18n.js";
|
|
31
31
|
import { resolveSecurityMode } from "./subagent-security-gate.js";
|
|
32
32
|
import { THINKING_LEVELS } from "./subagent-templates.js";
|
|
33
|
+
import { CONVERSATION_TOOL_NAME, SUBAGENT_TOOL_NAME } from "./tool-manager.js";
|
|
34
|
+
export { CONVERSATION_TOOL_NAME, SUBAGENT_TOOL_NAME } from "./tool-manager.js";
|
|
33
35
|
/**
|
|
34
36
|
* subagent_wait_all 的最长阻塞时间:必须短暂低于工具看门狗(默认 20 分钟,
|
|
35
37
|
* PI_WEB_TOOL_TIMEOUT_MS 可调),否则看门狗会先中止整个会话而不是让 wait
|
|
@@ -49,10 +51,10 @@ export function computeWaitCapMs(watchdogMs) {
|
|
|
49
51
|
: 20 * 60_000;
|
|
50
52
|
return Math.max(Math.floor(watchdog * 0.8), 5_000);
|
|
51
53
|
}
|
|
52
|
-
/**
|
|
53
|
-
*
|
|
54
|
+
/** Idle is terminal only when the host has no pending task dependencies.
|
|
55
|
+
* Idle failures/cancellations remain terminal regardless of pending dependencies. */
|
|
54
56
|
export function isSubagentTerminal(r) {
|
|
55
|
-
return !!r && !r.streaming;
|
|
57
|
+
return !!r && !r.streaming && (!r.taskPending || !!r.error || !!r.canceled);
|
|
56
58
|
}
|
|
57
59
|
/** 从 prompt 取首行作为标题(截断 40 字符)。 */
|
|
58
60
|
export function subagentTitle(prompt) {
|
|
@@ -68,29 +70,39 @@ export function subagentTitle(prompt) {
|
|
|
68
70
|
* 可能已切到别的项目,直接读 activeId 会把孩子记到无关会话名下(错组/沉底)。
|
|
69
71
|
* 每个会话创建 runtime 时用本函数包一层,让它的 spawn 天然带自己的会话 id。
|
|
70
72
|
*/
|
|
71
|
-
export function withSubagentOwner(host, ownerId) {
|
|
73
|
+
export function withSubagentOwner(host, ownerId, resolveOwner = () => ownerId) {
|
|
72
74
|
return {
|
|
73
75
|
...host,
|
|
74
|
-
spawnSubagent: (prompt, type, cwd, templateName, model, _parentId, persist, thinking, notifyOnDone, isolation, extra) => {
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
spawnSubagent: (prompt, type, cwd, templateName, model, _parentId, persist, thinking, notifyOnDone, isolation, extra, signal) => {
|
|
77
|
+
signal?.throwIfAborted();
|
|
78
|
+
const args = [prompt, type, cwd, templateName, model, resolveOwner(), persist, thinking, notifyOnDone];
|
|
79
|
+
if (isolation !== undefined || extra !== undefined || signal !== undefined) {
|
|
77
80
|
args.push(isolation);
|
|
78
81
|
}
|
|
79
|
-
if (extra !== undefined) {
|
|
82
|
+
if (extra !== undefined || signal !== undefined) {
|
|
80
83
|
args.push(extra);
|
|
81
84
|
}
|
|
85
|
+
if (signal !== undefined)
|
|
86
|
+
args.push(signal);
|
|
82
87
|
return host.spawnSubagent(...args);
|
|
83
88
|
},
|
|
84
|
-
handoffSubagent: (fromRunId, toRunId, payload) =>
|
|
89
|
+
handoffSubagent: async (fromRunId, toRunId, payload) => {
|
|
90
|
+
const selfId = resolveOwner();
|
|
91
|
+
if (!selfId)
|
|
92
|
+
throw new Error("Handoff requires a verified conversation identity.");
|
|
93
|
+
if (fromRunId && fromRunId !== selfId)
|
|
94
|
+
throw new Error("Handoff source must match the calling conversation.");
|
|
95
|
+
return host.handoffSubagent(selfId, toRunId, payload);
|
|
96
|
+
},
|
|
85
97
|
markSubagentsConsumed: (runIds) => host.markSubagentsConsumed?.(runIds),
|
|
86
98
|
finalizeSubagentWorktree: (convId) => host.finalizeSubagentWorktree?.(convId) ?? Promise.resolve(),
|
|
87
99
|
getActiveConversationId: () => host.getActiveConversationId?.(),
|
|
88
100
|
dismissSubagent: (convId, opts) => host.dismissSubagent?.(convId, opts) ?? Promise.resolve({ ok: false, reason: "unsupported" }),
|
|
89
101
|
};
|
|
90
102
|
}
|
|
91
|
-
export const SUBAGENT_TOOL_NAME = "subagent";
|
|
92
103
|
export const SUBAGENT_ACTIONS = [
|
|
93
104
|
"spawn",
|
|
105
|
+
"complete",
|
|
94
106
|
"get_result",
|
|
95
107
|
"steer",
|
|
96
108
|
"list",
|
|
@@ -99,6 +111,9 @@ export const SUBAGENT_ACTIONS = [
|
|
|
99
111
|
"templates",
|
|
100
112
|
"handoff",
|
|
101
113
|
"dismiss",
|
|
114
|
+
"consult",
|
|
115
|
+
"answer",
|
|
116
|
+
"escalate",
|
|
102
117
|
];
|
|
103
118
|
/**
|
|
104
119
|
* 单 action 子代理总工具(注册进每个会话的 customTools,供主 agent 驱动子代理)。
|
|
@@ -120,6 +135,9 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
120
135
|
content: [{ type: "text", text: t }],
|
|
121
136
|
details,
|
|
122
137
|
});
|
|
138
|
+
// Share delivery memory across the primary tool and legacy alias. Keep only live requests.
|
|
139
|
+
const deliveredConsults = new Set();
|
|
140
|
+
const consultKey = (parentId, runId, requestId) => JSON.stringify([parentId, runId, requestId]);
|
|
123
141
|
const expandDescendants = (roots) => {
|
|
124
142
|
if (roots instanceof Set ? roots.size === 0 : roots.length === 0)
|
|
125
143
|
return [];
|
|
@@ -182,29 +200,62 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
182
200
|
: computeWaitCapMs();
|
|
183
201
|
const capSeconds = Math.floor(currentWaitCapMs / 1000);
|
|
184
202
|
return defineTool({
|
|
185
|
-
name:
|
|
186
|
-
label: "
|
|
187
|
-
description: "
|
|
203
|
+
name: CONVERSATION_TOOL_NAME,
|
|
204
|
+
label: "Conversation collaboration",
|
|
205
|
+
description: "Create and manage collaborative conversations, including temporary subagents and persistent sessions, for delegation, research, and execution. " +
|
|
188
206
|
"Each action's arguments are documented on the parameters below.",
|
|
189
|
-
promptSnippet: "
|
|
207
|
+
promptSnippet: "Delegate tasks, inspect results, or request task completion.",
|
|
208
|
+
promptGuidelines: [
|
|
209
|
+
"Prefer communicate for messages and questions; consult/answer/escalate/handoff remain compatible.",
|
|
210
|
+
],
|
|
190
211
|
parameters: Type.Object({
|
|
191
212
|
action: Type.Unsafe({
|
|
192
213
|
type: "string",
|
|
193
214
|
enum: [...SUBAGENT_ACTIONS],
|
|
194
215
|
description: "The subagent action to perform.",
|
|
195
216
|
}),
|
|
217
|
+
questions: Type.Optional(Type.Array(Type.Object({
|
|
218
|
+
id: Type.String({ minLength: 1 }),
|
|
219
|
+
question: Type.String({ minLength: 1 }),
|
|
220
|
+
detail: Type.Optional(Type.String()),
|
|
221
|
+
header: Type.Optional(Type.String()),
|
|
222
|
+
options: Type.Optional(Type.Array(Type.Object({
|
|
223
|
+
label: Type.String(),
|
|
224
|
+
description: Type.Optional(Type.String()),
|
|
225
|
+
preview: Type.Optional(Type.String()),
|
|
226
|
+
recommended: Type.Optional(Type.Boolean()),
|
|
227
|
+
}))),
|
|
228
|
+
multiSelect: Type.Optional(Type.Boolean()),
|
|
229
|
+
dependsOn: Type.Optional(Type.Object({
|
|
230
|
+
questionId: Type.String(),
|
|
231
|
+
value: Type.Optional(Type.Union([Type.String(), Type.Array(Type.String())])),
|
|
232
|
+
})),
|
|
233
|
+
optionsMap: Type.Optional(Type.Record(Type.String(), Type.Array(Type.Object({
|
|
234
|
+
label: Type.String(),
|
|
235
|
+
description: Type.Optional(Type.String()),
|
|
236
|
+
preview: Type.Optional(Type.String()),
|
|
237
|
+
recommended: Type.Optional(Type.Boolean()),
|
|
238
|
+
})))),
|
|
239
|
+
}), { description: "consult: ask the parent for a decision.", minItems: 1, maxItems: 3 })),
|
|
240
|
+
requestId: Type.Optional(Type.String({ description: "answer/escalate: pending consult request ID." })),
|
|
241
|
+
answers: Type.Optional(Type.Array(Type.Object({
|
|
242
|
+
id: Type.String(),
|
|
243
|
+
selected: Type.Array(Type.String()),
|
|
244
|
+
custom: Type.Optional(Type.String()),
|
|
245
|
+
}), { description: "answer: responses to the child's consult.", minItems: 1 })),
|
|
196
246
|
prompt: Type.Optional(Type.String({
|
|
197
247
|
description: "spawn: instructions (goal, constraints, expected output).",
|
|
198
248
|
})),
|
|
199
249
|
runId: Type.Optional(Type.String({
|
|
200
|
-
description: "get_result/steer/stop/dismiss: target conversation ID.",
|
|
250
|
+
description: "get_result/steer/stop/dismiss/answer/escalate: target conversation ID.",
|
|
201
251
|
})),
|
|
202
252
|
runIds: Type.Optional(Type.Array(Type.String(), {
|
|
203
253
|
description: "wait_all/dismiss: conversation IDs to wait for or dismiss.",
|
|
204
254
|
})),
|
|
205
255
|
message: Type.Optional(Type.String({
|
|
206
|
-
description: "steer: follow-up instruction.",
|
|
256
|
+
description: "steer: follow-up instruction; complete: completion summary alias.",
|
|
207
257
|
})),
|
|
258
|
+
summary: Type.Optional(Type.String({ description: "complete: final task summary." })),
|
|
208
259
|
payload: Type.Optional(Type.String({
|
|
209
260
|
description: "handoff: what to transfer to the peer.",
|
|
210
261
|
})),
|
|
@@ -212,7 +263,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
212
263
|
description: "handoff: target peer ID.",
|
|
213
264
|
})),
|
|
214
265
|
fromRunId: Type.Optional(Type.String({
|
|
215
|
-
description: "handoff: source ID
|
|
266
|
+
description: "handoff: optional source ID; must match the calling conversation.",
|
|
216
267
|
})),
|
|
217
268
|
type: Type.Optional(Type.String({
|
|
218
269
|
description: "spawn: role/type (e.g. explore/implement/review, default: general). When matching a template name, the template and its security profile (e.g. readonly for explore, verify for review) are automatically applied.",
|
|
@@ -227,8 +278,8 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
227
278
|
enum: [...THINKING_LEVELS],
|
|
228
279
|
description: 'spawn: thinking budget level ("off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max").',
|
|
229
280
|
})),
|
|
230
|
-
notifyOnDone: Type.Optional(Type.Boolean({
|
|
231
|
-
description: "spawn:
|
|
281
|
+
notifyOnDone: Type.Optional(Type.Union([Type.Boolean(), Type.Literal("manual")], {
|
|
282
|
+
description: "spawn: true wakes parent per turn, false disables wakes, manual waits for task completion (default: true).",
|
|
232
283
|
})),
|
|
233
284
|
cwd: Type.Optional(Type.String({
|
|
234
285
|
description: "spawn: working directory (default = current).",
|
|
@@ -245,7 +296,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
245
296
|
description: "list: filter subagents by kind (default: all).",
|
|
246
297
|
})),
|
|
247
298
|
timeoutSeconds: Type.Optional(Type.Integer({
|
|
248
|
-
description: `wait_all: max wait in seconds (default: ${capSeconds}s).`,
|
|
299
|
+
description: `wait_all: max wait in seconds (default: ${capSeconds}s); returns early for new parent consults.`,
|
|
249
300
|
minimum: 1,
|
|
250
301
|
maximum: capSeconds,
|
|
251
302
|
})),
|
|
@@ -263,9 +314,75 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
263
314
|
execute: async (_id, p, signal, _onUpdate, ctx) => {
|
|
264
315
|
const action = (p.action ?? "").trim().toLowerCase();
|
|
265
316
|
if (!action) {
|
|
266
|
-
return text(pick(getLang(),
|
|
317
|
+
return text(pick(getLang(), `subagent 工具缺少 action 参数(可选:${SUBAGENT_ACTIONS.join(", ")})。`, `subagent tool requires an action parameter (one of: ${SUBAGENT_ACTIONS.join(", ")}).`, "subagents.action.missing"));
|
|
267
318
|
}
|
|
268
319
|
switch (action) {
|
|
320
|
+
case "complete": {
|
|
321
|
+
signal?.throwIfAborted();
|
|
322
|
+
const selfId = selfIdOf();
|
|
323
|
+
if (!selfId || !host.completeSubagent)
|
|
324
|
+
throw new Error("Task completion is unavailable.");
|
|
325
|
+
const summary = (p.summary ?? p.message ?? "").trim();
|
|
326
|
+
if (!summary)
|
|
327
|
+
throw new Error("complete requires a nonempty summary or message.");
|
|
328
|
+
const result = await host.completeSubagent(selfId, summary);
|
|
329
|
+
if (result && typeof result === "object" && "ok" in result && result.ok === false) {
|
|
330
|
+
throw new Error(String("error" in result ? result.error : "Completion request rejected."));
|
|
331
|
+
}
|
|
332
|
+
return text("Completion intent recorded; settlement waits for idle state and pending dependencies.", {
|
|
333
|
+
status: "completion_requested",
|
|
334
|
+
runId: selfId,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
case "consult": {
|
|
338
|
+
signal?.throwIfAborted();
|
|
339
|
+
const selfId = selfIdOf();
|
|
340
|
+
if (!selfId || !host.consultParent)
|
|
341
|
+
throw new Error("Parent consultation is unavailable.");
|
|
342
|
+
if (!Array.isArray(p.questions) ||
|
|
343
|
+
p.questions.length < 1 ||
|
|
344
|
+
p.questions.length > 3 ||
|
|
345
|
+
p.questions.some((q) => !q || typeof q.id !== "string" || !q.id.trim() || typeof q.question !== "string" || !q.question.trim()) ||
|
|
346
|
+
new Set(p.questions.map((q) => q.id)).size !== p.questions.length) {
|
|
347
|
+
throw new Error("consult requires 1-3 questions with unique IDs and nonempty text.");
|
|
348
|
+
}
|
|
349
|
+
const result = await host.consultParent(selfId, p.questions, signal);
|
|
350
|
+
signal?.throwIfAborted();
|
|
351
|
+
return text(`${JSON.stringify(result) ?? "Consult resolved."}\nIf timed_out, do not choose on the parent's behalf. Ask again with only the context needed for the decision.`, result);
|
|
352
|
+
}
|
|
353
|
+
case "answer":
|
|
354
|
+
case "escalate": {
|
|
355
|
+
signal?.throwIfAborted();
|
|
356
|
+
const selfId = selfIdOf();
|
|
357
|
+
if (!selfId || !p.runId?.trim() || !p.requestId?.trim()) {
|
|
358
|
+
throw new Error(`${action} requires caller identity, runId and requestId.`);
|
|
359
|
+
}
|
|
360
|
+
let result;
|
|
361
|
+
if (action === "answer") {
|
|
362
|
+
if (!host.answerConsult)
|
|
363
|
+
throw new Error("Consult answers are unavailable.");
|
|
364
|
+
if (!Array.isArray(p.answers) ||
|
|
365
|
+
p.answers.length === 0 ||
|
|
366
|
+
p.answers.some((a) => !a ||
|
|
367
|
+
typeof a.id !== "string" ||
|
|
368
|
+
!a.id.trim() ||
|
|
369
|
+
!Array.isArray(a.selected) ||
|
|
370
|
+
a.selected.some((s) => typeof s !== "string") ||
|
|
371
|
+
(a.custom !== undefined && typeof a.custom !== "string"))) {
|
|
372
|
+
throw new Error("answer requires structured answers.");
|
|
373
|
+
}
|
|
374
|
+
result = await host.answerConsult(selfId, p.runId, p.requestId, p.answers);
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
if (!host.escalateConsult)
|
|
378
|
+
throw new Error("Consult escalation is unavailable.");
|
|
379
|
+
result = await host.escalateConsult(selfId, p.runId, p.requestId);
|
|
380
|
+
}
|
|
381
|
+
if (result && typeof result === "object" && "ok" in result && result.ok === false) {
|
|
382
|
+
throw new Error("error" in result ? String(result.error) : `Consult ${action} rejected.`);
|
|
383
|
+
}
|
|
384
|
+
return text(JSON.stringify(result) ?? `Consult ${action} submitted.`, result);
|
|
385
|
+
}
|
|
269
386
|
case "spawn": {
|
|
270
387
|
if (!p.prompt || typeof p.prompt !== "string" || !p.prompt.trim()) {
|
|
271
388
|
return text(pick(getLang(), 'subagent(action="spawn") 缺少 prompt 参数。', 'subagent(action="spawn") requires prompt parameter.', "subagents.spawn.missing.prompt"));
|
|
@@ -304,12 +421,15 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
304
421
|
p.thinking,
|
|
305
422
|
p.notifyOnDone,
|
|
306
423
|
];
|
|
307
|
-
if (isolationMode === "worktree" || extra !== undefined) {
|
|
424
|
+
if (isolationMode === "worktree" || extra !== undefined || signal !== undefined) {
|
|
308
425
|
spawnArgs.push(isolationMode === "worktree" ? "worktree" : undefined);
|
|
309
426
|
}
|
|
310
|
-
if (extra !== undefined) {
|
|
427
|
+
if (extra !== undefined || signal !== undefined) {
|
|
311
428
|
spawnArgs.push(extra);
|
|
312
429
|
}
|
|
430
|
+
if (signal !== undefined)
|
|
431
|
+
spawnArgs.push(signal);
|
|
432
|
+
signal?.throwIfAborted();
|
|
313
433
|
convId = await host.spawnSubagent(...spawnArgs);
|
|
314
434
|
}
|
|
315
435
|
catch (err) {
|
|
@@ -359,7 +479,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
359
479
|
model: p.model,
|
|
360
480
|
thinking: p.thinking,
|
|
361
481
|
persisted: !!p.persist,
|
|
362
|
-
notifyOnDone: p.notifyOnDone
|
|
482
|
+
notifyOnDone: p.notifyOnDone ?? true,
|
|
363
483
|
isolation: isolationMode === "worktree" ? "worktree" : undefined,
|
|
364
484
|
});
|
|
365
485
|
}
|
|
@@ -376,7 +496,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
376
496
|
const doneDetail = verdictText(r, getLang());
|
|
377
497
|
const doneOutput = r.output || (getLang() === "zh" ? "(无结果)" : "(no result)");
|
|
378
498
|
const modelTag = r.model ? ` · ${r.model}${r.thinkingLevel ? `:${r.thinkingLevel}` : ""}` : "";
|
|
379
|
-
if (r
|
|
499
|
+
if (!isSubagentTerminal(r)) {
|
|
380
500
|
const runningId = shortId(r.convId);
|
|
381
501
|
const runningOutput = r.output || (getLang() === "zh" ? "(暂无输出)" : "(no output yet)");
|
|
382
502
|
return text(pick(getLang(), `子代理 ${runningId}(${r.type}${modelTag})仍在运行(状态 ${r.state})。\n当前输出:\n${runningOutput}`, `Subagent ${runningId} (${r.type}${modelTag}) is still running (state ${r.state}).\nCurrent output:\n${runningOutput}`, "subagents.get.running", { runningId, "r.type": r.type, modelTag, "r.state": r.state, runningOutput }), r);
|
|
@@ -497,7 +617,29 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
497
617
|
wanted.delete(selfId);
|
|
498
618
|
for (const ancId of selfAncestorIds)
|
|
499
619
|
wanted.delete(ancId);
|
|
620
|
+
const collectConsults = () => {
|
|
621
|
+
const parentId = selfIdOf();
|
|
622
|
+
if (!parentId || !host.getPendingConsults || signal?.aborted)
|
|
623
|
+
return;
|
|
624
|
+
// The host authorizes direct-child requests for this parent, independent of runIds.
|
|
625
|
+
const pending = host.getPendingConsults(parentId);
|
|
626
|
+
const liveKeys = new Set(pending.map((r) => consultKey(parentId, r.runId, r.requestId)));
|
|
627
|
+
for (const key of deliveredConsults) {
|
|
628
|
+
if (!liveKeys.has(key))
|
|
629
|
+
deliveredConsults.delete(key);
|
|
630
|
+
}
|
|
631
|
+
const requests = pending.filter((r) => !deliveredConsults.has(consultKey(parentId, r.runId, r.requestId)));
|
|
632
|
+
if (requests.length === 0)
|
|
633
|
+
return;
|
|
634
|
+
for (const r of requests)
|
|
635
|
+
deliveredConsults.add(consultKey(parentId, r.runId, r.requestId));
|
|
636
|
+
const result = { status: "needs_input", requests };
|
|
637
|
+
return text(`Child consults need your decision. Use answer or escalate before waiting again.\n${JSON.stringify(result)}`, result);
|
|
638
|
+
};
|
|
500
639
|
if (wanted.size === 0) {
|
|
640
|
+
const consults = collectConsults();
|
|
641
|
+
if (consults)
|
|
642
|
+
return consults;
|
|
501
643
|
return text(pick(getLang(), "没有需要等待的子代理(调用者自身与其祖先永不计入等待;子代理无参数调用时只等待属于它自己的后代)。", "No subagents to wait for (the calling session itself and its ancestors are never waited on; a subagent without runIds only waits for its own descendants).", "subagents.wait.empty"));
|
|
502
644
|
}
|
|
503
645
|
const liveWaitCapMs = typeof host.getWatchdogTimeoutMs === "function"
|
|
@@ -507,24 +649,37 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
507
649
|
const timeoutMs = Math.min(Math.max(p.timeoutSeconds ?? liveCapSeconds, 1), liveCapSeconds) * 1000;
|
|
508
650
|
const startedAt = Date.now();
|
|
509
651
|
const POLL_INTERVAL_MS = 250;
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
652
|
+
try {
|
|
653
|
+
const waitingParentId = selfIdOf();
|
|
654
|
+
if (waitingParentId)
|
|
655
|
+
host.setConsultWaiting?.(waitingParentId, true);
|
|
656
|
+
while (!signal?.aborted && Date.now() - startedAt < timeoutMs) {
|
|
657
|
+
for (const descId of expandDescendants(wanted)) {
|
|
658
|
+
if (selfId && descId === selfId)
|
|
659
|
+
continue;
|
|
660
|
+
if (selfAncestorIds.has(descId))
|
|
661
|
+
continue;
|
|
662
|
+
wanted.add(descId);
|
|
663
|
+
}
|
|
664
|
+
const consults = collectConsults();
|
|
665
|
+
if (consults)
|
|
666
|
+
return consults;
|
|
667
|
+
const allDone = Array.from(wanted).every((id) => {
|
|
668
|
+
const r = host.getSubagent(id);
|
|
669
|
+
// #488:getSubagent 返回 undefined = 已被移出(强行关闭/收尾清理)
|
|
670
|
+
// ——视为终态,与下方报告段「已移出或不存在」口径一致;否则等待
|
|
671
|
+
// 集合含被移出子代理时 allDone 恒 false,必然白等满 timeoutMs。
|
|
672
|
+
return r === undefined || isSubagentTerminal(r);
|
|
673
|
+
});
|
|
674
|
+
if (allDone)
|
|
675
|
+
break;
|
|
676
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
517
677
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
return r === undefined || isSubagentTerminal(r);
|
|
524
|
-
});
|
|
525
|
-
if (allDone)
|
|
526
|
-
break;
|
|
527
|
-
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
678
|
+
}
|
|
679
|
+
finally {
|
|
680
|
+
const waitingParentId = selfIdOf();
|
|
681
|
+
if (waitingParentId)
|
|
682
|
+
host.setConsultWaiting?.(waitingParentId, false);
|
|
528
683
|
}
|
|
529
684
|
const tLang = getLang();
|
|
530
685
|
const waitedSecs = Math.max(1, Math.round((Date.now() - startedAt) / 1000));
|
|
@@ -609,7 +764,13 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
609
764
|
return text(pick(getLang(), `可用的子代理模板(subagent 的 template 参数传名字,如 subagent(action="spawn", template="${firstTemplateName}")):\n${templateLines}`, `Available subagent templates (pass the name as subagent's template param, e.g. subagent(action="spawn", template="${firstTemplateName}")):\n${templateLines}`, "subagents.templates.list", { firstTemplateName, templateLines }));
|
|
610
765
|
}
|
|
611
766
|
case "handoff": {
|
|
612
|
-
|
|
767
|
+
signal?.throwIfAborted();
|
|
768
|
+
const fromId = selfIdOf();
|
|
769
|
+
if (!fromId)
|
|
770
|
+
throw new Error("Handoff requires a verified conversation identity.");
|
|
771
|
+
if (p.fromRunId && p.fromRunId !== fromId) {
|
|
772
|
+
throw new Error("Handoff source must match the calling conversation.");
|
|
773
|
+
}
|
|
613
774
|
if (!p.toRunId || typeof p.toRunId !== "string" || !p.toRunId.trim()) {
|
|
614
775
|
return text(pick(getLang(), 'subagent(action="handoff") 缺少 toRunId 参数。', 'subagent(action="handoff") requires toRunId parameter.', "subagents.handoff.missing.toRunId"));
|
|
615
776
|
}
|
|
@@ -807,7 +968,7 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
807
968
|
return text(pick(getLang(), `已成功移出 ${dismissed.length} 个子代理${skippedZh}。移出后不可逆(会话已从左栏移除并释放运行时与临时数据)。提示:如需获取产物,请在移出前调用 subagent(action="get_result")。`, `Successfully dismissed ${dismissed.length} subagent(s)${skippedEn}. Dismissal is irreversible (sessions removed from panel, runtimes and temporary data released). Note: call subagent(action="get_result") before dismissal if you need their outputs.`, "subagents.dismiss.success.batch", { count: dismissed.length, skippedZh, skippedEn }), { dismissed, skipped });
|
|
808
969
|
}
|
|
809
970
|
default:
|
|
810
|
-
return text(pick(getLang(), `未知 action:${action}。支持的 action
|
|
971
|
+
return text(pick(getLang(), `未知 action:${action}。支持的 action:${SUBAGENT_ACTIONS.join(", ")}。`, `Unknown action: ${action}. Supported actions: ${SUBAGENT_ACTIONS.join(", ")}.`, "subagents.action.unknown", { action }));
|
|
811
972
|
}
|
|
812
973
|
},
|
|
813
974
|
});
|
|
@@ -816,7 +977,17 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
816
977
|
* 保持数组签名的子代理工具导出,兼容原有调用点与批处理包装。
|
|
817
978
|
*/
|
|
818
979
|
export function makeSubagentTools(host, lang, selfConvId) {
|
|
819
|
-
|
|
980
|
+
const primary = makeSubagentTool(host, lang, selfConvId);
|
|
981
|
+
return [
|
|
982
|
+
primary,
|
|
983
|
+
{
|
|
984
|
+
...primary,
|
|
985
|
+
name: SUBAGENT_TOOL_NAME,
|
|
986
|
+
label: "Conversation collaboration (legacy alias)",
|
|
987
|
+
description: "Compatibility alias for conversation. Prefer conversation for new calls; parameters and behavior are identical.",
|
|
988
|
+
promptSnippet: "support existing subagent calls; prefer conversation",
|
|
989
|
+
},
|
|
990
|
+
];
|
|
820
991
|
}
|
|
821
992
|
/** 短 id 前缀(前端展示/日志用)。 */
|
|
822
993
|
function shortId(id) {
|
|
@@ -873,7 +1044,7 @@ function subagentVerdict(r, lang = "en") {
|
|
|
873
1044
|
return pick(lang, "error(报错)", "error", "subagents.verdict.error");
|
|
874
1045
|
if (r.canceled)
|
|
875
1046
|
return pick(lang, "canceled(已中止)", "canceled", "subagents.verdict.canceled");
|
|
876
|
-
return r.state;
|
|
1047
|
+
return r.taskPending ? "pending" : r.state;
|
|
877
1048
|
}
|
|
878
1049
|
/** 终态的可读说明(错误文本 / 中止说明 / 空)。运行中返回空。 */
|
|
879
1050
|
function verdictText(r, lang = "en") {
|
package/dist/server/tabs.js
CHANGED
|
@@ -32,7 +32,15 @@ export const ALL_TABS = ["chat", "terminal", "git", "search", "tasks", "settings
|
|
|
32
32
|
* is exactly the failure this module exists to prevent.
|
|
33
33
|
*/
|
|
34
34
|
const OWNED = {
|
|
35
|
-
terminal: [
|
|
35
|
+
terminal: [
|
|
36
|
+
"terminal_attach",
|
|
37
|
+
"terminal_create",
|
|
38
|
+
"terminal_input",
|
|
39
|
+
"terminal_resize",
|
|
40
|
+
"terminal_kill",
|
|
41
|
+
"rename_terminal",
|
|
42
|
+
"run_command",
|
|
43
|
+
],
|
|
36
44
|
git: ["scm_status", "scm_history", "scm_filediff", "scm_commit"],
|
|
37
45
|
tasks: ["list_bg_servers", "kill_background_server", "kill_background_servers"],
|
|
38
46
|
search: ["search_files", "search_sessions"],
|