@aivin-labs/cli 1.0.13 → 1.0.24

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.
Files changed (73) hide show
  1. package/README.md +325 -304
  2. package/bin/cli.mjs +97 -18
  3. package/bin/lib/localPreview.mjs +437 -0
  4. package/bin/lib/openFile.mjs +235 -0
  5. package/bin/lib/previewCache.mjs +71 -0
  6. package/bin/lib/remote/atomicFile.mjs +32 -0
  7. package/bin/lib/remote/autoStart.mjs +2 -1
  8. package/bin/lib/remote/autoUpdate.mjs +153 -129
  9. package/bin/lib/remote/callLedger.mjs +21 -0
  10. package/bin/lib/remote/cdpPolicy.mjs +14 -2
  11. package/bin/lib/remote/client.mjs +1025 -889
  12. package/bin/lib/remote/codingAgents.mjs +2 -2
  13. package/bin/lib/remote/constants.mjs +263 -251
  14. package/bin/lib/remote/credentials.mjs +81 -4
  15. package/bin/lib/remote/daemonLock.mjs +57 -17
  16. package/bin/lib/remote/desktop/castInput.mjs +98 -0
  17. package/bin/lib/remote/desktop/desktopCast.mjs +337 -198
  18. package/bin/lib/remote/desktop/desktopCastCaptureSource.mjs +598 -0
  19. package/bin/lib/remote/desktop/desktopCastSource.mjs +880 -514
  20. package/bin/lib/remote/desktop/desktopWebRtc.mjs +251 -95
  21. package/bin/lib/remote/desktop/fileAssociation.mjs +108 -0
  22. package/bin/lib/remote/desktop/index.mjs +21 -7
  23. package/bin/lib/remote/desktop/linuxTraySource.mjs +1 -8
  24. package/bin/lib/remote/desktop/macTraySource.mjs +0 -2
  25. package/bin/lib/remote/desktop/strings.mjs +28 -2
  26. package/bin/lib/remote/desktop/traySource.mjs +380 -16
  27. package/bin/lib/remote/desktop/webrtcRuntime.mjs +137 -0
  28. package/bin/lib/remote/desktop/webrtcWorker.mjs +183 -0
  29. package/bin/lib/remote/deviceProfile.mjs +2 -4
  30. package/bin/lib/remote/fileIndexer.mjs +30 -14
  31. package/bin/lib/remote/folderRules.mjs +3 -0
  32. package/bin/lib/remote/gitSafe.mjs +31 -0
  33. package/bin/lib/remote/gui/index.mjs +66 -24
  34. package/bin/lib/remote/gui/officeHostSource.mjs +635 -393
  35. package/bin/lib/remote/gui/windowsHost.mjs +3 -1
  36. package/bin/lib/remote/gui/windowsHostSource.mjs +291 -60
  37. package/bin/lib/remote/httpTransfer.mjs +64 -3
  38. package/bin/lib/remote/localPolicy.mjs +73 -7
  39. package/bin/lib/remote/mascot/ask.mjs +956 -768
  40. package/bin/lib/remote/mascot/askBlocksSource.mjs +286 -0
  41. package/bin/lib/remote/mascot/askHostSource.mjs +658 -530
  42. package/bin/lib/remote/mascot/blocks.mjs +201 -0
  43. package/bin/lib/remote/mascot/bot.mjs +26 -2
  44. package/bin/lib/remote/mascot/chartLayout.mjs +382 -0
  45. package/bin/lib/remote/mascot/diagramRender.mjs +154 -0
  46. package/bin/lib/remote/mascot/emojiSource.mjs +273 -0
  47. package/bin/lib/remote/mascot/fileChips.mjs +62 -0
  48. package/bin/lib/remote/mascot/hostSource.mjs +328 -49
  49. package/bin/lib/remote/mascot/hotkey.mjs +31 -7
  50. package/bin/lib/remote/mascot/images.mjs +111 -0
  51. package/bin/lib/remote/mascot/index.mjs +663 -493
  52. package/bin/lib/remote/mascot/lucideIcons.mjs +32 -0
  53. package/bin/lib/remote/mascot/mermaidBundle.mjs +28 -0
  54. package/bin/lib/remote/mascot/mood.mjs +57 -0
  55. package/bin/lib/remote/mascot/rigSource.mjs +643 -609
  56. package/bin/lib/remote/mascot/safeUrl.mjs +29 -0
  57. package/bin/lib/remote/mascot/strings.mjs +459 -375
  58. package/bin/lib/remote/mascot/ui.mjs +27 -7
  59. package/bin/lib/remote/multiUser.mjs +7 -2
  60. package/bin/lib/remote/notify.mjs +4 -1
  61. package/bin/lib/remote/office/index.mjs +12 -6
  62. package/bin/lib/remote/processes.mjs +5 -2
  63. package/bin/lib/remote/sandbox.mjs +26 -0
  64. package/bin/lib/remote/secretPaths.mjs +21 -0
  65. package/bin/lib/remote/tokenRotation.mjs +28 -0
  66. package/bin/lib/remote/toolHandlers.mjs +79 -15
  67. package/bin/lib/remote/watchBatcher.mjs +56 -0
  68. package/bin/lib/selfUpdate.mjs +12 -2
  69. package/bin/lib/update/binarySwap.mjs +15 -1
  70. package/bin/lib/update/state.mjs +10 -0
  71. package/docs/CLI.md +1545 -1504
  72. package/docs/media/aivin-ecosystem.jpg +0 -0
  73. package/package.json +75 -71
@@ -1,6 +1,7 @@
1
1
  import axios from 'axios';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
+ import { Transform } from 'stream';
4
5
  import { pipeline } from 'stream/promises';
5
6
  import { DEVICE_API_PREFIX, DeviceErrorCode, ToolGroup } from './constants.mjs';
6
7
  import { DeviceToolError, displayPath, resolveInRoots } from './sandbox.mjs';
@@ -9,6 +10,8 @@ import { DeviceToolError, displayPath, resolveInRoots } from './sandbox.mjs';
9
10
  const DEVICE_TOKEN_HEADER = 'x-aivin-device-token';
10
11
  const TICKET_RE = /^[A-Za-z0-9_-]{43}$/;
11
12
  const PART_RETRIES = 2;
13
+ /** Trần cỡ một tệp tải về qua HTTP thẳng (02/11/2026) — tránh đầy ổ khi vé / máy chủ trả dữ liệu không dứt. */
14
+ export const MAX_DOWNLOAD_BYTES = 8 * 1024 ** 3;
12
15
 
13
16
  /**
14
17
  * Tệp lớn hơn trần socket đi HTTP thẳng giữa máy và kho Aivin (be DeviceDirectTransferService). Chỉ BE gọi (internal, Planner không thấy):
@@ -40,18 +43,38 @@ export function buildTransferTools({ serverUrl, deviceToken }) {
40
43
  return { path: displayPath(env.roots, abs), bytes: size, parts };
41
44
  }
42
45
 
46
+ /**
47
+ * Tải về (02/11/2026): ghi ra `<đích>.part` trước, đủ + đúng cỡ mới thay đích (bản cũ vào kho hoàn tác như fs.write) — trước đây ghi thẳng
48
+ * đè đích: đứt giữa chừng là tệp gốc bị cắt cụt, không lấy lại được, và không có trần dung lượng (đầy ổ).
49
+ */
43
50
  async function download(args, ctx, env) {
44
51
  if (env.runAs) throw new DeviceToolError(DeviceErrorCode.INVALID_ARGS, 'Direct transfer is not available on a shared computer');
45
52
  const abs = resolveInRoots(env.roots, args.path || '');
53
+ const limit = downloadLimit(args);
54
+ const expected = Number.isFinite(Number(args.size)) && args.size !== null && args.size !== '' ? Number(args.size) : null;
55
+ if (expected !== null && expected > limit) throw tooLarge(limit);
46
56
  await fs.promises.mkdir(path.dirname(abs), { recursive: true });
47
57
  const res = await axios.get(urlOf(args.ticket), { headers: headers(), signal: ctx.signal, responseType: 'stream', validateStatus: () => true });
48
58
  if (res.status !== 200) {
49
59
  res.data?.destroy?.();
50
60
  throw new DeviceToolError(DeviceErrorCode.EXECUTION_FAILED, `Download failed (HTTP ${res.status})`);
51
61
  }
52
- await pipeline(res.data, fs.createWriteStream(abs), { signal: ctx.signal });
53
- const bytes = (await fs.promises.stat(abs)).size;
54
- return { path: displayPath(env.roots, abs), bytes };
62
+ if (Number(res.headers?.['content-length']) > limit) {
63
+ res.data?.destroy?.();
64
+ throw tooLarge(limit);
65
+ }
66
+ const part = `${abs}.part`;
67
+ let bytes = 0;
68
+ try {
69
+ await pipeline(res.data, byteCap(limit, (n) => { bytes = n; }), fs.createWriteStream(part), { signal: ctx.signal });
70
+ if (expected !== null && bytes !== expected) {
71
+ throw new DeviceToolError(DeviceErrorCode.EXECUTION_FAILED, `Download incomplete (${bytes} of ${expected} bytes) — the file was not changed`);
72
+ }
73
+ } catch (e) {
74
+ await fs.promises.rm(part, { force: true }).catch(() => undefined);
75
+ throw e;
76
+ }
77
+ return { path: displayPath(env.roots, abs), bytes, ...(await commitPart(part, abs, args, env)) };
55
78
  }
56
79
 
57
80
  return [
@@ -62,6 +85,44 @@ export function buildTransferTools({ serverUrl, deviceToken }) {
62
85
  ];
63
86
  }
64
87
 
88
+ /** Trần một lần tải về: `args.max_bytes` (BE) chỉ được hạ, không vượt `MAX_DOWNLOAD_BYTES`. */
89
+ function downloadLimit(args) {
90
+ const asked = Number(args?.max_bytes);
91
+ return asked > 0 ? Math.min(asked, MAX_DOWNLOAD_BYTES) : MAX_DOWNLOAD_BYTES;
92
+ }
93
+
94
+ const tooLarge = (limit) => new DeviceToolError(DeviceErrorCode.OUTPUT_TOO_LARGE, `File is larger than the ${Math.round(limit / 1024 ** 2)} MB limit for one download — nothing was written`);
95
+
96
+ /** Đếm byte đi qua; quá `limit` → huỷ cả đường ống (tệp .part bị xoá ở nơi gọi). */
97
+ function byteCap(limit, onCount) {
98
+ let seen = 0;
99
+ return new Transform({
100
+ transform(chunk, _enc, cb) {
101
+ seen += chunk.length;
102
+ onCount(seen);
103
+ if (seen > limit) return cb(tooLarge(limit));
104
+ cb(null, chunk);
105
+ },
106
+ });
107
+ }
108
+
109
+ /** Đổi `.part` thành đích: đích có sẵn → lưu bản cũ vào kho hoàn tác trước; tệp mới → ghi lại để hoàn tác thì bỏ đi. */
110
+ async function commitPart(part, abs, args, env) {
111
+ const undo = env.undo ? env.undo.begin(args.undo_group, 'write') : null;
112
+ const exists = fs.existsSync(abs);
113
+ try {
114
+ const backup = exists ? await undo?.backupFile(abs) : undefined;
115
+ await fs.promises.rename(part, abs);
116
+ if (!exists) undo?.created(abs);
117
+ return { created: !exists, ...(exists && undo ? { previous_version_kept: !!backup } : {}) };
118
+ } catch (e) {
119
+ await fs.promises.rm(part, { force: true }).catch(() => undefined);
120
+ throw e;
121
+ } finally {
122
+ undo?.commit();
123
+ }
124
+ }
125
+
65
126
  /** Một khúc = một PUT có Content-Length cố định (BE đối chiếu cỡ khúc theo vé; stream từ đĩa, không nạp cả khúc vào RAM). */
66
127
  async function putPart({ url, abs, start, length, signal, headers }) {
67
128
  const body = length ? fs.createReadStream(abs, { start, end: start + length - 1 }) : Buffer.alloc(0);
@@ -4,6 +4,7 @@ import path from 'path';
4
4
  import { DeviceErrorCode, REMOTE_CONFIG_DIR } from './constants.mjs';
5
5
  import { DeviceToolError } from './sandbox.mjs';
6
6
  import { openToken, sealToken } from './tokenStore.mjs';
7
+ import { notePolicySealed, policySealedNoted } from './credentials.mjs';
7
8
 
8
9
  /**
9
10
  * Sàn luật TẠI MÁY (29/10/2026). Trước đây máy tin BE gần như tuyệt đối: ngoài thư mục được phép + công tắc ngắt + vài lệnh thảm hoạ, mọi
@@ -53,6 +54,43 @@ const ALWAYS_RISKY_REASON = {
53
54
  'meeting.start': 'Ghi âm cuộc họp (micro + âm thanh máy) và chụp màn hình',
54
55
  };
55
56
 
57
+ /**
58
+ * Công cụ NỘI BỘ (BE tự gọi, Planner không thấy) mà vẫn ghi tệp lên máy — xét rủi ro / hỏi xác nhận như `fs.write`, không được miễn như các
59
+ * công cụ nội bộ khác (đọc khúc tệp, ghi nhớ, báo…) (02/11/2026).
60
+ */
61
+ const INTERNAL_WRITE_TOOLS = new Set(['fs.download']);
62
+
63
+ /** Công cụ ghi tệp → tham số chứa đường ĐÍCH (`fs.move_many`: `moves[].to`). */
64
+ const WRITE_TARGET_ARGS = Object.freeze({
65
+ 'fs.write': 'path', 'fs.edit': 'path', 'fs.download': 'path', 'fs.copy': 'destinationPath', 'fs.move': 'destinationPath',
66
+ });
67
+
68
+ /**
69
+ * Chỗ TỰ CHẠY (02/11/2026): ghi tệp vào đây là cài được lệnh chạy khi đăng nhập / mở terminal / mở dự án — cùng loại bám trụ với `sys.schedule`
70
+ * nên buộc hỏi tại máy. Khớp trên đường dẫn đã chuẩn hoá (`/`, chữ thường); đường tương đối (theo thư mục nhà) cũng khớp.
71
+ */
72
+ const AUTOSTART_PATH_PATTERNS = [
73
+ /\/start menu\/programs\/startup(\/|$)/, // Windows: thư mục Startup (người dùng / mọi người dùng)
74
+ /\/(windows)?powershell\/([^/]*_)?profile\.ps1$/, // hồ sơ PowerShell (chạy mỗi lần mở PowerShell)
75
+ /\/\.(bashrc|bash_profile|bash_login|profile|zshrc|zshenv|zprofile|zlogin|login|cshrc|tcshrc|xprofile|xinitrc)$/,
76
+ /\/\.config\/fish\/config\.fish$/,
77
+ /\/library\/(launchagents|launchdaemons)(\/|$)/, // macOS
78
+ /\/\.config\/(autostart|systemd\/user)(\/|$)/, // Linux desktop / systemd người dùng
79
+ /\/\.git\/hooks(\/|$)/, // chạy ở lần git commit / checkout kế tiếp
80
+ /\/\.vscode\/tasks\.json$/, // VS Code: task "runOn: folderOpen" chạy khi mở thư mục
81
+ ];
82
+
83
+ /** Đường đích (trong tham số) rơi vào chỗ tự chạy — trả đường đó, không thì null. */
84
+ export function autostartTarget(toolName, args = {}) {
85
+ const key = WRITE_TARGET_ARGS[toolName];
86
+ const targets = key ? [args?.[key]] : toolName === 'fs.move_many' && Array.isArray(args?.moves) ? args.moves.map((m) => m?.to) : [];
87
+ return targets.find((t) => {
88
+ if (typeof t !== 'string' || !t.trim()) return false;
89
+ const p = `/${t.trim().replace(/\\/g, '/').toLowerCase()}`;
90
+ return AUTOSTART_PATH_PATTERNS.some((re) => re.test(p));
91
+ }) || null;
92
+ }
93
+
56
94
  /**
57
95
  * Lệnh có hậu quả khó lấy lại / chạm bảo mật — khớp chuỗi nên lách được (ghép chuỗi, mã hoá), nhưng chính các cách lách thông dụng
58
96
  * (`-EncodedCommand`, `iex`, `| sh`) cũng nằm trong danh sách.
@@ -68,7 +106,9 @@ const RISKY_COMMAND_PATTERNS = [
68
106
  /\b(set|add)-mppreference\b/i, /\bdisable-?(windows)?defender/i, /\btakeown\b/i, /\bicacls\b[^|;]*\/grant/i,
69
107
  /\bchmod\s+(-[a-z]*r[a-z]*\s+)?[0-7]*7{2,}/i, /\bchown\s+-[a-z]*r/i, /\bsudo\b/i, /\brunas\b/i, /-verb\s+runas/i,
70
108
  // Kho mật khẩu / khoá đăng nhập
71
- /\bcmdkey\b/i, /\bsecurity\s+(find|dump|export)-/i, /\bvaultcmd\b/i, /login data|cookies\.sqlite|keychain-db|\.ssh[\\/]id_/i,
109
+ /\bcmdkey\b/i, /\bsecurity\s+(find|dump|export)-/i, /\bvaultcmd\b/i, /login data|cookies\.sqlite|keychain-db|\.ssh[\\/]id_|\bid_(rsa|dsa|ecdsa|ed25519)\b/i,
110
+ // Gửi dữ liệu ra ngoài bằng lớp .NET / chép ra thư mục mạng (UNC) — không có cờ nào của curl để nhận ra
111
+ /\.upload(file|string|data|values)(async)?\s*\(/i, /(^|[\s"'=(])\\\\(?!localhost\\|127\.0\.0\.1\\|\?\\|\.\\)[\w.-]+\\/, /\bnet\s+use\b/i,
72
112
  // Tải về rồi chạy / chạy chuỗi mã hoá
73
113
  /\b(curl|wget)\b[^|;]*\|\s*(sudo\s+)?(ba|z)?sh\b/i, /\b(iwr|irm|invoke-webrequest|invoke-restmethod)\b[^|;]*\|\s*(iex|invoke-expression)\b/i,
74
114
  /\b(iex|invoke-expression)\b/i, /-e(nc(odedcommand)?)?\s+[a-z0-9+/=]{20,}/i, /\bbase64\s+(-d|--decode)\b[^|;]*\|\s*(ba|z)?sh\b/i,
@@ -149,6 +189,7 @@ export function saveLocalPolicy(policy, file = REMOTE_POLICY_FILE, { keyFile = R
149
189
  fs.writeFileSync(file, JSON.stringify(signed, null, 2) + '\n', { mode: 0o600 });
150
190
  const record = key ? readKeyRecord(keyFile) : null;
151
191
  if (record) writeKeyRecord(keyFile, { ...record, policy: signed });
192
+ if (key) { try { notePolicySealed(); } catch { /* dấu bền chỉ để phát hiện bị xoá — xem createPolicyGuard */ } }
152
193
  return clean;
153
194
  }
154
195
 
@@ -170,7 +211,9 @@ export function verifyLocalPolicy(file = REMOTE_POLICY_FILE, { keyFile = REMOTE_
170
211
  raw = JSON.parse(fs.readFileSync(file, 'utf8'));
171
212
  } catch (e) {
172
213
  const keyExists = fs.existsSync(keyFile);
173
- return { policy: normalize(null), trusted: e?.code === 'ENOENT' && !keyExists, base: keyExists ? signedBackup(keyFile, policyKey(keyFile)) : null };
214
+ // `pristine`: không có tệp luật lẫn tệp khoá — có thể là chưa từng đặt luật, HOẶC cả hai vừa bị xoá (createPolicyGuard phân biệt).
215
+ const pristine = e?.code === 'ENOENT' && !keyExists;
216
+ return { policy: normalize(null), trusted: pristine, pristine, base: keyExists ? signedBackup(keyFile, policyKey(keyFile)) : null };
174
217
  }
175
218
  const policy = normalize(raw);
176
219
  const key = policyKey(keyFile);
@@ -192,15 +235,33 @@ export function stricterPolicy(trusted, other) {
192
235
  * Luật daemon dùng (đọc lại mỗi lời gọi — chủ máy đổi ở cửa sổ khác thì có hiệu lực ngay). Tệp có chữ ký đúng → dùng và nhớ làm bản đúng;
193
236
  * tệp bị sửa ngoài `aivin remote policy` → chặt hơn của (bản có chữ ký gần nhất — chép trong tệp khoá, không có thì bản đúng daemon đã thấy,
194
237
  * tệp): siết thì nhận, nới thì bỏ. `onTamper(policy)` báo một lần mỗi lần nội dung tệp đổi.
238
+ *
239
+ * Xoá CẢ tệp luật lẫn tệp khoá (02/11/2026): trước đây trông y như "chưa từng đặt luật" → tin, luật về mặc định ngay cả khi daemon đang chạy.
240
+ * Nay daemon đã từng thấy luật có chữ ký (trong phiên này, hoặc theo dấu bền `sealedMarker` — mặc định ghi trong tệp ghép máy, credentials.mjs)
241
+ * thì coi trạng thái "không có gì" là bị can thiệp: giữ bản đúng gần nhất, báo `onTamper`. Giới hạn: daemon khởi động lại sau khi bị xoá cả
242
+ * ba (luật, khoá, dấu) thì không còn gì để phân biệt — nhưng xoá tệp ghép máy cũng làm máy mất kết nối với Aivin.
195
243
  */
196
- export function createPolicyGuard({ file = REMOTE_POLICY_FILE, keyFile = REMOTE_POLICY_KEY_FILE, onTamper } = {}) {
244
+ export function createPolicyGuard({
245
+ file = REMOTE_POLICY_FILE, keyFile = REMOTE_POLICY_KEY_FILE, onTamper, sealedMarker = { seen: policySealedNoted, note: notePolicySealed },
246
+ } = {}) {
247
+ const safe = (fn) => { try { return fn?.(); } catch { return undefined; } };
197
248
  const first = verifyLocalPolicy(file, { keyFile });
198
- let lastTrusted = first.trusted ? first.policy : first.base || normalize(null);
249
+ let everSigned = (first.trusted && !first.pristine) || !!first.base || !!safe(sealedMarker?.seen);
250
+ const noteSigned = () => {
251
+ if (everSigned && safe(sealedMarker?.seen)) return;
252
+ everSigned = true;
253
+ safe(sealedMarker?.note);
254
+ };
255
+ if (first.trusted && !first.pristine) noteSigned();
256
+ let lastTrusted = first.trusted && !(first.pristine && everSigned) ? first.policy : first.base || normalize(null);
199
257
  let reported = null;
200
258
  return {
201
259
  read() {
202
- const { policy, trusted, base } = verifyLocalPolicy(file, { keyFile });
260
+ const verdict = verifyLocalPolicy(file, { keyFile });
261
+ const { policy, base } = verdict;
262
+ const trusted = verdict.trusted && !(verdict.pristine && everSigned);
203
263
  if (trusted) {
264
+ if (!verdict.pristine && !everSigned) noteSigned();
204
265
  lastTrusted = policy;
205
266
  reported = null;
206
267
  return policy;
@@ -223,6 +284,7 @@ const commandOf = (toolName, args) => (COMMAND_ARG[toolName] ? String(args?.[COM
223
284
  export function riskReason(tool, args = {}) {
224
285
  if (ALWAYS_RISKY_TOOLS.has(tool.name)) return ALWAYS_RISKY_REASON[tool.name];
225
286
  if (tool.destructive && args.permanent === true) return 'Xoá hẳn, không lấy lại được';
287
+ if (autostartTarget(tool.name, args)) return 'Ghi vào chỗ tự chạy (khởi động máy / mở terminal / mở dự án)';
226
288
  const command = commandOf(tool.name, args);
227
289
  if (command && RISKY_COMMAND_PATTERNS.some((re) => re.test(command))) return 'Lệnh có thể thay đổi hệ thống hoặc cài đặt bảo mật';
228
290
  return null;
@@ -230,7 +292,9 @@ export function riskReason(tool, args = {}) {
230
292
 
231
293
  /**
232
294
  * Quyết định của sàn luật cho một lời gọi: `{ action: 'allow' }`, `{ action: 'confirm', reason }` hoặc ném `DeviceToolError` khi bị cấm.
233
- * Lời gọi nội bộ (BE tự dùng: đọc khúc tệp, ghi nhớ…) và chỉ đọc không bao giờ cần xác nhận.
295
+ * Lời gọi nội bộ (BE tự dùng: đọc khúc tệp, ghi nhớ…) và chỉ đọc không bao giờ cần xác nhận — nhưng phần CẤM (`deny_tools`, lệnh bị chặn) áp
296
+ * cho mọi công cụ, kể cả nội bộ (02/11/2026: trước đó daemon bỏ qua sàn luật với công cụ nội bộ). Công cụ nội bộ có ghi tệp
297
+ * (`INTERNAL_WRITE_TOOLS`) xét như `fs.write`.
234
298
  */
235
299
  export function evaluateLocalPolicy(policy, tool, args = {}) {
236
300
  // gui.do is only a compact route into the same GUI actuator. A device owner who disabled the
@@ -243,7 +307,8 @@ export function evaluateLocalPolicy(policy, tool, args = {}) {
243
307
  if (command && policy.blocked_commands.some((re) => new RegExp(re, 'i').test(command))) {
244
308
  throw new DeviceToolError(DeviceErrorCode.LOCAL_DENIED, 'Command blocked by a rule the owner of this computer set');
245
309
  }
246
- if (tool.read_only || tool.internal || policy.confirm === ConfirmMode.NEVER) return { action: 'allow' };
310
+ const confirmExempt = tool.read_only || (tool.internal && !INTERNAL_WRITE_TOOLS.has(tool.name));
311
+ if (confirmExempt || policy.confirm === ConfirmMode.NEVER) return { action: 'allow' };
247
312
  if (policy.confirm === ConfirmMode.ALWAYS) return { action: 'confirm', reason: riskReason(tool, args) || 'Thay đổi trên máy (bạn đặt luật hỏi mọi việc)' };
248
313
  const reason = riskReason(tool, args);
249
314
  return reason ? { action: 'confirm', reason } : { action: 'allow' };
@@ -257,6 +322,7 @@ export function describeCall(tool, args = {}) {
257
322
  if (tool.name === 'office.outlook.send') return cut(`Tới: ${args.to || '?'} — ${args.subject || ''}`, 300);
258
323
  if (tool.name === 'meeting.start') return cut(`${args.title || 'Cuộc họp'}${args.then ? ` — sau đó: ${args.then}` : ''}`, 300);
259
324
  if (args.path) return cut(args.path, 300);
325
+ if (args.destinationPath) return cut(`${args.sourcePath || '?'} → ${args.destinationPath}`, 300);
260
326
  if (Array.isArray(args.paths)) return cut(args.paths.join(', '), 300);
261
327
  return tool.name;
262
328
  }