show-me-the-env 0.93.1 → 0.93.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "show-me-the-env",
3
- "version": "0.93.1",
3
+ "version": "0.93.3",
4
4
  "description": "Save and restore your whole agent and coding environment as one versioned .agenv repository.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -409,7 +409,7 @@ if ($Mode -eq 'Live') {
409
409
  $default = (& wsl.exe --list --quiet 2>$null | ForEach-Object { ($_ -replace "`0", '').Trim() } | Where-Object { $_ -and $_ -notmatch '^docker-desktop' } | Select-Object -First 1)
410
410
  $route = if ($default) { & wsl.exe -d $default --exec /bin/sh -c 'ip route show default' 2>$null } else { '' }
411
411
  Write-Info "distribution=$default route=$route"
412
- Test-Check ([bool]$route) 'the WSL guest has a default route under mirrored networking; when it has only loopback, read docs/CONTRACT.md#windows-hosted-provider-from-wsl for the 4095-port reservation'
412
+ Test-Check ([bool]$route) 'the WSL guest has a default route under mirrored networking; when it has only loopback, read docs/RUNTIME-PREFLIGHT.md#windows-hosted-provider-from-wsl for the 4095-port reservation'
413
413
  }
414
414
 
415
415
  Write-Step 'Live tooling'
@@ -47,6 +47,30 @@ export function runnerLimits(runner, row, defaults) {
47
47
  return limits;
48
48
  }
49
49
 
50
+ // The leader is the person's own machine, the one that runs this queue: no unit starts there. On 2026-12-04 the founder's laptop froze in a
51
+ // game while about 80 agent node and chrome processes ran on it at 60-100% CPU (leader 04:4x). A machine is the leader when its register
52
+ // row's role, or its runner entry's role in the settings, says leader.
53
+ export const LEADER_ROLE = /\bleader\b/i;
54
+ // An ssh host that is this machine itself.
55
+ const LOCAL_HOSTS = new Set(['local', 'localhost', '127.0.0.1']);
56
+ const same = (a, b) => String(a ?? '').toLowerCase() === String(b ?? '').toLowerCase();
57
+ // A machine name as a word of a note: not a part of a longer name.
58
+ const namesWord = (text, name) => new RegExp('(?<![\\w-])' + String(name).replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '(?![\\w-])', 'i').test(String(text ?? ''));
59
+
60
+ // Why a runner is the leader, or null: its register row's role or its settings role says leader, its machine or its ssh host is a leader
61
+ // the register names (a row's host is what agenv machine register --host was given), or it is this machine (its ssh host is localhost,
62
+ // or its machine is this machine's name) while this machine is the leader.
63
+ export function leaderOf(runner, row, { leaders = [], hostname = os.hostname() } = {}) {
64
+ const machine = runner.machine ?? runner.id;
65
+ if (LEADER_ROLE.test(String(row?.role ?? ''))) return 'its register row ' + (row.id ?? machine) + ' has role ' + JSON.stringify(row.role);
66
+ if (LEADER_ROLE.test(String(runner.role ?? ''))) return 'its settings role is ' + JSON.stringify(runner.role);
67
+ if (leaders.some((n) => same(n, machine))) return 'its machine ' + machine + ' is the leader in the register';
68
+ if (leaders.some((n) => same(n, runner.host))) return 'its ssh host ' + runner.host + ' is the leader in the register';
69
+ const local = LOCAL_HOSTS.has(String(runner.host).toLowerCase()) || same(machine, hostname);
70
+ if (local && leaders.some((n) => same(n, hostname))) return 'it is this machine (' + hostname + '), the leader in the register';
71
+ return null;
72
+ }
73
+
50
74
  function registerRows(file) {
51
75
  if (!file) return [];
52
76
  try { return JSON.parse(fs.readFileSync(file, 'utf8')).machines ?? []; } catch (e) { throw new Error('The register of machines ' + file + ' could not be read (' + (e.code ?? e.message) + ').'); }
@@ -54,7 +78,7 @@ function registerRows(file) {
54
78
 
55
79
  // The fleet settings, from the person's own file: their runners, the folders on this machine and on the runners, the model routes and
56
80
  // what every launched prompt carries. Everything a household or company would recognise lives there, never in this code.
57
- export function readFleet(file, { queueFile, home = os.homedir() } = {}) {
81
+ export function readFleet(file, { queueFile, home = os.homedir(), hostname = os.hostname() } = {}) {
58
82
  let raw;
59
83
  try { raw = JSON.parse(fs.readFileSync(file, 'utf8')); } catch (e) { throw new Error('The fleet settings ' + file + ' could not be read (' + (e.code ?? e.message) + '). Its shape is in docs/MACHINES.md.'); }
60
84
  const need = (ok, what) => { if (!ok) throw new Error('The fleet settings ' + file + ' need ' + what + '. Its shape is in docs/MACHINES.md.'); };
@@ -76,8 +100,17 @@ export function readFleet(file, { queueFile, home = os.homedir() } = {}) {
76
100
  const register = raw.register ? raw.register.replace(/^~(?=[\\/]|$)/, home) : null;
77
101
  const rows = registerRows(register);
78
102
  const rowOf = (machine) => rows.find((row) => String(row.host ?? '').toLowerCase() === String(machine).toLowerCase());
103
+ // The leader's machine names: each register row whose role says leader (a row registered with --host local is this machine), and each
104
+ // runner whose settings role does. The word leader itself is no machine name, since a start note says "not on the leader" of any unit.
105
+ const leaders = [...new Set([...rows.filter((row) => LEADER_ROLE.test(String(row.role ?? ''))).map((row) => (LOCAL_HOSTS.has(String(row.host ?? '').toLowerCase()) ? hostname : row.host)), ...raw.runners.filter((r) => LEADER_ROLE.test(String(r.role ?? ''))).map((r) => r.machine ?? r.id)].filter((n) => n && !LEADER_ROLE.test(String(n))).map(String))];
106
+ const runners = raw.runners.map((r) => {
107
+ const leader = leaderOf(r, rowOf(r.machine ?? r.id), { leaders, hostname });
108
+ // A leader runner has no session slot, so no pass and no --runner auto picks it.
109
+ return { id: r.id, host: r.host, machine: r.machine ?? r.id, gpu: r.gpu === true, ...runnerLimits(r, rowOf(r.machine ?? r.id), defaults), ...(leader ? { cap: 0, leader } : { leader: null }) };
110
+ });
79
111
  return {
80
- runners: raw.runners.map((r) => ({ id: r.id, host: r.host, machine: r.machine ?? r.id, gpu: r.gpu === true, ...runnerLimits(r, rowOf(r.machine ?? r.id), defaults) })),
112
+ runners,
113
+ leaders,
81
114
  root,
82
115
  ...defaults,
83
116
  register,
@@ -131,9 +164,23 @@ export function overlaps(a, b) {
131
164
  return ta.some((x) => !x.startsWith('out/') && tb.some((y) => !y.startsWith('out/') && (x.startsWith(y) || y.startsWith(x))));
132
165
  }
133
166
 
134
- // A unit the queue keeps for the person's own machine (its class is leader, or it starts in the leader lane) never goes to a runner.
167
+ // A unit the queue keeps for the person's own machine (its class is leader, or it starts in the leader lane) never goes to a runner, and
168
+ // the queue never starts it on the leader either: it stays unlaunched for the person.
135
169
  export const forRunners = (u) => u.machineClass !== 'leader' && !/leader lane/.test(u.startNow ?? '');
136
170
 
171
+ // Why a unit's placement resolves to the leader, or null: --place names a leader runner, or its class or start note names a leader's
172
+ // machine or a leader runner. Such a unit is refused, never moved to another runner, since whoever wrote the name meant that machine.
173
+ export function leaderPlacement(u, runners, place = {}, leaders = []) {
174
+ const placed = runners.find((r) => r.id === place[u.id]);
175
+ if (placed?.leader) return '--place names ' + placed.id + ', the leader (' + placed.leader + ')';
176
+ const names = [...new Set([...leaders, ...runners.filter((r) => r.leader).flatMap((r) => [r.id, r.machine])])].filter((n) => n && !LEADER_ROLE.test(String(n)));
177
+ for (const [field, what] of [['machineClass', 'its machineClass'], ['startNow', 'its start note']]) {
178
+ const hit = names.find((n) => namesWord(u[field], n));
179
+ if (hit) return what + ' names ' + hit + ', the leader';
180
+ }
181
+ return null;
182
+ }
183
+
137
184
  // The status line session.mjs gives when ssh never reached the runner (exit 255): the session's state is unknown, never "no session".
138
185
  export const UNREACHABLE = '(runner unreachable';
139
186
 
@@ -179,10 +226,11 @@ export function namedSkills(text, roster) {
179
226
  // runner; the runner its start note names while that one has a free slot; else every runner, most free slots first. A runner that avoids
180
227
  // visual work (a person plays or draws on it) takes no visual and no GPU unit, unless --place names it.
181
228
  export function candidatesFor(u, runners, free, place = {}) {
182
- if (place[u.id]) return [place[u.id]];
229
+ if (place[u.id]) return runners.find((r) => r.id === place[u.id])?.leader ? [] : [place[u.id]];
183
230
  const cls = u.machineClass ?? '';
184
231
  const gpuUnit = /GPU/.test(cls) || runners.some((r) => r.gpu && cls.includes(r.id));
185
- const open = runners.filter((r) => !(r.avoidVisual && (gpuUnit || isVisual(u))));
232
+ // The leader is never a candidate (leaderOf).
233
+ const open = runners.filter((r) => !r.leader && !(r.avoidVisual && (gpuUnit || isVisual(u))));
186
234
  if (gpuUnit) return open.filter((r) => r.gpu).map((r) => r.id);
187
235
  const named = open.find((r) => (u.startNow ?? '').includes(r.machine));
188
236
  if (named && free[named.id] > 0) return [named.id];
@@ -199,16 +247,25 @@ export function candidatesFor(u, runners, free, place = {}) {
199
247
  // preflightOf, when the settings name a dispatch check, runs for a unit that has a runner, before it takes the slot: a unit it holds
200
248
  // keeps the slot free for the next unit, and its reason is logged once. A batch whose files name no path gives the check no surface to
201
249
  // compare, so it is passed over with a log line and the batch rule of overlaps decides what runs beside it (leader, 2026-12-02).
202
- export async function chooseUnits({ units, state, runners, loads, cap, minFreeGB, capOverride = null, only = null, place = {}, running = [], hasCheckout, commitOf, wantsOf, preflightOf = null }) {
250
+ export async function chooseUnits({ units, state, runners, loads, cap, minFreeGB, capOverride = null, only = null, place = {}, running = [], hasCheckout, commitOf, wantsOf, preflightOf = null, leaders = [] }) {
203
251
  const byId = Object.fromEntries(units.map((u) => [u.id, u]));
204
- const free = Object.fromEntries(runners.map((r) => [r.id, loads[r.id] && loads[r.id].freeGB >= (r.minFreeGB ?? minFreeGB) ? Math.max(0, (capOverride ?? r.cap ?? cap) - loads[r.id].running) : 0]));
252
+ // A leader runner has no free slot, whatever --cap says.
253
+ const free = Object.fromEntries(runners.map((r) => [r.id, !r.leader && loads[r.id] && loads[r.id].freeGB >= (r.minFreeGB ?? minFreeGB) ? Math.max(0, (capOverride ?? r.cap ?? cap) - loads[r.id].running) : 0]));
205
254
  const picks = [], notes = [];
206
- const skillHeld = { ...(state.skillHeld ?? {}) }, preflightHeld = { ...(state.preflightHeld ?? {}) }, noCheckout = [...(state.noCheckout ?? [])];
255
+ const skillHeld = { ...(state.skillHeld ?? {}) }, preflightHeld = { ...(state.preflightHeld ?? {}) }, noCheckout = [...(state.noCheckout ?? [])], leaderRefused = { ...(state.leaderRefused ?? {}) };
207
256
  const entryOf = ledgerKey;
208
257
  for (const u of units) {
209
258
  if (only && !only.includes(u.id)) continue;
210
259
  if (state.launched[u.id] || (state.skip ?? []).includes(u.id) || (state.hold ?? []).includes(u.id)) continue;
211
260
  if (!forRunners(u)) continue;
261
+ // A unit whose placement resolves to the leader is refused with one log line, and stays waiting until its placement changes.
262
+ const toLeader = leaderPlacement(u, runners, place, leaders);
263
+ if (toLeader) {
264
+ if (leaderRefused[u.id] !== toLeader) notes.push('launch REFUSED ' + u.id + ': ' + toLeader + '; the queue starts no unit on the leader');
265
+ leaderRefused[u.id] = toLeader;
266
+ continue;
267
+ }
268
+ delete leaderRefused[u.id];
212
269
  const [repo, ref] = String(u.base).split('@');
213
270
  if (!hasCheckout(repo)) {
214
271
  if (!noCheckout.includes(u.id)) { notes.push('skip ' + u.id + ': repository ' + repo + ' has no checkout in the workspace'); noCheckout.push(u.id); }
@@ -248,7 +305,7 @@ export async function chooseUnits({ units, state, runners, loads, cap, minFreeGB
248
305
  picks.push({ unit: u, runner, repo, sha, block });
249
306
  free[runner] -= 1;
250
307
  }
251
- return { picks, free, skillHeld, preflightHeld, noCheckout, notes };
308
+ return { picks, free, skillHeld, preflightHeld, noCheckout, leaderRefused, notes };
252
309
  }
253
310
 
254
311
  // The person's dispatch check (preflight.command in the settings), run for one unit about to start. Exit 0 lets it start, and the block
@@ -440,7 +497,7 @@ export async function fillPass({ fleet, queueFile, options = {}, shadow = false,
440
497
  save();
441
498
  }
442
499
  const names = Object.fromEntries(q.units.map((u) => [u.id, runNameOf(u, st)]));
443
- say('pass: running ' + (running.join(',') || 'none') + ' | ' + fleet.runners.map((r) => { const l = loads[r.id]; return r.id + ' ' + (l ? l.running + '/' + (capOverride ?? r.cap) + ' sessions (' + (l.names.join(',') || '-') + '), ' + l.freeGB + ' GB free' : 'unread'); }).join(' | '));
500
+ say('pass: running ' + (running.join(',') || 'none') + ' | ' + fleet.runners.map((r) => { const l = loads[r.id]; return r.id + ' ' + (r.leader ? 'leader, takes no unit (' + r.leader + ')' + (l ? ', ' + l.running + ' sessions (' + (l.names.join(',') || '-') + ')' : '') : l ? l.running + '/' + (capOverride ?? r.cap) + ' sessions (' + (l.names.join(',') || '-') + '), ' + l.freeGB + ' GB free' : 'unread'); }).join(' | '));
444
501
  // The commit a unit's base names in its checkout here, after this pass's fetch: origin/main when it names main, else the ref or commit it
445
502
  // pins. A pinned full commit id the checkout lacks (a cut session's work sits on a rescue ref) is fetched once by its id; still none is null.
446
503
  const commitOf = async (repo, ref) => {
@@ -453,8 +510,9 @@ export async function fillPass({ fleet, queueFile, options = {}, shadow = false,
453
510
  return /^[0-9a-f]{40}$/.test(sha) ? sha : null;
454
511
  };
455
512
  const preflightOf = fleet.preflight ? (u) => (io.preflight ?? runPreflight)(fleet, u) : null;
456
- const choice = await chooseUnits({ units: q.units, state: st, runners: fleet.runners, loads, cap: fleet.cap, minFreeGB: fleet.minFreeGB, capOverride, only: options.only ? list(options.only) : null, place, running, hasCheckout, commitOf, wantsOf, preflightOf });
513
+ const choice = await chooseUnits({ units: q.units, state: st, runners: fleet.runners, loads, cap: fleet.cap, minFreeGB: fleet.minFreeGB, capOverride, only: options.only ? list(options.only) : null, place, running, hasCheckout, commitOf, wantsOf, preflightOf, leaders: fleet.leaders ?? [] });
457
514
  for (const n of choice.notes) say(n);
515
+ st.leaderRefused = choice.leaderRefused;
458
516
  st.skillHeld = choice.skillHeld;
459
517
  st.preflightHeld = choice.preflightHeld;
460
518
  st.noCheckout = choice.noCheckout;
@@ -51,7 +51,9 @@ const isGpt = (model) => /^gpt-/i.test(String(model ?? ''));
51
51
 
52
52
  const READ = ['Read', 'Glob', 'Grep', 'LS', 'WebSearch', 'WebFetch', 'TodoWrite', 'Task'];
53
53
  const EFFORTS = ['low', 'medium', 'high', 'xhigh', 'max'];
54
- const WRITE = [...READ, 'Edit', 'MultiEdit', 'Write', 'NotebookEdit', 'Bash(git:*)', 'Bash(node:*)', 'Bash(pnpm:*)', 'Bash(npm:*)', 'Bash(npx:*)', 'Bash(curl:*)', 'Bash(unzip:*)', 'Bash(sha256sum:*)', 'Bash(file:*)', 'Bash(ls:*)', 'Bash(cat:*)', 'Bash(head:*)', 'Bash(tail:*)', 'Bash(wc:*)', 'Bash(mkdir:*)', 'Bash(cp:*)', 'Bash(mv:*)', 'Bash(rg:*)'];
54
+ // python, uv, ffmpeg and docker joined on 2026-12-04, when three runner units stopped BLOCKED on a refused sound measurement, a
55
+ // uv-run test suite and a postgres:17 test database.
56
+ const WRITE = [...READ, 'Edit', 'MultiEdit', 'Write', 'NotebookEdit', 'Bash(git:*)', 'Bash(node:*)', 'Bash(pnpm:*)', 'Bash(npm:*)', 'Bash(npx:*)', 'Bash(curl:*)', 'Bash(unzip:*)', 'Bash(sha256sum:*)', 'Bash(file:*)', 'Bash(ls:*)', 'Bash(cat:*)', 'Bash(head:*)', 'Bash(tail:*)', 'Bash(wc:*)', 'Bash(mkdir:*)', 'Bash(cp:*)', 'Bash(mv:*)', 'Bash(rg:*)', 'Bash(python:*)', 'Bash(python3:*)', 'Bash(uv:*)', 'Bash(uvx:*)', 'Bash(ffmpeg:*)', 'Bash(ffprobe:*)', 'Bash(docker:*)'];
55
57
  const LEAD = /^[\s>*_`#-]+/;
56
58
  const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
57
59
  const alive = (pid) => { if (!pid) return false; try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; } };
@@ -155,11 +155,22 @@ export function startScript(cmd, cwd, priority = null) {
155
155
  return startup + '$r = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{ CommandLine = ' + q(cmd) + '; CurrentDirectory = ' + q(cwd) + (startup ? '; ProcessStartupInformation = [ciminstance]$si' : '') + " }; 'rc ' + $r.ReturnValue + ' pid ' + $r.ProcessId";
156
156
  }
157
157
 
158
+ // The start check's first step: the machine ssh reached answers with its own name, and one the register names as the leader refuses, so
159
+ // an ssh alias that resolves to the leader (a LAN or tailnet alias, localhost) starts nothing there. Empty when no leader is known.
160
+ export function leaderCheck(leaders = []) {
161
+ const names = leaders.filter((n) => /^[\w.-]+$/.test(String(n)));
162
+ return names.length ? 'if (@(' + names.map(q).join(',') + ") -contains $env:COMPUTERNAME) { 'leader ' + $env:COMPUTERNAME } else" : '';
163
+ }
164
+
158
165
  // Starts one session: checks the runner can take it, makes its folder, sends the prompt, the launch settings and the wrapper, checks the
159
166
  // commit out on a branch of its own clone, copies or links its inputs and starts the wrapper detached. { ok, message, exists }: exists is
160
- // live or cut when a folder of that name is already there, by whether the wrapper its pid.txt names still runs.
161
- export async function startSession(fleet, tools, runner, { name, promptFile, repoDir = null, sha = null, mode = 'write', model, effort = null, minutes = 60, branch = null, inputsDir = null, links = [], cap = runner.cap ?? fleet.cap }) {
167
+ // live or cut when a folder of that name is already there, by whether the wrapper its pid.txt names still runs. A runner that is the leader
168
+ // (queue.mjs leaderOf), or whose ssh answers from a machine the register names as the leader, is refused before anything is sent, whoever
169
+ // starts it: the queue, agenv run --session --runner <id> or --runner auto. io holds this function's own runner calls (the checkout keeps its
170
+ // own), so a test can stand in for the runner.
171
+ export async function startSession(fleet, tools, runner, { name, promptFile, repoDir = null, sha = null, mode = 'write', model, effort = null, minutes = 60, branch = null, inputsDir = null, links = [], cap = runner.cap ?? fleet.cap }, io = { ps, scp }) {
162
172
  const fail = (message) => ({ ok: false, message });
173
+ if (runner.leader) return fail(runner.id + ' is the leader (' + runner.leader + '); no session starts there');
163
174
  if (!/^[a-z0-9][a-z0-9-]{0,47}$/.test(name)) return fail('a session name is lowercase letters, digits and dashes, at most 48');
164
175
  if (!/^[A-Za-z0-9._:-]+$/.test(model ?? '') || !(minutes > 0 && minutes <= 240)) return fail('a session takes a model name and 1 to 240 minutes');
165
176
  if (branch && !/^[A-Za-z0-9][A-Za-z0-9._\/-]{0,79}$/.test(branch)) return fail('a branch name was expected, got ' + branch);
@@ -168,26 +179,29 @@ export async function startSession(fleet, tools, runner, { name, promptFile, rep
168
179
  const route = (/^gpt-/i.test(model) && fleet.routes.gpt ? fleet.routes.gpt : fleet.routes.claude).replace(/\/$/, '');
169
180
  const cliName = path.basename(fleet.agentCli);
170
181
  // The runner can take it: the name is free, the CLI is installed, the runner is under its cap and the model route answers.
171
- const pre = await ps(tools, runner.host, 'if (Test-Path ' + q(D) + ') { $w = if (Test-Path ' + q(D + '/pid.txt') + ') { (Get-Content ' + q(D + '/pid.txt') + ").Split(' ')[0] } else { '' }; if ($w -and (Get-Process -Id $w -ErrorAction SilentlyContinue)) { 'exists live' } else { 'exists cut' } } elseif (-not (Test-Path " + q(fleet.agentCli) + ")) { 'no cli' } else { $n = " + cliCount(fleet.root, cliName) + '; if ($n -ge ' + Number(cap) + ") { 'full ' + $n } else { try { 'relay ' + (Invoke-WebRequest -UseBasicParsing -TimeoutSec 20 " + q(route + '/v1/models') + ' -Headers @{ authorization = ' + q('Bearer ' + fleet.token) + " }).StatusCode } catch { 'relay down' } } }");
182
+ const lead = leaderCheck(fleet.leaders);
183
+ // lead ends with "else", so the check below continues it as elseif.
184
+ const pre = await io.ps(tools, runner.host, lead + 'if (Test-Path ' + q(D) + ') { $w = if (Test-Path ' + q(D + '/pid.txt') + ') { (Get-Content ' + q(D + '/pid.txt') + ").Split(' ')[0] } else { '' }; if ($w -and (Get-Process -Id $w -ErrorAction SilentlyContinue)) { 'exists live' } else { 'exists cut' } } elseif (-not (Test-Path " + q(fleet.agentCli) + ")) { 'no cli' } else { $n = " + cliCount(fleet.root, cliName) + '; if ($n -ge ' + Number(cap) + ") { 'full ' + $n } else { try { 'relay ' + (Invoke-WebRequest -UseBasicParsing -TimeoutSec 20 " + q(route + '/v1/models') + ' -Headers @{ authorization = ' + q('Bearer ' + fleet.token) + " }).StatusCode } catch { 'relay down' } } }");
172
185
  const said = pre.out.trim();
186
+ if (said.startsWith('leader ')) return fail(runner.id + ' (' + runner.host + ') answers as ' + said.slice(7) + ', the leader in the register; no session starts there');
173
187
  if (said.startsWith('exists')) return { ...fail('a session named ' + name + ' already exists on ' + runner.id + (said === 'exists live' ? ', its wrapper running' : ', no wrapper running')), exists: said.slice(7) };
174
188
  if (said === 'no cli') return fail(runner.id + ' has no agent CLI at ' + fleet.agentCli);
175
189
  if (said.startsWith('full')) return fail(runner.id + ' is full: ' + said.slice(5) + ' sessions running, cap ' + cap);
176
190
  if (said !== 'relay 200') return fail(runner.id + ' cannot reach the model route ' + route + ' (' + (said || pre.err || 'no answer') + ')');
177
- const mk = await ps(tools, runner.host, 'New-Item -ItemType Directory -Force ' + ['work', 'out', 'config', 'tmp'].map((d) => q(D + '/' + d)).join(',') + ' | Out-Null; [IO.File]::WriteAllText(' + q(D + '/launch.json') + ', [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(' + q(b64(JSON.stringify(launchFile(fleet, { mode, model, minutes, effort }), null, 1) + '\n')) + "))); 'ok'");
191
+ const mk = await io.ps(tools, runner.host, 'New-Item -ItemType Directory -Force ' + ['work', 'out', 'config', 'tmp'].map((d) => q(D + '/' + d)).join(',') + ' | Out-Null; [IO.File]::WriteAllText(' + q(D + '/launch.json') + ', [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(' + q(b64(JSON.stringify(launchFile(fleet, { mode, model, minutes, effort }), null, 1) + '\n')) + "))); 'ok'");
178
192
  if (!mk.out.includes('ok')) return fail('could not make ' + D + ' on ' + runner.id + ': ' + mk.err.slice(0, 200));
179
- if (!(await scp(tools, [promptFile, runner.host + ':' + D + '/prompt.txt'])).ok) return fail('the prompt copy to ' + runner.id + ' failed');
193
+ if (!(await io.scp(tools, [promptFile, runner.host + ':' + D + '/prompt.txt'])).ok) return fail('the prompt copy to ' + runner.id + ' failed');
180
194
  // The wrapper and the bash guard are copied only when the runner's copy differs, and then by a rename, so a launch beside other launches
181
195
  // never truncates a file under a session that is starting.
182
196
  for (const [file, fileName, what] of [[WRAPPER, WRAPPER_NAME, 'session wrapper'], [GUARD, GUARD_NAME, 'bash guard']]) {
183
197
  const want = createHash('sha256').update(fs.readFileSync(file)).digest('hex').toUpperCase();
184
198
  const target = fleet.root + '/bin/' + fileName;
185
- const have = (await ps(tools, runner.host, 'if (Test-Path ' + q(target) + ') { (Get-FileHash -Algorithm SHA256 -LiteralPath ' + q(target) + ").Hash } else { 'none' }")).out.trim();
199
+ const have = (await io.ps(tools, runner.host, 'if (Test-Path ' + q(target) + ') { (Get-FileHash -Algorithm SHA256 -LiteralPath ' + q(target) + ").Hash } else { 'none' }")).out.trim();
186
200
  if (have === want) continue;
187
201
  const tmp = target + '.' + name + '.tmp';
188
- await ps(tools, runner.host, 'New-Item -ItemType Directory -Force ' + q(fleet.root + '/bin') + ' | Out-Null');
189
- if (!(await scp(tools, [file, runner.host + ':' + tmp])).ok) return fail('the ' + what + ' copy to ' + runner.id + ' failed');
190
- if (!(await ps(tools, runner.host, 'Move-Item -Force -LiteralPath ' + q(tmp) + ' -Destination ' + q(target) + "; 'moved'")).out.includes('moved')) return fail('the ' + what + ' rename on ' + runner.id + ' failed');
202
+ await io.ps(tools, runner.host, 'New-Item -ItemType Directory -Force ' + q(fleet.root + '/bin') + ' | Out-Null');
203
+ if (!(await io.scp(tools, [file, runner.host + ':' + tmp])).ok) return fail('the ' + what + ' copy to ' + runner.id + ' failed');
204
+ if (!(await io.ps(tools, runner.host, 'Move-Item -Force -LiteralPath ' + q(tmp) + ' -Destination ' + q(target) + "; 'moved'")).out.includes('moved')) return fail('the ' + what + ' rename on ' + runner.id + ' failed');
191
205
  }
192
206
  if (repoDir) {
193
207
  const checkedOut = await checkout(fleet, tools, runner, { D, name, repoDir, sha, branch: branch ?? 'fleet/' + name });
@@ -197,7 +211,7 @@ export async function startSession(fleet, tools, runner, { name, promptFile, rep
197
211
  const bad = secretFiles(inputsDir);
198
212
  if (bad.length) return fail('these input files look like credentials and stay here: ' + bad.slice(0, 10).join(', '));
199
213
  // Into an inputs folder that does not exist yet, so the folder's contents land flat in it.
200
- const c = await scp(tools, [path.resolve(inputsDir), runner.host + ':' + D + '/work/inputs']);
214
+ const c = await io.scp(tools, [path.resolve(inputsDir), runner.host + ':' + D + '/work/inputs']);
201
215
  if (!c.ok) return fail('the inputs copy to ' + runner.id + ' failed: ' + c.err.slice(0, 200));
202
216
  }
203
217
  // A large input is one read-only copy per runner under <root>/shared, linked into the session's inputs as a junction. Removing a session
@@ -205,11 +219,11 @@ export async function startSession(fleet, tools, runner, { name, promptFile, rep
205
219
  for (const { rel, target } of links) {
206
220
  if (!/^[A-Za-z0-9._][A-Za-z0-9._\/-]*$/.test(rel) || rel.split('/').includes('..') || !target?.startsWith(fleet.root + '/shared/')) return fail('a link takes a path under inputs and a shared copy under ' + fleet.root + '/shared');
207
221
  const at = D + '/work/inputs/' + rel;
208
- const o = await ps(tools, runner.host, 'if (-not (Test-Path ' + q(target + '/.shared-stamp') + ")) { 'no shared copy' } else { New-Item -ItemType Directory -Force (Split-Path " + q(at) + ') | Out-Null; if (-not (Test-Path ' + q(at) + ')) { New-Item -ItemType Junction -Path ' + q(at) + ' -Target ' + q(win(target)) + ' | Out-Null }; (Get-Item ' + q(at) + ').LinkType }');
222
+ const o = await io.ps(tools, runner.host, 'if (-not (Test-Path ' + q(target + '/.shared-stamp') + ")) { 'no shared copy' } else { New-Item -ItemType Directory -Force (Split-Path " + q(at) + ') | Out-Null; if (-not (Test-Path ' + q(at) + ')) { New-Item -ItemType Junction -Path ' + q(at) + ' -Target ' + q(win(target)) + ' | Out-Null }; (Get-Item ' + q(at) + ').LinkType }');
209
223
  if (o.out.trim() !== 'Junction') return fail('link ' + rel + ' failed: ' + (o.out + o.err).trim().slice(0, 200));
210
224
  }
211
225
  const cmd = '"' + win(fleet.runnerNode) + '" ' + win(fleet.root + '/bin/' + WRAPPER_NAME) + ' ' + win(D);
212
- const st = await ps(tools, runner.host, startScript(cmd, win(D), runner.priority));
226
+ const st = await io.ps(tools, runner.host, startScript(cmd, win(D), runner.priority));
213
227
  if (!/rc 0 pid \d+/.test(st.out)) return fail('start failed: ' + (st.out + st.err).trim().slice(0, 200));
214
228
  return { ok: true, message: name + ' started on ' + runner.id + ' (' + st.out.trim() + (runner.priority ? ', ' + runner.priority : '') + '), ' + mode + ' mode, model ' + model + ', at most ' + minutes + ' min, folder ' + D };
215
229
  }