#!/usr/bin/env python3
"""
auditor — a modular skill package for the node AI, LIVING OUTSIDE node_ai/ (consumer of the
frozen S041 ABI, never a fork of it). Wired to the REAL vendored `node_core` in
node_ai/node_core/ via a sys.path shim (this package is not inside node_ai, so it cannot rely
on node_ai's own package layout) — never a lookalike/reimplementation of the ABI.

    from auditor import SKILL
    SKILL.run("rollforward_ending", {"beginning_balance": 1000000, "additions": 250000,
                                      "disposals": 100000})
    # -> {"value": 1150000, ...}   (right-or-refuse; refuses garbage/judgment)
"""
import os
import sys

# BUNDLE PATCH (apostol-reconcile-demo release): the source package shims
# sys.path up to the repo's node_ai/ to find the vendored node_core. In this
# bundle the package lives at ai_node/auditor_skills/auditor/ and node_core
# at ai_node/node_core/, so the shim resolves the BUNDLED ai_node/ instead.
_HERE = os.path.dirname(os.path.abspath(__file__))
_AUDITOR_SKILLS_ROOT = os.path.dirname(_HERE)                       # ai_node/auditor_skills
_AI_NODE_ROOT = os.path.dirname(_AUDITOR_SKILLS_ROOT)               # ai_node (bundled node_core lives here)
if _AI_NODE_ROOT not in sys.path:
    sys.path.insert(0, _AI_NODE_ROOT)

from node_core import DomainSkill, ConformanceError      # the frozen S041 ABI, imported READ-ONLY

from . import rollforward as _rf
from . import liabilities as _liab
from . import leadsheet as _ls
from . import judgment as _judg
from .manifest import MANIFEST

# merge the three leaf tool registries (disjoint tool names) into the raw domain pack
_RAW_TOOLS = {}
for _mod in (_rf, _liab, _ls):
    for _n, _t in _mod.TOOLS.items():
        if _n in _RAW_TOOLS:
            raise ConformanceError(f"duplicate tool name across modules: {_n!r}")
        _RAW_TOOLS[_n] = _t

# build the conformant skill (this CONFORMANCE-CHECKS and raises loudly if the ABI is violated)
SKILL = DomainSkill(MANIFEST, _RAW_TOOLS, judge=_judg.judge, judgment_refusals=_judg.JUDGMENT_REFUSALS)

__all__ = ["SKILL", "MANIFEST"]
