agentlane 0.4.1 → 0.5.0
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 +76 -0
- package/dist/agents/claude-plugin.js +54 -8
- package/dist/agents/cli.js +11 -4
- package/dist/agents/hook-check.js +290 -0
- package/dist/agents/launcher.js +34 -6
- package/dist/agents/wiring-check.js +10 -4
- package/dist/agents/wiring.js +6 -33
- package/dist/browser/env.js +27 -7
- package/dist/browser/install.js +144 -6
- package/dist/browser/lane-browser.js +6 -3
- package/dist/browser/stop.js +2 -17
- package/dist/cache/key.js +23 -11
- package/dist/cli.js +63 -23
- package/dist/devices/backend.js +6 -0
- package/dist/devices/emulator.js +15 -5
- package/dist/devices/simctl.js +15 -3
- package/dist/disk-limits.js +134 -0
- package/dist/driver/caller.js +21 -6
- package/dist/driver/client.js +9 -5
- package/dist/driver/engine.js +29 -14
- package/dist/driver/install.js +88 -36
- package/dist/driver/paths.js +15 -11
- package/dist/driver/session.js +4 -1
- package/dist/driver/superseded.js +378 -0
- package/dist/driver-cli.js +32 -23
- package/dist/evidence/device.js +4 -0
- package/dist/evidence/evidence.js +4 -2
- package/dist/evidence/files.js +68 -0
- package/dist/evidence/strays.js +107 -0
- package/dist/hooks/env.js +2 -1
- package/dist/mcp/server.js +15 -0
- package/dist/mcp/tools.js +9 -1
- package/dist/plugin/guard.js +30 -0
- package/dist/plugin/hook-cli.js +101 -6
- package/dist/plugin/hook-mark.js +73 -0
- package/dist/plugin/hook-once.js +78 -0
- package/dist/plugin/shell.js +109 -8
- package/dist/processes.js +52 -2
- package/dist/registry/config.js +12 -8
- package/dist/registry/holds.js +37 -0
- package/dist/registry/leases.js +109 -0
- package/dist/registry/owner-checks.js +55 -0
- package/dist/registry/owner.js +18 -0
- package/dist/registry/parks.js +60 -0
- package/dist/registry/paths.js +28 -4
- package/dist/registry/ports.js +5 -1
- package/dist/registry/prune.js +643 -24
- package/dist/registry/refusal.js +1 -0
- package/dist/registry/registry.js +1258 -235
- package/dist/registry/rows.js +18 -4
- package/dist/registry/status.js +51 -8
- package/dist/registry/store.js +63 -1
- package/dist/registry/touch.js +180 -0
- package/dist/registry-cli.js +197 -36
- package/dist/services/services.js +223 -54
- package/dist/services/system.js +2 -1
- package/dist/up/answers.js +124 -0
- package/dist/up/doctor.js +27 -3
- package/dist/up/exec.js +29 -4
- package/dist/up/lane-files.js +26 -8
- package/dist/up/lane-services.js +8 -3
- package/dist/up/park.js +146 -0
- package/dist/up/preflight.js +2 -10
- package/dist/up/release.js +20 -24
- package/dist/up/restart.js +9 -2
- package/dist/up/sweep.js +437 -0
- package/dist/up/up.js +33 -12
- package/dist/up/wake.js +124 -0
- package/dist/up/waker.js +49 -0
- package/dist/up-cli.js +6 -1
- package/package.json +2 -2
- package/skills/dev-loop/SKILL.md +7 -5
- package/skills/drive/SKILL.md +4 -0
- package/skills/setup/SKILL.md +2 -2
|
@@ -3,7 +3,7 @@ import net from 'node:net';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { tail } from "../hooks/run.js";
|
|
5
5
|
import { CLI } from "../name.js";
|
|
6
|
-
import { describeStart } from "../processes.js";
|
|
6
|
+
import { describeStart, startMs } from "../processes.js";
|
|
7
7
|
export class ServiceFailed extends Error {
|
|
8
8
|
service;
|
|
9
9
|
constructor(service, problem, log) {
|
|
@@ -13,24 +13,27 @@ export class ServiceFailed extends Error {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
const PROBE_TIMEOUT_MS = 2000;
|
|
16
|
-
|
|
17
|
-
const starts = system.
|
|
16
|
+
function checkLeader(system, proc) {
|
|
17
|
+
const starts = system.running([proc.pid]);
|
|
18
18
|
if (!starts)
|
|
19
|
-
return 'cant-tell';
|
|
19
|
+
return { state: 'cant-tell', unread: 'ps could not read when it started' };
|
|
20
20
|
const start = starts.get(proc.pid);
|
|
21
21
|
if (start === undefined)
|
|
22
|
-
return 'gone';
|
|
22
|
+
return { state: 'gone' };
|
|
23
23
|
if (start !== proc.start)
|
|
24
|
-
return 'pid-reused';
|
|
24
|
+
return { state: 'pid-reused' };
|
|
25
25
|
if (proc.cwd === null)
|
|
26
|
-
return 'alive';
|
|
26
|
+
return { state: 'alive' };
|
|
27
27
|
const cwd = system.processes.cwd(proc.pid);
|
|
28
28
|
if (cwd === undefined)
|
|
29
|
-
return 'cant-tell';
|
|
30
|
-
return cwd === proc.cwd ? 'alive' : 'moved';
|
|
29
|
+
return { state: 'cant-tell', unread: 'its working directory could not be read' };
|
|
30
|
+
return { state: cwd === proc.cwd ? 'alive' : 'moved' };
|
|
31
|
+
}
|
|
32
|
+
export function judgeLeader(system, proc) {
|
|
33
|
+
return checkLeader(system, proc).state;
|
|
31
34
|
}
|
|
32
|
-
function describeLeader(
|
|
33
|
-
switch (state) {
|
|
35
|
+
function describeLeader(check, proc) {
|
|
36
|
+
switch (check.state) {
|
|
34
37
|
case 'alive':
|
|
35
38
|
return `pid ${String(proc.pid)} is running`;
|
|
36
39
|
case 'gone':
|
|
@@ -40,7 +43,7 @@ function describeLeader(state, proc) {
|
|
|
40
43
|
case 'moved':
|
|
41
44
|
return `pid ${String(proc.pid)} is no longer in ${proc.cwd ?? '(unknown)'}`;
|
|
42
45
|
case 'cant-tell':
|
|
43
|
-
return `pid ${String(proc.pid)} could not be checked
|
|
46
|
+
return `pid ${String(proc.pid)} could not be checked: ${check.unread}`;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
function connects(host, port) {
|
|
@@ -133,7 +136,8 @@ export function describeListeners(listeners) {
|
|
|
133
136
|
return listeners.map(l => `pid ${String(l.pid)} (${l.command.slice(0, 80)})`).join(', ');
|
|
134
137
|
}
|
|
135
138
|
export async function inspectService(system, service, port, proc) {
|
|
136
|
-
const
|
|
139
|
+
const check = proc ? checkLeader(system, proc) : null;
|
|
140
|
+
const leader = check?.state ?? 'not-started';
|
|
137
141
|
const listeners = listenersOn(system, port, leader === 'alive' && proc ? proc.pid : null);
|
|
138
142
|
const probe = await probeReady(service.ready, port);
|
|
139
143
|
const ours = listeners !== null && listeners.length > 0 && listeners.every(l => l.ours);
|
|
@@ -142,6 +146,7 @@ export async function inspectService(system, service, port, proc) {
|
|
|
142
146
|
port,
|
|
143
147
|
process: proc,
|
|
144
148
|
leader,
|
|
149
|
+
leaderDetail: proc && check ? describeLeader(check, proc) : 'not started by the toolkit',
|
|
145
150
|
listeners,
|
|
146
151
|
ready: probe.ready,
|
|
147
152
|
readyDetail: probe.detail,
|
|
@@ -149,11 +154,7 @@ export async function inspectService(system, service, port, proc) {
|
|
|
149
154
|
};
|
|
150
155
|
}
|
|
151
156
|
export function explainInspection(inspection) {
|
|
152
|
-
const parts = [];
|
|
153
|
-
if (inspection.process)
|
|
154
|
-
parts.push(describeLeader(inspection.leader, inspection.process));
|
|
155
|
-
else
|
|
156
|
-
parts.push('not started by the toolkit');
|
|
157
|
+
const parts = [inspection.leaderDetail];
|
|
157
158
|
if (inspection.listeners === null)
|
|
158
159
|
parts.push(`the listener on ${String(inspection.port)} could not be read`);
|
|
159
160
|
else if (inspection.listeners.length === 0)
|
|
@@ -178,6 +179,7 @@ export function startService(system, service, env, log) {
|
|
|
178
179
|
export async function waitForService(system, service, port, proc, clock, log, pollMs = 250) {
|
|
179
180
|
const deadline = clock.now() + service.timeoutMs;
|
|
180
181
|
for (;;) {
|
|
182
|
+
const checkedAt = clock.now();
|
|
181
183
|
const leader = judgeLeader(system, proc);
|
|
182
184
|
if (leader === 'gone' || leader === 'pid-reused')
|
|
183
185
|
throw new ServiceFailed(service.name, `exited before it was ready (pid ${String(proc.pid)})`, log);
|
|
@@ -189,7 +191,7 @@ export async function waitForService(system, service, port, proc, clock, log, po
|
|
|
189
191
|
const probe = await probeReady(service.ready, port);
|
|
190
192
|
if (probe.ready && listeners !== null && listeners.length > 0) {
|
|
191
193
|
const cwd = system.processes.cwd(proc.pid);
|
|
192
|
-
return { ...proc, cwd: cwd ?? null };
|
|
194
|
+
return { ...proc, cwd: cwd ?? null, ...(leader === 'alive' ? { aliveAt: checkedAt } : {}) };
|
|
193
195
|
}
|
|
194
196
|
if (clock.now() >= deadline) {
|
|
195
197
|
throw new ServiceFailed(service.name, `was not ready after ${String(service.timeoutMs / 1000)} s: ${probe.detail}`, log);
|
|
@@ -197,72 +199,239 @@ export async function waitForService(system, service, port, proc, clock, log, po
|
|
|
197
199
|
await clock.sleep(pollMs);
|
|
198
200
|
}
|
|
199
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* The moment just before a check that found the leader's pid running with its recorded start time, or undefined when
|
|
204
|
+
* the check didn't find it. Store it with `Registry.recordLeaderAlive` so `stopService` can later prove the group.
|
|
205
|
+
*/
|
|
206
|
+
export function leaderAliveAt(system, proc, clock) {
|
|
207
|
+
const at = clock.now();
|
|
208
|
+
return judgeLeader(system, { ...proc, cwd: null }) === 'alive' ? at : undefined;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* `leaderAliveAt` for many processes in one read of the process table: the moment just before it, and those of `procs`
|
|
212
|
+
* it found running with their recorded start time. Null when ps could not read them.
|
|
213
|
+
*/
|
|
214
|
+
export function leadersAliveAt(system, procs, clock) {
|
|
215
|
+
const at = clock.now();
|
|
216
|
+
if (procs.length === 0)
|
|
217
|
+
return { at, alive: [] };
|
|
218
|
+
const starts = system.running(procs.map(p => p.process.pid));
|
|
219
|
+
if (!starts)
|
|
220
|
+
return null;
|
|
221
|
+
return { at, alive: procs.filter(p => starts.get(p.process.pid) === p.process.start) };
|
|
222
|
+
}
|
|
200
223
|
export async function stopService(system, proc, clock, graceMs = 5000, pollMs = 100) {
|
|
201
|
-
const leader =
|
|
202
|
-
if (leader === 'pid-reused' || leader === 'moved')
|
|
224
|
+
const leader = checkLeader(system, proc);
|
|
225
|
+
if (leader.state === 'pid-reused' || leader.state === 'moved')
|
|
203
226
|
return { kind: 'not-ours', reason: describeLeader(leader, proc) };
|
|
204
|
-
if (leader === 'cant-tell')
|
|
227
|
+
if (leader.state === 'cant-tell')
|
|
205
228
|
return { kind: 'cant-tell', reason: describeLeader(leader, proc) };
|
|
206
|
-
|
|
229
|
+
let group;
|
|
230
|
+
if (leader.state === 'gone') {
|
|
207
231
|
const members = system.groupMembers(proc.pid);
|
|
208
232
|
if (members === undefined)
|
|
209
233
|
return { kind: 'cant-tell', reason: 'ps could not list the process group' };
|
|
210
234
|
if (members.length === 0)
|
|
211
235
|
return { kind: 'already-gone' };
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
reason: `
|
|
215
|
-
|
|
236
|
+
const found = withStarts(system, members);
|
|
237
|
+
if (found === undefined)
|
|
238
|
+
return { kind: 'cant-tell', reason: `ps could not read when processes ${members.join(', ')} started` };
|
|
239
|
+
if (!found.some(member => inOriginalGroup(proc, member.start))) {
|
|
240
|
+
return {
|
|
241
|
+
kind: 'cant-tell',
|
|
242
|
+
reason: `its leader pid ${String(proc.pid)} exited and none of processes ${members.join(', ')} left in its group started with it or before it was last seen running, so they can't be proven ours; stop them with kill ${members.join(' ')}`,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
group = found;
|
|
216
246
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
247
|
+
else {
|
|
248
|
+
const members = system.groupMembers(proc.pid);
|
|
249
|
+
const found = members === undefined ? [] : (withStarts(system, members) ?? []);
|
|
250
|
+
group = [{ pid: proc.pid, start: proc.start }, ...found.filter(member => member.pid !== proc.pid)];
|
|
251
|
+
}
|
|
252
|
+
const strays = outsideGroup(system, proc.pid, leader.state === 'gone' ? group.map(member => member.pid) : [proc.pid]);
|
|
253
|
+
const proven = [...group, ...strays.proven];
|
|
254
|
+
const provenPids = proven.map(p => p.pid);
|
|
255
|
+
const left = (processes) => {
|
|
256
|
+
const starts = system.running(processes.map(p => p.pid));
|
|
257
|
+
return starts === undefined ? undefined : processes.filter(p => starts.get(p.pid) === p.start).map(p => p.pid);
|
|
258
|
+
};
|
|
259
|
+
const seen = { groupEveryPoll: true, lastOurs: provenPids, lastInGroup: [] };
|
|
260
|
+
const poll = () => {
|
|
261
|
+
const provenLeft = left(proven);
|
|
262
|
+
const inGroup = system.groupMembers(proc.pid);
|
|
263
|
+
if (provenLeft)
|
|
264
|
+
seen.lastOurs = provenLeft;
|
|
265
|
+
if (inGroup !== undefined)
|
|
266
|
+
seen.lastInGroup = inGroup;
|
|
267
|
+
if (inGroup === undefined || inGroup.length === 0)
|
|
268
|
+
seen.groupEveryPoll = false;
|
|
269
|
+
if (provenLeft === undefined || inGroup === undefined) {
|
|
270
|
+
return { kind: 'unread', starts: provenLeft === undefined, group: inGroup === undefined };
|
|
271
|
+
}
|
|
272
|
+
if (seen.groupEveryPoll) {
|
|
273
|
+
return { kind: 'listed', inGroup, ours: [...inGroup, ...provenLeft.filter(pid => !inGroup.includes(pid))], unproven: [] };
|
|
274
|
+
}
|
|
275
|
+
return { kind: 'listed', inGroup, ours: provenLeft, unproven: inGroup.filter(pid => !provenLeft.includes(pid)) };
|
|
221
276
|
};
|
|
222
|
-
const
|
|
277
|
+
const settled = (p) => p.kind === 'listed' && p.ours.length === 0;
|
|
278
|
+
const waitSettled = async (ms) => {
|
|
223
279
|
const until = clock.now() + ms;
|
|
224
280
|
for (;;) {
|
|
225
|
-
const
|
|
226
|
-
if (
|
|
227
|
-
return
|
|
281
|
+
const now = poll();
|
|
282
|
+
if (settled(now) || clock.now() >= until)
|
|
283
|
+
return now;
|
|
228
284
|
await clock.sleep(pollMs);
|
|
229
285
|
}
|
|
230
286
|
};
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
287
|
+
const killed = { group: false, pids: new Set(), unread: false };
|
|
288
|
+
const sigkill = () => killed.group || killed.pids.size > 0 ? { group: killed.group, pids: [...killed.pids] } : undefined;
|
|
289
|
+
const cantTell = (reasons) => {
|
|
290
|
+
const reason = reasons.join('; ');
|
|
291
|
+
const kill = sigkill();
|
|
292
|
+
return kill ? { kind: 'cant-tell', sent: 'SIGKILL', killed: kill, reason } : { kind: 'cant-tell', sent: 'SIGTERM', reason };
|
|
293
|
+
};
|
|
294
|
+
const outcome = (p) => {
|
|
295
|
+
if (p.kind === 'unread') {
|
|
296
|
+
const failed = [
|
|
297
|
+
...(p.starts ? [`read when processes ${provenPids.join(', ')} started`] : []),
|
|
298
|
+
...(p.group ? [`list process group ${String(proc.pid)}`] : []),
|
|
299
|
+
].join(', nor ');
|
|
300
|
+
const pids = [...new Set([...seen.lastOurs, ...seen.lastInGroup])].join(' ');
|
|
301
|
+
return cantTell([
|
|
302
|
+
pids === ''
|
|
303
|
+
? `ps could not ${failed}, so it can't be proven stopped`
|
|
304
|
+
: `ps could not ${failed}, so processes ${pids} can't be proven stopped; stop them with kill ${pids}`,
|
|
305
|
+
...strays.unread,
|
|
306
|
+
]);
|
|
307
|
+
}
|
|
308
|
+
const sentKill = (pid) => killed.pids.has(pid) || (killed.group && p.inGroup.includes(pid));
|
|
309
|
+
const survivors = p.ours.filter(sentKill);
|
|
310
|
+
const unkilled = p.ours.filter(pid => !sentKill(pid));
|
|
311
|
+
if (unkilled.length === 0 && strays.unread.length === 0 && survivors.length > 0) {
|
|
312
|
+
return { kind: 'survived', members: survivors, ...(p.unproven.length > 0 ? { unproven: p.unproven } : {}) };
|
|
313
|
+
}
|
|
314
|
+
const why = killed.unread ? ': ps could not read when they started, so they were' : ' and were';
|
|
315
|
+
const reasons = [
|
|
316
|
+
...(unkilled.length > 0
|
|
317
|
+
? [`processes ${unkilled.join(', ')} remain${why} not sent SIGKILL; stop them with kill ${unkilled.join(' ')}`]
|
|
318
|
+
: []),
|
|
319
|
+
...(survivors.length > 0 ? [`processes ${survivors.join(', ')} survived SIGKILL`] : []),
|
|
320
|
+
...(p.unproven.length > 0 ? [unprovenLeft(proc.pid, p.unproven)] : []),
|
|
321
|
+
...strays.unread,
|
|
322
|
+
];
|
|
323
|
+
if (reasons.length > 0)
|
|
324
|
+
return cantTell(reasons);
|
|
325
|
+
const kill = sigkill();
|
|
326
|
+
return kill ? { kind: 'stopped', signal: 'SIGKILL', killed: kill } : { kind: 'stopped', signal: 'SIGTERM' };
|
|
235
327
|
};
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
328
|
+
system.signalGroup(proc.pid, 'SIGTERM');
|
|
329
|
+
for (const stray of strays.proven)
|
|
330
|
+
system.signal(stray.pid, 'SIGTERM');
|
|
331
|
+
const grace = await waitSettled(graceMs);
|
|
332
|
+
if (settled(grace))
|
|
333
|
+
return outcome(grace);
|
|
334
|
+
// A pid can't name a new process group while a group of that id lives (XBD 4.14), but polls only sample the group:
|
|
335
|
+
// one listed with processes in it at every poll since SIGTERM may have emptied and been made anew between two polls
|
|
336
|
+
// or since the last one. That window is bounded by one poll interval, not ruled out.
|
|
337
|
+
if (seen.groupEveryPoll)
|
|
338
|
+
killed.group = system.signalGroup(proc.pid, 'SIGKILL');
|
|
339
|
+
const alive = left(proven);
|
|
340
|
+
killed.unread = alive === undefined;
|
|
341
|
+
for (const pid of alive ?? [])
|
|
342
|
+
if (system.signal(pid, 'SIGKILL'))
|
|
343
|
+
killed.pids.add(pid);
|
|
344
|
+
return outcome(await waitSettled(2000));
|
|
242
345
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
346
|
+
function unprovenLeft(pgid, pids) {
|
|
347
|
+
return `processes ${pids.join(', ')} in a process group of id ${String(pgid)} can't be proven ours; stop them with kill ${pids.join(' ')}`;
|
|
348
|
+
}
|
|
349
|
+
function withStarts(system, pids) {
|
|
350
|
+
const starts = system.running(pids);
|
|
351
|
+
if (!starts)
|
|
352
|
+
return undefined;
|
|
249
353
|
return pids.flatMap(pid => {
|
|
250
|
-
const start = starts
|
|
354
|
+
const start = starts.get(pid);
|
|
251
355
|
return start === undefined ? [] : [{ pid, start }];
|
|
252
356
|
});
|
|
253
357
|
}
|
|
358
|
+
const STARTED_WITH_LEADER_MS = 1000;
|
|
359
|
+
const START_RESOLUTION_MS = 1000;
|
|
360
|
+
/**
|
|
361
|
+
* Whether a process left in the group after its leader exited proves the group is still the one the leader started.
|
|
362
|
+
* POSIX keeps a pid from naming a new process while a process group of that id lives (XBD 4.14 Process ID Reuse;
|
|
363
|
+
* XNU's forkproc skips such pids), so a later group of that id is made after the original group is gone, a full cycle
|
|
364
|
+
* of the pid space later. A process started in the leader's second or the next is older than such a group could be,
|
|
365
|
+
* and so is one started before a moment the leader was seen running, when the original group still held the id.
|
|
366
|
+
*/
|
|
367
|
+
function inOriginalGroup(proc, start) {
|
|
368
|
+
const member = startMs(start);
|
|
369
|
+
const after = member - startMs(proc.start);
|
|
370
|
+
if (Number.isNaN(after) || after < 0)
|
|
371
|
+
return false;
|
|
372
|
+
if (after <= STARTED_WITH_LEADER_MS)
|
|
373
|
+
return true;
|
|
374
|
+
return proc.aliveAt !== undefined && member + START_RESOLUTION_MS <= proc.aliveAt;
|
|
375
|
+
}
|
|
376
|
+
function retryOnce(read) {
|
|
377
|
+
return read() ?? read();
|
|
378
|
+
}
|
|
379
|
+
/** The service's processes that left its process group, found while a process of the group still ties them to it. */
|
|
380
|
+
function outsideGroup(system, pgid, roots) {
|
|
381
|
+
const below = new Map();
|
|
382
|
+
const unlisted = [];
|
|
383
|
+
for (const root of roots) {
|
|
384
|
+
if (below.has(root))
|
|
385
|
+
continue;
|
|
386
|
+
const descendants = retryOnce(() => system.descendants(root));
|
|
387
|
+
if (descendants === undefined)
|
|
388
|
+
unlisted.push(root);
|
|
389
|
+
for (const d of descendants ?? [])
|
|
390
|
+
below.set(d.pid, d.pgid);
|
|
391
|
+
}
|
|
392
|
+
const pids = [...below].filter(([, group]) => group !== pgid).map(([pid]) => pid);
|
|
393
|
+
const proven = pids.length === 0 ? [] : retryOnce(() => withStarts(system, pids));
|
|
394
|
+
return {
|
|
395
|
+
proven: proven ?? [],
|
|
396
|
+
unread: [
|
|
397
|
+
...(unlisted.length > 0
|
|
398
|
+
? [
|
|
399
|
+
`ps could not list the processes below ${unlisted.length === 1 ? 'pid' : 'pids'} ${unlisted.join(', ')}, so any of them outside process group ${String(pgid)} were not found and were sent nothing`,
|
|
400
|
+
]
|
|
401
|
+
: []),
|
|
402
|
+
...(proven === undefined
|
|
403
|
+
? [
|
|
404
|
+
`ps could not read when processes ${pids.join(', ')} started, so they were sent nothing; stop them with kill ${pids.join(' ')}`,
|
|
405
|
+
]
|
|
406
|
+
: []),
|
|
407
|
+
],
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function describeKilled(pgid, killed) {
|
|
411
|
+
return [
|
|
412
|
+
...(killed.group ? [`process group ${String(pgid)}`] : []),
|
|
413
|
+
...(killed.pids.length > 0 ? [`processes ${killed.pids.join(', ')}`] : []),
|
|
414
|
+
].join(' and ');
|
|
415
|
+
}
|
|
254
416
|
export function describeStop(proc, outcome) {
|
|
255
417
|
const who = `${proc.service} (pid ${String(proc.pid)}, started ${describeStart(proc.start)})`;
|
|
256
418
|
switch (outcome.kind) {
|
|
257
419
|
case 'stopped':
|
|
258
|
-
|
|
420
|
+
if (outcome.signal === 'SIGTERM')
|
|
421
|
+
return `stopped ${who}`;
|
|
422
|
+
return `stopped ${who} with SIGKILL to ${describeKilled(proc.pid, outcome.killed)}, which SIGTERM did not end`;
|
|
259
423
|
case 'already-gone':
|
|
260
424
|
return `${who} had already exited`;
|
|
261
425
|
case 'not-ours':
|
|
262
426
|
return `left ${who} alone: ${outcome.reason}`;
|
|
263
427
|
case 'cant-tell':
|
|
428
|
+
if (outcome.sent === 'SIGKILL') {
|
|
429
|
+
return `sent SIGTERM to ${who}, then SIGKILL to ${describeKilled(proc.pid, outcome.killed)}, but ${outcome.reason}`;
|
|
430
|
+
}
|
|
431
|
+
if (outcome.sent === 'SIGTERM')
|
|
432
|
+
return `sent SIGTERM to ${who}, but ${outcome.reason}`;
|
|
264
433
|
return `left ${who} alone: ${outcome.reason}`;
|
|
265
434
|
case 'survived':
|
|
266
|
-
return `${who} survived SIGKILL: processes ${outcome.members.join(', ')} remain`;
|
|
435
|
+
return `${who} survived SIGKILL: processes ${outcome.members.join(', ')} remain${outcome.unproven ? `; ${unprovenLeft(proc.pid, outcome.unproven)}` : ''}`;
|
|
267
436
|
}
|
|
268
437
|
}
|
package/dist/services/system.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { spawn, spawnSync } from 'node:child_process';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { systemProcesses } from "../processes.js";
|
|
4
|
+
import { runningStartTimes, systemProcesses } from "../processes.js";
|
|
5
5
|
const SEARCH_PATH = `${process.env.PATH ?? ''}:/usr/sbin:/usr/bin:/bin:/sbin`;
|
|
6
6
|
function run(command, args) {
|
|
7
7
|
const result = spawnSync(command, args, {
|
|
@@ -97,6 +97,7 @@ function deliver(target, signal) {
|
|
|
97
97
|
}
|
|
98
98
|
export const realServiceSystem = {
|
|
99
99
|
processes: systemProcesses,
|
|
100
|
+
running: runningStartTimes,
|
|
100
101
|
spawnGroup(command, options) {
|
|
101
102
|
fs.mkdirSync(path.dirname(options.log), { recursive: true });
|
|
102
103
|
fs.appendFileSync(options.log, `--- ${new Date().toISOString()} start: ${command}\n`);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { JAVA_HOME_ENV } from "../hooks/env.js";
|
|
2
|
+
class Remembered {
|
|
3
|
+
answers = new Map();
|
|
4
|
+
ask(key, question) {
|
|
5
|
+
const known = this.answers.get(key);
|
|
6
|
+
if (known)
|
|
7
|
+
return known;
|
|
8
|
+
const answer = question();
|
|
9
|
+
this.answers.set(key, answer);
|
|
10
|
+
answer.catch(() => {
|
|
11
|
+
if (this.answers.get(key) === answer)
|
|
12
|
+
this.answers.delete(key);
|
|
13
|
+
});
|
|
14
|
+
return answer;
|
|
15
|
+
}
|
|
16
|
+
forget() {
|
|
17
|
+
this.answers.clear();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function rememberToolchain(toolchain) {
|
|
21
|
+
const xcode = new Remembered();
|
|
22
|
+
const charmaps = new Remembered();
|
|
23
|
+
const javas = new Remembered();
|
|
24
|
+
return {
|
|
25
|
+
xcodeVersion: () => xcode.ask('', () => toolchain.xcodeVersion()),
|
|
26
|
+
androidToolchain: (root, env) => toolchain.androidToolchain(root, env),
|
|
27
|
+
localeCharmap: locale => charmaps.ask(locale, () => toolchain.localeCharmap(locale)),
|
|
28
|
+
findJava17: env => javas.ask(JSON.stringify([env[JAVA_HOME_ENV] ?? null, env.JAVA_HOME ?? null]), () => toolchain.findJava17(env)),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function rememberBackend(backend, changed) {
|
|
32
|
+
const specs = new Map();
|
|
33
|
+
const changing = (act) => (...args) => {
|
|
34
|
+
changed();
|
|
35
|
+
let result;
|
|
36
|
+
try {
|
|
37
|
+
result = act(...args);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
changed();
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
if (result instanceof Promise)
|
|
44
|
+
return result.finally(changed);
|
|
45
|
+
changed();
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
const resolveSpec = (request) => {
|
|
49
|
+
const key = JSON.stringify([request.deviceType ?? null, request.runtime ?? null]);
|
|
50
|
+
const known = specs.get(key);
|
|
51
|
+
if (known)
|
|
52
|
+
return { ...known };
|
|
53
|
+
const spec = backend.resolveSpec(request);
|
|
54
|
+
specs.set(key, spec);
|
|
55
|
+
return { ...spec };
|
|
56
|
+
};
|
|
57
|
+
const remembered = {
|
|
58
|
+
resolveSpec,
|
|
59
|
+
create: changing((name, spec) => backend.create(name, spec)),
|
|
60
|
+
delete: changing((id) => {
|
|
61
|
+
backend.delete(id);
|
|
62
|
+
}),
|
|
63
|
+
shutdown: changing((id) => {
|
|
64
|
+
backend.shutdown(id);
|
|
65
|
+
}),
|
|
66
|
+
boot: changing((id, consolePort) => backend.boot(id, consolePort)),
|
|
67
|
+
};
|
|
68
|
+
return new Proxy(backend, {
|
|
69
|
+
get(target, property) {
|
|
70
|
+
if (Object.hasOwn(remembered, property))
|
|
71
|
+
return remembered[property];
|
|
72
|
+
const value = Reflect.get(target, property, target);
|
|
73
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function rememberSim(sim, devices) {
|
|
78
|
+
const device = async (udid) => {
|
|
79
|
+
const info = await devices.ask(udid, () => sim.device(udid));
|
|
80
|
+
return info && { ...info };
|
|
81
|
+
};
|
|
82
|
+
const changing = (act) => async (udid) => {
|
|
83
|
+
devices.forget();
|
|
84
|
+
try {
|
|
85
|
+
await act(udid);
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
devices.forget();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const boot = changing(udid => sim.boot(udid));
|
|
92
|
+
const shutdown = changing(udid => sim.shutdown(udid));
|
|
93
|
+
return new Proxy(sim, {
|
|
94
|
+
get(target, property) {
|
|
95
|
+
if (property === 'device')
|
|
96
|
+
return device;
|
|
97
|
+
if (property === 'boot')
|
|
98
|
+
return boot;
|
|
99
|
+
if (property === 'shutdown')
|
|
100
|
+
return shutdown;
|
|
101
|
+
const value = Reflect.get(target, property, target);
|
|
102
|
+
return typeof value === 'function' ? value.bind(target) : value;
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
export function rememberAnswers(given) {
|
|
107
|
+
const sims = new Remembered();
|
|
108
|
+
const forgetDeviceStates = () => {
|
|
109
|
+
sims.forget();
|
|
110
|
+
};
|
|
111
|
+
const devices = {};
|
|
112
|
+
for (const [platform, backend] of Object.entries(given.devices)) {
|
|
113
|
+
devices[platform] = rememberBackend(backend, forgetDeviceStates);
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
deps: {
|
|
117
|
+
...given,
|
|
118
|
+
toolchain: rememberToolchain(given.toolchain),
|
|
119
|
+
devices,
|
|
120
|
+
sim: given.sim && rememberSim(given.sim, sims),
|
|
121
|
+
},
|
|
122
|
+
forgetDeviceStates,
|
|
123
|
+
};
|
|
124
|
+
}
|
package/dist/up/doctor.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { setupFix } from "../agents/skills.js";
|
|
2
|
-
import {
|
|
2
|
+
import { agentHookChecks } from "../agents/hook-check.js";
|
|
3
|
+
import { agentsSetUp, agentWiringChecks } from "../agents/wiring-check.js";
|
|
3
4
|
import { browserChecks, hasBrowser } from "../browser/lane-browser.js";
|
|
4
5
|
import { realBrowserTools } from "../browser/tools.js";
|
|
5
6
|
import { stateDir } from "../registry/paths.js";
|
|
@@ -16,6 +17,8 @@ import { judgeAndroidVariant, judgeIosVariant, readIosBundle, } from "../devices
|
|
|
16
17
|
import { CLI } from "../name.js";
|
|
17
18
|
import { asMobile } from "../project/config.js";
|
|
18
19
|
import { AGENTS, describeOwner, describeState } from "../registry/owner.js";
|
|
20
|
+
import { formatTime } from "../registry/format.js";
|
|
21
|
+
import { describeRestarts } from "../registry/parks.js";
|
|
19
22
|
import { explainInspection, inspectService, listenersElsewhere } from "../services/services.js";
|
|
20
23
|
import { toolchainFindings } from "./preflight.js";
|
|
21
24
|
function variantCheck(verdict, expected) {
|
|
@@ -201,8 +204,11 @@ export function describeMaestroBuild(build) {
|
|
|
201
204
|
}
|
|
202
205
|
}
|
|
203
206
|
function wiringChecks(config, folder, env) {
|
|
204
|
-
const
|
|
205
|
-
|
|
207
|
+
const root = config?.dir ?? folder;
|
|
208
|
+
const wired = agentWiringChecks(root, env);
|
|
209
|
+
if (wired.length > 0)
|
|
210
|
+
return [...wired, ...agentHookChecks(root, agentsSetUp(root), env)];
|
|
211
|
+
if (!config)
|
|
206
212
|
return wired;
|
|
207
213
|
return [
|
|
208
214
|
{
|
|
@@ -257,6 +263,10 @@ export async function diagnose(deps, input) {
|
|
|
257
263
|
checks.push({ name: 'Maestro', ok: true, detail: describeMaestroBuild(await maestroBuild(deps.env)), fix: '' });
|
|
258
264
|
}
|
|
259
265
|
}
|
|
266
|
+
if (lane && !mismatch && input.park) {
|
|
267
|
+
checks.push(parkCheck(lane, input.park));
|
|
268
|
+
return finish(lane, checks);
|
|
269
|
+
}
|
|
260
270
|
if (!config || !lane || mismatch)
|
|
261
271
|
return finish(lane, checks);
|
|
262
272
|
checks.push(...resourceChecks(config, lane));
|
|
@@ -410,6 +420,20 @@ async function webAppCheck(tools, config, lane, checks) {
|
|
|
410
420
|
fix: answer === null ? UP : `read the log of ${service} in the lane's log folder`,
|
|
411
421
|
};
|
|
412
422
|
}
|
|
423
|
+
function parkCheck(lane, park) {
|
|
424
|
+
const by = park.by === null ? '' : ` by pid ${String(park.by)}`;
|
|
425
|
+
const problems = park.problems.length > 0 ? `; ${park.problems.join('; ')}` : '';
|
|
426
|
+
const detail = park.state === 'parked'
|
|
427
|
+
? `lane ${lane.id} has been parked since ${formatTime(park.parkedAt ?? park.since)}, after going unused: its device went back to the pool and its services stopped, and its next call brings back ${describeRestarts(park.restarts)}${problems}`
|
|
428
|
+
: `lane ${lane.id} is being ${park.state === 'parking' ? 'parked' : 'brought back'}${by} since ${formatTime(park.since)}${problems}`;
|
|
429
|
+
return {
|
|
430
|
+
name: 'parked',
|
|
431
|
+
ok: true,
|
|
432
|
+
warning: true,
|
|
433
|
+
detail,
|
|
434
|
+
fix: `any call on the lane (${CLI} look, ${CLI} exec, ${CLI} restart) brings it back first, and so does ${UP}`,
|
|
435
|
+
};
|
|
436
|
+
}
|
|
413
437
|
function finish(lane, checks) {
|
|
414
438
|
return { ok: checks.every(c => c.ok), lane: lane?.id ?? null, checks };
|
|
415
439
|
}
|
package/dist/up/exec.js
CHANGED
|
@@ -11,12 +11,15 @@ import { CLI, TOOL } from "../name.js";
|
|
|
11
11
|
import { asMobile, findProjectConfig, loadLaneConfig } from "../project/config.js";
|
|
12
12
|
import { describeOwner, resolveOwner } from "../registry/owner.js";
|
|
13
13
|
import { stateDir } from "../registry/paths.js";
|
|
14
|
-
import { NotClaimed, UsageError } from "../registry/refusal.js";
|
|
14
|
+
import { NotClaimed, Refusal, UsageError } from "../registry/refusal.js";
|
|
15
15
|
import { Registry } from "../registry/registry.js";
|
|
16
|
+
import { keepTouching, recordCall, touchLane } from "../registry/touch.js";
|
|
16
17
|
import { resolveFolder } from "../registry-cli.js";
|
|
17
18
|
import { laneDir, readUpRecord } from "./lane-files.js";
|
|
18
19
|
import { reversePorts } from "./doctor.js";
|
|
19
20
|
import { driverVariables } from "./maestro-env.js";
|
|
21
|
+
import { enterLane } from "./wake.js";
|
|
22
|
+
import { upWaker } from "./waker.js";
|
|
20
23
|
function lenientConfig(file, platform, log) {
|
|
21
24
|
if (!file)
|
|
22
25
|
return { config: null, problem: null };
|
|
@@ -64,16 +67,24 @@ export async function execInLane(deps, argv) {
|
|
|
64
67
|
clock: deps.clock,
|
|
65
68
|
});
|
|
66
69
|
let lane;
|
|
70
|
+
let park;
|
|
67
71
|
try {
|
|
68
|
-
lane = registry.
|
|
72
|
+
lane = registry.takeBack(owner, folder.worktree);
|
|
69
73
|
if (!lane) {
|
|
70
74
|
throw new NotClaimed(`${describeOwner(owner)} holds no lane in ${folder.worktree}`, `${CLI} up (or ${CLI} claim)`);
|
|
71
75
|
}
|
|
72
|
-
|
|
76
|
+
recordCall(state, { id: lane.id, token: lane.token }, deps.clock.now());
|
|
77
|
+
park = registry.parkOf(lane.id);
|
|
73
78
|
}
|
|
74
79
|
finally {
|
|
75
80
|
registry.close();
|
|
76
81
|
}
|
|
82
|
+
lane = await enterLane({ stateDir: state, processes: deps.processes, clock: deps.clock }, lane, park, upWaker(deps), line => {
|
|
83
|
+
deps.log(`${TOOL} exec: ${line}`);
|
|
84
|
+
});
|
|
85
|
+
const site = { dir: state, processes: deps.processes, clock: deps.clock };
|
|
86
|
+
const ref = { id: lane.id, token: lane.token };
|
|
87
|
+
touchLane(site, ref, `exec: ${command}`);
|
|
77
88
|
const dir = laneDir(state, lane.id);
|
|
78
89
|
const record = readUpRecord(dir);
|
|
79
90
|
const { config, problem } = lenientConfig(record?.config ?? findProjectConfig(deps.cwd), record?.platform ?? lane.device?.platform, deps.log);
|
|
@@ -96,7 +107,21 @@ export async function execInLane(deps, argv) {
|
|
|
96
107
|
: null;
|
|
97
108
|
if (browser)
|
|
98
109
|
env = { ...env, ...browser.vars };
|
|
99
|
-
const
|
|
110
|
+
const stopTouching = keepTouching(site, ref, `exec: ${command}`, deps.heartbeatMs);
|
|
111
|
+
let code;
|
|
112
|
+
try {
|
|
113
|
+
code = await run(deps, command, args, env);
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
stopTouching();
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
touchLane(site, ref, `exec: ${command}`);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (!(error instanceof Refusal))
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
100
125
|
if (code !== 0 && browser && (await browser.control.isOpen().catch(() => false))) {
|
|
101
126
|
const kept = await keepFailureEvidence(browser.control, browser.setting.paths.evidence, [command, ...args].join(' '));
|
|
102
127
|
deps.log(`${TOOL} exec: ${command} exited ${String(code)}; kept the lane's browser as it was in ${kept.dir}: ${kept.files.map(f => path.basename(f)).join(', ') || 'nothing could be read'}${kept.problems.length > 0 ? ` (${kept.problems.join('; ')})` : ''}`);
|