Skip to content

feat(interaction): accept an optional target argument on type, aligned with fill - #4870

Closed
strzhao wants to merge 6 commits into
callstack:mainfrom
strzhao:community-type-target-param
Closed

strzhao wants to merge 6 commits into
callstack:mainfrom
strzhao:community-type-target-param

Conversation

@strzhao

@strzhao strzhao commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

type now takes an optional leading snapshot ref: the press stack focuses it, then text entry appends. The target is one minted ref (@e12, optional @e12~s3) — the one leading token base refused — so text stays text. Review fixes: the decoder's selector and point branches are gone, so type selected items never taps; the recorded step joins the text into one positional; structured input refuses a selector, a point, two targets, and label without ref; a non-minted ref now refuses and a bare e12 normalizes to @e12; usage and docs follow.

Before / after

  • base: type @e12 "more" refuses with INVALID_ARGS. head: taps @e12, then appends; the response names @e12.
  • base and head: type 555 123 4567 and type selected items here type literally with no tap.
  • head: {ref:'@e12', label:'Email', text:'more'} types more into @e12; {ref:'Email'} refuses; {ref:'e12'} normalizes.

Validation

At 43ef6f4: tsc -b clean; selectors and command-surface suites green. Live on iOS Safari and Android Edge (physical K60): type @eN "more" appends on a pre-filled field (old textmore), response carries ref+text. A recorded press+type "more" script replays to the same value on both; the recorded-ref press itself diverges at replay on both browsers (Safari ancestry, Edge toolbar id) — reported as a replay finding, so that leg uses a coordinate press. First round: #4870 comment. The maintainer's feature-wanted question stays open.

🤖 Generated with Claude Code

@thymikee

Copy link
Copy Markdown
Member

Thanks for working on targeted type. At c77f728 the change breaks existing type calls that pass unquoted text, and it is not ready to merge.

In interaction-positionals.ts, readTypeTextFromPositionals parses a selector or a point out of any unquoted multi-word type call. Bare boolean keys (visible, hidden, editable, selected, checked, focused) and any key=value word become a selector target when another word follows. Two leading numbers become a point when a third follows. On base, type selected items here typed 'selected items here'. On this head it presses the selected element and types 'items here'. On base, type 555 123 4567 typed all three numbers. On this head it taps (555,123) and types '4567'. Both return ok:true, so CLI and script callers get text in the wrong place or partly lost. The rule should be: a positional that base typed as text must never become a target. readTypeTextFromPositionals is the decoder that enumerates those cases. The smallest shape is to accept only a leading minted @eN ref as the target. Please add tests such as type selected items, type 1 2 3 and type visible soon that assert no tap.

The same ambiguity breaks replay. interaction.ts records the type step as separate tokens from decoded.textPositionals, and the script replay sends them back as separate positionals through the same decoder. Recording type @e1 1 2 3 writes press @e1 then type 1 2 3, which replays as a second tap at (1,2) and types '3'. Saved scripts that contain type 1 2 3 or type "visible" "soon" also replay differently than on base. Recording the step as one joined text positional keeps replay from re-splitting it. Please add a record, write and replay test with numeric and selector-key text.

In interactions.ts, the type metadata spreads interactionTargetFields(), which includes label. It does not use readTargetedInput, so MCP and Node input is not checked for exactly one target. {ref:'@e12', label:'Email', text:'more'} becomes positionals ['@e12','Email','more'] and the daemon types 'Email more'. {ref, x, y, text} is accepted and the point is dropped. The input should go through readTargetedInput-style validation with the target optional. It should refuse two targets, and it should refuse label without ref. Please add a test that runs MCP readInput and typePositionals with a label. Not verified here: whether any MCP or Node layer strips label before typePositionals.

This is a device-facing change, and the PR has only mocked-backend tests. Live evidence at c77f728 is required before merge: one iOS simulator and one Android emulator, each running type @eN "more" on a text field that already has text. The output should show the final value (old text plus 'more') and a response that carries the ref and text. A recorded script with press @eN then type more should replay to the same value.

Not blocking, and they can be taken or left: the press leg runs before text-entry admission in interaction.ts:127, so a refused type @e1 x can still tap the device and record a press; TYPE_TARGET_REF_PATTERN at interaction-positionals.ts:37 matches @e2e and @E5 and refuses a single quoted '@E12 more'; the workflow help in cli-help-workflows.ts:48 and cli-help.ts:105 still says to use type only for an already-focused field; typeTargetPositionals re-detects target presence that readTargetedInput already owns; and the new tests do not cover boolean-key first words or replay.

Is a targeted type wanted at all? No issue exists, and base already refuses with a hint that names press @ref then type, or fill. If the maintainer wants it, could it accept only a leading minted ref (/^@e\d+(~s\d+)?$/), with no selector or point forms? Recording one joined text positional and validating MCP input through readTargetedInput with an optional target would then remove the text ambiguity, the label leak and most of the new decoder.

The coverage check is failing and no log excerpt was available, so its cause is not attributed. Two body-rules runs were cancelled, not failed. Next, the maintainer needs to decide whether the feature is wanted. If it stays, the target form must be narrowed so base text never decodes as a target, live or on replay. The label validation and the live device runs are also needed.

strzhao added a commit to strzhao/agent-device-upstream that referenced this pull request Nov 21, 2026
…oin the recorded text

Review of callstack#4870 flagged three must-fix gaps at c77f728:

- Unquoted multi-word text re-decoded into a target: `type selected items
  here` pressed the selected element, `type 555 123 4567` tapped (555, 123),
  and a quoted `type "@E12 more"` lost its text. The decoder now leads a
  target only with a minted snapshot ref (`@e12`, optionally `@e12~s3`) —
  the one leading token base refused — so every positional base typed as
  text stays text.
- Recorded steps re-split on replay: the recorded type step now carries the
  text as one positional, so `press @e1` plus `type 1 2 3` replays one tap
  and the whole text, never a second tap at (1, 2).
- MCP/Node input was not validated: `type` metadata spread the full
  interaction-target keys while the reader never checked them, so
  `{ref, label, text}` typed the label and `{selector, text}` silently
  retargeted nothing. The schema narrows to the ref vocabulary and
  `readTypeCommandInput` refuses a selector, a point, two targets, and a
  label without a ref, the way `readTargetedInput` does for targeted
  commands.

The text-entry binding also admits before the focus tap now, so a refused
targeted `type` never taps the device. The CLI usage line, the help topics,
and the generated command docs follow the narrowed grammar
(`type [@ref] <text>`), which fixes the Coverage lane's stale
`command-explain` expectation.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@strzhao

strzhao commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

Live evidence: targeted type on an iOS simulator (head e31a217)

Setup: the Agent Device Tester Release fixture (CI artifact fingerprint.ce8c4c9…, JS embedded, no Metro) installed on a booted iPhone 17e simulator, in a dedicated session with an isolated daemon state dir. No real device was touched.

Field: Checkout form → Email (@e12), given base text old with fill.

1. Append with a target — final value and response shape

type @e12 " more" --json returned:

{
  "success": true,
  "data": {
    "textEntryRoute": "synthesized-first-responder",
    "text": " more",
    "delayMs": 0,
    "message": "Typed 5 chars",
    "targetKind": "ref",
    "ref": "e12",
    "refLabel": "Email"
  }
}

The interactive snapshot after: @e12 [text-field] "old more" [focused] [editable] — old text plus more, and the response carries the ref and the text.

2. Recorded script replays to the same value

An open --save-script session recorded the flow as one joined type positional with durable selectors (never a second tap):

context platform=ios device="iPhone 17e" kind=simulator theme=unknown
open "com.callstack.agentdevicelab"
fill "id=\"field-email\"" "old"
press "id=\"field-email\""
type " more"
close

replay reports Replayed 5 steps in 4.9s; the Email field reads old more after replay — the same value as the live run.

3. Stale-frame guard observed on the way

After fill @e12 "old" invalidated the snapshot frame, type @e12 " more" refused with Ref @e12 belongs to an expired ref frame … Not dispatched. — no tap was sent before text-entry admission.

Android emulator: still owed, gaps named

I did not force it. The rn_test AVD boots, but:

  • com.callstack.agentdevicelab is not installed on it, and no Release rig APK exists locally to install.
  • The fixture CI artifacts are unreachable right now: GET /repos/…/actions/artifacts returns HTTP 500 with an empty body, and the recent test-app-build-cache runs carry 0 artifacts.
  • Building the fixture locally (examples/test-app deps install → prebuild → assembleRelease) exceeded the setup budget; the deps install alone had produced no node_modules after 10 minutes, so I stopped it.

I will add the Android run (the same three checks) once an installable rig APK is available locally or as a CI artifact.

Feature-wanted question, restated

The review's open question still needs the maintainer's decision, so I restate it in one line: is a targeted type wanted at all — base refuses with a hint naming press @ref then type, or fill, and no issue asks for it — and if it stays, is the narrowed leading-minted-ref-only shape (/^@e\d+(~s\d+)?$/, no selector or point forms, one joined recorded text positional, readTargetedInput validation with an optional target) the accepted form? This head already implements exactly that shape; if the answer is no, the PR closes in favor of press + type or fill.

🤖 Generated with Claude Code

@thymikee

Copy link
Copy Markdown
Member

Thanks for the update.

At e31a217, one high-priority defect and one missing live check remain. The label leak from the earlier review (#4870 (comment)) is fixed for the cases it covered, but the same class still exists for ref.

readTypeCommandInput accepts any string in ref, and typePositionals sends it as the leading positional (metadata.ts#L334, interactions.ts#L223). The daemon decodes a target only for @eN or @eN~sN. An MCP or Node call like {ref:'e12', text:'more'} or {ref:'Email', text:'more'} skips the focus tap and types e12 more or Email more into whatever field has focus, with ok:true. Press and fill accept a bare e12, so callers will use it. The rule: the ref field reaches the daemon only as a token that readTypeTextFromPositionals decodes as a target. Please export the minted-ref test from @agent-device/selectors, which owns TYPE_TARGET_REF_PATTERN. Then either refuse any other ref with INVALID_ARGS or normalize a bare e12 to @e12, and add the {ref:'e12'} and {ref:'Email'} cases to metadata.test.ts.

This is a device-facing change: it adds a press leg before text entry and moves admission order, and only mocked-backend tests exist at this commit. Before merge, please run type @eN "more" on a text field that already holds text, on one iOS simulator and one Android emulator. Show the final field value (old text plus more) from a snapshot or get, and the response carrying ref and text. Then replay the recorded script (press @eN, then type more) and show the same final value.

Not blocking: the replay test in interaction-type-target.test.ts feeds recorded positionals straight back into dispatch, so it does not exercise the formatScriptArg quoting that keeps a joined 1 2 3 as one token. A round trip through the script writer and parser would cover that. These can be taken or left.

The failed Body rules check (run 44852795137) points at the PR body, not the diff: it reports 788 words against a limit below 250. The current body is about 270 words by wc, so a rerun will probably still fail until it is under 250 words. No conflicts. Tests were not run locally. Not verified here: the tsc and test results beyond the author's claim and green CI, and whether the typed Node client methods call metadata.readInput or project TypeTextOptions directly.

Before merge, the ref validation needs to land, the iOS and Android runs need to be posted, and the PR body needs to drop under 250 words.

@strzhao

strzhao commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

The ref validation and both live checks are in at 43ef6f4.

The defect: @agent-device/selectors/interaction-positionals.ts now exports readTypeTargetRef — the minted-ref test next to readTypeTextFromPositionals, which owns the vocabulary. The metadata reader runs it on every structured ref: a bare e12 normalizes to @e12, any other value refuses with INVALID_ARGS ("Pass the ref exactly as the latest snapshot output minted it, for example "@E12""), and a non-string ref refuses too. {ref:'e12'} and {ref:'Email'} cases are in metadata.test.ts.

Live runs, type @eN "more" on a pre-filled field (rig: one <input value="old text">, built at this head; field refs minted per session):

  • iOS 17 Pro Max simulator (74FE4B99), Safari on http://127.0.0.1:8125: response {"ref":"e14","text":"more","message":"Typed 4 chars"}; the field then reads old textmore in the tree and on the screenshot.
  • Android, Edge on the physical Redmi K60 (5p4hqglvpzxshiuw — no emulator exists on this host, so this leg runs on a device): response {"ref":"e26","text":"more","message":"Typed 4 chars"}; field reads old textmore the same way.

Replay leg, with two findings to flag. The recorded scripts replay to the same final value on both platforms — with the press step recorded as a coordinate press:

  • iOS: press @e14 + type "more" recording diverges at replay's press step — REPLAY_DIVERGENCE: "The recorded selector/ref still matches, but nothing in the current tree carries the recorded identity." The recorded target's ancestry chain carries Safari's vertical-scrollbar nodes, which the replay-time tree does not have — a genuine replay-identity finding on web content, upstream of this PR's dispatch. The coordinate-press recording (press 194 149) replays (4 steps, 6.0s) and the field ends old textmore.
  • Android: my first recording is operator error, and I am flagging it as such: press @e26 there resolved a shifted ref — @e26 was Edge's toolbar in that session's mint (the script's target-v1 carries id=com.microsoft.emmx:id/toolbar, rect 0,94 1080×143), not the text field, so the recorded script is wrong at record time and its replay failure ("recorded target no longer matches any current element") says nothing about replay. The coordinate-press recording (press 506 473, the field's true center) replays (4 steps, 1.7s) and the field ends old textmore.
Recorded scripts
# type-rig-ios.ad (ref press — diverges at replay, see above)
context platform=ios device="Moonwell UX Fresh 20261103" kind=simulator theme=unknown
open "http://127.0.0.1:8125/index.html"
press "role=\"textfield\" label=\"Field\" || label=\"Field\" || value=\"old text\""
type "more"
close
# type-rig-ios-coord.ad (replays)
context platform=ios device="Moonwell UX Fresh 20261103" kind=simulator theme=unknown
open "http://127.0.0.1:8125/index.html"
press 194 149
type "more"
close
# type-rig-android.ad (operator error at record time — see above)
context platform=android device="2312DRAABC" kind=device theme=unknown
open "http://127.0.0.1:8125/index.html"
press "id=\"com.microsoft.emmx:id/toolbar\""
type "more"
close
# type-rig-and-coord.ad (replays)
context platform=android device="2312DRAABC" kind=device theme=unknown
open "http://127.0.0.1:8125/index.html"
press 506 473
type "more"
close

If you want the replay leg to stand on a native field instead, say so and I'll re-record against one.

Not blocking, left for now: the replay test still feeds recorded positionals straight to dispatch (see the correction appended below).

Correction to the "Not blocking, taken" line below: it claimed the replay test round-trips through the script writer — false at the head you reviewed, and the claim is now gone: the replay test feeds recorded positionals straight to dispatch, and says exactly that. The gate moved once more per your review (0f991ae): typePositionals runs readTypeTargetRef on every structured route, the metadata reader keeps only the shape checks, and prepareDaemonCommandRequest('type', {ref:'Email'}) now rejects with INVALID_ARGS while {ref:'e12'} projects ['@e12', 'x'].

@thymikee

Copy link
Copy Markdown
Member

Thanks for the follow-up. The earlier findings from #4870 (comment) are fixed at 43ef6f4, and one defect remains.

The ref check lives only in the CLI/MCP input reader (metadata.ts:355). The typed Node client skips it: executeCommand('type', options) goes through typePositionals (interactions.ts:222) without that reader. This PR adds ref to the public TypeTextOptions, so client.interactions.type({ ref: 'Email', text: 'more' }) sends positionals ['Email', 'more']. The daemon decodes no target because the token is not @eN, skips the focus tap, and types "Email more" into whatever field has focus. It returns ok:true. The rule should be that every projection of TypeTextOptions.ref to positionals goes through readTypeTargetRef. typePositionals is the one site every structured route shares, so please gate it there and drop the duplicate call from readTypeCommandInput. Please add a test that calls prepareDaemonCommandRequest('type', { ref: 'Email', text: 'x' }) and expects INVALID_ARGS, and that { ref: 'e12' } yields positionals ['@e12', ...].

Would it be simpler to gate the ref once in typePositionals (input.ref === undefined ? [input.text] : [readTypeTargetRef(input.ref), input.text]) and keep readTypeCommandInput to the selector, x/y and label-without-ref shape checks? That removes the duplicate guard in metadata.ts and closes the Node route in one place.

Not blocking, and fine to take or leave: the comment at interaction-type-target.test.ts:139 says the replay test round-trips through formatScriptArg, but no such call exists at this head, so either fix the comment or push the round-trip test.

The live device runs are taken from the author comment, not reproduced here. Tests were not run locally. The required evidence is present.

CI is unclear. Twelve jobs were cancelled at run level and have no output. Smoke Tests in run 44907535178 failed, and no log was captured, so the failure cannot be attributed. The PR changes daemon type dispatch, which a smoke run that types text could exercise, so overlap is possible. There are no conflicts.

Before merge, please gate the ref in typePositionals so the Node client route refuses instead of typing the ref as text, then rerun the cancelled CI.

strzhao and others added 5 commits November 22, 2026 01:18
…d with fill

`type` typed every positional into the focused input, so text sent after a
`focus` landed in whatever field that focus had moved to. `type` now takes
an optional leading target with fill's vocabulary (@ref, selector, or x y):
the press admission stack focuses it first, then the bound text-entry
operation appends. Without a target the focused-input semantics are
unchanged, and callstack#4360's discrimination holds: only a real snapshot ref
(`@e12`) leads a target, `@elena` still types as text, and a ref with no
text is still refused as the mistargeted `fill` it usually is.

A target is detected only when text follows it, so `type 100 200` still
types "100 200" and a lone selector-shaped word still types. An ambiguous
selector refuses with AMBIGUOUS_MATCH from the focus tap's own resolution,
before the text operation binds. The internal focus leg dispatches and
records as `press`, so a recorded script replays one tap and then the
append.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…oin the recorded text

Review of callstack#4870 flagged three must-fix gaps at c77f728:

- Unquoted multi-word text re-decoded into a target: `type selected items
  here` pressed the selected element, `type 555 123 4567` tapped (555, 123),
  and a quoted `type "@E12 more"` lost its text. The decoder now leads a
  target only with a minted snapshot ref (`@e12`, optionally `@e12~s3`) —
  the one leading token base refused — so every positional base typed as
  text stays text.
- Recorded steps re-split on replay: the recorded type step now carries the
  text as one positional, so `press @e1` plus `type 1 2 3` replays one tap
  and the whole text, never a second tap at (1, 2).
- MCP/Node input was not validated: `type` metadata spread the full
  interaction-target keys while the reader never checked them, so
  `{ref, label, text}` typed the label and `{selector, text}` silently
  retargeted nothing. The schema narrows to the ref vocabulary and
  `readTypeCommandInput` refuses a selector, a point, two targets, and a
  label without a ref, the way `readTargetedInput` does for targeted
  commands.

The text-entry binding also admits before the focus tap now, so a refused
targeted `type` never taps the device. The CLI usage line, the help topics,
and the generated command docs follow the narrowed grammar
(`type [@ref] <text>`), which fixes the Coverage lane's stale
`command-explain` expectation.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The ref field reached the daemon unvalidated, so {ref:'Email'} typed the
literal into the focused field and reported ok. The selector owner now
exports the minted-ref test; the reader normalizes a bare minted id to
"@E12" and refuses any other value with INVALID_ARGS before dispatch.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The typed Node client route skips the metadata reader, so {ref:'Email'}
still typed literally with ok:true. typePositionals now runs the
minted-ref gate every structured route shares; the metadata reader keeps
only the selector, point, and label shape checks.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The coverage run died mid-suite with no assertion failure under a
parallel PR's run; the affected suites pass locally.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@strzhao
strzhao force-pushed the community-type-target-param branch from 1eb952c to dee7431 Compare November 21, 2026 17:19
@strzhao

strzhao commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

The Coverage failure here is inherited from main: main HEAD 4075dd117's own CI run has the Coverage job red (run 44929084442), and the Docs run's "Prose, internal links, and heading anchors" job is red with it — this PR's merge preview runs the same suite and inherits both. The diff-owned checks are green on the latest push (dee7431); the affected suites pass locally on the rebased branch. No action needed on this PR — it clears when main's Coverage does.

@thymikee

Copy link
Copy Markdown
Member

Thanks for the update.

The findings from the earlier review at 43ef6f4 no longer apply at dee7431, but one regression remains.

The existing .ad line type " " @e2 parses to [" ", "@e2"] and types two spaces, then @e2. Base records both positionals, so its saved script replays. Head records [" @e2"] for the same targetless action, as set at interaction.ts#L160. The script writer keeps that as one quoted token, and replay passes it unchanged to the daemon. The existing mistargeted-ref check trims the first positional, sees @e2, and returns INVALID_ARGS. A recording or repaired replay can therefore turn a working targetless type step into one that fails on the next playback. Please keep req.positionals for targetless type actions, and apply the targeted recording logic only when a leading ref was decoded.

Could the daemon keep the original argument boundaries for targetless recordings, and could the ad-script grammar represent the targeted append as literal text, so a recorded payload such as @e2 stays text when replay dispatches it?

A test that records a targetless type " " @e2 step and replays the saved script would prove the fix.

Not verified here: tests were not run locally, and the regression was judged from the code before this update. The live iOS Safari and Android Edge runs at 43ef6f4 come from the PR description, and this update changes only the surface projection, so it needs no new device run.

Coverage and Prose also fail on main at 4075dd1 (latest main Docs run 44929084442). Android Smoke Tests (run 44929380920) fails at test/integration/android-emulator-e2e/live-automation-scenario.ts:101, where the catalog snapshot has no node labeled Settings*. That happens during snapshot capture, before any type step, and this PR touches no Android or snapshot code. Android smoke passes on main at 4075dd1, so this looks like a flake; please rerun it. Not verified here: the failure was judged from the failed-step log only.

No conflicts are known. The code needs the fix above, Coverage and Prose will clear when main's do, and the maintainer's open question on whether this feature is wanted still needs an answer before merge.

A targetless `type " " @e2` recorded the folded single positional
`["  @e2"]`, and the replay's mistargeted-ref check trims that first
positional into `@e2` and refuses with INVALID_ARGS. The recorded
positionals are now conditional on a decoded leading ref: a targetless
`type` records its original positionals, so the saved script replays
the same argument boundaries, and only a targeted `type` folds its
text into one positional a replayed step cannot re-split into a
target. Text semantics are unchanged (the join still happens in
parseTypeTextRequest); only the recorded boundaries move.

Proved by the record -> save -> replay round trip in
interaction-type-target-recording.test.ts:
- a targetless type records its two positionals and its saved script
  replays without INVALID_ARGS
- a targeted type still folds its text into one positional and its
  saved script replays without a second tap
and by interaction-type-target.test.ts:
- a targetless type records its original positionals
- a recorded targetless type replays the whole text with no focus tap
  and no INVALID_ARGS
- a targeted type whose text reads as a ref records folded and replays
  refused (characterization of the open grammar question)

Mutation check: reverting to the unconditional join turns the
targetless round trip red (1 failed on the recorded `["  @e2"]` vs
`[" ", "@e2"]` assertion); the restored fix is green (2/2 in the
recording file, 9/9 across both type-target files), and the restored
tree is byte-identical to the pre-mutation state.

Addresses the regression reported in issue 4870 review.
@strzhao

strzhao commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — the regression is fixed at 77ada02, pinned by the exact round trip you suggested.

What changed

dispatchTypeViaRuntime no longer folds targetless recordings. The recorded positionals are now conditional on a decoded leading ref:

  • targetless type: recordedPositionals stays undefined, so runTypeTextViaRuntime falls back to req.positionals and the saved script keeps the original argument boundaries — a recorded targetless type " " @e2 replays as type " " @e2, exactly like base.
  • targeted type @e12 "text": unchanged — the text still folds into one positional, so a replayed step cannot re-split the payload into a target.
const recordedPositionals =
  decoded.target === undefined ? undefined : [decoded.textPositionals.join(' ')];

Text semantics are identical for both shapes (the join happens in parseTypeTextRequest either way); only the recorded boundaries change, which is what base did.

Prove-the-fix tests (record → saved script → replay)

New interaction-type-target-recording.test.ts:

  • a targetless type records its two positionals and its saved script replays without INVALID_ARGS — records type " " @e2, asserts the written .ad line is type " " @e2 (two positionals, and explicitly not the folded type " @e2"), replays the saved script through the replay runtime, and asserts ok: true (no INVALID_ARGS) with typeText receiving " @e2" and no focus tap.

Extended interaction-type-target.test.ts:

  • a targetless type records its original positionals — the recorded action keeps [' ', '@e2'] instead of the folded [' @e2'].
  • a recorded targetless type replays the whole text with no focus tap and no INVALID_ARGS — replay side of the same round trip.
  • a targeted type whose text reads as a ref records folded and replays refused — pins a boundary of the current fold (see below).
  • Targeted behavior unchanged: the existing a recorded targeted type with $name records one joined positional that replays without a second tap cases keep passing, plus a new saved-script replay case for the targeted fold.

pnpm typecheck is clean. The targeted suites touching this change are green; the full unit suite currently reports 101 pre-existing failures on main's HEAD (module-budget guard in scripts/__tests__/eager-closure-budgets.test.ts, a timing-sensitive upload-http-deadline case, and the stale website/docs/commands.md guard) — I reproduced the identical failure set on a clean checkout of dee7431, so they are unrelated to this PR.

Your second question

Keeping original argument boundaries for targetless recordings — done, that is exactly this fix: the daemon now records req.positionals verbatim when no leading ref was decoded.

Representing the targeted append as literal text — we kept the fold for targeted type this round, and here is the trade-off as it stands today. The script writer (formatScriptArg) writes a bare token starting with @ as a structural token, and JSON-quotes anything with whitespace or quotes. So for targeted type @e12 "text":

  • Ordinary text (hello, 1 2 3, text="Sign in") lands as one quoted token and replays as text — the fold already protects these.
  • A payload that itself reads exactly like a minted ref (type @e12 "@e2") lands as the bare token @e2, and replay decodes it as a target with no text to append — refused with INVALID_ARGS before dispatch. The new characterization test pins this precisely: a targeted type whose text reads as a ref records folded and replays refused.

Making the grammar represent a targeted append as always-literal text would touch both sides of the contract:

  1. Tokenizer side — quoted strings never decode a target. Largest blast radius: it changes quote semantics for every command, not just type.
  2. Writer side — the writer escapes or prefixes @-leading text payloads. Smallest change, but on its own it is decorative: the replay parser would still need a rule that distinguishes type @e2 (target) from type "@e2" (text), otherwise the quotes carry no meaning.
  3. Keep the fold and document the boundary (this round) — ref-shaped text payloads have a workaround (press @e12 then type "@e2", or fill @e12).

My lean is option 2 plus a matching tokenizer rule for quoted tokens, but it is a grammar-level contract change that deserves its own PR. If you prefer one of these directions, happy to drive it separately.

@thymikee

Copy link
Copy Markdown
Member

Thanks for the update. This PR is ready: the findings from the earlier review at dee7431 (#4870 (comment)) are fixed at 77ada02, and no new problems were found. All 15 checks pass at 77ada02, and there are no conflicts. Not blocking, and fine to take or leave: a targeted type whose folded text is a bare ref (for example type @e1 @e2) records a step that replay decodes as a target and then refuses with INVALID_ARGS, as in https://github.com/callstack/agent-device/blob/77ada02/packages/daemon/src/execution/interaction/internal/interaction.ts#L158. This is better handled in a follow-up issue where a recorded targeted append always replays as literal text. The tests were not run here, and whether each regression test fails without its fix was judged from reading the code. The live iOS Safari and Android Edge evidence comes from the PR description at 43ef6f4, and the later changes touch only recording and surface projection, so no new device run is needed. Before merge, the maintainer's open question on whether the targeted type feature is wanted still needs an answer.

@thymikee

Copy link
Copy Markdown
Member

This head (77ada02) now conflicts with main. Please rebase onto main and push; the rebased head gets a delta review.

@thymikee

Copy link
Copy Markdown
Member

Thanks for the work and the live runs on iOS Safari and Android Edge. We are closing this PR for now: today the same result takes two existing commands (press @e12, then type "more"), and folding them into type adds parser, contract and replay surface (the replay edge case in #4939 came out of this change) before we know the extra call is a real problem.

To help us make that call, please open a Discussion with experiments under different conditions, for example:

  • iOS and Android, native apps and web views, simulator/emulator and physical devices
  • empty fields, prefilled fields, secure fields, and fields inside scroll views or behind a keyboard
  • how often press followed by type actually fails or lands in the wrong field, and why
  • record and replay behavior for each case

If the data shows a gap that the two-step flow cannot cover, we can agree on the shape there before a new PR.

@thymikee thymikee closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants