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
|
@@ -21,6 +21,9 @@ import { checkDangerousToolCall, pluginApprovalCategory } from "./tool-approval.
|
|
|
21
21
|
import { parseHashlinePatch } from "./hashline-engine.js";
|
|
22
22
|
import { denialText, } from "./plugin-tool-guard.js";
|
|
23
23
|
import { createRemoteSdkOperations, isRemoteWorkspaceUri, parseRemoteWorkspaceUri, resolveRemoteWorkspacePath, restoreWorkspaceUriFromSessionDir, } from "./remote-ssh-service.js";
|
|
24
|
+
function checkCancellation(signal) {
|
|
25
|
+
signal?.throwIfAborted();
|
|
26
|
+
}
|
|
24
27
|
/**
|
|
25
28
|
* 计划模式闸门装饰(通用):套在任何工具定义外层,只在**执行前**判定一次。
|
|
26
29
|
* 与权限沙箱/插件守卫平行且更靠外 —— 计划模式是会话级硬约束,不给任何
|
|
@@ -31,6 +34,7 @@ export function withPlanModeGate(def, planMode, getLang) {
|
|
|
31
34
|
return {
|
|
32
35
|
...def,
|
|
33
36
|
execute: (async (...args) => {
|
|
37
|
+
checkCancellation(args[2]);
|
|
34
38
|
if (planMode()) {
|
|
35
39
|
const params = args[1];
|
|
36
40
|
const denied = planModeDenial(def.name, params);
|
|
@@ -45,6 +49,7 @@ export function withPlanModeGate(def, planMode, getLang) {
|
|
|
45
49
|
throw err;
|
|
46
50
|
}
|
|
47
51
|
}
|
|
52
|
+
checkCancellation(args[2]);
|
|
48
53
|
return def.execute(...args);
|
|
49
54
|
}),
|
|
50
55
|
};
|
|
@@ -60,6 +65,7 @@ export function withGoalReviewGate(def, reviewTurn, getLang) {
|
|
|
60
65
|
return {
|
|
61
66
|
...def,
|
|
62
67
|
execute: (async (...args) => {
|
|
68
|
+
checkCancellation(args[2]);
|
|
63
69
|
if (reviewTurn()) {
|
|
64
70
|
const params = args[1];
|
|
65
71
|
const denied = goalReviewDenial(def.name, params);
|
|
@@ -71,6 +77,7 @@ export function withGoalReviewGate(def, reviewTurn, getLang) {
|
|
|
71
77
|
};
|
|
72
78
|
}
|
|
73
79
|
}
|
|
80
|
+
checkCancellation(args[2]);
|
|
74
81
|
return def.execute(...args);
|
|
75
82
|
}),
|
|
76
83
|
};
|
|
@@ -93,6 +100,7 @@ export function withApprovalGate(def, opts) {
|
|
|
93
100
|
const wrapped = {
|
|
94
101
|
...def,
|
|
95
102
|
execute: (async (toolCallId, params, signal, onUpdate, ctx) => {
|
|
103
|
+
checkCancellation(signal);
|
|
96
104
|
const lang = opts.getLang();
|
|
97
105
|
const conversationId = opts.conversationId?.();
|
|
98
106
|
const cwd = opts.cwd();
|
|
@@ -120,7 +128,8 @@ export function withApprovalGate(def, opts) {
|
|
|
120
128
|
}
|
|
121
129
|
let effectiveParams = params;
|
|
122
130
|
if (danger.dangerous && opts.askApproval) {
|
|
123
|
-
const res = await opts.askApproval(toolCallId, def.name, params, danger.reason, danger.reasonEn, conversationId, danger.category, danger.hits);
|
|
131
|
+
const res = await opts.askApproval(toolCallId, def.name, params, danger.reason, danger.reasonEn, conversationId, danger.category, danger.hits, signal);
|
|
132
|
+
checkCancellation(signal);
|
|
124
133
|
if (res.decision === "deny") {
|
|
125
134
|
const reasonText = res.reason ? ` 原因:${res.reason}` : "";
|
|
126
135
|
const reasonTextEn = res.reason ? ` Reason: ${res.reason}` : "";
|
|
@@ -139,6 +148,7 @@ export function withApprovalGate(def, opts) {
|
|
|
139
148
|
effectiveParams = res.editedParams ?? params;
|
|
140
149
|
}
|
|
141
150
|
}
|
|
151
|
+
checkCancellation(signal);
|
|
142
152
|
return def.execute(toolCallId, effectiveParams, signal, onUpdate, ctx);
|
|
143
153
|
}),
|
|
144
154
|
};
|
|
@@ -155,6 +165,7 @@ export function withDelegationGate(def, delegateMode, getLang) {
|
|
|
155
165
|
return {
|
|
156
166
|
...def,
|
|
157
167
|
execute: (async (...args) => {
|
|
168
|
+
checkCancellation(args[2]);
|
|
158
169
|
if (delegateMode()) {
|
|
159
170
|
const params = args[1];
|
|
160
171
|
const denied = delegationDenial(def.name, params);
|
|
@@ -166,6 +177,7 @@ export function withDelegationGate(def, delegateMode, getLang) {
|
|
|
166
177
|
};
|
|
167
178
|
}
|
|
168
179
|
}
|
|
180
|
+
checkCancellation(args[2]);
|
|
169
181
|
return def.execute(...args);
|
|
170
182
|
}),
|
|
171
183
|
};
|
|
@@ -194,6 +206,7 @@ export function withToolGuard(def, opts) {
|
|
|
194
206
|
return {
|
|
195
207
|
...def,
|
|
196
208
|
execute: (async (toolCallId, params, signal, onUpdate, ctx) => {
|
|
209
|
+
checkCancellation(signal);
|
|
197
210
|
const lang = opts.getLang();
|
|
198
211
|
const conversationId = opts.conversationId?.();
|
|
199
212
|
let pre;
|
|
@@ -204,6 +217,7 @@ export function withToolGuard(def, opts) {
|
|
|
204
217
|
catch {
|
|
205
218
|
pre = { verdict: { decision: "allow" } };
|
|
206
219
|
}
|
|
220
|
+
checkCancellation(signal);
|
|
207
221
|
}
|
|
208
222
|
// 检查是否需要人工协同审批(Human-in-the-Loop)
|
|
209
223
|
let needApproval = false;
|
|
@@ -262,7 +276,8 @@ export function withToolGuard(def, opts) {
|
|
|
262
276
|
let effectiveParams = params;
|
|
263
277
|
let userEdited = false;
|
|
264
278
|
if (needApproval && opts.askApproval) {
|
|
265
|
-
const res = await opts.askApproval(toolCallId, toolName, params, approvalReason, approvalReasonEn, conversationId, approvalCategory, approvalHits);
|
|
279
|
+
const res = await opts.askApproval(toolCallId, toolName, params, approvalReason, approvalReasonEn, conversationId, approvalCategory, approvalHits, signal);
|
|
280
|
+
checkCancellation(signal);
|
|
266
281
|
if (res.decision === "deny") {
|
|
267
282
|
const reasonText = res.reason ? ` 原因:${res.reason}` : "";
|
|
268
283
|
const reasonTextEn = res.reason ? ` Reason: ${res.reason}` : "";
|
|
@@ -291,7 +306,9 @@ export function withToolGuard(def, opts) {
|
|
|
291
306
|
isError: true,
|
|
292
307
|
};
|
|
293
308
|
}
|
|
309
|
+
checkCancellation(signal);
|
|
294
310
|
const result = (await def.execute(toolCallId, effectiveParams, signal, onUpdate, ctx));
|
|
311
|
+
checkCancellation(signal);
|
|
295
312
|
if (userEdited && result && typeof result === "object") {
|
|
296
313
|
result.details = {
|
|
297
314
|
...result.details,
|
|
@@ -308,6 +325,7 @@ export function withToolGuard(def, opts) {
|
|
|
308
325
|
catch {
|
|
309
326
|
post = undefined;
|
|
310
327
|
}
|
|
328
|
+
checkCancellation(signal);
|
|
311
329
|
if (post?.content)
|
|
312
330
|
return { ...result, content: post.content };
|
|
313
331
|
}
|
|
@@ -340,6 +358,7 @@ export function wrapWriteToolWithPermission(cwd, getPermission, getRoots, getLan
|
|
|
340
358
|
return {
|
|
341
359
|
...effectiveBase,
|
|
342
360
|
execute: async (toolCallId, params, signal, onUpdate, ctx) => {
|
|
361
|
+
checkCancellation(signal);
|
|
343
362
|
const perm = getPermission();
|
|
344
363
|
if (perm === "read-only") {
|
|
345
364
|
return {
|
|
@@ -384,7 +403,8 @@ export function wrapWriteToolWithPermission(cwd, getPermission, getRoots, getLan
|
|
|
384
403
|
};
|
|
385
404
|
}
|
|
386
405
|
if (danger.dangerous) {
|
|
387
|
-
const res = await askApproval(toolCallId, "write", params, danger.reason, danger.reasonEn, getConversationId?.(), danger.category, danger.hits);
|
|
406
|
+
const res = await askApproval(toolCallId, "write", params, danger.reason, danger.reasonEn, getConversationId?.(), danger.category, danger.hits, signal);
|
|
407
|
+
checkCancellation(signal);
|
|
388
408
|
if (res.decision === "deny") {
|
|
389
409
|
return {
|
|
390
410
|
content: [
|
|
@@ -403,7 +423,9 @@ export function wrapWriteToolWithPermission(cwd, getPermission, getRoots, getLan
|
|
|
403
423
|
}
|
|
404
424
|
}
|
|
405
425
|
}
|
|
426
|
+
checkCancellation(signal);
|
|
406
427
|
const result = (await effectiveBase.execute(toolCallId, effectiveParams, signal, onUpdate, ctx));
|
|
428
|
+
checkCancellation(signal);
|
|
407
429
|
if (userEdited && result && typeof result === "object") {
|
|
408
430
|
result.details = {
|
|
409
431
|
...result.details,
|
|
@@ -441,6 +463,7 @@ export function wrapEditToolWithPermission(cwd, getPermission, getRoots, getLang
|
|
|
441
463
|
return {
|
|
442
464
|
...effectiveBase,
|
|
443
465
|
execute: async (toolCallId, params, signal, onUpdate, ctx) => {
|
|
466
|
+
checkCancellation(signal);
|
|
444
467
|
const perm = getPermission();
|
|
445
468
|
if (perm === "read-only") {
|
|
446
469
|
return {
|
|
@@ -485,7 +508,8 @@ export function wrapEditToolWithPermission(cwd, getPermission, getRoots, getLang
|
|
|
485
508
|
};
|
|
486
509
|
}
|
|
487
510
|
if (danger.dangerous) {
|
|
488
|
-
const res = await askApproval(toolCallId, "edit", params, danger.reason, danger.reasonEn, getConversationId?.(), danger.category, danger.hits);
|
|
511
|
+
const res = await askApproval(toolCallId, "edit", params, danger.reason, danger.reasonEn, getConversationId?.(), danger.category, danger.hits, signal);
|
|
512
|
+
checkCancellation(signal);
|
|
489
513
|
if (res.decision === "deny") {
|
|
490
514
|
return {
|
|
491
515
|
content: [
|
|
@@ -504,7 +528,9 @@ export function wrapEditToolWithPermission(cwd, getPermission, getRoots, getLang
|
|
|
504
528
|
}
|
|
505
529
|
}
|
|
506
530
|
}
|
|
531
|
+
checkCancellation(signal);
|
|
507
532
|
const result = (await effectiveBase.execute(toolCallId, effectiveParams, signal, onUpdate, ctx));
|
|
533
|
+
checkCancellation(signal);
|
|
508
534
|
if (userEdited && result && typeof result === "object") {
|
|
509
535
|
result.details = {
|
|
510
536
|
...result.details,
|
|
@@ -523,6 +549,7 @@ export function wrapEditSoftToolWithPermission(tool, cwd, getPermission, getRoot
|
|
|
523
549
|
return {
|
|
524
550
|
...tool,
|
|
525
551
|
execute: async (toolCallId, params, signal, onUpdate, ctx) => {
|
|
552
|
+
checkCancellation(signal);
|
|
526
553
|
const perm = getPermission();
|
|
527
554
|
if (perm === "read-only") {
|
|
528
555
|
return {
|
|
@@ -567,7 +594,8 @@ export function wrapEditSoftToolWithPermission(tool, cwd, getPermission, getRoot
|
|
|
567
594
|
};
|
|
568
595
|
}
|
|
569
596
|
if (danger.dangerous) {
|
|
570
|
-
const res = await askApproval(toolCallId, "edit_soft", params, danger.reason, danger.reasonEn, getConversationId?.(), danger.category, danger.hits);
|
|
597
|
+
const res = await askApproval(toolCallId, "edit_soft", params, danger.reason, danger.reasonEn, getConversationId?.(), danger.category, danger.hits, signal);
|
|
598
|
+
checkCancellation(signal);
|
|
571
599
|
if (res.decision === "deny") {
|
|
572
600
|
return {
|
|
573
601
|
content: [
|
|
@@ -586,7 +614,9 @@ export function wrapEditSoftToolWithPermission(tool, cwd, getPermission, getRoot
|
|
|
586
614
|
}
|
|
587
615
|
}
|
|
588
616
|
}
|
|
617
|
+
checkCancellation(signal);
|
|
589
618
|
const result = (await tool.execute(toolCallId, effectiveParams, signal, onUpdate, ctx));
|
|
619
|
+
checkCancellation(signal);
|
|
590
620
|
if (userEdited && result && typeof result === "object") {
|
|
591
621
|
result.details = {
|
|
592
622
|
...result.details,
|
|
@@ -611,6 +641,7 @@ export function wrapPatchToolWithPermission(tool, cwd, getPermission, getRoots,
|
|
|
611
641
|
return {
|
|
612
642
|
...tool,
|
|
613
643
|
execute: async (toolCallId, params, signal, onUpdate, ctx) => {
|
|
644
|
+
checkCancellation(signal);
|
|
614
645
|
const patchText = typeof params?.patch === "string" ? params.patch : "";
|
|
615
646
|
// 解析失败/空补丁不拦:引擎自己会报错,不会发生任何写。
|
|
616
647
|
let targets = [];
|
|
@@ -688,7 +719,8 @@ export function wrapPatchToolWithPermission(tool, cwd, getPermission, getRoots,
|
|
|
688
719
|
};
|
|
689
720
|
}
|
|
690
721
|
if (asked) {
|
|
691
|
-
const res = await askApproval(toolCallId, "patch", { ...params, path: askedPath }, asked.reason, asked.reasonEn, getConversationId?.(), asked.category, asked.hits);
|
|
722
|
+
const res = await askApproval(toolCallId, "patch", { ...params, path: askedPath }, asked.reason, asked.reasonEn, getConversationId?.(), asked.category, asked.hits, signal);
|
|
723
|
+
checkCancellation(signal);
|
|
692
724
|
if (res.decision === "deny") {
|
|
693
725
|
return {
|
|
694
726
|
content: [
|
|
@@ -710,7 +742,9 @@ export function wrapPatchToolWithPermission(tool, cwd, getPermission, getRoots,
|
|
|
710
742
|
}
|
|
711
743
|
}
|
|
712
744
|
}
|
|
745
|
+
checkCancellation(signal);
|
|
713
746
|
const result = (await tool.execute(toolCallId, effectiveParams, signal, onUpdate, ctx));
|
|
747
|
+
checkCancellation(signal);
|
|
714
748
|
if (userEdited && result && typeof result === "object") {
|
|
715
749
|
result.details = {
|
|
716
750
|
...result.details,
|
|
@@ -729,6 +763,7 @@ export function wrapBashToolWithPermission(tool, getPermission, getLang) {
|
|
|
729
763
|
return {
|
|
730
764
|
...tool,
|
|
731
765
|
execute: async (toolCallId, params, signal, onUpdate, ctx) => {
|
|
766
|
+
checkCancellation(signal);
|
|
732
767
|
const perm = getPermission();
|
|
733
768
|
if (perm === "read-only") {
|
|
734
769
|
return {
|
|
@@ -741,6 +776,7 @@ export function wrapBashToolWithPermission(tool, getPermission, getLang) {
|
|
|
741
776
|
isError: true,
|
|
742
777
|
};
|
|
743
778
|
}
|
|
779
|
+
checkCancellation(signal);
|
|
744
780
|
return tool.execute(toolCallId, params, signal, onUpdate, ctx);
|
|
745
781
|
},
|
|
746
782
|
};
|
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
/** 画布流水线编辑工具(定义见 canvas/canvas-agent-tool.ts,单 action:list/get/add_node/update_node/delete_node/add_edge/delete_edge/apply_dag)。 */
|
|
19
19
|
export const CANVAS_TOOL_NAME = "canvas";
|
|
20
20
|
/** 持久终端工具(定义见 terminals.ts,工具名在此唯一登记)。 */
|
|
21
|
-
export const
|
|
21
|
+
export const TERMINAL_TOOL_NAME = "terminal";
|
|
22
|
+
export const TERMINAL_TOOL_NAMES = [TERMINAL_TOOL_NAME];
|
|
23
|
+
/** Persisted names only; never register these as active tools. */
|
|
24
|
+
export const LEGACY_TERMINAL_TOOL_NAMES = [
|
|
22
25
|
"terminal_create",
|
|
23
26
|
"terminal_list",
|
|
24
27
|
"terminal_close",
|
|
@@ -28,8 +31,11 @@ export const TERMINAL_TOOL_NAMES = [
|
|
|
28
31
|
"terminal_wait",
|
|
29
32
|
];
|
|
30
33
|
/** 第一方子代理工具(定义见 subagents.ts,统一为单 action 工具)。 */
|
|
34
|
+
export const CONVERSATION_TOOL_NAME = "conversation";
|
|
35
|
+
/** Structured communication between execution conversations. */
|
|
36
|
+
export const COMMUNICATE_TOOL_NAME = "communicate";
|
|
31
37
|
export const SUBAGENT_TOOL_NAME = "subagent";
|
|
32
|
-
export const SUBAGENT_TOOL_NAMES = [SUBAGENT_TOOL_NAME];
|
|
38
|
+
export const SUBAGENT_TOOL_NAMES = [CONVERSATION_TOOL_NAME, SUBAGENT_TOOL_NAME];
|
|
33
39
|
/** 旧版 8 个独立子代理工具名(持久化配置迁移用)。 */
|
|
34
40
|
export const LEGACY_SUBAGENT_TOOL_NAMES = [
|
|
35
41
|
"subagent_spawn",
|
|
@@ -50,9 +56,8 @@ export const ASK_USER_QUESTION_TOOL_NAME = "ask_user_question";
|
|
|
50
56
|
/** 浏览器页面操作工具(定义见 agent-service.ts makeBrowserPageTool):模型经
|
|
51
57
|
* page-picker 浏览器扩展读/操作用户已授权的页面。 */
|
|
52
58
|
export const BROWSER_PAGE_TOOL_NAME = "browser_page";
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
export const CONVERSATION_READ_TOOL_NAME = "conversation_read";
|
|
59
|
+
/** Compatibility constant: running/history transcript inspection is part of conversation. */
|
|
60
|
+
export const CONVERSATION_READ_TOOL_NAME = CONVERSATION_TOOL_NAME;
|
|
56
61
|
/** 技能全文按名加载工具(定义见 skill-tool.ts):名录见 {{skills}} 段,
|
|
57
62
|
* 全文走本工具按需取,不再让模型拼路径调 read。 */
|
|
58
63
|
export const SKILL_TOOL_NAME = "skill";
|
|
@@ -84,6 +89,8 @@ export const MCP_MANAGE_TOOL_NAME = "mcp_manage";
|
|
|
84
89
|
export const SANDBOX_TOOL_NAME = "sandbox";
|
|
85
90
|
/** Git 工作树管理工具(定义见 worktree-tool.ts):创建/切换/清理工作树,保持多 PR 开发与界面工作区同步。 */
|
|
86
91
|
export const WORKTREE_TOOL_NAME = "worktree";
|
|
92
|
+
/** Bound local device collaboration service. */
|
|
93
|
+
export const DEVICE_COLLAB_TOOL_NAME = "device_collab";
|
|
87
94
|
/** QuickJS WASM 沙箱代码执行与批量调用工具(SDK 内置 codemode 扩展)。 */
|
|
88
95
|
export const CODEMODE_TOOL_NAME = "codemode";
|
|
89
96
|
/** 基于 BM25 算法的延迟工具检索与激活工具(SDK 内置 tool-search 扩展)。 */
|
|
@@ -112,6 +119,13 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
112
119
|
defaultOn: true,
|
|
113
120
|
dshVisible: false,
|
|
114
121
|
})),
|
|
122
|
+
{
|
|
123
|
+
name: COMMUNICATE_TOOL_NAME,
|
|
124
|
+
group: "subagent",
|
|
125
|
+
defaultOn: true,
|
|
126
|
+
dshVisible: false,
|
|
127
|
+
descKey: "Read your inbox, send messages, request decisions, reply, or escalate between execution conversations.",
|
|
128
|
+
},
|
|
115
129
|
{
|
|
116
130
|
name: EDIT_SOFT_TOOL_NAME,
|
|
117
131
|
group: "other",
|
|
@@ -146,15 +160,6 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
146
160
|
descKey: "browserPageEnabledDesc",
|
|
147
161
|
offHintKey: "browserPageOffHint",
|
|
148
162
|
},
|
|
149
|
-
// 只读别的对话(含子代理实时消息与历史转录),默认开;DSH 引擎没有该 customTool。
|
|
150
|
-
{
|
|
151
|
-
name: CONVERSATION_READ_TOOL_NAME,
|
|
152
|
-
group: "other",
|
|
153
|
-
defaultOn: true,
|
|
154
|
-
dshVisible: false,
|
|
155
|
-
descKey: "conversationReadEnabledDesc",
|
|
156
|
-
offHintKey: "conversationReadOffHint",
|
|
157
|
-
},
|
|
158
163
|
// 文件认领(事前打招呼,纯 advisory):默认开,不打开 AI 不知道能认领;
|
|
159
164
|
// 关掉只少一路提醒(事后触碰集照常工作);DSH 引擎没有该 customTool
|
|
160
165
|
// (走 goal-rpc,无 customTool 注册面),提醒是服务端算的、DSH 照样能看到。
|
|
@@ -287,6 +292,14 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
287
292
|
descKey: "toolsWorktreeDesc",
|
|
288
293
|
offHintKey: "toolsWorktreeOffHint",
|
|
289
294
|
},
|
|
295
|
+
{
|
|
296
|
+
name: DEVICE_COLLAB_TOOL_NAME,
|
|
297
|
+
group: "other",
|
|
298
|
+
defaultOn: false,
|
|
299
|
+
dshVisible: false,
|
|
300
|
+
descKey: "toolsDeviceCollabDesc",
|
|
301
|
+
offHintKey: "toolsDeviceCollabOffHint",
|
|
302
|
+
},
|
|
290
303
|
{
|
|
291
304
|
name: CANVAS_TOOL_NAME,
|
|
292
305
|
group: "other",
|
|
@@ -375,7 +388,7 @@ export function isConfigurableAgentTool(name) {
|
|
|
375
388
|
}
|
|
376
389
|
/** 根据禁用名单计算出当前系统中真正启用的可用工具列表(只取当前系统可用的配置)。 */
|
|
377
390
|
export function resolveEnabledAgentTools(disabled) {
|
|
378
|
-
const disabledSet = new Set(disabled);
|
|
391
|
+
const disabledSet = new Set(normalizeDisabledAgentTools(disabled));
|
|
379
392
|
return ALL_KNOWN_AGENT_TOOL_NAMES.filter((name) => !disabledSet.has(name));
|
|
380
393
|
}
|
|
381
394
|
/**
|
|
@@ -384,6 +397,9 @@ export function resolveEnabledAgentTools(disabled) {
|
|
|
384
397
|
*/
|
|
385
398
|
export function resolveDisabledAgentToolsFromEnabled(enabled) {
|
|
386
399
|
const enabledSet = new Set(enabled);
|
|
400
|
+
// An old per-action allowlist grants the merged tool only when all actions were enabled.
|
|
401
|
+
if (LEGACY_TERMINAL_TOOL_NAMES.every((name) => enabledSet.has(name)))
|
|
402
|
+
enabledSet.add(TERMINAL_TOOL_NAME);
|
|
387
403
|
return ALL_KNOWN_AGENT_TOOL_NAMES.filter((name) => !enabledSet.has(name));
|
|
388
404
|
}
|
|
389
405
|
/** 归一化禁用名单:非数组回落默认(= 默认关的那些);数组则只保留已知工具名
|
|
@@ -394,9 +410,20 @@ export function normalizeDisabledAgentTools(v) {
|
|
|
394
410
|
const out = [];
|
|
395
411
|
for (const x of v) {
|
|
396
412
|
let name = x;
|
|
413
|
+
if (typeof name === "string" && LEGACY_TERMINAL_TOOL_NAMES.includes(name)) {
|
|
414
|
+
name = TERMINAL_TOOL_NAME;
|
|
415
|
+
}
|
|
397
416
|
// 旧版子代理工具迁移:任意旧 subagent_* 关闭均迁移为关闭 subagent 工具。
|
|
398
417
|
if (typeof name === "string" && LEGACY_SUBAGENT_TOOL_NAMES.includes(name)) {
|
|
399
|
-
name =
|
|
418
|
+
name = CONVERSATION_TOOL_NAME;
|
|
419
|
+
}
|
|
420
|
+
if (name === "conversation_read")
|
|
421
|
+
name = CONVERSATION_TOOL_NAME;
|
|
422
|
+
if (typeof name === "string" && SUBAGENT_TOOL_NAMES.includes(name)) {
|
|
423
|
+
for (const alias of SUBAGENT_TOOL_NAMES)
|
|
424
|
+
if (!out.includes(alias))
|
|
425
|
+
out.push(alias);
|
|
426
|
+
continue;
|
|
400
427
|
}
|
|
401
428
|
// 旧版定时任务三件套迁移:任意旧 schedule_* 关闭均迁移为关闭 schedule 工具(#193)。
|
|
402
429
|
if (typeof name === "string" && LEGACY_SCHEDULE_TOOL_NAMES.includes(name)) {
|
|
@@ -464,8 +491,8 @@ export function setAgentToolsEnabled(session, names, on) {
|
|
|
464
491
|
* 1. 宿主受管工具(Host-Managed Tools,即核心内置工具 + AGENT_TOOL_CATALOG 工具):
|
|
465
492
|
* 由 Web UI 的 disabledAgentTools 开关、模式硬闸门与预设白名单完全掌控状态。
|
|
466
493
|
* 2. 扩展自主工具(Extension-Owned Tools,如 pi-web-search 的 url_context 等):
|
|
467
|
-
* Web UI
|
|
468
|
-
*
|
|
494
|
+
* Web UI 继承其既有活跃状态(getActiveToolNames),同时应用本次禁用集(延迟加载、
|
|
495
|
+
* 子代理白名单等);绝不擅自重新启用已被扩展主动关闭的外部工具。
|
|
469
496
|
* 3. 预设安全过滤:预设(Preset)只对最终候选集做安全收缩(例如 ask 纯对话清空所有工具,
|
|
470
497
|
* minimal 仅保留 bash+read 等)。
|
|
471
498
|
*
|
|
@@ -484,7 +511,7 @@ export function applyAgentToolsGating(session, disabled, preset, options) {
|
|
|
484
511
|
if (isHostManagedTool(name)) {
|
|
485
512
|
names.add(name);
|
|
486
513
|
}
|
|
487
|
-
else if (initialActiveNames.has(name)) {
|
|
514
|
+
else if (initialActiveNames.has(name) && !off.has(name)) {
|
|
488
515
|
names.add(name);
|
|
489
516
|
}
|
|
490
517
|
}
|
|
@@ -492,7 +519,7 @@ export function applyAgentToolsGating(session, disabled, preset, options) {
|
|
|
492
519
|
if (off.has(t.name)) {
|
|
493
520
|
// issue #481: 若第三方扩展注册了同名工具(如 nicobailon/pi-subagents 的 subagent),
|
|
494
521
|
// 关闭内置工具时允许扩展工具透传,不从活跃名单删除;其余由扩展自身注册的工具(如 codemode)正常随禁用名单剔除
|
|
495
|
-
const isShadowedCustomTool = t.name
|
|
522
|
+
const isShadowedCustomTool = SUBAGENT_TOOL_NAMES.includes(t.name);
|
|
496
523
|
const hasExtensionTool = isShadowedCustomTool &&
|
|
497
524
|
Boolean(session?.extensionRunner
|
|
498
525
|
?.getAllRegisteredTools?.()
|
|
@@ -76,18 +76,20 @@ export function installToolOverrides(session, specs, options) {
|
|
|
76
76
|
export function syncSubagentOverride(session, subagentDisabled, builtinSubagentTool) {
|
|
77
77
|
if (!Array.isArray(session._customTools) || typeof session._refreshToolRegistry !== "function")
|
|
78
78
|
return;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (idx !== -1) {
|
|
85
|
-
session._customTools = session._customTools.filter((t) => t.name !==
|
|
86
|
-
|
|
79
|
+
let changed = false;
|
|
80
|
+
for (const name of ["conversation", "subagent"]) {
|
|
81
|
+
if (!extensionToolDefinition(session, name))
|
|
82
|
+
continue;
|
|
83
|
+
const idx = session._customTools.findIndex((t) => t.name === name);
|
|
84
|
+
if (subagentDisabled && idx !== -1) {
|
|
85
|
+
session._customTools = session._customTools.filter((t) => t.name !== name);
|
|
86
|
+
changed = true;
|
|
87
|
+
}
|
|
88
|
+
else if (!subagentDisabled && idx === -1 && builtinSubagentTool) {
|
|
89
|
+
session._customTools = [builtinSubagentTool(name), ...session._customTools];
|
|
90
|
+
changed = true;
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
|
-
|
|
90
|
-
session._customTools = [builtinSubagentTool(), ...session._customTools];
|
|
93
|
+
if (changed)
|
|
91
94
|
session._refreshToolRegistry();
|
|
92
|
-
}
|
|
93
95
|
}
|
|
@@ -63,7 +63,35 @@ export function normalizeToolPromptOverrides(v, knownTools) {
|
|
|
63
63
|
return knownTools.has(key);
|
|
64
64
|
return knownTools.includes(key);
|
|
65
65
|
};
|
|
66
|
-
|
|
66
|
+
const source = { ...v };
|
|
67
|
+
const conversationOverride = normalizeToolPromptOverride(source.conversation) ?? normalizeToolPromptOverride(source.subagent);
|
|
68
|
+
if (conversationOverride) {
|
|
69
|
+
source.conversation = conversationOverride;
|
|
70
|
+
source.subagent = conversationOverride;
|
|
71
|
+
}
|
|
72
|
+
// Explicit merged settings win; otherwise select the first valid legacy override
|
|
73
|
+
// in this stable order, independent of JSON insertion order.
|
|
74
|
+
const legacyNames = [
|
|
75
|
+
"terminal_create",
|
|
76
|
+
"terminal_list",
|
|
77
|
+
"terminal_close",
|
|
78
|
+
"terminal_input",
|
|
79
|
+
"terminal_key",
|
|
80
|
+
"terminal_read",
|
|
81
|
+
"terminal_wait",
|
|
82
|
+
];
|
|
83
|
+
if (!normalizeToolPromptOverride(source.terminal)) {
|
|
84
|
+
for (const name of legacyNames) {
|
|
85
|
+
const legacy = normalizeToolPromptOverride(source[name]);
|
|
86
|
+
if (legacy) {
|
|
87
|
+
source.terminal = legacy;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const name of legacyNames)
|
|
93
|
+
delete source[name];
|
|
94
|
+
for (const [name, raw] of Object.entries(source)) {
|
|
67
95
|
const key = name.trim();
|
|
68
96
|
if (!key || !isKnown(key))
|
|
69
97
|
continue;
|
|
@@ -79,7 +107,9 @@ export function normalizeToolPromptOverrides(v, knownTools) {
|
|
|
79
107
|
}
|
|
80
108
|
/** 取某工具的有效覆盖(没有 → null)。 */
|
|
81
109
|
export function toolPromptOverrideOf(map, name) {
|
|
82
|
-
const ov =
|
|
110
|
+
const ov = ["terminal", "conversation", "subagent"].includes(name)
|
|
111
|
+
? normalizeToolPromptOverrides(map)[name]
|
|
112
|
+
: map?.[name];
|
|
83
113
|
return ov && Object.keys(ov).length > 0 ? ov : null;
|
|
84
114
|
}
|
|
85
115
|
/** 叠加覆盖后的有效文案(覆盖字段优先,缺省回落默认)。 */
|
|
@@ -19,7 +19,7 @@ export const BASH_DESCRIPTION = "Run a shell command and return its full output
|
|
|
19
19
|
export const BASH_PROMPT_SNIPPET = "run shell commands";
|
|
20
20
|
/** 行为要点:只在「何时用/顺序/禁止」上说 description 没说的事。 */
|
|
21
21
|
export const BASH_PROMPT_GUIDELINES = [
|
|
22
|
-
"For interactive commands (REPLs, y/n prompts) set persist=true and drive them with
|
|
22
|
+
"For interactive commands (REPLs, y/n prompts) set persist=true and drive them with terminal(action='input'/'key')",
|
|
23
23
|
"Use the dedicated worktree tool instead of running 'git worktree' in bash to prevent unsynchronized workspace state",
|
|
24
24
|
];
|
|
25
25
|
/** 参数 schema(含参数说明):三条执行路径共用,避免「分流后 schema 变陌生」。 */
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Keep one clock across tools, steering and automatic retries. */
|
|
2
|
+
export function startTurnTiming(conv, now = Date.now()) {
|
|
3
|
+
if (!conv.turnTiming || conv.turnTiming.finishedAt !== undefined) {
|
|
4
|
+
conv.turnTiming = { startedAt: now };
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export function finishTurnTiming(conv, now = Date.now()) {
|
|
8
|
+
if (conv.turnTiming && conv.turnTiming.finishedAt === undefined) {
|
|
9
|
+
conv.turnTiming = { ...conv.turnTiming, finishedAt: Math.max(now, conv.turnTiming.startedAt) };
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* session-store.ts — 通用 Agent 会话的轻量级磁盘持久化。
|
|
3
3
|
*
|
|
4
|
-
* 会话存储在 <dataDir>/universal-sessions/<cwdHash>/<convId>.json 下。
|
|
4
|
+
* 会话存储在 <dataDir>/universal-sessions/<engine>/<cwdHash>/<convId>.json 下。
|
|
5
5
|
* 格式为纯 JSON,严格线性结构,便于直读、回放与恢复。
|
|
6
6
|
*/
|
|
7
7
|
import { existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync } from "node:fs";
|
|
@@ -10,9 +10,13 @@ import { createHash } from "node:crypto";
|
|
|
10
10
|
import { writeJsonAtomicSync } from "../atomic-file.js";
|
|
11
11
|
import { normalizePathKey } from "../client-state.js";
|
|
12
12
|
export class UniversalSessionStore {
|
|
13
|
+
engine;
|
|
13
14
|
baseDir;
|
|
14
|
-
constructor(dataDir) {
|
|
15
|
-
this.
|
|
15
|
+
constructor(dataDir, engine = "claude") {
|
|
16
|
+
this.engine = engine;
|
|
17
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(engine))
|
|
18
|
+
throw new Error("Invalid engine namespace");
|
|
19
|
+
this.baseDir = join(dataDir, "universal-sessions", engine);
|
|
16
20
|
try {
|
|
17
21
|
mkdirSync(this.baseDir, { recursive: true });
|
|
18
22
|
}
|
|
@@ -34,6 +38,7 @@ export class UniversalSessionStore {
|
|
|
34
38
|
return join(this.cwdDir(cwd), `${safeId}.json`);
|
|
35
39
|
}
|
|
36
40
|
listConversations(cwd) {
|
|
41
|
+
this.importLegacy(cwd);
|
|
37
42
|
const dir = this.cwdDir(cwd);
|
|
38
43
|
if (!existsSync(dir))
|
|
39
44
|
return [];
|
|
@@ -44,7 +49,7 @@ export class UniversalSessionStore {
|
|
|
44
49
|
try {
|
|
45
50
|
const full = join(dir, file);
|
|
46
51
|
const data = JSON.parse(readFileSync(full, "utf-8"));
|
|
47
|
-
if (data && data.id && Array.isArray(data.messages)) {
|
|
52
|
+
if (data && data.engine === this.engine && data.id && Array.isArray(data.messages)) {
|
|
48
53
|
list.push(data);
|
|
49
54
|
}
|
|
50
55
|
}
|
|
@@ -56,11 +61,13 @@ export class UniversalSessionStore {
|
|
|
56
61
|
return list.sort((a, b) => b.updatedAt - a.updatedAt);
|
|
57
62
|
}
|
|
58
63
|
loadConversation(cwd, convId) {
|
|
64
|
+
this.importLegacy(cwd);
|
|
59
65
|
const p = this.convPath(cwd, convId);
|
|
60
66
|
if (!existsSync(p))
|
|
61
67
|
return null;
|
|
62
68
|
try {
|
|
63
|
-
|
|
69
|
+
const data = JSON.parse(readFileSync(p, "utf-8"));
|
|
70
|
+
return data.engine === this.engine && data.id === convId && Array.isArray(data.messages) ? data : null;
|
|
64
71
|
}
|
|
65
72
|
catch {
|
|
66
73
|
return null;
|
|
@@ -68,9 +75,44 @@ export class UniversalSessionStore {
|
|
|
68
75
|
}
|
|
69
76
|
saveConversation(cwd, conv) {
|
|
70
77
|
const p = this.convPath(cwd, conv.id);
|
|
71
|
-
writeJsonAtomicSync(p, conv);
|
|
78
|
+
writeJsonAtomicSync(p, { ...conv, engine: this.engine });
|
|
79
|
+
}
|
|
80
|
+
/** Import legacy messages; ambiguous driver identities never cross engine boundaries. */
|
|
81
|
+
importLegacy(cwd) {
|
|
82
|
+
const hash = createHash("sha256").update(normalizePathKey(cwd)).digest("hex").slice(0, 16);
|
|
83
|
+
const legacyDir = join(this.baseDir, "..", hash);
|
|
84
|
+
if (!existsSync(legacyDir))
|
|
85
|
+
return;
|
|
86
|
+
for (const file of readdirSync(legacyDir)) {
|
|
87
|
+
if (!file.endsWith(".json"))
|
|
88
|
+
continue;
|
|
89
|
+
const path = join(legacyDir, file);
|
|
90
|
+
try {
|
|
91
|
+
const conv = JSON.parse(readFileSync(path, "utf-8"));
|
|
92
|
+
if ((conv.engine && conv.engine !== this.engine) || !conv.id || !Array.isArray(conv.messages))
|
|
93
|
+
continue;
|
|
94
|
+
if (!conv.engine) {
|
|
95
|
+
// Ambiguous legacy transcripts are message-only imports. Never resume a foreign driver.
|
|
96
|
+
const marker = `${this.convPath(cwd, conv.id)}.legacy-imported`;
|
|
97
|
+
if (existsSync(marker))
|
|
98
|
+
continue;
|
|
99
|
+
const imported = { ...conv, driverSessionId: undefined };
|
|
100
|
+
if (!existsSync(this.convPath(cwd, conv.id)))
|
|
101
|
+
this.saveConversation(cwd, imported);
|
|
102
|
+
writeJsonAtomicSync(marker, { imported: true });
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (!existsSync(this.convPath(cwd, conv.id)))
|
|
106
|
+
this.saveConversation(cwd, conv);
|
|
107
|
+
unlinkSync(path);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
/* Leave unreadable or failed imports untouched. */
|
|
111
|
+
}
|
|
112
|
+
}
|
|
72
113
|
}
|
|
73
114
|
deleteConversation(cwd, convId) {
|
|
115
|
+
this.importLegacy(cwd);
|
|
74
116
|
const p = this.convPath(cwd, convId);
|
|
75
117
|
if (existsSync(p)) {
|
|
76
118
|
try {
|
|
@@ -31,7 +31,7 @@ export class UniversalAgentService {
|
|
|
31
31
|
this.dataDir = opts.dataDir;
|
|
32
32
|
this.agentDir = opts.agentDir;
|
|
33
33
|
this.engine = opts.engine ?? "claude";
|
|
34
|
-
this.store = new UniversalSessionStore(opts.dataDir);
|
|
34
|
+
this.store = new UniversalSessionStore(opts.dataDir, this.engine);
|
|
35
35
|
this.stateStore = opts.stateStore;
|
|
36
36
|
// 默认使用 MockDriver;接入 Claude Code 时可替换
|
|
37
37
|
this.driverFactory = opts.driverFactory ?? ((cwd) => new MockAgentDriver(cwd));
|