pi-web-ui 0.98.0 → 0.100.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 +85 -5
- package/README.md +2 -1
- package/README.zh-CN.md +2 -1
- package/bin/pi-web-ui.mjs +174 -36
- package/dist/server/agent-service.js +1169 -152
- package/dist/server/approval-rules.js +95 -23
- package/dist/server/attachments.js +55 -0
- package/dist/server/bg-servers.js +82 -2
- package/dist/server/claim-files-tool.js +4 -4
- package/dist/server/client-state.js +41 -0
- package/dist/server/compact-context-tool.js +10 -9
- package/dist/server/conversation-read-tool.js +7 -8
- package/dist/server/conversation-touches.js +19 -0
- package/dist/server/delegate-task.js +10 -14
- package/dist/server/dsh/dsh-agent-service.js +116 -12
- package/dist/server/edit-soft-tool.js +10 -12
- package/dist/server/eval-tool.js +26 -6
- package/dist/server/goal-evidence.js +173 -0
- package/dist/server/goal-service.js +78 -15
- package/dist/server/hashline-engine.js +198 -31
- package/dist/server/index.js +55 -9
- package/dist/server/load-tools-tool.js +100 -0
- package/dist/server/lsp-tool.js +10 -16
- package/dist/server/marker-service.js +53 -12
- package/dist/server/markers/builtins/action.js +108 -0
- package/dist/server/markers/index.js +4 -1
- package/dist/server/model-enrich.js +2 -0
- package/dist/server/patch-remote-catalog.js +28 -10
- package/dist/server/patch-tool.js +74 -38
- package/dist/server/plan-manager.js +71 -30
- package/dist/server/plan-mode.js +7 -6
- package/dist/server/plugin-api-catalog.js +10 -3
- package/dist/server/plugin-conversation-view.js +47 -0
- package/dist/server/plugins.js +113 -26
- package/dist/server/present-files-tool.js +10 -11
- package/dist/server/preset-fields.js +693 -0
- package/dist/server/preset-share.js +1178 -0
- package/dist/server/prompt-composer.js +23 -9
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/read-tool.js +8 -10
- package/dist/server/resolve-global-sdk.js +80 -18
- package/dist/server/schedule-agent-tool.js +147 -146
- package/dist/server/sdk-origin.js +125 -37
- package/dist/server/settings-service.js +103 -84
- package/dist/server/skill-tool.js +3 -4
- package/dist/server/subagents.js +15 -22
- package/dist/server/terminals.js +29 -39
- package/dist/server/tool-approval.js +3 -1
- package/dist/server/tool-manager.js +63 -27
- package/dist/server/tool-prompt-overrides.js +158 -0
- package/dist/server/tool-prompts.js +42 -0
- package/dist/server/tool-signature.js +104 -0
- package/dist/server/update-check.js +0 -15
- package/dist/server/workspace-snapshot.js +42 -11
- package/package.json +5 -3
- package/plugin-sdk/README.md +8 -4
- package/plugin-sdk/import-check.mjs +210 -0
- package/plugin-sdk/index.d.ts +4 -1
- package/plugin-sdk/index.mjs +1 -0
- package/plugins/catalog.json +33 -2
- package/themes/zhupi-dark.css +1 -1
- package/themes/zhupi.css +1 -1
- package/web/dist/assets/{TerminalPanel-C88r3r3Q.js → TerminalPanel-C3I1Mc-C.js} +2 -2
- package/web/dist/assets/index-B-E2EM_0.css +1 -0
- package/web/dist/assets/index-BYumAaGi.js +379 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-2jDtjHvW.css +0 -1
- package/web/dist/assets/index-BjdK7s1M.js +0 -368
|
@@ -11,58 +11,143 @@
|
|
|
11
11
|
*
|
|
12
12
|
* 纯函数 + 零副作用,便于单测(见 tests/unit/sdk-origin.test.ts)。
|
|
13
13
|
*/
|
|
14
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
15
|
-
import { dirname, join } from "node:path";
|
|
14
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
15
|
+
import { dirname, join, delimiter, isAbsolute } from "node:path";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
17
|
const PKG = "@earendil-works/pi-coding-agent";
|
|
18
|
-
|
|
18
|
+
function addCopy(pjPath, out, requireName = false) {
|
|
19
|
+
if (!existsSync(pjPath))
|
|
20
|
+
return;
|
|
21
|
+
const norm = pjPath.replace(/\\/g, "/");
|
|
22
|
+
if (out.some((c) => c.path.replace(/\\/g, "/") === norm))
|
|
23
|
+
return;
|
|
24
|
+
try {
|
|
25
|
+
const raw = readFileSync(pjPath, "utf8");
|
|
26
|
+
const info = JSON.parse(raw);
|
|
27
|
+
if (requireName && info?.name !== PKG)
|
|
28
|
+
return;
|
|
29
|
+
if (typeof info?.version === "string" && info.version) {
|
|
30
|
+
out.push({ path: pjPath, version: info.version });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch { }
|
|
34
|
+
}
|
|
35
|
+
/** 探测 PATH 上的 pi 可执行文件反推其包根(issue #559, #562)。 */
|
|
36
|
+
function scanPathForPi(out, env = process.env) {
|
|
37
|
+
const rawPath = env.PATH || "";
|
|
38
|
+
if (!rawPath)
|
|
39
|
+
return;
|
|
40
|
+
const dirs = rawPath.split(delimiter).filter(Boolean);
|
|
41
|
+
const isWin = process.platform === "win32";
|
|
42
|
+
const names = isWin ? ["pi.cmd", "pi.exe", "pi.ps1", "pi"] : ["pi"];
|
|
43
|
+
for (const dir of dirs) {
|
|
44
|
+
for (const name of names) {
|
|
45
|
+
const candidate = join(dir, name);
|
|
46
|
+
if (!existsSync(candidate))
|
|
47
|
+
continue;
|
|
48
|
+
// 1. 尝试 realpathSync 解析符号链接(Unix 下 npm/pnpm 全局 bin 标准布局)
|
|
49
|
+
try {
|
|
50
|
+
const real = realpathSync(candidate);
|
|
51
|
+
let cur = dirname(real);
|
|
52
|
+
for (let i = 0; i < 5; i++) {
|
|
53
|
+
const pj = join(cur, "package.json");
|
|
54
|
+
addCopy(pj, out, true);
|
|
55
|
+
const parent = dirname(cur);
|
|
56
|
+
if (parent === cur)
|
|
57
|
+
break;
|
|
58
|
+
cur = parent;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch { }
|
|
62
|
+
// 2. 检查常见同级/相对 node_modules 目录(Windows npm 全局 bin 同级 node_modules 等)
|
|
63
|
+
addCopy(join(dir, "node_modules", PKG, "package.json"), out);
|
|
64
|
+
addCopy(join(dir, "..", "lib", "node_modules", PKG, "package.json"), out);
|
|
65
|
+
addCopy(join(dir, "..", "node_modules", PKG, "package.json"), out);
|
|
66
|
+
// 3. 脚本包装内容解析(Windows 下 .cmd / .ps1 或 Unix 下 shell 包装脚本)
|
|
67
|
+
try {
|
|
68
|
+
const head = readFileSync(candidate, "utf8").slice(0, 4096);
|
|
69
|
+
const m = head.match(/[^\r\n"']*@earendil-works[/\\]pi-coding-agent[^\r\n"']*/);
|
|
70
|
+
if (m) {
|
|
71
|
+
let matchedPath = m[0].trim().replace(/%~?dp0%?[/\\]/gi, "");
|
|
72
|
+
let targetDir = isAbsolute(matchedPath) ? matchedPath : join(dir, matchedPath);
|
|
73
|
+
for (let i = 0; i < 5; i++) {
|
|
74
|
+
const pj = join(targetDir, "package.json");
|
|
75
|
+
addCopy(pj, out, true);
|
|
76
|
+
const parent = dirname(targetDir);
|
|
77
|
+
if (parent === targetDir)
|
|
78
|
+
break;
|
|
79
|
+
targetDir = parent;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch { }
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** 探测 npm / pnpm 全局 prefix 目录(issue #559)。 */
|
|
88
|
+
function scanGlobalPrefixes(out, env = process.env) {
|
|
89
|
+
const home = env.HOME || env.USERPROFILE || "";
|
|
90
|
+
// 1. npm_config_prefix / PREFIX
|
|
91
|
+
const prefix = env.npm_config_prefix || env.PREFIX;
|
|
92
|
+
if (prefix) {
|
|
93
|
+
addCopy(join(prefix, "lib", "node_modules", PKG, "package.json"), out);
|
|
94
|
+
addCopy(join(prefix, "node_modules", PKG, "package.json"), out);
|
|
95
|
+
}
|
|
96
|
+
// 2. 用户级 npm 全局 (~/.npm-global, %APPDATA%\npm)
|
|
97
|
+
if (home) {
|
|
98
|
+
addCopy(join(home, ".npm-global", "lib", "node_modules", PKG, "package.json"), out);
|
|
99
|
+
addCopy(join(home, ".npm-global", "node_modules", PKG, "package.json"), out);
|
|
100
|
+
}
|
|
101
|
+
if (env.APPDATA) {
|
|
102
|
+
addCopy(join(env.APPDATA, "npm", "node_modules", PKG, "package.json"), out);
|
|
103
|
+
}
|
|
104
|
+
// 3. POSIX 系统级 npm 全局
|
|
105
|
+
if (process.platform !== "win32") {
|
|
106
|
+
addCopy(join("/usr", "local", "lib", "node_modules", PKG, "package.json"), out);
|
|
107
|
+
addCopy(join("/usr", "lib", "node_modules", PKG, "package.json"), out);
|
|
108
|
+
}
|
|
109
|
+
// 4. pnpm 全局目录 (PNPM_HOME, ~/.local/share/pnpm/global, %LOCALAPPDATA%\pnpm\global)
|
|
110
|
+
if (env.PNPM_HOME) {
|
|
111
|
+
addCopy(join(env.PNPM_HOME, "node_modules", PKG, "package.json"), out);
|
|
112
|
+
addCopy(join(env.PNPM_HOME, "global", "node_modules", PKG, "package.json"), out);
|
|
113
|
+
}
|
|
114
|
+
if (home) {
|
|
115
|
+
addCopy(join(home, ".local", "share", "pnpm", "global", "node_modules", PKG, "package.json"), out);
|
|
116
|
+
}
|
|
117
|
+
if (env.LOCALAPPDATA) {
|
|
118
|
+
addCopy(join(env.LOCALAPPDATA, "pnpm", "global", "node_modules", PKG, "package.json"), out);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** 从某个文件出发,逐级向上查找 `<dir>/node_modules/<pkg>/package.json`,
|
|
122
|
+
* 并探测系统/全局已安装的 pi SDK 副本(issue #260, #321, #559, #562)。
|
|
19
123
|
* `fromFile` 收 URL(`import.meta.url`)或普通文件路径(便于单测)。 */
|
|
20
|
-
export function sdkCopies(fromFile = import.meta.url) {
|
|
124
|
+
export function sdkCopies(fromFile = import.meta.url, options = {}) {
|
|
125
|
+
const env = options.env ?? process.env;
|
|
126
|
+
const includeGlobal = options.includeGlobal ?? (options.env ? true : !process.env.VITEST);
|
|
21
127
|
const out = [];
|
|
22
128
|
let dir = dirname(fromFile.startsWith("file:") ? fileURLToPath(fromFile) : fromFile);
|
|
23
129
|
for (;;) {
|
|
24
130
|
const pj = join(dir, "node_modules", PKG, "package.json");
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
const version = JSON.parse(readFileSync(pj, "utf8")).version;
|
|
28
|
-
if (typeof version === "string" && version)
|
|
29
|
-
out.push({ path: pj, version });
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
// 坏 JSON:跳过这一份,不影响其它候选(best-effort,同 process-utils 的口径)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
131
|
+
addCopy(pj, out);
|
|
35
132
|
const parent = dirname(dir);
|
|
36
133
|
if (parent === dir)
|
|
37
134
|
break;
|
|
38
135
|
dir = parent;
|
|
39
136
|
}
|
|
40
137
|
// 显式透传的宿主 SDK 路径(如 extensions/webui.ts 宿主传递,issue #482)
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
if (existsSync(pj) && !out.some((c) => c.path === pj)) {
|
|
44
|
-
try {
|
|
45
|
-
const version = JSON.parse(readFileSync(pj, "utf8")).version;
|
|
46
|
-
if (typeof version === "string" && version) {
|
|
47
|
-
out.push({ path: pj, version });
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
catch { }
|
|
51
|
-
}
|
|
138
|
+
if (env.PI_WEB_SDK_DIR) {
|
|
139
|
+
addCopy(join(env.PI_WEB_SDK_DIR, "package.json"), out);
|
|
52
140
|
}
|
|
53
141
|
// 宿主 Pi Node 路径探测(~/.local/share/pi-node/current/...,issue #482)
|
|
54
|
-
const home =
|
|
142
|
+
const home = env.HOME || env.USERPROFILE;
|
|
55
143
|
if (home) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
catch { }
|
|
65
|
-
}
|
|
144
|
+
addCopy(join(home, ".local", "share", "pi-node", "current", "lib", "node_modules", PKG, "package.json"), out);
|
|
145
|
+
}
|
|
146
|
+
if (includeGlobal) {
|
|
147
|
+
// PATH 上的 pi 可执行文件反推(issue #559)
|
|
148
|
+
scanPathForPi(out, env);
|
|
149
|
+
// npm / pnpm 全局 prefix 目录探测(issue #559)
|
|
150
|
+
scanGlobalPrefixes(out, env);
|
|
66
151
|
}
|
|
67
152
|
return out;
|
|
68
153
|
}
|
|
@@ -85,7 +170,10 @@ export function compareVersions(a, b) {
|
|
|
85
170
|
* (如部分桌面/容器布局)时按自带算 —— 那本来就是唯一能加载的份。
|
|
86
171
|
* UI 用它决定是否亮「安装全局引擎并切换」入口(issue #321)。
|
|
87
172
|
*/
|
|
88
|
-
export function isBundledInUse(copies, effectiveVersion) {
|
|
173
|
+
export function isBundledInUse(copies, effectiveVersion, bundledCopy) {
|
|
174
|
+
if (bundledCopy !== undefined) {
|
|
175
|
+
return bundledCopy !== null && effectiveVersion === bundledCopy.version;
|
|
176
|
+
}
|
|
89
177
|
return copies.length === 0 || effectiveVersion === copies[0].version;
|
|
90
178
|
}
|
|
91
179
|
/**
|
|
@@ -9,13 +9,16 @@
|
|
|
9
9
|
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
10
10
|
import { basename, dirname, join } from "node:path";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
|
-
import { extensionKey, normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeSkillList, normalizeToolWatchdogTimeoutMs, normalizeUiLayout, } from "./client-state.js";
|
|
12
|
+
import { extensionKey, normalizeBgCleanupMinutes, normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeSkillList, normalizeToolWatchdogTimeoutMs, normalizeUiLayout, settingsPresetToUi, } from "./client-state.js";
|
|
13
13
|
import { normalizeSoftCapByModel, normalizeSoftCapTokens } from "./soft-cap.js";
|
|
14
14
|
import { findVisionModels, SYSTEM_PROMPT } from "./vision-bridge.js";
|
|
15
15
|
import { COMMITMSG_SYSTEM_PROMPT } from "./scm-commitmsg.js";
|
|
16
16
|
import { PLAN_MODE_SYSTEM_PROMPT } from "./plan-mode.js";
|
|
17
17
|
import { DEFAULT_TEMPLATES } from "./subagent-templates.js";
|
|
18
18
|
import { deriveLegacy, foldLegacyIntoDisabled, normalizeDisabledAgentTools } from "./tool-manager.js";
|
|
19
|
+
import { normalizeToolPromptOverrides } from "./tool-prompt-overrides.js";
|
|
20
|
+
import { resolveServerLang } from "./i18n.js";
|
|
21
|
+
import { exportPresetVia, importPresetFromUrlVia, importPresetVia, packageVersion, pushPresetCatalogVia, sharePresetVia, } from "./preset-share.js";
|
|
19
22
|
export class SettingsService {
|
|
20
23
|
host;
|
|
21
24
|
templates;
|
|
@@ -283,6 +286,7 @@ export class SettingsService {
|
|
|
283
286
|
customSystemPrompt: this.settings.customSystemPrompt,
|
|
284
287
|
promptTemplate: this.settings.promptTemplate ?? "",
|
|
285
288
|
promptOverrides: { ...this.settings.promptOverrides },
|
|
289
|
+
toolPromptOverrides: { ...this.settings.toolPromptOverrides },
|
|
286
290
|
disabledAgentTools: [...normalizeDisabledAgentTools(this.settings.disabledAgentTools)],
|
|
287
291
|
disabledPluginTools: [...normalizeDisabledPluginTools(this.settings.disabledPluginTools)],
|
|
288
292
|
terminalToolsEnabled: legacyTools.terminalToolsEnabled,
|
|
@@ -291,6 +295,8 @@ export class SettingsService {
|
|
|
291
295
|
terminalBashMaxForegroundMs: this.settings.terminalBashMaxForegroundMs,
|
|
292
296
|
toolWatchdogTimeoutMs: this.settings.toolWatchdogTimeoutMs,
|
|
293
297
|
readDirEnabled: this.settings.readDirEnabled !== false,
|
|
298
|
+
bgAutoCleanupMin: normalizeBgCleanupMinutes(this.settings.bgAutoCleanupMin),
|
|
299
|
+
toolLazyLoading: this.settings.toolLazyLoading !== false,
|
|
294
300
|
toolApprovalEnabled: this.settings.toolApprovalEnabled !== false,
|
|
295
301
|
approvalPolicy: this.host.getApprovalPolicy?.() ?? { allowAll: false, categories: [] },
|
|
296
302
|
approvalRules: this.approvalRules?.list() ?? [],
|
|
@@ -331,7 +337,7 @@ export class SettingsService {
|
|
|
331
337
|
skills,
|
|
332
338
|
reviewSkills,
|
|
333
339
|
extensions,
|
|
334
|
-
presets: this.presets.map(
|
|
340
|
+
presets: this.presets.map(settingsPresetToUi),
|
|
335
341
|
...(this.host.getMarkerState
|
|
336
342
|
? this.host.getMarkerState()
|
|
337
343
|
: {
|
|
@@ -405,7 +411,9 @@ export class SettingsService {
|
|
|
405
411
|
partial.disabledPlugins !== undefined ||
|
|
406
412
|
partial.terminalToolsEnabled !== undefined ||
|
|
407
413
|
partial.editSoftEnabled !== undefined ||
|
|
408
|
-
partial.questionnaireEnabled !== undefined
|
|
414
|
+
partial.questionnaireEnabled !== undefined ||
|
|
415
|
+
partial.toolPromptOverrides !== undefined ||
|
|
416
|
+
partial.toolLazyLoading !== undefined;
|
|
409
417
|
if (partial.promptMode !== undefined)
|
|
410
418
|
this.settings.promptMode = partial.promptMode;
|
|
411
419
|
if (partial.customSystemPrompt !== undefined) {
|
|
@@ -425,6 +433,18 @@ export class SettingsService {
|
|
|
425
433
|
}
|
|
426
434
|
this.settings.promptOverrides = next;
|
|
427
435
|
}
|
|
436
|
+
if (partial.toolPromptOverrides !== undefined) {
|
|
437
|
+
// 逐工具合并:给出的键整体替换(归一化后为空 = 清除该工具覆盖)。
|
|
438
|
+
const next = { ...this.settings.toolPromptOverrides };
|
|
439
|
+
const normalized = normalizeToolPromptOverrides(partial.toolPromptOverrides);
|
|
440
|
+
for (const key of Object.keys(partial.toolPromptOverrides)) {
|
|
441
|
+
if (normalized[key])
|
|
442
|
+
next[key] = normalized[key];
|
|
443
|
+
else
|
|
444
|
+
delete next[key];
|
|
445
|
+
}
|
|
446
|
+
this.settings.toolPromptOverrides = normalizeToolPromptOverrides(next);
|
|
447
|
+
}
|
|
428
448
|
if (partial.disabledSkills !== undefined) {
|
|
429
449
|
this.settings.disabledSkills = partial.disabledSkills;
|
|
430
450
|
}
|
|
@@ -478,6 +498,16 @@ export class SettingsService {
|
|
|
478
498
|
if (partial.readDirEnabled !== undefined) {
|
|
479
499
|
this.settings.readDirEnabled = partial.readDirEnabled;
|
|
480
500
|
}
|
|
501
|
+
// 「后台任务」自动清理阈值(分钟;0 = 关):bg-servers 的定时器每轮实时读,即时生效。
|
|
502
|
+
if (partial.bgAutoCleanupMin !== undefined) {
|
|
503
|
+
this.settings.bgAutoCleanupMin = normalizeBgCleanupMinutes(partial.bgAutoCleanupMin);
|
|
504
|
+
}
|
|
505
|
+
// 工具延迟加载开关(默认开):门控每次实时读取,改动经 applyToolGating 重放生效
|
|
506
|
+
// (见 toolGatingChanged)——**只影响新会话与之后的门控重放**,已有对话的已加载
|
|
507
|
+
// 集合不会被反向清空(不想让在跑的对话凭空丢掉工具)。
|
|
508
|
+
if (partial.toolLazyLoading !== undefined) {
|
|
509
|
+
this.settings.toolLazyLoading = partial.toolLazyLoading !== false;
|
|
510
|
+
}
|
|
481
511
|
// 工具执行审批总开关:审批入口每次实时读取(askApproval 顶部门禁),无需 reload。
|
|
482
512
|
if (partial.toolApprovalEnabled !== undefined) {
|
|
483
513
|
this.settings.toolApprovalEnabled = partial.toolApprovalEnabled;
|
|
@@ -588,7 +618,7 @@ export class SettingsService {
|
|
|
588
618
|
if (needsReload)
|
|
589
619
|
await this.applyRuntime();
|
|
590
620
|
}
|
|
591
|
-
/**
|
|
621
|
+
/** 保存当前设置为命名预设(同名覆盖)。 */
|
|
592
622
|
async savePreset(name) {
|
|
593
623
|
const n = name.trim();
|
|
594
624
|
if (!n) {
|
|
@@ -600,28 +630,7 @@ export class SettingsService {
|
|
|
600
630
|
});
|
|
601
631
|
return;
|
|
602
632
|
}
|
|
603
|
-
const preset =
|
|
604
|
-
name: n,
|
|
605
|
-
promptMode: this.settings.promptMode,
|
|
606
|
-
customSystemPrompt: this.settings.customSystemPrompt,
|
|
607
|
-
promptTemplate: this.settings.promptTemplate ?? "",
|
|
608
|
-
promptOverrides: { ...this.settings.promptOverrides },
|
|
609
|
-
disabledSkills: [...this.settings.disabledSkills],
|
|
610
|
-
disabledExtensions: [...this.settings.disabledExtensions],
|
|
611
|
-
disabledAgentTools: [...normalizeDisabledAgentTools(this.settings.disabledAgentTools)],
|
|
612
|
-
disabledPluginTools: [...normalizeDisabledPluginTools(this.settings.disabledPluginTools)],
|
|
613
|
-
terminalToolsEnabled: this.settings.terminalToolsEnabled,
|
|
614
|
-
terminalBash: this.settings.terminalBash,
|
|
615
|
-
terminalBashIdleMs: this.settings.terminalBashIdleMs,
|
|
616
|
-
terminalBashMaxForegroundMs: this.settings.terminalBashMaxForegroundMs,
|
|
617
|
-
editSoftEnabled: this.settings.editSoftEnabled,
|
|
618
|
-
retryMaxAttempts: this.settings.retryMaxAttempts,
|
|
619
|
-
softCapTokens: this.settings.softCapTokens,
|
|
620
|
-
softCapByModel: { ...this.settings.softCapByModel },
|
|
621
|
-
reviewPrompt: this.settings.reviewPrompt,
|
|
622
|
-
reviewDisabledSkills: [...this.settings.reviewDisabledSkills],
|
|
623
|
-
skillsFullText: [...normalizeSkillList(this.settings.skillsFullText)],
|
|
624
|
-
};
|
|
633
|
+
const preset = this.snapshotPreset(n);
|
|
625
634
|
const existing = this.presets.findIndex((p) => p.name === n);
|
|
626
635
|
if (existing >= 0)
|
|
627
636
|
this.presets[existing] = preset;
|
|
@@ -630,6 +639,13 @@ export class SettingsService {
|
|
|
630
639
|
this.host.stateStore.savePresets(this.host.clientId, this.presets);
|
|
631
640
|
this.push();
|
|
632
641
|
}
|
|
642
|
+
/** 把当前设置快照成一条预设(名字由调用方给定)。
|
|
643
|
+
* **全量**:`ClientSettings` 的每个字段都进预设(字段清单/分组见 `server/preset-fields.ts`),
|
|
644
|
+
* 导出/分享/导入共用同一张白名单;深层对象做一份拷贝,避免与当前设置共享引用。 */
|
|
645
|
+
snapshotPreset(name) {
|
|
646
|
+
const s = structuredClone(this.settings);
|
|
647
|
+
return { ...s, name };
|
|
648
|
+
}
|
|
633
649
|
/** Replace the current settings with the named preset and apply it. */
|
|
634
650
|
async applyPreset(name) {
|
|
635
651
|
const p = this.presets.find((x) => x.name === name);
|
|
@@ -642,74 +658,27 @@ export class SettingsService {
|
|
|
642
658
|
});
|
|
643
659
|
return;
|
|
644
660
|
}
|
|
645
|
-
//
|
|
646
|
-
// 从当前禁用名单继承,即保留当前问卷状态)。
|
|
661
|
+
// 统一工具开关:新预设直接用它;旧预设(只有遗留两开关)按当前禁用名单折算。
|
|
647
662
|
const presetDisabled = normalizeDisabledAgentTools(p.disabledAgentTools ??
|
|
648
663
|
foldLegacyIntoDisabled(this.settings.disabledAgentTools ?? [], {
|
|
649
664
|
terminalToolsEnabled: p.terminalToolsEnabled,
|
|
650
665
|
editSoftEnabled: p.editSoftEnabled,
|
|
651
666
|
}));
|
|
652
667
|
const presetLegacy = deriveLegacy(presetDisabled);
|
|
668
|
+
// 全量预设 = 当前设置叠加预设里**实际存在**的字段(缺字段保持当前值)。
|
|
669
|
+
// 旧预设(19 字段)、以及导入时只勾了一部分的预设,都靠这个 merge 落地。
|
|
670
|
+
const patch = { ...p };
|
|
671
|
+
delete patch.name;
|
|
672
|
+
for (const k of Object.keys(patch))
|
|
673
|
+
if (patch[k] === undefined)
|
|
674
|
+
delete patch[k];
|
|
653
675
|
this.settings = {
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
promptOverrides: { ...(p.promptOverrides ?? this.settings.promptOverrides) },
|
|
658
|
-
disabledSkills: [...p.disabledSkills],
|
|
659
|
-
disabledExtensions: [...p.disabledExtensions],
|
|
676
|
+
...this.settings,
|
|
677
|
+
...patch,
|
|
678
|
+
// 工具开关与两个遗留别名以派生结果为准(单源:disabledAgentTools)。
|
|
660
679
|
disabledAgentTools: presetDisabled,
|
|
661
|
-
disabledPluginTools: normalizeDisabledPluginTools(p.disabledPluginTools ?? this.settings.disabledPluginTools),
|
|
662
680
|
terminalToolsEnabled: presetLegacy.terminalToolsEnabled,
|
|
663
|
-
// 终端接管偏好随预设走;旧预设缺字段时保留当前值。
|
|
664
|
-
terminalBash: p.terminalBash ?? this.settings.terminalBash,
|
|
665
|
-
terminalBashIdleMs: p.terminalBashIdleMs ?? this.settings.terminalBashIdleMs,
|
|
666
|
-
terminalBashMaxForegroundMs: p.terminalBashMaxForegroundMs ?? this.settings.terminalBashMaxForegroundMs,
|
|
667
|
-
// read 读目录是纯运行行为开关,不进预设——保留当前值。
|
|
668
|
-
readDirEnabled: this.settings.readDirEnabled !== false,
|
|
669
|
-
// 工具审批总开关同样是纯运行开关,不进预设——保留当前值。
|
|
670
|
-
toolApprovalEnabled: this.settings.toolApprovalEnabled !== false,
|
|
671
|
-
// toolWatchdogTimeoutMs 是纯运行行为参数,不进预设——保留当前值。
|
|
672
|
-
toolWatchdogTimeoutMs: this.settings.toolWatchdogTimeoutMs,
|
|
673
681
|
editSoftEnabled: presetLegacy.editSoftEnabled,
|
|
674
|
-
// 重试次数随预设走;旧预设缺字段时保留当前值,应用后即时注入各会话。
|
|
675
|
-
retryMaxAttempts: p.retryMaxAttempts ?? this.settings.retryMaxAttempts,
|
|
676
|
-
// 压缩软上限同样随预设走(issue #229);旧预设缺字段时保留当前值。
|
|
677
|
-
softCapTokens: normalizeSoftCapTokens(p.softCapTokens ?? this.settings.softCapTokens),
|
|
678
|
-
softCapByModel: normalizeSoftCapByModel(p.softCapByModel ?? this.settings.softCapByModel),
|
|
679
|
-
// 问卷开关不进预设——保留当前值。
|
|
680
|
-
questionnaireEnabled: this.settings.questionnaireEnabled,
|
|
681
|
-
// 同项目并行提醒开关不进预设——保留当前值。
|
|
682
|
-
parallelReminderEnabled: this.settings.parallelReminderEnabled ?? true,
|
|
683
|
-
// 目标模式总开关不进预设——保留当前值。
|
|
684
|
-
goalModeEnabled: this.settings.goalModeEnabled,
|
|
685
|
-
reviewPrompt: p.reviewPrompt ?? this.settings.reviewPrompt,
|
|
686
|
-
reviewDisabledSkills: [...(p.reviewDisabledSkills ?? this.settings.reviewDisabledSkills)],
|
|
687
|
-
// 全文注入名单随预设走;旧预设缺字段时保留当前值。
|
|
688
|
-
skillsFullText: normalizeSkillList(p.skillsFullText ?? this.settings.skillsFullText),
|
|
689
|
-
// 纯 UI 偏好不进预设——保留当前值。
|
|
690
|
-
devNoCache: this.settings.devNoCache,
|
|
691
|
-
autoReload: this.settings.autoReload,
|
|
692
|
-
thinkingWrap: this.settings.thinkingWrap,
|
|
693
|
-
toolsWrap: this.settings.toolsWrap,
|
|
694
|
-
toolImagesEnabled: this.settings.toolImagesEnabled ?? true,
|
|
695
|
-
// UI 布局偏好也不进预设——保留当前值。
|
|
696
|
-
uiLayout: normalizeUiLayout(this.settings.uiLayout),
|
|
697
|
-
// Presets don't capture vision-bridge prefs — keep the current ones.
|
|
698
|
-
visionBridgeEnabled: this.settings.visionBridgeEnabled,
|
|
699
|
-
visionBridgeModel: this.settings.visionBridgeModel,
|
|
700
|
-
visionBridgePromptMode: this.settings.visionBridgePromptMode,
|
|
701
|
-
visionBridgePrompt: this.settings.visionBridgePrompt,
|
|
702
|
-
// 「AI 提交信息」提示词同样不进预设——保留当前值。
|
|
703
|
-
scmCommitMsgPromptMode: this.settings.scmCommitMsgPromptMode,
|
|
704
|
-
scmCommitMsgPrompt: this.settings.scmCommitMsgPrompt,
|
|
705
|
-
// 计划模式提示词同样不进预设——保留当前值。
|
|
706
|
-
planModePromptMode: this.settings.planModePromptMode,
|
|
707
|
-
planModePrompt: this.settings.planModePrompt,
|
|
708
|
-
// 子代理默认模型也不进预设——保留当前值。
|
|
709
|
-
subagentDefaultModel: this.settings.subagentDefaultModel,
|
|
710
|
-
// 快捷短语是纯 UI 偏好,不进预设——保留当前值。
|
|
711
|
-
quickPhrases: [...this.settings.quickPhrases],
|
|
712
|
-
quickPhrasesEnabled: this.settings.quickPhrasesEnabled,
|
|
713
682
|
};
|
|
714
683
|
this.host.stateStore.saveSettings(this.host.clientId, this.settings);
|
|
715
684
|
// 预设可能改了重试次数:即时注入(流式中延迟的 reload 之后还会由调用方重放)。
|
|
@@ -725,6 +694,56 @@ export class SettingsService {
|
|
|
725
694
|
this.host.stateStore.savePresets(this.host.clientId, this.presets);
|
|
726
695
|
this.push();
|
|
727
696
|
}
|
|
697
|
+
/* ---------------------------------------------------------------- */
|
|
698
|
+
/* 预设分享:导出 / 导入 / 分享 / 社区目录(server/preset-share.ts) */
|
|
699
|
+
/* ---------------------------------------------------------------- */
|
|
700
|
+
/** 当前客户端语言(服务端文案用;与 agent-service 同源)。 */
|
|
701
|
+
get lang() {
|
|
702
|
+
return resolveServerLang(this.host.stateStore.get(this.host.clientId).locale);
|
|
703
|
+
}
|
|
704
|
+
/** 分享编排(server/preset-share.ts)需要的最小能力集合。 */
|
|
705
|
+
sharePort() {
|
|
706
|
+
return {
|
|
707
|
+
lang: () => this.lang,
|
|
708
|
+
appVersion: () => packageVersion(),
|
|
709
|
+
presets: () => this.presets,
|
|
710
|
+
currentSettings: () => {
|
|
711
|
+
const { name: _drop, ...rest } = this.snapshotPreset("");
|
|
712
|
+
return { ...rest };
|
|
713
|
+
},
|
|
714
|
+
upsertPreset: (preset) => {
|
|
715
|
+
const i = this.presets.findIndex((p) => p.name === preset.name);
|
|
716
|
+
if (i >= 0)
|
|
717
|
+
this.presets[i] = preset;
|
|
718
|
+
else
|
|
719
|
+
this.presets.push(preset);
|
|
720
|
+
this.host.stateStore.savePresets(this.host.clientId, this.presets);
|
|
721
|
+
},
|
|
722
|
+
applyPreset: (name) => this.applyPreset(name),
|
|
723
|
+
pushSettings: () => this.push(),
|
|
724
|
+
emit: (msg) => this.host.emit(msg),
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
/** 导出预设(name 命名的预设)或当前设置(source=current)为 JSON 文本。 */
|
|
728
|
+
async exportPreset(msg) {
|
|
729
|
+
exportPresetVia(this.sharePort(), msg);
|
|
730
|
+
}
|
|
731
|
+
/** 解析导入的预设 JSON:dryRun = 只回预览(不落盘);apply = 导入后立即应用。 */
|
|
732
|
+
async importPreset(msg) {
|
|
733
|
+
await importPresetVia(this.sharePort(), msg);
|
|
734
|
+
}
|
|
735
|
+
/** 按网址导入(服务端抓取:避开浏览器 CORS;内网地址已拦截)。 */
|
|
736
|
+
async importPresetFromUrl(msg) {
|
|
737
|
+
await importPresetFromUrlVia(this.sharePort(), msg);
|
|
738
|
+
}
|
|
739
|
+
/** 一键分享到社区共享仓库(gh issue create;gh 不可用时回落预填网页)。 */
|
|
740
|
+
async sharePreset(msg) {
|
|
741
|
+
await sharePresetVia(this.sharePort(), msg);
|
|
742
|
+
}
|
|
743
|
+
/** 拉社区共享目录(5 分钟缓存;失败保留上一次成功的列表)。 */
|
|
744
|
+
async pushPresetCatalog(msg) {
|
|
745
|
+
await pushPresetCatalogVia(this.sharePort(), msg);
|
|
746
|
+
}
|
|
728
747
|
/** Upsert 一个子代理模板(全局共享)。模板只影响未来派生的子代理,
|
|
729
748
|
* 不需要 reload runtime —— 直接推送新设置状态即可。 */
|
|
730
749
|
async saveTemplate(template) {
|
|
@@ -61,10 +61,9 @@ export function makeSkillTool(host, lang) {
|
|
|
61
61
|
return defineTool({
|
|
62
62
|
name: SKILL_TOOL_NAME,
|
|
63
63
|
label: "Load a skill",
|
|
64
|
-
description: "Load a skill's full text by its exact name (see the <available_skills> catalog
|
|
65
|
-
"Prefer this over reading the skill file with
|
|
66
|
-
|
|
67
|
-
promptSnippet: "load a skill's full text by name (skill tool, preferred over read)",
|
|
64
|
+
description: "Load a skill's full text by its exact name (see the <available_skills> catalog). " +
|
|
65
|
+
"Prefer this over reading the skill file with read — no path guessing.",
|
|
66
|
+
promptSnippet: "use a skill from <available_skills> by name",
|
|
68
67
|
parameters: Type.Object({
|
|
69
68
|
name: Type.Optional(Type.String({
|
|
70
69
|
description: "Exact skill name from the catalog. Omit to list the current catalog.",
|
package/dist/server/subagents.js
CHANGED
|
@@ -107,16 +107,9 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
107
107
|
return defineTool({
|
|
108
108
|
name: SUBAGENT_TOOL_NAME,
|
|
109
109
|
label: "Subagent manager",
|
|
110
|
-
description: "Manage background subagent conversations for parallel delegation, research, and execution.
|
|
111
|
-
"
|
|
112
|
-
|
|
113
|
-
"- `steer`: inject a `message` into a running subagent with `runId`.\n" +
|
|
114
|
-
"- `list`: list managed subagents (optional `kind`).\n" +
|
|
115
|
-
"- `stop`: abort a running subagent with `runId`.\n" +
|
|
116
|
-
"- `wait_all`: block until subagents finish (optional `runIds`, `timeoutSeconds`).\n" +
|
|
117
|
-
"- `templates`: list available subagent templates.\n" +
|
|
118
|
-
"- `handoff`: transfer `payload` to peer subagent with `toRunId` (optional `fromRunId`).",
|
|
119
|
-
promptSnippet: "manage background subagents: spawn, get_result, steer, list, stop, wait_all, templates, handoff",
|
|
110
|
+
description: "Manage background subagent conversations for parallel delegation, research, and execution. " +
|
|
111
|
+
"Each action's arguments are documented on the parameters below.",
|
|
112
|
+
promptSnippet: "manage background subagents (spawn/steer/wait/templates)",
|
|
120
113
|
parameters: Type.Object({
|
|
121
114
|
action: Type.Unsafe({
|
|
122
115
|
type: "string",
|
|
@@ -124,47 +117,47 @@ export function makeSubagentTool(host, lang, selfConvId) {
|
|
|
124
117
|
description: "The subagent action to perform.",
|
|
125
118
|
}),
|
|
126
119
|
prompt: Type.Optional(Type.String({
|
|
127
|
-
description: "spawn: instructions
|
|
120
|
+
description: "spawn: instructions (goal, constraints, expected output).",
|
|
128
121
|
})),
|
|
129
122
|
runId: Type.Optional(Type.String({
|
|
130
|
-
description: "get_result/steer/stop: target
|
|
123
|
+
description: "get_result/steer/stop: target conversation ID.",
|
|
131
124
|
})),
|
|
132
125
|
runIds: Type.Optional(Type.Array(Type.String(), {
|
|
133
|
-
description: "wait_all:
|
|
126
|
+
description: "wait_all: conversation IDs to wait for (omit = all active).",
|
|
134
127
|
})),
|
|
135
128
|
message: Type.Optional(Type.String({
|
|
136
|
-
description: "steer: follow-up instruction
|
|
129
|
+
description: "steer: follow-up instruction.",
|
|
137
130
|
})),
|
|
138
131
|
payload: Type.Optional(Type.String({
|
|
139
|
-
description: "handoff:
|
|
132
|
+
description: "handoff: what to transfer to the peer.",
|
|
140
133
|
})),
|
|
141
134
|
toRunId: Type.Optional(Type.String({
|
|
142
|
-
description: "handoff: target peer
|
|
135
|
+
description: "handoff: target peer ID.",
|
|
143
136
|
})),
|
|
144
137
|
fromRunId: Type.Optional(Type.String({
|
|
145
|
-
description: "handoff: source
|
|
138
|
+
description: "handoff: source ID (default = this subagent).",
|
|
146
139
|
})),
|
|
147
140
|
type: Type.Optional(Type.String({
|
|
148
|
-
description: "spawn: role/type
|
|
141
|
+
description: "spawn: role/type (e.g. explore/implement/review, default: general).",
|
|
149
142
|
})),
|
|
150
143
|
template: Type.Optional(Type.String({
|
|
151
|
-
description: "spawn:
|
|
144
|
+
description: "spawn: template name (see action=templates).",
|
|
152
145
|
})),
|
|
153
146
|
model: Type.Optional(Type.String({
|
|
154
147
|
description: 'spawn: model override "provider/id".',
|
|
155
148
|
})),
|
|
156
149
|
cwd: Type.Optional(Type.String({
|
|
157
|
-
description: "spawn: working directory (
|
|
150
|
+
description: "spawn: working directory (default = current).",
|
|
158
151
|
})),
|
|
159
152
|
persist: Type.Optional(Type.Boolean({
|
|
160
|
-
description: "spawn: persist as a regular session
|
|
153
|
+
description: "spawn: persist as a regular session (default = ephemeral).",
|
|
161
154
|
})),
|
|
162
155
|
kind: Type.Optional(Type.String({
|
|
163
156
|
enum: ["all", "subagent", "persistent"],
|
|
164
157
|
description: "list: filter subagents by kind (default: all).",
|
|
165
158
|
})),
|
|
166
159
|
timeoutSeconds: Type.Optional(Type.Integer({
|
|
167
|
-
description: `wait_all: max wait in seconds (
|
|
160
|
+
description: `wait_all: max wait in seconds (default: ${capSeconds}s).`,
|
|
168
161
|
minimum: 1,
|
|
169
162
|
maximum: capSeconds,
|
|
170
163
|
})),
|