{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://equaxis.local/schema/equaxis-config-v1.json",
  "title": "Equaxis Unified Configuration",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "runtime",
    "extensions",
    "reliability",
    "memory",
    "skills",
    "codeGraph",
    "goalState",
    "refine",
    "wiki",
    "evaluation",
    "subagents",
    "protocols"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "runtime": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "profile",
        "services",
        "gates"
      ],
      "properties": {
        "profile": {
          "enum": [
            "raw",
            "minimal",
            "standard",
            "full"
          ]
        },
        "services": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "config",
            "diagnostics",
            "trace",
            "status"
          ],
          "properties": {
            "config": {
              "type": "boolean"
            },
            "diagnostics": {
              "type": "boolean"
            },
            "trace": {
              "type": "boolean"
            },
            "status": {
              "type": "boolean"
            }
          }
        },
        "gates": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "enabled",
            "minBenchmarkPassRate",
            "maxReliabilityRegression",
            "maxUnitCostUsd",
            "maxLatencyMs",
            "minImprovementDelta"
          ],
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "minBenchmarkPassRate": {
              "type": "number",
              "minimum": 0,
              "maximum": 1
            },
            "maxReliabilityRegression": {
              "type": "number",
              "minimum": 0,
              "maximum": 10
            },
            "maxUnitCostUsd": {
              "type": "number",
              "minimum": 0,
              "maximum": 1000000
            },
            "maxLatencyMs": {
              "type": "integer",
              "minimum": 1,
              "maximum": 600000
            },
            "minImprovementDelta": {
              "type": "number",
              "minimum": -10,
              "maximum": 10
            }
          }
        }
      }
    },
    "extensions": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "manifest",
        "enabled",
        "disabled"
      ],
      "properties": {
        "manifest": {
          "type": "string",
          "minLength": 1
        },
        "enabled": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "disabled": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "reliability": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "traceDir",
        "trace",
        "protectPaths",
        "approval",
        "limits",
        "toolRouting"
      ],
      "properties": {
        "mode": {
          "enum": [
            "enforce",
            "audit",
            "off"
          ]
        },
        "traceDir": {
          "type": "string",
          "minLength": 1
        },
        "trace": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "maxFileBytes",
            "maxFiles"
          ],
          "properties": {
            "maxFileBytes": {
              "type": "integer",
              "minimum": 4096,
              "maximum": 1073741824
            },
            "maxFiles": {
              "type": "integer",
              "minimum": 1,
              "maximum": 20
            }
          }
        },
        "protectPaths": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "approval": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "highRiskBash",
            "writesOutsideWorkspace",
            "externalEditPolicy",
            "externalEditRoots",
            "sessionFork"
          ],
          "properties": {
            "highRiskBash": {
              "type": "boolean"
            },
            "writesOutsideWorkspace": {
              "type": "boolean"
            },
            "externalEditPolicy": {
              "enum": [
                "prompt",
                "auto",
                "deny"
              ]
            },
            "externalEditRoots": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            },
            "sessionFork": {
              "type": "boolean"
            },
            "webQueue": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "enabled": {
                  "type": "boolean"
                },
                "timeoutMs": {
                  "type": "integer",
                  "minimum": 1000,
                  "maximum": 600000
                }
              }
            },
            "denyRephrase": {
              "type": "boolean"
            },
            "batchPerTurn": {
              "type": "boolean"
            }
          }
        },
        "limits": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "maxToolCallsPerTurn",
            "maxHighRiskCallsPerTurn",
            "maxRepairAttemptsPerError",
            "maxRepeatedCalls"
          ],
          "properties": {
            "maxToolCallsPerTurn": {
              "type": "integer",
              "minimum": 1,
              "maximum": 1000
            },
            "maxHighRiskCallsPerTurn": {
              "type": "integer",
              "minimum": 0,
              "maximum": 100
            },
            "maxRepairAttemptsPerError": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10
            },
            "maxRepeatedCalls": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50
            }
          }
        },
        "toolRouting": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "enabled",
            "maxCandidates"
          ],
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "maxCandidates": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50
            }
          }
        },
        "costBrake": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "enabled",
            "maxSessionCostUsd",
            "warnAtFraction"
          ],
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "maxSessionCostUsd": {
              "type": "number",
              "minimum": 0.01
            },
            "warnAtFraction": {
              "type": "number",
              "minimum": 0.1,
              "maximum": 1
            }
          }
        },
        "commandAllowlist": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "enabled",
            "extraCommands"
          ],
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "extraCommands": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        }
      }
    },
    "memory": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "enabled",
        "pythonCommand",
        "rootDir",
        "autoRecall",
        "defaultWing",
        "defaultRoom",
        "recallLimit",
        "maxContextChars",
        "maxStoredMessageChars",
        "requestTimeoutMs",
        "governance"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "backend": {
          "type": "string",
          "enum": ["native", "python"]
        },
        "pythonCommand": {
          "type": "string",
          "minLength": 1
        },
        "rootDir": {
          "type": "string",
          "minLength": 1
        },
        "autoRecall": {
          "type": "boolean"
        },
        "defaultWing": {
          "type": "string",
          "minLength": 1
        },
        "defaultRoom": {
          "type": "string",
          "minLength": 1
        },
        "recallLimit": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100
        },
        "maxContextChars": {
          "type": "integer",
          "minimum": 256,
          "maximum": 1000000
        },
        "maxStoredMessageChars": {
          "type": "integer",
          "minimum": 256,
          "maximum": 1000000
        },
        "requestTimeoutMs": {
          "type": "integer",
          "minimum": 100,
          "maximum": 600000
        },
        "governance": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "enabled",
            "auditPath",
            "retentionDays"
          ],
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "auditPath": {
              "type": "string",
              "minLength": 1
            },
            "retentionDays": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "hot",
                "warm",
                "cold"
              ],
              "properties": {
                "hot": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 36500
                },
                "warm": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 36500
                },
                "cold": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 36500
                }
              }
            }
          }
        },
        "dream": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "onShutdown": {
              "type": "boolean"
            },
            "maxEntries": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500
            },
            "provider": {
              "type": "string",
              "minLength": 1
            },
            "model": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      }
    },
    "skills": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "enabled",
        "rootDir",
        "autoInject",
        "maxContextTokens",
        "requiredNames"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "rootDir": {
          "type": "string",
          "minLength": 1
        },
        "autoInject": {
          "type": "boolean"
        },
        "maxContextTokens": {
          "type": "integer",
          "minimum": 100,
          "maximum": 1000000
        },
        "requiredNames": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "codeGraph": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "enabled",
        "rootDir",
        "includeDirs",
        "maxFiles",
        "rebuildIfStaleMs"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "rootDir": {
          "type": "string",
          "minLength": 1
        },
        "includeDirs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "maxFiles": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        },
        "rebuildIfStaleMs": {
          "type": "integer",
          "minimum": 60000
        }
      }
    },
    "goalState": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "enabled",
        "rootDir",
        "defaultQuota",
        "autoWake"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "rootDir": {
          "type": "string",
          "minLength": 1
        },
        "defaultQuota": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "tokenBudget",
            "windowHours"
          ],
          "properties": {
            "tokenBudget": {
              "type": "integer",
              "minimum": 1
            },
            "windowHours": {
              "type": "integer",
              "minimum": 1
            }
          }
        },
        "autoWake": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "enabled",
            "intervalMinutes",
            "provider",
            "model"
          ],
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "intervalMinutes": {
              "type": "integer",
              "minimum": 5,
              "maximum": 1440
            },
            "provider": {
              "type": "string"
            },
            "model": {
              "type": "string"
            }
          }
        }
      }
    },
    "refine": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "enabled",
        "rootDir"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "rootDir": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "wiki": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "enabled",
        "rootDir",
        "includeDirs",
        "extensions",
        "maxFiles"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "rootDir": {
          "type": "string",
          "minLength": 1
        },
        "includeDirs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "extensions": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "maxFiles": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        }
      }
    },
    "evaluation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "enabled",
        "rootDir",
        "minSamples",
        "minSuccessRateDelta",
        "maxLatencyRegression",
        "maxCostRegression",
        "confidenceZ"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "rootDir": {
          "type": "string",
          "minLength": 1
        },
        "minSamples": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100000
        },
        "minSuccessRateDelta": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "maxLatencyRegression": {
          "type": "number",
          "minimum": 0,
          "maximum": 10
        },
        "maxCostRegression": {
          "type": "number",
          "minimum": 0,
          "maximum": 10
        },
        "confidenceZ": {
          "type": "number",
          "minimum": 0,
          "maximum": 10
        }
      }
    },
    "subagents": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "enabled",
        "maxConcurrent",
        "piEntry",
        "jsonArgs",
        "budgets",
        "persistence",
        "isolation"
      ],
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "maxConcurrent": {
          "type": "integer",
          "minimum": 1,
          "maximum": 32
        },
        "piEntry": {
          "type": "string"
        },
        "jsonArgs": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "budgets": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "timeoutMs",
            "maxRetries"
          ],
          "properties": {
            "timeoutMs": {
              "type": [
                "integer",
                "null"
              ],
              "minimum": 100,
              "maximum": 600000
            },
            "maxRetries": {
              "type": "integer",
              "minimum": 0,
              "maximum": 5
            }
          }
        },
        "persistence": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "enabled",
            "rootDir"
          ],
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "rootDir": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "isolation": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "enabled",
            "scrubEnv",
            "outputRoot",
            "extraEnvAllowlist"
          ],
          "properties": {
            "enabled": {
              "type": "boolean"
            },
            "scrubEnv": {
              "type": "boolean"
            },
            "outputRoot": {
              "type": "string",
              "minLength": 1
            },
            "extraEnvAllowlist": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            },
            "worktree": {
              "type": "boolean"
            }
          }
        }
      }
    },
    "protocols": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "lsp",
        "dap"
      ],
      "properties": {
        "lsp": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "command",
            "args",
            "cwd",
            "requestTimeoutMs",
            "allowCommandOverride"
          ],
          "properties": {
            "command": {
              "type": "string"
            },
            "args": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "cwd": {
              "type": "string"
            },
            "requestTimeoutMs": {
              "type": "integer",
              "minimum": 100,
              "maximum": 120000
            },
            "allowCommandOverride": {
              "type": "boolean"
            }
          }
        },
        "dap": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "command",
            "args",
            "cwd",
            "requestTimeoutMs",
            "allowCommandOverride"
          ],
          "properties": {
            "command": {
              "type": "string"
            },
            "args": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "cwd": {
              "type": "string"
            },
            "requestTimeoutMs": {
              "type": "integer",
              "minimum": 100,
              "maximum": 120000
            },
            "allowCommandOverride": {
              "type": "boolean"
            }
          }
        }
      }
    },
    "advisor": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": {
          "type": "boolean"
        },
        "provider": {
          "type": "string"
        },
        "model": {
          "type": "string"
        },
        "mode": {
          "type": "string",
          "enum": ["recommend", "review"]
        },
        "triggers": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "complexPlanStepThreshold": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100
        }
      }
    }
  }
}
