Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

feat(lume): add post_ssh_commands for reliable post-setup configuration (#971)

Francesco Bonaccid09d42d605c1
diff --git a/libs/lume/src/Resources/unattended-presets/sequoia.yml b/libs/lume/src/Resources/unattended-presets/sequoia.yml
index 484a8db537..22ccb4e3cb 100644
--- a/libs/lume/src/Resources/unattended-presets/sequoia.yml
+++ b/libs/lume/src/Resources/unattended-presets/sequoia.yml
@@ -229,35 +229,7 @@ boot_commands:
- "<delay 2>"
# ============================================
- # 3. Disable Screen Lock and Sleep
- # ============================================
- # Disable screen saver
- - "<type 'defaults -currentHost write com.apple.screensaver idleTime -int 0'>"
- - "<enter>"
- - "<delay 1>"
-
- # Disable require password after sleep/screen saver
- - "<type 'defaults write com.apple.screensaver askForPassword -int 0'>"
- - "<enter>"
- - "<delay 1>"
-
- # Prevent display from sleeping (never)
- - "<type 'sudo pmset -a displaysleep 0'>"
- - "<enter>"
- - "<delay 1>"
-
- # Prevent system sleep (never)
- - "<type 'sudo pmset -a sleep 0'>"
- - "<enter>"
- - "<delay 1>"
-
- # Disable auto-logout
- - "<type 'sudo defaults write /Library/Preferences/.GlobalPreferences com.apple.autologout.AutoLogOutDelay -int 0'>"
- - "<enter>"
- - "<delay 1>"
-
- # ============================================
- # 4. Enable Full Disk Access for Remote Users
+ # 3. Enable Full Disk Access for Remote Users
# ============================================
# This requires navigating System Settings GUI since TCC.db is SIP-protected
@@ -320,3 +292,17 @@ health_check:
timeout: 30
retries: 5
retry_delay: 10
+
+# Post-setup commands to run via SSH after health check passes
+# These are more reliable than typing in Terminal via VNC
+post_ssh_commands:
+ # Disable screen saver
+ - "defaults -currentHost write com.apple.screensaver idleTime -int 0"
+ # Disable require password after sleep/screen saver
+ - "defaults write com.apple.screensaver askForPassword -int 0"
+ # Prevent display from sleeping (never)
+ - "sudo pmset -a displaysleep 0"
+ # Prevent system sleep (never)
+ - "sudo pmset -a sleep 0"
+ # Disable auto-logout
+ - "sudo defaults write /Library/Preferences/.GlobalPreferences com.apple.autologout.AutoLogOutDelay -int 0"
diff --git a/libs/lume/src/Resources/unattended-presets/tahoe.yml b/libs/lume/src/Resources/unattended-presets/tahoe.yml
index b93383087b..c82c213bfa 100644
--- a/libs/lume/src/Resources/unattended-presets/tahoe.yml
+++ b/libs/lume/src/Resources/unattended-presets/tahoe.yml
@@ -240,35 +240,7 @@ boot_commands:
- "<delay 2>"
# ============================================
- # 3. Disable Screen Lock and Sleep
- # ============================================
- # Disable screen saver
- - "<type 'defaults -currentHost write com.apple.screensaver idleTime -int 0'>"
- - "<enter>"
- - "<delay 1>"
-
- # Disable require password after sleep/screen saver
- - "<type 'defaults write com.apple.screensaver askForPassword -int 0'>"
- - "<enter>"
- - "<delay 1>"
-
- # Prevent display from sleeping (never)
- - "<type 'sudo pmset -a displaysleep 0'>"
- - "<enter>"
- - "<delay 1>"
-
- # Prevent system sleep (never)
- - "<type 'sudo pmset -a sleep 0'>"
- - "<enter>"
- - "<delay 1>"
-
- # Disable auto-logout
- - "<type 'sudo defaults write /Library/Preferences/.GlobalPreferences com.apple.autologout.AutoLogOutDelay -int 0'>"
- - "<enter>"
- - "<delay 1>"
-
- # ============================================
- # 4. Enable Full Disk Access for Remote Users
+ # 3. Enable Full Disk Access for Remote Users
# ============================================
# This requires navigating System Settings GUI since TCC.db is SIP-protected
@@ -331,3 +303,17 @@ health_check:
timeout: 30
retries: 5
retry_delay: 10
+
+# Post-setup commands to run via SSH after health check passes
+# These are more reliable than typing in Terminal via VNC
+post_ssh_commands:
+ # Disable screen saver
+ - "defaults -currentHost write com.apple.screensaver idleTime -int 0"
+ # Disable require password after sleep/screen saver
+ - "defaults write com.apple.screensaver askForPassword -int 0"
+ # Prevent display from sleeping (never)
+ - "sudo pmset -a displaysleep 0"
+ # Prevent system sleep (never)
+ - "sudo pmset -a sleep 0"
+ # Disable auto-logout
+ - "sudo defaults write /Library/Preferences/.GlobalPreferences com.apple.autologout.AutoLogOutDelay -int 0"
diff --git a/libs/lume/src/Unattended/HealthCheckRunner.swift b/libs/lume/src/Unattended/HealthCheckRunner.swift
index 5b57d4ee5f..8f8304fd7c 100644
--- a/libs/lume/src/Unattended/HealthCheckRunner.swift
+++ b/libs/lume/src/Unattended/HealthCheckRunner.swift
@@ -108,4 +108,78 @@ struct HealthCheckRunner {
])
return false
}
+
+ /// Run post-setup commands via SSH
+ /// These are more reliable than typing commands via VNC
+ func runPostSshCommands(commands: [String], vmIP: String, user: String, password: String) async throws {
+ Logger.info("Running post-SSH commands", metadata: [
+ "host": vmIP,
+ "user": user,
+ "commandCount": "\(commands.count)"
+ ])
+
+ for (index, command) in commands.enumerated() {
+ Logger.info("Executing SSH command", metadata: [
+ "index": "\(index + 1)/\(commands.count)",
+ "command": command.prefix(50).description
+ ])
+
+ // Handle sudo commands by using sudo -S which reads password from stdin
+ let actualCommand: String
+ if command.hasPrefix("sudo ") {
+ // Replace "sudo " with "echo password | sudo -S " to provide password via stdin
+ let sudoCommand = String(command.dropFirst(5)) // Remove "sudo "
+ // Escape single quotes in password for shell: ' becomes '\''
+ let escapedPassword = password.replacingOccurrences(of: "'", with: "'\\''")
+ actualCommand = "echo '\(escapedPassword)' | sudo -S \(sudoCommand)"
+ } else {
+ actualCommand = command
+ }
+
+ let process = Process()
+ process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
+ process.arguments = [
+ "sshpass", "-p", password,
+ "ssh",
+ "-o", "StrictHostKeyChecking=no",
+ "-o", "UserKnownHostsFile=/dev/null",
+ "-o", "ConnectTimeout=30",
+ "-o", "BatchMode=no",
+ "\(user)@\(vmIP)",
+ actualCommand
+ ]
+
+ let outputPipe = Pipe()
+ let errorPipe = Pipe()
+ process.standardOutput = outputPipe
+ process.standardError = errorPipe
+
+ do {
+ try process.run()
+ process.waitUntilExit()
+
+ if process.terminationStatus != 0 {
+ let errorData = errorPipe.fileHandleForReading.readDataToEndOfFile()
+ let errorOutput = String(data: errorData, encoding: .utf8) ?? ""
+ Logger.info("SSH command returned non-zero exit code", metadata: [
+ "command": command.prefix(50).description,
+ "exitCode": "\(process.terminationStatus)",
+ "error": errorOutput.prefix(200).description
+ ])
+ // Continue with other commands even if one fails
+ }
+ } catch {
+ Logger.info("SSH command failed", metadata: [
+ "command": command.prefix(50).description,
+ "error": error.localizedDescription
+ ])
+ // Continue with other commands even if one fails
+ }
+
+ // Small delay between commands
+ try await Task.sleep(nanoseconds: 500_000_000) // 0.5s
+ }
+
+ Logger.info("Post-SSH commands completed")
+ }
}
diff --git a/libs/lume/src/Unattended/UnattendedConfig.swift b/libs/lume/src/Unattended/UnattendedConfig.swift
index def5f98eed..ffd0605e3c 100644
--- a/libs/lume/src/Unattended/UnattendedConfig.swift
+++ b/libs/lume/src/Unattended/UnattendedConfig.swift
@@ -51,16 +51,22 @@ struct UnattendedConfig: Codable, Sendable {
/// Optional health check to verify setup success
let healthCheck: HealthCheck?
+ /// Optional commands to run via SSH after health check passes
+ /// These are more reliable than typing in Terminal via VNC
+ let postSshCommands: [String]?
+
enum CodingKeys: String, CodingKey {
case bootWait = "boot_wait"
case bootCommands = "boot_commands"
case healthCheck = "health_check"
+ case postSshCommands = "post_ssh_commands"
}
- init(bootWait: Int = 60, bootCommands: [String], healthCheck: HealthCheck? = nil) {
+ init(bootWait: Int = 60, bootCommands: [String], healthCheck: HealthCheck? = nil, postSshCommands: [String]? = nil) {
self.bootWait = bootWait
self.bootCommands = bootCommands
self.healthCheck = healthCheck
+ self.postSshCommands = postSshCommands
}
/// Load configuration from a YAML file path or preset name
diff --git a/libs/lume/src/Unattended/UnattendedInstaller.swift b/libs/lume/src/Unattended/UnattendedInstaller.swift
index 51d456a650..70f5eebc3a 100644
--- a/libs/lume/src/Unattended/UnattendedInstaller.swift
+++ b/libs/lume/src/Unattended/UnattendedInstaller.swift
@@ -140,6 +140,18 @@ final class UnattendedInstaller {
if passed {
Logger.info("Health check passed ✓", metadata: ["type": healthCheck.type])
+
+ // Run post-SSH commands if configured (more reliable than VNC typing)
+ if let postCommands = config.postSshCommands, !postCommands.isEmpty {
+ Logger.info("Running post-SSH commands", metadata: ["count": "\(postCommands.count)"])
+ try await runner.runPostSshCommands(
+ commands: postCommands,
+ vmIP: vmIP,
+ user: healthCheck.user ?? "lume",
+ password: healthCheck.password ?? "lume"
+ )
+ Logger.info("Post-SSH commands completed ✓")
+ }
} else {
Logger.error("Health check failed ✗", metadata: ["type": healthCheck.type])
throw UnattendedError.healthCheckFailed("Health check '\(healthCheck.type)' failed")