{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "data-format-transformations/bash-output/v1.0.0",
  "title": "Bash Script Output Parsing Schema",
  "description": "Schema for parsing bash script output with typed format (Integration Point 6.4)",
  "type": "object",
  "required": ["output_id", "script", "output", "timestamp"],
  "properties": {
    "output_id": {
      "type": "string",
      "description": "Unique identifier for output",
      "pattern": "^bash-output-[a-z0-9-]+$"
    },
    "script": {
      "type": "object",
      "description": "Script information",
      "required": ["path", "command"],
      "properties": {
        "path": {
          "type": "string",
          "description": "Script file path",
          "pattern": "^.*\\.sh$"
        },
        "command": {
          "type": "string",
          "description": "Full command executed"
        },
        "exit_code": {
          "type": "integer",
          "description": "Script exit code"
        }
      }
    },
    "output": {
      "type": "object",
      "description": "Parsed script output",
      "required": ["format", "data"],
      "properties": {
        "format": {
          "type": "string",
          "enum": ["json", "yaml", "text", "table", "structured"],
          "description": "Output format"
        },
        "data": {
          "description": "Parsed output data (type depends on format)",
          "oneOf": [
            {
              "type": "object"
            },
            {
              "type": "array"
            },
            {
              "type": "string"
            }
          ]
        },
        "raw": {
          "type": "string",
          "description": "Raw output before parsing"
        }
      }
    },
    "timestamp": {
      "type": "string",
      "format": "date-time",
      "description": "Output capture timestamp"
    },
    "parsing": {
      "type": "object",
      "description": "Parsing configuration",
      "properties": {
        "parser_type": {
          "type": "string",
          "enum": ["json", "yaml", "regex", "custom"],
          "description": "Type of parser used"
        },
        "parsing_rules": {
          "type": "array",
          "description": "Parsing rules applied",
          "items": {
            "type": "object",
            "properties": {
              "pattern": {
                "type": "string",
                "description": "Regex pattern"
              },
              "extraction": {
                "type": "string",
                "description": "What to extract"
              }
            }
          }
        },
        "validation": {
          "type": "object",
          "description": "Output validation",
          "properties": {
            "valid": {
              "type": "boolean"
            },
            "errors": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "typed_output": {
      "type": "object",
      "description": "Typed output format specification",
      "properties": {
        "type_schema": {
          "type": "object",
          "description": "Schema defining expected types",
          "additionalProperties": {
            "type": "string",
            "enum": ["string", "number", "boolean", "array", "object"]
          }
        },
        "type_validation_enabled": {
          "type": "boolean",
          "default": true
        },
        "type_coercion": {
          "type": "boolean",
          "description": "Whether to coerce types (e.g., \"123\" → 123)",
          "default": true
        }
      }
    },
    "error_handling": {
      "type": "object",
      "description": "Error handling for script failures",
      "properties": {
        "stderr": {
          "type": "string",
          "description": "Standard error output"
        },
        "error_parsed": {
          "type": "boolean",
          "description": "Whether error was successfully parsed"
        },
        "error_details": {
          "type": "object",
          "properties": {
            "error_type": {
              "type": "string"
            },
            "error_message": {
              "type": "string"
            }
          }
        }
      }
    },
    "unified_format": {
      "type": "object",
      "description": "Unified output format across scripts",
      "properties": {
        "standardized": {
          "type": "boolean",
          "description": "Whether output follows standard format"
        },
        "format_version": {
          "type": "string",
          "pattern": "^\\d+\\.\\d+\\.\\d+$"
        }
      }
    }
  },
  "additionalProperties": false,
  "examples": [
    {
      "output_id": "bash-output-coordination-001",
      "script": {
        "path": "./.claude/skills/cfn-coordination/coordination-signal.sh",
        "command": "coordination-signal \"swarm:task-auth:done\" \"complete\"",
        "exit_code": 0
      },
      "output": {
        "format": "json",
        "data": {
          "success": true,
          "channel": "swarm:task-auth:done",
          "message": "complete",
          "timestamp": "2025-11-17T10:30:00Z"
        },
        "raw": "{\"success\":true,\"channel\":\"swarm:task-auth:done\",\"message\":\"complete\",\"timestamp\":\"2025-11-17T10:30:00Z\"}"
      },
      "timestamp": "2025-11-17T10:30:00Z",
      "parsing": {
        "parser_type": "json",
        "validation": {
          "valid": true,
          "errors": []
        }
      },
      "typed_output": {
        "type_schema": {
          "success": "boolean",
          "channel": "string",
          "message": "string",
          "timestamp": "string"
        },
        "type_validation_enabled": true,
        "type_coercion": true
      },
      "unified_format": {
        "standardized": true,
        "format_version": "1.0.0"
      }
    }
  ]
}
