let s = import "./schema.ncl" in

# Tool and dependency requirements for the ontoref ecosystem.
# Query (agent or newcomer):
#   nickel export reflection/requirements/base.ncl | get tools | select id binary version_min install_hint
#
# Query by context:
#   nickel export reflection/requirements/base.ncl | get tools | where (contexts | any { |c| $c == "local_dev" })
#
# Validate environment:
#   nu reflection/bin/check-prereqs.nu --context local_dev

{
  tools = [

    # ── Core (required in every context) ─────────────────────────────────────

    ({
      id              = "nickel",
      binary          = "nickel",
      description     = "Type-safe configuration language. Primary config source of truth (ADR-001).",
      version_min     = "1.9.0",
      check_cmd       = "nickel --version",
      version_extract = "nickel (\\d+\\.\\d+\\.\\d+)",
      install_hint    = "cargo install nickel-lang-cli  # or: brew install nickel-lang",
      docs_url        = "https://nickel-lang.org",
      severity        = 'Hard,
      contexts        = ["local_dev", "ci", "agent", "benchmark"],
      used_by_forms   = ["new_adr", "query_constraints", "new_project", "supersede_adr"],
      used_by_modes   = ["new_adr", "read_as_agent", "validate_decision", "supersede_adr"],
    } | s.Tool),

    ({
      id              = "nushell",
      binary          = "nu",
      description     = "Structured shell and scripting language. Used for check_hints, scripts, and mode execution.",
      version_min     = "0.110.0",
      check_cmd       = "nu --version",
      version_extract = "(\\d+\\.\\d+\\.\\d+)",
      install_hint    = "cargo install nu  # or: brew install nushell",
      docs_url        = "https://nushell.sh",
      severity        = 'Hard,
      contexts        = ["local_dev", "ci", "agent", "benchmark"],
      used_by_forms   = ["new_project", "supersede_adr"],
      used_by_modes   = ["validate_decision", "new_project", "supersede_adr", "query_constraints"],
      config_check    = "nu -c 'version | get version'",
      config_hint     = "Minimum 0.110.0 required for pipeline let binding and `| complete` patterns.",
    } | s.Tool),

    ({
      id              = "git",
      binary          = "git",
      description     = "Version control. Required for ADR commit workflow and project initialization.",
      version_min     = "2.40.0",
      check_cmd       = "git --version",
      version_extract = "git version (\\d+\\.\\d+\\.\\d+)",
      install_hint    = "brew install git  # or: system package manager",
      severity        = 'Hard,
      contexts        = ["local_dev", "ci"],
      used_by_forms   = ["new_adr", "supersede_adr", "new_project"],
      used_by_modes   = ["new_adr", "supersede_adr", "new_project"],
    } | s.Tool),

    # ── Interactive / form layer ──────────────────────────────────────────────

    ({
      id              = "typedialog",
      binary          = "typedialog",
      description     = "Multibackend form runner. Required for interactive ADR authoring and project initialization. Forms are NCL records (not TOML). Uses nickel-roundtrip for editing existing files.",
      version_min     = "0.1.0",
      check_cmd       = "typedialog --version",
      version_extract = "typedialog (\\d+\\.\\d+\\.\\d+)",
      install_hint    = "cargo install typedialog",
      docs_url        = "https://repo.jesusperez.pro/jesus/typedialog",
      severity        = 'Soft,
      contexts        = ["local_dev"],
      used_by_forms   = ["new_adr", "new_project", "supersede_adr", "query_constraints"],
      used_by_modes   = ["new_adr", "new_project", "supersede_adr"],
      config_check    = "do { ^typedialog --version } | complete | get stdout | str contains '0.'",
      config_hint     = "Forms use NCL format (not TOML). Command: typedialog nickel-roundtrip --input <file.ncl> --form <form.ncl> --output <out.ncl>",
    } | s.Tool),

    # ── NATS ─────────────────────────────────────────────────────────────────

    ({
      id              = "nats-cli",
      binary          = "nats",
      description     = "NATS CLI for stream creation and message publishing. Required for ecosystem event publishing and NATS stream setup.",
      version_min     = "0.1.0",
      check_cmd       = "nats --version",
      version_extract = "(\\d+\\.\\d+\\.\\d+)",
      install_hint    = "brew install nats-io/nats-tools/nats  # or: go install github.com/nats-io/natscli/nats@latest",
      severity        = 'Soft,
      contexts        = ["local_dev"],
      used_by_forms   = ["new_project"],
      used_by_modes   = ["new_project"],
      config_check    = "do { ^nats server check --server nats://localhost:4222 } | complete | get stdout | str contains 'OK'",
      config_hint     = "NATS server must be running at nats://localhost:4222 for ecosystem event publishing. Start: nats-server -js",
    } | s.Tool),

    # ── Nu plugins ───────────────────────────────────────────────────────────
    # Checked via `plugin list`, not `which`. plugin_name drives the check path.

    ({
      id          = "nu-plugin-nickel",
      binary      = "nu_plugin_nickel",
      plugin_name = "nickel",
      description = "Nushell plugin for Nickel. Provides nickel-export (no from json), nickel-eval (cached), nickel-validate, nickel-format.",
      version_min = "0.110.0",
      check_cmd   = "plugin list | where name == 'nickel' | first | get version",
      install_hint = "plugin add ~/.local/bin/nu_plugin_nickel  # then restart nu",
      severity    = 'Soft,
      contexts    = ["local_dev", "agent"],
      used_by_forms = ["new_adr", "new_project", "supersede_adr"],
      used_by_modes = ["new_adr", "new_project"],
    } | s.Tool),

    ({
      id          = "nu-plugin-tera",
      binary      = "nu_plugin_tera",
      plugin_name = "tera",
      description = "Nushell plugin for Tera (Jinja2-compatible) template rendering. Used by agent render path: nickel-export | tera-render template.ncl.j2.",
      version_min = "0.110.0",
      check_cmd   = "plugin list | where name == 'tera' | first | get version",
      install_hint = "plugin add ~/.local/bin/nu_plugin_tera  # then restart nu",
      severity    = 'Soft,
      contexts    = ["local_dev", "agent"],
      used_by_forms = ["new_adr", "new_project", "supersede_adr"],
      used_by_modes = ["new_adr", "new_project"],
    } | s.Tool),

    ({
      id          = "nu-plugin-nats",
      binary      = "nu_plugin_nats",
      plugin_name = "nats",
      description = "Nushell plugin for NATS JetStream. Provides nats pub, nats stream setup, nats status, nats notify.",
      version_min = "0.110.0",
      check_cmd   = "plugin list | where name == 'nats' | first | get version",
      install_hint = "plugin add /path/to/nu_plugin_nats  # then restart nu",
      severity    = 'Soft,
      contexts    = ["local_dev"],
      used_by_forms = ["new_project"],
      used_by_modes = ["new_project"],
      config_check = "plugin list | where name == 'nats' | is-not-empty | into string",
      config_hint  = "nats plugin must be registered: plugin add /path/to/nu_plugin_nats",
    } | s.Tool),

    # ── Optional ecosystem tooling ────────────────────────────────────────────

    ({
      id              = "kogral",
      binary          = "kogral",
      description     = "Graph database CLI. Optional — new_project continues without it.",
      version_min     = "0.1.0",
      check_cmd       = "kogral --version",
      version_extract = "(\\d+\\.\\d+\\.\\d+)",
      install_hint    = "cargo install kogral  # see: https://repo.jesusperez.pro/jesus/kogral",
      severity        = 'Soft,
      contexts        = ["local_dev"],
      used_by_forms   = ["new_project"],
      used_by_modes   = ["new_project"],
    } | s.Tool),

    ({
      id              = "syntaxis",
      binary          = "syntaxis",
      description     = "Project registry CLI. Optional — new_project continues without it.",
      version_min     = "0.1.0",
      check_cmd       = "syntaxis --version",
      version_extract = "(\\d+\\.\\d+\\.\\d+)",
      install_hint    = "cargo install syntaxis  # see: https://repo.jesusperez.pro/jesus/syntaxis",
      severity        = 'Soft,
      contexts        = ["local_dev"],
      used_by_forms   = ["new_project"],
      used_by_modes   = ["new_project"],
    } | s.Tool),

  ],
}
