/** * Type definitions for the generate command state machine * * Defines context, events, and state types for the generate flow. */ import type { StorageMode } from '../../constants.js'; import type { AvailablePackages } from '../../context/framework-detection.js'; import type { PackageManagerResult } from '../../context/package-manager-detection.js'; import type { CliContext } from '../../context/types.js'; import type { BaseMachineContext, FileModification } from '../types.js'; /** * UI style selection for component generation */ export type UIStyle = 'prebuilt' | 'expanded'; /** * Theme preset */ export type ExpandedTheme = 'none' | 'minimal' | 'dark' | 'tailwind'; /** * Context for the generate state machine */ export interface GenerateMachineContext extends BaseMachineContext { /** Reference to the CLI context (not serializable, set on init) */ cliContext: CliContext | null; /** Project root directory */ projectRoot: string; /** Detected framework information */ framework: { name: string | null; version: string | null; pkg: AvailablePackages; hasReact: boolean; reactVersion: string | null; tailwindVersion: string | null; } | null; /** Detected package manager */ packageManager: PackageManagerResult | null; /** Whether preflight checks passed */ preflightPassed: boolean; /** Preflight check details */ preflightChecks: PreflightCheckResult[]; /** Selected storage mode */ selectedMode: StorageMode | null; /** Mode passed as CLI argument */ modeArg: StorageMode | null; /** Hosted provider selection when mode is hosted */ hostedProvider: 'inth.com' | 'self-hosted' | null; /** Backend URL for hosted mode (inth.com or self-hosted provider) */ backendURL: string | null; /** Whether to proxy requests via Next.js rewrites */ proxyNextjs: boolean; /** Whether to enable SSR for initial data fetch */ enableSSR: boolean; /** Whether to install and enable c15t DevTools */ enableDevTools: boolean; /** UI component style selection */ uiStyle: UIStyle; /** Theme preset for expanded components */ expandedTheme: ExpandedTheme | null; /** Whether to add c15t scripts package */ addScripts: boolean; /** Selected scripts to pre-configure */ selectedScripts: string[]; /** Paths to files created during generation */ filesCreated: string[]; /** Files modified with backup for rollback */ filesModified: FileModification[]; /** Dependencies to install */ dependenciesToAdd: string[]; /** Whether user confirmed dependency installation */ installConfirmed: boolean; /** Whether installation was attempted */ installAttempted: boolean; /** Whether installation succeeded */ installSucceeded: boolean; /** Whether to run database migrations (self-hosted mode) */ runMigrations: boolean; /** Whether agent skills were installed */ skillsInstalled: boolean; /** Reason for cancellation if cancelled */ cancelReason: string | null; /** Whether cleanup has been performed */ cleanupDone: boolean; } /** * Result of a preflight check */ export interface PreflightCheckResult { name: string; status: 'pass' | 'warn' | 'fail'; message: string; hint?: string; } /** * Events for the generate state machine */ export type GenerateMachineEvent = { type: 'START'; } | { type: 'CANCEL'; reason?: string; } | { type: 'RETRY'; } | { type: 'RESET'; } | { type: 'PREFLIGHT_COMPLETE'; result: { passed: boolean; checks: PreflightCheckResult[]; projectRoot: string; framework: GenerateMachineContext['framework']; packageManager: PackageManagerResult; }; } | { type: 'PREFLIGHT_RETRY'; } | { type: 'SELECT_MODE'; mode: StorageMode; } | { type: 'MODE_SELECTED'; mode: StorageMode; } | { type: 'ACCOUNT_CREATION_COMPLETE'; needsAccount: boolean; } | { type: 'BROWSER_OPENED'; } | { type: 'BACKEND_URL_ENTERED'; url: string; } | { type: 'BACKEND_OPTIONS_COMPLETE'; proxyNextjs: boolean; } | { type: 'FRONTEND_OPTIONS_COMPLETE'; enableSSR?: boolean; enableDevTools?: boolean; uiStyle: UIStyle; expandedTheme?: ExpandedTheme; } | { type: 'SCRIPTS_OPTION_COMPLETE'; addScripts: boolean; } | { type: 'FILES_GENERATED'; filesCreated: string[]; filesModified: FileModification[]; } | { type: 'FILE_GENERATION_ERROR'; error: Error; } | { type: 'CONFIRM_INSTALL'; confirmed: boolean; } | { type: 'INSTALL_COMPLETE'; success: boolean; } | { type: 'SKIP_INSTALL'; } | { type: 'SHOW_SUMMARY'; } | { type: 'GITHUB_STAR_PROMPT'; opened: boolean; } | { type: 'COMPLETE'; } | { type: 'ROLLBACK_COMPLETE'; } | { type: 'CLEANUP_COMPLETE'; }; /** * State value types for the generate machine */ export type GenerateMachineStateValue = 'idle' | 'preflight' | 'preflightError' | 'modeSelection' | 'hostedMode' | 'offlineMode' | 'customMode' | 'backendOptions' | 'frontendOptions' | 'scriptsOptions' | 'fileGeneration' | 'dependencyInstall' | 'summary' | 'skillsInstall' | 'githubStar' | 'complete' | 'error' | 'cancelling' | 'cleanup' | 'exited'; /** * Initial context for the generate machine */ export declare const createInitialContext: (cliContext?: CliContext, modeArg?: StorageMode) => GenerateMachineContext; /** * Type guard for checking if a mode requires backend URL */ export declare const modeRequiresBackend: (mode: StorageMode) => boolean; /** * Type guard for checking if framework is Next.js */ export declare const isNextjsFramework: (framework: GenerateMachineContext['framework']) => boolean; /** * Type guard for checking if framework has React */ export declare const hasReactFramework: (framework: GenerateMachineContext['framework']) => boolean;