@ours.network/install 0.17.0-nightly.8 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/install.mjs CHANGED
@@ -2,16 +2,9 @@
2
2
  // ours.network — the unified `ours-install` experience (the real UX behind install.sh's thin
3
3
  // bootstrap, and the `ours-install` command once the stack is on the machine).
4
4
  //
5
- // ONE installer for the WHOLE stack — the shared ours daemon + the harness plugins (Claude Code /
6
- // Codex / Hermes) + ours-fleet + the Telegram connector + Rooms (ours-cowork) — for someone who
7
- // ALREADY has Claude, Codex, and/or Hermes.
8
- //
9
- // TOPOLOGY. Step 1 installs and configures ONE shared daemon and the user picks its listen port
10
- // there; every consumer below is wired to that endpoint. The Telegram connector may instead be
11
- // given its OWN daemon — its own port, state directory and boot unit — chosen independently, and
12
- // defaulting to the shared one so Enter and non-interactive runs keep the historical topology.
13
- // Rooms answers the same question, plus a third answer the connector has no use for: keeping
14
- // cowork's own EMBEDDED daemon, which is what every pre-PR#9 cowork install runs (see step 5).
5
+ // ONE installer for the WHOLE stack — ours core (the daemon) + the harness plugins (Claude Code /
6
+ // Codex / Hermes) + ours-fleet + the Telegram connector — for someone who ALREADY has Claude,
7
+ // Codex, and/or Hermes.
15
8
  // Its whole job: install the stack cleanly, then hand back ONE copy-paste prompt the user drops
16
9
  // into their agent to finish remaining configuration conversationally. Voice API credentials are
17
10
  // the one guided secret flow: interactive, masked, optional, and written atomically with mode 0600.
@@ -27,29 +20,21 @@
27
20
  import { spawn, spawnSync } from 'node:child_process';
28
21
  import { readFileSync, existsSync } from 'node:fs';
29
22
  import { homedir, userInfo, platform as osPlatform, release as osRelease } from 'node:os';
30
- import { join, resolve } from 'node:path';
23
+ import { join } from 'node:path';
31
24
  import { banner, heading, ok, info, warn, c, box, withSpinner, openTty, makeWriter, closeSync } from './lib/ui.mjs';
32
25
  import { askLine, askYesNo, isCancel } from './lib/prompt.mjs';
33
26
  import {
34
27
  suggestPort, parsePort, validateBroker, mergeConfig, parseVersion, parseStatus,
35
28
  detectPlatform, classifyHarnessProbe, buildHandoffPrompt,
36
- voiceSetupStatus, resolveSharedBroker, tgConfigPath, planTgDaemonConfig, daemonEndpoint,
29
+ voiceSetupStatus,
37
30
  DEFAULT_PORT, resolveChannel, pkgSpec,
38
- validateDaemonPort, planPorts, dedicatedDaemonPaths, DEDICATED_INSTANCES,
39
- coworkConfigPath, planCoworkConfig, COWORK_DEFAULT_PORT, coworkDaemonMode,
40
- coworkSupportsExternalDaemon, COWORK_EXTERNAL_MIN_VERSION,
41
31
  } from './lib/logic.mjs';
42
32
  import { atomicWriteConfig } from './lib/config.mjs';
43
- import { runNightlyInstaller } from './lib/nightly-install.mjs';
44
33
 
45
34
  const NPM = process.env.OURS_NPM || 'npm';
46
- // Release channel: OURS_CHANNEL=nightly installs each package's PRERELEASE dist-tag —
47
- // @nightly for mcp/tg-connector/fleet/the plugin launchers, and @latest for cowork,
48
- // and @next for cowork, whose repo has always called its prerelease line `next`
49
- // (see PKG_CHANNEL_TAGS in lib/logic.mjs). With no explicit
50
- // selection the installer follows its OWN channel, so a nightly installer builds a
51
- // nightly stack instead of silently mixing tags across an architecture boundary.
52
- const CHANNEL = resolveChannel(process.env.OURS_CHANNEL || process.env.OURS_INSTALL_CHANNEL, pkgVersion());
35
+ // Release channel: OURS_CHANNEL=nightly installs @nightly for mcp/tg-connector/plugin
36
+ // launchers but keeps @ours.network/fleet at @latest (fleet has no nightly). Default: latest.
37
+ const CHANNEL = resolveChannel(process.env.OURS_CHANNEL || process.env.OURS_INSTALL_CHANNEL);
53
38
  const spec = (pkgKey) => pkgSpec(pkgKey, CHANNEL); // → "@ours.network/<key>@<tag>"
54
39
  let DRY = !!process.env.OURS_INSTALL_DRY_RUN;
55
40
  const SELFHOST_URL = 'ours.network';
@@ -61,11 +46,10 @@ const line = (s = '') => sink(`${s}\n`);
61
46
  const say = (s) => sink(`ours: ${s}\n`);
62
47
 
63
48
  // --- external command helpers (never throw; the installer degrades, it doesn't crash) ----------
64
- function run(bin, args, { capture = false, timeout, env } = {}) {
49
+ function run(bin, args, { capture = false, timeout } = {}) {
65
50
  const r = spawnSync(bin, args, {
66
51
  encoding: 'utf8',
67
52
  timeout,
68
- env: env ? { ...process.env, ...env } : process.env,
69
53
  stdio: capture ? ['ignore', 'pipe', 'pipe'] : 'inherit',
70
54
  });
71
55
  const timedOut = !!(r.error && (r.error.code === 'ETIMEDOUT' || r.signal === 'SIGTERM'));
@@ -103,30 +87,16 @@ async function actSpin(label, desc, fn) {
103
87
 
104
88
  // --- daemon probes (always safe to run — read-only) --------------------------------------------
105
89
  const daemonVersionLine = () => (run('ours-mcp', ['--version'], { capture: true }).out.split('\n')[0] || '').trim();
106
- const daemonStatusText = (env) => run('ours-mcp', ['status'], { capture: true, ...(env ? { env } : {}) }).out;
90
+ const daemonStatusText = () => run('ours-mcp', ['status'], { capture: true }).out;
107
91
  function daemonLifecycleState() {
108
92
  const status = run('ours-mcp', ['status'], { capture: true });
109
93
  if (!status.ok) return 'stopped';
110
94
  return /^\s*pid:\s*\d+/m.test(status.out) ? 'managed' : 'external';
111
95
  }
112
96
  const daemonRunning = () => daemonLifecycleState() !== 'stopped';
113
- // LISTENING, not merely alive — and the difference is not academic. `ours-mcp start`
114
- // exits 0 when it only FINDS a live pid in the state directory (core cmdStart: it
115
- // checks `isAlive(pid)` and nothing else, so a pid file left by a previous boot whose
116
- // number now belongs to any other process reads as "already running"). `ours-mcp
117
- // status` then exits 0 for that same pid while printing "(port not answering!)" —
118
- // core cmdStatus only sets a non-zero exit for the no-pid case. So neither exit code
119
- // proves a daemon is there, and a readiness line built from one can tell the user
120
- // "ready — no problems" about a port nothing is bound to. The status line the daemon
121
- // prints only when the port actually answered is the honest signal, so use it.
122
- const daemonReachable = (env) => /\(reachable\)/.test(daemonStatusText(env));
123
- // The installed version of a global package, INCLUDING any prerelease suffix. The
124
- // suffix is not cosmetic here: the Rooms daemon guard compares against an exact
125
- // `0.4.1-nightly.<date>.<sha>` floor, and truncating at the dash would make every
126
- // 0.4.1 nightly look alike — including ones published before the mode existed.
127
97
  const globalVersion = (pkg) => {
128
98
  const ls = run(NPM, ['ls', '-g', pkg], { capture: true }).out;
129
- const m = ls.match(new RegExp(pkg.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&') + '@(\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?)'));
99
+ const m = ls.match(new RegExp(pkg.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&') + '@([0-9][0-9.]*)'));
130
100
  return m ? m[1] : '';
131
101
  };
132
102
 
@@ -139,18 +109,6 @@ function writeConfigPatch(patch) {
139
109
  return p;
140
110
  }
141
111
 
142
- // The daemon's state directory, resolved exactly the way packages/core/src/config.ts
143
- // resolves it (env > config file > ~/.ours). The Telegram connector needs the ABSOLUTE
144
- // path: the SDK reads the daemon's API token from it and refuses to send that token to
145
- // a separately-chosen endpoint unless the state dir was chosen just as deliberately.
146
- function daemonStateDir() {
147
- const fromEnv = process.env.OURS_STATE_DIR?.trim();
148
- if (fromEnv) return resolve(fromEnv);
149
- const fromFile = readConfigObject().stateDir;
150
- if (typeof fromFile === 'string' && fromFile.trim()) return resolve(fromFile.trim());
151
- return join(homedir(), '.ours');
152
- }
153
-
154
112
  function daemonVoiceCapability() {
155
113
  const r = run('ours-mcp', ['voice-status', '--json'], { capture: true, timeout: 6000 });
156
114
  if (!r.ok) return null;
@@ -221,13 +179,10 @@ const USAGE = `ours-install — the unified ours.network stack installer.
221
179
 
222
180
  ours-install [--dry-run] [--help] [--version]
223
181
 
224
- Guided ~3-minute setup for the whole stack: the shared ours daemon (you pick its
225
- port), the harness plugins (Claude Code + Codex + Hermes), ours-fleet, the Telegram
226
- connector, and Rooms (ours-cowork) — then one copy-paste hand-off prompt. You approve
227
- each step; re-run any time to add a piece or update.
228
-
229
- Telegram can share the daemon from step 1 or be given its own (its own port, state
230
- directory and boot service); Enter keeps the shared one.
182
+ Guided ~3-minute setup for the whole stack: ours core (the daemon), the harness
183
+ plugins (Claude Code + Codex + Hermes), ours-fleet, and the Telegram connector — then one
184
+ copy-paste hand-off prompt. You approve each step; re-run any time to add a piece
185
+ or update.
231
186
 
232
187
  --dry-run walk the whole flow and print what it WOULD do — install/change nothing
233
188
  --help show this help and exit
@@ -317,16 +272,6 @@ async function main() {
317
272
  finish(ttyFd); return;
318
273
  }
319
274
 
320
- // HARD RELEASE BOUNDARY. Nightly owns the topology-first profile flow. The
321
- // latest/stable consumer-first implementation below remains untouched and
322
- // never reads or writes installer-profiles.json or emits --application.
323
- if (CHANNEL === 'nightly') {
324
- return runNightlyInstaller({
325
- harnesses, ttyFd, interactive, write, yes, ask, cont, dry: DRY,
326
- npm: NPM, run, runAsync, act, actSpin, finish,
327
- });
328
- }
329
-
330
275
  // Daemon state up front (decides first-install vs update, and whether Step 0 runs at all).
331
276
  const versionBefore = daemonVersionLine();
332
277
  const daemonInstalled = !!versionBefore;
@@ -336,44 +281,56 @@ async function main() {
336
281
  line('');
337
282
  cont();
338
283
 
284
+ // ============================================================================================
285
+ // STEP 0 — the two config questions (asked ONCE, up front). SKIPPED entirely when a daemon is
286
+ // already configured (update path reuses its port/broker; delta #1859).
287
+ // ============================================================================================
339
288
  const status0 = parseStatus(daemonStatusText());
340
289
  let chosenBroker; // undefined = keep default / existing
341
290
  let chosenPort = status0.port || DEFAULT_PORT;
342
291
  const configFirst = !daemonInstalled;
343
292
 
344
- // Every port this run has committed to, so a later daemon can't be handed one an
345
- // earlier daemon claimed. A live bind probe cannot see these — nothing is
346
- // listening on them yet — which is exactly why they're tracked by hand.
347
- const claimedPorts = [];
348
- // The finished topology, for the end-of-run cross-check. Each entry is one thing that
349
- // will try to BIND a port, named so a collision can be reported in the user's terms.
350
- const topology = [];
351
- const claimPort = (port, label) => {
352
- if (!Number.isInteger(port)) return;
353
- if (!claimedPorts.includes(port)) claimedPorts.push(port);
354
- if (label) topology.push({ label, port });
355
- };
293
+ if (configFirst) {
294
+ line(heading('A couple of quick settings'));
295
+ // 0a — broker (owner edit #1: SECURE wording; owner edit #2: self-host → website only).
296
+ line(info('Your agents connect through a "broker" — a shared meeting point that lets them find'));
297
+ line(info("each other. It's secure: your messages are end-to-end encrypted, so the broker never"));
298
+ line(info('sees what they say. Almost everyone uses the standard one — just press Enter.'));
299
+ const custom = yes(' Use a custom broker address?', false);
300
+ if (custom) {
301
+ line(info(`(Only needed if you run your own broker. More at ${SELFHOST_URL}.)`));
302
+ const entered = ask(' Enter the broker address: ', '');
303
+ const v = validateBroker(entered);
304
+ if (entered && v.ok && !v.empty) {
305
+ // Undo safety net: a mistaken custom entry is one keystroke back to the standard broker.
306
+ const keep = yes(` Use "${v.value}"? (No = go back to the standard broker)`, true);
307
+ if (keep) { chosenBroker = v.value; line(ok(`broker set to ${chosenBroker}.`)); }
308
+ else line(ok('using the standard broker.'));
309
+ } else {
310
+ if (entered) line(warn(`"${entered}" doesn't look like a ws:// address — using the standard broker.`));
311
+ else line(ok('using the standard broker.'));
312
+ }
313
+ } else {
314
+ line(ok('using the standard broker.'));
315
+ }
356
316
 
357
- // Ask for ONE daemon's port, validate it, and keep asking until the answer is
358
- // usable. Enter (and every non-interactive run) takes `def` unchanged — that is
359
- // what keeps the historical behaviour and scripted installs identical.
360
- const askDaemonPort = (prompt, def) => {
361
- let candidate = def;
362
- for (let attempt = 0; attempt < 3; attempt++) {
363
- const raw = ask(` ${prompt} ${c.gray(`[Enter for ${candidate}]`)}: `, String(candidate));
364
- const v = validateDaemonPort(raw, { fallback: candidate, isTaken: portTakenSync, taken: claimedPorts });
365
- if (v.ok) return v.port;
366
- line(warn(`${v.reason}.`));
367
- if (!interactive) break; // no one to re-ask; fall through to a suggestion
368
- candidate = suggestPort(v.port + 1, (p) => claimedPorts.includes(p) || portTakenSync(p));
369
- line(info(`Suggesting ${candidate} instead.`));
317
+ // 0b — port: probe 3050; only ask if busy. Minimize the concept.
318
+ if (!portTakenSync(DEFAULT_PORT)) {
319
+ chosenPort = DEFAULT_PORT;
320
+ line(ok(`Using local port ${DEFAULT_PORT}.`));
321
+ } else {
322
+ line(info(`The standard local port (${DEFAULT_PORT}) is already in use on your machine.`));
323
+ let candidate = suggestPort(DEFAULT_PORT + 1, portTakenSync);
324
+ const raw = ask(` Pick another number for the ours daemon? ${c.gray(`[Enter for ${candidate}]`)}: `, String(candidate));
325
+ const parsed = parsePort(raw, candidate);
326
+ candidate = suggestPort(parsed.ok ? parsed.port : candidate, portTakenSync);
327
+ chosenPort = candidate;
328
+ line(ok(`Using local port ${chosenPort}.`));
370
329
  }
371
- // Out of attempts (or headless): take the first genuinely free port rather
372
- // than persisting one we know is unusable.
373
- const fallback = suggestPort(candidate, (p) => claimedPorts.includes(p) || portTakenSync(p));
374
- line(ok(`Using port ${fallback}.`));
375
- return fallback;
376
- };
330
+ line('');
331
+ line(ok(`Config ready — broker: ${chosenBroker ? 'custom' : 'standard'}, port: ${chosenPort}.`));
332
+ cont();
333
+ }
377
334
 
378
335
  // Track outcomes for the summary + hand-off.
379
336
  const summary = [];
@@ -460,57 +417,13 @@ async function main() {
460
417
  };
461
418
 
462
419
  // ============================================================================================
463
- // STEP 1 / 5 — the SHARED ours daemon. Its own visible step, and it owns its own configuration
464
- // (broker + listen port) rather than a nameless "quick settings" preamble: every consumer below
465
- // is wired to the endpoint chosen HERE, so the choice belongs to the step that makes it.
466
- // Config-first within the step: choose → write config → optional voice → start ONCE.
420
+ // STEP 1 / 4 — ours core (the daemon). Config-first: write config → optional voice → start ONCE.
467
421
  // ============================================================================================
468
- line(heading('1/5 — the shared ours daemon'));
469
- line(info('This is the piece that lets your agents talk to each other securely. The harness'));
470
- line(info('plugins, ours-fleet and the Telegram connector all connect to it — Telegram can be'));
471
- line(info('given its own instead, later — and so can Rooms.'));
422
+ line(heading('1/4 — ours core (the daemon)'));
423
+ line(info('This is the piece that lets your agents talk to each other securely. Everything else'));
424
+ line(info('needs it.'));
472
425
  const before = parseVersion(versionBefore);
473
426
 
474
- if (configFirst) {
475
- // Broker (owner edit #1: SECURE wording; owner edit #2: self-host → website only).
476
- line('');
477
- line(info('Your agents connect through a "broker" — a shared meeting point that lets them find'));
478
- line(info("each other. It's secure: your messages are end-to-end encrypted, so the broker never"));
479
- line(info('sees what they say. Almost everyone uses the standard one — just press Enter.'));
480
- const custom = yes(' Use a custom broker address?', false);
481
- if (custom) {
482
- line(info(`(Only needed if you run your own broker. More at ${SELFHOST_URL}.)`));
483
- const entered = ask(' Enter the broker address: ', '');
484
- const v = validateBroker(entered);
485
- if (entered && v.ok && !v.empty) {
486
- // Undo safety net: a mistaken custom entry is one keystroke back to the standard broker.
487
- const keep = yes(` Use "${v.value}"? (No = go back to the standard broker)`, true);
488
- if (keep) { chosenBroker = v.value; line(ok(`broker set to ${chosenBroker}.`)); }
489
- else line(ok('using the standard broker.'));
490
- } else {
491
- if (entered) line(warn(`"${entered}" doesn't look like a ws:// address — using the standard broker.`));
492
- else line(ok('using the standard broker.'));
493
- }
494
- } else {
495
- line(ok('using the standard broker.'));
496
- }
497
-
498
- // Listen port. ALWAYS asked now, so the shared daemon's endpoint is a decision the
499
- // user makes rather than one they only hear about when 3050 happens to be busy.
500
- // The default is still 3050 (the next free port when it is taken), so Enter and
501
- // every non-interactive run land exactly where they always did.
502
- line('');
503
- line(info('The daemon listens on a local port. Everything else in this install is pointed at it.'));
504
- const portDefault = portTakenSync(DEFAULT_PORT) ? suggestPort(DEFAULT_PORT + 1, portTakenSync) : DEFAULT_PORT;
505
- if (portDefault !== DEFAULT_PORT) line(info(`The standard port (${DEFAULT_PORT}) is already in use on your machine.`));
506
- chosenPort = askDaemonPort('Which local port should the shared daemon use?', portDefault);
507
- line(ok(`Shared daemon: port ${chosenPort}, broker ${chosenBroker ? 'custom' : 'standard'}.`));
508
- line('');
509
- } else {
510
- line(ok(`Shared daemon already configured — port ${chosenPort}. Keeping it.`));
511
- }
512
- claimPort(chosenPort, 'the shared ours daemon');
513
-
514
427
  if (!daemonInstalled) {
515
428
  const goCore = yes(' Install and start it?', true);
516
429
  if (!goCore) {
@@ -526,24 +439,10 @@ async function main() {
526
439
  const voice = offerVoiceSetup({ readinessAfterStart: true });
527
440
  const started = await act(`ours-mcp start (port ${chosenPort})`, async () => run('ours-mcp', ['start']));
528
441
  const svc = await act('ours-mcp install-service (survives reboot)', async () => run('ours-mcp', ['install-service']));
529
- // `ours-mcp install-service` STOPS the daemon before it writes the unit (core's
530
- // cmdInstallService), then exits non-zero if `systemctl --user enable --now` fails —
531
- // no linger, no user bus, a container, WSL without systemd. Left alone that turns a
532
- // WORKING daemon into no daemon at all, while the line below still said "ready": the
533
- // human identity and every MCP client then fail against a port nothing is listening
534
- // on. Put the one shared daemon back up and report what is actually true.
535
- // `started.ok` is the exit code of `ours-mcp start`, which is not evidence that
536
- // anything is listening (see daemonReachable). Ask the daemon instead.
537
- let running = DRY ? started.ok : daemonReachable();
538
- if (!DRY && !svc.ok && !running) {
539
- line(info('the boot-service step stopped the daemon before it failed — restarting it.'));
540
- run('ours-mcp', ['start']);
541
- running = daemonReachable();
542
- }
543
- if (running) line(ok(`ours core ready — running on port ${chosenPort}. No problems.`));
442
+ if (started.ok) line(ok(`ours core ready — running on port ${chosenPort}. No problems.`));
544
443
  else line(warn(`could not auto-start — run '${c.cyan('ours-mcp start')}' to bring it up.`));
545
444
  if (!svc.ok && !svc.dry) line(warn(`boot-service not installed — retry '${c.cyan('ours-mcp install-service')}' later.`));
546
- if (voice.setupRan && !DRY && running) {
445
+ if (voice.setupRan && !DRY && started.ok) {
547
446
  const verified = daemonVoiceCapability();
548
447
  if (verified?.ready) {
549
448
  line(ok(`Voice transcription readiness confirmed (${verified.provider}) after the first start.`));
@@ -556,13 +455,7 @@ async function main() {
556
455
  }
557
456
  }
558
457
  }
559
- record({
560
- key: 'core',
561
- label: 'ours core (daemon)',
562
- state: running ? 'installed' : 'failed',
563
- version: parseVersion(daemonVersionLine()),
564
- note: svc.ok ? 'starts on boot' : 'running; no boot service',
565
- });
458
+ record({ key: 'core', label: 'ours core (daemon)', state: started.ok ? 'installed' : 'failed', version: parseVersion(daemonVersionLine()), note: 'starts on boot' });
566
459
  } else {
567
460
  // Installed: offer an update; never re-ask config; reuse the running port everywhere.
568
461
  const daemonState = daemonLifecycleState();
@@ -619,11 +512,9 @@ async function main() {
619
512
  line(ok(`Your human identity "${name}" is created.`));
620
513
  record({ key: 'identity', label: 'Human identity', state: 'installed', note: name });
621
514
  } else {
622
- // A freshly-started daemon may need a moment to BIND ITS PORT before create-root
623
- // can reach it — which is the one thing a liveness check cannot see, so this
624
- // waits on the port answering rather than on a process existing.
625
- let reachable = daemonReachable();
626
- for (let i = 0; i < 6 && !reachable; i++) { sleepMs(400); reachable = daemonReachable(); }
515
+ // A freshly-started daemon may need a moment to bind its port before create-root can reach it.
516
+ let reachable = daemonRunning();
517
+ for (let i = 0; i < 6 && !reachable; i++) { sleepMs(400); reachable = daemonRunning(); }
627
518
  const r = reachable ? run('ours-mcp', ['create-root', name], { capture: true }) : { ok: false, out: '', err: 'daemon not running' };
628
519
  const outText = `${r.out} ${r.err}`;
629
520
  const existing = outText.match(/already exists \("([^"]+)"\)/);
@@ -702,10 +593,10 @@ async function main() {
702
593
  }
703
594
 
704
595
  // ============================================================================================
705
- // STEP 2 / 5 — harness plugins (Claude Code + Codex + Hermes). The installer drives the plugin
596
+ // STEP 2 / 4 — harness plugins (Claude Code + Codex + Hermes). The installer drives the plugin
706
597
  // CLIs for Claude/Codex; Hermes installs via npm + ours-hermes-install (no CLI driving).
707
598
  // ============================================================================================
708
- line(heading('2/5 — harness plugins'));
599
+ line(heading('2/4 — harness plugins'));
709
600
  line(info('These teach Claude Code, Codex, and Hermes the ours skills, so you can just talk to your'));
710
601
  line(info("agent to message people and set things up. I'll install them for you — no commands to type."));
711
602
  for (const h of harnesses) {
@@ -718,21 +609,16 @@ async function main() {
718
609
  }
719
610
 
720
611
  // ============================================================================================
721
- // STEP 3 / 5 — ours-fleet. Appealing wording (owner edit #4); default YES.
612
+ // STEP 3 / 4 — ours-fleet. Appealing wording (owner edit #4); default YES.
722
613
  // ============================================================================================
723
- line(heading('3/5 — ours-fleet (your always-online agent team)'));
614
+ line(heading('3/4 — ours-fleet (your always-online agent team)'));
724
615
  line(info('This makes your harnesses PERSISTENT: Claude Code and Codex stop being just a terminal'));
725
616
  line(info('session and become always-online daemons that survive a reboot. Stand up your own team'));
726
617
  line(info('of always-online developers, combine harnesses, run several Claude Codes, and link them'));
727
618
  line(info('over Telegram so they talk to each other — and it all configures maximally easily.'));
728
619
  const goFleet = yes(' Install it?', true);
729
620
  if (goFleet) {
730
- // ours-fleet FOLLOWS the channel, like everything else here: it publishes its own
731
- // nightly dist-tag from adapt-toolkit/ours-fleet, and lib/logic.mjs maps it
732
- // accordingly. (This comment used to claim the opposite — that fleet had no nightly
733
- // tag and was pinned to @latest even under OURS_CHANNEL=nightly — which stopped
734
- // being true when the map gained its `fleet` entry. The code always followed the
735
- // map; only the comment was stale, which is the more dangerous of the two.)
621
+ // ours-fleet is ALWAYS @latest — it has no nightly tag (pkgSpec pins it even under OURS_CHANNEL=nightly).
736
622
  await actSpin(`installing ${spec('fleet')}…`, `npm i -g ${spec('fleet')}`, () => runAsync(NPM, ['i', '-g', spec('fleet')]));
737
623
  const init = await act('ours-fleet init (one-time host setup: units, dirs, linger)', async () => run('ours-fleet', ['init']));
738
624
  if (!init.ok) line(warn(`ours-fleet host setup didn't finish — retry '${c.cyan('ours-fleet init')}'.`));
@@ -753,147 +639,24 @@ async function main() {
753
639
  }
754
640
  cont(goFleet);
755
641
 
756
- // The broker the WHOLE deployment shares, whichever daemon a consumer talks to.
757
- const sharedBroker = () => resolveSharedBroker({
758
- chosenBroker,
759
- statusBroker: status0.broker,
760
- configBroker: readConfigObject().brokerUrl,
761
- });
762
-
763
- // Provision a daemon that belongs to ONE consumer: its own config file, its own
764
- // state directory, its own port, and — via core's OURS_SERVICE_NAME — its own boot
765
- // unit, so `install-service` cannot overwrite the shared daemon's. Returns the
766
- // endpoint + state dir to wire that consumer to, and whether it came up.
767
- async function provisionDedicatedDaemon({ instance, port, label }) {
768
- const { stateDir, configPath: cfgPath, serviceName } = dedicatedDaemonPaths(homedir(), instance);
769
- const env = { OURS_CONFIG: cfgPath, OURS_STATE_DIR: stateDir, OURS_SERVICE_NAME: serviceName };
770
- // The dedicated daemon has to exist as a package before it can be started; on a
771
- // fresh machine step 1 already installed it, but a re-run that skipped core has not.
772
- await actSpin(`ensuring ${spec('mcp')}…`, `npm i -g ${spec('mcp')}`, () => runAsync(NPM, ['i', '-g', spec('mcp')]));
773
- const desired = { port, stateDir, serviceName };
774
- const broker = sharedBroker();
775
- if (broker) desired.brokerUrl = broker;
776
- let existing = {};
777
- try { existing = JSON.parse(readFileSync(cfgPath, 'utf8')); } catch { /* absent or unreadable */ }
778
- const sameAlready = existing.port === port && existing.stateDir === stateDir && existing.serviceName === serviceName;
779
- if (sameAlready) {
780
- line(ok(`The ${label} daemon is already configured on port ${port} — no change.`));
781
- // Nothing to change AND it is already up: do not touch it. `install-service` STOPS
782
- // the daemon before rewriting the unit, so re-running it here would bounce a healthy
783
- // daemon for no reason.
784
- if (!DRY && daemonReachable(env)) {
785
- line(ok(`Dedicated ${label} daemon already running on port ${port} — left alone.`));
786
- return { endpoint: daemonEndpoint(port), stateDir, serviceName, configPath: cfgPath, running: true, port };
787
- }
788
- } else {
789
- await act(`write ${cfgPath} (dedicated ${label} daemon, port ${port}, state ${stateDir})`, async () => {
790
- atomicWriteConfig(cfgPath, mergeConfig(existing, desired));
791
- return { ok: true };
792
- });
793
- }
794
- const started = await act(`ours-mcp start (dedicated ${label} daemon, port ${port})`, async () => run('ours-mcp', ['start'], { env }));
795
- const svc = await act(`ours-mcp install-service (dedicated ${label} daemon, unit ours-${serviceName})`, async () => run('ours-mcp', ['install-service'], { env }));
796
- // Same recovery as the shared daemon: install-service STOPS the daemon before it
797
- // writes the unit, so a failure there leaves nothing listening on this port.
798
- // Same rule as the shared daemon: an exit code is not evidence of a bound port.
799
- let running = DRY ? started.ok : daemonReachable(env);
800
- if (!DRY && !svc.ok) {
801
- if (!running) {
802
- line(info(`the boot-service step stopped the ${label} daemon before it failed — restarting it.`));
803
- run('ours-mcp', ['start'], { env });
804
- running = daemonReachable(env);
805
- }
806
- line(warn(`the ${label} daemon has no boot service — retry '${c.cyan(`OURS_CONFIG=${cfgPath} OURS_SERVICE_NAME=${serviceName} ours-mcp install-service`)}'.`));
807
- }
808
- if (running || DRY) line(ok(`Dedicated ${label} daemon ready on port ${port} (state ${stateDir}, unit ours-${serviceName}).`));
809
- else line(warn(`could not start the dedicated ${label} daemon — run '${c.cyan(`OURS_CONFIG=${cfgPath} ours-mcp start`)}'.`));
810
- return { endpoint: daemonEndpoint(port), stateDir, serviceName, configPath: cfgPath, running: running || DRY, port };
811
- }
812
-
813
- // Ask one consumer whether it uses the COMMON daemon or gets its own. Enter and
814
- // every non-interactive run answer "common" — the historical topology.
815
- const askDaemonMode = (what) => {
816
- line(info(`${what} can share the daemon from step 1, or run against its own isolated one.`));
817
- line(info('Sharing is right for almost everyone — press Enter. A dedicated daemon gets its own'));
818
- line(info('port, state directory and boot service, and does not see the shared daemon\'s identities.'));
819
- return yes(` Give ${what} its OWN dedicated daemon?`, false) ? 'dedicated' : 'common';
820
- };
821
-
822
- // Give the Telegram connector the daemon it was assigned: that daemon's loopback
823
- // endpoint, the state directory that endpoint's API token belongs to, and — for a
824
- // pre-0.3.3 connector that still meets the daemon at a broker instead — that broker.
825
- // Idempotent: an unchanged selection writes nothing. Returns { changed, hadPrevious }
826
- // so the caller can warn about a service unit that froze an older selection.
827
- async function writeTgDaemonConfig({ endpoint, stateDir }) {
828
- const path = tgConfigPath(process.env, homedir());
829
- const desired = {
830
- daemonUrl: endpoint,
831
- daemonStateDir: stateDir,
832
- brokerUrl: sharedBroker(),
833
- };
834
- let existing = {};
835
- try { existing = JSON.parse(readFileSync(path, 'utf8')); } catch { /* absent or unreadable */ }
836
- const plan = planTgDaemonConfig(existing, desired);
837
- const hadPrevious = !!(plan.previous.daemonUrl || plan.previous.brokerUrl);
838
- if (!plan.changed) {
839
- line(ok(`Telegram connector already points at this daemon (${desired.daemonUrl}) — no change.`));
840
- return { changed: false, hadPrevious };
841
- }
842
- await act(`write ${path} (daemon ${desired.daemonUrl}, state ${stateDir})`, async () => {
843
- atomicWriteConfig(path, plan.text);
844
- return { ok: true };
845
- });
846
- line(ok(`Telegram connector configured to use this daemon (${desired.daemonUrl}).`));
847
- return { changed: true, hadPrevious };
848
- }
849
-
850
642
  // ============================================================================================
851
- // STEP 4 / 5 — Telegram connector. Install-only (no bot tokens here). Then: run as a service?
643
+ // STEP 4 / 4 — Telegram connector. Install-only (no bot tokens here). Then: run as a service?
852
644
  // ============================================================================================
853
- line(heading('4/5 — Telegram connector'));
645
+ line(heading('4/4 — Telegram connector'));
854
646
  line(info('This bridges a Telegram bot to your Ours node, so you can talk to your agent from'));
855
647
  line(info("Telegram. (You'll set up the actual bot later, with your agent — not here.)"));
856
648
  const goTg = yes(' Install it?', false);
857
649
  if (goTg) {
858
650
  await actSpin(`installing ${spec('tg-connector')}…`, `npm i -g ${spec('tg-connector')}`, () => runAsync(NPM, ['i', '-g', spec('tg-connector')]));
859
- // WHICH daemon — asked independently of every other consumer, and answered
860
- // "common" by Enter / non-interactive so the historical topology is the default.
861
- line('');
862
- const tgMode = askDaemonMode('the Telegram connector');
863
- let tgDaemon = { endpoint: daemonEndpoint(chosenPort), stateDir: daemonStateDir(), port: chosenPort, mode: 'common' };
864
- if (tgMode === 'dedicated') {
865
- const instance = DEDICATED_INSTANCES.telegram;
866
- const suggested = suggestPort(chosenPort + 1, (p) => claimedPorts.includes(p) || portTakenSync(p));
867
- const port = askDaemonPort('Which local port should the Telegram daemon use?', suggested);
868
- claimPort(port, 'the dedicated Telegram daemon');
869
- const provisioned = await provisionDedicatedDaemon({ instance, port, label: 'Telegram' });
870
- tgDaemon = { ...provisioned, mode: 'dedicated' };
871
- } else {
872
- line(ok(`Telegram will use the shared daemon on port ${chosenPort}.`));
873
- }
874
- // POINT IT AT THAT DAEMON — BEFORE it is started or installed as a service.
875
- // The connector never inherits ~/.ours/config.json (its SDK reports configPath:
876
- // null unless told otherwise), and `install-service` bakes whatever it resolves
877
- // into the unit as environment variables that outrank the file from then on. So
878
- // the daemon's identity has to be in its config BEFORE either happens. See
879
- // planTgDaemonConfig for why all three keys are written.
880
- const tgConfigured = await writeTgDaemonConfig(tgDaemon);
881
- const where = tgDaemon.mode === 'dedicated' ? `its own daemon on port ${tgDaemon.port}` : `the shared daemon on port ${tgDaemon.port}`;
882
651
  const asService = yes(' Keep it running in the background so it starts automatically on boot?', true);
883
652
  if (asService) {
884
653
  const svc = await act('ours-tg-connector install-service (starts on boot)', async () => run('ours-tg-connector', ['install-service']));
885
- if (svc.ok) line(ok(`Telegram connector installed and running as a service (starts on boot), pointed at ${where}. No problems.`));
654
+ if (svc.ok) line(ok('Telegram connector installed and running as a service (starts on boot). No problems.'));
886
655
  else line(warn(`connector installed, but the service didn't start — retry '${c.cyan('ours-tg-connector install-service')}'.`));
887
- record({ key: 'telegram', label: 'Telegram connector', state: 'installed', version: globalVersion('@ours.network/tg-connector'), note: `service (boot) · ${tgDaemon.mode} daemon ${tgDaemon.port}` });
656
+ record({ key: 'telegram', label: 'Telegram connector', state: 'installed', version: globalVersion('@ours.network/tg-connector'), note: 'service (boot)' });
888
657
  } else {
889
- line(ok(`Telegram connector installed, pointed at ${where}. Start it any time with '${c.cyan('ours-tg-connector start')}'. No problems.`));
890
- // A connector already installed as a service froze its OLD daemon selection into
891
- // the unit's environment, which outranks the file we just wrote. Config alone
892
- // cannot repair that — say so plainly rather than let it look fixed.
893
- if (tgConfigured.changed && tgConfigured.hadPrevious) {
894
- line(warn(`if you previously ran '${c.cyan('ours-tg-connector install-service')}', re-run it — the old service froze the previous daemon selection in its unit.`));
895
- }
896
- record({ key: 'telegram', label: 'Telegram connector', state: 'installed', version: globalVersion('@ours.network/tg-connector'), note: `start on demand · ${tgDaemon.mode} daemon ${tgDaemon.port}` });
658
+ line(ok(`Telegram connector installed. Start it any time with '${c.cyan('ours-tg-connector start')}'. No problems.`));
659
+ record({ key: 'telegram', label: 'Telegram connector', state: 'installed', version: globalVersion('@ours.network/tg-connector'), note: 'start on demand' });
897
660
  }
898
661
  } else {
899
662
  line(info('skipped cleanly.'));
@@ -901,146 +664,6 @@ async function main() {
901
664
  }
902
665
  cont(goTg);
903
666
 
904
- // ============================================================================================
905
- // STEP 5 / 5 — Rooms (ours-cowork). Two independent things get configured here.
906
- //
907
- // ITS OWN SURFACE — the deployment broker, its private state directory, and its loopback
908
- // console/REST port. Those it has always had.
909
- //
910
- // WHICH DAEMON — ours-cowork used to host its own, always. It now supports an EXTERNAL ours
911
- // daemon (cowork PR #9), so Rooms answers the same common-vs-dedicated question the Telegram
912
- // connector does, plus a third state the connector does not have: EMBEDDED, cowork's own.
913
- // Contract (see logic.mjs): the `daemon` block is optional; absent means embedded; external is
914
- // { mode:'external', endpoint, stateDir } and REQUIRES both halves, because cowork holds no
915
- // token and its SDK reads <stateDir>/daemon-token.
916
- //
917
- // Boot is FAIL-CLOSED on an unreachable endpoint, a non-ours daemon, or a mismatched state
918
- // directory — there is no embedded fallback. So an install that is ALREADY running embedded is
919
- // never migrated behind the user's back: non-interactively it is left exactly as it is, and
920
- // interactively the question is asked plainly before anything is written.
921
- // ============================================================================================
922
- line(heading('5/5 — Rooms (ours-cowork)'));
923
- line(info('Durable mission rooms: a room keeps its own ordered history, and people and agents'));
924
- line(info('join it as seats. It serves a local web console, and reaches everyone through the'));
925
- line(info('same broker as the rest of your install.'));
926
- const goRooms = yes(' Install it?', false);
927
- if (goRooms) {
928
- await actSpin(`installing ${spec('cowork')}…`, `npm i -g ${spec('cowork')}`, () => runAsync(NPM, ['i', '-g', spec('cowork')]));
929
- const roomsStateDir = join(homedir(), '.ours-cowork');
930
- const cfgPath = coworkConfigPath(process.env, homedir());
931
- let existingRooms = {};
932
- try { existingRooms = JSON.parse(readFileSync(cfgPath, 'utf8')); } catch { /* absent or unreadable */ }
933
- const restDefault = Number.isInteger(existingRooms.rest?.port) ? existingRooms.rest.port : COWORK_DEFAULT_PORT;
934
- line('');
935
- line(info('Rooms serves a console on a loopback port — 127.0.0.1 only, never exposed.'));
936
- // COWORK_DEFAULT_PORT is in RESERVED_PORTS (so no ours daemon can be handed it),
937
- // so validate this one against the daemon ports only.
938
- const roomsPort = (() => {
939
- let candidate = restDefault;
940
- for (let attempt = 0; attempt < 3; attempt++) {
941
- const raw = ask(` Which local port should the Rooms console use? ${c.gray(`[Enter for ${candidate}]`)}: `, String(candidate));
942
- const v = validateDaemonPort(raw, {
943
- fallback: candidate, isTaken: (p) => (p === restDefault ? false : portTakenSync(p)),
944
- taken: claimedPorts, reserved: [],
945
- });
946
- if (v.ok) return v.port;
947
- line(warn(`${v.reason}.`));
948
- if (!interactive) break;
949
- candidate = suggestPort(v.port + 1, (p) => claimedPorts.includes(p) || portTakenSync(p));
950
- line(info(`Suggesting ${candidate} instead.`));
951
- }
952
- return candidate;
953
- })();
954
- claimPort(roomsPort, 'the Rooms console');
955
-
956
- // WHICH DAEMON. `undefined` means "leave whatever is there alone" — the answer for an
957
- // existing embedded install nobody asked to migrate.
958
- const wasEmbedded = coworkDaemonMode(existingRooms) === 'embedded';
959
- const hadConfig = existsSync(cfgPath);
960
- // Ask the BUILD, not the channel: this runs after the install above, so the version
961
- // read here is the one actually on the machine.
962
- const coworkVersion = globalVersion('@ours.network/cowork');
963
- const externalSupported = coworkSupportsExternalDaemon(coworkVersion);
964
- let roomsDaemon;
965
- let roomsDaemonLabel;
966
- if (!externalSupported) {
967
- // The build we just installed predates cowork's external-daemon mode. Its config
968
- // is a strict document and its boot fails closed, so writing a selection it cannot
969
- // honour would break Rooms rather than degrade it.
970
- line(info(`This Rooms build${coworkVersion ? ` (${coworkVersion})` : ''} hosts its own daemon; pointing it at the shared`));
971
- line(info(`one needs ${COWORK_EXTERNAL_MIN_VERSION} or newer. Re-run with ${c.cyan('OURS_CHANNEL=nightly')} to get it.`));
972
- roomsDaemonLabel = 'embedded';
973
- } else if (hadConfig && wasEmbedded && !interactive) {
974
- // Fail-closed boot makes this migration a real risk; never do it unasked.
975
- line(info('Rooms already runs its own embedded daemon — leaving that alone.'));
976
- line(info(`To point it at this install's daemon, re-run ${c.cyan('ours-install')} in a terminal.`));
977
- roomsDaemonLabel = 'embedded (unchanged)';
978
- } else {
979
- line('');
980
- const roomsMode = askDaemonMode('Rooms');
981
- if (roomsMode === 'dedicated') {
982
- const instance = DEDICATED_INSTANCES.rooms;
983
- const suggested = suggestPort(chosenPort + 1, (p) => claimedPorts.includes(p) || portTakenSync(p));
984
- const port = askDaemonPort('Which local port should the Rooms daemon use?', suggested);
985
- claimPort(port, 'the dedicated Rooms daemon');
986
- const provisioned = await provisionDedicatedDaemon({ instance, port, label: 'Rooms' });
987
- roomsDaemon = { endpoint: provisioned.endpoint, stateDir: provisioned.stateDir };
988
- roomsDaemonLabel = `dedicated daemon ${port}`;
989
- } else {
990
- roomsDaemon = { endpoint: daemonEndpoint(chosenPort), stateDir: daemonStateDir() };
991
- roomsDaemonLabel = `common daemon ${chosenPort}`;
992
- line(ok(`Rooms will use the shared daemon on port ${chosenPort}.`));
993
- }
994
- }
995
-
996
- const roomsPlan = planCoworkConfig(existingRooms, {
997
- brokerUrl: sharedBroker(),
998
- stateDir: roomsStateDir,
999
- restPort: roomsPort,
1000
- daemon: roomsDaemon,
1001
- });
1002
- if (roomsPlan.error) {
1003
- // Only reachable if a daemon selection lost half of itself; a half-written block
1004
- // would fail closed at cowork's boot, so refuse rather than write it.
1005
- line(warn(`not changing the Rooms daemon selection — ${roomsPlan.error}.`));
1006
- } else if (roomsPlan.changed) {
1007
- await act(`write ${cfgPath} (console port ${roomsPort}, state ${roomsStateDir}${roomsDaemon ? `, daemon ${roomsDaemon.endpoint}` : ''})`, async () => {
1008
- atomicWriteConfig(cfgPath, roomsPlan.text);
1009
- return { ok: true };
1010
- });
1011
- if (roomsDaemon) line(ok(`Rooms configured to use ${roomsDaemonLabel} (${roomsDaemon.endpoint}, state ${roomsDaemon.stateDir}).`));
1012
- } else {
1013
- line(ok(`Rooms is already configured for this deployment (console port ${roomsPort}) — no change.`));
1014
- }
1015
- const svc = await act('ours-cowork install-service (starts on boot)', async () => run('ours-cowork', ['install-service']));
1016
- if (svc.ok) {
1017
- line(ok(`Rooms ready — console at ${c.cyan(`http://127.0.0.1:${roomsPort}/`)}, sharing your broker. No problems.`));
1018
- } else {
1019
- line(warn(`Rooms installed, but its service didn't start — retry '${c.cyan('ours-cowork install-service')}'.`));
1020
- line(info(`You can also run it in the foreground: '${c.cyan('ours-cowork web')}'.`));
1021
- }
1022
- record({
1023
- key: 'rooms',
1024
- label: 'Rooms (ours-cowork)',
1025
- state: svc.ok ? 'installed' : 'failed',
1026
- version: coworkVersion,
1027
- note: svc.ok ? `console ${roomsPort} · ${roomsDaemonLabel}` : 'ours-cowork install-service failed',
1028
- });
1029
- } else {
1030
- line(info('skipped cleanly — re-run ours-install any time to add it.'));
1031
- record({ key: 'rooms', label: 'Rooms (ours-cowork)', state: 'skipped' });
1032
- }
1033
- cont(goRooms);
1034
-
1035
- // Last guard on the whole topology: no two daemons in this install may share a port.
1036
- // Each answer was validated as it was given, but only the finished plan proves the set.
1037
- const portPlan = planPorts(topology);
1038
- if (!portPlan.ok) {
1039
- for (const d of portPlan.duplicates) {
1040
- line(warn(`port ${d.port} ended up claimed by both ${d.labels[0]} and ${d.labels[1]} — one of them will fail to bind.`));
1041
- }
1042
- }
1043
-
1044
667
  return endScreen({ ttyFd, summary, chosenPort, chosenBroker });
1045
668
  }
1046
669
 
@@ -1119,9 +742,7 @@ function endScreen({ ttyFd, summary, chosenPort, chosenBroker }) {
1119
742
  const has = (k) => summary.some((r) => r.key === k && (r.state === 'installed' || r.state === 'current'));
1120
743
  if (has('core')) {
1121
744
  const identityDone = has('identity');
1122
- const { text, empty } = buildHandoffPrompt({
1123
- identity: !identityDone, fleet: has('fleet'), telegram: has('telegram'), rooms: has('rooms'),
1124
- });
745
+ const { text, empty } = buildHandoffPrompt({ identity: !identityDone, fleet: has('fleet'), telegram: has('telegram') });
1125
746
  if (empty) {
1126
747
  // Nothing left to finish (identity created in-install, no fleet/Telegram). Don't show an empty box.
1127
748
  line('');