vamp-mcp 0.2.0 → 0.2.4

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 (134) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +144 -107
  3. package/THIRD_PARTY_NOTICES.md +32 -27
  4. package/bin/vamp-mcp.mjs +37 -37
  5. package/notices/mcp-virtualbox-LICENSE +21 -21
  6. package/notices/mcp-virtualbox-PROVENANCE.json +37 -37
  7. package/package.json +51 -17
  8. package/runtime/backends/common/Test-Environment.ps1 +7 -6
  9. package/runtime/backends/common/guest-install.json +58 -0
  10. package/runtime/backends/common/guest_install.py +57 -0
  11. package/runtime/backends/common/host-support.cjs +16 -0
  12. package/runtime/backends/common/packer.cjs +16 -0
  13. package/runtime/backends/hyperv/scripts/Manage-Desktop.ps1 +40 -67
  14. package/runtime/backends/hyperv/scripts/Send-InstallerBoot.ps1 +25 -0
  15. package/runtime/backends/kvm/debian-preseed.cfg +35 -35
  16. package/runtime/backends/library/registry.py +77 -77
  17. package/runtime/backends/library/replay.py +154 -154
  18. package/runtime/backends/packer/answer_media.py +16 -0
  19. package/runtime/backends/packer/deploy-hyperv.ps1 +10 -0
  20. package/runtime/backends/packer/drivers.py +49 -0
  21. package/runtime/backends/packer/hyperv-network.ps1 +10 -0
  22. package/runtime/backends/packer/images.py +75 -0
  23. package/runtime/backends/packer/osinfo.py +113 -0
  24. package/runtime/backends/packer/policy.json +15 -0
  25. package/runtime/backends/packer/runner.py +224 -0
  26. package/runtime/backends/packer/templates.py +118 -0
  27. package/runtime/backends/packer/toolchain.py +80 -0
  28. package/runtime/backends/remote_ssh/server.mjs +310 -93
  29. package/runtime/backends/virtualbox/desktop.cjs +37 -0
  30. package/runtime/backends/virtualbox/display.py +101 -101
  31. package/runtime/backends/virtualbox/history.py +139 -139
  32. package/runtime/backends/virtualbox/mouse_click.py +15 -15
  33. package/runtime/backends/virtualbox/mouse_move.py +18 -18
  34. package/runtime/backends/virtualbox/profiles.json +46 -46
  35. package/runtime/backends/virtualbox/provision.py +238 -197
  36. package/runtime/backends/virtualbox/recording_listener.py +29 -29
  37. package/runtime/backends/virtualbox/recordings.py +39 -39
  38. package/runtime/backends/virtualbox/requirements.txt +7 -7
  39. package/runtime/backends/virtualbox/rpas/debian_first_boot/manifest.json +1 -1
  40. package/runtime/backends/virtualbox/rpas/debian_first_boot/run.robot +13 -13
  41. package/runtime/backends/virtualbox/rpas/debian_first_boot/workflow.py +75 -75
  42. package/runtime/backends/virtualbox/rpas/observe/manifest.json +7 -7
  43. package/runtime/backends/virtualbox/rpas/observe/run.robot +13 -13
  44. package/runtime/backends/virtualbox/rpas/observe/workflow.py +14 -14
  45. package/runtime/backends/virtualbox/server.mjs +288 -237
  46. package/runtime/backends/virtualbox/setup_windows_sdk.py +58 -58
  47. package/runtime/backends/virtualbox/shares.py +68 -68
  48. package/runtime/backends/virtualbox/snapshots.py +53 -53
  49. package/runtime/backends/virtualbox/transfers.py +89 -89
  50. package/runtime/backends/virtualbox/vnc.py +61 -61
  51. package/runtime/guest_keys.py +13 -13
  52. package/runtime/guest_setup/http/debian-preseed.cfg +39 -0
  53. package/runtime/guest_setup/http/postdeb.sh +50 -3
  54. package/runtime/guest_setup/http/postwin.ps1 +53 -28
  55. package/runtime/guest_setup/http/setup-all.ps1 +25 -25
  56. package/runtime/guest_setup/http/setup-win.cmd +7 -7
  57. package/runtime/guest_setup/http/setup.ps1 +44 -29
  58. package/runtime/guest_setup/kvm/setup-windows.ps1 +52 -52
  59. package/runtime/guest_setup/recorder/README.txt +12 -12
  60. package/runtime/guest_setup/recorder/RECORDER-LICENSE +674 -674
  61. package/runtime/guest_setup/recorder/RECORDING-GUIDE.txt +31 -31
  62. package/runtime/guest_setup/recorder/apply-display.py +41 -41
  63. package/runtime/guest_setup/recorder/configure-debian-mirrors.py +62 -62
  64. package/runtime/guest_setup/recorder/configure-gdm.py +23 -0
  65. package/runtime/guest_setup/recorder/configure-session.ps1 +14 -0
  66. package/runtime/guest_setup/recorder/gnome-display.py +60 -60
  67. package/runtime/guest_setup/recorder/install-display-startup.py +67 -39
  68. package/runtime/guest_setup/recorder/install-hypervisor-drivers.ps1 +34 -0
  69. package/runtime/guest_setup/recorder/install-resolution-shortcut.ps1 +36 -0
  70. package/runtime/guest_setup/recorder/postwin.cmd +10 -10
  71. package/runtime/guest_setup/recorder/prepare-recording.py +30 -30
  72. package/runtime/guest_setup/recorder/requirements-recorder.txt +2 -2
  73. package/runtime/guest_setup/recorder/session-policy.py +22 -0
  74. package/runtime/guest_setup/recorder/set-resolution-registry.ps1 +40 -0
  75. package/runtime/guest_setup/recorder/setup-user.py +53 -53
  76. package/runtime/guest_setup/recorder/setup-win.cmd +4 -60
  77. package/runtime/guest_setup/recorder/setup.ps1 +112 -81
  78. package/runtime/guest_setup/recorder/setup.sh +1 -0
  79. package/runtime/guest_setup/recorder/vamp-recorder.py +148 -148
  80. package/runtime/guest_setup/recorder/verify-recorder.py +4 -4
  81. package/runtime/guest_setup/recorder/windows-display.py +76 -76
  82. package/runtime/guest_setup/requirements.txt +2 -2
  83. package/runtime/guest_setup/setup-all.ps1 +35 -35
  84. package/runtime/guest_setup/vault/Install-VCRuntime.ps1 +26 -26
  85. package/runtime/guest_setup/vault/setup-guest-vault.ps1 +148 -148
  86. package/runtime/recording_converter.py +230 -230
  87. package/runtime/requirements-mcp.txt +11 -11
  88. package/runtime/rpas/README.md +161 -161
  89. package/runtime/rpas/captcha_handoff/manifest.json +27 -27
  90. package/runtime/rpas/captcha_handoff/run.robot +16 -16
  91. package/runtime/rpas/captcha_handoff/workflow.py +11 -11
  92. package/runtime/rpas/common.resource +26 -26
  93. package/runtime/rpas/debian_update/manifest.json +27 -27
  94. package/runtime/rpas/debian_update/run.robot +17 -17
  95. package/runtime/rpas/debian_update/workflow.py +13 -13
  96. package/runtime/rpas/desktop_control/manifest.json +26 -26
  97. package/runtime/rpas/desktop_control/run.robot +27 -27
  98. package/runtime/rpas/desktop_control/workflow.py +51 -51
  99. package/runtime/rpas/firefox_launch/manifest.json +27 -27
  100. package/runtime/rpas/firefox_launch/run.robot +15 -15
  101. package/runtime/rpas/firefox_launch/workflow.py +25 -25
  102. package/runtime/rpas/firefox_naver/manifest.json +27 -27
  103. package/runtime/rpas/firefox_naver/run.robot +21 -21
  104. package/runtime/rpas/firefox_naver/workflow.py +28 -28
  105. package/runtime/rpas/kvm_validation/README.md +11 -11
  106. package/runtime/rpas/kvm_validation/manifest.json +28 -28
  107. package/runtime/rpas/kvm_validation/run.robot +30 -30
  108. package/runtime/rpas/kvm_validation/workflow.py +91 -91
  109. package/runtime/rpas/manifest.schema.json +105 -105
  110. package/runtime/rpas/naver_login/login.robot +25 -25
  111. package/runtime/rpas/naver_login/manifest.json +33 -33
  112. package/runtime/rpas/naver_login/run.robot +20 -20
  113. package/runtime/rpas/naver_login/workflow.py +32 -32
  114. package/runtime/rpas/windows_naver_recorded/README.md +24 -24
  115. package/runtime/rpas/windows_naver_recorded/conversion.json +25 -25
  116. package/runtime/rpas/windows_naver_recorded/manifest.json +28 -28
  117. package/runtime/rpas/windows_naver_recorded/run.robot +37 -37
  118. package/runtime/rpas/windows_naver_recorded/workflow.py +32 -32
  119. package/runtime/scripts/build_recorder_media.py +39 -39
  120. package/runtime/scripts/macos/setup-host.sh +0 -0
  121. package/runtime/scripts/script_server.py +571 -517
  122. package/runtime/skills/vamp-rpa-ui-checks/SKILL.md +26 -0
  123. package/runtime/skills/vamp-rpa-ui-checks/agents/openai.yaml +4 -0
  124. package/runtime/skills/vamp-rpa-ui-checks/references/display.md +12 -0
  125. package/runtime/skills/vamp-rpa-ui-checks/references/user-guide.md +51 -0
  126. package/runtime/skills/vamp-ui-cleanup/SKILL.md +15 -0
  127. package/runtime/skills/vamp-ui-cleanup/agents/openai.yaml +4 -0
  128. package/runtime/skills/vamp-ui-validation/SKILL.md +27 -0
  129. package/runtime/skills/vamp-ui-validation/agents/openai.yaml +4 -0
  130. package/runtime/third_party/mcp-virtualbox/scripts/mouse_click.py +65 -65
  131. package/runtime/third_party/pyautogui-recorder/LICENSE +674 -674
  132. package/runtime/third_party/pyautogui-recorder/PROVENANCE.json +16 -16
  133. package/runtime/third_party/pyautogui-recorder/PyAutoGuiRecorder.py +169 -169
  134. package/runtime/third_party/pyautogui-recorder/README.md +53 -53
@@ -32,9 +32,125 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
32
32
  mod
33
33
  ));
34
34
 
35
- // backends/common/host-backends.cjs
36
- var require_host_backends = __commonJS({
37
- "backends/common/host-backends.cjs"(exports, module) {
35
+ // backends/common/guest-install.json
36
+ var require_guest_install = __commonJS({
37
+ "backends/common/guest-install.json"(exports, module) {
38
+ module.exports = {
39
+ schema_version: 1,
40
+ boot_wait_seconds: 10,
41
+ script_server_port: 8421,
42
+ hosts: {
43
+ virtualbox: [
44
+ "win32",
45
+ "linux",
46
+ "darwin"
47
+ ],
48
+ hyperv: [
49
+ "win32"
50
+ ],
51
+ kvm: [
52
+ "linux"
53
+ ],
54
+ "apple-hypervisor": [
55
+ "darwin"
56
+ ]
57
+ },
58
+ amd64_install_host_arches: [
59
+ "x64",
60
+ "AMD64",
61
+ "x86_64"
62
+ ],
63
+ debian: {
64
+ cfg: "debian-preseed.cfg",
65
+ efi_boot: [
66
+ {
67
+ kind: "text",
68
+ text: "c"
69
+ },
70
+ {
71
+ kind: "wait",
72
+ seconds: 1
73
+ },
74
+ {
75
+ kind: "line",
76
+ text: "linux /install.amd/vmlinuz auto=true priority=critical preseed/url={base_url}/debian-preseed.cfg vamp_base={base_url} --- quiet"
77
+ },
78
+ {
79
+ kind: "line",
80
+ text: "initrd /install.amd/initrd.gz"
81
+ },
82
+ {
83
+ kind: "line",
84
+ text: "boot"
85
+ }
86
+ ]
87
+ },
88
+ windows11: {
89
+ efi_boot: [
90
+ {
91
+ kind: "enter"
92
+ }
93
+ ]
94
+ }
95
+ };
96
+ }
97
+ });
98
+
99
+ // backends/common/host-support.cjs
100
+ var require_host_support = __commonJS({
101
+ "backends/common/host-support.cjs"(exports, module) {
102
+ var profile = require_guest_install();
103
+ function requireBackendHost(backend, platform = process.platform) {
104
+ if (!profile.hosts[backend]?.includes(platform)) throw Error(`${backend} local management is unsupported on ${platform}`);
105
+ }
106
+ function requireInstallHost(backend, platform = process.platform, architecture = process.arch) {
107
+ requireBackendHost(backend, platform);
108
+ if (!profile.amd64_install_host_arches.includes(architecture)) throw Error(`Current amd64 installer profiles require an x64 host; ${architecture} is unsupported`);
109
+ }
110
+ function backendCapabilities(platform = process.platform) {
111
+ return Object.fromEntries(Object.entries(profile.hosts).map(([backend, hosts]) => [backend, {
112
+ hostSupported: hosts.includes(platform),
113
+ implemented: backend !== "apple-hypervisor",
114
+ reason: !hosts.includes(platform) ? "unsupported_host" : backend === "apple-hypervisor" ? "not_implemented" : null
115
+ }]));
116
+ }
117
+ module.exports = { requireBackendHost, requireInstallHost, backendCapabilities };
118
+ }
119
+ });
120
+
121
+ // backends/common/packer.cjs
122
+ var require_packer = __commonJS({
123
+ "backends/common/packer.cjs"(exports, module) {
124
+ var path3 = __require("node:path");
125
+ var { execFile: execFile2 } = __require("node:child_process");
126
+ function packer({ runtime, python = () => process.env.RPA_HOST_PYTHON || (process.platform === "win32" ? "python" : "python3"), spawn = execFile2 } = {}) {
127
+ return function call(action, { backend = "virtualbox", id, confirmed = false, ...request } = {}) {
128
+ const args = [path3.join(runtime, "backends/packer/runner.py"), action, "--backend", backend];
129
+ if (id) args.push("--id", id);
130
+ if (confirmed) args.push("--confirmed");
131
+ return new Promise((resolve, reject) => {
132
+ const child = spawn(typeof python === "function" ? python() : python, args, { windowsHide: true, timeout: 6e5, maxBuffer: 4 * 1024 ** 2 }, (error, stdout, stderr) => {
133
+ let data;
134
+ try {
135
+ data = JSON.parse(stdout);
136
+ } catch {
137
+ }
138
+ if (error || data?.status === "failed") reject(Error(data?.error || stderr || error?.message || "Packer response was invalid"));
139
+ else resolve(data);
140
+ });
141
+ child.stdin.on("error", () => {
142
+ });
143
+ child.stdin.end(action === "create" ? JSON.stringify({ backend, ...request }) : "");
144
+ });
145
+ };
146
+ }
147
+ module.exports = { packer };
148
+ }
149
+ });
150
+
151
+ // backends/kvm/desktop.cjs
152
+ var require_desktop = __commonJS({
153
+ "backends/kvm/desktop.cjs"(exports, module) {
38
154
  var fs2 = __require("node:fs");
39
155
  var path3 = __require("node:path");
40
156
  var { execFile: execFile2 } = __require("node:child_process");
@@ -65,8 +181,9 @@ var require_host_backends = __commonJS({
65
181
  }
66
182
  throw Error("This VM does not expose VNC. Create a KVM desktop here to use the embedded viewer.");
67
183
  }
68
- function hostBackends(context, { runtime, config, execute = run }) {
69
- const storage = path3.join(context.globalStorageUri.fsPath, "desktops");
184
+ function createKvmAdapter(context, { runtime, config, execute = run, platform = process.platform }) {
185
+ require_host_support().requireBackendHost("kvm", platform);
186
+ const storage = path3.join(process.env.VAMP_HOME || path3.join(__require("node:os").homedir(), ".vamp"), "vms");
70
187
  const uri = () => config().get("libvirtUri") || "qemu:///session";
71
188
  const command = async (exe, args, timeout = 3e4) => (await execute(exe, args, { timeout, maxBuffer: 4 * 1024 ** 2, env: { ...process.env, LC_ALL: "C" } })).stdout;
72
189
  const virsh = (args) => command("virsh", ["-c", uri(), ...args]);
@@ -74,25 +191,22 @@ var require_host_backends = __commonJS({
74
191
  if (!UUID.test(id)) throw Error("Invalid VM identifier");
75
192
  return id;
76
193
  };
77
- const record = (backend, name) => path3.join(storage, backend, name, "vamp-ui.json");
78
194
  function managed(backend, id) {
79
- const root = path3.join(storage, backend);
80
- if (!fs2.existsSync(root)) return;
81
- for (const name of fs2.readdirSync(root)) {
82
- try {
83
- const item = JSON.parse(fs2.readFileSync(record(backend, name), "utf8"));
84
- if (item.id === id) return { ...item, folder: path3.dirname(record(backend, name)) };
85
- } catch {
195
+ for (const base of [storage, path3.join(context.globalStorageUri.fsPath, "desktops")]) {
196
+ const root = path3.join(base, backend);
197
+ if (!fs2.existsSync(root)) continue;
198
+ for (const name of fs2.readdirSync(root)) {
199
+ const record = path3.join(root, name, "vamp-ui.json");
200
+ try {
201
+ const item = JSON.parse(fs2.readFileSync(record, "utf8"));
202
+ if (item.id === id) return { ...item, folder: path3.dirname(record) };
203
+ } catch {
204
+ }
86
205
  }
87
206
  }
88
207
  }
89
- async function hyperv(action, data = {}) {
90
- if (process.platform !== "win32") throw Error("Hyper-V management is available on a Windows host with Hyper-V enabled.");
91
- const result = await command("powershell.exe", ["-NoLogo", "-NoProfile", "-NonInteractive", "-File", path3.join(runtime, "backends/hyperv/scripts/Manage-Desktop.ps1"), "-RequestBase64", Buffer.from(JSON.stringify({ action, ...data })).toString("base64"), "-StoragePath", path3.join(storage, "hyperv")], 18e4);
92
- return JSON.parse(result);
93
- }
94
208
  async function ensureNoVirtualBox() {
95
- if (process.platform !== "linux") return;
209
+ if (platform !== "linux") return;
96
210
  try {
97
211
  const active = await command(process.env.VBOXMANAGE_PATH || "VBoxManage", ["list", "runningvms"]);
98
212
  if (active.trim()) throw Error("A VirtualBox VM is active. Shut it down before starting KVM; simultaneous execution can crash VirtualBox (VERR_SVM_IN_USE).");
@@ -101,19 +215,14 @@ var require_host_backends = __commonJS({
101
215
  }
102
216
  }
103
217
  return {
104
- async check(backend) {
105
- if (backend === "hyperv") {
106
- await hyperv("check");
107
- return "Hyper-V ready";
108
- }
109
- if (process.platform !== "linux") throw Error("KVM requires a Linux host. Choose VirtualBox or Hyper-V on Windows.");
218
+ async check() {
219
+ if (platform !== "linux") throw Error("KVM requires a Linux host. Choose VirtualBox or Hyper-V on Windows.");
110
220
  await virsh(["list", "--all", "--uuid"]);
111
221
  await command("virt-install", ["--version"]);
112
222
  await command("qemu-img", ["--version"]);
113
223
  return "KVM \xB7 " + uri();
114
224
  },
115
- async list(backend) {
116
- if (backend === "hyperv") return (await hyperv("list")).vms;
225
+ async list() {
117
226
  const ids = (await virsh(["list", "--all", "--uuid"])).split(/\s+/).filter((id) => UUID.test(id));
118
227
  return Promise.all(ids.map(async (id) => {
119
228
  const info = domainInfo(await virsh(["dumpxml", id]));
@@ -121,86 +230,183 @@ var require_host_backends = __commonJS({
121
230
  return { ...info, backend: "kvm", state: { "shut off": "poweroff", running: "running", paused: "paused", crashed: "aborted" }[raw] || raw, managed: !!managed("kvm", id) };
122
231
  }));
123
232
  },
124
- async create(backend, { name, iso_path, guest_os, memory_mb, cpus, disk_mb, installation_mode }) {
125
- if (!/^[A-Za-z][A-Za-z0-9_-]{0,62}$/.test(name)) throw Error("Use a name starting with a letter, followed by letters, numbers, hyphens or underscores.");
126
- if (!["debian", "ubuntu", "windows11"].includes(guest_os)) throw Error("Unsupported operating system");
127
- if (backend === "hyperv") return hyperv("create", { name, iso_path, guest_os, memory_mb, cpus, disk_mb, installation_mode });
128
- if (backend !== "kvm") throw Error("Unsupported backend");
129
- for (const [value, min, max] of [[memory_mb, guest_os === "windows11" ? 4096 : 2048, 131072], [cpus, 1, 64], [disk_mb, 32768, 2097152]]) if (!Number.isInteger(value) || value < min || value > max) throw Error("Invalid VM resources");
130
- const mode = installation_mode || (guest_os === "debian" ? "unattended" : "manual");
131
- if (!["manual", "unattended"].includes(mode) || mode === "unattended" && guest_os !== "debian") throw Error("Automatic installation is supported for Debian amd64 installer ISOs only");
132
- if (!fs2.statSync(iso_path).isFile() || iso_path.includes(",")) throw Error("Choose a readable local ISO without a comma in its path.");
133
- await ensureNoVirtualBox();
134
- const existing = await virsh(["list", "--all", "--name"]);
135
- if (existing.split(/\r?\n/).includes(name)) throw Error("A VM with this name already exists.");
136
- const folder = path3.join(storage, "kvm", name);
137
- fs2.mkdirSync(path3.dirname(folder), { recursive: true });
138
- fs2.mkdirSync(folder);
139
- const disk = path3.join(folder, "disk.qcow2");
140
- let installer = iso_path, location = [];
141
- if (mode === "unattended") {
142
- const packaged = path3.join(runtime, "backends/kvm/debian-preseed.cfg");
143
- if (!fs2.existsSync(packaged)) throw Error("Packaged Debian preseed file is missing from the VAMP runtime; choose manual installation.");
144
- const preseed = path3.join(folder, "preseed.cfg");
145
- fs2.copyFileSync(packaged, preseed);
146
- location = [
147
- "--location",
148
- `${iso_path},kernel=install.amd/vmlinuz,initrd=install.amd/initrd.gz`,
149
- "--initrd-inject",
150
- preseed,
151
- "--extra-args",
152
- "auto=true priority=critical preseed/file=/preseed.cfg console=ttyS0,115200n8 console=tty0"
153
- ];
154
- installer = null;
155
- }
156
- fs2.writeFileSync(path3.join(folder, "creation.json"), JSON.stringify({ status: "preparing", name, disk, iso_path }));
157
- await command("qemu-img", ["create", "-f", "qcow2", disk, `${disk_mb}M`]);
158
- const args = ["--connect", uri(), "--name", name, "--virt-type", "kvm", "--memory", String(memory_mb), "--vcpus", String(cpus), "--cpu", "host-passthrough", "--disk", `path=${disk},format=qcow2,bus=${guest_os === "windows11" ? "sata" : "virtio"}`, ...installer ? ["--disk", `path=${installer},device=cdrom,readonly=on`] : [], ...location, ...location.length ? [] : ["--import"], "--osinfo", "detect=on,require=off", "--graphics", "vnc,listen=127.0.0.1", "--video", guest_os === "windows11" ? "vga" : "virtio", "--input", "tablet,bus=usb", "--network", uri().endsWith("/session") ? "user,model=e1000e" : "network=default,model=virtio", "--noautoconsole", "--serial", `pty,log.file=${path3.join(folder, "serial.log")},log.append=on`];
159
- if (guest_os === "windows11") args.push("--boot", "uefi,hd,cdrom", "--tpm", "backend.type=emulator,backend.version=2.0,model=tpm-crb");
160
- else args.push("--boot", "hd,cdrom");
161
- try {
162
- await command("virt-install", args, 18e4);
163
- } catch (error) {
164
- throw Error(`KVM setup failed. Partial setup preserved at ${folder}. ${error.message}${mode === "unattended" ? " Debian automatic installation reads the stock ISO with virt-install; if the host lacks that tooling, choose manual installation (xorriso is no longer used)." : ""}`);
165
- }
166
- const id = (await virsh(["domuuid", name])).trim();
167
- checkID(id);
168
- const state = (await virsh(["domstate", id])).trim();
169
- if (state !== "running") throw Error(`VM was created but did not start (state: ${state}). Setup is preserved at ${folder}`);
170
- fs2.writeFileSync(record("kvm", name), JSON.stringify({ id, name, disk, guest_os, installation_mode: mode }));
171
- return { status: "installation_started", installation_mode: mode, vm: name, id, vm_state: state, startup_verified: true, installation_verified: false, serial_log: path3.join(folder, "serial.log"), ...mode === "unattended" ? { credentials: { username: "vboxuser", password: "password123!", public_sandbox_credentials: true } } : {} };
172
- },
173
- async start(backend, id) {
233
+ create: (values) => require_packer().packer({ runtime, python: () => config().get("kvmPythonExecutable") || "python3" })("create", { backend: "kvm", libvirt_uri: uri(), ...values }),
234
+ async start(id) {
174
235
  checkID(id);
175
- if (backend === "hyperv") return hyperv("start", { id });
176
236
  await ensureNoVirtualBox();
177
237
  await virsh(["start", id]);
178
238
  const state = (await virsh(["domstate", id])).trim();
179
239
  if (state !== "running") throw Error("VM did not reach Running state: " + state);
180
240
  return { status: "running", startup_verified: true };
181
241
  },
182
- async stop(backend, id) {
242
+ async stop(id) {
183
243
  checkID(id);
184
- if (backend === "hyperv") return hyperv("stop", { id });
185
244
  return virsh(["shutdown", id]);
186
245
  },
187
246
  async endpoint(id) {
188
247
  checkID(id);
189
248
  return vncEndpoint(await virsh(["dumpxml", id]));
190
249
  },
191
- async remove(backend, id) {
250
+ async remove(id) {
192
251
  checkID(id);
193
- if (backend === "hyperv") return hyperv("delete", { id });
194
252
  const item = managed("kvm", id);
195
253
  if (!item) throw Error("Only desktops created by VAMP can be deleted here.");
196
254
  const state = (await virsh(["domstate", id])).trim();
197
255
  if (state !== "shut off") throw Error("Shut down the VM before deleting it.");
198
256
  await virsh(["undefine", id, "--nvram", "--tpm", "--managed-save", "--snapshots-metadata", "--checkpoints-metadata"]);
257
+ if (item.volume) {
258
+ if (item.pool !== "default" || !/^vamp-[A-Za-z][A-Za-z0-9_-]{0,62}\.qcow2$/.test(item.volume)) throw Error("Unexpected managed storage volume; inspect the ownership record.");
259
+ await virsh(["vol-delete", "--pool", item.pool, item.volume]);
260
+ }
199
261
  fs2.rmSync(item.folder, { recursive: true, force: true });
200
262
  }
201
263
  };
202
264
  }
203
- module.exports = { hostBackends, domainInfo, vncEndpoint };
265
+ module.exports = { createKvmAdapter, domainInfo, vncEndpoint };
266
+ }
267
+ });
268
+
269
+ // backends/hyperv/desktop.cjs
270
+ var require_desktop2 = __commonJS({
271
+ "backends/hyperv/desktop.cjs"(exports, module) {
272
+ var path3 = __require("node:path");
273
+ var { execFile: execFile2 } = __require("node:child_process");
274
+ var { promisify } = __require("node:util");
275
+ var { requireBackendHost } = require_host_support();
276
+ function createHyperVAdapter(context, { runtime, execute = promisify(execFile2), platform = process.platform }) {
277
+ requireBackendHost("hyperv", platform);
278
+ const storage = path3.join(process.env.VAMP_HOME || path3.join(__require("node:os").homedir(), ".vamp"), "vms/hyperv");
279
+ async function call(action, data = {}) {
280
+ const request = Buffer.from(JSON.stringify({ action, ...data })).toString("base64");
281
+ const result = await execute("powershell.exe", ["-NoLogo", "-NoProfile", "-NonInteractive", "-File", path3.join(runtime, "backends/hyperv/scripts/Manage-Desktop.ps1"), "-RequestBase64", request, "-StoragePath", storage, "-LegacyStoragePath", path3.join(context.globalStorageUri.fsPath, "desktops/hyperv")], { timeout: 18e4, maxBuffer: 4 * 1024 ** 2 });
282
+ return JSON.parse(result.stdout);
283
+ }
284
+ return {
285
+ check: async () => {
286
+ await call("check");
287
+ return "Hyper-V ready";
288
+ },
289
+ list: async () => (await call("list")).vms,
290
+ create: (values) => require_packer().packer({ runtime })("create", { backend: "hyperv", ...values }),
291
+ start: (id) => call("start", { id }),
292
+ stop: (id) => call("stop", { id }),
293
+ remove: (id) => call("delete", { id })
294
+ };
295
+ }
296
+ module.exports = { createHyperVAdapter };
297
+ }
298
+ });
299
+
300
+ // backends/virtualbox/desktop.cjs
301
+ var require_desktop3 = __commonJS({
302
+ "backends/virtualbox/desktop.cjs"(exports, module) {
303
+ var path3 = __require("node:path");
304
+ var fs2 = __require("node:fs");
305
+ var { execFile: execFile2 } = __require("node:child_process");
306
+ var { promisify } = __require("node:util");
307
+ var { requireBackendHost, requireInstallHost } = require_host_support();
308
+ function createVirtualBoxAdapter(_context, { runtime, config = () => ({ get: () => void 0 }), execute = promisify(execFile2), spawn = execFile2, python = () => process.env.RPA_HOST_PYTHON || (process.platform === "win32" ? "python" : "python3"), platform = process.platform, architecture = process.arch, vboxExecutable } = {}) {
309
+ requireBackendHost("virtualbox", platform);
310
+ const executable = () => typeof vboxExecutable === "function" ? vboxExecutable() : vboxExecutable || config().get("vboxManagePath") || process.env.VBOXMANAGE_PATH || (platform === "win32" ? path3.join(process.env.ProgramFiles || "C:/Program Files", "Oracle/VirtualBox/VBoxManage.exe") : "VBoxManage");
311
+ const command = async (args) => (await execute(executable(), args, { timeout: 3e4, maxBuffer: 4 * 1024 ** 2 })).stdout;
312
+ const info = (text) => Object.fromEntries(text.split(/\r?\n/).flatMap((line) => {
313
+ const m = line.match(/^([^=]+)=(.*)$/);
314
+ return m ? [[m[1], m[2].replace(/^"|"$/g, "")]] : [];
315
+ }));
316
+ return {
317
+ command,
318
+ async list() {
319
+ const rows = (await command(["list", "vms"])).split(/\r?\n/).flatMap((line) => {
320
+ const m = line.match(/^"(.*)"\s+\{([a-f0-9-]{36})\}$/i);
321
+ return m ? [{ name: m[1], id: m[2] }] : [];
322
+ });
323
+ return (await Promise.all(rows.map(async (row) => {
324
+ try {
325
+ const details = info(await command(["showvminfo", row.id, "--machinereadable"]));
326
+ let installation;
327
+ try {
328
+ installation = JSON.parse(fs2.readFileSync(path3.join(path3.dirname(details.CfgFile), "vamp-install.json"), "utf8"));
329
+ } catch {
330
+ }
331
+ if (installation?.development_only && process.env.VAMP_SHOW_DEVELOPMENT_VMS !== "1") return null;
332
+ return {
333
+ ...row,
334
+ backend: "virtualbox",
335
+ managed: true,
336
+ state: details.VMState,
337
+ memory: details.memory,
338
+ cpus: details.cpus,
339
+ guestOS: details.ostype,
340
+ installation: installation ? { status: installation.status, verified: installation.installation_verified, mode: installation.installation_mode } : void 0
341
+ };
342
+ } catch {
343
+ return { ...row, state: "unavailable" };
344
+ }
345
+ }))).filter(Boolean);
346
+ },
347
+ async start(id) {
348
+ await command(["startvm", id, "--type", "headless"]);
349
+ const state = info(await command(["showvminfo", id, "--machinereadable"])).VMState;
350
+ if (state !== "running") throw Error("VM did not reach Running state: " + (state || "unknown"));
351
+ return { status: "running", startup_verified: true };
352
+ },
353
+ stop: (id) => command(["controlvm", id, "acpipowerbutton"]),
354
+ remove: (id) => command(["unregistervm", id, "--delete"]),
355
+ check: async () => (await command(["--version"])).trim(),
356
+ async create(request) {
357
+ requireInstallHost("virtualbox", platform, architecture);
358
+ return require_packer().packer({ runtime, python, spawn })("create", { backend: "virtualbox", ...request });
359
+ }
360
+ };
361
+ }
362
+ module.exports = { createVirtualBoxAdapter };
363
+ }
364
+ });
365
+
366
+ // backends/common/host-backends.cjs
367
+ var require_host_backends = __commonJS({
368
+ "backends/common/host-backends.cjs"(exports, module) {
369
+ var { requireBackendHost, requireInstallHost, backendCapabilities } = require_host_support();
370
+ var { domainInfo, vncEndpoint } = require_desktop();
371
+ function hostBackends(context, options) {
372
+ const platform = options.platform || process.platform;
373
+ const cache = /* @__PURE__ */ new Map();
374
+ function adapter(backend) {
375
+ requireBackendHost(backend, platform);
376
+ if (backend === "apple-hypervisor") throw Error("Apple Hypervisor adapter is not implemented");
377
+ if (!cache.has(backend)) {
378
+ if (backend === "kvm") cache.set(backend, require_desktop().createKvmAdapter(context, { ...options, platform }));
379
+ else if (backend === "hyperv") cache.set(backend, require_desktop2().createHyperVAdapter(context, { ...options, platform }));
380
+ else if (backend === "virtualbox") cache.set(backend, require_desktop3().createVirtualBoxAdapter(context, { ...options, platform }));
381
+ else throw Error("Unsupported backend");
382
+ }
383
+ const implementation = cache.get(backend);
384
+ for (const method of ["check", "list", "create", "start", "stop", "remove"]) {
385
+ if (typeof implementation[method] !== "function") throw Error(`${backend} adapter is missing ${method}`);
386
+ }
387
+ return implementation;
388
+ }
389
+ const uuid = (id) => {
390
+ if (!/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(id)) throw Error("Invalid VM identifier");
391
+ return id;
392
+ };
393
+ return {
394
+ command: async (backend, args) => adapter(backend).command(args),
395
+ capabilities: () => backendCapabilities(platform),
396
+ check: async (backend) => adapter(backend).check(),
397
+ list: async (backend) => adapter(backend).list(),
398
+ async create(backend, values) {
399
+ requireInstallHost(backend, platform, options.architecture || process.arch);
400
+ return (options.packerCall || require_packer().packer(options))("create", { backend, libvirt_uri: options.config?.().get("libvirtUri"), ...values });
401
+ },
402
+ start: async (backend, id) => adapter(backend).start(uuid(id)),
403
+ stop: async (backend, id) => adapter(backend).stop(uuid(id)),
404
+ remove: async (backend, id) => adapter(backend).remove(uuid(id)),
405
+ endpoint: async (id) => adapter("kvm").endpoint(uuid(id))
406
+ };
407
+ }
408
+ var preparePacker = (options, backend) => require_packer().packer(options)("prepare", { backend: backend === "remote" ? "virtualbox" : backend });
409
+ module.exports = { hostBackends, domainInfo, vncEndpoint, preparePacker, packer: require_packer().packer };
204
410
  }
205
411
  });
206
412
 
@@ -266,6 +472,8 @@ function describeConfig(config) {
266
472
  }
267
473
 
268
474
  // backends/remote_ssh/tools.mjs
475
+ var import_host_support = __toESM(require_host_support(), 1);
476
+ var import_packer = __toESM(require_packer(), 1);
269
477
  import fs from "node:fs/promises";
270
478
  import path2 from "node:path";
271
479
 
@@ -780,6 +988,8 @@ function parseMonitorReply(stdout) {
780
988
  function createTools({ run, config, fsx = fs, now = () => /* @__PURE__ */ new Date() }) {
781
989
  const exec = async (exe, args, { timeoutMs = 3e4, input } = {}) => {
782
990
  try {
991
+ const tool = path2.basename(exe).replace(/\.exe$/i, "");
992
+ if (["virsh", "virt-install", "qemu-img"].includes(tool)) import_host_support.default.requireBackendHost("kvm", config.platform);
783
993
  const result = await run(exe, args, { timeoutMs, input });
784
994
  return { ok: true, stdout: String(result?.stdout ?? ""), stderr: String(result?.stderr ?? "") };
785
995
  } catch (error) {
@@ -1232,7 +1442,7 @@ function createTools({ run, config, fsx = fs, now = () => /* @__PURE__ */ new Da
1232
1442
  const manager = managers.find(([, found]) => found)?.[0];
1233
1443
  const sudo = await exec("sudo", ["-n", "true"], { timeoutMs: 1e4 });
1234
1444
  const installs = {
1235
- "apt-get": ["apt-get", "install", "-y", "qemu-kvm", "libvirt-daemon-system", "libvirt-clients", "virtinst", "qemu-utils"],
1445
+ "apt-get": ["apt-get", "install", "-y", "qemu-kvm", "libvirt-daemon-system", "libvirt-clients", "virtinst", "qemu-utils", "osinfo-db", "libosinfo-bin", "ovmf", "swtpm"],
1236
1446
  dnf: ["dnf", "install", "-y", "qemu-kvm", "libvirt-daemon-config-network", "libvirt-daemon-kvm", "virt-install", "qemu-img"],
1237
1447
  yum: ["yum", "install", "-y", "qemu-kvm", "libvirt", "libvirt-client", "virt-install", "qemu-img"],
1238
1448
  zypper: ["zypper", "--non-interactive", "install", "qemu-kvm", "libvirt", "virt-install"],
@@ -1264,6 +1474,8 @@ function createTools({ run, config, fsx = fs, now = () => /* @__PURE__ */ new Da
1264
1474
  const vboxState2 = dry_run ? "planned" : version.ok ? "ok" : "needs_manual";
1265
1475
  record("vboxmanage", "VBoxManage", vboxState2, `${config.vboxManage} --version`, dry_run ? void 0 : version.ok ? { note: version.stdout.trim() } : { fix: "Install VirtualBox on the remote host (https://www.virtualbox.org/wiki/Downloads), then set remoteVboxManage if it is not on PATH." });
1266
1476
  }
1477
+ const packerScript = path2.join(config.repo || config.workdir, "backends/packer/runner.py");
1478
+ await runStep("packer", "Install HashiCorp Packer CLI and official hypervisor plugin", [config.python || "python3", packerScript, "prepare", "--backend", config.backend], 6e5);
1267
1479
  const failed = steps.filter((step) => step.status === "failed");
1268
1480
  const manual = steps.filter((step) => step.status === "needs_manual");
1269
1481
  return {
@@ -1275,8 +1487,7 @@ function createTools({ run, config, fsx = fs, now = () => /* @__PURE__ */ new Da
1275
1487
  };
1276
1488
  }
1277
1489
  async function createVm(args = {}) {
1278
- if (config.backend !== "kvm") throw new Error("VM creation through this host server is KVM-only. Use the VirtualBox vm_create tool for VirtualBox.");
1279
- if (config.platform !== "linux") throw new Error("KVM creation requires a Linux host.");
1490
+ import_host_support.default.requireBackendHost(config.backend, config.platform);
1280
1491
  if (args.confirmed !== true) return { status: "needs_confirmation", vm_created: false, message: "Authorize creation and startup, then pass confirmed:true with a host ISO path." };
1281
1492
  const guest_os = args.guest_os ?? "debian";
1282
1493
  if (!["debian", "ubuntu", "windows11"].includes(guest_os)) throw new Error("Unsupported guest_os");
@@ -1290,20 +1501,26 @@ function createTools({ run, config, fsx = fs, now = () => /* @__PURE__ */ new Da
1290
1501
  const lifecycle = (await Promise.resolve().then(() => __toESM(require_host_backends(), 1))).default;
1291
1502
  const adapter = lifecycle.hostBackends({ globalStorageUri: { fsPath: config.workdir } }, {
1292
1503
  runtime: config.repo || config.workdir,
1504
+ python: () => config.python || (process.platform === "win32" ? "python" : "python3"),
1505
+ platform: config.platform,
1293
1506
  config: () => ({ get: (key) => key === "libvirtUri" ? config.libvirtUri : key === "kvmPythonExecutable" ? config.python : void 0 }),
1294
1507
  execute: (exe, argv, options) => run(exe, argv, { timeoutMs: options.timeout })
1295
1508
  });
1296
- const created = await adapter.create("kvm", { name: args.name, iso_path: args.iso_path, guest_os, installation_mode: args.installation_mode, ...values });
1509
+ const created = await adapter.create(config.backend, { name: args.name, iso_path: args.iso_path, guest_os, installation_mode: args.installation_mode, windows_confirmed: args.windows_confirmed, ...values });
1297
1510
  return {
1298
1511
  ...created,
1299
- backend: "kvm",
1512
+ backend: config.backend,
1300
1513
  guest_os,
1301
1514
  os_installation_completed: false,
1302
1515
  guest_setup_completed: false,
1303
- next_action: created.installation_mode === "unattended" ? "Debian unattended installation started; verify the guest desktop before declaring completion. Public sandbox login: vboxuser / password123!." : "Complete the OS installer in the guest console. VM startup is not installation completion."
1516
+ next_action: "Packer build queued. Use remote_golden_images for completion status, file paths, sizes and logs. Public sandbox autologin: vboxuser / password123!."
1304
1517
  };
1305
1518
  }
1519
+ const packer = import_packer.default.packer({ runtime: config.repo || config.workdir, python: () => config.python || (process.platform === "win32" ? "python" : "python3") });
1306
1520
  const tools = [
1521
+ { name: "remote_packer_prepare", description: "Download the managed Packer CLI and selected official plugin on this host; creates no VM.", inputSchema: { type: "object", properties: {}, additionalProperties: false }, handler: () => packer("prepare", { backend: config.backend }) },
1522
+ { name: "remote_golden_images", description: "List golden image build status, absolute paths and byte sizes on this host.", inputSchema: { type: "object", properties: {}, additionalProperties: false }, handler: () => packer("images") },
1523
+ { name: "remote_golden_image_delete", description: "Delete a VAMP golden image by ID. Without confirmed returns path/size; get explicit user approval before confirmed:true. Live VM disks are separate.", inputSchema: { type: "object", properties: { id: { type: "string", pattern: "^[a-f0-9]{32}$" }, confirmed: { type: "boolean", default: false } }, required: ["id"], additionalProperties: false }, handler: (args) => packer("delete-image", args) },
1307
1524
  {
1308
1525
  name: "remote_env_check",
1309
1526
  title: "Check the remote host environment",
@@ -1328,13 +1545,13 @@ function createTools({ run, config, fsx = fs, now = () => /* @__PURE__ */ new Da
1328
1545
  },
1329
1546
  {
1330
1547
  name: "remote_vm_create",
1331
- title: "Create a KVM VM from a host ISO",
1332
- description: "KVM only: create and start a new VM using the same provisioner as the VS Code manager. Requires confirmed:true. Debian default; Windows additionally requires windows_confirmed:true and your own license. Debian amd64 installer ISOs default to automatic installation using public sandbox credentials vboxuser/password123!. Ubuntu/Windows are manual; use installation_mode:manual to opt out.",
1548
+ title: "Create a VM with HashiCorp Packer",
1549
+ description: "Create and deploy a new VM with the selected hypervisor through the same Packer runner as VS Code. Requires confirmed:true. HashiCorp Packer installs Debian/Windows and post-install scripts, waits 60s after reboot, exports a golden image and deploys a separate live disk. Windows requires windows_confirmed:true and your own license. Public sandbox autologin vboxuser/password123!.",
1333
1550
  inputSchema: { type: "object", properties: {
1334
1551
  name: { type: "string", pattern: "^[A-Za-z][A-Za-z0-9_-]{0,62}$" },
1335
1552
  iso_path: { type: "string", description: "Absolute ISO path on the host running this server" },
1336
- guest_os: { type: "string", enum: ["debian", "ubuntu", "windows11"], default: "debian" },
1337
- installation_mode: { type: "string", enum: ["manual", "unattended"] },
1553
+ guest_os: { type: "string", enum: ["debian", "windows11"], default: "debian" },
1554
+ installation_mode: { type: "string", enum: ["auto", "unattended"] },
1338
1555
  memory_mb: { type: "integer", minimum: 2048, maximum: 131072 },
1339
1556
  cpus: { type: "integer", minimum: 1, maximum: 64 },
1340
1557
  disk_mb: { type: "integer", minimum: 32768, maximum: 2097152 },
@@ -0,0 +1,37 @@
1
+ // Cross-platform VirtualBox adapter. Guest provisioning stays in shared Python.
2
+ const path=require('node:path');
3
+ const fs=require('node:fs');
4
+ const {execFile}=require('node:child_process');
5
+ const {promisify}=require('node:util');
6
+ const {requireBackendHost,requireInstallHost}=require('../common/host-support.cjs');
7
+ /** @returns {import('../common/desktop-interface').DesktopAdapter} */
8
+ function createVirtualBoxAdapter(_context,{runtime,config=()=>({get:()=>undefined}),execute=promisify(execFile),spawn=execFile,python=()=>process.env.RPA_HOST_PYTHON||(process.platform==='win32'?'python':'python3'),platform=process.platform,architecture=process.arch,vboxExecutable}={}){
9
+ requireBackendHost('virtualbox',platform);
10
+ const executable=()=>typeof vboxExecutable==='function'?vboxExecutable():vboxExecutable||config().get('vboxManagePath')||process.env.VBOXMANAGE_PATH||(platform==='win32'?path.join(process.env.ProgramFiles||'C:/Program Files','Oracle/VirtualBox/VBoxManage.exe'):'VBoxManage');
11
+ const command=async args=>(await execute(executable(),args,{timeout:30000,maxBuffer:4*1024**2})).stdout;
12
+ const info=text=>Object.fromEntries(text.split(/\r?\n/).flatMap(line=>{const m=line.match(/^([^=]+)=(.*)$/);return m?[[m[1],m[2].replace(/^"|"$/g,'')]]:[];}));
13
+ return {command,
14
+ async list(){
15
+ const rows=(await command(['list','vms'])).split(/\r?\n/).flatMap(line=>{const m=line.match(/^"(.*)"\s+\{([a-f0-9-]{36})\}$/i);return m?[{name:m[1],id:m[2]}]:[];});
16
+ return (await Promise.all(rows.map(async row=>{
17
+ try{
18
+ const details=info(await command(['showvminfo',row.id,'--machinereadable']));
19
+ let installation;
20
+ try{installation=JSON.parse(fs.readFileSync(path.join(path.dirname(details.CfgFile),'vamp-install.json'),'utf8'));}catch{}
21
+ if(installation?.development_only && process.env.VAMP_SHOW_DEVELOPMENT_VMS!=='1')return null;
22
+ return {...row,backend:'virtualbox',managed:true,state:details.VMState,memory:details.memory,cpus:details.cpus,guestOS:details.ostype,
23
+ installation:installation?{status:installation.status,verified:installation.installation_verified,mode:installation.installation_mode}:undefined};
24
+ }catch{return {...row,state:'unavailable'};}
25
+ }))).filter(Boolean);
26
+ },
27
+ async start(id){await command(['startvm',id,'--type','headless']);const state=info(await command(['showvminfo',id,'--machinereadable'])).VMState;if(state!=='running')throw Error('VM did not reach Running state: '+(state||'unknown'));return {status:'running',startup_verified:true};},
28
+ stop:id=>command(['controlvm',id,'acpipowerbutton']),
29
+ remove:id=>command(['unregistervm',id,'--delete']),
30
+ check:async()=>(await command(['--version'])).trim(),
31
+ async create(request){
32
+ requireInstallHost('virtualbox',platform,architecture);
33
+ return require('../common/packer.cjs').packer({runtime,python,spawn})('create',{backend:'virtualbox',...request});
34
+ },
35
+ };
36
+ }
37
+ module.exports={createVirtualBoxAdapter};