{
  "$schema": "https://raw.githubusercontent.com/anthropics/claude-code/main/schemas/settings.json",
  "version": "2.0.0",
  "name": "AutoWorkflow",
  "description": "Automated workflow enforcement for Claude Code via hooks and system prompts",

  "hooks": {
    "UserPromptSubmit": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/session-check.sh",
            "timeout": 10
          }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/pre-edit.sh",
            "timeout": 5
          }
        ]
      },
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/pre-tool-router.sh",
            "timeout": 300
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Write|Edit",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/post-edit.sh",
            "timeout": 120
          }
        ]
      },
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": ".claude/hooks/post-bash-router.sh",
            "timeout": 30
          }
        ]
      }
    ]
  },

  "instructions": [
    "## WORKFLOW ENFORCEMENT",
    "",
    "You MUST follow this workflow for ALL tasks:",
    "",
    "### Phase Flow",
    "```",
    "ANALYZE → PLAN → CONFIRM → IMPLEMENT → VERIFY → AUDIT → COMMIT → UPDATE",
    "```",
    "",
    "### CRITICAL: ONE FIX AT A TIME RULE",
    "**This is NON-NEGOTIABLE and applies to ALL projects (TypeScript, PHP, Python, Go, Rust, etc.):**",
    "",
    "1. **NEVER batch multiple fixes** - Fix ONE issue, verify, then move to next",
    "2. **MUST show 3-tier suggestions FIRST** before any fix:",
    "   - 🔴 Required (must fix)",
    "   - 🟡 Recommended (should fix)",
    "   - 🟢 Optional (nice to have)",
    "3. **MUST WAIT for user to select** which items to implement",
    "4. **After user selects**, implement ONE item at a time",
    "5. **Verify after EACH fix** before moving to the next",
    "",
    "❌ WRONG: 'I found 14 issues, let me fix them all'",
    "✅ RIGHT: 'I found 14 issues. Here are my suggestions: [show tiers]. Which would you like me to fix first?'",
    "",
    "",
    "### Skill Loading (CRITICAL)",
    "When executing ANY command from .claude/commands/:",
    "1. Read the command's YAML frontmatter",
    "2. Check for `skills_required` array",
    "3. For EACH skill listed, READ the file from `.claude/skills/` BEFORE executing",
    "4. Apply the knowledge from skills during command execution",
    "",
    "Example: `/audit` has `skills_required: [security.md, code-review.md]`",
    "→ Read `.claude/skills/security.md` first",
    "→ Read `.claude/skills/code-review.md` second",
    "→ THEN execute the audit with this knowledge loaded",
    "",
    "### Auto-Triggers (Hooks enforce these)",
    "1. **SESSION START**: If no documentation provided → Prompt user for project documentation",
    "2. **AFTER CODE CHANGES**: Run `npm run verify` automatically. Fix errors until passing (max 10 iterations)",
    "3. **BEFORE COMMIT**: All 7 gates must pass or commit is BLOCKED:",
    "   - TypeScript errors = 0",
    "   - ESLint warnings = 0",
    "   - No TODO/FIXME in changes",
    "   - No console.log in changes",
    "   - No orphan features (audit:ui)",
    "   - No circular deps (audit:cycles)",
    "   - Conventional commit format: type(scope): description",
    "",
    "### Blocking Gates",
    "- **plan_approval_gate**: WAIT for user approval before implementing",
    "- **verify_gate**: Code must pass typecheck + lint",
    "- **audit_gate**: No orphan features, no cycles (for features/refactors)",
    "- **pre_commit_gate**: All checks must pass",
    "",
    "### Task Types (from system/router.md)",
    "| Type | Workflow | Audit? |",
    "|------|----------|--------|",
    "| feature | Full (all phases) | Yes |",
    "| fix | Standard (no audit) | No |",
    "| refactor | Full with audit | Yes |",
    "| docs | Simple | No |",
    "| query | Analyze → Respond | No |",
    "",
    "### Required Files",
    "- Read instructions/AI_RULES.md for coding standards",
    "- Reference user's documentation (single source of truth)",
    "- Read system/router.md to classify task type",
    "- Read system/gates.md for blocking rules",
    "",
    "### State Tracking",
    "Check .claude/.autoworkflow/ for current workflow state:",
    "- phase: Current phase (ANALYZE, PLAN, etc.)",
    "- task-type: Classified task type",
    "- verify-iteration: Current verify loop count",
    "- gate-status: Last gate check result",
    "",
    "### Memory System (Persistent Context)",
    "Edit these files directly using the Edit tool:",
    "- `.claude/.autoworkflow/memories/decisions.md` - After PLAN: record architectural choices",
    "- `.claude/.autoworkflow/memories/patterns.md` - After IMPLEMENT: record discovered patterns",
    "- `.claude/.autoworkflow/memories/blockers.md` - When errors: record issues and workarounds",
    "- `.claude/.autoworkflow/memories/context.md` - Before COMMIT: update session summary",
    "",
    "Format: ## Title, *Date*, Content, ---"
  ],

  "workflow": {
    "phases": ["ANALYZE", "PLAN", "CONFIRM", "IMPLEMENT", "VERIFY", "FIX", "AUDIT", "COMMIT", "UPDATE"],
    "maxFixIterations": 10,
    "maxAuditIterations": 5
  },

  "gates": {
    "plan_approval": {
      "blocking": true,
      "requires": ["User explicit approval"]
    },
    "verify": {
      "blocking": true,
      "command": "npm run verify"
    },
    "audit": {
      "blocking": true,
      "commands": ["npm run audit:ui", "npm run audit:cycles"],
      "appliesTo": ["feature", "refactor"]
    },
    "pre_commit": {
      "blocking": true,
      "checks": ["TypeScript", "ESLint", "No TODO/FIXME", "No console.log", "UI Enforcement", "Circular Deps", "Commit Format"]
    }
  },

  "taskTypes": {
    "feature": {
      "workflow": ["ANALYZE", "PLAN", "CONFIRM", "IMPLEMENT", "VERIFY", "AUDIT", "COMMIT", "UPDATE"],
      "requiresAudit": true,
      "requiresSuggestions": true
    },
    "fix": {
      "workflow": ["ANALYZE", "PLAN", "CONFIRM", "IMPLEMENT", "VERIFY", "COMMIT"],
      "requiresAudit": false
    },
    "refactor": {
      "workflow": ["ANALYZE", "PLAN", "CONFIRM", "IMPLEMENT", "VERIFY", "AUDIT", "COMMIT"],
      "requiresAudit": true
    },
    "docs": {
      "workflow": ["ANALYZE", "IMPLEMENT", "COMMIT"],
      "requiresAudit": false
    },
    "query": {
      "workflow": ["ANALYZE", "RESPOND"],
      "requiresAudit": false
    }
  },

  "commands": {
    "verify": "npm run verify",
    "typecheck": "npm run typecheck",
    "lint": "npm run lint",
    "audit:ui": "npm run audit:ui",
    "audit:cycles": "npm run audit:cycles",
    "format": "npm run format"
  },

  "rules": {
    "noTodoComments": true,
    "noConsoleLogs": true,
    "noOrphanFeatures": true,
    "noCircularDependencies": true,
    "conventionalCommits": true,
    "readBeforeWrite": true,
    "planBeforeImplement": true,
    "verifyAfterImplement": true,
    "auditBeforeCommit": true
  }
}
