/**
 * @harness-engineering/orchestrator
 *
 * Orchestrator daemon for dispatching coding agents to issues.
 *
 * This package provides the core logic for the Harness Orchestrator,
 * including state management, issue tracker adapters, agent runners,
 * and a management server.
 */

export * from './types/index';
export * from './core/index';
export * from './workflow/loader';
export * from './workflow/config';
export * from './tracker/adapters/roadmap';
export * from './tracker/extensions/linear';
export * from './workspace/manager';
export * from './workspace/hooks';
// Backend implementations are internal — use Orchestrator's factory methods instead.
// Re-exporting only the mock backend for test consumers.
export * from './agent/backends/mock';
export * from './prompt/renderer';
export * from './orchestrator';
export * from './tui/launcher';
// Spec 2 Phase 3 / Task 14: re-export the multi-backend-routing surface
// so external consumers (CLI commands, tests, dashboards) can construct
// routers, factories, and migration helpers without reaching into
// internal paths.
export { BackendRouter } from './agent/backend-router';
export type { BackendRouterOptions } from './agent/backend-router';
export { OrchestratorBackendFactory } from './agent/orchestrator-backend-factory';
export type { OrchestratorBackendFactoryOptions } from './agent/orchestrator-backend-factory';
export { migrateAgentConfig } from './agent/config-migration';
export type { MigrationResult } from './agent/config-migration';
export { createBackend } from './agent/backend-factory';

// Phase 1 sync-main helper public surface. Wired into the maintenance
// scheduler in Phase 2; exported here so the CLI can wrap it directly.
export { syncMain } from './maintenance/sync-main';
export type { SyncMainResult, SyncMainOptions, SyncSkipReason } from './maintenance/sync-main';

// Hermes Phase 2 — public surface for the maintenance CLI subcommand
// (`harness maintenance list/show`). The CLI consumes these directly so it
// can read built-in + custom task definitions and the per-task output store
// without booting a full orchestrator instance.
export { BUILT_IN_TASKS } from './maintenance/task-registry';
export { TaskOutputStore } from './maintenance/output-store';
export type { PersistedOutputEntry } from './maintenance/output-store';
export { validateCustomTasks } from './maintenance/custom-task-validator';
export type { CustomTaskValidationError } from './maintenance/custom-task-validator';
export type { TaskDefinition, TaskType, RunOrigin } from './maintenance/types';

// Hermes Phase 0 / Phase 1: re-export TokenStore so the CLI (`harness gateway token`)
// and the dashboard tokens router can construct it via the package root without
// reaching into the `./auth` subpath (decision phase1-d4).
export { TokenStore } from './auth';
export type { CreateTokenInput, CreateTokenResult } from './auth';

// Hermes Phase 0 / Phase 4: expose WebhookQueue so the CLI (`harness gateway
// deliveries`) can open the SQLite file directly without depending on the
// orchestrator being running. MAX_ATTEMPTS is re-exported so test fixtures
// can drive markFailed past the dead-letter threshold without re-deriving
// the constant.
export { WebhookQueue, MAX_ATTEMPTS, RETRY_DELAYS_MS } from './gateway/webhooks/queue';
export type { QueueStats, QueueRow, QueueInsertInput } from './gateway/webhooks/queue';

// Session search + summarization + archive hooks.
export {
  SqliteSearchIndex,
  openSearchIndex,
  searchIndexPath,
  normalizeFts5Query,
  indexSessionDirectory,
  reindexFromArchive,
} from './sessions/search-index';
export type { IndexedDoc, SearchOptions } from './sessions/search-index';

export {
  summarizeArchivedSession,
  renderLlmSummaryMarkdown,
  truncateForBudget,
  isSummaryEnabled,
} from './sessions/summarize';
export type { SummarizeContext, SummarizeResult } from './sessions/summarize';

export { buildArchiveHooks } from './sessions/archive-hooks';
export type { BuildArchiveHooksOptions } from './sessions/archive-hooks';

// Notification sinks (envelope wrapper, Slack adapter, in-process dispatcher).
// The CLI's `harness notifications test` and the integration tests reach for
// these directly; everything else is wired by the orchestrator boot.
export {
  wrapAsEnvelope,
  SlackSink,
  SinkRegistry,
  SinkConfigError,
  wireNotificationSinks,
} from './notifications';
export type {
  NotificationSink,
  NotificationSinkDeliverInput,
  RegistryEntry,
  FromConfigOptions,
  SlackSinkOptions,
} from './notifications';

// Phase 4 skill-proposal pipeline (gate + promote + lifecycle emitters).
// The HTTP routes wire these into the v1 bridge; CLI and tests reach for
// them via this barrel.
export {
  runGate,
  promote,
  GateRunError,
  GateNotReadyError,
  PromotionError,
  emitProposalCreated,
  emitProposalApproved,
  emitProposalRejected,
} from './proposals';
export type {
  GateResult,
  PromotionResult,
  ProposalCreatedData,
  ProposalApprovedData,
  ProposalRejectedData,
} from './proposals';
