@aarwitz/tapp 0.35.7 → 0.35.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tapp",
3
3
  "description": "Give Claude hands and eyes on iOS, Android, and web apps, with exploration, replayable flows, evidence, and deterministic CI gates.",
4
- "version": "0.35.7",
4
+ "version": "0.35.9",
5
5
  "author": {
6
6
  "name": "Aaron Horowitz",
7
7
  "url": "https://github.com/aarwitz"
@@ -24,7 +24,7 @@
24
24
  "command": "npx",
25
25
  "args": [
26
26
  "-y",
27
- "@aarwitz/tapp@0.35.7",
27
+ "@aarwitz/tapp@0.35.9",
28
28
  "mcp"
29
29
  ],
30
30
  "cwd": "${CLAUDE_PROJECT_DIR}"
@@ -12,6 +12,17 @@ import XCTest
12
12
  /// - testDumpUITree: One-shot accessibility tree dump
13
13
  /// - testTapAtCoordinate / testTapById: Single action for engine control
14
14
  /// - testScreenshot: Capture and attach a screenshot
15
+ extension XCUIElementQuery {
16
+ /// XCUITest raises NSInternalInconsistencyException for an identifier subscript longer than
17
+ /// 128 characters, which ends the whole run. Longer text is matched with a predicate on
18
+ /// label, value, title or identifier instead, so it is found like short text.
19
+ func byText(_ text: String) -> XCUIElement {
20
+ if text.count <= 128 { return self[text] }
21
+ let predicate = NSPredicate(format: "label == %@ OR value == %@ OR title == %@ OR identifier == %@", text, text, text, text)
22
+ return matching(predicate).firstMatch
23
+ }
24
+ }
25
+
15
26
  class ExplorerTests: XCTestCase {
16
27
 
17
28
  private struct InputDescriptor {
@@ -154,7 +165,7 @@ class ExplorerTests: XCTestCase {
154
165
  addUIInterruptionMonitor(withDescription: "System Alert") { alert in
155
166
  let allowLabels = ["Allow", "Allow While Using App", "OK", "Continue", "Allow Full Access"]
156
167
  for label in allowLabels {
157
- let btn = alert.buttons[label]
168
+ let btn = alert.buttons.byText(label)
158
169
  if btn.exists {
159
170
  btn.tap()
160
171
  return true
@@ -229,7 +240,7 @@ class ExplorerTests: XCTestCase {
229
240
  app.links, app.switches, app.textFields
230
241
  ]
231
242
  for query in queries {
232
- let element = query[identifier]
243
+ let element = query.byText(identifier)
233
244
  if element.exists && element.isHittable {
234
245
  if !waitForEnabled(element) {
235
246
  print("OCQA_ACTION:{\"type\":\"tap\",\"identifier\":\"\(identifier)\",\"status\":\"disabled\"}")
@@ -282,14 +293,14 @@ class ExplorerTests: XCTestCase {
282
293
  }
283
294
  let identifier = resolve("OCQA_TYPE_ID")
284
295
  if !identifier.isEmpty {
285
- let field = app.textFields[identifier]
296
+ let field = app.textFields.byText(identifier)
286
297
  if field.exists {
287
298
  field.tap()
288
299
  field.typeText(text)
289
300
  print("OCQA_ACTION:{\"type\":\"typeText\",\"identifier\":\"\(identifier)\"}")
290
301
  return
291
302
  }
292
- let secure = app.secureTextFields[identifier]
303
+ let secure = app.secureTextFields.byText(identifier)
293
304
  if secure.exists {
294
305
  secure.tap()
295
306
  secure.typeText(text)
@@ -558,9 +569,14 @@ class ExplorerTests: XCTestCase {
558
569
  private func sessionTapById(_ identifier: String) -> String {
559
570
  var existedButNotHittable = false
560
571
  var existedButDisabled = false
572
+ var existedButCovered = false
561
573
  func tryTap(_ el: XCUIElement) -> Bool {
562
574
  guard el.exists else { return false }
563
575
  if !waitForEnabled(el) { existedButDisabled = true; return false }
576
+ // TM-897: isHittable is true for an element only partly under the tab bar, and the
577
+ // touch at its centre then lands on the tab bar. Treat that as not reachable so the
578
+ // scroll below runs, and a tap that still cannot clear the bar fails, never passes.
579
+ if el.isHittable && coveredByTabBar(el) { existedButCovered = true; existedButNotHittable = true; return false }
564
580
  if el.isHittable { el.tap(); return true }
565
581
  // Often covered by the keyboard (a submit button below filled fields) — dismiss + retry,
566
582
  // like Playwright auto-scrolls a target into view.
@@ -570,7 +586,18 @@ class ExplorerTests: XCTestCase {
570
586
  return false
571
587
  }
572
588
  let queries: [XCUIElementQuery] = [app.buttons, app.staticTexts, app.cells, app.links, app.switches, app.textFields, app.secureTextFields, app.textViews]
573
- for query in queries where tryTap(query[identifier]) { return "ok" }
589
+ // TM-922: enumerate rather than subscript. subscripting a query by identifier resolves to ONE element, and
590
+ // when a screen hidden under a full-screen cover shares the identifier XCTest aborts the run
591
+ // with "Multiple matching elements found". Enumerating lets the visible one win.
592
+ lastAmbiguity = ""
593
+ func tryTapNamed(_ query: XCUIElementQuery) -> Bool {
594
+ guard let el = preferVisible(query.matching(identifier: identifier).allElementsBoundByIndex, name: identifier) else { return false }
595
+ return tryTap(el)
596
+ }
597
+ for query in queries {
598
+ if tryTapNamed(query) { return "ok" }
599
+ if !lastAmbiguity.isEmpty { return "ambiguous" }
600
+ }
574
601
  // Exact label, then a forgiving case-insensitive "contains" match so callers can tap by the
575
602
  // visible text they see in the tree without an exact accessibility id.
576
603
  let exactMatches = app.descendants(matching: .any).matching(NSPredicate(format: "label == %@", identifier)).allElementsBoundByIndex
@@ -584,7 +611,10 @@ class ExplorerTests: XCTestCase {
584
611
  for _ in 0..<3 {
585
612
  app.swipeUp()
586
613
  Thread.sleep(forTimeInterval: 0.25)
587
- for query in queries where tryTap(query[identifier]) { return "ok" }
614
+ for query in queries {
615
+ if tryTapNamed(query) { return "ok" }
616
+ if !lastAmbiguity.isEmpty { return "ambiguous" }
617
+ }
588
618
  let scrolledExact = app.descendants(matching: .any).matching(NSPredicate(format: "label == %@", identifier)).allElementsBoundByIndex
589
619
  for match in scrolledExact where tryTap(match) { return "ok" }
590
620
  let scrolledContains = app.descendants(matching: .any).matching(NSPredicate(format: "label CONTAINS[c] %@", identifier)).allElementsBoundByIndex
@@ -595,12 +625,53 @@ class ExplorerTests: XCTestCase {
595
625
  // label) — "Password" must reach the secureTextField or a later `type` lands in whatever
596
626
  // field still has keyboard focus.
597
627
  if let field = resolveFieldByHint(identifier), tryTap(field) { return "ok" }
628
+ if !lastAmbiguity.isEmpty { return "ambiguous" }
598
629
  // "disabled" outranks the others: the control was found and refused to act, which
599
630
  // is a different answer from "it is not here" and needs a different fix.
600
631
  if existedButDisabled { return "disabled" }
632
+ if existedButCovered { return "covered" }
601
633
  return existedButNotHittable ? "not_hittable" : "not_found"
602
634
  }
603
635
 
636
+ /// TM-922: what the last lookup could not choose between, in plain words. Empty when it chose.
637
+ private var lastAmbiguity = ""
638
+
639
+ /// Of several elements sharing one name, the one the person can see. A box on a screen hidden
640
+ /// under a full-screen cover keeps its accessibility identifier but is not hittable, so the
641
+ /// visible one wins. With none visible the first is returned (the caller reports why it can't
642
+ /// be reached); with two visible at different places this sets `lastAmbiguity` and returns nil.
643
+ private func preferVisible(_ matches: [XCUIElement], name: String) -> XCUIElement? {
644
+ let live = matches.filter { $0.exists }
645
+ guard live.count > 1 else { return live.first }
646
+ let visible = live.filter { $0.isHittable }
647
+ if visible.count == 1 { return visible[0] }
648
+ if visible.isEmpty { return live[0] }
649
+ var distinct: [XCUIElement] = []
650
+ for el in visible where !distinct.contains(where: { $0.frame == el.frame }) { distinct.append(el) }
651
+ if distinct.count == 1 { return distinct[0] }
652
+ let described = distinct.map { el -> String in
653
+ let f = el.frame
654
+ return "‘\(fieldDesc(el))’ at \(Int(f.minX)),\(Int(f.minY))"
655
+ }.joined(separator: " and ")
656
+ lastAmbiguity = "‘\(name)’ matches \(distinct.count) boxes that are all on screen — \(described) — so tapp cannot tell which one you mean; give the one you want a more specific name"
657
+ return nil
658
+ }
659
+
660
+ /// True when the point a tap would touch (the element's centre) sits under the app's tab bar
661
+ /// and the element is not itself a tab bar item (TM-897).
662
+ private func coveredByTabBar(_ el: XCUIElement) -> Bool {
663
+ let bar = app.tabBars.firstMatch
664
+ guard bar.exists, bar.isHittable, let elFrame = (try? el.snapshot())?.frame else { return false }
665
+ let barFrame = bar.frame
666
+ guard barFrame.height > 0,
667
+ barFrame.contains(CGPoint(x: elFrame.midX, y: elFrame.midY)) else { return false }
668
+ let isTabItem = bar.descendants(matching: .any).allElementsBoundByIndex.contains {
669
+ guard let f = (try? $0.snapshot())?.frame else { return false }
670
+ return f == elFrame
671
+ }
672
+ return !isTabItem
673
+ }
674
+
604
675
  /// Resolve a text/secure field by accessibility id, label, or placeholder (exact first, then
605
676
  /// case-insensitive contains), then by semantic keyword ("password" → first secure field;
606
677
  /// "email"/"username" → first plain text field). Subscript queries miss placeholder-named
@@ -632,10 +703,18 @@ class ExplorerTests: XCTestCase {
632
703
  // highest on screen, so a field whose label happens to equal the hint would beat the
633
704
  // field actually named that — precedence the identifier subscripts used to provide, and
634
705
  // which was lost when this resolver moved in front of them (caught in review, TM-496).
635
- if let match = described.first(where: { $0.identifier == h }) { return match.element }
636
- if let match = described.first(where: { $0.label == h }) { return match.element }
637
- if let match = described.first(where: { $0.placeholder == h }) { return match.element }
638
- if let match = described.first(where: { "\($0.identifier) \($0.label) \($0.placeholder)".contains(h) }) { return match.element }
706
+ // TM-922: a tier can match several boxes (a sign-in screen still sitting under a full-screen
707
+ // cover). The visible one wins; two visible ones is reported, not guessed at.
708
+ lastAmbiguity = ""
709
+ let tiers: [((identifier: String, label: String, placeholder: String)) -> Bool] = [
710
+ { $0.identifier == h }, { $0.label == h }, { $0.placeholder == h },
711
+ { "\($0.identifier) \($0.label) \($0.placeholder)".contains(h) },
712
+ ]
713
+ for tier in tiers {
714
+ let hits = described.filter { tier(($0.identifier, $0.label, $0.placeholder)) }.map { $0.element }
715
+ if hits.isEmpty { continue }
716
+ return preferVisible(hits, name: hint)
717
+ }
639
718
  if h.contains("password") {
640
719
  let secure = app.secureTextFields.firstMatch
641
720
  if secure.exists { return secure }
@@ -679,7 +758,7 @@ class ExplorerTests: XCTestCase {
679
758
  // SwiftUI apps don't resign focus on background taps by default.
680
759
  let kb = app.keyboards.firstMatch
681
760
  for label in ["Done", "done", "Return", "return", "Go", "go"] {
682
- let key = kb.buttons[label]
761
+ let key = kb.buttons.byText(label)
683
762
  if key.exists && key.isHittable {
684
763
  key.tap()
685
764
  Thread.sleep(forTimeInterval: 0.4)
@@ -716,7 +795,7 @@ class ExplorerTests: XCTestCase {
716
795
  let deadline = Date().addingTimeInterval(Double(timeoutMs) / 1000.0)
717
796
  repeat {
718
797
  let queries: [XCUIElementQuery] = [app.buttons, app.staticTexts, app.cells, app.links, app.switches, app.textFields, app.otherElements]
719
- for q in queries where q[target].exists { return true }
798
+ for q in queries where q.byText(target).exists { return true }
720
799
  if app.descendants(matching: .any).matching(NSPredicate(format: "label == %@ OR label CONTAINS[c] %@", target, target)).firstMatch.exists { return true }
721
800
  Thread.sleep(forTimeInterval: 0.3)
722
801
  } while Date() < deadline
@@ -737,7 +816,7 @@ class ExplorerTests: XCTestCase {
737
816
  // submits, and append-on-retry turns "Lemonade" into "LemonadeLemonade" — a malformed
738
817
  // credential the server rejects with no visible cause.
739
818
  if let id = id, !id.isEmpty {
740
- // Enumerate before subscripting. `app.textFields[hint]` builds a query against
819
+ // Enumerate before subscripting. `app.textFields.byText(hint)` builds a query against
741
820
  // IDENTIFIERS, and resolving one of those against a SwiftUI `TextField(axis:
742
821
  // .vertical)` raises "Failed to get matching snapshot … Automation type mismatch:
743
822
  // computed TextField from legacy attrib", which aborts the whole run instead of
@@ -748,7 +827,8 @@ class ExplorerTests: XCTestCase {
748
827
  guard replaceText(on: field, with: text) else { return false }
749
828
  lastTypedInto = fieldDesc(field); return true
750
829
  }
751
- for field in [app.textFields[id], app.secureTextFields[id], app.textViews[id]] where field.exists {
830
+ if !lastAmbiguity.isEmpty { lastTypeFailure = lastAmbiguity; return false }
831
+ for field in [app.textFields.byText(id), app.secureTextFields.byText(id), app.textViews.byText(id)] where field.exists {
752
832
  guard replaceText(on: field, with: text) else { return false }
753
833
  lastTypedInto = fieldDesc(field); return true
754
834
  }
@@ -823,7 +903,7 @@ class ExplorerTests: XCTestCase {
823
903
  // iOS offers to save the password after a successful sign-in — never wanted
824
904
  // in QA; decline so login lands on the app's real post-auth screen.
825
905
  for label in ["Not Now", "Not now", "Never", "Never for This Website"] {
826
- let b = app.buttons[label]
906
+ let b = app.buttons.byText(label)
827
907
  if b.exists && b.isHittable {
828
908
  b.tap()
829
909
  waitForAnimationsToSettle()
@@ -943,7 +1023,7 @@ class ExplorerTests: XCTestCase {
943
1023
  }
944
1024
  // 1. An explicit dismissal control, in the app and in SpringBoard (extensions live there).
945
1025
  for label in ["Close", "Cancel", "Done", "Dismiss"] {
946
- for candidate in [app.buttons[label], XCUIApplication(bundleIdentifier: "com.apple.springboard").buttons[label]] {
1026
+ for candidate in [app.buttons.byText(label), XCUIApplication(bundleIdentifier: "com.apple.springboard").buttons.byText(label)] {
947
1027
  if candidate.exists && candidate.isHittable {
948
1028
  candidate.tap()
949
1029
  waitForUIStability(timeout: 1.5)
@@ -975,7 +1055,7 @@ class ExplorerTests: XCTestCase {
975
1055
  private func tapSystemSheetButton(_ identifier: String) -> Bool {
976
1056
  let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
977
1057
  for query in [springboard.buttons, springboard.staticTexts] {
978
- let element = query[identifier]
1058
+ let element = query.byText(identifier)
979
1059
  if element.exists && element.isHittable { element.tap(); return true }
980
1060
  }
981
1061
  let matches = springboard.descendants(matching: .any)
@@ -1206,7 +1286,9 @@ class ExplorerTests: XCTestCase {
1206
1286
  // whatever guards it.
1207
1287
  switch tapStatus {
1208
1288
  case "disabled": detail = "‘\(target)’ is on screen but disabled — an earlier step has not met whatever enables it"
1289
+ case "covered": detail = "‘\(target)’ is on screen but sits under the tab bar, and scrolling did not clear it — a tap there would open a tab instead"
1209
1290
  case "not_hittable": detail = "‘\(target)’ exists but could not be reached, even after dismissing the keyboard and scrolling"
1291
+ case "ambiguous": detail = lastAmbiguity
1210
1292
  default: detail = "could not find ‘\(target)’ on this screen"
1211
1293
  }
1212
1294
  let alertButtons = systemAlertButtonLabels()
@@ -1229,6 +1311,13 @@ class ExplorerTests: XCTestCase {
1229
1311
  if detail.lowercased().contains("accessing the keychain") {
1230
1312
  detail += " — simulator keychain is stale; `xcrun simctl erase <udid>` (or Device ▸ Erase All Content and Settings) usually fixes Firebase keychain errors"
1231
1313
  }
1314
+ } else if let pressed = handleSystemAlert(mode: "dismiss") {
1315
+ // TM-996: iOS's own "Save Password?" offer follows a real sign-in
1316
+ // unpredictably — only some runs, regardless of the flow's own `alerts:`
1317
+ // setting, since no flow author expects it. Checked here, once, right
1318
+ // after login succeeds, rather than asking every flow to anticipate it.
1319
+ let loginAlertNote = "a system alert was dismissed after signing in: pressed ‘\(escapeJSON(pressed))’"
1320
+ alertNote = alertNote.isEmpty ? loginAlertNote : "\(alertNote); \(loginAlertNote)"
1232
1321
  }
1233
1322
  case "swipe":
1234
1323
  switch target.lowercased() { case "down": app.swipeDown(); case "left": app.swipeLeft(); case "right": app.swipeRight(); default: app.swipeUp() }
@@ -1238,6 +1327,23 @@ class ExplorerTests: XCTestCase {
1238
1327
  // screen and fail somewhere unrelated.
1239
1328
  status = sessionBack() == "ok" ? "pass" : "fail"
1240
1329
  if status == "fail" { detail = "back did not navigate: no back control on this screen, or tapping it did not change the screen\(visibleLabelsHint())" }
1330
+ case "open_url":
1331
+ // A journey starting from an email link ("tap the sign-in link in your receipt")
1332
+ // opens it the way the system would hand it to the app under test — not a debug
1333
+ // hook or a shell wrapper that writes a token into the app's defaults before launch.
1334
+ if let url = URL(string: target), !target.isEmpty {
1335
+ if #available(iOS 16.4, *) {
1336
+ XCUIDevice.shared.system.open(url)
1337
+ waitForUIStability(timeout: 1.5)
1338
+ status = "pass"
1339
+ } else {
1340
+ status = "fail"
1341
+ detail = "open_url needs iOS 16.4 or later on the simulator/device running this Flow"
1342
+ }
1343
+ } else {
1344
+ status = "fail"
1345
+ detail = "‘\(target)’ is not a URL open_url can open"
1346
+ }
1241
1347
  case "wait":
1242
1348
  Thread.sleep(forTimeInterval: Double(timeoutMs) / 1000.0)
1243
1349
  case "wait_for":
@@ -1350,7 +1456,7 @@ class ExplorerTests: XCTestCase {
1350
1456
  private func elementPresent(_ target: String) -> Bool {
1351
1457
  guard !target.isEmpty else { return false }
1352
1458
  let queries: [XCUIElementQuery] = [app.buttons, app.staticTexts, app.cells, app.links, app.switches, app.textFields, app.otherElements]
1353
- for q in queries where q[target].exists { return true }
1459
+ for q in queries where q.byText(target).exists { return true }
1354
1460
  return app.descendants(matching: .any).matching(NSPredicate(format: "label == %@ OR label CONTAINS[c] %@", target, target)).firstMatch.exists
1355
1461
  }
1356
1462
 
@@ -1557,7 +1663,7 @@ class ExplorerTests: XCTestCase {
1557
1663
  if allSecureFields.count > 1 {
1558
1664
  let existingAccountLabels = ["Back to login", "Back to Login", "Already have an account?", "Sign in instead", "Log in instead"]
1559
1665
  for label in existingAccountLabels {
1560
- let control = app.buttons[label].exists ? app.buttons[label] : app.staticTexts[label]
1666
+ let control = app.buttons.byText(label).exists ? app.buttons.byText(label) : app.staticTexts.byText(label)
1561
1667
  if control.exists && control.isHittable {
1562
1668
  control.tap()
1563
1669
  print("OCQA_STATE:login_preamble_switched_from_signup")
@@ -1651,13 +1757,13 @@ class ExplorerTests: XCTestCase {
1651
1757
  let loginLabels = ["Log In", "Login", "Sign In", "Sign in", "log in", "LOG IN", "SIGN IN"]
1652
1758
  var tappedLogin = false
1653
1759
  for label in loginLabels {
1654
- let btn = app.buttons[label]
1760
+ let btn = app.buttons.byText(label)
1655
1761
  if btn.exists && btn.isHittable {
1656
1762
  btn.tap()
1657
1763
  tappedLogin = true
1658
1764
  break
1659
1765
  }
1660
- let st = app.staticTexts[label]
1766
+ let st = app.staticTexts.byText(label)
1661
1767
  if st.exists && st.isHittable {
1662
1768
  st.tap()
1663
1769
  tappedLogin = true
@@ -1673,7 +1779,7 @@ class ExplorerTests: XCTestCase {
1673
1779
  let continueLabels = ["Continue", "Next", "Submit", "Proceed", "Get Started"]
1674
1780
  var tappedContinue = false
1675
1781
  for label in continueLabels {
1676
- let btn = app.buttons[label]
1782
+ let btn = app.buttons.byText(label)
1677
1783
  if btn.exists && btn.isHittable {
1678
1784
  btn.tap()
1679
1785
  tappedContinue = true
@@ -1691,7 +1797,7 @@ class ExplorerTests: XCTestCase {
1691
1797
  passFieldAfter.typeText(preamblePassword)
1692
1798
  Thread.sleep(forTimeInterval: 0.3)
1693
1799
  for label in loginLabels + continueLabels {
1694
- let btn = app.buttons[label]
1800
+ let btn = app.buttons.byText(label)
1695
1801
  if btn.exists && btn.isHittable {
1696
1802
  btn.tap()
1697
1803
  print("OCQA_STATE:login_preamble_two_step_submitted")
@@ -1721,7 +1827,7 @@ class ExplorerTests: XCTestCase {
1721
1827
  print("OCQA_STATE:otp_entered")
1722
1828
  Thread.sleep(forTimeInterval: 0.3)
1723
1829
  for label in ["Verify", "Continue", "Submit", "Confirm"] {
1724
- let btn = app.buttons[label]
1830
+ let btn = app.buttons.byText(label)
1725
1831
  if btn.exists && btn.isHittable { btn.tap(); break }
1726
1832
  }
1727
1833
  Thread.sleep(forTimeInterval: 2.0)
@@ -1751,7 +1857,7 @@ class ExplorerTests: XCTestCase {
1751
1857
  let startupAlert = XCUIApplication(bundleIdentifier: "com.apple.springboard").alerts.firstMatch
1752
1858
  if startupAlert.exists {
1753
1859
  for label in ["Allow While Using App", "Allow Once", "OK", "Allow", "Don't Allow"] {
1754
- let button = startupAlert.buttons[label]
1860
+ let button = startupAlert.buttons.byText(label)
1755
1861
  if button.exists && button.isHittable {
1756
1862
  button.tap()
1757
1863
  waitForAnimationsToSettle()
@@ -3415,7 +3521,7 @@ class ExplorerTests: XCTestCase {
3415
3521
  }
3416
3522
  var tappedLabel: String? = nil
3417
3523
  for label in candidates {
3418
- let btn = app.buttons[label]
3524
+ let btn = app.buttons.byText(label)
3419
3525
  if btn.exists && btn.isHittable {
3420
3526
  btn.tap()
3421
3527
  Thread.sleep(forTimeInterval: 0.5)
@@ -3817,7 +3923,7 @@ class ExplorerTests: XCTestCase {
3817
3923
  let deadline = Date().addingTimeInterval(max(0, timeoutSeconds))
3818
3924
  repeat {
3819
3925
  for query in [app.buttons, app.cells, app.links, app.staticTexts] {
3820
- let el = query[trimmed]
3926
+ let el = query.byText(trimmed)
3821
3927
  if el.exists && el.isHittable { el.tap(); return true }
3822
3928
  }
3823
3929
  let exact = app.descendants(matching: .any).matching(NSPredicate(format: "label == %@", trimmed)).allElementsBoundByIndex
@@ -4083,9 +4189,9 @@ class ExplorerTests: XCTestCase {
4083
4189
 
4084
4190
  private func resolveTextElement(for element: SimpleElement, in app: XCUIApplication) -> XCUIElement? {
4085
4191
  if !element.identifier.isEmpty {
4086
- let tf = app.textFields[element.identifier]
4192
+ let tf = app.textFields.byText(element.identifier)
4087
4193
  if tf.exists { return tf }
4088
- let stf = app.secureTextFields[element.identifier]
4194
+ let stf = app.secureTextFields.byText(element.identifier)
4089
4195
  if stf.exists { return stf }
4090
4196
  }
4091
4197
 
@@ -4306,7 +4412,7 @@ class ExplorerTests: XCTestCase {
4306
4412
  }
4307
4413
  // Try common dismiss buttons (expanded set)
4308
4414
  for label in ["Close", "Cancel", "Done", "Dismiss", "Back", "X", "close"] {
4309
- let btn = app.buttons[label]
4415
+ let btn = app.buttons.byText(label)
4310
4416
  if btn.exists && btn.isHittable {
4311
4417
  btn.tap()
4312
4418
  Thread.sleep(forTimeInterval: 0.5)
package/bin/tapp.js CHANGED
@@ -465,7 +465,7 @@ function safeCommandUsage(verb) {
465
465
  baseline: "tapp ci baseline [repo] [--platform PLATFORM] [--target NAME] [--from GATE.json] [--replace]",
466
466
  ci: "tapp ci ...\ntapp ci install [repo] [--out FILE] [--manifest FILE] [--dry-run] [--replace]\ntapp ci baseline [repo] [--platform PLATFORM] [--target NAME] [--from GATE.json] [--replace]",
467
467
  actor: "tapp plan actor set NAME --email-env ENV --password-env ENV [--replace] [--project-dir DIR]\ntapp plan actor list [repo]",
468
- app: "tapp app [repo] [--no-open] [--port PORT]",
468
+ app: "tapp app [repo] [--no-open] [--port PORT] [--connect [https://app.runtapp.com]]\n --connect: drive this machine from the hosted Studio in your browser; everything still runs here",
469
469
  report: "tapp report [captureId|latest]\n --journeys: list the journeys you own and how each one's last check went (exit 1 if any is failing)\n Add --studio https://app.runtapp.com (or $TAPP_STUDIO) with a token from the Studio's “Your coding agent” card ($TAPP_TOKEN) to ask your hosted Studio.",
470
470
  feedback: "tapp feedback \"short title\" [--body TEXT|--body-file FILE] [--type bug|idea|question] [--capture ID|latest|none] [--as human] [--submit] [--json]\n Drafts a public GitHub issue on aarwitz/tapp about tapp itself; --submit files it with the authenticated gh CLI.\n Exit codes: 0 drafted or filed · 1 gh submission failed · 2 usage error",
471
471
  audit: "tapp explore --read-only <url> [<url>...] [--urls FILE] [--pages N] [--delay MS] [--links N] [--json [FILE]] [--no-capture] [--device NAME] [--viewport WxH]\n Read-only: renders each page and reads it, never clicks — safe to point at production or a site you do not own.\n Finds dead controls, broken images/assets/links, 5xx/failed requests, JS exceptions, mixed content, horizontal overflow.\n --pages N crawls same-origin links (robots.txt honoured, --delay between pages). Writes a capture with screenshots, evidence and report.html.\n Exit codes: 0 nothing broken · 1 defects found · 2 usage/infrastructure",
@@ -1488,7 +1488,7 @@ switch (command) {
1488
1488
  break;
1489
1489
  }
1490
1490
  if (!["run", "validate"].includes(verb) || !flowPath) {
1491
- console.error("usage: tapp validate --example\n tapp flow steps [--json]\n tapp run <flow.yml|glob> [...more] [--var NAME=VALUE ...] [--platform ios|android|web] [--actor NAME] [--email VALUE] [--password VALUE] [--url URL] [--app-id ID] [--apk FILE] [--serial ID] [--record out.mp4 [--hold 3s]]\n tapp validate <flow.yml|glob> [...more]\n Several Flows (or a glob) run in sequence and print one line per Flow; exit 1 if any failed.");
1491
+ console.error("usage: tapp validate --example\n tapp flow steps [--json]\n tapp run <flow.yml|glob> [...more] [--var NAME=VALUE ...] [--platform ios|android|web] [--actor NAME] [--email VALUE] [--password VALUE] [--url URL] [--app-id ID] [--apk FILE] [--serial ID] [--record out.mp4 [--hold 3s]] [--no-report]\n tapp validate <flow.yml|glob> [...more]\n Several Flows (or a glob) run in sequence and print one line per Flow; exit 1 if any failed.");
1492
1492
  process.exit(2);
1493
1493
  }
1494
1494
  // Several Flows in one command (field issue #9): the shell usually expands the glob, but a
@@ -1722,6 +1722,21 @@ switch (command) {
1722
1722
  const evidenceWritten = fs.existsSync(evidenceDir) && fs.readdirSync(evidenceDir).length > 0;
1723
1723
  if (evidenceWritten) console.log(`\nEvidence: ${evidenceDir}`);
1724
1724
  else console.error("\n⚠️ Evidence unavailable — the platform runner did not write any artifacts for this Flow run.");
1725
+ // A machine linked to an account reports how the journey went — the name and the result,
1726
+ // never the Flow, a credential or a screenshot (ADR-0011 §4). The same rule as the Studio on
1727
+ // this machine, so an iOS or Android journey run from a terminal shows on the account too.
1728
+ // `--no-report` keeps one run to itself; a Studio that cannot be reached never fails the run.
1729
+ if (flags["no-report"] !== true) {
1730
+ const { studioLinkFor, reportStudioJourney, flowResultFromLog } = await import(path.join(packageRoot, "mcp-server", "src", "studio-client.js"));
1731
+ const link = studioLinkFor();
1732
+ if (link) {
1733
+ const verdict = flowResultFromLog(fs.existsSync(flowLog) ? fs.readFileSync(flowLog, "utf8") : "") || {};
1734
+ try {
1735
+ await reportStudioJourney(link, { name: flow.name || path.basename(flowPath, path.extname(flowPath)), platform, url: flow.url || "", steps: (flow.steps || []).length, machine: os.hostname(), passed: verdict.passed ?? result.status === 0, executed: verdict.executed ?? 0, total: verdict.total ?? (flow.steps || []).length, failed: verdict.failed ?? 0 });
1736
+ console.log(`Reported to ${link.origin}${link.email ? ` as ${link.email}` : ""}`);
1737
+ } catch (error) { console.error(`⚠️ Could not report to ${link.origin}: ${error.message}`); }
1738
+ }
1739
+ }
1725
1740
  await pruneEvidenceQuietly();
1726
1741
  process.exit(result.status ?? 1);
1727
1742
  }
@@ -2081,6 +2096,16 @@ switch (command) {
2081
2096
  + `${usage.oldestMs ? `, oldest ${formatAge(Date.now() - usage.oldestMs)}` : ""} · ${window}`);
2082
2097
  }
2083
2098
 
2099
+ // Evidence an older Tapp wrote into its own source checkout (TM-651): the clearing-out above
2100
+ // never looks there, so it stays until someone deletes it. Mentioned once it exists.
2101
+ const repoCaptures = path.join(packageRoot, "captures");
2102
+ const stray = evidenceUsage({ root: repoCaptures });
2103
+ report.strayEvidence = stray.runs ? { path: repoCaptures, runs: stray.runs, bytes: stray.bytes } : null;
2104
+ if (stray.runs) {
2105
+ say(` ⚠️ Old evidence in the Tapp checkout — ${formatStorage(stray.bytes)} in ${stray.runs} run${stray.runs === 1 ? "" : "s"} at ${repoCaptures}`
2106
+ + ` · never cleared automatically; Tapp no longer writes there, so delete it once: rm -rf "${repoCaptures}"`);
2107
+ }
2108
+
2084
2109
  say("\n Platforms:");
2085
2110
  if (process.platform === "darwin") {
2086
2111
  const xcode = run("xcode-select", ["-p"]);
@@ -2454,6 +2479,12 @@ switch (command) {
2454
2479
  // there is no way to offer them safely to an anonymous visitor on a shared machine.
2455
2480
  const publicAccess = flags.public === true;
2456
2481
  const publicOrigin = typeof flags.origin === "string" ? flags.origin : "";
2482
+ // --connect: this runtime is driven from app.runtapp.com (or another hosted Studio) in the
2483
+ // browser, instead of from its own page. The hosted page is opened with this runtime's
2484
+ // address and launch secret in the URL fragment, which never reaches the hosted server.
2485
+ const connectOrigin = flags.connect === true ? "https://app.runtapp.com" : typeof flags.connect === "string" ? flags.connect.replace(/\/$/, "") : "";
2486
+ if (connectOrigin && publicAccess) { console.error("❌ --connect is for a Studio on your own machine, not a --public one"); process.exit(2); }
2487
+ if (connectOrigin && !/^https?:\/\/[^\s/]+$/.test(connectOrigin)) { console.error("❌ --connect needs a Studio origin like https://app.runtapp.com"); process.exit(2); }
2457
2488
  // https for anything real; plain http on loopback so the public mode can be dry-run locally
2458
2489
  // before a tunnel or TLS terminator is in front of it.
2459
2490
  const localOrigin = /^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\])(?::\d{1,5})?$/.test(publicOrigin);
@@ -2465,10 +2496,11 @@ switch (command) {
2465
2496
  const { startBrowserProduct } = await import(path.join(packageRoot, "mcp-server", "src", "browser-product.js"));
2466
2497
  const product = await startBrowserProduct({
2467
2498
  projectDir, port,
2468
- launch: !publicAccess && flags.open !== false && flags["no-open"] !== true,
2499
+ launch: !publicAccess && !connectOrigin && flags.open !== false && flags["no-open"] !== true,
2469
2500
  // A loopback origin is a trial of the public Studio on your own machine; pinning its
2470
2501
  // browser to public addresses would stop it reaching the very thing you are trying.
2471
2502
  ...(publicAccess ? { publicAccess: true, publicOrigin, publicEgressOnly: !localOrigin } : {}),
2503
+ ...(connectOrigin ? { connectOrigin } : {}),
2472
2504
  });
2473
2505
  if (publicAccess) {
2474
2506
  console.log(`Tapp · public Studio for ${publicOrigin}`);
@@ -2476,6 +2508,12 @@ switch (command) {
2476
2508
  console.log("Anonymous visitors may audit a public website read-only. Repositories, live");
2477
2509
  console.log("sessions and the release gate require an authenticated local session.");
2478
2510
  console.log(localOrigin ? "Local trial: browser egress is not pinned, so this can reach services on this machine." : "Browser egress is pinned to public addresses; private ranges are refused.");
2511
+ } else if (connectOrigin) {
2512
+ console.log(`Tapp · this machine, driven from ${connectOrigin}`);
2513
+ console.log(`Open: ${product.connectUrl}`);
2514
+ console.log(`If that page cannot reach this machine (some browsers refuse), open it directly: ${product.launchUrl}`);
2515
+ console.log("Everything still runs here; press Ctrl-C to stop.");
2516
+ if (flags.open !== false && flags["no-open"] !== true) product.openConnect();
2479
2517
  } else {
2480
2518
  console.log(`Tapp · ${product.root || "choose a local folder or GitHub repository in the browser"}`);
2481
2519
  console.log(`Open: ${product.launchUrl}`);
package/browser/app.css CHANGED
@@ -477,6 +477,12 @@ dialog::backdrop { background:rgba(0,0,0,.6); }
477
477
  .prompt-suggestions button:hover { background:var(--tapp-panel); }
478
478
  .prompt-suggestions button span { font-size:16px; text-align:center; } .prompt-suggestions button b { font-weight:600; font-family:var(--tapp-font-mono); font-size:12.5px; white-space:nowrap; } .prompt-suggestions button small { color:var(--tapp-text-faint); font-size:12.5px; }
479
479
  .prompt-note { text-align:center; color:var(--tapp-text-faint); font-size:12px; margin:8px 0 0; }
480
+ #business-results { display:grid; gap:10px; margin:12px 0; }
481
+ #business-results p { margin:0; }
482
+ .business-match { display:flex; flex-wrap:wrap; gap:6px 12px; align-items:center; border-top:1px solid var(--tapp-border); padding:10px 0; }
483
+ .business-match strong { flex:1 1 60%; }
484
+ .business-match small { display:block; font-weight:400; }
485
+ .business-match button { overflow-wrap:anywhere; }
480
486
  .sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
481
487
 
482
488
  /* ---- Overview stage: the device as big as it can be, the chat floating over the corner -------- */
@@ -514,6 +520,16 @@ dialog::backdrop { background:rgba(0,0,0,.6); }
514
520
  .chat-line em { color:var(--tapp-text-faint); font-style:normal; }
515
521
  .chat-line.phase { color:var(--tapp-text-soft); }
516
522
  .chat-line.warning { color:var(--tapp-amber); }
523
+ .chat-line.agent { color:var(--tapp-text); white-space:pre-wrap; }
524
+ .chat-line.you { color:var(--tapp-text-soft); font-style:italic; }
525
+ /* Asking the person's own agent (ADR-0012). */
526
+ .chat-prompt { display:flex; gap:6px; padding:8px; border-top:1px solid var(--tapp-border); }
527
+ .chat-prompt input { flex:1 1 auto; min-width:0; font:inherit; font-size:13px; padding:8px 10px; border-radius:10px; border:1px solid var(--tapp-border); background:rgba(0,0,0,.25); color:var(--tapp-text); }
528
+ .chat-prompt button { font:inherit; font-size:12px; padding:7px 12px; border-radius:10px; cursor:pointer; white-space:nowrap; }
529
+ .engine-row { display:grid; grid-template-columns:auto 1fr auto; gap:10px; align-items:center; padding:8px 10px; border-bottom:1px solid var(--tapp-border); font-size:13px; }
530
+ .engine-row:last-child { border-bottom:0; }
531
+ .engine-row small { color:var(--muted); display:block; }
532
+ .engine-row .journey-status.warning { background:rgba(210,153,34,.18); color:var(--tapp-amber-soft, #e3b341); }
517
533
  .chat-line.finding.critical, .chat-line.finding.high { color:var(--tapp-red); } .chat-line.finding.medium { color:var(--tapp-amber); } .chat-line.finding.low { color:var(--tapp-text-soft); }
518
534
  .chat-line.typing { color:var(--tapp-text-faint); } .chat-line.typing i { font-style:normal; animation:ellipsis 1.2s steps(4) infinite; }
519
535
  @keyframes ellipsis { 0% { content:""; opacity:.2; } 100% { opacity:1; } }
@@ -569,6 +585,42 @@ dialog::backdrop { background:rgba(0,0,0,.6); }
569
585
  .signin-row input { flex:1 1 220px; font:inherit; padding:9px 12px; border-radius:10px; border:1px solid var(--line); background:rgba(0,0,0,.15); color:inherit; }
570
586
  .signin-row button { font:inherit; padding:9px 14px; border-radius:10px; cursor:pointer; }
571
587
  .signin-sent { margin:0; }
588
+ /* The front door's second answer (ADR-0011): what runs on the person's own machine, with the command. */
589
+ .selfhost-card { max-width:560px; margin:14px auto 0; padding:14px 16px; border-radius:var(--tapp-radius-lg, 14px); border:1px solid var(--line); background:var(--control); font-size:13px; line-height:1.5; }
590
+ .selfhost-card p { margin:0 0 10px; }
591
+ .selfhost-card small { display:block; margin-top:8px; color:var(--tapp-text-faint); }
592
+ .selfhost-row { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
593
+ .selfhost-row code { flex:1 1 220px; font-family:var(--tapp-font-mono); font-size:12.5px; padding:9px 12px; border-radius:10px; border:1px solid var(--line); background:rgba(0,0,0,.25); color:inherit; overflow-wrap:anywhere; }
594
+ .selfhost-row button { font:inherit; font-size:12px; padding:7px 12px; border-radius:999px; border:1px solid var(--line); background:var(--control); color:inherit; cursor:pointer; }
595
+ .selfhost-row input { flex:1 1 220px; min-width:0; font:inherit; font-size:13px; padding:9px 12px; border-radius:10px; border:1px solid var(--line); background:rgba(0,0,0,.15); color:inherit; }
596
+ .linklike { font:inherit; font-size:inherit; background:none; border:0; padding:0; color:var(--tapp-accent, #4f6cf7); cursor:pointer; text-decoration:underline; }
597
+ .cloud-sent { margin:8px 0 0; }
598
+ /* Setting this machine up (ADR-0012). */
599
+ .setup-card { max-width:760px; margin:18px auto 0; padding:16px 18px; border-radius:var(--tapp-radius-lg, 14px); border:1px solid var(--line); background:var(--control); font-size:13px; line-height:1.5; text-align:left; }
600
+ .setup-head { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; }
601
+ .setup-head h2 { margin:2px 0 4px; font-size:16px; } .setup-head p { margin:0; } .setup-head .eyebrow { margin:0; }
602
+ .setup-steps { list-style:none; margin:12px 0 0; padding:0; display:grid; gap:10px; }
603
+ .setup-step { display:grid; grid-template-columns:26px 1fr; gap:10px; padding:10px 0 0; border-top:1px solid var(--tapp-border); }
604
+ .setup-step > i { font-style:normal; font-size:16px; text-align:center; line-height:1.3; }
605
+ .setup-step h3 { margin:0 0 2px; font-size:13.5px; } .setup-step p { margin:0; color:var(--tapp-text-soft); }
606
+ .setup-step ul { list-style:none; margin:6px 0 0; padding:0; display:grid; gap:3px; }
607
+ .setup-step li { display:grid; grid-template-columns:18px 1fr; gap:6px; } .setup-step li small { color:var(--tapp-text-faint); display:block; }
608
+ .setup-step li.engine-line { grid-template-columns:96px 1fr; gap:10px; align-items:start; margin-top:4px; }
609
+ .setup-step li.engine-line .journey-status { white-space:nowrap; }
610
+ .setup-step form { display:flex; gap:6px; flex-wrap:wrap; margin-top:8px; }
611
+ .setup-step form input { flex:1 1 220px; min-width:0; font:inherit; font-size:13px; padding:7px 10px; border-radius:10px; border:1px solid var(--line); background:rgba(0,0,0,.15); color:inherit; }
612
+ .setup-step form button, .setup-step .button-row button { font:inherit; font-size:12px; padding:6px 12px; border-radius:999px; cursor:pointer; }
613
+ .setup-step .button-row { display:flex; gap:6px; flex-wrap:wrap; margin-top:8px; align-items:center; }
614
+ .setup-step code { font-family:var(--tapp-font-mono); font-size:12px; padding:1px 5px; border-radius:6px; background:rgba(0,0,0,.25); }
615
+ .setup-summary { display:flex; gap:10px; flex-wrap:wrap; align-items:center; margin-top:8px; }
616
+ .setup-card.collapsed .setup-steps { display:none; }
617
+
618
+ /* Linking this machine to an account (ADR-0011 §4). */
619
+ .link-form { display:grid; gap:8px; max-width:560px; }
620
+ .link-form input { font:inherit; padding:9px 12px; border-radius:10px; border:1px solid var(--line); background:rgba(0,0,0,.15); color:inherit; }
621
+ .link-form .ask-actions { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
622
+ .link-form small, .link-state small { color:var(--tapp-text-faint); }
623
+ .link-state { display:flex; gap:10px; align-items:center; flex-wrap:wrap; font-size:13px; }
572
624
  .actor-row { display:grid; grid-template-columns:1fr auto auto; gap:10px; align-items:center; padding:8px 10px; border-bottom:1px solid var(--tapp-border); font-size:13px; }
573
625
  .actor-row:last-child { border-bottom:0; }
574
626
  .actor-row small { color:var(--muted); }
@@ -630,7 +682,6 @@ dialog::backdrop { background:rgba(0,0,0,.6); }
630
682
  .platform-state.needs-machine { color:var(--tapp-amber-soft); border-color:rgba(210,153,34,.38); }
631
683
 
632
684
  /* A suggestion this Studio cannot start is dimmed, not deleted: pressing it still answers. */
633
- .prompt-suggestions [data-kind].elsewhere { opacity:.62; }
634
685
 
635
686
  /* ---- Findings and Coverage (TM-794) -------------------------------------------------------
636
687
  Findings reads as a short list of kinds a person can scan, each opening onto the individual