pi-web-ui 0.118.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 +143 -1
- 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 +930 -166
- package/dist/server/approval-default-rules.js +4 -4
- package/dist/server/ask-user-question-tool.js +3 -40
- package/dist/server/atomic-file.js +130 -5
- package/dist/server/background-executors.js +235 -0
- package/dist/server/bash-timeout.js +47 -0
- package/dist/server/bash-tool.js +72 -5
- package/dist/server/bg-servers.js +19 -13
- package/dist/server/browser-page-tool.js +38 -29
- package/dist/server/browser-script-tool.js +119 -0
- package/dist/server/canvas/canvas-agent-tool.js +46 -35
- package/dist/server/canvas/canvas-dispatch.js +12 -1
- package/dist/server/claim-files-tool.js +6 -7
- package/dist/server/client-state.js +457 -41
- package/dist/server/communicate-tool.js +59 -77
- package/dist/server/compact-context-tool.js +4 -13
- package/dist/server/conversation-communication.js +23 -1
- package/dist/server/conversation-read-tool.js +14 -23
- package/dist/server/conversation-rows.js +17 -0
- package/dist/server/conversation-tool-names.js +2 -2
- package/dist/server/conversation-tool.js +23 -15
- package/dist/server/conversation-touches.js +1 -1
- package/dist/server/delegate-mode.js +0 -1
- package/dist/server/delegate-task.js +18 -39
- package/dist/server/device-center/approval-summary.js +0 -1
- package/dist/server/device-center/bot-execution.js +0 -1
- package/dist/server/device-center/group-router-runtime.js +2 -0
- package/dist/server/device-center/hub-upgrade.js +5 -10
- package/dist/server/device-center/task-progress.js +2 -2
- package/dist/server/dispatch-domain-handlers.js +97 -24
- package/dist/server/dispatch-plugin-handlers.js +10 -0
- package/dist/server/dsh/dsh-agent-service.js +21 -19
- package/dist/server/durable/durable-agent-service.js +1 -1
- package/dist/server/edit-tool.js +293 -0
- package/dist/server/engine-catalog.js +8 -2
- package/dist/server/engine-cli.js +29 -7
- package/dist/server/engine-probe.js +11 -6
- package/dist/server/eval-tool.js +5 -19
- package/dist/server/files-service.js +41 -19
- package/dist/server/fs-copy.js +93 -0
- package/dist/server/goal-review-gate.js +2 -3
- package/dist/server/index.js +92 -3
- package/dist/server/job-runner.js +345 -0
- package/dist/server/lsp-tool.js +10 -28
- package/dist/server/marker-service.js +42 -30
- package/dist/server/mcp-agent-tool.js +22 -47
- package/dist/server/model-session.js +16 -0
- package/dist/server/native-cli-session-hooks.js +3 -2
- package/dist/server/native-cli-session.js +27 -2
- package/dist/server/patch-tool.js +2 -8
- package/dist/server/phone-tool.js +167 -0
- package/dist/server/plan-mode.js +7 -4
- package/dist/server/plan-update-tool.js +5 -8
- package/dist/server/plugin-api-catalog.js +13 -1
- package/dist/server/plugin-bundled.js +35 -28
- package/dist/server/plugin-catalog.js +6 -0
- package/dist/server/plugin-delivery.js +358 -0
- package/dist/server/plugin-inbox.js +152 -0
- package/dist/server/plugin-installer.js +15 -0
- package/dist/server/plugin-ledger.js +183 -0
- package/dist/server/plugin-manifest-validate.js +19 -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 +205 -48
- package/dist/server/present-files-tool.js +7 -13
- package/dist/server/preset-fields.js +23 -12
- package/dist/server/preset-share.js +1 -1
- 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/question-params.js +98 -0
- package/dist/server/quick-ask-settings.js +0 -1
- package/dist/server/quick-ask.js +3 -0
- package/dist/server/read-tool.js +10 -17
- package/dist/server/remote-ssh-service.js +40 -1
- package/dist/server/sandbox-runtime-gate.js +1 -1
- package/dist/server/sandbox-service.js +0 -1
- package/dist/server/sandbox-tool.js +25 -34
- package/dist/server/schedule-agent-tool.js +9 -19
- 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 +49 -19
- package/dist/server/skill-tool.js +4 -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 -3
- package/dist/server/subagent-settle.js +71 -0
- package/dist/server/subagents.js +566 -211
- package/dist/server/tabs.js +8 -1
- package/dist/server/terminals.js +34 -28
- package/dist/server/tool-approval.js +15 -1
- package/dist/server/tool-guards.js +0 -91
- package/dist/server/tool-manager.js +127 -47
- package/dist/server/tool-overrides.js +8 -1
- package/dist/server/tool-prompt-overrides.js +3 -6
- package/dist/server/tool-prompts.js +60 -17
- package/dist/server/universal/driver-base.js +2 -0
- package/dist/server/universal/drivers/claude-code.js +210 -211
- package/dist/server/universal/drivers/codex.js +29 -24
- package/dist/server/universal/engine-mcp.js +107 -0
- package/dist/server/universal/universal-attachments.js +77 -1
- package/dist/server/universal/universal-service.js +1 -1
- package/dist/server/universal/universal-session.js +106 -69
- 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/dist/server/worktree-tool.js +13 -20
- package/docs/README.md +40 -36
- package/docs/architecture-plugins.md +64 -35
- package/docs/device-center.md +1 -1
- package/package.json +16 -4
- package/plugin-sdk/index.d.ts +102 -0
- package/plugins/catalog.json +23 -51
- package/themes/bases/flow-base.css +8 -17
- package/themes/dark-teal.css +0 -3
- 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-CAWcs9tm.js → CanvasStudio-BB_Iq7pl.js} +3 -3
- package/web/dist/assets/CanvasStudio-DU6O3N4u.js +1579 -0
- package/web/dist/assets/DeviceCenter-By1zVTSY.js +3 -0
- package/web/dist/assets/DeviceCenter-Cnm0Tjrx.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-qJzbI0Cf.js +1 -0
- package/web/dist/assets/{DeviceGroups-C_fZMNeK.js → DeviceGroups-DPrQxW6B.js} +1 -1
- package/web/dist/assets/DeviceGroups-DoucyUjI.js +1 -0
- package/web/dist/assets/{Dropdown-CTgVLUbp.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-1-lsPO1f.js +61 -0
- package/web/dist/assets/GroupConversation-HeiyW_O_.js +61 -0
- package/web/dist/assets/{GroupWorkItems-BIvZtr10.js → GroupWorkItems-BYJv2XFj.js} +1 -1
- package/web/dist/assets/{HintTip-Da6qc566.js → HintTip-DFhoclDw.js} +1 -1
- package/web/dist/assets/ModelConfigModal-D2Ro-jUZ.js +2 -0
- package/web/dist/assets/ModelConfigModal-DPc9R1pq.js +2 -0
- package/web/dist/assets/{NativeCliPanel-CU1rZmyu.js → NativeCliPanel-B108d697.js} +3 -3
- package/web/dist/assets/NativeCliPanel-DupvGwQM.js +5 -0
- package/web/dist/assets/{PiSetupModal-DZKY5Wiw.js → PiSetupModal-D0HitBfd.js} +1 -1
- package/web/dist/assets/ProviderOAuthControls-BLKUEDde.js +1 -0
- package/web/dist/assets/SCMPanel-DDbWrUHR.js +2 -0
- package/web/dist/assets/SCMPanel-DluNcd2-.js +2 -0
- 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-Bt5WKAxP.js → TermXterm-SYc-MUk2.js} +2 -2
- package/web/dist/assets/TerminalPanel-CgA_lhVT.js +1 -0
- package/web/dist/assets/TerminalPanel-vdSIOPjD.js +1 -0
- package/web/dist/assets/TuiOverlayModal-Cy1jYYIw.js +1 -0
- package/web/dist/assets/TuiOverlayModal-kXY_4hV8.js +1 -0
- package/web/dist/assets/app-globals-CBEscsYP.js +129 -0
- package/web/dist/assets/{canvas-client-WkhM55mR.js → canvas-client-Clsypfs6.js} +1 -1
- package/web/dist/assets/{desktop-B8NZ3KW-.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-VWBcq-LQ.js +1 -0
- 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/dist/server/edit-soft-tool.js +0 -297
- package/web/dist/assets/BgTasksModal-D-x7kA63.js +0 -1
- package/web/dist/assets/DeviceCenter-Dc0whRcu.js +0 -3
- package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +0 -1
- package/web/dist/assets/FilePreview-C6W0PvaK.js +0 -2
- package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +0 -1
- package/web/dist/assets/GroupConversation-C81YjF2C.js +0 -61
- package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +0 -2
- package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +0 -1
- package/web/dist/assets/SCMPanel-CuEgzAlO.js +0 -2
- package/web/dist/assets/SettingsModal-Cdu5h29p.js +0 -33
- package/web/dist/assets/TerminalPanel-BCIBV8se.js +0 -1
- package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +0 -1
- package/web/dist/assets/app-globals-CZjFtI4F.js +0 -129
- package/web/dist/assets/index-CQc3VrWa.css +0 -1
- package/web/dist/assets/index-D_AGu4Zv.js +0 -404
- package/web/dist/assets/plugin-host-uqZGpvCs.js +0 -1
- package/web/dist/assets/remote-ssh-client-Cdf-cTUe.js +0 -1
- package/web/dist/assets/theme-DGL7hLUs.js +0 -1
package/dist/server/tabs.js
CHANGED
|
@@ -13,7 +13,14 @@ const OWNED = {
|
|
|
13
13
|
"run_command",
|
|
14
14
|
],
|
|
15
15
|
git: ["scm_status", "scm_history", "scm_filediff", "scm_commit"],
|
|
16
|
-
tasks: [
|
|
16
|
+
tasks: [
|
|
17
|
+
"list_bg_servers",
|
|
18
|
+
"kill_background_server",
|
|
19
|
+
"kill_background_servers",
|
|
20
|
+
"project_scripts",
|
|
21
|
+
"start_bg_script",
|
|
22
|
+
"restart_bg_job",
|
|
23
|
+
],
|
|
17
24
|
search: ["search_files", "search_sessions"],
|
|
18
25
|
};
|
|
19
26
|
export function parseTabs(env = process.env) {
|
package/dist/server/terminals.js
CHANGED
|
@@ -12,6 +12,7 @@ import { MAX_NATIVE_CLI_PASTE, resolveNativeCliLaunch, sanitizeNativeCliPaste, v
|
|
|
12
12
|
import { attachPersistentRemoteNativeCli, openPersistentRemoteNativeCli, probePersistentRemoteNativeCli, } from "./remote-cli-persistence.js";
|
|
13
13
|
import { resolveRemoteNativeCliLaunch } from "./remote-native-cli.js";
|
|
14
14
|
import { BASH_DESCRIPTION, BASH_PARAMETERS, BASH_PROMPT_GUIDELINES, BASH_PROMPT_SNIPPET } from "./tool-prompts.js";
|
|
15
|
+
import { withDefaultBashTimeout } from "./bash-timeout.js";
|
|
15
16
|
import { pick } from "./i18n.js";
|
|
16
17
|
import { armDelay } from "./plugin-schedule.js";
|
|
17
18
|
import { getGlobalRemoteSshService, isRemoteWorkspaceUri, parseRemoteWorkspaceUri, resolveWorkspaceSessionDir, } from "./remote-ssh-service.js";
|
|
@@ -111,7 +112,7 @@ const isWindows = process.platform === "win32";
|
|
|
111
112
|
const MAX_TERMINALS = 16;
|
|
112
113
|
const OUTPUT_FLUSH_MS = 16;
|
|
113
114
|
const MAX_TERMINAL_HISTORY = 32;
|
|
114
|
-
const MAX_OUTPUT =
|
|
115
|
+
const MAX_OUTPUT = 2_000_000;
|
|
115
116
|
const MAX_INPUT = 64 * 1024;
|
|
116
117
|
const MAX_ID = 80;
|
|
117
118
|
export function terminalIdleNotifyMs() {
|
|
@@ -775,7 +776,11 @@ export class TerminalManager {
|
|
|
775
776
|
const entry = this.find(id);
|
|
776
777
|
if (!entry)
|
|
777
778
|
return false;
|
|
778
|
-
|
|
779
|
+
const isDefaultFallback = cols === 80 && rows === 24;
|
|
780
|
+
const hasStableExistingSize = entry.cols > 80 || entry.rows > 24;
|
|
781
|
+
if (!isDefaultFallback || !hasStableExistingSize) {
|
|
782
|
+
this.resize(id, cols, rows);
|
|
783
|
+
}
|
|
779
784
|
this.flushPending(entry);
|
|
780
785
|
this.emit({ type: "terminal_output", terminalId: id, data: entry.output, reset: true });
|
|
781
786
|
return true;
|
|
@@ -2118,7 +2123,9 @@ export function makeTerminalBashTool(terminals, opts) {
|
|
|
2118
2123
|
promptSnippet: BASH_PROMPT_SNIPPET,
|
|
2119
2124
|
promptGuidelines: BASH_PROMPT_GUIDELINES,
|
|
2120
2125
|
parameters: BASH_PARAMETERS,
|
|
2121
|
-
execute: async (_id,
|
|
2126
|
+
execute: async (_id, rawParams, signal) => {
|
|
2127
|
+
// 与 makeKillableBashTool 同一处归一(server/bash-timeout.ts):没传 timeout 就是 120s,不是无限制。
|
|
2128
|
+
const p = withDefaultBashTimeout(rawParams);
|
|
2122
2129
|
const lang = opts.lang?.() ?? "en";
|
|
2123
2130
|
if (signal?.aborted)
|
|
2124
2131
|
throw new Error("Command aborted");
|
|
@@ -2377,7 +2384,8 @@ function backgroundResult(terminals, opts, command, partialText, durationSeconds
|
|
|
2377
2384
|
};
|
|
2378
2385
|
}
|
|
2379
2386
|
export { TERMINAL_TOOL_NAMES } from "./tool-manager.js";
|
|
2380
|
-
|
|
2387
|
+
/** `terminal` 的 action 单源:schema 枚举与 execute 的合法性校验共用这一份。 */
|
|
2388
|
+
export const TERMINAL_ACTIONS = ["create", "list", "close", "input", "key", "read", "wait"];
|
|
2381
2389
|
export function makePersistentTerminalTools(terminals, cwd, lang, options) {
|
|
2382
2390
|
const getLang = lang ?? (() => "en");
|
|
2383
2391
|
const result = (text, details = {}) => ({ content: [{ type: "text", text }], details });
|
|
@@ -2412,43 +2420,41 @@ export function makePersistentTerminalTools(terminals, cwd, lang, options) {
|
|
|
2412
2420
|
defineTool({
|
|
2413
2421
|
name: "terminal",
|
|
2414
2422
|
label: "Terminal",
|
|
2415
|
-
description: "
|
|
2423
|
+
description: "Drive persistent interactive PTYs and read their output incrementally. Only list is read-only on the tool itself; input/key drive the program.",
|
|
2416
2424
|
promptSnippet: "drive interactive programs or inspect persistent terminal output",
|
|
2417
2425
|
promptGuidelines: [
|
|
2418
2426
|
"Prefer bash for ordinary commands. Use read(waitMs) for output from input/key; use wait only for tracked bash commands. Retain the returned cursor for incremental reads.",
|
|
2419
2427
|
],
|
|
2420
2428
|
parameters: Type.Object({
|
|
2421
|
-
action: Type.
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
data: Type.Optional(Type.String({ description: "Required for input; include newline to submit" })),
|
|
2435
|
-
key: Type.Optional(Type.String({ description: "Required for key, e.g. Enter or c" })),
|
|
2429
|
+
action: Type.Unsafe({
|
|
2430
|
+
type: "string",
|
|
2431
|
+
enum: [...TERMINAL_ACTIONS],
|
|
2432
|
+
description: "list | create(terminalId,cwd?,cols?,rows?) | close(terminalId) | input(terminalId,data) | " +
|
|
2433
|
+
"key(terminalId,key,modifiers?) | read(terminalId,cursor?,waitMs?,maxBytes?,head?|tail?,search?) | " +
|
|
2434
|
+
"wait(terminalId,maxWaitMs?)",
|
|
2435
|
+
}),
|
|
2436
|
+
terminalId: Type.Optional(Type.String()),
|
|
2437
|
+
cwd: Type.Optional(Type.String()),
|
|
2438
|
+
cols: Type.Optional(Type.Integer()),
|
|
2439
|
+
rows: Type.Optional(Type.Integer()),
|
|
2440
|
+
data: Type.Optional(Type.String({ description: "Include newline to submit" })),
|
|
2441
|
+
key: Type.Optional(Type.String()),
|
|
2436
2442
|
modifiers: Type.Optional(Type.Object({
|
|
2437
2443
|
ctrl: Type.Optional(Type.Boolean()),
|
|
2438
2444
|
alt: Type.Optional(Type.Boolean()),
|
|
2439
2445
|
shift: Type.Optional(Type.Boolean()),
|
|
2440
2446
|
})),
|
|
2441
|
-
cursor: Type.Optional(Type.Integer(
|
|
2442
|
-
maxBytes: Type.Optional(Type.Integer(
|
|
2443
|
-
waitMs: Type.Optional(Type.Integer(
|
|
2444
|
-
maxWaitMs: Type.Optional(Type.Integer(
|
|
2445
|
-
head: Type.Optional(Type.Integer(
|
|
2446
|
-
tail: Type.Optional(Type.Integer(
|
|
2447
|
-
search: Type.Optional(Type.String(
|
|
2447
|
+
cursor: Type.Optional(Type.Integer()),
|
|
2448
|
+
maxBytes: Type.Optional(Type.Integer()),
|
|
2449
|
+
waitMs: Type.Optional(Type.Integer()),
|
|
2450
|
+
maxWaitMs: Type.Optional(Type.Integer()),
|
|
2451
|
+
head: Type.Optional(Type.Integer()),
|
|
2452
|
+
tail: Type.Optional(Type.Integer()),
|
|
2453
|
+
search: Type.Optional(Type.String()),
|
|
2448
2454
|
}),
|
|
2449
2455
|
execute: async (_id, args, signal) => {
|
|
2450
2456
|
signal?.throwIfAborted();
|
|
2451
|
-
if (!
|
|
2457
|
+
if (!TERMINAL_ACTIONS.includes(args.action))
|
|
2452
2458
|
throw new Error("Unknown terminal action");
|
|
2453
2459
|
if (args.action !== "list" && (typeof args.terminalId !== "string" || !args.terminalId.trim()))
|
|
2454
2460
|
throw new Error("terminalId is required for " + args.action);
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
+
import { isPseudoClientId } from "./client-id-utils.js";
|
|
1
2
|
import { DEFAULT_APPROVAL_RULES, evaluateApprovalRules, extractTargetPath, } from "./approval-rules.js";
|
|
3
|
+
/** 无人值守会话的审批等待上限(秒);实际值可用 PI_WEB_UNATTENDED_APPROVAL_TIMEOUT 覆盖。 */
|
|
4
|
+
export const DEFAULT_UNATTENDED_APPROVAL_TIMEOUT_S = 120;
|
|
5
|
+
/**
|
|
6
|
+
* 伪客户端(plugin: / scheduler: / canvas:)的会话没有人在看 UI。
|
|
7
|
+
* 这类会话的审批等不到人点,必须超时兜底。
|
|
8
|
+
*/
|
|
9
|
+
export function unattendedApprovalTimeoutMs(clientId, rawEnv = process.env.PI_WEB_UNATTENDED_APPROVAL_TIMEOUT) {
|
|
10
|
+
if (!isPseudoClientId(clientId))
|
|
11
|
+
return null;
|
|
12
|
+
const v = Number(rawEnv);
|
|
13
|
+
const seconds = Number.isFinite(v) && v > 0 ? Math.min(v, 3_600) : DEFAULT_UNATTENDED_APPROVAL_TIMEOUT_S;
|
|
14
|
+
return seconds * 1000;
|
|
15
|
+
}
|
|
2
16
|
export function isApprovalPolicyEmpty(policy) {
|
|
3
17
|
return !policy || (!policy.allowAll && policy.categories.size === 0);
|
|
4
18
|
}
|
|
@@ -28,7 +42,7 @@ export function isWideScopeOrRootOperation(toolName, params) {
|
|
|
28
42
|
return true;
|
|
29
43
|
}
|
|
30
44
|
}
|
|
31
|
-
if (toolName === "write" || toolName === "edit" || toolName === "
|
|
45
|
+
if (toolName === "write" || toolName === "edit" || toolName === "patch") {
|
|
32
46
|
const p = extractTargetPath(params);
|
|
33
47
|
if (p.includes("/etc/") ||
|
|
34
48
|
p.includes("/boot/") ||
|
|
@@ -375,13 +375,6 @@ export function wrapWriteToolWithPermission(cwd, getPermission, getRoots, getLan
|
|
|
375
375
|
[APPROVAL_GUARDED]: true,
|
|
376
376
|
};
|
|
377
377
|
}
|
|
378
|
-
export const EDIT_DESCRIPTION = "Edit a single file by exact text replacement: every edits[].oldText must uniquely match the original file.";
|
|
379
|
-
export const EDIT_GUIDELINES = [
|
|
380
|
-
"Use edit for precise changes; oldText must match exactly",
|
|
381
|
-
"When changing several separate locations in one file, put them in ONE call's edits[] instead of multiple calls",
|
|
382
|
-
"Each oldText matches the original file, not earlier edits in the same call — never overlapping or nested",
|
|
383
|
-
"Keep oldText small but unique; never pad with large unchanged regions",
|
|
384
|
-
];
|
|
385
378
|
export function wrapEditToolWithPermission(cwd, getPermission, getRoots, getLang, askApproval, getConversationId, getRules, base) {
|
|
386
379
|
const remoteOps = !base ? createRemoteSdkOperations(cwd) : null;
|
|
387
380
|
const effectiveBase = base ?? createEditToolDefinition(cwd, remoteOps ? { operations: remoteOps.edit } : undefined);
|
|
@@ -468,90 +461,6 @@ export function wrapEditToolWithPermission(cwd, getPermission, getRoots, getLang
|
|
|
468
461
|
[APPROVAL_GUARDED]: true,
|
|
469
462
|
};
|
|
470
463
|
}
|
|
471
|
-
export function wrapEditSoftToolWithPermission(tool, cwd, getPermission, getRoots, getLang, askApproval, getConversationId, getRules) {
|
|
472
|
-
return {
|
|
473
|
-
...tool,
|
|
474
|
-
execute: async (toolCallId, params, signal, onUpdate, ctx) => {
|
|
475
|
-
checkCancellation(signal);
|
|
476
|
-
const perm = getPermission();
|
|
477
|
-
if (perm === "read-only") {
|
|
478
|
-
return {
|
|
479
|
-
content: [
|
|
480
|
-
{
|
|
481
|
-
type: "text",
|
|
482
|
-
text: pick(getLang(), "【权限被拒绝】当前会话处于「只读模式」(read-only),禁止编辑文件。若需修改请切换权限预设。", "[Permission Denied] The current session is in 'read-only' mode; editing files is forbidden. Switch permission preset if needed."),
|
|
483
|
-
},
|
|
484
|
-
],
|
|
485
|
-
isError: true,
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
if (perm === "workspace-write-never") {
|
|
489
|
-
const p = params?.path ?? "";
|
|
490
|
-
if (!isInsideWorkspaceRoots(p, cwd, getRoots())) {
|
|
491
|
-
return {
|
|
492
|
-
content: [
|
|
493
|
-
{
|
|
494
|
-
type: "text",
|
|
495
|
-
text: pick(getLang(), `【权限被拒绝】当前会话处于「工作区内修改」(workspace-write-never)模式,禁止修改工作区外部文件("${p}")。若需修改请切换至「完全权限」。`, `[Permission Denied] The current session is in 'workspace-write-never' mode; editing files outside the workspace ("${p}") is forbidden. Switch to 'danger-full-access' if needed.`),
|
|
496
|
-
},
|
|
497
|
-
],
|
|
498
|
-
isError: true,
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
let effectiveParams = params;
|
|
503
|
-
let userEdited = false;
|
|
504
|
-
if (askApproval) {
|
|
505
|
-
const danger = checkDangerousToolCall("edit_soft", params, cwd, getRoots(), getRules?.());
|
|
506
|
-
if (danger.denied) {
|
|
507
|
-
return {
|
|
508
|
-
content: [
|
|
509
|
-
{
|
|
510
|
-
type: "text",
|
|
511
|
-
text: pick(getLang(), `【文件编辑被审批规则直接阻断】${danger.reason ? ` 原因:${danger.reason}` : ""}`, `[File edit blocked by approval rule]${danger.reason ? ` Reason: ${danger.reason}` : ""}`),
|
|
512
|
-
},
|
|
513
|
-
],
|
|
514
|
-
details: { guardDenied: true, ruleDenied: true, reason: danger.reason },
|
|
515
|
-
isError: true,
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
if (danger.dangerous) {
|
|
519
|
-
const res = await askApproval(toolCallId, "edit_soft", params, danger.reason, danger.reasonEn, getConversationId?.(), danger.category, danger.hits, signal);
|
|
520
|
-
checkCancellation(signal);
|
|
521
|
-
if (res.decision === "deny") {
|
|
522
|
-
return {
|
|
523
|
-
content: [
|
|
524
|
-
{
|
|
525
|
-
type: "text",
|
|
526
|
-
text: pick(getLang(), `【文件编辑被用户拒绝】${res.reason ? ` 原因:${res.reason}` : ""}`, `[File edit denied by user]${res.reason ? ` Reason: ${res.reason}` : ""}`),
|
|
527
|
-
},
|
|
528
|
-
],
|
|
529
|
-
details: { guardDenied: true, userDenied: true, reason: res.reason },
|
|
530
|
-
isError: true,
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
else if (res.decision === "edit") {
|
|
534
|
-
effectiveParams = res.editedParams ?? params;
|
|
535
|
-
userEdited = true;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
checkCancellation(signal);
|
|
540
|
-
const result = (await tool.execute(toolCallId, effectiveParams, signal, onUpdate, ctx));
|
|
541
|
-
checkCancellation(signal);
|
|
542
|
-
if (userEdited && result && typeof result === "object") {
|
|
543
|
-
result.details = {
|
|
544
|
-
...result.details,
|
|
545
|
-
userEdited: true,
|
|
546
|
-
originalParams: params,
|
|
547
|
-
executedParams: effectiveParams,
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
return result;
|
|
551
|
-
},
|
|
552
|
-
[APPROVAL_GUARDED]: true,
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
464
|
export function wrapPatchToolWithPermission(tool, cwd, getPermission, getRoots, getLang, askApproval, getConversationId, getRules) {
|
|
556
465
|
return {
|
|
557
466
|
...tool,
|
|
@@ -12,9 +12,9 @@ export const LEGACY_TERMINAL_TOOL_NAMES = [
|
|
|
12
12
|
];
|
|
13
13
|
export const CONVERSATION_TOOL_NAME = "conversation";
|
|
14
14
|
export const COMMUNICATE_TOOL_NAME = "communicate";
|
|
15
|
-
|
|
16
|
-
export const SUBAGENT_TOOL_NAMES = [CONVERSATION_TOOL_NAME, SUBAGENT_TOOL_NAME];
|
|
15
|
+
/** Tool names that fold into `conversation`: the pre-rename subagent_* family plus the retired `subagent` alias. */
|
|
17
16
|
export const LEGACY_SUBAGENT_TOOL_NAMES = [
|
|
17
|
+
"subagent",
|
|
18
18
|
"subagent_spawn",
|
|
19
19
|
"subagent_get_result",
|
|
20
20
|
"subagent_steer",
|
|
@@ -24,10 +24,11 @@ export const LEGACY_SUBAGENT_TOOL_NAMES = [
|
|
|
24
24
|
"subagent_templates",
|
|
25
25
|
"subagent_handoff",
|
|
26
26
|
];
|
|
27
|
-
export const EDIT_SOFT_TOOL_NAME = "edit_soft";
|
|
28
27
|
export const DELEGATE_TASK_TOOL_NAME = "delegate_task";
|
|
29
28
|
export const ASK_USER_QUESTION_TOOL_NAME = "ask_user_question";
|
|
30
29
|
export const BROWSER_PAGE_TOOL_NAME = "browser_page";
|
|
30
|
+
export const BROWSER_SCRIPT_TOOL_NAME = "browser_script";
|
|
31
|
+
export const PHONE_TOOL_NAME = "phone";
|
|
31
32
|
export const CONVERSATION_READ_TOOL_NAME = CONVERSATION_TOOL_NAME;
|
|
32
33
|
export const SKILL_TOOL_NAME = "skill";
|
|
33
34
|
export const SCHEDULE_TOOL_NAME = "schedule";
|
|
@@ -47,6 +48,35 @@ export const CODEMODE_TOOL_NAME = "codemode";
|
|
|
47
48
|
export const TOOL_SEARCH_TOOL_NAME = "tool_search";
|
|
48
49
|
export const LOAD_TOOLS_TOOL_NAME = "load_tools";
|
|
49
50
|
export const LAZY_CORE_TOOL_NAMES = ["bash", "read", "edit", "write"];
|
|
51
|
+
/**
|
|
52
|
+
* 工具名统一规则(架构单源):内置 + 插件 + MCP + 未来工具共用。
|
|
53
|
+
* 内置在 `ALL_KNOWN_SET` 里;插件/MCP/未来工具按此正则收,不写死名单,自动包含插件。
|
|
54
|
+
* 与 `normalizeDisabledPluginTools`(client-state.ts)的 128/256 上限对齐。
|
|
55
|
+
*/
|
|
56
|
+
export const TOOL_NAME_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9_.-]*$/;
|
|
57
|
+
export const TOOL_NAME_MAX_LENGTH = 128;
|
|
58
|
+
export const TOOL_LIST_MAX_ENTRIES = 256;
|
|
59
|
+
export function isValidToolName(name) {
|
|
60
|
+
if (!name || name.length > TOOL_NAME_MAX_LENGTH)
|
|
61
|
+
return false;
|
|
62
|
+
return TOOL_NAME_PATTERN.test(name);
|
|
63
|
+
}
|
|
64
|
+
/** 旧别名统一折叠(禁用列表与按需名单共用,免得旧存档丢项)。 */
|
|
65
|
+
export function foldLegacyToolName(name) {
|
|
66
|
+
if (LEGACY_TERMINAL_TOOL_NAMES.includes(name))
|
|
67
|
+
return TERMINAL_TOOL_NAME;
|
|
68
|
+
if (LEGACY_SUBAGENT_TOOL_NAMES.includes(name))
|
|
69
|
+
return CONVERSATION_TOOL_NAME;
|
|
70
|
+
if (name === "conversation_read")
|
|
71
|
+
return CONVERSATION_TOOL_NAME;
|
|
72
|
+
if (LEGACY_SCHEDULE_TOOL_NAMES.includes(name))
|
|
73
|
+
return SCHEDULE_TOOL_NAME;
|
|
74
|
+
return name;
|
|
75
|
+
}
|
|
76
|
+
/** 永不延迟:核心 4 件套 + load_tools 本体。前端置灰与后端过滤共用此语义(前端见 LAZY_CORE 注)。 */
|
|
77
|
+
export function isNeverLazyTool(name) {
|
|
78
|
+
return name === LOAD_TOOLS_TOOL_NAME || LAZY_CORE_TOOL_NAMES.includes(name);
|
|
79
|
+
}
|
|
50
80
|
export const AGENT_TOOL_CATALOG = [
|
|
51
81
|
...TERMINAL_TOOL_NAMES.map((name) => ({
|
|
52
82
|
name,
|
|
@@ -54,12 +84,12 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
54
84
|
defaultOn: false,
|
|
55
85
|
dshVisible: true,
|
|
56
86
|
})),
|
|
57
|
-
|
|
58
|
-
name,
|
|
87
|
+
{
|
|
88
|
+
name: CONVERSATION_TOOL_NAME,
|
|
59
89
|
group: "subagent",
|
|
60
90
|
defaultOn: true,
|
|
61
91
|
dshVisible: false,
|
|
62
|
-
}
|
|
92
|
+
},
|
|
63
93
|
{
|
|
64
94
|
name: COMMUNICATE_TOOL_NAME,
|
|
65
95
|
group: "subagent",
|
|
@@ -68,18 +98,10 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
68
98
|
descKey: "communicateEnabledDesc",
|
|
69
99
|
offHintKey: "communicateOffHint",
|
|
70
100
|
},
|
|
71
|
-
{
|
|
72
|
-
name: EDIT_SOFT_TOOL_NAME,
|
|
73
|
-
group: "other",
|
|
74
|
-
defaultOn: false,
|
|
75
|
-
dshVisible: false,
|
|
76
|
-
descKey: "editSoftEnabledDesc",
|
|
77
|
-
offHintKey: "editSoftOffHint",
|
|
78
|
-
},
|
|
79
101
|
{
|
|
80
102
|
name: DELEGATE_TASK_TOOL_NAME,
|
|
81
103
|
group: "other",
|
|
82
|
-
defaultOn:
|
|
104
|
+
defaultOn: false,
|
|
83
105
|
dshVisible: false,
|
|
84
106
|
descKey: "delegateTaskEnabledDesc",
|
|
85
107
|
offHintKey: "delegateTaskOffHint",
|
|
@@ -100,6 +122,23 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
100
122
|
descKey: "browserPageEnabledDesc",
|
|
101
123
|
offHintKey: "browserPageOffHint",
|
|
102
124
|
},
|
|
125
|
+
{
|
|
126
|
+
name: BROWSER_SCRIPT_TOOL_NAME,
|
|
127
|
+
group: "other",
|
|
128
|
+
defaultOn: false,
|
|
129
|
+
dshVisible: false,
|
|
130
|
+
descKey: "browserScriptEnabledDesc",
|
|
131
|
+
offHintKey: "browserScriptOffHint",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
// 让智能体操作手机(无障碍服务)。默认关:等于把整台手机交给模型,必须用户显式打开。
|
|
135
|
+
name: PHONE_TOOL_NAME,
|
|
136
|
+
group: "other",
|
|
137
|
+
defaultOn: false,
|
|
138
|
+
dshVisible: false,
|
|
139
|
+
descKey: "phoneEnabledDesc",
|
|
140
|
+
offHintKey: "phoneOffHint",
|
|
141
|
+
},
|
|
103
142
|
{
|
|
104
143
|
name: CLAIM_FILES_TOOL_NAME,
|
|
105
144
|
group: "other",
|
|
@@ -119,7 +158,7 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
119
158
|
{
|
|
120
159
|
name: PATCH_TOOL_NAME,
|
|
121
160
|
group: "other",
|
|
122
|
-
defaultOn:
|
|
161
|
+
defaultOn: false,
|
|
123
162
|
dshVisible: false,
|
|
124
163
|
descKey: "patchToolEnabledDesc",
|
|
125
164
|
offHintKey: "patchToolOffHint",
|
|
@@ -199,7 +238,7 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
199
238
|
{
|
|
200
239
|
name: SANDBOX_TOOL_NAME,
|
|
201
240
|
group: "other",
|
|
202
|
-
defaultOn:
|
|
241
|
+
defaultOn: false,
|
|
203
242
|
dshVisible: false,
|
|
204
243
|
descKey: "sandboxEnabledDesc",
|
|
205
244
|
offHintKey: "sandboxOffHint",
|
|
@@ -207,7 +246,7 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
207
246
|
{
|
|
208
247
|
name: WORKTREE_TOOL_NAME,
|
|
209
248
|
group: "other",
|
|
210
|
-
defaultOn:
|
|
249
|
+
defaultOn: false,
|
|
211
250
|
dshVisible: false,
|
|
212
251
|
descKey: "toolsWorktreeDesc",
|
|
213
252
|
offHintKey: "toolsWorktreeOffHint",
|
|
@@ -215,7 +254,7 @@ export const AGENT_TOOL_CATALOG = [
|
|
|
215
254
|
{
|
|
216
255
|
name: CANVAS_TOOL_NAME,
|
|
217
256
|
group: "other",
|
|
218
|
-
defaultOn:
|
|
257
|
+
defaultOn: false,
|
|
219
258
|
dshVisible: false,
|
|
220
259
|
descKey: "canvasToolEnabledDesc",
|
|
221
260
|
offHintKey: "canvasToolOffHint",
|
|
@@ -246,7 +285,7 @@ export const CORE_TOOL_CATALOG = [
|
|
|
246
285
|
allowAgentToggle: false,
|
|
247
286
|
descKey: "toolCorePowershellDesc",
|
|
248
287
|
},
|
|
249
|
-
{ name: "ls", group: "core", defaultOn:
|
|
288
|
+
{ name: "ls", group: "core", defaultOn: false, allowAgentToggle: false, descKey: "toolCoreLsDesc" },
|
|
250
289
|
{ name: "grep", group: "core", defaultOn: true, allowAgentToggle: false, descKey: "toolCoreGrepDesc" },
|
|
251
290
|
{ name: "find", group: "core", defaultOn: true, allowAgentToggle: false, descKey: "toolCoreFindDesc" },
|
|
252
291
|
];
|
|
@@ -316,12 +355,6 @@ export function normalizeDisabledAgentTools(v) {
|
|
|
316
355
|
}
|
|
317
356
|
if (name === "conversation_read")
|
|
318
357
|
name = CONVERSATION_TOOL_NAME;
|
|
319
|
-
if (typeof name === "string" && SUBAGENT_TOOL_NAMES.includes(name)) {
|
|
320
|
-
for (const alias of SUBAGENT_TOOL_NAMES)
|
|
321
|
-
if (!out.includes(alias))
|
|
322
|
-
out.push(alias);
|
|
323
|
-
continue;
|
|
324
|
-
}
|
|
325
358
|
if (typeof name === "string" && LEGACY_SCHEDULE_TOOL_NAMES.includes(name)) {
|
|
326
359
|
name = SCHEDULE_TOOL_NAME;
|
|
327
360
|
}
|
|
@@ -388,7 +421,7 @@ export function applyAgentToolsGating(session, disabled, preset, options) {
|
|
|
388
421
|
}
|
|
389
422
|
for (const t of AGENT_TOOL_CATALOG) {
|
|
390
423
|
if (off.has(t.name)) {
|
|
391
|
-
const isShadowedCustomTool =
|
|
424
|
+
const isShadowedCustomTool = t.name === CONVERSATION_TOOL_NAME;
|
|
392
425
|
const hasExtensionTool = isShadowedCustomTool &&
|
|
393
426
|
Boolean(session?.extensionRunner
|
|
394
427
|
?.getAllRegisteredTools?.()
|
|
@@ -434,9 +467,67 @@ export function applyAgentToolsGating(session, disabled, preset, options) {
|
|
|
434
467
|
}
|
|
435
468
|
catch { }
|
|
436
469
|
}
|
|
437
|
-
export function
|
|
470
|
+
export function normalizeToolOnDemandList(v) {
|
|
471
|
+
if (!Array.isArray(v))
|
|
472
|
+
return [];
|
|
473
|
+
const out = [];
|
|
474
|
+
for (const x of v) {
|
|
475
|
+
if (typeof x !== "string")
|
|
476
|
+
continue;
|
|
477
|
+
const name = foldLegacyToolName(x.trim());
|
|
478
|
+
if (!name || out.includes(name))
|
|
479
|
+
continue;
|
|
480
|
+
// 内置直接收;插件 / MCP / 未来工具按统一命名规则收,不写死名单,自动包含插件。
|
|
481
|
+
// 孤儿项(插件已卸载、跨设备同步)同样保留,UI 兜底展示, gating 按 live 库存解析。
|
|
482
|
+
if (ALL_KNOWN_SET.has(name) || isValidToolName(name)) {
|
|
483
|
+
out.push(name);
|
|
484
|
+
if (out.length >= TOOL_LIST_MAX_ENTRIES)
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return out;
|
|
489
|
+
}
|
|
490
|
+
export function normalizeLazyOnDemandList(v) {
|
|
491
|
+
return normalizeToolOnDemandList(v).filter((n) => n !== LOAD_TOOLS_TOOL_NAME && !LAZY_CORE_TOOL_NAMES.includes(n));
|
|
492
|
+
}
|
|
493
|
+
export function lazyLoadingDisabledTools(allNames, loaded, core = LAZY_CORE_TOOL_NAMES, only) {
|
|
438
494
|
const keep = new Set([...core, LOAD_TOOLS_TOOL_NAME, ...loaded]);
|
|
439
|
-
|
|
495
|
+
const onlySet = only ? new Set(only) : undefined;
|
|
496
|
+
return allNames.filter((n) => {
|
|
497
|
+
if (keep.has(n))
|
|
498
|
+
return false;
|
|
499
|
+
// 名单制:只延迟名单里的工具;名单外常驻。`only` 为空集合时等于都不延迟。
|
|
500
|
+
if (onlySet && !onlySet.has(n))
|
|
501
|
+
return false;
|
|
502
|
+
return true;
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* 延迟划分单源(架构级):所有调用方(门控/目录/加载/JIT/提示词)共用同一划分,
|
|
507
|
+
* 避免各处手写 `allowed - onDemand` 导致分歧。输入均为 live 库存,孤儿名单项自动忽略。
|
|
508
|
+
*/
|
|
509
|
+
export function partitionLazyTools(args) {
|
|
510
|
+
const allowedSet = args.allowed instanceof Set ? args.allowed : new Set(args.allowed);
|
|
511
|
+
const onDemandSet = args.onDemand instanceof Set ? args.onDemand : new Set(args.onDemand);
|
|
512
|
+
const loadedSet = args.loaded instanceof Set ? args.loaded : new Set(args.loaded);
|
|
513
|
+
// 名单里永不延迟的(核心/load)直接视为常驻,不进入 pending。
|
|
514
|
+
const lazyable = new Set([...onDemandSet].filter((n) => !isNeverLazyTool(n)));
|
|
515
|
+
const resident = [];
|
|
516
|
+
const pending = [];
|
|
517
|
+
const loadedLazy = [];
|
|
518
|
+
for (const n of args.all) {
|
|
519
|
+
if (!allowedSet.has(n))
|
|
520
|
+
continue;
|
|
521
|
+
if (!lazyable.has(n)) {
|
|
522
|
+
resident.push(n);
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
if (loadedSet.has(n))
|
|
526
|
+
loadedLazy.push(n);
|
|
527
|
+
else
|
|
528
|
+
pending.push(n);
|
|
529
|
+
}
|
|
530
|
+
return { resident, pending, loadedLazy };
|
|
440
531
|
}
|
|
441
532
|
export const PI_AGENT_PRESETS = [
|
|
442
533
|
{
|
|
@@ -465,8 +556,8 @@ export const PI_AGENT_PRESETS = [
|
|
|
465
556
|
isDefault: false,
|
|
466
557
|
name: "代码开发",
|
|
467
558
|
nameEn: "Code development",
|
|
468
|
-
description: "专注于代码读写与执行(bash, read, edit, write
|
|
469
|
-
descriptionEn: "Focused on reading, writing and running code (bash, read, edit, write
|
|
559
|
+
description: "专注于代码读写与执行(bash, read, edit, write);插件工具与技能名录同步隐藏",
|
|
560
|
+
descriptionEn: "Focused on reading, writing and running code (bash, read, edit, write); plugin tools and skill catalog are hidden too",
|
|
470
561
|
order: 2,
|
|
471
562
|
},
|
|
472
563
|
{
|
|
@@ -495,8 +586,8 @@ export const PI_PERMISSION_OPTIONS = [
|
|
|
495
586
|
value: "read-only",
|
|
496
587
|
name: "只读模式",
|
|
497
588
|
nameEn: "Read Only",
|
|
498
|
-
description: "禁止所有文件修改(write/edit
|
|
499
|
-
descriptionEn: "Forbids all file modification (write/edit
|
|
589
|
+
description: "禁止所有文件修改(write/edit)及任何非只读操作",
|
|
590
|
+
descriptionEn: "Forbids all file modification (write/edit) and any non-read-only operation",
|
|
500
591
|
},
|
|
501
592
|
{
|
|
502
593
|
value: "workspace-write-never",
|
|
@@ -533,14 +624,13 @@ export function filterToolsByPreset(tools, preset) {
|
|
|
533
624
|
return all.filter((n) => n === "bash" || n === "read");
|
|
534
625
|
}
|
|
535
626
|
if (preset === "code") {
|
|
536
|
-
const codeSet = new Set(["bash", "read", "edit", "write"
|
|
627
|
+
const codeSet = new Set(["bash", "read", "edit", "write"]);
|
|
537
628
|
return all.filter((n) => codeSet.has(n));
|
|
538
629
|
}
|
|
539
630
|
if (preset === "reader") {
|
|
540
631
|
const writeTools = new Set([
|
|
541
632
|
"write",
|
|
542
633
|
"edit",
|
|
543
|
-
"edit_soft",
|
|
544
634
|
"bash",
|
|
545
635
|
"powershell",
|
|
546
636
|
"terminal_create",
|
|
@@ -572,8 +662,6 @@ export function legacyToDisabled(s) {
|
|
|
572
662
|
for (const n of TERMINAL_TOOL_NAMES)
|
|
573
663
|
off.delete(n);
|
|
574
664
|
}
|
|
575
|
-
if (s.editSoftEnabled === true)
|
|
576
|
-
off.delete(EDIT_SOFT_TOOL_NAME);
|
|
577
665
|
if (s.questionnaireEnabled === false)
|
|
578
666
|
off.add(ASK_USER_QUESTION_TOOL_NAME);
|
|
579
667
|
return normalizeDisabledAgentTools([...off]);
|
|
@@ -582,7 +670,6 @@ export function deriveLegacy(disabled) {
|
|
|
582
670
|
const off = new Set(disabled);
|
|
583
671
|
return {
|
|
584
672
|
terminalToolsEnabled: TERMINAL_TOOL_NAMES.every((n) => !off.has(n)),
|
|
585
|
-
editSoftEnabled: !off.has(EDIT_SOFT_TOOL_NAME),
|
|
586
673
|
questionnaireEnabled: !off.has(ASK_USER_QUESTION_TOOL_NAME),
|
|
587
674
|
};
|
|
588
675
|
}
|
|
@@ -599,7 +686,6 @@ export function foldLegacyIntoDisabled(current, legacy) {
|
|
|
599
686
|
}
|
|
600
687
|
};
|
|
601
688
|
applyGroup(TERMINAL_TOOL_NAMES, legacy.terminalToolsEnabled);
|
|
602
|
-
applyGroup([EDIT_SOFT_TOOL_NAME], legacy.editSoftEnabled);
|
|
603
689
|
applyGroup([ASK_USER_QUESTION_TOOL_NAME], legacy.questionnaireEnabled);
|
|
604
690
|
return [...next];
|
|
605
691
|
}
|
|
@@ -607,13 +693,7 @@ export function effectiveDisabledAgentTools(s) {
|
|
|
607
693
|
const next = new Set(legacyToDisabled({ ...s, disabledAgentTools: s.disabledAgentTools }));
|
|
608
694
|
if (s.questionnaireEnabled === false)
|
|
609
695
|
next.add(ASK_USER_QUESTION_TOOL_NAME);
|
|
696
|
+
// 按需名单不再是硬关闭:它只在 `toolLazyLoading` 开启时决定哪些工具延迟,
|
|
697
|
+
// 常驻/禁用只由 `disabledAgentTools`、预设与模式闸门决定。这里不并入名单。
|
|
610
698
|
return [...next];
|
|
611
699
|
}
|
|
612
|
-
export function isTerminalGuidanceOn(disabled, preset) {
|
|
613
|
-
const on = TERMINAL_TOOL_NAMES.filter((n) => !disabled.includes(n));
|
|
614
|
-
if (on.length === 0)
|
|
615
|
-
return false;
|
|
616
|
-
if (!preset || preset === "standard")
|
|
617
|
-
return true;
|
|
618
|
-
return filterToolsByPreset(on, preset).length > 0;
|
|
619
|
-
}
|
|
@@ -32,7 +32,7 @@ export function syncSubagentOverride(session, subagentDisabled, builtinSubagentT
|
|
|
32
32
|
if (!Array.isArray(session._customTools) || typeof session._refreshToolRegistry !== "function")
|
|
33
33
|
return;
|
|
34
34
|
let changed = false;
|
|
35
|
-
for (const name of ["conversation"
|
|
35
|
+
for (const name of ["conversation"]) {
|
|
36
36
|
if (!extensionToolDefinition(session, name))
|
|
37
37
|
continue;
|
|
38
38
|
const idx = session._customTools.findIndex((t) => t.name === name);
|
|
@@ -48,3 +48,10 @@ export function syncSubagentOverride(session, subagentDisabled, builtinSubagentT
|
|
|
48
48
|
if (changed)
|
|
49
49
|
session._refreshToolRegistry();
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* 只换模型看到的文案与参数 schema,行为仍走 base(SDK 内置实现)。
|
|
53
|
+
* 用于那些「宿主不拥有实现、但拥有提示词」的工具(write/grep/find)。
|
|
54
|
+
*/
|
|
55
|
+
export function withSlimPrompt(base, description, parameters) {
|
|
56
|
+
return { ...base, description, parameters };
|
|
57
|
+
}
|
|
@@ -55,10 +55,9 @@ export function normalizeToolPromptOverrides(v, knownTools) {
|
|
|
55
55
|
};
|
|
56
56
|
const source = { ...v };
|
|
57
57
|
const conversationOverride = normalizeToolPromptOverride(source.conversation) ?? normalizeToolPromptOverride(source.subagent);
|
|
58
|
-
if (conversationOverride)
|
|
58
|
+
if (conversationOverride)
|
|
59
59
|
source.conversation = conversationOverride;
|
|
60
|
-
|
|
61
|
-
}
|
|
60
|
+
delete source.subagent;
|
|
62
61
|
const legacyNames = [
|
|
63
62
|
"terminal_create",
|
|
64
63
|
"terminal_list",
|
|
@@ -94,9 +93,7 @@ export function normalizeToolPromptOverrides(v, knownTools) {
|
|
|
94
93
|
return out;
|
|
95
94
|
}
|
|
96
95
|
export function toolPromptOverrideOf(map, name) {
|
|
97
|
-
const ov = ["terminal", "conversation"
|
|
98
|
-
? normalizeToolPromptOverrides(map)[name]
|
|
99
|
-
: map?.[name];
|
|
96
|
+
const ov = ["terminal", "conversation"].includes(name) ? normalizeToolPromptOverrides(map)[name] : map?.[name];
|
|
100
97
|
return ov && Object.keys(ov).length > 0 ? ov : null;
|
|
101
98
|
}
|
|
102
99
|
export function effectiveToolPrompt(base, override) {
|