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.

Files changed (141) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +144 -107
  3. package/THIRD_PARTY_NOTICES.md +32 -27
  4. package/bin/vamp-mcp.mjs +37 -37
  5. package/notices/mcp-virtualbox-LICENSE +21 -21
  6. package/notices/mcp-virtualbox-PROVENANCE.json +37 -37
  7. package/package.json +51 -17
  8. package/runtime/backends/common/Test-Environment.ps1 +7 -6
  9. package/runtime/backends/common/guest-install.json +58 -0
  10. package/runtime/backends/common/guest_install.py +57 -0
  11. package/runtime/backends/common/host-support.cjs +16 -0
  12. package/runtime/backends/common/packer.cjs +16 -0
  13. package/runtime/backends/hyperv/scripts/Manage-Desktop.ps1 +40 -67
  14. package/runtime/backends/hyperv/scripts/Send-InstallerBoot.ps1 +25 -0
  15. package/runtime/backends/kvm/debian-preseed.cfg +35 -35
  16. package/runtime/backends/library/registry.py +77 -77
  17. package/runtime/backends/library/replay.py +154 -154
  18. package/runtime/backends/packer/answer_media.py +16 -0
  19. package/runtime/backends/packer/deploy-hyperv.ps1 +10 -0
  20. package/runtime/backends/packer/drivers.py +49 -0
  21. package/runtime/backends/packer/hyperv-network.ps1 +10 -0
  22. package/runtime/backends/packer/images.py +75 -0
  23. package/runtime/backends/packer/osinfo.py +113 -0
  24. package/runtime/backends/packer/policy.json +15 -0
  25. package/runtime/backends/packer/runner.py +224 -0
  26. package/runtime/backends/packer/templates.py +118 -0
  27. package/runtime/backends/packer/toolchain.py +80 -0
  28. package/runtime/backends/remote_ssh/server.mjs +321 -94
  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 -184
  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 +440 -63
  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 +94 -0
  54. package/runtime/guest_setup/http/postwin.ps1 +53 -0
  55. package/runtime/guest_setup/http/setup-all.ps1 +25 -0
  56. package/runtime/guest_setup/http/setup-win.cmd +7 -0
  57. package/runtime/guest_setup/http/setup.ps1 +44 -0
  58. package/runtime/guest_setup/http/setup.sh +50 -0
  59. package/runtime/guest_setup/kvm/setup-debian.sh +73 -0
  60. package/runtime/guest_setup/kvm/setup-windows.ps1 +52 -0
  61. package/runtime/guest_setup/recorder/README.txt +12 -8
  62. package/runtime/guest_setup/recorder/RECORDER-LICENSE +674 -674
  63. package/runtime/guest_setup/recorder/RECORDING-GUIDE.txt +31 -31
  64. package/runtime/guest_setup/recorder/apply-display.py +41 -41
  65. package/runtime/guest_setup/recorder/configure-debian-mirrors.py +62 -62
  66. package/runtime/guest_setup/recorder/configure-gdm.py +23 -0
  67. package/runtime/guest_setup/recorder/configure-session.ps1 +14 -0
  68. package/runtime/guest_setup/recorder/gnome-display.py +60 -60
  69. package/runtime/guest_setup/recorder/install-display-startup.py +67 -39
  70. package/runtime/guest_setup/recorder/install-hypervisor-drivers.ps1 +34 -0
  71. package/runtime/guest_setup/recorder/install-resolution-shortcut.ps1 +36 -0
  72. package/runtime/guest_setup/recorder/postwin.cmd +10 -10
  73. package/runtime/guest_setup/recorder/prepare-recording.py +30 -30
  74. package/runtime/guest_setup/recorder/recorder.zip +0 -0
  75. package/runtime/guest_setup/recorder/requirements-recorder.txt +2 -2
  76. package/runtime/guest_setup/recorder/session-policy.py +22 -0
  77. package/runtime/guest_setup/recorder/set-resolution-registry.ps1 +40 -0
  78. package/runtime/guest_setup/recorder/setup-user.py +53 -35
  79. package/runtime/guest_setup/recorder/setup-win.cmd +4 -11
  80. package/runtime/guest_setup/recorder/setup.ps1 +112 -30
  81. package/runtime/guest_setup/recorder/setup.sh +19 -1
  82. package/runtime/guest_setup/recorder/vamp-recorder.py +148 -148
  83. package/runtime/guest_setup/recorder/verify-recorder.py +4 -4
  84. package/runtime/guest_setup/recorder/windows-display.py +76 -76
  85. package/runtime/guest_setup/requirements.txt +2 -0
  86. package/runtime/guest_setup/setup-all.ps1 +35 -0
  87. package/runtime/guest_setup/setup-all.sh +22 -0
  88. package/runtime/guest_setup/vault/Install-VCRuntime.ps1 +26 -0
  89. package/runtime/guest_setup/vault/setup-guest-vault.ps1 +148 -0
  90. package/runtime/guest_setup/vault/setup-guest-vault.sh +75 -0
  91. package/runtime/recording_converter.py +230 -230
  92. package/runtime/requirements-mcp.txt +11 -11
  93. package/runtime/rpas/README.md +161 -161
  94. package/runtime/rpas/captcha_handoff/manifest.json +27 -27
  95. package/runtime/rpas/captcha_handoff/run.robot +16 -16
  96. package/runtime/rpas/captcha_handoff/workflow.py +11 -11
  97. package/runtime/rpas/common.resource +26 -26
  98. package/runtime/rpas/debian_update/manifest.json +27 -27
  99. package/runtime/rpas/debian_update/run.robot +17 -17
  100. package/runtime/rpas/debian_update/workflow.py +13 -13
  101. package/runtime/rpas/desktop_control/manifest.json +26 -26
  102. package/runtime/rpas/desktop_control/run.robot +27 -27
  103. package/runtime/rpas/desktop_control/workflow.py +51 -51
  104. package/runtime/rpas/firefox_launch/manifest.json +27 -27
  105. package/runtime/rpas/firefox_launch/run.robot +15 -15
  106. package/runtime/rpas/firefox_launch/workflow.py +25 -25
  107. package/runtime/rpas/firefox_naver/manifest.json +27 -27
  108. package/runtime/rpas/firefox_naver/run.robot +21 -21
  109. package/runtime/rpas/firefox_naver/workflow.py +28 -28
  110. package/runtime/rpas/kvm_validation/README.md +11 -11
  111. package/runtime/rpas/kvm_validation/manifest.json +28 -28
  112. package/runtime/rpas/kvm_validation/run.robot +30 -30
  113. package/runtime/rpas/kvm_validation/workflow.py +91 -91
  114. package/runtime/rpas/manifest.schema.json +105 -105
  115. package/runtime/rpas/naver_login/login.robot +25 -25
  116. package/runtime/rpas/naver_login/manifest.json +33 -33
  117. package/runtime/rpas/naver_login/run.robot +20 -20
  118. package/runtime/rpas/naver_login/workflow.py +32 -32
  119. package/runtime/rpas/windows_naver_recorded/README.md +24 -24
  120. package/runtime/rpas/windows_naver_recorded/conversion.json +25 -25
  121. package/runtime/rpas/windows_naver_recorded/manifest.json +28 -28
  122. package/runtime/rpas/windows_naver_recorded/run.robot +37 -37
  123. package/runtime/rpas/windows_naver_recorded/workflow.py +32 -32
  124. package/runtime/scripts/build_recorder_media.py +39 -39
  125. package/runtime/scripts/macos/setup-host.sh +126 -0
  126. package/runtime/scripts/remote_host_setup.sh +7 -4
  127. package/runtime/scripts/script_server.py +571 -0
  128. package/runtime/skills/vamp-rpa-ui-checks/SKILL.md +26 -0
  129. package/runtime/skills/vamp-rpa-ui-checks/agents/openai.yaml +4 -0
  130. package/runtime/skills/vamp-rpa-ui-checks/references/display.md +12 -0
  131. package/runtime/skills/vamp-rpa-ui-checks/references/user-guide.md +51 -0
  132. package/runtime/skills/vamp-ui-cleanup/SKILL.md +15 -0
  133. package/runtime/skills/vamp-ui-cleanup/agents/openai.yaml +4 -0
  134. package/runtime/skills/vamp-ui-validation/SKILL.md +27 -0
  135. package/runtime/skills/vamp-ui-validation/agents/openai.yaml +4 -0
  136. package/runtime/third_party/mcp-virtualbox/scripts/mouse_click.py +65 -65
  137. package/runtime/third_party/pyautogui-recorder/LICENSE +674 -674
  138. package/runtime/third_party/pyautogui-recorder/PROVENANCE.json +16 -16
  139. package/runtime/third_party/pyautogui-recorder/PyAutoGuiRecorder.py +169 -169
  140. package/runtime/third_party/pyautogui-recorder/README.md +53 -53
  141. package/runtime/scripts/build_debian_installer.py +0 -48
@@ -1,230 +1,230 @@
1
- """Parse recorder source as data; never import, eval or execute a recording."""
2
- import argparse
3
- import ast
4
- from collections import Counter
5
- import hashlib
6
- import json
7
- import math
8
- from pathlib import Path
9
- import re
10
-
11
- ROOT=Path(__file__).resolve().parent
12
- KEY_ALIASES={'cmd':'super','command':'super','win':'super','winleft':'super','winright':'superright',
13
- 'ctrl_l':'ctrl','ctrl_r':'ctrlright','ctrlleft':'ctrl','ctrlright':'ctrlright',
14
- 'shift_l':'shift','shift_r':'shiftright','shiftleft':'shift','shiftright':'shiftright',
15
- 'alt_l':'alt','alt_r':'altright','altleft':'alt','altright':'altright',
16
- 'return':'enter','escape':'esc','del':'delete','pgup':'pageup','pgdn':'pagedown'}
17
- SPECIAL_KEYS={'enter','esc','tab','space','ctrl','ctrlright','alt','altright','shift','shiftright',
18
- 'super','superright','backspace','left','right','up','down','delete','home','end','pageup','pagedown',
19
- 'insert','capslock',*[f'f{i}' for i in range(1,13)]}
20
-
21
-
22
- def key_name(value):
23
- if not isinstance(value,str) or not value:
24
- raise ValueError('Expected a key name')
25
- key=KEY_ALIASES.get(value.lower(),value.lower())
26
- if key in SPECIAL_KEYS or len(value)==1 and 32<=ord(value)<=126:
27
- return key if len(value)>1 else value
28
- raise ValueError('Unsupported recorded key name')
29
-
30
-
31
- def number(value):
32
- if isinstance(value,bool) or not isinstance(value,(int,float)) or not math.isfinite(value):
33
- raise ValueError('Expected a finite numeric value')
34
- return value
35
-
36
-
37
- def parse_recording(source,width=1920,height=1080,coordinate_space='guest',viewport=None):
38
- if width<=0 or height<=0:
39
- raise ValueError('Guest resolution must be positive')
40
- if coordinate_space=='host' and (not viewport or len(viewport)!=4 or not all(math.isfinite(v) for v in viewport) or viewport[2]<=0 or viewport[3]<=0):
41
- raise ValueError('Host recordings require --viewport LEFT TOP WIDTH HEIGHT in recorded coordinate units')
42
- modules={}; functions={}; actions=[]
43
- def point(x,y):
44
- x,y=number(x),number(y)
45
- if coordinate_space=='host':
46
- left,top,w,h=viewport
47
- if not (left<=x<left+w and top<=y<top+h):
48
- raise ValueError('Recorded point lies outside the specified guest viewport')
49
- x,y=(x-left)*width/w,(y-top)*height/h
50
- if not (0<=x<width and 0<=y<height):
51
- raise ValueError('Recorded point is outside the declared guest resolution')
52
- return min(width-1,round(x)),min(height-1,round(y))
53
- def walk(body):
54
- for node in body:
55
- if isinstance(node,ast.Import):
56
- for alias in node.names:
57
- if alias.name not in ('pyautogui','time'):
58
- raise ValueError(f'Unsupported import at line {node.lineno}')
59
- modules[alias.asname or alias.name]=alias.name
60
- continue
61
- if isinstance(node,ast.ImportFrom) and node.module in ('pyautogui','time'):
62
- for alias in node.names:
63
- if alias.name=='*':raise ValueError('Wildcard imports are not supported')
64
- functions[alias.asname or alias.name]=(node.module,alias.name)
65
- continue
66
- if isinstance(node,ast.If) and ast.dump(node.test)==ast.dump(ast.parse("__name__ == '__main__'",mode='eval').body) and not node.orelse:
67
- walk(node.body);continue
68
- if isinstance(node,ast.Expr) and isinstance(node.value,ast.Constant) and isinstance(node.value.value,str):
69
- continue
70
- if not isinstance(node,ast.Expr) or not isinstance(node.value,ast.Call):
71
- raise ValueError(f'Unsupported Python statement at line {node.lineno}; review manually')
72
- call=node.value
73
- if isinstance(call.func,ast.Attribute) and isinstance(call.func.value,ast.Name):
74
- module,name=modules.get(call.func.value.id),call.func.attr
75
- elif isinstance(call.func,ast.Name) and call.func.id in functions:
76
- module,name=functions[call.func.id]
77
- else:
78
- raise ValueError(f'Unsupported call at line {node.lineno}')
79
- try:
80
- args=[ast.literal_eval(a) for a in call.args]
81
- kwargs={k.arg:ast.literal_eval(k.value) for k in call.keywords if k.arg is not None}
82
- if any(k.arg is None for k in call.keywords) or len(kwargs)!=len(call.keywords):raise ValueError()
83
- except (ValueError,TypeError,SyntaxError):
84
- raise ValueError(f'Only literal arguments are allowed at line {node.lineno}') from None
85
- action={'line':node.lineno}
86
- def take(index,key,default=None):
87
- if len(args)>index and key in kwargs:raise ValueError('Duplicate argument')
88
- return args[index] if len(args)>index else kwargs.get(key,default)
89
- allowed=set();max_args=0
90
- if module=='time' and name=='sleep' or module=='pyautogui' and name=='sleep':
91
- allowed={'seconds'};max_args=1
92
- seconds=number(take(0,'seconds'))
93
- if seconds<0:raise ValueError('Negative sleep')
94
- action.update(op='wait',seconds=seconds)
95
- elif module=='pyautogui' and name in ('keyDown','keyUp'):
96
- allowed={'key'};max_args=1
97
- action.update(op='key_down' if name=='keyDown' else 'key_up',key=key_name(take(0,'key')))
98
- elif module=='pyautogui' and name in ('write','typewrite'):
99
- allowed={'message','interval'};max_args=2
100
- message=take(0,'message');interval=number(take(1,'interval',.06))
101
- if interval<0:raise ValueError('Negative key interval')
102
- if isinstance(message,str) and all(32<=ord(c)<=126 or c in '\n\t' for c in message):
103
- action.update(op='write',text=message,interval=interval)
104
- elif isinstance(message,(list,tuple)):
105
- action.update(op='press',keys=[key_name(k) for k in message],presses=1,interval=interval)
106
- else:raise ValueError('Only ASCII text or literal key lists are supported')
107
- elif module=='pyautogui' and name=='press':
108
- allowed={'keys','presses','interval'};max_args=3
109
- keys=take(0,'keys');keys=[keys] if isinstance(keys,str) else keys
110
- presses=take(1,'presses',1);interval=number(take(2,'interval',.05))
111
- if not isinstance(keys,(list,tuple)) or type(presses)!=int or presses<1 or interval<0:raise ValueError('Invalid press arguments')
112
- action.update(op='press',keys=[key_name(k) for k in keys],presses=presses,interval=interval)
113
- elif module=='pyautogui' and name=='hotkey':
114
- allowed={'interval'};max_args=len(args)
115
- interval=number(kwargs.get('interval',.05))
116
- if not args or interval<0:raise ValueError('Invalid hotkey')
117
- action.update(op='hotkey',keys=[key_name(k) for k in args],interval=interval)
118
- elif module=='pyautogui' and name in ('click','doubleClick','rightClick','middleClick','moveTo'):
119
- max_args=2;allowed={'x','y','duration','button','clicks','interval'}
120
- if kwargs.get('duration',0)!=0:raise ValueError('Timed movement requires manual conversion')
121
- x,y=point(take(0,'x'),take(1,'y'))
122
- if name=='moveTo':
123
- if set(kwargs)-{'x','y','duration'}:raise ValueError('Invalid moveTo arguments')
124
- action.update(op='move',x=x,y=y)
125
- else:
126
- button=kwargs.get('button',{'rightClick':'right','middleClick':'middle'}.get(name,'left'))
127
- clicks=kwargs.get('clicks',2 if name=='doubleClick' else 1)
128
- interval=number(kwargs.get('interval',.1))
129
- if button not in ('left','middle','right') or type(clicks)!=int or clicks<1 or interval<0:raise ValueError('Invalid click arguments')
130
- action.update(op='click',x=x,y=y,button=button,clicks=clicks,interval=interval)
131
- elif module=='pyautogui' and name=='scroll':
132
- allowed={'clicks','x','y'};max_args=3
133
- clicks=take(0,'clicks')
134
- if type(clicks)!=int:raise ValueError('Wheel clicks must be an integer')
135
- action.update(op='scroll',clicks=clicks)
136
- x,y=take(1,'x'),take(2,'y')
137
- if x is not None or y is not None:
138
- x,y=point(x,y);action.update(x=x,y=y)
139
- else:
140
- raise ValueError(f'Unsupported recorder operation at line {node.lineno}; no code was executed')
141
- if len(args)>max_args or set(kwargs)-allowed:
142
- raise ValueError(f'Unsupported arguments at line {node.lineno}')
143
- actions.append(action)
144
- walk(ast.parse(source).body)
145
- if not actions:raise ValueError('No supported actions found')
146
- return actions
147
-
148
-
149
- def generate(source_path,package_id,guest_os='windows11',width=1920,height=1080,
150
- coordinate_space='guest',viewport=None,package_root=None):
151
- if not re.fullmatch('[a-z][a-z0-9_]*',package_id):raise ValueError('Invalid package id')
152
- source_path=Path(source_path).expanduser().resolve()
153
- raw=source_path.read_bytes()
154
- actions=parse_recording(raw.decode('utf-8-sig'),width,height,coordinate_space,viewport)
155
- parent=Path(package_root) if package_root else ROOT/'rpas'
156
- target=parent/package_id
157
- if target.exists():raise ValueError('Package already exists; use a new id to preserve manual edits')
158
- held=set()
159
- for action in actions:
160
- if action['op']=='key_down':held.add(action['key'])
161
- if action['op']=='key_up':held.discard(action['key'])
162
- starts_launcher=(len(actions)>=2 and actions[0].get('op')=='key_down' and actions[0].get('key')=='super'
163
- and actions[1].get('op')=='key_down' and actions[1].get('key','').lower()=='r') or (
164
- actions[0].get('op')=='hotkey' and actions[0].get('keys')==['super','r'])
165
- warnings=['Mechanical conversion only: review target positions and replace waits with state checks.',
166
- 'Review all recorded input for private credentials before replay or sharing.']
167
- if held:warnings.append(f'{len(held)} key(s) remain held at recording end; replay teardown will release them.')
168
- if guest_os=='windows11' and not starts_launcher:warnings.append('No initial Win+R launcher detected; replace desktop-icon launch with a common launcher.')
169
- manifest={'format_version':1,'id':package_id,'name':'Recorded '+package_id,'version':'0.1.0',
170
- 'default_entrypoint':'run','entrypoints':[{'name':'run','file':'run.robot','credentials':'environment_or_prompt'}],
171
- 'python_libraries':['workflow.py'],'dependencies':['spice','paddleocr_optional'],
172
- 'skill':'spice-recording-convert','outputs':{'summary':'${OUTPUT DIR}/summary.json',
173
- 'robot_log':'${OUTPUT DIR}/log.html','robot_report':'${OUTPUT DIR}/report.html'}}
174
- report={'format_version':1,'source_name':source_path.name,'source_sha256':hashlib.sha256(raw).hexdigest(),
175
- 'guest_os':guest_os,'coordinate_space':coordinate_space,'guest_resolution':[width,height],
176
- 'action_count':len(actions),'operations':dict(Counter(a['op'] for a in actions)),
177
- 'initial_win_r':starts_launcher,'requires_review':True,'warnings':warnings}
178
- target.mkdir(parents=True)
179
- for name,data in [('manifest.json',manifest),('conversion.json',report),
180
- ('recording.local.json',{'format_version':1,'guest_os':guest_os,'resolution':[width,height],'actions':actions})]:
181
- path=target/name;path.write_text(json.dumps(data,ensure_ascii=False,indent=2)+'\n')
182
- if name=='recording.local.json':path.chmod(0o600)
183
- (target/'workflow.py').write_text('''"""Generated adapter: keep detailed input and coordinates in Python/local data."""
184
- from pathlib import Path
185
- from robot.api.deco import library
186
- from recording_runtime import RecordedWorkflow
187
-
188
-
189
- @library(scope='SUITE',auto_keywords=False)
190
- class Workflow(RecordedWorkflow):
191
- def __init__(self):
192
- super().__init__(Path(__file__).resolve().parent)
193
- ''')
194
- lines=['*** Settings ***','Resource ${CURDIR}/../common.resource',
195
- 'Library ${CURDIR}/workflow.py WITH NAME Workflow',
196
- 'Suite Setup Contract.Begin Result ${RPA_ID}',
197
- 'Suite Teardown Stop RPA','Task Teardown End Recorded Task','',
198
- '*** Variables ***',f'${{RPA_ID}} {package_id}',
199
- '${ALLOW_REPLAY} ${FALSE}','${EXPECTED_TEXT} ${EMPTY}','${LANGUAGES} en','',
200
- '*** Tasks ***','Replay Reviewed Guest Recording',
201
- ' ${ready}= Workflow.Load Recording ${ALLOW_REPLAY}',
202
- ' IF not $ready',' ${review}= Workflow.Review Result',
203
- ' Contract.Publish Result ${review}',' Skip Review conversion.json and recording.local.json; set ALLOW_REPLAY only after review.',
204
- ' END',' Spice.Connect Spice ${SPICE_URI}',' Workflow.Check Guest Geometry']
205
- lines[lines.index(' ${review}= Workflow.Review Result')]=' ${review}= Workflow.Review Result'
206
- lines.extend([' ${count}= Workflow.Action Count',
207
- ' FOR ${index} IN RANGE ${count}',
208
- ' Workflow.Replay Event ${index}',' END'])
209
- lines.extend([' ${result}= Workflow.Verify Replay ${EXPECTED_TEXT} ${LANGUAGES}',
210
- ' Contract.Publish Result ${result}',' Pause For User Verification ${result}',
211
- ' Should Not Be Equal ${result}[status] verification_failed','','*** Keywords ***','End Recorded Task',
212
- ' Run Keyword And Continue On Failure Workflow.Release Recorded Inputs',' Finish RPA Task',''])
213
- (target/'run.robot').write_text('\n'.join(lines))
214
- (target/'README.md').write_text(f'''# {package_id}\n\nGenerated from `{source_path.name}` without executing source code.\n\n- Guest: `{guest_os}`, {width}×{height}; source space: `{coordinate_space}`.\n- Review `conversion.json` and the private `recording.local.json` before replay.\n- `run.robot` controls the order; `workflow.py` and `recording_runtime.py` execute SPICE input.\n- Default run returns `needs_review` without connecting to the VM.\n- Explicit replay: `.venv/bin/python scripts/run_rpa.py {package_id} --var ALLOW_REPLAY:True --var SPICE_URI:<actual-guest-uri>`\n- No application success is claimed unless an expected OCR text is configured; otherwise result is `replayed_unverified`.\n- `recording.local.json` is excluded from Git because recorded keystrokes can contain credentials. Regenerate from a local source on a new checkout.\n- See [conversion guide](../../docs/RECORDING_CONVERSION.md) for refinement and credential replacement.\n''')
215
- return {'status':'generated_needs_review','rpa_id':package_id,'package_path':str(target.resolve()),
216
- 'action_count':len(actions),'initial_win_r':starts_launcher,'report':str((target/'conversion.json').resolve())}
217
-
218
-
219
- def main():
220
- parser=argparse.ArgumentParser()
221
- parser.add_argument('source')
222
- parser.add_argument('--id',required=True)
223
- parser.add_argument('--guest-os',choices=['windows11','debian'],default='windows11')
224
- parser.add_argument('--width',type=int,default=1920);parser.add_argument('--height',type=int,default=1080)
225
- parser.add_argument('--coordinate-space',choices=['guest','host'],default='guest')
226
- parser.add_argument('--viewport',type=float,nargs=4,metavar=('LEFT','TOP','WIDTH','HEIGHT'))
227
- args=parser.parse_args()
228
- try:result=generate(args.source,args.id,args.guest_os,args.width,args.height,args.coordinate_space,args.viewport)
229
- except (ValueError,OSError,SyntaxError) as error:parser.error(str(error))
230
- print(json.dumps(result,ensure_ascii=False,indent=2))
1
+ """Parse recorder source as data; never import, eval or execute a recording."""
2
+ import argparse
3
+ import ast
4
+ from collections import Counter
5
+ import hashlib
6
+ import json
7
+ import math
8
+ from pathlib import Path
9
+ import re
10
+
11
+ ROOT=Path(__file__).resolve().parent
12
+ KEY_ALIASES={'cmd':'super','command':'super','win':'super','winleft':'super','winright':'superright',
13
+ 'ctrl_l':'ctrl','ctrl_r':'ctrlright','ctrlleft':'ctrl','ctrlright':'ctrlright',
14
+ 'shift_l':'shift','shift_r':'shiftright','shiftleft':'shift','shiftright':'shiftright',
15
+ 'alt_l':'alt','alt_r':'altright','altleft':'alt','altright':'altright',
16
+ 'return':'enter','escape':'esc','del':'delete','pgup':'pageup','pgdn':'pagedown'}
17
+ SPECIAL_KEYS={'enter','esc','tab','space','ctrl','ctrlright','alt','altright','shift','shiftright',
18
+ 'super','superright','backspace','left','right','up','down','delete','home','end','pageup','pagedown',
19
+ 'insert','capslock',*[f'f{i}' for i in range(1,13)]}
20
+
21
+
22
+ def key_name(value):
23
+ if not isinstance(value,str) or not value:
24
+ raise ValueError('Expected a key name')
25
+ key=KEY_ALIASES.get(value.lower(),value.lower())
26
+ if key in SPECIAL_KEYS or len(value)==1 and 32<=ord(value)<=126:
27
+ return key if len(value)>1 else value
28
+ raise ValueError('Unsupported recorded key name')
29
+
30
+
31
+ def number(value):
32
+ if isinstance(value,bool) or not isinstance(value,(int,float)) or not math.isfinite(value):
33
+ raise ValueError('Expected a finite numeric value')
34
+ return value
35
+
36
+
37
+ def parse_recording(source,width=1920,height=1080,coordinate_space='guest',viewport=None):
38
+ if width<=0 or height<=0:
39
+ raise ValueError('Guest resolution must be positive')
40
+ if coordinate_space=='host' and (not viewport or len(viewport)!=4 or not all(math.isfinite(v) for v in viewport) or viewport[2]<=0 or viewport[3]<=0):
41
+ raise ValueError('Host recordings require --viewport LEFT TOP WIDTH HEIGHT in recorded coordinate units')
42
+ modules={}; functions={}; actions=[]
43
+ def point(x,y):
44
+ x,y=number(x),number(y)
45
+ if coordinate_space=='host':
46
+ left,top,w,h=viewport
47
+ if not (left<=x<left+w and top<=y<top+h):
48
+ raise ValueError('Recorded point lies outside the specified guest viewport')
49
+ x,y=(x-left)*width/w,(y-top)*height/h
50
+ if not (0<=x<width and 0<=y<height):
51
+ raise ValueError('Recorded point is outside the declared guest resolution')
52
+ return min(width-1,round(x)),min(height-1,round(y))
53
+ def walk(body):
54
+ for node in body:
55
+ if isinstance(node,ast.Import):
56
+ for alias in node.names:
57
+ if alias.name not in ('pyautogui','time'):
58
+ raise ValueError(f'Unsupported import at line {node.lineno}')
59
+ modules[alias.asname or alias.name]=alias.name
60
+ continue
61
+ if isinstance(node,ast.ImportFrom) and node.module in ('pyautogui','time'):
62
+ for alias in node.names:
63
+ if alias.name=='*':raise ValueError('Wildcard imports are not supported')
64
+ functions[alias.asname or alias.name]=(node.module,alias.name)
65
+ continue
66
+ if isinstance(node,ast.If) and ast.dump(node.test)==ast.dump(ast.parse("__name__ == '__main__'",mode='eval').body) and not node.orelse:
67
+ walk(node.body);continue
68
+ if isinstance(node,ast.Expr) and isinstance(node.value,ast.Constant) and isinstance(node.value.value,str):
69
+ continue
70
+ if not isinstance(node,ast.Expr) or not isinstance(node.value,ast.Call):
71
+ raise ValueError(f'Unsupported Python statement at line {node.lineno}; review manually')
72
+ call=node.value
73
+ if isinstance(call.func,ast.Attribute) and isinstance(call.func.value,ast.Name):
74
+ module,name=modules.get(call.func.value.id),call.func.attr
75
+ elif isinstance(call.func,ast.Name) and call.func.id in functions:
76
+ module,name=functions[call.func.id]
77
+ else:
78
+ raise ValueError(f'Unsupported call at line {node.lineno}')
79
+ try:
80
+ args=[ast.literal_eval(a) for a in call.args]
81
+ kwargs={k.arg:ast.literal_eval(k.value) for k in call.keywords if k.arg is not None}
82
+ if any(k.arg is None for k in call.keywords) or len(kwargs)!=len(call.keywords):raise ValueError()
83
+ except (ValueError,TypeError,SyntaxError):
84
+ raise ValueError(f'Only literal arguments are allowed at line {node.lineno}') from None
85
+ action={'line':node.lineno}
86
+ def take(index,key,default=None):
87
+ if len(args)>index and key in kwargs:raise ValueError('Duplicate argument')
88
+ return args[index] if len(args)>index else kwargs.get(key,default)
89
+ allowed=set();max_args=0
90
+ if module=='time' and name=='sleep' or module=='pyautogui' and name=='sleep':
91
+ allowed={'seconds'};max_args=1
92
+ seconds=number(take(0,'seconds'))
93
+ if seconds<0:raise ValueError('Negative sleep')
94
+ action.update(op='wait',seconds=seconds)
95
+ elif module=='pyautogui' and name in ('keyDown','keyUp'):
96
+ allowed={'key'};max_args=1
97
+ action.update(op='key_down' if name=='keyDown' else 'key_up',key=key_name(take(0,'key')))
98
+ elif module=='pyautogui' and name in ('write','typewrite'):
99
+ allowed={'message','interval'};max_args=2
100
+ message=take(0,'message');interval=number(take(1,'interval',.06))
101
+ if interval<0:raise ValueError('Negative key interval')
102
+ if isinstance(message,str) and all(32<=ord(c)<=126 or c in '\n\t' for c in message):
103
+ action.update(op='write',text=message,interval=interval)
104
+ elif isinstance(message,(list,tuple)):
105
+ action.update(op='press',keys=[key_name(k) for k in message],presses=1,interval=interval)
106
+ else:raise ValueError('Only ASCII text or literal key lists are supported')
107
+ elif module=='pyautogui' and name=='press':
108
+ allowed={'keys','presses','interval'};max_args=3
109
+ keys=take(0,'keys');keys=[keys] if isinstance(keys,str) else keys
110
+ presses=take(1,'presses',1);interval=number(take(2,'interval',.05))
111
+ if not isinstance(keys,(list,tuple)) or type(presses)!=int or presses<1 or interval<0:raise ValueError('Invalid press arguments')
112
+ action.update(op='press',keys=[key_name(k) for k in keys],presses=presses,interval=interval)
113
+ elif module=='pyautogui' and name=='hotkey':
114
+ allowed={'interval'};max_args=len(args)
115
+ interval=number(kwargs.get('interval',.05))
116
+ if not args or interval<0:raise ValueError('Invalid hotkey')
117
+ action.update(op='hotkey',keys=[key_name(k) for k in args],interval=interval)
118
+ elif module=='pyautogui' and name in ('click','doubleClick','rightClick','middleClick','moveTo'):
119
+ max_args=2;allowed={'x','y','duration','button','clicks','interval'}
120
+ if kwargs.get('duration',0)!=0:raise ValueError('Timed movement requires manual conversion')
121
+ x,y=point(take(0,'x'),take(1,'y'))
122
+ if name=='moveTo':
123
+ if set(kwargs)-{'x','y','duration'}:raise ValueError('Invalid moveTo arguments')
124
+ action.update(op='move',x=x,y=y)
125
+ else:
126
+ button=kwargs.get('button',{'rightClick':'right','middleClick':'middle'}.get(name,'left'))
127
+ clicks=kwargs.get('clicks',2 if name=='doubleClick' else 1)
128
+ interval=number(kwargs.get('interval',.1))
129
+ if button not in ('left','middle','right') or type(clicks)!=int or clicks<1 or interval<0:raise ValueError('Invalid click arguments')
130
+ action.update(op='click',x=x,y=y,button=button,clicks=clicks,interval=interval)
131
+ elif module=='pyautogui' and name=='scroll':
132
+ allowed={'clicks','x','y'};max_args=3
133
+ clicks=take(0,'clicks')
134
+ if type(clicks)!=int:raise ValueError('Wheel clicks must be an integer')
135
+ action.update(op='scroll',clicks=clicks)
136
+ x,y=take(1,'x'),take(2,'y')
137
+ if x is not None or y is not None:
138
+ x,y=point(x,y);action.update(x=x,y=y)
139
+ else:
140
+ raise ValueError(f'Unsupported recorder operation at line {node.lineno}; no code was executed')
141
+ if len(args)>max_args or set(kwargs)-allowed:
142
+ raise ValueError(f'Unsupported arguments at line {node.lineno}')
143
+ actions.append(action)
144
+ walk(ast.parse(source).body)
145
+ if not actions:raise ValueError('No supported actions found')
146
+ return actions
147
+
148
+
149
+ def generate(source_path,package_id,guest_os='windows11',width=1920,height=1080,
150
+ coordinate_space='guest',viewport=None,package_root=None):
151
+ if not re.fullmatch('[a-z][a-z0-9_]*',package_id):raise ValueError('Invalid package id')
152
+ source_path=Path(source_path).expanduser().resolve()
153
+ raw=source_path.read_bytes()
154
+ actions=parse_recording(raw.decode('utf-8-sig'),width,height,coordinate_space,viewport)
155
+ parent=Path(package_root) if package_root else ROOT/'rpas'
156
+ target=parent/package_id
157
+ if target.exists():raise ValueError('Package already exists; use a new id to preserve manual edits')
158
+ held=set()
159
+ for action in actions:
160
+ if action['op']=='key_down':held.add(action['key'])
161
+ if action['op']=='key_up':held.discard(action['key'])
162
+ starts_launcher=(len(actions)>=2 and actions[0].get('op')=='key_down' and actions[0].get('key')=='super'
163
+ and actions[1].get('op')=='key_down' and actions[1].get('key','').lower()=='r') or (
164
+ actions[0].get('op')=='hotkey' and actions[0].get('keys')==['super','r'])
165
+ warnings=['Mechanical conversion only: review target positions and replace waits with state checks.',
166
+ 'Review all recorded input for private credentials before replay or sharing.']
167
+ if held:warnings.append(f'{len(held)} key(s) remain held at recording end; replay teardown will release them.')
168
+ if guest_os=='windows11' and not starts_launcher:warnings.append('No initial Win+R launcher detected; replace desktop-icon launch with a common launcher.')
169
+ manifest={'format_version':1,'id':package_id,'name':'Recorded '+package_id,'version':'0.1.0',
170
+ 'default_entrypoint':'run','entrypoints':[{'name':'run','file':'run.robot','credentials':'environment_or_prompt'}],
171
+ 'python_libraries':['workflow.py'],'dependencies':['spice','paddleocr_optional'],
172
+ 'skill':'spice-recording-convert','outputs':{'summary':'${OUTPUT DIR}/summary.json',
173
+ 'robot_log':'${OUTPUT DIR}/log.html','robot_report':'${OUTPUT DIR}/report.html'}}
174
+ report={'format_version':1,'source_name':source_path.name,'source_sha256':hashlib.sha256(raw).hexdigest(),
175
+ 'guest_os':guest_os,'coordinate_space':coordinate_space,'guest_resolution':[width,height],
176
+ 'action_count':len(actions),'operations':dict(Counter(a['op'] for a in actions)),
177
+ 'initial_win_r':starts_launcher,'requires_review':True,'warnings':warnings}
178
+ target.mkdir(parents=True)
179
+ for name,data in [('manifest.json',manifest),('conversion.json',report),
180
+ ('recording.local.json',{'format_version':1,'guest_os':guest_os,'resolution':[width,height],'actions':actions})]:
181
+ path=target/name;path.write_text(json.dumps(data,ensure_ascii=False,indent=2)+'\n')
182
+ if name=='recording.local.json':path.chmod(0o600)
183
+ (target/'workflow.py').write_text('''"""Generated adapter: keep detailed input and coordinates in Python/local data."""
184
+ from pathlib import Path
185
+ from robot.api.deco import library
186
+ from recording_runtime import RecordedWorkflow
187
+
188
+
189
+ @library(scope='SUITE',auto_keywords=False)
190
+ class Workflow(RecordedWorkflow):
191
+ def __init__(self):
192
+ super().__init__(Path(__file__).resolve().parent)
193
+ ''')
194
+ lines=['*** Settings ***','Resource ${CURDIR}/../common.resource',
195
+ 'Library ${CURDIR}/workflow.py WITH NAME Workflow',
196
+ 'Suite Setup Contract.Begin Result ${RPA_ID}',
197
+ 'Suite Teardown Stop RPA','Task Teardown End Recorded Task','',
198
+ '*** Variables ***',f'${{RPA_ID}} {package_id}',
199
+ '${ALLOW_REPLAY} ${FALSE}','${EXPECTED_TEXT} ${EMPTY}','${LANGUAGES} en','',
200
+ '*** Tasks ***','Replay Reviewed Guest Recording',
201
+ ' ${ready}= Workflow.Load Recording ${ALLOW_REPLAY}',
202
+ ' IF not $ready',' ${review}= Workflow.Review Result',
203
+ ' Contract.Publish Result ${review}',' Skip Review conversion.json and recording.local.json; set ALLOW_REPLAY only after review.',
204
+ ' END',' Spice.Connect Spice ${SPICE_URI}',' Workflow.Check Guest Geometry']
205
+ lines[lines.index(' ${review}= Workflow.Review Result')]=' ${review}= Workflow.Review Result'
206
+ lines.extend([' ${count}= Workflow.Action Count',
207
+ ' FOR ${index} IN RANGE ${count}',
208
+ ' Workflow.Replay Event ${index}',' END'])
209
+ lines.extend([' ${result}= Workflow.Verify Replay ${EXPECTED_TEXT} ${LANGUAGES}',
210
+ ' Contract.Publish Result ${result}',' Pause For User Verification ${result}',
211
+ ' Should Not Be Equal ${result}[status] verification_failed','','*** Keywords ***','End Recorded Task',
212
+ ' Run Keyword And Continue On Failure Workflow.Release Recorded Inputs',' Finish RPA Task',''])
213
+ (target/'run.robot').write_text('\n'.join(lines))
214
+ (target/'README.md').write_text(f'''# {package_id}\n\nGenerated from `{source_path.name}` without executing source code.\n\n- Guest: `{guest_os}`, {width}×{height}; source space: `{coordinate_space}`.\n- Review `conversion.json` and the private `recording.local.json` before replay.\n- `run.robot` controls the order; `workflow.py` and `recording_runtime.py` execute SPICE input.\n- Default run returns `needs_review` without connecting to the VM.\n- Explicit replay: `.venv/bin/python scripts/run_rpa.py {package_id} --var ALLOW_REPLAY:True --var SPICE_URI:<actual-guest-uri>`\n- No application success is claimed unless an expected OCR text is configured; otherwise result is `replayed_unverified`.\n- `recording.local.json` is excluded from Git because recorded keystrokes can contain credentials. Regenerate from a local source on a new checkout.\n- See [conversion guide](../../docs/RECORDING_CONVERSION.md) for refinement and credential replacement.\n''')
215
+ return {'status':'generated_needs_review','rpa_id':package_id,'package_path':str(target.resolve()),
216
+ 'action_count':len(actions),'initial_win_r':starts_launcher,'report':str((target/'conversion.json').resolve())}
217
+
218
+
219
+ def main():
220
+ parser=argparse.ArgumentParser()
221
+ parser.add_argument('source')
222
+ parser.add_argument('--id',required=True)
223
+ parser.add_argument('--guest-os',choices=['windows11','debian'],default='windows11')
224
+ parser.add_argument('--width',type=int,default=1920);parser.add_argument('--height',type=int,default=1080)
225
+ parser.add_argument('--coordinate-space',choices=['guest','host'],default='guest')
226
+ parser.add_argument('--viewport',type=float,nargs=4,metavar=('LEFT','TOP','WIDTH','HEIGHT'))
227
+ args=parser.parse_args()
228
+ try:result=generate(args.source,args.id,args.guest_os,args.width,args.height,args.coordinate_space,args.viewport)
229
+ except (ValueError,OSError,SyntaxError) as error:parser.error(str(error))
230
+ print(json.dumps(result,ensure_ascii=False,indent=2))
@@ -1,11 +1,11 @@
1
- # Optional stdio MCP server; install the host backend requirements separately.
2
- mcp==1.30.0
3
- robotframework==7.5.1
4
-
5
- pycdlib==1.14.0
6
-
7
- # Shared VNC control and optional Robot video recording
8
- asyncvnc==1.3.0
9
- imageio-ffmpeg==0.8.1
10
- PyYAML>=6.0
11
- requests>=2.31
1
+ # Optional stdio MCP server; install the host backend requirements separately.
2
+ mcp==1.30.0
3
+ robotframework==7.5.1
4
+
5
+ pycdlib==1.14.0
6
+
7
+ # Shared VNC control and optional Robot video recording
8
+ asyncvnc==1.3.0
9
+ imageio-ffmpeg==0.8.1
10
+ PyYAML>=6.0
11
+ requests>=2.31