Files
stack/docs/plans/foundation-v1-candidate/command-events.schema.json
T

196 lines
9.7 KiB
JSON

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "urn:mosaic:planning:issue-53:command-events:candidate-1",
"title": "Planning candidate only: managed command request and evidence",
"description": "Not a runtime contract. Schema validity does not prove authentication, authorization, containment, durable recording, or reference integrity.",
"oneOf": [
{ "$ref": "#/$defs/request" },
{ "$ref": "#/$defs/event" }
],
"$defs": {
"id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9._-]{0,63}$" },
"runtimeId": { "type": "string", "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$" },
"revision": { "type": "integer", "minimum": 1, "maximum": 9007199254740991 },
"digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
"time": { "type": "string", "format": "date-time", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$" },
"scope": {
"type": "object", "additionalProperties": false,
"required": ["kind", "projectId", "workspaceId"],
"properties": {
"kind": { "const": "workspace" },
"projectId": { "$ref": "#/$defs/id" },
"workspaceId": { "$ref": "#/$defs/id" }
}
},
"workRef": {
"type": "object", "additionalProperties": false,
"required": ["kind", "id", "scope", "revision"],
"properties": {
"kind": { "enum": ["task", "assignment"] },
"id": { "$ref": "#/$defs/id" },
"scope": { "$ref": "#/$defs/scope" },
"revision": { "$ref": "#/$defs/revision" }
}
},
"taskRef": { "allOf": [{ "$ref": "#/$defs/workRef" }, { "properties": { "kind": { "const": "task" } } }] },
"assignmentRef": { "allOf": [{ "$ref": "#/$defs/workRef" }, { "properties": { "kind": { "const": "assignment" } } }] },
"artifactRef": {
"type": "object", "additionalProperties": false,
"required": ["runId", "artifactId", "digest"],
"properties": {
"runId": { "$ref": "#/$defs/id" },
"artifactId": { "$ref": "#/$defs/id" },
"digest": { "$ref": "#/$defs/digest" }
}
},
"actor": {
"type": "object", "additionalProperties": false,
"required": ["kind", "principalId", "executionId"],
"properties": {
"kind": { "enum": ["human", "service", "agent"] },
"principalId": { "$ref": "#/$defs/id" },
"executionId": { "oneOf": [{ "$ref": "#/$defs/runtimeId" }, { "type": "null" }] }
},
"if": { "properties": { "kind": { "const": "agent" } } },
"then": { "properties": { "executionId": { "$ref": "#/$defs/runtimeId" } } },
"else": { "properties": { "executionId": { "type": "null" } } }
},
"binding": {
"type": "object", "additionalProperties": false,
"required": ["agentId", "scope", "sessionId", "executionId", "claimGeneration", "assignmentRef", "taskRef"],
"properties": {
"agentId": { "$ref": "#/$defs/id" },
"scope": { "$ref": "#/$defs/scope" },
"sessionId": { "$ref": "#/$defs/runtimeId" },
"executionId": { "$ref": "#/$defs/runtimeId" },
"claimGeneration": { "$ref": "#/$defs/revision" },
"assignmentRef": { "$ref": "#/$defs/assignmentRef" },
"taskRef": { "$ref": "#/$defs/taskRef" }
}
},
"request": {
"type": "object", "additionalProperties": false,
"required": ["requestVersion", "requestId", "operation", "binding", "commandSpecRef", "timeoutSeconds"],
"properties": {
"requestVersion": { "const": 1 },
"requestId": { "$ref": "#/$defs/runtimeId" },
"operation": { "const": "command.execute" },
"binding": { "$ref": "#/$defs/binding" },
"commandSpecRef": { "$ref": "#/$defs/artifactRef" },
"timeoutSeconds": { "type": "integer", "minimum": 1, "maximum": 600 }
}
},
"producer": {
"type": "object", "additionalProperties": false,
"required": ["componentId", "instanceId"],
"properties": {
"componentId": { "$ref": "#/$defs/id" },
"instanceId": { "$ref": "#/$defs/runtimeId" }
}
},
"intent": {
"type": "object", "additionalProperties": false,
"required": ["requestId", "requestDigest", "commandSpecRef", "limitsRef", "coverage"],
"properties": {
"requestId": { "$ref": "#/$defs/runtimeId" },
"requestDigest": { "$ref": "#/$defs/digest" },
"commandSpecRef": { "$ref": "#/$defs/artifactRef" },
"limitsRef": { "$ref": "#/$defs/artifactRef" },
"coverage": { "const": "command-invocation-v1" }
}
},
"started": {
"type": "object", "additionalProperties": false,
"required": ["intentEventId", "processRef"],
"properties": {
"intentEventId": { "$ref": "#/$defs/runtimeId" },
"processRef": { "$ref": "#/$defs/artifactRef" }
}
},
"finished": {
"type": "object", "additionalProperties": false,
"required": ["intentEventId", "outcome", "exitCode", "signal", "termination", "terminationProofRef", "effects", "evidenceRefs"],
"properties": {
"intentEventId": { "$ref": "#/$defs/runtimeId" },
"outcome": { "enum": ["succeeded", "failed", "canceled", "unknown"] },
"exitCode": { "type": ["integer", "null"], "minimum": 0, "maximum": 255 },
"signal": { "oneOf": [{ "type": "null" }, { "type": "string", "pattern": "^SIG[A-Z0-9]{1,16}$" }] },
"termination": { "enum": ["confirmed", "unconfirmed", "not-started"] },
"terminationProofRef": { "oneOf": [{ "$ref": "#/$defs/artifactRef" }, { "type": "null" }] },
"effects": { "enum": ["not-issued", "unverified", "reconciled"] },
"evidenceRefs": { "type": "array", "maxItems": 1024, "uniqueItems": true, "items": { "$ref": "#/$defs/artifactRef" } }
},
"allOf": [
{
"if": { "properties": { "outcome": { "const": "succeeded" } } },
"then": { "properties": { "exitCode": { "const": 0 }, "signal": { "type": "null" }, "termination": { "const": "confirmed" }, "effects": { "enum": ["unverified", "reconciled"] } } }
},
{
"if": { "properties": { "termination": { "const": "confirmed" } } },
"then": { "properties": { "terminationProofRef": { "$ref": "#/$defs/artifactRef" } } },
"else": { "properties": { "terminationProofRef": { "type": "null" } } }
},
{
"if": { "properties": { "termination": { "const": "unconfirmed" } } },
"then": { "properties": { "outcome": { "const": "unknown" }, "effects": { "const": "unverified" } } }
},
{
"if": { "properties": { "termination": { "const": "not-started" } } },
"then": { "properties": { "outcome": { "enum": ["failed", "canceled"] }, "exitCode": { "type": "null" }, "signal": { "type": "null" }, "effects": { "const": "not-issued" } } },
"else": { "properties": { "effects": { "enum": ["unverified", "reconciled"] } } }
},
{
"if": { "properties": { "signal": { "type": "string" } } },
"then": { "properties": { "exitCode": { "type": "null" } } }
},
{
"if": { "properties": { "outcome": { "const": "failed" }, "termination": { "const": "confirmed" } } },
"then": { "anyOf": [
{ "properties": { "exitCode": { "type": "integer", "minimum": 1 } } },
{ "properties": { "signal": { "type": "string" } } }
] }
},
{
"if": { "properties": { "effects": { "const": "reconciled" } } },
"then": { "properties": { "evidenceRefs": { "minItems": 1 } } }
}
]
},
"recovered": {
"type": "object", "additionalProperties": false,
"required": ["priorEventId", "checkEventIds", "decisionRef", "result"],
"properties": {
"priorEventId": { "$ref": "#/$defs/runtimeId" },
"checkEventIds": { "type": "array", "minItems": 1, "maxItems": 1024, "uniqueItems": true, "items": { "$ref": "#/$defs/runtimeId" } },
"decisionRef": { "$ref": "#/$defs/artifactRef" },
"result": { "$ref": "#/$defs/finished" }
}
},
"event": {
"type": "object", "additionalProperties": false,
"required": ["eventVersion", "eventId", "eventType", "commandId", "sequence", "recordedAt", "observedAt", "actor", "producer", "binding", "authorizationRef", "causedByEventId", "payload"],
"properties": {
"eventVersion": { "const": 1 },
"eventId": { "$ref": "#/$defs/runtimeId" },
"eventType": { "enum": ["command.intent", "command.started", "command.finished", "command.recovered"] },
"commandId": { "$ref": "#/$defs/runtimeId" },
"sequence": { "$ref": "#/$defs/revision" },
"recordedAt": { "$ref": "#/$defs/time" },
"observedAt": { "$ref": "#/$defs/time" },
"actor": { "$ref": "#/$defs/actor" },
"producer": { "$ref": "#/$defs/producer" },
"binding": { "$ref": "#/$defs/binding" },
"authorizationRef": { "$ref": "#/$defs/runtimeId" },
"causedByEventId": { "$ref": "#/$defs/runtimeId" },
"payload": { "type": "object" }
},
"allOf": [
{ "if": { "properties": { "eventType": { "const": "command.intent" } } }, "then": { "properties": { "payload": { "$ref": "#/$defs/intent" } } } },
{ "if": { "properties": { "eventType": { "const": "command.started" } } }, "then": { "properties": { "payload": { "$ref": "#/$defs/started" } } } },
{ "if": { "properties": { "eventType": { "const": "command.finished" } } }, "then": { "properties": { "payload": { "$ref": "#/$defs/finished" } } } },
{ "if": { "properties": { "eventType": { "const": "command.recovered" } } }, "then": { "properties": { "payload": { "$ref": "#/$defs/recovered" } } } }
]
}
}
}