@ours.network/install 2.1.4 → 2.1.7
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/README.md +28 -48
- package/assets/Dockerfile +0 -1
- package/assets/docker-compose.yaml +0 -20
- package/assets/gateway-entrypoint.sh +3 -1
- package/assets/images.json +39 -0
- package/assets/release-lock.json +16 -16
- package/assets/release.json +1 -1
- package/assets/scripts/maintenance/README.md +2 -4
- package/assets/scripts/maintenance/docker-layout-conversion.mjs +16 -164
- package/assets/sources.json +1 -1
- package/lib/docker-context.mjs +28 -0
- package/lib/effects.mjs +44 -174
- package/lib/gateway.mjs +10 -4
- package/lib/image-acquisition.mjs +164 -0
- package/lib/managed-cli.mjs +2 -104
- package/lib/orchestrate-uninstall.mjs +2 -0
- package/lib/orchestrate.mjs +7 -26
- package/lib/plan.mjs +19 -36
- package/lib/prompt.mjs +2 -2
- package/lib/removal.mjs +17 -4
- package/lib/server-onboarding.mjs +6 -6
- package/lib/setup-options.mjs +165 -122
- package/lib/setup.mjs +60 -21
- package/lib/state-validation.mjs +98 -0
- package/lib/target.mjs +2 -0
- package/lib/usage.mjs +2 -4
- package/lib/welcome.mjs +5 -7
- package/package.json +1 -1
- package/assets/Dockerfile.gateway +0 -5
- package/assets/scripts/runtime/legacy-import.mjs +0 -103
- package/lib/docker-conversion-runtime.mjs +0 -100
- package/lib/docker-layout-installation.mjs +0 -63
- package/lib/layout-conversion.mjs +0 -297
- package/lib/legacy-migration.mjs +0 -213
- package/lib/legacy-state.mjs +0 -205
package/lib/legacy-state.mjs
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
import * as net from 'node:net';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
5
|
-
import { dirname, join, resolve, isAbsolute, sep } from 'node:path';
|
|
6
|
-
import { installationPaths } from './plan.mjs';
|
|
7
|
-
import { copyPrivateTree, scanSource } from '../assets/scripts/maintenance/state-archive.mjs';
|
|
8
|
-
import { publishNoReplace } from '../assets/scripts/maintenance/state-native.mjs';
|
|
9
|
-
|
|
10
|
-
const MARKER = '.ours-legacy-import.json';
|
|
11
|
-
const uid = () => process.getuid();
|
|
12
|
-
const ownership = () => ({ uid: uid(), gid: process.getgid() });
|
|
13
|
-
function canonical(path) {
|
|
14
|
-
if (typeof path !== 'string' || !isAbsolute(path) || resolve(path) !== path) throw Error('Legacy migration requires normalized absolute paths');
|
|
15
|
-
let cursor = path;
|
|
16
|
-
while (true) {
|
|
17
|
-
try { if (fs.realpathSync(cursor) !== cursor) throw Error('Legacy migration refuses symlink paths'); return path; }
|
|
18
|
-
catch (error) { if (error.code !== 'ENOENT') throw error; const parent = dirname(cursor); if (parent === cursor) throw error; cursor = parent; }
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function privatePath(path, directory = false) {
|
|
22
|
-
canonical(path); const stat = fs.lstatSync(path);
|
|
23
|
-
if (!(directory ? stat.isDirectory() : stat.isFile()) || stat.uid !== uid()
|
|
24
|
-
|| (stat.mode & 0o7777) !== (directory ? 0o700 : 0o600) || (!directory && stat.nlink !== 1))
|
|
25
|
-
throw Error('Legacy migration requires private owner-only regular files and directories');
|
|
26
|
-
return stat;
|
|
27
|
-
}
|
|
28
|
-
function objectFile(path) {
|
|
29
|
-
privatePath(path); const value = JSON.parse(fs.readFileSync(path, 'utf8'));
|
|
30
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) throw Error('Legacy configuration must be an object');
|
|
31
|
-
return value;
|
|
32
|
-
}
|
|
33
|
-
const contains = (parent, child) => parent === child || child.startsWith(parent + sep);
|
|
34
|
-
function inspectRoot(stateDir) {
|
|
35
|
-
const root = objectFile(join(stateDir, 'root.json'));
|
|
36
|
-
if (root.v !== 1 || typeof root.name !== 'string' || !root.name || root.name !== root.name.trim()
|
|
37
|
-
|| root.name.normalize('NFC') !== root.name || root.name.length > 64 || /[\x00-\x1f\x7f/\\]/.test(root.name)
|
|
38
|
-
|| ['.', '..', 'contact-book', 'root.json', 'bindings.json'].includes(root.name)) throw Error('Legacy root marker is invalid');
|
|
39
|
-
privatePath(join(stateDir, root.name), true);
|
|
40
|
-
for (const file of ['identity.key', 'state_data.bin']) if (privatePath(join(stateDir, root.name, file)).size === 0) throw Error('Legacy root identity is incomplete');
|
|
41
|
-
// CID and hierarchy are packet facts, not fields in root.json. The caller
|
|
42
|
-
// must compare authenticated identity-list results before/after activation.
|
|
43
|
-
return root.name;
|
|
44
|
-
}
|
|
45
|
-
export function inspectLegacyState(configPath, targetRoot) {
|
|
46
|
-
canonical(configPath); canonical(targetRoot);
|
|
47
|
-
const config = objectFile(configPath);
|
|
48
|
-
const defaultState = join(homedir(), '.ours');
|
|
49
|
-
if (config.stateDir === undefined && configPath !== join(defaultState, 'config.json')) throw Error('Custom legacy config requires explicit stateDir');
|
|
50
|
-
const stateDir = config.stateDir === undefined ? canonical(defaultState) : canonical(config.stateDir);
|
|
51
|
-
privatePath(stateDir, true);
|
|
52
|
-
if (contains(stateDir, targetRoot) || contains(targetRoot, stateDir) || contains(targetRoot, configPath)) throw Error('Legacy source and target roots must be disjoint');
|
|
53
|
-
if (config.database && (typeof config.database !== 'object' || Array.isArray(config.database)
|
|
54
|
-
|| (config.database.provider !== undefined && config.database.provider !== 'sqlite') || config.database.url))
|
|
55
|
-
throw Error('Legacy migration does not support external or non-SQLite history');
|
|
56
|
-
const entries = scanSource(stateDir, ownership());
|
|
57
|
-
if (entries.some(entry => entry.name.split('/').includes('.ours-provenance'))) throw Error('Legacy unmanaged migration does not support existing build provenance');
|
|
58
|
-
if (entries.some(entry => entry.name.endsWith('/history-postgresql.json'))) throw Error('Legacy migration cannot copy external PostgreSQL history');
|
|
59
|
-
if (fs.existsSync(join(stateDir, '.mcp'))) privatePath(join(stateDir, '.mcp'), true);
|
|
60
|
-
if (config.networkMcp !== undefined) {
|
|
61
|
-
const mcp = config.networkMcp;
|
|
62
|
-
if (!mcp || typeof mcp !== 'object' || Array.isArray(mcp)
|
|
63
|
-
|| mcp.applicationConfigPath !== join(stateDir, '.mcp/config.json')
|
|
64
|
-
|| !mcp.profile || mcp.profile.credentialPath !== join(stateDir, 'daemon-token'))
|
|
65
|
-
throw Error('Legacy migration requires embedded MCP configuration and credentials; external MCP paths are unsupported');
|
|
66
|
-
}
|
|
67
|
-
if (config.apiTokenDeliveryFiles !== undefined && (!Array.isArray(config.apiTokenDeliveryFiles)
|
|
68
|
-
|| config.apiTokenDeliveryFiles.some(path => path !== join(stateDir, 'daemon-token'))))
|
|
69
|
-
throw Error('Legacy migration does not support external token delivery paths');
|
|
70
|
-
return { configPath, stateDir, config, rootCid: null, rootName: inspectRoot(stateDir) };
|
|
71
|
-
}
|
|
72
|
-
const receipt = (source, record) => ({ sourceStateDir: source.stateDir, sourceConfigPath: source.configPath, targetRoot: record.root, rootName: source.rootName });
|
|
73
|
-
function writePrivate(path, value) {
|
|
74
|
-
fs.writeFileSync(path, JSON.stringify(value, null, 2) + '\n', { mode: 0o600 }); fs.chmodSync(path, 0o600);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function publishLegacyMcp(source, destination, expected, profile) {
|
|
78
|
-
canonical(destination);
|
|
79
|
-
if (fs.existsSync(destination)) {
|
|
80
|
-
privatePath(destination, true);
|
|
81
|
-
if (fs.existsSync(join(destination, MARKER))) {
|
|
82
|
-
if (JSON.stringify(objectFile(join(destination, MARKER))) !== JSON.stringify(expected)) throw Error('Legacy MCP destination receipt mismatch');
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
if (fs.readdirSync(destination).length) throw Error('Legacy MCP destination must be absent or empty');
|
|
86
|
-
}
|
|
87
|
-
const staging = join(dirname(destination), `.legacy-mcp-${randomUUID()}`);
|
|
88
|
-
try {
|
|
89
|
-
const embedded = join(source.stateDir, '.mcp');
|
|
90
|
-
if (fs.existsSync(embedded)) copyPrivateTree(embedded, staging, ownership());
|
|
91
|
-
else fs.mkdirSync(staging, { mode: 0o700 });
|
|
92
|
-
writePrivate(join(staging, 'profile.json'), profile);
|
|
93
|
-
writePrivate(join(staging, MARKER), expected);
|
|
94
|
-
scanSource(staging, ownership());
|
|
95
|
-
if (fs.existsSync(destination)) fs.rmdirSync(destination);
|
|
96
|
-
publishNoReplace(staging, destination);
|
|
97
|
-
} finally { fs.rmSync(staging, { recursive: true, force: true }); }
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Caller excludes source writers and owns installation exclusion through activation.
|
|
101
|
-
export function stageLegacyState(source, record) {
|
|
102
|
-
if (record.schema !== 2 || !['packages', 'docker'].includes(record.mode)
|
|
103
|
-
|| !Number.isInteger(record.port) || record.port < 1 || record.port > 65535) throw Error('Unsupported legacy migration destination');
|
|
104
|
-
const fresh = inspectLegacyState(source.configPath, record.root);
|
|
105
|
-
if (fresh.stateDir !== source.stateDir || fresh.rootName !== source.rootName) throw Error('Legacy source selection changed');
|
|
106
|
-
const paths = installationPaths(record);
|
|
107
|
-
const destination = paths.daemon, parent = dirname(destination);
|
|
108
|
-
canonical(destination); privatePath(parent, true);
|
|
109
|
-
const expected = receipt(fresh, record);
|
|
110
|
-
if (fs.existsSync(destination)) {
|
|
111
|
-
privatePath(destination, true);
|
|
112
|
-
if (fs.existsSync(join(destination, MARKER))) {
|
|
113
|
-
const saved = objectFile(join(destination, MARKER));
|
|
114
|
-
if (JSON.stringify(saved) !== JSON.stringify(expected) || inspectRoot(destination) !== fresh.rootName) throw Error('Legacy destination receipt does not match selected source');
|
|
115
|
-
const mcpReceipt = objectFile(join(paths.mcp, MARKER));
|
|
116
|
-
if (JSON.stringify(mcpReceipt) !== JSON.stringify(expected)) throw Error('Legacy MCP destination receipt does not match selected source');
|
|
117
|
-
return { ...expected, destination, reused: true };
|
|
118
|
-
}
|
|
119
|
-
if (fs.readdirSync(destination).length) throw Error('Legacy destination must be absent or empty');
|
|
120
|
-
}
|
|
121
|
-
const staging = join(parent, `.legacy-${randomUUID()}`);
|
|
122
|
-
try {
|
|
123
|
-
copyPrivateTree(fresh.stateDir, staging, ownership());
|
|
124
|
-
// Preserve the untouched source as the rollback copy. Only copied PID hints
|
|
125
|
-
// are discarded; opaque identities, authority, SQLite sidecars all survive.
|
|
126
|
-
for (const name of ['ours-cli-daemon.json', 'daemon.pid', 'startup-progress.json']) fs.rmSync(join(staging, name), { force: true });
|
|
127
|
-
const config = structuredClone(fresh.config);
|
|
128
|
-
config.stateDir = record.mode === 'docker' ? '/var/lib/ours' : destination;
|
|
129
|
-
config.port = record.mode === 'docker' ? 3050 : record.port; config.apiVisibility = 'owner';
|
|
130
|
-
delete config.apiToken; delete config.apiTokenDeliveryFiles;
|
|
131
|
-
config.networkMcp = {
|
|
132
|
-
profile: { endpoint: `http://127.0.0.1:${config.port}`, expectedInstanceId: record.instanceId, credentialPath: join(config.stateDir, 'daemon-token') },
|
|
133
|
-
applicationConfigPath: record.mode === 'docker' ? '/var/lib/ours-mcp/config.json' : join(paths.mcp, 'config.json'),
|
|
134
|
-
};
|
|
135
|
-
// Publish MCP separately before daemon publication. Its receipt allows a
|
|
136
|
-
// retry after an interrupted second rename, without overwriting live data.
|
|
137
|
-
publishLegacyMcp(fresh, paths.mcp, expected, config.networkMcp.profile);
|
|
138
|
-
writePrivate(join(staging, 'config.json'), config); writePrivate(join(staging, MARKER), expected);
|
|
139
|
-
scanSource(staging, ownership());
|
|
140
|
-
if (fs.existsSync(destination)) fs.rmdirSync(destination); // succeeds only for the empty skeleton
|
|
141
|
-
publishNoReplace(staging, destination);
|
|
142
|
-
return { ...expected, destination, reused: false };
|
|
143
|
-
} finally { fs.rmSync(staging, { recursive: true, force: true }); }
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
let Database;
|
|
147
|
-
export async function ensureLegacyLockSupport() {
|
|
148
|
-
if (!['linux', 'darwin'].includes(process.platform) || typeof process.getuid !== 'function') throw Error('Legacy migration requires Linux/macOS source locking');
|
|
149
|
-
try { ({ DatabaseSync: Database } = await import('node:sqlite')); }
|
|
150
|
-
catch { throw Error('Legacy migration requires Node with node:sqlite support; upgrade Node before stopping the source daemon'); }
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Protocol adapted from SDK src/internal/state-root-lock.ts: permanent SQLite
|
|
154
|
-
// guard serializes stale socket probe/unlink/rebind; socket ownership lasts for
|
|
155
|
-
// the callback. Never replace the guard inode or unlink on ambiguous probes.
|
|
156
|
-
function lockDirectory(path) {
|
|
157
|
-
try { fs.mkdirSync(path, { mode: 0o700 }); } catch (error) { if (error.code !== 'EEXIST') throw error; }
|
|
158
|
-
privatePath(path, true);
|
|
159
|
-
}
|
|
160
|
-
function probe(path) {
|
|
161
|
-
return new Promise(resolveProbe => {
|
|
162
|
-
const socket = net.createConnection(path); let finished = false;
|
|
163
|
-
const done = result => { if (finished) return; finished = true; socket.destroy(); resolveProbe(result); };
|
|
164
|
-
socket.setTimeout(1000);
|
|
165
|
-
socket.once('connect', () => done('live'));
|
|
166
|
-
socket.once('timeout', () => done('ambiguous'));
|
|
167
|
-
socket.once('error', error => done(['ECONNREFUSED', 'ENOENT'].includes(error.code) ? 'stale' : 'ambiguous'));
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
async function socketLock(stateDir, path) {
|
|
171
|
-
for (let attempt = 0; attempt < 8; attempt++) {
|
|
172
|
-
const server = net.createServer(socket => { socket.on('error', () => {}); socket.end(JSON.stringify({ pid: process.pid, stateDir, startedAt: new Date().toISOString() }) + '\n'); });
|
|
173
|
-
try {
|
|
174
|
-
await new Promise((accept, reject) => { server.once('error', reject); server.listen(path, () => { server.removeListener('error', reject); accept(); }); });
|
|
175
|
-
server.unref(); return server;
|
|
176
|
-
} catch (error) {
|
|
177
|
-
try { server.close(); } catch { /* not listening */ }
|
|
178
|
-
if (error.code !== 'EADDRINUSE') throw error;
|
|
179
|
-
const result = await probe(path);
|
|
180
|
-
if (result !== 'stale') throw Error(`Legacy source lock is ${result}; refusing to remove a potentially live owner`);
|
|
181
|
-
try { fs.unlinkSync(path); } catch (failure) { if (failure.code !== 'ENOENT') throw failure; }
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
throw Error('Could not acquire legacy source lock');
|
|
185
|
-
}
|
|
186
|
-
export async function withLegacyStateLock(stateDir, callback) {
|
|
187
|
-
await ensureLegacyLockSupport(); canonical(stateDir); privatePath(stateDir, true);
|
|
188
|
-
const base = `/tmp/ours-${uid()}`; lockDirectory(base); lockDirectory(join(base, 'locks'));
|
|
189
|
-
const path = join(base, 'locks', createHash('sha256').update(stateDir).digest('hex') + '.sock');
|
|
190
|
-
if (Buffer.byteLength(path) > 103) throw Error('Legacy lock socket path exceeds portable limit');
|
|
191
|
-
const guardPath = path + '.guard';
|
|
192
|
-
try { const fd = fs.openSync(guardPath, fs.constants.O_RDWR | fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_NOFOLLOW, 0o600); fs.closeSync(fd); }
|
|
193
|
-
catch (error) { if (error.code !== 'EEXIST') throw error; }
|
|
194
|
-
const before = privatePath(guardPath), guard = new Database(guardPath); let server;
|
|
195
|
-
try {
|
|
196
|
-
const after = privatePath(guardPath);
|
|
197
|
-
if (before.dev !== after.dev || before.ino !== after.ino || before.mode !== after.mode || before.uid !== after.uid) throw Error('Legacy acquisition guard changed');
|
|
198
|
-
guard.exec('PRAGMA busy_timeout=0; BEGIN EXCLUSIVE'); server = await socketLock(stateDir, path);
|
|
199
|
-
} finally { guard.close(); }
|
|
200
|
-
let closed = false;
|
|
201
|
-
const close = async () => { if (closed) return; closed = true; await new Promise(resolveClose => server.close(resolveClose)); };
|
|
202
|
-
if (callback === undefined) return { stateDir, close };
|
|
203
|
-
try { return await callback(); }
|
|
204
|
-
finally { await close(); }
|
|
205
|
-
}
|