{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tokrepo.com/schemas/agent-memory.schema.json",
  "title": "TokRepo Project Agent Memory",
  "description": "Machine-readable project memory written by tokrepo init-agent --target all so future agents know to use tokrepo_discover, tokrepo_verify, tokrepo_install_plan, and tokrepo_handoff_plan before rebuilding reusable work.",
  "type": "object",
  "required": ["schema_version", "tokrepo"],
  "properties": {
    "schema_version": { "type": "integer", "const": 1 },
    "schema": { "type": "string", "format": "uri" },
    "name": { "type": "string" },
    "updated_at": { "type": "string" },
    "tokrepo": {
      "type": "object",
      "required": ["enabled", "planning_tool", "trust_tool", "install_plan_tool", "handoff_plan_tool", "cli_fallbacks", "policy"],
      "properties": {
        "enabled": { "type": "boolean" },
        "initialized_by": { "type": "string" },
        "target": { "type": "string" },
        "machine_manifest": { "type": "string", "format": "uri" },
        "trust_manifest": { "type": "string", "format": "uri" },
        "tool_catalog": { "type": "string", "format": "uri" },
        "evidence_bundle_schema": {
          "type": "string",
          "format": "uri",
          "description": "Schema URL for verification/install evidence bundles.",
          "examples": ["https://tokrepo.com/schemas/agent-evidence-bundle.schema.json"]
        },
        "handoff_package_schema": {
          "type": "string",
          "format": "uri",
          "description": "Schema URL for reusable post-task handoff packages.",
          "examples": ["https://tokrepo.com/schemas/handoff-package.schema.json"]
        },
        "hosted_mcp": { "type": "string", "format": "uri" },
        "local_mcp_server": { "type": ["string", "null"] },
        "planning_tool": { "type": "string", "const": "tokrepo_discover" },
        "detail_tool": { "type": "string", "const": "tokrepo_detail" },
        "trust_tool": { "type": "string", "const": "tokrepo_verify" },
        "install_plan_tool": { "type": "string", "const": "tokrepo_install_plan" },
        "handoff_plan_tool": { "type": "string", "const": "tokrepo_handoff_plan" },
        "find_for_task_tool": {
          "type": "string",
          "const": "tokrepo_find_for_task",
          "description": "Atomic action 1 of 3 (find/install/harvest). REST: POST /api/v1/tokenboard/agent/find_for_task."
        },
        "atomic_actions": {
          "type": "object",
          "description": "The three canonical atomic actions agents perform in TokRepo's agent-native lifecycle.",
          "properties": {
            "find": { "type": "string", "const": "tokrepo_find_for_task" },
            "install": {
              "type": "array",
              "description": "Ordered chain: plan → verify → dry-run apply → rollback on failure.",
              "items": { "type": "string" },
              "default": ["tokrepo_install_plan", "tokrepo_verify", "tokrepo_codex_install", "tokrepo_rollback"]
            },
            "harvest": { "type": "string", "const": "tokrepo_harvest" }
          }
        },
        "last_action": {
          "type": "string",
          "enum": ["find_for_task", "install_plan", "install_apply", "rollback", "harvest_plan", "harvest_publish"],
          "description": "Most recent atomic action sub-step the agent performed in this project. Optional; written by mature clients to resume from the right step."
        },
        "lifecycle_tools": {
          "type": "array",
          "items": { "type": "string" }
        },
        "cli_fallbacks": {
          "type": "object",
          "required": ["planning", "verify", "install_dry_run", "handoff"],
          "additionalProperties": { "type": "string" }
        },
        "project_surfaces": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["target", "file", "purpose"],
            "properties": {
              "target": { "type": "string" },
              "file": { "type": "string" },
              "purpose": { "type": "string" }
            }
          }
        },
        "project_state_files": {
          "type": "array",
          "description": "Project-local lifecycle state files that agents can inspect before reinstalling, updating, uninstalling, or rolling back TokRepo-managed assets. Standard TokRepo installs write TokRepo.lock and .tokrepo/state.json.",
          "default": ["TokRepo.lock", ".tokrepo/state.json"],
          "items": {
            "type": "string",
            "examples": ["TokRepo.lock", ".tokrepo/state.json"]
          },
          "allOf": [
            { "contains": { "const": "TokRepo.lock" } },
            { "contains": { "const": ".tokrepo/state.json" } }
          ]
        },
        "mcp_config": { "type": ["string", "null"] },
        "policy": {
          "type": "object",
          "required": ["discover_before_build", "verify_before_activation", "dry_run_before_write", "human_confirmation_before_push"],
          "properties": {
            "discover_before_build": { "type": "boolean" },
            "verify_before_activation": { "type": "boolean" },
            "dry_run_before_write": { "type": "boolean" },
            "human_confirmation_before_push": { "type": "boolean" },
            "private_by_default": { "type": "boolean" }
          }
        }
      }
    }
  }
}
