/**
 * idl/index.mjs — framework-side re-export of the IDL v1 runtime registry.
 *
 * Single source of truth lives at packages/framework/src/driver-sdk/idl.ts
 * (inlined in 0.8.5 — originally `@aperant/driver-sdk`). This file
 * re-exports those runtime values so existing callers (bundled drivers,
 * resolver, driver-doctor, conformance kit) keep working without a
 * refactor of every callsite.
 *
 * If you add a verb, edit packages/framework/src/driver-sdk/idl.ts.
 *
 * Defense-in-depth (issue #248). `@aperant/framework/driver-sdk` resolves
 * via the package `exports` map to `dist/driver-sdk/index.js`. A *static*
 * `export … from '@aperant/framework/driver-sdk'` here made this barrel —
 * and therefore the whole apt-tools CLI, since `dispatch.mjs` eagerly
 * imports `driver-doctor.mjs` which imports this barrel — crash at
 * module-resolution time with an opaque `ERR_MODULE_NOT_FOUND` when the
 * dist was not built (e.g. a CI step that skipped `pnpm build`), before
 * any command body could run. Resolving the registry via a *dynamic*
 * `await import()` wrapped in try/catch keeps that dependency off the
 * hard module-link path: dist present (tests, post-build CI, published
 * tarball) → the REAL registry values are re-exported unchanged; dist
 * absent → empty/no-op fallbacks let the CLI load (so commands that don't
 * touch the IDL registry, like `route`, still run) instead of crashing.
 */

/** @type {typeof import('@aperant/framework/driver-sdk')} */
let _sdk
try {
	_sdk = await import('@aperant/framework/driver-sdk')
} catch (err) {
	// Only the intended "dist not built" condition degrades. A corrupt or
	// partially-written dist (SyntaxError, broken transitive load) raises a
	// different code and MUST surface, not be masked into an empty registry.
	if (err?.code !== 'ERR_MODULE_NOT_FOUND') throw err
	// dist/driver-sdk absent — degrade to empty registry so module load
	// does not crash. Any code path that actually needs a verb registry
	// (driver-doctor, the bundled drivers) requires a built dist anyway;
	// commands that don't (e.g. `route`) keep working.
	_sdk = {
		ASSERTION_VERBS: [],
		ASYNC_VERBS: [],
		EVIDENCE_VERBS: [],
		IDL_VERB_ARGS: {},
		IDL_VERB_NAMES: [],
		INTERACTION_VERBS: [],
		isVerbResult: () => false,
		LIFECYCLE_VERBS: [],
		validateVerbArgs: () => ({ ok: true, errors: [] }),
	}
}

export const ASSERTION_VERBS = _sdk.ASSERTION_VERBS
export const ASYNC_VERBS = _sdk.ASYNC_VERBS
export const EVIDENCE_VERBS = _sdk.EVIDENCE_VERBS
export const IDL_VERB_ARGS = _sdk.IDL_VERB_ARGS
export const IDL_VERB_NAMES = _sdk.IDL_VERB_NAMES
export const INTERACTION_VERBS = _sdk.INTERACTION_VERBS
export const isVerbResult = _sdk.isVerbResult
export const LIFECYCLE_VERBS = _sdk.LIFECYCLE_VERBS
export const validateVerbArgs = _sdk.validateVerbArgs
