pi-web-ui 0.101.0 → 0.103.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 +37 -1
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/bin/pi-web-ui.mjs +13 -9
- package/dist/server/agent-service-daemon.js +19 -12
- package/dist/server/agent-service.js +255 -58
- package/dist/server/ask-user-question-tool.js +12 -2
- package/dist/server/bash-tool.js +19 -1
- package/dist/server/client-state.js +24 -1
- package/dist/server/dispatch-domain-handlers.js +69 -3
- package/dist/server/dsh/dsh-agent-service.js +21 -4
- package/dist/server/dsh/runtime/goal-rpc.mjs +5 -1
- package/dist/server/edit-soft-tool.js +15 -3
- package/dist/server/files-service.js +636 -14
- package/dist/server/index.js +7 -1
- package/dist/server/plugin-installer.js +6 -1
- package/dist/server/plugins.js +1 -0
- package/dist/server/preset-fields.js +28 -0
- package/dist/server/preset-share.js +8 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/read-tool.js +11 -4
- package/dist/server/remote-ssh-service.js +1314 -0
- package/dist/server/scm.js +16 -0
- package/dist/server/settings-service.js +15 -0
- package/dist/server/terminals.js +65 -20
- package/dist/server/tool-guards.js +18 -6
- package/dist/server/virtual-tui.js +258 -0
- package/dist/server/webui-context.js +109 -4
- package/package.json +7 -1
- package/themes/zhupi-dark.css +3 -14
- package/themes/zhupi.css +2 -16
- package/web/dist/assets/TerminalPanel-PIx1pMZ0.js +3 -0
- package/web/dist/assets/index-CYQdZEbx.css +1 -0
- package/web/dist/assets/index-CtaYhpZt.js +680 -0
- package/web/dist/index.html +4 -2
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/TerminalPanel-DD7I5_aC.js +0 -3
- package/web/dist/assets/index-CpjA1YdT.css +0 -1
- package/web/dist/assets/index-nKn87VuM.js +0 -678
|
@@ -21,6 +21,9 @@ ownerId) {
|
|
|
21
21
|
preview: Type.Optional(Type.String({
|
|
22
22
|
description: "Optional preview (markdown/HTML/code)",
|
|
23
23
|
})),
|
|
24
|
+
recommended: Type.Optional(Type.Boolean({
|
|
25
|
+
description: "Highlight as recommended option",
|
|
26
|
+
})),
|
|
24
27
|
});
|
|
25
28
|
const QuestionSchema = Type.Object({
|
|
26
29
|
id: Type.String({ description: "Unique identifier (snake_case)" }),
|
|
@@ -68,12 +71,19 @@ ownerId) {
|
|
|
68
71
|
if (qs.length > 3) {
|
|
69
72
|
throw new Error("ask_user_question allows at most 3 questions per call to prevent question fatigue (单次提问最多不得超过 3 个问题)");
|
|
70
73
|
}
|
|
71
|
-
const
|
|
74
|
+
const res = await clientSession.askUser(qs, {
|
|
72
75
|
aborted: signal?.aborted,
|
|
73
76
|
}, ownerId);
|
|
74
|
-
if (
|
|
77
|
+
if (res === null) {
|
|
75
78
|
throw new Error("User cancelled the question.\n用户取消了提问。");
|
|
76
79
|
}
|
|
80
|
+
if (!Array.isArray(res) && res.cancelled) {
|
|
81
|
+
const cancelReason = res.reason?.trim();
|
|
82
|
+
const note = cancelReason ? `\nUser note / 附言: ${cancelReason}` : "";
|
|
83
|
+
const noteZh = cancelReason ? `\n附言:${cancelReason}` : "";
|
|
84
|
+
throw new Error(`User cancelled the question.${note}\n用户取消了提问。${noteZh}`);
|
|
85
|
+
}
|
|
86
|
+
const answers = res;
|
|
77
87
|
// 工具结果:把每道题的回答拼成简洁文本给模型,同时留 details 供 UI 展示。
|
|
78
88
|
const lines = answers.map((a) => {
|
|
79
89
|
const q = qs.find((q) => q.id === a.id);
|
package/dist/server/bash-tool.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { createBashToolDefinition, createLocalBashOperations, } from "@earendil-works/pi-coding-agent";
|
|
10
10
|
import { applyHeadTail } from "./terminals.js";
|
|
11
11
|
import { BASH_DESCRIPTION, BASH_PARAMETERS, BASH_PROMPT_GUIDELINES, BASH_PROMPT_SNIPPET } from "./tool-prompts.js";
|
|
12
|
+
import { getGlobalRemoteSshService, isRemoteWorkspaceUri, restoreWorkspaceUriFromSessionDir, } from "./remote-ssh-service.js";
|
|
12
13
|
/**
|
|
13
14
|
* Killable bash tool: wraps the SDK bash tool (native process spawn, NO terminal).
|
|
14
15
|
* Used when the「默认 bash 覆盖」setting is OFF. Registers its own AbortController
|
|
@@ -28,9 +29,26 @@ lang = () => "en") {
|
|
|
28
29
|
kills.add(ac);
|
|
29
30
|
try {
|
|
30
31
|
const signals = [opts.signal, ac.signal].filter((s) => s !== undefined);
|
|
32
|
+
const combinedSignal = signals.length > 1 ? AbortSignal.any(signals) : signals[0];
|
|
33
|
+
const effCwd = restoreWorkspaceUriFromSessionDir(c || cwd);
|
|
34
|
+
if (isRemoteWorkspaceUri(effCwd)) {
|
|
35
|
+
const sshSvc = getGlobalRemoteSshService();
|
|
36
|
+
if (!sshSvc) {
|
|
37
|
+
throw new Error("Remote SSH service is not initialized");
|
|
38
|
+
}
|
|
39
|
+
const timeoutMs = opts.timeout !== undefined && Number.isFinite(opts.timeout) && opts.timeout > 0
|
|
40
|
+
? opts.timeout * 1000
|
|
41
|
+
: undefined;
|
|
42
|
+
const res = await sshSvc.execInWorkspace(effCwd, command, {
|
|
43
|
+
signal: combinedSignal,
|
|
44
|
+
timeoutMs,
|
|
45
|
+
onData: opts.onData,
|
|
46
|
+
});
|
|
47
|
+
return { exitCode: res.exitCode };
|
|
48
|
+
}
|
|
31
49
|
return await base.exec(command, c, {
|
|
32
50
|
...opts,
|
|
33
|
-
signal:
|
|
51
|
+
signal: combinedSignal,
|
|
34
52
|
});
|
|
35
53
|
}
|
|
36
54
|
finally {
|
|
@@ -256,6 +256,17 @@ export const DEFAULT_TOOL_LAZY_LOADING = (() => {
|
|
|
256
256
|
const v = (process.env.PI_WEB_TOOL_LAZY_LOADING ?? "").trim().toLowerCase();
|
|
257
257
|
return !(v === "0" || v === "false" || v === "off" || v === "no");
|
|
258
258
|
})();
|
|
259
|
+
export const DEFAULT_CODEMODE_MODE = "on";
|
|
260
|
+
export const DEFAULT_CODEMODE_INLINE_BUDGET = 3000;
|
|
261
|
+
export function normalizeCodemodeMode(v) {
|
|
262
|
+
return v === "only" ? "only" : "on";
|
|
263
|
+
}
|
|
264
|
+
export function normalizeCodemodeInlineBudget(v) {
|
|
265
|
+
if (typeof v === "number" && Number.isFinite(v) && v > 0) {
|
|
266
|
+
return Math.floor(v);
|
|
267
|
+
}
|
|
268
|
+
return DEFAULT_CODEMODE_INLINE_BUDGET;
|
|
269
|
+
}
|
|
259
270
|
/** 预设 → 设置面板列表用的 UI 形状(协议要求字段完整:旧/部分预设用默认值补齐)。 */
|
|
260
271
|
export function settingsPresetToUi(p) {
|
|
261
272
|
return {
|
|
@@ -347,8 +358,12 @@ export function normalizeWorkspaceRoots(v) {
|
|
|
347
358
|
}
|
|
348
359
|
return out;
|
|
349
360
|
}
|
|
350
|
-
/** 跨平台(尤其是 Windows)路径归一化键:统一转绝对路径,并在 Windows 下转小写以消除大小写与正反斜杠差异。
|
|
361
|
+
/** 跨平台(尤其是 Windows)路径归一化键:统一转绝对路径,并在 Windows 下转小写以消除大小写与正反斜杠差异。
|
|
362
|
+
* 对于 ssh:// 格式的远程工作区 URI 保持原样不走路径解析。 */
|
|
351
363
|
export function normalizePathKey(p) {
|
|
364
|
+
if (p.startsWith("ssh://")) {
|
|
365
|
+
return p;
|
|
366
|
+
}
|
|
352
367
|
try {
|
|
353
368
|
const resolved = resolve(p);
|
|
354
369
|
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
|
|
@@ -632,8 +647,12 @@ export class ClientStateStore {
|
|
|
632
647
|
});
|
|
633
648
|
}
|
|
634
649
|
/** 单条路径的存活性探测(issue #441):异步 access,绝不阻塞事件循环。
|
|
650
|
+
* 远程工作区 URI (ssh://) 始终判定存活,避免被本地 fs.access 过滤掉。
|
|
635
651
|
* 独立成 protected 方法便于单测用子类覆写做计数探针。 */
|
|
636
652
|
async pathExists(path) {
|
|
653
|
+
if (path.startsWith("ssh://")) {
|
|
654
|
+
return true;
|
|
655
|
+
}
|
|
637
656
|
return fsPromises.access(path).then(() => true, () => false);
|
|
638
657
|
}
|
|
639
658
|
/** Record discovered projects into global settings cache (without clobbering tombstones). */
|
|
@@ -791,6 +810,8 @@ export class ClientStateStore {
|
|
|
791
810
|
readDirEnabled: stored?.readDirEnabled ?? true,
|
|
792
811
|
bgAutoCleanupMin: normalizeBgCleanupMinutes(stored?.bgAutoCleanupMin),
|
|
793
812
|
toolLazyLoading: stored?.toolLazyLoading ?? DEFAULT_TOOL_LAZY_LOADING,
|
|
813
|
+
codemodeMode: normalizeCodemodeMode(stored?.codemodeMode),
|
|
814
|
+
codemodeInlineBudget: normalizeCodemodeInlineBudget(stored?.codemodeInlineBudget),
|
|
794
815
|
toolApprovalEnabled: stored?.toolApprovalEnabled ?? true,
|
|
795
816
|
editSoftEnabled: stored?.disabledAgentTools !== undefined
|
|
796
817
|
? deriveLegacy(legacyToDisabled(stored)).editSoftEnabled
|
|
@@ -856,6 +877,8 @@ export class ClientStateStore {
|
|
|
856
877
|
readDirEnabled: settings.readDirEnabled ?? cur.readDirEnabled ?? true,
|
|
857
878
|
bgAutoCleanupMin: normalizeBgCleanupMinutes(settings.bgAutoCleanupMin ?? cur.bgAutoCleanupMin),
|
|
858
879
|
toolLazyLoading: settings.toolLazyLoading ?? cur.toolLazyLoading ?? DEFAULT_TOOL_LAZY_LOADING,
|
|
880
|
+
codemodeMode: normalizeCodemodeMode(settings.codemodeMode ?? cur.codemodeMode ?? DEFAULT_CODEMODE_MODE),
|
|
881
|
+
codemodeInlineBudget: normalizeCodemodeInlineBudget(settings.codemodeInlineBudget ?? cur.codemodeInlineBudget ?? DEFAULT_CODEMODE_INLINE_BUDGET),
|
|
859
882
|
toolApprovalEnabled: settings.toolApprovalEnabled ?? cur.toolApprovalEnabled ?? true,
|
|
860
883
|
editSoftEnabled: settings.editSoftEnabled ?? cur.editSoftEnabled ?? false,
|
|
861
884
|
questionnaireEnabled: settings.questionnaireEnabled ?? cur.questionnaireEnabled ?? true,
|
|
@@ -354,7 +354,7 @@ export function handleSessionLifecycleMessage(msg, cs) {
|
|
|
354
354
|
void cs.dismissFinishedSubagents(msg.parentId);
|
|
355
355
|
return true;
|
|
356
356
|
case "switch_session":
|
|
357
|
-
void cs.switchSession(msg.path);
|
|
357
|
+
void cs.switchSession(msg.path, msg.sessionId);
|
|
358
358
|
return true;
|
|
359
359
|
case "switch_conversation":
|
|
360
360
|
void cs.switchConversation(msg.id);
|
|
@@ -591,11 +591,20 @@ export function handleInteractiveResponseMessage(msg, cs, service, clientId, sen
|
|
|
591
591
|
case "dialog_response":
|
|
592
592
|
cs.resolveDialog(msg.id, msg.value);
|
|
593
593
|
return true;
|
|
594
|
+
case "tui_overlay_input":
|
|
595
|
+
cs.handleTuiOverlayInput?.(msg.id, msg.data);
|
|
596
|
+
return true;
|
|
597
|
+
case "tui_overlay_resize":
|
|
598
|
+
cs.handleTuiOverlayResize?.(msg.id, msg.cols, msg.rows);
|
|
599
|
+
return true;
|
|
600
|
+
case "tui_overlay_cancel":
|
|
601
|
+
cs.handleTuiOverlayCancel?.(msg.id);
|
|
602
|
+
return true;
|
|
594
603
|
case "question_answer":
|
|
595
604
|
if (msg.owner) {
|
|
596
605
|
// 跨页作答:答案转交持有方会话(本页不持有该问卷)。
|
|
597
606
|
if (typeof service.answerElsewhereQuestion === "function" && clientId) {
|
|
598
|
-
void service.answerElsewhereQuestion(clientId, msg.owner, msg.id, msg.answers, msg.cancelled);
|
|
607
|
+
void service.answerElsewhereQuestion(clientId, msg.owner, msg.id, msg.answers, msg.cancelled, msg.cancelReason);
|
|
599
608
|
}
|
|
600
609
|
else {
|
|
601
610
|
send({
|
|
@@ -607,7 +616,7 @@ export function handleInteractiveResponseMessage(msg, cs, service, clientId, sen
|
|
|
607
616
|
}
|
|
608
617
|
}
|
|
609
618
|
else {
|
|
610
|
-
void cs.answerQuestion?.(msg.id, msg.answers, msg.cancelled);
|
|
619
|
+
void cs.answerQuestion?.(msg.id, msg.answers, msg.cancelled, msg.cancelReason);
|
|
611
620
|
}
|
|
612
621
|
return true;
|
|
613
622
|
case "tool_approval_response":
|
|
@@ -629,3 +638,60 @@ export function handleInteractiveResponseMessage(msg, cs, service, clientId, sen
|
|
|
629
638
|
return false;
|
|
630
639
|
}
|
|
631
640
|
}
|
|
641
|
+
/** 远程 SSH 连接、探针与目录浏览处理 */
|
|
642
|
+
export function handleRemoteSshMessage(msg, remoteSshSvc, send) {
|
|
643
|
+
switch (msg.type) {
|
|
644
|
+
case "remote_ssh_probe":
|
|
645
|
+
void (async () => {
|
|
646
|
+
const res = await remoteSshSvc.probe(msg.params);
|
|
647
|
+
send({
|
|
648
|
+
type: "remote_ssh_probe_result",
|
|
649
|
+
reqId: msg.reqId,
|
|
650
|
+
...res,
|
|
651
|
+
});
|
|
652
|
+
})();
|
|
653
|
+
return true;
|
|
654
|
+
case "remote_ssh_list_dir":
|
|
655
|
+
void (async () => {
|
|
656
|
+
const res = await remoteSshSvc.listDir(msg.connectionId, msg.path);
|
|
657
|
+
send({
|
|
658
|
+
type: "remote_ssh_list_dir_result",
|
|
659
|
+
reqId: msg.reqId,
|
|
660
|
+
...res,
|
|
661
|
+
});
|
|
662
|
+
})();
|
|
663
|
+
return true;
|
|
664
|
+
case "remote_ssh_install_tools":
|
|
665
|
+
void (async () => {
|
|
666
|
+
const res = await remoteSshSvc.installTools(msg.connectionId, msg.tools);
|
|
667
|
+
send({
|
|
668
|
+
type: "remote_ssh_install_result",
|
|
669
|
+
reqId: msg.reqId,
|
|
670
|
+
...res,
|
|
671
|
+
});
|
|
672
|
+
})();
|
|
673
|
+
return true;
|
|
674
|
+
case "remote_ssh_list_profiles":
|
|
675
|
+
void (async () => {
|
|
676
|
+
const profiles = await remoteSshSvc.listProfiles();
|
|
677
|
+
send({
|
|
678
|
+
type: "remote_ssh_profiles_result",
|
|
679
|
+
reqId: msg.reqId,
|
|
680
|
+
profiles,
|
|
681
|
+
});
|
|
682
|
+
})();
|
|
683
|
+
return true;
|
|
684
|
+
case "remote_ssh_delete_profile":
|
|
685
|
+
void (async () => {
|
|
686
|
+
await remoteSshSvc.deleteProfile(msg.name);
|
|
687
|
+
const profiles = await remoteSshSvc.listProfiles();
|
|
688
|
+
send({
|
|
689
|
+
type: "remote_ssh_profiles_result",
|
|
690
|
+
profiles,
|
|
691
|
+
});
|
|
692
|
+
})();
|
|
693
|
+
return true;
|
|
694
|
+
default:
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
@@ -1393,6 +1393,7 @@ export class DshClientSession {
|
|
|
1393
1393
|
continue;
|
|
1394
1394
|
list.push({
|
|
1395
1395
|
id: conv.id,
|
|
1396
|
+
sessionId: conv.sessionId,
|
|
1396
1397
|
title: conv.title,
|
|
1397
1398
|
cwd: conv.cwd,
|
|
1398
1399
|
messageCount: conv.messages.length,
|
|
@@ -2093,6 +2094,7 @@ export class DshClientSession {
|
|
|
2093
2094
|
const { events } = readSessionLog(file);
|
|
2094
2095
|
summaries.push({
|
|
2095
2096
|
path: file,
|
|
2097
|
+
sessionId,
|
|
2096
2098
|
name: sessionId,
|
|
2097
2099
|
firstMessage: firstUserText(events, this.getLang()),
|
|
2098
2100
|
messageCount: events.filter((e) => e.type === "user/message" || e.type === "assistant/message" || e.type === "tool/result").length,
|
|
@@ -2232,17 +2234,30 @@ export class DshClientSession {
|
|
|
2232
2234
|
});
|
|
2233
2235
|
}
|
|
2234
2236
|
/** 切换会话:读 JSONL 回放 → 新建 conversation(同一 sessionId 续聊)。 */
|
|
2235
|
-
async switchSession(path) {
|
|
2237
|
+
async switchSession(path, wantSessionId) {
|
|
2236
2238
|
try {
|
|
2237
|
-
const
|
|
2238
|
-
const sessionId = basename(dirname(
|
|
2239
|
+
const explicitSid = wantSessionId?.trim() ?? "";
|
|
2240
|
+
const sessionId = explicitSid || basename(dirname(resolve(path)));
|
|
2239
2241
|
// 同一 sessionId 已在运行 → 直接切过去。
|
|
2240
2242
|
for (const conv of this.convs.values()) {
|
|
2241
|
-
if (conv.sessionId === sessionId) {
|
|
2243
|
+
if (conv.sessionId === sessionId || conv.id === sessionId) {
|
|
2242
2244
|
await this.switchConversation(conv.id);
|
|
2243
2245
|
return;
|
|
2244
2246
|
}
|
|
2245
2247
|
}
|
|
2248
|
+
if (!path.trim() && explicitSid) {
|
|
2249
|
+
const candidateFile = join(this.sessionRoot, explicitSid, "session.jsonl");
|
|
2250
|
+
if (!existsSync(candidateFile)) {
|
|
2251
|
+
this.emit({
|
|
2252
|
+
type: "notice",
|
|
2253
|
+
level: "warning",
|
|
2254
|
+
text: `未找到会话:${explicitSid}`,
|
|
2255
|
+
textEn: `Session not found: ${explicitSid}`,
|
|
2256
|
+
});
|
|
2257
|
+
this.flushSnapshot(true);
|
|
2258
|
+
return;
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2246
2261
|
// issue #145:同 pi 引擎 —— 别处正在跑同一 sessionId 时不建第二个持有者。
|
|
2247
2262
|
const owner = this.findSessionOwnerById?.(sessionId);
|
|
2248
2263
|
if (owner && owner.isStreaming) {
|
|
@@ -2656,6 +2671,8 @@ export class DshClientSession {
|
|
|
2656
2671
|
bgAutoCleanupMin: Number(this.settings.bgAutoCleanupMin ?? 0),
|
|
2657
2672
|
// DSH 无 pi 工具注册面,不适用延迟加载;保协议完整。
|
|
2658
2673
|
toolLazyLoading: true,
|
|
2674
|
+
codemodeMode: "on",
|
|
2675
|
+
codemodeInlineBudget: 3000,
|
|
2659
2676
|
editSoftEnabled: this.settings.editSoftEnabled,
|
|
2660
2677
|
// DSH 无独立重试配置(pi 引擎才暴露),保持默认。
|
|
2661
2678
|
retryMaxAttempts: DEFAULT_RETRY_MAX_ATTEMPTS,
|
|
@@ -923,7 +923,11 @@ class DshGoalJsonRpcServer extends HarnessSdkJsonRpcServer {
|
|
|
923
923
|
}
|
|
924
924
|
this.questionBridge.pending = null;
|
|
925
925
|
if (params?.cancelled) {
|
|
926
|
-
|
|
926
|
+
const reason =
|
|
927
|
+
typeof params?.cancelReason === "string" && params.cancelReason.trim()
|
|
928
|
+
? `(附言:${params.cancelReason.trim()})`
|
|
929
|
+
: "";
|
|
930
|
+
pending.reject(new Error(`用户取消了提问${reason}`));
|
|
927
931
|
} else {
|
|
928
932
|
const answers = Array.isArray(params?.answers) ? params.answers : [];
|
|
929
933
|
pending.resolve({ answers });
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
import { constants } from "node:fs";
|
|
24
24
|
import { access, readFile, writeFile } from "node:fs/promises";
|
|
25
25
|
import { homedir } from "node:os";
|
|
26
|
+
import { createRemoteSdkOperations } from "./remote-ssh-service.js";
|
|
26
27
|
import { isAbsolute, join, resolve as nodeResolve } from "node:path";
|
|
27
28
|
import { Type } from "typebox";
|
|
28
29
|
import { defineTool, generateDiffString, generateUnifiedPatch, withFileMutationQueue, } from "@earendil-works/pi-coding-agent";
|
|
@@ -321,6 +322,7 @@ export function makeEditSoftTool(fallbackCwd, getLang) {
|
|
|
321
322
|
}
|
|
322
323
|
const cwd = typeof ctx?.cwd === "string" ? ctx.cwd : fallbackCwd;
|
|
323
324
|
const absolutePath = resolveToCwd(path, cwd);
|
|
325
|
+
const remoteOps = createRemoteSdkOperations(cwd);
|
|
324
326
|
return withFileMutationQueue(absolutePath, async () => {
|
|
325
327
|
const throwIfAborted = () => {
|
|
326
328
|
if (signal?.aborted)
|
|
@@ -328,7 +330,12 @@ export function makeEditSoftTool(fallbackCwd, getLang) {
|
|
|
328
330
|
};
|
|
329
331
|
throwIfAborted();
|
|
330
332
|
try {
|
|
331
|
-
|
|
333
|
+
if (remoteOps) {
|
|
334
|
+
await remoteOps.edit.access(absolutePath);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
await access(absolutePath, constants.R_OK | constants.W_OK);
|
|
338
|
+
}
|
|
332
339
|
}
|
|
333
340
|
catch (error) {
|
|
334
341
|
throwIfAborted();
|
|
@@ -336,7 +343,7 @@ export function makeEditSoftTool(fallbackCwd, getLang) {
|
|
|
336
343
|
throw new Error(pick(lang, `无法编辑文件:${path}。${errorMessage}。`, `Could not edit file: ${path}. ${errorMessage}.`, "editsoft.file.access.failed", { path, errorMessage }));
|
|
337
344
|
}
|
|
338
345
|
throwIfAborted();
|
|
339
|
-
const buffer = await readFile(absolutePath);
|
|
346
|
+
const buffer = remoteOps ? await remoteOps.edit.readFile(absolutePath) : await readFile(absolutePath);
|
|
340
347
|
const rawContent = buffer.toString("utf-8");
|
|
341
348
|
throwIfAborted();
|
|
342
349
|
const { bom, text: content } = splitBom(rawContent);
|
|
@@ -345,7 +352,12 @@ export function makeEditSoftTool(fallbackCwd, getLang) {
|
|
|
345
352
|
const { baseContent, newContent } = applySoftEdits(normalizedContent, edits, path, lang);
|
|
346
353
|
throwIfAborted();
|
|
347
354
|
const finalContent = bom + restoreLineEndings(newContent, originalEnding);
|
|
348
|
-
|
|
355
|
+
if (remoteOps) {
|
|
356
|
+
await remoteOps.edit.writeFile(absolutePath, finalContent);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
await writeFile(absolutePath, finalContent, "utf-8");
|
|
360
|
+
}
|
|
349
361
|
throwIfAborted();
|
|
350
362
|
const diffResult = generateDiffString(baseContent, newContent);
|
|
351
363
|
const patch = generateUnifiedPatch(path, baseContent, newContent);
|