vamp-mcp 0.2.0 → 0.2.3

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 (133) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +142 -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 +66 -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/setup-user.py +53 -53
  75. package/runtime/guest_setup/recorder/setup-win.cmd +4 -60
  76. package/runtime/guest_setup/recorder/setup.ps1 +108 -81
  77. package/runtime/guest_setup/recorder/setup.sh +1 -0
  78. package/runtime/guest_setup/recorder/vamp-recorder.py +148 -148
  79. package/runtime/guest_setup/recorder/verify-recorder.py +4 -4
  80. package/runtime/guest_setup/recorder/windows-display.py +76 -76
  81. package/runtime/guest_setup/requirements.txt +2 -2
  82. package/runtime/guest_setup/setup-all.ps1 +35 -35
  83. package/runtime/guest_setup/vault/Install-VCRuntime.ps1 +26 -26
  84. package/runtime/guest_setup/vault/setup-guest-vault.ps1 +148 -148
  85. package/runtime/recording_converter.py +230 -230
  86. package/runtime/requirements-mcp.txt +11 -11
  87. package/runtime/rpas/README.md +161 -161
  88. package/runtime/rpas/captcha_handoff/manifest.json +27 -27
  89. package/runtime/rpas/captcha_handoff/run.robot +16 -16
  90. package/runtime/rpas/captcha_handoff/workflow.py +11 -11
  91. package/runtime/rpas/common.resource +26 -26
  92. package/runtime/rpas/debian_update/manifest.json +27 -27
  93. package/runtime/rpas/debian_update/run.robot +17 -17
  94. package/runtime/rpas/debian_update/workflow.py +13 -13
  95. package/runtime/rpas/desktop_control/manifest.json +26 -26
  96. package/runtime/rpas/desktop_control/run.robot +27 -27
  97. package/runtime/rpas/desktop_control/workflow.py +51 -51
  98. package/runtime/rpas/firefox_launch/manifest.json +27 -27
  99. package/runtime/rpas/firefox_launch/run.robot +15 -15
  100. package/runtime/rpas/firefox_launch/workflow.py +25 -25
  101. package/runtime/rpas/firefox_naver/manifest.json +27 -27
  102. package/runtime/rpas/firefox_naver/run.robot +21 -21
  103. package/runtime/rpas/firefox_naver/workflow.py +28 -28
  104. package/runtime/rpas/kvm_validation/README.md +11 -11
  105. package/runtime/rpas/kvm_validation/manifest.json +28 -28
  106. package/runtime/rpas/kvm_validation/run.robot +30 -30
  107. package/runtime/rpas/kvm_validation/workflow.py +91 -91
  108. package/runtime/rpas/manifest.schema.json +105 -105
  109. package/runtime/rpas/naver_login/login.robot +25 -25
  110. package/runtime/rpas/naver_login/manifest.json +33 -33
  111. package/runtime/rpas/naver_login/run.robot +20 -20
  112. package/runtime/rpas/naver_login/workflow.py +32 -32
  113. package/runtime/rpas/windows_naver_recorded/README.md +24 -24
  114. package/runtime/rpas/windows_naver_recorded/conversion.json +25 -25
  115. package/runtime/rpas/windows_naver_recorded/manifest.json +28 -28
  116. package/runtime/rpas/windows_naver_recorded/run.robot +37 -37
  117. package/runtime/rpas/windows_naver_recorded/workflow.py +32 -32
  118. package/runtime/scripts/build_recorder_media.py +39 -39
  119. package/runtime/scripts/macos/setup-host.sh +0 -0
  120. package/runtime/scripts/script_server.py +571 -517
  121. package/runtime/skills/vamp-rpa-ui-checks/SKILL.md +26 -0
  122. package/runtime/skills/vamp-rpa-ui-checks/agents/openai.yaml +4 -0
  123. package/runtime/skills/vamp-rpa-ui-checks/references/display.md +12 -0
  124. package/runtime/skills/vamp-rpa-ui-checks/references/user-guide.md +49 -0
  125. package/runtime/skills/vamp-ui-cleanup/SKILL.md +15 -0
  126. package/runtime/skills/vamp-ui-cleanup/agents/openai.yaml +4 -0
  127. package/runtime/skills/vamp-ui-validation/SKILL.md +27 -0
  128. package/runtime/skills/vamp-ui-validation/agents/openai.yaml +4 -0
  129. package/runtime/third_party/mcp-virtualbox/scripts/mouse_click.py +65 -65
  130. package/runtime/third_party/pyautogui-recorder/LICENSE +674 -674
  131. package/runtime/third_party/pyautogui-recorder/PROVENANCE.json +16 -16
  132. package/runtime/third_party/pyautogui-recorder/PyAutoGuiRecorder.py +169 -169
  133. package/runtime/third_party/pyautogui-recorder/README.md +53 -53
@@ -1,46 +1,46 @@
1
- {
2
- "schema_version": 1,
3
- "observed_at": "2026-11-15",
4
- "source": "Read-only VirtualBox showvminfo/showmediuminfo on current running user VMs, 2026-11-15. Capacity is virtual disk capacity, not allocated host space.",
5
- "profiles": {
6
- "windows11": {
7
- "memory_mb": 4096,
8
- "cpus": 2,
9
- "disk_mb": 256000,
10
- "firmware": "efi",
11
- "disk_allocation": "dynamic",
12
- "native_resolution": [
13
- 1920,
14
- 1080
15
- ],
16
- "reference_guest": "Win-RPA",
17
- "windows_license_required": true
18
- },
19
- "debian": {
20
- "memory_mb": 2048,
21
- "cpus": 2,
22
- "disk_mb": 256000,
23
- "firmware": "bios",
24
- "disk_allocation": "dynamic",
25
- "native_resolution": [
26
- 1920,
27
- 1080
28
- ],
29
- "reference_guest": "Debian-RPA",
30
- "windows_license_required": false
31
- },
32
- "ubuntu": {
33
- "memory_mb": 2048,
34
- "cpus": 2,
35
- "disk_mb": 256000,
36
- "firmware": "bios",
37
- "disk_allocation": "dynamic",
38
- "native_resolution": [
39
- 1920,
40
- 1080
41
- ],
42
- "reference_guest": "Debian-RPA resources only; Ubuntu guest not observed",
43
- "windows_license_required": false
44
- }
45
- }
46
- }
1
+ {
2
+ "schema_version": 1,
3
+ "observed_at": "2026-11-15",
4
+ "source": "Read-only VirtualBox showvminfo/showmediuminfo on current running user VMs, 2026-11-15. Capacity is virtual disk capacity, not allocated host space.",
5
+ "profiles": {
6
+ "windows11": {
7
+ "memory_mb": 4096,
8
+ "cpus": 2,
9
+ "disk_mb": 256000,
10
+ "firmware": "efi",
11
+ "disk_allocation": "dynamic",
12
+ "native_resolution": [
13
+ 1920,
14
+ 1080
15
+ ],
16
+ "reference_guest": "Win-RPA",
17
+ "windows_license_required": true
18
+ },
19
+ "debian": {
20
+ "memory_mb": 2048,
21
+ "cpus": 2,
22
+ "disk_mb": 256000,
23
+ "firmware": "bios",
24
+ "disk_allocation": "dynamic",
25
+ "native_resolution": [
26
+ 1920,
27
+ 1080
28
+ ],
29
+ "reference_guest": "Debian-RPA",
30
+ "windows_license_required": false
31
+ },
32
+ "ubuntu": {
33
+ "memory_mb": 2048,
34
+ "cpus": 2,
35
+ "disk_mb": 256000,
36
+ "firmware": "bios",
37
+ "disk_allocation": "dynamic",
38
+ "native_resolution": [
39
+ 1920,
40
+ 1080
41
+ ],
42
+ "reference_guest": "Debian-RPA resources only; Ubuntu guest not observed",
43
+ "windows_license_required": false
44
+ }
45
+ }
46
+ }
@@ -1,197 +1,238 @@
1
- """Deterministic VirtualBox unattended provisioning; no AI loop required."""
2
- from __future__ import annotations
3
- import argparse
4
- import json
5
- import os
6
- from pathlib import Path
7
- import re
8
- import shutil
9
- import subprocess
10
- import sys
11
- import time
12
- import uuid
13
-
14
- ROOT=Path(__file__).resolve().parents[2]
15
- sys.path.insert(0,str(ROOT/'scripts'))
16
- sys.path.insert(0,str(Path(__file__).resolve().parent))
17
- from script_server import SCRIPT_SERVER_PORT, guest_commands, start as start_script_server
18
-
19
- PUBLIC_CREDENTIALS={'username':'vboxuser','password':'password123!','public_sandbox_credentials':True}
20
-
21
-
22
- def parse(text):
23
- return {m[1].strip():m[2].strip() for line in text.splitlines()
24
- if (m:=re.match(r'([^=]+)=\"?(.*?)\"?$',line.strip()))}
25
-
26
-
27
- def executable():
28
- if os.environ.get('VBOXMANAGE_PATH'): return os.environ['VBOXMANAGE_PATH']
29
- if sys.platform=='win32':
30
- candidate=Path(os.environ.get('PROGRAMFILES','C:/Program Files'))/'Oracle/VirtualBox/VBoxManage.exe'
31
- if candidate.is_file():return str(candidate)
32
- return shutil.which('VBoxManage') or 'VBoxManage'
33
-
34
-
35
- def assert_no_active_kvm():
36
- if not sys.platform.startswith('linux'):return
37
- for uri in ('qemu:///session','qemu:///system'):
38
- try:
39
- result=subprocess.run(['virsh','-c',uri,'list','--name'],capture_output=True,text=True,timeout=10)
40
- except (FileNotFoundError,subprocess.TimeoutExpired):continue
41
- if result.returncode==0 and result.stdout.strip():
42
- raise RuntimeError('A KVM VM is active. Shut it down before starting VirtualBox; simultaneous execution can cause VERR_SVM_IN_USE.')
43
-
44
-
45
- def post_install_command(guest_os, base_url):
46
- """Post-install hook fetched from the host script server; no ISO is rewritten or mounted."""
47
- if guest_os=='windows11':
48
- return f'powershell -ExecutionPolicy Bypass -Command "irm {base_url}/postwin.ps1 | iex"'
49
- return f'wget -qO /tmp/vamp-postdeb.sh {base_url}/postdeb.sh && sh /tmp/vamp-postdeb.sh'
50
-
51
-
52
- def create(iso_path,name=None,memory_mb=None,cpus=None,disk_mb=None,basedir=None,image_index=1,product_key='',windows_confirmed=False,guest_os=None,preflight_only=False,allow_manual_install=False,installation_mode="auto",serve_scripts=True,script_server_ttl=3600):
53
- if installation_mode not in ('auto','manual'):raise ValueError('installation_mode must be auto or manual')
54
- name=name or ('VAMP-'+uuid.uuid4().hex[:8])
55
- if not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_-]{0,63}',name):raise ValueError('Use 1-64 letters/digits/underscore/hyphen for name')
56
- iso=Path(iso_path).expanduser().resolve(strict=True)
57
- if not iso.is_file():raise ValueError('ISO path must be a readable local file on the VM host')
58
- journal={'status':'preparing','vm':name,'credentials':PUBLIC_CREDENTIALS,'events':[],
59
- 'installation_verified':False,'recorder_installed_verified':False,
60
- 'guest_setup_transport':f'http://10.0.2.2:{SCRIPT_SERVER_PORT} (host Python script server)'}
61
- folder=Path(basedir or Path.home()/'VirtualBox VMs').expanduser().resolve()/name
62
- def run(*args,timeout=120):
63
- proc=subprocess.run([executable(),*map(str,args)],capture_output=True,text=True,timeout=timeout)
64
- if proc.returncode:raise RuntimeError(f'VBoxManage {args[0]} failed: {proc.stderr.strip()[:500]}')
65
- return proc.stdout
66
- listed=run('list','vms')
67
- if any(line.startswith('"'+name+'" ') for line in listed.splitlines()):raise ValueError('VM name already exists; refusing to modify it')
68
- try:
69
- detected=parse(run('unattended','detect','--iso',iso,'--machine-readable'))
70
- except RuntimeError:
71
- manual_types={'debian':'Debian_64','ubuntu':'Ubuntu_64','windows11':'Windows11_64'}
72
- if not allow_manual_install or guest_os not in manual_types:raise
73
- detected={'OSTypeId':manual_types[guest_os],'IsInstallSupported':'false'}
74
- os_type=detected.get('OSTypeId',detected.get('detectedOSTypeId',''))
75
- if not (re.fullmatch(r'Debian[0-9]*_64',os_type) or re.fullmatch(r'Ubuntu[0-9]*_64',os_type) or os_type=='Windows11_64'):
76
- raise ValueError(f'Only detected Debian/Ubuntu amd64 or Windows11 x64 ISO supported by this initial profile: {os_type or "unknown"}')
77
- unattended_supported=detected.get('IsInstallSupported',detected.get('isInstallSupported','true')).lower() in ('true','1','yes','on')
78
- if installation_mode=='manual':unattended_supported=False
79
- if not unattended_supported and not allow_manual_install:
80
- raise ValueError('VirtualBox reports this ISO does not support unattended installation')
81
- selected='windows11' if os_type=='Windows11_64' else ('ubuntu' if os_type.startswith('Ubuntu') else 'debian')
82
- if guest_os and guest_os!=selected:raise ValueError('Selected guest OS does not match detected ISO')
83
- profile=json.loads(Path(__file__).with_name('profiles.json').read_text())['profiles'][selected]
84
- memory_mb=memory_mb if memory_mb is not None else profile['memory_mb']
85
- cpus=cpus if cpus is not None else profile['cpus']
86
- disk_mb=disk_mb if disk_mb is not None else profile['disk_mb']
87
- if not (2048<=memory_mb<=131072 and 1<=cpus<=64 and 32768<=disk_mb<=2097152 and image_index>=1):
88
- raise ValueError('Invalid VM resource/image limits')
89
- if preflight_only:
90
- return {'status':'preflight_ready','vm_created':False,'guest_os':selected,
91
- 'resource_profile':{'memory_mb':memory_mb,'cpus':cpus,'disk_mb':disk_mb},
92
- 'windows_confirmation_required':selected=='windows11' and not windows_confirmed,
93
- 'installation_mode':'unattended' if unattended_supported else 'manual',
94
- 'guest_setup':{'transport':'http','port':SCRIPT_SERVER_PORT,'commands':guest_commands(SCRIPT_SERVER_PORT)},
95
- 'credentials':PUBLIC_CREDENTIALS,'iso':str(iso)}
96
- if selected=='windows11' and not windows_confirmed:
97
- return {'status':'needs_windows_confirmation','no_vm_created':True,'profile':profile,
98
- 'action_required':'Ask the user whether to create Windows with these specs. Windows requires a valid license; activate it yourself after installation in Settings > System > Activation. VAMP does not include a Windows license.',
99
- 'credentials':PUBLIC_CREDENTIALS}
100
- journal['resource_profile']={'guest_os':selected,'memory_mb':memory_mb,'cpus':cpus,'disk_mb':disk_mb,
101
- 'native_resolution':[1920,1080]}
102
- if selected=='windows11':journal['license_notice']='Windows requires a valid license. Activate Windows yourself after installation; VAMP supplies no license or activation bypass.'
103
- if os_type=='Windows11_64' and memory_mb<4096:raise ValueError('Windows 11 requires at least 4096 MB')
104
- # Check version-specific password option before creating any VM.
105
- help_text=''
106
- if unattended_supported:
107
- help_proc=subprocess.run([executable(),'unattended','install','--help'],capture_output=True,text=True)
108
- help_text=help_proc.stdout+help_proc.stderr
109
- password_flag='--user-password' if '--user-password' in help_text else '--password'
110
- assert_no_active_kvm()
111
- folder.mkdir(parents=True,exist_ok=False)
112
- journal_path=folder/'vamp-install.json'
113
- def start_verified():
114
- # startvm waits for its session to open; still verify the hypervisor state.
115
- run('startvm',name,'--type','headless')
116
- state=''
117
- for attempt in range(15):
118
- state=parse(run('showvminfo',name,'--machinereadable')).get('VMState','unknown')
119
- if state=='running':
120
- journal.update(vm_state=state,startup_verified=True)
121
- return
122
- if state not in ('starting','restoring'):break
123
- time.sleep(1)
124
- raise RuntimeError(f'VM creation completed but startup was not verified (state: {state}); inspect the VM log')
125
- def record(stage):
126
- journal['events'].append(stage)
127
- journal_path.write_text(json.dumps(journal,indent=2)+'\n')
128
- script_server=None
129
- if serve_scripts and not os.environ.get('VAMP_SCRIPT_SERVER_DISABLE'):
130
- try:
131
- script_server=start_script_server(port=SCRIPT_SERVER_PORT,ttl=script_server_ttl)
132
- except Exception as exc:
133
- script_server={'status':'failed','port':SCRIPT_SERVER_PORT,'error':str(exc)}
134
- journal['script_server']=script_server
135
- if script_server.get('status')!='running':
136
- journal['script_server_warning']=('Guest setup scripts are not being served. Start them with '
137
- f'"python3 scripts/script_server.py start" before the guest runs its post-install step ({script_server.get("error","unknown error")}).')
138
- base_url=(script_server or {}).get('guest_urls',{}).get('virtualbox_nat') or f'http://10.0.2.2:{SCRIPT_SERVER_PORT}'
139
- try:
140
- run('createvm','--name',name,'--ostype',os_type,'--register','--basefolder',folder.parent)
141
- record('vm-created')
142
- from display import preferences
143
- journal['display']=preferences(name,run)
144
- from shares import prepare
145
- journal['recording_share']=prepare(name,run)
146
- options=['modifyvm',name,'--memory',memory_mb,'--cpus',cpus,'--vram',128,
147
- '--mouse','usbtablet','--nic1','nat','--boot1','dvd','--boot2','disk',
148
- '--graphicscontroller','vboxsvga' if os_type=='Windows11_64' else 'vmsvga']
149
- if os_type=='Windows11_64':options+=['--firmware','efi','--tpm-type','2.0','--ioapic','on']
150
- run(*options)
151
- disk=folder/(name+'.vdi')
152
- run('createmedium','disk','--filename',disk,'--size',disk_mb,'--format','VDI')
153
- run('storagectl',name,'--name','SATA','--add','sata','--controller','IntelAhci','--portcount','4')
154
- run('storageattach',name,'--storagectl','SATA','--port','0','--device','0','--type','hdd','--medium',disk)
155
- run('storagectl',name,'--name','IDE','--add','ide')
156
- if not unattended_supported:
157
- run('storageattach',name,'--storagectl','SATA','--port','1','--device','0','--type','dvddrive','--medium',iso)
158
- start_verified()
159
- journal.update(status='installation_started',installation_mode='manual',os_type=os_type,
160
- frontend='headless',journal=str(journal_path),
161
- credentials={'public_sandbox_credentials':False,'account_setup':'Choose your account in the OS installer'},
162
- action_required=(f'This ISO needs a manual installation: complete the stock installer in the VM screen, '
163
- f'choose your own guest account, then run the guest setup command from '
164
- f'http://10.0.2.2:{SCRIPT_SERVER_PORT}/ (for example '
165
- f'"wget -qO- {base_url}/setup.sh | sh"). No ISO was rewritten and no automatic account or recorder setup ran.'))
166
- record('manual-installation-started')
167
- return journal
168
- if os_type=='Windows11_64':
169
- from display import insert_additions
170
- journal['guest_additions']=insert_additions(name,run=run)
171
- install_args=['unattended','install',name,'--iso',iso,'--user','vboxuser',password_flag,'password123!',
172
- '--full-user-name','VAMP Sandbox User','--hostname',name.lower()+'.vamp.local',
173
- '--no-install-additions','--post-install-command',post_install_command(selected,base_url)]
174
- if os_type=='Windows11_64':
175
- install_args+=['--image-index',image_index]
176
- if product_key:install_args+=['--key',product_key]
177
- run(*install_args,timeout=300)
178
- start_verified()
179
- journal.update(status='installation_started',installation_mode='unattended',os_type=os_type,frontend='headless',
180
- recorder_setup=f'First login downloads the setup bundle from the host script server on port {SCRIPT_SERVER_PORT}',
181
- guest_setup_command=f'wget -qO- {base_url}/setup.sh | sh' if selected!='windows11' else f'irm {base_url}/setup.ps1 | iex',
182
- requires_ai_loop=False,journal=str(journal_path))
183
- record('unattended-installation-started')
184
- return journal
185
- except Exception as exc:
186
- journal.update(status='failed',error=str(exc),partial_vm_preserved=True)
187
- record('failed')
188
- raise RuntimeError(f'{exc}; partial setup preserved at {folder}') from exc
189
-
190
-
191
- if __name__=='__main__':
192
- parser=argparse.ArgumentParser(description=__doc__)
193
- parser.add_argument('--json-stdin',action='store_true',required=True)
194
- parser.parse_args()
195
- try: print(json.dumps(create(**json.load(sys.stdin))))
196
- except Exception as exc:
197
- print(json.dumps({'status':'failed','error':str(exc)}));sys.exit(1)
1
+ """Deterministic VirtualBox unattended provisioning; no AI loop required."""
2
+ from __future__ import annotations
3
+ import argparse
4
+ import base64
5
+ import json
6
+ import os
7
+ from pathlib import Path
8
+ import re
9
+ import shutil
10
+ import subprocess
11
+ import sys
12
+ import time
13
+ import uuid
14
+
15
+ ROOT=Path(__file__).resolve().parents[2]
16
+ sys.path.insert(0,str(ROOT/'scripts'))
17
+ sys.path.insert(0,str(ROOT/'backends/common'))
18
+ from guest_install import PROFILE, require_install_host, efi_boot_plan, virtualbox_preseed, post_create_notice
19
+ sys.path.insert(0,str(Path(__file__).resolve().parent))
20
+ from script_server import SCRIPT_SERVER_PORT, guest_commands, start as start_script_server
21
+
22
+ PUBLIC_CREDENTIALS={'username':'vboxuser','password':'password123!','public_sandbox_credentials':True}
23
+
24
+
25
+ def parse(text):
26
+ return {m[1].strip():m[2].strip() for line in text.splitlines()
27
+ if (m:=re.match(r'([^=]+)=\"?(.*?)\"?$',line.strip()))}
28
+
29
+
30
+ def executable():
31
+ if os.environ.get('VBOXMANAGE_PATH'): return os.environ['VBOXMANAGE_PATH']
32
+ if sys.platform=='win32':
33
+ candidate=Path(os.environ.get('PROGRAMFILES','C:/Program Files'))/'Oracle/VirtualBox/VBoxManage.exe'
34
+ if candidate.is_file():return str(candidate)
35
+ return shutil.which('VBoxManage') or 'VBoxManage'
36
+
37
+
38
+ def assert_no_active_kvm():
39
+ if not sys.platform.startswith('linux'):return
40
+ for uri in ('qemu:///session','qemu:///system'):
41
+ try:
42
+ result=subprocess.run(['virsh','-c',uri,'list','--name'],capture_output=True,text=True,timeout=10)
43
+ except (FileNotFoundError,subprocess.TimeoutExpired):continue
44
+ if result.returncode==0 and result.stdout.strip():
45
+ raise RuntimeError('A KVM VM is active. Shut it down before starting VirtualBox; simultaneous execution can cause VERR_SVM_IN_USE.')
46
+
47
+
48
+ def post_install_command(guest_os, base_url):
49
+ """Post-install hook fetched from the host script server; no ISO is rewritten or mounted."""
50
+ if guest_os=='windows11':
51
+ command=("$ErrorActionPreference='Stop'; $p=Join-Path $env:TEMP 'vamp-postwin.ps1'; "
52
+ "for($i=0;$i -lt 30;$i++){try{"
53
+ f"Invoke-WebRequest -UseBasicParsing -Uri '{base_url}/postwin.ps1' -OutFile $p -TimeoutSec 20; break"
54
+ "}catch{if($i -eq 29){throw}; Start-Sleep -Seconds 3}}; & $p")
55
+ # VBox's VBOXPOST.CMD also echoes this command inside double quotes.
56
+ # A nested -Command string exposes its pipe/operators to cmd.exe there.
57
+ encoded=base64.b64encode(command.encode('utf-16-le')).decode('ascii')
58
+ return f'powershell.exe -NoProfile -ExecutionPolicy Bypass -EncodedCommand {encoded}'
59
+ return f'wget -qO /tmp/vamp-postdeb.sh {base_url}/postdeb.sh && sh /tmp/vamp-postdeb.sh'
60
+
61
+
62
+ def create(iso_path,name=None,memory_mb=None,cpus=None,disk_mb=None,basedir=None,image_index=1,product_key='',windows_confirmed=False,guest_os=None,preflight_only=False,allow_manual_install=False,installation_mode="auto",serve_scripts=True,script_server_ttl=7200):
63
+ require_install_host('virtualbox')
64
+ if installation_mode not in ('auto','manual'):raise ValueError('installation_mode must be auto or manual')
65
+ name=name or ('VAMP-'+uuid.uuid4().hex[:8])
66
+ if not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_-]{0,63}',name):raise ValueError('Use 1-64 letters/digits/underscore/hyphen for name')
67
+ iso=Path(iso_path).expanduser().resolve(strict=True)
68
+ if not iso.is_file():raise ValueError('ISO path must be a readable local file on the VM host')
69
+ journal={'status':'preparing','vm':name,'credentials':PUBLIC_CREDENTIALS,'events':[],
70
+ 'installation_verified':False,'recorder_installed_verified':False,
71
+ 'development_only':os.environ.get('VAMP_DEVELOPMENT_VM')=='1',
72
+ 'guest_setup_transport':f'http://10.0.2.2:{SCRIPT_SERVER_PORT} (host Python script server)'}
73
+ folder=Path(basedir or Path.home()/'VirtualBox VMs').expanduser().resolve()/name
74
+ def run(*args,timeout=120):
75
+ proc=subprocess.run([executable(),*map(str,args)],capture_output=True,text=True,timeout=timeout)
76
+ if proc.returncode:raise RuntimeError(f'VBoxManage {args[0]} failed: {proc.stderr.strip()[:500]}')
77
+ return proc.stdout
78
+ listed=run('list','vms')
79
+ if any(line.startswith('"'+name+'" ') for line in listed.splitlines()):raise ValueError('VM name already exists; refusing to modify it')
80
+ try:
81
+ detected=parse(run('unattended','detect','--iso',iso,'--machine-readable'))
82
+ except RuntimeError:
83
+ manual_types={'debian':'Debian_64','ubuntu':'Ubuntu_64','windows11':'Windows11_64'}
84
+ if guest_os not in manual_types or not (allow_manual_install or (guest_os=='debian' and installation_mode=='auto')):raise
85
+ detected={'OSTypeId':manual_types[guest_os],'IsInstallSupported':'false'}
86
+ os_type=detected.get('OSTypeId',detected.get('detectedOSTypeId',''))
87
+ if not (re.fullmatch(r'Debian[0-9]*_64',os_type) or re.fullmatch(r'Ubuntu[0-9]*_64',os_type) or os_type=='Windows11_64'):
88
+ raise ValueError(f'Only detected Debian/Ubuntu amd64 or Windows11 x64 ISO supported by this initial profile: {os_type or "unknown"}')
89
+ unattended_supported=detected.get('IsInstallSupported',detected.get('isInstallSupported','true')).lower() in ('true','1','yes','on')
90
+ if installation_mode=='manual':unattended_supported=False
91
+ direct_debian_boot=(installation_mode=='auto' and guest_os=='debian' and not unattended_supported)
92
+ if not unattended_supported and not allow_manual_install and not direct_debian_boot:
93
+ raise ValueError('VirtualBox reports this ISO does not support unattended installation')
94
+ selected='windows11' if os_type=='Windows11_64' else ('ubuntu' if os_type.startswith('Ubuntu') else 'debian')
95
+ if guest_os and guest_os!=selected:raise ValueError('Selected guest OS does not match detected ISO')
96
+ profile=json.loads(Path(__file__).with_name('profiles.json').read_text())['profiles'][selected]
97
+ memory_mb=memory_mb if memory_mb is not None else profile['memory_mb']
98
+ cpus=cpus if cpus is not None else profile['cpus']
99
+ disk_mb=disk_mb if disk_mb is not None else profile['disk_mb']
100
+ if not (2048<=memory_mb<=131072 and 1<=cpus<=64 and 32768<=disk_mb<=2097152 and image_index>=1):
101
+ raise ValueError('Invalid VM resource/image limits')
102
+ if preflight_only:
103
+ return {'status':'preflight_ready','vm_created':False,'guest_os':selected,
104
+ 'resource_profile':{'memory_mb':memory_mb,'cpus':cpus,'disk_mb':disk_mb},
105
+ 'windows_confirmation_required':selected=='windows11' and not windows_confirmed,
106
+ 'installation_mode':'unattended' if unattended_supported or direct_debian_boot else 'manual',
107
+ 'guest_setup':{'transport':'http','port':SCRIPT_SERVER_PORT,'commands':guest_commands(SCRIPT_SERVER_PORT)},
108
+ 'credentials':PUBLIC_CREDENTIALS,'iso':str(iso)}
109
+ if selected=='windows11' and not windows_confirmed:
110
+ return {'status':'needs_windows_confirmation','no_vm_created':True,'profile':profile,
111
+ 'action_required':'Ask the user whether to create Windows with these specs. Windows requires a valid license; activate it yourself after installation in Settings > System > Activation. VAMP does not include a Windows license.',
112
+ 'credentials':PUBLIC_CREDENTIALS}
113
+ journal['resource_profile']={'guest_os':selected,'memory_mb':memory_mb,'cpus':cpus,'disk_mb':disk_mb,
114
+ 'native_resolution':[1920,1080]}
115
+ if selected=='windows11':journal['license_notice']='Windows requires a valid license. Activate Windows yourself after installation; VAMP supplies no license or activation bypass.'
116
+ if os_type=='Windows11_64' and memory_mb<4096:raise ValueError('Windows 11 requires at least 4096 MB')
117
+ # Check version-specific password option before creating any VM.
118
+ help_text=''
119
+ if unattended_supported:
120
+ help_proc=subprocess.run([executable(),'unattended','install','--help'],capture_output=True,text=True)
121
+ help_text=help_proc.stdout+help_proc.stderr
122
+ password_flag='--user-password' if '--user-password' in help_text else '--password'
123
+ assert_no_active_kvm()
124
+ folder.mkdir(parents=True,exist_ok=False)
125
+ journal_path=folder/'vamp-install.json'
126
+ def start_verified():
127
+ # startvm waits for its session to open; still verify the hypervisor state.
128
+ run('startvm',name,'--type','headless')
129
+ state=''
130
+ for attempt in range(15):
131
+ state=parse(run('showvminfo',name,'--machinereadable')).get('VMState','unknown')
132
+ if state=='running':
133
+ journal.update(vm_state=state,startup_verified=True)
134
+ # Stock Windows install media waits for a key before booting.
135
+ # Send once on the initial provisioning boot, never on later reboots.
136
+ if selected=='windows11':
137
+ time.sleep(PROFILE['boot_wait_seconds'])
138
+ run('controlvm',name,'keyboardputscancode','1c','9c')
139
+ journal['events'].append('installer-boot-enter-sent')
140
+ return
141
+ if state not in ('starting','restoring'):break
142
+ time.sleep(1)
143
+ raise RuntimeError(f'VM creation completed but startup was not verified (state: {state}); inspect the VM log')
144
+ def record(stage):
145
+ journal['events'].append(stage)
146
+ journal_path.write_text(json.dumps(journal,indent=2)+'\n')
147
+ script_server=None
148
+ if serve_scripts and not os.environ.get('VAMP_SCRIPT_SERVER_DISABLE'):
149
+ try:
150
+ script_server=start_script_server(port=SCRIPT_SERVER_PORT,ttl=script_server_ttl)
151
+ except Exception as exc:
152
+ script_server={'status':'failed','port':SCRIPT_SERVER_PORT,'error':str(exc)}
153
+ journal['script_server']=script_server
154
+ if script_server.get('status')!='running':
155
+ journal.update(status='failed',error='Guest setup HTTP server could not start: '+str(script_server.get('error',script_server.get('status'))))
156
+ record('script-server-failed')
157
+ raise RuntimeError(journal['error'])
158
+ base_url=(script_server or {}).get('guest_urls',{}).get('virtualbox_nat') or f'http://10.0.2.2:{SCRIPT_SERVER_PORT}'
159
+ journal['post_create_notice']=post_create_notice(selected,base_url)
160
+ try:
161
+ run('createvm','--name',name,'--ostype',os_type,'--register','--basefolder',folder.parent)
162
+ record('vm-created')
163
+ from display import preferences
164
+ journal['display']=preferences(name,run)
165
+ from shares import prepare
166
+ journal['recording_share']=prepare(name,run)
167
+ options=['modifyvm',name,'--memory',memory_mb,'--cpus',cpus,'--vram',128,
168
+ '--mouse','usbtablet','--nic1','nat','--nat-localhostreachable1','on','--boot1','dvd','--boot2','disk',
169
+ '--graphicscontroller','vboxsvga' if os_type=='Windows11_64' else 'vmsvga']
170
+ if os_type=='Windows11_64':options+=['--firmware','efi','--tpm-type','2.0','--ioapic','on']
171
+ if direct_debian_boot:options+=['--firmware','efi']
172
+ run(*options)
173
+ disk=folder/(name+'.vdi')
174
+ run('createmedium','disk','--filename',disk,'--size',disk_mb,'--format','VDI')
175
+ run('storagectl',name,'--name','SATA','--add','sata','--controller','IntelAhci','--portcount','4')
176
+ run('storageattach',name,'--storagectl','SATA','--port','0','--device','0','--type','hdd','--medium',disk)
177
+ run('storagectl',name,'--name','IDE','--add','ide')
178
+ if not unattended_supported:
179
+ run('storageattach',name,'--storagectl','SATA','--port','1','--device','0','--type','dvddrive','--medium',iso)
180
+ start_verified()
181
+ if direct_debian_boot:
182
+ # Debian 13 DVD detection is unimplemented in some VBox builds.
183
+ # Boot the stock EFI GRUB console with the HTTP preseed instead.
184
+ time.sleep(PROFILE['boot_wait_seconds'])
185
+ for step in efi_boot_plan('debian',base_url):
186
+ if step['kind']=='wait':time.sleep(step['seconds'])
187
+ elif step['kind'] in ('text','line'):
188
+ run('controlvm',name,'keyboardputstring',step['text'])
189
+ if step['kind'] in ('line','enter'):
190
+ run('controlvm',name,'keyboardputscancode','1c','9c')
191
+ journal.update(status='installation_started',installation_mode='unattended',boot_method='efi-http-preseed',os_type=os_type,credentials=PUBLIC_CREDENTIALS,journal=str(journal_path))
192
+ record('debian-http-preseed-boot-dispatched')
193
+ return journal
194
+ journal.update(status='installation_started',installation_mode='manual',os_type=os_type,
195
+ frontend='headless',journal=str(journal_path),
196
+ credentials={'public_sandbox_credentials':False,'account_setup':'Choose your account in the OS installer'},
197
+ action_required=(f'This ISO needs a manual installation: complete the stock installer in the VM screen, '
198
+ f'choose your own guest account, then run the guest setup command from '
199
+ f'http://10.0.2.2:{SCRIPT_SERVER_PORT}/ (for example '
200
+ f'"wget -qO- {base_url}/setup.sh | sh"). No ISO was rewritten and no automatic account or recorder setup ran.'))
201
+ record('manual-installation-started')
202
+ return journal
203
+ if os_type=='Windows11_64':
204
+ from display import insert_additions
205
+ journal['guest_additions']=insert_additions(name,run=run)
206
+ install_args=['unattended','install',name,'--iso',iso,'--user','vboxuser',password_flag,'password123!',
207
+ '--full-user-name','VAMP Sandbox User','--hostname',name.lower()+'.vamp.local',
208
+ '--no-install-additions','--post-install-command',post_install_command(selected,base_url)]
209
+ if selected=='debian':
210
+ template=folder/'debian-preseed.cfg'
211
+ template.write_text(virtualbox_preseed(),encoding='utf-8')
212
+ install_args+=['--script-template',str(template)]
213
+ if os_type=='Windows11_64':
214
+ install_args+=['--image-index',image_index]
215
+ if product_key:install_args+=['--key',product_key]
216
+ run(*install_args,timeout=300)
217
+ start_verified()
218
+ journal.update(status='installation_started',installation_mode='unattended',os_type=os_type,frontend='headless',
219
+ recorder_setup=f'First login downloads the setup bundle from the host script server on port {SCRIPT_SERVER_PORT}',
220
+ guest_setup_command=f'wget -qO- {base_url}/setup.sh | sh' if selected!='windows11' else f'irm {base_url}/setup.ps1 | iex',
221
+ requires_ai_loop=False,journal=str(journal_path))
222
+ record('unattended-installation-started')
223
+ return journal
224
+ except Exception as exc:
225
+ journal.update(status='failed',error=str(exc),partial_vm_preserved=True)
226
+ record('failed')
227
+ raise RuntimeError(f'{exc}; partial setup preserved at {folder}') from exc
228
+
229
+
230
+ if __name__=='__main__':
231
+ parser=argparse.ArgumentParser(description=__doc__)
232
+ parser.add_argument('--json-stdin',action='store_true',required=True)
233
+ parser.parse_args()
234
+ sys.path.insert(0,str(ROOT/'backends/packer'))
235
+ from runner import create as packer_create
236
+ try: print(json.dumps(packer_create({'backend':'virtualbox',**json.load(sys.stdin)})))
237
+ except Exception as exc:
238
+ print(json.dumps({'status':'failed','error':str(exc)}));sys.exit(1)
@@ -1,29 +1,29 @@
1
- """Robot Framework v3 listener: optional low-resolution video and SQLite evidence."""
2
- import sys
3
- from pathlib import Path
4
- sys.path.insert(0,str(Path(__file__).resolve().parent))
5
- from history import begin,capture,end,event
6
-
7
- class RecordingListener:
8
- ROBOT_LISTENER_API_VERSION=3
9
- def __init__(self,vm,video='false'):
10
- self.vm=vm;self.video=str(video).lower() in ('true','1','yes');self.depth=0;self.run_id=None
11
- def start_suite(self,data,result):
12
- self.depth+=1
13
- if self.depth==1:
14
- try:self.run_id=begin(self.vm,self.video)['run_id']
15
- except Exception as exc:
16
- from robot.api import logger
17
- logger.warn('VAMP evidence initialization failed: '+str(exc))
18
- def end_test(self,data,result):
19
- if self.run_id:
20
- event(self.run_id,'robot_task',{'name':result.name,'status':result.status,'elapsed_ms':int(result.elapsed_time.total_seconds()*1000)})
21
- try:capture(self.run_id,'task-'+result.status.lower())
22
- except Exception as exc:event(self.run_id,'capture_error',{'error':str(exc)[:300]})
23
- def end_suite(self,data,result):
24
- if self.depth==1 and self.run_id:
25
- try:end(self.run_id,result.status)
26
- except Exception as exc:
27
- from robot.api import logger
28
- logger.warn('VAMP evidence finalization failed: '+str(exc))
29
- self.depth-=1
1
+ """Robot Framework v3 listener: optional low-resolution video and SQLite evidence."""
2
+ import sys
3
+ from pathlib import Path
4
+ sys.path.insert(0,str(Path(__file__).resolve().parent))
5
+ from history import begin,capture,end,event
6
+
7
+ class RecordingListener:
8
+ ROBOT_LISTENER_API_VERSION=3
9
+ def __init__(self,vm,video='false'):
10
+ self.vm=vm;self.video=str(video).lower() in ('true','1','yes');self.depth=0;self.run_id=None
11
+ def start_suite(self,data,result):
12
+ self.depth+=1
13
+ if self.depth==1:
14
+ try:self.run_id=begin(self.vm,self.video)['run_id']
15
+ except Exception as exc:
16
+ from robot.api import logger
17
+ logger.warn('VAMP evidence initialization failed: '+str(exc))
18
+ def end_test(self,data,result):
19
+ if self.run_id:
20
+ event(self.run_id,'robot_task',{'name':result.name,'status':result.status,'elapsed_ms':int(result.elapsed_time.total_seconds()*1000)})
21
+ try:capture(self.run_id,'task-'+result.status.lower())
22
+ except Exception as exc:event(self.run_id,'capture_error',{'error':str(exc)[:300]})
23
+ def end_suite(self,data,result):
24
+ if self.depth==1 and self.run_id:
25
+ try:end(self.run_id,result.status)
26
+ except Exception as exc:
27
+ from robot.api import logger
28
+ logger.warn('VAMP evidence finalization failed: '+str(exc))
29
+ self.depth-=1