import type { CapabilityWorkspaceType } from './capability-workspace.js'; interface ResourceChoice { type: CapabilityWorkspaceType; id: string; selection_ref: string; } interface ContentConflict { type: CapabilityWorkspaceType; id: string; resource_id: string; selection_ref?: string; } interface SyncFailure { type: CapabilityWorkspaceType; id: string; action: string; code?: string; } export type StartupBlocker = | ({ code: 'CAPABILITY_SELECTION_REQUIRED' } & ResourceChoice) | ({ code: 'CAPABILITY_CONTENT_CONFLICT' } & ContentConflict) | { code: 'SKILL_NAME_CONFLICT'; type: CapabilityWorkspaceType; id: string }; /** Preserve resource choices that must be handled before starting, including personas. */ export function summarizeStartupBlockers( selections: readonly ResourceChoice[], conflicts: readonly ContentConflict[], failures: readonly SyncFailure[], ): { blockers: StartupBlocker[] } { return { blockers: [ ...selections.map(({ type, id, selection_ref }): StartupBlocker => ({ code: 'CAPABILITY_SELECTION_REQUIRED', type, id, selection_ref, })), ...conflicts.map(({ type, id, resource_id, selection_ref }): StartupBlocker => ({ code: 'CAPABILITY_CONTENT_CONFLICT', type, id, resource_id, ...(selection_ref ? { selection_ref } : {}), })), ...failures.filter(value => value.action === 'equipment' && value.code === 'SKILL_NAME_CONFLICT') .map(({ type, id }): StartupBlocker => ({ code: 'SKILL_NAME_CONFLICT', type, id })), ], }; }