agentlane 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/dist/agents/claude-plugin.js +69 -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/hygiene.js +20 -4
- 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 +1261 -236
- package/dist/registry/rows.js +18 -4
- package/dist/registry/status.js +51 -8
- package/dist/registry/store.js +65 -2
- package/dist/registry/touch.js +180 -0
- package/dist/registry-cli.js +197 -36
- package/dist/services/services.js +227 -56
- package/dist/services/system.js +2 -1
- package/dist/up/answers.js +124 -0
- package/dist/up/doctor.js +29 -4
- 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 +38 -15
- 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,15 +136,17 @@ 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
|
-
const ours = listeners
|
|
143
|
+
const ours = listeners === null || (listeners.length > 0 && listeners.every(l => l.ours));
|
|
140
144
|
return {
|
|
141
145
|
service: service.name,
|
|
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,13 +154,11 @@ 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
|
-
parts.push(
|
|
159
|
+
parts.push(inspection.healthy
|
|
160
|
+
? `the listener on ${String(inspection.port)} could not be read, so its ready check stands for it`
|
|
161
|
+
: `the listener on ${String(inspection.port)} could not be read`);
|
|
159
162
|
else if (inspection.listeners.length === 0)
|
|
160
163
|
parts.push(`nothing listens on ${String(inspection.port)}`);
|
|
161
164
|
else {
|
|
@@ -178,6 +181,7 @@ export function startService(system, service, env, log) {
|
|
|
178
181
|
export async function waitForService(system, service, port, proc, clock, log, pollMs = 250) {
|
|
179
182
|
const deadline = clock.now() + service.timeoutMs;
|
|
180
183
|
for (;;) {
|
|
184
|
+
const checkedAt = clock.now();
|
|
181
185
|
const leader = judgeLeader(system, proc);
|
|
182
186
|
if (leader === 'gone' || leader === 'pid-reused')
|
|
183
187
|
throw new ServiceFailed(service.name, `exited before it was ready (pid ${String(proc.pid)})`, log);
|
|
@@ -189,7 +193,7 @@ export async function waitForService(system, service, port, proc, clock, log, po
|
|
|
189
193
|
const probe = await probeReady(service.ready, port);
|
|
190
194
|
if (probe.ready && listeners !== null && listeners.length > 0) {
|
|
191
195
|
const cwd = system.processes.cwd(proc.pid);
|
|
192
|
-
return { ...proc, cwd: cwd ?? null };
|
|
196
|
+
return { ...proc, cwd: cwd ?? null, ...(leader === 'alive' ? { aliveAt: checkedAt } : {}) };
|
|
193
197
|
}
|
|
194
198
|
if (clock.now() >= deadline) {
|
|
195
199
|
throw new ServiceFailed(service.name, `was not ready after ${String(service.timeoutMs / 1000)} s: ${probe.detail}`, log);
|
|
@@ -197,72 +201,239 @@ export async function waitForService(system, service, port, proc, clock, log, po
|
|
|
197
201
|
await clock.sleep(pollMs);
|
|
198
202
|
}
|
|
199
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* The moment just before a check that found the leader's pid running with its recorded start time, or undefined when
|
|
206
|
+
* the check didn't find it. Store it with `Registry.recordLeaderAlive` so `stopService` can later prove the group.
|
|
207
|
+
*/
|
|
208
|
+
export function leaderAliveAt(system, proc, clock) {
|
|
209
|
+
const at = clock.now();
|
|
210
|
+
return judgeLeader(system, { ...proc, cwd: null }) === 'alive' ? at : undefined;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* `leaderAliveAt` for many processes in one read of the process table: the moment just before it, and those of `procs`
|
|
214
|
+
* it found running with their recorded start time. Null when ps could not read them.
|
|
215
|
+
*/
|
|
216
|
+
export function leadersAliveAt(system, procs, clock) {
|
|
217
|
+
const at = clock.now();
|
|
218
|
+
if (procs.length === 0)
|
|
219
|
+
return { at, alive: [] };
|
|
220
|
+
const starts = system.running(procs.map(p => p.process.pid));
|
|
221
|
+
if (!starts)
|
|
222
|
+
return null;
|
|
223
|
+
return { at, alive: procs.filter(p => starts.get(p.process.pid) === p.process.start) };
|
|
224
|
+
}
|
|
200
225
|
export async function stopService(system, proc, clock, graceMs = 5000, pollMs = 100) {
|
|
201
|
-
const leader =
|
|
202
|
-
if (leader === 'pid-reused' || leader === 'moved')
|
|
226
|
+
const leader = checkLeader(system, proc);
|
|
227
|
+
if (leader.state === 'pid-reused' || leader.state === 'moved')
|
|
203
228
|
return { kind: 'not-ours', reason: describeLeader(leader, proc) };
|
|
204
|
-
if (leader === 'cant-tell')
|
|
229
|
+
if (leader.state === 'cant-tell')
|
|
205
230
|
return { kind: 'cant-tell', reason: describeLeader(leader, proc) };
|
|
206
|
-
|
|
231
|
+
let group;
|
|
232
|
+
if (leader.state === 'gone') {
|
|
207
233
|
const members = system.groupMembers(proc.pid);
|
|
208
234
|
if (members === undefined)
|
|
209
235
|
return { kind: 'cant-tell', reason: 'ps could not list the process group' };
|
|
210
236
|
if (members.length === 0)
|
|
211
237
|
return { kind: 'already-gone' };
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
reason: `
|
|
215
|
-
|
|
238
|
+
const found = withStarts(system, members);
|
|
239
|
+
if (found === undefined)
|
|
240
|
+
return { kind: 'cant-tell', reason: `ps could not read when processes ${members.join(', ')} started` };
|
|
241
|
+
if (!found.some(member => inOriginalGroup(proc, member.start))) {
|
|
242
|
+
return {
|
|
243
|
+
kind: 'cant-tell',
|
|
244
|
+
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(' ')}`,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
group = found;
|
|
216
248
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
249
|
+
else {
|
|
250
|
+
const members = system.groupMembers(proc.pid);
|
|
251
|
+
const found = members === undefined ? [] : (withStarts(system, members) ?? []);
|
|
252
|
+
group = [{ pid: proc.pid, start: proc.start }, ...found.filter(member => member.pid !== proc.pid)];
|
|
253
|
+
}
|
|
254
|
+
const strays = outsideGroup(system, proc.pid, leader.state === 'gone' ? group.map(member => member.pid) : [proc.pid]);
|
|
255
|
+
const proven = [...group, ...strays.proven];
|
|
256
|
+
const provenPids = proven.map(p => p.pid);
|
|
257
|
+
const left = (processes) => {
|
|
258
|
+
const starts = system.running(processes.map(p => p.pid));
|
|
259
|
+
return starts === undefined ? undefined : processes.filter(p => starts.get(p.pid) === p.start).map(p => p.pid);
|
|
260
|
+
};
|
|
261
|
+
const seen = { groupEveryPoll: true, lastOurs: provenPids, lastInGroup: [] };
|
|
262
|
+
const poll = () => {
|
|
263
|
+
const provenLeft = left(proven);
|
|
264
|
+
const inGroup = system.groupMembers(proc.pid);
|
|
265
|
+
if (provenLeft)
|
|
266
|
+
seen.lastOurs = provenLeft;
|
|
267
|
+
if (inGroup !== undefined)
|
|
268
|
+
seen.lastInGroup = inGroup;
|
|
269
|
+
if (inGroup === undefined || inGroup.length === 0)
|
|
270
|
+
seen.groupEveryPoll = false;
|
|
271
|
+
if (provenLeft === undefined || inGroup === undefined) {
|
|
272
|
+
return { kind: 'unread', starts: provenLeft === undefined, group: inGroup === undefined };
|
|
273
|
+
}
|
|
274
|
+
if (seen.groupEveryPoll) {
|
|
275
|
+
return { kind: 'listed', inGroup, ours: [...inGroup, ...provenLeft.filter(pid => !inGroup.includes(pid))], unproven: [] };
|
|
276
|
+
}
|
|
277
|
+
return { kind: 'listed', inGroup, ours: provenLeft, unproven: inGroup.filter(pid => !provenLeft.includes(pid)) };
|
|
221
278
|
};
|
|
222
|
-
const
|
|
279
|
+
const settled = (p) => p.kind === 'listed' && p.ours.length === 0;
|
|
280
|
+
const waitSettled = async (ms) => {
|
|
223
281
|
const until = clock.now() + ms;
|
|
224
282
|
for (;;) {
|
|
225
|
-
const
|
|
226
|
-
if (
|
|
227
|
-
return
|
|
283
|
+
const now = poll();
|
|
284
|
+
if (settled(now) || clock.now() >= until)
|
|
285
|
+
return now;
|
|
228
286
|
await clock.sleep(pollMs);
|
|
229
287
|
}
|
|
230
288
|
};
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
289
|
+
const killed = { group: false, pids: new Set(), unread: false };
|
|
290
|
+
const sigkill = () => killed.group || killed.pids.size > 0 ? { group: killed.group, pids: [...killed.pids] } : undefined;
|
|
291
|
+
const cantTell = (reasons) => {
|
|
292
|
+
const reason = reasons.join('; ');
|
|
293
|
+
const kill = sigkill();
|
|
294
|
+
return kill ? { kind: 'cant-tell', sent: 'SIGKILL', killed: kill, reason } : { kind: 'cant-tell', sent: 'SIGTERM', reason };
|
|
295
|
+
};
|
|
296
|
+
const outcome = (p) => {
|
|
297
|
+
if (p.kind === 'unread') {
|
|
298
|
+
const failed = [
|
|
299
|
+
...(p.starts ? [`read when processes ${provenPids.join(', ')} started`] : []),
|
|
300
|
+
...(p.group ? [`list process group ${String(proc.pid)}`] : []),
|
|
301
|
+
].join(', nor ');
|
|
302
|
+
const pids = [...new Set([...seen.lastOurs, ...seen.lastInGroup])].join(' ');
|
|
303
|
+
return cantTell([
|
|
304
|
+
pids === ''
|
|
305
|
+
? `ps could not ${failed}, so it can't be proven stopped`
|
|
306
|
+
: `ps could not ${failed}, so processes ${pids} can't be proven stopped; stop them with kill ${pids}`,
|
|
307
|
+
...strays.unread,
|
|
308
|
+
]);
|
|
309
|
+
}
|
|
310
|
+
const sentKill = (pid) => killed.pids.has(pid) || (killed.group && p.inGroup.includes(pid));
|
|
311
|
+
const survivors = p.ours.filter(sentKill);
|
|
312
|
+
const unkilled = p.ours.filter(pid => !sentKill(pid));
|
|
313
|
+
if (unkilled.length === 0 && strays.unread.length === 0 && survivors.length > 0) {
|
|
314
|
+
return { kind: 'survived', members: survivors, ...(p.unproven.length > 0 ? { unproven: p.unproven } : {}) };
|
|
315
|
+
}
|
|
316
|
+
const why = killed.unread ? ': ps could not read when they started, so they were' : ' and were';
|
|
317
|
+
const reasons = [
|
|
318
|
+
...(unkilled.length > 0
|
|
319
|
+
? [`processes ${unkilled.join(', ')} remain${why} not sent SIGKILL; stop them with kill ${unkilled.join(' ')}`]
|
|
320
|
+
: []),
|
|
321
|
+
...(survivors.length > 0 ? [`processes ${survivors.join(', ')} survived SIGKILL`] : []),
|
|
322
|
+
...(p.unproven.length > 0 ? [unprovenLeft(proc.pid, p.unproven)] : []),
|
|
323
|
+
...strays.unread,
|
|
324
|
+
];
|
|
325
|
+
if (reasons.length > 0)
|
|
326
|
+
return cantTell(reasons);
|
|
327
|
+
const kill = sigkill();
|
|
328
|
+
return kill ? { kind: 'stopped', signal: 'SIGKILL', killed: kill } : { kind: 'stopped', signal: 'SIGTERM' };
|
|
235
329
|
};
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
330
|
+
system.signalGroup(proc.pid, 'SIGTERM');
|
|
331
|
+
for (const stray of strays.proven)
|
|
332
|
+
system.signal(stray.pid, 'SIGTERM');
|
|
333
|
+
const grace = await waitSettled(graceMs);
|
|
334
|
+
if (settled(grace))
|
|
335
|
+
return outcome(grace);
|
|
336
|
+
// 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:
|
|
337
|
+
// one listed with processes in it at every poll since SIGTERM may have emptied and been made anew between two polls
|
|
338
|
+
// or since the last one. That window is bounded by one poll interval, not ruled out.
|
|
339
|
+
if (seen.groupEveryPoll)
|
|
340
|
+
killed.group = system.signalGroup(proc.pid, 'SIGKILL');
|
|
341
|
+
const alive = left(proven);
|
|
342
|
+
killed.unread = alive === undefined;
|
|
343
|
+
for (const pid of alive ?? [])
|
|
344
|
+
if (system.signal(pid, 'SIGKILL'))
|
|
345
|
+
killed.pids.add(pid);
|
|
346
|
+
return outcome(await waitSettled(2000));
|
|
242
347
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
348
|
+
function unprovenLeft(pgid, pids) {
|
|
349
|
+
return `processes ${pids.join(', ')} in a process group of id ${String(pgid)} can't be proven ours; stop them with kill ${pids.join(' ')}`;
|
|
350
|
+
}
|
|
351
|
+
function withStarts(system, pids) {
|
|
352
|
+
const starts = system.running(pids);
|
|
353
|
+
if (!starts)
|
|
354
|
+
return undefined;
|
|
249
355
|
return pids.flatMap(pid => {
|
|
250
|
-
const start = starts
|
|
356
|
+
const start = starts.get(pid);
|
|
251
357
|
return start === undefined ? [] : [{ pid, start }];
|
|
252
358
|
});
|
|
253
359
|
}
|
|
360
|
+
const STARTED_WITH_LEADER_MS = 1000;
|
|
361
|
+
const START_RESOLUTION_MS = 1000;
|
|
362
|
+
/**
|
|
363
|
+
* Whether a process left in the group after its leader exited proves the group is still the one the leader started.
|
|
364
|
+
* POSIX keeps a pid from naming a new process while a process group of that id lives (XBD 4.14 Process ID Reuse;
|
|
365
|
+
* XNU's forkproc skips such pids), so a later group of that id is made after the original group is gone, a full cycle
|
|
366
|
+
* of the pid space later. A process started in the leader's second or the next is older than such a group could be,
|
|
367
|
+
* and so is one started before a moment the leader was seen running, when the original group still held the id.
|
|
368
|
+
*/
|
|
369
|
+
function inOriginalGroup(proc, start) {
|
|
370
|
+
const member = startMs(start);
|
|
371
|
+
const after = member - startMs(proc.start);
|
|
372
|
+
if (Number.isNaN(after) || after < 0)
|
|
373
|
+
return false;
|
|
374
|
+
if (after <= STARTED_WITH_LEADER_MS)
|
|
375
|
+
return true;
|
|
376
|
+
return proc.aliveAt !== undefined && member + START_RESOLUTION_MS <= proc.aliveAt;
|
|
377
|
+
}
|
|
378
|
+
function retryOnce(read) {
|
|
379
|
+
return read() ?? read();
|
|
380
|
+
}
|
|
381
|
+
/** The service's processes that left its process group, found while a process of the group still ties them to it. */
|
|
382
|
+
function outsideGroup(system, pgid, roots) {
|
|
383
|
+
const below = new Map();
|
|
384
|
+
const unlisted = [];
|
|
385
|
+
for (const root of roots) {
|
|
386
|
+
if (below.has(root))
|
|
387
|
+
continue;
|
|
388
|
+
const descendants = retryOnce(() => system.descendants(root));
|
|
389
|
+
if (descendants === undefined)
|
|
390
|
+
unlisted.push(root);
|
|
391
|
+
for (const d of descendants ?? [])
|
|
392
|
+
below.set(d.pid, d.pgid);
|
|
393
|
+
}
|
|
394
|
+
const pids = [...below].filter(([, group]) => group !== pgid).map(([pid]) => pid);
|
|
395
|
+
const proven = pids.length === 0 ? [] : retryOnce(() => withStarts(system, pids));
|
|
396
|
+
return {
|
|
397
|
+
proven: proven ?? [],
|
|
398
|
+
unread: [
|
|
399
|
+
...(unlisted.length > 0
|
|
400
|
+
? [
|
|
401
|
+
`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`,
|
|
402
|
+
]
|
|
403
|
+
: []),
|
|
404
|
+
...(proven === undefined
|
|
405
|
+
? [
|
|
406
|
+
`ps could not read when processes ${pids.join(', ')} started, so they were sent nothing; stop them with kill ${pids.join(' ')}`,
|
|
407
|
+
]
|
|
408
|
+
: []),
|
|
409
|
+
],
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
function describeKilled(pgid, killed) {
|
|
413
|
+
return [
|
|
414
|
+
...(killed.group ? [`process group ${String(pgid)}`] : []),
|
|
415
|
+
...(killed.pids.length > 0 ? [`processes ${killed.pids.join(', ')}`] : []),
|
|
416
|
+
].join(' and ');
|
|
417
|
+
}
|
|
254
418
|
export function describeStop(proc, outcome) {
|
|
255
419
|
const who = `${proc.service} (pid ${String(proc.pid)}, started ${describeStart(proc.start)})`;
|
|
256
420
|
switch (outcome.kind) {
|
|
257
421
|
case 'stopped':
|
|
258
|
-
|
|
422
|
+
if (outcome.signal === 'SIGTERM')
|
|
423
|
+
return `stopped ${who}`;
|
|
424
|
+
return `stopped ${who} with SIGKILL to ${describeKilled(proc.pid, outcome.killed)}, which SIGTERM did not end`;
|
|
259
425
|
case 'already-gone':
|
|
260
426
|
return `${who} had already exited`;
|
|
261
427
|
case 'not-ours':
|
|
262
428
|
return `left ${who} alone: ${outcome.reason}`;
|
|
263
429
|
case 'cant-tell':
|
|
430
|
+
if (outcome.sent === 'SIGKILL') {
|
|
431
|
+
return `sent SIGTERM to ${who}, then SIGKILL to ${describeKilled(proc.pid, outcome.killed)}, but ${outcome.reason}`;
|
|
432
|
+
}
|
|
433
|
+
if (outcome.sent === 'SIGTERM')
|
|
434
|
+
return `sent SIGTERM to ${who}, but ${outcome.reason}`;
|
|
264
435
|
return `left ${who} alone: ${outcome.reason}`;
|
|
265
436
|
case 'survived':
|
|
266
|
-
return `${who} survived SIGKILL: processes ${outcome.members.join(', ')} remain`;
|
|
437
|
+
return `${who} survived SIGKILL: processes ${outcome.members.join(', ')} remain${outcome.unproven ? `; ${unprovenLeft(proc.pid, outcome.unproven)}` : ''}`;
|
|
267
438
|
}
|
|
268
439
|
}
|
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));
|
|
@@ -318,9 +328,10 @@ export async function diagnose(deps, input) {
|
|
|
318
328
|
name: 'hygiene',
|
|
319
329
|
ok: hygiene.ok,
|
|
320
330
|
detail: hygiene.ok
|
|
321
|
-
? hygiene.steps.map(s => `${s.step} ${s.got}`).join('; ')
|
|
331
|
+
? hygiene.steps.map(s => (s.unconfirmed ? `${s.step} unconfirmed: ${s.unconfirmed}` : `${s.step} ${s.got}`)).join('; ')
|
|
322
332
|
: off.map(s => `${s.step} reads ${s.got}, not ${s.wanted}`).join('; '),
|
|
323
333
|
fix: UP,
|
|
334
|
+
...(hygiene.ok && hygiene.steps.some(s => s.unconfirmed) ? { warning: true } : {}),
|
|
324
335
|
});
|
|
325
336
|
}
|
|
326
337
|
catch (error) {
|
|
@@ -410,6 +421,20 @@ async function webAppCheck(tools, config, lane, checks) {
|
|
|
410
421
|
fix: answer === null ? UP : `read the log of ${service} in the lane's log folder`,
|
|
411
422
|
};
|
|
412
423
|
}
|
|
424
|
+
function parkCheck(lane, park) {
|
|
425
|
+
const by = park.by === null ? '' : ` by pid ${String(park.by)}`;
|
|
426
|
+
const problems = park.problems.length > 0 ? `; ${park.problems.join('; ')}` : '';
|
|
427
|
+
const detail = park.state === 'parked'
|
|
428
|
+
? `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}`
|
|
429
|
+
: `lane ${lane.id} is being ${park.state === 'parking' ? 'parked' : 'brought back'}${by} since ${formatTime(park.since)}${problems}`;
|
|
430
|
+
return {
|
|
431
|
+
name: 'parked',
|
|
432
|
+
ok: true,
|
|
433
|
+
warning: true,
|
|
434
|
+
detail,
|
|
435
|
+
fix: `any call on the lane (${CLI} look, ${CLI} exec, ${CLI} restart) brings it back first, and so does ${UP}`,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
413
438
|
function finish(lane, checks) {
|
|
414
439
|
return { ok: checks.every(c => c.ok), lane: lane?.id ?? null, checks };
|
|
415
440
|
}
|
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('; ')})` : ''}`);
|