#!/usr/bin/env bash
#MISE description="Iter-156 default-when-no-subcommand dispatcher for the commits namespace. Prints a compact operator-facing index of the iter-150-through-iter-155 conventional-commits arc toolkit: 5 tools across release:history (iter-150 readable view), commits:health (iter-152 5-panel dashboard, default + --json), commits:advise (iter-153 pre-commit dry-run advisor, default + --json + --strict). Includes iter-150 50/72 convention reminder + cross-reference to the canonical docs/RELEASE.md Conventional-Commits Operator Toolkit Index section. Closes the discoverability gap surfaced by the iter-156 adversarial audit: the 5 arc tools were scattered across release/ and commits/ mise namespaces with no single entry point, undiscoverable without spelunking 100+ entries in `mise tasks` output."
set -euo pipefail

# ANSI color codes — gracefully degrade to plain text when stdout is not a TTY.
if [[ -t 1 ]]; then
    ITER156_ANSI_COLOR_BOLD="$(printf '\033[1m')"
    ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS="$(printf '\033[36m')"
    ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS="$(printf '\033[32m')"
    ITER156_ANSI_COLOR_RESET="$(printf '\033[0m')"
else
    ITER156_ANSI_COLOR_BOLD=""
    ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS=""
    ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS=""
    ITER156_ANSI_COLOR_RESET=""
fi

cat <<EOF

═══════════════════════════════════════════════════════════════════════════════
  ${ITER156_ANSI_COLOR_BOLD}CC-SKILLS CONVENTIONAL-COMMITS OPERATOR TOOLKIT${ITER156_ANSI_COLOR_RESET}  (iter-150 → iter-164 arc)
═══════════════════════════════════════════════════════════════════════════════

${ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS}─── VIEW (iter-150) — readable rendering of verbose commit subjects ───${ITER156_ANSI_COLOR_RESET}

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run release:history${ITER156_ANSI_COLOR_RESET}
      Awk-based soft-wrap renderer for verbose conventional-commit subjects.
      Tunables: ITER150_COMMIT_COUNT_TO_DISPLAY (default 10),
                ITER150_SOFT_WRAP_COLUMN_WIDTH (default 80).

${ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS}─── DETECT (iter-151) — preflight long-subject overlay classifier ───${ITER156_ANSI_COLOR_RESET}

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run audit-recent-git-commit-messages-...${ITER156_ANSI_COLOR_RESET}
      (Runs automatically as Check 4l during release:preflight.)
      Iter-151 extended the iter-82 validator with informational overlay
      flagging conformant commits whose subject exceeds the iter-150
      72-char industry hard cap.

${ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS}─── HEALTH SUMMARY (iter-152, with iter-155 --json) — 5-panel dashboard ───${ITER156_ANSI_COLOR_RESET}

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run commits:health${ITER156_ANSI_COLOR_RESET}
      5-panel operator dashboard: readable view + length-distribution
      histogram + worst-offender callouts + type distribution + trend
      signal (IMPROVING/REGRESSING/STABLE/MIXED vs previous N-commit
      window).

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run commits:health --json${ITER156_ANSI_COLOR_RESET}
      Same data, machine-readable JSON for AI-agent automation. Stable
      iter155_schema_version=1. Pipe to jq:
        \`mise run commits:health --json | jq .panel_5_recent_vs_previous_window_trend_signal.verdict\`

${ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS}─── PRE-COMMIT ADVISE (iter-153, with iter-154 hardening) — dry-run advisor ───${ITER156_ANSI_COLOR_RESET}

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run commits:advise -- "<proposed subject>"${ITER156_ANSI_COLOR_RESET}
      Classify a proposed conventional-commit subject BEFORE committing.
      Verdict: COMMIT_READY / COMMIT_READY_WITH_READABILITY_WARNING /
      SILENT_FAIL_RISK (COMPOUND-PREFIX or MISSING-TYPE).

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run commits:advise --json -- "<subject>"${ITER156_ANSI_COLOR_RESET}
      Same advisor, machine-readable JSON for AI agents.

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run commits:advise --strict -- "<subject>"${ITER156_ANSI_COLOR_RESET}
      Exit non-zero on silent-fail-class violations (manual gating mode).

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run commits:advise${ITER156_ANSI_COLOR_RESET}    (no args, in interactive terminal)
      Iter-154 auto-detect: reads .git/COMMIT_EDITMSG when invoked
      during an editor-launched git commit flow.

${ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS}─── SEMVER-BUMP PREVIEW (iter-161, iter-162 body-aware, iter-164 concrete next-version) ───${ITER156_ANSI_COLOR_RESET}

  All four ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}commits:advise${ITER156_ANSI_COLOR_RESET} invocation forms above now include the iter-161
  semver-bump preview overlay: maps the {type, breaking-change marker}
  pair to the actual MAJOR/MINOR/PATCH/NONE bump that semantic-release
  will apply per cc-skills .releaserc.yml release rules. Closes the
  conventional-commits ecosystem advisor gap — commitlint, commitizen,
  and conventional-pre-commit all stop at grammar conformance and never
  preview the bump. Available in both human-readable and --json modes;
  --json embeds a nested iter161_semver_bump_preview object with stable
  iter161_schema_version=1 for AI-agent automation pipelines.

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run commits:advise --message-file <path>${ITER156_ANSI_COLOR_RESET}
      Iter-162 body-aware extension: reads the FULL multi-line commit
      message (subject + body), then detects Conventional Commits §13
      BREAKING-CHANGE footer-tokens (BREAKING CHANGE:, BREAKING-CHANGE:,
      BREAKING CHANGES:) in the body. OR'd with the subject \`!\` marker
      so footer-form breaking changes correctly preview as MAJOR (not
      mis-predicted MINOR). Used internally by the iter-157 commit-msg
      hook to forward .git/COMMIT_EDITMSG. JSON mode adds the
      iter162_breaking_change_signal_source field with canonical values:
      none / subject_bang_marker / body_footer_token / both.

  Iter-164 concrete next-version preview: resolves the iter-161 bump
  LABEL into the actual NEXT VERSION NUMBER by applying semver.org §2
  increment rules to the current \`git describe --tags\` tag. Human
  output adds a line like \`next version: v21.71.0 → v21.72.0\` directly
  below the bump-label line. --json embeds a nested
  iter164_next_version_preview object with stable iter164_schema_version=1
  + current_git_tag + next_version + resolution_rationale. Closes the
  "MINOR bump means what version exactly?" gap that the bump-label-only
  preview leaves open. Pure-bash — no \`semantic-release --dry-run\`
  invocation needed (saves the multi-second push-permission verify cost
  per the 2026 semantic-release FAQ).

${ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS}─── AUTOMATE (iter-157) — install as git commit-msg hook ───${ITER156_ANSI_COLOR_RESET}

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run commits:install-hook${ITER156_ANSI_COLOR_RESET}
      Install the iter-153 advisor as a .git/hooks/commit-msg hook in
      the current repo. After install, every \`git commit\` automatically
      runs --strict classification and rejects silent-fail-class
      violations (COMPOUND-PREFIX, MISSING-TYPE) — no operator
      discipline required. Idempotent; backs up existing hooks.

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run commits:uninstall-hook${ITER156_ANSI_COLOR_RESET}
      Remove cc-skills-managed hook + restore most recent backup.

${ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS}─── DIAGNOSE (iter-160) — self-diagnosis of the entire commits toolkit ───${ITER156_ANSI_COLOR_RESET}

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run commits:status${ITER156_ANSI_COLOR_RESET}
      9-check self-diagnosis across iter-150 → iter-158 tools:
      structural validity, functional correctness, hook-install state,
      pre-commit-framework binary availability. Per-check wall-clock
      latency reporting. Industry-standard brew-doctor/npm-doctor
      pattern. Exit 0 if toolkit healthy; exit 1 if CRITICAL check
      fails.

  ${ITER156_ANSI_COLOR_GREEN_FOR_TOOL_INVOCATIONS}mise run commits:status --json${ITER156_ANSI_COLOR_RESET}
      Same checks, machine-readable JSON output with stable
      iter160_schema_version=1 for AI-agent automation pipelines.

${ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS}─── POLYGLOT (iter-158, iter-159) — pre-commit framework integration ───${ITER156_ANSI_COLOR_RESET}

  Other repos using the pre-commit framework can consume cc-skills WITHOUT
  cloning it locally. Add to their .pre-commit-config.yaml:

    default_install_hook_types: [pre-commit, commit-msg]
    repos:
      - repo: https://github.com/terrylica/cc-skills
        rev: <latest-cc-skills-tag>
        hooks:
          - id: cc-skills-commits-advise-commit-msg

  Then: pre-commit install --hook-type commit-msg

  Iter-159 empirically validated this end-to-end against the real
  pre-commit framework binary (4/4 subject variants pass: REJECT
  COMPOUND-PREFIX + MISSING-TYPE, ACCEPT STANDARD-CONFORMANT + feat!:
  breaking-change). The iter-159 harness caught and fixed iter-158's
  language=system → language=script bug before any upstream consumer
  could be affected.

${ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS}─── CONVENTION (iter-150 going-forward standard) ───${ITER156_ANSI_COLOR_RESET}

  Conventional-commits 50/72 rule:
    Subject: ≤50 chars hard target, ≤72 chars hard cap
    Body:    wrapped at 72 chars per line, blank line separates subject

  Canonical spec:    https://www.conventionalcommits.org/
  Seven-rules essay: https://cbea.ms/git-commit/

${ITER156_ANSI_COLOR_CYAN_FOR_SECTION_HEADERS}─── DEEP DIVE ───${ITER156_ANSI_COLOR_RESET}

  Full operator documentation:
    docs/RELEASE.md → "Conventional-Commits Operator Toolkit Index"
    https://github.com/terrylica/cc-skills/blob/main/docs/RELEASE.md

═══════════════════════════════════════════════════════════════════════════════

EOF
