feat(fleet): harden v1 migration preview
Some checks failed
ci/woodpecker/pr/ci Pipeline failed

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Jarvis
2026-07-16 00:57:33 -05:00
parent 0e814324ca
commit 04891422b3
14 changed files with 477 additions and 82 deletions

View File

@@ -1,6 +1,5 @@
import { createHash } from 'node:crypto';
import { readFile } from 'node:fs/promises';
import { homedir } from 'node:os';
import { join } from 'node:path';
import YAML from 'yaml';
import { canonicalizeRoleClass, type PersonaDirs } from '../commands/fleet-personas.js';
@@ -646,11 +645,14 @@ export async function previewV1ToV2Migration(
}
}
const canonicalInventoryOnlyAgents = [...inventoryOnlyAgents].sort((left, right): number =>
compareCodePoints(left.name, right.name),
);
const status = blockers.length === 0 ? 'ready' : 'blocked';
return {
status,
inventory,
inventoryOnlyAgents,
inventoryOnlyAgents: canonicalInventoryOnlyAgents,
blockers,
...(status === 'ready' && canonicalRoster && canonicalYaml
? { canonicalRoster, canonicalYaml }
@@ -664,10 +666,12 @@ export async function previewV1ToV2Migration(
...(status === 'ready' && canonicalYaml
? { candidate: { sha256: sha256(canonicalYaml), generation: decisions.generation } }
: {}),
observations,
observations: [...observations].sort((left, right): number =>
compareCodePoints(left.agent, right.agent),
),
excludedInventory: [
...(raw.connector === undefined ? [] : ['connector']),
...inventoryOnlyAgents.map(({ name }): string => `agents.${name}`),
...canonicalInventoryOnlyAgents.map(({ name }): string => `agents.${name}`),
],
recovery: {
executable: false,
@@ -1161,9 +1165,7 @@ function normalizeRuntimes(
}
const runtime = record(value);
const resetCommand =
stringValue(runtime.reset_command) ||
stringValue(runtime.resetCommand) ||
V1_RUNTIME_RESETS[name];
stringValue(runtime.reset_command) || stringValue(runtime.resetCommand) || '/clear';
result[name] = { reset_command: resetCommand };
}
return result;
@@ -1294,15 +1296,11 @@ function generatedValues(
MOSAIC_AGENT_MODEL: agent.model,
MOSAIC_AGENT_REASONING: agent.reasoning,
MOSAIC_AGENT_TOOL_POLICY: agent.toolPolicy,
MOSAIC_AGENT_WORKDIR: expandHome(agent.workingDirectory),
MOSAIC_AGENT_WORKDIR: agent.workingDirectory,
MOSAIC_TMUX_SOCKET: roster.tmux.socketName,
};
}
function expandHome(path: string): string {
return path === '~' ? homedir() : path.startsWith('~/') ? join(homedir(), path.slice(2)) : path;
}
function safeEnvironmentDiagnostic(error: unknown): string {
if (
typeof error === 'object' &&