/** * Control Plane Supporting Types * * This module defines supporting types and type aliases used throughout * the control plane architecture. * * @module control-plane/types * @since 3.0.0 */ /** * Scanner execution frequency. * * Determines when/how often a scanner runs: * - **on-demand**: Only when explicitly invoked * - **on-change**: When source data changes (file watch, git hooks, etc.) * - **interval**: On a periodic schedule * * @example * ```typescript * const config: FilesystemScanConfig = { * frequency: 'on-change', // Re-scan when files change * watchPaths: ['src/**'] * }; * ``` */ export type ScanFrequency = 'on-demand' | 'on-change' | 'interval'; /** * Scanner status. * * Tracks scanner lifecycle state: * - **idle**: Not currently scanning * - **running**: Scan in progress * - **completed**: Last scan finished successfully * - **failed**: Last scan failed * - **disabled**: Scanner is disabled */ export type ScannerStatus = 'idle' | 'running' | 'completed' | 'failed' | 'disabled'; /** * Processor execution mode. * * - **full**: Full rebuild from artifacts (ignores previous state) * - **incremental**: Compute diff from previous state and merge * - **auto**: Processor decides based on state version/freshness */ export type ProcessorMode = 'full' | 'incremental' | 'auto'; /** * State update strategy. * * - **replace**: Completely replace previous state * - **merge**: Merge with previous state (keep unchanged parts) * - **diff**: Store only changes (requires reconstruction for queries) */ export type StateUpdateStrategy = 'replace' | 'merge' | 'diff'; /** * Rule severity level. * * Determines how violations are handled: * - **error**: Blocks operation, non-zero exit code * - **warning**: Logged but doesn't block, zero exit code * - **info**: Informational only, for reporting */ export type RuleSeverity = 'error' | 'warning' | 'info'; /** * Rule condition operator. * * Specifies what must hold about an evaluation result: * - **always**: `result.ok === true` * - **never**: `result.ok === false` * - **threshold**: Numeric value satisfies min/max bounds * - **custom**: Custom predicate function */ export type RuleMustHold = 'always' | 'never' | 'threshold' | 'custom'; /** * Rule execution status. * * Tracks rule evaluation lifecycle: * - **pending**: Not yet evaluated * - **evaluating**: Evaluation in progress * - **satisfied**: Rule condition holds (no violation) * - **violated**: Rule condition does not hold * - **skipped**: Rule was not evaluated (disabled, missing state, etc.) * - **error**: Evaluation failed with error */ export type RuleStatus = 'pending' | 'evaluating' | 'satisfied' | 'violated' | 'skipped' | 'error'; /** * Evaluation execution mode. * * - **synchronous**: Wait for result before continuing * - **asynchronous**: Return immediately, result delivered later * - **cached**: Use cached result if available */ export type EvaluationMode = 'synchronous' | 'asynchronous' | 'cached'; /** * Aggregated rule evaluation summary. * * Summarizes results across multiple rules: * - Total rules evaluated * - Counts by status (satisfied, violated, skipped, error) * - Counts by severity (errors, warnings, info) * - Overall pass/fail * * @example * ```typescript * const summary: RuleSummary = { * totalRules: 10, * satisfied: 7, * violated: 2, * skipped: 1, * errors: 0, * errorCount: 1, * warningCount: 1, * infoCount: 0, * hasErrors: true, * hasWarnings: true * }; * ``` */ export interface RuleSummary { /** Total number of rules evaluated */ totalRules: number; /** Number of rules satisfied (no violations) */ satisfied: number; /** Number of rules violated */ violated: number; /** Number of rules skipped (disabled, missing state, etc.) */ skipped: number; /** Number of rules that failed with errors during evaluation */ errors: number; /** Number of error-severity violations */ errorCount: number; /** Number of warning-severity violations */ warningCount: number; /** Number of info-severity violations */ infoCount: number; /** Whether any error-severity violations exist */ hasErrors: boolean; /** Whether any warning-severity violations exist */ hasWarnings: boolean; } /** * Result of evaluating a single rule. * * Contains: * - Rule ID * - Whether rule was satisfied * - List of violations (if any) * - Execution metadata * * @example * ```typescript * const evaluation: RuleEvaluation = { * ruleId: 'branch-protection', * satisfied: false, * violations: [{ * ruleId: 'branch-protection', * evaluation: {...}, * message: 'Cannot work on protected branch', * severity: 'error' * }], * metadata: { * evaluationDurationMs: 12, * stateVersion: 5 * } * }; * ``` */ export interface RuleEvaluation { /** ID of the rule evaluated */ ruleId: string; /** Whether the rule was satisfied (no violations) */ satisfied: boolean; /** List of violations (empty if satisfied) */ violations: import('./core').Violation[]; /** Optional metadata about evaluation */ metadata?: Record; } /** * Cache key for artifacts, states, or results. * * Composite key used for caching: * - type: What kind of cached item (artifact, state, result) * - id: Unique identifier (scanner ID, state ID, etc.) * - version: Optional version for cache invalidation * * @example * ```typescript * const artifactKey: CacheKey = { * type: 'artifact', * id: 'git', * version: '2025-11-24T12:00:00Z' * }; * * const stateKey: CacheKey = { * type: 'state', * id: 'filesystem-state:/project', * version: '5' * }; * ``` */ export interface CacheKey { /** Type of cached item */ type: 'artifact' | 'state' | 'result'; /** Unique identifier for item */ id: string; /** Optional version for cache invalidation */ version?: string; } /** * Cache entry with metadata. * * Wraps cached item with: * - Timestamp when cached * - TTL (time to live) * - Access count for LRU eviction * * @template T The type of cached item */ export interface CacheEntry { /** The cached item */ value: T; /** When this item was cached */ cachedAt: Date; /** Time to live in milliseconds (optional) */ ttl?: number; /** Number of times this item was accessed */ accessCount: number; /** Last access timestamp */ lastAccessedAt: Date; } /** * Execution plan for orchestrating scanners, processors, and rules. * * The orchestrator uses this to determine: * - Which scanners to run (based on rule triggers) * - Execution order (dependency graph) * - Parallelization opportunities * - State dependencies * * @example * ```typescript * const plan: ExecutionPlan = { * scanners: [ * { id: 'git', parallelizable: true }, * { id: 'filesystem', parallelizable: true } * ], * processors: [ * { id: 'git-processor', dependsOn: ['git'] }, * { id: 'filesystem-processor', dependsOn: ['filesystem'] }, * { id: 'property-graph', dependsOn: ['filesystem', 'ast'] } * ], * rules: [ * { id: 'branch-protection', dependsOn: ['git-state'] }, * { id: 'architecture-layering', dependsOn: ['property-graph'] } * ] * }; * ``` */ export interface ExecutionPlan { /** Scanners to execute */ scanners: Array<{ id: string; parallelizable: boolean; }>; /** Processors to execute */ processors: Array<{ id: string; dependsOn: string[]; }>; /** Rules to evaluate */ rules: Array<{ id: string; dependsOn: string[]; }>; } /** * Execution context passed through pipeline. * * Contains: * - Cached artifacts * - Cached states * - Evaluation results * - Execution metadata * * Allows components to access previous results without re-computation. */ export interface ExecutionContext { /** Cached scan artifacts by scanner ID */ artifacts: Map; /** Cached states by state ID (serialized as string) */ states: Map; /** Evaluation results by rule ID */ evaluations: Map; /** Execution start time */ startedAt: Date; /** Optional metadata about execution */ metadata?: Record; } /** * Result type for operations that may fail. * * Similar to Rust's Result or Haskell's Either. * Avoids throwing exceptions for expected failures. * * @template T Success value type * @template E Error type (defaults to Error) * * @example * ```typescript * function parseConfig(yaml: string): Result { * try { * const config = YAML.parse(yaml); * return { ok: true, value: config }; * } catch (error) { * return { ok: false, error: new ParseError(error.message) }; * } * } * * const result = parseConfig(yamlString); * if (result.ok) { * console.log('Config:', result.value); * } else { * console.error('Parse error:', result.error); * } * ``` */ export type Result = { ok: true; value: T; } | { ok: false; error: E; }; /** * Async result type. * * Promise that resolves to Result. * Combines async/await with Result pattern. * * @template T Success value type * @template E Error type */ export type AsyncResult = Promise>; /** * Type guard to check if result is success. * * @param result Result to check * @returns True if result is success */ export declare function isOk(result: Result): result is { ok: true; value: T; }; /** * Type guard to check if result is error. * * @param result Result to check * @returns True if result is error */ export declare function isErr(result: Result): result is { ok: false; error: E; }; import type { FilePath } from '../value-objects/FilePath'; import type { BranchName } from '../value-objects/BranchName'; /** * File tree node. */ export interface FileTreeNode { /** Node name (file or directory name) */ name: string; /** Full path */ path: FilePath; /** Whether this is a directory */ isDirectory: boolean; /** Child nodes (if directory) */ children?: Map; /** File count (for directories, recursive) */ fileCount?: number; } /** * Filesystem state data. * * Contains processed filesystem information with efficient * data structures for querying. */ export interface FilesystemStateData { /** Root directory */ root: FilePath; /** File tree structure */ tree: FileTreeNode; /** File index: path → FilePath */ fileIndex: Map; /** Directory index: path → FilePath[] (files in directory) */ dirIndex: Map; /** Total number of files */ totalFiles: number; /** Total size in bytes */ totalSize: number; } /** * Git state data. * * Contains processed Git information with domain objects. */ export interface GitStateData { /** Working directory */ workingDirectory: FilePath; /** Current branch (undefined if detached HEAD) */ currentBranch?: BranchName; /** List of uncommitted files */ uncommittedFiles: FilePath[]; /** Whether there are uncommitted changes */ hasUncommittedChanges: boolean; /** Last commit hash */ lastCommitHash?: string; /** Last commit message */ lastCommitMessage?: string; /** Remote branch */ remoteBranch?: BranchName; /** Whether working tree is clean */ isClean: boolean; } /** * Claude settings state data. * * Contains processed Claude settings with efficient lookup structures. */ export interface ClaudeSettingsStateData { /** Path to settings file */ settingsPath: FilePath; /** Whether settings file exists */ settingsExists: boolean; /** Whether settings is valid JSON */ isValid: boolean; /** Set of read-only patterns for fast lookup */ readOnlyPatterns: Set; /** List of patterns (for display) */ readOnlyPatternsList: string[]; /** Whether any read-only patterns are configured */ hasReadOnlyPatterns: boolean; /** Parse error message (if invalid) */ parseError?: string; } /** * Git evaluation operation types. */ export type GitOperation = 'branchIsProtected' | 'hasUncommittedChanges' | 'isOnBranch' | 'isClean'; /** * Parameters for Git evaluations. */ export interface GitEvalParams { /** Operation to perform */ operation: GitOperation; /** Protected branches list (for 'branchIsProtected' operation) */ protectedBranches?: string[]; /** Branch name (for 'isOnBranch' operation) */ branchName?: string; } /** * Payload for 'branchIsProtected' operation. */ export interface GitBranchProtectedPayload { currentBranch: string | null; isProtected: boolean; protectedBranches: string[]; } /** * Payload for 'hasUncommittedChanges' operation. */ export interface GitUncommittedChangesPayload { hasChanges: boolean; fileCount: number; files: string[]; } /** * Payload for 'isOnBranch' operation. */ export interface GitIsOnBranchPayload { currentBranch: string | null; targetBranch: string; matches: boolean; } /** * Payload for 'isClean' operation. */ export interface GitIsCleanPayload { isClean: boolean; uncommittedFileCount: number; } /** * Union type for all Git evaluation payloads. */ export type GitEvalPayload = GitBranchProtectedPayload | GitUncommittedChangesPayload | GitIsOnBranchPayload | GitIsCleanPayload; /** * Filesystem evaluation operation types. */ export type FilesystemOperation = 'exists' | 'glob' | 'list' | 'count' | 'isMonorepoRoot'; /** * Parameters for filesystem evaluations. */ export interface FilesystemEvalParams { /** Operation to perform */ operation: FilesystemOperation; /** Path (for 'exists' operation) */ path?: string; /** Glob pattern (for 'glob' operation) */ pattern?: string; /** Directory path (for 'list' operation) */ directory?: string; } /** * Payload for 'exists' operation. */ export interface FsExistsPayload { path: string; exists: boolean; } /** * Payload for 'glob' operation. */ export interface FsGlobPayload { pattern: string; matches: string[]; count: number; } /** * Payload for 'list' operation. */ export interface FsListPayload { directory: string; files: string[]; count: number; } /** * Payload for 'count' operation. */ export interface FsCountPayload { pattern?: string; count: number; totalSize: number; } /** * Payload for 'isMonorepoRoot' operation. */ export interface FsMonorepoRootPayload { isMonorepo: boolean; isRoot: boolean; monorepoType?: string; projectCount: number; projects: Array<{ name: string; path: string; }>; } /** * Union type for all filesystem evaluation payloads. */ export type FilesystemEvalPayload = FsExistsPayload | FsGlobPayload | FsListPayload | FsCountPayload | FsMonorepoRootPayload; /** * Claude settings evaluation operation types. */ export type ClaudeSettingsOperation = 'isFileProtected' | 'hasReadOnlyPatterns' | 'settingsValid'; /** * Parameters for Claude settings evaluations. */ export interface ClaudeSettingsEvalParams { /** Operation to perform */ operation: ClaudeSettingsOperation; /** File path to check (for 'isFileProtected') */ filePath?: string; /** Multiple files to check (for 'isFileProtected') */ requiredFiles?: string[]; } /** * Payload for 'isFileProtected' operation. */ export interface ClaudeSettingsFileProtectedPayload { /** Single file path being checked */ filePath?: string; /** Multiple files being checked */ requiredFiles?: string[]; /** Whether the file is protected */ isProtected: boolean; /** Pattern that matched (if protected) */ matchedPattern?: string; /** Whether all required files are protected */ allFilesProtected: boolean; /** List of files that are NOT protected */ unprotectedFiles: string[]; /** All configured read-only patterns */ readOnlyPatterns: string[]; } /** * Payload for 'hasReadOnlyPatterns' operation. */ export interface ClaudeSettingsHasPatternsPayload { /** Whether any patterns are configured */ hasPatterns: boolean; /** Number of patterns configured */ patternCount: number; /** List of all patterns */ patterns: string[]; } /** * Payload for 'settingsValid' operation. */ export interface ClaudeSettingsValidPayload { /** Whether settings file exists */ settingsExists: boolean; /** Whether settings is valid JSON */ isValid: boolean; /** Parse error message if invalid */ parseError?: string; } /** * Union type for all Claude settings evaluation payloads. */ export type ClaudeSettingsEvalPayload = ClaudeSettingsFileProtectedPayload | ClaudeSettingsHasPatternsPayload | ClaudeSettingsValidPayload; /** * Extract payload type from Scanner. * * @example * ```typescript * type GitPayload = ScannerPayload; * ``` */ export type ScannerPayload = S extends import('./core').Scanner ? P : never; /** * Extract config type from Scanner. */ export type ScannerConfig = S extends import('./core').Scanner ? C : never; /** * Extract state data type from Processor. */ export type ProcessorStateData

= P extends import('./core').Processor ? D : never; /** * Extract params type from EvaluationInterface. */ export type EvaluationParams = E extends import('./core').EvaluationInterface ? P : never; /** * Extract payload type from EvaluationInterface. */ export type EvaluationPayload = E extends import('./core').EvaluationInterface ? P : never; /** * Extract view model type from StateView. */ export type ViewModelType = V extends import('./core').StateView ? VM : never; //# sourceMappingURL=types.d.ts.map