@ours.network/install 1.2.1-nightly.52 → 1.2.1-nightly.54

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/GATEWAY_SETUP.md CHANGED
@@ -11,8 +11,8 @@ control local processes; they do not carry server management requests.
11
11
 
12
12
  The nightly manifest selects one published dependency graph: SDK
13
13
  `3.8.1-nightly.18`, CLI `2.8.1-nightly.16`, daemon `3.8.1-nightly.10`,
14
- Fleet `1.2.0-nightly.67`, MCP/Codex/Claude Code `1.2.0-nightly.14`,
15
- Telegram `1.0.1-nightly.12`, Messenger `1.0.31-nightly.19`, Notifications
14
+ Fleet `1.2.0-nightly.68`, MCP/Codex/Claude Code `1.2.0-nightly.14`,
15
+ Telegram `1.0.1-nightly.12`, Messenger `1.0.31-nightly.20`, Notifications
16
16
  `0.3.1-nightly.4`, and Cowork `1.3.4-nightly.20261013.e8a690f`. Exact archive checksums are retained in
17
17
  `releases/nightly.json`; the host CLI uses the same SDK/CLI pair.
18
18
 
package/README.md CHANGED
@@ -707,7 +707,13 @@ Cloudflare management tokens are forbidden in these payloads.
707
707
 
708
708
  Docker and `cloudflared` are required for the fresh workflow. Supply a complete
709
709
  `--fleet-settings` JSON for noninteractive Fleet initialization, or answer its
710
- terminal prompts. Dry-run never initializes or enrolls Fleet. Read the matching
710
+ terminal prompts. Dry-run never initializes or enrolls Fleet. A one-use App setup
711
+ grant is redeemed only after argument and host-state checks, the read-only
712
+ setup plan (environment overrides, platform, source policy) and `--fleet-settings`
713
+ validation, and Fleet/`cloudflared` availability pass; dry-run and these rejections
714
+ leave the command usable until it expires. Checks that need the private envelope (resumed-workspace match,
715
+ optional-profile Fleet capability) follow redemption, so their failure requires a
716
+ fresh command. Ambiguous redemption is never retried automatically. Read the matching
711
717
  ours-app `server/DEPLOYMENT.md` for exact task source-policy generation, external
712
718
  Google/Cloudflare prerequisites and account-server setup. On uncertain enrollment
713
719
  check account status before requesting a new payload; do not reset identities or
@@ -739,7 +745,7 @@ Existing installation records keep their ports and identities. A listener acquir
739
745
  by another process after preflight still causes startup to fail safely; no foreign
740
746
  process is stopped and no retained installation is silently moved.
741
747
 
742
- Workspace setup pins Fleet `1.2.0-nightly.67` with its recorded registry integrity. This release includes first-time Fleet setup through the host API for the account App, direct App access to the workspace services with the device credential, v2 positional one-use grants and automatic QR/connection-code output from `ours-fleet setup-tunnel`, optional private file/stdin inputs for legacy v1 payloads, a separate `ours-fleet link-device` command for additional devices, host prerequisite checks before the one-time workspace proof (`setup-tunnel --check`), `setup-tunnel --resume` to finish a setup that stopped after the host saved its private pending setup record (not when the proof's answer was lost, or after the setup window expired with an unconfirmed non-default port), and persists the available Fleet loopback port used by the workspace tunnel. It also accepts a setup-generated configuration left behind after the host enrollment state was removed, runs the host Codex when it is at least as new as the packaged one, offers only the Codex models the signed-in account can use, and removes the temporary setup contact after confirmation. Fleet serves no pages and opens no browser: every screen is in the App. Fleet also serves the workspace notification routes, produces notifications through the server gateway with the imported producer credential, accepts the App's device credential on the notification presence socket so an open App receives no push, and defaults agent wakes to `monitor.interrupt: after_tool` (Hermes: no interrupt; role snapshots saved before this default keep no interrupt). Existing installation identities and configured ports remain retained; a retained-port collision fails safely.
748
+ Workspace setup pins Fleet `1.2.0-nightly.68` with its recorded registry integrity. This release includes first-time Fleet setup through the host API for the account App, direct App access to the workspace services with the device credential, v2 positional one-use grants and automatic QR/connection-code output from `ours-fleet setup-tunnel`, optional private file/stdin inputs for legacy v1 payloads, a separate `ours-fleet link-device` command for additional devices, host prerequisite checks before the one-time workspace proof (`setup-tunnel --check`), `setup-tunnel --resume` to finish a setup that stopped after the host saved its private pending setup record (not when the proof's answer was lost, or after the setup window expired with an unconfirmed non-default port), and persists the available Fleet loopback port used by the workspace tunnel. It also accepts a setup-generated configuration left behind after the host enrollment state was removed, runs the host Codex when it is at least as new as the packaged one, offers only the Codex models the signed-in account can use, and removes the temporary setup contact after confirmation. Fleet serves no pages and opens no browser: every screen is in the App. Fleet also serves the workspace notification routes, produces notifications through the server gateway with the imported producer credential, accepts the App's device credential on the notification presence socket so an open App receives no push, and defaults agent wakes to `monitor.interrupt: after_tool` (Hermes: no interrupt; role snapshots saved before this default keep no interrupt). Existing installation identities and configured ports remain retained; a retained-port collision fails safely.
743
749
 
744
750
  ### App tunnel setup prerelease sequencing
745
751
 
@@ -756,7 +762,7 @@ connection code automatically; the App checks readiness and opens the code field
756
762
  Private `--file`/`--stdin` transports remain optional and are the only transports
757
763
  for legacy v1 payloads with long-lived credentials.
758
764
 
759
- The nightly installer release manifest selects published Fleet `1.2.0-nightly.67`
765
+ The nightly installer release manifest selects published Fleet `1.2.0-nightly.68`
760
766
  and its actual registry integrity through the normal release manifest/source-policy
761
767
  generators. This release includes v2 argument and private-input support. The former
762
768
  nightly.41 selection predates this capability. Merge and publish the repinned
@@ -13,9 +13,9 @@
13
13
  "@ours.network/codex": "1.2.0-nightly.14",
14
14
  "@ours.network/cowork": "1.3.4-nightly.20261013.e8a690f",
15
15
  "@ours.network/daemon": "3.8.1-nightly.10",
16
- "@ours.network/fleet": "1.2.0-nightly.67",
16
+ "@ours.network/fleet": "1.2.0-nightly.68",
17
17
  "@ours.network/mcp": "1.2.0-nightly.14",
18
- "@ours.network/messenger-server": "1.0.31-nightly.19",
18
+ "@ours.network/messenger-server": "1.0.31-nightly.20",
19
19
  "@ours.network/notifications": "0.3.1-nightly.4",
20
20
  "@ours.network/sdk": "3.8.1-nightly.18",
21
21
  "@ours.network/tg-connector": "1.0.1-nightly.12"
@@ -429,9 +429,9 @@
429
429
  }
430
430
  },
431
431
  "node_modules/@agentclientprotocol/sdk": {
432
- "version": "1.8.0",
433
- "resolved": "https://registry.npmjs.org/@agentclientprotocol/sdk/-/sdk-1.8.0.tgz",
434
- "integrity": "sha512-fbP7qHZsFyTJVT0/RPrcWJ8An26qLXHEuGCHHEKDyxD1xpXV+Ejyh2LAE6vBAFePkpVjZeeohnbgvuEhZ7wLMg==",
432
+ "version": "1.9.0",
433
+ "resolved": "https://registry.npmjs.org/@agentclientprotocol/sdk/-/sdk-1.9.0.tgz",
434
+ "integrity": "sha512-saCOTPYBK1iqWqJFAYHXbg3+zCoFXyZZFoqQAwdTWkbrZZPpAETr80QOnYr2l+dzPwL0jpNhn3eDY8MoEIDbUA==",
435
435
  "license": "Apache-2.0",
436
436
  "peerDependencies": {
437
437
  "zod": "^3.25.0 || ^4.0.0"
@@ -1030,9 +1030,9 @@
1030
1030
  }
1031
1031
  },
1032
1032
  "node_modules/@ours.network/fleet": {
1033
- "version": "1.2.0-nightly.67",
1034
- "resolved": "https://registry.npmjs.org/@ours.network/fleet/-/fleet-1.2.0-nightly.67.tgz",
1035
- "integrity": "sha512-kWsslhAbZ2juI8eehRxcJWB6fzLvbHe8dCxXyGLh7jx/V9khZnMhKX3mrfaSsOo494Y8utvzXYRykcUZ3Uf5IA==",
1033
+ "version": "1.2.0-nightly.68",
1034
+ "resolved": "https://registry.npmjs.org/@ours.network/fleet/-/fleet-1.2.0-nightly.68.tgz",
1035
+ "integrity": "sha512-u8z2s/xZ+HPTCRb0hkOC66zSI5Xf3q90dnI2i4gS7J2u7IGh8nYVgf8+m3wSTegRR1e/5Qe409ozvGkc5pgVFQ==",
1036
1036
  "license": "FSL-1.1-Apache-2.0",
1037
1037
  "dependencies": {
1038
1038
  "@agentclientprotocol/sdk": "^1.3.0",
@@ -1086,9 +1086,9 @@
1086
1086
  }
1087
1087
  },
1088
1088
  "node_modules/@ours.network/messenger-server": {
1089
- "version": "1.0.31-nightly.19",
1090
- "resolved": "https://registry.npmjs.org/@ours.network/messenger-server/-/messenger-server-1.0.31-nightly.19.tgz",
1091
- "integrity": "sha512-2yuvk8B5W5giQQoZu5HOd9ZS1D3aLI/1J1HZKlHKHQ34LDMMLtHpZf3oMNPXyrZWpZJm4p3hC9X8Pf13pOmcYw==",
1089
+ "version": "1.0.31-nightly.20",
1090
+ "resolved": "https://registry.npmjs.org/@ours.network/messenger-server/-/messenger-server-1.0.31-nightly.20.tgz",
1091
+ "integrity": "sha512-I2LLxl5HdFA2EhNe4cwal8Yhc3luNa+twEcsTIMcrhPWwejCm7D8U7E9XFAUpZ4TmYXvNaGC1f7BRE9gprEfeg==",
1092
1092
  "license": "FSL-1.1-Apache-2.0",
1093
1093
  "dependencies": {
1094
1094
  "@eslint-community/regexpp": "4.12.2",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "channel": "nightly",
4
- "installerVersion": "1.2.1-nightly.52",
4
+ "installerVersion": "1.2.1-nightly.54",
5
5
  "packages": {
6
6
  "@ours.network/sdk": {
7
7
  "version": "3.8.1-nightly.18",
@@ -20,16 +20,16 @@
20
20
  "integrity": "sha512-t0eQoyMcfp5ar/eXkvGwTHHkkwvuD119WMbcFffsRhknJkZtnQOeLcKgfIiajVwk1HZIEONNeA4Eibml5M0DGw=="
21
21
  },
22
22
  "@ours.network/messenger-server": {
23
- "version": "1.0.31-nightly.19",
24
- "integrity": "sha512-2yuvk8B5W5giQQoZu5HOd9ZS1D3aLI/1J1HZKlHKHQ34LDMMLtHpZf3oMNPXyrZWpZJm4p3hC9X8Pf13pOmcYw=="
23
+ "version": "1.0.31-nightly.20",
24
+ "integrity": "sha512-I2LLxl5HdFA2EhNe4cwal8Yhc3luNa+twEcsTIMcrhPWwejCm7D8U7E9XFAUpZ4TmYXvNaGC1f7BRE9gprEfeg=="
25
25
  },
26
26
  "@ours.network/notifications": {
27
27
  "version": "0.3.1-nightly.4",
28
28
  "integrity": "sha512-z2n4MKigIsDNvOBgJ6rhyWMHT+lfAFNT8bL9mna1IR0ysSz4diAHZSvdc18KE5AdXEXr4YypH9Rmx7frMPG6rA=="
29
29
  },
30
30
  "@ours.network/fleet": {
31
- "version": "1.2.0-nightly.67",
32
- "integrity": "sha512-kWsslhAbZ2juI8eehRxcJWB6fzLvbHe8dCxXyGLh7jx/V9khZnMhKX3mrfaSsOo494Y8utvzXYRykcUZ3Uf5IA=="
31
+ "version": "1.2.0-nightly.68",
32
+ "integrity": "sha512-u8z2s/xZ+HPTCRb0hkOC66zSI5Xf3q90dnI2i4gS7J2u7IGh8nYVgf8+m3wSTegRR1e/5Qe409ozvGkc5pgVFQ=="
33
33
  },
34
34
  "@ours.network/mcp": {
35
35
  "version": "1.2.0-nightly.14",
@@ -2,7 +2,7 @@
2
2
  "release": {
3
3
  "schema": 1,
4
4
  "channel": "nightly",
5
- "installerVersion": "1.2.1-nightly.52",
5
+ "installerVersion": "1.2.1-nightly.54",
6
6
  "packages": {
7
7
  "@ours.network/sdk": {
8
8
  "version": "3.8.1-nightly.18",
@@ -21,16 +21,16 @@
21
21
  "integrity": "sha512-t0eQoyMcfp5ar/eXkvGwTHHkkwvuD119WMbcFffsRhknJkZtnQOeLcKgfIiajVwk1HZIEONNeA4Eibml5M0DGw=="
22
22
  },
23
23
  "@ours.network/messenger-server": {
24
- "version": "1.0.31-nightly.19",
25
- "integrity": "sha512-2yuvk8B5W5giQQoZu5HOd9ZS1D3aLI/1J1HZKlHKHQ34LDMMLtHpZf3oMNPXyrZWpZJm4p3hC9X8Pf13pOmcYw=="
24
+ "version": "1.0.31-nightly.20",
25
+ "integrity": "sha512-I2LLxl5HdFA2EhNe4cwal8Yhc3luNa+twEcsTIMcrhPWwejCm7D8U7E9XFAUpZ4TmYXvNaGC1f7BRE9gprEfeg=="
26
26
  },
27
27
  "@ours.network/notifications": {
28
28
  "version": "0.3.1-nightly.4",
29
29
  "integrity": "sha512-z2n4MKigIsDNvOBgJ6rhyWMHT+lfAFNT8bL9mna1IR0ysSz4diAHZSvdc18KE5AdXEXr4YypH9Rmx7frMPG6rA=="
30
30
  },
31
31
  "@ours.network/fleet": {
32
- "version": "1.2.0-nightly.67",
33
- "integrity": "sha512-kWsslhAbZ2juI8eehRxcJWB6fzLvbHe8dCxXyGLh7jx/V9khZnMhKX3mrfaSsOo494Y8utvzXYRykcUZ3Uf5IA=="
32
+ "version": "1.2.0-nightly.68",
33
+ "integrity": "sha512-u8z2s/xZ+HPTCRb0hkOC66zSI5Xf3q90dnI2i4gS7J2u7IGh8nYVgf8+m3wSTegRR1e/5Qe409ozvGkc5pgVFQ=="
34
34
  },
35
35
  "@ours.network/mcp": {
36
36
  "version": "1.2.0-nightly.14",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "@ours.network/messenger-server": {
81
81
  "type": "npm",
82
- "version": "1.0.31-nightly.19"
82
+ "version": "1.0.31-nightly.20"
83
83
  },
84
84
  "@ours.network/notifications": {
85
85
  "type": "npm",
@@ -87,7 +87,7 @@
87
87
  },
88
88
  "@ours.network/fleet": {
89
89
  "type": "npm",
90
- "version": "1.2.0-nightly.67"
90
+ "version": "1.2.0-nightly.68"
91
91
  },
92
92
  "@ours.network/mcp": {
93
93
  "type": "npm",
@@ -1069,6 +1069,116 @@ export async function runFleetManagedCliSetup(args, effects, plan, target) {
1069
1069
  return { state: declared.every(role => good.includes(role.setup.state)) ? 'prepared' : 'attention', report };
1070
1070
  }
1071
1071
 
1072
+ export const FLEET_SERVICE_REFRESH_CAPABILITY = 'service.refresh-v1';
1073
+
1074
+ /** Order matters only for the supervisor: it stops and resumes agents, so it goes last. */
1075
+ const FLEET_RESTART_ORDER = ['web', 'watchdogs', 'supervisor'];
1076
+ const FLEET_RESTART_TIMEOUT_MS = 120_000;
1077
+
1078
+ /** Whether this installer runs inside `unit`'s cgroup, where restarting it would kill this run. */
1079
+ function insideUnit(effects, unit) {
1080
+ const cgroup = effects.readText('/proc/self/cgroup');
1081
+ return cgroup === null || cgroup.split('\n').some(line => line.split(':').slice(2).join(':').split('/').includes(unit));
1082
+ }
1083
+
1084
+ /** The platform's own restart command for a Fleet service definition. */
1085
+ function fleetRestartCommand(effects, service) {
1086
+ return effects.platform.platform === 'darwin'
1087
+ ? `launchctl kickstart -k gui/$(id -u)/${basename(service.path, '.plist')}`
1088
+ : `systemctl --user try-restart ${basename(service.path)}`;
1089
+ }
1090
+
1091
+ /**
1092
+ * An active Fleet service started from the replaced release keeps running it.
1093
+ * Restart each one that `service refresh` reports running a stale release once
1094
+ * its definition starts this release, then confirm with the read-only
1095
+ * `service check` that it now runs this release. The restart is systemd's
1096
+ * `try-restart`, which acts only on an active unit, so a service stopped at
1097
+ * any point is never started. A service whose definition still points
1098
+ * elsewhere, launchd, or the unit hosting this run is left alone with a notice
1099
+ * naming the manual restart; a running state Fleet cannot determine is never
1100
+ * restarted and is reported as unconfirmed.
1101
+ */
1102
+ async function restartStaleFleetServices(effects, fleet, shown, env, services) {
1103
+ const attention = [];
1104
+ for (const service of services.filter(service => service.running === 'unknown' && (service.state === 'refreshed' || service.state === 'current'))) {
1105
+ attention.push(service.service);
1106
+ effects.out(warn(`Could not confirm which release the Fleet ${service.service} service is running; if it is running and was started before this update, restart it: ${fleetRestartCommand(effects, service)}${service.service === 'supervisor' ? ' (agents resume through their supervisor)' : ''}.`));
1107
+ }
1108
+ const stale = services.filter(service => service.running === 'stale')
1109
+ .sort((a, b) => FLEET_RESTART_ORDER.indexOf(a.service) - FLEET_RESTART_ORDER.indexOf(b.service));
1110
+ if (!stale.length) return attention;
1111
+ const linux = effects.platform.platform === 'linux';
1112
+ const restarted = [];
1113
+ for (const service of stale) {
1114
+ const unit = basename(service.path);
1115
+ const left = why => { attention.push(service.service); effects.out(warn(`Running Fleet ${service.service} service still uses the previous release: ${why}; when convenient: ${fleetRestartCommand(effects, service)}${service.service === 'supervisor' ? ' (agents resume through their supervisor)' : ''}.`)); };
1116
+ if (!linux) { left('this installer restarts Fleet services only under systemd'); continue; }
1117
+ if (service.state !== 'refreshed' && service.state !== 'current') { left('its definition does not start this release yet, so a restart would not help'); continue; }
1118
+ if (insideUnit(effects, unit)) { left('this installer runs inside it, so restarting it would stop this run'); continue; }
1119
+ try {
1120
+ // try-restart: a unit stopped since the report was taken stays stopped.
1121
+ await effects.run('systemctl', ['--user', 'try-restart', unit], { timeout: FLEET_RESTART_TIMEOUT_MS });
1122
+ restarted.push(service);
1123
+ } catch (error) {
1124
+ left(`restarting it failed (${installerFailure(error)})`);
1125
+ }
1126
+ }
1127
+ if (!restarted.length) return attention;
1128
+ let checked;
1129
+ try {
1130
+ const result = await effects.run(fleet, ['service', 'check', '--json'], { env, allowCodes: [1] });
1131
+ checked = JSON.parse(result.stdout ?? '').services;
1132
+ if (!Array.isArray(checked)) throw new Error('unrecognised report');
1133
+ } catch (error) {
1134
+ effects.out(warn(`Restarted Fleet ${restarted.map(service => service.service).join(', ')} service, but could not confirm which release it runs (${installerFailure(error)}); check: ${shown} service check`));
1135
+ return [...attention, ...restarted.map(service => service.service)];
1136
+ }
1137
+ for (const service of restarted) {
1138
+ const now = checked.find(entry => entry.service === service.service);
1139
+ if (now?.running === 'current') effects.out(ok(`Restarted Fleet ${service.service} service; it now runs this release${service.service === 'supervisor' ? ' and resumes its agents' : ''}.`));
1140
+ else {
1141
+ attention.push(service.service);
1142
+ effects.out(warn(now?.running === 'stopped'
1143
+ ? `Fleet ${service.service} service is not running after the restart (it was stopped, or exited); this installer did not start it. Check: systemctl --user status ${basename(service.path)}`
1144
+ : `Restarted Fleet ${service.service} service, but it is not confirmed on this release (${now?.running ?? 'not reported'}); check: systemctl --user status ${basename(service.path)}`));
1145
+ }
1146
+ }
1147
+ return attention;
1148
+ }
1149
+
1150
+ /**
1151
+ * Fleet service definitions pin the release tree that wrote them, and an update
1152
+ * installs a new tree. Ask the installed Fleet to re-point its own existing
1153
+ * definitions (it never creates, starts, stops or restarts a service), then
1154
+ * restart only the services that were already running the replaced release.
1155
+ */
1156
+ export async function runFleetServiceRefresh(args, effects, plan, target) {
1157
+ const fleet = args.acquiredFleet || plan.init[0];
1158
+ const env = target.mode === 'host-profile' ? profileEnv(target) : daemonEnv(target.stateDir, target.port);
1159
+ const capabilities = await effects.fleetCapabilities(fleet, env);
1160
+ if (!capabilities.includes(FLEET_SERVICE_REFRESH_CAPABILITY)) return { state: 'unavailable' };
1161
+ const shown = fleet === plan.init[0] ? fleet : shellQuote(fleet);
1162
+ const manual = `${shown} service refresh`;
1163
+ let services;
1164
+ try {
1165
+ const result = await effects.run(fleet, ['service', 'refresh', '--json'], { env });
1166
+ services = JSON.parse(result.stdout ?? '').services;
1167
+ if (!Array.isArray(services)) throw new Error('unrecognised report');
1168
+ } catch (error) {
1169
+ effects.out(warn(`Fleet service definitions were not refreshed (${installerFailure(error)}). After a reboot the previous Fleet release may start; retry: ${manual}`));
1170
+ return { state: 'failed' };
1171
+ }
1172
+ for (const service of services) {
1173
+ if (service.state === 'refreshed') effects.out(ok(`Fleet ${service.service} service now starts this release (${service.path}).`));
1174
+ if (service.state === 'unrecognized') effects.out(warn(`Fleet ${service.service} service definition was left unchanged: ${service.detail ?? 'not generated by Fleet'} (${service.path}).`));
1175
+ if (service.state === 'stale') effects.out(warn(`Fleet ${service.service} service still starts another release${service.detail ? `: ${service.detail}` : ''}; retry: ${manual}`));
1176
+ if (service.state === 'reload-failed') effects.out(warn(`Fleet ${service.service} service definition was updated, but the service manager did not reload it, so it still starts the previous release${service.detail ? ` (${service.detail})` : ''}; retry: systemctl --user daemon-reload`));
1177
+ }
1178
+ const unrestarted = await restartStaleFleetServices(effects, fleet, shown, env, services);
1179
+ return { state: unrestarted.length || services.some(service => service.state !== 'refreshed' && service.state !== 'current' && service.state !== 'absent') ? 'attention' : 'refreshed', services };
1180
+ }
1181
+
1072
1182
  /** Install Fleet and let its interactive wizard publish the owned configuration. */
1073
1183
  export async function runFleetPhase(args, effects, { target, isDefaultStateDir }) {
1074
1184
  effects.out(heading('ours-fleet (your always-online agent team)'));
@@ -1089,7 +1199,12 @@ export async function runFleetPhase(args, effects, { target, isDefaultStateDir }
1089
1199
  if (!install.ok) return { key: 'fleet', label: plan.label, state: 'failed', note: 'Fleet installation failed' };
1090
1200
  effects.out(ok('Fleet CLI installed; agent and model setup deferred to the App. Existing Fleet configuration was retained.'));
1091
1201
  // A retained configuration may already declare the workflow; its generated policy names the package path this run just replaced.
1092
- if (!args.dryRun && effects.readText(plan.configPath) !== null) await runFleetManagedCliSetup(args, effects, plan, target);
1202
+ // A retained configuration means Fleet was set up before, so its service
1203
+ // definitions may pin the release this run just replaced.
1204
+ if (!args.dryRun && effects.readText(plan.configPath) !== null) {
1205
+ await runFleetManagedCliSetup(args, effects, plan, target);
1206
+ await runFleetServiceRefresh(args, effects, plan, target);
1207
+ }
1093
1208
  return { key: 'fleet', label: plan.label, state: 'installed', note: 'agents setup deferred' };
1094
1209
  }
1095
1210
  // Fleet owns its v2 manifest, roles, models and permissions. With no prepared
@@ -1116,6 +1231,7 @@ export async function runFleetPhase(args, effects, { target, isDefaultStateDir }
1116
1231
  }
1117
1232
  effects.out(ok('ours-fleet installed and initialized; no fleet roles were started.'));
1118
1233
  if (!args.dryRun) await runFleetManagedCliSetup(args, effects, plan, target);
1234
+ if (!args.dryRun) await runFleetServiceRefresh(args, effects, plan, target);
1119
1235
  if (plan.instruction) effects.out(info(plan.instruction));
1120
1236
  return { key: 'fleet', label: plan.label, state: 'installed', note: `configured at ${plan.configPath}; stopped` };
1121
1237
  }
package/lib/setup.mjs CHANGED
@@ -109,6 +109,16 @@ export async function prepareSetupPlan(options, effects) {
109
109
  return plan;
110
110
  }
111
111
 
112
+ /**
113
+ * Read-only preflight of a complete noninteractive setup command and optional Fleet
114
+ * settings: the same validation and dry-run planning as runSetup, without prompts,
115
+ * locks, installs or service changes.
116
+ */
117
+ export async function preflightSetup(argv, effects, { fleetSettingsPath } = {}) {
118
+ if (fleetSettingsPath) validateFleetSettings(readObject(effects, fleetSettingsPath, 'Fleet settings'));
119
+ if (argv) await prepareSetupPlan(validateSetupOptions({ ...parseSetupArgs(argv, { home: effects.home, validate: false }), dryRun: true }, { interactive: false }), effects);
120
+ }
121
+
112
122
  export async function executeSetupPlan(plan, effects, { server = runServerCommand, client = runClientCommand } = {}) {
113
123
  if (!plan.interactive) effects.out(banner());
114
124
  effects.out(heading(`${plan.operation === 'update' ? 'Update' : 'Install'} ours.network`));
@@ -1,30 +1,66 @@
1
1
  import { chmodSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
2
2
  import { join,resolve } from 'node:path';
3
3
  import {parseSetupArgs} from './setup-options.mjs';
4
+ import {preflightSetup} from './setup.mjs';
4
5
  /** Base64 is transport, not encryption. Broad provider credentials are never accepted. */
5
6
  export function decodeWorkspacePayload(encoded,now=Date.now()) {
6
7
  if(typeof encoded!=='string' || encoded.length>32768 || !/^[A-Za-z0-9_-]+$/.test(encoded.trim()))throw Error('Invalid private workspace payload');
7
8
  let p;try{p=JSON.parse(Buffer.from(encoded.trim(),'base64url'));}catch{throw Error('Invalid private workspace payload');}
8
- const allowed=['version','appOrigin','hostname','rootName','name','surname','connectorToken','invitation','serverCid','challenge'];
9
- if(!p || Object.keys(p).some(k=>!allowed.includes(k)) || p.version!==1 || !['https://app.ours.network','https://app.ours-tunnel.com'].includes(p.appOrigin) || !/^[a-z0-9][a-z0-9-]{2,60}\.ours-tunnel\.com$/.test(p.hostname) || !/^[a-z0-9-]{2,30}@[a-z0-9-]{2,30}$/.test(p.rootName) || !/^[a-f0-9]{64}$/i.test(p.serverCid))throw Error('Invalid workspace payload boundary');
10
- for(const key of ['name','surname','connectorToken','invitation'])if(typeof p[key]!=='string' || !p[key].trim() || p[key].length>8192 || /[\x00-\x1f\x7f]/.test(p[key]))throw Error('Invalid private workspace payload');
9
+ const allowed=['version','appOrigin','hostname','rootName','fullName','name','surname','connectorToken','invitation','serverCid','challenge','renewal'];
10
+ if(!p || typeof p!=='object' || Array.isArray(p) || Object.keys(p).some(k=>!allowed.includes(k)) || p.version!==1 || !['https://app.ours.network','https://app.ours-tunnel.com'].includes(p.appOrigin) || !/^[a-z0-9][a-z0-9-]{2,60}\.ours-tunnel\.com$/.test(p.hostname) || !/^[a-z0-9-]{2,30}@[a-z0-9-]{2,30}$/.test(p.rootName) || !/^[a-f0-9]{64}$/i.test(p.serverCid))throw Error('Invalid workspace payload boundary');
11
+ for(const key of ['fullName','name','surname']){const value=p[key];if(value==null || value===''){p[key]=null;continue;}if(typeof value!=='string' || value.length>8192 || /[\x00-\x1f\x7f]/.test(value))throw Error('Invalid private workspace profile');p[key]=value.trim()||null;}
12
+ if(p.renewal!==undefined && typeof p.renewal!=='boolean')throw Error('Invalid workspace renewal');
13
+ for(const key of ['connectorToken','invitation'])if(!(key==='connectorToken' && p[key]===undefined && p.renewal===true) && (typeof p[key]!=='string' || !p[key].trim() || p[key].length>8192 || /[\x00-\x1f\x7f]/.test(p[key])))throw Error('Invalid private workspace payload');
11
14
  if(!p.challenge || !['nonce','accountId','workspaceId'].every(k=>/^[\w-]{43}$/.test(p.challenge[k])) || !Number.isFinite(p.challenge.expiresAt) || p.challenge.expiresAt<=now || p.challenge.expiresAt>now+16*60000)throw Error('Workspace challenge expired or invalid');
12
15
  return p;
13
16
  }
17
+ // A v1 envelope is local. A v2 grant is one-use, so it is parsed here and redeemed only after the
18
+ // payload-independent checks in runWorkspaceSetup (arguments, host state, read-only setup and Fleet
19
+ // settings preflight, Fleet/tunnel availability, dry run) pass.
20
+ function workspaceGrant(input){
21
+ if(typeof input!=='string' || !/^[A-Za-z0-9_-]{1,32768}$/.test(input.trim()))throw Error('Invalid workspace setup input');
22
+ let grant;try{grant=JSON.parse(Buffer.from(input.trim(),'base64url'));}catch{throw Error('Invalid workspace setup input');}
23
+ if(grant?.version===1)return null;
24
+ const now=Date.now();
25
+ if(grant?.version!==2 || Object.keys(grant).sort().join(',')!=='appOrigin,code,expiresAt,version'
26
+ || !['https://app.ours.network','https://app.ours-tunnel.com'].includes(grant.appOrigin)
27
+ || !/^[A-Za-z0-9_-]{43}$/.test(grant.code) || !Number.isSafeInteger(grant.expiresAt) || grant.expiresAt<=now || grant.expiresAt>now+16*60000)
28
+ throw Error('Workspace setup grant is invalid or expired; get a fresh command from the App');
29
+ return grant;
30
+ }
31
+ // Redeem only the minimal public grant; the private envelope stays in process/file transport.
32
+ async function redeemWorkspaceGrant(grant,request){
33
+ let response;
34
+ try{response=await request(grant.appOrigin+'/account-api/workspace-install-redeem',{method:'POST',redirect:'error',credentials:'omit',signal:AbortSignal.timeout(30000),headers:{'Content-Type':'application/json',Origin:grant.appOrigin},body:JSON.stringify({code:grant.code})});}
35
+ catch{throw Error('Workspace grant redemption could not be confirmed; check the App before requesting a fresh command');}
36
+ if(!response.ok || response.redirected){await response.body?.cancel();throw Error(response.status===410?'Workspace grant expired or was already used; get a fresh command from the App':'Workspace grant redemption failed; check the App before requesting a fresh command');}
37
+ let result;
38
+ try{
39
+ const chunks=[];let bytes=0;
40
+ if(!response.body)throw Error();
41
+ for await(const chunk of response.body){bytes+=chunk.length;if(bytes>33792)throw Error();chunks.push(chunk);}
42
+ result=JSON.parse(Buffer.concat(chunks).toString('utf8'));
43
+ }catch{throw Error('Invalid workspace setup response; get a fresh command from the App');}
44
+ if(typeof result?.payload!=='string' || !/^[A-Za-z0-9_-]{1,32768}$/.test(result.payload))throw Error('Invalid workspace setup response');
45
+ const payload=decodeWorkspacePayload(result.payload);
46
+ if(payload.appOrigin!==grant.appOrigin)throw Error('Workspace setup response origin mismatch');
47
+ return result.payload;
48
+ }
14
49
  export function extractWorkspaceArgs(args){
15
50
  const flags=['--setup-workspace','--setup-workspace-file','--workspace-fleet-bin','--fleet-settings'];const values={},rest=[];
16
51
  for(let i=0;i<args.length;i++){const at=args[i].indexOf('='),flag=at<0?args[i]:args[i].slice(0,at);if(!flags.includes(flag)){rest.push(args[i]);continue;}if(values[flag]!==undefined)throw Error('Duplicate workspace flag');const value=at<0?args[++i]:args[i].slice(at+1);if(!value || value.startsWith('--'))throw Error('Workspace flag requires a value');values[flag]=value;}
17
52
  if(values['--setup-workspace'] && values['--setup-workspace-file'])throw Error('Choose one private payload transport');
18
53
  return {values,rest};
19
54
  }
20
- export async function runWorkspaceSetup(args,effects,runSetup){
55
+ export async function runWorkspaceSetup(args,effects,runSetup,request=fetch){
21
56
  const migrateAppOrigin=args.includes('--workspace-migrate-app-origin');
22
57
  if(args.filter(arg=>arg==='--workspace-migrate-app-origin').length>1)throw Error('Duplicate workspace migration flag');
23
58
  const {values,rest}=extractWorkspaceArgs(args.filter(arg=>arg!=='--workspace-migrate-app-origin'));let encoded;
24
59
  if(values['--setup-workspace-file']){const path=resolve(values['--setup-workspace-file']),stat=lstatSync(path);if(!stat.isFile() || stat.isSymbolicLink() || stat.nlink!==1 || stat.uid!==process.getuid?.() || stat.size>32768 || (stat.mode&0o077)!==0)throw Error('Setup file must be owned and private (chmod 600)');encoded=readFileSync(path,'utf8').trim();}
25
60
  else if(values['--setup-workspace']==='-'){const chunks=[];let bytes=0;for await(const chunk of process.stdin){bytes+=chunk.length;if(bytes>32768)throw Error('Private payload too large');chunks.push(chunk);}encoded=Buffer.concat(chunks).toString().trim();}
26
61
  else encoded=values['--setup-workspace'];
27
- const p=decodeWorkspacePayload(encoded),fleetBin=values['--workspace-fleet-bin'] || 'ours-fleet';
62
+ const grant=workspaceGrant(encoded);
63
+ let p=grant?null:decodeWorkspacePayload(encoded);const fleetBin=values['--workspace-fleet-bin'] || 'ours-fleet';
28
64
  const parsed=parseSetupArgs(rest,{home:effects.home,validate:false});
29
65
  if(parsed.scope==='server')throw Error('Workspace setup requires all or client scope');
30
66
  if(parsed.identityName!==undefined || parsed.integrations!==undefined)throw Error('Workspace setup supplies identity and client integration selection');
@@ -43,33 +79,54 @@ export async function runWorkspaceSetup(args,effects,runSetup){
43
79
  const stat=lstatSync(marker);
44
80
  if(!stat.isFile() || stat.isSymbolicLink() || stat.nlink!==1 || stat.uid!==process.getuid?.() || (stat.mode&0o077)!==0 || stat.size>4096)throw Error('Workspace retry marker must be owned and private');
45
81
  pending=JSON.parse(readFileSync(marker,'utf8'));
46
- if(pending.version!==1 || pending.accountId!==p.challenge.accountId || pending.workspaceId!==p.challenge.workspaceId || pending.appOrigin!==p.appOrigin)throw Error('Pending fresh installation belongs to another workspace; identity was not changed. Resume the original workspace, or back up the host and remove only ~/.ours-client/workspace-setup-pending.json to treat it as existing (preserving its profile)');
47
82
  }
83
+ const resumable=()=>{if(pending && (pending.version!==1 || pending.accountId!==p.challenge.accountId || pending.workspaceId!==p.challenge.workspaceId || pending.appOrigin!==p.appOrigin))throw Error('Pending fresh installation belongs to another workspace; identity was not changed. Resume the original workspace, or back up the host and remove only ~/.ours-client/workspace-setup-pending.json to treat it as existing (preserving its profile)');};
84
+ if(p)resumable();
48
85
  const preserveProfile=existing && !pending;
49
86
  if(existing && parsed.scope && parsed.scope!=='client')throw Error('Existing workspace setup requires client scope; root identity was not changed');
50
87
  if(!existing && !pending && (existsSync(join(root,'installation.json')) || existsSync(join(effects.home,'fleet.yaml'))))throw Error('Existing host requires its gateway client profile; no new root was created');
51
88
  const options=[...rest];
52
89
  if(!parsed.scope)options.push('--scope',existing?'client':'all');
53
90
  if(existing && !parsed.config)options.push('--config',existingProfile);
54
- if(!existing){if(!parsed.mode)options.push('--mode','docker');if(!parsed.stateDir)options.push('--state-dir',root);options.push('--identity-name',p.rootName);}
91
+ if(!existing){if(!parsed.mode)options.push('--mode','docker');if(!parsed.stateDir)options.push('--state-dir',root);}
55
92
  options.push('--integrations','none');
56
- parseSetupArgs(options,{home:effects.home});
57
- if(preserveProfile){
93
+ // The App assigns the root identity on redemption. Before that, a well-formed stand-in validates the
94
+ // remaining options; explicit username/hostname options derive their own identity instead.
95
+ const setupOptions=identity=>existing || identity===undefined?options:[...options,'--identity-name',identity];
96
+ const standIn=parsed.localUsername===undefined?'workspace@preview':undefined;
97
+ parseSetupArgs(setupOptions(p?.rootName ?? standIn),{home:effects.home});
98
+ const fleetHome=effects.env?.OURS_FLEET_HOME || effects.home,fleetConfig=join(fleetHome,'fleet.yaml');
99
+ // Fresh setup and Fleet initialization would reject these only after redemption.
100
+ if(grant)await preflightSetup(existing?null:setupOptions(standIn),effects,{fleetSettingsPath:existsSync(fleetConfig)?undefined:fleetSettings});
101
+ const capable=async capability=>{
58
102
  const version=await effects.run(fleetBin,['version','--json'],{sensitive:true});
59
103
  let info;try{info=JSON.parse(version.stdout);}catch{}
60
- if(!version.ok || !info?.capabilities?.includes('workspace.enroll.preserve-profile-v1'))throw Error('Existing-host setup requires a profile-preserving Fleet release; nothing was changed');
61
- }
104
+ return version.ok && Array.isArray(info?.capabilities) && info.capabilities.includes(capability);
105
+ };
106
+ const optionalProfile=()=>!preserveProfile && Boolean(p.fullName || !p.name || !p.surname);
107
+ const requireOptionalProfile=async()=>{if(optionalProfile() && !await capable('workspace.enroll.optional-profile-v1'))throw Error('Optional workspace profile requires an updated Fleet; update ours-fleet before retrying setup'+(grant?' with a fresh command from the App':''));};
108
+ if(p)await requireOptionalProfile();
109
+ if(preserveProfile && !await capable('workspace.enroll.preserve-profile-v1'))throw Error('Existing-host setup requires a profile-preserving Fleet release; nothing was changed');
62
110
  const help=await effects.run(fleetBin,['workspace-enroll','--help'],{sensitive:true});if(!help.ok)throw Error('Fleet workspace enrollment is unavailable');
63
111
  const tunnel=await effects.run('cloudflared',['--version'],{sensitive:true});if(!tunnel.ok)throw Error('Tunnel connector is unavailable');
64
- if(options.includes('--dry-run')){if(!existing)return runSetup(options,effects);return 0;}
112
+ if(options.includes('--dry-run')){
113
+ if(grant)effects.out('Preview only: the workspace setup grant was not redeemed; this command remains usable until it expires.');
114
+ if(!existing)return runSetup(setupOptions(p?.rootName ?? standIn),effects);return 0;
115
+ }
116
+ if(grant){
117
+ // Checks below depend on the private envelope, so a failure here leaves the grant spent.
118
+ encoded=await redeemWorkspaceGrant(grant,request);p=decodeWorkspacePayload(encoded);
119
+ resumable();
120
+ parseSetupArgs(setupOptions(p.rootName),{home:effects.home});
121
+ await requireOptionalProfile();
122
+ }
65
123
  if(!existing){
66
124
  if(!pending){mkdirSync(join(effects.home,'.ours-client'),{recursive:true,mode:0o700});writeFileSync(marker,JSON.stringify({version:1,accountId:p.challenge.accountId,workspaceId:p.challenge.workspaceId,appOrigin:p.appOrigin})+'\n',{mode:0o600,flag:'wx'});}
67
- const result=await runSetup(options,effects);if(result!==0)return result;
125
+ const result=await runSetup(setupOptions(p.rootName),effects);if(result!==0)return result;
68
126
  }
69
127
  const selected=existingProfile || effects.readManagedClientProfile();if(!selected)throw Error('Workspace client profile was not installed');
70
128
  const env={OURS_CONFIG:existingProfile || managedPath};
71
129
  for(const key of ['OURS_PORT','OURS_STATE_DIR','OURS_API_TOKEN','OURS_DAEMON_ID','OURS_DAEMON_URL','OURS_DAEMON_CREDENTIAL_PATH'])env[key]=undefined;
72
- const fleetHome=effects.env?.OURS_FLEET_HOME || effects.home,fleetConfig=join(fleetHome,'fleet.yaml');
73
130
  if(!existsSync(fleetConfig)){
74
131
  const initArgs=['init',...(fleetSettings?['--settings',fleetSettings]:[])];
75
132
  const initialized=fleetSettings?await effects.run(fleetBin,initArgs,{env}):await effects.runInteractive(fleetBin,initArgs,{env});if(!initialized.ok)throw Error('Fleet configuration incomplete');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ours.network/install",
3
- "version": "1.2.1-nightly.52",
3
+ "version": "1.2.1-nightly.54",
4
4
  "private": false,
5
5
  "description": "The all-in-one ours.network installer: one shared daemon, MCP, cowork, Telegram, Fleet initialization, harness plugins, Human identity, progress UI, and guided next steps.",
6
6
  "type": "module",