tauri-agent-tools 0.9.0 → 0.9.2

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.
@@ -1,4 +1,4 @@
1
- import { addBridgeOptions } from '../shared.js';
1
+ import { addBridgeOptions, parseIntArg } from '../shared.js';
2
2
  /**
3
3
  * Escapes backslashes and single quotes in CSS selectors for safe
4
4
  * embedding inside JS string literals wrapped in single quotes.
@@ -59,4 +59,269 @@ export function buildWaitAndFindScript(selector, waitMs) {
59
59
  export function addInteractOptions(cmd) {
60
60
  return addBridgeOptions(cmd).option('--json', 'Output result as JSON');
61
61
  }
62
+ // === Value writing + verification (type, select) ===
63
+ /**
64
+ * Default deadline for the post-write re-read. An accepted write resolves on
65
+ * the first (synchronous) check, so it costs nothing; only a rejected write
66
+ * waits out the whole deadline.
67
+ */
68
+ export const DEFAULT_VERIFY_TIMEOUT_MS = 500;
69
+ /**
70
+ * dev_bridge.rs answers 504 after 5 s and BridgeClient.eval aborts at 5 s;
71
+ * keep at least 1 s of slack for dispatch + IPC + HTTP.
72
+ */
73
+ export const MAX_VERIFY_TIMEOUT_MS = 4000;
74
+ /**
75
+ * Poll cadence after the synchronous first check. React commits
76
+ * transition-lane updates on a Scheduler macrotask, so a microtask/rAF
77
+ * re-read would be too early.
78
+ */
79
+ export const VERIFY_INTERVAL_MS = 50;
80
+ export function resolveVerifyTimeout(opts) {
81
+ const ms = opts?.verifyTimeoutMs ?? DEFAULT_VERIFY_TIMEOUT_MS;
82
+ if (!Number.isInteger(ms) || ms < 0 || ms > MAX_VERIFY_TIMEOUT_MS) {
83
+ throw new Error(`--verify-timeout must be an integer between 0 and ${MAX_VERIFY_TIMEOUT_MS} ms (the bridge aborts evals after 5000 ms)`);
84
+ }
85
+ return ms;
86
+ }
87
+ /** Adds --verify-timeout to a value-writing interaction command. */
88
+ export function addVerifyOptions(cmd) {
89
+ return cmd.option('--verify-timeout <ms>', `Max time to wait for the written value to stick before reporting it reverted (max ${MAX_VERIFY_TIMEOUT_MS}, 0 = single check)`, parseIntArg, DEFAULT_VERIFY_TIMEOUT_MS);
90
+ }
91
+ /**
92
+ * JS snippet defining `__resolveValueWriter(node)`.
93
+ *
94
+ * React (react-dom's inputValueTracking) redefines `value` as an own accessor
95
+ * on every mounted <input>/<textarea> instance to remember what it wrote;
96
+ * assigning through that accessor makes the following input/change event a
97
+ * no-op for React (#10). Built-in form elements are therefore written through
98
+ * the prototype setter React itself captured. Custom elements are searched up
99
+ * their prototype chain (Lit/Stencil define accessors on the class prototype)
100
+ * and fall back to plain assignment for instance-defined or class-field
101
+ * `value`s. Anything else has no value setter and is refused instead of being
102
+ * silently given an expando property.
103
+ *
104
+ * The parameter is deliberately named `node` so generated scripts never
105
+ * contain the text `el.value =`.
106
+ */
107
+ export const NATIVE_VALUE_WRITER_SNIPPET = `
108
+ function __resolveValueWriter(node) {
109
+ var tag = node.tagName;
110
+ var proto = tag === 'INPUT' ? HTMLInputElement.prototype
111
+ : tag === 'TEXTAREA' ? HTMLTextAreaElement.prototype
112
+ : tag === 'SELECT' ? HTMLSelectElement.prototype
113
+ : null;
114
+ if (proto) {
115
+ var d = Object.getOwnPropertyDescriptor(proto, 'value');
116
+ if (d && typeof d.set === 'function') return { kind: 'native', set: function (v) { d.set.call(node, v); } };
117
+ return { kind: 'assign', set: function (v) { node.value = v; } };
118
+ }
119
+ if (String(node.localName || '').indexOf('-') !== -1) {
120
+ var p = Object.getPrototypeOf(node);
121
+ while (p && p !== Object.prototype) {
122
+ var cd = Object.getOwnPropertyDescriptor(p, 'value');
123
+ if (cd && typeof cd.set === 'function') return { kind: 'custom', set: function (v) { cd.set.call(node, v); } };
124
+ p = Object.getPrototypeOf(p);
125
+ }
126
+ if ('value' in node) return { kind: 'assign', set: function (v) { node.value = v; } };
127
+ }
128
+ return null;
129
+ }`;
130
+ /**
131
+ * JS snippet defining `__verify(read, expected, timeoutMs, intervalMs)`.
132
+ *
133
+ * The first read is synchronous: React restores a rejected controlled value
134
+ * inside dispatchEvent, so it is already visible. Later reads catch
135
+ * transition-lane commits and frameworks that apply values asynchronously.
136
+ * Resolves `{ ok, observed }` and never rejects. `read` is re-invoked on every
137
+ * tick so a re-mounted node is read instead of a stale reference.
138
+ */
139
+ export const VERIFY_POLL_SNIPPET = `
140
+ function __verify(read, expected, timeoutMs, intervalMs) {
141
+ return new Promise(function (resolve) {
142
+ var deadline = Date.now() + timeoutMs;
143
+ function check() {
144
+ var observed;
145
+ try { observed = read(); } catch (e) { observed = undefined; }
146
+ if (observed === expected) { resolve({ ok: true, observed: observed }); return; }
147
+ if (Date.now() >= deadline) { resolve({ ok: false, observed: observed }); return; }
148
+ setTimeout(check, intervalMs);
149
+ }
150
+ check();
151
+ });
152
+ }`;
153
+ /**
154
+ * JS snippet defining `__settle()` — resolves after two macrotasks. Used after
155
+ * focus()/--clear so that state the app changed in response (React flushes an
156
+ * onFocus setState on a microtask, an accepted clear commits synchronously, and
157
+ * a commit scheduled from the app's own zero-delay timer lands on a Scheduler
158
+ * task after the first macrotask) is visible before the pre-write baseline is
159
+ * read and the target node is re-resolved.
160
+ */
161
+ export const SETTLE_SNIPPET = `
162
+ function __settle() {
163
+ return new Promise(function (resolve) {
164
+ setTimeout(function () { setTimeout(resolve, 0); }, 0);
165
+ });
166
+ }`;
167
+ /** JS snippet defining `__selectOptionValues(node)` — option values of a <select>, [] otherwise. */
168
+ export const SELECT_OPTIONS_SNIPPET = `
169
+ function __selectOptionValues(node) {
170
+ if (!node.options || typeof node.options.length !== 'number') return [];
171
+ return Array.prototype.map.call(node.options, function (o) { return String(o.value); });
172
+ }`;
173
+ /**
174
+ * Shared script body for `type` and `select` value mode. Returns an arrow IIFE
175
+ * that resolves (via a Promise — the bridge awaits it) to a JSON string and
176
+ * never throws into the bridge.
177
+ *
178
+ * Sequence: snapshot `previousValue` → [focus] → [clear + input] → settle →
179
+ * re-resolve the target (the app may have re-mounted it) → snapshot `baseline`
180
+ * → native write → `applied` → refuse values the browser discarded or clamped
181
+ * back → input, change → verify. `reverted` means the re-read equals
182
+ * `baseline` or `previousValue`; comparing only against the pre-command value
183
+ * would let an app that accepted the clear (or changed the value on focus) but
184
+ * rejected the real write pass as `transformed`. A field the app empties after
185
+ * a non-empty write is a failure too ("cleared"): the intended value did not
186
+ * land whether the app rejected or consumed it.
187
+ */
188
+ export function buildSetValueScript(selector, value, o) {
189
+ const escapedSelector = escapeSelector(selector);
190
+ const safeValue = JSON.stringify(value);
191
+ const tagExpr = o.lowerCaseTagName ? 'el.tagName.toLowerCase()' : 'el.tagName';
192
+ const focusBlock = o.focus
193
+ ? `
194
+ if (typeof el.focus === 'function') el.focus();`
195
+ : '';
196
+ const clearBlock = o.clear
197
+ ? `
198
+ if (typeof el.select === 'function') el.select();
199
+ writer.set('');
200
+ el.dispatchEvent(new Event('input', { bubbles: true }));`
201
+ : '';
202
+ return `(() => {${NATIVE_VALUE_WRITER_SNIPPET}${VERIFY_POLL_SNIPPET}${SETTLE_SNIPPET}${SELECT_OPTIONS_SNIPPET}
203
+ var selector = '${escapedSelector}';
204
+ var requested = ${safeValue};
205
+ var clearRan = ${o.clear ? 'true' : 'false'};
206
+ var fail = function (extra) { return JSON.stringify(Object.assign({ success: false, selector: selector }, extra)); };
207
+ function describe(node) {
208
+ var t = node.tagName.toLowerCase();
209
+ var it = t === 'input' ? String(node.type || 'text').toLowerCase() : '';
210
+ return '<' + t + (it ? ' type=' + it : '') + '>';
211
+ }
212
+ function unsupported(node) {
213
+ return { error: 'Unsupported element ' + describe(node) + ': no value setter', hint: 'Supported: <input>, <textarea>, <select>, and custom elements that expose a value property. For contenteditable regions use \`eval\`.' };
214
+ }
215
+ try {
216
+ var el = document.querySelector(selector);
217
+ if (!el) return fail({ error: ${o.notFoundErrorExpr} });
218
+ var tagName = ${tagExpr};
219
+ var inputType = el.tagName === 'INPUT' ? String(el.type || 'text').toLowerCase() : '';
220
+ if (inputType === 'checkbox' || inputType === 'radio') {
221
+ return fail({ tagName: tagName, error: 'Cannot set a text value on <input type=' + inputType + '>', hint: 'Use \`select <selector> --toggle\` to change its checked state.' });
222
+ }
223
+ if (inputType === 'file') {
224
+ return fail({ tagName: tagName, error: 'Cannot set the value of <input type=file>: browsers reject scripted file values' });
225
+ }
226
+ var writer = __resolveValueWriter(el);
227
+ if (!writer) return fail(Object.assign({ tagName: tagName }, unsupported(el)));
228
+ if (el.tagName === 'SELECT') {
229
+ var options = __selectOptionValues(el);
230
+ if (options.indexOf(requested) === -1) {
231
+ return fail({ tagName: tagName, requestedValue: requested, options: options.slice(0, 50), error: 'No <option> with value ' + JSON.stringify(requested), hint: 'Pass the option value attribute, not its label. Available values: ' + options.slice(0, 20).join(', ') });
232
+ }
233
+ }
234
+ var previousValue = String(el.value);${focusBlock}${clearBlock}
235
+ var base = { selector: selector, tagName: tagName, requestedValue: requested, previousValue: previousValue };
236
+ return __settle().then(function () {
237
+ var live = document.querySelector(selector);
238
+ if (!live) {
239
+ return fail(Object.assign({ error: 'Element left the document after focus/clear (removed or re-rendered without a matching selector); nothing was written', hint: 'The app re-rendered in response to focus or the clear. Re-query the DOM and retry, or target a stable selector.' }, base));
240
+ }
241
+ if (live !== el) {
242
+ el = live;
243
+ writer = __resolveValueWriter(el);
244
+ if (!writer) return fail(Object.assign({}, base, unsupported(el)));
245
+ }
246
+ var baseline = String(el.value);
247
+ writer.set(requested);
248
+ var applied = String(el.value);
249
+ if (writer.kind === 'native' && requested !== '' && applied === '') {
250
+ // Undo our own writes only: after --clear that is the pre-clear value;
251
+ // otherwise the value the field held right before the write (which an
252
+ // app may have changed on focus).
253
+ var restored = clearRan ? previousValue : baseline;
254
+ writer.set(restored);
255
+ if (clearRan) el.dispatchEvent(new Event('input', { bubbles: true }));
256
+ return fail(Object.assign({
257
+ value: restored,
258
+ error: 'Browser discarded the value: ' + describe(el) + ' sanitized ' + JSON.stringify(requested) + ' to ""',
259
+ hint: 'Use a value the control accepts (e.g. digits for type=number, YYYY-MM-DD for type=date). The previous value was restored' + (clearRan ? ' (the field had already been cleared, so an input event was dispatched for the restore).' : ' and no events were dispatched.')
260
+ }, base));
261
+ }
262
+ if (writer.kind === 'native' && requested !== baseline && applied === baseline) {
263
+ return fail(Object.assign({
264
+ value: baseline,
265
+ error: 'Browser did not take the value: ' + describe(el) + ' still reads ' + JSON.stringify(baseline) + ' after writing ' + JSON.stringify(requested),
266
+ hint: 'The control clamped or sanitized the value back onto its current value (e.g. min/max on type=range, the format of type=color). No events were dispatched.'
267
+ }, base));
268
+ }
269
+ // Built-in controls may legitimately normalize the value (newlines stripped, numbers canonicalized): verify against what the setter kept. Custom elements may reflect asynchronously: verify against the request.
270
+ var expected = writer.kind === 'native' ? applied : requested;
271
+ el.dispatchEvent(new Event('input', { bubbles: true }));
272
+ (document.querySelector(selector) || el).dispatchEvent(new Event('change', { bubbles: true }));
273
+ return __verify(function () {
274
+ var cur = document.querySelector(selector) || (el.isConnected ? el : null);
275
+ return cur ? String(cur.value) : null;
276
+ }, expected, ${o.verifyTimeoutMs}, ${VERIFY_INTERVAL_MS}).then(function (v) {
277
+ if (v.ok) {
278
+ return JSON.stringify(Object.assign({ success: true, value: v.observed, verified: true, verification: 'matched' }, base));
279
+ }
280
+ if (v.observed === null) {
281
+ return fail(Object.assign({ value: applied, verified: false, error: 'Element left the document after the write; the value could not be verified', hint: 'The app removed or re-rendered the element without a matching selector after the input/change events (navigation, a remount). Re-query the DOM to confirm the app state.' }, base));
282
+ }
283
+ var observed = v.observed === undefined ? '' : v.observed;
284
+ if (observed === baseline || observed === previousValue) {
285
+ return fail(Object.assign({
286
+ value: observed, verified: false, verification: 'reverted',
287
+ error: 'Value reverted: wrote ' + JSON.stringify(applied) + ' but the element reads ' + JSON.stringify(observed) + ' again after ${o.verifyTimeoutMs}ms',
288
+ hint: 'The app restored the previous value: a controlled input whose change handler did not accept the write (app-side validation), or one that normalized it to the value already present. Check the app state binding; if the app applies values asynchronously, raise --verify-timeout.'
289
+ }, base));
290
+ }
291
+ if (requested !== '' && observed === '') {
292
+ return fail(Object.assign({
293
+ value: observed, verified: false, verification: 'reverted',
294
+ error: 'Value cleared: wrote ' + JSON.stringify(applied) + ' but the element is empty after ${o.verifyTimeoutMs}ms',
295
+ hint: 'The app emptied the field after the write: it rejected the value (validation reset) or consumed it (e.g. a tag/chip input). Check the app state to tell which.'
296
+ }, base));
297
+ }
298
+ return JSON.stringify(Object.assign({ success: true, value: observed, verified: false, verification: 'transformed' }, base));
299
+ });
300
+ }).catch(function (e) {
301
+ return fail({ error: 'Script error: ' + (e && e.message ? e.message : String(e)) });
302
+ });
303
+ } catch (e) {
304
+ return fail({ error: 'Script error: ' + (e && e.message ? e.message : String(e)) });
305
+ }
306
+ })()`;
307
+ }
308
+ /**
309
+ * Parses an interaction result from the bridge. dev_bridge.rs turns a thrown
310
+ * script into the string "ERROR: <message>", which JSON.parse would reject
311
+ * with an opaque SyntaxError — surface it as an actionable error instead.
312
+ */
313
+ export function parseInteractResult(raw, schema, command) {
314
+ const text = String(raw ?? '');
315
+ if (text.startsWith('ERROR: ')) {
316
+ throw new Error(`${command} failed: the bridge script threw: ${text.slice('ERROR: '.length)}`);
317
+ }
318
+ let parsed;
319
+ try {
320
+ parsed = JSON.parse(text);
321
+ }
322
+ catch {
323
+ throw new Error(`${command} failed: bridge returned a non-JSON result: ${text.slice(0, 200)}`);
324
+ }
325
+ return schema.parse(parsed);
326
+ }
62
327
  //# sourceMappingURL=shared.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/commands/interact/shared.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAA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ptions } from './shared.js';
2
3
  /**
3
- * Build a JS IIFE script that types text into the element matched by selector.
4
+ * Build a JS IIFE that types text into the element matched by selector.
5
+ *
6
+ * Both the --clear write and the final write go through the element's native
7
+ * prototype value setter (see NATIVE_VALUE_WRITER_SNIPPET) so React-style
8
+ * instance trackers see the following input/change events as real changes
9
+ * (#10). The script then re-reads the value (synchronously, then polled up to
10
+ * verifyTimeoutMs) and reports `reverted` when the app restored the previous
11
+ * value. Returns a Promise-resolving IIFE; the bridge awaits it.
4
12
  */
5
- export declare function buildTypeScript(selector: string, text: string, clear: boolean): string;
13
+ export declare function buildTypeScript(selector: string, text: string, clear: boolean, options?: VerifyOptions): string;
6
14
  export declare function registerType(program: Command): void;
@@ -1,31 +1,25 @@
1
1
  import { Command } from 'commander';
2
2
  import { resolveBridge } from '../shared.js';
3
- import { addInteractOptions, escapeSelector } from './shared.js';
3
+ import { addInteractOptions, addVerifyOptions, buildSetValueScript, parseInteractResult, resolveVerifyTimeout, } from './shared.js';
4
4
  import { TypeResultSchema } from '../../schemas/interact.js';
5
5
  /**
6
- * Build a JS IIFE script that types text into the element matched by selector.
6
+ * Build a JS IIFE that types text into the element matched by selector.
7
+ *
8
+ * Both the --clear write and the final write go through the element's native
9
+ * prototype value setter (see NATIVE_VALUE_WRITER_SNIPPET) so React-style
10
+ * instance trackers see the following input/change events as real changes
11
+ * (#10). The script then re-reads the value (synchronously, then polled up to
12
+ * verifyTimeoutMs) and reports `reverted` when the app restored the previous
13
+ * value. Returns a Promise-resolving IIFE; the bridge awaits it.
7
14
  */
8
- export function buildTypeScript(selector, text, clear) {
9
- const escapedSelector = escapeSelector(selector);
10
- const safeText = JSON.stringify(text);
11
- const clearBlock = clear
12
- ? `
13
- el.focus();
14
- el.select();
15
- el.value = '';
16
- el.dispatchEvent(new Event('input', { bubbles: true }));`
17
- : '';
18
- return `(() => {
19
- var el = document.querySelector('${escapedSelector}');
20
- if (!el) {
21
- return JSON.stringify({ success: false, selector: '${escapedSelector}', error: 'Element not found' });
22
- }
23
- el.focus();${clearBlock}
24
- el.value = ${safeText};
25
- el.dispatchEvent(new Event('input', { bubbles: true }));
26
- el.dispatchEvent(new Event('change', { bubbles: true }));
27
- return JSON.stringify({ success: true, selector: '${escapedSelector}', tagName: el.tagName, value: el.value });
28
- })()`;
15
+ export function buildTypeScript(selector, text, clear, options) {
16
+ return buildSetValueScript(selector, text, {
17
+ focus: true,
18
+ clear,
19
+ lowerCaseTagName: false,
20
+ notFoundErrorExpr: `'Element not found'`,
21
+ verifyTimeoutMs: resolveVerifyTimeout(options),
22
+ });
29
23
  }
30
24
  export function registerType(program) {
31
25
  const cmd = new Command('type')
@@ -37,22 +31,43 @@ export function registerType(program) {
37
31
  Examples:
38
32
  $ tauri-agent-tools type "#username" "admin"
39
33
  $ tauri-agent-tools type "input[name=email]" "user@example.com" --clear
40
- $ tauri-agent-tools type ".search-input" "hello world" --json`);
34
+ $ tauri-agent-tools type ".search-input" "hello world" --json
35
+ $ tauri-agent-tools type "#q" "term" --verify-timeout 2000 # app applies the value asynchronously
36
+
37
+ The value is written through the element's native prototype setter followed by
38
+ bubbling input + change events, so React/Vue/Svelte controlled inputs see it.
39
+ The element is then re-read; the command fails with "Value reverted" when the
40
+ app restored the previous value (a controlled input that rejected the write).`);
41
41
  addInteractOptions(cmd);
42
+ addVerifyOptions(cmd);
42
43
  cmd.action(async (selector, text, opts) => {
44
+ // Build first: an invalid --verify-timeout fails before any bridge call.
45
+ const script = buildTypeScript(selector, text, !!opts.clear, { verifyTimeoutMs: opts.verifyTimeout });
43
46
  const bridge = await resolveBridge(opts);
44
- const script = buildTypeScript(selector, text, !!opts.clear);
45
47
  const raw = await bridge.eval(script);
46
- const result = TypeResultSchema.parse(JSON.parse(String(raw)));
48
+ const result = parseInteractResult(raw, TypeResultSchema, 'Type');
47
49
  if (!result.success) {
48
- throw new Error(`Type failed: ${result.error} (selector: ${result.selector})`);
50
+ // With --json the failure object (verification, hint, options, …) goes to
51
+ // stdout so scripts can branch on it; the thrown error still reaches
52
+ // stderr and sets exit code 1.
53
+ if (opts.json)
54
+ console.log(JSON.stringify(result, null, 2));
55
+ const hint = result.hint ? `\n hint: ${result.hint}` : '';
56
+ throw new Error(`Type failed: ${result.error} (selector: ${result.selector})${hint}`);
49
57
  }
50
58
  if (opts.json) {
51
59
  console.log(JSON.stringify(result, null, 2));
60
+ return;
61
+ }
62
+ const tag = (result.tagName ?? 'element').toLowerCase();
63
+ let note = '';
64
+ if (result.verification === 'transformed') {
65
+ note = ` (app transformed the requested value ${JSON.stringify(result.requestedValue)})`;
52
66
  }
53
- else {
54
- console.log(`Typed into ${(result.tagName ?? 'element').toLowerCase()}: "${result.value}"`);
67
+ else if (result.requestedValue !== undefined && result.value !== result.requestedValue) {
68
+ note = ` (browser normalized the requested value ${JSON.stringify(result.requestedValue)})`;
55
69
  }
70
+ console.log(`Typed into ${tag}: "${result.value}"${note}`);
56
71
  });
57
72
  program.addCommand(cmd);
58
73
  }
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/commands/interact/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,QAAgB,EAAE,IAAY,EAAE,KAAc;IAC5E,MAAM,eAAe,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAEtC,MAAM,UAAU,GAAG,KAAK;QACtB,CAAC,CAAC;;;;6DAIuD;QACzD,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;qCAC4B,eAAe;;yDAEK,eAAe;;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AE,CAAC;QACd,IAAI,MAAM,CAAC,YAAY,KAAK,aAAa,EAAE,CAAC;YAC1C,IAAI,GAAG,yCAAyC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC;QAC3F,CAAC;aAAM,IAAI,MAAM,CAAC,cAAc,KAAK,SAAS,IAAI,MAAM,CAAC,KAAK,KAAK,MAAM,CAAC,cAAc,EAAE,CAAC;YACzF,IAAI,GAAG,4CAA4C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC;QAC9F,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,cAAc,GAAG,MAAM,MAAM,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC,CACF,CAAC;IAEF,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { writeFile } from 'node:fs/promises';
2
2
  import { Command } from 'commander';
3
3
  import { ImageFormatSchema } from '../schemas/commands.js';
4
- import { addBridgeOptions, resolveBridge, parseIntArg } from './shared.js';
4
+ import { addBridgeOptions, resolveBridge, resolveWindowId, parseIntArg } from './shared.js';
5
5
  import { computeCropRect, cropImage, resizeImage } from '../util/image.js';
6
6
  function autoOutputPath(format) {
7
7
  const ts = new Date().toISOString().replace(/[:.]/g, '-');
@@ -11,7 +11,8 @@ export function registerScreenshot(program, getAdapter) {
11
11
  const cmd = new Command('screenshot')
12
12
  .description('Capture a screenshot of a window or DOM element')
13
13
  .option('-s, --selector <css>', 'CSS selector — screenshot just this element (requires bridge)')
14
- .option('-t, --title <regex>', 'Window title to match (default: auto-discover from bridge)')
14
+ .option('-t, --title <regex>', 'Window title to match — regex; quote titles with spaces (default: auto-discover from bridge)')
15
+ .option('-w, --window-id <id>', 'Platform window id (from list-windows) — overrides --title')
15
16
  .option('-o, --output <path>', 'Output file path (default: auto-named)')
16
17
  .option('--format <fmt>', 'Output format: png or jpg', 'png')
17
18
  .option('--max-width <number>', 'Resize to max width', parseIntArg)
@@ -19,6 +20,7 @@ export function registerScreenshot(program, getAdapter) {
19
20
  .addHelpText('after', `
20
21
  Examples:
21
22
  $ tauri-agent-tools screenshot --title "My App"
23
+ $ tauri-agent-tools screenshot --window-id 12345 -o win.png # id from list-windows, no bridge needed
22
24
  $ tauri-agent-tools screenshot --selector ".sidebar" --output sidebar.png
23
25
  $ tauri-agent-tools screenshot --selector "#login" --format jpg --json`);
24
26
  addBridgeOptions(cmd);
@@ -30,6 +32,7 @@ Examples:
30
32
  const format = formatResult.data;
31
33
  const adapter = await getAdapter();
32
34
  let buffer;
35
+ let windowId;
33
36
  if (opts.selector) {
34
37
  // DOM-targeted pixel capture — the core feature
35
38
  const bridge = await resolveBridge(opts);
@@ -38,18 +41,7 @@ Examples:
38
41
  throw new Error(`Element not found: ${opts.selector}`);
39
42
  }
40
43
  const viewport = await bridge.getViewportSize();
41
- // Find window
42
- let windowId;
43
- if (opts.title) {
44
- windowId = await adapter.findWindow(opts.title);
45
- }
46
- else {
47
- const title = await bridge.getDocumentTitle();
48
- if (!title) {
49
- throw new Error('Could not get window title from bridge. Use --title to specify.');
50
- }
51
- windowId = await adapter.findWindow(title);
52
- }
44
+ windowId = await resolveWindowId(adapter, bridge, opts);
53
45
  const windowGeom = await adapter.getWindowGeometry(windowId);
54
46
  // Capture full window
55
47
  buffer = await adapter.captureWindow(windowId, format);
@@ -62,10 +54,15 @@ Examples:
62
54
  }
63
55
  else {
64
56
  // Full window fallback — no bridge needed
65
- if (!opts.title) {
66
- throw new Error('Either --selector (with bridge) or --title is required');
57
+ if (opts.windowId) {
58
+ windowId = opts.windowId;
59
+ }
60
+ else if (opts.title) {
61
+ windowId = await adapter.findWindow(opts.title);
62
+ }
63
+ else {
64
+ throw new Error('Either --selector (with bridge), --title, or --window-id is required');
67
65
  }
68
- const windowId = await adapter.findWindow(opts.title);
69
66
  buffer = await adapter.captureWindow(windowId, format);
70
67
  }
71
68
  if (opts.maxWidth) {
@@ -80,6 +77,7 @@ Examples:
80
77
  size: buffer.length,
81
78
  selector: opts.selector ?? null,
82
79
  windowTitle: opts.title ?? null,
80
+ windowId,
83
81
  }, null, 2));
84
82
  }
85
83
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../src/commands/screenshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE3E,SAAS,cAAc,CAAC,MAAmB;IACzC,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC1D,OAAO,cAAc,EAAE,IAAI,MAAM,EAAE,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,OAAgB,EAChB,UAA4D;IAE5D,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,YAAY,CAAC;SAClC,WAAW,CAAC,iDAAiD,CAAC;SAC9D,MAAM,CAAC,sBAAsB,EAAE,+DAA+D,CAAC;SAC/F,MAAM,CAAC,qBAAqB,EAAE,4DAA4D,CAAC;SAC3F,MAAM,CAAC,qBAAqB,EAAE,wCAAwC,CAAC;SACvE,MAAM,CAAC,gBAAgB,EAAE,2BAA2B,EAAE,KAAK,CAAC;SAC5D,MAAM,CAAC,sBAAsB,EAAE,qBAAqB,EAAE,WAAW,CAAC;SAClE,MAAM,CAAC,QAAQ,EAAE,iCAAiC,CAAC;SACnD,WAAW,CAAC,OAAO,EAAE;;;;yEA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AAI,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;gBACzB,IAAI,EAAE,MAAM;gBACZ,MAAM;gBACN,IAAI,EAAE,MAAM,CAAC,MAAM;gBACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,IAAI;gBAC/B,WAAW,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI;gBAC/B,QAAQ;aACT,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACf,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACtB,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import type { Command } from 'commander';
2
2
  import type { z } from 'zod';
3
3
  import type { BridgeConfig } from '../schemas/bridge.js';
4
+ import type { PlatformAdapter } from '../types.js';
4
5
  import { BridgeClient } from '../bridge/client.js';
5
6
  /**
6
7
  * Options parsed from the bridge-related CLI flags.
@@ -17,6 +18,22 @@ export interface BridgeOpts {
17
18
  */
18
19
  strict?: boolean;
19
20
  }
21
+ /**
22
+ * Options parsed from the window-targeting CLI flags.
23
+ */
24
+ export interface WindowTargetOpts {
25
+ windowId?: string;
26
+ title?: string;
27
+ }
28
+ /**
29
+ * Resolve the platform window id for a window-consuming command.
30
+ * Precedence: --window-id (used verbatim) > --title regex > bridge document.title.
31
+ *
32
+ * The id is not validated here: its format is adapter-specific (X11/macOS/Sway
33
+ * numeric, Hyprland hex 0x…), and the adapters that interpolate ids into shell
34
+ * commands already guard with validateWindowId().
35
+ */
36
+ export declare function resolveWindowId(adapter: PlatformAdapter, bridge: BridgeClient, opts: WindowTargetOpts): Promise<string>;
20
37
  /**
21
38
  * Parse a value with a Zod enum schema, throwing a human-readable error on failure.
22
39
  * Replaces raw `.parse()` calls that would surface cryptic ZodError messages.
@@ -1,5 +1,24 @@
1
1
  import { BridgeClient } from '../bridge/client.js';
2
2
  import { discoverBridge, discoverBridgesByPid } from '../bridge/tokenDiscovery.js';
3
+ /**
4
+ * Resolve the platform window id for a window-consuming command.
5
+ * Precedence: --window-id (used verbatim) > --title regex > bridge document.title.
6
+ *
7
+ * The id is not validated here: its format is adapter-specific (X11/macOS/Sway
8
+ * numeric, Hyprland hex 0x…), and the adapters that interpolate ids into shell
9
+ * commands already guard with validateWindowId().
10
+ */
11
+ export async function resolveWindowId(adapter, bridge, opts) {
12
+ if (opts.windowId)
13
+ return opts.windowId;
14
+ if (opts.title)
15
+ return adapter.findWindow(opts.title);
16
+ const docTitle = await bridge.getDocumentTitle();
17
+ if (!docTitle) {
18
+ throw new Error('Could not get window title from bridge. Use --title or --window-id.');
19
+ }
20
+ return adapter.findWindow(docTitle);
21
+ }
3
22
  /**
4
23
  * Parse a value with a Zod enum schema, throwing a human-readable error on failure.
5
24
  * Replaces raw `.parse()` calls that would surface cryptic ZodError messages.
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/commands/shared.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAkBnF;;;GAGG;AACH,MAAM,UAAU,SAAS,CACvB,MAAoB,EACpB,KAAa,EACb,KAAa;IAEb,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,WAAW,KAAK,KAAK,KAAK,qBAAqB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9F,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC;AACrB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,K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AE,CAAC;QAC1C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,4BAA4B;gBAC1B,mDAAmD;gBACnD,0CAA0C,CAC7C,CAAC;QACJ,CAAC;QACD,MAAM,GAAG;YACP,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI;YAClC,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK;SACtC,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;AACpD,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { writeFile } from 'node:fs/promises';
2
2
  import { Command } from 'commander';
3
- import { addBridgeOptions, resolveBridge, parseIntArg } from './shared.js';
3
+ import { addBridgeOptions, resolveBridge, resolveWindowId, parseIntArg } from './shared.js';
4
4
  import { buildSerializerScript } from './dom.js';
5
5
  import { computeCropRect, cropImage } from '../util/image.js';
6
6
  import { DomNodeSchema } from '../schemas/dom.js';
@@ -20,20 +20,13 @@ const STORAGE_SCRIPT = `(() => {
20
20
  var session = Object.keys(sessionStorage).map(function(k) { return { key: k, value: sessionStorage.getItem(k) }; });
21
21
  return JSON.stringify({ localStorage: local, sessionStorage: session });
22
22
  })()`;
23
- async function resolveWindowId(adapter, bridge, title) {
24
- if (title)
25
- return adapter.findWindow(title);
26
- const docTitle = await bridge.getDocumentTitle();
27
- if (!docTitle)
28
- throw new Error('Could not get window title. Use --title.');
29
- return adapter.findWindow(docTitle);
30
- }
31
23
  export function registerSnapshot(program, getAdapter) {
32
24
  const cmd = new Command('snapshot')
33
25
  .description('Capture screenshot + DOM + page state + storage in one shot')
34
26
  .requiredOption('-o, --output <prefix>', 'Output path prefix (e.g. /tmp/debug)')
35
27
  .option('-s, --selector <css>', 'CSS selector to screenshot (full window if omitted)')
36
- .option('-t, --title <regex>', 'Window title to match (default: auto-discover)')
28
+ .option('-t, --title <regex>', 'Window title to match — regex; quote titles with spaces (default: auto-discover)')
29
+ .option('-w, --window-id <id>', 'Platform window id (from list-windows) — overrides --title')
37
30
  .option('--dom-depth <number>', 'DOM tree depth', parseIntArg, 3)
38
31
  .option('--eval <js>', 'Additional JS to eval and save')
39
32
  .option('--json', 'Output structured manifest');
@@ -46,7 +39,7 @@ export function registerSnapshot(program, getAdapter) {
46
39
  const files = {};
47
40
  // 1. Screenshot
48
41
  try {
49
- const windowId = await resolveWindowId(adapter, bridge, opts.title);
42
+ const windowId = await resolveWindowId(adapter, bridge, opts);
50
43
  let buffer;
51
44
  if (opts.selector) {
52
45
  const elementRect = await bridge.getElementRect(opts.selector);