@aria-cli/tools 1.0.9 → 1.0.11

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 (241) hide show
  1. package/package.json +9 -5
  2. package/src/__tests__/web-fetch-download.test.ts +0 -433
  3. package/src/__tests__/web-tools.test.ts +0 -619
  4. package/src/ask-user-interaction.ts +0 -33
  5. package/src/cache/web-cache.ts +0 -110
  6. package/src/definitions/arion.ts +0 -118
  7. package/src/definitions/browser/browser.ts +0 -502
  8. package/src/definitions/browser/index.ts +0 -5
  9. package/src/definitions/browser/pw-downloads.ts +0 -142
  10. package/src/definitions/browser/pw-interactions.ts +0 -282
  11. package/src/definitions/browser/pw-responses.ts +0 -98
  12. package/src/definitions/browser/pw-session.ts +0 -405
  13. package/src/definitions/browser/pw-shared.ts +0 -85
  14. package/src/definitions/browser/pw-snapshot.ts +0 -383
  15. package/src/definitions/browser/pw-state.ts +0 -101
  16. package/src/definitions/browser/types.ts +0 -203
  17. package/src/definitions/code-intelligence.ts +0 -526
  18. package/src/definitions/core.ts +0 -118
  19. package/src/definitions/delegation.ts +0 -567
  20. package/src/definitions/deploy.ts +0 -73
  21. package/src/definitions/filesystem.ts +0 -217
  22. package/src/definitions/frg.ts +0 -67
  23. package/src/definitions/index.ts +0 -28
  24. package/src/definitions/memory.ts +0 -150
  25. package/src/definitions/messaging.ts +0 -734
  26. package/src/definitions/meta.ts +0 -392
  27. package/src/definitions/network.ts +0 -179
  28. package/src/definitions/outlook.ts +0 -318
  29. package/src/definitions/patch/apply-patch.ts +0 -235
  30. package/src/definitions/patch/fuzzy-match.ts +0 -217
  31. package/src/definitions/patch/index.ts +0 -1
  32. package/src/definitions/patch/patch-parser.ts +0 -297
  33. package/src/definitions/patch/sandbox-paths.ts +0 -129
  34. package/src/definitions/process/index.ts +0 -5
  35. package/src/definitions/process/process-registry.ts +0 -303
  36. package/src/definitions/process/process.ts +0 -456
  37. package/src/definitions/process/pty-keys.ts +0 -298
  38. package/src/definitions/process/session-slug.ts +0 -147
  39. package/src/definitions/quip.ts +0 -225
  40. package/src/definitions/search.ts +0 -67
  41. package/src/definitions/session-history.ts +0 -79
  42. package/src/definitions/shell.ts +0 -202
  43. package/src/definitions/slack.ts +0 -211
  44. package/src/definitions/web.ts +0 -119
  45. package/src/executors/apply-patch.ts +0 -1035
  46. package/src/executors/arion.ts +0 -199
  47. package/src/executors/code-intelligence.ts +0 -1179
  48. package/src/executors/deploy.ts +0 -1066
  49. package/src/executors/filesystem.ts +0 -1428
  50. package/src/executors/frg-freshness.ts +0 -743
  51. package/src/executors/frg.ts +0 -394
  52. package/src/executors/index.ts +0 -280
  53. package/src/executors/learning-meta.ts +0 -1367
  54. package/src/executors/lsp-client.ts +0 -355
  55. package/src/executors/memory.ts +0 -978
  56. package/src/executors/meta.ts +0 -293
  57. package/src/executors/process-registry.ts +0 -570
  58. package/src/executors/pty-session-store.ts +0 -43
  59. package/src/executors/pty.ts +0 -342
  60. package/src/executors/restart.ts +0 -133
  61. package/src/executors/search-freshness.ts +0 -249
  62. package/src/executors/search-types.ts +0 -98
  63. package/src/executors/search.ts +0 -89
  64. package/src/executors/self-diagnose.ts +0 -552
  65. package/src/executors/session-history.ts +0 -435
  66. package/src/executors/shell-safety.ts +0 -519
  67. package/src/executors/shell.ts +0 -1243
  68. package/src/executors/utils.ts +0 -40
  69. package/src/executors/web.ts +0 -786
  70. package/src/extraction/content-extraction.ts +0 -281
  71. package/src/extraction/index.ts +0 -5
  72. package/src/headless-control-contract.ts +0 -1149
  73. package/src/index.ts +0 -788
  74. package/src/local-control-http-auth.ts +0 -2
  75. package/src/mcp/client.ts +0 -218
  76. package/src/mcp/connection.ts +0 -568
  77. package/src/mcp/index.ts +0 -11
  78. package/src/mcp/jsonrpc.ts +0 -195
  79. package/src/mcp/types.ts +0 -199
  80. package/src/network-control-adapter.ts +0 -88
  81. package/src/network-runtime/address-types.ts +0 -218
  82. package/src/network-runtime/db-owner-fencing.ts +0 -91
  83. package/src/network-runtime/delivery-receipts.ts +0 -372
  84. package/src/network-runtime/direct-endpoint-authority.ts +0 -35
  85. package/src/network-runtime/index.ts +0 -316
  86. package/src/network-runtime/local-control-contract.ts +0 -784
  87. package/src/network-runtime/node-store-contract.ts +0 -46
  88. package/src/network-runtime/pair-route-contract.ts +0 -97
  89. package/src/network-runtime/peer-capabilities.ts +0 -48
  90. package/src/network-runtime/peer-principal-ref.ts +0 -20
  91. package/src/network-runtime/peer-state-machine.ts +0 -160
  92. package/src/network-runtime/protocol-schemas.ts +0 -265
  93. package/src/network-runtime/runtime-bootstrap-contract.ts +0 -83
  94. package/src/outlook/desktop-session.ts +0 -409
  95. package/src/policy.ts +0 -171
  96. package/src/providers/brave.ts +0 -80
  97. package/src/providers/duckduckgo.ts +0 -199
  98. package/src/providers/exa.ts +0 -85
  99. package/src/providers/firecrawl.ts +0 -77
  100. package/src/providers/index.ts +0 -8
  101. package/src/providers/jina.ts +0 -70
  102. package/src/providers/router.ts +0 -121
  103. package/src/providers/search-provider.ts +0 -74
  104. package/src/providers/tavily.ts +0 -74
  105. package/src/quip/desktop-session.ts +0 -435
  106. package/src/registry/index.ts +0 -1
  107. package/src/registry/registry.ts +0 -905
  108. package/src/runtime-socket-local-control-client.ts +0 -632
  109. package/src/security/dns-normalization.ts +0 -34
  110. package/src/security/dns-pinning.ts +0 -138
  111. package/src/security/external-content.ts +0 -129
  112. package/src/security/ssrf.ts +0 -207
  113. package/src/slack/desktop-session.ts +0 -493
  114. package/src/tool-factory.ts +0 -91
  115. package/src/types.ts +0 -1341
  116. package/src/utils/retry.ts +0 -163
  117. package/src/utils/safe-parse-json.ts +0 -176
  118. package/src/utils/url.ts +0 -20
  119. package/tests/benchmarks/registry.bench.ts +0 -57
  120. package/tests/cache/web-cache.test.ts +0 -147
  121. package/tests/critical-integration.test.ts +0 -1465
  122. package/tests/definitions/apply-patch.test.ts +0 -586
  123. package/tests/definitions/browser.test.ts +0 -495
  124. package/tests/definitions/delegation-pause-resume.test.ts +0 -758
  125. package/tests/definitions/execution.test.ts +0 -671
  126. package/tests/definitions/messaging-inbox-scope.test.ts +0 -229
  127. package/tests/definitions/messaging.test.ts +0 -1468
  128. package/tests/definitions/outlook.test.ts +0 -30
  129. package/tests/definitions/process.test.ts +0 -469
  130. package/tests/definitions/slack.test.ts +0 -28
  131. package/tests/definitions/tool-inventory.test.ts +0 -218
  132. package/tests/e2e/delegation-quest-orchestration.e2e.test.ts +0 -433
  133. package/tests/e2e/memory-tool-discovery-contract.e2e.test.ts +0 -81
  134. package/tests/executors/apply-patch.test.ts +0 -538
  135. package/tests/executors/arion.test.ts +0 -309
  136. package/tests/executors/conversation-primitives.test.ts +0 -250
  137. package/tests/executors/deploy.test.ts +0 -746
  138. package/tests/executors/filesystem-tools.test.ts +0 -357
  139. package/tests/executors/filesystem.test.ts +0 -959
  140. package/tests/executors/frg-freshness.test.ts +0 -136
  141. package/tests/executors/frg-merge.test.ts +0 -70
  142. package/tests/executors/frg-session-content.test.ts +0 -40
  143. package/tests/executors/frg.test.ts +0 -56
  144. package/tests/executors/memory-bugfixes.test.ts +0 -257
  145. package/tests/executors/memory-real-memoria.integration.test.ts +0 -316
  146. package/tests/executors/memory.test.ts +0 -853
  147. package/tests/executors/meta-tools.test.ts +0 -411
  148. package/tests/executors/meta.test.ts +0 -683
  149. package/tests/executors/path-containment.test.ts +0 -51
  150. package/tests/executors/process-registry.test.ts +0 -505
  151. package/tests/executors/pty.test.ts +0 -664
  152. package/tests/executors/quest-security.test.ts +0 -249
  153. package/tests/executors/read-file-media.test.ts +0 -230
  154. package/tests/executors/recall-knowledge-schema.test.ts +0 -209
  155. package/tests/executors/recall-tags.test.ts +0 -278
  156. package/tests/executors/remember-null-safety.contract.test.ts +0 -41
  157. package/tests/executors/restart.test.ts +0 -67
  158. package/tests/executors/search-unified.test.ts +0 -381
  159. package/tests/executors/session-history.test.ts +0 -340
  160. package/tests/executors/session-transcript.test.ts +0 -561
  161. package/tests/executors/shell-abort.test.ts +0 -416
  162. package/tests/executors/shell-env-blocklist.test.ts +0 -648
  163. package/tests/executors/shell-env-process.test.ts +0 -245
  164. package/tests/executors/shell-process-registry.test.ts +0 -334
  165. package/tests/executors/shell-tools.test.ts +0 -393
  166. package/tests/executors/shell.test.ts +0 -690
  167. package/tests/executors/web-abort-vs-timeout.test.ts +0 -213
  168. package/tests/executors/web-integration.test.ts +0 -633
  169. package/tests/executors/web-symlink.test.ts +0 -18
  170. package/tests/executors/web.test.ts +0 -1400
  171. package/tests/executors/write-stdin.test.ts +0 -145
  172. package/tests/extraction/content-extraction.test.ts +0 -153
  173. package/tests/guards/tools-default-test-lane.integration.test.ts +0 -21
  174. package/tests/guards/tools-package-test-commands.e2e.test.ts +0 -43
  175. package/tests/guards/tools-test-lane-manifest.contract.test.ts +0 -76
  176. package/tests/guards/tools-vitest-workspace-alias.contract.test.ts +0 -63
  177. package/tests/helpers/async-waits.ts +0 -53
  178. package/tests/integration/headless-control-contract.integration.test.ts +0 -153
  179. package/tests/integration/memory-tool-schema-parity.integration.test.ts +0 -67
  180. package/tests/integration/meta-tools-round-trip.integration.test.ts +0 -506
  181. package/tests/integration/quest-round-trip.test.ts +0 -303
  182. package/tests/integration/registry-executor-flow.test.ts +0 -85
  183. package/tests/integration.test.ts +0 -177
  184. package/tests/loading-tier.test.ts +0 -126
  185. package/tests/mcp/client-reconnect.test.ts +0 -267
  186. package/tests/mcp/connection.test.ts +0 -846
  187. package/tests/mcp/injectable-logger.test.ts +0 -83
  188. package/tests/mcp/jsonrpc.test.ts +0 -109
  189. package/tests/mcp/lifecycle.test.ts +0 -879
  190. package/tests/network-runtime/address-types.contract.test.ts +0 -143
  191. package/tests/network-runtime/continuity-bind-schema.contract.test.ts +0 -203
  192. package/tests/network-runtime/local-control-contract.test.ts +0 -869
  193. package/tests/network-runtime/local-control-invite-token.contract.test.ts +0 -146
  194. package/tests/network-runtime/node-store-contract.test.ts +0 -11
  195. package/tests/network-runtime/pair-protocol-nodeid.contract.test.ts +0 -15
  196. package/tests/network-runtime/peer-state-machine.contract.test.ts +0 -148
  197. package/tests/network-runtime/protocol-schemas.contract.test.ts +0 -512
  198. package/tests/network-runtime/relay-pending-nodeid.contract.test.ts +0 -62
  199. package/tests/network-runtime/runtime-bootstrap-contract.test.ts +0 -227
  200. package/tests/network-runtime/runtime-socket-local-control-client.test.ts +0 -621
  201. package/tests/network-runtime/wait-for-message-script.test.ts +0 -288
  202. package/tests/parallel.test.ts +0 -71
  203. package/tests/policy.test.ts +0 -184
  204. package/tests/print-default-test-lane.ts +0 -14
  205. package/tests/print-test-lane-manifest.ts +0 -22
  206. package/tests/providers/brave.test.ts +0 -159
  207. package/tests/providers/duckduckgo.test.ts +0 -207
  208. package/tests/providers/exa.test.ts +0 -175
  209. package/tests/providers/firecrawl.test.ts +0 -168
  210. package/tests/providers/jina.test.ts +0 -144
  211. package/tests/providers/router.test.ts +0 -328
  212. package/tests/providers/tavily.test.ts +0 -165
  213. package/tests/registry/discovery.test.ts +0 -154
  214. package/tests/registry/injectable-logger.test.ts +0 -230
  215. package/tests/registry/input-validation.test.ts +0 -361
  216. package/tests/registry/interface-completeness.test.ts +0 -85
  217. package/tests/registry/mcp-integration.test.ts +0 -103
  218. package/tests/registry/mcp-read-only-hint.test.ts +0 -60
  219. package/tests/registry/memoria-discovery.test.ts +0 -390
  220. package/tests/registry/nested-validation.test.ts +0 -283
  221. package/tests/registry/pseudo-tool-filtering.test.ts +0 -258
  222. package/tests/registry/registration-lifecycle.test.ts +0 -133
  223. package/tests/registry-validation.test.ts +0 -424
  224. package/tests/registry.test.ts +0 -460
  225. package/tests/security/dns-pinning.test.ts +0 -162
  226. package/tests/security/external-content.test.ts +0 -144
  227. package/tests/security/ssrf.test.ts +0 -118
  228. package/tests/shell-safety-integration.test.ts +0 -32
  229. package/tests/shell-safety.test.ts +0 -365
  230. package/tests/slack/desktop-session.test.ts +0 -50
  231. package/tests/test-lane-manifest.ts +0 -440
  232. package/tests/test-utils.ts +0 -27
  233. package/tests/tool-factory.test.ts +0 -188
  234. package/tests/utils/retry.test.ts +0 -231
  235. package/tests/utils/url.test.ts +0 -63
  236. package/tsconfig.cjs.json +0 -24
  237. package/tsconfig.json +0 -12
  238. package/vitest.config.ts +0 -55
  239. package/vitest.e2e.config.ts +0 -24
  240. package/vitest.integration.config.ts +0 -24
  241. package/vitest.native.config.ts +0 -24
@@ -1,383 +0,0 @@
1
- // Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
2
- // https://github.com/openclaw/openclaw
3
- // Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
4
-
5
- /**
6
- * Accessibility tree snapshot and role-ref system.
7
- * Ported from OpenClaw's pw-role-snapshot.ts + pw-tools-core.snapshot.ts.
8
- */
9
-
10
- import type { PwPage, RoleRefMap, RoleSnapshotStats, SnapshotResult } from "./types.js";
11
-
12
- // ── Role classification sets ──────────────────────────────────────────
13
-
14
- const INTERACTIVE_ROLES = new Set([
15
- "button",
16
- "link",
17
- "textbox",
18
- "checkbox",
19
- "radio",
20
- "combobox",
21
- "listbox",
22
- "menuitem",
23
- "menuitemcheckbox",
24
- "menuitemradio",
25
- "option",
26
- "searchbox",
27
- "slider",
28
- "spinbutton",
29
- "switch",
30
- "tab",
31
- "treeitem",
32
- ]);
33
-
34
- const CONTENT_ROLES = new Set([
35
- "heading",
36
- "cell",
37
- "gridcell",
38
- "columnheader",
39
- "rowheader",
40
- "listitem",
41
- "article",
42
- "region",
43
- "main",
44
- "navigation",
45
- ]);
46
-
47
- const STRUCTURAL_ROLES = new Set([
48
- "generic",
49
- "group",
50
- "list",
51
- "table",
52
- "row",
53
- "rowgroup",
54
- "grid",
55
- "treegrid",
56
- "menu",
57
- "menubar",
58
- "toolbar",
59
- "tablist",
60
- "tree",
61
- "directory",
62
- "document",
63
- "application",
64
- "presentation",
65
- "none",
66
- ]);
67
-
68
- // ── Snapshot options ──────────────────────────────────────────────────
69
-
70
- export interface RoleSnapshotOptions {
71
- /** Only include interactive elements (buttons, links, inputs, etc.). */
72
- interactive?: boolean;
73
- /** Maximum depth to include (0 = root only). */
74
- maxDepth?: number;
75
- /** Remove unnamed structural elements and empty branches. */
76
- compact?: boolean;
77
- }
78
-
79
- // ── Stats ─────────────────────────────────────────────────────────────
80
-
81
- export function getRoleSnapshotStats(snapshot: string, refs: RoleRefMap): RoleSnapshotStats {
82
- const interactive = Object.values(refs).filter((r) => INTERACTIVE_ROLES.has(r.role)).length;
83
- return {
84
- lines: snapshot.split("\n").length,
85
- chars: snapshot.length,
86
- refs: Object.keys(refs).length,
87
- interactive,
88
- };
89
- }
90
-
91
- // ── Internal helpers ──────────────────────────────────────────────────
92
-
93
- function getIndentLevel(line: string): number {
94
- const match = line.match(/^(\s*)/);
95
- return match ? Math.floor(match[1]!.length / 2) : 0;
96
- }
97
-
98
- type RoleNameTracker = {
99
- counts: Map<string, number>;
100
- refsByKey: Map<string, string[]>;
101
- getKey: (role: string, name?: string) => string;
102
- getNextIndex: (role: string, name?: string) => number;
103
- trackRef: (role: string, name: string | undefined, ref: string) => void;
104
- getDuplicateKeys: () => Set<string>;
105
- };
106
-
107
- function createRoleNameTracker(): RoleNameTracker {
108
- const counts = new Map<string, number>();
109
- const refsByKey = new Map<string, string[]>();
110
- return {
111
- counts,
112
- refsByKey,
113
- getKey(role: string, name?: string) {
114
- return `${role}:${name ?? ""}`;
115
- },
116
- getNextIndex(role: string, name?: string) {
117
- const key = this.getKey(role, name);
118
- const current = counts.get(key) ?? 0;
119
- counts.set(key, current + 1);
120
- return current;
121
- },
122
- trackRef(role: string, name: string | undefined, ref: string) {
123
- const key = this.getKey(role, name);
124
- const list = refsByKey.get(key) ?? [];
125
- list.push(ref);
126
- refsByKey.set(key, list);
127
- },
128
- getDuplicateKeys() {
129
- const out = new Set<string>();
130
- for (const [key, refs] of refsByKey) {
131
- if (refs.length > 1) {
132
- out.add(key);
133
- }
134
- }
135
- return out;
136
- },
137
- };
138
- }
139
-
140
- function removeNthFromNonDuplicates(refs: RoleRefMap, tracker: RoleNameTracker) {
141
- const duplicates = tracker.getDuplicateKeys();
142
- for (const [ref, data] of Object.entries(refs)) {
143
- const key = tracker.getKey(data.role, data.name);
144
- if (!duplicates.has(key)) {
145
- delete refs[ref]?.nth;
146
- }
147
- }
148
- }
149
-
150
- function compactTree(tree: string): string {
151
- const lines = tree.split("\n");
152
- const result: string[] = [];
153
-
154
- for (let i = 0; i < lines.length; i += 1) {
155
- const line = lines[i]!;
156
- if (line.includes("[ref=")) {
157
- result.push(line);
158
- continue;
159
- }
160
- if (line.includes(":") && !line.trimEnd().endsWith(":")) {
161
- result.push(line);
162
- continue;
163
- }
164
-
165
- const currentIndent = getIndentLevel(line);
166
- let hasRelevantChildren = false;
167
- for (let j = i + 1; j < lines.length; j += 1) {
168
- const childIndent = getIndentLevel(lines[j]!);
169
- if (childIndent <= currentIndent) {
170
- break;
171
- }
172
- if (lines[j]?.includes("[ref=")) {
173
- hasRelevantChildren = true;
174
- break;
175
- }
176
- }
177
- if (hasRelevantChildren) {
178
- result.push(line);
179
- }
180
- }
181
-
182
- return result.join("\n");
183
- }
184
-
185
- function matchInteractiveSnapshotLine(
186
- line: string,
187
- options: RoleSnapshotOptions,
188
- ): { roleRaw: string; role: string; name?: string; suffix: string } | null {
189
- const depth = getIndentLevel(line);
190
- if (options.maxDepth !== undefined && depth > options.maxDepth) {
191
- return null;
192
- }
193
- const match = line.match(/^(\s*-\s*)(\w+)(?:\s+"([^"]*)")?(.*)$/);
194
- if (!match) {
195
- return null;
196
- }
197
- const [, , roleRaw, name, suffix] = match;
198
- if (roleRaw!.startsWith("/")) {
199
- return null;
200
- }
201
- const role = roleRaw!.toLowerCase();
202
- return {
203
- roleRaw: roleRaw!,
204
- role,
205
- ...(name ? { name } : {}),
206
- suffix: suffix!,
207
- };
208
- }
209
-
210
- function processLine(
211
- line: string,
212
- refs: RoleRefMap,
213
- options: RoleSnapshotOptions,
214
- tracker: RoleNameTracker,
215
- nextRef: () => string,
216
- ): string | null {
217
- const depth = getIndentLevel(line);
218
- if (options.maxDepth !== undefined && depth > options.maxDepth) {
219
- return null;
220
- }
221
-
222
- const match = line.match(/^(\s*-\s*)(\w+)(?:\s+"([^"]*)")?(.*)$/);
223
- if (!match) {
224
- return options.interactive ? null : line;
225
- }
226
-
227
- const [, prefix, roleRaw, name, suffix] = match;
228
- if (roleRaw!.startsWith("/")) {
229
- return options.interactive ? null : line;
230
- }
231
-
232
- const role = roleRaw!.toLowerCase();
233
- const isInteractive = INTERACTIVE_ROLES.has(role);
234
- const isContent = CONTENT_ROLES.has(role);
235
- const isStructural = STRUCTURAL_ROLES.has(role);
236
-
237
- if (options.interactive && !isInteractive) {
238
- return null;
239
- }
240
- if (options.compact && isStructural && !name) {
241
- return null;
242
- }
243
-
244
- const shouldHaveRef = isInteractive || (isContent && !!name);
245
- if (!shouldHaveRef) {
246
- return line;
247
- }
248
-
249
- const ref = nextRef();
250
- const nth = tracker.getNextIndex(role, name);
251
- tracker.trackRef(role, name, ref);
252
- refs[ref] = { role, name, nth };
253
-
254
- let enhanced = `${prefix}${roleRaw}`;
255
- if (name) {
256
- enhanced += ` "${name}"`;
257
- }
258
- enhanced += ` [ref=${ref}]`;
259
- if (nth > 0) {
260
- enhanced += ` [nth=${nth}]`;
261
- }
262
- if (suffix) {
263
- enhanced += suffix;
264
- }
265
- return enhanced;
266
- }
267
-
268
- // ── Public API ────────────────────────────────────────────────────────
269
-
270
- /**
271
- * Build a role-ref snapshot from Playwright's ariaSnapshot() output.
272
- * This is the core transform: raw ARIA tree text -> annotated tree + ref map.
273
- */
274
- export function buildRoleSnapshotFromAriaSnapshot(
275
- ariaSnapshot: string,
276
- options: RoleSnapshotOptions = {},
277
- ): { snapshot: string; refs: RoleRefMap } {
278
- const lines = ariaSnapshot.split("\n");
279
- const refs: RoleRefMap = {};
280
- const tracker = createRoleNameTracker();
281
-
282
- let counter = 0;
283
- const nextRef = () => {
284
- counter += 1;
285
- return `e${counter}`;
286
- };
287
-
288
- if (options.interactive) {
289
- const result: string[] = [];
290
- for (const line of lines) {
291
- const parsed = matchInteractiveSnapshotLine(line, options);
292
- if (!parsed) {
293
- continue;
294
- }
295
- const { roleRaw, role, name, suffix } = parsed;
296
- if (!INTERACTIVE_ROLES.has(role)) {
297
- continue;
298
- }
299
-
300
- const ref = nextRef();
301
- const nth = tracker.getNextIndex(role, name);
302
- tracker.trackRef(role, name, ref);
303
- refs[ref] = { role, name, nth };
304
-
305
- let enhanced = `- ${roleRaw}`;
306
- if (name) {
307
- enhanced += ` "${name}"`;
308
- }
309
- enhanced += ` [ref=${ref}]`;
310
- if (nth > 0) {
311
- enhanced += ` [nth=${nth}]`;
312
- }
313
- if (suffix.includes("[")) {
314
- enhanced += suffix;
315
- }
316
- result.push(enhanced);
317
- }
318
-
319
- removeNthFromNonDuplicates(refs, tracker);
320
-
321
- return {
322
- snapshot: result.join("\n") || "(no interactive elements)",
323
- refs,
324
- };
325
- }
326
-
327
- const result: string[] = [];
328
- for (const line of lines) {
329
- const processed = processLine(line, refs, options, tracker, nextRef);
330
- if (processed !== null) {
331
- result.push(processed);
332
- }
333
- }
334
-
335
- removeNthFromNonDuplicates(refs, tracker);
336
-
337
- const tree = result.join("\n") || "(empty)";
338
- return {
339
- snapshot: options.compact ? compactTree(tree) : tree,
340
- refs,
341
- };
342
- }
343
-
344
- /**
345
- * Take a role-based accessibility snapshot of a page.
346
- * Uses Playwright's built-in ariaSnapshot() on the :root locator,
347
- * then annotates elements with [ref=eN] markers.
348
- */
349
- export async function snapshotPage(
350
- page: PwPage,
351
- options?: RoleSnapshotOptions,
352
- ): Promise<SnapshotResult> {
353
- const locator = page.locator(":root");
354
- const ariaSnapshot = await locator.ariaSnapshot();
355
- const built = buildRoleSnapshotFromAriaSnapshot(String(ariaSnapshot ?? ""), options);
356
- const stats = getRoleSnapshotStats(built.snapshot, built.refs);
357
- return {
358
- snapshot: built.snapshot,
359
- refs: built.refs,
360
- stats,
361
- url: page.url(),
362
- title: await page.title(),
363
- };
364
- }
365
-
366
- /**
367
- * Navigate a page to a URL.
368
- */
369
- export async function navigatePage(
370
- page: PwPage,
371
- url: string,
372
- timeoutMs?: number,
373
- ): Promise<{ url: string }> {
374
- const target = String(url ?? "").trim();
375
- if (!target) {
376
- throw new Error("url is required");
377
- }
378
- await page.goto(target, {
379
- timeout: Math.max(1000, Math.min(120_000, timeoutMs ?? 20_000)),
380
- waitUntil: "domcontentloaded",
381
- });
382
- return { url: page.url() };
383
- }
@@ -1,101 +0,0 @@
1
- // Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
2
- // https://github.com/openclaw/openclaw
3
- // Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
4
-
5
- /**
6
- * Cookie and storage management.
7
- * Ported from OpenClaw's pw-tools-core.state.ts + pw-tools-core.storage.ts.
8
- */
9
-
10
- import type { PwBrowserContext, PwCookie, PwPage } from "./types.js";
11
-
12
- // ── Cookies ───────────────────────────────────────────────────────────
13
-
14
- export async function cookiesGet(context: PwBrowserContext): Promise<{ cookies: PwCookie[] }> {
15
- const cookies = await context.cookies();
16
- return { cookies };
17
- }
18
-
19
- export async function cookiesSet(
20
- context: PwBrowserContext,
21
- cookies: Array<{
22
- name: string;
23
- value: string;
24
- domain: string;
25
- path?: string;
26
- }>,
27
- ): Promise<void> {
28
- if (!cookies.length) {
29
- throw new Error("cookies are required");
30
- }
31
- for (const cookie of cookies) {
32
- if (!cookie.name || cookie.value === undefined) {
33
- throw new Error("cookie name and value are required");
34
- }
35
- if (!cookie.domain) {
36
- throw new Error("cookie domain is required");
37
- }
38
- }
39
- await context.addCookies(
40
- cookies.map((c) => ({
41
- name: c.name,
42
- value: c.value,
43
- domain: c.domain,
44
- path: c.path ?? "/",
45
- })),
46
- );
47
- }
48
-
49
- export async function cookiesClear(context: PwBrowserContext): Promise<void> {
50
- await context.clearCookies();
51
- }
52
-
53
- // ── Storage ───────────────────────────────────────────────────────────
54
- // String-form evaluate is used to avoid TypeScript signature conflicts
55
- // with the minimal PwPage interface.
56
-
57
- type StorageKind = "local" | "session";
58
-
59
- export async function storageGet(
60
- page: PwPage,
61
- kind: StorageKind,
62
- key?: string,
63
- ): Promise<{ values: Record<string, string> }> {
64
- const script = key
65
- ? `(function() {
66
- var store = ${kind === "session" ? "window.sessionStorage" : "window.localStorage"};
67
- var value = store.getItem(${JSON.stringify(key)});
68
- return value === null ? {} : { ${JSON.stringify(key)}: value };
69
- })()`
70
- : `(function() {
71
- var store = ${kind === "session" ? "window.sessionStorage" : "window.localStorage"};
72
- var out = {};
73
- for (var i = 0; i < store.length; i++) {
74
- var k = store.key(i);
75
- if (!k) continue;
76
- var v = store.getItem(k);
77
- if (v !== null) out[k] = v;
78
- }
79
- return out;
80
- })()`;
81
- const values = (await page.evaluate(script)) as Record<string, string>;
82
- return { values: values ?? {} };
83
- }
84
-
85
- export async function storageSet(
86
- page: PwPage,
87
- kind: StorageKind,
88
- key: string,
89
- value: string,
90
- ): Promise<void> {
91
- if (!key) {
92
- throw new Error("key is required");
93
- }
94
- const storeName = kind === "session" ? "window.sessionStorage" : "window.localStorage";
95
- await page.evaluate(`${storeName}.setItem(${JSON.stringify(key)}, ${JSON.stringify(value)})`);
96
- }
97
-
98
- export async function storageClear(page: PwPage, kind: StorageKind): Promise<void> {
99
- const storeName = kind === "session" ? "window.sessionStorage" : "window.localStorage";
100
- await page.evaluate(`${storeName}.clear()`);
101
- }
@@ -1,203 +0,0 @@
1
- // Originally from OpenClaw (MIT License, Copyright 2025 Peter Steinberger)
2
- // https://github.com/openclaw/openclaw
3
- // Modified for ARIA — stripped OpenClaw runtime, rewired to ARIA Tool interface
4
-
5
- /**
6
- * Shared browser tool types.
7
- *
8
- * Playwright types are referenced dynamically (the `playwright` package is an
9
- * optional peer dependency loaded via `await import("playwright")`).
10
- */
11
-
12
- // ── Playwright stand-in types ─────────────────────────────────────────
13
- // We avoid a static import of playwright so the tool module can load even
14
- // when the package is not installed. These narrow interfaces cover only
15
- // the subset our code actually touches.
16
-
17
- /** Minimal Browser interface (matches Playwright's Browser). */
18
- export interface PwBrowser {
19
- close(): Promise<void>;
20
- contexts(): PwBrowserContext[];
21
- isConnected(): boolean;
22
- }
23
-
24
- /** Minimal BrowserContext interface. */
25
- export interface PwBrowserContext {
26
- pages(): PwPage[];
27
- newPage(): Promise<PwPage>;
28
- cookies(urls?: string | string[]): Promise<PwCookie[]>;
29
- addCookies(cookies: PwCookie[]): Promise<void>;
30
- clearCookies(): Promise<void>;
31
- setOffline(offline: boolean): Promise<void>;
32
- close(): Promise<void>;
33
- }
34
-
35
- /** Minimal Page interface. */
36
- export interface PwPage {
37
- goto(
38
- url: string,
39
- options?: {
40
- timeout?: number;
41
- waitUntil?: "load" | "domcontentloaded" | "networkidle" | "commit";
42
- },
43
- ): Promise<unknown>;
44
- url(): string;
45
- title(): Promise<string>;
46
- close(): Promise<void>;
47
- content(): Promise<string>;
48
- setViewportSize(size: { width: number; height: number }): Promise<void>;
49
- screenshot(options?: { type?: "png" | "jpeg"; fullPage?: boolean }): Promise<Buffer>;
50
- evaluate<T>(fn: string | ((...args: unknown[]) => T), arg?: unknown): Promise<T>;
51
- locator(selector: string): PwLocator;
52
- getByRole(role: string, options?: { name?: string; exact?: boolean }): PwLocator;
53
- keyboard: { press(key: string, options?: { delay?: number }): Promise<void> };
54
- mouse: {
55
- wheel(deltaX: number, deltaY: number): Promise<void>;
56
- };
57
- waitForTimeout(timeout: number): Promise<void>;
58
- waitForSelector(
59
- selector: string,
60
- options?: { timeout?: number; state?: string },
61
- ): Promise<unknown>;
62
- waitForLoadState(state?: string, options?: { timeout?: number }): Promise<void>;
63
- on(event: string, handler: (...args: unknown[]) => void): void;
64
- off(event: string, handler: (...args: unknown[]) => void): void;
65
- isClosed(): boolean;
66
- frameLocator(selector: string): PwFrameLocator;
67
- }
68
-
69
- export interface PwFrameLocator {
70
- locator(selector: string): PwLocator;
71
- getByRole(role: string, options?: { name?: string; exact?: boolean }): PwLocator;
72
- }
73
-
74
- export interface PwLocator {
75
- click(options?: { timeout?: number; button?: string; modifiers?: string[] }): Promise<void>;
76
- dblclick(options?: { timeout?: number; button?: string; modifiers?: string[] }): Promise<void>;
77
- fill(value: string, options?: { timeout?: number }): Promise<void>;
78
- type(text: string, options?: { timeout?: number; delay?: number }): Promise<void>;
79
- press(key: string, options?: { timeout?: number }): Promise<void>;
80
- hover(options?: { timeout?: number }): Promise<void>;
81
- selectOption(values: string | string[], options?: { timeout?: number }): Promise<string[]>;
82
- dragTo(target: PwLocator, options?: { timeout?: number }): Promise<void>;
83
- setInputFiles(files: string | string[]): Promise<void>;
84
- highlight(): Promise<void>;
85
- screenshot(options?: { type?: "png" | "jpeg" }): Promise<Buffer>;
86
- scrollIntoViewIfNeeded(options?: { timeout?: number }): Promise<void>;
87
- boundingBox(): Promise<{ x: number; y: number; width: number; height: number } | null>;
88
- elementHandle(): Promise<PwElementHandle | null>;
89
- nth(index: number): PwLocator;
90
- first(): PwLocator;
91
- waitFor(options?: { state?: string; timeout?: number }): Promise<void>;
92
- ariaSnapshot(): Promise<string>;
93
- setChecked(checked: boolean, options?: { timeout?: number }): Promise<void>;
94
- }
95
-
96
- export interface PwElementHandle {
97
- evaluate<T>(fn: (el: Element, ...args: unknown[]) => T, ...args: unknown[]): Promise<T>;
98
- }
99
-
100
- export interface PwCookie {
101
- name: string;
102
- value: string;
103
- domain?: string;
104
- path?: string;
105
- url?: string;
106
- expires?: number;
107
- httpOnly?: boolean;
108
- secure?: boolean;
109
- sameSite?: "Lax" | "None" | "Strict";
110
- }
111
-
112
- // ── ARIA browser types ────────────────────────────────────────────────
113
-
114
- export interface BrowserSession {
115
- browser: PwBrowser;
116
- context: PwBrowserContext;
117
- page: PwPage;
118
- }
119
-
120
- export interface RoleRef {
121
- role: string;
122
- name?: string;
123
- /** Index used only when role+name duplicates exist. */
124
- nth?: number;
125
- }
126
-
127
- export type RoleRefMap = Record<string, RoleRef>;
128
-
129
- export interface RoleSnapshotStats {
130
- lines: number;
131
- chars: number;
132
- refs: number;
133
- interactive: number;
134
- }
135
-
136
- export interface SnapshotResult {
137
- /** Text representation of accessibility tree */
138
- snapshot: string;
139
- refs: RoleRefMap;
140
- stats: RoleSnapshotStats;
141
- url: string;
142
- title: string;
143
- }
144
-
145
- export interface BrowserConsoleMessage {
146
- type: string;
147
- text: string;
148
- timestamp: string;
149
- }
150
-
151
- export interface BrowserNetworkRequest {
152
- id: string;
153
- timestamp: string;
154
- method: string;
155
- url: string;
156
- status?: number;
157
- resourceType?: string;
158
- ok?: boolean;
159
- failureText?: string;
160
- }
161
-
162
- export interface BrowserPageError {
163
- message: string;
164
- name?: string;
165
- timestamp: string;
166
- }
167
-
168
- // ── Action union ──────────────────────────────────────────────────────
169
-
170
- export type BrowserAction =
171
- | { action: "launch"; url?: string; headless?: boolean }
172
- | { action: "close" }
173
- | { action: "navigate"; url: string }
174
- | { action: "snapshot"; interactive?: boolean }
175
- | {
176
- action: "click";
177
- ref: string;
178
- button?: "left" | "right" | "middle";
179
- modifiers?: string[];
180
- doubleClick?: boolean;
181
- }
182
- | { action: "type"; ref: string; text: string; submit?: boolean; slowly?: boolean }
183
- | { action: "hover"; ref: string }
184
- | { action: "drag"; startRef: string; endRef: string }
185
- | { action: "select_option"; ref: string; values: string[] }
186
- | { action: "press_key"; key: string }
187
- | { action: "scroll"; direction: "up" | "down"; amount?: number }
188
- | { action: "evaluate"; script: string }
189
- | { action: "screenshot" }
190
- | { action: "get_console"; level?: string }
191
- | { action: "get_network"; filter?: string }
192
- | { action: "wait"; selector?: string; text?: string; timeout?: number }
193
- | { action: "tab_list" }
194
- | { action: "tab_new"; url?: string }
195
- | { action: "tab_select"; index: number }
196
- | { action: "tab_close"; index?: number }
197
- | { action: "cookies_get"; url?: string }
198
- | {
199
- action: "cookies_set";
200
- cookies: Array<{ name: string; value: string; domain: string; path?: string }>;
201
- }
202
- | { action: "cookies_clear" }
203
- | { action: "upload"; ref: string; paths: string[] };