@aivin-labs/cli 1.0.11 → 1.0.21
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/README.md +325 -288
- package/bin/cli.mjs +163 -17
- package/bin/lib/localPreview.mjs +437 -0
- package/bin/lib/openFile.mjs +235 -0
- package/bin/lib/previewCache.mjs +71 -0
- package/bin/lib/remote/atomicFile.mjs +32 -0
- package/bin/lib/remote/autoStart.mjs +2 -1
- package/bin/lib/remote/autoUpdate.mjs +12 -0
- package/bin/lib/remote/browserTunnel.mjs +47 -8
- package/bin/lib/remote/callLedger.mjs +94 -14
- package/bin/lib/remote/cdpPolicy.mjs +14 -2
- package/bin/lib/remote/client.mjs +1024 -808
- package/bin/lib/remote/cloudFiles.mjs +53 -0
- package/bin/lib/remote/codingAgents.mjs +2 -2
- package/bin/lib/remote/constants.mjs +261 -234
- package/bin/lib/remote/credentials.mjs +81 -4
- package/bin/lib/remote/daemonLock.mjs +57 -17
- package/bin/lib/remote/dailyBrowser.mjs +8 -2
- package/bin/lib/remote/desktop/castInput.mjs +98 -0
- package/bin/lib/remote/desktop/desktopCast.mjs +334 -0
- package/bin/lib/remote/desktop/desktopCastCaptureSource.mjs +598 -0
- package/bin/lib/remote/desktop/desktopCastSource.mjs +798 -0
- package/bin/lib/remote/desktop/desktopWebRtc.mjs +242 -0
- package/bin/lib/remote/desktop/fileAssociation.mjs +108 -0
- package/bin/lib/remote/desktop/index.mjs +58 -7
- package/bin/lib/remote/desktop/linux.mjs +1 -1
- package/bin/lib/remote/desktop/linuxTraySource.mjs +427 -427
- package/bin/lib/remote/desktop/mac.mjs +2 -2
- package/bin/lib/remote/desktop/macTraySource.mjs +293 -292
- package/bin/lib/remote/desktop/strings.mjs +28 -2
- package/bin/lib/remote/desktop/traySource.mjs +905 -527
- package/bin/lib/remote/desktop/webrtcRuntime.mjs +137 -0
- package/bin/lib/remote/desktop/webrtcWorker.mjs +181 -0
- package/bin/lib/remote/deviceProfile.mjs +1 -0
- package/bin/lib/remote/docText.mjs +85 -0
- package/bin/lib/remote/fileIndexer.mjs +773 -399
- package/bin/lib/remote/folderRules.mjs +143 -0
- package/bin/lib/remote/gitSafe.mjs +31 -0
- package/bin/lib/remote/gui/index.mjs +170 -19
- package/bin/lib/remote/gui/officeHostSource.mjs +635 -393
- package/bin/lib/remote/gui/windowsHost.mjs +12 -3
- package/bin/lib/remote/gui/windowsHostSource.mjs +461 -87
- package/bin/lib/remote/httpTransfer.mjs +64 -3
- package/bin/lib/remote/idempotency.mjs +49 -20
- package/bin/lib/remote/localPolicy.mjs +81 -9
- package/bin/lib/remote/mascot/ask.mjs +207 -42
- package/bin/lib/remote/mascot/askBlocksSource.mjs +286 -0
- package/bin/lib/remote/mascot/askHostSource.mjs +658 -512
- package/bin/lib/remote/mascot/blocks.mjs +201 -0
- package/bin/lib/remote/mascot/bot.mjs +54 -5
- package/bin/lib/remote/mascot/chartLayout.mjs +382 -0
- package/bin/lib/remote/mascot/diagramRender.mjs +154 -0
- package/bin/lib/remote/mascot/emojiSource.mjs +273 -0
- package/bin/lib/remote/mascot/fileChips.mjs +62 -0
- package/bin/lib/remote/mascot/hostSource.mjs +331 -52
- package/bin/lib/remote/mascot/hotkey.mjs +31 -7
- package/bin/lib/remote/mascot/images.mjs +111 -0
- package/bin/lib/remote/mascot/index.mjs +663 -493
- package/bin/lib/remote/mascot/lucideIcons.mjs +32 -0
- package/bin/lib/remote/mascot/mermaidBundle.mjs +28 -0
- package/bin/lib/remote/mascot/mood.mjs +57 -0
- package/bin/lib/remote/mascot/rigSource.mjs +648 -609
- package/bin/lib/remote/mascot/safeUrl.mjs +29 -0
- package/bin/lib/remote/mascot/strings.mjs +456 -375
- package/bin/lib/remote/mascot/ui.mjs +27 -7
- package/bin/lib/remote/multiUser.mjs +7 -2
- package/bin/lib/remote/notify.mjs +4 -1
- package/bin/lib/remote/office/index.mjs +12 -6
- package/bin/lib/remote/osSearch.mjs +107 -0
- package/bin/lib/remote/processes.mjs +5 -2
- package/bin/lib/remote/sandbox.mjs +26 -0
- package/bin/lib/remote/secretPaths.mjs +21 -0
- package/bin/lib/remote/sqliteDb.mjs +51 -0
- package/bin/lib/remote/tokenRotation.mjs +28 -0
- package/bin/lib/remote/toolHandlers.mjs +852 -741
- package/bin/lib/remote/watchBatcher.mjs +56 -0
- package/bin/lib/remoteControl.mjs +26 -26
- package/bin/lib/selfUpdate.mjs +12 -2
- package/bin/lib/update/binarySwap.mjs +15 -1
- package/bin/lib/update/state.mjs +10 -0
- package/docs/AIVIN_MASCOT.md +14 -0
- package/docs/CLI.md +1545 -1484
- package/docs/media/aivin-ecosystem.jpg +0 -0
- package/docs/media/aivin-mascot-live.gif +0 -0
- package/docs/media/aivin-mascot-live.png +0 -0
- package/docs/media/aivin-remote-architecture.svg +102 -0
- package/package.json +75 -71
- package/docs/media/aivin-mascot-states.mp4 +0 -0
package/bin/cli.mjs
CHANGED
|
@@ -61,10 +61,14 @@ import { DAEMON_RUNNING } from './lib/remote/daemonLock.mjs';
|
|
|
61
61
|
import { runPolicyCommand } from './lib/remote/policyCommand.mjs';
|
|
62
62
|
import { loadMascotSettings, saveMascotSettings } from './lib/remote/mascot/index.mjs';
|
|
63
63
|
import { MascotText, mascotLang, mascotText } from './lib/remote/mascot/strings.mjs';
|
|
64
|
-
import {
|
|
64
|
+
import { DESKTOP_WEBRTC_WORKER_ARG, runDesktopWebRtcWorker } from './lib/remote/desktop/webrtcWorker.mjs';
|
|
65
|
+
import { DemoScope, UiResult, showMascotDemo, showMascotUi } from './lib/remote/mascot/ui.mjs';
|
|
65
66
|
import { desktopAppStatus, installDesktopApp, uninstallDesktopApp } from './lib/remote/autoStart.mjs';
|
|
67
|
+
import { OpenDisplay, openFile, openText } from './lib/openFile.mjs';
|
|
68
|
+
import { OPEN_WITH_EXTENSIONS, SAFE_DEFAULT_EXTENSIONS, defaultAssociationsXml, openDefaultAppsSettings } from './lib/remote/desktop/fileAssociation.mjs';
|
|
69
|
+
import { showOSNotification } from './lib/remote/notify.mjs';
|
|
66
70
|
import { createMeetingManager, requestMeeting } from './lib/remote/meeting/index.mjs';
|
|
67
|
-
import { DEFAULT_HOTKEYS, hotkeyCandidates, parseHotkey, probeHotkey } from './lib/remote/mascot/hotkey.mjs';
|
|
71
|
+
import { DEFAULT_CHAT_HOTKEYS, DEFAULT_HOTKEYS, hotkeyCandidates, parseHotkey, probeHotkey } from './lib/remote/mascot/hotkey.mjs';
|
|
68
72
|
import { RESTART_EXIT_CODE, UPDATE_ROLLED_BACK, UpdateStatus, cleanupRetired, downloadRoot, installUpdate, isStandaloneBinary, saveUpdateSettings } from './lib/selfUpdate.mjs';
|
|
69
73
|
import {
|
|
70
74
|
createAutomationJob,
|
|
@@ -94,8 +98,10 @@ import {
|
|
|
94
98
|
resetDeviceId,
|
|
95
99
|
loadDeviceCredentials,
|
|
96
100
|
pairDevice,
|
|
101
|
+
pairWithCodeOnly,
|
|
97
102
|
listDevices,
|
|
98
103
|
unpairDevice,
|
|
104
|
+
assertHumanCommand,
|
|
99
105
|
isRemotePaused,
|
|
100
106
|
setRemotePaused,
|
|
101
107
|
getRecentLogs,
|
|
@@ -107,6 +113,11 @@ import {
|
|
|
107
113
|
deleteMemoryItems,
|
|
108
114
|
clearDeviceMemory,
|
|
109
115
|
createFileIndex,
|
|
116
|
+
loadIndexFolders,
|
|
117
|
+
saveIndexFolders,
|
|
118
|
+
loadIndexExcludes,
|
|
119
|
+
saveIndexExcludes,
|
|
120
|
+
resolveInRoots,
|
|
110
121
|
indexRootsFor,
|
|
111
122
|
runRemoteMission,
|
|
112
123
|
MemoryKind,
|
|
@@ -1025,14 +1036,23 @@ program
|
|
|
1025
1036
|
.command('ui')
|
|
1026
1037
|
.description('Show the Aivin mascot on this computer with its ask box (Windows) - starts the background listener if it is not running')
|
|
1027
1038
|
.option('--demo', 'Preview every mascot animation state without pairing or starting the listener')
|
|
1039
|
+
.option('--moods', 'With --demo: only the faces the mascot makes from the emoji of an answer (sad, cry, sheepish, happy...)')
|
|
1028
1040
|
.action(async (options) => {
|
|
1029
1041
|
const lang = mascotLang();
|
|
1030
1042
|
const say = (key, color = chalk.green) => console.log(color(mascotText(lang, key)));
|
|
1031
1043
|
if (options.demo) {
|
|
1032
|
-
const result = showMascotDemo(
|
|
1044
|
+
const result = showMascotDemo({
|
|
1045
|
+
scope: options.moods ? DemoScope.MOODS : DemoScope.ALL,
|
|
1046
|
+
onEarlyExit: () => {
|
|
1047
|
+
console.error(chalk.yellow('Cửa sổ demo đóng ngay: linh vật thật đang chạy (mỗi lúc chỉ một linh vật). Tắt nó bằng `aivin remote mascot off`, chạy lại demo, xong thì `aivin remote mascot on`.'));
|
|
1048
|
+
process.exitCode = 1;
|
|
1049
|
+
},
|
|
1050
|
+
});
|
|
1033
1051
|
if (result === UiResult.UNSUPPORTED) return say(MascotText.CMD_UNSUPPORTED, chalk.yellow);
|
|
1034
1052
|
if (result === UiResult.START_FAILED) { console.error(chalk.red('Không thể mở bản demo linh vật.')); process.exitCode = 1; return; }
|
|
1035
|
-
console.log(chalk.green(
|
|
1053
|
+
console.log(chalk.green(options.moods
|
|
1054
|
+
? '✓ Demo linh vật đang chạy qua 7 nét mặt theo emoji — đóng cửa sổ hoặc nhấn Ctrl+C để dừng.'
|
|
1055
|
+
: '✓ Demo linh vật đang chạy qua 8 trạng thái + 7 nét mặt theo emoji — đóng cửa sổ hoặc nhấn Ctrl+C để dừng.'));
|
|
1036
1056
|
return;
|
|
1037
1057
|
}
|
|
1038
1058
|
const result = await showMascotUi({ onStarting: () => say(MascotText.UI_STARTING, chalk.gray) });
|
|
@@ -1046,9 +1066,11 @@ program
|
|
|
1046
1066
|
|
|
1047
1067
|
program
|
|
1048
1068
|
.command('desktop [action]')
|
|
1049
|
-
.description('Aivin as a desktop app: install (Windows: system tray + Start menu; macOS: menu bar + Aivin.app; Linux: app menu + tray) and start it with the computer | uninstall | status (default)')
|
|
1069
|
+
.description('Aivin as a desktop app: install (Windows: system tray + Start menu; macOS: menu bar + Aivin.app; Linux: app menu + tray) and start it with the computer | uninstall | defaults (Windows: pick AIVIN Bot as default for file types) | status (default)')
|
|
1050
1070
|
.option('--no-autostart', "install: don't start Aivin with the computer (turn it on later from Aivin's menu or the system's startup settings)")
|
|
1051
1071
|
.option('--no-launch', "install: don't open Aivin now")
|
|
1072
|
+
.option('--export-xml <file>', 'defaults (Windows): write a default-associations file for IT (Group Policy / Intune) instead of opening Settings')
|
|
1073
|
+
.option('--all', 'defaults --export-xml: include Office formats, not only md/txt/csv')
|
|
1052
1074
|
.action((action = 'status', options) => {
|
|
1053
1075
|
// Chỗ bật / tắt khởi động cùng máy của từng hệ điều hành — cùng chỗ menu Aivin và `aivin remote enable|disable` đổi.
|
|
1054
1076
|
const startupWhere = { win32: 'Task Manager → Startup apps', darwin: 'System Settings → General → Login Items', linux: 'Startup Applications / Autostart' }[process.platform] || '';
|
|
@@ -1059,6 +1081,8 @@ program
|
|
|
1059
1081
|
console.log(chalk.green(`✅ Đã cài Aivin vào máy: ${where}.`));
|
|
1060
1082
|
console.log(chalk.gray(` Ứng dụng: ${res.exe}`));
|
|
1061
1083
|
console.log(chalk.gray(` Khởi động cùng máy: ${res.autostart ? 'bật' : 'tắt'} (đổi ở menu Aivin hoặc ${startupWhere})`));
|
|
1084
|
+
if (res.openWith?.registered) console.log(chalk.gray(' Mở tệp: chuột phải tệp → "Mở bằng AIVIN Bot", hoặc Open with → AIVIN Bot → Always để mở mặc định'));
|
|
1085
|
+
else if (res.openWith?.error) console.log(chalk.yellow(` ⚠️ Chưa thêm được "Mở bằng AIVIN Bot": ${res.openWith.error}`));
|
|
1062
1086
|
if (process.platform === 'linux' && !desktopAppStatus().tray) {
|
|
1063
1087
|
console.log(chalk.yellow(' ⚠️ Máy chưa có AppIndicator cho python3 nên không có biểu tượng khay — Aivin vẫn chạy nền. Cài: sudo apt install gir1.2-ayatanaappindicator3-0.1 (Ubuntu / Debian)'));
|
|
1064
1088
|
}
|
|
@@ -1070,7 +1094,19 @@ program
|
|
|
1070
1094
|
if (!res.removed) console.log(chalk.yellow(' ⚠️ Ứng dụng còn đang chạy nên chưa xoá hết được tệp — chạy lại lệnh này sau ít giây.'));
|
|
1071
1095
|
return;
|
|
1072
1096
|
}
|
|
1073
|
-
if (action
|
|
1097
|
+
if (action === 'defaults') {
|
|
1098
|
+
if (process.platform !== 'win32') throw new Error('`aivin desktop defaults` chỉ có trên Windows.');
|
|
1099
|
+
if (options.exportXml) {
|
|
1100
|
+
fs.writeFileSync(options.exportXml, defaultAssociationsXml(options.all ? OPEN_WITH_EXTENSIONS : SAFE_DEFAULT_EXTENSIONS));
|
|
1101
|
+
console.log(chalk.green(`✅ Đã ghi ${options.exportXml} — IT áp bằng Group Policy "Set a default associations configuration file" hoặc Intune.`));
|
|
1102
|
+
return;
|
|
1103
|
+
}
|
|
1104
|
+
openDefaultAppsSettings();
|
|
1105
|
+
console.log(chalk.green('✅ Đã mở Settings → Default apps → AIVIN Bot. Chọn AIVIN Bot cho từng loại tệp để nháy đúp là mở bằng Aivin.'));
|
|
1106
|
+
console.log(chalk.gray(` Nên chọn: ${SAFE_DEFAULT_EXTENSIONS.map((e) => `.${e}`).join(', ')}. Tệp Office dựng lại định dạng khi xuất, nên cân nhắc trước khi đặt mặc định.`));
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
if (action !== 'status') throw new Error('Dùng: aivin desktop install [--no-autostart] [--no-launch] | uninstall | defaults [--export-xml <tệp>] [--all] | status');
|
|
1074
1110
|
const st = desktopAppStatus();
|
|
1075
1111
|
if (st.supported === false) return console.log(chalk.gray(`Chưa có ứng dụng Aivin trên màn hình cho ${process.platform} — dùng \`aivin remote enable\`.`));
|
|
1076
1112
|
console.log(chalk.blue('🖥️ Aivin trên máy này:'));
|
|
@@ -1078,12 +1114,36 @@ program
|
|
|
1078
1114
|
if (st.installed) console.log(chalk.gray(` Tìm bằng: ${st.search || 'không'}`));
|
|
1079
1115
|
console.log(chalk.gray(` Khởi động cùng máy: ${st.startup.registered ? (st.startup.enabled ? 'bật' : `tắt (${startupWhere})`) : 'không'}`));
|
|
1080
1116
|
if (process.platform === 'linux') console.log(chalk.gray(` Biểu tượng khay: ${st.tray ? 'có' : 'không (thiếu python3 + AppIndicator) — vẫn chạy nền'}`));
|
|
1117
|
+
if (process.platform === 'win32') console.log(chalk.gray(` Mở bằng AIVIN Bot: ${st.openWith ? 'có (chuột phải tệp / Open with)' : 'chưa — aivin desktop install'}`));
|
|
1081
1118
|
} catch (error) {
|
|
1082
1119
|
console.error(chalk.red('❌'), error.message);
|
|
1083
1120
|
process.exit(1);
|
|
1084
1121
|
}
|
|
1085
1122
|
});
|
|
1086
1123
|
|
|
1124
|
+
program
|
|
1125
|
+
.command('open <files...>')
|
|
1126
|
+
.description('Open files from this computer in your Aivin Drive (uploads once; the same content reopens the same Drive file). Windows: `aivin desktop install` adds "Open with AIVIN Bot" to Explorer.')
|
|
1127
|
+
.option('-w, --workspace <id>', 'Workspace to upload into (default: your personal workspace)')
|
|
1128
|
+
.option('--tab', 'Open in a normal browser tab instead of its own window')
|
|
1129
|
+
.option('--print', 'Print the Drive link instead of opening anything')
|
|
1130
|
+
.action(async (files, options) => {
|
|
1131
|
+
// Gọi từ Explorer qua Aivin.exe --open (không có console) → báo bằng thông báo hệ điều hành.
|
|
1132
|
+
const toast = process.env.AIVIN_OPEN_UI === 'toast';
|
|
1133
|
+
for (const file of files) {
|
|
1134
|
+
try {
|
|
1135
|
+
if (toast) showOSNotification({ title: 'AIVIN Bot', body: openText('opening', { name: path.basename(file) }) });
|
|
1136
|
+
const display = options.print ? OpenDisplay.NONE : options.tab ? OpenDisplay.TAB : OpenDisplay.WINDOW;
|
|
1137
|
+
const res = await openFile(file, { workspace: options.workspace, display });
|
|
1138
|
+
console.log(options.print ? res.url : chalk.green(`✅ ${res.name} → ${res.url}${res.reused ? ' (Drive copy reused)' : ''}${res.viewOnly ? ' (view only, not signed in - closes with its window)' : ''}`));
|
|
1139
|
+
} catch (error) {
|
|
1140
|
+
console.error(chalk.red('❌'), error.message);
|
|
1141
|
+
if (toast) showOSNotification({ title: openText('failed_title'), body: error.message });
|
|
1142
|
+
process.exitCode = 1;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1087
1147
|
program
|
|
1088
1148
|
.command('update')
|
|
1089
1149
|
.description('Update aivin to the latest release (installs from get.aivin.vn; checks the release signature, the SHA256 and that the new build starts)')
|
|
@@ -1121,6 +1181,16 @@ program
|
|
|
1121
1181
|
}
|
|
1122
1182
|
});
|
|
1123
1183
|
|
|
1184
|
+
// Agent chạy CLI này trong lệnh shell của nó: không đổi việc ghép máy / luật tại máy, không giao việc mới (sandbox.mjs).
|
|
1185
|
+
program.hook('preAction', (_cmd, action) => {
|
|
1186
|
+
try {
|
|
1187
|
+
assertHumanCommand(action.parent?.name(), action.name());
|
|
1188
|
+
} catch (error) {
|
|
1189
|
+
console.error(chalk.red('❌'), error.message);
|
|
1190
|
+
process.exit(1);
|
|
1191
|
+
}
|
|
1192
|
+
});
|
|
1193
|
+
|
|
1124
1194
|
const remoteCommand = program
|
|
1125
1195
|
.command('remote')
|
|
1126
1196
|
.description('Let your Aivin agents work on this computer (Device Agent) - pair, run the listener, manage memory and safety')
|
|
@@ -1174,8 +1244,18 @@ remoteCommand
|
|
|
1174
1244
|
.description('Pair (or re-pair) this computer with your account without starting the listener')
|
|
1175
1245
|
.option('--dir <path>', 'Folder the agent may work in (default: current folder)')
|
|
1176
1246
|
.option('--name <name>', 'Name shown for this computer (default: hostname)')
|
|
1247
|
+
.option('--code <code>', 'Pair with a one-time code from Aivin (chat box → Browser ▾ → Add this computer) - no `aivin login` needed')
|
|
1248
|
+
.option('--server <url>', 'Aivin server the code belongs to')
|
|
1249
|
+
.option('--full-access', 'Let the agent work anywhere on this computer (with --code)')
|
|
1177
1250
|
.action(async (options) => {
|
|
1178
1251
|
try {
|
|
1252
|
+
if (options.code) {
|
|
1253
|
+
// Bộ cài (đã có khay): chỉ ghép — khay mở listener ngay khi thấy máy đã ghép.
|
|
1254
|
+
const { creds, stopped } = await pairWithCodeOnly(options);
|
|
1255
|
+
console.log(chalk.green(`✅ Đã kết nối máy "${creds.name}" với tài khoản ${creds.account || 'Aivin của bạn'} — quay lại Aivin để chọn máy này.`));
|
|
1256
|
+
if (stopped) console.log(chalk.gray(' Đã dừng phiên nhận việc cũ — Aivin mở lại bằng kết nối mới.'));
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1179
1259
|
const roots = [path.resolve(options.dir || process.cwd())];
|
|
1180
1260
|
const creds = await pairDevice({ serverUrl: missionServerUrl(), apiKey: process.env.API_KEY, roots, name: options.name, profile: buildDeviceProfile(roots) });
|
|
1181
1261
|
console.log(chalk.green(`✅ Đã ghép máy "${creds.name}" (${creds.device_id})`));
|
|
@@ -1227,26 +1307,39 @@ remoteCommand
|
|
|
1227
1307
|
|
|
1228
1308
|
remoteCommand
|
|
1229
1309
|
.command('mascot [action] [combo]')
|
|
1230
|
-
.description('The Aivin mascot floating on screen while the listener runs (Windows): on | off — no argument shows the current setting; hotkey [combo|off|default] — the key combination that
|
|
1231
|
-
.
|
|
1310
|
+
.description('The Aivin mascot floating on screen while the listener runs (Windows): on | off — no argument shows the current setting; hotkey [combo|off|default] — the key combination for voice (default Alt+Shift+Space; off turns off both keys), with --chat the one that opens the ask box to type (default Alt+Space)')
|
|
1311
|
+
.option('--chat', 'hotkey: show or set the key that opens the ask box instead of the voice key')
|
|
1312
|
+
.action((action, combo, options) => {
|
|
1232
1313
|
const lang = mascotLang();
|
|
1233
1314
|
if (action === 'hotkey') {
|
|
1234
1315
|
try {
|
|
1235
|
-
const
|
|
1316
|
+
const settings = loadMascotSettings();
|
|
1317
|
+
const key = options.chat ? 'chat_hotkey' : 'hotkey';
|
|
1318
|
+
const otherKey = options.chat ? 'hotkey' : 'chat_hotkey';
|
|
1319
|
+
const defaults = options.chat ? DEFAULT_CHAT_HOTKEYS : DEFAULT_HOTKEYS;
|
|
1320
|
+
const name = options.chat ? 'Phím tắt mở ô hỏi' : 'Phím tắt nói chuyện';
|
|
1321
|
+
const setting = settings[key];
|
|
1236
1322
|
if (!combo) {
|
|
1237
|
-
const active = hotkeyCandidates(setting);
|
|
1238
|
-
if (
|
|
1239
|
-
return console.log(
|
|
1323
|
+
const active = hotkeyCandidates(setting, defaults);
|
|
1324
|
+
if (settings.hotkey === 'off') return console.log(`${name}: tắt (bật lại: aivin remote mascot hotkey default)`);
|
|
1325
|
+
if (!active.length) return console.log(`${name}: tắt (bật lại: aivin remote mascot hotkey --chat default)`);
|
|
1326
|
+
return console.log(`${name}: ${active[0].label}${setting ? '' : ' (mặc định)'} — không đăng ký được thì thử lần lượt: ${active.slice(1).map((h) => h.label).join(', ')}`);
|
|
1240
1327
|
}
|
|
1241
|
-
if (combo === 'off') {
|
|
1242
|
-
|
|
1328
|
+
if (combo === 'off') {
|
|
1329
|
+
saveMascotSettings({ [key]: 'off' });
|
|
1330
|
+
return console.log(chalk.green(options.chat ? '✅ Đã tắt phím tắt mở ô hỏi.' : '✅ Đã tắt phím tắt gọi linh vật (cả nói chuyện và mở ô hỏi).'));
|
|
1331
|
+
}
|
|
1332
|
+
if (combo === 'default') { saveMascotSettings({ [key]: null }); return console.log(chalk.green(`✅ ${name}: dùng mặc định ${defaults[0]}.`)); }
|
|
1243
1333
|
const hotkey = parseHotkey(combo);
|
|
1334
|
+
if (settings[otherKey] && settings[otherKey] !== 'off' && parseHotkey(settings[otherKey]).label === hotkey.label) {
|
|
1335
|
+
throw new Error(`${hotkey.label} đang dùng cho ${options.chat ? 'nói chuyện' : 'mở ô hỏi'} — chọn tổ hợp khác.`);
|
|
1336
|
+
}
|
|
1244
1337
|
const free = probeHotkey(hotkey);
|
|
1245
1338
|
if (free === false) {
|
|
1246
1339
|
console.log(chalk.yellow(`⚠️ ${hotkey.label} đang bị một ứng dụng khác (hoặc chính linh vật đang chạy) giữ — nếu không phải linh vật thì chọn tổ hợp khác.`));
|
|
1247
1340
|
}
|
|
1248
|
-
saveMascotSettings({
|
|
1249
|
-
return console.log(chalk.green(`✅
|
|
1341
|
+
saveMascotSettings({ [key]: hotkey.label });
|
|
1342
|
+
return console.log(chalk.green(`✅ ${name}: ${hotkey.label} — có hiệu lực khi linh vật khởi động lại (aivin remote start).`));
|
|
1250
1343
|
} catch (error) {
|
|
1251
1344
|
return remoteFail(error);
|
|
1252
1345
|
}
|
|
@@ -1464,6 +1557,57 @@ remoteCommand
|
|
|
1464
1557
|
}
|
|
1465
1558
|
});
|
|
1466
1559
|
|
|
1560
|
+
remoteCommand
|
|
1561
|
+
.command('index [action] [folder]')
|
|
1562
|
+
.description('Working folders indexed fully (code too) so agents find everything in them instantly: list (default) | add <folder> | remove <folder>. Agents add one themselves when you tell them in chat where you work')
|
|
1563
|
+
.action((action = 'list', folder) => {
|
|
1564
|
+
try {
|
|
1565
|
+
const creds = loadDeviceCredentials();
|
|
1566
|
+
if (action === 'list') {
|
|
1567
|
+
const folders = loadIndexFolders();
|
|
1568
|
+
if (!folders.length) return console.log(chalk.gray('Chưa có thư mục làm việc nào. Thêm: aivin remote index add <thư mục>'));
|
|
1569
|
+
return folders.forEach((f) => console.log(`📁 ${f}`));
|
|
1570
|
+
}
|
|
1571
|
+
if (!['add', 'remove'].includes(action) || !folder) throw new Error('Dùng: aivin remote index [list | add <thư mục> | remove <thư mục>]');
|
|
1572
|
+
// Chỉ trong thư mục máy cho phép — chỉ mục ngoài đó trả về tệp mà agent không mở được.
|
|
1573
|
+
const abs = creds?.roots?.length ? resolveInRoots(creds.roots, folder) : path.resolve(folder);
|
|
1574
|
+
if (action === 'add') {
|
|
1575
|
+
if (!fs.statSync(abs, { throwIfNoEntry: false })?.isDirectory()) throw new Error(`Không phải thư mục: ${abs}`);
|
|
1576
|
+
saveIndexFolders([...loadIndexFolders(), abs]);
|
|
1577
|
+
console.log(chalk.green(`✅ Đã thêm thư mục làm việc ${abs} — listener đang chạy sẽ lập chỉ mục trong vài giây.`));
|
|
1578
|
+
} else {
|
|
1579
|
+
saveIndexFolders(loadIndexFolders().filter((f) => f !== abs));
|
|
1580
|
+
console.log(chalk.green(`✅ Đã bỏ thư mục làm việc ${abs}`));
|
|
1581
|
+
}
|
|
1582
|
+
} catch (error) {
|
|
1583
|
+
remoteFail(error);
|
|
1584
|
+
}
|
|
1585
|
+
});
|
|
1586
|
+
|
|
1587
|
+
remoteCommand
|
|
1588
|
+
.command('index-exclude [action] [pattern]')
|
|
1589
|
+
.description('Custom exclude rules for file indexing: list (default) | add <name/pattern> | remove <name/pattern>')
|
|
1590
|
+
.action((action = 'list', pattern) => {
|
|
1591
|
+
try {
|
|
1592
|
+
if (action === 'list') {
|
|
1593
|
+
const excludes = loadIndexExcludes();
|
|
1594
|
+
if (!excludes.length) return console.log(chalk.gray('Chưa có mẫu loại trừ tuỳ biến nào. Thêm: aivin remote index-exclude add <tên_hoặc_mẫu>'));
|
|
1595
|
+
return excludes.forEach((e) => console.log(`🚫 ${e}`));
|
|
1596
|
+
}
|
|
1597
|
+
if (!['add', 'remove'].includes(action) || !pattern) throw new Error('Dùng: aivin remote index-exclude [list | add <mẫu> | remove <mẫu>]');
|
|
1598
|
+
const item = String(pattern).trim();
|
|
1599
|
+
if (action === 'add') {
|
|
1600
|
+
saveIndexExcludes([...loadIndexExcludes(), item]);
|
|
1601
|
+
console.log(chalk.green(`✅ Đã thêm mẫu loại trừ "${item}" — listener đang chạy sẽ áp dụng trong vài giây.`));
|
|
1602
|
+
} else {
|
|
1603
|
+
saveIndexExcludes(loadIndexExcludes().filter((e) => e.toLowerCase() !== item.toLowerCase()));
|
|
1604
|
+
console.log(chalk.green(`✅ Đã xoá mẫu loại trừ "${item}"`));
|
|
1605
|
+
}
|
|
1606
|
+
} catch (error) {
|
|
1607
|
+
remoteFail(error);
|
|
1608
|
+
}
|
|
1609
|
+
});
|
|
1610
|
+
|
|
1467
1611
|
remoteCommand
|
|
1468
1612
|
.command('reset-id')
|
|
1469
1613
|
.description('Give this computer a new device id (cloned machines) - you must pair again')
|
|
@@ -1908,5 +2052,7 @@ function resolveIsMain() {
|
|
|
1908
2052
|
}
|
|
1909
2053
|
|
|
1910
2054
|
if (resolveIsMain()) {
|
|
1911
|
-
|
|
2055
|
+
// Tiến trình con WebRTC của xem màn hình từ web (daemon tự gọi, không phải lệnh cho người dùng) — xem lib/remote/desktop/webrtcWorker.mjs.
|
|
2056
|
+
if (process.argv.includes(DESKTOP_WEBRTC_WORKER_ARG)) await runDesktopWebRtcWorker();
|
|
2057
|
+
else program.parse(process.argv);
|
|
1912
2058
|
}
|