{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"$id": "https://ultimate-pi.local/.pi/harness/specs/plan-execution-plan.schema.json",
	"title": "ExecutionPlan",
	"type": "object",
	"additionalProperties": false,
	"required": [
		"schema_version",
		"phases",
		"work_items",
		"sprint_contract",
		"wbs_dictionary",
		"risk_register",
		"schedule_metadata",
		"dag_validation"
	],
	"properties": {
		"schema_version": { "type": "string", "const": "1.0.0" },
		"phases": {
			"type": "array",
			"minItems": 1,
			"items": { "$ref": "#/$defs/phase" }
		},
		"work_items": {
			"type": "array",
			"minItems": 1,
			"items": { "$ref": "#/$defs/work_item" }
		},
		"sprint_contract": { "$ref": "#/$defs/sprint_contract" },
		"wbs_dictionary": {
			"type": "array",
			"items": { "$ref": "#/$defs/wbs_entry" }
		},
		"risk_register": {
			"type": "array",
			"items": { "$ref": "#/$defs/risk" }
		},
		"schedule_metadata": { "$ref": "#/$defs/schedule_metadata" },
		"dag_validation": { "$ref": "#/$defs/dag_validation" },
		"lakes": {
			"type": "array",
			"items": { "$ref": "#/$defs/lake" }
		},
		"executor_strategy": {
			"type": "string",
			"enum": ["single_pass", "per_lake", "per_work_item"]
		},
		"critical_path_lake_ids": {
			"type": "array",
			"items": { "type": "string", "minLength": 1 }
		}
	},
	"$defs": {
		"lake": {
			"type": "object",
			"additionalProperties": false,
			"required": ["lake_id", "title", "outcome", "done_criteria"],
			"properties": {
				"lake_id": { "type": "string", "minLength": 1 },
				"title": { "type": "string", "minLength": 1 },
				"outcome": { "type": "string", "minLength": 1 },
				"done_criteria": { "type": "string", "minLength": 1 },
				"context_bundle_path": { "type": "string", "minLength": 1 },
				"files": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				},
				"out_of_scope": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				}
			}
		},
		"phase": {
			"type": "object",
			"additionalProperties": false,
			"required": [
				"phase_id",
				"name",
				"objective",
				"entry_criteria",
				"exit_criteria",
				"milestone",
				"work_item_ids"
			],
			"properties": {
				"phase_id": { "type": "string", "minLength": 1 },
				"name": { "type": "string", "minLength": 1 },
				"objective": { "type": "string", "minLength": 1 },
				"entry_criteria": {
					"type": "array",
					"minItems": 1,
					"items": { "type": "string", "minLength": 1 }
				},
				"exit_criteria": {
					"type": "array",
					"minItems": 1,
					"items": { "type": "string", "minLength": 1 }
				},
				"milestone": { "type": "string", "minLength": 1 },
				"work_item_ids": {
					"type": "array",
					"minItems": 1,
					"items": { "type": "string", "minLength": 1 }
				}
			}
		},
		"work_item": {
			"type": "object",
			"additionalProperties": false,
			"required": [
				"work_item_id",
				"phase_id",
				"title",
				"description",
				"depends_on",
				"files",
				"parallel_safe",
				"done_criteria",
				"acceptance_check_ids"
			],
			"properties": {
				"work_item_id": { "type": "string", "minLength": 1 },
				"phase_id": { "type": "string", "minLength": 1 },
				"title": { "type": "string", "minLength": 1 },
				"description": { "type": "string", "minLength": 1 },
				"depends_on": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				},
				"files": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				},
				"parallel_safe": { "type": "boolean" },
				"non_code": { "type": "boolean" },
				"done_criteria": { "$ref": "#/$defs/done_criteria" },
				"acceptance_check_ids": {
					"type": "array",
					"minItems": 1,
					"items": { "type": "string", "minLength": 1 }
				},
				"lake_id": { "type": "string", "minLength": 1 },
				"context_bundle_path": { "type": "string", "minLength": 1 },
				"context_refs": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				}
			}
		},
		"done_criteria": {
			"type": "object",
			"additionalProperties": false,
			"required": ["type", "spec"],
			"properties": {
				"type": {
					"type": "string",
					"enum": ["command", "test", "lint", "manual", "artifact"]
				},
				"spec": { "type": "string", "minLength": 1 }
			}
		},
		"sprint_contract": {
			"type": "object",
			"additionalProperties": false,
			"required": [
				"in_scope",
				"out_of_scope",
				"definition_of_done",
				"assumptions",
				"external_dependencies"
			],
			"properties": {
				"in_scope": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				},
				"out_of_scope": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				},
				"definition_of_done": { "type": "string", "minLength": 1 },
				"assumptions": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				},
				"external_dependencies": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				}
			}
		},
		"wbs_entry": {
			"type": "object",
			"additionalProperties": false,
			"required": [
				"work_item_id",
				"deliverable",
				"owner_role",
				"inputs",
				"outputs"
			],
			"properties": {
				"work_item_id": { "type": "string", "minLength": 1 },
				"deliverable": { "type": "string", "minLength": 1 },
				"owner_role": {
					"type": "string",
					"enum": ["executor", "human", "research"]
				},
				"inputs": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				},
				"outputs": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				}
			}
		},
		"risk": {
			"type": "object",
			"additionalProperties": false,
			"required": [
				"risk_id",
				"description",
				"likelihood",
				"impact",
				"mitigation",
				"linked_work_item_ids"
			],
			"properties": {
				"risk_id": { "type": "string", "minLength": 1 },
				"description": { "type": "string", "minLength": 1 },
				"likelihood": {
					"type": "string",
					"enum": ["low", "med", "high"]
				},
				"impact": {
					"type": "string",
					"enum": ["low", "med", "high"]
				},
				"mitigation": { "type": "string", "minLength": 1 },
				"linked_work_item_ids": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				}
			}
		},
		"schedule_metadata": {
			"type": "object",
			"additionalProperties": false,
			"required": [
				"critical_path_work_item_ids",
				"parallel_groups",
				"schedule_baseline_note"
			],
			"properties": {
				"critical_path_work_item_ids": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				},
				"parallel_groups": {
					"type": "array",
					"items": {
						"type": "array",
						"items": { "type": "string", "minLength": 1 }
					}
				},
				"schedule_baseline_note": { "type": "string", "minLength": 1 }
			}
		},
		"dag_validation": {
			"type": "object",
			"additionalProperties": false,
			"required": ["status", "topological_order", "cycles", "conflicts"],
			"properties": {
				"status": { "type": "string", "enum": ["pass", "fail"] },
				"topological_order": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				},
				"cycles": {
					"type": "array",
					"items": { "type": "array", "items": { "type": "string" } }
				},
				"conflicts": {
					"type": "array",
					"items": { "type": "string", "minLength": 1 }
				}
			}
		}
	}
}
