vamp-mcp 0.1.9 → 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.
Potentially problematic release.
This version of vamp-mcp might be problematic. Click here for more details.
- package/LICENSE +21 -21
- package/README.md +144 -107
- package/THIRD_PARTY_NOTICES.md +32 -27
- package/bin/vamp-mcp.mjs +37 -37
- package/notices/mcp-virtualbox-LICENSE +21 -21
- package/notices/mcp-virtualbox-PROVENANCE.json +37 -37
- package/package.json +51 -17
- package/runtime/backends/common/Test-Environment.ps1 +7 -6
- package/runtime/backends/common/guest-install.json +58 -0
- package/runtime/backends/common/guest_install.py +57 -0
- package/runtime/backends/common/host-support.cjs +16 -0
- package/runtime/backends/common/packer.cjs +16 -0
- package/runtime/backends/hyperv/scripts/Manage-Desktop.ps1 +40 -67
- package/runtime/backends/hyperv/scripts/Send-InstallerBoot.ps1 +25 -0
- package/runtime/backends/kvm/debian-preseed.cfg +35 -35
- package/runtime/backends/library/registry.py +77 -77
- package/runtime/backends/library/replay.py +154 -154
- package/runtime/backends/packer/answer_media.py +16 -0
- package/runtime/backends/packer/deploy-hyperv.ps1 +10 -0
- package/runtime/backends/packer/drivers.py +49 -0
- package/runtime/backends/packer/hyperv-network.ps1 +10 -0
- package/runtime/backends/packer/images.py +75 -0
- package/runtime/backends/packer/osinfo.py +113 -0
- package/runtime/backends/packer/policy.json +15 -0
- package/runtime/backends/packer/runner.py +224 -0
- package/runtime/backends/packer/templates.py +118 -0
- package/runtime/backends/packer/toolchain.py +80 -0
- package/runtime/backends/remote_ssh/server.mjs +321 -94
- package/runtime/backends/virtualbox/desktop.cjs +37 -0
- package/runtime/backends/virtualbox/display.py +101 -101
- package/runtime/backends/virtualbox/history.py +139 -139
- package/runtime/backends/virtualbox/mouse_click.py +15 -15
- package/runtime/backends/virtualbox/mouse_move.py +18 -18
- package/runtime/backends/virtualbox/profiles.json +46 -46
- package/runtime/backends/virtualbox/provision.py +238 -184
- package/runtime/backends/virtualbox/recording_listener.py +29 -29
- package/runtime/backends/virtualbox/recordings.py +39 -39
- package/runtime/backends/virtualbox/requirements.txt +7 -7
- package/runtime/backends/virtualbox/rpas/debian_first_boot/manifest.json +1 -1
- package/runtime/backends/virtualbox/rpas/debian_first_boot/run.robot +13 -13
- package/runtime/backends/virtualbox/rpas/debian_first_boot/workflow.py +75 -75
- package/runtime/backends/virtualbox/rpas/observe/manifest.json +7 -7
- package/runtime/backends/virtualbox/rpas/observe/run.robot +13 -13
- package/runtime/backends/virtualbox/rpas/observe/workflow.py +14 -14
- package/runtime/backends/virtualbox/server.mjs +440 -63
- package/runtime/backends/virtualbox/setup_windows_sdk.py +58 -58
- package/runtime/backends/virtualbox/shares.py +68 -68
- package/runtime/backends/virtualbox/snapshots.py +53 -53
- package/runtime/backends/virtualbox/transfers.py +89 -89
- package/runtime/backends/virtualbox/vnc.py +61 -61
- package/runtime/guest_keys.py +13 -13
- package/runtime/guest_setup/http/debian-preseed.cfg +39 -0
- package/runtime/guest_setup/http/postdeb.sh +94 -0
- package/runtime/guest_setup/http/postwin.ps1 +53 -0
- package/runtime/guest_setup/http/setup-all.ps1 +25 -0
- package/runtime/guest_setup/http/setup-win.cmd +7 -0
- package/runtime/guest_setup/http/setup.ps1 +44 -0
- package/runtime/guest_setup/http/setup.sh +50 -0
- package/runtime/guest_setup/kvm/setup-debian.sh +73 -0
- package/runtime/guest_setup/kvm/setup-windows.ps1 +52 -0
- package/runtime/guest_setup/recorder/README.txt +12 -8
- package/runtime/guest_setup/recorder/RECORDER-LICENSE +674 -674
- package/runtime/guest_setup/recorder/RECORDING-GUIDE.txt +31 -31
- package/runtime/guest_setup/recorder/apply-display.py +41 -41
- package/runtime/guest_setup/recorder/configure-debian-mirrors.py +62 -62
- package/runtime/guest_setup/recorder/configure-gdm.py +23 -0
- package/runtime/guest_setup/recorder/configure-session.ps1 +14 -0
- package/runtime/guest_setup/recorder/gnome-display.py +60 -60
- package/runtime/guest_setup/recorder/install-display-startup.py +67 -39
- package/runtime/guest_setup/recorder/install-hypervisor-drivers.ps1 +34 -0
- package/runtime/guest_setup/recorder/install-resolution-shortcut.ps1 +36 -0
- package/runtime/guest_setup/recorder/postwin.cmd +10 -10
- package/runtime/guest_setup/recorder/prepare-recording.py +30 -30
- package/runtime/guest_setup/recorder/recorder.zip +0 -0
- package/runtime/guest_setup/recorder/requirements-recorder.txt +2 -2
- package/runtime/guest_setup/recorder/session-policy.py +22 -0
- package/runtime/guest_setup/recorder/set-resolution-registry.ps1 +40 -0
- package/runtime/guest_setup/recorder/setup-user.py +53 -35
- package/runtime/guest_setup/recorder/setup-win.cmd +4 -11
- package/runtime/guest_setup/recorder/setup.ps1 +112 -30
- package/runtime/guest_setup/recorder/setup.sh +19 -1
- package/runtime/guest_setup/recorder/vamp-recorder.py +148 -148
- package/runtime/guest_setup/recorder/verify-recorder.py +4 -4
- package/runtime/guest_setup/recorder/windows-display.py +76 -76
- package/runtime/guest_setup/requirements.txt +2 -0
- package/runtime/guest_setup/setup-all.ps1 +35 -0
- package/runtime/guest_setup/setup-all.sh +22 -0
- package/runtime/guest_setup/vault/Install-VCRuntime.ps1 +26 -0
- package/runtime/guest_setup/vault/setup-guest-vault.ps1 +148 -0
- package/runtime/guest_setup/vault/setup-guest-vault.sh +75 -0
- package/runtime/recording_converter.py +230 -230
- package/runtime/requirements-mcp.txt +11 -11
- package/runtime/rpas/README.md +161 -161
- package/runtime/rpas/captcha_handoff/manifest.json +27 -27
- package/runtime/rpas/captcha_handoff/run.robot +16 -16
- package/runtime/rpas/captcha_handoff/workflow.py +11 -11
- package/runtime/rpas/common.resource +26 -26
- package/runtime/rpas/debian_update/manifest.json +27 -27
- package/runtime/rpas/debian_update/run.robot +17 -17
- package/runtime/rpas/debian_update/workflow.py +13 -13
- package/runtime/rpas/desktop_control/manifest.json +26 -26
- package/runtime/rpas/desktop_control/run.robot +27 -27
- package/runtime/rpas/desktop_control/workflow.py +51 -51
- package/runtime/rpas/firefox_launch/manifest.json +27 -27
- package/runtime/rpas/firefox_launch/run.robot +15 -15
- package/runtime/rpas/firefox_launch/workflow.py +25 -25
- package/runtime/rpas/firefox_naver/manifest.json +27 -27
- package/runtime/rpas/firefox_naver/run.robot +21 -21
- package/runtime/rpas/firefox_naver/workflow.py +28 -28
- package/runtime/rpas/kvm_validation/README.md +11 -11
- package/runtime/rpas/kvm_validation/manifest.json +28 -28
- package/runtime/rpas/kvm_validation/run.robot +30 -30
- package/runtime/rpas/kvm_validation/workflow.py +91 -91
- package/runtime/rpas/manifest.schema.json +105 -105
- package/runtime/rpas/naver_login/login.robot +25 -25
- package/runtime/rpas/naver_login/manifest.json +33 -33
- package/runtime/rpas/naver_login/run.robot +20 -20
- package/runtime/rpas/naver_login/workflow.py +32 -32
- package/runtime/rpas/windows_naver_recorded/README.md +24 -24
- package/runtime/rpas/windows_naver_recorded/conversion.json +25 -25
- package/runtime/rpas/windows_naver_recorded/manifest.json +28 -28
- package/runtime/rpas/windows_naver_recorded/run.robot +37 -37
- package/runtime/rpas/windows_naver_recorded/workflow.py +32 -32
- package/runtime/scripts/build_recorder_media.py +39 -39
- package/runtime/scripts/macos/setup-host.sh +126 -0
- package/runtime/scripts/remote_host_setup.sh +7 -4
- package/runtime/scripts/script_server.py +571 -0
- package/runtime/skills/vamp-rpa-ui-checks/SKILL.md +26 -0
- package/runtime/skills/vamp-rpa-ui-checks/agents/openai.yaml +4 -0
- package/runtime/skills/vamp-rpa-ui-checks/references/display.md +12 -0
- package/runtime/skills/vamp-rpa-ui-checks/references/user-guide.md +51 -0
- package/runtime/skills/vamp-ui-cleanup/SKILL.md +15 -0
- package/runtime/skills/vamp-ui-cleanup/agents/openai.yaml +4 -0
- package/runtime/skills/vamp-ui-validation/SKILL.md +27 -0
- package/runtime/skills/vamp-ui-validation/agents/openai.yaml +4 -0
- package/runtime/third_party/mcp-virtualbox/scripts/mouse_click.py +65 -65
- package/runtime/third_party/pyautogui-recorder/LICENSE +674 -674
- package/runtime/third_party/pyautogui-recorder/PROVENANCE.json +16 -16
- package/runtime/third_party/pyautogui-recorder/PyAutoGuiRecorder.py +169 -169
- package/runtime/third_party/pyautogui-recorder/README.md +53 -53
- package/runtime/scripts/build_debian_installer.py +0 -48
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
"""Native guest 1920x1080 plus a scaled observation frontend."""
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
import argparse
|
|
4
|
-
import json
|
|
5
|
-
import os
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
import struct
|
|
8
|
-
import subprocess
|
|
9
|
-
import sys
|
|
10
|
-
import tempfile
|
|
11
|
-
try:
|
|
12
|
-
from .provision import executable, parse
|
|
13
|
-
except ImportError:
|
|
14
|
-
from provision import executable, parse
|
|
15
|
-
|
|
16
|
-
WIDTH,HEIGHT=1920,1080
|
|
17
|
-
DISPLAY_DATA={'GUI/Fullscreen':'','GUI/Seamless':'','GUI/Scale':'true',
|
|
18
|
-
'GUI/AutoresizeGuest':'false','GUI/LastGuestSizeHint':'1920,1080',
|
|
19
|
-
'CustomVideoMode1':'1920x1080x32'}
|
|
20
|
-
|
|
21
|
-
def command(*args):
|
|
22
|
-
result=subprocess.run([executable(),*map(str,args)],capture_output=True,text=True,timeout=60)
|
|
23
|
-
if result.returncode:raise RuntimeError(result.stderr.strip()[:500] or 'VBoxManage failed')
|
|
24
|
-
return result.stdout
|
|
25
|
-
|
|
26
|
-
def preferences(vm,run=command):
|
|
27
|
-
# Permit full HD even when the host viewer's available area is smaller.
|
|
28
|
-
run('setextradata','global','GUI/MaxGuestResolution','any')
|
|
29
|
-
for key,value in DISPLAY_DATA.items():run('setextradata',vm,key,value)
|
|
30
|
-
return {'native_target':[WIDTH,HEIGHT],'viewer':'scaled','auto_resize_guest':False,
|
|
31
|
-
'resolution_verified':False,'viewer_reopen_may_be_required':True}
|
|
32
|
-
|
|
33
|
-
def configure(vm,run=command):
|
|
34
|
-
info=parse(run('showvminfo',vm,'--machinereadable'))
|
|
35
|
-
result=preferences(vm,run)
|
|
36
|
-
result.update(status='configured',vm=vm)
|
|
37
|
-
if info.get('VMState')=='running':
|
|
38
|
-
try:
|
|
39
|
-
run('controlvm',vm,'setvideomodehint',WIDTH,HEIGHT,32)
|
|
40
|
-
result['video_hint']='sent'
|
|
41
|
-
except RuntimeError as exc:result.update(video_hint='failed',action_required=str(exc))
|
|
42
|
-
try:
|
|
43
|
-
with tempfile.TemporaryDirectory() as directory:
|
|
44
|
-
shot=Path(directory)/'screen.png'
|
|
45
|
-
run('controlvm',vm,'screenshotpng',shot)
|
|
46
|
-
header=shot.read_bytes()[:24]
|
|
47
|
-
if header[:8]!=b'\x89PNG\r\n\x1a\n':raise ValueError('Screenshot is not PNG')
|
|
48
|
-
size=struct.unpack('>II',header[16:24]);result['observed_resolution']=list(size)
|
|
49
|
-
result['resolution_verified']=size==(WIDTH,HEIGHT)
|
|
50
|
-
except (OSError,ValueError,RuntimeError,struct.error) as exc:
|
|
51
|
-
result['verification_error']=str(exc)
|
|
52
|
-
if not result['resolution_verified']:
|
|
53
|
-
result['action_required']='Set 1920x1080 inside the guest OS after installing display drivers/Guest Additions; recheck with vm_configure_display.'
|
|
54
|
-
return result
|
|
55
|
-
|
|
56
|
-
def find_additions(run=command,iso_path=None):
|
|
57
|
-
if iso_path:
|
|
58
|
-
path=Path(iso_path).expanduser().resolve(strict=True)
|
|
59
|
-
if not path.is_file():raise ValueError('Guest Additions ISO must be a local file')
|
|
60
|
-
return path
|
|
61
|
-
text=run('list','systemproperties')
|
|
62
|
-
for line in text.splitlines():
|
|
63
|
-
if 'Default Additions ISO' in line:
|
|
64
|
-
candidate=Path(line.split(':',1)[1].strip())
|
|
65
|
-
if candidate.is_file():return candidate
|
|
66
|
-
candidates=[Path(executable()).resolve().parent/'VBoxGuestAdditions.iso',
|
|
67
|
-
Path(os.environ.get('PROGRAMFILES','C:/Program Files'))/'Oracle/VirtualBox/VBoxGuestAdditions.iso',
|
|
68
|
-
Path('/usr/share/virtualbox/VBoxGuestAdditions.iso'),
|
|
69
|
-
Path('/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso')]
|
|
70
|
-
return next((p for p in candidates if p.is_file()),None)
|
|
71
|
-
|
|
72
|
-
def insert_additions(vm,iso_path=None,run=command):
|
|
73
|
-
info=parse(run('showvminfo',vm,'--machinereadable'))
|
|
74
|
-
if not info.get('ostype','').startswith('Windows'):
|
|
75
|
-
raise ValueError('This handoff is for a Windows VM; inspect the VM OS type first')
|
|
76
|
-
iso=find_additions(run,iso_path)
|
|
77
|
-
if iso is None:
|
|
78
|
-
return {'status':'iso_not_found','vm':vm,'guest_additions_installed_verified':False,
|
|
79
|
-
'action_required':'Install/download the Guest Additions ISO matching your host VirtualBox version, then pass iso_path.'}
|
|
80
|
-
if not any(k.startswith('storagecontrollername') and v=='SATA' for k,v in info.items()):
|
|
81
|
-
raise ValueError('Expected VAMP SATA controller. Select an empty optical drive manually for other VM layouts.')
|
|
82
|
-
# Port 2 is reserved for GA in VAMP-created VMs; never replace another disk/ISO.
|
|
83
|
-
occupied=info.get('SATA-2-0','')
|
|
84
|
-
if occupied and occupied not in ('none','emptydrive'):
|
|
85
|
-
if os.path.normcase(os.path.abspath(occupied))!=os.path.normcase(str(iso.resolve())):
|
|
86
|
-
raise ValueError('Reserved SATA port 2 is occupied; refusing to replace media')
|
|
87
|
-
else:
|
|
88
|
-
run('storageattach',vm,'--storagectl','SATA','--port',2,'--device',0,
|
|
89
|
-
'--type','dvddrive','--medium',iso)
|
|
90
|
-
return {'status':'media_inserted','vm':vm,'iso':str(iso),'guest_additions_installed_verified':False,
|
|
91
|
-
'action_required':'In Windows open the VirtualBox Guest Additions CD, run VBoxWindowsAdditions.exe, approve UAC and reboot. Then select Display resolution 1920x1080, Scale 100%, and call vm_configure_display.'}
|
|
92
|
-
|
|
93
|
-
if __name__=='__main__':
|
|
94
|
-
parser=argparse.ArgumentParser(description=__doc__)
|
|
95
|
-
parser.add_argument('action',choices=['configure','additions'])
|
|
96
|
-
args=parser.parse_args()
|
|
97
|
-
try:
|
|
98
|
-
values=json.load(sys.stdin)
|
|
99
|
-
print(json.dumps((configure if args.action=='configure' else insert_additions)(**values)))
|
|
100
|
-
except Exception as exc:
|
|
101
|
-
print(json.dumps({'status':'failed','error':str(exc)}));sys.exit(1)
|
|
1
|
+
"""Native guest 1920x1080 plus a scaled observation frontend."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
import argparse
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import struct
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
import tempfile
|
|
11
|
+
try:
|
|
12
|
+
from .provision import executable, parse
|
|
13
|
+
except ImportError:
|
|
14
|
+
from provision import executable, parse
|
|
15
|
+
|
|
16
|
+
WIDTH,HEIGHT=1920,1080
|
|
17
|
+
DISPLAY_DATA={'GUI/Fullscreen':'','GUI/Seamless':'','GUI/Scale':'true',
|
|
18
|
+
'GUI/AutoresizeGuest':'false','GUI/LastGuestSizeHint':'1920,1080',
|
|
19
|
+
'CustomVideoMode1':'1920x1080x32'}
|
|
20
|
+
|
|
21
|
+
def command(*args):
|
|
22
|
+
result=subprocess.run([executable(),*map(str,args)],capture_output=True,text=True,timeout=60)
|
|
23
|
+
if result.returncode:raise RuntimeError(result.stderr.strip()[:500] or 'VBoxManage failed')
|
|
24
|
+
return result.stdout
|
|
25
|
+
|
|
26
|
+
def preferences(vm,run=command):
|
|
27
|
+
# Permit full HD even when the host viewer's available area is smaller.
|
|
28
|
+
run('setextradata','global','GUI/MaxGuestResolution','any')
|
|
29
|
+
for key,value in DISPLAY_DATA.items():run('setextradata',vm,key,value)
|
|
30
|
+
return {'native_target':[WIDTH,HEIGHT],'viewer':'scaled','auto_resize_guest':False,
|
|
31
|
+
'resolution_verified':False,'viewer_reopen_may_be_required':True}
|
|
32
|
+
|
|
33
|
+
def configure(vm,run=command):
|
|
34
|
+
info=parse(run('showvminfo',vm,'--machinereadable'))
|
|
35
|
+
result=preferences(vm,run)
|
|
36
|
+
result.update(status='configured',vm=vm)
|
|
37
|
+
if info.get('VMState')=='running':
|
|
38
|
+
try:
|
|
39
|
+
run('controlvm',vm,'setvideomodehint',WIDTH,HEIGHT,32)
|
|
40
|
+
result['video_hint']='sent'
|
|
41
|
+
except RuntimeError as exc:result.update(video_hint='failed',action_required=str(exc))
|
|
42
|
+
try:
|
|
43
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
44
|
+
shot=Path(directory)/'screen.png'
|
|
45
|
+
run('controlvm',vm,'screenshotpng',shot)
|
|
46
|
+
header=shot.read_bytes()[:24]
|
|
47
|
+
if header[:8]!=b'\x89PNG\r\n\x1a\n':raise ValueError('Screenshot is not PNG')
|
|
48
|
+
size=struct.unpack('>II',header[16:24]);result['observed_resolution']=list(size)
|
|
49
|
+
result['resolution_verified']=size==(WIDTH,HEIGHT)
|
|
50
|
+
except (OSError,ValueError,RuntimeError,struct.error) as exc:
|
|
51
|
+
result['verification_error']=str(exc)
|
|
52
|
+
if not result['resolution_verified']:
|
|
53
|
+
result['action_required']='Set 1920x1080 inside the guest OS after installing display drivers/Guest Additions; recheck with vm_configure_display.'
|
|
54
|
+
return result
|
|
55
|
+
|
|
56
|
+
def find_additions(run=command,iso_path=None):
|
|
57
|
+
if iso_path:
|
|
58
|
+
path=Path(iso_path).expanduser().resolve(strict=True)
|
|
59
|
+
if not path.is_file():raise ValueError('Guest Additions ISO must be a local file')
|
|
60
|
+
return path
|
|
61
|
+
text=run('list','systemproperties')
|
|
62
|
+
for line in text.splitlines():
|
|
63
|
+
if 'Default Additions ISO' in line:
|
|
64
|
+
candidate=Path(line.split(':',1)[1].strip())
|
|
65
|
+
if candidate.is_file():return candidate
|
|
66
|
+
candidates=[Path(executable()).resolve().parent/'VBoxGuestAdditions.iso',
|
|
67
|
+
Path(os.environ.get('PROGRAMFILES','C:/Program Files'))/'Oracle/VirtualBox/VBoxGuestAdditions.iso',
|
|
68
|
+
Path('/usr/share/virtualbox/VBoxGuestAdditions.iso'),
|
|
69
|
+
Path('/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso')]
|
|
70
|
+
return next((p for p in candidates if p.is_file()),None)
|
|
71
|
+
|
|
72
|
+
def insert_additions(vm,iso_path=None,run=command):
|
|
73
|
+
info=parse(run('showvminfo',vm,'--machinereadable'))
|
|
74
|
+
if not info.get('ostype','').startswith('Windows'):
|
|
75
|
+
raise ValueError('This handoff is for a Windows VM; inspect the VM OS type first')
|
|
76
|
+
iso=find_additions(run,iso_path)
|
|
77
|
+
if iso is None:
|
|
78
|
+
return {'status':'iso_not_found','vm':vm,'guest_additions_installed_verified':False,
|
|
79
|
+
'action_required':'Install/download the Guest Additions ISO matching your host VirtualBox version, then pass iso_path.'}
|
|
80
|
+
if not any(k.startswith('storagecontrollername') and v=='SATA' for k,v in info.items()):
|
|
81
|
+
raise ValueError('Expected VAMP SATA controller. Select an empty optical drive manually for other VM layouts.')
|
|
82
|
+
# Port 2 is reserved for GA in VAMP-created VMs; never replace another disk/ISO.
|
|
83
|
+
occupied=info.get('SATA-2-0','')
|
|
84
|
+
if occupied and occupied not in ('none','emptydrive'):
|
|
85
|
+
if os.path.normcase(os.path.abspath(occupied))!=os.path.normcase(str(iso.resolve())):
|
|
86
|
+
raise ValueError('Reserved SATA port 2 is occupied; refusing to replace media')
|
|
87
|
+
else:
|
|
88
|
+
run('storageattach',vm,'--storagectl','SATA','--port',2,'--device',0,
|
|
89
|
+
'--type','dvddrive','--medium',iso)
|
|
90
|
+
return {'status':'media_inserted','vm':vm,'iso':str(iso),'guest_additions_installed_verified':False,
|
|
91
|
+
'action_required':'In Windows open the VirtualBox Guest Additions CD, run VBoxWindowsAdditions.exe, approve UAC and reboot. Then select Display resolution 1920x1080, Scale 100%, and call vm_configure_display.'}
|
|
92
|
+
|
|
93
|
+
if __name__=='__main__':
|
|
94
|
+
parser=argparse.ArgumentParser(description=__doc__)
|
|
95
|
+
parser.add_argument('action',choices=['configure','additions'])
|
|
96
|
+
args=parser.parse_args()
|
|
97
|
+
try:
|
|
98
|
+
values=json.load(sys.stdin)
|
|
99
|
+
print(json.dumps((configure if args.action=='configure' else insert_additions)(**values)))
|
|
100
|
+
except Exception as exc:
|
|
101
|
+
print(json.dumps({'status':'failed','error':str(exc)}));sys.exit(1)
|
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
"""Local SQLite execution history plus bounded, optional VirtualBox screen recording."""
|
|
2
|
-
from datetime import datetime,timezone
|
|
3
|
-
from contextlib import contextmanager
|
|
4
|
-
import json
|
|
5
|
-
import os
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
import sqlite3
|
|
8
|
-
import subprocess
|
|
9
|
-
import sys
|
|
10
|
-
import uuid
|
|
11
|
-
import time
|
|
12
|
-
try:
|
|
13
|
-
from .provision import executable,parse
|
|
14
|
-
except ImportError:
|
|
15
|
-
from provision import executable,parse
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def data_root():return Path(os.environ.get('VAMP_DATA_DIR',Path.home()/'VAMP')).resolve()
|
|
19
|
-
def now():return datetime.now(timezone.utc).isoformat()
|
|
20
|
-
@contextmanager
|
|
21
|
-
def connect():
|
|
22
|
-
root=data_root();root.mkdir(parents=True,exist_ok=True)
|
|
23
|
-
db=sqlite3.connect(root/'history.sqlite3',timeout=15);db.row_factory=sqlite3.Row
|
|
24
|
-
db.executescript('''PRAGMA foreign_keys=ON;
|
|
25
|
-
CREATE TABLE IF NOT EXISTS runs(id TEXT PRIMARY KEY,vm TEXT,status TEXT,started_at TEXT,finished_at TEXT,robot_status TEXT,error_summary TEXT);
|
|
26
|
-
CREATE UNIQUE INDEX IF NOT EXISTS one_active_vm ON runs(vm) WHERE status='running';
|
|
27
|
-
CREATE TABLE IF NOT EXISTS events(id INTEGER PRIMARY KEY,run_id TEXT REFERENCES runs(id),kind TEXT,created_at TEXT,payload_json TEXT);
|
|
28
|
-
CREATE TABLE IF NOT EXISTS artifacts(id INTEGER PRIMARY KEY,run_id TEXT REFERENCES runs(id),kind TEXT,path TEXT UNIQUE,created_at TEXT,bytes INTEGER);
|
|
29
|
-
''')
|
|
30
|
-
try:
|
|
31
|
-
with db:yield db
|
|
32
|
-
finally:db.close()
|
|
33
|
-
|
|
34
|
-
def run_command(*args):
|
|
35
|
-
proc=subprocess.run([executable(),*map(str,args)],capture_output=True,text=True,timeout=90)
|
|
36
|
-
if proc.returncode:raise RuntimeError(proc.stderr.strip()[:400] or 'VBoxManage command failed')
|
|
37
|
-
return proc.stdout
|
|
38
|
-
|
|
39
|
-
def event(run_id,kind,payload):
|
|
40
|
-
with connect() as db:db.execute('INSERT INTO events(run_id,kind,created_at,payload_json) VALUES(?,?,?,?)',(run_id,kind,now(),json.dumps(payload)))
|
|
41
|
-
|
|
42
|
-
def row(run_id):
|
|
43
|
-
with connect() as db:r=db.execute('SELECT * FROM runs WHERE id=?',(run_id,)).fetchone()
|
|
44
|
-
if not r:raise ValueError('Unknown run id')
|
|
45
|
-
return dict(r)
|
|
46
|
-
|
|
47
|
-
def add_artifact(run_id,kind,path):
|
|
48
|
-
path=Path(path).resolve();size=path.stat().st_size
|
|
49
|
-
if not path.is_relative_to(data_root()/'runs'/run_id):raise ValueError('Artifact outside selected run')
|
|
50
|
-
with connect() as db:
|
|
51
|
-
db.execute('INSERT OR REPLACE INTO artifacts(run_id,kind,path,created_at,bytes) VALUES(?,?,?,?,?)',(run_id,kind,str(path),now(),size))
|
|
52
|
-
return {'kind':kind,'path':str(path),'bytes':size}
|
|
53
|
-
|
|
54
|
-
def capture(run_id,label='screen',run=run_command):
|
|
55
|
-
item=row(run_id)
|
|
56
|
-
if not label.replace('-','').replace('_','').isalnum():raise ValueError('Invalid screenshot label')
|
|
57
|
-
folder=data_root()/'runs'/run_id;folder.mkdir(parents=True,exist_ok=True)
|
|
58
|
-
path=folder/(label+'-'+uuid.uuid4().hex[:6]+'.png')
|
|
59
|
-
run('controlvm',item['vm'],'screenshotpng',path)
|
|
60
|
-
return add_artifact(run_id,'screenshot',path)
|
|
61
|
-
|
|
62
|
-
def begin(vm,video=False,run=run_command):
|
|
63
|
-
info=parse(run('showvminfo',vm,'--machinereadable'))
|
|
64
|
-
if info.get('VMState')!='running':raise ValueError('Observation requires a running VM; no implicit startup')
|
|
65
|
-
run_id=uuid.uuid4().hex[:16];folder=data_root()/'runs'/run_id;folder.mkdir(parents=True)
|
|
66
|
-
if video and (info.get('recording_started')=='on' or info.get('recording')=='on'):raise ValueError('VM is already recording; do not replace another recording')
|
|
67
|
-
with connect() as db:db.execute('INSERT INTO runs VALUES(?,?,?,?,?,?,?)',(run_id,vm,'running',now(),None,None,None))
|
|
68
|
-
result={'status':'running','run_id':run_id,'vm':vm,'database':str(data_root()/'history.sqlite3'),'video_started':False}
|
|
69
|
-
try:
|
|
70
|
-
if video:
|
|
71
|
-
for setting,value in [('filename',folder/'screen.webm'),('videofps','5'),('maxtime','180'),('maxfilesize','20'),('opts','vc_enabled=true,ac_enabled=false')]:
|
|
72
|
-
run('controlvm',vm,'recording',setting,value)
|
|
73
|
-
run('controlvm',vm,'recording','videores',640,360)
|
|
74
|
-
run('controlvm',vm,'recording','on')
|
|
75
|
-
state=parse(run('showvminfo',vm,'--machinereadable'))
|
|
76
|
-
if state.get('recording_started')=='off':run('controlvm',vm,'recording','start')
|
|
77
|
-
result['video_started']=True
|
|
78
|
-
event(run_id,'start',{'video_started':result['video_started'],'video_limits':{'width':640,'height':360,'fps':5,'seconds':180,'max_mb':20}})
|
|
79
|
-
try:result['start_screenshot']=capture(run_id,'start',run)
|
|
80
|
-
except Exception as exc:event(run_id,'capture_error',{'error':str(exc)[:300]})
|
|
81
|
-
return result
|
|
82
|
-
except Exception as exc:
|
|
83
|
-
# If recording started but later initialization fails, stop our own recording.
|
|
84
|
-
if result['video_started']:
|
|
85
|
-
try:run('controlvm',vm,'recording','off')
|
|
86
|
-
except Exception:pass
|
|
87
|
-
with connect() as db:db.execute('UPDATE runs SET status=?,finished_at=?,error_summary=? WHERE id=?',('failed',now(),str(exc)[:400],run_id))
|
|
88
|
-
raise
|
|
89
|
-
|
|
90
|
-
def end(run_id,robot_status='completed',run=run_command):
|
|
91
|
-
item=row(run_id)
|
|
92
|
-
if item['status']!='running':return {'status':item['status'],'run_id':run_id,'already_finished':True}
|
|
93
|
-
with connect() as db:
|
|
94
|
-
start=db.execute("SELECT payload_json FROM events WHERE run_id=? AND kind='start' ORDER BY id LIMIT 1",(run_id,)).fetchone()
|
|
95
|
-
if start and json.loads(start[0]).get('video_started'):
|
|
96
|
-
try:run('controlvm',item['vm'],'recording','stop')
|
|
97
|
-
except Exception as exc:event(run_id,'recording_stop_notice',{'error':str(exc)[:300]})
|
|
98
|
-
try:run('controlvm',item['vm'],'recording','off')
|
|
99
|
-
except Exception as exc:event(run_id,'recording_stop_error',{'error':str(exc)[:300]})
|
|
100
|
-
time.sleep(.3)
|
|
101
|
-
try:capture(run_id,'end',run)
|
|
102
|
-
except Exception as exc:event(run_id,'capture_error',{'error':str(exc)[:300]})
|
|
103
|
-
videos=list((data_root()/'runs'/run_id).glob('*.webm'))+list((data_root()/'runs'/run_id).glob('*.mkv'))
|
|
104
|
-
for video in videos:
|
|
105
|
-
if video.stat().st_size:add_artifact(run_id,'video',video)
|
|
106
|
-
with connect() as db:db.execute('UPDATE runs SET status=?,finished_at=?,robot_status=? WHERE id=?',('finished',now(),robot_status,run_id))
|
|
107
|
-
event(run_id,'end',{'robot_status':robot_status})
|
|
108
|
-
return detail(run_id)
|
|
109
|
-
|
|
110
|
-
def detail(run_id):
|
|
111
|
-
item=row(run_id)
|
|
112
|
-
with connect() as db:
|
|
113
|
-
item['artifact_count']=db.execute('SELECT count(*) FROM artifacts WHERE run_id=?',(run_id,)).fetchone()[0]
|
|
114
|
-
item['artifacts']=[dict(r) for r in db.execute('SELECT * FROM artifacts WHERE run_id=? ORDER BY id DESC LIMIT 30',(run_id,))]
|
|
115
|
-
initial=db.execute("SELECT payload_json FROM events WHERE run_id=? AND kind='start' ORDER BY id LIMIT 1",(run_id,)).fetchone()
|
|
116
|
-
item['video_requested']=bool(initial and json.loads(initial[0]).get('video_started'))
|
|
117
|
-
item['video_saved']=db.execute("SELECT count(*) FROM artifacts WHERE run_id=? AND kind='video' AND bytes>0",(run_id,)).fetchone()[0]>0
|
|
118
|
-
item['evidence_status']='video_saved' if item['video_saved'] else ('video_missing' if item['video_requested'] else 'screenshots_only')
|
|
119
|
-
item['events']=[dict(r) for r in db.execute('SELECT * FROM events WHERE run_id=? ORDER BY id DESC LIMIT 30',(run_id,))]
|
|
120
|
-
return item
|
|
121
|
-
|
|
122
|
-
def listing(limit=20):
|
|
123
|
-
if not 1<=limit<=100:raise ValueError('History limit must be 1-100')
|
|
124
|
-
with connect() as db:runs=[dict(r) for r in db.execute('SELECT * FROM runs ORDER BY started_at DESC LIMIT ?',(limit,))]
|
|
125
|
-
return {'status':'observed','database':str(data_root()/'history.sqlite3'),'runs':runs}
|
|
126
|
-
|
|
127
|
-
def artifact(artifact_id):
|
|
128
|
-
with connect() as db:r=db.execute('SELECT * FROM artifacts WHERE id=?',(artifact_id,)).fetchone()
|
|
129
|
-
if not r:raise ValueError('Unknown artifact id')
|
|
130
|
-
item=dict(r);path=Path(item['path']).resolve()
|
|
131
|
-
if not path.is_relative_to(data_root()/'runs'/item['run_id']) or not path.is_file():raise ValueError('Artifact unavailable')
|
|
132
|
-
return item
|
|
133
|
-
|
|
134
|
-
if __name__=='__main__':
|
|
135
|
-
try:
|
|
136
|
-
args=json.load(sys.stdin);op=args.pop('action','list')
|
|
137
|
-
functions={'begin':begin,'end':end,'capture':capture,'list':listing,'detail':detail,'artifact':artifact}
|
|
138
|
-
print(json.dumps(functions[op](**args)))
|
|
139
|
-
except Exception as exc:print(json.dumps({'status':'failed','error':str(exc)}));sys.exit(1)
|
|
1
|
+
"""Local SQLite execution history plus bounded, optional VirtualBox screen recording."""
|
|
2
|
+
from datetime import datetime,timezone
|
|
3
|
+
from contextlib import contextmanager
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import sqlite3
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
import uuid
|
|
11
|
+
import time
|
|
12
|
+
try:
|
|
13
|
+
from .provision import executable,parse
|
|
14
|
+
except ImportError:
|
|
15
|
+
from provision import executable,parse
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def data_root():return Path(os.environ.get('VAMP_DATA_DIR',Path.home()/'VAMP')).resolve()
|
|
19
|
+
def now():return datetime.now(timezone.utc).isoformat()
|
|
20
|
+
@contextmanager
|
|
21
|
+
def connect():
|
|
22
|
+
root=data_root();root.mkdir(parents=True,exist_ok=True)
|
|
23
|
+
db=sqlite3.connect(root/'history.sqlite3',timeout=15);db.row_factory=sqlite3.Row
|
|
24
|
+
db.executescript('''PRAGMA foreign_keys=ON;
|
|
25
|
+
CREATE TABLE IF NOT EXISTS runs(id TEXT PRIMARY KEY,vm TEXT,status TEXT,started_at TEXT,finished_at TEXT,robot_status TEXT,error_summary TEXT);
|
|
26
|
+
CREATE UNIQUE INDEX IF NOT EXISTS one_active_vm ON runs(vm) WHERE status='running';
|
|
27
|
+
CREATE TABLE IF NOT EXISTS events(id INTEGER PRIMARY KEY,run_id TEXT REFERENCES runs(id),kind TEXT,created_at TEXT,payload_json TEXT);
|
|
28
|
+
CREATE TABLE IF NOT EXISTS artifacts(id INTEGER PRIMARY KEY,run_id TEXT REFERENCES runs(id),kind TEXT,path TEXT UNIQUE,created_at TEXT,bytes INTEGER);
|
|
29
|
+
''')
|
|
30
|
+
try:
|
|
31
|
+
with db:yield db
|
|
32
|
+
finally:db.close()
|
|
33
|
+
|
|
34
|
+
def run_command(*args):
|
|
35
|
+
proc=subprocess.run([executable(),*map(str,args)],capture_output=True,text=True,timeout=90)
|
|
36
|
+
if proc.returncode:raise RuntimeError(proc.stderr.strip()[:400] or 'VBoxManage command failed')
|
|
37
|
+
return proc.stdout
|
|
38
|
+
|
|
39
|
+
def event(run_id,kind,payload):
|
|
40
|
+
with connect() as db:db.execute('INSERT INTO events(run_id,kind,created_at,payload_json) VALUES(?,?,?,?)',(run_id,kind,now(),json.dumps(payload)))
|
|
41
|
+
|
|
42
|
+
def row(run_id):
|
|
43
|
+
with connect() as db:r=db.execute('SELECT * FROM runs WHERE id=?',(run_id,)).fetchone()
|
|
44
|
+
if not r:raise ValueError('Unknown run id')
|
|
45
|
+
return dict(r)
|
|
46
|
+
|
|
47
|
+
def add_artifact(run_id,kind,path):
|
|
48
|
+
path=Path(path).resolve();size=path.stat().st_size
|
|
49
|
+
if not path.is_relative_to(data_root()/'runs'/run_id):raise ValueError('Artifact outside selected run')
|
|
50
|
+
with connect() as db:
|
|
51
|
+
db.execute('INSERT OR REPLACE INTO artifacts(run_id,kind,path,created_at,bytes) VALUES(?,?,?,?,?)',(run_id,kind,str(path),now(),size))
|
|
52
|
+
return {'kind':kind,'path':str(path),'bytes':size}
|
|
53
|
+
|
|
54
|
+
def capture(run_id,label='screen',run=run_command):
|
|
55
|
+
item=row(run_id)
|
|
56
|
+
if not label.replace('-','').replace('_','').isalnum():raise ValueError('Invalid screenshot label')
|
|
57
|
+
folder=data_root()/'runs'/run_id;folder.mkdir(parents=True,exist_ok=True)
|
|
58
|
+
path=folder/(label+'-'+uuid.uuid4().hex[:6]+'.png')
|
|
59
|
+
run('controlvm',item['vm'],'screenshotpng',path)
|
|
60
|
+
return add_artifact(run_id,'screenshot',path)
|
|
61
|
+
|
|
62
|
+
def begin(vm,video=False,run=run_command):
|
|
63
|
+
info=parse(run('showvminfo',vm,'--machinereadable'))
|
|
64
|
+
if info.get('VMState')!='running':raise ValueError('Observation requires a running VM; no implicit startup')
|
|
65
|
+
run_id=uuid.uuid4().hex[:16];folder=data_root()/'runs'/run_id;folder.mkdir(parents=True)
|
|
66
|
+
if video and (info.get('recording_started')=='on' or info.get('recording')=='on'):raise ValueError('VM is already recording; do not replace another recording')
|
|
67
|
+
with connect() as db:db.execute('INSERT INTO runs VALUES(?,?,?,?,?,?,?)',(run_id,vm,'running',now(),None,None,None))
|
|
68
|
+
result={'status':'running','run_id':run_id,'vm':vm,'database':str(data_root()/'history.sqlite3'),'video_started':False}
|
|
69
|
+
try:
|
|
70
|
+
if video:
|
|
71
|
+
for setting,value in [('filename',folder/'screen.webm'),('videofps','5'),('maxtime','180'),('maxfilesize','20'),('opts','vc_enabled=true,ac_enabled=false')]:
|
|
72
|
+
run('controlvm',vm,'recording',setting,value)
|
|
73
|
+
run('controlvm',vm,'recording','videores',640,360)
|
|
74
|
+
run('controlvm',vm,'recording','on')
|
|
75
|
+
state=parse(run('showvminfo',vm,'--machinereadable'))
|
|
76
|
+
if state.get('recording_started')=='off':run('controlvm',vm,'recording','start')
|
|
77
|
+
result['video_started']=True
|
|
78
|
+
event(run_id,'start',{'video_started':result['video_started'],'video_limits':{'width':640,'height':360,'fps':5,'seconds':180,'max_mb':20}})
|
|
79
|
+
try:result['start_screenshot']=capture(run_id,'start',run)
|
|
80
|
+
except Exception as exc:event(run_id,'capture_error',{'error':str(exc)[:300]})
|
|
81
|
+
return result
|
|
82
|
+
except Exception as exc:
|
|
83
|
+
# If recording started but later initialization fails, stop our own recording.
|
|
84
|
+
if result['video_started']:
|
|
85
|
+
try:run('controlvm',vm,'recording','off')
|
|
86
|
+
except Exception:pass
|
|
87
|
+
with connect() as db:db.execute('UPDATE runs SET status=?,finished_at=?,error_summary=? WHERE id=?',('failed',now(),str(exc)[:400],run_id))
|
|
88
|
+
raise
|
|
89
|
+
|
|
90
|
+
def end(run_id,robot_status='completed',run=run_command):
|
|
91
|
+
item=row(run_id)
|
|
92
|
+
if item['status']!='running':return {'status':item['status'],'run_id':run_id,'already_finished':True}
|
|
93
|
+
with connect() as db:
|
|
94
|
+
start=db.execute("SELECT payload_json FROM events WHERE run_id=? AND kind='start' ORDER BY id LIMIT 1",(run_id,)).fetchone()
|
|
95
|
+
if start and json.loads(start[0]).get('video_started'):
|
|
96
|
+
try:run('controlvm',item['vm'],'recording','stop')
|
|
97
|
+
except Exception as exc:event(run_id,'recording_stop_notice',{'error':str(exc)[:300]})
|
|
98
|
+
try:run('controlvm',item['vm'],'recording','off')
|
|
99
|
+
except Exception as exc:event(run_id,'recording_stop_error',{'error':str(exc)[:300]})
|
|
100
|
+
time.sleep(.3)
|
|
101
|
+
try:capture(run_id,'end',run)
|
|
102
|
+
except Exception as exc:event(run_id,'capture_error',{'error':str(exc)[:300]})
|
|
103
|
+
videos=list((data_root()/'runs'/run_id).glob('*.webm'))+list((data_root()/'runs'/run_id).glob('*.mkv'))
|
|
104
|
+
for video in videos:
|
|
105
|
+
if video.stat().st_size:add_artifact(run_id,'video',video)
|
|
106
|
+
with connect() as db:db.execute('UPDATE runs SET status=?,finished_at=?,robot_status=? WHERE id=?',('finished',now(),robot_status,run_id))
|
|
107
|
+
event(run_id,'end',{'robot_status':robot_status})
|
|
108
|
+
return detail(run_id)
|
|
109
|
+
|
|
110
|
+
def detail(run_id):
|
|
111
|
+
item=row(run_id)
|
|
112
|
+
with connect() as db:
|
|
113
|
+
item['artifact_count']=db.execute('SELECT count(*) FROM artifacts WHERE run_id=?',(run_id,)).fetchone()[0]
|
|
114
|
+
item['artifacts']=[dict(r) for r in db.execute('SELECT * FROM artifacts WHERE run_id=? ORDER BY id DESC LIMIT 30',(run_id,))]
|
|
115
|
+
initial=db.execute("SELECT payload_json FROM events WHERE run_id=? AND kind='start' ORDER BY id LIMIT 1",(run_id,)).fetchone()
|
|
116
|
+
item['video_requested']=bool(initial and json.loads(initial[0]).get('video_started'))
|
|
117
|
+
item['video_saved']=db.execute("SELECT count(*) FROM artifacts WHERE run_id=? AND kind='video' AND bytes>0",(run_id,)).fetchone()[0]>0
|
|
118
|
+
item['evidence_status']='video_saved' if item['video_saved'] else ('video_missing' if item['video_requested'] else 'screenshots_only')
|
|
119
|
+
item['events']=[dict(r) for r in db.execute('SELECT * FROM events WHERE run_id=? ORDER BY id DESC LIMIT 30',(run_id,))]
|
|
120
|
+
return item
|
|
121
|
+
|
|
122
|
+
def listing(limit=20):
|
|
123
|
+
if not 1<=limit<=100:raise ValueError('History limit must be 1-100')
|
|
124
|
+
with connect() as db:runs=[dict(r) for r in db.execute('SELECT * FROM runs ORDER BY started_at DESC LIMIT ?',(limit,))]
|
|
125
|
+
return {'status':'observed','database':str(data_root()/'history.sqlite3'),'runs':runs}
|
|
126
|
+
|
|
127
|
+
def artifact(artifact_id):
|
|
128
|
+
with connect() as db:r=db.execute('SELECT * FROM artifacts WHERE id=?',(artifact_id,)).fetchone()
|
|
129
|
+
if not r:raise ValueError('Unknown artifact id')
|
|
130
|
+
item=dict(r);path=Path(item['path']).resolve()
|
|
131
|
+
if not path.is_relative_to(data_root()/'runs'/item['run_id']) or not path.is_file():raise ValueError('Artifact unavailable')
|
|
132
|
+
return item
|
|
133
|
+
|
|
134
|
+
if __name__=='__main__':
|
|
135
|
+
try:
|
|
136
|
+
args=json.load(sys.stdin);op=args.pop('action','list')
|
|
137
|
+
functions={'begin':begin,'end':end,'capture':capture,'list':listing,'detail':detail,'artifact':artifact}
|
|
138
|
+
print(json.dumps(functions[op](**args)))
|
|
139
|
+
except Exception as exc:print(json.dumps({'status':'failed','error':str(exc)}));sys.exit(1)
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Adapt zero-based screenshot pixels to VirtualBox's one-based absolute mouse API.
|
|
3
|
-
Delegates to the preserved MIT chryaner/mcp-virtualbox helper.
|
|
4
|
-
"""
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
import runpy
|
|
7
|
-
import sys
|
|
8
|
-
|
|
9
|
-
if __name__=='__main__':
|
|
10
|
-
if len(sys.argv)<4:raise SystemExit('Expected VM x y [button]')
|
|
11
|
-
for index in (2,3):
|
|
12
|
-
coordinate=int(sys.argv[index])
|
|
13
|
-
if coordinate<0:raise SystemExit('Guest coordinates must be non-negative')
|
|
14
|
-
sys.argv[index]=str(coordinate+1)
|
|
15
|
-
runpy.run_path(str(Path(__file__).resolve().parents[2]/'third_party/mcp-virtualbox/scripts/mouse_click.py'),run_name='__main__')
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Adapt zero-based screenshot pixels to VirtualBox's one-based absolute mouse API.
|
|
3
|
+
Delegates to the preserved MIT chryaner/mcp-virtualbox helper.
|
|
4
|
+
"""
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import runpy
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
if __name__=='__main__':
|
|
10
|
+
if len(sys.argv)<4:raise SystemExit('Expected VM x y [button]')
|
|
11
|
+
for index in (2,3):
|
|
12
|
+
coordinate=int(sys.argv[index])
|
|
13
|
+
if coordinate<0:raise SystemExit('Guest coordinates must be non-negative')
|
|
14
|
+
sys.argv[index]=str(coordinate+1)
|
|
15
|
+
runpy.run_path(str(Path(__file__).resolve().parents[2]/'third_party/mcp-virtualbox/scripts/mouse_click.py'),run_name='__main__')
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Move the guest USB tablet through the matching VirtualBox SDK, without clicking."""
|
|
3
|
-
import argparse
|
|
4
|
-
|
|
5
|
-
def move(vm, x, y):
|
|
6
|
-
if x < 0 or y < 0: raise ValueError('Guest coordinates must be non-negative')
|
|
7
|
-
from vboxapi import VirtualBoxManager
|
|
8
|
-
manager=VirtualBoxManager(None,None)
|
|
9
|
-
vbox=manager.getVirtualBox();session=manager.getSessionObject(vbox)
|
|
10
|
-
vbox.findMachine(vm).lockMachine(session,manager.constants.LockType_Shared)
|
|
11
|
-
try:
|
|
12
|
-
mouse=session.console.mouse
|
|
13
|
-
if not mouse.absoluteSupported:raise RuntimeError('Guest has no absolute pointing device')
|
|
14
|
-
mouse.putMouseEventAbsolute(x+1,y+1,0,0,0)
|
|
15
|
-
finally:session.unlockMachine()
|
|
16
|
-
|
|
17
|
-
if __name__=='__main__':
|
|
18
|
-
p=argparse.ArgumentParser();p.add_argument('vm');p.add_argument('x',type=int);p.add_argument('y',type=int);a=p.parse_args();move(a.vm,a.x,a.y)
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Move the guest USB tablet through the matching VirtualBox SDK, without clicking."""
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
def move(vm, x, y):
|
|
6
|
+
if x < 0 or y < 0: raise ValueError('Guest coordinates must be non-negative')
|
|
7
|
+
from vboxapi import VirtualBoxManager
|
|
8
|
+
manager=VirtualBoxManager(None,None)
|
|
9
|
+
vbox=manager.getVirtualBox();session=manager.getSessionObject(vbox)
|
|
10
|
+
vbox.findMachine(vm).lockMachine(session,manager.constants.LockType_Shared)
|
|
11
|
+
try:
|
|
12
|
+
mouse=session.console.mouse
|
|
13
|
+
if not mouse.absoluteSupported:raise RuntimeError('Guest has no absolute pointing device')
|
|
14
|
+
mouse.putMouseEventAbsolute(x+1,y+1,0,0,0)
|
|
15
|
+
finally:session.unlockMachine()
|
|
16
|
+
|
|
17
|
+
if __name__=='__main__':
|
|
18
|
+
p=argparse.ArgumentParser();p.add_argument('vm');p.add_argument('x',type=int);p.add_argument('y',type=int);a=p.parse_args();move(a.vm,a.x,a.y)
|