-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(perps): agentic lifecycle actions and multi-device support #28709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e0e2b1
feat(perps): add lifecycle actions and multi-device support to agenti…
abretonc7s 2684700
fix(perps): handle empty string input and unnamed device dedup in age…
abretonc7s bd2da4e
fix(perps): add when-guard for switch/end nodes + log capture
abretonc7s 44d4fe4
fix(perps): log error before teardown so it appears in run.log
abretonc7s 423546b
fix(perps): sanitize run.log output + fix end node stats counting
abretonc7s b3948ed
fix(perps): sanitize console output to break CodeQL taint path
abretonc7s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| 'use strict'; | ||
|
|
||
| const { spawnSync } = require('node:child_process'); | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Platform detection | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| function detectPlatform() { | ||
| if (process.env.ADB_SERIAL || process.env.ANDROID_SERIAL) { | ||
| return 'android'; | ||
| } | ||
| if (process.platform === 'darwin') { | ||
| return 'ios'; | ||
| } | ||
| throw new Error( | ||
| 'Cannot detect simulator platform. Set ADB_SERIAL for Android or run on macOS for iOS.', | ||
| ); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // iOS helpers | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| function resolveBootedSimulatorUdid() { | ||
| const result = spawnSync( | ||
| 'xcrun', | ||
| ['simctl', 'list', 'devices', 'booted', '-j'], | ||
| { encoding: 'utf8' }, | ||
| ); | ||
| const parsed = JSON.parse(result.stdout || '{}'); | ||
| for (const devices of Object.values(parsed.devices || {})) { | ||
| for (const d of devices) { | ||
| if (d.state === 'Booted') { | ||
| return d.udid; | ||
| } | ||
| } | ||
| } | ||
| throw new Error('No booted iOS simulator found'); | ||
| } | ||
|
|
||
| function resolveIosBundleId(udid) { | ||
| const result = spawnSync('xcrun', ['simctl', 'listapps', udid], { | ||
| encoding: 'utf8', | ||
| }); | ||
| const match = (result.stdout || '').match( | ||
| /CFBundleIdentifier\s*=\s*"(io\.metamask\.[^"]+)"/, | ||
| ); | ||
| return match ? match[1] : 'io.metamask.MetaMask'; | ||
| } | ||
|
|
||
| function iosBackground() { | ||
| spawnSync( | ||
| 'osascript', | ||
| [ | ||
| '-e', 'tell application "Simulator" to activate', | ||
| '-e', 'delay 0.3', | ||
| '-e', 'tell application "System Events" to keystroke "h" using {command down, shift down}', | ||
| ], | ||
| { encoding: 'utf8' }, | ||
| ); | ||
| } | ||
|
|
||
| function iosForeground(udid, bundleId) { | ||
| spawnSync('xcrun', ['simctl', 'launch', udid, bundleId], { | ||
| encoding: 'utf8', | ||
| }); | ||
| } | ||
|
|
||
| function iosTerminate(udid, bundleId) { | ||
| spawnSync('xcrun', ['simctl', 'terminate', udid, bundleId], { | ||
| encoding: 'utf8', | ||
| }); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Android helpers | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| function resolveAdbSerial() { | ||
| return process.env.ADB_SERIAL || process.env.ANDROID_SERIAL || ''; | ||
| } | ||
|
|
||
| function resolveAndroidPackage() { | ||
| // Check for running MetaMask activity | ||
| const serial = resolveAdbSerial(); | ||
| const args = serial ? ['-s', serial] : []; | ||
| const result = spawnSync( | ||
| 'adb', | ||
| [...args, 'shell', 'dumpsys', 'activity', 'activities'], | ||
| { encoding: 'utf8' }, | ||
| ); | ||
| const match = (result.stdout || '').match( | ||
| /(io\.metamask[.\w]*)\/.+Activity/, | ||
| ); | ||
| return match ? match[1] : 'io.metamask'; | ||
| } | ||
|
|
||
| function adbShell(...shellArgs) { | ||
| const serial = resolveAdbSerial(); | ||
| const args = serial ? ['-s', serial] : []; | ||
| return spawnSync('adb', [...args, 'shell', ...shellArgs], { | ||
| encoding: 'utf8', | ||
| }); | ||
| } | ||
|
|
||
| function androidBackground() { | ||
| adbShell('input', 'keyevent', 'KEYCODE_HOME'); | ||
| } | ||
|
|
||
| function androidForeground(packageName) { | ||
| adbShell( | ||
| 'monkey', | ||
| '-p', packageName, | ||
| '-c', 'android.intent.category.LAUNCHER', | ||
| '1', | ||
| ); | ||
| } | ||
|
|
||
| function androidTerminate(packageName) { | ||
| adbShell('am', 'force-stop', packageName); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Public API — platform-agnostic | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| /** | ||
| * Send the app to the OS home screen. | ||
| * @returns {{ bundleId: string }} Resolved app identifier | ||
| */ | ||
| function backgroundApp() { | ||
| const platform = detectPlatform(); | ||
| if (platform === 'ios') { | ||
| const udid = resolveBootedSimulatorUdid(); | ||
| const bundleId = resolveIosBundleId(udid); | ||
| iosBackground(); | ||
| return { bundleId }; | ||
| } | ||
| const packageName = resolveAndroidPackage(); | ||
| androidBackground(); | ||
| return { bundleId: packageName }; | ||
| } | ||
|
|
||
| /** | ||
| * Bring the app back to the foreground. | ||
| * @returns {{ bundleId: string }} | ||
| */ | ||
| function foregroundApp() { | ||
| const platform = detectPlatform(); | ||
| if (platform === 'ios') { | ||
| const udid = resolveBootedSimulatorUdid(); | ||
| const bundleId = resolveIosBundleId(udid); | ||
| iosForeground(udid, bundleId); | ||
| return { bundleId }; | ||
| } | ||
| const packageName = resolveAndroidPackage(); | ||
| androidForeground(packageName); | ||
| return { bundleId: packageName }; | ||
| } | ||
|
|
||
| /** | ||
| * Terminate and relaunch the app. | ||
| * @returns {{ bundleId: string }} | ||
| */ | ||
| function restartApp() { | ||
| const platform = detectPlatform(); | ||
| if (platform === 'ios') { | ||
| const udid = resolveBootedSimulatorUdid(); | ||
| const bundleId = resolveIosBundleId(udid); | ||
| iosTerminate(udid, bundleId); | ||
| iosForeground(udid, bundleId); | ||
| return { bundleId }; | ||
| } | ||
| const packageName = resolveAndroidPackage(); | ||
| androidTerminate(packageName); | ||
| androidForeground(packageName); | ||
| return { bundleId: packageName }; | ||
| } | ||
|
|
||
| module.exports = { | ||
| backgroundApp, | ||
| detectPlatform, | ||
| foregroundApp, | ||
| restartApp, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.