{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"$id": "https://ultimate-pi.local/.pi/harness/specs/run-trace.schema.json",
	"title": "RunTrace",
	"description": "Append-only execution trace row for harness phases.",
	"type": "object",
	"additionalProperties": false,
	"required": [
		"schema_version",
		"contract_version",
		"run_id",
		"plan_id",
		"agent_id",
		"phase",
		"model",
		"thinking_level",
		"tool_spans",
		"artifact_refs",
		"cost"
	],
	"properties": {
		"schema_version": {
			"type": "string",
			"const": "1.0.0"
		},
		"contract_version": {
			"type": "string",
			"const": "1.0.0"
		},
		"run_id": {
			"type": "string",
			"minLength": 1
		},
		"plan_id": {
			"type": "string",
			"minLength": 1
		},
		"agent_id": {
			"type": "string",
			"minLength": 1
		},
		"phase": {
			"type": "string",
			"enum": ["plan", "execute", "evaluate", "adversary", "merge"]
		},
		"model": {
			"type": "string",
			"minLength": 1
		},
		"thinking_level": {
			"type": "string",
			"enum": ["off", "low", "medium", "high", "xhigh"]
		},
		"tool_spans": {
			"type": "array",
			"items": {
				"type": "object",
				"additionalProperties": false,
				"required": ["tool_call_id", "tool_name", "started_at", "ended_at"],
				"properties": {
					"tool_call_id": {
						"type": "string",
						"minLength": 1
					},
					"tool_name": {
						"type": "string",
						"minLength": 1
					},
					"started_at": {
						"type": "string",
						"format": "date-time"
					},
					"ended_at": {
						"type": "string",
						"format": "date-time"
					}
				}
			}
		},
		"artifact_refs": {
			"type": "array",
			"items": {
				"type": "string",
				"minLength": 1
			}
		},
		"cost": {
			"type": "object",
			"additionalProperties": false,
			"required": ["input_tokens", "output_tokens", "total_tokens"],
			"properties": {
				"input_tokens": {
					"type": "integer",
					"minimum": 0
				},
				"output_tokens": {
					"type": "integer",
					"minimum": 0
				},
				"total_tokens": {
					"type": "integer",
					"minimum": 0
				}
			}
		}
	}
}
