// v2.8.0: Dynamic Workflow Engine — public surface.
//
// ## Status: experimental / intentionally decoupled from the coder flow-runner
//
// This module is an in-process multi-agent orchestrator that creates BooChat
// sessions+chats and dispatches inference via the native `runInference`
// pipeline. It is NOT currently wired into the server (`apps/server/src/index.ts`)
// — no routes import it, no service initialises it, and the server has no
// `projectRoot`/`projectId` concept at startup. All code is preserved for future
// evaluation but is not in use.
//
// ## Relationship to the coder flow-runner
//
// The canonical orchestrator implementation lives at:
//   `apps/coder/src/services/flow-runner.ts` (1102 lines, actively wired)
//
// The two modules serve different dispatch strategies:
//
//   | Dimension         | Server WorkflowManager (this)     | Coder flow-runner                  |
//   |-------------------|-----------------------------------|------------------------------------|
//   | Dispatch          | In-process via `runInference`     | Task rows → external agent binary  |
//   | Agent target      | BooChat native inference          | qwen via PTY (--approval-mode plan)|
//   | Session model     | Per-agent BooChat sessions+chats  | Per-step synthetic sessions        |
//   | Persistence       | In-memory (Map<runId, state>)     | DB-backed (flow_runs/flow_steps)   |
//   | Lifecycle         | Polling loop + AbortController    | Dispatcher hook (onTaskTerminal)   |
//   | Status            | Experimental, not wired           | Active, production                 |
//
// These two engines are NOT competitors — they are alternative approaches for
// different dispatch surfaces. Use the coder flow-runner for the current
// orchestrator; revisit this module if in-process BooChat-native multi-agent
// orchestration becomes a requirement.
//
// Re-exports all types and classes from the workflow sub-modules so consumers
// import from a single entry point:
//
// ```typescript
// import { WorkflowManager } from './services/workflow/index.js';
// ```

export { WorkflowManager } from './manager.js';
export type { WorkflowMetaInfo } from './manager.js';
export type { WorkflowEventHandler } from './manager.js';

export { discoverWorkflows, findWorkflow, isValidWorkflowPath, isBuiltinWorkflow } from './discovery.js';
export type { WorkflowMeta } from './discovery.js';

export {
  loadWorkflowScript,
  loadWorkflowScriptFromCode,
  executeWorkflowScript,
  executeWorkflowScriptFromCode,
  buildSandbox,
  transformEsmToCjs,
  isEsmSyntax,
} from './sandbox.js';

export {
  getBuiltinWorkflows,
  getBuiltinWorkflow,
  mergeBuiltinWorkflows,
  fingerprintAgentTask,
} from './catalog.js';
export type { BuiltinWorkflow } from './catalog.js';

export {
  cacheKey,
  getCachedResult,
  setCachedResult,
  invalidateRun,
  clearCache,
  cacheSize,
} from './resumability.js';
export type { CachedResult } from './resumability.js';

export type {
  WorkflowScript,
  WorkflowScriptMeta,
  WorkflowContext,
  AgentTaskSpec,
  AgentTaskResult,
  WorkflowRun,
  WorkflowRunStatus,
  WorkflowEvent,
} from './types.js';
