pi-web-ui 0.105.1 → 0.106.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 +193 -797
- package/README.zh-CN.md +186 -625
- package/README.zh-TW.md +781 -0
- package/bin/frp-manager.mjs +1488 -0
- package/bin/pi-web-ui.mjs +27 -0
- package/deploy/nginx-subpath.conf +16 -1
- package/dist/server/agent-service-daemon.js +34 -0
- package/dist/server/agent-service.js +227 -44
- package/dist/server/claim-files-tool.js +8 -1
- package/dist/server/client-state.js +136 -30
- package/dist/server/conversation-read-tool.js +12 -4
- package/dist/server/delegate-task.js +9 -1
- package/dist/server/dispatch-domain-handlers.js +15 -0
- package/dist/server/dsh/dsh-agent-service.js +838 -241
- package/dist/server/dsh/dsh-client.js +59 -18
- package/dist/server/dsh/dsh-market-service.js +233 -0
- package/dist/server/dsh/dsh-serialize.js +11 -3
- package/dist/server/dsh/dsh-sessions.js +64 -2
- package/dist/server/dsh/preset-clones.js +12 -1
- package/dist/server/dsh/runtime/goal-rpc.mjs +183 -45
- package/dist/server/engine-capabilities.js +72 -0
- package/dist/server/engine-probe.js +243 -0
- package/dist/server/goal-service.js +23 -12
- package/dist/server/i18n.js +20 -1
- package/dist/server/index.js +171 -66
- package/dist/server/locales.js +1 -0
- package/dist/server/mcp-agent-tool.js +10 -7
- package/dist/server/mcp-bridge.js +428 -24
- package/dist/server/model-admin.js +172 -74
- package/dist/server/model-resolver.js +221 -0
- package/dist/server/plugin-installer.js +4 -2
- package/dist/server/plugins.js +71 -11
- package/dist/server/present-files-tool.js +10 -2
- package/dist/server/preset-fields.js +14 -0
- package/dist/server/preset-share.js +2 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/schedule-agent-tool.js +2 -1
- package/dist/server/scm-commitmsg.js +3 -2
- package/dist/server/settings-service.js +10 -2
- package/dist/server/skill-discovery.js +161 -0
- package/dist/server/skill-tool.js +2 -1
- package/dist/server/slash-commands.js +154 -73
- package/dist/server/subagent-templates-hant.js +215 -0
- package/dist/server/subagent-templates.js +49 -2
- package/dist/server/subagents.js +22 -12
- package/dist/server/terminals.js +2 -2
- package/dist/server/tool-manager.js +3 -0
- package/dist/server/universal/driver-base.js +56 -0
- package/dist/server/universal/drivers/claude-code.js +462 -0
- package/dist/server/universal/drivers/dsh-driver.js +376 -0
- package/dist/server/universal/drivers/mock-driver.js +103 -0
- package/dist/server/universal/index.js +10 -0
- package/dist/server/universal/session-store.js +100 -0
- package/dist/server/universal/universal-attachments.js +175 -0
- package/dist/server/universal/universal-service.js +149 -0
- package/dist/server/universal/universal-session.js +2610 -0
- package/dist/server/universal/universal-types.js +4 -0
- package/dist/server/update-check.js +4 -1
- package/dist/server/worktree-service.js +1 -1
- package/dist/server/worktree-tool.js +9 -7
- package/package.json +3 -2
- package/plugin-sdk/index.d.ts +12 -2
- package/plugins/catalog.json +39 -5
- package/themes/dark-teal.css +20 -23
- package/themes/md-preview.css +1 -2
- package/themes/wallpaper-obsidian.css +693 -0
- package/web/dist/assets/{TerminalPanel-Mk4laCAL.js → TerminalPanel-CfxKLDW9.js} +2 -2
- package/web/dist/assets/index-BtcP6BDk.css +1 -0
- package/web/dist/assets/index-XVtCzcHR.js +690 -0
- package/web/dist/index.html +2 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-BDLVjBeK.js +0 -690
- package/web/dist/assets/index-BQC6lADz.css +0 -1
|
@@ -16,22 +16,32 @@
|
|
|
16
16
|
import { resolve } from "node:path";
|
|
17
17
|
import { dirname, join } from "node:path";
|
|
18
18
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
19
|
+
import { existsSync } from "node:fs";
|
|
19
20
|
import { JsonRpcLineTransport } from "@deepseek-ai/dsh-sdk-protocol";
|
|
20
21
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
21
22
|
|
|
22
23
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
23
24
|
|
|
24
|
-
/** 官方 jsonrpc-server 入口(env
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
)
|
|
25
|
+
/** 官方 jsonrpc-server 入口(env 优先,兜底从本文件向上找 node_modules 里的官方包)。 */
|
|
26
|
+
function findOfficialEntry() {
|
|
27
|
+
if (process.env.PI_WEB_DSH_JSONRPC_ENTRY) return resolve(process.env.PI_WEB_DSH_JSONRPC_ENTRY);
|
|
28
|
+
let cur = HERE;
|
|
29
|
+
for (let i = 0; i < 6; i++) {
|
|
30
|
+
const candidate = join(cur, "node_modules", "@deepseek-ai", "dsh-sdk-jsonrpc-server", "lib", "index.js");
|
|
31
|
+
if (existsSync(candidate)) return candidate;
|
|
32
|
+
cur = dirname(cur);
|
|
33
|
+
}
|
|
34
|
+
return join(
|
|
35
|
+
resolve(HERE, "..", "..", ".."),
|
|
36
|
+
"node_modules",
|
|
37
|
+
"@deepseek-ai",
|
|
38
|
+
"dsh-sdk-jsonrpc-server",
|
|
39
|
+
"lib",
|
|
40
|
+
"index.js",
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const officialEntry = findOfficialEntry();
|
|
35
45
|
|
|
36
46
|
const official = await import(pathToFileURL(officialEntry).href);
|
|
37
47
|
const { HarnessSdkJsonRpcServer, Config } = official;
|
|
@@ -78,32 +88,143 @@ function escapeTextSimple(s) {
|
|
|
78
88
|
return String(s).replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
79
89
|
}
|
|
80
90
|
|
|
91
|
+
const DSH_VALID_TYPES = new Set(["string", "number", "integer", "boolean", "null", "array", "object", "json"]);
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 把任意 JSON Schema 节点规整为 DSH schema compiler 支持的纯净 value schema。
|
|
95
|
+
* @param {unknown} def 原始属性定义
|
|
96
|
+
* @param {boolean} [allowRequired=false] 是否允许 required 字段(仅顶层 property-map 允许)
|
|
97
|
+
*/
|
|
98
|
+
function normalizeDshNode(def, allowRequired = false) {
|
|
99
|
+
if (!def || typeof def !== "object" || Array.isArray(def)) {
|
|
100
|
+
return { type: "string" };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const out = {};
|
|
104
|
+
|
|
105
|
+
// 1. 复制合法的 annotations
|
|
106
|
+
if (typeof def.description === "string") out.description = def.description;
|
|
107
|
+
if (typeof def.title === "string") out.title = def.title;
|
|
108
|
+
if (def.default !== undefined) out.default = def.default;
|
|
109
|
+
if (Array.isArray(def.examples)) out.examples = def.examples;
|
|
110
|
+
if (allowRequired && def.required === true) out.required = true;
|
|
111
|
+
|
|
112
|
+
// 2. 处理 oneOf / anyOf(DSH 仅支持 oneOf,且与 type 互斥)
|
|
113
|
+
const unionCandidates = Array.isArray(def.oneOf) ? def.oneOf : Array.isArray(def.anyOf) ? def.anyOf : null;
|
|
114
|
+
|
|
115
|
+
if (unionCandidates) {
|
|
116
|
+
const branches = unionCandidates.map((branch) => normalizeDshNode(branch, false)).filter(Boolean);
|
|
117
|
+
if (branches.length >= 2) {
|
|
118
|
+
out.oneOf = branches;
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
if (branches.length === 1) {
|
|
122
|
+
return { ...branches[0], ...out };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 3. 处理 type 字段(可能为数组,如 ["string", "null"])
|
|
127
|
+
let rawType = def.type;
|
|
128
|
+
if (Array.isArray(rawType)) {
|
|
129
|
+
const types = rawType
|
|
130
|
+
.map((t) => (typeof t === "string" ? t.toLowerCase().trim() : ""))
|
|
131
|
+
.filter((t) => DSH_VALID_TYPES.has(t));
|
|
132
|
+
if (types.length >= 2) {
|
|
133
|
+
out.oneOf = types.map((t) => {
|
|
134
|
+
const branch = { type: t };
|
|
135
|
+
if (t === "object") branch.additionalProperties = true;
|
|
136
|
+
return branch;
|
|
137
|
+
});
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
rawType = types[0];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
let type = typeof rawType === "string" ? rawType.toLowerCase().trim() : undefined;
|
|
144
|
+
if (type === "float") type = "number";
|
|
145
|
+
else if (type === "int") type = "integer";
|
|
146
|
+
else if (type === "bool") type = "boolean";
|
|
147
|
+
|
|
148
|
+
if (!type) {
|
|
149
|
+
if (def.properties && typeof def.properties === "object") type = "object";
|
|
150
|
+
else if (def.items) type = "array";
|
|
151
|
+
else type = "string";
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (!DSH_VALID_TYPES.has(type)) {
|
|
155
|
+
type = "string";
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
out.type = type;
|
|
159
|
+
|
|
160
|
+
// 4. 根据具体 type 补充/规整专属字段(严格限制在 DSH 允许子集,去除 format/pattern 等不支持属性)
|
|
161
|
+
switch (type) {
|
|
162
|
+
case "object": {
|
|
163
|
+
out.additionalProperties = typeof def.additionalProperties === "boolean" ? def.additionalProperties : true;
|
|
164
|
+
if (def.properties && typeof def.properties === "object" && !Array.isArray(def.properties)) {
|
|
165
|
+
const nestedProps = {};
|
|
166
|
+
const reqList = Array.isArray(def.required) ? def.required : [];
|
|
167
|
+
for (const [pKey, pDef] of Object.entries(def.properties)) {
|
|
168
|
+
const pNode = normalizeDshNode(pDef, true);
|
|
169
|
+
if (reqList.includes(pKey)) pNode.required = true;
|
|
170
|
+
nestedProps[pKey] = pNode;
|
|
171
|
+
}
|
|
172
|
+
out.properties = nestedProps;
|
|
173
|
+
}
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
case "array": {
|
|
177
|
+
if (def.items && typeof def.items === "object" && !Array.isArray(def.items)) {
|
|
178
|
+
out.items = normalizeDshNode(def.items, false);
|
|
179
|
+
}
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case "string":
|
|
183
|
+
case "number":
|
|
184
|
+
case "integer":
|
|
185
|
+
case "boolean":
|
|
186
|
+
case "null": {
|
|
187
|
+
if (Array.isArray(def.enum) && def.enum.length > 0) {
|
|
188
|
+
out.enum = def.enum;
|
|
189
|
+
}
|
|
190
|
+
if (def.const !== undefined) {
|
|
191
|
+
out.const = def.const;
|
|
192
|
+
}
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
case "json":
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
|
|
81
202
|
/** 把 pi-web-ui 插件工具的标准 JSON Schema `parameters`(`{type,properties,required[]}`)
|
|
82
203
|
* 转成 DSH defineTool 的 per-property 参数映射 spec(`{key:{type,required?,description}}`)。
|
|
83
204
|
* DSH 的 parameterSchemaSpecToJsonSchema 需要 property-map 形状(required 挂在每条属性上),
|
|
84
205
|
* 而 pi 插件/TypeBox 用的是标准 JSON Schema(required 是对象数组)。纯函数。 */
|
|
85
|
-
function piParamsToDshSpec(parameters) {
|
|
206
|
+
export function piParamsToDshSpec(parameters) {
|
|
86
207
|
if (!parameters || typeof parameters !== "object" || Array.isArray(parameters)) return {};
|
|
208
|
+
let propSource;
|
|
209
|
+
let requiredList = [];
|
|
87
210
|
if (parameters.properties && typeof parameters.properties === "object" && !Array.isArray(parameters.properties)) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
return propMap;
|
|
211
|
+
propSource = parameters.properties;
|
|
212
|
+
if (Array.isArray(parameters.required)) requiredList = parameters.required;
|
|
213
|
+
} else if (parameters.type === "object") {
|
|
214
|
+
// 标准 JSON Schema 的无属性对象:{ type: "object" }
|
|
215
|
+
return {};
|
|
216
|
+
} else {
|
|
217
|
+
// 已是 DSH property-map 形状
|
|
218
|
+
propSource = parameters;
|
|
219
|
+
if (Array.isArray(parameters.required)) requiredList = parameters.required;
|
|
220
|
+
}
|
|
221
|
+
const propMap = {};
|
|
222
|
+
for (const [key, def] of Object.entries(propSource)) {
|
|
223
|
+
const node = normalizeDshNode(def, true);
|
|
224
|
+
if (requiredList.includes(key)) node.required = true;
|
|
225
|
+
propMap[key] = node;
|
|
104
226
|
}
|
|
105
|
-
|
|
106
|
-
return parameters;
|
|
227
|
+
return propMap;
|
|
107
228
|
}
|
|
108
229
|
|
|
109
230
|
/** goal view → RPC 载荷(紧凑 JSON;view 是扁平结构,无目标时 get 返回 undefined)。 */
|
|
@@ -354,7 +475,12 @@ class DshGoalJsonRpcServer extends HarnessSdkJsonRpcServer {
|
|
|
354
475
|
const agent = this.liveAgent(rec, params.sessionId);
|
|
355
476
|
const permission = this.ctx.permissionPresets;
|
|
356
477
|
if (!permission) throw new Error("permission/get: permission service unavailable");
|
|
357
|
-
|
|
478
|
+
if (typeof permission.selectFor === "function") {
|
|
479
|
+
return permission.selectFor(permission.permissionState(agent.session));
|
|
480
|
+
}
|
|
481
|
+
const cat = typeof permission.catalog === "function" ? permission.catalog() : {};
|
|
482
|
+
const cur = typeof permission.current === "function" ? permission.current(agent.session) : undefined;
|
|
483
|
+
return { ...cat, currentValue: cur };
|
|
358
484
|
}
|
|
359
485
|
|
|
360
486
|
/** permission/set RPC:按会话热切换权限预设(写会话日志,无需重启;
|
|
@@ -376,10 +502,18 @@ class DshGoalJsonRpcServer extends HarnessSdkJsonRpcServer {
|
|
|
376
502
|
const rec = await this.getOrCreateSession(params.sessionId);
|
|
377
503
|
const agent = this.liveAgent(rec, params.sessionId);
|
|
378
504
|
permission.apply(agent.session, params.preset, (policy) => this.ctx.approval.setPolicy(agent, policy));
|
|
505
|
+
const snapshot =
|
|
506
|
+
typeof permission.selectFor === "function"
|
|
507
|
+
? permission.selectFor(permission.permissionState(agent.session))
|
|
508
|
+
: {
|
|
509
|
+
...(typeof permission.catalog === "function" ? permission.catalog() : {}),
|
|
510
|
+
currentValue:
|
|
511
|
+
typeof permission.current === "function" ? permission.current(agent.session) : params.preset,
|
|
512
|
+
};
|
|
379
513
|
return {
|
|
380
514
|
ok: true,
|
|
381
515
|
preset: params.preset,
|
|
382
|
-
...
|
|
516
|
+
...snapshot,
|
|
383
517
|
};
|
|
384
518
|
} catch (err) {
|
|
385
519
|
return { ok: false, code: "permission/error", message: err?.message ?? String(err) };
|
|
@@ -653,19 +787,23 @@ class DshGoalJsonRpcServer extends HarnessSdkJsonRpcServer {
|
|
|
653
787
|
const registered = [];
|
|
654
788
|
for (const t of tools) {
|
|
655
789
|
if (!t || typeof t.name !== "string" || typeof t.description !== "string") continue;
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
790
|
+
try {
|
|
791
|
+
const tool = defineTool({
|
|
792
|
+
name: t.name,
|
|
793
|
+
description: t.description,
|
|
794
|
+
parameters: piParamsToDshSpec(t.parameters),
|
|
795
|
+
output: {
|
|
796
|
+
schema: { type: "string" },
|
|
797
|
+
render: (_args, value) => [{ type: "text", text: String(value ?? "") }],
|
|
798
|
+
},
|
|
799
|
+
execute: (args, exec) => this.invokeBridgedTool(exec, t.name, args),
|
|
800
|
+
});
|
|
801
|
+
const off = this.ctx.tools.register(tool);
|
|
802
|
+
this.toolUnregisters.push(off);
|
|
803
|
+
registered.push(t.name);
|
|
804
|
+
} catch (err) {
|
|
805
|
+
console.warn(`[dsh] 工具 ${t.name} 注册跳过:`, err?.message ?? err);
|
|
806
|
+
}
|
|
669
807
|
}
|
|
670
808
|
return { registered, count: registered.length };
|
|
671
809
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* engine-capabilities.ts — 智能体底座能力声明规范与出厂事实源。
|
|
3
|
+
*
|
|
4
|
+
* 职责:
|
|
5
|
+
* 1. 为 pi / dsh / 通用基座(Claude Code 等)及未来第三方驱动提供标准能力声明契约;
|
|
6
|
+
* 2. 提供各内置引擎的开箱即用能力事实源(Pi 全能力、DSH 差异化子集、通用基座保守默认);
|
|
7
|
+
* 3. 辅助生成安全归一化的 AgentEngineCapabilities 对象。
|
|
8
|
+
*/
|
|
9
|
+
/** Pi 原生引擎能力:全功能全集 */
|
|
10
|
+
export const DEFAULT_PI_CAPABILITIES = Object.freeze({
|
|
11
|
+
remoteSsh: true,
|
|
12
|
+
sandboxes: true,
|
|
13
|
+
workspaceRoots: true,
|
|
14
|
+
conversationRef: true,
|
|
15
|
+
pageRef: true,
|
|
16
|
+
presentFiles: true,
|
|
17
|
+
planMode: true,
|
|
18
|
+
delegateMode: true,
|
|
19
|
+
subagents: true,
|
|
20
|
+
toolPromptOverride: true,
|
|
21
|
+
lazyTools: true,
|
|
22
|
+
softCap: true,
|
|
23
|
+
treeFork: true,
|
|
24
|
+
messageEdit: true,
|
|
25
|
+
steer: true,
|
|
26
|
+
ephemeralChat: true,
|
|
27
|
+
});
|
|
28
|
+
/** DSH 引擎能力:外部独立进程运行时(缺失 SSH 透明接管、conversation_read 等宿主特性) */
|
|
29
|
+
export const DEFAULT_DSH_CAPABILITIES = Object.freeze({
|
|
30
|
+
remoteSsh: false,
|
|
31
|
+
sandboxes: false,
|
|
32
|
+
workspaceRoots: false,
|
|
33
|
+
conversationRef: false,
|
|
34
|
+
pageRef: false,
|
|
35
|
+
presentFiles: false,
|
|
36
|
+
planMode: false,
|
|
37
|
+
delegateMode: false,
|
|
38
|
+
subagents: false,
|
|
39
|
+
toolPromptOverride: false,
|
|
40
|
+
lazyTools: false,
|
|
41
|
+
softCap: false,
|
|
42
|
+
treeFork: false,
|
|
43
|
+
messageEdit: false,
|
|
44
|
+
steer: false,
|
|
45
|
+
ephemeralChat: false,
|
|
46
|
+
});
|
|
47
|
+
/** 通用基座保守默认能力:外部 CLI / 子进程默认仅支持纯线性消息对话 */
|
|
48
|
+
export const DEFAULT_UNIVERSAL_CAPABILITIES = Object.freeze({
|
|
49
|
+
remoteSsh: false,
|
|
50
|
+
sandboxes: false,
|
|
51
|
+
workspaceRoots: false,
|
|
52
|
+
conversationRef: false,
|
|
53
|
+
pageRef: false,
|
|
54
|
+
presentFiles: false,
|
|
55
|
+
planMode: false,
|
|
56
|
+
delegateMode: false,
|
|
57
|
+
subagents: true,
|
|
58
|
+
toolPromptOverride: false,
|
|
59
|
+
lazyTools: false,
|
|
60
|
+
softCap: false,
|
|
61
|
+
treeFork: false,
|
|
62
|
+
messageEdit: false,
|
|
63
|
+
steer: false,
|
|
64
|
+
ephemeralChat: true,
|
|
65
|
+
});
|
|
66
|
+
/** 合并并归一化能力声明(默认回落到通用基座保守值) */
|
|
67
|
+
export function resolveEngineCapabilities(caps, base = DEFAULT_UNIVERSAL_CAPABILITIES) {
|
|
68
|
+
return {
|
|
69
|
+
...base,
|
|
70
|
+
...(caps ?? {}),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { VERSION } from "@earendil-works/pi-coding-agent";
|
|
5
|
+
import { runtimeBaseCandidates } from "./dsh/preset-clones.js";
|
|
6
|
+
import { probeClaudeCode } from "./universal/drivers/claude-code.js";
|
|
7
|
+
import { compareVersions, defaultFetcher, fetchLatest, NPM_DEFAULT_REGISTRY, } from "./update-check.js";
|
|
8
|
+
export const ENGINE_PACKAGES = {
|
|
9
|
+
pi: {
|
|
10
|
+
id: "pi",
|
|
11
|
+
packageName: "@earendil-works/pi-coding-agent",
|
|
12
|
+
installCommand: "npm i -g @earendil-works/pi-coding-agent",
|
|
13
|
+
},
|
|
14
|
+
dsh: {
|
|
15
|
+
id: "dsh",
|
|
16
|
+
packageName: "@deepseek-ai/dsh",
|
|
17
|
+
installCommand: "npm i -g @deepseek-ai/dsh",
|
|
18
|
+
},
|
|
19
|
+
claude: {
|
|
20
|
+
id: "claude",
|
|
21
|
+
packageName: "@anthropic-ai/claude-code",
|
|
22
|
+
installCommand: "npm i -g @anthropic-ai/claude-code",
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
/** 探针缓存 TTL:5 秒(短时多次连接或 UI 打开时免除重复频繁执行进程调用) */
|
|
26
|
+
const CACHE_TTL_MS = 5000;
|
|
27
|
+
/** 远端 npm registry 查询缓存:5 分钟 */
|
|
28
|
+
const REGISTRY_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
29
|
+
const registryCache = new Map();
|
|
30
|
+
let lastProbeAt = 0;
|
|
31
|
+
let cachedStatuses = [
|
|
32
|
+
{ id: "pi", installed: true, packageName: ENGINE_PACKAGES.pi.packageName, version: VERSION },
|
|
33
|
+
{ id: "dsh", installed: false, packageName: ENGINE_PACKAGES.dsh.packageName },
|
|
34
|
+
{ id: "claude", installed: false, packageName: ENGINE_PACKAGES.claude.packageName },
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* 查询全局包在 npm 远端的最新版本号(带 5 分钟缓存)。
|
|
38
|
+
*/
|
|
39
|
+
export async function checkPackageLatest(packageName, force = false) {
|
|
40
|
+
const now = Date.now();
|
|
41
|
+
const cached = registryCache.get(packageName);
|
|
42
|
+
if (!force && cached && now - cached.at < REGISTRY_CACHE_TTL_MS) {
|
|
43
|
+
return cached.latest;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const res = await fetchLatest(defaultFetcher, packageName, NPM_DEFAULT_REGISTRY, null);
|
|
47
|
+
registryCache.set(packageName, { at: now, latest: res.latest });
|
|
48
|
+
return res.latest;
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return cached?.latest ?? null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 为已安装的引擎注入 npm 远端更新检测结果(latestVersion 与 hasUpdate 标记)。
|
|
56
|
+
*/
|
|
57
|
+
export async function enrichWithUpdateInfo(status, force = false) {
|
|
58
|
+
if (!status.installed || !status.packageName || !status.version) {
|
|
59
|
+
return status;
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
const latest = await checkPackageLatest(status.packageName, force);
|
|
63
|
+
if (latest) {
|
|
64
|
+
status.latestVersion = latest;
|
|
65
|
+
status.hasUpdate = compareVersions(latest, status.version) > 0;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
/* best effort */
|
|
70
|
+
}
|
|
71
|
+
return status;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 探测 Pi 原生引擎状态(作为内置/捆绑引擎恒存在)。
|
|
75
|
+
*/
|
|
76
|
+
export function probePi() {
|
|
77
|
+
return {
|
|
78
|
+
id: "pi",
|
|
79
|
+
installed: true,
|
|
80
|
+
packageName: ENGINE_PACKAGES.pi.packageName,
|
|
81
|
+
version: VERSION,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 快速探测 DSH 引擎全局包/运行时树是否已安装。
|
|
86
|
+
* 1. 优先检查常见全局 node_modules / 候选路径中的 @deepseek-ai/dsh package.json 与 dsh-base;
|
|
87
|
+
* 2. 回退通过命令行探针执行 `dsh --version`。
|
|
88
|
+
*/
|
|
89
|
+
export async function probeDsh() {
|
|
90
|
+
const pkgName = ENGINE_PACKAGES.dsh.packageName;
|
|
91
|
+
// 1. 路径快速探测(纯 fs 访问,无进程派生开销)
|
|
92
|
+
try {
|
|
93
|
+
for (const root of runtimeBaseCandidates()) {
|
|
94
|
+
if (!root)
|
|
95
|
+
continue;
|
|
96
|
+
// A. 直接在全局或候选 node_modules 中找到 @deepseek-ai/dsh 包目录
|
|
97
|
+
const dshPkgJson = join(root, "@deepseek-ai", "dsh", "package.json");
|
|
98
|
+
if (existsSync(dshPkgJson)) {
|
|
99
|
+
try {
|
|
100
|
+
const pkg = JSON.parse(readFileSync(dshPkgJson, "utf8"));
|
|
101
|
+
return { id: "dsh", installed: true, packageName: pkgName, version: pkg.version };
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return { id: "dsh", installed: true, packageName: pkgName };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// B. 检查平铺运行树(@deepseek-ai/dsh-base)
|
|
108
|
+
const flatBase = join(root, "@deepseek-ai", "dsh-base", "cordis.patch.yml");
|
|
109
|
+
const flatBoot = join(root, "@deepseek-ai", "dsh-app-boot", "lib", "index.js");
|
|
110
|
+
if (existsSync(flatBase) && existsSync(flatBoot)) {
|
|
111
|
+
return { id: "dsh", installed: true, packageName: pkgName };
|
|
112
|
+
}
|
|
113
|
+
// C. 检查嵌套运行树(@deepseek-ai/dsh/node_modules/@deepseek-ai/dsh-base)
|
|
114
|
+
const nestedBase = join(root, "@deepseek-ai", "dsh", "node_modules", "@deepseek-ai", "dsh-base", "cordis.patch.yml");
|
|
115
|
+
const nestedBoot = join(root, "@deepseek-ai", "dsh", "node_modules", "@deepseek-ai", "dsh-app-boot", "lib", "index.js");
|
|
116
|
+
if (existsSync(nestedBase) && existsSync(nestedBoot)) {
|
|
117
|
+
return { id: "dsh", installed: true, packageName: pkgName };
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
/* ignore fs errors */
|
|
123
|
+
}
|
|
124
|
+
// 2. 命令行回退探测(检查 PATH 中是否有可用的 dsh CLI)
|
|
125
|
+
try {
|
|
126
|
+
const cliProbe = await new Promise((resolve) => {
|
|
127
|
+
execFile("dsh", ["--version"], {
|
|
128
|
+
timeout: 3000,
|
|
129
|
+
shell: process.platform === "win32",
|
|
130
|
+
}, (err, stdout) => {
|
|
131
|
+
if (err) {
|
|
132
|
+
resolve({ installed: false });
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
const v = stdout.trim();
|
|
136
|
+
resolve({ installed: true, version: v || undefined });
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
if (cliProbe.installed) {
|
|
141
|
+
return {
|
|
142
|
+
id: "dsh",
|
|
143
|
+
installed: true,
|
|
144
|
+
packageName: pkgName,
|
|
145
|
+
version: cliProbe.version,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
/* ignore cli error */
|
|
151
|
+
}
|
|
152
|
+
return { id: "dsh", installed: false, packageName: pkgName };
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* 探测 Claude Code 引擎状态。
|
|
156
|
+
*/
|
|
157
|
+
export async function probeClaude() {
|
|
158
|
+
const pkgName = ENGINE_PACKAGES.claude.packageName;
|
|
159
|
+
try {
|
|
160
|
+
const res = await probeClaudeCode();
|
|
161
|
+
return {
|
|
162
|
+
id: "claude",
|
|
163
|
+
installed: res.installed,
|
|
164
|
+
packageName: pkgName,
|
|
165
|
+
version: res.version,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
return { id: "claude", installed: false, packageName: pkgName };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 按引擎 ID 单独探测状态。
|
|
174
|
+
*/
|
|
175
|
+
export async function probeEngine(id, force = false) {
|
|
176
|
+
if (id === "pi")
|
|
177
|
+
return probePi();
|
|
178
|
+
if (!force && Date.now() - lastProbeAt < CACHE_TTL_MS) {
|
|
179
|
+
const found = cachedStatuses.find((e) => e.id === id);
|
|
180
|
+
if (found)
|
|
181
|
+
return found;
|
|
182
|
+
}
|
|
183
|
+
let result;
|
|
184
|
+
if (id === "dsh") {
|
|
185
|
+
result = await probeDsh();
|
|
186
|
+
}
|
|
187
|
+
else if (id === "claude") {
|
|
188
|
+
result = await probeClaude();
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
result = { id, installed: false };
|
|
192
|
+
}
|
|
193
|
+
await enrichWithUpdateInfo(result, force);
|
|
194
|
+
// 更新单项缓存
|
|
195
|
+
const idx = cachedStatuses.findIndex((e) => e.id === id);
|
|
196
|
+
if (idx >= 0)
|
|
197
|
+
cachedStatuses[idx] = result;
|
|
198
|
+
else
|
|
199
|
+
cachedStatuses.push(result);
|
|
200
|
+
return result;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* 探测全部已知引擎并返回最新状态列表(带 TTL 缓存防抖)。
|
|
204
|
+
*/
|
|
205
|
+
export async function probeAllEngines(force = false) {
|
|
206
|
+
if (!force && Date.now() - lastProbeAt < CACHE_TTL_MS && cachedStatuses.length > 0) {
|
|
207
|
+
return cachedStatuses;
|
|
208
|
+
}
|
|
209
|
+
const [pi, dsh, claude] = await Promise.all([probePi(), probeDsh(), probeClaude()]);
|
|
210
|
+
await Promise.all([
|
|
211
|
+
enrichWithUpdateInfo(pi, force),
|
|
212
|
+
enrichWithUpdateInfo(dsh, force),
|
|
213
|
+
enrichWithUpdateInfo(claude, force),
|
|
214
|
+
]);
|
|
215
|
+
cachedStatuses = [pi, dsh, claude];
|
|
216
|
+
lastProbeAt = Date.now();
|
|
217
|
+
return cachedStatuses;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* 同步获取当前缓存的引擎探测结果(握手帧或即时读取使用)。
|
|
221
|
+
*/
|
|
222
|
+
export function getCachedEngineStatuses() {
|
|
223
|
+
return [...cachedStatuses];
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 收集已安装的第三方全局引擎包,供全量更新检查(check_updates_all)纳入统一检查名录。
|
|
227
|
+
*/
|
|
228
|
+
export function collectInstalledEngineTargets() {
|
|
229
|
+
const out = [];
|
|
230
|
+
for (const status of cachedStatuses) {
|
|
231
|
+
// pi-core 在 collectTargets 中已有独立专属条目(PI_CORE_PACKAGE),此处收纳其他已安装引擎全局包
|
|
232
|
+
if (status.id !== "pi" && status.installed && status.packageName && status.version) {
|
|
233
|
+
out.push({
|
|
234
|
+
name: status.packageName,
|
|
235
|
+
version: status.version,
|
|
236
|
+
kind: "engine",
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return out;
|
|
241
|
+
}
|
|
242
|
+
// 模块加载时预热后台探测
|
|
243
|
+
void probeAllEngines(true).catch(() => { });
|