/** Typed error code from the closed MACP_ERROR_CODES set. */
export type MacpErrorCode = (typeof MACP_ERROR_CODES)[number];
/**
 * Typed fail-closed capability errors (RI-N2, SDLC-D-035).
 *
 * MACP must fail closed when a required capability (executor, reviewer,
 * command, CI provider, human authority) is absent. These typed codes mirror
 * the Forge failure vocabulary (FORGE_NO_*) so both packages speak the same
 * language: an unimplemented capability is a failure, never a stub success.
 */

/** Closed set of typed MACP capability error codes. */
export const MACP_ERROR_CODES = [
  'MACP_NOT_IMPLEMENTED',
  'MACP_NO_COMMAND',
  'MACP_NO_REVIEWER',
  'MACP_NO_CI_PIPELINE',
  'MACP_NO_PROVIDER',
  'MACP_AUTHORITY_REQUIRED',
] as const;

/** Raised when a required capability is missing and execution must fail closed. */
export class MACPCapabilityError extends Error {
  /** Typed error code from the closed MACP_ERROR_CODES set. */
  readonly code: MacpErrorCode;
  /** The missing capability, e.g. `ci-provider`, `task-persistence`, `command`. */
  readonly capability: string;

  constructor(code: MacpErrorCode, capability: string, message: string) {
    super(message);
    this.name = 'MACPCapabilityError';
    this.code = code;
    this.capability = capability;
  }
}
