// src/index.ts
// Omega Language - Public API
//
// Clean interface for VS Code extensions, CLI tools, and external integrations.

// ═══════════════════════════════════════════════════════════════════════════════
// CORE RUNTIME
// ═══════════════════════════════════════════════════════════════════════════════

export { OmegaRuntime, evalOmegaCode, type OmegaConfig, type EvalResult, type InferResult } from "./runtime";

// Outcomes and diagnostics
export {
  ok,
  err,
  failure,
  warn,
  info,
  error as diagnosticError,
  isOk,
  isErr,
  FAILURE_CODES,
  type Outcome,
  type Ok,
  type Err,
  type Failure,
  type FailureCode,
  type Diagnostic,
  type DiagnosticSpan,
  type DiagnosticPosition,
  type DiagnosticSeverity,
} from "./core/outcome";

// ═══════════════════════════════════════════════════════════════════════════════
// FRAME IR PACKAGE
// ═══════════════════════════════════════════════════════════════════════════════

export {
  canonicalJson,
  merkleHash,
  merkleize,
  type FrameValue,
  type FlowIR,
  type FlowStepIR,
  type MerkleArrayNode,
  type MerkleNode,
  type MerkleObjectEntry,
  type MerkleObjectNode,
  type MerkleValueNode,
  type MessageIR,
  type PromptIR,
  type ScalarIR,
  type ValueIR,
} from "./frameir";

// ═══════════════════════════════════════════════════════════════════════════════
// VALUES & TYPES
// ═══════════════════════════════════════════════════════════════════════════════

export type { Val } from "./core/eval/values";
export type { Expr } from "./core/ast";
export type { DistVal, DistItem } from "./core/eval/dist";
export { dist, distNormalize, distSample, distTopK, distFrom, isDist } from "./core/eval/dist";

// ═══════════════════════════════════════════════════════════════════════════════
// ORACLE PROTOCOL
// ═══════════════════════════════════════════════════════════════════════════════

export type { OracleReq, OracleResp, Meaning, QExpr } from "../packages/oracle/core/src/protocol";
export type { OracleAdapter, OracleInit } from "../packages/oracle/core/src/adapter";
export type { MeaningVal } from "./core/meaning";
export { meaning, isMeaning } from "./core/meaning";
export { matchAST } from "../packages/oracle/core/src/match";

// ═══════════════════════════════════════════════════════════════════════════════
// ADAPTERS (LLM Backends)
// ═══════════════════════════════════════════════════════════════════════════════

export type { LLMConfig, AdapterCaps, ToolDef, OracleAdapterWithCaps } from "../packages/oracle/core/src/adapters/types";
export { DepthTrackingAdapter, TracingAdapter } from "../packages/oracle/core/src/adapters/types";
// Vendor-specific adapters removed in JOB-06. Use @omega/driver-* via DriverRegistry.
export { MCPClientAdapter, OmegaMCPServer, BidirectionalMCPAdapter } from "../packages/oracle/core/src/adapters/mcpAdapter";
export { PiAiAdapter, createPiAiFromEnv } from "../packages/oracle/piai/src/piai";
export type { PiAiConfig } from "../packages/oracle/piai/src/piai";
export { nativeToolOracle, warmUpOracle, type NativeToolDef, type OracleCallbacks } from "../packages/oracle/piai/src/nativeToolOracle";

// ═══════════════════════════════════════════════════════════════════════════════
// GOVERNANCE
// ═══════════════════════════════════════════════════════════════════════════════

export type { Cap, CapSet } from "./core/governance/caps";
export { capHas, capRequire, DEFAULT_CAPS, FULL_CAPS } from "./core/governance/caps";
export type { BudgetLimits, Budget } from "./core/governance/budgets";
export { budgetDefault, budgetRemaining, budgetConsumeOracleTurn, budgetConsumeEvalStep, budgetConsumeToolCall } from "./core/governance/budgets";
export type { Profile, TruthRegime } from "./core/governance/profile";
export { PROFILE_SPECULATIVE, PROFILE_TEST_CERTIFIED, PROFILE_PROOF_CERTIFIED, DEFAULT_PROFILE } from "./core/governance/profile";

// ═══════════════════════════════════════════════════════════════════════════════
// CONTEXT (Env = Ctx)
// ═══════════════════════════════════════════════════════════════════════════════

export type { Ctx, Constraint, Evidence } from "./core/ctx/ctx";
export {
  ctxDefine,
  ctxLookup,
  ctxExtend,
  ctxSeal,
  ctxAddEvidence,
  ctxApplyProfile,
  ctxRootFromProfile,
  ctxProject,
  isCtx,
} from "./core/ctx/ctx";

// ═══════════════════════════════════════════════════════════════════════════════
// CONTEXT RECEIPTS (Snapshot/Compress/Hydrate)
// ═══════════════════════════════════════════════════════════════════════════════

export type { CtxReceipt } from "../packages/oracle/core/src/ctxReceipts";
export { CtxReceiptRepo } from "../packages/oracle/core/src/ctxReceipts";

// ═══════════════════════════════════════════════════════════════════════════════
// PROVENANCE
// ═══════════════════════════════════════════════════════════════════════════════

export { ProvenanceGraph } from "./core/provenance/graph";
export type { ProvenanceGraphData, StalenessReport, StaleItem, SourceChecker } from "./core/provenance/graph";
export { evidenceId, computeSourceHash } from "./core/provenance/evidence";
export { FileProvenanceStore } from "./core/provenance/store/file";
export type { ProvenanceStore, StoredReceipt, ReceiptFilter } from "./core/provenance/store/interface";

// ═══════════════════════════════════════════════════════════════════════════════
// FRAMEIR (Canonical IR)
// ═══════════════════════════════════════════════════════════════════════════════

export * from "./frameir";
export * from "./outcome";

// ═══════════════════════════════════════════════════════════════════════════════
// REGISTRY (Primitive descriptors)
// ═══════════════════════════════════════════════════════════════════════════════

export * from "./registry";

// ═══════════════════════════════════════════════════════════════════════════════
// CLI TOOLS - CEKS Machine (Low-Level Debugging Support)
// ═══════════════════════════════════════════════════════════════════════════════

// Store (Copy-on-Write memory)
export { COWStore, type Store } from "./core/eval/store";

// Single-step execution (for debugger)
export { stepOnce, type StepResult } from "./core/eval/machineStep";

// Run to completion (for REPL)
export { runToCompletionWithState, runToCompletion } from "./core/eval/run";

// Machine state types
export type { State, Frame } from "./core/eval/machine";

// Environment type
export type { Env } from "./core/eval/env";

// Compilation (text -> AST)
export { compileTextToExpr } from "./core/pipeline/compileText";

// Effects runtime (for handling oracle calls)
export { RuntimeImpl } from "./core/effects/runtimeImpl";
export type { EffectBackend } from "./core/effects/backend";
export type { OpCall, Resumption } from "./core/effects/opcall";

// Oracle state management
export { SnapshotRepo } from "../packages/oracle/core/src/snapshots";
export { InMemoryReceiptStore, type ReceiptStore } from "../packages/oracle/core/src/receipts";

// Vendor adapters removed in JOB-06. Use @omega/driver-* via DriverRegistry.

// Primitive installation (for initializing REPL environment)
export { installPrims } from "./core/prims";

// Session management
export {
  SessionWriter,
  SessionReader,
  JumpController,
  serializeState,
  deserializeState,
  renderEvent,
  renderTrace,
} from "./core/session";
export type { SessionEvent, SessionIndex, LLMReceipt } from "./core/session";

// Help system (progressive discovery for agents)
export {
  loadPackageDocs,
  handlePackagesCommand,
  handleDocCommand,
  handleAproposCommand,
  handleHelpPackageCommand,
  handleManCommand,
  getPackages,
  getPrimitive,
  searchPrimitives,
} from "./core/help";

// REPL engine (shared by CLI and daemon)
export {
  OmegaRepl,
  extractDefName,
  normalizeCtxBindings,
  type IReplExecutor,
  type ReplCoreState,
  type SerializedReplState,
  type ReplEvalOpts,
  type ReplEvalResult,
} from "./core/repl";
