@ours.network/install 2.1.3 → 2.1.6
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 +26 -46
- 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 +19 -19
- package/assets/release.json +3 -3
- package/assets/scripts/maintenance/README.md +2 -4
- package/assets/scripts/maintenance/docker-layout-conversion.mjs +16 -164
- package/assets/sources.json +4 -4
- 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/removal.mjs +17 -4
- package/lib/setup-options.mjs +31 -75
- package/lib/setup.mjs +4 -14
- 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/managed-cli.mjs
CHANGED
|
@@ -1,41 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
import {
|
|
3
|
-
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { createHash, randomUUID } from 'node:crypto';
|
|
1
|
+
/** The managed `ours` launcher bound to one installation record. */
|
|
2
|
+
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
6
3
|
|
|
7
4
|
const marker = '// ours-managed-cli-v1 ';
|
|
8
|
-
const backupName = 'managed-cli-original.json';
|
|
9
|
-
const sha = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
10
|
-
const uid = () => process.getuid();
|
|
11
5
|
function absolute(path) {
|
|
12
6
|
if (typeof path !== 'string' || !isAbsolute(path) || resolve(path) !== path || /[\r\n\0]/.test(path)) throw new Error('Managed CLI requires normalized absolute paths');
|
|
13
7
|
return path;
|
|
14
8
|
}
|
|
15
|
-
function owned(path, { directory = false, writable = false } = {}) {
|
|
16
|
-
const stat = lstatSync(path);
|
|
17
|
-
if (stat.uid !== uid() || (directory ? !stat.isDirectory() : (!stat.isFile() || stat.nlink !== 1)) || (stat.mode & 0o022)) throw new Error(`Managed CLI refuses foreign or unsafe ownership: ${path}`);
|
|
18
|
-
if (directory && realpathSync(path) !== path) throw new Error('Managed CLI directory must be canonical');
|
|
19
|
-
if (writable) {
|
|
20
|
-
if (!(stat.mode & 0o200)) throw new Error(`Managed CLI path is read-only: ${path}`);
|
|
21
|
-
accessSync(path, constants.W_OK | (directory ? constants.X_OK : 0));
|
|
22
|
-
}
|
|
23
|
-
return stat;
|
|
24
|
-
}
|
|
25
|
-
function snapshot(path) {
|
|
26
|
-
const stat = lstatSync(path);
|
|
27
|
-
if (stat.uid !== uid() || (!stat.isSymbolicLink() && (!stat.isFile() || stat.nlink !== 1))) throw new Error('Managed CLI entry is not an owned file or symlink');
|
|
28
|
-
if (!stat.isSymbolicLink() && (stat.mode & 0o022)) throw new Error('Managed CLI entry is writable by another user');
|
|
29
|
-
return { kind: stat.isSymbolicLink() ? 'symlink' : 'file', dev: stat.dev, ino: stat.ino, uid: stat.uid, mode: stat.mode & 0o7777,
|
|
30
|
-
size: stat.size, mtimeMs: stat.mtimeMs, ...(stat.isSymbolicLink() ? { link: readlinkSync(path), resolved: realpathSync(path) } : {}), digest: sha(readFileSync(path)) };
|
|
31
|
-
}
|
|
32
|
-
function readBackup(targetRoot) {
|
|
33
|
-
const path = join(targetRoot, 'legacy-backup', backupName);
|
|
34
|
-
owned(dirname(path), { directory: true }); owned(path);
|
|
35
|
-
const value = JSON.parse(readFileSync(path, 'utf8'));
|
|
36
|
-
if (value.schema !== 1 || value.targetRoot !== targetRoot || !value.original || typeof value.originalProgram !== 'string') throw new Error('Invalid managed CLI backup');
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
9
|
|
|
40
10
|
export function buildManagedCli(recordPath, installerPath) {
|
|
41
11
|
absolute(recordPath); absolute(installerPath);
|
|
@@ -90,75 +60,3 @@ if (result.signal) { process.kill(process.pid, result.signal); process.exit(1);
|
|
|
90
60
|
process.exit(result.status ?? 1);
|
|
91
61
|
`;
|
|
92
62
|
}
|
|
93
|
-
|
|
94
|
-
export async function inspectManagedCli(effects, targetRoot) {
|
|
95
|
-
if (!['linux', 'darwin'].includes(effects.platform?.platform ?? process.platform) || typeof process.getuid !== 'function') throw new Error('Managed CLI cutover supports Linux/macOS only');
|
|
96
|
-
absolute(targetRoot);
|
|
97
|
-
const output = async args => {
|
|
98
|
-
const result = await effects.run(args[0], args.slice(1));
|
|
99
|
-
if (result.code !== undefined && result.code !== 0) throw new Error('Cannot determine the existing global CLI selection');
|
|
100
|
-
return absolute(result.stdout.trim());
|
|
101
|
-
};
|
|
102
|
-
const npmRoot = await output(['npm', 'root', '--global']);
|
|
103
|
-
const prefix = await output(['npm', 'prefix', '--global']);
|
|
104
|
-
const binPath = join(prefix, 'bin', 'ours');
|
|
105
|
-
const selected = await output(['which', 'ours']);
|
|
106
|
-
if (selected !== binPath) throw new Error('PATH selects another ours command; select the verified npm global bin before migration');
|
|
107
|
-
owned(dirname(binPath), { directory: true, writable: true });
|
|
108
|
-
const packageRoot = realpathSync(join(npmRoot, '@ours.network/cli'));
|
|
109
|
-
const packagePath = join(packageRoot, 'package.json'); owned(packagePath);
|
|
110
|
-
const pkg = JSON.parse(readFileSync(packagePath, 'utf8'));
|
|
111
|
-
if (pkg.name !== '@ours.network/cli' || typeof pkg.bin?.ours !== 'string') throw new Error('Global package does not declare the expected ours CLI');
|
|
112
|
-
const originalProgram = realpathSync(resolve(packageRoot, pkg.bin.ours));
|
|
113
|
-
if (!originalProgram.startsWith(packageRoot + '/')) throw new Error('Global CLI bin escapes its package');
|
|
114
|
-
owned(originalProgram); accessSync(originalProgram, constants.R_OK | constants.X_OK);
|
|
115
|
-
const before = snapshot(binPath);
|
|
116
|
-
let installed = false;
|
|
117
|
-
let installerPath = fileURLToPath(new URL('../install.mjs', import.meta.url));
|
|
118
|
-
if (before.kind === 'symlink') {
|
|
119
|
-
if (before.resolved !== originalProgram) throw new Error('Global ours symlink does not target the verified npm CLI');
|
|
120
|
-
} else {
|
|
121
|
-
const contents = readFileSync(binPath, 'utf8');
|
|
122
|
-
const line = contents.split('\n')[1];
|
|
123
|
-
if (!line?.startsWith(marker)) throw new Error('Refusing to replace an unknown ours executable');
|
|
124
|
-
const binding = JSON.parse(line.slice(marker.length));
|
|
125
|
-
if (binding.schema !== 1 || binding.targetRoot !== targetRoot || binding.recordPath !== join(targetRoot, 'installation.json')) throw new Error('Managed CLI belongs to another installation');
|
|
126
|
-
installerPath = absolute(binding.installerPath);
|
|
127
|
-
if (contents !== buildManagedCli(binding.recordPath, installerPath)) throw new Error('Managed CLI launcher was modified');
|
|
128
|
-
const backup = readBackup(targetRoot);
|
|
129
|
-
if (backup.binPath !== binPath || backup.originalProgram !== originalProgram) throw new Error('Managed CLI backup selects another original executable');
|
|
130
|
-
installed = true;
|
|
131
|
-
}
|
|
132
|
-
return { schema: 1, targetRoot, binPath, originalProgram, installerPath, before, installed };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export async function installManagedCli(record, cliPlan, effects, { rename = renameSync } = {}) {
|
|
136
|
-
if (record.root !== cliPlan.targetRoot) throw new Error('Managed CLI target changed after inspection');
|
|
137
|
-
const fresh = await inspectManagedCli(effects, record.root);
|
|
138
|
-
if (fresh.binPath !== cliPlan.binPath || fresh.originalProgram !== cliPlan.originalProgram || JSON.stringify(fresh.before) !== JSON.stringify(cliPlan.before)) throw new Error('Global CLI changed after inspection; cutover refused');
|
|
139
|
-
const installerPath = absolute(cliPlan.installerPath);
|
|
140
|
-
owned(installerPath);
|
|
141
|
-
if (realpathSync(installerPath) !== installerPath) throw new Error('Managed installer path must be canonical');
|
|
142
|
-
if (fresh.installed && fresh.installerPath !== installerPath) throw new Error('Managed installer selection changed after inspection');
|
|
143
|
-
if (fresh.installed) return { binPath: fresh.binPath, originalProgram: fresh.originalProgram, changed: false };
|
|
144
|
-
owned(record.root, { directory: true });
|
|
145
|
-
const backupDir = join(record.root, 'legacy-backup');
|
|
146
|
-
if (!existsSync(backupDir)) mkdirSync(backupDir, { mode: 0o700 });
|
|
147
|
-
const backupStat = owned(backupDir, { directory: true });
|
|
148
|
-
if (backupStat.mode & 0o077) throw new Error('CLI backup directory must be private');
|
|
149
|
-
const backupPath = join(backupDir, backupName);
|
|
150
|
-
const backup = { schema: 1, targetRoot: record.root, binPath: fresh.binPath, originalProgram: fresh.originalProgram,
|
|
151
|
-
original: fresh.before, ...(fresh.before.kind === 'file' ? { bytes: readFileSync(fresh.binPath).toString('base64') } : {}) };
|
|
152
|
-
if (existsSync(backupPath)) {
|
|
153
|
-
const original = readBackup(record.root);
|
|
154
|
-
if (original.binPath !== backup.binPath || original.originalProgram !== backup.originalProgram) throw new Error('Existing CLI backup differs from the selected original');
|
|
155
|
-
} else writeFileSync(backupPath, JSON.stringify(backup, null, 2) + '\n', { flag: 'wx', mode: 0o600 });
|
|
156
|
-
const contents = buildManagedCli(join(record.root, 'installation.json'), installerPath);
|
|
157
|
-
const temporary = join(dirname(fresh.binPath), `.ours-managed-${randomUUID()}`);
|
|
158
|
-
try {
|
|
159
|
-
writeFileSync(temporary, contents, { flag: 'wx', mode: 0o700 }); chmodSync(temporary, 0o755);
|
|
160
|
-
if (JSON.stringify(snapshot(fresh.binPath)) !== JSON.stringify(fresh.before)) throw new Error('Global CLI changed during cutover');
|
|
161
|
-
rename(temporary, fresh.binPath);
|
|
162
|
-
} finally { rmSync(temporary, { force: true }); }
|
|
163
|
-
return { binPath: fresh.binPath, originalProgram: fresh.originalProgram, changed: true };
|
|
164
|
-
}
|
|
@@ -24,6 +24,7 @@ import { tgConfigPath, coworkConfigPath } from './components.mjs';
|
|
|
24
24
|
import { configJournal, reportRollback } from './journal.mjs';
|
|
25
25
|
import { UNINSTALL_USAGE } from './usage.mjs';
|
|
26
26
|
import { ok, info, warn, heading } from './ui.mjs';
|
|
27
|
+
import { UNSUPPORTED_LAYOUT, refuseOldLayout } from './plan.mjs';
|
|
27
28
|
|
|
28
29
|
export const EXIT_OK = 0;
|
|
29
30
|
export const EXIT_REFUSED = 2;
|
|
@@ -86,6 +87,7 @@ export async function runUninstall(argv, effects) {
|
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
const managed = effects.readJson(join(dir, 'installation.json'));
|
|
90
|
+
try { refuseOldLayout(managed, dir, path => effects.readJson(path)); } catch { effects.out(warn(`ours: ${UNSUPPORTED_LAYOUT}`)); return EXIT_REFUSED; }
|
|
89
91
|
if (managed?.schema === 2 && ['docker', 'packages'].includes(managed.mode)) {
|
|
90
92
|
if (contract.engaged || args.config || effects.env.OURS_CONFIG) {
|
|
91
93
|
effects.out(warn('Managed server uninstall does not support legacy component/profile selections. Nothing was changed; use an explicit server uninstall with those selectors cleared.'));
|
package/lib/orchestrate.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { assertSecureNodeVersion } from './security-versions.mjs';
|
|
2
2
|
import { validateGatewayClientProfile } from './target.mjs';
|
|
3
3
|
import { enableGateway } from './gateway-transition.mjs';
|
|
4
|
-
import { executeLegacyMigration } from './legacy-migration.mjs';
|
|
5
4
|
// ours-install v3 — the orchestrator.
|
|
6
5
|
//
|
|
7
6
|
// This is the part that cannot be pure: it walks the flow, renders the screens
|
|
@@ -30,7 +29,7 @@ import { executeLegacyMigration } from './legacy-migration.mjs';
|
|
|
30
29
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
31
30
|
import { parseNetworkArgs, validateHostProfile, parseInstallArgs, resolveTarget, resolveProfileSelection, profileEnv, InstallUsageError } from './target.mjs';
|
|
32
31
|
import { NOTIFICATIONS_PRODUCER_FILE } from './server-onboarding.mjs';
|
|
33
|
-
import { clientPackageNames, selectSourcePackages, validateInstallation, SERVER_SERVICES, planDaemonConfig, planServiceInstall, serviceInstallCommand } from './plan.mjs';
|
|
32
|
+
import { clientPackageNames, selectSourcePackages, validateInstallation, refuseOldLayout, MIGRATE_FROM_UNSUPPORTED, SERVER_SERVICES, planDaemonConfig, planServiceInstall, serviceInstallCommand } from './plan.mjs';
|
|
34
33
|
import {
|
|
35
34
|
COMPONENTS,
|
|
36
35
|
planComponentSelection, planMcpAttachment, planTgAttachment, planCoworkAttachment,
|
|
@@ -1557,9 +1556,9 @@ export async function runInstall(argv, effects) {
|
|
|
1557
1556
|
|
|
1558
1557
|
export async function runServerCommand(args, effects) {
|
|
1559
1558
|
if (args.operation === 'status') return executeServerCommand(args, effects);
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1559
|
+
if (args.migrateFrom !== undefined) throw new InstallUsageError(MIGRATE_FROM_UNSUPPORTED);
|
|
1560
|
+
refuseOldLayout(effects.readJson(join(args.stateDir, 'installation.json')), args.stateDir, effects.readJson);
|
|
1561
|
+
return effects.withInstallationLock(args.stateDir, () => executeServerCommand(args, effects));
|
|
1563
1562
|
}
|
|
1564
1563
|
|
|
1565
1564
|
async function executeServerCommand(args, effects) {
|
|
@@ -1567,7 +1566,7 @@ async function executeServerCommand(args, effects) {
|
|
|
1567
1566
|
let record = effects.readJson(recordPath);
|
|
1568
1567
|
const existing = record !== null;
|
|
1569
1568
|
if (existing) {
|
|
1570
|
-
record = validateInstallation(record, args.stateDir);
|
|
1569
|
+
record = validateInstallation(refuseOldLayout(record, args.stateDir, effects.readJson), args.stateDir);
|
|
1571
1570
|
if (args.containerEngine && args.containerEngine !== (record.containerEngine ?? 'docker')) throw new Error('Conflicting container engine; explicit migration is required');
|
|
1572
1571
|
if (args.mode && args.mode !== record.mode) throw new Error('Conflicting runtime mode; retained installation was not changed');
|
|
1573
1572
|
if (args.product && args.product !== productOf(record)) throw new Error(`This installation is ${PRODUCT_LABELS[productOf(record)].toLowerCase()}; it is kept as it is. Use a separate empty directory for the other kind of installation.`);
|
|
@@ -1585,13 +1584,10 @@ async function executeServerCommand(args, effects) {
|
|
|
1585
1584
|
if (existing && record.gateway.serverUrl !== args.serverUrl) throw new Error('Conflicting gateway server URL');
|
|
1586
1585
|
record.gateway = { ...record.gateway, serverUrl: args.serverUrl };
|
|
1587
1586
|
}
|
|
1588
|
-
if (record.layoutConversion && !['install', 'start', 'stop', 'status'].includes(args.operation)) {
|
|
1589
|
-
throw new Error('Layout conversion is incomplete; resume with server install or server start before changing state or authority');
|
|
1590
|
-
}
|
|
1591
1587
|
if (record.buildTransition && !['stop', 'status', record.buildTransition.operation].includes(args.operation)) {
|
|
1592
1588
|
throw new Error(`Server build activation is incomplete; repeat server ${record.buildTransition.operation} before other mutations`);
|
|
1593
1589
|
}
|
|
1594
|
-
const showInstallProgress = args.operation === 'install'
|
|
1590
|
+
const showInstallProgress = args.operation === 'install';
|
|
1595
1591
|
const installStageCount = (existing ? 7 : 9) + (args.identityName ? 2 : 0)
|
|
1596
1592
|
+ (args.identityName && args.name && args.surname && (!existing || [undefined, null, args.identityName, `${args.name} ${args.surname}`].includes(record.messengerIdentity)) ? 1 : 0);
|
|
1597
1593
|
let completedInstallStages = 0;
|
|
@@ -1618,19 +1614,7 @@ async function executeServerCommand(args, effects) {
|
|
|
1618
1614
|
await installStage('Prerequisite checks', record.mode === 'docker' ? 'Check Docker Engine and Docker Compose.' : 'Check native tools and the user service manager.', () => effects.serverPreflight(record, args.operation, {
|
|
1619
1615
|
existing, sourcePath: args.sources ?? record.sourcesPath, sourceManifest: args.resolvedSources, identityName: args.identityName, explicitPorts: args.explicitPorts,
|
|
1620
1616
|
}));
|
|
1621
|
-
if (
|
|
1622
|
-
&& ['install', 'start', 'restart', 'update', 'rebuild'].includes(args.operation)) {
|
|
1623
|
-
record = record.mode === 'docker'
|
|
1624
|
-
? await effects.convertDockerInstallation(record, args.operation)
|
|
1625
|
-
: await effects.convertPackageInstallation(record, args.operation);
|
|
1626
|
-
if (['install', 'start', 'restart'].includes(args.operation)) {
|
|
1627
|
-
effects.out(ok(`Server ${args.operation} completed after layout conversion for ${record.root}`));
|
|
1628
|
-
return EXIT_OK;
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
if (args.operation === 'stop' && record.layoutConversion) {
|
|
1632
|
-
await effects.stopPendingConversion(record);
|
|
1633
|
-
} else if (args.operation === 'install') {
|
|
1617
|
+
if (args.operation === 'install') {
|
|
1634
1618
|
if (!existing) {
|
|
1635
1619
|
await installStage('Installation setup', 'Save the selected packages and installation settings.', async () => {
|
|
1636
1620
|
await effects.initializeSelection(record, args.resolvedSources);
|
|
@@ -1695,9 +1679,6 @@ async function executeServerCommand(args, effects) {
|
|
|
1695
1679
|
if (args.operation === 'status') effects.out(JSON.stringify({
|
|
1696
1680
|
mode: record.mode, instanceId: record.instanceId, schema: record.schema, running,
|
|
1697
1681
|
...(record.buildTransition ? { buildTransition: record.buildTransition.phase } : {}),
|
|
1698
|
-
...(record.layoutConversion ? {
|
|
1699
|
-
layoutConversion: record.schema === 1 ? 'preparation-pending' : 'activation-pending',
|
|
1700
|
-
} : {}),
|
|
1701
1682
|
}));
|
|
1702
1683
|
if (args.operation === 'status') return EXIT_OK;
|
|
1703
1684
|
}
|
package/lib/plan.mjs
CHANGED
|
@@ -349,25 +349,31 @@ export async function resolveSourcePolicy(manifest, role, clients = [], resolveN
|
|
|
349
349
|
return exact;
|
|
350
350
|
}
|
|
351
351
|
|
|
352
|
-
/** Installer-owned physical layout; package defaults remain unchanged. */
|
|
352
|
+
/** Installer-owned physical layout (schema 2); package defaults remain unchanged. */
|
|
353
353
|
export function installationPaths(record) {
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
const
|
|
357
|
-
const daemon = join(state, shared ? 'daemon' : 'data');
|
|
358
|
-
const credentials = Object.fromEntries(['telegram', 'cowork', 'messenger'].map(service => [
|
|
359
|
-
service, shared ? join(state, 'credentials', service, 'daemon-token') : join(root, 'credentials', `${service}-token`),
|
|
360
|
-
]));
|
|
354
|
+
const state = join(record.root, 'storage', 'state');
|
|
355
|
+
const daemon = join(state, 'daemon');
|
|
356
|
+
const credentials = Object.fromEntries(['telegram', 'cowork', 'messenger'].map(service => [service, join(state, 'credentials', service, 'daemon-token')]));
|
|
361
357
|
return {
|
|
362
358
|
state, daemon, mcp: join(state, 'mcp'), telegram: join(state, 'telegram'),
|
|
363
359
|
cowork: join(state, 'cowork'), messenger: join(state, 'messenger'), credentials,
|
|
364
|
-
config:
|
|
360
|
+
config: join(daemon, 'config.json'),
|
|
365
361
|
};
|
|
366
362
|
}
|
|
367
363
|
|
|
364
|
+
export const UNSUPPORTED_LAYOUT = 'Unsupported old installation layout (schema 1 / legacy ~/.ours). Migration from old layouts is no longer supported; install fresh into a new folder. Existing data was not changed.';
|
|
365
|
+
export const MIGRATE_FROM_UNSUPPORTED = '--migrate-from is no longer supported: migration from old installation layouts (schema 1 / legacy ~/.ours) was removed. Install fresh into a new folder; existing data was not changed.';
|
|
366
|
+
/** Schema-1 selections, pending layout conversions and unfinished ~/.ours imports are refused before any write. */
|
|
367
|
+
export function refuseOldLayout(record, root, readJson) {
|
|
368
|
+
if (record && (record.schema === 1 || record.layoutConversion !== undefined
|
|
369
|
+
|| (record.legacyMigrationSource !== undefined && readJson(join(root, 'legacy-migration.json'))?.phase !== 'complete'))) throw new Error(UNSUPPORTED_LAYOUT);
|
|
370
|
+
return record;
|
|
371
|
+
}
|
|
372
|
+
|
|
368
373
|
export function validateInstallation(record, root) {
|
|
374
|
+
if (record?.schema === 1 || record?.layoutConversion !== undefined) throw new Error(UNSUPPORTED_LAYOUT);
|
|
369
375
|
if (record) validateContainerEngine(record);
|
|
370
|
-
if (!record ||
|
|
376
|
+
if (!record || record.schema !== 2 || !['docker', 'packages'].includes(record.mode)
|
|
371
377
|
|| record.root !== root || record.configPath !== installationPaths(record).config
|
|
372
378
|
|| record.sourcesPath !== join(root, 'sources.json') || record.workDir !== join(root, 'runtime')
|
|
373
379
|
|| !/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/.test(record.instanceId ?? '')
|
|
@@ -377,41 +383,18 @@ export function validateInstallation(record, root) {
|
|
|
377
383
|
throw new Error('Invalid or conflicting installation selection');
|
|
378
384
|
}
|
|
379
385
|
if (record.product !== undefined && (!PRODUCTS.includes(record.product) || record.product === 'workspace'
|
|
380
|
-
|| record.
|
|
386
|
+
|| record.mode !== 'docker' || record.gateway !== undefined
|
|
381
387
|
|| JSON.stringify(record.services) !== JSON.stringify(['daemon']))) {
|
|
382
388
|
throw new Error('Invalid plugin-only installation selection');
|
|
383
389
|
}
|
|
384
|
-
if (record.gateway !== undefined && (record.
|
|
390
|
+
if (record.gateway !== undefined && (record.mode !== 'docker' || record.gateway?.version !== 1
|
|
385
391
|
|| Object.keys(record.gateway).some(key => !['version', 'serverUrl'].includes(key)) || record.services.at(-1) !== 'gateway')) {
|
|
386
392
|
throw new Error('Invalid gateway installation selection');
|
|
387
393
|
}
|
|
388
394
|
if (record.gateway) gatewayAddress(record);
|
|
389
|
-
if (record.layoutConversion !== undefined) {
|
|
390
|
-
// DEPRECATED (introduced in 2.0): legacy managed-layout conversion only.
|
|
391
|
-
// Removal target: 3.0, after supported installs convert and upgrade inputs
|
|
392
|
-
// no longer need this reader. Retain backups and supported archive import.
|
|
393
|
-
const conversion = record.layoutConversion;
|
|
394
|
-
const source = conversion?.sourceRecord;
|
|
395
|
-
if (conversion?.version !== 1 || source?.schema !== 1 || source.layoutConversion !== undefined
|
|
396
|
-
|| typeof conversion.backupPath !== 'string'
|
|
397
|
-
|| dirname(conversion.backupPath) !== join(root, 'storage', 'backups')
|
|
398
|
-
|| resolve(conversion.backupPath) !== conversion.backupPath
|
|
399
|
-
|| !Array.isArray(conversion.runningServices)
|
|
400
|
-
|| new Set(conversion.runningServices).size !== conversion.runningServices.length) {
|
|
401
|
-
throw new Error('Invalid layout conversion record');
|
|
402
|
-
}
|
|
403
|
-
validateInstallation(source, root);
|
|
404
|
-
if (JSON.stringify(source.containerBinding) !== JSON.stringify(record.containerBinding)) throw new Error('Conflicting conversion backend');
|
|
405
|
-
if (['mode', 'containerEngine', 'instanceId', 'project', 'sourcesPath', 'workDir'].some(key => source[key] !== record[key])
|
|
406
|
-
|| JSON.stringify(source.services) !== JSON.stringify(record.services)
|
|
407
|
-
|| conversion.runningServices.some(service => !source.services.includes(service))) {
|
|
408
|
-
throw new Error('Conflicting layout conversion source');
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
395
|
if (record.buildTransition !== undefined) {
|
|
412
396
|
const transition = record.buildTransition, candidate = transition?.candidate;
|
|
413
|
-
if (
|
|
414
|
-
|| candidate.buildTransition !== undefined || candidate.layoutConversion !== undefined
|
|
397
|
+
if (!candidate || candidate.buildTransition !== undefined
|
|
415
398
|
|| dirname(candidate.root ?? '') !== root || !/^\.build-[A-Za-z0-9]{6}$/.test(basename(candidate.root ?? ''))
|
|
416
399
|
|| !/^ours-build[0-9a-f]{32}$/.test(candidate.project ?? '')
|
|
417
400
|
|| !['update', 'rebuild'].includes(transition.operation)
|
package/lib/removal.mjs
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import { basename, dirname, join, resolve } from 'node:path';
|
|
13
13
|
import { modify, applyEdits, parse as parseJsonc } from 'jsonc-parser';
|
|
14
|
-
import { validateInstallation, unitNameForStateDir } from './plan.mjs';
|
|
14
|
+
import { validateInstallation, refuseOldLayout, unitNameForStateDir, UNSUPPORTED_LAYOUT } from './plan.mjs';
|
|
15
15
|
import { validateContainerEngine, runContainer } from './container-engine.mjs';
|
|
16
16
|
import { classifyStateDir } from './detect.mjs';
|
|
17
17
|
import { stripManagedBlock, YAML_BLOCK, MD_BLOCK } from './uninstall.mjs';
|
|
@@ -101,8 +101,12 @@ export async function discoverFootprint(effects, { stateDirs = [], journal = nul
|
|
|
101
101
|
continue;
|
|
102
102
|
}
|
|
103
103
|
let record;
|
|
104
|
-
try { record = validateInstallation(json(text), root); if (record.containerBinding || record.containerEngine) validateContainerEngine(record); }
|
|
105
|
-
catch
|
|
104
|
+
try { record = refuseOldLayout(validateInstallation(json(text), root), root, path => json(effects.readText(path) ?? '')); if (record.containerBinding || record.containerEngine) validateContainerEngine(record); }
|
|
105
|
+
catch (error) {
|
|
106
|
+
keep('data', `Folder ${root}`, error.message === UNSUPPORTED_LAYOUT ? 'it holds an old installation layout this installer no longer supports, so nothing in it is removed automatically; remove the folder yourself if you no longer need it'
|
|
107
|
+
: 'its Ours installation record is damaged, so nothing in it is removed automatically; repair or remove the folder yourself, then run the removal again', true);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
106
110
|
if (retained && retained.instanceId !== record.instanceId) { keep('data', `Folder ${root}`, 'it now holds a different Ours installation than the unfinished removal recorded'); continue; }
|
|
107
111
|
const item = { ...journalInstallation(record), ...(retained?.candidateProjects?.length ? { candidateProjects: [...new Set([...retained.candidateProjects, ...journalInstallation(record).candidateProjects])] } : {}), ...(retained?.images ? { images: retained.images } : {}), record, tombstone: tombstone(root, 'root', record.instanceId) };
|
|
108
112
|
item.ownedImages = json(effects.readText(join(root, 'owned-images.json')) ?? '')?.images ?? null;
|
|
@@ -534,7 +538,16 @@ async function executeStep(step, effects, context) {
|
|
|
534
538
|
const [image] = JSON.parse(found.stdout);
|
|
535
539
|
if (image.Id !== id) { problems.push(`${tag} changed since it was checked and was left in place`); continue; }
|
|
536
540
|
// Remove only this name. An image ID still named or used elsewhere stays.
|
|
537
|
-
try {
|
|
541
|
+
try {
|
|
542
|
+
await runContainer(effects, step.installation, ['image', 'rm', tag]);
|
|
543
|
+
// A published image this installer pulled keeps only its registry digest name;
|
|
544
|
+
// drop that too once no other name uses it. A still-used image stays in place.
|
|
545
|
+
if (!(image.RepoTags ?? []).some(other => other !== tag && !/^(?:docker\.io\/)?adaptframework\/ours-(?:runtime|maintenance)@/.test(other))) {
|
|
546
|
+
for (const digest of (image.RepoDigests ?? []).filter(name => /^(?:docker\.io\/)?adaptframework\/ours-(?:runtime|maintenance)@sha256:[0-9a-f]{64}$/.test(name))) {
|
|
547
|
+
try { await runContainer(effects, step.installation, ['image', 'rm', digest]); } catch { /* still used elsewhere */ }
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
538
551
|
catch {
|
|
539
552
|
let users = '';
|
|
540
553
|
try { users = (await runContainer(effects, step.installation, ['ps', '-a', '--filter', `ancestor=${id}`, '--format', '{{.Names}}'])).stdout.split(/\s+/).filter(Boolean).join(', '); } catch { /* named generically below */ }
|
package/lib/setup-options.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { hostname } from 'node:os';
|
|
2
2
|
import { serverBase } from './gateway.mjs';
|
|
3
|
-
import { join, resolve
|
|
3
|
+
import { join, resolve } from 'node:path';
|
|
4
4
|
import { PRODUCTS, PLUGIN_ONLY, PLUGIN_ONLY_INTEGRATIONS } from './product.mjs';
|
|
5
|
+
import { MIGRATE_FROM_UNSUPPORTED, refuseOldLayout } from './plan.mjs';
|
|
6
|
+
import { InstallUsageError } from './target.mjs';
|
|
5
7
|
|
|
6
8
|
const scopes = ['all', 'server', 'client'];
|
|
7
9
|
const integrations = ['codex', 'claude-code', 'fleet'];
|
|
@@ -9,12 +11,12 @@ const valueFlags = new Map(Object.entries({
|
|
|
9
11
|
'--container-engine': 'containerEngine', '--server-url': 'serverUrl', '--scope': 'scope', '--action': 'operation', '--mode': 'mode', '--state-dir': 'stateDir',
|
|
10
12
|
'--username': 'localUsername', '--name': 'name', '--surname': 'surname', '--hostname': 'hostname',
|
|
11
13
|
'--identity-name': 'identityName', '--integrations': 'integrations', '--fleet-settings': 'fleetSettingsPath', '--fleet-task-workflow': 'fleetTaskWorkflowAgents',
|
|
12
|
-
'--config': 'config', '--sources': 'sources', '--
|
|
14
|
+
'--config': 'config', '--sources': 'sources', '--port': 'port', '--cowork-port': 'coworkPort', '--messenger-port': 'messengerPort',
|
|
13
15
|
}));
|
|
14
16
|
const boolFlags = new Map([['--compatible', 'compatible'], ['--dry-run', 'dryRun'], ['--migrate', 'migrate'], ['--disable-fleet-agents-setup', 'disableFleetAgentsSetup']]);
|
|
15
17
|
const allowed = new Set([...valueFlags.values(), ...boolFlags.values(), 'interactive', 'explicitPorts', 'product']);
|
|
16
18
|
const defaults = { port: 3050, coworkPort: 3052, messengerPort: 8420 };
|
|
17
|
-
const paths = ['stateDir', 'config', 'sources', 'fleetSettingsPath'
|
|
19
|
+
const paths = ['stateDir', 'config', 'sources', 'fleetSettingsPath'];
|
|
18
20
|
const nonempty = value => typeof value === 'string' && value.trim().length > 0 && !/[\x00-\x1f\x7f]/.test(value);
|
|
19
21
|
|
|
20
22
|
export function recommendedMode({ platform, arch, release = '' } = {}) {
|
|
@@ -27,14 +29,13 @@ export function recommendedMode({ platform, arch, release = '' } = {}) {
|
|
|
27
29
|
|
|
28
30
|
export function validateSetupOptions(input, { interactive = input?.interactive === true } = {}) {
|
|
29
31
|
if (!input || typeof input !== 'object' || Array.isArray(input)) throw new Error('Setup options must be an object');
|
|
32
|
+
if (input.migrateFrom !== undefined) throw new InstallUsageError(MIGRATE_FROM_UNSUPPORTED);
|
|
30
33
|
for (const key of Object.keys(input)) if (!allowed.has(key)) throw new Error(`Unknown setup option: ${key}`);
|
|
31
34
|
const options = { ...input, scope: input.scope ?? 'all', operation: input.operation ?? 'install', interactive };
|
|
32
35
|
if (!scopes.includes(options.scope)) throw new Error('Scope must be all, server, or client');
|
|
33
36
|
if (!['install', 'update'].includes(options.operation)) throw new Error('Operation must be install or update');
|
|
34
37
|
const server = options.scope !== 'client';
|
|
35
38
|
const client = options.scope !== 'server';
|
|
36
|
-
if (options.migrateFrom !== undefined && (!server || options.operation !== 'install')) throw new Error('--migrate-from requires server or all scope and operation install');
|
|
37
|
-
if (options.migrateFrom !== undefined && (!nonempty(options.migrateFrom) || !isAbsolute(options.migrateFrom))) throw new Error('--migrate-from requires an absolute daemon config path');
|
|
38
39
|
const suppliedHuman = ['localUsername', 'name', 'surname'].some(key => options[key] !== undefined);
|
|
39
40
|
if (suppliedHuman) {
|
|
40
41
|
for (const key of ['localUsername', 'name', 'surname']) if (!nonempty(options[key])) throw new Error(`Missing human profile option: ${key}`);
|
|
@@ -50,8 +51,8 @@ export function validateSetupOptions(input, { interactive = input?.interactive =
|
|
|
50
51
|
options.hostname = options.hostname?.trim() || defaultHostname();
|
|
51
52
|
if (!/^[a-z0-9][a-z0-9-]{0,29}$/.test(options.hostname)) throw new Error('Hostname must contain 1–30 lowercase letters, digits or hyphens');
|
|
52
53
|
const identity = `${options.localUsername}@${options.hostname}`;
|
|
53
|
-
if (options.
|
|
54
|
-
|
|
54
|
+
if (options.identityName !== undefined && options.identityName !== identity) throw new Error('--identity-name conflicts with username and hostname');
|
|
55
|
+
options.identityName = identity;
|
|
55
56
|
} else if (options.hostname !== undefined) throw new Error('--hostname requires username, name and surname');
|
|
56
57
|
if (options.disableFleetAgentsSetup !== undefined && typeof options.disableFleetAgentsSetup !== 'boolean') throw new Error('disableFleetAgentsSetup must be a boolean');
|
|
57
58
|
if (options.disableFleetAgentsSetup && options.fleetSettingsPath) throw new Error('--disable-fleet-agents-setup conflicts with --fleet-settings');
|
|
@@ -71,7 +72,7 @@ export function validateSetupOptions(input, { interactive = input?.interactive =
|
|
|
71
72
|
if (options.mode !== undefined && !['docker'].includes(options.mode)) throw new Error('--plugin-only runs the daemon in Docker or Podman; native packages are not supported for it');
|
|
72
73
|
if (options.integrations?.some?.(name => !PLUGIN_ONLY_INTEGRATIONS.includes(name))) throw new Error('--plugin-only connects Claude Code and/or Codex; Fleet is part of the complete workspace');
|
|
73
74
|
for (const [key, flag] of [['fleetSettingsPath', '--fleet-settings'], ['fleetTaskWorkflowAgents', '--fleet-task-workflow'], ['disableFleetAgentsSetup', '--disable-fleet-agents-setup'],
|
|
74
|
-
['name', '--name'], ['surname', '--surname'], ['
|
|
75
|
+
['name', '--name'], ['surname', '--surname'], ['serverUrl', '--server-url']]) {
|
|
75
76
|
if (options[key] !== undefined && options[key] !== false) throw new Error(`${flag} belongs to the complete workspace and cannot be combined with --plugin-only`);
|
|
76
77
|
}
|
|
77
78
|
if (options.explicitPorts?.some?.(key => key !== 'port')) throw new Error('--plugin-only uses one port; --cowork-port and --messenger-port do not apply');
|
|
@@ -79,10 +80,10 @@ export function validateSetupOptions(input, { interactive = input?.interactive =
|
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
const missing = [];
|
|
82
|
-
if (server) for (const [key, flag] of [['mode', '--mode'], ['stateDir', '--state-dir'],
|
|
83
|
+
if (server) for (const [key, flag] of [['mode', '--mode'], ['stateDir', '--state-dir'], ['identityName', '--identity-name']]) if (!nonempty(options[key])) missing.push(flag);
|
|
83
84
|
if (client && options.integrations === undefined) missing.push('--integrations (use none to skip)');
|
|
84
85
|
if (!server && !nonempty(options.config)) missing.push('--config');
|
|
85
|
-
if (server &&
|
|
86
|
+
if (server && options.operation === 'update' && options.compatible !== true) missing.push('--compatible');
|
|
86
87
|
if (Array.isArray(options.integrations) && options.integrations.includes('fleet') && !interactive && !options.disableFleetAgentsSetup && !nonempty(options.fleetSettingsPath)) missing.push('--fleet-settings');
|
|
87
88
|
if (missing.length) throw new Error(`Missing required setup options: ${missing.join(', ')}`);
|
|
88
89
|
if (options.mode === 'native') options.mode = 'packages';
|
|
@@ -128,10 +129,7 @@ function expandPaths(options, home) {
|
|
|
128
129
|
if (value === '~' || value.startsWith('~/')) {
|
|
129
130
|
if (!nonempty(home)) throw new Error('Home directory is required to expand ~/ paths');
|
|
130
131
|
output[key] = resolve(home, value === '~' ? '' : value.slice(2));
|
|
131
|
-
} else
|
|
132
|
-
if (key === 'migrateFrom' && !isAbsolute(value)) throw new Error('--migrate-from requires an absolute daemon config path');
|
|
133
|
-
output[key] = resolve(value);
|
|
134
|
-
}
|
|
132
|
+
} else output[key] = resolve(value);
|
|
135
133
|
}
|
|
136
134
|
return output;
|
|
137
135
|
}
|
|
@@ -158,6 +156,7 @@ export function parseSetupArgs(argv, { home, validate = true } = {}) {
|
|
|
158
156
|
if (equal >= 0) throw new Error(`${flag} takes no value`);
|
|
159
157
|
put(boolFlags.get(flag), true); continue;
|
|
160
158
|
}
|
|
159
|
+
if (flag === '--migrate-from') throw new InstallUsageError(MIGRATE_FROM_UNSUPPORTED);
|
|
161
160
|
if (!valueFlags.has(flag)) throw new Error(`Unknown setup flag: ${flag}`);
|
|
162
161
|
const value = equal < 0 ? argv[++i] : arg.slice(equal + 1);
|
|
163
162
|
if (!nonempty(value) || value.startsWith('--')) throw new Error(`${flag} requires a value`);
|
|
@@ -191,7 +190,6 @@ export async function collectSetupOptions(effects, presets = {}) {
|
|
|
191
190
|
options.scope ??= await effects.select('What would you like to set up?', scopeChoices, 'all');
|
|
192
191
|
if (!scopes.includes(options.scope)) throw new Error('Scope must be all, server, or client');
|
|
193
192
|
let existing;
|
|
194
|
-
let pendingMigration;
|
|
195
193
|
if (options.scope !== 'client') {
|
|
196
194
|
const recommendedRoot = join(effects.home, '.ours-install');
|
|
197
195
|
effects.out(`Stores the server programs and data, including identities and messages. The recommended folder is ${recommendedRoot}; choose another only if you want to manage its location yourself.`);
|
|
@@ -201,61 +199,21 @@ export async function collectSetupOptions(effects, presets = {}) {
|
|
|
201
199
|
], 'recommended');
|
|
202
200
|
options.stateDir ??= location === 'recommended' ? recommendedRoot : await effects.askLine('Folder for server programs and data: ', recommendedRoot);
|
|
203
201
|
options.stateDir = expandPaths({ stateDir: options.stateDir }, effects.home).stateDir;
|
|
204
|
-
existing = effects.readJson(join(options.stateDir, 'installation.json'));
|
|
205
|
-
const migrationJournal = existing?.legacyMigrationSource ? effects.readJson(join(options.stateDir, 'legacy-migration.json')) : null;
|
|
206
|
-
pendingMigration = existing?.legacyMigrationSource && migrationJournal?.phase !== 'complete' ? existing.legacyMigrationSource : null;
|
|
202
|
+
existing = refuseOldLayout(effects.readJson(join(options.stateDir, 'installation.json')), options.stateDir, effects.readJson);
|
|
207
203
|
}
|
|
208
|
-
effects.out(
|
|
209
|
-
? 'An earlier migration is unfinished. Resume it in this same folder to retain the copied data and repair the installation.'
|
|
210
|
-
: existing
|
|
204
|
+
effects.out(existing
|
|
211
205
|
? 'This folder already contains an installation. Update selects this installer’s release while retaining state; repair reinstalls the retained package selection.'
|
|
212
206
|
: options.scope === 'client' ? 'Install connects your selected apps. Update refreshes their packages while keeping the server connection.'
|
|
213
207
|
: 'Install creates a managed installation in the selected folder. Update requires an installation already recorded there.');
|
|
214
208
|
options.operation ??= !existing && options.scope !== 'client' ? 'install' : await effects.select('What should happen?', [
|
|
215
|
-
{ value: 'install', label:
|
|
209
|
+
{ value: 'install', label: existing ? 'Repair this installation' : 'Install and configure' },
|
|
216
210
|
{ value: 'update', label: 'Update an existing installation' },
|
|
217
|
-
], existing
|
|
218
|
-
if (options.scope !== 'client' && options.operation === 'install') {
|
|
219
|
-
const defaultConfig = join(effects.home, '.ours', 'config.json');
|
|
220
|
-
const legacy = !existing ? effects.readJson(defaultConfig) : null;
|
|
221
|
-
const legacyState = nonempty(legacy?.stateDir) ? legacy.stateDir
|
|
222
|
-
: legacy && legacy.stateDir === undefined && nonempty(effects.readJson(join(effects.home, '.ours', 'root.json'))?.name)
|
|
223
|
-
? join(effects.home, '.ours') : null;
|
|
224
|
-
if (options.migrateFrom) { /* Explicit selection is validated below. */ }
|
|
225
|
-
else if (pendingMigration) options.migrateFrom = pendingMigration;
|
|
226
|
-
else if (legacyState) {
|
|
227
|
-
effects.out(`Found an existing ours installation at ${legacyState}. Upgrade it to keep its identities, messages and settings. The old server will stop; its original state is kept as a recovery copy.`);
|
|
228
|
-
if (await effects.ask('Upgrade this existing ours installation and keep its data?', true)) options.migrateFrom = defaultConfig;
|
|
229
|
-
else {
|
|
230
|
-
effects.out('A separate installation creates a different server. It does not move or share the identities and messages in the existing installation.');
|
|
231
|
-
if (!await effects.ask('Create a separate fresh installation and keep the existing daemon unchanged?', false)) throw new Error('Setup cancelled; existing daemon was not changed');
|
|
232
|
-
}
|
|
233
|
-
} else {
|
|
234
|
-
effects.out('Start fresh if you have no existing ours data to bring over. If your old installation is stored elsewhere, select its configuration file to retain its data.');
|
|
235
|
-
const migration = await effects.select('Should existing ours data be brought over?', [
|
|
236
|
-
{ value: 'fresh', label: 'Start a fresh installation' },
|
|
237
|
-
{ value: 'migrate', label: 'Bring data from another existing installation' },
|
|
238
|
-
], 'fresh');
|
|
239
|
-
if (migration === 'migrate') options.migrateFrom = expandPaths({ migrateFrom: await effects.askLine('Existing daemon configuration file: ', '') }, effects.home).migrateFrom;
|
|
240
|
-
}
|
|
241
|
-
if (options.migrateFrom) {
|
|
242
|
-
if (existing && pendingMigration !== options.migrateFrom) throw new Error('--migrate-from requires a new managed installation root; the selected root already has installation.json');
|
|
243
|
-
const sourceConfig = effects.readJson(options.migrateFrom);
|
|
244
|
-
const sourceState = sourceConfig?.stateDir ?? dirname(options.migrateFrom);
|
|
245
|
-
const root = effects.readJson(join(sourceState, 'root.json'));
|
|
246
|
-
if (!nonempty(root?.name)) throw new Error('Cannot read the existing Human identity name; choose the configuration file for a complete existing installation');
|
|
247
|
-
options.identityName = root.name;
|
|
248
|
-
effects.out(`Your existing Human identity, ${root.name}, will be retained; no replacement identity will be created. Migration keeps the original state, but compatibility with an older release cannot be guaranteed automatically.`);
|
|
249
|
-
options.compatible ??= await effects.ask('Proceed with this release and keep the original state as a recovery copy?', false);
|
|
250
|
-
if (!options.compatible) throw new Error('Migration requires explicit compatibility confirmation (--compatible)');
|
|
251
|
-
}
|
|
252
|
-
}
|
|
211
|
+
], existing ? 'update' : 'install');
|
|
253
212
|
if (options.scope !== 'client') {
|
|
254
213
|
const recommendation = recommendedMode({ ...effects.platform, arch: effects.platform?.arch ?? process.arch });
|
|
255
214
|
// Native runs the server only: local clients need the container gateway. A retained
|
|
256
215
|
// native installation keeps its mode, so a full setup of it cannot finish.
|
|
257
|
-
|
|
258
|
-
if (options.scope === 'all' && existing?.mode === 'packages' && !options.migrateFrom)
|
|
216
|
+
if (options.scope === 'all' && existing?.mode === 'packages')
|
|
259
217
|
throw new Error('This installation runs natively, which supports the server only. Choose the server-only setup to maintain it (ours-install server); local clients need an installation that runs in Docker or Podman. Nothing was changed.');
|
|
260
218
|
const nativeOffered = options.scope === 'server' || existing?.mode === 'packages';
|
|
261
219
|
effects.out(nativeOffered
|
|
@@ -266,22 +224,20 @@ export async function collectSetupOptions(effects, presets = {}) {
|
|
|
266
224
|
], existing?.mode === 'docker' && existing?.containerEngine === 'podman' ? 'podman' : existing?.mode ?? recommendation.mode);
|
|
267
225
|
options.mode = runtime === 'podman' ? 'docker' : runtime;
|
|
268
226
|
if (runtime === 'podman') options.containerEngine = 'podman';
|
|
269
|
-
if (
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
options.hostname ??= await effects.askLine('Host / machine name (optional): ', '');
|
|
280
|
-
}
|
|
227
|
+
if (existing?.messengerIdentity) {
|
|
228
|
+
effects.out(`Existing Human identity ${existing.messengerIdentity} and Messenger profile will be retained.`);
|
|
229
|
+
// Supplied profile inputs never rename a retained root.
|
|
230
|
+
if (!['localUsername', 'name', 'surname'].some(key => options[key] !== undefined)) options.identityName ??= existing.messengerIdentity;
|
|
231
|
+
} else if (options.identityName === undefined || options.localUsername !== undefined) {
|
|
232
|
+
effects.out('Choose a local username (no global uniqueness check). Name and Surname appear in Messenger; the optional host name identifies this workspace.');
|
|
233
|
+
options.localUsername ??= await effects.askLine('Local username: ', (effects.username?.() ?? 'me').toLowerCase().replace(/[^a-z0-9-]/g, '-').slice(0, 30));
|
|
234
|
+
options.name ??= await effects.askLine('Name: ', '');
|
|
235
|
+
options.surname ??= await effects.askLine('Surname: ', '');
|
|
236
|
+
options.hostname ??= await effects.askLine('Host / machine name (optional): ', '');
|
|
281
237
|
}
|
|
282
238
|
if (['localUsername', 'name', 'surname'].some(key => options[key] !== undefined)) {
|
|
283
|
-
// Partial profile presets still collect missing fields on retained
|
|
284
|
-
//
|
|
239
|
+
// Partial profile presets still collect missing fields on the retained
|
|
240
|
+
// path; these inputs never replace its authoritative root.
|
|
285
241
|
effects.out('Name and Surname initialize a missing Messenger profile; an existing profile is retained.');
|
|
286
242
|
options.localUsername ??= await effects.askLine('Local username: ', (effects.username?.() ?? 'me').toLowerCase().replace(/[^a-z0-9-]/g, '-').slice(0, 30));
|
|
287
243
|
options.name ??= await effects.askLine('Name: ', '');
|
|
@@ -336,7 +292,7 @@ export async function collectSetupOptions(effects, presets = {}) {
|
|
|
336
292
|
}
|
|
337
293
|
const validated = validateSetupOptions(expandPaths(options, effects.home), { interactive: true });
|
|
338
294
|
const scopeLabel = scopeChoices.find(choice => choice.value === validated.scope).label;
|
|
339
|
-
effects.out(`Setup: ${scopeLabel}; ${validated.operation}${validated.mode ? ` using ${validated.mode === 'packages' ? 'native packages' : 'Docker'} in ${validated.stateDir}` : ` from ${validated.config}`}; integrations: ${validated.integrations?.join(', ') || 'none'}
|
|
295
|
+
effects.out(`Setup: ${scopeLabel}; ${validated.operation}${validated.mode ? ` using ${validated.mode === 'packages' ? 'native packages' : 'Docker'} in ${validated.stateDir}` : ` from ${validated.config}`}; integrations: ${validated.integrations?.join(', ') || 'none'}.`);
|
|
340
296
|
effects.out('Continue to apply these choices. Cancelling now leaves programs, services and data unchanged.');
|
|
341
297
|
if (!await effects.ask('Continue with this setup?', false)) throw new Error('Setup cancelled; nothing was changed');
|
|
342
298
|
return validated;
|