@ours.network/install 1.2.1-nightly.53 → 1.2.1-nightly.55

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
@@ -690,6 +690,8 @@ Fleet and Messenger task builds. Do not advertise it as available in `@latest`.
690
690
  Use an owned private directory and a 0600 downloaded payload:
691
691
 
692
692
  ```sh
693
+ OURS_ACCOUNT_ORIGIN=https://accounts.example.com \
694
+ OURS_WORKSPACE_HOST=alice-home.workspaces.example.com \
693
695
  node /absolute/task-ours-network/packages/installer/install.mjs \
694
696
  --setup-workspace-file /absolute/private/workspace.payload \
695
697
  --workspace-fleet-bin /absolute/task-ours-fleet/dist/cli.js \
@@ -707,15 +709,30 @@ Cloudflare management tokens are forbidden in these payloads.
707
709
 
708
710
  Docker and `cloudflared` are required for the fresh workflow. Supply a complete
709
711
  `--fleet-settings` JSON for noninteractive Fleet initialization, or answer its
710
- terminal prompts. Dry-run never initializes or enrolls Fleet. Read the matching
712
+ terminal prompts. Dry-run never initializes or enrolls Fleet. A one-use App setup
713
+ grant is redeemed only after argument and host-state checks, the read-only
714
+ setup plan (environment overrides, platform, source policy) and `--fleet-settings`
715
+ validation, and Fleet/`cloudflared` availability pass; dry-run and these rejections
716
+ leave the command usable until it expires. Checks that need the private envelope (resumed-workspace match,
717
+ optional-profile Fleet capability) follow redemption, so their failure requires a
718
+ fresh command. Ambiguous redemption is never retried automatically. Read the matching
711
719
  ours-app `server/DEPLOYMENT.md` for exact task source-policy generation, external
712
720
  Google/Cloudflare prerequisites and account-server setup. On uncertain enrollment
713
721
  check account status before requesting a new payload; do not reset identities or
714
722
  replay a consumed invitation.
715
723
 
716
- Workspace setup accepts exactly https://app.ours.network and the controlled test
717
- account origin https://app.ours-tunnel.com. To move an existing same workspace to
718
- the other origin, obtain a fresh payload from the moved account server and add
724
+ Workspace setup requires the trusted invocation configuration `OURS_ACCOUNT_ORIGIN`
725
+ to name the exact HTTPS account origin. The generated App command also carries
726
+ `OURS_WORKSPACE_HOST`, the exact account-record hostname; it takes precedence over
727
+ `OURS_WORKSPACE_DOMAIN`. An operator bootstrap without an exact host may instead
728
+ configure `OURS_WORKSPACE_DOMAIN`, accepting one DNS label under that suffix. A
729
+ missing configuration has no historical-domain fallback. Never obtain these trust
730
+ values from a grant, redeemed envelope, or query. Grant origins are checked before
731
+ redemption; envelope origins and hosts are checked before setup/enrollment, and
732
+ the same trusted configuration is forwarded to Fleet. A v2 grant has no hostname.
733
+
734
+ To move an existing same workspace to another configured origin, obtain a fresh
735
+ payload from the moved account server, select that trusted origin explicitly, and add
719
736
  `--workspace-migrate-app-origin`. Fleet verifies the signed binding receipt before
720
737
  changing local origin trust, preserves identities/config/device records, and
721
738
  restarts the runtime. An implicit origin change is rejected. Browser account
@@ -739,7 +756,7 @@ Existing installation records keep their ports and identities. A listener acquir
739
756
  by another process after preflight still causes startup to fail safely; no foreign
740
757
  process is stopped and no retained installation is silently moved.
741
758
 
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.
759
+ 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
760
 
744
761
  ### App tunnel setup prerelease sequencing
745
762
 
@@ -756,7 +773,7 @@ connection code automatically; the App checks readiness and opens the code field
756
773
  Private `--file`/`--stdin` transports remain optional and are the only transports
757
774
  for legacy v1 payloads with long-lived credentials.
758
775
 
759
- The nightly installer release manifest selects published Fleet `1.2.0-nightly.67`
776
+ The nightly installer release manifest selects published Fleet `1.2.0-nightly.68`
760
777
  and its actual registry integrity through the normal release manifest/source-policy
761
778
  generators. This release includes v2 argument and private-input support. The former
762
779
  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",
@@ -3168,9 +3168,9 @@
3168
3168
  "license": "ISC"
3169
3169
  },
3170
3170
  "node_modules/ret": {
3171
- "version": "0.5.0",
3172
- "resolved": "https://registry.npmjs.org/ret/-/ret-0.5.0.tgz",
3173
- "integrity": "sha512-I1XxrZSQ+oErkRR4jYbAyEEu2I0avBvvMM5JN+6EBprOGRCs63ENqZ3vjavq8fBw2+62G5LF5XelKwuJpcvcxw==",
3171
+ "version": "0.5.1",
3172
+ "resolved": "https://registry.npmjs.org/ret/-/ret-0.5.1.tgz",
3173
+ "integrity": "sha512-Z/nyvABwcRnRD2mMP7Kz6G1dFZZqX1mNErOnxF42OCQKE07b9k9hK9SQxHL3LFEZUdzQaLM4dId1E/E6Vm4WhA==",
3174
3174
  "license": "MIT",
3175
3175
  "engines": {
3176
3176
  "node": ">=10"
@@ -3367,9 +3367,9 @@
3367
3367
  "license": "ISC"
3368
3368
  },
3369
3369
  "node_modules/set-cookie-parser": {
3370
- "version": "3.1.3",
3371
- "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-3.1.3.tgz",
3372
- "integrity": "sha512-xletSdAI5efyVJjsatBbzDkXl3M/Zmad3xfnQe7ZXuBB0yNwW7C2WFsNGjdRNfZunmNHQuX79xs/ACMTLCdcew==",
3370
+ "version": "3.1.4",
3371
+ "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-3.1.4.tgz",
3372
+ "integrity": "sha512-iEmdEew+Tn1BwMGMP8LzGBEPC7Mf1sySjglCeEPb/Vchm9bnGezePvacYcId+fGprQzIng+TBkzqfJ/qS7AsBg==",
3373
3373
  "license": "MIT"
3374
3374
  },
3375
3375
  "node_modules/setprototypeof": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema": 1,
3
3
  "channel": "nightly",
4
- "installerVersion": "1.2.1-nightly.53",
4
+ "installerVersion": "1.2.1-nightly.55",
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.53",
5
+ "installerVersion": "1.2.1-nightly.55",
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",
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,80 @@
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';
5
+ // Invocation configuration is trusted; an incoming grant/envelope never selects its authority.
6
+ const dnsName=value=>typeof value==='string' && value.length<=253 && value.includes('.') && value.split('.').every(label=>/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(label));
7
+ function configuredOrigin(value,env) {
8
+ const configured=env.OURS_ACCOUNT_ORIGIN;
9
+ let url;try{url=new URL(configured);}catch{return false;}
10
+ return typeof configured==='string' && url.protocol==='https:' && url.origin===configured && !url.username && !url.password && !url.hostname.includes('*') && value===configured;
11
+ }
12
+ function configuredHost(value,env) {
13
+ if(!dnsName(value))return false;
14
+ if(env.OURS_WORKSPACE_HOST!==undefined)return dnsName(env.OURS_WORKSPACE_HOST) && value===env.OURS_WORKSPACE_HOST;
15
+ const domain=env.OURS_WORKSPACE_DOMAIN;
16
+ return dnsName(domain) && value.endsWith('.'+domain) && !value.slice(0,-domain.length-1).includes('.');
17
+ }
4
18
  /** Base64 is transport, not encryption. Broad provider credentials are never accepted. */
5
- export function decodeWorkspacePayload(encoded,now=Date.now()) {
19
+ export function decodeWorkspacePayload(encoded,now=Date.now(),env={}) {
6
20
  if(typeof encoded!=='string' || encoded.length>32768 || !/^[A-Za-z0-9_-]+$/.test(encoded.trim()))throw Error('Invalid private workspace payload');
7
21
  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');
22
+ const allowed=['version','appOrigin','hostname','rootName','fullName','name','surname','connectorToken','invitation','serverCid','challenge','renewal'];
23
+ if(!p || typeof p!=='object' || Array.isArray(p) || Object.keys(p).some(k=>!allowed.includes(k)) || p.version!==1 || !configuredOrigin(p.appOrigin,env) || !configuredHost(p.hostname,env) || !/^[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');
24
+ 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;}
25
+ if(p.renewal!==undefined && typeof p.renewal!=='boolean')throw Error('Invalid workspace renewal');
26
+ 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
27
  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
28
  return p;
13
29
  }
30
+ // A v1 envelope is local. A v2 grant is one-use, so it is parsed here and redeemed only after the
31
+ // payload-independent checks in runWorkspaceSetup (arguments, host state, read-only setup and Fleet
32
+ // settings preflight, Fleet/tunnel availability, dry run) pass.
33
+ function workspaceGrant(input,env){
34
+ if(typeof input!=='string' || !/^[A-Za-z0-9_-]{1,32768}$/.test(input.trim()))throw Error('Invalid workspace setup input');
35
+ let grant;try{grant=JSON.parse(Buffer.from(input.trim(),'base64url'));}catch{throw Error('Invalid workspace setup input');}
36
+ if(grant?.version===1)return null;
37
+ const now=Date.now();
38
+ if(grant?.version!==2 || Object.keys(grant).sort().join(',')!=='appOrigin,code,expiresAt,version'
39
+ || !configuredOrigin(grant.appOrigin,env)
40
+ || !/^[A-Za-z0-9_-]{43}$/.test(grant.code) || !Number.isSafeInteger(grant.expiresAt) || grant.expiresAt<=now || grant.expiresAt>now+16*60000)
41
+ throw Error('Workspace setup grant is invalid or expired; get a fresh command from the App');
42
+ return grant;
43
+ }
44
+ // Redeem only the minimal public grant; the private envelope stays in process/file transport.
45
+ async function redeemWorkspaceGrant(grant,request,env){
46
+ let response;
47
+ 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})});}
48
+ catch{throw Error('Workspace grant redemption could not be confirmed; check the App before requesting a fresh command');}
49
+ 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');}
50
+ let result;
51
+ try{
52
+ const chunks=[];let bytes=0;
53
+ if(!response.body)throw Error();
54
+ for await(const chunk of response.body){bytes+=chunk.length;if(bytes>33792)throw Error();chunks.push(chunk);}
55
+ result=JSON.parse(Buffer.concat(chunks).toString('utf8'));
56
+ }catch{throw Error('Invalid workspace setup response; get a fresh command from the App');}
57
+ if(typeof result?.payload!=='string' || !/^[A-Za-z0-9_-]{1,32768}$/.test(result.payload))throw Error('Invalid workspace setup response');
58
+ const payload=decodeWorkspacePayload(result.payload,Date.now(),env);
59
+ if(payload.appOrigin!==grant.appOrigin)throw Error('Workspace setup response origin mismatch');
60
+ return result.payload;
61
+ }
14
62
  export function extractWorkspaceArgs(args){
15
63
  const flags=['--setup-workspace','--setup-workspace-file','--workspace-fleet-bin','--fleet-settings'];const values={},rest=[];
16
64
  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
65
  if(values['--setup-workspace'] && values['--setup-workspace-file'])throw Error('Choose one private payload transport');
18
66
  return {values,rest};
19
67
  }
20
- export async function runWorkspaceSetup(args,effects,runSetup){
68
+ export async function runWorkspaceSetup(args,effects,runSetup,request=fetch){
21
69
  const migrateAppOrigin=args.includes('--workspace-migrate-app-origin');
22
70
  if(args.filter(arg=>arg==='--workspace-migrate-app-origin').length>1)throw Error('Duplicate workspace migration flag');
23
71
  const {values,rest}=extractWorkspaceArgs(args.filter(arg=>arg!=='--workspace-migrate-app-origin'));let encoded;
24
72
  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
73
  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
74
  else encoded=values['--setup-workspace'];
27
- const p=decodeWorkspacePayload(encoded),fleetBin=values['--workspace-fleet-bin'] || 'ours-fleet';
75
+ const authority={OURS_ACCOUNT_ORIGIN:effects.env?.OURS_ACCOUNT_ORIGIN,OURS_WORKSPACE_HOST:effects.env?.OURS_WORKSPACE_HOST,OURS_WORKSPACE_DOMAIN:effects.env?.OURS_WORKSPACE_DOMAIN};
76
+ const grant=workspaceGrant(encoded,authority);
77
+ let p=grant?null:decodeWorkspacePayload(encoded,Date.now(),authority);const fleetBin=values['--workspace-fleet-bin'] || 'ours-fleet';
28
78
  const parsed=parseSetupArgs(rest,{home:effects.home,validate:false});
29
79
  if(parsed.scope==='server')throw Error('Workspace setup requires all or client scope');
30
80
  if(parsed.identityName!==undefined || parsed.integrations!==undefined)throw Error('Workspace setup supplies identity and client integration selection');
@@ -43,33 +93,54 @@ export async function runWorkspaceSetup(args,effects,runSetup){
43
93
  const stat=lstatSync(marker);
44
94
  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
95
  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
96
  }
97
+ 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)');};
98
+ if(p)resumable();
48
99
  const preserveProfile=existing && !pending;
49
100
  if(existing && parsed.scope && parsed.scope!=='client')throw Error('Existing workspace setup requires client scope; root identity was not changed');
50
101
  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
102
  const options=[...rest];
52
103
  if(!parsed.scope)options.push('--scope',existing?'client':'all');
53
104
  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);}
105
+ if(!existing){if(!parsed.mode)options.push('--mode','docker');if(!parsed.stateDir)options.push('--state-dir',root);}
55
106
  options.push('--integrations','none');
56
- parseSetupArgs(options,{home:effects.home});
57
- if(preserveProfile){
107
+ // The App assigns the root identity on redemption. Before that, a well-formed stand-in validates the
108
+ // remaining options; explicit username/hostname options derive their own identity instead.
109
+ const setupOptions=identity=>existing || identity===undefined?options:[...options,'--identity-name',identity];
110
+ const standIn=parsed.localUsername===undefined?'workspace@preview':undefined;
111
+ parseSetupArgs(setupOptions(p?.rootName ?? standIn),{home:effects.home});
112
+ const fleetHome=effects.env?.OURS_FLEET_HOME || effects.home,fleetConfig=join(fleetHome,'fleet.yaml');
113
+ // Fresh setup and Fleet initialization would reject these only after redemption.
114
+ if(grant)await preflightSetup(existing?null:setupOptions(standIn),effects,{fleetSettingsPath:existsSync(fleetConfig)?undefined:fleetSettings});
115
+ const capable=async capability=>{
58
116
  const version=await effects.run(fleetBin,['version','--json'],{sensitive:true});
59
117
  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
- }
118
+ return version.ok && Array.isArray(info?.capabilities) && info.capabilities.includes(capability);
119
+ };
120
+ const optionalProfile=()=>!preserveProfile && Boolean(p.fullName || !p.name || !p.surname);
121
+ 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':''));};
122
+ if(p)await requireOptionalProfile();
123
+ if(preserveProfile && !await capable('workspace.enroll.preserve-profile-v1'))throw Error('Existing-host setup requires a profile-preserving Fleet release; nothing was changed');
62
124
  const help=await effects.run(fleetBin,['workspace-enroll','--help'],{sensitive:true});if(!help.ok)throw Error('Fleet workspace enrollment is unavailable');
63
125
  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;}
126
+ if(options.includes('--dry-run')){
127
+ if(grant)effects.out('Preview only: the workspace setup grant was not redeemed; this command remains usable until it expires.');
128
+ if(!existing)return runSetup(setupOptions(p?.rootName ?? standIn),effects);return 0;
129
+ }
130
+ if(grant){
131
+ // Checks below depend on the private envelope, so a failure here leaves the grant spent.
132
+ encoded=await redeemWorkspaceGrant(grant,request,authority);p=decodeWorkspacePayload(encoded,Date.now(),authority);
133
+ resumable();
134
+ parseSetupArgs(setupOptions(p.rootName),{home:effects.home});
135
+ await requireOptionalProfile();
136
+ }
65
137
  if(!existing){
66
138
  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;
139
+ const result=await runSetup(setupOptions(p.rootName),effects);if(result!==0)return result;
68
140
  }
69
141
  const selected=existingProfile || effects.readManagedClientProfile();if(!selected)throw Error('Workspace client profile was not installed');
70
- const env={OURS_CONFIG:existingProfile || managedPath};
142
+ const env={...authority,OURS_CONFIG:existingProfile || managedPath};
71
143
  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
144
  if(!existsSync(fleetConfig)){
74
145
  const initArgs=['init',...(fleetSettings?['--settings',fleetSettings]:[])];
75
146
  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.53",
3
+ "version": "1.2.1-nightly.55",
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",