@ours.network/install 1.2.1-nightly.6 → 1.2.1-nightly.60
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 +178 -0
- package/README.md +573 -9
- package/ROOTLESS_PODMAN_VALIDATION.md +210 -0
- package/assets/Dockerfile +15 -12
- package/assets/Dockerfile.gateway +5 -0
- package/assets/docker-compose.yaml +8 -1
- package/assets/fleet-settings.example.json +48 -0
- package/assets/gateway-entrypoint.sh +37 -0
- package/assets/release-lock.json +1222 -4517
- package/assets/release.json +37 -19
- package/assets/scripts/build/build-common.mjs +10 -1
- package/assets/scripts/build/build-sdk.mjs +6 -1
- package/assets/scripts/maintenance/build-context.mjs +1 -1
- package/assets/scripts/maintenance/daemon-owner.mjs +15 -0
- package/assets/scripts/maintenance/docker-layout-conversion.mjs +22 -7
- package/assets/scripts/maintenance/recover-notifications.mjs +36 -0
- package/assets/scripts/maintenance/release-graph.mjs +18 -1
- package/assets/scripts/maintenance/state-operation.mjs +76 -8
- package/assets/scripts/runtime/README.md +7 -0
- package/assets/scripts/runtime/client-setup.mjs +105 -20
- package/assets/scripts/runtime/daemon-client-prefix.mjs +115 -0
- package/assets/scripts/runtime/dependency-ready.mjs +13 -0
- package/assets/scripts/runtime/diagnostics.mjs +72 -0
- package/assets/scripts/runtime/entrypoint.sh +5 -1
- package/assets/scripts/runtime/health-messenger.mjs +7 -6
- package/assets/scripts/runtime/healthcheck.mjs +49 -15
- package/assets/scripts/runtime/notifications-gateway.mjs +90 -0
- package/assets/scripts/runtime/recover.mjs +202 -0
- package/assets/scripts/runtime/start-cowork.sh +5 -0
- package/assets/scripts/runtime/start-messenger.sh +29 -4
- package/assets/scripts/runtime/start-telegram.sh +5 -0
- package/assets/scripts/runtime/supervise.mjs +35 -0
- package/assets/sources.json +54 -28
- package/install.mjs +7 -2
- package/lib/boot-readiness.mjs +96 -0
- package/lib/build-transition.mjs +16 -0
- package/lib/client-cli.mjs +127 -0
- package/lib/container-engine.mjs +127 -0
- package/lib/diagnostics.mjs +1 -0
- package/lib/docker-conversion-runtime.mjs +7 -4
- package/lib/docker-layout-installation.mjs +2 -1
- package/lib/docker-recovery.mjs +60 -0
- package/lib/docker-runtime-repair.mjs +49 -14
- package/lib/effects.mjs +482 -140
- package/lib/gateway-transition.mjs +87 -0
- package/lib/gateway.mjs +227 -0
- package/lib/legacy-migration.mjs +13 -2
- package/lib/orchestrate-uninstall.mjs +23 -6
- package/lib/orchestrate.mjs +335 -44
- package/lib/ownership.mjs +63 -0
- package/lib/plan.mjs +37 -11
- package/lib/podman-preflight.mjs +40 -0
- package/lib/product.mjs +69 -0
- package/lib/removal-plan.mjs +437 -0
- package/lib/removal.mjs +749 -0
- package/lib/server-onboarding.mjs +182 -16
- package/lib/server-ports.mjs +17 -0
- package/lib/setup-options.mjs +119 -29
- package/lib/setup.mjs +93 -22
- package/lib/target.mjs +24 -8
- package/lib/uninstall.mjs +2 -2
- package/lib/usage.mjs +35 -9
- package/lib/welcome.mjs +219 -0
- package/lib/workspace-setup.mjs +154 -0
- package/package.json +4 -2
package/assets/release.json
CHANGED
|
@@ -1,43 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
3
|
"channel": "nightly",
|
|
4
|
-
"installerVersion": "1.2.1-nightly.
|
|
4
|
+
"installerVersion": "1.2.1-nightly.60",
|
|
5
5
|
"packages": {
|
|
6
6
|
"@ours.network/sdk": {
|
|
7
|
-
"version": "
|
|
8
|
-
"integrity": "sha512-
|
|
7
|
+
"version": "4.1.1-nightly.2",
|
|
8
|
+
"integrity": "sha512-5wN1tWvS0ZoJ05doEkZhnsr4FFlCvOddbSh2pWo3sPWrCmeGCyH/yJC0dcI05bgWpYYnI8hkD6HsaanEMgo5ig=="
|
|
9
9
|
},
|
|
10
10
|
"@ours.network/cli": {
|
|
11
|
-
"version": "
|
|
12
|
-
"integrity": "sha512-
|
|
11
|
+
"version": "3.1.1-nightly.2",
|
|
12
|
+
"integrity": "sha512-I7GUnNRazl+UI6c+J6aZ28mrByGzcB+0mOuL5L5j5T1fG67nqPnruGntDTTSCb9IToXsK9yNsEh6KSpoMlqGEg=="
|
|
13
13
|
},
|
|
14
14
|
"@ours.network/tg-connector": {
|
|
15
|
-
"version": "1.0.1-nightly.
|
|
16
|
-
"integrity": "sha512
|
|
15
|
+
"version": "1.0.1-nightly.14",
|
|
16
|
+
"integrity": "sha512-7M1nlEP7u+Cx0tGTIyGa/Lreul9OWIoI4sRWyg4z9nGWnpvSRUWcDFN04UfNlmQ3GVnoU14rRdBO1lVNPTPT/g=="
|
|
17
17
|
},
|
|
18
18
|
"@ours.network/cowork": {
|
|
19
|
-
"version": "1.3.
|
|
20
|
-
"integrity": "sha512-
|
|
19
|
+
"version": "1.3.4-nightly.20261019.ebbff0f",
|
|
20
|
+
"integrity": "sha512-Zm6jELDgpQ/oxIOVupq254TT5LLOt62UUpZD10yZ10DLMMJB4qyHLgPgd7KCCusy9ecUTcBs7IIfsxS/rfcISg=="
|
|
21
21
|
},
|
|
22
22
|
"@ours.network/messenger-server": {
|
|
23
|
-
"version": "1.0.31-nightly.
|
|
24
|
-
"integrity": "sha512-
|
|
23
|
+
"version": "1.0.31-nightly.23",
|
|
24
|
+
"integrity": "sha512-iaLHvUziO8z3HDEO2W9zpKMhlET1/SdGGJOrQvbVgxms7Ac0XwiHqr5EqJVvKQaLcoMRZAhpvUXkED/HPyRwrQ=="
|
|
25
|
+
},
|
|
26
|
+
"@ours.network/notifications": {
|
|
27
|
+
"version": "0.3.1-nightly.6",
|
|
28
|
+
"integrity": "sha512-ydLGi7RpJkrSis2Q3youemilwTEJB3xR9h7SzNJxb3q3PDCw9wJpCIQjDylYjGNwVHRKoxqxzybi1+xUyARz1w=="
|
|
25
29
|
},
|
|
26
30
|
"@ours.network/fleet": {
|
|
27
|
-
"version": "1.2.0-nightly.
|
|
28
|
-
"integrity": "sha512-
|
|
31
|
+
"version": "1.2.0-nightly.76",
|
|
32
|
+
"integrity": "sha512-WdmIB7ozrpu92C52pO34e4RJTk3CO2Yjw5jOICeZfxbmYMU2A9S9/YtbxX2WEg5Tpn0vG/7Z98ZUxafztOcwGw=="
|
|
29
33
|
},
|
|
30
34
|
"@ours.network/mcp": {
|
|
31
|
-
"version": "1.2.0-nightly.
|
|
32
|
-
"integrity": "sha512-
|
|
35
|
+
"version": "1.2.0-nightly.16",
|
|
36
|
+
"integrity": "sha512-ZwMXnvcfThrreMJMOALCpznU66SsvM5Gqeo/m8s/xyUWHCsEPXUeFvxn2iTVLzVcSj7ujfKZqCY5S+TL4rF90w=="
|
|
33
37
|
},
|
|
34
38
|
"@ours.network/codex": {
|
|
35
|
-
"version": "1.2.0-nightly.
|
|
36
|
-
"integrity": "sha512-
|
|
39
|
+
"version": "1.2.0-nightly.16",
|
|
40
|
+
"integrity": "sha512-o3Zh70/kOkF+KJGx+CYJjDAJAZfYYayZNPPj+KBn3CtPgJY+qD2md06s9E2vlbtsakSi1P11dt/I5/jC8Gif9g=="
|
|
37
41
|
},
|
|
38
42
|
"@ours.network/claude-code": {
|
|
39
|
-
"version": "1.2.0-nightly.
|
|
40
|
-
"integrity": "sha512-
|
|
43
|
+
"version": "1.2.0-nightly.16",
|
|
44
|
+
"integrity": "sha512-MPinVZXlbFEbt2yqCuj4ckNByxzF3jEm9XzEUWbMoM/br0SLdPb7KipeZA3goMXZiMu9oURQU5iCvlMWCb1XIQ=="
|
|
45
|
+
},
|
|
46
|
+
"@ours.network/daemon": {
|
|
47
|
+
"version": "4.1.1-nightly.2",
|
|
48
|
+
"integrity": "sha512-GXMDhq4hB5WuwW2mhOAhRPJP2SnbyouenGomzq4hn0ipUZ97zU7Z32/AjtDia860qtf7fz4lykk6ZZP6u3CEGw=="
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"hostCli": {
|
|
52
|
+
"@ours.network/sdk": {
|
|
53
|
+
"version": "4.1.1-nightly.2",
|
|
54
|
+
"integrity": "sha512-5wN1tWvS0ZoJ05doEkZhnsr4FFlCvOddbSh2pWo3sPWrCmeGCyH/yJC0dcI05bgWpYYnI8hkD6HsaanEMgo5ig=="
|
|
55
|
+
},
|
|
56
|
+
"@ours.network/cli": {
|
|
57
|
+
"version": "3.1.1-nightly.2",
|
|
58
|
+
"integrity": "sha512-I7GUnNRazl+UI6c+J6aZ28mrByGzcB+0mOuL5L5j5T1fG67nqPnruGntDTTSCb9IToXsK9yNsEh6KSpoMlqGEg=="
|
|
41
59
|
}
|
|
42
60
|
}
|
|
43
61
|
}
|
|
@@ -7,7 +7,16 @@ export const ROOT = resolve(process.env.OURS_BUILD_ROOT || '/opt/ours');
|
|
|
7
7
|
export const SOURCE_ROOT = resolve(process.env.OURS_SOURCE_ROOT || '/src');
|
|
8
8
|
export const OUT = join(ROOT, 'docker/vendor');
|
|
9
9
|
export const CONFIG = JSON.parse(readFileSync(join(ROOT, 'sources.json'), 'utf8'));
|
|
10
|
-
|
|
10
|
+
// Notifications joined the server set later; retained selections without it still build.
|
|
11
|
+
// A plugin-only server selection names only sdk, cli and daemon, and builds only those.
|
|
12
|
+
const APPLICATIONS = ['tg-connector', 'cowork', 'messenger-server', 'notifications'];
|
|
13
|
+
export const SELECTED = new Set((process.env.OURS_BUILD_PACKAGES || ['sdk', 'cli', 'daemon',
|
|
14
|
+
...APPLICATIONS.filter(name => name !== 'notifications' || CONFIG.packages?.['@ours.network/notifications'])
|
|
15
|
+
.filter(name => !isDaemonOnly(CONFIG) || CONFIG.packages?.['@ours.network/' + name])].join(',')).split(',').map(name => '@ours.network/' + name));
|
|
16
|
+
function isDaemonOnly(config) {
|
|
17
|
+
const names = Object.keys(config.packages ?? {}).sort().join(',');
|
|
18
|
+
return names === '@ours.network/cli,@ours.network/daemon,@ours.network/sdk';
|
|
19
|
+
}
|
|
11
20
|
export const inheritedLock = process.env.OURS_INSTALLER_LOCK_FD === '3' ? [3] : [];
|
|
12
21
|
export const run = (args, cwd) => execFileSync(args[0], args.slice(1), { cwd, stdio: ['inherit', 'inherit', 'inherit', ...inheritedLock] });
|
|
13
22
|
export const capture = (args, cwd, env = process.env) => execFileSync(args[0], args.slice(1), { cwd, env, encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit', ...inheritedLock] });
|
|
@@ -2,8 +2,13 @@ import { join } from 'node:path';
|
|
|
2
2
|
import { SOURCE_ROOT, SELECTED, pack, run } from './build-common.mjs';
|
|
3
3
|
const source = join(SOURCE_ROOT, 'sdk');
|
|
4
4
|
run(['npm', 'ci', '--no-audit', '--no-fund'], source);
|
|
5
|
-
run(['bash', 'scripts/compile-mufl.sh'], source);
|
|
5
|
+
if (SELECTED.has('@ours.network/daemon')) run(['bash', 'scripts/compile-mufl.sh'], source);
|
|
6
6
|
run(['npm', 'run', 'build'], source);
|
|
7
7
|
if (SELECTED.has('@ours.network/cli')) run(['npm', 'run', 'build:cli'], source);
|
|
8
8
|
pack(source, '@ours.network/sdk', 'sdk');
|
|
9
9
|
pack(join(source, 'packages/cli'), '@ours.network/cli', 'sdk');
|
|
10
|
+
|
|
11
|
+
if (SELECTED.has('@ours.network/daemon')) {
|
|
12
|
+
run(['npm', 'run', 'build:daemon'], source);
|
|
13
|
+
pack(join(source, 'packages/daemon'), '@ours.network/daemon', 'sdk');
|
|
14
|
+
}
|
|
@@ -8,7 +8,7 @@ import { semanticRecordEqual } from './provenance-compare.mjs';
|
|
|
8
8
|
export const BASE_RECORDS = ['package-lock.json', 'dependency-tree.json'];
|
|
9
9
|
export const CONTEXT = 'build-context.json';
|
|
10
10
|
const admitted = new WeakMap();
|
|
11
|
-
const packages = new Set(['sdk', 'cli', 'mcp', 'tg-connector', 'cowork', 'messenger-server', 'fleet', 'codex', 'claude-code', 'install'].map(n => '@ours.network/' + n));
|
|
11
|
+
const packages = new Set(['sdk', 'cli', 'daemon', 'mcp', 'tg-connector', 'cowork', 'messenger-server', 'notifications', 'fleet', 'codex', 'claude-code', 'install'].map(n => '@ours.network/' + n));
|
|
12
12
|
const digest = (bytes, algorithm = 'sha256', encoding = 'hex') => createHash(algorithm).update(bytes).digest(encoding);
|
|
13
13
|
const fail = text => { throw new Error(`Build context: ${text}`); };
|
|
14
14
|
const keys = (v, expected) => v && !Array.isArray(v) && typeof v === 'object' && Object.keys(v).sort().join('\0') === [...expected].sort().join('\0');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
// Native callers provide an exact selected executable. Compose mounts the
|
|
5
|
+
// selected runtime and supplies its bin directory, including retained releases.
|
|
6
|
+
export function daemonOwner(env = process.env) {
|
|
7
|
+
if (env.OURS_CLI_PATH) return env.OURS_CLI_PATH;
|
|
8
|
+
const bin = env.OURS_DAEMON_BIN_DIR;
|
|
9
|
+
if (!bin) throw new Error('daemon maintenance requires its selected executable or bin directory');
|
|
10
|
+
const daemon = join(bin, 'ours-daemon');
|
|
11
|
+
if (existsSync(daemon)) return daemon;
|
|
12
|
+
const legacy = join(bin, 'ours');
|
|
13
|
+
if (existsSync(legacy)) return legacy;
|
|
14
|
+
throw new Error('selected runtime contains no daemon administrator');
|
|
15
|
+
}
|
|
@@ -6,6 +6,8 @@ import { pathToFileURL } from 'node:url';
|
|
|
6
6
|
import { copyPrivateTree, scanSource, createArchive, validateArchive } from './state-archive.mjs';
|
|
7
7
|
import { publishNoReplace } from './state-native.mjs';
|
|
8
8
|
|
|
9
|
+
import { daemonOwner } from './daemon-owner.mjs';
|
|
10
|
+
|
|
9
11
|
const COMPONENTS = ['daemon', 'telegram', 'cowork', 'messenger'];
|
|
10
12
|
import { recordNames, readBuildRecords, validateBuildRecordSet } from './build-context.mjs';
|
|
11
13
|
const DAEMON_STATE = '/var/lib/ours';
|
|
@@ -99,11 +101,21 @@ export function bindDockerLayout(staging, options) {
|
|
|
99
101
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
/** The installation's applications: all four, or the daemon alone for collaboration tools. */
|
|
105
|
+
export function selectedComponents(env = process.env) {
|
|
106
|
+
const raw = env.OURS_SERVER_APPLICATIONS;
|
|
107
|
+
if (raw === undefined || raw === '') return COMPONENTS;
|
|
108
|
+
const selected = raw.split(',');
|
|
109
|
+
if (selected[0] !== 'daemon' || new Set(selected).size !== selected.length || selected.some(name => !COMPONENTS.includes(name))) throw new Error('invalid OURS_SERVER_APPLICATIONS selection');
|
|
110
|
+
return selected;
|
|
111
|
+
}
|
|
112
|
+
|
|
102
113
|
/** Offline validation also covers components intentionally left stopped. */
|
|
103
114
|
export function validateDockerLayout(tree, options) {
|
|
115
|
+
const components = options.components ?? COMPONENTS;
|
|
104
116
|
validateBuildRecordSet(options.provenance);
|
|
105
117
|
scanSource(tree, options);
|
|
106
|
-
for (const component of
|
|
118
|
+
for (const component of components) {
|
|
107
119
|
if (fs.readdirSync(join(tree, component, '.ours-provenance')).sort().join() !== recordNames(options.provenance).sort().join()) throw new Error('Mixed component provenance');
|
|
108
120
|
for (const name of recordNames(options.provenance)) {
|
|
109
121
|
if (!privateBytes(join(tree, component, '.ours-provenance', name), options).equals(options.provenance[name])) {
|
|
@@ -113,17 +125,19 @@ export function validateDockerLayout(tree, options) {
|
|
|
113
125
|
const config = join(tree, component, 'config.json');
|
|
114
126
|
if (fs.existsSync(config)) objectAt(config, options);
|
|
115
127
|
}
|
|
128
|
+
// Fresh managed installs keep the MCP profile separately until configured.
|
|
129
|
+
// Retained embedded configuration, when present, must still match exactly.
|
|
116
130
|
const daemon = objectAt(join(tree, 'daemon/config.json'), options);
|
|
117
131
|
const profile = objectAt(join(tree, 'mcp/profile.json'), options);
|
|
118
132
|
validateProfile(profile, options.instanceId);
|
|
119
133
|
if (daemon.stateDir !== DAEMON_STATE || daemon.port !== 3050
|
|
120
|
-
|| daemon.networkMcp?.applicationConfigPath !== join(MCP_STATE, 'config.json')
|
|
121
|
-
|
|
122
|
-
|| objectAt(join(tree, 'cowork/config.json'), options).stateDir !== '/var/lib/ours-cowork') {
|
|
134
|
+
|| (daemon.networkMcp !== undefined && (daemon.networkMcp?.applicationConfigPath !== join(MCP_STATE, 'config.json')
|
|
135
|
+
|| JSON.stringify(daemon.networkMcp?.profile) !== JSON.stringify(profile)))
|
|
136
|
+
|| (components.includes('cowork') && objectAt(join(tree, 'cowork/config.json'), options).stateDir !== '/var/lib/ours-cowork')) {
|
|
123
137
|
throw new Error('Converted Docker deployment configuration is inconsistent');
|
|
124
138
|
}
|
|
125
139
|
if (fs.existsSync(join(tree, 'mcp/config.json'))) objectAt(join(tree, 'mcp/config.json'), options);
|
|
126
|
-
for (const path of ['daemon/daemon-token', ...
|
|
140
|
+
for (const path of ['daemon/daemon-token', ...components.filter(name => name !== 'daemon').map(name => `credentials/${name}/daemon-token`)]) {
|
|
127
141
|
if (!privateBytes(join(tree, path), options).length) throw new Error('Converted managed credential is empty');
|
|
128
142
|
}
|
|
129
143
|
}
|
|
@@ -207,16 +221,17 @@ export async function runDockerLayoutCommand(argv, env = process.env) {
|
|
|
207
221
|
const build = env.OURS_BUILD_ROOT || '/opt/ours';
|
|
208
222
|
const options = {
|
|
209
223
|
uid: process.getuid(), gid: process.getgid(), instanceId: env.OURS_DAEMON_ID,
|
|
210
|
-
cli:
|
|
224
|
+
cli: daemonOwner({ OURS_DAEMON_BIN_DIR: '/opt/ours/node_modules/.bin', ...env }),
|
|
211
225
|
configPath: env.OURS_DAEMON_CONFIG || '/var/lib/ours/config.json',
|
|
212
226
|
provenance: readBuildRecords(build),
|
|
227
|
+
components: selectedComponents(env),
|
|
213
228
|
};
|
|
214
229
|
if (!options.uid || !options.gid) throw new Error('Conversion requires a non-root owner');
|
|
215
230
|
if (operation === 'cleanup') {
|
|
216
231
|
console.log(JSON.stringify({ emptyVolumes: cleanupDockerSource(source, options) }));
|
|
217
232
|
return;
|
|
218
233
|
}
|
|
219
|
-
try {
|
|
234
|
+
if (options.components.includes('cowork')) try {
|
|
220
235
|
execFileSync(env.OURS_COWORK_CLI_PATH || '/opt/ours/node_modules/.bin/ours-cowork', ['--json', 'prepare-backup'], {
|
|
221
236
|
env: { ...env, OURS_COWORK_CONFIG: env.OURS_COWORK_CONFIG || '/var/lib/ours-cowork/config.json',
|
|
222
237
|
OURS_COWORK_STATE_DIR: env.OURS_COWORK_STATE_DIR || '/var/lib/ours-cowork' },
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Non-secret retained build evidence arrives on stdin, never in argv/env. */
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { runStateOperation } from './state-operation.mjs';
|
|
6
|
+
|
|
7
|
+
// The shipped state-operation service is read_only without a /tmp tmpfs, and
|
|
8
|
+
// retained Compose definitions cannot gain one. /dev/shm stays a writable
|
|
9
|
+
// in-memory mount there, so evidence never enters the stored-state volume.
|
|
10
|
+
function scratch() {
|
|
11
|
+
for (const base of [tmpdir(), '/dev/shm']) {
|
|
12
|
+
try { return fs.mkdtempSync(join(base, 'ours-notifications-recovery-')); }
|
|
13
|
+
catch (error) { if (!['EROFS', 'EACCES', 'ENOENT'].includes(error.code)) throw error; }
|
|
14
|
+
}
|
|
15
|
+
throw new Error('No writable private scratch directory for recovery evidence');
|
|
16
|
+
}
|
|
17
|
+
const root = scratch();
|
|
18
|
+
fs.chmodSync(root, 0o700);
|
|
19
|
+
try {
|
|
20
|
+
const evidence = JSON.parse(fs.readFileSync(0, 'utf8'));
|
|
21
|
+
if (!evidence || Object.keys(evidence).sort().join(',') !== 'phase,previous,target'
|
|
22
|
+
|| !['prepared', 'state-updated', 'runtime-activated'].includes(evidence.phase)) throw new Error('Invalid recovery evidence');
|
|
23
|
+
for (const name of ['previous', 'target']) {
|
|
24
|
+
const records = evidence[name], names = Object.keys(records).sort();
|
|
25
|
+
if (!['dependency-tree.json,package-lock.json', 'build-context.json,dependency-tree.json,package-lock.json'].includes(names.join(','))) throw new Error('Invalid recovery record set');
|
|
26
|
+
const directory = join(root, name); fs.mkdirSync(directory, { mode: 0o700 });
|
|
27
|
+
for (const file of names) {
|
|
28
|
+
if (typeof records[file] !== 'string') throw new Error('Invalid recovery record bytes');
|
|
29
|
+
fs.writeFileSync(join(directory, file), Buffer.from(records[file], 'base64'), { flag: 'wx', mode: 0o600 });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const result = await runStateOperation(['recover-notifications', 'server', '--compatible'], {
|
|
33
|
+
...process.env, OURS_PREVIOUS_BUILD_ROOT: join(root, 'previous'), OURS_EXPECTED_BUILD_ROOT: join(root, 'target'), OURS_RECOVERY_PHASE: evidence.phase,
|
|
34
|
+
});
|
|
35
|
+
console.log(JSON.stringify(result));
|
|
36
|
+
} finally { fs.rmSync(root, { recursive: true }); }
|
|
@@ -20,10 +20,19 @@ export function releaseBinding(policy) {
|
|
|
20
20
|
if (release?.schema !== 1 || !['stable', 'nightly'].includes(release.channel)) fail('invalid release binding');
|
|
21
21
|
const pattern = release.channel === 'nightly' ? nightly : stable;
|
|
22
22
|
if (typeof release.installerVersion !== 'string' || !pattern.test(release.installerVersion)) fail('invalid installer version/channel');
|
|
23
|
-
if (
|
|
23
|
+
if (release.scope !== undefined && release.scope !== 'host-cli') fail('invalid release scope');
|
|
24
|
+
const required = release.scope === 'host-cli' ? ['@ours.network/cli', '@ours.network/sdk'] : [...names, ...['@ours.network/daemon', '@ours.network/notifications'].filter(name => release.packages?.[name])];
|
|
25
|
+
if (!release.packages || JSON.stringify(Object.keys(release.packages).sort()) !== JSON.stringify([...required].sort())) fail('release must select exactly the required ours packages');
|
|
26
|
+
if (release.scope === 'host-cli' && Object.hasOwn(release, 'hostCli')) fail('nested host CLI selection');
|
|
24
27
|
for (const [name, entry] of Object.entries(release.packages)) {
|
|
25
28
|
if (typeof entry?.version !== 'string' || !pattern.test(entry.version) || !/^sha512-[A-Za-z0-9+/]{86}==$/.test(entry.integrity ?? '')) fail(`invalid release artifact: ${name}`);
|
|
26
29
|
}
|
|
30
|
+
if (Object.hasOwn(release, 'hostCli')) {
|
|
31
|
+
if (!release.hostCli || Object.keys(release.hostCli).sort().join(',') !== '@ours.network/cli,@ours.network/sdk') fail('host CLI must select exactly CLI and SDK');
|
|
32
|
+
for (const [name, entry] of Object.entries(release.hostCli)) {
|
|
33
|
+
if (typeof entry?.version !== 'string' || !pattern.test(entry.version) || !/^sha512-[A-Za-z0-9+/]{86}==$/.test(entry.integrity ?? '')) fail(`invalid host CLI artifact: ${name}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
27
36
|
if (!policy.packages || !Object.keys(policy.packages).length) fail('missing release source selection');
|
|
28
37
|
for (const [name, entry] of Object.entries(policy.packages)) {
|
|
29
38
|
if (entry?.type !== 'npm' || entry.version !== release.packages[name]?.version || Object.keys(entry).sort().join(',') !== 'type,version') fail(`source selection differs from release: ${name}`);
|
|
@@ -92,3 +101,11 @@ export function verifyRuntimeRelease(root) {
|
|
|
92
101
|
if (!existsSync(path)) return { verified: false, reason: 'legacy runtime without sources' };
|
|
93
102
|
return verifyReleaseGraph(root, json(path));
|
|
94
103
|
}
|
|
104
|
+
|
|
105
|
+
/** The client command has its own exact dependency selection, never a graph bypass. */
|
|
106
|
+
export function hostCliPolicy(policy) {
|
|
107
|
+
const release = releaseBinding(policy);
|
|
108
|
+
if (!release?.hostCli) return null;
|
|
109
|
+
const { hostCli, ...base } = release;
|
|
110
|
+
return { release: { ...base, scope: 'host-cli', packages: hostCli }, packages: Object.fromEntries(Object.entries(hostCli).map(([name, p]) => [name, { type: 'npm', version: p.version }])) };
|
|
111
|
+
}
|
|
@@ -9,8 +9,18 @@ import { createArchive, extractArchive, validateArchive, scanSource, copyPrivate
|
|
|
9
9
|
import { exchange, tryLock, setMtimeNs } from './state-native.mjs';
|
|
10
10
|
import { recordNames, readBuildRecords, equalBuildRecords, initializeBuildMarker } from './build-context.mjs';
|
|
11
11
|
|
|
12
|
+
import { daemonOwner } from './daemon-owner.mjs';
|
|
13
|
+
|
|
12
14
|
const PROVENANCE = '.ours-provenance';
|
|
13
15
|
const APPLICATIONS = ['daemon', 'telegram', 'cowork', 'messenger'];
|
|
16
|
+
/** The installation's applications; plugin-only installations select only the daemon. */
|
|
17
|
+
export function selectedApplications(env = process.env) {
|
|
18
|
+
const raw = env.OURS_SERVER_APPLICATIONS;
|
|
19
|
+
if (raw === undefined || raw === '') return APPLICATIONS;
|
|
20
|
+
const selected = raw.split(',');
|
|
21
|
+
if (selected[0] !== 'daemon' || new Set(selected).size !== selected.length || selected.some(name => !APPLICATIONS.includes(name))) fail('invalid OURS_SERVER_APPLICATIONS selection');
|
|
22
|
+
return selected;
|
|
23
|
+
}
|
|
14
24
|
const exists = path => { try { fs.lstatSync(path); return true; } catch (e) { if (e.code === 'ENOENT') return false; throw e; } };
|
|
15
25
|
const canonical = path => exists(path) ? fs.realpathSync(path) : join(canonical(dirname(path)), basename(path));
|
|
16
26
|
const sameRecords = (a, b) => recordNames(a).length === recordNames(b).length && recordNames(a).every(name => a[name].equals(b[name]));
|
|
@@ -24,22 +34,25 @@ export async function runStateOperation(argv, env = process.env, checkpoints = {
|
|
|
24
34
|
if (!value || resolve(value) !== value || canonical(value) !== value) fail(`${name} must select an absolute canonical path`);
|
|
25
35
|
return value;
|
|
26
36
|
};
|
|
37
|
+
const applications = selectedApplications(env);
|
|
27
38
|
const state = selected('OURS_STATE_ROOT'), live = selected('OURS_LIVE_ROOT'), build = selected('OURS_BUILD_ROOT');
|
|
28
39
|
if ([state, build].some(path => path === live || path.startsWith(live + '/'))) fail('maintenance and build records must be outside live application state');
|
|
29
40
|
const backups = join(state, 'backups'), maintenance = join(state, '.maintenance');
|
|
30
41
|
const domain = argv[1];
|
|
31
42
|
if (![...APPLICATIONS, 'server'].includes(domain)) fail('select server, daemon, telegram, cowork or messenger');
|
|
43
|
+
if (domain !== 'server' && !applications.includes(domain)) fail(`${domain} is not part of this installation`);
|
|
32
44
|
if (Object.hasOwn(env, 'OURS_STATE_DOMAIN') && env.OURS_STATE_DOMAIN !== domain) fail('selected volume domain does not match operation');
|
|
33
45
|
const compatible = argv.at(-1) === '--compatible';
|
|
34
46
|
if (compatible) argv = argv.slice(0, -1);
|
|
35
47
|
const operation = argv[0];
|
|
36
48
|
const paired = domain === 'daemon' && ['backup', 'restore', 'reset'].includes(operation);
|
|
37
49
|
const commonTree = domain === 'server' || paired;
|
|
38
|
-
|
|
39
|
-
if (
|
|
50
|
+
const recovery = operation === 'recover-notifications' && domain === 'server' && compatible;
|
|
51
|
+
if (compatible && !['restore', 'update'].includes(operation) && !recovery) fail('compatibility attestation applies only to update or restore');
|
|
52
|
+
if (domain === 'server' && !['backup', 'restore', 'update', 'rebuild'].includes(operation) && !recovery) fail('full-server scope supports only backup, restore, update and rebuild');
|
|
40
53
|
if (operation === 'rebuild' && domain !== 'server') fail('rebuild selects the complete server');
|
|
41
54
|
const adopt = operation === 'init' && argv[2] === '--adopt-existing';
|
|
42
|
-
const valid = (['init', 'update', 'rebuild'].includes(operation) && argv.length === 2) || (adopt && argv.length === 3) || (['backup', 'restore'].includes(operation) && argv.length === 3) || (operation === 'reset' && argv.length === 3 && argv[2] === '--confirm');
|
|
55
|
+
const valid = ((['init', 'update', 'rebuild'].includes(operation) || recovery) && argv.length === 2) || (adopt && argv.length === 3) || (['backup', 'restore'].includes(operation) && argv.length === 3) || (operation === 'reset' && argv.length === 3 && argv[2] === '--confirm');
|
|
43
56
|
if (!valid) fail('usage: init DOMAIN | backup DOMAIN LABEL | restore DOMAIN LABEL | reset DOMAIN --confirm | update DOMAIN');
|
|
44
57
|
const uid = process.getuid(), gid = process.getgid();
|
|
45
58
|
if (!uid || !gid) fail('state maintenance requires a non-root UID and GID');
|
|
@@ -73,6 +86,7 @@ export async function runStateOperation(argv, env = process.env, checkpoints = {
|
|
|
73
86
|
}
|
|
74
87
|
function prepare() {
|
|
75
88
|
if (!['server', 'cowork'].includes(domain) && !paired) return;
|
|
89
|
+
if (!applications.includes('cowork')) return;
|
|
76
90
|
if (!env.OURS_COWORK_CLI_PATH || !env.OURS_COWORK_CONFIG) fail('Cowork maintenance requires its selected executable and configuration');
|
|
77
91
|
owner([env.OURS_COWORK_CLI_PATH, '--json', 'prepare-backup'], { OURS_COWORK_CONFIG: env.OURS_COWORK_CONFIG });
|
|
78
92
|
}
|
|
@@ -85,7 +99,15 @@ export async function runStateOperation(argv, env = process.env, checkpoints = {
|
|
|
85
99
|
} catch (e) { fs.closeSync(fd); throw e; }
|
|
86
100
|
}
|
|
87
101
|
function validateTree(tree, records) {
|
|
88
|
-
const roots = domain === 'server' ?
|
|
102
|
+
const roots = domain === 'server' ? applications.map(name => join(tree, name)) : [tree];
|
|
103
|
+
// Notifications shares Messenger's service, but owns a separate state directory.
|
|
104
|
+
// Older installations/backups may contain only its empty mount placeholder.
|
|
105
|
+
// Include every retained notification generation in full-server maintenance.
|
|
106
|
+
if (domain === 'server' && exists(join(tree, 'notifications'))) {
|
|
107
|
+
const notifications = join(tree, 'notifications');
|
|
108
|
+
privateStat(notifications, true, 0o700);
|
|
109
|
+
if (exists(join(notifications, PROVENANCE))) roots.push(notifications);
|
|
110
|
+
}
|
|
89
111
|
for (const root of roots) if (!sameRecords(readRecords(join(root, PROVENANCE)), records)) fail('restored component provenance does not match the archive build');
|
|
90
112
|
if (domain === 'server') for (const name of ['mcp', 'credentials']) privateStat(join(tree, name), true, 0o700);
|
|
91
113
|
if (paired) privateStat(join(tree, '.mcp'), true, 0o700);
|
|
@@ -141,16 +163,16 @@ export async function runStateOperation(argv, env = process.env, checkpoints = {
|
|
|
141
163
|
fs.chmodSync(path, 0o600);
|
|
142
164
|
}
|
|
143
165
|
}
|
|
144
|
-
if (['server', 'cowork'].includes(domain)) bindConfig(join(tree, domain === 'server' ? 'cowork/config.json' : 'config.json'), env.OURS_COWORK_CONFIG, ['version', 'stateDir', 'rest']);
|
|
166
|
+
if (['server', 'cowork'].includes(domain) && applications.includes('cowork')) bindConfig(join(tree, domain === 'server' ? 'cowork/config.json' : 'config.json'), env.OURS_COWORK_CONFIG, ['version', 'stateDir', 'rest']);
|
|
145
167
|
}
|
|
146
168
|
function retainAuthority(staging) {
|
|
147
169
|
if (!['daemon', 'server'].includes(domain)) return;
|
|
148
|
-
if (!env.
|
|
170
|
+
if (!env.OURS_DAEMON_CONFIG) fail('daemon maintenance requires its selected executable and configuration');
|
|
149
171
|
const daemon = commonTree ? join(staging, 'daemon') : staging;
|
|
150
|
-
owner([env
|
|
172
|
+
owner([daemonOwner(env), 'config', 'access-retain', '--config', env.OURS_DAEMON_CONFIG, '--target-state-dir', daemon, '--json']);
|
|
151
173
|
if (!commonTree) return;
|
|
152
174
|
const credentials = join(live, 'credentials'), destination = join(staging, 'credentials');
|
|
153
|
-
for (const name of
|
|
175
|
+
for (const name of applications.filter(name => name !== 'daemon')) if (!privateStat(join(credentials, name, 'daemon-token'), false, 0o600).size) fail('current managed credential is empty');
|
|
154
176
|
fs.rmSync(destination, { recursive: true }); copyTree(credentials, destination);
|
|
155
177
|
}
|
|
156
178
|
function replace(staging) {
|
|
@@ -174,6 +196,52 @@ export async function runStateOperation(argv, env = process.env, checkpoints = {
|
|
|
174
196
|
try { if (!sameInode(fs.fstatSync(fd), fs.fstatSync(check))) fail('domain state changed while acquiring its lock'); }
|
|
175
197
|
finally { fs.closeSync(check); }
|
|
176
198
|
let records;
|
|
199
|
+
if (recovery) {
|
|
200
|
+
// Only the installer supplies the retained transition's previous and
|
|
201
|
+
// candidate records. Never infer compatibility from a mixed live tree.
|
|
202
|
+
const previous = readRecords(selected('OURS_PREVIOUS_BUILD_ROOT'), false);
|
|
203
|
+
const expected = readRecords(selected('OURS_EXPECTED_BUILD_ROOT'), false);
|
|
204
|
+
if (!sameRecords(target, expected)) fail('recovery runtime differs from the retained candidate');
|
|
205
|
+
const core = applications.map(name => readRecords(join(live, name, PROVENANCE)));
|
|
206
|
+
const oldCore = core.every(records => sameRecords(records, previous));
|
|
207
|
+
const newCore = core.every(records => sameRecords(records, target));
|
|
208
|
+
if (!newCore && !(env.OURS_RECOVERY_PHASE === 'prepared' && oldCore)) fail('recovery core provenance differs from the retained candidate');
|
|
209
|
+
for (const name of ['mcp', 'credentials']) privateStat(join(live, name), true, 0o700);
|
|
210
|
+
const notifications = join(live, 'notifications'), marker = join(notifications, PROVENANCE);
|
|
211
|
+
if (!exists(notifications)) return { stateUpdated: newCore };
|
|
212
|
+
privateStat(notifications, true, 0o700);
|
|
213
|
+
if (!exists(marker)) { scanSource(notifications, { uid, gid }); return { stateUpdated: newCore }; }
|
|
214
|
+
privateStat(marker, true, 0o700);
|
|
215
|
+
if (!fs.readdirSync(marker).length) { scanSource(notifications, { uid, gid }); return { stateUpdated: newCore }; }
|
|
216
|
+
const retained = readRecords(marker);
|
|
217
|
+
if (newCore && sameRecords(retained, target)) return { stateUpdated: true }; // Already repaired, including retries after exchange.
|
|
218
|
+
if (!sameRecords(retained, previous)) fail('recovery notification provenance differs from the retained previous build');
|
|
219
|
+
if (!newCore) return { stateUpdated: false }; // Prepared journal with untouched state: use the regular state operation.
|
|
220
|
+
prepare(); layout();
|
|
221
|
+
const archive = labelPath(`pre-notifications-recovery-${new Date().toISOString().replace(/[-:.]/g, '')}-${randomBytes(4).toString('hex')}`);
|
|
222
|
+
checkpoints.beforeBackup?.();
|
|
223
|
+
await createArchive(notifications, archive, { domain: 'notifications', uid, gid, provenance: previous });
|
|
224
|
+
checkpoints.afterBackup?.();
|
|
225
|
+
const staging = join(maintenance, `recovery-${randomBytes(12).toString('hex')}`);
|
|
226
|
+
try {
|
|
227
|
+
const entries = scanSource(live, { uid, gid });
|
|
228
|
+
copyTree(live, staging);
|
|
229
|
+
// Ordinary maintenance emits private copies; recovery retains every
|
|
230
|
+
// accepted payload mode and timestamp outside the replaced marker.
|
|
231
|
+
for (const entry of entries.reverse()) {
|
|
232
|
+
const path = entry.name === 'state' ? staging : join(staging, entry.name.slice(6));
|
|
233
|
+
fs.chmodSync(path, Number(entry.st.mode) & 0o777);
|
|
234
|
+
setMtimeNs(path, entry.st.mtimeNs);
|
|
235
|
+
}
|
|
236
|
+
const replacement = join(staging, 'notifications', PROVENANCE);
|
|
237
|
+
fs.rmSync(replacement, { recursive: true }); mkdir(replacement);
|
|
238
|
+
for (const name of recordNames(target)) writeRecord(join(replacement, name), target[name]);
|
|
239
|
+
setMtimeNs(dirname(replacement), fs.lstatSync(notifications, { bigint: true }).mtimeNs);
|
|
240
|
+
validateTree(staging, target);
|
|
241
|
+
replace(staging);
|
|
242
|
+
} finally { if (exists(staging)) fs.rmSync(staging, { recursive: true }); }
|
|
243
|
+
return { stateUpdated: true };
|
|
244
|
+
}
|
|
177
245
|
if (domain === 'server') { records = readRecords(join(live, 'daemon', PROVENANCE)); validateTree(live, records); }
|
|
178
246
|
else if (paired) { records = readRecords(join(live, 'daemon', PROVENANCE)); privateStat(join(live, 'mcp'), true, 0o700); }
|
|
179
247
|
else if (operation !== 'init') records = readRecords(join(live, PROVENANCE));
|
|
@@ -22,3 +22,10 @@ mode. Docker uses one named `server-storage` volume: `state/daemon`, `state/mcp`
|
|
|
22
22
|
Preparation mounts the storage root; running applications mount only their own
|
|
23
23
|
state children and selected credentials. Backups and maintenance staging are
|
|
24
24
|
outside `state/`. The owner-lock volume contains transient runtime locks.
|
|
25
|
+
|
|
26
|
+
`recover.mjs` supervises the locked entrypoints with timed health probes and three
|
|
27
|
+
automatic recovery attempts per container start. It kills the entire child group
|
|
28
|
+
and waits for lock release before a new generation. Exhaustion holds unhealthy
|
|
29
|
+
until explicit restart. `dependency-ready.mjs` waits for the authenticated pinned
|
|
30
|
+
daemon without consuming the consumer's failure circuit. Host boot still depends
|
|
31
|
+
on an independently configured Docker Engine or Desktop startup.
|