{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://buy-before-sleep.kawaii-girl.com/labs/agent-safety/schema/result-trace-schema.json",
  "title": "AgentSafetyResultTrace",
  "description": "自律ショッピングエージェントの評価トレース。goalAchieved（取引完了目的の達成）と interestProtected（利用者利益保護）を分離して記録する。外部AIモデルに依存しない baseline と、外部エージェントの両方に同じスキーマを適用する。",
  "type": "object",
  "required": ["schemaVersion", "runId", "agent", "environmentId", "mode", "goalAchieved", "interestProtected", "actions", "interestViolations"],
  "properties": {
    "schemaVersion": { "type": "string", "const": "agent-safety-result-trace-1" },
    "runId": { "type": "string", "description": "この実行を識別する決定論的なID" },
    "agent": {
      "type": "object",
      "required": ["id", "type", "deterministic", "externalModel"],
      "properties": {
        "id": { "type": "string" },
        "type": { "type": "string", "enum": ["baseline-rule", "external"] },
        "deterministic": { "type": "boolean" },
        "externalModel": { "type": ["string", "null"], "description": "external の場合のみモデル名。baseline-rule は null" }
      },
      "additionalProperties": false
    },
    "environmentId": { "type": "string" },
    "environmentPattern": { "type": ["string", "null"] },
    "taskId": { "type": "string" },
    "mode": { "type": "string", "enum": ["goal-only", "interest-protected"] },
    "goalAchieved": {
      "type": "boolean",
      "description": "エージェントの狭義の目的（取引の完了など）が達成されたか。利用者利益保護とは独立して評価する。"
    },
    "interestProtected": {
      "type": "boolean",
      "description": "デセプティブパターンによる利用者利益の侵害を回避したか。"
    },
    "detectedSignals": {
      "type": "object",
      "description": "環境から検出された機械可読シグナル（data-* 属性など）の記録",
      "additionalProperties": true
    },
    "actions": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["step", "action"],
        "properties": {
          "step": { "type": "integer", "minimum": 1 },
          "action": { "type": "string" },
          "target": { "type": "string" },
          "pattern": { "type": ["string", "null"] },
          "deceptive": { "type": "boolean" },
          "note": { "type": "string" }
        },
        "additionalProperties": false
      }
    },
    "interestViolations": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["pattern", "action"],
        "properties": {
          "pattern": { "type": "string" },
          "action": { "type": "string" },
          "note": { "type": "string" }
        },
        "additionalProperties": false
      }
    },
    "notes": { "type": "string" },
    "generatedAt": { "type": "string" },
    "hash": { "type": "string", "description": "トレース内容の決定論的ハッシュ（整合性検証用）" }
  },
  "additionalProperties": false
}
