$schema: "@gobing-ai/spur/schemas/rule-file.schema.json"
# CLI surface consistency — structural checks that every command file follows
# the registerXxxCommand convention and that --json claims are backed by real
# output serialization (toEnvelopeJson, toJson, or JSON.stringify).
#
# Part of the recommended-pre-check preset. Run:
#   spur rule run --preset recommended-pre-check

include:
  - "apps/cli/src/commands/*.ts"

exclude:
  # Not command files: stubs.ts is an empty module shim (consistency.test.ts
  # excludes it too); shared-options.ts is the option registry.
  - "apps/cli/src/commands/stubs.ts"
  - "apps/cli/src/commands/shared-options.ts"

rules:
  - id: cli-register-pattern
    description: >
      Every CLI command file must export a registerXxxCommand(program, context)
      function matching the standard Commander.js wiring pattern.
    severity: error
    evaluator:
      type: rg
      config:
        pattern: "export function register\\w+Command\\("
        mode: require

  - id: cli-json-output
    description: >
      Command files that register --json options must call toEnvelopeJson()
      (ADR-091 envelope seam), toJson(), or JSON.stringify() to produce
      machine-readable output.
    severity: error
    evaluator:
      type: rg
      config:
        pattern: "toEnvelopeJson\\b|toJson\\b|JSON\\.stringify\\b"
        mode: require
