fleet: fix four defects that made no seat launchable on a clean install

Found by rehearsing the full install on a greenfield Debian 13 VM
(mosaic-sbx-dev) rather than on a host that already had a working Mosaic
tree. Each one is invisible on a developer machine and fatal on a new host.

1. Required system settings layer. The framework ships runtime/<harness>/
   for claude, codex, opencode and pi but a settings.json only for claude,
   so requiring the file made every pi, codex and opencode seat refuse to
   compose. The system layer is now optional; what must exist is the
   harness runtime directory, which is the thing that actually proves the
   framework is installed and carries that harness.

2. Required mcpServers in canonical Claude settings. The shipped
   settings.json has no such key, so `fleet agent new` refused to scaffold
   any Claude seat. Absent now means the same as empty. A present but
   wrong-typed value is still an error.

3. Never-enrolled hosts were told their auth directory "must be a real,
   non-symlink directory", which reads as a tampering report when the real
   situation is that nobody has logged in yet. Absent and wrong-shaped are
   now separate messages, and the absent one names `mosaic auth enroll`.

4. A fleet seat whose host had no system SOUL.md reached checkSoul(),
   which spawns the interactive `mosaic wizard` with inherited stdio. On a
   detached tmux seat that parks the pane on a menu with nobody at it: the
   session is live, the systemd unit reports fine, and no agent ever
   starts. A seat's identity is its own SOUL.md, written by `fleet agent
   new`, so the fleet path checks that and fails loudly instead.

Each fix has a regression test verified red against the unfixed source.
The launch.spec.ts seat fixtures gained a SOUL.md they always should have
had -- without it those tests were satisfied by whatever SOUL.md the
developer's real ~/.config/mosaic happened to contain.

Full suite before and after: the same 5 pre-existing failures in
mutator-gate.acceptance.spec.ts and install-ordering-guard.spec.ts,
1585 -> 1591 passing. typecheck and eslint clean.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WYgWocp36goy8hj2ui6ps1
This commit is contained in:
terra
2026-08-14 19:03:30 -05:00
co-authored by Claude Opus 5
parent c1a42cdb81
commit 309a99a600
6 changed files with 196 additions and 18 deletions
@@ -318,9 +318,20 @@ function lstatIfPresent(path: string): Stats | undefined {
}
}
function assertRealDirectory(path: string, label: string): void {
function assertRealDirectory(path: string, label: string, absentHint?: string): void {
const info = lstatIfPresent(path);
if (!info?.isDirectory() || info.isSymbolicLink()) {
// Absent and wrong-shaped are different problems and want different words. A host that has
// simply never enrolled a bundle was being told its auth directory "must be a real,
// non-symlink directory", which reads as a tampering report rather than "log in first".
if (!info) {
throw new FleetLaunchError(
'COMPOSITION_FAILED',
absentHint
? `${label} does not exist: ${path}${absentHint}`
: `${label} does not exist: ${path}`,
);
}
if (!info.isDirectory() || info.isSymbolicLink()) {
throw new FleetLaunchError(
'COMPOSITION_FAILED',
`${label} must be a real, non-symlink directory: ${path}`,
@@ -338,6 +349,22 @@ function assertContained(root: string, candidate: string, label: string): void {
}
}
/**
* Proves the framework is installed and knows this harness. This is the check the required
* system settings layer used to stand in for, moved to the thing that is actually always
* present: the runtime directory. A missing one means an uninstalled framework or a harness
* the install does not carry, and both are worth failing on before a seat is composed.
*/
function assertHarnessRuntimeInstalled(systemHome: string, harness: string): void {
const runtimeDir = join(systemHome, 'runtime', harness);
if (!lstatIfPresent(runtimeDir)?.isDirectory()) {
throw new FleetLaunchError(
'COMPOSITION_FAILED',
`harness runtime is not installed: ${runtimeDir} — install the Mosaic framework, or check the harness name`,
);
}
}
function readSettingsLayer(
name: SettingsLayer['name'],
path: string,
@@ -403,9 +430,10 @@ function resolveCredential(
assertRealDirectory(userHome, 'user Mosaic root');
const realUserHome = realpathSync(userHome);
const authDirectory = join(userHome, 'auth');
assertRealDirectory(authDirectory, 'auth directory');
const enrollHint = `no auth bundle has been enrolled yet — run: mosaic auth enroll --harness ${profile.harness} --bundle ${profile.bundle}`;
assertRealDirectory(authDirectory, 'auth directory', enrollHint);
const authRoot = join(authDirectory, profile.harness);
assertRealDirectory(authRoot, `${profile.harness} auth root`);
assertRealDirectory(authRoot, `${profile.harness} auth root`, enrollHint);
const resolvedAuthRoot = realpathSync(authRoot);
assertContained(realUserHome, resolvedAuthRoot, `${profile.harness} auth root`);
@@ -735,11 +763,16 @@ export function resolveFleetLaunchComposition(
}
const overlayPath = join(agentDir, profile.overlay ?? 'overlay.json');
assertContained(agentDir, overlayPath, 'agent overlay');
// The framework ships a runtime directory per harness but a settings.json only where it
// has settings to state -- as of 0.0.49 that is claude alone, so requiring the file made
// every pi, codex and opencode seat unlaunchable on a clean install. The install is what
// has to be present; an absent base layer just means the harness has no system settings.
assertHarnessRuntimeInstalled(roots.systemHome, profile.harness);
const layers: SettingsLayer[] = [
readSettingsLayer(
'system',
join(roots.systemHome, 'runtime', profile.harness, 'settings.json'),
true,
false,
),
readSettingsLayer(
'user',