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
package/dist/registry-cli.js
CHANGED
|
@@ -10,19 +10,24 @@ import { CLI, TOOL } from "./name.js";
|
|
|
10
10
|
import { describeStart } from "./processes.js";
|
|
11
11
|
import { formatAge, formatTime, shellQuote } from "./registry/format.js";
|
|
12
12
|
import { DEVICE_MEMORY_MB } from "./registry/config.js";
|
|
13
|
-
import { describeOwner, describeState, isProven, ownerKey, resolveOwner } from "./registry/owner.js";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
13
|
+
import { describeHostSession, describeOwner, describeState, isProven, ownerKey, resolveOwner } from "./registry/owner.js";
|
|
14
|
+
import { RETURN_WINDOW_MS } from "./registry/owner-checks.js";
|
|
15
|
+
import { databasePath, FORMER_STATE_DIR_ENV, STATE_DIR_ENV, stateDir } from "./registry/paths.js";
|
|
16
|
+
import { deleteLeftovers, deleteOrphan, describeLeftoverResult, describeOrphanResult, describePruneResult, listPrunable, putBackAsideCopies, renderPruneReport, reportPrunable, requireHome, } from "./registry/prune.js";
|
|
16
17
|
import { NotClaimed, Refusal, UsageError } from "./registry/refusal.js";
|
|
17
18
|
import { readRegistryStatus, Registry } from "./registry/registry.js";
|
|
19
|
+
import { DEFAULT_HOLD_MS, parseHoldTime } from "./registry/holds.js";
|
|
20
|
+
import { recordCall } from "./registry/touch.js";
|
|
21
|
+
import { describeRestarts } from "./registry/parks.js";
|
|
18
22
|
import { realServiceSystem } from "./services/system.js";
|
|
19
|
-
import { pruneEndedLaneFiles } from "./up/lane-files.js";
|
|
20
|
-
import {
|
|
23
|
+
import { LANE_FILES_KEEP_MS, pruneEndedLaneFiles } from "./up/lane-files.js";
|
|
24
|
+
import { tearDownLane } from "./up/release.js";
|
|
21
25
|
import { tearDownEndedResources } from "./up/resources.js";
|
|
26
|
+
import { runSweep, SWEEP_INTERVAL_MS } from "./up/sweep.js";
|
|
22
27
|
import { systemClock } from "./clock.js";
|
|
23
28
|
import { claudeSessionName } from "./plugin/session-name.js";
|
|
24
29
|
import { groupUsage, helpOf } from "./usage.js";
|
|
25
|
-
export const REGISTRY_COMMANDS = ['claim', 'release', 'status', 'lanes', 'touch', 'prune'];
|
|
30
|
+
export const REGISTRY_COMMANDS = ['claim', 'release', 'keep', 'status', 'lanes', 'touch', 'reap', 'prune'];
|
|
26
31
|
export const REGISTRY_HELP = {
|
|
27
32
|
title: 'Lanes:',
|
|
28
33
|
entries: {
|
|
@@ -52,16 +57,45 @@ export const REGISTRY_HELP = {
|
|
|
52
57
|
--force with an id: release it even if its owner is alive or can't be judged;
|
|
53
58
|
for an ended lane, drop the record of a teardown that fails again
|
|
54
59
|
`,
|
|
55
|
-
|
|
60
|
+
keep: ` keep Hold this session's lane for this folder up while a person looks at the running
|
|
61
|
+
app, so it is not parked until the hold ends, however long since its last call:
|
|
62
|
+
${TOOL} keep --for 2h --reason "the user is reviewing the checkout screen".
|
|
63
|
+
Running keep again replaces the hold. The hold ends with the lane, at release or when
|
|
64
|
+
the session ends, and status shows it with its reason and its end.
|
|
65
|
+
--for <time> how long: minutes or hours, such as 45m, 2h or 1h30m (default 1h,
|
|
66
|
+
at most 24h)
|
|
67
|
+
--reason <text> who is looking at what; status shows it (required)
|
|
68
|
+
--worktree <dir> the folder whose lane to hold (default: this git worktree)
|
|
69
|
+
`,
|
|
70
|
+
status: ` status Every lane on this Mac: owner, folder, start, idle time, last action, and whether
|
|
71
|
+
it is held or parked.
|
|
56
72
|
`,
|
|
57
73
|
lanes: ` lanes --json: the same as status, as JSON for tools.
|
|
58
74
|
`,
|
|
59
75
|
touch: ` touch Record activity on this session's lane (--action <text>).
|
|
60
76
|
`,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
77
|
+
reap: ` reap Run the sweep now, for every lane on this Mac, and print what it did. Every ${TOOL}
|
|
78
|
+
command runs it in the background as it starts, and each running MCP server every
|
|
79
|
+
${formatAge(SWEEP_INTERVAL_MS)}; reap is for running it on a schedule of your own, such as cron or
|
|
80
|
+
launchd. It asks the process table about the owners no call or check has shown alive
|
|
81
|
+
lately. A lane whose owner is gone is parked at once: its servers stop and its device goes
|
|
82
|
+
back to the pool. ${formatAge(RETURN_WINDOW_MS)} later it ends with everything release does, unless
|
|
83
|
+
the owner's Claude Code session or Codex thread calls on it from its folder first and takes
|
|
84
|
+
it back with its ports and resources. It also parks the lanes unused for the park window.
|
|
85
|
+
--json print what it did as JSON
|
|
86
|
+
`,
|
|
87
|
+
prune: ` prune List what takes disk and nothing uses, each with its size; --yes deletes it:
|
|
88
|
+
the pool simulators and emulators no lane holds, 0.2.x's included; devices named
|
|
89
|
+
like pool devices that no registry prune reads records and that are shut down;
|
|
90
|
+
and, while no registry 0.2.x may use has a lane, the downloads 0.2.x left in
|
|
91
|
+
~/.local/share/agent-env and its build cache in .git/agent-env of this repository
|
|
92
|
+
and of every folder a registry names. prune reads the registries in
|
|
93
|
+
${STATE_DIR_ENV} and ${FORMER_STATE_DIR_ENV} when they are set, and in the
|
|
94
|
+
${TOOL} and agent-env folders of $XDG_STATE_HOME and ~/.local/state. It
|
|
95
|
+
can't see a lane whose registry is in any other folder, so run prune with
|
|
96
|
+
the same variables that lane's ${TOOL} runs with. Each deletion locks those
|
|
97
|
+
registries and checks again, so a device a lane of either version claimed
|
|
98
|
+
meanwhile is kept.
|
|
65
99
|
--yes delete them; without it, prune only lists
|
|
66
100
|
--json print the listing, and with --yes each result, as JSON
|
|
67
101
|
`,
|
|
@@ -142,10 +176,6 @@ function renderOutcome(outcome, now, deps, json) {
|
|
|
142
176
|
deps.stdout(`${JSON.stringify({ ...outcome, env: laneEnv(lane) }, null, 2)}\n`);
|
|
143
177
|
return;
|
|
144
178
|
}
|
|
145
|
-
for (const e of outcome.freed)
|
|
146
|
-
deps.stderr(`${TOOL}: ${describeEnded(e, now)}\n`);
|
|
147
|
-
for (const e of outcome.tookOver)
|
|
148
|
-
deps.stderr(`${TOOL}: ${describeEnded(e, now)}\n`);
|
|
149
179
|
for (const note of outcome.notes)
|
|
150
180
|
deps.stderr(`${TOOL}: ${note}\n`);
|
|
151
181
|
const verb = outcome.created ? 'claimed lane' : 'reusing lane';
|
|
@@ -153,13 +183,50 @@ function renderOutcome(outcome, now, deps, json) {
|
|
|
153
183
|
for (const [key, value] of Object.entries(laneEnv(lane)))
|
|
154
184
|
deps.stdout(`export ${key}=${shellQuote(value)}\n`);
|
|
155
185
|
}
|
|
156
|
-
function
|
|
186
|
+
function renderKept(kept, deps) {
|
|
187
|
+
const { lane, hold, replaced, park } = kept;
|
|
188
|
+
deps.stderr(`${TOOL}: holding lane ${lane.id} until ${formatTime(hold.until)} (${formatAge(hold.until - hold.since)}): ${hold.reason}\n`);
|
|
189
|
+
if (replaced)
|
|
190
|
+
deps.stderr(`${TOOL}: this replaces its hold until ${formatTime(replaced.until)}: ${replaced.reason}\n`);
|
|
191
|
+
if (park?.state === 'parked') {
|
|
192
|
+
deps.stderr(`${TOOL}: lane ${lane.id} is parked; its next call brings back ${describeRestarts(park.restarts)}, and the hold keeps it up from then\n`);
|
|
193
|
+
}
|
|
194
|
+
else if (park?.state === 'parking') {
|
|
195
|
+
deps.stderr(`${TOOL}: lane ${lane.id} is being parked by pid ${String(park.holder?.pid ?? 'unknown')}; if it parks, its next call brings it back, and the hold keeps it up from then\n`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function parkLines(park, now) {
|
|
199
|
+
const at = park.parkedAt ?? park.since;
|
|
200
|
+
const head = park.state === 'parked'
|
|
201
|
+
? ` parked since ${formatTime(at)} (${formatAge(now - at)} ago); its next call brings back ${describeRestarts(park.restarts)}`
|
|
202
|
+
: ` ${park.state.padEnd(13)}since ${formatTime(park.since)}, by pid ${String(park.by ?? 'unknown')}`;
|
|
203
|
+
return [head, ...park.problems.map(p => ` problem ${p}`)];
|
|
204
|
+
}
|
|
205
|
+
function goneLine(gone, c, now) {
|
|
206
|
+
const found = ` owner gone ${describeState(gone.state)}, found ${formatTime(gone.foundAt)} (${formatAge(now - gone.foundAt)} ago)`;
|
|
207
|
+
if (gone.by !== null)
|
|
208
|
+
return `${found}; pid ${String(gone.by)} is ending the lane`;
|
|
209
|
+
if (now >= gone.endsAt)
|
|
210
|
+
return `${found}; the next sweep ends the lane`;
|
|
211
|
+
const session = describeHostSession(c.owner);
|
|
212
|
+
const ends = `the lane ends ${formatTime(gone.endsAt)} (in ${formatAge(gone.endsAt - now)})`;
|
|
213
|
+
return session
|
|
214
|
+
? `${found}; ${ends} unless ${session} calls on it from its folder`
|
|
215
|
+
: `${found}; ${ends}, and nothing can take it back`;
|
|
216
|
+
}
|
|
217
|
+
function holdLine(hold, now) {
|
|
218
|
+
return ` held until ${formatTime(hold.until)} (${formatAge(hold.until - now)} left): ${hold.reason}`;
|
|
219
|
+
}
|
|
220
|
+
function laneLines(c, sessionName, now) {
|
|
157
221
|
const state = c.ownerState === 'alive' ? 'alive' : describeState(c.ownerState).toUpperCase();
|
|
158
222
|
const name = sessionName(c);
|
|
159
223
|
const lines = [
|
|
160
224
|
` ${c.id} ${describeOwner(c.owner)}${name ? ` "${name}"` : ''} [${state}]`,
|
|
161
225
|
` folder ${c.worktree}${c.projectRoot !== c.worktree ? ` (project ${c.projectRoot})` : ''}`,
|
|
162
226
|
` started ${formatTime(c.createdAt)} idle ${formatAge(c.idleMs)} last action: ${c.lastAction}`,
|
|
227
|
+
...(c.ownerGone ? [goneLine(c.ownerGone, c, now)] : []),
|
|
228
|
+
...(c.hold ? [holdLine(c.hold, now)] : []),
|
|
229
|
+
...(c.park ? parkLines(c.park, now) : []),
|
|
163
230
|
];
|
|
164
231
|
if (c.device) {
|
|
165
232
|
lines.push(` device ${c.device.name} (${c.device.deviceTypeName}, ${c.device.runtimeName}) ${c.device.serial ?? c.device.id} ${c.deviceState ?? ''}`);
|
|
@@ -176,7 +243,7 @@ function laneLines(c, sessionName) {
|
|
|
176
243
|
lines.push(` resources ${shown.join(', ')}`);
|
|
177
244
|
}
|
|
178
245
|
for (const p of c.processes)
|
|
179
|
-
lines.push(` process ${p.service} pid ${String(p.pid)} (started ${describeStart(p.start)})`);
|
|
246
|
+
lines.push(` process ${p.service} pid ${String(p.pid)} (started ${describeStart(p.start)}) ${p.state === 'unknown' ? "can't tell" : p.state}`);
|
|
180
247
|
if (c.ownerState === 'cant-tell')
|
|
181
248
|
lines.push(` left alone: its owner can't be judged; ${CLI} release --lane ${c.id} --force frees it`);
|
|
182
249
|
return lines;
|
|
@@ -192,7 +259,7 @@ export function renderStatus(report, sessionName = () => null) {
|
|
|
192
259
|
const { config } = report;
|
|
193
260
|
const lines = [
|
|
194
261
|
`${TOOL} registry: ${report.stateDir}`,
|
|
195
|
-
`pool: ${poolLine(report)};
|
|
262
|
+
`pool: ${poolLine(report)}; a lane is parked ${formatAge(config.parkMs)} after its last call, giving its device back, unless a hold keeps it up; a lane whose owner is gone is parked at once and ends ${formatAge(RETURN_WINDOW_MS)} later`,
|
|
196
263
|
`ports: ${Object.entries(config.blocks)
|
|
197
264
|
.map(([type, b]) => `${type} ${String(b.first)}-${String(b.last)}`)
|
|
198
265
|
.join(', ')}`,
|
|
@@ -203,7 +270,7 @@ export function renderStatus(report, sessionName = () => null) {
|
|
|
203
270
|
else {
|
|
204
271
|
lines.push(`lanes (${String(report.lanes.length)}):`);
|
|
205
272
|
for (const c of report.lanes)
|
|
206
|
-
lines.push(...laneLines(c, sessionName));
|
|
273
|
+
lines.push(...laneLines(c, sessionName, report.now));
|
|
207
274
|
}
|
|
208
275
|
if (report.queue.length > 0) {
|
|
209
276
|
lines.push('', 'queue:');
|
|
@@ -268,6 +335,7 @@ function open(deps) {
|
|
|
268
335
|
devices: deps.devices,
|
|
269
336
|
...(deps.clock ? { clock: deps.clock } : {}),
|
|
270
337
|
...(deps.pollMs !== undefined ? { pollMs: deps.pollMs } : {}),
|
|
338
|
+
...(deps.passBy ? { sweepSoon: deps.passBy } : {}),
|
|
271
339
|
});
|
|
272
340
|
}
|
|
273
341
|
function teardownDeps(deps) {
|
|
@@ -335,7 +403,20 @@ async function pendingRelease(deps, registry, target, json) {
|
|
|
335
403
|
}
|
|
336
404
|
return teardowns.some(t => t.problems.length > 0 && !target.force) ? 1 : 0;
|
|
337
405
|
}
|
|
406
|
+
function takeBackIn(deps, who, worktree) {
|
|
407
|
+
if (!fs.existsSync(databasePath(stateDir(deps.env))))
|
|
408
|
+
return;
|
|
409
|
+
const registry = open(deps);
|
|
410
|
+
try {
|
|
411
|
+
registry.takeBack(who, worktree);
|
|
412
|
+
}
|
|
413
|
+
finally {
|
|
414
|
+
registry.close();
|
|
415
|
+
}
|
|
416
|
+
}
|
|
338
417
|
async function releaseLanes(deps, who, target, json) {
|
|
418
|
+
if (target.folder !== null)
|
|
419
|
+
takeBackIn(deps, who, target.folder);
|
|
339
420
|
const teardowns = await tearDownTargets(deps, who, target);
|
|
340
421
|
const registry = open(deps);
|
|
341
422
|
const notes = [];
|
|
@@ -383,34 +464,83 @@ function releaseId(positionals, flag) {
|
|
|
383
464
|
throw new UsageError(`release ${bare} and --lane ${flag} name two lanes`, `pass one: ${CLI} release <id>`);
|
|
384
465
|
return bare ?? flag ?? null;
|
|
385
466
|
}
|
|
467
|
+
const PRUNE_LOCK_WAIT_MS = 30_000;
|
|
386
468
|
function prune(deps, yes, json) {
|
|
469
|
+
requireHome(deps.env);
|
|
387
470
|
const dir = stateDir(deps.env);
|
|
471
|
+
const ctx = { env: deps.env, cwd: deps.cwd, lockWaitMs: PRUNE_LOCK_WAIT_MS };
|
|
388
472
|
const registry = fs.existsSync(databasePath(dir)) ? open(deps) : null;
|
|
389
473
|
try {
|
|
390
|
-
const
|
|
474
|
+
const report = reportPrunable(registry ? registry.prunable() : listPrunable(null, dir, deps.devices), ctx);
|
|
391
475
|
if (!json)
|
|
392
|
-
deps.stdout(
|
|
476
|
+
deps.stdout(renderPruneReport(report, yes));
|
|
477
|
+
const tell = (outcome, line) => {
|
|
478
|
+
if (json)
|
|
479
|
+
return;
|
|
480
|
+
if (outcome === 'failed')
|
|
481
|
+
deps.stderr(`${TOOL}: ${line}\n`);
|
|
482
|
+
else
|
|
483
|
+
deps.stdout(`${line}\n`);
|
|
484
|
+
};
|
|
393
485
|
const results = [];
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
486
|
+
const orphanResults = [];
|
|
487
|
+
let leftoverResults = [];
|
|
488
|
+
if (yes) {
|
|
489
|
+
if (registry) {
|
|
490
|
+
for (const device of report.free) {
|
|
491
|
+
const result = registry.pruneDevice(device);
|
|
492
|
+
results.push(result);
|
|
493
|
+
tell(result.outcome, describePruneResult(result));
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
for (const device of report.orphans) {
|
|
497
|
+
const result = deleteOrphan(ctx, deps.devices[device.platform], device);
|
|
498
|
+
orphanResults.push(result);
|
|
499
|
+
tell(result.outcome, describeOrphanResult(result));
|
|
404
500
|
}
|
|
501
|
+
leftoverResults =
|
|
502
|
+
report.leftoversKept === null ? deleteLeftovers(ctx, report.leftovers) : putBackAsideCopies(ctx, report.leftovers);
|
|
503
|
+
for (const result of leftoverResults)
|
|
504
|
+
tell(result.outcome, describeLeftoverResult(result));
|
|
405
505
|
}
|
|
406
|
-
if (json)
|
|
407
|
-
|
|
408
|
-
|
|
506
|
+
if (json) {
|
|
507
|
+
const done = yes ? { results, orphanResults, leftoverResults } : {};
|
|
508
|
+
deps.stdout(`${JSON.stringify({ ...report, ...done }, null, 2)}\n`);
|
|
509
|
+
}
|
|
510
|
+
return [...results, ...orphanResults, ...leftoverResults].some(r => r.outcome === 'failed') ? 1 : 0;
|
|
409
511
|
}
|
|
410
512
|
finally {
|
|
411
513
|
registry?.close();
|
|
412
514
|
}
|
|
413
515
|
}
|
|
516
|
+
async function reap(deps, json) {
|
|
517
|
+
const said = [];
|
|
518
|
+
const report = await runSweep({
|
|
519
|
+
dir: stateDir(deps.env),
|
|
520
|
+
env: deps.env,
|
|
521
|
+
processes: deps.processes,
|
|
522
|
+
system: deps.system ?? realServiceSystem,
|
|
523
|
+
clock: deps.clock ?? systemClock,
|
|
524
|
+
devices: deps.devices,
|
|
525
|
+
ports: deps.ports,
|
|
526
|
+
browser: deps.browser ?? realBrowserTools,
|
|
527
|
+
sim: deps.sim ?? null,
|
|
528
|
+
...(deps.adb ? { adb: deps.adb } : {}),
|
|
529
|
+
...(deps.evidence ? { evidence: deps.evidence } : {}),
|
|
530
|
+
log: line => said.push(line),
|
|
531
|
+
});
|
|
532
|
+
if (json)
|
|
533
|
+
deps.stdout(`${JSON.stringify(report, null, 2)}\n`);
|
|
534
|
+
else {
|
|
535
|
+
for (const line of said)
|
|
536
|
+
deps.stderr(`${TOOL}: ${line}\n`);
|
|
537
|
+
if (said.length === 0) {
|
|
538
|
+
const asked = report.checked.length === 0 ? 'no owner was due a check' : `the owners of ${report.checked.join(', ')} are not gone`;
|
|
539
|
+
deps.stderr(`${TOOL}: nothing to park or end: ${asked}\n`);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
return report.problems.length > 0 ? 1 : 0;
|
|
543
|
+
}
|
|
414
544
|
function now(deps) {
|
|
415
545
|
return deps.clock ? deps.clock.now() : Date.now();
|
|
416
546
|
}
|
|
@@ -461,14 +591,13 @@ async function dispatch(command, args, deps) {
|
|
|
461
591
|
renderOutcome(outcome, now(deps), deps, values.json);
|
|
462
592
|
const state = stateDir(deps.env);
|
|
463
593
|
const stopped = [
|
|
464
|
-
...(await stopEndedLanes(teardownDeps(deps), state, [...outcome.freed, ...outcome.tookOver])),
|
|
465
594
|
...(await stopEndedBrowsers(teardownDeps(deps).browser, registry, state, teardownDeps(deps).clock)),
|
|
466
595
|
...(await tearDownEndedResources(teardownDeps(deps), registry, state)),
|
|
467
596
|
];
|
|
468
597
|
for (const t of stopped)
|
|
469
598
|
for (const line of [...t.notes, ...t.problems])
|
|
470
599
|
deps.stderr(`${TOOL}: lane ${t.lane}: ${line}\n`);
|
|
471
|
-
pruneEndedLaneFiles(state,
|
|
600
|
+
pruneEndedLaneFiles(state, registry.keptLaneIds(now(deps) - LANE_FILES_KEEP_MS), now(deps), deps.env);
|
|
472
601
|
return 0;
|
|
473
602
|
}
|
|
474
603
|
finally {
|
|
@@ -513,6 +642,34 @@ async function dispatch(command, args, deps) {
|
|
|
513
642
|
: renderStatus(report, names));
|
|
514
643
|
return 0;
|
|
515
644
|
}
|
|
645
|
+
case 'keep': {
|
|
646
|
+
const { values } = parseArgs({
|
|
647
|
+
args,
|
|
648
|
+
strict: true,
|
|
649
|
+
options: { for: { type: 'string' }, reason: { type: 'string' }, worktree: { type: 'string' } },
|
|
650
|
+
});
|
|
651
|
+
const forMs = values.for === undefined ? DEFAULT_HOLD_MS : parseHoldTime(values.for);
|
|
652
|
+
const reason = values.reason?.trim() ?? '';
|
|
653
|
+
if (reason === '') {
|
|
654
|
+
throw new UsageError('keep needs --reason', `say who is looking at what: ${CLI} keep --reason "the user is reviewing the checkout screen"`);
|
|
655
|
+
}
|
|
656
|
+
const who = owner();
|
|
657
|
+
const worktree = resolveFolder(values.worktree ?? deps.cwd).worktree;
|
|
658
|
+
const registry = open(deps);
|
|
659
|
+
try {
|
|
660
|
+
const lane = registry.takeBack(who, worktree);
|
|
661
|
+
if (!lane) {
|
|
662
|
+
throw new NotClaimed(`${describeOwner(who)} holds no lane in ${worktree}`, `${CLI} up (run in ${worktree}; keep holds a lane that is up)`);
|
|
663
|
+
}
|
|
664
|
+
const ref = { id: lane.id, token: lane.token };
|
|
665
|
+
recordCall(stateDir(deps.env), ref, now(deps));
|
|
666
|
+
renderKept(registry.keep(ref, reason, forMs), deps);
|
|
667
|
+
return 0;
|
|
668
|
+
}
|
|
669
|
+
finally {
|
|
670
|
+
registry.close();
|
|
671
|
+
}
|
|
672
|
+
}
|
|
516
673
|
case 'touch': {
|
|
517
674
|
const { values } = parseArgs({
|
|
518
675
|
args,
|
|
@@ -530,6 +687,10 @@ async function dispatch(command, args, deps) {
|
|
|
530
687
|
registry.close();
|
|
531
688
|
}
|
|
532
689
|
}
|
|
690
|
+
case 'reap': {
|
|
691
|
+
const { values } = parseArgs({ args, strict: true, options: { json: { type: 'boolean', default: false } } });
|
|
692
|
+
return reap(deps, values.json);
|
|
693
|
+
}
|
|
533
694
|
case 'prune': {
|
|
534
695
|
const { values } = parseArgs({
|
|
535
696
|
args,
|