{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Bilt Task Definitions and Governance Configurations",
  "description": "Standardized task definitions, CI/CD gates, pre-commit hooks, and agent governance templates for Bilt Toolkit.",
  "tasks": {
    "ciPullRequestGate": {
      "name": "Bilt Verification Gate (GitHub Actions)",
      "file": ".github/workflows/bilt-gate.yml",
      "purpose": "Verifies pull requests against base branch, enforces anti-tamper, and evaluates loop budget.",
      "definition": {
        "name": "Bilt Verification Gate",
        "on": {
          "pull_request": {
            "branches": ["main", "master", "develop"]
          }
        },
        "jobs": {
          "verify": {
            "name": "Verify Production Readiness",
            "runs-on": "ubuntu-latest",
            "steps": [
              {
                "name": "Checkout repository",
                "uses": "actions/checkout@v4",
                "with": {
                  "fetch-depth": 0
                }
              },
              {
                "name": "Setup Node.js",
                "uses": "actions/setup-node@v4",
                "with": {
                  "node-version": "20",
                  "cache": "npm"
                }
              },
              {
                "name": "Install Bilt Toolkit",
                "run": "npm install -g bilt-toolkit"
              },
              {
                "name": "Execute Bilt Verification Gate",
                "run": "bilt verify --base origin/${{ github.base_ref }} --max-iterations 5"
              }
            ]
          }
        }
      }
    },
    "preCommitHook": {
      "name": "Husky Pre-commit Verification Hook",
      "file": ".husky/pre-commit",
      "purpose": "Prevents developers or coding agents from committing unverified changes or secrets locally.",
      "definition": "#!/usr/bin/env sh\n. \"$(dirname -- \"$0\")/_/husky.sh\"\n\nnpx bilt check --changed --strict\n"
    },
    "agentSelfHealingLoop": {
      "name": "AI Coding Agent Remediation Protocol",
      "description": "Standard execution task loop for autonomous agents (Claude Code, Cursor, Devin, Antigravity).",
      "steps": [
        {
          "step": 1,
          "action": "Run Bilt in machine format",
          "command": "npx bilt check --format agent"
        },
        {
          "step": 2,
          "action": "Check process exit code",
          "decision": {
            "exitCode_0": "Halt loop. All checks passed. Proceed to commit or merge.",
            "exitCode_1": "Proceed to Step 3 (Remediate hard failures).",
            "exitCode_2": "Inform developer of needs_review heuristics if --strict is enabled.",
            "exitCode_3": "Repair command arguments or syntax error in source files.",
            "exitCode_4": "HALT IMMEDIATELY. Escalation triggered. Do not repeat failed edits. Notify human maintainer."
          }
        },
        {
          "step": 3,
          "action": "Parse JSON findings",
          "details": "Read finding.ruleId, finding.file, finding.line, finding.agent_action, and loop_budget."
        },
        {
          "step": 4,
          "action": "Apply targeted remediation",
          "details": "Follow finding.agent_action. Never disable rules or weaken .biltrc.json."
        },
        {
          "step": 5,
          "action": "Re-verify",
          "command": "npx bilt check --format agent",
          "condition": "Repeat until exitCode == 0 or loop_budget.escalate == true."
        }
      ]
    },
    "atomicRemediation": {
      "name": "Safe Fix and Undo Rollback",
      "commands": {
        "applySafe": "npx bilt fix --safe",
        "previewDryRun": "npx bilt fix --dry-run",
        "rollbackUndo": "npx bilt undo"
      },
      "guarantees": "Atomic rollback restores previous state in sub-2ms using .bilt/snapshots/."
    },
    "baselineCreation": {
      "name": "Baseline Legacy Debt Lock",
      "command": "npx bilt baseline create",
      "file": ".bilt/baseline.json",
      "purpose": "Locks existing technical debt so teams can adopt Bilt immediately without blocking on legacy issues."
    },
    "riskAcceptance": {
      "name": "Formal Risk Acceptance Recording",
      "command": "npx bilt accept-risk <finding-id> --reason \"<justification>\" --owner \"<developer-email>\" --expires \"<yyyy-mm-dd>\"",
      "file": ".bilt/risk-acceptance.json",
      "rules": "Strictly rejected for the 6 mandatory invariant categories (secrets-and-env, auth, authorization, input-validation, api-abuse-and-cost, database)."
    }
  },
  "schemas": {
    "biltrc": {
      "filename": ".biltrc.json",
      "example": {
        "version": 1,
        "strict": false,
        "ignore": [
          "**/node_modules/**",
          "**/dist/**",
          "**/*.test.ts"
        ],
        "categories": {
          "secrets-and-env": { "enabled": true },
          "auth": { "enabled": true },
          "authorization": { "enabled": true },
          "input-validation": { "enabled": true },
          "api-abuse-and-cost": { "enabled": true },
          "database": { "enabled": true },
          "dependencies": { "enabled": true },
          "error-handling-logs": { "enabled": true },
          "transport-and-headers": { "enabled": true },
          "deploy-config": { "enabled": true },
          "file-uploads": { "enabled": true },
          "payments": { "enabled": true },
          "privacy-and-pii": { "enabled": true },
          "monitoring-rollback": { "enabled": true }
        },
        "maxIterations": 5
      }
    },
    "agentsMd": {
      "filename": "AGENTS.md",
      "content": "# AI Agent Instructions for Bilt\n\n1. Always run `npx bilt check --format agent` before declaring any task complete.\n2. If exit code is 1, read `findings[].agent_action` and fix the code directly.\n3. Never modify `.biltrc.json` or `.gitignore` to suppress security findings.\n4. If exit code is 4, halt retries and report the block to the user.\n"
    }
  }
}
