windows-development-sandbox 1.13.0 → 1.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/app/features/accounts/accounts.def.d.ts +1 -0
  2. package/dist/app/features/accounts/accounts.def.js +12 -3
  3. package/dist/app/features/accounts/accounts.run.d.ts +1 -0
  4. package/dist/app/features/accounts/accounts.run.js +20 -11
  5. package/dist/app/features/defs.d.ts +1 -0
  6. package/dist/app/features/settings/settings-file.d.ts +7 -0
  7. package/dist/app/features/settings/settings-file.js +19 -2
  8. package/dist/app/features/settings/settings-rows.js +9 -1
  9. package/dist/bin/agent-sandbox.js +7 -1
  10. package/dist/bin/chunk-IL7BXJF2.js +7 -0
  11. package/dist/bin/chunk-K4SU3MHJ.js +10432 -0
  12. package/dist/bin/chunk-VENWSGX2.js +78437 -0
  13. package/dist/bin/claude-host.js +10 -4
  14. package/dist/bin/claude-sbx.js +8 -2
  15. package/dist/bin/codex-sbx.js +8 -2
  16. package/dist/bin/gemini-sbx.js +8 -2
  17. package/dist/bin/sandbox.js +7 -2
  18. package/dist/bin/sbx-hide.js +8 -2
  19. package/dist/bin/sbx-show.js +8 -2
  20. package/dist/cli/commands/launch/prepare.js +24 -7
  21. package/dist/cli/commands/launch/running.js +4 -0
  22. package/dist/cli/commands/storage/offer.js +1 -1
  23. package/dist/cli/menu/live.d.ts +29 -0
  24. package/dist/cli/menu/live.js +92 -21
  25. package/dist/cli/menu/menu.d.ts +2 -1
  26. package/dist/cli/menu/menu.js +16 -2
  27. package/dist/cli/menu/pages/list-page.d.ts +5 -0
  28. package/dist/cli/menu/pages/list-page.js +19 -0
  29. package/dist/cli/menu/shell.d.ts +2 -0
  30. package/dist/cli/menu/shell.js +1 -1
  31. package/dist/cli/services/accounts-service.d.ts +7 -0
  32. package/dist/cli/services/accounts-service.js +20 -0
  33. package/dist/cli/tui/app.d.ts +4 -0
  34. package/dist/cli/tui/app.js +5 -0
  35. package/dist/cli/tui/terminal.d.ts +6 -0
  36. package/dist/cli/tui/terminal.js +8 -1
  37. package/dist/cli/validate.js +8 -4
  38. package/dist/core/package-info.js +1 -1
  39. package/dist/host/sandbox/platform.d.ts +2 -0
  40. package/dist/host/sandbox/platform.js +19 -4
  41. package/dist/host/storage/contained/state.d.ts +3 -2
  42. package/dist/host/storage/contained/state.js +5 -2
  43. package/dist/selftest/layout.test.js +10 -1
  44. package/dist/selftest/menu-perf.test.js +198 -12
  45. package/dist/selftest/menu.test.js +4 -0
  46. package/dist/web/index.html +1 -1
  47. package/dist/web/{main-Z2WYAE2Z.js → main-NBQ3LF4E.js} +1 -1
  48. package/native/csharp/HcsHost/AssemblyInfo.cs +3 -3
  49. package/native/csharp/HostTools/AssemblyInfo.cs +3 -3
  50. package/package.json +1 -1
@@ -4,7 +4,7 @@ import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import { DATABASES } from '../core/detect/index.js';
6
6
  import { fail } from '../core/util/index.js';
7
- import { AccountStore } from '../host/profile/index.js';
7
+ import { AccountsService } from './services/accounts-service.js';
8
8
  /** Edit distance, for "did you mean". */
9
9
  export function distance(a, b) {
10
10
  let row = Array.from({ length: b.length + 1 }, (_, i) => i);
@@ -79,11 +79,15 @@ export function validateOptions(ctx) {
79
79
  unknownValue('database', db, DATABASES, 'Repeat --database for several.');
80
80
  }
81
81
  if (o.account !== undefined) {
82
- const names = new AccountStore(ctx.storageRoot).list(ctx.dataPath).map((a) => a.name);
82
+ // The launched agent's saved logins (an agent that keeps none says so).
83
+ const agent = o.harness ?? ctx.loaded.config.defaultHarness;
84
+ const names = new AccountsService(ctx).list(agent).map((a) => a.name);
83
85
  if (!names.includes(o.account))
84
86
  unknownValue('account', o.account, names, names.length
85
- ? 'See them with: sandbox account list'
86
- : 'None saved yet: sign in inside the sandbox, then run sandbox account save <name>.');
87
+ ? 'See them with: sandbox account list' + (agent === 'claude' ? '' : ' --agent ' + agent)
88
+ : 'None saved yet: sign in inside the sandbox, then run sandbox account save <name>' +
89
+ (agent === 'claude' ? '' : ' --agent ' + agent) +
90
+ '.');
87
91
  }
88
92
  for (const s of o.sessions) {
89
93
  checkHarness(s.harness, harnesses);
@@ -1,5 +1,5 @@
1
1
  // Where this package is installed and its version. This file is dist/core/package-info.js, two folders below
2
- // package.json.
2
+ // package.json, or bundled into a chunk in dist/bin (scripts/bundle.mjs), also two folders below.
3
3
  import path from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { z } from 'zod';
@@ -7,6 +7,8 @@ export declare function insideSandbox(): boolean;
7
7
  export declare const GUEST_DATA_DIR = "C:\\AgentData";
8
8
  /** Whether a Windows Sandbox program is in this process list (tasklist /NH /FO CSV output). */
9
9
  export declare function sandboxInTasklist(tasklist: string): boolean;
10
+ /** The process ids of the Windows Sandbox programs in this process list (tasklist /NH /FO CSV output). */
11
+ export declare function sandboxPids(tasklist: string): number[];
10
12
  export declare function isSandboxRunning(): boolean;
11
13
  export declare function sandboxFeatureInstalled(): boolean;
12
14
  /** `owner`: whose sandbox runs, when the caller knows (host/sharing); it makes the message say who started it. */
@@ -10,15 +10,19 @@ import { launchBlocked } from '../sharing/rules.js';
10
10
  const HELPER_TIMEOUT_MS = 15000;
11
11
  const START_WAIT_MS = 20000;
12
12
  const SANDBOX_PROCESSES = ['WindowsSandboxClient.exe', 'WindowsSandboxRemoteSession.exe', 'WindowsSandbox.exe'];
13
+ /** Whether the launch and data folders are mapped in (looked for once; see insideSandbox). */
14
+ let mappedIn;
13
15
  /**
14
16
  * Running INSIDE a Windows Sandbox this tool started (its launch folder and data folder are mapped in): then the CLI
15
17
  * talks to the sandbox it is in, through C:\\AgentData and loopback, instead of looking for one on a PC.
16
18
  */
17
19
  export function insideSandbox() {
18
- return (isWin &&
19
- !process.env.AGENT_SANDBOX_HOST_ONLY &&
20
- fs.existsSync('C:\\AgentLaunch\\session.json') &&
21
- fs.existsSync('C:\\AgentData\\run'));
20
+ if (!isWin || process.env.AGENT_SANDBOX_HOST_ONLY)
21
+ return false;
22
+ // The launch folder and the data folder are mapped in for the sandbox's whole life (and never exist on a PC), so
23
+ // they are looked for once: the menu asks this many times a second.
24
+ mappedIn ??= fs.existsSync('C:\\AgentLaunch\\session.json') && fs.existsSync('C:\\AgentData\\run');
25
+ return mappedIn;
22
26
  }
23
27
  export const GUEST_DATA_DIR = 'C:\\AgentData';
24
28
  /** Whether a Windows Sandbox program is in this process list (tasklist /NH /FO CSV output). */
@@ -26,6 +30,17 @@ export function sandboxInTasklist(tasklist) {
26
30
  const out = tasklist.toLowerCase();
27
31
  return SANDBOX_PROCESSES.some((image) => out.includes('"' + image.toLowerCase() + '"'));
28
32
  }
33
+ /** The process ids of the Windows Sandbox programs in this process list (tasklist /NH /FO CSV output). */
34
+ export function sandboxPids(tasklist) {
35
+ const images = new Set(SANDBOX_PROCESSES.map((image) => image.toLowerCase()));
36
+ const pids = [];
37
+ for (const line of tasklist.split('\n')) {
38
+ const row = /^"([^"]{1,260})","(\d{1,10})"/.exec(line);
39
+ if (row && images.has(row[1].toLowerCase()))
40
+ pids.push(Number(row[2]));
41
+ }
42
+ return pids;
43
+ }
29
44
  export function isSandboxRunning() {
30
45
  if (!isWin)
31
46
  return false;
@@ -83,7 +83,8 @@ export declare class StateFile {
83
83
  export declare function mountedSets(storageRoot: string): string[];
84
84
  /**
85
85
  * A line for the start of a command when the record says an image is mounted that no running process holds and no
86
- * sandbox uses (nothing is looked up on the disk: this is only the record), or null.
86
+ * sandbox uses (nothing is looked up on the disk: this is only the record), or null. `sandboxRunning` can be a
87
+ * function: it is only asked (it runs tasklist) when the record says an image is mounted.
87
88
  */
88
- export declare function staleMountNote(storageRoot: string, set: string, sandboxRunning: boolean, alive?: (pid: number) => boolean): string | null;
89
+ export declare function staleMountNote(storageRoot: string, set: string, sandboxRunning: boolean | (() => boolean), alive?: (pid: number) => boolean): string | null;
89
90
  export {};
@@ -155,12 +155,15 @@ export function mountedSets(storageRoot) {
155
155
  }
156
156
  /**
157
157
  * A line for the start of a command when the record says an image is mounted that no running process holds and no
158
- * sandbox uses (nothing is looked up on the disk: this is only the record), or null.
158
+ * sandbox uses (nothing is looked up on the disk: this is only the record), or null. `sandboxRunning` can be a
159
+ * function: it is only asked (it runs tasklist) when the record says an image is mounted.
159
160
  */
160
161
  export function staleMountNote(storageRoot, set, sandboxRunning, alive = processAlive) {
161
162
  const record = setStateOf(new JsonFile(ContainedStateSchema, path.join(path.resolve(storageRoot), 'mounts', 'state.json')).read() ??
162
163
  EMPTY_STATE, set);
163
- if (!record.mounted || sandboxRunning || record.holders.some((h) => alive(h.pid)))
164
+ if (!record.mounted || record.holders.some((h) => alive(h.pid)))
165
+ return null;
166
+ if (typeof sandboxRunning === 'function' ? sandboxRunning() : sandboxRunning)
164
167
  return null;
165
168
  return 'Contained storage is still mounted from an earlier sandbox. Run sandbox repair to dismount it (Windows asks for permission).';
166
169
  }
@@ -1,6 +1,7 @@
1
1
  // The architecture rules, checked on the compiled output (dist/**/*.js): which areas may import which, the guest's
2
2
  // portable core, the pure guest files the host and tests may load without the guest runtime's side effects, and no
3
- // import cycles. The bundled dist/runtime is left out (it has no imports).
3
+ // import cycles. The bundled dist/runtime is left out (it has no imports); the bundled commands (dist/bin) must import
4
+ // only their own chunks.
4
5
  import fs from 'node:fs';
5
6
  import path from 'node:path';
6
7
  const STATIC = /^\s*(?:import|export)\b[^;]*?\bfrom\s*(['"])([^'"\n]+)\1;?\s*$|^\s*import\s*(['"])([^'"\n]+)\3;?\s*$/gm;
@@ -149,5 +150,13 @@ export const layoutSuite = {
149
150
  .filter((d) => area(d) === 'app' && !(area(f) === 'host' && d.startsWith('app/kernel/')))
150
151
  .map((d) => f + ' -> ' + d));
151
152
  t.check(!intoApp.length, 'below the CLI only host code uses the shared core, and only its kernel', list(intoApp));
153
+ t.section('the commands');
154
+ // Loading the CLI as hundreds of modules took most of a second before anything was shown (scripts/bundle.mjs).
155
+ const bins = files.filter((f) => area(f) === 'bin');
156
+ const unbundled = bins.flatMap((f) => modules
157
+ .get(f)
158
+ .statics.filter((d) => area(d) !== 'bin')
159
+ .map((d) => f + ' -> ' + d));
160
+ t.check(bins.includes('bin/sandbox.js') && bins.some((f) => f.startsWith('bin/chunk-')) && !unbundled.length, 'the commands (dist/bin) are bundled: they load no compiled module one by one', list(unbundled));
152
161
  },
153
162
  };
@@ -1,16 +1,21 @@
1
- // The menu stays quick: no key or draw waits for a child process (tasklist is faked and counted), a slow tab load shows
2
- // "Loading…" instead of holding up the keys, a held key is drawn once, and the terminal writes only the rows that
3
- // changed (the screen after the diffs is the same as a full draw, also after a resize).
1
+ // The menu stays quick: no key or draw waits for a child process (tasklist is faked and counted), the first screen does
2
+ // not wait for the process list, a slow tab load shows "Loading…" instead of holding up the keys, a section seen before
3
+ // shows at once, a held key is drawn once, Esc is a key at once, an idle menu writes nothing, and the terminal writes
4
+ // only the rows that changed (the screen after the diffs is the same as a full draw, also after a resize). The process
5
+ // list is fetched only when it may have changed, and the settings file is read once for a whole list.
6
+ import fs from 'node:fs';
4
7
  import { EventEmitter } from 'node:events';
5
8
  import { PassThrough } from 'node:stream';
9
+ import { ConfigFile } from '../app/features/settings/index.js';
6
10
  import { DEFAULTS } from '../core/config/index.js';
7
11
  import { sleep } from '../core/util/index.js';
8
12
  import { Menu } from '../cli/menu/menu.js';
9
- import { LiveStatus } from '../cli/menu/live.js';
13
+ import { LiveStatus, listGap } from '../cli/menu/live.js';
10
14
  import { ListPage } from '../cli/menu/pages/list-page.js';
11
15
  import { App, Text, Terminal } from '../cli/tui/index.js';
12
- import { supportsSyncUpdate } from '../cli/tui/terminal.js';
13
- import { isSandboxRunning, useTasklistCache, useTasklistRunners } from '../host/sandbox/index.js';
16
+ import { ESCAPE_TIMEOUT_MS, supportsSyncUpdate } from '../cli/tui/terminal.js';
17
+ import { isSandboxRunning, readTasklist, sandboxPids, useTasklistCache, useTasklistRunners, } from '../host/sandbox/index.js';
18
+ import { staleMountNote } from '../host/storage/index.js';
14
19
  const TASKLIST = [
15
20
  '"System Idle Process","0","Services","0","8 K"',
16
21
  '"WindowsSandboxClient.exe","4242","Console","1","9,000 K"',
@@ -124,6 +129,26 @@ export const menuPerfSuite = {
124
129
  app.close();
125
130
  t.check(result === 'bye' && handled === 31 && renders < 10, 'keys that are already waiting are handled first and drawn once, not once each', 'handled ' + handled + ', drawn ' + renders);
126
131
  }
132
+ t.section('Esc is a key at once');
133
+ {
134
+ const tty = new FakeTty();
135
+ const term = tty.terminal();
136
+ term.start();
137
+ const times = [];
138
+ for (let i = 0; i < 3; i++) {
139
+ const at = Date.now();
140
+ tty.type('\x1b');
141
+ const key = await term.key();
142
+ times.push(Date.now() - at);
143
+ if (key.name !== 'escape')
144
+ times.push(9999);
145
+ }
146
+ tty.type('\x1b[B');
147
+ const arrow = await term.key();
148
+ term.stop();
149
+ t.check(Math.max(...times) < 250 && ESCAPE_TIMEOUT_MS <= 50, 'Esc arrives in ' + times.join(', ') + ' ms (Node waits 500 ms for the rest of a sequence by default)', times.join(', '));
150
+ t.check(arrow.name === 'down', 'an arrow key is still one key, not Esc and letters');
151
+ }
127
152
  t.section('a slow load does not hold up the keys');
128
153
  {
129
154
  const tty = new FakeTty();
@@ -131,9 +156,10 @@ export const menuPerfSuite = {
131
156
  class Slow extends ListPage {
132
157
  label = 'Slow';
133
158
  rows = [];
159
+ next = ['alpha', 'beta'];
134
160
  async load() {
135
161
  await sleep(500);
136
- this.rows = ['alpha', 'beta'];
162
+ this.rows = this.next;
137
163
  }
138
164
  options() {
139
165
  return { path: [], items: this.rows.map((r) => ({ value: r, label: r })) };
@@ -150,6 +176,14 @@ export const menuPerfSuite = {
150
176
  t.check(waited < 400 && page.loading && text().includes('Loading'), 'the tab opens at once and says Loading… while the data comes', 'waited ' + waited + ' ms');
151
177
  const arrived = await t.waitFor(() => (text().includes('beta') ? true : null), 5000, 20);
152
178
  t.check(arrived === true && !page.loading, 'the list is built when the data arrives');
179
+ // Back on the section later: what it had shows at once, the fresh data replaces it when it is there.
180
+ page.next = ['alpha', 'gamma'];
181
+ const again = Date.now();
182
+ await page.show();
183
+ const shownIn = Date.now() - again;
184
+ t.check(shownIn < 100 && text().includes('beta'), 'a section seen before shows its last data at once (in ' + shownIn + ' ms), not Loading…', text());
185
+ const fresh = await t.waitFor(() => (text().includes('gamma') ? true : null), 5000, 20);
186
+ t.check(fresh === true && !text().includes('beta'), 'and its fresh data when it has loaded');
153
187
  }
154
188
  t.section('no child process on a key or a draw');
155
189
  const saved = { hostOnly: process.env.AGENT_SANDBOX_HOST_ONLY };
@@ -177,24 +211,34 @@ export const menuPerfSuite = {
177
211
  return TASKLIST;
178
212
  },
179
213
  refreshMs: 100,
214
+ // The sandbox's process is gone at every look: the list is fetched again on every tick.
215
+ processAlive: () => false,
180
216
  });
217
+ const startedAt = Date.now();
181
218
  const done = menu.start();
182
- const shown = await t.waitFor(() => tty.writes.length > 0, 20000, 20);
219
+ const shown = await t.waitFor(() => tty.writes.length > 0, 20000, 5);
220
+ const firstPaint = Date.now() - startedAt;
183
221
  t.check(shown === true, 'the menu draws its first screen');
222
+ t.check(firstPaint < 1000, 'the first screen does not wait for a 1.5 second process list (drawn after ' + firstPaint + ' ms)');
184
223
  const slowest = { ms: 0, key: '' };
224
+ const took = [];
185
225
  const press = async (name, bytes) => {
186
226
  const before = tty.writes.length;
187
227
  const at = Date.now();
188
228
  tty.type(bytes);
189
229
  // Not every key changes the screen: give the ones that do a chance, and measure those.
190
- await t.waitFor(() => tty.writes.length > before, 400, 5);
191
- const took = Date.now() - at;
192
- if (tty.writes.length > before && took > slowest.ms) {
193
- slowest.ms = took;
230
+ await t.waitFor(() => tty.writes.length > before, 400, 2);
231
+ const ms = Date.now() - at;
232
+ if (tty.writes.length > before)
233
+ took.push(ms);
234
+ if (tty.writes.length > before && ms > slowest.ms) {
235
+ slowest.ms = ms;
194
236
  slowest.key = name;
195
237
  }
196
238
  await sleep(15);
197
239
  };
240
+ // The pages have their data (the first process list came after 1.5 s).
241
+ await sleep(1700);
198
242
  const syncBefore = calls.sync;
199
243
  for (const section of ['2', '3', '4', '5', '6', '7', '1'])
200
244
  await press('section ' + section, section);
@@ -209,6 +253,21 @@ export const menuPerfSuite = {
209
253
  ' ' +
210
254
  slowest.ms +
211
255
  ' ms)');
256
+ const median = [...took].sort((a, b) => a - b)[Math.floor(took.length / 2)] ?? 9999;
257
+ t.check(median < 100, 'a key is usually drawn at once (median ' + median + ' ms over ' + took.length + ' keys)');
258
+ // Left alone, the menu writes nothing: the process list keeps coming (every tick here), but nothing on the
259
+ // screen changes, so nothing is drawn.
260
+ await sleep(300);
261
+ const idleFrom = tty.writes.length;
262
+ const fetchesFrom = calls.async;
263
+ await sleep(3000);
264
+ const idleWrites = tty.writes.slice(idleFrom);
265
+ const idleBytes = idleWrites.join('').length;
266
+ t.check(idleWrites.length <= 1 && idleBytes < 4000 && calls.async > fetchesFrom, 'an idle menu writes nothing for 3 s (' +
267
+ idleWrites.length +
268
+ ' writes, ' +
269
+ idleBytes +
270
+ ' bytes) while the process list is looked at in the background', Text.strip(idleWrites.join('')).slice(0, 300));
212
271
  tty.type(KEYS.ctrlC);
213
272
  const code = await Promise.race([done, sleep(5000).then(() => -1)]);
214
273
  t.check(code === 130, 'Ctrl+C leaves the menu');
@@ -244,5 +303,132 @@ export const menuPerfSuite = {
244
303
  await sleep(80);
245
304
  t.check(live.line() === 'status b' && changes === 2, 'a stopped status looks at nothing');
246
305
  }
306
+ t.section('the process list is fetched only when it may have changed');
307
+ {
308
+ t.equal([0, 1, 2, 3, 4, 10, -1].map((n) => listGap(n, 2500, 30000)), [2500, 5000, 10000, 20000, 30000, 30000, 2500], 'while nothing changes, the gap between two lists doubles up to the longest');
309
+ t.equal(sandboxPids(TASKLIST + '\r\n"WindowsSandbox.exe","77","Console","1","5 K"'), [4242, 77], 'the ids of the sandbox programs are read from the list');
310
+ // A sandbox runs: its programs are checked by id, and the list is fetched again only when one has ended.
311
+ let fetches = 0;
312
+ let derived = 0;
313
+ let alive = true;
314
+ const running = new LiveStatus({
315
+ fetch: () => {
316
+ fetches++;
317
+ return Promise.resolve(TASKLIST);
318
+ },
319
+ derive: () => String(++derived),
320
+ onChange: () => undefined,
321
+ intervalMs: 20,
322
+ alive: () => alive,
323
+ needsList: () => true,
324
+ });
325
+ await running.start();
326
+ await sleep(400);
327
+ t.check(fetches === 1 && derived > 5, 'while the sandbox runs, its programs are checked by id: no new list (' +
328
+ fetches +
329
+ ' fetched), the line is still derived (' +
330
+ derived +
331
+ ' times)');
332
+ alive = false;
333
+ const refetched = await t.waitFor(() => fetches > 1, 3000, 10);
334
+ running.stop();
335
+ t.check(refetched === true, 'when one of them has ended, the list is fetched again');
336
+ // None runs: fewer and fewer lists, one at once after a key press or when the data folder changes.
337
+ fetches = 0;
338
+ let signal = 'a';
339
+ const idle = new LiveStatus({
340
+ fetch: () => {
341
+ fetches++;
342
+ return Promise.resolve('"System Idle Process","0","Services","0","8 K"');
343
+ },
344
+ derive: () => 'none',
345
+ onChange: () => undefined,
346
+ intervalMs: 20,
347
+ idleMaxMs: 100000,
348
+ needsList: () => true,
349
+ signal: () => signal,
350
+ });
351
+ await idle.start();
352
+ await sleep(1000);
353
+ const quiet = fetches;
354
+ t.check(quiet >= 2 && quiet <= 8, 'with nothing running, a second of 20 ms ticks fetched the list ' + quiet + ' times (not 50)');
355
+ signal = 'b';
356
+ const onSignal = await t.waitFor(() => fetches > quiet, 1000, 5);
357
+ t.check(onSignal === true, 'a change in the data folder fetches the list at once');
358
+ await sleep(100);
359
+ const beforeKey = fetches;
360
+ idle.touch();
361
+ const onKey = await t.waitFor(() => fetches > beforeKey, 1000, 5);
362
+ idle.stop();
363
+ t.check(onKey === true, 'so does a key press (someone is looking)');
364
+ // Inside a sandbox the list is never needed: nothing runs tasklist, not even a question asked meanwhile.
365
+ fetches = 0;
366
+ let syncRuns = 0;
367
+ useTasklistRunners({
368
+ sync: () => {
369
+ syncRuns++;
370
+ return '';
371
+ },
372
+ async: () => Promise.resolve(''),
373
+ });
374
+ try {
375
+ const inside = new LiveStatus({
376
+ fetch: () => {
377
+ fetches++;
378
+ return Promise.resolve('');
379
+ },
380
+ derive: () => 'inside',
381
+ onChange: () => undefined,
382
+ intervalMs: 20,
383
+ needsList: () => false,
384
+ });
385
+ await inside.start();
386
+ await sleep(200);
387
+ const list = readTasklist();
388
+ inside.stop();
389
+ t.check(fetches === 0 && syncRuns === 0 && list === '', 'when the list is not needed, it is never fetched and nothing asks tasklist meanwhile');
390
+ }
391
+ finally {
392
+ useTasklistRunners();
393
+ }
394
+ }
395
+ t.section('nothing before the menu waits for tasklist');
396
+ {
397
+ let asked = 0;
398
+ const note = staleMountNote(t.dir('no-mounts'), 'main', () => {
399
+ asked++;
400
+ return false;
401
+ });
402
+ t.check(note === null && asked === 0, 'with no image mounted, "is a sandbox running?" is not even asked');
403
+ }
404
+ t.section('the settings file is read once for a whole list');
405
+ {
406
+ const file = t.write(t.at('settings', 'config.json'), JSON.stringify({ defaultHarness: 'codex', workspaceFilter: { exclude: ['a', 'b'] } }));
407
+ const config = new ConfigFile('user', file);
408
+ const reads = { count: 0 };
409
+ const original = fs.readFileSync;
410
+ const counting = ((...args) => {
411
+ if (String(args[0]) === file)
412
+ reads.count++;
413
+ return original(...args);
414
+ });
415
+ fs.readFileSync = counting;
416
+ let first;
417
+ try {
418
+ first = Array.from({ length: 200 }, () => config.valueInFile(['defaultHarness']));
419
+ }
420
+ finally {
421
+ fs.readFileSync = original;
422
+ }
423
+ t.check(reads.count === 1 && first.every((v) => v === 'codex'), '200 values in one run read the file once (' + reads.count + ' reads)');
424
+ const exclude = ['workspaceFilter', 'exclude'];
425
+ config.valueInFile(exclude).push('c');
426
+ t.equal(config.valueInFile(exclude), ['a', 'b'], 'a value handed out is a copy (changing it changes nothing)');
427
+ fs.writeFileSync(file, JSON.stringify({ defaultHarness: 'gemini' }));
428
+ await Promise.resolve();
429
+ t.equal(config.valueInFile(['defaultHarness']), 'gemini', 'the next run reads the file again (a change outside)');
430
+ const result = config.set(['defaultHarness'], 'opencode');
431
+ t.equal([result, config.valueInFile(['defaultHarness'])], ['saved', 'opencode'], 'a save is seen at once');
432
+ }
247
433
  },
248
434
  };
@@ -725,6 +725,10 @@ export const menuSuite = {
725
725
  ['main', false, false],
726
726
  ['second', true, true],
727
727
  ], 'rename keeps the default and active marks');
728
+ const ensured = [service.ensure('codex', 'main'), service.activeName('codex'), fs.readFileSync(codexAuth, 'utf8')];
729
+ t.equal(ensured, ['main', 'main', '{"token":"A"}'], 'a launch with --account switches the sandbox to that login');
730
+ t.equal([service.ensure('codex', null), service.activeName('codex'), fs.readFileSync(codexAuth, 'utf8')], ['second', 'second', '{"token":"B2"}'], 'a launch without --account switches the sandbox back to the default login');
731
+ t.equal([service.ensure('claude', null), service.ensure('nobody', 'x')], [null, null], 'an agent with no saved login, or one that keeps no login: nothing to switch');
728
732
  await t.throws(() => service.save('x', false, 'nobody'), 'Unknown agent', 'an unknown agent: refused');
729
733
  await t.throws(() => service.save('bad name', false, 'codex'), 'Invalid account name', 'bad names are refused');
730
734
  t.section('every screen');
@@ -6,7 +6,7 @@
6
6
  <title>Sandbox</title>
7
7
  <link rel="icon" href="data:," />
8
8
  <link rel="stylesheet" href="/main-UAQPI5XD.css" />
9
- <script type="module" src="/main-Z2WYAE2Z.js"></script>
9
+ <script type="module" src="/main-NBQ3LF4E.js"></script>
10
10
  </head>
11
11
  <body>
12
12
  <div id="root"></div>