@capagents/forgeqe 2.9.5 → 2.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/HOW_TO_USE.md +130 -1
  2. package/README.md +3 -0
  3. package/dist/docs-site/docs/architecture/index.html +1 -1
  4. package/dist/docs-site/docs/containers/index.html +2 -2
  5. package/dist/docs-site/docs/cost-architecture/index.html +1 -1
  6. package/dist/docs-site/docs/custom-agents-first-run/index.html +216 -0
  7. package/dist/docs-site/docs/desktop/index.html +1 -1
  8. package/dist/docs-site/docs/desktop-ci/index.html +1 -1
  9. package/dist/docs-site/docs/evidence/index.html +992 -0
  10. package/dist/docs-site/docs/feature-test-prompts/index.html +1 -1
  11. package/dist/docs-site/docs/graphify/index.html +380 -0
  12. package/dist/docs-site/docs/guardrails/index.html +2 -2
  13. package/dist/docs-site/docs/index.html +141 -6
  14. package/dist/docs-site/docs/mobile/index.html +1 -1
  15. package/dist/docs-site/docs/model-routing/index.html +1 -1
  16. package/dist/docs-site/docs/product-graph/index.html +356 -0
  17. package/dist/docs-site/docs/product-knowledge/index.html +3 -3
  18. package/dist/docs-site/docs/product-views/index.html +431 -0
  19. package/dist/docs-site/docs/search.js +1 -1
  20. package/dist/docs-site/docs/web-app/index.html +2 -2
  21. package/dist/forgeqe.js +1866 -1664
  22. package/dist/web/assets/{Agent-BU8FKiQt.js → Agent-I5mRol1P.js} +1 -1
  23. package/dist/web/assets/{ApiTests-Bsv3NhD5.js → ApiTests--JGFKbOa.js} +1 -1
  24. package/dist/web/assets/{Browse-D-ho9bS_.js → Browse-CIcl1j4N.js} +2 -2
  25. package/dist/web/assets/Chat-Baph1nlV.js +3 -0
  26. package/dist/web/assets/{CommandPalette-CrLuxoE5.js → CommandPalette-Dd0seTKQ.js} +1 -1
  27. package/dist/web/assets/{Compare-DfHMTNGi.js → Compare-B7barE31.js} +1 -1
  28. package/dist/web/assets/{Cost-BYb3T8-c.js → Cost-CGXZTXSz.js} +1 -1
  29. package/dist/web/assets/{Data-EF_k6c_T.js → Data-DGKi3KHS.js} +1 -1
  30. package/dist/web/assets/{Desktop-DY5Q1Sd3.js → Desktop-wfNhaxat.js} +1 -1
  31. package/dist/web/assets/{DesktopReview-DFKpYor2.js → DesktopReview-Cxn3mgKO.js} +1 -1
  32. package/dist/web/assets/{Evidence-Db9H4-Nu.js → Evidence-BZ-WKU9t.js} +1 -1
  33. package/dist/web/assets/{Explore-B0EkFCFe.js → Explore-pa8l7kiC.js} +1 -1
  34. package/dist/web/assets/{Features-8jsv2A1d.js → Features-JDMSSUpb.js} +1 -1
  35. package/dist/web/assets/{Flags-DtzmOA5o.js → Flags-DcWTBteQ.js} +1 -1
  36. package/dist/web/assets/{Flaky-BCzOx7Mq.js → Flaky-DnHWlzlk.js} +1 -1
  37. package/dist/web/assets/{ForceGraph-i1zlas5l.js → ForceGraph-BLYMwmyj.js} +1 -1
  38. package/dist/web/assets/{Impact-Da9L1tDd.js → Impact-Dn5PPQ5Z.js} +1 -1
  39. package/dist/web/assets/{Jobs-CHw00lcx.js → Jobs-CNhlUenm.js} +1 -1
  40. package/dist/web/assets/{KindPage-DiOmtzVZ.js → KindPage-BPwFdxHe.js} +1 -1
  41. package/dist/web/assets/{Migration-Cu4JgOj1.js → Migration-DsGwJd40.js} +1 -1
  42. package/dist/web/assets/{Product-DmvUI7pH.js → Product-DsolJU4Y.js} +1 -1
  43. package/dist/web/assets/{Production-CLoOV4jl.js → Production-Cnh3wWiK.js} +1 -1
  44. package/dist/web/assets/{Quality-ylTg9e0c.js → Quality-W_rQ6nRf.js} +1 -1
  45. package/dist/web/assets/{Readiness-BMD5Uj8D.js → Readiness-IWAIRZwC.js} +1 -1
  46. package/dist/web/assets/Record-DOImb7O7.js +2 -0
  47. package/dist/web/assets/{Regression-D_Hy9bMt.js → Regression-DQuiIAFx.js} +1 -1
  48. package/dist/web/assets/{Reports-DXphAHAy.js → Reports-C16UVZtQ.js} +1 -1
  49. package/dist/web/assets/{Response-PDQ8zEZU.js → Response-Vh2lEWnS.js} +1 -1
  50. package/dist/web/assets/{RunDiff-C3MIKipo.js → RunDiff-CVnhT7JE.js} +1 -1
  51. package/dist/web/assets/{Runs-DSQZwCpE.js → Runs-CI8NJB1v.js} +1 -1
  52. package/dist/web/assets/{Steps-CY6WROAr.js → Steps-Bwe4WAjy.js} +1 -1
  53. package/dist/web/assets/{TestCases-BjgWdtPi.js → TestCases-D5oOzYL4.js} +1 -1
  54. package/dist/web/assets/{TestData-CDziNp2d.js → TestData-27tyi6OD.js} +1 -1
  55. package/dist/web/assets/{TestDebt-D59zFYSu.js → TestDebt-D9k3uAiS.js} +1 -1
  56. package/dist/web/assets/{Tosca-umw1O224.js → Tosca-CMmixiPy.js} +1 -1
  57. package/dist/web/assets/{WhatsNew-DqNMAytd.js → WhatsNew-CuCua9dD.js} +1 -1
  58. package/dist/web/assets/{dataParts-DGVc48Ed.js → dataParts-D06wI4i1.js} +1 -1
  59. package/dist/web/assets/{families-DlfXDoO8.js → families-B0QIuAe3.js} +1 -1
  60. package/dist/web/assets/filters-mFECJpMB.js +1 -0
  61. package/dist/web/assets/{fold-BKAl2p_2.js → fold-CeQ84ypG.js} +1 -1
  62. package/dist/web/assets/frame-BcGZt823.js +4 -0
  63. package/dist/web/assets/{index-BLUj4Sgh.js → index-CotEpFLY.js} +19 -17
  64. package/dist/web/assets/index-VgSzQGK8.css +2 -0
  65. package/dist/web/assets/{logos-J0WPxDqj.js → logos-DN9jLn4q.js} +1 -1
  66. package/dist/web/assets/{palette-DViz4KwG.js → palette-BdMPhc9j.js} +1 -1
  67. package/dist/web/assets/{parts-W2J4TR3o.js → parts-z_AE9U-M.js} +1 -1
  68. package/dist/web/assets/{productParts-_8gKGn4o.js → productParts-C4vc_bLJ.js} +1 -1
  69. package/dist/web/assets/{qualityParts-DnbSeK-G.js → qualityParts-Cfirt7dZ.js} +1 -1
  70. package/dist/web/assets/{recordTest-etYNiLQy.js → recordTest-GvGQjhR4.js} +1 -1
  71. package/dist/web/assets/{rows-CbXelp5_.js → rows-CiR4hGkv.js} +1 -1
  72. package/dist/web/assets/{segmented-B7n6eLrO.js → segmented-DANusepM.js} +1 -1
  73. package/dist/web/assets/thread-CyTIuLgk.js +5 -0
  74. package/dist/web/assets/{usePageChat-DMOtRwzT.js → usePageChat-DOTAHsIS.js} +1 -1
  75. package/dist/web/index.html +4 -4
  76. package/docs/user-guide.html +137 -2
  77. package/env.example.yaml +1 -0
  78. package/forgeqe.example.yaml +14 -0
  79. package/package.json +1 -1
  80. package/prompts/brain.md +6 -3
  81. package/prompts/doc-reader.md +49 -0
  82. package/prompts/knowledge-agent.md +64 -0
  83. package/py/forgeqe_engine/brand.py +10 -1
  84. package/py/forgeqe_engine/capture.py +28 -12
  85. package/py/forgeqe_engine/logins.py +27 -0
  86. package/py/forgeqe_engine/loops.py +9 -0
  87. package/py/forgeqe_engine/memory.py +59 -0
  88. package/py/forgeqe_engine/recordsession.py +315 -40
  89. package/py/forgeqe_engine/service.py +11 -3
  90. package/py/forgeqe_engine/webrecord.py +153 -12
  91. package/py/forgeqe_engine/webrecord_page.py +211 -45
  92. package/dist/web/assets/Chat-czaM5kUi.js +0 -3
  93. package/dist/web/assets/Record-CoCnmfqW.js +0 -2
  94. package/dist/web/assets/filters-NVjc0d8i.js +0 -1
  95. package/dist/web/assets/frame-B0nzdTfN.js +0 -4
  96. package/dist/web/assets/index-RzPHjTCW.css +0 -2
  97. package/dist/web/assets/thread-BIUxcjeu.js +0 -5
@@ -21,6 +21,7 @@ Uploads and drag and drop are not recorded; the result lists them.
21
21
  """
22
22
  from __future__ import annotations
23
23
 
24
+ import json
24
25
  import os
25
26
  import re
26
27
  from dataclasses import dataclass, field
@@ -45,6 +46,71 @@ _NAME = re.compile(r"[^a-z0-9_]+")
45
46
  SECRET_FILE = re.compile(r"^(?:forgeqe\.ya?ml|credentials\.json|application_default_credentials\.json|auth\.json|llms\.json|id_(?:rsa|dsa|ecdsa|ed25519)|.*\.(?:pem|key|pfx|p12|kdbx))$", re.I)
46
47
 
47
48
 
49
+ # CAPTCHA widgets, by the address of the frame they run in: what is done in one is a person proving they are one, which
50
+ # a test cannot repeat and must not try to (the test environment turns it off: the provider's test keys, a bypass).
51
+ CAPTCHA_FRAMES = (
52
+ ("reCAPTCHA", re.compile(r"^https://(?:www\.)?(?:google\.com|recaptcha\.net)/recaptcha/", re.I)),
53
+ ("hCaptcha", re.compile(r"^https://(?:[\w-]+\.)*hcaptcha\.com/", re.I)),
54
+ ("Turnstile", re.compile(r"^https://challenges\.cloudflare\.com/", re.I)),
55
+ ("Arkose", re.compile(r"^https://(?:[\w-]+\.)*(?:arkoselabs\.com|funcaptcha\.com)/", re.I)),
56
+ ("GeeTest", re.compile(r"^https://(?:[\w-]+\.)*geetest\.com/", re.I)),
57
+ )
58
+
59
+
60
+ def captcha_of(frames: List[Dict[str, Any]]) -> str:
61
+ """The CAPTCHA a step's element is in, by its frames' addresses ("reCAPTCHA", "hCaptcha", …), or ""."""
62
+ for f in frames:
63
+ src = str(f.get("src") or "")
64
+ for name, rx in CAPTCHA_FRAMES:
65
+ if rx.match(src):
66
+ return name
67
+ return ""
68
+
69
+
70
+ # A file chosen from outside the working folder is copied into the recording's own folder (files/), up to this size.
71
+ MAX_UPLOAD_BYTES = 25 * 1024 * 1024
72
+ MAX_UPLOAD_FILES = 10
73
+
74
+
75
+ def keep_upload(path: str, work_dir: str, run_dir: str) -> Tuple[str, Optional[str], str]:
76
+ """
77
+ Where an upload's file is kept for the test: ("work", path relative to the working folder) when it is there;
78
+ ("run", "files/<name>") when it was chosen from elsewhere (Downloads, the desktop) and is copied into the
79
+ recording's folder; or ("", None, why not): a hidden file or folder, a file named like credentials, not a regular
80
+ file, or too large.
81
+ """
82
+ rel, why = upload_path(path, work_dir)
83
+ if rel:
84
+ return "work", rel, ""
85
+ if not path or not run_dir:
86
+ return "", None, why
87
+ real = os.path.realpath(path)
88
+ name = os.path.basename(real)
89
+ work = os.path.realpath(work_dir) if work_dir else ""
90
+ inside = bool(work) and not os.path.relpath(real, work).startswith(os.pardir)
91
+ if inside or any(part.startswith(".") for part in real.split(os.sep) if part) or SECRET_FILE.match(name):
92
+ return "", None, why
93
+ try:
94
+ size = os.stat(real).st_size
95
+ if not os.path.isfile(real):
96
+ return "", None, f"{name} is not a file"
97
+ except OSError:
98
+ return "", None, f"{name} could not be read"
99
+ if size > MAX_UPLOAD_BYTES:
100
+ return "", None, f"{name} is larger than {MAX_UPLOAD_BYTES // (1024 * 1024)} MB; put a smaller one in the repository's test data and record again"
101
+ folder = os.path.join(run_dir, "files")
102
+ os.makedirs(folder, exist_ok=True)
103
+ plain = re.sub(r"[^A-Za-z0-9._ -]+", "_", name).strip(" .") or "file"
104
+ target, n = os.path.join(folder, plain), 2
105
+ while os.path.exists(target):
106
+ stem, ext = os.path.splitext(plain)
107
+ target, n = os.path.join(folder, f"{stem}-{n}{ext}"), n + 1
108
+ import shutil
109
+
110
+ shutil.copyfile(real, target)
111
+ return "run", f"files/{os.path.basename(target)}", ""
112
+
113
+
48
114
  def upload_path(path: str, work_dir: str) -> Tuple[Optional[str], str]:
49
115
  """
50
116
  (path relative to the working folder, "") for a file the tester chose that a test may use, or (None, why not): it
@@ -97,6 +163,13 @@ class Target:
97
163
  url: str
98
164
  facts: Dict[str, Any]
99
165
  locators: List[Dict[str, Any]]
166
+ # The frames it is in, outermost first: each <iframe>'s own facts (id, name, title, src, index), as
167
+ # recordsession.frame_chain reads them. Empty for an element of the page itself.
168
+ frames: List[Dict[str, Any]] = field(default_factory=list)
169
+ # Where in it a click landed, for an element with nothing inside to name (a canvas): {x, y} from its top left.
170
+ position: Optional[Dict[str, int]] = None
171
+ # Inside a shadow root the page made closed, which the recorder and the replay open (OPEN_SHADOW_JS).
172
+ closed_shadow: bool = False
100
173
 
101
174
  @property
102
175
  def tag(self) -> str:
@@ -110,7 +183,34 @@ class Target:
110
183
  def key(self) -> Tuple[str, str]:
111
184
  """What makes two targets the same element: the page and its best locator."""
112
185
  best = self.locators[0] if self.locators else {}
113
- return (page_id(self.url) or self.url, f"{best.get('type')}:{best.get('value')}")
186
+ where = "".join(f"{f.get('id') or f.get('name') or f.get('title') or f.get('src') or f.get('index')}>" for f in self.frames)
187
+ at = f"@{self.position['x']},{self.position['y']}" if self.position else ""
188
+ return (page_id(self.url) or self.url, f"{where}{best.get('type')}:{best.get('value')}{at}")
189
+
190
+
191
+ def frame_selector(frame: Dict[str, Any]) -> str:
192
+ """A CSS selector for a frame's <iframe>, as src/code/pagefacts.ts frameSelector writes it; empty when nothing names it."""
193
+ q = json.dumps
194
+ fid, name, title, src, index = (frame.get(k) for k in ("id", "name", "title", "src", "index"))
195
+ if fid:
196
+ return f"iframe#{fid}" if re.match(r"^[A-Za-z_-][\w-]*$", str(fid)) else f"iframe[id={q(str(fid))}]"
197
+ if name:
198
+ return f"iframe[name={q(str(name))}]"
199
+ if title:
200
+ return f"iframe[title={q(str(title))}]"
201
+ if src:
202
+ return f"iframe[src={q(str(src))}]"
203
+ if isinstance(index, int) and not isinstance(index, bool) and 0 <= index < 1000:
204
+ return f"iframe >> nth={index}"
205
+ return ""
206
+
207
+
208
+ def in_frames(expr: Optional[str], frames: List[Dict[str, Any]]) -> Optional[str]:
209
+ """A Playwright locator on the page reached through its frames, outermost first, as Playwright's codegen writes it."""
210
+ sels = [frame_selector(f) for f in frames]
211
+ if not expr or not sels or not all(sels) or not expr.startswith("page."):
212
+ return expr
213
+ return "page." + "".join(f"frameLocator({json.dumps(sel)})." for sel in sels) + expr[len("page."):]
114
214
 
115
215
 
116
216
  def element_step(op: str, t: Target) -> Dict[str, Any]:
@@ -121,13 +221,18 @@ def element_step(op: str, t: Target) -> Dict[str, Any]:
121
221
  "op": op,
122
222
  "page": page_id(t.url) or t.url,
123
223
  "label": _clip(element_label(f), 120),
124
- "best_locator": locs[0].get("playwright") if locs else None,
224
+ "best_locator": in_frames(locs[0].get("playwright"), t.frames) if locs else None,
225
+ **({"position": dict(t.position)} if t.position else {}),
226
+ **({"shadow": "closed"} if t.closed_shadow else {}),
125
227
  "locators": [
126
- {"type": l["type"], "value": l["value"], "confidence": l.get("confidence"), **{k: l[k] for k in ("css", "attr", "verified") if l.get(k)}}
228
+ {"type": l["type"], "value": l["value"], "confidence": l.get("confidence"), **{k: l[k] for k in ("css", "attr", "verified", "within") if l.get(k)}}
127
229
  for l in locs
128
230
  if l.get("type") and l.get("value")
129
231
  ],
130
232
  "locator": {k: v for k, v in {"tag": (f.get("tag") or "").upper(), "role": f.get("role"), "name": f.get("name")}.items() if v},
233
+ # In a frame: `frame` is the outermost (as the browser agent's steps name one), `frames` every one when nested.
234
+ **({"frame": t.frames[0]} if t.frames else {}),
235
+ **({"frames": t.frames} if len(t.frames) > 1 else {}),
131
236
  }
132
237
 
133
238
 
@@ -157,7 +262,9 @@ def describe(step: Dict[str, Any]) -> str:
157
262
  if op == "navigate":
158
263
  return f"open {step.get('url')}"
159
264
  if op in ("click", "dblclick", "hover"):
160
- return f"{'double-click' if op == 'dblclick' else op} {label}"
265
+ pos = step.get("position") if isinstance(step.get("position"), dict) else None
266
+ at = f" at {pos.get('x')},{pos.get('y')}" if pos else ""
267
+ return f"{'double-click' if op == 'dblclick' else op} {label}{at}"
161
268
  if op == "input":
162
269
  if step.get("text_env"):
163
270
  return f"type ${step['text_env']} into {label}"
@@ -174,8 +281,11 @@ def describe(step: Dict[str, Any]) -> str:
174
281
  return "go back"
175
282
  if op == "wait_for":
176
283
  return f"wait for {label}"
284
+ if op == "captcha":
285
+ return f"solve the {step.get('provider') or 'CAPTCHA'} (a person; a test turns it off)"
177
286
  if op == "upload":
178
- return f"upload {', '.join(step.get('files') or [])} into {label}"
287
+ names = list(step.get("files") or []) + [os.path.basename(f) for f in step.get("run_files") or []]
288
+ return f"{'drop' if step.get('drop') else 'upload'} {', '.join(names)} {'onto' if step.get('drop') else 'into'} {label}"
179
289
  if op == "capture":
180
290
  return f"keep {label} as {{{{{step.get('name')}}}}}"
181
291
  if op == "expect":
@@ -265,6 +375,20 @@ class WebRecorder:
265
375
  self._last_click = (t.key, at)
266
376
  return describe(self.steps[-1])
267
377
 
378
+ def on_captcha(self, provider: str) -> Optional[str]:
379
+ """
380
+ Something done in a CAPTCHA: one `captcha` step for it, however many clicks it took (the checkbox, the pictures,
381
+ Verify). The replay waits for a person to solve it when the browser is visible, and says so otherwise.
382
+ """
383
+ if self.paused:
384
+ return None
385
+ self._last_action = self.clock()
386
+ self._last_click = None
387
+ if self.steps[-1].get("op") == "captcha" and self.steps[-1].get("provider") == provider:
388
+ return None
389
+ self._add({"op": "captcha", "provider": provider, "page": page_id(self.url) or self.url})
390
+ return describe(self.steps[-1])
391
+
268
392
  def on_dblclick(self, t: Target) -> Optional[str]:
269
393
  """The browser's own double-click event: the two clicks before it on the element become one double-click."""
270
394
  if self.paused:
@@ -332,19 +456,32 @@ class WebRecorder:
332
456
  self._add({"op": "press", "keys": keys})
333
457
  return describe(self.steps[-1])
334
458
 
335
- def on_upload(self, t: Target, files: List[str], refused: List[str]) -> Optional[str]:
336
- """Files the tester chose in a file field: `files` relative to the working folder, `refused` why others are not."""
459
+ def on_upload(self, t: Target, files: List[str], refused: List[str], *, run_files: Optional[List[str]] = None, drop: bool = False) -> Optional[str]:
460
+ """
461
+ Files the tester chose in a file field, or dropped on the page (`drop`): `files` relative to the working folder,
462
+ `run_files` copied into the recording's folder, `refused` why others are not. The click just before that opened
463
+ the file chooser (a "Browse" button) becomes part of the step: the replay clicks it and answers the chooser.
464
+ """
337
465
  if self.paused:
338
466
  return None
339
467
  self._last_action = self.clock()
340
468
  self._last_click = None
341
469
  for why in refused:
342
470
  self._skip("upload", why)
343
- if not files:
471
+ run_files = list(run_files or [])
472
+ if not files and not run_files:
344
473
  return f"not recorded: upload: {refused[0]}" if refused else None
345
- if len(self.steps) > 1 and self.steps[-1].get("op") == "click" and _same(self.steps[-1], t):
346
- self.steps.pop()
347
- self._add({**element_step("upload", t), "files": files})
474
+ chooser: Optional[Dict[str, Any]] = None
475
+ if len(self.steps) > 1 and self.steps[-1].get("op") == "click" and not drop:
476
+ prev = self.steps.pop()
477
+ if not _same(prev, t):
478
+ chooser = {k: prev[k] for k in ("label", "best_locator", "locators", "frame", "frames", "shadow") if prev.get(k)}
479
+ step = {**element_step("upload", t), **({"files": files} if files else {}), **({"run_files": run_files} if run_files else {})}
480
+ if drop:
481
+ step["drop"] = True
482
+ if chooser:
483
+ step["chooser"] = chooser
484
+ self._add(step)
348
485
  return describe(self.steps[-1])
349
486
 
350
487
  def on_unsupported(self, action: str, reason: str) -> str:
@@ -605,4 +742,8 @@ def _same(step: Dict[str, Any], t: Target) -> bool:
605
742
  """Whether a recorded step acted on target `t`: the same page and the same best locator."""
606
743
  locs = step.get("locators") or []
607
744
  best = locs[0] if locs else {}
608
- return (step.get("page"), f"{best.get('type')}:{best.get('value')}") == t.key
745
+ frames = step.get("frames") or ([step["frame"]] if isinstance(step.get("frame"), dict) else [])
746
+ where = "".join(f"{f.get('id') or f.get('name') or f.get('title') or f.get('src') or f.get('index')}>" for f in frames if isinstance(f, dict))
747
+ pos = step.get("position") if isinstance(step.get("position"), dict) else None
748
+ at = f"@{pos['x']},{pos['y']}" if pos else ""
749
+ return (step.get("page"), f"{where}{best.get('type')}:{best.get('value')}{at}") == t.key