pi-web-ui 0.112.0 → 0.113.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 +38 -1
- package/bin/pi-web-ui.mjs +325 -45
- package/dist/server/agent-service-daemon.js +29 -4
- package/dist/server/agent-service.js +215 -35
- package/dist/server/canvas/canvas-agent-tool.js +2 -0
- package/dist/server/canvas/canvas-orchestrator.js +40 -1
- package/dist/server/canvas/pstack-skills-data.js +498 -0
- package/dist/server/dispatch-domain-handlers.js +36 -11
- package/dist/server/dsh/dsh-agent-service.js +52 -4
- package/dist/server/durable/durable-driver.js +37 -98
- package/dist/server/durable/durable-event-projector.js +253 -0
- package/dist/server/engine-probe.js +35 -11
- package/dist/server/index.js +67 -41
- package/dist/server/model-admin.js +185 -63
- package/dist/server/plugins.js +10 -6
- package/dist/server/remote-ssh-service.js +110 -12
- package/dist/server/serialize.js +1 -1
- package/dist/server/settings-service.js +36 -48
- package/dist/server/setup-page.js +632 -0
- package/dist/server/skill-discovery.js +361 -59
- package/dist/server/skill-maintenance.js +231 -0
- package/dist/server/skill-tool.js +32 -3
- package/dist/server/soft-cap.js +29 -7
- package/dist/server/subagents.js +246 -31
- package/dist/server/tool-host-factories.js +2 -0
- package/dist/server/tool-manager.js +106 -28
- package/dist/server/universal/drivers/claude-code.js +96 -4
- package/dist/server/universal/universal-session.js +19 -0
- package/package.json +1 -1
- package/plugins/catalog.json +10 -0
- package/web/dist/assets/{TerminalPanel-Dqr1dK28.js → TerminalPanel-3wojLfLk.js} +2 -2
- package/web/dist/assets/index-A8YXwnpZ.js +2008 -0
- package/web/dist/assets/index-BwL7qBh6.css +1 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-Dh8BX-lP.js +0 -720
- package/web/dist/assets/index-DqrC1I_a.css +0 -1
|
@@ -387,6 +387,9 @@ export class RemoteSshService {
|
|
|
387
387
|
}
|
|
388
388
|
}
|
|
389
389
|
get profilesFilePath() {
|
|
390
|
+
return path.join(this.dataDir, "global-hosts.json");
|
|
391
|
+
}
|
|
392
|
+
get legacyProfilesFilePath() {
|
|
390
393
|
return path.join(this.dataDir, "ssh-profiles.json");
|
|
391
394
|
}
|
|
392
395
|
async loadProfilesData() {
|
|
@@ -398,6 +401,16 @@ export class RemoteSshService {
|
|
|
398
401
|
return parsed;
|
|
399
402
|
}
|
|
400
403
|
}
|
|
404
|
+
else if (existsSync(this.legacyProfilesFilePath)) {
|
|
405
|
+
const content = await fs.readFile(this.legacyProfilesFilePath, "utf8");
|
|
406
|
+
const parsed = JSON.parse(content);
|
|
407
|
+
if (parsed && parsed.version === 1 && typeof parsed.profiles === "object") {
|
|
408
|
+
// 迁移到新的 global-hosts.json
|
|
409
|
+
await fs.mkdir(this.dataDir, { recursive: true });
|
|
410
|
+
await fs.writeFile(this.profilesFilePath, JSON.stringify(parsed, null, 2), "utf8");
|
|
411
|
+
return parsed;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
401
414
|
}
|
|
402
415
|
catch { }
|
|
403
416
|
return { version: 1, profiles: {} };
|
|
@@ -405,7 +418,10 @@ export class RemoteSshService {
|
|
|
405
418
|
async saveProfilesData(data) {
|
|
406
419
|
try {
|
|
407
420
|
await fs.mkdir(this.dataDir, { recursive: true });
|
|
408
|
-
|
|
421
|
+
const json = JSON.stringify(data, null, 2);
|
|
422
|
+
await fs.writeFile(this.profilesFilePath, json, "utf8");
|
|
423
|
+
// 同时保持旧文件同步(防止外部或旧调用方异常)
|
|
424
|
+
await fs.writeFile(this.legacyProfilesFilePath, json, "utf8").catch(() => { });
|
|
409
425
|
}
|
|
410
426
|
catch (err) {
|
|
411
427
|
console.error("[remote-ssh] 无法保存 profiles 文件:", err);
|
|
@@ -423,9 +439,41 @@ export class RemoteSshService {
|
|
|
423
439
|
authType: p.authType,
|
|
424
440
|
privateKeyPath: p.privateKeyPath,
|
|
425
441
|
lastConnected: p.lastConnected,
|
|
442
|
+
remotePath: p.remotePath,
|
|
443
|
+
description: p.description,
|
|
426
444
|
}))
|
|
427
445
|
.sort((a, b) => (b.lastConnected ?? 0) - (a.lastConnected ?? 0));
|
|
428
446
|
}
|
|
447
|
+
/** 获取解密后的 profile 凭据(仅供受信任的服务端内部模块使用) */
|
|
448
|
+
async getDecryptedProfile(name) {
|
|
449
|
+
const data = await this.loadProfilesData();
|
|
450
|
+
const p = data.profiles[name];
|
|
451
|
+
if (!p)
|
|
452
|
+
return null;
|
|
453
|
+
let password;
|
|
454
|
+
let passphrase;
|
|
455
|
+
if (p.authType === "password" && p.encryptedPassword) {
|
|
456
|
+
password = await this.unseal(p.encryptedPassword);
|
|
457
|
+
}
|
|
458
|
+
else if (p.authType === "key" && p.encryptedPassphrase) {
|
|
459
|
+
passphrase = await this.unseal(p.encryptedPassphrase);
|
|
460
|
+
}
|
|
461
|
+
return {
|
|
462
|
+
profile: {
|
|
463
|
+
name: p.name,
|
|
464
|
+
host: p.host,
|
|
465
|
+
port: p.port,
|
|
466
|
+
username: p.username,
|
|
467
|
+
authType: p.authType,
|
|
468
|
+
privateKeyPath: p.privateKeyPath,
|
|
469
|
+
lastConnected: p.lastConnected,
|
|
470
|
+
remotePath: p.remotePath,
|
|
471
|
+
description: p.description,
|
|
472
|
+
},
|
|
473
|
+
password,
|
|
474
|
+
passphrase,
|
|
475
|
+
};
|
|
476
|
+
}
|
|
429
477
|
/** 删除一个已保存的 profile */
|
|
430
478
|
async deleteProfile(name) {
|
|
431
479
|
const data = await this.loadProfilesData();
|
|
@@ -435,7 +483,7 @@ export class RemoteSshService {
|
|
|
435
483
|
}
|
|
436
484
|
}
|
|
437
485
|
/** 记录或更新一个 profile */
|
|
438
|
-
async saveProfile(name, params) {
|
|
486
|
+
async saveProfile(name, params, meta) {
|
|
439
487
|
const data = await this.loadProfilesData();
|
|
440
488
|
const existing = data.profiles[name];
|
|
441
489
|
const auth = params.auth;
|
|
@@ -447,6 +495,8 @@ export class RemoteSshService {
|
|
|
447
495
|
authType: auth.type,
|
|
448
496
|
privateKeyPath: auth.type === "key" ? auth.privateKeyPath : undefined,
|
|
449
497
|
lastConnected: Date.now(),
|
|
498
|
+
remotePath: meta?.remotePath ?? existing?.remotePath,
|
|
499
|
+
description: meta?.description ?? existing?.description,
|
|
450
500
|
};
|
|
451
501
|
if (auth.type === "password") {
|
|
452
502
|
if (auth.password) {
|
|
@@ -689,18 +739,30 @@ export class RemoteSshService {
|
|
|
689
739
|
async probe(params) {
|
|
690
740
|
let client;
|
|
691
741
|
let hydrated;
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
742
|
+
let conn;
|
|
743
|
+
const port = params.port ?? 22;
|
|
744
|
+
const hostKey = `${params.username}@${params.host}:${port}`;
|
|
745
|
+
const existingId = this.hostConnections.get(hostKey);
|
|
746
|
+
const existingConn = existingId ? this.connections.get(existingId) : undefined;
|
|
747
|
+
if (existingConn && existingConn.alive) {
|
|
748
|
+
conn = existingConn;
|
|
749
|
+
client = existingConn.client;
|
|
750
|
+
hydrated = existingConn.params;
|
|
696
751
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
752
|
+
else {
|
|
753
|
+
try {
|
|
754
|
+
const res = await this.createClient(params);
|
|
755
|
+
client = res.client;
|
|
756
|
+
hydrated = res.hydrated;
|
|
757
|
+
conn = this.registerConnection(client, hydrated);
|
|
758
|
+
}
|
|
759
|
+
catch (err) {
|
|
760
|
+
return {
|
|
761
|
+
ok: false,
|
|
762
|
+
error: err.message || String(err),
|
|
763
|
+
};
|
|
764
|
+
}
|
|
702
765
|
}
|
|
703
|
-
const conn = this.registerConnection(client, hydrated);
|
|
704
766
|
// 无论是否显式勾选,连接成功都持久化凭据以便打开远程工作区后能够跨请求/跨重启自动重连
|
|
705
767
|
if (params.saveProfile !== false) {
|
|
706
768
|
const pName = params.profileName?.trim() || `${hydrated.username}@${hydrated.host}`;
|
|
@@ -713,6 +775,8 @@ uname -m
|
|
|
713
775
|
uname -n
|
|
714
776
|
echo "$USER"
|
|
715
777
|
echo "$HOME"
|
|
778
|
+
(nproc 2>/dev/null || grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo "1")
|
|
779
|
+
(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo 2>/dev/null || free -m 2>/dev/null | awk '/Mem:/ {print $2}' || sysctl -n hw.memsize 2>/dev/null | awk '{print int($1/1024/1024)}' || echo "0")
|
|
716
780
|
echo "===GIT==="
|
|
717
781
|
which git 2>/dev/null && git --version 2>/dev/null || echo "NONE"
|
|
718
782
|
echo "===NODE==="
|
|
@@ -767,6 +831,8 @@ done
|
|
|
767
831
|
const hostname = sysLines[2] || "";
|
|
768
832
|
const user = sysLines[3] || "";
|
|
769
833
|
const homeDir = sysLines[4] || "/";
|
|
834
|
+
const cores = parseInt(sysLines[5] || "1", 10) || 1;
|
|
835
|
+
const totalMemMb = parseInt(sysLines[6] || "0", 10) || 0;
|
|
770
836
|
const gitLines = (sections["GIT"] || []).filter(Boolean);
|
|
771
837
|
const gitInstalled = gitLines.length > 0 && gitLines[0] !== "NONE";
|
|
772
838
|
const gitVersion = gitInstalled ? gitLines.join(" ") : undefined;
|
|
@@ -793,6 +859,8 @@ done
|
|
|
793
859
|
hostname,
|
|
794
860
|
user,
|
|
795
861
|
homeDir,
|
|
862
|
+
cores,
|
|
863
|
+
totalMemMb,
|
|
796
864
|
},
|
|
797
865
|
tools: {
|
|
798
866
|
git: { installed: gitInstalled, version: gitVersion },
|
|
@@ -1428,6 +1496,36 @@ fi
|
|
|
1428
1496
|
};
|
|
1429
1497
|
return virtualPty;
|
|
1430
1498
|
}
|
|
1499
|
+
/**
|
|
1500
|
+
* 为目标主机打开交互式 PTY Shell 通道(返回底层 ClientChannel 流与连接)
|
|
1501
|
+
*/
|
|
1502
|
+
async openShell(target, options = {}) {
|
|
1503
|
+
const port = target.port ?? 22;
|
|
1504
|
+
const conn = await this.getOrConnectHost(target.host, port, target.username);
|
|
1505
|
+
return new Promise((resolve, reject) => {
|
|
1506
|
+
conn.client.shell({
|
|
1507
|
+
term: options.term ?? "xterm-256color",
|
|
1508
|
+
cols: Math.max(2, Math.floor(options.cols ?? 80)),
|
|
1509
|
+
rows: Math.max(2, Math.floor(options.rows ?? 24)),
|
|
1510
|
+
}, (err, stream) => {
|
|
1511
|
+
if (err)
|
|
1512
|
+
return reject(err);
|
|
1513
|
+
if (target.remotePath && target.remotePath !== "~") {
|
|
1514
|
+
stream.write(`cd ${shellQuotePosix(target.remotePath)} && clear\r`);
|
|
1515
|
+
}
|
|
1516
|
+
resolve({
|
|
1517
|
+
stream,
|
|
1518
|
+
conn,
|
|
1519
|
+
close: () => {
|
|
1520
|
+
try {
|
|
1521
|
+
stream.close();
|
|
1522
|
+
}
|
|
1523
|
+
catch { }
|
|
1524
|
+
},
|
|
1525
|
+
});
|
|
1526
|
+
});
|
|
1527
|
+
});
|
|
1528
|
+
}
|
|
1431
1529
|
}
|
|
1432
1530
|
/**
|
|
1433
1531
|
* 通过 SFTP 流式响应远程工作区文件的 HTTP 下载与媒体/HTML 预览请求(/api/file 与 /api/preview)。
|
package/dist/server/serialize.js
CHANGED
|
@@ -3,7 +3,7 @@ import { saveAttachmentSync } from "./attachment-store.js";
|
|
|
3
3
|
import { stripMarkers } from "./markers/index.js";
|
|
4
4
|
export const TEXT_CAP = 200_000;
|
|
5
5
|
export const TOOL_OUTPUT_CAP = 100_000;
|
|
6
|
-
export const ARGS_CAP =
|
|
6
|
+
export const ARGS_CAP = 200_000;
|
|
7
7
|
/**
|
|
8
8
|
* toolResult 里单张图片进快照的上限(dataUrl 字符数 ≈ 1.5MB 二进制)。
|
|
9
9
|
* 视口/元素截图随便过;超大整页截图回落成占位文本(模型侧不受影响 —— 图它
|
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* 预设存取 + 何时需要 reload」,真正动 runtime 的 session.reload() 走宿主回调
|
|
7
7
|
* (reloadSession 里还会刷新斜杠命令目录)。
|
|
8
8
|
*/
|
|
9
|
-
import { existsSync,
|
|
10
|
-
import { homedir } from "node:os";
|
|
9
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
11
10
|
import { basename, dirname, join } from "node:path";
|
|
12
11
|
import { fileURLToPath } from "node:url";
|
|
13
12
|
import { extensionKey, isInternalExtension, normalizeBgCleanupMinutes, normalizeDisabledPluginTools, normalizeRetryMaxAttempts, normalizeKeepRecentMessages, normalizeSkillList, normalizeSkillsCatalogBudget, normalizeSkillsCatalogMaxDesc, normalizeToolWatchdogTimeoutMs, normalizeUiLayout, defaultSubagentAutoWakeMaxTurns, normalizeSubagentAutoWakeMaxTurns, settingsPresetToUi, } from "./client-state.js";
|
|
@@ -16,6 +15,7 @@ import { findVisionModels, SYSTEM_PROMPT } from "./vision-bridge.js";
|
|
|
16
15
|
import { COMMITMSG_SYSTEM_PROMPT } from "./scm-commitmsg.js";
|
|
17
16
|
import { PLAN_MODE_SYSTEM_PROMPT } from "./plan-mode.js";
|
|
18
17
|
import { DEFAULT_TEMPLATES, localizeTemplate } from "./subagent-templates.js";
|
|
18
|
+
import { discoverDiskSkills, isSkillStillOnDisk } from "./skill-discovery.js";
|
|
19
19
|
import { deriveLegacy, foldLegacyIntoDisabled, normalizeDisabledAgentTools } from "./tool-manager.js";
|
|
20
20
|
import { normalizeToolPromptOverrides } from "./tool-prompt-overrides.js";
|
|
21
21
|
import { resolveServerLang } from "./i18n.js";
|
|
@@ -70,51 +70,13 @@ export class SettingsService {
|
|
|
70
70
|
this.pendingReload = false;
|
|
71
71
|
return v;
|
|
72
72
|
}
|
|
73
|
-
/** 判断某个 skill
|
|
74
|
-
*
|
|
75
|
-
* 出现在设置面板,也不应留在持久化记录里。 */
|
|
73
|
+
/** 判断某个 skill 名是否仍存在于磁盘任何来源(各类 Agent 项目区 / 全局 / 祖先 / npm 包等)。
|
|
74
|
+
* 被禁用且文件已删除的名字不应再出现在设置面板,也不应留在持久化记录里。 */
|
|
76
75
|
skillStillOnDisk(name) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (check(join(agentDir, "skills")))
|
|
82
|
-
return true;
|
|
83
|
-
// SDK 始终扫描用户级 ~/.agents/skills,不依赖 cwd 的祖先链(issue #669)。
|
|
84
|
-
if (check(join(process.env.HOME || homedir(), ".agents", "skills")))
|
|
85
|
-
return true;
|
|
86
|
-
if (check(join(cwd, ".pi", "skills")))
|
|
87
|
-
return true;
|
|
88
|
-
// ③ 祖先链 .agents/skills(SDK collectAncestorAgentsSkillDirs 语义,最多上溯 6 层)
|
|
89
|
-
let dir = cwd;
|
|
90
|
-
for (let i = 0; i < 6 && dir !== dirname(dir); i++, dir = dirname(dir)) {
|
|
91
|
-
if (check(join(dir, ".agents", "skills")))
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
// ④ npm 包内 skills(agent 级 + 项目级,含 @scope 两级子包)
|
|
95
|
-
for (const npmRoot of [join(agentDir, "npm", "node_modules"), join(cwd, ".pi", "npm", "node_modules")]) {
|
|
96
|
-
try {
|
|
97
|
-
for (const entry of readdirSync(npmRoot, { withFileTypes: true })) {
|
|
98
|
-
if (!entry.isDirectory())
|
|
99
|
-
continue;
|
|
100
|
-
if (!entry.name.startsWith("@")) {
|
|
101
|
-
if (check(join(npmRoot, entry.name, "skills")))
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
for (const sub of readdirSync(join(npmRoot, entry.name), { withFileTypes: true })) {
|
|
106
|
-
if (sub.isDirectory() && check(join(npmRoot, entry.name, sub.name, "skills"))) {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch {
|
|
114
|
-
// npm 目录不存在/不可读 → 不是来源
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
76
|
+
return isSkillStillOnDisk(name, {
|
|
77
|
+
cwd: this.host.cwd(),
|
|
78
|
+
agentDir: this.host.agentDir(),
|
|
79
|
+
});
|
|
118
80
|
}
|
|
119
81
|
/** 判断某个扩展 id 是否仍存在(loader 之外的兜底,供禁用残留清理用):
|
|
120
82
|
* npm: 包 → 任一 npm 根还有目录,或还列在任一 settings.json packages 里
|
|
@@ -178,10 +140,19 @@ export class SettingsService {
|
|
|
178
140
|
const loadedExts = allLoadedExts.filter((e) => !isInternalExtension(e));
|
|
179
141
|
loadedSkillNames = new Set(loadedSkills.map((s) => s.name));
|
|
180
142
|
loadedExtNames = new Set(loadedExts.map((e) => extensionKey(e)));
|
|
143
|
+
// 实时全源磁盘扫描:动态发现外部新安装/更新的各类 Agent 全局与本地技能
|
|
144
|
+
const diskSkills = discoverDiskSkills({
|
|
145
|
+
cwd: this.host.cwd(),
|
|
146
|
+
agentDir: this.host.agentDir(),
|
|
147
|
+
});
|
|
181
148
|
// Prune entries that no longer exist on disk AND aren't disabled
|
|
182
149
|
// (e.g. a skill/extension file was deleted). Disabled entries are
|
|
183
150
|
// kept so they can be re-enabled even when filtered out of the loader.
|
|
184
|
-
const keepSkills = new Set([
|
|
151
|
+
const keepSkills = new Set([
|
|
152
|
+
...loadedSkills.map((s) => s.name),
|
|
153
|
+
...diskSkills.map((s) => s.name),
|
|
154
|
+
...this.settings.disabledSkills,
|
|
155
|
+
]);
|
|
185
156
|
const keepExts = new Set([
|
|
186
157
|
...loadedExts.map((e) => extensionKey(e)),
|
|
187
158
|
...this.settings.disabledExtensions.filter((id) => !isInternalExtension({ path: id })),
|
|
@@ -203,6 +174,18 @@ export class SettingsService {
|
|
|
203
174
|
enabled: true,
|
|
204
175
|
});
|
|
205
176
|
}
|
|
177
|
+
for (const ds of diskSkills) {
|
|
178
|
+
if (!this.knownSkills.has(ds.name)) {
|
|
179
|
+
this.knownSkills.set(ds.name, {
|
|
180
|
+
name: ds.name,
|
|
181
|
+
description: ds.description,
|
|
182
|
+
enabled: !disabledSkills.has(ds.name),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
else if (!this.knownSkills.get(ds.name).description && ds.description) {
|
|
186
|
+
this.knownSkills.get(ds.name).description = ds.description;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
206
189
|
for (const e of loadedExts) {
|
|
207
190
|
const id = extensionKey(e);
|
|
208
191
|
const p = e.sourceInfo?.path ?? e.path;
|
|
@@ -213,6 +196,11 @@ export class SettingsService {
|
|
|
213
196
|
enabled: true,
|
|
214
197
|
});
|
|
215
198
|
}
|
|
199
|
+
// 若发现磁盘新增了 loader 尚未加载的技能,触发会话后台异步 reload 以刷新提示词和技能工具
|
|
200
|
+
const hasUnloadedDiskSkills = diskSkills.some((ds) => !loadedSkillNames.has(ds.name));
|
|
201
|
+
if (hasUnloadedDiskSkills && !this.host.isStreaming()) {
|
|
202
|
+
void this.host.reloadSession();
|
|
203
|
+
}
|
|
216
204
|
}
|
|
217
205
|
catch {
|
|
218
206
|
// Session not ready yet — keep whatever we already know.
|
|
@@ -228,7 +216,7 @@ export class SettingsService {
|
|
|
228
216
|
...this.settings.reviewDisabledSkills,
|
|
229
217
|
...normalizeSkillList(this.settings.skillsFullText),
|
|
230
218
|
]),
|
|
231
|
-
].filter((name) => !
|
|
219
|
+
].filter((name) => !this.knownSkills.has(name) && !this.skillStillOnDisk(name));
|
|
232
220
|
if (stale.length > 0) {
|
|
233
221
|
this.settings.disabledSkills = this.settings.disabledSkills.filter((n) => !stale.includes(n));
|
|
234
222
|
this.settings.reviewDisabledSkills = this.settings.reviewDisabledSkills.filter((n) => !stale.includes(n));
|