{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:awoooi:javascript-package-inventory-v1",
  "title": "AWOOOI JavaScript 套件盤點 v1",
  "description": "由 repo 內 package.json、pnpm-workspace.yaml 與 pnpm-lock.yaml 產生的只讀 JavaScript / pnpm 套件盤點。此 schema 不授權安裝套件、升級套件、寫 lockfile、查外部 CVE、執行 npm audit 或改生產路由。",
  "type": "object",
  "required": [
    "schema_version",
    "generated_at",
    "program_status",
    "source_refs",
    "lockfile_summary",
    "rollups",
    "workspaces",
    "lockfile_drift",
    "drift_findings",
    "operation_boundaries",
    "approval_boundaries"
  ],
  "properties": {
    "schema_version": {
      "type": "string",
      "const": "javascript_package_inventory_v1"
    },
    "generated_at": {
      "type": "string",
      "minLength": 1
    },
    "program_status": {
      "type": "object",
      "required": [
        "overall_completion_percent",
        "current_priority",
        "current_task_id",
        "next_task_id",
        "read_only_mode"
      ],
      "properties": {
        "overall_completion_percent": {
          "type": "integer",
          "minimum": 0,
          "maximum": 100
        },
        "current_priority": {
          "type": "string",
          "enum": ["P0", "P1", "P2", "P3"]
        },
        "current_task_id": {
          "type": "string",
          "minLength": 1
        },
        "next_task_id": {
          "type": "string",
          "minLength": 1
        },
        "read_only_mode": {
          "type": "boolean",
          "const": true
        }
      },
      "additionalProperties": false
    },
    "source_refs": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "lockfile_summary": {
      "type": "object",
      "required": [
        "lockfile_ref",
        "lockfile_version",
        "importer_count",
        "package_entry_count",
        "snapshot_entry_count",
        "settings",
        "status",
        "write_allowed"
      ],
      "properties": {
        "lockfile_ref": {
          "type": "string",
          "minLength": 1
        },
        "lockfile_version": {
          "type": "string",
          "minLength": 1
        },
        "importer_count": {
          "type": "integer",
          "minimum": 0
        },
        "package_entry_count": {
          "type": "integer",
          "minimum": 0
        },
        "snapshot_entry_count": {
          "type": "integer",
          "minimum": 0
        },
        "settings": {
          "type": "object",
          "additionalProperties": {
            "type": ["boolean", "string", "integer", "number", "null"]
          }
        },
        "status": {
          "type": "string",
          "enum": ["in_sync", "action_required", "blocked"]
        },
        "write_allowed": {
          "type": "boolean",
          "const": false
        }
      },
      "additionalProperties": false
    },
    "rollups": {
      "type": "object",
      "required": [
        "total_workspaces",
        "total_direct_dependencies",
        "production_dependency_count",
        "dev_dependency_count",
        "workspace_dependency_count",
        "external_dependency_count",
        "caret_specifier_count",
        "exact_specifier_count",
        "tilde_specifier_count",
        "manifest_lock_mismatch_count",
        "missing_in_lockfile_count",
        "extra_in_lockfile_count",
        "by_status",
        "action_required_workspace_ids",
        "planned_next_workspace_ids"
      ],
      "properties": {
        "total_workspaces": {
          "type": "integer",
          "minimum": 0
        },
        "total_direct_dependencies": {
          "type": "integer",
          "minimum": 0
        },
        "production_dependency_count": {
          "type": "integer",
          "minimum": 0
        },
        "dev_dependency_count": {
          "type": "integer",
          "minimum": 0
        },
        "workspace_dependency_count": {
          "type": "integer",
          "minimum": 0
        },
        "external_dependency_count": {
          "type": "integer",
          "minimum": 0
        },
        "caret_specifier_count": {
          "type": "integer",
          "minimum": 0
        },
        "exact_specifier_count": {
          "type": "integer",
          "minimum": 0
        },
        "tilde_specifier_count": {
          "type": "integer",
          "minimum": 0
        },
        "manifest_lock_mismatch_count": {
          "type": "integer",
          "minimum": 0
        },
        "missing_in_lockfile_count": {
          "type": "integer",
          "minimum": 0
        },
        "extra_in_lockfile_count": {
          "type": "integer",
          "minimum": 0
        },
        "by_status": {
          "type": "object",
          "additionalProperties": {
            "type": "integer",
            "minimum": 0
          }
        },
        "action_required_workspace_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "planned_next_workspace_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "additionalProperties": false
    },
    "workspaces": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "workspace_id",
          "display_name",
          "manifest_ref",
          "lockfile_importer",
          "status",
          "risk_level",
          "private_package",
          "package_manager",
          "dependency_counts",
          "specifier_counts",
          "workspace_dependency_names",
          "evidence_refs",
          "next_action"
        ],
        "properties": {
          "workspace_id": {
            "type": "string",
            "minLength": 1
          },
          "display_name": {
            "type": "string",
            "minLength": 1
          },
          "manifest_ref": {
            "type": "string",
            "minLength": 1
          },
          "lockfile_importer": {
            "type": "string",
            "minLength": 1
          },
          "status": {
            "type": "string",
            "enum": ["ready", "action_required", "planned_next", "blocked", "deferred"]
          },
          "risk_level": {
            "type": "string",
            "enum": ["low", "medium", "high", "critical"]
          },
          "private_package": {
            "type": ["boolean", "null"]
          },
          "package_manager": {
            "type": ["string", "null"]
          },
          "dependency_counts": {
            "type": "object",
            "required": ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies", "total"],
            "properties": {
              "dependencies": {
                "type": "integer",
                "minimum": 0
              },
              "devDependencies": {
                "type": "integer",
                "minimum": 0
              },
              "peerDependencies": {
                "type": "integer",
                "minimum": 0
              },
              "optionalDependencies": {
                "type": "integer",
                "minimum": 0
              },
              "total": {
                "type": "integer",
                "minimum": 0
              }
            },
            "additionalProperties": false
          },
          "specifier_counts": {
            "type": "object",
            "required": ["workspace", "caret", "exact", "tilde", "other"],
            "properties": {
              "workspace": {
                "type": "integer",
                "minimum": 0
              },
              "caret": {
                "type": "integer",
                "minimum": 0
              },
              "exact": {
                "type": "integer",
                "minimum": 0
              },
              "tilde": {
                "type": "integer",
                "minimum": 0
              },
              "other": {
                "type": "integer",
                "minimum": 0
              }
            },
            "additionalProperties": false
          },
          "workspace_dependency_names": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "evidence_refs": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "next_action": {
            "type": "string",
            "minLength": 1
          }
        },
        "additionalProperties": false
      }
    },
    "lockfile_drift": {
      "type": "object",
      "required": [
        "status",
        "missing_in_lockfile",
        "specifier_mismatches",
        "extra_in_lockfile"
      ],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["in_sync", "action_required", "blocked"]
        },
        "missing_in_lockfile": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "specifier_mismatches": {
          "type": "array",
          "items": {
            "type": "object"
          }
        },
        "extra_in_lockfile": {
          "type": "array",
          "items": {
            "type": "object"
          }
        }
      },
      "additionalProperties": false
    },
    "drift_findings": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "finding_id",
          "severity",
          "status",
          "summary",
          "evidence_refs",
          "next_action"
        ],
        "properties": {
          "finding_id": {
            "type": "string",
            "minLength": 1
          },
          "severity": {
            "type": "string",
            "enum": ["low", "medium", "high", "critical"]
          },
          "status": {
            "type": "string",
            "enum": ["action_required", "planned_next", "blocked", "accepted"]
          },
          "summary": {
            "type": "string",
            "minLength": 1
          },
          "evidence_refs": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "minLength": 1
            }
          },
          "next_action": {
            "type": "string",
            "minLength": 1
          }
        },
        "additionalProperties": false
      }
    },
    "operation_boundaries": {
      "type": "object",
      "required": [
        "read_only_api_allowed",
        "package_installation_allowed",
        "package_upgrade_allowed",
        "lockfile_write_allowed",
        "external_cve_lookup_allowed",
        "npm_audit_allowed",
        "pnpm_install_allowed",
        "production_routing_allowed"
      ],
      "properties": {
        "read_only_api_allowed": {
          "type": "boolean",
          "const": true
        },
        "package_installation_allowed": {
          "type": "boolean",
          "const": false
        },
        "package_upgrade_allowed": {
          "type": "boolean",
          "const": false
        },
        "lockfile_write_allowed": {
          "type": "boolean",
          "const": false
        },
        "external_cve_lookup_allowed": {
          "type": "boolean",
          "const": false
        },
        "npm_audit_allowed": {
          "type": "boolean",
          "const": false
        },
        "pnpm_install_allowed": {
          "type": "boolean",
          "const": false
        },
        "production_routing_allowed": {
          "type": "boolean",
          "const": false
        }
      },
      "additionalProperties": false
    },
    "approval_boundaries": {
      "type": "object",
      "required": [
        "sdk_installation_allowed",
        "paid_api_call_allowed",
        "shadow_or_canary_allowed",
        "production_routing_allowed",
        "destructive_operation_allowed"
      ],
      "properties": {
        "sdk_installation_allowed": {
          "type": "boolean",
          "const": false
        },
        "paid_api_call_allowed": {
          "type": "boolean",
          "const": false
        },
        "shadow_or_canary_allowed": {
          "type": "boolean",
          "const": false
        },
        "production_routing_allowed": {
          "type": "boolean",
          "const": false
        },
        "destructive_operation_allowed": {
          "type": "boolean",
          "const": false
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
