vanspod 0.4.15 → 0.4.16

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.
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.localSystem = exports.MAX_READ_CHARS = exports.NO_PROJECT_FOLDER_NOTE = void 0;
7
7
  exports.createLocalTools = createLocalTools;
8
8
  exports.findGitBash = findGitBash;
9
- // The Local Tools that a Device answers for Agent Builder (ADR 0013).
9
+ // The Local Tools that a Device answers for a Remote Agent (ADR 0013).
10
10
  // A tool that is not built yet answers `unknown_tool`.
11
11
  const promises_1 = __importDefault(require("node:fs/promises"));
12
12
  const node_os_1 = __importDefault(require("node:os"));
@@ -15,6 +15,7 @@ const lineChanges_1 = require("./lineChanges");
15
15
  const localCommands_1 = require("./localCommands");
16
16
  const localToolApproval_1 = require("./localToolApproval");
17
17
  const projectPath_1 = require("./projectPath");
18
+ const remoteAgentLog_1 = require("./remoteAgentLog");
18
19
  const saveImage_1 = require("./saveImage");
19
20
  const systemPath_1 = require("./systemPath");
20
21
  const windowsEnvironmentSystem_1 = require("./windowsEnvironmentSystem");
@@ -116,17 +117,24 @@ async function writeFile(projectFolder, args, signal, context) {
116
117
  return target;
117
118
  let title = `寫入新檔案 ${target.relative}`;
118
119
  let body = content;
120
+ let before;
119
121
  if (target.exists) {
120
122
  if ((await promises_1.default.stat(target.absolute)).isDirectory()) {
121
123
  return { ok: false, error: "invalid_arguments", message: `「${target.relative}」是資料夾,不能寫成檔案。` };
122
124
  }
123
125
  const old = await promises_1.default.readFile(target.absolute);
124
126
  title = `修改檔案 ${target.relative}`;
125
- body = old.includes(0)
127
+ before = old.includes(0) ? undefined : old.toString("utf8");
128
+ body = before === undefined
126
129
  ? `(原本不是文字檔,整個檔案會換成下面的內容)\n${content}`
127
- : (0, lineChanges_1.lineChanges)(old.toString("utf8"), content);
130
+ : (0, lineChanges_1.lineChanges)(before, content);
131
+ context.call.wrote(content, before, false);
128
132
  }
129
- const refusal = await (0, localToolApproval_1.askApproval)(context.approver, { tool: "write_file", title, body, folder: projectFolder }, signal, NOT_WRITTEN);
133
+ else {
134
+ context.call.wrote(content, undefined, true);
135
+ }
136
+ const contents = before === undefined ? [content] : [content, before];
137
+ const refusal = await (0, localToolApproval_1.askApproval)(context.approver, { tool: "write_file", title, body, target: target.relative, folder: projectFolder, contents }, signal, NOT_WRITTEN);
130
138
  if (refusal)
131
139
  return refusal;
132
140
  // Resolve again: the folder may have changed while the student decided.
@@ -150,9 +158,22 @@ const PROJECT_TOOLS = {
150
158
  bash: localCommands_1.bashTool,
151
159
  save_image: saveImage_1.saveImage,
152
160
  };
161
+ /** The path or the command of a call, for the Remote Agent Log. */
162
+ function callTarget(tool, args) {
163
+ const text = (value) => typeof value === "string" ? value : "";
164
+ if (tool === "bash")
165
+ return text(args.command);
166
+ if (tool === "list_files")
167
+ return text(args.path ?? ".");
168
+ if (tool === "save_image")
169
+ return `images/${text(args.file_name)}`;
170
+ if (tool === "local_status")
171
+ return "";
172
+ return text(args.path);
173
+ }
153
174
  function createLocalTools(options) {
154
- const context = { approver: options.approver, commands: options.commands ?? (0, localCommands_1.createCommandLog)(), gitBash: () => options.system.gitBash() };
155
- return async (tool, args, signal) => {
175
+ const log = options.log ?? (0, remoteAgentLog_1.createRemoteAgentLog)();
176
+ return (tool, args, signal) => log.record(tool, callTarget(tool, args), async (call) => {
156
177
  if (tool === "local_status")
157
178
  return localStatus(options);
158
179
  const projectTool = Object.hasOwn(PROJECT_TOOLS, tool) ? PROJECT_TOOLS[tool] : undefined;
@@ -160,10 +181,12 @@ function createLocalTools(options) {
160
181
  const folder = options.projectFolder();
161
182
  if (!folder)
162
183
  return { ok: false, error: "no_project_folder", message: exports.NO_PROJECT_FOLDER_NOTE };
163
- return projectTool(folder, args, signal, context);
184
+ // The entry keeps how each Local Tool Approval ended.
185
+ const approver = { request: (request, abort) => call.ask(options.approver, request, abort) };
186
+ return projectTool(folder, args, signal, { approver, call, gitBash: () => options.system.gitBash() });
164
187
  }
165
188
  return { ok: false, error: "unknown_tool", message: `這台電腦的 VansPod 不認識工具「${tool}」,請更新 VansPod。` };
166
- };
189
+ });
167
190
  }
168
191
  function osName() {
169
192
  const release = node_os_1.default.release();
@@ -16,18 +16,12 @@ exports.modelStatusScript = `
16
16
  }
17
17
  function applyModelStatus(status) {
18
18
  if (status.localTools) {
19
- var localState = document.querySelector("[data-local-tools-state]");
20
- if (localState && localState.textContent !== status.localTools.text) localState.textContent = status.localTools.text;
21
- var localSwitch = document.querySelector("[data-local-tools-switch]");
22
- if (localSwitch && localSwitch.getAttribute("aria-checked") !== String(status.localTools.on)) {
23
- localSwitch.setAttribute("aria-checked", String(status.localTools.on));
24
- localSwitch.value = status.localTools.on ? "0" : "1";
25
- localSwitch.textContent = status.localTools.on ? "開" : "關";
26
- localSwitch.classList.toggle("on", status.localTools.on);
27
- }
28
- var commandList = document.querySelector("[data-local-commands]");
29
- var commands = status.localTools.commands;
30
- if (commandList && commands && (commandList.getAttribute("data-commands-key") || "") !== commands.key) commandList.outerHTML = commands.html;
19
+ var statusBar = document.querySelector("[data-remote-status]");
20
+ var remoteStatus = status.localTools.status;
21
+ if (statusBar && remoteStatus && (statusBar.getAttribute("data-status-key") || "") !== remoteStatus.key) statusBar.outerHTML = remoteStatus.html;
22
+ var logList = document.querySelector("[data-log-list]");
23
+ var log = status.localTools.log;
24
+ if (logList && log && (logList.getAttribute("data-log-key") || "") !== log.key && typeof replaceRemoteAgentLog === "function") replaceRemoteAgentLog(log);
31
25
  var approvalBlock = document.querySelector("[data-local-approval]");
32
26
  if (approvalBlock) {
33
27
  var approval = status.localTools.approval;
@@ -36,6 +30,8 @@ exports.modelStatusScript = `
36
30
  } else if (approval) {
37
31
  var seconds = approvalBlock.querySelector("[data-approval-seconds]");
38
32
  if (seconds) seconds.textContent = String(approval.secondsLeft);
33
+ var bar = approvalBlock.querySelector("[data-approval-bar]");
34
+ if (bar) bar.style.width = approval.bar;
39
35
  }
40
36
  }
41
37
  }