{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://wstein.github.io/cx-cli/schemas/manifest-v12.schema.json",
  "title": "cx Manifest v12",
  "description": "On-disk format for a cx bundle manifest (schemaVersion 12). Records the oracle adapter package identity so reproducibility is bound to the selected oracle adapter as well as the bundle configuration.",
  "type": "object",
  "required": [
    "schemaVersion",
    "bundleVersion",
    "projectName",
    "sourceRoot",
    "bundleDir",
    "checksumFile",
    "createdAt",
    "cxVersion",
    "checksumAlgorithm",
    "oracleAdapter",
    "settings",
    "totalTokenCount",
    "vcsProvider",
    "dirtyState",
    "modifiedFiles",
    "trustModel",
    "traceability",
    "sections",
    "assets"
  ],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": {
      "description": "Manifest schema version. Must be exactly 12.",
      "const": 12
    },
    "bundleVersion": {
      "description": "Bundle format version. Must be exactly 1.",
      "const": 1
    },
    "projectName": {
      "description": "Project name as declared in cx.toml.",
      "type": "string",
      "minLength": 1
    },
    "sourceRoot": {
      "description": "Absolute path to the source root at bundle time.",
      "type": "string",
      "minLength": 1
    },
    "bundleDir": {
      "description": "Absolute path to the bundle output directory.",
      "type": "string",
      "minLength": 1
    },
    "checksumFile": {
      "description": "Filename of the SHA-256 checksum sidecar (relative to bundleDir).",
      "type": "string",
      "minLength": 1
    },
    "handoverFile": {
      "description": "Filename of the shared handover artifact (relative to bundleDir).",
      "type": "string",
      "minLength": 1
    },
    "createdAt": {
      "description": "ISO 8601 timestamp at which the bundle was created.",
      "type": "string",
      "format": "date-time"
    },
    "cxVersion": {
      "description": "Version of the cx CLI that produced this manifest.",
      "type": "string",
      "minLength": 1
    },
    "checksumAlgorithm": {
      "description": "Algorithm used in the checksum sidecar.",
      "const": "sha256"
    },
    "settings": {
      "$ref": "#/$defs/ManifestSettings"
    },
    "oracleAdapter": {
      "$ref": "#/$defs/ManifestOracleAdapterIdentity"
    },
    "totalTokenCount": {
      "description": "Total token count for all text content represented in this bundle.",
      "type": "integer",
      "minimum": 0
    },
    "vcsProvider": {
      "description": "Version-control system detected at bundle time. 'none' indicates the filesystem fallback was used (no .git or Fossil repository found).",
      "enum": ["git", "fossil", "hg", "none"]
    },
    "dirtyState": {
      "description": "Source-tree dirty-state at bundle time.\n\nclean — no working-tree modifications; standard verified bundle.\nsafe_dirty — only untracked files were present; bundle integrity is unaffected.\nforced_dirty — tracked files with uncommitted changes were bundled because the operator passed --force. The LLM must treat this bundle as containing uncommitted work.",
      "enum": ["clean", "safe_dirty", "forced_dirty"]
    },
    "modifiedFiles": {
      "description": "Relative POSIX paths of VCS-tracked files that had uncommitted local changes at bundle time. Populated only when dirtyState is 'forced_dirty'; empty array otherwise.",
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "trustModel": {
      "$ref": "#/$defs/ManifestTrustModel"
    },
    "traceability": {
      "$ref": "#/$defs/ManifestTraceability"
    },
    "sections": {
      "description": "Ordered list of text-file sections in the bundle.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/SectionRecord"
      }
    },
    "assets": {
      "description": "Raw files copied into the bundle without Repomix rendering.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/AssetRecord"
      }
    },
    "notes": {
      "description": "Repository notes metadata recorded at bundle time so AI tooling can inspect the note graph without reparsing Markdown.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/NoteRecord"
      }
    },
    "derivedReviewExports": {
      "description": "Derived docs exports written for review workflows. These are checksum-covered bundle artifacts but not proof-path section outputs.",
      "type": "array",
      "items": {
        "$ref": "#/$defs/DerivedReviewExportRecord"
      }
    }
  },
  "$defs": {
    "ManifestOracleAdapterIdentity": {
      "description": "Reference-oracle adapter package identity recorded at bundle time.",
      "type": "object",
      "required": [
        "modulePath",
        "packageName",
        "packageVersion",
        "adapterContract"
      ],
      "additionalProperties": false,
      "properties": {
        "modulePath": {
          "description": "Effective module path used for the oracle adapter.",
          "type": "string",
          "minLength": 1
        },
        "packageName": {
          "description": "Installed package name resolved for the oracle adapter.",
          "type": "string",
          "minLength": 1
        },
        "packageVersion": {
          "description": "Installed package version resolved for the oracle adapter.",
          "type": "string",
          "minLength": 1
        },
        "adapterContract": {
          "description": "Adapter contract expected by cx oracle diagnostics.",
          "const": "repomix-pack-v1"
        }
      }
    },
    "ManifestSettings": {
      "description": "Snapshot of the cx configuration settings used to build this bundle.",
      "type": "object",
      "required": [
        "globalStyle",
        "tokenEncoding",
        "showLineNumbers",
        "includeEmptyDirectories",
        "securityCheck",
        "normalizationPolicy",
        "includeLinkedNotes"
      ],
      "additionalProperties": false,
      "properties": {
        "globalStyle": {
          "description": "Default Repomix output style for sections.",
          "enum": ["xml", "markdown", "json", "plain"]
        },
        "tokenEncoding": {
          "description": "Tokenizer encoding used to produce exact token counts.",
          "type": "string",
          "minLength": 1
        },
        "showLineNumbers": { "type": "boolean" },
        "includeEmptyDirectories": { "type": "boolean" },
        "securityCheck": { "type": "boolean" },
        "normalizationPolicy": {
          "description": "Versioned policy describing how file content was normalized before hashing.",
          "const": "repomix-default-v1"
        },
        "includeLinkedNotes": {
          "description": "Whether linked notes were included in the bundle plan.",
          "type": "boolean"
        }
      }
    },
    "ManifestTrustModel": {
      "description": "Explicit trust labels for the bundle proof surface and its upstream reasoning inputs.",
      "type": "object",
      "required": ["sourceTree", "notes", "agentOutput", "bundle"],
      "additionalProperties": false,
      "properties": {
        "sourceTree": {
          "const": "trusted"
        },
        "notes": {
          "const": "conditional"
        },
        "agentOutput": {
          "const": "untrusted_until_verified"
        },
        "bundle": {
          "const": "trusted"
        }
      }
    },
    "ManifestTraceability": {
      "description": "Explicit provenance hooks that explain how to audit bundle trust and agent decisions.",
      "type": "object",
      "required": ["bundle", "notes", "agent"],
      "additionalProperties": false,
      "properties": {
        "bundle": {
          "type": "object",
          "required": ["command", "track"],
          "additionalProperties": false,
          "properties": {
            "command": {
              "const": "cx bundle"
            },
            "track": {
              "const": "A"
            }
          }
        },
        "notes": {
          "type": "object",
          "required": ["governanceCommand", "trustLevel"],
          "additionalProperties": false,
          "properties": {
            "governanceCommand": {
              "const": "cx notes check"
            },
            "trustLevel": {
              "const": "conditional"
            }
          }
        },
        "agent": {
          "type": "object",
          "required": ["auditLogPath", "outputTrust", "decisionSource"],
          "additionalProperties": false,
          "properties": {
            "auditLogPath": {
              "const": ".cx/audit.log"
            },
            "outputTrust": {
              "const": "untrusted_until_verified"
            },
            "decisionSource": {
              "const": "mcp_audit_log"
            }
          }
        }
      }
    },
    "SectionRecord": {
      "description": "A rendered text-file section and its file metadata.",
      "type": "object",
      "required": ["name", "style", "outputFile", "outputSha256", "fileCount", "tokenCount", "files"],
      "additionalProperties": false,
      "properties": {
        "name": {
          "description": "Section name as declared in cx.toml [sections.<name>].",
          "type": "string",
          "minLength": 1
        },
        "style": {
          "description": "Repomix output style used to render this section.",
          "enum": ["xml", "markdown", "json", "plain"]
        },
        "outputFile": {
          "description": "Filename of the rendered section output (relative to bundleDir).",
          "type": "string",
          "minLength": 1
        },
        "outputSha256": {
          "description": "SHA-256 hex digest of the rendered section output file.",
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "fileCount": {
          "description": "Number of source files embedded in this section.",
          "type": "integer",
          "minimum": 0
        },
        "tokenCount": {
          "description": "Exact token count of the section's embedded source content.",
          "type": "integer",
          "minimum": 0
        },
        "files": {
          "description": "Ordered list of source files embedded in this section.",
          "type": "array",
          "items": {
            "$ref": "#/$defs/ManifestFileRow"
          }
        }
      }
    },
    "ManifestFileRow": {
      "description": "Metadata for one source file represented in the bundle.",
      "type": "object",
      "required": [
        "path",
        "kind",
        "storedIn",
        "sha256",
        "sizeBytes",
        "tokenCount",
        "mtime",
        "mediaType",
        "outputStartLine",
        "outputEndLine"
      ],
      "additionalProperties": false,
      "properties": {
        "path": {
          "description": "Source-relative path of the original file.",
          "type": "string",
          "minLength": 1
        },
        "kind": {
          "description": "Whether this row represents text content or a raw copied asset.",
          "enum": ["text", "asset"]
        },
        "storedIn": {
          "description": "Whether the file is stored in a section output or copied verbatim.",
          "enum": ["packed", "copied"]
        },
        "sha256": {
          "description": "SHA-256 hex digest of the normalized packed content stored in the section output.",
          "type": "string",
          "minLength": 1
        },
        "sizeBytes": {
          "description": "Original source file size in bytes.",
          "type": "integer",
          "minimum": 0
        },
        "tokenCount": {
          "description": "Exact token count of the source file content.",
          "type": "integer",
          "minimum": 0
        },
        "mtime": {
          "description": "ISO 8601 source file modification time.",
          "type": "string",
          "minLength": 1
        },
        "mediaType": {
          "description": "MIME media type of the source file.",
          "type": "string",
          "minLength": 1
        },
        "outputStartLine": {
          "description": "First bare content line of the file block in the section output (null when span capture is disabled).",
          "oneOf": [
            { "type": "integer", "minimum": 1 },
            { "type": "null" }
          ]
        },
        "outputEndLine": {
          "description": "Last bare content line of the file block in the section output (null when span capture is disabled).",
          "oneOf": [
            { "type": "integer", "minimum": 1 },
            { "type": "null" }
          ]
        },
        "provenance": {
          "description": "Optional ordered markers describing why this file was included in the plan.",
          "type": "array",
          "items": {
            "enum": [
              "section_match",
              "catch_all_section_match",
              "asset_rule_match",
              "linked_note_enrichment",
              "manifest_note_inclusion"
            ]
          },
          "uniqueItems": true
        }
      }
    },
    "AssetRecord": {
      "description": "A raw file copied into the bundle without Repomix rendering.",
      "type": "object",
      "required": ["sourcePath", "storedPath", "sha256", "sizeBytes", "mtime", "mediaType"],
      "additionalProperties": false,
      "properties": {
        "sourcePath": {
          "description": "Source-relative path of the original file.",
          "type": "string",
          "minLength": 1
        },
        "storedPath": {
          "description": "Path where the file is stored in the bundle (relative to bundleDir).",
          "type": "string",
          "minLength": 1
        },
        "sha256": {
          "description": "SHA-256 hex digest of the file content.",
          "type": "string",
          "minLength": 1
        },
        "sizeBytes": {
          "description": "File size in bytes.",
          "type": "integer",
          "minimum": 0
        },
        "mtime": {
          "description": "ISO 8601 modification time of the source file.",
          "type": "string",
          "minLength": 1
        },
        "mediaType": {
          "description": "MIME media type.",
          "type": "string",
          "minLength": 1
        },
        "provenance": {
          "description": "Optional ordered markers describing why this asset was included in the plan.",
          "type": "array",
          "items": {
            "enum": [
              "section_match",
              "catch_all_section_match",
              "asset_rule_match",
              "linked_note_enrichment",
              "manifest_note_inclusion"
            ]
          },
          "uniqueItems": true
        }
      }
    },
    "DerivedReviewExportRecord": {
      "description": "A derived Antora assembly export captured for review-oriented workflows.",
      "type": "object",
      "required": [
        "assemblyName",
        "title",
        "moduleName",
        "storedPath",
        "sha256",
        "sizeBytes",
        "pageCount",
        "rootLevel",
        "sourcePaths",
        "generator",
        "trustClassification"
      ],
      "additionalProperties": false,
      "properties": {
        "assemblyName": {
          "type": "string",
          "minLength": 1
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "moduleName": {
          "type": ["string", "null"],
          "minLength": 1
        },
        "storedPath": {
          "description": "Path where the export is stored in the bundle (relative to bundleDir).",
          "type": "string",
          "minLength": 1
        },
        "sha256": {
          "description": "SHA-256 hex digest of the exported docs file.",
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "sizeBytes": {
          "type": "integer",
          "minimum": 0
        },
        "pageCount": {
          "type": "integer",
          "minimum": 0
        },
        "rootLevel": {
          "type": "integer",
          "enum": [0, 1]
        },
        "sourcePaths": {
          "description": "Ordered source page paths that were assembled into this export.",
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "generator": {
          "type": "object",
          "required": ["name", "version", "format", "extension"],
          "additionalProperties": false,
          "properties": {
            "name": {
              "const": "@wsmy/antora-markdown-exporter"
            },
            "version": {
              "type": "string",
              "minLength": 1
            },
            "format": {
              "const": "multimarkdown"
            },
            "extension": {
              "const": ".mmd.txt"
            }
          }
        },
        "trustClassification": {
          "const": "derived_review_export"
        }
      }
    },
    "NoteRecord": {
      "description": "Repository note metadata captured for AI-first workflows.",
      "type": "object",
      "required": [
        "id",
        "title",
        "fileName",
        "aliases",
        "tags",
        "summary",
        "codeLinks",
        "cognitionScore",
        "cognitionLabel",
        "trustLevel",
        "lastModified"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "description": "Time-based note identifier.",
          "type": "string",
          "minLength": 1
        },
        "title": {
          "description": "Human-readable note title.",
          "type": "string",
          "minLength": 1
        },
        "fileName": {
          "description": "Relative filename of the note within the notes directory.",
          "type": "string",
          "minLength": 1
        },
        "aliases": {
          "description": "Alternative names for the note.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "tags": {
          "description": "Note tags used for grouping and retrieval.",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "summary": {
          "description": "Short summary extracted from the note body.",
          "type": "string",
          "minLength": 1
        },
        "codeLinks": {
          "description": "Repository-path-style wikilink targets found in the note body (e.g. src/auth/index.ts).",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "cognitionScore": {
          "description": "Diagnostic cognition score computed from summary quality, structure, and evidence links.",
          "type": "integer",
          "minimum": 0
        },
        "cognitionLabel": {
          "description": "Quality label derived from the cognition score.",
          "enum": ["high_signal", "review", "low_signal"]
        },
        "trustLevel": {
          "description": "Trust label for note-derived reasoning.",
          "const": "conditional"
        },
        "lastModified": {
          "description": "ISO 8601 timestamp of when the note record was last written.",
          "type": "string"
        }
      }
    }
  }
}
