// GENERATED by `harn dump-protocol-artifacts` - do not edit by hand.
// Source: Harn adapter schemas and Rust wire vocabulary.

export const HARN_PROTOCOL_ARTIFACT_VERSION = "0.8.104"

export const MCP_PROTOCOL_VERSION = "2025-11-25"
export const MCP_STABLE_PROTOCOL_VERSION = "2025-11-25"
export const MCP_DRAFT_PROTOCOL_VERSION = "DRAFT-2026-v1"
export const MCP_FINAL_2026_PROTOCOL_VERSION = "2026-07-28"
export const MCP_JSON_SCHEMA_2020_12_DIALECT = "https://json-schema.org/draft/2020-12/schema"
export const MCP_UNSUPPORTED_PROTOCOL_VERSION_ERROR = { code: -32004, message: "Unsupported protocol version" } as const

export const ACP_AGENT_METHODS = [
  "initialize",
  "session/inject",
  "session/new",
  "session/load",
  "session/replace_inject",
  "session/resume",
  "session/prompt",
  "session/revoke_inject",
  "session/truncate",
  "session/rollback",
  "session/redo",
  "session/remind",
  "session/pending_injections",
  "session/revoke_reminder",
  "session/cancel_tool_call",
  "session/close",
  "session/stop",
] as const
export type ACPAgentMethod = (typeof ACP_AGENT_METHODS)[number]

export const ACP_AGENT_METHOD = {
  initialize: "initialize",
  sessionInject: "session/inject",
  sessionNew: "session/new",
  sessionLoad: "session/load",
  sessionReplaceInject: "session/replace_inject",
  sessionResume: "session/resume",
  sessionPrompt: "session/prompt",
  sessionRevokeInject: "session/revoke_inject",
  sessionTruncate: "session/truncate",
  sessionRollback: "session/rollback",
  sessionRedo: "session/redo",
  sessionRemind: "session/remind",
  sessionPendingInjections: "session/pending_injections",
  sessionRevokeReminder: "session/revoke_reminder",
  sessionCancelToolCall: "session/cancel_tool_call",
  sessionClose: "session/close",
  /** @deprecated Use session/close; session/stop will be removed after one release. */
  sessionStop: "session/stop",
} as const

export const ACP_CLIENT_METHODS = [
  "fs/read_text_file",
  "fs/write_text_file",
  "terminal/create",
  "terminal/kill",
  "session/request_permission",
] as const
export type ACPClientMethod = (typeof ACP_CLIENT_METHODS)[number]

export const ACP_AGENT_NOTIFICATIONS = [
  "session/message",
  "session/update",
  "terminal/output",
] as const
export type ACPAgentNotification = (typeof ACP_AGENT_NOTIFICATIONS)[number]

export const ACP_SESSION_UPDATES = [
  "user_message",
  "user_message_chunk",
  "agent_message_chunk",
  "agent_thought_chunk",
  "tool_call",
  "tool_call_update",
  "plan",
  "available_commands_update",
  "current_mode_update",
  "config_option_update",
  "session_info_update",
  "session_redo",
  "session_rollback",
  "session_truncated",
  "artifact",
  "fs_watch",
  "handoff",
  "hitl_request",
  "hitl_resolved",
  "log",
  "progress",
  "reminder_emitted",
  "skill_activated",
  "skill_deactivated",
  "skill_narrow",
  "skill_scope_tools",
  "tool_search_query",
  "tool_search_result",
  "transcript_compacted",
  "transcript_projected",
  "worker_update",
] as const
export type ACPSessionUpdate = (typeof ACP_SESSION_UPDATES)[number]

export const HARN_ACP_SESSION_UPDATE_EXTENSIONS = [
  "artifact",
  "available_commands_update",
  "fs_watch",
  "handoff",
  "hitl_request",
  "hitl_resolved",
  "log",
  "progress",
  "reminder_emitted",
  "skill_activated",
  "skill_deactivated",
  "skill_narrow",
  "skill_scope_tools",
  "tool_search_query",
  "tool_search_result",
  "transcript_compacted",
  "transcript_projected",
  "worker_update",
] as const
export type HarnACPSessionUpdateExtension = (typeof HARN_ACP_SESSION_UPDATE_EXTENSIONS)[number]

export const HARN_AGENT_EVENT_METHOD = "_harn/agentEvent"
export const HARN_PROVIDER_CATALOG_METHOD = "_harn/providerCatalog"
export const HARN_AGENT_EVENT_KINDS = [
  "budget_circuit_breaker",
  "budget_exhausted",
  "composition_child_call",
  "composition_child_result",
  "composition_error",
  "composition_finish",
  "composition_start",
  "compass_routing_decision",
  "control_outcome",
  "daemon_watchdog_tripped",
  "feedback_injected",
  "iteration_end",
  "iteration_start",
  "judge_decision",
  "loop_control_decision",
  "loop_stuck",
  "mcp_auth_required",
  "mcp_catalog_changed",
  "mcp_notification",
  "progress_reported",
  "scope_classifier_verdict",
  "session_closed",
  "structural_validator_decision",
  "step_judge_decision",
  "tool_call_audit",
  "tool_format_override",
  "typed_checkpoint",
] as const
export type HarnAgentEventKind = (typeof HARN_AGENT_EVENT_KINDS)[number]

export const ACP_CONTENT_BLOCK_TYPES = [
  "text",
  "resource_link",
  "resource",
  "image",
  "audio",
] as const
export type ACPContentBlockType = (typeof ACP_CONTENT_BLOCK_TYPES)[number]

export const ACP_TOOL_KINDS = [
  "read",
  "edit",
  "delete",
  "move",
  "search",
  "execute",
  "think",
  "fetch",
  "other",
] as const
export type ACPToolKind = (typeof ACP_TOOL_KINDS)[number]

export const ACP_TOOL_CALL_STATUSES = [
  "pending",
  "in_progress",
  "completed",
  "failed",
] as const
export type ACPToolCallStatus = (typeof ACP_TOOL_CALL_STATUSES)[number]

export const HARN_TOOL_CALL_ERROR_CATEGORIES = [
  "schema_validation",
  "tool_error",
  "mcp_server_error",
  "host_bridge_error",
  "permission_denied",
  "rejected_loop",
  "parse_aborted",
  "timeout",
  "network",
  "cancelled",
  "unknown",
] as const
export type HarnToolCallErrorCategory = (typeof HARN_TOOL_CALL_ERROR_CATEGORIES)[number]

export const HARN_SIDE_EFFECT_LEVELS = [
  "none",
  "read_only",
  "workspace_write",
  "process_exec",
  "network",
] as const
export type HarnSideEffectLevel = (typeof HARN_SIDE_EFFECT_LEVELS)[number]

export const HARN_WORKER_STATUSES = [
  "running",
  "progressed",
  "awaiting_input",
  "suspended",
  "completed",
  "failed",
  "stopped",
  "cancelled",
] as const
export type HarnWorkerStatus = (typeof HARN_WORKER_STATUSES)[number]

export const HARN_TOOL_CALL_RECEIPT_STATUSES = [
  "ok",
  "schema_violation",
  "consent_denied",
  "timeout",
  "error",
] as const
export type HarnToolCallReceiptStatus = (typeof HARN_TOOL_CALL_RECEIPT_STATUSES)[number]

export const HARN_TOOL_CALL_RECEIPT_EXECUTORS = [
  "harn",
  "host_bridge",
  "mcp_server",
  "provider_native",
] as const
export type HarnToolCallReceiptExecutor = (typeof HARN_TOOL_CALL_RECEIPT_EXECUTORS)[number]

export const A2A_TASK_STATES = [
  "submitted",
  "working",
  "completed",
  "failed",
  "canceled",
  "cancelled",
  "input-required",
  "rejected",
  "auth-required",
] as const
export type A2ATaskState = (typeof A2A_TASK_STATES)[number]

export const A2A_TASK_EVENT_TYPES = [
  "status",
  "message",
  "worker_update",
] as const
export type A2ATaskEventType = (typeof A2A_TASK_EVENT_TYPES)[number]

export const MCP_PROTOCOL_VERSIONS = [
  "DRAFT-2026-v1",
  "2025-11-25",
] as const
export type MCPProtocolVersion = (typeof MCP_PROTOCOL_VERSIONS)[number]

export const MCP_METHODS = [
  "server/discover",
  "initialize",
  "tools/list",
  "tools/call",
  "resources/list",
  "resources/read",
  "resources/templates/list",
  "prompts/list",
  "prompts/get",
  "completion/complete",
  "logging/setLevel",
  "sampling/createMessage",
  "elicitation/create",
  "notifications/initialized",
  "notifications/message",
] as const
export type MCPMethod = (typeof MCP_METHODS)[number]

export const MCP_REQUIRED_METADATA_KEYS = [
  "io.modelcontextprotocol/protocolVersion",
  "io.modelcontextprotocol/clientInfo",
  "io.modelcontextprotocol/clientCapabilities",
] as const
export type MCPRequiredMetadataKey = (typeof MCP_REQUIRED_METADATA_KEYS)[number]

export const MCP_METADATA_KEYS = [
  "io.modelcontextprotocol/protocolVersion",
  "io.modelcontextprotocol/clientInfo",
  "io.modelcontextprotocol/clientCapabilities",
  "io.modelcontextprotocol/logLevel",
  "progressToken",
  "traceparent",
  "tracestate",
  "baggage",
] as const
export type MCPMetadataKey = (typeof MCP_METADATA_KEYS)[number]

export const MCP_STANDARD_HTTP_HEADERS = [
  "MCP-Protocol-Version",
  "Mcp-Method",
  "Mcp-Name",
] as const
export type MCPStandardHTTPHeader = (typeof MCP_STANDARD_HTTP_HEADERS)[number]

export const MCP_CACHE_RESULT_FIELDS = [
  "ttlMs",
  "cacheScope",
] as const
export type MCPCacheResultField = (typeof MCP_CACHE_RESULT_FIELDS)[number]

export const MCP_CACHE_SCOPES = [
  "private",
  "public",
] as const
export type MCPCacheScope = (typeof MCP_CACHE_SCOPES)[number]

export const MCP_RESULT_TYPES = [
  "complete",
  "input_required",
] as const
export type MCPResultType = (typeof MCP_RESULT_TYPES)[number]

export const MCP_LOGGING_LEVELS = [
  "debug",
  "info",
  "notice",
  "warning",
  "error",
  "critical",
  "alert",
  "emergency",
] as const
export type MCPLoggingLevel = (typeof MCP_LOGGING_LEVELS)[number]

export const MCP_OAUTH_CLIENT_REGISTRATION_MODES = [
  "pre_registered",
  "client_id_metadata_document",
  "dynamic_client_registration",
  "manual",
] as const
export type MCPOAuthClientRegistrationMode = (typeof MCP_OAUTH_CLIENT_REGISTRATION_MODES)[number]

export const MCP_OAUTH_AUTH_MODES = [
  "cimd",
  "dcr",
  "static",
  "byo",
] as const
export type MCPOAuthAuthMode = (typeof MCP_OAUTH_AUTH_MODES)[number]

export const MCP_OAUTH_APPLICATION_TYPES = [
  "native",
  "web",
] as const
export type MCPOAuthApplicationType = (typeof MCP_OAUTH_APPLICATION_TYPES)[number]


export type ACPObject = { [key: string]: ACPValue }
export type ACPValue = null | boolean | number | string | ACPValue[] | ACPObject
export type JsonRpcId = number | string | null

export interface ACPRequest {
  jsonrpc: "2.0"
  id: Exclude<JsonRpcId, null>
  method: string
  params?: ACPValue
}

export interface ACPResponse {
  jsonrpc: "2.0"
  id: JsonRpcId
  result?: ACPValue
  error?: ACPError
}

export interface ACPError {
  code: number
  message: string
  data?: ACPValue
}

export interface ACPNotification {
  jsonrpc: "2.0"
  method: string
  params?: ACPValue
}

export type ACPMessage = ACPRequest | ACPResponse | ACPNotification

export interface ACPExtensionMeta<T extends object = ACPObject> {
  harn?: T
}

export interface ACPContentBlock {
  type: "text" | "resource_link" | "resource" | "image" | "audio" | string
  text?: string
  _meta?: ACPExtensionMeta<ACPObject>
}

export type ACPToolExecutor =
  | "harn_builtin"
  | "host_bridge"
  | "provider_native"
  | { kind: "mcp_server"; serverName: string }

export interface HarnToolLifecycleMeta {
  audit?: ACPValue
  durationMs?: number
  error?: string
  errorCategory?: HarnToolCallErrorCategory
  executionDurationMs?: number
  executor?: ACPToolExecutor
  parsing?: boolean
  rawInputPartial?: string
}

export interface ToolCallReceipt {
  schema_version: number
  session_id: string
  run_id: string | null
  tool_call_id: string
  tool_name: string
  iteration: number
  turn_index: number | null
  emit_order: number
  reason: string | null
  kind: string | null
  executor: HarnToolCallReceiptExecutor | null
  status: HarnToolCallReceiptStatus
  error_category: string | null
  duration_ms: number
  args_hash: string
  result_hash: string | null
  audit: ACPValue
  emitted_at: string
  model: string | null
  provider: string | null
}

export interface ACPToolCall {
  sessionUpdate: "tool_call"
  toolCallId: string
  title: string
  kind?: ACPToolKind
  status?: ACPToolCallStatus
  content?: ACPContentBlock[]
  locations?: ACPValue[]
  rawInput?: ACPValue
  rawOutput?: ACPValue
  _meta?: ACPExtensionMeta<HarnToolLifecycleMeta>
}

export interface ACPToolCallUpdate {
  sessionUpdate: "tool_call_update"
  toolCallId: string
  title?: string | null
  kind?: ACPToolKind
  status?: ACPToolCallStatus | null
  content?: ACPContentBlock[]
  locations?: ACPValue[]
  rawInput?: ACPValue
  rawOutput?: ACPValue
  _meta?: ACPExtensionMeta<HarnToolLifecycleMeta>
}

export interface ACPMessageChunkUpdate {
  sessionUpdate: "agent_message_chunk" | "agent_thought_chunk" | "user_message_chunk"
  content: ACPContentBlock
}

export interface ACPUserMessageUpdate {
  sessionUpdate: "user_message"
  messageId: string
  content: ACPContentBlock[]
}

export interface ACPPlanUpdate {
  sessionUpdate: "plan"
  entries: ACPValue[]
  harnPlan?: ACPValue
}

export interface ACPSessionTruncatedUpdate {
  sessionUpdate: "session_truncated"
  keptTurnCount: number
  removedTurnCount: number
  newTipTurnId?: string | null
  reason?: string
}

export interface ACPHarnExtensionUpdate {
  sessionUpdate: HarnACPSessionUpdateExtension
  _meta?: ACPExtensionMeta<ACPObject>
}

export type ACPSessionUpdateEnvelope =
  | ACPUserMessageUpdate
  | ACPMessageChunkUpdate
  | ACPToolCall
  | ACPToolCallUpdate
  | ACPPlanUpdate
  | ACPSessionTruncatedUpdate
  | ACPHarnExtensionUpdate

export interface ACPSessionUpdateParams {
  sessionId: string
  update: ACPSessionUpdateEnvelope
}

export interface ACPSessionUpdateNotification {
  jsonrpc: "2.0"
  method: "session/update"
  params: ACPSessionUpdateParams
}

export interface HarnAgentEventNotification {
  jsonrpc: "2.0"
  method: typeof HARN_AGENT_EVENT_METHOD
  params: ACPObject & {
    sessionId: string
    kind: HarnAgentEventKind
  }
}

export interface ACPPermissionToolCall {
  sessionUpdate?: "tool_call_update"
  toolCallId: string
  title?: string
  kind?: string
  rawInput?: ACPValue
  _meta?: ACPExtensionMeta<ACPObject>
}

export type ACPPermissionOptionKind =
  | "allow_once"
  | "allow_always"
  | "reject_once"
  | "reject_always"

export interface ACPPermissionOption {
  optionId: string
  name: string
  kind: ACPPermissionOptionKind
}

export interface ACPSessionRequestPermissionParams {
  sessionId: string
  toolCall: ACPPermissionToolCall
  options: ACPPermissionOption[]
}

export type ACPPermissionOutcome =
  | { outcome: "selected"; optionId: string }
  | { outcome: "cancelled" }

export interface ACPSessionRequestPermissionResult {
  outcome: ACPPermissionOutcome
  reason?: string
}

export interface ACPPromptCapabilities {
  image?: boolean
  audio?: boolean
  embeddedContext?: boolean
}

export interface ACPAgentCapabilities {
  _meta?: ACPExtensionMeta<{
    schemaCompatibility?: string
    sessionUpdateExtensions?: HarnACPSessionUpdateExtension[]
    toolLifecycleExtensionFields?: string[]
    contentExtensionFields?: string[]
    extensionMethods?: Record<string, ACPObject>
    hostCapabilityOperations?: Record<string, string[]>
    extensionContract?: string
  }>
  loadSession?: boolean
  session?: ACPObject
  promptCapabilities?: ACPPromptCapabilities
  mcpCapabilities?: ACPObject
  sessionCapabilities?: ACPObject
}

export interface ACPClientCapabilities {
  fs?: {
    readTextFile?: boolean
    writeTextFile?: boolean
  }
  terminal?: {
    create?: boolean
  }
}

export interface HarnToolArgSchema {
  path_params: string[]
  arg_aliases: Record<string, string>
  required: string[]
}

export interface HarnToolAnnotations {
  kind: ACPToolKind
  side_effect_level: HarnSideEffectLevel
  arg_schema: HarnToolArgSchema
  capabilities: Record<string, string[]>
  emits_artifacts: boolean
  result_readers: string[]
  inline_result: boolean
}

export interface A2ATaskStatus {
  state: A2ATaskState
  message?: A2AMessage
  timestamp?: string
}

export interface A2ATask {
  id: string
  contextId?: string | null
  status: A2ATaskStatus
  history?: A2AMessage[]
  artifacts?: ACPValue[]
  metadata?: ACPObject
}

export interface A2AMessage {
  id: string
  role: "user" | "agent"
  parts: ACPValue[]
}

export type A2ATaskEvent =
  | { type: "status"; taskId: string; status: A2ATaskStatus }
  | { type: "message" | "worker_update"; taskId: string; message?: A2AMessage }
  | { statusUpdate: { taskId: string; contextId?: string | null; status: A2ATaskStatus } }

export type MCPJsonSchema202012 = ACPObject

export interface MCPImplementation {
  name: string
  version: string
  title?: string
  description?: string
  websiteUrl?: string
}

export interface MCPRequestMeta {
  "io.modelcontextprotocol/protocolVersion": MCPProtocolVersion | string
  "io.modelcontextprotocol/clientInfo": MCPImplementation
  "io.modelcontextprotocol/clientCapabilities": ACPObject
  "io.modelcontextprotocol/logLevel"?: MCPLoggingLevel
  progressToken?: string | number
  traceparent?: string
  tracestate?: string
  baggage?: string
  [key: string]: ACPValue | MCPImplementation | undefined
}

export interface MCPHTTPHeaders {
  "MCP-Protocol-Version": MCPProtocolVersion | string
  "Mcp-Method": MCPMethod | string
  "Mcp-Name"?: string
  [header: string]: string | undefined
}

export interface MCPCacheHints {
  ttlMs: number
  cacheScope: MCPCacheScope
}

export interface MCPDiscoverResult {
  resultType: "complete"
  supportedVersions: (MCPProtocolVersion | string)[]
  capabilities: ACPObject
  serverInfo: MCPImplementation
  instructions?: string
  _meta?: ACPObject
}

export interface MCPInputRequiredResult {
  resultType: "input_required"
  inputRequests?: Record<string, ACPObject>
  requestState?: string
  _meta?: ACPObject
}

export interface MCPUnsupportedProtocolVersionError {
  jsonrpc: "2.0"
  id?: JsonRpcId
  error: {
    code: typeof MCP_UNSUPPORTED_PROTOCOL_VERSION_ERROR.code
    message: typeof MCP_UNSUPPORTED_PROTOCOL_VERSION_ERROR.message
    data: {
      requested: string
      supported: (MCPProtocolVersion | string)[]
    }
  }
}

export interface MCPTool {
  name: string
  title?: string
  description?: string
  inputSchema: MCPJsonSchema202012
  outputSchema?: MCPJsonSchema202012
  annotations?: ACPObject
}

export interface MCPResource {
  uri: string
  name: string
  title?: string
  description?: string
  mimeType?: string
}

export interface MCPResourceTemplate {
  uriTemplate: string
  name: string
  title?: string
  description?: string
  mimeType?: string
}

export interface MCPPrompt {
  name: string
  title?: string
  description?: string
  arguments?: ACPObject[]
}

export interface MCPOAuthProtectedResourceMetadata {
  resource?: string
  authorization_servers: string[]
  scopes_supported?: string[]
  bearer_methods_supported?: string[]
  [key: string]: ACPValue | undefined
}

export interface MCPOAuthAuthorizationServerMetadata {
  issuer: string
  authorization_endpoint: string
  token_endpoint: string
  registration_endpoint?: string
  token_endpoint_auth_methods_supported?: string[]
  code_challenge_methods_supported?: string[]
  scopes_supported?: string[]
  client_id_metadata_document_supported?: boolean
  authorization_response_iss_parameter_supported?: boolean
  [key: string]: ACPValue | undefined
}

export interface MCPOAuthWwwAuthenticateChallenge {
  scheme: string
  params: Record<string, string>
}

export interface MCPOAuthDiscoveryResult {
  protectedResourceMetadataUrl: string
  protectedResourceMetadata: MCPOAuthProtectedResourceMetadata
  authorizationServerIssuer: string
  authorizationServerMetadataUrl: string
  authorizationServerMetadataKind: "oauth_authorization_server" | "openid_configuration"
  authorizationServerMetadata: MCPOAuthAuthorizationServerMetadata
  challenge?: MCPOAuthWwwAuthenticateChallenge
  scopes: string[]
}

export interface MCPOAuthDynamicClientRegistrationRequest {
  client_name: string
  redirect_uris: string[]
  grant_types: string[]
  response_types: string[]
  token_endpoint_auth_method: string
  application_type: MCPOAuthApplicationType
  scope?: string
}

export function isRequest(msg: ACPMessage): msg is ACPRequest {
  return "id" in msg && "method" in msg
}

export function isResponse(msg: ACPMessage): msg is ACPResponse {
  return "id" in msg && !("method" in msg)
}

export function isNotification(msg: ACPMessage): msg is ACPNotification {
  return !("id" in msg) && "method" in msg
}
