284 Commits

Author SHA1 Message Date
Michał Pierzchała 5cea4dd0b1 feat: pass through GitHub Actions artifact install sources (#437) 2026-04-25 19:30:51 -04:00
Michał Pierzchała 4ddd29cb5c feat: add Metro reload command (#440) 2026-04-25 19:30:24 -04:00
Michał Pierzchała 6c7e8323e1 fix: support remote Android React DevTools tunnel (#438)
* 0.13.0

* fix: support remote android react devtools tunnel
2026-04-25 19:30:12 -04:00
Michał Pierzchała b0813cad84 feat: add react devtools passthrough (#435)
* feat: add react devtools passthrough

* docs: clarify react devtools passthrough

* fix: preserve react devtools global flags

* docs: add react devtools validation guidance

* docs: simplify react devtools validation notes
2026-04-24 18:54:14 -04:00
Kacper Mikołajczak 2062bffc64 feat: parametrise .ad replay scripts (#433)
* feat: parametrise .ad replay scripts

Support ${VAR} substitution with env header directives and CLI -e
overrides so flows can be reused across app variants, environments,
and devices without duplicating the script.

Precedence (high->low): CLI -e > AD_* shell env > file-local env >
built-ins (AD_PLATFORM, AD_SESSION, AD_FILENAME, AD_DEVICE,
AD_ARTIFACTS). Supports ${VAR:-default} fallback, \${ escape, and
fails with file:line on unresolved vars.

* refactor: harden .ad replay parametrisation

Tighten the parametrisation surface introduced in the feat commit after
an internal review pass:

- Reserve the AD_* namespace for built-ins. User env (file env, CLI -e,
  shell AD_VAR_*) can no longer define AD_* keys, which closes a built-in
  shadowing vector (e.g. AD_VAR_AD_SESSION).
- Change the shell-env prefix from AD_* to AD_VAR_* so unrelated CI
  secrets that happen to start with AD_ (AD_TOKEN, AD_SECRET_KEY) are
  not auto-imported into replay scripts.
- Extend the replay -u guard to also reject scripts with \${VAR}
  substitutions in any action, not just those with env directives, so
  the writer never silently drops substitutions on heal-rewrite.
- Reword DX-unfriendly regex errors ("must match /^[A-Z_]...$/" ->
  "must be uppercase letters, digits, and underscores, e.g. APP_ID").
- Docs rewrite with precedence table, three recipes, fallback/escape
  examples, and a Notes block covering replay -u limitation, remote
  daemon caveat, no nested fallback, and loud typo behaviour.
- Additional unit tests: namespace reservation on every path, shell
  prefix migration, \${VAR} round-trip preservation through
  writeReplayScript, green-path integration test with a fake invoke.

* fix: collect .ad replay shell env on the CLI, not the daemon

Review feedback (https://github.com/callstackincubator/agent-device/pull/433#discussion_r3130695225):
the daemon was reading AD_VAR_* from its own process.env, which meant
"AD_VAR_K=V agent-device replay" only worked if V was set when the
daemon started, and never worked for remote daemons.

The client now filters process.env for AD_VAR_* at request time and
ships the result as replayShellEnv on the DaemonRequest flags. The
daemon prefers the request value when present and falls back to its
own process.env for direct-daemon callers (internal tests).

Adds two integration tests pinning both paths and updates the docs
Notes block to reflect the new behaviour.

* fix: thread per-attempt artifacts dir into AD_ARTIFACTS under test

Review feedback (https://github.com/callstackincubator/agent-device/pull/433#discussion_r3130695235):
AD_ARTIFACTS is documented as available under "agent-device test", but
buildReplayBuiltinVars was only reading the raw flags.artifactsDir.
Under the default artifacts layout the flag is unset and \${AD_ARTIFACTS}
failed; when set with --artifacts-dir it pointed at the suite root, not
the resolved per-attempt directory the test runner actually writes to.

Plumb the attempt-level artifacts dir from session-test.ts through the
runReplay callback (via runReplayTestAttempt) down into the nested
replay request's flags.artifactsDir. The daemon side is unchanged -
buildReplayBuiltinVars just now sees the right value.

Extracts the nested-request flag merge into a testable helper
(buildNestedReplayFlags) to close the coverage gap between the test
harness and the replay runtime.

* refactor: DRY .ad replay parametrisation internals

- Share VAR_KEY_RE between session-replay-vars and session-replay-script
  instead of re-declaring the same /^[A-Z_][A-Z0-9_]*$/ in each.
- Fold resolveReplayFlags + resolveReplayRuntime into a single generic
  resolveStringProps<T>; the two were near-identical object-walkers.
- Un-export parseReplayEnvLine (was only used inside its own module).
- Table-drive the four "reject AD_* namespace" tests with test.each
  instead of four near-duplicate test blocks.
- Extract runReplayFixture helper for runReplayScriptFile integration
  tests; each test is now ~10 lines instead of ~30.

No behaviour change. 812 tests still green.

* docs: clarify replay built-in variables

* test: cover replay env serialization

---------

Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
2026-04-24 18:54:03 -04:00
Michał Pierzchała 22936fd628 fix: use artifacts route for daemon downloads (#434) 2026-04-24 17:52:42 -04:00
Michał Pierzchała bb24567582 fix: improve android snapshot freshness (#430)
* fix: improve android snapshot freshness

* fix: tune android snapshot freshness mitigation

* fix: keep android ref refresh best-effort
2026-04-20 11:03:25 +02:00
Michał Pierzchała 57ba479e51 fix: add screenshot max-size flag (#428) 2026-04-18 19:30:39 +02:00
Michał Pierzchała 77365ab708 refactor: simplify Android hidden-content hints (#427) 2026-04-18 19:13:22 +02:00
Michał Pierzchała ee6cc7cc5b fix: use bridge metro runtime descriptors (#425) 2026-04-17 20:01:20 +02:00
Michał Pierzchała 33083b5a86 chore: codebase cleanup pass (dedup, types, dead code, cycles) (#420)
* refactor: remove dead code and unused exports

- Delete interaction-get.ts, interaction-is.ts, interaction-selector.ts (superseded by selector-runtime dispatchers)
- Remove handleWaitCommand and its private helpers from snapshot-wait.ts (replaced by dispatchWaitViaRuntime)
- Remove unused distanceFromSafeViewportBand/isRectWithinSafeViewportBand from rect-visibility
- Trim Linux platform barrel to only the re-export still in use (snapshotLinux)

* refactor: consolidate duplicated helpers

- Move sleep() to utils/timeouts.ts; remove 6 duplicate implementations
- Use existing isApplePlatform() helper for ios||macos checks (5 sites)
- Export trimRuntimeValue from runtime-hints; drop duplicate trimRuntimeString
- Merge normalizeTextSurfaceType/normalizeType into single text-surface helper
- Remove pointless isScrollableContainerType wrapper

* refactor: consolidate accidentally-duplicated type definitions

- SnapshotDiffLine/Summary: single definition in utils/snapshot-diff, re-exported from capture-snapshot
- FindLocator: single definition in utils/finders, re-exported from client-types
- JsonRpc envelope in http-server now uses JsonRpcRequestEnvelope/JsonRpcId from contracts
- Inline 'primary'|'secondary'|'middle' literals replaced with ClickButton (internal sites only)

* refactor: strengthen weak types and fix DEVICE_IN_USE downgrade bug

- Add toAppErrorCode() validator and DEVICE_IN_USE to AppErrorCode union
- Replace 'as any' casts on wire error codes with the validator (daemon-error, daemon-client, request-router, http-server)
- Type Metro worker payload as MetroTunnelResponseMessage
- Type xctestrun plist parsing with explicit partial schema
- Narrow 'details.stderr' via typeof checks on Android error paths
- Type runner-session parseRunnerResponse with RunnerResponsePayload

Bug fix: handler emitted 'DEVICE_IN_USE' but router cast silently downgraded to
'COMMAND_FAILED' because the code was missing from AppErrorCode. Clients can now
react to same-device contention.

* refactor: collapse redundant 'ignore' comments in empty catch blocks

- Replace 16 instances of 3-line catch { // ignore } with 1-line catch {}
- Remove one self-describing 'Re-export public API' comment

Specific 'ignore shutdown races' / 'ignore malformed pid files' style comments
that name concrete failure modes are kept.

* refactor: eliminate circular dependencies by extracting shared types to leaves

Resolves all 44 cycles reported by madge. Pattern throughout: extract shared
type into a leaf module; both producer and consumer import from the leaf;
original module re-exports for API stability.

New leaf type modules:
- src/runtime-contract.ts (AgentDeviceRuntime, CommandContext, ...)
- src/metro-types.ts (MetroRuntimeHints, MetroBridgeResult, ...)
- src/commands/runtime-types.ts (CommandResult, RuntimeCommand, ...)
- src/commands/diagnostics-types.ts
- src/cli/commands/router-types.ts (ClientCommandParams, ...)
- src/core/interactor-types.ts (Interactor, BackMode, ...)
- src/platforms/ios/runner-session-types.ts (RunnerSession)
- src/utils/screenshot-diff-region-types.ts (MutableDiffRegion)
- src/daemon/handlers/record-trace-types.ts

madge --circular now reports 0 cycles (was 44). No runtime behavior changes.

* fix: preserve wire error codes verbatim (addresses codex review)

The initial weak-types pass validated wire error codes against a closed
union, silently downgrading any unknown code to COMMAND_FAILED. This
dropped signals like AMBIGUOUS_MATCH that handlers emit and clients are
documented to handle (skills/agent-device/references/exploration.md).

- Widen AppErrorCode to 'KnownAppErrorCode | (string & {})' so autocomplete
  of known codes is preserved while any wire code flows through
- toAppErrorCode now preserves any non-empty code; fallback only when
  undefined or empty
- Add AMBIGUOUS_MATCH to KnownAppErrorCode (documented public code)
- Add test coverage for preservation and fallback behavior

* refactor: address review follow-ups

- Add DEVICE_IN_USE to the batch error taxonomy in exploration.md (now
  observable by clients after earlier fix, needs agent-facing guidance)
- Delete one-line src/platforms/linux/index.ts barrel; both consumers
  (core/dispatch, daemon/handlers/snapshot-capture) now import from
  platforms/linux/snapshot directly
- Replace inline { tenantId; runId; leaseId } shapes with MetroBridgeScope
  alias at client-types, metro, and cli/commands/connection-runtime
- Consolidate remaining inline setTimeout wrappers onto utils/timeouts.ts#sleep
  (12 files, ~18 sites). Left test files and the runtime-clock aware helper
  in commands/selector-read-utils alone. Also removes the local sleepMs
  helper from daemon-client.ts.

* refactor: address low-priority review follow-ups

- daemon-client RPC error path: stringify any non-null data.code instead
  of only forwarding strings. Preserves numeric codes from hypothetical
  future proxies/servers; for first-party daemon today this is a no-op
  since handlers already emit strings.
- errors.ts: expand AppErrorCode comment to call out the exhaustiveness
  tradeoff of the '(string & {})' widening for SDK consumers.
2026-04-17 13:22:46 +02:00
Michał Pierzchała 63ab9d625c fix: propagate remote config through remote flows (#422)
* fix: propagate remote config through commands

* fix: complete remote React Native flow

* test: cover remote install source lease reuse

* fix: honor remote config session scope

* refactor: drop remote react native shortcut

* docs: simplify remote tenancy skill flow

* docs: use trusted artifact placeholders

* docs: prune remote tenancy prompt note
2026-04-17 12:26:42 +02:00
Michał Pierzchała 1b71dfee4c fix: defer remote connect lease and metro setup (#417) 2026-04-16 17:53:04 +02:00
Michał Pierzchała f0eb8c6d4f feat: add runtime admin, batch, diagnostics, and recording commands (#416)
* feat: add runtime admin and orchestration commands

* feat: add runtime diagnostics commands

* refactor: clean up runtime router surface

* refactor: remove runtime cleanup dead weight

* fix: clean up admin install temp inputs on resolve failure
2026-04-16 17:41:16 +02:00
Michał Pierzchała afcd375323 feat: add runtime system and gesture commands (#415) 2026-04-16 15:32:17 +02:00
Michał Pierzchała 2c41225b7b feat: add runtime app commands (#414) 2026-04-16 14:41:10 +02:00
Michał Pierzchała 8bcefb754a feat: add runtime command boundary (#412)
* feat: add runtime command boundary

* refactor: harden runtime command boundary

* fix: address runtime boundary review

* fix: preserve selector snapshot flags

* fix: preserve selector get and screenshot cleanup

* fix: harden runtime boundary follow-ups

* fix: close runtime parity gaps

* test: harden android replay navigation

* fix: close screenshot surface edge cases

* test: harden packaged runtime API smoke

* fix: close runtime review edge cases

* test: isolate CLI state dir in unit helpers
2026-04-16 13:03:31 +02:00
Michał Pierzchała 5868ace77b fix: optimize remote install artifact uploads (#413)
* fix: optimize remote install artifact uploads

* refactor: clean up upload client flow

* fix: fall back after direct upload failure

* docs: correct ios install source examples
2026-04-16 12:25:50 +02:00
Michał Pierzchała 364844e01d feat: add recording quality flag (#409)
* feat: add recording quality flag

* test: cover quality edge cases

* fix: scale transform translation in resize

* fix: narrow recording quality flag
2026-04-15 13:18:57 +02:00
Michał Pierzchała e99bbb526e fix: include lease scope in Metro bridge calls (#408) 2026-04-13 17:32:23 +02:00
Michał Pierzchała 39a09f95c4 feat: export Android app parsers (#406) 2026-04-13 14:11:53 +02:00
Michał Pierzchała 47a1529e98 feat: add remote connect lifecycle (#407) 2026-04-13 14:11:40 +02:00
Michał Pierzchała 17317d01ac fix: support saved screenshot diffs (#404) 2026-04-12 14:09:55 +02:00
Michał Pierzchała 3e0a7b56bb feat: enrich screenshot diff guidance (#403)
* feat: enrich screenshot diff guidance

* fix: address screenshot diff review feedback

* docs: organize screenshot diff skill guidance

* refactor: prune screenshot diff result metadata

* refactor: tighten screenshot diff readout

* refactor: generalize screenshot diff heuristics

* feat: add compact screenshot diff hints

* refactor: prune screenshot diff guidance output
2026-04-12 12:45:15 +02:00
Michał Pierzchała f4f143ced7 fix: restore helper subpath exports (#402)
* fix: restore helper subpath exports

* fix: polish helper subpath typings
2026-04-11 22:16:32 +02:00
Michał Pierzchała d63cfcd956 fix: harden executable override policy (#398) 2026-04-11 21:36:54 +02:00
Michał Pierzchała 43110aa7d3 fix: support portable zip install-source extraction (#401) 2026-04-11 21:08:09 +02:00
Michał Pierzchała 24f398c9a9 refactor: remove scrollintoview command (#400) 2026-04-11 21:07:54 +02:00
Michał Pierzchała 8e42f2e654 fix: harden public API boundaries (#399) 2026-04-11 21:01:09 +02:00
Michał Pierzchała 0fe724f252 feat: export error contract helpers (#396) 2026-04-11 20:14:46 +02:00
Michał Pierzchała 037caf749f feat: export artifact package resolver (#392) 2026-04-11 20:02:14 +02:00
Michał Pierzchała 0b76783360 feat: export install-source helpers (#393)
* feat: export install-source helpers

* fix: freeze exported archive extensions
2026-04-11 20:00:38 +02:00
Michał Pierzchała d2b02f1b93 feat: export snapshot contracts (#394) 2026-04-11 19:54:34 +02:00
Michał Pierzchała 6f13f60659 feat: export runtime transport helper (#395) 2026-04-11 19:53:24 +02:00
Michał Pierzchała 966fcb2547 feat: export finder helpers (#391) 2026-04-11 19:51:30 +02:00
Michał Pierzchała 84098be37a fix: preserve script argument whitespace (#397) 2026-04-11 19:49:54 +02:00
Michał Pierzchała 6cf63c262c feat: expose selector helper subpath (#384) 2026-04-11 19:07:42 +02:00
Michał Pierzchała ffd472a5bf feat: expose typed client command methods (#380) 2026-04-11 16:24:16 +02:00
Michał Pierzchała 60bed774c6 chore: clean up unused exports (#383) 2026-04-11 15:43:39 +02:00
Michał Pierzchała 98dc1c7def refactor: extract shared test utilities and remove redundant assertions (#382)
* Remove test assertions redundant with TypeScript static analysis

Drop assertions that merely verify unset optional properties are
undefined (a JavaScript language guarantee) and a second test block
whose only runtime value was re-checking literals just assigned to
typed variables. TypeScript's compiler already validates that these
object literals conform to the declared union types.

* fix: remove unused descriptor variable to fix noUnusedLocals

* refactor: extract shared test utilities from duplicated patterns

Introduce src/__tests__/test-utils/ with reusable device fixtures,
session factories, store factory, snapshot builders, and mocked
binary helpers. Migrate 27 test files to use these shared utilities,
eliminating duplicated DeviceInfo constants, makeSession/makeStore
helpers, snapshot node builders, and withMockedAdb/withMockedXcrun
across core, daemon, and handler tests.

Add AGENTS.md guidance to check test-utils before writing new tests.

* fix: restore public Metro type contract coverage with satisfies fixtures
2026-04-11 14:21:15 +02:00
Michał Pierzchała 20021c3d1c refactor: reduce duplication and simplify codebase (#374)
* refactor: reduce duplication and simplify codebase

Eliminate copy-pasted functions, inline error boilerplate, and repeated
patterns across daemon handlers and platform modules.

Key changes:
- Deduplicate isEnvTruthy, displayNodeLabel, roundPercent into single sources
- Extract throwDaemonError helper for client/CLI daemon response errors
- Add sessionNotFoundResponse/unsupportedOperationResponse helpers and
  adopt errorResponse() across ~30 handler files (-565 lines)
- Unify BATCH_PARENT_FLAG_KEYS/REPLAY_PARENT_FLAG_KEYS into shared
  mergeParentFlags helper in handler-utils
- Extract createLinuxToolResolver for screenshot/clipboard tool detection
- Remove stale type-sync comments from contracts.ts and metro.ts

* refactor: deeper structural simplification pass

Bigger wins from restructuring, not just mechanical dedup:

- cli.ts: move logTailStopper to try/finally (eliminates 28 duplicate
  calls), extract writeCommandCliOutput/writeLogsCliOutput/writeNetworkCliOutput
  from 350-line if/else chain, fix remaining throwDaemonError site
- session-store.ts: replace 67-line sanitizeFlags destructure/reconstruct
  with 10-line pick-from-array loop
- record-trace: extract finalizeRecordingOverlay helper, replacing 4
  copies of the telemetry+overlay block across ios/android/recording files
- Deduplicate normalizeText (finders.ts + selectors-match.ts)
- Fix isEnvTruthy to preserve whitespace-tolerant parsing (.trim())

* fix: ensure logTailStopper runs before process.exit

process.exit() does not unwind the stack, so finally blocks are
skipped. Restore explicit logTailStopper() calls before each
process.exit() to prevent leaking the background daemon log tail
process. The finally block remains as a safety net for normal
return paths.

Also refactor writeCommandCliOutput to return an exit code instead
of calling process.exit() directly, keeping the exit decision in
the caller where cleanup is visible.

* refactor: simplify daemon failure responses

* refactor: remove redundant daemon response cast
2026-04-11 12:53:53 +02:00
Michał Pierzchała be001e1906 feat: add upload cache preflight (#379) 2026-04-11 12:53:30 +02:00
Michał Pierzchała 52d9707647 feat: expose apps list in node client (#378) 2026-04-11 12:33:58 +02:00
Michał Pierzchała 937ce8f6b2 test: stabilize android emulator boot tests (#377) 2026-04-11 10:36:38 +02:00
Michał Pierzchała 897c25def8 fix: clean up metro companion workers (#376)
* fix: clean up metro companion workers

* fix: clarify metro companion lease shutdown

* test: fix installed-package metro typecheck
2026-04-11 09:38:03 +02:00
Michał Pierzchała 3c62a2b839 fix: carry remote-config run id for install-from-source (#375)
* fix: carry remote-config run id for install-from-source

* test: reuse CLI capture helper in remote-config regression
2026-04-10 20:27:34 +02:00
Michał Pierzchała be09c1d58a feat: expose bridge-facing contract and metro APIs (#373)
* feat: expose bridge-facing contract and metro APIs

* chore: address review feedback on public contract exports

* refactor: reuse public daemon contracts internally

* refactor: reuse public metro types internally

* fix: widen bridge-facing public contracts
2026-04-10 14:06:27 +02:00
Michał Pierzchała 66d65c887c refactor: expose metro and remote config node apis (#372)
* refactor: expose metro and remote config node apis

* refactor: tighten public node api surface

* refactor: tighten metro public type boundaries

* refactor: normalize remote config public profile

* refactor: make remote config parser library-owned

* refactor: share remote config parsing primitives

* refactor: avoid regex in base url normalization
2026-04-10 13:03:13 +02:00
Michał Pierzchała a4d686e686 fix: package detached worker entrypoints (#371)
* fix: package detached worker entrypoints

* refactor: rename metro companion worker entry

* chore: trim packaged smoke logging
2026-04-10 11:45:20 +02:00
Michał Pierzchała f3181a51b6 fix: auto-manage metro companion for remote runs (#370)
* fix: auto-manage metro companion for remote runs

* fix: fail fast on non-retryable metro bridge errors

* fix: scope metro companion ownership by profile

* fix: align remote close metro companion cleanup

* fix: guard metro companion shutdown reconnect

* test: ignore expected bridge reset in metro reconnect test

* chore: format, cleanup
2026-04-10 09:42:38 +02:00