@developerz.ai/ui-debugger-mcp 1.0.0

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 (162) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -0
  3. package/dist/adapters/android/adb.d.ts +38 -0
  4. package/dist/adapters/android/adb.js +72 -0
  5. package/dist/adapters/android/adb.js.map +1 -0
  6. package/dist/adapters/android/android-adapter.d.ts +63 -0
  7. package/dist/adapters/android/android-adapter.js +306 -0
  8. package/dist/adapters/android/android-adapter.js.map +1 -0
  9. package/dist/adapters/android/commands.d.ts +59 -0
  10. package/dist/adapters/android/commands.js +178 -0
  11. package/dist/adapters/android/commands.js.map +1 -0
  12. package/dist/adapters/android/uiautomator.d.ts +81 -0
  13. package/dist/adapters/android/uiautomator.js +296 -0
  14. package/dist/adapters/android/uiautomator.js.map +1 -0
  15. package/dist/adapters/browser/browser-adapter.d.ts +72 -0
  16. package/dist/adapters/browser/browser-adapter.js +434 -0
  17. package/dist/adapters/browser/browser-adapter.js.map +1 -0
  18. package/dist/adapters/browser/cdp.d.ts +83 -0
  19. package/dist/adapters/browser/cdp.js +308 -0
  20. package/dist/adapters/browser/cdp.js.map +1 -0
  21. package/dist/adapters/browser/query.d.ts +25 -0
  22. package/dist/adapters/browser/query.js +85 -0
  23. package/dist/adapters/browser/query.js.map +1 -0
  24. package/dist/adapters/contract.d.ts +159 -0
  25. package/dist/adapters/contract.js +22 -0
  26. package/dist/adapters/contract.js.map +1 -0
  27. package/dist/adapters/desktop/atspi.d.ts +95 -0
  28. package/dist/adapters/desktop/atspi.js +359 -0
  29. package/dist/adapters/desktop/atspi.js.map +1 -0
  30. package/dist/adapters/desktop/capture.d.ts +35 -0
  31. package/dist/adapters/desktop/capture.js +67 -0
  32. package/dist/adapters/desktop/capture.js.map +1 -0
  33. package/dist/adapters/desktop/desktop-adapter.d.ts +60 -0
  34. package/dist/adapters/desktop/desktop-adapter.js +215 -0
  35. package/dist/adapters/desktop/desktop-adapter.js.map +1 -0
  36. package/dist/adapters/desktop/input.d.ts +67 -0
  37. package/dist/adapters/desktop/input.js +191 -0
  38. package/dist/adapters/desktop/input.js.map +1 -0
  39. package/dist/adapters/desktop/proc.d.ts +23 -0
  40. package/dist/adapters/desktop/proc.js +38 -0
  41. package/dist/adapters/desktop/proc.js.map +1 -0
  42. package/dist/adapters/factory.d.ts +23 -0
  43. package/dist/adapters/factory.js +45 -0
  44. package/dist/adapters/factory.js.map +1 -0
  45. package/dist/agent/belt/act.d.ts +100 -0
  46. package/dist/agent/belt/act.js +166 -0
  47. package/dist/agent/belt/act.js.map +1 -0
  48. package/dist/agent/belt/look.d.ts +98 -0
  49. package/dist/agent/belt/look.js +160 -0
  50. package/dist/agent/belt/look.js.map +1 -0
  51. package/dist/agent/belt/observe.d.ts +102 -0
  52. package/dist/agent/belt/observe.js +185 -0
  53. package/dist/agent/belt/observe.js.map +1 -0
  54. package/dist/agent/belt/report.d.ts +133 -0
  55. package/dist/agent/belt/report.js +112 -0
  56. package/dist/agent/belt/report.js.map +1 -0
  57. package/dist/agent/loop.d.ts +136 -0
  58. package/dist/agent/loop.js +173 -0
  59. package/dist/agent/loop.js.map +1 -0
  60. package/dist/agent/models.d.ts +26 -0
  61. package/dist/agent/models.js +22 -0
  62. package/dist/agent/models.js.map +1 -0
  63. package/dist/agent/prompts/android-addendum.d.ts +12 -0
  64. package/dist/agent/prompts/android-addendum.js +76 -0
  65. package/dist/agent/prompts/android-addendum.js.map +1 -0
  66. package/dist/agent/prompts/compose.d.ts +30 -0
  67. package/dist/agent/prompts/compose.js +52 -0
  68. package/dist/agent/prompts/compose.js.map +1 -0
  69. package/dist/agent/prompts/debug-agent.d.ts +9 -0
  70. package/dist/agent/prompts/debug-agent.js +102 -0
  71. package/dist/agent/prompts/debug-agent.js.map +1 -0
  72. package/dist/agent/prompts/desktop-addendum.d.ts +10 -0
  73. package/dist/agent/prompts/desktop-addendum.js +66 -0
  74. package/dist/agent/prompts/desktop-addendum.js.map +1 -0
  75. package/dist/agent/prompts/web-addendum.d.ts +9 -0
  76. package/dist/agent/prompts/web-addendum.js +70 -0
  77. package/dist/agent/prompts/web-addendum.js.map +1 -0
  78. package/dist/agent/provider.d.ts +17 -0
  79. package/dist/agent/provider.js +29 -0
  80. package/dist/agent/provider.js.map +1 -0
  81. package/dist/cli/control.d.ts +19 -0
  82. package/dist/cli/control.js +152 -0
  83. package/dist/cli/control.js.map +1 -0
  84. package/dist/cli/help.d.ts +9 -0
  85. package/dist/cli/help.js +41 -0
  86. package/dist/cli/help.js.map +1 -0
  87. package/dist/cli/init.d.ts +20 -0
  88. package/dist/cli/init.js +119 -0
  89. package/dist/cli/init.js.map +1 -0
  90. package/dist/config/load.d.ts +64 -0
  91. package/dist/config/load.js +105 -0
  92. package/dist/config/load.js.map +1 -0
  93. package/dist/config/schema.d.ts +105 -0
  94. package/dist/config/schema.js +62 -0
  95. package/dist/config/schema.js.map +1 -0
  96. package/dist/errors.d.ts +41 -0
  97. package/dist/errors.js +90 -0
  98. package/dist/errors.js.map +1 -0
  99. package/dist/findings/schema.d.ts +64 -0
  100. package/dist/findings/schema.js +27 -0
  101. package/dist/findings/schema.js.map +1 -0
  102. package/dist/index.d.ts +2 -0
  103. package/dist/index.js +4 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/main.d.ts +2 -0
  106. package/dist/main.js +95 -0
  107. package/dist/main.js.map +1 -0
  108. package/dist/mcp/server.d.ts +25 -0
  109. package/dist/mcp/server.js +31 -0
  110. package/dist/mcp/server.js.map +1 -0
  111. package/dist/mcp/tools/describe.d.ts +12 -0
  112. package/dist/mcp/tools/describe.js +32 -0
  113. package/dist/mcp/tools/describe.js.map +1 -0
  114. package/dist/mcp/tools/end-session.d.ts +11 -0
  115. package/dist/mcp/tools/end-session.js +27 -0
  116. package/dist/mcp/tools/end-session.js.map +1 -0
  117. package/dist/mcp/tools/get-findings.d.ts +12 -0
  118. package/dist/mcp/tools/get-findings.js +42 -0
  119. package/dist/mcp/tools/get-findings.js.map +1 -0
  120. package/dist/mcp/tools/index.d.ts +17 -0
  121. package/dist/mcp/tools/index.js +24 -0
  122. package/dist/mcp/tools/index.js.map +1 -0
  123. package/dist/mcp/tools/result.d.ts +10 -0
  124. package/dist/mcp/tools/result.js +20 -0
  125. package/dist/mcp/tools/result.js.map +1 -0
  126. package/dist/mcp/tools/send-message.d.ts +11 -0
  127. package/dist/mcp/tools/send-message.js +31 -0
  128. package/dist/mcp/tools/send-message.js.map +1 -0
  129. package/dist/mcp/tools/start-debug.d.ts +12 -0
  130. package/dist/mcp/tools/start-debug.js +50 -0
  131. package/dist/mcp/tools/start-debug.js.map +1 -0
  132. package/dist/services/debug-service.d.ts +133 -0
  133. package/dist/services/debug-service.js +163 -0
  134. package/dist/services/debug-service.js.map +1 -0
  135. package/dist/services/replay.d.ts +102 -0
  136. package/dist/services/replay.js +184 -0
  137. package/dist/services/replay.js.map +1 -0
  138. package/dist/services/session-builder.d.ts +65 -0
  139. package/dist/services/session-builder.js +198 -0
  140. package/dist/services/session-builder.js.map +1 -0
  141. package/dist/services/summarize.d.ts +59 -0
  142. package/dist/services/summarize.js +93 -0
  143. package/dist/services/summarize.js.map +1 -0
  144. package/dist/session/findings-store.d.ts +52 -0
  145. package/dist/session/findings-store.js +176 -0
  146. package/dist/session/findings-store.js.map +1 -0
  147. package/dist/session/manager.d.ts +47 -0
  148. package/dist/session/manager.js +66 -0
  149. package/dist/session/manager.js.map +1 -0
  150. package/dist/session/process-identity.d.ts +45 -0
  151. package/dist/session/process-identity.js +81 -0
  152. package/dist/session/process-identity.js.map +1 -0
  153. package/dist/session/session.d.ts +156 -0
  154. package/dist/session/session.js +309 -0
  155. package/dist/session/session.js.map +1 -0
  156. package/dist/session/state-file.d.ts +72 -0
  157. package/dist/session/state-file.js +104 -0
  158. package/dist/session/state-file.js.map +1 -0
  159. package/dist/session/workspace.d.ts +60 -0
  160. package/dist/session/workspace.js +75 -0
  161. package/dist/session/workspace.js.map +1 -0
  162. package/package.json +53 -0
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Desktop read state — the AT-SPI2 accessibility tree over D-Bus (`org.a11y.atspi`).
3
+ *
4
+ * AT-SPI2 is the one display-agnostic read path (same on X11 and Wayland). We reach
5
+ * it via **busctl** (systemd, no extra deps), which speaks D-Bus and emits machine
6
+ * JSON (`--json=short`). The walk is a two-bus hop (`idea/desktop-control.md`):
7
+ * 1. session bus → `org.a11y.Bus.GetAddress` yields the a11y peer-bus address,
8
+ * 2. a11y bus → from the registry root, recurse `Accessible.GetChildren`,
9
+ * reading `GetRoleName`, `Name`, `GetState`, and `Component.GetExtents(SCREEN)`
10
+ * per node, normalizing each onto the contract {@link Node}.
11
+ *
12
+ * One busctl process per call makes this spawn-heavy; the walk is bounded by
13
+ * `maxNodes`/`maxDepth` to stay sane. Chromium/Electron need
14
+ * `--force-renderer-accessibility`; canvas/games expose nothing → vision fallback
15
+ * (future). Fails loud — a malformed reply or unreachable bus throws {@link AdapterError}.
16
+ *
17
+ * The wire-shape parsers (busctl JSON, extents, state bitfield, role map, filters)
18
+ * are pure and unit-tested; {@link BusctlAtspi} is the integration-validated runner.
19
+ */
20
+ import type { Bounds, Filters, Node, Query } from '../contract.js';
21
+ /** A node plus the computed `visible` flag backing the `visible_eq` filter. */
22
+ export interface AtspiNode extends Node {
23
+ visible: boolean;
24
+ }
25
+ /** A D-Bus object reference on the a11y bus — `(unique-name, object-path)`. */
26
+ export interface AtspiRef {
27
+ dest: string;
28
+ path: string;
29
+ }
30
+ /** Tunables for one {@link AtspiSource.readTree} walk. */
31
+ export interface AtspiReadOptions {
32
+ maxNodes?: number;
33
+ maxDepth?: number;
34
+ }
35
+ /** The read seam the adapter depends on — implemented by {@link BusctlAtspi}, faked in tests. */
36
+ export interface AtspiSource {
37
+ readTree(opts?: AtspiReadOptions): Promise<AtspiNode[]>;
38
+ }
39
+ /** Whitelisted `filters` keys for desktop nodes — anything else is rejected, not ignored. */
40
+ export declare const DESKTOP_FILTER_KEYS: readonly ["visible_eq", "enabled_eq", "role_in", "name_contains"];
41
+ /** Normalize an AT-SPI role name to a contract role; unknown roles pass through cleaned. */
42
+ export declare function mapRole(roleName: string): string;
43
+ /** Parse a busctl `--json=short` reply, returning its `data` field (loud on malformed JSON). */
44
+ export declare function busctlData(stdout: string): unknown;
45
+ /** Decode `Component.GetExtents` `(iiii)` → screen {@link Bounds}. */
46
+ export declare function parseExtents(value: unknown): Bounds;
47
+ /** Decode `Accessible.GetState` `au` → the two 32-bit state words `[low, high]`. */
48
+ export declare function parseStateWords(value: unknown): [number, number];
49
+ /** True when `bit` is set in the split 64-bit AT-SPI state field. */
50
+ export declare function hasState(words: [number, number], bit: number): boolean;
51
+ /** Derive the contract `enabled` + internal `visible` flags from a state field. */
52
+ export declare function stateFlags(words: [number, number]): {
53
+ enabled: boolean;
54
+ visible: boolean;
55
+ };
56
+ /** Decode `Accessible.GetChildren` `a(so)` → child {@link AtspiRef}s. */
57
+ export declare function parseChildren(value: unknown): AtspiRef[];
58
+ /** A parsed agent query: an optional role and/or a name substring. */
59
+ export interface ParsedQuery {
60
+ role?: string;
61
+ name?: string;
62
+ }
63
+ /** Parse an agent target (`button "Save"` or plain `Save`) into a {@link ParsedQuery}. */
64
+ export declare function parseRoleNameQuery(raw: string): ParsedQuery;
65
+ /** True when a node satisfies a {@link ParsedQuery} (role exact, name case-insensitive substring). */
66
+ export declare function matchesQuery(node: Node, parsed: ParsedQuery): boolean;
67
+ /**
68
+ * Apply the whitelisted node `filters` in JS. Throws {@link AdapterError} on an
69
+ * unknown key (no silent injection surface) or a wrong value type.
70
+ */
71
+ export declare function applyDesktopFilters(nodes: AtspiNode[], filters?: Filters): AtspiNode[];
72
+ /** Drop the internal `visible` flag — the public contract returns plain {@link Node}s. */
73
+ export declare function toNode(node: AtspiNode): Node;
74
+ /** True when a node's center sits inside `region` — used to scope a read by `within`. */
75
+ export declare function centerWithin(node: Node, region: Bounds): boolean;
76
+ /**
77
+ * Scope, filter, query-match and cap a read tree onto contract {@link Node}s —
78
+ * the shared shaping `readState`/`find` apply after the (adapter-side) walk.
79
+ */
80
+ export declare function shapeNodes(nodes: AtspiNode[], opts: Query, defaultLimit: number, region?: Bounds): Node[];
81
+ /** A busctl invocation (args only — the `busctl` binary is fixed). Injected for tests. */
82
+ export type BusctlExec = (args: string[]) => Promise<string>;
83
+ /**
84
+ * {@link AtspiSource} backed by `busctl`. Walks the a11y tree breadth-first from the
85
+ * registry root, bounded by `maxNodes`/`maxDepth`. Resolves the a11y bus address once
86
+ * and caches it. Every reply is validated by the pure parsers above; failures throw loud.
87
+ */
88
+ export declare class BusctlAtspi implements AtspiSource {
89
+ #private;
90
+ constructor(init?: {
91
+ display?: string;
92
+ exec?: BusctlExec;
93
+ });
94
+ readTree(opts?: AtspiReadOptions): Promise<AtspiNode[]>;
95
+ }
@@ -0,0 +1,359 @@
1
+ /**
2
+ * Desktop read state — the AT-SPI2 accessibility tree over D-Bus (`org.a11y.atspi`).
3
+ *
4
+ * AT-SPI2 is the one display-agnostic read path (same on X11 and Wayland). We reach
5
+ * it via **busctl** (systemd, no extra deps), which speaks D-Bus and emits machine
6
+ * JSON (`--json=short`). The walk is a two-bus hop (`idea/desktop-control.md`):
7
+ * 1. session bus → `org.a11y.Bus.GetAddress` yields the a11y peer-bus address,
8
+ * 2. a11y bus → from the registry root, recurse `Accessible.GetChildren`,
9
+ * reading `GetRoleName`, `Name`, `GetState`, and `Component.GetExtents(SCREEN)`
10
+ * per node, normalizing each onto the contract {@link Node}.
11
+ *
12
+ * One busctl process per call makes this spawn-heavy; the walk is bounded by
13
+ * `maxNodes`/`maxDepth` to stay sane. Chromium/Electron need
14
+ * `--force-renderer-accessibility`; canvas/games expose nothing → vision fallback
15
+ * (future). Fails loud — a malformed reply or unreachable bus throws {@link AdapterError}.
16
+ *
17
+ * The wire-shape parsers (busctl JSON, extents, state bitfield, role map, filters)
18
+ * are pure and unit-tested; {@link BusctlAtspi} is the integration-validated runner.
19
+ */
20
+ import { AdapterError } from '../../errors.js';
21
+ import { desktopEnv, makeExec } from './proc.js';
22
+ const A11Y_IFACE = 'org.a11y.atspi.Accessible';
23
+ const COMPONENT_IFACE = 'org.a11y.atspi.Component';
24
+ const REGISTRY_DEST = 'org.a11y.atspi.Registry';
25
+ const ROOT_PATH = '/org/a11y/atspi/accessible/root';
26
+ /** `ATSPI_COORD_TYPE_SCREEN` — extents relative to the screen, for clicks + vision. */
27
+ const COORD_SCREEN = 0;
28
+ /** Walk caps — keep the (spawn-heavy) tree read bounded. */
29
+ const DEFAULT_MAX_NODES = 200;
30
+ const DEFAULT_MAX_DEPTH = 25;
31
+ /** `AtspiStateType` bit indices we care about (full enum in at-spi2-core). */
32
+ const STATE_ENABLED = 8;
33
+ const STATE_SENSITIVE = 24;
34
+ const STATE_SHOWING = 25;
35
+ const STATE_VISIBLE = 30;
36
+ /** Whitelisted `filters` keys for desktop nodes — anything else is rejected, not ignored. */
37
+ export const DESKTOP_FILTER_KEYS = [
38
+ 'visible_eq',
39
+ 'enabled_eq',
40
+ 'role_in',
41
+ 'name_contains',
42
+ ];
43
+ // --- Role mapping -----------------------------------------------------------
44
+ /** AT-SPI `GetRoleName` strings → contract roles (ARIA-ish, target-agnostic). */
45
+ const ROLE_MAP = {
46
+ 'push button': 'button',
47
+ 'toggle button': 'button',
48
+ button: 'button',
49
+ link: 'link',
50
+ entry: 'textbox',
51
+ 'password text': 'textbox',
52
+ text: 'textbox',
53
+ 'check box': 'checkbox',
54
+ 'check menu item': 'menuitem',
55
+ 'radio button': 'radio',
56
+ 'radio menu item': 'menuitem',
57
+ 'combo box': 'combobox',
58
+ slider: 'slider',
59
+ 'spin button': 'spinbutton',
60
+ 'page tab': 'tab',
61
+ 'page tab list': 'tablist',
62
+ heading: 'heading',
63
+ label: 'label',
64
+ 'menu item': 'menuitem',
65
+ menu: 'menu',
66
+ 'list item': 'listitem',
67
+ list: 'list',
68
+ table: 'table',
69
+ image: 'img',
70
+ icon: 'img',
71
+ frame: 'window',
72
+ window: 'window',
73
+ dialog: 'dialog',
74
+ alert: 'alert',
75
+ 'tool bar': 'toolbar',
76
+ 'status bar': 'status',
77
+ 'document web': 'document',
78
+ panel: 'group',
79
+ filler: 'group',
80
+ section: 'group',
81
+ };
82
+ /** Normalize an AT-SPI role name to a contract role; unknown roles pass through cleaned. */
83
+ export function mapRole(roleName) {
84
+ const key = roleName.trim().toLowerCase();
85
+ return ROLE_MAP[key] ?? key.replace(/\s+/g, ' ');
86
+ }
87
+ // --- Type guards (fail loud, never coerce) ----------------------------------
88
+ function asArray(value, ctx) {
89
+ if (!Array.isArray(value))
90
+ throw new AdapterError(`AT-SPI: expected an array for ${ctx}`);
91
+ return value;
92
+ }
93
+ function asString(value, ctx) {
94
+ if (typeof value !== 'string')
95
+ throw new AdapterError(`AT-SPI: expected a string for ${ctx}`);
96
+ return value;
97
+ }
98
+ function asNumber(value, ctx) {
99
+ if (typeof value !== 'number')
100
+ throw new AdapterError(`AT-SPI: expected a number for ${ctx}`);
101
+ return value;
102
+ }
103
+ // --- busctl JSON parsing ----------------------------------------------------
104
+ /** Parse a busctl `--json=short` reply, returning its `data` field (loud on malformed JSON). */
105
+ export function busctlData(stdout) {
106
+ let parsed;
107
+ try {
108
+ parsed = JSON.parse(stdout);
109
+ }
110
+ catch {
111
+ throw new AdapterError(`AT-SPI: busctl returned non-JSON: ${stdout.slice(0, 120)}`);
112
+ }
113
+ if (typeof parsed !== 'object' || parsed === null || !('data' in parsed)) {
114
+ throw new AdapterError('AT-SPI: busctl reply missing `data`');
115
+ }
116
+ return parsed.data;
117
+ }
118
+ /** First return value of a method `call` (busctl wraps returns in a `data` array). */
119
+ function firstReturn(data, ctx) {
120
+ const arr = asArray(data, ctx);
121
+ if (arr.length === 0)
122
+ throw new AdapterError(`AT-SPI: empty reply for ${ctx}`);
123
+ return arr[0];
124
+ }
125
+ /** Decode `Component.GetExtents` `(iiii)` → screen {@link Bounds}. */
126
+ export function parseExtents(value) {
127
+ const a = asArray(value, 'extents');
128
+ if (a.length < 4)
129
+ throw new AdapterError('AT-SPI: extents needs 4 ints');
130
+ return {
131
+ x: asNumber(a[0], 'extents.x'),
132
+ y: asNumber(a[1], 'extents.y'),
133
+ width: asNumber(a[2], 'extents.width'),
134
+ height: asNumber(a[3], 'extents.height'),
135
+ };
136
+ }
137
+ /** Decode `Accessible.GetState` `au` → the two 32-bit state words `[low, high]`. */
138
+ export function parseStateWords(value) {
139
+ const a = asArray(value, 'state');
140
+ if (a.length < 2)
141
+ throw new AdapterError('AT-SPI: state needs 2 words');
142
+ return [asNumber(a[0], 'state[0]'), asNumber(a[1], 'state[1]')];
143
+ }
144
+ /** True when `bit` is set in the split 64-bit AT-SPI state field. */
145
+ export function hasState(words, bit) {
146
+ const word = bit < 32 ? words[0] : words[1];
147
+ return ((word >>> (bit % 32)) & 1) === 1;
148
+ }
149
+ /** Derive the contract `enabled` + internal `visible` flags from a state field. */
150
+ export function stateFlags(words) {
151
+ return {
152
+ enabled: hasState(words, STATE_ENABLED) && hasState(words, STATE_SENSITIVE),
153
+ visible: hasState(words, STATE_SHOWING) && hasState(words, STATE_VISIBLE),
154
+ };
155
+ }
156
+ /** Decode `Accessible.GetChildren` `a(so)` → child {@link AtspiRef}s. */
157
+ export function parseChildren(value) {
158
+ return asArray(value, 'children').map((entry) => {
159
+ const pair = asArray(entry, 'childRef');
160
+ if (pair.length < 2)
161
+ throw new AdapterError('AT-SPI: child ref needs (dest, path)');
162
+ return { dest: asString(pair[0], 'childRef.dest'), path: asString(pair[1], 'childRef.path') };
163
+ });
164
+ }
165
+ /** Parse an agent target (`button "Save"` or plain `Save`) into a {@link ParsedQuery}. */
166
+ export function parseRoleNameQuery(raw) {
167
+ const q = raw.trim();
168
+ const match = /^([a-zA-Z][\w-]*)\s+["'](.+)["']$/.exec(q);
169
+ const role = match?.[1];
170
+ const name = match?.[2];
171
+ if (role && name)
172
+ return { role: role.toLowerCase(), name };
173
+ return { name: q };
174
+ }
175
+ /** True when a node satisfies a {@link ParsedQuery} (role exact, name case-insensitive substring). */
176
+ export function matchesQuery(node, parsed) {
177
+ if (parsed.role && node.role.toLowerCase() !== parsed.role)
178
+ return false;
179
+ if (parsed.name && !node.name.toLowerCase().includes(parsed.name.toLowerCase()))
180
+ return false;
181
+ return true;
182
+ }
183
+ function expectBoolean(key, value) {
184
+ if (typeof value !== 'boolean')
185
+ throw new AdapterError(`filter \`${key}\` expects a boolean`);
186
+ return value;
187
+ }
188
+ function expectString(key, value) {
189
+ if (typeof value !== 'string')
190
+ throw new AdapterError(`filter \`${key}\` expects a string`);
191
+ return value;
192
+ }
193
+ function expectStringArray(key, value) {
194
+ if (!Array.isArray(value) || value.some((v) => typeof v !== 'string')) {
195
+ throw new AdapterError(`filter \`${key}\` expects a string[]`);
196
+ }
197
+ return value;
198
+ }
199
+ /**
200
+ * Apply the whitelisted node `filters` in JS. Throws {@link AdapterError} on an
201
+ * unknown key (no silent injection surface) or a wrong value type.
202
+ */
203
+ export function applyDesktopFilters(nodes, filters) {
204
+ if (!filters)
205
+ return nodes;
206
+ let out = nodes;
207
+ for (const [key, value] of Object.entries(filters)) {
208
+ switch (key) {
209
+ case 'visible_eq': {
210
+ const want = expectBoolean(key, value);
211
+ out = out.filter((n) => n.visible === want);
212
+ break;
213
+ }
214
+ case 'enabled_eq': {
215
+ const want = expectBoolean(key, value);
216
+ out = out.filter((n) => n.enabled === want);
217
+ break;
218
+ }
219
+ case 'role_in': {
220
+ const roles = expectStringArray(key, value);
221
+ out = out.filter((n) => roles.includes(n.role));
222
+ break;
223
+ }
224
+ case 'name_contains': {
225
+ const needle = expectString(key, value).toLowerCase();
226
+ out = out.filter((n) => n.name.toLowerCase().includes(needle));
227
+ break;
228
+ }
229
+ default:
230
+ throw new AdapterError(`unknown filter \`${key}\` for desktop adapter (allowed: ${DESKTOP_FILTER_KEYS.join(', ')})`);
231
+ }
232
+ }
233
+ return out;
234
+ }
235
+ /** Drop the internal `visible` flag — the public contract returns plain {@link Node}s. */
236
+ export function toNode(node) {
237
+ return { role: node.role, name: node.name, bounds: node.bounds, enabled: node.enabled };
238
+ }
239
+ /** True when a node's center sits inside `region` — used to scope a read by `within`. */
240
+ export function centerWithin(node, region) {
241
+ const cx = node.bounds.x + node.bounds.width / 2;
242
+ const cy = node.bounds.y + node.bounds.height / 2;
243
+ return (cx >= region.x &&
244
+ cx <= region.x + region.width &&
245
+ cy >= region.y &&
246
+ cy <= region.y + region.height);
247
+ }
248
+ /**
249
+ * Scope, filter, query-match and cap a read tree onto contract {@link Node}s —
250
+ * the shared shaping `readState`/`find` apply after the (adapter-side) walk.
251
+ */
252
+ export function shapeNodes(nodes, opts, defaultLimit, region) {
253
+ let out = nodes;
254
+ if (region)
255
+ out = out.filter((n) => centerWithin(n, region));
256
+ if (opts.query) {
257
+ const parsed = parseRoleNameQuery(opts.query);
258
+ out = out.filter((n) => matchesQuery(n, parsed));
259
+ }
260
+ out = applyDesktopFilters(out, opts.filters);
261
+ const limit = opts.limit ?? defaultLimit;
262
+ return out.slice(0, limit).map(toNode);
263
+ }
264
+ /**
265
+ * {@link AtspiSource} backed by `busctl`. Walks the a11y tree breadth-first from the
266
+ * registry root, bounded by `maxNodes`/`maxDepth`. Resolves the a11y bus address once
267
+ * and caches it. Every reply is validated by the pure parsers above; failures throw loud.
268
+ */
269
+ export class BusctlAtspi {
270
+ #exec;
271
+ #address = null;
272
+ constructor(init = {}) {
273
+ const exec = makeExec(desktopEnv(init.display));
274
+ this.#exec = init.exec ?? ((args) => exec('busctl', args));
275
+ }
276
+ async readTree(opts = {}) {
277
+ const maxNodes = opts.maxNodes ?? DEFAULT_MAX_NODES;
278
+ const maxDepth = opts.maxDepth ?? DEFAULT_MAX_DEPTH;
279
+ const out = [];
280
+ const seen = new Set();
281
+ // Start at the registry root's children (apps); the desktop root itself is not UI.
282
+ let frontier = await this.#children({ dest: REGISTRY_DEST, path: ROOT_PATH });
283
+ for (let depth = 0; frontier.length > 0 && depth < maxDepth; depth += 1) {
284
+ const next = [];
285
+ for (const ref of frontier) {
286
+ if (out.length >= maxNodes)
287
+ return out;
288
+ const key = `${ref.dest}${ref.path}`;
289
+ if (seen.has(key))
290
+ continue;
291
+ seen.add(key);
292
+ out.push(await this.#describe(ref));
293
+ next.push(...(await this.#children(ref)));
294
+ }
295
+ frontier = next;
296
+ }
297
+ return out;
298
+ }
299
+ /** Resolve (and cache) the a11y peer-bus address via the session bus. */
300
+ async #a11yAddress() {
301
+ if (this.#address)
302
+ return this.#address;
303
+ const data = busctlData(await this.#exec([
304
+ '--user',
305
+ '--json=short',
306
+ 'call',
307
+ 'org.a11y.Bus',
308
+ '/org/a11y/bus',
309
+ 'org.a11y.Bus',
310
+ 'GetAddress',
311
+ ]));
312
+ const address = asString(firstReturn(data, 'GetAddress'), 'a11y bus address');
313
+ if (address === '')
314
+ throw new AdapterError('AT-SPI: empty a11y bus address');
315
+ this.#address = address;
316
+ return address;
317
+ }
318
+ /** Call a method on the a11y bus, returning the parsed `data` array of return values. */
319
+ async #call(ref, iface, member, extra = []) {
320
+ const address = await this.#a11yAddress();
321
+ return busctlData(await this.#exec([
322
+ `--address=${address}`,
323
+ '--json=short',
324
+ 'call',
325
+ ref.dest,
326
+ ref.path,
327
+ iface,
328
+ member,
329
+ ...extra,
330
+ ]));
331
+ }
332
+ async #children(ref) {
333
+ return parseChildren(firstReturn(await this.#call(ref, A11Y_IFACE, 'GetChildren'), 'GetChildren'));
334
+ }
335
+ /** Read the `Name` property as a plain scalar (`get-property` avoids a variant wrapper). */
336
+ async #name(ref) {
337
+ const address = await this.#a11yAddress();
338
+ const data = busctlData(await this.#exec([
339
+ `--address=${address}`,
340
+ '--json=short',
341
+ 'get-property',
342
+ ref.dest,
343
+ ref.path,
344
+ A11Y_IFACE,
345
+ 'Name',
346
+ ]));
347
+ return asString(data, 'Name');
348
+ }
349
+ /** Read a single node's role/name/state/extents into a normalized {@link AtspiNode}. */
350
+ async #describe(ref) {
351
+ const roleName = asString(firstReturn(await this.#call(ref, A11Y_IFACE, 'GetRoleName'), 'GetRoleName'), 'GetRoleName');
352
+ const role = mapRole(roleName);
353
+ const name = await this.#name(ref);
354
+ const { enabled, visible } = stateFlags(parseStateWords(firstReturn(await this.#call(ref, A11Y_IFACE, 'GetState'), 'GetState')));
355
+ const bounds = parseExtents(firstReturn(await this.#call(ref, COMPONENT_IFACE, 'GetExtents', ['u', String(COORD_SCREEN)]), 'GetExtents'));
356
+ return { role, name, bounds, enabled, visible };
357
+ }
358
+ }
359
+ //# sourceMappingURL=atspi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"atspi.js","sourceRoot":"","sources":["../../../src/adapters/desktop/atspi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAa,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE5D,MAAM,UAAU,GAAG,2BAA2B,CAAC;AAC/C,MAAM,eAAe,GAAG,0BAA0B,CAAC;AACnD,MAAM,aAAa,GAAG,yBAAyB,CAAC;AAChD,MAAM,SAAS,GAAG,iCAAiC,CAAC;AAEpD,uFAAuF;AACvF,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,4DAA4D;AAC5D,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAC9B,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,8EAA8E;AAC9E,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,aAAa,GAAG,EAAE,CAAC;AACzB,MAAM,aAAa,GAAG,EAAE,CAAC;AAwBzB,6FAA6F;AAC7F,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,eAAe;CACP,CAAC;AAEX,+EAA+E;AAE/E,iFAAiF;AACjF,MAAM,QAAQ,GAA2B;IACvC,aAA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CAAC,CAAC;QACnC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,UAAU,CACrC,eAAe,CAAC,WAAW,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC,CACxF,CAAC;QACF,MAAM,MAAM,GAAG,YAAY,CACzB,WAAW,CACT,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,eAAe,EAAE,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,EACjF,YAAY,CACb,CACF,CAAC;QACF,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAClD,CAAC;CACF"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Desktop screenshots — compositor-aware capture to PNG bytes.
3
+ *
4
+ * There is no universal Linux screen-capture API: naive X11 grabbers return BLACK
5
+ * on Wayland (`idea/desktop-control.md`). So detect the session and dispatch —
6
+ * **grim** on wlroots/Wayland, **scrot** on X11. Both write a temp PNG we read and
7
+ * delete, keeping one uniform path. GNOME/KDE D-Bus + portal routes are future work.
8
+ *
9
+ * The picker + arg builders are pure and unit-tested; {@link Screenshot} is the
10
+ * thin runner that shells out and fails loud as an {@link AdapterError}.
11
+ */
12
+ import { type Exec } from './proc.js';
13
+ /** Capture backends we dispatch to, chosen by the live session type. */
14
+ export type CaptureTool = 'grim' | 'scrot';
15
+ /**
16
+ * Pick the capture tool from the environment: Wayland (`WAYLAND_DISPLAY`) → grim,
17
+ * X11 (`DISPLAY`) → scrot. Throws loud when neither is set — there is nothing to capture.
18
+ */
19
+ export declare function chooseCaptureTool(env: NodeJS.ProcessEnv): CaptureTool;
20
+ /** Build the capture argv that writes a PNG to `file` (grim: positional · scrot: `--overwrite`). */
21
+ export declare function captureArgs(tool: CaptureTool, file: string): string[];
22
+ /** Screenshot surface the adapter calls — implemented by {@link Screenshot}, faked in tests. */
23
+ export interface ScreenCapture {
24
+ capture(): Promise<Uint8Array>;
25
+ }
26
+ /** grim/scrot-backed {@link ScreenCapture}. Construct with a target `display` (or inject `exec`). */
27
+ export declare class Screenshot implements ScreenCapture {
28
+ #private;
29
+ constructor(init?: {
30
+ display?: string;
31
+ exec?: Exec;
32
+ });
33
+ /** Capture the current frame as PNG bytes via a temp file (read then deleted). */
34
+ capture(): Promise<Uint8Array>;
35
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Desktop screenshots — compositor-aware capture to PNG bytes.
3
+ *
4
+ * There is no universal Linux screen-capture API: naive X11 grabbers return BLACK
5
+ * on Wayland (`idea/desktop-control.md`). So detect the session and dispatch —
6
+ * **grim** on wlroots/Wayland, **scrot** on X11. Both write a temp PNG we read and
7
+ * delete, keeping one uniform path. GNOME/KDE D-Bus + portal routes are future work.
8
+ *
9
+ * The picker + arg builders are pure and unit-tested; {@link Screenshot} is the
10
+ * thin runner that shells out and fails loud as an {@link AdapterError}.
11
+ */
12
+ import { mkdtemp, readFile, rm } from 'node:fs/promises';
13
+ import { tmpdir } from 'node:os';
14
+ import { join } from 'node:path';
15
+ import { AdapterError } from '../../errors.js';
16
+ import { desktopEnv, errMessage, makeExec } from './proc.js';
17
+ /**
18
+ * Pick the capture tool from the environment: Wayland (`WAYLAND_DISPLAY`) → grim,
19
+ * X11 (`DISPLAY`) → scrot. Throws loud when neither is set — there is nothing to capture.
20
+ */
21
+ export function chooseCaptureTool(env) {
22
+ if (env.WAYLAND_DISPLAY)
23
+ return 'grim';
24
+ if (env.DISPLAY)
25
+ return 'scrot';
26
+ throw new AdapterError('desktop: cannot screenshot — neither WAYLAND_DISPLAY nor DISPLAY is set');
27
+ }
28
+ /** Build the capture argv that writes a PNG to `file` (grim: positional · scrot: `--overwrite`). */
29
+ export function captureArgs(tool, file) {
30
+ switch (tool) {
31
+ case 'grim':
32
+ return [file];
33
+ case 'scrot':
34
+ return ['--overwrite', file];
35
+ default: {
36
+ const unreachable = tool;
37
+ throw new AdapterError(`unknown capture tool: ${String(unreachable)}`);
38
+ }
39
+ }
40
+ }
41
+ /** grim/scrot-backed {@link ScreenCapture}. Construct with a target `display` (or inject `exec`). */
42
+ export class Screenshot {
43
+ #env;
44
+ #exec;
45
+ constructor(init = {}) {
46
+ this.#env = desktopEnv(init.display);
47
+ this.#exec = init.exec ?? makeExec(this.#env);
48
+ }
49
+ /** Capture the current frame as PNG bytes via a temp file (read then deleted). */
50
+ async capture() {
51
+ const tool = chooseCaptureTool(this.#env);
52
+ const dir = await mkdtemp(join(tmpdir(), 'uidbg-shot-'));
53
+ const file = join(dir, 'shot.png');
54
+ try {
55
+ await this.#exec(tool, captureArgs(tool, file));
56
+ const buffer = await readFile(file);
57
+ return new Uint8Array(buffer);
58
+ }
59
+ catch (error) {
60
+ throw new AdapterError(`desktop.screenshot failed (${tool}): ${errMessage(error)}`);
61
+ }
62
+ finally {
63
+ await rm(dir, { recursive: true, force: true });
64
+ }
65
+ }
66
+ }
67
+ //# sourceMappingURL=capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.js","sourceRoot":"","sources":["../../../src/adapters/desktop/capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAa,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAKxE;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAsB;IACtD,IAAI,GAAG,CAAC,eAAe;QAAE,OAAO,MAAM,CAAC;IACvC,IAAI,GAAG,CAAC,OAAO;QAAE,OAAO,OAAO,CAAC;I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CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,YAAY,CAAC,8BAA8B,IAAI,MAAM,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACtF,CAAC;gBAAS,CAAC;YACT,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Desktop adapter — drives a native Linux app behind the shared {@link Adapter}
3
+ * contract, so the agent loop stays adapter-blind.
4
+ *
5
+ * Composition (split per SRP — see siblings):
6
+ * - read → {@link AtspiSource} (AT-SPI2 a11y tree over D-Bus, `atspi.ts`)
7
+ * - input → {@link PointerInput} (xdotool, X11/XWayland, `input.ts`)
8
+ * - capture→ {@link ScreenCapture} (scrot/grim per compositor, `capture.ts`)
9
+ *
10
+ * **Managed only**: the desktop target has no attach handle (unlike web `cdpUrl` /
11
+ * android `adbSerial`), so `open` launches the configured command and `close` stops
12
+ * it. Reads/clicks key off AT-SPI screen extents; vision fallback is future work.
13
+ *
14
+ * Desktop apps expose no console/network channels — those methods throw loud
15
+ * ({@link AdapterError}), never a silent empty list. Every backend failure surfaces
16
+ * as an {@link AdapterError}; our own loud errors pass through un-rewrapped.
17
+ */
18
+ import type { DesktopTarget } from '../../config/schema.js';
19
+ import type { Adapter, ConsoleEntry, NetworkEntry, Node, NodeRef, Query, ScrollOptions, WaitOptions } from '../contract.js';
20
+ import { type AtspiSource } from './atspi.js';
21
+ import { type ScreenCapture } from './capture.js';
22
+ import { type PointerInput } from './input.js';
23
+ /** Map a pixel scroll `amount` onto a positive integer count of wheel clicks. */
24
+ export declare function scrollRepeat(amount?: number): number;
25
+ export interface DesktopAdapterInit {
26
+ /** Resolved desktop-target config (launch command, window match, display). */
27
+ config: DesktopTarget;
28
+ /** Override the AT-SPI read backend (defaults to {@link BusctlAtspi}); a seam for tests. */
29
+ atspi?: AtspiSource;
30
+ /** Override the input backend (defaults to {@link Xdotool}); a seam for tests. */
31
+ input?: PointerInput;
32
+ /** Override the capture backend (defaults to {@link Screenshot}); a seam for tests. */
33
+ capture?: ScreenCapture;
34
+ }
35
+ /**
36
+ * The desktop {@link Adapter}: an xdotool + AT-SPI2 + scrot/grim trio behind one
37
+ * contract. Construct via {@link DesktopAdapter.create}.
38
+ */
39
+ export declare class DesktopAdapter implements Adapter {
40
+ #private;
41
+ private constructor();
42
+ /** Wire the adapter from config, binding each backend to the chosen X11 display. */
43
+ static create(init: DesktopAdapterInit): DesktopAdapter;
44
+ /** Launch the managed app (once) and activate the target window. `target` is a title fallback. */
45
+ open(target: string): Promise<void>;
46
+ find(opts: Query): Promise<Node | null>;
47
+ readState(opts?: Query): Promise<Node[]>;
48
+ click(target: NodeRef): Promise<void>;
49
+ type(target: NodeRef, text: string): Promise<void>;
50
+ pressKey(key: string): Promise<void>;
51
+ scroll(opts: ScrollOptions): Promise<void>;
52
+ screenshot(): Promise<Uint8Array>;
53
+ waitFor(opts: WaitOptions): Promise<void>;
54
+ /** Desktop apps expose no console channel — unsupported, surfaced loud. */
55
+ console(): Promise<ConsoleEntry[]>;
56
+ /** Desktop apps expose no network channel — unsupported, surfaced loud. */
57
+ network(): Promise<NetworkEntry[]>;
58
+ /** Managed teardown: SIGTERM the launched process group; an already-dead process is a no-op. */
59
+ close(): Promise<void>;
60
+ }