@capagents/forgeqe 2.9.2 → 2.9.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.
- package/HOW_TO_USE.md +72 -11
- package/README.md +1 -1
- package/dist/docs-site/docs/architecture/index.html +6 -0
- package/dist/docs-site/docs/index.html +59 -2
- package/dist/docs-site/docs/search.js +1 -1
- package/dist/docs-site/docs/web-app/index.html +12 -1
- package/dist/forgeqe.js +1752 -1681
- package/dist/web/assets/Agent-djRg2i0o.js +7 -0
- package/dist/web/assets/ApiTests-Becz5PP-.js +10 -0
- package/dist/web/assets/Browse-_TcGuZ8l.js +2 -0
- package/dist/web/assets/Chat-VERzcB2r.js +3 -0
- package/dist/web/assets/CommandPalette-5QEcqEYi.js +1 -0
- package/dist/web/assets/{Compare-CGcGp9qD.js → Compare-Dl4z18KO.js} +1 -1
- package/dist/web/assets/Cost-B_i8IzAR.js +1 -0
- package/dist/web/assets/Data-DKSQEWFO.js +6 -0
- package/dist/web/assets/Desktop-DkNohPJ7.js +1 -0
- package/dist/web/assets/DesktopReview-BUgkvk9D.js +1 -0
- package/dist/web/assets/Evidence-Bmr0i0nA.js +1 -0
- package/dist/web/assets/{Explore-2M7wI0Sf.js → Explore-oz_P_CL1.js} +2 -2
- package/dist/web/assets/{Features-DmQ5JiMI.js → Features-CxcjdJkb.js} +1 -1
- package/dist/web/assets/{Flags-Bg-l5HxL.js → Flags-DF0H61Vl.js} +2 -2
- package/dist/web/assets/{Flaky-DJlkxmHT.js → Flaky-DkjqrHrF.js} +1 -1
- package/dist/web/assets/{ForceGraph-B5i3Ewd5.js → ForceGraph-i1zlas5l.js} +1 -1
- package/dist/web/assets/Impact-DiTAOm8k.js +3 -0
- package/dist/web/assets/Jobs-DR_mV4Mu.js +5 -0
- package/dist/web/assets/KindPage-CLRfAada.js +6 -0
- package/dist/web/assets/Migration-DQgCEr0G.js +2 -0
- package/dist/web/assets/{Product-BHqJVCMn.js → Product-165KSr60.js} +3 -3
- package/dist/web/assets/{Production-GL8lbwxD.js → Production-DoF4CcF-.js} +1 -1
- package/dist/web/assets/{Quality-jI3YgvqZ.js → Quality-CEVce0Rs.js} +1 -1
- package/dist/web/assets/{Readiness-B3OZ51FG.js → Readiness-DcnpsaAD.js} +1 -1
- package/dist/web/assets/Record-B7hLtTK5.js +2 -0
- package/dist/web/assets/Regression-BMftRz5h.js +5 -0
- package/dist/web/assets/{Reports-BAat71wo.js → Reports-sL20ZyMf.js} +2 -2
- package/dist/web/assets/{Response-DjqmewrL.js → Response-C2roHnWk.js} +2 -2
- package/dist/web/assets/{RunDiff-BbBom2fJ.js → RunDiff-C0AZaAAA.js} +1 -1
- package/dist/web/assets/{Runs-CIQWWRl3.js → Runs-CIgHrNZ7.js} +2 -2
- package/dist/web/assets/Steps-GPPeoUP-.js +2 -0
- package/dist/web/assets/{TestCases-8BBW6RSi.js → TestCases-xpJiurmK.js} +1 -1
- package/dist/web/assets/TestData-D07oKCRW.js +2 -0
- package/dist/web/assets/TestDebt-BaXdxqnZ.js +1 -0
- package/dist/web/assets/Tosca-BfIh2vCw.js +3 -0
- package/dist/web/assets/{WhatsNew-CBS7kmGu.js → WhatsNew-rQKGxI3X.js} +1 -1
- package/dist/web/assets/{dataParts-B3Fz4S59.js → dataParts-D9LZxYD6.js} +3 -3
- package/dist/web/assets/{families-BiqSaqoO.js → families-DlfXDoO8.js} +1 -1
- package/dist/web/assets/filters-NVjc0d8i.js +1 -0
- package/dist/web/assets/{fold-b2g0_ndv.js → fold-D1JElpyx.js} +1 -1
- package/dist/web/assets/frame-CgFXIaLn.js +4 -0
- package/dist/web/assets/index-BoLw7yMm.js +73 -0
- package/dist/web/assets/index-RzPHjTCW.css +2 -0
- package/dist/web/assets/{logos-DSveGjIW.js → logos-BGd4nsug.js} +1 -1
- package/dist/web/assets/{palette-CF8GLAVN.js → palette-BWPcuOsU.js} +1 -1
- package/dist/web/assets/{parts-D7OvxdrL.js → parts-W2J4TR3o.js} +1 -1
- package/dist/web/assets/{productParts-BDM3LIjp.js → productParts-_8gKGn4o.js} +1 -1
- package/dist/web/assets/{qualityParts-DP09bVel.js → qualityParts-9olnn4fj.js} +1 -1
- package/dist/web/assets/recordTest-etYNiLQy.js +1 -0
- package/dist/web/assets/{rows-B0vZ5x5N.js → rows-BWeaaykT.js} +1 -1
- package/dist/web/assets/{segmented-BfWimTC0.js → segmented-B7n6eLrO.js} +1 -1
- package/dist/web/assets/{thread-DASfqw-f.js → thread-B8W__QtF.js} +1 -1
- package/dist/web/assets/{usePageChat-BLEUldCJ.js → usePageChat-DvfE62rZ.js} +1 -1
- package/dist/web/index.html +4 -4
- package/docs/ARCHITECTURE.md +5 -0
- package/docs/WEB_APP.md +17 -1
- package/docs/user-guide.html +59 -2
- package/forgeqe.example.yaml +3 -1
- package/package.json +1 -1
- package/prompts/README.md +1 -0
- package/prompts/brain.md +9 -0
- package/prompts/business-persona.md +62 -0
- package/py/forgeqe_desktop/agentdesktop_driver.py +69 -0
- package/py/forgeqe_desktop/boxes.py +32 -0
- package/py/forgeqe_desktop/handhooks.py +55 -5
- package/py/forgeqe_desktop/pywinauto_driver.py +25 -0
- package/py/forgeqe_desktop/service.py +85 -3
- package/py/forgeqe_engine/brand.py +3 -0
- package/py/forgeqe_engine/browser.py +46 -6
- package/py/forgeqe_engine/cli.py +10 -1
- package/py/forgeqe_engine/recordsession.py +92 -2
- package/py/forgeqe_engine/video.py +423 -0
- package/py/forgeqe_mobile/hyperexecute.py +1 -1
- package/py/forgeqe_mobile/maestro.py +1 -1
- package/py/forgeqe_tosca/vendored.py +3 -2
- package/skills/bdd-gherkin/SKILL.md +141 -0
- package/skills/bdd-gherkin/references/cucumber-js.md +52 -0
- package/skills/bdd-gherkin/references/cucumber-jvm.md +54 -0
- package/skills/bdd-gherkin/references/python-bdd.md +50 -0
- package/skills/bdd-gherkin/references/reqnroll-specflow.md +83 -0
- package/skills/bdd-gherkin/references/review-checklist.md +37 -0
- package/skills/bdd-scenario-design/SKILL.md +50 -0
- package/skills/dynamics-365/SKILL.md +30 -15
- package/skills/dynamics-365-automation/SKILL.md +72 -0
- package/skills/dynamics-365-automation/references/elements.md +187 -0
- package/skills/dynamics-365-automation/references/recipes.md +97 -0
- package/dist/web/assets/Agent-BFwkMMHm.js +0 -4
- package/dist/web/assets/ApiTests-Bgt4R_yB.js +0 -10
- package/dist/web/assets/Browse-B3YI1MeV.js +0 -2
- package/dist/web/assets/Chat-K3kp-ji2.js +0 -3
- package/dist/web/assets/CommandPalette-nmLCmEsp.js +0 -1
- package/dist/web/assets/Cost-BvCShgln.js +0 -1
- package/dist/web/assets/Data-3EEe7vIz.js +0 -6
- package/dist/web/assets/Desktop-Drj-7jBV.js +0 -1
- package/dist/web/assets/Evidence-D1HiXQK6.js +0 -1
- package/dist/web/assets/Impact-huKs-mOc.js +0 -3
- package/dist/web/assets/Jobs-BwK79TQ8.js +0 -5
- package/dist/web/assets/KindPage-C0MoC9da.js +0 -6
- package/dist/web/assets/Migration-CTVyQeqW.js +0 -2
- package/dist/web/assets/Record-Yw-SGwQ9.js +0 -2
- package/dist/web/assets/Regression-v2dpbgs4.js +0 -5
- package/dist/web/assets/Steps-DfNHCe8N.js +0 -2
- package/dist/web/assets/TestData-BFkACDve.js +0 -2
- package/dist/web/assets/TestDebt-CUcklHEN.js +0 -1
- package/dist/web/assets/Tosca-DTWwUJBW.js +0 -3
- package/dist/web/assets/desktopAppPath-CMac6aJ0.js +0 -1
- package/dist/web/assets/filters-B4VDnWbr.js +0 -1
- package/dist/web/assets/frame-D-hqu7Oi.js +0 -4
- package/dist/web/assets/index-CtX74khE.js +0 -45
- package/dist/web/assets/index-DUf5ddb0.css +0 -2
|
@@ -41,6 +41,7 @@ from dataclasses import dataclass, field
|
|
|
41
41
|
from typing import Any, Callable, Dict, Iterator, List, Mapping, Optional, Sequence, Set, Tuple
|
|
42
42
|
|
|
43
43
|
from .apps import AppSpec
|
|
44
|
+
from .boxes import SNAPSHOT_LIMIT, snapshot_boxes
|
|
44
45
|
from .replay import ControlNotFound
|
|
45
46
|
from .workflow import MODIFIERS, WorkflowError, parse_chord
|
|
46
47
|
|
|
@@ -209,6 +210,27 @@ def _text(node: Mapping[str, Any], key: str) -> str:
|
|
|
209
210
|
return v if isinstance(v, str) else ""
|
|
210
211
|
|
|
211
212
|
|
|
213
|
+
def _rect(b: Any) -> Optional[Tuple[int, int, int, int]]:
|
|
214
|
+
"""agent-desktop's bounds ({x, y, width, height}) as left, top, right, bottom; None unless all four are numbers."""
|
|
215
|
+
if not isinstance(b, dict):
|
|
216
|
+
return None
|
|
217
|
+
try:
|
|
218
|
+
x, y, w, h = (b[k] for k in ("x", "y", "width", "height"))
|
|
219
|
+
except KeyError:
|
|
220
|
+
return None
|
|
221
|
+
if not all(isinstance(v, (int, float)) and not isinstance(v, bool) for v in (x, y, w, h)) or w <= 0 or h <= 0:
|
|
222
|
+
return None
|
|
223
|
+
return int(round(x)), int(round(y)), int(round(x + w)), int(round(y + h))
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _secret_field(node: Mapping[str, Any]) -> bool:
|
|
227
|
+
"""A field whose text is not kept: one marked secure or protected, or one named or identified like a password."""
|
|
228
|
+
role = _text(node, "role").lower()
|
|
229
|
+
if "secure" in role or "password" in role or node.get("is_password") is True or node.get("protected") is True:
|
|
230
|
+
return True
|
|
231
|
+
return bool(re.search(r"pass(word|wd)?|pin|secret", f"{_text(node, 'name')} {_native_id(node)}", re.I))
|
|
232
|
+
|
|
233
|
+
|
|
212
234
|
def _walk(node: Any, ancestors: Tuple[Mapping[str, Any], ...] = (), depth: int = 0) -> Iterator[Tuple[Mapping[str, Any], Tuple[Mapping[str, Any], ...]]]:
|
|
213
235
|
if not isinstance(node, dict) or depth > 200:
|
|
214
236
|
return
|
|
@@ -591,6 +613,53 @@ class AgentDesktopDriver:
|
|
|
591
613
|
return out
|
|
592
614
|
return out
|
|
593
615
|
|
|
616
|
+
# Most controls asked for their bounds when a snapshot does not give them, and how long that may take.
|
|
617
|
+
BOUNDS_CALLS = 80
|
|
618
|
+
BOUNDS_SECONDS = 3.0
|
|
619
|
+
|
|
620
|
+
def controls_snapshot(self) -> Optional[Dict[str, Any]]:
|
|
621
|
+
"""
|
|
622
|
+
The first window's controls as its picture shows them (snapshot_boxes): from one snapshot, each control's bounds
|
|
623
|
+
from the snapshot when it gives them, else asked of its ref (at most BOUNDS_CALLS, within BOUNDS_SECONDS); a
|
|
624
|
+
control with neither is left out, and a password field's text is never kept. None when nothing can be read.
|
|
625
|
+
"""
|
|
626
|
+
if not self.pids:
|
|
627
|
+
return None
|
|
628
|
+
try:
|
|
629
|
+
windows = self._windows()
|
|
630
|
+
if not windows:
|
|
631
|
+
return None
|
|
632
|
+
win = _rect(windows[0].get("bounds"))
|
|
633
|
+
if win is None:
|
|
634
|
+
return None
|
|
635
|
+
snap = self._snapshot(windows[0]["id"])
|
|
636
|
+
items: List[Tuple[Tuple[int, int, int, int], Dict[str, str], str, bool]] = []
|
|
637
|
+
calls, started = 0, time.monotonic()
|
|
638
|
+
for node, _ in _walk(snap.get("tree")):
|
|
639
|
+
props = {"automation_id": _native_id(node), "name": plain(_text(node, "name"), 300), "control_type": control_type_of(_text(node, "role"))}
|
|
640
|
+
if not props["automation_id"] and not props["name"]:
|
|
641
|
+
continue
|
|
642
|
+
rect = _rect(node.get("bounds"))
|
|
643
|
+
ref = node.get("ref_id")
|
|
644
|
+
if rect is None and isinstance(ref, str) and REF.match(ref) and calls < self.BOUNDS_CALLS and time.monotonic() - started < self.BOUNDS_SECONDS:
|
|
645
|
+
calls += 1
|
|
646
|
+
try:
|
|
647
|
+
got = self._call("get", ref, "--property", "bounds")
|
|
648
|
+
rect = _rect(got.get("value") if isinstance(got, dict) else None)
|
|
649
|
+
except AgentDesktopError as e:
|
|
650
|
+
if not e.safe:
|
|
651
|
+
raise
|
|
652
|
+
if rect is None:
|
|
653
|
+
continue
|
|
654
|
+
password = _secret_field(node)
|
|
655
|
+
text = "" if password else plain(_text(node, "value") or _text(node, "name"), 300)
|
|
656
|
+
items.append((rect, props, text, password))
|
|
657
|
+
if len(items) >= SNAPSHOT_LIMIT:
|
|
658
|
+
break
|
|
659
|
+
return snapshot_boxes(win, items)
|
|
660
|
+
except Exception:
|
|
661
|
+
return None
|
|
662
|
+
|
|
594
663
|
def _capture(self, window: str) -> Optional[bytes]:
|
|
595
664
|
make_private(self.home)
|
|
596
665
|
fd, path = tempfile.mkstemp(suffix=".png", dir=self.home)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""The controls a step's picture shows, for choosing a check by clicking it: the same shape from either driver."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, Dict, List, Tuple
|
|
6
|
+
|
|
7
|
+
# Most controls a picture's list holds, and the longest text kept of one.
|
|
8
|
+
SNAPSHOT_LIMIT = 300
|
|
9
|
+
SNAPSHOT_TEXT = 300
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def snapshot_boxes(window: Tuple[int, int, int, int], items: List[Tuple[Tuple[int, int, int, int], Dict[str, str], str, bool]]) -> Dict[str, Any]:
|
|
13
|
+
"""
|
|
14
|
+
The controls a window's picture shows, for choosing a check by clicking it: each one's box relative to the window
|
|
15
|
+
(as the picture is), its plain properties, and the text it shows (never a password field's), only those inside
|
|
16
|
+
the window with a size.
|
|
17
|
+
"""
|
|
18
|
+
left, top, right, bottom = window
|
|
19
|
+
w, h = max(0, right - left), max(0, bottom - top)
|
|
20
|
+
out: List[Dict[str, Any]] = []
|
|
21
|
+
for (l, t, r, b), props, text, password in items:
|
|
22
|
+
x, y, bw, bh = l - left, t - top, r - l, b - t
|
|
23
|
+
if bw <= 0 or bh <= 0 or x < 0 or y < 0 or x + bw > w or y + bh > h:
|
|
24
|
+
continue
|
|
25
|
+
keep = {k: v[:SNAPSHOT_TEXT] for k, v in props.items() if k in ("automation_id", "name", "control_type") and isinstance(v, str) and v}
|
|
26
|
+
if not keep.get("automation_id") and not keep.get("name"):
|
|
27
|
+
continue
|
|
28
|
+
shown = "" if password else " ".join(str(text or "").split())[:SNAPSHOT_TEXT]
|
|
29
|
+
out.append({"x": x, "y": y, "w": bw, "h": bh, **keep, **({"text": shown} if shown else {})})
|
|
30
|
+
if len(out) >= SNAPSHOT_LIMIT:
|
|
31
|
+
break
|
|
32
|
+
return {"w": w, "h": h, "controls": out}
|
|
@@ -284,6 +284,43 @@ def handle_event(ev: tuple, uia: Any, recorder: HandRecorder, events: "queue.Que
|
|
|
284
284
|
return None
|
|
285
285
|
|
|
286
286
|
|
|
287
|
+
def shown_step(step: Dict[str, Any]) -> Dict[str, Any]:
|
|
288
|
+
"""A recorded step as the page shows it: what was done, to which control, and the text typed, chosen or checked."""
|
|
289
|
+
out = {k: v for k, v in step.items() if k in ("op", "target", "keys", "value")}
|
|
290
|
+
if "value" not in out and isinstance(step.get("text"), str):
|
|
291
|
+
out["value"] = step["text"]
|
|
292
|
+
return out
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def changed_steps(steps: List[Dict[str, Any]], sent: Dict[int, Dict[str, Any]]) -> List[Dict[str, Any]]:
|
|
296
|
+
"""The steps after the launch that are new or changed since they were last sent (typing goes on in one step), each
|
|
297
|
+
with its 1-based index; ``sent`` is updated."""
|
|
298
|
+
out = []
|
|
299
|
+
for i in range(1, len(steps)):
|
|
300
|
+
shown = shown_step(steps[i])
|
|
301
|
+
if sent.get(i) != shown:
|
|
302
|
+
sent[i] = shown
|
|
303
|
+
out.append({"index": i + 1, **shown})
|
|
304
|
+
return out
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
class ShotQueue:
|
|
308
|
+
"""When to take each step's picture: a moment after the step is done or changes, so the app has drawn its result."""
|
|
309
|
+
|
|
310
|
+
def __init__(self, settle: float = 0.6) -> None:
|
|
311
|
+
self.settle = settle
|
|
312
|
+
self.due: Dict[int, float] = {}
|
|
313
|
+
|
|
314
|
+
def add(self, index: int, now: float) -> None:
|
|
315
|
+
self.due[index] = now + self.settle
|
|
316
|
+
|
|
317
|
+
def ready(self, now: float, all_of_them: bool = False) -> List[int]:
|
|
318
|
+
out = sorted(i for i, t in self.due.items() if all_of_them or t <= now)
|
|
319
|
+
for i in out:
|
|
320
|
+
del self.due[i]
|
|
321
|
+
return out
|
|
322
|
+
|
|
323
|
+
|
|
287
324
|
def record_by_hand(
|
|
288
325
|
driver: Any,
|
|
289
326
|
spec: Any,
|
|
@@ -292,6 +329,7 @@ def record_by_hand(
|
|
|
292
329
|
log: Callable[[str], None] = lambda s: None,
|
|
293
330
|
on_change: Callable[[Dict[str, Any]], None] = lambda e: None,
|
|
294
331
|
max_seconds: float = 3 * 3600,
|
|
332
|
+
on_shot: Optional[Callable[[int], None]] = None,
|
|
295
333
|
) -> str:
|
|
296
334
|
"""Start the app, record until the hotkey, the app closing, ``stop``, or ``max_seconds``; why it stopped."""
|
|
297
335
|
if sys.platform != "win32":
|
|
@@ -305,7 +343,13 @@ def record_by_hand(
|
|
|
305
343
|
hooks.start()
|
|
306
344
|
log(f"Recording {spec.name}: do the steps in the app. {CHECK_HINT} adds a check of the control under the mouse; {STOP_HINT} or closing the app stops.")
|
|
307
345
|
started = time.time()
|
|
308
|
-
|
|
346
|
+
# Each step as last sent to the page: one is sent again when it changes, not only when a step is added.
|
|
347
|
+
sent: Dict[int, Dict[str, Any]] = {}
|
|
348
|
+
changed_steps(recorder.steps, sent)
|
|
349
|
+
# Each step's picture a moment after it (the app started is step 1), when asked for.
|
|
350
|
+
shots = ShotQueue()
|
|
351
|
+
if on_shot is not None:
|
|
352
|
+
shots.add(1, time.time())
|
|
309
353
|
reason = "stopped"
|
|
310
354
|
last_alive = 0.0
|
|
311
355
|
try:
|
|
@@ -324,10 +368,12 @@ def record_by_hand(
|
|
|
324
368
|
if handle_event(ev, uia, recorder, events, log) == "stop":
|
|
325
369
|
reason = "hotkey"
|
|
326
370
|
break
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
371
|
+
for change in changed_steps(recorder.steps, sent):
|
|
372
|
+
on_change(change)
|
|
373
|
+
shots.add(change["index"], time.time())
|
|
374
|
+
if on_shot is not None:
|
|
375
|
+
for i in shots.ready(time.time()):
|
|
376
|
+
on_shot(i)
|
|
331
377
|
if time.time() - last_alive > 1.0:
|
|
332
378
|
last_alive = time.time()
|
|
333
379
|
try:
|
|
@@ -339,4 +385,8 @@ def record_by_hand(
|
|
|
339
385
|
break
|
|
340
386
|
finally:
|
|
341
387
|
hooks.stop()
|
|
388
|
+
# The last steps' pictures, before the app is closed (an app already closed has none to give).
|
|
389
|
+
if on_shot is not None and reason != "app closed":
|
|
390
|
+
for i in shots.ready(time.time(), all_of_them=True):
|
|
391
|
+
on_shot(i)
|
|
342
392
|
return reason
|
|
@@ -65,6 +65,9 @@ def _is_password(control: Any) -> bool:
|
|
|
65
65
|
return False
|
|
66
66
|
|
|
67
67
|
|
|
68
|
+
from .boxes import SNAPSHOT_LIMIT, snapshot_boxes # noqa: F401 (the picture's controls, shared with agent-desktop)
|
|
69
|
+
|
|
70
|
+
|
|
68
71
|
def foreground_owner() -> Optional[int]:
|
|
69
72
|
"""The process id owning the window in front, or None when it cannot be told."""
|
|
70
73
|
try:
|
|
@@ -399,6 +402,28 @@ class PywinautoDriver:
|
|
|
399
402
|
except Exception:
|
|
400
403
|
return None
|
|
401
404
|
|
|
405
|
+
def controls_snapshot(self) -> Optional[Dict[str, Any]]:
|
|
406
|
+
"""The top window's controls as its picture shows them (snapshot_boxes), or None when they cannot be read."""
|
|
407
|
+
if self.app is None:
|
|
408
|
+
return None
|
|
409
|
+
try:
|
|
410
|
+
win = self.app.top_window().wrapper_object()
|
|
411
|
+
r = win.rectangle()
|
|
412
|
+
items = []
|
|
413
|
+
for c in win.descendants()[: SNAPSHOT_LIMIT * 3]:
|
|
414
|
+
info = c.element_info
|
|
415
|
+
rc = info.rectangle
|
|
416
|
+
props = {"automation_id": info.automation_id or "", "name": info.name or "", "control_type": info.control_type or ""}
|
|
417
|
+
password = _is_password(c)
|
|
418
|
+
try:
|
|
419
|
+
text = "" if password else self.text_of(c)
|
|
420
|
+
except Exception:
|
|
421
|
+
text = ""
|
|
422
|
+
items.append(((rc.left, rc.top, rc.right, rc.bottom), props, text, password))
|
|
423
|
+
return snapshot_boxes((r.left, r.top, r.right, r.bottom), items)
|
|
424
|
+
except Exception:
|
|
425
|
+
return None
|
|
426
|
+
|
|
402
427
|
def close(self) -> None:
|
|
403
428
|
"""Close the app this driver started, and only that one: a polite close first, then terminate."""
|
|
404
429
|
if self.app is not None:
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
browser engine. A later ``stop`` line on stdin stops a replay between steps, or ends a recording.
|
|
4
4
|
|
|
5
5
|
Request: ``mode`` (``replay``, ``explore`` or ``record``), ``out_dir``, ``desktop`` (``apps``, ``secrets``,
|
|
6
|
-
``ufo_dir
|
|
6
|
+
``ufo_dir``, ``video`` (true: video.mp4 of the screen while the request runs, forgeqe_engine.video); for replay ``driver`` (``pywinauto`` or ``agent-desktop``), ``headed`` and ``agent_desktop.path``), ``llm`` and ``profile_name`` (the llms.json profile, for healing and explore), and per mode: ``workflow``,
|
|
7
7
|
``variables``, ``heal``, ``screenshots``, ``update_baselines`` (replay); ``goal``, ``app``, ``name`` (explore); ``app``,
|
|
8
8
|
``name`` (record: the tester does the steps by hand).
|
|
9
9
|
|
|
@@ -127,6 +127,7 @@ def run_replay(req: Mapping[str, Any], events: Events, driver: Any, stop: thread
|
|
|
127
127
|
if png:
|
|
128
128
|
shot = f"steps/{res.index:03d}.png"
|
|
129
129
|
(out / shot).write_bytes(png)
|
|
130
|
+
write_controls(driver, out / "steps" / f"{res.index:03d}.json")
|
|
130
131
|
events.emit({"type": "step", **_step_fields(res), "screenshot": shot})
|
|
131
132
|
|
|
132
133
|
result = replay(
|
|
@@ -345,6 +346,32 @@ def _explored_from_memory(req: Mapping[str, Any], events: Events, driver: Any, m
|
|
|
345
346
|
}
|
|
346
347
|
|
|
347
348
|
|
|
349
|
+
def write_controls(driver: Any, file: Path) -> None:
|
|
350
|
+
"""Beside a step's picture, the controls it shows (where each is, what it is called and shows), so a check can be
|
|
351
|
+
chosen by clicking the picture. Nothing when the driver cannot tell."""
|
|
352
|
+
snap = getattr(driver, "controls_snapshot", None)
|
|
353
|
+
if snap is None:
|
|
354
|
+
return
|
|
355
|
+
try:
|
|
356
|
+
boxes = snap()
|
|
357
|
+
except Exception:
|
|
358
|
+
boxes = None
|
|
359
|
+
if boxes and boxes.get("controls"):
|
|
360
|
+
file.write_text(json.dumps(boxes), encoding="utf-8")
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def recording_shots(steps: List[Dict[str, Any]], out: Path) -> List[Dict[str, Any]]:
|
|
364
|
+
"""Each recorded step's picture with what the step does and to which control, so a review finds a step's picture
|
|
365
|
+
by the step itself, after steps are added or removed."""
|
|
366
|
+
shots = []
|
|
367
|
+
for i, s in enumerate(steps, 1):
|
|
368
|
+
file = f"steps/{i:03d}.png"
|
|
369
|
+
if (out / file).is_file():
|
|
370
|
+
t = s.get("target") if isinstance(s.get("target"), dict) else {}
|
|
371
|
+
shots.append({"index": i, "file": file, "op": s.get("op"), "target": {k: t[k] for k in ("automation_id", "name", "control_type") if k in t}})
|
|
372
|
+
return shots
|
|
373
|
+
|
|
374
|
+
|
|
348
375
|
def run_record(req: Mapping[str, Any], events: Events, driver: Any, stop: threading.Event, recorder_loop: Optional[Callable[..., str]] = None) -> Dict[str, Any]:
|
|
349
376
|
"""Recording by hand: the tester does the steps, their clicks and keys become workflow.yaml. No model."""
|
|
350
377
|
from .handrecord import HandRecorder
|
|
@@ -363,8 +390,26 @@ def run_record(req: Mapping[str, Any], events: Events, driver: Any, stop: thread
|
|
|
363
390
|
started = time.time()
|
|
364
391
|
reason = ""
|
|
365
392
|
error = ""
|
|
393
|
+
# Each step's picture as the app showed it, as replay keeps them: steps/NNN.png in the run folder.
|
|
394
|
+
grab = getattr(driver, "screenshot_png", None)
|
|
395
|
+
want_shots = bool(req.get("screenshots", True)) and grab is not None
|
|
396
|
+
if want_shots:
|
|
397
|
+
(out / "steps").mkdir(exist_ok=True)
|
|
398
|
+
|
|
399
|
+
def on_shot(index: int) -> None:
|
|
400
|
+
try:
|
|
401
|
+
png = grab() if grab is not None else None
|
|
402
|
+
except Exception:
|
|
403
|
+
png = None
|
|
404
|
+
if png and 0 < index < 1000:
|
|
405
|
+
(out / "steps" / f"{index:03d}.png").write_bytes(png)
|
|
406
|
+
write_controls(driver, out / "steps" / f"{index:03d}.json")
|
|
407
|
+
|
|
366
408
|
try:
|
|
367
|
-
|
|
409
|
+
loop_kwargs: Dict[str, Any] = {"log": events.log, "on_change": lambda e: events.emit({"type": "recorded", **e})}
|
|
410
|
+
if want_shots:
|
|
411
|
+
loop_kwargs["on_shot"] = on_shot
|
|
412
|
+
reason = recorder_loop(driver, spec, recorder, stop, **loop_kwargs)
|
|
368
413
|
except Exception as e:
|
|
369
414
|
error = f"Recording stopped with an error: {type(e).__name__}: {e}"[:2000]
|
|
370
415
|
events.log(error, "error")
|
|
@@ -380,6 +425,10 @@ def run_record(req: Mapping[str, Any], events: Events, driver: Any, stop: thread
|
|
|
380
425
|
if recorded:
|
|
381
426
|
save(workflow, workflow_file)
|
|
382
427
|
checks = sum(1 for s in workflow["steps"] if s["op"] == "expect")
|
|
428
|
+
shots = recording_shots(workflow["steps"], out) if recorded else []
|
|
429
|
+
if shots:
|
|
430
|
+
(out / "shots.json").write_text(json.dumps(shots, indent=2), encoding="utf-8")
|
|
431
|
+
shot_of = {s["index"]: s["file"] for s in shots}
|
|
383
432
|
return {
|
|
384
433
|
"mode": "record",
|
|
385
434
|
"ok": recorded > 0 and not error,
|
|
@@ -392,7 +441,7 @@ def run_record(req: Mapping[str, Any], events: Events, driver: Any, stop: thread
|
|
|
392
441
|
"secrets": list(recorder.secrets_used),
|
|
393
442
|
"skipped": skipped,
|
|
394
443
|
"workflow": str(workflow_file) if recorded else None,
|
|
395
|
-
"steps": [{"index": i, "op": s["op"], "ok": True, "ms": 0, "target": s.get("target")} for i, s in enumerate(workflow["steps"], 1)],
|
|
444
|
+
"steps": [{"index": i, "op": s["op"], "ok": True, "ms": 0, "target": s.get("target"), "screenshot": shot_of.get(i)} for i, s in enumerate(workflow["steps"], 1)],
|
|
396
445
|
"error": error or ("" if recorded else "nothing was recorded: no click or typing in the app's windows"),
|
|
397
446
|
}
|
|
398
447
|
|
|
@@ -414,6 +463,29 @@ def default_driver(req: Mapping[str, Any]) -> Any:
|
|
|
414
463
|
return PywinautoDriver()
|
|
415
464
|
|
|
416
465
|
|
|
466
|
+
VIDEO_FILE = "video.mp4"
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
def _start_screen(req: Mapping[str, Any], events: Events, out: Path, factory: Optional[Callable[[Path], Any]] = None) -> Any:
|
|
470
|
+
"""desktop.video: the screen as video.mp4 in the run folder while the request runs; None (said once) when it cannot be."""
|
|
471
|
+
desktop = req.get("desktop") if isinstance(req.get("desktop"), dict) else {}
|
|
472
|
+
if desktop.get("video") is not True:
|
|
473
|
+
return None
|
|
474
|
+
if factory is not None:
|
|
475
|
+
screen = factory(out / VIDEO_FILE)
|
|
476
|
+
else:
|
|
477
|
+
try:
|
|
478
|
+
from forgeqe_engine.video import ScreenVideo
|
|
479
|
+
except Exception as e:
|
|
480
|
+
events.log(f"No video of this run: {type(e).__name__}", "warn")
|
|
481
|
+
return None
|
|
482
|
+
screen = ScreenVideo(out / VIDEO_FILE)
|
|
483
|
+
if not screen.start():
|
|
484
|
+
events.log(f"No video of this run: {screen.error}", "warn")
|
|
485
|
+
return None
|
|
486
|
+
return screen
|
|
487
|
+
|
|
488
|
+
|
|
417
489
|
def _watch_stop(stream: IO[str], stop: threading.Event) -> None:
|
|
418
490
|
for line in stream:
|
|
419
491
|
if line.strip() == "stop":
|
|
@@ -428,11 +500,13 @@ def serve(
|
|
|
428
500
|
runner: Optional[Callable[..., List[Dict[str, Any]]]] = None,
|
|
429
501
|
model_factory: Optional[Callable[..., Any]] = None,
|
|
430
502
|
recorder_loop: Optional[Callable[..., str]] = None,
|
|
503
|
+
screen_factory: Optional[Callable[[Path], Any]] = None,
|
|
431
504
|
) -> int:
|
|
432
505
|
events = Events(stdout)
|
|
433
506
|
stop = threading.Event()
|
|
434
507
|
result: Dict[str, Any]
|
|
435
508
|
out: Optional[Path] = None
|
|
509
|
+
screen: Any = None
|
|
436
510
|
driver_name = ""
|
|
437
511
|
req_mode = ""
|
|
438
512
|
try:
|
|
@@ -446,6 +520,8 @@ def serve(
|
|
|
446
520
|
req_mode = str(mode or "")
|
|
447
521
|
driver = driver_factory() if driver_factory is not None else default_driver(req)
|
|
448
522
|
driver_name = str(getattr(driver, "name", "") or "")
|
|
523
|
+
if mode in ("replay", "explore", "record"):
|
|
524
|
+
screen = _start_screen(req, events, out, screen_factory)
|
|
449
525
|
if mode == "replay":
|
|
450
526
|
result = run_replay(req, events, driver, stop, model_factory)
|
|
451
527
|
elif mode == "explore":
|
|
@@ -456,6 +532,12 @@ def serve(
|
|
|
456
532
|
raise WorkflowError(f"mode must be replay, explore or record, not {mode!r}")
|
|
457
533
|
except Exception as e:
|
|
458
534
|
result = {"ok": False, "error": f"{type(e).__name__}: {e}" if not isinstance(e, (WorkflowError, ValueError)) else str(e)}
|
|
535
|
+
if screen is not None:
|
|
536
|
+
# Finished before run.json is written, so the report finds it (video.mp4 beside run.json).
|
|
537
|
+
if screen.close():
|
|
538
|
+
result["video"] = VIDEO_FILE
|
|
539
|
+
else:
|
|
540
|
+
events.log(f"No video of this run: {screen.error or 'nothing was recorded'}", "warn")
|
|
459
541
|
result.setdefault("format", FORMAT)
|
|
460
542
|
if driver_name and result.get("mode", req_mode) == "replay":
|
|
461
543
|
result.setdefault("driver", driver_name)
|
|
@@ -291,6 +291,9 @@ def install() -> None:
|
|
|
291
291
|
from browser_use.browser.watchdogs.aboutblank_watchdog import AboutBlankWatchdog
|
|
292
292
|
except ImportError:
|
|
293
293
|
return
|
|
294
|
+
from .browser import take_edge_new_tab
|
|
295
|
+
|
|
296
|
+
take_edge_new_tab()
|
|
294
297
|
|
|
295
298
|
async def start_page(self: Any, target_id: Any, *args: Any, **kwargs: Any) -> None:
|
|
296
299
|
overlay = _OVERLAYS.get(id(self.browser_session))
|
|
@@ -366,6 +366,34 @@ def install_patient_start() -> None:
|
|
|
366
366
|
|
|
367
367
|
if getattr(LocalBrowserWatchdog._wait_for_cdp_url, "__name__", "") != "wait_for_devtools":
|
|
368
368
|
LocalBrowserWatchdog._wait_for_cdp_url = staticmethod(wait_for_devtools)
|
|
369
|
+
take_edge_new_tab()
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
# Microsoft Edge's new tab page. Edge opens it in its first window, and the library takes only Chrome's for a blank tab:
|
|
373
|
+
# a run, a recording and the start page met Edge's news page (which the tab then loads) instead of a blank tab.
|
|
374
|
+
_EDGE_NEW_TAB = ("edge://newtab/", "edge://newtab")
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def take_edge_new_tab() -> None:
|
|
378
|
+
"""Have the library treat Edge's new tab page as Chrome's: turned into a blank tab when the browser starts."""
|
|
379
|
+
try:
|
|
380
|
+
import browser_use.utils as utils
|
|
381
|
+
except ImportError:
|
|
382
|
+
return
|
|
383
|
+
original = utils.is_new_tab_page
|
|
384
|
+
if getattr(original, "__forgeqe__", False):
|
|
385
|
+
return
|
|
386
|
+
|
|
387
|
+
def is_new_tab_page(url: str) -> bool:
|
|
388
|
+
return original(url) or url in _EDGE_NEW_TAB
|
|
389
|
+
|
|
390
|
+
is_new_tab_page.__forgeqe__ = True # type: ignore[attr-defined]
|
|
391
|
+
utils.is_new_tab_page = is_new_tab_page
|
|
392
|
+
# Modules that imported the check by name keep their own reference.
|
|
393
|
+
for name in ("browser_use.browser.session", "browser_use.agent.prompts", "browser_use.tools.registry.service"):
|
|
394
|
+
module = sys.modules.get(name)
|
|
395
|
+
if module is not None and getattr(module, "is_new_tab_page", None) is original:
|
|
396
|
+
module.is_new_tab_page = is_new_tab_page
|
|
369
397
|
|
|
370
398
|
|
|
371
399
|
def find_playwright_chromium() -> Optional[str]:
|
|
@@ -771,7 +799,7 @@ def remote_debugging_policy() -> Optional[str]:
|
|
|
771
799
|
if sys.platform == "win32":
|
|
772
800
|
for key in _CHROME_POLICY_KEYS:
|
|
773
801
|
try:
|
|
774
|
-
r = subprocess.run(["reg", "query", key, "/v", "RemoteDebuggingAllowed"], capture_output=True, text=True, timeout=10)
|
|
802
|
+
r = subprocess.run(["reg", "query", key, "/v", "RemoteDebuggingAllowed"], capture_output=True, text=True, errors="replace", timeout=10)
|
|
775
803
|
except Exception:
|
|
776
804
|
continue
|
|
777
805
|
for line in (r.stdout or "").splitlines():
|
|
@@ -1138,22 +1166,34 @@ def _end_browsers(seen: Dict[int, List[str]], *, grace: float = 5.0) -> int:
|
|
|
1138
1166
|
return 0
|
|
1139
1167
|
import psutil
|
|
1140
1168
|
|
|
1141
|
-
|
|
1169
|
+
found: Dict[int, Any] = {}
|
|
1170
|
+
left: Dict[int, Any] = {}
|
|
1142
1171
|
for pid, args in seen.items():
|
|
1143
1172
|
try:
|
|
1144
1173
|
p = psutil.Process(pid)
|
|
1145
1174
|
if p.cmdline() != args:
|
|
1146
1175
|
continue
|
|
1147
|
-
|
|
1176
|
+
found[pid] = p
|
|
1177
|
+
for q in [p, *p.children(recursive=True)]:
|
|
1178
|
+
left.setdefault(q.pid, q)
|
|
1148
1179
|
except (psutil.Error, OSError):
|
|
1149
1180
|
continue
|
|
1150
1181
|
if not left:
|
|
1151
1182
|
return 0
|
|
1152
|
-
|
|
1153
|
-
|
|
1183
|
+
|
|
1184
|
+
def _under_another(p: Any) -> bool:
|
|
1185
|
+
# A launcher that starts the browser again with the same arguments (on Windows, a Python venv's python.exe
|
|
1186
|
+
# does too) leaves one browser, not two.
|
|
1187
|
+
try:
|
|
1188
|
+
return any(a.pid in found for a in p.parents())
|
|
1189
|
+
except (psutil.Error, OSError):
|
|
1190
|
+
return False
|
|
1191
|
+
|
|
1192
|
+
browsers = sum(1 for p in found.values() if not _under_another(p))
|
|
1193
|
+
for p in left.values():
|
|
1154
1194
|
with contextlib.suppress(psutil.Error, OSError):
|
|
1155
1195
|
p.terminate()
|
|
1156
|
-
_, alive = psutil.wait_procs(left, timeout=grace)
|
|
1196
|
+
_, alive = psutil.wait_procs(list(left.values()), timeout=grace)
|
|
1157
1197
|
for p in alive:
|
|
1158
1198
|
with contextlib.suppress(psutil.Error, OSError):
|
|
1159
1199
|
p.kill()
|
package/py/forgeqe_engine/cli.py
CHANGED
|
@@ -14,7 +14,8 @@ Engine process protocol, used by the Bun CLI:
|
|
|
14
14
|
python -m forgeqe_engine doctor
|
|
15
15
|
python -m forgeqe_engine token (stdin: an llms.json profile with auth: entra; prints {token, expires_on})
|
|
16
16
|
python -m forgeqe_engine probe (stdin: an llms.json profile; prints {ok, ms, structured, vision, error?})
|
|
17
|
-
python -m forgeqe_engine
|
|
17
|
+
python -m forgeqe_engine video <frames> <file.mp4> (a replay's kept frames as a video; see video.py)
|
|
18
|
+
python -m forgeqe_engine copilot-gateway (GitHub Copilot as an OpenAI-style endpoint on 127.0.0.1; see copilot_gateway.py)
|
|
18
19
|
"""
|
|
19
20
|
from __future__ import annotations
|
|
20
21
|
|
|
@@ -90,6 +91,10 @@ def _doctor(out: TextIO) -> int:
|
|
|
90
91
|
info["video"] = version("imageio")
|
|
91
92
|
except Exception:
|
|
92
93
|
pass
|
|
94
|
+
try:
|
|
95
|
+
info["ffmpeg"] = version("imageio-ffmpeg")
|
|
96
|
+
except Exception:
|
|
97
|
+
pass
|
|
93
98
|
try:
|
|
94
99
|
from .service import local_browser_launch_kwargs
|
|
95
100
|
|
|
@@ -338,6 +343,10 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
338
343
|
return _probe(out)
|
|
339
344
|
if cmd == "suggest":
|
|
340
345
|
return _suggest(out)
|
|
346
|
+
if cmd == "video":
|
|
347
|
+
from .video import main as video_main
|
|
348
|
+
|
|
349
|
+
return video_main(args[1:], out)
|
|
341
350
|
if cmd == "copilot-gateway":
|
|
342
351
|
from .copilot_gateway import main as copilot_gateway
|
|
343
352
|
|