pi-web-ui 0.111.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 +92 -2
- package/bin/frp-manager.mjs +9 -2
- package/bin/pi-web-ui.mjs +325 -45
- package/dist/server/agent-service-daemon.js +29 -4
- package/dist/server/agent-service.js +1527 -510
- package/dist/server/approval-audit.js +119 -0
- package/dist/server/approval-default-rules.js +4 -4
- package/dist/server/approval-rules.js +42 -17
- package/dist/server/attachment-store.js +8 -8
- package/dist/server/canvas/canvas-agent-tool.js +8 -0
- package/dist/server/canvas/canvas-orchestrator.js +128 -22
- package/dist/server/canvas/pstack-skills-data.js +498 -0
- package/dist/server/client-state.js +28 -0
- package/dist/server/delegate-mode.js +6 -3
- package/dist/server/delegate-task.js +18 -3
- package/dist/server/dispatch-domain-handlers.js +39 -11
- package/dist/server/dsh/dsh-agent-service.js +294 -15
- package/dist/server/dsh/dsh-serialize.js +1 -1
- package/dist/server/durable/durable-driver.js +112 -107
- package/dist/server/durable/durable-event-projector.js +253 -0
- package/dist/server/durable/durable-loader.js +1 -14
- package/dist/server/durable/durable-models.js +107 -0
- package/dist/server/durable/index.js +0 -4
- package/dist/server/engine-probe.js +111 -48
- package/dist/server/eval-tool.js +28 -3
- package/dist/server/goal-service.js +7 -0
- package/dist/server/index.js +371 -57
- package/dist/server/json-utils.js +57 -0
- package/dist/server/marker-service.js +8 -0
- package/dist/server/message-window.js +43 -10
- package/dist/server/model-admin.js +247 -163
- package/dist/server/model-resolver.js +66 -44
- package/dist/server/plan-manager.js +3 -6
- package/dist/server/plugin-api-catalog.js +1 -0
- package/dist/server/plugin-assets.js +238 -0
- package/dist/server/plugin-facilities.js +22 -0
- package/dist/server/plugin-ui-slots.js +1 -0
- package/dist/server/plugins.js +209 -11
- package/dist/server/preset-fields.js +25 -1
- package/dist/server/preset-share.js +5 -2
- package/dist/server/prompt-assembler.js +2 -1
- package/dist/server/prompt-composer.js +18 -8
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/queue-utils.js +156 -0
- package/dist/server/remote-ssh-service.js +110 -12
- package/dist/server/sdk-builtin-extensions.js +85 -0
- package/dist/server/serialize.js +1 -1
- package/dist/server/server-config.js +66 -0
- package/dist/server/session-parser.js +49 -13
- package/dist/server/session-search.js +4 -3
- package/dist/server/settings-service.js +74 -53
- 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 +30 -6
- package/dist/server/subagent-helpers.js +22 -1
- package/dist/server/subagent-notify.js +93 -0
- package/dist/server/subagent-security-gate.js +282 -0
- package/dist/server/subagent-templates.js +8 -0
- package/dist/server/subagents.js +390 -48
- package/dist/server/terminals.js +196 -8
- package/dist/server/text-quote.js +61 -0
- package/dist/server/tool-approval.js +63 -4
- package/dist/server/tool-guards.js +208 -0
- package/dist/server/tool-host-factories.js +48 -10
- package/dist/server/tool-manager.js +106 -28
- package/dist/server/tool-overrides.js +21 -11
- package/dist/server/universal/driver-base.js +8 -0
- package/dist/server/universal/drivers/claude-code.js +116 -7
- package/dist/server/universal/drivers/dsh-driver.js +3 -0
- package/dist/server/universal/index.js +0 -1
- package/dist/server/universal/universal-session.js +106 -10
- package/dist/server/worktree-service.js +189 -1
- package/docs/dsh-engine.md +1 -5
- package/package.json +1 -1
- package/plugin-sdk/client-utils.mjs +192 -5
- package/plugin-sdk/index.d.ts +63 -1
- package/plugin-sdk/index.mjs +94 -0
- package/plugin-sdk/package.json +5 -1
- package/plugins/catalog.json +21 -0
- package/web/dist/assets/{TerminalPanel-BiUNySMA.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 +11 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/index-B0ajS__T.js +0 -697
- package/web/dist/assets/index-BHik5WGG.css +0 -1
|
@@ -281,3 +281,110 @@ export function resolveDurableModelChoice(modelId, fallbackList, agentDir) {
|
|
|
281
281
|
modelId: trimmed,
|
|
282
282
|
};
|
|
283
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* 根据模型配置(reasoning 与 thinkingLevelMap)解析支持的思考强度档位。
|
|
286
|
+
*/
|
|
287
|
+
export function calculateSupportedThinkingLevels(modelDef) {
|
|
288
|
+
if (!modelDef) {
|
|
289
|
+
return ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
290
|
+
}
|
|
291
|
+
if (modelDef.reasoning === false) {
|
|
292
|
+
return ["off"];
|
|
293
|
+
}
|
|
294
|
+
const allLevels = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
295
|
+
if (modelDef.thinkingLevelMap && typeof modelDef.thinkingLevelMap === "object") {
|
|
296
|
+
return allLevels.filter((lvl) => {
|
|
297
|
+
const mapped = modelDef.thinkingLevelMap?.[lvl];
|
|
298
|
+
if (mapped === null)
|
|
299
|
+
return false;
|
|
300
|
+
if (lvl === "xhigh" || lvl === "max")
|
|
301
|
+
return mapped !== undefined;
|
|
302
|
+
return true;
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
// 默认具备 reasoning 能力时支持 off, minimal, low, medium, high
|
|
306
|
+
return ["off", "minimal", "low", "medium", "high"];
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* 快速同步解析指定模型的思考能力(优先 models 容器,次之 models.json / models-store.json / cachedModels)。
|
|
310
|
+
*/
|
|
311
|
+
export function resolveDurableThinkingLevels(modelId, options) {
|
|
312
|
+
if (!modelId || !modelId.trim() || modelId === "default") {
|
|
313
|
+
return ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
314
|
+
}
|
|
315
|
+
const choice = resolveDurableModelChoice(modelId, options?.cachedModels, options?.agentDir);
|
|
316
|
+
const provider = choice?.provider;
|
|
317
|
+
const bareModelId = choice?.modelId;
|
|
318
|
+
// 1. 尝试从已装配的 models 容器中取
|
|
319
|
+
if (options?.modelsContainer && typeof options.modelsContainer.getModel === "function" && provider && bareModelId) {
|
|
320
|
+
try {
|
|
321
|
+
const m = options.modelsContainer.getModel(provider, bareModelId);
|
|
322
|
+
if (m) {
|
|
323
|
+
return calculateSupportedThinkingLevels(m);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
catch {
|
|
327
|
+
/* ignore */
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
// 2. 尝试从 models.json 中取
|
|
331
|
+
try {
|
|
332
|
+
const { providers } = readModelsJson(options?.agentDir);
|
|
333
|
+
if (provider && providers[provider]?.models && Array.isArray(providers[provider].models)) {
|
|
334
|
+
const list = providers[provider].models;
|
|
335
|
+
const found = list.find((m) => m.id === bareModelId);
|
|
336
|
+
if (found) {
|
|
337
|
+
return calculateSupportedThinkingLevels(found);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// 若按 provider 未匹配,遍历所有 provider 寻找裸模型 ID 匹配
|
|
341
|
+
for (const pConfig of Object.values(providers)) {
|
|
342
|
+
if (Array.isArray(pConfig?.models)) {
|
|
343
|
+
const found = pConfig.models.find((m) => m.id === bareModelId);
|
|
344
|
+
if (found) {
|
|
345
|
+
return calculateSupportedThinkingLevels(found);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
/* ignore */
|
|
352
|
+
}
|
|
353
|
+
// 3. 尝试从 models-store.json 中取
|
|
354
|
+
try {
|
|
355
|
+
const userAgentDir = options?.agentDir || join(homedir(), ".pi", "agent");
|
|
356
|
+
const storePath = join(userAgentDir, "models-store.json");
|
|
357
|
+
if (existsSync(storePath)) {
|
|
358
|
+
const store = JSON.parse(readFileSync(storePath, "utf8"));
|
|
359
|
+
if (provider && Array.isArray(store[provider]?.models)) {
|
|
360
|
+
const found = store[provider].models.find((m) => m.id === bareModelId);
|
|
361
|
+
if (found) {
|
|
362
|
+
return calculateSupportedThinkingLevels(found);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
// 若按 provider 未匹配,遍历 store 所有 provider 寻找裸模型 ID 匹配
|
|
366
|
+
for (const pData of Object.values(store)) {
|
|
367
|
+
if (Array.isArray(pData?.models)) {
|
|
368
|
+
const found = pData.models.find((m) => m.id === bareModelId);
|
|
369
|
+
if (found) {
|
|
370
|
+
return calculateSupportedThinkingLevels(found);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
/* ignore */
|
|
378
|
+
}
|
|
379
|
+
// 4. 尝试从 cachedModels 中取
|
|
380
|
+
if (options?.cachedModels && options.cachedModels.length > 0) {
|
|
381
|
+
const found = options.cachedModels.find((m) => m.id === modelId ||
|
|
382
|
+
m.id.endsWith(`/${bareModelId}`) ||
|
|
383
|
+
(provider && m.provider === provider && m.id.endsWith(bareModelId)));
|
|
384
|
+
if (found && found.reasoning === false) {
|
|
385
|
+
return ["off"];
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
// 未明确识别或通用兜底
|
|
389
|
+
return ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
390
|
+
}
|
|
@@ -2,7 +2,3 @@
|
|
|
2
2
|
* server/durable/index.ts — Pi Durable 独立智能体引擎模块统一出口。
|
|
3
3
|
*/
|
|
4
4
|
export { DurableAgentService } from "./durable-agent-service.js";
|
|
5
|
-
export { DurableAgentDriver } from "./durable-driver.js";
|
|
6
|
-
export { openDurableStorage } from "./durable-storage.js";
|
|
7
|
-
export { setupDurableRegistry } from "./durable-tools.js";
|
|
8
|
-
export { DEFAULT_DURABLE_CAPABILITIES, resolveDurableCapabilities } from "./durable-capabilities.js";
|
|
@@ -34,20 +34,47 @@ const CACHE_TTL_MS = 5000;
|
|
|
34
34
|
/** 远端 npm registry 查询缓存:5 分钟 */
|
|
35
35
|
const REGISTRY_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
36
36
|
const registryCache = new Map();
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
/** 引擎状态原子字典:单一事实源,收敛 status / probedAt / updating 三元组,杜绝独立状态撕裂 */
|
|
38
|
+
const engineRegistry = new Map([
|
|
39
|
+
[
|
|
40
|
+
"pi",
|
|
41
|
+
{
|
|
42
|
+
status: { id: "pi", installed: true, packageName: ENGINE_PACKAGES.pi.packageName, version: VERSION },
|
|
43
|
+
probedAt: 0,
|
|
44
|
+
updating: false,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
"dsh",
|
|
49
|
+
{
|
|
50
|
+
status: { id: "dsh", installed: false, packageName: ENGINE_PACKAGES.dsh.packageName },
|
|
51
|
+
probedAt: 0,
|
|
52
|
+
updating: false,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
"claude",
|
|
57
|
+
{
|
|
58
|
+
status: { id: "claude", installed: false, packageName: ENGINE_PACKAGES.claude.packageName },
|
|
59
|
+
probedAt: 0,
|
|
60
|
+
updating: false,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
"durable",
|
|
65
|
+
{
|
|
66
|
+
status: { id: "durable", installed: false, packageName: ENGINE_PACKAGES.durable.packageName },
|
|
67
|
+
probedAt: 0,
|
|
68
|
+
updating: false,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
]);
|
|
72
|
+
function toPublicStatus(entry) {
|
|
73
|
+
return {
|
|
74
|
+
...entry.status,
|
|
75
|
+
...(entry.updating ? { updating: true } : {}),
|
|
76
|
+
};
|
|
44
77
|
}
|
|
45
|
-
let cachedStatuses = [
|
|
46
|
-
{ id: "pi", installed: true, packageName: ENGINE_PACKAGES.pi.packageName, version: VERSION },
|
|
47
|
-
{ id: "dsh", installed: false, packageName: ENGINE_PACKAGES.dsh.packageName },
|
|
48
|
-
{ id: "claude", installed: false, packageName: ENGINE_PACKAGES.claude.packageName },
|
|
49
|
-
{ id: "durable", installed: false, packageName: ENGINE_PACKAGES.durable.packageName },
|
|
50
|
-
];
|
|
51
78
|
/**
|
|
52
79
|
* 查询全局包在 npm 远端的最新版本号(带 5 分钟缓存)。
|
|
53
80
|
*/
|
|
@@ -179,20 +206,39 @@ export async function probeDsh() {
|
|
|
179
206
|
/**
|
|
180
207
|
* 探测 Claude Code 引擎状态。
|
|
181
208
|
*/
|
|
182
|
-
export async function probeClaude() {
|
|
209
|
+
export async function probeClaude(force = false) {
|
|
183
210
|
const pkgName = ENGINE_PACKAGES.claude.packageName;
|
|
184
211
|
try {
|
|
185
212
|
const res = await probeClaudeCode();
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
213
|
+
if (res.installed) {
|
|
214
|
+
return {
|
|
215
|
+
id: "claude",
|
|
216
|
+
installed: true,
|
|
217
|
+
packageName: pkgName,
|
|
218
|
+
version: res.version,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
/* ignore */
|
|
224
|
+
}
|
|
225
|
+
// 降级兜底:某些环境(如 fnm/nvm 目录未生成直接软链,或全局通过 npm 安装了包但 postinstall 尚未就绪)
|
|
226
|
+
// 尝试通过全局包管理器探测是否已安装该包
|
|
227
|
+
try {
|
|
228
|
+
const globalProbe = probeGlobalPackage(pkgName, { refresh: force });
|
|
229
|
+
if (globalProbe.installed) {
|
|
230
|
+
return {
|
|
231
|
+
id: "claude",
|
|
232
|
+
installed: true,
|
|
233
|
+
packageName: pkgName,
|
|
234
|
+
version: globalProbe.version,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
192
237
|
}
|
|
193
238
|
catch {
|
|
194
|
-
|
|
239
|
+
/* ignore */
|
|
195
240
|
}
|
|
241
|
+
return { id: "claude", installed: false, packageName: pkgName };
|
|
196
242
|
}
|
|
197
243
|
/**
|
|
198
244
|
* 探测 Pi Durable 引擎状态。
|
|
@@ -222,65 +268,77 @@ export async function probeDurable(force = false) {
|
|
|
222
268
|
export async function probeEngine(id, force = false) {
|
|
223
269
|
if (id === "pi")
|
|
224
270
|
return probePi();
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return found;
|
|
271
|
+
const entry = engineRegistry.get(id);
|
|
272
|
+
if (!force && entry && entry.probedAt > 0 && Date.now() - entry.probedAt < CACHE_TTL_MS) {
|
|
273
|
+
return toPublicStatus(entry);
|
|
229
274
|
}
|
|
230
275
|
let result;
|
|
231
276
|
if (id === "dsh") {
|
|
232
277
|
result = await probeDsh();
|
|
233
278
|
}
|
|
234
279
|
else if (id === "claude") {
|
|
235
|
-
result = await probeClaude();
|
|
280
|
+
result = await probeClaude(force);
|
|
236
281
|
}
|
|
237
282
|
else if (id === "durable") {
|
|
238
|
-
result = await probeDurable();
|
|
283
|
+
result = await probeDurable(force);
|
|
239
284
|
}
|
|
240
285
|
else {
|
|
241
286
|
result = { id: id, installed: false };
|
|
242
287
|
}
|
|
243
288
|
await enrichWithUpdateInfo(result, force);
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
else
|
|
249
|
-
cachedStatuses.push(result);
|
|
250
|
-
return {
|
|
251
|
-
...result,
|
|
252
|
-
...(updatingEngineIds.has(id) ? { updating: true } : {}),
|
|
289
|
+
const updatedEntry = {
|
|
290
|
+
status: result,
|
|
291
|
+
probedAt: Date.now(),
|
|
292
|
+
updating: entry?.updating ?? false,
|
|
253
293
|
};
|
|
294
|
+
engineRegistry.set(id, updatedEntry);
|
|
295
|
+
return toPublicStatus(updatedEntry);
|
|
254
296
|
}
|
|
255
297
|
/**
|
|
256
298
|
* 探测全部已知引擎并返回最新状态列表(带 TTL 缓存防抖)。
|
|
257
299
|
*/
|
|
258
300
|
export async function probeAllEngines(force = false) {
|
|
259
|
-
|
|
260
|
-
|
|
301
|
+
const now = Date.now();
|
|
302
|
+
const entries = Array.from(engineRegistry.values());
|
|
303
|
+
const allFresh = entries.every((e) => e.probedAt > 0 && now - e.probedAt < CACHE_TTL_MS);
|
|
304
|
+
if (!force && allFresh && entries.length > 0) {
|
|
305
|
+
return entries.map(toPublicStatus);
|
|
261
306
|
}
|
|
262
|
-
const [pi, dsh, claude, durable] = await Promise.all([
|
|
307
|
+
const [pi, dsh, claude, durable] = await Promise.all([
|
|
308
|
+
probePi(),
|
|
309
|
+
probeDsh(),
|
|
310
|
+
probeClaude(force),
|
|
311
|
+
probeDurable(force),
|
|
312
|
+
]);
|
|
263
313
|
await Promise.all([
|
|
264
314
|
enrichWithUpdateInfo(pi, force),
|
|
265
315
|
enrichWithUpdateInfo(dsh, force),
|
|
266
316
|
enrichWithUpdateInfo(claude, force),
|
|
267
317
|
enrichWithUpdateInfo(durable, force),
|
|
268
318
|
]);
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
319
|
+
const timestamp = Date.now();
|
|
320
|
+
const results = [pi, dsh, claude, durable];
|
|
321
|
+
for (const res of results) {
|
|
322
|
+
const existing = engineRegistry.get(res.id);
|
|
323
|
+
engineRegistry.set(res.id, {
|
|
324
|
+
status: res,
|
|
325
|
+
probedAt: timestamp,
|
|
326
|
+
updating: existing?.updating ?? false,
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
return Array.from(engineRegistry.values()).map(toPublicStatus);
|
|
272
330
|
}
|
|
273
331
|
/**
|
|
274
332
|
* 同步获取当前缓存的引擎探测结果(握手帧或即时读取使用)。
|
|
275
333
|
*/
|
|
276
334
|
export function getCachedEngineStatuses() {
|
|
277
|
-
return
|
|
335
|
+
return Array.from(engineRegistry.values()).map(toPublicStatus);
|
|
278
336
|
}
|
|
279
337
|
/**
|
|
280
338
|
* 查询指定引擎是否正在执行后台更新子进程。
|
|
281
339
|
*/
|
|
282
340
|
export function isEngineUpdating(engineId) {
|
|
283
|
-
return
|
|
341
|
+
return engineRegistry.get(engineId)?.updating ?? false;
|
|
284
342
|
}
|
|
285
343
|
/**
|
|
286
344
|
* 在后台子进程中执行引擎全局包更新(npm i -g <pkg>@latest)。
|
|
@@ -291,10 +349,12 @@ export async function updateEngineBackground(engineId, options) {
|
|
|
291
349
|
if (!meta || !meta.packageName) {
|
|
292
350
|
return { ok: false, error: `不支持或未知的引擎「${engineId}」` };
|
|
293
351
|
}
|
|
294
|
-
|
|
352
|
+
const currentEntry = engineRegistry.get(engineId);
|
|
353
|
+
if (currentEntry?.updating) {
|
|
295
354
|
return { ok: false, error: `引擎「${engineId}」正在后台更新中,请勿重复操作` };
|
|
296
355
|
}
|
|
297
|
-
|
|
356
|
+
if (currentEntry)
|
|
357
|
+
currentEntry.updating = true;
|
|
298
358
|
const pkg = meta.packageName;
|
|
299
359
|
const timeoutMs = Math.max(10_000, Number(options?.timeoutMs ?? 300_000));
|
|
300
360
|
const isWin = process.platform === "win32";
|
|
@@ -367,7 +427,9 @@ export async function updateEngineBackground(engineId, options) {
|
|
|
367
427
|
};
|
|
368
428
|
}
|
|
369
429
|
finally {
|
|
370
|
-
|
|
430
|
+
const finalEntry = engineRegistry.get(engineId);
|
|
431
|
+
if (finalEntry)
|
|
432
|
+
finalEntry.updating = false;
|
|
371
433
|
}
|
|
372
434
|
}
|
|
373
435
|
/**
|
|
@@ -375,7 +437,8 @@ export async function updateEngineBackground(engineId, options) {
|
|
|
375
437
|
*/
|
|
376
438
|
export function collectInstalledEngineTargets() {
|
|
377
439
|
const out = [];
|
|
378
|
-
for (const
|
|
440
|
+
for (const entry of engineRegistry.values()) {
|
|
441
|
+
const status = entry.status;
|
|
379
442
|
// pi-core 在 collectTargets 中已有独立专属条目(PI_CORE_PACKAGE),此处收纳其他已安装引擎全局包
|
|
380
443
|
if (status.id !== "pi" && status.installed && status.packageName && status.version) {
|
|
381
444
|
out.push({
|
package/dist/server/eval-tool.js
CHANGED
|
@@ -70,6 +70,16 @@ function resolvePythonCmd() {
|
|
|
70
70
|
const PYTHON_DRIVER_SCRIPT = `
|
|
71
71
|
import sys, io, ast, json, traceback, os
|
|
72
72
|
|
|
73
|
+
# 跨平台编码对齐:Windows 默认代码页(如 CP936/GBK)读取 UTF-8 管道会导致多字节截断、
|
|
74
|
+
# 反斜杠被吞噬破坏 JSON 结构(报 Expecting ',' delimiter)或触发 UnicodeDecodeError。
|
|
75
|
+
# 强制标准流一律按 UTF-8 重配并附带容错替换策略,避免解码死锁。
|
|
76
|
+
if hasattr(sys.stdin, "reconfigure"):
|
|
77
|
+
sys.stdin.reconfigure(encoding="utf-8", errors="replace")
|
|
78
|
+
if hasattr(sys.stdout, "reconfigure"):
|
|
79
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="backslashreplace")
|
|
80
|
+
if hasattr(sys.stderr, "reconfigure"):
|
|
81
|
+
sys.stderr.reconfigure(encoding="utf-8", errors="backslashreplace")
|
|
82
|
+
|
|
73
83
|
WORKDIR = os.environ.get('PI_EVAL_WORKDIR', '')
|
|
74
84
|
PROJECT_DIR = os.environ.get('PI_EVAL_PROJECT_DIR', '')
|
|
75
85
|
|
|
@@ -119,7 +129,7 @@ for line in sys.stdin:
|
|
|
119
129
|
except Exception as e:
|
|
120
130
|
resp = {'ok': False, 'stdout': '', 'stderr': '', 'result': None, 'error': traceback.format_exc()}
|
|
121
131
|
|
|
122
|
-
sys.stdout.write('__PI_EVAL_RES__' + json.dumps(resp, ensure_ascii=
|
|
132
|
+
sys.stdout.write('__PI_EVAL_RES__' + json.dumps(resp, ensure_ascii=True) + '\\n')
|
|
123
133
|
sys.stdout.flush()
|
|
124
134
|
`;
|
|
125
135
|
const NODE_DRIVER_SCRIPT = `
|
|
@@ -247,6 +257,19 @@ export function sanitizeEvalEnv(sourceEnv) {
|
|
|
247
257
|
}
|
|
248
258
|
return cleanEnv;
|
|
249
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* 传输层 ASCII 安全序列化:
|
|
262
|
+
* 将所有非 ASCII 字符(> 0x7F,含中文、特殊符号与 Emoji 代理对)转义为标准 JSON \uXXXX 格式。
|
|
263
|
+
* 纯 7-bit ASCII 传输流在跨平台任何操作系统本地代码页(如 Windows CP936/GBK/Shift-JIS)下
|
|
264
|
+
* 绝不会发生反斜杠 0x5C 被多字节汉字首字节“吞噬”导致 JSON 结构损毁或崩溃的问题。
|
|
265
|
+
*/
|
|
266
|
+
export function toAsciiJson(data) {
|
|
267
|
+
const raw = JSON.stringify(data);
|
|
268
|
+
if (!/[^\x00-\x7F]/.test(raw)) {
|
|
269
|
+
return raw;
|
|
270
|
+
}
|
|
271
|
+
return raw.replace(/[^\x00-\x7F]/g, (c) => "\\u" + c.charCodeAt(0).toString(16).padStart(4, "0"));
|
|
272
|
+
}
|
|
250
273
|
/** 单个持久内核工作进程包装。 */
|
|
251
274
|
class EvalKernel {
|
|
252
275
|
language;
|
|
@@ -277,6 +300,8 @@ class EvalKernel {
|
|
|
277
300
|
...sanitizeEvalEnv(process.env),
|
|
278
301
|
PI_EVAL_WORKDIR: this.workdir,
|
|
279
302
|
PI_EVAL_PROJECT_DIR: this.cwd,
|
|
303
|
+
PYTHONUTF8: "1",
|
|
304
|
+
PYTHONIOENCODING: "utf-8",
|
|
280
305
|
},
|
|
281
306
|
};
|
|
282
307
|
if (this.language === "py") {
|
|
@@ -284,7 +309,7 @@ class EvalKernel {
|
|
|
284
309
|
if (!pyCmd) {
|
|
285
310
|
throw new Error("Python executable not found in PATH. Please install Python or use language: 'js'.");
|
|
286
311
|
}
|
|
287
|
-
this.proc = spawn(pyCmd, ["-u", "-c", PYTHON_DRIVER_SCRIPT], spawnOpts);
|
|
312
|
+
this.proc = spawn(pyCmd, ["-X", "utf8", "-u", "-c", PYTHON_DRIVER_SCRIPT], spawnOpts);
|
|
288
313
|
}
|
|
289
314
|
else {
|
|
290
315
|
// js / ts:独立 node -e 驱动,ts 时带 --experimental-strip-types 支持 TypeScript 原生剥离执行。
|
|
@@ -403,7 +428,7 @@ class EvalKernel {
|
|
|
403
428
|
const item = this.queue.shift();
|
|
404
429
|
this.current = item;
|
|
405
430
|
try {
|
|
406
|
-
this.proc.stdin.write(
|
|
431
|
+
this.proc.stdin.write(toAsciiJson(item.req) + "\n");
|
|
407
432
|
}
|
|
408
433
|
catch (err) {
|
|
409
434
|
this.current = null;
|
|
@@ -1531,6 +1531,13 @@ export class GoalService {
|
|
|
1531
1531
|
}
|
|
1532
1532
|
conv.goal.phase = "idle";
|
|
1533
1533
|
}
|
|
1534
|
+
/** 会话关闭/移除时(removeConversation)彻底终止目标循环并清理关联的执行者与向导。 */
|
|
1535
|
+
notifyConversationRemoved(conv) {
|
|
1536
|
+
this.notifyTakeover(conv);
|
|
1537
|
+
if (this.wizardOwnerId === conv.id) {
|
|
1538
|
+
void this.abortWizard();
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1534
1541
|
/** 读某会话累计用量(取不到返回 undefined;getSessionStats 会遍历转写,只在轮次边界调)。 */
|
|
1535
1542
|
sessionUsage(session) {
|
|
1536
1543
|
try {
|