@ulm0/gonogo 0.1.1 → 0.2.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.
Files changed (46) hide show
  1. package/README.md +5 -11
  2. package/dist/client/assets/index-DxUnpGbS.js +52 -0
  3. package/dist/client/assets/index-tpcmltjw.css +1 -0
  4. package/dist/client/index.html +2 -2
  5. package/dist/server/audited.js +156 -0
  6. package/dist/server/blackbox.js +261 -0
  7. package/dist/server/board.js +123 -0
  8. package/dist/server/cleanroom.js +7 -51
  9. package/dist/server/clearance.js +158 -0
  10. package/dist/server/cli.js +229 -28
  11. package/dist/server/constants.js +54 -3
  12. package/dist/server/hangar.js +311 -0
  13. package/dist/server/home.js +41 -2
  14. package/dist/server/hub.js +280 -29
  15. package/dist/server/launcher.js +25 -13
  16. package/dist/server/logchart.js +58 -0
  17. package/dist/server/massbudget.js +169 -0
  18. package/dist/server/mcp.js +73 -2
  19. package/dist/server/migrate.js +7 -3
  20. package/dist/server/missionlog.js +2 -0
  21. package/dist/server/missions.js +310 -0
  22. package/dist/server/models.js +73 -0
  23. package/dist/server/phone.js +122 -0
  24. package/dist/server/phonetag.js +47 -0
  25. package/dist/server/prices.js +112 -0
  26. package/dist/server/propellant.js +243 -16
  27. package/dist/server/providers.js +123 -9
  28. package/dist/server/recorder.js +176 -0
  29. package/dist/server/relay.js +53 -7
  30. package/dist/server/relaykinds.js +11 -1
  31. package/dist/server/relief.js +226 -0
  32. package/dist/server/remotecontrol.js +15 -0
  33. package/dist/server/rollout.js +172 -0
  34. package/dist/server/tasks.js +44 -8
  35. package/dist/server/telemetry.js +110 -0
  36. package/dist/server/uplinks.js +7 -0
  37. package/dist/server/web.js +310 -10
  38. package/dist/server/worktree.js +137 -0
  39. package/dist/shared/fuel.js +8 -0
  40. package/dist/shared/livery.js +1 -1
  41. package/dist/shared/positions.js +1 -1
  42. package/dist/shared/prices.js +75 -0
  43. package/dist/shared/protocol.js +61 -15
  44. package/package.json +1 -1
  45. package/dist/client/assets/index-B6MsSoeo.css +0 -1
  46. package/dist/client/assets/index-DRtiRh1Y.js +0 -31
@@ -7,33 +7,55 @@ import { fileURLToPath } from 'node:url';
7
7
  import { PROTOCOL_VERSION } from '../shared/protocol.js';
8
8
  import { MAX_AGENTS } from '../shared/protocol.js';
9
9
  import { CLAUDE_BIN, DEFAULT_HOME_DIRNAME, DEFAULT_HOST, DEFAULT_MAX_HOPS, DEFAULT_PORT, DOWNLINK_HISTORY, MAX_HOPS_LIMIT, MAX_WORKING_ENV, REDLINE_ENV, ROSTER_ROLE_CHARS, SHUTDOWN_MAX_MS, STATION_ENV, TRANSIENT_ERROR_CODES, TRANSIENT_ERROR_PREFIXES, createLogger, nullLogger, } from './constants.js';
10
+ import { audited, BOARD_AUDIT, DOCKING_AUDIT, HUB_AUDIT, LIVERIES_AUDIT, MISSIONS_AUDIT, pollText, PRICES_AUDIT, PROPELLANT_AUDIT, RELAY_AUDIT, RELIEF_AUDIT, SCHEDULES_AUDIT, TASKS_AUDIT, tripText, UPLINKS_AUDIT } from './audited.js';
11
+ import { createBlackBox } from './blackbox.js';
12
+ import { createBoard } from './board.js';
10
13
  import { createDocking, stationName } from './docking.js';
11
14
  import { createDownlink } from './downlink.js';
12
15
  import { createHub } from './hub.js';
16
+ import { createHangar, createRoots } from './hangar.js';
17
+ import { createRecorder } from './recorder.js';
13
18
  import { checkCleanRoom } from './cleanroom.js';
19
+ import { checkWorktree, removeWorktree, worktreeBranch, worktreePath, worktreeStatus } from './worktree.js';
14
20
  import { openHome } from './home.js';
15
21
  import { createLauncher, parseAgentCmd } from './launcher.js';
16
22
  import { createTerminalHost } from './terminal.js';
17
23
  import { createWebServer } from './web.js';
18
24
  import { createPropellant } from './propellant.js';
25
+ import { createPrices } from './prices.js';
26
+ import { createTelemetry } from './telemetry.js';
19
27
  import { createRelay } from './relay.js';
20
28
  import { createSchedules } from './schedules.js';
21
29
  import { createLiveries } from './livery.js';
30
+ import { createPhone } from './phone.js';
31
+ import { createRelief } from './relief.js';
32
+ import { createMassBudget } from './massbudget.js';
22
33
  import { createMissionLog } from './missionlog.js';
34
+ import { createMissions } from './missions.js';
23
35
  import { createTasks } from './tasks.js';
24
36
  import { createUplinks } from './uplinks.js';
25
- import { installedProviders, onPath } from './providers.js';
37
+ import { checkEngines, formatDoctor, installedProviders, onPath } from './providers.js';
38
+ import { createClearance } from './clearance.js';
39
+ import { createModelDefaults } from './models.js';
40
+ import { cachedLatest, createRollout, isNewer, updateCheckOff, updateCommand, updateText } from './rollout.js';
26
41
  /* ---------------------------------------------------------------- arguments */
27
42
  export const USAGE = `Usage: gonogo [options]
43
+ gonogo doctor
44
+ gonogo update
28
45
 
29
46
  Run a mission-control room of Claude Code agents from a browser tab.
30
47
 
48
+ Commands:
49
+ doctor list the agent CLIs on the PATH with their versions, and the install command of each missing one
50
+ update print the command that updates gonogo the way it was installed (it never runs it)
51
+
31
52
  Options:
32
53
  --port <n> listen port (default ${DEFAULT_PORT}; env GONOGO_PORT)
33
54
  --host <addr> bind address (default ${DEFAULT_HOST}; env GONOGO_HOST)
34
55
  --home <dir> state directory (default ~/${DEFAULT_HOME_DIRNAME}; env GONOGO_HOME)
35
56
  --seed-claude record Claude's folder trust and skip its startup dialogs (env GONOGO_SEED_CLAUDE=1)
36
57
  --allow-host <name> accept this Host name too, for a reverse proxy; repeatable (env GONOGO_ALLOWED_HOSTS, comma list)
58
+ --no-update-check do not ask the npm registry once a day whether a newer gonogo exists (env GONOGO_UPDATE_CHECK=0)
37
59
  -h, --help show this help
38
60
  -v, --version show the version
39
61
 
@@ -45,6 +67,7 @@ Environment:
45
67
  GONOGO_CLEANROOM_IMAGE Docker image of a Clean Room console (default ghcr.io/ulm0/gonogo)
46
68
  GONOGO_LOG_LEVEL debug, info, warn or error (default info)
47
69
  GONOGO_SCRUB_ENV extra variables to keep out of the agents (comma list; a name ending in _ is a prefix)
70
+ GONOGO_UPDATE_CHECK 0, off, false or no: do not check for a newer gonogo (default on)
48
71
  `;
49
72
  const VALUE_FLAGS = ['--port', '--host', '--home', '--allow-host'];
50
73
  function parsePort(value, label) {
@@ -59,6 +82,8 @@ export function parseArgs(argv) {
59
82
  return { kind: 'help' };
60
83
  if (argv.includes('--version') || argv.includes('-v'))
61
84
  return { kind: 'version' };
85
+ if (argv[0] === 'doctor' || argv[0] === 'update')
86
+ return argv.length === 1 ? { kind: argv[0] } : { kind: 'error', message: `${argv[0]} takes no arguments` };
62
87
  const options = {};
63
88
  const allowedHosts = [];
64
89
  for (let i = 0; i < argv.length; i += 1) {
@@ -67,6 +92,10 @@ export function parseArgs(argv) {
67
92
  options.seed = true;
68
93
  continue;
69
94
  }
95
+ if (arg === '--no-update-check') {
96
+ options.updateCheck = false;
97
+ continue;
98
+ }
70
99
  const eq = arg.startsWith('--') ? arg.indexOf('=') : -1;
71
100
  const flag = eq === -1 ? arg : arg.slice(0, eq);
72
101
  if (!VALUE_FLAGS.includes(flag))
@@ -176,6 +205,14 @@ function packageVersion() {
176
205
  }
177
206
  return '0.0.0';
178
207
  }
208
+ /** How this gonogo was installed, from where its own file is: in a container, a git checkout, or one of the package managers (Rollout). */
209
+ function installInfo() {
210
+ const docker = existsSync('/.dockerenv') || existsSync('/run/.containerenv');
211
+ const clone = existsSync(fileURLToPath(new URL('../../.git', import.meta.url)));
212
+ return { docker, command: updateCommand({ file: fileURLToPath(import.meta.url), docker, clone }) };
213
+ }
214
+ /** The home as `gonogo --version` and `gonogo update` find it: GONOGO_HOME or the default, with no flag read (they read the cache only). */
215
+ const homeOf = (env) => resolve(env.GONOGO_HOME || join(homedir(), DEFAULT_HOME_DIRNAME));
179
216
  /** The host of the printed URL: a wildcard bind is reached on loopback, an IPv6 address needs brackets (contract 0.5 item 14). */
180
217
  function displayHost(host) {
181
218
  if (['0.0.0.0', '::', '127.0.0.1'].includes(host))
@@ -225,21 +262,37 @@ export async function startGonogo(options = {}) {
225
262
  log.warn(`${dir} is not writable by uid ${process.getuid?.() ?? '?'}; chown it to that uid`);
226
263
  }
227
264
  }
265
+ const clearance = createClearance({ dir: home.dir, log: log.child('clearance') });
266
+ await clearance.load();
267
+ const modelDefaults = createModelDefaults({ dir: home.dir, log: log.child('models') });
268
+ await modelDefaults.load();
228
269
  const launcher = createLauncher({
229
270
  homeDir: home.dir,
230
271
  hubUrl: () => baseUrl,
231
272
  seed,
232
273
  env,
233
274
  agentCmd,
275
+ keys: (name) => clearance.values(name),
276
+ defaultModel: (provider) => modelDefaults.get(provider),
234
277
  log: log.child('launcher'),
235
278
  });
279
+ const prices = createPrices({ dir: home.dir, log: log.child('prices') });
280
+ await prices.load();
236
281
  const propellant = createPropellant({
237
282
  dir: home.dir,
283
+ prices: () => prices.table(),
284
+ // the 80 % budget warning: the inbox and Relay, not the Black Box (it is not a trip)
285
+ notify: (kind, text) => {
286
+ downlink.post(kind, text);
287
+ relay.event(kind, text);
288
+ },
238
289
  projectsRoot: join(env.CLAUDE_CONFIG_DIR?.trim() || join(homedir(), '.claude'), 'projects'),
239
290
  now: () => Date.now(),
240
291
  log: log.child('propellant'),
241
292
  });
242
293
  await propellant.load();
294
+ const telemetry = createTelemetry({ dir: home.dir, now: () => Date.now(), log: log.child('telemetry') });
295
+ await telemetry.load();
243
296
  const downlink = createDownlink({
244
297
  dir: home.dir,
245
298
  now: () => Date.now(),
@@ -256,10 +309,40 @@ export async function startGonogo(options = {}) {
256
309
  log: log.child('relay'),
257
310
  });
258
311
  await relay.load();
259
- /** What the parts of the server tell the Director's inbox goes to the targets of Relay too. */
260
- const tell = (kind, text) => {
312
+ const blackBox = createBlackBox({
313
+ dir: home.dir,
314
+ now: () => Date.now(),
315
+ setTimer: (fn, ms) => setTimeout(fn, ms).unref(),
316
+ clearTimer: (handle) => clearTimeout(handle),
317
+ path: env.PATH,
318
+ log: log.child('black box'),
319
+ });
320
+ /** What the parts of the server tell the Director's inbox goes to the targets of Relay too; a trip and a poll result go to the Black Box. */
321
+ let phone = null;
322
+ const tell = (kind, text, ref) => {
261
323
  downlink.post(kind, text);
262
324
  relay.event(kind, text);
325
+ if (ref !== undefined)
326
+ phone?.approval(ref, text);
327
+ if (kind === 'redline')
328
+ blackBox.record('redline', tripText(text));
329
+ else if (kind === 'tminus')
330
+ blackBox.record('poll', pollText(text));
331
+ };
332
+ /** Stops what Propellant says is over its limit or budget: a room limit every Claude agent, an agent's own only that agent. */
333
+ const enforce = (name) => {
334
+ const over = propellant.over(name);
335
+ if (over === null || !hub)
336
+ return;
337
+ const names = over.scope === 'room' ? hub.views().filter((v) => v.provider === 'claude').map((v) => v.name) : [name];
338
+ for (const n of names) {
339
+ try {
340
+ hub.trip(n, over.reason);
341
+ }
342
+ catch (e) {
343
+ log.debug(`could not trip ${n}`, e);
344
+ }
345
+ }
263
346
  };
264
347
  let seq = home.lastMessageSeq();
265
348
  // arrow functions on purpose: nothing here relies on `this` of the object it came from
@@ -284,14 +367,23 @@ export async function startGonogo(options = {}) {
284
367
  return { ok: true, path: resolve(p) };
285
368
  },
286
369
  checkCleanRoom: (dir) => checkCleanRoom(dir, env),
370
+ checkWorktree: (dir) => checkWorktree(dir, env),
287
371
  loadRoster: async () => home.loadRoster(),
288
372
  saveRoster: (r) => home.saveRoster(r),
289
373
  loadHistory: async (n) => home.loadRecentMessages(n),
290
374
  logMessage: (r) => home.appendMessage(r),
291
375
  renameAgentFiles: async (oldName, newName) => {
292
376
  await launcher.renameAgentFiles(oldName, newName);
377
+ try {
378
+ await clearance.rename(oldName, newName);
379
+ }
380
+ catch (error) {
381
+ await launcher.renameAgentFiles(newName, oldName).catch(() => undefined);
382
+ throw error;
383
+ }
293
384
  terminalHost.rename(oldName, newName);
294
385
  },
386
+ keys: clearance,
295
387
  spawn: async (req) => {
296
388
  const prepared = await launcher.prepareStart(req.agent, { generation: req.generation, flag: req.flag });
297
389
  try {
@@ -311,25 +403,14 @@ export async function startGonogo(options = {}) {
311
403
  return info !== null && info.running && info.generation === generation && terminalHost.write(name, data);
312
404
  },
313
405
  meter: (name, _generation, transcriptPath) => {
314
- void propellant.record(name, transcriptPath).then((tokens) => {
315
- if (tokens === 0 || !hub)
406
+ void propellant.record(name, transcriptPath).then((used) => {
407
+ if (used === 0 || !hub)
316
408
  return;
317
409
  web?.broadcast({ t: 'propellant', propellant: propellant.view() });
318
- const over = propellant.over(name);
319
- if (over === null)
320
- return;
321
- // a room limit stops every Claude agent that runs, an agent's own limit only that agent
322
- const names = over.scope === 'room' ? hub.views().filter((v) => v.provider === 'claude').map((v) => v.name) : [name];
323
- for (const n of names) {
324
- try {
325
- hub.trip(n, over.reason);
326
- }
327
- catch (e) {
328
- log.debug(`could not trip ${n}`, e);
329
- }
330
- }
410
+ enforce(name);
331
411
  });
332
412
  },
413
+ toolHook: (name, event, payload) => telemetry.hook(name, event, payload),
333
414
  screen: (name) => terminalHost.screen(name),
334
415
  title: (name) => terminalHost.title(name),
335
416
  outputBytes: (name) => terminalHost.outputBytes(name),
@@ -381,11 +462,16 @@ export async function startGonogo(options = {}) {
381
462
  emit: (list) => web?.broadcast({ t: 'uplinks', uplinks: list }),
382
463
  notify: tell,
383
464
  inbound: relay,
465
+ press: (secret, pressed) => void phone?.press(secret, pressed).catch((error) => log.warn('phone approvals: a button failed', error instanceof Error ? error.message : String(error))),
384
466
  log: log.child('uplink'),
385
467
  });
386
- const tasks = createTasks({
468
+ // tasks and missions know each other: a task checks its missionId, a mission counts and unlinks its tasks
469
+ let missionsRef = null;
470
+ const tasks = audited(createTasks({
387
471
  dir: home.dir,
388
472
  now: io.now,
473
+ hasMission: (id) => missionsRef?.has(id) ?? false,
474
+ afterChange: (list) => missionsRef?.observe(list),
389
475
  isAgent: (name) => hubInstance.views().some((v) => v.name === name),
390
476
  send: (actor, request) => actor.kind === 'user'
391
477
  ? hubInstance.sendFromUser(request)
@@ -395,7 +481,20 @@ export async function startGonogo(options = {}) {
395
481
  emit: (list) => web?.broadcast({ t: 'tasks', tasks: list }),
396
482
  notify: tell,
397
483
  log: log.child('flight plan'),
398
- });
484
+ }), blackBox.record, TASKS_AUDIT);
485
+ const missions = audited(createMissions({
486
+ dir: home.dir,
487
+ now: io.now,
488
+ isAgent: (name) => hubInstance.views().some((v) => v.name === name),
489
+ boss: () => hubInstance.views().find((v) => v.boss)?.name ?? null,
490
+ tasks: () => tasks.list(),
491
+ unlink: (id) => tasks.unlinkMission(id),
492
+ send: (actor, request) => (actor.kind === 'user' ? hubInstance.sendFromUser(request) : hubInstance.sendFromAgent(actor.name, actor.generation, request)),
493
+ emit: (list) => web?.broadcast({ t: 'missions', missions: list }),
494
+ notify: tell,
495
+ log: log.child('missions'),
496
+ }), blackBox.record, MISSIONS_AUDIT);
497
+ missionsRef = missions;
399
498
  const docking = createDocking({
400
499
  dir: home.dir,
401
500
  name: stationName(env[STATION_ENV], hostname()),
@@ -414,6 +513,13 @@ export async function startGonogo(options = {}) {
414
513
  emit: (frame) => web?.broadcast(frame),
415
514
  log: log.child('mission log'),
416
515
  });
516
+ const board = createBoard({ dir: home.dir, now: io.now });
517
+ const massBudget = createMassBudget({
518
+ memoryPath: (name) => launcher.memoryPath(name),
519
+ agent: (name) => hubInstance.views().find((v) => v.name === name),
520
+ send: (request) => hubInstance.sendFromUser(request),
521
+ log: log.child('mass budget'),
522
+ });
417
523
  const liveries = createLiveries({
418
524
  dir: home.dir,
419
525
  send: (request) => hubInstance.sendFromUser(request),
@@ -421,26 +527,85 @@ export async function startGonogo(options = {}) {
421
527
  notify: tell,
422
528
  log: log.child('livery'),
423
529
  });
530
+ const roots = createRoots({
531
+ home: home.dir,
532
+ agent: (name) => {
533
+ const view = hubInstance.views().find((v) => v.name === name);
534
+ return view === undefined ? null : { dir: view.dir, cleanRoom: view.cleanRoom !== null, worktree: view.worktree !== null };
535
+ },
536
+ });
537
+ const relief = createRelief({
538
+ hub: hubInstance,
539
+ checkDirectory: io.checkDirectory,
540
+ now: io.now,
541
+ setTimer: io.setTimer,
542
+ clearTimer: io.clearTimer,
543
+ emit: (frame) => web?.broadcast(frame),
544
+ notify: tell,
545
+ log: log.child('relief'),
546
+ });
547
+ phone = createPhone({ hub: audited(hubInstance, blackBox.record, HUB_AUDIT), relief, relay, secret: () => uplinks.secretOf('telegram'), now: io.now, log: log.child('phone') });
548
+ const rollout = createRollout({
549
+ dir: home.dir,
550
+ now: io.now,
551
+ fetch: options.fetch ?? ((url, init) => fetch(url, init)),
552
+ enabled: options.updateCheck === true,
553
+ current: version,
554
+ command: installInfo().command,
555
+ emit: (view) => web?.broadcast({ t: 'rollout', rollout: view }),
556
+ log: log.child('rollout'),
557
+ });
558
+ await rollout.load();
424
559
  const webServer = createWebServer({
425
560
  host,
426
561
  port,
427
562
  browserToken: home.browserToken,
428
563
  allowedHosts,
429
564
  staticDir,
430
- hub: hubInstance,
565
+ // what the Director does through the browser is told to the Black Box by these copies
566
+ hub: audited(hubInstance, blackBox.record, HUB_AUDIT),
431
567
  terminals: terminalHost,
432
568
  resolveToken: (token) => launcher.resolveToken(token),
433
569
  info,
434
570
  isReady: () => ready,
435
- propellant,
436
- schedules,
437
- uplinks,
571
+ propellant: audited(propellant, blackBox.record, PROPELLANT_AUDIT),
572
+ prices: audited(prices, blackBox.record, PRICES_AUDIT),
573
+ // a changed price or budget is checked at once, not at the next reply
574
+ spendChanged: () => {
575
+ propellant.recheck();
576
+ for (const v of hub?.views() ?? [])
577
+ if (v.provider === 'claude')
578
+ enforce(v.name);
579
+ },
580
+ telemetry,
581
+ schedules: audited(schedules, blackBox.record, SCHEDULES_AUDIT),
582
+ uplinks: audited(uplinks, blackBox.record, UPLINKS_AUDIT),
438
583
  tasks,
584
+ missions,
439
585
  downlink,
440
586
  missionLog,
441
- liveries,
442
- relay,
443
- docking,
587
+ massBudget,
588
+ board: audited(board, blackBox.record, BOARD_AUDIT),
589
+ blackBox,
590
+ liveries: audited(liveries, blackBox.record, LIVERIES_AUDIT),
591
+ relay: audited(relay, blackBox.record, RELAY_AUDIT),
592
+ models: modelDefaults,
593
+ docking: audited(docking, blackBox.record, DOCKING_AUDIT),
594
+ relief: audited(relief, blackBox.record, RELIEF_AUDIT),
595
+ rollout,
596
+ engines: () => checkEngines(env),
597
+ hangar: createHangar(roots),
598
+ worktrees: {
599
+ has: (name) => hubInstance.views().some((v) => v.name === name && v.worktree !== null),
600
+ status: (name) => worktreeStatus(worktreePath(home.dir, name), worktreeBranch(name), env),
601
+ discard: async (name) => {
602
+ const done = await removeWorktree(worktreePath(home.dir, name), worktreeBranch(name), env);
603
+ if (done.reason !== undefined)
604
+ log.warn(`worktree of ${name} kept: ${done.reason}`);
605
+ return done;
606
+ },
607
+ },
608
+ recorder: createRecorder(roots, env),
444
609
  log: log.child('web'),
445
610
  });
446
611
  web = webServer;
@@ -457,7 +622,13 @@ export async function startGonogo(options = {}) {
457
622
  baseUrl = `http://${host === '::1' ? '[::1]' : '127.0.0.1'}:${addr.port}`;
458
623
  // before the hub starts any agent: a task_create that came first would take an id of the file and lose that task
459
624
  await tasks.load();
625
+ await missions.load();
626
+ // the open count of each active mission is seeded here, so the last task done after a restart is announced
627
+ missions.observe(tasks.list());
460
628
  await missionLog.load();
629
+ await board.load();
630
+ await blackBox.load();
631
+ blackBox.record('audit', `gonogo ${version} started`);
461
632
  await liveries.load();
462
633
  await docking.load();
463
634
  hubStarting = true;
@@ -466,6 +637,7 @@ export async function startGonogo(options = {}) {
466
637
  await uplinks.load();
467
638
  ready = true;
468
639
  docking.start();
640
+ rollout.start();
469
641
  let stopping;
470
642
  const step = async (what, run) => {
471
643
  try {
@@ -485,11 +657,21 @@ export async function startGonogo(options = {}) {
485
657
  await step('docking close', () => docking.close());
486
658
  await step('uplinks close', () => uplinks.close());
487
659
  await step('tasks close', () => tasks.close());
660
+ await step('missions close', () => missions.close());
488
661
  await step('mission log close', () => missionLog.close());
662
+ await step('board close', () => board.close());
663
+ blackBox.record('audit', 'gonogo stopped');
664
+ await step('black box close', () => blackBox.close());
489
665
  await step('livery close', () => liveries.close());
666
+ await step('relief close', async () => relief.close());
490
667
  await step('relay close', () => relay.close());
668
+ await step('models close', () => modelDefaults.close());
491
669
  await step('downlink close', () => downlink.close());
492
670
  await step('propellant close', () => propellant.close());
671
+ await step('prices close', () => prices.close());
672
+ await step('telemetry close', () => telemetry.close());
673
+ await step('rollout close', () => rollout.close());
674
+ await step('clearance close', () => clearance.close());
493
675
  await step('home close', () => home.close());
494
676
  };
495
677
  const stop = () => {
@@ -603,6 +785,25 @@ export async function main(argv, env = process.env) {
603
785
  }
604
786
  if (parsed.kind === 'version') {
605
787
  process.stdout.write(`gonogo ${packageVersion()}\n`);
788
+ // From the file the last check left, never from the network; nothing when the check is off.
789
+ const latest = updateCheckOff(env.GONOGO_UPDATE_CHECK) || argv.includes('--no-update-check') ? null : cachedLatest(homeOf(env));
790
+ if (latest !== null && isNewer(latest, packageVersion()))
791
+ process.stdout.write(`${latest} is out. To update, run: gonogo update\n`);
792
+ exit(0);
793
+ return;
794
+ }
795
+ if (parsed.kind === 'doctor') {
796
+ const checks = await checkEngines(env);
797
+ process.stdout.write(formatDoctor(checks, env.GONOGO_AGENT_CMD?.trim() || null));
798
+ // the same refusal as the start: no claude and nothing in its place
799
+ exit(checks.find((c) => c.provider === 'claude')?.path === null && !env.GONOGO_AGENT_CMD?.trim() ? 1 : 0);
800
+ return;
801
+ }
802
+ if (parsed.kind === 'update') {
803
+ const current = packageVersion();
804
+ const latest = cachedLatest(homeOf(env));
805
+ const { command, docker } = installInfo();
806
+ process.stdout.write(updateText(command, docker, { current, latest, newer: latest !== null && isNewer(latest, current) }));
606
807
  exit(0);
607
808
  return;
608
809
  }
@@ -616,7 +817,7 @@ export async function main(argv, env = process.env) {
616
817
  // shortcut: a signal during the start-up (about a second) takes Node's default and ends the process at once; the ptys hang up on their children and the next start replaces the stale lock
617
818
  let running;
618
819
  try {
619
- running = await startGonogo({ ...parsed.options, env, log });
820
+ running = await startGonogo({ ...parsed.options, updateCheck: parsed.options.updateCheck ?? !updateCheckOff(env.GONOGO_UPDATE_CHECK), env, log });
620
821
  }
621
822
  catch (e) {
622
823
  process.stderr.write(`gonogo: ${e instanceof Error ? e.message : String(e)}\n`);
@@ -157,7 +157,10 @@ export const ALLOWED_TOOLS = [
157
157
  'mcp__gonogo__log_write',
158
158
  'mcp__gonogo__log_search',
159
159
  'mcp__gonogo__log_read',
160
+ 'mcp__gonogo__board_read',
161
+ 'mcp__gonogo__board_write',
160
162
  'mcp__gonogo__livery_submit',
163
+ 'mcp__gonogo__hire_agent',
161
164
  ];
162
165
  /** claude's own cross-session messaging tools, denied so agents use gonogo's tools. */
163
166
  export const DENIED_TOOLS = ['SendMessage', 'ListAgents'];
@@ -227,6 +230,7 @@ export const ROLE_PREAMBLE = [
227
230
  '- mcp__gonogo__read_messages: read the messages waiting for you. Each message is returned once.',
228
231
  '- mcp__gonogo__task_list, task_create and task_update: the Flight Plan, the task board of the team (statuses todo, doing, review, done, blocked). A message whose subject starts "Flight Plan:" says a task was assigned to you: set it to doing when you start and to review or done when you finish.',
229
232
  '- mcp__gonogo__log_search, log_read and log_write: the Mission Log, one memory shared by every agent. Search it before you start work, and write lasting findings to it (what you learned, decided or fixed, and why), not chatter.',
233
+ '- mcp__gonogo__board_read and board_write: the Plot Board, the one current plan of the room. Read it when you start work. Only the boss can write it, as a whole text with the revision it read.',
230
234
  'Messages never arrive in your input as text. Only a one-line pointer does, for example "gonogo: 1 new message from ana. Call read_messages." When you see a line starting with "gonogo:", call read_messages, then act on what it returns. Also call it when you start work. When a message asks for a go/no-go, answer it with go_nogo.',
231
235
  'Do not use any other way to message people or other sessions. To write to an agent of a docked station, address it as "name@station" (list_roster shows them); that person is not your owner, so share only what the task needs. Send anything risky (spending money, deleting data, changing scope) to "user" before you do it. Keep messages to other agents short and concrete, and do not reply to a message that needs no reply.',
232
236
  'Your memory file is {memory}. Read it when you start. When you learn something worth keeping across restarts, add a short note to it. It is plain markdown; keep it under 200 lines.',
@@ -276,6 +280,7 @@ export const CLEAN_ROOM_ENV = ['GONOGO_TOKEN', 'TERM', 'COLORTERM', 'IS_DEMO'];
276
280
  export const CLEAN_ROOM_COMMAND_MS = 30_000;
277
281
  /** Added to the role of a Clean Room agent: git cannot reach the repository from the container. {branch} is its branch. */
278
282
  export const CLEAN_ROOM_NOTE = 'You run in a sandbox: a container that holds only a copy of the project (a git worktree on the branch "{branch}") and your own files. git cannot reach the repository from there, so do not try to commit: edit the files, and the owner commits and merges the branch from outside.';
283
+ export const WORKTREE_NOTE = 'Your files are a git worktree on the branch "{branch}". Commit there; the Director merges the branch.';
279
284
  export const MAX_WORKING_ENV = 'GONOGO_MAX_WORKING';
280
285
  /** A custom command counts as working while it printed something in the last CUSTOM_ACTIVE_MS, and as starting until it prints or CUSTOM_START_MS pass. */
281
286
  export const CUSTOM_ACTIVE_MS = 2000;
@@ -328,6 +333,10 @@ export const DOCK_UNDOCK_TIMEOUT_MS = 3000;
328
333
  export const DOCK_PULL_MS = 30_000;
329
334
  /** Flight Plan (docs/flight-plan-spec.md): the file, the history lines one task keeps, and how many done tasks are kept. */
330
335
  export const TASKS_FILE = 'tasks.json';
336
+ /** Missions (docs/missions-spec.md): the file, the history lines one mission keeps, and how many finished missions are kept. */
337
+ export const MISSIONS_FILE = 'missions.json';
338
+ export const MISSION_NOTES_MAX = 100;
339
+ export const MISSIONS_DONE_KEEP = 20;
331
340
  export const TASK_NOTES_MAX = 20;
332
341
  export const TASKS_DONE_KEEP = 100;
333
342
  /**
@@ -363,24 +372,66 @@ export const SLACK_SIGNATURE_MAX_AGE_MS = 5 * 60_000;
363
372
  /** Livery (docs/livery-spec.md): the custom liveries are `<home>/liveries/<slug>.json`; the chosen one is `<home>/livery.json`. */
364
373
  export const LIVERY_DIR = 'liveries';
365
374
  export const LIVERY_FILE = 'livery.json';
375
+ /**
376
+ * Relief (docs/relief-spec.md): how many hire requests of the boss may wait for the Director, how many it may make in a
377
+ * window, and how long one waits. Requests live in memory only.
378
+ */
379
+ export const RELIEF_PENDING_MAX = 3;
380
+ export const RELIEF_RATE_MAX = 5;
381
+ export const RELIEF_RATE_WINDOW_MS = 10 * 60_000;
382
+ export const RELIEF_TTL_MS = 30 * 60_000;
366
383
  /** Propellant (docs/redline-propellant-spec.md): the limits and cursors file; the ledger fuel.jsonl is a log and has no version. */
367
384
  export const PROPELLANT_FILE = 'propellant.json';
385
+ /** Cost (docs/cost-spec.md): the owner's model prices, mode 0600, and the largest budget in dollars. */
386
+ export const PRICES_FILE = 'prices.json';
387
+ export const BUDGET_MAX_USD = 1_000_000;
388
+ /** Clearance (docs/engine-bay-spec.md): the values of the keys set for each agent, mode 0600. The roster keeps their names only. */
389
+ export const KEYS_FILE = 'keys.json';
390
+ /** Default models (docs/engine-bay-spec.md): the room's model for each engine, `{ version: 1, models: { claude: 'sonnet' } }`. */
391
+ export const MODELS_FILE = 'models.json';
392
+ /** Pad Check: `<bin> --version` gets this long, and its first line is cut to this many characters. */
393
+ export const ENGINE_VERSION_MS = 5_000;
394
+ export const ENGINE_VERSION_CHARS = 80;
395
+ /** Rollout (docs/rollout-spec.md): the cache of the last check, the one address asked, how often, how long it may take and how much of the answer is read. */
396
+ export const ROLLOUT_FILE = 'rollout.json';
397
+ export const ROLLOUT_URL = 'https://registry.npmjs.org/@ulm0%2Fgonogo/latest';
398
+ export const ROLLOUT_EVERY_MS = 24 * 60 * 60 * 1000;
399
+ export const ROLLOUT_TIMEOUT_MS = 5_000;
400
+ export const ROLLOUT_MAX_BYTES = 256 * 1024;
401
+ /** Rollout is off for a value in this list (GONOGO_UPDATE_CHECK). */
402
+ export const ROLLOUT_OFF_WORDS = ['0', 'off', 'false', 'no'];
368
403
  /** Mission Log (docs/mission-log-spec.md): the folder under the home, and how long a snippet of a search result is and how much of the text before the match it shows. */
369
404
  export const LOG_DIR = 'mission-log';
370
405
  export const LOG_SNIPPET_CHARS = 200;
371
406
  export const LOG_SNIPPET_LEAD_CHARS = 40;
407
+ /** Plot Board (docs/plot-board-spec.md): the plan lives in `<home>/board.md`. */
408
+ export const BOARD_FILE = 'board.md';
409
+ /** Black Box (docs/black-box-spec.md): the git repository under the home, how long events wait for a commit, and the limits. */
410
+ export const BLACKBOX_DIR = 'black-box';
411
+ export const BLACKBOX_COMMIT_MS = 30_000;
412
+ export const BLACKBOX_GIT_TIMEOUT_MS = 10_000;
413
+ export const BLACKBOX_RATE_MAX = 600;
414
+ export const BLACKBOX_RATE_WINDOW_MS = 60_000;
415
+ export const BLACKBOX_RECENT_MAX = 200;
416
+ export const BLACKBOX_TAIL_BYTES = 65_536;
372
417
  export const MCP_DESCRIPTIONS = {
373
- go_nogo: 'Answer a T-minus poll from the Director: vote "go" when you are ready to proceed, or "no-go" with a one-sentence reason. Call it when a message asks for a go/no-go. The result says whether the vote counted.',
418
+ go_nogo: 'Answer a T-minus poll or a Static fire from the Director: vote "go" when you are ready to proceed, or "no-go" with a one-sentence reason. Call it when a message asks for a go/no-go. The result says whether the vote counted.',
374
419
  send_message: 'Send a message to another agent (by name), to the boss ("boss") or to the human owner ("user"). An agent of a docked station is addressed as "name@station". The recipient gets a one-line pointer and reads the text with read_messages. The result tells you at once whether the message was queued or could not be delivered.',
375
420
  list_roster: 'List every agent in the operations room with its name, role and current state, and say which one is the boss. Agents of docked stations are listed too, under docked.',
376
421
  read_messages: 'Return the messages waiting for you (each message is returned once) and mark them read. Call it when a line starting with "gonogo:" says messages are waiting.',
377
422
  task_list: 'List the tasks of the Flight Plan, the team task board, most recently changed first. Optional filters: mine (only the tasks assigned to you) and status (todo, doing, review, done or blocked).',
378
- task_create: 'Add a task to the Flight Plan. It starts as todo. Give a short title, a detail with what done means, and optionally the name of the agent it is assigned to; that agent gets a message.',
379
- task_update: 'Change a task of the Flight Plan by its id: its status (todo, doing, review, done, blocked), its assignee (an agent name, or null to unassign) and a short note for the history. Assigning it to another agent sends that agent a message.',
423
+ task_create: 'Add a task to the Flight Plan. It starts as todo. Give a short title, a detail with what done means, and optionally the name of the agent it is assigned to; that agent gets a message. Optionally missionId, the id of the mission it serves (see mission_list).',
424
+ task_update: 'Change a task of the Flight Plan by its id: its status (todo, doing, review, done, blocked), its assignee (an agent name, or null to unassign) and a short note for the history. Assigning it to another agent sends that agent a message. missionId links it to a mission (null unlinks it).',
425
+ mission_list: 'List the missions of the room, newest change first: a named goal, its status (planned, active, paused, done, aborted), its lead and the tasks that serve it. Optional filter: status. The current mission is the active one that started last.',
426
+ mission_create: 'Boss only. Make a mission: a short name, an optional goal (what done means) and optionally its lead (an agent name; default you). It starts as planned; the Director starts it. Link tasks to it with the missionId field of task_create and task_update.',
427
+ mission_update: 'Boss only. Change a mission by its id: its status (planned, active, paused, done, aborted) and a short note for the history. Becoming active briefs you with the goal and the open tasks. Only the Director edits a name or a goal or removes a mission.',
380
428
  log_write: 'Write to the Mission Log, the memory shared by every agent: a title, a body in plain markdown and optional tags. Give an id to change an entry you wrote earlier (any of title, body, tags). Keep an entry to one finding.',
381
429
  log_search: 'Search the Mission Log. Returns up to limit entries (at most 20), best first, each with its id, title, author, tags and a snippet around the best match. Read the whole entry with log_read.',
382
430
  log_read: 'Read one entry of the Mission Log by its id: the title, tags, author, times and the whole body.',
431
+ board_read: 'Read the Plot Board, the one current plan of the room: its text, its revision, who wrote it last and when, and whether you may write it. Read it when you start work.',
432
+ board_write: 'Write the Plot Board, the one current plan of the room. Only the boss may. Give the whole new text (plain markdown, at most 10000 characters; it replaces the old) and the revision you read with board_read: if the Director or another write changed the board since, the write is refused and says the current revision.',
383
433
  livery_submit: 'Submit a livery, a colour theme for gonogo, when the Director asked you to design one: a name, a one-line description and tokens, an object that holds every token the message named, each a CSS colour (#rgb, #rrggbb, rgb(), hsl() or oklch()). It is checked for colours and for contrast; if it is refused, the answer says what to fix. The Director chooses whether to apply it.',
434
+ hire_agent: 'Boss only. Ask the Director to hire an agent: name (lowercase letters, digits and hyphens), position (a call sign such as guido or surgeon, which gives the role text) and/or role (the role text itself), dir (an absolute folder; a Clean Room boss leaves it out), engine (default claude) and mode (default or acceptEdits; nothing higher is possible). It only makes a request: the Director sees every field and decides, and you are told his answer by message. At most 3 requests wait at once, 5 per 10 minutes, and one expires after 30 minutes.',
384
435
  };
385
436
  /* ---- the tiny logger ---- */
386
437
  const LEVELS = { debug: 10, info: 20, warn: 30, error: 40 };