testingterm 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/AGENT-DOCS.md +77 -0
  2. package/LICENSE +21 -0
  3. package/dist/ai.d.ts +24 -0
  4. package/dist/attach.d.ts +6 -0
  5. package/dist/capabilities.d.ts +6 -0
  6. package/dist/chunks/ai-MISD5ZKB.js +260 -0
  7. package/dist/chunks/args-FJPX5SKE.js +8 -0
  8. package/dist/chunks/attach-STVPRW4U.js +30 -0
  9. package/dist/chunks/chunk-66N3P624.js +44 -0
  10. package/dist/chunks/chunk-IJ5VA4HN.js +41 -0
  11. package/dist/chunks/chunk-INTJPVJZ.js +191 -0
  12. package/dist/chunks/chunk-NM755IGG.js +658 -0
  13. package/dist/chunks/chunk-PA67Y4XN.js +65 -0
  14. package/dist/chunks/chunk-U52LFC23.js +68 -0
  15. package/dist/chunks/chunk-YFGNBX2I.js +229 -0
  16. package/dist/chunks/chunk-YHQYNBAN.js +801 -0
  17. package/dist/chunks/commands-IWTFRW33.js +540 -0
  18. package/dist/chunks/context-QML5TP36.js +14 -0
  19. package/dist/chunks/help-I5WIJHZM.js +359 -0
  20. package/dist/chunks/paths-X3C4P67K.js +18 -0
  21. package/dist/chunks/run-RNFQMMXD.js +95 -0
  22. package/dist/chunks/setup-WIZULKES.js +106 -0
  23. package/dist/chunks/themes.gen-E3CTYIQE.js +8 -0
  24. package/dist/chunks/upgrade-43JWCQ63.js +143 -0
  25. package/dist/chunks/verify-55DFXJOY.js +37 -0
  26. package/dist/cli/args.d.ts +13 -0
  27. package/dist/cli/commands.d.ts +5 -0
  28. package/dist/cli/help.d.ts +2 -0
  29. package/dist/cli/main.d.ts +2 -0
  30. package/dist/cli/main.js +83 -0
  31. package/dist/cli/run.d.ts +2 -0
  32. package/dist/cli/setup.d.ts +6 -0
  33. package/dist/cli/upgrade.d.ts +19 -0
  34. package/dist/cli/verify.d.ts +2 -0
  35. package/dist/context.d.ts +33 -0
  36. package/dist/engine.d.ts +56 -0
  37. package/dist/errors.d.ts +4 -0
  38. package/dist/expect.d.ts +62 -0
  39. package/dist/index.d.ts +27 -0
  40. package/dist/index.js +205 -0
  41. package/dist/install.d.ts +13 -0
  42. package/dist/instances.d.ts +23 -0
  43. package/dist/locator.d.ts +49 -0
  44. package/dist/paths.d.ts +7 -0
  45. package/dist/runner.d.ts +56 -0
  46. package/dist/sync.d.ts +8 -0
  47. package/dist/terminal.d.ts +146 -0
  48. package/dist/themes.gen.d.ts +4 -0
  49. package/dist/types.d.ts +214 -0
  50. package/package.json +41 -4
  51. package/skill/testingterm/SKILL.md +138 -0
  52. package/README.md +0 -3
package/AGENT-DOCS.md ADDED
@@ -0,0 +1,77 @@
1
+ <!-- fixme: placeholder copy -->
2
+ # testingterm: documentation for agents
3
+
4
+ Paths are relative to `packages/testingterm/`. Public exports: `src/index.ts`. Every public method has a doc comment in its `.d.ts`.
5
+
6
+ ## Where things are
7
+
8
+ | path | contents |
9
+ | --- | --- |
10
+ | `src/index.ts` | `launch`, and re-exports of everything public |
11
+ | `src/terminal.ts` | `Terminal`: input, waits, screen reads, screenshots, recording, profiling, `verify` |
12
+ | `src/locator.ts` | `Locator` from `terminal.getByText()`: strict text matching, `click`, `hover`, `nth` |
13
+ | `src/expect.ts` | `expect()`: retrying assertions for terminals and locators, plain checks for values |
14
+ | `src/runner.ts` | `test()`, and how `testingterm run` loads files, retries, and collects artifacts |
15
+ | `src/types.ts` | `LaunchOptions`, `Screen`, `Box`, `VerifyOptions` and the other public types |
16
+ | `src/capabilities.ts` | capability presets; `../../engine/crates/core/src/filter.rs` enforces them on program output |
17
+ | `src/sync.ts` | `theme: "ghostty"` and `theme: "rex"`: reading Ghostty config files and Rex settings |
18
+ | `src/ai.ts` | experimental `verify`: runs Claude Code or Codex over ACP against a terminal |
19
+ | `src/engine.ts` | the JSON-lines protocol to the Rust engine (stdio for scripts, a unix socket for the CLI) |
20
+ | `src/cli/` | the `testingterm` CLI; `help.ts` holds every command's help text |
21
+ | `../../engine/crates/core/src/engine.rs` | the engine: requests, waits, input queue, screenshots, recording, profiles |
22
+ | `../../engine/crates/core/src/raster.rs` | the CPU renderer used for screenshots, videos and the headed window |
23
+ | `../../engine/themes/ghostty.tsv` | Ghostty's themes, generated by `node scripts/themes.ts`; `src/themes.gen.ts` holds their names |
24
+ | `../../skill/testingterm/SKILL.md` | the skill `testingterm setup` installs for coding agents |
25
+
26
+ ## The model
27
+
28
+ `launch()` starts the engine (one process per terminal) and returns a `Terminal` right away; requests queue until the engine is up. The engine runs the program in a pty, feeds its output to libghostty-vt, and answers requests. Waits run inside the engine and resolve the moment their condition holds, so nothing polls. Input is queued with a few milliseconds between keys (60ms after a lone Escape) so programs read one key at a time, the way they would from a person.
29
+
30
+ Coordinates for mouse actions are pixels in screenshot space (padding included, scaled by `scale`), or cells with `{ col, row }`. `find()` and `getByText().box()` return both.
31
+
32
+ Every terminal also listens on a unix socket and is listed by `testingterm ls`, so the CLI and agents can inspect a terminal a running script opened.
33
+
34
+ ## Library API
35
+
36
+ ```ts
37
+ launch(command?: string | string[] | LaunchOptions, options?: LaunchOptions): Terminal
38
+
39
+ terminal.screen() / text() / scrollback() / styles() / info()
40
+ terminal.type(text, { delay }) / press(keys, { count }) / paste(text)
41
+ terminal.click(point, { button, count, modifiers }) / dblclick / move / down / up / drag(from, to) / wheel(lines, at?)
42
+ terminal.getByText(text | RegExp, { exact }) -> Locator: first() last() nth(i) all() count() box() waitFor() click() hover()
43
+ terminal.find(text | RegExp) -> Box[]
44
+ terminal.waitForText / waitForGone / waitForIdle(ms) / waitForStable(ms) / waitForTitle / waitForExit
45
+ terminal.screenshot({ path, name, cursor }) -> { path, width, height }
46
+ terminal.startRecording({ path, fps }) / stopRecording()
47
+ terminal.startProfile({ path }) / stopProfile()
48
+ terminal.resize(cols, rows) / signal(name) / focus(bool) / scroll(lines)
49
+ terminal.setTheme("Dracula" | { base, background, foreground, cursor, cursorText, palette })
50
+ themes (every bundled Ghostty theme name)
51
+ terminal.verify(statement, { agent, model, effort, interact, timeout, artifacts, soft }) experimental
52
+ terminal.close() -> { video?, profile? }
53
+
54
+ expect(terminal).toHaveText / toHaveScreen / toHaveTitle / toHaveCursorAt / toHaveExited({ code }) (.not works)
55
+ expect(locator).toBeVisible / toHaveCount
56
+ expect(value).toBe / toEqual / toBeTruthy / toContain / toMatch / toBeGreaterThan / toBeLessThan
57
+
58
+ test(name, async ({ launch, name, artifacts }) => {}, { timeout, retries }) test.only test.skip
59
+ ```
60
+
61
+ ## Environment variables
62
+
63
+ | name | effect |
64
+ | --- | --- |
65
+ | `TESTINGTERM_HEADED=1` | open a window for every terminal |
66
+ | `TESTINGTERM_SLOW_MO` | milliseconds to wait after every action |
67
+ | `TESTINGTERM_VIDEO` | `on`, `off`, `retain-on-failure` |
68
+ | `TESTINGTERM_PROFILE=1` | profile every terminal |
69
+ | `TESTINGTERM_THEME` | default theme for every terminal |
70
+ | `TESTINGTERM_CAPABILITIES` | default capabilities preset for every terminal |
71
+ | `TESTINGTERM_GHOSTTY_CONFIG_DIRS` | where `theme: "ghostty"` looks for Ghostty config, instead of the usual places |
72
+ | `TESTINGTERM_TIMEOUT` | default timeout for waits and assertions |
73
+ | `TESTINGTERM_ARTIFACTS` | artifacts folder |
74
+ | `TESTINGTERM_ID` | the terminal CLI commands act on |
75
+ | `TESTINGTERM_AGENT` | `claude` or `codex` for `verify` |
76
+ | `TESTINGTERM_DEBUG=1` | print engine timing and logs to stderr |
77
+ | `TESTINGTERM_ENGINE` | path to a `testingterm-engine` binary to use instead of the bundled one |
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zenbu Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/ai.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import type { Scope } from "./context.ts";
2
+ import type { AgentChoice, VerifyOptions, VerifyResult } from "./types.ts";
3
+ export interface Inspectable {
4
+ id: string;
5
+ name: string;
6
+ command: string[];
7
+ artifacts: string;
8
+ text(): Promise<string>;
9
+ reports(): Promise<unknown[]>;
10
+ screenshot(options: {
11
+ name: string;
12
+ }): Promise<{
13
+ path: string;
14
+ }>;
15
+ }
16
+ interface Launch {
17
+ name: string;
18
+ command: string;
19
+ args: string[];
20
+ env: Record<string, string>;
21
+ }
22
+ export declare function chooseAgent(choice: AgentChoice | undefined): Launch;
23
+ export declare function verify(terminal: Inspectable, expectation: string, options: VerifyOptions, scope: Scope, stack: string): Promise<VerifyResult>;
24
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { Inspectable } from "./ai.ts";
2
+ import type { Connection } from "./engine.ts";
3
+ import type { InstanceRecord } from "./instances.ts";
4
+ export declare function attach(record: InstanceRecord, connect: (socket: string) => Promise<Connection>): Promise<Inspectable & {
5
+ detach(): void;
6
+ }>;
@@ -0,0 +1,6 @@
1
+ import type { Capabilities, CapabilityPreset, CapabilitiesOption } from "./types.ts";
2
+ export type ResolvedCapabilities = Required<Omit<Capabilities, "preset" | "term">> & {
3
+ term?: string;
4
+ };
5
+ export declare const CAPABILITY_PRESETS: CapabilityPreset[];
6
+ export declare function resolveCapabilities(option: CapabilitiesOption | undefined): ResolvedCapabilities;
@@ -0,0 +1,260 @@
1
+ import {
2
+ PACKAGE_ROOT
3
+ } from "./chunk-PA67Y4XN.js";
4
+
5
+ // src/ai.ts
6
+ import { spawn, execFileSync } from "node:child_process";
7
+ import fs from "node:fs";
8
+ import { createRequire } from "node:module";
9
+ import os from "node:os";
10
+ import path from "node:path";
11
+ import { Readable, Writable } from "node:stream";
12
+ import { fileURLToPath } from "node:url";
13
+ var CLAUDE_ACP = "@agentclientprotocol/claude-agent-acp@0.114.0";
14
+ var CODEX_ACP = "@zed-industries/codex-acp@latest";
15
+ function onPath(binary) {
16
+ try {
17
+ execFileSync(process.platform === "win32" ? "where" : "which", [binary], { stdio: "ignore" });
18
+ return true;
19
+ } catch {
20
+ return false;
21
+ }
22
+ }
23
+ function localBin(spec) {
24
+ const name = spec.slice(0, spec.lastIndexOf("@"));
25
+ try {
26
+ const require2 = createRequire(path.join(PACKAGE_ROOT, "package.json"));
27
+ const manifest = require2.resolve(`${name}/package.json`);
28
+ const pkg = JSON.parse(fs.readFileSync(manifest, "utf8"));
29
+ const bin = typeof pkg.bin === "string" ? pkg.bin : pkg.bin && Object.values(pkg.bin)[0];
30
+ return bin ? path.join(path.dirname(manifest), bin) : null;
31
+ } catch {
32
+ return null;
33
+ }
34
+ }
35
+ function npx() {
36
+ const beside = path.join(path.dirname(process.execPath), "npx");
37
+ return fs.existsSync(beside) ? beside : "npx";
38
+ }
39
+ function adapter(name, spec) {
40
+ const local = localBin(spec);
41
+ if (local) return { name, command: process.execPath, args: [local], env: {} };
42
+ return { name, command: npx(), args: ["-y", spec], env: {} };
43
+ }
44
+ function chooseAgent(choice) {
45
+ if (choice && typeof choice === "object") return { name: path.basename(choice.command), command: choice.command, args: choice.args ?? [], env: choice.env ?? {} };
46
+ const pick = choice ?? process.env.TESTINGTERM_AGENT;
47
+ if (pick === "claude") return adapter("claude", CLAUDE_ACP);
48
+ if (pick === "codex") return adapter("codex", CODEX_ACP);
49
+ const home = os.homedir();
50
+ if (onPath("claude") || fs.existsSync(path.join(home, ".claude"))) return adapter("claude", CLAUDE_ACP);
51
+ if (onPath("codex") || fs.existsSync(path.join(home, ".codex"))) return adapter("codex", CODEX_ACP);
52
+ throw new Error("verify needs Claude Code or Codex installed and signed in, or an ACP agent passed as { agent: { command, args } }");
53
+ }
54
+ function callSite(stack) {
55
+ const own = path.resolve(PACKAGE_ROOT);
56
+ for (const frame of stack.split("\n").slice(1)) {
57
+ const match = /\(?((?:file:\/\/)?\/[^():]+):(\d+):\d+\)?\s*$/.exec(frame);
58
+ if (!match) continue;
59
+ const file = match[1].startsWith("file://") ? fileURLToPath(match[1]) : match[1];
60
+ if (file.startsWith(own) || file.includes("node:")) continue;
61
+ const line = Number(match[2]);
62
+ try {
63
+ const lines = fs.readFileSync(file, "utf8").split("\n");
64
+ const start = Math.max(0, line - 12);
65
+ const excerpt = lines.slice(start, line + 3).map((text, i) => `${String(start + i + 1).padStart(4)}${start + i + 1 === line ? " >" : " "} ${text}`).join("\n");
66
+ return { file, line, excerpt };
67
+ } catch {
68
+ return { file, line, excerpt: "" };
69
+ }
70
+ }
71
+ return null;
72
+ }
73
+ function cliShim(dir) {
74
+ const bin = path.join(dir, ".bin");
75
+ fs.mkdirSync(bin, { recursive: true });
76
+ const cli = path.join(PACKAGE_ROOT, "dist", "cli", "main.js");
77
+ const shim = path.join(bin, "testingterm");
78
+ fs.writeFileSync(shim, `#!/bin/sh
79
+ exec "${process.execPath}" "${cli}" "$@"
80
+ `, { mode: 493 });
81
+ return bin;
82
+ }
83
+ function prompt(terminal, expectation, options, scope, stack, screen) {
84
+ const id = terminal.id;
85
+ const site = callSite(stack);
86
+ const steps = scope.steps.filter((step) => step.terminal === terminal.name).slice(-30).map((step) => ` ${String(step.at).padStart(6)}ms ${step.action}`).join("\n");
87
+ const interact = options.interact ? `
88
+ You may also interact, like a person would:
89
+ testingterm press --id ${id} Enter (keys: Enter, Tab, Up, ctrl+c, ...)
90
+ testingterm type --id ${id} "text"
91
+ testingterm click --id ${id} --text "Label" (or: testingterm click --id ${id} <x> <y> in screenshot pixels)
92
+ testingterm wait --id ${id} --text "Done"` : `
93
+ Only look; do not type, press keys or click.`;
94
+ return `You are checking a terminal app as one step of an automated test. Decide whether this is true:
95
+
96
+ ${expectation}
97
+
98
+ The app is running in a terminal that testingterm controls (terminal id ${id}, command: ${terminal.command.join(" ") || "shell"}).
99
+ Inspect it with these commands:
100
+ testingterm screen --id ${id} the visible text, cursor and terminal modes
101
+ testingterm screen --id ${id} --styles text with colors and bold/underline
102
+ testingterm screenshot --id ${id} <file.png> a pixel-exact image; read the PNG to see layout and colors
103
+ testingterm scrollback --id ${id} everything printed, including scrolled-off lines
104
+ ${interact}
105
+ ${site ? `
106
+ The check comes from ${site.file}:${site.line}${scope.name !== "script" ? ` (test "${scope.name}")` : ""}:
107
+ ${site.excerpt}
108
+ ` : ""}${steps ? `
109
+ What the test did so far:
110
+ ${steps}
111
+ ` : ""}
112
+ The screen right now:
113
+ \`\`\`
114
+ ${screen}
115
+ \`\`\`
116
+
117
+ When you have decided, run exactly one of these and then stop:
118
+ testingterm report --id ${id} --pass "<one sentence: what you saw>"
119
+ testingterm report --id ${id} --fail "<one sentence: what is wrong>"
120
+
121
+ Do not edit files. Be quick and concrete.`;
122
+ }
123
+ function verdictFrom(reports, transcript) {
124
+ for (const report of [...reports].reverse()) {
125
+ const r = report;
126
+ if (typeof r?.pass === "boolean") return { pass: r.pass, reason: String(r.reason ?? "") };
127
+ }
128
+ const tail = transcript.slice(-2e3);
129
+ if (/\bPASS\b/.test(tail) && !/\bFAIL\b/.test(tail)) return { pass: true, reason: tail.trim().split("\n").at(-1) ?? "" };
130
+ if (/\bFAIL\b/.test(tail)) return { pass: false, reason: tail.trim().split("\n").at(-1) ?? "" };
131
+ return null;
132
+ }
133
+ async function verify(terminal, expectation, options, scope, stack) {
134
+ const acp = await import("@agentclientprotocol/sdk");
135
+ const started = Date.now();
136
+ const launch = chooseAgent(options.agent);
137
+ const screen = await terminal.text();
138
+ const before = (await terminal.reports()).length;
139
+ const bin = cliShim(terminal.artifacts);
140
+ const child = spawn(launch.command, launch.args, {
141
+ cwd: process.cwd(),
142
+ env: { ...process.env, ...launch.env, PATH: `${bin}${path.delimiter}${process.env.PATH ?? ""}`, TESTINGTERM_ID: terminal.id },
143
+ stdio: ["pipe", "pipe", "pipe"],
144
+ detached: true
145
+ });
146
+ const killTree = () => {
147
+ try {
148
+ if (child.pid) process.kill(-child.pid, "SIGTERM");
149
+ } catch {
150
+ }
151
+ child.kill("SIGTERM");
152
+ };
153
+ let stderr = "";
154
+ child.stderr.setEncoding("utf8");
155
+ child.stderr.on("data", (chunk) => {
156
+ stderr = (stderr + chunk).slice(-4e3);
157
+ });
158
+ let transcript = "";
159
+ const allowed = (request) => {
160
+ const call = request.toolCall ?? {};
161
+ const input = call.rawInput ?? {};
162
+ const command = typeof input.command === "string" ? input.command.trim() : Array.isArray(input.command) ? input.command.join(" ") : "";
163
+ if (command) return /^testingterm(\s|$)/.test(command) && !/[;&|`$<>]/.test(command.replace(/"[^"]*"|'[^']*'/g, ""));
164
+ return call.kind === "read" || call.kind === "search" || call.kind === "think";
165
+ };
166
+ const exited = new Promise((resolve) => child.once("exit", (code) => resolve(`the agent exited (${code}): ${stderr.trim().split("\n").at(-1) ?? ""}`)));
167
+ const stream = acp.ndJsonStream(Writable.toWeb(child.stdin), Readable.toWeb(child.stdout));
168
+ const connection = new acp.ClientApp({ name: "testingterm" }).onRequest(acp.methods.client.session.requestPermission, (ctx) => {
169
+ const ok = allowed(ctx.params);
170
+ const option = ctx.params.options.find((o) => ok ? o.kind === "allow_once" || o.kind === "allow_always" : o.kind === "reject_once" || o.kind === "reject_always");
171
+ if (!option) return { outcome: { outcome: "cancelled" } };
172
+ return { outcome: { outcome: "selected", optionId: option.optionId } };
173
+ }).onNotification(acp.methods.client.session.update, (ctx) => {
174
+ const update = ctx.params.update;
175
+ if (update.sessionUpdate === "agent_message_chunk" && update.content?.type === "text") transcript += update.content.text ?? "";
176
+ if (update.sessionUpdate === "tool_call" && update.title) transcript += `
177
+ [tool] ${update.title}
178
+ `;
179
+ }).connect(stream);
180
+ const timeout = options.timeout ?? 18e4;
181
+ let timer;
182
+ try {
183
+ const run = (async () => {
184
+ await connection.agent.request(acp.methods.agent.initialize, {
185
+ protocolVersion: acp.PROTOCOL_VERSION,
186
+ clientCapabilities: {},
187
+ clientInfo: { name: "testingterm", version: "0" }
188
+ });
189
+ const session = await connection.agent.request(acp.methods.agent.session.new, { cwd: process.cwd(), mcpServers: [] });
190
+ if (options.model) {
191
+ try {
192
+ await connection.agent.request(acp.methods.agent.session.setConfigOption, { sessionId: session.sessionId, configId: "model", value: options.model });
193
+ } catch (error) {
194
+ throw new Error(`${launch.name} would not use model ${options.model}: ${error.message}`);
195
+ }
196
+ }
197
+ if (options.effort) {
198
+ await connection.agent.request(acp.methods.agent.session.setConfigOption, { sessionId: session.sessionId, configId: "effort", value: options.effort }).catch(() => {
199
+ });
200
+ }
201
+ await connection.agent.request(acp.methods.agent.session.prompt, {
202
+ sessionId: session.sessionId,
203
+ prompt: [{ type: "text", text: prompt(terminal, expectation, options, scope, stack, screen) }]
204
+ });
205
+ })();
206
+ const outcome = await Promise.race([
207
+ run.then(
208
+ () => null,
209
+ (error) => {
210
+ const detail = error?.data?.message ?? error?.message ?? String(error);
211
+ const hint = stderr.trim().split("\n").filter(Boolean).at(-1);
212
+ return `${launch.name} failed: ${detail}${hint && !detail.includes(hint) ? ` (${hint})` : ""}`;
213
+ }
214
+ ),
215
+ exited,
216
+ // fixme: placeholder copy
217
+ new Promise((resolve) => timer = setTimeout(() => resolve(`the agent did not finish within ${timeout}ms`), timeout))
218
+ ]);
219
+ const reports = (await terminal.reports()).slice(before);
220
+ const reported = verdictFrom(reports, transcript);
221
+ const failure = reported ? void 0 : outcome ?? "the agent finished without reporting a result";
222
+ const verdict = reported ?? { pass: false, reason: failure };
223
+ const artifacts = [];
224
+ if (!verdict.pass && options.artifacts !== false) {
225
+ const shot = await terminal.screenshot({ name: "verify-failed" }).catch(() => null);
226
+ if (shot) artifacts.push(shot.path);
227
+ const notes = path.join(terminal.artifacts, `${terminal.name}-${terminal.id}-verify-${Date.now()}.md`);
228
+ fs.writeFileSync(notes, `# ${expectation}
229
+
230
+ result: fail
231
+ reason: ${verdict.reason}
232
+ agent: ${launch.name}
233
+
234
+ ## screen
235
+
236
+ \`\`\`
237
+ ${await terminal.text().catch(() => screen)}
238
+ \`\`\`
239
+
240
+ ## agent transcript
241
+
242
+ ${transcript}
243
+ `);
244
+ artifacts.push(notes);
245
+ }
246
+ return { pass: verdict.pass, reason: verdict.reason, agent: launch.name, durationMs: Date.now() - started, artifacts, ...failure ? { error: failure } : {} };
247
+ } finally {
248
+ clearTimeout(timer);
249
+ connection.close();
250
+ killTree();
251
+ child.stdin?.destroy();
252
+ child.stdout?.destroy();
253
+ child.stderr?.destroy();
254
+ child.unref();
255
+ }
256
+ }
257
+ export {
258
+ chooseAgent,
259
+ verify
260
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ Args,
3
+ UsageError
4
+ } from "./chunk-U52LFC23.js";
5
+ export {
6
+ Args,
7
+ UsageError
8
+ };
@@ -0,0 +1,30 @@
1
+ // src/attach.ts
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ async function attach(record, connect) {
5
+ const connection = await connect(record.socket);
6
+ fs.mkdirSync(record.artifacts, { recursive: true });
7
+ return {
8
+ id: record.id,
9
+ name: record.name,
10
+ command: record.command,
11
+ artifacts: record.artifacts,
12
+ async text() {
13
+ return String((await connection.request("screen")).text ?? "");
14
+ },
15
+ async reports() {
16
+ return (await connection.request("reports")).reports;
17
+ },
18
+ async screenshot({ name }) {
19
+ const file = path.join(record.artifacts, `${record.id}-${name}-${Date.now()}.png`);
20
+ await connection.request("screenshot", { path: file });
21
+ return { path: file };
22
+ },
23
+ detach() {
24
+ connection.close();
25
+ }
26
+ };
27
+ }
28
+ export {
29
+ attach
30
+ };
@@ -0,0 +1,44 @@
1
+ import {
2
+ PACKAGE_ROOT
3
+ } from "./chunk-PA67Y4XN.js";
4
+
5
+ // src/install.ts
6
+ import fs from "node:fs";
7
+ import os from "node:os";
8
+ import path from "node:path";
9
+ function dataBase() {
10
+ const configured = process.env.XDG_DATA_HOME;
11
+ return configured && path.isAbsolute(configured) ? configured : path.join(os.homedir(), ".local", "share");
12
+ }
13
+ var DATA_DIR = process.env.TESTINGTERM_DATA_DIR ?? path.join(dataBase(), "testingterm");
14
+ var RELEASES_URL = (process.env.TESTINGTERM_RELEASES ?? "https://testingterm.com/install").replace(/\/$/, "");
15
+ var CHANNEL = process.env.TESTINGTERM_CHANNEL ?? "stable";
16
+ var TARGET = `${process.platform}-${process.arch}`;
17
+ var installPaths = {
18
+ builds: path.join(DATA_DIR, "builds"),
19
+ runtimes: path.join(DATA_DIR, "runtimes"),
20
+ current: path.join(DATA_DIR, "current"),
21
+ previous: path.join(DATA_DIR, "previous"),
22
+ skill: path.join(DATA_DIR, "skill"),
23
+ downloads: path.join(DATA_DIR, "downloads")
24
+ };
25
+ function installed() {
26
+ const real = (file) => {
27
+ try {
28
+ return fs.realpathSync(file);
29
+ } catch {
30
+ return null;
31
+ }
32
+ };
33
+ const builds = real(installPaths.builds);
34
+ const own = real(PACKAGE_ROOT);
35
+ return Boolean(builds && own && own.startsWith(builds + path.sep));
36
+ }
37
+
38
+ export {
39
+ RELEASES_URL,
40
+ CHANNEL,
41
+ TARGET,
42
+ installPaths,
43
+ installed
44
+ };
@@ -0,0 +1,41 @@
1
+ // src/context.ts
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ function stamp() {
6
+ return (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").replace("T", "_").slice(0, 19);
7
+ }
8
+ var settings = {
9
+ artifacts: process.env.TESTINGTERM_ARTIFACTS ?? path.join(os.tmpdir(), "testingterm", `run-${stamp()}-${process.pid}`),
10
+ headed: process.env.TESTINGTERM_HEADED === "1",
11
+ slowMo: Number(process.env.TESTINGTERM_SLOW_MO ?? 0),
12
+ video: process.env.TESTINGTERM_VIDEO ?? "off",
13
+ profile: process.env.TESTINGTERM_PROFILE === "1",
14
+ timeout: Number(process.env.TESTINGTERM_TIMEOUT ?? 5e3),
15
+ theme: process.env.TESTINGTERM_THEME,
16
+ capabilities: process.env.TESTINGTERM_CAPABILITIES
17
+ };
18
+ var rootScope = {
19
+ name: "script",
20
+ file: null,
21
+ artifacts: settings.artifacts,
22
+ terminals: /* @__PURE__ */ new Set(),
23
+ produced: [],
24
+ steps: [],
25
+ started: Date.now()
26
+ };
27
+ var scopes = new AsyncLocalStorage();
28
+ function currentScope() {
29
+ return scopes.getStore() ?? rootScope;
30
+ }
31
+ function safeName(name) {
32
+ return name.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 60) || "terminal";
33
+ }
34
+
35
+ export {
36
+ settings,
37
+ rootScope,
38
+ scopes,
39
+ currentScope,
40
+ safeName
41
+ };