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,101 @@
1
+ import { spawn } from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ export function describeExit(run) {
5
+ if (run.timedOut)
6
+ return `ran past its ${String((run.timeoutMs ?? 0) / 1000)} s and was stopped`;
7
+ return run.signal ? `was killed by ${run.signal}` : `exited ${String(run.code)}`;
8
+ }
9
+ export class HookFailed extends Error {
10
+ run;
11
+ constructor(run, tail) {
12
+ super(`the ${run.hook} hook ${describeExit(run)}: ${run.command}\n${tail}\nfull log: ${run.log}`);
13
+ this.name = 'HookFailed';
14
+ this.run = run;
15
+ }
16
+ }
17
+ export function tail(file, lines = 30) {
18
+ let text;
19
+ try {
20
+ text = fs.readFileSync(file, 'utf8');
21
+ }
22
+ catch {
23
+ return '(no output)';
24
+ }
25
+ const all = text.trimEnd().split('\n');
26
+ return all
27
+ .slice(-lines)
28
+ .map(line => ` | ${line}`)
29
+ .join('\n');
30
+ }
31
+ function runShell(command, cwd, env, out, timeoutMs) {
32
+ const started = Date.now();
33
+ return new Promise((resolve, reject) => {
34
+ const child = spawn('/bin/sh', ['-c', command], {
35
+ cwd,
36
+ env,
37
+ stdio: ['ignore', out, out],
38
+ detached: timeoutMs !== undefined,
39
+ });
40
+ let timedOut = false;
41
+ const timer = timeoutMs === undefined
42
+ ? undefined
43
+ : setTimeout(() => {
44
+ timedOut = true;
45
+ try {
46
+ process.kill(-(child.pid ?? 0), 'SIGKILL');
47
+ }
48
+ catch {
49
+ child.kill('SIGKILL');
50
+ }
51
+ }, timeoutMs);
52
+ child.once('error', error => {
53
+ clearTimeout(timer);
54
+ reject(error);
55
+ });
56
+ child.once('close', (code, signal) => {
57
+ clearTimeout(timer);
58
+ resolve({ code, signal, ms: Date.now() - started, ...(timedOut ? { timedOut } : {}) });
59
+ });
60
+ });
61
+ }
62
+ export async function runHook(hook, command, options) {
63
+ fs.mkdirSync(path.dirname(options.log), { recursive: true });
64
+ fs.appendFileSync(options.log, `--- ${new Date().toISOString()} ${hook}: ${command}\n`);
65
+ const fd = fs.openSync(options.log, 'a');
66
+ let result;
67
+ try {
68
+ result = await runShell(command, options.cwd, options.env, fd, options.timeoutMs);
69
+ }
70
+ finally {
71
+ fs.closeSync(fd);
72
+ }
73
+ const run = {
74
+ hook,
75
+ command,
76
+ log: options.log,
77
+ ...result,
78
+ ...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
79
+ };
80
+ if (result.code !== 0)
81
+ throw new HookFailed(run, tail(options.log));
82
+ return run;
83
+ }
84
+ export function runCheck(command, options) {
85
+ const started = Date.now();
86
+ return new Promise((resolve, reject) => {
87
+ const child = spawn('/bin/sh', ['-c', command], { cwd: options.cwd, env: options.env, stdio: ['ignore', 'pipe', 'pipe'] });
88
+ const chunks = [];
89
+ child.stdout.on('data', (chunk) => chunks.push(chunk));
90
+ child.stderr.on('data', (chunk) => chunks.push(chunk));
91
+ const timer = setTimeout(() => child.kill('SIGKILL'), options.timeoutMs ?? 30_000);
92
+ child.once('error', error => {
93
+ clearTimeout(timer);
94
+ reject(error);
95
+ });
96
+ child.once('close', (code, signal) => {
97
+ clearTimeout(timer);
98
+ resolve({ code, signal, ms: Date.now() - started, output: Buffer.concat(chunks).toString('utf8').trim() });
99
+ });
100
+ });
101
+ }
@@ -0,0 +1,69 @@
1
+ import { createInterface } from 'node:readline';
2
+ const PROTOCOL_VERSIONS = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
3
+ /** A stdio MCP server: newline-delimited JSON-RPC, tools only. Resolves when the input closes and every call has answered. */
4
+ export function serveMcp(options) {
5
+ const send = (message) => options.output.write(`${JSON.stringify({ jsonrpc: '2.0', ...message })}\n`);
6
+ const lines = createInterface({ input: options.input });
7
+ const inFlight = new Set();
8
+ lines.on('line', line => {
9
+ if (!line.trim())
10
+ return;
11
+ let message;
12
+ try {
13
+ message = JSON.parse(line);
14
+ }
15
+ catch {
16
+ send({ id: null, error: { code: -32700, message: 'Parse error' } });
17
+ return;
18
+ }
19
+ if (typeof message !== 'object' || Array.isArray(message)) {
20
+ send({ id: null, error: { code: -32600, message: 'Invalid request' } });
21
+ return;
22
+ }
23
+ const id = message.id;
24
+ if (id === undefined || id === null)
25
+ return;
26
+ const params = message.params ?? {};
27
+ switch (message.method) {
28
+ case 'initialize': {
29
+ const asked = typeof params.protocolVersion === 'string' ? params.protocolVersion : '';
30
+ send({
31
+ id,
32
+ result: {
33
+ protocolVersion: PROTOCOL_VERSIONS.includes(asked) ? asked : PROTOCOL_VERSIONS[0],
34
+ capabilities: { tools: {} },
35
+ serverInfo: options.info,
36
+ },
37
+ });
38
+ return;
39
+ }
40
+ case 'ping':
41
+ send({ id, result: {} });
42
+ return;
43
+ case 'tools/list':
44
+ send({ id, result: { tools: options.tools } });
45
+ return;
46
+ case 'tools/call': {
47
+ const name = typeof params.name === 'string' ? params.name : '';
48
+ const args = typeof params.arguments === 'object' && params.arguments !== null ? params.arguments : {};
49
+ const job = options.call(name, args).then(result => {
50
+ send({ id, result });
51
+ }, (error) => {
52
+ send({ id, result: { content: [{ type: 'text', text: String(error) }], isError: true } });
53
+ });
54
+ inFlight.add(job);
55
+ void job.finally(() => inFlight.delete(job));
56
+ return;
57
+ }
58
+ default:
59
+ send({ id, error: { code: -32601, message: `Method not found: ${message.method ?? '(none)'}` } });
60
+ }
61
+ });
62
+ return new Promise(resolve => {
63
+ lines.on('close', () => {
64
+ void Promise.allSettled([...inFlight]).then(() => {
65
+ resolve();
66
+ });
67
+ });
68
+ });
69
+ }
@@ -0,0 +1,246 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { hasBrowser } from "../browser/lane-browser.js";
4
+ import { lookAtBrowser, screenshotBrowser } from "../browser/screen.js";
5
+ import { realBrowserTools } from "../browser/tools.js";
6
+ import { callEngine } from "../driver/client.js";
7
+ import { resolveCallerLane } from "../driver/caller.js";
8
+ import { DriverError, messageOf } from "../driver/errors.js";
9
+ import { CLI, TOOL } from "../name.js";
10
+ import { resolveOwner } from "../registry/owner.js";
11
+ import { NotClaimed, Refusal, UsageError } from "../registry/refusal.js";
12
+ export const TOOLS = [
13
+ {
14
+ name: 'look',
15
+ description: "What's on this session's simulator screen now, one line per element: role, id (testID), label and state. " +
16
+ 'Read it before acting and after the screen changes. A nearly empty read (maps, canvases) comes with a screenshot: tap what it shows by point. ' +
17
+ "On a lane that holds a browser and no simulator, or with browser: true, it reads the page in the lane's browser instead: role, ref (what the browser driver's CLI acts on), name and state.",
18
+ inputSchema: {
19
+ type: 'object',
20
+ properties: {
21
+ interactiveOnly: { type: 'boolean', description: 'Only elements you can tap, toggle or type into.' },
22
+ within: { type: 'string', description: "An id or label: show only that element's subtree." },
23
+ depth: { type: 'integer', minimum: 1, description: 'How many levels of elements to show.' },
24
+ bounds: { type: 'boolean', description: "Add each element's bounds in points, [x1,y1][x2,y2]. Simulator only." },
25
+ browser: { type: 'boolean', description: "Read the lane's browser, when the lane holds a simulator as well." },
26
+ },
27
+ additionalProperties: false,
28
+ },
29
+ annotations: { title: 'Look at the screen', readOnlyHint: true },
30
+ },
31
+ {
32
+ name: 'run',
33
+ description: "Run Maestro flow YAML on this session's simulator and get back what changed on screen. " +
34
+ 'A failure names the step, its kind, whether it reached the device, the screen now and selectors to try. ' +
35
+ `Passing steps are recorded: '${CLI} record save <file>' writes them as a flow.`,
36
+ inputSchema: {
37
+ type: 'object',
38
+ properties: {
39
+ yaml: {
40
+ type: 'string',
41
+ description: 'Maestro commands, with or without an `appId:` header and `---`. Without one, appId or the last app used is added.',
42
+ },
43
+ file: { type: 'string', description: "A flow file instead, absolute or relative to the lane's folder." },
44
+ appId: { type: 'string', description: 'The bundle id for YAML without a header.' },
45
+ quick: { type: 'boolean', description: 'Tap without waiting for the screen to settle; for exploring, not for proof.' },
46
+ env: { type: 'object', additionalProperties: { type: 'string' }, description: 'Flow variables, read as ${NAME}.' },
47
+ },
48
+ additionalProperties: false,
49
+ },
50
+ annotations: { title: 'Run a Maestro flow', readOnlyHint: false },
51
+ },
52
+ {
53
+ name: 'screenshot',
54
+ description: "This session's simulator screen as a JPEG, or the lane's browser viewport as a PNG when the lane holds a browser and no simulator, or with browser: true. " +
55
+ '`look` finds elements more cheaply; use this to judge how the screen looks.',
56
+ inputSchema: {
57
+ type: 'object',
58
+ properties: {
59
+ scale: { type: 'number', exclusiveMinimum: 0, maximum: 1, description: 'Shrink the image, e.g. 0.5.' },
60
+ browser: { type: 'boolean', description: "Screenshot the lane's browser, when the lane holds a simulator as well." },
61
+ crop: {
62
+ type: 'object',
63
+ description: 'A region in points, as look prints bounds. Simulator only.',
64
+ properties: { x: { type: 'number' }, y: { type: 'number' }, width: { type: 'number' }, height: { type: 'number' } },
65
+ required: ['x', 'y', 'width', 'height'],
66
+ additionalProperties: false,
67
+ },
68
+ },
69
+ additionalProperties: false,
70
+ },
71
+ annotations: { title: 'Screenshot the simulator', readOnlyHint: true },
72
+ },
73
+ ];
74
+ function isRecord(value) {
75
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
76
+ }
77
+ function bad(problem) {
78
+ throw new UsageError(problem, 'see the tool schema');
79
+ }
80
+ function optional(args, key, check, what) {
81
+ const value = args[key];
82
+ if (value === undefined)
83
+ return undefined;
84
+ if (!check(value))
85
+ bad(`${key} must be ${what}`);
86
+ return value;
87
+ }
88
+ const isString = (value) => typeof value === 'string';
89
+ const isBoolean = (value) => typeof value === 'boolean';
90
+ const isNumber = (value) => typeof value === 'number' && Number.isFinite(value);
91
+ function onlyKeys(tool, args) {
92
+ const properties = TOOLS.find(definition => definition.name === tool)?.inputSchema.properties;
93
+ const known = typeof properties === 'object' && properties !== null ? Object.keys(properties) : [];
94
+ const unknown = Object.keys(args).filter(key => !known.includes(key));
95
+ if (unknown.length > 0) {
96
+ throw new UsageError(`${tool} takes ${known.join(', ')}, not ${unknown.join(', ')}`, "drop them; the simulator and the browser always come from this session's lane");
97
+ }
98
+ }
99
+ function wantsBrowser(args) {
100
+ return optional(args, 'browser', isBoolean, 'true or false') === true;
101
+ }
102
+ function withoutBrowser(args) {
103
+ return Object.fromEntries(Object.entries(args).filter(([key]) => key !== 'browser'));
104
+ }
105
+ export function lookArgs(args) {
106
+ onlyKeys('look', args);
107
+ args = withoutBrowser(args);
108
+ const out = {};
109
+ const interactiveOnly = optional(args, 'interactiveOnly', isBoolean, 'true or false');
110
+ const within = optional(args, 'within', isString, 'a string');
111
+ const depth = optional(args, 'depth', isNumber, 'a number');
112
+ const bounds = optional(args, 'bounds', isBoolean, 'true or false');
113
+ if (interactiveOnly !== undefined)
114
+ out.interactiveOnly = interactiveOnly;
115
+ if (within !== undefined)
116
+ out.within = within;
117
+ if (depth !== undefined) {
118
+ if (!Number.isInteger(depth) || depth < 1)
119
+ bad('depth must be a whole number of at least 1');
120
+ out.depth = depth;
121
+ }
122
+ if (bounds !== undefined)
123
+ out.bounds = bounds;
124
+ return out;
125
+ }
126
+ export function runArgs(args, base) {
127
+ onlyKeys('run', args);
128
+ const out = {};
129
+ const yaml = optional(args, 'yaml', isString, 'a string');
130
+ const file = optional(args, 'file', isString, 'a string');
131
+ if ((yaml === undefined || yaml.trim() === '') === (file === undefined || file === ''))
132
+ bad('give exactly one of yaml and file');
133
+ if (yaml !== undefined && yaml.trim() !== '')
134
+ out.yaml = yaml;
135
+ if (file !== undefined && file !== '')
136
+ out.file = path.resolve(base, file);
137
+ const appId = optional(args, 'appId', isString, 'a bundle id');
138
+ if (appId !== undefined)
139
+ out.appId = appId;
140
+ const quick = optional(args, 'quick', isBoolean, 'true or false');
141
+ if (quick !== undefined)
142
+ out.quick = quick;
143
+ const env = args.env;
144
+ if (env !== undefined) {
145
+ if (!isRecord(env) || !Object.values(env).every(isString))
146
+ bad('env must map variable names to strings');
147
+ out.env = env;
148
+ }
149
+ return out;
150
+ }
151
+ export function screenshotArgs(args) {
152
+ onlyKeys('screenshot', args);
153
+ args = withoutBrowser(args);
154
+ const out = {};
155
+ const scale = optional(args, 'scale', isNumber, 'a number');
156
+ if (scale !== undefined) {
157
+ if (scale <= 0 || scale > 1)
158
+ bad('scale must be above 0 and at most 1');
159
+ out.scale = scale;
160
+ }
161
+ const crop = args.crop;
162
+ if (crop !== undefined) {
163
+ if (!isRecord(crop) || !['x', 'y', 'width', 'height'].every(key => isNumber(crop[key])))
164
+ bad('crop needs x, y, width and height');
165
+ const { x, y, width, height } = crop;
166
+ if (width <= 0 || height <= 0)
167
+ bad('crop needs a positive width and height');
168
+ out.crop = { x, y, width, height };
169
+ }
170
+ return out;
171
+ }
172
+ export function contentOf(response) {
173
+ const content = [];
174
+ const text = response.text ?? response.error;
175
+ if (response.image)
176
+ content.push({ type: 'image', data: response.image.data, mimeType: response.image.mimeType });
177
+ if (text !== undefined && text !== '')
178
+ content.push({ type: 'text', text });
179
+ return response.ok ? { content } : { content, isError: true };
180
+ }
181
+ async function browserLook(target, args) {
182
+ if (args.bounds === true)
183
+ bad("bounds are a simulator's; the lane's browser is read by role, ref and name");
184
+ const page = await lookAtBrowser(target, {
185
+ ...(args.interactiveOnly === undefined ? {} : { interactiveOnly: args.interactiveOnly }),
186
+ ...(args.within === undefined ? {} : { within: args.within }),
187
+ ...(args.depth === undefined ? {} : { depth: args.depth }),
188
+ });
189
+ return { content: [{ type: 'text', text: page.text }] };
190
+ }
191
+ async function browserScreenshot(target, args) {
192
+ if (args.scale !== undefined || args.crop !== undefined)
193
+ bad("scale and crop are a simulator's; the lane's browser screenshot is its whole viewport");
194
+ const file = await screenshotBrowser(target);
195
+ return {
196
+ content: [
197
+ { type: 'image', data: fs.readFileSync(file).toString('base64'), mimeType: 'image/png' },
198
+ { type: 'text', text: `Saved to ${file}` },
199
+ ],
200
+ };
201
+ }
202
+ function errorResult(text) {
203
+ return { content: [{ type: 'text', text }], isError: true };
204
+ }
205
+ /** The MCP tools' handler. It resolves the owner once, and the lane on every call, so a new lane is picked up. */
206
+ export function createToolHandler(context) {
207
+ let owner;
208
+ return async (name, args) => {
209
+ try {
210
+ owner ??= resolveOwner(context.env, context.processes);
211
+ const screen = name === 'look' || name === 'screenshot';
212
+ const asked = screen && wantsBrowser(args);
213
+ const caller = {
214
+ env: context.env,
215
+ cwd: context.cwd,
216
+ processes: context.processes,
217
+ owner,
218
+ need: !screen ? 'device' : asked ? 'browser' : 'either',
219
+ };
220
+ const { lane, stateDir } = resolveCallerLane(caller);
221
+ if (screen && hasBrowser(lane) && (asked || lane.device === null)) {
222
+ const browser = { tools: context.browser ?? realBrowserTools, stateDir, lane, env: context.env };
223
+ return name === 'look'
224
+ ? await browserLook(browser, lookArgs(args))
225
+ : await browserScreenshot(browser, screenshotArgs(args));
226
+ }
227
+ const target = { stateDir, lane, env: context.env };
228
+ if (name === 'look')
229
+ return contentOf(await callEngine(target, { op: 'look', args: lookArgs(args) }));
230
+ if (name === 'run')
231
+ return contentOf(await callEngine(target, { op: 'run', args: runArgs(args, lane.worktree) }));
232
+ if (name === 'screenshot')
233
+ return contentOf(await callEngine(target, { op: 'screenshot', args: screenshotArgs(args) }));
234
+ return errorResult(`Unknown tool ${JSON.stringify(name)}; this server has ${TOOLS.map(tool => tool.name).join(', ')}.`);
235
+ }
236
+ catch (error) {
237
+ if (error instanceof NotClaimed ||
238
+ error instanceof Refusal ||
239
+ error instanceof UsageError ||
240
+ error instanceof DriverError) {
241
+ return errorResult(`${TOOL}: ${error.message}`);
242
+ }
243
+ return errorResult(`${TOOL}: ${messageOf(error)}`);
244
+ }
245
+ };
246
+ }
package/dist/name.js ADDED
@@ -0,0 +1,22 @@
1
+ export const TOOL = 'agentlane';
2
+ export const CLI = `node_modules/.bin/${TOOL}`;
3
+ export const ENV_PREFIX = 'AGENTLANE';
4
+ export const POOL_NAME_PREFIX = `${TOOL}-pool-`;
5
+ export const EMULATOR_NAME_PREFIX = `${TOOL}-emu-`;
6
+ export const CONFIG_FILE = `${TOOL}.json`;
7
+ export const SCHEMA_FILE = `${TOOL}.schema.json`;
8
+ export function envName(suffix) {
9
+ return `${ENV_PREFIX}_${suffix}`;
10
+ }
11
+ const FORMER_TOOL = 'agent-env';
12
+ /** The names 0.2.x uses, read where 0.2.x still runs on the same Mac and in projects it set up. */
13
+ export const FORMER = {
14
+ tool: FORMER_TOOL,
15
+ cli: `node_modules/.bin/${FORMER_TOOL}`,
16
+ envPrefix: 'AGENT_ENV',
17
+ configFile: `${FORMER_TOOL}.json`,
18
+ schemaFile: `${FORMER_TOOL}.schema.json`,
19
+ poolNamePrefix: `${FORMER_TOOL}-pool-`,
20
+ emulatorNamePrefix: `${FORMER_TOOL}-emu-`,
21
+ lanesFolder: 'claims',
22
+ };