/**
 * InstinctEngine Types
 *
 * Types for the self-improvement engine that extracts patterns,
 * tracks failures, and proposes self-patches.
 */

/** An extracted pattern (instinct) */
export interface Instinct {
  /** Unique name */
  name: string
  /** Trigger words that activate this instinct */
  triggers: string[]
  /** Confidence score (0-1) */
  confidence: number
  /** How many times this pattern has been used */
  usageCount: number
  /** When it was first extracted */
  createdAt: number
  /** When it was last used */
  lastUsed: number
  /** Steps to follow */
  steps: string[]
  /** Gotchas to watch out for */
  gotchas: string[]
  /** Scope: project-local or global */
  scope: 'project' | 'global'
}

/** A tracked failure pattern */
export interface FailurePattern {
  /** Unique identifier */
  id: string
  /** Category of failure */
  type: FailureType
  /** Human-readable description */
  description: string
  /** Number of occurrences */
  count: number
  /** When it first occurred */
  firstOccurrence: number
  /** When it last occurred */
  lastOccurrence: number
  /** Files typically affected */
  affectedFiles: string[]
  /** Threshold for triggering a self-patch proposal */
  threshold: number
  /** Whether a patch has been proposed */
  patchProposed: boolean
}

/** Types of failures we track */
export type FailureType =
  | 'type_mismatch'
  | 'missing_import'
  | 'missing_test'
  | 'missing_error_handling'
  | 'forgot_typescript_types'
  | 'forgot_validation'
  | 'runtime_error'
  | 'test_failure'
  | 'lint_failure'
  | 'build_failure'
  | 'unknown'

/** A proposed self-patch */
export interface SelfPatch {
  /** What type of patch */
  type: 'hook' | 'rule' | 'instinct_modification' | 'config'
  /** Human-readable description */
  description: string
  /** Reason for the patch */
  reason: string
  /** The actual patch content (hook script, rule text, etc.) */
  content: string
  /** Which failure it addresses */
  failureId: string
  /** When it was proposed */
  proposedAt: number
  /** Whether the user approved it */
  approved: boolean
}

/** Failure tracking state */
export interface FailureTrackingState {
  /** Schema version */
  version: 1
  /** Tracked failures */
  failures: FailurePattern[]
  /** Proposed patches */
  patches: SelfPatch[]
}
