/**
 * Public entry point for `core/`.
 *
 * Right now this re-exports the foundational utilities (config, logger, ids,
 * time). Subsequent phases will plug `createMemoryCore` and the algorithm
 * pipeline in here.
 */

export * from "./id.js";
export * from "./time.js";

export {
  loadConfig,
  loadConfigForAgent,
  resolveConfig,
  resolveHome,
  DEFAULT_CONFIG,
  SECRET_FIELD_PATHS,
  type ResolvedConfig,
  type ResolvedHome,
} from "./config/index.js";

export {
  rootLogger,
  initLogger,
  initTestLogger,
  flushLogger,
  shutdownLogger,
  memoryBuffer,
} from "./logger/index.js";

export {
  openDb,
  runMigrations,
  runMigrationsForPath,
  makeRepos,
  encodeVector,
  decodeVector,
  cosine,
  topKCosine,
  scanAndTopK,
  type StorageDb,
  type Repos,
  type OpenDbOptions,
  type MigrationsResult,
  type VectorHit,
} from "./storage/index.js";
export { withCtx, getCtx, ensureTraceId } from "./logger/context.js";
export { runSelfCheck } from "./logger/self-check.js";

export {
  createLlmClient,
  createLlmClientWithProvider,
  makeProviderFor as makeLlmProviderFor,
  parseLlmJson,
  buildJsonSystemHint,
  registerHostLlmBridge,
  getHostLlmBridge,
  OpenAiLlmProvider,
  AnthropicLlmProvider,
  GeminiLlmProvider,
  BedrockLlmProvider,
  HostLlmProvider,
  LocalOnlyLlmProvider,
  REFLECTION_SCORE_PROMPT,
  REWARD_R_HUMAN_PROMPT,
  L2_INDUCTION_PROMPT,
  L3_ABSTRACTION_PROMPT,
  DECISION_REPAIR_PROMPT,
  SKILL_CRYSTALLIZE_PROMPT,
  languageSteeringLine,
  type HostLlmBridge,
  type HostLlmCompleteInput,
  type HostLlmCompletion,
  type LlmCallOptions,
  type LlmCompleteJsonOptions,
  type LlmClient,
  type LlmClientStats,
  type LlmCompletion,
  type LlmConfig,
  type LlmJsonCompletion,
  type LlmMessage,
  type LlmProvider,
  type LlmProviderCtx,
  type LlmProviderLogger,
  type LlmProviderName,
  type LlmRole,
  type LlmStreamChunk,
  type LlmUsage,
  type ProviderCallInput,
  type ProviderCompletion,
} from "./llm/index.js";

export {
  createEmbedder,
  createEmbedderWithProvider,
  makeProviderFor,
  LruEmbedCache,
  NullEmbedCache,
  makeCacheKey,
  l2Normalize,
  enforceDim,
  postProcess,
  toFloat32,
  LocalEmbeddingProvider,
  OpenAiEmbeddingProvider,
  GeminiEmbeddingProvider,
  CohereEmbeddingProvider,
  VoyageEmbeddingProvider,
  MistralEmbeddingProvider,
  type EmbedCache,
  type EmbedCacheStats,
  type EmbedInput,
  type EmbedRole,
  type EmbedStats,
  type Embedder,
  type EmbeddingConfig,
  type EmbeddingProvider,
  type EmbeddingProviderName,
  type ProviderCallCtx,
  type ProviderLogger,
} from "./embedding/index.js";

export {
  createSessionManager,
  createEpisodeManager,
  createIntentClassifier,
  createSessionEventBus,
  listHeuristicRules,
  HEURISTIC_RULES,
  matchFirst,
  retrievalFor,
  adaptSessionsRepo,
  adaptEpisodesRepo,
  type SessionManager,
  type SessionManagerDeps,
  type StartEpisodeInput,
  type EpisodeManager,
  type EpisodeManagerDeps,
  type IntentClassifier,
  type IntentClassifierOptions,
  type HeuristicRule,
  type HeuristicMatch,
  type SessionRepo as SessionPersistenceRepo,
  type EpisodesRepo as EpisodePersistenceRepo,
  type EpisodeCloseReason,
  type EpisodeFinalizeInput,
  type EpisodeSnapshot,
  type EpisodeStartInput,
  type EpisodeTurn,
  type IntentDecision,
  type IntentKind,
  type SessionEvent,
  type SessionEventBus,
  type SessionEventKind,
  type SessionEventListener,
  type SessionOpenInput,
  type SessionSnapshot,
  type TurnRole,
} from "./session/index.js";
export {
  createCaptureRunner,
  attachCaptureSubscriber,
  createCaptureEventBus,
  extractSteps as extractCaptureSteps,
  normalizeSteps as normalizeCaptureSteps,
  extractReflection,
  synthesizeReflection,
  scoreReflection,
  disabledScore as disabledReflectionScore,
  embedSteps as embedCaptureSteps,
  type CaptureConfig,
  type CaptureDeps,
  type CaptureEvent,
  type CaptureEventBus,
  type CaptureEventKind,
  type CaptureEventListener,
  type CaptureInput,
  type CaptureResult,
  type CaptureRunner,
  type CaptureSubscription,
  type CaptureSubscriberOptions,
  type NormalizedStep,
  type ReflectionScore,
  type ScoredStep,
  type StepCandidate,
  type TraceCandidate,
} from "./capture/index.js";

export {
  createRewardRunner,
  attachRewardSubscriber,
  createRewardEventBus,
  backprop,
  priorityFor,
  scoreHuman,
  heuristicScore,
  buildTaskSummary,
  type BackpropInput,
  type BackpropResult,
  type BackpropUpdate,
  type HumanScore,
  type HumanScoreInput,
  type RewardConfig,
  type RewardDeps,
  type RewardEvent,
  type RewardEventBus,
  type RewardEventKind,
  type RewardEventListener,
  type RewardInput,
  type RewardResult,
  type RewardRunner,
  type RewardSubscription,
  type RewardSubscriberOptions,
  type TaskSummary,
  type UserFeedback,
} from "./reward/index.js";

export {
  turnStartRetrieve,
  toolDrivenRetrieve,
  skillInvokeRetrieve,
  subAgentRetrieve,
  repairRetrieve,
  Retriever,
  createRetrievalEventBus,
  buildQuery as buildRetrievalQuery,
  extractTags as extractRetrievalTags,
  type TurnStartRetrieveCtx,
  type ToolDrivenRetrieveCtx,
  type SkillInvokeRetrieveCtx,
  type SubAgentRetrieveCtx,
  type RepairRetrieveCtx,
  type RetrieveOptions,
  type RetrievalCtx,
  type RetrievalConfig,
  type RetrievalDeps,
  type RetrievalEmbedder,
  type RetrievalRepos,
  type RetrievalResult,
  type RetrievalStats,
  type RetrievalEvent,
  type RetrievalEventBus,
  type RetrievalEventKind,
  type RetrievalEventListener,
  type SkillCandidate,
  type TraceCandidate as RetrievedTraceCandidate,
  type EpisodeCandidate as RetrievedEpisodeCandidate,
  type WorldModelCandidate,
  type TierCandidate,
  type TierKind,
  type TraceVecKind,
  type RankedSnippet,
  type SkillInvokeCtx as SkillInvokeRequestCtx,
  type SubAgentCtx as SubAgentRequestCtx,
} from "./retrieval/index.js";

// ─── core/memory/l2 public surface ────────────────────────────────────────
export {
  runL2,
  attachL2Subscriber,
  createL2EventBus,
  signatureOf,
  parseSignature,
  componentsOf,
  bucketKeyOf,
  tracePolicySimilarity,
  valueWeightedMean,
  arithmeticMeanValue,
  centroid,
  induceDraft,
  buildPolicyRow,
  computeGain,
  nextStatus,
  applyGain,
  partition as partitionTraces,
  makeCandidatePool,
  candidateIdFor,
  signatureHash,
  type AssociationResult,
  type InductionResult,
  type InductionDraft,
  type InductionDraftResult,
  type GainResult,
  type GainInput,
  type L2Config,
  type L2Event,
  type L2EventBus,
  type L2EventKind,
  type L2EventListener,
  type L2ProcessInput,
  type L2ProcessResult,
  type L2SubscriberDeps,
  type L2SubscriberHandle,
  type PatternSignature,
  type SignatureComponents,
  type RunL2Deps,
  type InduceInput,
  type InduceDeps,
} from "./memory/l2/index.js";

// ─── core/memory/l3 public surface ────────────────────────────────────────
export {
  runL3,
  adjustConfidence as adjustWorldModelConfidence,
  attachL3Subscriber,
  createL3EventBus,
  abstractDraft,
  buildWorldModelRow,
  clusterPolicies,
  domainKeyOf,
  chooseMergeTarget,
  gatherMergeCandidates,
  mergeForUpdate,
  type AbstractionResult,
  type L3AbstractionDraft,
  type L3AbstractionDraftEntry,
  type L3AbstractionDraftResult,
  type L3Config,
  type L3Event,
  type L3EventBus,
  type L3EventKind,
  type L3EventListener,
  type L3ProcessInput,
  type L3ProcessResult,
  type L3SubscriberDeps,
  type L3SubscriberHandle,
  type PolicyCluster,
  type PolicyClusterKey,
  type MergeDecision as L3MergeDecision,
  type MergedPatch as L3MergedPatch,
  type RunL3Deps,
} from "./memory/l3/index.js";

// ─── core/skill public surface ─────────────────────────────────────────────
export {
  attachSkillSubscriber,
  applyFeedback as applySkillLifecycleFeedback,
  applySkillFeedback,
  buildSkillRow,
  createSkillEventBus,
  crystallizeDraft,
  defaultDraftValidator as defaultSkillDraftValidator,
  evaluateEligibility as evaluateSkillEligibility,
  gatherEvidence as gatherSkillEvidence,
  recomputeEta as recomputeSkillEta,
  runSkill,
  shouldArchiveIdle as shouldArchiveIdleSkill,
  verifyDraft as verifySkillDraft,
  type EligibilityDecision as SkillEligibilityDecision,
  type EligibilityInput as SkillEligibilityInput,
  type EligibilityResult as SkillEligibilityResult,
  type EvidenceDeps as SkillEvidenceDeps,
  type EvidenceResult as SkillEvidenceResult,
  type LifecycleUpdate as SkillLifecycleUpdate,
  type PackagerDeps as SkillPackagerDeps,
  type PackagerInput as SkillPackagerInput,
  type PackagerResult as SkillPackagerResult,
  type RunSkillDeps,
  type RunSkillInput,
  type RunSkillResult,
  type SkillCandidate as SkillCrystallizationCandidate,
  type SkillConfig,
  type SkillCrystallizationDraft,
  type SkillEvent,
  type SkillEventBus,
  type SkillEventKind,
  type SkillEventListener,
  type SkillExampleDraft,
  type SkillFeedbackKind,
  type SkillFeedbackSignal,
  type SkillLifecycleTransition,
  type SkillParameterDraft,
  type SkillProcedure,
  type SkillStepDraft,
  type SkillSubscriberDeps,
  type SkillSubscriberHandle,
  type SkillTrigger,
  type VerifyDeps as SkillVerifyDeps,
  type VerifyInput as SkillVerifyInput,
  type VerifyResult as SkillVerifyResult,
  type CrystallizeDeps as SkillCrystallizeDeps,
  type CrystallizeInput as SkillCrystallizeInput,
  type CrystallizeResult as SkillCrystallizeResult,
} from "./skill/index.js";

// ─── core/feedback public surface ──────────────────────────────────────────
export {
  attachFeedbackSubscriber,
  attachRepairToPolicies,
  classifyFeedback,
  contextHashOf,
  createFailureSignals,
  createFeedbackEventBus,
  gatherRepairEvidence,
  runRepair,
  synthesizeDraft,
  type ClassifiedFeedback,
  type DecisionRepairDraft,
  type FailureBurst,
  type FailureRecord,
  type FailureState,
  type FeedbackConfig,
  type FeedbackEvent,
  type FeedbackEventBus,
  type FeedbackEventKind,
  type FeedbackEventListener,
  type FeedbackSubscriberDeps,
  type FeedbackSubscriberHandle,
  type RecordToolCallInput,
  type RepairDeps,
  type RepairEvidenceResult,
  type RepairInput,
  type RepairResult,
  type RepairTrigger,
  type SubmitUserFeedbackInput,
  type SynthesizeDeps,
  type SynthesizeInput,
  type SynthesizeResult,
  type UserFeedbackShape,
} from "./feedback/index.js";

export type { Logger, LogRecord, LogLevel, LogKind, LogContext, LlmLogPayload } from "./logger/types.js";
export { LOG_LEVELS, LOG_LEVEL_ORDER, levelGte } from "./logger/levels.js";

// ─── core/pipeline public surface ──────────────────────────────────────────
export {
  createPipeline,
  createMemoryCore,
  bootstrapMemoryCore,
  bridgeToCoreEvents,
  wrapRetrievalRepos,
  extractAlgorithmConfig,
  buildPipelineBuses,
  buildPipelineSession,
  buildPipelineSubscribers,
  buildRetrievalDeps,
  pipelineLogger,
  type PipelineDeps,
  type PipelineHandle,
  type PipelineBuses,
  type PipelineAlgorithmConfig,
  type RecordToolOutcomeInput,
  type TurnEndResult,
  type BootstrapOptions,
  type CreateMemoryCoreOptions,
} from "./pipeline/index.js";
