@developerz.ai/ui-debugger-mcp 1.10.0 → 1.11.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 (178) hide show
  1. package/README.md +9 -5
  2. package/dist/adapters/android/abortable.d.ts +6 -0
  3. package/dist/adapters/android/abortable.js +22 -0
  4. package/dist/adapters/android/abortable.js.map +1 -0
  5. package/dist/adapters/android/android-adapter.d.ts +7 -39
  6. package/dist/adapters/android/android-adapter.js +54 -436
  7. package/dist/adapters/android/android-adapter.js.map +1 -1
  8. package/dist/adapters/android/commands.d.ts +10 -0
  9. package/dist/adapters/android/commands.js +22 -0
  10. package/dist/adapters/android/commands.js.map +1 -1
  11. package/dist/adapters/android/emulator.d.ts +41 -0
  12. package/dist/adapters/android/emulator.js +115 -0
  13. package/dist/adapters/android/emulator.js.map +1 -0
  14. package/dist/adapters/android/logcat.d.ts +87 -0
  15. package/dist/adapters/android/logcat.js +352 -0
  16. package/dist/adapters/android/logcat.js.map +1 -0
  17. package/dist/adapters/browser/browser-adapter.js +30 -42
  18. package/dist/adapters/browser/browser-adapter.js.map +1 -1
  19. package/dist/adapters/browser/cdp.d.ts +7 -10
  20. package/dist/adapters/browser/cdp.js +93 -69
  21. package/dist/adapters/browser/cdp.js.map +1 -1
  22. package/dist/adapters/browser/exchange-read.d.ts +39 -0
  23. package/dist/adapters/browser/exchange-read.js +102 -0
  24. package/dist/adapters/browser/exchange-read.js.map +1 -0
  25. package/dist/adapters/browser/extractor.js +9 -2
  26. package/dist/adapters/browser/extractor.js.map +1 -1
  27. package/dist/adapters/browser/lifecycle.d.ts +33 -0
  28. package/dist/adapters/browser/lifecycle.js +47 -4
  29. package/dist/adapters/browser/lifecycle.js.map +1 -1
  30. package/dist/adapters/browser/locate.d.ts +18 -2
  31. package/dist/adapters/browser/locate.js +48 -3
  32. package/dist/adapters/browser/locate.js.map +1 -1
  33. package/dist/adapters/browser/log-filters.d.ts +1 -1
  34. package/dist/adapters/browser/log-filters.js +15 -4
  35. package/dist/adapters/browser/log-filters.js.map +1 -1
  36. package/dist/adapters/browser/log-format.d.ts +12 -0
  37. package/dist/adapters/browser/log-format.js +123 -7
  38. package/dist/adapters/browser/log-format.js.map +1 -1
  39. package/dist/adapters/contract.d.ts +22 -5
  40. package/dist/adapters/desktop/atspi-busctl.js +3 -1
  41. package/dist/adapters/desktop/atspi-busctl.js.map +1 -1
  42. package/dist/adapters/desktop/atspi.d.ts +6 -0
  43. package/dist/adapters/desktop/atspi.js.map +1 -1
  44. package/dist/adapters/desktop/desktop-adapter.d.ts +2 -0
  45. package/dist/adapters/desktop/desktop-adapter.js +132 -98
  46. package/dist/adapters/desktop/desktop-adapter.js.map +1 -1
  47. package/dist/adapters/desktop/input.d.ts +1 -1
  48. package/dist/adapters/desktop/input.js +14 -3
  49. package/dist/adapters/desktop/input.js.map +1 -1
  50. package/dist/adapters/desktop/managed-app.d.ts +43 -0
  51. package/dist/adapters/desktop/managed-app.js +114 -0
  52. package/dist/adapters/desktop/managed-app.js.map +1 -0
  53. package/dist/adapters/desktop/proc.d.ts +2 -0
  54. package/dist/adapters/desktop/proc.js +4 -0
  55. package/dist/adapters/desktop/proc.js.map +1 -1
  56. package/dist/adapters/desktop/wait-poll.d.ts +17 -0
  57. package/dist/adapters/desktop/wait-poll.js +38 -0
  58. package/dist/adapters/desktop/wait-poll.js.map +1 -0
  59. package/dist/adapters/factory.d.ts +1 -1
  60. package/dist/adapters/factory.js +1 -1
  61. package/dist/adapters/log-format.d.ts +6 -0
  62. package/dist/adapters/log-format.js +10 -2
  63. package/dist/adapters/log-format.js.map +1 -1
  64. package/dist/agent/belt/act.d.ts +6 -3
  65. package/dist/agent/belt/act.js +40 -60
  66. package/dist/agent/belt/act.js.map +1 -1
  67. package/dist/agent/belt/look.d.ts +9 -3
  68. package/dist/agent/belt/look.js +21 -5
  69. package/dist/agent/belt/look.js.map +1 -1
  70. package/dist/agent/belt/observe.d.ts +9 -43
  71. package/dist/agent/belt/observe.js +66 -242
  72. package/dist/agent/belt/observe.js.map +1 -1
  73. package/dist/agent/belt/redact-output.d.ts +20 -0
  74. package/dist/agent/belt/redact-output.js +70 -0
  75. package/dist/agent/belt/redact-output.js.map +1 -0
  76. package/dist/agent/belt/same-origin.d.ts +21 -0
  77. package/dist/agent/belt/same-origin.js +38 -0
  78. package/dist/agent/belt/same-origin.js.map +1 -0
  79. package/dist/agent/belt/target-refs.d.ts +39 -0
  80. package/dist/agent/belt/target-refs.js +60 -0
  81. package/dist/agent/belt/target-refs.js.map +1 -0
  82. package/dist/agent/belt/tree-targets.d.ts +79 -0
  83. package/dist/agent/belt/tree-targets.js +242 -0
  84. package/dist/agent/belt/tree-targets.js.map +1 -0
  85. package/dist/agent/loop-frames.d.ts +26 -0
  86. package/dist/agent/loop-frames.js +106 -0
  87. package/dist/agent/loop-frames.js.map +1 -0
  88. package/dist/agent/loop.d.ts +13 -24
  89. package/dist/agent/loop.js +40 -104
  90. package/dist/agent/loop.js.map +1 -1
  91. package/dist/agent/prompts/debug-agent.js +3 -2
  92. package/dist/agent/prompts/debug-agent.js.map +1 -1
  93. package/dist/agent/prompts/web-addendum.d.ts +2 -2
  94. package/dist/agent/prompts/web-addendum.js +21 -32
  95. package/dist/agent/prompts/web-addendum.js.map +1 -1
  96. package/dist/agent/provider.d.ts +3 -1
  97. package/dist/agent/provider.js +4 -2
  98. package/dist/agent/provider.js.map +1 -1
  99. package/dist/boot.js +3 -1
  100. package/dist/boot.js.map +1 -1
  101. package/dist/cli/chromium-libs.d.ts +6 -1
  102. package/dist/cli/chromium-libs.js +27 -3
  103. package/dist/cli/chromium-libs.js.map +1 -1
  104. package/dist/cli/control.js +30 -5
  105. package/dist/cli/control.js.map +1 -1
  106. package/dist/config/load.js +10 -0
  107. package/dist/config/load.js.map +1 -1
  108. package/dist/config/schema.js +12 -10
  109. package/dist/config/schema.js.map +1 -1
  110. package/dist/errors.d.ts +17 -16
  111. package/dist/errors.js +33 -32
  112. package/dist/errors.js.map +1 -1
  113. package/dist/index.d.ts +1 -1
  114. package/dist/index.js +1 -1
  115. package/dist/mcp/server.js +10 -1
  116. package/dist/mcp/server.js.map +1 -1
  117. package/dist/mcp/tools/end-session.js +2 -1
  118. package/dist/mcp/tools/end-session.js.map +1 -1
  119. package/dist/mcp/tools/output.d.ts +7 -0
  120. package/dist/mcp/tools/output.js +5 -0
  121. package/dist/mcp/tools/output.js.map +1 -1
  122. package/dist/mcp/tools/result.js +4 -1
  123. package/dist/mcp/tools/result.js.map +1 -1
  124. package/dist/redact.d.ts +20 -4
  125. package/dist/redact.js +134 -19
  126. package/dist/redact.js.map +1 -1
  127. package/dist/services/auth-persona.d.ts +19 -0
  128. package/dist/services/auth-persona.js +32 -0
  129. package/dist/services/auth-persona.js.map +1 -0
  130. package/dist/services/debug-api.d.ts +7 -0
  131. package/dist/services/debug-service.d.ts +1 -1
  132. package/dist/services/debug-service.js +64 -65
  133. package/dist/services/debug-service.js.map +1 -1
  134. package/dist/services/foreign-findings.d.ts +22 -0
  135. package/dist/services/foreign-findings.js +38 -0
  136. package/dist/services/foreign-findings.js.map +1 -0
  137. package/dist/services/login-failure.d.ts +10 -0
  138. package/dist/services/login-failure.js +24 -0
  139. package/dist/services/login-failure.js.map +1 -0
  140. package/dist/services/login-selectors.d.ts +18 -0
  141. package/dist/services/login-selectors.js +44 -0
  142. package/dist/services/login-selectors.js.map +1 -0
  143. package/dist/services/login-session.d.ts +25 -0
  144. package/dist/services/login-session.js +59 -0
  145. package/dist/services/login-session.js.map +1 -0
  146. package/dist/services/login.d.ts +9 -27
  147. package/dist/services/login.js +78 -80
  148. package/dist/services/login.js.map +1 -1
  149. package/dist/services/replay.js +15 -3
  150. package/dist/services/replay.js.map +1 -1
  151. package/dist/services/session-builder.js +19 -4
  152. package/dist/services/session-builder.js.map +1 -1
  153. package/dist/services/shutdown.d.ts +8 -4
  154. package/dist/services/shutdown.js +21 -8
  155. package/dist/services/shutdown.js.map +1 -1
  156. package/dist/services/start-guards.d.ts +6 -1
  157. package/dist/services/start-guards.js +13 -2
  158. package/dist/services/start-guards.js.map +1 -1
  159. package/dist/session/cleanup.d.ts +3 -2
  160. package/dist/session/cleanup.js +6 -2
  161. package/dist/session/cleanup.js.map +1 -1
  162. package/dist/session/finalize.d.ts +45 -0
  163. package/dist/session/finalize.js +150 -0
  164. package/dist/session/finalize.js.map +1 -0
  165. package/dist/session/flock-backend.d.ts +117 -0
  166. package/dist/session/flock-backend.js +293 -0
  167. package/dist/session/flock-backend.js.map +1 -0
  168. package/dist/session/owner-lock.d.ts +4 -95
  169. package/dist/session/owner-lock.js +7 -288
  170. package/dist/session/owner-lock.js.map +1 -1
  171. package/dist/session/session.js +11 -134
  172. package/dist/session/session.js.map +1 -1
  173. package/dist/session/state-file.js +9 -1
  174. package/dist/session/state-file.js.map +1 -1
  175. package/dist/session/workspace.d.ts +32 -2
  176. package/dist/session/workspace.js +65 -4
  177. package/dist/session/workspace.js.map +1 -1
  178. package/package.json +8 -8
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Output redaction for belt tools whose results are free text end to end.
3
+ *
4
+ * `observe` redacts field by field (it must keep node `name`s intact for the
5
+ * selectors built on them). `act` and the vision `look` have no such constraint:
6
+ * everything they return — a step label, tab urls/titles, reloaded urls, the
7
+ * vision guy's description of a screen that may SHOW a credential — is prose the
8
+ * driver reads and the SDK re-sends every step. {@link withRedactedOutput} masks
9
+ * the run's secrets in all of it, and in the message of anything the tool throws
10
+ * (the SDK feeds a tool error back to the model verbatim).
11
+ *
12
+ * NOT for self-look: its result carries the frame as base64, where a short
13
+ * secret can match by chance and corrupt the image.
14
+ */
15
+ import { AgentError } from '../../errors.js';
16
+ /** Deep copy of plain JSON-shaped data with every string run through `redact`. */
17
+ export function redactStrings(value, redact) {
18
+ if (typeof value === 'string')
19
+ return redact(value);
20
+ if (Array.isArray(value))
21
+ return value.map((item) => redactStrings(item, redact));
22
+ if (typeof value !== 'object' || value === null)
23
+ return value;
24
+ // Only plain objects: bytes, dates and class instances pass through untouched.
25
+ if (Object.getPrototypeOf(value) !== Object.prototype)
26
+ return value;
27
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactStrings(item, redact)]));
28
+ }
29
+ /**
30
+ * `error` with its message (and stack, which repeats it) redacted — SAME class and
31
+ * `name`, because callers key off both: the vision latch (`VisionUnavailableError`),
32
+ * an abort (`AbortError`). A fresh object rather than a wrapper: the original must
33
+ * never ride along as `cause`, since it carries the secret. Other own fields
34
+ * (a provider error's response body) are deliberately not copied for the same reason.
35
+ */
36
+ function redactedError(error, redact) {
37
+ const copy = Object.create(Object.getPrototypeOf(error));
38
+ const field = (value) => ({ value, writable: true, configurable: true });
39
+ // Own properties: `name` is a prototype getter on DOMException and needs a real instance.
40
+ Object.defineProperties(copy, {
41
+ name: field(error.name),
42
+ message: field(redact(error.message)),
43
+ stack: field(redact(error.stack ?? '')),
44
+ });
45
+ return copy;
46
+ }
47
+ /** Wrap a belt tool so its result and its thrown error message carry no run secret. */
48
+ export function withRedactedOutput(tool, redact) {
49
+ const original = tool.execute;
50
+ if (!original)
51
+ return tool;
52
+ return {
53
+ ...tool,
54
+ execute: async (input, options) => {
55
+ try {
56
+ return redactStrings(await original(input, options), redact);
57
+ }
58
+ catch (error) {
59
+ const message = error instanceof Error ? error.message : String(error);
60
+ // Untouched errors pass through as the same object.
61
+ if (redact(message) === message)
62
+ throw error;
63
+ throw error instanceof Error
64
+ ? redactedError(error, redact)
65
+ : new AgentError(redact(message));
66
+ }
67
+ },
68
+ };
69
+ }
70
+ //# sourceMappingURL=redact-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redact-output.js","sourceRoot":"","sources":["../../../src/agent/belt/redact-output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,kFAAkF;AAClF,MAAM,UAAU,aAAa,CAAC,KAAc,EAAE,MAAgB;IAC5D,IA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C;KACxC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,kBAAkB,CAAiB,IAAO,EAAE,MAAgB;IAC1E,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC;IAC9B,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,OAAO;QACL,GAAG,IAAI;QACP,OAAO,EAAE,KAAK,EAAE,KAAc,EAAE,OAAuC,EAAE,EAAE;YACzE,IAAI,CAAC;gBACH,OAAO,aAAa,CAAC,MAAM,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;YAC/D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACvE,oDAAoD;gBACpD,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,OAAO;oBAAE,MAAM,KAAK,CAAC;gBAC7C,MAAM,KAAK,YAAY,KAAK;oBAC1B,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC;oBAC9B,CAAC,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;KACG,CAAC;AACT,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The navigation guard `act` applies to `navigate` — the run stays on the app
3
+ * under test. Split from `act.ts` (one responsibility per file).
4
+ */
5
+ /**
6
+ * Refuse a `navigate` that leaves the app under test.
7
+ *
8
+ * Observed end-to-end: driven at the local fixture with the goal "debug the Nimbus
9
+ * Store home page", the driver's FIRST action was
10
+ * `navigate → https://nimbus-store.vercel.app` — a public site it inferred from the
11
+ * goal text. It never returned, and the run ended with six confident, fully-evidenced
12
+ * bugs about a stranger's production app, with nothing in the output hinting the
13
+ * target had been left. The smart agent would have gone hunting for a CORS bug that
14
+ * does not exist in its repo.
15
+ *
16
+ * `origin` is the run's own origin (web only; empty for desktop/android, whose
17
+ * `navigate` means a window title or an app package). Same-origin URLs and relative
18
+ * paths pass; anything else fails loud, naming where the driver is supposed to be.
19
+ * A run that wanders off the app under test is worse than a run that stops.
20
+ */
21
+ export declare function assertSameOrigin(target: string, origin: string | undefined): void;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * The navigation guard `act` applies to `navigate` — the run stays on the app
3
+ * under test. Split from `act.ts` (one responsibility per file).
4
+ */
5
+ import { AgentError } from '../../errors.js';
6
+ /**
7
+ * Refuse a `navigate` that leaves the app under test.
8
+ *
9
+ * Observed end-to-end: driven at the local fixture with the goal "debug the Nimbus
10
+ * Store home page", the driver's FIRST action was
11
+ * `navigate → https://nimbus-store.vercel.app` — a public site it inferred from the
12
+ * goal text. It never returned, and the run ended with six confident, fully-evidenced
13
+ * bugs about a stranger's production app, with nothing in the output hinting the
14
+ * target had been left. The smart agent would have gone hunting for a CORS bug that
15
+ * does not exist in its repo.
16
+ *
17
+ * `origin` is the run's own origin (web only; empty for desktop/android, whose
18
+ * `navigate` means a window title or an app package). Same-origin URLs and relative
19
+ * paths pass; anything else fails loud, naming where the driver is supposed to be.
20
+ * A run that wanders off the app under test is worse than a run that stops.
21
+ */
22
+ export function assertSameOrigin(target, origin) {
23
+ if (!origin)
24
+ return; // non-web target, or no origin to enforce
25
+ let destination;
26
+ try {
27
+ destination = new URL(target, origin); // relative paths resolve against the app
28
+ }
29
+ catch {
30
+ return; // not URL-shaped — let the adapter reject it with its own message
31
+ }
32
+ if (destination.origin === origin)
33
+ return;
34
+ throw new AgentError(`act 'navigate' refused: '${target}' leaves the app under test (${origin}). ` +
35
+ 'Findings about another site cannot be acted on. Use a path or a URL on ' +
36
+ `${origin}; if the app genuinely lives elsewhere, the smart agent must pass that url to start_debug.`);
37
+ }
38
+ //# sourceMappingURL=same-origin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"same-origin.js","sourceRoot":"","sources":["../../../src/agent/belt/same-origin.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc,EAAE,MAA0B;IACzE,IAAI,CAAC,MAAM;QAAE,OAAO,CAAC,0CAA0C;IAC/D,IAAI,WAAgB,CAAC;IACrB,IAAI,CAAC;QACH,WAAW,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,yCAAyC;IAClF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,kEAAkE;IAC5E,CAAC;IACD,IAAI,WAAW,CAAC,MAAM,KAAK,MAAM;QAAE,OAAO;IAC1C,MAAM,IAAI,UAAU,CAClB,4BAA4B,MAAM,gCAAgC,MAAM,KAAK;QAC3E,yEAAyE;QACzE,GAAG,MAAM,4FAA4F,CACxG,CAAC;AACJ,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Opaque target references — how a node stays addressable when its selector
3
+ * would carry one of the run's secrets.
4
+ *
5
+ * `observe` builds each node's `target` from its accessible name. A page that
6
+ * echoes a persona value in visible text ("Signed in as …") therefore puts the
7
+ * secret into a selector the driver reads and the SDK re-sends every step.
8
+ * Masking the selector would break it; omitting it leaves the node unreachable
9
+ * (its name is masked too). So the belt hands out a reference instead and keeps
10
+ * the real selector here, keyed by the run's adapter — `observe` issues, `act`
11
+ * (and `observe`'s own `query`/`within`) resolve. One adapter per run, so a
12
+ * reference can never resolve against another run's page.
13
+ *
14
+ * ## The spelling: `@@ref:N`
15
+ *
16
+ * It must not collide with a selector a driver could mean. Both dialects accept
17
+ * ANY string as visible text in the end, so no printable spelling is impossible
18
+ * outright — this one is chosen to mean nothing ELSE, and resolution is by exact
19
+ * issued string, never by shape alone:
20
+ * - web (`browser/query.ts`): not an engine (`css=`, `text=`, `role=`, `id=`,
21
+ * `data-testid=`, `xpath=`, `internal:…=` — and Playwright's own `aria-ref=`
22
+ * — all need `name=`; this has no `=`), not `role "name"`, not a bare tag,
23
+ * and not valid CSS (`@` cannot start a selector).
24
+ * - native (`desktop/atspi-parse.ts`, `android/uiautomator.ts`): not
25
+ * `role "name"`; it could only be a literal name substring.
26
+ * So the one reading left is "visible text that literally says `@@ref:3`" — and
27
+ * that passes through untouched unless this run issued exactly that string. A
28
+ * plain `ref=1` selector is never touched at all.
29
+ */
30
+ import type { Adapter } from '../../adapters/contract.js';
31
+ /** The reference standing in for `selector` on this adapter — stable across re-reads. */
32
+ export declare function targetRefFor(adapter: Adapter, selector: string): string;
33
+ /**
34
+ * The real selector behind `target` when it is EXACTLY a reference this adapter
35
+ * issued; every other string — including a reference-shaped one nobody issued —
36
+ * passes through untouched and the adapter reports the miss as it would for any
37
+ * selector that matches nothing.
38
+ */
39
+ export declare function resolveTargetRef(adapter: Adapter, target: string): string;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Opaque target references — how a node stays addressable when its selector
3
+ * would carry one of the run's secrets.
4
+ *
5
+ * `observe` builds each node's `target` from its accessible name. A page that
6
+ * echoes a persona value in visible text ("Signed in as …") therefore puts the
7
+ * secret into a selector the driver reads and the SDK re-sends every step.
8
+ * Masking the selector would break it; omitting it leaves the node unreachable
9
+ * (its name is masked too). So the belt hands out a reference instead and keeps
10
+ * the real selector here, keyed by the run's adapter — `observe` issues, `act`
11
+ * (and `observe`'s own `query`/`within`) resolve. One adapter per run, so a
12
+ * reference can never resolve against another run's page.
13
+ *
14
+ * ## The spelling: `@@ref:N`
15
+ *
16
+ * It must not collide with a selector a driver could mean. Both dialects accept
17
+ * ANY string as visible text in the end, so no printable spelling is impossible
18
+ * outright — this one is chosen to mean nothing ELSE, and resolution is by exact
19
+ * issued string, never by shape alone:
20
+ * - web (`browser/query.ts`): not an engine (`css=`, `text=`, `role=`, `id=`,
21
+ * `data-testid=`, `xpath=`, `internal:…=` — and Playwright's own `aria-ref=`
22
+ * — all need `name=`; this has no `=`), not `role "name"`, not a bare tag,
23
+ * and not valid CSS (`@` cannot start a selector).
24
+ * - native (`desktop/atspi-parse.ts`, `android/uiautomator.ts`): not
25
+ * `role "name"`; it could only be a literal name substring.
26
+ * So the one reading left is "visible text that literally says `@@ref:3`" — and
27
+ * that passes through untouched unless this run issued exactly that string. A
28
+ * plain `ref=1` selector is never touched at all.
29
+ */
30
+ const registries = new WeakMap();
31
+ /** The exact shape of an issued reference; capture = its 1-based number. */
32
+ const REF = /^@@ref:([1-9]\d*)$/;
33
+ /** The reference standing in for `selector` on this adapter — stable across re-reads. */
34
+ export function targetRefFor(adapter, selector) {
35
+ let registry = registries.get(adapter);
36
+ if (!registry) {
37
+ registry = { selectors: [], refs: new Map() };
38
+ registries.set(adapter, registry);
39
+ }
40
+ const known = registry.refs.get(selector);
41
+ if (known !== undefined)
42
+ return known;
43
+ registry.selectors.push(selector);
44
+ const ref = `@@ref:${registry.selectors.length}`;
45
+ registry.refs.set(selector, ref);
46
+ return ref;
47
+ }
48
+ /**
49
+ * The real selector behind `target` when it is EXACTLY a reference this adapter
50
+ * issued; every other string — including a reference-shaped one nobody issued —
51
+ * passes through untouched and the adapter reports the miss as it would for any
52
+ * selector that matches nothing.
53
+ */
54
+ export function resolveTargetRef(adapter, target) {
55
+ const match = REF.exec(target);
56
+ if (!match)
57
+ return target;
58
+ return registries.get(adapter)?.selectors[Number(match[1]) - 1] ?? target;
59
+ }
60
+ //# sourceMappingURL=target-refs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"target-refs.js","sourceRoot":"","sources":["../../../src/agent/belt/target-refs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAYH,MAAM,UAAU,GAAG,IAAI,OAAO,EAAqB,CAAC;AAEpD,4EAA4E;AAC5E,MAAM,GAAG,GAAG,oBAAoB,CAAC;AAEjC,yFAAyF;AACzF,MAAM,UAAU,YAAY,CAAC,OAAgB,EAAE,QAAgB;IAC7D,IAAI,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;QAC9C,UAAU,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IACtC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClC,MAAM,GAAG,GAAG,SAAS,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;IACjD,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACjC,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgB,EAAE,MAAc;IAC/D,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,KAAK;QAAE,OAAO,MAAM,CAAC;IAC1B,OAAO,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,MAAM,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Tree-node selectors for the belt — the `target` string `observe` attaches to
3
+ * every node it returns, and the `within` scope it accepts back.
4
+ *
5
+ * Split from `observe.ts` (one responsibility per file): `observe` routes reads,
6
+ * this module knows the two selector dialects ({@link SelectorDialect}) and how a
7
+ * node round-trips between a read and the next `act`/`observe`.
8
+ */
9
+ import { z } from 'zod';
10
+ import type { Adapter, Node, NodeField, NodeRef, SelectorDialect } from '../../adapters/contract.js';
11
+ /**
12
+ * A {@link Node} echoed back as a `within` scope (the alternative to a selector string).
13
+ *
14
+ * `bounds`/`enabled` are OPTIONAL: a `fields:["role","name"]` read — what the web
15
+ * addendum recommends for slim reads — returns neither, and rejecting the very node
16
+ * observe just handed back is the kind of contradiction that burns steps. Role + name
17
+ * are enough; {@link coerceWithin} turns a region-less node into a selector.
18
+ */
19
+ export declare const NodeSchema: z.ZodObject<{
20
+ role: z.ZodString;
21
+ name: z.ZodString;
22
+ bounds: z.ZodOptional<z.ZodObject<{
23
+ x: z.ZodNumber;
24
+ y: z.ZodNumber;
25
+ width: z.ZodNumber;
26
+ height: z.ZodNumber;
27
+ }, z.core.$strip>>;
28
+ enabled: z.ZodOptional<z.ZodBoolean>;
29
+ testid: z.ZodOptional<z.ZodString>;
30
+ }, z.core.$strip>;
31
+ /** A `within` node as the driver may pass it — possibly projected down to role + name. */
32
+ type WithinNode = z.infer<typeof NodeSchema>;
33
+ /** A tree node projected for the agent, plus a ready-to-use `target` selector for `act`. */
34
+ export type TreeNode = Partial<Node> & {
35
+ target?: string;
36
+ };
37
+ /**
38
+ * The dialect an adapter speaks — READ from the adapter's own declaration
39
+ * ({@link Adapter.selectorDialect}).
40
+ *
41
+ * It used to be inferred from `tabs`, which the contract marks optional and
42
+ * web-only: a native target that grew a tab listing would silently flip to the
43
+ * web dialect and hand the driver selectors its own parser cannot resolve. The
44
+ * dialect is explicit now, and a missing or unknown declaration fails loud
45
+ * instead of falling back to `web`.
46
+ */
47
+ export declare function dialectOf(adapter: Adapter): SelectorDialect;
48
+ /**
49
+ * Attach a copy-paste `target` to each tree node, disambiguating duplicates with
50
+ * `>> nth=` in document order — so the agent never has to invent a selector (the
51
+ * #1 cause of wasted steps: a blind model guessing CSS that does not resolve).
52
+ *
53
+ * A `scoped` read (`query`/`within`/`filters`) returns a *subset*, so the `nth=`
54
+ * index — and even a bare role/text selector — can resolve a different element when
55
+ * `act` replays it with an unscoped, document-wide `find` (e.g. header "Settings"
56
+ * instead of the sidebar "Settings" the narrowed read returned). In that case we
57
+ * emit no `target` — EXCEPT a testid one, which is document-unique and survives
58
+ * any scoping. Otherwise, better the agent falls back (visible text /
59
+ * `role "name"`) than act on the wrong node.
60
+ *
61
+ * `>> nth=` is Playwright chaining and exists on WEB only; the native parsers read
62
+ * it as part of a name substring and match nothing. So on a native target a
63
+ * repeated selector yields a `target` for the FIRST node only — the others are
64
+ * genuinely unaddressable there, and saying so beats handing out a string that
65
+ * silently acts on the first one.
66
+ */
67
+ export declare function withTargets(nodes: Node[], dialect: SelectorDialect, fields?: readonly NodeField[], scoped?: boolean): TreeNode[];
68
+ /**
69
+ * Resolve `within` to something the {@link Adapter} contract takes — a selector string
70
+ * or a {@link Node}. Two coercions, each fixing a shape drivers actually produce:
71
+ *
72
+ * - a JSON-*stringified* node (`within: "{\"role\": …}"`). Before this it fell through
73
+ * as a selector, normalized to `text={"role"…}`, matched nothing, and returned an
74
+ * empty tree with no clue why — the single biggest step-waster observed.
75
+ * Garbage-that-looks-like-JSON fails loud instead of reading the whole page.
76
+ * - a node projected without `bounds` (`fields:["role","name"]`) → {@link scopeOf}.
77
+ */
78
+ export declare function coerceWithin(within: string | WithinNode | undefined, dialect: SelectorDialect): NodeRef | undefined;
79
+ export {};
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Tree-node selectors for the belt — the `target` string `observe` attaches to
3
+ * every node it returns, and the `within` scope it accepts back.
4
+ *
5
+ * Split from `observe.ts` (one responsibility per file): `observe` routes reads,
6
+ * this module knows the two selector dialects ({@link SelectorDialect}) and how a
7
+ * node round-trips between a read and the next `act`/`observe`.
8
+ */
9
+ import { z } from 'zod';
10
+ import { AgentError } from '../../errors.js';
11
+ /**
12
+ * Columns a no-`fields` read returns. `style` (colour + contrast per text node)
13
+ * is opt-in only — on a 200-node default read it would triple the payload the
14
+ * text driver re-reads every step for data it rarely needs.
15
+ */
16
+ const DEFAULT_PROJECTION = [
17
+ 'role',
18
+ 'name',
19
+ 'bounds',
20
+ 'enabled',
21
+ 'testid',
22
+ 'frame',
23
+ 'value',
24
+ 'checked',
25
+ ];
26
+ /** On-screen rectangle backing a {@link Node} `within` reference. */
27
+ const BoundsSchema = z.object({
28
+ x: z.number(),
29
+ y: z.number(),
30
+ width: z.number(),
31
+ height: z.number(),
32
+ });
33
+ /**
34
+ * A {@link Node} echoed back as a `within` scope (the alternative to a selector string).
35
+ *
36
+ * `bounds`/`enabled` are OPTIONAL: a `fields:["role","name"]` read — what the web
37
+ * addendum recommends for slim reads — returns neither, and rejecting the very node
38
+ * observe just handed back is the kind of contradiction that burns steps. Role + name
39
+ * are enough; {@link coerceWithin} turns a region-less node into a selector.
40
+ */
41
+ export const NodeSchema = z.object({
42
+ role: z.string(),
43
+ name: z.string(),
44
+ bounds: BoundsSchema.optional(),
45
+ enabled: z.boolean().optional(),
46
+ testid: z.string().optional(),
47
+ });
48
+ /**
49
+ * The dialect an adapter speaks — READ from the adapter's own declaration
50
+ * ({@link Adapter.selectorDialect}).
51
+ *
52
+ * It used to be inferred from `tabs`, which the contract marks optional and
53
+ * web-only: a native target that grew a tab listing would silently flip to the
54
+ * web dialect and hand the driver selectors its own parser cannot resolve. The
55
+ * dialect is explicit now, and a missing or unknown declaration fails loud
56
+ * instead of falling back to `web`.
57
+ */
58
+ export function dialectOf(adapter) {
59
+ // Read as `unknown`: the declaration is data, and a missing or misspelled one
60
+ // must fail loud rather than slip through as the web default.
61
+ const declared = adapter.selectorDialect;
62
+ if (declared === 'web')
63
+ return 'web';
64
+ if (declared === 'native')
65
+ return 'native';
66
+ throw new AgentError(`adapter declares no usable selector dialect (got ${String(declared)}) — ` +
67
+ 'every adapter must declare `selectorDialect: "web" | "native"`');
68
+ }
69
+ /** A role token both native parsers accept as the leading word of `role "name"`. */
70
+ const NATIVE_ROLE_TOKEN = /^[a-zA-Z][\w-]*$/;
71
+ /**
72
+ * The base selector for a node on a NATIVE target (desktop AT-SPI · android
73
+ * uiautomator). Their query parsers accept exactly two shapes — `role "name"`
74
+ * (`/^([a-zA-Z][\w-]*)\s+["'](.+)["']$/`, role matched exactly, name as a
75
+ * case-insensitive substring) and a bare name substring — so that is all we emit.
76
+ *
77
+ * A `testid` here is android's `resource-id` (`com.app:id/submit`), which its
78
+ * matcher tests against `name + resourceId`: the bare id is both accepted and
79
+ * near-unique, so it wins, exactly like `data-testid` does on web.
80
+ */
81
+ function nativeSelector(node) {
82
+ if (node.testid)
83
+ return node.testid;
84
+ const name = node.name.trim();
85
+ if (!name)
86
+ return null;
87
+ // A quote inside the name would close the parser's quoted group early; fall back
88
+ // to the bare-name form rather than emit a selector that resolves the wrong node.
89
+ if (NATIVE_ROLE_TOKEN.test(node.role) && !name.includes('"'))
90
+ return `${node.role} "${name}"`;
91
+ return name;
92
+ }
93
+ /** ARIA roles Playwright's `role=` engine accepts (others fall back to a text selector). */
94
+ const ARIA_ROLES = new Set([
95
+ 'button',
96
+ 'link',
97
+ 'checkbox',
98
+ 'radio',
99
+ 'textbox',
100
+ 'combobox',
101
+ 'slider',
102
+ 'heading',
103
+ 'img',
104
+ 'navigation',
105
+ 'main',
106
+ 'form',
107
+ 'list',
108
+ 'listitem',
109
+ 'tab',
110
+ 'menuitem',
111
+ 'switch',
112
+ 'dialog',
113
+ 'banner',
114
+ 'contentinfo',
115
+ 'region',
116
+ 'article',
117
+ 'search',
118
+ 'table',
119
+ ]);
120
+ /**
121
+ * The base selector for a node the agent can paste straight into `act`'s `target`,
122
+ * in the target's own {@link SelectorDialect} (a `native` node goes to
123
+ * {@link nativeSelector}). Web: role + accessible name when the role is
124
+ * ARIA-addressable, else the visible text. `null` for an unnamed, non-semantic
125
+ * node (the agent targets those by other means).
126
+ */
127
+ function baseSelector(node, dialect) {
128
+ if (dialect === 'native')
129
+ return nativeSelector(node);
130
+ // A test hook beats everything: document-unique, stable across renames/moves.
131
+ if (node.testid)
132
+ return `data-testid=${JSON.stringify(node.testid)}`;
133
+ const name = node.name.trim();
134
+ if (node.role && ARIA_ROLES.has(node.role) && name) {
135
+ return `role=${node.role}[name=${JSON.stringify(name)} i]`;
136
+ }
137
+ if (name)
138
+ return `text=${name}`;
139
+ return null;
140
+ }
141
+ /**
142
+ * Attach a copy-paste `target` to each tree node, disambiguating duplicates with
143
+ * `>> nth=` in document order — so the agent never has to invent a selector (the
144
+ * #1 cause of wasted steps: a blind model guessing CSS that does not resolve).
145
+ *
146
+ * A `scoped` read (`query`/`within`/`filters`) returns a *subset*, so the `nth=`
147
+ * index — and even a bare role/text selector — can resolve a different element when
148
+ * `act` replays it with an unscoped, document-wide `find` (e.g. header "Settings"
149
+ * instead of the sidebar "Settings" the narrowed read returned). In that case we
150
+ * emit no `target` — EXCEPT a testid one, which is document-unique and survives
151
+ * any scoping. Otherwise, better the agent falls back (visible text /
152
+ * `role "name"`) than act on the wrong node.
153
+ *
154
+ * `>> nth=` is Playwright chaining and exists on WEB only; the native parsers read
155
+ * it as part of a name substring and match nothing. So on a native target a
156
+ * repeated selector yields a `target` for the FIRST node only — the others are
157
+ * genuinely unaddressable there, and saying so beats handing out a string that
158
+ * silently acts on the first one.
159
+ */
160
+ export function withTargets(nodes, dialect, fields, scoped = false) {
161
+ const seen = new Map();
162
+ const projection = fields && fields.length > 0 ? fields : DEFAULT_PROJECTION;
163
+ return nodes.map((node) => {
164
+ const projected = pick(node, projection);
165
+ if (scoped) {
166
+ if (node.testid) {
167
+ projected.target =
168
+ dialect === 'native' ? node.testid : `data-testid=${JSON.stringify(node.testid)}`;
169
+ }
170
+ return projected;
171
+ }
172
+ const base = baseSelector(node, dialect);
173
+ if (!base)
174
+ return projected;
175
+ const k = seen.get(base) ?? 0;
176
+ seen.set(base, k + 1);
177
+ if (k === 0)
178
+ projected.target = base;
179
+ else if (dialect === 'web')
180
+ projected.target = `${base} >> nth=${k}`;
181
+ return projected;
182
+ });
183
+ }
184
+ /** Pick a subset of keys off an object (a typed `SELECT cols`) for the `fields` projection. */
185
+ function pick(obj, keys) {
186
+ const out = {};
187
+ // Skip absent optionals (testid/style) so they never serialize as explicit nulls.
188
+ for (const key of keys)
189
+ if (obj[key] !== undefined)
190
+ out[key] = obj[key];
191
+ return out;
192
+ }
193
+ /**
194
+ * A `within` node as a contract {@link NodeRef}: its on-screen region when it has one,
195
+ * else the selector its testid/role/name resolve to — the same string `observe` would
196
+ * have attached to that node as `target`.
197
+ *
198
+ * Adapters scope a {@link Node} `within` by `bounds` ALONE, so a region-less node has
199
+ * to become a selector or it would silently read nothing. `enabled` is never read when
200
+ * scoping; the contract just requires the field, so a projection that dropped it
201
+ * defaults to `true` rather than throwing away an exact region.
202
+ */
203
+ function scopeOf(node, dialect) {
204
+ const { bounds } = node;
205
+ if (bounds !== undefined)
206
+ return { ...node, bounds, enabled: node.enabled ?? true };
207
+ const selector = baseSelector(node, dialect);
208
+ if (selector)
209
+ return selector;
210
+ throw new AgentError('observe `within` node has no `bounds` and no name/testid to resolve it — re-read with `fields` including "bounds", or pass a selector string');
211
+ }
212
+ /**
213
+ * Resolve `within` to something the {@link Adapter} contract takes — a selector string
214
+ * or a {@link Node}. Two coercions, each fixing a shape drivers actually produce:
215
+ *
216
+ * - a JSON-*stringified* node (`within: "{\"role\": …}"`). Before this it fell through
217
+ * as a selector, normalized to `text={"role"…}`, matched nothing, and returned an
218
+ * empty tree with no clue why — the single biggest step-waster observed.
219
+ * Garbage-that-looks-like-JSON fails loud instead of reading the whole page.
220
+ * - a node projected without `bounds` (`fields:["role","name"]`) → {@link scopeOf}.
221
+ */
222
+ export function coerceWithin(within, dialect) {
223
+ if (within === undefined)
224
+ return undefined;
225
+ if (typeof within !== 'string')
226
+ return scopeOf(within, dialect);
227
+ if (!within.trimStart().startsWith('{'))
228
+ return within;
229
+ let data;
230
+ try {
231
+ data = JSON.parse(within);
232
+ }
233
+ catch {
234
+ throw new AgentError('observe `within` looks like a JSON node but does not parse — pass the node OBJECT exactly as observe returned it, or a selector string');
235
+ }
236
+ const parsed = NodeSchema.safeParse(data);
237
+ if (!parsed.success) {
238
+ throw new AgentError('observe `within` was a JSON string but not a valid node (needs role + name) — pass a node from a previous observe, or a selector string');
239
+ }
240
+ return scopeOf(parsed.data, dialect);
241
+ }
242
+ //# sourceMappingURL=tree-targets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-targets.js","sourceRoot":"","sources":["../../../src/agent/belt/tree-targets.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;GAIG;AACH,MAAM,kBAAkB,GAAG;IACzB,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,OAAO;IACP,OAAO;IACP,SAAS;CAC8B,CAAC;AAE1C,qEAAqE;AACrE,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;IACb,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE;IACb,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE;IACjB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;CACnB,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,MAAM,EAAE,YAAY,CAAC,QAAQ,EAAE;IAC/B,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC/B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC,CAAC;AAQH;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAC,OAAgB;I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C/I,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAuC,EACvC,OAAwB;IAExB,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC3C,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAO,MAAM,CAAC;IACvD,IAAI,IAAa,CAAC;IAClB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,UAAU,CAClB,wIAAwI,CACzI,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,UAAU,CAClB,yIAAyI,CAC1I,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Self-look frame hygiene for the debug loop's transcript.
3
+ *
4
+ * A multimodal driver's `look` returns the screenshot itself, and the SDK
5
+ * re-sends every tool result on every step — so each frame would ride along for
6
+ * the rest of the run. {@link pruneStaleFrames} keeps only the newest one live;
7
+ * the loop applies it per step in `prepareStep` (`loop.ts`).
8
+ */
9
+ import type { ModelMessage } from 'ai';
10
+ /** What a pruned frame collapses to — tells the driver how to get a fresh one. */
11
+ export declare const STALE_FRAME_NOTE = "[stale frame removed \u2014 call look again for a fresh screenshot]";
12
+ /**
13
+ * Keep only the NEWEST self-look frame in the transcript. The SDK re-sends every
14
+ * tool result on every step, so each `look` image would otherwise ride along for
15
+ * the rest of the run — N looks × M steps of image tokens. Rebuilt per step in
16
+ * `prepareStep`, over the stripped chain (`stripInjectedStepMessages`, `loop.ts`).
17
+ *
18
+ * Counts FRAMES, not messages: AI SDK 6 collects ALL of a step's tool results
19
+ * into ONE `tool`-role message, so a step that looked twice holds two frames in
20
+ * a single message. The newest frame (last in transcript order) stays live and
21
+ * every older one collapses to {@link STALE_FRAME_NOTE}; the rest of each
22
+ * tool-result (its own text, a sibling `act` result) is left exactly as it was.
23
+ * Returns the SAME array when the transcript holds at most ONE frame, keeping
24
+ * the no-change fast path.
25
+ */
26
+ export declare function pruneStaleFrames(messages: ModelMessage[]): ModelMessage[];