agentlane 0.0.0 → 0.4.0-rc.2

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 (146) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/LICENSE +27 -0
  3. package/README.md +167 -2
  4. package/dist/agents/claude-plugin.js +79 -0
  5. package/dist/agents/cli.js +258 -0
  6. package/dist/agents/detect.js +88 -0
  7. package/dist/agents/init.js +251 -0
  8. package/dist/agents/launcher.js +32 -0
  9. package/dist/agents/package.js +119 -0
  10. package/dist/agents/skills.js +59 -0
  11. package/dist/agents/toml.js +325 -0
  12. package/dist/agents/wiring-check.js +117 -0
  13. package/dist/agents/wiring.js +374 -0
  14. package/dist/bench/host.js +104 -0
  15. package/dist/bench/live.js +511 -0
  16. package/dist/bench/mcp-client.js +91 -0
  17. package/dist/bench/model.js +15 -0
  18. package/dist/bench/report.js +162 -0
  19. package/dist/bench/run.js +121 -0
  20. package/dist/bench/schedule.js +140 -0
  21. package/dist/bench/stats.js +59 -0
  22. package/dist/bench-cli.js +167 -0
  23. package/dist/browser/aria.js +184 -0
  24. package/dist/browser/control.js +203 -0
  25. package/dist/browser/env.js +118 -0
  26. package/dist/browser/evidence.js +44 -0
  27. package/dist/browser/install.js +361 -0
  28. package/dist/browser/kinds.js +10 -0
  29. package/dist/browser/lane-browser.js +224 -0
  30. package/dist/browser/libraries.js +56 -0
  31. package/dist/browser/paths.js +29 -0
  32. package/dist/browser/release.js +121 -0
  33. package/dist/browser/screen.js +19 -0
  34. package/dist/browser/signin.js +154 -0
  35. package/dist/browser/stop.js +163 -0
  36. package/dist/browser/tools.js +25 -0
  37. package/dist/cache/build.js +154 -0
  38. package/dist/cache/config.js +186 -0
  39. package/dist/cache/index.js +4 -0
  40. package/dist/cache/key.js +196 -0
  41. package/dist/cache/store.js +303 -0
  42. package/dist/cli.js +178 -0
  43. package/dist/clock.js +4 -0
  44. package/dist/devices/adb.js +160 -0
  45. package/dist/devices/android.js +214 -0
  46. package/dist/devices/backend.js +7 -0
  47. package/dist/devices/bundler.js +46 -0
  48. package/dist/devices/common.js +51 -0
  49. package/dist/devices/controls.js +65 -0
  50. package/dist/devices/dial.js +56 -0
  51. package/dist/devices/emulator.js +396 -0
  52. package/dist/devices/hygiene.js +202 -0
  53. package/dist/devices/index.js +5 -0
  54. package/dist/devices/launch.js +76 -0
  55. package/dist/devices/simctl.js +119 -0
  56. package/dist/devices/tools.js +1 -0
  57. package/dist/devices/variant.js +99 -0
  58. package/dist/devices/xcrun.js +265 -0
  59. package/dist/driver/absence.js +54 -0
  60. package/dist/driver/caller.js +51 -0
  61. package/dist/driver/client.js +312 -0
  62. package/dist/driver/diff.js +180 -0
  63. package/dist/driver/elements.js +70 -0
  64. package/dist/driver/engine-main.js +13 -0
  65. package/dist/driver/engine.js +499 -0
  66. package/dist/driver/errors.js +11 -0
  67. package/dist/driver/exec.js +66 -0
  68. package/dist/driver/failure.js +156 -0
  69. package/dist/driver/flow.js +94 -0
  70. package/dist/driver/idle.js +100 -0
  71. package/dist/driver/images.js +68 -0
  72. package/dist/driver/install.js +272 -0
  73. package/dist/driver/lock.js +101 -0
  74. package/dist/driver/look.js +223 -0
  75. package/dist/driver/maestro-child.js +194 -0
  76. package/dist/driver/maestro-runs.js +46 -0
  77. package/dist/driver/paths.js +105 -0
  78. package/dist/driver/pixels.js +144 -0
  79. package/dist/driver/plan.js +108 -0
  80. package/dist/driver/release.js +7 -0
  81. package/dist/driver/runner.js +42 -0
  82. package/dist/driver/selector.js +91 -0
  83. package/dist/driver/session.js +474 -0
  84. package/dist/driver/suggest.js +86 -0
  85. package/dist/driver/supervisor.js +251 -0
  86. package/dist/driver/tree.js +426 -0
  87. package/dist/driver-cli.js +865 -0
  88. package/dist/evidence/device.js +177 -0
  89. package/dist/evidence/evidence.js +304 -0
  90. package/dist/evidence/files.js +92 -0
  91. package/dist/hooks/env.js +81 -0
  92. package/dist/hooks/run.js +101 -0
  93. package/dist/mcp/server.js +69 -0
  94. package/dist/mcp/tools.js +246 -0
  95. package/dist/name.js +22 -0
  96. package/dist/plugin/aims.js +465 -0
  97. package/dist/plugin/conventions.js +73 -0
  98. package/dist/plugin/guard.js +163 -0
  99. package/dist/plugin/hook-cli.js +216 -0
  100. package/dist/plugin/session-name.js +28 -0
  101. package/dist/plugin/shell.js +254 -0
  102. package/dist/processes.js +77 -0
  103. package/dist/project/config.js +316 -0
  104. package/dist/project/schema.js +335 -0
  105. package/dist/project/validate.js +224 -0
  106. package/dist/registry/config.js +142 -0
  107. package/dist/registry/format.js +22 -0
  108. package/dist/registry/owner.js +265 -0
  109. package/dist/registry/paths.js +50 -0
  110. package/dist/registry/ports.js +26 -0
  111. package/dist/registry/prune.js +160 -0
  112. package/dist/registry/refusal.js +53 -0
  113. package/dist/registry/registry.js +1027 -0
  114. package/dist/registry/resources.js +117 -0
  115. package/dist/registry/rows.js +115 -0
  116. package/dist/registry/status.js +85 -0
  117. package/dist/registry/store.js +274 -0
  118. package/dist/registry/types.js +1 -0
  119. package/dist/registry-cli.js +544 -0
  120. package/dist/services/services.js +268 -0
  121. package/dist/services/system.js +189 -0
  122. package/dist/up/deps.js +1 -0
  123. package/dist/up/doctor.js +424 -0
  124. package/dist/up/exec.js +133 -0
  125. package/dist/up/lane-files.js +75 -0
  126. package/dist/up/lane-services.js +38 -0
  127. package/dist/up/maestro-env.js +172 -0
  128. package/dist/up/preflight.js +232 -0
  129. package/dist/up/release.js +148 -0
  130. package/dist/up/resources.js +178 -0
  131. package/dist/up/restart.js +87 -0
  132. package/dist/up/setup.js +28 -0
  133. package/dist/up/up.js +610 -0
  134. package/dist/up-cli.js +258 -0
  135. package/dist/usage.js +16 -0
  136. package/package.json +58 -3
  137. package/schema/agentlane.schema.json +675 -0
  138. package/skills/create-verification-skill/LICENSE +21 -0
  139. package/skills/create-verification-skill/SKILL.md +88 -0
  140. package/skills/dev-loop/LICENSE +21 -0
  141. package/skills/dev-loop/SKILL.md +61 -0
  142. package/skills/device/SKILL.md +8 -0
  143. package/skills/drive/SKILL.md +64 -0
  144. package/skills/maintain-verification-skill/LICENSE +21 -0
  145. package/skills/maintain-verification-skill/SKILL.md +42 -0
  146. package/skills/setup/SKILL.md +80 -0
@@ -0,0 +1,184 @@
1
+ const LINE = /^(\s*)- (.*)$/;
2
+ function unquoteName(raw) {
3
+ if (!raw.startsWith('"'))
4
+ return { name: '', rest: raw };
5
+ let i = 1;
6
+ while (i < raw.length) {
7
+ const ch = raw[i];
8
+ if (ch === '\\')
9
+ i += 2;
10
+ else if (ch === '"')
11
+ break;
12
+ else
13
+ i += 1;
14
+ }
15
+ const literal = raw.slice(0, i + 1);
16
+ let name;
17
+ try {
18
+ name = JSON.parse(literal);
19
+ }
20
+ catch {
21
+ name = literal.slice(1, -1);
22
+ }
23
+ return { name, rest: raw.slice(i + 1) };
24
+ }
25
+ function parseAttributes(rest, into) {
26
+ let text = rest.trimStart();
27
+ for (;;) {
28
+ const match = /^\[([^\]]*)\]\s*/.exec(text);
29
+ if (!match)
30
+ return text;
31
+ for (const part of (match[1] ?? '').split(',')) {
32
+ const item = part.trim();
33
+ if (item === '')
34
+ continue;
35
+ const at = item.indexOf('=');
36
+ if (at === -1)
37
+ into[item] = true;
38
+ else
39
+ into[item.slice(0, at)] = item.slice(at + 1);
40
+ }
41
+ text = text.slice(match[0].length);
42
+ }
43
+ }
44
+ function parseItem(body) {
45
+ if (body.startsWith('/')) {
46
+ const at = body.indexOf(':');
47
+ return { prop: at === -1 ? body.slice(1) : body.slice(1, at), value: at === -1 ? '' : body.slice(at + 1).trim() };
48
+ }
49
+ const roleMatch = /^([A-Za-z][\w-]*)/.exec(body);
50
+ const role = roleMatch?.[1] ?? 'text';
51
+ let rest = roleMatch ? body.slice(role.length) : body;
52
+ if (rest.startsWith(':') && role === 'text') {
53
+ return { role, name: '', ref: null, attributes: {}, text: rest.slice(1).trim(), props: {}, children: [] };
54
+ }
55
+ const { name, rest: afterName } = unquoteName(rest.trimStart());
56
+ const attributes = {};
57
+ rest = parseAttributes(afterName, attributes);
58
+ let text = null;
59
+ if (rest.startsWith(':')) {
60
+ const tail = rest.slice(1).trim();
61
+ if (tail !== '')
62
+ text = tail.startsWith('"') ? unquoteName(tail).name : tail;
63
+ }
64
+ const ref = typeof attributes.ref === 'string' ? attributes.ref : null;
65
+ delete attributes.ref;
66
+ return { role, name, ref, attributes, text, props: {}, children: [] };
67
+ }
68
+ /** Parses the YAML-like accessibility snapshot both drivers print: `- role "name" [attr] [ref=e2]: text`, nested by indentation. */
69
+ export function parseAriaSnapshot(snapshot) {
70
+ const roots = [];
71
+ const stack = [];
72
+ for (const raw of snapshot.split('\n')) {
73
+ const match = LINE.exec(raw.replace(/\r$/, ''));
74
+ if (!match)
75
+ continue;
76
+ const indent = match[1]?.length ?? 0;
77
+ const item = parseItem(match[2] ?? '');
78
+ while (stack.length > 0 && (stack.at(-1)?.indent ?? 0) >= indent)
79
+ stack.pop();
80
+ const parent = stack.at(-1)?.node;
81
+ if ('prop' in item) {
82
+ if (parent)
83
+ parent.props[item.prop] = item.value;
84
+ continue;
85
+ }
86
+ if (parent)
87
+ parent.children.push(item);
88
+ else
89
+ roots.push(item);
90
+ stack.push({ indent, node: item });
91
+ }
92
+ return roots;
93
+ }
94
+ export const INTERACTIVE_ARIA_ROLES = new Set([
95
+ 'button',
96
+ 'link',
97
+ 'textbox',
98
+ 'searchbox',
99
+ 'checkbox',
100
+ 'radio',
101
+ 'switch',
102
+ 'combobox',
103
+ 'listbox',
104
+ 'option',
105
+ 'menuitem',
106
+ 'menuitemcheckbox',
107
+ 'menuitemradio',
108
+ 'slider',
109
+ 'spinbutton',
110
+ 'tab',
111
+ 'treeitem',
112
+ ]);
113
+ const LIMIT = 120;
114
+ function quote(text) {
115
+ return JSON.stringify(text.length > LIMIT ? `${text.slice(0, LIMIT)}…` : text);
116
+ }
117
+ function describe(node) {
118
+ const parts = [`[${node.role}]`];
119
+ if (node.ref !== null)
120
+ parts.push(`ref=${node.ref}`);
121
+ if (node.name !== '')
122
+ parts.push(quote(node.name));
123
+ if (node.text !== null && node.text !== node.name)
124
+ parts.push(`text=${quote(node.text)}`);
125
+ for (const [key, value] of Object.entries(node.attributes)) {
126
+ if (key === 'cursor' || key === 'active')
127
+ continue;
128
+ parts.push(value === true ? key : `${key}=${value}`);
129
+ }
130
+ if (node.props.url !== undefined)
131
+ parts.push(`url=${node.props.url}`);
132
+ return parts.join(' ');
133
+ }
134
+ function shows(node) {
135
+ if (node.role === 'text')
136
+ return node.text !== null && node.text !== '';
137
+ return node.ref !== null || node.name !== '' || node.text !== null;
138
+ }
139
+ function matchesWithin(node, within) {
140
+ return node.ref === within || node.name.toLowerCase() === within.toLowerCase();
141
+ }
142
+ function findWithin(nodes, within) {
143
+ for (const node of nodes) {
144
+ if (matchesWithin(node, within))
145
+ return node;
146
+ const inside = findWithin(node.children, within);
147
+ if (inside)
148
+ return inside;
149
+ }
150
+ return undefined;
151
+ }
152
+ /**
153
+ * Renders a page the way `look` renders a device screen: one line per element, indented by nesting, refs where a
154
+ * device read has ids. Unnamed containers without a ref are skipped and their children shown in their place.
155
+ */
156
+ export function lookAtPage(page, options = {}) {
157
+ const notes = [];
158
+ let roots = page.tree;
159
+ if (options.within !== undefined) {
160
+ const found = findWithin(page.tree, options.within);
161
+ if (found)
162
+ roots = [found];
163
+ else
164
+ notes.push(`Nothing on the page has the ref or name ${JSON.stringify(options.within)}; showing the whole page.`);
165
+ }
166
+ const lines = [];
167
+ let interactive = 0;
168
+ const walk = (nodes, depth) => {
169
+ for (const node of nodes) {
170
+ const isInteractive = INTERACTIVE_ARIA_ROLES.has(node.role);
171
+ if (isInteractive)
172
+ interactive += 1;
173
+ const picked = shows(node) && (!options.interactiveOnly || isInteractive);
174
+ if (picked && (options.depth === undefined || depth < options.depth))
175
+ lines.push(`${' '.repeat(depth)}${describe(node)}`);
176
+ walk(node.children, picked ? depth + 1 : depth);
177
+ }
178
+ };
179
+ walk(roots, 0);
180
+ if (lines.length === 0)
181
+ notes.push(options.interactiveOnly ? 'Nothing interactive is on the page.' : 'Nothing on the page has a role, a name or text.');
182
+ const header = `Page: ${page.title === '' ? '(no title)' : quote(page.title)} at ${page.url}`;
183
+ return { text: [header, ...notes, ...lines].join('\n'), lines, shown: lines.length, interactive };
184
+ }
@@ -0,0 +1,203 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { DriverError } from "../driver/errors.js";
4
+ import { runCommand, tail } from "../driver/exec.js";
5
+ import { CLI } from "../name.js";
6
+ import { parseAriaSnapshot } from "./aria.js";
7
+ const CALL_MS = 60_000;
8
+ function failed(driver, args, ran) {
9
+ const said = tail(`${ran.stdout}\n${ran.stderr}`.trim(), 8);
10
+ return new DriverError(`${driver} ${args.join(' ')} ${ran.error ?? `exited ${String(ran.code)}`}${said ? `:\n${said}` : ''}`, `${CLI} doctor names what is wrong with the lane's browser or its web app; when it reports ready, close the browser with ${CLI} exec -- ${driver} close, and ${CLI} up opens a new one`);
11
+ }
12
+ async function ok(driver, run, args, timeoutMs = CALL_MS) {
13
+ const ran = await run(args, timeoutMs);
14
+ if (ran.code !== 0 || ran.error !== undefined)
15
+ throw failed(driver, args, ran);
16
+ return ran;
17
+ }
18
+ function yamlBlock(text) {
19
+ const match = /```yaml\n([\s\S]*?)```/.exec(text);
20
+ return match?.[1] ?? '';
21
+ }
22
+ function pageField(text, field) {
23
+ return new RegExp(`^- Page ${field}: (.*)$`, 'm').exec(text)?.[1]?.trim() ?? '';
24
+ }
25
+ /** Paths the driver lists as markdown links: `- [Trace](out/traces/x.trace)`, relative to where it ran. */
26
+ function linkedFiles(text, base) {
27
+ return [...text.matchAll(/\]\(([^)]+)\)/g)].flatMap(m => (m[1] ? [path.resolve(base, m[1])] : []));
28
+ }
29
+ function copyInto(files, into) {
30
+ fs.mkdirSync(into, { recursive: true, mode: 0o700 });
31
+ const kept = [];
32
+ for (const file of files) {
33
+ if (!fs.existsSync(file))
34
+ continue;
35
+ const target = path.join(into, path.basename(file));
36
+ fs.cpSync(file, target, { recursive: true });
37
+ kept.push(target);
38
+ }
39
+ return kept;
40
+ }
41
+ /**
42
+ * What a live Playwright trace names beside it that tracing-stop doesn't list: its `.stacks` file and the screencast
43
+ * frames it records as `"file":"screencast/<frame>.jpeg"`, relative to the trace's folder.
44
+ */
45
+ function traceCompanions(trace) {
46
+ const dir = path.dirname(trace);
47
+ const named = new Set([path.basename(trace).replace(/\.trace$/, '.stacks')]);
48
+ const text = fs.existsSync(trace) ? fs.readFileSync(trace, 'utf8') : '';
49
+ for (const match of text.matchAll(/"file":"(screencast\/[^"/]+)"/g))
50
+ if (match[1])
51
+ named.add(match[1]);
52
+ return [...named].map(name => path.join(dir, name));
53
+ }
54
+ function copyCompanions(traces, into) {
55
+ const kept = [];
56
+ for (const trace of traces) {
57
+ const dir = path.dirname(trace);
58
+ for (const file of traceCompanions(trace)) {
59
+ if (!fs.existsSync(file))
60
+ continue;
61
+ const target = path.join(into, path.relative(dir, file));
62
+ fs.mkdirSync(path.dirname(target), { recursive: true, mode: 0o700 });
63
+ fs.copyFileSync(file, target);
64
+ kept.push(target);
65
+ }
66
+ }
67
+ return kept;
68
+ }
69
+ /** playwright-cli 1.64 keeps one trace per session, and refuses a second `tracing-start` with this. */
70
+ const TRACE_RUNS = 'Tracing has already been started';
71
+ export function playwrightControl(run, cwd) {
72
+ const call = (args, timeoutMs) => ok('playwright-cli', run, args, timeoutMs);
73
+ return {
74
+ driver: 'playwright',
75
+ tracesActions: true,
76
+ async isOpen() {
77
+ const ran = await run(['--json', 'list'], CALL_MS);
78
+ if (ran.code !== 0)
79
+ return false;
80
+ try {
81
+ const listed = JSON.parse(ran.stdout);
82
+ return (listed.browsers ?? []).some(b => b.status === 'open');
83
+ }
84
+ catch {
85
+ return false;
86
+ }
87
+ },
88
+ async open(url) {
89
+ if (await this.isOpen())
90
+ await call(['goto', url]);
91
+ else
92
+ await call(['open', url], 120_000);
93
+ },
94
+ async loadState(file) {
95
+ await call(['state-load', file]);
96
+ },
97
+ async read() {
98
+ const ran = await call(['snapshot']);
99
+ return {
100
+ url: pageField(ran.stdout, 'URL'),
101
+ title: pageField(ran.stdout, 'Title'),
102
+ tree: parseAriaSnapshot(yamlBlock(ran.stdout)),
103
+ };
104
+ },
105
+ async screenshot(file) {
106
+ await call(['screenshot', `--filename=${file}`]);
107
+ },
108
+ async traceStart() {
109
+ const ran = await run(['tracing-start'], CALL_MS);
110
+ if (ran.code === 0 && ran.error === undefined)
111
+ return;
112
+ if (!`${ran.stdout}\n${ran.stderr}`.includes(TRACE_RUNS))
113
+ throw failed('playwright-cli', ['tracing-start'], ran);
114
+ await call(['tracing-stop']);
115
+ await call(['tracing-start']);
116
+ },
117
+ async traceStop(into) {
118
+ const ran = await call(['tracing-stop']);
119
+ const linked = linkedFiles(ran.stdout, cwd);
120
+ const kept = copyInto(linked, into);
121
+ return [
122
+ ...kept,
123
+ ...copyCompanions(linked.filter(file => file.endsWith('.trace')), into),
124
+ ];
125
+ },
126
+ async videoStart(file) {
127
+ await call(['video-start', file]);
128
+ },
129
+ async videoStop() {
130
+ await call(['video-stop']);
131
+ },
132
+ async console() {
133
+ return (await call(['console'])).stdout;
134
+ },
135
+ async close() {
136
+ await call(['close-all']);
137
+ },
138
+ };
139
+ }
140
+ /** agent-browser's `--json session list`: the sessions whose daemon runs, by name. */
141
+ function listsSession(stdout, session) {
142
+ try {
143
+ const listed = JSON.parse(stdout);
144
+ const sessions = listed.data?.sessions;
145
+ return Array.isArray(sessions) && sessions.includes(session);
146
+ }
147
+ catch {
148
+ return false;
149
+ }
150
+ }
151
+ export function agentBrowserControl(run, session) {
152
+ const call = (args, timeoutMs) => ok('agent-browser', run, args, timeoutMs);
153
+ return {
154
+ driver: 'agent-browser',
155
+ tracesActions: false,
156
+ async isOpen() {
157
+ const ran = await run(['--json', 'session', 'list'], CALL_MS);
158
+ return ran.code === 0 && listsSession(ran.stdout, session);
159
+ },
160
+ async open(url) {
161
+ await call(['open', url], 120_000);
162
+ },
163
+ async loadState(file) {
164
+ await call(['state', 'load', file]);
165
+ },
166
+ async read() {
167
+ const snapshot = await call(['snapshot']);
168
+ const url = (await call(['get', 'url'])).stdout.trim();
169
+ const title = (await call(['get', 'title'])).stdout.trim();
170
+ return { url, title, tree: parseAriaSnapshot(snapshot.stdout) };
171
+ },
172
+ async screenshot(file) {
173
+ await call(['screenshot', file]);
174
+ },
175
+ async traceStart() {
176
+ await call(['trace', 'start']);
177
+ },
178
+ async traceStop(into) {
179
+ fs.mkdirSync(into, { recursive: true, mode: 0o700 });
180
+ const file = path.join(into, 'devtools-trace.json');
181
+ await call(['trace', 'stop', file]);
182
+ return fs.existsSync(file) ? [file] : [];
183
+ },
184
+ async videoStart(file) {
185
+ await call(['record', 'start', file]);
186
+ },
187
+ async videoStop() {
188
+ await call(['record', 'stop']);
189
+ },
190
+ async console() {
191
+ const messages = (await call(['console'])).stdout;
192
+ const errors = (await call(['errors'])).stdout;
193
+ return `${messages.trimEnd()}\n${errors.trimEnd()}\n`;
194
+ },
195
+ async close() {
196
+ await call(['close', '--all']);
197
+ },
198
+ };
199
+ }
200
+ export function controlFor(driver, shim, env, cwd) {
201
+ const run = (args, timeoutMs) => runCommand(shim, args, { env, cwd, timeoutMs: timeoutMs ?? CALL_MS });
202
+ return driver === 'playwright' ? playwrightControl(run, cwd) : agentBrowserControl(run, env.AGENT_BROWSER_SESSION ?? '');
203
+ }
@@ -0,0 +1,118 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { CLI, envName, TOOL } from "../name.js";
4
+ import { STORAGE_STATE_ENV } from "../project/schema.js";
5
+ import { shellQuote } from "../registry/format.js";
6
+ export const BROWSER_DRIVER_ENV = envName('BROWSER_DRIVER');
7
+ export const BROWSER_SESSION_ENV = envName('BROWSER_SESSION');
8
+ export const BROWSER_PROFILE_ENV = envName('BROWSER_PROFILE');
9
+ export const BROWSER_CDP_ENV = envName('BROWSER_CDP');
10
+ export function cdpUrl(browser) {
11
+ return `http://127.0.0.1:${String(browser.debugPort)}`;
12
+ }
13
+ /** Playwright's global CLI config for the lane: the launch flag that gives the browser the lane's debugging port. */
14
+ export function playwrightConfig(browser) {
15
+ return `${JSON.stringify({ browser: { launchOptions: { args: [`--remote-debugging-port=${String(browser.debugPort)}`] } } }, null, 2)}\n`;
16
+ }
17
+ export function playwrightShim(cli, laneId) {
18
+ return `#!/bin/sh
19
+ # ${TOOL}: playwright-cli for lane ${laneId}, the toolkit's pinned build.
20
+ for arg in "$@"; do
21
+ case "$arg" in
22
+ kill-all)
23
+ echo "${TOOL}: playwright-cli kill-all stops every Playwright browser on this Mac, other lanes' too. Run playwright-cli close-all: it closes this lane's sessions." >&2
24
+ exit 2 ;;
25
+ install-browser)
26
+ echo "${TOOL}: the lane's browsers are pinned and installed by ${TOOL} into a folder other lanes share, so playwright-cli install-browser is refused here; ${CLI} browser install installs them." >&2
27
+ exit 2 ;;
28
+ esac
29
+ done
30
+ exec ${cli.map(shellQuote).join(' ')} "$@"
31
+ `;
32
+ }
33
+ export function agentBrowserShim(cli, ffmpegDir) {
34
+ const pathLine = ffmpegDir === null ? '' : `PATH=${shellQuote(ffmpegDir)}:"$PATH"\nexport PATH\n`;
35
+ return `#!/bin/sh
36
+ # ${TOOL}: agent-browser, the toolkit's pinned build, on the toolkit's Chrome for Testing.
37
+ case "$1" in
38
+ install|upgrade)
39
+ echo "${TOOL}: agent-browser and its Chrome are pinned and installed by ${TOOL} (${CLI} browser install), so agent-browser $1 is refused here." >&2
40
+ exit 2 ;;
41
+ esac
42
+ ${pathLine}exec ${cli.map(shellQuote).join(' ')} "$@"
43
+ `;
44
+ }
45
+ function writeExecutable(file, content) {
46
+ const temp = `${file}.${String(process.pid)}.tmp`;
47
+ fs.writeFileSync(temp, content, { mode: 0o755 });
48
+ fs.renameSync(temp, file);
49
+ }
50
+ /** Writes the lane's driver wrapper and the files its driver reads, and returns the folder that goes first on PATH. */
51
+ export function writeDriverFiles(setting, laneId) {
52
+ const { paths, install, browser } = setting;
53
+ for (const dir of [paths.dir, paths.bin, paths.output, paths.evidence])
54
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
55
+ if (browser.driver === 'playwright') {
56
+ fs.mkdirSync(paths.playwrightSessions, { recursive: true, mode: 0o700 });
57
+ const config = path.join(paths.playwrightConfigHome, '.playwright');
58
+ fs.mkdirSync(config, { recursive: true, mode: 0o700 });
59
+ fs.writeFileSync(path.join(config, 'cli.config.json'), playwrightConfig(browser));
60
+ writeExecutable(path.join(paths.bin, 'playwright-cli'), playwrightShim(install.cli, laneId));
61
+ }
62
+ else {
63
+ fs.mkdirSync(paths.agentBrowserSockets, { recursive: true, mode: 0o700 });
64
+ let ffmpegDir = null;
65
+ if (install.ffmpeg !== '') {
66
+ ffmpegDir = path.join(paths.dir, 'ffmpeg');
67
+ fs.mkdirSync(ffmpegDir, { recursive: true, mode: 0o700 });
68
+ const link = path.join(ffmpegDir, 'ffmpeg');
69
+ fs.rmSync(link, { force: true });
70
+ fs.symlinkSync(install.ffmpeg, link);
71
+ }
72
+ writeExecutable(path.join(paths.bin, 'agent-browser'), agentBrowserShim(install.cli, ffmpegDir));
73
+ }
74
+ return paths.bin;
75
+ }
76
+ /**
77
+ * The variables that bind the driver's own CLI, and Playwright tests, to the lane's browser. Both drivers read their
78
+ * session, profile and launch settings from these; playwright-cli's session and config folders are its PWTEST_
79
+ * variables, the only way it takes them.
80
+ */
81
+ export function browserVariables(setting, basePath) {
82
+ const { browser, paths, install } = setting;
83
+ const vars = {
84
+ [BROWSER_DRIVER_ENV]: browser.driver,
85
+ [BROWSER_SESSION_ENV]: browser.session,
86
+ [BROWSER_PROFILE_ENV]: paths.profile,
87
+ [BROWSER_CDP_ENV]: cdpUrl(browser),
88
+ [STORAGE_STATE_ENV]: paths.storageState,
89
+ PLAYWRIGHT_BROWSERS_PATH: install.browsersPath,
90
+ PATH: [paths.bin, basePath].join(path.delimiter),
91
+ };
92
+ if (setting.url !== null)
93
+ vars.PLAYWRIGHT_TEST_BASE_URL = setting.url;
94
+ if (browser.driver === 'playwright') {
95
+ Object.assign(vars, {
96
+ PLAYWRIGHT_CLI_SESSION: browser.session,
97
+ PWTEST_DAEMON_SESSION_DIR: paths.playwrightSessions,
98
+ PWTEST_CLI_GLOBAL_CONFIG: paths.playwrightConfigHome,
99
+ PLAYWRIGHT_MCP_BROWSER: 'chromium',
100
+ PLAYWRIGHT_MCP_USER_DATA_DIR: paths.profile,
101
+ PLAYWRIGHT_MCP_HEADLESS: setting.headed ? 'false' : 'true',
102
+ PLAYWRIGHT_MCP_OUTPUT_DIR: paths.output,
103
+ });
104
+ return vars;
105
+ }
106
+ Object.assign(vars, {
107
+ AGENT_BROWSER_SESSION: browser.session,
108
+ AGENT_BROWSER_SOCKET_DIR: paths.agentBrowserSockets,
109
+ AGENT_BROWSER_PROFILE: paths.profile,
110
+ AGENT_BROWSER_ARGS: `--remote-debugging-port=${String(browser.debugPort)}`,
111
+ AGENT_BROWSER_SCREENSHOT_DIR: paths.output,
112
+ });
113
+ if (install.headlessShell !== '')
114
+ vars.AGENT_BROWSER_EXECUTABLE_PATH = install.headlessShell;
115
+ if (browser.streamPort !== null)
116
+ vars.AGENT_BROWSER_STREAM_PORT = String(browser.streamPort);
117
+ return vars;
118
+ }
@@ -0,0 +1,44 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { messageOf } from "../driver/errors.js";
4
+ import { evidenceLabel, newEvidenceFolder } from "../evidence/files.js";
5
+ import { lookAtPage } from "./aria.js";
6
+ /**
7
+ * What the lane's browser shows after a failed command: the trace of the driver's actions where the driver keeps one
8
+ * (restarted at once, so the next failure has its own), a screenshot, the page as `look` reads it, and the console.
9
+ */
10
+ export async function keepFailureEvidence(control, evidence, label, at = new Date()) {
11
+ const dir = newEvidenceFolder(evidence, `${evidenceLabel(label).slice(0, 32)}-failed`, at);
12
+ const kept = { dir, files: [], problems: [] };
13
+ const attempt = async (what, work) => {
14
+ try {
15
+ kept.files.push(...(await work()));
16
+ }
17
+ catch (error) {
18
+ kept.problems.push(`${what}: ${messageOf(error).split('\n')[0] ?? ''}`);
19
+ }
20
+ };
21
+ if (control.tracesActions) {
22
+ await attempt('trace', async () => {
23
+ const files = await control.traceStop(path.join(dir, 'trace'));
24
+ await control.traceStart();
25
+ return files;
26
+ });
27
+ }
28
+ await attempt('screenshot', async () => {
29
+ const file = path.join(dir, 'screenshot.png');
30
+ await control.screenshot(file);
31
+ return fs.existsSync(file) ? [file] : [];
32
+ });
33
+ await attempt('page', async () => {
34
+ const file = path.join(dir, 'page.txt');
35
+ fs.writeFileSync(file, `${lookAtPage(await control.read()).text}\n`);
36
+ return [file];
37
+ });
38
+ await attempt('console', async () => {
39
+ const file = path.join(dir, 'console.txt');
40
+ fs.writeFileSync(file, await control.console());
41
+ return [file];
42
+ });
43
+ return kept;
44
+ }