@aarwitz/tapp 0.34.0 → 0.35.1
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.
- package/.claude-plugin/plugin.json +2 -2
- package/MacHarness/tapp-mac-ax.swift +291 -0
- package/README.md +1 -0
- package/bin/tapp.js +53 -8
- package/browser/product-contract.js +4 -4
- package/mcp-server/src/browser-product.js +10 -3
- package/mcp-server/src/index.js +54 -0
- package/mcp-server/src/macos-driver.js +253 -0
- package/mcp-server/src/macos-explorer.js +210 -0
- package/mcp-server/src/macos-flow.js +138 -0
- package/mcp-server/src/platforms.js +22 -16
- package/package.json +4 -2
- package/scripts/run-macos-flow.js +32 -0
|
@@ -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.
|
|
4
|
+
"version": "0.35.1",
|
|
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.
|
|
27
|
+
"@aarwitz/tapp@0.35.1",
|
|
28
28
|
"mcp"
|
|
29
29
|
],
|
|
30
30
|
"cwd": "${CLAUDE_PROJECT_DIR}"
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// tapp's macOS desktop driver, one process away from the engine.
|
|
2
|
+
//
|
|
3
|
+
// Android is driven through `adb` and a UIAutomator dump; iOS through XCUITest. macOS has an
|
|
4
|
+
// equivalent that needs neither a test bundle nor a rebuild of the application under test: the
|
|
5
|
+
// Accessibility API. Any running application exposes a tree of AXUIElements with roles, titles,
|
|
6
|
+
// values and actions, which is the same shape the rest of tapp already speaks.
|
|
7
|
+
//
|
|
8
|
+
// This is deliberately a plain command-line tool rather than a test target, so tapp can be
|
|
9
|
+
// pointed at a .app the way it is pointed at an .apk — nothing to link, nothing to re-sign.
|
|
10
|
+
//
|
|
11
|
+
// It requires the Accessibility permission (System Settings → Privacy & Security →
|
|
12
|
+
// Accessibility) for whatever runs it. There is no way to grant that from code and tapp does not
|
|
13
|
+
// try: `trusted` reports the truth and the CLI explains the one-time step.
|
|
14
|
+
//
|
|
15
|
+
// Elements are addressed by their path of child indices from the application element ("0.3.1").
|
|
16
|
+
// A path is only valid for the snapshot it came from, so every action re-reads the tree first —
|
|
17
|
+
// the same discipline as the Android driver's `snap`.
|
|
18
|
+
import ApplicationServices
|
|
19
|
+
import AppKit
|
|
20
|
+
import Foundation
|
|
21
|
+
|
|
22
|
+
// MARK: - Attribute reading
|
|
23
|
+
|
|
24
|
+
func attribute(_ element: AXUIElement, _ name: String) -> CFTypeRef? {
|
|
25
|
+
var value: CFTypeRef?
|
|
26
|
+
return AXUIElementCopyAttributeValue(element, name as CFString, &value) == .success ? value : nil
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
func stringAttribute(_ element: AXUIElement, _ name: String) -> String {
|
|
30
|
+
guard let value = attribute(element, name) else { return "" }
|
|
31
|
+
if let text = value as? String { return text }
|
|
32
|
+
if let number = value as? NSNumber { return number.stringValue }
|
|
33
|
+
// AXValue of a text area can arrive as an attributed string.
|
|
34
|
+
if let attributed = value as? NSAttributedString { return attributed.string }
|
|
35
|
+
return ""
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
func boolAttribute(_ element: AXUIElement, _ name: String, default fallback: Bool) -> Bool {
|
|
39
|
+
guard let value = attribute(element, name) as? NSNumber else { return fallback }
|
|
40
|
+
return value.boolValue
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func frame(_ element: AXUIElement) -> [Double] {
|
|
44
|
+
var origin = CGPoint.zero
|
|
45
|
+
var size = CGSize.zero
|
|
46
|
+
if let value = attribute(element, kAXPositionAttribute as String) {
|
|
47
|
+
AXValueGetValue(value as! AXValue, .cgPoint, &origin)
|
|
48
|
+
}
|
|
49
|
+
if let value = attribute(element, kAXSizeAttribute as String) {
|
|
50
|
+
AXValueGetValue(value as! AXValue, .cgSize, &size)
|
|
51
|
+
}
|
|
52
|
+
return [Double(origin.x), Double(origin.y), Double(size.width), Double(size.height)]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
func children(_ element: AXUIElement) -> [AXUIElement] {
|
|
56
|
+
guard let value = attribute(element, kAXChildrenAttribute as String) as? [AXUIElement] else { return [] }
|
|
57
|
+
return value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
func actions(_ element: AXUIElement) -> [String] {
|
|
61
|
+
var names: CFArray?
|
|
62
|
+
guard AXUIElementCopyActionNames(element, &names) == .success, let list = names as? [String] else { return [] }
|
|
63
|
+
return list
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// MARK: - Walking
|
|
67
|
+
|
|
68
|
+
struct Node: Encodable {
|
|
69
|
+
let path: String
|
|
70
|
+
let role: String
|
|
71
|
+
let subrole: String
|
|
72
|
+
let title: String
|
|
73
|
+
let desc: String
|
|
74
|
+
let value: String
|
|
75
|
+
let identifier: String
|
|
76
|
+
let enabled: Bool
|
|
77
|
+
let focused: Bool
|
|
78
|
+
let frame: [Double]
|
|
79
|
+
let actions: [String]
|
|
80
|
+
var children: [Node]
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/// Caps exist because a document-shaped application (a long outline, a big table) can expose tens
|
|
84
|
+
/// of thousands of elements, and a snapshot that takes a minute is not a snapshot.
|
|
85
|
+
let maxNodesDefault = 2500
|
|
86
|
+
let maxDepthDefault = 28
|
|
87
|
+
|
|
88
|
+
final class Walker {
|
|
89
|
+
var visited = 0
|
|
90
|
+
let maxNodes: Int
|
|
91
|
+
let maxDepth: Int
|
|
92
|
+
init(maxNodes: Int, maxDepth: Int) { self.maxNodes = maxNodes; self.maxDepth = maxDepth }
|
|
93
|
+
|
|
94
|
+
func walk(_ element: AXUIElement, path: String, depth: Int) -> Node {
|
|
95
|
+
visited += 1
|
|
96
|
+
let box = frame(element)
|
|
97
|
+
var node = Node(
|
|
98
|
+
path: path,
|
|
99
|
+
role: stringAttribute(element, kAXRoleAttribute as String),
|
|
100
|
+
subrole: stringAttribute(element, kAXSubroleAttribute as String),
|
|
101
|
+
title: stringAttribute(element, kAXTitleAttribute as String),
|
|
102
|
+
desc: stringAttribute(element, kAXDescriptionAttribute as String),
|
|
103
|
+
value: String(stringAttribute(element, kAXValueAttribute as String).prefix(400)),
|
|
104
|
+
identifier: stringAttribute(element, kAXIdentifierAttribute as String),
|
|
105
|
+
enabled: boolAttribute(element, kAXEnabledAttribute as String, default: true),
|
|
106
|
+
focused: boolAttribute(element, kAXFocusedAttribute as String, default: false),
|
|
107
|
+
frame: box,
|
|
108
|
+
actions: actions(element),
|
|
109
|
+
children: []
|
|
110
|
+
)
|
|
111
|
+
if depth >= maxDepth || visited >= maxNodes { return node }
|
|
112
|
+
for (index, child) in children(element).enumerated() {
|
|
113
|
+
if visited >= maxNodes { break }
|
|
114
|
+
node.children.append(walk(child, path: path.isEmpty ? "\(index)" : "\(path).\(index)", depth: depth + 1))
|
|
115
|
+
}
|
|
116
|
+
return node
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
func element(at path: String, from root: AXUIElement) -> AXUIElement? {
|
|
121
|
+
if path.isEmpty { return root }
|
|
122
|
+
var current = root
|
|
123
|
+
for component in path.split(separator: ".") {
|
|
124
|
+
guard let index = Int(component) else { return nil }
|
|
125
|
+
let kids = children(current)
|
|
126
|
+
guard index >= 0 && index < kids.count else { return nil }
|
|
127
|
+
current = kids[index]
|
|
128
|
+
}
|
|
129
|
+
return current
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// MARK: - Output
|
|
133
|
+
|
|
134
|
+
func emit(_ value: Encodable, pretty: Bool = false) {
|
|
135
|
+
let encoder = JSONEncoder()
|
|
136
|
+
if pretty { encoder.outputFormatting = [.prettyPrinted, .sortedKeys] }
|
|
137
|
+
struct Box<T: Encodable>: Encodable { let v: T }
|
|
138
|
+
guard let data = try? encoder.encode(AnyEncodable(value)) else { fail("could not encode result") }
|
|
139
|
+
FileHandle.standardOutput.write(data)
|
|
140
|
+
FileHandle.standardOutput.write("\n".data(using: .utf8)!)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
struct AnyEncodable: Encodable {
|
|
144
|
+
private let encodeTo: (Encoder) throws -> Void
|
|
145
|
+
init(_ wrapped: Encodable) { encodeTo = wrapped.encode }
|
|
146
|
+
func encode(to encoder: Encoder) throws { try encodeTo(encoder) }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
func fail(_ message: String) -> Never {
|
|
150
|
+
struct Failure: Encodable { let ok = false; let error: String }
|
|
151
|
+
if let data = try? JSONEncoder().encode(Failure(error: message)) {
|
|
152
|
+
FileHandle.standardError.write(data)
|
|
153
|
+
FileHandle.standardError.write("\n".data(using: .utf8)!)
|
|
154
|
+
}
|
|
155
|
+
exit(1)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
struct Ok: Encodable { let ok = true; let detail: String }
|
|
159
|
+
|
|
160
|
+
// MARK: - Arguments
|
|
161
|
+
|
|
162
|
+
var arguments = Array(CommandLine.arguments.dropFirst())
|
|
163
|
+
guard let command = arguments.first else {
|
|
164
|
+
fail("usage: tapp-mac-ax <trusted|launch|tree|press|setvalue|key|windows|quit> [options]")
|
|
165
|
+
}
|
|
166
|
+
arguments = Array(arguments.dropFirst())
|
|
167
|
+
|
|
168
|
+
func option(_ name: String) -> String? {
|
|
169
|
+
guard let index = arguments.firstIndex(of: "--\(name)"), index + 1 < arguments.count else { return nil }
|
|
170
|
+
return arguments[index + 1]
|
|
171
|
+
}
|
|
172
|
+
func intOption(_ name: String, _ fallback: Int) -> Int { Int(option(name) ?? "") ?? fallback }
|
|
173
|
+
|
|
174
|
+
func requirePid() -> pid_t {
|
|
175
|
+
guard let raw = option("pid"), let pid = Int32(raw) else { fail("--pid is required") }
|
|
176
|
+
return pid
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
func requireTrusted() {
|
|
180
|
+
guard AXIsProcessTrusted() else {
|
|
181
|
+
fail("This program is not allowed to use the Accessibility API. Grant it in System Settings → Privacy & Security → Accessibility, for the application that runs tapp (your terminal, or the tapp app).")
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// MARK: - Commands
|
|
186
|
+
|
|
187
|
+
switch command {
|
|
188
|
+
case "trusted":
|
|
189
|
+
struct Trust: Encodable { let trusted: Bool }
|
|
190
|
+
emit(Trust(trusted: AXIsProcessTrusted()))
|
|
191
|
+
|
|
192
|
+
case "launch":
|
|
193
|
+
// Launching is ordinary AppKit, not Accessibility: no permission needed to start a program.
|
|
194
|
+
guard let bundlePath = option("app") else { fail("--app /path/to/App.app is required") }
|
|
195
|
+
let url = URL(fileURLWithPath: bundlePath)
|
|
196
|
+
guard FileManager.default.fileExists(atPath: url.path) else { fail("No application at \(url.path)") }
|
|
197
|
+
let configuration = NSWorkspace.OpenConfiguration()
|
|
198
|
+
configuration.activates = true
|
|
199
|
+
configuration.createsNewApplicationInstance = false
|
|
200
|
+
let semaphore = DispatchSemaphore(value: 0)
|
|
201
|
+
var launched: NSRunningApplication?
|
|
202
|
+
var launchError: Error?
|
|
203
|
+
NSWorkspace.shared.openApplication(at: url, configuration: configuration) { application, error in
|
|
204
|
+
launched = application; launchError = error; semaphore.signal()
|
|
205
|
+
}
|
|
206
|
+
if semaphore.wait(timeout: .now() + 30) == .timedOut { fail("Timed out launching \(url.lastPathComponent)") }
|
|
207
|
+
if let error = launchError { fail("Could not launch \(url.lastPathComponent): \(error.localizedDescription)") }
|
|
208
|
+
guard let application = launched else { fail("Could not launch \(url.lastPathComponent)") }
|
|
209
|
+
struct Launched: Encodable { let ok = true; let pid: Int32; let bundleId: String; let name: String }
|
|
210
|
+
emit(Launched(pid: application.processIdentifier,
|
|
211
|
+
bundleId: application.bundleIdentifier ?? "",
|
|
212
|
+
name: application.localizedName ?? url.deletingPathExtension().lastPathComponent))
|
|
213
|
+
|
|
214
|
+
case "tree":
|
|
215
|
+
requireTrusted()
|
|
216
|
+
let pid = requirePid()
|
|
217
|
+
let application = AXUIElementCreateApplication(pid)
|
|
218
|
+
let walker = Walker(maxNodes: intOption("max-nodes", maxNodesDefault), maxDepth: intOption("max-depth", maxDepthDefault))
|
|
219
|
+
struct Tree: Encodable { let ok = true; let pid: Int32; let app: String; let window: String; let truncated: Bool; let nodes: Int; let root: Node }
|
|
220
|
+
let root = walker.walk(application, path: "", depth: 0)
|
|
221
|
+
// The focused window names the screen, the way an h1 names a web page.
|
|
222
|
+
var window = ""
|
|
223
|
+
if let focused = attribute(application, kAXFocusedWindowAttribute as String) {
|
|
224
|
+
window = stringAttribute(focused as! AXUIElement, kAXTitleAttribute as String)
|
|
225
|
+
}
|
|
226
|
+
if window.isEmpty, let windows = attribute(application, kAXWindowsAttribute as String) as? [AXUIElement], let first = windows.first {
|
|
227
|
+
window = stringAttribute(first, kAXTitleAttribute as String)
|
|
228
|
+
}
|
|
229
|
+
let name = NSRunningApplication(processIdentifier: pid)?.localizedName ?? ""
|
|
230
|
+
emit(Tree(pid: pid, app: name, window: window, truncated: walker.visited >= walker.maxNodes, nodes: walker.visited, root: root))
|
|
231
|
+
|
|
232
|
+
case "press":
|
|
233
|
+
requireTrusted()
|
|
234
|
+
let pid = requirePid()
|
|
235
|
+
guard let path = option("path") else { fail("--path is required") }
|
|
236
|
+
let application = AXUIElementCreateApplication(pid)
|
|
237
|
+
guard let target = element(at: path, from: application) else { fail("No element at path \(path)") }
|
|
238
|
+
let available = actions(target)
|
|
239
|
+
let wanted = option("action") ?? (available.contains(kAXPressAction as String) ? kAXPressAction as String : available.first ?? "")
|
|
240
|
+
guard !wanted.isEmpty else { fail("Element at \(path) has no actions") }
|
|
241
|
+
let code = AXUIElementPerformAction(target, wanted as CFString)
|
|
242
|
+
guard code == .success else { fail("\(wanted) on \(path) failed (AXError \(code.rawValue))") }
|
|
243
|
+
emit(Ok(detail: wanted))
|
|
244
|
+
|
|
245
|
+
case "setvalue":
|
|
246
|
+
requireTrusted()
|
|
247
|
+
let pid = requirePid()
|
|
248
|
+
guard let path = option("path") else { fail("--path is required") }
|
|
249
|
+
let text = option("text") ?? ""
|
|
250
|
+
let application = AXUIElementCreateApplication(pid)
|
|
251
|
+
guard let target = element(at: path, from: application) else { fail("No element at path \(path)") }
|
|
252
|
+
// Focus first: some fields only accept a value while they are the responder, and a field the
|
|
253
|
+
// user can see being filled is what a recording should show.
|
|
254
|
+
AXUIElementSetAttributeValue(target, kAXFocusedAttribute as CFString, kCFBooleanTrue)
|
|
255
|
+
let code = AXUIElementSetAttributeValue(target, kAXValueAttribute as CFString, text as CFTypeRef)
|
|
256
|
+
guard code == .success else { fail("Could not set the value of \(path) (AXError \(code.rawValue))") }
|
|
257
|
+
emit(Ok(detail: "set"))
|
|
258
|
+
|
|
259
|
+
case "key":
|
|
260
|
+
requireTrusted()
|
|
261
|
+
let pid = requirePid()
|
|
262
|
+
guard let name = option("key") else { fail("--key is required") }
|
|
263
|
+
let codes: [String: CGKeyCode] = ["return": 36, "enter": 36, "tab": 48, "space": 49, "delete": 51, "escape": 53,
|
|
264
|
+
"left": 123, "right": 124, "down": 125, "up": 126]
|
|
265
|
+
guard let keyCode = codes[name.lowercased()] else { fail("Unknown key '\(name)'. Known: \(codes.keys.sorted().joined(separator: ", "))") }
|
|
266
|
+
guard let source = CGEventSource(stateID: .hidSystemState) else { fail("Could not create an event source") }
|
|
267
|
+
let down = CGEvent(keyboardEventSource: source, virtualKey: keyCode, keyDown: true)
|
|
268
|
+
let up = CGEvent(keyboardEventSource: source, virtualKey: keyCode, keyDown: false)
|
|
269
|
+
down?.postToPid(pid)
|
|
270
|
+
up?.postToPid(pid)
|
|
271
|
+
emit(Ok(detail: name))
|
|
272
|
+
|
|
273
|
+
case "windows":
|
|
274
|
+
requireTrusted()
|
|
275
|
+
let pid = requirePid()
|
|
276
|
+
let application = AXUIElementCreateApplication(pid)
|
|
277
|
+
struct Window: Encodable { let title: String; let frame: [Double] }
|
|
278
|
+
struct Windows: Encodable { let ok = true; let windows: [Window] }
|
|
279
|
+
let list = (attribute(application, kAXWindowsAttribute as String) as? [AXUIElement] ?? [])
|
|
280
|
+
.map { Window(title: stringAttribute($0, kAXTitleAttribute as String), frame: frame($0)) }
|
|
281
|
+
emit(Windows(windows: list))
|
|
282
|
+
|
|
283
|
+
case "quit":
|
|
284
|
+
let pid = requirePid()
|
|
285
|
+
guard let application = NSRunningApplication(processIdentifier: pid) else { emit(Ok(detail: "not running")); exit(0) }
|
|
286
|
+
application.terminate()
|
|
287
|
+
emit(Ok(detail: "terminated"))
|
|
288
|
+
|
|
289
|
+
default:
|
|
290
|
+
fail("Unknown command '\(command)'")
|
|
291
|
+
}
|
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ Supported targets:
|
|
|
30
30
|
| iOS | Simulator on macOS with Xcode; driven through XCUITest and accessibility |
|
|
31
31
|
| Android | Connected emulator or device with `adb`; driven through UIAutomator |
|
|
32
32
|
| Web | Owned browser app in Playwright Chromium |
|
|
33
|
+
| macOS desktop | Any `.app` on a Mac, driven through the Accessibility API; needs the Accessibility permission (`tapp doctor` says how) |
|
|
33
34
|
| Windows desktop | WPF, WinForms, and WinUI apps through Windows UI Automation — early runs are set up through the pilot |
|
|
34
35
|
|
|
35
36
|
Windows hosts Android and web testing when their prerequisites are installed, and is the home of
|
package/bin/tapp.js
CHANGED
|
@@ -265,11 +265,9 @@ function repeatedFlagValues(argv, name) {
|
|
|
265
265
|
// `--platform windows` used to be indistinguishable from `--platform wbe`: both got
|
|
266
266
|
// "must be ios|android|web", which tells someone who read runtapp.com's Windows card that they
|
|
267
267
|
// typed it wrong. They did not — tapp has no driver for it yet. Say which of the two it is.
|
|
268
|
-
const DRIVEN_PLATFORMS = ["ios", "android", "web"];
|
|
268
|
+
const DRIVEN_PLATFORMS = ["ios", "android", "web", "macos"];
|
|
269
269
|
const DECLARED_WITHOUT_DRIVER = {
|
|
270
270
|
windows: "Windows desktop applications (WPF, WinForms, WinUI)",
|
|
271
|
-
macos: "macOS desktop applications",
|
|
272
|
-
mac: "macOS desktop applications",
|
|
273
271
|
desktop: "desktop applications",
|
|
274
272
|
};
|
|
275
273
|
function refusePlatform(platform) {
|
|
@@ -277,9 +275,9 @@ function refusePlatform(platform) {
|
|
|
277
275
|
if (described) {
|
|
278
276
|
console.error(`❌ tapp has no driver for ${described} yet, so there is nothing to run here.`);
|
|
279
277
|
console.error(" Early runs are set up with us while the driver lands: hello@runtapp.com");
|
|
280
|
-
console.error(" Today tapp drives: web (anywhere), iOS
|
|
278
|
+
console.error(" Today tapp drives: web (anywhere), iOS and macOS apps (on a Mac), Android (adb).");
|
|
281
279
|
} else {
|
|
282
|
-
console.error("❌ --platform must be ios|android|web");
|
|
280
|
+
console.error("❌ --platform must be ios|android|web|macos");
|
|
283
281
|
}
|
|
284
282
|
process.exit(2);
|
|
285
283
|
}
|
|
@@ -313,10 +311,19 @@ function requireMacFor(what) {
|
|
|
313
311
|
process.exit(1);
|
|
314
312
|
}
|
|
315
313
|
|
|
314
|
+
// A macOS application bundle and an iOS simulator build are both directories called
|
|
315
|
+
// Something.app. The difference is where the executable lives: a Mac bundle keeps it in
|
|
316
|
+
// Contents/MacOS, a simulator build keeps it at the top level.
|
|
317
|
+
function looksLikeMacosBundle(target) {
|
|
318
|
+
try { return /\.app\/?$/.test(target) && fs.existsSync(path.join(target, "Contents", "MacOS")); }
|
|
319
|
+
catch { return false; }
|
|
320
|
+
}
|
|
321
|
+
|
|
316
322
|
function requestedPlatform(flags, target = "") {
|
|
317
323
|
if (typeof flags.platform === "string") return flags.platform.toLowerCase();
|
|
318
324
|
if (/^https?:\/\//i.test(target)) return "web";
|
|
319
325
|
if (/\.apk$/i.test(target)) return "android";
|
|
326
|
+
if (looksLikeMacosBundle(target)) return "macos";
|
|
320
327
|
return "ios";
|
|
321
328
|
}
|
|
322
329
|
|
|
@@ -1021,6 +1028,10 @@ switch (command) {
|
|
|
1021
1028
|
const platform = requestedPlatform(flags, target);
|
|
1022
1029
|
if (!DRIVEN_PLATFORMS.includes(platform)) refusePlatform(platform);
|
|
1023
1030
|
if (platform === "ios") requireMacFor("iOS testing");
|
|
1031
|
+
if (platform === "macos") {
|
|
1032
|
+
requireMacFor("macOS application testing");
|
|
1033
|
+
if (!target) { console.error("❌ macOS exploration needs an application: tapp explore /Applications/Yours.app"); process.exit(2); }
|
|
1034
|
+
}
|
|
1024
1035
|
if (flags.watch === true && platform !== "web") {
|
|
1025
1036
|
console.error("❌ --watch is currently available for web exploration only");
|
|
1026
1037
|
process.exit(2);
|
|
@@ -1035,7 +1046,7 @@ switch (command) {
|
|
|
1035
1046
|
}
|
|
1036
1047
|
const bundleId = platform === "ios" ? await resolveTargetOrExit(engine, target) : null;
|
|
1037
1048
|
const android = platform === "android" ? androidTarget(flags, target) : null;
|
|
1038
|
-
const progressMetric = platform === "web" ? "pages reached" : platform === "ios" ? "structural states observed" : "screens reached";
|
|
1049
|
+
const progressMetric = platform === "web" ? "pages reached" : platform === "ios" ? "structural states observed" : platform === "macos" ? "window states observed" : "screens reached";
|
|
1039
1050
|
const onProgress = (p) =>
|
|
1040
1051
|
writeProgress(`🔍 Exploring… ${p.action}/${p.max || flags.actions || 60} actions · ${p.states} ${progressMetric}`);
|
|
1041
1052
|
// --interactive: when the run meets a sign-in it has no credentials for, it stops and asks
|
|
@@ -1092,6 +1103,17 @@ switch (command) {
|
|
|
1092
1103
|
surface: "cli",
|
|
1093
1104
|
onProgress,
|
|
1094
1105
|
})
|
|
1106
|
+
: platform === "macos"
|
|
1107
|
+
? await engine.runQaMacos({
|
|
1108
|
+
appPath: target,
|
|
1109
|
+
maxActions: flags.actions,
|
|
1110
|
+
timeout: flags.timeout,
|
|
1111
|
+
testEmail: flags.email,
|
|
1112
|
+
testPassword: flags.password,
|
|
1113
|
+
baselineFindings,
|
|
1114
|
+
surface: "cli",
|
|
1115
|
+
onProgress,
|
|
1116
|
+
})
|
|
1095
1117
|
: await engine.runQaIos({
|
|
1096
1118
|
bundleId,
|
|
1097
1119
|
maxActions: flags.actions,
|
|
@@ -1495,7 +1517,7 @@ switch (command) {
|
|
|
1495
1517
|
process.exit(2);
|
|
1496
1518
|
}
|
|
1497
1519
|
const platform = String(flags.platform || flow.platform || (flow.url || /^https?:\/\//i.test(flow.app || "") ? "web" : "ios")).toLowerCase();
|
|
1498
|
-
if (!
|
|
1520
|
+
if (!DRIVEN_PLATFORMS.includes(platform)) {
|
|
1499
1521
|
console.error(`❌ Unsupported Flow platform: ${platform}`);
|
|
1500
1522
|
process.exit(2);
|
|
1501
1523
|
}
|
|
@@ -1578,6 +1600,11 @@ switch (command) {
|
|
|
1578
1600
|
} else if (platform === "android") {
|
|
1579
1601
|
const target = androidTarget(flags, typeof flags["app-id"] === "string" ? flags["app-id"] : flow.app || "");
|
|
1580
1602
|
invocation = [process.execPath, [path.join(packageRoot, "scripts", "run-android-flow.js"), absolute, target.appId, target.apkPath || "", target.serial || ""]];
|
|
1603
|
+
} else if (platform === "macos") {
|
|
1604
|
+
requireMacFor("macOS Flow replay");
|
|
1605
|
+
const app = typeof flags.app === "string" ? flags.app : flow.app || "";
|
|
1606
|
+
if (!app) { console.error("❌ A macOS Flow needs `app:` with the path to the application, or --app"); process.exit(2); }
|
|
1607
|
+
invocation = [process.execPath, [path.join(packageRoot, "scripts", "run-macos-flow.js"), absolute, app]];
|
|
1581
1608
|
} else {
|
|
1582
1609
|
requireMacFor("iOS Flow replay");
|
|
1583
1610
|
invocation = ["bash", [path.join(packageRoot, "scripts", "run-flow.sh"), absolute, typeof flags["bundle-id"] === "string" ? flags["bundle-id"] : flow.app || ""]];
|
|
@@ -1897,7 +1924,7 @@ switch (command) {
|
|
|
1897
1924
|
const { flags: doctorFlags } = parseVerbArgs(rest);
|
|
1898
1925
|
const jsonMode = doctorFlags.json === true;
|
|
1899
1926
|
const report = { version: pkg.version, healthy: true, node: {}, python3: {}, disk: {},
|
|
1900
|
-
platforms: { ios: {}, android: {}, web: {} }, home: tappHome };
|
|
1927
|
+
platforms: { ios: {}, macos: {}, android: {}, web: {} }, home: tappHome };
|
|
1901
1928
|
const say = (line) => { if (!jsonMode) console.log(line); };
|
|
1902
1929
|
const sayOk = (label, detail = "") => { if (!jsonMode) ok(label, detail); };
|
|
1903
1930
|
const sayBad = (label, detail = "") => { if (!jsonMode) bad(label, detail); };
|
|
@@ -1948,6 +1975,24 @@ switch (command) {
|
|
|
1948
1975
|
say(` ⬜ iOS — requires macOS (this host: ${process.platform})`);
|
|
1949
1976
|
}
|
|
1950
1977
|
|
|
1978
|
+
// macOS desktop applications. The driver is the Accessibility API, which needs a one-time
|
|
1979
|
+
// permission nothing can grant for you — so report the permission, not just the platform.
|
|
1980
|
+
if (process.platform === "darwin") {
|
|
1981
|
+
try {
|
|
1982
|
+
const { macAccessibilityTrusted, ACCESSIBILITY_REMEDIATION } = await import(path.join(packageRoot, "mcp-server", "src", "macos-driver.js"));
|
|
1983
|
+
const trusted = macAccessibilityTrusted({ home: tappHome });
|
|
1984
|
+
report.platforms.macos = { available: trusted, accessibility: trusted, ...(trusted ? {} : { reason: "Accessibility permission not granted" }) };
|
|
1985
|
+
if (trusted) sayOk("macOS apps", "Accessibility permission granted");
|
|
1986
|
+
else say(` ⬜ macOS apps — ${ACCESSIBILITY_REMEDIATION}`);
|
|
1987
|
+
} catch (error) {
|
|
1988
|
+
report.platforms.macos = { available: false, reason: String(error.message || error).slice(0, 160) };
|
|
1989
|
+
say(` ⬜ macOS apps — ${String(error.message || error).slice(0, 120)}`);
|
|
1990
|
+
}
|
|
1991
|
+
} else {
|
|
1992
|
+
report.platforms.macos = { available: false, reason: `requires macOS (this host: ${process.platform})` };
|
|
1993
|
+
say(` ⬜ macOS apps — requires macOS (this host: ${process.platform})`);
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1951
1996
|
const { resolveAdbPath, resolveAndroidSdkRoot } = await import(path.join(packageRoot, "mcp-server", "src", "android-driver.js"));
|
|
1952
1997
|
const adbPath = resolveAdbPath();
|
|
1953
1998
|
const adb = adbPath ? run(adbPath, ["devices"]) : { code: 1, stdout: "" };
|
|
@@ -6,10 +6,10 @@ export const customerProductContract = Object.freeze({
|
|
|
6
6
|
schemaVersion: 2,
|
|
7
7
|
product: "Tapp",
|
|
8
8
|
interface: "customer-browser",
|
|
9
|
-
// What tapp has a driver for.
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
targetPlatforms: ["ios", "android", "web"],
|
|
9
|
+
// What tapp has a driver for. Windows desktop applications are shown in the Studio's
|
|
10
|
+
// Platforms view as having no driver yet — declared honestly, never counted here, because
|
|
11
|
+
// this list is what the engine can actually drive (ADR-0010).
|
|
12
|
+
targetPlatforms: ["ios", "android", "web", "macos"],
|
|
13
13
|
// A repository is opened by path (`tapp app /path/to/repo`); a website by URL in the Studio.
|
|
14
14
|
repositorySources: ["local-path", "github"],
|
|
15
15
|
entryLayers: ["repository", "website"],
|
|
@@ -25,6 +25,7 @@ import { oauthProviders, oauthAuthorizeUrl, oauthEmailFromCode, isOauthProvider
|
|
|
25
25
|
import { journeyFromCapture, JourneyStore, slugify } from "./journeys.js";
|
|
26
26
|
import { AlertStore, alertForChange, alertMessage, deliverAlert } from "./alerts.js";
|
|
27
27
|
import { platformStates, selfHostAnswer, PLATFORM_TARGETS, hostToolchain } from "./platforms.js";
|
|
28
|
+
import { isMacosAppBundle } from "./macos-driver.js";
|
|
28
29
|
|
|
29
30
|
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
30
31
|
const assetRoot = path.join(packageRoot, "browser");
|
|
@@ -1474,14 +1475,20 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
1474
1475
|
return;
|
|
1475
1476
|
}
|
|
1476
1477
|
const prompt = classifyPrompt(body.input);
|
|
1477
|
-
if (!["bundle", "app", "apk"].includes(prompt.kind)) throw Object.assign(new Error("Give a bundle id (com.company.app), a
|
|
1478
|
+
if (!["bundle", "app", "apk"].includes(prompt.kind)) throw Object.assign(new Error("Give a bundle id (com.company.app), a .app (macOS or simulator), or an .apk"), { statusCode: 400 });
|
|
1478
1479
|
const job = startJob(operation, async (progress) => {
|
|
1479
1480
|
const engine = await import("./index.js");
|
|
1480
|
-
|
|
1481
|
+
// A .app is either a macOS application or an iOS simulator build; the difference is
|
|
1482
|
+
// whether its executable lives in Contents/MacOS (mcp-server/src/macos-driver.js).
|
|
1483
|
+
const macosBundle = prompt.kind === "app" && isMacosAppBundle(prompt.value);
|
|
1484
|
+
job.platform = prompt.kind === "apk" ? "android" : macosBundle ? "macos" : "ios";
|
|
1481
1485
|
job.liveSimulator = job.platform === "ios";
|
|
1482
1486
|
const forward = (entry) => progress({ phase: "explore", text: entry.narrative || `${entry.action || 0}/${entry.max || 0} actions · ${entry.states || 0} states`, ...(entry.action ? { current: entry.action, total: entry.max } : {}), ...(entry.screen ? { screen: entry.screen } : {}), ...(entry.screenshot ? { screenshot: entry.screenshot } : {}) });
|
|
1483
1487
|
let result;
|
|
1484
|
-
if (
|
|
1488
|
+
if (macosBundle) {
|
|
1489
|
+
progress({ phase: "runtime", text: `Launching ${path.basename(prompt.value)}` });
|
|
1490
|
+
result = await engine.runQaMacos({ appPath: prompt.value, maxActions: Number(body.maxActions) || 40, timeout: Number(body.timeout) || 600, onProgress: forward });
|
|
1491
|
+
} else if (prompt.kind === "apk") {
|
|
1485
1492
|
progress({ phase: "runtime", text: `Installing ${path.basename(prompt.value)} on the connected Android device` });
|
|
1486
1493
|
result = await engine.runQaAndroid({ apkPath: prompt.value, appId: String(body.appId || ""), maxActions: Number(body.maxActions) || 40, timeout: Number(body.timeout) || 600, onProgress: forward });
|
|
1487
1494
|
} else {
|
package/mcp-server/src/index.js
CHANGED
|
@@ -2094,6 +2094,60 @@ export async function runQaAndroid({ appId, apkPath, serial, maxActions, timeout
|
|
|
2094
2094
|
return { structured, text };
|
|
2095
2095
|
}
|
|
2096
2096
|
|
|
2097
|
+
/**
|
|
2098
|
+
* Explore a macOS desktop application. The shape mirrors runQaAndroid exactly, because the
|
|
2099
|
+
* marker contract is the same and everything downstream — report.js, the UI Map, the HTML
|
|
2100
|
+
* report, journeys, the gate — is platform-agnostic by design.
|
|
2101
|
+
*/
|
|
2102
|
+
export async function runQaMacos({ appPath, maxActions, timeout, testEmail, testPassword, baselineFindings, surface = "mcp", onProgress = () => {} }) {
|
|
2103
|
+
if (process.platform !== "darwin") {
|
|
2104
|
+
return { error: "macOS applications can only be driven on macOS. Use a Mac, or have tapp run it for you." };
|
|
2105
|
+
}
|
|
2106
|
+
const { storagePreflight } = await import("./environment-preflight.js");
|
|
2107
|
+
const storage = storagePreflight(capturesDir);
|
|
2108
|
+
if (!storage.ok) return { error: storage.message, details: { environment: "storage", storage } };
|
|
2109
|
+
const resolved = path.resolve(String(appPath || "").trim());
|
|
2110
|
+
if (!fs.existsSync(resolved)) return { error: `No application at ${resolved}` };
|
|
2111
|
+
const label = path.basename(resolved, ".app");
|
|
2112
|
+
const actions = Math.max(1, Math.min(1000, asInteger(maxActions, 40)));
|
|
2113
|
+
const timeoutSec = Math.max(30, Math.min(3600, asInteger(timeout, 600)));
|
|
2114
|
+
const id = "macos-" + new Date().toISOString().replace(/[-:T]/g, "").slice(0, 14).replace(/^(\d{8})/, "$1-");
|
|
2115
|
+
const outDir = path.join(capturesDir, id);
|
|
2116
|
+
const provenance = writeCaptureProvenance(outDir, { kind: "explore", platform: "macos", target: resolved, projectDir: workspaceRoot });
|
|
2117
|
+
let macResult;
|
|
2118
|
+
try {
|
|
2119
|
+
const { exploreMacos } = await import("./macos-explorer.js");
|
|
2120
|
+
macResult = await exploreMacos({
|
|
2121
|
+
appPath: resolved,
|
|
2122
|
+
maxActions: actions,
|
|
2123
|
+
timeoutSec,
|
|
2124
|
+
outDir,
|
|
2125
|
+
testEmail: isNonEmptyString(testEmail) ? testEmail.trim() : "",
|
|
2126
|
+
testPassword: isNonEmptyString(testPassword) ? testPassword : "",
|
|
2127
|
+
onProgress,
|
|
2128
|
+
});
|
|
2129
|
+
} catch (error) {
|
|
2130
|
+
return { error: error.message || String(error), details: { capture: { id, path: outDir } } };
|
|
2131
|
+
}
|
|
2132
|
+
const report = buildQaReport(macResult.markersPath, { platform: "macos", target: resolved });
|
|
2133
|
+
if (!report) return { error: "macOS exploration produced no markers", details: { capture: { id, path: outDir } } };
|
|
2134
|
+
const backend = remoteAiOptedIn() ? resolveModelBackend() : null;
|
|
2135
|
+
if (backend && report.findings.length) {
|
|
2136
|
+
const { enrichFindings } = await import("./enrich.js");
|
|
2137
|
+
await enrichFindings(report.findings, { backend, callModel, screens: report.screens, appLabel: label });
|
|
2138
|
+
}
|
|
2139
|
+
const regression = computeRegression(report.findings, baselineFindings);
|
|
2140
|
+
const uiMap = await writeRunUiMap({ markersPath: macResult.markersPath, platform: "macos", target: resolved, runId: id, outDir });
|
|
2141
|
+
let reportHtml = null;
|
|
2142
|
+
try {
|
|
2143
|
+
const { writeHtmlReport } = await import("./html-report.js");
|
|
2144
|
+
reportHtml = writeHtmlReport(outDir, { report, label });
|
|
2145
|
+
} catch {}
|
|
2146
|
+
const structured = { ...report, regression, platform: "macos", uiMap, reportHtml, capture: { id, path: outDir, relativePath: path.relative(repoRoot, outDir), provenance } };
|
|
2147
|
+
const text = formatQaReport(report, { regression, bundleId: label, aiConfigured: !!backend, reportHtml, uiMap: uiMap.error ? null : uiMap, surface });
|
|
2148
|
+
return { structured, text };
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2097
2151
|
export async function runQaIos({ bundleId, maxActions, timeout, args = {}, device = "", surface = "mcp", onProgress = () => {} }) {
|
|
2098
2152
|
const { storagePreflight } = await import("./environment-preflight.js");
|
|
2099
2153
|
const storage = storagePreflight(capturesDir);
|