{
  "openapi": "3.1.0",
  "info": {
    "title": "DayOneBuilder Resolver API",
    "version": "0.2.0",
    "description": "Callable service contract for agents choosing the best existing executor before building from scratch. Reference implementation: services/dob_resolver_api.py."
  },
  "servers": [
    {
      "url": "https://dayonebuilder.online"
    },
    {
      "url": "http://127.0.0.1:8787",
      "description": "Local reference service started with python3 services/dob_resolver_api.py --site site"
    }
  ],
  "paths": {
    "/healthz": {
      "get": {
        "summary": "Health check",
        "responses": {
          "200": {
            "description": "Service health",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["status", "service"],
                  "properties": {
                    "status": { "const": "ok" },
                    "service": { "const": "dob_resolver_api" },
                    "generated_at": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/recommend": {
      "get": {
        "summary": "Recommend the best executor for a task",
        "parameters": [
          {
            "name": "task",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "runtime",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "examples": ["codex-cli", "mcp", "skill", "shell"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Best executor recommendation",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Recommendation"
                }
              }
            }
          }
        }
      }
    },
    "/api/repo": {
      "get": {
        "summary": "Return a GitHub-backed report for one repository",
        "parameters": [
          {
            "name": "repo",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[^/]+/[^/]+$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Repository report",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RepoReport"
                }
              }
            }
          }
        }
      }
    },
    "/api/events": {
      "post": {
        "summary": "Record an audited resolver adoption event",
        "description": "Writes a JSONL event record for internal adoption telemetry. Raw task text is hashed by default.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResolverEvent"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Event accepted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["status", "record"],
                  "properties": {
                    "status": { "const": "accepted" },
                    "record": { "type": "object" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/stats": {
      "get": {
        "summary": "Return internal adoption event counts",
        "description": "Counts are for operational diagnostics. Do not publish badge counters until collection is audited.",
        "responses": {
          "200": {
            "description": "Event counts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResolverStats"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Recommendation": {
        "type": "object",
        "required": ["selected_source_url", "first_action", "smoke_test", "proof_signal", "fallback"],
        "properties": {
          "selected_action_id": { "type": "string" },
          "selected_source_url": { "type": "string" },
          "executor_type": { "type": "string" },
          "first_action": { "type": "string" },
          "smoke_test": { "type": "string" },
          "proof_signal": { "type": "string" },
          "fallback": { "type": "string" },
          "confidence": { "type": "string", "enum": ["high", "medium", "low"] },
          "matched_aliases": { "type": "array", "items": { "type": "string" } },
          "alternatives": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/RecommendationOption" }
          }
        }
      },
      "RecommendationOption": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "source_url": { "type": "string" },
          "title": { "type": "string" },
          "score": { "type": "number" },
          "matched_aliases": { "type": "array", "items": { "type": "string" } },
          "reason": { "type": "string" }
        }
      },
      "RepoReport": {
        "type": "object",
        "required": ["repo", "source", "github", "agent_action_plan"],
        "properties": {
          "repo": { "type": "string" },
          "source": { "const": "github_public_api_with_authenticated_cache" },
          "github": {
            "type": "object",
            "properties": {
              "stars": { "type": "integer" },
              "forks": { "type": "integer" },
              "subscribers_count": { "type": "integer" },
              "open_issues": { "type": "integer" },
              "pushed_at": { "type": "string" },
              "license": { "type": "string" },
              "topics": { "type": "array", "items": { "type": "string" } }
            }
          },
          "github_signal_score": { "type": "integer" },
          "detected_commands": {
            "type": "array",
            "items": { "type": "string" }
          },
          "agent_action_plan": { "$ref": "#/components/schemas/Recommendation" }
        }
      },
      "ResolverEvent": {
        "type": "object",
        "required": ["event_name"],
        "properties": {
          "event_name": {
            "type": "string",
            "enum": [
              "api_recommend_call",
              "mcp_recommend_call",
              "repo_report_loaded",
              "repo_report_error",
              "install_snippet_copy",
              "outbound_repo_click",
              "resolver_call",
              "smoke_test_pass"
            ]
          },
          "task": { "type": "string" },
          "repo": { "type": "string" },
          "runtime": { "type": "string" },
          "selected_action_id": { "type": "string" },
          "destination": { "type": "string" },
          "source": { "type": "string" }
        }
      },
      "ResolverStats": {
        "type": "object",
        "required": ["source", "generated_at", "total_events", "counts"],
        "properties": {
          "source": { "const": "dob_resolver_api_event_log" },
          "generated_at": { "type": "string" },
          "total_events": { "type": "integer" },
          "counts": {
            "type": "object",
            "additionalProperties": { "type": "integer" }
          },
          "public_use_note": { "type": "string" }
        }
      }
    }
  },
  "x-dayonebuilder-service-requirements": {
    "github": "Use an authenticated GitHub token, cache public repo/readme responses, and never show synthetic route/click/copy counts.",
    "agent_standard_goal": "Expose the same recommendation function through HTTP API, MCP tool, and installable skill.",
    "reference_run_command": "python3 services/dob_resolver_api.py --site site --host 127.0.0.1 --port 8787",
    "telemetry_rule": "Server telemetry is internal until audited; GitHub repo signals must come from GitHub API/cache."
  }
}
