Repository navigation
computer use #382
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
computer use #382
Changes from all commits
Commits
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
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,16 @@ | ||
| import { expect, test } from "bun:test" | ||
| import { createHash } from "node:crypto" | ||
| import { computerArtifact, verifyComputerArchive } from "./provision-computer" | ||
|
|
||
| test("desktop targets use pinned runtimes and reject unsupported targets", () => { | ||
| expect(computerArtifact("aarch64-apple-darwin")).toEqual(computerArtifact("x86_64-apple-darwin")) | ||
| expect(computerArtifact("x86_64-pc-windows-msvc").binary).toBe("cua-driver.exe") | ||
| expect(() => computerArtifact("unknown")).toThrow("Unsupported") | ||
| }) | ||
|
|
||
| test("a modified archive cannot be staged as the bundled runtime", () => { | ||
| const bytes = Buffer.from("verified archive") | ||
| const digest = createHash("sha256").update(bytes).digest("hex") | ||
| verifyComputerArchive(bytes, digest) | ||
| expect(() => verifyComputerArchive(Buffer.from("modified archive"), digest)).toThrow("checksum mismatch") | ||
| }) |
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,72 @@ | ||
| import { createHash } from "node:crypto" | ||
| import { chmod, cp, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises" | ||
| import { tmpdir } from "node:os" | ||
| import { dirname, join, resolve } from "node:path" | ||
| import { fileURLToPath } from "node:url" | ||
|
|
||
| // Pinned upstream release assets; never download or install software at runtime. | ||
| // https://github.com/trycua/cua/releases/tag/cua-driver-rs-v0.62.1 | ||
| const VERSION = "0.62.1" | ||
| export function computerArtifact(target: string): { name: string; sha256: string; binary: string } { | ||
| if (["aarch64-apple-darwin", "x86_64-apple-darwin"].includes(target)) return { | ||
| name: `cua-driver-rs-${VERSION}-darwin-universal-binary.tar.gz`, | ||
| sha256: "05ed121a1c57c83c8af22914e93ea02b1795e5d971b6761deaf6d6edb951f5f8", | ||
| binary: "cua-driver", | ||
| } | ||
| if (target === "x86_64-pc-windows-msvc") return { | ||
| name: `cua-driver-rs-${VERSION}-windows-x86_64-binary.zip`, | ||
| sha256: "6fce4254c42dfbf1cbd2d03340da259c5e3cd0d31254907322629c2d89675d9d", | ||
| binary: "cua-driver.exe", | ||
| } | ||
| throw new Error(`Unsupported computer runtime target: ${target}`) | ||
| } | ||
|
|
||
| export function verifyComputerArchive(bytes: Uint8Array, expected: string): void { | ||
| if (createHash("sha256").update(bytes).digest("hex") !== expected) throw new Error("Computer runtime checksum mismatch") | ||
| } | ||
|
|
||
| async function run(command: string, args: string[]): Promise<void> { | ||
| const child = Bun.spawn([command, ...args], { stdout: "inherit", stderr: "inherit" }) | ||
| if (await child.exited !== 0) throw new Error(`Computer runtime ${command} failed`) | ||
| } | ||
|
|
||
| async function provision(): Promise<void> { | ||
| const host = Bun.spawnSync(["rustc", "--print", "host-tuple"]) | ||
| if (host.exitCode !== 0) throw new Error("Rust is required to select the desktop target") | ||
| const target = process.argv[2] ?? host.stdout.toString().trim() | ||
| const artifact = computerArtifact(target) | ||
| const base = resolve(dirname(fileURLToPath(import.meta.url)), "../src-tauri/resources") | ||
| await mkdir(base, { recursive: true }) | ||
| const temporary = await mkdtemp(join(tmpdir(), "nova-computer-")) | ||
| try { | ||
| let bytes: Uint8Array | ||
| if (process.env.NOVA_CUA_ARCHIVE) { | ||
| bytes = await readFile(process.env.NOVA_CUA_ARCHIVE) | ||
| } else { | ||
| const response = await fetch(`https://github.com/trycua/cua/releases/download/cua-driver-rs-v${VERSION}/${artifact.name}`) | ||
| if (!response.ok) throw new Error(`Could not download computer runtime: ${response.status}`) | ||
| bytes = new Uint8Array(await response.arrayBuffer()) | ||
| } | ||
| verifyComputerArchive(bytes, artifact.sha256) | ||
| const archive = join(temporary, artifact.name) | ||
| await writeFile(archive, bytes) | ||
| const extracted = join(temporary, "runtime") | ||
| await mkdir(extracted) | ||
| await run("tar", ["-xf", archive, "-C", extracted]) | ||
| const binary = join(extracted, artifact.binary) | ||
| await chmod(binary, 0o755) | ||
| if (target.endsWith("apple-darwin")) { | ||
| if (process.platform !== "darwin") throw new Error("Provision the macOS runtime on a Mac so it can be signed") | ||
| await run("codesign", ["--force", "--identifier", "ai.supercode.nova.desktop.computer", "--sign", process.env.APPLE_SIGNING_IDENTITY ?? "-", binary]) | ||
| } | ||
| // Replace only the generated runtime directory after download verification. | ||
| const destination = join(base, "cua-driver") | ||
| await rm(destination, { recursive: true, force: true }) | ||
| await cp(extracted, destination, { recursive: true }) | ||
| process.stdout.write(`Bundled computer runtime ${VERSION} for ${target}\n`) | ||
| } finally { | ||
| await rm(temporary, { recursive: true, force: true }) | ||
| } | ||
| } | ||
|
|
||
| if (import.meta.main) await provision() | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nova declares macOS 12 support, but the bundled driver requires macOS 13.
tauri.bundle.conf.jsonsetsmacOS.minimumSystemVersionto12.0. The script provisions the same universal Cua Driver 0.62.1 archive for both Apple targets. The upstream release listing for 0.62.1, as mirrored by OpenNavo, states "macOS 13 or later." The script does not check the host macOS version.On macOS 12, the app can install and start, but computer use can fail at runtime because the bundled
cua-drivermay not support that OS.Align the declared minimum with the driver's requirement before merge. Either set
minimumSystemVersionto13.0, or keep12.0and disable computer use on macOS 12 with a clear message.