/** * Checklist Registry - registry & filtering for checklist items * * Phase 1.1: Foundation for dynamic state + pattern-based checklists. * This file is intentionally minimal and side‑effect free so we can * evolve it safely without breaking existing review checklist logic. */ import type { WorkflowState } from '@shadel/workflow-core'; /** * Task context used for filtering checklist items. * * NOTE: This is a narrowed view of the full task; we only keep * fields that are useful for checklist filtering. */ export interface TaskContext { state: WorkflowState; goal?: string; patterns?: string[]; roles?: string[]; tags?: string[]; } export type ChecklistPriority = 'high' | 'medium' | 'low'; /** * Generic checklist item definition, designed to be compatible with * existing ReviewChecklistItem while adding filtering metadata. * * IMPORTANT: * - Do NOT remove or rename existing fields used by review checklist * until migration is fully implemented and tested. * - New fields are optional so we don't break old data. */ export interface ChecklistItem { id: string; title: string; description: string; required?: boolean; priority?: ChecklistPriority; applicableStates?: WorkflowState[]; applicableGoals?: string[]; applicablePatterns?: string[]; applicableRoles?: string[]; applicableTags?: string[]; condition?: (context: TaskContext) => boolean; } /** * Pattern checklist item - specialization for pattern-based checks. * * This extends ChecklistItem with a required patternId so later phases * (PatternChecklistGenerator, PatternVerificationService) can rely on it * without changing the base interface. */ export interface PatternChecklistItem extends ChecklistItem { patternId: string; } /** * ChecklistRegistry * * - Registers checklist items (state + pattern based) * - Provides filtered view for a given TaskContext * - Uses a simple in‑memory cache to avoid recomputing filters * * NOTE: * - This class is intentionally framework‑agnostic (no fs, no side effects) * - Integration with services (StateChecklistService, PatternChecklistGenerator) * will be done in later phases. */ export declare class ChecklistRegistry { private items; private cache; private defaultItemsRegistered; /** * Register a new checklist item. * * Safe to call multiple times; duplicated IDs will overwrite the previous * definition to keep latest version. */ register(item: ChecklistItem): void; /** * Get all checklist items matching the given context. * Results are cached based on a stable cache key. */ getChecklistsForContext(context: TaskContext): ChecklistItem[]; /** * Build a stable cache key from context. We only include fields that * affect filtering. */ private buildCacheKey; /** * Check whether an item matches the given context. * * Matching is designed to be: * - Conservative (if metadata missing → treat as globally applicable) * - Performance optimized (quick checks first, fail fast) * * Order of checks (fastest to slowest): * 1. State filter (enum equality - fastest) * 2. Arrays existence check (early exit if no arrays) * 3. Array includes (patterns, roles, tags - fast O(n)) * 4. String search (goal keywords - slower O(n*m)) * 5. Custom condition (function call - slowest) */ private matchesContext; /** * Register default state-specific checklist items. * * This method can be called multiple times safely (idempotent). * Only registers defaults once to avoid duplicates. * * Phase 1.4: Register default checklist items */ registerDefaultChecklists(): void; /** * Register multiple checklist items at once. * Useful for bulk registration of default items. */ registerItems(items: ChecklistItem[]): void; /** * Check if default items have been registered. */ hasDefaultItems(): boolean; /** * Get all registered items (for testing/debugging). */ getAllItems(): readonly ChecklistItem[]; /** * Clear all registered items (for testing). */ clear(): void; }