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.
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 +310 -93
- 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 -197
- 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 +288 -237
- 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 +50 -3
- package/runtime/guest_setup/http/postwin.ps1 +53 -28
- package/runtime/guest_setup/http/setup-all.ps1 +25 -25
- package/runtime/guest_setup/http/setup-win.cmd +7 -7
- package/runtime/guest_setup/http/setup.ps1 +44 -29
- package/runtime/guest_setup/kvm/setup-windows.ps1 +52 -52
- package/runtime/guest_setup/recorder/README.txt +12 -12
- 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/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 -53
- package/runtime/guest_setup/recorder/setup-win.cmd +4 -60
- package/runtime/guest_setup/recorder/setup.ps1 +112 -81
- package/runtime/guest_setup/recorder/setup.sh +1 -0
- 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 -2
- package/runtime/guest_setup/setup-all.ps1 +35 -35
- package/runtime/guest_setup/vault/Install-VCRuntime.ps1 +26 -26
- package/runtime/guest_setup/vault/setup-guest-vault.ps1 +148 -148
- 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 +0 -0
- package/runtime/scripts/script_server.py +571 -517
- 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/package.json
CHANGED
|
@@ -1,17 +1,51 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vamp-mcp",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
5
|
-
"type": "module",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"author": "wayfarer6",
|
|
8
|
-
"repository": {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "vamp-mcp",
|
|
3
|
+
"version": "0.2.4",
|
|
4
|
+
"description": "Packer-powered VM installation, post-install setup, golden image management and GUI automation over MCP for VirtualBox, KVM and Hyper-V.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "wayfarer6",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/wayfarer6/vamp-mcp.git",
|
|
11
|
+
"directory": "npm-package"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/wayfarer6/vamp-mcp#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/wayfarer6/vamp-mcp/issues"
|
|
16
|
+
},
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=22"
|
|
19
|
+
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"vamp-mcp": "bin/vamp-mcp.mjs"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"bin/",
|
|
25
|
+
"runtime/",
|
|
26
|
+
"notices/",
|
|
27
|
+
"LICENSE",
|
|
28
|
+
"THIRD_PARTY_NOTICES.md",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"keywords": [
|
|
32
|
+
"mcp",
|
|
33
|
+
"virtualbox",
|
|
34
|
+
"kvm",
|
|
35
|
+
"virtual-machine",
|
|
36
|
+
"rpa",
|
|
37
|
+
"automation",
|
|
38
|
+
"stdio",
|
|
39
|
+
"packer",
|
|
40
|
+
"golden-image"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "node build.mjs",
|
|
44
|
+
"prepack": "npm run build",
|
|
45
|
+
"test": "node --test test/package.test.mjs"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public",
|
|
49
|
+
"registry": "https://registry.npmjs.org/"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
param([Parameter(Mandatory=$true)][string]$EnvironmentPath)
|
|
2
|
-
$ErrorActionPreference='Stop'
|
|
3
|
-
. (Join-Path $EnvironmentPath 'Scripts\Activate.ps1')
|
|
4
|
-
$code='import sys,os,json,importlib.metadata as m; from pathlib import Path; import mcp,robot,pycdlib,asyncvnc; expected=Path(sys.argv[1]).resolve(); assert Path(sys.prefix).resolve()==expected and sys.prefix!=sys.base_prefix; assert Path(os.environ["VIRTUAL_ENV"]).resolve()==expected; print(json.dumps({"status":"ready","activated":True,"python":sys.executable,"version":sys.version.split()[0],"packages":{n:m.version(n) for n in ["mcp","robotframework","pycdlib","asyncvnc"]}}))'
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
param([Parameter(Mandatory=$true)][string]$EnvironmentPath)
|
|
2
|
+
$ErrorActionPreference='Stop'
|
|
3
|
+
. (Join-Path $EnvironmentPath 'Scripts\Activate.ps1')
|
|
4
|
+
$code='import sys,os,json,importlib.metadata as m; from pathlib import Path; import mcp,robot,pycdlib,asyncvnc; expected=Path(sys.argv[1]).resolve(); assert Path(sys.prefix).resolve()==expected and sys.prefix!=sys.base_prefix; assert Path(os.environ["VIRTUAL_ENV"]).resolve()==expected; print(json.dumps({"status":"ready","activated":True,"python":sys.executable,"version":sys.version.split()[0],"packages":{n:m.version(n) for n in ["mcp","robotframework","pycdlib","asyncvnc"]}}))'
|
|
5
|
+
# stdin avoids Windows PowerShell 5.1 stripping quotes from native -c arguments.
|
|
6
|
+
$code | & (Join-Path $EnvironmentPath 'Scripts\python.exe') - $EnvironmentPath
|
|
7
|
+
if($LASTEXITCODE -ne 0){throw 'Activated environment failed its import or interpreter check'}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema_version": 1,
|
|
3
|
+
"boot_wait_seconds": 10,
|
|
4
|
+
"script_server_port": 8421,
|
|
5
|
+
"hosts": {
|
|
6
|
+
"virtualbox": [
|
|
7
|
+
"win32",
|
|
8
|
+
"linux",
|
|
9
|
+
"darwin"
|
|
10
|
+
],
|
|
11
|
+
"hyperv": [
|
|
12
|
+
"win32"
|
|
13
|
+
],
|
|
14
|
+
"kvm": [
|
|
15
|
+
"linux"
|
|
16
|
+
],
|
|
17
|
+
"apple-hypervisor": [
|
|
18
|
+
"darwin"
|
|
19
|
+
]
|
|
20
|
+
},
|
|
21
|
+
"amd64_install_host_arches": [
|
|
22
|
+
"x64",
|
|
23
|
+
"AMD64",
|
|
24
|
+
"x86_64"
|
|
25
|
+
],
|
|
26
|
+
"debian": {
|
|
27
|
+
"cfg": "debian-preseed.cfg",
|
|
28
|
+
"efi_boot": [
|
|
29
|
+
{
|
|
30
|
+
"kind": "text",
|
|
31
|
+
"text": "c"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"kind": "wait",
|
|
35
|
+
"seconds": 1
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"kind": "line",
|
|
39
|
+
"text": "linux /install.amd/vmlinuz auto=true priority=critical preseed/url={base_url}/debian-preseed.cfg vamp_base={base_url} --- quiet"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"kind": "line",
|
|
43
|
+
"text": "initrd /install.amd/initrd.gz"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"kind": "line",
|
|
47
|
+
"text": "boot"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"windows11": {
|
|
52
|
+
"efi_boot": [
|
|
53
|
+
{
|
|
54
|
+
"kind": "enter"
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Host-independent installer policy shared by MCP and VSIX runtimes.
|
|
2
|
+
|
|
3
|
+
This module builds plans and renders configuration; it never starts a VM or
|
|
4
|
+
injects input. Backend adapters execute plans using their native APIs.
|
|
5
|
+
"""
|
|
6
|
+
import json
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import platform
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
ROOT=Path(__file__).resolve().parents[2]
|
|
12
|
+
HOST_ARCH=platform.machine()
|
|
13
|
+
PROFILE=json.loads(Path(__file__).with_name('guest-install.json').read_text())
|
|
14
|
+
|
|
15
|
+
def require_install_host(backend, host=None, architecture=None):
|
|
16
|
+
host=host or sys.platform
|
|
17
|
+
architecture=architecture or HOST_ARCH
|
|
18
|
+
if host not in PROFILE['hosts'].get(backend,[]):
|
|
19
|
+
raise ValueError(f'{backend} local installation is unsupported on {host}')
|
|
20
|
+
if architecture not in PROFILE['amd64_install_host_arches']:
|
|
21
|
+
raise ValueError(f'Current amd64 installer profiles require an x64 host; {architecture} is unsupported')
|
|
22
|
+
|
|
23
|
+
def efi_boot_plan(guest_os, base_url):
|
|
24
|
+
if guest_os not in ('debian','windows11'):
|
|
25
|
+
raise ValueError('No automatic EFI boot profile for '+guest_os)
|
|
26
|
+
return [dict(step,**({'text':step['text'].format(base_url=base_url.rstrip('/'))} if 'text' in step else {}))
|
|
27
|
+
for step in PROFILE[guest_os]['efi_boot']]
|
|
28
|
+
|
|
29
|
+
def post_create_notice(guest_os, base_url):
|
|
30
|
+
"""The same user-facing handoff is returned to MCP and rendered by VSIX."""
|
|
31
|
+
base_url=base_url.rstrip('/')
|
|
32
|
+
windows=guest_os=='windows11'
|
|
33
|
+
return {
|
|
34
|
+
'title':'Warning: Verify post-install setup after first login.',
|
|
35
|
+
'message':'Log in after OS installation. Guest setup downloads and runs automatically. If it fails or does not start, run the recovery command below inside the guest. Do not suspend or lock the VM until setup completes. Setup disables automatic sleep and screen locking.',
|
|
36
|
+
'setup_command':f'powershell -NoProfile -ExecutionPolicy Unrestricted -Command "irm {base_url}/setup.ps1 | iex"' if windows else f'wget -qO /tmp/vamp-setup.sh {base_url}/setup.sh && sh /tmp/vamp-setup.sh --base={base_url}',
|
|
37
|
+
'resolution_reset':{'windows_desktop':'Set-Resolution-1920x1080.cmd','windows_powershell':'Set-Resolution-1920x1080.ps1','debian_home':'~/set-resolution-1920x1080.sh'},
|
|
38
|
+
'resolution_note':'Windows Desktop: double-click Set-Resolution-1920x1080.cmd if the display drifts. Before automation, set Windows Settings > System > Display to 1920x1080 and Scale 100%. Open the resolution guide in VM Manager if this mode is unavailable.' if windows else 'Debian home folder: run ~/set-resolution-1920x1080.sh if the display drifts. Debian may not keep 1920x1080. After setup, run this command in a GNOME Xorg terminal. If the mode is unavailable, check Guest Additions and guest display settings.',
|
|
39
|
+
'resolution_command':None if windows else 'xrandr --output "$(xrandr --query | awk \'/ connected/{print $1; exit}\')" --mode 1920x1080',
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
def virtualbox_preseed():
|
|
43
|
+
# One Debian policy source; only account substitution and the native late
|
|
44
|
+
# command differ for VirtualBox's built-in unattended installer.
|
|
45
|
+
source=(ROOT/'guest_setup/http/debian-preseed.cfg').read_text()
|
|
46
|
+
substitutions={
|
|
47
|
+
'd-i netcfg/get_hostname':'d-i netcfg/get_hostname string @@VBOX_INSERT_HOSTNAME_WITHOUT_DOMAIN@@',
|
|
48
|
+
'd-i passwd/user-fullname':'d-i passwd/user-fullname string @@VBOX_INSERT_USER_FULL_NAME@@',
|
|
49
|
+
'd-i passwd/username':'d-i passwd/username string @@VBOX_INSERT_USER_LOGIN@@',
|
|
50
|
+
'd-i preseed/late_command':'d-i preseed/late_command string cp /cdrom/vboxpostinstall.sh /target/root/vboxpostinstall.sh && chmod +x /target/root/vboxpostinstall.sh && /bin/sh /target/root/vboxpostinstall.sh --need-target-bash --preseed-late-command',
|
|
51
|
+
}
|
|
52
|
+
lines=[]
|
|
53
|
+
for line in source.splitlines():
|
|
54
|
+
if line.startswith('d-i passwd/user-password'):continue
|
|
55
|
+
lines.append(next((value for key,value in substitutions.items() if line.startswith(key+' ')),line))
|
|
56
|
+
lines.append('d-i passwd/user-password-crypted password @@VBOX_INSERT_USER_PASSWORD_SHACRYPT512@@')
|
|
57
|
+
return '\n'.join(lines)+'\n'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// No hypervisor commands here: host capability policy shared by UI adapters.
|
|
2
|
+
const profile=require('./guest-install.json');
|
|
3
|
+
function requireBackendHost(backend,platform=process.platform){
|
|
4
|
+
if(!profile.hosts[backend]?.includes(platform))throw Error(`${backend} local management is unsupported on ${platform}`);
|
|
5
|
+
}
|
|
6
|
+
function requireInstallHost(backend,platform=process.platform,architecture=process.arch){
|
|
7
|
+
requireBackendHost(backend,platform);
|
|
8
|
+
if(!profile.amd64_install_host_arches.includes(architecture))throw Error(`Current amd64 installer profiles require an x64 host; ${architecture} is unsupported`);
|
|
9
|
+
}
|
|
10
|
+
function backendCapabilities(platform=process.platform){
|
|
11
|
+
return Object.fromEntries(Object.entries(profile.hosts).map(([backend,hosts])=>[backend,{
|
|
12
|
+
hostSupported:hosts.includes(platform),implemented:backend!=='apple-hypervisor',
|
|
13
|
+
reason:!hosts.includes(platform)?'unsupported_host':backend==='apple-hypervisor'?'not_implemented':null,
|
|
14
|
+
}]));
|
|
15
|
+
}
|
|
16
|
+
module.exports={requireBackendHost,requireInstallHost,backendCapabilities};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const path=require('node:path');
|
|
2
|
+
const {execFile}=require('node:child_process');
|
|
3
|
+
function packer({runtime,python=()=>process.env.RPA_HOST_PYTHON||(process.platform==='win32'?'python':'python3'),spawn=execFile}={}){
|
|
4
|
+
return function call(action,{backend='virtualbox',id,confirmed=false,...request}={}){
|
|
5
|
+
const args=[path.join(runtime,'backends/packer/runner.py'),action,'--backend',backend];
|
|
6
|
+
if(id)args.push('--id',id);if(confirmed)args.push('--confirmed');
|
|
7
|
+
return new Promise((resolve,reject)=>{
|
|
8
|
+
const child=spawn(typeof python==='function'?python():python,args,{windowsHide:true,timeout:600000,maxBuffer:4*1024**2},(error,stdout,stderr)=>{
|
|
9
|
+
let data;try{data=JSON.parse(stdout);}catch{}
|
|
10
|
+
if(error||data?.status==='failed')reject(Error(data?.error||stderr||error?.message||'Packer response was invalid'));else resolve(data);
|
|
11
|
+
});
|
|
12
|
+
child.stdin.on('error',()=>{});child.stdin.end(action==='create'?JSON.stringify({backend,...request}):'');
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
module.exports={packer};
|
|
@@ -1,67 +1,40 @@
|
|
|
1
|
-
# Local UI lifecycle API. No generic PowerShell execution or embedded display.
|
|
2
|
-
param([Parameter(Mandatory=$true)][string]$RequestBase64,[Parameter(Mandatory=$true)][string]$StoragePath)
|
|
3
|
-
$ErrorActionPreference='Stop'
|
|
4
|
-
Import-Module Hyper-V -ErrorAction Stop
|
|
5
|
-
$request=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($RequestBase64)) | ConvertFrom-Json
|
|
6
|
-
function Get-ManagedRecord([string]$Id) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
$
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
$
|
|
27
|
-
|
|
28
|
-
$
|
|
29
|
-
if($
|
|
30
|
-
$
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
$switch=Get-VMSwitch | Where-Object Name -eq 'Default Switch' | Select-Object -First 1
|
|
42
|
-
if($switch){Connect-VMNetworkAdapter -VMName $name -SwitchName $switch.Name}
|
|
43
|
-
if($request.guest_os -eq 'windows11'){
|
|
44
|
-
Set-VMKeyProtector -VM $vm -NewLocalKeyProtector
|
|
45
|
-
Enable-VMTPM -VM $vm
|
|
46
|
-
} else {Set-VMFirmware -VM $vm -EnableSecureBoot Off}
|
|
47
|
-
$dvd=Add-VMDvdDrive -VM $vm -Path $iso -Passthru
|
|
48
|
-
Set-VMFirmware -VM $vm -FirstBootDevice $dvd
|
|
49
|
-
Start-VM -VM $vm
|
|
50
|
-
@{status='installation_started';installation_mode='manual';id=$vm.Id.ToString();vm=$name;embedded_display_supported=$false;network_connected=[bool]$switch} | ConvertTo-Json -Compress
|
|
51
|
-
}
|
|
52
|
-
{$_ -in 'start','stop','delete'} {
|
|
53
|
-
$id=[guid]$request.id
|
|
54
|
-
$vm=Get-VM -Id $id
|
|
55
|
-
if($request.action -eq 'start'){Start-VM -VM $vm}
|
|
56
|
-
if($request.action -eq 'stop'){Stop-VM -VM $vm -Confirm:$false}
|
|
57
|
-
if($request.action -eq 'delete'){
|
|
58
|
-
if([string]$vm.State -ne 'Off'){throw 'Shut down the VM before deleting it'}
|
|
59
|
-
$record=Get-ManagedRecord $id.ToString()
|
|
60
|
-
if(-not $record){throw 'Only desktops created by VAMP can be deleted here'}
|
|
61
|
-
Remove-VM -VM $vm -Force
|
|
62
|
-
Remove-Item -LiteralPath $record.folder -Recurse -Force
|
|
63
|
-
}
|
|
64
|
-
@{status='requested'} | ConvertTo-Json -Compress
|
|
65
|
-
}
|
|
66
|
-
default {throw 'Unsupported desktop action'}
|
|
67
|
-
}
|
|
1
|
+
# Local UI lifecycle API. No generic PowerShell execution or embedded display.
|
|
2
|
+
param([Parameter(Mandatory=$true)][string]$RequestBase64,[Parameter(Mandatory=$true)][string]$StoragePath,[string]$LegacyStoragePath)
|
|
3
|
+
$ErrorActionPreference='Stop'
|
|
4
|
+
Import-Module Hyper-V -ErrorAction Stop
|
|
5
|
+
$request=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($RequestBase64)) | ConvertFrom-Json
|
|
6
|
+
function Get-ManagedRecord([string]$Id) {
|
|
7
|
+
foreach($root in @($StoragePath,$LegacyStoragePath)){
|
|
8
|
+
if(-not $root -or -not(Test-Path -LiteralPath $root)){continue}
|
|
9
|
+
foreach($file in Get-ChildItem -LiteralPath $root -Filter vamp-ui.json -Recurse -File){
|
|
10
|
+
$item=Get-Content -LiteralPath $file.FullName -Raw | ConvertFrom-Json
|
|
11
|
+
if($item.id -eq $Id){return @{item=$item;folder=$file.DirectoryName;root=$root}}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return $null
|
|
15
|
+
}
|
|
16
|
+
switch($request.action){
|
|
17
|
+
'check' { Get-VMHost | Out-Null; @{status='ready'} | ConvertTo-Json -Compress }
|
|
18
|
+
'list' {
|
|
19
|
+
$rows=@(Get-VM | ForEach-Object {
|
|
20
|
+
@{id=$_.Id.ToString();name=$_.Name;state=@{Running='running';Off='poweroff';Saved='saved';Paused='paused'}[[string]$_.State];memory=[int]($_.MemoryStartup/1MB);cpus=$_.ProcessorCount;backend='hyperv';managed=[bool](Get-ManagedRecord $_.Id.ToString())}
|
|
21
|
+
})
|
|
22
|
+
@{vms=$rows} | ConvertTo-Json -Depth 6 -Compress
|
|
23
|
+
}
|
|
24
|
+
'create' { throw 'VM installation uses backends/packer/runner.py; direct installation is retired' }
|
|
25
|
+
{$_ -in 'start','stop','delete'} {
|
|
26
|
+
$id=[guid]$request.id
|
|
27
|
+
$vm=Get-VM -Id $id
|
|
28
|
+
if($request.action -eq 'start'){Start-VM -VM $vm}
|
|
29
|
+
if($request.action -eq 'stop'){Stop-VM -VM $vm -Confirm:$false}
|
|
30
|
+
if($request.action -eq 'delete'){
|
|
31
|
+
if([string]$vm.State -ne 'Off'){throw 'Shut down the VM before deleting it'}
|
|
32
|
+
$record=Get-ManagedRecord $id.ToString()
|
|
33
|
+
if(-not $record){throw 'Only desktops created by VAMP can be deleted here'}
|
|
34
|
+
Remove-VM -VM $vm -Force
|
|
35
|
+
Remove-Item -LiteralPath $record.folder -Recurse -Force
|
|
36
|
+
}
|
|
37
|
+
@{status='requested'} | ConvertTo-Json -Compress
|
|
38
|
+
}
|
|
39
|
+
default {throw 'Unsupported desktop action'}
|
|
40
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Hyper-V synthetic keyboard adapter; never sends input to host windows.
|
|
2
|
+
function Invoke-HyperVInstallerBoot {
|
|
3
|
+
param($VM,[string]$GuestOS,[string]$BaseUrl)
|
|
4
|
+
$profile=Get-Content -LiteralPath (Join-Path $PSScriptRoot '../../common/guest-install.json') -Raw | ConvertFrom-Json
|
|
5
|
+
Start-Sleep -Seconds $profile.boot_wait_seconds
|
|
6
|
+
# Synthetic keyboard targets this VM directly, without host window focus.
|
|
7
|
+
$system=Get-CimInstance -Namespace root/virtualization/v2 -ClassName Msvm_ComputerSystem -Filter ("Name='"+$VM.Id.ToString()+"'")
|
|
8
|
+
$keyboard=Get-CimAssociatedInstance -InputObject $system -ResultClassName Msvm_Keyboard
|
|
9
|
+
if(-not $keyboard){throw 'Hyper-V synthetic keyboard unavailable; inspect VMConnect'}
|
|
10
|
+
function Send-Text([string]$Text){
|
|
11
|
+
$r=Invoke-CimMethod -InputObject $keyboard -MethodName TypeText -Arguments @{asciiText=$Text}
|
|
12
|
+
if($r.ReturnValue -ne 0){throw 'Hyper-V keyboard text dispatch failed'}
|
|
13
|
+
}
|
|
14
|
+
function Send-Enter {
|
|
15
|
+
$r=Invoke-CimMethod -InputObject $keyboard -MethodName TypeKey -Arguments @{keyCode=[uint32]13}
|
|
16
|
+
if($r.ReturnValue -ne 0){throw 'Hyper-V Enter dispatch failed'}
|
|
17
|
+
}
|
|
18
|
+
if($GuestOS -eq 'debian'){
|
|
19
|
+
foreach($step in $profile.debian.efi_boot){
|
|
20
|
+
if($step.kind -eq 'wait'){Start-Sleep -Seconds $step.seconds}
|
|
21
|
+
if($step.kind -in 'text','line'){Send-Text ($step.text.Replace('{base_url}',$BaseUrl))}
|
|
22
|
+
if($step.kind -in 'line','enter'){Send-Enter}
|
|
23
|
+
}
|
|
24
|
+
} else {Send-Enter}
|
|
25
|
+
}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
d-i debian-installer/locale string en_US.UTF-8
|
|
2
|
-
d-i keyboard-configuration/xkb-keymap select us
|
|
3
|
-
d-i netcfg/choose_interface select auto
|
|
4
|
-
d-i netcfg/get_hostname string vamp-desktop
|
|
5
|
-
d-i netcfg/get_domain string local
|
|
6
|
-
d-i mirror/country string manual
|
|
7
|
-
d-i mirror/http/hostname string deb.debian.org
|
|
8
|
-
d-i mirror/http/directory string /debian
|
|
9
|
-
d-i mirror/http/proxy string
|
|
10
|
-
d-i passwd/root-login boolean false
|
|
11
|
-
d-i passwd/user-fullname string VAMP Test
|
|
12
|
-
d-i passwd/username string vboxuser
|
|
13
|
-
d-i passwd/user-password password password123!
|
|
14
|
-
d-i passwd/user-password-again password password123!
|
|
15
|
-
d-i clock-setup/utc boolean true
|
|
16
|
-
d-i time/zone string Asia/Seoul
|
|
17
|
-
d-i clock-setup/ntp boolean false
|
|
18
|
-
d-i partman-auto/method string regular
|
|
19
|
-
d-i partman-auto/choose_recipe select atomic
|
|
20
|
-
d-i partman-partitioning/confirm_write_new_label boolean true
|
|
21
|
-
d-i partman/choose_partition select finish
|
|
22
|
-
d-i partman/confirm boolean true
|
|
23
|
-
d-i partman/confirm_nooverwrite boolean true
|
|
24
|
-
d-i apt-setup/cdrom/set-first boolean false
|
|
25
|
-
d-i apt-setup/disable-cdrom-entries boolean true
|
|
26
|
-
d-i apt-setup/use_mirror boolean true
|
|
27
|
-
d-i pkgsel/run_tasksel boolean false
|
|
28
|
-
d-i pkgsel/include string qemu-guest-agent sudo python3 xserver-xorg lightdm lightdm-gtk-greeter openbox xterm firefox-esr fonts-dejavu dbus-x11 x11-xserver-utils
|
|
29
|
-
d-i pkgsel/upgrade select none
|
|
30
|
-
popularity-contest popularity-contest/participate boolean false
|
|
31
|
-
d-i grub-installer/only_debian boolean true
|
|
32
|
-
d-i grub-installer/bootdev string default
|
|
33
|
-
d-i preseed/late_command string mkdir -p /target/etc/lightdm/lightdm.conf.d /target/home/vboxuser/.config/openbox; printf '[Seat:*]\nautologin-user=vboxuser\nautologin-user-timeout=0\nuser-session=openbox\n' > /target/etc/lightdm/lightdm.conf.d/50-vamp.conf; printf 'xrandr --output Virtual-1 --mode 1920x1080 || xrandr --output Virtual1 --mode 1920x1080 || true\nxset s off\nxset -dpms\nxterm -geometry 100x28+80+80 -fa Monospace -fs 18 -title VAMP-DESKTOP-READY &\n' > /target/home/vboxuser/.config/openbox/autostart; in-target chown -R vboxuser:vboxuser /home/vboxuser/.config; in-target systemctl enable lightdm; in-target systemctl set-default graphical.target; in-target touch /var/lib/vamp-debian-installed; echo VAMP-DEBIAN-INSTALL-COMPLETE > /dev/ttyS0 || true
|
|
34
|
-
d-i finish-install/reboot_in_progress note
|
|
35
|
-
d-i cdrom-detect/eject boolean true
|
|
1
|
+
d-i debian-installer/locale string en_US.UTF-8
|
|
2
|
+
d-i keyboard-configuration/xkb-keymap select us
|
|
3
|
+
d-i netcfg/choose_interface select auto
|
|
4
|
+
d-i netcfg/get_hostname string vamp-desktop
|
|
5
|
+
d-i netcfg/get_domain string local
|
|
6
|
+
d-i mirror/country string manual
|
|
7
|
+
d-i mirror/http/hostname string deb.debian.org
|
|
8
|
+
d-i mirror/http/directory string /debian
|
|
9
|
+
d-i mirror/http/proxy string
|
|
10
|
+
d-i passwd/root-login boolean false
|
|
11
|
+
d-i passwd/user-fullname string VAMP Test
|
|
12
|
+
d-i passwd/username string vboxuser
|
|
13
|
+
d-i passwd/user-password password password123!
|
|
14
|
+
d-i passwd/user-password-again password password123!
|
|
15
|
+
d-i clock-setup/utc boolean true
|
|
16
|
+
d-i time/zone string Asia/Seoul
|
|
17
|
+
d-i clock-setup/ntp boolean false
|
|
18
|
+
d-i partman-auto/method string regular
|
|
19
|
+
d-i partman-auto/choose_recipe select atomic
|
|
20
|
+
d-i partman-partitioning/confirm_write_new_label boolean true
|
|
21
|
+
d-i partman/choose_partition select finish
|
|
22
|
+
d-i partman/confirm boolean true
|
|
23
|
+
d-i partman/confirm_nooverwrite boolean true
|
|
24
|
+
d-i apt-setup/cdrom/set-first boolean false
|
|
25
|
+
d-i apt-setup/disable-cdrom-entries boolean true
|
|
26
|
+
d-i apt-setup/use_mirror boolean true
|
|
27
|
+
d-i pkgsel/run_tasksel boolean false
|
|
28
|
+
d-i pkgsel/include string qemu-guest-agent sudo python3 xserver-xorg lightdm lightdm-gtk-greeter openbox xterm firefox-esr fonts-dejavu dbus-x11 x11-xserver-utils
|
|
29
|
+
d-i pkgsel/upgrade select none
|
|
30
|
+
popularity-contest popularity-contest/participate boolean false
|
|
31
|
+
d-i grub-installer/only_debian boolean true
|
|
32
|
+
d-i grub-installer/bootdev string default
|
|
33
|
+
d-i preseed/late_command string mkdir -p /target/etc/lightdm/lightdm.conf.d /target/home/vboxuser/.config/openbox; printf '[Seat:*]\nautologin-user=vboxuser\nautologin-user-timeout=0\nuser-session=openbox\n' > /target/etc/lightdm/lightdm.conf.d/50-vamp.conf; printf 'xrandr --output Virtual-1 --mode 1920x1080 || xrandr --output Virtual1 --mode 1920x1080 || true\nxset s off\nxset -dpms\nxterm -geometry 100x28+80+80 -fa Monospace -fs 18 -title VAMP-DESKTOP-READY &\n' > /target/home/vboxuser/.config/openbox/autostart; in-target chown -R vboxuser:vboxuser /home/vboxuser/.config; in-target systemctl enable lightdm; in-target systemctl set-default graphical.target; in-target touch /var/lib/vamp-debian-installed; echo VAMP-DEBIAN-INSTALL-COMPLETE > /dev/ttyS0 || true
|
|
34
|
+
d-i finish-install/reboot_in_progress note
|
|
35
|
+
d-i cdrom-detect/eject boolean true
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
"""Save a reviewed recorder definition in its own local Git repository."""
|
|
2
|
-
import hashlib
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
import re
|
|
7
|
-
import subprocess
|
|
8
|
-
import sys
|
|
9
|
-
import uuid
|
|
10
|
-
ROOT=Path(__file__).resolve().parents[2];sys.path.insert(0,str(ROOT))
|
|
11
|
-
from recording_converter import parse_recording
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def git(folder,*args,check=True):
|
|
15
|
-
try:p=subprocess.run(['git','-C',str(folder),*args],capture_output=True,text=True,timeout=30)
|
|
16
|
-
except FileNotFoundError:raise ValueError('Git is required for per-RPA version history. Install Git and try again') from None
|
|
17
|
-
if check and p.returncode:raise ValueError('RPA Git operation failed: '+p.stderr.strip()[:300])
|
|
18
|
-
return p.stdout.strip()
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def register(root,request):
|
|
22
|
-
title=str(request.get('title','')).strip();description=str(request.get('description','')).strip()
|
|
23
|
-
if not 1<=len(title)<=120 or not 10<=len(description)<=4000:raise ValueError('Enter a title and a description of at least 10 characters')
|
|
24
|
-
backend=request.get('backend','virtualbox')
|
|
25
|
-
if backend not in ('virtualbox','kvm'):raise ValueError('Recorded replay supports VirtualBox or KVM; Hyper-V desktop input is not implemented')
|
|
26
|
-
width=int(request.get('width',1920));height=int(request.get('height',1080))
|
|
27
|
-
if not 320<=width<=16384 or not 200<=height<=16384:raise ValueError('Enter the recorded guest screen resolution')
|
|
28
|
-
source=Path(request['source_path']).resolve(strict=True)
|
|
29
|
-
if source.suffix.lower()!='.py' or source.stat().st_size>5_000_000:raise ValueError('Choose a Python recorder script under 5 MB')
|
|
30
|
-
raw=source.read_bytes();actions=parse_recording(raw.decode('utf-8-sig'),width,height)
|
|
31
|
-
names=request.get('inputs',[])
|
|
32
|
-
if not isinstance(names,list) or len(names)>20 or any(not isinstance(n,str) or not re.fullmatch('[A-Za-z_][A-Za-z0-9_]{0,63}',n) for n in names):raise ValueError('Input names must contain only letters, digits and underscores')
|
|
33
|
-
for name in names:
|
|
34
|
-
if not any('${'+name+'}' in a.get('text','') for a in actions):raise ValueError(f'Input {name} has no ${{{name}}} placeholder in the recorded text')
|
|
35
|
-
if len(actions)>10000 or any(a.get('seconds',0)>60 or a.get('interval',0)>10 or a.get('presses',0)>1000 or a.get('clicks',0)>1000 for a in actions):raise ValueError('Split large recordings or long delays into smaller tasks')
|
|
36
|
-
root=Path(root).resolve();root.mkdir(parents=True,exist_ok=True,mode=0o700)
|
|
37
|
-
git(root,'--version')
|
|
38
|
-
identifier=str(uuid.UUID(request['id'])) if request.get('id') else str(uuid.uuid4())
|
|
39
|
-
folder=root/identifier;previous=None
|
|
40
|
-
if request.get('id'):
|
|
41
|
-
previous=json.loads((folder/'rpa.json').read_text(encoding='utf8'))
|
|
42
|
-
if previous.get('format')!='vamp-saved-rpa':raise ValueError('Unknown editable definition')
|
|
43
|
-
else:folder.mkdir(mode=0o700)
|
|
44
|
-
folder.chmod(0o700)
|
|
45
|
-
lock=folder/'.rpa-save.lock'
|
|
46
|
-
try:fd=os.open(lock,os.O_CREAT|os.O_EXCL|os.O_WRONLY,0o600)
|
|
47
|
-
except FileExistsError:raise ValueError('Another update is saving this RPA. Retry after it finishes') from None
|
|
48
|
-
try:
|
|
49
|
-
os.close(fd)
|
|
50
|
-
if request.get('expected_commit') and git(folder,'rev-parse','HEAD')!=request['expected_commit']:raise ValueError('RPA changed since it was read. Read the latest revision before repairing')
|
|
51
|
-
version='1.0.0'
|
|
52
|
-
if previous:
|
|
53
|
-
old=str(previous.get('version','1.0.0')).split('.');version='.'.join(old[:2]+[str(int(old[2])+1)])
|
|
54
|
-
definition={'format':'vamp-saved-rpa','id':identifier,'name':title,'description':description,
|
|
55
|
-
'when_to_use':str(request.get('when_to_use',''))[:2000],'expected_result':str(request.get('expected_result',''))[:2000],
|
|
56
|
-
'tags':[str(t).strip()[:80] for t in request.get('tags',[])[:20] if str(t).strip()],
|
|
57
|
-
'inputs':names,'backend':backend,'resolution':[width,height],'reviewed':request.get('reviewed') is True,
|
|
58
|
-
'version':version,'entrypoints':[{'name':'run','file':'source.py'}],
|
|
59
|
-
'source_sha256':hashlib.sha256(raw).hexdigest(),'action_count':len(actions),'source_executed':False}
|
|
60
|
-
encoded=(json.dumps(actions,ensure_ascii=False,indent=2)+'\n').encode();definition['actions_sha256']=hashlib.sha256(encoded).hexdigest()
|
|
61
|
-
(folder/'source.py').write_bytes(raw);(folder/'actions.json').write_bytes(encoded)
|
|
62
|
-
(folder/'rpa.json').write_text(json.dumps(definition,ensure_ascii=False,indent=2)+'\n',encoding='utf8')
|
|
63
|
-
(folder/'README.md').write_text(f'# {title}\n\n{description}\n\n## When to use\n\n{definition["when_to_use"]}\n\n## Expected result\n\n{definition["expected_result"]}\n\nVersion: {version}. Backend: {backend}. Recorded resolution: {width}×{height}.\n\nParsed without executing source. Agent replay needs review and explicit confirmation. Inputs use ${{name}} placeholders. completed_unverified requires application-result verification. This folder has independent local Git history; exports include the latest committed files without .git.\n',encoding='utf8')
|
|
64
|
-
(folder/'.gitignore').write_text('.rpa-save.lock\n*.part\n',encoding='utf8')
|
|
65
|
-
for file in folder.iterdir():
|
|
66
|
-
if file.is_file():file.chmod(0o600)
|
|
67
|
-
if not(folder/'.git').is_dir():git(folder,'init','--quiet')
|
|
68
|
-
git(folder,'add','--','source.py','actions.json','rpa.json','README.md','.gitignore')
|
|
69
|
-
message=str(request.get('commit_message') or f'{"Update" if previous else "Create"} {title} v{version}')[:200]
|
|
70
|
-
git(folder,'-c','user.name=VAMP','-c','user.email=vamp@localhost','commit','--quiet','-m',message)
|
|
71
|
-
return {'status':'registered','definition':definition,'folder':str(folder),'commit':git(folder,'rev-parse','HEAD')}
|
|
72
|
-
finally:lock.unlink(missing_ok=True)
|
|
73
|
-
|
|
74
|
-
if __name__=='__main__':
|
|
75
|
-
try:
|
|
76
|
-
request=json.load(sys.stdin);print(json.dumps(register(request.pop('registry'),request),ensure_ascii=False))
|
|
77
|
-
except Exception as error:print(json.dumps({'status':'error','message':str(error)}));sys.exit(1)
|
|
1
|
+
"""Save a reviewed recorder definition in its own local Git repository."""
|
|
2
|
+
import hashlib
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import re
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import uuid
|
|
10
|
+
ROOT=Path(__file__).resolve().parents[2];sys.path.insert(0,str(ROOT))
|
|
11
|
+
from recording_converter import parse_recording
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def git(folder,*args,check=True):
|
|
15
|
+
try:p=subprocess.run(['git','-C',str(folder),*args],capture_output=True,text=True,timeout=30)
|
|
16
|
+
except FileNotFoundError:raise ValueError('Git is required for per-RPA version history. Install Git and try again') from None
|
|
17
|
+
if check and p.returncode:raise ValueError('RPA Git operation failed: '+p.stderr.strip()[:300])
|
|
18
|
+
return p.stdout.strip()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def register(root,request):
|
|
22
|
+
title=str(request.get('title','')).strip();description=str(request.get('description','')).strip()
|
|
23
|
+
if not 1<=len(title)<=120 or not 10<=len(description)<=4000:raise ValueError('Enter a title and a description of at least 10 characters')
|
|
24
|
+
backend=request.get('backend','virtualbox')
|
|
25
|
+
if backend not in ('virtualbox','kvm'):raise ValueError('Recorded replay supports VirtualBox or KVM; Hyper-V desktop input is not implemented')
|
|
26
|
+
width=int(request.get('width',1920));height=int(request.get('height',1080))
|
|
27
|
+
if not 320<=width<=16384 or not 200<=height<=16384:raise ValueError('Enter the recorded guest screen resolution')
|
|
28
|
+
source=Path(request['source_path']).resolve(strict=True)
|
|
29
|
+
if source.suffix.lower()!='.py' or source.stat().st_size>5_000_000:raise ValueError('Choose a Python recorder script under 5 MB')
|
|
30
|
+
raw=source.read_bytes();actions=parse_recording(raw.decode('utf-8-sig'),width,height)
|
|
31
|
+
names=request.get('inputs',[])
|
|
32
|
+
if not isinstance(names,list) or len(names)>20 or any(not isinstance(n,str) or not re.fullmatch('[A-Za-z_][A-Za-z0-9_]{0,63}',n) for n in names):raise ValueError('Input names must contain only letters, digits and underscores')
|
|
33
|
+
for name in names:
|
|
34
|
+
if not any('${'+name+'}' in a.get('text','') for a in actions):raise ValueError(f'Input {name} has no ${{{name}}} placeholder in the recorded text')
|
|
35
|
+
if len(actions)>10000 or any(a.get('seconds',0)>60 or a.get('interval',0)>10 or a.get('presses',0)>1000 or a.get('clicks',0)>1000 for a in actions):raise ValueError('Split large recordings or long delays into smaller tasks')
|
|
36
|
+
root=Path(root).resolve();root.mkdir(parents=True,exist_ok=True,mode=0o700)
|
|
37
|
+
git(root,'--version')
|
|
38
|
+
identifier=str(uuid.UUID(request['id'])) if request.get('id') else str(uuid.uuid4())
|
|
39
|
+
folder=root/identifier;previous=None
|
|
40
|
+
if request.get('id'):
|
|
41
|
+
previous=json.loads((folder/'rpa.json').read_text(encoding='utf8'))
|
|
42
|
+
if previous.get('format')!='vamp-saved-rpa':raise ValueError('Unknown editable definition')
|
|
43
|
+
else:folder.mkdir(mode=0o700)
|
|
44
|
+
folder.chmod(0o700)
|
|
45
|
+
lock=folder/'.rpa-save.lock'
|
|
46
|
+
try:fd=os.open(lock,os.O_CREAT|os.O_EXCL|os.O_WRONLY,0o600)
|
|
47
|
+
except FileExistsError:raise ValueError('Another update is saving this RPA. Retry after it finishes') from None
|
|
48
|
+
try:
|
|
49
|
+
os.close(fd)
|
|
50
|
+
if request.get('expected_commit') and git(folder,'rev-parse','HEAD')!=request['expected_commit']:raise ValueError('RPA changed since it was read. Read the latest revision before repairing')
|
|
51
|
+
version='1.0.0'
|
|
52
|
+
if previous:
|
|
53
|
+
old=str(previous.get('version','1.0.0')).split('.');version='.'.join(old[:2]+[str(int(old[2])+1)])
|
|
54
|
+
definition={'format':'vamp-saved-rpa','id':identifier,'name':title,'description':description,
|
|
55
|
+
'when_to_use':str(request.get('when_to_use',''))[:2000],'expected_result':str(request.get('expected_result',''))[:2000],
|
|
56
|
+
'tags':[str(t).strip()[:80] for t in request.get('tags',[])[:20] if str(t).strip()],
|
|
57
|
+
'inputs':names,'backend':backend,'resolution':[width,height],'reviewed':request.get('reviewed') is True,
|
|
58
|
+
'version':version,'entrypoints':[{'name':'run','file':'source.py'}],
|
|
59
|
+
'source_sha256':hashlib.sha256(raw).hexdigest(),'action_count':len(actions),'source_executed':False}
|
|
60
|
+
encoded=(json.dumps(actions,ensure_ascii=False,indent=2)+'\n').encode();definition['actions_sha256']=hashlib.sha256(encoded).hexdigest()
|
|
61
|
+
(folder/'source.py').write_bytes(raw);(folder/'actions.json').write_bytes(encoded)
|
|
62
|
+
(folder/'rpa.json').write_text(json.dumps(definition,ensure_ascii=False,indent=2)+'\n',encoding='utf8')
|
|
63
|
+
(folder/'README.md').write_text(f'# {title}\n\n{description}\n\n## When to use\n\n{definition["when_to_use"]}\n\n## Expected result\n\n{definition["expected_result"]}\n\nVersion: {version}. Backend: {backend}. Recorded resolution: {width}×{height}.\n\nParsed without executing source. Agent replay needs review and explicit confirmation. Inputs use ${{name}} placeholders. completed_unverified requires application-result verification. This folder has independent local Git history; exports include the latest committed files without .git.\n',encoding='utf8')
|
|
64
|
+
(folder/'.gitignore').write_text('.rpa-save.lock\n*.part\n',encoding='utf8')
|
|
65
|
+
for file in folder.iterdir():
|
|
66
|
+
if file.is_file():file.chmod(0o600)
|
|
67
|
+
if not(folder/'.git').is_dir():git(folder,'init','--quiet')
|
|
68
|
+
git(folder,'add','--','source.py','actions.json','rpa.json','README.md','.gitignore')
|
|
69
|
+
message=str(request.get('commit_message') or f'{"Update" if previous else "Create"} {title} v{version}')[:200]
|
|
70
|
+
git(folder,'-c','user.name=VAMP','-c','user.email=vamp@localhost','commit','--quiet','-m',message)
|
|
71
|
+
return {'status':'registered','definition':definition,'folder':str(folder),'commit':git(folder,'rev-parse','HEAD')}
|
|
72
|
+
finally:lock.unlink(missing_ok=True)
|
|
73
|
+
|
|
74
|
+
if __name__=='__main__':
|
|
75
|
+
try:
|
|
76
|
+
request=json.load(sys.stdin);print(json.dumps(register(request.pop('registry'),request),ensure_ascii=False))
|
|
77
|
+
except Exception as error:print(json.dumps({'status':'error','message':str(error)}));sys.exit(1)
|