From 0f8ab97147381fc31ec1335ac01ef0328271a66b Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:44:23 -0500 Subject: [PATCH 01/12] feat(tern): add desktop engine --- .changeset/tern-engine.md | 5 + README.md | 2 +- docs/docs.json | 1 + docs/tern.mdx | 43 ++++ package.json | 4 +- packages/tern/NOTICE | 4 + packages/tern/README.md | 33 +++ packages/tern/package.json | 33 +++ packages/tern/src/drive.ts | 56 +++++ packages/tern/src/index.ts | 332 ++++++++++++++++++++++++++++++ packages/tern/src/tree.ts | 177 ++++++++++++++++ packages/tern/src/tsp.ts | 35 ++++ packages/tern/tests/tree.test.ts | 72 +++++++ packages/tern/tests/tsp.test.ts | 16 ++ packages/tern/tsconfig.build.json | 6 + packages/tern/tsconfig.json | 6 + pnpm-lock.yaml | 16 ++ 17 files changed, 838 insertions(+), 3 deletions(-) create mode 100644 .changeset/tern-engine.md create mode 100644 docs/tern.mdx create mode 100644 packages/tern/NOTICE create mode 100644 packages/tern/README.md create mode 100644 packages/tern/package.json create mode 100644 packages/tern/src/drive.ts create mode 100644 packages/tern/src/index.ts create mode 100644 packages/tern/src/tree.ts create mode 100644 packages/tern/src/tsp.ts create mode 100644 packages/tern/tests/tree.test.ts create mode 100644 packages/tern/tests/tsp.test.ts create mode 100644 packages/tern/tsconfig.build.json create mode 100644 packages/tern/tsconfig.json diff --git a/.changeset/tern-engine.md b/.changeset/tern-engine.md new file mode 100644 index 0000000000..5d6da84fec --- /dev/null +++ b/.changeset/tern-engine.md @@ -0,0 +1,5 @@ +--- +"@e2e-dev/tern": minor +--- + +Add the Tern desktop/TUI engine, using Tern's structured control surface for semantic observation and standard e2e actions for input. diff --git a/README.md b/README.md index 874dbfd09a..a16d1f67d9 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Flutter, each a standalone project with a passing suite. | --- | --- | | [`e2e`](https://www.npmjs.com/package/e2e) | The SDK, runner, and CLI. | | [`@e2e-dev/web`](https://www.npmjs.com/package/@e2e-dev/web) | Browser engine: Chromium, Firefox, and WebKit through Playwright. | -| [`@e2e-dev/mobile`](https://www.npmjs.com/package/@e2e-dev/mobile) | iOS and Android engine: simulators and emulators through agent-device. | +| [`@e2e-dev/mobile`](https://www.npmjs.com/package/@e2e-dev/mobile) | iOS and Android engine: simulators and emulators through agent-device. |\n| [`@e2e-dev/tern`](https://www.npmjs.com/package/@e2e-dev/tern) | Desktop/TUI engine through Tern's structured control surface. | | [`@e2e-dev/github`](https://www.npmjs.com/package/@e2e-dev/github) | Reporter that posts results as a pull request comment. | | [`@e2e-dev/kernel`](https://www.npmjs.com/package/@e2e-dev/kernel) | Kernel hosted browsers for the web engine. | | [`@e2e-dev/eas`](https://www.npmjs.com/package/@e2e-dev/eas) | EAS Simulators hosted iOS simulators and Android emulators for the mobile engine. | diff --git a/docs/docs.json b/docs/docs.json index 59d48138c6..8e9e905ec9 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -143,6 +143,7 @@ "pages": [ "web", "mobile", + "tern", "api-testing" ] }, diff --git a/docs/tern.mdx b/docs/tern.mdx new file mode 100644 index 0000000000..f357ff2a7a --- /dev/null +++ b/docs/tern.mdx @@ -0,0 +1,43 @@ +--- +title: Tern +description: Test terminal and TUI surfaces through Tern's structured control plane. +icon: "terminal" +--- + +`ternEngine()` from `@e2e-dev/tern` connects e2e to a Tern pane through the +same public engine contract used by web and mobile. + +It prefers Tern's structured control surface—accessibility nodes, element +geometry, pane state, and native input—so locators and agent actions operate on +current UI evidence instead of an opaque screenshot. + +## Setup + +```bash +pnpm add -D @e2e-dev/tern +``` + +```ts title="e2e.config.ts" +import type { E2EConfig } from 'e2e'; +import { ternEngine } from '@e2e-dev/tern'; + +export default { + targets: [{ + name: 'tui', + engine: ternEngine({ pane: process.env.TERN_PANE, control: process.env.TERN_CONTROL }), + app: {}, + }], +} satisfies E2EConfig; +``` + +`control` defaults to `TERN_CONTROL` and then Tern's default control socket. +Without `pane`, the engine creates a fresh Tern tab for each attempt using +`command` and closes it during teardown. + +With a reachable control socket it reads `state`, `a11y`, and `tree` and +maps them into e2e semantic nodes. If that surface is unavailable it falls back +to surface/scrollback capture; an optional TSP record can preserve tool-card +heads in that fallback. + +Input stays on e2e's standard action vocabulary. No Tern-specific verbs are +added to runner core. diff --git a/package.json b/package.json index a53a86afaa..8042bc14e4 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ ], "type": "module", "scripts": { - "build": "pnpm --filter e2e run build && pnpm --filter @e2e-dev/web run build && pnpm --filter @e2e-dev/mobile run build && pnpm --filter @e2e-dev/github run build && pnpm --filter @e2e-dev/kernel run build && pnpm --filter @e2e-dev/eas run build && pnpm --filter @e2e-dev/decision run build", + "build": "pnpm --filter e2e run build && pnpm --filter @e2e-dev/web run build && pnpm --filter @e2e-dev/mobile run build && pnpm --filter @e2e-dev/github run build && pnpm --filter @e2e-dev/kernel run build && pnpm --filter @e2e-dev/eas run build && pnpm --filter @e2e-dev/decision run build && pnpm --filter @e2e-dev/tern run build", "check": "pnpm run lint && pnpm run check:dead-code && pnpm run typecheck && pnpm run docs:check-errors && pnpm run check:peer-ranges && pnpm run check:install-scripts && pnpm run docs:check", "check:dead-code": "fallow dead-code", "check:peer-ranges": "node scripts/check-peer-ranges.ts", @@ -25,7 +25,7 @@ "canary": "node scripts/canary-changeset.ts && changeset version --snapshot canary && pnpm run build", "canary:publish": "changeset publish --tag canary --no-git-tag && node scripts/restore-peer-ranges.ts", "typecheck": "pnpm run build && pnpm -r run typecheck && tsc -p scripts", - "test": "pnpm run build && pnpm --filter e2e run test && pnpm --filter @e2e-dev/web run test && pnpm --filter @e2e-dev/mobile run test && pnpm --filter @e2e-dev/github run test && pnpm --filter @e2e-dev/kernel run test && pnpm --filter @e2e-dev/eas run test && pnpm --filter @e2e-dev/decision run test && pnpm run test:scripts", + "test": "pnpm run build && pnpm --filter e2e run test && pnpm --filter @e2e-dev/web run test && pnpm --filter @e2e-dev/mobile run test && pnpm --filter @e2e-dev/github run test && pnpm --filter @e2e-dev/kernel run test && pnpm --filter @e2e-dev/eas run test && pnpm --filter @e2e-dev/decision run test && pnpm --filter @e2e-dev/tern run test && pnpm run test:scripts", "test:testbed": "pnpm run build && pnpm --filter @e2e-dev/testbed test", "test:web-benchmark": "pnpm run build && pnpm --filter @e2e-dev/web-benchmark test", "test:mobile-benchmark": "pnpm run build && pnpm --filter @e2e-dev/mobile-benchmark test", diff --git a/packages/tern/NOTICE b/packages/tern/NOTICE new file mode 100644 index 0000000000..a7b3323674 --- /dev/null +++ b/packages/tern/NOTICE @@ -0,0 +1,4 @@ +@e2e-dev/tern +Copyright 2026 contributors to tester-army/e2e + +This product includes software developed for the tester-army/e2e project. diff --git a/packages/tern/README.md b/packages/tern/README.md new file mode 100644 index 0000000000..1582b73422 --- /dev/null +++ b/packages/tern/README.md @@ -0,0 +1,33 @@ +# @e2e-dev/tern + +Tern desktop/TUI engine for [e2e](https://www.npmjs.com/package/e2e). + +It reads Tern's structured control surface and drives input through Tern while +keeping the runner on the standard `e2e/engine` contract. + +## Usage + +```ts +import type { E2EConfig } from 'e2e'; +import { ternEngine } from '@e2e-dev/tern'; + +export default { + targets: [{ + name: 'tui', + engine: ternEngine({ pane: process.env.TERN_PANE, control: process.env.TERN_CONTROL }), + app: {}, + }], +} satisfies E2EConfig; +``` + +When `pane` is omitted, every attempt gets a fresh Tern tab using `command` +(a shell by default), and teardown closes it. + +## Credit + +Initial Tern engine implementation by Kevin Rajan ([kvnloo](https://github.com/kvnloo)), +built on e2e's `defineEngine` contract and Tern/TSP's control surface. + +## License + +Apache-2.0 diff --git a/packages/tern/package.json b/packages/tern/package.json new file mode 100644 index 0000000000..5b741fcab2 --- /dev/null +++ b/packages/tern/package.json @@ -0,0 +1,33 @@ +{ + "name": "@e2e-dev/tern", + "version": "0.0.1", + "description": "Tern desktop engine for e2e agentic end-to-end testing", + "keywords": ["e2e", "end-to-end", "testing", "agentic", "desktop-testing", "terminal", "tui", "tern"], + "license": "Apache-2.0", + "repository": { + "type": "git", + "url": "git+https://github.com/tester-army/e2e.git", + "directory": "packages/tern" + }, + "bugs": {"url": "https://github.com/tester-army/e2e/issues"}, + "homepage": "https://github.com/tester-army/e2e/tree/main/packages/tern#readme", + "publishConfig": {"registry": "https://registry.npmjs.org/", "access": "public", "tag": "latest"}, + "type": "module", + "exports": {".": {"types": "./dist/index.d.ts", "default": "./dist/index.js"}}, + "files": ["dist", "NOTICE"], + "scripts": { + "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc --project tsconfig.build.json && node ../../scripts/stamp-dist.ts", + "prepublishOnly": "node ../../scripts/check-dist.ts", + "typecheck": "tsc --noEmit", + "test": "vitest run", + "test:watch": "vitest" + }, + "peerDependencies": {"e2e": ">=0.18.0 <1"}, + "devDependencies": { + "@types/node": "26.6.2", + "e2e": "workspace:*", + "typescript": "7.0.2", + "vitest": "5.0.1" + }, + "engines": {"node": "^22.22.3 || >=24.8.0"} +} diff --git a/packages/tern/src/drive.ts b/packages/tern/src/drive.ts new file mode 100644 index 0000000000..bc51ef86ef --- /dev/null +++ b/packages/tern/src/drive.ts @@ -0,0 +1,56 @@ +import { parseKey, type Key, type ParsedKey } from "e2e/engine"; + +import type { Box } from "./tree.ts"; + +export interface Cell { + readonly col: number; + readonly row: number; +} + +const NAMED: Readonly> = { + ArrowDown: "down", + ArrowLeft: "left", + ArrowRight: "right", + ArrowUp: "up", + Backspace: "backspace", + Delete: "delete", + End: "end", + Enter: "enter", + Escape: "escape", + Home: "home", + Insert: "insert", + PageDown: "pagedown", + PageUp: "pageup", + Space: "space", + Tab: "tab", +}; + +/** The cell under the center of `rect`, inside a pane of `cols` by `rows`. */ +export function cellAt(rect: Box, pane: Box, cols: number, rows: number): Cell { + const width = pane.width / Math.max(1, cols); + const height = pane.height / Math.max(1, rows); + const col = Math.min(cols - 1, Math.max(0, Math.floor((rect.x + rect.width / 2 - pane.x) / width))); + const row = Math.min(rows - 1, Math.max(0, Math.floor((rect.y + rect.height / 2 - pane.y) / height))); + return { col, row }; +} + +/** A `press` key as `tern send` spells a combo. */ +export function ternCombo(key: Key): string | undefined { + const parsed = parseKey(key); + if (parsed === undefined) return undefined; + return comboOf(parsed); +} + +function comboOf(parsed: ParsedKey): string { + const mods = parsed.modifiers.map((mod) => (mod === "Control" || mod === "ControlOrMeta" ? "ctrl" : mod === "Alt" ? "alt" : mod === "Shift" ? "shift" : "super")); + const name = parsed.key.kind === "char" ? parsed.key.char : (NAMED[parsed.key.name] ?? parsed.key.name.toLowerCase()); + return [...mods, name].join("+"); +} + +/** Keys that scroll the focused pane. A finger moving up reveals what is below. */ +export function scrollKeys(direction: "up" | "down" | "left" | "right"): string { + if (direction === "up") return "pagedown"; + if (direction === "down") return "pageup"; + if (direction === "left") return "right"; + return "left"; +} diff --git a/packages/tern/src/index.ts b/packages/tern/src/index.ts new file mode 100644 index 0000000000..8a740324f4 --- /dev/null +++ b/packages/tern/src/index.ts @@ -0,0 +1,332 @@ +import { execFile } from "node:child_process"; +import { readdir, readFile } from "node:fs/promises"; +import { createRequire } from "node:module"; +import { promisify } from "node:util"; +import { createHash } from "node:crypto"; +import { + defineEngine, + EngineError, + resolveExpression, + type EngineHandle, + type Key, + type LocatorAction, + type SemanticNode, + type ViewportSize, +} from "e2e/engine"; +import { cellAt, scrollKeys, ternCombo } from "./drive.ts"; +import { toolCards } from "./tsp.ts"; +import { boxOf, hitsOf, semanticTree, type A11yNode, type Box, type ElementNode, type Hit } from "./tree.ts"; + +const exec = promisify(execFile); + +/** This package's published version, read through require resolution. */ +function ownVersion(): string { + try { + return (createRequire(import.meta.url)("../package.json") as { version: string }).version; + } catch { + return "unknown"; + } +} + +export interface TernOptions { + /** Program the attempt launches in a new pane. Default: a shell. */ + readonly command?: readonly string[]; + /** Observe this pane instead of launching one. */ + readonly pane?: string; + /** Optional TSP record. Tool heads come from this file when the control tree is absent. */ + readonly record?: string; + /** Control socket. Default: `TERN_CONTROL`, else the socket whose state lists the pane. */ + readonly control?: string; +} + +interface PaneGrid { + readonly box: Box; + readonly cols: number; + readonly rows: number; +} + +async function tern(args: string[]): Promise { + const result = await exec("tern", args, { encoding: "utf8", maxBuffer: 8 * 1024 * 1024 }); + return result.stdout; +} + +async function ctl(socket: string, command: string): Promise { + const stdout = await tern(["ctl", "--control", socket, command]); + return JSON.parse(stdout) as unknown; +} + +function textNodes(capture: string): SemanticNode[] { + const seen = new Map(); + return capture + .split("\n") + .map((line) => line.trim()) + .filter((line) => line.length > 0) + .map((line) => { + const digest = createHash("sha1").update(line).digest("hex").slice(0, 12); + const n = (seen.get(digest) ?? 0) + 1; + seen.set(digest, n); + return { + ref: { id: n === 1 ? `cap:${digest}` : `cap:${digest}#${n}`, revision: "" }, + role: "status" as const, + name: line, + text: line, + }; + }); +} + +function recordNodes(record: string): SemanticNode[] { + return toolCards(record).map((card) => ({ + ref: { id: card.id === "" ? `tool:${card.name}:${card.target}` : `tool:${card.id}`, revision: "" }, + role: "button" as const, + name: card.name, + text: card.target, + ...(card.status === "error" ? { states: { invalid: true } } : {}), + })); +} + +/** One Tern pane. Observe the control tree. Act through the tern CLI. */ +export function ternEngine(options: TernOptions = {}): EngineHandle { + let pane = options.pane; + let owned = false; + let socket = options.control ?? process.env.TERN_CONTROL; + let grid: PaneGrid | undefined; + let hits = new Map(); + + async function findSocket(id: string): Promise { + const candidates = [socket, "/tmp/tern.sock"].filter((item): item is string => Boolean(item)); + try { + const names = await readdir("/tmp"); + for (const name of names) { + if (name.startsWith("tern") && name.endsWith(".sock")) candidates.push(`/tmp/${name}`); + } + } catch { + // A missing /tmp is not a reason to fail the observe. + } + const tried = new Set(); + for (const candidate of candidates) { + if (tried.has(candidate)) continue; + tried.add(candidate); + try { + const state = (await ctl(candidate, "state")) as { panes?: { id?: number }[] }; + if ((state.panes ?? []).some((item) => String(item.id) === id)) return candidate; + } catch { + continue; + } + } + return undefined; + } + + async function readControl(id: string, found: string): Promise<{ nodes: SemanticNode[]; viewport: ViewportSize; truncated: boolean }> { + const [a11yRaw, treeRaw, stateRaw] = await Promise.all([ + ctl(found, "a11y") as Promise, + ctl(found, "tree") as Promise<{ tree?: ElementNode[] }>, + ctl(found, "state") as Promise<{ panes?: { id?: number; cols?: number; rows?: number }[] }>, + ]); + const elements = treeRaw.tree ?? []; + const nodes = semanticTree(a11yRaw, elements); + const paneState = (stateRaw.panes ?? []).find((item) => String(item.id) === id); + const paneIndex = (stateRaw.panes ?? []).findIndex((item) => String(item.id) === id); + const paneBoxes = elements + .flatMap(function boxes(node: ElementNode): Box[] { + const box = boxOf(node.rect); + const own = (node.class ?? "").includes("tn-pane") && box !== undefined ? [box] : []; + return [...own, ...(node.children ?? []).flatMap(boxes)]; + }) + .filter((box) => box.width > 0) + .sort((a, b) => a.x - b.x); + const paneBox = paneBoxes[paneIndex]; + if (paneBox !== undefined && paneState?.cols !== undefined && paneState.rows !== undefined) { + grid = { box: paneBox, cols: paneState.cols, rows: paneState.rows }; + } + hits = hitsOf(nodes); + const windowBox = boxOf(a11yRaw.bounds); + return { + nodes, + viewport: windowBox === undefined ? { width: 80, height: 24 } : { width: windowBox.width, height: windowBox.height }, + truncated: false, + }; + } + + async function snapshot(): Promise<{ nodes: SemanticNode[]; viewport: ViewportSize; truncated: boolean }> { + if (!pane) return { nodes: [], viewport: { width: 80, height: 24 }, truncated: false }; + const found = await findSocket(pane); + if (found !== undefined) { + socket = found; + try { + return await readControl(pane, found); + } catch { + // The socket answered state and then failed a later read. Fall back to text. + } + } + const surface = await tern(["capture", "--surfaces", pane]).catch(() => ""); + const scroll = await tern(["capture", "--scrollback", pane]).catch(() => ""); + const record = options.record ? await readFile(options.record, "utf8") : ""; + const nodes = [...recordNodes(record), ...textNodes(`${surface}\n${scroll}`)]; + hits = hitsOf(nodes); + grid = undefined; + return { nodes, viewport: { width: 80, height: 24 }, truncated: true }; + } + + function requireHit(id: string): Hit { + const hit = hits.get(id); + if (hit === undefined) { + throw new EngineError("NODE_STALE", `node ${id} is not on the current Tern screen`, { retryable: true }); + } + return hit; + } + + async function daemonPane(id: string): Promise { + try { + await tern(["process", id, "--json"]); + return true; + } catch { + return false; + } + } + + async function click(id: string, button: "left" | "right", times: number): Promise { + if (!pane) throw new EngineError("INVALID_STATE", "tern engine has no pane", { retryable: false }); + const hit = requireHit(id); + const center = { x: Math.round(hit.rect.x + hit.rect.width / 2), y: Math.round(hit.rect.y + hit.rect.height / 2) }; + if (socket !== undefined && !(await daemonPane(pane))) { + for (let i = 0; i < times; i += 1) { + await tern(["ctl", "--control", socket, "click", String(center.x), String(center.y)]); + } + return; + } + if (grid === undefined) { + throw new EngineError("UNSUPPORTED_CAPABILITY", "tern control tree has no pane grid, so a tap has no cell", { retryable: false }); + } + const cell = cellAt(hit.rect, grid.box, grid.cols, grid.rows); + for (let i = 0; i < times; i += 1) { + const args = ["send", pane, "mouse", "press", String(cell.col), String(cell.row)]; + if (button === "right") args.push("--button", "right"); + await tern(args); + await tern(["send", pane, "mouse", "release", String(cell.col), String(cell.row), ...(button === "right" ? ["--button", "right"] : [])]); + } + } + async function useCtl(): Promise { + return socket !== undefined && pane !== undefined && !(await daemonPane(pane)); + } + + async function sendKeys(key: Key): Promise { + if (!pane) throw new EngineError("INVALID_STATE", "tern engine has no pane", { retryable: false }); + const combo = ternCombo(key); + if (combo === undefined) { + throw new EngineError("UNSUPPORTED_CAPABILITY", `tern cannot send key ${key}`, { retryable: false }); + } + if ((await useCtl()) && socket !== undefined) await tern(["ctl", "--control", socket, "key", combo]); + else await tern(["send", pane, "keys", combo]); + } + + async function perform(id: string, action: LocatorAction): Promise { + if (!pane) throw new EngineError("INVALID_STATE", "tern engine has no pane", { retryable: false }); + if (id !== "root") requireHit(id); + const headless = await useCtl(); + switch (action.kind) { + case "tap": + case "focus": + case "scrollIntoView": + await click(id, "left", 1); + return; + case "doubleTap": + await click(id, "left", 2); + return; + case "secondaryTap": + await click(id, "right", 1); + return; + case "fill": + await click(id, "left", 1); + if (headless && socket !== undefined) await tern(["ctl", "--control", socket, "type", action.value]); + else await tern(["send", pane, "text", action.value]); + return; + case "clear": + await click(id, "left", 1); + if (headless && socket !== undefined) { + await tern(["ctl", "--control", socket, "key", "ctrl+a"]); + await tern(["ctl", "--control", socket, "key", "backspace"]); + } else { + await tern(["send", pane, "keys", "ctrl+a", "backspace"]); + } + return; + case "press": + await sendKeys(action.key); + return; + case "swipe": + if (headless && socket !== undefined) { + const lines = action.direction === "up" || action.direction === "left" ? "-12" : "12"; + await tern(["ctl", "--control", socket, "scroll", lines]); + } else { + await tern(["send", pane, "keys", scrollKeys(action.direction)]); + } + return; + default: + throw new EngineError("UNSUPPORTED_CAPABILITY", `tern engine does not perform ${action.kind}`, { retryable: false }); + } + } + + return defineEngine({ + name: "tern", + version: ownVersion(), + spiVersion: 1, + platform: "desktop", + actions: ["tap", "doubleTap", "secondaryTap", "focus", "fill", "clear", "press", "swipe", "scrollIntoView"], + async observe() { + const snap = await snapshot(); + return { + location: pane ? `tern:${pane}` : "tern:", + root: { ref: { id: "root", revision: "" }, role: "window", name: pane ?? "tern", children: snap.nodes }, + viewport: snap.viewport, + truncated: snap.truncated, + }; + }, + async locate(expression) { + return resolveExpression(expression, (await snapshot()).nodes); + }, + async perform(ref, action) { + await perform(ref.id, action); + }, + keyboard: { + async type(text) { + if (!pane) throw new EngineError("INVALID_STATE", "tern engine has no pane", { retryable: false }); + if ((await useCtl()) && socket !== undefined) await tern(["ctl", "--control", socket, "type", text]); + else await tern(["send", pane, "text", text]); + }, + async press(key) { + await sendKeys(key); + }, + }, + async startAttempt() { + if (options.pane) { + pane = options.pane; + return; + } + const command = options.command ?? ["zsh"]; + const id = (await tern(["new", "tab", "--keep-open", "--", ...command])).trim().split(/\s+/)[0]; + if (!id) throw new EngineError("ENGINE_FAILURE", "tern new tab returned no pane id", { retryable: false }); + pane = id; + owned = true; + }, + session: { + async restart() { + if (options.pane) { + pane = options.pane; + return; + } + if (owned && pane) await tern(["close", pane]).catch(() => undefined); + const command = options.command ?? ["zsh"]; + const id = (await tern(["new", "tab", "--keep-open", "--", ...command])).trim().split(/\s+/)[0]; + if (!id) throw new EngineError("ENGINE_FAILURE", "tern new tab returned no pane id", { retryable: false }); + pane = id; + owned = true; + }, + }, + async endAttempt() { + if (owned && pane) await tern(["close", pane]).catch(() => undefined); + if (!options.pane) pane = undefined; + owned = false; + hits = new Map(); + grid = undefined; + }, + }); +} diff --git a/packages/tern/src/tree.ts b/packages/tern/src/tree.ts new file mode 100644 index 0000000000..dd7f6fbe2a --- /dev/null +++ b/packages/tern/src/tree.ts @@ -0,0 +1,177 @@ +import type { SemanticNode } from "e2e/engine"; + +export interface A11yNode { + readonly id?: number; + readonly role?: string; + readonly name?: string; + readonly bounds?: readonly number[]; + readonly children?: readonly A11yNode[]; +} + +export interface ElementNode { + readonly tag?: string; + readonly id?: string; + readonly class?: string; + readonly text?: string; + readonly rect?: readonly number[]; + readonly children?: readonly ElementNode[]; +} + +export interface Box { + readonly x: number; + readonly y: number; + readonly width: number; + readonly height: number; +} + +export interface Hit { + readonly rect: Box; +} + +const ROLE: Readonly> = { + Button: "button", + CheckBox: "checkbox", + ComboBox: "combobox", + Link: "link", + ListBox: "listbox", + MenuItem: "menuitem", + RadioButton: "radio", + SearchField: "searchbox", + Slider: "slider", + Switch: "switch", + Tab: "tab", + TextBox: "textbox", + TextField: "textbox", +}; + +/** A box from a Tern `[x, y, width, height]` list. */ +export function boxOf(raw: readonly number[] | undefined): Box | undefined { + if (!raw || raw.length < 4) return undefined; + const [x, y, width, height] = raw; + if (x === undefined || y === undefined || width === undefined || height === undefined) return undefined; + return { x, y, width, height }; +} + +function texts(node: ElementNode): string[] { + const found: string[] = []; + if (node.text) found.push(node.text); + for (const child of node.children ?? []) found.push(...texts(child)); + return found; +} + +function contains(outer: Box, inner: Box): boolean { + const cx = inner.x + inner.width / 2; + const cy = inner.y + inner.height / 2; + return cx >= outer.x && cx <= outer.x + outer.width && cy >= outer.y && cy <= outer.y + outer.height; +} + +/** Tool cards from a `tern ctl tree` payload. The id stays on the card, not its place on screen. */ +export function toolNodes(tree: readonly ElementNode[]): SemanticNode[] { + const cards: SemanticNode[] = []; + const seen = new Map(); + + const walk = (node: ElementNode): void => { + const parts = (node.class ?? "").split(/\s+/).filter(Boolean); + const head = parts.includes("sf-tool") && !parts.some((part) => part.startsWith("sf-tool-")); + if (head) { + const bits = texts(node); + const title = bits[0] ?? "tool"; + const target = bits.slice(1, 6).join(" "); + const base = `tool:${title}:${target}`; + const n = (seen.get(base) ?? 0) + 1; + seen.set(base, n); + const rect = boxOf(node.rect); + const status = parts.includes("st-error") ? "error" : parts.includes("st-done") ? "done" : ""; + const text = [target, status].filter((part) => part !== "").join(" "); + cards.push({ + ref: { id: n === 1 ? base : `${base}#${n}`, revision: "" }, + role: "button", + name: title, + ...(text === "" ? {} : { text }), + ...(rect === undefined ? {} : { rect }), + states: { + expanded: !parts.includes("collapsed"), + }, + attributes: { + class: parts.join(" "), + ...(status === "" ? {} : { status }), + }, + }); + } + for (const child of node.children ?? []) walk(child); + }; + + for (const node of tree) walk(node); + return cards; +} + +function a11yNode(node: A11yNode): SemanticNode | undefined { + const role = node.role === undefined ? undefined : ROLE[node.role]; + const rect = boxOf(node.bounds); + const children = (node.children ?? []).flatMap((child) => { + const next = a11yNode(child); + return next === undefined ? [] : [next]; + }); + const hidden = rect !== undefined && (rect.width <= 0 || rect.height <= 0); + if (role === undefined && node.name === undefined && children.length === 0) return undefined; + return { + ref: { id: `a${node.id ?? "x"}`, revision: "" }, + ...(role === undefined ? {} : { role }), + ...(node.name === undefined || node.name === "" ? {} : { name: node.name }), + ...(rect === undefined ? {} : { rect }), + ...(hidden ? { states: { hidden: true } } : {}), + ...(children.length === 0 ? {} : { children }), + }; +} + +function smallestHost(nodes: readonly SemanticNode[], card: Box): string | undefined { + let best: { id: string; area: number } | undefined; + const visit = (node: SemanticNode): void => { + if (node.rect !== undefined && contains(node.rect, card)) { + const area = node.rect.width * node.rect.height; + if (best === undefined || area < best.area) best = { id: node.ref.id, area }; + } + for (const child of node.children ?? []) visit(child); + }; + for (const node of nodes) visit(node); + return best?.id; +} + +function insert(nodes: readonly SemanticNode[], host: string, card: SemanticNode): SemanticNode[] { + return nodes.map((node) => { + const children = node.children === undefined ? undefined : insert(node.children, host, card); + if (node.ref.id !== host) return children === node.children ? node : { ...node, children }; + return { ...node, children: [...(children ?? node.children ?? []), card] }; + }); +} + +/** + * One screen. Accessibility nodes keep Tern's numeric ids. Tool cards keep + * a name and target id, so a fold or a badge is a change, not a new node. + */ +export function semanticTree(a11y: A11yNode | undefined, elements: readonly ElementNode[]): SemanticNode[] { + const cards = toolNodes(elements); + let nodes = a11y === undefined ? [] : (a11y.children ?? []).flatMap((child) => { + const next = a11yNode(child); + return next === undefined ? [] : [next]; + }); + if (nodes.length === 0) return cards; + const loose: SemanticNode[] = []; + for (const card of cards) { + const host = card.rect === undefined ? undefined : smallestHost(nodes, card.rect); + if (host === undefined) loose.push(card); + else nodes = insert(nodes, host, card); + } + return [...nodes, ...loose]; +} + +/** Every node id that an action can address, with the box a tap uses. */ +export function hitsOf(nodes: readonly SemanticNode[]): Map { + const hits = new Map(); + const visit = (node: SemanticNode): void => { + if (node.rect !== undefined) hits.set(node.ref.id, { rect: node.rect }); + for (const child of node.children ?? []) visit(child); + }; + for (const node of nodes) visit(node); + return hits; +} diff --git a/packages/tern/src/tsp.ts b/packages/tern/src/tsp.ts new file mode 100644 index 0000000000..658314ebd9 --- /dev/null +++ b/packages/tern/src/tsp.ts @@ -0,0 +1,35 @@ +export interface TernToolCard { + readonly id: string; + readonly name: string; + readonly target: string; + readonly status: string; +} + +/** Tool heads Tern draws are `tool` nodes. Cell capture omits them. */ +export function toolCards(record: string): TernToolCard[] { + const found: TernToolCard[] = []; + for (const line of record.split("\n")) { + if (!line.startsWith("{")) continue; + let obj: { body?: { ops?: unknown } }; + try { + obj = JSON.parse(line) as { body?: { ops?: unknown } }; + } catch { + continue; + } + const ops = obj.body?.ops; + if (!Array.isArray(ops)) continue; + for (const op of ops) { + if (!Array.isArray(op) || op[0] !== "add") continue; + const node = op[op.length - 1] as { id?: string; k?: string; p?: Record } | undefined; + if (!node || node.k !== "tool") continue; + const props = node.p ?? {}; + found.push({ + id: String(node.id ?? ""), + name: String(props.name ?? ""), + target: String(props.target ?? props.title ?? ""), + status: String(props.status ?? ""), + }); + } + } + return found; +} diff --git a/packages/tern/tests/tree.test.ts b/packages/tern/tests/tree.test.ts new file mode 100644 index 0000000000..ccdca6f858 --- /dev/null +++ b/packages/tern/tests/tree.test.ts @@ -0,0 +1,72 @@ +import { describe, expect, it } from "vitest"; + +import { cellAt, scrollKeys, ternCombo } from "../src/drive.ts"; +import { semanticTree, type A11yNode, type ElementNode } from "../src/tree.ts"; + +const a11y: A11yNode = { + id: 0, + role: "Window", + name: "Tern", + bounds: [0, 0, 800, 600], + children: [ + { + id: 7, + role: "Button", + name: "Run", + bounds: [10, 20, 80, 24], + }, + { + id: 9, + role: "Region", + name: "Agent block", + bounds: [0, 40, 400, 500], + }, + ], +}; + +function card(collapsed: boolean): ElementNode { + return { + class: `tn-pane${collapsed ? "" : ""}`, + rect: [0, 40, 400, 500], + children: [ + { + class: `sf sf-tool card ${collapsed ? "collapsed" : ""} st-error`, + rect: [12, 80, 200, 40], + children: [ + { text: "Bash" }, + { text: "npm test" }, + { text: "exit 1" }, + ], + }, + ], + }; +} + +describe("semantic tree", () => { + it("keeps a tool id when the card folds and marks the fold as a state", () => { + const closed = semanticTree(a11y, [card(true)]); + const open = semanticTree(a11y, [card(false)]); + const closedCard = closed[1]?.children?.[0]; + const openCard = open[1]?.children?.[0]; + + expect(closed[0]).toMatchObject({ role: "button", name: "Run", ref: { id: "a7" } }); + expect(closedCard?.ref.id).toBe("tool:Bash:npm test exit 1"); + expect(closedCard?.ref.id).toBe(openCard?.ref.id); + expect(closedCard?.states?.expanded).toBe(false); + expect(openCard?.states?.expanded).toBe(true); + expect(closedCard?.text).toContain("error"); + expect(closedCard?.role).toBe("button"); + }); +}); + +describe("drive", () => { + it("maps a box center to a cell and a key to a tern combo", () => { + expect(cellAt({ x: 10, y: 20, width: 80, height: 24 }, { x: 0, y: 0, width: 800, height: 600 }, 80, 24)).toEqual({ + col: 5, + row: 1, + }); + expect(ternCombo("Enter")).toBe("enter"); + expect(ternCombo("Control+a")).toBe("ctrl+a"); + expect(scrollKeys("up")).toBe("pagedown"); + }); +}); diff --git a/packages/tern/tests/tsp.test.ts b/packages/tern/tests/tsp.test.ts new file mode 100644 index 0000000000..713601e2c5 --- /dev/null +++ b/packages/tern/tests/tsp.test.ts @@ -0,0 +1,16 @@ +import { expect, test } from "vitest"; +import { toolCards } from "../src/tsp.ts"; + +test("reads native tool heads from a TSP record", () => { + const record = [ + JSON.stringify({ + body: { + ops: [ + ["add", "u", "main", null, { id: "u", k: "tool", p: { name: "bash", target: "echo tool-card-ok", status: "done" } }], + ["add", "v", "main", null, { id: "v", k: "text", p: { text: "tool-card-ok" } }], + ], + }, + }), + ].join("\n"); + expect(toolCards(record)).toEqual([{ id: "u", name: "bash", target: "echo tool-card-ok", status: "done" }]); +}); diff --git a/packages/tern/tsconfig.build.json b/packages/tern/tsconfig.build.json new file mode 100644 index 0000000000..766fc44fbe --- /dev/null +++ b/packages/tern/tsconfig.build.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": {"rootDir": "src", "outDir": "dist", "noEmit": false, "declaration": true}, + "include": ["src/**/*.ts"], + "exclude": ["dist", "node_modules"] +} diff --git a/packages/tern/tsconfig.json b/packages/tern/tsconfig.json new file mode 100644 index 0000000000..0118b1f9ba --- /dev/null +++ b/packages/tern/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": {"rootDir": ".", "noEmit": true}, + "include": ["src/**/*.ts", "tests/**/*.ts"], + "exclude": ["dist", "node_modules"] +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1fbc76d1d6..6247344725 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -525,6 +525,22 @@ importers: specifier: 5.0.1 version: 5.0.1(@types/node@26.6.2)(vite@8.1.5(@types/node@26.6.2)(esbuild@0.28.2)(jiti@1.21.7)(terser@5.51.2)(tsx@4.23.13)(yaml@2.9.0)) + + packages/tern: + devDependencies: + '@types/node': + specifier: 26.6.2 + version: 26.6.2 + e2e: + specifier: workspace:* + version: link:../e2e + typescript: + specifier: 7.0.2 + version: 7.0.2 + vitest: + specifier: 5.0.1 + version: 5.0.1(@types/node@26.6.2)(vite@8.1.5(@types/node@26.6.2)(esbuild@0.28.2)(jiti@1.21.7)(terser@5.51.2)(tsx@4.23.13)(yaml@2.9.0)) + packages/web: dependencies: playwright-core: From c62e2b956f30482cd297f48ad723f25d121e7522 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:44:53 -0500 Subject: [PATCH 02/12] docs(tern): document package boundary --- AGENTS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AGENTS.md b/AGENTS.md index b1455dc7d0..34330c006b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -67,6 +67,7 @@ suites that consume the built packages the way a user would. (error taxonomy, text and URL matching, assertion polling, JSON-value rules) are exported there, and there is no `e2e/internal` subpath. - `packages/mobile` — the published `@e2e-dev/mobile` package: the +- `packages/tern` — the published `@e2e-dev/tern` desktop/TUI engine. It adapts Tern's control/TSP surfaces to the public `e2e/engine` contract and keeps Tern-specific observation/input mechanics out of runner core. iOS/Android engine on agent-device, built with the same public `defineEngine`, contributing the `device` fixture. Like the web engine it depends on `e2e` (peer), never the reverse; the engine implementation From 7caf65265f1e9daf3eb1d286361a98df1f207033 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:44:55 -0500 Subject: [PATCH 03/12] docs(tern): list desktop engine --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5f47d3dc16..f05ece5b12 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,6 +43,7 @@ This project is a pnpm monorepo. `packages/` holds what publishes to npm, - `packages/e2e`: the published `e2e` package (SDK, runner, CLI, engine contract) - `packages/web`: the published `@e2e-dev/web` browser engine - `packages/mobile`: the published `@e2e-dev/mobile` mobile engine +- `packages/tern`: the published `@e2e-dev/tern` desktop/TUI engine - `packages/decision`: the decision-model executor on the public `StepExecutor` contract - `apps/testbed`: private dogfood suite that consumes the built packages - `apps/web-benchmark`: private Next.js app of hard-surface scenarios plus the e2e suites written against them From 1626f04eb2575d5f967a2532f2c26a2c8d5e50f4 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:49:51 -0500 Subject: [PATCH 04/12] docs(tern): include package in changeset guidance --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f05ece5b12..3b086ec443 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -124,8 +124,8 @@ We use [changesets](https://github.com/changesets/changesets) to publish new versions. It handles bumping the version based on semver, writing the changelog, and creating tags and GitHub releases. -If your change affects `e2e`, `@e2e-dev/web`, `@e2e-dev/mobile`, or -`@e2e-dev/decision`, add a changeset: +If your change affects `e2e`, `@e2e-dev/web`, `@e2e-dev/mobile`, +`@e2e-dev/decision`, or `@e2e-dev/tern`, add a changeset: ```sh pnpm changeset From 45aae8a96113790a0ff5efbfc5542c98af69c12e Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:52:48 -0500 Subject: [PATCH 05/12] fix(tern): keep control socket selection deterministic --- packages/tern/src/index.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/tern/src/index.ts b/packages/tern/src/index.ts index 8a740324f4..ce6238a260 100644 --- a/packages/tern/src/index.ts +++ b/packages/tern/src/index.ts @@ -1,5 +1,5 @@ import { execFile } from "node:child_process"; -import { readdir, readFile } from "node:fs/promises"; +import { readFile } from "node:fs/promises"; import { createRequire } from "node:module"; import { promisify } from "node:util"; import { createHash } from "node:crypto"; @@ -35,7 +35,7 @@ export interface TernOptions { readonly pane?: string; /** Optional TSP record. Tool heads come from this file when the control tree is absent. */ readonly record?: string; - /** Control socket. Default: `TERN_CONTROL`, else the socket whose state lists the pane. */ + /** Control socket. Default: `TERN_CONTROL`, then Tern's default `/tmp/tern.sock`. */ readonly control?: string; } @@ -93,15 +93,10 @@ export function ternEngine(options: TernOptions = {}): EngineHandle { let hits = new Map(); async function findSocket(id: string): Promise { + // Pane ids can collide across independent Tern instances. Never scan + // arbitrary sockets: use the configured/env socket or Tern's default, + // then verify that the selected instance owns this pane. const candidates = [socket, "/tmp/tern.sock"].filter((item): item is string => Boolean(item)); - try { - const names = await readdir("/tmp"); - for (const name of names) { - if (name.startsWith("tern") && name.endsWith(".sock")) candidates.push(`/tmp/${name}`); - } - } catch { - // A missing /tmp is not a reason to fail the observe. - } const tried = new Set(); for (const candidate of candidates) { if (tried.has(candidate)) continue; From c25549b12718615dcbd289bcd827301b31850c82 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:54:22 -0500 Subject: [PATCH 06/12] fix(tern): do not advertise unsupported scroll-into-view --- packages/tern/src/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/tern/src/index.ts b/packages/tern/src/index.ts index ce6238a260..f5b008b091 100644 --- a/packages/tern/src/index.ts +++ b/packages/tern/src/index.ts @@ -221,7 +221,6 @@ export function ternEngine(options: TernOptions = {}): EngineHandle { switch (action.kind) { case "tap": case "focus": - case "scrollIntoView": await click(id, "left", 1); return; case "doubleTap": @@ -265,7 +264,7 @@ export function ternEngine(options: TernOptions = {}): EngineHandle { version: ownVersion(), spiVersion: 1, platform: "desktop", - actions: ["tap", "doubleTap", "secondaryTap", "focus", "fill", "clear", "press", "swipe", "scrollIntoView"], + actions: ["tap", "doubleTap", "secondaryTap", "focus", "fill", "clear", "press", "swipe"], async observe() { const snap = await snapshot(); return { From fbe13c88f7f33bd3dbfbbdc9b3b0a133904384d1 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:55:36 -0500 Subject: [PATCH 07/12] docs(tern): fix package table --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a16d1f67d9..aaf32702e0 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,8 @@ Flutter, each a standalone project with a passing suite. | --- | --- | | [`e2e`](https://www.npmjs.com/package/e2e) | The SDK, runner, and CLI. | | [`@e2e-dev/web`](https://www.npmjs.com/package/@e2e-dev/web) | Browser engine: Chromium, Firefox, and WebKit through Playwright. | -| [`@e2e-dev/mobile`](https://www.npmjs.com/package/@e2e-dev/mobile) | iOS and Android engine: simulators and emulators through agent-device. |\n| [`@e2e-dev/tern`](https://www.npmjs.com/package/@e2e-dev/tern) | Desktop/TUI engine through Tern's structured control surface. | +| [`@e2e-dev/mobile`](https://www.npmjs.com/package/@e2e-dev/mobile) | iOS and Android engine: simulators and emulators through agent-device. | +| [`@e2e-dev/tern`](https://www.npmjs.com/package/@e2e-dev/tern) | Desktop/TUI engine through Tern's structured control surface. | | [`@e2e-dev/github`](https://www.npmjs.com/package/@e2e-dev/github) | Reporter that posts results as a pull request comment. | | [`@e2e-dev/kernel`](https://www.npmjs.com/package/@e2e-dev/kernel) | Kernel hosted browsers for the web engine. | | [`@e2e-dev/eas`](https://www.npmjs.com/package/@e2e-dev/eas) | EAS Simulators hosted iOS simulators and Android emulators for the mobile engine. | From c3401fc1b107e50e4c98c5429ddc74b74f606243 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:55:38 -0500 Subject: [PATCH 08/12] docs(tern): keep package boundaries intact --- AGENTS.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 34330c006b..5145c0fcbf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -67,7 +67,6 @@ suites that consume the built packages the way a user would. (error taxonomy, text and URL matching, assertion polling, JSON-value rules) are exported there, and there is no `e2e/internal` subpath. - `packages/mobile` — the published `@e2e-dev/mobile` package: the -- `packages/tern` — the published `@e2e-dev/tern` desktop/TUI engine. It adapts Tern's control/TSP surfaces to the public `e2e/engine` contract and keeps Tern-specific observation/input mechanics out of runner core. iOS/Android engine on agent-device, built with the same public `defineEngine`, contributing the `device` fixture. Like the web engine it depends on `e2e` (peer), never the reverse; the engine implementation @@ -75,6 +74,9 @@ suites that consume the built packages the way a user would. The `@e2e-dev/mobile/tools` subpath holds the agent-side `open_app`, `swipe`, and `alert` tools; focused-field typing uses the engine's keyboard grammar. The main entry never loads the AI SDK. +- `packages/tern` — the published `@e2e-dev/tern` desktop/TUI engine. It + adapts Tern's control/TSP surfaces to the public `e2e/engine` contract, + keeping Tern-specific observation and input mechanics out of runner core. - `packages/kernel` - the published `@e2e-dev/kernel` package: Kernel hosted browsers for the web engine. An official integration with a hosted service is one package per service, named after it (`@e2e-dev/`), with the From 3f50eaf0f545d5d414db52eb0eac85fa26dcd704 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:55:53 -0500 Subject: [PATCH 09/12] chore(tern): match package formatting --- packages/tern/package.json | 41 +++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/packages/tern/package.json b/packages/tern/package.json index 5b741fcab2..5263f80314 100644 --- a/packages/tern/package.json +++ b/packages/tern/package.json @@ -2,19 +2,42 @@ "name": "@e2e-dev/tern", "version": "0.0.1", "description": "Tern desktop engine for e2e agentic end-to-end testing", - "keywords": ["e2e", "end-to-end", "testing", "agentic", "desktop-testing", "terminal", "tui", "tern"], + "keywords": [ + "e2e", + "end-to-end", + "testing", + "agentic", + "desktop-testing", + "terminal", + "tui", + "tern" + ], "license": "Apache-2.0", "repository": { "type": "git", "url": "git+https://github.com/tester-army/e2e.git", "directory": "packages/tern" }, - "bugs": {"url": "https://github.com/tester-army/e2e/issues"}, + "bugs": { + "url": "https://github.com/tester-army/e2e/issues" + }, "homepage": "https://github.com/tester-army/e2e/tree/main/packages/tern#readme", - "publishConfig": {"registry": "https://registry.npmjs.org/", "access": "public", "tag": "latest"}, + "publishConfig": { + "registry": "https://registry.npmjs.org/", + "access": "public", + "tag": "latest" + }, "type": "module", - "exports": {".": {"types": "./dist/index.d.ts", "default": "./dist/index.js"}}, - "files": ["dist", "NOTICE"], + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + }, + "files": [ + "dist", + "NOTICE" + ], "scripts": { "build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc --project tsconfig.build.json && node ../../scripts/stamp-dist.ts", "prepublishOnly": "node ../../scripts/check-dist.ts", @@ -22,12 +45,16 @@ "test": "vitest run", "test:watch": "vitest" }, - "peerDependencies": {"e2e": ">=0.18.0 <1"}, + "peerDependencies": { + "e2e": ">=0.18.0 <1" + }, "devDependencies": { "@types/node": "26.6.2", "e2e": "workspace:*", "typescript": "7.0.2", "vitest": "5.0.1" }, - "engines": {"node": "^22.22.3 || >=24.8.0"} + "engines": { + "node": "^22.22.3 || >=24.8.0" + } } From d1ac24447da9e016eafc0a39105bddc2696025f5 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:55:56 -0500 Subject: [PATCH 10/12] chore(tern): format TypeScript config --- packages/tern/tsconfig.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/tern/tsconfig.json b/packages/tern/tsconfig.json index 0118b1f9ba..635a4f631a 100644 --- a/packages/tern/tsconfig.json +++ b/packages/tern/tsconfig.json @@ -1,6 +1,9 @@ { "extends": "../../tsconfig.base.json", - "compilerOptions": {"rootDir": ".", "noEmit": true}, + "compilerOptions": { + "rootDir": ".", + "noEmit": true + }, "include": ["src/**/*.ts", "tests/**/*.ts"], "exclude": ["dist", "node_modules"] } From 3aa08047b86ed901c96bdcd0a8450ed968f17875 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:55:58 -0500 Subject: [PATCH 11/12] chore(tern): format build config --- packages/tern/tsconfig.build.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/tern/tsconfig.build.json b/packages/tern/tsconfig.build.json index 766fc44fbe..65d5a8150f 100644 --- a/packages/tern/tsconfig.build.json +++ b/packages/tern/tsconfig.build.json @@ -1,6 +1,11 @@ { "extends": "../../tsconfig.base.json", - "compilerOptions": {"rootDir": "src", "outDir": "dist", "noEmit": false, "declaration": true}, + "compilerOptions": { + "rootDir": "src", + "outDir": "dist", + "noEmit": false, + "declaration": true + }, "include": ["src/**/*.ts"], "exclude": ["dist", "node_modules"] } From 135128d2ccd23ba592c4481777d66f9862be8029 Mon Sep 17 00:00:00 2001 From: Kevin Rajan <7121943+kvnloo@users.noreply.github.com> Date: Wed, 7 Oct 2026 14:56:35 -0500 Subject: [PATCH 12/12] test(tern): include engine in install smoke --- scripts/install-smoke.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/install-smoke.ts b/scripts/install-smoke.ts index f4188b7e82..4fd4b38503 100644 --- a/scripts/install-smoke.ts +++ b/scripts/install-smoke.ts @@ -1,6 +1,6 @@ /** * A first install, the way a new user meets it: packs the built `e2e`, - * `@e2e-dev/web`, and `@e2e-dev/mobile`, installs them with a given pnpm + * `@e2e-dev/web`, `@e2e-dev/mobile`, and `@e2e-dev/tern`, installs them with a given pnpm * into a fresh project outside this repository, installs again from the * lockfile, and runs a TypeScript test through the installed CLI. * @@ -28,7 +28,7 @@ if (pnpmVersion === undefined) { } /** The packages a new user installs: the runner and its engines. */ -const PACKAGES = ['e2e', 'web', 'mobile'] as const; +const PACKAGES = ['e2e', 'web', 'mobile', 'tern'] as const; const root = mkdtempSync(join(tmpdir(), 'e2e-install-smoke-')); const tarballs = join(root, 'tarballs'); @@ -60,7 +60,12 @@ try { name: 'install-smoke', private: true, type: 'module', - devDependencies: { e2e: tarball('e2e-0'), '@e2e-dev/web': tarball('e2e-dev-web-'), '@e2e-dev/mobile': tarball('e2e-dev-mobile-') }, + devDependencies: { + e2e: tarball('e2e-0'), + '@e2e-dev/web': tarball('e2e-dev-web-'), + '@e2e-dev/mobile': tarball('e2e-dev-mobile-'), + '@e2e-dev/tern': tarball('e2e-dev-tern-'), + }, }), ); writeFileSync(join(project, 'e2e.config.ts'), "import type { E2EConfig } from 'e2e';\n\nexport default { targets: [{ name: 'local', platform: 'test' }] } satisfies E2EConfig;\n");