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
package/dist/server/terminals.js
CHANGED
|
@@ -900,12 +900,62 @@ export function encodeTerminalKey(key, modifiers = {}) {
|
|
|
900
900
|
}
|
|
901
901
|
return { data };
|
|
902
902
|
}
|
|
903
|
+
/**
|
|
904
|
+
* 终端行输入流状态机解析(纯函数,issue #721)。
|
|
905
|
+
*
|
|
906
|
+
* 结合前次未完成的行缓冲与本次输入字符,按换行符(CR / LF / CRLF)切分出
|
|
907
|
+
* 全部已闭合的完整命令行,并正确处理退格(Backspace)与中断清除(Ctrl+C / Ctrl+U)。
|
|
908
|
+
*/
|
|
909
|
+
export function parseTerminalLineStream(previousPending, inputChunk) {
|
|
910
|
+
const completedLines = [];
|
|
911
|
+
let current = previousPending;
|
|
912
|
+
let i = 0;
|
|
913
|
+
while (i < inputChunk.length) {
|
|
914
|
+
const ch = inputChunk[i];
|
|
915
|
+
if (ch === "\r" || ch === "\n") {
|
|
916
|
+
completedLines.push(current);
|
|
917
|
+
current = "";
|
|
918
|
+
// 处理 CRLF 双字符换行:若为 \r 且后一个字符是 \n,跳过后续 \n
|
|
919
|
+
if (ch === "\r" && i + 1 < inputChunk.length && inputChunk[i + 1] === "\n") {
|
|
920
|
+
i++;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
else if (ch === "\x03" || ch === "\x15") {
|
|
924
|
+
// Ctrl+C (ETX) 或 Ctrl+U (NAK) 清除当前行
|
|
925
|
+
current = "";
|
|
926
|
+
}
|
|
927
|
+
else if (ch === "\x7f" || ch === "\x08") {
|
|
928
|
+
// 退格键 Backspace
|
|
929
|
+
if (current.length > 0) {
|
|
930
|
+
current = current.slice(0, -1);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
else {
|
|
934
|
+
current += ch;
|
|
935
|
+
}
|
|
936
|
+
i++;
|
|
937
|
+
}
|
|
938
|
+
return {
|
|
939
|
+
completedLines,
|
|
940
|
+
remainingPending: current,
|
|
941
|
+
};
|
|
942
|
+
}
|
|
903
943
|
/**
|
|
904
944
|
* Owns one or more PTYs for a conversation. All output is forwarded as
|
|
905
945
|
* `terminal_output` messages through the provided emit (broadcast to every
|
|
906
946
|
* socket attached to the client session). Failed spawns emit an error notice and
|
|
907
947
|
* terminal_exit instead of throwing into the WebSocket dispatcher.
|
|
908
948
|
*/
|
|
949
|
+
/**
|
|
950
|
+
* 识别是否属于终端仿真器自动回传的握手/探测序列(如光标位置报告 CPR、设备属性 DA1/DA2、焦点通知等)。
|
|
951
|
+
* 这些序列由 xterm.js 接收到 Shell/ConPTY 发出的探针后自动回复,绝非用户真实键盘输入。
|
|
952
|
+
* 收到此类自动响应时不应把 pristine 裸 shell 标记为 used,否则点开终端自动建的空 shell 会被永久误判为
|
|
953
|
+
* “用户动过的终端”并阻断会话移出。
|
|
954
|
+
*/
|
|
955
|
+
export const TERMINAL_QUERY_RESPONSE_RE = /^(?:\x1b\[(?:\??|>|<)?\d*(?:;\d+)*(?:\$?y|[cRnIOt])|\x1b\]\d+;[^\x07\x1b]*(?:\x07|\x1b\\))+$/;
|
|
956
|
+
export function isTerminalQueryResponse(data) {
|
|
957
|
+
return TERMINAL_QUERY_RESPONSE_RE.test(data);
|
|
958
|
+
}
|
|
909
959
|
export class TerminalManager {
|
|
910
960
|
emit;
|
|
911
961
|
workspaceRoot;
|
|
@@ -919,6 +969,22 @@ export class TerminalManager {
|
|
|
919
969
|
/** 宿主回调:AI 触碰过的终端静默 ≥ 阈值时触发(一次性/纪元语义见
|
|
920
970
|
* noteAgentActivity)。宿主自行判断会话是否在运行并决定是否注入。 */
|
|
921
971
|
onAgentIdle = null;
|
|
972
|
+
/** 获取该终端当前被 AI 累积但尚未提交的命令行(issue #721) */
|
|
973
|
+
getAgentPendingLine(id) {
|
|
974
|
+
return this.terms.get(id)?.agentPendingLine ?? "";
|
|
975
|
+
}
|
|
976
|
+
/** 设置该终端 AI 累积的待提交行(issue #721) */
|
|
977
|
+
setAgentPendingLine(id, line) {
|
|
978
|
+
const entry = this.terms.get(id);
|
|
979
|
+
if (entry)
|
|
980
|
+
entry.agentPendingLine = line;
|
|
981
|
+
}
|
|
982
|
+
/** 清空该终端 AI 累积的待提交行(issue #721) */
|
|
983
|
+
clearAgentPendingLine(id) {
|
|
984
|
+
const entry = this.terms.get(id);
|
|
985
|
+
if (entry)
|
|
986
|
+
entry.agentPendingLine = "";
|
|
987
|
+
}
|
|
922
988
|
constructor(emit, workspaceRoot,
|
|
923
989
|
// issue #91:按键/输入校验错误按客户端 UI 语言出中英(英文默认)。
|
|
924
990
|
lang) {
|
|
@@ -1171,6 +1237,7 @@ export class TerminalManager {
|
|
|
1171
1237
|
// noteAgentActivity)。
|
|
1172
1238
|
used: agentBash || command !== undefined,
|
|
1173
1239
|
locale,
|
|
1240
|
+
agentPendingLine: "",
|
|
1174
1241
|
};
|
|
1175
1242
|
this.terms.set(id, entry);
|
|
1176
1243
|
// The closures capture `entry`: after a restart the map points at the
|
|
@@ -1480,12 +1547,14 @@ export class TerminalManager {
|
|
|
1480
1547
|
return pick(this.lang?.() ?? "en", "终端不存在或进程已退出", "Terminal not found or its process has exited", "terminals.not.found.exited");
|
|
1481
1548
|
// 已武装的纪元里任何人(含用户手动敲键盘)写了输入都算新活动,重置倒计时。
|
|
1482
1549
|
// 成功的输入同时把终端标为“用过”(见 used):动过的 shell 才参与对话保留/
|
|
1483
|
-
// 关闭拦截,没动过的空 shell
|
|
1550
|
+
// 关闭拦截,没动过的空 shell 不算。仿真器自动应答探针(CPR/DA 等)不计入用过。
|
|
1484
1551
|
entry.lastActivityAt = Date.now();
|
|
1485
1552
|
if (entry.idleTimer)
|
|
1486
1553
|
this.armIdleWatch(entry);
|
|
1487
1554
|
entry.pty.write(data);
|
|
1488
|
-
|
|
1555
|
+
if (data.length > 0 && !isTerminalQueryResponse(data)) {
|
|
1556
|
+
entry.used = true;
|
|
1557
|
+
}
|
|
1489
1558
|
return null;
|
|
1490
1559
|
}
|
|
1491
1560
|
key(id, key, modifiers = {}) {
|
|
@@ -1642,6 +1711,9 @@ export class TerminalManager {
|
|
|
1642
1711
|
this.emitList();
|
|
1643
1712
|
}
|
|
1644
1713
|
input(id, data) {
|
|
1714
|
+
if (data.includes("\r") || data.includes("\n") || data.includes("\x03")) {
|
|
1715
|
+
this.clearAgentPendingLine(id);
|
|
1716
|
+
}
|
|
1645
1717
|
void this.inputChecked(id, data);
|
|
1646
1718
|
}
|
|
1647
1719
|
resize(id, cols, rows) {
|
|
@@ -2207,6 +2279,30 @@ lang, options) {
|
|
|
2207
2279
|
if (error)
|
|
2208
2280
|
throw new Error(error);
|
|
2209
2281
|
};
|
|
2282
|
+
// 针对单测或外部 mock 的行缓冲兜底支持
|
|
2283
|
+
const fallbackPending = new Map();
|
|
2284
|
+
const getPending = (id) => {
|
|
2285
|
+
if (typeof terminals.getAgentPendingLine === "function") {
|
|
2286
|
+
return terminals.getAgentPendingLine(id);
|
|
2287
|
+
}
|
|
2288
|
+
return fallbackPending.get(id) ?? "";
|
|
2289
|
+
};
|
|
2290
|
+
const setPending = (id, line) => {
|
|
2291
|
+
if (typeof terminals.setAgentPendingLine === "function") {
|
|
2292
|
+
terminals.setAgentPendingLine(id, line);
|
|
2293
|
+
}
|
|
2294
|
+
else {
|
|
2295
|
+
fallbackPending.set(id, line);
|
|
2296
|
+
}
|
|
2297
|
+
};
|
|
2298
|
+
const clearPending = (id) => {
|
|
2299
|
+
if (typeof terminals.clearAgentPendingLine === "function") {
|
|
2300
|
+
terminals.clearAgentPendingLine(id);
|
|
2301
|
+
}
|
|
2302
|
+
else {
|
|
2303
|
+
fallbackPending.delete(id);
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2210
2306
|
return [
|
|
2211
2307
|
defineTool({
|
|
2212
2308
|
name: "terminal_create",
|
|
@@ -2265,13 +2361,54 @@ lang, options) {
|
|
|
2265
2361
|
parameters: Type.Object({ terminalId: Type.String(), data: Type.String() }),
|
|
2266
2362
|
execute: async (_id, p) => {
|
|
2267
2363
|
const lang = getLang();
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2364
|
+
const prevPending = getPending(p.terminalId);
|
|
2365
|
+
const parsed = parseTerminalLineStream(prevPending, p.data);
|
|
2366
|
+
if (options?.checkSafety && parsed.completedLines.length > 0) {
|
|
2367
|
+
for (const line of parsed.completedLines) {
|
|
2368
|
+
const cleanCmd = stripAnsi(line).trim();
|
|
2369
|
+
if (!cleanCmd)
|
|
2370
|
+
continue;
|
|
2371
|
+
const safety = await options.checkSafety(cleanCmd, {
|
|
2372
|
+
terminalId: p.terminalId,
|
|
2373
|
+
toolCallId: _id,
|
|
2374
|
+
toolName: "terminal_input",
|
|
2375
|
+
});
|
|
2376
|
+
if (safety.blocked) {
|
|
2377
|
+
// 发现阻断:若终端此前已留有未提交字符,发送 \x03 取消当前行
|
|
2378
|
+
if (prevPending) {
|
|
2379
|
+
try {
|
|
2380
|
+
terminals.inputChecked(p.terminalId, "\x03");
|
|
2381
|
+
}
|
|
2382
|
+
catch {
|
|
2383
|
+
// ignore
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
clearPending(p.terminalId);
|
|
2387
|
+
const reason = pick(lang, safety.reason ?? "", safety.reasonEn ?? safety.reason ?? "");
|
|
2388
|
+
const reasonSuffix = reason ? (lang === "zh" ? ` 原因:${reason}` : ` Reason: ${reason}`) : "";
|
|
2389
|
+
throw new Error(safety.userDenied
|
|
2390
|
+
? pick(lang, `【操作被用户拒绝】${reasonSuffix}`, `[Operation denied by user]${reasonSuffix}`, "terminals.operation.denied", { reasonSuffix })
|
|
2391
|
+
: pick(lang, `【终端输入命令被安全规则阻断】${reasonSuffix}`, `[Terminal command blocked by safety rule]${reasonSuffix}`, "terminals.command.blocked", { reasonSuffix }));
|
|
2392
|
+
}
|
|
2393
|
+
if (safety.editedCommand !== undefined) {
|
|
2394
|
+
// 用户通过审批改写了命令
|
|
2395
|
+
if (prevPending) {
|
|
2396
|
+
try {
|
|
2397
|
+
terminals.inputChecked(p.terminalId, "\x03");
|
|
2398
|
+
}
|
|
2399
|
+
catch {
|
|
2400
|
+
// ignore
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
clearPending(p.terminalId);
|
|
2404
|
+
failIf(terminals.inputChecked(p.terminalId, safety.editedCommand + "\r"));
|
|
2405
|
+
terminals.noteAgentActivity(p.terminalId);
|
|
2406
|
+
return result(pick(lang, `已发送改写后的命令到 ${p.terminalId}:${safety.editedCommand}`, `Sent edited command to ${p.terminalId}: ${safety.editedCommand}`, "terminals.input.edited_sent", { command: safety.editedCommand, "p.terminalId": p.terminalId }));
|
|
2407
|
+
}
|
|
2272
2408
|
}
|
|
2273
2409
|
}
|
|
2274
2410
|
failIf(terminals.inputChecked(p.terminalId, p.data));
|
|
2411
|
+
setPending(p.terminalId, parsed.remainingPending);
|
|
2275
2412
|
// AI 发了输入 = 在等结果,重开一个静默纪元。
|
|
2276
2413
|
terminals.noteAgentActivity(p.terminalId);
|
|
2277
2414
|
return result(pick(lang, `已发送 ${p.data.length} 个字符到 ${p.terminalId}`, `Sent ${p.data.length} chars to ${p.terminalId}`, "terminals.input.sent", { "p.data.length": p.data.length, "p.terminalId": p.terminalId }));
|
|
@@ -2294,8 +2431,59 @@ lang, options) {
|
|
|
2294
2431
|
}),
|
|
2295
2432
|
execute: async (_id, p) => {
|
|
2296
2433
|
const lang = getLang();
|
|
2297
|
-
|
|
2298
|
-
|
|
2434
|
+
const encoded = encodeTerminalKey(p.key, p.modifiers);
|
|
2435
|
+
if ("error" in encoded)
|
|
2436
|
+
throw new Error(encoded.error);
|
|
2437
|
+
const isEnter = encoded.data.includes("\r") || encoded.data.includes("\n");
|
|
2438
|
+
if (isEnter) {
|
|
2439
|
+
const pending = getPending(p.terminalId);
|
|
2440
|
+
const cleanCmd = stripAnsi(pending).trim();
|
|
2441
|
+
if (options?.checkSafety && cleanCmd) {
|
|
2442
|
+
const safety = await options.checkSafety(cleanCmd, {
|
|
2443
|
+
terminalId: p.terminalId,
|
|
2444
|
+
toolCallId: _id,
|
|
2445
|
+
toolName: "terminal_key",
|
|
2446
|
+
});
|
|
2447
|
+
if (safety.blocked) {
|
|
2448
|
+
// 阻断 Enter 提交:发送 \x03 冲刷取消终端屏幕残留的脏命令
|
|
2449
|
+
try {
|
|
2450
|
+
terminals.inputChecked(p.terminalId, "\x03");
|
|
2451
|
+
}
|
|
2452
|
+
catch {
|
|
2453
|
+
// ignore
|
|
2454
|
+
}
|
|
2455
|
+
clearPending(p.terminalId);
|
|
2456
|
+
const reason = pick(lang, safety.reason ?? "", safety.reasonEn ?? safety.reason ?? "");
|
|
2457
|
+
const reasonSuffix = reason ? (lang === "zh" ? ` 原因:${reason}` : ` Reason: ${reason}`) : "";
|
|
2458
|
+
throw new Error(safety.userDenied
|
|
2459
|
+
? pick(lang, `【操作被用户拒绝】${reasonSuffix}`, `[Operation denied by user]${reasonSuffix}`, "terminals.operation.denied", { reasonSuffix })
|
|
2460
|
+
: pick(lang, `【终端输入命令被安全规则阻断】${reasonSuffix}`, `[Terminal command blocked by safety rule]${reasonSuffix}`, "terminals.command.blocked", { reasonSuffix }));
|
|
2461
|
+
}
|
|
2462
|
+
if (safety.editedCommand !== undefined) {
|
|
2463
|
+
// 用户在审批弹窗中改写了命令:先取消原行,再提交改写后的命令
|
|
2464
|
+
try {
|
|
2465
|
+
terminals.inputChecked(p.terminalId, "\x03");
|
|
2466
|
+
}
|
|
2467
|
+
catch {
|
|
2468
|
+
// ignore
|
|
2469
|
+
}
|
|
2470
|
+
clearPending(p.terminalId);
|
|
2471
|
+
failIf(terminals.inputChecked(p.terminalId, safety.editedCommand + "\r"));
|
|
2472
|
+
terminals.noteAgentActivity(p.terminalId);
|
|
2473
|
+
return result(pick(lang, `已发送改写后的命令到 ${p.terminalId}:${safety.editedCommand}`, `Sent edited command to ${p.terminalId}: ${safety.editedCommand}`, "terminals.key.edited_sent", { command: safety.editedCommand, "p.terminalId": p.terminalId }));
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
// 提交回车成功
|
|
2477
|
+
failIf(terminals.inputChecked(p.terminalId, encoded.data));
|
|
2478
|
+
clearPending(p.terminalId);
|
|
2479
|
+
terminals.noteAgentActivity(p.terminalId);
|
|
2480
|
+
return result(pick(lang, `已发送按键 ${p.key} 到 ${p.terminalId}`, `Sent key ${p.key} to ${p.terminalId}`, "terminals.key.sent", { "p.key": p.key, "p.terminalId": p.terminalId }));
|
|
2481
|
+
}
|
|
2482
|
+
// 非回车按键:若为退格或清除键,更新 pending 缓冲
|
|
2483
|
+
const prev = getPending(p.terminalId);
|
|
2484
|
+
const parsed = parseTerminalLineStream(prev, encoded.data);
|
|
2485
|
+
failIf(terminals.inputChecked(p.terminalId, encoded.data));
|
|
2486
|
+
setPending(p.terminalId, parsed.remainingPending);
|
|
2299
2487
|
terminals.noteAgentActivity(p.terminalId);
|
|
2300
2488
|
return result(pick(lang, `已发送按键 ${p.key} 到 ${p.terminalId}`, `Sent key ${p.key} to ${p.terminalId}`, "terminals.key.sent", { "p.key": p.key, "p.terminalId": p.terminalId }));
|
|
2301
2489
|
},
|
|
@@ -62,6 +62,67 @@ export function formatStreamingPrompt(text, textAsides = [], quotes = [], imageN
|
|
|
62
62
|
}
|
|
63
63
|
return parts.join("\n\n");
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* 将附件消息(asides)解构为流式排队/插队可消费的载荷。
|
|
67
|
+
* 统一作为单源解析,杜绝空闲/流式分支错位造成的丢图、漏附件与非视觉模型静默丢弃。
|
|
68
|
+
*/
|
|
69
|
+
export function extractStreamingPayload(asides, initialQuotes = [], mainSupportsVision = false, modelLabel = "unknown") {
|
|
70
|
+
const promptImages = [];
|
|
71
|
+
const textAsides = [];
|
|
72
|
+
const imageNames = [];
|
|
73
|
+
const quotes = [...initialQuotes];
|
|
74
|
+
for (const aside of asides) {
|
|
75
|
+
const details = aside.message?.details;
|
|
76
|
+
const isBridged = details?.mode === "bridged";
|
|
77
|
+
const isQuote = details?.mode === "quote";
|
|
78
|
+
if (isQuote && details?.quote) {
|
|
79
|
+
const q = readTextQuote(details.quote);
|
|
80
|
+
if (q) {
|
|
81
|
+
quotes.push(q);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const rawContent = aside.message?.content;
|
|
86
|
+
if (typeof rawContent === "string") {
|
|
87
|
+
if (rawContent.trim())
|
|
88
|
+
textAsides.push(rawContent.trim());
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const content = Array.isArray(rawContent) ? rawContent : [];
|
|
92
|
+
for (const b of content) {
|
|
93
|
+
if (typeof b === "string") {
|
|
94
|
+
if (b.trim())
|
|
95
|
+
textAsides.push(b.trim());
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (!b || typeof b !== "object")
|
|
99
|
+
continue;
|
|
100
|
+
const block = b;
|
|
101
|
+
if (block.type === "image" && typeof block.data === "string") {
|
|
102
|
+
const imgName = details?.name ?? "image.png";
|
|
103
|
+
if (mainSupportsVision) {
|
|
104
|
+
promptImages.push({
|
|
105
|
+
type: "image",
|
|
106
|
+
data: block.data,
|
|
107
|
+
mimeType: typeof block.mimeType === "string" && block.mimeType ? block.mimeType : "image/png",
|
|
108
|
+
});
|
|
109
|
+
imageNames.push(imgName);
|
|
110
|
+
}
|
|
111
|
+
else if (!isBridged) {
|
|
112
|
+
imageNames.push(imgName);
|
|
113
|
+
textAsides.push(`[Attached image "${imgName}" omitted: model (${modelLabel}) does not support vision]`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (block.type === "text" && typeof block.text === "string" && block.text.trim()) {
|
|
117
|
+
textAsides.push(block.text.trim());
|
|
118
|
+
if (isBridged && details?.name) {
|
|
119
|
+
imageNames.push(details.name);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { promptImages, textAsides, imageNames, quotes };
|
|
125
|
+
}
|
|
65
126
|
/** 排队项把引用与附件随提问一起保存;展示时拆分末尾的引用块与附件标记。 */
|
|
66
127
|
export function splitQuotedPrompt(value) {
|
|
67
128
|
let text = value;
|
|
@@ -17,26 +17,85 @@
|
|
|
17
17
|
* - 本对话「允许同类」→ 该对话内同一规则档位(category)不再弹。
|
|
18
18
|
* 策略只活在内存里(挂在 Conversation 上,过户随对话搬走),重启/新对话即恢复询问。
|
|
19
19
|
*/
|
|
20
|
-
import { DEFAULT_APPROVAL_RULES, evaluateApprovalRules, } from "./approval-rules.js";
|
|
20
|
+
import { DEFAULT_APPROVAL_RULES, evaluateApprovalRules, extractTargetPath, } from "./approval-rules.js";
|
|
21
21
|
/** 策略为空(既没全部允许也没记同类):调用方据此不挂空策略、面板据此不显示撤销区。 */
|
|
22
22
|
export function isApprovalPolicyEmpty(policy) {
|
|
23
23
|
return !policy || (!policy.allowAll && policy.categories.size === 0);
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* 判定某个工具调用是否属于超宽范围、全局根目录或系统级不可逆操作(Issue #722)。
|
|
27
|
+
* 针对此类全局高危操作,即便用户之前曾为局部目录勾选过「允许同类」,
|
|
28
|
+
* 同类记忆(category)亦强制失效,必须显式弹窗审批(除非用户选择了本对话「全部允许」)。
|
|
29
|
+
*/
|
|
30
|
+
export function isWideScopeOrRootOperation(toolName, params) {
|
|
31
|
+
if (!params || typeof params !== "object")
|
|
32
|
+
return false;
|
|
33
|
+
const obj = params;
|
|
34
|
+
if (toolName === "bash") {
|
|
35
|
+
const cmd = String(obj.command ?? "").trim();
|
|
36
|
+
// 1. 递归/强制删除大范围根路径、家目录、父目录、盘符根目录或通配符
|
|
37
|
+
// 形如 `rm -rf /`、`rm -rf ~`、`rm -rf ..`、`rm -rf *`、`rm -rf C:\`
|
|
38
|
+
if (/\brm\s+.*(-[a-zA-Z0-9]*[rf]|--recursive)/i.test(cmd)) {
|
|
39
|
+
// 匹配单独的危险目标 token:/、~、..、*、或 Windows 根盘如 C:\
|
|
40
|
+
if (/(?:^|\s)(?:[/~*]|\.\.|[a-zA-Z]:[\\/])(?:\s|$)/.test(cmd)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// 2. Windows 强制递归删除系统/根盘目标
|
|
45
|
+
if (/\b(del|rmdir|rd)\s+[/\\-][fsq]/i.test(cmd)) {
|
|
46
|
+
if (/(?:^|\s)(?:[/~*]|\.\.|[a-zA-Z]:[\\/])(?:\s|$)/.test(cmd)) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// 3. 磁盘格式化或底层写入 (format C:, mkfs, dd if=)
|
|
51
|
+
if (/\b(mkfs|format\s+[a-zA-Z]:|dd\s+if=)/i.test(cmd)) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
// 4. 重定向覆盖系统目录
|
|
55
|
+
if (/>\s*(?:\/etc\/|\/boot\/|C:\\Windows)/i.test(cmd)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
// 5. 全局危险权限修改 chmod 777 -R / 或 chmod -R 777 /
|
|
59
|
+
if (/\bchmod\s+.*?(?:777|000).*?(?:[/~]|[a-zA-Z]:[\\/])/i.test(cmd)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (toolName === "write" || toolName === "edit" || toolName === "edit_soft" || toolName === "patch") {
|
|
64
|
+
const p = extractTargetPath(params);
|
|
65
|
+
// 敏感系统文件与密钥凭据(跨文件的同类不能随意扩散到系统或密钥)
|
|
66
|
+
if (p.includes("/etc/") ||
|
|
67
|
+
p.includes("/boot/") ||
|
|
68
|
+
p.includes("C:\\Windows") ||
|
|
69
|
+
p.includes(".ssh") ||
|
|
70
|
+
p.includes("id_rsa") ||
|
|
71
|
+
p.includes("id_ed25519")) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
25
77
|
/**
|
|
26
78
|
* 三档放行的纯判定:返回 null = 需要弹审批,否则返回放行的原因。
|
|
27
79
|
* - `disabled`:全局开关关(设置 →「工具」页)→ 一切审批都不弹(插件显式 ask 也放行);
|
|
28
80
|
* - `allow-all`:本对话已「全部允许」;
|
|
29
|
-
* - `category
|
|
81
|
+
* - `category`:本对话已记住该同类档位(但全局高危/根路径操作除外,见 isWideScopeOrRootOperation)。
|
|
30
82
|
*/
|
|
31
|
-
export function approvalSuppressionReason(policy, enabled, categoryId) {
|
|
83
|
+
export function approvalSuppressionReason(policy, enabled, categoryId, toolName, params) {
|
|
32
84
|
if (!enabled)
|
|
33
85
|
return "disabled";
|
|
34
86
|
if (!policy)
|
|
35
87
|
return null;
|
|
36
88
|
if (policy.allowAll)
|
|
37
89
|
return "allow-all";
|
|
38
|
-
if (categoryId && policy.categories.has(categoryId))
|
|
90
|
+
if (categoryId && policy.categories.has(categoryId)) {
|
|
91
|
+
// 特权边界收敛(Issue #722):
|
|
92
|
+
// 即使已记住同类档位,若当前操作属于全局根路径、系统破坏性或敏感密钥写入等超宽操作,
|
|
93
|
+
// 严禁凭同类记忆静默放行,必须强制弹窗要求显式确认。
|
|
94
|
+
if (toolName && params && isWideScopeOrRootOperation(toolName, params)) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
39
97
|
return "category";
|
|
98
|
+
}
|
|
40
99
|
return null;
|
|
41
100
|
}
|
|
42
101
|
/** 插件显式要求确认(pre guard 的 ask)对应的档位:按插件 id 分档,可「允许同类」。 */
|