[importlinter]
root_package = mcp_hangar
include_external_packages = False

# ---------------------------------------------------------------------------
# Hexagon layering
# ---------------------------------------------------------------------------
# Read bottom-up: a layer may import anything BELOW it and nothing above.
#
#   shared kernel   cross-cutting vocabulary every layer may speak: logging,
#                   the error taxonomy, protocol constants, the SDK shim, the
#                   vendored task wire (ADR-015). No I/O, no policy.
#   domain          entities, value objects, policies, ports.
#   application     use cases, command/query handlers, sagas, read models.
#   infrastructure  adapters. The root-level modules on this line are adapters
#                   that never moved into the package: metrics is a Prometheus
#                   registry, http_client and stdio_client are transports,
#                   retry/progress/gc are runtime machinery.
#   delivery        HTTP/MCP surfaces and the facade.
#
# The split of the root-level modules is the point of this contract rather than
# a detail. Folding all 14 into the shared kernel would have been a shorter
# file and would have legitimised `domain -> metrics` and
# `domain.contracts.launcher -> http_client` -- a port importing its own
# adapter. Those are the leaks the contract exists to make visible.
#
# Component packages (auth, approvals, compliance, integrations, bootstrap,
# observability) carry their own internal layering and are deliberately out of
# scope here; exhaustive = False keeps them unconstrained rather than
# pretending this contract governs them.

[importlinter:contract:hexagon]
name = Hexagon: shared kernel < domain < application < infrastructure < delivery
type = layers
layers =
    mcp_hangar.server : mcp_hangar.fastmcp_server : mcp_hangar.facade
    mcp_hangar.infrastructure : mcp_hangar.metrics : mcp_hangar.http_client : mcp_hangar.stdio_client : mcp_hangar.retry : mcp_hangar.progress : mcp_hangar.gc
    mcp_hangar.application
    mcp_hangar.domain
    mcp_hangar.logging_config : mcp_hangar.errors : mcp_hangar.protocol : mcp_hangar.context : mcp_hangar._sdk_compat : mcp_hangar.tasks_wire : mcp_hangar.negotiation : mcp_hangar.observability
exhaustive = False

# The debt ledger. Every line is an edge that exists today and should not.
# It may shrink; tests/unit/test_import_contracts.py caps it so it cannot grow.
#
# Three groups worth recognising:
#   * domain.services.mcp_server_launcher.* -- seven deprecation shims that
#     re-export from infrastructure.launchers. Deleting them at 3.0 clears
#     seven lines at once.
#   * domain -> metrics / http_client / stdio_client / lock_hierarchy -- the
#     aggregate and one port reaching for adapters. IMetricsPublisher is
#     already injected into the aggregate, so part of this is a half-finished
#     migration rather than a design choice.
#   * application -> infrastructure / server -- five and four edges, all
#     function-scoped imports that read as cycle avoidance.
ignore_imports =
    mcp_hangar.application.commands.handlers -> mcp_hangar.metrics
    mcp_hangar.application.commands.load_handlers -> mcp_hangar.infrastructure.runtime_store
    mcp_hangar.application.commands.reload_handler -> mcp_hangar.server.config
    mcp_hangar.application.discovery.discovery_orchestrator -> mcp_hangar.metrics
    mcp_hangar.application.event_handlers.cost_handler -> mcp_hangar.metrics
    mcp_hangar.application.event_handlers.detection_handler -> mcp_hangar.server.api.sessions
    mcp_hangar.application.event_handlers.metrics_handler -> mcp_hangar.metrics
    mcp_hangar.application.event_handlers.persistent_audit_store -> mcp_hangar.infrastructure.async_executor
    mcp_hangar.application.mcp.tooling -> mcp_hangar.fastmcp_server.asgi
    mcp_hangar.application.queries.handlers -> mcp_hangar.infrastructure.event_store
    mcp_hangar.application.sagas.mcp_server_failover_saga -> mcp_hangar.infrastructure.saga_manager
    mcp_hangar.application.sagas.mcp_server_recovery_saga -> mcp_hangar.infrastructure.saga_manager
    mcp_hangar.context -> mcp_hangar.domain.value_objects.identity
    mcp_hangar.domain.contracts.launcher -> mcp_hangar.http_client
    mcp_hangar.domain.contracts.launcher -> mcp_hangar.stdio_client
    mcp_hangar.domain.model.mcp_server -> mcp_hangar.infrastructure.launchers
    mcp_hangar.domain.model.mcp_server -> mcp_hangar.infrastructure.lock_hierarchy
    mcp_hangar.domain.model.mcp_server -> mcp_hangar.metrics
    mcp_hangar.domain.model.mcp_server_group -> mcp_hangar.infrastructure.lock_hierarchy
    mcp_hangar.domain.repository -> mcp_hangar.infrastructure.lock_hierarchy
    mcp_hangar.domain.services -> mcp_hangar.application.read_models.tool_projection
    mcp_hangar.domain.services -> mcp_hangar.infrastructure.launchers
    mcp_hangar.domain.services.mcp_server_launcher -> mcp_hangar.infrastructure.launchers
    mcp_hangar.domain.services.mcp_server_launcher.base -> mcp_hangar.infrastructure.launchers.base
    mcp_hangar.domain.services.mcp_server_launcher.container -> mcp_hangar.infrastructure.launchers.container
    mcp_hangar.domain.services.mcp_server_launcher.docker -> mcp_hangar.infrastructure.launchers.docker
    mcp_hangar.domain.services.mcp_server_launcher.factory -> mcp_hangar.infrastructure.launchers.factory
    mcp_hangar.domain.services.mcp_server_launcher.http -> mcp_hangar.infrastructure.launchers.http
    mcp_hangar.domain.services.mcp_server_launcher.subprocess -> mcp_hangar.infrastructure.launchers.subprocess
    mcp_hangar.infrastructure.truncation.manager -> mcp_hangar.server.tools.batch.models
    mcp_hangar.logging_config -> mcp_hangar.domain.security.redactor
    mcp_hangar.protocol -> mcp_hangar.server.context
    mcp_hangar.observability.tracing -> mcp_hangar.metrics
