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.
- package/CHANGELOG.md +118 -0
- package/LICENSE +27 -0
- package/README.md +167 -2
- package/dist/agents/claude-plugin.js +79 -0
- package/dist/agents/cli.js +258 -0
- package/dist/agents/detect.js +88 -0
- package/dist/agents/init.js +251 -0
- package/dist/agents/launcher.js +32 -0
- package/dist/agents/package.js +119 -0
- package/dist/agents/skills.js +59 -0
- package/dist/agents/toml.js +325 -0
- package/dist/agents/wiring-check.js +117 -0
- package/dist/agents/wiring.js +374 -0
- package/dist/bench/host.js +104 -0
- package/dist/bench/live.js +511 -0
- package/dist/bench/mcp-client.js +91 -0
- package/dist/bench/model.js +15 -0
- package/dist/bench/report.js +162 -0
- package/dist/bench/run.js +121 -0
- package/dist/bench/schedule.js +140 -0
- package/dist/bench/stats.js +59 -0
- package/dist/bench-cli.js +167 -0
- package/dist/browser/aria.js +184 -0
- package/dist/browser/control.js +203 -0
- package/dist/browser/env.js +118 -0
- package/dist/browser/evidence.js +44 -0
- package/dist/browser/install.js +361 -0
- package/dist/browser/kinds.js +10 -0
- package/dist/browser/lane-browser.js +224 -0
- package/dist/browser/libraries.js +56 -0
- package/dist/browser/paths.js +29 -0
- package/dist/browser/release.js +121 -0
- package/dist/browser/screen.js +19 -0
- package/dist/browser/signin.js +154 -0
- package/dist/browser/stop.js +163 -0
- package/dist/browser/tools.js +25 -0
- package/dist/cache/build.js +154 -0
- package/dist/cache/config.js +186 -0
- package/dist/cache/index.js +4 -0
- package/dist/cache/key.js +196 -0
- package/dist/cache/store.js +303 -0
- package/dist/cli.js +178 -0
- package/dist/clock.js +4 -0
- package/dist/devices/adb.js +160 -0
- package/dist/devices/android.js +214 -0
- package/dist/devices/backend.js +7 -0
- package/dist/devices/bundler.js +46 -0
- package/dist/devices/common.js +51 -0
- package/dist/devices/controls.js +65 -0
- package/dist/devices/dial.js +56 -0
- package/dist/devices/emulator.js +396 -0
- package/dist/devices/hygiene.js +202 -0
- package/dist/devices/index.js +5 -0
- package/dist/devices/launch.js +76 -0
- package/dist/devices/simctl.js +119 -0
- package/dist/devices/tools.js +1 -0
- package/dist/devices/variant.js +99 -0
- package/dist/devices/xcrun.js +265 -0
- package/dist/driver/absence.js +54 -0
- package/dist/driver/caller.js +51 -0
- package/dist/driver/client.js +312 -0
- package/dist/driver/diff.js +180 -0
- package/dist/driver/elements.js +70 -0
- package/dist/driver/engine-main.js +13 -0
- package/dist/driver/engine.js +499 -0
- package/dist/driver/errors.js +11 -0
- package/dist/driver/exec.js +66 -0
- package/dist/driver/failure.js +156 -0
- package/dist/driver/flow.js +94 -0
- package/dist/driver/idle.js +100 -0
- package/dist/driver/images.js +68 -0
- package/dist/driver/install.js +272 -0
- package/dist/driver/lock.js +101 -0
- package/dist/driver/look.js +223 -0
- package/dist/driver/maestro-child.js +194 -0
- package/dist/driver/maestro-runs.js +46 -0
- package/dist/driver/paths.js +105 -0
- package/dist/driver/pixels.js +144 -0
- package/dist/driver/plan.js +108 -0
- package/dist/driver/release.js +7 -0
- package/dist/driver/runner.js +42 -0
- package/dist/driver/selector.js +91 -0
- package/dist/driver/session.js +474 -0
- package/dist/driver/suggest.js +86 -0
- package/dist/driver/supervisor.js +251 -0
- package/dist/driver/tree.js +426 -0
- package/dist/driver-cli.js +865 -0
- package/dist/evidence/device.js +177 -0
- package/dist/evidence/evidence.js +304 -0
- package/dist/evidence/files.js +92 -0
- package/dist/hooks/env.js +81 -0
- package/dist/hooks/run.js +101 -0
- package/dist/mcp/server.js +69 -0
- package/dist/mcp/tools.js +246 -0
- package/dist/name.js +22 -0
- package/dist/plugin/aims.js +465 -0
- package/dist/plugin/conventions.js +73 -0
- package/dist/plugin/guard.js +163 -0
- package/dist/plugin/hook-cli.js +216 -0
- package/dist/plugin/session-name.js +28 -0
- package/dist/plugin/shell.js +254 -0
- package/dist/processes.js +77 -0
- package/dist/project/config.js +316 -0
- package/dist/project/schema.js +335 -0
- package/dist/project/validate.js +224 -0
- package/dist/registry/config.js +142 -0
- package/dist/registry/format.js +22 -0
- package/dist/registry/owner.js +265 -0
- package/dist/registry/paths.js +50 -0
- package/dist/registry/ports.js +26 -0
- package/dist/registry/prune.js +160 -0
- package/dist/registry/refusal.js +53 -0
- package/dist/registry/registry.js +1027 -0
- package/dist/registry/resources.js +117 -0
- package/dist/registry/rows.js +115 -0
- package/dist/registry/status.js +85 -0
- package/dist/registry/store.js +274 -0
- package/dist/registry/types.js +1 -0
- package/dist/registry-cli.js +544 -0
- package/dist/services/services.js +268 -0
- package/dist/services/system.js +189 -0
- package/dist/up/deps.js +1 -0
- package/dist/up/doctor.js +424 -0
- package/dist/up/exec.js +133 -0
- package/dist/up/lane-files.js +75 -0
- package/dist/up/lane-services.js +38 -0
- package/dist/up/maestro-env.js +172 -0
- package/dist/up/preflight.js +232 -0
- package/dist/up/release.js +148 -0
- package/dist/up/resources.js +178 -0
- package/dist/up/restart.js +87 -0
- package/dist/up/setup.js +28 -0
- package/dist/up/up.js +610 -0
- package/dist/up-cli.js +258 -0
- package/dist/usage.js +16 -0
- package/package.json +58 -3
- package/schema/agentlane.schema.json +675 -0
- package/skills/create-verification-skill/LICENSE +21 -0
- package/skills/create-verification-skill/SKILL.md +88 -0
- package/skills/dev-loop/LICENSE +21 -0
- package/skills/dev-loop/SKILL.md +61 -0
- package/skills/device/SKILL.md +8 -0
- package/skills/drive/SKILL.md +64 -0
- package/skills/maintain-verification-skill/LICENSE +21 -0
- package/skills/maintain-verification-skill/SKILL.md +42 -0
- package/skills/setup/SKILL.md +80 -0
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { TOOL } from "../name.js";
|
|
3
|
+
import { splitCommands } from "./shell.js";
|
|
4
|
+
const ASSIGNMENT = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s;
|
|
5
|
+
const SHELLS = new Set(['sh', 'bash', 'zsh', 'dash', 'ksh', 'fish']);
|
|
6
|
+
const RUNNERS = new Set(['npx', 'bunx', 'pnpx']);
|
|
7
|
+
const PACKAGE_MANAGERS = new Set(['pnpm', 'npm', 'yarn', 'bun']);
|
|
8
|
+
const PASS_THROUGH = new Set(['exec', 'nohup', 'builtin', 'noglob']);
|
|
9
|
+
const ADB_READ_ONLY = new Set([
|
|
10
|
+
'devices',
|
|
11
|
+
'version',
|
|
12
|
+
'help',
|
|
13
|
+
'start-server',
|
|
14
|
+
'keygen',
|
|
15
|
+
'mdns',
|
|
16
|
+
'track-devices',
|
|
17
|
+
'host-features',
|
|
18
|
+
'get-state',
|
|
19
|
+
'get-serialno',
|
|
20
|
+
'get-devpath',
|
|
21
|
+
'pair',
|
|
22
|
+
]);
|
|
23
|
+
const ADB_WITH_VALUE = new Set(['-s', '-t', '-H', '-P', '-L', '-p', '--one-device']);
|
|
24
|
+
const SIMCTL_NO_DEVICE = new Set(['list', 'help', 'create', 'runtime']);
|
|
25
|
+
const PLAYWRIGHT_SESSION_ENV = 'PLAYWRIGHT_CLI_SESSION';
|
|
26
|
+
const AGENT_BROWSER_SESSION_ENV = 'AGENT_BROWSER_SESSION';
|
|
27
|
+
/** The browser driver a command word runs: its CLI by name or path, or its npm package as npx names it. */
|
|
28
|
+
function browserDriverOf(word) {
|
|
29
|
+
if (!word?.literal)
|
|
30
|
+
return null;
|
|
31
|
+
const name = path.basename(word.text);
|
|
32
|
+
if (name === 'playwright-cli' || /^@playwright\/cli(@[^/]*)?$/.test(word.text))
|
|
33
|
+
return 'playwright';
|
|
34
|
+
if (name === 'agent-browser' || /^agent-browser@[^/]*$/.test(word.text))
|
|
35
|
+
return 'agent-browser';
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
/** A debugging port from a CDP endpoint: a bare port, or a URL or host with one. */
|
|
39
|
+
function portOf(endpoint) {
|
|
40
|
+
const bare = /^\d{1,5}$/.exec(endpoint);
|
|
41
|
+
const port = bare ? Number(endpoint) : Number(/:(\d{1,5})(?:[/?#]|$)/.exec(endpoint)?.[1] ?? Number.NaN);
|
|
42
|
+
return Number.isInteger(port) && port > 0 && port < 65536 ? port : null;
|
|
43
|
+
}
|
|
44
|
+
function value(word, scope) {
|
|
45
|
+
if (!word)
|
|
46
|
+
return null;
|
|
47
|
+
if (word.literal)
|
|
48
|
+
return word.text;
|
|
49
|
+
const variable = /^\$\{?([A-Za-z_][A-Za-z0-9_]*)\}?$/.exec(word.text);
|
|
50
|
+
if (!variable?.[1])
|
|
51
|
+
return null;
|
|
52
|
+
return scope.env.get(variable[1]) ?? null;
|
|
53
|
+
}
|
|
54
|
+
function base(word) {
|
|
55
|
+
return word?.literal ? path.basename(word.text) : null;
|
|
56
|
+
}
|
|
57
|
+
function joined(words) {
|
|
58
|
+
return words.map(w => (/[\s"'$]/.test(w.text) && w.literal ? JSON.stringify(w.text) : w.text)).join(' ');
|
|
59
|
+
}
|
|
60
|
+
function skipOptions(words, start, withValue) {
|
|
61
|
+
let i = start;
|
|
62
|
+
while (i < words.length) {
|
|
63
|
+
const text = words[i]?.text ?? '';
|
|
64
|
+
if (text === '--')
|
|
65
|
+
return i + 1;
|
|
66
|
+
if (!words[i]?.literal || !text.startsWith('-') || text === '-')
|
|
67
|
+
return i;
|
|
68
|
+
i += withValue.has(text) ? 2 : 1;
|
|
69
|
+
}
|
|
70
|
+
return i;
|
|
71
|
+
}
|
|
72
|
+
class Interpreter {
|
|
73
|
+
aims = [];
|
|
74
|
+
scope;
|
|
75
|
+
constructor(env, cwd) {
|
|
76
|
+
this.scope = { env: new Map(Object.entries(env).map(([k, v]) => [k, v ?? null])), cwd };
|
|
77
|
+
}
|
|
78
|
+
script(text, scope = this.scope) {
|
|
79
|
+
for (const command of splitCommands(text))
|
|
80
|
+
this.command(command.words, scope);
|
|
81
|
+
}
|
|
82
|
+
aim(aim, words, scope) {
|
|
83
|
+
this.aims.push({ aim, command: joined(words), cwd: scope.cwd });
|
|
84
|
+
}
|
|
85
|
+
command(words, outer) {
|
|
86
|
+
let i = 0;
|
|
87
|
+
const local = { env: new Map(outer.env), cwd: outer.cwd };
|
|
88
|
+
for (; i < words.length; i++) {
|
|
89
|
+
const word = words[i];
|
|
90
|
+
const match = word?.literal ? ASSIGNMENT.exec(word.text) : null;
|
|
91
|
+
if (!match?.[1]) {
|
|
92
|
+
const raw = word ? /^([A-Za-z_][A-Za-z0-9_]*)=/.exec(word.text) : null;
|
|
93
|
+
if (!raw?.[1])
|
|
94
|
+
break;
|
|
95
|
+
local.env.set(raw[1], null);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
local.env.set(match[1], match[2] ?? '');
|
|
99
|
+
}
|
|
100
|
+
const rest = words.slice(i);
|
|
101
|
+
if (rest.length === 0) {
|
|
102
|
+
for (const [k, v] of local.env)
|
|
103
|
+
outer.env.set(k, v);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.run(rest, local, outer);
|
|
107
|
+
}
|
|
108
|
+
run(words, scope, outer) {
|
|
109
|
+
const head = base(words[0]);
|
|
110
|
+
if (head === null)
|
|
111
|
+
return;
|
|
112
|
+
const args = words.slice(1);
|
|
113
|
+
const driver = browserDriverOf(words[0]);
|
|
114
|
+
if (driver !== null) {
|
|
115
|
+
this.browser(driver, words, args, scope);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
switch (head) {
|
|
119
|
+
case 'export':
|
|
120
|
+
for (const w of args) {
|
|
121
|
+
const m = w.literal ? ASSIGNMENT.exec(w.text) : null;
|
|
122
|
+
if (m?.[1])
|
|
123
|
+
outer.env.set(m[1], m[2] ?? '');
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
case 'cd':
|
|
127
|
+
outer.cwd = this.cd(args, outer);
|
|
128
|
+
return;
|
|
129
|
+
case 'env':
|
|
130
|
+
this.env(args, scope);
|
|
131
|
+
return;
|
|
132
|
+
case 'command':
|
|
133
|
+
if (args[0]?.text === '-v' || args[0]?.text === '-V')
|
|
134
|
+
return;
|
|
135
|
+
this.command(args.slice(skipOptions(args, 0, new Set())), scope);
|
|
136
|
+
return;
|
|
137
|
+
case 'nice':
|
|
138
|
+
this.command(args.slice(skipOptions(args, 0, new Set(['-n']))), scope);
|
|
139
|
+
return;
|
|
140
|
+
case 'timeout':
|
|
141
|
+
case 'gtimeout': {
|
|
142
|
+
const at = skipOptions(args, 0, new Set(['-s', '-k', '--signal', '--kill-after']));
|
|
143
|
+
this.command(args.slice(at + 1), scope);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
case 'sudo':
|
|
147
|
+
case 'doas':
|
|
148
|
+
this.command(args.slice(skipOptions(args, 0, new Set(['-u', '-g', '-C', '-h', '-p', '-r', '-t', '-D', '-U']))), scope);
|
|
149
|
+
return;
|
|
150
|
+
case 'xargs':
|
|
151
|
+
this.command(args.slice(skipOptions(args, 0, new Set(['-n', '-I', '-L', '-P', '-s', '-E', '-d', '-a', '-J', '-R', '-S']))), scope);
|
|
152
|
+
return;
|
|
153
|
+
case 'caffeinate':
|
|
154
|
+
this.command(args.slice(skipOptions(args, 0, new Set(['-t', '-w']))), scope);
|
|
155
|
+
return;
|
|
156
|
+
case 'stdbuf':
|
|
157
|
+
this.command(args.slice(skipOptions(args, 0, new Set(['-i', '-o', '-e']))), scope);
|
|
158
|
+
return;
|
|
159
|
+
case 'arch':
|
|
160
|
+
this.command(args.slice(skipOptions(args, 0, new Set(['-arch']))), scope);
|
|
161
|
+
return;
|
|
162
|
+
case 'watch': {
|
|
163
|
+
const at = skipOptions(args, 0, new Set(['-n', '--interval']));
|
|
164
|
+
this.script(args
|
|
165
|
+
.slice(at)
|
|
166
|
+
.map(w => w.text)
|
|
167
|
+
.join(' '), scope);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
case 'eval':
|
|
171
|
+
this.script(args.map(w => w.text).join(' '), scope);
|
|
172
|
+
return;
|
|
173
|
+
case 'xcrun':
|
|
174
|
+
this.xcrun(words, args, scope);
|
|
175
|
+
return;
|
|
176
|
+
case 'simctl':
|
|
177
|
+
this.simctl(words, args, scope);
|
|
178
|
+
return;
|
|
179
|
+
case 'adb':
|
|
180
|
+
case 'adb.exe':
|
|
181
|
+
this.adb(words, args, scope);
|
|
182
|
+
return;
|
|
183
|
+
case 'emulator':
|
|
184
|
+
this.emulator(words, args, scope);
|
|
185
|
+
return;
|
|
186
|
+
case 'avdmanager':
|
|
187
|
+
this.avdmanager(words, args, scope);
|
|
188
|
+
return;
|
|
189
|
+
default:
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
if (PASS_THROUGH.has(head)) {
|
|
193
|
+
this.command(args.slice(skipOptions(args, 0, new Set(['-a']))), scope);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (SHELLS.has(head)) {
|
|
197
|
+
const c = args.findIndex(w => w.literal && /^-[a-zA-Z]*c[a-zA-Z]*$/.test(w.text));
|
|
198
|
+
const script = c === -1 ? null : value(args[c + 1], scope);
|
|
199
|
+
if (script !== null)
|
|
200
|
+
this.script(script, { env: new Map(scope.env), cwd: scope.cwd });
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (RUNNERS.has(head)) {
|
|
204
|
+
this.command(args.slice(skipOptions(args, 0, new Set(['-p', '--package', '-c']))), scope);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (PACKAGE_MANAGERS.has(head) && (args[0]?.text === 'exec' || args[0]?.text === 'dlx' || args[0]?.text === 'x')) {
|
|
208
|
+
this.command(args.slice(skipOptions(args, 1, new Set())), scope);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (head === TOOL && args[0]?.text === 'exec') {
|
|
212
|
+
this.command(args.slice(skipOptions(args, 1, new Set())), scope);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* playwright-cli takes its session as `-s=<name>`, `-s <name>`, `--session[=]<name>` or PLAYWRIGHT_CLI_SESSION, and
|
|
217
|
+
* `kill-all` stops every Playwright daemon on the machine; `attach --cdp=<endpoint>` joins a running browser. Its
|
|
218
|
+
* parser (minimist) lets any other option take the next word as its value, so `kill-all` counts wherever it stands.
|
|
219
|
+
* agent-browser takes `--session[=]<name>` or AGENT_BROWSER_SESSION, and `--cdp <endpoint>` or `connect <endpoint>`.
|
|
220
|
+
*/
|
|
221
|
+
browser(driver, words, args, scope) {
|
|
222
|
+
const texts = args.map(w => value(w, scope));
|
|
223
|
+
let session;
|
|
224
|
+
const ports = [];
|
|
225
|
+
const positionals = [];
|
|
226
|
+
for (let i = 0; i < texts.length; i++) {
|
|
227
|
+
const t = texts[i];
|
|
228
|
+
if (t === null || t === undefined)
|
|
229
|
+
continue;
|
|
230
|
+
const flag = /^(-s|--session|--cdp)(?:=(.*))?$/s.exec(t);
|
|
231
|
+
if (flag?.[1] === '-s' && driver !== 'playwright') {
|
|
232
|
+
positionals.push(t);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (flag?.[1]) {
|
|
236
|
+
const given = flag[2] ?? texts[i + 1] ?? null;
|
|
237
|
+
if (flag[2] === undefined)
|
|
238
|
+
i++;
|
|
239
|
+
if (flag[1] === '--cdp') {
|
|
240
|
+
const port = given === null ? null : portOf(given);
|
|
241
|
+
if (port !== null)
|
|
242
|
+
ports.push(port);
|
|
243
|
+
}
|
|
244
|
+
else
|
|
245
|
+
session = given;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (!t.startsWith('-'))
|
|
249
|
+
positionals.push(t);
|
|
250
|
+
}
|
|
251
|
+
const [command, target] = positionals;
|
|
252
|
+
if (driver === 'playwright' && positionals.includes('kill-all')) {
|
|
253
|
+
this.aim({ kind: 'every-browser', driver }, words, scope);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (driver === 'agent-browser' && command === 'connect' && target !== undefined) {
|
|
257
|
+
const port = portOf(target);
|
|
258
|
+
if (port !== null)
|
|
259
|
+
ports.push(port);
|
|
260
|
+
}
|
|
261
|
+
for (const port of ports)
|
|
262
|
+
this.aim({ kind: 'browser-port', driver, port }, words, scope);
|
|
263
|
+
if (session === undefined)
|
|
264
|
+
session = scope.env.get(driver === 'playwright' ? PLAYWRIGHT_SESSION_ENV : AGENT_BROWSER_SESSION_ENV);
|
|
265
|
+
if (session)
|
|
266
|
+
this.aim({ kind: 'browser-session', driver, session }, words, scope);
|
|
267
|
+
}
|
|
268
|
+
cd(args, scope) {
|
|
269
|
+
const target = args.find(w => !(w.literal && w.text.startsWith('-') && w.text !== '-'));
|
|
270
|
+
if (!target)
|
|
271
|
+
return scope.env.get('HOME') ?? null;
|
|
272
|
+
const dir = value(target, scope);
|
|
273
|
+
if (dir === null || dir === '-')
|
|
274
|
+
return null;
|
|
275
|
+
const expanded = dir.startsWith('~/') ? path.join(scope.env.get('HOME') ?? '~', dir.slice(2)) : dir;
|
|
276
|
+
if (path.isAbsolute(expanded))
|
|
277
|
+
return path.normalize(expanded);
|
|
278
|
+
return scope.cwd === null ? null : path.resolve(scope.cwd, expanded);
|
|
279
|
+
}
|
|
280
|
+
env(args, scope) {
|
|
281
|
+
const local = { env: new Map(scope.env), cwd: scope.cwd };
|
|
282
|
+
let i = 0;
|
|
283
|
+
while (i < args.length) {
|
|
284
|
+
const w = args[i];
|
|
285
|
+
if (!w?.literal)
|
|
286
|
+
break;
|
|
287
|
+
const t = w.text;
|
|
288
|
+
if (t === '-i' || t === '--ignore-environment' || t === '-')
|
|
289
|
+
local.env = new Map();
|
|
290
|
+
else if (t === '-u' || t === '--unset') {
|
|
291
|
+
local.env.delete(args[i + 1]?.text ?? '');
|
|
292
|
+
i++;
|
|
293
|
+
}
|
|
294
|
+
else if (t.startsWith('--unset='))
|
|
295
|
+
local.env.delete(t.slice('--unset='.length));
|
|
296
|
+
else if (t === '-C' || t === '--chdir') {
|
|
297
|
+
local.cwd = this.cd([args[i + 1] ?? { text: '-', literal: true }], local);
|
|
298
|
+
i++;
|
|
299
|
+
}
|
|
300
|
+
else if (t === '-S' || t === '--split-string') {
|
|
301
|
+
this.script([args[i + 1]?.text ?? '', ...args.slice(i + 2).map(a => a.text)].join(' '), local);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
else if (t === '-P')
|
|
305
|
+
i++;
|
|
306
|
+
else if (t === '--') {
|
|
307
|
+
i++;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
else if (!t.startsWith('-'))
|
|
311
|
+
break;
|
|
312
|
+
i++;
|
|
313
|
+
}
|
|
314
|
+
this.command(args.slice(i), local);
|
|
315
|
+
}
|
|
316
|
+
xcrun(words, args, scope) {
|
|
317
|
+
let i = 0;
|
|
318
|
+
while (i < args.length) {
|
|
319
|
+
const t = args[i]?.text ?? '';
|
|
320
|
+
if (!args[i]?.literal)
|
|
321
|
+
return;
|
|
322
|
+
if (['--find', '-f', '-find'].includes(t) || t.startsWith('--show-sdk') || t.startsWith('-show-sdk'))
|
|
323
|
+
return;
|
|
324
|
+
if (['--sdk', '-sdk', '--toolchain', '-toolchain'].includes(t))
|
|
325
|
+
i += 2;
|
|
326
|
+
else if (t.startsWith('-'))
|
|
327
|
+
i++;
|
|
328
|
+
else
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
if (base(args[i]) === 'simctl')
|
|
332
|
+
this.simctl(words, args.slice(i + 1), scope);
|
|
333
|
+
}
|
|
334
|
+
simctl(words, args, scope) {
|
|
335
|
+
const at = skipOptions(args, 0, new Set(['--set', '--profiles']));
|
|
336
|
+
const sub = value(args[at], scope);
|
|
337
|
+
if (sub === null || SIMCTL_NO_DEVICE.has(sub))
|
|
338
|
+
return;
|
|
339
|
+
const rest = args.slice(at + 1).map(w => value(w, scope));
|
|
340
|
+
if (['shutdown', 'erase', 'delete'].includes(sub) && rest.includes('all')) {
|
|
341
|
+
this.aim({ kind: 'every', platform: 'ios' }, words, scope);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
if (sub === 'delete' && rest.includes('unavailable')) {
|
|
345
|
+
this.aim({ kind: 'every', platform: 'ios' }, words, scope);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
for (const ref of rest) {
|
|
349
|
+
if (ref === null || ref.startsWith('-'))
|
|
350
|
+
continue;
|
|
351
|
+
if (ref === 'booted')
|
|
352
|
+
this.aim({ kind: 'booted' }, words, scope);
|
|
353
|
+
else
|
|
354
|
+
this.aim({ kind: 'device', platform: 'ios', ref }, words, scope);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
adb(words, args, scope) {
|
|
358
|
+
let serial;
|
|
359
|
+
let unselected = false;
|
|
360
|
+
let usb = false;
|
|
361
|
+
let i = 0;
|
|
362
|
+
while (i < args.length) {
|
|
363
|
+
const w = args[i];
|
|
364
|
+
const t = w?.text ?? '';
|
|
365
|
+
if (!w?.literal) {
|
|
366
|
+
if (i === 0)
|
|
367
|
+
return;
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
if (!t.startsWith('-'))
|
|
371
|
+
break;
|
|
372
|
+
if (t === '-s' || t === '--one-device') {
|
|
373
|
+
serial = value(args[i + 1], scope);
|
|
374
|
+
i += 2;
|
|
375
|
+
}
|
|
376
|
+
else if (t.startsWith('-s') && t.length > 2) {
|
|
377
|
+
serial = t.slice(2);
|
|
378
|
+
i++;
|
|
379
|
+
}
|
|
380
|
+
else if (t === '-t' || (t.startsWith('-t') && t.length > 2) || t === '-e') {
|
|
381
|
+
unselected = true;
|
|
382
|
+
i += t === '-t' ? 2 : 1;
|
|
383
|
+
}
|
|
384
|
+
else if (t === '-d') {
|
|
385
|
+
usb = true;
|
|
386
|
+
i++;
|
|
387
|
+
}
|
|
388
|
+
else
|
|
389
|
+
i += ADB_WITH_VALUE.has(t) ? 2 : 1;
|
|
390
|
+
}
|
|
391
|
+
const command = value(args[i], scope);
|
|
392
|
+
if (command === null)
|
|
393
|
+
return;
|
|
394
|
+
const rest = args.slice(i + 1).map(w => value(w, scope));
|
|
395
|
+
if (ADB_READ_ONLY.has(command) || command === '--version')
|
|
396
|
+
return;
|
|
397
|
+
if (rest[0] === '--list' && (command === 'forward' || command === 'reverse'))
|
|
398
|
+
return;
|
|
399
|
+
const selected = serial !== undefined || unselected || usb;
|
|
400
|
+
if (command === 'kill-server' ||
|
|
401
|
+
command === 'connect' ||
|
|
402
|
+
(command === 'disconnect' && rest.length === 0) ||
|
|
403
|
+
(command === 'reconnect' && rest[0] === 'offline') ||
|
|
404
|
+
(command === 'forward' && rest[0] === '--remove-all' && !selected)) {
|
|
405
|
+
this.aim({ kind: 'every', platform: 'android' }, words, scope);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (command === 'disconnect') {
|
|
409
|
+
for (const ref of rest)
|
|
410
|
+
if (ref !== null)
|
|
411
|
+
this.aim({ kind: 'device', platform: 'android', ref }, words, scope);
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (serial === undefined && !unselected && !usb) {
|
|
415
|
+
const fromEnv = scope.env.get('ANDROID_SERIAL');
|
|
416
|
+
if (fromEnv)
|
|
417
|
+
serial = fromEnv;
|
|
418
|
+
}
|
|
419
|
+
if (serial !== undefined && serial !== null)
|
|
420
|
+
this.aim({ kind: 'device', platform: 'android', ref: serial }, words, scope);
|
|
421
|
+
else if (serial === undefined && !usb)
|
|
422
|
+
this.aim({ kind: 'unselected' }, words, scope);
|
|
423
|
+
}
|
|
424
|
+
emulator(words, args, scope) {
|
|
425
|
+
for (let i = 0; i < args.length; i++) {
|
|
426
|
+
const t = value(args[i], scope);
|
|
427
|
+
if (t === null)
|
|
428
|
+
continue;
|
|
429
|
+
if (t === '-avd') {
|
|
430
|
+
const avd = value(args[i + 1], scope);
|
|
431
|
+
if (avd)
|
|
432
|
+
this.aim({ kind: 'device', platform: 'android', ref: avd }, words, scope);
|
|
433
|
+
}
|
|
434
|
+
else if (t.startsWith('@') && t.length > 1) {
|
|
435
|
+
this.aim({ kind: 'device', platform: 'android', ref: t.slice(1) }, words, scope);
|
|
436
|
+
}
|
|
437
|
+
else if (t === '-port') {
|
|
438
|
+
const port = value(args[i + 1], scope);
|
|
439
|
+
if (port)
|
|
440
|
+
this.aim({ kind: 'device', platform: 'android', ref: `emulator-${port}` }, words, scope);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
avdmanager(words, args, scope) {
|
|
445
|
+
const texts = args.map(w => value(w, scope));
|
|
446
|
+
if (!texts.includes('delete') && !texts.includes('move'))
|
|
447
|
+
return;
|
|
448
|
+
for (let i = 0; i < texts.length; i++) {
|
|
449
|
+
const t = texts[i];
|
|
450
|
+
if (t === '-n' || t === '--name') {
|
|
451
|
+
const name = texts[i + 1];
|
|
452
|
+
if (name)
|
|
453
|
+
this.aim({ kind: 'device', platform: 'android', ref: name }, words, scope);
|
|
454
|
+
}
|
|
455
|
+
else if (t?.startsWith('--name=')) {
|
|
456
|
+
this.aim({ kind: 'device', platform: 'android', ref: t.slice('--name='.length) }, words, scope);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
export function aimsOf(script, env, cwd) {
|
|
462
|
+
const interpreter = new Interpreter(env, cwd);
|
|
463
|
+
interpreter.script(script);
|
|
464
|
+
return interpreter.aims;
|
|
465
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
const quiet = { stdout: '', stderr: '', code: 0 };
|
|
3
|
+
const json = (value) => ({ stdout: `${JSON.stringify(value)}\n`, stderr: '', code: 0 });
|
|
4
|
+
const exit2 = (reason) => ({ stdout: '', stderr: `${reason}\n`, code: 2 });
|
|
5
|
+
export const CONVENTIONS = {
|
|
6
|
+
claude: {
|
|
7
|
+
deny: reason => json({ hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: reason } }),
|
|
8
|
+
allow: quiet,
|
|
9
|
+
failExit: 1,
|
|
10
|
+
release: 'at-once',
|
|
11
|
+
keepOn: new Set(['clear', 'resume']),
|
|
12
|
+
},
|
|
13
|
+
codex: { deny: exit2, allow: quiet, failExit: 1, release: 'by-thread', keepOn: new Set(['clear', 'resume']) },
|
|
14
|
+
gemini: { deny: exit2, allow: quiet, failExit: 1, release: 'once-the-owner-exits', keepOn: new Set(['clear']) },
|
|
15
|
+
copilot: {
|
|
16
|
+
deny: reason => json({ permissionDecision: 'deny', permissionDecisionReason: reason }),
|
|
17
|
+
allow: quiet,
|
|
18
|
+
failExit: 0,
|
|
19
|
+
release: 'once-the-owner-exits',
|
|
20
|
+
keepOn: new Set(),
|
|
21
|
+
},
|
|
22
|
+
cursor: {
|
|
23
|
+
deny: reason => json({ permission: 'deny', user_message: reason.split('\n', 1)[0] ?? reason, agent_message: reason }),
|
|
24
|
+
allow: json({ permission: 'allow' }),
|
|
25
|
+
failExit: 1,
|
|
26
|
+
release: 'once-the-owner-exits',
|
|
27
|
+
keepOn: new Set(),
|
|
28
|
+
},
|
|
29
|
+
antigravity: {
|
|
30
|
+
deny: reason => json({ decision: 'deny', reason }),
|
|
31
|
+
allow: quiet,
|
|
32
|
+
failExit: 0,
|
|
33
|
+
release: null,
|
|
34
|
+
keepOn: new Set(),
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
function record(value) {
|
|
38
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
|
|
39
|
+
}
|
|
40
|
+
function text(...values) {
|
|
41
|
+
for (const value of values)
|
|
42
|
+
if (typeof value === 'string' && value !== '')
|
|
43
|
+
return value;
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
function first(value) {
|
|
47
|
+
return Array.isArray(value) ? value[0] : undefined;
|
|
48
|
+
}
|
|
49
|
+
function toolArgs(value) {
|
|
50
|
+
if (typeof value !== 'string')
|
|
51
|
+
return record(value);
|
|
52
|
+
try {
|
|
53
|
+
return record(JSON.parse(value));
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Reads the hook input of every supported agent: Claude Code, Codex, Gemini CLI, Copilot CLI, Cursor and Antigravity. */
|
|
60
|
+
export function readHookInput(raw) {
|
|
61
|
+
const input = raw.trim() === '' ? {} : record(JSON.parse(raw));
|
|
62
|
+
const tool = record(input.tool_input);
|
|
63
|
+
const copilot = toolArgs(input.toolArgs);
|
|
64
|
+
const antigravity = record(record(input.toolCall).args);
|
|
65
|
+
const base = text(input.cwd, first(input.workspace_roots), first(input.workspacePaths));
|
|
66
|
+
const dir = text(tool.dir_path, tool.directory, antigravity.Cwd, copilot.cwd);
|
|
67
|
+
return {
|
|
68
|
+
command: text(tool.command, input.command, copilot.command, antigravity.CommandLine),
|
|
69
|
+
cwd: dir === null ? base : base === null ? dir : path.resolve(base, dir),
|
|
70
|
+
sessionId: text(input.session_id, input.sessionId, input.conversation_id, input.conversationId),
|
|
71
|
+
reason: text(input.reason),
|
|
72
|
+
};
|
|
73
|
+
}
|