Repository navigation
feat(jev): support windows workflows and grouped steps #520
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
Open
yichen11818
wants to merge
5
commits into
vercel-labs:main
Choose a base branch
from
yichen11818:codex/jev-windows-flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
14cb71d
fix(jev): run on windows and read deep electron windows
yichen11818 6ce67a1
feat(jev): run several known steps per screen with flow.mjs
yichen11818 5fb8092
test(jev): isolate binary lookup from local builds
yichen11818 6d902fa
fix(jev): preserve retry policy across partial batches
yichen11818 24dd146
fix(jev): ignore the windows title bar menu
yichen11818 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /** | ||
| * Which agent-desktop binary the scripts start, and the snapshot flags every | ||
| * read shares. Both entry points read the screen the same way, so both take | ||
| * these from here. | ||
| * | ||
| * On Windows a bare `agent-desktop` cannot be started by execFileSync: npm | ||
| * installs a `.cmd` and a `.ps1` shim, and Node refuses to spawn either without | ||
| * a shell. A shell would re-parse the supplied text, so the native executable | ||
| * the npm package ships is found instead, next to the shim on PATH. | ||
| */ | ||
| import { existsSync } from "node:fs"; | ||
| import { delimiter, dirname, join } from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const REPO = join(dirname(fileURLToPath(import.meta.url)), "..", ".."); | ||
|
|
||
| const npmNative = (env, arch) => { | ||
| for (const dir of (env.PATH ?? env.Path ?? "").split(delimiter).filter(Boolean)) { | ||
| if (!existsSync(join(dir, "agent-desktop.cmd"))) continue; | ||
| const exe = join(dir, "node_modules", "agent-desktop", "bin", `agent-desktop-win32-${arch}.exe`); | ||
| if (existsSync(exe)) return exe; | ||
| } | ||
| return null; | ||
| }; | ||
|
|
||
| const releaseBuild = (platform) => join(REPO, "target", "release", platform === "win32" ? "agent-desktop.exe" : "agent-desktop"); | ||
|
|
||
| export const defaultBin = ({ platform = process.platform, arch = process.arch, env = process.env, release = releaseBuild(platform) } = {}) => { | ||
| if (existsSync(release)) return release; | ||
| if (platform === "win32") return npmNative(env, arch) ?? "agent-desktop.exe"; | ||
| return "agent-desktop"; | ||
| }; | ||
|
|
||
| const bounded = (name, raw, min, max) => { | ||
| if (raw === undefined || raw === "") return null; | ||
| const value = Number(raw); | ||
| if (!Number.isInteger(value) || value < min || value > max) { | ||
| throw new Error(`${name} must be a whole number from ${min} to ${max}, not ${JSON.stringify(raw)}`); | ||
| } | ||
| return String(value); | ||
| }; | ||
|
|
||
| /** | ||
| * A Chromium or Electron window can take longer than the CLI's 3 s default to | ||
| * settle, and its controls often sit deeper than the default depth of 10, where | ||
| * a read returns a tree without them. Both stay at the CLI defaults unless set. | ||
| */ | ||
| export const snapshotFlags = ({ depth = true, env = process.env } = {}) => { | ||
| const timeout = bounded("JEV_SNAPSHOT_TIMEOUT_MS", env.JEV_SNAPSHOT_TIMEOUT_MS, 1, 120000); | ||
| const maxDepth = depth ? bounded("JEV_SNAPSHOT_MAX_DEPTH", env.JEV_SNAPSHOT_MAX_DEPTH, 1, 100) : null; | ||
| return [...(timeout ? ["--timeout-ms", timeout] : []), ...(maxDepth ? ["--max-depth", maxDepth] : [])]; | ||
| }; | ||
|
|
||
| export const pasteCombo = (platform = process.platform) => (platform === "darwin" ? "cmd+v" : "ctrl+v"); | ||
|
|
||
| /** | ||
| * A minimized window answers a snapshot with an empty tree or a timeout, which | ||
| * reads like a broken application. The window list says which it is. | ||
| */ | ||
| export const minimizedHint = (cli, app, windowId) => { | ||
| const listed = cli("list-windows", "--app", app); | ||
| if (!listed.ok || !Array.isArray(listed.data)) return null; | ||
| const windows = windowId ? listed.data.filter((w) => w.id === windowId) : listed.data; | ||
| const shut = windows.filter((w) => w.minimized); | ||
| if (!shut.length || shut.length !== windows.length) return null; | ||
| return `the window is minimized; run agent-desktop restore --window-id ${shut[0].id} and try again`; | ||
| }; | ||
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,62 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
|
|
||
| import { defaultBin, minimizedHint, pasteCombo, snapshotFlags } from "./bin.mjs"; | ||
|
|
||
| assert.equal(pasteCombo("darwin"), "cmd+v"); | ||
| assert.equal(pasteCombo("win32"), "ctrl+v"); | ||
| assert.equal(pasteCombo("linux"), "ctrl+v"); | ||
|
|
||
| assert.deepEqual(snapshotFlags({ env: {} }), []); | ||
| assert.deepEqual(snapshotFlags({ env: { JEV_SNAPSHOT_TIMEOUT_MS: "15000" } }), ["--timeout-ms", "15000"]); | ||
| assert.deepEqual(snapshotFlags({ env: { JEV_SNAPSHOT_TIMEOUT_MS: "15000", JEV_SNAPSHOT_MAX_DEPTH: "30" } }), | ||
| ["--timeout-ms", "15000", "--max-depth", "30"]); | ||
| assert.deepEqual(snapshotFlags({ depth: false, env: { JEV_SNAPSHOT_MAX_DEPTH: "30" } }), [], | ||
| "a skeleton read keeps the CLI depth so the shallow first look stays shallow"); | ||
| for (const bad of ["0", "-1", "1.5", "abc", "120001"]) { | ||
| assert.throws(() => snapshotFlags({ env: { JEV_SNAPSHOT_TIMEOUT_MS: bad } }), /JEV_SNAPSHOT_TIMEOUT_MS/, bad); | ||
| } | ||
| assert.throws(() => snapshotFlags({ env: { JEV_SNAPSHOT_MAX_DEPTH: "101" } }), /JEV_SNAPSHOT_MAX_DEPTH/); | ||
|
|
||
| const absent = join(tmpdir(), "jev-no-release-build"); | ||
| assert.equal(defaultBin({ platform: "linux", env: {}, release: absent }), "agent-desktop"); | ||
| assert.equal(defaultBin({ platform: "darwin", env: {}, release: absent }), "agent-desktop"); | ||
|
|
||
| const directory = mkdtempSync(join(tmpdir(), "jev-bin-test-")); | ||
| try { | ||
| const shims = join(directory, "npm"); | ||
| const native = join(shims, "node_modules", "agent-desktop", "bin"); | ||
| mkdirSync(native, { recursive: true }); | ||
| writeFileSync(join(shims, "agent-desktop.cmd"), ""); | ||
| writeFileSync(join(native, "agent-desktop-win32-x64.exe"), ""); | ||
| const empty = join(directory, "elsewhere"); | ||
| mkdirSync(empty); | ||
| const path = [empty, shims].join(process.platform === "win32" ? ";" : ":"); | ||
|
|
||
| assert.equal(defaultBin({ platform: "win32", arch: "x64", env: { PATH: path }, release: absent }), | ||
| join(native, "agent-desktop-win32-x64.exe"), "the npm shim on PATH leads to the shipped executable"); | ||
| assert.equal(defaultBin({ platform: "win32", arch: "x64", env: { Path: path }, release: absent }), | ||
| join(native, "agent-desktop-win32-x64.exe"), "Windows spells the variable Path"); | ||
| assert.equal(defaultBin({ platform: "win32", arch: "arm64", env: { PATH: path }, release: absent }), "agent-desktop.exe", | ||
| "an executable for another architecture is not used"); | ||
| assert.equal(defaultBin({ platform: "win32", arch: "x64", env: { PATH: empty }, release: absent }), "agent-desktop.exe"); | ||
| const release = join(directory, "agent-desktop.exe"); | ||
| writeFileSync(release, ""); | ||
| assert.equal(defaultBin({ platform: "win32", arch: "x64", env: { PATH: path }, release }), release, | ||
| "a release build in the clone wins over the installed package"); | ||
| } finally { | ||
| rmSync(directory, { recursive: true, force: true }); | ||
| } | ||
|
|
||
| const listing = (windows) => () => ({ ok: true, data: windows }); | ||
| assert.match(minimizedHint(listing([{ id: "w-1", minimized: true }]), "App", null), /restore --window-id w-1/); | ||
| assert.equal(minimizedHint(listing([{ id: "w-1", minimized: false }]), "App", null), null); | ||
| assert.equal(minimizedHint(listing([{ id: "w-1", minimized: true }, { id: "w-2", minimized: false }]), "App", null), null, | ||
| "one open window means minimizing is not why the read failed"); | ||
| assert.match(minimizedHint(listing([{ id: "w-1", minimized: true }, { id: "w-2", minimized: false }]), "App", "w-1"), | ||
| /w-1/, "a pinned window is judged on its own"); | ||
| assert.equal(minimizedHint(() => ({ ok: false, error: { code: "APP_NOT_FOUND" } }), "App", null), null); | ||
|
|
||
| console.log("ok"); |
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,71 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { spawnSync } from "node:child_process"; | ||
| import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { fileURLToPath, pathToFileURL } from "node:url"; | ||
|
|
||
| const directory = mkdtempSync(join(tmpdir(), "jev-flow-test-")); | ||
| const log = join(directory, "batches.jsonl"); | ||
| const preload = join(directory, "fetch.mjs"); | ||
| const entry = new URL("./flow.mjs", import.meta.url); | ||
|
|
||
| writeFileSync(join(directory, "snapshot"), ` | ||
| const nodes = [1, 2].map(i => ({ref_id:'@s1:e'+i,role:'button',name:'Button '+i,available_actions:['Click']})); | ||
| const result = process.argv.includes('--surface') | ||
| ? {ok:false,error:{code:'INVALID_ARGS'}} | ||
| : {ok:true,data:{window:{id:'w-1',title:'Fixture'},tree:{role:'window',children:nodes}}}; | ||
| console.log(JSON.stringify(result)); | ||
| `); | ||
| writeFileSync(join(directory, "batch"), ` | ||
| const fs = require('node:fs'); | ||
| const entries = JSON.parse(process.argv.at(-1)); | ||
| const before = fs.readFileSync(process.env.JEV_TEST_LOG, 'utf8'); | ||
| fs.appendFileSync(process.env.JEV_TEST_LOG, JSON.stringify(entries)+'\\n'); | ||
| const safe = process.env.JEV_TEST_MODE === 'stale_safe'; | ||
| const error = {code:process.env.JEV_TEST_MODE === 'timeout' ? 'TIMEOUT' : 'STALE_REF', | ||
| disposition:{retry:safe?'safe':'unsafe',delivery:safe?'not_delivered':'delivery_uncertain'}}; | ||
| console.log(JSON.stringify({ok:true,data:{results:before ? [{ok:true}] : [{ok:true},{ok:false,error}]}})); | ||
| `); | ||
| writeFileSync(preload, ` | ||
| globalThis.fetch = async (_url, options) => { | ||
| const request = JSON.parse(options.body); | ||
| const answers = Object.fromEntries(Object.keys(request.questions).map(key => [key, | ||
| key.startsWith('target_') | ||
| ? {type:'choice',choice:'@s1:e'+(Number(key.split('_')[1])+1),confidence:0.99} | ||
| : {type:'noul',noul:0.1}])); | ||
| return {ok:true,json:async()=>({answers})}; | ||
| }; | ||
| `); | ||
|
|
||
| try { | ||
| for (const mode of ["timeout", "stale_unsafe", "stale_safe"]) { | ||
| writeFileSync(log, ""); | ||
| const result = spawnSync(process.execPath, ["--import", pathToFileURL(preload).href, | ||
| fileURLToPath(entry), "--app", "Fixture", "--window-id", "w-1", | ||
| "--execute", "Button 1", "Button 2"], { | ||
| cwd: directory, encoding: "utf8", timeout: 10000, | ||
| env: { ...process.env, TYPESAFE_API_KEY: "fixture", AGENT_DESKTOP_BIN: process.execPath, | ||
| JEV_TEST_LOG: log, JEV_TEST_MODE: mode }, | ||
| }); | ||
| assert.ifError(result.error); | ||
| const events = result.stdout.trim().split("\n").map(JSON.parse); | ||
| const batches = readFileSync(log, "utf8").trim().split("\n").map(JSON.parse); | ||
| const last = events.at(-1); | ||
| if (mode === "stale_safe") { | ||
| assert.equal(result.status, 0, result.stderr); | ||
| assert.equal(last.done, true); | ||
| assert.equal(batches.length, 2); | ||
| assert.equal(batches[1].length, 1, "a completed step is never replayed"); | ||
| assert.equal(batches[1][0].args.ref_id, "@s1:e2"); | ||
| } else { | ||
| assert.equal(result.status, 1, mode); | ||
| assert.equal(last.stop, "action_failed", mode); | ||
| assert.equal(batches.length, 1, "partial success does not permit retrying an unsafe error"); | ||
| } | ||
| } | ||
| } finally { | ||
| rmSync(directory, { recursive: true, force: true }); | ||
| } | ||
|
|
||
| console.log("ok"); |
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.
With a local npm installation on Windows and no release build, binary lookup misses the executable beside node_modules/.bin and JEv fails to launch agent-desktop.